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 WINDOW_CLOSE_EVENT(ReverbWindow)
67 ReverbLevelInit::ReverbLevelInit(Reverb *reverb, int x, int y)
70 reverb->config.level_init,
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");
89 ReverbDelayInit::ReverbDelayInit(Reverb *reverb, int x, int y)
92 reverb->config.delay_init,
96 this->reverb = reverb;
98 ReverbDelayInit::~ReverbDelayInit()
101 int ReverbDelayInit::handle_event()
103 reverb->config.delay_init = get_value();
104 reverb->send_configure_change();
108 ReverbRefLevel1::ReverbRefLevel1(Reverb *reverb, int x, int y)
111 reverb->config.ref_level1,
115 this->reverb = reverb;
117 ReverbRefLevel1::~ReverbRefLevel1() {}
118 int ReverbRefLevel1::handle_event()
120 reverb->config.ref_level1 = get_value();
121 reverb->send_configure_change();
126 ReverbRefLevel2::ReverbRefLevel2(Reverb *reverb, int x, int y)
129 reverb->config.ref_level2,
133 this->reverb = reverb;
135 ReverbRefLevel2::~ReverbRefLevel2() {}
136 int ReverbRefLevel2::handle_event()
138 reverb->config.ref_level2 = get_value();
139 reverb->send_configure_change();
143 ReverbRefTotal::ReverbRefTotal(Reverb *reverb, int x, int y)
146 reverb->config.ref_total,
150 this->reverb = reverb;
152 ReverbRefTotal::~ReverbRefTotal() {}
153 int ReverbRefTotal::handle_event()
155 reverb->config.ref_total = get_value();
156 reverb->send_configure_change();
161 ReverbRefLength::ReverbRefLength(Reverb *reverb, int x, int y)
164 reverb->config.ref_length,
168 this->reverb = reverb;
170 ReverbRefLength::~ReverbRefLength() {}
171 int ReverbRefLength::handle_event()
173 reverb->config.ref_length = get_value();
174 reverb->send_configure_change();
178 ReverbLowPass1::ReverbLowPass1(Reverb *reverb, int x, int 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();
193 ReverbLowPass2::ReverbLowPass2(Reverb *reverb, int x, int 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();
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()
219 //delete set_default;
220 for(int i = 0; i < total_loads; i++)
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);
238 int ReverbMenu::load_defaults(BC_Hash *defaults)
241 total_loads = defaults->get("TOTAL_LOADS", 0);
244 filemenu->add_item(new BC_MenuItem("-"));
245 char string[1024], path[1024], filename[1024];
247 for(int i = 0; i < total_loads; i++)
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));
259 int ReverbMenu::save_defaults(BC_Hash *defaults)
263 defaults->update("TOTAL_LOADS", total_loads);
266 for(int i = 0; i < total_loads; i++)
268 sprintf(string, "LOADPREVIOUS%d", i);
269 defaults->update(string, prev_load[i]->path);
275 int ReverbMenu::add_load(char *path)
279 filemenu->add_item(new BC_MenuItem("-"));
282 // test for existing copy
284 char text[1024], new_path[1024]; // get text and path
285 fs.extract_name(text, path);
286 strcpy(new_path, path);
288 for(int i = 0; i < total_loads; i++)
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
294 prev_load[j]->set_text(prev_load[j - 1]->get_text());
295 prev_load[j]->set_path(prev_load[j - 1]->path);
297 prev_load[0]->set_text(text);
298 prev_load[0]->set_path(new_path);
304 if(total_loads < TOTAL_LOADS)
306 filemenu->add_item(prev_load[total_loads] = new ReverbLoadPrev(reverb, this));
311 for(int i = total_loads - 1; i > 0; i--)
313 // set menu item text
314 prev_load[i]->set_text(prev_load[i - 1]->get_text());
316 prev_load[i]->set_path(prev_load[i - 1]->path);
319 // set up the new load
320 prev_load[0]->set_text(text);
321 prev_load[0]->set_path(new_path);
325 ReverbLoad::ReverbLoad(Reverb *reverb, ReverbMenu *menu)
326 : BC_MenuItem(_("Load..."))
328 this->reverb = reverb;
330 thread = new ReverbLoadThread(reverb, menu);
332 ReverbLoad::~ReverbLoad()
336 int ReverbLoad::handle_event()
342 ReverbSave::ReverbSave(Reverb *reverb, ReverbMenu *menu)
343 : BC_MenuItem(_("Save..."))
345 this->reverb = reverb;
347 thread = new ReverbSaveThread(reverb, menu);
349 ReverbSave::~ReverbSave()
353 int ReverbSave::handle_event()
359 ReverbSetDefault::ReverbSetDefault()
360 : BC_MenuItem(_("Set default"))
363 int ReverbSetDefault::handle_event()
368 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu, char *filename, char *path)
369 : BC_MenuItem(filename)
371 this->reverb = reverb;
373 strcpy(this->path, path);
375 ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu)
378 this->reverb = reverb;
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)
395 this->reverb = reverb;
398 ReverbSaveThread::~ReverbSaveThread()
401 void ReverbSaveThread::run()
405 ReverbSaveDialog dialog(reverb);
406 dialog.create_objects();
407 result = dialog.run_window();
408 // if(!result) strcpy(reverb->config_directory, dialog.get_path());
412 result = reverb->save_to_file(reverb->config_directory);
413 menu->add_load(reverb->config_directory);
417 ReverbSaveDialog::ReverbSaveDialog(Reverb *reverb)
420 reverb->config_directory,
422 _("Select the reverb file to save as"))
424 this->reverb = reverb;
426 ReverbSaveDialog::~ReverbSaveDialog()
429 int ReverbSaveDialog::ok_event()
434 int ReverbSaveDialog::cancel_event()
442 ReverbLoadThread::ReverbLoadThread(Reverb *reverb, ReverbMenu *menu)
445 this->reverb = reverb;
448 ReverbLoadThread::~ReverbLoadThread()
451 void ReverbLoadThread::run()
455 ReverbLoadDialog dialog(reverb);
456 dialog.create_objects();
457 result = dialog.run_window();
458 // if(!result) strcpy(reverb->config_directory, dialog.get_path());
462 result = reverb->load_from_file(reverb->config_directory);
465 menu->add_load(reverb->config_directory);
466 reverb->send_configure_change();
471 ReverbLoadPrevThread::ReverbLoadPrevThread(Reverb *reverb, ReverbMenu *menu) : Thread()
473 this->reverb = reverb;
476 ReverbLoadPrevThread::~ReverbLoadPrevThread()
479 void ReverbLoadPrevThread::run()
482 strcpy(reverb->config_directory, path);
483 result = reverb->load_from_file(path);
486 menu->add_load(path);
487 reverb->send_configure_change();
490 int ReverbLoadPrevThread::set_path(char *path)
492 strcpy(this->path, path);
500 ReverbLoadDialog::ReverbLoadDialog(Reverb *reverb)
503 reverb->config_directory,
505 _("Select the reverb file to load from"), 0, 0)
507 this->reverb = reverb;
509 ReverbLoadDialog::~ReverbLoadDialog()
512 int ReverbLoadDialog::ok_event()
517 int ReverbLoadDialog::cancel_event()