Skip to content

Commit 2f38465

Browse files
committed
NG: Add integral reset.
1 parent e6494ab commit 2f38465

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/nodegraph/include/nodegraph/operations/NodeGraphOpMathNumerical.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace l::nodegraph {
2626
{
2727
AddInput2("x");
2828
AddInput("Friction", 1.0f, 1, 0.0f, 1.0f);
29+
AddInput2("Reset Toggle");
2930
AddOutput2("Intgr(x)");
3031
}
3132

@@ -38,6 +39,7 @@ namespace l::nodegraph {
3839
int32_t mReadSamples = 0;
3940

4041
float mOutput = 0.0f;
42+
float mResetPrev = 0.0f;
4143
};
4244

4345
/*********************************************************************/

packages/nodegraph/source/common/operations/NodeGraphOpMathNumerical.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@ namespace l::nodegraph {
1313
auto input0 = &inputs.at(0).Get(numSamples);
1414
auto friction = inputs.at(1).Get();
1515
auto frictionFactor = l::math::clamp(l::math::pow(friction, 0.25f), 0.0f, 1.0f);
16+
auto resetInput = &inputs.at(2).Get(numSamples);
1617
auto output = &outputs.at(0).Get(numSamples);
1718

1819
if (mReadSamples == 0) {
1920
mOutput = 0.0f;
21+
mResetPrev = 0.0f;
2022
}
2123

2224
for (int32_t i = 0; i < numSamples; i++) {
25+
auto reset = *resetInput++;
26+
if (reset < 0.0f && mResetPrev > 0.0f || reset > 0.0f && mResetPrev < 0.0f) {
27+
mOutput = 0.0f;
28+
}
2329
mOutput += *input0++;
2430
mOutput *= frictionFactor;
2531
*output++ = mOutput;
32+
33+
mResetPrev = reset;
2634
}
2735

2836
mReadSamples += numSamples;
2937

3038
if (mReadSamples >= numCacheSamples) {
3139
mReadSamples = 0;
32-
mOutput = 0.0f;
3340
}
3441

3542
if (isnan(mOutput)) {

0 commit comments

Comments
 (0)