X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fcontrol.c;fp=src%2Fcontrol.c;h=612f1add2bc7e57e145d764e2f384a5660d0a41c;hb=9638c3cc3c60587117673f7d1b821e8c960fe355;hp=0000000000000000000000000000000000000000;hpb=ff7f700c3f8b82388b185d61293e36a28a24d448;p=melted_gui diff --git a/src/control.c b/src/control.c new file mode 100644 index 0000000..612f1ad --- /dev/null +++ b/src/control.c @@ -0,0 +1,180 @@ +/* + * control.c -- GTK+ 2 melted gui + * Copyright (C) 2012 Maksym Veremeyenko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "control.h" +#include "ui.h" +#include "timecode.h" +#include "support.h" +#include "playlist.h" + +void control_release(instance_t* app) +{ +}; + +void control_init(instance_t* app) +{ +}; + +typedef struct player_handle_desc +{ + mvcp_parser parser; + mvcp command; + mvcp status; +} player_handle_t; + +int control_route(instance_t* app, control_buttons_t button) +{ + int i; + int idx, start, stop; + player_t *player; + player_handle_t* handle; + mvcp_error_code m; + + pthread_mutex_lock(&app->playlist.lock); + + idx = playlist_get_first_selected_item_idx(app); + + if(idx < 0) + { + pthread_mutex_unlock(&app->playlist.lock); + return -1; + }; + + g_warning("control_route: selected item is %d\n", idx); + + if(playlist_get_block(app, idx, &start, &stop) < 0) + { + pthread_mutex_unlock(&app->playlist.lock); + return -2; + }; + + g_warning("control_route: range %d -> %d\n", start, stop); + + player = playlist_get_player_at_pos(app, start); + + if(!player) + { + pthread_mutex_unlock(&app->playlist.lock); + return -3; + }; + + handle = player->handle; + + pthread_mutex_lock(&app->players.lock); + + if(BUTTON_PLAYER_STOP == button || BUTTON_PLAYER_CUE == button) + { + /* stop */ + mvcp_unit_stop(handle->command, player->unit); + + /* detach previous clips */ + player->playlist_length = -1; + mvcp_unit_clear(handle->command, player->unit); + }; + + if(BUTTON_PLAYER_CUE == button) + { + playlist_item_t* item; + int o, c, j; + + /* reset int_idx */ + for(i = start; i <= stop; i++) + app->playlist.item[i].int_idx = -1; + + /* Attach clips to timeline */ + for(i = 0, c = 0, o = 0; i < (stop - start + 1); i++) + { + /* calc seq to playlist grid */ + j = idx + i; + if(j > stop) + { + if(app->playlist.item[start].type & PLAYLIST_BLOCK_LOOP) + j = start + j - stop - 1; + else + continue; + }; + g_warning("control_route: i = %d, j = %d\n", i, j); + + item = &app->playlist.item[j]; + + /* append clip */ + m = mvcp_unit_append(handle->command, player->unit, + item->id, item->in, item->in + item->dur - 1); + + if(mvcp_ok != m) + { + g_warning("cue: failed with %d, %s\n", m, "unknown" /*OmPlrGetErrorString((OmPlrError)r)*/); + item->error |= PLAYLIST_ITEM_ERROR_CUE; + } + else + { + item->int_idx = i; + item->error &= 0xF ^ PLAYLIST_ITEM_ERROR_CUE; + c++; + }; + }; + + if(c) + { + mvcp_unit_pause(handle->command, player->unit); + + /* setup loop */ + if(app->playlist.item[start].type & PLAYLIST_BLOCK_LOOP) + mvcp_unit_set(handle->command, player->unit, "eof", "loop"); + else + mvcp_unit_set(handle->command, player->unit, "eof", "pause"); + + player->playlist_start = start; + player->playlist_length = stop - start + 1; + }; + }; + + if(BUTTON_PLAYER_PLAY == button) + /* play */ + mvcp_unit_play(handle->command, player->unit); + + if(BUTTON_PLAYER_PAUSE == button) + /* pause */ + mvcp_unit_pause(handle->command, player->unit); + + pthread_mutex_unlock(&app->players.lock); + + pthread_mutex_unlock(&app->playlist.lock); + + return 0; +};