summaryrefslogtreecommitdiff
path: root/src/synth
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2017-09-24 09:18:26 -0400
committerGraham Northup <grahamnorthup@yahoo.com>2017-09-24 19:01:22 -0400
commit150d71cae770598ade7e09419150f1218e961128 (patch)
treea1b0848642fa59f746d9e4587e585a22df0188e2 /src/synth
parent5f1e73ab5bd0709dd408064c06f2717182777537 (diff)
Fix more style things
All reported by clippy. Mostly stuff like unnecessary lifetimes or references.
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/logic.rs8
-rw-r--r--src/synth/math.rs16
-rw-r--r--src/synth/mod.rs16
-rw-r--r--src/synth/noise.rs2
-rw-r--r--src/synth/param.rs2
-rw-r--r--src/synth/rel.rs20
-rw-r--r--src/synth/saw.rs4
-rw-r--r--src/synth/sine.rs4
-rw-r--r--src/synth/square.rs4
-rw-r--r--src/synth/triangle.rs4
10 files changed, 40 insertions, 40 deletions
diff --git a/src/synth/logic.rs b/src/synth/logic.rs
index 672cc78..d5f9401 100644
--- a/src/synth/logic.rs
+++ b/src/synth/logic.rs
@@ -57,7 +57,7 @@ impl Generator for IfElse {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -67,9 +67,9 @@ 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 cond = params.remove_param("cond", 0)?.into_gen()?;
+ let iftrue = params.remove_param("iftrue", 1)?.into_gen()?;
+ let iffalse = params.remove_param("iffalse", 2)?.into_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 }))
}
diff --git a/src/synth/math.rs b/src/synth/math.rs
index 2b81786..1889139 100644
--- a/src/synth/math.rs
+++ b/src/synth/math.rs
@@ -20,7 +20,7 @@ impl Generator for Add {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -31,7 +31,7 @@ pub struct AddFactory;
impl GeneratorFactory for AddFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Add {
- terms: params.get_pos_params().into_iter().map(|x| x.as_gen()).collect::<Result<Vec<_>, _>>()?,
+ terms: params.get_pos_params().into_iter().map(|x| x.into_gen()).collect::<Result<Vec<_>, _>>()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
}
@@ -58,7 +58,7 @@ impl Generator for Mul {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -69,7 +69,7 @@ pub struct MulFactory;
impl GeneratorFactory for MulFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Mul {
- factors: params.get_pos_params().into_iter().map(|x| x.as_gen()).collect::<Result<Vec<_>, _>>()?,
+ factors: params.get_pos_params().into_iter().map(|x| x.into_gen()).collect::<Result<Vec<_>, _>>()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
}
@@ -98,7 +98,7 @@ impl Generator for Negate {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -108,7 +108,7 @@ pub struct NegateFactory;
impl GeneratorFactory for NegateFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let gen = params.remove_param("value", 0)?.as_gen()?;
+ let gen = params.remove_param("value", 0)?.into_gen()?;
let len = gen.buffer().len();
Ok(Box::new(Negate {
value: gen,
@@ -140,7 +140,7 @@ impl Generator for Reciprocate {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -150,7 +150,7 @@ pub struct ReciprocateFactory;
impl GeneratorFactory for ReciprocateFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let gen = params.remove_param("value", 0)?.as_gen()?;
+ let gen = params.remove_param("value", 0)?.into_gen()?;
let len = gen.buffer().len();
Ok(Box::new(Reciprocate {
value: gen,
diff --git a/src/synth/mod.rs b/src/synth/mod.rs
index fb9714b..e8d1758 100644
--- a/src/synth/mod.rs
+++ b/src/synth/mod.rs
@@ -63,7 +63,7 @@ impl SampleBuffer {
self.samples.len()
}
- pub fn iter_mut<'a>(&'a mut self) -> slice::IterMut<'a, f32> {
+ pub fn iter_mut(&mut self) -> slice::IterMut<f32> {
self.samples.iter_mut()
}
@@ -160,7 +160,7 @@ impl IndexMut<usize> for SampleBuffer {
pub trait Generator : Debug {
fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer;
- fn buffer<'a>(&'a self) -> &'a SampleBuffer;
+ fn buffer(&self) -> &SampleBuffer;
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer;
}
@@ -186,10 +186,10 @@ impl GenFactoryErrorType {
desc: "".to_string(),
};
- ret.desc = match &ret.kind {
- &GenFactoryError::MissingRequiredParam(ref name, pos) => format!("Needed a parameter named {} or at pos {}", name, pos),
- &GenFactoryError::CannotConvert(from, to) => format!("Cannot convert {:?} to {:?}", from, to),
- &GenFactoryError::BadType(ty) => format!("Bad parameter type {:?}", ty),
+ ret.desc = match ret.kind {
+ GenFactoryError::MissingRequiredParam(ref name, pos) => format!("Needed a parameter named {} or at pos {}", name, pos),
+ GenFactoryError::CannotConvert(from, to) => format!("Cannot convert {:?} to {:?}", from, to),
+ GenFactoryError::BadType(ty) => format!("Bad parameter type {:?}", ty),
};
ret
@@ -210,7 +210,7 @@ impl From<GenFactoryError> for GenFactoryErrorType {
}
impl Error for GenFactoryErrorType {
- fn description<'a>(&'a self) -> &'a str {
+ fn description(&self) -> &str {
&self.desc
}
}
@@ -279,7 +279,7 @@ impl ParamValue {
}
}
- pub fn as_gen(self) -> Result<GenBox, GenFactoryError> {
+ pub fn into_gen(self) -> Result<GenBox, GenFactoryError> {
match self {
ParamValue::Integer(v) => Ok(Box::new(self::param::Param { name : "_".to_string(), default: v as f32, buf: SampleBuffer::new(1) })),
ParamValue::Float(v) => Ok(Box::new(self::param::Param { name : "_".to_string(), default: v, buf: SampleBuffer::new(1) })),
diff --git a/src/synth/noise.rs b/src/synth/noise.rs
index f241beb..850b75b 100644
--- a/src/synth/noise.rs
+++ b/src/synth/noise.rs
@@ -19,7 +19,7 @@ impl Generator for Noise {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
diff --git a/src/synth/param.rs b/src/synth/param.rs
index 859f789..b020574 100644
--- a/src/synth/param.rs
+++ b/src/synth/param.rs
@@ -12,7 +12,7 @@ impl Generator for Param {
self.buf.set(*params.vars.get(&self.name).unwrap_or(&self.default));
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
diff --git a/src/synth/rel.rs b/src/synth/rel.rs
index bb3cf1f..e3c4216 100644
--- a/src/synth/rel.rs
+++ b/src/synth/rel.rs
@@ -105,7 +105,7 @@ impl Generator for Rel {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -115,18 +115,18 @@ pub struct RelFactory;
impl GeneratorFactory for RelFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let op = match params.get_req_param("rel", 1)? {
+ let op = match *params.get_req_param("rel", 1)? {
/* TODO
- &ParamValue::Integer(v) => v.into(),
- &ParamValue::Float(v) => (v as isize).into(),
+ ParamValue::Integer(v) => v.into(),
+ ParamValue::Float(v) => (v as isize).into(),
*/
- &ParamValue::Integer(_) => return Err(GenFactoryError::BadType(ParamKind::Integer)),
- &ParamValue::Float(_) => return Err(GenFactoryError::BadType(ParamKind::Float)),
- &ParamValue::String(ref v) => (&*v as &str).into(),
- &ParamValue::Generator(_) => return Err(GenFactoryError::BadType(ParamKind::Generator)),
+ ParamValue::Integer(_) => return Err(GenFactoryError::BadType(ParamKind::Integer)),
+ ParamValue::Float(_) => return Err(GenFactoryError::BadType(ParamKind::Float)),
+ ParamValue::String(ref v) => (&*v as &str).into(),
+ ParamValue::Generator(_) => return Err(GenFactoryError::BadType(ParamKind::Generator)),
};
- let left = params.remove_param("left", 0)?.as_gen()?;
- let right = params.remove_param("right", 2)?.as_gen()?;
+ let left = params.remove_param("left", 0)?.into_gen()?;
+ let right = params.remove_param("right", 2)?.into_gen()?;
let buf = SampleBuffer::new(cmp::max(left.buffer().len(), right.buffer().len()));
Ok(Box::new(Rel {
left: left,
diff --git a/src/synth/saw.rs b/src/synth/saw.rs
index b85794d..054b3c8 100644
--- a/src/synth/saw.rs
+++ b/src/synth/saw.rs
@@ -19,7 +19,7 @@ impl Generator for Saw {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -30,7 +30,7 @@ pub struct SawFactory;
impl GeneratorFactory for SawFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Saw {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/sine.rs b/src/synth/sine.rs
index 918261c..66f29ef 100644
--- a/src/synth/sine.rs
+++ b/src/synth/sine.rs
@@ -22,7 +22,7 @@ impl Generator for Sine {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % TAU;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -33,7 +33,7 @@ pub struct SineFactory;
impl GeneratorFactory for SineFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Sine {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/square.rs b/src/synth/square.rs
index d207562..9b4374f 100644
--- a/src/synth/square.rs
+++ b/src/synth/square.rs
@@ -23,7 +23,7 @@ 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 buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -34,7 +34,7 @@ pub struct SquareFactory;
impl GeneratorFactory for SquareFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Square {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/triangle.rs b/src/synth/triangle.rs
index 4f62e4c..19a2296 100644
--- a/src/synth/triangle.rs
+++ b/src/synth/triangle.rs
@@ -27,7 +27,7 @@ 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 buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -38,7 +38,7 @@ 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()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))