【问题标题】:How to send Midi messages to a midi controller in python如何将 Midi 消息发送到 python 中的 midi 控制器
【发布时间】:2022-01-22 21:47:18
【问题描述】:

我想用 python 向我的Mpk Mini 2(一个 midi 控制器)发送 midi 消息,但我不知道怎么做。我找到的唯一教程解释了如何接收消息,而不是如何发送消息。

使用 MidiView 应用程序,我看到了我必须发送的消息。唯一的问题是我不知道该怎么做

我得到了我的端口


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

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

我想做的是向键盘发送一条 midi 消息,以便它的打击垫闪烁。有人可以帮我吗?

【问题讨论】:

    标签: python midi


    【解决方案1】:

    rtmidi 的文档中有一个example 发送 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)

    【讨论】:

    • 我遇到了这个错误:Traceback (most recent call last): File "c:\Users\baron_btjit4i\Desktop\test.py", line 7, in <module> midiout.open_port('MPKmini2 1') File "src\_rtmidi.pyx", line 549, in rtmidi._rtmidi.MidiBase.open_port TypeError: an integer is required
    • 试试midiout.open_port(1)。在文档中,我读到我们可以按名称打开端口,但如果它不起作用,只需传递get_ports()1 返回的端口号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多