1 #include "bcdisplayinfo.h"
3 #include "filesystem.h"
5 #include "reverbwindow.h"
9 PLUGIN_THREAD_OBJECT(Reverb, ReverbThread, ReverbWindow)
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,
30 this->reverb = reverb;
33 ReverbWindow::~ReverbWindow()
37 int ReverbWindow::create_objects()
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;
61 int ReverbWindow::close_event()
63 // Set result to 1 to indicate a client side close
72 ReverbLevelInit::ReverbLevelInit(Reverb *reverb, int x, int y)
75 reverb->config.level_init,
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");
94 ReverbDelayInit::ReverbDelayInit(Reverb *reverb, int x, int y)
97 reverb->config.delay_init,
101 this->reverb = reverb;
103 ReverbDelayInit::~ReverbDelayInit()
106 int ReverbDelayInit::handle_event()
108 reverb->config.delay_init = get_value();
109 reverb->send_configure_change();
113 ReverbRefLevel1::ReverbRefLevel1(Reverb *reverb, int x, int y)
116 reverb->config.ref_level1,
120 this->reverb = reverb;
122 ReverbRefLevel1::~ReverbRefLevel1() {}
123 int ReverbRefLevel1::handle_event()
125 reverb->config.ref_level1 = get_value();
126 reverb->send_configure_change();
131 ReverbRefLevel2::ReverbRefLevel2(Reverb *reverb, int x, int y)
134 reverb->config.ref_level2,
138 this->reverb = reverb;
140 ReverbRefLevel2::~ReverbRefLevel2() {}
141 int ReverbRefLevel2::handle_event()
143 reverb->config.ref_level2 = get_value();
144 reverb->send_configure_change();
148 ReverbRefTotal::ReverbRefTotal(Reverb *reverb, int x, int y)
151 reverb->config.ref_total,
155 this->reverb = reverb;
157 ReverbRefTotal::~ReverbRefTotal() {}
158 int ReverbRefTotal::handle_event()
160 reverb->config.ref_total = get_value();
161 reverb->send_configure_change();
166 ReverbRefLength::ReverbRefLength(Reverb *reverb, int x, int y)
169 reverb->config.ref_length,
173 this->reverb = reverb;
175 ReverbRefLength::~ReverbRefLength() {}
176 int ReverbRefLength::handle_event()
178 reverb->config.ref_length = get_value();
179 reverb->send_configure_change();
183 ReverbLowPass1::ReverbLowPass1(Reverb *reverb, int x, int 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();
198 ReverbLowPass2::ReverbLowPass2(Reverb *reverb, int x, int 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();
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()
224 //delete set_default;
225 for(int i = 0; i < total_loads; i++)
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);
243 int ReverbMenu::load_defaults(Defaults *defaults)
246 total_loads = defaults->get("TOTAL_LOADS", 0);
249 filemenu->add_item(new BC_MenuItem("-"));
250 char string[1024], path[1024], filename[1024];
252 for(int i = 0; i < total_loads; i++)
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));
264 int ReverbMenu::save_defaults(Defaults *defaults)
268 defaults->update("TOTAL_LOADS", total_loads);
271 for(int i = 0; i < total_loads; i++)
273 sprintf(string, "LOADPREVIOUS%d", i);
274 defaults->update(string, prev_load[i]->path);
280 int ReverbMenu::add_load(char *path)
284 filemenu->add_item(new BC_MenuItem("-"));
287 // test for existing copy
289 char text[1024], new_path[1024]; // get text and path
290 fs.extract_name(text, path);
291 strcpy(new_path, path);
293 for(int i = 0; i < total_loads; i++)
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
299 prev_load[j]->set_text(prev_load[j - 1]->get_text());
300 prev_load[j]->set_path(prev_load[j - 1]->path);
302 prev_load[0]->set_text(text);
303 prev_load[0]->set_path(new_path);
309 if(total_loads < TOTAL_LOADS)
311 filemenu->add_item(prev_load[total_loads] = new ReverbLoadPrev(reverb, this));
316 for(int i = total_loads - 1; i > 0; i--)
318 // set menu item text
319 prev_load[i]->set_text(prev_load[i - 1]->get_text());
321 prev_load[i]->set_path(prev_load[i - 1]->path);
324 // set up the new load
325 prev_load[0]->set_text(text);
326 prev_load[0]->set_path(new_path);
330 ReverbLoad::ReverbLoad(Reverb *reverb, ReverbMenu *menu)
331 : BC_MenuItem(_("Load..."))
333 this->reverb = reverb;
335 thread = new ReverbLoadThread(reverb, menu);
337 ReverbLoad::~ReverbLoad()
341 int ReverbLoad::handle_event()
347 ReverbSave::ReverbSave(Reverb *reverb, ReverbMenu *menu)
348 : BC_MenuItem(_("Save..."))
350 this->reverb = reverb;
352 thread = new ReverbSaveThread(reverb, menu);
354 ReverbSave::~ReverbSave()
358 int ReverbSave::handle_event()
364 ReverbSetDefault::ReverbSetDefault()
365 : BC_MenuItem(_("Set default"))
368 int ReverbSetDefault::handle_event()
373 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu, char *filename, char *path)
374 : BC_MenuItem(filename)
376 this->reverb = reverb;
378 strcpy(this->path, path);
380 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu)
383 this->reverb = reverb;
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)
400 this->reverb = reverb;
403 ReverbSaveThread::~ReverbSaveThread()
406 void ReverbSaveThread::run()
410 ReverbSaveDialog dialog(reverb);
411 dialog.create_objects();
412 result = dialog.run_window();
413 if(!result) strcpy(reverb->config_directory, dialog.get_path());
417 result = reverb->save_to_file(reverb->config_directory);
418 menu->add_load(reverb->config_directory);
422 ReverbSaveDialog::ReverbSaveDialog(Reverb *reverb)
425 reverb->config_directory,
427 _("Select the reverb file to save as"), 0, 0)
429 this->reverb = reverb;
431 ReverbSaveDialog::~ReverbSaveDialog()
434 int ReverbSaveDialog::ok_event()
439 int ReverbSaveDialog::cancel_event()
447 ReverbLoadThread::ReverbLoadThread(Reverb *reverb, ReverbMenu *menu)
450 this->reverb = reverb;
453 ReverbLoadThread::~ReverbLoadThread()
456 void ReverbLoadThread::run()
460 ReverbLoadDialog dialog(reverb);
461 dialog.create_objects();
462 result = dialog.run_window();
463 if(!result) strcpy(reverb->config_directory, dialog.get_path());
467 result = reverb->load_from_file(reverb->config_directory);
470 menu->add_load(reverb->config_directory);
471 reverb->send_configure_change();
476 ReverbLoadPrevThread::ReverbLoadPrevThread(Reverb *reverb, ReverbMenu *menu) : Thread()
478 this->reverb = reverb;
481 ReverbLoadPrevThread::~ReverbLoadPrevThread()
484 void ReverbLoadPrevThread::run()
487 strcpy(reverb->config_directory, path);
488 result = reverb->load_from_file(path);
491 menu->add_load(path);
492 reverb->send_configure_change();
495 int ReverbLoadPrevThread::set_path(char *path)
497 strcpy(this->path, path);
505 ReverbLoadDialog::ReverbLoadDialog(Reverb *reverb)
508 reverb->config_directory,
510 _("Select the reverb file to load from"), 0, 0)
512 this->reverb = reverb;
514 ReverbLoadDialog::~ReverbLoadDialog()
517 int ReverbLoadDialog::ok_event()
522 int ReverbLoadDialog::cancel_event()