From e933100dc3d8c318c0991ecf2c27b993f0ce75b9 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Thu, 18 Jan 2024 01:22:21 -0600 Subject: [PATCH] move Plugin, Processor, and Editor into modules --- examples/gain/src/lib.rs | 2 +- src/{parent.rs => editor.rs} | 16 ++++++++ src/format/clap/factory.rs | 2 +- src/format/clap/gui.rs | 4 +- src/format/clap/instance.rs | 5 ++- src/format/vst3/buffers.rs | 2 +- src/format/vst3/component.rs | 5 ++- src/format/vst3/factory.rs | 2 +- src/format/vst3/mod.rs | 2 +- src/format/vst3/view.rs | 4 +- src/lib.rs | 71 ++---------------------------------- src/plugin.rs | 38 +++++++++++++++++++ src/{block.rs => process.rs} | 15 ++++++++ 13 files changed, 87 insertions(+), 81 deletions(-) rename src/{parent.rs => editor.rs} (56%) create mode 100644 src/plugin.rs rename src/{block.rs => process.rs} (81%) diff --git a/examples/gain/src/lib.rs b/examples/gain/src/lib.rs index 49317da..3cb49e0 100644 --- a/examples/gain/src/lib.rs +++ b/examples/gain/src/lib.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use coupler::buffers::bind::*; use coupler::format::clap::*; use coupler::format::vst3::*; -use coupler::{block::*, bus::*, events::*, params::*, parent::*, *}; +use coupler::{bus::*, editor::*, events::*, params::*, plugin::*, process::*}; #[derive(Params, Serialize, Deserialize, Clone)] struct GainParams { diff --git a/src/parent.rs b/src/editor.rs similarity index 56% rename from src/parent.rs rename to src/editor.rs index 822cff6..24c04e7 100644 --- a/src/parent.rs +++ b/src/editor.rs @@ -1,5 +1,7 @@ use std::ffi::{c_ulong, c_void}; +use crate::params::{ParamId, ParamValue}; + #[derive(Copy, Clone)] pub enum RawParent { Win32(*mut c_void), @@ -20,3 +22,17 @@ impl Parent { self.parent } } + +pub struct Size { + pub width: f64, + pub height: f64, +} + +pub trait Editor: Sized + 'static { + fn exists() -> bool { + true + } + + fn size(&self) -> Size; + fn set_param(&mut self, id: ParamId, value: ParamValue); +} diff --git a/src/format/clap/factory.rs b/src/format/clap/factory.rs index e7ce84b..ec7de73 100644 --- a/src/format/clap/factory.rs +++ b/src/format/clap/factory.rs @@ -8,7 +8,7 @@ use clap_sys::{host::*, plugin::*, plugin_factory::*, version::*}; use super::instance::Instance; use super::ClapPlugin; -use crate::{Plugin, PluginInfo}; +use crate::plugin::{Plugin, PluginInfo}; struct FactoryState { descriptor: clap_plugin_descriptor, diff --git a/src/format/clap/gui.rs b/src/format/clap/gui.rs index a79a86a..77eb1fa 100644 --- a/src/format/clap/gui.rs +++ b/src/format/clap/gui.rs @@ -4,8 +4,8 @@ use clap_sys::ext::gui::*; use clap_sys::plugin::*; use super::instance::Instance; -use crate::parent::{Parent, RawParent}; -use crate::{Editor, Plugin}; +use crate::editor::{Editor, Parent, RawParent}; +use crate::plugin::Plugin; impl Instance

{ pub(super) const GUI: clap_plugin_gui = clap_plugin_gui { diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index 09bca1c..b051235 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -9,14 +9,15 @@ use std::{io, ptr, slice}; use clap_sys::ext::{audio_ports::*, audio_ports_config::*, gui::*, params::*, state::*}; use clap_sys::{events::*, id::*, plugin::*, process::*, stream::*}; -use crate::block::Block; use crate::buffers::{Buffers, BusData}; use crate::bus::{BusDir, Format}; +use crate::editor::Editor; use crate::events::{Data, Event, Events}; use crate::params::{ParamId, ParamInfo, ParamValue}; +use crate::plugin::{Host, Plugin, PluginInfo}; +use crate::process::{Block, Config, Processor}; use crate::sync::params::ParamValues; use crate::util::{copy_cstring, slice_from_raw_parts_checked, DisplayParam}; -use crate::{Config, Editor, Host, Plugin, PluginInfo, Processor}; fn port_type_from_format(format: &Format) -> &'static CStr { match format { diff --git a/src/format/vst3/buffers.rs b/src/format/vst3/buffers.rs index 00f4e86..3cc4f14 100644 --- a/src/format/vst3/buffers.rs +++ b/src/format/vst3/buffers.rs @@ -6,8 +6,8 @@ use vst3::Steinberg::Vst::ProcessData; use crate::buffers::{Buffers, BusData}; use crate::bus::{BusDir, BusInfo}; +use crate::process::Config; use crate::util::slice_from_raw_parts_checked; -use crate::Config; pub struct ScratchBuffers { inputs_active: Vec, diff --git a/src/format/vst3/component.rs b/src/format/vst3/component.rs index eba8648..9244664 100644 --- a/src/format/vst3/component.rs +++ b/src/format/vst3/component.rs @@ -9,13 +9,14 @@ use vst3::{Class, ComRef, ComWrapper, Steinberg::Vst::*, Steinberg::*}; use super::buffers::ScratchBuffers; use super::util::{copy_wstring, utf16_from_ptr}; use super::view::View; -use crate::block::Block; use crate::bus::{BusDir, Format, Layout}; +use crate::editor::Editor; use crate::events::{Data, Event, Events}; use crate::params::ParamId; +use crate::plugin::{Host, Plugin, PluginInfo}; +use crate::process::{Block, Config, Processor}; use crate::sync::params::ParamValues; use crate::util::{slice_from_raw_parts_checked, DisplayParam}; -use crate::{Config, Editor, Host, Plugin, PluginInfo, Processor}; fn format_to_speaker_arrangement(format: &Format) -> SpeakerArrangement { match format { diff --git a/src/format/vst3/factory.rs b/src/format/vst3/factory.rs index 0980583..1f5645f 100644 --- a/src/format/vst3/factory.rs +++ b/src/format/vst3/factory.rs @@ -7,8 +7,8 @@ use vst3::{uid, Class, ComWrapper, Steinberg::Vst::*, Steinberg::*}; use super::component::Component; use super::util::copy_wstring; use super::{Uuid, Vst3Info, Vst3Plugin}; +use crate::plugin::{Plugin, PluginInfo}; use crate::util::copy_cstring; -use crate::{Plugin, PluginInfo}; fn uuid_to_tuid(uuid: &Uuid) -> TUID { uid(uuid.0, uuid.1, uuid.2, uuid.3) diff --git a/src/format/vst3/mod.rs b/src/format/vst3/mod.rs index f6f5f50..75d8524 100644 --- a/src/format/vst3/mod.rs +++ b/src/format/vst3/mod.rs @@ -10,7 +10,7 @@ mod factory; mod util; mod view; -use crate::Plugin; +use crate::plugin::Plugin; use factory::Factory; pub struct Uuid(pub u32, pub u32, pub u32, pub u32); diff --git a/src/format/vst3/view.rs b/src/format/vst3/view.rs index d2d4fb7..49abd1f 100644 --- a/src/format/vst3/view.rs +++ b/src/format/vst3/view.rs @@ -5,8 +5,8 @@ use std::sync::Arc; use vst3::{Class, Steinberg::*}; use super::component::MainThreadState; -use crate::parent::{Parent, RawParent}; -use crate::{Editor, Plugin}; +use crate::editor::{Editor, Parent, RawParent}; +use crate::plugin::Plugin; pub struct View { main_thread_state: Arc>>, diff --git a/src/lib.rs b/src/lib.rs index 9dce629..0a78e5e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,76 +1,11 @@ -use std::io::{self, Read, Write}; - -pub mod block; pub mod buffers; pub mod bus; +pub mod editor; pub mod events; pub mod format; pub mod params; -pub mod parent; +pub mod plugin; +pub mod process; mod sync; mod util; - -use block::Block; -use bus::{BusInfo, Layout}; -use params::{ParamId, ParamInfo, ParamValue}; -use parent::Parent; - -pub struct PluginInfo { - pub name: String, - pub version: String, - pub vendor: String, - pub url: String, - pub email: String, - pub buses: Vec, - pub layouts: Vec, - pub params: Vec, -} - -pub struct Host {} - -pub trait Plugin: Send + Sized + 'static { - type Processor: Processor; - type Editor: Editor; - - fn info() -> PluginInfo; - fn new(host: Host) -> Self; - fn set_param(&mut self, id: ParamId, value: ParamValue); - 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(&self, config: Config) -> Self::Processor; - fn editor(&self, parent: Parent) -> Self::Editor; - - #[allow(unused_variables)] - fn latency(&self, config: &Config) -> u64 { - 0 - } -} - -#[derive(Clone)] -pub struct Config { - pub layout: Layout, - pub sample_rate: f64, - pub max_buffer_size: usize, -} - -pub trait Processor: Send + Sized + 'static { - fn set_param(&mut self, id: ParamId, value: ParamValue); - fn reset(&mut self); - fn process(&mut self, block: Block); -} - -pub struct Size { - pub width: f64, - pub height: f64, -} - -pub trait Editor: Sized + 'static { - fn exists() -> bool { - true - } - - fn size(&self) -> Size; - fn set_param(&mut self, id: ParamId, value: ParamValue); -} diff --git a/src/plugin.rs b/src/plugin.rs new file mode 100644 index 0000000..5a61701 --- /dev/null +++ b/src/plugin.rs @@ -0,0 +1,38 @@ +use std::io::{self, Read, Write}; + +use crate::bus::{BusInfo, Layout}; +use crate::editor::{Editor, Parent}; +use crate::params::{ParamId, ParamInfo, ParamValue}; +use crate::process::{Config, Processor}; + +pub struct PluginInfo { + pub name: String, + pub version: String, + pub vendor: String, + pub url: String, + pub email: String, + pub buses: Vec, + pub layouts: Vec, + pub params: Vec, +} + +pub struct Host {} + +pub trait Plugin: Send + Sized + 'static { + type Processor: Processor; + type Editor: Editor; + + fn info() -> PluginInfo; + fn new(host: Host) -> Self; + fn set_param(&mut self, id: ParamId, value: ParamValue); + 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(&self, config: Config) -> Self::Processor; + fn editor(&self, parent: Parent) -> Self::Editor; + + #[allow(unused_variables)] + fn latency(&self, config: &Config) -> u64 { + 0 + } +} diff --git a/src/block.rs b/src/process.rs similarity index 81% rename from src/block.rs rename to src/process.rs index 236709d..1815a26 100644 --- a/src/block.rs +++ b/src/process.rs @@ -1,11 +1,26 @@ use crate::buffers::Buffers; +use crate::bus::Layout; use crate::events::Events; +use crate::params::{ParamId, ParamValue}; + +#[derive(Clone)] +pub struct Config { + pub layout: Layout, + pub sample_rate: f64, + pub max_buffer_size: usize, +} pub struct Block<'a, 'b> { pub buffers: Buffers<'a>, pub events: Events<'b>, } +pub trait Processor: Send + Sized + 'static { + fn set_param(&mut self, id: ParamId, value: ParamValue); + fn reset(&mut self); + fn process(&mut self, block: Block); +} + impl<'a, 'b> Block<'a, 'b> { #[inline] pub fn split_at_events(self) -> SplitAtEvents<'a, 'b> {