Midibuffer malarkey

Could someone give an example of how to use the midibuffer in JAP. Like say, how one would loop though it and filter out everything except note on and off messages… or whatever really.

Is the same buffer used for both in and out? And those time stamping thingies, can you set a message to play outside the confines of the current sample buffer?

[quote=“Pukeweed”]Could someone give an example of how to use the midibuffer in JAP. Like say, how one would loop though it and filter out everything except note on and off messages… or whatever really.
[/quote]

the following works for me - just loops through looking for note on/offs- ignoring the time-stamps:

[code]//midiMessages is passed into processBlock

MidiBuffer::Iterator midi_buffer_iterator(midiMessages);

MidiMessage midi_message(0);
int sample_number;

while(midi_buffer_iterator.getNextEvent(midi_message,sample_number))
{

if( midi_message.isNoteOff())
{
//note on at sample_number samples after
//the begining of the current buffer
}
else if( midi_message.isNoteOff())
{

}

}[/code]

i believe the same buffer is used for in and out - ie. if you don’t clear it the events will be passed on to the next plugin. It doesn’t really make sense to set a time stamp greater than the buffer size - i’m sure, you could do it, but depending how the follwoing plugins process midi events, they may either ignore it or do something bad (or work just fine ). probably not a good thing to do though :wink:

Hope that helps.

Well,I was thinking the framework might buffer them and hand them out at the right time? But that doesn’y make alot of sense when I think about it.

Thanks for the code. Exactly what I wanted.

Another question:
Does midi_buffer_iterator.getNextEvent() remove the midi message from the buffer, or does it just copy it? Because we are not getting a pointer, are we?

[quote=“Pukeweed”]Another question:
Does midi_buffer_iterator.getNextEvent() remove the midi message from the buffer, or does it just copy it? Because we are not getting a pointer, are we?[/quote]

no, it doesn’t remove it. In my example, the midi data in the buffer is simply copied to midi_message.

as it stands, it seems the clear() methods are the only way of removing data from a MidiBuffer. Somebody correct me if i’m wrong…

Yep, at the moment you can just add messages and clear the buffer. The idea was really just to have an object that made it efficient to handle lists of messages without each message being a separately-allocated object.

I might add some extra methods to it as time goes on, but it’s really aimed more at storing messages than manipulating them.