简体   繁体   中英

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. 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. 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']

What I would like to do is send a midi message to the keyboard so that its pads 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.

With your MidiView app, if you already have the message, you can send it like that, with send_message() method:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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