Removing all active Midi Notes

Hi everyone! I am currently making my first Plugin, and I ran into some very specific issues: In this plugin, the user can select the song’s key, which will influence the midi that is played, i.e. the midi will be transposed in some way. It all works fine so far, but when the user changes key during the playback (which might happen if the key parameter is automated for example) an issue occurs: The currently active notes will ring out forever, because the NoteOff message is never sent correctly in this case (it gets transposed). I would like to remove this problem. The easiest way would be to remove all current midi whenever the user selects the key. I thought this implementation in the processBlock would work:

void MIditestAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages)
{
// clear anything that might intererfere (current buffer and left over audio)
buffer.clear();

if (MIditestAudioProcessor::midiProcessor.notesNeedClearing)
{
	// Send "All Sound Off" for each channel
	for (int channel = 1; channel <= 16; ++channel)
	{
		midiMessages.addEvent(juce::MidiMessage::allSoundOff(channel), 0);
	}

	MIditestAudioProcessor::midiProcessor.notesNeedClearing = false;  // Reset the flag
}

// Process existing MIDI messages


midiProcessor.process(midiMessages);

}

notesNeedClearing is a flag, that is set to ‘true’ whenever the user changes key. But allSoundOff just seems to do nothing, the notes still ring out. Is there a command that will tell the DAW to just stop all Midi Notes right now? I should add that I have also tried allNotesOff and allControllersOff. Would these commands work if i used them differently? Many thanks in advance!

It would depend on the target synth if that works or not, I don’t think it’s mandatory for synths/plugins to implement that.

You should either :

  • Send explicit note offs for all notes in all channels

or

  • Keep track of what notes you’ve activated/deactivated yourself and when needed send the needed note offs based on that tracking

Oh okay, thanks for the reply! I’ll give it a shot.