forked from polyend/FxPatchSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-code-skeleton.cpp
More file actions
227 lines (197 loc) · 6.03 KB
/
Copy pathpatch-code-skeleton.cpp
File metadata and controls
227 lines (197 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Patch code skeleton for Polyend Endless
//
// Copy this file into effects/ and rename it for the patch you are building.
//
// TODO: replace the placeholder patch name, voice description, control mapping, and LED
// scheme with the patch-specific design. Pair this with
// docs/templates/patch-build-walkthrough.md while you implement the effect.
//
// Primary voice:
// TODO: describe the default sound and the core circuit/DSP idea.
//
// Alternate voice:
// TODO: describe the long-press mode, if the patch has one.
//
// Controls:
// Left knob — TODO
// Mid knob — TODO
// Right knob — TODO (also expression pedal in this repo's current wrapper)
// Footswitch — Press: bypass, Hold: alternate voice toggle
// LED — TODO: document active/bypassed colors for each voice
#include "../source/Patch.h"
#include <cmath>
namespace {
// These helpers mirror the style already used in effects/*.cpp. If this repo grows a
// shared source/dsp/ layer, move these into that shared code instead of redefining them.
[[maybe_unused]] constexpr float kFs = static_cast<float>(Patch::kSampleRate);
[[maybe_unused]] constexpr float kTwoPi = 6.283185307f;
[[maybe_unused]] constexpr float kHalfPi = 1.57079632679f;
[[maybe_unused]] float clamp01(float value)
{
if (value < 0.0f) {
return 0.0f;
}
if (value > 1.0f) {
return 1.0f;
}
return value;
}
[[maybe_unused]] float clampUnit(float value)
{
if (value < -1.0f) {
return -1.0f;
}
if (value > 1.0f) {
return 1.0f;
}
return value;
}
[[maybe_unused]] float hpCoeff(float fc)
{
return 1.0f / (1.0f + kTwoPi * fc / kFs);
}
[[maybe_unused]] float lpCoeff(float fc)
{
const float omega = kTwoPi * fc / kFs;
return omega / (1.0f + omega);
}
[[maybe_unused]] float equalPowerDry(float mix)
{
return cosf(clamp01(mix) * kHalfPi);
}
[[maybe_unused]] float equalPowerWet(float mix)
{
return sinf(clamp01(mix) * kHalfPi);
}
} // namespace
class PatchImpl final : public Patch
{
public:
void init() override
{
left_ = 0.5f;
mid_ = 0.5f;
right_ = 0.5f;
bypassed_ = false;
alternateVoice_ = false;
// TODO: reset filter state, delay write pointers, envelopes, LFO phase, and any
// other per-voice state here.
}
void setWorkingBuffer(std::span<float, kWorkingBufferSize> buffer) override
{
// TODO: partition the external buffer only if the patch needs long delay lines,
// tables, grains, or other bulk storage.
//
// Example:
// delayL_ = buffer.data();
// delayR_ = buffer.data() + kDelayLen;
(void)buffer;
}
void processAudio(std::span<float> left, std::span<float> right) override
{
// Current SDK buffers are in-place. Leaving samples unchanged is a passthrough.
if (bypassed_) {
return;
}
const float leftParam = clamp01(left_);
const float midParam = clamp01(mid_);
const float rightParam = clamp01(right_);
(void)leftParam;
(void)midParam;
(void)rightParam;
for (size_t i = 0; i < left.size(); ++i) {
const float inL = left[i];
const float inR = right[i];
float outL = inL;
float outR = inR;
// TODO: DSP here.
// Example structure:
// 1. map params with musical tapers
// 2. update coefficients outside the inner loop when possible
// 3. process core nonlinear/filter/delay path
// 4. clamp or soft-limit only as needed
left[i] = clampUnit(outL);
right[i] = clampUnit(outR);
}
}
ParameterMetadata getParameterMetadata(int paramIdx) override
{
switch (paramIdx) {
case 0:
return {0.0f, 1.0f, 0.5f};
case 1:
return {0.0f, 1.0f, 0.5f};
case 2:
return {0.0f, 1.0f, 0.5f};
default:
return {0.0f, 1.0f, 0.5f};
}
}
// Short display names for the three knobs, surfaced through the firmware's
// agent_get_param_name ABI slot. Keep them to 8 characters or fewer -- the
// buffer size is undocumented and the wrapper truncates silently. Return
// nullptr for a knob you deliberately leave unused.
const char* getParameterName(int paramIdx) override
{
switch (paramIdx) {
case 0: return "TODO";
case 1: return "TODO";
case 2: return "TODO";
default: return nullptr;
}
}
void setParamValue(int paramIdx, float value) override
{
switch (paramIdx) {
case 0:
left_ = value;
break;
case 1:
mid_ = value;
break;
case 2:
right_ = value;
break;
default:
break;
}
}
void handleAction(int actionIdx) override
{
switch (actionIdx) {
case static_cast<int>(endless::ActionId::kLeftFootSwitchPress):
bypassed_ = !bypassed_;
break;
case static_cast<int>(endless::ActionId::kLeftFootSwitchHold):
alternateVoice_ = !alternateVoice_;
// TODO: decide whether changing voices should clear or preserve state.
break;
default:
break;
}
}
Color getStateLedColor() override
{
if (alternateVoice_) {
return bypassed_ ? Color::kDimWhite : Color::kBeige;
}
return bypassed_ ? Color::kDimBlue : Color::kLightBlueColor;
}
private:
// No heap allocations: keep state in members and use the working buffer explicitly.
float left_ = 0.5f;
float mid_ = 0.5f;
float right_ = 0.5f;
bool bypassed_ = false;
bool alternateVoice_ = false;
// TODO: add patch state here.
// float z1_ = 0.0f;
// float z2_ = 0.0f;
// float* delayL_ = nullptr;
// float* delayR_ = nullptr;
};
static PatchImpl patch;
Patch* Patch::getInstance()
{
return &patch;
}