mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
tweaks to avoid user code name clashes with Timer.
This commit is contained in:
parent
0c99e8e068
commit
490baecdc5
2 changed files with 49 additions and 51 deletions
|
|
@ -112,10 +112,10 @@ public:
|
|||
{
|
||||
const LockType::ScopedLockType sl (lock);
|
||||
|
||||
while (firstTimer != nullptr && firstTimer->countdownMs <= 0)
|
||||
while (firstTimer != nullptr && firstTimer->timerCountdownMs <= 0)
|
||||
{
|
||||
Timer* const t = firstTimer;
|
||||
t->countdownMs = t->periodMs;
|
||||
t->timerCountdownMs = t->timerPeriodMs;
|
||||
|
||||
removeTimer (t);
|
||||
addTimer (t);
|
||||
|
|
@ -169,11 +169,11 @@ public:
|
|||
{
|
||||
if (instance != nullptr)
|
||||
{
|
||||
tim->countdownMs = newCounter;
|
||||
tim->periodMs = newCounter;
|
||||
tim->timerCountdownMs = newCounter;
|
||||
tim->timerPeriodMs = newCounter;
|
||||
|
||||
if ((tim->next != nullptr && tim->next->countdownMs < tim->countdownMs)
|
||||
|| (tim->previous != nullptr && tim->previous->countdownMs > tim->countdownMs))
|
||||
if ((tim->nextTimer != nullptr && tim->nextTimer->timerCountdownMs < tim->timerCountdownMs)
|
||||
|| (tim->previousTimer != nullptr && tim->previousTimer->timerCountdownMs > tim->timerCountdownMs))
|
||||
{
|
||||
instance->removeTimer (tim);
|
||||
instance->addTimer (tim);
|
||||
|
|
@ -210,28 +210,28 @@ private:
|
|||
|
||||
Timer* i = firstTimer;
|
||||
|
||||
if (i == nullptr || i->countdownMs > t->countdownMs)
|
||||
if (i == nullptr || i->timerCountdownMs > t->timerCountdownMs)
|
||||
{
|
||||
t->next = firstTimer;
|
||||
t->nextTimer = firstTimer;
|
||||
firstTimer = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (i->next != nullptr && i->next->countdownMs <= t->countdownMs)
|
||||
i = i->next;
|
||||
while (i->nextTimer != nullptr && i->nextTimer->timerCountdownMs <= t->timerCountdownMs)
|
||||
i = i->nextTimer;
|
||||
|
||||
jassert (i != nullptr);
|
||||
|
||||
t->next = i->next;
|
||||
t->previous = i;
|
||||
i->next = t;
|
||||
t->nextTimer = i->nextTimer;
|
||||
t->previousTimer = i;
|
||||
i->nextTimer = t;
|
||||
}
|
||||
|
||||
if (t->next != nullptr)
|
||||
t->next->previous = t;
|
||||
if (t->nextTimer != nullptr)
|
||||
t->nextTimer->previousTimer = t;
|
||||
|
||||
jassert ((t->next == nullptr || t->next->countdownMs >= t->countdownMs)
|
||||
&& (t->previous == nullptr || t->previous->countdownMs <= t->countdownMs));
|
||||
jassert ((t->nextTimer == nullptr || t->nextTimer->timerCountdownMs >= t->timerCountdownMs)
|
||||
&& (t->previousTimer == nullptr || t->previousTimer->timerCountdownMs <= t->timerCountdownMs));
|
||||
|
||||
notify();
|
||||
}
|
||||
|
|
@ -244,32 +244,32 @@ private:
|
|||
jassert (timerExists (t));
|
||||
#endif
|
||||
|
||||
if (t->previous != nullptr)
|
||||
if (t->previousTimer != nullptr)
|
||||
{
|
||||
jassert (firstTimer != t);
|
||||
t->previous->next = t->next;
|
||||
t->previousTimer->nextTimer = t->nextTimer;
|
||||
}
|
||||
else
|
||||
{
|
||||
jassert (firstTimer == t);
|
||||
firstTimer = t->next;
|
||||
firstTimer = t->nextTimer;
|
||||
}
|
||||
|
||||
if (t->next != nullptr)
|
||||
t->next->previous = t->previous;
|
||||
if (t->nextTimer != nullptr)
|
||||
t->nextTimer->previousTimer = t->previousTimer;
|
||||
|
||||
t->next = nullptr;
|
||||
t->previous = nullptr;
|
||||
t->nextTimer = nullptr;
|
||||
t->previousTimer = nullptr;
|
||||
}
|
||||
|
||||
int getTimeUntilFirstTimer (const int numMillisecsElapsed) const
|
||||
{
|
||||
const LockType::ScopedLockType sl (lock);
|
||||
|
||||
for (Timer* t = firstTimer; t != nullptr; t = t->next)
|
||||
t->countdownMs -= numMillisecsElapsed;
|
||||
for (Timer* t = firstTimer; t != nullptr; t = t->nextTimer)
|
||||
t->timerCountdownMs -= numMillisecsElapsed;
|
||||
|
||||
return firstTimer != nullptr ? firstTimer->countdownMs : 1000;
|
||||
return firstTimer != nullptr ? firstTimer->timerCountdownMs : 1000;
|
||||
}
|
||||
|
||||
void handleAsyncUpdate() override
|
||||
|
|
@ -280,7 +280,7 @@ private:
|
|||
#if JUCE_DEBUG
|
||||
bool timerExists (Timer* const t) const noexcept
|
||||
{
|
||||
for (Timer* tt = firstTimer; tt != nullptr; tt = tt->next)
|
||||
for (Timer* tt = firstTimer; tt != nullptr; tt = tt->nextTimer)
|
||||
if (tt == t)
|
||||
return true;
|
||||
|
||||
|
|
@ -296,18 +296,18 @@ Timer::TimerThread::LockType Timer::TimerThread::lock;
|
|||
|
||||
//==============================================================================
|
||||
Timer::Timer() noexcept
|
||||
: countdownMs (0),
|
||||
periodMs (0),
|
||||
previous (nullptr),
|
||||
next (nullptr)
|
||||
: timerCountdownMs (0),
|
||||
timerPeriodMs (0),
|
||||
previousTimer (nullptr),
|
||||
nextTimer (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Timer::Timer (const Timer&) noexcept
|
||||
: countdownMs (0),
|
||||
periodMs (0),
|
||||
previous (nullptr),
|
||||
next (nullptr)
|
||||
: timerCountdownMs (0),
|
||||
timerPeriodMs (0),
|
||||
previousTimer (nullptr),
|
||||
nextTimer (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -320,10 +320,10 @@ void Timer::startTimer (const int interval) noexcept
|
|||
{
|
||||
const TimerThread::LockType::ScopedLockType sl (TimerThread::lock);
|
||||
|
||||
if (periodMs == 0)
|
||||
if (timerPeriodMs == 0)
|
||||
{
|
||||
countdownMs = interval;
|
||||
periodMs = jmax (1, interval);
|
||||
timerCountdownMs = interval;
|
||||
timerPeriodMs = jmax (1, interval);
|
||||
TimerThread::add (this);
|
||||
}
|
||||
else
|
||||
|
|
@ -344,10 +344,10 @@ void Timer::stopTimer() noexcept
|
|||
{
|
||||
const TimerThread::LockType::ScopedLockType sl (TimerThread::lock);
|
||||
|
||||
if (periodMs > 0)
|
||||
if (timerPeriodMs > 0)
|
||||
{
|
||||
TimerThread::remove (this);
|
||||
periodMs = 0;
|
||||
timerPeriodMs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ class JUCE_API Timer
|
|||
protected:
|
||||
//==============================================================================
|
||||
/** Creates a Timer.
|
||||
|
||||
When created, the timer is stopped, so use startTimer() to get it going.
|
||||
*/
|
||||
Timer() noexcept;
|
||||
|
|
@ -64,7 +63,7 @@ protected:
|
|||
Note that this timer won't be started, even if the one you're copying
|
||||
is running.
|
||||
*/
|
||||
Timer (const Timer& other) noexcept;
|
||||
Timer (const Timer&) noexcept;
|
||||
|
||||
public:
|
||||
//==============================================================================
|
||||
|
|
@ -86,8 +85,8 @@ public:
|
|||
time between calling this method and the next timer callback
|
||||
will not be less than the interval length passed in.
|
||||
|
||||
@param intervalInMilliseconds the interval to use (any values less than 1 will be
|
||||
rounded up to 1)
|
||||
@param intervalInMilliseconds the interval to use (any value less
|
||||
than 1 will be rounded up to 1)
|
||||
*/
|
||||
void startTimer (int intervalInMilliseconds) noexcept;
|
||||
|
||||
|
|
@ -108,12 +107,12 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Returns true if the timer is currently running. */
|
||||
bool isTimerRunning() const noexcept { return periodMs > 0; }
|
||||
bool isTimerRunning() const noexcept { return timerPeriodMs > 0; }
|
||||
|
||||
/** Returns the timer's interval.
|
||||
@returns the timer's interval in milliseconds if it's running, or 0 if it's not.
|
||||
*/
|
||||
int getTimerInterval() const noexcept { return periodMs; }
|
||||
int getTimerInterval() const noexcept { return timerPeriodMs; }
|
||||
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -125,11 +124,10 @@ public:
|
|||
private:
|
||||
class TimerThread;
|
||||
friend class TimerThread;
|
||||
int countdownMs, periodMs;
|
||||
Timer* previous;
|
||||
Timer* next;
|
||||
int timerCountdownMs, timerPeriodMs; // NB: these member variable names are a little verbose
|
||||
Timer* previousTimer, *nextTimer; // to reduce risk of name-clashes with user subclasses
|
||||
|
||||
Timer& operator= (const Timer&);
|
||||
Timer& operator= (const Timer&) JUCE_DELETED_FUNCTION;
|
||||
};
|
||||
|
||||
#endif // JUCE_TIMER_H_INCLUDED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue