[LAD] alsa sequencer and sysex editing

Fons Adriaensen fons at kokkinizita.net
Mon Jun 2 19:55:30 UTC 2008


On Mon, Jun 02, 2008 at 07:32:16PM +0200, rdxesy at yahoo.de wrote:

> thank you for that info. The problem with that thread
> approach is that i cannot call gtk_* stuff from it (which
> is needed, as most answers are values that will be used to
> set sliders, comboboxes and spinbuttons).
> I could use g_idle_add or g_timeout_add for that thread but
> that adds another async layer, and questions like "what
> would be the timeout"?
> Is there a way to call a function in the main loop from a
> thread "now and once" (i mean, without using
> g_idle/timeout_add, something thats just like a call to a
> "normal" function but calls it in the main loop)?

"In the main loop" and "from a(nother) thread" are contradictory
- these *are* different threads and nothing can change that.

I don't know the details of GTK, but this is a classic problem
with high-level GUI toolsets: they don't allow you to wait
for X events (which trigger the loop, behind the scenes) and
anyhting else at the same time in the same thread. They don't
even separate _waiting_ for an X event, and _handling_ it into
two separate user calls (which would allow the user to add the
missing multiple wait functionality). This is one of the
reasons why I wrote my own GUI toolkit.

Now if the messages you receive are for display only, there
is no need to be faster than the display update rate, or a
human reader. If the GTK loop times out every say 50ms,
checks the midi input, and if there is any, displays it,
then things should just work. There's no problem if you
are too late as the midi data is buffered. There's no
problem if you're to early, you will get the message next
time. 

Other solutions are:

- Use a separate thread to read the midi data, then send
it as an X event (you can make 'user' event types) to your
main window. Doing this will trigger the GTK loop.

- Use a separate thread, and a mutex used by this thread
and the GTK loop to avoid concurrent access to data and
mixed-up X-calls.


Ciao,

-- 
FA

Laboratorio di Acustica ed Elettroacustica
Parma, Italia

Lascia la spina, cogli la rosa.




More information about the Linux-audio-dev mailing list