Skip to content

Instantly share code, notes, and snippets.

View analogcode's full-sized avatar

Matthew Fecher analogcode

View GitHub Profile
@analogcode
analogcode / gist:fa097afb59ee57ccd29e59dfb2526977
Last active January 6, 2024 02:15
Handling AudioBus MIDI Input & State Saving
// **********************************************************
// MARK: - AudioBus MIDI Input
// **********************************************************
extension ParentViewController {
func setupAudioBusInput() {
midiInput = ABMIDIReceiverPort(name: "FM Player MIDI In", title: "FM Player MIDI In") { (port, midiPacketListPointer) in
let events = AKMIDIEvent.midiEventsFrom(packetListPointer: midiPacketListPointer)
// **********************************************************
// MARK: - AudioBus Host Icon
// **********************************************************
private func startObservingInterAppAudioConnections() {
audioUnitPropertyListener = AudioUnitPropertyListener { (audioUnit, property) in
self.hostAppIcon.image = AudioOutputUnitGetHostIcon(AudioKit.engine.outputNode.audioUnit!, 44)
}
AudioKit.engine.outputNode.audioUnit!.add(listener: audioUnitPropertyListener, toProperty: kAudioUnitProperty_IsInterAppConnected)
// in ViewDidLoad in ParentViewController.Swift
// IAA MIDI
var callbackStruct = AudioOutputUnitMIDICallbacks(
userData: nil,
MIDIEventProc: {
(first, status, data1, data2, offset) in
AudioKit.midi.sendMessage([MIDIByte(status), MIDIByte(data1), MIDIByte(data2)])},
MIDISysExProc: {
(firstPointer, secondPinter, anotherInt32) in