add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / playbackprefs.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 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 "audioconfig.h"
24 #include "audiodevice.inc"
25 #include "bcsignals.h"
26 #include "clip.h"
27 #include "bchash.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "language.h"
31 #include "mainsession.h"
32 #include "mwindow.h"
33 #include "overlayframe.inc"
34 #include "playbackprefs.h"
35 #include "preferences.h"
36 #include "theme.h"
37 #include "vdeviceprefs.h"
38 #include "videodevice.inc"
39
40
41
42 PlaybackPrefs::PlaybackPrefs(MWindow *mwindow, PreferencesWindow *pwindow, int config_number)
43  : PreferencesDialog(mwindow, pwindow)
44 {
45         this->config_number = config_number;
46         audio_device = 0;
47         video_device = 0;
48         audio_offset = 0;
49         play_gain = 0;
50 }
51
52 PlaybackPrefs::~PlaybackPrefs()
53 {
54         delete audio_device;
55         delete video_device;
56         delete audio_offset;
57         delete play_gain;
58 }
59
60 void PlaybackPrefs::create_objects()
61 {
62         int xs5 = xS(5), xs10 = xS(10), xs30 = xS(30);
63         int ys5 = yS(5), ys30 = yS(30);
64         int x, y, x2, y2;
65         char string[BCTEXTLEN];
66         BC_WindowBase *window;
67
68
69         playback_config = pwindow->thread->edl->session->playback_config;
70
71         x = mwindow->theme->preferencesoptions_x;
72         y = mwindow->theme->preferencesoptions_y;
73         int margin = mwindow->theme->widget_border;
74
75 // Audio
76         BC_Title *title1, *title2;
77         add_subwindow(title1 = new BC_Title(x, y, _("Audio Out"), LARGEFONT));
78         y += title1->get_h() + margin;
79         add_subwindow(title2 = new BC_Title(x, y, _("Playback buffer samples:"), MEDIUMFONT));
80         x2 = title2->get_x() + title2->get_w() + margin;
81
82 SET_TRACE
83         sprintf(string, "%d", playback_config->aconfig->fragment_size);
84         PlaybackModuleFragment *menu;
85         add_subwindow(menu = new PlaybackModuleFragment(x2, y, pwindow, this, string));
86         menu->add_item(new BC_MenuItem("1024"));
87         menu->add_item(new BC_MenuItem("2048"));
88         menu->add_item(new BC_MenuItem("4096"));
89         menu->add_item(new BC_MenuItem("8192"));
90         menu->add_item(new BC_MenuItem("16384"));
91         menu->add_item(new BC_MenuItem("32768"));
92         menu->add_item(new BC_MenuItem("65536"));
93         menu->add_item(new BC_MenuItem("131072"));
94         menu->add_item(new BC_MenuItem("262144"));
95
96         y += menu->get_h() + ys5;
97         x2 = x;
98         add_subwindow(title1 = new BC_Title(x2, y, _("Audio offset (sec):")));
99         x2 += title1->get_w() + xs5;
100         audio_offset = new PlaybackAudioOffset(pwindow, this, x2, y);
101         audio_offset->create_objects();
102         y += audio_offset->get_h() + ys5;
103
104 SET_TRACE
105         add_subwindow(new PlaybackViewFollows(pwindow,
106                 pwindow->thread->edl->session->view_follows_playback, y));
107         y += ys30;
108         add_subwindow(new PlaybackSoftwareTimer(pwindow,
109                 pwindow->thread->edl->session->playback_software_position, y));
110         y += ys30;
111         add_subwindow(new PlaybackRealTime(pwindow,
112                 pwindow->thread->edl->session->real_time_playback, y));
113         y += ys30;
114         PlaybackMap51_2 *map51_2 = new PlaybackMap51_2(pwindow, this,
115                 playback_config->aconfig->map51_2, y);
116         add_subwindow(map51_2);
117         x2 =  map51_2->get_x() + map51_2->get_w() + xS(15);
118         y2 = y + BC_TextBox::calculate_h(this,MEDIUMFONT,1,1) - get_text_height(MEDIUMFONT);
119
120         add_subwindow(title2 = new BC_Title(x2, y2, _("Gain:")));
121         x2 += title2->get_w() + xS(8);
122         play_gain = new PlaybackGain(x2, y, pwindow, this);
123         play_gain->create_objects();
124         y += yS(40);
125         add_subwindow(new BC_Title(x, y, _("Audio Driver:")));
126         audio_device = new ADevicePrefs(x + xS(100), y, pwindow,
127                 this, playback_config->aconfig, 0, MODEPLAY);
128         audio_device->initialize(0);
129 SET_TRACE
130 // Video
131         y += audio_device->get_h(0) + margin;
132
133 SET_TRACE
134         add_subwindow(new BC_Bar(x, y,  get_w() - x * 2));
135         y += ys5;
136
137 SET_TRACE
138         add_subwindow(title1 = new BC_Title(x, y, _("Video Out"), LARGEFONT));
139         y += title1->get_h() + margin;
140
141 SET_TRACE
142         add_subwindow(window = new VideoEveryFrame(pwindow, this, x, y));
143         int x1 = x + window->get_w() + xs30;
144         const char *txt = _("Framerate achieved:");
145         int y1 = y + (window->get_h() - BC_Title::calculate_h(this, txt)) / 2;
146         add_subwindow(title1 = new BC_Title(x1, y1, txt));
147         x1 += title1->get_w() + margin;
148         add_subwindow(framerate_title = new BC_Title(x1, y1, "--", MEDIUMFONT, RED));
149         draw_framerate(0);
150         y += window->get_h() + 2*margin;
151
152 //      add_subwindow(asynchronous = new VideoAsynchronous(pwindow, x, y));
153 //      y += asynchronous->get_h() + ys10;
154
155 SET_TRACE
156         add_subwindow(title1 = new BC_Title(x, y, _("Scaling equation: Enlarge / Reduce ")));
157         VScalingEquation *vscaling_equation =
158                 new VScalingEquation(x + title1->get_w() + xS(65), y,
159                         &pwindow->thread->edl->session->interpolation_type);
160         add_subwindow(vscaling_equation);
161         vscaling_equation->create_objects();
162 SET_TRACE
163         y += yS(35);
164
165         add_subwindow(title1 = new BC_Title(x, y, _("DVD Subtitle to display:")));
166         PlaybackSubtitleNumber *subtitle_number;
167         x1 = x + title1->get_w() + margin;
168         subtitle_number = new PlaybackSubtitleNumber(x1, y, pwindow, this);
169         subtitle_number->create_objects();
170
171         x2 = x + title1->get_w() + xs10 + subtitle_number->get_w() + xS(85);
172         PlaybackSubtitle *subtitle_toggle;
173         x1 += subtitle_number->get_w() + margin;
174         add_subwindow(subtitle_toggle = new PlaybackSubtitle(x2, y, pwindow, this));
175         y += subtitle_toggle->get_h();
176
177         PlaybackLabelCells *label_cells_toggle;
178         add_subwindow(label_cells_toggle = new PlaybackLabelCells(x2, y, pwindow, this));
179         y2 = y + label_cells_toggle->get_h();
180
181         add_subwindow(title1=new BC_Title(x2, y2, _("TOC Program No:"), MEDIUMFONT));
182         PlaybackProgramNumber *program_number;
183         program_number = new PlaybackProgramNumber(
184                 x2 + title1->get_w() + xs10, y2, pwindow, this);
185         program_number->create_objects();
186
187         add_subwindow(interpolate_raw = new PlaybackInterpolateRaw( x, y,
188                 pwindow, this));
189         y += interpolate_raw->get_h() + margin;
190
191         add_subwindow(white_balance_raw = new PlaybackWhiteBalanceRaw(x, y,
192                 pwindow, this));
193         if(!pwindow->thread->edl->session->interpolate_raw)
194                 white_balance_raw->disable();
195         y += white_balance_raw->get_h() + margin;
196
197         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
198         y += vdevice_title->get_h() + margin;
199         video_device = new VDevicePrefs(x, y, pwindow, this,
200                 playback_config->vconfig, 0, MODEPLAY);
201         video_device->initialize(0);
202 }
203
204
205 int PlaybackPrefs::draw_framerate(int flush)
206 {
207 //printf("PlaybackPrefs::draw_framerate 1 %f\n", mwindow->session->actual_frame_rate);
208         char string[BCTEXTLEN];
209         sprintf(string, "%.4f", mwindow->session->actual_frame_rate);
210         framerate_title->update(string, flush);
211         return 0;
212 }
213
214
215
216 PlaybackAudioOffset::PlaybackAudioOffset(PreferencesWindow *pwindow,
217         PlaybackPrefs *playback, int x, int y)
218  : BC_TumbleTextBox(playback, playback->playback_config->aconfig->audio_offset,
219         -10.0, 10.0, x, y, xS(100))
220 {
221         this->pwindow = pwindow;
222         this->playback = playback;
223         set_precision(2);
224         set_increment(0.1);
225 }
226
227 int PlaybackAudioOffset::handle_event()
228 {
229         playback->playback_config->aconfig->audio_offset = atof(get_text());
230         return 1;
231 }
232
233
234
235
236 PlaybackModuleFragment::PlaybackModuleFragment(int x, int y,
237         PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
238  : BC_PopupMenu(x, y, xS(100), text, 1)
239 {
240         this->pwindow = pwindow;
241         this->playback = playback;
242 }
243
244 int PlaybackModuleFragment::handle_event()
245 {
246         playback->playback_config->aconfig->fragment_size = atol(get_text());
247         return 1;
248 }
249
250
251 PlaybackViewFollows::PlaybackViewFollows(PreferencesWindow *pwindow, int value, int y)
252  : BC_CheckBox(xS(10), y, value, _("View follows playback"))
253 {
254         this->pwindow = pwindow;
255 }
256
257 int PlaybackViewFollows::handle_event()
258 {
259         pwindow->thread->edl->session->view_follows_playback = get_value();
260         return 1;
261 }
262
263
264 PlaybackSoftwareTimer::PlaybackSoftwareTimer(PreferencesWindow *pwindow, int value, int y)
265  : BC_CheckBox(xS(10), y, value, _("Disable hardware synchronization"))
266 {
267         this->pwindow = pwindow;
268 }
269
270 int PlaybackSoftwareTimer::handle_event()
271 {
272         pwindow->thread->edl->session->playback_software_position = get_value();
273         return 1;
274 }
275
276
277 PlaybackRealTime::PlaybackRealTime(PreferencesWindow *pwindow, int value, int y)
278  : BC_CheckBox(xS(10), y, value, _("Audio playback in real time priority (root only)"))
279 {
280         this->pwindow = pwindow;
281 }
282
283 int PlaybackRealTime::handle_event()
284 {
285         pwindow->thread->edl->session->real_time_playback = get_value();
286         return 1;
287 }
288
289
290 PlaybackMap51_2::PlaybackMap51_2(PreferencesWindow *pwindow,
291                 PlaybackPrefs *playback_prefs, int value, int y)
292  : BC_CheckBox(xS(10), y, value, _("Map 5.1->2"))
293 {
294         this->pwindow = pwindow;
295         this->playback_prefs = playback_prefs;
296 }
297
298 int PlaybackMap51_2::handle_event()
299 {
300         playback_prefs->playback_config->aconfig->map51_2 = get_value();
301         return 1;
302 }
303
304
305 PlaybackInterpolateRaw::PlaybackInterpolateRaw( int x, int y,
306                 PreferencesWindow *pwindow, PlaybackPrefs *playback)
307  : BC_CheckBox(x, y, pwindow->thread->edl->session->interpolate_raw,
308         _("Interpolate CR2 images"))
309 {
310         this->pwindow = pwindow;
311         this->playback = playback;
312 }
313
314 int PlaybackInterpolateRaw::handle_event()
315 {
316         pwindow->thread->edl->session->interpolate_raw = get_value();
317         if( !pwindow->thread->edl->session->interpolate_raw ) {
318                 playback->white_balance_raw->update(0, 0);
319                 playback->white_balance_raw->disable();
320         }
321         else {
322                 playback->white_balance_raw->update(pwindow->thread->edl->session->white_balance_raw, 0);
323                 playback->white_balance_raw->enable();
324         }
325         return 1;
326 }
327
328 PlaybackWhiteBalanceRaw::PlaybackWhiteBalanceRaw( int x, int y,
329                 PreferencesWindow *pwindow, PlaybackPrefs *playback)
330  : BC_CheckBox(x, y,
331         pwindow->thread->edl->session->interpolate_raw &&
332                 pwindow->thread->edl->session->white_balance_raw,
333         _("White balance CR2 images"))
334 {
335         this->pwindow = pwindow;
336         this->playback = playback;
337         if(!pwindow->thread->edl->session->interpolate_raw) disable();
338 }
339
340 int PlaybackWhiteBalanceRaw::handle_event()
341 {
342         pwindow->thread->edl->session->white_balance_raw = get_value();
343         return 1;
344 }
345
346 // VideoAsynchronous::VideoAsynchronous(PreferencesWindow *pwindow, int x, int y)
347 //  : BC_CheckBox(x, y,
348 //      pwindow->thread->edl->session->video_every_frame &&
349 //              pwindow->thread->edl->session->video_asynchronous,
350 //      _("Decode frames asynchronously"))
351 // {
352 //      this->pwindow = pwindow;
353 //      if(!pwindow->thread->edl->session->video_every_frame)
354 //              disable();
355 // }
356 //
357 // int VideoAsynchronous::handle_event()
358 // {
359 //      pwindow->thread->edl->session->video_asynchronous = get_value();
360 //      return 1;
361 // }
362
363
364 VideoEveryFrame::VideoEveryFrame(PreferencesWindow *pwindow,
365         PlaybackPrefs *playback_prefs, int x, int y)
366  : BC_CheckBox(x, y, pwindow->thread->edl->session->video_every_frame, _("Play every frame"))
367 {
368         this->pwindow = pwindow;
369         this->playback_prefs = playback_prefs;
370 }
371
372 int VideoEveryFrame::handle_event()
373 {
374         pwindow->thread->edl->session->video_every_frame = get_value();
375 //      if(!pwindow->thread->edl->session->video_every_frame) {
376 //              playback_prefs->asynchronous->update(0, 0);
377 //              playback_prefs->asynchronous->disable();
378 //      }
379 //      else {
380 //              playback_prefs->asynchronous->update(pwindow->thread->edl->session->video_asynchronous, 0);
381 //              playback_prefs->asynchronous->enable();
382 //      }
383         return 1;
384 }
385
386
387 PlaybackSubtitle::PlaybackSubtitle(int x, int y,
388         PreferencesWindow *pwindow, PlaybackPrefs *playback)
389  : BC_CheckBox(x, y,
390         pwindow->thread->edl->session->decode_subtitles,
391         _("Enable subtitles/captioning"))
392 {
393         this->pwindow = pwindow;
394         this->playback = playback;
395 }
396
397 int PlaybackSubtitle::handle_event()
398 {
399         pwindow->thread->edl->session->decode_subtitles = get_value();
400         return 1;
401 }
402
403
404 PlaybackSubtitleNumber::PlaybackSubtitleNumber(int x, int y,
405         PreferencesWindow *pwindow, PlaybackPrefs *playback)
406  : BC_TumbleTextBox(playback, pwindow->thread->edl->session->subtitle_number,
407         0, 31, x, y, xS(50))
408 {
409         this->pwindow = pwindow;
410         this->playback = playback;
411 }
412
413 int PlaybackSubtitleNumber::handle_event()
414 {
415         pwindow->thread->edl->session->subtitle_number = atoi(get_text());
416         return 1;
417 }
418
419
420 PlaybackLabelCells::PlaybackLabelCells(int x, int y,
421         PreferencesWindow *pwindow, PlaybackPrefs *playback)
422  : BC_CheckBox(x, y,
423         pwindow->thread->edl->session->label_cells,
424         _("Label cells"))
425 {
426         this->pwindow = pwindow;
427         this->playback = playback;
428 }
429
430 int PlaybackLabelCells::handle_event()
431 {
432         pwindow->thread->edl->session->label_cells = get_value();
433         return 1;
434 }
435
436
437 PlaybackProgramNumber::PlaybackProgramNumber(int x, int y,
438         PreferencesWindow *pwindow, PlaybackPrefs *playback)
439  : BC_TumbleTextBox(playback,
440         pwindow->thread->edl->session->program_no,
441         0, 31, x, y, xS(50))
442 {
443         this->pwindow = pwindow;
444         this->playback = playback;
445 }
446
447 int PlaybackProgramNumber::handle_event()
448 {
449         pwindow->thread->edl->session->program_no = atoi(get_text());
450         return 1;
451 }
452
453 PlaybackGain::PlaybackGain(int x, int y,
454         PreferencesWindow *pwindow, PlaybackPrefs *playback)
455  : BC_TumbleTextBox(playback,
456                 pwindow->thread->edl->session->playback_config->aconfig->play_gain,
457                 0.0001f, 10000.0f, x, y, xS(72))
458 {
459         this->pwindow = pwindow;
460         this->set_increment(0.1);
461 }
462
463 int PlaybackGain::handle_event()
464 {
465         pwindow->thread->edl->session->playback_config->
466                 aconfig->play_gain = atof(get_text());
467         return 1;
468 }
469