Hi, I'm trying to play a MIDI track that I have recorded using JUCE MIDI input. I have found this old thread (http://www.juce.com/api/classMidiMessageSequence.html#a1d40da64c5a9fd61c7350346ca8c8144), but there's no final solution.
I have a separate thread which implements the run method like this:
void MidiPlayer::run(){ if (!workingTrack || !deviceManager) return; int index; double time = workingTrack->getStartTime(), nextTime; for (index = 0; index < workingTrack->getNumEvents(); index++){ if (threadShouldExit()) break; sleep((nextTime = workingTrack->getEventTime(index)) - time); deviceManager->getDefaultMidiOutput()->sendMessageNow((workingTrack->getEventPointer(index))->message); time = nextTime; } }
But the problem is similar as in the posted thread. It seems to play everything in a moment.
I think that I don't quite understand the timestamp in this case. What is the "double" suppose to mean? The thing is that there should be some tempo settings and those other MIDI settings but I just cannot put it together.
I record the track like this (it is taken out from the MIDI demo and modified a bit):
void handleNoteOn(MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override { MidiMessage m(MidiMessage::noteOn(midiChannel, midiNoteNumber, velocity)); m.setTimeStamp(Time::getMillisecondCounterHiRes() * 0.001); //play sound MidiOutput* out = deviceManager->getDefaultMidiOutput(); if (out) out->sendMessageNow(m); //record workingTrack.addEvent(m); }
Thanks a lot...
//Edit: I think I am beginning to understand... There's no dimension to the timestamp, it is just what I make it to be, right? And it is up to me to interpret it correctly. So in the case above the problem is that I record it in seconds but try to play it in millis. But I stilll do not understand wheteher there is any support for this tempo/clicks per quater note built in or whether I need to implement this as well...