4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcsignals.h"
25 #include "channelinfo.h"
27 #include "cplayback.h"
29 #include "ctracking.h"
31 #include "cwindowgui.h"
32 #include "cwindowtool.h"
36 #include "edlsession.h"
38 #include "localsession.h"
40 #include "mainsession.h"
43 #include "mwindowgui.h"
44 #include "playbackengine.h"
45 #include "playtransport.h"
46 #include "preferences.h"
47 #include "remotecontrol.h"
50 #include "trackcanvas.h"
52 #include "transportque.h"
58 CWindow::CWindow(MWindow *mwindow)
61 this->mwindow = mwindow;
67 if(gui && running()) {
72 delete playback_engine;
73 delete playback_cursor;
76 void CWindow::create_objects()
78 destination = mwindow->defaults->get("CWINDOW_DESTINATION", 0);
81 gui = new CWindowGUI(mwindow, this);
83 gui->create_objects();
86 playback_engine = new CPlayback(mwindow, this, gui->canvas);
90 playback_engine->create_objects();
92 gui->transport->set_engine(playback_engine);
94 playback_cursor = new CTracking(mwindow, this);
96 playback_cursor->create_objects();
101 void CWindow::show_window()
103 gui->lock_window("CWindow::show_cwindow");
107 gui->unlock_window();
109 gui->tool_panel->show_tool();
112 void CWindow::hide_window()
115 gui->mwindow->session->show_cwindow = 0;
116 // Unlock in case MWindow is waiting for it.
117 gui->unlock_window();
119 gui->tool_panel->hide_tool();
121 mwindow->gui->lock_window("CWindowGUI::close_event");
122 mwindow->gui->mainmenu->show_cwindow->set_checked(0);
123 mwindow->gui->unlock_window();
124 mwindow->save_defaults();
126 gui->lock_window("CWindow::hide_window");
130 Track* CWindow::calculate_affected_track()
132 Track* affected_track = 0;
133 for(Track *track = mwindow->edl->tracks->first;
137 if(track->data_type == TRACK_VIDEO &&
140 affected_track = track;
144 return affected_track;
147 Auto* CWindow::calculate_affected_auto(Autos *autos,
152 Auto* affected_auto = 0;
153 if(created) *created = 0;
157 int total = autos->total();
158 affected_auto = autos->get_auto_for_editing();
161 if(total != autos->total())
163 if(created) *created = 1;
166 // May have to unlock CWindowGUI here.
167 mwindow->gui->lock_window("CWindow::calculate_affected_auto");
168 mwindow->gui->draw_overlays(1);
169 mwindow->gui->unlock_window();
175 affected_auto = autos->get_prev_auto(PLAY_FORWARD, affected_auto);
178 return affected_auto;
183 void CWindow::calculate_affected_autos(FloatAuto **x_auto,
192 if(x_auto) (*x_auto) = 0;
193 if(y_auto) (*y_auto) = 0;
194 if(z_auto) (*z_auto) = 0;
200 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
201 track->automation->autos[AUTOMATION_CAMERA_X], create_x);
202 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
203 track->automation->autos[AUTOMATION_CAMERA_Y], create_y);
204 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
205 track->automation->autos[AUTOMATION_CAMERA_Z], create_z);
209 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
210 track->automation->autos[AUTOMATION_PROJECTOR_X], create_x);
211 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
212 track->automation->autos[AUTOMATION_PROJECTOR_Y], create_y);
213 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
214 track->automation->autos[AUTOMATION_PROJECTOR_Z], create_z);
218 void CWindow::stop_playback(int wait)
220 playback_engine->stop_playback(wait);
228 void CWindow::update(int position,
237 refresh_frame(CHANGE_NONE);
240 gui->lock_window("CWindow::update 2");
243 // Create tool window
246 gui->set_operation(mwindow->edl->session->cwindow_operation);
250 // Updated by video device.
251 if(overlays && !position)
253 gui->canvas->draw_refresh();
256 // Update tool parameters
257 // Never updated by someone else
258 if(tool_window || position)
265 gui->timebar->update(1);
268 double zoom = !mwindow->edl->session->cwindow_scrollbars ?
269 0 :mwindow->edl->session->cwindow_zoom;
270 gui->zoom_panel->update(zoom);
272 gui->canvas->update_zoom(mwindow->edl->session->cwindow_xscroll,
273 mwindow->edl->session->cwindow_yscroll,
274 mwindow->edl->session->cwindow_zoom);
275 gui->canvas->reposition_window(mwindow->edl,
276 mwindow->theme->ccanvas_x,
277 mwindow->theme->ccanvas_y,
278 mwindow->theme->ccanvas_w,
279 mwindow->theme->ccanvas_h);
284 gui->unlock_window();
291 int CWindow::update_position(double position)
293 gui->unlock_window();
295 playback_engine->interrupt_playback(1);
297 position = mwindow->edl->align_to_frame(position, 0);
298 position = MAX(0, position);
300 mwindow->gui->lock_window("CWindowSlider::handle_event 2");
301 mwindow->select_point(position);
302 mwindow->gui->unlock_window();
304 gui->lock_window("CWindow::update_position 1");
308 void CWindow::refresh_frame(int change_type, EDL *edl)
310 mwindow->refresh_mixers();
311 playback_engine->refresh_frame(change_type, edl);
314 void CWindow::refresh_frame(int change_type)
316 refresh_frame(change_type, mwindow->edl);
319 CWindowRemoteHandler::
320 CWindowRemoteHandler(RemoteControl *remote_control)
321 : RemoteHandler(remote_control->gui, RED)
326 CWindowRemoteHandler::
327 ~CWindowRemoteHandler()
331 int CWindowRemoteHandler::remote_process_key(RemoteControl *remote_control, int key)
333 MWindowGUI *mwindow_gui = remote_control->mwindow_gui;
334 EDL *edl = mwindow_gui->mwindow->edl;
336 PlayTransport *transport = mwindow_gui->mbuttons->transport;
337 if( !transport->get_edl() ) return 0;
338 PlaybackEngine *engine = transport->engine;
339 double position = engine->get_tracking_position();
340 double length = edl->tracks->total_length();
341 int next_command = -1, lastkey = last_key;
345 case '1': case '2': case '3': case '4':
346 case '5': case '6': case '7': case '8':
347 if( lastkey == 'e' ) {
348 mwindow_gui->mwindow->select_asset(key-'1', 1);
352 position = length * (key-'0')/10.0;
354 case UP: position += 60.0; break;
355 case DOWN: position -= 60.0; break;
356 case LEFT: position -= 10.0; break;
357 case RIGHT: position += 10.0; break;
358 case KPSTOP: next_command = STOP; break;
359 case KPREV: next_command = NORMAL_REWIND; break;
360 case KPPLAY: next_command = NORMAL_FWD; break;
361 case KPBACK: next_command = FAST_REWIND; break;
362 case KPFWRD: next_command = FAST_FWD; break;
363 case KPRECD: next_command = SLOW_REWIND; break;
364 case KPAUSE: next_command = SLOW_FWD; break;
365 case ' ': next_command = NORMAL_FWD; break;
366 case 'a': gui->tile_windows(0); return 1;
367 case 'b': gui->tile_windows(1); return 1;
368 case 'c': gui->tile_windows(2); return 1;
371 mwindow_gui->channel_info->toggle_scan();
377 Canvas *canvas = mwindow_gui->mwindow->cwindow->gui->canvas;
378 if( !canvas->get_fullscreen() )
379 canvas->start_fullscreen();
381 canvas->stop_fullscreen();
387 if( next_command < 0 ) {
388 if( position < 0 ) position = 0;
389 transport->change_position(position);
392 transport->handle_transport(next_command, 0, 0);