Skip to content

Commit

Permalink
remove In/Out/InOut structs; impl BindBuffers for Buffer(Mut) directly
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Feb 12, 2024
1 parent 60bfd28 commit 39ab989
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
3 changes: 1 addition & 2 deletions examples/gain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::io::{self, Read, Write};

use serde::{Deserialize, Serialize};

use coupler::buffers::bind::*;
use coupler::format::clap::*;
use coupler::format::vst3::*;
use coupler::{
Expand Down Expand Up @@ -131,7 +130,7 @@ impl Processor for GainProcessor {
}
}

let InOut(mut main) = buffers.bind().unwrap();
let mut main = buffers.bind::<BufferMut>().unwrap();

for i in 0..main.len() {
let gain = self.params.gain.next();
Expand Down
28 changes: 5 additions & 23 deletions src/buffers/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,28 @@ pub trait BindBuffers<'a, 'b>: Sized {
I: Iterator<Item = BufferDir<'a, 'b>>;
}

pub struct In<'a, 'b>(pub Buffer<'a, 'b>);

impl<'a, 'b> BindBuffers<'a, 'b> for In<'a, 'b> {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = BufferDir<'a, 'b>>,
{
match buffers.next() {
Some(BufferDir::In(buffer)) => Some(In(buffer)),
_ => None,
}
}
}

pub struct Out<'a, 'b>(pub BufferMut<'a, 'b>);

impl<'a, 'b> BindBuffers<'a, 'b> for Out<'a, 'b> {
impl<'a, 'b> BindBuffers<'a, 'b> for Buffer<'a, 'b> {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = BufferDir<'a, 'b>>,
{
match buffers.next() {
Some(BufferDir::Out(buffer)) => Some(Out(buffer)),
Some(BufferDir::In(buffer)) => Some(buffer),
_ => None,
}
}
}

pub struct InOut<'a, 'b>(pub BufferMut<'a, 'b>);

impl<'a, 'b> BindBuffers<'a, 'b> for InOut<'a, 'b> {
impl<'a, 'b> BindBuffers<'a, 'b> for BufferMut<'a, 'b> {
#[inline]
fn bind<I>(buffers: &mut I) -> Option<Self>
where
I: Iterator<Item = BufferDir<'a, 'b>>,
{
match buffers.next() {
Some(BufferDir::InOut(buffer)) => Some(InOut(buffer)),
Some(BufferDir::Out(buffer)) => Some(buffer),
Some(BufferDir::InOut(buffer)) => Some(buffer),
_ => None,
}
}
Expand Down

0 comments on commit 39ab989

Please sign in to comment.