Re: [LAD] how to store deferred events in a real time audio app?

From: Harry van Haaren <harryhaaren@email-addr-hidden>
Date: Wed Dec 21 2011 - 03:04:19 EET

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

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Wed Dec 21 04:15:03 2011

This archive was generated by hypermail 2.1.8 : Wed Dec 21 2011 - 04:15:03 EET