JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::TimedCallback Class Referencefinal

Utility class wrapping a single non-null callback called by a Timer. More...

#include <juce_TimedCallback.h>

Inheritance diagram for juce::TimedCallback:
Collaboration diagram for juce::TimedCallback:

Public Member Functions

 TimedCallback (std::function< void()> callbackIn)
 Constructor.
 
 ~TimedCallback () noexcept override
 Destructor.
 
int getTimerInterval () const noexcept
 Returns the timer's interval.
 
bool isTimerRunning () const noexcept
 Returns true if the timer is currently running.
 
void startTimer (int intervalInMilliseconds) noexcept
 Starts the timer and sets the length of interval required.
 
void startTimerHz (int timerFrequencyHz) noexcept
 Starts the timer with an interval specified in Hertz.
 
void stopTimer () noexcept
 Stops the timer.
 

Private Member Functions

void timerCallback () override
 The user-defined callback routine that actually gets called periodically.
 

Static Private Member Functions

static void callAfterDelay (int milliseconds, std::function< void()> functionToCall)
 Invokes a lambda after a given number of milliseconds.
 
static void callPendingTimersSynchronously ()
 For internal use only: invokes any timers that need callbacks.
 

Private Attributes

std::function< void()> callback
 
size_t positionInQueue = (size_t) -1
 
int timerPeriodMs = 0
 
SharedResourcePointer< TimerThread > timerThread
 

Detailed Description

Utility class wrapping a single non-null callback called by a Timer.

You can use the usual Timer functions to start and stop the TimedCallback. Deleting the TimedCallback will automatically stop the underlying Timer.

With this class you can use the Timer facility without inheritance.

See also
Timer @tags{Events}

Constructor & Destructor Documentation

◆ TimedCallback()

juce::TimedCallback::TimedCallback ( std::function< void()>  callbackIn)
inlineexplicit

Constructor.

The passed in callback must be non-null.

References callback, and jassert.

◆ ~TimedCallback()

juce::TimedCallback::~TimedCallback ( )
inlineoverridenoexcept

Destructor.

References stopTimer().

Member Function Documentation

◆ callAfterDelay()

static void juce::Timer::callAfterDelay ( int  milliseconds,
std::function< void()>  functionToCall 
)
staticinherited

Invokes a lambda after a given number of milliseconds.

◆ callPendingTimersSynchronously()

static void juce::Timer::callPendingTimersSynchronously ( )
staticinherited

For internal use only: invokes any timers that need callbacks.

Don't call this unless you really know what you're doing!

◆ getTimerInterval()

int juce::Timer::getTimerInterval ( ) const
inlinenoexcept

Returns the timer's interval.

Returns
the timer's interval in milliseconds if it's running, or 0 if it's not.

◆ isTimerRunning()

bool juce::Timer::isTimerRunning ( ) const
inlinenoexcept

Returns true if the timer is currently running.

◆ startTimer()

void juce::Timer::startTimer ( int  intervalInMilliseconds)
noexcept

Starts the timer and sets the length of interval required.

If the timer is already started, this will reset it, so the time between calling this method and the next timer callback will not be less than the interval length passed in.

Parameters
intervalInMillisecondsthe interval to use (any value less than 1 will be rounded up to 1)

◆ startTimerHz()

void juce::Timer::startTimerHz ( int  timerFrequencyHz)
noexcept

Starts the timer with an interval specified in Hertz.

This is effectively the same as calling startTimer (1000 / timerFrequencyHz).

◆ stopTimer()

void juce::Timer::stopTimer ( )
noexcept

Stops the timer.

No more timer callbacks will be triggered after this method returns.

Note that if you call this from a background thread while the message-thread is already in the middle of your callback, then this method will cancel any future timer callbacks, but it will return without waiting for the current one to finish. The current callback will continue, possibly still running some of your timer code after this method has returned.

Referenced by ~TimedCallback().

◆ timerCallback()

void juce::TimedCallback::timerCallback ( )
inlineoverrideprivatevirtual

The user-defined callback routine that actually gets called periodically.

It's perfectly ok to call startTimer() or stopTimer() from within this callback to change the subsequent intervals.

Implements juce::Timer.

References callback.

Member Data Documentation

◆ callback

std::function<void()> juce::TimedCallback::callback
private

Referenced by TimedCallback(), and timerCallback().

◆ positionInQueue

size_t juce::Timer::positionInQueue = (size_t) -1
privateinherited

◆ timerPeriodMs

int juce::Timer::timerPeriodMs = 0
privateinherited

◆ timerThread

SharedResourcePointer<TimerThread> juce::Timer::timerThread
privateinherited

The documentation for this class was generated from the following file: