ffmpeg versioning mods from Andrew
[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 // *** CONTEXT_HELP ***
179         context_help_set_keyword("Recording Immediately to Capture");
180 }
181
182 RecordGUIRec::~RecordGUIRec()
183 {
184 }
185
186 int RecordGUIRec::handle_event()
187 {
188         if( record_transport->record->cron_active() > 0 ) return 0;
189         unlock_window();
190         record_transport->start_writing_file();
191         lock_window("RecordGUIRec::handle_event");
192         return 1;
193 }
194
195 int RecordGUIRec::keypress_event()
196 {
197         return context_help_check_and_show();
198 }
199
200 RecordGUIRecFrame::RecordGUIRecFrame(RecordTransport *record_transport, int x, int y)
201  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("recframe"))
202 {
203         this->record_transport = record_transport;
204         set_tooltip(_("RecordTransport single frame"));
205 // *** CONTEXT_HELP ***
206         context_help_set_keyword("Recording Immediately to Capture");
207 }
208
209 RecordGUIRecFrame::~RecordGUIRecFrame()
210 {
211 }
212
213 int RecordGUIRecFrame::handle_event()
214 {
215         if( record_transport->record->cron_active() > 0 ) return 0;
216         unlock_window();
217         record_transport->start_writing_file(1);
218         lock_window("RecordGUIRecFrame::handle_event");
219         return 1;
220 }
221
222 int RecordGUIRecFrame::keypress_event()
223 {
224         return context_help_check_and_show();
225 }
226
227 RecordGUIPlay::RecordGUIPlay(RecordTransport *record_transport, int x, int y)
228  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("play"))
229 {
230         this->record_transport = record_transport;
231         set_tooltip(_("Preview recording"));
232 }
233
234 RecordGUIPlay::~RecordGUIPlay()
235 {
236 }
237
238 int RecordGUIPlay::handle_event()
239 {
240         unlock_window();
241         lock_window();
242         return 1;
243 }
244
245 int RecordGUIPlay::keypress_event()
246 {
247         return context_help_check_and_show();
248 }
249
250
251 RecordGUIStop::RecordGUIStop(RecordTransport *record_transport, int x, int y)
252  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("stoprec"))
253 {
254         this->record_transport = record_transport;
255         set_tooltip(_("Stop operation"));
256 // *** CONTEXT_HELP ***
257         context_help_set_keyword("Recording Immediately to Capture");
258 }
259
260 RecordGUIStop::~RecordGUIStop()
261 {
262 }
263
264 int RecordGUIStop::handle_event()
265 {
266         unlock_window();
267         record_transport->stop_writing();
268         lock_window("RecordGUIStop::handle_event");
269         return 1;
270 }
271
272 int RecordGUIStop::keypress_event()
273 {
274         return context_help_check_and_show();
275 }
276
277
278
279 RecordGUIPause::RecordGUIPause(RecordTransport *record_transport, int x, int y)
280  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("pause"))
281 {
282         this->record_transport = record_transport;
283         set_tooltip(_("Pause"));
284 }
285
286 RecordGUIPause::~RecordGUIPause()
287 {
288 }
289
290 int RecordGUIPause::handle_event()
291 {
292         return 1;
293 }
294
295 int RecordGUIPause::keypress_event()
296 {
297         return context_help_check_and_show();
298 }
299
300
301
302 RecordGUIRewind::RecordGUIRewind(RecordTransport *record_transport, int x, int y)
303  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("rewind"))
304 {
305         this->record_transport = record_transport;
306         set_tooltip(_("Start over"));
307 // *** CONTEXT_HELP ***
308         context_help_set_keyword("Recording Immediately to Capture");
309 }
310
311 RecordGUIRewind::~RecordGUIRewind()
312 {
313 }
314
315 int RecordGUIRewind::handle_event()
316 {
317         RecordGUI *record_gui = record_transport->record->record_gui;
318         if( !record_gui->startover_thread->running() )
319                 record_gui->startover_thread->start();
320         return 1;
321 }
322
323 int RecordGUIRewind::keypress_event()
324 {
325         return context_help_check_and_show();
326 }
327
328
329
330 RecordGUIBack::RecordGUIBack(RecordTransport *record_transport, int x, int y)
331  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("fastrev"))
332 {
333         this->record_transport = record_transport;
334         set_tooltip(_("Fast rewind"));
335         repeat_id = 257;
336 }
337
338 RecordGUIBack::~RecordGUIBack()
339 {
340 }
341
342 int RecordGUIBack::handle_event()
343 {
344         return 1;
345 }
346
347 int RecordGUIBack::button_press()
348 {
349         return 1;
350 }
351
352 int RecordGUIBack::button_release()
353 {
354         unset_repeat(repeat_id);
355         return 1;
356 }
357
358 int RecordGUIBack::repeat_event()
359 {
360 return 0;
361         return 1;
362 }
363
364 int RecordGUIBack::keypress_event()
365 {
366         return context_help_check_and_show();
367 }
368
369
370
371 RecordGUIFwd::RecordGUIFwd(RecordTransport *record_transport, int x, int y)
372  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("fastfwd"))
373 {
374         this->record_transport = record_transport;
375         set_tooltip(_("Fast forward"));
376         repeat_id = 255;
377 }
378
379 RecordGUIFwd::~RecordGUIFwd()
380 {
381 }
382
383 int RecordGUIFwd::handle_event()
384 {
385         return 1;
386 }
387
388 int RecordGUIFwd::button_press()
389 {
390         return 1;
391 }
392
393 int RecordGUIFwd::button_release()
394 {
395         unset_repeat(repeat_id);
396         return 1;
397 }
398
399 int RecordGUIFwd::repeat_event()
400 {
401         return 0;
402 }
403
404 int RecordGUIFwd::keypress_event()
405 {
406         return context_help_check_and_show();
407 }
408
409
410
411 RecordGUIEnd::RecordGUIEnd(RecordTransport *record_transport, int x, int y)
412  : BC_Button(x, y, record_transport->mwindow->theme->get_image_set("end"))
413 {
414         this->record_transport = record_transport;
415         set_tooltip(_("Seek to end of recording"));
416 }
417
418 RecordGUIEnd::~RecordGUIEnd()
419 {
420 }
421
422 int RecordGUIEnd::handle_event()
423 {
424         return 1;
425 }
426
427 int RecordGUIEnd::keypress_event()
428 {
429         return context_help_check_and_show();
430 }
431