From a014949e2c7fa4c8bc02e3a54a74ae3727924076 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Fri, 3 Dec 2021 12:56:05 -0600 Subject: Add: partial hooking up Instrument in place of Osc --- klangfarbrs/src/instrument.rs | 9 +++++++++ klangfarbrs/src/lib.rs | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'klangfarbrs') 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); } -- cgit v1.2.3