changeset 197:ccd034857702 trunk

[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
author nenolod
date Tue, 15 Nov 2005 20:21:50 -0800
parents b3b2fc5c8fe9
children 5a338b31e393
files audacious/Makefile.am audacious/genevent.c audacious/genevent.h audacious/main.c audacious/mainwin.c audacious/mainwin.h
diffstat 6 files changed, 219 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/audacious/Makefile.am	Tue Nov 15 19:24:17 2005 -0800
+++ b/audacious/Makefile.am	Tue Nov 15 20:21:50 2005 -0800
@@ -22,6 +22,7 @@
 	-I$(top_srcdir)/intl
 
 audacious_SOURCES = \
+	genevent.c genevent.h \
 	skin.c skin.h \
 	util.c util.h \
 	output.c output.h \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/audacious/genevent.c	Tue Nov 15 20:21:50 2005 -0800
@@ -0,0 +1,151 @@
+/*  Audacious - Cross-platform multimedia platform.
+ *  Copyright (C) 2005  Audacious development team.
+ *
+ *  Based on BMP:
+ *  Copyright (C) 2003-2004  BMP development team.
+ *
+ *  Based on XMMS:
+ *  Copyright (C) 1998-2003  XMMS 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; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "main.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gprintf.h>
+#include <gdk/gdk.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <time.h>
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include "libaudacious/configdb.h"
+#include "libaudacious/beepctrl.h"
+#include "libaudacious/util.h"
+#include "libaudacious/vfs.h"
+
+#include "controlsocket.h"
+#include "dnd.h"
+#include "dock.h"
+#include "effect.h"
+#include "equalizer.h"
+#include "general.h"
+#include "hints.h"
+#include "input.h"
+#include "logger.h"
+#include "mainwin.h"
+#include "output.h"
+#include "playback.h"
+#include "playlist.h"
+#include "playlistwin.h"
+#include "pluginenum.h"
+#include "prefswin.h"
+#include "skin.h"
+#include "skinwin.h"
+#include "util.h"
+#include "visualization.h"
+
+gboolean ev_waiting = FALSE;
+
+static gboolean
+idle_func_change_song(gboolean waiting)
+{
+    static GTimer *pause_timer = NULL;
+
+    if (!pause_timer)
+        pause_timer = g_timer_new();
+
+    if (cfg.pause_between_songs) {
+        gint timeleft;
+
+        if (!waiting) {
+            g_timer_start(pause_timer);
+            waiting = TRUE;
+        }
+
+        timeleft = cfg.pause_between_songs_time -
+            (gint) g_timer_elapsed(pause_timer, NULL);
+
+        if (mainwin_10min_num != NULL) {
+            number_set_number(mainwin_10min_num, timeleft / 600);
+            number_set_number(mainwin_min_num, (timeleft / 60) % 10);
+            number_set_number(mainwin_10sec_num, (timeleft / 10) % 6);
+            number_set_number(mainwin_sec_num, timeleft % 10);
+        }
+
+        if (mainwin_sposition != NULL && !mainwin_sposition->hs_pressed) {
+            gchar time_str[5];
+
+            g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft / 60);
+            textbox_set_text(mainwin_stime_min, time_str);
+
+            g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft % 60);
+            textbox_set_text(mainwin_stime_sec, time_str);
+        }
+
+        playlistwin_set_time(timeleft * 1000, 0, TIMER_ELAPSED);
+    }
+
+    if (!cfg.pause_between_songs ||
+        g_timer_elapsed(pause_timer, NULL) >= cfg.pause_between_songs_time) {
+
+        GDK_THREADS_ENTER();
+        playlist_eof_reached();
+        GDK_THREADS_LEAVE();
+
+        waiting = FALSE;
+    }
+
+    return waiting;
+}
+
+gint
+audcore_generic_events(void)
+{
+    gint time = 0;
+
+    if (bmp_playback_get_playing()) {
+        time = bmp_playback_get_time();
+
+        switch (time) {
+        case -1:
+            /* no song playing */
+            ev_waiting = idle_func_change_song(ev_waiting);
+            break;
+
+        default:
+            ev_waiting = FALSE;
+        }
+    }
+
+    return time;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/audacious/genevent.h	Tue Nov 15 20:21:50 2005 -0800
@@ -0,0 +1,36 @@
+/*  Audacious -- Cross-platform multimedia platform
+ *  Copyright (C) 2005  Audacious development team.
+ *
+ *  Based on BMP:
+ *  Copyright (C) 2003-2004  BMP development team.
+ *
+ *  Based on XMMS:
+ *  Copyright (C) 1998-2003  XMMS 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; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GENEVENT_H
+#define GENEVENT_H
+
+#include "mainwin.h"
+#include "textbox.h"
+#include "vis.h"
+
+extern gboolean ev_waiting;
+
+gint audcore_generic_events(void);
+
+#endif
--- a/audacious/main.c	Tue Nov 15 19:24:17 2005 -0800
+++ b/audacious/main.c	Tue Nov 15 20:21:50 2005 -0800
@@ -1,4 +1,7 @@
-/*  BMP - Cross-platform multimedia player
+/*  Audacious - Cross-platform multimedia platform.
+ *  Copyright (C) 2005  Audacious development team.
+ *
+ *  Based on BMP:
  *  Copyright (C) 2003-2004  BMP development team.
  *
  *  Based on XMMS:
@@ -55,11 +58,13 @@
 #include "effect.h"
 #include "equalizer.h"
 #include "general.h"
+#include "genevent.h"
 #include "hints.h"
 #include "input.h"
 #include "logger.h"
 #include "mainwin.h"
 #include "output.h"
+#include "playback.h"
 #include "playlist.h"
 #include "playlistwin.h"
 #include "pluginenum.h"
@@ -1044,6 +1049,8 @@
 
         for (;;)
 	{
+	    /* headless eventloop */
+	    audcore_generic_events();
 	    ctrlsocket_check();
             xmms_usleep(10000);
         }
--- a/audacious/mainwin.c	Tue Nov 15 19:24:17 2005 -0800
+++ b/audacious/mainwin.c	Tue Nov 15 20:21:50 2005 -0800
@@ -55,7 +55,7 @@
 #include "playlistwin.h"
 #include "prefswin.h"
 #include "skinwin.h"
-
+#include "genevent.h"
 #include "hslider.h"
 #include "menurow.h"
 #include "monostereo.h"
@@ -180,14 +180,14 @@
 
 TButton *mainwin_shuffle, *mainwin_repeat, *mainwin_eq, *mainwin_pl;
 TextBox *mainwin_info;
+TextBox *mainwin_stime_min, *mainwin_stime_sec;
 
 static TextBox *mainwin_rate_text, *mainwin_freq_text;
-static TextBox *mainwin_stime_min, *mainwin_stime_sec;
 
 PlayStatus *mainwin_playstatus;
 
-static Number *mainwin_minus_num, *mainwin_10min_num, *mainwin_min_num;
-static Number *mainwin_10sec_num, *mainwin_sec_num;
+Number *mainwin_minus_num, *mainwin_10min_num, *mainwin_min_num;
+Number *mainwin_10sec_num, *mainwin_sec_num;
 
 static gboolean setting_volume = FALSE;
 
@@ -195,9 +195,10 @@
 Vis *mainwin_vis;
 SVis *mainwin_svis;
 
+HSlider *mainwin_sposition = NULL;
+
 static MenuRow *mainwin_menurow;
 static HSlider *mainwin_volume, *mainwin_balance, *mainwin_position;
-static HSlider *mainwin_sposition = NULL;
 static MonoStereo *mainwin_monostereo;
 static SButton *mainwin_srew, *mainwin_splay, *mainwin_spause;
 static SButton *mainwin_sstop, *mainwin_sfwd, *mainwin_seject, *mainwin_about;
@@ -3231,56 +3232,6 @@
                                        mainwin_idle_func, NULL);
 }
 
-static gboolean
-idle_func_change_song(gboolean waiting)
-{
-    static GTimer *pause_timer = NULL;
-
-    if (!pause_timer)
-        pause_timer = g_timer_new();
-
-    if (cfg.pause_between_songs) {
-        gint timeleft;
-
-        if (!waiting) {
-            g_timer_start(pause_timer);
-            waiting = TRUE;
-        }
-
-        timeleft = cfg.pause_between_songs_time -
-            (gint) g_timer_elapsed(pause_timer, NULL);
-
-        number_set_number(mainwin_10min_num, timeleft / 600);
-        number_set_number(mainwin_min_num, (timeleft / 60) % 10);
-        number_set_number(mainwin_10sec_num, (timeleft / 10) % 6);
-        number_set_number(mainwin_sec_num, timeleft % 10);
-
-        if (!mainwin_sposition->hs_pressed) {
-            gchar time_str[5];
-
-            g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft / 60);
-            textbox_set_text(mainwin_stime_min, time_str);
-
-            g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft % 60);
-            textbox_set_text(mainwin_stime_sec, time_str);
-        }
-
-        playlistwin_set_time(timeleft * 1000, 0, TIMER_ELAPSED);
-    }
-
-    if (!cfg.pause_between_songs ||
-        g_timer_elapsed(pause_timer, NULL) >= cfg.pause_between_songs_time) {
-
-        GDK_THREADS_ENTER();
-        playlist_eof_reached();
-        GDK_THREADS_LEAVE();
-
-        waiting = FALSE;
-    }
-
-    return waiting;
-}
-
 static void
 idle_func_update_song_info(gint time)
 {
@@ -3350,52 +3301,35 @@
     }
 }
 
-
 static gboolean
 mainwin_idle_func(gpointer data)
 {
-    static gboolean waiting = FALSE;
     static gint count = 0;
-
-    gint time;
-
-    if (bmp_playback_get_playing()) {
-        GDK_THREADS_ENTER();
-        vis_playback_start();
-        GDK_THREADS_LEAVE();
-
-        time = bmp_playback_get_time();
-
-        switch (time) {
-        case -1:
-            /* no song playing */
-            waiting = idle_func_change_song(waiting);
-            break;
-
+    gint time = 0;
+
+    /* run audcore events, then run our own. --nenolod */
+    switch((time = audcore_generic_events()))
+    {
         case -2:
             /* no usable output device */
             GDK_THREADS_ENTER();
             run_no_output_device_dialog();
             mainwin_stop_pushed();
             GDK_THREADS_LEAVE();
-            waiting = FALSE;
+            ev_waiting = FALSE;
             break;
 
         default:
-            /* song playing, all's well */
             idle_func_update_song_info(time);
-            waiting = FALSE;
-        }
-    }
-    else {
-        GDK_THREADS_ENTER();
-        vis_playback_stop();
-        GDK_THREADS_LEAVE();
+            /* nothing at this time */
     }
 
     GDK_THREADS_ENTER();
 
-    ctrlsocket_check();
+    if (bmp_playback_get_playing())
+        vis_playback_start();
+    else
+        vis_playback_stop();
 
     draw_main_window(mainwin_force_redraw);
 
--- a/audacious/mainwin.h	Tue Nov 15 19:24:17 2005 -0800
+++ b/audacious/mainwin.h	Tue Nov 15 20:21:50 2005 -0800
@@ -31,6 +31,7 @@
 #include "textbox.h"
 #include "svis.h"
 #include "vis.h"
+#include "hslider.h"
 
 /* yes, main window size is fixed */
 #define MAINWIN_WIDTH            (gint)275
@@ -106,6 +107,7 @@
 extern GtkItemFactory *mainwin_vis_menu;
 extern GtkItemFactory *mainwin_play_menu, *mainwin_view_menu;
 
+extern TextBox *mainwin_stime_min, *mainwin_stime_sec;
 extern TextBox *mainwin_info;
 extern TButton *mainwin_shuffle, *mainwin_repeat, *mainwin_eq, *mainwin_pl;
 
@@ -115,6 +117,10 @@
 
 extern PlayStatus *mainwin_playstatus;
 
+extern Number *mainwin_minus_num, *mainwin_10min_num, *mainwin_min_num;
+extern Number *mainwin_10sec_num, *mainwin_sec_num;
+
+extern HSlider *mainwin_sposition;
 
 void mainwin_create(void);
 void read_volume(gint when);