4 * Copyright (C) 2008 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 "condition.h"
25 #include "edlsession.h"
27 #include "localsession.h"
28 #include "mainsession.h"
31 #include "mwindowgui.h"
35 #include "plugindialog.h"
36 #include "pluginserver.h"
40 #include "transition.h"
43 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
46 this->mwindow = mwindow;
50 PluginDialogThread::~PluginDialogThread()
55 void PluginDialogThread::start_window(Track *track,
61 if(!BC_DialogThread::is_running())
63 // At this point, the caller should hold the main window mutex.
64 // mwindow->gui->lock_window("PluginDialogThread::start_window");
66 this->data_type = data_type;
67 this->plugin = plugin;
68 this->is_mainmenu = is_mainmenu;
69 single_standalone = mwindow->edl->session->single_standalone;
73 plugin->calculate_title(plugin_title, 0);
74 this->shared_location = plugin->shared_location;
75 this->plugin_type = plugin->plugin_type;
79 this->plugin_title[0] = 0;
80 this->shared_location.plugin = -1;
81 this->shared_location.module = -1;
82 this->plugin_type = PLUGIN_NONE;
85 strcpy(this->window_title, title);
86 mwindow->gui->unlock_window();
88 BC_DialogThread::start();
89 mwindow->gui->lock_window("PluginDialogThread::start_window");
93 BC_Window* PluginDialogThread::new_gui()
95 mwindow->gui->lock_window("PluginDialogThread::new_gui");
96 int x = mwindow->gui->get_abs_cursor_x(0) -
97 mwindow->session->plugindialog_w / 2;
98 int y = mwindow->gui->get_abs_cursor_y(0) -
99 mwindow->session->plugindialog_h / 2;
101 PluginDialog *window = new PluginDialog(mwindow,
106 window->create_objects();
107 mwindow->gui->unlock_window();
111 void PluginDialogThread::handle_done_event(int result)
113 PluginDialog *window = (PluginDialog*)BC_DialogThread::get_gui();
114 if(window->selected_available >= 0)
116 window->attach_new(window->selected_available);
119 if(window->selected_shared >= 0)
121 window->attach_shared(window->selected_shared);
124 if(window->selected_modules >= 0)
126 window->attach_module(window->selected_modules);
129 mwindow->edl->session->single_standalone = single_standalone;
132 void PluginDialogThread::handle_close_event(int result)
138 mwindow->gui->lock_window("PluginDialogThread::run 3");
141 mwindow->undo->update_undo_before();
144 mwindow->insert_effect(plugin_title,
154 if(mwindow->edl->tracks->plugin_exists(plugin))
156 plugin->change_plugin(plugin_title,
163 if(mwindow->edl->tracks->track_exists(track))
165 mwindow->insert_effect(plugin_title,
176 mwindow->save_backup();
177 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
178 mwindow->restart_brender();
179 mwindow->update_plugin_states();
180 mwindow->sync_parameters(CHANGE_EDL);
181 mwindow->gui->update(1,
189 mwindow->gui->unlock_window();
203 PluginDialog::PluginDialog(MWindow *mwindow,
204 PluginDialogThread *thread,
205 const char *window_title,
208 : BC_Window(window_title,
211 mwindow->session->plugindialog_w,
212 mwindow->session->plugindialog_h,
219 this->mwindow = mwindow;
220 this->thread = thread;
221 single_standalone = 0;
224 PluginDialog::~PluginDialog()
226 lock_window("PluginDialog::~PluginDialog");
227 standalone_data.remove_all_objects();
229 shared_data.remove_all_objects();
231 module_data.remove_all_objects();
233 plugin_locations.remove_all_objects();
235 module_locations.remove_all_objects();
237 delete standalone_list;
243 void PluginDialog::create_objects()
245 // int use_default = 1;
246 char string[BCTEXTLEN];
247 mwindow->theme->get_plugindialog_sizes();
249 lock_window("PluginDialog::create_objects");
252 strcpy(string, thread->plugin->title);
258 sprintf(string, _("None"));
266 // GET A LIST OF ALL THE PLUGINS AVAILABLE
267 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
268 thread->data_type == TRACK_VIDEO,
271 mwindow->edl->get_shared_plugins(thread->track,
275 mwindow->edl->get_shared_tracks(thread->track,
280 // Construct listbox items
281 for(int i = 0; i < plugin_locations.total; i++)
283 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
284 char *track_title = track->title;
285 int number = plugin_locations.values[i]->plugin;
286 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->get_selectionstart(1),
291 char *plugin_title = plugin->title;
292 char string[BCTEXTLEN];
294 snprintf(string, sizeof(string), "%s: %s", track_title, _(plugin_title));
295 shared_data.append(new BC_ListBoxItem(string));
297 for(int i = 0; i < module_locations.total; i++)
299 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
300 module_data.append(new BC_ListBoxItem(track->title));
308 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
309 mwindow->theme->plugindialog_new_y - 20,
311 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
312 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
313 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
314 int dy = search_text->get_h() + 10;
318 add_subwindow(standalone_list = new PluginDialogNew(this,
319 &standalone_data, x1, y1, w1, h1));
321 // if(thread->plugin)
322 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
324 // mwindow->theme->plugindialog_newattach_x,
325 // mwindow->theme->plugindialog_newattach_y));
327 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
329 // mwindow->theme->plugindialog_newattach_x,
330 // mwindow->theme->plugindialog_newattach_y));
339 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
340 mwindow->theme->plugindialog_shared_y - 20,
341 _("Shared effects:")));
342 add_subwindow(shared_list = new PluginDialogShared(this,
344 mwindow->theme->plugindialog_shared_x,
345 mwindow->theme->plugindialog_shared_y,
346 mwindow->theme->plugindialog_shared_w,
347 mwindow->theme->plugindialog_shared_h));
348 // if(thread->plugin)
349 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
351 // mwindow->theme->plugindialog_sharedattach_x,
352 // mwindow->theme->plugindialog_sharedattach_y));
354 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
356 // mwindow->theme->plugindialog_sharedattach_x,
357 // mwindow->theme->plugindialog_sharedattach_y));
367 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
368 mwindow->theme->plugindialog_module_y - 20,
369 _("Shared tracks:")));
370 add_subwindow(module_list = new PluginDialogModules(this,
372 mwindow->theme->plugindialog_module_x,
373 mwindow->theme->plugindialog_module_y,
374 mwindow->theme->plugindialog_module_w,
375 mwindow->theme->plugindialog_module_h));
376 // if(thread->plugin)
377 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
379 // mwindow->theme->plugindialog_moduleattach_x,
380 // mwindow->theme->plugindialog_moduleattach_y));
382 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
384 // mwindow->theme->plugindialog_moduleattach_x,
385 // mwindow->theme->plugindialog_moduleattach_y));
389 // Add option for the menu invocation
390 // add_subwindow(file_title = new BC_Title(
391 // mwindow->theme->menueffect_file_x,
392 // mwindow->theme->menueffect_file_y,
393 // _("One standalone effect is attached to the first track.\n"
394 // "Shared effects are attached to the remaining tracks.")));
396 if(thread->is_mainmenu)
397 add_subwindow(single_standalone = new PluginDialogSingle(this,
398 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
399 mwindow->theme->plugindialog_new_y +
400 mwindow->theme->plugindialog_new_h +
401 get_text_height(MEDIUMFONT)));
405 add_subwindow(new BC_OKButton(this));
406 add_subwindow(new BC_CancelButton(this));
408 selected_available = -1;
409 selected_shared = -1;
410 selected_modules = -1;
417 int PluginDialog::resize_event(int w, int h)
419 mwindow->session->plugindialog_w = w;
420 mwindow->session->plugindialog_h = h;
421 mwindow->theme->get_plugindialog_sizes();
424 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
425 mwindow->theme->plugindialog_new_y - 20);
426 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
427 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
428 search_text->reposition_window(x1, y1, w1);
429 int dy = search_text->get_h() + 10;
431 standalone_list->reposition_window(x1, y1, w1, h1);
433 // if(standalone_attach)
434 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
435 // mwindow->theme->plugindialog_newattach_y);
437 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
438 // mwindow->theme->plugindialog_newattach_y);
440 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
441 mwindow->theme->plugindialog_shared_y - 20);
442 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
443 mwindow->theme->plugindialog_shared_y,
444 mwindow->theme->plugindialog_shared_w,
445 mwindow->theme->plugindialog_shared_h);
447 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
448 // mwindow->theme->plugindialog_sharedattach_y);
450 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
451 // mwindow->theme->plugindialog_sharedattach_y);
457 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
458 mwindow->theme->plugindialog_module_y - 20);
459 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
460 mwindow->theme->plugindialog_module_y,
461 mwindow->theme->plugindialog_module_w,
462 mwindow->theme->plugindialog_module_h);
464 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
465 // mwindow->theme->plugindialog_moduleattach_y);
467 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
468 // mwindow->theme->plugindialog_moduleattach_y);
471 if(single_standalone)
472 single_standalone->reposition_window(mwindow->theme->plugindialog_new_x,
473 mwindow->theme->plugindialog_new_y +
474 mwindow->theme->plugindialog_new_h +
475 get_text_height(MEDIUMFONT));
481 int PluginDialog::attach_new(int number)
483 if(number >= 0 && number < plugindb.size())
485 strcpy(thread->plugin_title, plugindb.values[number]->title);
486 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
491 int PluginDialog::attach_shared(int number)
493 if(number >= 0 && number < plugin_locations.size())
495 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
496 thread->shared_location = *(plugin_locations.values[number]); // copy location
501 int PluginDialog::attach_module(int number)
503 if(number >= 0 && number < module_locations.size())
505 // title->update(module_data.values[number]->get_text());
506 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
507 thread->shared_location = *(module_locations.values[number]); // copy location
512 void PluginDialog::save_settings()
523 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
524 // : BC_TextBox(x, y, 200, 1, text)
526 // this->dialog = dialog;
528 // PluginDialogTextBox::~PluginDialogTextBox()
530 // int PluginDialogTextBox::handle_event()
533 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
534 // : BC_GenericButton(x, y, _("Detach"))
536 // this->dialog = dialog;
538 // PluginDialogDetach::~PluginDialogDetach()
540 // int PluginDialogDetach::handle_event()
542 // // dialog->title->update(_("None"));
543 // dialog->thread->plugin_type = 0; // type is none
544 // dialog->thread->plugin_title[0] = 0;
561 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
562 ArrayList<BC_ListBoxItem*> *standalone_data,
563 int x, int y, int w, int h)
564 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
566 this->dialog = dialog;
569 PluginDialogNew::~PluginDialogNew() { }
570 int PluginDialogNew::handle_event()
572 // dialog->attach_new(get_selection_number(0, 0));
578 int PluginDialogNew::selection_changed()
580 int no = get_selection_number(0, 0);
581 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
582 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
583 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
584 dialog->shared_list->draw_items(1);
585 dialog->selected_shared = -1;
586 dialog->module_list->set_all_selected(&dialog->module_data, 0);
587 dialog->module_list->draw_items(1);
588 dialog->selected_modules = -1;
592 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
593 // : BC_GenericButton(x, y, _("Attach"))
595 // this->dialog = dialog;
597 // PluginDialogAttachNew::~PluginDialogAttachNew()
600 // int PluginDialogAttachNew::handle_event()
602 // dialog->attach_new(dialog->selected_available);
607 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
608 // : BC_GenericButton(x, y, _("Change"))
610 // this->dialog = dialog;
612 // PluginDialogChangeNew::~PluginDialogChangeNew()
615 // int PluginDialogChangeNew::handle_event()
617 // dialog->attach_new(dialog->selected_available);
631 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
632 ArrayList<BC_ListBoxItem*> *shared_data,
644 this->dialog = dialog;
646 PluginDialogShared::~PluginDialogShared() { }
647 int PluginDialogShared::handle_event()
649 // dialog->attach_shared(get_selection_number(0, 0));
654 int PluginDialogShared::selection_changed()
656 dialog->selected_shared = get_selection_number(0, 0);
659 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
660 dialog->standalone_list->draw_items(1);
661 dialog->module_list->set_all_selected(&dialog->module_data, 0);
662 dialog->module_list->draw_items(1);
663 dialog->selected_available = -1;
664 dialog->selected_modules = -1;
668 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
669 // PluginDialog *dialog,
672 // : BC_GenericButton(x, y, _("Attach"))
674 // this->dialog = dialog;
676 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
677 // int PluginDialogAttachShared::handle_event()
679 // dialog->attach_shared(dialog->selected_shared);
684 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
685 // PluginDialog *dialog,
688 // : BC_GenericButton(x, y, _("Change"))
690 // this->dialog = dialog;
692 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
693 // int PluginDialogChangeShared::handle_event()
695 // dialog->attach_shared(dialog->selected_shared);
712 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
713 ArrayList<BC_ListBoxItem*> *module_data,
725 this->dialog = dialog;
727 PluginDialogModules::~PluginDialogModules() { }
728 int PluginDialogModules::handle_event()
730 // dialog->attach_module(get_selection_number(0, 0));
736 int PluginDialogModules::selection_changed()
738 dialog->selected_modules = get_selection_number(0, 0);
741 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
742 dialog->standalone_list->draw_items(1);
743 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
744 dialog->shared_list->draw_items(1);
745 dialog->selected_available = -1;
746 dialog->selected_shared = -1;
750 void PluginDialog::load_plugin_list(int redraw)
752 standalone_data.remove_all_objects();
753 const char *text = search_text->get_text();
755 for( int i=0; i<plugindb.total; ++i ) {
756 const char *title = plugindb.values[i]->title;
757 if( text && text[0] && !bstrcasestr(title, text) ) continue;
758 standalone_data.append(new PluginDialogListItem(title, i));
762 standalone_list->draw_items(1);
765 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
766 : BC_TextBox(x, y, w, 1, "")
768 this->dialog = dialog;
771 int PluginDialogSearchText::handle_event()
773 dialog->load_plugin_list(1);
777 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
780 dialog->thread->single_standalone,
781 _("Attach single standlone and share others"))
783 this->dialog = dialog;
786 int PluginDialogSingle::handle_event()
788 dialog->thread->single_standalone = get_value();
793 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
794 // PluginDialog *dialog,
797 // : BC_GenericButton(x, y, _("Attach"))
799 // this->dialog = dialog;
801 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
802 // int PluginDialogAttachModule::handle_event()
804 // dialog->attach_module(dialog->selected_modules);
809 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
810 // PluginDialog *dialog,
813 // : BC_GenericButton(x, y, _("Change"))
815 // this->dialog = dialog;
817 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
818 // int PluginDialogChangeModule::handle_event()
820 // dialog->attach_module(dialog->selected_modules);