Commit 26be1c4f authored by sheldon_knuth's avatar sheldon_knuth

plantuml test

parent d4186992
use std::cell::*;
use controller::Knob;
use base::{Frequency, Duration, SignalGenerator, SoundModule};
pub const CHUNK_SIZE: usize = 4096;
pub struct MonoStateContainer<T: Copy> {
knob: Knob<T>,
output_time: Duration,
output: RefCell<Vec<f32>>,
state: RefCell<T>
}
impl<T: Copy> SignalGenerator for MonoStateContainer<T> where
T: SignalGenerator<Output = Frequency>
{
type Output = f32;
pub fn new(knob: Knob<f32>, state: T) -> Self {
Self {
knob: knob,
output_time: Duration::to_seconds(0.0),
output: RefCell::new(vec![0.0; CHUNK_SIZE]),
state: RefCell::new(state)
}
}
pub fn time(&self) -> f32 {
self.knob.get()
}
pub fn clock_advanced(&self) -> bool {
self.output_time.from_seconds() != self.knob.get()
}
pub fn borrow_output(&self) -> Ref<Vec<f32>> {
self.output.borrow()
}
pub fn borrow_to_modify(&self) -> RefMut<Vec<f32>> {
self.output.borrow_mut()
}
pub fn borrow_state_mut(&self) -> RefMut<T> {
self.state.borrow_mut()
}
}
pub trait MonoEmitter {
// The returned Ref must go out of scope before this fn can be called again.
fn output(&self) -> Ref<Vec<f32>>;
}
pub struct StereoStateContainer<T> {
knob: Knob<T>,
left: RefCell<Vec<f32>>,
right: RefCell<Vec<f32>>,
state: RefCell<T>
}
impl<T> StereoStateContainer<T> {
pub fn new(knob: Knob<T>, state: T) -> Self {
Self {
knob: knob,
left: RefCell::new(vec![0.0; CHUNK_SIZE]),
right: RefCell::new(vec![0.0; CHUNK_SIZE]),
state: RefCell::new(state)
}
}
pub fn time(&self) -> T {
self.knob.get()
}
pub fn borrow_output(&self) -> (Ref<Vec<f32>>, Ref<Vec<f32>>) {
(self.left.borrow(),
self.right.borrow())
}
pub fn borrow_to_modify(&self) -> (RefMut<Vec<f32>>, RefMut<Vec<f32>>) {
(self.left.borrow_mut(),
self.right.borrow_mut())
}
pub fn borrow_state_mut(&self) -> RefMut<T> {
self.state.borrow_mut()
}
}
pub trait StereoEmitter {
fn output(&self) -> (Ref<Vec<f32>>, Ref<Vec<f32>>);
}
[plantuml, format="png", id="myDiagram", width="200px"]
--
Bob -> Alice : hello
Alice -> Bob : hi
--
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment