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