add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / recordprefs.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2013 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 "adeviceprefs.h"
23 #include "asset.h"
24 #include "audioconfig.h"
25 #include "clip.h"
26 #include "edl.h"
27 #include "edlsession.h"
28 #include "formattools.h"
29 #include "new.h"
30 #include "language.h"
31 #include "mwindow.h"
32 #include "preferences.h"
33 #include "recordconfig.h"
34 #include "recordprefs.h"
35 #include "theme.h"
36 #include "vdeviceprefs.h"
37
38
39
40
41 RecordPrefs::RecordPrefs(MWindow *mwindow, PreferencesWindow *pwindow)
42  : PreferencesDialog(mwindow, pwindow)
43 {
44         this->mwindow = mwindow;
45 // *** CONTEXT_HELP ***
46         context_help_set_keyword("Recording");
47 }
48
49 RecordPrefs::~RecordPrefs()
50 {
51         delete audio_in_device;
52         delete video_in_device;
53         delete recording_format;
54 //      delete duplex_device;
55 }
56
57 void RecordPrefs::create_objects()
58 {
59         int xs5 = xS(5), xs10 = xS(10), xs30 = xS(30);
60         int ys5 = yS(5), ys27 = yS(27), ys30 = yS(30);
61         int x, y, x1, x2;
62         char string[BCTEXTLEN];
63         BC_Resources *resources = BC_WindowBase::get_resources();
64         BC_Title *title;
65         BC_Title *title0, *title1, *title2, *title3;
66         BC_TextBox *textbox;
67
68         x = mwindow->theme->preferencesoptions_x;
69         y = mwindow->theme->preferencesoptions_y;
70         int margin = mwindow->theme->widget_border;
71         int x0 = x, y0 = y;
72
73         add_subwindow(title = new BC_Title(x, y, _("File Format:"),
74                 LARGEFONT, resources->text_default));
75         title->context_help_set_keyword("File Format section");
76         y += title->get_h() + margin;
77
78         recording_format = new FormatTools(mwindow, this,
79                         pwindow->thread->edl->session->recording_format);
80
81         recording_format->create_objects(x, y,
82                 1,  // Include tools for audio
83                 1,  // Include tools for video
84                 1,  // Include checkbox for audio
85                 1,  // Include checkbox for video
86                 0,
87                 1,
88                 0,  // Select compressors to be offered
89                 1,  // Prompt for recording options
90                 0,  // prompt for use labels
91                 0); // Supply file formats for background rendering
92
93         realtime_toc = new RecordRealtimeTOC(mwindow, pwindow,
94                 x0+xS(400), y0, pwindow->thread->edl->session->record_realtime_toc);
95         add_subwindow(realtime_toc);
96         realtime_toc->context_help_set_keyword("File Format section");
97
98 // Audio hardware
99         add_subwindow(new BC_Bar(x, y,  get_w() - x * 2));
100         y += margin;
101
102
103         add_subwindow(title = new BC_Title(x, y,
104                 _("Audio In"), LARGEFONT,
105                 resources->text_default));
106         title->context_help_set_keyword("Audio In section");
107
108         y += title->get_h() + margin;
109
110         add_subwindow(title = new BC_Title(x, y, _("Record Driver:"),
111                 MEDIUMFONT, resources->text_default));
112         title->context_help_set_keyword("Audio In section");
113         audio_in_device = new ADevicePrefs(x + xS(110), y, pwindow, this, 0,
114                 pwindow->thread->edl->session->aconfig_in, MODERECORD);
115         audio_in_device->initialize(1);
116         y += audio_in_device->get_h(1) + margin;
117
118
119         int pad = RecordWriteLength::calculate_h(this,
120                 MEDIUMFONT, 1, 1) + mwindow->theme->widget_border;
121         add_subwindow(title0 = new BC_Title(x, y, _("Samples read from device:")));
122         title0->context_help_set_keyword("Audio In section");
123         add_subwindow(title1 = new BC_Title(x, y + pad, _("Samples to write to disk:")));
124         title1->context_help_set_keyword("Audio In section");
125         add_subwindow(title2 = new BC_Title(x, y + pad * 2, _("Sample rate for recording:")));
126         title2->context_help_set_keyword("Audio In section");
127         add_subwindow(title3 = new BC_Title(x, y + pad * 3, _("Channels to record:")));
128         title3->context_help_set_keyword("Audio In section");
129         x2 = MAX(title0->get_w(), title1->get_w()) + margin;
130         x2 = MAX(x2, title2->get_w() + margin);
131         x2 = MAX(x2, title3->get_w() + margin);
132
133
134         sprintf(string, "%ld", (long)pwindow->thread->edl->session->record_fragment_size);
135         RecordFragment *menu;
136         add_subwindow(menu = new RecordFragment(x2, y, pwindow, this, string));
137         y += menu->get_h() + mwindow->theme->widget_border;
138         menu->add_item(new BC_MenuItem("1024"));
139         menu->add_item(new BC_MenuItem("2048"));
140         menu->add_item(new BC_MenuItem("4096"));
141         menu->add_item(new BC_MenuItem("8192"));
142         menu->add_item(new BC_MenuItem("16384"));
143         menu->add_item(new BC_MenuItem("32768"));
144         menu->add_item(new BC_MenuItem("65536"));
145         menu->add_item(new BC_MenuItem("131072"));
146         menu->add_item(new BC_MenuItem("262144"));
147         menu->context_help_set_keyword("Audio In section");
148
149         sprintf(string, "%jd", pwindow->thread->edl->session->record_write_length);
150         add_subwindow(textbox = new RecordWriteLength(mwindow, pwindow, x2, y, string));
151         textbox->context_help_set_keyword("Audio In section");
152         y += textbox->get_h() + mwindow->theme->widget_border;
153         add_subwindow(textbox = new RecordSampleRate(pwindow, x2, y));
154         textbox->context_help_set_keyword("Audio In section");
155         add_subwindow(new SampleRatePulldown(mwindow, textbox, x2 + textbox->get_w(), y));
156         y += textbox->get_h() + mwindow->theme->widget_border;
157
158         RecordChannels *channels = new RecordChannels(pwindow, this, x2, y);
159         channels->create_objects();
160         y += channels->get_h() + mwindow->theme->widget_border;
161
162         RecordMap51_2 *record_map51_2 = new RecordMap51_2(mwindow, pwindow, x, y,
163                 pwindow->thread->edl->session->aconfig_in->map51_2);
164         add_subwindow(record_map51_2);
165         record_map51_2->context_help_set_keyword("Audio In section");
166
167         x2 = x + record_map51_2->get_w() + xs30;
168         int y2 = y + BC_TextBox::calculate_h(this,MEDIUMFONT,1,1) - get_text_height(MEDIUMFONT);
169         add_subwindow(title = new BC_Title(x2, y2, _("Gain:")));
170         title->context_help_set_keyword("Audio In section");
171         x2 += title->get_w() + xS(8);
172         RecordGain *rec_gain = new RecordGain(pwindow, this, x2, y);
173         rec_gain->create_objects();
174
175         x2 += rec_gain->get_w() + xs30;
176         add_subwindow(new RecordRealTime(mwindow, pwindow, x2, y,
177                 pwindow->thread->edl->session->real_time_record));
178         y += ys30;
179         x = xs5;
180
181
182 // Video hardware
183         add_subwindow(new BC_Bar(xs5, y, get_w() - xs10));
184         y += margin;
185
186         add_subwindow(title1 = new BC_Title(x, y, _("Video In"), LARGEFONT,
187                 resources->text_default));
188         title1->context_help_set_keyword("Video In section");
189         y += title1->get_h() + margin;
190
191         add_subwindow(title1 = new BC_Title(x, y, _("Record Driver:"), MEDIUMFONT,
192                 resources->text_default));
193         title1->context_help_set_keyword("Video In section");
194         video_in_device = new VDevicePrefs(x + title1->get_w() + margin, y,
195                 pwindow, this, 0, pwindow->thread->edl->session->vconfig_in, MODERECORD);
196         video_in_device->initialize(1);
197         y += video_in_device->get_h() + margin;
198
199         add_subwindow(title1 = new BC_Title(x, y, _("Frames to record to disk at a time:")));
200         title1->context_help_set_keyword("Video In section");
201         x1 = x + title1->get_w() + margin;
202         sprintf(string, "%d", pwindow->thread->edl->session->video_write_length);
203         add_subwindow(textbox = new VideoWriteLength(pwindow, string, x1, y));
204         textbox->context_help_set_keyword("Video In section");
205         x1 += textbox->get_w() + margin;
206         add_subwindow(new CaptureLengthTumbler(pwindow, textbox, x1, y));
207         y += ys27;
208
209         add_subwindow(title1 = new BC_Title(x, y, _("Frames to buffer in device:")));
210         title1->context_help_set_keyword("Video In section");
211         x1 = x + title1->get_w() + margin;
212         sprintf(string, "%d", pwindow->thread->edl->session->vconfig_in->capture_length);
213         add_subwindow(textbox = new VideoCaptureLength(pwindow, string, x1, y));
214         textbox->context_help_set_keyword("Video In section");
215         x1 += textbox->get_w() + margin;
216         add_subwindow(new CaptureLengthTumbler(pwindow, textbox, x1, y));
217         y += ys27;
218
219         x1 = x;
220         add_subwindow(title1 = new BC_Title(x1, y, _("Positioning:")));
221         title1->context_help_set_keyword("Video In section");
222         x1 += xS(120);
223         add_subwindow(textbox = new BC_TextBox(x1, y, xS(200), 1, ""));
224         textbox->context_help_set_keyword("Video In section");
225         RecordPositioning *positioning = new RecordPositioning(pwindow,textbox);
226         add_subwindow(positioning);
227         positioning->create_objects();
228         positioning->context_help_set_keyword("Video In section");
229         y += positioning->get_h() + ys5;
230
231         add_subwindow(new RecordSyncDrives(pwindow,
232                 pwindow->thread->edl->session->record_sync_drives,
233                 x, y));
234         y += yS(35);
235
236         BC_TextBox *w_text, *h_text;
237         add_subwindow(title1 = new BC_Title(x, y, _("Size of captured frame:")));
238         title1->context_help_set_keyword("Video In section");
239         x += title1->get_w() + margin;
240         add_subwindow(w_text = new RecordW(pwindow, x, y));
241         w_text->context_help_set_keyword("Video In section");
242         x += w_text->get_w() + margin;
243         add_subwindow(title1 = new BC_Title(x, y, "x"));
244         title1->context_help_set_keyword("Video In section");
245         x += title1->get_w() + margin;
246         add_subwindow(h_text = new RecordH(pwindow, x, y));
247         h_text->context_help_set_keyword("Video In section");
248         x += h_text->get_w() + margin;
249         FrameSizePulldown *frame_sizes;
250         add_subwindow(frame_sizes = new FrameSizePulldown(mwindow->theme,
251                 w_text, h_text, x, y));
252         frame_sizes->context_help_set_keyword("Video In section");
253         y += frame_sizes->get_h() + margin;
254
255         x = mwindow->theme->preferencesoptions_x;
256         add_subwindow(title1 = new BC_Title(x, y, _("Frame rate for recording:")));
257         title1->context_help_set_keyword("Video In section");
258         x += title1->get_w() + margin;
259         add_subwindow(textbox = new RecordFrameRate(pwindow, x, y));
260         textbox->context_help_set_keyword("Video In section");
261         x += textbox->get_w() + margin;
262         add_subwindow(new FrameRatePulldown(mwindow, textbox, x, y));
263
264 }
265
266
267 int RecordPrefs::show_window(int flush)
268 {
269         PreferencesDialog::show_window(flush);
270         if( pwindow->thread->edl->session->recording_format->format == FILE_MPEG &&
271             pwindow->thread->edl->session->vconfig_in->driver == CAPTURE_DVB &&
272             pwindow->thread->edl->session->aconfig_in->driver == AUDIO_DVB )
273                 return realtime_toc->show_window(flush);
274         return realtime_toc->hide_window(flush);
275 }
276
277
278 RecordFragment::RecordFragment(int x,
279         int y,
280         PreferencesWindow *pwindow,
281         RecordPrefs *record,
282         char *text)
283  : BC_PopupMenu(x, y, xS(100), text, 1)
284 {
285         this->pwindow = pwindow;
286         this->record = record;
287 }
288
289 int RecordFragment::handle_event()
290 {
291         pwindow->thread->edl->session->record_fragment_size = atol(get_text());
292         return 1;
293 }
294
295
296 RecordWriteLength::RecordWriteLength(MWindow *mwindow, PreferencesWindow *pwindow, int x, int y, char *text)
297  : BC_TextBox(x, y, xS(100), 1, text)
298 {
299         this->pwindow = pwindow;
300 }
301
302 int RecordWriteLength::handle_event()
303 {
304         pwindow->thread->edl->session->record_write_length = atol(get_text());
305         return 1;
306 }
307
308
309 RecordRealTime::RecordRealTime(MWindow *mwindow,
310         PreferencesWindow *pwindow, int x, int y, int value)
311  : BC_CheckBox(x, y, value,
312         _("Record in realtime priority (root only)"))
313 {
314         this->pwindow = pwindow;
315 // *** CONTEXT_HELP ***
316         context_help_set_keyword("Audio In section");
317 }
318
319 int RecordRealTime::handle_event()
320 {
321         pwindow->thread->edl->session->real_time_record = get_value();
322         return 1;
323 }
324
325
326 RecordMap51_2::RecordMap51_2(MWindow *mwindow,
327         PreferencesWindow *pwindow, int x, int y, int value)
328  : BC_CheckBox(x, y, value, _("Map 5.1->2"))
329 {
330         this->pwindow = pwindow;
331 }
332
333 int RecordMap51_2::handle_event()
334 {
335         pwindow->thread->edl->session->aconfig_in->map51_2 = get_value();
336         return 1;
337 }
338
339
340 RecordSampleRate::RecordSampleRate(PreferencesWindow *pwindow, int x, int y)
341  : BC_TextBox(x, y, xS(70), 1, pwindow->thread->edl->session->aconfig_in->in_samplerate)
342 {
343         this->pwindow = pwindow;
344 }
345 int RecordSampleRate::handle_event()
346 {
347         pwindow->thread->edl->session->aconfig_in->in_samplerate = atol(get_text());
348         return 1;
349 }
350
351
352 RecordRealtimeTOC::RecordRealtimeTOC(MWindow *mwindow,
353         PreferencesWindow *pwindow, int x, int y, int value)
354  : BC_CheckBox(x, y, value, _("Realtime TOC"))
355 {
356         this->pwindow = pwindow;
357 }
358
359 int RecordRealtimeTOC::handle_event()
360 {
361         pwindow->thread->edl->session->record_realtime_toc = get_value();
362         return 1;
363 }
364
365
366 // DuplexEnable::DuplexEnable(MWindow *mwindow, PreferencesWindow *pwindow, int x, int y, int value)
367 //  : BC_CheckBox(x, y, value, _("Enable full duplex"))
368 // { this->pwindow = pwindow; }
369 //
370 // int DuplexEnable::handle_event()
371 // {
372 //      pwindow->thread->edl->session->enable_duplex = get_value();
373 // }
374 //
375
376
377 RecordW::RecordW(PreferencesWindow *pwindow, int x, int y)
378  : BC_TextBox(x, y, xS(70), 1, pwindow->thread->edl->session->vconfig_in->w)
379 {
380         this->pwindow = pwindow;
381 }
382 int RecordW::handle_event()
383 {
384         pwindow->thread->edl->session->vconfig_in->w = atol(get_text());
385         return 1;
386 }
387
388 RecordH::RecordH(PreferencesWindow *pwindow, int x, int y)
389  : BC_TextBox(x, y, xS(70), 1, pwindow->thread->edl->session->vconfig_in->h)
390 {
391         this->pwindow = pwindow;
392 }
393 int RecordH::handle_event()
394 {
395         pwindow->thread->edl->session->vconfig_in->h = atol(get_text());
396         return 1;
397 }
398
399 RecordFrameRate::RecordFrameRate(PreferencesWindow *pwindow, int x, int y)
400  : BC_TextBox(x, y, xS(140), 1, pwindow->thread->edl->session->vconfig_in->in_framerate)
401 {
402         this->pwindow = pwindow;
403 }
404 int RecordFrameRate::handle_event()
405 {
406         pwindow->thread->edl->session->vconfig_in->in_framerate = atof(get_text());
407         return 1;
408 }
409
410
411
412 RecordChannels::RecordChannels(PreferencesWindow *pwindow, BC_SubWindow *gui, int x, int y)
413  : BC_TumbleTextBox(gui,
414                 pwindow->thread->edl->session->aconfig_in->channels,
415                 1, MAX_CHANNELS, x, y, xS(100))
416 {
417         this->pwindow = pwindow;
418 }
419
420 int RecordChannels::handle_event()
421 {
422         pwindow->thread->edl->session->aconfig_in->channels = atoi(get_text());
423         return 1;
424 }
425
426 RecordGain::RecordGain(PreferencesWindow *pwindow, BC_SubWindow *gui, int x, int y)
427  : BC_TumbleTextBox(gui,
428                 pwindow->thread->edl->session->aconfig_in->rec_gain,
429                 0.0001f, 10000.0f, x, y, xS(72))
430 {
431         this->pwindow = pwindow;
432         this->set_increment(0.1);
433 }
434
435 int RecordGain::handle_event()
436 {
437         pwindow->thread->edl->session->aconfig_in->rec_gain = atof(get_text());
438         return 1;
439 }
440
441
442
443 VideoWriteLength::VideoWriteLength(PreferencesWindow *pwindow, char *text, int x, int y)
444  : BC_TextBox(x, y, xS(100), 1, text)
445 {
446         this->pwindow = pwindow;
447 }
448
449 int VideoWriteLength::handle_event()
450 {
451         pwindow->thread->edl->session->video_write_length = atol(get_text());
452         return 1;
453 }
454
455
456 VideoCaptureLength::VideoCaptureLength(PreferencesWindow *pwindow, char *text, int x, int y)
457  : BC_TextBox(x, y, xS(100), 1, text)
458 {
459         this->pwindow = pwindow;
460 }
461
462 int VideoCaptureLength::handle_event()
463 {
464         pwindow->thread->edl->session->vconfig_in->capture_length = atol(get_text());
465         return 1;
466 }
467
468 CaptureLengthTumbler::CaptureLengthTumbler(PreferencesWindow *pwindow, BC_TextBox *text, int x, int y)
469  : BC_Tumbler(x, y)
470 {
471         this->pwindow = pwindow;
472         this->text = text;
473 // *** CONTEXT_HELP ***
474         context_help_set_keyword("Video In section");
475 }
476
477 int CaptureLengthTumbler::handle_up_event()
478 {
479         int value = atol(text->get_text());
480         value++;
481         char string[BCTEXTLEN];
482         sprintf(string, "%d", value);
483         text->update(string);
484         text->handle_event();
485         return 1;
486 }
487
488 int CaptureLengthTumbler::handle_down_event()
489 {
490         int value = atol(text->get_text());
491         value--;
492         value = MAX(1, value);
493         char string[BCTEXTLEN];
494         sprintf(string, "%d", value);
495         text->update(string);
496         text->handle_event();
497         return 1;
498 }
499
500 RecordPositioning::RecordPositioning(PreferencesWindow *pwindow, BC_TextBox *textbox)
501  : BC_ListBox(textbox->get_x() + textbox->get_w(), textbox->get_y(),
502                  xS(200), yS(100), LISTBOX_TEXT, &position_type, 0, 0, 1, 0, 1)
503 {
504         this->pwindow = pwindow;
505         this->textbox = textbox;
506 }
507
508 RecordPositioning::~RecordPositioning()
509 {
510         for( int i=0; i<position_type.total; ++i )
511                 delete position_type.values[i];
512 }
513
514 void RecordPositioning::create_objects()
515 {
516         position_type.append(new BC_ListBoxItem(_("Presentation Timestamps")));
517         position_type.append(new BC_ListBoxItem(_("Software timing")));
518         position_type.append(new BC_ListBoxItem(_("Device Position")));
519         position_type.append(new BC_ListBoxItem(_("Sample Position")));
520         int value = pwindow->thread->edl->session->record_positioning;
521         textbox->update(position_type.values[value]->get_text());
522 }
523
524 int RecordPositioning::handle_event()
525 {
526         int v = get_selection_number(0, 0);
527         pwindow->thread->edl->session->record_positioning = v;
528         textbox->update(position_type.values[v]->get_text());
529         textbox->handle_event();
530         return 1;
531 }
532
533
534 RecordSyncDrives::RecordSyncDrives(PreferencesWindow *pwindow, int value, int x, int y)
535  : BC_CheckBox(x, y, value, _("Sync drives automatically"))
536 {
537         this->pwindow = pwindow;
538 // *** CONTEXT_HELP ***
539         context_help_set_keyword("Video In section");
540 }
541
542 int RecordSyncDrives::handle_event()
543 {
544         pwindow->thread->edl->session->record_sync_drives = get_value();
545         return 1;
546 }
547
548