From 56d46e62c178d1931c3879d5f8b2ce59d273e83f Mon Sep 17 00:00:00 2001 From: kennypm Date: Fri, 12 Aug 2022 11:30:12 -0400 Subject: [PATCH] add samplerate callback since pipewire supports dynamic samplerate changes --- include/modules/jack.hpp | 6 ++++-- src/modules/jack.cpp | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/modules/jack.hpp b/include/modules/jack.hpp index e3a09cd6..a3555be6 100644 --- a/include/modules/jack.hpp +++ b/include/modules/jack.hpp @@ -15,7 +15,8 @@ class JACK : public ALabel { ~JACK() = default; auto update() -> void; - int bufSize(unsigned int size); + int bufSize(jack_nframes_t size); + int sampleRate(jack_nframes_t rate); int xrun(); void shutdown(); @@ -35,6 +36,7 @@ class JACK : public ALabel { } // namespace waybar::modules -int bufSizeCallback(unsigned int size, void *obj); +int bufSizeCallback(jack_nframes_t size, void *obj); +int sampleRateCallback(jack_nframes_t rate, void *obj); int xrunCallback(void *obj); void shutdownCallback(void *obj); diff --git a/src/modules/jack.cpp b/src/modules/jack.cpp index 72c50581..7e5ae630 100644 --- a/src/modules/jack.cpp +++ b/src/modules/jack.cpp @@ -40,6 +40,7 @@ std::string JACK::JACKState() { bufsize_ = jack_get_buffer_size(client_); samplerate_ = jack_get_sample_rate(client_); + jack_set_sample_rate_callback(client_, sampleRateCallback, this); jack_set_buffer_size_callback(client_, bufSizeCallback, this); jack_set_xrun_callback(client_, xrunCallback, this); jack_on_shutdown(client_, shutdownCallback, this); @@ -89,9 +90,14 @@ auto JACK::update() -> void { ALabel::update(); } -int JACK::bufSize(unsigned int size) { +int JACK::bufSize(jack_nframes_t size) { bufsize_ = size; - return size; + return 0; +} + +int JACK::sampleRate(jack_nframes_t rate) { + samplerate_ = rate; + return 0; } int JACK::xrun() { @@ -107,10 +113,14 @@ void JACK::shutdown() { } // namespace waybar::modules -int bufSizeCallback(unsigned int size, void *obj) { +int bufSizeCallback(jack_nframes_t size, void *obj) { return static_cast(obj)->bufSize(size); } +int sampleRateCallback(jack_nframes_t rate, void *obj) { + return static_cast(obj)->sampleRate(rate); +} + int xrunCallback(void *obj) { return static_cast(obj)->xrun(); } void shutdownCallback(void *obj) { return static_cast(obj)->shutdown(); }