JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AnimatedAppComponent.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29AnimatedAppComponent::AnimatedAppComponent()
30{
31 setOpaque (true);
32}
33
35{
36 jassert (0 < framesPerSecond && framesPerSecond < 1000);
37 framesPerSecond = framesPerSecondIn;
38 updateSync();
39}
40
41void AnimatedAppComponent::updateSync()
42{
43 if (useVBlank)
44 {
45 stopTimer();
46
47 if (vBlankAttachment.isEmpty())
48 vBlankAttachment = { this, [this] { timerCallback(); } };
49 }
50 else
51 {
52 vBlankAttachment = {};
53
54 const auto interval = 1000 / framesPerSecond;
55
56 if (getTimerInterval() != interval)
57 startTimer (interval);
58 }
59}
60
62{
63 useVBlank = syncToVBlank;
64 updateSync();
65}
66
68{
69 return (int) (Time::getCurrentTime() - lastUpdateTime).inMilliseconds();
70}
71
72void AnimatedAppComponent::timerCallback()
73{
74 ++totalUpdates;
75 update();
76 repaint();
77 lastUpdateTime = Time::getCurrentTime();
78}
79
80} // namespace juce
void setFramesPerSecond(int framesPerSecond)
Your subclass can call this to start a timer running which will call update() and repaint the compone...
int getMillisecondsSinceLastUpdate() const noexcept
When called from update(), this returns the number of milliseconds since the last update call.
void setSynchroniseToVBlank(bool syncToVBlank)
You can use this function to synchronise animation updates with the current display's vblank events.
virtual void update()=0
Called periodically, at the frequency specified by setFramesPerSecond().
void setOpaque(bool shouldBeOpaque)
Indicates whether any parts of the component might be transparent.
void repaint()
Marks the whole component as needing to be redrawn.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
void stopTimer() noexcept
Stops the timer.
int getTimerInterval() const noexcept
Returns the timer's interval.
Definition juce_Timer.h:116
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
bool isEmpty() const
Returns true for a default constructed object.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88