r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / plugindialog.C
blob4ada0f2df5edc2088b66ef6c4b404239789c85de
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         int x = mwindow->gui->get_abs_cursor_x(1) - mwindow->session->plugindialog_w / 2;
96         int y = mwindow->gui->get_abs_cursor_y(1) - mwindow->session->plugindialog_h / 2;
98         window_lock->lock("PluginDialogThread::run 1"); 
99         window = new PluginDialog(mwindow, this, window_title, x, y);
100         window->create_objects();
101         window_lock->unlock();
103         result = window->run_window();
106         window_lock->lock("PluginDialogThread::run 2");
107         delete window;
108         window = 0;
109         window_lock->unlock();
111         completion->unlock();
113 // Done at closing
114         if(!result)
115         {
116                 if(plugin_type)
117                 {
118                         mwindow->gui->lock_window("PluginDialogThread::run 3");
120                         mwindow->undo->update_undo_before(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
122                         if(plugin)
123                         {
124                                 plugin->change_plugin(plugin_title,
125                                         &shared_location,
126                                         plugin_type);
127                         }
128                         else
129                         {
130                                 mwindow->insert_effect(plugin_title, 
131                                                                 &shared_location,
132                                                                 track,
133                                                                 0,
134                                                                 0,
135                                                                 0,
136                                                                 plugin_type);
137                         }
139                         
140                         mwindow->save_backup();
141                         mwindow->undo->update_undo_after();
142                         mwindow->restart_brender();
143                         mwindow->update_plugin_states();
144                         mwindow->sync_parameters(CHANGE_EDL);
145                         mwindow->gui->update(1,
146                                 1,
147                                 0,
148                                 0,
149                                 1, 
150                                 0,
151                                 0);
153                         mwindow->gui->unlock_window();
154                 }
155         }
156         plugin = 0;
167 PluginDialog::PluginDialog(MWindow *mwindow, 
168         PluginDialogThread *thread, 
169         char *window_title,
170         int x,
171         int y)
172  : BC_Window(window_title, 
173         x,
174         y,
175         mwindow->session->plugindialog_w, 
176         mwindow->session->plugindialog_h, 
177         510, 
178         415,
179         1,
180         0,
181         1)
183         this->mwindow = mwindow;  
184         this->thread = thread;
185         standalone_attach = 0;
186         shared_attach = 0;
187         module_attach = 0;
188         standalone_change = 0;
189         shared_change = 0;
190         module_change = 0;
191         inoutthru = 0;
194 PluginDialog::~PluginDialog()
196         int i;
197         standalone_data.remove_all_objects();
198         
199         shared_data.remove_all_objects();
200         
201         module_data.remove_all_objects();
203         plugin_locations.remove_all_objects();
205         module_locations.remove_all_objects();
207 //      delete title;
208 //      delete detach;
209         delete standalone_list;
210         delete shared_list;
211         delete module_list;
212         if(standalone_attach) delete standalone_attach;
213         if(shared_attach) delete shared_attach;
214         if(module_attach) delete module_attach;
215         if(standalone_change) delete standalone_change;
216         if(shared_change) delete shared_change;
217         if(module_change) delete module_change;
218 //      delete in;
219 //      delete out;
222 int PluginDialog::create_objects()
224         int use_default = 1;
225         char string[BCTEXTLEN];
226         int module_number;
227         mwindow->theme->get_plugindialog_sizes();
229         if(thread->plugin)
230         {
231                 strcpy(string, thread->plugin->title);
232                 use_default = 1;
233         }
234         else
235         {
236 // no plugin
237                 sprintf(string, _("None"));
238         }
245 // GET A LIST OF ALL THE PLUGINS AVAILABLE
246         mwindow->create_plugindb(thread->data_type == TRACK_AUDIO, 
247                 thread->data_type == TRACK_VIDEO, 
248                 1, 
249                 0,
250                 0,
251                 plugindb);
253         mwindow->edl->get_shared_plugins(thread->track,
254                 &plugin_locations);
256         mwindow->edl->get_shared_tracks(thread->track,
257                 &module_locations);
266 // Construct listbox items
267         for(int i = 0; i < plugindb.total; i++)
268                 standalone_data.append(new BC_ListBoxItem(_(plugindb.values[i]->title)));
269         for(int i = 0; i < plugin_locations.total; i++)
270         {
271                 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
272                 char *track_title = track->title;
273                 int number = plugin_locations.values[i]->plugin;
274                 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->selectionstart, 
275                         number, 
276                         PLAY_FORWARD,
277                         1,
278                         0);
279                 char *plugin_title = plugin->title;
280                 char string[BCTEXTLEN];
282                 sprintf(string, "%s: %s", track_title, _(plugin_title));
283                 shared_data.append(new BC_ListBoxItem(string));
284         }
285         for(int i = 0; i < module_locations.total; i++)
286         {
287                 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
288                 module_data.append(new BC_ListBoxItem(track->title));
289         }
295 // Create widgets
296         add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x, 
297                 mwindow->theme->plugindialog_new_y - 20, 
298                 _("Plugins:")));
299         add_subwindow(standalone_list = new PluginDialogNew(this, 
300                 &standalone_data, 
301                 mwindow->theme->plugindialog_new_x, 
302                 mwindow->theme->plugindialog_new_y,
303                 mwindow->theme->plugindialog_new_w,
304                 mwindow->theme->plugindialog_new_h));
306         if(thread->plugin)
307                 add_subwindow(standalone_change = new PluginDialogChangeNew(mwindow,
308                         this,
309                         mwindow->theme->plugindialog_newattach_x,
310                         mwindow->theme->plugindialog_newattach_y));
311         else
312                 add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow, 
313                         this, 
314                         mwindow->theme->plugindialog_newattach_x, 
315                         mwindow->theme->plugindialog_newattach_y));
324         add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x, 
325                 mwindow->theme->plugindialog_shared_y - 20, 
326                 _("Shared effects:")));
327         add_subwindow(shared_list = new PluginDialogShared(this, 
328                 &shared_data, 
329                 mwindow->theme->plugindialog_shared_x, 
330                 mwindow->theme->plugindialog_shared_y,
331                 mwindow->theme->plugindialog_shared_w,
332                 mwindow->theme->plugindialog_shared_h));
333         if(thread->plugin)
334       add_subwindow(shared_change = new PluginDialogChangeShared(mwindow,
335          this,
336          mwindow->theme->plugindialog_sharedattach_x,
337          mwindow->theme->plugindialog_sharedattach_y));
338    else
339                 add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow, 
340                         this, 
341                         mwindow->theme->plugindialog_sharedattach_x, 
342                         mwindow->theme->plugindialog_sharedattach_y));
352         add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x, 
353                 mwindow->theme->plugindialog_module_y - 20, 
354                 _("Shared tracks:")));
355         add_subwindow(module_list = new PluginDialogModules(this, 
356                 &module_data, 
357                 mwindow->theme->plugindialog_module_x, 
358                 mwindow->theme->plugindialog_module_y,
359                 mwindow->theme->plugindialog_module_w,
360                 mwindow->theme->plugindialog_module_h));
361         if(thread->plugin)
362       add_subwindow(module_change = new PluginDialogChangeModule(mwindow,
363          this,
364          mwindow->theme->plugindialog_moduleattach_x,
365          mwindow->theme->plugindialog_moduleattach_y));
366    else
367                 add_subwindow(module_attach = new PluginDialogAttachModule(mwindow, 
368                         this, 
369                         mwindow->theme->plugindialog_moduleattach_x, 
370                         mwindow->theme->plugindialog_moduleattach_y));
378         add_subwindow(new BC_CancelButton(this));
380         selected_available = -1;
381         selected_shared = -1;
382         selected_modules = -1;
383         
384         show_window();
385         flush();
386         return 0;
389 int PluginDialog::resize_event(int w, int h)
391         mwindow->session->plugindialog_w = w;
392         mwindow->session->plugindialog_h = h;
393         mwindow->theme->get_plugindialog_sizes();
396         standalone_title->reposition_window(mwindow->theme->plugindialog_new_x, 
397                 mwindow->theme->plugindialog_new_y - 20);
398         standalone_list->reposition_window(mwindow->theme->plugindialog_new_x, 
399                 mwindow->theme->plugindialog_new_y,
400                 mwindow->theme->plugindialog_new_w,
401                 mwindow->theme->plugindialog_new_h);
402         if(standalone_attach)
403                 standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x, 
404                         mwindow->theme->plugindialog_newattach_y);
405         else
406                 standalone_change->reposition_window(mwindow->theme->plugindialog_newattach_x,
407                         mwindow->theme->plugindialog_newattach_y);
413         shared_title->reposition_window(mwindow->theme->plugindialog_shared_x, 
414                 mwindow->theme->plugindialog_shared_y - 20);
415         shared_list->reposition_window(mwindow->theme->plugindialog_shared_x, 
416                 mwindow->theme->plugindialog_shared_y,
417                 mwindow->theme->plugindialog_shared_w,
418                 mwindow->theme->plugindialog_shared_h);
419         if(shared_attach)
420                 shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x, 
421                         mwindow->theme->plugindialog_sharedattach_y);
422         else
423                 shared_change->reposition_window(mwindow->theme->plugindialog_sharedattach_x,
424                         mwindow->theme->plugindialog_sharedattach_y);
430         module_title->reposition_window(mwindow->theme->plugindialog_module_x, 
431                 mwindow->theme->plugindialog_module_y - 20);
432         module_list->reposition_window(mwindow->theme->plugindialog_module_x, 
433                 mwindow->theme->plugindialog_module_y,
434                 mwindow->theme->plugindialog_module_w,
435                 mwindow->theme->plugindialog_module_h);
436         if(module_attach)
437                 module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x, 
438                         mwindow->theme->plugindialog_moduleattach_y);
439         else
440                 module_change->reposition_window(mwindow->theme->plugindialog_moduleattach_x,
441                         mwindow->theme->plugindialog_moduleattach_y);
442         flush();
445 int PluginDialog::attach_new(int number)
447         if(number > -1 && number < standalone_data.total) 
448         {
449                 strcpy(thread->plugin_title, plugindb.values[number]->title);
450                 thread->plugin_type = PLUGIN_STANDALONE;         // type is plugin
451         }
452         return 0;
455 int PluginDialog::attach_shared(int number)
457         if(number > -1 && number < shared_data.total) 
458         {
459                 thread->plugin_type = PLUGIN_SHAREDPLUGIN;         // type is shared plugin
460                 thread->shared_location = *(plugin_locations.values[number]); // copy location
461         }
462         return 0;
465 int PluginDialog::attach_module(int number)
467         if(number > -1 && number < module_data.total) 
468         {
469 //              title->update(module_data.values[number]->get_text());
470                 thread->plugin_type = PLUGIN_SHAREDMODULE;         // type is module
471                 thread->shared_location = *(module_locations.values[number]); // copy location
472         }
473         return 0;
476 int PluginDialog::save_settings()
487 PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
488  : BC_TextBox(x, y, 200, 1, text) 
490         this->dialog = dialog;
492 PluginDialogTextBox::~PluginDialogTextBox() 
493 { }
494 int PluginDialogTextBox::handle_event() 
495 { }
497 PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
498  : BC_GenericButton(x, y, _("Detach")) 
500         this->dialog = dialog; 
502 PluginDialogDetach::~PluginDialogDetach() 
503 { }
504 int PluginDialogDetach::handle_event() 
506 //      dialog->title->update(_("None"));
507         dialog->thread->plugin_type = 0;         // type is none
508         dialog->thread->plugin_title[0] = 0;
509         return 1;
525 PluginDialogNew::PluginDialogNew(PluginDialog *dialog, 
526         ArrayList<BC_ListBoxItem*> *standalone_data, 
527         int x,
528         int y,
529         int w,
530         int h)
531  : BC_ListBox(x, 
532         y, 
533         w, 
534         h, 
535         LISTBOX_TEXT,
536         standalone_data) 
538         this->dialog = dialog; 
540 PluginDialogNew::~PluginDialogNew() { }
541 int PluginDialogNew::handle_event() 
543         dialog->attach_new(get_selection_number(0, 0)); 
544         deactivate();
546         set_done(0); 
547         return 1;
549 int PluginDialogNew::selection_changed()
551         dialog->selected_available = get_selection_number(0, 0);
552         return 1;
555 PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
556  : BC_GenericButton(x, y, _("Attach")) 
558         this->dialog = dialog; 
560 PluginDialogAttachNew::~PluginDialogAttachNew() 
563 int PluginDialogAttachNew::handle_event() 
565         dialog->attach_new(dialog->selected_available); 
566         set_done(0);
567         return 1;
570 PluginDialogChangeNew::PluginDialogChangeNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
571  : BC_GenericButton(x, y, _("Change"))
573    this->dialog = dialog;
575 PluginDialogChangeNew::~PluginDialogChangeNew()
578 int PluginDialogChangeNew::handle_event() 
579 {  
580    dialog->attach_new(dialog->selected_available);
581    set_done(0);
582    return 1;
594 PluginDialogShared::PluginDialogShared(PluginDialog *dialog, 
595         ArrayList<BC_ListBoxItem*> *shared_data, 
596         int x,
597         int y,
598         int w,
599         int h)
600  : BC_ListBox(x, 
601         y, 
602         w, 
603         h, 
604         LISTBOX_TEXT, 
605         shared_data) 
607         this->dialog = dialog; 
609 PluginDialogShared::~PluginDialogShared() { }
610 int PluginDialogShared::handle_event()
612         dialog->attach_shared(get_selection_number(0, 0)); 
613         deactivate();
614         set_done(0); 
615         return 1;
617 int PluginDialogShared::selection_changed()
619         dialog->selected_shared = get_selection_number(0, 0);
620         return 1;
623 PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow, 
624         PluginDialog *dialog, 
625         int x,
626         int y)
627  : BC_GenericButton(x, y, _("Attach")) 
629         this->dialog = dialog; 
631 PluginDialogAttachShared::~PluginDialogAttachShared() { }
632 int PluginDialogAttachShared::handle_event() 
634         dialog->attach_shared(dialog->selected_shared); 
635         set_done(0);
636         return 1;
639 PluginDialogChangeShared::PluginDialogChangeShared(MWindow *mwindow,
640    PluginDialog *dialog,
641    int x,
642    int y)
643  : BC_GenericButton(x, y, _("Change"))
645    this->dialog = dialog;
647 PluginDialogChangeShared::~PluginDialogChangeShared() { }
648 int PluginDialogChangeShared::handle_event()
650    dialog->attach_shared(dialog->selected_shared);
651    set_done(0);
652    return 1;
667 PluginDialogModules::PluginDialogModules(PluginDialog *dialog, 
668         ArrayList<BC_ListBoxItem*> *module_data, 
669         int x, 
670         int y,
671         int w,
672         int h)
673  : BC_ListBox(x, 
674         y, 
675         w, 
676         h, 
677         LISTBOX_TEXT, 
678         module_data) 
680         this->dialog = dialog; 
682 PluginDialogModules::~PluginDialogModules() { }
683 int PluginDialogModules::handle_event()
685         dialog->attach_module(get_selection_number(0, 0)); 
686         deactivate();
688         set_done(0); 
689         return 1;
691 int PluginDialogModules::selection_changed()
693         dialog->selected_modules = get_selection_number(0, 0);
694         return 1;
698 PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow, 
699         PluginDialog *dialog, 
700         int x, 
701         int y)
702  : BC_GenericButton(x, y, _("Attach")) 
704         this->dialog = dialog; 
706 PluginDialogAttachModule::~PluginDialogAttachModule() { }
707 int PluginDialogAttachModule::handle_event() 
709         dialog->attach_module(dialog->selected_modules);
710         set_done(0);
711         return 1;
714 PluginDialogChangeModule::PluginDialogChangeModule(MWindow *mwindow,
715    PluginDialog *dialog,
716    int x,
717    int y)
718  : BC_GenericButton(x, y, _("Change"))
720    this->dialog = dialog;
722 PluginDialogChangeModule::~PluginDialogChangeModule() { }
723 int PluginDialogChangeModule::handle_event()
725    dialog->attach_module(dialog->selected_modules);
726    set_done(0);
727    return 1;
744 PluginDialogIn::PluginDialogIn(PluginDialog *dialog, int setting, int x, int y)
745  : BC_CheckBox(x, y, setting, _("Send")) 
747         this->dialog = dialog; 
749 PluginDialogIn::~PluginDialogIn() { }
750 int PluginDialogIn::handle_event() 
752 //      dialog->thread->in = get_value();
753         return 1;
755 int PluginDialogIn::button_press()
757         dialog->inoutthru = 1;
758         dialog->new_value = get_value();
759         return 1;
761 int PluginDialogIn::button_release()
763         if(dialog->inoutthru) dialog->inoutthru = 0;
765 int PluginDialogIn::cursor_moved_over()
767         if(dialog->inoutthru && get_value() != dialog->new_value)
768         {
769                 update(dialog->new_value);
770         }
773 PluginDialogOut::PluginDialogOut(PluginDialog *dialog, int setting, int x, int y)
774  : BC_CheckBox(x, y, setting, _("Receive")) 
776         this->dialog = dialog; 
778 PluginDialogOut::~PluginDialogOut() { }
779 int PluginDialogOut::handle_event() 
781 //      dialog->thread->out = get_value();
782         return 1;
784 int PluginDialogOut::button_press()
786         dialog->inoutthru = 1;
787         dialog->new_value = get_value();
788         return 1;
790 int PluginDialogOut::button_release()
792         if(dialog->inoutthru) dialog->inoutthru = 0;
794 int PluginDialogOut::cursor_moved_over()
796         if(dialog->inoutthru && get_value() != dialog->new_value)
797         {
798                 update(dialog->new_value);
799         }
802 PluginDialogThru::PluginDialogThru(PluginDialog *dialog, int setting)
803  : BC_CheckBox(300, 350, setting, _("Thru")) 
805         this->dialog = dialog; 
807 PluginDialogThru::~PluginDialogThru() { }
808 int PluginDialogThru::handle_event() { }
809 int PluginDialogThru::button_press()
811         dialog->inoutthru = 1;
812         dialog->new_value = get_value();
813         return 1;
815 int PluginDialogThru::button_release()
817         if(dialog->inoutthru) dialog->inoutthru = 0;
819 int PluginDialogThru::cursor_moved_over()
821         if(dialog->inoutthru && get_value() != dialog->new_value)
822         {
823                 update(dialog->new_value);
824         }