简体   繁体   English

如何将 Midi 消息发送到 python 中的 midi controller

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

I want to send midi messages in python to my Mpk Mini 2 (a midi controller) but I don't find how to do that.我想将 python 中的 midi 消息发送到我的Mpk Mini 2 (midi 控制器),但我不知道该怎么做。 The only tutorials I found explain how to receive messages, not how to send them.我发现的唯一教程解释了如何接收消息,而不是如何发送消息。

With MidiView app, I saw the messages I had to send.使用 MidiView 应用程序,我看到了我必须发送的消息。 The only problem is I don't know how to do it唯一的问题是我不知道该怎么做

And I got my ports我得到了我的端口


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

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

What I would like to do is send a midi message to the keyboard so that its pads flash.我想做的是向键盘发送一条 midi 消息,以便其垫 flash。 Can someone help me?有人能帮我吗?

There is an example of sending a MIDI message in the documentation of rtmidi that you can follow to accomplish what you want.rtmidi的文档中有一个发送 MIDI 消息的示例,您可以按照该示例来完成您想要的操作。

With your MidiView app, if you already have the message, you can send it like that, with send_message() method:使用您的 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 is Note-on message, 0x80 is Note-off) (0x90 是 Note-on 消息,0x80 是 Note-off)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM