簡體   English   中英

如何使用 AudioKit 編寫從鍵盤打印所有 MIDI 音符的 Mac 命令行應用程序?

[英]How to use AudioKit to write a Mac command line app that print all the midi notes from keyboard?

我想編寫一個簡單的程序來打印從鍵盤輸入的音符。 我已經在下面顯示了一些內容,但是程序將完成並且不會在那里等待 MIDI 信號。 有任何想法嗎? 謝謝

主文件:

import Foundation
import AudioKit

let midi = MIDI()
midi.openInput()
let receiver = MIDIReceiver()
midi.addListener(receiver)

print("Done")

MIDIReceiver 類:

import Foundation
import AudioKit
import CoreMIDI

class MIDIReceiver: MIDIListener {
func receivedMIDINoteOn(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(noteNumber)
}

func receivedMIDINoteOff(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(noteNumber)
}

func receivedMIDIController(_ controller: MIDIByte, value: MIDIByte, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(controller)
}

func receivedMIDIAftertouch(noteNumber: MIDINoteNumber, pressure: MIDIByte, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(noteNumber)
}

func receivedMIDIAftertouch(_ pressure: MIDIByte, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(pressure)
}

func receivedMIDIPitchWheel(_ pitchWheelValue: MIDIWord, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(pitchWheelValue)
}

func receivedMIDIProgramChange(_ program: MIDIByte, channel: MIDIChannel, portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(program)
}

func receivedMIDISystemCommand(_ data: [MIDIByte], portID: MIDIUniqueID?, offset: MIDITimeStamp) {
    print(data)
}

func receivedMIDISetupChange() {
    print("SetupChange")
}

func receivedMIDIPropertyChange(propertyChangeInfo: MIDIObjectPropertyChangeNotification) {
    print(propertyChangeInfo)
}

func receivedMIDINotification(notification: MIDINotification) {
    print(notification)
}


}

萊納斯,

請查看 SwiftUI 中的 AudioKit v5 Cookbook。 它包括一個 MIDI 監視器示例,可打印出您的應用程序收到的所有 MIDI 音符、程序更改和連續控制編號:

https://github.com/AudioKit/Cookbook/blob/main/Cookbook/Cookbook/Recipes/MIDIMonitor.swift

小心,
標記

只需讓程序繼續運行直到發生按鍵,例如按“q”或“esc”鍵。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM