diff options
author | Graham Northup <grissess@nexusg.org> | 2017-09-24 03:41:45 -0400 |
---|---|---|
committer | Graham Northup <grissess@nexusg.org> | 2017-09-24 03:41:45 -0400 |
commit | 7eef21b3b90898f4ef05fa4220fde608cf55c6ab (patch) | |
tree | db09a752bef57a5b6eb6040048ed1fdf66ab5043 /src/synth/logic.rs | |
parent | 3d370b9a980d88f884ddd87b62bc785c3b963e1d (diff) |
parser appears to work (oh my)
Diffstat (limited to 'src/synth/logic.rs')
-rw-r--r-- | src/synth/logic.rs | 19 |
1 files changed, 17 insertions, 2 deletions
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<GenBox, GenFactoryError> { + 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; |