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"
35 #include "filesystem.h"
37 #include "interfaceprefs.h"
40 #include "levelwindow.h"
41 #include "levelwindowgui.h"
42 #include "mainclock.h"
43 #include "mainerror.h"
45 #include "meterpanel.h"
48 #include "mwindowgui.h"
50 #include "performanceprefs.h"
51 #include "playbackengine.h"
52 #include "playbackprefs.h"
53 #include "preferences.h"
54 #include "recordprefs.h"
55 #include "shbtnprefs.h"
57 #include "trackcanvas.h"
58 #include "transportque.h"
60 #include "vwindowgui.h"
70 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
71 : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
73 this->mwindow = mwindow;
76 thread = new PreferencesThread(mwindow);
79 PreferencesMenuitem::~PreferencesMenuitem()
85 int PreferencesMenuitem::handle_event()
87 mwindow->gui->unlock_window();
89 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
96 PreferencesThread::PreferencesThread(MWindow *mwindow)
99 this->mwindow = mwindow;
104 PreferencesThread::~PreferencesThread()
109 BC_Window* PreferencesThread::new_gui()
112 preferences = new Preferences;
114 edl->create_objects();
115 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
116 preferences->copy_from(mwindow->preferences);
117 edl->copy_session(mwindow->edl);
124 //int need_new_indexes = 0;
127 mwindow->gui->lock_window("NewThread::new_gui");
128 int scr_x = mwindow->gui->get_screen_x(0, -1);
129 int scr_w = mwindow->gui->get_screen_w(0, -1);
130 int scr_h = mwindow->gui->get_screen_h(0, -1);
132 int w = WIDTH, h = HEIGHT;
133 int min_w = mwindow->theme->preferencescategory_x;
134 for(int i = 0; i < CATEGORIES; i++) {
135 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
136 mwindow->theme->preferences_category_overlap;
138 if( w < min_w ) w = min_w;
139 int x = scr_x + scr_w / 2 - w / 2;
140 int y = scr_h / 2 - h / 2;
142 window = new PreferencesWindow(mwindow, this, x, y, w, h);
143 window->create_objects();
144 mwindow->gui->unlock_window();
150 void PreferencesThread::handle_close_event(int result)
156 mwindow->save_defaults();
161 edl->Garbage::remove_user();
165 mwindow->defaults->update("DEFAULTPREF", current_dialog);
166 if( mwindow->restart() )
167 mwindow->gui->set_done(0);
172 int PreferencesThread::update_framerate()
176 lock_gui("PreferencesThread::update_framerate");
177 PreferencesWindow *window = (PreferencesWindow*)get_gui();
178 if(window) window->update_framerate();
185 void PreferencesThread::update_rates()
189 lock_gui("PreferencesThread::update_framerate");
190 PreferencesWindow *window = (PreferencesWindow*)get_gui();
191 if(window) window->update_rates();
196 int PreferencesThread::apply_settings()
200 PlaybackConfig *this_playback_config = edl->session->playback_config;
201 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
202 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
203 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
204 AudioOutConfig *aconfig = playback_config->aconfig;
205 VideoOutConfig *vconfig = playback_config->vconfig;
208 edl->session->need_rerender(mwindow->edl->session) ||
209 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
210 this_playback_config->active_config != playback_config->active_config ||
211 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
212 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
214 if( strcmp(preferences->theme, mwindow->preferences->theme) != 0 )
215 mwindow->restart_status = -1; // reload, need new bcresources
216 if( strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) != 0 )
217 mwindow->restart_status = -1;
219 mwindow->edl->copy_session(edl, 1);
220 mwindow->preferences->copy_from(preferences);
221 mwindow->init_brender();
223 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
224 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
225 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
226 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
227 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
228 BC_Trace::enable_locks();
231 BC_Trace::disable_locks();
234 mwindow->reset_android_remote();
235 int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFPMEG_Early");
236 mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
237 mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
238 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
239 mwindow->gui->mainshbtns->load(mwindow->preferences);
241 //edl->session->recording_format->dump();
242 //mwindow->edl->session->recording_format->dump();
244 if(((mwindow->edl->session->output_w % 4) ||
245 (mwindow->edl->session->output_h % 4)) &&
246 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
248 MainError::show_error(
249 _("This project's dimensions are not multiples of 4 so\n"
250 "it can't be rendered by OpenGL."));
256 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
257 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
258 edl->session->min_meter_db,
259 edl->session->max_meter_db);
260 mwindow->cwindow->gui->unlock_window();
264 for(int i = 0; i < mwindow->vwindows.size(); i++) {
265 VWindow *vwindow = mwindow->vwindows.get(i);
266 if( !vwindow->is_running() ) continue;
267 vwindow->gui->lock_window("PreferencesThread::apply_settings");
268 vwindow->gui->meters->change_format(edl->session->meter_format,
269 edl->session->min_meter_db,
270 edl->session->max_meter_db);
271 vwindow->gui->unlock_window();
276 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
277 mwindow->gui->set_meter_format(edl->session->meter_format,
278 edl->session->min_meter_db,
279 edl->session->max_meter_db);
280 mwindow->gui->unlock_window();
284 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
285 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
286 edl->session->min_meter_db,
287 edl->session->max_meter_db);
288 mwindow->lwindow->gui->unlock_window();
293 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
294 mwindow->gui->draw_overlays(1);
295 mwindow->gui->unlock_window();
300 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
301 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
302 mwindow->gui->redraw_time_dependancies();
303 mwindow->gui->unlock_window();
308 //printf("PreferencesThread::apply_settings 1\n");
309 // This doesn't stop and restart, only reloads the assets before
310 // the next play command.
311 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
315 //printf("PreferencesThread::apply_settings 10\n");
318 if(redraw_times || redraw_overlays)
320 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
321 mwindow->gui->flush();
322 mwindow->gui->unlock_window();
328 const char* PreferencesThread::category_to_text(int category)
330 PlaybackConfig *playback_config = edl->session->playback_config;
334 return playback_config->active_config==0 ?
335 _("*Playback A") : _("Playback A");
337 return playback_config->active_config==1 ?
338 _("*Playback B") : _("Playback B");
340 return _("Recording");
342 return _("Performance");
344 return _("Interface");
346 return _("Appearance");
353 int PreferencesThread::text_to_category(const char *category)
356 int min_result = -1, result, result_num = 0;
357 for(int i = 0; i < CATEGORIES; i++)
359 result = labs(strcmp(category_to_text(i), category));
360 if(result < min_result || min_result < 0)
377 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
378 PreferencesThread *thread, int x, int y, int w, int h)
379 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
381 this->mwindow = mwindow;
382 this->thread = thread;
387 PreferencesWindow::~PreferencesWindow()
389 lock_window("PreferencesWindow::~PreferencesWindow");
393 if(dialog) delete dialog;
396 for(int i = 0; i < categories.total; i++)
397 delete categories.values[i];
401 void PreferencesWindow::create_objects()
405 lock_window("PreferencesWindow::create_objects");
406 set_icon(mwindow->theme->get_image("mwindow_icon"));
407 mwindow->theme->draw_preferences_bg(this);
410 int x = mwindow->theme->preferencescategory_x;
411 int y = mwindow->theme->preferencescategory_y;
412 for(int i = 0; i < CATEGORIES; i++)
414 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
415 thread, x, y, i, thread->category_to_text(i),
416 (i == thread->current_dialog) ?
417 mwindow->theme->get_image_set("category_button_checked") :
418 mwindow->theme->get_image_set("category_button")));
419 x += category_button[i]->get_w() -
420 mwindow->theme->preferences_category_overlap;
424 // for(int i = 0; i < CATEGORIES; i++)
425 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
426 // category = new PreferencesCategory(mwindow,
428 // mwindow->theme->preferencescategory_x,
429 // mwindow->theme->preferencescategory_y);
430 // category->create_objects();
433 add_subwindow(button = new PreferencesOK(mwindow, thread));
434 add_subwindow(new PreferencesApply(mwindow, thread));
435 add_subwindow(new PreferencesCancel(mwindow, thread));
437 set_current_dialog(thread->current_dialog);
443 int PreferencesWindow::update_framerate()
445 lock_window("PreferencesWindow::update_framerate");
446 if(thread->current_dialog < PreferencesThread::RECORD)
448 dialog->draw_framerate(1);
456 void PreferencesWindow::update_rates()
458 lock_window("PreferencesWindow::update_rates");
459 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
461 dialog->update_rates();
467 int PreferencesWindow::set_current_dialog(int number)
469 if(dialog) delete dialog;
471 thread->current_dialog = number;
474 PreferencesDialog *dialog2 = dialog;
478 // Redraw category buttons
479 for(int i = 0; i < CATEGORIES; i++)
483 category_button[i]->set_images(
484 mwindow->theme->get_image_set("category_button_checked"));
488 category_button[i]->set_images(
489 mwindow->theme->get_image_set("category_button"));
491 category_button[i]->draw_face(0);
493 // Copy face to background for next button's overlap.
494 // Still can't do state changes right.
499 PlaybackConfig *playback_config = thread->edl->session->playback_config;
502 case PreferencesThread::PLAYBACK_A:
503 case PreferencesThread::PLAYBACK_B:
504 playback_config->load_defaults(mwindow->defaults,
505 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
506 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
509 case PreferencesThread::RECORD:
510 add_subwindow(dialog = new RecordPrefs(mwindow, this));
513 case PreferencesThread::PERFORMANCE:
514 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
517 case PreferencesThread::INTERFACE:
518 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
521 case PreferencesThread::APPEARANCE:
522 add_subwindow(dialog = new AppearancePrefs(mwindow, this));
525 case PreferencesThread::ABOUT:
526 add_subwindow(dialog = new AboutPrefs(mwindow, this));
533 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
534 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
535 dialog->create_objects();
536 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
537 dialog->lower_window();
538 dialog->show_window(0);
543 dialog2->hide_window(0);
560 PreferencesButton::PreferencesButton(MWindow *mwindow,
561 PreferencesThread *thread,
567 : BC_GenericButton(x, y, text, images)
569 this->mwindow = mwindow;
570 this->thread = thread;
571 this->category = category;
574 int PreferencesButton::handle_event()
576 thread->window->set_current_dialog(category);
588 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
589 PreferencesWindow *pwindow)
592 pwindow->get_w() - 20,
593 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
595 this->pwindow = pwindow;
596 this->mwindow = mwindow;
597 preferences = pwindow->thread->preferences;
600 PreferencesDialog::~PreferencesDialog()
604 // ============================== category window
609 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
610 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
611 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
614 this->mwindow = mwindow;
615 this->thread = thread;
617 int PreferencesApply::handle_event()
619 thread->apply_settings();
622 int PreferencesApply::resize_event(int w, int h)
624 reposition_window(w/2 - get_w()/2, h-get_h()-10);
631 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
632 : BC_GenericButton(10,
633 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
636 this->mwindow = mwindow;
637 this->thread = thread;
639 int PreferencesOK::keypress_event()
641 if(get_keypress() == RETURN)
643 thread->window->set_done(0);
648 int PreferencesOK::handle_event()
650 thread->window->set_done(0);
653 int PreferencesOK::resize_event(int w, int h)
655 reposition_window(10, h-get_h()-10);
661 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
662 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
663 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
666 this->mwindow = mwindow;
667 this->thread = thread;
669 int PreferencesCancel::keypress_event()
671 if(get_keypress() == ESC)
673 thread->window->set_done(1);
678 int PreferencesCancel::handle_event()
680 thread->window->set_done(1);
683 int PreferencesCancel::resize_event(int w, int h)
685 reposition_window(w-get_w()-10, h-get_h()-10);
698 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
699 : BC_PopupTextBox(thread->window,
700 &thread->window->categories,
701 thread->category_to_text(thread->current_dialog),
707 this->mwindow = mwindow;
708 this->thread = thread;
711 PreferencesCategory::~PreferencesCategory()
715 int PreferencesCategory::handle_event()
718 thread->window->set_current_dialog(thread->text_to_category(get_text()));