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