LMMS
Loading...
Searching...
No Matches
juce::Timer Class Referenceabstract

#include <juce_Timer.h>

Inheritance diagram for juce::Timer:
juce::AnimatedPosition< AnimatedPositionBehaviours::ContinuousWithMomentum > juce::ARADocumentControllerSpecialisation::ARADocumentControllerImpl juce::ASIOAudioIODevice juce::AnimatedAppComponent juce::AnimatedPosition< Behaviour > juce::AudioProcessorValueTreeState juce::BubbleMessageComponent juce::Button::CallbackHelper juce::CallOutBox juce::CallOutBoxCallback juce::CaretComponent juce::CodeEditorComponent::Pimpl juce::ComponentAnimator juce::CoreAudioClasses::AudioIODeviceCombiner juce::CoreAudioClasses::CoreAudioIODevice juce::CoreAudioClasses::CoreAudioInternal juce::Desktop juce::DeviceChangeDetector juce::DragAndDropContainer::DragImageComponent juce::DropShadower::ParentVisibilityChangedListener juce::FileBrowserComponent juce::HWNDComponentPeer juce::HWNDComponentPeer::TemporaryImage juce::ImageCache::Pimpl juce::ImagePreviewComponent juce::JUCESplashScreen juce::LambdaInvoker juce::LinuxComponentPeer::LinuxRepaintManager juce::ListBox::ListViewport juce::MenuBarComponent juce::MouseInactivityDetector juce::MouseInputSource::SourceList juce::MultiTimerCallback juce::ParameterListener juce::PluginListComponent::Scanner juce::PopupMenu::HelperClasses::MouseSourceState juce::ProgressBar juce::PropertiesFile juce::ScreenSaverDefeater juce::ScrollBar juce::Slider::Pimpl::PopupDisplayComponent juce::SplashScreen juce::StatusItemContainer juce::TextEditor::TextHolderComponent juce::ThreadWithProgressWindow juce::TooltipWindow juce::TopLevelWindowManager juce::Win32MidiService

Classes

class  TimerThread

Public Member Functions

virtual ~Timer ()
virtual void timerCallback ()=0
void startTimer (int intervalInMilliseconds) noexcept
void startTimerHz (int timerFrequencyHz) noexcept
void stopTimer () noexcept
bool isTimerRunning () const noexcept
int getTimerInterval () const noexcept

Static Public Member Functions

static void JUCE_CALLTYPE callAfterDelay (int milliseconds, std::function< void()> functionToCall)
static void JUCE_CALLTYPE callPendingTimersSynchronously ()

Protected Member Functions

 Timer () noexcept
 Timer (const Timer &) noexcept

Private Member Functions

Timeroperator= (const Timer &)=delete

Private Attributes

size_t positionInQueue = (size_t) -1
int timerPeriodMs = 0

Friends

class TimerThread

Detailed Description

Makes repeated callbacks to a virtual method at a specified time interval.

A Timer's timerCallback() method will be repeatedly called at a given interval. When you create a Timer object, it will do nothing until the startTimer() method is called, which will cause the message thread to start making callbacks at the specified interval, until stopTimer() is called or the object is deleted.

The time interval isn't guaranteed to be precise to any more than maybe 10-20ms, and the intervals may end up being much longer than requested if the system is busy. Because the callbacks are made by the main message thread, anything that blocks the message queue for a period of time will also prevent any timers from running until it can carry on.

If you need to have a single callback that is shared by multiple timers with different frequencies, then the MultiTimer class allows you to do that - its structure is very similar to the Timer class, but contains multiple timers internally, each one identified by an ID number.

See also
HighResolutionTimer, MultiTimer

@tags{Events}

Constructor & Destructor Documentation

◆ Timer() [1/2]

juce::Timer::Timer ( )
protectednoexcept

Creates a Timer. When created, the timer is stopped, so use startTimer() to get it going.

◆ Timer() [2/2]

juce::Timer::Timer ( const Timer & )
protectednoexcept

Creates a copy of another timer.

Note that this timer won't be started, even if the one you're copying is running.

◆ ~Timer()

juce::Timer::~Timer ( )
virtual

Destructor.

Member Function Documentation

◆ callAfterDelay()

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

Invokes a lambda after a given number of milliseconds.

◆ callPendingTimersSynchronously()

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

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.

◆ operator=()

Timer & juce::Timer::operator= ( const Timer & )
privatedelete

◆ 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.

◆ timerCallback()

virtual void juce::Timer::timerCallback ( )
pure virtual

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.

Implemented in juce::AnimatedAppComponent, juce::AnimatedPosition< Behaviour >, juce::AnimatedPosition< AnimatedPositionBehaviours::ContinuousWithMomentum >, juce::ARADocumentControllerSpecialisation::ARADocumentControllerImpl, juce::ASIOAudioIODevice, juce::AudioProcessorValueTreeState, juce::BubbleMessageComponent, juce::Button::CallbackHelper, juce::CallOutBox, juce::CallOutBoxCallback, juce::CaretComponent, juce::CodeEditorComponent::Pimpl, juce::ComponentAnimator, juce::CoreAudioClasses::AudioIODeviceCombiner, juce::CoreAudioClasses::CoreAudioInternal, juce::CoreAudioClasses::CoreAudioIODevice, juce::Desktop, juce::DeviceChangeDetector, juce::DragAndDropContainer::DragImageComponent, juce::DropShadower::ParentVisibilityChangedListener, juce::FileBrowserComponent, juce::HWNDComponentPeer::TemporaryImage, juce::HWNDComponentPeer, juce::ImageCache::Pimpl, juce::ImagePreviewComponent, juce::JUCESplashScreen, juce::LambdaInvoker, juce::LinuxComponentPeer::LinuxRepaintManager, juce::ListBox::ListViewport, juce::MenuBarComponent, juce::MouseInactivityDetector, juce::MouseInputSource::SourceList, juce::MultiTimerCallback, juce::ParameterListener, juce::PluginListComponent::Scanner, juce::PopupMenu::HelperClasses::MouseSourceState, juce::ProgressBar, juce::PropertiesFile, juce::ScreenSaverDefeater, juce::ScrollBar, juce::Slider::Pimpl::PopupDisplayComponent, juce::SplashScreen, juce::StatusItemContainer, juce::TextEditor::TextHolderComponent, juce::ThreadWithProgressWindow, juce::TooltipWindow, juce::TopLevelWindowManager, and juce::Win32MidiService.

◆ TimerThread

friend class TimerThread
friend

Member Data Documentation

◆ positionInQueue

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

◆ timerPeriodMs

int juce::Timer::timerPeriodMs = 0
private

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