PulseAudio Qt Bindings

source.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 "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
16namespace PulseAudioQt
17{
18Source::Source(QObject *parent)
19 : Device(parent)
20 , d(new SourcePrivate(this))
21{
22 connect(Context::instance()->server(), &Server::defaultSourceChanged, this, &Source::defaultChanged);
23}
24
25SourcePrivate::SourcePrivate(Source *q)
26 : q(q)
27{
28}
29
30void SourcePrivate::update(const pa_source_info *info)
31{
32 q->Device::d->updateDevice(info);
33}
34
35void 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
40void Source::setMuted(bool muted)
41{
42 Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_source_mute_by_index);
43}
44
45void 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
55void 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
60bool Source::isDefault() const
61{
62 return Context::instance()->server()->defaultSource() == this;
63}
64
65void Source::setDefault(bool enable)
66{
67 if (!isDefault() && enable) {
68 Context::instance()->server()->setDefaultSource(this);
69 }
70}
71
72void Source::switchStreams()
73{
74 const auto sourceOutputs = Context::instance()->sourceOutputs();
75 for (const auto &sourceOutput : sourceOutputs) {
76 sourceOutput->setDeviceIndex(index());
77 }
78}
79
80void Source::setChannelVolumes(const QList<qint64> &volumes)
81{
82 Context::instance()->d->setGenericVolumes(index(), volumes, VolumeObject::d->m_volume, &pa_context_set_source_volume_by_index);
83}
84
85Source::~Source()
86{
87 delete d;
88}
89} // PulseAudioQt
A PulseAudio port.
Definition port.h:19
The primary namespace of PulseAudioQt.
Definition card.cpp:17
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:52:10 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.