Peter
Brinkmann wrote:
Also, what sort of functionality would you like to implement by polling
Python Queues in the MIDI thread?
I planned to consume events from the GUI thread periodically - this
would allow the MIDI thread to operate unhindered by the GUI if there's
a lot of work to do.
The problem may be that I don't know the right
idioms for doing this in
Python yet, but I haven't found anything worthy of study yet.
Here's how I would solve this problem, using an ALSA idiom of sorts.
ALSA sequencer events are more general than MIDI events, and you can
use them to communicate with your MIDI thread. In particular, when
new data is available in your queue, you can alert the MIDI thread to
the new data by sending it an echo event. The file midiplayer.py in
the PySeq distribution uses echo events in this fashion, so that you
can glean the basic idea from it.
There are a few ways to extend this basic idea. For instance, if you
have several queues, then you can tag your echo events according to
which queue currently has data. You could also add an intermediate
thread that just waits for new data in a queue and fires off an echo
message to the MIDI thread when needed. Like this, your top-level
GUI code wouldn't have to be ALSA-aware.
Would this work for you?