static gboolean on_main_window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer user_data )
{
- gtk_exit(0);
- return TRUE;
+ g_print ("delete event occurred [start]\n");
+ gdk_threads_leave();
+ omnplay_release((omnplay_instance_t*)user_data);
+ gdk_threads_enter();
+ g_print ("delete event occurred [finish]\n");
+
+ return FALSE;
+}
+
+static void on_main_window_destroy( GtkWidget *widget, gpointer user_data )
+{
+ g_print ("destroy occurred\n");
+ gtk_main_quit();
}
omnplay_instance_t* omnplay_create(int argc, char** argv)
OmPlrStatus st_curr, st_prev;
omnplay_player_t* player = (omnplay_player_t*)data;
+ g_warning("omnplay_thread_proc\n");
+
/* connect */
pthread_mutex_lock(&player->app->players.lock);
r = OmPlrOpen(player->host, player->name, (OmPlrHandle*)&player->handle);
pthread_mutex_unlock(&player->app->players.lock);
if(r)
{
- fprintf(stderr, "ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n",
+ g_warning("ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n",
player->host, player->name, r);
return (void*)r;
if(r)
{
- fprintf(stderr, "ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n",
+ g_warning("ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n",
player->app->players.path, r);
pthread_mutex_lock(&player->app->players.lock);
for(r = 0 ; !player->app->f_exit && !r;)
{
/* sleep */
+#ifdef _WIN32
+ Sleep(100);
+#else
usleep(100000);
+#endif
/* get status */
pthread_mutex_lock(&player->app->players.lock);
pthread_mutex_unlock(&player->app->players.lock);
if(r)
- fprintf(stderr, "ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r);
+ g_warning("ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r);
else
if(memcmp(&st_curr, &st_prev, sizeof(OmPlrStatus)))
omnplay_update_status(player, &st_prev , &st_curr);
};
/* update border items */
- if(!start && !(app->playlist.item[start - 1].type & OMNPLAY_PLAYLIST_BLOCK_END))
+ if(start && !(app->playlist.item[start - 1].type & OMNPLAY_PLAYLIST_BLOCK_END))
{
app->playlist.item[start - 1].type = (playlist_item_type_t)(OMNPLAY_PLAYLIST_BLOCK_END
| app->playlist.item[start - 1].type);
};
}
else
- fprintf(stderr, "omnplay_playlist_block: range [%d %d] do OVERLAP player\n",
+ g_warning("omnplay_playlist_block: range [%d %d] do OVERLAP player\n",
start, stop);
pthread_mutex_unlock(&app->players.lock);
if(app->playlist.item[stop].type & OMNPLAY_PLAYLIST_BLOCK_END)
break;
- fprintf(stderr, "get_playlist_block: range %d -> %d\n", start, stop);
+ g_warning("get_playlist_block: range %d -> %d\n", start, stop);
/* check block range */
if(start >= 0 && stop < app->playlist.count)
idx = idxs[j] - j;
/* fix block types */
- if(idx)
- app->playlist.item[idx - 1].type = (playlist_item_type_t)(app->playlist.item[idx - 1].type |
- OMNPLAY_PLAYLIST_BLOCK_END);
- if(idx + 1 < app->playlist.count)
- app->playlist.item[idx + 1].type = (playlist_item_type_t)(app->playlist.item[idx + 1].type |
- OMNPLAY_PLAYLIST_BLOCK_BEGIN);
+ if( app->playlist.item[idx].type != OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY &&
+ app->playlist.item[idx].type != OMNPLAY_PLAYLIST_ITEM_LOOP_BODY)
+ {
+ if(idx)
+ app->playlist.item[idx - 1].type = (playlist_item_type_t)(app->playlist.item[idx - 1].type |
+ OMNPLAY_PLAYLIST_BLOCK_END);
+ if(idx + 1 < app->playlist.count)
+ app->playlist.item[idx + 1].type = (playlist_item_type_t)(app->playlist.item[idx + 1].type |
+ OMNPLAY_PLAYLIST_BLOCK_BEGIN);
+ };
/* shift playlist items */
memmove
if(!omnplay_playlist_insert_check(app, idx, &t))
return;
- fprintf(stderr, "allowed insert into idx=%d\n", idx);
+ g_warning("allowed insert into idx=%d\n", idx);
/* clear item */
memset(&item, 0, sizeof(playlist_item_t));
if(ui_playlist_item_dialog(app, &item))
{
+ omnplay_library_normalize_item(app, &item);
item.type = t;
omnplay_playlist_insert_items(app, idx, &item, 1);
};
if(ui_playlist_item_dialog(app, &item))
{
+ omnplay_library_normalize_item(app, &item);
app->playlist.item[idx] = item;
omnplay_playlist_draw_item(app, idx);
};
return;
};
- fprintf(stderr, "cue: selected item is %d\n", idx);
+ g_warning("cue: selected item is %d\n", idx);
if(get_playlist_block(app, idx, &start, &stop) < 0)
{
return;
};
- fprintf(stderr, "cue: range %d -> %d\n", start, stop);
+ g_warning("cue: range %d -> %d\n", start, stop);
player = get_player_at_pos(app, start);
{
unsigned int l;
- fprintf(stderr, "OmPlrClipGetInfo(%s): firstFrame=%d, lastFrame=%d\n",
+ g_warning("OmPlrClipGetInfo(%s): firstFrame=%d, lastFrame=%d\n",
app->playlist.item[i].id, clip.firstFrame, clip.lastFrame);
/* should we fix playlist clip timings */
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",
+ g_warning("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);
if(r)
{
- fprintf(stderr, "cue: failed with %d, %s\n", r, OmPlrGetErrorString((OmPlrError)r));
+ g_warning("cue: failed with %d, %s\n", r, OmPlrGetErrorString((OmPlrError)r));
app->playlist.item[i].omn_idx = -1;
app->playlist.item[i].omn_offset = -1;
+ app->playlist.item[i].error |= PLAYLIST_ITEM_ERROR_CUE;
}
else
{
app->playlist.item[i].omn_idx = c;
app->playlist.item[i].omn_offset = o;
+ app->playlist.item[i].error &= 0xF ^ PLAYLIST_ITEM_ERROR_CUE;
/* save selected item offset */
if(i == idx) p = o;
static void omnplay_playlist_item_swap(omnplay_instance_t* app, int dir)
{
- int sel, a, b;
+ int sel, a, b, e = 1;
GtkTreePath* path;
playlist_item_t item;
app->playlist.item[b] = item;
/* rewite type */
- app->playlist.item[a].type = OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE;
- app->playlist.item[b].type = OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE;
+ if(app->playlist.item[a].type != app->playlist.item[b].type)
+ {
+ e = 0;
+ app->playlist.item[a].type = OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE;
+ app->playlist.item[b].type = OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE;
+ };
/* redraw main items */
omnplay_playlist_draw_item(app, a);
omnplay_playlist_draw_item(app, b);
/* fix block types */
- if(a)
+ if(a && !e)
{
app->playlist.item[a - 1].type = (playlist_item_type_t)(app->playlist.item[a - 1].type |
OMNPLAY_PLAYLIST_BLOCK_END);
omnplay_playlist_draw_item(app, a - 1);
};
- if(b + 1 < app->playlist.count)
+ if(b + 1 < app->playlist.count && !e)
{
app->playlist.item[b + 1].type = (playlist_item_type_t)(app->playlist.item[b + 1].type |
OMNPLAY_PLAYLIST_BLOCK_BEGIN);
pthread_mutex_unlock(&app->playlist.lock);
};
+static void omnplay_library_add(omnplay_instance_t* app, int after)
+{
+ int idx, c, i;
+ playlist_item_t* items;
+ playlist_item_type_t t;
+
+ /* find insert position */
+ idx = get_first_selected_item_playlist(app);
+ if(idx < 0)
+ idx = 0;
+ else
+ idx += (after)?1:0;
+
+ if(!omnplay_playlist_insert_check(app, idx, &t))
+ return;
+
+ items = omnplay_library_get_selected(app, &c);
+
+ /* clear item */
+ if(items)
+ {
+ for(i = 0; i < c; i++)
+ {
+ items[i].type = t;
+ items[i].error = 0;
+ };
+ omnplay_playlist_insert_items(app, idx, items, c);
+ };
+};
+
+
static gboolean omnplay_button_click(omnplay_instance_t* app, control_buttons_t button)
{
switch(button)
omnplay_ctl(app, button);
break;
case BUTTON_LIBRARY_ADD:
+ omnplay_library_add(app, 0);
break;
case BUTTON_LIBRARY_REFRESH:
omnplay_library_refresh(app);
break;
+ case BUTTON_LIBRARY_FIND:
+ omnplay_library_search(app, 0);
+ break;
+ case BUTTON_LIBRARY_FIND_NEXT:
+ omnplay_library_search(app, 1);
+ break;
};
return TRUE;
return FALSE;
};
+static void omnplay_playlist_item_copy(omnplay_instance_t* app)
+{
+ int *list, i;
+
+ list = get_selected_items_playlist(app);
+ if(!list) return;
+
+ for(i = 0; i < list[0]; i++)
+ app->clipboard.item[i] = app->playlist.item[list[i + 1]];
+ app->clipboard.count = list[0];
+
+ free(list);
+};
+
+static void omnplay_playlist_item_paste(omnplay_instance_t* app, int after)
+{
+ int idx, i;
+ playlist_item_t* items;
+ playlist_item_type_t t;
+
+ /* find insert position */
+ idx = get_first_selected_item_playlist(app);
+ if(idx < 0)
+ idx = 0;
+ else
+ idx += (after)?1:0;
+
+ if(!omnplay_playlist_insert_check(app, idx, &t))
+ return;
+
+ /* clear item */
+ if(app->clipboard.count)
+ {
+ for(i = 0; i < app->clipboard.count; i++)
+ {
+ app->clipboard.item[i].type = t;
+ app->clipboard.item[i].error = 0;
+ };
+ omnplay_playlist_insert_items(app, idx, app->clipboard.item, app->clipboard.count);
+ };
+};
+
static gboolean on_playlist_grid_key(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
omnplay_instance_t* app = (omnplay_instance_t*)data;
case GDK_c:
if(event->state & GDK_CONTROL_MASK)
{
- fprintf(stderr, "CTRL+c\n");
+ omnplay_playlist_item_copy(app);
return TRUE;
};
break;
case GDK_v:
if(event->state & GDK_CONTROL_MASK)
{
- fprintf(stderr, "CTRL+v\n");
+ omnplay_playlist_item_paste(app, 0);
return TRUE;
};
break;
case GDK_x:
if(event->state & GDK_CONTROL_MASK)
{
- fprintf(stderr, "CTRL+x\n");
+ omnplay_playlist_item_copy(app);
+ omnplay_playlist_item_del(app);
+ return TRUE;
+ };
+ break;
+ case GDK_S:
+ case GDK_s:
+ if(event->state & GDK_CONTROL_MASK)
+ {
+ omnplay_playlist_save(app);
+ return TRUE;
+ };
+ break;
+ case GDK_O:
+ case GDK_o:
+ if(event->state & GDK_CONTROL_MASK)
+ {
+ omnplay_playlist_load(app);
return TRUE;
};
break;
return FALSE;
};
+static gboolean on_library_grid_key(GtkWidget *widget, GdkEventKey *event, gpointer data)
+{
+ omnplay_instance_t* app = (omnplay_instance_t*)data;
+
+ switch(event->keyval)
+ {
+ case GDK_C:
+ case GDK_c:
+ if(event->state & GDK_CONTROL_MASK)
+ {
+ int count;
+ playlist_item_t* items;
+
+ items = omnplay_library_get_selected(app, &count);
+
+ if(items)
+ {
+ int i;
+
+ for(i = 0; i < count; i++)
+ app->clipboard.item[i] = items[i];
+
+ app->clipboard.count = count;
+ };
+
+ return TRUE;
+ };
+ break;
+ case GDK_V:
+ case GDK_v:
+ if(event->state & GDK_CONTROL_MASK)
+ {
+ g_warning("CTRL+v\n");
+ return TRUE;
+ };
+ break;
+ case GDK_X:
+ case GDK_x:
+ if(event->state & GDK_CONTROL_MASK)
+ {
+ g_warning("CTRL+x\n");
+ return TRUE;
+ };
+ break;
+ };
+
+ return FALSE;
+};
+
+static gboolean on_library_grid_button(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ if(event->button==1 && event->type==GDK_2BUTTON_PRESS)
+ {
+ omnplay_library_add((omnplay_instance_t* )data, 0);
+ return TRUE;
+ };
+
+ return FALSE;
+};
+
+static gboolean on_playlist_grid_button(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ if(event->button==1 && event->type==GDK_2BUTTON_PRESS)
+ {
+ omnplay_ctl((omnplay_instance_t* )data, BUTTON_PLAYER_CUE);
+ return TRUE;
+ };
+
+ return FALSE;
+};
+
void omnplay_init(omnplay_instance_t* app)
{
int i;
pthread_mutexattr_t attr;
+ pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- gtk_signal_connect( GTK_OBJECT( app->window ), "destroy",
+ gtk_signal_connect( GTK_OBJECT( app->window ), "delete-event",
GTK_SIGNAL_FUNC(on_main_window_delete_event), app);
+ gtk_signal_connect( GTK_OBJECT( app->window ), "destroy",
+ GTK_SIGNAL_FUNC(on_main_window_destroy), app);
+
gtk_widget_add_events(app->playlist_grid, GDK_BUTTON_PRESS_MASK);
gtk_signal_connect(GTK_OBJECT(app->playlist_grid), "key-press-event",
GTK_SIGNAL_FUNC(on_playlist_grid_key), app);
+ gtk_widget_add_events(app->library_grid, GDK_BUTTON_PRESS_MASK);
+ gtk_signal_connect(GTK_OBJECT(app->library_grid), "key-press-event",
+ GTK_SIGNAL_FUNC(on_library_grid_key), app);
+
+ gtk_signal_connect(GTK_OBJECT(app->playlist_grid), "button-press-event",
+ GTK_SIGNAL_FUNC(on_playlist_grid_button), app);
+
+ gtk_signal_connect(GTK_OBJECT(app->library_grid), "button-press-event",
+ GTK_SIGNAL_FUNC(on_library_grid_button), app);
+
/* create lock */
pthread_mutex_init(&app->players.lock, &attr);
pthread_create(&app->players.item[i].thread, NULL,
omnplay_thread_proc, &app->players.item[i]);
+
/* create lock */
pthread_mutex_init(&app->playlist.lock, &attr);
/* load library */
omnplay_library_load(app);
+
+ pthread_mutexattr_destroy(&attr);
};
void omnplay_release(omnplay_instance_t* app)
/* destroy library lock */
pthread_mutex_destroy(&app->library.lock);
};
+
+void omnplay_playlist_normalize(omnplay_instance_t* app)
+{
+ int i;
+
+ /* normalize playlist */
+ for(i = 0; i < app->playlist.count; i++)
+ if(omnplay_library_normalize_item(app, &app->playlist.item[i]))
+ omnplay_playlist_draw_item(app, i);
+};