Toggle between MIDI notes (one note on at time)

Hey everyone!

I am trying to play one midi note at a time from my plugin but when I play a few notes the notesAllOff doesn’t turn the notes off and I have tried changing the timestamps on the MIDI message. I want noteON messages to be sent when the playingANote bool is true. What can I do to fix this? The following is my process block:

void MyMidireaderAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();

for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());


    auto* channelData = buffer.getReadPointer (0);
    for (auto i = 0; i < buffer.getNumSamples(); ++i)
    {
                    pushNextSampleIntoFifo (channelData[i]);
    }
           
    if(playingANote)
    {
        
        if(lastNoteNumber != noteNumber)
        {
                MidiMessage m = MidiMessage::noteOff (channelNumber, lastNoteNumber, 0.0f);
                m.setTimeStamp (time+1);
                midiMessages.addEvent(m,time+1);
        }
        
        MidiMessage m = MidiMessage::noteOn (channelNumber, noteNumber, noteVelocity);
        m.setTimeStamp (time+3);
        midiMessages.addEvent(m,time+3);
    
    } else {
        MidiMessage m = MidiMessage::allNotesOff (channelNumber);
        m.setTimeStamp (time+6);
        midiMessages.addEvent(m,time+6);
    }

}

I figured it out. The allNotesOff() method is not compatible with most plugins so was not turning the notes off. I tracked the Midi signals that are currently on and turned them off individually.

1 Like