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