FastLED 3.9.15
Loading...
Searching...
No Matches
fx_engine.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/flat_map.h"
4#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
5#include "fl/stl/vector.h"
6#include "fl/audio/audio_frame.h" // AudioFrame (stored in vectors)
8#include "fl/fx/fx.h"
9#include "fl/fx/time.h"
10#include "fl/fx/video.h"
11#include "fl/stl/stdint.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl { namespace audio { class Processor; } }
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(u16 numLeds, bool interpolate = true);
41
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, fl::span<CRGB> outputBuffer);
89
95 bool nextFx(u16 transition_ms = 500);
96
103 bool setNextFx(int index, u16 duration);
104
106
114 void pushAudioFrame(const AudioFrame &frame);
115
123
129 void setSpeed(float scale) { mTimeFunction.setSpeed(scale); }
130 float getSpeed() const { return mTimeFunction.scale(); }
131
132 private:
133 int mCounter = 0;
134 TimeWarp mTimeFunction; // FxEngine controls the clock, to allow
135 // "time-bending" effects.
139 u16 mDuration = 0;
141 false;
142 bool mInterpolate = true;
143
144 // Double-buffered audio frame accumulator.
145 // mAudioBack: frames pushed between draw() calls (write buffer).
146 // mAudioFront: frozen snapshot passed to effects during draw() (read buffer).
149
150 // Optional auto-polled audio source (set via setAudio()).
152};
153
154} // namespace fl
fl::UISlider scale("Scale", 4,.1, 4,.1)
void setAudio(fl::shared_ptr< fl::audio::Processor > proc)
Connects an audio processor for automatic audio delivery.
fl::vector< AudioFrame > mAudioBack
Definition fx_engine.h:148
bool nextFx(u16 transition_ms=500)
Transitions to the next effect in the sequence.
int addFx(FxPtr effect)
Adds a new effect to the engine.
FxEngine(u16 numLeds, bool interpolate=true)
Constructs an FxEngine with the specified number of LEDs.
void setSpeed(float scale)
Sets the speed of the fx engine, which will impact the speed of all effects.
Definition fx_engine.h:129
bool mDurationSet
Flag indicating if a new transition has been set.
Definition fx_engine.h:140
float getSpeed() const
Definition fx_engine.h:130
FxCompositor mCompositor
Handles effect transitions and rendering.
Definition fx_engine.h:137
int getCurrentFxId() const
Definition fx_engine.h:81
int mCurrId
Id of the current effect.
Definition fx_engine.h:138
fl::vector< AudioFrame > mAudioFront
Definition fx_engine.h:147
fl::shared_ptr< fl::audio::Processor > mAudioProcessor
Definition fx_engine.h:151
~FxEngine() FL_NOEXCEPT
Destructor for FxEngine.
u16 mDuration
Duration of the current transition.
Definition fx_engine.h:139
bool setNextFx(int index, u16 duration)
Sets the next effect to transition to.
IntFxMap & _getEffects()
Definition fx_engine.h:105
IntFxMap mEffects
Collection of effects.
Definition fx_engine.h:136
bool draw(fl::u32 now, fl::span< CRGB > outputBuffer)
Renders the current effect or transition to the output buffer.
void pushAudioFrame(const AudioFrame &frame)
Pushes an audio frame into the back buffer.
FxPtr removeFx(int index)
Requests removal of an effect from the engine, which might not happen immediately (for example the Fx...
fl::flat_map< int, FxPtr > IntFxMap
Definition fx_engine.h:35
FxPtr getFx(int index)
Retrieves an effect from the engine without removing it.
bool mInterpolate
Definition fx_engine.h:142
TimeWarp mTimeFunction
Definition fx_engine.h:134
int addFx(Fx &effect)
Adds a new effect to the engine.
Definition fx_engine.h:63
Definition fx.h:18
shared_ptr< T > make_shared_no_tracking(T &obj) FL_NOEXCEPT
Definition shared_ptr.h:435
Base definition for an LED controller.
Definition crgb.hpp:179
Lightweight snapshot of pre-computed audio analysis for one audio sample.
Definition audio_frame.h:10
#define FL_NOEXCEPT