繁体   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