Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::Debouncer Class Reference

Generic debouncer that delays execution of a callback until a specified time period has elapsed without the debounce being called again. More...

#include <src/utils/debouncer.h>

Inheritance diagram for zrythm::utils::Debouncer:
Collaboration diagram for zrythm::utils::Debouncer:

Public Types

using Callback = std::function<void ()>

Public Member Functions

 Debouncer (std::chrono::milliseconds delay, Callback callback, QObject *parent=nullptr)
 Construct a debouncer.
void operator() ()
 Call this to schedule the callback execution.
void debounce ()
 Alternative method name for scheduling callback execution.
void set_delay (std::chrono::milliseconds delay)
 Set the delay for future debounce operations.
std::chrono::milliseconds get_delay () const
 Get the current delay.
bool is_pending () const
 Check if there's a pending callback execution.
void cancel ()
 Cancel any pending callback execution.

Detailed Description

Generic debouncer that delays execution of a callback until a specified time period has elapsed without the debounce being called again.

This is useful for scenarios where you want to batch multiple rapid events into a single operation, such as:

  • Search boxes that should only search after user stops typing
  • Cache updates that should only run after multiple rapid changes
  • UI updates that should be debounced to avoid excessive redraws

Definition at line 26 of file debouncer.h.

Member Typedef Documentation

◆ Callback

using zrythm::utils::Debouncer::Callback = std::function<void ()>

Definition at line 31 of file debouncer.h.

Constructor & Destructor Documentation

◆ Debouncer()

zrythm::utils::Debouncer::Debouncer ( std::chrono::milliseconds delay,
Callback callback,
QObject * parent = nullptr )

Construct a debouncer.

Parameters
delayThe delay to wait before executing the callback
callbackThe function to call when debounce period expires
parentQObject parent

Member Function Documentation

◆ operator()()

void zrythm::utils::Debouncer::operator() ( )

Call this to schedule the callback execution.

If called multiple times before the delay expires, the timer will restart and the callback will only execute once after the final call.

◆ set_delay()

void zrythm::utils::Debouncer::set_delay ( std::chrono::milliseconds delay)

Set the delay for future debounce operations.

Parameters
delayNew delay duration

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