NSApplication(MIKMIDI)

@interface NSApplication (MIKMIDI)

MIKMIDI implements a category on NSApplication (on OS X) or UIApplication (on iOS) to facilitate the creation and use of a MIDI responder hierarchy, along with the ability to send MIDI commands to responders in that hierarchy.

  • Register a MIDI responder for receipt of incoming MIDI messages.

    If targeting OS X 10.8 or higher, or iOS, the application maintains a zeroing weak reference to the responder, so unregistering the responder on deallocate is not necessary.

    For applications targeting OS X 10.7, registered responders must be explicitly unregistered (e.g. in their -dealloc method) by calling -unregisterMIDIResponder before being deallocated.

    Declaration

    Objective-C

    - (void)registerMIDIResponder:(nonnull id<MIKMIDIResponder>)responder;

    Parameters

    responder

    The responder to register.

  • Unregister a previously-registered MIDI responder so it stops receiving incoming MIDI messages.

    Declaration

    Objective-C

    - (void)unregisterMIDIResponder:(nonnull id<MIKMIDIResponder>)responder;

    Parameters

    responder

    The responder to unregister.

  • When subresponder caching is enabled via shouldCacheMIKMIDISubresponders, This method will cause the cache to be invalidated and regenerated. If a previously registered MIDI responders’ subresponders have changed, it can call this method to force the cache to be refreshed.

    If subresponder caching is disabled (the default), calling this method has no effect, as subresponders are dynamically searched on every call to -MIDIResponderWithIdentifier and -allMIDIResponders.

    See

    shouldCacheMIKMIDISubresponders

    Declaration

    Objective-C

    - (void)refreshMIDIRespondersAndSubresponders;

    Swift

    func refreshMIDIRespondersAndSubresponders()
  • NSApplication (OS X) or UIApplication (iOS) itself implements to methods in the MIKMIDIResponder protocol. This method determines if any responder in the MIDI responder chain (registered responders and their subresponders) responds to the passed in MIDI command, and returns YES if so.

    Declaration

    Objective-C

    - (BOOL)respondsToMIDICommand:(nonnull MIKMIDICommand *)command;

    Swift

    func responds(to command: MIKMIDICommand) -> Bool

    Parameters

    command

    An MIKMIDICommand instance.

    Return Value

    YES if any registered MIDI responder responds to the command.

  • When this method is invoked with a MIDI command, the application will search its registered MIDI responders, for responders that respond to the command, then call their -handleMIDICommand: method.

    Call this method from a MIDI source event handler block to automatically dispatch MIDI commands/messages from that source to all interested registered responders.

    Declaration

    Objective-C

    - (void)handleMIDICommand:(nonnull MIKMIDICommand *)command;

    Swift

    func handle(_ command: MIKMIDICommand)

    Parameters

    command

    The command to dispatch to responders.

  • Returns a registered MIDI responder with the given MIDI identifier.

    Declaration

    Objective-C

    - (nullable id<MIKMIDIResponder>)MIDIResponderWithIdentifier:
        (nonnull NSString *)identifier;

    Parameters

    identifier

    An NSString instance containing the MIDI identifier to search for.

    Return Value

    An object that conforms to MIKMIDIResponder, or nil if no registered responder for the passed in identifier could be found.

  • Returns all MIDI responders that have been registered with the application.

    Declaration

    Objective-C

    - (nonnull NSSet<id<MIKMIDIResponder>> *)allMIDIResponders;

    Return Value

    An NSSet containing objects that conform to the MIKMIDIResponder protocol.

  • When this option is set, the application will cache registered MIDI responders’ subresponders. Setting this option can greatly improve performance of -MIDIResponderWithIdentifier. However, when set, registered responders’ -subresponders method cannot dynamically return different results e.g. for each MIDI command received.

    The entire cache is automatically refreshed anytime a new MIDI responder is registered or unregistered. It can also be manually refreshed by calling -refreshRespondersAndSubresponders.

    For backwards compatibility the default for this option is NO, or no caching.

    See

    -refreshRespondersAndSubresponders

    Declaration

    Objective-C

    @property (nonatomic) BOOL shouldCacheMIKMIDISubresponders;

    Swift

    var shouldCacheMIKMIDISubresponders: Bool { get set }