Skip to content

Commit

Permalink
pass a single Block struct containing Buffers and Events to process()
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Jan 15, 2024
1 parent f469bbb commit 21c049d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
8 changes: 4 additions & 4 deletions examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use coupler::format::clap::*;
use coupler::format::vst3::*;
use coupler::{buffers::*, bus::*, events::*, params::*, parent::*, *};
use coupler::{block::*, buffers::*, bus::*, events::*, params::*, parent::*, *};

#[derive(Params, Serialize, Deserialize, Clone)]
struct GainParams {
Expand Down Expand Up @@ -113,8 +113,8 @@ impl Processor for GainProcessor {

fn reset(&mut self) {}

fn process(&mut self, mut buffers: Buffers, events: Events) {
for event in events {
fn process(&mut self, mut block: Block) {
for event in block.events {
match event.data {
Data::ParamChange { id, value } => {
self.params.set_param(id, value);
Expand All @@ -123,7 +123,7 @@ impl Processor for GainProcessor {
}
}

let Some(BufferDir::InOut(mut main)) = buffers.get(0) else {
let Some(BufferDir::InOut(mut main)) = block.buffers.get(0) else {
unreachable!();
};

Expand Down
7 changes: 7 additions & 0 deletions src/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::buffers::Buffers;
use crate::events::Events;

pub struct Block<'a, 'b, 'c> {
pub buffers: Buffers<'a, 'b>,
pub events: Events<'c>,
}
9 changes: 5 additions & 4 deletions 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::*, id::*, plugin::*, process::*, stream::*};

use crate::block::Block;
use crate::buffers::{Buffers, BusData};
use crate::bus::{BusDir, Format};
use crate::events::{Data, Event, Events};
Expand Down Expand Up @@ -308,10 +309,10 @@ impl<P: Plugin> Instance<P> {
}

instance.sync_processor(processor);
processor.process(
Buffers::from_raw_parts(&process_state.buses, &process_state.buffer_ptrs, len),
Events::new(&process_state.events),
);
processor.process(Block {
buffers: Buffers::from_raw_parts(&process_state.buses, &process_state.buffer_ptrs, len),
events: Events::new(&process_state.events),
});

CLAP_PROCESS_CONTINUE
}
Expand Down
6 changes: 5 additions & 1 deletion src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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::events::{Data, Event, Events};
use crate::sync::params::ParamValues;
Expand Down Expand Up @@ -518,7 +519,10 @@ impl<P: Plugin> IAudioProcessorTrait for Component<P> {
}

self.sync_processor(processor);
processor.process(buffers, Events::new(&process_state.events));
processor.process(Block {
buffers,
events: Events::new(&process_state.events),
});

kResultOk
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::io::{self, Read, Write};

pub mod block;
pub mod buffers;
pub mod bus;
pub mod events;
Expand All @@ -10,9 +11,8 @@ pub mod parent;
mod sync;
mod util;

use buffers::Buffers;
use block::Block;
use bus::{BusInfo, Layout};
use events::Events;
use params::ParamInfo;
use parent::Parent;

Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct Config {
pub trait Processor: Send + Sized + 'static {
fn set_param(&mut self, id: ParamId, value: ParamValue);
fn reset(&mut self);
fn process(&mut self, buffers: Buffers, events: Events);
fn process(&mut self, block: Block);
}

pub struct Size {
Expand Down

0 comments on commit 21c049d

Please sign in to comment.