diff options
Diffstat (limited to 'ios/WALT/MIDIEndpoint.m')
-rw-r--r-- | ios/WALT/MIDIEndpoint.m | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/ios/WALT/MIDIEndpoint.m b/ios/WALT/MIDIEndpoint.m new file mode 100644 index 0000000..9fe7163 --- /dev/null +++ b/ios/WALT/MIDIEndpoint.m @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "MIDIEndpoint.h" + +@interface MIDIEndpoint () +@property (readwrite, nonatomic, assign) MIDIEndpointRef endpoint; +@end + +@implementation MIDIEndpoint +- (NSString *)name { + CFStringRef result = CFSTR(""); + MIDIObjectGetStringProperty(self.endpoint, kMIDIPropertyDisplayName, &result); + return CFBridgingRelease(result); +} + +- (BOOL)isOnline { + SInt32 result = 1; + MIDIObjectGetIntegerProperty(self.endpoint, kMIDIPropertyOffline, &result); + return (result == 0 ? YES : NO); +} +@end + +@implementation MIDIDestination ++ (NSArray *)allDestinations { + NSMutableArray<MIDIDestination *> *destinations = + [[NSMutableArray<MIDIDestination *> alloc] init]; + + ItemCount destinationCount = MIDIGetNumberOfDestinations(); + for (ItemCount i = 0; i < destinationCount; ++i) { + MIDIEndpointRef endpoint = MIDIGetDestination(i); + if (endpoint) { + MIDIDestination *destination = [[MIDIDestination alloc] init]; + destination.endpoint = endpoint; + [destinations addObject:destination]; + } else { + NSLog(@"Error getting destination at index %lud, skipping.", i); + } + } + + return destinations; +} +@end + +@implementation MIDISource ++ (NSArray *)allSources { + NSMutableArray<MIDISource *> *sources = [[NSMutableArray<MIDISource *> alloc] init]; + + ItemCount sourceCount = MIDIGetNumberOfSources(); + for (ItemCount i = 0; i < sourceCount; ++i) { + MIDIEndpointRef endpoint = MIDIGetSource(i); + if (endpoint) { + MIDISource *source = [[MIDISource alloc] init]; + source.endpoint = endpoint; + [sources addObject:source]; + } else { + NSLog(@"Error getting source at index %lud, skipping.", i); + } + } + + return sources; +} +@end |