Quellcode durchsuchen

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

mitchmindtree vor 8 Jahren
Ursprung
Commit
6030fea9f7
1 geänderte Dateien mit 28 neuen und 2 gelöschten Zeilen
  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)
+    }
+}