Vital
Loading...
Searching...
No Matches
vital::Voice Class Reference

Represents a single playing note/voice, including voice-state and event handling. More...

#include <voice_handler.h>

Public Types

enum  KeyState {
  kTriggering , kHeld , kSustained , kReleased ,
  kDead , kNumStates
}
 Describes the lifecycle stage of a voice: kTriggering -> kHeld -> kReleased -> kDead, with special states for sustain. More...
 

Public Member Functions

 Voice (AggregateVoice *parent)
 Constructs a Voice owned by a given AggregateVoice.
 
 Voice ()=delete
 Disabled default constructor: Voice must belong to an AggregateVoice.
 
virtual ~Voice ()
 Virtual destructor.
 
force_inline AggregateVoiceparent ()
 Returns the pointer to the parent AggregateVoice.
 
force_inline const VoiceStatestate ()
 Returns a const reference to the VoiceState struct that holds all relevant data.
 
force_inline const KeyState last_key_state ()
 Returns the previous key state (before the most recent update).
 
force_inline const KeyState key_state ()
 Returns the current key state.
 
force_inline int event_sample ()
 Returns the sample index at which the latest event (on/off) was triggered.
 
force_inline int voice_index ()
 Returns the index of this voice within an AggregateVoice (also the SIMD lane grouping).
 
force_inline poly_mask voice_mask ()
 Returns the SIMD mask representing this voice's active lanes.
 
force_inline mono_float aftertouch ()
 Returns the current aftertouch value for this voice.
 
force_inline mono_float aftertouch_sample ()
 Returns the sample index at which the latest aftertouch event occurred.
 
force_inline mono_float slide ()
 Returns the current slide (MPE expression) value for this voice.
 
force_inline mono_float slide_sample ()
 Returns the sample index at which the latest slide event occurred.
 
force_inline void activate (int midi_note, mono_float tuned_note, mono_float velocity, poly_float last_note, int note_pressed, int note_count, int sample, int channel)
 Activates (starts) the voice with the given note parameters.
 
force_inline void setKeyState (KeyState key_state)
 Sets the key state of this voice (e.g., from Triggering to Held).
 
force_inline void sustain ()
 Switches this voice to the kSustained state, typically when a sustain pedal is active.
 
force_inline bool sustained ()
 Returns true if the voice is in the kSustained state.
 
force_inline bool held ()
 Returns true if the voice is in the kHeld state.
 
force_inline bool released ()
 Returns true if the voice is in the kReleased state.
 
force_inline bool sostenuto ()
 Returns true if the voice has sostenuto pressed.
 
force_inline void setSostenuto (bool sostenuto)
 Sets the sostenuto flag on or off.
 
force_inline void setLocalPitchBend (mono_float bend)
 Sets the local pitch bend (used for legato transitions or channel pitch bend).
 
force_inline void setLiftVelocity (mono_float lift)
 Adjusts the lift velocity (release velocity) of the note-off.
 
force_inline void deactivate (int sample=0)
 Deactivates (turns off) this voice with a note-off event, transitioning to kReleased.
 
force_inline void kill (int sample=0)
 Immediately kills this voice (disregarding release).
 
force_inline void markDead ()
 Marks this voice as kDead, meaning it's completely inactive.
 
force_inline bool hasNewEvent ()
 Checks if there is a new (non-processed) on/off event for this voice.
 
force_inline void setAftertouch (mono_float aftertouch, int sample=0)
 Sets the aftertouch (pressure) value for the voice.
 
force_inline void setSlide (mono_float slide, int sample=0)
 Sets the MPE "slide" value for the voice (often CC#74).
 
force_inline bool hasNewAftertouch ()
 Returns true if there's a new aftertouch event not yet processed.
 
force_inline bool hasNewSlide ()
 Returns true if there's a new slide event not yet processed.
 
force_inline void completeVoiceEvent ()
 Completes (consumes) the voice event, marking it as processed. If the voice was kTriggering, transitions it to kHeld.
 
force_inline void shiftVoiceEvent (int num_samples)
 Shifts the event sample index by num_samples (e.g., for partial block processing).
 
force_inline void shiftAftertouchEvent (int num_samples)
 Shifts the aftertouch event sample index by num_samples.
 
force_inline void shiftSlideEvent (int num_samples)
 Shifts the slide event sample index by num_samples.
 
force_inline void clearAftertouchEvent ()
 Clears the unprocessed aftertouch event, if any.
 
force_inline void clearSlideEvent ()
 Clears the unprocessed slide event, if any.
 
force_inline void clearEvents ()
 Clears both note-on/off events and aftertouch events, marking them processed.
 
force_inline void setSharedVoices (std::vector< Voice * > shared_voices)
 Stores references to other Voices in the same parallel group for advanced sharing logic.
 
force_inline void setVoiceInfo (int voice_index, poly_mask voice_mask)
 Sets the voice index within its parallel group and the corresponding SIMD mask.
 

Static Public Attributes

static constexpr mono_float kDefaultLiftVelocity = 0.5f
 Default lift velocity to use if none is provided.
 

Detailed Description

Represents a single playing note/voice, including voice-state and event handling.

Voices can be grouped into AggregateVoice sets, with each group sharing a Processor. This class stores the note data and manages transitions between states (on/off/sustain).

Member Enumeration Documentation

◆ KeyState

Describes the lifecycle stage of a voice: kTriggering -> kHeld -> kReleased -> kDead, with special states for sustain.

Enumerator
kTriggering 

Note-on occurred, but hasn't processed yet.

kHeld 

The note is actively held down.

kSustained 

The note has ended, but sustain pedal is holding it on.

kReleased 

The note has ended (off event) and is releasing.

kDead 

The voice is no longer active.

kNumStates 

Constructor & Destructor Documentation

◆ Voice() [1/2]

vital::Voice::Voice ( AggregateVoice * parent)

Constructs a Voice owned by a given AggregateVoice.

Parameters
parentPointer to the owning AggregateVoice.

◆ Voice() [2/2]

vital::Voice::Voice ( )
delete

Disabled default constructor: Voice must belong to an AggregateVoice.

◆ ~Voice()

virtual vital::Voice::~Voice ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ activate()

force_inline void vital::Voice::activate ( int midi_note,
mono_float tuned_note,
mono_float velocity,
poly_float last_note,
int note_pressed,
int note_count,
int sample,
int channel )
inline

Activates (starts) the voice with the given note parameters.

Parameters
midi_noteMIDI note number.
tuned_notePossibly adjusted note frequency (from Tuning).
velocityVelocity of note-on.
last_noteThe previous note value (for legato).
note_pressedThe count of pressed notes for note-on logic.
note_countA global note increment for event ordering.
sampleThe sample index at which note-on occurs.
channelThe MIDI channel for this note.

◆ aftertouch()

force_inline mono_float vital::Voice::aftertouch ( )
inline

Returns the current aftertouch value for this voice.

◆ aftertouch_sample()

force_inline mono_float vital::Voice::aftertouch_sample ( )
inline

Returns the sample index at which the latest aftertouch event occurred.

◆ clearAftertouchEvent()

force_inline void vital::Voice::clearAftertouchEvent ( )
inline

Clears the unprocessed aftertouch event, if any.

◆ clearEvents()

force_inline void vital::Voice::clearEvents ( )
inline

Clears both note-on/off events and aftertouch events, marking them processed.

◆ clearSlideEvent()

force_inline void vital::Voice::clearSlideEvent ( )
inline

Clears the unprocessed slide event, if any.

◆ completeVoiceEvent()

force_inline void vital::Voice::completeVoiceEvent ( )
inline

Completes (consumes) the voice event, marking it as processed. If the voice was kTriggering, transitions it to kHeld.

◆ deactivate()

force_inline void vital::Voice::deactivate ( int sample = 0)
inline

Deactivates (turns off) this voice with a note-off event, transitioning to kReleased.

Parameters
sampleThe sample index at which note-off occurs.

◆ event_sample()

force_inline int vital::Voice::event_sample ( )
inline

Returns the sample index at which the latest event (on/off) was triggered.

◆ hasNewAftertouch()

force_inline bool vital::Voice::hasNewAftertouch ( )
inline

Returns true if there's a new aftertouch event not yet processed.

◆ hasNewEvent()

force_inline bool vital::Voice::hasNewEvent ( )
inline

Checks if there is a new (non-processed) on/off event for this voice.

◆ hasNewSlide()

force_inline bool vital::Voice::hasNewSlide ( )
inline

Returns true if there's a new slide event not yet processed.

◆ held()

force_inline bool vital::Voice::held ( )
inline

Returns true if the voice is in the kHeld state.

◆ key_state()

force_inline const KeyState vital::Voice::key_state ( )
inline

Returns the current key state.

◆ kill()

force_inline void vital::Voice::kill ( int sample = 0)
inline

Immediately kills this voice (disregarding release).

Parameters
sampleThe sample index at which kill occurs.

◆ last_key_state()

force_inline const KeyState vital::Voice::last_key_state ( )
inline

Returns the previous key state (before the most recent update).

◆ markDead()

force_inline void vital::Voice::markDead ( )
inline

Marks this voice as kDead, meaning it's completely inactive.

◆ parent()

force_inline AggregateVoice * vital::Voice::parent ( )
inline

Returns the pointer to the parent AggregateVoice.

◆ released()

force_inline bool vital::Voice::released ( )
inline

Returns true if the voice is in the kReleased state.

◆ setAftertouch()

force_inline void vital::Voice::setAftertouch ( mono_float aftertouch,
int sample = 0 )
inline

Sets the aftertouch (pressure) value for the voice.

Parameters
aftertouchThe new aftertouch value.
sampleThe sample index at which the event is received.

◆ setKeyState()

force_inline void vital::Voice::setKeyState ( KeyState key_state)
inline

Sets the key state of this voice (e.g., from Triggering to Held).

Parameters
key_stateThe new KeyState.

◆ setLiftVelocity()

force_inline void vital::Voice::setLiftVelocity ( mono_float lift)
inline

Adjusts the lift velocity (release velocity) of the note-off.

◆ setLocalPitchBend()

force_inline void vital::Voice::setLocalPitchBend ( mono_float bend)
inline

Sets the local pitch bend (used for legato transitions or channel pitch bend).

◆ setSharedVoices()

force_inline void vital::Voice::setSharedVoices ( std::vector< Voice * > shared_voices)
inline

Stores references to other Voices in the same parallel group for advanced sharing logic.

Parameters
shared_voicesA list of pointers to parallel voices in the same AggregateVoice.

◆ setSlide()

force_inline void vital::Voice::setSlide ( mono_float slide,
int sample = 0 )
inline

Sets the MPE "slide" value for the voice (often CC#74).

Parameters
slideThe new slide value.
sampleThe sample index at which the event is received.

◆ setSostenuto()

force_inline void vital::Voice::setSostenuto ( bool sostenuto)
inline

Sets the sostenuto flag on or off.

◆ setVoiceInfo()

force_inline void vital::Voice::setVoiceInfo ( int voice_index,
poly_mask voice_mask )
inline

Sets the voice index within its parallel group and the corresponding SIMD mask.

Parameters
voice_indexAn integer index (0..kParallelVoices-1).
voice_maskA poly_mask enabling only the lanes relevant to this voice.

◆ shiftAftertouchEvent()

force_inline void vital::Voice::shiftAftertouchEvent ( int num_samples)
inline

Shifts the aftertouch event sample index by num_samples.

◆ shiftSlideEvent()

force_inline void vital::Voice::shiftSlideEvent ( int num_samples)
inline

Shifts the slide event sample index by num_samples.

◆ shiftVoiceEvent()

force_inline void vital::Voice::shiftVoiceEvent ( int num_samples)
inline

Shifts the event sample index by num_samples (e.g., for partial block processing).

Parameters
num_samplesHow many samples to shift.

◆ slide()

force_inline mono_float vital::Voice::slide ( )
inline

Returns the current slide (MPE expression) value for this voice.

◆ slide_sample()

force_inline mono_float vital::Voice::slide_sample ( )
inline

Returns the sample index at which the latest slide event occurred.

◆ sostenuto()

force_inline bool vital::Voice::sostenuto ( )
inline

Returns true if the voice has sostenuto pressed.

◆ state()

force_inline const VoiceState & vital::Voice::state ( )
inline

Returns a const reference to the VoiceState struct that holds all relevant data.

◆ sustain()

force_inline void vital::Voice::sustain ( )
inline

Switches this voice to the kSustained state, typically when a sustain pedal is active.

◆ sustained()

force_inline bool vital::Voice::sustained ( )
inline

Returns true if the voice is in the kSustained state.

◆ voice_index()

force_inline int vital::Voice::voice_index ( )
inline

Returns the index of this voice within an AggregateVoice (also the SIMD lane grouping).

◆ voice_mask()

force_inline poly_mask vital::Voice::voice_mask ( )
inline

Returns the SIMD mask representing this voice's active lanes.

Member Data Documentation

◆ kDefaultLiftVelocity

mono_float vital::Voice::kDefaultLiftVelocity = 0.5f
staticconstexpr

Default lift velocity to use if none is provided.


The documentation for this class was generated from the following files: