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