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 mwindow->theme->get_plugindialog_sizes();
247 lock_window("PluginDialog::create_objects");
249 // GET A LIST OF ALL THE PLUGINS AVAILABLE
250 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
251 thread->data_type == TRACK_VIDEO,
254 mwindow->edl->get_shared_plugins(thread->track,
258 mwindow->edl->get_shared_tracks(thread->track,
263 // Construct listbox items
264 for(int i = 0; i < plugin_locations.total; i++)
266 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
267 char *track_title = track->title;
268 int number = plugin_locations.values[i]->plugin;
269 double start = mwindow->edl->local_session->get_selectionstart(1);
270 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
271 if( !plugin ) continue;
272 char string[BCTEXTLEN];
273 const char *plugin_title = _(plugin->title);
274 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
275 shared_data.append(new BC_ListBoxItem(string));
277 for(int i = 0; i < module_locations.total; i++)
279 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
280 module_data.append(new BC_ListBoxItem(track->title));
288 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
289 mwindow->theme->plugindialog_new_y - 20,
291 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
292 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
293 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
294 int dy = search_text->get_h() + 10;
298 add_subwindow(standalone_list = new PluginDialogNew(this,
299 &standalone_data, x1, y1, w1, h1));
301 // if(thread->plugin)
302 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
304 // mwindow->theme->plugindialog_newattach_x,
305 // mwindow->theme->plugindialog_newattach_y));
307 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
309 // mwindow->theme->plugindialog_newattach_x,
310 // mwindow->theme->plugindialog_newattach_y));
313 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
314 mwindow->theme->plugindialog_shared_y - 20,
315 _("Shared effects:")));
316 add_subwindow(shared_list = new PluginDialogShared(this,
318 mwindow->theme->plugindialog_shared_x,
319 mwindow->theme->plugindialog_shared_y,
320 mwindow->theme->plugindialog_shared_w,
321 mwindow->theme->plugindialog_shared_h));
322 // if(thread->plugin)
323 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
325 // mwindow->theme->plugindialog_sharedattach_x,
326 // mwindow->theme->plugindialog_sharedattach_y));
328 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
330 // mwindow->theme->plugindialog_sharedattach_x,
331 // mwindow->theme->plugindialog_sharedattach_y));
334 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
335 mwindow->theme->plugindialog_module_y - 20,
336 _("Shared tracks:")));
337 add_subwindow(module_list = new PluginDialogModules(this,
339 mwindow->theme->plugindialog_module_x,
340 mwindow->theme->plugindialog_module_y,
341 mwindow->theme->plugindialog_module_w,
342 mwindow->theme->plugindialog_module_h));
343 // if(thread->plugin)
344 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
346 // mwindow->theme->plugindialog_moduleattach_x,
347 // mwindow->theme->plugindialog_moduleattach_y));
349 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
351 // mwindow->theme->plugindialog_moduleattach_x,
352 // mwindow->theme->plugindialog_moduleattach_y));
356 // Add option for the menu invocation
357 // add_subwindow(file_title = new BC_Title(
358 // mwindow->theme->menueffect_file_x,
359 // mwindow->theme->menueffect_file_y,
360 // _("One standalone effect is attached to the first track.\n"
361 // "Shared effects are attached to the remaining tracks.")));
363 if(thread->is_mainmenu)
364 add_subwindow(single_standalone = new PluginDialogSingle(this,
365 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
366 mwindow->theme->plugindialog_new_y +
367 mwindow->theme->plugindialog_new_h +
368 get_text_height(MEDIUMFONT)));
372 add_subwindow(new BC_OKButton(this));
373 add_subwindow(new BC_CancelButton(this));
375 selected_available = -1;
376 selected_shared = -1;
377 selected_modules = -1;
384 int PluginDialog::resize_event(int w, int h)
386 mwindow->session->plugindialog_w = w;
387 mwindow->session->plugindialog_h = h;
388 mwindow->theme->get_plugindialog_sizes();
391 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
392 mwindow->theme->plugindialog_new_y - 20);
393 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
394 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
395 search_text->reposition_window(x1, y1, w1);
396 int dy = search_text->get_h() + 10;
398 standalone_list->reposition_window(x1, y1, w1, h1);
400 // if(standalone_attach)
401 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
402 // mwindow->theme->plugindialog_newattach_y);
404 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
405 // mwindow->theme->plugindialog_newattach_y);
407 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
408 mwindow->theme->plugindialog_shared_y - 20);
409 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
410 mwindow->theme->plugindialog_shared_y,
411 mwindow->theme->plugindialog_shared_w,
412 mwindow->theme->plugindialog_shared_h);
414 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
415 // mwindow->theme->plugindialog_sharedattach_y);
417 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
418 // mwindow->theme->plugindialog_sharedattach_y);
424 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
425 mwindow->theme->plugindialog_module_y - 20);
426 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
427 mwindow->theme->plugindialog_module_y,
428 mwindow->theme->plugindialog_module_w,
429 mwindow->theme->plugindialog_module_h);
431 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
432 // mwindow->theme->plugindialog_moduleattach_y);
434 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
435 // mwindow->theme->plugindialog_moduleattach_y);
438 if(single_standalone)
439 single_standalone->reposition_window(
440 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
441 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
442 get_text_height(MEDIUMFONT));
448 int PluginDialog::attach_new(int number)
450 if(number >= 0 && number < plugindb.size())
452 strcpy(thread->plugin_title, plugindb.values[number]->title);
453 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
458 int PluginDialog::attach_shared(int number)
460 if(number >= 0 && number < plugin_locations.size())
462 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
463 thread->shared_location = *(plugin_locations.values[number]); // copy location
468 int PluginDialog::attach_module(int number)
470 if(number >= 0 && number < module_locations.size())
472 // title->update(module_data.values[number]->get_text());
473 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
474 thread->shared_location = *(module_locations.values[number]); // copy location
479 void PluginDialog::save_settings()
490 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
491 // : BC_TextBox(x, y, 200, 1, text)
493 // this->dialog = dialog;
495 // PluginDialogTextBox::~PluginDialogTextBox()
497 // int PluginDialogTextBox::handle_event()
500 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
501 // : BC_GenericButton(x, y, _("Detach"))
503 // this->dialog = dialog;
505 // PluginDialogDetach::~PluginDialogDetach()
507 // int PluginDialogDetach::handle_event()
509 // // dialog->title->update(_("None"));
510 // dialog->thread->plugin_type = 0; // type is none
511 // dialog->thread->plugin_title[0] = 0;
528 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
529 ArrayList<BC_ListBoxItem*> *standalone_data,
530 int x, int y, int w, int h)
531 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
533 this->dialog = dialog;
536 PluginDialogNew::~PluginDialogNew() { }
537 int PluginDialogNew::handle_event()
539 // dialog->attach_new(get_selection_number(0, 0));
545 int PluginDialogNew::selection_changed()
547 int no = get_selection_number(0, 0);
548 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
549 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
550 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
551 dialog->shared_list->draw_items(1);
552 dialog->selected_shared = -1;
553 dialog->module_list->set_all_selected(&dialog->module_data, 0);
554 dialog->module_list->draw_items(1);
555 dialog->selected_modules = -1;
559 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
560 // : BC_GenericButton(x, y, _("Attach"))
562 // this->dialog = dialog;
564 // PluginDialogAttachNew::~PluginDialogAttachNew()
567 // int PluginDialogAttachNew::handle_event()
569 // dialog->attach_new(dialog->selected_available);
574 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
575 // : BC_GenericButton(x, y, _("Change"))
577 // this->dialog = dialog;
579 // PluginDialogChangeNew::~PluginDialogChangeNew()
582 // int PluginDialogChangeNew::handle_event()
584 // dialog->attach_new(dialog->selected_available);
598 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
599 ArrayList<BC_ListBoxItem*> *shared_data,
611 this->dialog = dialog;
613 PluginDialogShared::~PluginDialogShared() { }
614 int PluginDialogShared::handle_event()
616 // dialog->attach_shared(get_selection_number(0, 0));
621 int PluginDialogShared::selection_changed()
623 dialog->selected_shared = get_selection_number(0, 0);
626 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
627 dialog->standalone_list->draw_items(1);
628 dialog->module_list->set_all_selected(&dialog->module_data, 0);
629 dialog->module_list->draw_items(1);
630 dialog->selected_available = -1;
631 dialog->selected_modules = -1;
635 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
636 // PluginDialog *dialog,
639 // : BC_GenericButton(x, y, _("Attach"))
641 // this->dialog = dialog;
643 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
644 // int PluginDialogAttachShared::handle_event()
646 // dialog->attach_shared(dialog->selected_shared);
651 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
652 // PluginDialog *dialog,
655 // : BC_GenericButton(x, y, _("Change"))
657 // this->dialog = dialog;
659 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
660 // int PluginDialogChangeShared::handle_event()
662 // dialog->attach_shared(dialog->selected_shared);
679 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
680 ArrayList<BC_ListBoxItem*> *module_data,
692 this->dialog = dialog;
694 PluginDialogModules::~PluginDialogModules() { }
695 int PluginDialogModules::handle_event()
697 // dialog->attach_module(get_selection_number(0, 0));
703 int PluginDialogModules::selection_changed()
705 dialog->selected_modules = get_selection_number(0, 0);
708 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
709 dialog->standalone_list->draw_items(1);
710 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
711 dialog->shared_list->draw_items(1);
712 dialog->selected_available = -1;
713 dialog->selected_shared = -1;
717 void PluginDialog::load_plugin_list(int redraw)
719 standalone_data.remove_all_objects();
720 const char *text = search_text->get_text();
722 for( int i=0; i<plugindb.total; ++i ) {
723 const char *title = _(plugindb.values[i]->title);
724 if( text && text[0] && !bstrcasestr(title, text) ) continue;
725 standalone_data.append(new PluginDialogListItem(title, i));
729 standalone_list->draw_items(1);
732 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
733 : BC_TextBox(x, y, w, 1, "")
735 this->dialog = dialog;
738 int PluginDialogSearchText::handle_event()
740 dialog->load_plugin_list(1);
744 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
747 dialog->thread->single_standalone,
748 _("Attach single standalone and share others"))
750 this->dialog = dialog;
753 int PluginDialogSingle::handle_event()
755 dialog->thread->single_standalone = get_value();
760 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
761 // PluginDialog *dialog,
764 // : BC_GenericButton(x, y, _("Attach"))
766 // this->dialog = dialog;
768 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
769 // int PluginDialogAttachModule::handle_event()
771 // dialog->attach_module(dialog->selected_modules);
776 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
777 // PluginDialog *dialog,
780 // : BC_GenericButton(x, y, _("Change"))
782 // this->dialog = dialog;
784 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
785 // int PluginDialogChangeModule::handle_event()
787 // dialog->attach_module(dialog->selected_modules);