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 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->get_selectionstart(1),
274 char string[BCTEXTLEN];
275 const char *plugin_title = _(plugin->title);
276 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
277 shared_data.append(new BC_ListBoxItem(string));
279 for(int i = 0; i < module_locations.total; i++)
281 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
282 module_data.append(new BC_ListBoxItem(track->title));
290 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
291 mwindow->theme->plugindialog_new_y - 20,
293 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
294 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
295 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
296 int dy = search_text->get_h() + 10;
300 add_subwindow(standalone_list = new PluginDialogNew(this,
301 &standalone_data, x1, y1, w1, h1));
303 // if(thread->plugin)
304 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
306 // mwindow->theme->plugindialog_newattach_x,
307 // mwindow->theme->plugindialog_newattach_y));
309 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
311 // mwindow->theme->plugindialog_newattach_x,
312 // mwindow->theme->plugindialog_newattach_y));
315 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
316 mwindow->theme->plugindialog_shared_y - 20,
317 _("Shared effects:")));
318 add_subwindow(shared_list = new PluginDialogShared(this,
320 mwindow->theme->plugindialog_shared_x,
321 mwindow->theme->plugindialog_shared_y,
322 mwindow->theme->plugindialog_shared_w,
323 mwindow->theme->plugindialog_shared_h));
324 // if(thread->plugin)
325 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
327 // mwindow->theme->plugindialog_sharedattach_x,
328 // mwindow->theme->plugindialog_sharedattach_y));
330 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
332 // mwindow->theme->plugindialog_sharedattach_x,
333 // mwindow->theme->plugindialog_sharedattach_y));
336 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
337 mwindow->theme->plugindialog_module_y - 20,
338 _("Shared tracks:")));
339 add_subwindow(module_list = new PluginDialogModules(this,
341 mwindow->theme->plugindialog_module_x,
342 mwindow->theme->plugindialog_module_y,
343 mwindow->theme->plugindialog_module_w,
344 mwindow->theme->plugindialog_module_h));
345 // if(thread->plugin)
346 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
348 // mwindow->theme->plugindialog_moduleattach_x,
349 // mwindow->theme->plugindialog_moduleattach_y));
351 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
353 // mwindow->theme->plugindialog_moduleattach_x,
354 // mwindow->theme->plugindialog_moduleattach_y));
358 // Add option for the menu invocation
359 // add_subwindow(file_title = new BC_Title(
360 // mwindow->theme->menueffect_file_x,
361 // mwindow->theme->menueffect_file_y,
362 // _("One standalone effect is attached to the first track.\n"
363 // "Shared effects are attached to the remaining tracks.")));
365 if(thread->is_mainmenu)
366 add_subwindow(single_standalone = new PluginDialogSingle(this,
367 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
368 mwindow->theme->plugindialog_new_y +
369 mwindow->theme->plugindialog_new_h +
370 get_text_height(MEDIUMFONT)));
374 add_subwindow(new BC_OKButton(this));
375 add_subwindow(new BC_CancelButton(this));
377 selected_available = -1;
378 selected_shared = -1;
379 selected_modules = -1;
386 int PluginDialog::resize_event(int w, int h)
388 mwindow->session->plugindialog_w = w;
389 mwindow->session->plugindialog_h = h;
390 mwindow->theme->get_plugindialog_sizes();
393 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
394 mwindow->theme->plugindialog_new_y - 20);
395 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
396 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
397 search_text->reposition_window(x1, y1, w1);
398 int dy = search_text->get_h() + 10;
400 standalone_list->reposition_window(x1, y1, w1, h1);
402 // if(standalone_attach)
403 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
404 // mwindow->theme->plugindialog_newattach_y);
406 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
407 // mwindow->theme->plugindialog_newattach_y);
409 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
410 mwindow->theme->plugindialog_shared_y - 20);
411 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
412 mwindow->theme->plugindialog_shared_y,
413 mwindow->theme->plugindialog_shared_w,
414 mwindow->theme->plugindialog_shared_h);
416 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
417 // mwindow->theme->plugindialog_sharedattach_y);
419 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
420 // mwindow->theme->plugindialog_sharedattach_y);
426 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
427 mwindow->theme->plugindialog_module_y - 20);
428 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
429 mwindow->theme->plugindialog_module_y,
430 mwindow->theme->plugindialog_module_w,
431 mwindow->theme->plugindialog_module_h);
433 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
434 // mwindow->theme->plugindialog_moduleattach_y);
436 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
437 // mwindow->theme->plugindialog_moduleattach_y);
440 if(single_standalone)
441 single_standalone->reposition_window(mwindow->theme->plugindialog_new_x,
442 mwindow->theme->plugindialog_new_y +
443 mwindow->theme->plugindialog_new_h +
444 get_text_height(MEDIUMFONT));
450 int PluginDialog::attach_new(int number)
452 if(number >= 0 && number < plugindb.size())
454 strcpy(thread->plugin_title, plugindb.values[number]->title);
455 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
460 int PluginDialog::attach_shared(int number)
462 if(number >= 0 && number < plugin_locations.size())
464 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
465 thread->shared_location = *(plugin_locations.values[number]); // copy location
470 int PluginDialog::attach_module(int number)
472 if(number >= 0 && number < module_locations.size())
474 // title->update(module_data.values[number]->get_text());
475 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
476 thread->shared_location = *(module_locations.values[number]); // copy location
481 void PluginDialog::save_settings()
492 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
493 // : BC_TextBox(x, y, 200, 1, text)
495 // this->dialog = dialog;
497 // PluginDialogTextBox::~PluginDialogTextBox()
499 // int PluginDialogTextBox::handle_event()
502 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
503 // : BC_GenericButton(x, y, _("Detach"))
505 // this->dialog = dialog;
507 // PluginDialogDetach::~PluginDialogDetach()
509 // int PluginDialogDetach::handle_event()
511 // // dialog->title->update(_("None"));
512 // dialog->thread->plugin_type = 0; // type is none
513 // dialog->thread->plugin_title[0] = 0;
530 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
531 ArrayList<BC_ListBoxItem*> *standalone_data,
532 int x, int y, int w, int h)
533 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
535 this->dialog = dialog;
538 PluginDialogNew::~PluginDialogNew() { }
539 int PluginDialogNew::handle_event()
541 // dialog->attach_new(get_selection_number(0, 0));
547 int PluginDialogNew::selection_changed()
549 int no = get_selection_number(0, 0);
550 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
551 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
552 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
553 dialog->shared_list->draw_items(1);
554 dialog->selected_shared = -1;
555 dialog->module_list->set_all_selected(&dialog->module_data, 0);
556 dialog->module_list->draw_items(1);
557 dialog->selected_modules = -1;
561 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
562 // : BC_GenericButton(x, y, _("Attach"))
564 // this->dialog = dialog;
566 // PluginDialogAttachNew::~PluginDialogAttachNew()
569 // int PluginDialogAttachNew::handle_event()
571 // dialog->attach_new(dialog->selected_available);
576 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
577 // : BC_GenericButton(x, y, _("Change"))
579 // this->dialog = dialog;
581 // PluginDialogChangeNew::~PluginDialogChangeNew()
584 // int PluginDialogChangeNew::handle_event()
586 // dialog->attach_new(dialog->selected_available);
600 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
601 ArrayList<BC_ListBoxItem*> *shared_data,
613 this->dialog = dialog;
615 PluginDialogShared::~PluginDialogShared() { }
616 int PluginDialogShared::handle_event()
618 // dialog->attach_shared(get_selection_number(0, 0));
623 int PluginDialogShared::selection_changed()
625 dialog->selected_shared = get_selection_number(0, 0);
628 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
629 dialog->standalone_list->draw_items(1);
630 dialog->module_list->set_all_selected(&dialog->module_data, 0);
631 dialog->module_list->draw_items(1);
632 dialog->selected_available = -1;
633 dialog->selected_modules = -1;
637 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
638 // PluginDialog *dialog,
641 // : BC_GenericButton(x, y, _("Attach"))
643 // this->dialog = dialog;
645 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
646 // int PluginDialogAttachShared::handle_event()
648 // dialog->attach_shared(dialog->selected_shared);
653 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
654 // PluginDialog *dialog,
657 // : BC_GenericButton(x, y, _("Change"))
659 // this->dialog = dialog;
661 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
662 // int PluginDialogChangeShared::handle_event()
664 // dialog->attach_shared(dialog->selected_shared);
681 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
682 ArrayList<BC_ListBoxItem*> *module_data,
694 this->dialog = dialog;
696 PluginDialogModules::~PluginDialogModules() { }
697 int PluginDialogModules::handle_event()
699 // dialog->attach_module(get_selection_number(0, 0));
705 int PluginDialogModules::selection_changed()
707 dialog->selected_modules = get_selection_number(0, 0);
710 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
711 dialog->standalone_list->draw_items(1);
712 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
713 dialog->shared_list->draw_items(1);
714 dialog->selected_available = -1;
715 dialog->selected_shared = -1;
719 void PluginDialog::load_plugin_list(int redraw)
721 standalone_data.remove_all_objects();
722 const char *text = search_text->get_text();
724 for( int i=0; i<plugindb.total; ++i ) {
725 const char *title = plugindb.values[i]->title;
726 if( text && text[0] && !bstrcasestr(title, text) ) continue;
727 standalone_data.append(new PluginDialogListItem(title, i));
731 standalone_list->draw_items(1);
734 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
735 : BC_TextBox(x, y, w, 1, "")
737 this->dialog = dialog;
740 int PluginDialogSearchText::handle_event()
742 dialog->load_plugin_list(1);
746 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
749 dialog->thread->single_standalone,
750 _("Attach single standlone and share others"))
752 this->dialog = dialog;
755 int PluginDialogSingle::handle_event()
757 dialog->thread->single_standalone = get_value();
762 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
763 // PluginDialog *dialog,
766 // : BC_GenericButton(x, y, _("Attach"))
768 // this->dialog = dialog;
770 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
771 // int PluginDialogAttachModule::handle_event()
773 // dialog->attach_module(dialog->selected_modules);
778 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
779 // PluginDialog *dialog,
782 // : BC_GenericButton(x, y, _("Change"))
784 // this->dialog = dialog;
786 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
787 // int PluginDialogChangeModule::handle_event()
789 // dialog->attach_module(dialog->selected_modules);