4 * Copyright (C) 2008-2019 Adam Williams <broadcast at earthling dot net>
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.
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.
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
21 #include "bcdisplayinfo.h"
23 #include "bcsignals.h"
24 #include "filesystem.h"
28 #include "reverbwindow.h"
34 #define WINDOW_W xS(400)
35 #define WINDOW_H yS(450)
37 ReverbWindow::ReverbWindow(Reverb *reverb)
38 : PluginClientWindow(reverb,
39 WINDOW_W, WINDOW_H, WINDOW_W, WINDOW_H, 0)
41 this->reverb = reverb;
44 ReverbWindow::~ReverbWindow()
46 for( int i = 0; i < TOTAL_PARAMS; i++ )
51 void ReverbWindow::create_objects()
53 int margin = client->get_theme()->widget_border;
54 int x = xS(230), y = margin;
55 int x1 = x + BC_Pot::calculate_w();
56 int x2 = x1 + BC_Pot::calculate_w() + margin;
57 int text_w = get_w() - margin - x2;
58 int height = BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1) + margin;
62 params[i] = new ReverbParam(reverb, this,
63 margin, x, x2, y, text_w,
65 &reverb->config.level_init, // output_f
67 "Initial signal level (db):",
70 params[i]->initialize();
74 params[i] = new ReverbParam(reverb, this,
75 margin, x1, x2, y, text_w,
76 &reverb->config.delay_init, // output_i
79 "ms before reflections:",
81 MAX_DELAY_INIT); // max
82 params[i]->initialize();
86 params[i] = new ReverbParam(reverb, this,
87 margin, x, x2, y, text_w,
89 &reverb->config.ref_level1, // output_f
91 "First reflection level (db):",
94 params[i]->initialize();
98 params[i] = new ReverbParam(reverb, this,
99 margin, x1, x2, y, text_w,
101 &reverb->config.ref_level2, // output_f
103 "Last reflection level (db):",
106 params[i]->initialize();
110 params[i] = new ReverbParam(reverb, this,
111 margin, x, x2, y, text_w,
112 &reverb->config.ref_total, // output_i
115 "Number of reflections:",
116 MIN_REFLECTIONS, // min
117 MAX_REFLECTIONS); // max
118 params[i]->initialize();
122 params[i] = new ReverbParam(reverb, this,
123 margin, x1, x2, y, text_w,
124 &reverb->config.ref_length, // output_i
127 "ms of reflections:",
129 MAX_REFLENGTH); // max
130 params[i]->initialize();
134 params[i] = new ReverbParam(reverb, this,
135 margin, x, x2, y, text_w,
138 &reverb->config.low, // output_q
139 "Low freq of bandpass:",
142 params[i]->initialize();
146 params[i] = new ReverbParam(reverb, this,
147 margin, x1, x2, y, text_w,
150 &reverb->config.high, // output_q
151 "High freq of bandpass:",
154 params[i]->initialize();
158 params[i] = new ReverbParam(reverb, this,
159 margin, x, x2, y, text_w,
161 &reverb->config.q, // output_f
163 "Steepness of bandpass:",
166 params[i]->initialize();
167 params[i]->fpot->set_precision(0.01);
169 y += BC_Pot::calculate_h() + margin;
173 add_subwindow(title = new BC_Title(margin, y, _("Window:")));
174 add_subwindow(size = new ReverbSize(this, reverb,
175 margin + title->get_w() + margin, y));
176 size->create_objects();
177 size->update(reverb->config.window_size);
178 y += size->get_h() + margin;
182 int canvas_w = get_w() - margin;
183 int canvas_h = get_h() - canvas_y - margin;
184 canvas = new EQCanvas(this,
185 canvas_x, canvas_y, canvas_w, canvas_h,
187 canvas->initialize();
193 void ReverbWindow::update()
195 for( int i = 0; i < TOTAL_PARAMS; i++ )
196 params[i]->update(1, 1);
197 size->update(reverb->config.window_size);
202 void ReverbWindow::update_canvas()
204 double tracking_position = reverb->get_tracking_position();
205 CompressorFreqFrame *frame = (CompressorFreqFrame *)
206 reverb->get_gui_frame(tracking_position, 1);
207 canvas->update_spectrogram(frame, -1, -1, -1);
210 reverb->calculate_envelope();
211 canvas->draw_envelope(reverb->envelope,
212 reverb->PluginAClient::project_sample_rate,
213 reverb->config.window_size, 1, 0);
214 BC_SubWindow *gui = canvas->canvas;
216 //printf("ReverbWindow::update_canvas %d\n", __LINE__);
220 ReverbSize::ReverbSize(ReverbWindow *window, Reverb *plugin, int x, int y)
221 : BC_PopupMenu(x, y, xS(100), "4096", 1)
223 this->plugin = plugin;
224 this->window = window;
227 int ReverbSize::handle_event()
229 plugin->config.window_size = atoi(get_text());
230 plugin->send_configure_change();
232 window->update_canvas();
236 void ReverbSize::create_objects()
238 add_item(new BC_MenuItem("2048"));
239 add_item(new BC_MenuItem("4096"));
240 add_item(new BC_MenuItem("8192"));
241 add_item(new BC_MenuItem("16384"));
242 add_item(new BC_MenuItem("32768"));
243 add_item(new BC_MenuItem("65536"));
244 add_item(new BC_MenuItem("131072"));
245 add_item(new BC_MenuItem("262144"));
248 void ReverbSize::update(int size)
250 char string[BCTEXTLEN];
251 sprintf(string, "%d", size);
256 ReverbParam::ReverbParam(Reverb *reverb, ReverbWindow *gui,
257 int x, int x2, int x3, int y, int text_w,
259 float *output_f, // floating point output
261 const char *title, float min, float max)
263 this->output_i = output_i;
264 this->output_f = output_f;
265 this->output_q = output_q;
266 this->title = cstrdup(title);
267 this->reverb = reverb;
273 this->text_w = text_w;
282 ReverbParam::~ReverbParam()
291 void ReverbParam::initialize()
294 int y2 = y + (BC_Pot::calculate_h() -
295 BC_Title::calculate_h(gui, _(title), MEDIUMFONT)) / 2;
296 gui->add_tool(title_ = new BC_Title(x, y2, _(title)));
298 if( output_f ) gui->add_tool(fpot = new ReverbFPot(this, x2, y));
299 if( output_i ) gui->add_tool(ipot = new ReverbIPot(this, x2, y));
300 if( output_q ) gui->add_tool(qpot = new ReverbQPot(this, x2, y));
302 int y3 = y + (BC_Pot::calculate_h() -
303 BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1)) / 2;
305 gui->add_tool(text = new ReverbText(this, x3, y3, text_w, *output_i));
307 gui->add_tool(text = new ReverbText(this, x3, y3, text_w, *output_f));
309 gui->add_tool(text = new ReverbText(this, x3, y3, text_w, *output_q));
312 void ReverbParam::update(int skip_text, int skip_pot)
315 if( output_i ) text->update((int64_t)*output_i);
316 if( output_q ) text->update((int64_t)*output_q);
317 if( output_f ) text->update((float)*output_f);
321 if( ipot ) ipot->update((int64_t)*output_i);
322 if( qpot ) ipot->update((int64_t)*output_q);
323 if( fpot ) ipot->update((float)*output_f);
328 ReverbFPot::ReverbFPot(ReverbParam *param, int x, int y)
329 : BC_FPot(x, y, *param->output_f, param->min, param->max)
335 int ReverbFPot::handle_event()
337 *param->output_f = get_value();
339 param->reverb->send_configure_change();
340 param->gui->update_canvas();
345 ReverbIPot::ReverbIPot(ReverbParam *param, int x, int y)
346 : BC_IPot(x, y, *param->output_i, (int)param->min, (int)param->max)
352 int ReverbIPot::handle_event()
354 *param->output_i = get_value();
356 param->reverb->send_configure_change();
357 param->gui->update_canvas();
362 ReverbQPot::ReverbQPot(ReverbParam *param, int x, int y)
363 : BC_QPot(x, y, *param->output_q)
369 int ReverbQPot::handle_event()
371 *param->output_q = get_value();
373 param->reverb->send_configure_change();
374 param->gui->update_canvas();
379 ReverbText::ReverbText(ReverbParam *param, int x, int y, int text_w, int value)
380 : BC_TextBox(x, y, text_w, 1, (int64_t)value, 1, MEDIUMFONT)
385 ReverbText::ReverbText(ReverbParam *param, int x, int y, int text_w, float value)
386 : BC_TextBox(x, y, text_w, 1, (float)value, 1, MEDIUMFONT, 2)
391 int ReverbText::handle_event()
393 if( param->output_i ) *param->output_i = atoi(get_text());
394 if( param->output_f ) *param->output_f = atof(get_text());
395 if( param->output_q ) *param->output_q = atoi(get_text());
398 param->reverb->send_configure_change();
399 param->gui->update_canvas();