The pyrtmidi module is now complete, offering both a blocking or non-blocking getMessage(timeout_ms=None) and setCallback(func) option. As far as I know, this is now the only complete python midi I/O extension.
I have not compiled it on windows (in fact it probably won’t compile), have not compiled on linux (but it probably works), and the code passes initial tests on mac but other reports are more than welcome.
Thank you all for your patches, and have fun using midi hardware in your apps!
it doesn’t compile on ubuntu 10.04.
kernel 2.6.32-24-generic #43-Ubuntu SMP
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
log with errors from compiling is here:
How hilarious; I had literally just created a mercurial repo planning on doing almost all of this myself… then I figured, maybe google has an answer.
I think PK_WINOWS is mistakenly set for linux so HANDLE is not defined.
If I set PK_WINOWS 0 then I can compile
the test_callback gives me messages but claims all my events are AFTERTOUCH.
The other tests have problems
$ python clock_output.py
Exception in thread Thread-1:
Traceback (most recent call last):
File “/usr/lib/python2.6/threading.py”, line 532, in __bootstrap_inner
File “clock_output.py”, line 50, in run
File “clock_output.py”, line 85, in send
Error: argument 1 must be of type MidiMessage
i did (almost) the same with PK_WINDOWS (deleted them ;))
and this is the simplest test in ipython i came up with:
rtm = rtmidi.RtMidiIn()
mlm = rtmidi.MidiMessage().noteOn(0,33,.4)
rtmo = rtmidi.RtMidiOut()
this should print out the mlm midi message.. i think tests should be changed so the arguments for sendMessage are rtmidi.MidiMessage not hex numbers…
and yes.. i connected rtmidi in and out in qjackconnect.. that should be done so rtm can print out incoming midi messages
I’m glad to hear someone has this working (or am I mistaken?) on linux. I don’t have a linux machine and have no plans to build one again, but I will try this out on windows when I get a chance. It’s a shame that it is so hard to set up python and building extensions on windows or I’d be all over it.
here is the patch/diff. this worked for me on linux.
— rtmidimodule.cpp 2010-11-27 22:23:15.372724687 +0100
+++ rtmidimodule.cppNEW 2010-11-27 22:23:37.982726094 +0100
@@ -27,11 +27,15 @@
#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
-#define PK_WINDOWS 1
+#define PK_WINDOWS 0
#define PK_WINDOWS 0
+#define PK_WINDOWS 1
#if PY_MAJOR_VERSION == 3
#define PK_PYTHON3 1
The Marcell Mars patch was the only way for me to compile and install pyrtmidi. Thanks to you both.
Here is a patch I made for PyRtMidi.
It permits to pass a name in the RtMidiIn/Out constructors and openPort() to personalize your midi application.
Thank you all for your patches. They are all in the repository now and I have it working on my mac. Let me know if there are any more issues on linux.
Just to notice, I couldn’t make it works with Python 2.7. I have to use python 2.6.
With 2.7, I get this error message:
ImportError: /usr/local/lib/python2.7/dist-packages/rtmidi.so: undefined symbol: _ZN11MidiMessageaSERKS
just found your pyrtmidi and I tried to get it working. But when I tried to use it, it thwors an error similar to the last comment:
sascha@rd1:~/devel/pkaudio/pyrtmidi/tests$ python test_rtmidi.py
Traceback (most recent call last):
File “test_rtmidi.py”, line 29, in
ImportError: /usr/local/lib/python2.6/dist-packages/rtmidi.so: undefined symbol: _ZN11MidiMessageaSERKS_
What could cause this?
As you can see I’m using py26 on linux/debian
Am I missing any libraries?
Best regards Sascha
It’s a problem in the setup.py file for pyrtmidi, which is simply missing a source file. I will try to get it to build on ubuntu as soon as I get a chance, but anyone else that has a patch could send it along to speed this up. Should just be a one-liner.
Also, there is a pyrtmidi google group. Please post questions there:
Scratch that, I have moved pyrtmidi to github:
Please post all questions as issues there.