A MIDI Interface class. Risks?

Hi. I’m sort of creating a MIDI Interface class so the AudioProcessor class stays untouched. I have created my own MIDI scheduling system, but I don’t to add too many methods in the main processor class. Want to use an abstraction so I might reuse it easily for other projects.

I’m programming MIDI only plugins, no audio. I wonder if there’s any risk in passing a reference to the MIDIBuffer and Playhead to this new class.

I know there’s a warning in AudioPlayHead::getCurrentPosition that is only has context within processorBlock(). But it will be instantly passed by reference to the MIDI interface class so I can set some variables based in its content (BPM, PPQ, etc).

The same with MidiBuffer. My idea is to manipulate a copy of the MidiBuffer and exchange received midiBuffer with the edited MidiBuffer (with swap).

After some initial tests, i could see no problem whatsoever, but I ask if I might be overlooking something. My Midi processing is light enough to fit 100s of times in a single block.


Not sure exactly what you mean. Passing a reference to the playHead or the midi buffer is OK if you will be calling the MIDI interface class’ methods which use these references from within the processBlock function. If not, then simply copy out the data you need.

My processBlock() looks like this:

void MiditemplateAudioProcessor::processBlock( AudioSampleBuffer& buffer , MidiBuffer& midiMessages )
getPlayHead()->getCurrentPosition( myCurrentPosInfo );

MIDI_PROCESSING( midiMessages , myCurrentPosInfo , buffer.getNumSamples() );

// ready to exchange with the modified/edited version
midiMessages.swapWith( MI_MidiBuffer ); // Mi_MidiBuffer created in MIDI_PROCESSING method.


My AudioProcessor inherits from MIDI_Interface class

class MiditemplateAudioProcessor : public AudioProcessor, public MIDI_Interface

The MIDI_PROCESSING method is defined like this

void MIDI_Interface::MIDI_PROCESSING(const MidiBuffer& mb, const AudioPlayHead::CurrentPositionInfo& cpi, const int& blocksamples)

SInce my AudioProcessor is-a MIDI_Interface, I thought passing by const-reference would be more efficient.

I tested with a large number of Midi events and had no problems at all, but still I wonder if the design might pode some issues.


That should be fine as your MIDI_PROCESSING is called within the processBlock.