taime-f-r

nikolay079/mai-path/taime-f-r

No description
taime-f-r
@/taime-f-r
Fnumber
An interval between wave peaks, i.e. the period of the signal
rewnumber
An interval between wave peaks, i.e. the period of the signal
ENboolean
Enabled or not. If set to `false` pulses on `UPD` do not change the output value. Effictively that means the timer is paused. Set to `true` again to continue time counting.
RSTpulse
Resets the current time value to zero.
UPDpulse
Triggers the time value update.
taime-f-r
OUT
F
rew
EN
RST
UPD
OUTnumber
The current time value in seconds.
To use the node in your project you should have the nikolay079/mai-path 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

struct State {
    TimeMs lastUpdateTime;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    State* state = getState(ctx);
    bool enabled = getValue<input_EN>(ctx);
    bool update = isInputDirty<input_UPD>(ctx);
    bool reset = isInputDirty<input_RST>(ctx);
    Number f = getValue<input_F>(ctx);
    Number r = getValue<input_rew>(ctx);

    TimeMs t = transactionTime();
    if (reset)
        emitValue<output_OUT>(ctx, 0);
    else if (enabled && update) {
        Number dtSeconds = (t - state->lastUpdateTime)* r / f;
        Number oldSeconds = getValue<output_OUT>(ctx);
        emitValue<output_OUT> (ctx, oldSeconds + dtSeconds);
    }

    state->lastUpdateTime = t ;
}