Struct instrument::Instrument
[−]
[src]
pub struct Instrument<M, NFG> where
NFG: NoteFreqGenerator, { pub mode: M, pub voices: Vec<Voice<NFG::NoteFreq>>, pub detune: f32, pub note_freq_gen: NFG, pub attack_ms: Ms, pub release_ms: Ms, }
A performable Instrument
type that converts Note
events into a sequence of voices, each
with their own unique amplitude and frequency per frame. This is useful for driving the
playback of instrument types like synthesisers or samplers.
Instrument
handles the following logic:
- Playback mode: Legato, Retrigger or Polyphonic.
- Note on detuning.
- Note on "interoplation" / frequency generation: Legato or Constant.
- Sustained note warping:
- Multi-channel audio processing.
Fields
mode: M
The mode of note playback.
voices: Vec<Voice<NFG::NoteFreq>>
The stack of Voice
s used by the Instrument.
- If the Instrument is in Mono mode, it will play one voice at a time.
- If the Instrument is in Poly mode, it will play all voices at once.
detune: f32
The amount each voice's note_on should be detuned.
note_freq_gen: NFG
Note on "interoplation" / frequency generation: Legato or Constant.
attack_ms: Ms
A duration in frames over which the amplitude of each note will fade in after note_on
.
release_ms: Ms
A duration in frames over which the amplitude of each note will fade out after note_off
.
Methods
impl<M, NFG> Instrument<M, NFG> where
NFG: NoteFreqGenerator,
[src]
NFG: NoteFreqGenerator,
fn new(mode: M, note_freq_gen: NFG) -> Self
Construct a new Instrument
of the given mode using the given note frequency generator.
fn num_voices(self, num_voices: usize) -> Self
Build the Instrument with the given number of voices.
fn fade<A, R>(self, attack: A, release: R) -> Self where
A: Into<Ms>,
R: Into<Ms>,
A: Into<Ms>,
R: Into<Ms>,
Set the note fades for the Instrument
in frames.
fn attack<A>(self, attack: A) -> Self where
A: Into<Ms>,
A: Into<Ms>,
Set the attack.
fn release<R>(self, release: R) -> Self where
R: Into<Ms>,
R: Into<Ms>,
Set the release.
fn detune(self, detune: f32) -> Self
Set the Instrument's note_on detune amount.
fn note_freq_generator(self, generator: NFG) -> Self
Convert Self
into a new Instrument
with the given NoteFreqGenerator.
Generates new NoteFreq
s for each of the currently active Voice
s.
fn set_num_voices(&mut self, num_voices: usize)
Set the number of voices that the Instrument shall use.
fn is_active(&self) -> bool
Return whether or not there are any currently active voices.
fn note_on<T>(&mut self, note_hz: T, note_vel: NoteVelocity) where
M: Mode,
T: Into<Hz>,
M: Mode,
T: Into<Hz>,
Begin playback of a note. Instrument will try to use a free Voice
to do this.
If no Voice
s are free, the one playing the oldest note will be chosen to play the new
note instead.
fn note_off<T>(&mut self, note_hz: T) where
M: Mode,
T: Into<Hz>,
M: Mode,
T: Into<Hz>,
Stop playback of the note that was triggered with the matching frequency.
fn stop(&mut self) where
M: Mode,
M: Mode,
Stop playback and clear the current notes.
fn frames(&mut self, sample_hz: SampleHz) -> Frames<NFG::NoteFreq>
Provides an Iterator
like type that consecutively yields the next_frame_per_voice
for
the given sample_hz
.
fn frame_per_voice(
&mut self,
sample_hz: SampleHz
) -> FramePerVoice<NFG::NoteFreq>
&mut self,
sample_hz: SampleHz
) -> FramePerVoice<NFG::NoteFreq>
Produces an Iterator that yields the amplitude and frequency of each voice for the next frame.
Trait Implementations
impl<M: Clone, NFG: Clone> Clone for Instrument<M, NFG> where
NFG: NoteFreqGenerator,
NFG::NoteFreq: Clone,
[src]
NFG: NoteFreqGenerator,
NFG::NoteFreq: Clone,
fn clone(&self) -> Instrument<M, NFG>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<M: Debug, NFG: Debug> Debug for Instrument<M, NFG> where
NFG: NoteFreqGenerator,
NFG::NoteFreq: Debug,
[src]
NFG: NoteFreqGenerator,
NFG::NoteFreq: Debug,
impl<M: PartialEq, NFG: PartialEq> PartialEq for Instrument<M, NFG> where
NFG: NoteFreqGenerator,
NFG::NoteFreq: PartialEq,
[src]
NFG: NoteFreqGenerator,
NFG::NoteFreq: PartialEq,
fn eq(&self, __arg_0: &Instrument<M, NFG>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Instrument<M, NFG>) -> bool
This method tests for !=
.