chiark / gitweb /
spot changes to playing track via monitor list
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 1 Oct 2007 13:00:48 +0000 (14:00 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 1 Oct 2007 13:00:48 +0000 (14:00 +0100)
disobedience/disobedience.h
disobedience/log.c
disobedience/queue.c

index 53b4deb57f68b6e600952244edfb618e0746cf33..9443864d56caf14bd7ebe20597aa575262086431 100644 (file)
@@ -157,9 +157,6 @@ void queue_select_all(struct queuelike *ql);
 void queue_properties(struct queuelike *ql);
 /* Pop up properties of selected items in some queue */
 
-void playing_update(void);
-/* Called whenever we think the currently playing track might have changed */
-
 int queued(const char *track);
 /* Return nonzero iff TRACK is queued or playing */
 
index d8dbe35c8553d88136097409f9d70173ef89b175..11bad246f396051dd8a5891d9ecaae70ed6cb123 100644 (file)
@@ -81,7 +81,6 @@ static struct monitor *monitors;
 
 /** @brief Update everything */
 void all_update(void) {
-  playing_update();
   queue_update();
   recent_update();
   volume_update();
@@ -105,16 +104,12 @@ static void log_connected(void attribute((unused)) *v) {
 /** @brief Called when the current track finishes playing */
 static void log_completed(void attribute((unused)) *v,
                           const char attribute((unused)) *track) {
-  playing = 0;
-  playing_update();
 }
 
 /** @brief Called when the current track fails */
 static void log_failed(void attribute((unused)) *v,
                        const char attribute((unused)) *track,
                        const char attribute((unused)) *status) {
-  playing = 0;
-  playing_update();
 }
 
 /** @brief Called when some track is moved within the queue */
@@ -126,10 +121,6 @@ static void log_moved(void attribute((unused)) *v,
 static void log_playing(void attribute((unused)) *v,
                         const char attribute((unused)) *track,
                         const char attribute((unused)) *user) {
-  playing = 1;
-  playing_update();
-  /* we get a log_removed() anyway so we don't need to update_queue() from
-   * here */
 }
 
 /** @brief Called when a track is added to the queue */
@@ -164,8 +155,6 @@ static void log_removed(void attribute((unused)) *v,
 static void log_scratched(void attribute((unused)) *v,
                           const char attribute((unused)) *track,
                           const char attribute((unused)) *user) {
-  playing = 0;
-  playing_update();
 }
 
 /** @brief Called when a state change occurs */
@@ -189,10 +178,6 @@ static void log_state(void attribute((unused)) *v,
     if(changes & m->mask)
       m->callback(m->u);
   }
-  /* If the track is paused or resume then the currently playing track is
-   * refetched so that we can continue to correctly calculate the played so-far
-   * field */
-  playing_update();
 }
 
 /** @brief Called when volume changes */
@@ -205,7 +190,13 @@ static void log_volume(void attribute((unused)) *v,
   }
 }
 
-/** @brief Add a monitor to the list */
+/** @brief Add a monitor to the list
+ * @param callback Function to call
+ * @param u User data to pass to @p callback
+ * @param mask Mask of flags that @p callback cares about
+ *
+ * Pass @p mask as -1UL to match all flags.
+ */
 void register_monitor(monitor_callback *callback,
                       void *u,
                       unsigned long mask) {
index 6ef558db87f8212e96411def14d1a279b6905b12..65c09d30a0d37f178d3e24469418035a1efedc30 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  * USA
  */
+/** @file disobedience/queue.c
+ * @brief Queue widgets
+ *
+ * This file provides both the queue widget and the recently-played widget.
+ */
 
 #include "disobedience.h"
 
@@ -1197,10 +1202,24 @@ static struct menuitem queue_menu[] = {
   { 0, 0, 0, 0, 0 }
 };
 
+/** @brief Called whenever @ref DISORDER_PLAYING or @ref DISORDER_TRACK_PAUSED changes
+ *
+ * We monitor pause/resume as well as whether the track is playing in order to
+ * keep the time played so far up to date correctly.  See playing_completed().
+ */
+static void playing_update(void attribute((unused)) *v) {
+  D(("playing_update"));
+  gtk_label_set_text(GTK_LABEL(report_label), "updating playing track");
+  disorder_eclient_playing(client, playing_completed, 0);
+}
+
+/** @brief Create the queue widget */
 GtkWidget *queue_widget(void) {
   D(("queue_widget"));
   /* Arrange periodic update of the so-far played field */
   g_timeout_add(1000/*ms*/, adjust_sofar, 0);
+  /* Arrange a callback whenever the playing state changes */ 
+  register_monitor(playing_update, 0,  DISORDER_PLAYING|DISORDER_TRACK_PAUSED);
   /* We pass choose_update() as our notify function since the choose screen
    * marks tracks that are playing/in the queue. */
   return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu,
@@ -1218,12 +1237,6 @@ void queue_update(void) {
   disorder_eclient_queue(client, queuelike_completed, cbd);
 }
 
-void playing_update(void) {
-  D(("playing_update"));
-  gtk_label_set_text(GTK_LABEL(report_label), "updating playing track");
-  disorder_eclient_playing(client, playing_completed, 0);
-}
-
 /* Recently played tracks -------------------------------------------------- */
 
 static struct queue_entry *fixup_recent(struct queue_entry *q) {