PulseAudio Qt Bindings

source.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 "source.h"
8 #include "source_p.h"
9 
10 #include "context.h"
11 #include "context_p.h"
12 #include "device_p.h"
13 #include "server.h"
14 #include "volumeobject_p.h"
15 
16 namespace PulseAudioQt
17 {
18 Source::Source(QObject *parent)
19  : Device(parent)
20  , d(new SourcePrivate(this))
21 {
22  connect(Context::instance()->server(), &Server::defaultSourceChanged, this, &Source::defaultChanged);
23 }
24 
25 SourcePrivate::SourcePrivate(Source *q)
26  : q(q)
27 {
28 }
29 
30 void SourcePrivate::update(const pa_source_info *info)
31 {
32  q->Device::d->updateDevice(info);
33 }
34 
35 void Source::setVolume(qint64 volume)
36 {
37  Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index);
38 }
39 
40 void Source::setMuted(bool muted)
41 {
42  Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_source_mute_by_index);
43 }
44 
45 void Source::setActivePortIndex(quint32 port_index)
46 {
47  Port *port = qobject_cast<Port *>(ports().at(port_index));
48  if (!port) {
49  qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index;
50  return;
51  }
52  Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_source_port_by_index);
53 }
54 
55 void Source::setChannelVolume(int channel, qint64 volume)
56 {
57  Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index);
58 }
59 
60 bool Source::isDefault() const
61 {
62  return Context::instance()->server()->defaultSource() == this;
63 }
64 
65 void Source::setDefault(bool enable)
66 {
67  if (!isDefault() && enable) {
68  Context::instance()->server()->setDefaultSource(this);
69  }
70 }
71 
72 void Source::setChannelVolumes(const QVector<qint64> &volumes)
73 {
74  Context::instance()->d->setGenericVolumes(index(), volumes, VolumeObject::d->m_volume, &pa_context_set_source_volume_by_index);
75 }
76 
77 Source::~Source()
78 {
79  delete d;
80 }
81 } // PulseAudioQt
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: source.cpp:45
void setDefault(bool enable) override
Set whether this is the default device.
Definition: source.cpp:65
A PulseAudio port.
Definition: port.h:18
void setMuted(bool muted) override
Set whether this object is muted.
Definition: source.cpp:40
void setVolume(qint64 volume) override
Set the volume for this object.
Definition: source.cpp:35
bool isDefault() const override
Whether this is the default device.
Definition: source.cpp:60
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.