Files
Waybar/include/modules/cava.hpp
T

60 lines
1.6 KiB
C++
Raw Normal View History

2023-04-15 02:36:15 +03:00
#pragma once
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
2023-10-31 20:27:00 +03:00
namespace cava {
2023-04-15 02:36:15 +03:00
extern "C" {
2025-04-13 22:11:41 -07:00
// Need sdl_glsl output feature to be enabled on libcava
#ifndef SDL_GLSL
#define SDL_GLSL
#endif
2023-04-15 02:36:15 +03:00
#include <cava/common.h>
2025-04-13 22:11:41 -07:00
#ifdef SDL_GLSL
#undef SDL_GLSL
#endif
2023-04-15 02:36:15 +03:00
}
2023-10-31 23:31:58 +03:00
} // namespace cava
2023-04-15 02:36:15 +03:00
namespace waybar::modules {
using namespace std::literals::chrono_literals;
2023-04-17 09:01:14 +02:00
class Cava final : public ALabel {
public:
2023-04-15 02:36:15 +03:00
Cava(const std::string&, const Json::Value&);
virtual ~Cava();
auto update() -> void override;
auto doAction(const std::string& name) -> void override;
2023-04-17 09:01:14 +02:00
private:
2023-04-15 02:36:15 +03:00
util::SleeperThread thread_;
util::SleeperThread thread_fetch_input_;
2025-01-25 09:31:32 +01:00
struct cava::error_s error_{}; // cava errors
struct cava::config_params prm_{}; // cava parameters
struct cava::audio_raw audio_raw_{}; // cava handled raw audio data(is based on audio_data)
struct cava::audio_data audio_data_{}; // cava audio data
struct cava::cava_plan* plan_; //{new cava_plan{}};
2023-04-15 02:36:15 +03:00
// Cava API to read audio source
2023-10-31 20:27:00 +03:00
cava::ptr input_source_;
2023-04-15 02:36:15 +03:00
// Delay to handle audio source
std::chrono::milliseconds frame_time_milsec_{1s};
// Text to display
std::string text_{""};
int rePaint_{1};
std::chrono::seconds fetch_input_delay_{4};
std::chrono::seconds suspend_silence_delay_{0};
bool silence_{false};
bool hide_on_silence_{false};
2024-08-14 11:34:28 +03:00
std::string format_silent_{""};
2023-04-15 02:36:15 +03:00
int sleep_counter_{0};
// Cava method
void pause_resume();
// ModuleActionMap
2025-01-25 09:31:32 +01:00
static inline std::map<const std::string, void (waybar::modules::Cava::* const)()> actionMap_{
2023-04-17 09:01:14 +02:00
{"mode", &waybar::modules::Cava::pause_resume}};
2023-04-15 02:36:15 +03:00
};
2023-04-17 09:01:14 +02:00
} // namespace waybar::modules