r954: Improve icons of the liveaudio and livevideo effects.
[cinelerra_cv.git] / cinelerra / plugindialog.C
blob0b9e184ab41e2be96ef4f1923d966f0ba6861caa
1 #include "condition.h"
2 #include "edl.h"
3 #include "language.h"
4 #include "localsession.h"
5 #include "mainsession.h"
6 #include "mainundo.h"
7 #include "mwindow.h"
8 #include "mwindowgui.h"
9 #include "module.h"
10 #include "mutex.h"
11 #include "plugin.h"
12 #include "plugindialog.h"
13 #include "pluginserver.h"
14 #include "theme.h"
15 #include "track.h"
16 #include "tracks.h"
17 #include "transition.h"
20 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
21  : Thread()
23         this->mwindow = mwindow;
24         window = 0;
25         plugin = 0;
26         Thread::set_synchronous(0);
27         window_lock = new Mutex("PluginDialogThread::window_lock");
28         completion = new Condition(1, "PluginDialogThread::completion");
31 PluginDialogThread::~PluginDialogThread()
33         if(window)
34         {
35                 window->set_done(1);
36                 completion->lock("PluginDialogThread::~PluginDialogThread");
37                 completion->unlock();
38         }
39         delete window_lock;
40         delete completion;
43 void PluginDialogThread::start_window(Track *track,
44         Plugin *plugin, 
45         char *title)
47         if(Thread::running())
48         {
49                 window_lock->lock("PluginDialogThread::start_window");
50                 if(window)
51                 {
52                         window->lock_window("PluginDialogThread::start_window");
53                         window->raise_window();
54                         window->flush();
55                         window->unlock_window();
56                 }
57                 window_lock->unlock();
58         }
59         else
60         {
61                 this->track = track;
62                 this->data_type = track->data_type;
63                 this->plugin = plugin;
65                 if(plugin)
66                 {
67                         plugin->calculate_title(plugin_title, 0);
68                         this->shared_location = plugin->shared_location;
69                         this->plugin_type = plugin->plugin_type;
70                 }
71                 else
72                 {
73                         this->plugin_title[0] = 0;
74                         this->shared_location.plugin = -1;
75                         this->shared_location.module = -1;
76                         this->plugin_type = PLUGIN_NONE;
77                 }
79                 strcpy(this->window_title, title);
80                 completion->lock("PluginDialogThread::start_window");
81                 Thread::start();
82         }
86 int PluginDialogThread::set_dialog(Transition *transition, char *title)
88         return 0;
91 void PluginDialogThread::run()
93         int result = 0;
95         plugin_type = 0;
96         int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->session->plugindialog_w / 2;
97         int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->session->plugindialog_h / 2;
99         window_lock->lock("PluginDialogThread::run 1"); 
100         window = new PluginDialog(mwindow, this, window_title, x, y);
101         window->create_objects();
102         window_lock->unlock();
104         result = window->run_window();
107         window_lock->lock("PluginDialogThread::run 2");
109         if(window->selected_available >= 0)
110         {
111                 window->attach_new(window->selected_available);
112         }
113         else
114         if(window->selected_shared >= 0)
115         {
116                 window->attach_shared(window->selected_shared);
117         }
118         else
119         if(window->selected_modules >= 0)
120         {
121                 window->attach_module(window->selected_modules);
122         }
127         delete window;
128         window = 0;
129         window_lock->unlock();
131         completion->unlock();
133 // Done at closing
134         if(!result)
135         {
138                 if(plugin_type)
139                 {
140                         mwindow->gui->lock_window("PluginDialogThread::run 3");
143                         if(plugin)
144                         {
145                                 plugin->change_plugin(plugin_title,
146                                         &shared_location,
147                                         plugin_type);
148                         }
149                         else
150                         {
151                                 mwindow->insert_effect(plugin_title, 
152                                                                 &shared_location,
153                                                                 track,
154                                                                 0,
155                                                                 0,
156                                                                 0,
157                                                                 plugin_type);
158                         }
160                         
161                         mwindow->save_backup();
162                         mwindow->undo->update_undo(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
163                         mwindow->restart_brender();
164                         mwindow->update_plugin_states();
165                         mwindow->sync_parameters(CHANGE_EDL);
166                         mwindow->gui->update(1,
167                                 1,
168                                 0,
169                                 0,
170                                 1, 
171                                 0,
172                                 0);
174                         mwindow->gui->unlock_window();
175                 }
176         }
177         plugin = 0;
188 PluginDialog::PluginDialog(MWindow *mwindow, 
189         PluginDialogThread *thread, 
190         char *window_title,
191         int x,
192         int y)
193  : BC_Window(window_title, 
194         x,
195         y,
196         mwindow->session->plugindialog_w, 
197         mwindow->session->plugindialog_h, 
198         510, 
199         415,
200         1,
201         0,
202         1)
204         this->mwindow = mwindow;  
205         this->thread = thread;
206 //      standalone_attach = 0;
207 //      shared_attach = 0;
208 //      module_attach = 0;
209 //      standalone_change = 0;
210 //      shared_change = 0;
211 //      module_change = 0;
212         inoutthru = 0;
215 PluginDialog::~PluginDialog()
217         int i;
218         standalone_data.remove_all_objects();
219         
220         shared_data.remove_all_objects();
221         
222         module_data.remove_all_objects();
224         plugin_locations.remove_all_objects();
226         module_locations.remove_all_objects();
228 //      delete title;
229 //      delete detach;
230         delete standalone_list;
231         delete shared_list;
232         delete module_list;
233 //      if(standalone_attach) delete standalone_attach;
234 //      if(shared_attach) delete shared_attach;
235 //      if(module_attach) delete module_attach;
236 //      if(standalone_change) delete standalone_change;
237 //      if(shared_change) delete shared_change;
238 //      if(module_change) delete module_change;
239 //      delete in;
240 //      delete out;
243 int PluginDialog::create_objects()
245         int use_default = 1;
246         char string[BCTEXTLEN];
247         int module_number;
248         mwindow->theme->get_plugindialog_sizes();
250         if(thread->plugin)
251         {
252                 strcpy(string, thread->plugin->title);
253                 use_default = 1;
254         }
255         else
256         {
257 // no plugin
258                 sprintf(string, _("None"));
259         }
266 // GET A LIST OF ALL THE PLUGINS AVAILABLE
267         mwindow->create_plugindb(thread->data_type == TRACK_AUDIO, 
268                 thread->data_type == TRACK_VIDEO, 
269                 1, 
270                 0,
271                 0,
272                 plugindb);
274         mwindow->edl->get_shared_plugins(thread->track,
275                 &plugin_locations);
277         mwindow->edl->get_shared_tracks(thread->track,
278                 &module_locations);
287 // Construct listbox items
288         for(int i = 0; i < plugindb.total; i++)
289                 standalone_data.append(new BC_ListBoxItem(_(plugindb.values[i]->title)));
290         for(int i = 0; i < plugin_locations.total; i++)
291         {
292                 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
293                 char *track_title = track->title;
294                 int number = plugin_locations.values[i]->plugin;
295                 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->get_selectionstart(1), 
296                         number, 
297                         PLAY_FORWARD,
298                         1,
299                         0);
300                 char *plugin_title = plugin->title;
301                 char string[BCTEXTLEN];
303                 sprintf(string, "%s: %s", track_title, _(plugin_title));
304                 shared_data.append(new BC_ListBoxItem(string));
305         }
306         for(int i = 0; i < module_locations.total; i++)
307         {
308                 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
309                 module_data.append(new BC_ListBoxItem(track->title));
310         }
316 // Create widgets
317         add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x, 
318                 mwindow->theme->plugindialog_new_y - 20, 
319                 _("Plugins:")));
320         add_subwindow(standalone_list = new PluginDialogNew(this, 
321                 &standalone_data, 
322                 mwindow->theme->plugindialog_new_x, 
323                 mwindow->theme->plugindialog_new_y,
324                 mwindow->theme->plugindialog_new_w,
325                 mwindow->theme->plugindialog_new_h));
326 // 
327 //      if(thread->plugin)
328 //              add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
329 //                      this,
330 //                      mwindow->theme->plugindialog_newattach_x,
331 //                      mwindow->theme->plugindialog_newattach_y));
332 //      else
333 //              add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow, 
334 //                      this, 
335 //                      mwindow->theme->plugindialog_newattach_x, 
336 //                      mwindow->theme->plugindialog_newattach_y));
337 // 
345         add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x, 
346                 mwindow->theme->plugindialog_shared_y - 20, 
347                 _("Shared effects:")));
348         add_subwindow(shared_list = new PluginDialogShared(this, 
349                 &shared_data, 
350                 mwindow->theme->plugindialog_shared_x, 
351                 mwindow->theme->plugindialog_shared_y,
352                 mwindow->theme->plugindialog_shared_w,
353                 mwindow->theme->plugindialog_shared_h));
354 //      if(thread->plugin)
355 //       add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
356 //          this,
357 //          mwindow->theme->plugindialog_sharedattach_x,
358 //          mwindow->theme->plugindialog_sharedattach_y));
359 //    else
360 //              add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow, 
361 //                      this, 
362 //                      mwindow->theme->plugindialog_sharedattach_x, 
363 //                      mwindow->theme->plugindialog_sharedattach_y));
364 // 
373         add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x, 
374                 mwindow->theme->plugindialog_module_y - 20, 
375                 _("Shared tracks:")));
376         add_subwindow(module_list = new PluginDialogModules(this, 
377                 &module_data, 
378                 mwindow->theme->plugindialog_module_x, 
379                 mwindow->theme->plugindialog_module_y,
380                 mwindow->theme->plugindialog_module_w,
381                 mwindow->theme->plugindialog_module_h));
382 //      if(thread->plugin)
383 //       add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
384 //          this,
385 //          mwindow->theme->plugindialog_moduleattach_x,
386 //          mwindow->theme->plugindialog_moduleattach_y));
387 //    else
388 //              add_subwindow(module_attach = new PluginDialogAttachModule(mwindow, 
389 //                      this, 
390 //                      mwindow->theme->plugindialog_moduleattach_x, 
391 //                      mwindow->theme->plugindialog_moduleattach_y));
392 // 
398         add_subwindow(new BC_OKButton(this));
401         add_subwindow(new BC_CancelButton(this));
403         selected_available = -1;
404         selected_shared = -1;
405         selected_modules = -1;
406         
407         show_window();
408         flush();
409         return 0;
412 int PluginDialog::resize_event(int w, int h)
414         mwindow->session->plugindialog_w = w;
415         mwindow->session->plugindialog_h = h;
416         mwindow->theme->get_plugindialog_sizes();
419         standalone_title->reposition_window(mwindow->theme->plugindialog_new_x, 
420                 mwindow->theme->plugindialog_new_y - 20);
421         standalone_list->reposition_window(mwindow->theme->plugindialog_new_x, 
422                 mwindow->theme->plugindialog_new_y,
423                 mwindow->theme->plugindialog_new_w,
424                 mwindow->theme->plugindialog_new_h);
425 //      if(standalone_attach)
426 //              standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x, 
427 //                      mwindow->theme->plugindialog_newattach_y);
428 //      else
429 //              standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
430 //                      mwindow->theme->plugindialog_newattach_y);
436         shared_title->reposition_window(mwindow->theme->plugindialog_shared_x, 
437                 mwindow->theme->plugindialog_shared_y - 20);
438         shared_list->reposition_window(mwindow->theme->plugindialog_shared_x, 
439                 mwindow->theme->plugindialog_shared_y,
440                 mwindow->theme->plugindialog_shared_w,
441                 mwindow->theme->plugindialog_shared_h);
442 //      if(shared_attach)
443 //              shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x, 
444 //                      mwindow->theme->plugindialog_sharedattach_y);
445 //      else
446 //              shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
447 //                      mwindow->theme->plugindialog_sharedattach_y);
448 // 
453         module_title->reposition_window(mwindow->theme->plugindialog_module_x, 
454                 mwindow->theme->plugindialog_module_y - 20);
455         module_list->reposition_window(mwindow->theme->plugindialog_module_x, 
456                 mwindow->theme->plugindialog_module_y,
457                 mwindow->theme->plugindialog_module_w,
458                 mwindow->theme->plugindialog_module_h);
459 //      if(module_attach)
460 //              module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x, 
461 //                      mwindow->theme->plugindialog_moduleattach_y);
462 //      else
463 //              module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
464 //                      mwindow->theme->plugindialog_moduleattach_y);
465         flush();
468 int PluginDialog::attach_new(int number)
470         if(number > -1 && number < standalone_data.total) 
471         {
472                 strcpy(thread->plugin_title, plugindb.values[number]->title);
473                 thread->plugin_type = PLUGIN_STANDALONE;         // type is plugin
474         }
475         return 0;
478 int PluginDialog::attach_shared(int number)
480         if(number > -1 && number < shared_data.total) 
481         {
482                 thread->plugin_type = PLUGIN_SHAREDPLUGIN;         // type is shared plugin
483                 thread->shared_location = *(plugin_locations.values[number]); // copy location
484         }
485         return 0;
488 int PluginDialog::attach_module(int number)
490         if(number > -1 && number < module_data.total) 
491         {
492 //              title->update(module_data.values[number]->get_text());
493                 thread->plugin_type = PLUGIN_SHAREDMODULE;         // type is module
494                 thread->shared_location = *(module_locations.values[number]); // copy location
495         }
496         return 0;
499 int PluginDialog::save_settings()
509 // 
510 // PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
511 //  : BC_TextBox(x, y, 200, 1, text) 
512 // { 
513 //      this->dialog = dialog;
514 // }
515 // PluginDialogTextBox::~PluginDialogTextBox() 
516 // { }
517 // int PluginDialogTextBox::handle_event() 
518 // { }
519 // 
520 // PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
521 //  : BC_GenericButton(x, y, _("Detach")) 
522 // { 
523 //      this->dialog = dialog; 
524 // }
525 // PluginDialogDetach::~PluginDialogDetach() 
526 // { }
527 // int PluginDialogDetach::handle_event() 
528 // {
529 // //   dialog->title->update(_("None"));
530 //      dialog->thread->plugin_type = 0;         // type is none
531 //      dialog->thread->plugin_title[0] = 0;
532 //      return 1;
533 // }
534 // 
548 PluginDialogNew::PluginDialogNew(PluginDialog *dialog, 
549         ArrayList<BC_ListBoxItem*> *standalone_data, 
550         int x,
551         int y,
552         int w,
553         int h)
554  : BC_ListBox(x, 
555         y, 
556         w, 
557         h, 
558         LISTBOX_TEXT,
559         standalone_data) 
561         this->dialog = dialog; 
563 PluginDialogNew::~PluginDialogNew() { }
564 int PluginDialogNew::handle_event() 
566 //      dialog->attach_new(get_selection_number(0, 0)); 
567 //      deactivate();
569         set_done(0); 
570         return 1;
572 int PluginDialogNew::selection_changed()
574         dialog->selected_available = get_selection_number(0, 0);
577         dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
578         dialog->shared_list->draw_items(1);
579         dialog->module_list->set_all_selected(&dialog->module_data, 0);
580         dialog->module_list->draw_items(1);
581         dialog->selected_shared = -1;
582         dialog->selected_modules = -1;
583         return 1;
586 // PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
587 //  : BC_GenericButton(x, y, _("Attach")) 
588 // { 
589 //      this->dialog = dialog; 
590 // }
591 // PluginDialogAttachNew::~PluginDialogAttachNew() 
592 // {
593 // }
594 // int PluginDialogAttachNew::handle_event() 
595 // {
596 //      dialog->attach_new(dialog->selected_available); 
597 //      set_done(0);
598 //      return 1;
599 // }
600 // 
601 // PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
602 //  : BC_GenericButton(x, y, _("Change"))
603 // {
604 //    this->dialog = dialog;
605 // }
606 // PluginDialogChangeNew::~PluginDialogChangeNew()
607 // {
608 // }
609 // int PluginDialogChangeNew::handle_event() 
610 // {  
611 //    dialog->attach_new(dialog->selected_available);
612 //    set_done(0);
613 //    return 1;
614 // }
625 PluginDialogShared::PluginDialogShared(PluginDialog *dialog, 
626         ArrayList<BC_ListBoxItem*> *shared_data, 
627         int x,
628         int y,
629         int w,
630         int h)
631  : BC_ListBox(x, 
632         y, 
633         w, 
634         h, 
635         LISTBOX_TEXT, 
636         shared_data) 
638         this->dialog = dialog; 
640 PluginDialogShared::~PluginDialogShared() { }
641 int PluginDialogShared::handle_event()
643 //      dialog->attach_shared(get_selection_number(0, 0)); 
644 //      deactivate();
645         set_done(0); 
646         return 1;
648 int PluginDialogShared::selection_changed()
650         dialog->selected_shared = get_selection_number(0, 0);
653         dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
654         dialog->standalone_list->draw_items(1);
655         dialog->module_list->set_all_selected(&dialog->module_data, 0);
656         dialog->module_list->draw_items(1);
657         dialog->selected_available = -1;
658         dialog->selected_modules = -1;
659         return 1;
662 // PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow, 
663 //      PluginDialog *dialog, 
664 //      int x,
665 //      int y)
666 //  : BC_GenericButton(x, y, _("Attach")) 
667 // { 
668 //      this->dialog = dialog; 
669 // }
670 // PluginDialogAttachShared::~PluginDialogAttachShared() { }
671 // int PluginDialogAttachShared::handle_event() 
672 // { 
673 //      dialog->attach_shared(dialog->selected_shared); 
674 //      set_done(0);
675 //      return 1;
676 // }
677 // 
678 // PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
679 //    PluginDialog *dialog,
680 //    int x,
681 //    int y)
682 //  : BC_GenericButton(x, y, _("Change"))
683 // {
684 //    this->dialog = dialog;
685 // }
686 // PluginDialogChangeShared::~PluginDialogChangeShared() { }
687 // int PluginDialogChangeShared::handle_event()
688 // {
689 //    dialog->attach_shared(dialog->selected_shared);
690 //    set_done(0);
691 //    return 1;
692 // }
693 // 
706 PluginDialogModules::PluginDialogModules(PluginDialog *dialog, 
707         ArrayList<BC_ListBoxItem*> *module_data, 
708         int x, 
709         int y,
710         int w,
711         int h)
712  : BC_ListBox(x, 
713         y, 
714         w, 
715         h, 
716         LISTBOX_TEXT, 
717         module_data) 
719         this->dialog = dialog; 
721 PluginDialogModules::~PluginDialogModules() { }
722 int PluginDialogModules::handle_event()
724 //      dialog->attach_module(get_selection_number(0, 0)); 
725 //      deactivate();
727         set_done(0); 
728         return 1;
730 int PluginDialogModules::selection_changed()
732         dialog->selected_modules = get_selection_number(0, 0);
735         dialog->standalone_list->set_all_selected(&dialog->standalone_data, 0);
736         dialog->standalone_list->draw_items(1);
737         dialog->shared_list->set_all_selected(&dialog->shared_data, 0);
738         dialog->shared_list->draw_items(1);
739         dialog->selected_available = -1;
740         dialog->selected_shared = -1;
741         return 1;
745 // PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow, 
746 //      PluginDialog *dialog, 
747 //      int x, 
748 //      int y)
749 //  : BC_GenericButton(x, y, _("Attach")) 
750 // { 
751 //      this->dialog = dialog; 
752 // }
753 // PluginDialogAttachModule::~PluginDialogAttachModule() { }
754 // int PluginDialogAttachModule::handle_event() 
755 // { 
756 //      dialog->attach_module(dialog->selected_modules);
757 //      set_done(0);
758 //      return 1;
759 // }
760 // 
761 // PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
762 //    PluginDialog *dialog,
763 //    int x,
764 //    int y)
765 //  : BC_GenericButton(x, y, _("Change"))
766 // {
767 //    this->dialog = dialog;
768 // }
769 // PluginDialogChangeModule::~PluginDialogChangeModule() { }
770 // int PluginDialogChangeModule::handle_event()
771 // {
772 //    dialog->attach_module(dialog->selected_modules);
773 //    set_done(0);
774 //    return 1;
775 // }
776 //