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 x = scr_x + scr_w / 2 - WIDTH / 2;
131 int y = scr_h / 2 - HEIGHT / 2;
133 window = new PreferencesWindow(mwindow, this, x, y);
134 window->create_objects();
135 mwindow->gui->unlock_window();
141 void PreferencesThread::handle_close_event(int result)
147 mwindow->save_defaults();
152 edl->Garbage::remove_user();
156 mwindow->defaults->update("DEFAULTPREF", current_dialog);
157 if( mwindow->restart() )
158 mwindow->gui->set_done(0);
163 int PreferencesThread::update_framerate()
167 lock_gui("PreferencesThread::update_framerate");
168 PreferencesWindow *window = (PreferencesWindow*)get_gui();
169 if(window) window->update_framerate();
176 void PreferencesThread::update_rates()
180 lock_gui("PreferencesThread::update_framerate");
181 PreferencesWindow *window = (PreferencesWindow*)get_gui();
182 if(window) window->update_rates();
187 int PreferencesThread::apply_settings()
191 PlaybackConfig *this_playback_config = edl->session->playback_config;
192 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
193 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
194 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
195 AudioOutConfig *aconfig = playback_config->aconfig;
196 VideoOutConfig *vconfig = playback_config->vconfig;
199 edl->session->need_rerender(mwindow->edl->session) ||
200 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
201 this_playback_config->active_config != playback_config->active_config ||
202 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
203 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
205 if( strcmp(preferences->theme, mwindow->preferences->theme) != 0 )
206 mwindow->restart_status = -1; // reload, need new bcresources
208 mwindow->edl->copy_session(edl, 1);
209 mwindow->preferences->copy_from(preferences);
210 mwindow->init_brender();
212 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
213 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
214 BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
216 mwindow->reset_android_remote();
217 mwindow->gui->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
218 mwindow->gui->ffmpeg_toggle->set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
219 _("Try FFMpeg first") : _("Try FFMpeg last") );
220 mwindow->gui->mainshbtns->load(mwindow->preferences);
222 mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;
223 mwindow->gui->mainclock->set_position_offset(tc_position);
225 //edl->session->recording_format->dump();
226 //mwindow->edl->session->recording_format->dump();
228 if(((mwindow->edl->session->output_w % 4) ||
229 (mwindow->edl->session->output_h % 4)) &&
230 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
232 MainError::show_error(
233 _("This project's dimensions are not multiples of 4 so\n"
234 "it can't be rendered by OpenGL."));
240 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
241 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
242 edl->session->min_meter_db,
243 edl->session->max_meter_db);
244 mwindow->cwindow->gui->unlock_window();
248 for(int i = 0; i < mwindow->vwindows.size(); i++) {
249 VWindow *vwindow = mwindow->vwindows.get(i);
250 if( !vwindow->is_running() ) continue;
251 vwindow->gui->lock_window("PreferencesThread::apply_settings");
252 vwindow->gui->meters->change_format(edl->session->meter_format,
253 edl->session->min_meter_db,
254 edl->session->max_meter_db);
255 vwindow->gui->unlock_window();
260 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
261 mwindow->gui->set_meter_format(edl->session->meter_format,
262 edl->session->min_meter_db,
263 edl->session->max_meter_db);
264 mwindow->gui->unlock_window();
268 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
269 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
270 edl->session->min_meter_db,
271 edl->session->max_meter_db);
272 mwindow->lwindow->gui->unlock_window();
277 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
278 mwindow->gui->draw_overlays(1);
279 mwindow->gui->unlock_window();
284 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
285 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
286 mwindow->gui->redraw_time_dependancies();
287 mwindow->gui->unlock_window();
292 //printf("PreferencesThread::apply_settings 1\n");
293 // This doesn't stop and restart, only reloads the assets before
294 // the next play command.
295 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
299 //printf("PreferencesThread::apply_settings 10\n");
302 if(redraw_times || redraw_overlays)
304 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
305 mwindow->gui->flush();
306 mwindow->gui->unlock_window();
312 const char* PreferencesThread::category_to_text(int category)
314 PlaybackConfig *playback_config = edl->session->playback_config;
318 return playback_config->active_config==0 ?
319 _("*Playback A") : _("Playback A");
321 return playback_config->active_config==1 ?
322 _("*Playback B") : _("Playback B");
324 return _("Recording");
326 return _("Performance");
328 return _("Interface");
335 int PreferencesThread::text_to_category(const char *category)
338 int min_result = -1, result, result_num = 0;
339 for(int i = 0; i < CATEGORIES; i++)
341 result = labs(strcmp(category_to_text(i), category));
342 if(result < min_result || min_result < 0)
359 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
360 PreferencesThread *thread,
363 : BC_Window(_(PROGRAM_NAME ": Preferences"),
364 x,y, WIDTH,HEIGHT, WIDTH,HEIGHT, 1,0,1)
366 this->mwindow = mwindow;
367 this->thread = thread;
372 PreferencesWindow::~PreferencesWindow()
374 lock_window("PreferencesWindow::~PreferencesWindow");
378 if(dialog) delete dialog;
381 for(int i = 0; i < categories.total; i++)
382 delete categories.values[i];
386 void PreferencesWindow::create_objects()
390 lock_window("PreferencesWindow::create_objects");
391 set_icon(mwindow->theme->get_image("mwindow_icon"));
392 mwindow->theme->draw_preferences_bg(this);
395 int x = mwindow->theme->preferencescategory_x;
396 int y = mwindow->theme->preferencescategory_y;
397 for(int i = 0; i < CATEGORIES; i++)
399 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
404 thread->category_to_text(i),
405 (i == thread->current_dialog) ?
406 mwindow->theme->get_image_set("category_button_checked") :
407 mwindow->theme->get_image_set("category_button")));
408 x += category_button[i]->get_w() -
409 mwindow->theme->preferences_category_overlap;
413 // for(int i = 0; i < CATEGORIES; i++)
414 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
415 // category = new PreferencesCategory(mwindow,
417 // mwindow->theme->preferencescategory_x,
418 // mwindow->theme->preferencescategory_y);
419 // category->create_objects();
422 add_subwindow(button = new PreferencesOK(mwindow, thread));
423 add_subwindow(new PreferencesApply(mwindow, thread));
424 add_subwindow(new PreferencesCancel(mwindow, thread));
426 set_current_dialog(thread->current_dialog);
432 int PreferencesWindow::update_framerate()
434 lock_window("PreferencesWindow::update_framerate");
435 if(thread->current_dialog < PreferencesThread::RECORD)
437 dialog->draw_framerate(1);
445 void PreferencesWindow::update_rates()
447 lock_window("PreferencesWindow::update_rates");
448 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
450 dialog->update_rates();
456 int PreferencesWindow::set_current_dialog(int number)
458 if(dialog) delete dialog;
460 thread->current_dialog = number;
463 PreferencesDialog *dialog2 = dialog;
467 // Redraw category buttons
468 for(int i = 0; i < CATEGORIES; i++)
472 category_button[i]->set_images(
473 mwindow->theme->get_image_set("category_button_checked"));
477 category_button[i]->set_images(
478 mwindow->theme->get_image_set("category_button"));
480 category_button[i]->draw_face(0);
482 // Copy face to background for next button's overlap.
483 // Still can't do state changes right.
488 PlaybackConfig *playback_config = thread->edl->session->playback_config;
491 case PreferencesThread::PLAYBACK_A:
492 case PreferencesThread::PLAYBACK_B:
493 playback_config->load_defaults(mwindow->defaults,
494 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
495 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
498 case PreferencesThread::RECORD:
499 add_subwindow(dialog = new RecordPrefs(mwindow, this));
502 case PreferencesThread::PERFORMANCE:
503 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
506 case PreferencesThread::INTERFACE:
507 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
510 case PreferencesThread::ABOUT:
511 add_subwindow(dialog = new AboutPrefs(mwindow, this));
518 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
519 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
520 dialog->create_objects();
521 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
522 dialog->show_window(0);
527 dialog2->hide_window(0);
544 PreferencesButton::PreferencesButton(MWindow *mwindow,
545 PreferencesThread *thread,
551 : BC_GenericButton(x, y, text, images)
553 this->mwindow = mwindow;
554 this->thread = thread;
555 this->category = category;
558 int PreferencesButton::handle_event()
560 thread->window->set_current_dialog(category);
572 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
573 PreferencesWindow *pwindow)
576 pwindow->get_w() - 20,
577 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
579 this->pwindow = pwindow;
580 this->mwindow = mwindow;
581 preferences = pwindow->thread->preferences;
584 PreferencesDialog::~PreferencesDialog()
588 // ============================== category window
593 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
594 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
595 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
598 this->mwindow = mwindow;
599 this->thread = thread;
602 int PreferencesApply::handle_event()
604 thread->apply_settings();
611 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
612 : BC_GenericButton(10,
613 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
616 this->mwindow = mwindow;
617 this->thread = thread;
620 int PreferencesOK::keypress_event()
622 if(get_keypress() == RETURN)
624 thread->window->set_done(0);
629 int PreferencesOK::handle_event()
631 thread->window->set_done(0);
637 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
638 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
639 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
642 this->mwindow = mwindow;
643 this->thread = thread;
645 int PreferencesCancel::keypress_event()
647 if(get_keypress() == ESC)
649 thread->window->set_done(1);
655 int PreferencesCancel::handle_event()
657 thread->window->set_done(1);
670 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
671 : BC_PopupTextBox(thread->window,
672 &thread->window->categories,
673 thread->category_to_text(thread->current_dialog),
679 this->mwindow = mwindow;
680 this->thread = thread;
683 PreferencesCategory::~PreferencesCategory()
687 int PreferencesCategory::handle_event()
690 thread->window->set_current_dialog(thread->text_to_category(get_text()));