diff --git a/examples/gain/src/lib.rs b/examples/gain/src/lib.rs index 1c2a453..42d6af9 100644 --- a/examples/gain/src/lib.rs +++ b/examples/gain/src/lib.rs @@ -6,7 +6,9 @@ use portlight::{App, AppMode, AppOptions, Response, Window, WindowOptions}; use coupler::format::clap::*; use coupler::format::vst3::*; -use coupler::{buffers::*, bus::*, editor::*, events::*, params::*, plugin::*, process::*}; +use coupler::{ + buffers::*, bus::*, editor::*, events::*, host::*, params::*, plugin::*, process::*, +}; #[derive(Params, Serialize, Deserialize, Clone)] struct GainParams { diff --git a/src/format/clap/host.rs b/src/format/clap/host.rs index 59970ab..58c4f87 100644 --- a/src/format/clap/host.rs +++ b/src/format/clap/host.rs @@ -1,5 +1,10 @@ -use crate::plugin::HostInner; +use crate::host::HostInner; +use crate::params::{ParamId, ParamValue}; pub struct ClapHost {} -impl HostInner for ClapHost {} +impl HostInner for ClapHost { + fn begin_gesture(&self, _id: ParamId) {} + fn end_gesture(&self, _id: ParamId) {} + fn set_param(&self, _id: ParamId, _value: ParamValue) {} +} diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index fe36a83..4443017 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -14,8 +14,9 @@ use crate::buffers::{BufferData, BufferType, Buffers}; use crate::bus::{BusDir, Format}; use crate::editor::Editor; use crate::events::{Data, Event, Events}; +use crate::host::Host; use crate::params::{ParamId, ParamInfo, ParamValue}; -use crate::plugin::{Host, Plugin, PluginInfo}; +use crate::plugin::{Plugin, PluginInfo}; use crate::process::{Config, Processor}; use crate::sync::params::ParamValues; use crate::util::{copy_cstring, slice_from_raw_parts_checked, DisplayParam}; diff --git a/src/format/vst3/component.rs b/src/format/vst3/component.rs index 0255e14..2640159 100644 --- a/src/format/vst3/component.rs +++ b/src/format/vst3/component.rs @@ -13,8 +13,9 @@ use super::view::View; use crate::bus::{BusDir, Format, Layout}; use crate::editor::Editor; use crate::events::{Data, Event, Events}; +use crate::host::Host; use crate::params::ParamId; -use crate::plugin::{Host, Plugin, PluginInfo}; +use crate::plugin::{Plugin, PluginInfo}; use crate::process::{Config, Processor}; use crate::sync::params::ParamValues; use crate::util::{slice_from_raw_parts_checked, DisplayParam}; diff --git a/src/format/vst3/host.rs b/src/format/vst3/host.rs index 3a18d95..d5eeef8 100644 --- a/src/format/vst3/host.rs +++ b/src/format/vst3/host.rs @@ -1,5 +1,10 @@ -use crate::plugin::HostInner; +use crate::host::HostInner; +use crate::params::{ParamId, ParamValue}; pub struct Vst3Host {} -impl HostInner for Vst3Host {} +impl HostInner for Vst3Host { + fn begin_gesture(&self, _id: ParamId) {} + fn end_gesture(&self, _id: ParamId) {} + fn set_param(&self, _id: ParamId, _value: ParamValue) {} +} diff --git a/src/host.rs b/src/host.rs new file mode 100644 index 0000000..8ee5278 --- /dev/null +++ b/src/host.rs @@ -0,0 +1,46 @@ +use std::sync::Arc; + +use crate::params::{ParamId, ParamValue}; + +pub trait HostInner { + fn begin_gesture(&self, id: ParamId); + fn end_gesture(&self, id: ParamId); + fn set_param(&self, id: ParamId, value: ParamValue); +} + +#[derive(Clone)] +pub struct Host { + inner: Arc, +} + +impl Host { + pub fn from_inner(inner: Arc) -> Host { + Host { inner } + } + + pub fn edit_param(&self, id: ParamId) -> Gesture { + self.inner.begin_gesture(id); + + Gesture { + inner: Arc::clone(&self.inner), + id, + } + } +} + +pub struct Gesture { + inner: Arc, + id: ParamId, +} + +impl Gesture { + pub fn set_value(&self, value: ParamValue) { + self.inner.set_param(self.id, value); + } +} + +impl Drop for Gesture { + fn drop(&mut self) { + self.inner.end_gesture(self.id); + } +} diff --git a/src/lib.rs b/src/lib.rs index 0a78e5e..dc9583d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ pub mod bus; pub mod editor; pub mod events; pub mod format; +pub mod host; pub mod params; pub mod plugin; pub mod process; diff --git a/src/plugin.rs b/src/plugin.rs index 363b7f6..8a346fe 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,8 +1,8 @@ use std::io::{self, Read, Write}; -use std::sync::Arc; use crate::bus::{BusInfo, Layout}; use crate::editor::{Editor, Parent}; +use crate::host::Host; use crate::params::{ParamId, ParamInfo, ParamValue}; use crate::process::{Config, Processor}; @@ -34,19 +34,6 @@ impl Default for PluginInfo { } } -pub trait HostInner {} - -#[derive(Clone)] -pub struct Host { - _inner: Arc, -} - -impl Host { - pub fn from_inner(inner: Arc) -> Host { - Host { _inner: inner } - } -} - pub trait Plugin: Send + Sized + 'static { type Processor: Processor; type Editor: Editor;