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->locale, mwindow->preferences->locale) ||
241 strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) ||
242 preferences->awindow_picon_h != mwindow->preferences->awindow_picon_h ||
243 preferences->layout_scale != mwindow->preferences->layout_scale ||
244 preferences->vicon_size != mwindow->preferences->vicon_size ||
245 preferences->vicon_color_mode != mwindow->preferences->vicon_color_mode )
246 mwindow->restart_status = -1; // reconstruct/restart program
247 if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
249 if( reload_plugins ) {
250 MWindow::remove_plugin_index();
251 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
252 mwindow->restart_status = -1;
255 if( mwindow->preferences->perpetual_session && !preferences->perpetual_session )
256 mwindow->remove_undo_data();
258 mwindow->edl->copy_session(edl, 1);
259 mwindow->update_preferences(preferences);
261 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
262 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
263 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
264 BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
265 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
266 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
267 BC_Trace::enable_locks();
270 BC_Trace::disable_locks();
273 mwindow->reset_android_remote();
274 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
275 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
276 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
277 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
278 mwindow->gui->mainshbtns->load(mwindow->preferences);
279 mwindow->init_brender();
281 //edl->session->recording_format->dump();
282 //mwindow->edl->session->recording_format->dump();
284 if(((mwindow->edl->session->output_w % 4) ||
285 (mwindow->edl->session->output_h % 4)) &&
286 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
288 MainError::show_error(
289 _("This project's dimensions are not multiples of 4 so\n"
290 "it can't be rendered by OpenGL."));
296 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
297 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
298 edl->session->min_meter_db,
299 edl->session->max_meter_db);
300 mwindow->cwindow->gui->unlock_window();
304 for(int i = 0; i < mwindow->vwindows.size(); i++) {
305 VWindow *vwindow = mwindow->vwindows.get(i);
306 if( !vwindow->is_running() ) continue;
307 vwindow->gui->lock_window("PreferencesThread::apply_settings");
308 vwindow->gui->meters->change_format(edl->session->meter_format,
309 edl->session->min_meter_db,
310 edl->session->max_meter_db);
311 vwindow->gui->unlock_window();
316 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
317 mwindow->gui->set_meter_format(edl->session->meter_format,
318 edl->session->min_meter_db,
319 edl->session->max_meter_db);
320 mwindow->gui->unlock_window();
324 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
325 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
326 edl->session->min_meter_db,
327 edl->session->max_meter_db);
328 mwindow->lwindow->gui->unlock_window();
333 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
334 mwindow->gui->show_cursor(0);
335 mwindow->gui->draw_overlays(1);
336 mwindow->gui->unlock_window();
341 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
342 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
343 mwindow->gui->redraw_time_dependancies();
344 mwindow->gui->unlock_window();
349 //printf("PreferencesThread::apply_settings 1\n");
350 // This doesn't stop and restart, only reloads the assets before
351 // the next play command.
352 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
353 //printf("PreferencesThread::apply_settings 10\n");
358 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
359 mwindow->gui->draw_trackmovement();
360 mwindow->gui->unlock_window();
363 if(redraw_times || redraw_overlays || redraw_indexes)
365 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
366 mwindow->gui->flush();
367 mwindow->gui->unlock_window();
373 const char *PreferencesThread::busy()
375 if( mwindow->render->thread->running() )
377 Record *record = mwindow->gui->record;
378 if( record->capturing || record->recording || record->writing_file )
383 const char* PreferencesThread::category_to_text(int category)
385 PlaybackConfig *playback_config = edl->session->playback_config;
389 return playback_config->active_config==0 ?
390 _("*Playback A") : _("Playback A");
392 return playback_config->active_config==1 ?
393 _("*Playback B") : _("Playback B");
395 return _("Recording");
397 return _("Performance");
399 return _("Interface");
401 return _("Appearance");
408 int PreferencesThread::text_to_category(const char *category)
411 int min_result = -1, result, result_num = 0;
412 for(int i = 0; i < CATEGORIES; i++)
414 result = labs(strcmp(category_to_text(i), category));
415 if(result < min_result || min_result < 0)
426 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
427 PreferencesThread *thread, int x, int y, int w, int h)
428 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
430 this->mwindow = mwindow;
431 this->thread = thread;
437 PreferencesWindow::~PreferencesWindow()
439 lock_window("PreferencesWindow::~PreferencesWindow");
442 delete confirm_dialog;
443 for(int i = 0; i < categories.total; i++)
444 delete categories.values[i];
448 void PreferencesWindow::create_objects()
452 lock_window("PreferencesWindow::create_objects");
453 set_icon(mwindow->theme->get_image("mwindow_icon"));
454 mwindow->theme->draw_preferences_bg(this);
457 int x = mwindow->theme->preferencescategory_x;
458 int y = mwindow->theme->preferencescategory_y;
459 for(int i = 0; i < CATEGORIES; i++)
461 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
462 thread, x, y, i, thread->category_to_text(i),
463 (i == thread->current_dialog) ?
464 mwindow->theme->get_image_set("category_button_checked") :
465 mwindow->theme->get_image_set("category_button")));
466 x += category_button[i]->get_w() -
467 mwindow->theme->preferences_category_overlap;
471 // for(int i = 0; i < CATEGORIES; i++)
472 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
473 // category = new PreferencesCategory(mwindow,
475 // mwindow->theme->preferencescategory_x,
476 // mwindow->theme->preferencescategory_y);
477 // category->create_objects();
480 add_subwindow(button = new PreferencesOK(mwindow, thread));
481 add_subwindow(new PreferencesApply(mwindow, thread));
482 add_subwindow(new PreferencesCancel(mwindow, thread));
484 set_current_dialog(thread->current_dialog);
490 int PreferencesWindow::update_framerate()
492 lock_window("PreferencesWindow::update_framerate");
493 if(thread->current_dialog < PreferencesThread::RECORD)
495 dialog->draw_framerate(1);
503 void PreferencesWindow::update_rates()
505 lock_window("PreferencesWindow::update_rates");
506 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
508 dialog->update_rates();
513 void PreferencesWindow::confirm_update(const char *reason, int close)
515 delete confirm_dialog;
516 confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
517 confirm_dialog->start();
521 int PreferencesWindow::set_current_dialog(int number)
523 if(dialog) delete dialog;
525 thread->current_dialog = number;
528 PreferencesDialog *dialog2 = dialog;
532 // Redraw category buttons
533 for(int i = 0; i < CATEGORIES; i++)
537 category_button[i]->set_images(
538 mwindow->theme->get_image_set("category_button_checked"));
542 category_button[i]->set_images(
543 mwindow->theme->get_image_set("category_button"));
545 category_button[i]->draw_face(0);
547 // Copy face to background for next button's overlap.
548 // Still can't do state changes right.
553 PlaybackConfig *playback_config = thread->edl->session->playback_config;
556 case PreferencesThread::PLAYBACK_A:
557 case PreferencesThread::PLAYBACK_B:
558 playback_config->load_defaults(mwindow->defaults,
559 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
560 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
563 case PreferencesThread::RECORD:
564 add_subwindow(dialog = new RecordPrefs(mwindow, this));
567 case PreferencesThread::PERFORMANCE:
568 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
571 case PreferencesThread::INTERFACE:
572 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
575 case PreferencesThread::APPEARANCE:
576 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
579 case PreferencesThread::ABOUT:
580 add_subwindow(dialog = new AboutPrefs(mwindow, this));
587 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
588 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
589 dialog->create_objects();
590 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
591 dialog->lower_window();
592 dialog->show_window(0);
597 dialog2->hide_window(0);
605 PreferencesButton::PreferencesButton(MWindow *mwindow,
606 PreferencesThread *thread,
612 : BC_GenericButton(x, y, text, images)
614 this->mwindow = mwindow;
615 this->thread = thread;
616 this->category = category;
619 int PreferencesButton::handle_event()
621 thread->window->set_current_dialog(category);
626 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
627 PreferencesWindow *pwindow)
628 : BC_SubWindow(xS(10), yS(40),
629 pwindow->get_w() - xS(20),
630 pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
632 this->pwindow = pwindow;
633 this->mwindow = mwindow;
634 preferences = pwindow->thread->preferences;
637 PreferencesDialog::~PreferencesDialog()
642 // ============================== category window
644 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
645 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
646 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
649 this->mwindow = mwindow;
650 this->thread = thread;
652 int PreferencesApply::handle_event()
654 const char *reason = thread->busy();
656 thread->window->confirm_update(reason, 0);
658 thread->apply_settings();
659 mwindow->save_defaults();
663 int PreferencesApply::resize_event(int w, int h)
665 reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
670 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
671 : BC_GenericButton(xS(10),
672 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
675 this->mwindow = mwindow;
676 this->thread = thread;
678 PreferencesOK::~PreferencesOK()
682 int PreferencesOK::keypress_event()
684 if( get_keypress() == RETURN )
685 return handle_event();
689 int PreferencesOK::handle_event()
691 const char *reason = mwindow->restart() ? _("restart") : thread->busy();
693 thread->window->confirm_update(reason, 1);
695 thread->window->set_done(0);
698 int PreferencesOK::resize_event(int w, int h)
700 reposition_window(xS(10), h-get_h()-yS(10));
705 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
706 const char *reason, int close)
708 this->thread = thread;
710 sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
712 PreferencesConfirmDialog::~PreferencesConfirmDialog()
716 BC_Window *PreferencesConfirmDialog::new_gui()
718 qwindow = new PreferencesConfirmWindow(this);
719 qwindow->create_objects(query, 0);
722 void PreferencesConfirmDialog::handle_done_event(int result)
724 if( result != 2 ) return; // not yes
726 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
727 thread->apply_settings();
728 thread->mwindow->save_defaults();
729 thread->window->unlock_window();
732 thread->window->set_done(0);
735 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
736 : QuestionWindow(dialog->thread->mwindow)
738 this->dialog = dialog;
740 PreferencesConfirmWindow::~PreferencesConfirmWindow()
745 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
746 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
747 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
750 this->mwindow = mwindow;
751 this->thread = thread;
753 int PreferencesCancel::keypress_event()
755 if(get_keypress() == ESC)
757 thread->window->set_done(1);
762 int PreferencesCancel::handle_event()
764 thread->window->set_done(1);
767 int PreferencesCancel::resize_event(int w, int h)
769 reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
774 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
775 : BC_PopupTextBox(thread->window,
776 &thread->window->categories,
777 thread->category_to_text(thread->current_dialog),
778 x, y, xS(200), yS(150))
780 this->mwindow = mwindow;
781 this->thread = thread;
784 PreferencesCategory::~PreferencesCategory()
788 int PreferencesCategory::handle_event()
791 thread->window->set_current_dialog(thread->text_to_category(get_text()));