[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Midi Crashes on Error



On 13-11-03 09:57 AM, Christopher Arndt wrote:
Hi Lenard,

On 02.11.2013 02:25, Lenard Lindstrom wrote:
Just wondering, if the Python level callback is found to be too slow, could a
C level callback mechanism be provided?
how would you suggest this should be used? From Python or C?

In python-rtmidi this is currently not possible from Python, because
'MidiIn.set_callback' wraps a Python callback function with a C function
implemented in Cython (and you can't access the C++ object directly in
Python, only in the Cython code).

I guess it would be easy to make the C++ method 'RtMidiIn.setCallback'
available directly in Python, but I'm not sure how a pointer to a C
function could be passed by Python then or how such a pointer could be
obtained by Python.

So any ideas about a suitable API for this? And how it would tie into
PyGame's C code?


Chris
Cython has a C level sharing mechanism with cimport:

http://docs.cython.org/src/userguide/sharing_declarations.html#sharing-declarations-between-cython-modules

This should be usable from a standard C extension module. So something like:

int RtMidi_SetCallback(PyObject *midi_in, RtMidiCallback callback, void *data);

Anyway, I don't see any rush in implementing this. It may be that using a Python callback will be fast enough.

Lenard