Browse Source

cmMidiOsx.c : Fixed bug where the incorrect device index was reported by incoming MIDI messages.

master
kevin 6 years ago
parent
commit
b22f1d3ad3
1 changed files with 16 additions and 9 deletions
  1. 16
    9
      osx/cmMidiOsx.c

+ 16
- 9
osx/cmMidiOsx.c View File

@@ -27,7 +27,9 @@ typedef struct
27 27
 typedef struct
28 28
 {
29 29
   char*      nameStr;
30
-
30
+  unsigned   devId;     // this device is known to OSX by this id
31
+  unsigned   devIdx;    // this device is known externally by this device index (also index into cmMpRoot.devArray[])
32
+  
31 33
   unsigned   iPortCnt;
32 34
   cmMpPort*  iPortArray;
33 35
 
@@ -336,7 +338,7 @@ cmMpRC_t _cmMpIsDeviceActive( unsigned devIdx, MIDIDeviceRef mdr, ItemCount* src
336 338
   return rc;
337 339
 }
338 340
 
339
-cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRef, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, cmErr_t* errPtr )
341
+cmMpRC_t _cmMpCreateDevice( unsigned deviceId, unsigned deviceIdx, cmMpDev* drp,  MIDIPortRef inPortRef, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, cmErr_t* errPtr )
340 342
 {
341 343
   cmMpRC_t        rc        = kOkMpRC;
342 344
   MIDIDeviceRef mdr;
@@ -349,11 +351,11 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
349 351
   _cmMpDeviceInit(drp);
350 352
 
351 353
   // get the device ref
352
-  if((mdr = MIDIGetDevice(devIdx)) == 0 )
353
-    return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i failed.",devIdx);
354
+  if((mdr = MIDIGetDevice(deviceId)) == 0 )
355
+    return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i failed.",deviceId);
354 356
    
355 357
   // determine if the device port count and whether it is active
356
-  if((rc = _cmMpIsDeviceActive(devIdx, mdr, &devSrcCnt, &devDstCnt, &activeFl, errPtr )) != kOkMpRC )
358
+  if((rc = _cmMpIsDeviceActive(deviceId, mdr, &devSrcCnt, &devDstCnt, &activeFl, errPtr )) != kOkMpRC )
357 359
     return rc;
358 360
 
359 361
   // if the device is not active return with the device record empty
@@ -371,6 +373,9 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
371 373
   // form the device name string
372 374
   drp->nameStr = _cmMpFormLabel( errPtr, (MIDIObjectRef)mdr);
373 375
 
376
+  drp->devId = deviceId;
377
+  drp->devIdx = deviceIdx;
378
+
374 379
 
375 380
   unsigned entityCnt = MIDIDeviceGetNumberOfEntities(mdr);
376 381
   unsigned iPortCnt  = 0;
@@ -385,7 +390,7 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
385 390
     // get the entity reference
386 391
     if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
387 392
     {
388
-      rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
393
+      rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",deviceId,ei);
389 394
       goto errLabel;
390 395
     }
391 396
 
@@ -403,18 +408,20 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
403 408
       // fill idArray with the unique id's of the active ports on this entity
404 409
       if((rc = _cmMpGetEntityUniqueIdArray(mer,idArray,entityPortCnt,inputFl,&activeCnt,errPtr)) != kOkMpRC )
405 410
       {
406
-        rc = _cmMpError(errPtr,rc,noErr,"Unable to locate unique source ids on device:%i entity:%i",devIdx,ei);
411
+        rc = _cmMpError(errPtr,rc,noErr,"Unable to locate unique source ids on device:%i entity:%i",deviceId,ei);
407 412
         goto errLabel;
408 413
       }
409 414
 
410 415
       // assign the unique id's to each cmMpPort assoc'd with this entity
411
-      _cmMpInitPortArray(devIdx, inPortRef, mer, portArray + portCnt, idArray, entityPortCnt, inputFl, cbFunc, cbDataPtr, parserBufByteCnt, errPtr );
416
+      _cmMpInitPortArray(deviceIdx, inPortRef, mer, portArray + portCnt, idArray, entityPortCnt, inputFl, cbFunc, cbDataPtr, parserBufByteCnt, errPtr );
412 417
 
413 418
       if( inputFl )
414 419
         iPortCnt += entityPortCnt;
415 420
       else
416 421
         oPortCnt += entityPortCnt;
417 422
 
423
+
424
+      //printf("OSX MIDI %i %i %i %s\n",deviceId,ei,i,drp->nameStr);
418 425
     }
419 426
   }
420 427
 
@@ -454,7 +461,7 @@ cmMpRC_t _cmMpCreateDeviceArray( cmMpRoot* rp, unsigned parserBufByteCnt )
454 461
     cmMpDev* drp = rp->devArray + rp->devCnt;
455 462
 
456 463
     // attempt to create a device record for device di
457
-    if((rc = _cmMpCreateDevice(  di, drp, rp->inPortRef, rp->cbFunc, rp->cbDataPtr, parserBufByteCnt, &rp->err )) != kOkMpRC )
464
+    if((rc = _cmMpCreateDevice(  di, rp->devCnt, drp, rp->inPortRef, rp->cbFunc, rp->cbDataPtr, parserBufByteCnt, &rp->err )) != kOkMpRC )
458 465
       goto errLabel;
459 466
 
460 467
     // if the device di is active 

Loading…
Cancel
Save