簡體   English   中英

如何將 Midi 消息發送到 python 中的 midi controller

[英]How to send Midi messages to a midi controller in python

我想將 python 中的 midi 消息發送到我的Mpk Mini 2 (midi 控制器),但我不知道該怎么做。 我發現的唯一教程解釋了如何接收消息,而不是如何發送消息。

使用 MidiView 應用程序,我看到了我必須發送的消息。 唯一的問題是我不知道該怎么做

我得到了我的端口


midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
print(available_ports)

它返回: ['Microsoft GS Wavetable Synth 0', 'MPKmini2 1']

我想做的是向鍵盤發送一條 midi 消息,以便其墊 flash。 有人能幫我嗎?

rtmidi的文檔中有一個發送 MIDI 消息的示例,您可以按照該示例來完成您想要的操作。

使用您的 MidiView 應用程序,如果您已經有消息,您可以使用send_message()方法發送它:

midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()

if available_ports:
    midiout.open_port('MPKmini2 1')

with midiout:
    # This is an example of message, change it according your needs
    # with the MIDI message you get from MidiView
    note_on = [0x90, 60, 112] # channel 1, middle C, velocity 112
    note_off = [0x80, 60, 0]
    # Here you send the message to the device
    midiout.send_message(note_on)
    time.sleep(0.5)
    # Here you send the stop message
    midiout.send_message(note_off)
    time.sleep(0.1)

(0x90 是 Note-on 消息,0x80 是 Note-off)

暫無
暫無

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

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