r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / cinelerra / preferencesthread.C
blobf1f5f7aa86057b337f77ad9fce10ca7f1bf9e832
1 #include "aboutprefs.h"
2 #include "asset.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 "language.h"
16 #include "levelwindow.h"
17 #include "levelwindowgui.h"
18 #include "meterpanel.h"
19 #include "mutex.h"
20 #include "mwindow.h"
21 #include "mwindowgui.h"
22 #include "patchbay.h"
23 #include "performanceprefs.h"
24 #include "playbackengine.h"
25 #include "playbackprefs.h"
26 #include "preferences.h"
27 #include "recordprefs.h"
28 #include "theme.h"
29 #include "trackcanvas.h"
30 #include "transportque.h"
31 #include "vwindow.h"
32 #include "vwindowgui.h"
34 #include <string.h>
38 #define WIDTH 750
39 #define HEIGHT 700
42 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
43  : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
45         this->mwindow = mwindow; 
47         set_shift(1);
48         thread = new PreferencesThread(mwindow);
51 PreferencesMenuitem::~PreferencesMenuitem()
53         delete thread;
57 int PreferencesMenuitem::handle_event() 
59         if(!thread->running())
60         {
61                 thread->start();
62         }
63         else
64         {
65 // window_lock has to be locked but window can't be locked until after
66 // it is known to exist, so we neglect window_lock for now
67                 if(thread->window)
68                 {
69                         thread->window_lock->lock("SetFormat::handle_event");
70                         thread->window->lock_window("PreferencesMenuitem::handle_event");
71                         thread->window->raise_window();
72                         thread->window->unlock_window();
73                         thread->window_lock->unlock();
74                 }
75         }
76         return 1;
82 PreferencesThread::PreferencesThread(MWindow *mwindow)
83  : Thread()
85         this->mwindow = mwindow;
86         window = 0;
87         thread_running = 0;
88         window_lock = new Mutex("PreferencesThread::window_lock");
91 PreferencesThread::~PreferencesThread()
93         delete window_lock;
96 void PreferencesThread::run()
98         int need_new_indexes;
100         preferences = new Preferences;
101         edl = new EDL;
102         edl->create_objects();
103         current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
104         preferences->copy_from(mwindow->preferences);
105         edl->copy_session(mwindow->edl);
106         redraw_indexes = 0;
107         redraw_meters = 0;
108         redraw_times = 0;
109         redraw_overlays = 0;
110         close_assets = 0;
111         reload_plugins = 0;
112         need_new_indexes = 0;
113         rerender = 0;
115         int x = mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2;
116         int y = mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2;
118         window_lock->lock("PreferencesThread::run 1");
119         window = new PreferencesWindow(mwindow, this, x, y);
120         window->create_objects();
121         window_lock->unlock();
123         thread_running = 1;
124         int result = window->run_window();
126         thread_running = 0;
127         if(!result)
128         {
129                 apply_settings();
130                 mwindow->save_defaults();
131         }
133         window_lock->lock("PreferencesThread::run 2");
134         delete window;
135         window = 0;
136         window_lock->unlock();
137         delete preferences;
138         delete edl;
140         mwindow->defaults->update("DEFAULTPREF", current_dialog);
143 int PreferencesThread::update_framerate()
145         if(thread_running && window)
146         {
147                 window->update_framerate();
148         }
149         return 0;
152 int PreferencesThread::apply_settings()
154 // Compare sessions                                                                                     
157         AudioOutConfig *this_aconfig = edl->session->playback_config->aconfig;
158         VideoOutConfig *this_vconfig = edl->session->playback_config->vconfig;
159         AudioOutConfig *aconfig = mwindow->edl->session->playback_config->aconfig;
160         VideoOutConfig *vconfig = mwindow->edl->session->playback_config->vconfig;
163         rerender = 
164                 (edl->session->playback_preload != mwindow->edl->session->playback_preload) ||
165                 (edl->session->interpolation_type != mwindow->edl->session->interpolation_type) ||
166                 (edl->session->video_every_frame != mwindow->edl->session->video_every_frame) ||
167                 (edl->session->real_time_playback != mwindow->edl->session->real_time_playback) ||
168                 (edl->session->playback_software_position != mwindow->edl->session->playback_software_position) ||
169                 (edl->session->test_playback_edits != mwindow->edl->session->test_playback_edits) ||
170                 (edl->session->playback_buffer != mwindow->edl->session->playback_buffer) ||
171                 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
172                 (*this_aconfig != *aconfig) ||
173                 (*this_vconfig != *vconfig) ||
174                 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
179 // TODO: Need to copy just the parameters in PreferencesThread
180         mwindow->edl->copy_session(edl);
181         mwindow->preferences->copy_from(preferences);
182         mwindow->init_brender();
184         if(redraw_meters)
185         {
186                 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
187                 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
188                         edl->session->min_meter_db,
189                         edl->session->max_meter_db);
190                 mwindow->cwindow->gui->unlock_window();
194                 mwindow->vwindow->gui->lock_window("PreferencesThread::apply_settings");
195                 mwindow->vwindow->gui->meters->change_format(edl->session->meter_format,
196                         edl->session->min_meter_db,
197                         edl->session->max_meter_db);
198                 mwindow->vwindow->gui->unlock_window();
202                 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
203                 mwindow->gui->patchbay->change_meter_format(edl->session->meter_format,
204                         edl->session->min_meter_db,
205                         edl->session->max_meter_db);
206                 mwindow->gui->unlock_window();
210                 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
211                 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
212                         edl->session->min_meter_db,
213                         edl->session->max_meter_db);
214                 mwindow->lwindow->gui->unlock_window();
215         }
217         if(redraw_overlays)
218         {
219                 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
220                 mwindow->gui->canvas->draw_overlays();
221                 mwindow->gui->canvas->flash();
222                 mwindow->gui->unlock_window();
223         }
225         if(redraw_times)
226         {
227                 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
228                 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
229                 mwindow->gui->redraw_time_dependancies();
230                 mwindow->gui->unlock_window();
231         }
233         if(rerender)
234         {
235                 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
236                         CHANGE_ALL,
237                         mwindow->edl,
238                         1);
239         }
241         if(redraw_times || redraw_overlays)
242         {
243                 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
244                 mwindow->gui->flush();
245                 mwindow->gui->unlock_window();
246         }
247         return 0;
250 char* PreferencesThread::category_to_text(int category)
252         switch(category)
253         {
254                 case 0:
255                         return _("Playback");
256                         break;
257                 case 1:
258                         return _("Recording");
259                         break;
260                 case 2:
261                         return _("Performance");
262                         break;
263                 case 3:
264                         return _("Interface");
265                         break;
266 //              case 4:
267 //                      return _("Plugin Set");
268 //                      break;
269                 case 4:
270                         return _("About");
271                         break;
272         }
273         return "";
276 int PreferencesThread::text_to_category(char *category)
278         int min_result = -1, result, result_num = 0;
279         for(int i = 0; i < CATEGORIES; i++)
280         {
281                 result = labs(strcmp(category_to_text(i), category));
282                 if(result < min_result || min_result < 0) 
283                 {
284                         min_result = result;
285                         result_num = i;
286                 }
287         }
288         return result_num;
298 PreferencesWindow::PreferencesWindow(MWindow *mwindow, 
299         PreferencesThread *thread,
300         int x,
301         int y)
302  : BC_Window(PROGRAM_NAME ": Preferences", 
303         x,
304         y,
305         WIDTH, 
306         HEIGHT,
307         (int)BC_INFINITY,
308         (int)BC_INFINITY,
309         0,
310         0,
311         1)
313         this->mwindow = mwindow;
314         this->thread = thread;
315         dialog = 0;
318 PreferencesWindow::~PreferencesWindow()
320         delete category;
321         if(dialog) delete dialog;
322         for(int i = 0; i < categories.total; i++)
323                 delete categories.values[i];
326 int PreferencesWindow::create_objects()
328         BC_Button *button;
332         mwindow->theme->draw_preferences_bg(this);
333         flash();
336         for(int i = 0; i < CATEGORIES; i++)
337                 categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
338         category = new PreferencesCategory(mwindow, 
339                 thread, 
340                 mwindow->theme->preferencescategory_x, 
341                 mwindow->theme->preferencescategory_y);
342         category->create_objects();
345         add_subwindow(button = new PreferencesOK(mwindow, thread));
346         add_subwindow(new PreferencesApply(mwindow, thread));
347         add_subwindow(new PreferencesCancel(mwindow, thread));
349         set_current_dialog(thread->current_dialog);
350         show_window();
351         return 0;
354 int PreferencesWindow::update_framerate()
356         lock_window("PreferencesWindow::update_framerate");
357         if(thread->current_dialog == 0)
358         {
359                 thread->edl->session->actual_frame_rate = 
360                         mwindow->edl->session->actual_frame_rate;
361                 dialog->draw_framerate();
362                 flash();
363         }
364         unlock_window();
365         return 0;
368 int PreferencesWindow::set_current_dialog(int number)
370         thread->current_dialog = number;
371         if(dialog) delete dialog;
372         dialog = 0;
374         switch(number)
375         {
376                 case 0:
377                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this));
378                         break;
379         
380                 case 1:
381                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
382                         break;
383         
384                 case 2:
385                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
386                         break;
387         
388                 case 3:
389                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
390                         break;
391         
392 //              case 4:
393 //                      add_subwindow(dialog = new PluginPrefs(mwindow, this));
394 //                      break;
395         
396                 case 4:
397                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
398                         break;
399         }
400         if(dialog)
401         {
402                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
403                 dialog->flash();
404                 dialog->create_objects();
405         }
406         return 0;
409 // ================================== save values
413 PreferencesDialog::PreferencesDialog(MWindow *mwindow, PreferencesWindow *pwindow)
414  : BC_SubWindow(10, 
415         40, 
416         pwindow->get_w() - 20, 
417         pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
419         this->pwindow = pwindow;
420         this->mwindow = mwindow;
421         preferences = pwindow->thread->preferences;
424 PreferencesDialog::~PreferencesDialog()
428 // ============================== category window
433 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
434  : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2, 
435         thread->window->get_h() - BC_GenericButton::calculate_h() - 10, 
436         _("Apply"))
438         this->mwindow = mwindow;
439         this->thread = thread;
442 int PreferencesApply::handle_event()
444         thread->apply_settings();
445         return 1;
451 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
452  : BC_GenericButton(10, 
453         thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
454         _("OK"))
456         this->mwindow = mwindow;
457         this->thread = thread;
460 int PreferencesOK::keypress_event()
462         if(get_keypress() == RETURN)
463         {
464                 thread->window->set_done(0);
465                 return 1;
466         }
467         return 0;
469 int PreferencesOK::handle_event()
471         thread->window->set_done(0);
472         return 1;
477 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
478  : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
479         thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
480         _("Cancel"))
482         this->mwindow = mwindow;
483         this->thread = thread;
485 int PreferencesCancel::keypress_event()
487         if(get_keypress() == ESC)
488         {
489                 thread->window->set_done(1);
490                 return 1;
491         }
492         return 0;
495 int PreferencesCancel::handle_event()
497         thread->window->set_done(1);
498         return 1;
510 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
511  : BC_PopupTextBox(thread->window, 
512                 &thread->window->categories,
513                 thread->category_to_text(thread->current_dialog),
514                 x, 
515                 y, 
516                 200,
517                 150)
519         this->mwindow = mwindow;
520         this->thread = thread;
523 PreferencesCategory::~PreferencesCategory()
527 int PreferencesCategory::handle_event()
529         thread->window->set_current_dialog(thread->text_to_category(get_text()));
530         return 1;