From: Maksym Veremeyenko Date: Mon, 9 Jul 2012 06:55:33 +0000 (+0300) Subject: add mvcp unit control X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=9638c3cc3c60587117673f7d1b821e8c960fe355;hp=ff7f700c3f8b82388b185d61293e36a28a24d448;p=melted_gui add mvcp unit control --- diff --git a/src/Makefile.am b/src/Makefile.am index bb6a338..2d74eaa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ melted_gui_SOURCES = \ player.c player.h \ playlist.c playlist.h \ library.c library.h \ + control.c control.h \ opts.c opts.h # \ # whois.c \ 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; +}; diff --git a/src/control.h b/src/control.h new file mode 100644 index 0000000..cc22598 --- /dev/null +++ b/src/control.h @@ -0,0 +1,39 @@ +/* + * control.h -- 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. + */ + +#ifndef CONTROL_H +#define CONTROL_H + +#include "instance.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +void control_init(instance_t* app); +void control_release(instance_t* app); +int control_route(instance_t* app, control_buttons_t btn); + + +#ifdef __cplusplus +}; +#endif /* __cplusplus */ + +#endif /* CONTROL_H */ diff --git a/src/instance.c b/src/instance.c index 6749c62..54a4bf6 100644 --- a/src/instance.c +++ b/src/instance.c @@ -39,6 +39,7 @@ #include "player.h" #include "library.h" #include "playlist.h" +#include "control.h" GtkTargetEntry drag_targets[] = { { (char*) "application/playlist_item_t", 0, 0 } }; @@ -159,10 +160,10 @@ static gboolean playlist_grid_key(GtkWidget *widget, GdkEventKey *event, gpointe }; break; case GDK_KEY_space: -// omnplay_ctl(app, BUTTON_PLAYER_PLAY); + control_route(app, BUTTON_PLAYER_PLAY); return TRUE; case GDK_KEY_Return: -// omnplay_ctl(app, BUTTON_PLAYER_CUE); + control_route(app, BUTTON_PLAYER_CUE); return TRUE; case GDK_KEY_Insert: // omnplay_playlist_item_add(app, 0); @@ -240,7 +241,7 @@ static gboolean instance_button_click(instance_t* app, control_buttons_t button) case BUTTON_PLAYER_PLAY: case BUTTON_PLAYER_PAUSE: case BUTTON_PLAYER_STOP: -// omnplay_ctl(app, button); + control_route(app, button); break; case BUTTON_LIBRARY_ADD: playlist_item_add_from_library(app, 0); diff --git a/src/instance.h b/src/instance.h index be3fa87..6dae179 100644 --- a/src/instance.h +++ b/src/instance.h @@ -113,7 +113,7 @@ typedef struct playlist_item int player; /**< player index that item currenly associated, -1 otherwise */ playlist_item_type_t type; /**< block type of item */ int int_idx; /**< internal playlist index */ - int omn_offset; +// int omn_offset; int error; /**< flag indicates if any error occured with item */ int del; /**< */ /*@}*/ diff --git a/src/player.c b/src/player.c index 77b32f5..206191b 100644 --- a/src/player.c +++ b/src/player.c @@ -117,7 +117,7 @@ static void player_update_status(player_t* player, mvcp_status_t *status_prev , tc_rem[0] = 0; /* for play and cue calc new value */ - if(status_curr->status == unit_stopped || status_curr->status == unit_playing || status_curr->status == unit_paused) + if(/*status_curr->status == unit_stopped || */ status_curr->status == unit_playing || status_curr->status == unit_paused) frames2tc(status_curr->out - status_curr->position, 25.0, tc_rem); /* setup that value */