r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / preferencesthread.C
blob9f6ce35c3a798e72a3a73829e1839845fd20ae78
1 #include "aboutprefs.h"
2 #include "assets.h"
3 #include "audiodevice.inc"
4 #include "cache.h"
5 #include "cplayback.h"
6 #include "cwindow.h"
7 #include "cwindowgui.h"
8 #include "defaults.h"
9 #include "edl.h"
10 #include "edlsession.h"
11 #include "filesystem.h"
12 #include "fonts.h"
13 #include "interfaceprefs.h"
14 #include "keys.h"
15 #include "levelwindow.h"
16 #include "levelwindowgui.h"
17 #include "meterpanel.h"
18 #include "mwindow.h"
19 #include "mwindowgui.h"
20 #include "patchbay.h"
21 #include "performanceprefs.h"
22 #include "playbackengine.h"
23 #include "playbackprefs.h"
24 #include "preferences.h"
25 #include "recordprefs.h"
26 #include "theme.h"
27 #include "trackcanvas.h"
28 #include "transportque.h"
29 #include "vwindow.h"
30 #include "vwindowgui.h"
32 #include <string.h>
34 #include <libintl.h>
35 #define _(String) gettext(String)
36 #define gettext_noop(String) String
37 #define N_(String) gettext_noop (String)
39 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
40  : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
42         this->mwindow = mwindow; 
44         set_shift(1);
45         thread = new PreferencesThread(mwindow);
48 PreferencesMenuitem::~PreferencesMenuitem()
50         delete thread;
54 int PreferencesMenuitem::handle_event() 
56         if(thread->thread_running) return 1;
57         thread->start();
58         return 1;
64 PreferencesThread::PreferencesThread(MWindow *mwindow)
65  : Thread()
67         this->mwindow = mwindow;
68         window = 0;
69         thread_running = 0;
72 PreferencesThread::~PreferencesThread()
76 void PreferencesThread::run()
78         int need_new_indexes;
80         preferences = new Preferences;
81         edl = new EDL;
82         edl->create_objects();
83         current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
84         *preferences = *mwindow->preferences;
85         edl->copy_session(mwindow->edl);
86         redraw_indexes = 0;
87         redraw_meters = 0;
88         redraw_times = 0;
89         redraw_overlays = 0;
90         close_assets = 0;
91         reload_plugins = 0;
92         need_new_indexes = 0;
93         rerender = 0;
95         window = new PreferencesWindow(mwindow, this);
96         window->create_objects();
97         thread_running = 1;
98         int result = window->run_window();
100         thread_running = 0;
101         if(!result)
102         {
103                 apply_settings();
104                 mwindow->save_defaults();
105         }
107         delete window;
108         window = 0;
109         delete preferences;
110         delete edl;
112         mwindow->defaults->update("DEFAULTPREF", current_dialog);
115 int PreferencesThread::update_framerate()
117         if(thread_running && window)
118         {
119                 window->update_framerate();
120         }
121         return 0;
124 int PreferencesThread::apply_settings()
126 // Compare sessions                                                                                     
129         AudioOutConfig *this_aconfig = edl->session->playback_config[edl->session->playback_strategy].values[0]->aconfig;
130         VideoOutConfig *this_vconfig = edl->session->playback_config[edl->session->playback_strategy].values[0]->vconfig;
131         AudioOutConfig *aconfig = mwindow->edl->session->playback_config[edl->session->playback_strategy].values[0]->aconfig;
132         VideoOutConfig *vconfig = mwindow->edl->session->playback_config[edl->session->playback_strategy].values[0]->vconfig;
135         rerender = 
136                 (edl->session->playback_preload != mwindow->edl->session->playback_preload) ||
137                 (edl->session->interpolation_type != mwindow->edl->session->interpolation_type) ||
138                 (edl->session->video_every_frame != mwindow->edl->session->video_every_frame) ||
139                 (edl->session->real_time_playback != mwindow->edl->session->real_time_playback) ||
140                 (edl->session->playback_software_position != mwindow->edl->session->playback_software_position) ||
141                 (edl->session->test_playback_edits != mwindow->edl->session->test_playback_edits) ||
142                 (edl->session->playback_buffer != mwindow->edl->session->playback_buffer) ||
143                 (edl->session->audio_module_fragment != mwindow->edl->session->audio_module_fragment) ||
144                 (edl->session->audio_read_length != mwindow->edl->session->audio_read_length) ||
145                 (edl->session->playback_strategy != mwindow->edl->session->playback_strategy) ||
146                 (edl->session->force_uniprocessor != mwindow->edl->session->force_uniprocessor) ||
147                 (*this_aconfig != *aconfig) ||
148                 (*this_vconfig != *vconfig) ||
149                 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
154 // TODO: Need to copy just the parameters in PreferencesThread
155         mwindow->edl->copy_session(edl);
156         *mwindow->preferences = *preferences;
157         mwindow->init_brender();
159         if(redraw_meters)
160         {
161                 mwindow->cwindow->gui->lock_window();
162                 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
163                         edl->session->min_meter_db);
164                 mwindow->cwindow->gui->unlock_window();
168                 mwindow->vwindow->gui->lock_window();
169                 mwindow->vwindow->gui->meters->change_format(edl->session->meter_format,
170                         edl->session->min_meter_db);
171                 mwindow->vwindow->gui->unlock_window();
175                 mwindow->gui->lock_window();
176                 mwindow->gui->patchbay->change_meter_format(edl->session->meter_format,
177                         edl->session->min_meter_db);
178                 mwindow->gui->unlock_window();
182                 mwindow->lwindow->gui->lock_window();
183                 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
184                         edl->session->min_meter_db);
185                 mwindow->lwindow->gui->unlock_window();
186         }
188         if(redraw_overlays)
189         {
190                 mwindow->gui->lock_window();
191                 mwindow->gui->canvas->draw_overlays();
192                 mwindow->gui->canvas->flash();
193                 mwindow->gui->unlock_window();
194         }
196         if(redraw_times)
197         {
198                 mwindow->gui->lock_window();
199                 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
200                 mwindow->gui->redraw_time_dependancies();
201                 mwindow->gui->unlock_window();
202         }
204         if(rerender)
205         {
206                 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
207                         CHANGE_ALL,
208                         mwindow->edl,
209                         1);
210         }
212         if(redraw_times || redraw_overlays)
213         {
214                 mwindow->gui->flush();
215         }
216         return 0;
219 char* PreferencesThread::category_to_text(int category)
221         switch(category)
222         {
223                 case 0:
224                         return _("Playback");
225                         break;
226                 case 1:
227                         return _("Recording");
228                         break;
229                 case 2:
230                         return _("Performance");
231                         break;
232                 case 3:
233                         return _("Interface");
234                         break;
235 //              case 4:
236 //                      return _("Plugin Set");
237 //                      break;
238                 case 4:
239                         return _("About");
240                         break;
241         }
242         return "";
245 int PreferencesThread::text_to_category(char *category)
247         int min_result = -1, result, result_num = 0;
248         for(int i = 0; i < CATEGORIES; i++)
249         {
250                 result = labs(strcmp(category_to_text(i), category));
251                 if(result < min_result || min_result < 0) 
252                 {
253                         min_result = result;
254                         result_num = i;
255                 }
256         }
257         return result_num;
269 #define WIDTH 750
270 #define HEIGHT 700
272 PreferencesWindow::PreferencesWindow(MWindow *mwindow, 
273         PreferencesThread *thread)
274  : BC_Window(PROGRAM_NAME ": Preferences", 
275         mwindow->gui->get_root_w() / 2 - WIDTH / 2,
276         mwindow->gui->get_root_h() / 2 - HEIGHT / 2,
277         WIDTH, 
278         HEIGHT,
279         (int)BC_INFINITY,
280         (int)BC_INFINITY,
281         0,
282         0,
283         1)
285         this->mwindow = mwindow;
286         this->thread = thread;
287         dialog = 0;
290 PreferencesWindow::~PreferencesWindow()
292         delete category;
293         if(dialog) delete dialog;
294         for(int i = 0; i < categories.total; i++)
295                 delete categories.values[i];
298 int PreferencesWindow::create_objects()
300         int x = 10, y = 10;
301         BC_Button *button;
305         mwindow->theme->draw_preferences_bg(this);
306         flash();
309 //printf("PreferencesWindow::create_objects 1\n");
310         for(int i = 0; i < CATEGORIES; i++)
311                 categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
312 //      add_subwindow(new BC_Title(x, y, _("Category:"), LARGEFONT_3D, RED));
313         category = new PreferencesCategory(mwindow, thread, x, y);
314         category->create_objects();
316 //printf("PreferencesWindow::create_objects 1\n");
317         y += category->get_h();
319 //printf("PreferencesWindow::create_objects 1\n");
320         add_subwindow(button = new BC_OKButton(this));
321 //printf("PreferencesWindow::create_objects 1\n");
322         add_subwindow(new PreferencesApply(mwindow, 
323                 thread, 
324                 get_w() / 2 - 50, 
325                 button->get_y()));
326         x = get_w() - 100;
327 //printf("PreferencesWindow::create_objects 1\n");
328         add_subwindow(new BC_CancelButton(this));
330 //printf("PreferencesWindow::create_objects 1\n");
331         set_current_dialog(thread->current_dialog);
332 //printf("PreferencesWindow::create_objects 1\n");
333         show_window();
334 //printf("PreferencesWindow::create_objects 2\n");
335         return 0;
338 int PreferencesWindow::update_framerate()
340         lock_window();
341 //printf("PreferencesWindow::update_framerate 1\n");
342         if(thread->current_dialog == 0)
343         {
344 //printf("PreferencesWindow::update_framerate 2\n");
345                 thread->edl->session->actual_frame_rate = 
346                         mwindow->edl->session->actual_frame_rate;
347 //printf("PreferencesWindow::update_framerate 3\n");
348                 dialog->draw_framerate();
349 //printf("PreferencesWindow::update_framerate 4\n");
350                 flash();
351         }
352 //printf("PreferencesWindow::update_framerate 5\n");
353         unlock_window();
354         return 0;
357 int PreferencesWindow::set_current_dialog(int number)
359         thread->current_dialog = number;
360         if(dialog) delete dialog;
361         dialog = 0;
363         switch(number)
364         {
365                 case 0:
366                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this));
367                         break;
368         
369                 case 1:
370                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
371                         break;
372         
373                 case 2:
374                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
375                         break;
376         
377                 case 3:
378                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
379                         break;
380         
381 //              case 4:
382 //                      add_subwindow(dialog = new PluginPrefs(mwindow, this));
383 //                      break;
384         
385                 case 4:
386                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
387                         break;
388         }
389         if(dialog)
390         {
391                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
392                 dialog->flash();
393                 dialog->create_objects();
394         }
395         return 0;
398 // ================================== save values
402 PreferencesDialog::PreferencesDialog(MWindow *mwindow, PreferencesWindow *pwindow)
403  : BC_SubWindow(10, 40, pwindow->get_w() - 20, pwindow->get_h() - 100)
405         this->pwindow = pwindow;
406         this->mwindow = mwindow;
407         preferences = pwindow->thread->preferences;
410 PreferencesDialog::~PreferencesDialog()
414 // ============================== category window
419 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread, int x, int y)
420  : BC_GenericButton(x, y, _("Apply"))
422         this->mwindow = mwindow;
423         this->thread = thread;
426 PreferencesApply::~PreferencesApply()
430 int PreferencesApply::handle_event()
432         thread->apply_settings();
433         return 1;
438 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
439  : BC_PopupTextBox(thread->window, 
440                 &thread->window->categories,
441                 thread->category_to_text(thread->current_dialog),
442                 x, 
443                 y, 
444                 200,
445                 150)
447         this->mwindow = mwindow;
448         this->thread = thread;
451 PreferencesCategory::~PreferencesCategory()
455 int PreferencesCategory::handle_event()
457         thread->window->set_current_dialog(thread->text_to_category(get_text()));
458         return 1;