r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / cinelerra / playbackprefs.C
blobebcc738ebcc94278a8d31a69f046b0890d5cf107
1 #include "adeviceprefs.h"
2 #include "audioconfig.h"
3 #include "audiodevice.inc"
4 #include "bcsignals.h"
5 #include "clip.h"
6 #include "bchash.h"
7 #include "edl.h"
8 #include "edlsession.h"
9 #include "language.h"
10 #include "mwindow.h"
11 #include "overlayframe.inc"
12 #include "playbackprefs.h"
13 #include "preferences.h"
14 #include "theme.h"
15 #include "vdeviceprefs.h"
16 #include "videodevice.inc"
20 PlaybackPrefs::PlaybackPrefs(MWindow *mwindow, PreferencesWindow *pwindow)
21  : PreferencesDialog(mwindow, pwindow)
23         video_device = 0;
26 PlaybackPrefs::~PlaybackPrefs()
28         delete audio_device;
29         delete video_device;
32 int PlaybackPrefs::create_objects()
34         int x, y, x2;
35         char string[BCTEXTLEN];
36         BC_PopupTextBox *popup;
37         BC_WindowBase *window;
38         BC_Resources *resources = BC_WindowBase::get_resources();
40         playback_config = pwindow->thread->edl->session->playback_config;
42         x = mwindow->theme->preferencesoptions_x;
43         y = mwindow->theme->preferencesoptions_y;
45 // Audio
46         add_subwindow(new BC_Title(x, 
47                 y, 
48                 _("Audio Out"), 
49                 LARGEFONT));
51 SET_TRACE
53         y += get_text_height(LARGEFONT) + 5;
56         BC_Title *title1, *title2;
57         add_subwindow(title2 = new BC_Title(x, y, _("Playback buffer size:"), MEDIUMFONT));
58         x2 = MAX(title2->get_w(), title2->get_w()) + 10;
60 SET_TRACE
61         sprintf(string, "%d", playback_config->aconfig->fragment_size);
62         PlaybackModuleFragment *menu;
63         add_subwindow(menu = new PlaybackModuleFragment(x2, 
64                 y, 
65                 pwindow, 
66                 this, 
67                 string));
68         menu->add_item(new BC_MenuItem("2048"));
69         menu->add_item(new BC_MenuItem("4096"));
70         menu->add_item(new BC_MenuItem("8192"));
71         menu->add_item(new BC_MenuItem("16384"));
72         menu->add_item(new BC_MenuItem("32768"));
73         menu->add_item(new BC_MenuItem("65536"));
74         menu->add_item(new BC_MenuItem("131072"));
75         menu->add_item(new BC_MenuItem("262144"));
77 SET_TRACE
78         y += menu->get_h() + 5;
79         x2 = x;
80         add_subwindow(title1 = new BC_Title(x2, y, _("Audio offset (sec):")));
81         x2 += title1->get_w() + 5;
82         PlaybackAudioOffset *audio_offset = new PlaybackAudioOffset(pwindow,
83                 this,
84                 x2,
85                 y);
86         audio_offset->create_objects();
87         y += audio_offset->get_h() + 5;
89 SET_TRACE
90         add_subwindow(new PlaybackViewFollows(pwindow, pwindow->thread->edl->session->view_follows_playback, y));
91         y += 30;
92         add_subwindow(new PlaybackSoftwareTimer(pwindow, pwindow->thread->edl->session->playback_software_position, y));
93         y += 30;
94         add_subwindow(new PlaybackRealTime(pwindow, pwindow->thread->edl->session->real_time_playback, y));
95         y += 40;
96         add_subwindow(new BC_Title(x, y, _("Audio Driver:")));
97         audio_device = new ADevicePrefs(x + 100, 
98                 y, 
99                 pwindow, 
100                 this, 
101                 playback_config->aconfig, 
102                 0,
103                 MODEPLAY);
104         audio_device->initialize();
106 SET_TRACE
110 // Video
111         y += audio_device->get_h();
113 SET_TRACE
114         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
115         y += 5;
117 SET_TRACE
118         add_subwindow(new BC_Title(x, y, _("Video Out"), LARGEFONT));
119         y += 30;
121 SET_TRACE
122         add_subwindow(window = new VideoEveryFrame(pwindow, this, x, y));
124         add_subwindow(new BC_Title(x + 200, y + 5, _("Framerate achieved:")));
125         add_subwindow(framerate_title = new BC_Title(x + 350, y + 5, _("--"), MEDIUMFONT, RED));
126         draw_framerate();
127         y += window->get_h() + 5;
129         add_subwindow(asynchronous = new VideoAsynchronous(pwindow, x, y));
130         y += asynchronous->get_h() + 10;
132 SET_TRACE
133         add_subwindow(new BC_Title(x, y, _("Scaling equation:")));
134         y += 20;
135         add_subwindow(nearest_neighbor = new PlaybackNearest(pwindow, 
136                 this, 
137                 pwindow->thread->edl->session->interpolation_type == NEAREST_NEIGHBOR, 
138                 10, 
139                 y));
140         y += 20;
141         add_subwindow(cubic_linear = new PlaybackBicubicBilinear(pwindow, 
142                 this, 
143                 pwindow->thread->edl->session->interpolation_type == CUBIC_LINEAR, 
144                 10, 
145                 y));
146         y += 20;
147         add_subwindow(linear_linear = new PlaybackBilinearBilinear(pwindow, 
148                 this, 
149                 pwindow->thread->edl->session->interpolation_type == LINEAR_LINEAR, 
150                 10, 
151                 y));
153 SET_TRACE
154         y += 35;
155         add_subwindow(new BC_Title(x, y, _("Preload buffer for Quicktime:"), MEDIUMFONT));
156         sprintf(string, "%d", pwindow->thread->edl->session->playback_preload);
157         PlaybackPreload *preload;
158         add_subwindow(preload = new PlaybackPreload(x + 210, y, pwindow, this, string));
160         y += preload->get_h() + 5;
161         add_subwindow(title1 = new BC_Title(x, y, _("DVD Subtitle to display:")));
162         PlaybackSubtitleNumber *subtitle_number;
163         subtitle_number = new PlaybackSubtitleNumber(x + title1->get_w() + 10, 
164                 y, 
165                 pwindow, 
166                 this);
167         subtitle_number->create_objects();
169         PlaybackSubtitle *subtitle_toggle;
170         add_subwindow(subtitle_toggle = new PlaybackSubtitle(
171                 x + title1->get_w() + 10 + subtitle_number->get_w() + 10, 
172                 y, 
173                 pwindow, 
174                 this));
175         y += subtitle_number->get_h();
178         add_subwindow(interpolate_raw = new PlaybackInterpolateRaw(
179                 x, 
180                 y,
181                 pwindow,
182                 this));
183         y += interpolate_raw->get_h();
185         add_subwindow(white_balance_raw = new PlaybackWhiteBalanceRaw(
186                 x, 
187                 y,
188                 pwindow,
189                 this));
190         y += white_balance_raw->get_h() + 10;
191         if(!pwindow->thread->edl->session->interpolate_raw) 
192                 white_balance_raw->disable();
195 SET_TRACE
196 //      y += 30;
197 //      add_subwindow(new PlaybackDeblock(pwindow, 10, y));
199         add_subwindow(new BC_Title(x, y, _("Timecode offset:"), MEDIUMFONT, BLACK));
200         sprintf(string, "%d", pwindow->thread->edl->session->timecode_offset[3]);
201         add_subwindow(new TimecodeOffset(x + 120, y, pwindow, this, string, 3));
202         add_subwindow(new BC_Title(x + 152, y, _(":"), MEDIUMFONT, BLACK));
203         sprintf(string, "%d", pwindow->thread->edl->session->timecode_offset[2]);
204         add_subwindow(new TimecodeOffset(x + 160, y, pwindow, this, string, 2));
205         add_subwindow(new BC_Title(x + 192, y, _(":"), MEDIUMFONT, BLACK));
206         sprintf(string, "%d", pwindow->thread->edl->session->timecode_offset[1]);
207         add_subwindow(new TimecodeOffset(x + 200, y, pwindow, this, string, 1));
208         add_subwindow(new BC_Title(x + 232, y, _(":"), MEDIUMFONT, BLACK));
209         sprintf(string, "%d", pwindow->thread->edl->session->timecode_offset[0]);
210         add_subwindow(new TimecodeOffset(x + 240, y, pwindow, this, string, 0));
212         y += 35;
213         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
214         video_device = new VDevicePrefs(x + vdevice_title->get_w() + 10, 
215                 y, 
216                 pwindow, 
217                 this, 
218                 playback_config->vconfig, 
219                 0,
220                 MODEPLAY);
221         video_device->initialize();
223 SET_TRACE       
225         return 0;
229 void PlaybackPrefs::update(int interpolation)
231         pwindow->thread->edl->session->interpolation_type = interpolation;
232         nearest_neighbor->update(interpolation == NEAREST_NEIGHBOR);
233 //      cubic_cubic->update(interpolation == CUBIC_CUBIC);
234         cubic_linear->update(interpolation == CUBIC_LINEAR);
235         linear_linear->update(interpolation == LINEAR_LINEAR);
239 int PlaybackPrefs::get_buffer_bytes()
241 //      return pwindow->thread->edl->aconfig->oss_out_bits / 8 * pwindow->thread->preferences->aconfig->oss_out_channels * pwindow->thread->preferences->playback_buffer;
244 int PlaybackPrefs::draw_framerate()
246 //printf("PlaybackPrefs::draw_framerate 1 %f\n", pwindow->thread->edl->session->actual_frame_rate);
247         char string[BCTEXTLEN];
248         sprintf(string, "%.4f", pwindow->thread->edl->session->actual_frame_rate);
249         framerate_title->update(string);
250         return 0;
255 PlaybackAudioOffset::PlaybackAudioOffset(PreferencesWindow *pwindow, 
256         PlaybackPrefs *playback, 
257         int x, 
258         int y)
259  : BC_TumbleTextBox(playback,
260         playback->playback_config->aconfig->audio_offset,
261         -10.0,
262         10.0,
263         x,
264         y,
265         100)
267         this->pwindow = pwindow;
268         this->playback = playback;
269         set_precision(2);
270         set_increment(0.1);
273 int PlaybackAudioOffset::handle_event()
275         playback->playback_config->aconfig->audio_offset = atof(get_text());
276         return 1;
282 PlaybackModuleFragment::PlaybackModuleFragment(int x, 
283         int y, 
284         PreferencesWindow *pwindow, 
285         PlaybackPrefs *playback, 
286         char *text)
287  : BC_PopupMenu(x, 
288         y, 
289         100, 
290         text,
291         1)
293         this->pwindow = pwindow;
294         this->playback = playback;
297 int PlaybackModuleFragment::handle_event() 
299         playback->playback_config->aconfig->fragment_size = atol(get_text()); 
300         return 1;
306 PlaybackViewFollows::PlaybackViewFollows(PreferencesWindow *pwindow, int value, int y)
307  : BC_CheckBox(10, y, value, _("View follows playback"))
309         this->pwindow = pwindow; 
312 int PlaybackViewFollows::handle_event() 
314         pwindow->thread->edl->session->view_follows_playback = get_value(); 
315         return 1;
321 PlaybackSoftwareTimer::PlaybackSoftwareTimer(PreferencesWindow *pwindow, int value, int y)
322  : BC_CheckBox(10, y, value, _("Use software for positioning information"))
324         this->pwindow = pwindow; 
327 int PlaybackSoftwareTimer::handle_event() 
329         pwindow->thread->edl->session->playback_software_position = get_value(); 
330         return 1;
336 PlaybackRealTime::PlaybackRealTime(PreferencesWindow *pwindow, int value, int y)
337  : BC_CheckBox(10, y, value, _("Audio playback in real time priority (root only)"))
339         this->pwindow = pwindow; 
342 int PlaybackRealTime::handle_event() 
344         pwindow->thread->edl->session->real_time_playback = get_value(); 
345         return 1;
354 PlaybackNearest::PlaybackNearest(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
355  : BC_Radial(x, y, value, _("Nearest neighbor enlarge and reduce"))
357         this->pwindow = pwindow;
358         this->prefs = prefs;
360 int PlaybackNearest::handle_event()
362         prefs->update(NEAREST_NEIGHBOR);
363         return 1;
370 PlaybackBicubicBicubic::PlaybackBicubicBicubic(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
371  : BC_Radial(x, y, value, _("Bicubic enlarge and reduce"))
373         this->pwindow = pwindow;
374         this->prefs = prefs;
376 int PlaybackBicubicBicubic::handle_event()
378         prefs->update(CUBIC_CUBIC);
379         return 1;
385 PlaybackBicubicBilinear::PlaybackBicubicBilinear(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
386  : BC_Radial(x, y, value, _("Bicubic enlarge and bilinear reduce"))
388         this->pwindow = pwindow;
389         this->prefs = prefs;
391 int PlaybackBicubicBilinear::handle_event()
393         prefs->update(CUBIC_LINEAR);
394         return 1;
398 PlaybackBilinearBilinear::PlaybackBilinearBilinear(PreferencesWindow *pwindow, 
399         PlaybackPrefs *prefs, 
400         int value, 
401         int x, 
402         int y)
403  : BC_Radial(x, y, value, _("Bilinear enlarge and bilinear reduce"))
405         this->pwindow = pwindow;
406         this->prefs = prefs;
408 int PlaybackBilinearBilinear::handle_event()
410         prefs->update(LINEAR_LINEAR);
411         return 1;
415 PlaybackPreload::PlaybackPreload(int x, 
416         int y, 
417         PreferencesWindow *pwindow, 
418         PlaybackPrefs *playback, 
419         char *text)
420  : BC_TextBox(x, y, 100, 1, text)
422         this->pwindow = pwindow; 
423         this->playback = playback; 
426 int PlaybackPreload::handle_event() 
428         pwindow->thread->edl->session->playback_preload = atol(get_text()); 
429         return 1;
433 PlaybackInterpolateRaw::PlaybackInterpolateRaw(
434         int x, 
435         int y, 
436         PreferencesWindow *pwindow, 
437         PlaybackPrefs *playback)
438  : BC_CheckBox(x, 
439         y, 
440         pwindow->thread->edl->session->interpolate_raw, 
441         _("Interpolate CR2 images"))
443         this->pwindow = pwindow;
444         this->playback = playback;
447 int PlaybackInterpolateRaw::handle_event()
449         pwindow->thread->edl->session->interpolate_raw = get_value();
450         if(!pwindow->thread->edl->session->interpolate_raw)
451         {
452                 playback->white_balance_raw->update(0, 0);
453                 playback->white_balance_raw->disable();
454         }
455         else
456         {
457                 playback->white_balance_raw->update(pwindow->thread->edl->session->white_balance_raw, 0);
458                 playback->white_balance_raw->enable();
459         }
460         return 1;
466 PlaybackWhiteBalanceRaw::PlaybackWhiteBalanceRaw(
467         int x, 
468         int y, 
469         PreferencesWindow *pwindow, 
470         PlaybackPrefs *playback)
471  : BC_CheckBox(x, 
472         y, 
473         pwindow->thread->edl->session->interpolate_raw &&
474                 pwindow->thread->edl->session->white_balance_raw, 
475         _("White balance CR2 images"))
477         this->pwindow = pwindow;
478         this->playback = playback;
479         if(!pwindow->thread->edl->session->interpolate_raw) disable();
482 int PlaybackWhiteBalanceRaw::handle_event()
484         pwindow->thread->edl->session->white_balance_raw = get_value();
485         return 1;
493 VideoAsynchronous::VideoAsynchronous(PreferencesWindow *pwindow, int x, int y)
494  : BC_CheckBox(x, 
495         y, 
496         pwindow->thread->edl->session->video_every_frame &&
497                 pwindow->thread->edl->session->video_asynchronous, 
498         _("Decode frames asynchronously"))
500         this->pwindow = pwindow;
501         if(!pwindow->thread->edl->session->video_every_frame)
502                 disable();
505 int VideoAsynchronous::handle_event()
507         pwindow->thread->edl->session->video_asynchronous = get_value();
508         return 1;
514 VideoEveryFrame::VideoEveryFrame(PreferencesWindow *pwindow, 
515         PlaybackPrefs *playback_prefs,
516         int x, 
517         int y)
518  : BC_CheckBox(x, y, pwindow->thread->edl->session->video_every_frame, _("Play every frame"))
520         this->pwindow = pwindow;
521         this->playback_prefs = playback_prefs;
524 int VideoEveryFrame::handle_event()
526         pwindow->thread->edl->session->video_every_frame = get_value();
527         if(!pwindow->thread->edl->session->video_every_frame)
528         {
529                 playback_prefs->asynchronous->update(0, 0);
530                 playback_prefs->asynchronous->disable();
531         }
532         else
533         {
534                 playback_prefs->asynchronous->update(pwindow->thread->edl->session->video_asynchronous, 0);
535                 playback_prefs->asynchronous->enable();
536         }
537         return 1;
546 PlaybackSubtitle::PlaybackSubtitle(int x, 
547         int y, 
548         PreferencesWindow *pwindow, 
549         PlaybackPrefs *playback)
550  : BC_CheckBox(x, 
551         y, 
552         pwindow->thread->edl->session->decode_subtitles,
553         _("Enable subtitles"))
555         this->pwindow = pwindow;
556         this->playback = playback;
559 int PlaybackSubtitle::handle_event()
561         pwindow->thread->edl->session->decode_subtitles = get_value();
562         return 1;
574 PlaybackSubtitleNumber::PlaybackSubtitleNumber(int x, 
575         int y, 
576         PreferencesWindow *pwindow, 
577         PlaybackPrefs *playback)
578  : BC_TumbleTextBox(playback,
579         pwindow->thread->edl->session->subtitle_number,
580         0,
581         31,
582         x, 
583         y, 
584         50)
586         this->pwindow = pwindow;
587         this->playback = playback;
590 int PlaybackSubtitleNumber::handle_event()
592         pwindow->thread->edl->session->subtitle_number = atoi(get_text());
593         return 1;
599 TimecodeOffset::TimecodeOffset(int x, int y, PreferencesWindow *pwindow, 
600       PlaybackPrefs *playback, char *text, int unit)
601  : BC_TextBox(x, y, 30, 1, text)
603    this->pwindow = pwindow;
604    this->playback = playback;
605         this->unit = unit;
608 int TimecodeOffset::handle_event()
610         pwindow->thread->edl->session->timecode_offset[unit] = atol(get_text());
611         return 1;