Skip to content

Commit

Permalink
Fixed some bugs where we didn't disconnect receivers of MIDI when dea…
Browse files Browse the repository at this point in the history
…llocating them, possibly leading to crashes when closing documents, if MIDI was being received at the time.
  • Loading branch information
krevis committed Aug 19, 2009
1 parent 0e33a10 commit 4ffca93
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
Binary file modified Applications/MIDIMonitor/English.lproj/InfoPlist.strings
Binary file not shown.
6 changes: 3 additions & 3 deletions Applications/MIDIMonitor/Info-MIDIMonitor.plist
Expand Up @@ -28,7 +28,7 @@
<key>CFBundleExecutable</key>
<string>MIDI Monitor</string>
<key>CFBundleGetInfoString</key>
<string>1.2.2, Copyright 2001-2009 Kurt Revis</string>
<string>1.2.3b1, Copyright 2001-2009 Kurt Revis</string>
<key>CFBundleIconFile</key>
<string>MIDIMonitor.icns</string>
<key>CFBundleIdentifier</key>
Expand All @@ -40,11 +40,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.2</string>
<string>1.2.3b1</string>
<key>CFBundleSignature</key>
<string>mMon</string>
<key>CFBundleVersion</key>
<string>1.2.2</string>
<string>1.2.3b1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2001-2009 Kurt Revis</string>
<key>NSMainNibFile</key>
Expand Down
3 changes: 3 additions & 0 deletions Applications/MIDIMonitor/SMMCombinationInputStream.m
Expand Up @@ -76,12 +76,15 @@ - (void)dealloc;
[groupedInputSources release];
groupedInputSources = nil;

[portInputStream setMessageDestination:nil];
[portInputStream release];
portInputStream = nil;

[virtualInputStream setMessageDestination:nil];
[virtualInputStream release];
virtualInputStream = nil;

[spyingInputStream setMessageDestination:nil];
[spyingInputStream release];
spyingInputStream = nil;

Expand Down
2 changes: 2 additions & 0 deletions Applications/MIDIMonitor/SMMDocument.m
Expand Up @@ -98,8 +98,10 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[stream setMessageDestination:nil];
[stream release];
stream = nil;
[messageFilter setMessageDestination:nil];
[messageFilter release];
messageFilter = nil;
[windowFrameDescription release];
Expand Down
39 changes: 29 additions & 10 deletions Applications/MIDIMonitor/SMMSpyingInputStream.m
Expand Up @@ -94,20 +94,19 @@ - (void)addEndpoint:(SMDestinationEndpoint *)endpoint;
return;

parser = [self newParserWithOriginatingEndpoint:endpoint];

status = MIDISpyPortConnectDestination(spyPort, [endpoint endpointRef], parser);
if (status != noErr) {
NSLog(@"Error from MIDISpyPortConnectDestination: %ld", status);
return;
}

NSMapInsert(parsersForEndpoints, endpoint, parser);

center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(endpointDisappeared:) name:SMMIDIObjectDisappearedNotification object:endpoint];
[center addObserver:self selector:@selector(endpointWasReplaced:) name:SMMIDIObjectWasReplacedNotification object:endpoint];

[endpoints addObject:endpoint];

status = MIDISpyPortConnectDestination(spyPort, [endpoint endpointRef], parser);
if (status != noErr) {
NSLog(@"Error from MIDISpyPortConnectDestination: %ld", status);
return;
}
}

- (void)removeEndpoint:(SMDestinationEndpoint *)endpoint;
Expand Down Expand Up @@ -172,14 +171,34 @@ - (NSArray *)parsers;

- (SMMessageParser *)parserForSourceConnectionRefCon:(void *)refCon;
{
return (SMMessageParser *)refCon;
// note: refCon is an SMDestinationEndpoint*.
// We are allowed to return nil if we are no longer listening to this source endpoint.
return (SMMessageParser*)NSMapGet(parsersForEndpoints, refCon);
}

- (id<SMInputStreamSource>)streamSourceForParser:(SMMessageParser *)parser;
{
return [parser originatingEndpoint];
}

- (void)retainForIncomingMIDIWithSourceConnectionRefCon:(void *)refCon
{
// retain self
[super retainForIncomingMIDIWithSourceConnectionRefCon:refCon];

// and retain the endpoint too, since we use it as a key in -parserForSourceConnectionRefCon:
[(SMDestinationEndpoint*)refCon retain];
}

- (void)releaseForIncomingMIDIWithSourceConnectionRefCon:(void *)refCon
{
// release the endpoint that we retained earlier
[(SMDestinationEndpoint*)refCon release];

// and release self, LAST
[super releaseForIncomingMIDIWithSourceConnectionRefCon:refCon];
}

- (NSArray *)inputSources;
{
NSMutableArray *inputSources;
Expand Down
6 changes: 3 additions & 3 deletions Applications/SysExLibrarian/Info-SysExLibrarian.plist
Expand Up @@ -73,7 +73,7 @@
<key>CFBundleExecutable</key>
<string>SysEx Librarian</string>
<key>CFBundleGetInfoString</key>
<string>1.2.1, Copyright 2002-2009 Kurt Revis</string>
<string>1.2.2b1, Copyright 2002-2009 Kurt Revis</string>
<key>CFBundleIconFile</key>
<string>SysExLibrarian.icns</string>
<key>CFBundleIdentifier</key>
Expand All @@ -85,11 +85,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>1.2.2b1</string>
<key>CFBundleSignature</key>
<string>SnSX</string>
<key>CFBundleVersion</key>
<string>1.2.1</string>
<string>1.2.2b1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2002-2009 Kurt Revis</string>
<key>NSMainNibFile</key>
Expand Down
1 change: 1 addition & 0 deletions Applications/SysExLibrarian/SSEMIDIController.m
Expand Up @@ -125,6 +125,7 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];

[inputStream setMessageDestination:nil];
[inputStream release];
inputStream = nil;
[outputStream release];
Expand Down

0 comments on commit 4ffca93

Please sign in to comment.