cmMidiAlsa.c : cmMpPoll() now generates a cmTimeSpec_t timestamp with each message.

This commit is contained in:
kevin 2013-12-15 18:18:06 -05:00
parent 7aaba194c6
commit 2aa2938957

View File

@ -8,6 +8,7 @@
#include "cmMallocDebug.h" #include "cmMallocDebug.h"
#include "cmLinkedHeap.h" #include "cmLinkedHeap.h"
#include "cmThread.h" #include "cmThread.h"
#include "cmTime.h"
#include "cmMidi.h" #include "cmMidi.h"
#include "cmMidiPort.h" #include "cmMidiPort.h"
@ -62,6 +63,8 @@ typedef struct
unsigned prvTimeMicroSecs; // time of last recognized event in microseconds unsigned prvTimeMicroSecs; // time of last recognized event in microseconds
unsigned eventCnt; // count of recognized events unsigned eventCnt; // count of recognized events
cmTimeSpec_t baseTimeStamp;
} cmMpRoot_t; } cmMpRoot_t;
cmMpRoot_t* _cmMpRoot = NULL; cmMpRoot_t* _cmMpRoot = NULL;
@ -164,7 +167,7 @@ cmMpRC_t cmMpPoll()
//printf("dev:%i port:%i ch:%i %i\n",ev->source.client,ev->source.port,ev->data.note.channel,ev->data.note.note); //printf("dev:%i port:%i ch:%i %i\n",ev->source.client,ev->source.port,ev->data.note.channel,ev->data.note.note);
unsigned microSecs1 = (ev->time.time.tv_sec * 1000000) + (ev->time.time.tv_nsec/1000); unsigned microSecs1 = (ev->time.time.tv_sec * 1000000) + (ev->time.time.tv_nsec/1000);
unsigned deltaMicroSecs = p->prvTimeMicroSecs==0 ? 0 : microSecs1 - p->prvTimeMicroSecs; //unsigned deltaMicroSecs = p->prvTimeMicroSecs==0 ? 0 : microSecs1 - p->prvTimeMicroSecs;
cmMidiByte_t d0 = 0xff; cmMidiByte_t d0 = 0xff;
cmMidiByte_t d1 = 0xff; cmMidiByte_t d1 = 0xff;
cmMidiByte_t status = 0; cmMidiByte_t status = 0;
@ -254,8 +257,18 @@ cmMpRC_t cmMpPoll()
if( status != 0 ) if( status != 0 )
{ {
cmMidiByte_t ch = ev->data.note.channel; cmMidiByte_t ch = ev->data.note.channel;
cmTimeSpec_t ts;
ts.tv_sec = p->baseTimeStamp.tv_sec + ev->time.time.tv_sec;
ts.tv_nsec = p->baseTimeStamp.tv_nsec + ev->time.time.tv_nsec;
if( ts.tv_nsec > 1000000000 )
{
ts.tv_nsec -= 1000000000;
ts.tv_sec += 1;
}
cmMpParserMidiTriple(p->prvRcvPort->parserH, deltaMicroSecs, status | ch, d0, d1 ); //printf("MIDI: %ld %ld : 0x%x %i %i\n",ts.tv_sec,ts.tv_nsec,status,d0,d1);
cmMpParserMidiTriple(p->prvRcvPort->parserH, &ts, status | ch, d0, d1 );
p->prvTimeMicroSecs = microSecs1; p->prvTimeMicroSecs = microSecs1;
p->eventCnt += 1; p->eventCnt += 1;
@ -516,6 +529,9 @@ cmMpRC_t cmMpInitialize( cmCtx_t* ctx, cmMpCallback_t cbFunc, void* cbArg, unsig
// send any pending commands to the driver // send any pending commands to the driver
snd_seq_drain_output(p->h); snd_seq_drain_output(p->h);
// all time stamps will be an offset from this time stamp
clock_gettime(CLOCK_MONOTONIC,&p->baseTimeStamp);
if( cmThreadPause(p->thH,0) != kOkThRC ) if( cmThreadPause(p->thH,0) != kOkThRC )
rc = _cmMpErrMsg(&p->err,kThreadErrMpRC,0,"Thread start failed."); rc = _cmMpErrMsg(&p->err,kThreadErrMpRC,0,"Thread start failed.");