throttle-copy

hio/nwt-gus-hi/throttle-copy

Throttles input changes to happen no more often than once per interval specified. Useful to limit the rate of updates.
throttle-copy
@/throttle-copy
Throttles input changes to happen no more often than once per interval specified. Useful to limit the rate of updates.
INgeneric t1
Value or pulse to throttle
Tnumber
IN will propagate to OUT at most once per T seconds
throttle-copy
IN
OUT
T
OUTgeneric t1
The throttled output. Follows IN immediately if T time window has passed since the last update, otherwise conducts IN with a lag so that the time span between updates is no less than T
To use the node in your project you should have the hio/nwt-gus-hi library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

node {
    bool hasStarted : 1;
    bool shouldEmitOnEnd : 1;

    void evaluate(Context ctx) {
        if (isSettingUp()) {
            hasStarted = false;
            shouldEmitOnEnd = false;
        }
        auto inValue = getValue<input_IN>(ctx);

        if (isInputDirty<input_IN>(ctx)) {
            if (!hasStarted) {
                hasStarted = true;
                emitValue<output_OUT>(ctx, inValue);
                TimeMs dt = getValue<input_T>(ctx) * 1000;
                setTimeout(ctx, dt);
            } else {
                shouldEmitOnEnd = true;
            }
        }

        if (isTimedOut(ctx) && shouldEmitOnEnd) {
            shouldEmitOnEnd = false;
            TimeMs dt = getValue<input_T>(ctx) * 1000;
            setTimeout(ctx, dt);
            emitValue<output_OUT>(ctx, inValue);
        } else if (isTimedOut(ctx)) {
            hasStarted = false;
        }
    }
}