Debian Codegraph @

plugins/dragonfly-hall-reverb/Plugin.cpp

raw
1 /*
2 * Dragonfly Reverb, a hall-style reverb plugin
3 * Copyright (c) 2018 Michael Willis, Rob van den Berg
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of
8 * the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * For a full copy of the GNU General Public License see the LICENSE file.
16 */
17
18 #include "Plugin.hpp"
19 #include "DistrhoPluginInfo.h"
20 #include "DragonflyVersion.h"
21
22 START_NAMESPACE_DISTRHO
23
24 DragonflyReverbPlugin::DragonflyReverbPlugin() : Plugin(paramCount, 0, 1), dsp(getSampleRate()) {
25 bank = DEFAULT_BANK;
26 preset = DEFAULT_PRESET;
27 }
28
29 // -----------------------------------------------------------------------
30 // Init
31
32 void DragonflyReverbPlugin::initAudioPort(bool input, uint32_t index, AudioPort& port) {
33 // treat audio ports as stereo
34 port.groupId = kPortGroupStereo;
35
36 // everything else is as default
37 Plugin::initAudioPort(input, index, port);
38 }
39
40 void DragonflyReverbPlugin::initParameter(uint32_t index, Parameter& parameter) {
41 if (index < paramCount) {
42 parameter.hints = kParameterIsAutomatable;
43 parameter.name = PARAMS[index].name;
44 parameter.symbol = PARAMS[index].symbol;
45 parameter.ranges.min = PARAMS[index].range_min;
46 parameter.ranges.def = banks[DEFAULT_BANK].presets[DEFAULT_PRESET].params[index];
47 parameter.ranges.max = PARAMS[index].range_max;
48 parameter.unit = PARAMS[index].unit;
49 }
50 }
51
52 void DragonflyReverbPlugin::initState(uint32_t index, State& state) {
53 if (index == 0) {
54 state.key = "preset";
55 state.defaultValue = "Small Clear Hall";
56 }
57 }
58
59 // -----------------------------------------------------------------------
60 // Internal data
61
62 float DragonflyReverbPlugin::getParameterValue(uint32_t index) const {
63 return dsp.getParameterValue(index);
64 }
65
66 void DragonflyReverbPlugin::setParameterValue(uint32_t index, float value) {
67 dsp.setParameterValue(index, value);
68 }
69
70 void DragonflyReverbPlugin::setState(const char* key, const char* value) {
71 if (std::strcmp(key, "preset") == 0) {
72 for (int b = 0; b < NUM_BANKS; b++) {
73 for (int p = 0; p < PRESETS_PER_BANK; p++) {
74 if (std::strcmp(value, banks[b].presets[p].name) == 0) {
75 bank = b;
76 preset = p;
77
78 // backward compatibility
79 setParameterValue(paramDecay, banks[b].presets[p].params[paramDecay]);
80 }
81 }
82 }
83 }
84 }
85
86 // -----------------------------------------------------------------------
87 // Process
88
89 void DragonflyReverbPlugin::activate() {
90 sampleRateChanged(getSampleRate());
91 }
92
93 void DragonflyReverbPlugin::run(const float** inputs, float** outputs, uint32_t frames) {
94 dsp.run(inputs, outputs, frames);
95 }
96
97 // -----------------------------------------------------------------------
98 // Callbacks
99
100 void DragonflyReverbPlugin::sampleRateChanged(double newSampleRate) {
101 dsp.sampleRateChanged(newSampleRate);
102 }
103
104 // -----------------------------------------------------------------------
105
106 Plugin* createPlugin() {
107 return new DragonflyReverbPlugin();
108 }
109
110 // -----------------------------------------------------------------------
111
112 END_NAMESPACE_DISTRHO