summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2021-12-03 12:56:05 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2021-12-03 12:56:05 -0600
commita014949e2c7fa4c8bc02e3a54a74ae3727924076 (patch)
treefa2f12a09587e424101ae979f9aef67e22446f35
parent1e64d804eda19f52b998f81a2d7fd1fc699f271d (diff)
Add: partial hooking up Instrument in place of Osc
-rw-r--r--klangfarbrs/src/instrument.rs9
-rw-r--r--klangfarbrs/src/lib.rs5
2 files changed, 12 insertions, 2 deletions
diff --git a/klangfarbrs/src/instrument.rs b/klangfarbrs/src/instrument.rs
index 3a929af..65da6b6 100644
--- a/klangfarbrs/src/instrument.rs
+++ b/klangfarbrs/src/instrument.rs
@@ -5,6 +5,15 @@ struct Instrument {
envelope: Envelope,
}
+impl Instrument {
+ pub fn sample(&mut self) -> Sample {
+ match self.next() {
+ Some(s) => { s },
+ None => 0.0
+ }
+ }
+}
+
impl Iterator for Instrument {
type Item = Sample;
diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs
index 51f0c91..753f211 100644
--- a/klangfarbrs/src/lib.rs
+++ b/klangfarbrs/src/lib.rs
@@ -23,6 +23,7 @@ pub mod envelope;
use envelope::Envelope;
mod instrument;
+use instrument::Instrument;
mod utils;
@@ -36,7 +37,7 @@ type Millisecond = u32;
#[derive(NativeClass)]
#[inherit(Node)]
pub struct MonoSynth {
- pub osc: Osc,
+ pub osc: Instrument,
pub sample_rate: SamplesPerSecond,
pub frequency: Hz,
pub apply_bend: bool,
@@ -199,7 +200,7 @@ impl MonoSynth {
}
#[export]
- fn trigger(&mut self, _owner: &Node,
+ fn trigger(&mut self, _owner: &Node,
) {
self.envelope = Envelope::new(self.attack, self.decay, self.sustain, self.release, self.sample_rate);
}