friz
An animation control system for JUCE
Loading...
Searching...
No Matches
friz::Animator Class Reference

A class that can own Animation objects and execute them at a regular interval. More...

#include <animator.h>

Public Member Functions

 Animator (std::unique_ptr< Controller > controller_=nullptr)
 Construct a new Animator object. If not configured otherwise, will create an animator that is controlled by a timer that updates around 30 Hz.
 
void setController (std::unique_ptr< Controller > controller)
 Set a new controller object, replacing (and destryoying) the current one.
 
ControllergetController () const
 return a pointer to the active controller object.
 
bool setFrameRate (int rateInHz)
 Attempt to set the controller's frame rate.
 
float getFrameRate () const
 get the (reported) frame rate of the controller. This may be the rate that was requested or a rate that's measured; the actual value returned is dependent on the controller object in use
 
void gotoTime (juce::int64 timeInMs)
 Update all active animations with a new time.
 
bool addAnimation (std::unique_ptr< AnimationType > animation)
 
bool cancelAnimation (int id, bool moveToEndPosition)
 
bool cancelAllAnimations (bool moveToEndPosition)
 
AnimationTypegetAnimation (int id)
 
int getAnimations (int id, std::vector< AnimationType * > &animations)
 
bool updateTarget (int id, int valIndex, float newTarget)
 Pass a new ending value to the animation at id, if it is still in progress. Not all animated value classes support this operation, so it may silently fail.
 

Private Member Functions

void cleanup ()
 

Private Attributes

std::unique_ptr< Controllercontroller
 
std::vector< std::unique_ptr< AnimationType > > animations
 
juce::CriticalSection mutex
 

Detailed Description

A class that can own Animation objects and execute them at a regular interval.

Since the timer that drives the animations only executes if there is currently an animation happening, there's no overhead when the animator is idle.

Constructor & Destructor Documentation

◆ Animator()

friz::Animator::Animator ( std::unique_ptr< Controller controller_ = nullptr)

Construct a new Animator object. If not configured otherwise, will create an animator that is controlled by a timer that updates around 30 Hz.

Parameters
controller

Member Function Documentation

◆ addAnimation()

bool friz::Animator::addAnimation ( std::unique_ptr< AnimationType animation)

Add a new animation to our list, which will start it going!

Parameters
animationThe animation sequence to play.
Returns
true if added okay.

◆ cancelAllAnimations()

bool friz::Animator::cancelAllAnimations ( bool  moveToEndPosition)

Cancel all active animations.

Parameters
moveToEndPositionTrue to force all values to their end positions first.
Returns
True if we canceled anything.

◆ cancelAnimation()

bool friz::Animator::cancelAnimation ( int  id,
bool  moveToEndPosition 
)

Cancel any animations with the specified ID, optionally sending one last update call with all values set to their end positions. ID values aren't required to be unique, so this will check all active animations for a matching value.

Parameters
idID of the animation(s) to cancel.
moveToEndPositiontrue to force all values to their end position before canceling.
Returns
True if at least one animation was canceled.

◆ cleanup()

void friz::Animator::cleanup ( )
private

Remove any animations that are complete or canceled from the list. If we end with the list empty, stop the timer

◆ getAnimation()

AnimationType * friz::Animator::getAnimation ( int  id)

Attempt to get a running animation object by passing in its ID value.

Parameters
idID of the animation you want. If more than one animation use the same ID, this will only return the first one found.
Returns
non-owning pointer (or nullptr if not present). Don't store this pointer as it may be deleted from beneath you.
See also
getAnimations()

◆ getAnimations()

int friz::Animator::getAnimations ( int  id,
std::vector< AnimationType * > &  animations 
)

Attempt to get all animations that use a specific ID.

Parameters
idID to look for.
animationsVector to fill with non-owning pointers.
Returns
number of effects found.

◆ getController()

Controller * friz::Animator::getController ( ) const

return a pointer to the active controller object.

Returns
Controller*

◆ getFrameRate()

float friz::Animator::getFrameRate ( ) const

get the (reported) frame rate of the controller. This may be the rate that was requested or a rate that's measured; the actual value returned is dependent on the controller object in use

Returns
float, < 0 on error.

◆ gotoTime()

void friz::Animator::gotoTime ( juce::int64  timeInMs)

Update all active animations with a new time.

Parameters
timeInMs

◆ setController()

void friz::Animator::setController ( std::unique_ptr< Controller controller)

Set a new controller object, replacing (and destryoying) the current one.

Parameters
controller

◆ setFrameRate()

bool friz::Animator::setFrameRate ( int  rateInHz)

Attempt to set the controller's frame rate.

Parameters
rateInHz
Returns
true if the controller's framerate can be changed, and the requested rate is valid.

◆ updateTarget()

bool friz::Animator::updateTarget ( int  id,
int  valIndex,
float  newTarget 
)

Pass a new ending value to the animation at id, if it is still in progress. Not all animated value classes support this operation, so it may silently fail.

Parameters
id
valIndexindex of the value within the animation.
newTarget
Returns
true If the animation exists; this doesn't indicate that we actually succeeded.

Member Data Documentation

◆ mutex

juce::CriticalSection friz::Animator::mutex
private

protect code that might contain data races if updates come from a different thread.


The documentation for this class was generated from the following files: