A tutorial on how to send midi signals from a python script to a midi track in ableton live
- Python (duh...), I am using (python 3.7.3)[https://www.python.org/downloads/]
- Pip install this package pip install python-rtmidi
- Install this software: loopMidi by Tobias Erichsen
- A DAW (short for Digital Audio Workstation), I am using Ableton live 10 Standard 10.0.6
- Windows?
- Because I couldn't find any resources on how to send Midi Notes from a Python script to Ableton for windows
- You want to send Midi Signals from Python to Ableton Live on a Windows pc
- We can't communicate directly between ableton live and python
- We need to create a virtual port to which we can send midi signals from python and to which ableton will be "listening" to
- We need to write a script that send midi signals, for that purpose we will use the python-rtmidi package
- We need to setup ableton to listen to the port
- Install python and the python rt-midi package
- Install the loopMidi software, once you launch it you should see something like this:
- Now press the little plus button in the bottom-left corner: You'll see that it'll add an item to list. Voila, we created a new port.
- Now let's write the python script that'll send some notes to the port:
import time
import rtmidi
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
# here we're printing the ports to check that we see the one that loopMidi created.
# In the list we should see a port called "loopMIDI port".
print(available_ports)
# Attempt to open the port
if available_ports:
midiout.open_port(1)
else:
midiout.open_virtual_port("My virtual output")
note_on = [0x90, 60, 112]
note_off = [0x80, 60, 0]
midiout.send_message(note_on)
time.sleep(0.5)
# I tried running the script without having to invoke the sleep function but it doesn't work.
# If someone could enlighten me as to why this is, I'd be more than grateful.
midiout.send_message(note_off)
del midiout
Here we're simply sending a middle C note as MIDI to the port. Save this in a .py
file, we'll need to run it later.
-
Now let's set up Ableton:
- Go to Preferences -> MIDI link where you should see the loopMidi port as an input and output port. Set the loopMidi port's track and sync to "On"
- Create a new Midi track in your project
- Set the input of the track to be the "loopMidi Port" and set the track to "In"
- Also don't forget to load the track with a synth. An ableton stock sound should also do the trick.
-
Run the script
python "scriptname".py
in your command prompt, and you should be able to hear ableton play back a C note at you.
I hope this helped, if anything is unclear or you have suggestions let me know.