File indexing completed on 2024-05-26 12:32:36

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef CONTEXT_H
0008 #define CONTEXT_H
0009 
0010 #include "pulseaudioqt_export.h"
0011 #include <QObject>
0012 
0013 struct pa_context;
0014 
0015 /**
0016  * The primary namespace of PulseAudioQt.
0017  */
0018 namespace PulseAudioQt
0019 {
0020 class Card;
0021 class Client;
0022 class Sink;
0023 class SinkInput;
0024 class Source;
0025 class SourceOutput;
0026 class StreamRestore;
0027 class Module;
0028 class Server;
0029 
0030 /**
0031  * The normal volume (100%, 0 dB). Equivalent to PA_VOLUME_NORM.
0032  */
0033 PULSEAUDIOQT_EXPORT qint64 normalVolume();
0034 /**
0035  * The minimum volume (0%). Equivalent to PA_VOLUME_MUTED.
0036  */
0037 PULSEAUDIOQT_EXPORT qint64 minimumVolume();
0038 /**
0039  * The maximum volume PulseAudio can store. Equivalent to PA_VOLUME_MAX.
0040  * \warning For UI elements like volume sliders use maximumUIVolume instead.
0041  */
0042 PULSEAUDIOQT_EXPORT qint64 maximumVolume();
0043 
0044 /**
0045  * The maximum volume suitable to display in a UI. Equivalent to PA_VOLUME_UI_MAX.
0046  */
0047 PULSEAUDIOQT_EXPORT qint64 maximumUIVolume();
0048 
0049 class PULSEAUDIOQT_EXPORT Context : public QObject
0050 {
0051     Q_OBJECT
0052 
0053 public:
0054     ~Context();
0055 
0056     static Context *instance();
0057 
0058     /**
0059      * Set the application id that is reported to PulseAudio.
0060      * This needs to be called before accessing the context singleton the first time.
0061      * If not set QGuiApplication::desktopFileName() is used.
0062      */
0063     static void setApplicationId(const QString &applicationId);
0064 
0065     bool isValid();
0066 
0067     /**
0068      * Returns a list of all sinks.
0069      *
0070      * @return list of sinks
0071      */
0072     QVector<Sink *> sinks() const;
0073 
0074     /**
0075      * Returns a list of all sink inputs.
0076      *
0077      * @return list of sink inputs
0078      */
0079     QVector<SinkInput *> sinkInputs() const;
0080 
0081     /**
0082      * Returns a list of all sources.
0083      *
0084      * @return list of sources
0085      */
0086     QVector<Source *> sources() const;
0087 
0088     /**
0089      * Returns a list of all source outputs.
0090      *
0091      * @return list of source outputs
0092      */
0093     QVector<SourceOutput *> sourceOutputs() const;
0094 
0095     /**
0096      * Returns a list of all clients.
0097      *
0098      * @return list of clients
0099      */
0100     QVector<Client *> clients() const;
0101 
0102     /**
0103      * Returns a list of all cards.
0104      *
0105      * @return list of cards
0106      */
0107     QVector<Card *> cards() const;
0108 
0109     /**
0110      * Returns a list of all modules.
0111      *
0112      * @return list of modules
0113      */
0114     QVector<Module *> modules() const;
0115 
0116     /**
0117      * Returns a list of all stream restores.
0118      *
0119      * @return list of stream restores
0120      */
0121     QVector<StreamRestore *> streamRestores() const;
0122 
0123     Server *server() const;
0124 
0125     /**
0126      *  Returns a pointer to the raw PulseAudio context.
0127      */
0128     pa_context *context() const;
0129 
0130     void setCardProfile(quint32 index, const QString &profile);
0131     void setDefaultSink(const QString &name);
0132     void setDefaultSource(const QString &name);
0133 
0134 Q_SIGNALS:
0135     /**
0136      * Indicates that sink was added.
0137      */
0138     void sinkAdded(PulseAudioQt::Sink *sink);
0139 
0140     /**
0141      * Indicates that sink was removed.
0142      */
0143     void sinkRemoved(PulseAudioQt::Sink *sink);
0144 
0145     /**
0146      * Indicates that sink input was added.
0147      */
0148     void sinkInputAdded(PulseAudioQt::SinkInput *sinkInput);
0149 
0150     /**
0151      * Indicates that sink input was removed.
0152      */
0153     void sinkInputRemoved(PulseAudioQt::SinkInput *sinkInput);
0154 
0155     /**
0156      * Indicates that source was added.
0157      */
0158     void sourceAdded(PulseAudioQt::Source *source);
0159 
0160     /**
0161      * Indicates that source was removed.
0162      */
0163     void sourceRemoved(PulseAudioQt::Source *source);
0164 
0165     /**
0166      * Indicates that source output was added.
0167      */
0168     void sourceOutputAdded(PulseAudioQt::SourceOutput *sourceOutput);
0169 
0170     /**
0171      * Indicates that source output was removed.
0172      */
0173     void sourceOutputRemoved(PulseAudioQt::SourceOutput *sourceOutput);
0174 
0175     /**
0176      * Indicates that client was added.
0177      */
0178     void clientAdded(PulseAudioQt::Client *client);
0179 
0180     /**
0181      * Indicates that client was removed.
0182      */
0183     void clientRemoved(PulseAudioQt::Client *client);
0184 
0185     /**
0186      * Indicates that card was added.
0187      */
0188     void cardAdded(PulseAudioQt::Card *card);
0189 
0190     /**
0191      * Indicates that card was removed.
0192      */
0193     void cardRemoved(PulseAudioQt::Card *card);
0194 
0195     /**
0196      * Indicates that module was added.
0197      */
0198     void moduleAdded(PulseAudioQt::Module *module);
0199 
0200     /**
0201      * Indicates that module was removed.
0202      */
0203     void moduleRemoved(PulseAudioQt::Module *module);
0204 
0205     /**
0206      * Indicates that stream restore was added.
0207      */
0208     void streamRestoreAdded(PulseAudioQt::StreamRestore *streamRestore);
0209 
0210     /**
0211      * Indicates that streamRestore was removed.
0212      */
0213     void streamRestoreRemoved(PulseAudioQt::StreamRestore *streamRestore);
0214 
0215 private:
0216     explicit Context(QObject *parent = nullptr);
0217 
0218     class ContextPrivate *const d;
0219 
0220     friend class Sink;
0221     friend class SinkInput;
0222     friend class Source;
0223     friend class SourceOutput;
0224     friend class Stream;
0225     friend class StreamRestorePrivate;
0226     friend class Server;
0227     friend class SinkModel;
0228     friend class SinkInputModel;
0229     friend class SourceModel;
0230     friend class SourceOutputModel;
0231     friend class StreamRestoreModel;
0232     friend class CardModel;
0233     friend class ModuleModel;
0234 };
0235 
0236 } // PulseAudioQt
0237 
0238 #endif // CONTEXT_H