diff --git a/coupler-reflector/src/lib.rs b/coupler-reflector/src/lib.rs index aa3b016..1e7dfa0 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 State { framebuffer: Vec, } -impl EditorState { - fn new() -> EditorState { - EditorState { +impl State { + fn new() -> State { + State { framebuffer: Vec::new(), } } @@ -34,14 +34,14 @@ impl EditorState { } } -pub struct EditorWindow { +pub struct PluginWindow { #[allow(unused)] app: App, window: Window, } -impl EditorWindow { - pub fn open(parent: &ParentWindow, size: Size) -> Result { +impl PluginWindow { + 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 = State::new(); let window = options.open(app.handle(), move |cx, event| state.handle_event(cx, event))?; window.show(); - Ok(EditorWindow { app, window }) + Ok(PluginWindow { app, window }) } } -impl Editor for EditorWindow { +impl View for PluginWindow { fn size(&self) -> Size { let size = self.window.size(); diff --git a/examples/gain/src/lib.rs b/examples/gain/src/lib.rs index 9e2d772..0984900 100644 --- a/examples/gain/src/lib.rs +++ b/examples/gain/src/lib.rs @@ -4,11 +4,9 @@ use serde::{Deserialize, Serialize}; use coupler::format::clap::*; use coupler::format::vst3::*; -use coupler::{ - buffers::*, bus::*, editor::*, events::*, host::*, params::*, plugin::*, process::*, -}; +use coupler::{buffers::*, bus::*, engine::*, events::*, host::*, params::*, plugin::*, view::*}; -use coupler_reflector::EditorWindow; +use coupler_reflector::PluginWindow; #[derive(Params, Serialize, Deserialize, Clone)] struct GainParams { @@ -27,8 +25,8 @@ pub struct Gain { } impl Plugin for Gain { - type Processor = GainProcessor; - type Editor = EditorWindow; + type Engine = GainEngine; + type View = PluginWindow; fn info() -> PluginInfo { PluginInfo { @@ -50,7 +48,7 @@ impl Plugin for Gain { }, ], params: GainParams::params(), - has_editor: true, + has_view: true, } } @@ -80,19 +78,19 @@ impl Plugin for Gain { Ok(()) } - fn processor(&mut self, _config: Config) -> Self::Processor { - GainProcessor { + fn engine(&mut self, _config: Config) -> Self::Engine { + GainEngine { params: self.params.clone(), } } - 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() + PluginWindow::open(parent, size).unwrap() } } @@ -112,11 +110,11 @@ impl ClapPlugin for Gain { } } -pub struct GainProcessor { +pub struct GainEngine { params: GainParams, } -impl GainProcessor { +impl GainEngine { fn handle_event(&mut self, event: &Event) { if let Data::ParamChange { id, value } = event.data { self.params.set_param(id, value); @@ -124,7 +122,7 @@ impl GainProcessor { } } -impl Processor for GainProcessor { +impl Engine for GainEngine { fn reset(&mut self) {} fn flush(&mut self, events: Events) { diff --git a/src/process.rs b/src/engine.rs similarity index 87% rename from src/process.rs rename to src/engine.rs index 215e7d5..f70f897 100644 --- a/src/process.rs +++ b/src/engine.rs @@ -9,7 +9,7 @@ pub struct Config { pub max_buffer_size: usize, } -pub trait Processor: Send + Sized + 'static { +pub trait Engine: Send + Sized + 'static { fn reset(&mut self); fn flush(&mut self, events: Events); fn process(&mut self, buffers: Buffers, events: Events); 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 feba206..c11682e 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -12,15 +12,15 @@ 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; use crate::params::{ParamId, ParamInfo, ParamValue}; use crate::plugin::{Plugin, PluginInfo}; -use crate::process::{Config, Processor}; 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 { @@ -57,7 +57,7 @@ pub struct ProcessState { buffer_data: Vec, buffer_ptrs: Vec<*mut f32>, events: Vec, - processor: Option, + engine: Option, } #[repr(C)] @@ -69,10 +69,10 @@ pub struct Instance { pub input_bus_map: Vec, pub output_bus_map: Vec, pub param_map: Arc>, - // Processor -> plugin parameter changes + // Engine -> plugin parameter changes pub plugin_params: ParamValues, - // Plugin -> processor parameter changes - pub processor_params: ParamValues, + // Plugin -> engine parameter changes + pub engine_params: ParamValues, pub param_gestures: Arc, pub main_thread_state: UnsafeCell>, pub process_state: UnsafeCell>, @@ -125,20 +125,20 @@ impl Instance

{ output_bus_map, param_map: Arc::new(param_map), plugin_params: ParamValues::with_count(info.params.len()), - processor_params: ParamValues::with_count(info.params.len()), + engine_params: ParamValues::with_count(info.params.len()), param_gestures: Arc::new(ParamGestures::with_count(info.params.len())), main_thread_state: UnsafeCell::new(MainThreadState { 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()), buffer_data: Vec::new(), buffer_ptrs: Vec::new(), events: Vec::with_capacity(4096), - processor: None, + engine: None, }), } } @@ -148,14 +148,14 @@ 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); } } } - fn sync_processor(&self, events: &mut Vec) { - for (index, value) in self.processor_params.poll() { + fn sync_engine(&self, events: &mut Vec) { + for (index, value) in self.engine_params.poll() { events.push(Event { time: 0, data: Data::ParamChange { @@ -357,11 +357,11 @@ impl Instance

{ max_buffer_size: max_frames_count as usize, }; - // Discard any pending plugin -> processor parameter changes, since they will already be - // reflected in the initial state of the processor. - for _ in instance.processor_params.poll() {} + // Discard any pending plugin -> engine parameter changes, since they will already be + // reflected in the initial state of the engine. + for _ in instance.engine_params.poll() {} - process_state.processor = Some(main_thread_state.plugin.processor(config)); + process_state.engine = Some(main_thread_state.plugin.engine(config)); true } @@ -371,11 +371,11 @@ impl Instance

{ let main_thread_state = &mut *instance.main_thread_state.get(); let process_state = &mut *instance.process_state.get(); - // Apply any remaining processor -> plugin parameter changes. There won't be any more until + // Apply any remaining engine -> plugin parameter changes. There won't be any more until // the next call to `activate`. instance.sync_plugin(main_thread_state); - process_state.processor = None; + process_state.engine = None; } unsafe extern "C" fn start_processing(_plugin: *const clap_plugin) -> bool { @@ -388,16 +388,16 @@ impl Instance

{ let instance = &*(plugin as *const Self); let process_state = &mut *instance.process_state.get(); - if let Some(processor) = &mut process_state.processor { - // Flush plugin -> processor parameter changes + if let Some(engine) = &mut process_state.engine { + // Flush plugin -> engine parameter changes process_state.events.clear(); - instance.sync_processor(&mut process_state.events); + instance.sync_engine(&mut process_state.events); if !process_state.events.is_empty() { - processor.flush(Events::new(&process_state.events)); + engine.flush(Events::new(&process_state.events)); } - processor.reset(); + engine.reset(); } } @@ -408,7 +408,7 @@ impl Instance

{ let instance = &*(plugin as *const Self); let process_state = &mut *instance.process_state.get(); - let Some(processor) = &mut process_state.processor else { + let Some(engine) = &mut process_state.engine else { return CLAP_PROCESS_ERROR; }; @@ -471,7 +471,7 @@ impl Instance

{ } process_state.events.clear(); - instance.sync_processor(&mut process_state.events); + instance.sync_engine(&mut process_state.events); instance.process_param_events(process.in_events, &mut process_state.events); let last_sample = process.frames_count.saturating_sub(1); @@ -482,7 +482,7 @@ impl Instance

{ last_sample, ); - processor.process( + engine.process( Buffers::from_raw_parts( &process_state.buffer_data, &process_state.buffer_ptrs, @@ -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; } } @@ -800,9 +800,9 @@ impl Instance

{ let process_state = &mut *instance.process_state.get(); // If we are in the active state, flush will be called on the audio thread. - if let Some(processor) = &mut process_state.processor { + if let Some(engine) = &mut process_state.engine { process_state.events.clear(); - instance.sync_processor(&mut process_state.events); + instance.sync_engine(&mut process_state.events); instance.process_param_events(in_, &mut process_state.events); instance.process_gestures( &mut process_state.gesture_states, @@ -811,7 +811,7 @@ impl Instance

{ 0, ); - processor.flush(Events::new(&process_state.events)); + engine.flush(Events::new(&process_state.events)); } // Otherwise, flush will be called on the main thread. else { @@ -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); } } @@ -933,10 +933,10 @@ impl Instance

{ if main_thread_state.plugin.load(&mut StreamReader(stream)).is_ok() { for (index, param) in instance.info.params.iter().enumerate() { let value = main_thread_state.plugin.get_param(param.id); - instance.processor_params.set(index, value); + 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 8d2c73f..46d4f58 100644 --- a/src/format/clap/tests.rs +++ b/src/format/clap/tests.rs @@ -2,16 +2,16 @@ 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; +use crate::engine::{Config, Engine}; use crate::host::Host; use crate::params::{ParamId, ParamValue}; use crate::plugin::{Plugin, PluginInfo}; -use crate::process::{Config, Processor}; use super::{ClapInfo, ClapPlugin, Factory}; @@ -25,8 +25,8 @@ const ID: &str = "com.example.plugin"; struct TestPlugin; impl Plugin for TestPlugin { - type Processor = TestProcessor; - type Editor = TestEditor; + type Engine = TestEngine; + 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 { @@ -54,11 +54,11 @@ impl Plugin for TestPlugin { fn load(&mut self, _input: &mut impl Read) -> io::Result<()> { Ok(()) } - fn processor(&mut self, _config: Config) -> Self::Processor { - TestProcessor + 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)] @@ -73,17 +73,17 @@ impl ClapPlugin for TestPlugin { } } -struct TestProcessor; +struct TestEngine; -impl Processor for TestProcessor { +impl Engine for TestEngine { fn reset(&mut self) {} fn flush(&mut self, _events: Events) {} 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/buffers.rs b/src/format/vst3/buffers.rs index 505696c..cb4e347 100644 --- a/src/format/vst3/buffers.rs +++ b/src/format/vst3/buffers.rs @@ -6,7 +6,7 @@ use vst3::Steinberg::Vst::ProcessData; use crate::buffers::{BufferData, BufferType, Buffers}; use crate::bus::{BusDir, BusInfo}; -use crate::process::Config; +use crate::engine::Config; use crate::util::slice_from_raw_parts_checked; pub struct ScratchBuffers { @@ -87,7 +87,7 @@ impl ScratchBuffers { self.moves.reserve(in_out_channels); } - /// Set up buffer pointers for the processor given a VST3 `ProcessData` struct. + /// Set up buffer pointers for the engine given a VST3 `ProcessData` struct. /// /// This method is responsible for detecting if any of the buffers for an input bus are aliased /// by a output buffer and, if so, copying those inputs to scratch buffers. It is also @@ -98,7 +98,7 @@ impl ScratchBuffers { /// the buffer's length exceeds the maximum buffer size. It will return `Ok(None)` if the /// buffer's length is 0, as hosts are not guaranteed to provide the correct number of inputs /// and outputs in that case, and we don't need to construct a `Buffers` object as we will be - /// calling `Processor::flush` instead of `Processor::process`. + /// calling `Engine::flush` instead of `Engine::process`. pub unsafe fn get_buffers( &mut self, buses: &[BusInfo], diff --git a/src/format/vst3/component.rs b/src/format/vst3/component.rs index 6634481..e485bd5 100644 --- a/src/format/vst3/component.rs +++ b/src/format/vst3/component.rs @@ -10,16 +10,16 @@ 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::{View, 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; use crate::params::ParamId; use crate::plugin::{Plugin, PluginInfo}; -use crate::process::{Config, Processor}; 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,16 +39,16 @@ 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 { config: Config, scratch_buffers: ScratchBuffers, events: Vec, - processor: Option, + engine: Option, } pub struct Component { @@ -58,7 +58,7 @@ pub struct Component { layout_set: HashSet, param_map: HashMap, plugin_params: ParamValues, - processor_params: ParamValues, + engine_params: ParamValues, _host: Arc, main_thread_state: Arc>>, // When the audio processor is *not* active, references to ProcessState may only be formed from @@ -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()); @@ -108,20 +108,20 @@ impl Component

{ layout_set, param_map, plugin_params: ParamValues::with_count(info.params.len()), - processor_params: ParamValues::with_count(info.params.len()), + engine_params: ParamValues::with_count(info.params.len()), _host: host.clone(), 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, scratch_buffers, events: Vec::with_capacity(4096), - processor: None, + engine: None, }), } } @@ -265,21 +265,21 @@ impl IComponentTrait for Component

{ let process_state = &mut *self.process_state.get(); if state == 0 { - // Apply any remaining processor -> plugin parameter changes. There won't be any more + // Apply any remaining engine -> plugin parameter changes. There won't be any more // until the plugin becomes active again. self.sync_plugin(&mut main_thread_state.plugin); - process_state.processor = None; + process_state.engine = None; } else { let config = main_thread_state.config.clone(); process_state.config = config.clone(); process_state.scratch_buffers.resize(&self.info.buses, &config); - // Discard any pending plugin -> processor parameter changes, since they will already be - // reflected in the initial state of the processor. - for _ in self.processor_params.poll() {} + // Discard any pending plugin -> engine parameter changes, since they will already be + // reflected in the initial state of the engine. + for _ in self.engine_params.poll() {} - process_state.processor = Some(main_thread_state.plugin.processor(config)); + process_state.engine = Some(main_thread_state.plugin.engine(config)); } kResultOk @@ -313,11 +313,11 @@ impl IComponentTrait for Component

{ if main_thread_state.plugin.load(&mut StreamReader(state)).is_ok() { for (index, param) in self.info.params.iter().enumerate() { let value = main_thread_state.plugin.get_param(param.id); - self.processor_params.set(index, value); - main_thread_state.editor_params[index] = value; + self.engine_params.set(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); } } @@ -469,14 +469,14 @@ impl IAudioProcessorTrait for Component

{ unsafe fn setProcessing(&self, state: TBool) -> tresult { let process_state = &mut *self.process_state.get(); - let Some(processor) = &mut process_state.processor else { + let Some(engine) = &mut process_state.engine else { return kNotInitialized; }; if state == 0 { - // Flush plugin -> processor parameter changes + // Flush plugin -> engine parameter changes process_state.events.clear(); - for (index, value) in self.processor_params.poll() { + for (index, value) in self.engine_params.poll() { process_state.events.push(Event { time: 0, data: Data::ParamChange { @@ -487,10 +487,10 @@ impl IAudioProcessorTrait for Component

{ } if !process_state.events.is_empty() { - processor.flush(Events::new(&process_state.events)); + engine.flush(Events::new(&process_state.events)); } - processor.reset(); + engine.reset(); } kResultOk @@ -499,7 +499,7 @@ impl IAudioProcessorTrait for Component

{ unsafe fn process(&self, data: *mut ProcessData) -> tresult { let process_state = &mut *self.process_state.get(); - let Some(processor) = &mut process_state.processor else { + let Some(engine) = &mut process_state.engine else { return kNotInitialized; }; @@ -517,7 +517,7 @@ impl IAudioProcessorTrait for Component

{ process_state.events.clear(); - for (index, value) in self.processor_params.poll() { + for (index, value) in self.engine_params.poll() { process_state.events.push(Event { time: 0, data: Data::ParamChange { @@ -562,9 +562,9 @@ impl IAudioProcessorTrait for Component

{ let events = Events::new(&process_state.events); if let Some(buffers) = buffers { - processor.process(buffers, events); + engine.process(buffers, events); } else { - processor.flush(events); + engine.flush(events); } kResultOk @@ -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(); } @@ -719,7 +719,7 @@ impl IEditControllerTrait for Component

{ return ptr::null_mut(); } - let view = ComWrapper::new(View::new(&self.main_thread_state)); + let view = ComWrapper::new(PlugView::new(&self.main_thread_state)); view.to_com_ptr::().unwrap().into_raw() } } diff --git a/src/format/vst3/tests.rs b/src/format/vst3/tests.rs index 7e3cccf..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::process::{Config, Processor}; +use crate::view::{ParentWindow, Size, View, ViewHost}; use vst3::Steinberg::Vst::{IComponent, SDKVersionString}; use vst3::Steinberg::{char16, char8, int32}; @@ -32,8 +32,8 @@ const CLASS_ID: [u32; 4] = [0x11111111, 0x22222222, 0x33333333, 0x44444444]; struct TestPlugin; impl Plugin for TestPlugin { - type Processor = TestProcessor; - type Editor = TestEditor; + type Engine = TestEngine; + 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 { @@ -61,11 +61,11 @@ impl Plugin for TestPlugin { fn load(&mut self, _input: &mut impl Read) -> io::Result<()> { Ok(()) } - fn processor(&mut self, _config: Config) -> Self::Processor { - TestProcessor + 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)] @@ -82,17 +82,17 @@ impl Vst3Plugin for TestPlugin { } } -struct TestProcessor; +struct TestEngine; -impl Processor for TestProcessor { +impl Engine for TestEngine { fn reset(&mut self) {} fn flush(&mut self, _events: Events) {} 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 aeb5ba8..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 { @@ -51,23 +51,23 @@ impl EditorHostInner for Vst3EditorHost { } } -pub struct View { +pub struct PlugView { main_thread_state: Arc>>, } -impl View

{ - pub fn new(main_thread_state: &Arc>>) -> View

{ - View { +impl PlugView

{ + pub fn new(main_thread_state: &Arc>>) -> PlugView

{ + PlugView { main_thread_state: main_thread_state.clone(), } } } -impl Class for View

{ +impl Class for PlugView

{ type Interfaces = (IPlugView,); } -impl IPlugViewTrait for View

{ +impl IPlugViewTrait for PlugView

{ unsafe fn isPlatformTypeSupported(&self, type_: FIDString) -> tresult { #[cfg(target_os = "windows")] if CStr::from_ptr(type_) == CStr::from_ptr(kPlatformTypeHWND) { @@ -103,10 +103,10 @@ impl IPlugViewTrait for View

{ 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 View

{ 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 View

{ 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 e6fee83..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 process; +pub mod view; mod sync; mod util; diff --git a/src/plugin.rs b/src/plugin.rs index 6b2cc57..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::process::{Config, Processor}; +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 Processor: Processor; - type Editor: Editor; + type Engine: Engine; + type View: View; fn info() -> PluginInfo; fn new(host: Host) -> Self; @@ -45,8 +45,8 @@ pub trait Plugin: Send + Sized + 'static { fn get_param(&self, id: ParamId) -> ParamValue; fn save(&self, output: &mut impl Write) -> io::Result<()>; fn load(&mut self, input: &mut impl Read) -> io::Result<()>; - fn processor(&mut self, config: Config) -> Self::Processor; - fn editor(&mut self, host: EditorHost, parent: &ParentWindow) -> Self::Editor; + fn engine(&mut self, config: Config) -> Self::Engine; + 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,