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"
53 #include "trackcanvas.h"
54 #include "transportque.h"
56 #include "vwindowgui.h"
66 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
67 : BC_MenuItem(_("Preferences..."), _("Shift+P"), 'P')
69 this->mwindow = mwindow;
72 thread = new PreferencesThread(mwindow);
75 PreferencesMenuitem::~PreferencesMenuitem()
81 int PreferencesMenuitem::handle_event()
83 mwindow->gui->unlock_window();
85 mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
92 PreferencesThread::PreferencesThread(MWindow *mwindow)
95 this->mwindow = mwindow;
100 PreferencesThread::~PreferencesThread()
104 BC_Window* PreferencesThread::new_gui()
107 preferences = new Preferences;
109 edl->create_objects();
110 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
111 preferences->copy_from(mwindow->preferences);
112 edl->copy_session(mwindow->edl);
119 //int need_new_indexes = 0;
122 mwindow->gui->lock_window("NewThread::new_gui");
123 int scr_x = mwindow->gui->get_screen_x(0, -1);
124 int scr_w = mwindow->gui->get_screen_w(0, -1);
125 int scr_h = mwindow->gui->get_screen_h(0, -1);
127 int x = scr_x + scr_w / 2 - WIDTH / 2;
128 int y = scr_h / 2 - HEIGHT / 2;
130 window = new PreferencesWindow(mwindow, this, x, y);
131 window->create_objects();
132 mwindow->gui->unlock_window();
138 void PreferencesThread::handle_close_event(int result)
144 mwindow->save_defaults();
149 edl->Garbage::remove_user();
153 mwindow->defaults->update("DEFAULTPREF", current_dialog);
158 int PreferencesThread::update_framerate()
162 lock_gui("PreferencesThread::update_framerate");
163 PreferencesWindow *window = (PreferencesWindow*)get_gui();
164 if(window) window->update_framerate();
171 void PreferencesThread::update_rates()
175 lock_gui("PreferencesThread::update_framerate");
176 PreferencesWindow *window = (PreferencesWindow*)get_gui();
177 if(window) window->update_rates();
182 int PreferencesThread::apply_settings()
186 PlaybackConfig *this_playback_config = edl->session->playback_config;
187 AudioOutConfig *this_aconfig = this_playback_config->aconfig;
188 VideoOutConfig *this_vconfig = this_playback_config->vconfig;
189 PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
190 AudioOutConfig *aconfig = playback_config->aconfig;
191 VideoOutConfig *vconfig = playback_config->vconfig;
194 edl->session->need_rerender(mwindow->edl->session) ||
195 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
196 this_playback_config->active_config != playback_config->active_config ||
197 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
198 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
200 if( preferences->file_forking != mwindow->preferences->file_forking ) {
201 MainError::show_error(
202 _("Reseting file forking requires restarting cinelerra"));
204 mwindow->edl->copy_session(edl, 1);
205 mwindow->preferences->copy_from(preferences);
206 mwindow->init_brender();
208 BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
209 BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
211 mwindow->reset_android_remote();
212 mwindow->gui->mbuttons->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
214 //edl->session->recording_format->dump();
215 //mwindow->edl->session->recording_format->dump();
217 if(((mwindow->edl->session->output_w % 4) ||
218 (mwindow->edl->session->output_h % 4)) &&
219 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
221 MainError::show_error(
222 _("This project's dimensions are not multiples of 4 so\n"
223 "it can't be rendered by OpenGL."));
229 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
230 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
231 edl->session->min_meter_db,
232 edl->session->max_meter_db);
233 mwindow->cwindow->gui->unlock_window();
237 for(int i = 0; i < mwindow->vwindows.size(); i++)
239 VWindow *vwindow = mwindow->vwindows.get(i);
240 vwindow->gui->lock_window("PreferencesThread::apply_settings");
241 vwindow->gui->meters->change_format(edl->session->meter_format,
242 edl->session->min_meter_db,
243 edl->session->max_meter_db);
244 vwindow->gui->unlock_window();
249 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
250 mwindow->gui->set_meter_format(edl->session->meter_format,
251 edl->session->min_meter_db,
252 edl->session->max_meter_db);
253 mwindow->gui->unlock_window();
257 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
258 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
259 edl->session->min_meter_db,
260 edl->session->max_meter_db);
261 mwindow->lwindow->gui->unlock_window();
266 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
267 mwindow->gui->draw_overlays(1);
268 mwindow->gui->unlock_window();
273 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
274 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
275 mwindow->gui->redraw_time_dependancies();
276 mwindow->gui->unlock_window();
281 //printf("PreferencesThread::apply_settings 1\n");
282 // This doesn't stop and restart, only reloads the assets before
283 // the next play command.
284 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
288 //printf("PreferencesThread::apply_settings 10\n");
291 if(redraw_times || redraw_overlays)
293 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
294 mwindow->gui->flush();
295 mwindow->gui->unlock_window();
301 const char* PreferencesThread::category_to_text(int category)
303 PlaybackConfig *playback_config = edl->session->playback_config;
307 return playback_config->active_config==0 ?
308 _("*Playback A") : _("Playback A");
310 return playback_config->active_config==1 ?
311 _("*Playback B") : _("Playback B");
313 return _("Recording");
315 return _("Performance");
317 return _("Interface");
324 int PreferencesThread::text_to_category(const char *category)
327 int min_result = -1, result, result_num = 0;
328 for(int i = 0; i < CATEGORIES; i++)
330 result = labs(strcmp(category_to_text(i), category));
331 if(result < min_result || min_result < 0)
348 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
349 PreferencesThread *thread,
352 : BC_Window(_(PROGRAM_NAME ": Preferences"),
363 this->mwindow = mwindow;
364 this->thread = thread;
369 PreferencesWindow::~PreferencesWindow()
371 lock_window("PreferencesWindow::~PreferencesWindow");
375 if(dialog) delete dialog;
378 for(int i = 0; i < categories.total; i++)
379 delete categories.values[i];
383 void PreferencesWindow::create_objects()
389 lock_window("PreferencesWindow::create_objects");
391 mwindow->theme->draw_preferences_bg(this);
394 int x = mwindow->theme->preferencescategory_x;
395 int y = mwindow->theme->preferencescategory_y;
396 for(int i = 0; i < CATEGORIES; i++)
398 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
403 thread->category_to_text(i),
404 (i == thread->current_dialog) ?
405 mwindow->theme->get_image_set("category_button_checked") :
406 mwindow->theme->get_image_set("category_button")));
407 x += category_button[i]->get_w() -
408 mwindow->theme->preferences_category_overlap;
412 // for(int i = 0; i < CATEGORIES; i++)
413 // categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
414 // category = new PreferencesCategory(mwindow,
416 // mwindow->theme->preferencescategory_x,
417 // mwindow->theme->preferencescategory_y);
418 // category->create_objects();
421 add_subwindow(button = new PreferencesOK(mwindow, thread));
422 add_subwindow(new PreferencesApply(mwindow, thread));
423 add_subwindow(new PreferencesCancel(mwindow, thread));
425 set_current_dialog(thread->current_dialog);
431 int PreferencesWindow::update_framerate()
433 lock_window("PreferencesWindow::update_framerate");
434 if(thread->current_dialog < PreferencesThread::RECORD)
436 dialog->draw_framerate(1);
444 void PreferencesWindow::update_rates()
446 lock_window("PreferencesWindow::update_rates");
447 if(thread->current_dialog == PreferencesThread::PERFORMANCE)
449 dialog->update_rates();
455 int PreferencesWindow::set_current_dialog(int number)
457 if(dialog) delete dialog;
459 thread->current_dialog = number;
462 PreferencesDialog *dialog2 = dialog;
466 // Redraw category buttons
467 for(int i = 0; i < CATEGORIES; i++)
471 category_button[i]->set_images(
472 mwindow->theme->get_image_set("category_button_checked"));
476 category_button[i]->set_images(
477 mwindow->theme->get_image_set("category_button"));
479 category_button[i]->draw_face(0);
481 // Copy face to background for next button's overlap.
482 // Still can't do state changes right.
487 PlaybackConfig *playback_config = thread->edl->session->playback_config;
490 case PreferencesThread::PLAYBACK_A:
491 case PreferencesThread::PLAYBACK_B:
492 playback_config->load_defaults(mwindow->defaults,
493 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
494 add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
497 case PreferencesThread::RECORD:
498 add_subwindow(dialog = new RecordPrefs(mwindow, this));
501 case PreferencesThread::PERFORMANCE:
502 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
505 case PreferencesThread::INTERFACE:
506 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
509 case PreferencesThread::ABOUT:
510 add_subwindow(dialog = new AboutPrefs(mwindow, this));
517 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
518 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
519 dialog->create_objects();
520 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
521 dialog->show_window(0);
526 dialog2->hide_window(0);
543 PreferencesButton::PreferencesButton(MWindow *mwindow,
544 PreferencesThread *thread,
550 : BC_GenericButton(x, y, text, images)
552 this->mwindow = mwindow;
553 this->thread = thread;
554 this->category = category;
557 int PreferencesButton::handle_event()
559 thread->window->set_current_dialog(category);
571 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
572 PreferencesWindow *pwindow)
575 pwindow->get_w() - 20,
576 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
578 this->pwindow = pwindow;
579 this->mwindow = mwindow;
580 preferences = pwindow->thread->preferences;
583 PreferencesDialog::~PreferencesDialog()
587 // ============================== category window
592 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
593 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
594 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
597 this->mwindow = mwindow;
598 this->thread = thread;
601 int PreferencesApply::handle_event()
603 thread->apply_settings();
610 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
611 : BC_GenericButton(10,
612 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
615 this->mwindow = mwindow;
616 this->thread = thread;
619 int PreferencesOK::keypress_event()
621 if(get_keypress() == RETURN)
623 thread->window->set_done(0);
628 int PreferencesOK::handle_event()
630 thread->window->set_done(0);
636 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
637 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
638 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
641 this->mwindow = mwindow;
642 this->thread = thread;
644 int PreferencesCancel::keypress_event()
646 if(get_keypress() == ESC)
648 thread->window->set_done(1);
654 int PreferencesCancel::handle_event()
656 thread->window->set_done(1);
669 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
670 : BC_PopupTextBox(thread->window,
671 &thread->window->categories,
672 thread->category_to_text(thread->current_dialog),
678 this->mwindow = mwindow;
679 this->thread = thread;
682 PreferencesCategory::~PreferencesCategory()
686 int PreferencesCategory::handle_event()
689 thread->window->set_current_dialog(thread->text_to_category(get_text()));