25#include <juce_gui_basics/juce_gui_basics.h>
26#include <juce_gui_extra/juce_gui_extra.h>
28#if JUCE_VERSION >= (7 << 16)
29#define FRIZ_VBLANK_ENABLED 1
31#define FRIZ_VBLANK_ENABLED 0
53 void update (juce::int64 timeInMs);
68 juce::int64 lastUpdate { -1 };
69 static constexpr int frameCount { 24 };
70 std::array<int, frameCount> memory;
72 std::atomic<int>
sum { 0 };
73 std::atomic<int> updateCount { 0 };
142 jassert (frameRate_ > 0);
168 void stop ()
override { stopTimer (); }
174 bool isRunning ()
const override {
return isTimerRunning (); }
177 void timerCallback ()
override;
184#if FRIZ_VBLANK_ENABLED
193class DisplaySyncController :
public Controller
196 DisplaySyncController (juce::Component* syncSource_)
197 : syncSource { syncSource_ }
201 virtual float getFrameRate ()
const override
203 return isRunning () ? frameRate.get () : 0.f;
209 virtual void start ()
override;
215 virtual void stop ()
override
225 virtual bool isRunning ()
const override
237 juce::Component* syncSource;
240 juce::VBlankAttachment sync;
242 FrameRateCalculator frameRate;
243 bool running {
false };
259 void start ()
override { running =
true; }
261 void stop ()
override { running =
false; }
272 bool gotoTime (juce::int64 timeInMs);
276 bool running {
false };
277 juce::int64 lastTime { 0 };
A class that can own Animation objects and execute them at a regular interval.
Definition: animator.h:47
Controller to support clocking an animation manually, or at rates that aren't tied to wall-clock time...
Definition: controller.h:253
virtual float getFrameRate() const override
report the current frame rate, whether what was requested or the actual measured rate.
Definition: controller.h:257
bool isRunning() const override
Test to see if the timer is currently running.
Definition: controller.h:263
bool gotoTime(juce::int64 timeInMs)
Manually advance the animation to a point in time. Each call to this method must move time forward!
Definition: controller.cpp:94
void stop() override
Called whenever there are no more animations that need to be updated.
Definition: controller.h:261
void start() override
Called whenever we need to start timer callbacks flowing.
Definition: controller.h:259
Definition: controller.h:78
static juce::int64 getCurrentTime()
Calculate the current time in milliseconds since some event, probably system start....
Definition: controller.cpp:29
void setAnimator(Animator *animator_)
Definition: controller.h:89
virtual void start()=0
Called whenever we need to start timer callbacks flowing.
virtual float getFrameRate() const
report the current frame rate, whether what was requested or the actual measured rate.
Definition: controller.h:103
virtual bool setFrameRate(int)
Definition: controller.h:95
virtual void stop()=0
Called whenever there are no more animations that need to be updated.
Animator * animator
the animator object that owns us.
Definition: controller.h:133
virtual bool isRunning() const =0
Test to see if the timer is currently running.
Calculate the actual current (average) frame rate as measured at runtime.
Definition: controller.h:43
void clear()
reset all internal values before starting.
Definition: controller.cpp:62
std::atomic< int > sum
keep a running sum of intervals so we can just divide.
Definition: controller.h:72
void update(juce::int64 timeInMs)
Called each time we update the animator so we can keep track of the frequency.
Definition: controller.cpp:36
float get() const
Calculate the actual frame rate that we're running at.
Definition: controller.cpp:53
Definition: controller.h:138
void stop() override
Called whenever there are no more animations that need to be updated.
Definition: controller.h:168
void start() override
Called whenever we need to start timer callbacks flowing.
Definition: controller.h:158
bool setFrameRate(int frameRate_) override
Definition: controller.h:140
bool isRunning() const override
Test to see if the timer is currently running.
Definition: controller.h:174
int frameRate
Approx. frames/sec.
Definition: controller.h:181
float getFrameRate() const override
report the current frame rate, whether what was requested or the actual measured rate.
Definition: controller.h:153