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
7#include "crgb.h"
8#include "fl/map.h"
9#include "fx/fx.h"
11#include "fx/detail/fx_layer.h"
12#include "fl/namespace.h"
13#include "fl/ptr.h"
14#include "fl/ui.h"
15#include "fx/time.h"
16#include "fx/video.h"
17#include "fl/xymap.h"
18
19
20// Forward declaration
21class TimeFunction;
22
23#ifndef FASTLED_FX_ENGINE_MAX_FX
24#define FASTLED_FX_ENGINE_MAX_FX 64
25#endif
26
27namespace fl {
28
38class FxEngine {
39 public:
45 FxEngine(uint16_t numLeds, bool interpolate=true);
46
50 ~FxEngine();
51
57 int addFx(FxPtr effect);
58
59
68 int addFx(Fx& effect) { return addFx(fl::Ptr<Fx>::NoTracking(effect)); }
69
76 FxPtr removeFx(int index);
77
83 FxPtr getFx(int index);
84
85 int getCurrentFxId() const { return mCurrId; }
86
92 bool draw(uint32_t now, CRGB *outputBuffer);
93
99 bool nextFx(uint16_t transition_ms = 500);
100
107 bool setNextFx(int index, uint16_t duration);
108
109
111
116 void setSpeed(float scale) { mTimeFunction.setScale(scale); }
117
118 private:
119 int mCounter = 0;
120 TimeScale mTimeFunction; // FxEngine controls the clock, to allow "time-bending" effects.
124 uint16_t mDuration = 0;
125 bool mDurationSet = false;
126 bool mInterpolate = true;
127};
128
129} // namespace fl
UISlider scale("Scale", 4,.1, 4,.1)
int addFx(FxPtr effect)
Adds a new effect to the engine.
Definition fx_engine.cpp:16
void setSpeed(float scale)
Sets the speed of the fx engine, which will impact the speed of all effects.
Definition fx_engine.h:116
~FxEngine()
Destructor for FxEngine.
Definition fx_engine.cpp:14
fl::FixedMap< int, FxPtr, FASTLED_FX_ENGINE_MAX_FX > IntFxMap
Definition fx_engine.h:40
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
Definition fx_engine.cpp:37
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
TimeScale mTimeFunction
Definition fx_engine.h:120
int getCurrentFxId() const
Definition fx_engine.h:85
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:46
IntFxMap & _getEffects()
Definition fx_engine.h:110
FxEngine(uint16_t numLeds, bool interpolate=true)
Constructs an FxEngine with the specified number of LEDs.
Definition fx_engine.cpp:7
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.cpp:86
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:56
FxPtr getFx(int index)
Retrieves an effect from the engine without removing it.
Definition fx_engine.cpp:77
bool mInterpolate
Definition fx_engine.h:126
int addFx(Fx &effect)
Adds a new effect to the engine.
Definition fx_engine.h:68
Definition fx.h:18
static Ptr NoTracking(T &referent)
Definition ptr.h:116
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:54