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"
41 #include "meterpanel.h"
44 #include "mwindowgui.h"
46 #include "performanceprefs.h"
47 #include "playbackengine.h"
48 #include "playbackprefs.h"
49 #include "preferences.h"
50 #include "recordprefs.h"
52 #include "trackcanvas.h"
53 #include "transportque.h"
55 #include "vwindowgui.h"
65 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
66 : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
68 this->mwindow = mwindow;
71 thread = new PreferencesThread(mwindow);
74 PreferencesMenuitem::~PreferencesMenuitem()
80 int PreferencesMenuitem::handle_event()
82 mwindow->gui->unlock_window();
84 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
91 PreferencesThread::PreferencesThread(MWindow *mwindow)
94 this->mwindow = mwindow;
99 PreferencesThread::~PreferencesThread()
103 BC_Window* PreferencesThread::new_gui()
106 preferences = new Preferences;
108 edl->create_objects();
109 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
110 preferences->copy_from(mwindow->preferences);
111 edl->copy_session(mwindow->edl);
118 //int need_new_indexes = 0;
121 mwindow->gui->lock_window("NewThread::new_gui");
122 int scr_x = mwindow->gui->get_screen_x(0, -1);
123 int scr_w = mwindow->gui->get_screen_w(0, -1);
124 int scr_h = mwindow->gui->get_screen_h(0, -1);
126 int x = scr_x + scr_w / 2 - WIDTH / 2;
127 int y = scr_h / 2 - HEIGHT / 2;
129 window = new PreferencesWindow(mwindow, this, x, y);
130 window->create_objects();
131 mwindow->gui->unlock_window();
137 void PreferencesThread::handle_close_event(int result)
143 mwindow->save_defaults();
148 edl->Garbage::remove_user();
152 mwindow->defaults->update("DEFAULTPREF", current_dialog);
157 int PreferencesThread::update_framerate()
161 lock_gui("PreferencesThread::update_framerate");
162 PreferencesWindow *window = (PreferencesWindow*)get_gui();
163 if(window) window->update_framerate();
170 void PreferencesThread::update_rates()
174 lock_gui("PreferencesThread::update_framerate");
175 PreferencesWindow *window = (PreferencesWindow*)get_gui();
176 if(window) window->update_rates();
181 int PreferencesThread::apply_settings()
185 PlaybackConfig *this_playback_config = edl->session->playback_config;
186 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
187 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
188 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
189 AudioOutConfig *aconfig = playback_config->aconfig;
190 VideoOutConfig *vconfig = playback_config->vconfig;
193 edl->session->need_rerender(mwindow->edl->session) ||
194 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
195 this_playback_config->active_config != playback_config->active_config ||
196 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
197 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
199 if( preferences->file_forking != mwindow->preferences->file_forking ) {
200 MainError::show_error(
201 _("Reseting file forking requires restarting cinelerra"));
203 mwindow->edl->copy_session(edl, 1);
204 mwindow->preferences->copy_from(preferences);
205 mwindow->init_brender();
207 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
208 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
210 mwindow->reset_android_remote();
212 //edl->session->recording_format->dump();
213 //mwindow->edl->session->recording_format->dump();
215 if(((mwindow->edl->session->output_w % 4) ||
216 (mwindow->edl->session->output_h % 4)) &&
217 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
219 MainError::show_error(
220 _("This project's dimensions are not multiples of 4 so\n"
221 "it can't be rendered by OpenGL."));
227 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
228 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
229 edl->session->min_meter_db,
230 edl->session->max_meter_db);
231 mwindow->cwindow->gui->unlock_window();
235 for(int i = 0; i < mwindow->vwindows.size(); i++)
237 VWindow *vwindow = mwindow->vwindows.get(i);
238 vwindow->gui->lock_window("PreferencesThread::apply_settings");
239 vwindow->gui->meters->change_format(edl->session->meter_format,
240 edl->session->min_meter_db,
241 edl->session->max_meter_db);
242 vwindow->gui->unlock_window();
247 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
248 mwindow->gui->set_meter_format(edl->session->meter_format,
249 edl->session->min_meter_db,
250 edl->session->max_meter_db);
251 mwindow->gui->unlock_window();
255 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
256 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
257 edl->session->min_meter_db,
258 edl->session->max_meter_db);
259 mwindow->lwindow->gui->unlock_window();
264 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
265 mwindow->gui->draw_overlays(1);
266 mwindow->gui->unlock_window();
271 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
272 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
273 mwindow->gui->redraw_time_dependancies();
274 mwindow->gui->unlock_window();
279 //printf("PreferencesThread::apply_settings 1\n");
280 // This doesn't stop and restart, only reloads the assets before
281 // the next play command.
282 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
286 //printf("PreferencesThread::apply_settings 10\n");
289 if(redraw_times || redraw_overlays)
291 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
292 mwindow->gui->flush();
293 mwindow->gui->unlock_window();
299 const char* PreferencesThread::category_to_text(int category)
301 PlaybackConfig *playback_config = edl->session->playback_config;
305 return playback_config->active_config==0 ?
306 _("*Playback A") : _("Playback A");
308 return playback_config->active_config==1 ?
309 _("*Playback B") : _("Playback B");
311 return _("Recording");
313 return _("Performance");
315 return _("Interface");
322 int PreferencesThread::text_to_category(const char *category)
325 int min_result = -1, result, result_num = 0;
326 for(int i = 0; i < CATEGORIES; i++)
328 result = labs(strcmp(category_to_text(i), category));
329 if(result < min_result || min_result < 0)
346 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
347 PreferencesThread *thread,
350 : BC_Window(PROGRAM_NAME ": Preferences",
361 this->mwindow = mwindow;
362 this->thread = thread;
367 PreferencesWindow::~PreferencesWindow()
369 lock_window("PreferencesWindow::~PreferencesWindow");
373 if(dialog) delete dialog;
376 for(int i = 0; i < categories.total; i++)
377 delete categories.values[i];
381 void PreferencesWindow::create_objects()
387 lock_window("PreferencesWindow::create_objects");
389 mwindow->theme->draw_preferences_bg(this);
392 int x = mwindow->theme->preferencescategory_x;
393 int y = mwindow->theme->preferencescategory_y;
394 for(int i = 0; i < CATEGORIES; i++)
396 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
401 thread->category_to_text(i),
402 (i == thread->current_dialog) ?
403 mwindow->theme->get_image_set("category_button_checked") :
404 mwindow->theme->get_image_set("category_button")));
405 x += category_button[i]->get_w() -
406 mwindow->theme->preferences_category_overlap;
410 // for(int i = 0; i < CATEGORIES; i++)
411 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
412 // category = new PreferencesCategory(mwindow,
414 // mwindow->theme->preferencescategory_x,
415 // mwindow->theme->preferencescategory_y);
416 // category->create_objects();
419 add_subwindow(button = new PreferencesOK(mwindow, thread));
420 add_subwindow(new PreferencesApply(mwindow, thread));
421 add_subwindow(new PreferencesCancel(mwindow, thread));
423 set_current_dialog(thread->current_dialog);
429 int PreferencesWindow::update_framerate()
431 lock_window("PreferencesWindow::update_framerate");
432 if(thread->current_dialog < PreferencesThread::RECORD)
434 dialog->draw_framerate(1);
442 void PreferencesWindow::update_rates()
444 lock_window("PreferencesWindow::update_rates");
445 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
447 dialog->update_rates();
453 int PreferencesWindow::set_current_dialog(int number)
455 if(dialog) delete dialog;
457 thread->current_dialog = number;
460 PreferencesDialog *dialog2 = dialog;
464 // Redraw category buttons
465 for(int i = 0; i < CATEGORIES; i++)
469 category_button[i]->set_images(
470 mwindow->theme->get_image_set("category_button_checked"));
474 category_button[i]->set_images(
475 mwindow->theme->get_image_set("category_button"));
477 category_button[i]->draw_face(0);
479 // Copy face to background for next button's overlap.
480 // Still can't do state changes right.
485 PlaybackConfig *playback_config = thread->edl->session->playback_config;
488 case PreferencesThread::PLAYBACK_A:
489 case PreferencesThread::PLAYBACK_B:
490 playback_config->load_defaults(mwindow->defaults,
491 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
492 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
495 case PreferencesThread::RECORD:
496 add_subwindow(dialog = new RecordPrefs(mwindow, this));
499 case PreferencesThread::PERFORMANCE:
500 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
503 case PreferencesThread::INTERFACE:
504 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
507 case PreferencesThread::ABOUT:
508 add_subwindow(dialog = new AboutPrefs(mwindow, this));
515 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
516 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
517 dialog->create_objects();
518 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
519 dialog->show_window(0);
524 dialog2->hide_window(0);
541 PreferencesButton::PreferencesButton(MWindow *mwindow,
542 PreferencesThread *thread,
548 : BC_GenericButton(x, y, text, images)
550 this->mwindow = mwindow;
551 this->thread = thread;
552 this->category = category;
555 int PreferencesButton::handle_event()
557 thread->window->set_current_dialog(category);
569 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
570 PreferencesWindow *pwindow)
573 pwindow->get_w() - 20,
574 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
576 this->pwindow = pwindow;
577 this->mwindow = mwindow;
578 preferences = pwindow->thread->preferences;
581 PreferencesDialog::~PreferencesDialog()
585 // ============================== category window
590 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
591 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
592 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
595 this->mwindow = mwindow;
596 this->thread = thread;
599 int PreferencesApply::handle_event()
601 thread->apply_settings();
608 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
609 : BC_GenericButton(10,
610 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
613 this->mwindow = mwindow;
614 this->thread = thread;
617 int PreferencesOK::keypress_event()
619 if(get_keypress() == RETURN)
621 thread->window->set_done(0);
626 int PreferencesOK::handle_event()
628 thread->window->set_done(0);
634 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
635 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
636 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
639 this->mwindow = mwindow;
640 this->thread = thread;
642 int PreferencesCancel::keypress_event()
644 if(get_keypress() == ESC)
646 thread->window->set_done(1);
652 int PreferencesCancel::handle_event()
654 thread->window->set_done(1);
667 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
668 : BC_PopupTextBox(thread->window,
669 &thread->window->categories,
670 thread->category_to_text(thread->current_dialog),
676 this->mwindow = mwindow;
677 this->thread = thread;
680 PreferencesCategory::~PreferencesCategory()
684 int PreferencesCategory::handle_event()
687 thread->window->set_current_dialog(thread->text_to_category(get_text()));