On Saturday 04 February 2012, Harry van Haaren wrote:
Hi Alessandro!
You'll need to learn a bit about threading in C++, either Mutexs or Lock
Free Ringbuffers.
I'll advise Ringbuffers because it scales up, while mutexs is slightly
easier to learn, but you'll
want to learn ringbuffers soon thereafter anyway!
One option is to use the Gtk::timeout functions to update the values
regardless of if they've changed: bit of a hack but it works :)
http://developer.gnome.org/gtkmm-tutorial/3.0/sec-timeouts.html.en
Another option is to attach a "idle" function when a MIDI message is
recieved in the MIDI IN callback: which tells the UI to update.
Problem with both of these options: you need to tell the parameters what
value to update to: this involves either mutexs or a ringbuffer.
I've not looked at your code, this is all just C++ threading theory RE
RtMidi & Gtkmm. Same applies for JACK & Gtkmm, or any "callback" api,
and a
"blocking" api like Gtkmm.
Qt requires that all GUI updates be called from the main program's thread, the
one that runs the main event loop. Just don't update your GUI widgets from the
RtMIDI callback function, because this function is going to be called from
another thread or even a different process.
I don't care about Gtkmm, but in Qt the solution is very easy. You only need
to create custom events (QEvent subclass) in the RtMIDI callback function for
each received MIDI message, and invoke QCoreApplication::postEvent() to add
these custom events to the application's event queue. Your window (or other
QWidget subclass) should also override a handler, the customEvent() virtual
method, that shall receive your events in the right threading context, where
you can update the GUI safely. You can look to the VMPK implementation for
details:
http://vmpk.svn.sourceforge.net/viewvc/vmpk/trunk/desktop/src/vpiano.cpp?vi…
Regards,
Pedro
On Sat, Feb 4, 2012 at 5:57 PM, alessandro filippo
<
alessandro.filippo(a)infinito.it> wrote:
> Hi, I'm learning to write simple audio/midi applications in C++ with
> RtMidi and gtkmm libraries (version 2.4).
>
> This is the application I'm working on:
>
>
http://www.eclepticbox.altervista.org/index.php/download/finish/2-audio-
midi/8-sawlidsyngui
>
>
> I got some issues with RtMidi IN (Callback). I followed the RtMidi
> tutorial and the VMPK example (however this is written with Qt), but the
> problem is that the GUI freezes when I send some MIDI data and it
> doesn't refresh the widgets values.
>
> Midi Out works properly.
>
> I think the problem is in the Midi Callback and in the event/signal
> managing.
> I tried some function in order to refresh the gui but they didn't work.
>
> This is the smallest extract of code that has the issue (only a
> spinbutton sending / receiving MIDI Program Change):
>
>
>
http://www.eclepticbox.altervista.org/index.php/download/finish/2-audio-
midi/9-sawlidsyngui-test
>
> The sources are in the src folder, see:
>
> sawlidsyngui.cpp
> sawlidsyngui.h
>
> Any help is appreciated....
>
> Thanks ...
> Alessandro