From 1f9b074d804d0c89c1d288718931978ae4617e8b Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Tue, 26 Mar 2024 11:29:23 -0500 Subject: [PATCH] param edit gesture API --- src/format/clap/host.rs | 9 +++++-- src/format/clap/instance.rs | 3 ++- src/format/vst3/component.rs | 3 ++- src/format/vst3/host.rs | 9 +++++-- src/host.rs | 46 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/plugin.rs | 15 +----------- 7 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 src/host.rs diff --git a/src/format/clap/host.rs b/src/format/clap/host.rs index 59970ab..bb440c7 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..b93a5ed 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..bc396b1 --- /dev/null +++ b/src/host.rs @@ -0,0 +1,46 @@ +use std::sync::Arc; + +use crate::params::{ParamId, ParamInfo, 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;