MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ state_machine()

MAYAFLUX_API bool MayaFlux::Kinesis::Discrete::state_machine ( double  input,
std::span< double >  coefs 
)
noexcept

Mealy machine: the state and the input bit pick the next state and the output.

coefs: [threshold, states, state, table...]. Counters, debouncers, pulse sequencers and every other finite controller are tables. An out of range state falls back to state zero.

Definition at line 182 of file Boolean.cpp.

183{
184 if (coefs.size() < 3)
185 return false;
186
187 const size_t states = index_of(coefs[1]);
188 if (states == 0 || coefs.size() < 3 + 4 * states)
189 return false;
190
191 size_t current = index_of(coefs[2]);
192 if (current >= states)
193 current = 0;
194
195 const size_t row = 3 + 4 * current + (input > coefs[0] ? 2 : 0);
196 const size_t next = index_of(coefs[row]);
197 coefs[2] = static_cast<double>(next < states ? next : 0);
198 return coefs[row + 1] > 0.5;
199}
Core::GlobalInputConfig input
Definition Config.cpp:42
glm::vec2 current

References current, and input.