MIDI I/O in Python

Jul 20, 2013 at 6:24pm

MIDI I/O in Python

I want to write a MIDI effect in Python — something that can listen to my keyboard input, add a harmony*, and output both to Max. My I/O problems would be solved by a trivially simple piece of example code, one that just adds another note a halfstep up, or transposes its input an octave, or whatever. I could do the rest of it myself — I can write basic Python but I’m failing to get a handle on MIDI input/output.

I installed PythonMIDI (https://github.com/vishnubob/python-midi/) and not even its own tests would run. I installed portmidizero to discover it requires portmidi; I tried installing portmidi and could not figure it out. I tried PyMIDI but it cannot output MIDI, only input it.

I expect processing the notes to be difficult enough. Does anybody know of an easy way to input and output them?

I use a Mac.

#256603
Jul 28, 2013 at 4:01am

If you don’t mind spinning up a JVM, you could use Jython inside Max:

https://github.com/cassiel/net.loadbang.jython

#257347
Jul 29, 2013 at 10:42am

Portmidi works for me. I usually have a python script that opens a MIDI port and sends the notes to Max which renders the audio.

Here is the documentation for portmedia. I think I had to build it again in order to get it to install the python library. I still have the version I built if you need it.

http://sourceforge.net/projects/portmedia/files/portmidi/217/

#257497
Jul 29, 2013 at 10:54am

An even easier solution would be to use the python 2.7 external created by Thomas Grills

http://puredata.info/Members/thomas/py

You can run python scripts in it and then send the output anywhere you want without leaving the Max environment.

#257501
Nov 29, 2013 at 11:59am

My processing speed for your ideas leaves something to be desired. I apologize.

I may have installed PortMidi? What I got was an application called pmdefaults.app, which lets me route inputs to outputs. I don’t have any evidence that my Python library has been modified to allow me to work with PortMidi in Python. Anthony, what Python modules do you use to talk to PortMidi? Would you be willing to share your script?

I am hoping to keep the latency as low as possible, because I will be using it in real time to process my own playing, so I’m leery of using a virtual machine. I also hesitate to bind the code to Max/MSP; I would rather have it run standalone, to reduce the number of dependencies. For instance, I might later decide to go straight from Python into Ableton.

#274145

You must be logged in to reply to this topic.