sound-juicer r1976 - in trunk: . src



Author: rburton
Date: Sun Jan 13 21:32:35 2008
New Revision: 1976
URL: http://svn.gnome.org/viewvc/sound-juicer?rev=1976&view=rev

Log:
2008-01-13  Ross Burton  <ross burtonini com>

	* src/sj-play.c:
	Code refactoring, thanks Bill O'Shea.


Modified:
   trunk/ChangeLog
   trunk/src/sj-play.c

Modified: trunk/src/sj-play.c
==============================================================================
--- trunk/src/sj-play.c	(original)
+++ trunk/src/sj-play.c	Sun Jan 13 21:32:35 2008
@@ -43,6 +43,7 @@
 static gboolean seeking = FALSE, internal_update = FALSE;
 static guint64 slen = GST_CLOCK_TIME_NONE;
 static gfloat vol = 1.0;
+static void set_gst_ui_and_play (void);
 
 static GtkTreeIter current_iter;
 
@@ -56,31 +57,6 @@
 {
   GstElement *cd;
 
-  if (seek_to_track == -1) {
-    gint tracks =
-        gtk_tree_model_iter_n_children (GTK_TREE_MODEL (track_store), NULL);
-
-    seek_to_track = 0;
-    while (seek_to_track < tracks) {
-      gboolean do_play;
-      GtkTreeIter next_iter;
-
-      if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (track_store),
-                                          &next_iter, NULL, seek_to_track)) {
-        g_warning (G_STRLOC ": cannot get nth child");
-        return FALSE;
-      }
-      gtk_tree_model_get (GTK_TREE_MODEL (track_store), &next_iter,
-          COLUMN_EXTRACT, &do_play, -1);
-      if (do_play)
-        break;
-      seek_to_track++;
-    }
-    if (seek_to_track == tracks) {
-      seek_to_track = -1;
-      return FALSE;
-    }
-  }
   if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (track_store),
                                      &current_iter, NULL, seek_to_track)) {
     g_warning (G_STRLOC ": cannot get nth child");
@@ -91,8 +67,6 @@
   gst_element_set_state (pipeline, GST_STATE_PAUSED);
   gst_element_seek (pipeline, 1.0, gst_format_get_by_nick ("track"), GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, seek_to_track, GST_SEEK_TYPE_NONE, -1);
   current_track = seek_to_track;
-  seek_to_track = -1;
-
   return TRUE;
 }
 
@@ -172,24 +146,8 @@
     stop ();
     seek_to_track = 0;
   } else {
-    char *title;
-    seek_to_track = next_track;
-    gtk_list_store_set (track_store, &current_iter,
-        COLUMN_STATE, STATE_IDLE, -1);
-    select_track ();
-    gtk_list_store_set (track_store, &current_iter,
-        COLUMN_STATE, STATE_PLAYING, -1);
-    gtk_tree_model_get (model,
-        &current_iter, COLUMN_TITLE, &title, -1);
-    sj_main_set_title (title);
-    g_free (title);
-
-    /* Set the Treelist focus to the item to be extracted */
-    GtkTreePath* path = gtk_tree_model_get_path(GTK_TREE_MODEL (track_store), &current_iter); 
-    gtk_tree_view_set_cursor (GTK_TREE_VIEW (track_listview), path, NULL, TRUE);
-    gtk_tree_path_free(path);
-
-    play ();
+	seek_to_track = next_track;
+    set_gst_ui_and_play ();
   }
 }
 
@@ -444,32 +402,18 @@
 
   if (is_playing ()) {
     pause ();
-  } else if (pipeline && GST_STATE (pipeline) == GST_STATE_PAUSED && 
-                (current_track == seek_to_track || seek_to_track == -1)) {
+ } else if (pipeline && GST_STATE (pipeline) == GST_STATE_PAUSED && 
+             current_track == seek_to_track) {
     play ();
-  } else if (setup (&err)) {
-    char *title;
-    if (current_track != -1) {
-      if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (track_store),
+  } else if (pipeline && GST_STATE (pipeline) == GST_STATE_PAUSED &&
+			 current_track != seek_to_track) {
+    if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (track_store),
                                           &current_iter, NULL, current_track))
         return;
-    }
-    gtk_list_store_set (track_store, &current_iter,
-                        COLUMN_STATE, STATE_IDLE, -1);
-    if (select_track ()) {
-      gtk_list_store_set (track_store, &current_iter,
-          COLUMN_STATE, STATE_PLAYING, -1);
-      gtk_tree_model_get (GTK_TREE_MODEL (track_store),
-          &current_iter, COLUMN_TITLE, &title, -1);
-      sj_main_set_title (title);
-      g_free (title);
-
-      play ();
-    } else {
-      g_warning (G_STRLOC ": failed to select track");
-      stop ();
-    }
-  } else {
+	set_gst_ui_and_play ();
+  } else if (setup (&err)) {
+	cb_hop_track (NULL,NULL,NULL);
+  }	else {
     GtkWidget *dialog;
 
     dialog = gtk_message_dialog_new (GTK_WINDOW (main_window), 0,
@@ -499,7 +443,6 @@
       gtk_list_store_set (track_store, &current_iter, COLUMN_STATE, STATE_IDLE, -1);
 
   if (setup (&err)) {
-    char *title;
     seek_to_track = track - 1;
 
     if (current_track != -1) {
@@ -507,18 +450,8 @@
                                           &current_iter, NULL, current_track))
         return;
     }
-
-    gtk_list_store_set (track_store, &current_iter,
-        COLUMN_STATE, STATE_IDLE, -1);
-    select_track ();
-    gtk_list_store_set (track_store, &current_iter,
-        COLUMN_STATE, STATE_PLAYING, -1);
-    gtk_tree_model_get (GTK_TREE_MODEL (track_store),
-        &current_iter, COLUMN_TITLE, &title, -1);
-    sj_main_set_title (title);
-    g_free (title);
+    set_gst_ui_and_play ();
     current_iter = iter;
-    play ();
   } else {
     GtkWidget *dialog;
 
@@ -564,18 +497,29 @@
     stop ();
     seek_to_track = 0;
   } else {
-    char *title;
     seek_to_track = prev_track;
-    gtk_list_store_set (track_store, &current_iter,
-        COLUMN_STATE, STATE_IDLE, -1);
-    select_track ();
+    set_gst_ui_and_play ();
+  }
+}
+
+static void
+set_gst_ui_and_play (void)
+{
+  char *title;
+
+  gtk_list_store_set (track_store, &current_iter,
+      COLUMN_STATE, STATE_IDLE, -1);
+  if (select_track ()) {
     gtk_list_store_set (track_store, &current_iter,
         COLUMN_STATE, STATE_PLAYING, -1);
-    gtk_tree_model_get (model,
+    gtk_tree_model_get (GTK_TREE_MODEL (track_store),
         &current_iter, COLUMN_TITLE, &title, -1);
     sj_main_set_title (title);
     g_free (title);
     play ();
+  } else {
+    g_warning (G_STRLOC ": failed to select track");
+    stop ();
   }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]