add samplerate callback since pipewire supports dynamic samplerate changes

This commit is contained in:
kennypm 2022-08-12 11:30:12 -04:00
parent 89a57f6722
commit 56d46e62c1
2 changed files with 17 additions and 5 deletions

View File

@ -15,7 +15,8 @@ class JACK : public ALabel {
~JACK() = default; ~JACK() = default;
auto update() -> void; auto update() -> void;
int bufSize(unsigned int size); int bufSize(jack_nframes_t size);
int sampleRate(jack_nframes_t rate);
int xrun(); int xrun();
void shutdown(); void shutdown();
@ -35,6 +36,7 @@ class JACK : public ALabel {
} // namespace waybar::modules } // 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); int xrunCallback(void *obj);
void shutdownCallback(void *obj); void shutdownCallback(void *obj);

View File

@ -40,6 +40,7 @@ std::string JACK::JACKState() {
bufsize_ = jack_get_buffer_size(client_); bufsize_ = jack_get_buffer_size(client_);
samplerate_ = jack_get_sample_rate(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_buffer_size_callback(client_, bufSizeCallback, this);
jack_set_xrun_callback(client_, xrunCallback, this); jack_set_xrun_callback(client_, xrunCallback, this);
jack_on_shutdown(client_, shutdownCallback, this); jack_on_shutdown(client_, shutdownCallback, this);
@ -89,9 +90,14 @@ auto JACK::update() -> void {
ALabel::update(); ALabel::update();
} }
int JACK::bufSize(unsigned int size) { int JACK::bufSize(jack_nframes_t size) {
bufsize_ = size; bufsize_ = size;
return size; return 0;
}
int JACK::sampleRate(jack_nframes_t rate) {
samplerate_ = rate;
return 0;
} }
int JACK::xrun() { int JACK::xrun() {
@ -107,10 +113,14 @@ void JACK::shutdown() {
} // namespace waybar::modules } // namespace waybar::modules
int bufSizeCallback(unsigned int size, void *obj) { int bufSizeCallback(jack_nframes_t size, void *obj) {
return static_cast<waybar::modules::JACK *>(obj)->bufSize(size); return static_cast<waybar::modules::JACK *>(obj)->bufSize(size);
} }
int sampleRateCallback(jack_nframes_t rate, void *obj) {
return static_cast<waybar::modules::JACK *>(obj)->sampleRate(rate);
}
int xrunCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->xrun(); } int xrunCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->xrun(); }
void shutdownCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->shutdown(); } void shutdownCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->shutdown(); }