I am trying to take MidiEvents from the handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message) and convert the timeStamps in to ticks so I can save it in a MIDIFile. “startTime” is just calculated when recording is started with (startTime = (Time::getMillisecondCounterHiRes() * .001);).
I’m also confused how to correctly change the timeStamp since the MidiMessage is const? I would also like to alter the miciChannel number, but I’m stuck for the same reason
[code]void PerformerManagerComponent::handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message)
{
const int timeStamp = (int)((message.getTimeStamp() - startTime) * Time::getHighResolutionTicksPerSecond());
if(recState == true && playState == true)
{
for (int i = 0; i < enabledMidiInputChannels.size(); i++)
{
if(source->getName() == enabledMidiInputChannels[i])
{
MidiMessage* const newOne = new MidiMessage (message);
newOne->setTimeStamp (timeStamp);
newOne->setChannel(i+1);
midiSeqences[i]->addEvent(*newOne);
midiSeqences[i]->updateMatchedPairs();
DBG( String("Message: chn: ") + String(newOne->getChannel())
+ String(" Note: ") + String(newOne->getNoteNumber() )
+ String(" Vel: ") + String(newOne->getVelocity() )
+ String(" T: ") + String(newOne->getTimeStamp()) );
}
}
}
}[/code]
The midi file makes the notes, but the time relationship is all weird. I tried to use this thread as a starting point http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=5473&hilit=MIDIFile
Which had me setting up the MidiSequencers in there like this
// grab the BPM and add it to the XML file or however we are going to do this
/*********************/
int microsecondsperquarter = 60.0*Time::getHighResolutionTicksPerSecond()/120;
for(int i = 0; i < midiSeqences.size(); i++)
{
midiSeqences[i]->clear();
midiSeqences[i]->addEvent(MidiMessage::timeSignatureMetaEvent(4, 4));
midiSeqences[i]->addEvent(MidiMessage::tempoMetaEvent(microsecondsperquarter));
midiSeqences[i]->addEvent(MidiMessage::midiChannelMetaEvent(i+1));
}