Skip to content

Commit

Permalink
Issue #106: Fixed issues related to saving MIKMIDIConnectionManager c…
Browse files Browse the repository at this point in the history
…onfiguration.
  • Loading branch information
Andrew Madsen committed Nov 6, 2015
1 parent 41d5ed0 commit 0a2f6ce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Source/MIKMIDIConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ - (instancetype)initWithName:(NSString *)name delegate:(id<MIKMIDIConnectionMana
_name = [name copy];
_delegate = delegate;
_eventHandler = eventHandler;

_automaticallySavesConfiguration = YES;
_includesVirtualDevices = YES;

_internalConnectedDevices = [[NSMutableSet alloc] init];
Expand Down Expand Up @@ -141,14 +143,14 @@ - (void)saveConfiguration
NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithDictionary:[self savedConfiguration]];

// Save connected device names
NSMutableArray *connectedDeviceNames = configuration[MIKMIDIConnectionManagerConnectedDevicesKey];
NSMutableArray *connectedDeviceNames = [configuration[MIKMIDIConnectionManagerConnectedDevicesKey] mutableCopy];
if (!connectedDeviceNames) {
connectedDeviceNames = [NSMutableArray array];
configuration[MIKMIDIConnectionManagerConnectedDevicesKey] = connectedDeviceNames;
}

// And explicitly unconnected device names
NSMutableArray *unconnectedDeviceNames = configuration[MIKMIDIConnectionManagerUnconnectedDevicesKey];
NSMutableArray *unconnectedDeviceNames = [configuration[MIKMIDIConnectionManagerUnconnectedDevicesKey] mutableCopy];
if (!unconnectedDeviceNames) {
unconnectedDeviceNames = [NSMutableArray array];
configuration[MIKMIDIConnectionManagerUnconnectedDevicesKey] = unconnectedDeviceNames;
Expand All @@ -160,14 +162,17 @@ - (void)saveConfiguration
NSString *name = device.name;
if (![name length]) continue;
if ([self isConnectedToDevice:device]) {
[connectedDeviceNames addObject:name];
if (![connectedDeviceNames containsObject:name]) { [connectedDeviceNames addObject:name]; }
[unconnectedDeviceNames removeObject:name];
} else {
[connectedDeviceNames removeObject:name];
[unconnectedDeviceNames addObject:name];
if (![unconnectedDeviceNames containsObject:name]) { [unconnectedDeviceNames addObject:name]; }
}
}

configuration[MIKMIDIConnectionManagerConnectedDevicesKey] = connectedDeviceNames;
configuration[MIKMIDIConnectionManagerUnconnectedDevicesKey] = unconnectedDeviceNames;

[userDefaults setObject:configuration forKey:[self userDefaultsConfigurationKey]];
}

Expand Down

0 comments on commit 0a2f6ce

Please sign in to comment.