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"
24 #include "audiodevice.inc"
25 #include "bcsignals.h"
28 #include "cplayback.h"
30 #include "cwindowgui.h"
33 #include "edlsession.h"
34 #include "filesystem.h"
36 #include "interfaceprefs.h"
39 #include "levelwindow.h"
40 #include "levelwindowgui.h"
41 #include "mainclock.h"
42 #include "mainerror.h"
44 #include "meterpanel.h"
47 #include "mwindowgui.h"
49 #include "performanceprefs.h"
50 #include "playbackengine.h"
51 #include "playbackprefs.h"
52 #include "preferences.h"
53 #include "recordprefs.h"
54 #include "shbtnprefs.h"
56 #include "trackcanvas.h"
57 #include "transportque.h"
59 #include "vwindowgui.h"
69 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
70 : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
72 this->mwindow = mwindow;
75 thread = new PreferencesThread(mwindow);
78 PreferencesMenuitem::~PreferencesMenuitem()
84 int PreferencesMenuitem::handle_event()
86 mwindow->gui->unlock_window();
88 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
95 PreferencesThread::PreferencesThread(MWindow *mwindow)
98 this->mwindow = mwindow;
103 PreferencesThread::~PreferencesThread()
108 BC_Window* PreferencesThread::new_gui()
111 preferences = new Preferences;
113 edl->create_objects();
114 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
115 preferences->copy_from(mwindow->preferences);
116 edl->copy_session(mwindow->edl);
123 //int need_new_indexes = 0;
126 mwindow->gui->lock_window("NewThread::new_gui");
127 int scr_x = mwindow->gui->get_screen_x(0, -1);
128 int scr_w = mwindow->gui->get_screen_w(0, -1);
129 int scr_h = mwindow->gui->get_screen_h(0, -1);
131 int w = WIDTH, h = HEIGHT;
132 int min_w = mwindow->theme->preferencescategory_x;
133 for(int i = 0; i < CATEGORIES; i++) {
134 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
135 mwindow->theme->preferences_category_overlap;
137 if( w < min_w ) w = min_w;
138 int x = scr_x + scr_w / 2 - w / 2;
139 int y = scr_h / 2 - h / 2;
141 window = new PreferencesWindow(mwindow, this, x, y, w, h);
142 window->create_objects();
143 mwindow->gui->unlock_window();
149 void PreferencesThread::handle_close_event(int result)
155 mwindow->save_defaults();
160 edl->Garbage::remove_user();
164 mwindow->defaults->update("DEFAULTPREF", current_dialog);
165 if( mwindow->restart() )
166 mwindow->gui->set_done(0);
171 int PreferencesThread::update_framerate()
175 lock_gui("PreferencesThread::update_framerate");
176 PreferencesWindow *window = (PreferencesWindow*)get_gui();
177 if(window) window->update_framerate();
184 void PreferencesThread::update_rates()
188 lock_gui("PreferencesThread::update_framerate");
189 PreferencesWindow *window = (PreferencesWindow*)get_gui();
190 if(window) window->update_rates();
195 int PreferencesThread::apply_settings()
199 PlaybackConfig *this_playback_config = edl->session->playback_config;
200 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
201 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
202 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
203 AudioOutConfig *aconfig = playback_config->aconfig;
204 VideoOutConfig *vconfig = playback_config->vconfig;
207 edl->session->need_rerender(mwindow->edl->session) ||
208 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
209 this_playback_config->active_config != playback_config->active_config ||
210 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
211 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
213 if( strcmp(preferences->theme, mwindow->preferences->theme) != 0 )
214 mwindow->restart_status = -1; // reload, need new bcresources
216 mwindow->edl->copy_session(edl, 1);
217 mwindow->preferences->copy_from(preferences);
218 mwindow->init_brender();
220 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
221 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
222 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
223 BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
224 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
225 BC_Trace::enable_locks();
228 BC_Trace::disable_locks();
231 mwindow->reset_android_remote();
232 mwindow->gui->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
233 mwindow->gui->ffmpeg_toggle->set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
234 _("Try FFMpeg first") : _("Try FFMpeg last") );
235 mwindow->gui->mainshbtns->load(mwindow->preferences);
237 mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;
238 mwindow->gui->mainclock->set_position_offset(tc_position);
240 //edl->session->recording_format->dump();
241 //mwindow->edl->session->recording_format->dump();
243 if(((mwindow->edl->session->output_w % 4) ||
244 (mwindow->edl->session->output_h % 4)) &&
245 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
247 MainError::show_error(
248 _("This project's dimensions are not multiples of 4 so\n"
249 "it can't be rendered by OpenGL."));
255 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
256 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
257 edl->session->min_meter_db,
258 edl->session->max_meter_db);
259 mwindow->cwindow->gui->unlock_window();
263 for(int i = 0; i < mwindow->vwindows.size(); i++) {
264 VWindow *vwindow = mwindow->vwindows.get(i);
265 if( !vwindow->is_running() ) continue;
266 vwindow->gui->lock_window("PreferencesThread::apply_settings");
267 vwindow->gui->meters->change_format(edl->session->meter_format,
268 edl->session->min_meter_db,
269 edl->session->max_meter_db);
270 vwindow->gui->unlock_window();
275 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
276 mwindow->gui->set_meter_format(edl->session->meter_format,
277 edl->session->min_meter_db,
278 edl->session->max_meter_db);
279 mwindow->gui->unlock_window();
283 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
284 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
285 edl->session->min_meter_db,
286 edl->session->max_meter_db);
287 mwindow->lwindow->gui->unlock_window();
292 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
293 mwindow->gui->draw_overlays(1);
294 mwindow->gui->unlock_window();
299 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
300 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
301 mwindow->gui->redraw_time_dependancies();
302 mwindow->gui->unlock_window();
307 //printf("PreferencesThread::apply_settings 1\n");
308 // This doesn't stop and restart, only reloads the assets before
309 // the next play command.
310 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
314 //printf("PreferencesThread::apply_settings 10\n");
317 if(redraw_times || redraw_overlays)
319 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
320 mwindow->gui->flush();
321 mwindow->gui->unlock_window();
327 const char* PreferencesThread::category_to_text(int category)
329 PlaybackConfig *playback_config = edl->session->playback_config;
333 return playback_config->active_config==0 ?
334 _("*Playback A") : _("Playback A");
336 return playback_config->active_config==1 ?
337 _("*Playback B") : _("Playback B");
339 return _("Recording");
341 return _("Performance");
343 return _("Interface");
350 int PreferencesThread::text_to_category(const char *category)
353 int min_result = -1, result, result_num = 0;
354 for(int i = 0; i < CATEGORIES; i++)
356 result = labs(strcmp(category_to_text(i), category));
357 if(result < min_result || min_result < 0)
374 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
375 PreferencesThread *thread, int x, int y, int w, int h)
376 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
378 this->mwindow = mwindow;
379 this->thread = thread;
384 PreferencesWindow::~PreferencesWindow()
386 lock_window("PreferencesWindow::~PreferencesWindow");
390 if(dialog) delete dialog;
393 for(int i = 0; i < categories.total; i++)
394 delete categories.values[i];
398 void PreferencesWindow::create_objects()
402 lock_window("PreferencesWindow::create_objects");
403 set_icon(mwindow->theme->get_image("mwindow_icon"));
404 mwindow->theme->draw_preferences_bg(this);
407 int x = mwindow->theme->preferencescategory_x;
408 int y = mwindow->theme->preferencescategory_y;
409 for(int i = 0; i < CATEGORIES; i++)
411 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
416 thread->category_to_text(i),
417 (i == thread->current_dialog) ?
418 mwindow->theme->get_image_set("category_button_checked") :
419 mwindow->theme->get_image_set("category_button")));
420 x += category_button[i]->get_w() -
421 mwindow->theme->preferences_category_overlap;
425 // for(int i = 0; i < CATEGORIES; i++)
426 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
427 // category = new PreferencesCategory(mwindow,
429 // mwindow->theme->preferencescategory_x,
430 // mwindow->theme->preferencescategory_y);
431 // category->create_objects();
434 add_subwindow(button = new PreferencesOK(mwindow, thread));
435 add_subwindow(new PreferencesApply(mwindow, thread));
436 add_subwindow(new PreferencesCancel(mwindow, thread));
438 set_current_dialog(thread->current_dialog);
444 int PreferencesWindow::update_framerate()
446 lock_window("PreferencesWindow::update_framerate");
447 if(thread->current_dialog < PreferencesThread::RECORD)
449 dialog->draw_framerate(1);
457 void PreferencesWindow::update_rates()
459 lock_window("PreferencesWindow::update_rates");
460 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
462 dialog->update_rates();
468 int PreferencesWindow::set_current_dialog(int number)
470 if(dialog) delete dialog;
472 thread->current_dialog = number;
475 PreferencesDialog *dialog2 = dialog;
479 // Redraw category buttons
480 for(int i = 0; i < CATEGORIES; i++)
484 category_button[i]->set_images(
485 mwindow->theme->get_image_set("category_button_checked"));
489 category_button[i]->set_images(
490 mwindow->theme->get_image_set("category_button"));
492 category_button[i]->draw_face(0);
494 // Copy face to background for next button's overlap.
495 // Still can't do state changes right.
500 PlaybackConfig *playback_config = thread->edl->session->playback_config;
503 case PreferencesThread::PLAYBACK_A:
504 case PreferencesThread::PLAYBACK_B:
505 playback_config->load_defaults(mwindow->defaults,
506 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
507 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
510 case PreferencesThread::RECORD:
511 add_subwindow(dialog = new RecordPrefs(mwindow, this));
514 case PreferencesThread::PERFORMANCE:
515 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
518 case PreferencesThread::INTERFACE:
519 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
522 case PreferencesThread::ABOUT:
523 add_subwindow(dialog = new AboutPrefs(mwindow, this));
530 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
531 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
532 dialog->create_objects();
533 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
534 dialog->lower_window();
535 dialog->show_window(0);
540 dialog2->hide_window(0);
557 PreferencesButton::PreferencesButton(MWindow *mwindow,
558 PreferencesThread *thread,
564 : BC_GenericButton(x, y, text, images)
566 this->mwindow = mwindow;
567 this->thread = thread;
568 this->category = category;
571 int PreferencesButton::handle_event()
573 thread->window->set_current_dialog(category);
585 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
586 PreferencesWindow *pwindow)
589 pwindow->get_w() - 20,
590 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
592 this->pwindow = pwindow;
593 this->mwindow = mwindow;
594 preferences = pwindow->thread->preferences;
597 PreferencesDialog::~PreferencesDialog()
601 // ============================== category window
606 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
607 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
608 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
611 this->mwindow = mwindow;
612 this->thread = thread;
614 int PreferencesApply::handle_event()
616 thread->apply_settings();
619 int PreferencesApply::resize_event(int w, int h)
621 reposition_window(w/2 - get_w()/2, h-get_h()-10);
628 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
629 : BC_GenericButton(10,
630 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
633 this->mwindow = mwindow;
634 this->thread = thread;
636 int PreferencesOK::keypress_event()
638 if(get_keypress() == RETURN)
640 thread->window->set_done(0);
645 int PreferencesOK::handle_event()
647 thread->window->set_done(0);
650 int PreferencesOK::resize_event(int w, int h)
652 reposition_window(10, h-get_h()-10);
658 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
659 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
660 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
663 this->mwindow = mwindow;
664 this->thread = thread;
666 int PreferencesCancel::keypress_event()
668 if(get_keypress() == ESC)
670 thread->window->set_done(1);
675 int PreferencesCancel::handle_event()
677 thread->window->set_done(1);
680 int PreferencesCancel::resize_event(int w, int h)
682 reposition_window(w-get_w()-10, h-get_h()-10);
695 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
696 : BC_PopupTextBox(thread->window,
697 &thread->window->categories,
698 thread->category_to_text(thread->current_dialog),
704 this->mwindow = mwindow;
705 this->thread = thread;
708 PreferencesCategory::~PreferencesCategory()
712 int PreferencesCategory::handle_event()
715 thread->window->set_current_dialog(thread->text_to_category(get_text()));