MIKMIDIDeviceManager
Objective-C
@interface MIKMIDIDeviceManager : NSObject
Swift
class MIKMIDIDeviceManager : NSObject
MIKMIDIDeviceManager is used to retrieve devices and virtual endpoints available on the system, as well as for connecting to and disconnecting from MIDI endpoints. It is a singleton object.
To get a list of devices available on the system, call -availableDevices. Virtual sources can be retrieved by calling -virtualSources and -virtualDevices, respectively. All three of these properties, are KVO compliant, meaning they can be observed using KVO for changes, and (on OS X) can be bound to UI elements using Cocoa bindings.
MIKMIDIDeviceManager is also used to connect to and disonnect from MIDI endpoints, as well as to send and receive MIDI messages. To connect to a MIDI source endpoint, call -connectInput:error:eventHandler:. To disconnect, call -disconnectInput:. To send MIDI messages/commands to an output endpoint, call -sendCommands:toEndpoint:error:.
-
Used to obtain the shared MIKMIDIDeviceManager instance. MIKMIDIDeviceManager should not be created directly using +alloc/-init or +new. Rather, the singleton shared instance should always be obtained using this property.
Declaration
Objective-C
@property (class, readonly) MIKMIDIDeviceManager *_Nonnull sharedDeviceManager;
Swift
class var shared: MIKMIDIDeviceManager { get }
Return Value
The shared MIKMIDIDeviceManager instance.
-
Used to connect to a MIDI device. Returns a token that must be kept and passed into the -disconnectConnectionforToken: method.
When a connection is made using this method, all of the devices valid source endpoints are connected to. To connect to specific endpoints only, use -connectInput:error:eventHandler:
Declaration
Objective-C
- (nullable id)connectDevice:(nonnull MIKMIDIDevice *)device error:(NSError *_Nullable *_Nullable)error eventHandler:(nonnull MIKMIDIEventHandlerBlock)eventHandler;
Swift
func connect(_ device: MIKMIDIDevice, eventHandler: @escaping MIKMIDIEventHandlerBlock) throws -> Any
Parameters
device
An MIKMIDIDevice instance that should be connected.
error
If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
eventHandler
A block which will be called anytime incoming MIDI messages are received from the device.
Return Value
A connection token to be used to disconnect the input, or nil if an error occurred. The connection token is opaque.
-
Used to connect to a single MIDI input/source endpoint. Returns a token that must be kept and passed into the -disconnectConnectionforToken: method.
Declaration
Objective-C
- (nullable id)connectInput:(nonnull MIKMIDISourceEndpoint *)endpoint error:(NSError *_Nullable *_Nullable)error eventHandler:(nonnull MIKMIDIEventHandlerBlock)eventHandler;
Swift
func connectInput(_ endpoint: MIKMIDISourceEndpoint, eventHandler: @escaping MIKMIDIEventHandlerBlock) throws -> Any
Parameters
endpoint
An MIKMIDISourceEndpoint instance that should be connected.
error
If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
eventHandler
A block which will be called anytime incoming MIDI messages are received from the endpoint.
Return Value
A connection token to be used to disconnect the input, or nil if an error occurred. The connection token is opaque.
-
Disconnects a previously connected MIDI device or input/source endpoint. The connectionToken argument must be a token previously returned by -connectDevice:error:eventHandler: or -connectInput:error:eventHandler:. Only the event handler block passed into the call that returned the token will be disconnected.
Declaration
Objective-C
- (void)disconnectConnectionForToken:(nonnull id)connectionToken;
Swift
func disconnectConnection(forToken connectionToken: Any)
Parameters
connectionToken
The connection token returned by -connectInput:error:eventHandler: when the input was connected.
-
Used to send MIDI messages/commands from your application to a MIDI output endpoint. Use this to send messages to a connected device, or another app connected via virtual MIDI port.
Declaration
Objective-C
- (BOOL)sendCommands:(nonnull NSArray<MIKMIDICommand *> *)commands toEndpoint:(nonnull MIKMIDIDestinationEndpoint *)endpoint error:(NSError *_Nullable *_Nullable)error;
Swift
func send(_ commands: [MIKMIDICommand], to endpoint: MIKMIDIDestinationEndpoint) throws
Parameters
commands
An NSArray containing MIKMIDICommand instances to be sent.
endpoint
An MIKMIDIDestinationEndpoint to which the commands should be sent.
error
If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
Return Value
YES if the commands were successfully sent, NO if an error occurred.
-
Used to send MIDI messages/commands from your application to a MIDI output endpoint. Use this to send messages to a virtual MIDI port created in the your client using the MIKMIDIClientSourceEndpoint class.
Declaration
Objective-C
- (BOOL)sendCommands:(nonnull NSArray<MIKMIDICommand *> *)commands toVirtualEndpoint:(nonnull MIKMIDIClientSourceEndpoint *)endpoint error:(NSError *_Nullable *_Nullable)error;
Swift
func send(_ commands: [MIKMIDICommand], toVirtualEndpoint endpoint: MIKMIDIClientSourceEndpoint) throws
Parameters
commands
An NSArray containing MIKMIDICommand instances to be sent.
endpoint
An MIKMIDIClientSourceEndpoint to which the commands should be sent.
error
If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.
Return Value
YES if the commands were successfully sent, NO if an error occurred.
-
The current MIDI output port. Typically this should only be required for custom Core MIDI implementations in C/C++ where MIKMIDI has already been implemented to handle endpoint setup. Creates a new MIDI output port if one does not already exist.
Declaration
Objective-C
@property (nonatomic, readonly) MIKMIDIOutputPort *_Nonnull outputPort;
Swift
var outputPort: MIKMIDIOutputPort { get }
-
An NSArray containing MIKMIDIDevice instances representing MIDI devices connected to the system.
This property is Key Value Observing (KVO) compliant, and can be observed to be notified when devices are connected or disconnected. It is also suitable for binding to UI using Cocoa Bindings (OS X only).
See
MIKMIDIDeviceWasAddedNotificationSee
MIKMIDIDeviceWasRemovedNotificationDeclaration
Objective-C
@property (nonatomic, readonly) NSArray<MIKMIDIDevice *> *_Nonnull availableDevices;
Swift
var availableDevices: [MIKMIDIDevice] { get }
-
An NSArray containing MIKMIDISourceEndpoint instances representing virtual MIDI sources (inputs) on the system.
This property is Key Value Observing (KVO) compliant, and can be observed to be notified when virtual sources appear or disappear. It is also suitable for binding to UI using Cocoa Bindings (OS X only).
See
MIKMIDIVirtualEndpointWasAddedNotificationSee
MIKMIDIVirtualEndpointWasRemovedNotificationDeclaration
Objective-C
@property (nonatomic, readonly) NSArray<MIKMIDISourceEndpoint *> *_Nonnull virtualSources;
Swift
var virtualSources: [MIKMIDISourceEndpoint] { get }
-
An NSArray containing MIKMIDIDestinationEndpoint instances representing virtual MIDI destinations (outputs) on the system.
This property is Key Value Observing (KVO) compliant, and can be observed to be notified when virtual destinations appear or disappear. It is also suitable for binding to UI using Cocoa Bindings (OS X only).
See
MIKMIDIVirtualEndpointWasAddedNotificationSee
MIKMIDIVirtualEndpointWasRemovedNotificationDeclaration
Objective-C
@property (nonatomic, readonly) NSArray<MIKMIDIDestinationEndpoint *> *_Nonnull virtualDestinations;
Swift
var virtualDestinations: [MIKMIDIDestinationEndpoint] { get }
-
An NSArray of MIKMIDIDevice instances that are connected to at least one event handler.
Declaration
Objective-C
@property (nonatomic, readonly) NSArray<MIKMIDIDevice *> *_Nonnull connectedDevices;
Swift
var connectedDevices: [MIKMIDIDevice] { get }
-
An NSArray of MIKMIDISourceEndpoint instances that are connected to at least one event handler.
Declaration
Objective-C
@property (nonatomic, readonly) NSArray<MIKMIDISourceEndpoint *> *_Nonnull connectedInputSources;
Swift
var connectedInputSources: [MIKMIDISourceEndpoint] { get }
-
Deprecated
@deprecated Use disconnectConnectionforToken: instead. This method now simply calls through to that one.
Disconnects a previously connected MIDI input/source endpoint. The connectionToken argument must be a token previously returned by -connectInput:error:eventHandler:. Only the event handler block passed into the call that returned the token will be disconnected.
Declaration
Objective-C
- (void)disconnectInput:(nullable MIKMIDISourceEndpoint *)endpoint forConnectionToken:(nonnull id)connectionToken;
Swift
func disconnectInput(_ endpoint: MIKMIDISourceEndpoint?, forConnectionToken connectionToken: Any)
Parameters
endpoint
This argument is ignored.
connectionToken
The connection token returned by -connectInput:error:eventHandler: when the input was connected.