Skip to content

Commit e7a662a

Browse files
committed
supersaw: add various envelope routing options
1 parent e1eef31 commit e7a662a

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/supersaw.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ struct Supersaw : Module {
1717
PULSE_WIDTH_PARAM,
1818
RISE_PARAM,
1919
FALL_PARAM,
20+
ENV_TO_DUR_PARAM,
21+
ENV_TO_MIX_PARAM,
22+
ENV_TO_PW_PARAM,
23+
ENV_DUR_ATT_PARAM,
24+
ENV_MIX_ATT_PARAM,
25+
ENV_PW_ATT_PARAM,
2026
PARAMS_LEN
2127
};
2228
enum InputId {
@@ -65,6 +71,12 @@ struct Supersaw : Module {
6571
configInput(PULSE_WIDTH_CV_INPUT, "Pulse width CV");
6672
configParam(RISE_PARAM, 0.01, 5.0, 1.0, "Rise time", " s");
6773
configParam(FALL_PARAM, 0.01, 5.0, 1.0, "Fall time", " s");
74+
configParam(ENV_TO_DUR_PARAM, 0.0, 1.0, 0.0, "Envelope to noise duration");
75+
configParam(ENV_TO_MIX_PARAM, 0.0, 1.0, 0.0, "Envelope to noise mix");
76+
configParam(ENV_TO_PW_PARAM, 0.0, 1.0, 0.0, "Envelope to pulse width");
77+
configParam(ENV_DUR_ATT_PARAM, 0.0, 1.0, 0.0, "Envelope duration attenuation");
78+
configParam(ENV_MIX_ATT_PARAM, 0.0, 1.0, 0.0, "Envelope mix attenuation");
79+
configParam(ENV_PW_ATT_PARAM, 0.0, 1.0, 0.0, "Envelope pulse width attenuation");
6880
configInput(VOCT_INPUT, "1 V/Oct");
6981
configOutput(SIGNAL_OUTPUT, "Signal");
7082
for (int i = 0; i < 3; i++) {
@@ -99,10 +111,33 @@ struct Supersaw : Module {
99111
float noise_mix = params[NOISE_MIX_PARAM].getValue();
100112
float rise_time = params[RISE_PARAM].getValue();
101113
float fall_time = params[FALL_PARAM].getValue();
114+
bool env_to_dur = params[ENV_TO_DUR_PARAM].getValue() > 0.5;
115+
bool env_to_mix = params[ENV_TO_MIX_PARAM].getValue() > 0.5;
116+
bool env_to_pw = params[ENV_TO_PW_PARAM].getValue() > 0.5;
117+
float env_dur_att = params[ENV_DUR_ATT_PARAM].getValue();
118+
float env_mix_att = params[ENV_MIX_ATT_PARAM].getValue();
119+
float env_pw_att = params[ENV_PW_ATT_PARAM].getValue();
102120

103121
envelope.set_rise(rise_time);
104122
envelope.set_fall(fall_time);
105123

124+
if (env_to_dur) {
125+
noise_dur += envelope.env * env_dur_att * 0.001;
126+
noise_dur = clamp(noise_dur, 0.f, 0.001f);
127+
}
128+
129+
if (env_to_mix) {
130+
noise_mix += envelope.env * env_mix_att * 0.5;
131+
noise_mix = clamp(noise_mix, 0.f, 0.5f);
132+
}
133+
134+
if (env_to_pw) {
135+
float pw_min = 0.1;
136+
float pw_max = 0.9;
137+
pulse_width += envelope.env * env_pw_att * (pw_max - pw_min);
138+
pulse_width = clamp(pulse_width, pw_min, pw_max);
139+
}
140+
106141
for (int c = 0; c < channels; c++) {
107142
float voct = inputs[VOCT_INPUT].getVoltage(c);
108143

@@ -227,6 +262,21 @@ struct SupersawWidget : ModuleWidget {
227262
addOutput(createOutputCentered<PJ301MPort>(Vec(x, y), module, Supersaw::VCA_OUTPUT));
228263
x += dx;
229264
addOutput(createOutputCentered<PJ301MPort>(Vec(x, y), module, Supersaw::ENV_OUTPUT));
265+
x -= dx * 2;
266+
y += dy;
267+
addParam(createParamCentered<CKSS>(Vec(x, y), module, Supersaw::ENV_TO_DUR_PARAM));
268+
x += dx;
269+
addParam(createParamCentered<RoundSmallBlackKnob>(Vec(x, y), module, Supersaw::ENV_DUR_ATT_PARAM));
270+
x -= dx;
271+
y += dy;
272+
addParam(createParamCentered<CKSS>(Vec(x, y), module, Supersaw::ENV_TO_MIX_PARAM));
273+
x += dx;
274+
addParam(createParamCentered<RoundSmallBlackKnob>(Vec(x, y), module, Supersaw::ENV_MIX_ATT_PARAM));
275+
x -= dx;
276+
y += dy;
277+
addParam(createParamCentered<CKSS>(Vec(x, y), module, Supersaw::ENV_TO_PW_PARAM));
278+
x += dx;
279+
addParam(createParamCentered<RoundSmallBlackKnob>(Vec(x, y), module, Supersaw::ENV_PW_ATT_PARAM));
230280
}
231281
};
232282

0 commit comments

Comments
 (0)