cmMidiPort.h/c : cmMpParseMidiData() and cmMpParseMidiTriple() now take a MIDI time stamp as part of the incoming message.

This commit is contained in:
kevin 2013-12-15 18:16:36 -05:00
parent b403c1a2bf
commit 7aaba194c6
2 changed files with 12 additions and 11 deletions

View File

@ -5,6 +5,7 @@
#include "cmCtx.h" #include "cmCtx.h"
#include "cmMem.h" #include "cmMem.h"
#include "cmMallocDebug.h" #include "cmMallocDebug.h"
#include "cmTime.h"
#include "cmMidi.h" #include "cmMidi.h"
#include "cmMidiPort.h" #include "cmMidiPort.h"
@ -179,7 +180,7 @@ void _cmMpTransmitSysEx( cmMpParser_t* p )
} }
void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs, cmMidiByte_t d ) void _cmMpParserStoreChMsg( cmMpParser_t* p, const cmTimeSpec_t* timeStamp, cmMidiByte_t d )
{ {
// if there is not enough room left in the buffer then transmit // if there is not enough room left in the buffer then transmit
// the current messages // the current messages
@ -193,7 +194,7 @@ void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs, cmMidiByt
cmMidiMsg* msgPtr = (cmMidiMsg*)(p->buf + p->bufIdx); cmMidiMsg* msgPtr = (cmMidiMsg*)(p->buf + p->bufIdx);
// fill the buffer msg // fill the buffer msg
msgPtr->deltaUs = deltaMicroSecs; msgPtr->timeStamp = *timeStamp;
msgPtr->status = p->status; msgPtr->status = p->status;
switch( p->dataCnt ) switch( p->dataCnt )
@ -221,7 +222,7 @@ void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs, cmMidiByt
} }
void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiByte_t* iBuf, unsigned iByteCnt ) void cmMpParseMidiData( cmMpParserH_t h, const cmTimeSpec_t* timeStamp, const cmMidiByte_t* iBuf, unsigned iByteCnt )
{ {
cmMpParser_t* p = _cmMpParserFromHandle(h); cmMpParser_t* p = _cmMpParserFromHandle(h);
@ -271,7 +272,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
else else
{ {
// this is a status only msg - store it // this is a status only msg - store it
_cmMpParserStoreChMsg(p,deltaMicroSecs,*ip); _cmMpParserStoreChMsg(p,timeStamp,*ip);
p->state = kExpectStatusStId; p->state = kExpectStatusStId;
p->dataIdx = cmInvalidIdx; p->dataIdx = cmInvalidIdx;
@ -299,7 +300,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
switch( p->dataCnt ) switch( p->dataCnt )
{ {
case 1: // ... of a 1 byte msg - the msg is complete case 1: // ... of a 1 byte msg - the msg is complete
_cmMpParserStoreChMsg(p,deltaMicroSecs,*ip); _cmMpParserStoreChMsg(p,timeStamp,*ip);
p->state = kExpectStatusOrDataStId; p->state = kExpectStatusOrDataStId;
break; break;
@ -318,7 +319,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
assert( p->dataCnt == 2 ); assert( p->dataCnt == 2 );
assert( p->state == kExpectDataStId ); assert( p->state == kExpectDataStId );
_cmMpParserStoreChMsg(p,deltaMicroSecs,*ip); _cmMpParserStoreChMsg(p,timeStamp,*ip);
p->state = kExpectStatusOrDataStId; p->state = kExpectStatusOrDataStId;
p->dataIdx = 0; p->dataIdx = 0;
break; break;
@ -348,7 +349,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
} }
cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, unsigned deltaMicroSecs, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 ) cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, const cmTimeSpec_t* timeStamp, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 )
{ {
cmMpRC_t rc = kOkMpRC; cmMpRC_t rc = kOkMpRC;
cmMpParser_t* p = _cmMpParserFromHandle(h); cmMpParser_t* p = _cmMpParserFromHandle(h);
@ -385,7 +386,7 @@ cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, unsigned deltaMicroSecs, cmMi
} }
if( mb != 0xff ) if( mb != 0xff )
_cmMpParserStoreChMsg(p,deltaMicroSecs,mb); _cmMpParserStoreChMsg(p,timeStamp,mb);
p->dataCnt = cmInvalidCnt; p->dataCnt = cmInvalidCnt;
@ -512,7 +513,7 @@ void cmMpTestCb( const cmMidiPacket_t* pktArray, unsigned pktCnt )
for(j=0; j<p->msgCnt; ++j) for(j=0; j<p->msgCnt; ++j)
if( p->msgArray != NULL ) if( p->msgArray != NULL )
printf("%8i 0x%x %i %i\n", p->msgArray[j].deltaUs/1000, p->msgArray[j].status,p->msgArray[j].d0, p->msgArray[j].d1); printf("%ld %ld 0x%x %i %i\n", p->msgArray[j].timeStamp.tv_sec, p->msgArray[j].timeStamp.tv_nsec, p->msgArray[j].status,p->msgArray[j].d0, p->msgArray[j].d1);
else else
printf("0x%x ",p->sysExMsg[j]); printf("0x%x ",p->sysExMsg[j]);

View File

@ -46,13 +46,13 @@ extern "C" {
cmMpParserH_t cmMpParserCreate( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned bufByteCnt, cmRpt_t* rpt ); cmMpParserH_t cmMpParserCreate( unsigned devIdx, unsigned portIdx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned bufByteCnt, cmRpt_t* rpt );
void cmMpParserDestroy( cmMpParserH_t* hp ); void cmMpParserDestroy( cmMpParserH_t* hp );
unsigned cmMpParserErrorCount( cmMpParserH_t h ); unsigned cmMpParserErrorCount( cmMpParserH_t h );
void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiByte_t* buf, unsigned bufByteCnt ); void cmMpParseMidiData( cmMpParserH_t h, const cmTimeSpec_t* timestamp, const cmMidiByte_t* buf, unsigned bufByteCnt );
// The following two functions are intended to be used togetther. // The following two functions are intended to be used togetther.
// Use cmMpParserMidiTriple() to insert pre-parsed msg's to the output buffer, // Use cmMpParserMidiTriple() to insert pre-parsed msg's to the output buffer,
// and then use cmMpParserTransmit() to send the buffer via the parsers callback function. // and then use cmMpParserTransmit() to send the buffer via the parsers callback function.
// Set the data bytes to 0xff if they are not used by the message. // Set the data bytes to 0xff if they are not used by the message.
cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, unsigned deltaMicroSecs, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 ); cmMpRC_t cmMpParserMidiTriple( cmMpParserH_t h, const cmTimeSpec_t* timestamp, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 );
cmMpRC_t cmMpParserTransmit( cmMpParserH_t h ); cmMpRC_t cmMpParserTransmit( cmMpParserH_t h );
// Install/Remove additional callbacks. // Install/Remove additional callbacks.