From 7eef21b3b90898f4ef05fa4220fde608cf55c6ab Mon Sep 17 00:00:00 2001 From: Graham Northup Date: Sun, 24 Sep 2017 03:41:45 -0400 Subject: parser appears to work (oh my) --- src/synth/square.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/synth/square.rs') diff --git a/src/synth/square.rs b/src/synth/square.rs index 8197110..d207562 100644 --- a/src/synth/square.rs +++ b/src/synth/square.rs @@ -23,7 +23,22 @@ impl Generator for Square { self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0; &self.buf } + fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf } fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer { mem::replace(&mut self.buf, buf) } } + +pub struct SquareFactory; + +impl GeneratorFactory for SquareFactory { + fn new(&self, params: &mut FactoryParameters) -> Result { + Ok(Box::new(Square { + freq: params.remove_param("freq", 0)?.as_gen()?, + phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?, + buf: SampleBuffer::new(params.env.default_buffer_size), + })) + } +} + +pub static Factory: SquareFactory = SquareFactory; -- cgit v1.2.3-70-g09d2