Bläddra i källkod

cmMidiPort.h/c: Changed cmMidiPort to support cmMidiAlsa.c.

Updated cmMpInitialize() and cmMpTest() to use cmCtx_t.
Added following public functions:
cmMpDeviceNameToIndex()
cmMpDevicePortNameToIndex()

cmMpParserMidiTriple() and cmMpParserTransmit() to allow the MIDI parser
to transmit pre-parsed MIDI messages.
master
kevin 11 år sedan
förälder
incheckning
2171cf09ad
2 ändrade filer med 101 tillägg och 9 borttagningar
  1. 88
    7
      cmMidiPort.c
  2. 13
    2
      cmMidiPort.h

+ 88
- 7
cmMidiPort.c Visa fil

@@ -2,6 +2,7 @@
2 2
 #include "cmGlobal.h"
3 3
 #include "cmRpt.h"
4 4
 #include "cmErr.h"
5
+#include "cmCtx.h"
5 6
 #include "cmMem.h"
6 7
 #include "cmMallocDebug.h"
7 8
 #include "cmMidi.h"
@@ -180,7 +181,8 @@ void _cmMpTransmitSysEx( cmMpParser_t* p )
180 181
 
181 182
 void _cmMpParserStoreChMsg( cmMpParser_t* p, unsigned deltaMicroSecs,  cmMidiByte_t d )
182 183
 {
183
-  // if there is not enough room left in the buffer then transmit the current messages
184
+  // if there is not enough room left in the buffer then transmit
185
+  // the current messages
184 186
   if( p->bufByteCnt - p->bufIdx < sizeof(cmMidiMsg) )
185 187
     _cmMpTransmitChMsgs(p);
186 188
 
@@ -346,6 +348,58 @@ void cmMpParseMidiData( cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiBy
346 348
  
347 349
 }
348 350
 
351
+cmMpRC_t  cmMpParserMidiTriple(   cmMpParserH_t h, unsigned deltaMicroSecs, cmMidiByte_t status, cmMidiByte_t d0, cmMidiByte_t d1 )
352
+{
353
+  cmMpRC_t rc = kOkMpRC;
354
+  cmMpParser_t* p = _cmMpParserFromHandle(h);
355
+  cmMidiByte_t mb = -1;
356
+
357
+  if( d0 == 0xff )
358
+    p->dataCnt = 0;
359
+  else
360
+    if( d1 == 0xff )
361
+      p->dataCnt = 1;
362
+    else
363
+      p->dataCnt = 2;
364
+
365
+  p->status  = status;
366
+  switch( p->dataCnt )
367
+  {
368
+    case 0:      
369
+      mb = status;
370
+     break;
371
+
372
+    case 1:
373
+      mb = d0;
374
+      break;
375
+
376
+    case 2:
377
+      p->data0 = d0;
378
+      mb = d1;
379
+      break;
380
+
381
+    default:
382
+      rc = cmErrMsg(&p->err,kInvalidArgMpRC,"An invalid MIDI status byte (0x%x) was encountered by the MIDI data parser.");
383
+      goto errLabel;
384
+      break;
385
+  }
386
+
387
+  if( mb != -1 )
388
+    _cmMpParserStoreChMsg(p,deltaMicroSecs,mb);
389
+  
390
+  p->dataCnt = cmInvalidCnt;
391
+
392
+ errLabel:
393
+  return rc;
394
+}
395
+
396
+cmMpRC_t  cmMpParserTransmit(    cmMpParserH_t h )
397
+{
398
+  cmMpParser_t* p = _cmMpParserFromHandle(h);
399
+  _cmMpTransmitChMsgs(p);
400
+  return kOkMpRC;
401
+}
402
+
349 403
 cmMpRC_t      cmMpParserInstallCallback( cmMpParserH_t h, cmMpCallback_t  cbFunc, void* cbDataPtr )
350 404
 {
351 405
   cmMpParser_t*   p        = _cmMpParserFromHandle(h);
@@ -418,6 +472,32 @@ bool cmMpParserHasCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbData
418 472
 //
419 473
 //
420 474
 
475
+unsigned    cmMpDeviceNameToIndex(const cmChar_t* name)
476
+{
477
+  assert(name!=NULL);
478
+  unsigned i;
479
+  unsigned n = cmMpDeviceCount();
480
+  for(i=0; i<n; ++i)
481
+    if( strcmp(cmMpDeviceName(i),name)==0)
482
+      return i;
483
+  return cmInvalidIdx;
484
+}
485
+
486
+unsigned    cmMpDevicePortNameToIndex( unsigned devIdx, unsigned flags, const cmChar_t* name )
487
+{
488
+  unsigned i;
489
+  unsigned n = cmMpDevicePortCount(devIdx,flags);
490
+  for(i=0; i<n; ++i)
491
+    if( strcmp(cmMpDevicePortName(devIdx,flags,i),name)==0)
492
+      return i;
493
+
494
+  return cmInvalidIdx;
495
+}
496
+
497
+//====================================================================================================
498
+//
499
+//
500
+
421 501
 void cmMpTestPrint( void* userDataPtr, const char* fmt, va_list vl )
422 502
 {
423 503
   vprintf(fmt,vl);
@@ -439,20 +519,21 @@ void cmMpTestCb( const cmMidiPacket_t* pktArray, unsigned pktCnt )
439 519
   }
440 520
 }
441 521
 
442
-void cmMpTest( cmRpt_t* rpt )
522
+void cmMpTest( cmCtx_t* ctx )
443 523
 {
444 524
   char ch;
445 525
   unsigned parserBufByteCnt = 1024;
446
-  cmMpInitialize(cmMpTestCb,NULL,parserBufByteCnt,"app",rpt);
447
-  cmMpReport(rpt);
526
+  cmMpInitialize(ctx,cmMpTestCb,NULL,parserBufByteCnt,"app");
527
+  cmMpReport(&ctx->rpt);
448 528
 
449
-  
450
-  cmRptPrintf(rpt,"<return> to continue\n");
529
+ 
530
+  cmRptPrintf(&ctx->rpt,"<return> to continue\n");
451 531
 
452 532
   while((ch = getchar()) != 'q')
453 533
   {
454
-    cmMpDeviceSend(0,0,0x90,60,60);
534
+    cmMpDeviceSend(2,0,0x90,60,60);
455 535
   }
536
+ 
456 537
 
457 538
   cmMpFinalize();
458 539
 }

+ 13
- 2
cmMidiPort.h Visa fil

@@ -19,6 +19,8 @@ extern "C" {
19 19
   {
20 20
     kOkMpRC = cmOkRC,
21 21
     kCfStringErrMpRC,
22
+    kLHeapErrMpRC,
23
+    kThreadErrMpRC,
22 24
     kSysErrMpRC,
23 25
     kInvalidArgMpRC,
24 26
     kMemAllocFailMpRC,
@@ -46,6 +48,13 @@ extern "C" {
46 48
   unsigned      cmMpParserErrorCount( cmMpParserH_t h );
47 49
   void          cmMpParseMidiData(    cmMpParserH_t h, unsigned deltaMicroSecs, const cmMidiByte_t* buf, unsigned bufByteCnt );
48 50
 
51
+  // The following two functions are intended to be used togetther.
52
+  // Use cmMpParserMidiTriple() to insert pre-parsed msg's to the output buffer,
53
+  // and then use cmMpParserTransmit() to send the buffer via the parsers callback function.
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 );
56
+  cmMpRC_t      cmMpParserTransmit(    cmMpParserH_t h ); 
57
+
49 58
   // Install/Remove additional callbacks.
50 59
   cmMpRC_t      cmMpParserInstallCallback( cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
51 60
   cmMpRC_t      cmMpParserRemoveCallback(  cmMpParserH_t h, cmMpCallback_t cbFunc, void* cbDataPtr );
@@ -60,14 +69,16 @@ extern "C" {
60 69
 
61 70
   // 'cbFunc' and 'cbDataPtr' are optional (they may be set to NULL).  In this case
62 71
   // 'cbFunc' and 'cbDataPtr' may be set in a later call to cmMpInstallCallback().
63
-  cmMpRC_t    cmMpInitialize( cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr, cmRpt_t* rpt );
72
+  cmMpRC_t    cmMpInitialize( cmCtx_t* ctx, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr );
64 73
   cmMpRC_t    cmMpFinalize();
65 74
   bool        cmMpIsInitialized();
66 75
 
67 76
   unsigned    cmMpDeviceCount();
68 77
   const char* cmMpDeviceName(       unsigned devIdx );
78
+  unsigned    cmMpDeviceNameToIndex(const cmChar_t* name);
69 79
   unsigned    cmMpDevicePortCount(  unsigned devIdx, unsigned flags );
70 80
   const char* cmMpDevicePortName(   unsigned devIdx, unsigned flags, unsigned portIdx );
81
+  unsigned    cmMpDevicePortNameToIndex( unsigned devIdx, unsigned flags, const cmChar_t* name );
71 82
   cmMpRC_t    cmMpDeviceSend(       unsigned devIdx, unsigned portIdx, cmMidiByte_t st, cmMidiByte_t d0, cmMidiByte_t d1 );
72 83
   cmMpRC_t    cmMpDeviceSendData(   unsigned devIdx, unsigned portIdx, const cmMidiByte_t* dataPtr, unsigned byteCnt );
73 84
 
@@ -80,7 +91,7 @@ extern "C" {
80 91
 
81 92
   void        cmMpReport( cmRpt_t* rpt );
82 93
 
83
-  void cmMpTest( cmRpt_t* rpt );
94
+  void cmMpTest( cmCtx_t* ctx );
84 95
 
85 96
 #ifdef __cplusplus
86 97
 }

Laddar…
Avbryt
Spara