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;
140 // *** CONTEXT_HELP ***
141 switch( thread->data_type ) {
143 context_help_set_keyword("Audio Effects");
146 context_help_set_keyword("Video Effects");
149 context_help_set_keyword("How to Use Plugins");
154 PluginDialog::~PluginDialog()
156 lock_window("PluginDialog::~PluginDialog");
157 standalone_data.remove_all_objects();
159 shared_data.remove_all_objects();
161 module_data.remove_all_objects();
163 plugin_locations.remove_all_objects();
165 module_locations.remove_all_objects();
167 delete standalone_list;
173 void PluginDialog::create_objects()
176 int ys10 = yS(10), ys20 = yS(20);
177 // int use_default = 1;
178 mwindow->theme->get_plugindialog_sizes();
179 lock_window("PluginDialog::create_objects");
181 // GET A LIST OF ALL THE PLUGINS AVAILABLE
182 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
183 thread->data_type == TRACK_VIDEO,
186 mwindow->edl->get_shared_plugins(thread->track,
190 mwindow->edl->get_shared_tracks(thread->track,
195 // Construct listbox items
196 for(int i = 0; i < plugin_locations.total; )
198 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
199 char *track_title = track->title;
200 int number = plugin_locations.values[i]->plugin;
201 double start = mwindow->edl->local_session->get_selectionstart(1);
202 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
203 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
204 char string[BCTEXTLEN];
205 const char *plugin_title = _(plugin->title);
206 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
207 shared_data.append(new BC_ListBoxItem(string));
210 for(int i = 0; i < module_locations.total; i++)
212 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
213 module_data.append(new BC_ListBoxItem(track->title));
217 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
218 mwindow->theme->plugindialog_new_y - ys20,
220 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
221 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
222 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
223 int dy = search_text->get_h() + ys10;
227 add_subwindow(standalone_list = new PluginDialogNew(this,
228 &standalone_data, x1, y1, w1, h1));
230 // if(thread->plugin)
231 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
233 // mwindow->theme->plugindialog_newattach_x,
234 // mwindow->theme->plugindialog_newattach_y));
236 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
238 // mwindow->theme->plugindialog_newattach_x,
239 // mwindow->theme->plugindialog_newattach_y));
242 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
243 mwindow->theme->plugindialog_shared_y - ys20,
244 _("Shared effects:")));
245 add_subwindow(shared_list = new PluginDialogShared(this,
247 mwindow->theme->plugindialog_shared_x,
248 mwindow->theme->plugindialog_shared_y,
249 mwindow->theme->plugindialog_shared_w,
250 mwindow->theme->plugindialog_shared_h));
251 // if(thread->plugin)
252 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
254 // mwindow->theme->plugindialog_sharedattach_x,
255 // mwindow->theme->plugindialog_sharedattach_y));
257 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
259 // mwindow->theme->plugindialog_sharedattach_x,
260 // mwindow->theme->plugindialog_sharedattach_y));
263 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
264 mwindow->theme->plugindialog_module_y - ys20,
265 _("Shared tracks:")));
266 add_subwindow(module_list = new PluginDialogModules(this,
268 mwindow->theme->plugindialog_module_x,
269 mwindow->theme->plugindialog_module_y,
270 mwindow->theme->plugindialog_module_w,
271 mwindow->theme->plugindialog_module_h));
272 // if(thread->plugin)
273 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
275 // mwindow->theme->plugindialog_moduleattach_x,
276 // mwindow->theme->plugindialog_moduleattach_y));
278 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
280 // mwindow->theme->plugindialog_moduleattach_x,
281 // mwindow->theme->plugindialog_moduleattach_y));
285 // Add option for the menu invocation
286 // add_subwindow(file_title = new BC_Title(
287 // mwindow->theme->menueffect_file_x,
288 // mwindow->theme->menueffect_file_y,
289 // _("One standalone effect is attached to the first track.\n"
290 // "Shared effects are attached to the remaining tracks.")));
292 if(thread->is_mainmenu)
293 add_subwindow(single_standalone = new PluginDialogSingle(this,
294 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + xs10,
295 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
296 get_text_height(MEDIUMFONT)));
298 add_subwindow(ok_btn = new BC_OKButton(this));
299 add_subwindow(can_btn = new BC_CancelButton(this));
300 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
301 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
302 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
303 add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
304 selected_available = -1;
305 selected_shared = -1;
306 selected_modules = -1;
313 int PluginDialog::resize_event(int w, int h)
315 int ys10 = yS(10), ys20 = yS(20);
316 mwindow->session->plugindialog_w = w;
317 mwindow->session->plugindialog_h = h;
318 mwindow->theme->get_plugindialog_sizes();
320 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
321 mwindow->theme->plugindialog_new_y - ys20);
322 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
323 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
324 search_text->reposition_window(x1, y1, w1);
325 int dy = search_text->get_h() + ys10;
327 standalone_list->reposition_window(x1, y1, w1, h1);
329 // if(standalone_attach)
330 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
331 // mwindow->theme->plugindialog_newattach_y);
333 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
334 // mwindow->theme->plugindialog_newattach_y);
336 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
337 mwindow->theme->plugindialog_shared_y - ys20);
338 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
339 mwindow->theme->plugindialog_shared_y,
340 mwindow->theme->plugindialog_shared_w,
341 mwindow->theme->plugindialog_shared_h);
343 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
344 // mwindow->theme->plugindialog_sharedattach_y);
346 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
347 // mwindow->theme->plugindialog_sharedattach_y);
353 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
354 mwindow->theme->plugindialog_module_y - ys20);
355 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
356 mwindow->theme->plugindialog_module_y,
357 mwindow->theme->plugindialog_module_w,
358 mwindow->theme->plugindialog_module_h);
360 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
361 // mwindow->theme->plugindialog_moduleattach_y);
363 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
364 // mwindow->theme->plugindialog_moduleattach_y);
367 if(single_standalone)
368 single_standalone->reposition_window(
369 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + ys10,
370 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
371 get_text_height(MEDIUMFONT));
373 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
374 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
375 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
376 apy_btn->reposition_window(ax, ay);
382 int PluginDialog::attach_new(int number)
384 if(number >= 0 && number < plugindb.size())
386 strcpy(thread->plugin_title, plugindb.values[number]->title);
387 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
392 int PluginDialog::attach_shared(int number)
394 if(number >= 0 && number < plugin_locations.size())
396 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
397 thread->shared_location = *(plugin_locations.values[number]); // copy location
402 int PluginDialog::attach_module(int number)
404 if(number >= 0 && number < module_locations.size())
406 // title->update(module_data.values[number]->get_text());
407 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
408 thread->shared_location = *(module_locations.values[number]); // copy location
413 void PluginDialog::save_settings()
418 void PluginDialog::clear_selection()
420 standalone_list->set_all_selected(&standalone_data, 0);
421 standalone_list->draw_items(1);
422 shared_list->set_all_selected(&shared_data, 0);
423 shared_list->draw_items(1);
424 module_list->set_all_selected(&module_data, 0);
425 module_list->draw_items(1);
426 selected_available = -1;
427 selected_shared = -1;
428 selected_modules = -1;
429 thread->plugin_id = -1;
430 thread->plugin_type = PLUGIN_NONE;
433 void PluginDialog::apply()
435 if( selected_available >= 0 ) {
436 attach_new(selected_available);
438 else if( selected_shared >= 0 ) {
439 attach_shared(selected_shared);
441 else if( selected_modules >= 0 ) {
442 attach_module(selected_modules);
448 void PluginDialogThread::apply()
451 EDL *edl = mwindow->edl;
453 edl->session->single_standalone = single_standalone;
455 mwindow->gui->lock_window("PluginDialogThread::run 3");
456 mwindow->undo->update_undo_before();
458 mwindow->insert_effect(plugin_title, &shared_location,
459 data_type, plugin_type, single_standalone);
461 else if( (plugin=edl->tracks->plugin_exists(plugin_id)) != 0 ) {
462 plugin->change_plugin(plugin_title,
463 &shared_location, plugin_type);
465 else if( edl->tracks->track_exists(track) ) {
466 double start = edl->local_session->get_selectionstart();
467 double end = edl->local_session->get_selectionend();
470 end = track->get_length();
472 double length = end - start;
473 mwindow->insert_effect(plugin_title, &shared_location,
474 track, 0, start, length, plugin_type);
477 mwindow->save_backup();
478 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
479 mwindow->restart_brender();
480 mwindow->update_plugin_states();
481 mwindow->sync_parameters(CHANGE_EDL);
482 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
483 mwindow->gui->unlock_window();
488 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
489 : BC_GenericButton(x, y, _("Apply"))
491 this->dialog = dialog;
494 int PluginDialogApply::handle_event()
497 dialog->clear_selection();
507 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
508 // : BC_TextBox(x, y, xS(200), 1, text)
510 // this->dialog = dialog;
512 // PluginDialogTextBox::~PluginDialogTextBox()
514 // int PluginDialogTextBox::handle_event()
517 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
518 // : BC_GenericButton(x, y, _("Detach"))
520 // this->dialog = dialog;
522 // PluginDialogDetach::~PluginDialogDetach()
524 // int PluginDialogDetach::handle_event()
526 // // dialog->title->update(_("None"));
527 // dialog->thread->plugin_type = 0; // type is none
528 // dialog->thread->plugin_title[0] = 0;
535 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
536 ArrayList<BC_ListBoxItem*> *standalone_data,
537 int x, int y, int w, int h)
538 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
540 this->dialog = dialog;
543 PluginDialogNew::~PluginDialogNew() { }
544 int PluginDialogNew::handle_event()
546 // dialog->attach_new(get_selection_number(0, 0));
552 int PluginDialogNew::selection_changed()
554 int no = get_selection_number(0, 0);
555 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
556 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
557 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
558 dialog->shared_list->draw_items(1);
559 dialog->selected_shared = -1;
560 dialog->module_list->set_all_selected(&dialog->module_data, 0);
561 dialog->module_list->draw_items(1);
562 dialog->selected_modules = -1;
566 // *** CONTEXT_HELP ***
567 int PluginDialogNew::keypress_event()
570 char title[BCTEXTLEN];
571 PluginServer *plugin = 0;
573 // printf("PluginDialogNew::keypress_event: %d\n", get_keypress());
575 // If not our context help keystroke, redispatch it
576 // to the event handler of the base class
577 if (get_keypress() != 'h' || ! alt_down() ||
578 ! is_tooltip_event_win() || ! cursor_inside())
579 return BC_ListBox::keypress_event();
581 // Try to show help for the plugin currently under mouse
582 item = get_highlighted_item();
583 if (item >= 0 && item < dialog->standalone_data.size()) {
584 plugin_no = ((PluginDialogListItem *)dialog->standalone_data[item])->item_no;
585 if (plugin_no >= 0 && plugin_no < dialog->plugindb.total)
586 plugin = dialog->plugindb.values[plugin_no];
589 // If some plugin is highlighted, show its help
590 // Otherwise show more general help
592 strcpy(title, plugin->title);
593 if (! strcmp(title, "Overlay")) {
594 // "Overlay" plugin title is ambiguous
595 if (plugin->audio) strcat(title, " \\(Audio\\)");
596 if (plugin->video) strcat(title, " \\(Video\\)");
598 if (plugin->is_ffmpeg()) {
599 // FFmpeg plugins can be audio or video
601 strcpy(title, "FFmpeg Audio Plugins");
603 strcpy(title, "FFmpeg Video Plugins");
605 context_help_show(title);
609 switch (dialog->thread->data_type) {
611 context_help_show("Audio Effects");
614 context_help_show("Video Effects");
617 context_help_show("How to Use Plugins");
620 context_help_show("How to Use Plugins");
623 context_help_show("How to Use Plugins");
627 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
628 // : BC_GenericButton(x, y, _("Attach"))
630 // this->dialog = dialog;
632 // PluginDialogAttachNew::~PluginDialogAttachNew()
635 // int PluginDialogAttachNew::handle_event()
637 // dialog->attach_new(dialog->selected_available);
642 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
643 // : BC_GenericButton(x, y, _("Change"))
645 // this->dialog = dialog;
647 // PluginDialogChangeNew::~PluginDialogChangeNew()
650 // int PluginDialogChangeNew::handle_event()
652 // dialog->attach_new(dialog->selected_available);
658 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
659 ArrayList<BC_ListBoxItem*> *shared_data,
660 int x, int y, int w, int h)
661 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, shared_data)
663 this->dialog = dialog;
664 context_help_set_keyword("Shared Effects and Shared Tracks");
666 PluginDialogShared::~PluginDialogShared() { }
667 int PluginDialogShared::handle_event()
669 // dialog->attach_shared(get_selection_number(0, 0));
674 int PluginDialogShared::selection_changed()
676 dialog->selected_shared = get_selection_number(0, 0);
679 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
680 dialog->standalone_list->draw_items(1);
681 dialog->module_list->set_all_selected(&dialog->module_data, 0);
682 dialog->module_list->draw_items(1);
683 dialog->selected_available = -1;
684 dialog->selected_modules = -1;
688 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
689 // PluginDialog *dialog,
692 // : BC_GenericButton(x, y, _("Attach"))
694 // this->dialog = dialog;
696 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
697 // int PluginDialogAttachShared::handle_event()
699 // dialog->attach_shared(dialog->selected_shared);
704 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
705 // PluginDialog *dialog,
708 // : BC_GenericButton(x, y, _("Change"))
710 // this->dialog = dialog;
712 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
713 // int PluginDialogChangeShared::handle_event()
715 // dialog->attach_shared(dialog->selected_shared);
732 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
733 ArrayList<BC_ListBoxItem*> *module_data,
734 int x, int y, int w, int h)
735 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, module_data)
737 this->dialog = dialog;
738 context_help_set_keyword("Shared Effects and Shared Tracks");
740 PluginDialogModules::~PluginDialogModules() { }
741 int PluginDialogModules::handle_event()
743 // dialog->attach_module(get_selection_number(0, 0));
749 int PluginDialogModules::selection_changed()
751 dialog->selected_modules = get_selection_number(0, 0);
754 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
755 dialog->standalone_list->draw_items(1);
756 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
757 dialog->shared_list->draw_items(1);
758 dialog->selected_available = -1;
759 dialog->selected_shared = -1;
763 void PluginDialog::load_plugin_list(int redraw)
765 standalone_data.remove_all_objects();
766 const char *text = search_text->get_text();
768 for( int i=0; i<plugindb.total; ++i ) {
769 const char *title = _(plugindb.values[i]->title);
770 if( text && text[0] && !bstrcasestr(title, text) ) continue;
771 standalone_data.append(new PluginDialogListItem(title, i));
775 standalone_list->draw_items(1);
778 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
779 : BC_TextBox(x, y, w, 1, "")
781 this->dialog = dialog;
784 int PluginDialogSearchText::handle_event()
786 dialog->load_plugin_list(1);
790 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
791 : BC_CheckBox(x, y, dialog->thread->single_standalone,
792 _("Attach single standalone and share others"))
794 this->dialog = dialog;
795 context_help_set_keyword("Shared Effects and Shared Tracks");
798 int PluginDialogSingle::handle_event()
800 dialog->thread->single_standalone = get_value();
805 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
806 // PluginDialog *dialog,
809 // : BC_GenericButton(x, y, _("Attach"))
811 // this->dialog = dialog;
813 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
814 // int PluginDialogAttachModule::handle_event()
816 // dialog->attach_module(dialog->selected_modules);
821 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
822 // PluginDialog *dialog,
825 // : BC_GenericButton(x, y, _("Change"))
827 // this->dialog = dialog;
829 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
830 // int PluginDialogChangeModule::handle_event()
832 // dialog->attach_module(dialog->selected_modules);