Browse Source

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

master
kevin 7 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
 typedef struct
27
 typedef struct
28
 {
28
 {
29
   char*      nameStr;
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
   unsigned   iPortCnt;
33
   unsigned   iPortCnt;
32
   cmMpPort*  iPortArray;
34
   cmMpPort*  iPortArray;
33
 
35
 
336
   return rc;
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
   cmMpRC_t        rc        = kOkMpRC;
343
   cmMpRC_t        rc        = kOkMpRC;
342
   MIDIDeviceRef mdr;
344
   MIDIDeviceRef mdr;
349
   _cmMpDeviceInit(drp);
351
   _cmMpDeviceInit(drp);
350
 
352
 
351
   // get the device ref
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
   // determine if the device port count and whether it is active
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
     return rc;
359
     return rc;
358
 
360
 
359
   // if the device is not active return with the device record empty
361
   // if the device is not active return with the device record empty
371
   // form the device name string
373
   // form the device name string
372
   drp->nameStr = _cmMpFormLabel( errPtr, (MIDIObjectRef)mdr);
374
   drp->nameStr = _cmMpFormLabel( errPtr, (MIDIObjectRef)mdr);
373
 
375
 
376
+  drp->devId = deviceId;
377
+  drp->devIdx = deviceIdx;
378
+
374
 
379
 
375
   unsigned entityCnt = MIDIDeviceGetNumberOfEntities(mdr);
380
   unsigned entityCnt = MIDIDeviceGetNumberOfEntities(mdr);
376
   unsigned iPortCnt  = 0;
381
   unsigned iPortCnt  = 0;
385
     // get the entity reference
390
     // get the entity reference
386
     if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
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
       goto errLabel;
394
       goto errLabel;
390
     }
395
     }
391
 
396
 
403
       // fill idArray with the unique id's of the active ports on this entity
408
       // fill idArray with the unique id's of the active ports on this entity
404
       if((rc = _cmMpGetEntityUniqueIdArray(mer,idArray,entityPortCnt,inputFl,&activeCnt,errPtr)) != kOkMpRC )
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
         goto errLabel;
412
         goto errLabel;
408
       }
413
       }
409
 
414
 
410
       // assign the unique id's to each cmMpPort assoc'd with this entity
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
       if( inputFl )
418
       if( inputFl )
414
         iPortCnt += entityPortCnt;
419
         iPortCnt += entityPortCnt;
415
       else
420
       else
416
         oPortCnt += entityPortCnt;
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
     cmMpDev* drp = rp->devArray + rp->devCnt;
461
     cmMpDev* drp = rp->devArray + rp->devCnt;
455
 
462
 
456
     // attempt to create a device record for device di
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
       goto errLabel;
465
       goto errLabel;
459
 
466
 
460
     // if the device di is active 
467
     // if the device di is active 

Loading…
Cancel
Save