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,
56 Plugin *plugin, const char *title, int is_mainmenu, int data_type)
58 if(!BC_DialogThread::is_running())
60 // At this point, the caller should hold the main window mutex.
61 // mwindow->gui->lock_window("PluginDialogThread::start_window");
63 this->data_type = data_type;
64 this->plugin = plugin;
65 this->is_mainmenu = is_mainmenu;
66 single_standalone = mwindow->edl->session->single_standalone;
70 plugin->calculate_title(plugin_title, 0);
71 this->shared_location = plugin->shared_location;
72 this->plugin_type = plugin->plugin_type;
76 this->plugin_title[0] = 0;
77 this->shared_location.plugin = -1;
78 this->shared_location.module = -1;
79 this->plugin_type = PLUGIN_NONE;
82 strcpy(this->window_title, title);
83 mwindow->gui->unlock_window();
85 BC_DialogThread::start();
86 mwindow->gui->lock_window("PluginDialogThread::start_window");
90 BC_Window* PluginDialogThread::new_gui()
92 mwindow->gui->lock_window("PluginDialogThread::new_gui");
93 int x = mwindow->gui->get_abs_cursor_x(0) -
94 mwindow->session->plugindialog_w / 2;
95 int y = mwindow->gui->get_abs_cursor_y(0) -
96 mwindow->session->plugindialog_h / 2;
98 PluginDialog *window = new PluginDialog(mwindow,
103 window->create_objects();
104 mwindow->gui->unlock_window();
108 void PluginDialogThread::handle_done_event(int result)
110 PluginDialog *window = (PluginDialog*)BC_DialogThread::get_gui();
111 if(window->selected_available >= 0)
113 window->attach_new(window->selected_available);
116 if(window->selected_shared >= 0)
118 window->attach_shared(window->selected_shared);
121 if(window->selected_modules >= 0)
123 window->attach_module(window->selected_modules);
126 mwindow->edl->session->single_standalone = single_standalone;
129 void PluginDialogThread::handle_close_event(int result)
135 mwindow->gui->lock_window("PluginDialogThread::run 3");
138 mwindow->undo->update_undo_before();
141 mwindow->insert_effect(plugin_title,
151 if(mwindow->edl->tracks->plugin_exists(plugin))
153 plugin->change_plugin(plugin_title,
160 if(mwindow->edl->tracks->track_exists(track))
162 mwindow->insert_effect(plugin_title,
173 mwindow->save_backup();
174 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
175 mwindow->restart_brender();
176 mwindow->update_plugin_states();
177 mwindow->sync_parameters(CHANGE_EDL);
178 mwindow->gui->update(1,
186 mwindow->gui->unlock_window();
200 PluginDialog::PluginDialog(MWindow *mwindow,
201 PluginDialogThread *thread,
202 const char *window_title,
205 : BC_Window(window_title,
208 mwindow->session->plugindialog_w,
209 mwindow->session->plugindialog_h,
216 this->mwindow = mwindow;
217 this->thread = thread;
218 single_standalone = 0;
221 PluginDialog::~PluginDialog()
223 lock_window("PluginDialog::~PluginDialog");
224 standalone_data.remove_all_objects();
226 shared_data.remove_all_objects();
228 module_data.remove_all_objects();
230 plugin_locations.remove_all_objects();
232 module_locations.remove_all_objects();
234 delete standalone_list;
240 void PluginDialog::create_objects()
242 // int use_default = 1;
243 mwindow->theme->get_plugindialog_sizes();
244 lock_window("PluginDialog::create_objects");
246 // GET A LIST OF ALL THE PLUGINS AVAILABLE
247 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
248 thread->data_type == TRACK_VIDEO,
251 mwindow->edl->get_shared_plugins(thread->track,
255 mwindow->edl->get_shared_tracks(thread->track,
260 // Construct listbox items
261 for(int i = 0; i < plugin_locations.total; i++)
263 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
264 char *track_title = track->title;
265 int number = plugin_locations.values[i]->plugin;
266 double start = mwindow->edl->local_session->get_selectionstart(1);
267 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
268 if( !plugin ) continue;
269 char string[BCTEXTLEN];
270 const char *plugin_title = _(plugin->title);
271 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
272 shared_data.append(new BC_ListBoxItem(string));
274 for(int i = 0; i < module_locations.total; i++)
276 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
277 module_data.append(new BC_ListBoxItem(track->title));
285 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
286 mwindow->theme->plugindialog_new_y - 20,
288 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
289 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
290 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
291 int dy = search_text->get_h() + 10;
295 add_subwindow(standalone_list = new PluginDialogNew(this,
296 &standalone_data, x1, y1, w1, h1));
298 // if(thread->plugin)
299 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
301 // mwindow->theme->plugindialog_newattach_x,
302 // mwindow->theme->plugindialog_newattach_y));
304 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
306 // mwindow->theme->plugindialog_newattach_x,
307 // mwindow->theme->plugindialog_newattach_y));
310 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
311 mwindow->theme->plugindialog_shared_y - 20,
312 _("Shared effects:")));
313 add_subwindow(shared_list = new PluginDialogShared(this,
315 mwindow->theme->plugindialog_shared_x,
316 mwindow->theme->plugindialog_shared_y,
317 mwindow->theme->plugindialog_shared_w,
318 mwindow->theme->plugindialog_shared_h));
319 // if(thread->plugin)
320 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
322 // mwindow->theme->plugindialog_sharedattach_x,
323 // mwindow->theme->plugindialog_sharedattach_y));
325 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
327 // mwindow->theme->plugindialog_sharedattach_x,
328 // mwindow->theme->plugindialog_sharedattach_y));
331 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
332 mwindow->theme->plugindialog_module_y - 20,
333 _("Shared tracks:")));
334 add_subwindow(module_list = new PluginDialogModules(this,
336 mwindow->theme->plugindialog_module_x,
337 mwindow->theme->plugindialog_module_y,
338 mwindow->theme->plugindialog_module_w,
339 mwindow->theme->plugindialog_module_h));
340 // if(thread->plugin)
341 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
343 // mwindow->theme->plugindialog_moduleattach_x,
344 // mwindow->theme->plugindialog_moduleattach_y));
346 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
348 // mwindow->theme->plugindialog_moduleattach_x,
349 // mwindow->theme->plugindialog_moduleattach_y));
353 // Add option for the menu invocation
354 // add_subwindow(file_title = new BC_Title(
355 // mwindow->theme->menueffect_file_x,
356 // mwindow->theme->menueffect_file_y,
357 // _("One standalone effect is attached to the first track.\n"
358 // "Shared effects are attached to the remaining tracks.")));
360 if(thread->is_mainmenu)
361 add_subwindow(single_standalone = new PluginDialogSingle(this,
362 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
363 mwindow->theme->plugindialog_new_y +
364 mwindow->theme->plugindialog_new_h +
365 get_text_height(MEDIUMFONT)));
369 add_subwindow(new BC_OKButton(this));
370 add_subwindow(new BC_CancelButton(this));
372 selected_available = -1;
373 selected_shared = -1;
374 selected_modules = -1;
381 int PluginDialog::resize_event(int w, int h)
383 mwindow->session->plugindialog_w = w;
384 mwindow->session->plugindialog_h = h;
385 mwindow->theme->get_plugindialog_sizes();
388 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
389 mwindow->theme->plugindialog_new_y - 20);
390 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
391 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
392 search_text->reposition_window(x1, y1, w1);
393 int dy = search_text->get_h() + 10;
395 standalone_list->reposition_window(x1, y1, w1, h1);
397 // if(standalone_attach)
398 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
399 // mwindow->theme->plugindialog_newattach_y);
401 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
402 // mwindow->theme->plugindialog_newattach_y);
404 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
405 mwindow->theme->plugindialog_shared_y - 20);
406 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
407 mwindow->theme->plugindialog_shared_y,
408 mwindow->theme->plugindialog_shared_w,
409 mwindow->theme->plugindialog_shared_h);
411 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
412 // mwindow->theme->plugindialog_sharedattach_y);
414 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
415 // mwindow->theme->plugindialog_sharedattach_y);
421 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
422 mwindow->theme->plugindialog_module_y - 20);
423 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
424 mwindow->theme->plugindialog_module_y,
425 mwindow->theme->plugindialog_module_w,
426 mwindow->theme->plugindialog_module_h);
428 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
429 // mwindow->theme->plugindialog_moduleattach_y);
431 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
432 // mwindow->theme->plugindialog_moduleattach_y);
435 if(single_standalone)
436 single_standalone->reposition_window(
437 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
438 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
439 get_text_height(MEDIUMFONT));
445 int PluginDialog::attach_new(int number)
447 if(number >= 0 && number < plugindb.size())
449 strcpy(thread->plugin_title, plugindb.values[number]->title);
450 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
455 int PluginDialog::attach_shared(int number)
457 if(number >= 0 && number < plugin_locations.size())
459 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
460 thread->shared_location = *(plugin_locations.values[number]); // copy location
465 int PluginDialog::attach_module(int number)
467 if(number >= 0 && number < module_locations.size())
469 // title->update(module_data.values[number]->get_text());
470 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
471 thread->shared_location = *(module_locations.values[number]); // copy location
476 void PluginDialog::save_settings()
487 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
488 // : BC_TextBox(x, y, 200, 1, text)
490 // this->dialog = dialog;
492 // PluginDialogTextBox::~PluginDialogTextBox()
494 // int PluginDialogTextBox::handle_event()
497 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
498 // : BC_GenericButton(x, y, _("Detach"))
500 // this->dialog = dialog;
502 // PluginDialogDetach::~PluginDialogDetach()
504 // int PluginDialogDetach::handle_event()
506 // // dialog->title->update(_("None"));
507 // dialog->thread->plugin_type = 0; // type is none
508 // dialog->thread->plugin_title[0] = 0;
525 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
526 ArrayList<BC_ListBoxItem*> *standalone_data,
527 int x, int y, int w, int h)
528 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
530 this->dialog = dialog;
533 PluginDialogNew::~PluginDialogNew() { }
534 int PluginDialogNew::handle_event()
536 // dialog->attach_new(get_selection_number(0, 0));
542 int PluginDialogNew::selection_changed()
544 int no = get_selection_number(0, 0);
545 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
546 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
547 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
548 dialog->shared_list->draw_items(1);
549 dialog->selected_shared = -1;
550 dialog->module_list->set_all_selected(&dialog->module_data, 0);
551 dialog->module_list->draw_items(1);
552 dialog->selected_modules = -1;
556 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
557 // : BC_GenericButton(x, y, _("Attach"))
559 // this->dialog = dialog;
561 // PluginDialogAttachNew::~PluginDialogAttachNew()
564 // int PluginDialogAttachNew::handle_event()
566 // dialog->attach_new(dialog->selected_available);
571 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
572 // : BC_GenericButton(x, y, _("Change"))
574 // this->dialog = dialog;
576 // PluginDialogChangeNew::~PluginDialogChangeNew()
579 // int PluginDialogChangeNew::handle_event()
581 // dialog->attach_new(dialog->selected_available);
595 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
596 ArrayList<BC_ListBoxItem*> *shared_data,
608 this->dialog = dialog;
610 PluginDialogShared::~PluginDialogShared() { }
611 int PluginDialogShared::handle_event()
613 // dialog->attach_shared(get_selection_number(0, 0));
618 int PluginDialogShared::selection_changed()
620 dialog->selected_shared = get_selection_number(0, 0);
623 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
624 dialog->standalone_list->draw_items(1);
625 dialog->module_list->set_all_selected(&dialog->module_data, 0);
626 dialog->module_list->draw_items(1);
627 dialog->selected_available = -1;
628 dialog->selected_modules = -1;
632 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
633 // PluginDialog *dialog,
636 // : BC_GenericButton(x, y, _("Attach"))
638 // this->dialog = dialog;
640 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
641 // int PluginDialogAttachShared::handle_event()
643 // dialog->attach_shared(dialog->selected_shared);
648 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
649 // PluginDialog *dialog,
652 // : BC_GenericButton(x, y, _("Change"))
654 // this->dialog = dialog;
656 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
657 // int PluginDialogChangeShared::handle_event()
659 // dialog->attach_shared(dialog->selected_shared);
676 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
677 ArrayList<BC_ListBoxItem*> *module_data,
689 this->dialog = dialog;
691 PluginDialogModules::~PluginDialogModules() { }
692 int PluginDialogModules::handle_event()
694 // dialog->attach_module(get_selection_number(0, 0));
700 int PluginDialogModules::selection_changed()
702 dialog->selected_modules = get_selection_number(0, 0);
705 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
706 dialog->standalone_list->draw_items(1);
707 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
708 dialog->shared_list->draw_items(1);
709 dialog->selected_available = -1;
710 dialog->selected_shared = -1;
714 void PluginDialog::load_plugin_list(int redraw)
716 standalone_data.remove_all_objects();
717 const char *text = search_text->get_text();
719 for( int i=0; i<plugindb.total; ++i ) {
720 const char *title = _(plugindb.values[i]->title);
721 if( text && text[0] && !bstrcasestr(title, text) ) continue;
722 standalone_data.append(new PluginDialogListItem(title, i));
726 standalone_list->draw_items(1);
729 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
730 : BC_TextBox(x, y, w, 1, "")
732 this->dialog = dialog;
735 int PluginDialogSearchText::handle_event()
737 dialog->load_plugin_list(1);
741 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
744 dialog->thread->single_standalone,
745 _("Attach single standalone and share others"))
747 this->dialog = dialog;
750 int PluginDialogSingle::handle_event()
752 dialog->thread->single_standalone = get_value();
757 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
758 // PluginDialog *dialog,
761 // : BC_GenericButton(x, y, _("Attach"))
763 // this->dialog = dialog;
765 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
766 // int PluginDialogAttachModule::handle_event()
768 // dialog->attach_module(dialog->selected_modules);
773 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
774 // PluginDialog *dialog,
777 // : BC_GenericButton(x, y, _("Change"))
779 // this->dialog = dialog;
781 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
782 // int PluginDialogChangeModule::handle_event()
784 // dialog->attach_module(dialog->selected_modules);