add new boxblur plugin, mods to videoscope, fix segv for menu btns kfrm-tweak/kfrm...
[goodguy/cinelerra.git] / cinelerra-5.1 / 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 += xS(10);  y_end += yS(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 += xS(10);  y_end += yS(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         repeat_id = 257;
328 }
329
330 RecordGUIBack::~RecordGUIBack()
331 {
332 }
333
334 int RecordGUIBack::handle_event()
335 {
336         return 1;
337 }
338
339 int RecordGUIBack::button_press()
340 {
341         return 1;
342 }
343
344 int RecordGUIBack::button_release()
345 {
346         unset_repeat(repeat_id);
347         return 1;
348 }
349
350 int RecordGUIBack::repeat_event()
351 {
352 return 0;
353         return 1;
354 }
355
356 int RecordGUIBack::keypress_event()
357 {
358         return 0;
359 }
360
361
362
363 RecordGUIFwd::RecordGUIFwd(RecordTransport *record_transport, int x, int y)
364  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("fastfwd"))
365 {
366         this->record_transport = record_transport;
367         set_tooltip(_("Fast forward"));
368         repeat_id = 255;
369 }
370
371 RecordGUIFwd::~RecordGUIFwd()
372 {
373 }
374
375 int RecordGUIFwd::handle_event()
376 {
377         return 1;
378 }
379
380 int RecordGUIFwd::button_press()
381 {
382         return 1;
383 }
384
385 int RecordGUIFwd::button_release()
386 {
387         unset_repeat(repeat_id);
388         return 1;
389 }
390
391 int RecordGUIFwd::repeat_event()
392 {
393         return 0;
394 }
395
396 int RecordGUIFwd::keypress_event()
397 {
398         return 0;
399 }
400
401
402
403 RecordGUIEnd::RecordGUIEnd(RecordTransport *record_transport, int x, int y)
404  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("end"))
405 {
406         this->record_transport = record_transport;
407         set_tooltip(_("Seek to end of recording"));
408 }
409
410 RecordGUIEnd::~RecordGUIEnd()
411 {
412 }
413
414 int RecordGUIEnd::handle_event()
415 {
416         return 1;
417 }
418
419 int RecordGUIEnd::keypress_event()
420 {
421         return 0;
422 }
423