1 #include "aboutprefs.h"
3 #include "audiodevice.inc"
8 #include "cwindowgui.h"
11 #include "edlsession.h"
12 #include "filesystem.h"
14 #include "interfaceprefs.h"
17 #include "levelwindow.h"
18 #include "levelwindowgui.h"
19 #include "mainerror.h"
20 #include "meterpanel.h"
23 #include "mwindowgui.h"
25 #include "performanceprefs.h"
26 #include "playbackengine.h"
27 #include "playbackprefs.h"
28 #include "preferences.h"
29 #include "recordprefs.h"
31 #include "trackcanvas.h"
32 #include "transportque.h"
34 #include "vwindowgui.h"
44 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
45 : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
47 this->mwindow = mwindow;
50 thread = new PreferencesThread(mwindow);
53 PreferencesMenuitem::~PreferencesMenuitem()
59 int PreferencesMenuitem::handle_event()
61 if(!thread->running())
67 // window_lock has to be locked but window can't be locked until after
68 // it is known to exist, so we neglect window_lock for now
71 thread->window_lock->lock("SetFormat::handle_event");
72 thread->window->lock_window("PreferencesMenuitem::handle_event");
73 thread->window->raise_window();
74 thread->window->unlock_window();
75 thread->window_lock->unlock();
84 PreferencesThread::PreferencesThread(MWindow *mwindow)
87 this->mwindow = mwindow;
90 window_lock = new Mutex("PreferencesThread::window_lock");
93 PreferencesThread::~PreferencesThread()
98 void PreferencesThread::run()
100 int need_new_indexes;
102 preferences = new Preferences;
104 edl->create_objects();
105 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
106 preferences->copy_from(mwindow->preferences);
107 edl->copy_session(mwindow->edl);
114 need_new_indexes = 0;
117 int x = mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2;
118 int y = mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2;
120 window_lock->lock("PreferencesThread::run 1");
121 window = new PreferencesWindow(mwindow, this, x, y);
122 window->create_objects();
123 window_lock->unlock();
126 int result = window->run_window();
132 mwindow->save_defaults();
135 window_lock->lock("PreferencesThread::run 2");
138 window_lock->unlock();
142 mwindow->defaults->update("DEFAULTPREF", current_dialog);
145 int PreferencesThread::update_framerate()
147 if(thread_running && window)
149 window->update_framerate();
154 int PreferencesThread::apply_settings()
159 AudioOutConfig *this_aconfig = edl->session->playback_config->aconfig;
160 VideoOutConfig *this_vconfig = edl->session->playback_config->vconfig;
161 AudioOutConfig *aconfig = mwindow->edl->session->playback_config->aconfig;
162 VideoOutConfig *vconfig = mwindow->edl->session->playback_config->vconfig;
166 edl->session->need_rerender(mwindow->edl->session) ||
167 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
168 (*this_aconfig != *aconfig) ||
169 (*this_vconfig != *vconfig) ||
170 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
175 mwindow->edl->copy_session(edl, 1);
176 mwindow->preferences->copy_from(preferences);
177 mwindow->init_brender();
179 if(((mwindow->edl->session->output_w % 4) ||
180 (mwindow->edl->session->output_h % 4)) &&
181 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
183 MainError::show_error(
184 _("This project's dimensions are not multiples of 4 so\n"
185 "it can't be rendered by OpenGL."));
191 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
192 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
193 edl->session->min_meter_db,
194 edl->session->max_meter_db);
195 mwindow->cwindow->gui->unlock_window();
199 mwindow->vwindow->gui->lock_window("PreferencesThread::apply_settings");
200 mwindow->vwindow->gui->meters->change_format(edl->session->meter_format,
201 edl->session->min_meter_db,
202 edl->session->max_meter_db);
203 mwindow->vwindow->gui->unlock_window();
207 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
208 mwindow->gui->patchbay->change_meter_format(edl->session->meter_format,
209 edl->session->min_meter_db,
210 edl->session->max_meter_db);
211 mwindow->gui->unlock_window();
215 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
216 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
217 edl->session->min_meter_db,
218 edl->session->max_meter_db);
219 mwindow->lwindow->gui->unlock_window();
224 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
225 mwindow->gui->canvas->draw_overlays();
226 mwindow->gui->canvas->flash();
227 mwindow->gui->unlock_window();
232 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
233 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
234 mwindow->gui->redraw_time_dependancies();
235 mwindow->gui->unlock_window();
240 //printf("PreferencesThread::apply_settings 1\n");
241 // This doesn't stop and restart, only reloads the assets before
242 // the next play command.
243 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
247 //printf("PreferencesThread::apply_settings 10\n");
250 if(redraw_times || redraw_overlays)
252 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
253 mwindow->gui->flush();
254 mwindow->gui->unlock_window();
259 char* PreferencesThread::category_to_text(int category)
264 return _("Playback");
267 return _("Recording");
270 return _("Performance");
273 return _("Interface");
282 int PreferencesThread::text_to_category(char *category)
285 int min_result = -1, result, result_num = 0;
286 for(int i = 0; i < CATEGORIES; i++)
288 result = labs(strcmp(category_to_text(i), category));
289 if(result < min_result || min_result < 0)
306 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
307 PreferencesThread *thread,
310 : BC_Window(PROGRAM_NAME ": Preferences",
321 this->mwindow = mwindow;
322 this->thread = thread;
327 PreferencesWindow::~PreferencesWindow()
330 if(dialog) delete dialog;
331 for(int i = 0; i < categories.total; i++)
332 delete categories.values[i];
335 int PreferencesWindow::create_objects()
341 mwindow->theme->draw_preferences_bg(this);
344 int x = mwindow->theme->preferencescategory_x;
345 int y = mwindow->theme->preferencescategory_y;
346 for(int i = 0; i < CATEGORIES; i++)
348 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
353 thread->category_to_text(i),
354 (i == thread->current_dialog) ?
355 mwindow->theme->get_image_set("category_button_checked") :
356 mwindow->theme->get_image_set("category_button")));
357 x += category_button[i]->get_w() -
358 mwindow->theme->preferences_category_overlap;
362 // for(int i = 0; i < CATEGORIES; i++)
363 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
364 // category = new PreferencesCategory(mwindow,
366 // mwindow->theme->preferencescategory_x,
367 // mwindow->theme->preferencescategory_y);
368 // category->create_objects();
371 add_subwindow(button = new PreferencesOK(mwindow, thread));
372 add_subwindow(new PreferencesApply(mwindow, thread));
373 add_subwindow(new PreferencesCancel(mwindow, thread));
375 set_current_dialog(thread->current_dialog);
380 int PreferencesWindow::update_framerate()
382 lock_window("PreferencesWindow::update_framerate");
383 if(thread->current_dialog == 0)
385 thread->edl->session->actual_frame_rate =
386 mwindow->edl->session->actual_frame_rate;
387 dialog->draw_framerate();
394 int PreferencesWindow::set_current_dialog(int number)
396 thread->current_dialog = number;
397 if(dialog) delete dialog;
400 // Redraw category buttons
401 for(int i = 0; i < CATEGORIES; i++)
405 category_button[i]->set_images(
406 mwindow->theme->get_image_set("category_button_checked"));
410 category_button[i]->set_images(
411 mwindow->theme->get_image_set("category_button"));
413 category_button[i]->draw_face();
415 // Copy face to background for next button's overlap.
416 // Still can't to state changes right.
421 case PreferencesThread::PLAYBACK:
422 add_subwindow(dialog = new PlaybackPrefs(mwindow, this));
425 case PreferencesThread::RECORD:
426 add_subwindow(dialog = new RecordPrefs(mwindow, this));
429 case PreferencesThread::PERFORMANCE:
430 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
433 case PreferencesThread::INTERFACE:
434 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
437 case PreferencesThread::ABOUT:
438 add_subwindow(dialog = new AboutPrefs(mwindow, this));
444 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
446 dialog->create_objects();
461 PreferencesButton::PreferencesButton(MWindow *mwindow,
462 PreferencesThread *thread,
468 : BC_GenericButton(x, y, text, images)
470 this->mwindow = mwindow;
471 this->thread = thread;
472 this->category = category;
475 int PreferencesButton::handle_event()
477 thread->window->set_current_dialog(category);
489 PreferencesDialog::PreferencesDialog(MWindow *mwindow, PreferencesWindow *pwindow)
492 pwindow->get_w() - 20,
493 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
495 this->pwindow = pwindow;
496 this->mwindow = mwindow;
497 preferences = pwindow->thread->preferences;
500 PreferencesDialog::~PreferencesDialog()
504 // ============================== category window
509 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
510 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
511 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
514 this->mwindow = mwindow;
515 this->thread = thread;
518 int PreferencesApply::handle_event()
520 thread->apply_settings();
527 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
528 : BC_GenericButton(10,
529 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
532 this->mwindow = mwindow;
533 this->thread = thread;
536 int PreferencesOK::keypress_event()
538 if(get_keypress() == RETURN)
540 thread->window->set_done(0);
545 int PreferencesOK::handle_event()
547 thread->window->set_done(0);
553 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
554 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
555 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
558 this->mwindow = mwindow;
559 this->thread = thread;
561 int PreferencesCancel::keypress_event()
563 if(get_keypress() == ESC)
565 thread->window->set_done(1);
571 int PreferencesCancel::handle_event()
573 thread->window->set_done(1);
586 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
587 : BC_PopupTextBox(thread->window,
588 &thread->window->categories,
589 thread->category_to_text(thread->current_dialog),
595 this->mwindow = mwindow;
596 this->thread = thread;
599 PreferencesCategory::~PreferencesCategory()
603 int PreferencesCategory::handle_event()
606 thread->window->set_current_dialog(thread->text_to_category(get_text()));
613 // c-file-style: "linux"