2 * omnplay.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <gdk/gdkkeysyms.h>
40 #include "omplrclnt.h"
42 int omnplay_get_content(omnplay_instance_t
* app
, playlist_item_t
*items
, int limit
,
43 omnplay_get_content_cb_proc proc
, void* data
)
46 OmPlrClipInfo clip_info
;
47 char clip_name
[omPlrMaxClipDirLen
];
49 pthread_mutex_lock(&app
->players
.lock
);
51 r
= OmPlrClipGetFirst((OmPlrHandle
)app
->players
.item
[0].handle
, clip_name
, sizeof(clip_name
));
52 for(; c
< limit
&& !r
;)
55 clip_info
.maxMsTracks
= 0;
56 clip_info
.size
= sizeof(clip_info
);
58 r
= OmPlrClipGetInfo((OmPlrHandle
)app
->players
.item
[0].handle
, clip_name
, &clip_info
);
63 strncpy(items
[c
].id
, clip_name
, PATH_MAX
);
64 items
[c
].in
= clip_info
.firstFrame
;
65 items
[c
].dur
= clip_info
.lastFrame
- clip_info
.firstFrame
;
68 pthread_mutex_unlock(&app
->players
.lock
);
70 proc(app
, &items
[c
], data
);
71 pthread_mutex_lock(&app
->players
.lock
);
76 r
= OmPlrClipGetNext((OmPlrHandle
)app
->players
.item
[0].handle
, clip_name
, sizeof(clip_name
));
79 pthread_mutex_unlock(&app
->players
.lock
);
85 static gboolean
on_main_window_delete_event( GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
87 g_print ("delete event occurred [start]\n");
89 omnplay_release((omnplay_instance_t
*)user_data
);
91 g_print ("delete event occurred [finish]\n");
96 static void on_main_window_destroy( GtkWidget
*widget
, gpointer user_data
)
98 g_print ("destroy occurred\n");
102 omnplay_instance_t
* omnplay_create(int argc
, char** argv
)
105 omnplay_instance_t
* app
;
107 /* prepare application instance */
108 app
= (omnplay_instance_t
*)malloc(sizeof(omnplay_instance_t
));
109 memset(app
, 0, sizeof(omnplay_instance_t
));
111 /* load parameters from command line */
112 if(!omnplay_opt(argc
, argv
, app
) && app
->players
.count
)
113 app
->window
= ui_omnplay(app
);
120 void omnplay_destroy(omnplay_instance_t
* app
)
125 static int find_index_of_playlist_item(omnplay_instance_t
* app
, int start
, int idx
)
129 if(app
->playlist
.item
[start
].omn_idx
== idx
)
132 if(app
->playlist
.item
[start
].type
& OMNPLAY_PLAYLIST_BLOCK_END
)
141 static void omnplay_update_status(omnplay_player_t
* player
, OmPlrStatus
*prev
, OmPlrStatus
*curr
)
144 char tc_cur
[32], tc_rem
[32], state
[32], status
[32];
149 frames2tc(curr
->pos
- curr
->minPos
, 25.0, tc_cur
);
150 frames2tc(curr
->maxPos
- curr
->pos
, 25.0, tc_rem
);
151 strcpy(status
, "ONLINE");
152 clip
= curr
->currClipName
;
156 case omPlrStateStopped
: strcpy(state
, "STOPPED"); break;
157 case omPlrStateCuePlay
: strcpy(state
, "CUE_PLAY"); break;
158 case omPlrStatePlay
: strcpy(state
, "PLAY"); break;
159 case omPlrStateCueRecord
: strcpy(state
, "CUE_RECORD"); break;
160 case omPlrStateRecord
: strcpy(state
, "RECORD"); break;
169 strcpy(status
, "OFFLINE");
172 /* update status in status page */
174 gtk_label_set_text(GTK_LABEL (player
->label_tc_cur
), tc_cur
);
175 gtk_label_set_text(GTK_LABEL (player
->label_tc_rem
), tc_rem
);
176 gtk_label_set_text(GTK_LABEL (player
->label_state
), state
);
177 gtk_label_set_text(GTK_LABEL (player
->label_status
), status
);
178 gtk_label_set_text(GTK_LABEL (player
->label_clip
), clip
);
182 /* update remaining time */
184 pthread_mutex_lock(&player
->app
->playlist
.lock
);
185 pthread_mutex_lock(&player
->app
->players
.lock
);
186 if(curr
->state
== omPlrStatePlay
|| curr
->state
== omPlrStateCuePlay
)
188 idx
= find_index_of_playlist_item(player
->app
, player
->playlist_start
, curr
->currClipNum
);
191 frames2tc(curr
->currClipStartPos
+ curr
->currClipLen
- curr
->pos
, 25.0, tc_rem
);
192 omnplay_playlist_draw_item_rem(player
->app
, idx
, tc_rem
);
194 if(curr
->currClipNum
!= prev
->currClipNum
&& 1 != prev
->numClips
)
197 idx
= find_index_of_playlist_item(player
->app
, player
->playlist_start
, prev
->currClipNum
);
199 omnplay_playlist_draw_item_rem(player
->app
, idx
, tc_rem
);
205 idx
= find_index_of_playlist_item(player
->app
, player
->playlist_start
, curr
->currClipNum
);
207 omnplay_playlist_draw_item_rem(player
->app
, idx
, tc_rem
);
208 idx
= find_index_of_playlist_item(player
->app
, player
->playlist_start
, prev
->currClipNum
);
210 omnplay_playlist_draw_item_rem(player
->app
, idx
, tc_rem
);
212 pthread_mutex_unlock(&player
->app
->players
.lock
);
213 pthread_mutex_unlock(&player
->app
->playlist
.lock
);
218 memcpy(prev
, curr
, sizeof(OmPlrStatus
));
221 static void* omnplay_thread_proc(void* data
)
224 OmPlrStatus st_curr
, st_prev
;
225 omnplay_player_t
* player
= (omnplay_player_t
*)data
;
228 pthread_mutex_lock(&player
->app
->players
.lock
);
229 r
= OmPlrOpen(player
->host
, player
->name
, (OmPlrHandle
*)&player
->handle
);
230 pthread_mutex_unlock(&player
->app
->players
.lock
);
233 fprintf(stderr
, "ERROR: OmPlrOpen(%s, %s) failed with 0x%.8X\n",
234 player
->host
, player
->name
, r
);
239 /* setup to do not reconnect */
240 pthread_mutex_lock(&player
->app
->players
.lock
);
241 OmPlrSetRetryOpen((OmPlrHandle
)player
->handle
, 0);
242 pthread_mutex_unlock(&player
->app
->players
.lock
);
244 /* setup directory */
245 if(player
->app
->players
.path
[0])
247 pthread_mutex_lock(&player
->app
->players
.lock
);
248 r
= OmPlrClipSetDirectory((OmPlrHandle
)player
->handle
, player
->app
->players
.path
);
249 pthread_mutex_unlock(&player
->app
->players
.lock
);
253 fprintf(stderr
, "ERROR: OmPlrClipSetDirectory(%s) failed with 0x%.8X\n",
254 player
->app
->players
.path
, r
);
256 pthread_mutex_lock(&player
->app
->players
.lock
);
257 OmPlrClose((OmPlrHandle
)player
->handle
);
258 pthread_mutex_unlock(&player
->app
->players
.lock
);
265 for(r
= 0 ; !player
->app
->f_exit
&& !r
;)
271 pthread_mutex_lock(&player
->app
->players
.lock
);
272 st_curr
.size
= sizeof(OmPlrStatus
);
273 r
= OmPlrGetPlayerStatus((OmPlrHandle
)player
->handle
, &st_curr
);
274 pthread_mutex_unlock(&player
->app
->players
.lock
);
277 fprintf(stderr
, "ERROR: OmPlrGetPlayerStatus failed with 0x%.8X\n", r
);
279 if(memcmp(&st_curr
, &st_prev
, sizeof(OmPlrStatus
)))
280 omnplay_update_status(player
, &st_prev
, &st_curr
);
283 pthread_mutex_lock(&player
->app
->players
.lock
);
284 OmPlrClose((OmPlrHandle
)player
->handle
);
285 pthread_mutex_unlock(&player
->app
->players
.lock
);
290 void get_selected_items_playlist_proc(GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
, gpointer data
)
292 int idx
, *list
= (int*)data
;
293 gtk_tree_model_get(model
, iter
, 7, &idx
, -1);
294 list
[list
[0] + 1] = idx
;
295 list
[0] = list
[0] + 1;
298 static int* get_selected_items_playlist(omnplay_instance_t
* app
)
301 GtkTreeSelection
*selection
;
303 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(app
->playlist_grid
));
306 list
= (int*)malloc(sizeof(int) * (MAX_PLAYLIST_ITEMS
+ 1));
307 memset(list
, 0, sizeof(int) * (MAX_PLAYLIST_ITEMS
+ 1));
309 gtk_tree_selection_selected_foreach(
311 get_selected_items_playlist_proc
,
324 static int idx_in_players_range(omnplay_instance_t
* app
, int idx
)
328 for(i
= 0; i
< app
->players
.count
&& !r
; i
++)
332 a
= app
->players
.item
[i
].playlist_start
;
333 b
= app
->players
.item
[i
].playlist_length
;
340 if(idx
>= a
&& idx
<= b
) r
= 1;
346 static int idxs_in_players_range(omnplay_instance_t
* app
, int start
, int stop
)
350 for(i
= 0; i
< app
->players
.count
&& !r
; i
++)
354 a
= app
->players
.item
[i
].playlist_start
;
355 b
= app
->players
.item
[i
].playlist_length
;
362 #define IN_RANGE(A,B,C) (A <= C && C <= B)
363 if( IN_RANGE(a
,b
,start
) ||
364 IN_RANGE(a
,b
,stop
) ||
365 IN_RANGE(start
,stop
,a
) ||
366 IN_RANGE(start
,stop
,b
))
373 static void omnplay_playlist_block(omnplay_instance_t
* app
, control_buttons_t button
)
375 int start
, stop
, r
, i
;
376 int* list
= get_selected_items_playlist(app
);
381 pthread_mutex_lock(&app
->playlist
.lock
);
382 pthread_mutex_lock(&app
->players
.lock
);
385 stop
= list
[list
[0]];
387 if(!idxs_in_players_range(app
, start
, stop
))
389 int loop
= (button
== BUTTON_PLAYLIST_BLOCK_LOOP
)?OMNPLAY_PLAYLIST_BLOCK_LOOP
:0;
391 /* update selected item */
392 for(i
= start
; i
<= stop
; i
++)
394 int t
= OMNPLAY_PLAYLIST_BLOCK_BODY
| loop
;
396 if(i
== start
) t
|= OMNPLAY_PLAYLIST_BLOCK_BEGIN
;
397 if(i
== stop
) t
|= OMNPLAY_PLAYLIST_BLOCK_END
;
399 app
->playlist
.item
[i
].type
= (playlist_item_type_t
)t
;
401 omnplay_playlist_draw_item(app
, i
);
404 /* update border items */
405 if(start
&& !(app
->playlist
.item
[start
- 1].type
& OMNPLAY_PLAYLIST_BLOCK_END
))
407 app
->playlist
.item
[start
- 1].type
= (playlist_item_type_t
)(OMNPLAY_PLAYLIST_BLOCK_END
408 | app
->playlist
.item
[start
- 1].type
);
409 omnplay_playlist_draw_item(app
, start
- 1);
411 if((stop
+ 1) < app
->playlist
.count
&& !(app
->playlist
.item
[stop
+ 1].type
& OMNPLAY_PLAYLIST_BLOCK_BEGIN
))
413 app
->playlist
.item
[stop
+ 1].type
= (playlist_item_type_t
)(OMNPLAY_PLAYLIST_BLOCK_BEGIN
414 | app
->playlist
.item
[stop
+ 1].type
);
415 omnplay_playlist_draw_item(app
, stop
+ 1);
419 fprintf(stderr
, "omnplay_playlist_block: range [%d %d] do OVERLAP player\n",
422 pthread_mutex_unlock(&app
->players
.lock
);
423 pthread_mutex_unlock(&app
->playlist
.lock
);
428 static int get_first_selected_item_playlist(omnplay_instance_t
* app
)
431 int* list
= get_selected_items_playlist(app
);
438 static int get_playlist_block(omnplay_instance_t
* app
, int idx
, int* start_ptr
, int* stop_ptr
)
442 for(start
= idx
; start
>= 0; start
--)
443 if(app
->playlist
.item
[start
].type
& OMNPLAY_PLAYLIST_BLOCK_BEGIN
)
446 for(stop
= idx
; stop
< app
->playlist
.count
; stop
++)
447 if(app
->playlist
.item
[stop
].type
& OMNPLAY_PLAYLIST_BLOCK_END
)
450 fprintf(stderr
, "get_playlist_block: range %d -> %d\n", start
, stop
);
452 /* check block range */
453 if(start
>= 0 && stop
< app
->playlist
.count
)
457 return (stop
- start
+ 1);
463 static omnplay_player_t
*get_player_at_pos(omnplay_instance_t
* app
, int pos
)
465 /* check player range */
466 if(app
->playlist
.item
[pos
].player
> -1 && app
->playlist
.item
[pos
].player
< app
->players
.count
)
467 return &app
->players
.item
[app
->playlist
.item
[pos
].player
];
472 static void omnplay_playlist_delete_items(omnplay_instance_t
* app
, int* idxs
, int count
)
477 pthread_mutex_lock(&app
->playlist
.lock
);
478 pthread_mutex_lock(&app
->players
.lock
);
480 for(j
= 0; j
< count
; j
++)
484 /* fix block types */
485 if( app
->playlist
.item
[idx
].type
!= OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY
&&
486 app
->playlist
.item
[idx
].type
!= OMNPLAY_PLAYLIST_ITEM_LOOP_BODY
)
489 app
->playlist
.item
[idx
- 1].type
= (playlist_item_type_t
)(app
->playlist
.item
[idx
- 1].type
|
490 OMNPLAY_PLAYLIST_BLOCK_END
);
491 if(idx
+ 1 < app
->playlist
.count
)
492 app
->playlist
.item
[idx
+ 1].type
= (playlist_item_type_t
)(app
->playlist
.item
[idx
+ 1].type
|
493 OMNPLAY_PLAYLIST_BLOCK_BEGIN
);
496 /* shift playlist items */
499 &app
->playlist
.item
[idx
],
500 &app
->playlist
.item
[idx
+ 1],
501 (app
->playlist
.count
- idx
- 1) * sizeof(playlist_item_t
)
504 /* decrement items count */
505 app
->playlist
.count
--;
507 /* increment servers indexes */
508 for(i
= 0; i
< app
->players
.count
; i
++)
509 if(app
->players
.item
[i
].playlist_start
>= idx
)
510 app
->players
.item
[i
].playlist_start
--;
515 /* redraw playlist */
516 omnplay_playlist_draw(app
);
519 path
= gtk_tree_path_new_from_indices(idxs
[0], -1);
520 gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app
->playlist_grid
)), path
);
521 gtk_tree_view_set_cursor(GTK_TREE_VIEW(app
->playlist_grid
), path
, NULL
, FALSE
);
522 gtk_tree_path_free(path
);
525 pthread_mutex_unlock(&app
->players
.lock
);
526 pthread_mutex_unlock(&app
->playlist
.lock
);
529 static void omnplay_playlist_item_del(omnplay_instance_t
* app
)
534 list
= get_selected_items_playlist(app
);
537 list2
= (int*)malloc(sizeof(int) * list
[0]);
539 for(i
= 0, c
= 0; i
< list
[0]; i
++)
541 /* check for playing block */
542 if(idx_in_players_range(app
, list
[i
+ 1]))
546 list2
[c
++] = list
[i
+ 1];
550 omnplay_playlist_delete_items(app
, list2
, c
);
556 static int omnplay_playlist_insert_check(omnplay_instance_t
* app
, int idx
, playlist_item_type_t
* t
)
558 *t
= OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
;
560 /* before or after playlist */
561 if(!idx
|| idx
== app
->playlist
.count
)
564 /* check for block borders */
565 if( app
->playlist
.item
[idx
- 1].type
& OMNPLAY_PLAYLIST_BLOCK_END
&&
566 app
->playlist
.item
[idx
+ 0].type
& OMNPLAY_PLAYLIST_BLOCK_BEGIN
)
569 /* check for playing block */
570 if(idx_in_players_range(app
, idx
))
573 if(app
->playlist
.item
[idx
].type
& OMNPLAY_PLAYLIST_BLOCK_LOOP
)
574 *t
= OMNPLAY_PLAYLIST_ITEM_LOOP_BODY
;
576 *t
= OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY
;
581 static void omnplay_playlist_insert_items(omnplay_instance_t
* app
, int idx
,
582 playlist_item_t
* items
, int count
)
587 pthread_mutex_lock(&app
->playlist
.lock
);
588 pthread_mutex_lock(&app
->players
.lock
);
590 /* shift playlist items */
593 &app
->playlist
.item
[idx
+ count
],
594 &app
->playlist
.item
[idx
],
595 (app
->playlist
.count
- idx
) * sizeof(playlist_item_t
)
601 &app
->playlist
.item
[idx
],
603 count
* sizeof(playlist_item_t
)
606 /* increment servers indexes */
607 for(i
= 0; i
< app
->players
.count
; i
++)
608 if(app
->players
.item
[i
].playlist_start
>= idx
)
609 app
->players
.item
[i
].playlist_start
+= idx
;
611 /* increment items count */
612 app
->playlist
.count
+= count
;
614 /* redraw playlist */
615 omnplay_playlist_draw(app
);
618 path
= gtk_tree_path_new_from_indices(idx
+ count
, -1);
619 gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app
->playlist_grid
)), path
);
620 gtk_tree_view_set_cursor(GTK_TREE_VIEW(app
->playlist_grid
), path
, NULL
, FALSE
);
621 gtk_tree_path_free(path
);
623 pthread_mutex_unlock(&app
->players
.lock
);
624 pthread_mutex_unlock(&app
->playlist
.lock
);
627 static void omnplay_playlist_item_add(omnplay_instance_t
* app
, int after
)
630 playlist_item_t item
;
631 playlist_item_type_t t
;
633 /* find insert position */
634 idx
= get_first_selected_item_playlist(app
);
640 if(!omnplay_playlist_insert_check(app
, idx
, &t
))
643 fprintf(stderr
, "allowed insert into idx=%d\n", idx
);
646 memset(&item
, 0, sizeof(playlist_item_t
));
647 if(ui_playlist_item_dialog(app
, &item
))
649 omnplay_library_normalize_item(app
, &item
);
651 omnplay_playlist_insert_items(app
, idx
, &item
, 1);
655 static void omnplay_playlist_item_edit(omnplay_instance_t
* app
)
658 playlist_item_t item
;
660 /* find insert position */
661 idx
= get_first_selected_item_playlist(app
);
666 /* check for playing block */
667 if(idx_in_players_range(app
, idx
))
670 item
= app
->playlist
.item
[idx
];
672 if(ui_playlist_item_dialog(app
, &item
))
674 omnplay_library_normalize_item(app
, &item
);
675 app
->playlist
.item
[idx
] = item
;
676 omnplay_playlist_draw_item(app
, idx
);
680 static void omnplay_ctl(omnplay_instance_t
* app
, control_buttons_t button
)
683 int idx
, start
, stop
;
684 omnplay_player_t
*player
;
686 pthread_mutex_lock(&app
->playlist
.lock
);
688 idx
= get_first_selected_item_playlist(app
);
692 pthread_mutex_unlock(&app
->playlist
.lock
);
696 fprintf(stderr
, "cue: selected item is %d\n", idx
);
698 if(get_playlist_block(app
, idx
, &start
, &stop
) < 0)
700 pthread_mutex_unlock(&app
->playlist
.lock
);
704 fprintf(stderr
, "cue: range %d -> %d\n", start
, stop
);
706 player
= get_player_at_pos(app
, start
);
710 pthread_mutex_unlock(&app
->playlist
.lock
);
714 pthread_mutex_lock(&app
->players
.lock
);
716 if(BUTTON_PLAYER_STOP
== button
|| BUTTON_PLAYER_CUE
== button
)
719 OmPlrStop((OmPlrHandle
)player
->handle
);
721 /* detach previous clips */
722 player
->playlist_length
= -1;
723 OmPlrDetachAllClips((OmPlrHandle
)player
->handle
);
726 if(BUTTON_PLAYER_CUE
== button
)
730 /* Attach clips to timeline */
731 for(i
= start
, c
= 0, o
= 0; i
<= stop
; i
++)
736 clip
.maxMsTracks
= 0;
737 clip
.size
= sizeof(clip
);
738 r
= OmPlrClipGetInfo((OmPlrHandle
)player
->handle
, app
->playlist
.item
[i
].id
, &clip
);
744 fprintf(stderr
, "OmPlrClipGetInfo(%s): firstFrame=%d, lastFrame=%d\n",
745 app
->playlist
.item
[i
].id
, clip
.firstFrame
, clip
.lastFrame
);
747 /* should we fix playlist clip timings */
749 app
->playlist
.item
[i
].in
>= clip
.firstFrame
&&
750 app
->playlist
.item
[i
].in
+ app
->playlist
.item
[i
].dur
<= clip
.lastFrame
) ||
751 !app
->playlist
.item
[i
].dur
)
753 fprintf(stderr
, "cue: item [%s] will be updated [%d;%d]->[%d;%d]\n",
754 app
->playlist
.item
[i
].id
,
755 app
->playlist
.item
[i
].in
, app
->playlist
.item
[i
].dur
,
756 clip
.firstFrame
, clip
.lastFrame
- clip
.firstFrame
);
758 app
->playlist
.item
[i
].in
= clip
.firstFrame
;
759 app
->playlist
.item
[i
].dur
= clip
.lastFrame
- clip
.firstFrame
;
760 omnplay_playlist_draw_item(app
, i
);
763 r
= OmPlrAttach((OmPlrHandle
)player
->handle
,
764 app
->playlist
.item
[i
].id
,
765 app
->playlist
.item
[i
].in
,
766 app
->playlist
.item
[i
].in
+ app
->playlist
.item
[i
].dur
,
767 0, omPlrShiftModeAfter
, &l
);
772 fprintf(stderr
, "cue: failed with %d, %s\n", r
, OmPlrGetErrorString((OmPlrError
)r
));
773 app
->playlist
.item
[i
].omn_idx
= -1;
774 app
->playlist
.item
[i
].omn_offset
= -1;
775 app
->playlist
.item
[i
].error
|= PLAYLIST_ITEM_ERROR_CUE
;
779 app
->playlist
.item
[i
].omn_idx
= c
;
780 app
->playlist
.item
[i
].omn_offset
= o
;
781 app
->playlist
.item
[i
].error
&= 0xF ^ PLAYLIST_ITEM_ERROR_CUE
;
783 /* save selected item offset */
787 o
+= app
->playlist
.item
[i
].dur
;
795 /* Set timeline min/max */
796 OmPlrSetMinPosMin((OmPlrHandle
)player
->handle
);
797 OmPlrSetMaxPosMax((OmPlrHandle
)player
->handle
);
799 /* Set timeline position */
801 hs
.size
= sizeof(OmPlrStatus
);
802 OmPlrGetPlayerStatus((OmPlrHandle
)player
->handle
, &hs
);
803 OmPlrSetPos((OmPlrHandle
)player
->handle
, hs
.minPos
+ p
);
806 if(app
->playlist
.item
[start
].type
& OMNPLAY_PLAYLIST_BLOCK_LOOP
)
807 OmPlrLoop((OmPlrHandle
)player
->handle
, hs
.minPos
, hs
.maxPos
);
809 OmPlrLoop((OmPlrHandle
)player
->handle
, hs
.minPos
, hs
.minPos
);
811 player
->playlist_start
= start
;
812 player
->playlist_length
= stop
- start
+ 1;
815 OmPlrCuePlay((OmPlrHandle
)player
->handle
, 0.0);
819 if(BUTTON_PLAYER_PLAY
== button
)
822 OmPlrPlay((OmPlrHandle
)player
->handle
, 1.0);
825 if(BUTTON_PLAYER_PAUSE
== button
)
827 OmPlrPlay((OmPlrHandle
)player
->handle
, 0.0);
829 pthread_mutex_unlock(&app
->players
.lock
);
831 pthread_mutex_unlock(&app
->playlist
.lock
);
834 static void omnplay_playlist_item_swap(omnplay_instance_t
* app
, int dir
)
836 int sel
, a
, b
, e
= 1;
838 playlist_item_t item
;
840 /* find insert position */
841 sel
= get_first_selected_item_playlist(app
);
858 /* check for playing block */
859 if(idx_in_players_range(app
, a
) || idx_in_players_range(app
, b
))
862 pthread_mutex_lock(&app
->playlist
.lock
);
863 pthread_mutex_lock(&app
->players
.lock
);
866 item
= app
->playlist
.item
[a
];
867 app
->playlist
.item
[a
] = app
->playlist
.item
[b
];
868 app
->playlist
.item
[b
] = item
;
871 if(app
->playlist
.item
[a
].type
!= app
->playlist
.item
[b
].type
)
874 app
->playlist
.item
[a
].type
= OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
;
875 app
->playlist
.item
[b
].type
= OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE
;
878 /* redraw main items */
879 omnplay_playlist_draw_item(app
, a
);
880 omnplay_playlist_draw_item(app
, b
);
882 /* fix block types */
885 app
->playlist
.item
[a
- 1].type
= (playlist_item_type_t
)(app
->playlist
.item
[a
- 1].type
|
886 OMNPLAY_PLAYLIST_BLOCK_END
);
887 omnplay_playlist_draw_item(app
, a
- 1);
889 if(b
+ 1 < app
->playlist
.count
&& !e
)
891 app
->playlist
.item
[b
+ 1].type
= (playlist_item_type_t
)(app
->playlist
.item
[b
+ 1].type
|
892 OMNPLAY_PLAYLIST_BLOCK_BEGIN
);
893 omnplay_playlist_draw_item(app
, b
+ 1);
897 path
= gtk_tree_path_new_from_indices(sel
, -1);
898 gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app
->playlist_grid
)), path
);
899 gtk_tree_view_set_cursor(GTK_TREE_VIEW(app
->playlist_grid
), path
, NULL
, FALSE
);
900 gtk_tree_path_free(path
);
902 pthread_mutex_unlock(&app
->players
.lock
);
903 pthread_mutex_unlock(&app
->playlist
.lock
);
906 static void omnplay_library_add(omnplay_instance_t
* app
, int after
)
909 playlist_item_t
* items
;
910 playlist_item_type_t t
;
912 /* find insert position */
913 idx
= get_first_selected_item_playlist(app
);
919 if(!omnplay_playlist_insert_check(app
, idx
, &t
))
922 items
= omnplay_library_get_selected(app
, &c
);
927 for(i
= 0; i
< c
; i
++)
932 omnplay_playlist_insert_items(app
, idx
, items
, c
);
937 static gboolean
omnplay_button_click(omnplay_instance_t
* app
, control_buttons_t button
)
941 case BUTTON_PLAYLIST_ITEM_ADD
:
942 omnplay_playlist_item_add(app
, 0);
944 case BUTTON_PLAYLIST_ITEM_DEL
:
945 omnplay_playlist_item_del(app
);
947 case BUTTON_PLAYLIST_ITEM_EDIT
:
948 omnplay_playlist_item_edit(app
);
950 case BUTTON_PLAYLIST_LOAD
:
951 omnplay_playlist_load(app
);
953 case BUTTON_PLAYLIST_SAVE
:
954 omnplay_playlist_save(app
);
956 case BUTTON_PLAYLIST_BLOCK_SINGLE
:
957 case BUTTON_PLAYLIST_BLOCK_LOOP
:
958 omnplay_playlist_block(app
, button
);
960 case BUTTON_PLAYLIST_ITEM_UP
:
961 omnplay_playlist_item_swap(app
, -1);
963 case BUTTON_PLAYLIST_ITEM_DOWN
:
964 omnplay_playlist_item_swap(app
, +1);
966 case BUTTON_PLAYER_CUE
:
967 case BUTTON_PLAYER_PLAY
:
968 case BUTTON_PLAYER_PAUSE
:
969 case BUTTON_PLAYER_STOP
:
970 omnplay_ctl(app
, button
);
972 case BUTTON_LIBRARY_ADD
:
973 omnplay_library_add(app
, 0);
975 case BUTTON_LIBRARY_REFRESH
:
976 omnplay_library_refresh(app
);
978 case BUTTON_LIBRARY_FIND
:
979 omnplay_library_search(app
, 0);
981 case BUTTON_LIBRARY_FIND_NEXT
:
982 omnplay_library_search(app
, 1);
989 static gboolean
on_button_click(GtkWidget
*button
, gpointer user_data
)
992 omnplay_instance_t
* app
= (omnplay_instance_t
*)user_data
;
994 for(i
= 1; i
< BUTTON_LAST
; i
++)
995 if(app
->buttons
[i
] == button
)
996 return omnplay_button_click(app
, (control_buttons_t
)i
);
1001 static void omnplay_playlist_item_copy(omnplay_instance_t
* app
)
1005 list
= get_selected_items_playlist(app
);
1008 for(i
= 0; i
< list
[0]; i
++)
1009 app
->clipboard
.item
[i
] = app
->playlist
.item
[list
[i
+ 1]];
1010 app
->clipboard
.count
= list
[0];
1015 static void omnplay_playlist_item_paste(omnplay_instance_t
* app
, int after
)
1018 playlist_item_t
* items
;
1019 playlist_item_type_t t
;
1021 /* find insert position */
1022 idx
= get_first_selected_item_playlist(app
);
1028 if(!omnplay_playlist_insert_check(app
, idx
, &t
))
1032 if(app
->clipboard
.count
)
1034 for(i
= 0; i
< app
->clipboard
.count
; i
++)
1036 app
->clipboard
.item
[i
].type
= t
;
1037 app
->clipboard
.item
[i
].error
= 0;
1039 omnplay_playlist_insert_items(app
, idx
, app
->clipboard
.item
, app
->clipboard
.count
);
1043 static gboolean
on_playlist_grid_key(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1045 omnplay_instance_t
* app
= (omnplay_instance_t
*)data
;
1047 switch(event
->keyval
)
1051 if(event
->state
& GDK_CONTROL_MASK
)
1053 omnplay_playlist_item_copy(app
);
1059 if(event
->state
& GDK_CONTROL_MASK
)
1061 omnplay_playlist_item_paste(app
, 0);
1067 if(event
->state
& GDK_CONTROL_MASK
)
1069 omnplay_playlist_item_copy(app
);
1070 omnplay_playlist_item_del(app
);
1076 if(event
->state
& GDK_CONTROL_MASK
)
1078 omnplay_playlist_save(app
);
1084 if(event
->state
& GDK_CONTROL_MASK
)
1086 omnplay_playlist_load(app
);
1091 omnplay_ctl(app
, BUTTON_PLAYER_PLAY
);
1093 case GDK_KEY_Return
:
1094 omnplay_ctl(app
, BUTTON_PLAYER_CUE
);
1096 case GDK_KEY_Insert
:
1097 omnplay_playlist_item_add(app
, 0);
1099 case GDK_KEY_Delete
:
1100 omnplay_playlist_item_del(app
);
1102 case GDK_KEY_BackSpace
:
1103 omnplay_playlist_item_edit(app
);
1110 static gboolean
on_library_grid_key(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
1112 omnplay_instance_t
* app
= (omnplay_instance_t
*)data
;
1114 switch(event
->keyval
)
1118 if(event
->state
& GDK_CONTROL_MASK
)
1121 playlist_item_t
* items
;
1123 items
= omnplay_library_get_selected(app
, &count
);
1129 for(i
= 0; i
< count
; i
++)
1130 app
->clipboard
.item
[i
] = items
[i
];
1132 app
->clipboard
.count
= count
;
1140 if(event
->state
& GDK_CONTROL_MASK
)
1142 fprintf(stderr
, "CTRL+v\n");
1148 if(event
->state
& GDK_CONTROL_MASK
)
1150 fprintf(stderr
, "CTRL+x\n");
1159 static gboolean
on_library_grid_button(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
1161 if(event
->button
==1 && event
->type
==GDK_2BUTTON_PRESS
)
1163 omnplay_library_add((omnplay_instance_t
* )data
, 0);
1170 static gboolean
on_playlist_grid_button(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
1172 if(event
->button
==1 && event
->type
==GDK_2BUTTON_PRESS
)
1174 omnplay_ctl((omnplay_instance_t
* )data
, BUTTON_PLAYER_CUE
);
1181 void omnplay_init(omnplay_instance_t
* app
)
1184 pthread_mutexattr_t attr
;
1186 pthread_mutexattr_settype(&attr
, PTHREAD_MUTEX_RECURSIVE
);
1188 gtk_signal_connect( GTK_OBJECT( app
->window
), "delete-event",
1189 GTK_SIGNAL_FUNC(on_main_window_delete_event
), app
);
1191 gtk_signal_connect( GTK_OBJECT( app
->window
), "destroy",
1192 GTK_SIGNAL_FUNC(on_main_window_destroy
), app
);
1194 gtk_widget_add_events(app
->playlist_grid
, GDK_BUTTON_PRESS_MASK
);
1195 gtk_signal_connect(GTK_OBJECT(app
->playlist_grid
), "key-press-event",
1196 GTK_SIGNAL_FUNC(on_playlist_grid_key
), app
);
1198 gtk_widget_add_events(app
->library_grid
, GDK_BUTTON_PRESS_MASK
);
1199 gtk_signal_connect(GTK_OBJECT(app
->library_grid
), "key-press-event",
1200 GTK_SIGNAL_FUNC(on_library_grid_key
), app
);
1202 gtk_signal_connect(GTK_OBJECT(app
->playlist_grid
), "button-press-event",
1203 GTK_SIGNAL_FUNC(on_playlist_grid_button
), app
);
1205 gtk_signal_connect(GTK_OBJECT(app
->library_grid
), "button-press-event",
1206 GTK_SIGNAL_FUNC(on_library_grid_button
), app
);
1209 pthread_mutex_init(&app
->players
.lock
, &attr
);
1211 /* create a omneon status thread */
1212 for(i
= 0; i
< app
->players
.count
; i
++)
1213 pthread_create(&app
->players
.item
[i
].thread
, NULL
,
1214 omnplay_thread_proc
, &app
->players
.item
[i
]);
1217 pthread_mutex_init(&app
->playlist
.lock
, &attr
);
1219 /* attach buttons click */
1220 for(i
= 1; i
< BUTTON_LAST
; i
++)
1221 gtk_signal_connect(GTK_OBJECT(app
->buttons
[i
]), "clicked",
1222 GTK_SIGNAL_FUNC( on_button_click
), app
);
1225 pthread_mutex_init(&app
->library
.lock
, &attr
);
1228 omnplay_library_load(app
);
1231 void omnplay_release(omnplay_instance_t
* app
)
1238 for(i
= 0; i
< app
->players
.count
; i
++)
1239 /* create a omneon status thread */
1240 pthread_join(app
->players
.item
[i
].thread
, &r
);
1243 pthread_mutex_destroy(&app
->players
.lock
);
1246 pthread_mutex_destroy(&app
->playlist
.lock
);
1249 omnplay_library_save(app
);
1251 /* destroy library lock */
1252 pthread_mutex_destroy(&app
->library
.lock
);
1255 void omnplay_playlist_normalize(omnplay_instance_t
* app
)
1259 /* normalize playlist */
1260 for(i
= 0; i
< app
->playlist
.count
; i
++)
1261 if(omnplay_library_normalize_item(app
, &app
->playlist
.item
[i
]))
1262 omnplay_playlist_draw_item(app
, i
);