friz
An animation control system for JUCE
Loading...
Searching...
No Matches
animator.h
1/*
2 Copyright (c) 2019-2023 Brett g Porter
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21*/
22
23#pragma once
24
25// #include "../animatorApp.h"
26
27#include "../curves/constant.h"
28#include "../curves/easing.h"
29#include "../curves/linear.h"
30#include "../curves/spring.h"
31#include "animation.h"
32
33namespace friz
34{
35
36class Controller;
37
47{
48public:
56 Animator (std::unique_ptr<Controller> controller_ = nullptr);
57
58 ~Animator ();
59
66 void setController (std::unique_ptr<Controller> controller);
67
73 Controller* getController () const;
74
82 bool setFrameRate (int rateInHz);
83
91 float getFrameRate () const;
92
98 void gotoTime (juce::int64 timeInMs);
99
105 bool addAnimation (std::unique_ptr<AnimationType> animation);
106
117 bool cancelAnimation (int id, bool moveToEndPosition);
118
124 bool cancelAllAnimations (bool moveToEndPosition);
125
134 AnimationType* getAnimation (int id);
135
142 int getAnimations (int id, std::vector<AnimationType*>& animations);
143
155 bool updateTarget (int id, int valIndex, float newTarget);
156
157private:
162 void cleanup ();
163
164private:
165 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Animator)
166
167 std::unique_ptr<Controller> controller;
168
169 std::vector<std::unique_ptr<AnimationType>> animations;
170
173 juce::CriticalSection mutex;
174};
175
176} // namespace friz
Abstract base class; all the real action happens in the derived templated Animation class,...
Definition: animation.h:39
A class that can own Animation objects and execute them at a regular interval.
Definition: animator.h:47
void cleanup()
Definition: animator.cpp:138
AnimationType * getAnimation(int id)
Definition: animator.cpp:151
bool setFrameRate(int rateInHz)
Attempt to set the controller's frame rate.
Definition: animator.cpp:51
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 cl...
Definition: animator.cpp:178
void setController(std::unique_ptr< Controller > controller)
Set a new controller object, replacing (and destryoying) the current one.
Definition: animator.cpp:40
float getFrameRate() const
get the (reported) frame rate of the controller. This may be the rate that was requested or a rate th...
Definition: animator.cpp:62
int getAnimations(int id, std::vector< AnimationType * > &animations)
Definition: animator.cpp:162
bool cancelAnimation(int id, bool moveToEndPosition)
Definition: animator.cpp:113
void gotoTime(juce::int64 timeInMs)
Update all active animations with a new time.
Definition: animator.cpp:73
bool addAnimation(std::unique_ptr< AnimationType > animation)
Definition: animator.cpp:92
bool cancelAllAnimations(bool moveToEndPosition)
Definition: animator.cpp:133
Controller * getController() const
return a pointer to the active controller object.
Definition: animator.cpp:46
juce::CriticalSection mutex
Definition: animator.h:173
Definition: controller.h:78