Gtk-fortran 4.6 released, it plays a little melody

\sqrt[gtk]{fortran} = 4.6 provides Fortran interfaces to the latests GTK 4.14 and GLib 2.80 libraries on Linux, MSYS2/Windows 10, macOS, FreeBSD, Raspberry Pi OS (the macOS and Linux versions are also on conda-forge). It was tested with GFortran and ifx.

A problem was fixed concerning the macOS linker (which is not GNU ld and does not accept the -R option).

Recently, a reaction-diffusion example was added in the gtk-fortran-extra repository to demonstrate the use of ForColormap as a fpm dependency of a gtk-fortran program.

“By pressing down a special key, it plays a little melody” :loud_sound:

sang the German band Kraftwerk in Pocket Calculator (Computer World album, 1981). In the examples/bazaar.f90 program, click on Button1. It is the first time since 2011 that a gtk-fortran example demonstrates audio functionalities, by using a GtkMediaStream, introduced a few years ago in GTK 4. The GTK 4 GStreamer backend must be installed in your OS (libgtk-4-media-gstreamer package in Ubuntu). It was tested with .ogg, .wav and .mid files, but should work with every format handled by GStreamer.

The core code is:

	type(c_ptr) :: media
...
	media = gtk_media_file_new_for_filename("demo_sound.ogg"//c_null_char)
	call gtk_media_stream_set_volume(media, 1.0_c_double)
	call gtk_media_stream_play(media)
	call g_signal_connect(media, "notify::ended"//c_null_char, c_funloc(sound_ended), c_null_ptr)

This is a typical gtk-fortran code. You create an instance of an object and get back a C pointer that you then pass to its methods or to other objects. sound_ended is a Fortran subroutine that will be called by the C library when the object will emit the notify::ended signal. That is why we use c_funloc() to pass its address to the C side.

One of these days, when I am bored, I could write an example using ForSynth or ForMIDI as a fpm dependency…


P.s. In MSYS2/Windows, if ever you have GL rendering problems with the new ngl renderer, you can switch back to the old one by setting this environment variable:

$ GSK_RENDERER=gl ./my_gtk_program
9 Likes