Class NPlugMidiLearn
IMidiLearnService on top of the VST3 MIDI mapping of a controller: the host turns the assigned MIDI
controllers into parameter changes (IMidiMapping), learning listens to the live controllers the host reports
(IMidiLearn::onLiveMIDIControllerInput). Created by PluginUIController<TModel>, which saves the
assignments with the controller state.
public sealed class NPlugMidiLearn : IMidiLearnService
- Inheritance
-
NPlugMidiLearn
- Implements
- Inherited Members
Remarks
Learning needs a host that reports live MIDI controllers (VST3 IMidiLearn, e.g. Cubase and Nuendo); in
other hosts the learn entry stays pending until cancelled and the host's own MIDI learn remains available.
Assignments are per MIDI channel unless LearnOnAllChannels is set, and take precedence over the
fixed mappings declared with SetMidiCCMapping. All members run on the UI thread.
Constructors
NPlugMidiLearn(Func<IAudioControllerHandler?>)
Creates the service.
public NPlugMidiLearn(Func<IAudioControllerHandler?> handler)
Parameters
handlerFunc<IAudioControllerHandler>Returns the host handler (used to notify mapping changes); may return
null.
Properties
Assignments
Learned assignments: (channel, controller) → parameter; channel −1 means every channel.
public IReadOnlyDictionary<(int Channel, int Controller), AudioParameterId> Assignments { get; }
Property Value
- IReadOnlyDictionary<(int Channel, int Controller), AudioParameterId>
LearnOnAllChannels
When true, a learned controller applies to every MIDI channel (default: only the channel it came from).
public bool LearnOnAllChannels { get; set; }
Property Value
LearningParameter
Parameter waiting for a controller, or null.
public AudioParameterId? LearningParameter { get; }
Property Value
- AudioParameterId?
Methods
Assign(AudioParameterId, int, int)
Assigns a controller to a parameter, replacing the previous assignment of that controller.
public void Assign(AudioParameterId parameter, int channel, int controller)
Parameters
parameterAudioParameterIdThe parameter id.
channelintMIDI channel, 0-based, or −1 for every channel.
controllerintController number: 0..127, 128 (aftertouch) or 129 (pitch bend).
Exceptions
- ArgumentOutOfRangeException
The channel or the controller is out of range.
BeginLearn(IParameter)
Starts learning for a parameter (cancels any other learn in progress).
public void BeginLearn(IParameter parameter)
Parameters
parameterIParameterThe parameter to assign to the next MIDI controller moved.
CancelLearn()
Cancels the learn in progress, if any.
public void CancelLearn()
Clear()
Removes every assignment.
public void Clear()
Describe(int, int)
Text of an assignment ("CC 74 · Ch 1", "Pitch Bend", channel −1 = every channel).
public static string Describe(int channel, int controller)
Parameters
Returns
- string
The description.
Forget(AudioParameterId)
Removes every assignment of a parameter.
public void Forget(AudioParameterId parameter)
Parameters
parameterAudioParameterIdThe parameter id.
Forget(IParameter)
Removes the MIDI assignment of a parameter.
public void Forget(IParameter parameter)
Parameters
parameterIParameterA parameter.
GetAssignment(IParameter)
Short description of the assignment (e.g. "CC 74 · Ch 1"), or null if the parameter has none.
public string? GetAssignment(IParameter parameter)
Parameters
parameterIParameterA parameter.
Returns
- string
The assignment text, or
null.
IsLearning(IParameter)
true while parameter waits for a MIDI controller.
public bool IsLearning(IParameter parameter)
Parameters
parameterIParameterA parameter.
Returns
- bool
trueif learning for this parameter.
Load(PortableBinaryReader)
Reads assignments written by Save(PortableBinaryWriter). A state without them (saved by an older version of the plug-in) leaves the service empty and, when the stream can seek, the stream where it was.
public bool Load(PortableBinaryReader reader)
Parameters
readerPortableBinaryReaderThe reader.
Returns
- bool
trueif assignments were found.
OnLiveController(int, int, AudioMidiControllerNumber)
Live controller reported by the host: completes a learn in progress.
public bool OnLiveController(int busIndex, int channel, AudioMidiControllerNumber controller)
Parameters
busIndexintEvent input bus.
channelintMIDI channel, 0-based.
controllerAudioMidiControllerNumberController number.
Returns
- bool
trueif the controller was used (the assignment changed).
Save(PortableBinaryWriter)
Writes the assignments (controller state).
public void Save(PortableBinaryWriter writer)
Parameters
writerPortableBinaryWriterThe writer.
TryGetAssignment(int, int, AudioMidiControllerNumber, out AudioParameterId)
Parameter assigned to a controller on a channel (IMidiMapping query).
public bool TryGetAssignment(int busIndex, int channel, AudioMidiControllerNumber controller, out AudioParameterId parameter)
Parameters
busIndexintEvent input bus.
channelintMIDI channel, 0-based.
controllerAudioMidiControllerNumberController number.
parameterAudioParameterIdThe assigned parameter.
Returns
- bool
trueif a learned assignment exists.
Events
Changed
Raised when a learn starts, ends, or an assignment changes.
public event Action? Changed