Skip to content

Commit

Permalink
HostInner trait and backend-specific host structs
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Mar 18, 2024
1 parent 8ce9b1b commit fee31d2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/format/clap/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::plugin::HostInner;

pub struct ClapHost {}

impl HostInner for ClapHost {}
3 changes: 2 additions & 1 deletion src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,7 +123,7 @@ impl<P: Plugin> Instance<P> {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/format/clap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap_sys::{entry::*, version::*};

mod factory;
mod gui;
mod host;
mod instance;

#[doc(hidden)]
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 @@ -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};
Expand Down Expand Up @@ -104,7 +105,7 @@ impl<P: Plugin> Component<P> {
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,
})),
Expand Down
5 changes: 5 additions & 0 deletions src/format/vst3/host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::plugin::HostInner;

pub struct Vst3Host {}

impl HostInner for Vst3Host {}
1 change: 1 addition & 0 deletions src/format/vst3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use vst3::{ComWrapper, Steinberg::IPluginFactory};
mod buffers;
mod component;
mod factory;
mod host;
mod util;
mod view;

Expand Down
14 changes: 13 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{self, Read, Write};
use std::sync::Arc;

use crate::bus::{BusInfo, Layout};
use crate::editor::{Editor, Parent};
Expand Down Expand Up @@ -33,7 +34,18 @@ impl Default for PluginInfo {
}
}

pub struct Host {}
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;
Expand Down

0 comments on commit fee31d2

Please sign in to comment.