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"
24 #include "edlsession.h"
26 #include "localsession.h"
27 #include "mainsession.h"
30 #include "mwindowgui.h"
34 #include "plugindialog.h"
35 #include "pluginserver.h"
39 #include "transition.h"
42 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
45 this->mwindow = mwindow;
49 PluginDialogThread::~PluginDialogThread()
54 void PluginDialogThread::start_window(Track *track,
60 if(!BC_DialogThread::is_running())
62 // At this point, the caller should hold the main window mutex.
63 // mwindow->gui->lock_window("PluginDialogThread::start_window");
65 this->data_type = data_type;
66 this->plugin = plugin;
67 this->is_mainmenu = is_mainmenu;
68 single_standalone = mwindow->edl->session->single_standalone;
72 plugin->calculate_title(plugin_title, 0);
73 this->shared_location = plugin->shared_location;
74 this->plugin_type = plugin->plugin_type;
78 this->plugin_title[0] = 0;
79 this->shared_location.plugin = -1;
80 this->shared_location.module = -1;
81 this->plugin_type = PLUGIN_NONE;
84 strcpy(this->window_title, title);
85 mwindow->gui->unlock_window();
87 BC_DialogThread::start();
88 mwindow->gui->lock_window("PluginDialogThread::start_window");
92 BC_Window* PluginDialogThread::new_gui()
94 mwindow->gui->lock_window("PluginDialogThread::new_gui");
95 int x = mwindow->gui->get_abs_cursor_x(0) -
96 mwindow->session->plugindialog_w / 2;
97 int y = mwindow->gui->get_abs_cursor_y(0) -
98 mwindow->session->plugindialog_h / 2;
100 PluginDialog *window = new PluginDialog(mwindow,
105 window->create_objects();
106 mwindow->gui->unlock_window();
110 void PluginDialogThread::handle_done_event(int result)
112 PluginDialog *window = (PluginDialog*)BC_DialogThread::get_gui();
113 if(window->selected_available >= 0)
115 window->attach_new(window->selected_available);
118 if(window->selected_shared >= 0)
120 window->attach_shared(window->selected_shared);
123 if(window->selected_modules >= 0)
125 window->attach_module(window->selected_modules);
128 mwindow->edl->session->single_standalone = single_standalone;
131 void PluginDialogThread::handle_close_event(int result)
137 mwindow->gui->lock_window("PluginDialogThread::run 3");
140 mwindow->undo->update_undo_before();
143 mwindow->insert_effect(plugin_title,
153 if(mwindow->edl->tracks->plugin_exists(plugin))
155 plugin->change_plugin(plugin_title,
162 if(mwindow->edl->tracks->track_exists(track))
164 mwindow->insert_effect(plugin_title,
175 mwindow->save_backup();
176 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
177 mwindow->restart_brender();
178 mwindow->update_plugin_states();
179 mwindow->sync_parameters(CHANGE_EDL);
180 mwindow->gui->update(1,
188 mwindow->gui->unlock_window();
202 PluginDialog::PluginDialog(MWindow *mwindow,
203 PluginDialogThread *thread,
204 const char *window_title,
207 : BC_Window(window_title,
210 mwindow->session->plugindialog_w,
211 mwindow->session->plugindialog_h,
218 this->mwindow = mwindow;
219 this->thread = thread;
220 single_standalone = 0;
223 PluginDialog::~PluginDialog()
225 lock_window("PluginDialog::~PluginDialog");
226 standalone_data.remove_all_objects();
228 shared_data.remove_all_objects();
230 module_data.remove_all_objects();
232 plugin_locations.remove_all_objects();
234 module_locations.remove_all_objects();
236 delete standalone_list;
242 void PluginDialog::create_objects()
244 // int use_default = 1;
245 char string[BCTEXTLEN];
246 mwindow->theme->get_plugindialog_sizes();
248 lock_window("PluginDialog::create_objects");
251 strcpy(string, thread->plugin->title);
257 sprintf(string, _("None"));
265 // GET A LIST OF ALL THE PLUGINS AVAILABLE
266 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
267 thread->data_type == TRACK_VIDEO,
270 mwindow->edl->get_shared_plugins(thread->track,
274 mwindow->edl->get_shared_tracks(thread->track,
279 // Construct listbox items
280 for(int i = 0; i < plugin_locations.total; i++)
282 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
283 char *track_title = track->title;
284 int number = plugin_locations.values[i]->plugin;
285 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->get_selectionstart(1),
290 char *plugin_title = plugin->title;
291 char string[BCTEXTLEN];
293 snprintf(string, sizeof(string), "%s: %s", track_title, _(plugin_title));
294 shared_data.append(new BC_ListBoxItem(string));
296 for(int i = 0; i < module_locations.total; i++)
298 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
299 module_data.append(new BC_ListBoxItem(track->title));
307 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
308 mwindow->theme->plugindialog_new_y - 20,
310 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
311 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
312 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
313 int dy = search_text->get_h() + 10;
317 add_subwindow(standalone_list = new PluginDialogNew(this,
318 &standalone_data, x1, y1, w1, h1));
320 // if(thread->plugin)
321 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
323 // mwindow->theme->plugindialog_newattach_x,
324 // mwindow->theme->plugindialog_newattach_y));
326 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
328 // mwindow->theme->plugindialog_newattach_x,
329 // mwindow->theme->plugindialog_newattach_y));
338 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
339 mwindow->theme->plugindialog_shared_y - 20,
340 _("Shared effects:")));
341 add_subwindow(shared_list = new PluginDialogShared(this,
343 mwindow->theme->plugindialog_shared_x,
344 mwindow->theme->plugindialog_shared_y,
345 mwindow->theme->plugindialog_shared_w,
346 mwindow->theme->plugindialog_shared_h));
347 // if(thread->plugin)
348 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
350 // mwindow->theme->plugindialog_sharedattach_x,
351 // mwindow->theme->plugindialog_sharedattach_y));
353 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
355 // mwindow->theme->plugindialog_sharedattach_x,
356 // mwindow->theme->plugindialog_sharedattach_y));
366 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
367 mwindow->theme->plugindialog_module_y - 20,
368 _("Shared tracks:")));
369 add_subwindow(module_list = new PluginDialogModules(this,
371 mwindow->theme->plugindialog_module_x,
372 mwindow->theme->plugindialog_module_y,
373 mwindow->theme->plugindialog_module_w,
374 mwindow->theme->plugindialog_module_h));
375 // if(thread->plugin)
376 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
378 // mwindow->theme->plugindialog_moduleattach_x,
379 // mwindow->theme->plugindialog_moduleattach_y));
381 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
383 // mwindow->theme->plugindialog_moduleattach_x,
384 // mwindow->theme->plugindialog_moduleattach_y));
388 // Add option for the menu invocation
389 // add_subwindow(file_title = new BC_Title(
390 // mwindow->theme->menueffect_file_x,
391 // mwindow->theme->menueffect_file_y,
392 // _("One standalone effect is attached to the first track.\n"
393 // "Shared effects are attached to the remaining tracks.")));
395 if(thread->is_mainmenu)
396 add_subwindow(single_standalone = new PluginDialogSingle(this,
397 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
398 mwindow->theme->plugindialog_new_y +
399 mwindow->theme->plugindialog_new_h +
400 get_text_height(MEDIUMFONT)));
404 add_subwindow(new BC_OKButton(this));
405 add_subwindow(new BC_CancelButton(this));
407 selected_available = -1;
408 selected_shared = -1;
409 selected_modules = -1;
416 int PluginDialog::resize_event(int w, int h)
418 mwindow->session->plugindialog_w = w;
419 mwindow->session->plugindialog_h = h;
420 mwindow->theme->get_plugindialog_sizes();
423 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
424 mwindow->theme->plugindialog_new_y - 20);
425 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
426 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
427 search_text->reposition_window(x1, y1, w1);
428 int dy = search_text->get_h() + 10;
430 standalone_list->reposition_window(x1, y1, w1, h1);
432 // if(standalone_attach)
433 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
434 // mwindow->theme->plugindialog_newattach_y);
436 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
437 // mwindow->theme->plugindialog_newattach_y);
439 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
440 mwindow->theme->plugindialog_shared_y - 20);
441 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
442 mwindow->theme->plugindialog_shared_y,
443 mwindow->theme->plugindialog_shared_w,
444 mwindow->theme->plugindialog_shared_h);
446 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
447 // mwindow->theme->plugindialog_sharedattach_y);
449 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
450 // mwindow->theme->plugindialog_sharedattach_y);
456 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
457 mwindow->theme->plugindialog_module_y - 20);
458 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
459 mwindow->theme->plugindialog_module_y,
460 mwindow->theme->plugindialog_module_w,
461 mwindow->theme->plugindialog_module_h);
463 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
464 // mwindow->theme->plugindialog_moduleattach_y);
466 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
467 // mwindow->theme->plugindialog_moduleattach_y);
470 if(single_standalone)
471 single_standalone->reposition_window(mwindow->theme->plugindialog_new_x,
472 mwindow->theme->plugindialog_new_y +
473 mwindow->theme->plugindialog_new_h +
474 get_text_height(MEDIUMFONT));
480 int PluginDialog::attach_new(int number)
482 if(number > -1 && number < standalone_data.total)
484 strcpy(thread->plugin_title, plugindb.values[number]->title);
485 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
490 int PluginDialog::attach_shared(int number)
492 if(number > -1 && number < shared_data.total)
494 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
495 thread->shared_location = *(plugin_locations.values[number]); // copy location
500 int PluginDialog::attach_module(int number)
502 if(number > -1 && number < module_data.total)
504 // title->update(module_data.values[number]->get_text());
505 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
506 thread->shared_location = *(module_locations.values[number]); // copy location
511 void PluginDialog::save_settings()
522 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
523 // : BC_TextBox(x, y, 200, 1, text)
525 // this->dialog = dialog;
527 // PluginDialogTextBox::~PluginDialogTextBox()
529 // int PluginDialogTextBox::handle_event()
532 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
533 // : BC_GenericButton(x, y, _("Detach"))
535 // this->dialog = dialog;
537 // PluginDialogDetach::~PluginDialogDetach()
539 // int PluginDialogDetach::handle_event()
541 // // dialog->title->update(_("None"));
542 // dialog->thread->plugin_type = 0; // type is none
543 // dialog->thread->plugin_title[0] = 0;
560 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
561 ArrayList<BC_ListBoxItem*> *standalone_data,
562 int x, int y, int w, int h)
563 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
565 this->dialog = dialog;
568 PluginDialogNew::~PluginDialogNew() { }
569 int PluginDialogNew::handle_event()
571 // dialog->attach_new(get_selection_number(0, 0));
577 int PluginDialogNew::selection_changed()
579 dialog->selected_available = get_selection_number(0, 0);
582 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
583 dialog->shared_list->draw_items(1);
584 dialog->module_list->set_all_selected(&dialog->module_data, 0);
585 dialog->module_list->draw_items(1);
586 dialog->selected_shared = -1;
587 dialog->selected_modules = -1;
591 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
592 // : BC_GenericButton(x, y, _("Attach"))
594 // this->dialog = dialog;
596 // PluginDialogAttachNew::~PluginDialogAttachNew()
599 // int PluginDialogAttachNew::handle_event()
601 // dialog->attach_new(dialog->selected_available);
606 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
607 // : BC_GenericButton(x, y, _("Change"))
609 // this->dialog = dialog;
611 // PluginDialogChangeNew::~PluginDialogChangeNew()
614 // int PluginDialogChangeNew::handle_event()
616 // dialog->attach_new(dialog->selected_available);
630 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
631 ArrayList<BC_ListBoxItem*> *shared_data,
643 this->dialog = dialog;
645 PluginDialogShared::~PluginDialogShared() { }
646 int PluginDialogShared::handle_event()
648 // dialog->attach_shared(get_selection_number(0, 0));
653 int PluginDialogShared::selection_changed()
655 dialog->selected_shared = get_selection_number(0, 0);
658 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
659 dialog->standalone_list->draw_items(1);
660 dialog->module_list->set_all_selected(&dialog->module_data, 0);
661 dialog->module_list->draw_items(1);
662 dialog->selected_available = -1;
663 dialog->selected_modules = -1;
667 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
668 // PluginDialog *dialog,
671 // : BC_GenericButton(x, y, _("Attach"))
673 // this->dialog = dialog;
675 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
676 // int PluginDialogAttachShared::handle_event()
678 // dialog->attach_shared(dialog->selected_shared);
683 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
684 // PluginDialog *dialog,
687 // : BC_GenericButton(x, y, _("Change"))
689 // this->dialog = dialog;
691 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
692 // int PluginDialogChangeShared::handle_event()
694 // dialog->attach_shared(dialog->selected_shared);
711 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
712 ArrayList<BC_ListBoxItem*> *module_data,
724 this->dialog = dialog;
726 PluginDialogModules::~PluginDialogModules() { }
727 int PluginDialogModules::handle_event()
729 // dialog->attach_module(get_selection_number(0, 0));
735 int PluginDialogModules::selection_changed()
737 dialog->selected_modules = get_selection_number(0, 0);
740 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
741 dialog->standalone_list->draw_items(1);
742 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
743 dialog->shared_list->draw_items(1);
744 dialog->selected_available = -1;
745 dialog->selected_shared = -1;
749 void PluginDialog::load_plugin_list(int redraw)
751 standalone_data.remove_all_objects();
752 const char *text = search_text->get_text();
754 for( int i=0; i<plugindb.total; ++i ) {
755 const char *title = plugindb.values[i]->title;
756 if( text && text[0] && !strstr(title, text) ) continue;
757 standalone_data.append(new BC_ListBoxItem(title));
761 standalone_list->draw_items(1);
764 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
765 : BC_TextBox(x, y, w, 1, "")
767 this->dialog = dialog;
770 int PluginDialogSearchText::handle_event()
772 dialog->load_plugin_list(1);
776 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
779 dialog->thread->single_standalone,
780 _("Attach single standlone and share others"))
782 this->dialog = dialog;
785 int PluginDialogSingle::handle_event()
787 dialog->thread->single_standalone = get_value();
792 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
793 // PluginDialog *dialog,
796 // : BC_GenericButton(x, y, _("Attach"))
798 // this->dialog = dialog;
800 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
801 // int PluginDialogAttachModule::handle_event()
803 // dialog->attach_module(dialog->selected_modules);
808 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
809 // PluginDialog *dialog,
812 // : BC_GenericButton(x, y, _("Change"))
814 // this->dialog = dialog;
816 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
817 // int PluginDialogChangeModule::handle_event()
819 // dialog->attach_module(dialog->selected_modules);