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"
27 #include "cplayback.h"
29 #include "cwindowgui.h"
32 #include "edlsession.h"
33 #include "filesystem.h"
35 #include "interfaceprefs.h"
38 #include "levelwindow.h"
39 #include "levelwindowgui.h"
40 #include "mainclock.h"
41 #include "mainerror.h"
43 #include "meterpanel.h"
46 #include "mwindowgui.h"
48 #include "performanceprefs.h"
49 #include "playbackengine.h"
50 #include "playbackprefs.h"
51 #include "preferences.h"
52 #include "recordprefs.h"
53 #include "shbtnprefs.h"
55 #include "trackcanvas.h"
56 #include "transportque.h"
58 #include "vwindowgui.h"
68 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
69 : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
71 this->mwindow = mwindow;
74 thread = new PreferencesThread(mwindow);
77 PreferencesMenuitem::~PreferencesMenuitem()
83 int PreferencesMenuitem::handle_event()
85 mwindow->gui->unlock_window();
87 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
94 PreferencesThread::PreferencesThread(MWindow *mwindow)
97 this->mwindow = mwindow;
102 PreferencesThread::~PreferencesThread()
107 BC_Window* PreferencesThread::new_gui()
110 preferences = new Preferences;
112 edl->create_objects();
113 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
114 preferences->copy_from(mwindow->preferences);
115 edl->copy_session(mwindow->edl);
122 //int need_new_indexes = 0;
125 mwindow->gui->lock_window("NewThread::new_gui");
126 int scr_x = mwindow->gui->get_screen_x(0, -1);
127 int scr_w = mwindow->gui->get_screen_w(0, -1);
128 int scr_h = mwindow->gui->get_screen_h(0, -1);
130 int w = WIDTH, h = HEIGHT;
131 int min_w = mwindow->theme->preferencescategory_x;
132 for(int i = 0; i < CATEGORIES; i++) {
133 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
134 mwindow->theme->preferences_category_overlap;
136 if( w < min_w ) w = min_w;
137 int x = scr_x + scr_w / 2 - w / 2;
138 int y = scr_h / 2 - h / 2;
140 window = new PreferencesWindow(mwindow, this, x, y, w, h);
141 window->create_objects();
142 mwindow->gui->unlock_window();
148 void PreferencesThread::handle_close_event(int result)
154 mwindow->save_defaults();
159 edl->Garbage::remove_user();
163 mwindow->defaults->update("DEFAULTPREF", current_dialog);
164 if( mwindow->restart() )
165 mwindow->gui->set_done(0);
170 int PreferencesThread::update_framerate()
174 lock_gui("PreferencesThread::update_framerate");
175 PreferencesWindow *window = (PreferencesWindow*)get_gui();
176 if(window) window->update_framerate();
183 void PreferencesThread::update_rates()
187 lock_gui("PreferencesThread::update_framerate");
188 PreferencesWindow *window = (PreferencesWindow*)get_gui();
189 if(window) window->update_rates();
194 int PreferencesThread::apply_settings()
198 PlaybackConfig *this_playback_config = edl->session->playback_config;
199 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
200 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
201 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
202 AudioOutConfig *aconfig = playback_config->aconfig;
203 VideoOutConfig *vconfig = playback_config->vconfig;
206 edl->session->need_rerender(mwindow->edl->session) ||
207 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
208 this_playback_config->active_config != playback_config->active_config ||
209 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
210 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
212 if( strcmp(preferences->theme, mwindow->preferences->theme) != 0 )
213 mwindow->restart_status = -1; // reload, need new bcresources
215 mwindow->edl->copy_session(edl, 1);
216 mwindow->preferences->copy_from(preferences);
217 mwindow->init_brender();
219 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
220 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
221 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
223 mwindow->reset_android_remote();
224 mwindow->gui->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
225 mwindow->gui->ffmpeg_toggle->set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
226 _("Try FFMpeg first") : _("Try FFMpeg last") );
227 mwindow->gui->mainshbtns->load(mwindow->preferences);
229 mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;
230 mwindow->gui->mainclock->set_position_offset(tc_position);
232 //edl->session->recording_format->dump();
233 //mwindow->edl->session->recording_format->dump();
235 if(((mwindow->edl->session->output_w % 4) ||
236 (mwindow->edl->session->output_h % 4)) &&
237 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
239 MainError::show_error(
240 _("This project's dimensions are not multiples of 4 so\n"
241 "it can't be rendered by OpenGL."));
247 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
248 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
249 edl->session->min_meter_db,
250 edl->session->max_meter_db);
251 mwindow->cwindow->gui->unlock_window();
255 for(int i = 0; i < mwindow->vwindows.size(); i++) {
256 VWindow *vwindow = mwindow->vwindows.get(i);
257 if( !vwindow->is_running() ) continue;
258 vwindow->gui->lock_window("PreferencesThread::apply_settings");
259 vwindow->gui->meters->change_format(edl->session->meter_format,
260 edl->session->min_meter_db,
261 edl->session->max_meter_db);
262 vwindow->gui->unlock_window();
267 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
268 mwindow->gui->set_meter_format(edl->session->meter_format,
269 edl->session->min_meter_db,
270 edl->session->max_meter_db);
271 mwindow->gui->unlock_window();
275 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
276 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
277 edl->session->min_meter_db,
278 edl->session->max_meter_db);
279 mwindow->lwindow->gui->unlock_window();
284 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
285 mwindow->gui->draw_overlays(1);
286 mwindow->gui->unlock_window();
291 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
292 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
293 mwindow->gui->redraw_time_dependancies();
294 mwindow->gui->unlock_window();
299 //printf("PreferencesThread::apply_settings 1\n");
300 // This doesn't stop and restart, only reloads the assets before
301 // the next play command.
302 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
306 //printf("PreferencesThread::apply_settings 10\n");
309 if(redraw_times || redraw_overlays)
311 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
312 mwindow->gui->flush();
313 mwindow->gui->unlock_window();
319 const char* PreferencesThread::category_to_text(int category)
321 PlaybackConfig *playback_config = edl->session->playback_config;
325 return playback_config->active_config==0 ?
326 _("*Playback A") : _("Playback A");
328 return playback_config->active_config==1 ?
329 _("*Playback B") : _("Playback B");
331 return _("Recording");
333 return _("Performance");
335 return _("Interface");
342 int PreferencesThread::text_to_category(const char *category)
345 int min_result = -1, result, result_num = 0;
346 for(int i = 0; i < CATEGORIES; i++)
348 result = labs(strcmp(category_to_text(i), category));
349 if(result < min_result || min_result < 0)
366 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
367 PreferencesThread *thread, int x, int y, int w, int h)
368 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
370 this->mwindow = mwindow;
371 this->thread = thread;
376 PreferencesWindow::~PreferencesWindow()
378 lock_window("PreferencesWindow::~PreferencesWindow");
382 if(dialog) delete dialog;
385 for(int i = 0; i < categories.total; i++)
386 delete categories.values[i];
390 void PreferencesWindow::create_objects()
394 lock_window("PreferencesWindow::create_objects");
395 set_icon(mwindow->theme->get_image("mwindow_icon"));
396 mwindow->theme->draw_preferences_bg(this);
399 int x = mwindow->theme->preferencescategory_x;
400 int y = mwindow->theme->preferencescategory_y;
401 for(int i = 0; i < CATEGORIES; i++)
403 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
408 thread->category_to_text(i),
409 (i == thread->current_dialog) ?
410 mwindow->theme->get_image_set("category_button_checked") :
411 mwindow->theme->get_image_set("category_button")));
412 x += category_button[i]->get_w() -
413 mwindow->theme->preferences_category_overlap;
417 // for(int i = 0; i < CATEGORIES; i++)
418 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
419 // category = new PreferencesCategory(mwindow,
421 // mwindow->theme->preferencescategory_x,
422 // mwindow->theme->preferencescategory_y);
423 // category->create_objects();
426 add_subwindow(button = new PreferencesOK(mwindow, thread));
427 add_subwindow(new PreferencesApply(mwindow, thread));
428 add_subwindow(new PreferencesCancel(mwindow, thread));
430 set_current_dialog(thread->current_dialog);
436 int PreferencesWindow::update_framerate()
438 lock_window("PreferencesWindow::update_framerate");
439 if(thread->current_dialog < PreferencesThread::RECORD)
441 dialog->draw_framerate(1);
449 void PreferencesWindow::update_rates()
451 lock_window("PreferencesWindow::update_rates");
452 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
454 dialog->update_rates();
460 int PreferencesWindow::set_current_dialog(int number)
462 if(dialog) delete dialog;
464 thread->current_dialog = number;
467 PreferencesDialog *dialog2 = dialog;
471 // Redraw category buttons
472 for(int i = 0; i < CATEGORIES; i++)
476 category_button[i]->set_images(
477 mwindow->theme->get_image_set("category_button_checked"));
481 category_button[i]->set_images(
482 mwindow->theme->get_image_set("category_button"));
484 category_button[i]->draw_face(0);
486 // Copy face to background for next button's overlap.
487 // Still can't do state changes right.
492 PlaybackConfig *playback_config = thread->edl->session->playback_config;
495 case PreferencesThread::PLAYBACK_A:
496 case PreferencesThread::PLAYBACK_B:
497 playback_config->load_defaults(mwindow->defaults,
498 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
499 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
502 case PreferencesThread::RECORD:
503 add_subwindow(dialog = new RecordPrefs(mwindow, this));
506 case PreferencesThread::PERFORMANCE:
507 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
510 case PreferencesThread::INTERFACE:
511 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
514 case PreferencesThread::ABOUT:
515 add_subwindow(dialog = new AboutPrefs(mwindow, this));
522 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
523 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
524 dialog->create_objects();
525 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
526 dialog->lower_window();
527 dialog->show_window(0);
532 dialog2->hide_window(0);
549 PreferencesButton::PreferencesButton(MWindow *mwindow,
550 PreferencesThread *thread,
556 : BC_GenericButton(x, y, text, images)
558 this->mwindow = mwindow;
559 this->thread = thread;
560 this->category = category;
563 int PreferencesButton::handle_event()
565 thread->window->set_current_dialog(category);
577 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
578 PreferencesWindow *pwindow)
581 pwindow->get_w() - 20,
582 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
584 this->pwindow = pwindow;
585 this->mwindow = mwindow;
586 preferences = pwindow->thread->preferences;
589 PreferencesDialog::~PreferencesDialog()
593 // ============================== category window
598 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
599 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
600 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
603 this->mwindow = mwindow;
604 this->thread = thread;
606 int PreferencesApply::handle_event()
608 thread->apply_settings();
611 int PreferencesApply::resize_event(int w, int h)
613 reposition_window(w/2 - get_w()/2, h-get_h()-10);
620 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
621 : BC_GenericButton(10,
622 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
625 this->mwindow = mwindow;
626 this->thread = thread;
628 int PreferencesOK::keypress_event()
630 if(get_keypress() == RETURN)
632 thread->window->set_done(0);
637 int PreferencesOK::handle_event()
639 thread->window->set_done(0);
642 int PreferencesOK::resize_event(int w, int h)
644 reposition_window(10, h-get_h()-10);
650 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
651 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
652 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
655 this->mwindow = mwindow;
656 this->thread = thread;
658 int PreferencesCancel::keypress_event()
660 if(get_keypress() == ESC)
662 thread->window->set_done(1);
667 int PreferencesCancel::handle_event()
669 thread->window->set_done(1);
672 int PreferencesCancel::resize_event(int w, int h)
674 reposition_window(w-get_w()-10, h-get_h()-10);
687 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
688 : BC_PopupTextBox(thread->window,
689 &thread->window->categories,
690 thread->category_to_text(thread->current_dialog),
696 this->mwindow = mwindow;
697 this->thread = thread;
700 PreferencesCategory::~PreferencesCategory()
704 int PreferencesCategory::handle_event()
707 thread->window->set_current_dialog(thread->text_to_category(get_text()));