summaryrefslogtreecommitdiff
path: root/src/synth/triangle.rs
diff options
context:
space:
mode:
authorGraham Northup <grissess@nexusg.org>2017-09-24 03:41:45 -0400
committerGraham Northup <grissess@nexusg.org>2017-09-24 03:41:45 -0400
commit7eef21b3b90898f4ef05fa4220fde608cf55c6ab (patch)
treedb09a752bef57a5b6eb6040048ed1fdf66ab5043 /src/synth/triangle.rs
parent3d370b9a980d88f884ddd87b62bc785c3b963e1d (diff)
parser appears to work (oh my)
Diffstat (limited to 'src/synth/triangle.rs')
-rw-r--r--src/synth/triangle.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/synth/triangle.rs b/src/synth/triangle.rs
index 5c0c69a..4f62e4c 100644
--- a/src/synth/triangle.rs
+++ b/src/synth/triangle.rs
@@ -27,7 +27,22 @@ impl Generator for Triangle {
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 TriangleFactory;
+
+impl GeneratorFactory for TriangleFactory {
+ fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
+ Ok(Box::new(Triangle {
+ 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: TriangleFactory = TriangleFactory;