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, NORMAL_DRAW, 0, 0, 1, 0, 0);
179 mwindow->gui->unlock_window();
193 PluginDialog::PluginDialog(MWindow *mwindow,
194 PluginDialogThread *thread,
195 const char *window_title,
198 : BC_Window(window_title,
201 mwindow->session->plugindialog_w,
202 mwindow->session->plugindialog_h,
209 this->mwindow = mwindow;
210 this->thread = thread;
211 single_standalone = 0;
214 PluginDialog::~PluginDialog()
216 lock_window("PluginDialog::~PluginDialog");
217 standalone_data.remove_all_objects();
219 shared_data.remove_all_objects();
221 module_data.remove_all_objects();
223 plugin_locations.remove_all_objects();
225 module_locations.remove_all_objects();
227 delete standalone_list;
233 void PluginDialog::create_objects()
235 // int use_default = 1;
236 mwindow->theme->get_plugindialog_sizes();
237 lock_window("PluginDialog::create_objects");
239 // GET A LIST OF ALL THE PLUGINS AVAILABLE
240 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
241 thread->data_type == TRACK_VIDEO,
244 mwindow->edl->get_shared_plugins(thread->track,
248 mwindow->edl->get_shared_tracks(thread->track,
253 // Construct listbox items
254 for(int i = 0; i < plugin_locations.total; )
256 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
257 char *track_title = track->title;
258 int number = plugin_locations.values[i]->plugin;
259 double start = mwindow->edl->local_session->get_selectionstart(1);
260 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
261 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
262 char string[BCTEXTLEN];
263 const char *plugin_title = _(plugin->title);
264 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
265 shared_data.append(new BC_ListBoxItem(string));
268 for(int i = 0; i < module_locations.total; i++)
270 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
271 module_data.append(new BC_ListBoxItem(track->title));
279 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
280 mwindow->theme->plugindialog_new_y - 20,
282 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
283 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
284 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
285 int dy = search_text->get_h() + 10;
289 add_subwindow(standalone_list = new PluginDialogNew(this,
290 &standalone_data, x1, y1, w1, h1));
292 // if(thread->plugin)
293 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
295 // mwindow->theme->plugindialog_newattach_x,
296 // mwindow->theme->plugindialog_newattach_y));
298 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
300 // mwindow->theme->plugindialog_newattach_x,
301 // mwindow->theme->plugindialog_newattach_y));
304 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
305 mwindow->theme->plugindialog_shared_y - 20,
306 _("Shared effects:")));
307 add_subwindow(shared_list = new PluginDialogShared(this,
309 mwindow->theme->plugindialog_shared_x,
310 mwindow->theme->plugindialog_shared_y,
311 mwindow->theme->plugindialog_shared_w,
312 mwindow->theme->plugindialog_shared_h));
313 // if(thread->plugin)
314 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
316 // mwindow->theme->plugindialog_sharedattach_x,
317 // mwindow->theme->plugindialog_sharedattach_y));
319 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
321 // mwindow->theme->plugindialog_sharedattach_x,
322 // mwindow->theme->plugindialog_sharedattach_y));
325 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
326 mwindow->theme->plugindialog_module_y - 20,
327 _("Shared tracks:")));
328 add_subwindow(module_list = new PluginDialogModules(this,
330 mwindow->theme->plugindialog_module_x,
331 mwindow->theme->plugindialog_module_y,
332 mwindow->theme->plugindialog_module_w,
333 mwindow->theme->plugindialog_module_h));
334 // if(thread->plugin)
335 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
337 // mwindow->theme->plugindialog_moduleattach_x,
338 // mwindow->theme->plugindialog_moduleattach_y));
340 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
342 // mwindow->theme->plugindialog_moduleattach_x,
343 // mwindow->theme->plugindialog_moduleattach_y));
347 // Add option for the menu invocation
348 // add_subwindow(file_title = new BC_Title(
349 // mwindow->theme->menueffect_file_x,
350 // mwindow->theme->menueffect_file_y,
351 // _("One standalone effect is attached to the first track.\n"
352 // "Shared effects are attached to the remaining tracks.")));
354 if(thread->is_mainmenu)
355 add_subwindow(single_standalone = new PluginDialogSingle(this,
356 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
357 mwindow->theme->plugindialog_new_y +
358 mwindow->theme->plugindialog_new_h +
359 get_text_height(MEDIUMFONT)));
363 add_subwindow(new BC_OKButton(this));
364 add_subwindow(new BC_CancelButton(this));
366 selected_available = -1;
367 selected_shared = -1;
368 selected_modules = -1;
375 int PluginDialog::resize_event(int w, int h)
377 mwindow->session->plugindialog_w = w;
378 mwindow->session->plugindialog_h = h;
379 mwindow->theme->get_plugindialog_sizes();
382 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
383 mwindow->theme->plugindialog_new_y - 20);
384 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
385 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
386 search_text->reposition_window(x1, y1, w1);
387 int dy = search_text->get_h() + 10;
389 standalone_list->reposition_window(x1, y1, w1, h1);
391 // if(standalone_attach)
392 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
393 // mwindow->theme->plugindialog_newattach_y);
395 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
396 // mwindow->theme->plugindialog_newattach_y);
398 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
399 mwindow->theme->plugindialog_shared_y - 20);
400 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
401 mwindow->theme->plugindialog_shared_y,
402 mwindow->theme->plugindialog_shared_w,
403 mwindow->theme->plugindialog_shared_h);
405 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
406 // mwindow->theme->plugindialog_sharedattach_y);
408 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
409 // mwindow->theme->plugindialog_sharedattach_y);
415 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
416 mwindow->theme->plugindialog_module_y - 20);
417 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
418 mwindow->theme->plugindialog_module_y,
419 mwindow->theme->plugindialog_module_w,
420 mwindow->theme->plugindialog_module_h);
422 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
423 // mwindow->theme->plugindialog_moduleattach_y);
425 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
426 // mwindow->theme->plugindialog_moduleattach_y);
429 if(single_standalone)
430 single_standalone->reposition_window(
431 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
432 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
433 get_text_height(MEDIUMFONT));
439 int PluginDialog::attach_new(int number)
441 if(number >= 0 && number < plugindb.size())
443 strcpy(thread->plugin_title, plugindb.values[number]->title);
444 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
449 int PluginDialog::attach_shared(int number)
451 if(number >= 0 && number < plugin_locations.size())
453 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
454 thread->shared_location = *(plugin_locations.values[number]); // copy location
459 int PluginDialog::attach_module(int number)
461 if(number >= 0 && number < module_locations.size())
463 // title->update(module_data.values[number]->get_text());
464 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
465 thread->shared_location = *(module_locations.values[number]); // copy location
470 void PluginDialog::save_settings()
481 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
482 // : BC_TextBox(x, y, 200, 1, text)
484 // this->dialog = dialog;
486 // PluginDialogTextBox::~PluginDialogTextBox()
488 // int PluginDialogTextBox::handle_event()
491 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
492 // : BC_GenericButton(x, y, _("Detach"))
494 // this->dialog = dialog;
496 // PluginDialogDetach::~PluginDialogDetach()
498 // int PluginDialogDetach::handle_event()
500 // // dialog->title->update(_("None"));
501 // dialog->thread->plugin_type = 0; // type is none
502 // dialog->thread->plugin_title[0] = 0;
519 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
520 ArrayList<BC_ListBoxItem*> *standalone_data,
521 int x, int y, int w, int h)
522 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
524 this->dialog = dialog;
527 PluginDialogNew::~PluginDialogNew() { }
528 int PluginDialogNew::handle_event()
530 // dialog->attach_new(get_selection_number(0, 0));
536 int PluginDialogNew::selection_changed()
538 int no = get_selection_number(0, 0);
539 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
540 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
541 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
542 dialog->shared_list->draw_items(1);
543 dialog->selected_shared = -1;
544 dialog->module_list->set_all_selected(&dialog->module_data, 0);
545 dialog->module_list->draw_items(1);
546 dialog->selected_modules = -1;
550 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
551 // : BC_GenericButton(x, y, _("Attach"))
553 // this->dialog = dialog;
555 // PluginDialogAttachNew::~PluginDialogAttachNew()
558 // int PluginDialogAttachNew::handle_event()
560 // dialog->attach_new(dialog->selected_available);
565 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
566 // : BC_GenericButton(x, y, _("Change"))
568 // this->dialog = dialog;
570 // PluginDialogChangeNew::~PluginDialogChangeNew()
573 // int PluginDialogChangeNew::handle_event()
575 // dialog->attach_new(dialog->selected_available);
589 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
590 ArrayList<BC_ListBoxItem*> *shared_data,
602 this->dialog = dialog;
604 PluginDialogShared::~PluginDialogShared() { }
605 int PluginDialogShared::handle_event()
607 // dialog->attach_shared(get_selection_number(0, 0));
612 int PluginDialogShared::selection_changed()
614 dialog->selected_shared = get_selection_number(0, 0);
617 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
618 dialog->standalone_list->draw_items(1);
619 dialog->module_list->set_all_selected(&dialog->module_data, 0);
620 dialog->module_list->draw_items(1);
621 dialog->selected_available = -1;
622 dialog->selected_modules = -1;
626 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
627 // PluginDialog *dialog,
630 // : BC_GenericButton(x, y, _("Attach"))
632 // this->dialog = dialog;
634 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
635 // int PluginDialogAttachShared::handle_event()
637 // dialog->attach_shared(dialog->selected_shared);
642 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
643 // PluginDialog *dialog,
646 // : BC_GenericButton(x, y, _("Change"))
648 // this->dialog = dialog;
650 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
651 // int PluginDialogChangeShared::handle_event()
653 // dialog->attach_shared(dialog->selected_shared);
670 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
671 ArrayList<BC_ListBoxItem*> *module_data,
683 this->dialog = dialog;
685 PluginDialogModules::~PluginDialogModules() { }
686 int PluginDialogModules::handle_event()
688 // dialog->attach_module(get_selection_number(0, 0));
694 int PluginDialogModules::selection_changed()
696 dialog->selected_modules = get_selection_number(0, 0);
699 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
700 dialog->standalone_list->draw_items(1);
701 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
702 dialog->shared_list->draw_items(1);
703 dialog->selected_available = -1;
704 dialog->selected_shared = -1;
708 void PluginDialog::load_plugin_list(int redraw)
710 standalone_data.remove_all_objects();
711 const char *text = search_text->get_text();
713 for( int i=0; i<plugindb.total; ++i ) {
714 const char *title = _(plugindb.values[i]->title);
715 if( text && text[0] && !bstrcasestr(title, text) ) continue;
716 standalone_data.append(new PluginDialogListItem(title, i));
720 standalone_list->draw_items(1);
723 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
724 : BC_TextBox(x, y, w, 1, "")
726 this->dialog = dialog;
729 int PluginDialogSearchText::handle_event()
731 dialog->load_plugin_list(1);
735 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
738 dialog->thread->single_standalone,
739 _("Attach single standalone and share others"))
741 this->dialog = dialog;
744 int PluginDialogSingle::handle_event()
746 dialog->thread->single_standalone = get_value();
751 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
752 // PluginDialog *dialog,
755 // : BC_GenericButton(x, y, _("Attach"))
757 // this->dialog = dialog;
759 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
760 // int PluginDialogAttachModule::handle_event()
762 // dialog->attach_module(dialog->selected_modules);
767 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
768 // PluginDialog *dialog,
771 // : BC_GenericButton(x, y, _("Change"))
773 // this->dialog = dialog;
775 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
776 // int PluginDialogChangeModule::handle_event()
778 // dialog->attach_module(dialog->selected_modules);