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->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;
73 this->plugin_id = plugin->orig_id;
77 this->plugin_title[0] = 0;
78 this->shared_location.plugin = -1;
79 this->shared_location.module = -1;
80 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;
99 plugin_type = PLUGIN_NONE;
100 PluginDialog *window = new PluginDialog(mwindow,
105 window->create_objects();
106 mwindow->gui->unlock_window();
110 void PluginDialogThread::handle_done_event(int result)
113 PluginDialog *dialog = (PluginDialog *)get_gui();
119 void PluginDialogThread::handle_close_event(int result)
127 PluginDialog::PluginDialog(MWindow *mwindow,
128 PluginDialogThread *thread,
129 const char *window_title,
132 : BC_Window(window_title, x, y,
133 mwindow->session->plugindialog_w,
134 mwindow->session->plugindialog_h,
135 xS(510), yS(415), 1, 0, 1)
137 this->mwindow = mwindow;
138 this->thread = thread;
139 single_standalone = 0;
142 PluginDialog::~PluginDialog()
144 lock_window("PluginDialog::~PluginDialog");
145 standalone_data.remove_all_objects();
147 shared_data.remove_all_objects();
149 module_data.remove_all_objects();
151 plugin_locations.remove_all_objects();
153 module_locations.remove_all_objects();
155 delete standalone_list;
161 void PluginDialog::create_objects()
164 int ys10 = yS(10), ys20 = yS(20);
165 // int use_default = 1;
166 mwindow->theme->get_plugindialog_sizes();
167 lock_window("PluginDialog::create_objects");
169 // GET A LIST OF ALL THE PLUGINS AVAILABLE
170 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
171 thread->data_type == TRACK_VIDEO,
174 mwindow->edl->get_shared_plugins(thread->track,
178 mwindow->edl->get_shared_tracks(thread->track,
183 // Construct listbox items
184 for(int i = 0; i < plugin_locations.total; )
186 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
187 char *track_title = track->title;
188 int number = plugin_locations.values[i]->plugin;
189 double start = mwindow->edl->local_session->get_selectionstart(1);
190 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
191 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
192 char string[BCTEXTLEN];
193 const char *plugin_title = _(plugin->title);
194 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
195 shared_data.append(new BC_ListBoxItem(string));
198 for(int i = 0; i < module_locations.total; i++)
200 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
201 module_data.append(new BC_ListBoxItem(track->title));
205 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
206 mwindow->theme->plugindialog_new_y - ys20,
208 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
209 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
210 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
211 int dy = search_text->get_h() + ys10;
215 add_subwindow(standalone_list = new PluginDialogNew(this,
216 &standalone_data, x1, y1, w1, h1));
218 // if(thread->plugin)
219 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
221 // mwindow->theme->plugindialog_newattach_x,
222 // mwindow->theme->plugindialog_newattach_y));
224 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
226 // mwindow->theme->plugindialog_newattach_x,
227 // mwindow->theme->plugindialog_newattach_y));
230 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
231 mwindow->theme->plugindialog_shared_y - ys20,
232 _("Shared effects:")));
233 add_subwindow(shared_list = new PluginDialogShared(this,
235 mwindow->theme->plugindialog_shared_x,
236 mwindow->theme->plugindialog_shared_y,
237 mwindow->theme->plugindialog_shared_w,
238 mwindow->theme->plugindialog_shared_h));
239 // if(thread->plugin)
240 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
242 // mwindow->theme->plugindialog_sharedattach_x,
243 // mwindow->theme->plugindialog_sharedattach_y));
245 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
247 // mwindow->theme->plugindialog_sharedattach_x,
248 // mwindow->theme->plugindialog_sharedattach_y));
251 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
252 mwindow->theme->plugindialog_module_y - ys20,
253 _("Shared tracks:")));
254 add_subwindow(module_list = new PluginDialogModules(this,
256 mwindow->theme->plugindialog_module_x,
257 mwindow->theme->plugindialog_module_y,
258 mwindow->theme->plugindialog_module_w,
259 mwindow->theme->plugindialog_module_h));
260 // if(thread->plugin)
261 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
263 // mwindow->theme->plugindialog_moduleattach_x,
264 // mwindow->theme->plugindialog_moduleattach_y));
266 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
268 // mwindow->theme->plugindialog_moduleattach_x,
269 // mwindow->theme->plugindialog_moduleattach_y));
273 // Add option for the menu invocation
274 // add_subwindow(file_title = new BC_Title(
275 // mwindow->theme->menueffect_file_x,
276 // mwindow->theme->menueffect_file_y,
277 // _("One standalone effect is attached to the first track.\n"
278 // "Shared effects are attached to the remaining tracks.")));
280 if(thread->is_mainmenu)
281 add_subwindow(single_standalone = new PluginDialogSingle(this,
282 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + xs10,
283 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
284 get_text_height(MEDIUMFONT)));
286 add_subwindow(ok_btn = new BC_OKButton(this));
287 add_subwindow(can_btn = new BC_CancelButton(this));
288 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
289 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
290 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
291 add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
292 selected_available = -1;
293 selected_shared = -1;
294 selected_modules = -1;
301 int PluginDialog::resize_event(int w, int h)
303 int ys10 = yS(10), ys20 = yS(20);
304 mwindow->session->plugindialog_w = w;
305 mwindow->session->plugindialog_h = h;
306 mwindow->theme->get_plugindialog_sizes();
308 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
309 mwindow->theme->plugindialog_new_y - ys20);
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 search_text->reposition_window(x1, y1, w1);
313 int dy = search_text->get_h() + ys10;
315 standalone_list->reposition_window(x1, y1, w1, h1);
317 // if(standalone_attach)
318 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
319 // mwindow->theme->plugindialog_newattach_y);
321 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
322 // mwindow->theme->plugindialog_newattach_y);
324 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
325 mwindow->theme->plugindialog_shared_y - ys20);
326 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
327 mwindow->theme->plugindialog_shared_y,
328 mwindow->theme->plugindialog_shared_w,
329 mwindow->theme->plugindialog_shared_h);
331 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
332 // mwindow->theme->plugindialog_sharedattach_y);
334 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
335 // mwindow->theme->plugindialog_sharedattach_y);
341 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
342 mwindow->theme->plugindialog_module_y - ys20);
343 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
344 mwindow->theme->plugindialog_module_y,
345 mwindow->theme->plugindialog_module_w,
346 mwindow->theme->plugindialog_module_h);
348 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
349 // mwindow->theme->plugindialog_moduleattach_y);
351 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
352 // mwindow->theme->plugindialog_moduleattach_y);
355 if(single_standalone)
356 single_standalone->reposition_window(
357 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + ys10,
358 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
359 get_text_height(MEDIUMFONT));
361 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
362 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
363 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
364 apy_btn->reposition_window(ax, ay);
370 int PluginDialog::attach_new(int number)
372 if(number >= 0 && number < plugindb.size())
374 strcpy(thread->plugin_title, plugindb.values[number]->title);
375 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
380 int PluginDialog::attach_shared(int number)
382 if(number >= 0 && number < plugin_locations.size())
384 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
385 thread->shared_location = *(plugin_locations.values[number]); // copy location
390 int PluginDialog::attach_module(int number)
392 if(number >= 0 && number < module_locations.size())
394 // title->update(module_data.values[number]->get_text());
395 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
396 thread->shared_location = *(module_locations.values[number]); // copy location
401 void PluginDialog::save_settings()
406 void PluginDialog::clear_selection()
408 standalone_list->set_all_selected(&standalone_data, 0);
409 standalone_list->draw_items(1);
410 shared_list->set_all_selected(&shared_data, 0);
411 shared_list->draw_items(1);
412 module_list->set_all_selected(&module_data, 0);
413 module_list->draw_items(1);
414 selected_available = -1;
415 selected_shared = -1;
416 selected_modules = -1;
417 thread->plugin_id = -1;
418 thread->plugin_type = PLUGIN_NONE;
421 void PluginDialog::apply()
423 if( selected_available >= 0 ) {
424 attach_new(selected_available);
426 else if( selected_shared >= 0 ) {
427 attach_shared(selected_shared);
429 else if( selected_modules >= 0 ) {
430 attach_module(selected_modules);
436 void PluginDialogThread::apply()
439 mwindow->edl->session->single_standalone = single_standalone;
441 mwindow->gui->lock_window("PluginDialogThread::run 3");
442 mwindow->undo->update_undo_before();
444 mwindow->insert_effect(plugin_title, &shared_location,
445 data_type, plugin_type, single_standalone);
448 Plugin *plugin = mwindow->edl->tracks->plugin_exists(plugin_id);
450 plugin->change_plugin(plugin_title,
451 &shared_location, plugin_type);
453 else if( mwindow->edl->tracks->track_exists(track) ) {
454 mwindow->insert_effect(plugin_title, &shared_location,
455 track, 0, 0, 0, plugin_type);
459 mwindow->save_backup();
460 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
461 mwindow->restart_brender();
462 mwindow->update_plugin_states();
463 mwindow->sync_parameters(CHANGE_EDL);
464 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
465 mwindow->gui->unlock_window();
470 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
471 : BC_GenericButton(x, y, _("Apply"))
473 this->dialog = dialog;
476 int PluginDialogApply::handle_event()
479 dialog->clear_selection();
489 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
490 // : BC_TextBox(x, y, xS(200), 1, text)
492 // this->dialog = dialog;
494 // PluginDialogTextBox::~PluginDialogTextBox()
496 // int PluginDialogTextBox::handle_event()
499 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
500 // : BC_GenericButton(x, y, _("Detach"))
502 // this->dialog = dialog;
504 // PluginDialogDetach::~PluginDialogDetach()
506 // int PluginDialogDetach::handle_event()
508 // // dialog->title->update(_("None"));
509 // dialog->thread->plugin_type = 0; // type is none
510 // dialog->thread->plugin_title[0] = 0;
517 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
518 ArrayList<BC_ListBoxItem*> *standalone_data,
519 int x, int y, int w, int h)
520 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
522 this->dialog = dialog;
525 PluginDialogNew::~PluginDialogNew() { }
526 int PluginDialogNew::handle_event()
528 // dialog->attach_new(get_selection_number(0, 0));
534 int PluginDialogNew::selection_changed()
536 int no = get_selection_number(0, 0);
537 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
538 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
539 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
540 dialog->shared_list->draw_items(1);
541 dialog->selected_shared = -1;
542 dialog->module_list->set_all_selected(&dialog->module_data, 0);
543 dialog->module_list->draw_items(1);
544 dialog->selected_modules = -1;
548 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
549 // : BC_GenericButton(x, y, _("Attach"))
551 // this->dialog = dialog;
553 // PluginDialogAttachNew::~PluginDialogAttachNew()
556 // int PluginDialogAttachNew::handle_event()
558 // dialog->attach_new(dialog->selected_available);
563 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
564 // : BC_GenericButton(x, y, _("Change"))
566 // this->dialog = dialog;
568 // PluginDialogChangeNew::~PluginDialogChangeNew()
571 // int PluginDialogChangeNew::handle_event()
573 // dialog->attach_new(dialog->selected_available);
579 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
580 ArrayList<BC_ListBoxItem*> *shared_data,
581 int x, int y, int w, int h)
582 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, shared_data)
584 this->dialog = dialog;
586 PluginDialogShared::~PluginDialogShared() { }
587 int PluginDialogShared::handle_event()
589 // dialog->attach_shared(get_selection_number(0, 0));
594 int PluginDialogShared::selection_changed()
596 dialog->selected_shared = get_selection_number(0, 0);
599 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
600 dialog->standalone_list->draw_items(1);
601 dialog->module_list->set_all_selected(&dialog->module_data, 0);
602 dialog->module_list->draw_items(1);
603 dialog->selected_available = -1;
604 dialog->selected_modules = -1;
608 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
609 // PluginDialog *dialog,
612 // : BC_GenericButton(x, y, _("Attach"))
614 // this->dialog = dialog;
616 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
617 // int PluginDialogAttachShared::handle_event()
619 // dialog->attach_shared(dialog->selected_shared);
624 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
625 // PluginDialog *dialog,
628 // : BC_GenericButton(x, y, _("Change"))
630 // this->dialog = dialog;
632 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
633 // int PluginDialogChangeShared::handle_event()
635 // dialog->attach_shared(dialog->selected_shared);
652 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
653 ArrayList<BC_ListBoxItem*> *module_data,
654 int x, int y, int w, int h)
655 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, module_data)
657 this->dialog = dialog;
659 PluginDialogModules::~PluginDialogModules() { }
660 int PluginDialogModules::handle_event()
662 // dialog->attach_module(get_selection_number(0, 0));
668 int PluginDialogModules::selection_changed()
670 dialog->selected_modules = get_selection_number(0, 0);
673 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
674 dialog->standalone_list->draw_items(1);
675 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
676 dialog->shared_list->draw_items(1);
677 dialog->selected_available = -1;
678 dialog->selected_shared = -1;
682 void PluginDialog::load_plugin_list(int redraw)
684 standalone_data.remove_all_objects();
685 const char *text = search_text->get_text();
687 for( int i=0; i<plugindb.total; ++i ) {
688 const char *title = _(plugindb.values[i]->title);
689 if( text && text[0] && !bstrcasestr(title, text) ) continue;
690 standalone_data.append(new PluginDialogListItem(title, i));
694 standalone_list->draw_items(1);
697 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
698 : BC_TextBox(x, y, w, 1, "")
700 this->dialog = dialog;
703 int PluginDialogSearchText::handle_event()
705 dialog->load_plugin_list(1);
709 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
710 : BC_CheckBox(x, y, dialog->thread->single_standalone,
711 _("Attach single standalone and share others"))
713 this->dialog = dialog;
716 int PluginDialogSingle::handle_event()
718 dialog->thread->single_standalone = get_value();
723 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
724 // PluginDialog *dialog,
727 // : BC_GenericButton(x, y, _("Attach"))
729 // this->dialog = dialog;
731 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
732 // int PluginDialogAttachModule::handle_event()
734 // dialog->attach_module(dialog->selected_modules);
739 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
740 // PluginDialog *dialog,
743 // : BC_GenericButton(x, y, _("Change"))
745 // this->dialog = dialog;
747 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
748 // int PluginDialogChangeModule::handle_event()
750 // dialog->attach_module(dialog->selected_modules);