Blocking functionality to pyrtmidi

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.

http://trac2.assembla.com/pkaudio/wiki/pyrtmidi

Thank you all for your patches, and have fun using midi hardware in your apps!

By | 2010-09-27T01:33:00+00:00 September 27th, 2010|Uncategorized|15 Comments

15 Comments

  1. marcell September 27, 2010 at 12:08 pm - Reply

    it doesn’t compile on ubuntu 10.04.
    kernel 2.6.32-24-generic #43-Ubuntu SMP
    Python 2.6.5
    gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

    log with errors from compiling is here:
    http://pastebin.com/cTinVbwd

  2. Matt November 22, 2010 at 2:56 am - Reply

    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.

    Thanks!

  3. PJ November 27, 2010 at 3:26 pm - Reply

    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
    self.run()
    File “clock_output.py”, line 50, in run
    self.send(MIDI_CLOCK)
    File “clock_output.py”, line 85, in send
    self.dev.sendMessage(*args)
    Error: argument 1 must be of type MidiMessage

    ———–

  4. Nenad Romic aka Marcell Mars November 27, 2010 at 7:10 pm - Reply

    i did (almost) the same with PK_WINDOWS (deleted them ;))

    and this is the simplest test in ipython i came up with:

    import rtmidi
    rtm = rtmidi.RtMidiIn()
    rtm.openVirtualPort(“yo”)
    def foobar(a):
    print dir(a)

    rtm.setCallback(foobar)

    mlm = rtmidi.MidiMessage().noteOn(0,33,.4)
    rtmo = rtmidi.RtMidiOut()
    rtmo.openVirtualPort(“oy”)
    rtmo.sendMessage(mlm)

    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…

  5. Nenad Romic aka Marcell Mars November 27, 2010 at 7:12 pm - Reply

    and yes.. i connected rtmidi in and out in qjackconnect.. that should be done so rtm can print out incoming midi messages

  6. Patricio November 27, 2010 at 7:38 pm - Reply

    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.

  7. Nenad Romic aka Marcell Mars November 27, 2010 at 9:29 pm - Reply

    here is the patch/diff. this worked for me on linux.

    http://ge.tt/41Uitr

    cat pyrtmidi-APPLE_LINUX_WINDOWS.diff

    — 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;
    #endif

    -#ifndef __APPLE__
    -#define PK_WINDOWS 1
    -#else
    +#ifdef __APPLE__
    +#define PK_WINDOWS 0
    +#endif
    +#ifdef __LINUX__
    #define PK_WINDOWS 0
    #endif
    +#ifdef __WINDOWS__
    +#define PK_WINDOWS 1
    +#endif

    #if PY_MAJOR_VERSION == 3
    #define PK_PYTHON3 1

  8. Ted July 15, 2011 at 3:25 pm - Reply

    The Marcell Mars patch was the only way for me to compile and install pyrtmidi. Thanks to you both.

  9. Ted July 16, 2011 at 4:55 pm - Reply

    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.
    Enjoy 😉

    http://www.box.net/shared/nntxd2vijrfp7ekr6gdr

  10. Patricio July 18, 2011 at 2:22 am - Reply

    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.

  11. Ted September 28, 2011 at 8:54 am - Reply

    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

    Cheers,
    Ted

  12. Anonymous June 24, 2012 at 1:16 pm - Reply

    Hi Patrick

    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
    import rtmidi
    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

  13. Patrick Stinson June 25, 2012 at 6:07 pm - Reply

    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.

  14. Patrick Stinson June 25, 2012 at 6:08 pm - Reply

    Also, there is a pyrtmidi google group. Please post questions there:

    https://groups.google.com/forum/?fromgroups#!forum/pyrtmidi

  15. Patrick Stinson June 25, 2012 at 7:49 pm - Reply

    Scratch that, I have moved pyrtmidi to github:

    https://github.com/patrickkidd/pyrtmidi

    Please post all questions as issues there.

Leave A Comment

16 − 7 =