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