r1007: Make configure detect and work on amd64.
[cinelerra_cv/mob.git] / plugins / reverb / reverbwindow.C
blobcb8bb29a11e4074cb3aa30f2989e8304260b75aa
1 #include "bcdisplayinfo.h"
2 #include "bchash.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 WINDOW_CLOSE_EVENT(ReverbWindow)
67 ReverbLevelInit::ReverbLevelInit(Reverb *reverb, int x, int y)
68  : BC_FPot(x, 
69         y, 
70         reverb->config.level_init, 
71         INFINITYGAIN, 
72         0)
74         this->reverb = reverb;
76 ReverbLevelInit::~ReverbLevelInit() 
79 int ReverbLevelInit::handle_event()
81 //printf("ReverbLevelInit::handle_event 1 %p\n", reverb);
82         reverb->config.level_init = get_value();
83 //printf("ReverbLevelInit::handle_event 1\n");
84         reverb->send_configure_change();
85 //printf("ReverbLevelInit::handle_event 2\n");
86         return 1;
89 ReverbDelayInit::ReverbDelayInit(Reverb *reverb, int x, int y)
90  : BC_IPot(x, 
91         y, 
92         reverb->config.delay_init, 
93         0, 
94         1000)
96         this->reverb = reverb;
98 ReverbDelayInit::~ReverbDelayInit() 
101 int ReverbDelayInit::handle_event()
103         reverb->config.delay_init = get_value();
104         reverb->send_configure_change();
105         return 1;
108 ReverbRefLevel1::ReverbRefLevel1(Reverb *reverb, int x, int y)
109  : BC_FPot(x, 
110         y, 
111         reverb->config.ref_level1, 
112         INFINITYGAIN, 
113         0)
115         this->reverb = reverb;
117 ReverbRefLevel1::~ReverbRefLevel1() {}
118 int ReverbRefLevel1::handle_event()
120         reverb->config.ref_level1 = get_value();
121         reverb->send_configure_change();
122         return 1;
126 ReverbRefLevel2::ReverbRefLevel2(Reverb *reverb, int x, int y)
127  : BC_FPot(x, 
128         y, 
129         reverb->config.ref_level2, 
130         INFINITYGAIN, 
131         0)
133         this->reverb = reverb;
135 ReverbRefLevel2::~ReverbRefLevel2() {}
136 int ReverbRefLevel2::handle_event()
138         reverb->config.ref_level2 = get_value();
139         reverb->send_configure_change();
140         return 1;
143 ReverbRefTotal::ReverbRefTotal(Reverb *reverb, int x, int y)
144  : BC_IPot(x, 
145         y, 
146         reverb->config.ref_total, 
147         1, 
148         250)
150         this->reverb = reverb;
152 ReverbRefTotal::~ReverbRefTotal() {}
153 int ReverbRefTotal::handle_event()
155         reverb->config.ref_total = get_value();
156         reverb->send_configure_change();
157         return 1;
161 ReverbRefLength::ReverbRefLength(Reverb *reverb, int x, int y)
162  : BC_IPot(x, 
163         y, 
164         reverb->config.ref_length, 
165         0, 
166         5000)
168         this->reverb = reverb;
170 ReverbRefLength::~ReverbRefLength() {}
171 int ReverbRefLength::handle_event()
173         reverb->config.ref_length = get_value();
174         reverb->send_configure_change();
175         return 1;
178 ReverbLowPass1::ReverbLowPass1(Reverb *reverb, int x, int y)
179  : BC_QPot(x, 
180         y, 
181         reverb->config.lowpass1)
183         this->reverb = reverb;
185 ReverbLowPass1::~ReverbLowPass1() {}
186 int ReverbLowPass1::handle_event()
188         reverb->config.lowpass1 = get_value();
189         reverb->send_configure_change();
190         return 1;
193 ReverbLowPass2::ReverbLowPass2(Reverb *reverb, int x, int y)
194  : BC_QPot(x, 
195         y, 
196         reverb->config.lowpass2)
198         this->reverb = reverb;
200 ReverbLowPass2::~ReverbLowPass2() {}
201 int ReverbLowPass2::handle_event()
203         reverb->config.lowpass2 = get_value();
204         reverb->send_configure_change();
205         return 1;
208 ReverbMenu::ReverbMenu(Reverb *reverb, ReverbWindow *window)
209  : BC_MenuBar(0, 0, window->get_w())
211         this->window = window;
212         this->reverb = reverb;
215 ReverbMenu::~ReverbMenu()
217         delete load;
218         delete save;
219         //delete set_default;
220         for(int i = 0; i < total_loads; i++)
221         {
222                 delete prev_load[i];
223         }
224         delete prev_load_thread;
227 int ReverbMenu::create_objects(BC_Hash *defaults)
229         add_menu(filemenu = new BC_Menu(_("File")));
230         filemenu->add_item(load = new ReverbLoad(reverb, this));
231         filemenu->add_item(save = new ReverbSave(reverb, this));
232         //filemenu->add_item(set_default = new ReverbSetDefault);
233         load_defaults(defaults);
234         prev_load_thread = new ReverbLoadPrevThread(reverb, this);
235         return 0;
238 int ReverbMenu::load_defaults(BC_Hash *defaults)
240         FileSystem fs;
241         total_loads = defaults->get("TOTAL_LOADS", 0);
242         if(total_loads > 0)
243         {
244                 filemenu->add_item(new BC_MenuItem("-"));
245                 char string[1024], path[1024], filename[1024];
246         
247                 for(int i = 0; i < total_loads; i++)
248                 {
249                         sprintf(string, "LOADPREVIOUS%d", i);
250                         defaults->get(string, path);
251                         fs.extract_name(filename, path);
252 //printf("ReverbMenu::load_defaults %s\n", path);
253                         filemenu->add_item(prev_load[i] = new ReverbLoadPrev(reverb, this, filename, path));
254                 }
255         }
256         return 0;
259 int ReverbMenu::save_defaults(BC_Hash *defaults)
261         if(total_loads > 0)
262         {
263                 defaults->update("TOTAL_LOADS",  total_loads);
264                 char string[1024];
265                 
266                 for(int i = 0; i < total_loads; i++)
267                 {
268                         sprintf(string, "LOADPREVIOUS%d", i);
269                         defaults->update(string, prev_load[i]->path);
270                 }
271         }
272         return 0;
275 int ReverbMenu::add_load(char *path)
277         if(total_loads == 0)
278         {
279                 filemenu->add_item(new BC_MenuItem("-"));
280         }
281         
282 // test for existing copy
283         FileSystem fs;
284         char text[1024], new_path[1024];      // get text and path
285         fs.extract_name(text, path);
286         strcpy(new_path, path);
287         
288         for(int i = 0; i < total_loads; i++)
289         {
290                 if(!strcmp(prev_load[i]->get_text(), text))     // already exists
291                 {                                // swap for top load
292                         for(int j = i; j > 0; j--)   // move preceeding loads down
293                         {
294                                 prev_load[j]->set_text(prev_load[j - 1]->get_text());
295                                 prev_load[j]->set_path(prev_load[j - 1]->path);
296                         }
297                         prev_load[0]->set_text(text);
298                         prev_load[0]->set_path(new_path);
299                         return 1;
300                 }
301         }
302         
303 // add another load
304         if(total_loads < TOTAL_LOADS)
305         {
306                 filemenu->add_item(prev_load[total_loads] = new ReverbLoadPrev(reverb, this));
307                 total_loads++;
308         }
309         
310 // cycle loads down
311         for(int i = total_loads - 1; i > 0; i--)
312         {         
313         // set menu item text
314                 prev_load[i]->set_text(prev_load[i - 1]->get_text());
315         // set filename
316                 prev_load[i]->set_path(prev_load[i - 1]->path);
317         }
319 // set up the new load
320         prev_load[0]->set_text(text);
321         prev_load[0]->set_path(new_path);
322         return 0;
325 ReverbLoad::ReverbLoad(Reverb *reverb, ReverbMenu *menu)
326  : BC_MenuItem(_("Load..."))
328         this->reverb = reverb;
329         this->menu = menu;
330         thread = new ReverbLoadThread(reverb, menu);
332 ReverbLoad::~ReverbLoad()
334         delete thread;
336 int ReverbLoad::handle_event()
338         thread->start();
339         return 0;
342 ReverbSave::ReverbSave(Reverb *reverb, ReverbMenu *menu)
343  : BC_MenuItem(_("Save..."))
345         this->reverb = reverb;
346         this->menu = menu;
347         thread = new ReverbSaveThread(reverb, menu);
349 ReverbSave::~ReverbSave()
351         delete thread;
353 int ReverbSave::handle_event()
355         thread->start();
356         return 0;
359 ReverbSetDefault::ReverbSetDefault()
360  : BC_MenuItem(_("Set default"))
363 int ReverbSetDefault::handle_event()
365         return 0;
368 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu, char *filename, char *path)
369  : BC_MenuItem(filename)
371         this->reverb = reverb;
372         this->menu = menu;
373         strcpy(this->path, path);
375 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu)
376  : BC_MenuItem("")
378         this->reverb = reverb;
379         this->menu = menu;
381 int ReverbLoadPrev::handle_event()
383         menu->prev_load_thread->set_path(path);
384         menu->prev_load_thread->start();
386 int ReverbLoadPrev::set_path(char *path)
388         strcpy(this->path, path);
392 ReverbSaveThread::ReverbSaveThread(Reverb *reverb, ReverbMenu *menu)
393  : Thread()
395         this->reverb = reverb;
396         this->menu = menu;
398 ReverbSaveThread::~ReverbSaveThread()
401 void ReverbSaveThread::run()
403         int result = 0;
404         {
405                 ReverbSaveDialog dialog(reverb);
406                 dialog.create_objects();
407                 result = dialog.run_window();
408 //              if(!result) strcpy(reverb->config_directory, dialog.get_path());
409         }
410         if(!result) 
411         {
412                 result = reverb->save_to_file(reverb->config_directory);
413                 menu->add_load(reverb->config_directory);
414         }
417 ReverbSaveDialog::ReverbSaveDialog(Reverb *reverb)
418  : BC_FileBox(0,
419                         0, 
420                         reverb->config_directory, 
421                         _("Save reverb"), 
422                          _("Select the reverb file to save as")) 
424         this->reverb = reverb;
426 ReverbSaveDialog::~ReverbSaveDialog()
429 int ReverbSaveDialog::ok_event()
431         set_done(0);
432         return 0;
434 int ReverbSaveDialog::cancel_event()
436         set_done(1);
437         return 0;
442 ReverbLoadThread::ReverbLoadThread(Reverb *reverb, ReverbMenu *menu)
443  : Thread()
445         this->reverb = reverb;
446         this->menu = menu;
448 ReverbLoadThread::~ReverbLoadThread()
451 void ReverbLoadThread::run()
453         int result = 0;
454         {
455                 ReverbLoadDialog dialog(reverb);
456                 dialog.create_objects();
457                 result = dialog.run_window();
458 //              if(!result) strcpy(reverb->config_directory, dialog.get_path());
459         }
460         if(!result) 
461         {
462                 result = reverb->load_from_file(reverb->config_directory);
463                 if(!result)
464                 {
465                         menu->add_load(reverb->config_directory);
466                         reverb->send_configure_change();
467                 }
468         }
471 ReverbLoadPrevThread::ReverbLoadPrevThread(Reverb *reverb, ReverbMenu *menu) : Thread()
473         this->reverb = reverb;
474         this->menu = menu;
476 ReverbLoadPrevThread::~ReverbLoadPrevThread()
479 void ReverbLoadPrevThread::run()
481         int result = 0;
482         strcpy(reverb->config_directory, path);
483         result = reverb->load_from_file(path);
484         if(!result)
485         {
486                 menu->add_load(path);
487                 reverb->send_configure_change();
488         }
490 int ReverbLoadPrevThread::set_path(char *path)
492         strcpy(this->path, path);
493         return 0;
500 ReverbLoadDialog::ReverbLoadDialog(Reverb *reverb)
501  : BC_FileBox(0,
502                         0, 
503                         reverb->config_directory, 
504                         _("Load reverb"), 
505                         _("Select the reverb file to load from"), 0, 0)
507         this->reverb = reverb;
509 ReverbLoadDialog::~ReverbLoadDialog()
512 int ReverbLoadDialog::ok_event()
514         set_done(0);
515         return 0;
517 int ReverbLoadDialog::cancel_event()
519         set_done(1);
520         return 0;