FastLED 3.9.15
Loading...
Searching...
No Matches
fx_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6#include "crgb.h"
7#include "fl/map.h"
8#include "fl/namespace.h"
9#include "fl/ptr.h"
10#include "fl/ui.h"
11#include "fl/xymap.h"
13#include "fx/detail/fx_layer.h"
14#include "fx/fx.h"
15#include "fx/time.h"
16#include "fx/video.h"
17
18// Forward declaration
19class TimeFunction;
20
21#ifndef FASTLED_FX_ENGINE_MAX_FX
22#define FASTLED_FX_ENGINE_MAX_FX 64
23#endif
24
25namespace fl {
26
36class FxEngine {
37 public:
43 FxEngine(uint16_t numLeds, bool interpolate = true);
44
48 ~FxEngine();
49
56 int addFx(FxPtr effect);
57
66 int addFx(Fx &effect) { return addFx(fl::Ptr<Fx>::NoTracking(effect)); }
67
75 FxPtr removeFx(int index);
76
82 FxPtr getFx(int index);
83
84 int getCurrentFxId() const { return mCurrId; }
85
91 bool draw(uint32_t now, CRGB *outputBuffer);
92
98 bool nextFx(uint16_t transition_ms = 500);
99
106 bool setNextFx(int index, uint16_t duration);
107
109
115 void setSpeed(float scale) { mTimeFunction.setSpeed(scale); }
116
117 private:
118 int mCounter = 0;
119 TimeWarp mTimeFunction; // FxEngine controls the clock, to allow
120 // "time-bending" effects.
124 uint16_t mDuration = 0;
126 false;
127 bool mInterpolate = true;
128};
129
130} // namespace fl
UISlider scale("Scale", 1.0f, 0.0f, 1.0f, 0.01f)
int addFx(FxPtr effect)
Adds a new effect to the engine.
Definition fx_engine.cpp:12
void setSpeed(float scale)
Sets the speed of the fx engine, which will impact the speed of all effects.
Definition fx_engine.h:115
~FxEngine()
Destructor for FxEngine.
Definition fx_engine.cpp:10
fl::FixedMap< int, FxPtr, FASTLED_FX_ENGINE_MAX_FX > IntFxMap
Definition fx_engine.h:38
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
Definition fx_engine.cpp:33
bool mDurationSet
Flag indicating if a new transition has been set.
Definition fx_engine.h:125
FxCompositor mCompositor
Handles effect transitions and rendering.
Definition fx_engine.h:122
int getCurrentFxId() const
Definition fx_engine.h:84
int mCurrId
Id of the current effect.
Definition fx_engine.h:123
bool setNextFx(int index, uint16_t duration)
Sets the next effect to transition to.
Definition fx_engine.cpp:42
IntFxMap & _getEffects()
Definition fx_engine.h:108
FxEngine(uint16_t numLeds, bool interpolate=true)
Constructs an FxEngine with the specified number of LEDs.
Definition fx_engine.cpp:6
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.cpp:82
IntFxMap mEffects
Collection of effects.
Definition fx_engine.h:121
uint16_t mDuration
Duration of the current transition.
Definition fx_engine.h:124
FxPtr removeFx(int index)
Requests removal of an effect from the engine, which might not happen immediately (for example the Fx...
Definition fx_engine.cpp:52
FxPtr getFx(int index)
Retrieves an effect from the engine without removing it.
Definition fx_engine.cpp:73
bool mInterpolate
Definition fx_engine.h:127
TimeWarp mTimeFunction
Definition fx_engine.h:119
int addFx(Fx &effect)
Adds a new effect to the engine.
Definition fx_engine.h:66
Definition fx.h:18
static Ptr NoTracking(T &referent)
Definition ptr.h:132
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55