changeset 3092:1ddeb9f068ab

Backed out changeset b87335249c69d45d253b1b960a9ec7f60b68e5a5
author William Pitcock <nenolod@atheme-project.org>
date Mon, 16 Jul 2007 16:16:17 -0500
parents f40b8491a812
children a7e596cf1c3a
files src/audacious/Makefile src/audacious/genevent.c src/audacious/genevent.h src/audacious/main.c src/audacious/playback.c src/audacious/plugin.h src/audacious/ui_jumptotrack.c src/audacious/ui_main.c
diffstat 8 files changed, 203 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/Makefile	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/Makefile	Mon Jul 16 16:16:17 2007 -0500
@@ -70,6 +70,7 @@
 	fft.c \
 	formatter.c \
 	general.c \
+	genevent.c \
 	glade.c \
 	hints.c \
 	hook.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/genevent.c	Mon Jul 16 16:16:17 2007 -0500
@@ -0,0 +1,144 @@
+/*  Audacious - Cross-platform multimedia platform.
+ *  Copyright (C) 2005-2007  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; under version 2 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "dnd.h"
+#include "effect.h"
+#include "general.h"
+#include "hints.h"
+#include "input.h"
+#include "logger.h"
+#include "output.h"
+#include "playback.h"
+#include "playlist.h"
+#include "pluginenum.h"
+#include "ui_main.h"
+#include "ui_playlist.h"
+#include "ui_skinned_textbox.h"
+#include "ui_skinned_number.h"
+#include "ui_skinned_horizontal_slider.h"
+#include "util.h"
+#include "visualization.h"
+#include "vfs.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) {
+            ui_skinned_number_set_number(mainwin_10min_num, timeleft / 600);
+            ui_skinned_number_set_number(mainwin_min_num, (timeleft / 60) % 10);
+            ui_skinned_number_set_number(mainwin_10sec_num, (timeleft / 10) % 6);
+            ui_skinned_number_set_number(mainwin_sec_num, timeleft % 10);
+        }
+
+        if (mainwin_sposition != NULL && !UI_SKINNED_HORIZONTAL_SLIDER(mainwin_sposition)->pressed) {
+            gchar *time_str;
+
+            time_str = g_strdup_printf("%2.2d", timeleft / 60);
+            ui_skinned_textbox_set_text(mainwin_stime_min, time_str);
+            g_free(time_str);
+
+            time_str = g_strdup_printf("%2.2d", timeleft % 60);
+            ui_skinned_textbox_set_text(mainwin_stime_sec, time_str);
+            g_free(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)
+    {
+	Playlist *playlist = playlist_get_active();
+
+        GDK_THREADS_ENTER();
+        playlist_eof_reached(playlist);
+        GDK_THREADS_LEAVE();
+
+        waiting = FALSE;
+    }
+
+    return waiting;
+}
+
+gint
+audcore_generic_events(void)
+{
+    gint time = 0;
+
+    if (playback_get_playing()) {
+        time = 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/src/audacious/genevent.h	Mon Jul 16 16:16:17 2007 -0500
@@ -0,0 +1,33 @@
+/*  Audacious -- Cross-platform multimedia platform
+ *  Copyright (C) 2005-2007  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; under version 2 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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GENEVENT_H
+#define GENEVENT_H
+
+#include "ui_main.h"
+
+extern gboolean ev_waiting;
+
+gint audcore_generic_events(void);
+
+#endif
--- a/src/audacious/main.c	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/main.c	Mon Jul 16 16:16:17 2007 -0500
@@ -58,6 +58,7 @@
 #include "effect.h"
 #include "ui_equalizer.h"
 #include "general.h"
+#include "genevent.h"
 #include "hints.h"
 #include "input.h"
 #include "logger.h"
@@ -1095,6 +1096,7 @@
 static gboolean
 aud_headless_iteration(gpointer unused)
 {
+    audcore_generic_events();
     free_vis_data();
     return TRUE;
 }
--- a/src/audacious/playback.c	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/playback.c	Mon Jul 16 16:16:17 2007 -0500
@@ -123,6 +123,8 @@
     }
 
     vis_playback_start();
+
+    hook_call("playback begin", entry);
 }
 
 void
@@ -156,38 +158,29 @@
 void
 playback_stop(void)
 {
-    InputPlayback *playback = get_current_input_playback();
+    if (ip_data.playing && get_current_input_playback()) {
 
-    if (ip_data.playing && playback != NULL)
-    {
-        if (playback_get_paused())
-        {
+        if (playback_get_paused()) {
             output_flush(get_written_time()); /* to avoid noise */
             playback_pause();
         }
 
         ip_data.playing = FALSE; 
 
-        if (playback->plugin->stop)
-            playback->plugin->stop(playback);
+        if (get_current_input_playback()->plugin->stop)
+            get_current_input_playback()->plugin->stop(get_current_input_playback());
 
         free_vis_data();
         ip_data.paused = FALSE;
 
-        if (input_info_text != NULL)
-        {
+        if (input_info_text) {
             g_free(input_info_text);
             input_info_text = NULL;
             mainwin_set_info_text();
         }
 
-        g_cond_signal(playback->playback_cond);
-        g_thread_join(playback->playback_control);
-        g_cond_free(playback->playback_cond);
-        g_mutex_free(playback->playback_mutex);
-
-	g_free(playback->filename);
-	g_free(playback);
+	g_free(get_current_input_playback()->filename);
+	g_free(get_current_input_playback());
 	set_current_input_playback(NULL);
     }
 
@@ -220,37 +213,10 @@
     gtk_widget_destroy(dialog);
 }
 
-static gpointer
-playback_control_thread(gpointer data)
-{
-    InputPlayback *playback = (InputPlayback *) data;
-    g_return_val_if_fail(playback != NULL, NULL);
-
-    ip_data.playing = TRUE;
-
-    playback->plugin->play_file(playback);
-
-    hook_call("playback begin", playback->entry);
-
-    while (ip_data.playing == TRUE && playback->eof == FALSE && playback->playing == TRUE)
-    {
-        GTimeVal tmwait;
-        g_get_current_time(&tmwait);
-        g_time_val_add(&tmwait, 1000000);
-        g_cond_timed_wait(playback->playback_cond, playback->playback_mutex, &tmwait);
-    }
-
-    ip_data.playing = FALSE;
-
-    hook_call("playback end", playback->entry);
-
-    return NULL;
-}
-
 gboolean
 playback_play_file(PlaylistEntry *entry)
 {
-    InputPlayback *playback;
+    InputPlayback * playback;
     g_return_val_if_fail(entry != NULL, FALSE);
 
     if (!get_current_output_plugin()) {
@@ -278,17 +244,18 @@
     }
 
     playback = g_new0(InputPlayback, 1);
+    
+    entry->decoder->output = &psuedo_output_plugin;
 
-    set_current_input_playback(playback);
-    
     playback->plugin = entry->decoder;
     playback->output = &psuedo_output_plugin;
-    playback->plugin->output = playback->output;
     playback->filename = g_strdup(entry->filename);
-    playback->playback_mutex = g_mutex_new();
-    playback->playback_cond = g_cond_new();
-    playback->playback_control = g_thread_create(playback_control_thread, playback, TRUE, NULL);
-    playback->entry = entry;
+    
+    set_current_input_playback(playback);
+
+    entry->decoder->play_file(playback);
+
+    ip_data.playing = TRUE;
 
     return TRUE;
 }
--- a/src/audacious/plugin.h	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/plugin.h	Mon Jul 16 16:16:17 2007 -0500
@@ -190,12 +190,6 @@
     int playing;
     gboolean error;
     gboolean eof;
-
-    GThread *playback_control;
-    GMutex *playback_mutex;
-    GCond *playback_cond;
-
-    gpointer entry;
 };
 
 struct _InputPlugin {
--- a/src/audacious/ui_jumptotrack.c	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/ui_jumptotrack.c	Mon Jul 16 16:16:17 2007 -0500
@@ -61,6 +61,7 @@
 
 #include "dnd.h"
 #include "dock.h"
+#include "genevent.h"
 #include "hints.h"
 #include "input.h"
 #include "playback.h"
--- a/src/audacious/ui_main.c	Mon Jul 16 15:50:32 2007 -0500
+++ b/src/audacious/ui_main.c	Mon Jul 16 16:16:17 2007 -0500
@@ -61,6 +61,7 @@
 #include "configdb.h"
 #include "dnd.h"
 #include "dock.h"
+#include "genevent.h"
 #include "hints.h"
 #include "input.h"
 #include "playback.h"
@@ -2982,7 +2983,8 @@
     static gint count = 0;
     gint time = 0;
 
-    switch((time = playback_get_time()))
+    /* run audcore events, then run our own. --nenolod */
+    switch((time = audcore_generic_events()))
     {
         case -2:
             /* no usable output device */
@@ -2990,6 +2992,7 @@
             run_no_output_device_dialog();
             mainwin_stop_pushed();
             GDK_THREADS_LEAVE();
+            ev_waiting = FALSE;
             break;
 
         default: