changeset 3159:a2d552ea48f0 trunk

Use message passing to make sure the UI is updated in the main thread.
author William Pitcock <nenolod@atheme-project.org>
date Tue, 24 Jul 2007 01:05:57 -0500
parents 92717dcb09f6
children 03ff51c6412f
files src/audacious/Makefile src/audacious/playlist.c src/audacious/playlist_evlisteners.c src/audacious/playlist_evlisteners.h src/audacious/playlist_evmessages.h
diffstat 5 files changed, 116 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/Makefile	Mon Jul 23 19:35:59 2007 -0500
+++ b/src/audacious/Makefile	Tue Jul 24 01:05:57 2007 -0500
@@ -90,6 +90,7 @@
 	playback_evlisteners.c \
 	playlist.c \
 	playlist_container.c \
+	playlist_evlisteners.c \
 	pluginenum.c \
 	rcfile.c \
 	signals.c \
--- a/src/audacious/playlist.c	Mon Jul 23 19:35:59 2007 -0500
+++ b/src/audacious/playlist.c	Tue Jul 24 01:05:57 2007 -0500
@@ -71,6 +71,9 @@
 
 #include "hook.h"
 
+#include "playlist_evmessages.h"
+#include "playlist_evlisteners.h"
+
 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
 typedef void (*PlaylistSaveFunc) (FILE * file);
 
@@ -260,6 +263,8 @@
     initial_pl = playlist_new();
 
     playlist_add_playlist(initial_pl);
+
+    playlist_evlistener_init();
 }
 
 void
@@ -1039,6 +1044,7 @@
                           gint freq, gint nch)
 {
     Playlist *playlist = playlist_get_active();
+    PlaylistEventInfoChange *msg;
 
     g_return_if_fail(playlist != NULL);
 
@@ -1058,7 +1064,13 @@
 
     playlist_recalc_total_time(playlist);
 
-    mainwin_set_song_info(rate, freq, nch);
+    /* broadcast a PlaylistEventInfoChange message. */
+    msg = g_new0(PlaylistEventInfoChange, 1);
+    msg->bitrate = rate;
+    msg->samplerate = freq;
+    msg->channels = nch;
+
+    event_queue("playlist info change", msg);
 
     if ( playlist->position )
         hook_call( "playlist set info" , playlist->position );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/playlist_evlisteners.c	Tue Jul 24 01:05:57 2007 -0500
@@ -0,0 +1,44 @@
+/*
+ * Audacious
+ * Copyright (c) 2006-2007 Audacious development team.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ *
+ * The Audacious team does not consider modular code linking to
+ * Audacious or using our public API to be a derived work.
+ */
+
+#include <glib.h>
+#include "hook.h"
+#include "playback.h"
+#include "playlist.h"
+#include "playlist_evmessages.h"
+#include "playlist_evlisteners.h"
+
+#include "ui_main.h"
+
+static void
+playlist_evlistener_playlist_info_change(gpointer hook_data, gpointer user_data)
+{
+     PlaylistEventInfoChange *msg = (PlaylistEventInfoChange *) hook_data;
+
+     mainwin_set_song_info(msg->bitrate, msg->samplerate, msg->channels);
+
+     g_free(msg);
+}
+
+void playlist_evlistener_init(void)
+{
+     hook_associate("playlist info change", playlist_evlistener_playlist_info_change, NULL);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/playlist_evlisteners.h	Tue Jul 24 01:05:57 2007 -0500
@@ -0,0 +1,26 @@
+/*
+ * Audacious
+ * Copyright (c) 2006-2007 Audacious development team.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ *
+ * The Audacious team does not consider modular code linking to
+ * Audacious or using our public API to be a derived work.
+ */
+
+#ifndef __AUDACIOUS_PLAYLIST_EVLISTENERS_H__
+#define __AUDACIOUS_PLAYLIST_EVLISTENERS_H__
+
+void playlist_evlistener_init(void);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/playlist_evmessages.h	Tue Jul 24 01:05:57 2007 -0500
@@ -0,0 +1,32 @@
+/*
+ * Audacious
+ * Copyright (c) 2006-2007 Audacious development team.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ *
+ * The Audacious team does not consider modular code linking to
+ * Audacious or using our public API to be a derived work.
+ */
+
+#include <glib.h>
+
+#ifndef __AUDACIOUS_PLAYLIST_EVMESSAGES_H__
+#define __AUDACIOUS_PLAYLIST_EVMESSAGES_H__
+
+typedef struct {
+    gint bitrate;
+    gint samplerate;
+    gint channels;
+} PlaylistEventInfoChange;
+
+#endif