r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playbackprefs.C
blob3e69054581df17cf3c32bf30554a4a7354c78c45
1 #include "adeviceprefs.h"
2 #include "audioconfig.h"
3 #include "audiodevice.inc"
4 #include "clip.h"
5 #include "defaults.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "mwindow.h"
9 #include "overlayframe.inc"
10 #include "playbackprefs.h"
11 #include "preferences.h"
12 #include "vdeviceprefs.h"
13 #include "videodevice.inc"
15 #include <string.h>
16 #include <libintl.h>
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
22 PlaybackPrefs::PlaybackPrefs(MWindow *mwindow, PreferencesWindow *pwindow)
23  : PreferencesDialog(mwindow, pwindow)
25         head_text = 0;
26         head_count_text = 0;
27         host_text = 0;
28         video_device = 0;
31 PlaybackPrefs::~PlaybackPrefs()
33         delete_strategy();
34         mwindow->defaults->update("PLAYBACK_HEAD", current_head);
35         delete audio_device;
36         delete video_device;
39 int PlaybackPrefs::create_objects()
41         int x = 5, y = 5, x2;
42         char string[BCTEXTLEN];
43         BC_PopupTextBox *popup;
45         current_head = mwindow->defaults->get("PLAYBACK_HEAD", 0);
46         strategies.append(new BC_ListBoxItem(_("Local Host")));
47         strategies.append(new BC_ListBoxItem(_("Multihead")));
48         strategies.append(new BC_ListBoxItem(_("Blond Symphony")));
50 // Global playback options
52 // All strategies use these
53         add_subwindow(new BC_Title(x, y, _("Audio Out"), LARGEFONT, BLACK));
54         y += 30;
58         BC_Title *title1, *title2;
59         add_subwindow(title1 = new BC_Title(x, y, _("Samples to read from disk at a time:"), MEDIUMFONT, BLACK));
60         add_subwindow(title2 = new BC_Title(x, y + 30, _("Samples to send to console at a time:"), MEDIUMFONT, BLACK));
61         x2 = MAX(title1->get_w(), title2->get_w()) + 10;
63         sprintf(string, "%d", pwindow->thread->edl->session->audio_read_length);
64         add_subwindow(new PlaybackReadLength(x2, y, pwindow, this, string));
65         sprintf(string, "%d", pwindow->thread->edl->session->audio_module_fragment);
66         add_subwindow(new PlaybackModuleFragment(x2, y + 30, pwindow, this, string));
69         y += 60;
70         add_subwindow(new PlaybackViewFollows(pwindow, pwindow->thread->edl->session->view_follows_playback, y));
71         y += 30;
72         add_subwindow(new PlaybackSoftwareTimer(pwindow, pwindow->thread->edl->session->playback_software_position, y));
73         y += 30;
74         add_subwindow(new PlaybackRealTime(pwindow, pwindow->thread->edl->session->real_time_playback, y));
75         y += 40;
76         add_subwindow(new BC_Title(x, y, _("Audio Driver:")));
77         audio_device = new ADevicePrefs(x + 100, 
78                 y, 
79                 pwindow, 
80                 this, 
81                 current_config()->aconfig, 
82                 0,
83                 MODEPLAY);
84         audio_device->initialize();
86 // Strategic playback options created here
87         set_strategy(pwindow->thread->edl->session->playback_strategy);
88 // 
89 //      add_subwindow(new BC_Title(x, y, _("Playback driver:"), MEDIUMFONT, BLACK));
90 //      add_subwindow(new AudioDriverMenu(x, y + 20, out_device, &(pwindow->thread->preferences->aconfig->audio_out_driver), 0, 1));
91         y += 60;
93         add_subwindow(new BC_Title(x, y, _("Video Out"), LARGEFONT, BLACK));
94         y += 30;
96         add_subwindow(new VideoEveryFrame(pwindow, x, y));
98         add_subwindow(new BC_Title(x + 200, y + 10, _("Framerate achieved:")));
99         add_subwindow(framerate_title = new BC_Title(x + 350, y + 10, _("--"), MEDIUMFONT, RED));
100         draw_framerate();
102         y += 35;
103         add_subwindow(new BC_Title(x, y, _("Scaling equation:")));
104         y += 20;
105         add_subwindow(nearest_neighbor = new PlaybackNearest(pwindow, 
106                 this, 
107                 pwindow->thread->edl->session->interpolation_type == NEAREST_NEIGHBOR, 
108                 10, 
109                 y));
110         y += 20;
111         add_subwindow(cubic_linear = new PlaybackBicubicBilinear(pwindow, 
112                 this, 
113                 pwindow->thread->edl->session->interpolation_type == CUBIC_LINEAR, 
114                 10, 
115                 y));
116         y += 20;
117         add_subwindow(linear_linear = new PlaybackBilinearBilinear(pwindow, 
118                 this, 
119                 pwindow->thread->edl->session->interpolation_type == LINEAR_LINEAR, 
120                 10, 
121                 y));
123         y += 35;
124         add_subwindow(new BC_Title(x, y, _("Preload buffer for Quicktime:"), MEDIUMFONT, BLACK));
125         sprintf(string, "%d", pwindow->thread->edl->session->playback_preload);
126         add_subwindow(new PlaybackPreload(x + 210, y, pwindow, this, string));
128 //      y += 30;
129 //      add_subwindow(new PlaybackDeblock(pwindow, 10, y));
131         y += 35;
132         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
133         video_device = new VDevicePrefs(x + 100, 
134                 y, 
135                 pwindow, 
136                 this, 
137                 current_config()->vconfig, 
138                 0,
139                 MODEPLAY);
140         video_device->initialize();
142 // Strategic playback options created here
143 //      set_strategy(pwindow->thread->edl->session->playback_strategy, y);
144         
146         return 0;
149 char* PlaybackPrefs::strategy_to_string(int strategy)
151         switch(strategy)
152         {
153                 case PLAYBACK_LOCALHOST:
154                         return _("Local Host");
155                         break;
156                 case PLAYBACK_MULTIHEAD:
157                         return _("Multihead");
158                         break;
159                 case PLAYBACK_BLONDSYMPHONY:
160                         return _("Blond Symphony");
161                         break;
162         }
163         return _("Local Host");
166 // Delete strategy dependant objects
167 void PlaybackPrefs::delete_strategy()
169         if(head_text) 
170         {
171                 delete head_text;
172                 delete head_title;
173                 head_text = 0;
174         }
175         if(host_text)
176         {
177                 delete host_title;
178                 delete host_text;
179                 host_text = 0;
180         }
181         if(head_count_text)
182         {
183                 delete head_count_title;
184                 delete head_count_text;
185                 head_count_text = 0;
186         }
187         if(video_device)
188         {
189                 delete vdevice_title;
190                 delete video_device;
191                 video_device = 0;
192         }
195 int PlaybackPrefs::set_strategy(int strategy)
197         int x = 350, x1 = 450, y = 10;
198         delete_strategy();
200         pwindow->thread->edl->session->playback_strategy = strategy;
201         switch(strategy)
202         {
203                 case PLAYBACK_LOCALHOST:
204                         break;
205                 case PLAYBACK_MULTIHEAD:
206                         add_subwindow(head_title = new BC_Title(x, y, _("Head:")));
207                         head_text = new PlaybackHead(this, x1, y);
208                         head_text->create_objects();
209                         y += 25;
210                         add_subwindow(head_count_title = new BC_Title(x, y, _("Total Heads:")));
211                         head_count_text = new PlaybackHeadCount(this, x1, y);
212                         head_count_text->create_objects();
213                         x = 10;
214                         y = 390;
215                         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
216                         video_device = new VDevicePrefs(x + 100, 
217                                 y, 
218                                 pwindow, 
219                                 this, 
220                                 current_config()->vconfig, 
221                                 0,
222                                 MODEPLAY);
223                         video_device->initialize();
224                         break;
225                 case PLAYBACK_BLONDSYMPHONY:
226                         add_subwindow(head_title = new BC_Title(x, y, _("Head:")));
227                         head_text = new PlaybackHead(this, x1, y);
228                         head_text->create_objects();
229                         y += 25;
230                         add_subwindow(head_count_title = new BC_Title(x, y, _("Total Heads:")));
231                         head_count_text = new PlaybackHeadCount(this, x1, y);
232                         head_count_text->create_objects();
233                         y += 25;
234                         add_subwindow(host_title = new BC_Title(x, y, _("Hostname:")));
235                         add_subwindow(host_text = new PlaybackHost(this, x1, y));
236                         x = 10;
237                         y = 390;
238                         add_subwindow(vdevice_title = new BC_Title(x, y, _("Video Driver:")));
239                         video_device = new VDevicePrefs(x + 100, 
240                                 y, 
241                                 pwindow, 
242                                 this, 
243                                 current_config()->vconfig,
244                                 0,
245                                 MODEPLAY);
246                         video_device->initialize();
247                         break;
248         }
249         
250         return 1;
253 ArrayList<PlaybackConfig*>* PlaybackPrefs::current_config_list()
255         return &pwindow->thread->edl->session->playback_config[pwindow->thread->edl->session->playback_strategy];
258 PlaybackConfig* PlaybackPrefs::current_config()
260         return current_config_list()->values[current_head];
264 void PlaybackPrefs::update(int interpolation)
266         pwindow->thread->edl->session->interpolation_type = interpolation;
267         nearest_neighbor->update(interpolation == NEAREST_NEIGHBOR);
268 //      cubic_cubic->update(interpolation == CUBIC_CUBIC);
269         cubic_linear->update(interpolation == CUBIC_LINEAR);
270         linear_linear->update(interpolation == LINEAR_LINEAR);
274 int PlaybackPrefs::get_buffer_bytes()
276 //      return pwindow->thread->edl->aconfig->oss_out_bits / 8 * pwindow->thread->preferences->aconfig->oss_out_channels * pwindow->thread->preferences->playback_buffer;
279 int PlaybackPrefs::draw_framerate()
281 //printf("PlaybackPrefs::draw_framerate 1 %f\n", pwindow->thread->edl->session->actual_frame_rate);
282         char string[BCTEXTLEN];
283         sprintf(string, "%.4f", pwindow->thread->edl->session->actual_frame_rate);
284         framerate_title->update(string);
285         return 0;
292 PlaybackStrategy::PlaybackStrategy(PlaybackPrefs *prefs, 
293         int x, 
294         int y)
295  : BC_PopupTextBox(prefs, 
296                 &prefs->strategies,
297                 prefs->strategy_to_string(prefs->pwindow->thread->edl->session->playback_strategy),
298                 x, 
299                 y, 
300                 200,
301                 100)
303         this->prefs = prefs;
306 int PlaybackStrategy::handle_event()
308         prefs->set_strategy(get_number());
309         return 1;
316 PlaybackHead::PlaybackHead(PlaybackPrefs *prefs, 
317         int x, 
318         int y)
319  : BC_TumbleTextBox(prefs, 
320                 prefs->current_head,
321                 (int64_t)0, 
322                 (int64_t)prefs->current_config_list()->total - 1, 
323                 x,
324                 y,
325                 100)
327         this->prefs = prefs;
330 int PlaybackHead::handle_event()
332         return 1;
335 PlaybackHeadCount::PlaybackHeadCount(PlaybackPrefs *prefs, 
336         int x, 
337         int y)
338  : BC_TumbleTextBox(prefs, 
339                 prefs->current_config_list()->total, 
340                 1, 
341                 MAX_CHANNELS,
342                 x,
343                 y,
344                 100)
346         this->prefs = prefs;
349 int PlaybackHeadCount::handle_event()
351         return 1;
356 PlaybackHost::PlaybackHost(PlaybackPrefs *prefs, int x, int y)
357  : BC_TextBox(x, y, 100, 1, prefs->current_config()->hostname)
359         this->prefs = prefs; 
362 int PlaybackHost::handle_event() 
364         strcpy(prefs->current_config()->hostname, get_text()); 
365         return 1;
371 PlaybackReadLength::PlaybackReadLength(int x, int y, PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
372  : BC_TextBox(x, y, 100, 1, text)
374         this->pwindow = pwindow; 
375         this->playback = playback; 
378 int PlaybackReadLength::handle_event() 
380         pwindow->thread->edl->session->audio_read_length = atol(get_text()); 
381         return 1;
387 PlaybackModuleFragment::PlaybackModuleFragment(int x, int y, PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
388  : BC_TextBox(x, y, 100, 1, text)
390         this->pwindow = pwindow; 
393 int PlaybackModuleFragment::handle_event() 
395         pwindow->thread->edl->session->audio_module_fragment = atol(get_text()); 
396         return 1;
402 PlaybackBufferSize::PlaybackBufferSize(int x, int y, PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
403  : BC_TextBox(x, y, 100, 1, text)
405         this->pwindow = pwindow; 
406         this->playback = playback; 
409 int PlaybackBufferSize::handle_event() 
411         pwindow->thread->edl->session->playback_buffer = atol(get_text()); 
412         return 1;
415 PlaybackBufferBytes::PlaybackBufferBytes(int x, int y, PreferencesWindow *pwindow, PlaybackPrefs *playback, char *text)
416  : BC_Title(x, y, text)
418         this->pwindow = pwindow; 
419         this->playback = playback;
421 int PlaybackBufferBytes::update_bytes()
423         sprintf(string, "%d", playback->get_buffer_bytes());
424         update(string);
425         return 1;
428 PlaybackDisableNoEdits::PlaybackDisableNoEdits(PreferencesWindow *pwindow, int value, int y)
429  : BC_CheckBox(10, y, value, _("Disable tracks when no edits."))
431         this->pwindow = pwindow; 
434 int PlaybackDisableNoEdits::handle_event() 
436         pwindow->thread->edl->session->test_playback_edits = get_value(); 
437         return 1;
443 PlaybackViewFollows::PlaybackViewFollows(PreferencesWindow *pwindow, int value, int y)
444  : BC_CheckBox(10, y, value, _("View follows playback"))
446         this->pwindow = pwindow; 
449 int PlaybackViewFollows::handle_event() 
451         pwindow->thread->edl->session->view_follows_playback = get_value(); 
452         return 1;
458 PlaybackSoftwareTimer::PlaybackSoftwareTimer(PreferencesWindow *pwindow, int value, int y)
459  : BC_CheckBox(10, y, value, _("Use software for positioning information"))
461         this->pwindow = pwindow; 
464 int PlaybackSoftwareTimer::handle_event() 
466         pwindow->thread->edl->session->playback_software_position = get_value(); 
467         return 1;
473 PlaybackRealTime::PlaybackRealTime(PreferencesWindow *pwindow, int value, int y)
474  : BC_CheckBox(10, y, value, _("Audio playback in real time priority (root only)"))
476         this->pwindow = pwindow; 
479 int PlaybackRealTime::handle_event() 
481         pwindow->thread->edl->session->real_time_playback = get_value(); 
482         return 1;
491 PlaybackNearest::PlaybackNearest(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
492  : BC_Radial(x, y, value, _("Nearest neighbor enlarge and reduce"))
494         this->pwindow = pwindow;
495         this->prefs = prefs;
497 int PlaybackNearest::handle_event()
499         prefs->update(NEAREST_NEIGHBOR);
500         return 1;
507 PlaybackBicubicBicubic::PlaybackBicubicBicubic(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
508  : BC_Radial(x, y, value, _("Bicubic enlarge and reduce"))
510         this->pwindow = pwindow;
511         this->prefs = prefs;
513 int PlaybackBicubicBicubic::handle_event()
515         prefs->update(CUBIC_CUBIC);
516         return 1;
522 PlaybackBicubicBilinear::PlaybackBicubicBilinear(PreferencesWindow *pwindow, PlaybackPrefs *prefs, int value, int x, int y)
523  : BC_Radial(x, y, value, _("Bicubic enlarge and bilinear reduce"))
525         this->pwindow = pwindow;
526         this->prefs = prefs;
528 int PlaybackBicubicBilinear::handle_event()
530         prefs->update(CUBIC_LINEAR);
531         return 1;
535 PlaybackBilinearBilinear::PlaybackBilinearBilinear(PreferencesWindow *pwindow, 
536         PlaybackPrefs *prefs, 
537         int value, 
538         int x, 
539         int y)
540  : BC_Radial(x, y, value, _("Bilinear enlarge and bilinear reduce"))
542         this->pwindow = pwindow;
543         this->prefs = prefs;
545 int PlaybackBilinearBilinear::handle_event()
547         prefs->update(LINEAR_LINEAR);
548         return 1;
552 PlaybackPreload::PlaybackPreload(int x, 
553         int y, 
554         PreferencesWindow *pwindow, 
555         PlaybackPrefs *playback, 
556         char *text)
557  : BC_TextBox(x, y, 100, 1, text)
559         this->pwindow = pwindow; 
560         this->playback = playback; 
563 int PlaybackPreload::handle_event() 
565         pwindow->thread->edl->session->playback_preload = atol(get_text()); 
566         return 1;
571 VideoEveryFrame::VideoEveryFrame(PreferencesWindow *pwindow, int x, int y)
572  : BC_CheckBox(x, y, pwindow->thread->edl->session->video_every_frame, _("Play every frame"))
574         this->pwindow = pwindow;
577 int VideoEveryFrame::handle_event()
579         pwindow->thread->edl->session->video_every_frame = get_value();
580         return 1;
587 // PlaybackDeblock::PlaybackDeblock(PreferencesWindow *pwindow, int x, int y)
588 //  : BC_CheckBox(x, 
589 //      y, 
590 //      pwindow->thread->edl->session->mpeg4_deblock, 
591 //      _("MPEG-4 Deblocking"))
592 // {
593 //      this->pwindow = pwindow;
594 // }
595 // 
596 // int PlaybackDeblock::handle_event()
597 // {
598 //      pwindow->thread->edl->session->mpeg4_deblock = get_value();
599 //      return 1;
600 // }
601 //