Potentially silly Midi question

Hi, 

I am trying to print raw midi messages to a label.  It is a simple attempt to learn how MidiBuffer and MidiMessage work and I thought this would be pretty trivial.  It may be, but so far, I am failing to make this work quickly.  

Below is my first, likely extremely naive attempt at this.  Does anyone see where I am going wrong?  

    MidiBuffer mBuffTemp = ourProcessor->getMidiMessageArray();
    int startEvent = 0;
    int numEvents = mBuffTemp.getNumEvents();
    MidiBuffer::Iterator midiIterator (mBuffTemp);
    midiIterator.setNextSamplePosition (startEvent);
    MidiMessage m;

    while (numEvents > 0)
    {
        String sdssss = "Raw = " + String(*m.getRawData());
        labelTest->setText(sdssss, dontSendNotification);
        startEvent += startEvent;
        numEvents -= numEvents;
    }
    mBuffTemp.clear();

Thank you! :)

You never set your MidiBuffer m to any value. You need to repeatedly call getNextEvent on your iterator in the for loop and store the result into m. Use the return-value of getNextEvent as the for loop condition. Your code should look something like this (I haven't tested this so there may be some typos):

 

MidiBuffer mBuffTemp = ourProcessor->getMidiMessageArray();
MidiBuffer::Iterator midiIterator (mBuffTemp);
MidiMessage m;
int eventPosition;

while (midiIterator .getNextEvent (m, eventPosition))
{
    String sdssss = "Raw = " + String(*m.getRawData());
    labelTest->setText(sdssss, dontSendNotification);
}

Well, that makes more sense now  + this works nicely.

Thank you Fabian.