Public Member Functions | Protected Member Functions

Timer Class Reference

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

Inherited by BubbleMessageComponent [private], CarbonViewWrapperComponent, CaretComponent, CodeEditorComponent, ComponentAnimator [private], Desktop [private], ImagePreviewComponent [private], MenuBarComponent [private], MidiKeyboardComponent [private], PluginListComponent, ProgressBar [private], PropertiesFile [private], ScrollBar [private], SplashScreen, ThreadWithProgressWindow [private], and TooltipWindow [private].

List of all members.

Public Member Functions

virtual ~Timer ()
 Destructor.
virtual void timerCallback ()=0
 The user-defined callback routine that actually gets called periodically.
void startTimer (int intervalInMilliseconds) noexcept
 Starts the timer and sets the length of interval required.
void stopTimer () noexcept
 Stops the timer.
bool isTimerRunning () const noexcept
 Checks if the timer has been started.
int getTimerInterval () const noexcept
 Returns the timer's interval.

Protected Member Functions

 Timer () noexcept
 Creates a Timer.
 Timer (const Timer &other) noexcept
 Creates a copy of another timer.

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:
MultiTimer

Constructor & Destructor Documentation

Timer::Timer (  ) [protected]

Creates a Timer.

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

Timer::Timer ( const Timer other ) [protected]

Creates a copy of another timer.

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

virtual Timer::~Timer (  ) [virtual]

Destructor.


Member Function Documentation

virtual void 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 PluginListComponent, CodeEditorComponent, ImagePreviewComponent, CaretComponent, BubbleMessageComponent, MidiKeyboardComponent, SplashScreen, and CarbonViewWrapperComponent.

void Timer::startTimer ( int  intervalInMilliseconds )

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 values less than 1 will be rounded up to 1)

Referenced by CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

void Timer::stopTimer (  )

Stops the timer.

No more callbacks will be made after this method returns.

If this is called from a different thread, any callbacks that may be currently executing may be allowed to finish before the method returns.

Referenced by CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

bool Timer::isTimerRunning (  ) const

Checks if the timer has been started.

Returns:
true if the timer is running.
int Timer::getTimerInterval (  ) const

Returns the timer's interval.

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

Referenced by CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines