Discussion:
pygame.midi
Martin Tarenskeen
2012-08-17 09:22:12 UTC
Permalink
Hi,

This is my first post to the pygame-users list.

I am working on a python project and use pygame for MIDI I/O
functionality.

I want it to work on different platforms and, while I am writing in Python
2.7, it should not take more than running the 2to3 tool to make it running
with Python 3.2

Some strange things happen when using Python 3.2. I have managed to
fix/workaround most of them (I will share my experiences some other time)
and both MIDI IN and OUT is now working on my Linux Fedora 17 system with
both Python 2.7 and 3.2.

But now the strange things. On Windows MIDI IN is working when using
Python 2.7 but failing when using 3.2. I have tested with pre-compiled msi
python and pygame installers from the Python and Pygame websites.

Example code:

from pygame import midi
midi.init()
MIDI_INPUT = midi.Input(1, 5000) # comment: 1 is my MIDI IN device id

this gives an error message:

Traceback (most recent call last)
File "(stdin)", line 1, in <module>
File "C:\Python32\lib\site-packages\pygame\midi.py", line 262, in __init__
self._input = pypm.Input(device_id, buffer_size)
File "pypm.pyx", line 531, in pypm.Input.__init__ (src/pypm.c:2797)
Exception: b"PortMidi: `Insufficient memory'"

If I try the same code again, without a reset, another error message
appears:

Exception: b"PortMidi: `Host error'"


All this does not happen on my Linux Fedora 17 system, and it also does
not happen on Windows if I use Python 2.7

Any pygame.midi gurus here ?
Anyone who can help or knows what's happening here ?
--
MT
Christopher Arndt
2012-08-18 09:49:50 UTC
Permalink
Post by Martin Tarenskeen
Any pygame.midi gurus here ?
I didn't write the pygame.midi or the pyportmidi stuff, but I did a
cleanup of the Cython code a while ago. For various reasons though
(among them the confusing situation regarding the different pyportidi
forks/code bases and the lack of a callback-based API), I switched to
RtMidi. I recently released a new Python binding for it. Give it a try
and if you have any questions about it, let me know.


http://pypi.python.org/pypi/python-rtmidi


Chris
Martin Tarenskeen
2012-08-18 12:38:56 UTC
Permalink
Post by Christopher Arndt
forks/code bases and the lack of a callback-based API), I switched to
RtMidi. I recently released a new Python binding for it. Give it a try
and if you have any questions about it, let me know.
http://pypi.python.org/pypi/python-rtmidi
I installed it on my Linux Fedora 17 system, and only tried shortly, but
when I do

import rtmidi

I get:

ImportError: No module named _rtmidi


Where does that underscore in "_rtmidi" suddenly come from ???
--
MT
Martin Tarenskeen
2012-08-18 12:40:45 UTC
Permalink
Post by Christopher Arndt
http://pypi.python.org/pypi/python-rtmidi
I installed it on my Linux Fedora 17 system, and only tried shortly, but when
I do
import rtmidi
ImportError: No module named _rtmidi
Where does that underscore in "_rtmidi" suddenly come from ???
Never mind. The error message has disappeared.
--
MT
Christopher Arndt
2012-08-19 09:28:36 UTC
Permalink
Post by Martin Tarenskeen
Where does that underscore in "_rtmidi" suddenly come from ???
The package struture is:

rtmidi/
__init__.py
_rtmidi.so
release.py

and the symbols from the _rtmidi module are imported into the package
namespace in __init__.py.

The _rtmidi.so file is the C extension compiled from the C source file
rtmidi.c generated from the Cython file _rtmidi.pyx (in the src
directory of the distribution).
Post by Martin Tarenskeen
ImportError: No module named _rtmidi
I can't say why you got this without more detail, but if you follow the
installation instructions in the README and have all the dependencies
you should be ok.

Chris
Martin Tarenskeen
2012-08-19 10:41:47 UTC
Permalink
Post by Christopher Arndt
I can't say why you got this without more detail, but if you follow the
installation instructions in the README and have all the dependencies
you should be ok.
Yes, everything works fine now. I already have found rtmidi is better
suited for my (simple) midi needs than pygame.midi, and it works without
the sometimes strange error messages I have experienced with pygame.midi.

So thanks for pointing me to rtmidi!
--
MT
Martin Tarenskeen
2012-08-19 20:45:04 UTC
Permalink
Post by Christopher Arndt
I can't say why you got this without more detail, but if you follow the
installation instructions in the README and have all the dependencies
you should be ok.
Yes, everything works fine now. I already have found rtmidi is better suited
for my (simple) midi needs than pygame.midi, and it works without the
sometimes strange error messages I have experienced with pygame.midi.
So thanks for pointing me to rtmidi!
A little question about your python-rtmidi:

why didn't you stay closer to the function names from the original C++
code

for example:
why get_port_name() instead of getPortName(), get_port_count() instead of
getPortCount(), etcetera ?

something like this:

https://github.com/patrickkidd/pyrtmidi#readme


thanks,

MT
Christopher Arndt
2012-08-19 20:54:02 UTC
Permalink
why didn't you stay closer to the function names from the original C++ code
Because of PEP-8.

Chris
Martin Tarenskeen
2012-08-20 12:35:06 UTC
Permalink
Post by Christopher Arndt
I can't say why you got this without more detail, but if you follow the
installation instructions in the README and have all the dependencies
you should be ok.
Hi Christopher,

(I'm cross-posting also to the pygame-user list because mail to your
private mailaddress is bounced by my provider)

Is it possible to change the max queuesize for rtmidi.MidiIn() ?
I'm trying to fetch SysEx dumps from a synth. Itw orks on my Linux box.
But on a Windows machine it only succeeds with small size dumps.
--
MT
Christopher Arndt
2012-08-20 12:41:09 UTC
Permalink
Post by Martin Tarenskeen
Is it possible to change the max queuesize for rtmidi.MidiIn() ?
I'm trying to fetch SysEx dumps from a synth. Itw orks on my Linux box.
But on a Windows machine it only succeeds with small size dumps.
Yes, there is currently a max buffer size for receiving sysex messages
on Windows with the WinMM API, which is by default 1024 bytes. You can
set the RT_SYSEX_BUFFER_SIZE definition in src/RtMidi.cpp to a higher
value and recompile. Just remove the "build" directory and run "python
setup.py install" again.

See also http://www.music.mcgill.ca/~gary/rtmidi/index.html#apinotes
under Windows (Multimedia Library).


Chris
Christopher Arndt
2012-08-20 20:39:34 UTC
Permalink
Post by Christopher Arndt
Yes, there is currently a max buffer size for receiving sysex messages
on Windows with the WinMM API, which is by default 1024 bytes. You can
set the RT_SYSEX_BUFFER_SIZE definition in src/RtMidi.cpp to a higher
value and recompile. Just remove the "build" directory and run "python
setup.py install" again.
I have just uploaded a binary build for Windows 32-bit where I increased
the sysex input buffer size to 4096 bytes. This is a pre-release build
of version 0.3a of python-rtmidi but there are no significant other
changes in the moule code in this version so far.

http://chrisarndt.de/projects/python-rtmidi/download/python-rtmidi-0.3a.dev-r0-20120820.win32-py2.7.exe

HTH, Chris
Martin Tarenskeen
2012-08-21 06:40:13 UTC
Permalink
I have just uploaded a binary build for Windows 32-bit where I increased the
sysex input buffer size to 4096 bytes. This is a pre-release build of version
0.3a of python-rtmidi but there are no significant other changes in the moule
code in this version so far.
http://chrisarndt.de/projects/python-rtmidi/download/python-rtmidi-0.3a.dev-r0-20120820.win32-py2.7.exe
OK, thanks. I will try it.

BTW: On the website page I saw the following example:

note_on = [0x99, 60, 112] # channel 10, middle C, velocity 112
note_off = [0x89, 60, 0]

[0x89, 60, 0] means a note_off message with a note_off velocity value of
0. A (small) number of synths understands note_off velocity. You can
describe it in physical terms as a key that is released extremely slowly.
I have seen a synth (an old AKAI it was I think) that would react by a
very slow envelope release of the sound after the key is released.

As an example it would be better to give the velocity a more
sensible value:
note_off = [0x89, 60, 64]

Another method, used very often, is to use a note_on message with
a velocity value = 0:
note_off = [0x99, 60, 0]
--
MT

P.S: can I mail you via another private e-mail address? E-mail to
chris-***@public.gmane.org is bounced by my provider.
Christopher Arndt
2012-08-21 06:54:25 UTC
Permalink
Post by Martin Tarenskeen
[0x89, 60, 0] means a note_off message with a note_off velocity value of
0. A (small) number of synths understands note_off velocity. You can
describe it in physical terms as a key that is released extremely
slowly. I have seen a synth (an old AKAI it was I think) that would
react by a very slow envelope release of the sound after the key is
released.
So what? It's only an example. I expect people who are using this module
to know the MIDI spec.

Several of my synths can be programmed to react in totally different
ways to note-off velocity via the modulation matrix.

The example is a bit strange anyway, since channel 10 is reserved for
drums in the General MIDI spec.


Chris

Continue reading on narkive:
Loading...