34#ifndef SBL_CONTROL_SCHEDULER_HPP_
35#define SBL_CONTROL_SCHEDULER_HPP_
54template<u
int8_t Slots, u
int8_t Capacity = 16>
56 static_assert(
Slots > 0,
"Scheduler needs at least one slot");
57 static_assert(
Capacity > 0,
"Scheduler needs subscriber capacity");
69 if (count_ >=
Capacity || slot >=
Slots || fn ==
nullptr)
return false;
70 subs_[count_++] = {fn, context, stage, slot};
75 template<
typename T,
void (T::*Method)(u
int32_t)>
93 due[
s] = (phase_[
s] == 0);
99 if (++phase_[
s] >= divider_[
s]) phase_[
s] = 0;
105 const Subscriber&
sub = subs_[
i];
106 if (
sub.stage == stage &&
due[
sub.slot]) {
121 void* context =
nullptr;
126 Subscriber subs_[Capacity]{};
127 uint16_t divider_[Slots]{};
128 uint16_t phase_[Slots]{};
129 uint32_t last_[Slots]{};
131 bool started_ =
false;
void run(uint32_t sample_clock)
static constexpr uint8_t capacity()
static constexpr uint8_t slots()
bool subscribe(Stage stage, uint8_t slot, T &object)
Subscribe a member void T::method(uint32_t elapsed_samples).
Scheduler(const uint16_t(÷rs)[Slots])
uint16_t divider(uint8_t slot) const
bool subscribe(Stage stage, uint8_t slot, TickFn fn, void *context)
Add a subscriber. Returns false if full, the slot is out of range, or fn is null.
uint8_t subscriber_count() const
Control Stack v2: scheduler, event queue, merge, CC mapping, calibration, presets.
constexpr uint8_t kStageCount
Stage
Intra-tick order. Every due subscriber of a stage runs before any of the next.