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)
111 PluginDialog *dialog = (PluginDialog *)get_gui();
117 void PluginDialogThread::handle_close_event(int result)
125 PluginDialog::PluginDialog(MWindow *mwindow,
126 PluginDialogThread *thread,
127 const char *window_title,
130 : BC_Window(window_title,
133 mwindow->session->plugindialog_w,
134 mwindow->session->plugindialog_h,
141 this->mwindow = mwindow;
142 this->thread = thread;
143 single_standalone = 0;
146 PluginDialog::~PluginDialog()
148 lock_window("PluginDialog::~PluginDialog");
149 standalone_data.remove_all_objects();
151 shared_data.remove_all_objects();
153 module_data.remove_all_objects();
155 plugin_locations.remove_all_objects();
157 module_locations.remove_all_objects();
159 delete standalone_list;
165 void PluginDialog::create_objects()
167 // int use_default = 1;
168 mwindow->theme->get_plugindialog_sizes();
169 lock_window("PluginDialog::create_objects");
171 // GET A LIST OF ALL THE PLUGINS AVAILABLE
172 mwindow->search_plugindb(thread->data_type == TRACK_AUDIO,
173 thread->data_type == TRACK_VIDEO,
176 mwindow->edl->get_shared_plugins(thread->track,
180 mwindow->edl->get_shared_tracks(thread->track,
185 // Construct listbox items
186 for(int i = 0; i < plugin_locations.total; )
188 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
189 char *track_title = track->title;
190 int number = plugin_locations.values[i]->plugin;
191 double start = mwindow->edl->local_session->get_selectionstart(1);
192 Plugin *plugin = track->get_current_plugin(start, number, PLAY_FORWARD, 1, 0);
193 if( !plugin ) { plugin_locations.remove_object_number(i); continue; }
194 char string[BCTEXTLEN];
195 const char *plugin_title = _(plugin->title);
196 snprintf(string, sizeof(string), "%s: %s", track_title, plugin_title);
197 shared_data.append(new BC_ListBoxItem(string));
200 for(int i = 0; i < module_locations.total; i++)
202 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
203 module_data.append(new BC_ListBoxItem(track->title));
211 add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x,
212 mwindow->theme->plugindialog_new_y - 20,
214 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
215 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
216 add_subwindow(search_text = new PluginDialogSearchText(this, x1, y1, w1));
217 int dy = search_text->get_h() + 10;
221 add_subwindow(standalone_list = new PluginDialogNew(this,
222 &standalone_data, x1, y1, w1, h1));
224 // if(thread->plugin)
225 // add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
227 // mwindow->theme->plugindialog_newattach_x,
228 // mwindow->theme->plugindialog_newattach_y));
230 // add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow,
232 // mwindow->theme->plugindialog_newattach_x,
233 // mwindow->theme->plugindialog_newattach_y));
236 add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x,
237 mwindow->theme->plugindialog_shared_y - 20,
238 _("Shared effects:")));
239 add_subwindow(shared_list = new PluginDialogShared(this,
241 mwindow->theme->plugindialog_shared_x,
242 mwindow->theme->plugindialog_shared_y,
243 mwindow->theme->plugindialog_shared_w,
244 mwindow->theme->plugindialog_shared_h));
245 // if(thread->plugin)
246 // add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
248 // mwindow->theme->plugindialog_sharedattach_x,
249 // mwindow->theme->plugindialog_sharedattach_y));
251 // add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow,
253 // mwindow->theme->plugindialog_sharedattach_x,
254 // mwindow->theme->plugindialog_sharedattach_y));
257 add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x,
258 mwindow->theme->plugindialog_module_y - 20,
259 _("Shared tracks:")));
260 add_subwindow(module_list = new PluginDialogModules(this,
262 mwindow->theme->plugindialog_module_x,
263 mwindow->theme->plugindialog_module_y,
264 mwindow->theme->plugindialog_module_w,
265 mwindow->theme->plugindialog_module_h));
266 // if(thread->plugin)
267 // add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
269 // mwindow->theme->plugindialog_moduleattach_x,
270 // mwindow->theme->plugindialog_moduleattach_y));
272 // add_subwindow(module_attach = new PluginDialogAttachModule(mwindow,
274 // mwindow->theme->plugindialog_moduleattach_x,
275 // mwindow->theme->plugindialog_moduleattach_y));
279 // Add option for the menu invocation
280 // add_subwindow(file_title = new BC_Title(
281 // mwindow->theme->menueffect_file_x,
282 // mwindow->theme->menueffect_file_y,
283 // _("One standalone effect is attached to the first track.\n"
284 // "Shared effects are attached to the remaining tracks.")));
286 if(thread->is_mainmenu)
287 add_subwindow(single_standalone = new PluginDialogSingle(this,
288 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
289 mwindow->theme->plugindialog_new_y +
290 mwindow->theme->plugindialog_new_h +
291 get_text_height(MEDIUMFONT)));
295 add_subwindow(ok_btn = new BC_OKButton(this));
296 add_subwindow(can_btn = new BC_CancelButton(this));
297 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
298 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
299 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
300 add_subwindow(apy_btn = new PluginDialogApply(this, ax, ay));
301 selected_available = -1;
302 selected_shared = -1;
303 selected_modules = -1;
310 int PluginDialog::resize_event(int w, int h)
312 mwindow->session->plugindialog_w = w;
313 mwindow->session->plugindialog_h = h;
314 mwindow->theme->get_plugindialog_sizes();
317 standalone_title->reposition_window(mwindow->theme->plugindialog_new_x,
318 mwindow->theme->plugindialog_new_y - 20);
319 int x1 = mwindow->theme->plugindialog_new_x, y1 = mwindow->theme->plugindialog_new_y;
320 int w1 = mwindow->theme->plugindialog_new_w, h1 = mwindow->theme->plugindialog_new_h;
321 search_text->reposition_window(x1, y1, w1);
322 int dy = search_text->get_h() + 10;
324 standalone_list->reposition_window(x1, y1, w1, h1);
326 // if(standalone_attach)
327 // standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x,
328 // mwindow->theme->plugindialog_newattach_y);
330 // standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
331 // mwindow->theme->plugindialog_newattach_y);
333 shared_title->reposition_window(mwindow->theme->plugindialog_shared_x,
334 mwindow->theme->plugindialog_shared_y - 20);
335 shared_list->reposition_window(mwindow->theme->plugindialog_shared_x,
336 mwindow->theme->plugindialog_shared_y,
337 mwindow->theme->plugindialog_shared_w,
338 mwindow->theme->plugindialog_shared_h);
340 // shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
341 // mwindow->theme->plugindialog_sharedattach_y);
343 // shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
344 // mwindow->theme->plugindialog_sharedattach_y);
350 module_title->reposition_window(mwindow->theme->plugindialog_module_x,
351 mwindow->theme->plugindialog_module_y - 20);
352 module_list->reposition_window(mwindow->theme->plugindialog_module_x,
353 mwindow->theme->plugindialog_module_y,
354 mwindow->theme->plugindialog_module_w,
355 mwindow->theme->plugindialog_module_h);
357 // module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
358 // mwindow->theme->plugindialog_moduleattach_y);
360 // module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
361 // mwindow->theme->plugindialog_moduleattach_y);
364 if(single_standalone)
365 single_standalone->reposition_window(
366 mwindow->theme->plugindialog_new_x + BC_OKButton::calculate_w() + 10,
367 mwindow->theme->plugindialog_new_y + mwindow->theme->plugindialog_new_h +
368 get_text_height(MEDIUMFONT));
370 int aw = PluginDialogApply::calculate_w(this, _("Apply"));
371 int ax = (ok_btn->get_x()+can_btn->get_x()-aw) / 2;
372 int ay = ok_btn->get_y() + ok_btn->get_h() - PluginDialogApply::calculate_h();
373 apy_btn->reposition_window(ax, ay);
379 int PluginDialog::attach_new(int number)
381 if(number >= 0 && number < plugindb.size())
383 strcpy(thread->plugin_title, plugindb.values[number]->title);
384 thread->plugin_type = PLUGIN_STANDALONE; // type is plugin
389 int PluginDialog::attach_shared(int number)
391 if(number >= 0 && number < plugin_locations.size())
393 thread->plugin_type = PLUGIN_SHAREDPLUGIN; // type is shared plugin
394 thread->shared_location = *(plugin_locations.values[number]); // copy location
399 int PluginDialog::attach_module(int number)
401 if(number >= 0 && number < module_locations.size())
403 // title->update(module_data.values[number]->get_text());
404 thread->plugin_type = PLUGIN_SHAREDMODULE; // type is module
405 thread->shared_location = *(module_locations.values[number]); // copy location
410 void PluginDialog::save_settings()
415 void PluginDialog::apply()
417 if( selected_available >= 0 ) {
418 attach_new(selected_available);
420 else if( selected_shared >= 0 ) {
421 attach_shared(selected_shared);
423 else if( selected_modules >= 0 ) {
424 attach_module(selected_modules);
430 void PluginDialogThread::apply()
433 mwindow->edl->session->single_standalone = single_standalone;
435 mwindow->gui->lock_window("PluginDialogThread::run 3");
436 mwindow->undo->update_undo_before();
438 mwindow->insert_effect(plugin_title, &shared_location,
439 data_type, plugin_type, single_standalone);
443 if( mwindow->edl->tracks->plugin_exists(plugin) ) {
444 plugin->change_plugin(plugin_title,
445 &shared_location, plugin_type);
449 if( mwindow->edl->tracks->track_exists(track) ) {
450 mwindow->insert_effect(plugin_title, &shared_location,
451 track, 0, 0, 0, plugin_type);
456 mwindow->save_backup();
457 mwindow->undo->update_undo_after(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
458 mwindow->restart_brender();
459 mwindow->update_plugin_states();
460 mwindow->sync_parameters(CHANGE_EDL);
461 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
462 mwindow->gui->unlock_window();
467 PluginDialogApply::PluginDialogApply(PluginDialog *dialog, int x, int y)
468 : BC_GenericButton(x, y, _("Apply"))
470 this->dialog = dialog;
473 int PluginDialogApply::handle_event()
485 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
486 // : BC_TextBox(x, y, 200, 1, text)
488 // this->dialog = dialog;
490 // PluginDialogTextBox::~PluginDialogTextBox()
492 // int PluginDialogTextBox::handle_event()
495 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
496 // : BC_GenericButton(x, y, _("Detach"))
498 // this->dialog = dialog;
500 // PluginDialogDetach::~PluginDialogDetach()
502 // int PluginDialogDetach::handle_event()
504 // // dialog->title->update(_("None"));
505 // dialog->thread->plugin_type = 0; // type is none
506 // dialog->thread->plugin_title[0] = 0;
523 PluginDialogNew::PluginDialogNew(PluginDialog *dialog,
524 ArrayList<BC_ListBoxItem*> *standalone_data,
525 int x, int y, int w, int h)
526 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, standalone_data)
528 this->dialog = dialog;
531 PluginDialogNew::~PluginDialogNew() { }
532 int PluginDialogNew::handle_event()
534 // dialog->attach_new(get_selection_number(0, 0));
540 int PluginDialogNew::selection_changed()
542 int no = get_selection_number(0, 0);
543 dialog->selected_available = no >= 0 && no < dialog->standalone_data.size() ?
544 ((PluginDialogListItem *)dialog->standalone_data[no])->item_no : -1;
545 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
546 dialog->shared_list->draw_items(1);
547 dialog->selected_shared = -1;
548 dialog->module_list->set_all_selected(&dialog->module_data, 0);
549 dialog->module_list->draw_items(1);
550 dialog->selected_modules = -1;
554 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
555 // : BC_GenericButton(x, y, _("Attach"))
557 // this->dialog = dialog;
559 // PluginDialogAttachNew::~PluginDialogAttachNew()
562 // int PluginDialogAttachNew::handle_event()
564 // dialog->attach_new(dialog->selected_available);
569 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
570 // : BC_GenericButton(x, y, _("Change"))
572 // this->dialog = dialog;
574 // PluginDialogChangeNew::~PluginDialogChangeNew()
577 // int PluginDialogChangeNew::handle_event()
579 // dialog->attach_new(dialog->selected_available);
593 PluginDialogShared::PluginDialogShared(PluginDialog *dialog,
594 ArrayList<BC_ListBoxItem*> *shared_data,
606 this->dialog = dialog;
608 PluginDialogShared::~PluginDialogShared() { }
609 int PluginDialogShared::handle_event()
611 // dialog->attach_shared(get_selection_number(0, 0));
616 int PluginDialogShared::selection_changed()
618 dialog->selected_shared = get_selection_number(0, 0);
621 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
622 dialog->standalone_list->draw_items(1);
623 dialog->module_list->set_all_selected(&dialog->module_data, 0);
624 dialog->module_list->draw_items(1);
625 dialog->selected_available = -1;
626 dialog->selected_modules = -1;
630 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow,
631 // PluginDialog *dialog,
634 // : BC_GenericButton(x, y, _("Attach"))
636 // this->dialog = dialog;
638 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
639 // int PluginDialogAttachShared::handle_event()
641 // dialog->attach_shared(dialog->selected_shared);
646 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
647 // PluginDialog *dialog,
650 // : BC_GenericButton(x, y, _("Change"))
652 // this->dialog = dialog;
654 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
655 // int PluginDialogChangeShared::handle_event()
657 // dialog->attach_shared(dialog->selected_shared);
674 PluginDialogModules::PluginDialogModules(PluginDialog *dialog,
675 ArrayList<BC_ListBoxItem*> *module_data,
687 this->dialog = dialog;
689 PluginDialogModules::~PluginDialogModules() { }
690 int PluginDialogModules::handle_event()
692 // dialog->attach_module(get_selection_number(0, 0));
698 int PluginDialogModules::selection_changed()
700 dialog->selected_modules = get_selection_number(0, 0);
703 dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
704 dialog->standalone_list->draw_items(1);
705 dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
706 dialog->shared_list->draw_items(1);
707 dialog->selected_available = -1;
708 dialog->selected_shared = -1;
712 void PluginDialog::load_plugin_list(int redraw)
714 standalone_data.remove_all_objects();
715 const char *text = search_text->get_text();
717 for( int i=0; i<plugindb.total; ++i ) {
718 const char *title = _(plugindb.values[i]->title);
719 if( text && text[0] && !bstrcasestr(title, text) ) continue;
720 standalone_data.append(new PluginDialogListItem(title, i));
724 standalone_list->draw_items(1);
727 PluginDialogSearchText::PluginDialogSearchText(PluginDialog *dialog, int x, int y, int w)
728 : BC_TextBox(x, y, w, 1, "")
730 this->dialog = dialog;
733 int PluginDialogSearchText::handle_event()
735 dialog->load_plugin_list(1);
739 PluginDialogSingle::PluginDialogSingle(PluginDialog *dialog, int x, int y)
742 dialog->thread->single_standalone,
743 _("Attach single standalone and share others"))
745 this->dialog = dialog;
748 int PluginDialogSingle::handle_event()
750 dialog->thread->single_standalone = get_value();
755 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow,
756 // PluginDialog *dialog,
759 // : BC_GenericButton(x, y, _("Attach"))
761 // this->dialog = dialog;
763 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
764 // int PluginDialogAttachModule::handle_event()
766 // dialog->attach_module(dialog->selected_modules);
771 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
772 // PluginDialog *dialog,
775 // : BC_GenericButton(x, y, _("Change"))
777 // this->dialog = dialog;
779 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
780 // int PluginDialogChangeModule::handle_event()
782 // dialog->attach_module(dialog->selected_modules);