PulseAudio Qt Bindings

sink.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2015 Harald Sitter <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "sink.h"
8 #include "sink_p.h"
9 
10 #include "context.h"
11 #include "context_p.h"
12 #include "server.h"
13 
14 #include "device_p.h"
15 #include "volumeobject_p.h"
16 
17 namespace PulseAudioQt
18 {
19 Sink::Sink(QObject *parent)
20  : Device(parent)
21  , d(new SinkPrivate(this))
22 {
23  connect(Context::instance()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged);
24 }
25 
26 SinkPrivate::SinkPrivate(Sink *q)
27  : q(q)
28 {
29 }
30 
31 Sink::~Sink()
32 {
33  delete d;
34 }
35 
36 void SinkPrivate::update(const pa_sink_info *info)
37 {
38  q->Device::d->updateDevice(info);
39 
40  if (m_monitorIndex != info->monitor_source) {
41  m_monitorIndex = info->monitor_source;
42  Q_EMIT q->monitorIndexChanged();
43  }
44 }
45 
46 void Sink::setVolume(qint64 volume)
47 {
48  Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
49 }
50 
51 void Sink::setMuted(bool muted)
52 {
53  Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_sink_mute_by_index);
54 }
55 
56 void Sink::setActivePortIndex(quint32 port_index)
57 {
58  Port *port = qobject_cast<Port *>(ports().at(port_index));
59  if (!port) {
60  qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index;
61  return;
62  }
63  Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index);
64 }
65 
66 void Sink::setChannelVolume(int channel, qint64 volume)
67 {
68  Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
69 }
70 
71 bool Sink::isDefault() const
72 {
73  return Context::instance()->server()->defaultSink() == this;
74 }
75 
76 void Sink::setDefault(bool enable)
77 {
78  if (!isDefault() && enable) {
79  Context::instance()->server()->setDefaultSink(this);
80  }
81 }
82 
83 quint32 Sink::monitorIndex() const
84 {
85  return d->m_monitorIndex;
86 }
87 
88 void Sink::setChannelVolumes(const QVector<qint64> &channelVolumes)
89 {
90  Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_volume_by_index);
91 }
92 
93 } // PulseAudioQt
quint32 monitorIndex() const
Index of the monitor source for this sink.
Definition: sink.cpp:83
void setDefault(bool enable) override
Set whether this is the default device.
Definition: sink.cpp:76
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
The primary namespace of PulseAudioQt.
Definition: card.cpp:16
void setActivePortIndex(quint32 port_index) override
Set the currently active port, by index.
Definition: sink.cpp:56
bool isDefault() const override
Whether this is the default device.
Definition: sink.cpp:71
void setVolume(qint64 volume) override
Set the volume for this object.
Definition: sink.cpp:46
A PulseAudio port.
Definition: port.h:18
void setMuted(bool muted) override
Set whether this object is muted.
Definition: sink.cpp:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:12:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.