I have a Swift class that extends AudioKit's MIDIListener
to handle receiving MIDI messages from external and virtual devices. It receives noteOn
and noteOff
messages like so:
func receivedMIDINoteOn(noteNumber: MIDINoteNumber,
velocity: MIDIVelocity,
channel: MIDIChannel,
portID: MIDIUniqueID? = nil,
offset: MIDITimeStamp = 0) {
DispatchQueue.main.async {
self.data.noteOn = Int(noteNumber)
self.data.velocity = Int(velocity)
self.data.channel = Int(channel)
}
}
func receivedMIDINoteOff(noteNumber: MIDINoteNumber,
velocity: MIDIVelocity,
channel: MIDIChannel,
portID: MIDIUniqueID? = nil,
offset: MIDITimeStamp = 0) {
DispatchQueue.main.async {
self.data.noteOff = Int(noteNumber)
self.data.channel = Int(channel)
}
}
I'd like this class to also handle broadcasting or sending out MIDI messages created within the application out to these external and virtual devices. And I'm doing so with these calls:
midi.sendNoteOnMessage(noteNumber: MIDINoteNumber(note), velocity: MIDIVelocity(velocity))
And:
midi.sendNoteOffMessage(noteNumber: MIDINoteNumber(note), velocity: MIDIVelocity(velocity))
But, when I send messages the received
methods also fire. This duplicates the intended behavior for the end user in the application. Is there a preferred way to not send messages out, but not have them received internal to the application? Or a different method I should be calling?