Debian Codegraph @

plugins/dragonfly-plate-reverb/UI.cpp

raw
1 /*
2 * Dragonfly Reverb, copyright (c) 2019 Michael Willis, Rob van den Berg
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 3 of
7 * the License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * For a full copy of the GNU General Public License see the LICENSE file.
15 */
16
17 #include "DistrhoUI.hpp"
18 #include "DragonflyVersion.h"
19 #include "DSP.hpp"
20 #include "UI.hpp"
21 #include <array>
22 #include <vector>
23 #include <math.h>
24 #include <string>
25
26 START_NAMESPACE_DISTRHO
27
28 namespace Art = Artwork;
29 using DGL::Color;
30
31 static const int knobx[] = {435, 510, 585};
32 static const int knoby[] = {130, 245};
33
34 // -----------------------------------------------------------------------------------------------------------
35 DragonflyReverbUI::DragonflyReverbUI()
36 : DragonflyReverbAbstractUI ( Art::backgroundWidth, Art::backgroundHeight, PARAMS, Art::knobData, Art::knobWidth, Art::knobHeight, Art::questionData, Art::questionWidth, Art::questionHeight),
37 imgBackground ( Art::backgroundData, Art::backgroundWidth, Art::backgroundHeight, kImageFormatBGRA ),
38 imgTabOff ( Art::tab_offData, Art::tab_offWidth, Art::tab_offHeight, kImageFormatBGR ),
39 imgTabOn ( Art::tab_onData, Art::tab_onWidth,Art::tab_onHeight, kImageFormatBGR )
40 {
41 currentPreset = DEFAULT_PRESET;
42 currentAlg = presets[currentPreset].params[paramAlgorithm];
43
44 knobWidth = createLabelledKnob(&params[paramWidth], "%3.0f%%", knobx[0], knoby[0]);
45 knobPredelay = createLabelledKnob(&params[paramPredelay], "%2.0f ms", knobx[1], knoby[0]);
46 knobDecay = createLabelledKnob(&params[paramDecay], "%2.1f s", knobx[2], knoby[0]);
47
48 knobLowCut = createLabelledKnob(&params[paramLowCut], "%4.0f Hz", knobx[0], knoby[1]);
49 knobHighCut = createLabelledKnob(&params[paramHighCut], "%5.0f Hz", knobx[1], knoby[1]);
50 knobDamp = createLabelledKnob(&params[paramDamp], "%5.0f Hz", knobx[2], knoby[1]);
51
52 sliderDry = new ImageSlider ( this, Image ( Art::sliderData, Art::sliderWidth, Art::sliderHeight, kImageFormatBGRA ) );
53 sliderDry->setId ( paramDry );
54 sliderDry->setStartPos ( 17, 157 );
55 sliderDry->setEndPos ( 17, 317 );
56 sliderDry->setRange ( 0.0f, 100.0f );
57 sliderDry->setInverted ( true );
58 sliderDry->setCallback ( this );
59
60 sliderWet = new ImageSlider ( this, Image ( Art::sliderData, Art::sliderWidth, Art::sliderHeight, kImageFormatBGRA ) );
61 sliderWet->setId ( paramWet );
62 sliderWet->setStartPos ( 57, 157 );
63 sliderWet->setEndPos ( 57, 317 );
64 sliderWet->setRange ( 0.0f, 100.0f );
65 sliderWet->setInverted ( true );
66 sliderWet->setCallback ( this );
67
68 rectSliders[0].setPos ( 17, 157 );
69 rectSliders[0].setSize ( 26, 160 );
70 rectSliders[1].setPos ( 57, 157 );
71 rectSliders[1].setSize ( 26, 160 );
72
73 rectDisplay.setPos ( 110, 126 );
74 rectDisplay.setSize ( 305, 207 );
75
76 algorithmSelection = new Selection(this, this, 100, &nanoText, ALGORITHM_COUNT);
77 algorithmSelection->setAbsolutePos(575, 35);
78 algorithmSelection->setSelectedOption(presets[currentPreset].params[paramAlgorithm]);
79 for ( int i = 0; i < ALGORITHM_COUNT; ++i)
80 {
81 algorithmSelection->setOptionName(i, algorithmNames[i]);
82 }
83
84 presetSelection1 = new Selection(this, this, 115, &nanoText, NUM_PRESETS / 2);
85 presetSelection1->setAbsolutePos(340, 25);
86 presetSelection1->setSelectedOption(DEFAULT_PRESET);
87
88 presetSelection2 = new Selection(this, this, 115, &nanoText, NUM_PRESETS / 2);
89 presetSelection2->setAbsolutePos(455, 25);
90 presetSelection2->setSelectedOption(-1);
91
92 for ( int i = 0; i < NUM_PRESETS / 2; ++i)
93 {
94 presetSelection1->setOptionName(i, presets[i].name);
95 presetSelection2->setOptionName(i, presets[i + NUM_PRESETS / 2].name);
96 }
97
98 aboutButton->setAbsolutePos ( 390, 130 );
99
100 AbstractDSP *dsp = new DragonflyReverbDSP(SPECTROGRAM_SAMPLE_RATE);
101 spectrogram = new Spectrogram(this, &nanoText, &rectDisplay, dsp);
102 spectrogram->setAbsolutePos (110, 126);
103 }
104
105 /**
106 A parameter has changed on the plugin side
107 This is called by the host to inform the UI about parameter changes.
108 */
109 void DragonflyReverbUI::parameterChanged ( uint32_t index, float value )
110 {
111 displayAbout = false;
112
113 switch ( index )
114 {
115 case paramDry: sliderDry->setValue ( value ); break;
116 case paramWet: sliderWet->setValue ( value ); break;
117
118 case paramWidth: knobWidth->setValue ( value ); break;
119 case paramPredelay: knobPredelay->setValue ( value ); break;
120 case paramDecay: knobDecay->setValue ( value ); break;
121
122 case paramLowCut: knobLowCut->setValue ( value ); break;
123 case paramHighCut: knobHighCut->setValue ( value ); break;
124 case paramDamp: knobDamp->setValue ( value ); break;
125
126 case paramAlgorithm:
127 algorithmSelection->setSelectedOption( value ); break;
128 }
129
130 if (index != paramDry) {
131 spectrogram->setParameterValue(index, value);
132 }
133 }
134
135 void DragonflyReverbUI::stateChanged(const char* key, const char* value)
136 {
137 if (std::strcmp(key, "preset") == 0) {
138 for (int p = 0; p < NUM_PRESETS; p++) {
139 if (std::strcmp(value, presets[p].name) == 0) {
140 currentPreset = p;
141
142 if (p < NUM_PRESETS / 2) {
143 presetSelection1->setSelectedOption(p);
144 presetSelection2->setSelectedOption(-1);
145 } else {
146 presetSelection2->setSelectedOption(p - NUM_PRESETS / 2);
147 presetSelection1->setSelectedOption(-1);
148 }
149 }
150 }
151
152 updatePresetDefaults();
153 }
154
155 repaint();
156 }
157
158 /* ----------------------------------------------------------------------------------------------------------
159 * Widget Callbacks
160 *----------------------------------------------------------------------------------------------------------*/
161
162 void DragonflyReverbUI::imageKnobDragStarted ( ImageKnob* knob )
163 {
164 editParameter ( knob->getId(), true );
165 }
166
167 void DragonflyReverbUI::imageKnobDragFinished ( ImageKnob* knob )
168 {
169 editParameter ( knob->getId(), false );
170 }
171
172 void DragonflyReverbUI::imageKnobValueChanged ( ImageKnob* knob, float value )
173 {
174 setParameterValue ( knob->getId(),value );
175 spectrogram->setParameterValue ( knob->getId(), value );
176 }
177
178 void DragonflyReverbUI::imageSliderDragStarted ( ImageSlider* slider )
179 {
180 editParameter ( slider->getId(), true );
181 }
182
183 void DragonflyReverbUI::imageSliderDragFinished ( ImageSlider* slider )
184 {
185 editParameter ( slider->getId(), false );
186 }
187
188 void DragonflyReverbUI::imageSliderValueChanged ( ImageSlider* slider, float value )
189 {
190 int SliderID = slider->getId();
191 setParameterValue ( SliderID,value );
192 spectrogram->setParameterValue ( SliderID, value );
193 }
194
195 void DragonflyReverbUI::selectionClicked(Selection* selection, int selectedOption)
196 {
197 bool presetClicked = false;
198 if (selection == algorithmSelection)
199 {
200 currentAlg = selectedOption;
201 algorithmSelection->setSelectedOption(selectedOption);
202 setParameterValue ( paramAlgorithm, selectedOption );
203 spectrogram->setParameterValue( paramAlgorithm, selectedOption);
204 }
205 else if (selection == presetSelection1)
206 {
207 currentPreset = selectedOption;
208 presetSelection1->setSelectedOption(selectedOption);
209 presetSelection2->setSelectedOption(-1);
210 presetClicked = true;
211 }
212 else if (selection == presetSelection2)
213 {
214 currentPreset = selectedOption + NUM_PRESETS / 2;
215 presetSelection2->setSelectedOption(selectedOption);
216 presetSelection1->setSelectedOption(-1);
217 presetClicked = true;
218 }
219
220 if (presetClicked)
221 {
222 setState("preset", presets[currentPreset].name);
223 algorithmSelection->setSelectedOption(presets[currentPreset].params[paramAlgorithm]);
224 updatePresetDefaults();
225
226 const float *preset = presets[currentPreset].params;
227
228 knobWidth->setValue ( preset[paramWidth] );
229 knobPredelay->setValue ( preset[paramPredelay] );
230 knobDecay->setValue ( preset[paramDecay] );
231
232 knobLowCut->setValue ( preset[paramLowCut] );
233 knobHighCut->setValue ( preset[paramHighCut] );
234 knobDamp->setValue ( preset[paramDamp] );
235
236 for ( uint32_t i = 0; i < paramCount; i++ ) {
237 // Don't set sliders
238 if (i != paramDry && i != paramWet) {
239 setParameterValue ( i, preset[i] );
240 spectrogram->setParameterValue(i, preset[i]);
241 }
242 }
243
244 repaint();
245 }
246 }
247
248 void DragonflyReverbUI::onDisplay()
249 {
250 const GraphicsContext& context(getGraphicsContext());
251
252 imgBackground.draw(context);
253
254 float r,g,b;
255 r = 230.0f / 256;
256 g = 230.0f / 256;
257 b = 230.0f / 256;
258
259 // print parameters
260 nanoText.beginFrame ( this );
261 nanoText.fontSize ( 15 );
262 nanoText.textAlign ( NanoVG::ALIGN_CENTER|NanoVG::ALIGN_MIDDLE );
263
264 nanoText.fillColor ( Color ( r, g, b ) );
265
266 char strBuf[32+1];
267 strBuf[32] = '\0';
268
269 std::snprintf ( strBuf, 32, "%i%%", int ( sliderDry->getValue() ) );
270 nanoText.textBox ( 17 - 2, 330, 35.0f, strBuf, nullptr );
271 std::snprintf ( strBuf, 32, "%i%%", int ( sliderWet->getValue() ) );
272 nanoText.textBox ( 57 - 2, 330, 35.0f, strBuf, nullptr );
273
274 // print labels;
275 nanoText.fillColor ( Color ( 0.90f, 0.95f, 1.00f ) );
276 nanoText.fontSize ( 14 );
277 nanoText.textBox ( 10, 130, 40, "Dry\nLevel", nullptr );
278 nanoText.textBox ( 50, 130, 40, "Wet\nLevel", nullptr );
279 nanoText.endFrame();
280
281 //draw faders
282 r = 178.0f/255.f;
283 g = 148.0f/255.f;
284 b = 59.0f/255.f;
285 glColor4f ( r, g, b, 1.0f );
286 uint dry = ( float ( sliderDry->getValue() ) / 100.0 ) * 160.0 + 1.0f;
287 uint wet = ( float ( sliderWet->getValue() ) / 100.0 ) * 160.0 + 1.0f;
288
289 rectSliders[0].setHeight ( dry );
290 rectSliders[0].setY ( 118 + 200 - dry );
291
292 rectSliders[1].setHeight ( wet );
293 rectSliders[1].setY ( 118 + 200 - wet );
294
295 if ( dry > 1 )
296 rectSliders[0].draw(context);
297 if ( wet > 1 )
298 rectSliders[1].draw(context);
299
300 glColor4f ( 1.0f,1.0f,1.0f,1.0f );
301 Color bright = Color ( 0.90f, 0.95f, 1.00f );
302
303 nanoText.beginFrame ( this );
304 nanoText.fontSize ( 15 );
305 nanoText.fillColor(bright);
306 nanoText.textAlign ( NanoVG::ALIGN_CENTER | NanoVG::ALIGN_TOP );
307 nanoText.textBox ( 340, 10, 200, "Presets", nullptr );
308 nanoText.textAlign ( NanoVG::ALIGN_LEFT | NanoVG::ALIGN_TOP );
309 nanoText.textBox ( 575, 10, 100, "Reverb Type", nullptr );
310 nanoText.endFrame();
311
312 if (displayAbout) {
313 spectrogram->hide();
314 nanoText.beginFrame ( this );
315 nanoText.fontSize ( 15 );
316 nanoText.textAlign ( NanoVG::ALIGN_LEFT|NanoVG::ALIGN_TOP );
317
318 r = 230.0f / 256;
319 g = 230.0f / 256;
320 b = 230.0f / 256;
321 nanoText.fillColor ( Color ( r, g, b ) );
322
323 int x = rectDisplay.getX() + 5;
324 int y = rectDisplay.getY() + 5;
325 int w = rectDisplay.getWidth() - 10;
326
327 char textBuffer[400];
328
329 std::snprintf(textBuffer, 400,
330 "Dragonfly Plate is a free reverb effect\n"
331 "based on Freeverb3 NReverb and STRev.\n\n"
332 "Version: %d.%d.%d%s License: GPL 3+\n\n"
333 "• Michael Willis - Plugin Development\n"
334 "• James Peters - Quality Assurance\n"
335 "• Teru Kamogashira - Freeverb3\n"
336 "• \"falkTX\" Coelho - Distrho Plugin Framework",
337 MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION_SUFFIX
338 );
339
340 nanoText.textBox ( x, y, w, textBuffer, nullptr );
341 nanoText.endFrame();
342 }
343 else
344 {
345 spectrogram->show();
346 }
347
348 }
349
350 void DragonflyReverbUI::uiIdle() {
351 spectrogram->uiIdle();
352 }
353
354 void DragonflyReverbUI::updatePresetDefaults() {
355 const float *preset = presets[currentPreset].params;
356
357 currentAlg = preset[paramAlgorithm];
358 algorithmSelection->setSelectedOption(currentAlg);
359
360 knobWidth->setDefault ( preset[paramWidth] );
361 knobPredelay->setDefault ( preset[paramPredelay] );
362 knobDecay->setDefault ( preset[paramDecay] );
363
364 knobLowCut->setDefault ( preset[paramLowCut] );
365 knobHighCut->setDefault ( preset[paramHighCut] );
366 knobDamp->setDefault ( preset[paramDamp] );
367 }
368
369 /* ------------------------------------------------------------------------------------------------------------
370 * UI entry point, called by DPF to create a new UI instance. */
371
372 UI* createUI()
373 {
374 return new DragonflyReverbUI();
375 }
376
377 // -----------------------------------------------------------------------------------------------------------
378
379 END_NAMESPACE_DISTRHO