00001 #include "aboutprefs.h"
00002 #include "asset.h"
00003 #include "audiodevice.inc"
00004 #include "cache.h"
00005 #include "cplayback.h"
00006 #include "cwindow.h"
00007 #include "cwindowgui.h"
00008 #include "defaults.h"
00009 #include "edl.h"
00010 #include "edlsession.h"
00011 #include "filesystem.h"
00012 #include "fonts.h"
00013 #include "interfaceprefs.h"
00014 #include "keys.h"
00015 #include "language.h"
00016 #include "levelwindow.h"
00017 #include "levelwindowgui.h"
00018 #include "meterpanel.h"
00019 #include "mutex.h"
00020 #include "mwindow.h"
00021 #include "mwindowgui.h"
00022 #include "patchbay.h"
00023 #include "performanceprefs.h"
00024 #include "playbackengine.h"
00025 #include "playbackprefs.h"
00026 #include "preferences.h"
00027 #include "recordprefs.h"
00028 #include "theme.h"
00029 #include "trackcanvas.h"
00030 #include "transportque.h"
00031 #include "vwindow.h"
00032 #include "vwindowgui.h"
00033
00034 #include <string.h>
00035
00036
00037
00038 #define WIDTH 750
00039 #define HEIGHT 700
00040
00041
00042 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
00043 : BC_MenuItem(_("Preferences..."), "Shift+P", 'P')
00044 {
00045 this->mwindow = mwindow;
00046
00047 set_shift(1);
00048 thread = new PreferencesThread(mwindow);
00049 }
00050
00051 PreferencesMenuitem::~PreferencesMenuitem()
00052 {
00053 delete thread;
00054 }
00055
00056
00057 int PreferencesMenuitem::handle_event()
00058 {
00059 if(!thread->running())
00060 {
00061 thread->start();
00062 }
00063 else
00064 {
00065
00066
00067 if(thread->window)
00068 {
00069 thread->window_lock->lock("SetFormat::handle_event");
00070 thread->window->lock_window("PreferencesMenuitem::handle_event");
00071 thread->window->raise_window();
00072 thread->window->unlock_window();
00073 thread->window_lock->unlock();
00074 }
00075 }
00076 return 1;
00077 }
00078
00079
00080
00081
00082 PreferencesThread::PreferencesThread(MWindow *mwindow)
00083 : Thread()
00084 {
00085 this->mwindow = mwindow;
00086 window = 0;
00087 thread_running = 0;
00088 window_lock = new Mutex("PreferencesThread::window_lock");
00089 }
00090
00091 PreferencesThread::~PreferencesThread()
00092 {
00093 delete window_lock;
00094 }
00095
00096 void PreferencesThread::run()
00097 {
00098 int need_new_indexes;
00099
00100 preferences = new Preferences;
00101 edl = new EDL;
00102 edl->create_objects();
00103 current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
00104 preferences->copy_from(mwindow->preferences);
00105 edl->copy_session(mwindow->edl);
00106 redraw_indexes = 0;
00107 redraw_meters = 0;
00108 redraw_times = 0;
00109 redraw_overlays = 0;
00110 close_assets = 0;
00111 reload_plugins = 0;
00112 need_new_indexes = 0;
00113 rerender = 0;
00114
00115 int x = mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2;
00116 int y = mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2;
00117
00118 window_lock->lock("PreferencesThread::run 1");
00119 window = new PreferencesWindow(mwindow, this, x, y);
00120 window->create_objects();
00121 window_lock->unlock();
00122
00123 thread_running = 1;
00124 int result = window->run_window();
00125
00126 thread_running = 0;
00127 if(!result)
00128 {
00129 apply_settings();
00130 mwindow->save_defaults();
00131 }
00132
00133 window_lock->lock("PreferencesThread::run 2");
00134 delete window;
00135 window = 0;
00136 window_lock->unlock();
00137 delete preferences;
00138 delete edl;
00139
00140 mwindow->defaults->update("DEFAULTPREF", current_dialog);
00141 }
00142
00143 int PreferencesThread::update_framerate()
00144 {
00145 if(thread_running && window)
00146 {
00147 window->update_framerate();
00148 }
00149 return 0;
00150 }
00151
00152 int PreferencesThread::apply_settings()
00153 {
00154
00155
00156
00157 AudioOutConfig *this_aconfig = edl->session->playback_config->aconfig;
00158 VideoOutConfig *this_vconfig = edl->session->playback_config->vconfig;
00159 AudioOutConfig *aconfig = mwindow->edl->session->playback_config->aconfig;
00160 VideoOutConfig *vconfig = mwindow->edl->session->playback_config->vconfig;
00161
00162
00163 rerender =
00164 (edl->session->playback_preload != mwindow->edl->session->playback_preload) ||
00165 (edl->session->interpolation_type != mwindow->edl->session->interpolation_type) ||
00166 (edl->session->video_every_frame != mwindow->edl->session->video_every_frame) ||
00167 (edl->session->real_time_playback != mwindow->edl->session->real_time_playback) ||
00168 (edl->session->playback_software_position != mwindow->edl->session->playback_software_position) ||
00169 (edl->session->test_playback_edits != mwindow->edl->session->test_playback_edits) ||
00170 (edl->session->playback_buffer != mwindow->edl->session->playback_buffer) ||
00171 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
00172 (*this_aconfig != *aconfig) ||
00173 (*this_vconfig != *vconfig) ||
00174 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
00175
00176
00177
00178
00179
00180 mwindow->edl->copy_session(edl);
00181 mwindow->preferences->copy_from(preferences);
00182 mwindow->init_brender();
00183
00184 if(redraw_meters)
00185 {
00186 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
00187 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
00188 edl->session->min_meter_db,
00189 edl->session->max_meter_db);
00190 mwindow->cwindow->gui->unlock_window();
00191
00192
00193
00194 mwindow->vwindow->gui->lock_window("PreferencesThread::apply_settings");
00195 mwindow->vwindow->gui->meters->change_format(edl->session->meter_format,
00196 edl->session->min_meter_db,
00197 edl->session->max_meter_db);
00198 mwindow->vwindow->gui->unlock_window();
00199
00200
00201
00202 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
00203 mwindow->gui->patchbay->change_meter_format(edl->session->meter_format,
00204 edl->session->min_meter_db,
00205 edl->session->max_meter_db);
00206 mwindow->gui->unlock_window();
00207
00208
00209
00210 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
00211 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
00212 edl->session->min_meter_db,
00213 edl->session->max_meter_db);
00214 mwindow->lwindow->gui->unlock_window();
00215 }
00216
00217 if(redraw_overlays)
00218 {
00219 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
00220 mwindow->gui->canvas->draw_overlays();
00221 mwindow->gui->canvas->flash();
00222 mwindow->gui->unlock_window();
00223 }
00224
00225 if(redraw_times)
00226 {
00227 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
00228 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
00229 mwindow->gui->redraw_time_dependancies();
00230 mwindow->gui->unlock_window();
00231 }
00232
00233 if(rerender)
00234 {
00235 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
00236 CHANGE_ALL,
00237 mwindow->edl,
00238 1);
00239 }
00240
00241 if(redraw_times || redraw_overlays)
00242 {
00243 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
00244 mwindow->gui->flush();
00245 mwindow->gui->unlock_window();
00246 }
00247 return 0;
00248 }
00249
00250 char* PreferencesThread::category_to_text(int category)
00251 {
00252 switch(category)
00253 {
00254 case 0:
00255 return _("Playback");
00256 break;
00257 case 1:
00258 return _("Recording");
00259 break;
00260 case 2:
00261 return _("Performance");
00262 break;
00263 case 3:
00264 return _("Interface");
00265 break;
00266
00267
00268
00269 case 4:
00270 return _("About");
00271 break;
00272 }
00273 return "";
00274 }
00275
00276 int PreferencesThread::text_to_category(char *category)
00277 {
00278 int min_result = -1, result, result_num = 0;
00279 for(int i = 0; i < CATEGORIES; i++)
00280 {
00281 result = labs(strcmp(category_to_text(i), category));
00282 if(result < min_result || min_result < 0)
00283 {
00284 min_result = result;
00285 result_num = i;
00286 }
00287 }
00288 return result_num;
00289 }
00290
00291
00292
00293
00294
00295
00296
00297
00298 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
00299 PreferencesThread *thread,
00300 int x,
00301 int y)
00302 : BC_Window(PROGRAM_NAME ": Preferences",
00303 x,
00304 y,
00305 WIDTH,
00306 HEIGHT,
00307 (int)BC_INFINITY,
00308 (int)BC_INFINITY,
00309 0,
00310 0,
00311 1)
00312 {
00313 this->mwindow = mwindow;
00314 this->thread = thread;
00315 dialog = 0;
00316 }
00317
00318 PreferencesWindow::~PreferencesWindow()
00319 {
00320 delete category;
00321 if(dialog) delete dialog;
00322 for(int i = 0; i < categories.total; i++)
00323 delete categories.values[i];
00324 }
00325
00326 int PreferencesWindow::create_objects()
00327 {
00328 BC_Button *button;
00329
00330
00331
00332 mwindow->theme->draw_preferences_bg(this);
00333 flash();
00334
00335
00336 for(int i = 0; i < CATEGORIES; i++)
00337 categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
00338 category = new PreferencesCategory(mwindow,
00339 thread,
00340 mwindow->theme->preferencescategory_x,
00341 mwindow->theme->preferencescategory_y);
00342 category->create_objects();
00343
00344
00345 add_subwindow(button = new PreferencesOK(mwindow, thread));
00346 add_subwindow(new PreferencesApply(mwindow, thread));
00347 add_subwindow(new PreferencesCancel(mwindow, thread));
00348
00349 set_current_dialog(thread->current_dialog);
00350 show_window();
00351 return 0;
00352 }
00353
00354 int PreferencesWindow::update_framerate()
00355 {
00356 lock_window("PreferencesWindow::update_framerate");
00357 if(thread->current_dialog == 0)
00358 {
00359 thread->edl->session->actual_frame_rate =
00360 mwindow->edl->session->actual_frame_rate;
00361 dialog->draw_framerate();
00362 flash();
00363 }
00364 unlock_window();
00365 return 0;
00366 }
00367
00368 int PreferencesWindow::set_current_dialog(int number)
00369 {
00370 thread->current_dialog = number;
00371 if(dialog) delete dialog;
00372 dialog = 0;
00373
00374 switch(number)
00375 {
00376 case 0:
00377 add_subwindow(dialog = new PlaybackPrefs(mwindow, this));
00378 break;
00379
00380 case 1:
00381 add_subwindow(dialog = new RecordPrefs(mwindow, this));
00382 break;
00383
00384 case 2:
00385 add_subwindow(dialog = new PerformancePrefs(mwindow, this));
00386 break;
00387
00388 case 3:
00389 add_subwindow(dialog = new InterfacePrefs(mwindow, this));
00390 break;
00391
00392
00393
00394
00395
00396 case 4:
00397 add_subwindow(dialog = new AboutPrefs(mwindow, this));
00398 break;
00399 }
00400 if(dialog)
00401 {
00402 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
00403 dialog->flash();
00404 dialog->create_objects();
00405 }
00406 return 0;
00407 }
00408
00409
00410
00411
00412
00413 PreferencesDialog::PreferencesDialog(MWindow *mwindow, PreferencesWindow *pwindow)
00414 : BC_SubWindow(10,
00415 40,
00416 pwindow->get_w() - 20,
00417 pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
00418 {
00419 this->pwindow = pwindow;
00420 this->mwindow = mwindow;
00421 preferences = pwindow->thread->preferences;
00422 }
00423
00424 PreferencesDialog::~PreferencesDialog()
00425 {
00426 }
00427
00428
00429
00430
00431
00432
00433 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
00434 : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
00435 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
00436 _("Apply"))
00437 {
00438 this->mwindow = mwindow;
00439 this->thread = thread;
00440 }
00441
00442 int PreferencesApply::handle_event()
00443 {
00444 thread->apply_settings();
00445 return 1;
00446 }
00447
00448
00449
00450
00451 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
00452 : BC_GenericButton(10,
00453 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
00454 _("OK"))
00455 {
00456 this->mwindow = mwindow;
00457 this->thread = thread;
00458 }
00459
00460 int PreferencesOK::keypress_event()
00461 {
00462 if(get_keypress() == RETURN)
00463 {
00464 thread->window->set_done(0);
00465 return 1;
00466 }
00467 return 0;
00468 }
00469 int PreferencesOK::handle_event()
00470 {
00471 thread->window->set_done(0);
00472 return 1;
00473 }
00474
00475
00476
00477 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
00478 : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
00479 thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
00480 _("Cancel"))
00481 {
00482 this->mwindow = mwindow;
00483 this->thread = thread;
00484 }
00485 int PreferencesCancel::keypress_event()
00486 {
00487 if(get_keypress() == ESC)
00488 {
00489 thread->window->set_done(1);
00490 return 1;
00491 }
00492 return 0;
00493 }
00494
00495 int PreferencesCancel::handle_event()
00496 {
00497 thread->window->set_done(1);
00498 return 1;
00499 }
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
00511 : BC_PopupTextBox(thread->window,
00512 &thread->window->categories,
00513 thread->category_to_text(thread->current_dialog),
00514 x,
00515 y,
00516 200,
00517 150)
00518 {
00519 this->mwindow = mwindow;
00520 this->thread = thread;
00521 }
00522
00523 PreferencesCategory::~PreferencesCategory()
00524 {
00525 }
00526
00527 int PreferencesCategory::handle_event()
00528 {
00529 thread->window->set_current_dialog(thread->text_to_category(get_text()));
00530 return 1;
00531 }