From fee31d223a07afa73a9af5d4367291cdeaecd1ff Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Sun, 17 Mar 2024 22:22:34 -0500 Subject: [PATCH] HostInner trait and backend-specific host structs --- src/format/clap/host.rs | 5 +++++ src/format/clap/instance.rs | 3 ++- src/format/clap/mod.rs | 1 + src/format/vst3/component.rs | 3 ++- src/format/vst3/host.rs | 5 +++++ src/format/vst3/mod.rs | 1 + src/plugin.rs | 14 +++++++++++++- 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/format/clap/host.rs create mode 100644 src/format/vst3/host.rs diff --git a/src/format/clap/host.rs b/src/format/clap/host.rs new file mode 100644 index 0000000..59970ab --- /dev/null +++ b/src/format/clap/host.rs @@ -0,0 +1,5 @@ +use crate::plugin::HostInner; + +pub struct ClapHost {} + +impl HostInner for ClapHost {} diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index 84345ff..fe36a83 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -9,6 +9,7 @@ use std::{io, ptr, slice}; use clap_sys::ext::{audio_ports::*, audio_ports_config::*, gui::*, params::*, state::*}; 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; @@ -122,7 +123,7 @@ impl Instance

{ processor_params: ParamValues::new(&info.params), main_thread_state: UnsafeCell::new(MainThreadState { layout_index: 0, - plugin: P::new(Host {}), + plugin: P::new(Host::from_inner(Arc::new(ClapHost {}))), editor: None, }), process_state: UnsafeCell::new(ProcessState { diff --git a/src/format/clap/mod.rs b/src/format/clap/mod.rs index 829124f..fbce96c 100644 --- a/src/format/clap/mod.rs +++ b/src/format/clap/mod.rs @@ -4,6 +4,7 @@ use clap_sys::{entry::*, version::*}; mod factory; mod gui; +mod host; mod instance; #[doc(hidden)] diff --git a/src/format/vst3/component.rs b/src/format/vst3/component.rs index 53e4561..0255e14 100644 --- a/src/format/vst3/component.rs +++ b/src/format/vst3/component.rs @@ -7,6 +7,7 @@ use std::sync::Arc; 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; use crate::bus::{BusDir, Format, Layout}; @@ -104,7 +105,7 @@ impl Component

{ processor_params: ParamValues::new(&info.params), main_thread_state: Arc::new(UnsafeCell::new(MainThreadState { config: config.clone(), - plugin: P::new(Host {}), + plugin: P::new(Host::from_inner(Arc::new(Vst3Host {}))), editor_params, editor: None, })), diff --git a/src/format/vst3/host.rs b/src/format/vst3/host.rs new file mode 100644 index 0000000..3a18d95 --- /dev/null +++ b/src/format/vst3/host.rs @@ -0,0 +1,5 @@ +use crate::plugin::HostInner; + +pub struct Vst3Host {} + +impl HostInner for Vst3Host {} diff --git a/src/format/vst3/mod.rs b/src/format/vst3/mod.rs index 75d8524..3612703 100644 --- a/src/format/vst3/mod.rs +++ b/src/format/vst3/mod.rs @@ -7,6 +7,7 @@ use vst3::{ComWrapper, Steinberg::IPluginFactory}; mod buffers; mod component; mod factory; +mod host; mod util; mod view; diff --git a/src/plugin.rs b/src/plugin.rs index f549f0b..7e388dd 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,4 +1,5 @@ use std::io::{self, Read, Write}; +use std::sync::Arc; use crate::bus::{BusInfo, Layout}; use crate::editor::{Editor, Parent}; @@ -33,7 +34,18 @@ impl Default for PluginInfo { } } -pub struct Host {} +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;