Home | History | Annotate | Download | only in WALT
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #import "MIDIEndpoint.h"
     18 
     19 @interface MIDIEndpoint ()
     20 @property (readwrite, nonatomic, assign) MIDIEndpointRef endpoint;
     21 @end
     22 
     23 @implementation MIDIEndpoint
     24 - (NSString *)name {
     25   CFStringRef result = CFSTR("");
     26   MIDIObjectGetStringProperty(self.endpoint, kMIDIPropertyDisplayName, &result);
     27   return CFBridgingRelease(result);
     28 }
     29 
     30 - (BOOL)isOnline {
     31   SInt32 result = 1;
     32   MIDIObjectGetIntegerProperty(self.endpoint, kMIDIPropertyOffline, &result);
     33   return (result == 0 ? YES : NO);
     34 }
     35 @end
     36 
     37 @implementation MIDIDestination
     38 + (NSArray *)allDestinations {
     39   NSMutableArray<MIDIDestination *> *destinations =
     40       [[NSMutableArray<MIDIDestination *> alloc] init];
     41 
     42   ItemCount destinationCount = MIDIGetNumberOfDestinations();
     43   for (ItemCount i = 0; i < destinationCount; ++i) {
     44     MIDIEndpointRef endpoint = MIDIGetDestination(i);
     45     if (endpoint) {
     46       MIDIDestination *destination = [[MIDIDestination alloc] init];
     47       destination.endpoint = endpoint;
     48       [destinations addObject:destination];
     49     } else {
     50       NSLog(@"Error getting destination at index %lud, skipping.", i);
     51     }
     52   }
     53 
     54   return destinations;
     55 }
     56 @end
     57 
     58 @implementation MIDISource
     59 + (NSArray *)allSources {
     60   NSMutableArray<MIDISource *> *sources = [[NSMutableArray<MIDISource *> alloc] init];
     61 
     62   ItemCount sourceCount = MIDIGetNumberOfSources();
     63   for (ItemCount i = 0; i < sourceCount; ++i) {
     64     MIDIEndpointRef endpoint = MIDIGetSource(i);
     65     if (endpoint) {
     66       MIDISource *source = [[MIDISource alloc] init];
     67       source.endpoint = endpoint;
     68       [sources addObject:source];
     69     } else {
     70       NSLog(@"Error getting source at index %lud, skipping.", i);
     71     }
     72   }
     73 
     74   return sources;
     75 }
     76 @end
     77