1 #include "aboutprefs.h"
3 #include "audiodevice.inc"
7 #include "cwindowgui.h"
10 #include "edlsession.h"
11 #include "filesystem.h"
13 #include "interfaceprefs.h"
16 #include "levelwindow.h"
17 #include "levelwindowgui.h"
18 #include "meterpanel.h"
21 #include "mwindowgui.h"
23 #include "performanceprefs.h"
24 #include "playbackengine.h"
25 #include "playbackprefs.h"
26 #include "preferences.h"
27 #include "recordprefs.h"
29 #include "trackcanvas.h"
30 #include "transportque.h"
32 #include "vwindowgui.h"
42 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
43 : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
45 this->mwindow = mwindow;
48 thread = new PreferencesThread(mwindow);
51 PreferencesMenuitem::~PreferencesMenuitem()
57 int PreferencesMenuitem::handle_event()
59 if(!thread->running())
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
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();
82 PreferencesThread::PreferencesThread(MWindow *mwindow)
85 this->mwindow = mwindow;
88 window_lock = new Mutex("PreferencesThread::window_lock");
91 PreferencesThread::~PreferencesThread()
96 void PreferencesThread::run()
100 preferences = new Preferences;
102 edl->create_objects();
103 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
104 preferences->copy_from(mwindow->preferences);
105 edl->copy_session(mwindow->edl);
112 need_new_indexes = 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();
124 int result = window->run_window();
130 mwindow->save_defaults();
133 window_lock->lock("PreferencesThread::run 2");
136 window_lock->unlock();
140 mwindow->defaults->update("DEFAULTPREF", current_dialog);
143 int PreferencesThread::update_framerate()
145 if(thread_running && window)
147 window->update_framerate();
152 int PreferencesThread::apply_settings()
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;
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();
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();
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();
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();
235 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
241 if(redraw_times || redraw_overlays)
243 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
244 mwindow->gui->flush();
245 mwindow->gui->unlock_window();
250 char* PreferencesThread::category_to_text(int category)
255 return _("Playback");
258 return _("Recording");
261 return _("Performance");
264 return _("Interface");
267 // return _("Plugin Set");
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++)
281 result = labs(strcmp(category_to_text(i), category));
282 if(result < min_result || min_result < 0)
298 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
299 PreferencesThread *thread,
302 : BC_Window(PROGRAM_NAME ": Preferences",
313 this->mwindow = mwindow;
314 this->thread = thread;
318 PreferencesWindow::~PreferencesWindow()
321 if(dialog) delete dialog;
322 for(int i = 0; i < categories.total; i++)
323 delete categories.values[i];
326 int PreferencesWindow::create_objects()
332 mwindow->theme->draw_preferences_bg(this);
336 for(int i = 0; i < CATEGORIES; i++)
337 categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
338 category = new PreferencesCategory(mwindow,
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);
354 int PreferencesWindow::update_framerate()
356 lock_window("PreferencesWindow::update_framerate");
357 if(thread->current_dialog == 0)
359 thread->edl->session->actual_frame_rate =
360 mwindow->edl->session->actual_frame_rate;
361 dialog->draw_framerate();
368 int PreferencesWindow::set_current_dialog(int number)
370 thread->current_dialog = number;
371 if(dialog) delete dialog;
377 add_subwindow(dialog = new PlaybackPrefs(mwindow, this));
381 add_subwindow(dialog = new RecordPrefs(mwindow, this));
385 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
389 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
393 // add_subwindow(dialog = new PluginPrefs(mwindow, this));
397 add_subwindow(dialog = new AboutPrefs(mwindow, this));
402 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
404 dialog->create_objects();
409 // ================================== save values
413 PreferencesDialog::PreferencesDialog(MWindow *mwindow, PreferencesWindow *pwindow)
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,
438 this->mwindow = mwindow;
439 this->thread = thread;
442 int PreferencesApply::handle_event()
444 thread->apply_settings();
451 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
452 : BC_GenericButton(10,
453 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
456 this->mwindow = mwindow;
457 this->thread = thread;
460 int PreferencesOK::keypress_event()
462 if(get_keypress() == RETURN)
464 thread->window->set_done(0);
469 int PreferencesOK::handle_event()
471 thread->window->set_done(0);
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,
482 this->mwindow = mwindow;
483 this->thread = thread;
485 int PreferencesCancel::keypress_event()
487 if(get_keypress() == ESC)
489 thread->window->set_done(1);
495 int PreferencesCancel::handle_event()
497 thread->window->set_done(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),
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()));