Browse Source

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

master
kevin 10 years ago
parent
commit
7aaba194c6
2 changed files with 12 additions and 11 deletions
  1. 10
    9
      cmMidiPort.c
  2. 2
    2
      cmMidiPort.h

+ 10
- 9
cmMidiPort.c View File

@@ -5,6 +5,7 @@
5 5
 #include "cmCtx.h"
6 6
 #include "cmMem.h"
7 7
 #include "cmMallocDebug.h"
8
+#include "cmTime.h"
8 9
 #include "cmMidi.h"
9 10
 #include "cmMidiPort.h"
10 11
 
@@ -179,7 +180,7 @@ void _cmMpTransmitSysEx( cmMpParser_t* p )
179 180
 
180 181
 }
181 182
 
182
-void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs,  cmMidiByte_t d )
183
+void _cmMpParserStoreChMsg( cmMpParser_t* p, const cmTimeSpec_t* timeStamp,  cmMidiByte_t d )
183 184
 {
184 185
   // if there is not enough room left in the buffer then transmit
185 186
   // the current messages
@@ -193,7 +194,7 @@ void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs,  cmMidiByt
193 194
   cmMidiMsg* msgPtr = (cmMidiMsg*)(p->buf + p->bufIdx);
194 195
 
195 196
   // fill the buffer msg
196
-  msgPtr->deltaUs = deltaMicroSecs;
197
+  msgPtr->timeStamp = *timeStamp;
197 198
   msgPtr->status  = p->status;
198 199
 
199 200
   switch( p->dataCnt )
@@ -221,7 +222,7 @@ void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs,  cmMidiByt
221 222
 
222 223
 }
223 224
 
224
-void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiByte_t* iBuf, unsigned iByteCnt )
225
+void cmMpParseMidiData( cmMpParserH_t h, const cmTimeSpec_t* timeStamp, const cmMidiByte_t* iBuf, unsigned iByteCnt )
225 226
 {
226 227
   
227 228
   cmMpParser_t* p = _cmMpParserFromHandle(h);
@@ -271,7 +272,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
271 272
           else
272 273
           {
273 274
             // this is a status only msg - store it
274
-            _cmMpParserStoreChMsg(p,deltaMicroSecs,*ip);
275
+            _cmMpParserStoreChMsg(p,timeStamp,*ip);
275 276
 
276 277
             p->state   = kExpectStatusStId;
277 278
             p->dataIdx = cmInvalidIdx;
@@ -299,7 +300,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
299 300
             switch( p->dataCnt )
300 301
             {
301 302
               case 1: // ... of a 1 byte msg - the msg is complete
302
-                _cmMpParserStoreChMsg(p,deltaMicroSecs,*ip);
303
+                _cmMpParserStoreChMsg(p,timeStamp,*ip);
303 304
                 p->state = kExpectStatusOrDataStId; 
304 305
                 break;
305 306
 
@@ -318,7 +319,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
318 319
             assert( p->dataCnt == 2 );
319 320
             assert( p->state == kExpectDataStId );
320 321
 
321
-            _cmMpParserStoreChMsg(p,deltaMicroSecs,*ip);
322
+            _cmMpParserStoreChMsg(p,timeStamp,*ip);
322 323
             p->state   = kExpectStatusOrDataStId;
323 324
             p->dataIdx = 0;
324 325
             break;
@@ -348,7 +349,7 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
348 349
  
349 350
 }
350 351
 
351
-cmMpRC_t  cmMpParserMidiTriple(   cmMpParserH_t h, unsigned deltaMicroSecs, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 )
352
+cmMpRC_t  cmMpParserMidiTriple(   cmMpParserH_t h, const cmTimeSpec_t* timeStamp, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 )
352 353
 {
353 354
   cmMpRC_t rc = kOkMpRC;
354 355
   cmMpParser_t* p = _cmMpParserFromHandle(h);
@@ -385,7 +386,7 @@ cmMpRC_t  cmMpParserMidiTriple(   cmMpParserH_t h, unsigned deltaMicroSecs, cmMi
385 386
   }
386 387
 
387 388
   if( mb != 0xff )
388
-    _cmMpParserStoreChMsg(p,deltaMicroSecs,mb);
389
+    _cmMpParserStoreChMsg(p,timeStamp,mb);
389 390
   
390 391
   p->dataCnt = cmInvalidCnt;
391 392
 
@@ -512,7 +513,7 @@ void cmMpTestCb( const cmMidiPacket_t* pktArray, unsigned pktCnt )
512 513
 
513 514
     for(j=0; j<p->msgCnt; ++j)
514 515
       if( p->msgArray != NULL )
515
-        printf("%8i 0x%x %i %i\n", p->msgArray[j].deltaUs/1000, p->msgArray[j].status,p->msgArray[j].d0, p->msgArray[j].d1);
516
+        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);
516 517
       else
517 518
         printf("0x%x ",p->sysExMsg[j]);
518 519
 

+ 2
- 2
cmMidiPort.h View File

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

Loading…
Cancel
Save