-
Notifications
You must be signed in to change notification settings - Fork 69
Description
I think the documentation of the data parameter of the set_callback method should be improved. For me it wasn't clear what it does. I had to read the C++ documentation in order to know what this is about.
After reading the python documentation of set_callback:
https://spotlightkid.github.io/python-rtmidi/rtmidi.html#rtmidi.MidiIn.set_callback
which says:
and the second argument is value of the data argument passed to this function when the callback is registered.
It wasn't clear to me what this data argument was about. After reading the documentation of the C++ source code:
https://www.music.mcgill.ca/~gary/rtmidi
There it is written:
It is possible to provide a pointer to user data that can be accessed in the callback function
For me, that's much more clearer. So, I guess that data argument could be everything. Even an object instancing an own defined class, ie:
midiin.set_callback(MidiInputHandler(port_name), my_object)
Then I guess you can do things like:
class MidiInputHandler(object):
def __init__(self, port):
self.port = port
self._wallclock = time.time()
def __call__(self, event, data):
message, deltatime = event
self._wallclock += deltatime
print("[%s] @%0.6f %r" % (self.port, self._wallclock, message))
data.my_method(self.port, self._wallclock, message)
Is this the purpose of the data parameter? If so, you could even extend the midiin_callback.py example and instead of printing the message in the callback, you could define a class that does this or perhaps put some comments to that example telling that you could do that as well.
Thanks and a happy new year to you.
Best regards
Josef