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 if( mwindow->preferences->perpetual_session && !preferences->perpetual_session )
255 mwindow->remove_undo_data();
257 mwindow->edl->copy_session(edl, 1);
258 mwindow->update_preferences(preferences);
260 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
261 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
262 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
263 BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
264 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
265 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
266 BC_Trace::enable_locks();
269 BC_Trace::disable_locks();
272 mwindow->reset_android_remote();
273 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
274 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
275 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
276 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
277 mwindow->gui->mainshbtns->load(mwindow->preferences);
278 mwindow->init_brender();
280 //edl->session->recording_format->dump();
281 //mwindow->edl->session->recording_format->dump();
283 if(((mwindow->edl->session->output_w % 4) ||
284 (mwindow->edl->session->output_h % 4)) &&
285 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
287 MainError::show_error(
288 _("This project's dimensions are not multiples of 4 so\n"
289 "it can't be rendered by OpenGL."));
295 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
296 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
297 edl->session->min_meter_db,
298 edl->session->max_meter_db);
299 mwindow->cwindow->gui->unlock_window();
303 for(int i = 0; i < mwindow->vwindows.size(); i++) {
304 VWindow *vwindow = mwindow->vwindows.get(i);
305 if( !vwindow->is_running() ) continue;
306 vwindow->gui->lock_window("PreferencesThread::apply_settings");
307 vwindow->gui->meters->change_format(edl->session->meter_format,
308 edl->session->min_meter_db,
309 edl->session->max_meter_db);
310 vwindow->gui->unlock_window();
315 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
316 mwindow->gui->set_meter_format(edl->session->meter_format,
317 edl->session->min_meter_db,
318 edl->session->max_meter_db);
319 mwindow->gui->unlock_window();
323 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
324 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
325 edl->session->min_meter_db,
326 edl->session->max_meter_db);
327 mwindow->lwindow->gui->unlock_window();
332 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
333 mwindow->gui->show_cursor(0);
334 mwindow->gui->draw_overlays(1);
335 mwindow->gui->unlock_window();
340 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
341 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
342 mwindow->gui->redraw_time_dependancies();
343 mwindow->gui->unlock_window();
348 //printf("PreferencesThread::apply_settings 1\n");
349 // This doesn't stop and restart, only reloads the assets before
350 // the next play command.
351 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
352 //printf("PreferencesThread::apply_settings 10\n");
357 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
358 mwindow->gui->draw_trackmovement();
359 mwindow->gui->unlock_window();
362 if(redraw_times || redraw_overlays || redraw_indexes)
364 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
365 mwindow->gui->flush();
366 mwindow->gui->unlock_window();
372 const char *PreferencesThread::busy()
374 if( mwindow->render->thread->running() )
376 Record *record = mwindow->gui->record;
377 if( record->capturing || record->recording || record->writing_file )
382 const char* PreferencesThread::category_to_text(int category)
384 PlaybackConfig *playback_config = edl->session->playback_config;
388 return playback_config->active_config==0 ?
389 _("*Playback A") : _("Playback A");
391 return playback_config->active_config==1 ?
392 _("*Playback B") : _("Playback B");
394 return _("Recording");
396 return _("Performance");
398 return _("Interface");
400 return _("Appearance");
407 int PreferencesThread::text_to_category(const char *category)
410 int min_result = -1, result, result_num = 0;
411 for(int i = 0; i < CATEGORIES; i++)
413 result = labs(strcmp(category_to_text(i), category));
414 if(result < min_result || min_result < 0)
425 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
426 PreferencesThread *thread, int x, int y, int w, int h)
427 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
429 this->mwindow = mwindow;
430 this->thread = thread;
436 PreferencesWindow::~PreferencesWindow()
438 lock_window("PreferencesWindow::~PreferencesWindow");
441 delete confirm_dialog;
442 for(int i = 0; i < categories.total; i++)
443 delete categories.values[i];
447 void PreferencesWindow::create_objects()
451 lock_window("PreferencesWindow::create_objects");
452 set_icon(mwindow->theme->get_image("mwindow_icon"));
453 mwindow->theme->draw_preferences_bg(this);
456 int x = mwindow->theme->preferencescategory_x;
457 int y = mwindow->theme->preferencescategory_y;
458 for(int i = 0; i < CATEGORIES; i++)
460 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
461 thread, x, y, i, thread->category_to_text(i),
462 (i == thread->current_dialog) ?
463 mwindow->theme->get_image_set("category_button_checked") :
464 mwindow->theme->get_image_set("category_button")));
465 x += category_button[i]->get_w() -
466 mwindow->theme->preferences_category_overlap;
470 // for(int i = 0; i < CATEGORIES; i++)
471 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
472 // category = new PreferencesCategory(mwindow,
474 // mwindow->theme->preferencescategory_x,
475 // mwindow->theme->preferencescategory_y);
476 // category->create_objects();
479 add_subwindow(button = new PreferencesOK(mwindow, thread));
480 add_subwindow(new PreferencesApply(mwindow, thread));
481 add_subwindow(new PreferencesCancel(mwindow, thread));
483 set_current_dialog(thread->current_dialog);
489 int PreferencesWindow::update_framerate()
491 lock_window("PreferencesWindow::update_framerate");
492 if(thread->current_dialog < PreferencesThread::RECORD)
494 dialog->draw_framerate(1);
502 void PreferencesWindow::update_rates()
504 lock_window("PreferencesWindow::update_rates");
505 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
507 dialog->update_rates();
512 void PreferencesWindow::confirm_update(const char *reason, int close)
514 delete confirm_dialog;
515 confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
516 confirm_dialog->start();
520 int PreferencesWindow::set_current_dialog(int number)
522 if(dialog) delete dialog;
524 thread->current_dialog = number;
527 PreferencesDialog *dialog2 = dialog;
531 // Redraw category buttons
532 for(int i = 0; i < CATEGORIES; i++)
536 category_button[i]->set_images(
537 mwindow->theme->get_image_set("category_button_checked"));
541 category_button[i]->set_images(
542 mwindow->theme->get_image_set("category_button"));
544 category_button[i]->draw_face(0);
546 // Copy face to background for next button's overlap.
547 // Still can't do state changes right.
552 PlaybackConfig *playback_config = thread->edl->session->playback_config;
555 case PreferencesThread::PLAYBACK_A:
556 case PreferencesThread::PLAYBACK_B:
557 playback_config->load_defaults(mwindow->defaults,
558 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
559 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
562 case PreferencesThread::RECORD:
563 add_subwindow(dialog = new RecordPrefs(mwindow, this));
566 case PreferencesThread::PERFORMANCE:
567 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
570 case PreferencesThread::INTERFACE:
571 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
574 case PreferencesThread::APPEARANCE:
575 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
578 case PreferencesThread::ABOUT:
579 add_subwindow(dialog = new AboutPrefs(mwindow, this));
586 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
587 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
588 dialog->create_objects();
589 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
590 dialog->lower_window();
591 dialog->show_window(0);
596 dialog2->hide_window(0);
604 PreferencesButton::PreferencesButton(MWindow *mwindow,
605 PreferencesThread *thread,
611 : BC_GenericButton(x, y, text, images)
613 this->mwindow = mwindow;
614 this->thread = thread;
615 this->category = category;
618 int PreferencesButton::handle_event()
620 thread->window->set_current_dialog(category);
625 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
626 PreferencesWindow *pwindow)
627 : BC_SubWindow(xS(10), yS(40),
628 pwindow->get_w() - xS(20),
629 pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
631 this->pwindow = pwindow;
632 this->mwindow = mwindow;
633 preferences = pwindow->thread->preferences;
636 PreferencesDialog::~PreferencesDialog()
641 // ============================== category window
643 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
644 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
645 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
648 this->mwindow = mwindow;
649 this->thread = thread;
651 int PreferencesApply::handle_event()
653 const char *reason = thread->busy();
655 thread->window->confirm_update(reason, 0);
657 thread->apply_settings();
658 mwindow->save_defaults();
662 int PreferencesApply::resize_event(int w, int h)
664 reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
669 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
670 : BC_GenericButton(xS(10),
671 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
674 this->mwindow = mwindow;
675 this->thread = thread;
677 PreferencesOK::~PreferencesOK()
681 int PreferencesOK::keypress_event()
683 if( get_keypress() == RETURN )
684 return handle_event();
688 int PreferencesOK::handle_event()
690 const char *reason = mwindow->restart() ? _("restart") : thread->busy();
692 thread->window->confirm_update(reason, 1);
694 thread->window->set_done(0);
697 int PreferencesOK::resize_event(int w, int h)
699 reposition_window(xS(10), h-get_h()-yS(10));
704 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
705 const char *reason, int close)
707 this->thread = thread;
709 sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
711 PreferencesConfirmDialog::~PreferencesConfirmDialog()
715 BC_Window *PreferencesConfirmDialog::new_gui()
717 qwindow = new PreferencesConfirmWindow(this);
718 qwindow->create_objects(query, 0);
721 void PreferencesConfirmDialog::handle_done_event(int result)
723 if( result != 2 ) return; // not yes
725 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
726 thread->apply_settings();
727 thread->mwindow->save_defaults();
728 thread->window->unlock_window();
731 thread->window->set_done(0);
734 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
735 : QuestionWindow(dialog->thread->mwindow)
737 this->dialog = dialog;
739 PreferencesConfirmWindow::~PreferencesConfirmWindow()
744 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
745 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
746 thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
749 this->mwindow = mwindow;
750 this->thread = thread;
752 int PreferencesCancel::keypress_event()
754 if(get_keypress() == ESC)
756 thread->window->set_done(1);
761 int PreferencesCancel::handle_event()
763 thread->window->set_done(1);
766 int PreferencesCancel::resize_event(int w, int h)
768 reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
773 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
774 : BC_PopupTextBox(thread->window,
775 &thread->window->categories,
776 thread->category_to_text(thread->current_dialog),
777 x, y, xS(200), yS(150))
779 this->mwindow = mwindow;
780 this->thread = thread;
783 PreferencesCategory::~PreferencesCategory()
787 int PreferencesCategory::handle_event()
790 thread->window->set_current_dialog(thread->text_to_category(get_text()));