Midi ID


I have following code to detect midi events…

void AudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...

	MidiMessage message (0xf4, 0.0);
	MidiBuffer::Iterator i (midiMessages);
	int sampleOffset;
	while (i.getNextEvent (message, sampleOffset))
		if (message.isNoteOn())
			_synth->playNote(message.getNoteNumber(), message.getFloatVelocity(), sampleOffset);
		else if (message.isNoteOff())
			_synth->stopNote(message.getNoteNumber(), message.getFloatVelocity(), sampleOffset);

is there a member like an ID in MidiMessage? I want to save this ID when “isNoteOn” is true and compare it when “isNoteOff” is true so that I can stop the right note.
When I press a note and release it, there are two events and booth have to be the same ID. Is there anything like this?

Thanks and greetz from Germany


No, MidiMessage is really just a wrapper around the standard MIDI spec so just contains a few bytes of data. The MIDI spec has no concept of events, it just streams data.

You might want to have a look the Synthesizer class and SynthesizerVoice as this deals with a similar problem when determining note stealing. At the moment the classes just stop any existing notes with the same number and restart them with the new parameters. You could add your own note handling with something like a context number which gets incremented with each successive note on (with the same note number) and decremented with note-offs. Really difficult to get right though as I doubt you’ll be able to tell which note corresponds to which context so the voice may be at different stages in its sound.

To get this right you probably need to add some kind of hardware message that informs you of the context number as really that’s the only thing that can know.


All MIDI messages have a timestamp (or a sample number if running as an audio plugin), you can discard “unreal” events (duplicates) by comparing those timestamps (two note-on events in the same time in a monophonic synth is wrong for example)