I’m trying to write a VST that windows incoming MIDI CC data every beat, and then stores it as a MIDI file that I can look up later. I’m just trying to write the CC data to a MidiMessageSequence, and then print out the values… but the values seemed all jumbled when I print it back out? When I monitor the CC data coming in it seems all good, so I’m assuming the problem is when I pack or unpack the MidiMessageSequence. Any thoughts or suggestions?
MidiBuffer::Iterator inBufferIterator(midiMessages);
MidiMessage midi_message(0xf4);
int sample_number;
while(inBufferIterator.getNextEvent(midi_message,sample_number))
{
if(midi_message.isControllerOfType(14)){
//std::cout << midi_message.getControllerValue() << std::endl;
midiMessageSequence->addEvent(midi_message); //Adds CC_event to the midiMessageSequence
}
}
AudioPlayHead::CurrentPositionInfo currentPosition; //make a new playhead position object
getPlayHead()->getCurrentPosition(currentPosition); //I think this will store the current playhead info in the position object
if(!currentPosition.isPlaying)
{
if(test == false) {
test = true;
for(int i; i < midiMessageSequence->getNumEvents(); i++)
{
std::cout << midiMessageSequence->getEventPointer(i)->message.getControllerValue() << std::endl;
}
midiMessageSequence->clear();
}
} else {
test = false;
}
Ah, of course I keep forgetting the timestamp is context dependent. So I’m assuming I should convert from sample position in the buffer, to Ticks. Are there any convenience methods or tips for converting that? I’m assuming I would just use my own Tick resolution (960, or something like that).
****Edit: I realized I was creating my MidiMessageSequence in the audio callback. Doh!! That’s what I get for still coding at 4am.
I found the awesome “AudioPlayHead::CurrentPositionInfo” and got my VST to write the .mid file to disk, but when I load it back into the sequencer the data looks messed up. I’m guessing this is because I’m trying to write the file in the audioCallback I just want to test this right now, is there any recommendations on where I could call the write function from?