theallelectricsmartgrid

Theory of Time

The Theory of Time is the global clock that every other part of the system follows. It is implemented in private/src/TheoryOfTime.hpp and used by the Nonagon (sequencer).


Overview


Micro block and rolling buffer

For every micro block (8 samples), the Theory of Time computes all samples in that block plus the first sample of the next block. Arrays are sized x_microBlockBufferSize = 9; slot 8 holds the first sample of the next micro block (computed in the current block). At the start of each micro block, RolloverMicroblockBuffer copies slot 8 into slot 0—the first sample of this block was computed in the previous block. The Nonagon then runs at that sample, and Process(j) for j=1..8 computes the rest of this block and the first sample of the next. This ensures that interpolation anywhere inside a micro block always has accurate boundary samples.


True phase and phase-modulated phase


Six divisions: time loops

From the main loop we compute 6 divisions, forming a tree of maps S¹ → S¹ given by multiplication by an integer (mod 1). Each division is a time loop (TimeLoop).

For each loop we compute both pre- and post-modulation positions. Parameters (parent index and parent mult) are only allowed to change when the parent is at zero (i.e. when GetParent()->m_top is true). That way positions remain continuous when the topology or multipliers change. This is enforced in TimeLoop::HandleInput().


Integer positions and LCM logic

To avoid floating-point issues, integer positions are used so that all gates change on the same sample when they mathematically should.

Loop size and LCM:

So the parent’s loop size is the LCM of all (child_loopSize × child_parentMult), ensuring that when we divide by m_parentMult we get an integer. The factor of 2 is so that each loop has two distinct states per cycle (see gate, below): first half and second half of the circle.


Gate: two states per loop

Each time loop has two states depending on whether the position lies in the first or second half of the cycle:


Monodromy (relative state-change count)

The Theory of Time exposes relative monodromy numbers: how many times the gate of a given loop has changed state (flipped) since a chosen ancestor loop was at zero.


Statelessness

A guiding principle of the clock design is statelessness: the sequencer and LFO state are a pure function of the map R → S¹ and its six divisions. Given the same global phase and topology, the system reproduces the same time loops, gates, and monodromy. There is no separate “sequencer state” that has to be kept in sync with the clock; it is derived from the clock.