2 * control.c -- GTK+ 2 melted gui
3 * Copyright (C) 2012 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>
36 #include <mvcp/mvcp.h>
37 #include <mvcp/mvcp_remote.h>
45 void control_release(instance_t
* app
)
49 void control_init(instance_t
* app
)
53 typedef struct player_handle_desc
60 int control_route(instance_t
* app
, control_buttons_t button
)
65 player_handle_t
* handle
;
68 pthread_mutex_lock(&app
->playlist
.lock
);
70 idx
= playlist_get_first_selected_item_idx(app
);
74 pthread_mutex_unlock(&app
->playlist
.lock
);
78 g_warning("control_route: selected item is %d\n", idx
);
80 if(playlist_get_block(app
, idx
, &start
, &stop
) < 0)
82 pthread_mutex_unlock(&app
->playlist
.lock
);
86 g_warning("control_route: range %d -> %d\n", start
, stop
);
88 player
= playlist_get_player_at_pos(app
, start
);
92 pthread_mutex_unlock(&app
->playlist
.lock
);
96 handle
= player
->handle
;
98 pthread_mutex_lock(&app
->players
.lock
);
100 if(BUTTON_PLAYER_STOP
== button
|| BUTTON_PLAYER_CUE
== button
)
103 mvcp_unit_stop(handle
->command
, player
->unit
);
105 /* detach previous clips */
106 player
->playlist_length
= -1;
107 mvcp_unit_clear(handle
->command
, player
->unit
);
110 if(BUTTON_PLAYER_CUE
== button
)
112 playlist_item_t
* item
;
116 for(i
= start
; i
<= stop
; i
++)
117 app
->playlist
.item
[i
].int_idx
= -1;
119 /* Attach clips to timeline */
120 for(i
= 0, c
= 0, o
= 0; i
< (stop
- start
+ 1); i
++)
122 /* calc seq to playlist grid */
126 if(app
->playlist
.item
[start
].type
& PLAYLIST_BLOCK_LOOP
)
127 j
= start
+ j
- stop
- 1;
131 g_warning("control_route: i = %d, j = %d\n", i
, j
);
133 item
= &app
->playlist
.item
[j
];
136 m
= mvcp_unit_append(handle
->command
, player
->unit
,
137 item
->id
, item
->in
, item
->in
+ item
->dur
- 1);
141 g_warning("cue: failed with %d, %s\n", m
, "unknown" /*OmPlrGetErrorString((OmPlrError)r)*/);
142 item
->error
|= PLAYLIST_ITEM_ERROR_CUE
;
147 item
->error
&= 0xF ^ PLAYLIST_ITEM_ERROR_CUE
;
154 mvcp_unit_pause(handle
->command
, player
->unit
);
157 if(app
->playlist
.item
[start
].type
& PLAYLIST_BLOCK_LOOP
)
158 mvcp_unit_set(handle
->command
, player
->unit
, "eof", "loop");
160 mvcp_unit_set(handle
->command
, player
->unit
, "eof", "pause");
162 player
->playlist_start
= start
;
163 player
->playlist_length
= stop
- start
+ 1;
167 if(BUTTON_PLAYER_PLAY
== button
)
169 mvcp_unit_play(handle
->command
, player
->unit
);
171 if(BUTTON_PLAYER_PAUSE
== button
)
173 mvcp_unit_pause(handle
->command
, player
->unit
);
175 pthread_mutex_unlock(&app
->players
.lock
);
177 pthread_mutex_unlock(&app
->playlist
.lock
);