10#include "fx/detail/fx_compositor.h"
11#include "fx/detail/fx_layer.h"
15#include "fx/detail/time_warp.h"
22#ifndef FASTLED_FX_ENGINE_MAX_FX
23#define FASTLED_FX_ENGINE_MAX_FX 64
26FASTLED_NAMESPACE_BEGIN
56 int addFx(FxRef effect);
90 FxRef
getFx(
int index);
92 int getCurrentFxId()
const {
return mCurrId; }
99 bool draw(uint32_t now,
CRGB *outputBuffer);
106 bool nextFx(uint16_t transition_ms = 500);
114 bool setNextFx(
int index, uint16_t duration);
117 IntFxMap& _getEffects() {
return mEffects; }
123 void setTimeScale(
float timeScale) { mTimeWarp.setTimeScale(timeScale); }
132 uint16_t mDuration = 0;
133 bool mDurationSet =
false;
137 : mTimeBender(
"FxEngineSpeed", 1.0f, -50.0f, 50.0f, 0.01f),
139 mCompositor(numLeds),
146 bool auto_set = mEffects.empty();
147 bool ok = mEffects.insert(mCounter, effect);
153 mCompositor.startTransition(0, 0, effect);
159 auto vidfx = VideoFxRef::New(video, xymap);
160 int id =
addFx(vidfx);
165 bool ok = mEffects.next(mCurrId, &mCurrId,
true);
174 if (!mEffects.has(index)) {
178 mDuration = duration;
184 if (!mEffects.has(index)) {
189 bool ok = mEffects.get(index, &removedFx);
194 if (mCurrId == index) {
196 mEffects.next(mCurrId, &mCurrId,
true);
205 if (mEffects.has(
id)) {
207 mEffects.get(
id, &fx);
214 mTimeWarp.setTimeScale(mTimeBender);
215 mTimeWarp.update(now);
216 uint32_t warpedTime = mTimeWarp.getTime();
218 if (mEffects.empty()) {
223 bool ok = mEffects.get(mCurrId, &fx);
228 mCompositor.startTransition(now, mDuration, fx);
229 mDurationSet =
false;
231 if (!mEffects.empty()) {
232 mCompositor.draw(now, warpedTime, finalBuffer);
Manages and renders multiple visual effects (Fx) for LED strips.
int addFx(Fx &effect)
Adds a new effect to the engine.
int addFx(FxRef effect)
Adds a new effect to the engine.
bool setNextFx(int index, uint16_t duration)
Sets the next effect to transition to.
void setTimeScale(float timeScale)
Sets the time scale for the TimeWarp object.
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
FxRef removeFx(int index)
Requests removal of an effect from the engine, which might not happen immediately (for example the Fx...
~FxEngine()
Destructor for FxEngine.
int addVideo(Video video, XYMap xymap)
Adds a new video effect to the engine.
FxRef getFx(int index)
Retrieves an effect from the engine without removing it.
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
FxEngine(uint16_t numLeds)
Constructs an FxEngine with the specified number of LEDs.
Representation of an RGB pixel (Red, Green, Blue)