Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
CavaSpectrumProvider.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7
8#include <QByteArray>
9#include <QProcess>
10#include <QString>
11#include <QVector>
12
13namespace PhosphorAudio {
14
15class PHOSPHORAUDIO_EXPORT CavaSpectrumProvider : public IAudioSpectrumProvider
16{
17 Q_OBJECT
18
19public:
20 explicit CavaSpectrumProvider(QObject* parent = nullptr);
22
23 static bool isCavaInstalled();
24 static QString detectAudioMethod();
25
32
37 static QString generateConfig(const SpectrumOptions& options);
38
39 bool isAvailable() const override;
40 void start() override;
41 void stop() override;
42 bool isRunning() const override;
43
44 SpectrumOptions options() const override;
45 void setOptions(const SpectrumOptions& options) override;
46
47 QVector<float> spectrum() const override;
48
49private:
50 void onReadyReadStandardOutput();
51 void onProcessStateChanged(QProcess::ProcessState state);
52 void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
53 void onProcessError(QProcess::ProcessError error);
54 void restartAsync();
55
56 static constexpr qsizetype kMaxStdoutBufferSize = 65536;
57
58 QProcess* m_process = nullptr;
59 QByteArray m_stdoutBuffer;
60 SpectrumOptions m_options;
61 QVector<float> m_spectrum;
62 QVector<float> m_smoothedSpectrum;
63 bool m_stopping = false;
64 bool m_pendingRestart = false;
65 // Incremented each time restartAsync() arms a kill-escalation timer, so a
66 // timer left over from an earlier restart cannot cut a later restart's
67 // grace window short (m_process is one reused object across restarts, so
68 // the timer cannot tell generations apart by pointer).
69 int m_restartEpoch = 0;
70};
71
72} // namespace PhosphorAudio
Definition CavaSpectrumProvider.h:16
SpectrumOptions options() const override
The provider's current (normalized) parameter set.
static SpectrumOptions normalizedOptions(SpectrumOptions options)
Clamp/sanitize an option set to the values the provider would actually run with: integer ranges bound...
QVector< float > spectrum() const override
CavaSpectrumProvider(QObject *parent=nullptr)
bool isRunning() const override
bool isAvailable() const override
void setOptions(const SpectrumOptions &options) override
Apply a full parameter set.
static QString generateConfig(const SpectrumOptions &options)
The cava config-file text the provider would run options with (normalized first, so hostile or out-of...
Definition IAudioSpectrumProvider.h:86
Definition AudioDefaults.h:6
Full analysis parameter set for a spectrum provider.
Definition IAudioSpectrumProvider.h:52