Gin
Loading...
Searching...
No Matches
MidiLearn Class Reference

MIDI Learn system for mapping MIDI CC messages to plugin parameters. More...

#include <gin_midilearn.h>

Public Member Functions

 MidiLearn (gin::Processor &p)
 ~MidiLearn ()
void setSampleRate (double sr)
void setIgnoredCCs (const juce::Array< int > &ccNumbers)
 CCs the plugin handles itself (sustain pedal, mod wheel, etc).
bool isIgnoredCC (int ccNumber) const
void setMapping (int ccNumber, gin::Parameter *param)
void clearMapping (int ccNumber)
void clearMapping (gin::Parameter *param)
gin::Parameter * getMapping (int ccNumber) const
int getMappedCC (gin::Parameter *param) const
void startLearning (gin::Parameter *param)
void cancelLearning ()
bool isLearning () const
gin::Parameter * getLearningParameter () const
void processBlock (juce::MidiBuffer &midi, int numSamples)
void loadState (const juce::ValueTree &vt)
void saveState (juce::ValueTree &vt)

Static Public Member Functions

static bool isValidCC (int ccNumber)
 Returns true if the CC number is valid for MIDI learn.

Detailed Description

MIDI Learn system for mapping MIDI CC messages to plugin parameters.

MidiLearn provides a way to associate MIDI CC controllers (0-127) with plugin parameters. When a CC message is received, it automatically updates the corresponding parameter value and handles proper host notification with gesture begin/end tracking.

Key Features:

  • Maps 128 MIDI CC controllers to parameters
  • Automatic host notification for parameter changes
  • Gesture timeout (333ms) for grouping rapid CC changes
  • Auto-detects relative (two's-complement) delta encoders during learn, applying increments instead of absolute values. Existing maps without the flag load as absolute.
  • CCs the plugin handles itself (e.g. sustain pedal) can be excluded via setIgnoredCCs / ProcessorOptions::withMidiLearn
  • State persistence via ValueTree

Usage:

MidiLearn midiLearn(processor);
// Setup
midiLearn.setSampleRate(44100.0);
midiLearn.setMapping(1, modWheelParam); // CC1 -> mod wheel param
// In processBlock
midiLearn.processBlock(midiBuffer, numSamples);
// Save/load state
midiLearn.saveState(state);
midiLearn.loadState(state);
MidiLearn(gin::Processor &p)
See also
Parameter, Processor

Constructor & Destructor Documentation

◆ MidiLearn()

MidiLearn::MidiLearn ( gin::Processor & p)

◆ ~MidiLearn()

MidiLearn::~MidiLearn ( )

Member Function Documentation

◆ setSampleRate()

void MidiLearn::setSampleRate ( double sr)

◆ setIgnoredCCs()

void MidiLearn::setIgnoredCCs ( const juce::Array< int > & ccNumbers)

CCs the plugin handles itself (sustain pedal, mod wheel, etc).

Ignored CCs are never learned, never applied, and mappings saved for them are dropped on load.

◆ isIgnoredCC()

bool MidiLearn::isIgnoredCC ( int ccNumber) const

◆ setMapping()

void MidiLearn::setMapping ( int ccNumber,
gin::Parameter * param )

◆ clearMapping() [1/2]

void MidiLearn::clearMapping ( int ccNumber)

◆ clearMapping() [2/2]

void MidiLearn::clearMapping ( gin::Parameter * param)

◆ getMapping()

gin::Parameter * MidiLearn::getMapping ( int ccNumber) const

◆ getMappedCC()

int MidiLearn::getMappedCC ( gin::Parameter * param) const

◆ startLearning()

void MidiLearn::startLearning ( gin::Parameter * param)

◆ cancelLearning()

void MidiLearn::cancelLearning ( )

◆ isLearning()

bool MidiLearn::isLearning ( ) const

◆ getLearningParameter()

gin::Parameter * MidiLearn::getLearningParameter ( ) const

◆ processBlock()

void MidiLearn::processBlock ( juce::MidiBuffer & midi,
int numSamples )

◆ loadState()

void MidiLearn::loadState ( const juce::ValueTree & vt)

◆ saveState()

void MidiLearn::saveState ( juce::ValueTree & vt)

◆ isValidCC()

bool MidiLearn::isValidCC ( int ccNumber)
static

Returns true if the CC number is valid for MIDI learn.

Excludes CC 0 (Bank Select MSB), CC 32 (Bank Select LSB), and CC 120-127 (Channel Mode Messages).


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