ProcessBlock MidiBuffer?


#1

The processblock gives me the midibuffer

void DemoJuceFilter::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)

Can someone show me how I can Iterate thru the midiMessages? What is the exact syntax for the midibuffer Iterator. At the moment I just need to know when keys were pressed and what they were, any help or examples would be appreciated.


#2

you can use it like this:

	MidiMessage message (0);
	MidiBuffer::Iterator i (midiMessages);
	int messageFrameRelativeTothisProcess;
	while (i.getNextEvent (message, messageFrameRelativeTothisProcess))
	{
		// here you typically use message
		if (message.isNoteOnOrOff ())
		{
			int note = message.getNoteNumber ();
			message.setNoteNumber (note + 12); // transpose it
		}
	}

#3

got an exception when using
MidiMessage message (0);

It works if I put
MidiMessage message (0xf0);

Don’t understand why though


#4

a midi message with just zeroes is not valid, it has to begin with one of predefined bytes, though i think that MidiMessage (0) should be valid to indicate a uninitialized midi messages, because 0xf0 is a completely valid message and this object can’t be distinguished from a uninitialized message.