Skip to content

Commit 53d2d45

Browse files
committed
finished!
1 parent 8d25efd commit 53d2d45

File tree

13 files changed

+1539
-10
lines changed

13 files changed

+1539
-10
lines changed

Plateau/Plateau.cpp

Lines changed: 116 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#include "IPlug_include_in_plug_src.h"
33
#include "IControls.h"
44

5-
6-
75
#include "./controls/SVGLayerKnob.cpp"
86

7+
#include "./controls/IBButtonHold.cpp"
98

109
Plateau::Plateau(const InstanceInfo& info)
1110
: iplug::Plugin(info, MakeConfig(kNumParams, kNumPresets))
@@ -26,9 +25,12 @@ Plateau::Plateau(const InstanceInfo& info)
2625
GetParam(kFreeze)->InitBool("Freeze", false);
2726
GetParam(kClear)->InitBool("Clear", false);
2827
GetParam(kTunedMode)->InitBool("Tuned Mode", false);
29-
GetParam(kDiffuseInput)->InitBool("Diffuse Input", false);
30-
28+
GetParam(kDiffuseInput)->InitBool("Diffuse Input", true);
3129

30+
reverb.setSampleRate(GetSampleRate());
31+
envelope.setSampleRate(GetSampleRate());
32+
envelope.setTime(0.004f);
33+
envelope._value = 1.f;
3234

3335
#if IPLUG_EDITOR // http://bit.ly/2S64BDd
3436
mMakeGraphicsFunc = [&]() {
@@ -63,22 +65,126 @@ Plateau::Plateau(const InstanceInfo& info)
6365
pGraphics->AttachControl(new IBSwitchControl(IRECT::MakeXYWH(-14, 184, 102, 102), LedPNG, kTunedMode));
6466
pGraphics->AttachControl(new IBSwitchControl(IRECT::MakeXYWH(228, 184, 102, 102), LedPNG, kDiffuseInput));
6567

66-
pGraphics->AttachControl(new IBButtonControl(IRECT::MakeXYWH(238, 400, 102, 102), LedPNG,[this](IControl* freezeControl) {}));
67-
68+
pGraphics->AttachControl(new IBButtonHoldControl(IRECT::MakeXYWH(238, 400, 102, 102), LedPNG, [this](IControl* clearControl) {SetParameterValue(kClear, 1);}));
6869
};
6970
#endif
7071
}
7172

73+
void Plateau::OnParamChange(int index)
74+
{
75+
switch (index) {
76+
case kPreDelay:
77+
reverb.setPreDelay(GetParam(index)->Value());
78+
break;
79+
case kInputLowDamp:
80+
reverb.setInputFilterLowCutoffPitch(10.f - GetParam(index)->Value());
81+
break;
82+
case kInputHighDamp:
83+
reverb.setInputFilterHighCutoffPitch(GetParam(index)->Value());
84+
break;
85+
case kSize:
86+
case kTunedMode:
87+
{
88+
float size = GetParam(kSize)->Value();
89+
bool tunedMode = GetParam(kTunedMode)->Value();
90+
if (tunedMode) {
91+
reverb.setTimeScale(0.0025f * powf(2.f, size * 5.f));
92+
}
93+
else {
94+
reverb.setTimeScale(scale(size * size, 0.f, 1.f, 0.01f, 4.0f));
95+
}
96+
break;
97+
}
98+
case kDiffusion:
99+
reverb.setTankDiffusion(GetParam(index)->Value());
100+
break;
101+
case kDecay:
102+
{
103+
float decay = GetParam(index)->Value();
104+
reverb.setDecay(2.f * decay - decay * decay);
105+
break;
106+
}
107+
case kReverbLowDamp:
108+
reverb.setTankFilterLowCutFrequency(10.f - GetParam(index)->Value());
109+
break;
110+
case kReverbHighDamp:
111+
reverb.setTankFilterHighCutFrequency(GetParam(index)->Value());
112+
break;
113+
case kModSpeed:
114+
{
115+
float modSpeed = GetParam(index)->Value();
116+
reverb.setTankModSpeed(modSpeed * modSpeed * 99.f + 1.f);
117+
break;
118+
}
119+
case kModDepth:
120+
reverb.setTankModDepth(GetParam(index)->Value());
121+
break;
122+
case kModShape:
123+
reverb.setTankModShape(GetParam(index)->Value());
124+
break;
125+
case kDiffuseInput:
126+
reverb.enableInputDiffusion(GetParam(index)->Value());
127+
break;
128+
}
129+
}
130+
131+
72132
#if IPLUG_DSP
73133
void Plateau::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
74134
{
75-
const double gain = GetParam(kDry)->Value() / 100.;
135+
const bool clearParam = GetParam(kClear)->Value();
136+
const bool freezeParam = GetParam(kFreeze)->Value();
137+
const double dryParam = GetParam(kDry)->Value()/100;
138+
const double wetParam = GetParam(kWet)->Value()/100;
76139
const int nChans = NOutChansConnected();
77140

78141
for (int s = 0; s < nFrames; s++) {
79-
for (int c = 0; c < nChans; c++) {
80-
outputs[c][s] = inputs[c][s] * gain;
81-
}
142+
if (clearParam && !clear && cleared) {
143+
cleared = false;
144+
clear = true;
145+
}
146+
else if (!clearParam && cleared) {
147+
clear = false;
148+
}
149+
150+
if (clear) {
151+
if (!cleared && !fadeOut && !fadeIn) {
152+
fadeOut = true;
153+
envelope.setStartEndPoints(1.f, 0.f);
154+
envelope.trigger();
155+
}
156+
if (fadeOut && envelope._justFinished) {
157+
reverb.clear();
158+
fadeOut = false;
159+
fadeIn = true;
160+
envelope.setStartEndPoints(0.f, 1.f);
161+
envelope.trigger();
162+
}
163+
if (fadeIn && envelope._justFinished) {
164+
fadeIn = false;
165+
cleared = true;
166+
envelope._value = 1.f;
167+
SetParameterValue(kClear,0);
168+
}
169+
}
170+
envelope.process();
171+
172+
if (freezeParam && !frozen) {
173+
frozen = true;
174+
reverb.freeze(frozen);
175+
}
176+
else if (!freezeParam && frozen) {
177+
frozen = false;
178+
reverb.freeze(frozen);
179+
}
180+
181+
reverb.process((double)(inputs[0][s] * envelope._value), (double)(inputs[nChans>1?1:0][s] * envelope._value));
182+
183+
outputs[0][s] = inputs[0][s] * dryParam + reverb.getLeftOutput() * wetParam;
184+
if (nChans > 1)
185+
{
186+
outputs[1][s] = inputs[1][s] * dryParam + reverb.getRightOutput() * wetParam;
187+
}
82188
}
83189
}
84190
#endif

Plateau/Plateau.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include "IPlug_include_in_plug_hdr.h"
44

5+
#include "./dsp/LinearEnvelope.cpp"
6+
#include "./dsp/Dattorro.cpp"
7+
58
const int kNumPresets = 1;
69

710
enum EParams
@@ -34,7 +37,19 @@ class Plateau final : public Plugin
3437
public:
3538
Plateau(const InstanceInfo& info);
3639

40+
3741
#if IPLUG_DSP // http://bit.ly/2S64BDd
3842
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
43+
void OnParamChange(int index) override;
3944
#endif
45+
private:
46+
Dattorro reverb;
47+
LinearEnvelope envelope;
48+
49+
bool clear = false;
50+
bool cleared = true;
51+
bool fadeOut = false;
52+
bool fadeIn = false;
53+
54+
bool frozen = false;
4055
};

Plateau/controls/IBButtonHold.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "IControl.h"
2+
3+
BEGIN_IPLUG_NAMESPACE
4+
BEGIN_IGRAPHICS_NAMESPACE
5+
6+
class IBButtonHoldControl : public IButtonControlBase
7+
, public IBitmapBase
8+
{
9+
public:
10+
11+
IBButtonHoldControl::IBButtonHoldControl(float x, float y, const IBitmap& bitmap, IActionFunction aF)
12+
: IButtonControlBase(IRECT(x, y, bitmap), aF)
13+
, IBitmapBase(bitmap)
14+
{
15+
AttachIControl(this);
16+
}
17+
18+
IBButtonHoldControl::IBButtonHoldControl(const IRECT& bounds, const IBitmap& bitmap, IActionFunction aF)
19+
: IButtonControlBase(bounds.GetCentredInside(bitmap), aF)
20+
, IBitmapBase(bitmap)
21+
{
22+
AttachIControl(this);
23+
}
24+
25+
void Draw(IGraphics& g) override { DrawBitmap(g); }
26+
void OnRescale() override { mBitmap = GetUI()->GetScaledBitmap(mBitmap); }
27+
void OnMouseUp(float x, float y, const IMouseMod& mod) override {
28+
this->SetValue(0.);
29+
SetDirty(false);
30+
}
31+
};
32+
33+
END_IGRAPHICS_NAMESPACE
34+
END_IPLUG_NAMESPACE

Plateau/dsp/AllpassFilter.hpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @file AllpassFilter.hpp
3+
* @author Dale Johnson
4+
* @date ...uhhh
5+
*/
6+
7+
#pragma once
8+
#include "InterpDelay.hpp"
9+
#include <cassert>
10+
11+
template<class T>
12+
class AllpassFilter {
13+
public:
14+
AllpassFilter() {
15+
clear();
16+
gain = 0;
17+
}
18+
19+
AllpassFilter(long maxDelay, long initDelay = 0, T gain = 0) {
20+
clear();
21+
delay = InterpDelay<T>(maxDelay, initDelay);
22+
this->gain = gain;
23+
}
24+
25+
T inline process() {
26+
//Note that negative gain does something
27+
28+
//Feedback into delay buffer based on gain
29+
_inSum = input + delay.output * gain;
30+
31+
//output is the delay output subtract the feedback input
32+
output = delay.output - _inSum * gain;
33+
34+
//feed the next sample into the delay
35+
delay.input = _inSum;
36+
37+
//proccess the delay sample
38+
delay.process();
39+
40+
return output;
41+
}
42+
43+
void clear() {
44+
input = 0;
45+
output = 0;
46+
_inSum = 0;
47+
_outSum = 0;
48+
delay.clear();
49+
}
50+
51+
void setGain(const T newGain) {
52+
assert(newGain >= -1.0);
53+
assert(newGain <= 1.0);
54+
55+
gain = newGain;
56+
}
57+
58+
59+
//init signal IO
60+
T input;
61+
T output;
62+
63+
//Create an interpolating delay called delay
64+
InterpDelay<T> delay;
65+
66+
private:
67+
T gain;
68+
T _inSum;
69+
T _outSum;
70+
};
71+
72+
template<class T>
73+
class NestedAllPassType1 {
74+
public:
75+
NestedAllPassType1() {
76+
gain1 = 0;
77+
gain2 = 0;
78+
decay1 = 0;
79+
decay2 = 0;
80+
clear();
81+
}
82+
83+
NestedAllPassType1(long maxDelay, long delayTime1, long delayTime2) {
84+
delay1 = InterpDelay<T>(maxDelay, delayTime1);
85+
delay2 = InterpDelay<T>(maxDelay, delayTime2);
86+
gain1 = 0;
87+
gain2 = 0;
88+
decay1 = 0;
89+
decay2 = 0;
90+
clear();
91+
}
92+
93+
T inline process() {
94+
_inSum1 = input + delay1.output * gain1;
95+
_inSum2 = _inSum1 + delay2.output * gain2;
96+
delay2.input = _inSum2;
97+
delay1.input = delay2.output * decay2 - _inSum2 * gain2;
98+
output = delay1.output * decay1 - _inSum1 * gain1;
99+
delay1.process();
100+
delay2.process();
101+
return output;
102+
}
103+
104+
void clear() {
105+
input = 0;
106+
output = 0;
107+
108+
_inSum1 = 0;
109+
_inSum2 = 0;
110+
111+
delay1.clear();
112+
delay2.clear();
113+
}
114+
115+
//IO
116+
T input;
117+
T output;
118+
119+
//2 gains
120+
T gain1, gain2;
121+
122+
//2 decays
123+
T decay1, decay2;
124+
125+
//2 delays
126+
InterpDelay<T> delay1, delay2;
127+
private:
128+
T _inSum1, _inSum2;
129+
};

0 commit comments

Comments
 (0)