Skip to content

Commit

Permalink
move Plugin, Processor, and Editor into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Jan 18, 2024
1 parent 1a825df commit e933100
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 81 deletions.
2 changes: 1 addition & 1 deletion examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use coupler::buffers::bind::*;
use coupler::format::clap::*;
use coupler::format::vst3::*;
use coupler::{block::*, bus::*, events::*, params::*, parent::*, *};
use coupler::{bus::*, editor::*, events::*, params::*, plugin::*, process::*};

#[derive(Params, Serialize, Deserialize, Clone)]
struct GainParams {
Expand Down
16 changes: 16 additions & 0 deletions src/parent.rs → src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::ffi::{c_ulong, c_void};

use crate::params::{ParamId, ParamValue};

#[derive(Copy, Clone)]
pub enum RawParent {
Win32(*mut c_void),
Expand All @@ -20,3 +22,17 @@ impl Parent {
self.parent
}
}

pub struct Size {
pub width: f64,
pub height: f64,
}

pub trait Editor: Sized + 'static {
fn exists() -> bool {
true
}

fn size(&self) -> Size;
fn set_param(&mut self, id: ParamId, value: ParamValue);
}
2 changes: 1 addition & 1 deletion src/format/clap/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap_sys::{host::*, plugin::*, plugin_factory::*, version::*};

use super::instance::Instance;
use super::ClapPlugin;
use crate::{Plugin, PluginInfo};
use crate::plugin::{Plugin, PluginInfo};

struct FactoryState {
descriptor: clap_plugin_descriptor,
Expand Down
4 changes: 2 additions & 2 deletions src/format/clap/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use clap_sys::ext::gui::*;
use clap_sys::plugin::*;

use super::instance::Instance;
use crate::parent::{Parent, RawParent};
use crate::{Editor, Plugin};
use crate::editor::{Editor, Parent, RawParent};
use crate::plugin::Plugin;

impl<P: Plugin> Instance<P> {
pub(super) const GUI: clap_plugin_gui = clap_plugin_gui {
Expand Down
5 changes: 3 additions & 2 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use std::{io, ptr, slice};
use clap_sys::ext::{audio_ports::*, audio_ports_config::*, gui::*, params::*, state::*};
use clap_sys::{events::*, id::*, plugin::*, process::*, stream::*};

use crate::block::Block;
use crate::buffers::{Buffers, BusData};
use crate::bus::{BusDir, Format};
use crate::editor::Editor;
use crate::events::{Data, Event, Events};
use crate::params::{ParamId, ParamInfo, ParamValue};
use crate::plugin::{Host, Plugin, PluginInfo};
use crate::process::{Block, Config, Processor};
use crate::sync::params::ParamValues;
use crate::util::{copy_cstring, slice_from_raw_parts_checked, DisplayParam};
use crate::{Config, Editor, Host, Plugin, PluginInfo, Processor};

fn port_type_from_format(format: &Format) -> &'static CStr {
match format {
Expand Down
2 changes: 1 addition & 1 deletion src/format/vst3/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use vst3::Steinberg::Vst::ProcessData;

use crate::buffers::{Buffers, BusData};
use crate::bus::{BusDir, BusInfo};
use crate::process::Config;
use crate::util::slice_from_raw_parts_checked;
use crate::Config;

pub struct ScratchBuffers {
inputs_active: Vec<bool>,
Expand Down
5 changes: 3 additions & 2 deletions src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use vst3::{Class, ComRef, ComWrapper, Steinberg::Vst::*, Steinberg::*};
use super::buffers::ScratchBuffers;
use super::util::{copy_wstring, utf16_from_ptr};
use super::view::View;
use crate::block::Block;
use crate::bus::{BusDir, Format, Layout};
use crate::editor::Editor;
use crate::events::{Data, Event, Events};
use crate::params::ParamId;
use crate::plugin::{Host, Plugin, PluginInfo};
use crate::process::{Block, Config, Processor};
use crate::sync::params::ParamValues;
use crate::util::{slice_from_raw_parts_checked, DisplayParam};
use crate::{Config, Editor, Host, Plugin, PluginInfo, Processor};

fn format_to_speaker_arrangement(format: &Format) -> SpeakerArrangement {
match format {
Expand Down
2 changes: 1 addition & 1 deletion src/format/vst3/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use vst3::{uid, Class, ComWrapper, Steinberg::Vst::*, Steinberg::*};
use super::component::Component;
use super::util::copy_wstring;
use super::{Uuid, Vst3Info, Vst3Plugin};
use crate::plugin::{Plugin, PluginInfo};
use crate::util::copy_cstring;
use crate::{Plugin, PluginInfo};

fn uuid_to_tuid(uuid: &Uuid) -> TUID {
uid(uuid.0, uuid.1, uuid.2, uuid.3)
Expand Down
2 changes: 1 addition & 1 deletion src/format/vst3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod factory;
mod util;
mod view;

use crate::Plugin;
use crate::plugin::Plugin;
use factory::Factory;

pub struct Uuid(pub u32, pub u32, pub u32, pub u32);
Expand Down
4 changes: 2 additions & 2 deletions src/format/vst3/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::sync::Arc;
use vst3::{Class, Steinberg::*};

use super::component::MainThreadState;
use crate::parent::{Parent, RawParent};
use crate::{Editor, Plugin};
use crate::editor::{Editor, Parent, RawParent};
use crate::plugin::Plugin;

pub struct View<P: Plugin> {
main_thread_state: Arc<UnsafeCell<MainThreadState<P>>>,
Expand Down
71 changes: 3 additions & 68 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,76 +1,11 @@
use std::io::{self, Read, Write};

pub mod block;
pub mod buffers;
pub mod bus;
pub mod editor;
pub mod events;
pub mod format;
pub mod params;
pub mod parent;
pub mod plugin;
pub mod process;

mod sync;
mod util;

use block::Block;
use bus::{BusInfo, Layout};
use params::{ParamId, ParamInfo, ParamValue};
use parent::Parent;

pub struct PluginInfo {
pub name: String,
pub version: String,
pub vendor: String,
pub url: String,
pub email: String,
pub buses: Vec<BusInfo>,
pub layouts: Vec<Layout>,
pub params: Vec<ParamInfo>,
}

pub struct Host {}

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

fn info() -> PluginInfo;
fn new(host: Host) -> Self;
fn set_param(&mut self, id: ParamId, value: ParamValue);
fn get_param(&self, id: ParamId) -> ParamValue;
fn save(&self, output: &mut impl Write) -> io::Result<()>;
fn load(&mut self, input: &mut impl Read) -> io::Result<()>;
fn processor(&self, config: Config) -> Self::Processor;
fn editor(&self, parent: Parent) -> Self::Editor;

#[allow(unused_variables)]
fn latency(&self, config: &Config) -> u64 {
0
}
}

#[derive(Clone)]
pub struct Config {
pub layout: Layout,
pub sample_rate: f64,
pub max_buffer_size: usize,
}

pub trait Processor: Send + Sized + 'static {
fn set_param(&mut self, id: ParamId, value: ParamValue);
fn reset(&mut self);
fn process(&mut self, block: Block);
}

pub struct Size {
pub width: f64,
pub height: f64,
}

pub trait Editor: Sized + 'static {
fn exists() -> bool {
true
}

fn size(&self) -> Size;
fn set_param(&mut self, id: ParamId, value: ParamValue);
}
38 changes: 38 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::io::{self, Read, Write};

use crate::bus::{BusInfo, Layout};
use crate::editor::{Editor, Parent};
use crate::params::{ParamId, ParamInfo, ParamValue};
use crate::process::{Config, Processor};

pub struct PluginInfo {
pub name: String,
pub version: String,
pub vendor: String,
pub url: String,
pub email: String,
pub buses: Vec<BusInfo>,
pub layouts: Vec<Layout>,
pub params: Vec<ParamInfo>,
}

pub struct Host {}

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

fn info() -> PluginInfo;
fn new(host: Host) -> Self;
fn set_param(&mut self, id: ParamId, value: ParamValue);
fn get_param(&self, id: ParamId) -> ParamValue;
fn save(&self, output: &mut impl Write) -> io::Result<()>;
fn load(&mut self, input: &mut impl Read) -> io::Result<()>;
fn processor(&self, config: Config) -> Self::Processor;
fn editor(&self, parent: Parent) -> Self::Editor;

#[allow(unused_variables)]
fn latency(&self, config: &Config) -> u64 {
0
}
}
15 changes: 15 additions & 0 deletions src/block.rs → src/process.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use crate::buffers::Buffers;
use crate::bus::Layout;
use crate::events::Events;
use crate::params::{ParamId, ParamValue};

#[derive(Clone)]
pub struct Config {
pub layout: Layout,
pub sample_rate: f64,
pub max_buffer_size: usize,
}

pub struct Block<'a, 'b> {
pub buffers: Buffers<'a>,
pub events: Events<'b>,
}

pub trait Processor: Send + Sized + 'static {
fn set_param(&mut self, id: ParamId, value: ParamValue);
fn reset(&mut self);
fn process(&mut self, block: Block);
}

impl<'a, 'b> Block<'a, 'b> {
#[inline]
pub fn split_at_events(self) -> SplitAtEvents<'a, 'b> {
Expand Down

0 comments on commit e933100

Please sign in to comment.