FastLED 3.9.15
Loading...
Searching...
No Matches
frame_interpolator.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/fx/frame.h"
4#include "fl/stl/flat_map.h"
5#include "fl/stl/shared_ptr.h"
6#include "fl/stl/span.h"
7#include "fl/fx/frame.h"
9
10namespace fl {
11namespace video {
12
14
15// Holds onto frames and allow interpolation. This allows
16// effects to have high effective frame rate and also
17// respond to things like sound which can modify the timing.
19 public:
20 struct Less {
21 bool operator()(fl::u32 a, fl::u32 b) const { return a < b; }
22 };
24 FrameInterpolator(size_t nframes, float fpsVideo);
25
26 // Will search through the array, select the two frames that are closest to
27 // the current time and then interpolate between them, storing the results
28 // in the provided frame. The destination frame will have "now" as the
29 // current timestamp if and only if there are two frames that can be
30 // interpolated. Else it's set to the timestamp of the frame that was
31 // selected. Returns true if the interpolation was successful, false
32 // otherwise. If false then the destination frame will not be modified. Note
33 // that this adjustable_time is allowed to go pause or go backward in time.
34 bool draw(fl::u32 adjustable_time, Frame *dst);
35 bool draw(fl::u32 adjustable_time, fl::span<CRGB> leds);
36 bool insert(fl::u32 frameNumber, FramePtr frame) {
38 mFrames.insert(frameNumber, frame, &result);
40 }
41
42 // Clear all frames
43 void clear() { mFrames.clear(); }
44
45 bool empty() const { return mFrames.empty(); }
46
47 bool has(fl::u32 frameNum) const { return mFrames.has(frameNum); }
48
49 FramePtr erase(fl::u32 frameNum) {
50 FramePtr out;
51 auto it = mFrames.find(frameNum);
52 if (it == mFrames.end()) {
53 return out;
54 }
55 out = it->second;
56 mFrames.erase(it);
57 return out;
58 }
59
60 FramePtr get(fl::u32 frameNum) const {
61 auto it = mFrames.find(frameNum);
62 if (it != mFrames.end()) {
63 return it->second;
64 }
65 return FramePtr();
66 }
67
68 bool full() const { return mFrames.full(); }
69 size_t capacity() const { return mFrames.capacity(); }
70
72
73 bool needsFrame(fl::u32 now, fl::u32 *currentFrameNumber,
74 fl::u32 *nextFrameNumber) const {
75 mFrameTracker.get_interval_frames(now, currentFrameNumber,
76 nextFrameNumber);
77 return !has(*currentFrameNumber) || !has(*nextFrameNumber);
78 }
79
80 bool get_newest_frame_number(fl::u32 *frameNumber) const {
81 if (mFrames.empty()) {
82 return false;
83 }
84 auto &front = mFrames.back();
85 *frameNumber = front.first;
86 return true;
87 }
88
89 bool get_oldest_frame_number(fl::u32 *frameNumber) const {
90 if (mFrames.empty()) {
91 return false;
92 }
93 auto &front = mFrames.front();
94 *frameNumber = front.first;
95 return true;
96 }
97
98 fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const {
99 return mFrameTracker.get_exact_timestamp_ms(frameNumber);
100 }
101
103
104 private:
107};
108
109} // namespace video
110} // namespace fl
fl::CRGB leds[NUM_LEDS]
bool has(fl::u32 frameNum) const
fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const
FramePtr get(fl::u32 frameNum) const
FrameInterpolator(size_t nframes, float fpsVideo)
bool get_newest_frame_number(fl::u32 *frameNumber) const
bool get_oldest_frame_number(fl::u32 *frameNumber) const
fl::flat_map< fl::u32, FramePtr, Less > FrameBuffer
bool draw(fl::u32 adjustable_time, Frame *dst)
bool needsFrame(fl::u32 now, fl::u32 *currentFrameNumber, fl::u32 *nextFrameNumber) const
FramePtr erase(fl::u32 frameNum)
bool insert(fl::u32 frameNumber, FramePtr frame)
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
bool operator()(fl::u32 a, fl::u32 b) const