Skip to content

Commit

Permalink
param edit gesture API
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Mar 26, 2024
1 parent 1d38b57 commit 1f9b074
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/format/clap/host.rs
Original file line number Diff line number Diff line change
@@ -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) {}
}
3 changes: 2 additions & 1 deletion src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 2 additions & 1 deletion src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 7 additions & 2 deletions src/format/vst3/host.rs
Original file line number Diff line number Diff line change
@@ -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) {}
}
46 changes: 46 additions & 0 deletions src/host.rs
Original file line number Diff line number Diff line change
@@ -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<dyn HostInner + Send + Sync>,
}

impl Host {
pub fn from_inner(inner: Arc<dyn HostInner + Send + Sync>) -> 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<dyn HostInner + Send + Sync>,
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);
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 1 addition & 14 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -34,19 +34,6 @@ impl Default for PluginInfo {
}
}

pub trait HostInner {}

#[derive(Clone)]
pub struct Host {
_inner: Arc<dyn HostInner>,
}

impl Host {
pub fn from_inner(inner: Arc<dyn HostInner>) -> Host {
Host { _inner: inner }
}
}

pub trait Plugin: Send + Sized + 'static {
type Processor: Processor;
type Editor: Editor;
Expand Down

0 comments on commit 1f9b074

Please sign in to comment.