PulseAudio Qt Bindings

sink.cpp
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#include "sink.h"
8#include "sink_p.h"
9
10#include "context.h"
11#include "context_p.h"
12#include "server.h"
13#include "sinkinput.h"
14
15#include "device_p.h"
16#include "volumeobject_p.h"
17
18namespace PulseAudioQt
19{
20Sink::Sink(QObject *parent)
21 : Device(parent)
22 , d(new SinkPrivate(this))
23{
24 connect(Context::instance()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged);
25}
26
27SinkPrivate::SinkPrivate(Sink *q)
28 : q(q)
29{
30}
31
32Sink::~Sink()
33{
34 delete d;
35}
36
37void SinkPrivate::update(const pa_sink_info *info)
38{
39 q->Device::d->updateDevice(info);
40
41 if (m_monitorIndex != info->monitor_source) {
42 m_monitorIndex = info->monitor_source;
43 Q_EMIT q->monitorIndexChanged();
44 }
45}
46
47void Sink::setVolume(qint64 volume)
48{
49 Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
50}
51
52void Sink::setMuted(bool muted)
53{
54 Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_sink_mute_by_index);
55}
56
57void Sink::setActivePortIndex(quint32 port_index)
58{
59 Port *port = qobject_cast<Port *>(ports().at(port_index));
60 if (!port) {
61 qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index;
62 return;
63 }
64 Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index);
65}
66
67void Sink::setChannelVolume(int channel, qint64 volume)
68{
69 Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
70}
71
72bool Sink::isDefault() const
73{
74 return Context::instance()->server()->defaultSink() == this;
75}
76
77void Sink::setDefault(bool enable)
78{
79 if (!isDefault() && enable) {
80 Context::instance()->server()->setDefaultSink(this);
81 }
82}
83
84quint32 Sink::monitorIndex() const
85{
86 return d->m_monitorIndex;
87}
88
89void Sink::setChannelVolumes(const QVector<qint64> &channelVolumes)
90{
91 Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_volume_by_index);
92}
93
94void Sink::switchStreams()
95{
96 const auto sinkInputs = Context::instance()->sinkInputs();
97 for (const auto &sinkInput : sinkInputs) {
98 sinkInput->setDeviceIndex(index());
99 }
100}
101
102} // PulseAudioQt
A PulseAudio port.
Definition port.h:19
The primary namespace of PulseAudioQt.
Definition card.cpp:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:46:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.