Vital
Loading...
Searching...
No Matches
MidiManager Class Reference

The MidiManager class handles all incoming MIDI messages and directs them to the synthesizer engine. More...

#include <midi_manager.h>

Inheritance diagram for MidiManager:
MidiInputCallback

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).
 
- Public Member Functions inherited from MidiInputCallback
virtual ~MidiInputCallback ()
 

Protected Member Functions

void readMpeMessage (const MidiMessage &message)
 Parses and processes an MPE-related MIDI message.
 

Protected Attributes

SynthBasesynth_
 Associated synthesizer base instance.
 
vital::SoundEngineengine_
 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.
 
Listenerlistener_
 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::ValueDetailsarmed_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.
 

Detailed Description

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:

  • Process note on/off, pitch bend, mod wheel, aftertouch, and other MIDI control messages.
  • Handle MPE (MIDI Polyphonic Expression) messages if enabled.
  • Support MIDI learn functionality, allowing MIDI controls to be dynamically mapped to synth parameters.
  • Relay MIDI-driven preset changes and gather MIDI input from external sources.

Member Typedef Documentation

◆ midi_map

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.

Member Enumeration Documentation

◆ MidiMainType

Enum representing main categories of MIDI events (status bytes).

Enumerator
kNoteOff 

MIDI Note Off event.

kNoteOn 

MIDI Note On event.

kAftertouch 

MIDI Polyphonic Aftertouch.

kController 

MIDI Control Change event.

kProgramChange 

MIDI Program Change.

kChannelPressure 

MIDI Channel Pressure (monophonic aftertouch)

kPitchWheel 

MIDI Pitch Wheel event.

◆ MidiSecondaryType

Enum representing secondary MIDI controller values (MIDI CC numbers).

Enumerator
kBankSelect 
kModWheel 
kFolderSelect 
kSustainPedal 
kSostenutoPedal 
kSoftPedalOn 
kSlide 
kLsbPressure 
kLsbSlide 
kAllSoundsOff 
kAllControllersOff 
kAllNotesOff 

Constructor & Destructor Documentation

◆ MidiManager()

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.

Parameters
synthA pointer to the SynthBase to receive MIDI events.
keyboard_stateA pointer to a MidiKeyboardState for GUI keyboard handling.
gui_stateA map of GUI-related state strings.
listenerA listener for MIDI-driven parameter changes and preset loads, if any.

◆ ~MidiManager()

MidiManager::~MidiManager ( )
virtual

Destructor.

Member Function Documentation

◆ armMidiLearn()

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.

Parameters
nameThe parameter name to arm for MIDI learn.

◆ cancelMidiLearn()

void MidiManager::cancelMidiLearn ( )

Cancels the MIDI learn operation without assigning any mapping.

◆ clearMidiLearn()

void MidiManager::clearMidiLearn ( const std::string & name)

Clears an existing MIDI mapping for a given parameter.

Parameters
nameThe parameter name whose MIDI mapping will be cleared.

◆ getMidiLearnMap()

midi_map MidiManager::getMidiLearnMap ( )
inline

Returns the current MIDI learn map.

Returns
The current midi_map structure.

◆ handleIncomingMidiMessage()

void MidiManager::handleIncomingMidiMessage ( MidiInput * source,
const MidiMessage & midi_message )
overridevirtual

Handles incoming MIDI messages from a MidiInput source (MidiInputCallback interface).

Adds messages to the MidiMessageCollector queue for processing.

Parameters
sourceThe MidiInput source that provided the message.
midi_messageThe incoming MIDI message.

Reimplemented from MidiInputCallback.

◆ isMidiMapped()

bool MidiManager::isMidiMapped ( const std::string & name) const

Checks if a parameter is already mapped to a MIDI control.

Parameters
nameThe parameter name.
Returns
True if the parameter is MIDI-mapped, false otherwise.

◆ isMpeChannelMasterLowerZone()

force_inline bool MidiManager::isMpeChannelMasterLowerZone ( int channel)

Checks if the given channel is the MPE master channel for the lower zone.

Parameters
channelThe 0-based MIDI channel.
Returns
True if it is the MPE lower zone master channel.

◆ isMpeChannelMasterUpperZone()

force_inline bool MidiManager::isMpeChannelMasterUpperZone ( int channel)

Checks if the given channel is the MPE master channel for the upper zone.

Parameters
channelThe 0-based MIDI channel.
Returns
True if it is the MPE upper zone master channel.

◆ lowerMasterChannel()

force_inline int MidiManager::lowerMasterChannel ( )
inline

Returns the master channel index (0-based) of the MPE lower zone.

◆ lowerZoneEndChannel()

force_inline int MidiManager::lowerZoneEndChannel ( )
inline

Returns the end channel index (0-based) of the MPE lower zone.

◆ lowerZoneStartChannel()

force_inline int MidiManager::lowerZoneStartChannel ( )
inline

Returns the start channel index (0-based) of the MPE lower zone.

◆ midiInput()

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.

Parameters
controlThe MIDI control number.
valueThe MIDI value, generally 0-127.

◆ processAllNotesOff()

void MidiManager::processAllNotesOff ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes an 'All Notes Off' MIDI message.

Parameters
midi_messageThe MIDI message triggering the event.
sample_positionThe timing sample position.
channelThe MIDI channel (0-based) affected.

◆ processAllSoundsOff()

void MidiManager::processAllSoundsOff ( )

Processes an 'All Sounds Off' MIDI message, turning off all voices immediately.

◆ processMidiMessage()

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.

Parameters
midi_messageThe incoming MIDI message.
sample_positionThe sample frame position for timing (optional).

◆ processPitchBend()

void MidiManager::processPitchBend ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes a pitch bend MIDI message.

Parameters
midi_messageThe pitch bend message.
sample_positionThe timing sample position.
channelThe MIDI channel affected.

◆ processPressure()

void MidiManager::processPressure ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes channel pressure (aftertouch) MIDI messages.

Parameters
midi_messageThe aftertouch message.
sample_positionThe timing sample position.
channelThe MIDI channel affected.

◆ processSlide()

void MidiManager::processSlide ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes slide messages (MPE CC events) translating them to appropriate modulation.

Parameters
midi_messageThe slide-related CC message.
sample_positionThe timing sample position.
channelThe MIDI channel affected.

◆ processSostenuto()

void MidiManager::processSostenuto ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes a sostenuto pedal MIDI message.

Parameters
midi_messageThe MIDI sostenuto message.
sample_positionThe timing sample position.
channelThe MIDI channel affected.

◆ processSustain()

void MidiManager::processSustain ( const MidiMessage & midi_message,
int sample_position,
int channel )

Processes a sustain pedal MIDI message.

Parameters
midi_messageThe MIDI sustain message.
sample_positionThe timing sample position.
channelThe MIDI channel affected.

◆ readMpeMessage()

void MidiManager::readMpeMessage ( const MidiMessage & message)
protected

Parses and processes an MPE-related MIDI message.

Parameters
messageThe MIDI message to process.

◆ removeNextBlockOfMessages()

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.

Parameters
bufferA reference to the MidiBuffer to fill.
num_samplesThe number of audio samples in the current buffer.

◆ replaceKeyboardMessages()

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.

Parameters
bufferThe MidiBuffer to process.
num_samplesThe number of samples in the current audio block.

◆ setMidiLearnMap()

void MidiManager::setMidiLearnMap ( const midi_map & midi_learn_map)
inline

Sets the current MIDI learn map, overriding existing mappings.

Parameters
midi_learn_mapA midi_map of control-to-parameter assignments.

◆ setMpeEnabled()

void MidiManager::setMpeEnabled ( bool enabled)
inline

Enables or disables MPE mode for MIDI processing.

Parameters
enabledTrue to enable MPE, false to disable.

◆ setSampleRate()

void MidiManager::setSampleRate ( double sample_rate)

Sets the audio sample rate for MIDI message timing.

Parameters
sample_rateThe sample rate in Hz.

◆ upperMasterChannel()

force_inline int MidiManager::upperMasterChannel ( )
inline

Returns the master channel index (0-based) of the MPE upper zone.

◆ upperZoneEndChannel()

force_inline int MidiManager::upperZoneEndChannel ( )
inline

Returns the end channel index (0-based) of the MPE upper zone.

◆ upperZoneStartChannel()

force_inline int MidiManager::upperZoneStartChannel ( )
inline

Returns the start channel index (0-based) of the MPE upper zone.

Member Data Documentation

◆ armed_value_

const vital::ValueDetails* MidiManager::armed_value_
protected

Parameter armed for MIDI learn.

◆ current_bank_

int MidiManager::current_bank_
protected

Tracks the current bank for preset selection.

◆ current_folder_

int MidiManager::current_folder_
protected

Tracks the current folder for preset selection.

◆ current_preset_

int MidiManager::current_preset_
protected

Tracks the current preset within a folder.

◆ engine_

vital::SoundEngine* MidiManager::engine_
protected

The sound engine for handling audio events.

◆ gui_state_

std::map<std::string, String>* MidiManager::gui_state_
protected

Holds GUI-related state info.

◆ keyboard_state_

MidiKeyboardState* MidiManager::keyboard_state_
protected

The keyboard state for on-screen keyboard integration.

◆ listener_

Listener* MidiManager::listener_
protected

Listener for MIDI-driven parameter changes and preset loads.

◆ lsb_pressure_values_

int MidiManager::lsb_pressure_values_[vital::kNumMidiChannels]
protected

LSB values for channel pressure.

◆ lsb_slide_values_

int MidiManager::lsb_slide_values_[vital::kNumMidiChannels]
protected

LSB values for slide control.

◆ midi_collector_

MidiMessageCollector MidiManager::midi_collector_
protected

Collects incoming MIDI messages.

◆ midi_learn_map_

midi_map MidiManager::midi_learn_map_
protected

Mapping of MIDI controls to synth parameters.

◆ mpe_enabled_

bool MidiManager::mpe_enabled_
protected

True if MPE mode is enabled.

◆ mpe_zone_layout_

MPEZoneLayout MidiManager::mpe_zone_layout_
protected

MPE zone layout object.

◆ msb_pressure_values_

int MidiManager::msb_pressure_values_[vital::kNumMidiChannels]
protected

MSB values for channel pressure.

◆ msb_slide_values_

int MidiManager::msb_slide_values_[vital::kNumMidiChannels]
protected

MSB values for slide control.

◆ rpn_detector_

MidiRPNDetector MidiManager::rpn_detector_
protected

Detects and processes MIDI RPN/NRPN messages.

◆ synth_

SynthBase* MidiManager::synth_
protected

Associated synthesizer base instance.


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