hard edges rework, add hard edge in gwdw, config.ac nv/cuda tweaks, message log warn...
[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
54 #include <unistd.h>
55
56
57
58 CWindow::CWindow(MWindow *mwindow)
59  : Thread(1, 0, 0)
60 {
61         this->mwindow = mwindow;
62         this->playback_engine = 0;
63         this->playback_cursor = 0;
64         this->gui = 0;
65 }
66
67
68 CWindow::~CWindow()
69 {
70         if(gui && running()) {
71                 gui->set_done(0);
72         }
73         join();
74         delete gui;  gui = 0;
75         delete playback_engine;
76         delete playback_cursor;
77 }
78
79 void CWindow::create_objects()
80 {
81         destination = mwindow->defaults->get("CWINDOW_DESTINATION", 0);
82
83
84         gui = new CWindowGUI(mwindow, this);
85
86         gui->create_objects();
87
88
89         playback_engine = new CPlayback(mwindow, this, gui->canvas);
90
91
92 // Start command loop
93         playback_engine->create_objects();
94
95         gui->transport->set_engine(playback_engine);
96
97         playback_cursor = new CTracking(mwindow, this);
98
99         playback_cursor->create_objects();
100
101 }
102
103
104 void CWindow::show_window()
105 {
106         gui->lock_window("CWindow::show_cwindow");
107         gui->show_window();
108         gui->raise_window();
109         gui->flush();
110         gui->unlock_window();
111
112         gui->tool_panel->show_tool();
113 }
114
115 void CWindow::hide_window()
116 {
117         gui->hide_window();
118         gui->mwindow->session->show_cwindow = 0;
119 // Unlock in case MWindow is waiting for it.
120         gui->unlock_window();
121
122         gui->tool_panel->hide_tool();
123
124         mwindow->gui->lock_window("CWindowGUI::close_event");
125         mwindow->gui->mainmenu->show_cwindow->set_checked(0);
126         mwindow->gui->unlock_window();
127         mwindow->save_defaults();
128
129         gui->lock_window("CWindow::hide_window");
130 }
131
132
133 Track* CWindow::calculate_affected_track()
134 {
135         Track* affected_track = 0;
136         for(Track *track = mwindow->edl->tracks->first;
137                 track;
138                 track = track->next)
139         {
140                 if(track->data_type == TRACK_VIDEO &&
141                         track->record)
142                 {
143                         affected_track = track;
144                         break;
145                 }
146         }
147         return affected_track;
148 }
149
150 Auto* CWindow::calculate_affected_auto(Autos *autos,
151                 int create, int *created, int redraw)
152 {
153         Auto* affected_auto = 0;
154         if( created ) *created = 0;
155
156         if( create ) {
157                 int total = autos->total();
158                 affected_auto = autos->get_auto_for_editing(-1, create);
159
160 // Got created
161                 if( total != autos->total() ) {
162                         if( created ) *created = 1;
163                         if( redraw ) {
164 // May have to unlock CWindowGUI here.
165                                 mwindow->gui->lock_window("CWindow::calculate_affected_auto");
166                                 mwindow->gui->draw_overlays(1);
167                                 mwindow->gui->unlock_window();
168                         }
169                 }
170         }
171         else {
172                 affected_auto = autos->get_prev_auto(PLAY_FORWARD, affected_auto);
173         }
174
175         return affected_auto;
176 }
177
178
179
180 void CWindow::calculate_affected_autos(Track *track,
181                 FloatAuto **x_auto, FloatAuto **y_auto, FloatAuto **z_auto,
182                 int use_camera, int create_x, int create_y, int create_z,
183                 int redraw)
184 {
185         if( x_auto ) *x_auto = 0;
186         if( y_auto ) *y_auto = 0;
187         if( z_auto ) *z_auto = 0;
188         if( !track ) return;
189
190         int ix = use_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X, x_created = 0;
191         int iy = use_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y, y_created = 0;
192         int iz = use_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z, z_created = 0;
193
194         if( x_auto )
195                 *x_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[ix],
196                                 create_x, &x_created, redraw);
197         if( y_auto )
198                 *y_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[iy],
199                                 create_y, &y_created, redraw);
200         if( z_auto ) *z_auto = (FloatAuto*) calculate_affected_auto(track->automation->autos[iz],
201                                 create_z, &z_created, redraw);
202 }
203
204 void CWindow::stop_playback(int wait)
205 {
206         playback_engine->stop_playback(wait);
207 }
208
209 void CWindow::run()
210 {
211         gui->run_window();
212 }
213
214 void CWindow::update(int dir, int overlays, int tool_window, int operation, int timebar)
215 {
216
217         if( dir )
218                 refresh_frame(CHANGE_NONE, dir);
219
220         gui->lock_window("CWindow::update 2");
221 // Create tool window
222         if( operation )
223                 gui->set_operation(mwindow->edl->session->cwindow_operation);
224
225 // Updated by video device.
226         if( overlays && !dir )
227                 gui->canvas->refresh(1);
228
229 // Update tool parameters
230 // Never updated by someone else
231         if( tool_window || dir )
232                 gui->update_tool();
233
234         if( timebar )
235                 gui->timebar->update(1);
236
237         double zoom = !mwindow->edl->session->cwindow_scrollbars ?
238                 0 :mwindow->edl->session->cwindow_zoom;
239         gui->zoom_panel->update(zoom);
240
241         gui->canvas->update_zoom(mwindow->edl->session->cwindow_xscroll,
242                         mwindow->edl->session->cwindow_yscroll,
243                         mwindow->edl->session->cwindow_zoom);
244         gui->canvas->update_geometry(mwindow->edl,
245                         mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
246                         mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
247
248         gui->unlock_window();
249 }
250
251 int CWindow::update_position(double position)
252 {
253         gui->unlock_window();
254
255         playback_engine->interrupt_playback(1);
256
257         position = mwindow->edl->align_to_frame(position, 0);
258         position = MAX(0, position);
259
260         mwindow->gui->lock_window("CWindowSlider::handle_event 2");
261         mwindow->select_point(position);
262         mwindow->gui->unlock_window();
263
264         gui->lock_window("CWindow::update_position 1");
265         return 1;
266 }
267
268 void CWindow::refresh_frame(int change_type, EDL *edl, int dir)
269 {
270         mwindow->refresh_mixers(dir);
271         playback_engine->refresh_frame(change_type, edl, dir);
272 }
273
274 void CWindow::refresh_frame(int change_type, int dir)
275 {
276         refresh_frame(change_type, mwindow->edl, dir);
277 }
278
279 CWindowRemoteHandler::
280 CWindowRemoteHandler(RemoteControl *remote_control)
281  : RemoteHandler(remote_control->gui, RED)
282 {
283         last_key = -1;
284 }
285
286 CWindowRemoteHandler::
287 ~CWindowRemoteHandler()
288 {
289 }
290
291 int CWindowRemoteHandler::remote_process_key(RemoteControl *remote_control, int key)
292 {
293         MWindowGUI *mwindow_gui = remote_control->mwindow_gui;
294         EDL *edl = mwindow_gui->mwindow->edl;
295         if( !edl ) return 0;
296         PlayTransport *transport = mwindow_gui->mbuttons->transport;
297         if( !transport->get_edl() ) return 0;
298         PlaybackEngine *engine = transport->engine;
299         double position = engine->get_tracking_position();
300         double length = edl->tracks->total_length();
301         int next_command = -1, lastkey = last_key;
302         last_key = key;
303
304         switch( key ) {
305         case '1': case '2': case '3': case '4':
306         case '5': case '6': case '7': case '8':
307                 if( lastkey == 'e' ) {
308                         mwindow_gui->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':  gui->tile_windows(0);                return 1;
327         case 'b':  gui->tile_windows(1);                return 1;
328         case 'c':  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                 Canvas *canvas = mwindow_gui->mwindow->cwindow->gui->canvas;
338                 if( !canvas->get_fullscreen() )
339                         canvas->start_fullscreen();
340                 else
341                         canvas->stop_fullscreen();
342                 return 1; }
343         default:
344                 return -1;
345         }
346
347         if( next_command < 0 ) {
348                 if( position < 0 ) position = 0;
349                 transport->change_position(position);
350         }
351         else
352                 transport->handle_transport(next_command);
353         return 1;
354 }
355