FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AS/src/KillGate.cpp at V2 · AScustomWorks/AS · GitHub
AScustomWorks
/
AS
Public
Notifications
You must be signed in to change notification settings
Fork
16
Star
123
Code
Issues
15
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
AS
/
src
/
KillGate.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
279 lines (231 loc) · 8.39 KB
Breadcrumbs
AS
/
src
/
KillGate.cpp
Copy path
File metadata and controls
279 lines (231 loc) · 8.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
**************************************************************************************
//
KillGate module for VCV Rack by Alfredo Santamaria - AS - https://github.com/AScustomWorks/AS
//
//
Code adapted from Dual Counter - VCV Module, Strum 2017
//
**************************************************************************************
#
include
"
AS.hpp
"
//
#include "dsp/digital.hpp"
#
include
<
sstream
>
#
include
<
iomanip
>
struct
KillGate
: Module {
enum
ParamIds {
RST_BUTTON1
,
COUNT_NUM_PARAM_1
,
RST_BUTTON2
,
COUNT_NUM_PARAM_2
,
NUM_PARAMS
};
enum
InputIds {
INPUT_1
,
CLK_IN_1
,
RESET_IN_1
,
INPUT_2
,
CLK_IN_2
,
RESET_IN_2
,
NUM_INPUTS
};
enum
OutputIds {
OUTPUT_1
,
OUTPUT_2
,
NUM_OUTPUTS
};
enum
LightIds {
RESET_LIGHT1
,
RESET_LIGHT2
,
NUM_LIGHTS
};
dsp::SchmittTrigger clock_trigger_1;
dsp::SchmittTrigger reset_trigger_1;
dsp::SchmittTrigger reset_ext_trigger_1;
int
count_limit1 =
1
;
int
count1 =
0
;
dsp::SchmittTrigger clock_trigger_2;
dsp::SchmittTrigger reset_trigger_2;
dsp::SchmittTrigger reset_ext_trigger_2;
int
count_limit_2 =
1
;
int
count_2 =
0
;
const
float
lightLambda =
0.075
;
float
resetLight1 =
0
.
0f
;
float
resetLight2 =
0
.
0f
;
bool
gate1_open=
true
;
bool
gate2_open=
true
;
float
mute_fade1 =
0
.
0f
;
float
mute_fade2 =
0
.
0f
;
const
float
fade_speed =
0
.
001f
;
KillGate
() {
config
(
NUM_PARAMS
,
NUM_INPUTS
,
NUM_OUTPUTS
,
NUM_LIGHTS
);
configParam
(KillGate::
COUNT_NUM_PARAM_1
,
1
.
0f
,
64
.
0f
,
1
.
0f
,
"
CH 1 Count
"
);
configParam
(KillGate::
COUNT_NUM_PARAM_2
,
1
.
0f
,
64
.
0f
,
1
.
0f
,
"
CH 2 Count
"
);
//
New in V2, config switches info without displaying values
configButton
(
RST_BUTTON1
,
"
CH 1 Reset
"
);
configButton
(
RST_BUTTON2
,
"
CH 2 Reset
"
);
//
new V2, port labels
//
Inputs
configInput
(
INPUT_1
,
"
CH 1
"
);
configInput
(
INPUT_2
,
"
CH 2
"
);
configInput
(
CLK_IN_1
,
"
CH 1 Clock
"
);
configInput
(
CLK_IN_2
,
"
CH 2 Clock
"
);
configInput
(
RESET_IN_1
,
"
CH 1 Reset
"
);
configInput
(
RESET_IN_2
,
"
CH 2 Reset
"
);
//
Outputs
configOutput
(
OUTPUT_1
,
"
CH 1
"
);
configOutput
(
OUTPUT_2
,
"
CH 2
"
);
}
void
onReset
()
override
{
count_limit1 =
1
;
count1 =
0
;
count_limit_2 =
1
;
count_2 =
0
;
gate1_open=
true
;
gate2_open=
true
;
}
void
process
(
const
ProcessArgs &args)
override
{
count_limit1 =
round
(params[
COUNT_NUM_PARAM_1
].
getValue
());
count_limit_2 =
round
(params[
COUNT_NUM_PARAM_2
].
getValue
());
bool
reset1 =
false
;
bool
reset_2 =
false
;
//
/////////// counter 1
if
(reset_trigger_1.
process
(params[
RST_BUTTON1
].
getValue
()) || reset_ext_trigger_1.
process
(inputs[
RESET_IN_1
].
getVoltage
()) ){
reset1 =
true
;
count1 =
0
;
gate1_open=
true
;
resetLight1 =
1.0
;
}
resetLight1 -= resetLight1 / lightLambda / args.
sampleRate
;
lights[
RESET_LIGHT1
].
value
= resetLight1;
if
( reset1 ==
false
) {
if
( clock_trigger_1.
process
( inputs[
CLK_IN_1
].
getVoltage
() ) && count1 <= count_limit1 ) {
if
( gate1_open ) {
count1++;
}
}
}
if
( count1 == count_limit1 ) {
gate1_open =
false
;
}
//
SOFT MUTE/UNMUTE
mute_fade1 -= !gate1_open ? fade_speed : -fade_speed;
if
( mute_fade1 <
0
.
0f
) {
mute_fade1 =
0
.
0f
;
}
else
if
( mute_fade1 >
1
.
0f
) {
mute_fade1 =
1
.
0f
;
}
outputs[
OUTPUT_1
].
setVoltage
(inputs[
INPUT_1
].
getVoltage
() * mute_fade1);
//
/////////// counter 2
if
( reset_trigger_2.
process
( params[
RST_BUTTON2
].
getValue
() ) || reset_ext_trigger_2.
process
( inputs[
RESET_IN_2
].
getVoltage
() ) ) {
reset_2 =
true
;
count_2 =
0
;
gate2_open =
true
;
resetLight2 =
1
.
0f
;
}
resetLight2 -= resetLight2 / lightLambda / args.
sampleRate
;
lights[
RESET_LIGHT2
].
value
= resetLight2;
if
( reset_2 ==
false
) {
if
( clock_trigger_2.
process
( inputs[
CLK_IN_2
].
getVoltage
() ) && count_2 <= count_limit_2 ) {
if
( gate2_open ) {
count_2++;
}
}
}
if
( count_2 == count_limit_2 ) {
gate2_open =
false
;
}
//
SOFT MUTE/UNMUTE
mute_fade2 -= !gate2_open ? fade_speed : -fade_speed;
if
( mute_fade2 <
0
.
0f
) {
mute_fade2 =
0
.
0f
;
}
else
if
( mute_fade2 >
1
.
0f
) {
mute_fade2 =
1
.
0f
;
}
outputs[
OUTPUT_2
].
setVoltage
(inputs[
INPUT_2
].
getVoltage
() * mute_fade2);
}
};
//
/////////////////////////////////
struct
NumberDisplayWidget
: TransparentWidget {
int
*value =
NULL
;
std::shared_ptr<Font> font;
std::string fontPath = asset::plugin(pluginInstance,
"
res/Segment7Standard.ttf
"
);
void
drawLayer
(
const
DrawArgs& args,
int
layer)
override
{
if
(layer !=
1
){
return
;
}
if
(!value) {
return
;
}
font =
APP
->
window
->
loadFont
(fontPath);
//
text
if
(font) {
nvgFontSize
(args.
vg
,
18
);
nvgFontFaceId
(args.
vg
, font->
handle
);
nvgTextLetterSpacing
(args.
vg
,
2.5
);
std::stringstream to_display;
to_display << std::right <<
std::setw
(
2
) << *value;
Vec textPos =
Vec
(
4
.
0f
,
17
.
0f
);
NVGcolor textColor =
nvgRGB
(
0xf0
,
0x00
,
0x00
);
nvgFillColor
(args.
vg
, textColor);
nvgText
(args.
vg
, textPos.
x
, textPos.
y
, to_display.
str
().
c_str
(),
NULL
);
}
}
};
//
//////////////////////////////////
struct
KillGateWidget
: ModuleWidget {
KillGateWidget
(KillGate *
module
) {
setModule
(
module
);
setPanel
(
APP
->
window
->
loadSvg
(
asset::plugin
(pluginInstance,
"
res/KillGate.svg
"
)));
//
SCREWS
addChild
(createWidget<as_HexScrew>(
Vec
(
RACK_GRID_WIDTH
,
0
)));
addChild
(createWidget<as_HexScrew>(
Vec
(box.
size
.
x
-
2
*
RACK_GRID_WIDTH
,
0
)));
addChild
(createWidget<as_HexScrew>(
Vec
(
RACK_GRID_WIDTH
,
RACK_GRID_HEIGHT
-
RACK_GRID_WIDTH
)));
addChild
(createWidget<as_HexScrew>(
Vec
(box.
size
.
x
-
2
*
RACK_GRID_WIDTH
,
RACK_GRID_HEIGHT
-
RACK_GRID_WIDTH
)));
//
counter 1
//
COUNT DISPLAY
NumberDisplayWidget *display1 =
new
NumberDisplayWidget
();
display1->
box
.
pos
=
Vec
(
9
,
50
);
display1->
box
.
size
=
Vec
(
30
,
20
);
if
(
module
) {
display1->
value
= &
module
->
count1
;
}
addChild
(display1);
//
KillGate DISPLAY
NumberDisplayWidget *display2 =
new
NumberDisplayWidget
();
display2->
box
.
pos
=
Vec
(
49
,
50
);
display2->
box
.
size
=
Vec
(
30
,
20
);
if
(
module
) {
display2->
value
= &
module
->
count_limit1
;
}
addChild
(display2);
int
group_offset =
160
;
addParam
(createParam<LEDBezel>(
Vec
(
11
,
82
),
module
, KillGate::
RST_BUTTON1
));
addChild
(createLight<LEDBezelLight<RedLight>>(
Vec
(
11
+
2.2
,
82
+
2.3
),
module
, KillGate::
RESET_LIGHT1
));
addParam
(createParam<as_KnobBlackSnap>(
Vec
(
43
,
73
),
module
, KillGate::
COUNT_NUM_PARAM_1
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
10
,
125
),
module
, KillGate::
RESET_IN_1
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
55
,
125
),
module
, KillGate::
CLK_IN_1
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
10
,
170
),
module
, KillGate::
INPUT_1
));
addOutput
(createOutput<as_PJ301MPortGold>(
Vec
(
55
,
170
),
module
, KillGate::
OUTPUT_1
));
//
counter 2
//
COUNT DISPLAY
NumberDisplayWidget *display3 =
new
NumberDisplayWidget
();
display3->
box
.
pos
=
Vec
(
9
,
50
+ group_offset);
display3->
box
.
size
=
Vec
(
30
,
20
);
if
(
module
) {
display3->
value
= &
module
->
count_2
;
}
addChild
(display3);
//
KillGate DISPLAY
NumberDisplayWidget *display4 =
new
NumberDisplayWidget
();
display4->
box
.
pos
=
Vec
(
49
,
50
+ group_offset);
display4->
box
.
size
=
Vec
(
30
,
20
);
if
(
module
) {
display4->
value
= &
module
->
count_limit_2
;
}
addChild
(display4);
addParam
(createParam<LEDBezel>(
Vec
(
11
,
82
+ group_offset),
module
, KillGate::
RST_BUTTON2
));
addChild
(createLight<LEDBezelLight<RedLight>>(
Vec
(
11
+
2.2
,
82
+
2.3
+ group_offset),
module
, KillGate::
RESET_LIGHT2
));
addParam
(createParam<as_KnobBlackSnap>(
Vec
(
43
,
73
+ group_offset),
module
, KillGate::
COUNT_NUM_PARAM_2
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
10
,
125
+ group_offset),
module
, KillGate::
RESET_IN_2
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
55
,
125
+ group_offset),
module
, KillGate::
CLK_IN_2
));
addInput
(createInput<as_PJ301MPort>(
Vec
(
10
,
170
+ group_offset),
module
, KillGate::
INPUT_2
));
addOutput
(createOutput<as_PJ301MPortGold>(
Vec
(
55
,
170
+ group_offset),
module
, KillGate::
OUTPUT_2
));
}
};
Model *modelKillGate = createModel<KillGate, KillGateWidget>(
"
KillGate
"
);
Back
|
FazBrowse Home
|
New Git URL