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

A SynthModule and NoteHandler that manages a pool of polyphonic voices, handles note-on/off logic, and routes the data to multiple processors. More...

#include <voice_handler.h>

Inheritance diagram for vital::VoiceHandler:
vital::SynthModule vital::NoteHandler vital::ProcessorRouter vital::Processor vital::EffectsModulationHandler vital::SynthVoiceHandler

Public Types

enum  { kPolyphony , kVoicePriority , kVoiceOverride , kNumInputs }
 Input indexes for VoiceHandler control parameters. More...
 
enum  VoiceOverride { kKill , kSteal , kNumVoiceOverrides }
 Behavior for assigning a new note when at max polyphony. More...
 
enum  VoicePriority {
  kNewest , kOldest , kHighest , kLowest ,
  kRoundRobin , kNumVoicePriorities
}
 Determines the voice stealing strategy (oldest, newest, highest, etc.). More...
 

Public Member Functions

 VoiceHandler (int num_outputs, int polyphony, bool control_rate=false)
 Constructs a VoiceHandler with a given polyphony and outputs.
 
 VoiceHandler ()=delete
 Disabled default constructor; must specify polyphony and output count.
 
virtual ~VoiceHandler ()
 Virtual destructor.
 
virtual Processorclone () const override
 Clones this VoiceHandler. Not supported for this class.
 
virtual void process (int num_samples) override
 Processes audio for a block of samples. For each active voice, triggers events, updates parameters, and runs its Processor.
 
virtual void init () override
 Initializes the voice and global routers, then calls SynthModule::init().
 
virtual void setSampleRate (int sample_rate) override
 Sets the sample rate for both mono/global and voice (poly) routers.
 
void setTuning (const Tuning *tuning)
 Sets the custom Tuning object (if any) for note->frequency conversion.
 
int getNumActiveVoices ()
 Returns the number of currently active voices (not dead).
 
force_inline int getNumPressedNotes ()
 Returns how many notes are pressed (including partial states).
 
bool isNotePlaying (int note)
 Checks if a given MIDI note is playing.
 
bool isNotePlaying (int note, int channel)
 Checks if a given MIDI note is playing on a particular channel.
 
void allSoundsOff () override
 Immediately turns off all sounding notes and stops all sound production.
 
void allNotesOff (int sample) override
 Turns off all currently active notes, optionally specifying a sample index for timing.
 
void allNotesOff (int sample, int channel) override
 Turns off all currently active notes on a specific MIDI channel, optionally specifying a sample index.
 
void allNotesOffRange (int sample, int from_channel, int to_channel)
 
virtual void noteOn (int note, mono_float velocity, int sample, int channel) override
 Handles a MIDI note-on event, starting a note with a specified velocity and timing.
 
virtual void noteOff (int note, mono_float velocity, int sample, int channel) override
 Handles a MIDI note-off event, releasing a currently active note.
 
void setAftertouch (int note, mono_float aftertouch, int sample, int channel)
 Handles per-note aftertouch for a specific note and channel.
 
void setChannelAftertouch (int channel, mono_float aftertouch, int sample)
 Sets channel-wide aftertouch (applies to all voices on that channel).
 
void setChannelRangeAftertouch (int from_channel, int to_channel, mono_float aftertouch, int sample)
 Sets channel-wide aftertouch for a range of channels.
 
void setChannelSlide (int channel, mono_float aftertouch, int sample)
 Sets channel-wide MPE "slide" for a single channel.
 
void setChannelRangeSlide (int from_channel, int to_channel, mono_float aftertouch, int sample)
 Sets channel-wide MPE "slide" for a range of channels.
 
void sustainOn (int channel)
 Turns on sustain for a single channel.
 
void sustainOff (int sample, int channel)
 Turns off sustain for a single channel, prompting voices to release.
 
void sostenutoOn (int channel)
 Turns on sostenuto for a single channel.
 
void sostenutoOff (int sample, int channel)
 Turns off sostenuto for a single channel, prompting release if not sustained.
 
void sustainOnRange (int from_channel, int to_channel)
 Turns on sustain for a range of channels.
 
void sustainOffRange (int sample, int from_channel, int to_channel)
 Turns off sustain for a range of channels, prompting voices to release.
 
void sostenutoOnRange (int from_channel, int to_channel)
 Turns on sostenuto for a range of channels.
 
void sostenutoOffRange (int sample, int from_channel, int to_channel)
 Turns off sostenuto for a range of channels, prompting release if not sustained.
 
poly_mask getCurrentVoiceMask ()
 Returns a mask for the last active voice, used for writing to output buffers.
 
force_inline void setModWheel (mono_float value, int channel=0)
 Sets the mod wheel value for a single channel.
 
force_inline void setModWheelAllChannels (mono_float value)
 Sets the mod wheel value for all channels at once.
 
force_inline void setPitchWheel (mono_float value, int channel=0)
 Sets the pitch wheel value for a single channel, applying to all held voices on that channel.
 
force_inline void setZonedPitchWheel (mono_float value, int from_channel, int to_channel)
 Sets pitch wheel in a zoned manner for a range of MIDI channels.
 
force_inline Outputvoice_event ()
 Returns a pointer to the voice_event Output, used to track voice On/Off/Kill events.
 
force_inline Outputretrigger ()
 Returns a pointer to the retrigger Output, used for controlling certain envelope triggers.
 
force_inline Outputreset ()
 Returns a pointer to the reset Output, indicating a full voice reset (On from Dead).
 
force_inline Outputnote ()
 Returns a pointer to the note Output, giving the current tuned note frequency or pitch.
 
force_inline Outputlast_note ()
 Returns a pointer to the last_note Output, giving the previous note (for legato transitions).
 
force_inline Outputnote_pressed ()
 Returns a pointer to the note_pressed Output, a count of how many times a note was pressed.
 
force_inline Outputnote_count ()
 Returns a pointer to note_count, a global note counter.
 
force_inline Outputnote_in_octave ()
 Returns a pointer to note_in_octave, a fractional note position in [0..1).
 
force_inline Outputchannel ()
 Returns a pointer to channel, indicating the MIDI channel of the voice.
 
force_inline Outputvelocity ()
 Returns a pointer to velocity, the note-on velocity.
 
force_inline Outputlift ()
 Returns a pointer to lift, the note-off velocity or release velocity.
 
force_inline Outputaftertouch ()
 Returns a pointer to aftertouch, storing per-voice or channel-based aftertouch.
 
force_inline Outputslide ()
 Returns a pointer to slide, the MPE "slide" expression value.
 
force_inline Outputactive_mask ()
 Returns a pointer to active_mask, a mask that indicates which voices are active.
 
force_inline Outputpitch_wheel ()
 Returns a pointer to pitch_wheel, storing the pitch-bend range for each channel.
 
force_inline Outputpitch_wheel_percent ()
 Returns a pointer to pitch_wheel_percent, a normalized [0..1] version of pitch_wheel.
 
force_inline Outputlocal_pitch_bend ()
 Returns a pointer to local_pitch_bend, the per-voice pitch bend output.
 
force_inline Outputmod_wheel ()
 Returns a pointer to mod_wheel, storing the mod wheel value for each channel.
 
force_inline OutputgetAccumulatedOutput (Output *output)
 Retrieves the accumulated Output associated with a given output pointer.
 
force_inline int polyphony ()
 Returns the current maximum polyphony (number of active voices allowed).
 
mono_float getLastActiveNote () const
 Gets the last active note's tuned frequency (or 0 if none).
 
virtual ProcessorRoutergetMonoRouter () override
 Returns the monophonic (global) ProcessorRouter for this VoiceHandler.
 
virtual ProcessorRoutergetPolyRouter () override
 Returns the polyphonic (voice) ProcessorRouter for this VoiceHandler.
 
void addProcessor (Processor *processor) override
 Adds a Processor to be managed by this router.
 
void addIdleProcessor (Processor *processor) override
 Adds a Processor that should remain idle (not processed) in the router.
 
void removeProcessor (Processor *processor) override
 Removes a Processor from this router.
 
void addGlobalProcessor (Processor *processor)
 Adds a Processor to the "global" (monophonic) router, e.g. for final mixing or master effects.
 
void removeGlobalProcessor (Processor *processor)
 Removes a Processor from the global router.
 
void resetFeedbacks (poly_mask reset_mask) override
 Resets any feedback paths in the poly router, applying the given mask.
 
OutputregisterOutput (Output *output) override
 Registers an Output with this VoiceHandler, returning a pointer to a new accumulated or single-lane Output.
 
OutputregisterControlRateOutput (Output *output, bool active)
 Registers a control-rate Output with the VoiceHandler.
 
OutputregisterOutput (Output *output, int index) override
 Not implemented index-based registerOutput override (asserts false).
 
void setPolyphony (int polyphony)
 Sets the polyphony to a new value, allocating or freeing voices as needed.
 
force_inline void setVoiceKiller (const Output *killer)
 Specifies an Output from a Processor used to detect silence or inactivity for voice killing.
 
force_inline void setVoiceKiller (const Processor *killer)
 Overload for setting the voice killer from a Processor directly.
 
force_inline void setVoiceMidi (const Output *midi)
 Sets the Output that provides the current MIDI note for the voice.
 
force_inline void setLegato (bool legato)
 Enables or disables legato mode (disables retriggers if still in Held state).
 
force_inline bool legato ()
 Returns true if legato mode is enabled.
 
bool isPolyphonic (const Processor *processor) const override
 Checks if a given Processor is handled by the poly (voice) router.
 
virtual void setOversampleAmount (int oversample) override
 Sets the oversampling factor for both SynthModule and the internal poly/mono routers.
 
void setActiveNonaccumulatedOutput (Output *output)
 Marks an Output as "active" for non-accumulated usage (e.g., for the last active voice only).
 
void setInactiveNonaccumulatedOutput (Output *output)
 Marks an Output as "inactive" for non-accumulated usage, effectively disabling it.
 
- Public Member Functions inherited from vital::SynthModule
 SynthModule (int num_inputs, int num_outputs, bool control_rate=false)
 Constructs a SynthModule with specified I/O and control rate.
 
virtual ~SynthModule ()
 Destructor.
 
control_map getControls ()
 Returns a map of all controls from this module and its submodules.
 
OutputgetModulationSource (std::string name)
 Retrieves a modulation source output by name.
 
const StatusOutputgetStatusOutput (std::string name) const
 Retrieves a StatusOutput by name.
 
ProcessorgetModulationDestination (std::string name, bool poly)
 Retrieves a modulation destination Processor by name and poly mode.
 
ProcessorgetMonoModulationDestination (std::string name)
 Retrieves a mono modulation destination by name.
 
ProcessorgetPolyModulationDestination (std::string name)
 Retrieves a poly modulation destination by name.
 
ValueSwitchgetModulationSwitch (std::string name, bool poly)
 Retrieves a modulation switch by name and poly mode.
 
ValueSwitchgetMonoModulationSwitch (std::string name)
 Retrieves a mono modulation switch by name.
 
ValueSwitchgetPolyModulationSwitch (std::string name)
 Retrieves a poly modulation switch by name.
 
void updateAllModulationSwitches ()
 Updates all modulation switches based on whether their destinations have inputs.
 
output_mapgetModulationSources ()
 Returns a reference to the map of modulation sources.
 
input_mapgetMonoModulationDestinations ()
 Returns a reference to the map of mono modulation destinations.
 
input_mapgetPolyModulationDestinations ()
 Returns a reference to the map of poly modulation destinations.
 
virtual output_mapgetMonoModulations ()
 Returns a reference to the map of mono modulation readouts.
 
virtual output_mapgetPolyModulations ()
 Returns a reference to the map of poly modulation readouts.
 
virtual void correctToTime (double seconds)
 Allows correction of module state to a given time (if needed).
 
void enableOwnedProcessors (bool enable)
 Enables or disables all owned processors.
 
virtual void enable (bool enable) override
 Enables or disables this SynthModule and its owned processors.
 
void addMonoProcessor (Processor *processor, bool own=true)
 Adds a mono processor to this module.
 
void addIdleMonoProcessor (Processor *processor)
 Adds a mono processor that is considered idle (not part of main processing chain).
 
void addSubmodule (SynthModule *module)
 Adds a submodule to this SynthModule.
 
- Public Member Functions inherited from vital::ProcessorRouter
 ProcessorRouter (int num_inputs=0, int num_outputs=0, bool control_rate=false)
 Constructs a ProcessorRouter with a specified number of inputs and outputs.
 
 ProcessorRouter (const ProcessorRouter &original)
 Copy constructor. Creates a new ProcessorRouter from an existing one.
 
virtual ~ProcessorRouter ()
 Destructor.
 
virtual void addProcessorRealTime (Processor *processor)
 Adds a Processor to the router in real-time (no memory allocations).
 
void connect (Processor *destination, const Output *source, int index)
 Connects a source Output to a destination Processor input by index.
 
void disconnect (const Processor *destination, const Output *source)
 Disconnects a source Output from a destination Processor.
 
bool isDownstream (const Processor *first, const Processor *second) const
 Checks if one Processor is downstream from another, i.e., if there's a path from the second to the first.
 
bool areOrdered (const Processor *first, const Processor *second) const
 Checks if the order of two Processors is fixed in the router's processing sequence.
 
- Public Member Functions inherited from vital::Processor
 Processor (int num_inputs, int num_outputs, bool control_rate=false, int max_oversample=1)
 Constructs a Processor with a given number of inputs/outputs and oversampling.
 
virtual ~Processor ()
 Virtual destructor.
 
virtual bool hasState () const
 Indicates whether this Processor requires per-voice state.
 
virtual void processWithInput (const poly_float *audio_in, int num_samples)
 An optional processing function taking explicit input buffer. Fallback is an assertion failure (not supported).
 
virtual void reset (poly_mask reset_mask)
 Called to reset the Processor's per-voice state (e.g., on note-on).
 
virtual void hardReset ()
 Called to perform a "hard" reset for all voices.
 
bool initialized ()
 Returns whether this Processor has been initialized.
 
force_inline bool enabled () const
 Checks if this Processor is enabled.
 
force_inline int getSampleRate () const
 Retrieves the current (effective) sample rate.
 
force_inline int getOversampleAmount () const
 Retrieves the current oversampling factor.
 
force_inline bool isControlRate () const
 Checks if this Processor is running at control rate (buffer_size == 1).
 
virtual void setControlRate (bool control_rate)
 Sets whether this Processor runs at control rate.
 
force_inline poly_mask getResetMask (int input_index) const
 Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_value to kVoiceOn.
 
force_inline void clearOutputBufferForReset (poly_mask reset_mask, int input_index, int output_index) const
 Clears output samples for voices that are about to be reset, based on the trigger offset.
 
bool inputMatchesBufferSize (int input=0)
 Checks whether the buffer size of a particular input matches the size needed by this Processor.
 
bool checkInputAndOutputSize (int num_samples)
 Checks if all inputs and outputs have buffers big enough for num_samples.
 
virtual bool isPolyphonic () const
 Checks if this Processor is polyphonic by querying its ProcessorRouter.
 
void plug (const Output *source)
 Connects an external Output to this Processor's first input.
 
void plug (const Output *source, unsigned int input_index)
 Connects an external Output to a specified input index.
 
void plug (const Processor *source)
 Connects the first output of a Processor to this Processor's first input.
 
void plug (const Processor *source, unsigned int input_index)
 Connects the first output of a Processor to a specified input index.
 
void plugNext (const Output *source)
 Connects an external Output to the first available (unplugged) input.
 
void plugNext (const Processor *source)
 Connects the first output of a Processor to the first available (unplugged) input.
 
void useInput (Input *input)
 Uses an existing Input object as this Processor's first input.
 
void useInput (Input *input, int index)
 Uses an existing Input object at a specified input index.
 
void useOutput (Output *output)
 Uses an existing Output object as this Processor's first output.
 
void useOutput (Output *output, int index)
 Uses an existing Output object at a specified output index.
 
int connectedInputs ()
 Counts how many inputs are connected to a real source (not null_source_).
 
virtual void unplugIndex (unsigned int input_index)
 Removes the connection at a specified input index, if any.
 
virtual void unplug (const Output *source)
 Removes a connection to a given Output from all inputs.
 
virtual void unplug (const Processor *source)
 Removes connections to all outputs from a given Processor.
 
virtual void numInputsChanged ()
 Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic behavior.
 
force_inline void router (ProcessorRouter *router)
 Sets the ProcessorRouter that owns or manages this Processor.
 
force_inline ProcessorRouterrouter () const
 Returns the ProcessorRouter that currently owns this Processor.
 
ProcessorRoutergetTopLevelRouter () const
 Gets the topmost (root) ProcessorRouter by traversing parent routers.
 
virtual void registerInput (Input *input, int index)
 Registers a new input, appending it to the input list.
 
virtual void registerInput (Input *input)
 Registers a new Input by appending it to the end of the input list.
 
force_inline int numInputs () const
 Returns the total number of Input pointers (owned or otherwise).
 
force_inline int numOutputs () const
 Returns the total number of Output pointers (owned or otherwise).
 
force_inline int numOwnedInputs () const
 Returns how many Input objects this Processor owns.
 
force_inline int numOwnedOutputs () const
 Returns how many Output objects this Processor owns.
 
force_inline Inputinput (unsigned int index=0) const
 Retrieves the Input pointer at a given index.
 
force_inline bool isInputSourcePolyphonic (int index=0)
 Checks if the input source at a given index is polyphonic.
 
force_inline InputownedInput (unsigned int index=0) const
 Retrieves an owned Input pointer at a given index.
 
force_inline Outputoutput (unsigned int index=0) const
 Retrieves the Output pointer at a given index.
 
force_inline OutputownedOutput (unsigned int index=0) const
 Retrieves an owned Output pointer at a given index.
 
void setPluggingStart (int start)
 Sets the position at which plugNext starts searching for an open input.
 
- Public Member Functions inherited from vital::NoteHandler
virtual ~NoteHandler ()
 Virtual destructor.
 

Static Public Attributes

static constexpr mono_float kLocalPitchBendRange = 48.0f
 Range of local pitch bend in semitones for each voice.
 

Protected Member Functions

virtual bool shouldAccumulate (Output *output)
 Determines whether an Output should be summed across voices (accumulated) or handled individually.
 
- Protected Member Functions inherited from vital::SynthModule
ValuecreateBaseControl (std::string name, bool audio_rate=false, bool smooth_value=false)
 Creates a simple control processor for a given parameter name.
 
OutputcreateBaseModControl (std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
 Creates a base mod control, which is a control combined with a modulation input.
 
OutputcreateMonoModControl (std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
 Creates a monophonic mod control, including applying parameter scaling.
 
OutputcreatePolyModControl (std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr, Input *reset=nullptr)
 Creates a polyphonic mod control, including applying parameter scaling.
 
OutputcreateTempoSyncSwitch (std::string name, Processor *frequency, const Output *beats_per_second, bool poly, Input *midi=nullptr)
 Creates a tempo sync switch that toggles between tempo-based frequency and free-running frequency.
 
void createStatusOutput (std::string name, Output *source)
 Creates a status output associated with a given Output.
 
- Protected Member Functions inherited from vital::ProcessorRouter
virtual void addFeedback (Feedback *feedback)
 Adds a Feedback node to handle a feedback loop introduced by a connection.
 
virtual void removeFeedback (Feedback *feedback)
 Removes a previously added Feedback node.
 
void reorder (Processor *processor)
 Reorders the internal processing sequence to account for a Processor's dependencies.
 
virtual void updateAllProcessors ()
 Updates all processors to match the global order. Called when changes occur.
 
force_inline bool shouldUpdate ()
 Checks if local changes need to be synchronized with global changes.
 
virtual void createAddedProcessors ()
 Creates any processors that were added at the global level but not yet replicated locally.
 
virtual void deleteRemovedProcessors ()
 Deletes any processors that were removed at the global level but not yet removed locally.
 
const ProcessorgetContext (const Processor *processor) const
 Gets the processor context within this router for a global Processor reference.
 
void getDependencies (const Processor *processor) const
 Populates the internal dependencies structure for a given Processor.
 
ProcessorgetLocalProcessor (const Processor *global_processor)
 Retrieves the local instance of a globally defined Processor.
 
- Protected Member Functions inherited from vital::Processor
OutputaddOutput (int oversample=1)
 Creates and registers a new Output. Handles control rate vs. audio rate.
 
InputaddInput ()
 Creates and registers a new Input, initially connected to null_source_.
 

Additional Inherited Members

- Protected Attributes inherited from vital::SynthModule
std::shared_ptr< ModuleDatadata_
 Shared data storage for this SynthModule.
 
- Protected Attributes inherited from vital::ProcessorRouter
std::shared_ptr< CircularQueue< Processor * > > global_order_
 Global processing order reference.
 
std::shared_ptr< CircularQueue< Processor * > > global_reorder_
 Temporary storage for reorder operations.
 
CircularQueue< Processor * > local_order_
 Local ordering of Processors.
 
std::map< const Processor *, std::pair< int, std::unique_ptr< Processor > > > processors_
 Map of global to local Processors.
 
std::map< const Processor *, std::unique_ptr< Processor > > idle_processors_
 Idle Processors that are not active in the graph.
 
std::shared_ptr< std::vector< const Feedback * > > global_feedback_order_
 Global order of Feedback nodes.
 
std::vector< Feedback * > local_feedback_order_
 Local copies of Feedback nodes.
 
std::map< const Processor *, std::pair< int, std::unique_ptr< Feedback > > > feedback_processors_
 Map of global to local Feedback processors.
 
std::shared_ptr< int > global_changes_
 Global change counter.
 
int local_changes_
 Local change counter to track synchronization with global changes.
 
std::shared_ptr< CircularQueue< const Processor * > > dependencies_
 Queue for dependencies calculations.
 
std::shared_ptr< CircularQueue< const Processor * > > dependencies_visited_
 Queue of visited processors for dependencies calc.
 
std::shared_ptr< CircularQueue< const Processor * > > dependency_inputs_
 Queue of processors to check inputs for dependencies.
 
- Protected Attributes inherited from vital::Processor
std::shared_ptr< ProcessorStatestate_
 Shared state (sample rate, oversample, etc.)
 
int plugging_start_
 The index at which plugNext starts searching for an unplugged input.
 
std::vector< std::shared_ptr< Input > > owned_inputs_
 Inputs owned by this Processor.
 
std::vector< std::shared_ptr< Output > > owned_outputs_
 Outputs owned by this Processor.
 
std::shared_ptr< std::vector< Input * > > inputs_
 All inputs, owned or external.
 
std::shared_ptr< std::vector< Output * > > outputs_
 All outputs, owned or external.
 
ProcessorRouterrouter_
 The ProcessorRouter that manages this Processor.
 
- Static Protected Attributes inherited from vital::Processor
static const Output null_source_
 A null (dummy) source used for unconnected inputs.
 

Detailed Description

A SynthModule and NoteHandler that manages a pool of polyphonic voices, handles note-on/off logic, and routes the data to multiple processors.

The VoiceHandler class takes in note events (MIDI or otherwise) and dispatches them to available or stolen voices, tracks voice states (e.g., sustaining), and provides outputs that other modules can use to render audio or handle modulation based on active voices.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Input indexes for VoiceHandler control parameters.

Enumerator
kPolyphony 

Desired polyphony setting (1..kMaxActivePolyphony).

kVoicePriority 

Priority scheme for stealing or reassigning voices.

kVoiceOverride 

Behavior when exceeding polyphony: kill or steal.

kNumInputs 

◆ VoiceOverride

Behavior for assigning a new note when at max polyphony.

Enumerator
kKill 

Immediately kill an existing voice to free one.

kSteal 

Steal an existing voice that is in a certain state (released/sustained).

kNumVoiceOverrides 

◆ VoicePriority

Determines the voice stealing strategy (oldest, newest, highest, etc.).

Enumerator
kNewest 
kOldest 
kHighest 
kLowest 
kRoundRobin 
kNumVoicePriorities 

Constructor & Destructor Documentation

◆ VoiceHandler() [1/2]

vital::VoiceHandler::VoiceHandler ( int num_outputs,
int polyphony,
bool control_rate = false )

Constructs a VoiceHandler with a given polyphony and outputs.

Parameters
num_outputsHow many output channels to allocate (e.g., for various mod outputs).
polyphonyNumber of voices to allow.
control_rateTrue if running at control rate (buffer_size == 1).

◆ VoiceHandler() [2/2]

vital::VoiceHandler::VoiceHandler ( )
delete

Disabled default constructor; must specify polyphony and output count.

◆ ~VoiceHandler()

vital::VoiceHandler::~VoiceHandler ( )
virtual

Virtual destructor.

Member Function Documentation

◆ active_mask()

force_inline Output * vital::VoiceHandler::active_mask ( )
inline

Returns a pointer to active_mask, a mask that indicates which voices are active.

◆ addGlobalProcessor()

void vital::VoiceHandler::addGlobalProcessor ( Processor * processor)

Adds a Processor to the "global" (monophonic) router, e.g. for final mixing or master effects.

◆ addIdleProcessor()

void vital::VoiceHandler::addIdleProcessor ( Processor * processor)
overridevirtual

Adds a Processor that should remain idle (not processed) in the router.

Parameters
processorThe idle Processor to add.

Reimplemented from vital::ProcessorRouter.

◆ addProcessor()

void vital::VoiceHandler::addProcessor ( Processor * processor)
overridevirtual

Adds a Processor to be managed by this router.

Parameters
processorThe Processor to add.

The Processor becomes part of the routing graph. The router ensures that the Processor is run at the appropriate point in the signal flow.

Reimplemented from vital::ProcessorRouter.

◆ aftertouch()

force_inline Output * vital::VoiceHandler::aftertouch ( )
inline

Returns a pointer to aftertouch, storing per-voice or channel-based aftertouch.

◆ allNotesOff() [1/2]

void vital::VoiceHandler::allNotesOff ( int sample)
overridevirtual

Turns off all currently active notes, optionally specifying a sample index for timing.

Parameters
sampleThe sample index at which to turn off notes.

Implements vital::NoteHandler.

◆ allNotesOff() [2/2]

void vital::VoiceHandler::allNotesOff ( int sample,
int channel )
overridevirtual

Turns off all currently active notes on a specific MIDI channel, optionally specifying a sample index.

Parameters
sampleThe sample index at which to turn off notes.
channelThe MIDI channel for which to turn off notes.

Implements vital::NoteHandler.

◆ allNotesOffRange()

void vital::VoiceHandler::allNotesOffRange ( int sample,
int from_channel,
int to_channel )

◆ allSoundsOff()

void vital::VoiceHandler::allSoundsOff ( )
overridevirtual

Immediately turns off all sounding notes and stops all sound production.

Implements vital::NoteHandler.

◆ channel()

force_inline Output * vital::VoiceHandler::channel ( )
inline

Returns a pointer to channel, indicating the MIDI channel of the voice.

◆ clone()

virtual Processor * vital::VoiceHandler::clone ( ) const
inlineoverridevirtual

Clones this VoiceHandler. Not supported for this class.

Returns
Always returns nullptr after asserting false.

Reimplemented from vital::SynthModule.

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ getAccumulatedOutput()

force_inline Output * vital::VoiceHandler::getAccumulatedOutput ( Output * output)
inline

Retrieves the accumulated Output associated with a given output pointer.

Parameters
outputThe original Output pointer.
Returns
A pointer to the internally managed Output that accumulates across voices.

◆ getCurrentVoiceMask()

poly_mask vital::VoiceHandler::getCurrentVoiceMask ( )

Returns a mask for the last active voice, used for writing to output buffers.

◆ getLastActiveNote()

mono_float vital::VoiceHandler::getLastActiveNote ( ) const

Gets the last active note's tuned frequency (or 0 if none).

◆ getMonoRouter()

virtual ProcessorRouter * vital::VoiceHandler::getMonoRouter ( )
inlineoverridevirtual

Returns the monophonic (global) ProcessorRouter for this VoiceHandler.

Reimplemented from vital::ProcessorRouter.

◆ getNumActiveVoices()

int vital::VoiceHandler::getNumActiveVoices ( )

Returns the number of currently active voices (not dead).

◆ getNumPressedNotes()

force_inline int vital::VoiceHandler::getNumPressedNotes ( )
inline

Returns how many notes are pressed (including partial states).

◆ getPolyRouter()

virtual ProcessorRouter * vital::VoiceHandler::getPolyRouter ( )
inlineoverridevirtual

Returns the polyphonic (voice) ProcessorRouter for this VoiceHandler.

Reimplemented from vital::ProcessorRouter.

◆ init()

void vital::VoiceHandler::init ( )
overridevirtual

Initializes the voice and global routers, then calls SynthModule::init().

Reimplemented from vital::ProcessorRouter.

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ isNotePlaying() [1/2]

bool vital::VoiceHandler::isNotePlaying ( int note)

Checks if a given MIDI note is playing.

Parameters
noteThe MIDI note to check.
Returns
True if any voice is on with that note, false otherwise.

◆ isNotePlaying() [2/2]

bool vital::VoiceHandler::isNotePlaying ( int note,
int channel )

Checks if a given MIDI note is playing on a particular channel.

Parameters
noteThe MIDI note to check.
channelThe MIDI channel to check.
Returns
True if a matching voice is found, false otherwise.

◆ isPolyphonic()

bool vital::VoiceHandler::isPolyphonic ( const Processor * processor) const
overridevirtual

Checks if a given Processor is handled by the poly (voice) router.

Parameters
processorThe Processor to check.
Returns
True if processor belongs to the voice_router_, false otherwise.

Reimplemented from vital::ProcessorRouter.

◆ last_note()

force_inline Output * vital::VoiceHandler::last_note ( )
inline

Returns a pointer to the last_note Output, giving the previous note (for legato transitions).

◆ legato()

force_inline bool vital::VoiceHandler::legato ( )
inline

Returns true if legato mode is enabled.

◆ lift()

force_inline Output * vital::VoiceHandler::lift ( )
inline

Returns a pointer to lift, the note-off velocity or release velocity.

◆ local_pitch_bend()

force_inline Output * vital::VoiceHandler::local_pitch_bend ( )
inline

Returns a pointer to local_pitch_bend, the per-voice pitch bend output.

◆ mod_wheel()

force_inline Output * vital::VoiceHandler::mod_wheel ( )
inline

Returns a pointer to mod_wheel, storing the mod wheel value for each channel.

◆ note()

force_inline Output * vital::VoiceHandler::note ( )
inline

Returns a pointer to the note Output, giving the current tuned note frequency or pitch.

◆ note_count()

force_inline Output * vital::VoiceHandler::note_count ( )
inline

Returns a pointer to note_count, a global note counter.

◆ note_in_octave()

force_inline Output * vital::VoiceHandler::note_in_octave ( )
inline

Returns a pointer to note_in_octave, a fractional note position in [0..1).

◆ note_pressed()

force_inline Output * vital::VoiceHandler::note_pressed ( )
inline

Returns a pointer to the note_pressed Output, a count of how many times a note was pressed.

◆ noteOff()

void vital::VoiceHandler::noteOff ( int note,
mono_float lift,
int sample,
int channel )
overridevirtual

Handles a MIDI note-off event, releasing a currently active note.

Parameters
noteThe MIDI note number (0-127).
liftThe release velocity (0.0 to 1.0).
sampleThe sample index at which the note-off occurs.
channelThe MIDI channel on which the note-off occurred.

Implements vital::NoteHandler.

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ noteOn()

void vital::VoiceHandler::noteOn ( int note,
mono_float velocity,
int sample,
int channel )
overridevirtual

Handles a MIDI note-on event, starting a note with a specified velocity and timing.

Parameters
noteThe MIDI note number (0-127).
velocityThe velocity of the note-on event (0.0 to 1.0).
sampleThe sample index at which the note-on occurs.
channelThe MIDI channel on which the note-on occurred.

Implements vital::NoteHandler.

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ pitch_wheel()

force_inline Output * vital::VoiceHandler::pitch_wheel ( )
inline

Returns a pointer to pitch_wheel, storing the pitch-bend range for each channel.

◆ pitch_wheel_percent()

force_inline Output * vital::VoiceHandler::pitch_wheel_percent ( )
inline

Returns a pointer to pitch_wheel_percent, a normalized [0..1] version of pitch_wheel.

◆ polyphony()

force_inline int vital::VoiceHandler::polyphony ( )
inline

Returns the current maximum polyphony (number of active voices allowed).

◆ process()

void vital::VoiceHandler::process ( int num_samples)
overridevirtual

Processes audio for a block of samples. For each active voice, triggers events, updates parameters, and runs its Processor.

Parameters
num_samplesThe number of samples in this processing block.

Reimplemented from vital::ProcessorRouter.

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ registerControlRateOutput()

Output * vital::VoiceHandler::registerControlRateOutput ( Output * output,
bool active )

Registers a control-rate Output with the VoiceHandler.

Parameters
outputThe original Output pointer.
activeWhether this output is "active" (if false, it won't get updates).
Returns
The new control-rate Output pointer owned by VoiceHandler.

◆ registerOutput() [1/2]

Output * vital::VoiceHandler::registerOutput ( Output * output)
overridevirtual

Registers an Output with this VoiceHandler, returning a pointer to a new accumulated or single-lane Output.

Parameters
outputThe original Output pointer from a Processor.
Returns
The new Output pointer (owned by VoiceHandler).

Reimplemented from vital::Processor.

◆ registerOutput() [2/2]

Output * vital::VoiceHandler::registerOutput ( Output * output,
int index )
overridevirtual

Not implemented index-based registerOutput override (asserts false).

Reimplemented from vital::Processor.

◆ removeGlobalProcessor()

void vital::VoiceHandler::removeGlobalProcessor ( Processor * processor)

Removes a Processor from the global router.

◆ removeProcessor()

void vital::VoiceHandler::removeProcessor ( Processor * processor)
overridevirtual

Removes a Processor from this router.

Parameters
processorThe Processor to remove.

Reimplemented from vital::ProcessorRouter.

◆ reset()

force_inline Output * vital::VoiceHandler::reset ( )
inline

Returns a pointer to the reset Output, indicating a full voice reset (On from Dead).

◆ resetFeedbacks()

void vital::VoiceHandler::resetFeedbacks ( poly_mask reset_mask)
overridevirtual

Resets any feedback paths in the poly router, applying the given mask.

Parameters
reset_maskThe mask of voices to reset.

Reimplemented from vital::ProcessorRouter.

◆ retrigger()

force_inline Output * vital::VoiceHandler::retrigger ( )
inline

Returns a pointer to the retrigger Output, used for controlling certain envelope triggers.

◆ setActiveNonaccumulatedOutput()

void vital::VoiceHandler::setActiveNonaccumulatedOutput ( Output * output)

Marks an Output as "active" for non-accumulated usage (e.g., for the last active voice only).

Parameters
outputThe original Output pointer.

◆ setAftertouch()

void vital::VoiceHandler::setAftertouch ( int note,
mono_float aftertouch,
int sample,
int channel )

Handles per-note aftertouch for a specific note and channel.

Parameters
noteThe MIDI note.
aftertouchThe aftertouch value.
sampleThe sample index for the event.
channelMIDI channel.

◆ setChannelAftertouch()

void vital::VoiceHandler::setChannelAftertouch ( int channel,
mono_float aftertouch,
int sample )

Sets channel-wide aftertouch (applies to all voices on that channel).

Parameters
channelMIDI channel.
aftertouchThe aftertouch value.
sampleThe sample index for the event.

◆ setChannelRangeAftertouch()

void vital::VoiceHandler::setChannelRangeAftertouch ( int from_channel,
int to_channel,
mono_float aftertouch,
int sample )

Sets channel-wide aftertouch for a range of channels.

◆ setChannelRangeSlide()

void vital::VoiceHandler::setChannelRangeSlide ( int from_channel,
int to_channel,
mono_float aftertouch,
int sample )

Sets channel-wide MPE "slide" for a range of channels.

◆ setChannelSlide()

void vital::VoiceHandler::setChannelSlide ( int channel,
mono_float aftertouch,
int sample )

Sets channel-wide MPE "slide" for a single channel.

◆ setInactiveNonaccumulatedOutput()

void vital::VoiceHandler::setInactiveNonaccumulatedOutput ( Output * output)

Marks an Output as "inactive" for non-accumulated usage, effectively disabling it.

Parameters
outputThe original Output pointer.

◆ setLegato()

force_inline void vital::VoiceHandler::setLegato ( bool legato)
inline

Enables or disables legato mode (disables retriggers if still in Held state).

Parameters
legatoTrue to enable legato mode, false otherwise.

◆ setModWheel()

force_inline void vital::VoiceHandler::setModWheel ( mono_float value,
int channel = 0 )
inline

Sets the mod wheel value for a single channel.

Parameters
valueThe new mod wheel value [0..1].
channelThe MIDI channel.

◆ setModWheelAllChannels()

force_inline void vital::VoiceHandler::setModWheelAllChannels ( mono_float value)
inline

Sets the mod wheel value for all channels at once.

Parameters
valueThe new mod wheel value [0..1].

◆ setOversampleAmount()

virtual void vital::VoiceHandler::setOversampleAmount ( int oversample)
inlineoverridevirtual

Sets the oversampling factor for both SynthModule and the internal poly/mono routers.

Parameters
oversampleThe new oversampling factor.

Reimplemented from vital::ProcessorRouter.

◆ setPitchWheel()

force_inline void vital::VoiceHandler::setPitchWheel ( mono_float value,
int channel = 0 )
inline

Sets the pitch wheel value for a single channel, applying to all held voices on that channel.

Parameters
valueThe new pitch wheel value [0..1].
channelThe MIDI channel.

◆ setPolyphony()

void vital::VoiceHandler::setPolyphony ( int polyphony)

Sets the polyphony to a new value, allocating or freeing voices as needed.

Parameters
polyphonyThe desired number of voices (1..kMaxActivePolyphony).

◆ setSampleRate()

void vital::VoiceHandler::setSampleRate ( int sample_rate)
overridevirtual

Sets the sample rate for both mono/global and voice (poly) routers.

Parameters
sample_rateThe base sample rate (pre-oversampling).

Reimplemented from vital::ProcessorRouter.

◆ setTuning()

void vital::VoiceHandler::setTuning ( const Tuning * tuning)
inline

Sets the custom Tuning object (if any) for note->frequency conversion.

Parameters
tuningPointer to a Tuning object.

◆ setVoiceKiller() [1/2]

force_inline void vital::VoiceHandler::setVoiceKiller ( const Output * killer)
inline

Specifies an Output from a Processor used to detect silence or inactivity for voice killing.

Parameters
killerA pointer to the "voice killer" Output.

◆ setVoiceKiller() [2/2]

force_inline void vital::VoiceHandler::setVoiceKiller ( const Processor * killer)
inline

Overload for setting the voice killer from a Processor directly.

◆ setVoiceMidi()

force_inline void vital::VoiceHandler::setVoiceMidi ( const Output * midi)
inline

Sets the Output that provides the current MIDI note for the voice.

Parameters
midiOutput pointer (e.g., note_).

◆ setZonedPitchWheel()

force_inline void vital::VoiceHandler::setZonedPitchWheel ( mono_float value,
int from_channel,
int to_channel )
inline

Sets pitch wheel in a zoned manner for a range of MIDI channels.

Parameters
valueThe new pitch wheel value.
from_channelStarting channel.
to_channelEnding channel (inclusive).

◆ shouldAccumulate()

bool vital::VoiceHandler::shouldAccumulate ( Output * output)
protectedvirtual

Determines whether an Output should be summed across voices (accumulated) or handled individually.

Parameters
outputThe Output pointer.
Returns
True if it should be accumulated, false if not (e.g., control-rate).

Reimplemented in vital::EffectsModulationHandler, and vital::SynthVoiceHandler.

◆ slide()

force_inline Output * vital::VoiceHandler::slide ( )
inline

Returns a pointer to slide, the MPE "slide" expression value.

◆ sostenutoOff()

void vital::VoiceHandler::sostenutoOff ( int sample,
int channel )

Turns off sostenuto for a single channel, prompting release if not sustained.

◆ sostenutoOffRange()

void vital::VoiceHandler::sostenutoOffRange ( int sample,
int from_channel,
int to_channel )

Turns off sostenuto for a range of channels, prompting release if not sustained.

◆ sostenutoOn()

void vital::VoiceHandler::sostenutoOn ( int channel)

Turns on sostenuto for a single channel.

◆ sostenutoOnRange()

void vital::VoiceHandler::sostenutoOnRange ( int from_channel,
int to_channel )

Turns on sostenuto for a range of channels.

◆ sustainOff()

void vital::VoiceHandler::sustainOff ( int sample,
int channel )

Turns off sustain for a single channel, prompting voices to release.

◆ sustainOffRange()

void vital::VoiceHandler::sustainOffRange ( int sample,
int from_channel,
int to_channel )

Turns off sustain for a range of channels, prompting voices to release.

◆ sustainOn()

void vital::VoiceHandler::sustainOn ( int channel)

Turns on sustain for a single channel.

◆ sustainOnRange()

void vital::VoiceHandler::sustainOnRange ( int from_channel,
int to_channel )

Turns on sustain for a range of channels.

◆ velocity()

force_inline Output * vital::VoiceHandler::velocity ( )
inline

Returns a pointer to velocity, the note-on velocity.

◆ voice_event()

force_inline Output * vital::VoiceHandler::voice_event ( )
inline

Returns a pointer to the voice_event Output, used to track voice On/Off/Kill events.

Member Data Documentation

◆ kLocalPitchBendRange

mono_float vital::VoiceHandler::kLocalPitchBendRange = 48.0f
staticconstexpr

Range of local pitch bend in semitones for each voice.


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