Vital
|
The MidiManager class handles all incoming MIDI messages and directs them to the synthesizer engine. More...
#include <midi_manager.h>
Classes | |
class | Listener |
An interface for classes that listen to MIDI-driven parameter changes. More... | |
struct | PresetLoadedCallback |
A callback message class that notifies listeners of preset changes through MIDI. More... | |
Public Types | |
enum | MidiMainType { kNoteOff = 0x80 , kNoteOn = 0x90 , kAftertouch = 0xa0 , kController = 0xb0 , kProgramChange = 0xc0 , kChannelPressure = 0xd0 , kPitchWheel = 0xe0 } |
Enum representing main categories of MIDI events (status bytes). More... | |
enum | MidiSecondaryType { kBankSelect = 0x00 , kModWheel = 0x01 , kFolderSelect = 0x20 , kSustainPedal = 0x40 , kSostenutoPedal = 0x42 , kSoftPedalOn = 0x43 , kSlide = 0x4a , kLsbPressure = 0x66 , kLsbSlide = 0x6a , kAllSoundsOff = 0x78 , kAllControllersOff = 0x79 , kAllNotesOff = 0x7b } |
Enum representing secondary MIDI controller values (MIDI CC numbers). More... | |
typedef std::map< int, std::map< std::string, const vital::ValueDetails * > > | midi_map |
A nested type defining a map from MIDI controls to a map of parameter names and their ValueDetails. | |
Public Member Functions | |
MidiManager (SynthBase *synth, MidiKeyboardState *keyboard_state, std::map< std::string, String > *gui_state, Listener *listener=nullptr) | |
Constructs a MidiManager to handle MIDI events for a given SynthBase instance. | |
virtual | ~MidiManager () |
Destructor. | |
void | armMidiLearn (std::string name) |
Arms the MIDI learn functionality for a given parameter. | |
void | cancelMidiLearn () |
Cancels the MIDI learn operation without assigning any mapping. | |
void | clearMidiLearn (const std::string &name) |
Clears an existing MIDI mapping for a given parameter. | |
void | midiInput (int control, vital::mono_float value) |
Handles a direct MIDI input value and applies MIDI learn if armed. | |
void | processMidiMessage (const MidiMessage &midi_message, int sample_position=0) |
Processes a given MIDI message and forwards it to the synth engine. | |
bool | isMidiMapped (const std::string &name) const |
Checks if a parameter is already mapped to a MIDI control. | |
void | setSampleRate (double sample_rate) |
Sets the audio sample rate for MIDI message timing. | |
void | removeNextBlockOfMessages (MidiBuffer &buffer, int num_samples) |
Removes the next block of MIDI messages, filling a MidiBuffer. | |
void | replaceKeyboardMessages (MidiBuffer &buffer, int num_samples) |
Replaces keyboard messages in the given MIDI buffer. | |
void | processAllNotesOff (const MidiMessage &midi_message, int sample_position, int channel) |
Processes an 'All Notes Off' MIDI message. | |
void | processAllSoundsOff () |
Processes an 'All Sounds Off' MIDI message, turning off all voices immediately. | |
void | processSustain (const MidiMessage &midi_message, int sample_position, int channel) |
Processes a sustain pedal MIDI message. | |
void | processSostenuto (const MidiMessage &midi_message, int sample_position, int channel) |
Processes a sostenuto pedal MIDI message. | |
void | processPitchBend (const MidiMessage &midi_message, int sample_position, int channel) |
Processes a pitch bend MIDI message. | |
void | processPressure (const MidiMessage &midi_message, int sample_position, int channel) |
Processes channel pressure (aftertouch) MIDI messages. | |
void | processSlide (const MidiMessage &midi_message, int sample_position, int channel) |
Processes slide messages (MPE CC events) translating them to appropriate modulation. | |
bool | isMpeChannelMasterLowerZone (int channel) |
Checks if the given channel is the MPE master channel for the lower zone. | |
bool | isMpeChannelMasterUpperZone (int channel) |
Checks if the given channel is the MPE master channel for the upper zone. | |
force_inline int | lowerZoneStartChannel () |
Returns the start channel index (0-based) of the MPE lower zone. | |
force_inline int | upperZoneStartChannel () |
Returns the start channel index (0-based) of the MPE upper zone. | |
force_inline int | lowerZoneEndChannel () |
Returns the end channel index (0-based) of the MPE lower zone. | |
force_inline int | upperZoneEndChannel () |
Returns the end channel index (0-based) of the MPE upper zone. | |
force_inline int | lowerMasterChannel () |
Returns the master channel index (0-based) of the MPE lower zone. | |
force_inline int | upperMasterChannel () |
Returns the master channel index (0-based) of the MPE upper zone. | |
void | setMpeEnabled (bool enabled) |
Enables or disables MPE mode for MIDI processing. | |
midi_map | getMidiLearnMap () |
Returns the current MIDI learn map. | |
void | setMidiLearnMap (const midi_map &midi_learn_map) |
Sets the current MIDI learn map, overriding existing mappings. | |
void | handleIncomingMidiMessage (MidiInput *source, const MidiMessage &midi_message) override |
Handles incoming MIDI messages from a MidiInput source (MidiInputCallback interface). | |
![]() | |
virtual | ~MidiInputCallback () |
Protected Member Functions | |
void | readMpeMessage (const MidiMessage &message) |
Parses and processes an MPE-related MIDI message. | |
Protected Attributes | |
SynthBase * | synth_ |
Associated synthesizer base instance. | |
vital::SoundEngine * | engine_ |
The sound engine for handling audio events. | |
MidiKeyboardState * | keyboard_state_ |
The keyboard state for on-screen keyboard integration. | |
MidiMessageCollector | midi_collector_ |
Collects incoming MIDI messages. | |
std::map< std::string, String > * | gui_state_ |
Holds GUI-related state info. | |
Listener * | listener_ |
Listener for MIDI-driven parameter changes and preset loads. | |
int | current_bank_ |
Tracks the current bank for preset selection. | |
int | current_folder_ |
Tracks the current folder for preset selection. | |
int | current_preset_ |
Tracks the current preset within a folder. | |
const vital::ValueDetails * | armed_value_ |
Parameter armed for MIDI learn. | |
midi_map | midi_learn_map_ |
Mapping of MIDI controls to synth parameters. | |
int | msb_pressure_values_ [vital::kNumMidiChannels] |
MSB values for channel pressure. | |
int | lsb_pressure_values_ [vital::kNumMidiChannels] |
LSB values for channel pressure. | |
int | msb_slide_values_ [vital::kNumMidiChannels] |
MSB values for slide control. | |
int | lsb_slide_values_ [vital::kNumMidiChannels] |
LSB values for slide control. | |
bool | mpe_enabled_ |
True if MPE mode is enabled. | |
MPEZoneLayout | mpe_zone_layout_ |
MPE zone layout object. | |
MidiRPNDetector | rpn_detector_ |
Detects and processes MIDI RPN/NRPN messages. | |
The MidiManager class handles all incoming MIDI messages and directs them to the synthesizer engine.
This class interfaces with both the JUCE MIDI subsystem and the Vital SoundEngine
. It can:
std::map<int, std::map<std::string, const vital::ValueDetails*> > MidiManager::midi_map |
A nested type defining a map from MIDI controls to a map of parameter names and their ValueDetails.
The outer map key (int) corresponds to a MIDI control number, and the inner map relates parameter names (strings) to pointers of their associated ValueDetails struct.
Enum representing main categories of MIDI events (status bytes).
MidiManager::MidiManager | ( | SynthBase * | synth, |
MidiKeyboardState * | keyboard_state, | ||
std::map< std::string, String > * | gui_state, | ||
Listener * | listener = nullptr ) |
Constructs a MidiManager to handle MIDI events for a given SynthBase instance.
synth | A pointer to the SynthBase to receive MIDI events. |
keyboard_state | A pointer to a MidiKeyboardState for GUI keyboard handling. |
gui_state | A map of GUI-related state strings. |
listener | A listener for MIDI-driven parameter changes and preset loads, if any. |
|
virtual |
Destructor.
void MidiManager::armMidiLearn | ( | std::string | name | ) |
Arms the MIDI learn functionality for a given parameter.
The next MIDI control message will map that parameter to the corresponding MIDI control.
name | The parameter name to arm for MIDI learn. |
void MidiManager::cancelMidiLearn | ( | ) |
Cancels the MIDI learn operation without assigning any mapping.
void MidiManager::clearMidiLearn | ( | const std::string & | name | ) |
Clears an existing MIDI mapping for a given parameter.
name | The parameter name whose MIDI mapping will be cleared. |
|
inline |
Returns the current MIDI learn map.
|
overridevirtual |
Handles incoming MIDI messages from a MidiInput source (MidiInputCallback interface).
Adds messages to the MidiMessageCollector queue for processing.
source | The MidiInput source that provided the message. |
midi_message | The incoming MIDI message. |
Reimplemented from MidiInputCallback.
bool MidiManager::isMidiMapped | ( | const std::string & | name | ) | const |
Checks if a parameter is already mapped to a MIDI control.
name | The parameter name. |
force_inline bool MidiManager::isMpeChannelMasterLowerZone | ( | int | channel | ) |
Checks if the given channel is the MPE master channel for the lower zone.
channel | The 0-based MIDI channel. |
force_inline bool MidiManager::isMpeChannelMasterUpperZone | ( | int | channel | ) |
Checks if the given channel is the MPE master channel for the upper zone.
channel | The 0-based MIDI channel. |
|
inline |
Returns the master channel index (0-based) of the MPE lower zone.
|
inline |
Returns the end channel index (0-based) of the MPE lower zone.
|
inline |
Returns the start channel index (0-based) of the MPE lower zone.
void MidiManager::midiInput | ( | int | control, |
vital::mono_float | value ) |
Handles a direct MIDI input value and applies MIDI learn if armed.
If MIDI learn is armed, this maps the armed parameter to the given MIDI control. Otherwise, it updates any parameters already mapped to that MIDI control.
control | The MIDI control number. |
value | The MIDI value, generally 0-127. |
void MidiManager::processAllNotesOff | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes an 'All Notes Off' MIDI message.
midi_message | The MIDI message triggering the event. |
sample_position | The timing sample position. |
channel | The MIDI channel (0-based) affected. |
void MidiManager::processAllSoundsOff | ( | ) |
Processes an 'All Sounds Off' MIDI message, turning off all voices immediately.
void MidiManager::processMidiMessage | ( | const MidiMessage & | midi_message, |
int | sample_position = 0 ) |
Processes a given MIDI message and forwards it to the synth engine.
This handles note on/off, control changes, pitch bend, aftertouch, etc.
midi_message | The incoming MIDI message. |
sample_position | The sample frame position for timing (optional). |
void MidiManager::processPitchBend | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes a pitch bend MIDI message.
midi_message | The pitch bend message. |
sample_position | The timing sample position. |
channel | The MIDI channel affected. |
void MidiManager::processPressure | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes channel pressure (aftertouch) MIDI messages.
midi_message | The aftertouch message. |
sample_position | The timing sample position. |
channel | The MIDI channel affected. |
void MidiManager::processSlide | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes slide messages (MPE CC events) translating them to appropriate modulation.
midi_message | The slide-related CC message. |
sample_position | The timing sample position. |
channel | The MIDI channel affected. |
void MidiManager::processSostenuto | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes a sostenuto pedal MIDI message.
midi_message | The MIDI sostenuto message. |
sample_position | The timing sample position. |
channel | The MIDI channel affected. |
void MidiManager::processSustain | ( | const MidiMessage & | midi_message, |
int | sample_position, | ||
int | channel ) |
Processes a sustain pedal MIDI message.
midi_message | The MIDI sustain message. |
sample_position | The timing sample position. |
channel | The MIDI channel affected. |
|
protected |
Parses and processes an MPE-related MIDI message.
message | The MIDI message to process. |
void MidiManager::removeNextBlockOfMessages | ( | MidiBuffer & | buffer, |
int | num_samples ) |
Removes the next block of MIDI messages, filling a MidiBuffer.
This is typically called every audio block to retrieve pending MIDI events.
buffer | A reference to the MidiBuffer to fill. |
num_samples | The number of audio samples in the current buffer. |
void MidiManager::replaceKeyboardMessages | ( | MidiBuffer & | buffer, |
int | num_samples ) |
Replaces keyboard messages in the given MIDI buffer.
This allows on-screen keyboard events to be integrated into the MIDI processing flow.
buffer | The MidiBuffer to process. |
num_samples | The number of samples in the current audio block. |
|
inline |
Sets the current MIDI learn map, overriding existing mappings.
midi_learn_map | A midi_map of control-to-parameter assignments. |
|
inline |
Enables or disables MPE mode for MIDI processing.
enabled | True to enable MPE, false to disable. |
void MidiManager::setSampleRate | ( | double | sample_rate | ) |
Sets the audio sample rate for MIDI message timing.
sample_rate | The sample rate in Hz. |
|
inline |
Returns the master channel index (0-based) of the MPE upper zone.
|
inline |
Returns the end channel index (0-based) of the MPE upper zone.
|
inline |
Returns the start channel index (0-based) of the MPE upper zone.
|
protected |
Parameter armed for MIDI learn.
|
protected |
Tracks the current bank for preset selection.
|
protected |
Tracks the current folder for preset selection.
|
protected |
Tracks the current preset within a folder.
|
protected |
The sound engine for handling audio events.
|
protected |
Holds GUI-related state info.
|
protected |
The keyboard state for on-screen keyboard integration.
|
protected |
Listener for MIDI-driven parameter changes and preset loads.
|
protected |
LSB values for channel pressure.
|
protected |
LSB values for slide control.
|
protected |
Collects incoming MIDI messages.
|
protected |
Mapping of MIDI controls to synth parameters.
|
protected |
True if MPE mode is enabled.
|
protected |
MPE zone layout object.
|
protected |
MSB values for channel pressure.
|
protected |
MSB values for slide control.
|
protected |
Detects and processes MIDI RPN/NRPN messages.
|
protected |
Associated synthesizer base instance.