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_VBlankAttachment.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
30 : owner (c),
31 callback (std::move (callbackIn))
32{
33 jassert (owner != nullptr && callback);
34
35 updateOwner();
36 updatePeer();
37}
38
40 : VBlankAttachment (other.owner, std::move (other.callback))
41{
42 other.cleanup();
43}
44
45VBlankAttachment& VBlankAttachment::operator= (VBlankAttachment&& other)
46{
47 cleanup();
48
49 owner = other.owner;
50 callback = std::move (other.callback);
51 updateOwner();
52 updatePeer();
53
54 other.cleanup();
55
56 return *this;
57}
58
63
65{
66 callback();
67}
68
73
74void VBlankAttachment::updateOwner()
75{
76 if (auto previousLastOwner = std::exchange (lastOwner, owner); previousLastOwner != owner)
77 {
78 if (previousLastOwner != nullptr)
79 previousLastOwner->removeComponentListener (this);
80
81 if (owner != nullptr)
82 owner->addComponentListener (this);
83 }
84}
85
86void VBlankAttachment::updatePeer()
87{
88 if (owner != nullptr)
89 {
90 if (auto* peer = owner->getPeer())
91 {
92 peer->addVBlankListener (this);
93
94 if (lastPeer != peer && ComponentPeer::isValidPeer (lastPeer))
95 lastPeer->removeVBlankListener (this);
96
97 lastPeer = peer;
98 }
99 }
100 else if (auto peer = std::exchange (lastPeer, nullptr); ComponentPeer::isValidPeer (peer))
101 {
102 peer->removeVBlankListener (this);
103 }
104}
105
106void VBlankAttachment::cleanup()
107{
108 owner = nullptr;
109 updateOwner();
110 updatePeer();
111}
112
113} // namespace juce
void removeVBlankListener(VBlankListener *listenerToRemove)
Removes a VBlankListener.
static bool isValidPeer(const ComponentPeer *peer) noexcept
Checks if this peer object is valid.
The base class for all JUCE user-interface objects.
void addComponentListener(ComponentListener *newListener)
Adds a listener to be told about changes to the component hierarchy or position.
ComponentPeer * getPeer() const
Returns the heavyweight window that contains this component.
Helper class to synchronise Component updates to the vertical blank event of the display that the Com...
~VBlankAttachment() override
Destructor.
VBlankAttachment()=default
Default constructor for creating an empty object.
void componentParentHierarchyChanged(Component &) override
Called to indicate that the component's parents have changed.
void onVBlank() override
Called on every vertical blank of the display to which the peer is associated.
T exchange(T... args)
#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