Skip to content

Commit e6e24db

Browse files
authored
Merge pull request #308 from MaddTheSane/patch-1
Update RtMidi.cpp
2 parents 4db43af + 44c2ee6 commit e6e24db

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

RtMidi.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ unsigned int MidiInCore :: getPortCount()
12391239

12401240
// This function was submitted by Douglas Casey Tucker and apparently
12411241
// derived largely from PortMidi.
1242-
CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
1242+
CFStringRef CreateEndpointName( MIDIEndpointRef endpoint, bool isExternal )
12431243
{
12441244
CFMutableStringRef result = CFStringCreateMutable( NULL, 0 );
12451245
CFStringRef str;
@@ -1249,13 +1249,10 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
12491249
MIDIObjectGetStringProperty( endpoint, kMIDIPropertyName, &str );
12501250
if ( str != NULL ) {
12511251
CFStringAppend( result, str );
1252-
CFRelease( str );
12531252
}
12541253

12551254
// some MIDI devices have a leading space in endpoint name. trim
1256-
CFStringRef space = CFStringCreateWithCString(NULL, " ", kCFStringEncodingUTF8);
1257-
CFStringTrim(result, space);
1258-
CFRelease(space);
1255+
CFStringTrim(result, CFSTR(" "));
12591256

12601257
MIDIEntityRef entity = 0;
12611258
MIDIEndpointGetEntity( endpoint, &entity );
@@ -1269,7 +1266,6 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
12691266
MIDIObjectGetStringProperty( entity, kMIDIPropertyName, &str );
12701267
if ( str != NULL ) {
12711268
CFStringAppend( result, str );
1272-
CFRelease( str );
12731269
}
12741270
}
12751271
// now consider the device's name
@@ -1282,17 +1278,18 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
12821278
MIDIObjectGetStringProperty( device, kMIDIPropertyName, &str );
12831279
if ( CFStringGetLength( result ) == 0 ) {
12841280
CFRelease( result );
1281+
CFRetain( str );
12851282
return str;
12861283
}
12871284
if ( str != NULL ) {
12881285
// if an external device has only one entity, throw away
12891286
// the endpoint name and just use the device name
12901287
if ( isExternal && MIDIDeviceGetNumberOfEntities( device ) < 2 ) {
12911288
CFRelease( result );
1289+
CFRetain( str );
12921290
return str;
12931291
} else {
12941292
if ( CFStringGetLength( str ) == 0 ) {
1295-
CFRelease( str );
12961293
return result;
12971294
}
12981295
// does the entity name already start with the device name?
@@ -1307,15 +1304,14 @@ CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal )
13071304

13081305
CFStringInsert( result, 0, str );
13091306
}
1310-
CFRelease( str );
13111307
}
13121308
}
13131309
return result;
13141310
}
13151311

13161312
// This function was submitted by Douglas Casey Tucker and apparently
13171313
// derived largely from PortMidi.
1318-
static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
1314+
static CFStringRef CreateConnectedEndpointName( MIDIEndpointRef endpoint )
13191315
{
13201316
CFMutableStringRef result = CFStringCreateMutable( NULL, 0 );
13211317
CFStringRef str;
@@ -1342,11 +1338,12 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
13421338
if ( connObjectType == kMIDIObjectType_ExternalSource ||
13431339
connObjectType == kMIDIObjectType_ExternalDestination ) {
13441340
// Connected to an external device's endpoint (10.3 and later).
1345-
str = EndpointName( (MIDIEndpointRef)(connObject), true );
1341+
str = CreateEndpointName( (MIDIEndpointRef)(connObject), true );
13461342
} else {
13471343
// Connected to an external device (10.2) (or something else, catch-
13481344
str = NULL;
13491345
MIDIObjectGetStringProperty( connObject, kMIDIPropertyName, &str );
1346+
if ( str ) CFRetain ( str );
13501347
}
13511348
if ( str != NULL ) {
13521349
if ( anyStrings )
@@ -1367,7 +1364,7 @@ static CFStringRef ConnectedEndpointName( MIDIEndpointRef endpoint )
13671364
CFRelease( result );
13681365

13691366
// Here, either the endpoint had no connections, or we failed to obtain names
1370-
return EndpointName( endpoint, false );
1367+
return CreateEndpointName( endpoint, false );
13711368
}
13721369

13731370
std::string MidiInCore :: getPortName( unsigned int portNumber )
@@ -1387,7 +1384,7 @@ std::string MidiInCore :: getPortName( unsigned int portNumber )
13871384
}
13881385

13891386
portRef = MIDIGetSource( portNumber );
1390-
nameRef = ConnectedEndpointName( portRef );
1387+
nameRef = CreateConnectedEndpointName( portRef );
13911388
CFStringGetCString( nameRef, name, sizeof(name), kCFStringEncodingUTF8 );
13921389
CFRelease( nameRef );
13931390

@@ -1474,7 +1471,7 @@ std::string MidiOutCore :: getPortName( unsigned int portNumber )
14741471
}
14751472

14761473
portRef = MIDIGetDestination( portNumber );
1477-
nameRef = ConnectedEndpointName(portRef);
1474+
nameRef = CreateConnectedEndpointName(portRef);
14781475
CFStringGetCString( nameRef, name, sizeof(name), kCFStringEncodingUTF8 );
14791476
CFRelease( nameRef );
14801477

0 commit comments

Comments
 (0)