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/logic.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/synth/logic.rs') diff --git a/src/synth/logic.rs b/src/synth/logic.rs index 5071d95..672cc78 100644 --- a/src/synth/logic.rs +++ b/src/synth/logic.rs @@ -15,11 +15,11 @@ impl Generator for IfElse { let iftrue_buf = self.iftrue.eval(params); let iffalse_buf = self.iffalse.eval(params); - if ( + if cond_buf.rate == Rate::Control && iftrue_buf.rate == Rate::Control && iffalse_buf.rate == Rate::Control - ) { + { self.buf.set(if cond_buf.first() >= 0.5 { iftrue_buf.first() } else { @@ -57,7 +57,22 @@ impl Generator for IfElse { &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 IfElseFactory; + +impl GeneratorFactory for IfElseFactory { + fn new(&self, params: &mut FactoryParameters) -> Result { + let cond = params.remove_param("cond", 0)?.as_gen()?; + let iftrue = params.remove_param("iftrue", 1)?.as_gen()?; + let iffalse = params.remove_param("iffalse", 2)?.as_gen()?; + let buf = SampleBuffer::new(cmp::max(cmp::max(cond.buffer().len(), iftrue.buffer().len()), iffalse.buffer().len())); + Ok(Box::new(IfElse { cond: cond, iftrue: iftrue, iffalse: iffalse, buf: buf })) + } +} + +pub static Factory: IfElseFactory = IfElseFactory; -- cgit v1.2.3-70-g09d2