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