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, x, y,
132 mwindow->session->plugindialog_w,
133 mwindow->session->plugindialog_h,
134 xS(510), yS(415), 1, 0, 1)
136 this->mwindow = mwindow;
137 this->thread = thread;
138 single_standalone = 0;
141 PluginDialog::~PluginDialog()
143 lock_window("PluginDialog::~PluginDialog");
144 standalone_data.remove_all_objects();
146 shared_data.remove_all_objects();
148 module_data.remove_all_objects();
150 plugin_locations.remove_all_objects();
152 module_locations.remove_all_objects();
154 delete standalone_list;
160 void PluginDialog::create_objects()
163 int ys10 = yS(10), ys20 = yS(20);
164 // int use_default = 1;
165 mwindow->theme->get_plugindialog_sizes();
166 lock_window("PluginDialog::create_objects");
168 // GET A LIST OF ALL THE PLUGINS AVAILABLE
169 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
170 thread->data_type == TRACK_VIDEO,
173 mwindow->edl->get_shared_plugins(thread->track,
177 mwindow->edl->get_shared_tracks(thread->track,
182 // Construct listbox items
183 for(int i = 0; i < plugin_locations.total; )
185 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
186 char *track_title = track->title;
187 int number = plugin_locations.values[i]->plugin;
188 double start = mwindow->edl->local_session->get_selectionstart(1);
189 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
190 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
191 char string[BCTEXTLEN];
192 const char *plugin_title = _(plugin->title);
193 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
194 shared_data.append(new BC_ListBoxItem(string));
197 for(int i = 0; i < module_locations.total; i++)
199 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
200 module_data.append(new BC_ListBoxItem(track->title));
204 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
205 mwindow->theme->plugindialog_new_y - ys20,
207 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
208 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
209 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
210 int dy = search_text->get_h() + ys10;
214 add_subwindow(standalone_list = new PluginDialogNew(this,
215 &standalone_data, x1, y1, w1, h1));
217 // if(thread->plugin)
218 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
220 // mwindow->theme->plugindialog_newattach_x,
221 // mwindow->theme->plugindialog_newattach_y));
223 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
225 // mwindow->theme->plugindialog_newattach_x,
226 // mwindow->theme->plugindialog_newattach_y));
229 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
230 mwindow->theme->plugindialog_shared_y - ys20,
231 _("Shared effects:")));
232 add_subwindow(shared_list = new PluginDialogShared(this,
234 mwindow->theme->plugindialog_shared_x,
235 mwindow->theme->plugindialog_shared_y,
236 mwindow->theme->plugindialog_shared_w,
237 mwindow->theme->plugindialog_shared_h));
238 // if(thread->plugin)
239 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
241 // mwindow->theme->plugindialog_sharedattach_x,
242 // mwindow->theme->plugindialog_sharedattach_y));
244 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
246 // mwindow->theme->plugindialog_sharedattach_x,
247 // mwindow->theme->plugindialog_sharedattach_y));
250 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
251 mwindow->theme->plugindialog_module_y - ys20,
252 _("Shared tracks:")));
253 add_subwindow(module_list = new PluginDialogModules(this,
255 mwindow->theme->plugindialog_module_x,
256 mwindow->theme->plugindialog_module_y,
257 mwindow->theme->plugindialog_module_w,
258 mwindow->theme->plugindialog_module_h));
259 // if(thread->plugin)
260 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
262 // mwindow->theme->plugindialog_moduleattach_x,
263 // mwindow->theme->plugindialog_moduleattach_y));
265 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
267 // mwindow->theme->plugindialog_moduleattach_x,
268 // mwindow->theme->plugindialog_moduleattach_y));
272 // Add option for the menu invocation
273 // add_subwindow(file_title = new BC_Title(
274 // mwindow->theme->menueffect_file_x,
275 // mwindow->theme->menueffect_file_y,
276 // _("One standalone effect is attached to the first track.\n"
277 // "Shared effects are attached to the remaining tracks.")));
279 if(thread->is_mainmenu)
280 add_subwindow(single_standalone = new PluginDialogSingle(this,
281 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + xs10,
282 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
283 get_text_height(MEDIUMFONT)));
285 add_subwindow(ok_btn = new BC_OKButton(this));
286 add_subwindow(can_btn = new BC_CancelButton(this));
287 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
288 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
289 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
290 add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
291 selected_available = -1;
292 selected_shared = -1;
293 selected_modules = -1;
300 int PluginDialog::resize_event(int w, int h)
302 int ys10 = yS(10), ys20 = yS(20);
303 mwindow->session->plugindialog_w = w;
304 mwindow->session->plugindialog_h = h;
305 mwindow->theme->get_plugindialog_sizes();
307 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
308 mwindow->theme->plugindialog_new_y - ys20);
309 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
310 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
311 search_text->reposition_window(x1, y1, w1);
312 int dy = search_text->get_h() + ys10;
314 standalone_list->reposition_window(x1, y1, w1, h1);
316 // if(standalone_attach)
317 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
318 // mwindow->theme->plugindialog_newattach_y);
320 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
321 // mwindow->theme->plugindialog_newattach_y);
323 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
324 mwindow->theme->plugindialog_shared_y - ys20);
325 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
326 mwindow->theme->plugindialog_shared_y,
327 mwindow->theme->plugindialog_shared_w,
328 mwindow->theme->plugindialog_shared_h);
330 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
331 // mwindow->theme->plugindialog_sharedattach_y);
333 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
334 // mwindow->theme->plugindialog_sharedattach_y);
340 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
341 mwindow->theme->plugindialog_module_y - ys20);
342 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
343 mwindow->theme->plugindialog_module_y,
344 mwindow->theme->plugindialog_module_w,
345 mwindow->theme->plugindialog_module_h);
347 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
348 // mwindow->theme->plugindialog_moduleattach_y);
350 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
351 // mwindow->theme->plugindialog_moduleattach_y);
354 if(single_standalone)
355 single_standalone->reposition_window(
356 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + ys10,
357 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
358 get_text_height(MEDIUMFONT));
360 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
361 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
362 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
363 apy_btn->reposition_window(ax, ay);
369 int PluginDialog::attach_new(int number)
371 if(number >= 0 && number < plugindb.size())
373 strcpy(thread->plugin_title, plugindb.values[number]->title);
374 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
379 int PluginDialog::attach_shared(int number)
381 if(number >= 0 && number < plugin_locations.size())
383 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
384 thread->shared_location = *(plugin_locations.values[number]); // copy location
389 int PluginDialog::attach_module(int number)
391 if(number >= 0 && number < module_locations.size())
393 // title->update(module_data.values[number]->get_text());
394 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
395 thread->shared_location = *(module_locations.values[number]); // copy location
400 void PluginDialog::save_settings()
405 void PluginDialog::clear_selection()
407 standalone_list->set_all_selected(&standalone_data, 0);
408 standalone_list->draw_items(1);
409 shared_list->set_all_selected(&shared_data, 0);
410 shared_list->draw_items(1);
411 module_list->set_all_selected(&module_data, 0);
412 module_list->draw_items(1);
413 selected_available = -1;
414 selected_shared = -1;
415 selected_modules = -1;
417 thread->plugin_type = PLUGIN_NONE;
420 void PluginDialog::apply()
422 if( selected_available >= 0 ) {
423 attach_new(selected_available);
425 else if( selected_shared >= 0 ) {
426 attach_shared(selected_shared);
428 else if( selected_modules >= 0 ) {
429 attach_module(selected_modules);
435 void PluginDialogThread::apply()
438 mwindow->edl->session->single_standalone = single_standalone;
440 mwindow->gui->lock_window("PluginDialogThread::run 3");
441 mwindow->undo->update_undo_before();
443 mwindow->insert_effect(plugin_title, &shared_location,
444 data_type, plugin_type, single_standalone);
448 if( mwindow->edl->tracks->plugin_exists(plugin) ) {
449 plugin->change_plugin(plugin_title,
450 &shared_location, plugin_type);
454 if( mwindow->edl->tracks->track_exists(track) ) {
455 mwindow->insert_effect(plugin_title, &shared_location,
456 track, 0, 0, 0, plugin_type);
461 mwindow->save_backup();
462 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
463 mwindow->restart_brender();
464 mwindow->update_plugin_states();
465 mwindow->sync_parameters(CHANGE_EDL);
466 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
467 mwindow->gui->unlock_window();
472 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
473 : BC_GenericButton(x, y, _("Apply"))
475 this->dialog = dialog;
478 int PluginDialogApply::handle_event()
481 dialog->clear_selection();
491 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
492 // : BC_TextBox(x, y, xS(200), 1, text)
494 // this->dialog = dialog;
496 // PluginDialogTextBox::~PluginDialogTextBox()
498 // int PluginDialogTextBox::handle_event()
501 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
502 // : BC_GenericButton(x, y, _("Detach"))
504 // this->dialog = dialog;
506 // PluginDialogDetach::~PluginDialogDetach()
508 // int PluginDialogDetach::handle_event()
510 // // dialog->title->update(_("None"));
511 // dialog->thread->plugin_type = 0; // type is none
512 // 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);
581 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
582 ArrayList<BC_ListBoxItem*> *shared_data,
583 int x, int y, int w, int h)
584 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, shared_data)
586 this->dialog = dialog;
588 PluginDialogShared::~PluginDialogShared() { }
589 int PluginDialogShared::handle_event()
591 // dialog->attach_shared(get_selection_number(0, 0));
596 int PluginDialogShared::selection_changed()
598 dialog->selected_shared = get_selection_number(0, 0);
601 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
602 dialog->standalone_list->draw_items(1);
603 dialog->module_list->set_all_selected(&dialog->module_data, 0);
604 dialog->module_list->draw_items(1);
605 dialog->selected_available = -1;
606 dialog->selected_modules = -1;
610 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
611 // PluginDialog *dialog,
614 // : BC_GenericButton(x, y, _("Attach"))
616 // this->dialog = dialog;
618 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
619 // int PluginDialogAttachShared::handle_event()
621 // dialog->attach_shared(dialog->selected_shared);
626 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
627 // PluginDialog *dialog,
630 // : BC_GenericButton(x, y, _("Change"))
632 // this->dialog = dialog;
634 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
635 // int PluginDialogChangeShared::handle_event()
637 // dialog->attach_shared(dialog->selected_shared);
654 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
655 ArrayList<BC_ListBoxItem*> *module_data,
656 int x, int y, int w, int h)
657 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, module_data)
659 this->dialog = dialog;
661 PluginDialogModules::~PluginDialogModules() { }
662 int PluginDialogModules::handle_event()
664 // dialog->attach_module(get_selection_number(0, 0));
670 int PluginDialogModules::selection_changed()
672 dialog->selected_modules = get_selection_number(0, 0);
675 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
676 dialog->standalone_list->draw_items(1);
677 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
678 dialog->shared_list->draw_items(1);
679 dialog->selected_available = -1;
680 dialog->selected_shared = -1;
684 void PluginDialog::load_plugin_list(int redraw)
686 standalone_data.remove_all_objects();
687 const char *text = search_text->get_text();
689 for( int i=0; i<plugindb.total; ++i ) {
690 const char *title = _(plugindb.values[i]->title);
691 if( text && text[0] && !bstrcasestr(title, text) ) continue;
692 standalone_data.append(new PluginDialogListItem(title, i));
696 standalone_list->draw_items(1);
699 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
700 : BC_TextBox(x, y, w, 1, "")
702 this->dialog = dialog;
705 int PluginDialogSearchText::handle_event()
707 dialog->load_plugin_list(1);
711 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
712 : BC_CheckBox(x, y, dialog->thread->single_standalone,
713 _("Attach single standalone and share others"))
715 this->dialog = dialog;
718 int PluginDialogSingle::handle_event()
720 dialog->thread->single_standalone = get_value();
725 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
726 // PluginDialog *dialog,
729 // : BC_GenericButton(x, y, _("Attach"))
731 // this->dialog = dialog;
733 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
734 // int PluginDialogAttachModule::handle_event()
736 // dialog->attach_module(dialog->selected_modules);
741 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
742 // PluginDialog *dialog,
745 // : BC_GenericButton(x, y, _("Change"))
747 // this->dialog = dialog;
749 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
750 // int PluginDialogChangeModule::handle_event()
752 // dialog->attach_module(dialog->selected_modules);