|
Gin
|
An efficient timer that shares a single juce::Timer between multiple instances. More...
#include <gin_coalescedtimer.h>
Public Member Functions | |
| CoalescedTimer ()=default | |
| Creates a stopped CoalescedTimer. | |
| ~CoalescedTimer () | |
| Destructor. | |
| void | startTimer (int ms) |
| Starts the timer with the specified interval in milliseconds. | |
| void | startTimerHz (int hz) |
| Starts the timer with the specified frequency in Hz. | |
| void | stopTimer () |
| Stops the timer. | |
Public Attributes | |
| std::function< void()> | onTimer |
| Callback function called at the specified interval. | |
An efficient timer that shares a single juce::Timer between multiple instances.
Instead of each timer instance creating its own juce::Timer thread, this class coalesces all timers with the same interval into a single shared juce::Timer. This reduces overhead when you have many timers running at the same rate.
Benefits:
Example usage:
|
default |
Creates a stopped CoalescedTimer.
| CoalescedTimer::~CoalescedTimer | ( | ) |
Starts the timer with the specified interval in milliseconds.
If the timer is already running, it will be restarted with the new interval. Multiple CoalescedTimer instances with the same interval will share a single underlying juce::Timer.
| ms | The timer interval in milliseconds |
References stopTimer().
Referenced by startTimerHz().
Starts the timer with the specified frequency in Hz.
This is a convenience method that converts frequency to interval. For example, 60 Hz becomes approximately 16.67 milliseconds.
| hz | The desired frequency in Hz (must be > 0, or timer will stop) |
References startTimer(), and stopTimer().
| void CoalescedTimer::stopTimer | ( | ) |
Stops the timer.
The onTimer callback will no longer be called. If this was the last CoalescedTimer using this interval, the shared juce::Timer is deleted.
Referenced by startTimer(), startTimerHz(), and ~CoalescedTimer().
| std::function<void ()> CoalescedTimer::onTimer |
Callback function called at the specified interval.
Set this to a lambda or function to be executed when the timer fires.