4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "aboutprefs.h"
23 #include "appearanceprefs.h"
25 #include "audiodevice.inc"
26 #include "bcsignals.h"
29 #include "cplayback.h"
31 #include "cwindowgui.h"
34 #include "edlsession.h"
36 #include "filesystem.h"
38 #include "interfaceprefs.h"
41 #include "levelwindow.h"
42 #include "levelwindowgui.h"
43 #include "mainclock.h"
44 #include "mainerror.h"
46 #include "meterpanel.h"
49 #include "mwindowgui.h"
51 #include "performanceprefs.h"
52 #include "playbackengine.h"
53 #include "playbackprefs.h"
54 #include "preferences.h"
56 #include "recordprefs.h"
58 #include "shbtnprefs.h"
60 #include "trackcanvas.h"
61 #include "transportque.h"
63 #include "vwindowgui.h"
70 #define HEIGHT yS(700)
73 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
74 : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
76 this->mwindow = mwindow;
79 thread = new PreferencesThread(mwindow);
82 PreferencesMenuitem::~PreferencesMenuitem()
88 int PreferencesMenuitem::handle_event()
90 mwindow->gui->unlock_window();
92 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
99 PreferencesThread::PreferencesThread(MWindow *mwindow)
102 this->mwindow = mwindow;
107 PreferencesThread::~PreferencesThread()
112 BC_Window* PreferencesThread::new_gui()
115 preferences = new Preferences;
117 edl->create_objects();
118 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
119 preferences->copy_from(mwindow->preferences);
120 edl->copy_session(mwindow->edl);
127 //int need_new_indexes = 0;
130 mwindow->gui->lock_window("NewThread::new_gui");
131 int scr_x = mwindow->gui->get_screen_x(0, -1);
132 int scr_w = mwindow->gui->get_screen_w(0, -1);
133 int scr_h = mwindow->gui->get_screen_h(0, -1);
135 int w = WIDTH, h = HEIGHT;
136 int min_w = mwindow->theme->preferencescategory_x;
137 for(int i = 0; i < CATEGORIES; i++) {
138 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
139 mwindow->theme->preferences_category_overlap;
141 if( w < min_w ) w = min_w;
142 int x = scr_x + scr_w / 2 - w / 2;
143 int y = scr_h / 2 - h / 2;
145 window = new PreferencesWindow(mwindow, this, x, y, w, h);
146 window->create_objects();
147 mwindow->gui->unlock_window();
153 void PreferencesThread::handle_close_event(int result)
159 mwindow->save_defaults();
164 edl->Garbage::remove_user();
168 mwindow->defaults->update("DEFAULTPREF", current_dialog);
169 if( mwindow->restart() )
170 mwindow->gui->set_done(0);
175 int PreferencesThread::update_framerate()
179 lock_dialog("PreferencesThread::update_framerate");
180 PreferencesWindow *window = (PreferencesWindow*)get_gui();
181 if(window) window->update_framerate();
188 void PreferencesThread::update_rates()
192 lock_dialog("PreferencesThread::update_framerate");
193 PreferencesWindow *window = (PreferencesWindow*)get_gui();
194 if(window) window->update_rates();
199 int PreferencesThread::apply_settings()
203 PlaybackConfig *this_playback_config = edl->session->playback_config;
204 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
205 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
206 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
207 AudioOutConfig *aconfig = playback_config->aconfig;
208 VideoOutConfig *vconfig = playback_config->vconfig;
211 edl->session->need_rerender(mwindow->edl->session) ||
212 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
213 this_playback_config->active_config != playback_config->active_config ||
214 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
215 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
217 if( preferences->autocolor_assets != mwindow->preferences->autocolor_assets )
220 if( preferences->yuv_color_space != mwindow->preferences->yuv_color_space ||
221 preferences->yuv_color_range != mwindow->preferences->yuv_color_range ) {
222 YUV::yuv.yuv_set_colors(
223 preferences->yuv_color_space,
224 preferences->yuv_color_range);
228 if( preferences->highlight_inverse != mwindow->preferences->highlight_inverse ) {
229 mwindow->gui->lock_window("PreferencesThread::apply_settings 0");
230 mwindow->gui->hide_cursor(0);
231 mwindow->gui->unlock_window();
234 PreferencesWindow *window = (PreferencesWindow*)get_gui();
235 if( window ) window->unlock_window();
236 mwindow->stop_brender();
237 if( window ) window->lock_window("PreferencesThread::apply_settings 5");
239 if( strcmp(preferences->theme, mwindow->preferences->theme) ||
240 strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) ||
241 preferences->awindow_picon_h != mwindow->preferences->awindow_picon_h ||
242 preferences->layout_scale != mwindow->preferences->layout_scale ||
243 preferences->vicon_size != mwindow->preferences->vicon_size ||
244 preferences->vicon_color_mode != mwindow->preferences->vicon_color_mode )
245 mwindow->restart_status = -1; // reconstruct/restart program
246 if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
248 if( reload_plugins ) {
249 MWindow::remove_plugin_index();
250 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
251 mwindow->restart_status = -1;
254 mwindow->edl->copy_session(edl, 1);
255 mwindow->update_preferences(preferences);
257 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
258 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
259 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
260 BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
261 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
262 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
263 BC_Trace::enable_locks();
266 BC_Trace::disable_locks();
269 mwindow->reset_android_remote();
270 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
271 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
272 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
273 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
274 mwindow->gui->mainshbtns->load(mwindow->preferences);
275 mwindow->init_brender();
277 //edl->session->recording_format->dump();
278 //mwindow->edl->session->recording_format->dump();
280 if(((mwindow->edl->session->output_w % 4) ||
281 (mwindow->edl->session->output_h % 4)) &&
282 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
284 MainError::show_error(
285 _("This project's dimensions are not multiples of 4 so\n"
286 "it can't be rendered by OpenGL."));
292 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
293 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
294 edl->session->min_meter_db,
295 edl->session->max_meter_db);
296 mwindow->cwindow->gui->unlock_window();
300 for(int i = 0; i < mwindow->vwindows.size(); i++) {
301 VWindow *vwindow = mwindow->vwindows.get(i);
302 if( !vwindow->is_running() ) continue;
303 vwindow->gui->lock_window("PreferencesThread::apply_settings");
304 vwindow->gui->meters->change_format(edl->session->meter_format,
305 edl->session->min_meter_db,
306 edl->session->max_meter_db);
307 vwindow->gui->unlock_window();
312 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
313 mwindow->gui->set_meter_format(edl->session->meter_format,
314 edl->session->min_meter_db,
315 edl->session->max_meter_db);
316 mwindow->gui->unlock_window();
320 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
321 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
322 edl->session->min_meter_db,
323 edl->session->max_meter_db);
324 mwindow->lwindow->gui->unlock_window();
329 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
330 mwindow->gui->show_cursor(0);
331 mwindow->gui->draw_overlays(1);
332 mwindow->gui->unlock_window();
337 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
338 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
339 mwindow->gui->redraw_time_dependancies();
340 mwindow->gui->unlock_window();
345 //printf("PreferencesThread::apply_settings 1\n");
346 // This doesn't stop and restart, only reloads the assets before
347 // the next play command.
348 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
349 //printf("PreferencesThread::apply_settings 10\n");
354 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
355 mwindow->gui->draw_trackmovement();
356 mwindow->gui->unlock_window();
359 if(redraw_times || redraw_overlays || redraw_indexes)
361 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
362 mwindow->gui->flush();
363 mwindow->gui->unlock_window();
369 const char *PreferencesThread::busy()
371 if( mwindow->render->thread->running() )
373 Record *record = mwindow->gui->record;
374 if( record->capturing || record->recording || record->writing_file )
379 const char* PreferencesThread::category_to_text(int category)
381 PlaybackConfig *playback_config = edl->session->playback_config;
385 return playback_config->active_config==0 ?
386 _("*Playback A") : _("Playback A");
388 return playback_config->active_config==1 ?
389 _("*Playback B") : _("Playback B");
391 return _("Recording");
393 return _("Performance");
395 return _("Interface");
397 return _("Appearance");
404 int PreferencesThread::text_to_category(const char *category)
407 int min_result = -1, result, result_num = 0;
408 for(int i = 0; i < CATEGORIES; i++)
410 result = labs(strcmp(category_to_text(i), category));
411 if(result < min_result || min_result < 0)
422 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
423 PreferencesThread *thread, int x, int y, int w, int h)
424 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
426 this->mwindow = mwindow;
427 this->thread = thread;
433 PreferencesWindow::~PreferencesWindow()
435 lock_window("PreferencesWindow::~PreferencesWindow");
438 delete confirm_dialog;
439 for(int i = 0; i < categories.total; i++)
440 delete categories.values[i];
444 void PreferencesWindow::create_objects()
448 lock_window("PreferencesWindow::create_objects");
449 set_icon(mwindow->theme->get_image("mwindow_icon"));
450 mwindow->theme->draw_preferences_bg(this);
453 int x = mwindow->theme->preferencescategory_x;
454 int y = mwindow->theme->preferencescategory_y;
455 for(int i = 0; i < CATEGORIES; i++)
457 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
458 thread, x, y, i, thread->category_to_text(i),
459 (i == thread->current_dialog) ?
460 mwindow->theme->get_image_set("category_button_checked") :
461 mwindow->theme->get_image_set("category_button")));
462 x += category_button[i]->get_w() -
463 mwindow->theme->preferences_category_overlap;
467 // for(int i = 0; i < CATEGORIES; i++)
468 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
469 // category = new PreferencesCategory(mwindow,
471 // mwindow->theme->preferencescategory_x,
472 // mwindow->theme->preferencescategory_y);
473 // category->create_objects();
476 add_subwindow(button = new PreferencesOK(mwindow, thread));
477 add_subwindow(new PreferencesApply(mwindow, thread));
478 add_subwindow(new PreferencesCancel(mwindow, thread));
480 set_current_dialog(thread->current_dialog);
486 int PreferencesWindow::update_framerate()
488 lock_window("PreferencesWindow::update_framerate");
489 if(thread->current_dialog < PreferencesThread::RECORD)
491 dialog->draw_framerate(1);
499 void PreferencesWindow::update_rates()
501 lock_window("PreferencesWindow::update_rates");
502 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
504 dialog->update_rates();
509 void PreferencesWindow::confirm_update(const char *reason, int close)
511 delete confirm_dialog;
512 confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
513 confirm_dialog->start();
517 int PreferencesWindow::set_current_dialog(int number)
519 if(dialog) delete dialog;
521 thread->current_dialog = number;
524 PreferencesDialog *dialog2 = dialog;
528 // Redraw category buttons
529 for(int i = 0; i < CATEGORIES; i++)
533 category_button[i]->set_images(
534 mwindow->theme->get_image_set("category_button_checked"));
538 category_button[i]->set_images(
539 mwindow->theme->get_image_set("category_button"));
541 category_button[i]->draw_face(0);
543 // Copy face to background for next button's overlap.
544 // Still can't do state changes right.
549 PlaybackConfig *playback_config = thread->edl->session->playback_config;
552 case PreferencesThread::PLAYBACK_A:
553 case PreferencesThread::PLAYBACK_B:
554 playback_config->load_defaults(mwindow->defaults,
555 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
556 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
559 case PreferencesThread::RECORD:
560 add_subwindow(dialog = new RecordPrefs(mwindow, this));
563 case PreferencesThread::PERFORMANCE:
564 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
567 case PreferencesThread::INTERFACE:
568 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
571 case PreferencesThread::APPEARANCE:
572 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
575 case PreferencesThread::ABOUT:
576 add_subwindow(dialog = new AboutPrefs(mwindow, this));
583 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
584 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
585 dialog->create_objects();
586 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
587 dialog->lower_window();
588 dialog->show_window(0);
593 dialog2->hide_window(0);
601 PreferencesButton::PreferencesButton(MWindow *mwindow,
602 PreferencesThread *thread,
608 : BC_GenericButton(x, y, text, images)
610 this->mwindow = mwindow;
611 this->thread = thread;
612 this->category = category;
615 int PreferencesButton::handle_event()
617 thread->window->set_current_dialog(category);
622 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
623 PreferencesWindow *pwindow)
624 : BC_SubWindow(xS(10), yS(40),
625 pwindow->get_w() - xS(20),
626 pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
628 this->pwindow = pwindow;
629 this->mwindow = mwindow;
630 preferences = pwindow->thread->preferences;
633 PreferencesDialog::~PreferencesDialog()
638 // ============================== category window
640 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
641 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
642 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
645 this->mwindow = mwindow;
646 this->thread = thread;
648 int PreferencesApply::handle_event()
650 const char *reason = thread->busy();
652 thread->window->confirm_update(reason, 0);
654 thread->apply_settings();
655 mwindow->save_defaults();
659 int PreferencesApply::resize_event(int w, int h)
661 reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
666 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
667 : BC_GenericButton(xS(10),
668 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
671 this->mwindow = mwindow;
672 this->thread = thread;
674 PreferencesOK::~PreferencesOK()
678 int PreferencesOK::keypress_event()
680 if( get_keypress() == RETURN )
681 return handle_event();
685 int PreferencesOK::handle_event()
687 const char *reason = mwindow->restart() ? _("restart") : thread->busy();
689 thread->window->confirm_update(reason, 1);
691 thread->window->set_done(0);
694 int PreferencesOK::resize_event(int w, int h)
696 reposition_window(xS(10), h-get_h()-yS(10));
701 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
702 const char *reason, int close)
704 this->thread = thread;
706 sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
708 PreferencesConfirmDialog::~PreferencesConfirmDialog()
712 BC_Window *PreferencesConfirmDialog::new_gui()
714 qwindow = new PreferencesConfirmWindow(this);
715 qwindow->create_objects(query, 0);
718 void PreferencesConfirmDialog::handle_done_event(int result)
720 if( result != 2 ) return; // not yes
722 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
723 thread->apply_settings();
724 thread->mwindow->save_defaults();
725 thread->window->unlock_window();
728 thread->window->set_done(0);
731 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
732 : QuestionWindow(dialog->thread->mwindow)
734 this->dialog = dialog;
736 PreferencesConfirmWindow::~PreferencesConfirmWindow()
741 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
742 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
743 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
746 this->mwindow = mwindow;
747 this->thread = thread;
749 int PreferencesCancel::keypress_event()
751 if(get_keypress() == ESC)
753 thread->window->set_done(1);
758 int PreferencesCancel::handle_event()
760 thread->window->set_done(1);
763 int PreferencesCancel::resize_event(int w, int h)
765 reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
770 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
771 : BC_PopupTextBox(thread->window,
772 &thread->window->categories,
773 thread->category_to_text(thread->current_dialog),
774 x, y, xS(200), yS(150))
776 this->mwindow = mwindow;
777 this->thread = thread;
780 PreferencesCategory::~PreferencesCategory()
784 int PreferencesCategory::handle_event()
787 thread->window->set_current_dialog(thread->text_to_category(get_text()));