wintv remote control + kernel patch, add codec fileref, amp up OpenEDL, add loadmode...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "autos.h"
23 #include "bchash.h"
24 #include "bcsignals.h"
25 #include "channelinfo.h"
26 #include "clip.h"
27 #include "cplayback.h"
28 #include "ctimebar.h"
29 #include "ctracking.h"
30 #include "cwindow.h"
31 #include "cwindowgui.h"
32 #include "cwindowtool.h"
33 #include "edl.h"
34 #include "keys.h"
35 #include "edl.h"
36 #include "edlsession.h"
37 #include "language.h"
38 #include "localsession.h"
39 #include "mainmenu.h"
40 #include "mainsession.h"
41 #include "mbuttons.h"
42 #include "mwindow.h"
43 #include "mwindowgui.h"
44 #include "playbackengine.h"
45 #include "playtransport.h"
46 #include "preferences.h"
47 #include "remotecontrol.h"
48 #include "theme.h"
49 #include "track.h"
50 #include "trackcanvas.h"
51 #include "tracks.h"
52 #include "transportque.h"
53 #include "wintv.h"
54
55 #include <unistd.h>
56
57
58
59 CWindow::CWindow(MWindow *mwindow)
60  : Thread(1, 0, 0)
61 {
62         this->mwindow = mwindow;
63         this->playback_engine = 0;
64         this->playback_cursor = 0;
65         this->mask_track_id = -1;
66         this->gui = 0;
67 }
68
69
70 CWindow::~CWindow()
71 {
72         if(gui && running()) {
73                 gui->set_done(0);
74         }
75         join();
76         delete gui;  gui = 0;
77         delete playback_engine;
78         delete playback_cursor;
79 }
80
81 void CWindow::create_objects()
82 {
83         gui = new CWindowGUI(mwindow, this);
84         gui->create_objects();
85         playback_engine = new CPlayback(mwindow, this, gui->canvas);
86 // Start command loop
87         playback_engine->create_objects();
88         gui->transport->set_engine(playback_engine);
89         playback_cursor = new CTracking(mwindow, this);
90         playback_cursor->create_objects();
91 }
92
93
94 void CWindow::show_window()
95 {
96         gui->lock_window("CWindow::show_cwindow");
97         gui->show_window();
98         gui->raise_window();
99         gui->flush();
100         gui->unlock_window();
101
102         gui->tool_panel->show_tool();
103 }
104
105 void CWindow::hide_window()
106 {
107         gui->hide_window();
108         gui->mwindow->session->show_cwindow = 0;
109 // Unlock in case MWindow is waiting for it.
110         gui->unlock_window();
111
112         gui->tool_panel->hide_tool();
113
114         mwindow->gui->lock_window("CWindowGUI::close_event");
115         mwindow->gui->mainmenu->show_cwindow->set_checked(0);
116         mwindow->gui->unlock_window();
117         mwindow->save_defaults();
118
119         gui->lock_window("CWindow::hide_window");
120 }
121
122
123 Track* CWindow::calculate_affected_track()
124 {
125         Track *track = mwindow->edl->tracks->first;
126         for( ; track; track=track->next ) {
127                 if( track->data_type != TRACK_VIDEO ) continue;
128                 if( track->record ) break;
129         }
130         return track;
131 }
132
133 Track* CWindow::calculate_mask_track()
134 {
135         Track *track = mwindow->edl->tracks->first;
136         for( ; track; track=track->next ) {
137                 if( track->data_type != TRACK_VIDEO ) continue;
138                 if( track->record && track->get_id() == mask_track_id ) break;
139         }
140         return track;
141 }
142
143
144 Auto* CWindow::calculate_affected_auto(Autos *autos,
145                 int create, int *created, int redraw)
146 {
147         Auto* affected_auto = 0;
148         if( created ) *created = 0;
149
150         if( create ) {
151                 int total = autos->total();
152                 affected_auto = autos->get_auto_for_editing(-1, create);
153
154 // Got created
155                 if( total != autos->total() ) {
156                         if( created ) *created = 1;
157                         if( redraw ) {
158 // May have to unlock CWindowGUI here.
159                                 mwindow->gui->lock_window("CWindow::calculate_affected_auto");
160                                 mwindow->gui->draw_overlays(1);
161                                 mwindow->gui->unlock_window();
162                         }
163                 }
164         }
165         else {
166                 affected_auto = autos->get_prev_auto(PLAY_FORWARD, affected_auto);
167         }
168
169         return affected_auto;
170 }
171
172
173
174 void CWindow::calculate_affected_autos(Track *track,
175                 FloatAuto **x_auto, FloatAuto **y_auto, FloatAuto **z_auto,
176                 int use_camera, int create_x, int create_y, int create_z,
177                 int redraw)
178 {
179         if( x_auto ) *x_auto = 0;
180         if( y_auto ) *y_auto = 0;
181         if( z_auto ) *z_auto = 0;
182         if( !track ) return;
183
184         int ix = use_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X, x_created = 0;
185         int iy = use_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y, y_created = 0;
186         int iz = use_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z, z_created = 0;
187
188         if( x_auto )
189                 *x_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[ix],
190                                 create_x, &x_created, redraw);
191         if( y_auto )
192                 *y_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[iy],
193                                 create_y, &y_created, redraw);
194         if( z_auto ) *z_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[iz],
195                                 create_z, &z_created, redraw);
196 }
197
198 void CWindow::stop_playback(int wait)
199 {
200         playback_engine->stop_playback(wait);
201 }
202
203 void CWindow::run()
204 {
205         gui->run_window();
206 }
207
208 void CWindow::update(int dir, int overlays, int tool_window, int operation, int timebar)
209 {
210
211         if( dir )
212                 refresh_frame(CHANGE_NONE, dir);
213
214         gui->lock_window("CWindow::update 2");
215 // Create tool window
216         if( operation )
217                 gui->set_operation(mwindow->edl->session->cwindow_operation);
218
219 // Updated by video device.
220         if( overlays && !dir )
221                 gui->canvas->refresh(1);
222
223 // Update tool parameters
224 // Never updated by someone else
225         if( tool_window || dir )
226                 gui->update_tool();
227
228         if( timebar )
229                 gui->timebar->update(1);
230
231         double zoom = !mwindow->edl->session->cwindow_scrollbars ?
232                 0 : mwindow->edl->session->cwindow_zoom;
233         gui->zoom_panel->update(zoom);
234
235         gui->canvas->update_zoom(mwindow->edl->session->cwindow_xscroll,
236                         mwindow->edl->session->cwindow_yscroll,
237                         mwindow->edl->session->cwindow_zoom);
238         gui->canvas->update_geometry(mwindow->edl,
239                         mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
240                         mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
241
242         gui->unlock_window();
243 }
244
245 int CWindow::update_position(double position)
246 {
247         gui->unlock_window();
248
249         playback_engine->interrupt_playback(1);
250
251         position = mwindow->edl->align_to_frame(position, 0);
252         position = MAX(0, position);
253
254         mwindow->gui->lock_window("CWindowSlider::handle_event 2");
255         mwindow->select_point(position);
256         mwindow->gui->unlock_window();
257
258         gui->lock_window("CWindow::update_position 1");
259         return 1;
260 }
261
262 void CWindow::refresh_frame(int change_type, EDL *edl, int dir)
263 {
264         mwindow->refresh_mixers(dir);
265         playback_engine->refresh_frame(change_type, edl, dir);
266 }
267
268 void CWindow::refresh_frame(int change_type, int dir)
269 {
270         refresh_frame(change_type, mwindow->edl, dir);
271 }
272
273 CWindowRemoteHandler::
274 CWindowRemoteHandler(RemoteControl *remote_control)
275  : RemoteHandler(remote_control->gui, RED)
276 {
277         this->remote_control = remote_control;
278         this->mwindow = remote_control->mwindow_gui->mwindow;
279         last_key = -1;
280         key = -1;
281 }
282
283 CWindowRemoteHandler::
284 ~CWindowRemoteHandler()
285 {
286 }
287
288 int CWindowRemoteHandler::process_key(int key)
289 {
290         return remote_process_key(remote_control, key);
291 }
292
293 int CWindowRemoteHandler::remote_process_key(RemoteControl *remote_control, int key)
294 {
295         EDL *edl = mwindow->edl;
296         if( !edl ) return 0;
297         PlayTransport *transport = mwindow->gui->mbuttons->transport;
298         if( !transport->get_edl() ) return 0;
299         PlaybackEngine *engine = transport->engine;
300         double position = engine->get_tracking_position();
301         double length = edl->tracks->total_length();
302         int next_command = -1;
303
304         switch( key ) {
305         case '1': case '2': case '3': case '4':
306         case '5': case '6': case '7': case '8':
307                 if( last_key == 'e' ) {
308                         mwindow->select_asset(key-'1', 1);
309                         break;
310                 } // fall through
311         case '0': case '9':
312                 position = length * (key-'0')/10.0;
313                 break;
314         case UP:      position += 60.0;                 break;
315         case DOWN:    position -= 60.0;                 break;
316         case LEFT:    position -= 10.0;                 break;
317         case RIGHT:   position += 10.0;                 break;
318         case KPSTOP:  next_command = STOP;              break;
319         case KPREV:   next_command = NORMAL_REWIND;     break;
320         case KPPLAY:  next_command = NORMAL_FWD;        break;
321         case KPBACK:  next_command = FAST_REWIND;       break;
322         case KPFWRD:  next_command = FAST_FWD;          break;
323         case KPRECD:  next_command = SLOW_REWIND;       break;
324         case KPAUSE:  next_command = SLOW_FWD;          break;
325         case ' ':  next_command = NORMAL_FWD;           break;
326         case 'a':  remote_control->gui->tile_windows(0);  return 1;
327         case 'b':  remote_control->gui->tile_windows(1);  return 1;
328         case 'c':  remote_control->gui->tile_windows(2);  return 1;
329 #ifdef HAVE_DVB
330         case 'd':
331                 mwindow->gui->channel_info->toggle_scan();
332                 return 1;
333 #endif
334         case 'e':
335                 break;
336         case 'f': {
337                 CWindowCanvas *canvas = mwindow->cwindow->gui->canvas;
338                 int on = canvas->get_fullscreen() ? 0 : 1;
339                 canvas->Canvas::set_fullscreen(on, 0);
340                 return 1; }
341         default:
342                 return -1;
343         }
344
345         if( next_command < 0 ) {
346                 if( position < 0 ) position = 0;
347                 transport->change_position(position);
348         }
349         else
350                 transport->handle_transport(next_command);
351         return 1;
352 }
353