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);
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 if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
224 BC_Trace::enable_locks();
227 BC_Trace::disable_locks();
230 mwindow->reset_android_remote();
231 mwindow->gui->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
232 mwindow->gui->ffmpeg_toggle->set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
233 _("Try FFMpeg first") : _("Try FFMpeg last") );
234 mwindow->gui->mainshbtns->load(mwindow->preferences);
236 mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;
237 mwindow->gui->mainclock->set_position_offset(tc_position);
239 //edl->session->recording_format->dump();
240 //mwindow->edl->session->recording_format->dump();
242 if(((mwindow->edl->session->output_w % 4) ||
243 (mwindow->edl->session->output_h % 4)) &&
244 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
246 MainError::show_error(
247 _("This project's dimensions are not multiples of 4 so\n"
248 "it can't be rendered by OpenGL."));
254 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
255 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
256 edl->session->min_meter_db,
257 edl->session->max_meter_db);
258 mwindow->cwindow->gui->unlock_window();
262 for(int i = 0; i < mwindow->vwindows.size(); i++) {
263 VWindow *vwindow = mwindow->vwindows.get(i);
264 if( !vwindow->is_running() ) continue;
265 vwindow->gui->lock_window("PreferencesThread::apply_settings");
266 vwindow->gui->meters->change_format(edl->session->meter_format,
267 edl->session->min_meter_db,
268 edl->session->max_meter_db);
269 vwindow->gui->unlock_window();
274 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
275 mwindow->gui->set_meter_format(edl->session->meter_format,
276 edl->session->min_meter_db,
277 edl->session->max_meter_db);
278 mwindow->gui->unlock_window();
282 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
283 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
284 edl->session->min_meter_db,
285 edl->session->max_meter_db);
286 mwindow->lwindow->gui->unlock_window();
291 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
292 mwindow->gui->draw_overlays(1);
293 mwindow->gui->unlock_window();
298 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
299 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
300 mwindow->gui->redraw_time_dependancies();
301 mwindow->gui->unlock_window();
306 //printf("PreferencesThread::apply_settings 1\n");
307 // This doesn't stop and restart, only reloads the assets before
308 // the next play command.
309 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
313 //printf("PreferencesThread::apply_settings 10\n");
316 if(redraw_times || redraw_overlays)
318 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
319 mwindow->gui->flush();
320 mwindow->gui->unlock_window();
326 const char* PreferencesThread::category_to_text(int category)
328 PlaybackConfig *playback_config = edl->session->playback_config;
332 return playback_config->active_config==0 ?
333 _("*Playback A") : _("Playback A");
335 return playback_config->active_config==1 ?
336 _("*Playback B") : _("Playback B");
338 return _("Recording");
340 return _("Performance");
342 return _("Interface");
349 int PreferencesThread::text_to_category(const char *category)
352 int min_result = -1, result, result_num = 0;
353 for(int i = 0; i < CATEGORIES; i++)
355 result = labs(strcmp(category_to_text(i), category));
356 if(result < min_result || min_result < 0)
373 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
374 PreferencesThread *thread, int x, int y, int w, int h)
375 : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
377 this->mwindow = mwindow;
378 this->thread = thread;
383 PreferencesWindow::~PreferencesWindow()
385 lock_window("PreferencesWindow::~PreferencesWindow");
389 if(dialog) delete dialog;
392 for(int i = 0; i < categories.total; i++)
393 delete categories.values[i];
397 void PreferencesWindow::create_objects()
401 lock_window("PreferencesWindow::create_objects");
402 set_icon(mwindow->theme->get_image("mwindow_icon"));
403 mwindow->theme->draw_preferences_bg(this);
406 int x = mwindow->theme->preferencescategory_x;
407 int y = mwindow->theme->preferencescategory_y;
408 for(int i = 0; i < CATEGORIES; i++)
410 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
415 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::ABOUT:
522 add_subwindow(dialog = new AboutPrefs(mwindow, this));
529 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
530 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
531 dialog->create_objects();
532 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
533 dialog->lower_window();
534 dialog->show_window(0);
539 dialog2->hide_window(0);
556 PreferencesButton::PreferencesButton(MWindow *mwindow,
557 PreferencesThread *thread,
563 : BC_GenericButton(x, y, text, images)
565 this->mwindow = mwindow;
566 this->thread = thread;
567 this->category = category;
570 int PreferencesButton::handle_event()
572 thread->window->set_current_dialog(category);
584 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
585 PreferencesWindow *pwindow)
588 pwindow->get_w() - 20,
589 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
591 this->pwindow = pwindow;
592 this->mwindow = mwindow;
593 preferences = pwindow->thread->preferences;
596 PreferencesDialog::~PreferencesDialog()
600 // ============================== category window
605 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
606 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
607 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
610 this->mwindow = mwindow;
611 this->thread = thread;
613 int PreferencesApply::handle_event()
615 thread->apply_settings();
618 int PreferencesApply::resize_event(int w, int h)
620 reposition_window(w/2 - get_w()/2, h-get_h()-10);
627 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
628 : BC_GenericButton(10,
629 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
632 this->mwindow = mwindow;
633 this->thread = thread;
635 int PreferencesOK::keypress_event()
637 if(get_keypress() == RETURN)
639 thread->window->set_done(0);
644 int PreferencesOK::handle_event()
646 thread->window->set_done(0);
649 int PreferencesOK::resize_event(int w, int h)
651 reposition_window(10, h-get_h()-10);
657 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
658 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
659 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
662 this->mwindow = mwindow;
663 this->thread = thread;
665 int PreferencesCancel::keypress_event()
667 if(get_keypress() == ESC)
669 thread->window->set_done(1);
674 int PreferencesCancel::handle_event()
676 thread->window->set_done(1);
679 int PreferencesCancel::resize_event(int w, int h)
681 reposition_window(w-get_w()-10, h-get_h()-10);
694 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
695 : BC_PopupTextBox(thread->window,
696 &thread->window->categories,
697 thread->category_to_text(thread->current_dialog),
703 this->mwindow = mwindow;
704 this->thread = thread;
707 PreferencesCategory::~PreferencesCategory()
711 int PreferencesCategory::handle_event()
714 thread->window->set_current_dialog(thread->text_to_category(get_text()));