add6ab4588c769ed9bcbff3ac901cd28600fa558
[goodguy/history.git] / cinelerra-5.1 / plugins / reverb / reverbwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "bchash.h"
24 #include "bcsignals.h"
25 #include "filesystem.h"
26 #include "language.h"
27 #include "reverb.h"
28 #include "reverbwindow.h"
29
30 #include <string.h>
31
32
33
34 ReverbWindow::ReverbWindow(Reverb *reverb)
35  : PluginClientWindow(reverb,
36         300, 
37         230, 
38         300, 
39         230,
40         0)
41 {
42         this->reverb = reverb;
43 }
44
45 ReverbWindow::~ReverbWindow()
46 {
47 }
48
49 void ReverbWindow::create_objects()
50 {
51         int x = 200, y = 10;
52         add_tool(new BC_Title(5, y + 10, _("Initial signal level:")));
53         add_tool(level_init = new ReverbLevelInit(reverb, x, y)); y += 25;
54         add_tool(new BC_Title(5, y + 10, _("ms before reflections:")));
55         add_tool(delay_init = new ReverbDelayInit(reverb, x + 35, y)); y += 25;
56         add_tool(new BC_Title(5, y + 10, _("First reflection level:")));
57         add_tool(ref_level1 = new ReverbRefLevel1(reverb, x, y)); y += 25;
58         add_tool(new BC_Title(5, y + 10, _("Last reflection level:")));
59         add_tool(ref_level2 = new ReverbRefLevel2(reverb, x + 35, y)); y += 25;
60         add_tool(new BC_Title(5, y + 10, _("Number of reflections:")));
61         add_tool(ref_total = new ReverbRefTotal(reverb, x, y)); y += 25;
62         add_tool(new BC_Title(5, y + 10, _("ms of reflections:")));
63         add_tool(ref_length = new ReverbRefLength(reverb, x + 35, y)); y += 25;
64         add_tool(new BC_Title(5, y + 10, _("Start band for lowpass:")));
65         add_tool(lowpass1 = new ReverbLowPass1(reverb, x, y)); y += 25;
66         add_tool(new BC_Title(5, y + 10, _("End band for lowpass:")));
67         add_tool(lowpass2 = new ReverbLowPass2(reverb, x + 35, y)); y += 40;
68         show_window();
69         flush();
70 }
71
72
73
74
75
76
77 ReverbLevelInit::ReverbLevelInit(Reverb *reverb, int x, int y)
78  : BC_FPot(x,
79         y,
80         reverb->config.level_init,
81         INFINITYGAIN,
82         0)
83 {
84         this->reverb = reverb;
85 }
86 ReverbLevelInit::~ReverbLevelInit()
87 {
88 }
89 int ReverbLevelInit::handle_event()
90 {
91 //printf("ReverbLevelInit::handle_event 1 %p\n", reverb);
92         reverb->config.level_init = get_value();
93 //printf("ReverbLevelInit::handle_event 1\n");
94         reverb->send_configure_change();
95 //printf("ReverbLevelInit::handle_event 2\n");
96         return 1;
97 }
98
99 ReverbDelayInit::ReverbDelayInit(Reverb *reverb, int x, int y)
100  : BC_IPot(x,
101         y,
102         reverb->config.delay_init,
103         0,
104         MAX_DELAY_INIT)
105 {
106         this->reverb = reverb;
107 }
108 ReverbDelayInit::~ReverbDelayInit()
109 {
110 }
111 int ReverbDelayInit::handle_event()
112 {
113         reverb->config.delay_init = get_value();
114         reverb->send_configure_change();
115         return 1;
116 }
117
118 ReverbRefLevel1::ReverbRefLevel1(Reverb *reverb, int x, int y)
119  : BC_FPot(x,
120         y,
121         reverb->config.ref_level1,
122         INFINITYGAIN,
123         0)
124 {
125         this->reverb = reverb;
126 }
127 ReverbRefLevel1::~ReverbRefLevel1() {}
128 int ReverbRefLevel1::handle_event()
129 {
130         reverb->config.ref_level1 = get_value();
131         reverb->send_configure_change();
132         return 1;
133 }
134
135
136 ReverbRefLevel2::ReverbRefLevel2(Reverb *reverb, int x, int y)
137  : BC_FPot(x,
138         y,
139         reverb->config.ref_level2,
140         INFINITYGAIN,
141         0)
142 {
143         this->reverb = reverb;
144 }
145 ReverbRefLevel2::~ReverbRefLevel2() {}
146 int ReverbRefLevel2::handle_event()
147 {
148         reverb->config.ref_level2 = get_value();
149         reverb->send_configure_change();
150         return 1;
151 }
152
153 ReverbRefTotal::ReverbRefTotal(Reverb *reverb, int x, int y)
154  : BC_IPot(x,
155         y,
156         reverb->config.ref_total,
157         MIN_REFLECTIONS,
158         MAX_REFLECTIONS)
159 {
160         this->reverb = reverb;
161 }
162 ReverbRefTotal::~ReverbRefTotal() {}
163 int ReverbRefTotal::handle_event()
164 {
165         reverb->config.ref_total = get_value();
166         reverb->send_configure_change();
167         return 1;
168 }
169
170
171 ReverbRefLength::ReverbRefLength(Reverb *reverb, int x, int y)
172  : BC_IPot(x,
173         y,
174         reverb->config.ref_length,
175         0,
176         MAX_REFLENGTH)
177 {
178         this->reverb = reverb;
179 }
180 ReverbRefLength::~ReverbRefLength() {}
181 int ReverbRefLength::handle_event()
182 {
183         reverb->config.ref_length = get_value();
184         reverb->send_configure_change();
185         return 1;
186 }
187
188 ReverbLowPass1::ReverbLowPass1(Reverb *reverb, int x, int y)
189  : BC_QPot(x,
190         y,
191         reverb->config.lowpass1)
192 {
193         this->reverb = reverb;
194 }
195 ReverbLowPass1::~ReverbLowPass1() {}
196 int ReverbLowPass1::handle_event()
197 {
198         reverb->config.lowpass1 = get_value();
199         reverb->send_configure_change();
200         return 1;
201 }
202
203 ReverbLowPass2::ReverbLowPass2(Reverb *reverb, int x, int y)
204  : BC_QPot(x,
205         y,
206         reverb->config.lowpass2)
207 {
208         this->reverb = reverb;
209 }
210 ReverbLowPass2::~ReverbLowPass2() {}
211 int ReverbLowPass2::handle_event()
212 {
213         reverb->config.lowpass2 = get_value();
214         reverb->send_configure_change();
215         return 1;
216 }
217
218 // ReverbMenu::ReverbMenu(Reverb *reverb, ReverbWindow *window)
219 //  : BC_MenuBar(0, 0, window->get_w())
220 // {
221 //      this->window = window;
222 //      this->reverb = reverb;
223 // }
224 // 
225 // ReverbMenu::~ReverbMenu()
226 // {
227 //      delete load;
228 //      delete save;
229 //      //delete set_default;
230 //      for(int i = 0; i < total_loads; i++)
231 //      {
232 //              delete prev_load[i];
233 //      }
234 //      delete prev_load_thread;
235 // }
236 // 
237 // void ReverbMenu::create_objects(BC_Hash *defaults)
238 // {
239 //      add_menu(filemenu = new BC_Menu(_("File")));
240 //      filemenu->add_item(load = new ReverbLoad(reverb, this));
241 //      filemenu->add_item(save = new ReverbSave(reverb, this));
242 //      //filemenu->add_item(set_default = new ReverbSetDefault);
243 //      load_defaults(defaults);
244 //      prev_load_thread = new ReverbLoadPrevThread(reverb, this);
245 // }
246 // 
247 // int ReverbMenu::load_defaults(BC_Hash *defaults)
248 // {
249 //      FileSystem fs;
250 //      total_loads = defaults->get("TOTAL_LOADS", 0);
251 //      if(total_loads > 0)
252 //      {
253 //              filemenu->add_item(new BC_MenuItem("-"));
254 //              char string[1024], path[1024], filename[1024];
255 //      
256 //              for(int i = 0; i < total_loads; i++)
257 //              {
258 //                      sprintf(string, "LOADPREVIOUS%d", i);
259 //                      defaults->get(string, path);
260 //                      fs.extract_name(filename, path);
261 // //printf("ReverbMenu::load_defaults %s\n", path);
262 //                      filemenu->add_item(prev_load[i] = new ReverbLoadPrev(reverb, this, filename, path));
263 //              }
264 //      }
265 //      return 0;
266 // }
267 // 
268 // int ReverbMenu::save_defaults(BC_Hash *defaults)
269 // {
270 //      if(total_loads > 0)
271 //      {
272 //              defaults->update("TOTAL_LOADS",  total_loads);
273 //              char string[1024];
274 //              
275 //              for(int i = 0; i < total_loads; i++)
276 //              {
277 //                      sprintf(string, "LOADPREVIOUS%d", i);
278 //                      defaults->update(string, prev_load[i]->path);
279 //              }
280 //      }
281 //      return 0;
282 // }
283 // 
284 // int ReverbMenu::add_load(char *path)
285 // {
286 //      if(total_loads == 0)
287 //      {
288 //              filemenu->add_item(new BC_MenuItem("-"));
289 //      }
290 //      
291 // // test for existing copy
292 //      FileSystem fs;
293 //      char text[1024], new_path[1024];      // get text and path
294 //      fs.extract_name(text, path);
295 //      strcpy(new_path, path);
296 //      
297 //      for(int i = 0; i < total_loads; i++)
298 //      {
299 //              if(!strcmp(prev_load[i]->get_text(), text))     // already exists
300 //              {                                // swap for top load
301 //                      for(int j = i; j > 0; j--)   // move preceeding loads down
302 //                      {
303 //                              prev_load[j]->set_text(prev_load[j - 1]->get_text());
304 //                              prev_load[j]->set_path(prev_load[j - 1]->path);
305 //                      }
306 //                      prev_load[0]->set_text(text);
307 //                      prev_load[0]->set_path(new_path);
308 //                      return 1;
309 //              }
310 //      }
311 //      
312 // // add another load
313 //      if(total_loads < TOTAL_LOADS)
314 //      {
315 //              filemenu->add_item(prev_load[total_loads] = new ReverbLoadPrev(reverb, this));
316 //              total_loads++;
317 //      }
318 //      
319 // // cycle loads down
320 //      for(int i = total_loads - 1; i > 0; i--)
321 //      {         
322 //      // set menu item text
323 //              prev_load[i]->set_text(prev_load[i - 1]->get_text());
324 //      // set filename
325 //              prev_load[i]->set_path(prev_load[i - 1]->path);
326 //      }
327 // 
328 // // set up the new load
329 //      prev_load[0]->set_text(text);
330 //      prev_load[0]->set_path(new_path);
331 //      return 0;
332 // }
333 // 
334 // ReverbLoad::ReverbLoad(Reverb *reverb, ReverbMenu *menu)
335 //  : BC_MenuItem(_("Load..."))
336 // {
337 //      this->reverb = reverb;
338 //      this->menu = menu;
339 //      thread = new ReverbLoadThread(reverb, menu);
340 // }
341 // ReverbLoad::~ReverbLoad()
342 // {
343 //      delete thread;
344 // }
345 // int ReverbLoad::handle_event()
346 // {
347 //      thread->start();
348 //      return 0;
349 // }
350 // 
351 // ReverbSave::ReverbSave(Reverb *reverb, ReverbMenu *menu)
352 //  : BC_MenuItem(_("Save..."))
353 // {
354 //      this->reverb = reverb;
355 //      this->menu = menu;
356 //      thread = new ReverbSaveThread(reverb, menu);
357 // }
358 // ReverbSave::~ReverbSave()
359 // {
360 //      delete thread;
361 // }
362 // int ReverbSave::handle_event()
363 // {
364 //      thread->start();
365 //      return 0;
366 // }
367 // 
368 // ReverbSetDefault::ReverbSetDefault()
369 //  : BC_MenuItem(_("Set default"))
370 // {
371 // }
372 // int ReverbSetDefault::handle_event()
373 // {
374 //      return 0;
375 // }
376 // 
377 // ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu, char *filename, char *path)
378 //  : BC_MenuItem(filename)
379 // {
380 //      this->reverb = reverb;
381 //      this->menu = menu;
382 //      strcpy(this->path, path);
383 // }
384 // ReverbLoadPrev::ReverbLoadPrev(Reverb *reverb, ReverbMenu *menu)
385 //  : BC_MenuItem("")
386 // {
387 //      this->reverb = reverb;
388 //      this->menu = menu;
389 // }
390 // int ReverbLoadPrev::handle_event()
391 // {
392 //      menu->prev_load_thread->set_path(path);
393 //      menu->prev_load_thread->start();
394 // }
395 // int ReverbLoadPrev::set_path(char *path)
396 // {
397 //      strcpy(this->path, path);
398 // }
399 // 
400 // 
401 // ReverbSaveThread::ReverbSaveThread(Reverb *reverb, ReverbMenu *menu)
402 //  : Thread()
403 // {
404 //      this->reverb = reverb;
405 //      this->menu = menu;
406 // }
407 // ReverbSaveThread::~ReverbSaveThread()
408 // {
409 // }
410 // void ReverbSaveThread::run()
411 // {
412 //      int result = 0;
413 //      {
414 //              ReverbSaveDialog dialog(reverb);
415 //              dialog.create_objects();
416 //              result = dialog.run_window();
417 // //           if(!result) strcpy(reverb->config_directory, dialog.get_path());
418 //      }
419 //      if(!result) 
420 //      {
421 //              result = reverb->save_to_file(reverb->config_directory);
422 //              menu->add_load(reverb->config_directory);
423 //      }
424 // }
425 // 
426 // ReverbSaveDialog::ReverbSaveDialog(Reverb *reverb)
427 //  : BC_FileBox(0,
428 //                      0, 
429 //                      reverb->config_directory, 
430 //                      _("Save reverb"), 
431 //                      _("Select the reverb file to save as"), 0, 0)
432 // {
433 //      this->reverb = reverb;
434 // }
435 // ReverbSaveDialog::~ReverbSaveDialog()
436 // {
437 // }
438 // int ReverbSaveDialog::ok_event()
439 // {
440 //      set_done(0);
441 //      return 0;
442 // }
443 // int ReverbSaveDialog::cancel_event()
444 // {
445 //      set_done(1);
446 //      return 0;
447 // }
448 // 
449 // 
450 // 
451 // ReverbLoadThread::ReverbLoadThread(Reverb *reverb, ReverbMenu *menu)
452 //  : Thread()
453 // {
454 //      this->reverb = reverb;
455 //      this->menu = menu;
456 // }
457 // ReverbLoadThread::~ReverbLoadThread()
458 // {
459 // }
460 // void ReverbLoadThread::run()
461 // {
462 //      int result = 0;
463 //      {
464 //              ReverbLoadDialog dialog(reverb);
465 //              dialog.create_objects();
466 //              result = dialog.run_window();
467 // //           if(!result) strcpy(reverb->config_directory, dialog.get_path());
468 //      }
469 //      if(!result) 
470 //      {
471 //              result = reverb->load_from_file(reverb->config_directory);
472 //              if(!result)
473 //              {
474 //                      menu->add_load(reverb->config_directory);
475 //                      reverb->send_configure_change();
476 //              }
477 //      }
478 // }
479 // 
480 // ReverbLoadPrevThread::ReverbLoadPrevThread(Reverb *reverb, ReverbMenu *menu) : Thread()
481 // {
482 //      this->reverb = reverb;
483 //      this->menu = menu;
484 // }
485 // ReverbLoadPrevThread::~ReverbLoadPrevThread()
486 // {
487 // }
488 // void ReverbLoadPrevThread::run()
489 // {
490 //      int result = 0;
491 //      strcpy(reverb->config_directory, path);
492 //      result = reverb->load_from_file(path);
493 //      if(!result)
494 //      {
495 //              menu->add_load(path);
496 //              reverb->send_configure_change();
497 //      }
498 // }
499 // int ReverbLoadPrevThread::set_path(char *path)
500 // {
501 //      strcpy(this->path, path);
502 //      return 0;
503 // }
504 // 
505 // 
506 // 
507 // 
508 // 
509 // ReverbLoadDialog::ReverbLoadDialog(Reverb *reverb)
510 //  : BC_FileBox(0,
511 //                      0, 
512 //                      reverb->config_directory, 
513 //                      _("Load reverb"), 
514 //                      _("Select the reverb file to load from"), 0, 0)
515 // {
516 //      this->reverb = reverb;
517 // }
518 // ReverbLoadDialog::~ReverbLoadDialog()
519 // {
520 // }
521 // int ReverbLoadDialog::ok_event()
522 // {
523 //      set_done(0);
524 //      return 0;
525 // }
526 // int ReverbLoadDialog::cancel_event()
527 // {
528 //      set_done(1);
529 //      return 0;
530 // }
531