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);
128 //int need_new_indexes = 0;
131 mwindow->gui->lock_window("NewThread::new_gui");
132 int scr_x = mwindow->gui->get_screen_x(0, -1);
133 int scr_w = mwindow->gui->get_screen_w(0, -1);
134 int scr_h = mwindow->gui->get_screen_h(0, -1);
136 int w = WIDTH, h = HEIGHT;
137 int min_w = mwindow->theme->preferencescategory_x;
138 for(int i = 0; i < CATEGORIES; i++) {
139 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
140 mwindow->theme->preferences_category_overlap;
142 if( w < min_w ) w = min_w;
143 int x = scr_x + scr_w / 2 - w / 2;
144 int y = scr_h / 2 - h / 2;
146 window = new PreferencesWindow(mwindow, this, x, y, w, h);
147 window->create_objects();
148 mwindow->gui->unlock_window();
154 void PreferencesThread::handle_close_event(int result)
160 mwindow->save_defaults();
165 edl->Garbage::remove_user();
169 mwindow->defaults->update("DEFAULTPREF", current_dialog);
170 if( mwindow->restart() )
171 mwindow->gui->set_done(0);
176 int PreferencesThread::update_framerate()
180 lock_dialog("PreferencesThread::update_framerate");
181 PreferencesWindow *window = (PreferencesWindow*)get_gui();
182 if(window) window->update_framerate();
189 void PreferencesThread::update_rates()
193 lock_dialog("PreferencesThread::update_framerate");
194 PreferencesWindow *window = (PreferencesWindow*)get_gui();
195 if(window) window->update_rates();
200 int PreferencesThread::apply_settings()
204 PlaybackConfig *this_playback_config = edl->session->playback_config;
205 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
206 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
207 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
208 AudioOutConfig *aconfig = playback_config->aconfig;
209 VideoOutConfig *vconfig = playback_config->vconfig;
212 edl->session->need_rerender(mwindow->edl->session) ||
213 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
214 this_playback_config->active_config != playback_config->active_config ||
215 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
216 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
218 if( preferences->autocolor_assets != mwindow->preferences->autocolor_assets )
221 if( preferences->yuv_color_space != mwindow->preferences->yuv_color_space ||
222 preferences->yuv_color_range != mwindow->preferences->yuv_color_range ) {
223 YUV::yuv.yuv_set_colors(
224 preferences->yuv_color_space,
225 preferences->yuv_color_range);
229 if( preferences->highlight_inverse != mwindow->preferences->highlight_inverse ) {
230 mwindow->gui->lock_window("PreferencesThread::apply_settings 0");
231 mwindow->gui->hide_cursor(0);
232 mwindow->gui->unlock_window();
235 PreferencesWindow *window = (PreferencesWindow*)get_gui();
236 if( window ) window->unlock_window();
237 mwindow->stop_brender();
238 if( window ) window->lock_window("PreferencesThread::apply_settings 5");
240 if( strcmp(preferences->theme, mwindow->preferences->theme) ||
241 strcmp(preferences->locale, mwindow->preferences->locale) ||
242 strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) ||
243 preferences->awindow_picon_h != mwindow->preferences->awindow_picon_h ||
244 preferences->layout_scale != mwindow->preferences->layout_scale ||
245 preferences->vicon_size != mwindow->preferences->vicon_size ||
246 preferences->vicon_color_mode != mwindow->preferences->vicon_color_mode )
247 mwindow->restart_status = -1; // reconstruct/restart program
248 if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
250 if( reload_plugins ) {
251 MWindow::remove_plugin_index();
252 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
253 mwindow->restart_status = -1;
255 if( preferences->cache_size != mwindow->preferences->cache_size ||
256 preferences->cache_transitions != mwindow->preferences->cache_transitions )
259 if( mwindow->preferences->perpetual_session && !preferences->perpetual_session )
260 mwindow->remove_undo_data();
262 mwindow->edl->copy_session(edl, 1);
263 mwindow->update_preferences(preferences);
265 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
266 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
267 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
268 BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
269 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
270 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
271 BC_Trace::enable_locks();
274 BC_Trace::disable_locks();
277 mwindow->reset_caches(0);
279 mwindow->reset_android_remote();
280 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
281 mwindow->gui->lock_window("PreferencesThread::apply_settings 6");
282 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
283 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
284 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
285 mwindow->gui->unlock_window();
286 mwindow->gui->mainshbtns->load(mwindow->preferences);
287 mwindow->init_brender();
289 //edl->session->recording_format->dump();
290 //mwindow->edl->session->recording_format->dump();
292 if(((mwindow->edl->session->output_w % 4) ||
293 (mwindow->edl->session->output_h % 4)) &&
294 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
296 MainError::show_error(
297 _("This project's dimensions are not multiples of 4 so\n"
298 "it can't be rendered by OpenGL."));
304 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
305 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
306 edl->session->min_meter_db,
307 edl->session->max_meter_db);
308 mwindow->cwindow->gui->unlock_window();
312 for(int i = 0; i < mwindow->vwindows.size(); i++) {
313 VWindow *vwindow = mwindow->vwindows.get(i);
314 if( !vwindow->is_running() ) continue;
315 vwindow->gui->lock_window("PreferencesThread::apply_settings");
316 vwindow->gui->meters->change_format(edl->session->meter_format,
317 edl->session->min_meter_db,
318 edl->session->max_meter_db);
319 vwindow->gui->unlock_window();
324 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
325 mwindow->gui->set_meter_format(edl->session->meter_format,
326 edl->session->min_meter_db,
327 edl->session->max_meter_db);
328 mwindow->gui->unlock_window();
332 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
333 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
334 edl->session->min_meter_db,
335 edl->session->max_meter_db);
336 mwindow->lwindow->gui->unlock_window();
341 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
342 mwindow->gui->show_cursor(0);
343 mwindow->gui->draw_overlays(1);
344 mwindow->gui->unlock_window();
349 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
350 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
351 mwindow->gui->redraw_time_dependancies();
352 mwindow->gui->unlock_window();
357 //printf("PreferencesThread::apply_settings 1\n");
358 // This doesn't stop and restart, only reloads the assets before
359 // the next play command.
360 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
361 //printf("PreferencesThread::apply_settings 10\n");
366 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
367 mwindow->gui->draw_trackmovement();
368 mwindow->gui->unlock_window();
371 if(redraw_times || redraw_overlays || redraw_indexes)
373 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
374 mwindow->gui->flush();
375 mwindow->gui->unlock_window();
381 const char *PreferencesThread::busy()
383 if( mwindow->render->thread->running() )
385 Record *record = mwindow->gui->record;
386 if( record->capturing || record->recording || record->writing_file )
391 const char* PreferencesThread::category_to_text(int category)
393 PlaybackConfig *playback_config = edl->session->playback_config;
397 return playback_config->active_config==0 ?
398 _("*Playback A") : _("Playback A");
400 return playback_config->active_config==1 ?
401 _("*Playback B") : _("Playback B");
403 return _("Recording");
405 return _("Performance");
407 return _("Interface");
409 return _("Appearance");
416 int PreferencesThread::text_to_category(const char *category)
419 int min_result = -1, result, result_num = 0;
420 for(int i = 0; i < CATEGORIES; i++)
422 result = labs(strcmp(category_to_text(i), category));
423 if(result < min_result || min_result < 0)
434 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
435 PreferencesThread *thread, int x, int y, int w, int h)
436 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
438 this->mwindow = mwindow;
439 this->thread = thread;
443 // *** CONTEXT_HELP ***
444 context_help_set_keyword("Settings and Preferences");
447 PreferencesWindow::~PreferencesWindow()
449 lock_window("PreferencesWindow::~PreferencesWindow");
452 delete confirm_dialog;
453 for(int i = 0; i < categories.total; i++)
454 delete categories.values[i];
458 void PreferencesWindow::create_objects()
462 lock_window("PreferencesWindow::create_objects");
463 set_icon(mwindow->theme->get_image("mwindow_icon"));
464 mwindow->theme->draw_preferences_bg(this);
467 int x = mwindow->theme->preferencescategory_x;
468 int y = mwindow->theme->preferencescategory_y;
469 for(int i = 0; i < CATEGORIES; i++)
471 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
472 thread, x, y, i, thread->category_to_text(i),
473 (i == thread->current_dialog) ?
474 mwindow->theme->get_image_set("category_button_checked") :
475 mwindow->theme->get_image_set("category_button")));
476 x += category_button[i]->get_w() -
477 mwindow->theme->preferences_category_overlap;
481 // for(int i = 0; i < CATEGORIES; i++)
482 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
483 // category = new PreferencesCategory(mwindow,
485 // mwindow->theme->preferencescategory_x,
486 // mwindow->theme->preferencescategory_y);
487 // category->create_objects();
490 add_subwindow(button = new PreferencesOK(mwindow, thread));
491 add_subwindow(new PreferencesApply(mwindow, thread));
492 add_subwindow(new PreferencesCancel(mwindow, thread));
494 set_current_dialog(thread->current_dialog);
500 int PreferencesWindow::update_framerate()
502 lock_window("PreferencesWindow::update_framerate");
503 if(thread->current_dialog < PreferencesThread::RECORD)
505 dialog->draw_framerate(1);
513 void PreferencesWindow::update_rates()
515 lock_window("PreferencesWindow::update_rates");
516 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
518 dialog->update_rates();
523 void PreferencesWindow::confirm_update(const char *reason, int close)
525 delete confirm_dialog;
526 confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
527 confirm_dialog->start();
531 int PreferencesWindow::set_current_dialog(int number)
533 if(dialog) delete dialog;
535 thread->current_dialog = number;
538 PreferencesDialog *dialog2 = dialog;
542 // Redraw category buttons
543 for(int i = 0; i < CATEGORIES; i++)
547 category_button[i]->set_images(
548 mwindow->theme->get_image_set("category_button_checked"));
552 category_button[i]->set_images(
553 mwindow->theme->get_image_set("category_button"));
555 category_button[i]->draw_face(0);
557 // Copy face to background for next button's overlap.
558 // Still can't do state changes right.
563 PlaybackConfig *playback_config = thread->edl->session->playback_config;
566 case PreferencesThread::PLAYBACK_A:
567 case PreferencesThread::PLAYBACK_B:
568 playback_config->load_defaults(mwindow->defaults,
569 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
570 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
573 case PreferencesThread::RECORD:
574 add_subwindow(dialog = new RecordPrefs(mwindow, this));
577 case PreferencesThread::PERFORMANCE:
578 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
581 case PreferencesThread::INTERFACE:
582 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
585 case PreferencesThread::APPEARANCE:
586 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
589 case PreferencesThread::ABOUT:
590 add_subwindow(dialog = new AboutPrefs(mwindow, this));
597 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
598 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
599 dialog->create_objects();
600 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
601 dialog->lower_window();
602 dialog->show_window(0);
607 dialog2->hide_window(0);
615 PreferencesButton::PreferencesButton(MWindow *mwindow,
616 PreferencesThread *thread,
622 : BC_GenericButton(x, y, text, images)
624 this->mwindow = mwindow;
625 this->thread = thread;
626 this->category = category;
629 int PreferencesButton::handle_event()
631 thread->window->set_current_dialog(category);
636 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
637 PreferencesWindow *pwindow)
638 : BC_SubWindow(xS(10), yS(40),
639 pwindow->get_w() - xS(20),
640 pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
642 this->pwindow = pwindow;
643 this->mwindow = mwindow;
644 preferences = pwindow->thread->preferences;
647 PreferencesDialog::~PreferencesDialog()
652 // ============================== category window
654 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
655 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
656 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
659 this->mwindow = mwindow;
660 this->thread = thread;
662 int PreferencesApply::handle_event()
664 const char *reason = thread->busy();
666 thread->window->confirm_update(reason, 0);
668 thread->apply_settings();
669 mwindow->save_defaults();
673 int PreferencesApply::resize_event(int w, int h)
675 reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
680 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
681 : BC_GenericButton(xS(10),
682 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
685 this->mwindow = mwindow;
686 this->thread = thread;
688 PreferencesOK::~PreferencesOK()
692 int PreferencesOK::keypress_event()
694 if( get_keypress() == RETURN )
695 return handle_event();
696 return context_help_check_and_show();
699 int PreferencesOK::handle_event()
701 const char *reason = mwindow->restart() ? _("restart") : thread->busy();
703 thread->window->confirm_update(reason, 1);
705 thread->window->set_done(0);
708 int PreferencesOK::resize_event(int w, int h)
710 reposition_window(xS(10), h-get_h()-yS(10));
715 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
716 const char *reason, int close)
718 this->thread = thread;
720 sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
722 PreferencesConfirmDialog::~PreferencesConfirmDialog()
726 BC_Window *PreferencesConfirmDialog::new_gui()
728 qwindow = new PreferencesConfirmWindow(this);
729 qwindow->create_objects(query, 0);
732 void PreferencesConfirmDialog::handle_done_event(int result)
734 if( result != 2 ) return; // not yes
736 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
737 thread->apply_settings();
738 thread->mwindow->save_defaults();
739 thread->window->unlock_window();
742 thread->window->set_done(0);
745 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
746 : QuestionWindow(dialog->thread->mwindow)
748 this->dialog = dialog;
750 PreferencesConfirmWindow::~PreferencesConfirmWindow()
755 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
756 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
757 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
760 this->mwindow = mwindow;
761 this->thread = thread;
763 int PreferencesCancel::keypress_event()
765 if(get_keypress() == ESC)
767 thread->window->set_done(1);
770 return context_help_check_and_show();
772 int PreferencesCancel::handle_event()
774 thread->window->set_done(1);
777 int PreferencesCancel::resize_event(int w, int h)
779 reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
784 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
785 : BC_PopupTextBox(thread->window,
786 &thread->window->categories,
787 thread->category_to_text(thread->current_dialog),
788 x, y, xS(200), yS(150))
790 this->mwindow = mwindow;
791 this->thread = thread;
794 PreferencesCategory::~PreferencesCategory()
798 int PreferencesCategory::handle_event()
801 thread->window->set_current_dialog(thread->text_to_category(get_text()));