Where to call g_idle_add() in my Gtk4 codebase (ANSI C)?

Hello GTK users and devs.

In gtkstft.c: Embryo of a simple GtkGL audio STFT analyzer · GitHub you’ll find the embryo of Gtk4 GL audio real-time STFT (FFT) analyzer.

The end goal is to get data from the soundcard using Jack audio, do a FFT of each frame, and display the result in a GLArea.

For now the Jack part if commented out, and in my refresh callback I do a simple call to rand() for debugging purpose.

I don’t get about where to put g_idle_add() so that my GLArea is updated when the rest of the GUI is idle.

Its like some async event happening every 10 to 50ms needing to refresh the GL view, the computation happend in another thread, I’ve tried g_idle_add() but it
does not improve the refresh rate, the GLArea stand still.

Any help is warmly appreciated.

TIA, Philippe.

I was returning not the right value from my idle callback, but solving it went me into a busy loop problem, solved now using gtk_widget_add_tick_callback(). Thanks for your help!

1 Like