| 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 |
preset = DEFAULT_PRESET; |
| 25 |
} |
| 26 |
|
| 27 |
// ----------------------------------------------------------------------- |
| 28 |
// Init |
| 29 |
|
| 30 |
void DragonflyReverbPlugin::initAudioPort(bool input, uint32_t index, AudioPort& port) { |
| 31 |
// treat audio ports as stereo |
| 32 |
port.groupId = kPortGroupStereo; |
| 33 |
|
| 34 |
// everything else is as default |
| 35 |
Plugin::initAudioPort(input, index, port); |
| 36 |
} |
| 37 |
|
| 38 |
void DragonflyReverbPlugin::initParameter(uint32_t index, Parameter& parameter) { |
| 39 |
if (index < paramCount) { |
| 40 |
parameter.hints = kParameterIsAutomatable; |
| 41 |
parameter.name = PARAMS[index].name; |
| 42 |
parameter.symbol = PARAMS[index].symbol; |
| 43 |
parameter.ranges.min = PARAMS[index].range_min; |
| 44 |
parameter.ranges.def = presets[DEFAULT_PRESET].params[index]; |
| 45 |
parameter.ranges.max = PARAMS[index].range_max; |
| 46 |
parameter.unit = PARAMS[index].unit; |
| 47 |
if (index == paramAlgorithm) { |
| 48 |
parameter.hints |= kParameterIsInteger; |
| 49 |
parameter.enumValues.count = ALGORITHM_COUNT; |
| 50 |
parameter.enumValues.restrictedMode = true; |
| 51 |
ParameterEnumerationValue* const values = new ParameterEnumerationValue[ALGORITHM_COUNT]; |
| 52 |
parameter.enumValues.values = values; |
| 53 |
for (int i=0; i<ALGORITHM_COUNT; ++i) { |
| 54 |
values[i].label = algorithmNames[i]; |
| 55 |
values[i].value = i; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void DragonflyReverbPlugin::initState(uint32_t index, State& state) { |
| 62 |
if (index == 0) { |
| 63 |
state.key = "preset"; |
| 64 |
state.defaultValue = "Clear Plate"; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
// ----------------------------------------------------------------------- |
| 69 |
// Internal data |
| 70 |
|
| 71 |
float DragonflyReverbPlugin::getParameterValue(uint32_t index) const { |
| 72 |
return dsp.getParameterValue(index); |
| 73 |
} |
| 74 |
|
| 75 |
void DragonflyReverbPlugin::setParameterValue(uint32_t index, float value) { |
| 76 |
dsp.setParameterValue(index, value); |
| 77 |
} |
| 78 |
|
| 79 |
void DragonflyReverbPlugin::setState(const char* key, const char* value) { |
| 80 |
if (std::strcmp(key, "preset") == 0) { |
| 81 |
for (int p = 0; p < NUM_PRESETS; p++) { |
| 82 |
if (std::strcmp(value, presets[p].name) == 0) { |
| 83 |
preset = p; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// ----------------------------------------------------------------------- |
| 90 |
// Process |
| 91 |
|
| 92 |
void DragonflyReverbPlugin::activate() { |
| 93 |
sampleRateChanged(getSampleRate()); |
| 94 |
} |
| 95 |
|
| 96 |
void DragonflyReverbPlugin::run(const float** inputs, float** outputs, uint32_t frames) { |
| 97 |
dsp.run(inputs, outputs, frames); |
| 98 |
} |
| 99 |
|
| 100 |
// ----------------------------------------------------------------------- |
| 101 |
// Callbacks |
| 102 |
|
| 103 |
void DragonflyReverbPlugin::sampleRateChanged(double newSampleRate) { |
| 104 |
dsp.sampleRateChanged(newSampleRate); |
| 105 |
} |
| 106 |
|
| 107 |
// ----------------------------------------------------------------------- |
| 108 |
|
| 109 |
Plugin* createPlugin() { |
| 110 |
return new DragonflyReverbPlugin(); |
| 111 |
} |
| 112 |
|
| 113 |
// ----------------------------------------------------------------------- |
| 114 |
|
| 115 |
END_NAMESPACE_DISTRHO |