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