Bläddra i källkod

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

Use _cmMpRtPtr to notice the first use of _cmMpRoot.
master
kevin 11 år sedan
förälder
incheckning
48884c3389
1 ändrade filer med 27 tillägg och 18 borttagningar
  1. 27
    18
      osx/cmMidiOsx.c

+ 27
- 18
osx/cmMidiOsx.c Visa fil

@@ -7,6 +7,7 @@
7 7
 #include "cmGlobal.h"
8 8
 #include "cmRpt.h"
9 9
 #include "cmErr.h"
10
+#include "cmCtx.h"
10 11
 #include "cmMem.h"
11 12
 #include "cmMallocDebug.h"
12 13
 #include "cmMidi.h"
@@ -52,7 +53,8 @@ typedef struct
52 53
   
53 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 59
 cmMpRC_t _cmMpError( cmErr_t* errPtr, cmMpRC_t rc, OSStatus err, const char* fmt, ... )
58 60
 { 
@@ -186,7 +188,7 @@ char* _cmMpFormPortLabel( cmErr_t* errPtr, MIDIEntityRef mer, ItemCount pi, bool
186 188
   else 
187 189
     epr = MIDIEntityGetDestination( mer, pi); 
188 190
 
189
-  if(epr == NULL )
191
+  if(epr == 0 )
190 192
   {
191 193
     _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.", inputFl ? "source" : "destination",pi);
192 194
     return NULL;
@@ -212,7 +214,7 @@ cmMpRC_t _cmMpGetEntityUniqueIdArray( MIDIEntityRef mer, SInt32* idArray, unsign
212 214
   {
213 215
     epr = inputFl ? MIDIEntityGetSource( mer, pi) : MIDIEntityGetDestination( mer, pi); 
214 216
 
215
-    if(epr == NULL )
217
+    if(epr == 0 )
216 218
     {
217 219
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",dirLabel,pi);
218 220
       goto errLabel;
@@ -254,7 +256,7 @@ cmMpRC_t _cmMpInitPortArray( unsigned devIdx, MIDIPortRef mpr, MIDIEntityRef mer
254 256
   {
255 257
     MIDIEndpointRef epr = inputFl ? MIDIEntityGetSource(mer,pi) : MIDIEntityGetDestination(mer,pi);
256 258
 
257
-    if( epr == NULL )
259
+    if( epr == 0 )
258 260
       return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get %s endpoiint ref  %i failed.",inputFl ? "source" : "destination", pi);
259 261
 
260 262
     // if this is an active input port then connect it to the source port
@@ -304,7 +306,7 @@ cmMpRC_t _cmMpIsDeviceActive( unsigned devIdx, MIDIDeviceRef mdr, ItemCount* src
304 306
     ItemCount     activeCnt = 0;
305 307
     MIDIEntityRef mer;
306 308
 
307
-    if((mer = MIDIDeviceGetEntity( mdr, ei)) == NULL )
309
+    if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
308 310
       return _cmMpError( errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
309 311
 
310 312
     if((rc= _cmMpGetActiveEntityPortCount(mer,true,&srcCnt,&activeCnt,errPtr)) != kOkMpRC )
@@ -343,7 +345,7 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
343 345
   _cmMpDeviceInit(drp);
344 346
 
345 347
   // get the device ref
346
-  if((mdr = MIDIGetDevice(devIdx)) == NULL )
348
+  if((mdr = MIDIGetDevice(devIdx)) == 0 )
347 349
     return _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i failed.",devIdx);
348 350
    
349 351
   // determine if the device port count and whether it is active
@@ -377,7 +379,7 @@ cmMpRC_t _cmMpCreateDevice( unsigned devIdx, cmMpDev* drp,  MIDIPortRef inPortRe
377 379
     unsigned        i;
378 380
 
379 381
     // get the entity reference
380
-    if((mer = MIDIDeviceGetEntity( mdr, ei)) == NULL )
382
+    if((mer = MIDIDeviceGetEntity( mdr, ei)) == 0 )
381 383
     {
382 384
       rc = _cmMpError(errPtr,kSysErrMpRC,noErr,"Get midi device %i entity %i failed.",devIdx,ei);
383 385
       goto errLabel;
@@ -531,13 +533,20 @@ cmMpPort* _cmMpGetPort( cmMpDev* drp, unsigned portIdx, unsigned flags )
531 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 538
   cmMpRC_t                  rc                = kOkMpRC;
537 539
 	OSStatus                  err               = noErr;
538 540
 	CFStringRef               clientNameStrRef 	= NULL;
539 541
 	CFStringRef               inPortNameStrRef	= NULL;
540 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 551
   if((rc = cmMpFinalize()) != kOkMpRC )
543 552
     return rc;
@@ -611,28 +620,28 @@ cmMpRC_t cmMpFinalize()
611 620
   OSStatus err = noErr;
612 621
   cmMpRC_t   rc  = kOkMpRC;
613 622
 
614
-  if( _cmMpRoot.inPortRef != NULL )
623
+  if( _cmMpRoot.inPortRef != 0 )
615 624
   {
616 625
     if((err = MIDIPortDispose(_cmMpRoot.inPortRef)) != noErr )
617 626
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the input port.");
618 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 633
     if((err = MIDIPortDispose(_cmMpRoot.outPortRef)) != noErr )
625 634
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIPortDispose() failed on the output port.");
626 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 641
     if((err = MIDIClientDispose(_cmMpRoot.clientRef)) != noErr )
633 642
       rc = _cmMpError(&_cmMpRoot.err,kSysErrMpRC,err,"MIDIClientDispose() failed.");
634 643
     else
635
-      _cmMpRoot.clientRef = NULL;
644
+      _cmMpRoot.clientRef = 0;
636 645
   }
637 646
 
638 647
    _cmMpDestroyDeviceArray(&_cmMpRoot);
@@ -641,16 +650,16 @@ cmMpRC_t cmMpFinalize()
641 650
    _cmMpRoot.devArray   = NULL;
642 651
    _cmMpRoot.cbFunc     = NULL;
643 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 658
   return rc;
650 659
 }
651 660
 
652 661
 bool        cmMpIsInitialized()
653
-{ return _cmMpRoot.clientRef != NULL; }
662
+{ return _cmMpRoot.clientRef != 0; }
654 663
 
655 664
 unsigned      cmMpDeviceCount()
656 665
 {

Laddar…
Avbryt
Spara