r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / plugindialog.C
blob36b79bafa653418aa4bef59cce674bb5b63038e0
1 #include "edl.h"
2 #include "localsession.h"
3 #include "mainsession.h"
4 #include "mainundo.h"
5 #include "mwindow.h"
6 #include "mwindowgui.h"
7 #include "module.h"
8 #include "plugin.h"
9 #include "plugindialog.h"
10 #include "pluginserver.h"
11 #include "theme.h"
12 #include "track.h"
13 #include "tracks.h"
14 #include "transition.h"
16 #include <libintl.h>
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
22 PluginDialogThread::PluginDialogThread(MWindow *mwindow)
23  : Thread()
25         this->mwindow = mwindow;
26         window = 0;
27         plugin = 0;
28         Thread::set_synchronous(0);
31 PluginDialogThread::~PluginDialogThread()
33         if(window)
34         {
35                 window->set_done(1);
36                 completion.lock();
37                 completion.unlock();
38         }
41 void PluginDialogThread::start_window(Track *track,
42         Plugin *plugin, 
43         char *title)
45         if(Thread::running())
46         {
47                 window->raise_window();
48                 window->flush();
49         }
50         else
51         {
52                 this->track = track;
53                 this->data_type = track->data_type;
54                 this->plugin = plugin;
56                 if(plugin)
57                 {
58                         plugin->calculate_title(plugin_title);
59                         this->shared_location = plugin->shared_location;
60                         this->plugin_type = plugin->plugin_type;
61                 }
62                 else
63                 {
64                         this->plugin_title[0] = 0;
65                         this->shared_location.plugin = -1;
66                         this->shared_location.module = -1;
67                         this->plugin_type = PLUGIN_NONE;
68                 }
70                 strcpy(this->window_title, title);
71                 completion.lock();
72                 Thread::start();
73         }
77 int PluginDialogThread::set_dialog(Transition *transition, char *title)
79         return 0;
82 void PluginDialogThread::run()
84         int result = 0;
86         window = new PluginDialog(mwindow, this, window_title);
87         window->create_objects();
88         result = window->run_window();
89         delete window;
90         window = 0;
91         completion.unlock();
93 // Done at closing
94         if(!result)
95         {
96                 if(plugin_type)
97                 {
98                         mwindow->gui->lock_window();
100                         mwindow->undo->update_undo_before(_("attach effect"), LOAD_EDITS | LOAD_PATCHES);
102                         if(plugin)
103                         {
104                                 plugin->change_plugin(plugin_title,
105                                         &shared_location,
106                                         plugin_type);
107                         }
108                         else
109                         {
110                                 mwindow->insert_effect(plugin_title, 
111                                                                 &shared_location,
112                                                                 track,
113                                                                 0,
114                                                                 0,
115                                                                 0,
116                                                                 plugin_type);
117                         }
119                         
120                         mwindow->save_backup();
121                         mwindow->undo->update_undo_after();
122                         mwindow->restart_brender();
123                         mwindow->update_plugin_states();
124                         mwindow->sync_parameters(CHANGE_EDL);
125                         mwindow->gui->update(1,
126                                 1,
127                                 0,
128                                 0,
129                                 1, 
130                                 0,
131                                 0);
133                         mwindow->gui->unlock_window();
134                 }
135         }
136         plugin = 0;
147 PluginDialog::PluginDialog(MWindow *mwindow, 
148         PluginDialogThread *thread, 
149         char *window_title)
150  : BC_Window(window_title, 
151         mwindow->gui->get_abs_cursor_x() - mwindow->session->plugindialog_w / 2, 
152         mwindow->gui->get_abs_cursor_y() - mwindow->session->plugindialog_h / 2, 
153         mwindow->session->plugindialog_w, 
154         mwindow->session->plugindialog_h, 
155         510, 
156         415,
157         1,
158         0,
159         1)
161         this->mwindow = mwindow;  
162         this->thread = thread;
163         inoutthru = 0;
166 PluginDialog::~PluginDialog()
168         int i;
169         for(i = 0; i < standalone_data.total; i++) delete standalone_data.values[i];
170         standalone_data.remove_all();
171         
172         for(i = 0; i < shared_data.total; i++) delete shared_data.values[i];
173         shared_data.remove_all();
174         
175         for(i = 0; i < module_data.total; i++) delete module_data.values[i];
176         module_data.remove_all();
178         for(i = 0; i < plugin_locations.total; i++) delete plugin_locations.values[i];
179         plugin_locations.remove_all();
181         for(i = 0; i < module_locations.total; i++) delete module_locations.values[i];
182         module_locations.remove_all();
184 //      delete title;
185 //      delete detach;
186         delete standalone_list;
187         delete shared_list;
188         delete module_list;
189         delete standalone_attach;
190         delete shared_attach;
191         delete module_attach;
192 //      delete in;
193 //      delete out;
196 int PluginDialog::create_objects()
198         int use_default = 1;
199         char string[BCTEXTLEN];
200         int module_number;
201         mwindow->theme->get_plugindialog_sizes();
203         if(thread->plugin)
204         {
205                 strcpy(string, thread->plugin->title);
206                 use_default = 1;
207         }
208         else
209         {
210 // no plugin
211                 sprintf(string, _("None"));
212         }
219 // GET A LIST OF ALL THE PLUGINS AVAILABLE
220         ArrayList<PluginServer*> plugindb;
221         mwindow->create_plugindb(thread->data_type == TRACK_AUDIO, 
222                 thread->data_type == TRACK_VIDEO, 
223                 1, 
224                 0,
225                 0,
226                 plugindb);
228         mwindow->edl->get_shared_plugins(thread->track,
229                 &plugin_locations);
231         mwindow->edl->get_shared_tracks(thread->track,
232                 &module_locations);
241 // Construct listbox items
242         for(int i = 0; i < plugindb.total; i++)
243                 standalone_data.append(new BC_ListBoxItem(plugindb.values[i]->title));
244         for(int i = 0; i < plugin_locations.total; i++)
245         {
246                 Track *track = mwindow->edl->tracks->number(plugin_locations.values[i]->module);
247                 char *track_title = track->title;
248                 int number = plugin_locations.values[i]->plugin;
249                 Plugin *plugin = track->get_current_plugin(mwindow->edl->local_session->selectionstart, 
250                         number, 
251                         PLAY_FORWARD,
252                         1);
253                 char *plugin_title = plugin->title;
254                 char string[BCTEXTLEN];
256                 sprintf(string, "%s: %s", track_title, plugin_title);
257                 shared_data.append(new BC_ListBoxItem(string));
258         }
259         for(int i = 0; i < module_locations.total; i++)
260         {
261                 Track *track = mwindow->edl->tracks->number(module_locations.values[i]->module);
262                 module_data.append(new BC_ListBoxItem(track->title));
263         }
269 // Create widgets
270         add_subwindow(standalone_title = new BC_Title(mwindow->theme->plugindialog_new_x, 
271                 mwindow->theme->plugindialog_new_y - 20, 
272                 _("Plugins:")));
273         add_subwindow(standalone_list = new PluginDialogNew(this, 
274                 &standalone_data, 
275                 mwindow->theme->plugindialog_new_x, 
276                 mwindow->theme->plugindialog_new_y,
277                 mwindow->theme->plugindialog_new_w,
278                 mwindow->theme->plugindialog_new_h));
279         add_subwindow(standalone_attach = new PluginDialogAttachNew(mwindow, 
280                 this, 
281                 mwindow->theme->plugindialog_newattach_x, 
282                 mwindow->theme->plugindialog_newattach_y));
291         add_subwindow(shared_title = new BC_Title(mwindow->theme->plugindialog_shared_x, 
292                 mwindow->theme->plugindialog_shared_y - 20, 
293                 _("Shared effects:")));
294         add_subwindow(shared_list = new PluginDialogShared(this, 
295                 &shared_data, 
296                 mwindow->theme->plugindialog_shared_x, 
297                 mwindow->theme->plugindialog_shared_y,
298                 mwindow->theme->plugindialog_shared_w,
299                 mwindow->theme->plugindialog_shared_h));
300         add_subwindow(shared_attach = new PluginDialogAttachShared(mwindow, 
301                 this, 
302                 mwindow->theme->plugindialog_sharedattach_x, 
303                 mwindow->theme->plugindialog_sharedattach_y));
313         add_subwindow(module_title = new BC_Title(mwindow->theme->plugindialog_module_x, 
314                 mwindow->theme->plugindialog_module_y - 20, 
315                 _("Shared tracks:")));
316         add_subwindow(module_list = new PluginDialogModules(this, 
317                 &module_data, 
318                 mwindow->theme->plugindialog_module_x, 
319                 mwindow->theme->plugindialog_module_y,
320                 mwindow->theme->plugindialog_module_w,
321                 mwindow->theme->plugindialog_module_h));
322         add_subwindow(module_attach = new PluginDialogAttachModule(mwindow, 
323                 this, 
324                 mwindow->theme->plugindialog_moduleattach_x, 
325                 mwindow->theme->plugindialog_moduleattach_y));
333         add_subwindow(new BC_CancelButton(this));
335         selected_available = -1;
336         selected_shared = -1;
337         selected_modules = -1;
338         
339         show_window();
340         flush();
341         return 0;
344 int PluginDialog::resize_event(int w, int h)
346         mwindow->session->plugindialog_w = w;
347         mwindow->session->plugindialog_h = h;
348         mwindow->theme->get_plugindialog_sizes();
351         standalone_title->reposition_window(mwindow->theme->plugindialog_new_x, 
352                 mwindow->theme->plugindialog_new_y - 20);
353         standalone_list->reposition_window(mwindow->theme->plugindialog_new_x, 
354                 mwindow->theme->plugindialog_new_y,
355                 mwindow->theme->plugindialog_new_w,
356                 mwindow->theme->plugindialog_new_h);
357         standalone_attach->reposition_window(mwindow->theme->plugindialog_newattach_x, 
358                 mwindow->theme->plugindialog_newattach_y);
364         shared_title->reposition_window(mwindow->theme->plugindialog_shared_x, 
365                 mwindow->theme->plugindialog_shared_y - 20);
366         shared_list->reposition_window(mwindow->theme->plugindialog_shared_x, 
367                 mwindow->theme->plugindialog_shared_y,
368                 mwindow->theme->plugindialog_shared_w,
369                 mwindow->theme->plugindialog_shared_h);
370         shared_attach->reposition_window(mwindow->theme->plugindialog_sharedattach_x, 
371                 mwindow->theme->plugindialog_sharedattach_y);
377         module_title->reposition_window(mwindow->theme->plugindialog_module_x, 
378                 mwindow->theme->plugindialog_module_y - 20);
379         module_list->reposition_window(mwindow->theme->plugindialog_module_x, 
380                 mwindow->theme->plugindialog_module_y,
381                 mwindow->theme->plugindialog_module_w,
382                 mwindow->theme->plugindialog_module_h);
383         module_attach->reposition_window(mwindow->theme->plugindialog_moduleattach_x, 
384                 mwindow->theme->plugindialog_moduleattach_y);
385         flush();
388 int PluginDialog::attach_new(int number)
390         if(number > -1 && number < standalone_data.total) 
391         {
392                 strcpy(thread->plugin_title, standalone_data.values[number]->get_text());
393                 thread->plugin_type = PLUGIN_STANDALONE;         // type is plugin
394         }
395         return 0;
398 int PluginDialog::attach_shared(int number)
400         if(number > -1 && number < shared_data.total) 
401         {
402                 thread->plugin_type = PLUGIN_SHAREDPLUGIN;         // type is shared plugin
403                 thread->shared_location = *(plugin_locations.values[number]); // copy location
404         }
405         return 0;
408 int PluginDialog::attach_module(int number)
410         if(number > -1 && number < module_data.total) 
411         {
412 //              title->update(module_data.values[number]->get_text());
413                 thread->plugin_type = PLUGIN_SHAREDMODULE;         // type is module
414                 thread->shared_location = *(module_locations.values[number]); // copy location
415         }
416         return 0;
419 int PluginDialog::save_settings()
430 PluginDialogTextBox::PluginDialogTextBox(PluginDialog *dialog, char *text, int x, int y)
431  : BC_TextBox(x, y, 200, 1, text) 
433         this->dialog = dialog;
435 PluginDialogTextBox::~PluginDialogTextBox() 
436 { }
437 int PluginDialogTextBox::handle_event() 
438 { }
440 PluginDialogDetach::PluginDialogDetach(MWindow *mwindow, PluginDialog *dialog, int x, int y)
441  : BC_GenericButton(x, y, _("Detach")) 
443         this->dialog = dialog; 
445 PluginDialogDetach::~PluginDialogDetach() 
446 { }
447 int PluginDialogDetach::handle_event() 
449 //      dialog->title->update(_("None"));
450         dialog->thread->plugin_type = 0;         // type is none
451         dialog->thread->plugin_title[0] = 0;
452         return 1;
468 PluginDialogNew::PluginDialogNew(PluginDialog *dialog, 
469         ArrayList<BC_ListBoxItem*> *standalone_data, 
470         int x,
471         int y,
472         int w,
473         int h)
474  : BC_ListBox(x, 
475         y, 
476         w, 
477         h, 
478         LISTBOX_TEXT,
479         standalone_data) 
481         this->dialog = dialog; 
483 PluginDialogNew::~PluginDialogNew() { }
484 int PluginDialogNew::handle_event() 
486         dialog->attach_new(get_selection_number(0, 0)); 
487         deactivate();
489         set_done(0); 
490         return 1;
492 int PluginDialogNew::selection_changed()
494         dialog->selected_available = get_selection_number(0, 0);
495         return 1;
498 PluginDialogAttachNew::PluginDialogAttachNew(MWindow *mwindow, PluginDialog *dialog, int x, int y)
499  : BC_GenericButton(x, y, _("Attach")) 
501         this->dialog = dialog; 
503 PluginDialogAttachNew::~PluginDialogAttachNew() 
504 { }
505 int PluginDialogAttachNew::handle_event() 
507         dialog->attach_new(dialog->selected_available); 
508         set_done(0);
509         return 1;
521 PluginDialogShared::PluginDialogShared(PluginDialog *dialog, 
522         ArrayList<BC_ListBoxItem*> *shared_data, 
523         int x,
524         int y,
525         int w,
526         int h)
527  : BC_ListBox(x, 
528         y, 
529         w, 
530         h, 
531         LISTBOX_TEXT, 
532         shared_data) 
534         this->dialog = dialog; 
536 PluginDialogShared::~PluginDialogShared() { }
537 int PluginDialogShared::handle_event()
539         dialog->attach_shared(get_selection_number(0, 0)); 
540         deactivate();
541         set_done(0); 
542         return 1;
544 int PluginDialogShared::selection_changed()
546         dialog->selected_shared = get_selection_number(0, 0);
547         return 1;
550 PluginDialogAttachShared::PluginDialogAttachShared(MWindow *mwindow, 
551         PluginDialog *dialog, 
552         int x,
553         int y)
554  : BC_GenericButton(x, y, _("Attach")) 
556         this->dialog = dialog; 
558 PluginDialogAttachShared::~PluginDialogAttachShared() { }
559 int PluginDialogAttachShared::handle_event() 
561         dialog->attach_module(dialog->selected_shared); 
562         set_done(0);
563         return 1;
577 PluginDialogModules::PluginDialogModules(PluginDialog *dialog, 
578         ArrayList<BC_ListBoxItem*> *module_data, 
579         int x, 
580         int y,
581         int w,
582         int h)
583  : BC_ListBox(x, 
584         y, 
585         w, 
586         h, 
587         LISTBOX_TEXT, 
588         module_data) 
590         this->dialog = dialog; 
592 PluginDialogModules::~PluginDialogModules() { }
593 int PluginDialogModules::handle_event()
595         dialog->attach_module(get_selection_number(0, 0)); 
596         deactivate();
598         set_done(0); 
599         return 1;
601 int PluginDialogModules::selection_changed()
603         dialog->selected_modules = get_selection_number(0, 0);
604         return 1;
608 PluginDialogAttachModule::PluginDialogAttachModule(MWindow *mwindow, 
609         PluginDialog *dialog, 
610         int x, 
611         int y)
612  : BC_GenericButton(x, y, _("Attach")) 
614         this->dialog = dialog; 
616 PluginDialogAttachModule::~PluginDialogAttachModule() { }
617 int PluginDialogAttachModule::handle_event() 
619         dialog->attach_module(dialog->selected_modules);
620         set_done(0);
621         return 1;
637 PluginDialogIn::PluginDialogIn(PluginDialog *dialog, int setting, int x, int y)
638  : BC_CheckBox(x, y, setting, _("Send")) 
640         this->dialog = dialog; 
642 PluginDialogIn::~PluginDialogIn() { }
643 int PluginDialogIn::handle_event() 
645 //      dialog->thread->in = get_value();
646         return 1;
648 int PluginDialogIn::button_press()
650         dialog->inoutthru = 1;
651         dialog->new_value = get_value();
652         return 1;
654 int PluginDialogIn::button_release()
656         if(dialog->inoutthru) dialog->inoutthru = 0;
658 int PluginDialogIn::cursor_moved_over()
660         if(dialog->inoutthru && get_value() != dialog->new_value)
661         {
662                 update(dialog->new_value);
663         }
666 PluginDialogOut::PluginDialogOut(PluginDialog *dialog, int setting, int x, int y)
667  : BC_CheckBox(x, y, setting, _("Receive")) 
669         this->dialog = dialog; 
671 PluginDialogOut::~PluginDialogOut() { }
672 int PluginDialogOut::handle_event() 
674 //      dialog->thread->out = get_value();
675         return 1;
677 int PluginDialogOut::button_press()
679         dialog->inoutthru = 1;
680         dialog->new_value = get_value();
681         return 1;
683 int PluginDialogOut::button_release()
685         if(dialog->inoutthru) dialog->inoutthru = 0;
687 int PluginDialogOut::cursor_moved_over()
689         if(dialog->inoutthru && get_value() != dialog->new_value)
690         {
691                 update(dialog->new_value);
692         }
695 PluginDialogThru::PluginDialogThru(PluginDialog *dialog, int setting)
696  : BC_CheckBox(300, 350, setting, _("Thru")) 
698         this->dialog = dialog; 
700 PluginDialogThru::~PluginDialogThru() { }
701 int PluginDialogThru::handle_event() { }
702 int PluginDialogThru::button_press()
704         dialog->inoutthru = 1;
705         dialog->new_value = get_value();
706         return 1;
708 int PluginDialogThru::button_release()
710         if(dialog->inoutthru) dialog->inoutthru = 0;
712 int PluginDialogThru::cursor_moved_over()
714         if(dialog->inoutthru && get_value() != dialog->new_value)
715         {
716                 update(dialog->new_value);
717         }