Sending midi stream using python


I’m messing about with Python generation of midi.

I have the midi file specification which I’ll port to python friendly code.

Anyone know how to stream midi? I can output to a file but I’d like to generate midi on the fly and have it play through garritan personal orchestra or similar.

any thoughts?



Have a look at rtmidi:

This is one of the libraries we use on the Mad Music Machine.

Hi @adri123 - is this question related to the use of Sonic Pi in any way? If not, and it’s just specific to Python, then someone on here may be able to help out, but you’re going to have much more luck on Python-focussed forums :slight_smile:

Happened to kind of playing around with the idea of streaming MIDI to Sonic Pi.

Maybe you can try this:
MIDI to XML for Sonic Pi using Processing

But I think you can also use Python MIDO module and RTMIDI to send MIDI message into Sonic Pi. Seems to do the job, although MIDO can be a bit slow somewhat. It works cool though.

Seconding @gavin, I’ve also had good luck with python-rtmidi (though I haven’t tried it yet with Sonic Pi as the target for output).

See the example at

The basic steps are:

  1. Instantiate a MidiOut object
  2. Open a virtual port for output
  3. Compose midi messages as python lists
  4. Send the messages with MidiOut.send_message()

You’ll need to tell Sonic Pi to listen on your virtual port for incoming midi. It’s up to you to control when the messages (e.g. NoteOn and NoteOff) are sent so that notes begin and end at the appropriate times.

Hope this helps!