• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <Foundation/Foundation.h>
18 
19 @class MIDIClient;
20 @class MIDIDestination;
21 @class MIDISource;
22 
23 extern NSString * const MIDIClientErrorDomain;
24 
25 /**
26  * Callbacks for MIDIClient changes.
27  *
28  * Note that these methods may not be called on the main thread.
29  */
30 @protocol MIDIClientDelegate <NSObject>
31 /** Called when a MIDIClient receives data from a connected source. */
32 - (void)MIDIClient:(MIDIClient *)client receivedData:(NSData *)message;
33 
34 @optional
35 /** Called when a MIDI I/O error occurs on the client's endpoints. */
36 - (void)MIDIClient:(MIDIClient *)client receivedError:(NSError *)error;
37 
38 /** Called when a MIDI endpoint has been added to the system. */
39 - (void)MIDIClientEndpointAdded:(MIDIClient *)client;
40 
41 /** Called when a MIDI endpoint has been removed to the system. */
42 - (void)MIDIClientEndpointRemoved:(MIDIClient *)client;
43 
44 /** Called when the configuration of a MIDI object attached to the system has changed. */
45 - (void)MIDIClientConfigurationChanged:(MIDIClient *)client;
46 @end
47 
48 /** A MIDI client that can read data from a MIDI source and write data to a MIDI destination. */
49 @interface MIDIClient : NSObject
50 /** The source attached by -connectToSource:error:. */
51 @property (readonly, nonatomic) MIDISource *source;
52 
53 /** The destination attached by -connectToDestination:error:. */
54 @property (readonly, nonatomic) MIDIDestination *destination;
55 
56 @property (nonatomic, weak) id<MIDIClientDelegate> delegate;
57 
58 /**
59  * Creates a new MIDI client with a friendly name.
60  *
61  * If an error occurs, nil is returned and the error is populated with a description of the issue.
62  */
63 - (instancetype)initWithName:(NSString *)name error:(NSError **)error;
64 
65 /** Attaches an input source to the client. */
66 - (BOOL)connectToSource:(MIDISource *)source error:(NSError **)error;
67 
68 /** Attaches an output destination to the client. */
69 - (BOOL)connectToDestination:(MIDIDestination *)destination error:(NSError **)error;
70 
71 /** Sends a MIDI packet of data to the client's output destination. */
72 - (BOOL)sendData:(NSData *)data error:(NSError **)error;
73 @end
74