friz
An animation control system for JUCE
Loading...
Searching...
No Matches
sequence.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#pragma once
23
24#include "chain.h"
25
26namespace friz
27{
42template <std::size_t ValueCount>
43class Sequence : public Chain,
44 public UpdateSource<ValueCount>
45{
46public:
47 Sequence (int id = 0)
48 : Chain (id)
49 {
50 }
51
58 void addAnimation (std::unique_ptr<Animation<ValueCount>> effect)
59 {
60 // We need to make each of the effects notify us on update or completion,
61 // so that we can pass those along to whoever passed in a single
62 // lambda to us.
63 effect->updateFn =
64 [this] (int /*id*/, const typename Animation<ValueCount>::ValueList& val)
65 {
66 if (this->updateFn != nullptr)
67 this->updateFn (this->getId (), val);
68 };
69
70 effect->completionFn = [this] (int /*id*/, bool wasCanceled)
71 {
72 // Each effect in the sequence will notify us, but we only pass
73 // along the final one.
74 if ((currentEffect == sequence.size () - 1) && this->completionFn != nullptr)
75 this->completionFn (this->getId (), wasCanceled);
76 };
77
78 Chain::addAnimation (std::move (effect));
79 }
80};
81
82} // namespace friz
This class owns a number of AnimatedValue objects. On each animation frame it gets the next calculate...
Definition: animation.h:168
int getId() const
Definition: animation.h:60
CompletionFn completionFn
function to call when the animation is completed or canceled.
Definition: animation.h:126
A container animation object that holds several animations and executes them in order.
Definition: chain.h:41
std::vector< std::unique_ptr< AnimationType > > sequence
the vector that owns our chain of effects.
Definition: chain.h:114
int currentEffect
index (into the sequence vector) of the effect that we are currently processing.
Definition: chain.h:118
An Animation class that can hold multiple Animation objects and execute them in sequence.
Definition: sequence.h:45
void addAnimation(std::unique_ptr< Animation< ValueCount > > effect)
Add an animation with the correct number of values to our sequence of effects.
Definition: sequence.h:58
Definition: animation.h:137
UpdateFn updateFn
Definition: animation.h:151