r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / plugins / reverb / reverbwindow.C
blobc7f59ba3ffb6d30191483f85f9ca87bac8ac0c70
1 #include "bcdisplayinfo.h"
2 #include "defaults.h"
3 #include "filesystem.h"
4 #include "reverb.h"
5 #include "reverbwindow.h"
7 #include <string.h>
9 PLUGIN_THREAD_OBJECT(Reverb, ReverbThread, ReverbWindow)
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
18 ReverbWindow::ReverbWindow(Reverb *reverb, int x, int y)
19  : BC_Window(reverb->gui_string, 
20         x, 
21         y, 
22         250, 
23         230, 
24         250, 
25         230, 
26         0, 
27         0,
28         1)
29
30         this->reverb = reverb; 
33 ReverbWindow::~ReverbWindow()
37 int ReverbWindow::create_objects()
39         int x = 170, y = 10;
40         add_tool(new BC_Title(5, y + 10, _("Initial signal level:")));
41         add_tool(level_init = new ReverbLevelInit(reverb, x, y)); y += 25;
42         add_tool(new BC_Title(5, y + 10, _("ms before reflections:")));
43         add_tool(delay_init = new ReverbDelayInit(reverb, x + 35, y)); y += 25;
44         add_tool(new BC_Title(5, y + 10, _("First reflection level:")));
45         add_tool(ref_level1 = new ReverbRefLevel1(reverb, x, y)); y += 25;
46         add_tool(new BC_Title(5, y + 10, _("Last reflection level:")));
47         add_tool(ref_level2 = new ReverbRefLevel2(reverb, x + 35, y)); y += 25;
48         add_tool(new BC_Title(5, y + 10, _("Number of reflections:")));
49         add_tool(ref_total = new ReverbRefTotal(reverb, x, y)); y += 25;
50         add_tool(new BC_Title(5, y + 10, _("ms of reflections:")));
51         add_tool(ref_length = new ReverbRefLength(reverb, x + 35, y)); y += 25;
52         add_tool(new BC_Title(5, y + 10, _("Start band for lowpass:")));
53         add_tool(lowpass1 = new ReverbLowPass1(reverb, x, y)); y += 25;
54         add_tool(new BC_Title(5, y + 10, _("End band for lowpass:")));
55         add_tool(lowpass2 = new ReverbLowPass2(reverb, x + 35, y)); y += 40;
56         show_window();
57         flush();
58         return 0;
61 int ReverbWindow::close_event()
63 // Set result to 1 to indicate a client side close
64         set_done(1);
65         return 1;
72 ReverbLevelInit::ReverbLevelInit(Reverb *reverb, int x, int y)
73  : BC_FPot(x, 
74         y, 
75         reverb->config.level_init, 
76         INFINITYGAIN, 
77         0)
79         this->reverb = reverb;
81 ReverbLevelInit::~ReverbLevelInit() 
84 int ReverbLevelInit::handle_event()
86 //printf("ReverbLevelInit::handle_event 1 %p\n", reverb);
87         reverb->config.level_init = get_value();
88 //printf("ReverbLevelInit::handle_event 1\n");
89         reverb->send_configure_change();
90 //printf("ReverbLevelInit::handle_event 2\n");
91         return 1;
94 ReverbDelayInit::ReverbDelayInit(Reverb *reverb, int x, int y)
95  : BC_IPot(x, 
96         y, 
97         reverb->config.delay_init, 
98         0, 
99         1000)
101         this->reverb = reverb;
103 ReverbDelayInit::~ReverbDelayInit() 
106 int ReverbDelayInit::handle_event()
108         reverb->config.delay_init = get_value();
109         reverb->send_configure_change();
110         return 1;
113 ReverbRefLevel1::ReverbRefLevel1(Reverb *reverb, int x, int y)
114  : BC_FPot(x, 
115         y, 
116         reverb->config.ref_level1, 
117         INFINITYGAIN, 
118         0)
120         this->reverb = reverb;
122 ReverbRefLevel1::~ReverbRefLevel1() {}
123 int ReverbRefLevel1::handle_event()
125         reverb->config.ref_level1 = get_value();
126         reverb->send_configure_change();
127         return 1;
131 ReverbRefLevel2::ReverbRefLevel2(Reverb *reverb, int x, int y)
132  : BC_FPot(x, 
133         y, 
134         reverb->config.ref_level2, 
135         INFINITYGAIN, 
136         0)
138         this->reverb = reverb;
140 ReverbRefLevel2::~ReverbRefLevel2() {}
141 int ReverbRefLevel2::handle_event()
143         reverb->config.ref_level2 = get_value();
144         reverb->send_configure_change();
145         return 1;
148 ReverbRefTotal::ReverbRefTotal(Reverb *reverb, int x, int y)
149  : BC_IPot(x, 
150         y, 
151         reverb->config.ref_total, 
152         1, 
153         250)
155         this->reverb = reverb;
157 ReverbRefTotal::~ReverbRefTotal() {}
158 int ReverbRefTotal::handle_event()
160         reverb->config.ref_total = get_value();
161         reverb->send_configure_change();
162         return 1;
166 ReverbRefLength::ReverbRefLength(Reverb *reverb, int x, int y)
167  : BC_IPot(x, 
168         y, 
169         reverb->config.ref_length, 
170         0, 
171         5000)
173         this->reverb = reverb;
175 ReverbRefLength::~ReverbRefLength() {}
176 int ReverbRefLength::handle_event()
178         reverb->config.ref_length = get_value();
179         reverb->send_configure_change();
180         return 1;
183 ReverbLowPass1::ReverbLowPass1(Reverb *reverb, int x, int y)
184  : BC_QPot(x, 
185         y, 
186         reverb->config.lowpass1)
188         this->reverb = reverb;
190 ReverbLowPass1::~ReverbLowPass1() {}
191 int ReverbLowPass1::handle_event()
193         reverb->config.lowpass1 = get_value();
194         reverb->send_configure_change();
195         return 1;
198 ReverbLowPass2::ReverbLowPass2(Reverb *reverb, int x, int y)
199  : BC_QPot(x, 
200         y, 
201         reverb->config.lowpass2)
203         this->reverb = reverb;
205 ReverbLowPass2::~ReverbLowPass2() {}
206 int ReverbLowPass2::handle_event()
208         reverb->config.lowpass2 = get_value();
209         reverb->send_configure_change();
210         return 1;
213 ReverbMenu::ReverbMenu(Reverb *reverb, ReverbWindow *window)
214  : BC_MenuBar(0, 0, window->get_w())
216         this->window = window;
217         this->reverb = reverb;
220 ReverbMenu::~ReverbMenu()
222         delete load;
223         delete save;
224         //delete set_default;
225         for(int i = 0; i < total_loads; i++)
226         {
227                 delete prev_load[i];
228         }
229         delete prev_load_thread;
232 int ReverbMenu::create_objects(Defaults *defaults)
234         add_menu(filemenu = new BC_Menu(_("File")));
235         filemenu->add_item(load = new ReverbLoad(reverb, this));
236         filemenu->add_item(save = new ReverbSave(reverb, this));
237         //filemenu->add_item(set_default = new ReverbSetDefault);
238         load_defaults(defaults);
239         prev_load_thread = new ReverbLoadPrevThread(reverb, this);
240         return 0;
243 int ReverbMenu::load_defaults(Defaults *defaults)
245         FileSystem fs;
246         total_loads = defaults->get("TOTAL_LOADS", 0);
247         if(total_loads > 0)
248         {
249                 filemenu->add_item(new BC_MenuItem("-"));
250                 char string[1024], path[1024], filename[1024];
251         
252                 for(int i = 0; i < total_loads; i++)
253                 {
254                         sprintf(string, "LOADPREVIOUS%d", i);
255                         defaults->get(string, path);
256                         fs.extract_name(filename, path);
257 //printf("ReverbMenu::load_defaults %s\n", path);
258                         filemenu->add_item(prev_load[i] = new ReverbLoadPrev(reverb, this, filename, path));
259                 }
260         }
261         return 0;
264 int ReverbMenu::save_defaults(Defaults *defaults)
266         if(total_loads > 0)
267         {
268                 defaults->update("TOTAL_LOADS",  total_loads);
269                 char string[1024];
270                 
271                 for(int i = 0; i < total_loads; i++)
272                 {
273                         sprintf(string, "LOADPREVIOUS%d", i);
274                         defaults->update(string, prev_load[i]->path);
275                 }
276         }
277         return 0;
280 int ReverbMenu::add_load(char *path)
282         if(total_loads == 0)
283         {
284                 filemenu->add_item(new BC_MenuItem("-"));
285         }
286         
287 // test for existing copy
288         FileSystem fs;
289         char text[1024], new_path[1024];      // get text and path
290         fs.extract_name(text, path);
291         strcpy(new_path, path);
292         
293         for(int i = 0; i < total_loads; i++)
294         {
295                 if(!strcmp(prev_load[i]->get_text(), text))     // already exists
296                 {                                // swap for top load
297                         for(int j = i; j > 0; j--)   // move preceeding loads down
298                         {
299                                 prev_load[j]->set_text(prev_load[j - 1]->get_text());
300                                 prev_load[j]->set_path(prev_load[j - 1]->path);
301                         }
302                         prev_load[0]->set_text(text);
303                         prev_load[0]->set_path(new_path);
304                         return 1;
305                 }
306         }
307         
308 // add another load
309         if(total_loads < TOTAL_LOADS)
310         {
311                 filemenu->add_item(prev_load[total_loads] = new ReverbLoadPrev(reverb, this));
312                 total_loads++;
313         }
314         
315 // cycle loads down
316         for(int i = total_loads - 1; i > 0; i--)
317         {         
318         // set menu item text
319                 prev_load[i]->set_text(prev_load[i - 1]->get_text());
320         // set filename
321                 prev_load[i]->set_path(prev_load[i - 1]->path);
322         }
324 // set up the new load
325         prev_load[0]->set_text(text);
326         prev_load[0]->set_path(new_path);
327         return 0;
330 ReverbLoad::ReverbLoad(Reverb *reverb, ReverbMenu *menu)
331  : BC_MenuItem(_("Load..."))
333         this->reverb = reverb;
334         this->menu = menu;
335         thread = new ReverbLoadThread(reverb, menu);
337 ReverbLoad::~ReverbLoad()
339         delete thread;
341 int ReverbLoad::handle_event()
343         thread->start();
344         return 0;
347 ReverbSave::ReverbSave(Reverb *reverb, ReverbMenu *menu)
348  : BC_MenuItem(_("Save..."))
350         this->reverb = reverb;
351         this->menu = menu;
352         thread = new ReverbSaveThread(reverb, menu);
354 ReverbSave::~ReverbSave()
356         delete thread;
358 int ReverbSave::handle_event()
360         thread->start();
361         return 0;
364 ReverbSetDefault::ReverbSetDefault()
365  : BC_MenuItem(_("Set default"))
368 int ReverbSetDefault::handle_event()
370         return 0;
373 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu, char *filename, char *path)
374  : BC_MenuItem(filename)
376         this->reverb = reverb;
377         this->menu = menu;
378         strcpy(this->path, path);
380 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu)
381  : BC_MenuItem("")
383         this->reverb = reverb;
384         this->menu = menu;
386 int ReverbLoadPrev::handle_event()
388         menu->prev_load_thread->set_path(path);
389         menu->prev_load_thread->start();
391 int ReverbLoadPrev::set_path(char *path)
393         strcpy(this->path, path);
397 ReverbSaveThread::ReverbSaveThread(Reverb *reverb, ReverbMenu *menu)
398  : Thread()
400         this->reverb = reverb;
401         this->menu = menu;
403 ReverbSaveThread::~ReverbSaveThread()
406 void ReverbSaveThread::run()
408         int result = 0;
409         {
410                 ReverbSaveDialog dialog(reverb);
411                 dialog.create_objects();
412                 result = dialog.run_window();
413 //              if(!result) strcpy(reverb->config_directory, dialog.get_path());
414         }
415         if(!result) 
416         {
417                 result = reverb->save_to_file(reverb->config_directory);
418                 menu->add_load(reverb->config_directory);
419         }
422 ReverbSaveDialog::ReverbSaveDialog(Reverb *reverb)
423  : BC_FileBox(0,
424                         0, 
425                         reverb->config_directory, 
426                         _("Save reverb"), 
427                          _("Select the reverb file to save as")) 
429         this->reverb = reverb;
431 ReverbSaveDialog::~ReverbSaveDialog()
434 int ReverbSaveDialog::ok_event()
436         set_done(0);
437         return 0;
439 int ReverbSaveDialog::cancel_event()
441         set_done(1);
442         return 0;
447 ReverbLoadThread::ReverbLoadThread(Reverb *reverb, ReverbMenu *menu)
448  : Thread()
450         this->reverb = reverb;
451         this->menu = menu;
453 ReverbLoadThread::~ReverbLoadThread()
456 void ReverbLoadThread::run()
458         int result = 0;
459         {
460                 ReverbLoadDialog dialog(reverb);
461                 dialog.create_objects();
462                 result = dialog.run_window();
463 //              if(!result) strcpy(reverb->config_directory, dialog.get_path());
464         }
465         if(!result) 
466         {
467                 result = reverb->load_from_file(reverb->config_directory);
468                 if(!result)
469                 {
470                         menu->add_load(reverb->config_directory);
471                         reverb->send_configure_change();
472                 }
473         }
476 ReverbLoadPrevThread::ReverbLoadPrevThread(Reverb *reverb, ReverbMenu *menu) : Thread()
478         this->reverb = reverb;
479         this->menu = menu;
481 ReverbLoadPrevThread::~ReverbLoadPrevThread()
484 void ReverbLoadPrevThread::run()
486         int result = 0;
487         strcpy(reverb->config_directory, path);
488         result = reverb->load_from_file(path);
489         if(!result)
490         {
491                 menu->add_load(path);
492                 reverb->send_configure_change();
493         }
495 int ReverbLoadPrevThread::set_path(char *path)
497         strcpy(this->path, path);
498         return 0;
505 ReverbLoadDialog::ReverbLoadDialog(Reverb *reverb)
506  : BC_FileBox(0,
507                         0, 
508                         reverb->config_directory, 
509                         _("Load reverb"), 
510                         _("Select the reverb file to load from"), 0, 0)
512         this->reverb = reverb;
514 ReverbLoadDialog::~ReverbLoadDialog()
517 int ReverbLoadDialog::ok_event()
519         set_done(0);
520         return 0;
522 int ReverbLoadDialog::cancel_event()
524         set_done(1);
525         return 0;