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,
}Expand description
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: MThe mode of note playback.
voices: Vec<Voice<NFG::NoteFreq>>The stack of Voices 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: f32The amount each voice’s note_on should be detuned.
note_freq_gen: NFGNote on “interoplation” / frequency generation: Legato or Constant.
attack_ms: MsA duration in frames over which the amplitude of each note will fade in after note_on.
release_ms: MsA duration in frames over which the amplitude of each note will fade out after note_off.
Implementations§
Source§impl<M, NFG> Instrument<M, NFG>where
NFG: NoteFreqGenerator,
impl<M, NFG> Instrument<M, NFG>where
NFG: NoteFreqGenerator,
Sourcepub fn new(mode: M, note_freq_gen: NFG) -> Self
pub fn new(mode: M, note_freq_gen: NFG) -> Self
Construct a new Instrument of the given mode using the given note frequency generator.
Sourcepub fn num_voices(self, num_voices: usize) -> Self
pub fn num_voices(self, num_voices: usize) -> Self
Build the Instrument with the given number of voices.
Sourcepub fn fade<A, R>(self, attack: A, release: R) -> Self
pub fn fade<A, R>(self, attack: A, release: R) -> Self
Set the note fades for the Instrument in frames.
Sourcepub fn note_freq_generator(self, generator: NFG) -> Self
pub fn note_freq_generator(self, generator: NFG) -> Self
Convert Self into a new Instrument with the given NoteFreqGenerator.
Generates new NoteFreqs for each of the currently active Voices.
Sourcepub fn set_num_voices(&mut self, num_voices: usize)
pub fn set_num_voices(&mut self, num_voices: usize)
Set the number of voices that the Instrument shall use.
Sourcepub fn note_on<T>(&mut self, note_hz: T, note_vel: NoteVelocity)
pub fn note_on<T>(&mut self, note_hz: T, note_vel: NoteVelocity)
Begin playback of a note. Instrument will try to use a free Voice to do this.
If no Voices are free, the one playing the oldest note will be chosen to play the new
note instead.
Sourcepub fn note_off<T>(&mut self, note_hz: T)
pub fn note_off<T>(&mut self, note_hz: T)
Stop playback of the note that was triggered with the matching frequency.
Sourcepub fn frames(&mut self, sample_hz: SampleHz) -> Frames<'_, NFG::NoteFreq>
pub 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.
Sourcepub fn frame_per_voice(
&mut self,
sample_hz: SampleHz,
) -> FramePerVoice<'_, NFG::NoteFreq>
pub fn frame_per_voice( &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§
Source§impl<M: Clone, NFG> Clone for Instrument<M, NFG>
impl<M: Clone, NFG> Clone for Instrument<M, NFG>
Source§fn clone(&self) -> Instrument<M, NFG>
fn clone(&self) -> Instrument<M, NFG>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more