-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dispatchers for Graph, Meter and Oscilloscope
- Loading branch information
Showing
10 changed files
with
341 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,44 @@ | ||
// use core::slice; | ||
// use nih_plug::prelude::AtomicF32; | ||
// use std::{ | ||
// iter::{Copied, Map}, | ||
// sync::{atomic::Ordering, Arc}, | ||
// }; | ||
|
||
// use super::*; | ||
|
||
// pub struct IntoMonoBus<const C: usize, D> | ||
// where | ||
// for<'a> D: FnMut([f32; C]) -> f32 + 'static + Copy + Clone, | ||
// { | ||
// dispatchers: DispatcherList<C>, | ||
// sample_rate: Arc<AtomicF32>, | ||
// downmixer: D, | ||
// } | ||
|
||
// impl<const C: usize, D> IntoMonoBus<C, D> | ||
// where | ||
// for<'a> D: FnMut([f32; C]) -> f32 + 'static + Copy + Clone, | ||
// { | ||
// pub fn new(dispatchers: DispatcherList<C>, sample_rate: Arc<AtomicF32>, downmixer: D) -> Self { | ||
// Self { | ||
// dispatchers, | ||
// sample_rate, | ||
// downmixer, | ||
// } | ||
// } | ||
// } | ||
|
||
// impl<const C: usize, D> Bus for IntoMonoBus<C, D> | ||
// where | ||
// for<'a> D: FnMut([f32; C]) -> f32 + 'static + Copy + Clone, | ||
// { | ||
// type Input = f32; | ||
// type InputIter<'a> = slice::Iter<'a, f32>; | ||
// type Output = [f32; C]; | ||
// type OutputIter<'a> = slice::Iter<'a, [f32; C]>; | ||
|
||
// fn set_sample_rate(&self, sample_rate: f32) { | ||
// self.sample_rate.store(sample_rate, Ordering::Relaxed); | ||
// } | ||
|
||
// fn sample_rate(&self) -> f32 { | ||
// self.sample_rate.load(Ordering::Relaxed) | ||
// } | ||
|
||
// fn update(&self) { | ||
// // TODO | ||
// } | ||
|
||
// fn register_dispatcher<F>(&self, action: F) -> Rc<dyn for<'a> Fn(Self::OutputIter<'a>)> | ||
// where | ||
// F: for<'a> Fn(Self::InputIter<'a>) + 'static, | ||
// { | ||
// let mut downmix = self.downmixer.clone(); | ||
|
||
// let dispatcher: Rc<dyn for<'a> Fn(Self::OutputIter<'a>)> = Rc::new(move |data| { | ||
// let mapped = data.copied().map(move |x| downmix(x)).collect::<Vec<_>>(); | ||
// action(mapped.iter()) | ||
// }); | ||
|
||
// self.dispatchers | ||
// .write() | ||
// .unwrap() | ||
// .push(Rc::downgrade(&dispatcher)); | ||
|
||
// dispatcher | ||
// } | ||
// } | ||
use core::slice; | ||
use std::sync::Arc; | ||
|
||
use super::*; | ||
|
||
#[derive(Clone)] | ||
pub struct IntoMonoBus<const C: usize, D> | ||
where | ||
for<'a> D: Fn([f32; C]) -> f32 + 'static + Copy + Clone, | ||
{ | ||
pub(crate) bus: MultiChannelBus<C>, | ||
pub(crate) downmixer: D, | ||
} | ||
|
||
impl<const C: usize, D> Bus<f32> for IntoMonoBus<C, D> | ||
where | ||
for<'a> D: Fn([f32; C]) -> f32 + 'static + Copy + Clone, | ||
{ | ||
type I<'a> = slice::Iter<'a, f32>; | ||
type O<'a> = <MultiChannelBus<C> as Bus<[f32; C]>>::I<'a>; | ||
|
||
fn register_dispatcher<F: for<'a> Fn(Self::I<'a>) + Sync + Send + 'static>( | ||
&self, | ||
dispatcher: F, | ||
) -> Arc<dyn for<'a> Fn(Self::O<'a>) + Sync + Send> { | ||
self.bus.register_dispatcher(move |samples| { | ||
let mono_samples = samples.map(|x| x.into_iter().sum::<f32>() / C as f32); | ||
}) | ||
} | ||
|
||
fn update(&self) { | ||
self.bus.update() | ||
} | ||
|
||
#[inline] | ||
fn set_sample_rate(&self, sample_rate: f32) { | ||
self.bus.set_sample_rate(sample_rate) | ||
} | ||
|
||
#[inline] | ||
fn sample_rate(&self) -> f32 { | ||
self.bus.sample_rate() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
use std::{ | ||
rc::{Rc, Weak}, | ||
sync::{Arc, RwLock}, | ||
}; | ||
use std::sync::Arc; | ||
|
||
mod into_bus; | ||
mod mono; | ||
mod multichannel; | ||
|
||
pub use into_bus::*; | ||
pub use mono::*; | ||
pub use multichannel::*; | ||
|
||
pub type StereoBus = MultiChannelBus<2>; | ||
|
||
pub trait Bus<T: Clone + Copy + Sized + 'static>: Clone { | ||
type I<'a>: Iterator<Item = &'a T>; | ||
type O<'a>: Iterator; | ||
|
||
fn set_sample_rate(&self, sample_rate: f32); | ||
fn sample_rate(&self) -> f32; | ||
fn update(&self); | ||
fn register_dispatcher<F: for<'a> Fn(Self::I<'a>) + Sync + Send + 'static>( | ||
&self, | ||
dispatcher: F, | ||
) -> Arc<dyn for<'a> Fn(Self::I<'a>) + Sync + Send>; | ||
fn update(&self); | ||
fn set_sample_rate(&self, sample_rate: f32); | ||
fn sample_rate(&self) -> f32; | ||
) -> Arc<dyn for<'a> Fn(Self::O<'a>) + Sync + Send>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.