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
23 namespace juce
24{
25
26 struct 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//==============================================================================
45 MultiTimer::MultiTimer() noexcept {}
46 MultiTimer::MultiTimer (const MultiTimer&) noexcept {}
47
48 MultiTimer::~MultiTimer()
49{
50 const SpinLock::ScopedLockType sl (timerListLock);
51 timers.clear();
52}
53
54//==============================================================================
55 Timer* 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
68 void 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
77 timer->startTimer (intervalInMilliseconds);
78}
79
80 void 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
88 bool 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
98 int 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
juce::GenericScopedLock
Definition: juce_ScopedLock.h:55
juce::MultiTimer
Definition: juce_MultiTimer.h:46
juce::MultiTimer::MultiTimer
MultiTimer() noexcept
Definition: juce_MultiTimer.cpp:45
juce::MultiTimer::getTimerInterval
int getTimerInterval(int timerID) const noexcept
Definition: juce_MultiTimer.cpp:98
juce::MultiTimer::stopTimer
void stopTimer(int timerID) noexcept
Definition: juce_MultiTimer.cpp:80
juce::MultiTimer::isTimerRunning
bool isTimerRunning(int timerID) const noexcept
Definition: juce_MultiTimer.cpp:88
juce::MultiTimer::startTimer
void startTimer(int timerID, int intervalInMilliseconds) noexcept
Definition: juce_MultiTimer.cpp:68
juce::MultiTimer::~MultiTimer
virtual ~MultiTimer()
Definition: juce_MultiTimer.cpp:48
juce::Timer
Definition: juce_Timer.h:52
juce::Timer::startTimer
void startTimer(int intervalInMilliseconds) noexcept
Definition: juce_Timer.cpp:323