PulseAudio Qt Bindings

context.h
1/*
2 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef CONTEXT_H
8#define CONTEXT_H
9
10#include "pulseaudioqt_export.h"
11#include <QObject>
12
13struct pa_context;
14
15/**
16 * The primary namespace of PulseAudioQt.
17 */
18namespace PulseAudioQt
19{
20class Card;
21class Client;
22class Sink;
23class SinkInput;
24class Source;
25class SourceOutput;
26class StreamRestore;
27class Module;
28class Server;
29
30/**
31 * The normal volume (100%, 0 dB). Equivalent to PA_VOLUME_NORM.
32 */
33PULSEAUDIOQT_EXPORT qint64 normalVolume();
34/**
35 * The minimum volume (0%). Equivalent to PA_VOLUME_MUTED.
36 */
37PULSEAUDIOQT_EXPORT qint64 minimumVolume();
38/**
39 * The maximum volume PulseAudio can store. Equivalent to PA_VOLUME_MAX.
40 * \warning For UI elements like volume sliders use maximumUIVolume instead.
41 */
42PULSEAUDIOQT_EXPORT qint64 maximumVolume();
43
44/**
45 * The maximum volume suitable to display in a UI. Equivalent to PA_VOLUME_UI_MAX.
46 */
47PULSEAUDIOQT_EXPORT qint64 maximumUIVolume();
48
49class PULSEAUDIOQT_EXPORT Context : public QObject
50{
51 Q_OBJECT
52 /**
53 * The state of the Context. This is further augmented by the autoConnecting property.
54 *
55 * @since 1.6
56 */
57 Q_PROPERTY(State state READ state NOTIFY stateChanged)
58 /**
59 * Regardless of the state, this property indicates whether the Context is presently trying to
60 * automatically establish a connection. When this is false it may be useful to give the
61 * user a manual way to trigger a connection attempt. AutoConnecting is subject to internal
62 * timeouts that when hit will prevent further auto connecting until the Context managed to
63 * connect.
64 */
65 Q_PROPERTY(bool autoConnecting READ isAutoConnecting NOTIFY autoConnectingChanged)
66
67public:
68 /**
69 * @since 1.6
70 */
71 enum class State {
72 Unconnected = 0,
74 Authorizing,
75 SettingName,
76 Ready,
77 Failed,
78 Terminated,
79 };
80 Q_ENUM(State)
81
82 ~Context() override;
83
84 static Context *instance();
85
86 /**
87 * Set the application id that is reported to PulseAudio.
88 * This needs to be called before accessing the context singleton the first time.
89 * If not set QGuiApplication::desktopFileName() is used.
90 */
91 static void setApplicationId(const QString &applicationId);
92
93 bool isValid();
94
95 /**
96 * Returns a list of all sinks.
97 *
98 * @return list of sinks
99 */
100 QList<Sink *> sinks() const;
101
102 /**
103 * Returns a list of all sink inputs.
104 *
105 * @return list of sink inputs
106 */
107 QList<SinkInput *> sinkInputs() const;
108
109 /**
110 * Returns a list of all sources.
111 *
112 * @return list of sources
113 */
114 QList<Source *> sources() const;
115
116 /**
117 * Returns a list of all source outputs.
118 *
119 * @return list of source outputs
120 */
121 QList<SourceOutput *> sourceOutputs() const;
122
123 /**
124 * Returns a list of all clients.
125 *
126 * @return list of clients
127 */
128 QList<Client *> clients() const;
129
130 /**
131 * Returns a list of all cards.
132 *
133 * @return list of cards
134 */
135 QList<Card *> cards() const;
136
137 /**
138 * Returns a list of all modules.
139 *
140 * @return list of modules
141 */
142 QList<Module *> modules() const;
143
144 /**
145 * Returns a list of all stream restores.
146 *
147 * @return list of stream restores
148 */
149 QList<StreamRestore *> streamRestores() const;
150
151 Server *server() const;
152
153 /**
154 * Returns a pointer to the raw PulseAudio context.
155 */
156 pa_context *context() const;
157
158 void setCardProfile(quint32 index, const QString &profile);
159 void setDefaultSink(const QString &name);
160 void setDefaultSource(const QString &name);
161
162 /**
163 * @returns the state of the context.
164 *
165 * @since 1.6
166 */
167 [[nodiscard]] State state() const;
168
169 /**
170 * @returns whether the Context is currently trying to auto-connect to the daemon
171 *
172 * @since 1.6
173 */
174 [[nodiscard]] bool isAutoConnecting() const;
175
176public Q_SLOTS:
177 /**
178 * When the Context is not auto-connecting this may be used to give the user a manual trigger (e.g. a button)
179 *
180 * @since 1.6
181 */
182 void reconnectDaemon();
183
184Q_SIGNALS:
185 /**
186 * Indicates that sink was added.
187 */
188 void sinkAdded(PulseAudioQt::Sink *sink);
189
190 /**
191 * Indicates that sink was removed.
192 */
193 void sinkRemoved(PulseAudioQt::Sink *sink);
194
195 /**
196 * Indicates that sink input was added.
197 */
198 void sinkInputAdded(PulseAudioQt::SinkInput *sinkInput);
199
200 /**
201 * Indicates that sink input was removed.
202 */
203 void sinkInputRemoved(PulseAudioQt::SinkInput *sinkInput);
204
205 /**
206 * Indicates that source was added.
207 */
208 void sourceAdded(PulseAudioQt::Source *source);
209
210 /**
211 * Indicates that source was removed.
212 */
213 void sourceRemoved(PulseAudioQt::Source *source);
214
215 /**
216 * Indicates that source output was added.
217 */
218 void sourceOutputAdded(PulseAudioQt::SourceOutput *sourceOutput);
219
220 /**
221 * Indicates that source output was removed.
222 */
223 void sourceOutputRemoved(PulseAudioQt::SourceOutput *sourceOutput);
224
225 /**
226 * Indicates that client was added.
227 */
228 void clientAdded(PulseAudioQt::Client *client);
229
230 /**
231 * Indicates that client was removed.
232 */
233 void clientRemoved(PulseAudioQt::Client *client);
234
235 /**
236 * Indicates that card was added.
237 */
238 void cardAdded(PulseAudioQt::Card *card);
239
240 /**
241 * Indicates that card was removed.
242 */
243 void cardRemoved(PulseAudioQt::Card *card);
244
245 /**
246 * Indicates that module was added.
247 */
248 void moduleAdded(PulseAudioQt::Module *module);
249
250 /**
251 * Indicates that module was removed.
252 */
253 void moduleRemoved(PulseAudioQt::Module *module);
254
255 /**
256 * Indicates that stream restore was added.
257 */
258 void streamRestoreAdded(PulseAudioQt::StreamRestore *streamRestore);
259
260 /**
261 * Indicates that streamRestore was removed.
262 */
263 void streamRestoreRemoved(PulseAudioQt::StreamRestore *streamRestore);
264
265 /**
266 * Context state changed.
267 *
268 * @since 1.6
269 */
270 void stateChanged();
271
272 /**
273 * Indicates that autoConnecting changed.
274 *
275 * @since 1.6
276 */
277 void autoConnectingChanged();
278
279private:
280 explicit Context(QObject *parent = nullptr);
281
282 std::unique_ptr<class ContextPrivate> d;
283
284 friend class Sink;
285 friend class SinkInput;
286 friend class Source;
287 friend class SourceOutput;
288 friend class Stream;
289 friend class StreamRestorePrivate;
290 friend class Server;
291 friend class SinkModel;
292 friend class SinkInputModel;
293 friend class SourceModel;
294 friend class SourceOutputModel;
295 friend class StreamRestoreModel;
296 friend class CardModel;
297 friend class ModuleModel;
298};
299
300} // PulseAudioQt
301
302#endif // CONTEXT_H
A SinkInput stream.
Definition sinkinput.h:20
A PulseAudio sink.
Definition sink.h:20
A SourceOutput Stream.
A PulseAudio source.
Definition source.h:20
bool isValid(QStringView ifopt)
The primary namespace of PulseAudioQt.
Definition card.cpp:17
qint64 normalVolume()
The normal volume (100%, 0 dB).
Definition context.cpp:35
qint64 maximumUIVolume()
The maximum volume suitable to display in a UI.
Definition context.cpp:50
qint64 minimumVolume()
The minimum volume (0%).
Definition context.cpp:40
qint64 maximumVolume()
The maximum volume PulseAudio can store.
Definition context.cpp:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.