playlist item status display
[melted_gui] / src / omnplay.cpp
index 9604791..1a1889b 100644 (file)
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -64,8 +68,25 @@ void omnplay_destroy(omnplay_instance_t* app)
     free(app);
 };
 
+static int find_index_of_playlist_item(omnplay_instance_t* app, int start, int idx)
+{
+    while(1)
+    {
+        if(app->playlist.item[start].omn_idx == idx)
+            return start;
+
+        if(app->playlist.item[start].type & OMNPLAY_PLAYLIST_BLOCK_END)
+            break;
+
+        start++;
+    };
+
+    return -1;
+};
+
 static void omnplay_update_status(omnplay_player_t* player, OmPlrStatus *prev , OmPlrStatus *curr)
 {
+    int idx;
     char tc_cur[32], tc_rem[32], state[32], status[32];
     const char *clip;
 
@@ -94,6 +115,7 @@ static void omnplay_update_status(omnplay_player_t* player, OmPlrStatus *prev ,
         strcpy(status, "OFFLINE");
     };
 
+    /* update status in status page */
     gdk_threads_enter();
     gtk_label_set_text(GTK_LABEL (player->label_tc_cur), tc_cur);
     gtk_label_set_text(GTK_LABEL (player->label_tc_rem), tc_rem);
@@ -103,6 +125,42 @@ static void omnplay_update_status(omnplay_player_t* player, OmPlrStatus *prev ,
     gdk_flush();
     gdk_threads_leave();
 
+    /* update remaining time */
+    gdk_threads_enter();
+    pthread_mutex_lock(&player->app->playlist.lock);
+    pthread_mutex_lock(&player->app->players.lock);
+    if(curr->state == omPlrStatePlay || curr->state == omPlrStateCuePlay)
+    {
+        idx = find_index_of_playlist_item(player->app, player->playlist_start, curr->currClipNum);
+        if(idx >= 0)
+        {
+            strcpy(tc_rem, "PLAYING->");
+            omnplay_playlist_draw_item_rem(player->app, idx, tc_rem);
+        }
+        if(curr->currClipNum != prev->currClipNum && 1 != prev->numClips)
+        {
+            tc_rem[0] = 0;
+            idx = find_index_of_playlist_item(player->app, player->playlist_start, prev->currClipNum);
+            if(idx >= 0)
+                omnplay_playlist_draw_item_rem(player->app, idx, tc_rem);
+        };
+    }
+    else
+    {
+        tc_rem[0] = 0;
+        idx = find_index_of_playlist_item(player->app, player->playlist_start, curr->currClipNum);
+        if(idx >= 0)
+            omnplay_playlist_draw_item_rem(player->app, idx, tc_rem);
+        idx = find_index_of_playlist_item(player->app, player->playlist_start, prev->currClipNum);
+        if(idx >= 0)
+            omnplay_playlist_draw_item_rem(player->app, idx, tc_rem);
+    };
+    pthread_mutex_unlock(&player->app->players.lock);
+    pthread_mutex_unlock(&player->app->playlist.lock);
+    gdk_flush();
+    gdk_threads_leave();
+
+
     memcpy(prev, curr, sizeof(OmPlrStatus));
 };
 
@@ -267,8 +325,8 @@ static void omnplay_ctl(omnplay_instance_t* app, control_buttons_t button)
         OmPlrStop((OmPlrHandle)player->handle);
 
         /* detach previous clips */
-        player->playlist_start = -1;
-        player->playlist_count = -1;
+//        player->playlist_start = -1;
+//        player->playlist_count = -1;
         OmPlrDetachAllClips((OmPlrHandle)player->handle);
     };
 
@@ -294,10 +352,16 @@ static void omnplay_ctl(omnplay_instance_t* app, control_buttons_t button)
                     app->playlist.item[i].id, clip.firstFrame, clip.lastFrame);
 
                 /* should we fix playlist clip timings */
-                if((!
+                if(!(
                     app->playlist.item[i].in >= clip.firstFrame &&
-                    app->playlist.item[i].in + app->playlist.item[i].dur <= clip.lastFrame))
+                    app->playlist.item[i].in + app->playlist.item[i].dur <= clip.lastFrame) ||
+                    !app->playlist.item[i].dur)
                 {
+                    fprintf(stderr, "cue: item [%s] will be updated [%d;%d]->[%d;%d]\n",
+                        app->playlist.item[i].id,
+                        app->playlist.item[i].in, app->playlist.item[i].dur,
+                        clip.firstFrame, clip.lastFrame - clip.firstFrame);
+
                     app->playlist.item[i].in = clip.firstFrame;
                     app->playlist.item[i].dur = clip.lastFrame - clip.firstFrame;
                     omnplay_playlist_draw_item(app, i);
@@ -343,12 +407,15 @@ static void omnplay_ctl(omnplay_instance_t* app, control_buttons_t button)
             OmPlrGetPlayerStatus((OmPlrHandle)player->handle, &hs);
             OmPlrSetPos((OmPlrHandle)player->handle, hs.minPos + p);
 
+            /* setup loop */
+            if(app->playlist.item[start].type & OMNPLAY_PLAYLIST_BLOCK_LOOP)
+                OmPlrLoop((OmPlrHandle)player->handle, hs.minPos, hs.maxPos);
+
+            player->playlist_start = start;
+
             /* Cue */
             OmPlrCuePlay((OmPlrHandle)player->handle, 0.0);
             OmPlrPlay((OmPlrHandle)player->handle, 0.0);
-
-            player->playlist_start = start;
-            player->playlist_count = stop - start + 1;
         };
     };
 
@@ -416,12 +483,15 @@ static gboolean on_button_click(GtkWidget *button, gpointer user_data)
 void omnplay_init(omnplay_instance_t* app)
 {
     int i;
+    pthread_mutexattr_t attr;
+
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 
     gtk_signal_connect( GTK_OBJECT( app->window ), "destroy",
         GTK_SIGNAL_FUNC(on_main_window_delete_event), app);
 
     /* create lock */
-    pthread_mutex_init(&app->players.lock, NULL);
+    pthread_mutex_init(&app->players.lock, &attr);
 
     /* create a omneon status thread */
     for(i = 0; i < app->players.count; i++)
@@ -429,7 +499,7 @@ void omnplay_init(omnplay_instance_t* app)
             omnplay_thread_proc, &app->players.item[i]);
 
     /* create lock */
-    pthread_mutex_init(&app->playlist.lock, NULL);
+    pthread_mutex_init(&app->playlist.lock, &attr);
 
     /* attach buttons click */
     for(i = 1; i < BUTTON_LAST; i++)