initial commit
[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         add_subwindow(new BC_Title(x, y, _("Preload buffer for Quicktime:"), MEDIUMFONT));
176         sprintf(string, "" _LD "", pwindow->thread->edl->session->playback_preload);
177         PlaybackPreload *preload;
178         add_subwindow(preload = new PlaybackPreload(x + 210, y, pwindow, this, string));
179
180         y += preload->get_h() + 5;
181         add_subwindow(title1 = new BC_Title(x, y, _("DVD Subtitle to display:")));
182         PlaybackSubtitleNumber *subtitle_number;
183         subtitle_number = new PlaybackSubtitleNumber(x + title1->get_w() + 10, 
184                 y, 
185                 pwindow, 
186                 this);
187         subtitle_number->create_objects();
188
189         x2 = x + title1->get_w() + 10 + subtitle_number->get_w() + 30;
190         PlaybackSubtitle *subtitle_toggle;
191         add_subwindow(subtitle_toggle = new PlaybackSubtitle(x2, y, pwindow, this));
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         y2 = y + label_cells_toggle->get_h();
197
198         add_subwindow(title1=new BC_Title(x2, y2, _("TOC Program No:"), MEDIUMFONT));
199         PlaybackProgramNumber *program_number;
200         program_number = new PlaybackProgramNumber(
201                 x2 + title1->get_w() + 10, y2, pwindow, this);
202         program_number->create_objects();
203
204         add_subwindow(interpolate_raw = new PlaybackInterpolateRaw( x, y,
205                 pwindow, this));
206         y += interpolate_raw->get_h();
207
208         add_subwindow(white_balance_raw = new PlaybackWhiteBalanceRaw( x, y,
209                 pwindow, this));
210         y += white_balance_raw->get_h() + 10;
211         if(!pwindow->thread->edl->session->interpolate_raw) 
212                 white_balance_raw->disable();
213
214
215 SET_TRACE
216 //      y += 30;
217 //      add_subwindow(new PlaybackDeblock(pwindow, 10, y));
218
219         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
220         video_device = new VDevicePrefs(x + vdevice_title->get_w() + 10, y, 
221                 pwindow, this, playback_config->vconfig, 0, MODEPLAY);
222         video_device->initialize(0);
223 SET_TRACE       
224
225 }
226
227
228 int PlaybackPrefs::draw_framerate(int flush)
229 {
230 //printf("PlaybackPrefs::draw_framerate 1 %f\n", mwindow->session->actual_frame_rate);
231         char string[BCTEXTLEN];
232         sprintf(string, "%.4f", mwindow->session->actual_frame_rate);
233         framerate_title->update(string, flush);
234         return 0;
235 }
236
237
238
239 PlaybackAudioOffset::PlaybackAudioOffset(PreferencesWindow *pwindow, 
240         PlaybackPrefs *playback, int x, int y)
241  : BC_TumbleTextBox(playback, playback->playback_config->aconfig->audio_offset,
242         -10.0, 10.0, x, y, 100)
243 {
244         this->pwindow = pwindow;
245         this->playback = playback;
246         set_precision(2);
247         set_increment(0.1);
248 }
249
250 int PlaybackAudioOffset::handle_event()
251 {
252         playback->playback_config->aconfig->audio_offset = atof(get_text());
253         return 1;
254 }
255
256
257
258
259 PlaybackModuleFragment::PlaybackModuleFragment(int x, int y, 
260         PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
261  : BC_PopupMenu(x, y, 100, text, 1)
262
263         this->pwindow = pwindow;
264         this->playback = playback;
265 }
266
267 int PlaybackModuleFragment::handle_event() 
268 {
269         playback->playback_config->aconfig->fragment_size = atol(get_text()); 
270         return 1;
271 }
272
273
274 PlaybackViewFollows::PlaybackViewFollows(PreferencesWindow *pwindow, int value, int y)
275  : BC_CheckBox(10, y, value, _("View follows playback"))
276
277         this->pwindow = pwindow; 
278 }
279
280 int PlaybackViewFollows::handle_event() 
281
282         pwindow->thread->edl->session->view_follows_playback = get_value(); 
283         return 1;
284 }
285
286
287 PlaybackSoftwareTimer::PlaybackSoftwareTimer(PreferencesWindow *pwindow, int value, int y)
288  : BC_CheckBox(10, y, value, _("Use software for positioning information"))
289
290         this->pwindow = pwindow; 
291 }
292
293 int PlaybackSoftwareTimer::handle_event() 
294
295         pwindow->thread->edl->session->playback_software_position = get_value(); 
296         return 1;
297 }
298
299
300 PlaybackRealTime::PlaybackRealTime(PreferencesWindow *pwindow, int value, int y)
301  : BC_CheckBox(10, y, value, _("Audio playback in real time priority (root only)"))
302
303         this->pwindow = pwindow; 
304 }
305
306 int PlaybackRealTime::handle_event() 
307
308         pwindow->thread->edl->session->real_time_playback = get_value(); 
309         return 1;
310 }
311
312
313 PlaybackMap51_2::PlaybackMap51_2(PreferencesWindow *pwindow,
314                 PlaybackPrefs *playback_prefs, int value, int y)
315  : BC_CheckBox(10, y, value, _("Map 5.1->2"))
316 {
317         this->pwindow = pwindow;
318         this->playback_prefs = playback_prefs; 
319 }
320
321 int PlaybackMap51_2::handle_event() 
322 {
323         playback_prefs->playback_config->aconfig->map51_2 = get_value();
324         return 1;
325 }
326
327
328 PlaybackPreload::PlaybackPreload(int x, int y, 
329         PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
330  : BC_TextBox(x, y, 100, 1, text)
331
332         this->pwindow = pwindow; 
333         this->playback = playback; 
334 }
335
336 int PlaybackPreload::handle_event() 
337
338         pwindow->thread->edl->session->playback_preload = atol(get_text()); 
339         return 1;
340 }
341
342
343 PlaybackInterpolateRaw::PlaybackInterpolateRaw( int x, int y, 
344                 PreferencesWindow *pwindow, PlaybackPrefs *playback)
345  : BC_CheckBox(x, 
346         y, 
347         pwindow->thread->edl->session->interpolate_raw, 
348         _("Interpolate CR2 images"))
349 {
350         this->pwindow = pwindow;
351         this->playback = playback;
352 }
353
354 int PlaybackInterpolateRaw::handle_event()
355 {
356         pwindow->thread->edl->session->interpolate_raw = get_value();
357         if(!pwindow->thread->edl->session->interpolate_raw) {
358                 playback->white_balance_raw->update(0, 0);
359                 playback->white_balance_raw->disable();
360         }
361         else {
362                 playback->white_balance_raw->update(pwindow->thread->edl->session->white_balance_raw, 0);
363                 playback->white_balance_raw->enable();
364         }
365         return 1;
366 }
367
368
369 PlaybackWhiteBalanceRaw::PlaybackWhiteBalanceRaw( int x, int y, 
370                 PreferencesWindow *pwindow, PlaybackPrefs *playback)
371  : BC_CheckBox(x, 
372         y, 
373         pwindow->thread->edl->session->interpolate_raw &&
374                 pwindow->thread->edl->session->white_balance_raw, 
375         _("White balance CR2 images"))
376 {
377         this->pwindow = pwindow;
378         this->playback = playback;
379         if(!pwindow->thread->edl->session->interpolate_raw) disable();
380 }
381
382 int PlaybackWhiteBalanceRaw::handle_event()
383 {
384         pwindow->thread->edl->session->white_balance_raw = get_value();
385         return 1;
386 }
387
388
389 VideoAsynchronous::VideoAsynchronous(PreferencesWindow *pwindow, int x, int y)
390  : BC_CheckBox(x, y, 
391         pwindow->thread->edl->session->video_every_frame &&
392                 pwindow->thread->edl->session->video_asynchronous, 
393         _("Decode frames asynchronously"))
394 {
395         this->pwindow = pwindow;
396         if(!pwindow->thread->edl->session->video_every_frame)
397                 disable();
398 }
399
400 int VideoAsynchronous::handle_event()
401 {
402         pwindow->thread->edl->session->video_asynchronous = get_value();
403         return 1;
404 }
405
406
407 VideoEveryFrame::VideoEveryFrame(PreferencesWindow *pwindow, 
408         PlaybackPrefs *playback_prefs, int x, int y)
409  : BC_CheckBox(x, y, pwindow->thread->edl->session->video_every_frame, _("Play every frame"))
410 {
411         this->pwindow = pwindow;
412         this->playback_prefs = playback_prefs;
413 }
414
415 int VideoEveryFrame::handle_event()
416 {
417         pwindow->thread->edl->session->video_every_frame = get_value();
418         if(!pwindow->thread->edl->session->video_every_frame) {
419                 playback_prefs->asynchronous->update(0, 0);
420                 playback_prefs->asynchronous->disable();
421         }
422         else {
423                 playback_prefs->asynchronous->update(pwindow->thread->edl->session->video_asynchronous, 0);
424                 playback_prefs->asynchronous->enable();
425         }
426         return 1;
427 }
428
429
430 PlaybackSubtitle::PlaybackSubtitle(int x, int y, 
431         PreferencesWindow *pwindow, PlaybackPrefs *playback)
432  : BC_CheckBox(x, y, 
433         pwindow->thread->edl->session->decode_subtitles,
434         _("Enable subtitles/captioning"))
435 {
436         this->pwindow = pwindow;
437         this->playback = playback;
438 }
439
440 int PlaybackSubtitle::handle_event()
441 {
442         pwindow->thread->edl->session->decode_subtitles = get_value();
443         return 1;
444 }
445
446
447 PlaybackSubtitleNumber::PlaybackSubtitleNumber(int x, int y, 
448         PreferencesWindow *pwindow, PlaybackPrefs *playback)
449  : BC_TumbleTextBox(playback, pwindow->thread->edl->session->subtitle_number,
450         0, 31, x, y, 50)
451 {
452         this->pwindow = pwindow;
453         this->playback = playback;
454 }
455
456 int PlaybackSubtitleNumber::handle_event()
457 {
458         pwindow->thread->edl->session->subtitle_number = atoi(get_text());
459         return 1;
460 }
461
462
463 PlaybackLabelCells::PlaybackLabelCells(int x, int y, 
464         PreferencesWindow *pwindow, PlaybackPrefs *playback)
465  : BC_CheckBox(x, y, 
466         pwindow->thread->edl->session->label_cells,
467         _("Label cells"))
468 {
469         this->pwindow = pwindow;
470         this->playback = playback;
471 }
472
473 int PlaybackLabelCells::handle_event()
474 {
475         pwindow->thread->edl->session->label_cells = get_value();
476         return 1;
477 }
478
479
480 PlaybackProgramNumber::PlaybackProgramNumber(int x, int y, 
481         PreferencesWindow *pwindow, PlaybackPrefs *playback)
482  : BC_TumbleTextBox(playback,
483         pwindow->thread->edl->session->program_no,
484         0, 31, x, y, 50)
485 {
486         this->pwindow = pwindow;
487         this->playback = playback;
488 }
489
490 int PlaybackProgramNumber::handle_event()
491 {
492         pwindow->thread->edl->session->program_no = atoi(get_text());
493         return 1;
494 }
495
496 PlaybackGain::PlaybackGain(int x, int y,
497         PreferencesWindow *pwindow, PlaybackPrefs *playback)
498  : BC_TumbleTextBox(playback,
499                 pwindow->thread->edl->session->playback_config->aconfig->play_gain,
500                 0.0001f, 10000.0f, x, y, 72)
501 {
502         this->pwindow = pwindow; 
503         this->set_increment(0.1);
504 }
505
506 int PlaybackGain::handle_event()
507 {
508         pwindow->thread->edl->session->playback_config->
509                 aconfig->play_gain = atof(get_text());
510         return 1;
511 }
512
513