FastLED 3.9.15
Loading...
Searching...
No Matches
fx_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include "crgb.h"
4#include "fl/map.h"
5#include "fl/namespace.h"
6#include "fl/memory.h"
7#include "fl/ui.h"
8#include "fl/xymap.h"
10#include "fx/detail/fx_layer.h"
11#include "fx/fx.h"
12#include "fx/time.h"
13#include "fx/video.h"
14#include "fl/stdint.h"
15
16// TimeFunction is defined in fx/time.h (fl::TimeFunction)
17
18#ifndef FASTLED_FX_ENGINE_MAX_FX
19#define FASTLED_FX_ENGINE_MAX_FX 64
20#endif
21
22namespace fl {
23
33class FxEngine {
34 public:
40 FxEngine(uint16_t numLeds, bool interpolate = true);
41
45 ~FxEngine();
46
53 int addFx(FxPtr effect);
54
63 int addFx(Fx &effect) { return addFx(fl::make_shared_no_tracking(effect)); }
64
72 FxPtr removeFx(int index);
73
79 FxPtr getFx(int index);
80
81 int getCurrentFxId() const { return mCurrId; }
82
88 bool draw(fl::u32 now, CRGB *outputBuffer);
89
95 bool nextFx(uint16_t transition_ms = 500);
96
103 bool setNextFx(int index, uint16_t duration);
104
106
112 void setSpeed(float scale) { mTimeFunction.setSpeed(scale); }
113
114 private:
115 int mCounter = 0;
116 TimeWarp mTimeFunction; // FxEngine controls the clock, to allow
117 // "time-bending" effects.
121 uint16_t mDuration = 0;
123 false;
124 bool mInterpolate = true;
125};
126
127} // namespace fl
uint16_t scale
Definition Noise.ino:74
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:112
~FxEngine()
Destructor for FxEngine.
Definition fx_engine.cpp:10
fl::FixedMap< int, FxPtr, FASTLED_FX_ENGINE_MAX_FX > IntFxMap
Definition fx_engine.h:35
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:122
FxCompositor mCompositor
Handles effect transitions and rendering.
Definition fx_engine.h:119
int getCurrentFxId() const
Definition fx_engine.h:81
int mCurrId
Id of the current effect.
Definition fx_engine.h:120
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:105
FxEngine(uint16_t numLeds, bool interpolate=true)
Constructs an FxEngine with the specified number of LEDs.
Definition fx_engine.cpp:6
IntFxMap mEffects
Collection of effects.
Definition fx_engine.h:118
uint16_t mDuration
Duration of the current transition.
Definition fx_engine.h:121
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:124
TimeWarp mTimeFunction
Definition fx_engine.h:116
int addFx(Fx &effect)
Adds a new effect to the engine.
Definition fx_engine.h:63
bool draw(fl::u32 now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.cpp:82
Definition fx.h:18
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
shared_ptr< T > make_shared_no_tracking(T &obj)
Definition shared_ptr.h:379
IMPORTANT!
Definition crgb.h:20
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86