Debian Codegraph @

plugins/dragonfly-room-reverb/Plugin.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 "Plugin.hpp"
18 #include "DistrhoPluginInfo.h"
19 #include "DragonflyVersion.h"
20
21 START_NAMESPACE_DISTRHO
22
23 DragonflyReverbPlugin::DragonflyReverbPlugin() : Plugin(paramCount, 0, 1), dsp(getSampleRate()) {
24 bank = DEFAULT_BANK;
25 preset = DEFAULT_PRESET;
26 }
27
28 // -----------------------------------------------------------------------
29 // Init
30
31 void DragonflyReverbPlugin::initAudioPort(bool input, uint32_t index, AudioPort& port) {
32 // treat audio ports as stereo
33 port.groupId = kPortGroupStereo;
34
35 // everything else is as default
36 Plugin::initAudioPort(input, index, port);
37 }
38
39 void DragonflyReverbPlugin::initParameter(uint32_t index, Parameter& parameter) {
40 if (index < paramCount) {
41 parameter.hints = kParameterIsAutomatable;
42 parameter.name = PARAMS[index].name;
43 parameter.symbol = PARAMS[index].symbol;
44 parameter.ranges.min = PARAMS[index].range_min;
45 parameter.ranges.def = banks[DEFAULT_BANK].presets[DEFAULT_PRESET].params[index];
46 parameter.ranges.max = PARAMS[index].range_max;
47 parameter.unit = PARAMS[index].unit;
48 }
49 }
50
51 void DragonflyReverbPlugin::initState(uint32_t index, State& state) {
52 if (index == 0) {
53 state.key = "preset";
54 state.defaultValue = "Medium Clear Room";
55 }
56 }
57
58 // -----------------------------------------------------------------------
59 // Internal data
60
61 float DragonflyReverbPlugin::getParameterValue(uint32_t index) const {
62 return dsp.getParameterValue(index);
63 }
64
65 void DragonflyReverbPlugin::setParameterValue(uint32_t index, float value) {
66 dsp.setParameterValue(index, value);
67 }
68
69 void DragonflyReverbPlugin::setState(const char* key, const char* value) {
70 if (std::strcmp(key, "preset") == 0) {
71 for (int b = 0; b < NUM_BANKS; b++) {
72 for (int p = 0; p < PRESETS_PER_BANK; p++) {
73 if (std::strcmp(value, banks[b].presets[p].name) == 0) {
74 bank = b;
75 preset = p;
76 }
77 }
78 }
79 }
80 }
81
82 // -----------------------------------------------------------------------
83 // Process
84
85 void DragonflyReverbPlugin::activate() {
86 sampleRateChanged(getSampleRate());
87 }
88
89 void DragonflyReverbPlugin::run(const float** inputs, float** outputs, uint32_t frames) {
90 dsp.run(inputs, outputs, frames);
91 }
92
93 // -----------------------------------------------------------------------
94 // Callbacks
95
96 void DragonflyReverbPlugin::sampleRateChanged(double newSampleRate) {
97 dsp.sampleRateChanged(newSampleRate);
98 }
99
100 // -----------------------------------------------------------------------
101
102 Plugin* createPlugin() {
103 return new DragonflyReverbPlugin();
104 }
105
106 // -----------------------------------------------------------------------
107
108 END_NAMESPACE_DISTRHO