File indexing completed on 2024-12-01 13:02:23
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 #include "source.h" 0008 #include "source_p.h" 0009 0010 #include "context.h" 0011 #include "context_p.h" 0012 #include "device_p.h" 0013 #include "server.h" 0014 #include "volumeobject_p.h" 0015 0016 namespace PulseAudioQt 0017 { 0018 Source::Source(QObject *parent) 0019 : Device(parent) 0020 , d(new SourcePrivate(this)) 0021 { 0022 connect(Context::instance()->server(), &Server::defaultSourceChanged, this, &Source::defaultChanged); 0023 } 0024 0025 SourcePrivate::SourcePrivate(Source *q) 0026 : q(q) 0027 { 0028 } 0029 0030 void SourcePrivate::update(const pa_source_info *info) 0031 { 0032 q->Device::d->updateDevice(info); 0033 } 0034 0035 void Source::setVolume(qint64 volume) 0036 { 0037 Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index); 0038 } 0039 0040 void Source::setMuted(bool muted) 0041 { 0042 Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_source_mute_by_index); 0043 } 0044 0045 void Source::setActivePortIndex(quint32 port_index) 0046 { 0047 Port *port = qobject_cast<Port *>(ports().at(port_index)); 0048 if (!port) { 0049 qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index; 0050 return; 0051 } 0052 Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_source_port_by_index); 0053 } 0054 0055 void Source::setChannelVolume(int channel, qint64 volume) 0056 { 0057 Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_source_volume_by_index); 0058 } 0059 0060 bool Source::isDefault() const 0061 { 0062 return Context::instance()->server()->defaultSource() == this; 0063 } 0064 0065 void Source::setDefault(bool enable) 0066 { 0067 if (!isDefault() && enable) { 0068 Context::instance()->server()->setDefaultSource(this); 0069 } 0070 } 0071 0072 void Source::switchStreams() 0073 { 0074 const auto sourceOutputs = Context::instance()->sourceOutputs(); 0075 for (const auto &sourceOutput : sourceOutputs) { 0076 sourceOutput->setDeviceIndex(index()); 0077 } 0078 } 0079 0080 void Source::setChannelVolumes(const QVector<qint64> &volumes) 0081 { 0082 Context::instance()->d->setGenericVolumes(index(), volumes, VolumeObject::d->m_volume, &pa_context_set_source_volume_by_index); 0083 } 0084 0085 Source::~Source() 0086 { 0087 delete d; 0088 } 0089 } // PulseAudioQt