Skip to content

EffectBase

Source: EffectBase.h

EffectBase

class EffectBase
src/light/effects/EffectBase.h:46

Inherits: MoonModule

The light-domain MoonModule an effect derives from, adding the rendering context.

A zero-state layer holding accessors that forward to the parent Layer. An effect reads its context through these rather than caching a Layer* and the extents. DriverBase plays the same role for drivers against the Drivers container.

Prior art: MoonLight's Node and VirtualLayer, where an effect reaches the layer directly.

Public Methods

virtual inline ModuleRole role() const override : Role for type identification (no RTTI needed).

virtual inline Dim dimensions() const : Which axes the effect iterates, read at frame time: a hardcoded bound is a buffer overrun.

inline Layer * layer() const : The parent, always a Layer, defined in [Layer.h] once Layer is complete.

inline uint8_t * buffer() : The layer's pixel buffer, sized to width x height x depth x channels.

inline lengthType width() const : Lights along x.

inline lengthType height() const : Lights along y.

inline lengthType depth() const : Lights along z, which is 1 on a panel or a strip.

inline uint8_t channelsPerLight() const : Bytes each light occupies in the buffer.

inline nrOfLightsType nrOfLights() const : Lights in the whole layer.

inline uint32_t elapsed() const : Milliseconds since render start. Drive animation off this rather than a frame count.

inline mm::draw::Canvas canvas() : The layer's surface as one value, read once a frame since nothing may cache extents across ticks.

inline void setPan(nrOfLightsType index, uint8_t value) : Aim a fixture, a no-op on an absent channel, and never scaled by brightness.

inline void setTilt(nrOfLightsType index, uint8_t value) : Tilt the fixture, under the same contract as setPan.

inline void setZoom(nrOfLightsType index, uint8_t value) : Zoom the beam, under the same contract as setPan.

inline void setRotate(nrOfLightsType index, uint8_t value) : Spin the gobo or prism, under the same contract as setPan.

inline void setGobo(nrOfLightsType index, uint8_t value) : Select the gobo pattern, whose byte is a range per slot on most heads rather than an index.

inline bool movable() const : True when the lights carry pan or tilt, so an effect can skip motion math on a strip.

inline bool hasBeam() const : True when the lights carry a gobo or rotate channel, which plenty of moving heads lack.

More info

Writing an effect

Derive from EffectBase and include this one file, which is the whole surface an effect may use. A scripted MoonLive effect gets the same one, and unused declarations emit no code. An effect needing something outside that surface adds one include, and nothing more.

Animation

Speed controls use BPM rather than an abstract range, so 60 BPM is one beat a second. Multiply a time offset by the panel dimension, or a large display looks sluggish. Drive animation off elapsed() rather than a frame count, so speed holds at any frame rate. The speed control sets the dynamics and never the frame rate, which stays maximal.

One include writes an effect

This file brings EffectBase and every helper an effect may use, so an effect includes it alone.

Why the helper includes sit at the bottom

[Layer.h] includes this file, since a Layer holds effect children. So this file forward-declares Layer, and pulls [Layer.h] in after the class is complete. [Layer.h] re-enters harmlessly through the include guard and defines the accessor bodies.