Skip to content

MoonLivePalette

Source: MoonLivePalette.h

MoonLivePalette

class MoonLivePalette
src/light/moonlive/MoonLivePalette.h:30

A palette authored as code rather than stored as data.

Public Methods

inline void setScript(const char * name) : Point the palette at a script. The next [prepare()] compiles it.

inline const char * scriptName() const : The script file this palette runs.

inline void prepare(MoonModule & owner) : Compile if the named file changed, reporting status and dynamic bytes through owner.

inline void publishControls(ControlList & controls) : Publish the script's controls, so a scripted palette is configurable without editing it.

inline bool ok() const : Whether a script is compiled and ready to run.

inline void release() : Drop the compiled script and its memory.

inline bool tick(uint32_t nowMs) : Run the script for this frame and install the result, returning false when nothing ran.

Public Static Methods

static inline MoonLivePalette * active() : The palette script the frame should run, or nullptr.

static inline void setActiveInstance(MoonLivePalette * p) : Publish the palette script the frame should run.

static inline void clearActiveInstance(const MoonLivePalette * p) : Detach, for an owner whose storage is about to go away.

static inline void tickActive(uint32_t nowMs) : Run the active palette script, if there is one. Called once per frame before the layers.

More info

This is the fifth binding, and the one shape the other four do not have: it writes sixteen entries once per frame, and every effect in that frame samples them.

Why a palette is worth computing

A stop list is frozen the moment it is saved, where a palette that is code can follow the music, drift, or be computed. The audio builtins are already in the shared table, so audioBand in a palette costs nothing to expose, and it is the case that justifies the design.

Why it is cheap enough to run per frame

Cost is independent of rig size: a sixteen-iteration loop whatever the wall is. It fills a scratch palette and assigns the 48 bytes once, so an effect sees either the previous palette or the new one and never a mixture.

Why a broken script keeps the last good palette

The other bindings degrade to dark, which is honest when the script is the picture. Here the effects still run, so a black palette would blame them for a fault that is not theirs.