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"
55 #include "recordprefs.h"
56 #include "shbtnprefs.h"
58 #include "trackcanvas.h"
59 #include "transportque.h"
61 #include "vwindowgui.h"
71 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
72 : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
74 this->mwindow = mwindow;
77 thread = new PreferencesThread(mwindow);
80 PreferencesMenuitem::~PreferencesMenuitem()
86 int PreferencesMenuitem::handle_event()
88 mwindow->gui->unlock_window();
90 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
97 PreferencesThread::PreferencesThread(MWindow *mwindow)
100 this->mwindow = mwindow;
105 PreferencesThread::~PreferencesThread()
110 BC_Window* PreferencesThread::new_gui()
113 preferences = new Preferences;
115 edl->create_objects();
116 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
117 preferences->copy_from(mwindow->preferences);
118 edl->copy_session(mwindow->edl);
125 //int need_new_indexes = 0;
128 mwindow->gui->lock_window("NewThread::new_gui");
129 int scr_x = mwindow->gui->get_screen_x(0, -1);
130 int scr_w = mwindow->gui->get_screen_w(0, -1);
131 int scr_h = mwindow->gui->get_screen_h(0, -1);
133 int w = WIDTH, h = HEIGHT;
134 int min_w = mwindow->theme->preferencescategory_x;
135 for(int i = 0; i < CATEGORIES; i++) {
136 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
137 mwindow->theme->preferences_category_overlap;
139 if( w < min_w ) w = min_w;
140 int x = scr_x + scr_w / 2 - w / 2;
141 int y = scr_h / 2 - h / 2;
143 window = new PreferencesWindow(mwindow, this, x, y, w, h);
144 window->create_objects();
145 mwindow->gui->unlock_window();
151 void PreferencesThread::handle_close_event(int result)
157 mwindow->save_defaults();
162 edl->Garbage::remove_user();
166 mwindow->defaults->update("DEFAULTPREF", current_dialog);
167 if( mwindow->restart() )
168 mwindow->gui->set_done(0);
173 int PreferencesThread::update_framerate()
177 lock_gui("PreferencesThread::update_framerate");
178 PreferencesWindow *window = (PreferencesWindow*)get_gui();
179 if(window) window->update_framerate();
186 void PreferencesThread::update_rates()
190 lock_gui("PreferencesThread::update_framerate");
191 PreferencesWindow *window = (PreferencesWindow*)get_gui();
192 if(window) window->update_rates();
197 int PreferencesThread::apply_settings()
201 PlaybackConfig *this_playback_config = edl->session->playback_config;
202 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
203 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
204 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
205 AudioOutConfig *aconfig = playback_config->aconfig;
206 VideoOutConfig *vconfig = playback_config->vconfig;
209 edl->session->need_rerender(mwindow->edl->session) ||
210 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
211 this_playback_config->active_config != playback_config->active_config ||
212 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
213 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
215 if( preferences->yuv_color_space != mwindow->preferences->yuv_color_space ||
216 preferences->yuv_color_range != mwindow->preferences->yuv_color_range ) {
217 YUV::yuv.yuv_set_colors(
218 preferences->yuv_color_space,
219 preferences->yuv_color_range);
223 if( preferences->highlight_inverse != mwindow->preferences->highlight_inverse ) {
224 mwindow->gui->lock_window("PreferencesThread::apply_settings 0");
225 mwindow->gui->hide_cursor(0);
226 mwindow->gui->unlock_window();
229 PreferencesWindow *window = (PreferencesWindow*)get_gui();
230 if( window ) window->unlock_window();
231 mwindow->stop_brender();
232 if( window ) window->lock_window("PreferencesThread::apply_settings 5");
234 if( strcmp(preferences->theme, mwindow->preferences->theme) != 0 )
235 mwindow->restart_status = -1; // reload, need new bcresources
236 if( strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) != 0 )
237 mwindow->restart_status = -1;
238 if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
240 if( reload_plugins ) {
241 MWindow::remove_plugin_index();
242 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
243 mwindow->restart_status = -1;
246 mwindow->edl->copy_session(edl, 1);
247 mwindow->preferences->copy_from(preferences);
249 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
250 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
251 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
252 BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
253 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
254 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
255 BC_Trace::enable_locks();
258 BC_Trace::disable_locks();
261 mwindow->reset_android_remote();
262 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
263 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
264 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
265 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
266 mwindow->gui->mainshbtns->load(mwindow->preferences);
267 mwindow->init_brender();
269 //edl->session->recording_format->dump();
270 //mwindow->edl->session->recording_format->dump();
272 if(((mwindow->edl->session->output_w % 4) ||
273 (mwindow->edl->session->output_h % 4)) &&
274 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
276 MainError::show_error(
277 _("This project's dimensions are not multiples of 4 so\n"
278 "it can't be rendered by OpenGL."));
284 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
285 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
286 edl->session->min_meter_db,
287 edl->session->max_meter_db);
288 mwindow->cwindow->gui->unlock_window();
292 for(int i = 0; i < mwindow->vwindows.size(); i++) {
293 VWindow *vwindow = mwindow->vwindows.get(i);
294 if( !vwindow->is_running() ) continue;
295 vwindow->gui->lock_window("PreferencesThread::apply_settings");
296 vwindow->gui->meters->change_format(edl->session->meter_format,
297 edl->session->min_meter_db,
298 edl->session->max_meter_db);
299 vwindow->gui->unlock_window();
304 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
305 mwindow->gui->set_meter_format(edl->session->meter_format,
306 edl->session->min_meter_db,
307 edl->session->max_meter_db);
308 mwindow->gui->unlock_window();
312 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
313 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
314 edl->session->min_meter_db,
315 edl->session->max_meter_db);
316 mwindow->lwindow->gui->unlock_window();
321 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
322 mwindow->gui->show_cursor(0);
323 mwindow->gui->draw_overlays(1);
324 mwindow->gui->unlock_window();
329 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
330 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
331 mwindow->gui->redraw_time_dependancies();
332 mwindow->gui->unlock_window();
337 //printf("PreferencesThread::apply_settings 1\n");
338 // This doesn't stop and restart, only reloads the assets before
339 // the next play command.
340 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
341 //printf("PreferencesThread::apply_settings 10\n");
344 if(redraw_times || redraw_overlays)
346 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
347 mwindow->gui->flush();
348 mwindow->gui->unlock_window();
354 const char* PreferencesThread::category_to_text(int category)
356 PlaybackConfig *playback_config = edl->session->playback_config;
360 return playback_config->active_config==0 ?
361 _("*Playback A") : _("Playback A");
363 return playback_config->active_config==1 ?
364 _("*Playback B") : _("Playback B");
366 return _("Recording");
368 return _("Performance");
370 return _("Interface");
372 return _("Appearance");
379 int PreferencesThread::text_to_category(const char *category)
382 int min_result = -1, result, result_num = 0;
383 for(int i = 0; i < CATEGORIES; i++)
385 result = labs(strcmp(category_to_text(i), category));
386 if(result < min_result || min_result < 0)
403 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
404 PreferencesThread *thread, int x, int y, int w, int h)
405 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
407 this->mwindow = mwindow;
408 this->thread = thread;
413 PreferencesWindow::~PreferencesWindow()
415 lock_window("PreferencesWindow::~PreferencesWindow");
419 if(dialog) delete dialog;
422 for(int i = 0; i < categories.total; i++)
423 delete categories.values[i];
427 void PreferencesWindow::create_objects()
431 lock_window("PreferencesWindow::create_objects");
432 set_icon(mwindow->theme->get_image("mwindow_icon"));
433 mwindow->theme->draw_preferences_bg(this);
436 int x = mwindow->theme->preferencescategory_x;
437 int y = mwindow->theme->preferencescategory_y;
438 for(int i = 0; i < CATEGORIES; i++)
440 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
441 thread, x, y, i, thread->category_to_text(i),
442 (i == thread->current_dialog) ?
443 mwindow->theme->get_image_set("category_button_checked") :
444 mwindow->theme->get_image_set("category_button")));
445 x += category_button[i]->get_w() -
446 mwindow->theme->preferences_category_overlap;
450 // for(int i = 0; i < CATEGORIES; i++)
451 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
452 // category = new PreferencesCategory(mwindow,
454 // mwindow->theme->preferencescategory_x,
455 // mwindow->theme->preferencescategory_y);
456 // category->create_objects();
459 add_subwindow(button = new PreferencesOK(mwindow, thread));
460 add_subwindow(new PreferencesApply(mwindow, thread));
461 add_subwindow(new PreferencesCancel(mwindow, thread));
463 set_current_dialog(thread->current_dialog);
469 int PreferencesWindow::update_framerate()
471 lock_window("PreferencesWindow::update_framerate");
472 if(thread->current_dialog < PreferencesThread::RECORD)
474 dialog->draw_framerate(1);
482 void PreferencesWindow::update_rates()
484 lock_window("PreferencesWindow::update_rates");
485 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
487 dialog->update_rates();
493 int PreferencesWindow::set_current_dialog(int number)
495 if(dialog) delete dialog;
497 thread->current_dialog = number;
500 PreferencesDialog *dialog2 = dialog;
504 // Redraw category buttons
505 for(int i = 0; i < CATEGORIES; i++)
509 category_button[i]->set_images(
510 mwindow->theme->get_image_set("category_button_checked"));
514 category_button[i]->set_images(
515 mwindow->theme->get_image_set("category_button"));
517 category_button[i]->draw_face(0);
519 // Copy face to background for next button's overlap.
520 // Still can't do state changes right.
525 PlaybackConfig *playback_config = thread->edl->session->playback_config;
528 case PreferencesThread::PLAYBACK_A:
529 case PreferencesThread::PLAYBACK_B:
530 playback_config->load_defaults(mwindow->defaults,
531 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
532 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
535 case PreferencesThread::RECORD:
536 add_subwindow(dialog = new RecordPrefs(mwindow, this));
539 case PreferencesThread::PERFORMANCE:
540 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
543 case PreferencesThread::INTERFACE:
544 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
547 case PreferencesThread::APPEARANCE:
548 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
551 case PreferencesThread::ABOUT:
552 add_subwindow(dialog = new AboutPrefs(mwindow, this));
559 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
560 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
561 dialog->create_objects();
562 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
563 dialog->lower_window();
564 dialog->show_window(0);
569 dialog2->hide_window(0);
586 PreferencesButton::PreferencesButton(MWindow *mwindow,
587 PreferencesThread *thread,
593 : BC_GenericButton(x, y, text, images)
595 this->mwindow = mwindow;
596 this->thread = thread;
597 this->category = category;
600 int PreferencesButton::handle_event()
602 thread->window->set_current_dialog(category);
614 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
615 PreferencesWindow *pwindow)
618 pwindow->get_w() - 20,
619 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
621 this->pwindow = pwindow;
622 this->mwindow = mwindow;
623 preferences = pwindow->thread->preferences;
626 PreferencesDialog::~PreferencesDialog()
630 // ============================== category window
635 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
636 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
637 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
640 this->mwindow = mwindow;
641 this->thread = thread;
643 int PreferencesApply::handle_event()
645 thread->apply_settings();
646 mwindow->save_defaults();
649 int PreferencesApply::resize_event(int w, int h)
651 reposition_window(w/2 - get_w()/2, h-get_h()-10);
658 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
659 : BC_GenericButton(10,
660 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
663 this->mwindow = mwindow;
664 this->thread = thread;
666 int PreferencesOK::keypress_event()
668 if(get_keypress() == RETURN)
670 thread->window->set_done(0);
675 int PreferencesOK::handle_event()
677 thread->window->set_done(0);
680 int PreferencesOK::resize_event(int w, int h)
682 reposition_window(10, h-get_h()-10);
688 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
689 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
690 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
693 this->mwindow = mwindow;
694 this->thread = thread;
696 int PreferencesCancel::keypress_event()
698 if(get_keypress() == ESC)
700 thread->window->set_done(1);
705 int PreferencesCancel::handle_event()
707 thread->window->set_done(1);
710 int PreferencesCancel::resize_event(int w, int h)
712 reposition_window(w-get_w()-10, h-get_h()-10);
725 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
726 : BC_PopupTextBox(thread->window,
727 &thread->window->categories,
728 thread->category_to_text(thread->current_dialog),
734 this->mwindow = mwindow;
735 this->thread = thread;
738 PreferencesCategory::~PreferencesCategory()
742 int PreferencesCategory::handle_event()
745 thread->window->set_current_dialog(thread->text_to_category(get_text()));