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