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 "mainerror.h"
42 #include "meterpanel.h"
45 #include "mwindowgui.h"
47 #include "performanceprefs.h"
48 #include "playbackengine.h"
49 #include "playbackprefs.h"
50 #include "preferences.h"
51 #include "recordprefs.h"
52 #include "shbtnprefs.h"
54 #include "trackcanvas.h"
55 #include "transportque.h"
57 #include "vwindowgui.h"
67 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
68 : BC_MenuItem(_("Preferences..."), _("Shift+P"), 'P')
70 this->mwindow = mwindow;
73 thread = new PreferencesThread(mwindow);
76 PreferencesMenuitem::~PreferencesMenuitem()
82 int PreferencesMenuitem::handle_event()
84 mwindow->gui->unlock_window();
86 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
93 PreferencesThread::PreferencesThread(MWindow *mwindow)
96 this->mwindow = mwindow;
101 PreferencesThread::~PreferencesThread()
106 BC_Window* PreferencesThread::new_gui()
109 preferences = new Preferences;
111 edl->create_objects();
112 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
113 preferences->copy_from(mwindow->preferences);
114 edl->copy_session(mwindow->edl);
121 //int need_new_indexes = 0;
124 mwindow->gui->lock_window("NewThread::new_gui");
125 int scr_x = mwindow->gui->get_screen_x(0, -1);
126 int scr_w = mwindow->gui->get_screen_w(0, -1);
127 int scr_h = mwindow->gui->get_screen_h(0, -1);
129 int x = scr_x + scr_w / 2 - WIDTH / 2;
130 int y = scr_h / 2 - HEIGHT / 2;
132 window = new PreferencesWindow(mwindow, this, x, y);
133 window->create_objects();
134 mwindow->gui->unlock_window();
140 void PreferencesThread::handle_close_event(int result)
146 mwindow->save_defaults();
151 edl->Garbage::remove_user();
155 mwindow->defaults->update("DEFAULTPREF", current_dialog);
160 int PreferencesThread::update_framerate()
164 lock_gui("PreferencesThread::update_framerate");
165 PreferencesWindow *window = (PreferencesWindow*)get_gui();
166 if(window) window->update_framerate();
173 void PreferencesThread::update_rates()
177 lock_gui("PreferencesThread::update_framerate");
178 PreferencesWindow *window = (PreferencesWindow*)get_gui();
179 if(window) window->update_rates();
184 int PreferencesThread::apply_settings()
188 PlaybackConfig *this_playback_config = edl->session->playback_config;
189 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
190 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
191 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
192 AudioOutConfig *aconfig = playback_config->aconfig;
193 VideoOutConfig *vconfig = playback_config->vconfig;
196 edl->session->need_rerender(mwindow->edl->session) ||
197 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
198 this_playback_config->active_config != playback_config->active_config ||
199 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
200 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
202 mwindow->edl->copy_session(edl, 1);
203 mwindow->preferences->copy_from(preferences);
204 mwindow->init_brender();
206 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
207 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
209 mwindow->reset_android_remote();
210 mwindow->gui->mbuttons->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
211 mwindow->gui->mainshbtns->load(mwindow->preferences);
213 //edl->session->recording_format->dump();
214 //mwindow->edl->session->recording_format->dump();
216 if(((mwindow->edl->session->output_w % 4) ||
217 (mwindow->edl->session->output_h % 4)) &&
218 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
220 MainError::show_error(
221 _("This project's dimensions are not multiples of 4 so\n"
222 "it can't be rendered by OpenGL."));
228 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
229 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
230 edl->session->min_meter_db,
231 edl->session->max_meter_db);
232 mwindow->cwindow->gui->unlock_window();
236 for(int i = 0; i < mwindow->vwindows.size(); i++)
238 VWindow *vwindow = mwindow->vwindows.get(i);
239 vwindow->gui->lock_window("PreferencesThread::apply_settings");
240 vwindow->gui->meters->change_format(edl->session->meter_format,
241 edl->session->min_meter_db,
242 edl->session->max_meter_db);
243 vwindow->gui->unlock_window();
248 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
249 mwindow->gui->set_meter_format(edl->session->meter_format,
250 edl->session->min_meter_db,
251 edl->session->max_meter_db);
252 mwindow->gui->unlock_window();
256 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
257 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
258 edl->session->min_meter_db,
259 edl->session->max_meter_db);
260 mwindow->lwindow->gui->unlock_window();
265 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
266 mwindow->gui->draw_overlays(1);
267 mwindow->gui->unlock_window();
272 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
273 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
274 mwindow->gui->redraw_time_dependancies();
275 mwindow->gui->unlock_window();
280 //printf("PreferencesThread::apply_settings 1\n");
281 // This doesn't stop and restart, only reloads the assets before
282 // the next play command.
283 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
287 //printf("PreferencesThread::apply_settings 10\n");
290 if(redraw_times || redraw_overlays)
292 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
293 mwindow->gui->flush();
294 mwindow->gui->unlock_window();
300 const char* PreferencesThread::category_to_text(int category)
302 PlaybackConfig *playback_config = edl->session->playback_config;
306 return playback_config->active_config==0 ?
307 _("*Playback A") : _("Playback A");
309 return playback_config->active_config==1 ?
310 _("*Playback B") : _("Playback B");
312 return _("Recording");
314 return _("Performance");
316 return _("Interface");
323 int PreferencesThread::text_to_category(const char *category)
326 int min_result = -1, result, result_num = 0;
327 for(int i = 0; i < CATEGORIES; i++)
329 result = labs(strcmp(category_to_text(i), category));
330 if(result < min_result || min_result < 0)
347 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
348 PreferencesThread *thread,
351 : BC_Window(_(PROGRAM_NAME ": Preferences"),
362 this->mwindow = mwindow;
363 this->thread = thread;
368 PreferencesWindow::~PreferencesWindow()
370 lock_window("PreferencesWindow::~PreferencesWindow");
374 if(dialog) delete dialog;
377 for(int i = 0; i < categories.total; i++)
378 delete categories.values[i];
382 void PreferencesWindow::create_objects()
388 lock_window("PreferencesWindow::create_objects");
390 mwindow->theme->draw_preferences_bg(this);
393 int x = mwindow->theme->preferencescategory_x;
394 int y = mwindow->theme->preferencescategory_y;
395 for(int i = 0; i < CATEGORIES; i++)
397 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
402 thread->category_to_text(i),
403 (i == thread->current_dialog) ?
404 mwindow->theme->get_image_set("category_button_checked") :
405 mwindow->theme->get_image_set("category_button")));
406 x += category_button[i]->get_w() -
407 mwindow->theme->preferences_category_overlap;
411 // for(int i = 0; i < CATEGORIES; i++)
412 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
413 // category = new PreferencesCategory(mwindow,
415 // mwindow->theme->preferencescategory_x,
416 // mwindow->theme->preferencescategory_y);
417 // category->create_objects();
420 add_subwindow(button = new PreferencesOK(mwindow, thread));
421 add_subwindow(new PreferencesApply(mwindow, thread));
422 add_subwindow(new PreferencesCancel(mwindow, thread));
424 set_current_dialog(thread->current_dialog);
430 int PreferencesWindow::update_framerate()
432 lock_window("PreferencesWindow::update_framerate");
433 if(thread->current_dialog < PreferencesThread::RECORD)
435 dialog->draw_framerate(1);
443 void PreferencesWindow::update_rates()
445 lock_window("PreferencesWindow::update_rates");
446 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
448 dialog->update_rates();
454 int PreferencesWindow::set_current_dialog(int number)
456 if(dialog) delete dialog;
458 thread->current_dialog = number;
461 PreferencesDialog *dialog2 = dialog;
465 // Redraw category buttons
466 for(int i = 0; i < CATEGORIES; i++)
470 category_button[i]->set_images(
471 mwindow->theme->get_image_set("category_button_checked"));
475 category_button[i]->set_images(
476 mwindow->theme->get_image_set("category_button"));
478 category_button[i]->draw_face(0);
480 // Copy face to background for next button's overlap.
481 // Still can't do state changes right.
486 PlaybackConfig *playback_config = thread->edl->session->playback_config;
489 case PreferencesThread::PLAYBACK_A:
490 case PreferencesThread::PLAYBACK_B:
491 playback_config->load_defaults(mwindow->defaults,
492 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
493 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
496 case PreferencesThread::RECORD:
497 add_subwindow(dialog = new RecordPrefs(mwindow, this));
500 case PreferencesThread::PERFORMANCE:
501 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
504 case PreferencesThread::INTERFACE:
505 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
508 case PreferencesThread::ABOUT:
509 add_subwindow(dialog = new AboutPrefs(mwindow, this));
516 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
517 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
518 dialog->create_objects();
519 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
520 dialog->show_window(0);
525 dialog2->hide_window(0);
542 PreferencesButton::PreferencesButton(MWindow *mwindow,
543 PreferencesThread *thread,
549 : BC_GenericButton(x, y, text, images)
551 this->mwindow = mwindow;
552 this->thread = thread;
553 this->category = category;
556 int PreferencesButton::handle_event()
558 thread->window->set_current_dialog(category);
570 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
571 PreferencesWindow *pwindow)
574 pwindow->get_w() - 20,
575 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
577 this->pwindow = pwindow;
578 this->mwindow = mwindow;
579 preferences = pwindow->thread->preferences;
582 PreferencesDialog::~PreferencesDialog()
586 // ============================== category window
591 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
592 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
593 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
596 this->mwindow = mwindow;
597 this->thread = thread;
600 int PreferencesApply::handle_event()
602 thread->apply_settings();
609 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
610 : BC_GenericButton(10,
611 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
614 this->mwindow = mwindow;
615 this->thread = thread;
618 int PreferencesOK::keypress_event()
620 if(get_keypress() == RETURN)
622 thread->window->set_done(0);
627 int PreferencesOK::handle_event()
629 thread->window->set_done(0);
635 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
636 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
637 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
640 this->mwindow = mwindow;
641 this->thread = thread;
643 int PreferencesCancel::keypress_event()
645 if(get_keypress() == ESC)
647 thread->window->set_done(1);
653 int PreferencesCancel::handle_event()
655 thread->window->set_done(1);
668 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
669 : BC_PopupTextBox(thread->window,
670 &thread->window->categories,
671 thread->category_to_text(thread->current_dialog),
677 this->mwindow = mwindow;
678 this->thread = thread;
681 PreferencesCategory::~PreferencesCategory()
685 int PreferencesCategory::handle_event()
688 thread->window->set_current_dialog(thread->text_to_category(get_text()));