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; )
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 ) { plugin_locations.remove_object_number(i); 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));
275 for(int i = 0; i < module_locations.total; i++)
277 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
278 module_data.append(new BC_ListBoxItem(track->title));
286 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
287 mwindow->theme->plugindialog_new_y - 20,
289 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
290 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
291 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
292 int dy = search_text->get_h() + 10;
296 add_subwindow(standalone_list = new PluginDialogNew(this,
297 &standalone_data, x1, y1, w1, h1));
299 // if(thread->plugin)
300 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
302 // mwindow->theme->plugindialog_newattach_x,
303 // mwindow->theme->plugindialog_newattach_y));
305 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
307 // mwindow->theme->plugindialog_newattach_x,
308 // mwindow->theme->plugindialog_newattach_y));
311 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
312 mwindow->theme->plugindialog_shared_y - 20,
313 _("Shared effects:")));
314 add_subwindow(shared_list = new PluginDialogShared(this,
316 mwindow->theme->plugindialog_shared_x,
317 mwindow->theme->plugindialog_shared_y,
318 mwindow->theme->plugindialog_shared_w,
319 mwindow->theme->plugindialog_shared_h));
320 // if(thread->plugin)
321 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
323 // mwindow->theme->plugindialog_sharedattach_x,
324 // mwindow->theme->plugindialog_sharedattach_y));
326 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
328 // mwindow->theme->plugindialog_sharedattach_x,
329 // mwindow->theme->plugindialog_sharedattach_y));
332 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
333 mwindow->theme->plugindialog_module_y - 20,
334 _("Shared tracks:")));
335 add_subwindow(module_list = new PluginDialogModules(this,
337 mwindow->theme->plugindialog_module_x,
338 mwindow->theme->plugindialog_module_y,
339 mwindow->theme->plugindialog_module_w,
340 mwindow->theme->plugindialog_module_h));
341 // if(thread->plugin)
342 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
344 // mwindow->theme->plugindialog_moduleattach_x,
345 // mwindow->theme->plugindialog_moduleattach_y));
347 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
349 // mwindow->theme->plugindialog_moduleattach_x,
350 // mwindow->theme->plugindialog_moduleattach_y));
354 // Add option for the menu invocation
355 // add_subwindow(file_title = new BC_Title(
356 // mwindow->theme->menueffect_file_x,
357 // mwindow->theme->menueffect_file_y,
358 // _("One standalone effect is attached to the first track.\n"
359 // "Shared effects are attached to the remaining tracks.")));
361 if(thread->is_mainmenu)
362 add_subwindow(single_standalone = new PluginDialogSingle(this,
363 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
364 mwindow->theme->plugindialog_new_y +
365 mwindow->theme->plugindialog_new_h +
366 get_text_height(MEDIUMFONT)));
370 add_subwindow(new BC_OKButton(this));
371 add_subwindow(new BC_CancelButton(this));
373 selected_available = -1;
374 selected_shared = -1;
375 selected_modules = -1;
382 int PluginDialog::resize_event(int w, int h)
384 mwindow->session->plugindialog_w = w;
385 mwindow->session->plugindialog_h = h;
386 mwindow->theme->get_plugindialog_sizes();
389 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
390 mwindow->theme->plugindialog_new_y - 20);
391 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
392 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
393 search_text->reposition_window(x1, y1, w1);
394 int dy = search_text->get_h() + 10;
396 standalone_list->reposition_window(x1, y1, w1, h1);
398 // if(standalone_attach)
399 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
400 // mwindow->theme->plugindialog_newattach_y);
402 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
403 // mwindow->theme->plugindialog_newattach_y);
405 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
406 mwindow->theme->plugindialog_shared_y - 20);
407 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
408 mwindow->theme->plugindialog_shared_y,
409 mwindow->theme->plugindialog_shared_w,
410 mwindow->theme->plugindialog_shared_h);
412 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
413 // mwindow->theme->plugindialog_sharedattach_y);
415 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
416 // mwindow->theme->plugindialog_sharedattach_y);
422 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
423 mwindow->theme->plugindialog_module_y - 20);
424 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
425 mwindow->theme->plugindialog_module_y,
426 mwindow->theme->plugindialog_module_w,
427 mwindow->theme->plugindialog_module_h);
429 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
430 // mwindow->theme->plugindialog_moduleattach_y);
432 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
433 // mwindow->theme->plugindialog_moduleattach_y);
436 if(single_standalone)
437 single_standalone->reposition_window(
438 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
439 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
440 get_text_height(MEDIUMFONT));
446 int PluginDialog::attach_new(int number)
448 if(number >= 0 && number < plugindb.size())
450 strcpy(thread->plugin_title, plugindb.values[number]->title);
451 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
456 int PluginDialog::attach_shared(int number)
458 if(number >= 0 && number < plugin_locations.size())
460 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
461 thread->shared_location = *(plugin_locations.values[number]); // copy location
466 int PluginDialog::attach_module(int number)
468 if(number >= 0 && number < module_locations.size())
470 // title->update(module_data.values[number]->get_text());
471 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
472 thread->shared_location = *(module_locations.values[number]); // copy location
477 void PluginDialog::save_settings()
488 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
489 // : BC_TextBox(x, y, 200, 1, text)
491 // this->dialog = dialog;
493 // PluginDialogTextBox::~PluginDialogTextBox()
495 // int PluginDialogTextBox::handle_event()
498 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
499 // : BC_GenericButton(x, y, _("Detach"))
501 // this->dialog = dialog;
503 // PluginDialogDetach::~PluginDialogDetach()
505 // int PluginDialogDetach::handle_event()
507 // // dialog->title->update(_("None"));
508 // dialog->thread->plugin_type = 0; // type is none
509 // dialog->thread->plugin_title[0] = 0;
526 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
527 ArrayList<BC_ListBoxItem*> *standalone_data,
528 int x, int y, int w, int h)
529 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
531 this->dialog = dialog;
534 PluginDialogNew::~PluginDialogNew() { }
535 int PluginDialogNew::handle_event()
537 // dialog->attach_new(get_selection_number(0, 0));
543 int PluginDialogNew::selection_changed()
545 int no = get_selection_number(0, 0);
546 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
547 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
548 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
549 dialog->shared_list->draw_items(1);
550 dialog->selected_shared = -1;
551 dialog->module_list->set_all_selected(&dialog->module_data, 0);
552 dialog->module_list->draw_items(1);
553 dialog->selected_modules = -1;
557 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
558 // : BC_GenericButton(x, y, _("Attach"))
560 // this->dialog = dialog;
562 // PluginDialogAttachNew::~PluginDialogAttachNew()
565 // int PluginDialogAttachNew::handle_event()
567 // dialog->attach_new(dialog->selected_available);
572 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
573 // : BC_GenericButton(x, y, _("Change"))
575 // this->dialog = dialog;
577 // PluginDialogChangeNew::~PluginDialogChangeNew()
580 // int PluginDialogChangeNew::handle_event()
582 // dialog->attach_new(dialog->selected_available);
596 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
597 ArrayList<BC_ListBoxItem*> *shared_data,
609 this->dialog = dialog;
611 PluginDialogShared::~PluginDialogShared() { }
612 int PluginDialogShared::handle_event()
614 // dialog->attach_shared(get_selection_number(0, 0));
619 int PluginDialogShared::selection_changed()
621 dialog->selected_shared = get_selection_number(0, 0);
624 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
625 dialog->standalone_list->draw_items(1);
626 dialog->module_list->set_all_selected(&dialog->module_data, 0);
627 dialog->module_list->draw_items(1);
628 dialog->selected_available = -1;
629 dialog->selected_modules = -1;
633 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
634 // PluginDialog *dialog,
637 // : BC_GenericButton(x, y, _("Attach"))
639 // this->dialog = dialog;
641 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
642 // int PluginDialogAttachShared::handle_event()
644 // dialog->attach_shared(dialog->selected_shared);
649 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
650 // PluginDialog *dialog,
653 // : BC_GenericButton(x, y, _("Change"))
655 // this->dialog = dialog;
657 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
658 // int PluginDialogChangeShared::handle_event()
660 // dialog->attach_shared(dialog->selected_shared);
677 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
678 ArrayList<BC_ListBoxItem*> *module_data,
690 this->dialog = dialog;
692 PluginDialogModules::~PluginDialogModules() { }
693 int PluginDialogModules::handle_event()
695 // dialog->attach_module(get_selection_number(0, 0));
701 int PluginDialogModules::selection_changed()
703 dialog->selected_modules = get_selection_number(0, 0);
706 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
707 dialog->standalone_list->draw_items(1);
708 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
709 dialog->shared_list->draw_items(1);
710 dialog->selected_available = -1;
711 dialog->selected_shared = -1;
715 void PluginDialog::load_plugin_list(int redraw)
717 standalone_data.remove_all_objects();
718 const char *text = search_text->get_text();
720 for( int i=0; i<plugindb.total; ++i ) {
721 const char *title = _(plugindb.values[i]->title);
722 if( text && text[0] && !bstrcasestr(title, text) ) continue;
723 standalone_data.append(new PluginDialogListItem(title, i));
727 standalone_list->draw_items(1);
730 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
731 : BC_TextBox(x, y, w, 1, "")
733 this->dialog = dialog;
736 int PluginDialogSearchText::handle_event()
738 dialog->load_plugin_list(1);
742 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
745 dialog->thread->single_standalone,
746 _("Attach single standalone and share others"))
748 this->dialog = dialog;
751 int PluginDialogSingle::handle_event()
753 dialog->thread->single_standalone = get_value();
758 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
759 // PluginDialog *dialog,
762 // : BC_GenericButton(x, y, _("Attach"))
764 // this->dialog = dialog;
766 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
767 // int PluginDialogAttachModule::handle_event()
769 // dialog->attach_module(dialog->selected_modules);
774 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
775 // PluginDialog *dialog,
778 // : BC_GenericButton(x, y, _("Change"))
780 // this->dialog = dialog;
782 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
783 // int PluginDialogChangeModule::handle_event()
785 // dialog->attach_module(dialog->selected_modules);