Monday, November 22, 2010

Making Audio Meter pretty with Cairo

With GTK 3 coming out in a few months, one of the tasks for gnome-mplayer has been to replace the drawing code with cairo, rather than gdk drawing primitives. This gives us several cool features including better gradient support.

Here is a screen shot of the current code.


Side note.. one of these days gnome-screen shot should be fixed to grab compiz window decorations.

Friday, November 12, 2010

Getting the default volume from PulseAudio in C

I have been screwing around with trying to find out how to get the default volume from PulseAudio for the longest time. I finally got it working in a GTK application by reading the pavucontrol applications code. Since this was such a pain for me to find, I thought I would share it.

In your configure.in make sure you have these lines

PKG_CHECK_MODULES(PULSE, [libpulse libpulse-mainloop-glib])
AC_SUBST(PULSE_CFLAGS)
AC_SUBST(PULSE_LIBS)


Then make sure in your Makefile.am you have $(PULSE_CFLAGS) in the INCLUDES and $(PULSE_LIBS) in appname_LDADD. These may vary in your setup, but that should work for automake projects.

The code...

#include "gtk/gtk.h"
#include "pulse/pulseaudio.h"
#include "pulse/glib-mainloop.h"

void pa_sink_info_callback(pa_context *context, const pa_sink_info *i, int eol, gpointer data)
{
    if (i != NULL) {
        //printf("channels = %i\n", i->volume.channels);
        //printf("raw volume = %i\n", pa_cvolume_avg(&(i->volume)));
        //printf("linear volume = %f\n", pa_sw_volume_to_linear(pa_cvolume_avg(&(i->volume))));
        printf("percent volume = %f\n", (gdouble)pa_cvolume_avg(&(i->volume)) / (gdouble)PA_VOLUME_NORM);
    }
}
   

void pa_server_info_callback(pa_context *context, const pa_server_info *i, void *userdata)
{
    //printf("server info\n");
    printf("default sink name = %s\n",i->default_sink_name);
    pa_context_get_sink_info_by_name(context,i->default_sink_name, pa_sink_info_callback, NULL);
}

void context_state_callback(pa_context *context, void *userdata)
{
    //printf("context state callback\n");
   
    switch (pa_context_get_state(context)) {
        case PA_CONTEXT_READY: {
            pa_context_get_server_info(context,pa_server_info_callback,NULL);
        }

        default:
            return;
    }

}

int main(int argc, char *argv[]) {
   
    gtk_init(&argc,&argv);
    pa_glib_mainloop *loop = pa_glib_mainloop_new(g_main_context_default());
    pa_context *context = pa_context_new(pa_glib_mainloop_get_api(loop),"test");                             
    pa_context_connect(context, NULL, 0 , NULL);
    pa_context_set_state_callback(context, context_state_callback, NULL);
   
    gtk_main();
    return 1;
}

Thursday, November 11, 2010

Gnome Mplayer 1.0 is out and whats next

Well now that gnome-mplayer 1.0 is out.. where to from here. I have a couple of ideas that I am working on and basically just lack for time to get them all done.

1. Conversion of gnome-mplayer to gtk3
2. Which means redoing the audio meter widget in Cairo
3. I also am converting the main mplayer control to a GTK Widget in libgmtk
4. Probably spawning libgmlib and libgmtk into their own SVN projects

Why do all this, I'm hoping that by making it a widget it will solve some of the weird GTK positioning side effects that I have to work around. So far I have a basic version of the widget working and it seems decent. I have a test harness working where I can use the media player widget and the tracker widget and have them working with each other.






So that is what I am working on...