Sending offline midi to a Synthesizer

Hi all,

I have been attempting to send offline midi to a Synthesizer class. Right now it only processes one block and goes silent. I seem to me misunderstanding how this is supposed to work.

void SwingTheoryAudio::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) {

bufferToFill.clearActiveBufferRegion();

if((samplesPlayed < bufferLen) && isPlaying) {
    
    MidiBuffer::Iterator it(midibuffer);
    MidiMessage message;
    int samplenumber;

    while(it.getNextEvent(message, samplenumber)) {

        if(samplenumber > samplesPlayed && message.getTimeStamp() < samplesPlayed) {
            break;
        }
        
        MidiBuffer output;
        output.addEvent(message, 0);
        
        synth.renderNextBlock(*bufferToFill.buffer, output, bufferToFill.startSample, bufferToFill.numSamples);
        midibuffer.clear(samplesPlayed, samplesPlayed + bufferToFill.numSamples);
    }

    samplesPlayed += bufferToFill.numSamples;
} else {
    isPlaying = false;
}

}

The iterator will be re-initialised every time your getNextAudioBlock function is called. You probably want to keep the iterator as a member variable in your class so that the state is saved between getNextAudioBlock callbacks.

Thanks fabian, however that produces the same result.