prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / recordtransport.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 "asset.h"
23 #include "file.h"
24 #include "language.h"
25 #include "mwindow.h"
26 #include "record.h"
27 #include "recordgui.h"
28 #include "recordtransport.h"
29 #include "theme.h"
30 #include "units.h"
31
32
33 RecordTransport::RecordTransport(MWindow *mwindow, Record *record, 
34                 BC_WindowBase *window, int x, int y)
35 {
36         this->mwindow = mwindow;
37         this->record = record;
38         this->window = window;
39         this->x = x;
40         this->y = y;
41         record_active = 0;
42         play_active = 0;
43 }
44
45 void RecordTransport::create_objects()
46 {
47         int x = this->x, y = this->y;
48
49         window->add_subwindow(rewind_button = new RecordGUIRewind(this, x, y));
50         x += rewind_button->get_w();  y_end = y+rewind_button->get_h();
51         window->add_subwindow(record_button = new RecordGUIRec(this, x, y));
52         x += record_button->get_w();  y_end = max(y_end,y+record_button->get_h());
53         record_frame = 0;
54         if(record->default_asset->video_data) {
55                 window->add_subwindow(
56                         record_frame = new RecordGUIRecFrame(this, x, y));
57                 x += record_frame->get_w();  y_end = max(y_end,y+record_button->get_h());
58         }
59         window->add_subwindow(stop_button = new RecordGUIStop(this, x, y));
60         x += stop_button->get_w();  y_end = max(y_end,y+record_button->get_h());
61 //      window->add_subwindow(pause_button = new RecordGUIPause(this, x, y));
62 //      x += pause_button->get_w();  y_end = max(y_end,y+record_button->get_h());
63         x_end = x;
64
65 #if 0
66         x = this->x;  y = y_end;
67         window->add_subwindow(back_button = new RecordGUIBack(this, x, y));
68         x += back_button->get_w();  x_end = max(x, x_end);
69         y_end = max(y + back_button->get_h(), y_end);
70         window->add_subwindow(play_button = new RecordGUIPlay(this, x, y));
71         x += play_button->get_w();  x_end = max(x, x_end);
72         y_end = max(y + play_button->get_h(), y_end);
73         window->add_subwindow(fwd_button = new RecordGUIFwd(this, x, y));
74         x += fwd_button->get_w();  x_end = max(x, x_end);
75         y_end = max(y + fwd_button->get_h(), y_end);
76         window->add_subwindow(end_button = new RecordGUIEnd(this, x, y));
77         x += end_button->get_w();  x_end = max(x, x_end);
78         y_end = max(y + end_button->get_h(), y_end);
79 #endif
80         x_end += 10;  y_end += 10;
81 }
82
83 void RecordTransport::reposition_window(int x, int y)
84 {
85         this->x = x;  this->y = y;
86         rewind_button->reposition_window(x, y);
87         x += rewind_button->get_w();  y_end = y+rewind_button->get_h();
88         record_button->reposition_window(x, y);
89         x += record_button->get_w();  y_end = max(y_end,y+record_button->get_h());
90         if(record->default_asset->video_data) {
91                 record_frame->reposition_window(x, y);
92                 x += record_frame->get_w();  y_end = max(y_end,y+record_button->get_h());
93         }
94         stop_button->reposition_window(x, y);
95         x += stop_button->get_w();  y_end = max(y_end,y+record_button->get_h());
96 //      pause_button->reposition_window(x, y);
97 //      x += pause_button->get_w();  y_end = max(y_end,y+record_button->get_h());
98         x_end = x;
99
100 #if 0
101         x = this->x;  y = y_end;
102         back_button->reposition_window(x, y);
103         x += back_button->get_w();  x_end = max(x, x_end);
104         y_end = max(y + back_button->get_h(), y_end);
105         play_button->reposition_window(x, y);
106         x += play_button->get_w();  x_end = max(x, x_end);
107         y_end = max(y + play_button->get_h(), y_end);
108         fwd_button->reposition_window(x, y);
109         x += fwd_button->get_w();  x_end = max(x, x_end);
110         y_end = max(y + fwd_button->get_h(), y_end);
111         end_button->reposition_window(x, y);
112         x += end_button->get_w();  x_end = max(x, x_end);
113         y_end = max(y + end_button->get_h(), y_end);
114 #endif
115         x_end += 10;  y_end += 10;
116 }
117
118 int RecordTransport::get_h()
119 {
120         return y_end - y;
121 }
122
123 int RecordTransport::get_w()
124 {
125         return x_end - x;
126 }
127
128
129 RecordTransport::~RecordTransport()
130 {
131 }
132 void RecordTransport::
133 start_writing_file(int single_frame)
134 {
135         if( !record->writing_file ) {
136                 record->pause_input_threads();
137                 record->update_position();
138                 record->single_frame = single_frame;
139                 record->start_writing_file();
140                 record->resume_input_threads();
141         }
142 }
143
144 void RecordTransport::
145 stop_writing()
146 {
147         record->stop_cron_thread(_("Interrupted"));
148         record->stop_writing();
149 }
150
151 int RecordTransport::keypress_event()
152 {
153         if( record->cron_active() > 0 ) return 0;
154         if( window->get_keypress() == ' ' ) {
155 //printf("RecordTransport::keypress_event 1\n");
156                 if( record->writing_file ) {
157                         window->unlock_window();
158                         stop_writing();
159                         window->lock_window("RecordTransport::keypress_event 1");
160                 }
161                 else {
162                         window->unlock_window();
163                         start_writing_file();
164                         window->lock_window("RecordTransport::keypress_event 2");
165                 }
166 //printf("RecordTransport::keypress_event 2\n");
167                 return 1;
168         }
169         return 0;
170 }
171
172
173 RecordGUIRec::RecordGUIRec(RecordTransport *record_transport, int x, int y)
174  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("record"))
175 {
176         this->record_transport = record_transport;
177         set_tooltip(_("Start recording\nfrom current position"));
178 }
179
180 RecordGUIRec::~RecordGUIRec()
181 {
182 }
183
184 int RecordGUIRec::handle_event()
185 {
186         if( record_transport->record->cron_active() > 0 ) return 0;
187         unlock_window();
188         record_transport->start_writing_file();
189         lock_window("RecordGUIRec::handle_event");
190         return 1;
191 }
192
193 int RecordGUIRec::keypress_event()
194 {
195         return 0;
196 }
197
198 RecordGUIRecFrame::RecordGUIRecFrame(RecordTransport *record_transport, int x, int y)
199  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("recframe"))
200
201         this->record_transport = record_transport; 
202         set_tooltip(_("RecordTransport single frame"));
203 }
204
205 RecordGUIRecFrame::~RecordGUIRecFrame()
206 {
207 }
208
209 int RecordGUIRecFrame::handle_event()
210 {
211         if( record_transport->record->cron_active() > 0 ) return 0;
212         unlock_window();
213         record_transport->start_writing_file(1);
214         lock_window("RecordGUIRecFrame::handle_event");
215         return 1;
216 }
217
218 int RecordGUIRecFrame::keypress_event()
219 {
220         return 0;
221 }
222
223 RecordGUIPlay::RecordGUIPlay(RecordTransport *record_transport, int x, int y)
224  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("play"))
225
226         this->record_transport = record_transport; 
227         set_tooltip(_("Preview recording"));
228 }
229
230 RecordGUIPlay::~RecordGUIPlay()
231 {
232 }
233
234 int RecordGUIPlay::handle_event()
235 {
236         unlock_window();
237         lock_window();
238         return 1;
239 }
240
241 int RecordGUIPlay::keypress_event()
242 {
243         return 0;
244 }
245
246
247 RecordGUIStop::RecordGUIStop(RecordTransport *record_transport, int x, int y)
248  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("stoprec"))
249 {
250         this->record_transport = record_transport; 
251         set_tooltip(_("Stop operation"));
252 }
253
254 RecordGUIStop::~RecordGUIStop()
255 {
256 }
257
258 int RecordGUIStop::handle_event()
259 {
260         unlock_window();
261         record_transport->stop_writing();
262         lock_window("RecordGUIStop::handle_event");
263         return 1;
264 }
265
266 int RecordGUIStop::keypress_event()
267 {
268         return 0;
269 }
270
271
272
273 RecordGUIPause::RecordGUIPause(RecordTransport *record_transport, int x, int y)
274  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("pause"))
275 {
276         this->record_transport = record_transport; 
277         set_tooltip(_("Pause"));
278 }
279
280 RecordGUIPause::~RecordGUIPause()
281 {
282 }
283
284 int RecordGUIPause::handle_event()
285 {
286         return 1;
287 }
288
289 int RecordGUIPause::keypress_event()
290 {
291         return 0;
292 }
293
294
295
296 RecordGUIRewind::RecordGUIRewind(RecordTransport *record_transport, int x, int y)
297  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("rewind"))
298 {
299         this->record_transport = record_transport; 
300         set_tooltip(_("Start over"));
301 }
302
303 RecordGUIRewind::~RecordGUIRewind()
304 {
305 }
306
307 int RecordGUIRewind::handle_event()
308 {
309         RecordGUI *record_gui = record_transport->record->record_gui;
310         if( !record_gui->startover_thread->running() )
311                 record_gui->startover_thread->start();
312         return 1;
313 }
314
315 int RecordGUIRewind::keypress_event()
316 {
317         return 0;
318 }
319
320
321
322 RecordGUIBack::RecordGUIBack(RecordTransport *record_transport, int x, int y)
323  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("fastrev"))
324
325         this->record_transport = record_transport; 
326         set_tooltip(_("Fast rewind"));
327 }
328
329 RecordGUIBack::~RecordGUIBack()
330 {
331 }
332
333 int RecordGUIBack::handle_event()
334 {
335         return 1;
336 }
337
338 int RecordGUIBack::button_press()
339 {
340         return 1;
341 }
342
343 int RecordGUIBack::button_release()
344 {
345         unset_repeat(repeat_id);
346         return 1;
347 }
348
349 int RecordGUIBack::repeat_event()
350 {
351 return 0;
352         return 1;
353 }
354
355 int RecordGUIBack::keypress_event()
356 {
357         return 0;
358 }
359
360
361
362 RecordGUIFwd::RecordGUIFwd(RecordTransport *record_transport, int x, int y)
363  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("fastfwd"))
364
365         this->record_transport = record_transport; 
366         set_tooltip(_("Fast forward"));
367 }
368
369 RecordGUIFwd::~RecordGUIFwd()
370 {
371 }
372
373 int RecordGUIFwd::handle_event()
374 {
375         return 1;
376 }
377
378 int RecordGUIFwd::button_press()
379 {
380         return 1;
381 }
382
383 int RecordGUIFwd::button_release()
384 {
385         unset_repeat(repeat_id);
386         return 1;
387 }
388
389 int RecordGUIFwd::repeat_event()
390 {
391         return 0;
392 }
393
394 int RecordGUIFwd::keypress_event()
395 {
396         return 0;
397 }
398
399
400
401 RecordGUIEnd::RecordGUIEnd(RecordTransport *record_transport, int x, int y)
402  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("end"))
403
404         this->record_transport = record_transport; 
405         set_tooltip(_("Seek to end of recording"));
406 }
407
408 RecordGUIEnd::~RecordGUIEnd()
409 {
410 }
411
412 int RecordGUIEnd::handle_event()
413 {
414         return 1;
415 }
416
417 int RecordGUIEnd::keypress_event()
418 {
419         return 0;
420 }
421