diff --git a/coupler-reflector/src/lib.rs b/coupler-reflector/src/lib.rs index aa3b016..c2eabcd 100644 --- a/coupler-reflector/src/lib.rs +++ b/coupler-reflector/src/lib.rs @@ -1,17 +1,17 @@ -use coupler::editor::{Editor, ParentWindow, RawParent, Size}; use coupler::params::{ParamId, ParamValue}; +use coupler::view::{ParentWindow, RawParent, Size, View}; use reflector::platform::{ App, AppMode, AppOptions, Bitmap, Event, RawWindow, Response, Result, Window, WindowContext, WindowOptions, }; -struct EditorState { +struct ViewState { framebuffer: Vec, } -impl EditorState { - fn new() -> EditorState { - EditorState { +impl ViewState { + fn new() -> ViewState { + ViewState { framebuffer: Vec::new(), } } @@ -34,14 +34,14 @@ impl EditorState { } } -pub struct EditorWindow { +pub struct ViewWindow { #[allow(unused)] app: App, window: Window, } -impl EditorWindow { - pub fn open(parent: &ParentWindow, size: Size) -> Result { +impl ViewWindow { + pub fn open(parent: &ParentWindow, size: Size) -> Result { let app = AppOptions::new().mode(AppMode::Guest).build()?; let mut options = WindowOptions::new(); @@ -54,16 +54,16 @@ impl EditorWindow { }; unsafe { options.raw_parent(raw_parent) }; - let mut state = EditorState::new(); + let mut state = ViewState::new(); let window = options.open(app.handle(), move |cx, event| state.handle_event(cx, event))?; window.show(); - Ok(EditorWindow { app, window }) + Ok(ViewWindow { app, window }) } } -impl Editor for EditorWindow { +impl View for ViewWindow { fn size(&self) -> Size { let size = self.window.size(); diff --git a/examples/gain/src/lib.rs b/examples/gain/src/lib.rs index fcd8ae0..93adefb 100644 --- a/examples/gain/src/lib.rs +++ b/examples/gain/src/lib.rs @@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize}; use coupler::format::clap::*; use coupler::format::vst3::*; -use coupler::{buffers::*, bus::*, editor::*, engine::*, events::*, host::*, params::*, plugin::*}; +use coupler::{buffers::*, bus::*, engine::*, events::*, host::*, params::*, plugin::*, view::*}; -use coupler_reflector::EditorWindow; +use coupler_reflector::ViewWindow; #[derive(Params, Serialize, Deserialize, Clone)] struct GainParams { @@ -26,7 +26,7 @@ pub struct Gain { impl Plugin for Gain { type Engine = GainEngine; - type Editor = EditorWindow; + type View = ViewWindow; fn info() -> PluginInfo { PluginInfo { @@ -48,7 +48,7 @@ impl Plugin for Gain { }, ], params: GainParams::params(), - has_editor: true, + has_view: true, } } @@ -84,13 +84,13 @@ impl Plugin for Gain { } } - fn editor(&mut self, _host: EditorHost, parent: &ParentWindow) -> Self::Editor { + fn view(&mut self, _host: ViewHost, parent: &ParentWindow) -> Self::View { let size = Size { width: 512.0, height: 512.0, }; - EditorWindow::open(parent, size).unwrap() + ViewWindow::open(parent, size).unwrap() } } diff --git a/src/format/clap/gui.rs b/src/format/clap/gui.rs index 28dbbc7..a76b63f 100644 --- a/src/format/clap/gui.rs +++ b/src/format/clap/gui.rs @@ -7,19 +7,19 @@ use clap_sys::ext::{gui::*, params::*}; use clap_sys::{host::*, plugin::*}; use super::instance::Instance; -use crate::editor::{Editor, EditorHost, EditorHostInner, ParentWindow, RawParent}; use crate::params::{ParamId, ParamValue}; use crate::plugin::Plugin; use crate::sync::param_gestures::ParamGestures; +use crate::view::{ParentWindow, RawParent, View, ViewHost, ViewHostInner}; -struct ClapEditorHost { +struct ClapViewHost { host: *const clap_host, host_params: Option<*const clap_host_params>, param_map: Arc>, param_gestures: Arc, } -impl EditorHostInner for ClapEditorHost { +impl ViewHostInner for ClapViewHost { fn begin_gesture(&self, id: ParamId) { self.param_gestures.begin_gesture(self.param_map[&id]); @@ -113,7 +113,7 @@ impl Instance

{ let instance = &*(plugin as *const Self); let main_thread_state = &mut *instance.main_thread_state.get(); - main_thread_state.editor = None; + main_thread_state.view = None; } unsafe extern "C" fn gui_set_scale(_plugin: *const clap_plugin, _scale: f64) -> bool { @@ -128,8 +128,8 @@ impl Instance

{ let instance = &*(plugin as *const Self); let main_thread_state = &mut *instance.main_thread_state.get(); - if let Some(editor) = &main_thread_state.editor { - let size = editor.size(); + if let Some(view) = &main_thread_state.view { + let size = view.size(); *width = size.width.round() as u32; *height = size.height.round() as u32; @@ -189,15 +189,15 @@ impl Instance

{ let instance = &*(plugin as *const Self); let main_thread_state = &mut *instance.main_thread_state.get(); - let host = EditorHost::from_inner(Rc::new(ClapEditorHost { + let host = ViewHost::from_inner(Rc::new(ClapViewHost { host: instance.host, host_params: main_thread_state.host_params, param_map: Arc::clone(&instance.param_map), param_gestures: Arc::clone(&instance.param_gestures), })); let parent = ParentWindow::from_raw(raw_parent); - let editor = main_thread_state.plugin.editor(host, &parent); - main_thread_state.editor = Some(editor); + let view = main_thread_state.plugin.view(host, &parent); + main_thread_state.view = Some(view); true } diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index 5d89a7f..c11682e 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -12,7 +12,6 @@ use clap_sys::{events::*, host::*, id::*, plugin::*, process::*, stream::*}; use super::host::ClapHost; use crate::buffers::{BufferData, BufferType, Buffers}; use crate::bus::{BusDir, Format}; -use crate::editor::Editor; use crate::engine::{Config, Engine}; use crate::events::{Data, Event, Events}; use crate::host::Host; @@ -21,6 +20,7 @@ use crate::plugin::{Plugin, PluginInfo}; use crate::sync::param_gestures::{GestureStates, GestureUpdate, ParamGestures}; use crate::sync::params::ParamValues; use crate::util::{copy_cstring, slice_from_raw_parts_checked, DisplayParam}; +use crate::view::View; fn port_type_from_format(format: &Format) -> &'static CStr { match format { @@ -49,7 +49,7 @@ pub struct MainThreadState { pub host_params: Option<*const clap_host_params>, pub layout_index: usize, pub plugin: P, - pub editor: Option, + pub view: Option, } pub struct ProcessState { @@ -131,7 +131,7 @@ impl Instance

{ host_params: None, layout_index: 0, plugin: P::new(Host::from_inner(Arc::new(ClapHost {}))), - editor: None, + view: None, }), process_state: UnsafeCell::new(ProcessState { gesture_states: GestureStates::with_count(info.params.len()), @@ -148,8 +148,8 @@ impl Instance

{ let id = self.info.params[index].id; main_thread_state.plugin.set_param(id, value); - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(id, value); } } } @@ -519,7 +519,7 @@ impl Instance

{ if id == CLAP_EXT_GUI { let instance = &*(plugin as *const Self); - if instance.info.has_editor { + if instance.info.has_view { return &Self::GUI as *const _ as *const c_void; } } @@ -830,8 +830,8 @@ impl Instance

{ let value = map_param_in(&instance.info.params[index], event.value); main_thread_state.plugin.set_param(event.param_id, value); - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(event.param_id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(event.param_id, value); } } } @@ -843,8 +843,8 @@ impl Instance

{ if let Some(value) = update.set_value { main_thread_state.plugin.set_param(param.id, value); - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(param.id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(param.id, value); } } @@ -935,8 +935,8 @@ impl Instance

{ let value = main_thread_state.plugin.get_param(param.id); instance.engine_params.set(index, value); - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(param.id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(param.id, value); } } diff --git a/src/format/clap/tests.rs b/src/format/clap/tests.rs index 3ae66ba..46d4f58 100644 --- a/src/format/clap/tests.rs +++ b/src/format/clap/tests.rs @@ -2,8 +2,8 @@ use std::ffi::{c_char, CStr}; use std::io::{self, Read, Write}; use crate::buffers::Buffers; -use crate::editor::{Editor, EditorHost, ParentWindow, Size}; use crate::events::Events; +use crate::view::{ParentWindow, Size, View, ViewHost}; use clap_sys::plugin_factory::{clap_plugin_factory, CLAP_PLUGIN_FACTORY_ID}; use clap_sys::version::CLAP_VERSION; @@ -26,7 +26,7 @@ struct TestPlugin; impl Plugin for TestPlugin { type Engine = TestEngine; - type Editor = TestEditor; + type View = TestView; fn info() -> PluginInfo { PluginInfo { @@ -38,7 +38,7 @@ impl Plugin for TestPlugin { buses: Vec::new(), layouts: vec![], params: Vec::new(), - has_editor: false, + has_view: false, } } fn new(_host: Host) -> Self { @@ -57,8 +57,8 @@ impl Plugin for TestPlugin { fn engine(&mut self, _config: Config) -> Self::Engine { TestEngine } - fn editor(&mut self, _host: EditorHost, _parent: &ParentWindow) -> Self::Editor { - TestEditor + fn view(&mut self, _host: ViewHost, _parent: &ParentWindow) -> Self::View { + TestView } #[allow(unused_variables)] @@ -81,9 +81,9 @@ impl Engine for TestEngine { fn process(&mut self, _buffers: Buffers, _events: Events) {} } -struct TestEditor; +struct TestView; -impl Editor for TestEditor { +impl View for TestView { fn size(&self) -> Size { Size { width: 0.0, diff --git a/src/format/vst3/component.rs b/src/format/vst3/component.rs index 02778cc..b6af46a 100644 --- a/src/format/vst3/component.rs +++ b/src/format/vst3/component.rs @@ -10,9 +10,8 @@ use vst3::{Class, ComRef, ComWrapper, Steinberg::Vst::*, Steinberg::*}; use super::buffers::ScratchBuffers; use super::host::Vst3Host; use super::util::{copy_wstring, utf16_from_ptr}; -use super::view::{PlugView, Vst3EditorHost}; +use super::view::{PlugView, Vst3ViewHost}; use crate::bus::{BusDir, Format, Layout}; -use crate::editor::Editor; use crate::engine::{Config, Engine}; use crate::events::{Data, Event, Events}; use crate::host::Host; @@ -20,6 +19,7 @@ use crate::params::ParamId; use crate::plugin::{Plugin, PluginInfo}; use crate::sync::params::ParamValues; use crate::util::{slice_from_raw_parts_checked, DisplayParam}; +use crate::view::View; fn format_to_speaker_arrangement(format: &Format) -> SpeakerArrangement { match format { @@ -39,9 +39,9 @@ fn speaker_arrangement_to_format(speaker_arrangement: SpeakerArrangement) -> Opt pub struct MainThreadState { pub config: Config, pub plugin: P, - pub editor_params: Vec, - pub editor_host: Rc, - pub editor: Option, + pub view_params: Vec, + pub view_host: Rc, + pub view: Option, } struct ProcessState { @@ -95,7 +95,7 @@ impl Component

{ max_buffer_size: 0, }; - let editor_params = info.params.iter().map(|p| p.default).collect(); + let view_params = info.params.iter().map(|p| p.default).collect(); let scratch_buffers = ScratchBuffers::new(input_bus_map.len(), output_bus_map.len()); @@ -113,9 +113,9 @@ impl Component

{ main_thread_state: Arc::new(UnsafeCell::new(MainThreadState { config: config.clone(), plugin: P::new(Host::from_inner(host)), - editor_params, - editor_host: Rc::new(Vst3EditorHost::new()), - editor: None, + view_params, + view_host: Rc::new(Vst3ViewHost::new()), + view: None, })), process_state: UnsafeCell::new(ProcessState { config, @@ -314,10 +314,10 @@ impl IComponentTrait for Component

{ for (index, param) in self.info.params.iter().enumerate() { let value = main_thread_state.plugin.get_param(param.id); self.engine_params.set(index, value); - main_thread_state.editor_params[index] = value; + main_thread_state.view_params[index] = value; - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(param.id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(param.id, value); } } @@ -675,7 +675,7 @@ impl IEditControllerTrait for Component

{ let main_thread_state = &*self.main_thread_state.get(); if let Some(&index) = self.param_map.get(&id) { - return main_thread_state.editor_params[index]; + return main_thread_state.view_params[index]; } 0.0 @@ -685,10 +685,10 @@ impl IEditControllerTrait for Component

{ let main_thread_state = &mut *self.main_thread_state.get(); if let Some(&index) = self.param_map.get(&id) { - main_thread_state.editor_params[index] = value; + main_thread_state.view_params[index] = value; - if let Some(editor) = &mut main_thread_state.editor { - editor.param_changed(id, value); + if let Some(view) = &mut main_thread_state.view { + view.param_changed(id, value); } return kResultOk; @@ -700,7 +700,7 @@ impl IEditControllerTrait for Component

{ unsafe fn setComponentHandler(&self, handler: *mut IComponentHandler) -> tresult { let main_thread_state = &mut *self.main_thread_state.get(); - let mut current_handler = main_thread_state.editor_host.handler.borrow_mut(); + let mut current_handler = main_thread_state.view_host.handler.borrow_mut(); if let Some(handler) = ComRef::from_raw(handler) { *current_handler = Some(handler.to_com_ptr()); } else { @@ -711,7 +711,7 @@ impl IEditControllerTrait for Component

{ } unsafe fn createView(&self, name: FIDString) -> *mut IPlugView { - if !self.info.has_editor { + if !self.info.has_view { return ptr::null_mut(); } diff --git a/src/format/vst3/tests.rs b/src/format/vst3/tests.rs index e023cd0..5a942ae 100644 --- a/src/format/vst3/tests.rs +++ b/src/format/vst3/tests.rs @@ -4,12 +4,12 @@ use std::io::{self, Read, Write}; use std::{ptr, slice}; use crate::buffers::Buffers; -use crate::editor::{Editor, EditorHost, ParentWindow, Size}; use crate::engine::{Config, Engine}; use crate::events::Events; use crate::host::Host; use crate::params::{ParamId, ParamValue}; use crate::plugin::{Plugin, PluginInfo}; +use crate::view::{ParentWindow, Size, View, ViewHost}; use vst3::Steinberg::Vst::{IComponent, SDKVersionString}; use vst3::Steinberg::{char16, char8, int32}; @@ -33,7 +33,7 @@ struct TestPlugin; impl Plugin for TestPlugin { type Engine = TestEngine; - type Editor = TestEditor; + type View = TestView; fn info() -> PluginInfo { PluginInfo { @@ -45,7 +45,7 @@ impl Plugin for TestPlugin { buses: Vec::new(), layouts: vec![], params: Vec::new(), - has_editor: false, + has_view: false, } } fn new(_host: Host) -> Self { @@ -64,8 +64,8 @@ impl Plugin for TestPlugin { fn engine(&mut self, _config: Config) -> Self::Engine { TestEngine } - fn editor(&mut self, _host: EditorHost, _parent: &ParentWindow) -> Self::Editor { - TestEditor + fn view(&mut self, _host: ViewHost, _parent: &ParentWindow) -> Self::View { + TestView } #[allow(unused_variables)] @@ -90,9 +90,9 @@ impl Engine for TestEngine { fn process(&mut self, _buffers: Buffers, _events: Events) {} } -struct TestEditor; +struct TestView; -impl Editor for TestEditor { +impl View for TestView { fn size(&self) -> Size { Size { width: 0.0, diff --git a/src/format/vst3/view.rs b/src/format/vst3/view.rs index 4623a84..b4da8f0 100644 --- a/src/format/vst3/view.rs +++ b/src/format/vst3/view.rs @@ -6,23 +6,23 @@ use vst3::Steinberg::Vst::{IComponentHandler, IComponentHandlerTrait}; use vst3::{Class, ComPtr, Steinberg::*}; use super::component::MainThreadState; -use crate::editor::{Editor, EditorHost, EditorHostInner, ParentWindow, RawParent}; use crate::params::{ParamId, ParamValue}; use crate::plugin::Plugin; +use crate::view::{ParentWindow, RawParent, View, ViewHost, ViewHostInner}; -pub struct Vst3EditorHost { +pub struct Vst3ViewHost { pub handler: RefCell>>, } -impl Vst3EditorHost { - pub fn new() -> Vst3EditorHost { - Vst3EditorHost { +impl Vst3ViewHost { + pub fn new() -> Vst3ViewHost { + Vst3ViewHost { handler: RefCell::new(None), } } } -impl EditorHostInner for Vst3EditorHost { +impl ViewHostInner for Vst3ViewHost { fn begin_gesture(&self, id: ParamId) { let handler = self.handler.borrow(); if let Some(handler) = &*handler { @@ -103,10 +103,10 @@ impl IPlugViewTrait for PlugView

{ let main_thread_state = &mut *self.main_thread_state.get(); - let host = EditorHost::from_inner(main_thread_state.editor_host.clone()); + let host = ViewHost::from_inner(main_thread_state.view_host.clone()); let parent = ParentWindow::from_raw(raw_parent); - let editor = main_thread_state.plugin.editor(host, &parent); - main_thread_state.editor = Some(editor); + let view = main_thread_state.plugin.view(host, &parent); + main_thread_state.view = Some(view); kResultOk } @@ -114,7 +114,7 @@ impl IPlugViewTrait for PlugView

{ unsafe fn removed(&self) -> tresult { let main_thread_state = &mut *self.main_thread_state.get(); - main_thread_state.editor = None; + main_thread_state.view = None; kResultOk } @@ -138,14 +138,14 @@ impl IPlugViewTrait for PlugView

{ let main_thread_state = &*self.main_thread_state.get(); - if let Some(editor) = &main_thread_state.editor { - let editor_size = editor.size(); + if let Some(view) = &main_thread_state.view { + let view_size = view.size(); let rect = &mut *size; rect.left = 0; rect.top = 0; - rect.right = editor_size.width.round() as int32; - rect.bottom = editor_size.height.round() as int32; + rect.right = view_size.width.round() as int32; + rect.bottom = view_size.height.round() as int32; return kResultOk; } diff --git a/src/lib.rs b/src/lib.rs index b72f059..8d85cac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,13 +2,13 @@ pub mod buffers; pub mod bus; -pub mod editor; pub mod engine; pub mod events; pub mod format; pub mod host; pub mod params; pub mod plugin; +pub mod view; mod sync; mod util; diff --git a/src/plugin.rs b/src/plugin.rs index 75beebf..c1fd578 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,10 +1,10 @@ use std::io::{self, Read, Write}; use crate::bus::{BusInfo, Layout}; -use crate::editor::{Editor, EditorHost, ParentWindow}; use crate::engine::{Config, Engine}; use crate::host::Host; use crate::params::{ParamId, ParamInfo, ParamValue}; +use crate::view::{ParentWindow, View, ViewHost}; pub struct PluginInfo { pub name: String, @@ -15,7 +15,7 @@ pub struct PluginInfo { pub buses: Vec, pub layouts: Vec, pub params: Vec, - pub has_editor: bool, + pub has_view: bool, } #[allow(clippy::derivable_impls)] @@ -30,14 +30,14 @@ impl Default for PluginInfo { buses: Vec::new(), layouts: Vec::new(), params: Vec::new(), - has_editor: false, + has_view: false, } } } pub trait Plugin: Send + Sized + 'static { type Engine: Engine; - type Editor: Editor; + type View: View; fn info() -> PluginInfo; fn new(host: Host) -> Self; @@ -46,7 +46,7 @@ pub trait Plugin: Send + Sized + 'static { fn save(&self, output: &mut impl Write) -> io::Result<()>; fn load(&mut self, input: &mut impl Read) -> io::Result<()>; fn engine(&mut self, config: Config) -> Self::Engine; - fn editor(&mut self, host: EditorHost, parent: &ParentWindow) -> Self::Editor; + fn view(&mut self, host: ViewHost, parent: &ParentWindow) -> Self::View; #[allow(unused_variables)] fn latency(&self, config: &Config) -> u64 { diff --git a/src/editor.rs b/src/view.rs similarity index 83% rename from src/editor.rs rename to src/view.rs index c4a366e..d73cdbd 100644 --- a/src/editor.rs +++ b/src/view.rs @@ -4,22 +4,22 @@ use std::rc::Rc; use crate::params::{ParamId, ParamValue}; -pub trait EditorHostInner { +pub trait ViewHostInner { fn begin_gesture(&self, id: ParamId); fn end_gesture(&self, id: ParamId); fn set_param(&self, id: ParamId, value: ParamValue); } #[derive(Clone)] -pub struct EditorHost { - inner: Rc, +pub struct ViewHost { + inner: Rc, // Ensure !Send and !Sync _marker: PhantomData<*mut ()>, } -impl EditorHost { - pub fn from_inner(inner: Rc) -> EditorHost { - EditorHost { +impl ViewHost { + pub fn from_inner(inner: Rc) -> ViewHost { + ViewHost { inner, _marker: PhantomData, } @@ -64,14 +64,14 @@ pub struct Size { pub height: f64, } -pub trait Editor: Sized + 'static { +pub trait View: Sized + 'static { fn size(&self) -> Size; fn param_changed(&mut self, id: ParamId, value: ParamValue); } -pub struct NoEditor; +pub struct NoView; -impl Editor for NoEditor { +impl View for NoView { fn size(&self) -> Size { Size { width: 0.0,