OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce_MultiTimer.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26struct MultiTimerCallback : public Timer
27{
28 MultiTimerCallback (const int tid, MultiTimer& mt) noexcept
29 : owner (mt), timerID (tid)
30 {
31 }
32
33 void timerCallback() override
34 {
35 owner.timerCallback (timerID);
36 }
37
38 MultiTimer& owner;
39 const int timerID;
40
41 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiTimerCallback)
42};
43
44//==============================================================================
47
49{
50 const SpinLock::ScopedLockType sl (timerListLock);
51 timers.clear();
52}
53
54//==============================================================================
55Timer* MultiTimer::getCallback (int timerID) const noexcept
56{
57 for (int i = timers.size(); --i >= 0;)
58 {
59 MultiTimerCallback* const t = static_cast<MultiTimerCallback*> (timers.getUnchecked(i));
60
61 if (t->timerID == timerID)
62 return t;
63 }
64
65 return nullptr;
66}
67
68void MultiTimer::startTimer (const int timerID, const int intervalInMilliseconds) noexcept
69{
70 const SpinLock::ScopedLockType sl (timerListLock);
71
72 Timer* timer = getCallback (timerID);
73
74 if (timer == nullptr)
75 timers.add (timer = new MultiTimerCallback (timerID, *this));
76
78}
79
80void MultiTimer::stopTimer (const int timerID) noexcept
81{
82 const SpinLock::ScopedLockType sl (timerListLock);
83
84 if (Timer* const t = getCallback (timerID))
85 t->stopTimer();
86}
87
88bool MultiTimer::isTimerRunning (const int timerID) const noexcept
89{
90 const SpinLock::ScopedLockType sl (timerListLock);
91
92 if (Timer* const t = getCallback (timerID))
93 return t->isTimerRunning();
94
95 return false;
96}
97
98int MultiTimer::getTimerInterval (const int timerID) const noexcept
99{
100 const SpinLock::ScopedLockType sl (timerListLock);
101
102 if (Timer* const t = getCallback (timerID))
103 return t->getTimerInterval();
104
105 return 0;
106}
107
108} // namespace juce
void clear()
Definition juce_Array.h:188
int getTimerInterval(int timerID) const noexcept
void stopTimer(int timerID) noexcept
bool isTimerRunning(int timerID) const noexcept
void startTimer(int timerID, int intervalInMilliseconds) noexcept
void startTimer(int intervalInMilliseconds) noexcept