I've created a very basic MIDI sequence a while ago, and the following is
how I done it:
-"Time" is kept track of using JACK frames, and a BPM. This tells you how
many beats (from frame 0) you've played, and what "percentage" or part of
beat your in.
-"EventClip" objects have a big vector of "EventClipElement"s, which
represent events like NOTE_ON, NOTE_OFF, CC_CHANGE, etc.
-Process() gets Time information: int currentBeat; float currentPercent;
-Check if the "time" just went past the next Event in the clip:
// start code
if ( EventClip->upcomingEvent()->beat == currentBeat )
{
if ( EventClip->nextEvent()->percent <= currentPercent)
{
processEvent(); // write MIDI message in this case
EventClip->goToNextEvent();
}
}
// end code
That's pretty much it, now for the caveat's:
-Vector's are not RT friendly, so use a List, or reserve *plenty* of space
in your vector!
-The EventClip class can be very simple, it only needs a way to quickly
retrieve the *next* event, so having a member pointer to the next
EventClipElement in the vector will make avoid lots of array access.
-If you relocate on the timeline, then you'll have to "search" through the
vector to find the right nextEvent. (ie where currentBeat == beat, but
currentPercent < eventPercent)
Note this was the first time I got a MIDI sequencer running, and there are
probably other ways to do it too... perhaps which provide cleaner code &
better readability...
Keeping an eye on this :D -Harry