27#include "../curves/animatedValue.h"
55 virtual ~AnimationType () =
default;
68 virtual bool setValue (
size_t , std::unique_ptr<AnimatedValue> )
89 virtual void cancel (
bool moveToEndPosition) = 0;
140 using ValueList = std::array<float, ValueCount>;
141 using UpdateFn = std::function<void (
int,
const ValueList&)>;
165template <std::
size_t ValueCount>
170 using SourceList = std::array<std::unique_ptr<AnimatedValue>, ValueCount>;
171 using ValueList =
typename UpdateSource<ValueCount>::ValueList;
204 bool setValue (
size_t index, std::unique_ptr<AnimatedValue> value)
override
206 if (index >= ValueCount)
212 sources[index] = std::move (value);
225 if (index < ValueCount)
248 juce::int64 deltaTime;
261 const auto totalElapsed { timeInMs -
startTime };
269 const auto effectElapsed { totalElapsed -
preDelay };
270 deltaTime = std::min (deltaTime, totalElapsed);
274 int completeCount { 0 };
276 for (
int i = 0; i < ValueCount; ++i)
282 values[i] = val->getNextValue (
static_cast<int> (effectElapsed),
283 static_cast<int> (deltaTime));
284 completeCount += (val->isFinished ()) ? 1 : 0;
293 if (completeCount == ValueCount)
299 void cancel (
bool moveToEndPosition)
override
304 val->cancel (moveToEndPosition);
307 if (moveToEndPosition && this->
updateFn !=
nullptr)
312 for (
int i = 0; i < ValueCount; ++i)
315 jassert (val !=
nullptr);
317 values[i] = val->getEndValue ();
334 if (
nullptr == src.get ())
368template <
class T,
int ValueCount,
class... Args>
369std::unique_ptr<Animation<ValueCount>> makeAnimation (
370 int id, std::array<float, ValueCount>&& from, std::array<float, ValueCount>&& to,
374 static_assert (std::is_base_of<AnimatedValue, T>::value);
376 auto animation { std::make_unique<Animation<ValueCount>> (id) };
378 for (
int i { 0 }; i < ValueCount; ++i)
380 auto curve { std::make_unique<T> (from[i], to[i], std::forward<Args> (args)...) };
381 animation->setValue (i, std::move (curve));
391template <
class T,
class... Args>
392std::unique_ptr<Animation<1>> makeAnimation (
int id,
float from,
float to, Args... args)
394 return makeAnimation<T, 1> (
id, { from }, { to }, std::forward<Args> (args)...);
Abstract base class for objects that can generate a useful series of values to drive UI animations.
Definition: animatedValue.h:34
This class owns a number of AnimatedValue objects. On each animation frame it gets the next calculate...
Definition: animation.h:168
Animation(int id=0)
Definition: animation.h:181
bool isFinished() override
Definition: animation.h:328
bool finished
is this animation complete?
Definition: animation.h:348
Status gotoTime(juce::int64 timeInMs) override
Advance to the specified time, sending value updates to the code that's waiting for them.
Definition: animation.h:239
juce::int64 startTime
Timestamp of first update.
Definition: animation.h:343
bool setValue(size_t index, std::unique_ptr< AnimatedValue > value) override
Definition: animation.h:204
SourceList sources
The array of animated value objects.
Definition: animation.h:351
Animation(SourceList &&sources, int id=0)
Construct a new Animation object, given a list of value sources.
Definition: animation.h:192
void cancel(bool moveToEndPosition) override
Cancel an in-progress animation, optionally moving directly to its end value.
Definition: animation.h:299
juce::int64 lastTime
timestamp of most recent update.
Definition: animation.h:345
AnimatedValue * getValue(size_t index) override
Retrieve a pointer to one of this animation's value sources. This should probably not be used very mu...
Definition: animation.h:223
bool isReady() const override
Definition: animation.h:330
Abstract base class; all the real action happens in the derived templated Animation class,...
Definition: animation.h:39
Status
Definition: animation.h:42
@ processing
The animation is running right now.
@ finished
Finished running, okay to clean up.
virtual bool isFinished()=0
virtual AnimatedValue * getValue(size_t index)=0
Retrieve a pointer to one of this animation's value objects.
virtual bool isReady() const =0
int animationId
optional ID value for this animation.
Definition: animation.h:130
virtual Status gotoTime(juce::int64 timeInMs)=0
Advance all active animations to this point in time.
int preDelay
an optional pre-delay before beginning to execute the effect.
Definition: animation.h:133
int getId() const
Definition: animation.h:60
CompletionFn completionFn
function to call when the animation is completed or canceled.
Definition: animation.h:126
void onCompletion(CompletionFn complete)
Definition: animation.h:122
virtual void cancel(bool moveToEndPosition)=0
Cancel an in-progress animation, optionally moving directly to its end value.
void setDelay(int delay)
Definition: animation.h:66
std::function< void(int, bool)> CompletionFn
callback on completion of this effect
Definition: animation.h:115
Definition: animation.h:137
void onUpdate(UpdateFn update)
Definition: animation.h:147
UpdateFn updateFn
Definition: animation.h:151