2 #include <Fx/Types.hpp>
4 #include <ossia/dataflow/value_port.hpp>
5 #include <ossia/detail/logger.hpp>
6 #include <ossia/network/value/format_value.hpp>
8 #include <halp/callback.hpp>
9 #include <halp/controls.hpp>
10 #include <halp/layout.hpp>
11 #include <halp/meta.hpp>
12 #include <halp/midi.hpp>
14 namespace Nodes::RateLimiter
18 halp_meta(name,
"Rate Limiter")
19 halp_meta(c_name,
"RateLimiter")
20 halp_meta(category,
"Control/Mappings")
22 manual_url,
"https://ossia.io/score-docs/processes/rate-limiter.html#rate-limiter")
23 halp_meta(author,
"ossia score")
24 halp_meta(description,
"Limit and quantize the rate of a value stream")
25 halp_meta(uuid,
"76cfd504-7c10-4bdb-a1b4-fbe449cc06f0")
32 halp::hslider_i32<
"ms.", halp::irange{0, 1000, 10}> ms;
36 halp::timed_callback<
"out", ossia::value> out;
39 using tick = halp::tick_flicks;
40 bool should_output(
float quantif, int64_t ms, tick t)
44 else if(t.end_in_flicks >= (last_time + ms * flicks_per_ms))
46 last_time = t.end_in_flicks;
52 static const constexpr int64_t flicks_per_ms = 705'600;
55 void operator()(
const tick& t)
57 auto& in = *inputs.port.value;
58 auto quantif = inputs.quantification.value;
59 auto ms = inputs.ms.value;
60 for(
const ossia::timed_value& v : in.get_data())
64 if(should_output(quantif, ms, t))
65 outputs.out(v.timestamp, v.value);
69 for(
auto [t, q] : t.get_quantification_date(1. / quantif))
71 outputs.out(t, v.value);
80 halp_meta(layout, halp::layouts::hbox)
81 halp_meta(background, halp::colors::mid)
82 halp::control<&ins::quantification> q;
83 halp::control<&ins::ms> t;
Definition: RateLimiter.hpp:28
Definition: RateLimiter.hpp:79
Definition: RateLimiter.hpp:17