Explorar el Código

Add helper constructors for dynamic Sampler types to the dynamic module.

mitchmindtree hace 8 años
padre
commit
6030fea9f7
Se han modificado 1 ficheros con 28 adiciones y 2 borrados
  1. 28 2
      src/dynamic.rs

+ 28 - 2
src/dynamic.rs

@@ -1,6 +1,32 @@
 use instrument;
+use map;
 use sampler;
 
 /// An alias for a `Sampler` type that uses a dynamic instrument and note frequency mode.
-pub type Sampler<F> =
-    sampler::Sampler<instrument::mode::Dynamic, instrument::note_freq::DynamicGenerator, F>;
+pub type Sampler<A> =
+    sampler::Sampler<instrument::mode::Dynamic, instrument::note_freq::DynamicGenerator, A>;
+
+impl<A> Sampler<A>
+    where A: map::Audio,
+{
+    /// Construct a dynamic `Sampler`.
+    pub fn dynamic(mode: instrument::mode::Dynamic, map: map::Map<A>) -> Self {
+        let nfg = instrument::note_freq::DynamicGenerator::Constant;
+        Self::new(mode, nfg, map)
+    }
+
+    /// Construct a dynamic `Sampler` initialised with a `Mono::Legato` playback mode.
+    pub fn dynamic_legato(map: map::Map<A>) -> Self {
+        Self::dynamic(instrument::mode::Dynamic::legato(), map)
+    }
+
+    /// Construct a dynamic `Sampler` initialised with a `Mono::Retrigger` playback mode.
+    pub fn dynamic_retrigger(map: map::Map<A>) -> Self {
+        Self::dynamic(instrument::mode::Dynamic::retrigger(), map)
+    }
+
+    /// Construct a dynamic `Sampler` initialised with a `Poly` playback mode.
+    pub fn dynamic_poly(map: map::Map<A>) -> Self {
+        Self::dynamic(instrument::mode::Dynamic::poly(), map)
+    }
+}