X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fomnplay.cpp;h=e35479f9610e53983e2d120f3316d8f972798acc;hb=5ad064d3b7783d03e72c8d2b3a20888b84619625;hp=f881f4522c8b8ee7380dee179cecef9debe908c5;hpb=dc949fcd138c792f9d9f5a060327ff36c18ff4a1;p=omnplay diff --git a/src/omnplay.cpp b/src/omnplay.cpp index f881f45..e35479f 100644 --- a/src/omnplay.cpp +++ b/src/omnplay.cpp @@ -415,6 +415,208 @@ static omnplay_player_t *get_player_at_pos(omnplay_instance_t* app, int pos) return NULL; }; +static void omnplay_playlist_delete_items(omnplay_instance_t* app, int* idxs, int count) +{ + int i, j, idx; + GtkTreePath* path; + + pthread_mutex_lock(&app->playlist.lock); + pthread_mutex_lock(&app->players.lock); + + for(j = 0; j < count; j++) + { + 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); + + /* shift playlist items */ + memmove + ( + &app->playlist.item[idx], + &app->playlist.item[idx + 1], + (app->playlist.count - idx - 1) * sizeof(playlist_item_t) + ); + + /* decrement items count */ + app->playlist.count--; + + /* increment servers indexes */ + for(i = 0; i < app->players.count; i++) + if(app->players.item[i].playlist_start >= idx) + app->players.item[i].playlist_start--; + + + }; + + /* redraw playlist */ + omnplay_playlist_draw(app); + + /* select */ + path = gtk_tree_path_new_from_indices(idxs[0], -1); + gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app->playlist_grid)), path); + gtk_tree_view_set_cursor(GTK_TREE_VIEW(app->playlist_grid), path, NULL, FALSE); + gtk_tree_path_free(path); + + + pthread_mutex_unlock(&app->players.lock); + pthread_mutex_unlock(&app->playlist.lock); +}; + +static void omnplay_playlist_item_del(omnplay_instance_t* app) +{ + int i, idx, c; + int *list, *list2; + + list = get_selected_items_playlist(app); + if(!list) return; + + list2 = (int*)malloc(sizeof(int) * list[0]); + + for(i = 0, c = 0; i < list[0]; i++) + { + /* check for playing block */ + if(idx_in_players_range(app, list[i + 1])) + continue; + + /* save index */ + list2[c++] = list[i + 1]; + }; + + if(c) + omnplay_playlist_delete_items(app, list2, c); + + free(list2); + free(list); +}; + +static int omnplay_playlist_insert_check(omnplay_instance_t* app, int idx, playlist_item_type_t* t) +{ + *t = OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE; + + /* before or after playlist */ + if(!idx || idx == app->playlist.count) + return 1; + + /* check for block borders */ + if( app->playlist.item[idx - 1].type & OMNPLAY_PLAYLIST_BLOCK_END && + app->playlist.item[idx + 0].type & OMNPLAY_PLAYLIST_BLOCK_BEGIN) + return 1; + + /* check for playing block */ + if(idx_in_players_range(app, idx)) + return 0; + + if(app->playlist.item[idx].type & OMNPLAY_PLAYLIST_BLOCK_LOOP) + *t = OMNPLAY_PLAYLIST_ITEM_LOOP_BODY; + else + *t = OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY; + + return 1; +}; + +static void omnplay_playlist_insert_items(omnplay_instance_t* app, int idx, + playlist_item_t* items, int count) +{ + int i; + GtkTreePath* path; + + pthread_mutex_lock(&app->playlist.lock); + pthread_mutex_lock(&app->players.lock); + + /* shift playlist items */ + memmove + ( + &app->playlist.item[idx + count], + &app->playlist.item[idx], + (app->playlist.count - idx) * sizeof(playlist_item_t) + ); + + /* copy new items */ + memcpy + ( + &app->playlist.item[idx], + items, + count * sizeof(playlist_item_t) + ); + + /* increment servers indexes */ + for(i = 0; i < app->players.count; i++) + if(app->players.item[i].playlist_start >= idx) + app->players.item[i].playlist_start += idx; + + /* increment items count */ + app->playlist.count += count; + + /* redraw playlist */ + omnplay_playlist_draw(app); + + /* select */ + path = gtk_tree_path_new_from_indices(idx + count, -1); + gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app->playlist_grid)), path); + gtk_tree_view_set_cursor(GTK_TREE_VIEW(app->playlist_grid), path, NULL, FALSE); + gtk_tree_path_free(path); + + pthread_mutex_unlock(&app->players.lock); + pthread_mutex_unlock(&app->playlist.lock); +}; + +static void omnplay_playlist_item_add(omnplay_instance_t* app, int after) +{ + int idx; + playlist_item_t item; + 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; + + fprintf(stderr, "allowed insert into idx=%d\n", idx); + + /* clear item */ + memset(&item, 0, sizeof(playlist_item_t)); + if(ui_playlist_item_dialog(app, &item)) + { + item.type = t; + omnplay_playlist_insert_items(app, idx, &item, 1); + }; +}; + +static void omnplay_playlist_item_edit(omnplay_instance_t* app) +{ + int idx; + playlist_item_t item; + + /* find insert position */ + idx = get_first_selected_item_playlist(app); + + if(idx < 0) + return; + + /* check for playing block */ + if(idx_in_players_range(app, idx)) + return; + + item = app->playlist.item[idx]; + + if(ui_playlist_item_dialog(app, &item)) + { + app->playlist.item[idx] = item; + omnplay_playlist_draw_item(app, idx); + }; +}; + static void omnplay_ctl(omnplay_instance_t* app, control_buttons_t button) { int i, r; @@ -541,6 +743,8 @@ static void omnplay_ctl(omnplay_instance_t* app, control_buttons_t button) /* setup loop */ if(app->playlist.item[start].type & OMNPLAY_PLAYLIST_BLOCK_LOOP) OmPlrLoop((OmPlrHandle)player->handle, hs.minPos, hs.maxPos); + else + OmPlrLoop((OmPlrHandle)player->handle, hs.minPos, hs.minPos); player->playlist_start = start; player->playlist_length = stop - start + 1; @@ -570,8 +774,13 @@ static gboolean omnplay_button_click(omnplay_instance_t* app, control_buttons_t switch(button) { case BUTTON_PLAYLIST_ITEM_ADD: + omnplay_playlist_item_add(app, 0); + break; case BUTTON_PLAYLIST_ITEM_DEL: + omnplay_playlist_item_del(app); + break; case BUTTON_PLAYLIST_ITEM_EDIT: + omnplay_playlist_item_edit(app); break; case BUTTON_PLAYLIST_LOAD: omnplay_playlist_load(app);