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->ffmpeg_toggle->update(ffmpeg_early_probe);
282 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
283 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
284 mwindow->gui->mainshbtns->load(mwindow->preferences);
285 mwindow->init_brender();
287 //edl->session->recording_format->dump();
288 //mwindow->edl->session->recording_format->dump();
290 if(((mwindow->edl->session->output_w % 4) ||
291 (mwindow->edl->session->output_h % 4)) &&
292 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
294 MainError::show_error(
295 _("This project's dimensions are not multiples of 4 so\n"
296 "it can't be rendered by OpenGL."));
302 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
303 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
304 edl->session->min_meter_db,
305 edl->session->max_meter_db);
306 mwindow->cwindow->gui->unlock_window();
310 for(int i = 0; i < mwindow->vwindows.size(); i++) {
311 VWindow *vwindow = mwindow->vwindows.get(i);
312 if( !vwindow->is_running() ) continue;
313 vwindow->gui->lock_window("PreferencesThread::apply_settings");
314 vwindow->gui->meters->change_format(edl->session->meter_format,
315 edl->session->min_meter_db,
316 edl->session->max_meter_db);
317 vwindow->gui->unlock_window();
322 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
323 mwindow->gui->set_meter_format(edl->session->meter_format,
324 edl->session->min_meter_db,
325 edl->session->max_meter_db);
326 mwindow->gui->unlock_window();
330 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
331 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
332 edl->session->min_meter_db,
333 edl->session->max_meter_db);
334 mwindow->lwindow->gui->unlock_window();
339 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
340 mwindow->gui->show_cursor(0);
341 mwindow->gui->draw_overlays(1);
342 mwindow->gui->unlock_window();
347 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
348 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
349 mwindow->gui->redraw_time_dependancies();
350 mwindow->gui->unlock_window();
355 //printf("PreferencesThread::apply_settings 1\n");
356 // This doesn't stop and restart, only reloads the assets before
357 // the next play command.
358 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
359 //printf("PreferencesThread::apply_settings 10\n");
364 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
365 mwindow->gui->draw_trackmovement();
366 mwindow->gui->unlock_window();
369 if(redraw_times || redraw_overlays || redraw_indexes)
371 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
372 mwindow->gui->flush();
373 mwindow->gui->unlock_window();
379 const char *PreferencesThread::busy()
381 if( mwindow->render->thread->running() )
383 Record *record = mwindow->gui->record;
384 if( record->capturing || record->recording || record->writing_file )
389 const char* PreferencesThread::category_to_text(int category)
391 PlaybackConfig *playback_config = edl->session->playback_config;
395 return playback_config->active_config==0 ?
396 _("*Playback A") : _("Playback A");
398 return playback_config->active_config==1 ?
399 _("*Playback B") : _("Playback B");
401 return _("Recording");
403 return _("Performance");
405 return _("Interface");
407 return _("Appearance");
414 int PreferencesThread::text_to_category(const char *category)
417 int min_result = -1, result, result_num = 0;
418 for(int i = 0; i < CATEGORIES; i++)
420 result = labs(strcmp(category_to_text(i), category));
421 if(result < min_result || min_result < 0)
432 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
433 PreferencesThread *thread, int x, int y, int w, int h)
434 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
436 this->mwindow = mwindow;
437 this->thread = thread;
443 PreferencesWindow::~PreferencesWindow()
445 lock_window("PreferencesWindow::~PreferencesWindow");
448 delete confirm_dialog;
449 for(int i = 0; i < categories.total; i++)
450 delete categories.values[i];
454 void PreferencesWindow::create_objects()
458 lock_window("PreferencesWindow::create_objects");
459 set_icon(mwindow->theme->get_image("mwindow_icon"));
460 mwindow->theme->draw_preferences_bg(this);
463 int x = mwindow->theme->preferencescategory_x;
464 int y = mwindow->theme->preferencescategory_y;
465 for(int i = 0; i < CATEGORIES; i++)
467 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
468 thread, x, y, i, thread->category_to_text(i),
469 (i == thread->current_dialog) ?
470 mwindow->theme->get_image_set("category_button_checked") :
471 mwindow->theme->get_image_set("category_button")));
472 x += category_button[i]->get_w() -
473 mwindow->theme->preferences_category_overlap;
477 // for(int i = 0; i < CATEGORIES; i++)
478 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
479 // category = new PreferencesCategory(mwindow,
481 // mwindow->theme->preferencescategory_x,
482 // mwindow->theme->preferencescategory_y);
483 // category->create_objects();
486 add_subwindow(button = new PreferencesOK(mwindow, thread));
487 add_subwindow(new PreferencesApply(mwindow, thread));
488 add_subwindow(new PreferencesCancel(mwindow, thread));
490 set_current_dialog(thread->current_dialog);
496 int PreferencesWindow::update_framerate()
498 lock_window("PreferencesWindow::update_framerate");
499 if(thread->current_dialog < PreferencesThread::RECORD)
501 dialog->draw_framerate(1);
509 void PreferencesWindow::update_rates()
511 lock_window("PreferencesWindow::update_rates");
512 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
514 dialog->update_rates();
519 void PreferencesWindow::confirm_update(const char *reason, int close)
521 delete confirm_dialog;
522 confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
523 confirm_dialog->start();
527 int PreferencesWindow::set_current_dialog(int number)
529 if(dialog) delete dialog;
531 thread->current_dialog = number;
534 PreferencesDialog *dialog2 = dialog;
538 // Redraw category buttons
539 for(int i = 0; i < CATEGORIES; i++)
543 category_button[i]->set_images(
544 mwindow->theme->get_image_set("category_button_checked"));
548 category_button[i]->set_images(
549 mwindow->theme->get_image_set("category_button"));
551 category_button[i]->draw_face(0);
553 // Copy face to background for next button's overlap.
554 // Still can't do state changes right.
559 PlaybackConfig *playback_config = thread->edl->session->playback_config;
562 case PreferencesThread::PLAYBACK_A:
563 case PreferencesThread::PLAYBACK_B:
564 playback_config->load_defaults(mwindow->defaults,
565 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
566 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
569 case PreferencesThread::RECORD:
570 add_subwindow(dialog = new RecordPrefs(mwindow, this));
573 case PreferencesThread::PERFORMANCE:
574 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
577 case PreferencesThread::INTERFACE:
578 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
581 case PreferencesThread::APPEARANCE:
582 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
585 case PreferencesThread::ABOUT:
586 add_subwindow(dialog = new AboutPrefs(mwindow, this));
593 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
594 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
595 dialog->create_objects();
596 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
597 dialog->lower_window();
598 dialog->show_window(0);
603 dialog2->hide_window(0);
611 PreferencesButton::PreferencesButton(MWindow *mwindow,
612 PreferencesThread *thread,
618 : BC_GenericButton(x, y, text, images)
620 this->mwindow = mwindow;
621 this->thread = thread;
622 this->category = category;
625 int PreferencesButton::handle_event()
627 thread->window->set_current_dialog(category);
632 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
633 PreferencesWindow *pwindow)
634 : BC_SubWindow(xS(10), yS(40),
635 pwindow->get_w() - xS(20),
636 pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
638 this->pwindow = pwindow;
639 this->mwindow = mwindow;
640 preferences = pwindow->thread->preferences;
643 PreferencesDialog::~PreferencesDialog()
648 // ============================== category window
650 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
651 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
652 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
655 this->mwindow = mwindow;
656 this->thread = thread;
658 int PreferencesApply::handle_event()
660 const char *reason = thread->busy();
662 thread->window->confirm_update(reason, 0);
664 thread->apply_settings();
665 mwindow->save_defaults();
669 int PreferencesApply::resize_event(int w, int h)
671 reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
676 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
677 : BC_GenericButton(xS(10),
678 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
681 this->mwindow = mwindow;
682 this->thread = thread;
684 PreferencesOK::~PreferencesOK()
688 int PreferencesOK::keypress_event()
690 if( get_keypress() == RETURN )
691 return handle_event();
695 int PreferencesOK::handle_event()
697 const char *reason = mwindow->restart() ? _("restart") : thread->busy();
699 thread->window->confirm_update(reason, 1);
701 thread->window->set_done(0);
704 int PreferencesOK::resize_event(int w, int h)
706 reposition_window(xS(10), h-get_h()-yS(10));
711 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
712 const char *reason, int close)
714 this->thread = thread;
716 sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
718 PreferencesConfirmDialog::~PreferencesConfirmDialog()
722 BC_Window *PreferencesConfirmDialog::new_gui()
724 qwindow = new PreferencesConfirmWindow(this);
725 qwindow->create_objects(query, 0);
728 void PreferencesConfirmDialog::handle_done_event(int result)
730 if( result != 2 ) return; // not yes
732 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
733 thread->apply_settings();
734 thread->mwindow->save_defaults();
735 thread->window->unlock_window();
738 thread->window->set_done(0);
741 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
742 : QuestionWindow(dialog->thread->mwindow)
744 this->dialog = dialog;
746 PreferencesConfirmWindow::~PreferencesConfirmWindow()
751 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
752 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
753 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
756 this->mwindow = mwindow;
757 this->thread = thread;
759 int PreferencesCancel::keypress_event()
761 if(get_keypress() == ESC)
763 thread->window->set_done(1);
768 int PreferencesCancel::handle_event()
770 thread->window->set_done(1);
773 int PreferencesCancel::resize_event(int w, int h)
775 reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
780 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
781 : BC_PopupTextBox(thread->window,
782 &thread->window->categories,
783 thread->category_to_text(thread->current_dialog),
784 x, y, xS(200), yS(150))
786 this->mwindow = mwindow;
787 this->thread = thread;
790 PreferencesCategory::~PreferencesCategory()
794 int PreferencesCategory::handle_event()
797 thread->window->set_current_dialog(thread->text_to_category(get_text()));