Browse Source

cmMidiOsx.c: Check OSX references against 0 instead of NULL.

Use _cmMpRtPtr to notice the first use of _cmMpRoot.
master
kevin 11 years ago
parent
commit
48884c3389
1 changed files with 27 additions and 18 deletions
  1. 27
    18
      osx/cmMidiOsx.c

+ 27
- 18
osx/cmMidiOsx.c View File

7
 #include "cmGlobal.h"
7
 #include "cmGlobal.h"
8
 #include "cmRpt.h"
8
 #include "cmRpt.h"
9
 #include "cmErr.h"
9
 #include "cmErr.h"
10
+#include "cmCtx.h"
10
 #include "cmMem.h"
11
 #include "cmMem.h"
11
 #include "cmMallocDebug.h"
12
 #include "cmMallocDebug.h"
12
 #include "cmMidi.h"
13
 #include "cmMidi.h"
52
   
53
   
53
 } cmMpRoot;
54
 } cmMpRoot;
54
 
55
 
55
-cmMpRoot _cmMpRoot = { {NULL,NULL,kOkMpRC}, 0, NULL, NULL, NULL, NULL, NULL, NULL };
56
+cmMpRoot _cmMpRoot;
57
+cmMpRoot* _cmMpRtPtr = NULL;
56
 
58
 
57
 cmMpRC_t _cmMpError( cmErr_t* errPtr, cmMpRC_t rc, OSStatus err, const char* fmt, ... )
59
 cmMpRC_t _cmMpError( cmErr_t* errPtr, cmMpRC_t rc, OSStatus err, const char* fmt, ... )
58
 { 
60
 { 
186
   else 
188
   else 
187
     epr = MIDIEntityGetDestination( mer, pi); 
189
     epr = MIDIEntityGetDestination( mer, pi); 
188
 
190
 
189
-  if(epr == NULL )
191
+  if(epr == 0 )
190
   {
192
   {
191
     _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.", inputFl ? "source" : "destination",pi);
193
     _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.", inputFl ? "source" : "destination",pi);
192
     return NULL;
194
     return NULL;
212
   {
214
   {
213
     epr = inputFl ? MIDIEntityGetSource( mer, pi) : MIDIEntityGetDestination( mer, pi); 
215
     epr = inputFl ? MIDIEntityGetSource( mer, pi) : MIDIEntityGetDestination( mer, pi); 
214
 
216
 
215
-    if(epr == NULL )
217
+    if(epr == 0 )
216
     {
218
     {
217
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",dirLabel,pi);
219
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",dirLabel,pi);
218
       goto errLabel;
220
       goto errLabel;
254
   {
256
   {
255
     MIDIEndpointRef epr = inputFl ? MIDIEntityGetSource(mer,pi) : MIDIEntityGetDestination(mer,pi);
257
     MIDIEndpointRef epr = inputFl ? MIDIEntityGetSource(mer,pi) : MIDIEntityGetDestination(mer,pi);
256
 
258
 
257
-    if( epr == NULL )
259
+    if( epr == 0 )
258
       return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",inputFl ? "source" : "destination", pi);
260
       return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",inputFl ? "source" : "destination", pi);
259
 
261
 
260
     // if this is an active input port then connect it to the source port
262
     // if this is an active input port then connect it to the source port
304
     ItemCount     activeCnt = 0;
306
     ItemCount     activeCnt = 0;
305
     MIDIEntityRef mer;
307
     MIDIEntityRef mer;
306
 
308
 
307
-    if((mer = MIDIDeviceGetEntity( mdr, ei)) == NULL )
309
+    if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
308
       return _cmMpError( errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
310
       return _cmMpError( errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
309
 
311
 
310
     if((rc= _cmMpGetActiveEntityPortCount(mer,true,&srcCnt,&activeCnt,errPtr)) != kOkMpRC )
312
     if((rc= _cmMpGetActiveEntityPortCount(mer,true,&srcCnt,&activeCnt,errPtr)) != kOkMpRC )
343
   _cmMpDeviceInit(drp);
345
   _cmMpDeviceInit(drp);
344
 
346
 
345
   // get the device ref
347
   // get the device ref
346
-  if((mdr = MIDIGetDevice(devIdx)) == NULL )
348
+  if((mdr = MIDIGetDevice(devIdx)) == 0 )
347
     return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i failed.",devIdx);
349
     return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i failed.",devIdx);
348
    
350
    
349
   // determine if the device port count and whether it is active
351
   // determine if the device port count and whether it is active
377
     unsigned        i;
379
     unsigned        i;
378
 
380
 
379
     // get the entity reference
381
     // get the entity reference
380
-    if((mer = MIDIDeviceGetEntity( mdr, ei)) == NULL )
382
+    if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
381
     {
383
     {
382
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
384
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
383
       goto errLabel;
385
       goto errLabel;
531
   return inputFl ? drp->iPortArray + portIdx : drp->oPortArray + portIdx;
533
   return inputFl ? drp->iPortArray + portIdx : drp->oPortArray + portIdx;
532
 }
534
 }
533
 
535
 
534
-cmMpRC_t cmMpInitialize( cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr, cmRpt_t* rpt )
536
+cmMpRC_t cmMpInitialize( cmCtx_t* c, cmMpCallback_t cbFunc, void* cbDataPtr, unsigned parserBufByteCnt, const char* appNameStr )
535
 {
537
 {
536
   cmMpRC_t                  rc                = kOkMpRC;
538
   cmMpRC_t                  rc                = kOkMpRC;
537
 	OSStatus                  err               = noErr;
539
 	OSStatus                  err               = noErr;
538
 	CFStringRef               clientNameStrRef 	= NULL;
540
 	CFStringRef               clientNameStrRef 	= NULL;
539
 	CFStringRef               inPortNameStrRef	= NULL;
541
 	CFStringRef               inPortNameStrRef	= NULL;
540
 	CFStringRef               outPortNameStrRef	= NULL;
542
 	CFStringRef               outPortNameStrRef	= NULL;
543
+  cmRpt_t* rpt = &c->rpt;
544
+
545
+  if( _cmMpRtPtr == NULL )
546
+  {
547
+    memset(&_cmMpRoot,0,sizeof(_cmMpRoot));
548
+    _cmMpRtPtr = &_cmMpRoot;
549
+  }
541
 
550
 
542
   if((rc = cmMpFinalize()) != kOkMpRC )
551
   if((rc = cmMpFinalize()) != kOkMpRC )
543
     return rc;
552
     return rc;
611
   OSStatus err = noErr;
620
   OSStatus err = noErr;
612
   cmMpRC_t   rc  = kOkMpRC;
621
   cmMpRC_t   rc  = kOkMpRC;
613
 
622
 
614
-  if( _cmMpRoot.inPortRef != NULL )
623
+  if( _cmMpRoot.inPortRef != 0 )
615
   {
624
   {
616
     if((err = MIDIPortDispose(_cmMpRoot.inPortRef)) != noErr )
625
     if((err = MIDIPortDispose(_cmMpRoot.inPortRef)) != noErr )
617
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the input port.");
626
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the input port.");
618
     else
627
     else
619
-      _cmMpRoot.inPortRef = NULL;
628
+      _cmMpRoot.inPortRef = 0;
620
   }
629
   }
621
 
630
 
622
-  if( _cmMpRoot.outPortRef != NULL )
631
+  if( _cmMpRoot.outPortRef !=  0 )
623
   {
632
   {
624
     if((err = MIDIPortDispose(_cmMpRoot.outPortRef)) != noErr )
633
     if((err = MIDIPortDispose(_cmMpRoot.outPortRef)) != noErr )
625
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the output port.");
634
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the output port.");
626
     else
635
     else
627
-      _cmMpRoot.outPortRef = NULL;
636
+      _cmMpRoot.outPortRef = 0;
628
   }
637
   }
629
 
638
 
630
-  if( _cmMpRoot.clientRef != NULL )
639
+  if( _cmMpRoot.clientRef != 0 )
631
   {
640
   {
632
     if((err = MIDIClientDispose(_cmMpRoot.clientRef)) != noErr )
641
     if((err = MIDIClientDispose(_cmMpRoot.clientRef)) != noErr )
633
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIClientDispose() failed.");
642
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIClientDispose() failed.");
634
     else
643
     else
635
-      _cmMpRoot.clientRef = NULL;
644
+      _cmMpRoot.clientRef = 0;
636
   }
645
   }
637
 
646
 
638
    _cmMpDestroyDeviceArray(&_cmMpRoot);
647
    _cmMpDestroyDeviceArray(&_cmMpRoot);
641
    _cmMpRoot.devArray   = NULL;
650
    _cmMpRoot.devArray   = NULL;
642
    _cmMpRoot.cbFunc     = NULL;
651
    _cmMpRoot.cbFunc     = NULL;
643
    _cmMpRoot.cbDataPtr  = NULL;
652
    _cmMpRoot.cbDataPtr  = NULL;
644
-   _cmMpRoot.clientRef  = NULL;
645
-   _cmMpRoot.inPortRef  = NULL;
646
-   _cmMpRoot.outPortRef = NULL;
653
+   _cmMpRoot.clientRef  = 0;
654
+   _cmMpRoot.inPortRef  = 0;
655
+   _cmMpRoot.outPortRef = 0;
647
 
656
 
648
 
657
 
649
   return rc;
658
   return rc;
650
 }
659
 }
651
 
660
 
652
 bool        cmMpIsInitialized()
661
 bool        cmMpIsInitialized()
653
-{ return _cmMpRoot.clientRef != NULL; }
662
+{ return _cmMpRoot.clientRef != 0; }
654
 
663
 
655
 unsigned      cmMpDeviceCount()
664
 unsigned      cmMpDeviceCount()
656
 {
665
 {

Loading…
Cancel
Save