pub struct VoiceState {
pub active_note: Option<u8>,
pub velocity: f32,
pub gate: bool,
pub frequency: f32,
/* private fields */
}Expand description
Monophonic voice state for MIDI-controlled synthesis.
Tracks the currently active note, velocity, gate state, and frequency. Supports legato playing with last-note priority: when multiple notes are held, releasing a note will return to the previous held note without retriggering the envelope.
Fields§
§active_note: Option<u8>The currently active MIDI note number, if any.
velocity: f32Velocity of the active note (0.0 to 1.0).
gate: boolGate state: true while a note is held.
frequency: f32Frequency in Hz for the current note.
Implementations§
Source§impl VoiceState
impl VoiceState
Sourcepub fn new() -> VoiceState
pub fn new() -> VoiceState
Create a new voice state.
Sourcepub fn note_on(&mut self, note: u8, velocity: u8)
pub fn note_on(&mut self, note: u8, velocity: u8)
Process a note-on event.
Updates the active note, velocity, gate state, and frequency. The note is also pushed onto the note stack for legato handling. If the note stack is full (16 notes), the note is silently dropped from the stack but still becomes the active note.
Sourcepub fn note_off(&mut self, note: u8) -> bool
pub fn note_off(&mut self, note: u8) -> bool
Process a note-off event.
Returns true if the voice should enter release stage (no more notes held),
or false if switching to a previous legato note.
Sourcepub fn held_note_count(&self) -> usize
pub fn held_note_count(&self) -> usize
Returns the number of notes currently held.
Trait Implementations§
Source§impl Clone for VoiceState
impl Clone for VoiceState
Source§fn clone(&self) -> VoiceState
fn clone(&self) -> VoiceState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more