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;
48 this->plugin_type = PLUGIN_NONE;
51 PluginDialogThread::~PluginDialogThread()
56 void PluginDialogThread::start_window(Track *track,
57 Plugin *plugin, const char *title, int is_mainmenu, int data_type)
59 if(!BC_DialogThread::is_running())
61 // At this point, the caller should hold the main window mutex.
62 // mwindow->gui->lock_window("PluginDialogThread::start_window");
64 this->data_type = data_type;
65 this->plugin = plugin;
66 this->is_mainmenu = is_mainmenu;
67 single_standalone = mwindow->edl->session->single_standalone;
71 plugin->calculate_title(plugin_title, 0);
72 this->shared_location = plugin->shared_location;
73 this->plugin_type = plugin->plugin_type;
77 this->plugin_title[0] = 0;
78 this->shared_location.plugin = -1;
79 this->shared_location.module = -1;
80 this->plugin_type = PLUGIN_NONE;
83 strcpy(this->window_title, title);
84 mwindow->gui->unlock_window();
86 BC_DialogThread::start();
87 mwindow->gui->lock_window("PluginDialogThread::start_window");
91 BC_Window* PluginDialogThread::new_gui()
93 mwindow->gui->lock_window("PluginDialogThread::new_gui");
94 int x = mwindow->gui->get_abs_cursor_x(0) -
95 mwindow->session->plugindialog_w / 2;
96 int y = mwindow->gui->get_abs_cursor_y(0) -
97 mwindow->session->plugindialog_h / 2;
98 plugin_type = PLUGIN_NONE;
99 PluginDialog *window = new PluginDialog(mwindow,
104 window->create_objects();
105 mwindow->gui->unlock_window();
109 void PluginDialogThread::handle_done_event(int result)
112 PluginDialog *dialog = (PluginDialog *)get_gui();
118 void PluginDialogThread::handle_close_event(int result)
126 PluginDialog::PluginDialog(MWindow *mwindow,
127 PluginDialogThread *thread,
128 const char *window_title,
131 : BC_Window(window_title,
134 mwindow->session->plugindialog_w,
135 mwindow->session->plugindialog_h,
142 this->mwindow = mwindow;
143 this->thread = thread;
144 single_standalone = 0;
147 PluginDialog::~PluginDialog()
149 lock_window("PluginDialog::~PluginDialog");
150 standalone_data.remove_all_objects();
152 shared_data.remove_all_objects();
154 module_data.remove_all_objects();
156 plugin_locations.remove_all_objects();
158 module_locations.remove_all_objects();
160 delete standalone_list;
166 void PluginDialog::create_objects()
168 // int use_default = 1;
169 mwindow->theme->get_plugindialog_sizes();
170 lock_window("PluginDialog::create_objects");
172 // GET A LIST OF ALL THE PLUGINS AVAILABLE
173 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
174 thread->data_type == TRACK_VIDEO,
177 mwindow->edl->get_shared_plugins(thread->track,
181 mwindow->edl->get_shared_tracks(thread->track,
186 // Construct listbox items
187 for(int i = 0; i < plugin_locations.total; )
189 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
190 char *track_title = track->title;
191 int number = plugin_locations.values[i]->plugin;
192 double start = mwindow->edl->local_session->get_selectionstart(1);
193 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
194 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
195 char string[BCTEXTLEN];
196 const char *plugin_title = _(plugin->title);
197 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
198 shared_data.append(new BC_ListBoxItem(string));
201 for(int i = 0; i < module_locations.total; i++)
203 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
204 module_data.append(new BC_ListBoxItem(track->title));
212 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
213 mwindow->theme->plugindialog_new_y - 20,
215 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
216 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
217 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
218 int dy = search_text->get_h() + 10;
222 add_subwindow(standalone_list = new PluginDialogNew(this,
223 &standalone_data, x1, y1, w1, h1));
225 // if(thread->plugin)
226 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
228 // mwindow->theme->plugindialog_newattach_x,
229 // mwindow->theme->plugindialog_newattach_y));
231 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
233 // mwindow->theme->plugindialog_newattach_x,
234 // mwindow->theme->plugindialog_newattach_y));
237 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
238 mwindow->theme->plugindialog_shared_y - 20,
239 _("Shared effects:")));
240 add_subwindow(shared_list = new PluginDialogShared(this,
242 mwindow->theme->plugindialog_shared_x,
243 mwindow->theme->plugindialog_shared_y,
244 mwindow->theme->plugindialog_shared_w,
245 mwindow->theme->plugindialog_shared_h));
246 // if(thread->plugin)
247 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
249 // mwindow->theme->plugindialog_sharedattach_x,
250 // mwindow->theme->plugindialog_sharedattach_y));
252 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
254 // mwindow->theme->plugindialog_sharedattach_x,
255 // mwindow->theme->plugindialog_sharedattach_y));
258 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
259 mwindow->theme->plugindialog_module_y - 20,
260 _("Shared tracks:")));
261 add_subwindow(module_list = new PluginDialogModules(this,
263 mwindow->theme->plugindialog_module_x,
264 mwindow->theme->plugindialog_module_y,
265 mwindow->theme->plugindialog_module_w,
266 mwindow->theme->plugindialog_module_h));
267 // if(thread->plugin)
268 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
270 // mwindow->theme->plugindialog_moduleattach_x,
271 // mwindow->theme->plugindialog_moduleattach_y));
273 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
275 // mwindow->theme->plugindialog_moduleattach_x,
276 // mwindow->theme->plugindialog_moduleattach_y));
280 // Add option for the menu invocation
281 // add_subwindow(file_title = new BC_Title(
282 // mwindow->theme->menueffect_file_x,
283 // mwindow->theme->menueffect_file_y,
284 // _("One standalone effect is attached to the first track.\n"
285 // "Shared effects are attached to the remaining tracks.")));
287 if(thread->is_mainmenu)
288 add_subwindow(single_standalone = new PluginDialogSingle(this,
289 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
290 mwindow->theme->plugindialog_new_y +
291 mwindow->theme->plugindialog_new_h +
292 get_text_height(MEDIUMFONT)));
296 add_subwindow(ok_btn = new BC_OKButton(this));
297 add_subwindow(can_btn = new BC_CancelButton(this));
298 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
299 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
300 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
301 add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
302 selected_available = -1;
303 selected_shared = -1;
304 selected_modules = -1;
311 int PluginDialog::resize_event(int w, int h)
313 mwindow->session->plugindialog_w = w;
314 mwindow->session->plugindialog_h = h;
315 mwindow->theme->get_plugindialog_sizes();
318 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
319 mwindow->theme->plugindialog_new_y - 20);
320 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
321 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
322 search_text->reposition_window(x1, y1, w1);
323 int dy = search_text->get_h() + 10;
325 standalone_list->reposition_window(x1, y1, w1, h1);
327 // if(standalone_attach)
328 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
329 // mwindow->theme->plugindialog_newattach_y);
331 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
332 // mwindow->theme->plugindialog_newattach_y);
334 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
335 mwindow->theme->plugindialog_shared_y - 20);
336 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
337 mwindow->theme->plugindialog_shared_y,
338 mwindow->theme->plugindialog_shared_w,
339 mwindow->theme->plugindialog_shared_h);
341 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
342 // mwindow->theme->plugindialog_sharedattach_y);
344 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
345 // mwindow->theme->plugindialog_sharedattach_y);
351 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
352 mwindow->theme->plugindialog_module_y - 20);
353 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
354 mwindow->theme->plugindialog_module_y,
355 mwindow->theme->plugindialog_module_w,
356 mwindow->theme->plugindialog_module_h);
358 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
359 // mwindow->theme->plugindialog_moduleattach_y);
361 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
362 // mwindow->theme->plugindialog_moduleattach_y);
365 if(single_standalone)
366 single_standalone->reposition_window(
367 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
368 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
369 get_text_height(MEDIUMFONT));
371 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
372 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
373 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
374 apy_btn->reposition_window(ax, ay);
380 int PluginDialog::attach_new(int number)
382 if(number >= 0 && number < plugindb.size())
384 strcpy(thread->plugin_title, plugindb.values[number]->title);
385 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
390 int PluginDialog::attach_shared(int number)
392 if(number >= 0 && number < plugin_locations.size())
394 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
395 thread->shared_location = *(plugin_locations.values[number]); // copy location
400 int PluginDialog::attach_module(int number)
402 if(number >= 0 && number < module_locations.size())
404 // title->update(module_data.values[number]->get_text());
405 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
406 thread->shared_location = *(module_locations.values[number]); // copy location
411 void PluginDialog::save_settings()
416 void PluginDialog::clear_selection()
418 standalone_list->set_all_selected(&standalone_data, 0);
419 standalone_list->draw_items(1);
420 shared_list->set_all_selected(&shared_data, 0);
421 shared_list->draw_items(1);
422 module_list->set_all_selected(&module_data, 0);
423 module_list->draw_items(1);
424 selected_available = -1;
425 selected_shared = -1;
426 selected_modules = -1;
428 thread->plugin_type = PLUGIN_NONE;
431 void PluginDialog::apply()
433 if( selected_available >= 0 ) {
434 attach_new(selected_available);
436 else if( selected_shared >= 0 ) {
437 attach_shared(selected_shared);
439 else if( selected_modules >= 0 ) {
440 attach_module(selected_modules);
446 void PluginDialogThread::apply()
449 mwindow->edl->session->single_standalone = single_standalone;
451 mwindow->gui->lock_window("PluginDialogThread::run 3");
452 mwindow->undo->update_undo_before();
454 mwindow->insert_effect(plugin_title, &shared_location,
455 data_type, plugin_type, single_standalone);
459 if( mwindow->edl->tracks->plugin_exists(plugin) ) {
460 plugin->change_plugin(plugin_title,
461 &shared_location, plugin_type);
465 if( mwindow->edl->tracks->track_exists(track) ) {
466 mwindow->insert_effect(plugin_title, &shared_location,
467 track, 0, 0, 0, plugin_type);
472 mwindow->save_backup();
473 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
474 mwindow->restart_brender();
475 mwindow->update_plugin_states();
476 mwindow->sync_parameters(CHANGE_EDL);
477 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
478 mwindow->gui->unlock_window();
483 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
484 : BC_GenericButton(x, y, _("Apply"))
486 this->dialog = dialog;
489 int PluginDialogApply::handle_event()
492 dialog->clear_selection();
502 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
503 // : BC_TextBox(x, y, 200, 1, text)
505 // this->dialog = dialog;
507 // PluginDialogTextBox::~PluginDialogTextBox()
509 // int PluginDialogTextBox::handle_event()
512 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
513 // : BC_GenericButton(x, y, _("Detach"))
515 // this->dialog = dialog;
517 // PluginDialogDetach::~PluginDialogDetach()
519 // int PluginDialogDetach::handle_event()
521 // // dialog->title->update(_("None"));
522 // dialog->thread->plugin_type = 0; // type is none
523 // dialog->thread->plugin_title[0] = 0;
540 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
541 ArrayList<BC_ListBoxItem*> *standalone_data,
542 int x, int y, int w, int h)
543 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
545 this->dialog = dialog;
548 PluginDialogNew::~PluginDialogNew() { }
549 int PluginDialogNew::handle_event()
551 // dialog->attach_new(get_selection_number(0, 0));
557 int PluginDialogNew::selection_changed()
559 int no = get_selection_number(0, 0);
560 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
561 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
562 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
563 dialog->shared_list->draw_items(1);
564 dialog->selected_shared = -1;
565 dialog->module_list->set_all_selected(&dialog->module_data, 0);
566 dialog->module_list->draw_items(1);
567 dialog->selected_modules = -1;
571 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
572 // : BC_GenericButton(x, y, _("Attach"))
574 // this->dialog = dialog;
576 // PluginDialogAttachNew::~PluginDialogAttachNew()
579 // int PluginDialogAttachNew::handle_event()
581 // dialog->attach_new(dialog->selected_available);
586 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
587 // : BC_GenericButton(x, y, _("Change"))
589 // this->dialog = dialog;
591 // PluginDialogChangeNew::~PluginDialogChangeNew()
594 // int PluginDialogChangeNew::handle_event()
596 // dialog->attach_new(dialog->selected_available);
610 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
611 ArrayList<BC_ListBoxItem*> *shared_data,
623 this->dialog = dialog;
625 PluginDialogShared::~PluginDialogShared() { }
626 int PluginDialogShared::handle_event()
628 // dialog->attach_shared(get_selection_number(0, 0));
633 int PluginDialogShared::selection_changed()
635 dialog->selected_shared = get_selection_number(0, 0);
638 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
639 dialog->standalone_list->draw_items(1);
640 dialog->module_list->set_all_selected(&dialog->module_data, 0);
641 dialog->module_list->draw_items(1);
642 dialog->selected_available = -1;
643 dialog->selected_modules = -1;
647 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
648 // PluginDialog *dialog,
651 // : BC_GenericButton(x, y, _("Attach"))
653 // this->dialog = dialog;
655 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
656 // int PluginDialogAttachShared::handle_event()
658 // dialog->attach_shared(dialog->selected_shared);
663 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
664 // PluginDialog *dialog,
667 // : BC_GenericButton(x, y, _("Change"))
669 // this->dialog = dialog;
671 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
672 // int PluginDialogChangeShared::handle_event()
674 // dialog->attach_shared(dialog->selected_shared);
691 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
692 ArrayList<BC_ListBoxItem*> *module_data,
704 this->dialog = dialog;
706 PluginDialogModules::~PluginDialogModules() { }
707 int PluginDialogModules::handle_event()
709 // dialog->attach_module(get_selection_number(0, 0));
715 int PluginDialogModules::selection_changed()
717 dialog->selected_modules = get_selection_number(0, 0);
720 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
721 dialog->standalone_list->draw_items(1);
722 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
723 dialog->shared_list->draw_items(1);
724 dialog->selected_available = -1;
725 dialog->selected_shared = -1;
729 void PluginDialog::load_plugin_list(int redraw)
731 standalone_data.remove_all_objects();
732 const char *text = search_text->get_text();
734 for( int i=0; i<plugindb.total; ++i ) {
735 const char *title = _(plugindb.values[i]->title);
736 if( text && text[0] && !bstrcasestr(title, text) ) continue;
737 standalone_data.append(new PluginDialogListItem(title, i));
741 standalone_list->draw_items(1);
744 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
745 : BC_TextBox(x, y, w, 1, "")
747 this->dialog = dialog;
750 int PluginDialogSearchText::handle_event()
752 dialog->load_plugin_list(1);
756 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
759 dialog->thread->single_standalone,
760 _("Attach single standalone and share others"))
762 this->dialog = dialog;
765 int PluginDialogSingle::handle_event()
767 dialog->thread->single_standalone = get_value();
772 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
773 // PluginDialog *dialog,
776 // : BC_GenericButton(x, y, _("Attach"))
778 // this->dialog = dialog;
780 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
781 // int PluginDialogAttachModule::handle_event()
783 // dialog->attach_module(dialog->selected_modules);
788 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
789 // PluginDialog *dialog,
792 // : BC_GenericButton(x, y, _("Change"))
794 // this->dialog = dialog;
796 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
797 // int PluginDialogChangeModule::handle_event()
799 // dialog->attach_module(dialog->selected_modules);