00001 #include "condition.h"
00002 #include "edl.h"
00003 #include "language.h"
00004 #include "localsession.h"
00005 #include "mainsession.h"
00006 #include "mainundo.h"
00007 #include "mwindow.h"
00008 #include "mwindowgui.h"
00009 #include "module.h"
00010 #include "mutex.h"
00011 #include "plugin.h"
00012 #include "plugindialog.h"
00013 #include "pluginserver.h"
00014 #include "theme.h"
00015 #include "track.h"
00016 #include "tracks.h"
00017 #include "transition.h"
00018
00019
00020 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
00021 : Thread()
00022 {
00023 this->mwindow = mwindow;
00024 window = 0;
00025 plugin = 0;
00026 Thread::set_synchronous(0);
00027 window_lock = new Mutex("PluginDialogThread::window_lock");
00028 completion = new Condition(1, "PluginDialogThread::completion");
00029 }
00030
00031 PluginDialogThread::~PluginDialogThread()
00032 {
00033 if(window)
00034 {
00035 window->set_done(1);
00036 completion->lock("PluginDialogThread::~PluginDialogThread");
00037 completion->unlock();
00038 }
00039 delete window_lock;
00040 delete completion;
00041 }
00042
00043 void PluginDialogThread::start_window(Track *track,
00044 Plugin *plugin,
00045 char *title)
00046 {
00047 if(Thread::running())
00048 {
00049 window_lock->lock("PluginDialogThread::start_window");
00050 if(window)
00051 {
00052 window->lock_window("PluginDialogThread::start_window");
00053 window->raise_window();
00054 window->flush();
00055 window->unlock_window();
00056 }
00057 window_lock->unlock();
00058 }
00059 else
00060 {
00061 this->track = track;
00062 this->data_type = track->data_type;
00063 this->plugin = plugin;
00064
00065 if(plugin)
00066 {
00067 plugin->calculate_title(plugin_title, 0);
00068 this->shared_location = plugin->shared_location;
00069 this->plugin_type = plugin->plugin_type;
00070 }
00071 else
00072 {
00073 this->plugin_title[0] = 0;
00074 this->shared_location.plugin = -1;
00075 this->shared_location.module = -1;
00076 this->plugin_type = PLUGIN_NONE;
00077 }
00078
00079 strcpy(this->window_title, title);
00080 completion->lock("PluginDialogThread::start_window");
00081 Thread::start();
00082 }
00083 }
00084
00085
00086 int PluginDialogThread::set_dialog(Transition *transition, char *title)
00087 {
00088 return 0;
00089 }
00090
00091 void PluginDialogThread::run()
00092 {
00093 int result = 0;
00094
00095 int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->session->plugindialog_w / 2;
00096 int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->session->plugindialog_h / 2;
00097
00098 window_lock->lock("PluginDialogThread::run 1");
00099 window = new PluginDialog(mwindow, this, window_title, x, y);
00100 window->create_objects();
00101 window_lock->unlock();
00102
00103 result = window->run_window();
00104
00105
00106 window_lock->lock("PluginDialogThread::run 2");
00107 delete window;
00108 window = 0;
00109 window_lock->unlock();
00110
00111 completion->unlock();
00112
00113
00114 if(!result)
00115 {
00116 if(plugin_type)
00117 {
00118 mwindow->gui->lock_window("PluginDialogThread::run 3");
00119
00120
00121 if(plugin)
00122 {
00123 plugin->change_plugin(plugin_title,
00124 &shared_location,
00125 plugin_type);
00126 }
00127 else
00128 {
00129 mwindow->insert_effect(plugin_title,
00130 &shared_location,
00131 track,
00132 0,
00133 0,
00134 0,
00135 plugin_type);
00136 }
00137
00138
00139 mwindow->save_backup();
00140 mwindow->undo->update_undo(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
00141 mwindow->restart_brender();
00142 mwindow->update_plugin_states();
00143 mwindow->sync_parameters(CHANGE_EDL);
00144 mwindow->gui->update(1,
00145 1,
00146 0,
00147 0,
00148 1,
00149 0,
00150 0);
00151
00152 mwindow->gui->unlock_window();
00153 }
00154 }
00155 plugin = 0;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 PluginDialog::PluginDialog(MWindow *mwindow,
00167 PluginDialogThread *thread,
00168 char *window_title,
00169 int x,
00170 int y)
00171 : BC_Window(window_title,
00172 x,
00173 y,
00174 mwindow->session->plugindialog_w,
00175 mwindow->session->plugindialog_h,
00176 510,
00177 415,
00178 1,
00179 0,
00180 1)
00181 {
00182 this->mwindow = mwindow;
00183 this->thread = thread;
00184 standalone_attach = 0;
00185 shared_attach = 0;
00186 module_attach = 0;
00187 standalone_change = 0;
00188 shared_change = 0;
00189 module_change = 0;
00190 inoutthru = 0;
00191 }
00192
00193 PluginDialog::~PluginDialog()
00194 {
00195 int i;
00196 standalone_data.remove_all_objects();
00197
00198 shared_data.remove_all_objects();
00199
00200 module_data.remove_all_objects();
00201
00202 plugin_locations.remove_all_objects();
00203
00204 module_locations.remove_all_objects();
00205
00206
00207
00208 delete standalone_list;
00209 delete shared_list;
00210 delete module_list;
00211 if(standalone_attach) delete standalone_attach;
00212 if(shared_attach) delete shared_attach;
00213 if(module_attach) delete module_attach;
00214 if(standalone_change) delete standalone_change;
00215 if(shared_change) delete shared_change;
00216 if(module_change) delete module_change;
00217
00218
00219 }
00220
00221 int PluginDialog::create_objects()
00222 {
00223 int use_default = 1;
00224 char string[BCTEXTLEN];
00225 int module_number;
00226 mwindow->theme->get_plugindialog_sizes();
00227
00228 if(thread->plugin)
00229 {
00230 strcpy(string, thread->plugin->title);
00231 use_default = 1;
00232 }
00233 else
00234 {
00235
00236 sprintf(string, _("None"));
00237 }
00238
00239
00240
00241
00242
00243
00244
00245 mwindow->create_plugindb(thread->data_type == TRACK_AUDIO,
00246 thread->data_type == TRACK_VIDEO,
00247 1,
00248 0,
00249 0,
00250 plugindb);
00251
00252 mwindow->edl->get_shared_plugins(thread->track,
00253 &plugin_locations);
00254
00255 mwindow->edl->get_shared_tracks(thread->track,
00256 &module_locations);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 for(int i = 0; i < plugindb.total; i++)
00267 standalone_data.append(new BC_ListBoxItem(_(plugindb.values[i]->title)));
00268 for(int i = 0; i < plugin_locations.total; i++)
00269 {
00270 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
00271 char *track_title = track->title;
00272 int number = plugin_locations.values[i]->plugin;
00273 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->get_selectionstart(1),
00274 number,
00275 PLAY_FORWARD,
00276 1,
00277 0);
00278 char *plugin_title = plugin->title;
00279 char string[BCTEXTLEN];
00280
00281 sprintf(string, "%s: %s", track_title, _(plugin_title));
00282 shared_data.append(new BC_ListBoxItem(string));
00283 }
00284 for(int i = 0; i < module_locations.total; i++)
00285 {
00286 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
00287 module_data.append(new BC_ListBoxItem(track->title));
00288 }
00289
00290
00291
00292
00293
00294
00295 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
00296 mwindow->theme->plugindialog_new_y - 20,
00297 _("Plugins:")));
00298 add_subwindow(standalone_list = new PluginDialogNew(this,
00299 &standalone_data,
00300 mwindow->theme->plugindialog_new_x,
00301 mwindow->theme->plugindialog_new_y,
00302 mwindow->theme->plugindialog_new_w,
00303 mwindow->theme->plugindialog_new_h));
00304
00305 if(thread->plugin)
00306 add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
00307 this,
00308 mwindow->theme->plugindialog_newattach_x,
00309 mwindow->theme->plugindialog_newattach_y));
00310 else
00311 add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
00312 this,
00313 mwindow->theme->plugindialog_newattach_x,
00314 mwindow->theme->plugindialog_newattach_y));
00315
00316
00317
00318
00319
00320
00321
00322
00323 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
00324 mwindow->theme->plugindialog_shared_y - 20,
00325 _("Shared effects:")));
00326 add_subwindow(shared_list = new PluginDialogShared(this,
00327 &shared_data,
00328 mwindow->theme->plugindialog_shared_x,
00329 mwindow->theme->plugindialog_shared_y,
00330 mwindow->theme->plugindialog_shared_w,
00331 mwindow->theme->plugindialog_shared_h));
00332 if(thread->plugin)
00333 add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
00334 this,
00335 mwindow->theme->plugindialog_sharedattach_x,
00336 mwindow->theme->plugindialog_sharedattach_y));
00337 else
00338 add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
00339 this,
00340 mwindow->theme->plugindialog_sharedattach_x,
00341 mwindow->theme->plugindialog_sharedattach_y));
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
00352 mwindow->theme->plugindialog_module_y - 20,
00353 _("Shared tracks:")));
00354 add_subwindow(module_list = new PluginDialogModules(this,
00355 &module_data,
00356 mwindow->theme->plugindialog_module_x,
00357 mwindow->theme->plugindialog_module_y,
00358 mwindow->theme->plugindialog_module_w,
00359 mwindow->theme->plugindialog_module_h));
00360 if(thread->plugin)
00361 add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
00362 this,
00363 mwindow->theme->plugindialog_moduleattach_x,
00364 mwindow->theme->plugindialog_moduleattach_y));
00365 else
00366 add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
00367 this,
00368 mwindow->theme->plugindialog_moduleattach_x,
00369 mwindow->theme->plugindialog_moduleattach_y));
00370
00371
00372
00373
00374
00375
00376
00377 add_subwindow(new BC_CancelButton(this));
00378
00379 selected_available = -1;
00380 selected_shared = -1;
00381 selected_modules = -1;
00382
00383 show_window();
00384 flush();
00385 return 0;
00386 }
00387
00388 int PluginDialog::resize_event(int w, int h)
00389 {
00390 mwindow->session->plugindialog_w = w;
00391 mwindow->session->plugindialog_h = h;
00392 mwindow->theme->get_plugindialog_sizes();
00393
00394
00395 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
00396 mwindow->theme->plugindialog_new_y - 20);
00397 standalone_list->reposition_window(mwindow->theme->plugindialog_new_x,
00398 mwindow->theme->plugindialog_new_y,
00399 mwindow->theme->plugindialog_new_w,
00400 mwindow->theme->plugindialog_new_h);
00401 if(standalone_attach)
00402 standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
00403 mwindow->theme->plugindialog_newattach_y);
00404 else
00405 standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
00406 mwindow->theme->plugindialog_newattach_y);
00407
00408
00409
00410
00411
00412 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
00413 mwindow->theme->plugindialog_shared_y - 20);
00414 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
00415 mwindow->theme->plugindialog_shared_y,
00416 mwindow->theme->plugindialog_shared_w,
00417 mwindow->theme->plugindialog_shared_h);
00418 if(shared_attach)
00419 shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
00420 mwindow->theme->plugindialog_sharedattach_y);
00421 else
00422 shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
00423 mwindow->theme->plugindialog_sharedattach_y);
00424
00425
00426
00427
00428
00429 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
00430 mwindow->theme->plugindialog_module_y - 20);
00431 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
00432 mwindow->theme->plugindialog_module_y,
00433 mwindow->theme->plugindialog_module_w,
00434 mwindow->theme->plugindialog_module_h);
00435 if(module_attach)
00436 module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
00437 mwindow->theme->plugindialog_moduleattach_y);
00438 else
00439 module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
00440 mwindow->theme->plugindialog_moduleattach_y);
00441 flush();
00442 }
00443
00444 int PluginDialog::attach_new(int number)
00445 {
00446 if(number > -1 && number < standalone_data.total)
00447 {
00448 strcpy(thread->plugin_title, plugindb.values[number]->title);
00449 thread->plugin_type = PLUGIN_STANDALONE;
00450 }
00451 return 0;
00452 }
00453
00454 int PluginDialog::attach_shared(int number)
00455 {
00456 if(number > -1 && number < shared_data.total)
00457 {
00458 thread->plugin_type = PLUGIN_SHAREDPLUGIN;
00459 thread->shared_location = *(plugin_locations.values[number]);
00460 }
00461 return 0;
00462 }
00463
00464 int PluginDialog::attach_module(int number)
00465 {
00466 if(number > -1 && number < module_data.total)
00467 {
00468
00469 thread->plugin_type = PLUGIN_SHAREDMODULE;
00470 thread->shared_location = *(module_locations.values[number]);
00471 }
00472 return 0;
00473 }
00474
00475 int PluginDialog::save_settings()
00476 {
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486 PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
00487 : BC_TextBox(x, y, 200, 1, text)
00488 {
00489 this->dialog = dialog;
00490 }
00491 PluginDialogTextBox::~PluginDialogTextBox()
00492 { }
00493 int PluginDialogTextBox::handle_event()
00494 { }
00495
00496 PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
00497 : BC_GenericButton(x, y, _("Detach"))
00498 {
00499 this->dialog = dialog;
00500 }
00501 PluginDialogDetach::~PluginDialogDetach()
00502 { }
00503 int PluginDialogDetach::handle_event()
00504 {
00505
00506 dialog->thread->plugin_type = 0;
00507 dialog->thread->plugin_title[0] = 0;
00508 return 1;
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
00525 ArrayList<BC_ListBoxItem*> *standalone_data,
00526 int x,
00527 int y,
00528 int w,
00529 int h)
00530 : BC_ListBox(x,
00531 y,
00532 w,
00533 h,
00534 LISTBOX_TEXT,
00535 standalone_data)
00536 {
00537 this->dialog = dialog;
00538 }
00539 PluginDialogNew::~PluginDialogNew() { }
00540 int PluginDialogNew::handle_event()
00541 {
00542 dialog->attach_new(get_selection_number(0, 0));
00543 deactivate();
00544
00545 set_done(0);
00546 return 1;
00547 }
00548 int PluginDialogNew::selection_changed()
00549 {
00550 dialog->selected_available = get_selection_number(0, 0);
00551 return 1;
00552 }
00553
00554 PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
00555 : BC_GenericButton(x, y, _("Attach"))
00556 {
00557 this->dialog = dialog;
00558 }
00559 PluginDialogAttachNew::~PluginDialogAttachNew()
00560 {
00561 }
00562 int PluginDialogAttachNew::handle_event()
00563 {
00564 dialog->attach_new(dialog->selected_available);
00565 set_done(0);
00566 return 1;
00567 }
00568
00569 PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
00570 : BC_GenericButton(x, y, _("Change"))
00571 {
00572 this->dialog = dialog;
00573 }
00574 PluginDialogChangeNew::~PluginDialogChangeNew()
00575 {
00576 }
00577 int PluginDialogChangeNew::handle_event()
00578 {
00579 dialog->attach_new(dialog->selected_available);
00580 set_done(0);
00581 return 1;
00582 }
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
00594 ArrayList<BC_ListBoxItem*> *shared_data,
00595 int x,
00596 int y,
00597 int w,
00598 int h)
00599 : BC_ListBox(x,
00600 y,
00601 w,
00602 h,
00603 LISTBOX_TEXT,
00604 shared_data)
00605 {
00606 this->dialog = dialog;
00607 }
00608 PluginDialogShared::~PluginDialogShared() { }
00609 int PluginDialogShared::handle_event()
00610 {
00611 dialog->attach_shared(get_selection_number(0, 0));
00612 deactivate();
00613 set_done(0);
00614 return 1;
00615 }
00616 int PluginDialogShared::selection_changed()
00617 {
00618 dialog->selected_shared = get_selection_number(0, 0);
00619 return 1;
00620 }
00621
00622 PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
00623 PluginDialog *dialog,
00624 int x,
00625 int y)
00626 : BC_GenericButton(x, y, _("Attach"))
00627 {
00628 this->dialog = dialog;
00629 }
00630 PluginDialogAttachShared::~PluginDialogAttachShared() { }
00631 int PluginDialogAttachShared::handle_event()
00632 {
00633 dialog->attach_shared(dialog->selected_shared);
00634 set_done(0);
00635 return 1;
00636 }
00637
00638 PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
00639 PluginDialog *dialog,
00640 int x,
00641 int y)
00642 : BC_GenericButton(x, y, _("Change"))
00643 {
00644 this->dialog = dialog;
00645 }
00646 PluginDialogChangeShared::~PluginDialogChangeShared() { }
00647 int PluginDialogChangeShared::handle_event()
00648 {
00649 dialog->attach_shared(dialog->selected_shared);
00650 set_done(0);
00651 return 1;
00652 }
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
00667 ArrayList<BC_ListBoxItem*> *module_data,
00668 int x,
00669 int y,
00670 int w,
00671 int h)
00672 : BC_ListBox(x,
00673 y,
00674 w,
00675 h,
00676 LISTBOX_TEXT,
00677 module_data)
00678 {
00679 this->dialog = dialog;
00680 }
00681 PluginDialogModules::~PluginDialogModules() { }
00682 int PluginDialogModules::handle_event()
00683 {
00684 dialog->attach_module(get_selection_number(0, 0));
00685 deactivate();
00686
00687 set_done(0);
00688 return 1;
00689 }
00690 int PluginDialogModules::selection_changed()
00691 {
00692 dialog->selected_modules = get_selection_number(0, 0);
00693 return 1;
00694 }
00695
00696
00697 PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
00698 PluginDialog *dialog,
00699 int x,
00700 int y)
00701 : BC_GenericButton(x, y, _("Attach"))
00702 {
00703 this->dialog = dialog;
00704 }
00705 PluginDialogAttachModule::~PluginDialogAttachModule() { }
00706 int PluginDialogAttachModule::handle_event()
00707 {
00708 dialog->attach_module(dialog->selected_modules);
00709 set_done(0);
00710 return 1;
00711 }
00712
00713 PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
00714 PluginDialog *dialog,
00715 int x,
00716 int y)
00717 : BC_GenericButton(x, y, _("Change"))
00718 {
00719 this->dialog = dialog;
00720 }
00721 PluginDialogChangeModule::~PluginDialogChangeModule() { }
00722 int PluginDialogChangeModule::handle_event()
00723 {
00724 dialog->attach_module(dialog->selected_modules);
00725 set_done(0);
00726 return 1;
00727 }
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 PluginDialogIn::PluginDialogIn(PluginDialog *dialog, int setting, int x, int y)
00744 : BC_CheckBox(x, y, setting, _("Send"))
00745 {
00746 this->dialog = dialog;
00747 }
00748 PluginDialogIn::~PluginDialogIn() { }
00749 int PluginDialogIn::handle_event()
00750 {
00751
00752 return 1;
00753 }
00754 int PluginDialogIn::button_press()
00755 {
00756 dialog->inoutthru = 1;
00757 dialog->new_value = get_value();
00758 return 1;
00759 }
00760 int PluginDialogIn::button_release()
00761 {
00762 if(dialog->inoutthru) dialog->inoutthru = 0;
00763 }
00764 int PluginDialogIn::cursor_moved_over()
00765 {
00766 if(dialog->inoutthru && get_value() != dialog->new_value)
00767 {
00768 update(dialog->new_value);
00769 }
00770 }
00771
00772 PluginDialogOut::PluginDialogOut(PluginDialog *dialog, int setting, int x, int y)
00773 : BC_CheckBox(x, y, setting, _("Receive"))
00774 {
00775 this->dialog = dialog;
00776 }
00777 PluginDialogOut::~PluginDialogOut() { }
00778 int PluginDialogOut::handle_event()
00779 {
00780
00781 return 1;
00782 }
00783 int PluginDialogOut::button_press()
00784 {
00785 dialog->inoutthru = 1;
00786 dialog->new_value = get_value();
00787 return 1;
00788 }
00789 int PluginDialogOut::button_release()
00790 {
00791 if(dialog->inoutthru) dialog->inoutthru = 0;
00792 }
00793 int PluginDialogOut::cursor_moved_over()
00794 {
00795 if(dialog->inoutthru && get_value() != dialog->new_value)
00796 {
00797 update(dialog->new_value);
00798 }
00799 }
00800
00801 PluginDialogThru::PluginDialogThru(PluginDialog *dialog, int setting)
00802 : BC_CheckBox(300, 350, setting, _("Thru"))
00803 {
00804 this->dialog = dialog;
00805 }
00806 PluginDialogThru::~PluginDialogThru() { }
00807 int PluginDialogThru::handle_event() { }
00808 int PluginDialogThru::button_press()
00809 {
00810 dialog->inoutthru = 1;
00811 dialog->new_value = get_value();
00812 return 1;
00813 }
00814 int PluginDialogThru::button_release()
00815 {
00816 if(dialog->inoutthru) dialog->inoutthru = 0;
00817 }
00818 int PluginDialogThru::cursor_moved_over()
00819 {
00820 if(dialog->inoutthru && get_value() != dialog->new_value)
00821 {
00822 update(dialog->new_value);
00823 }
00824 }