File indexing completed on 2023-11-26 11:26:50
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 "sink.h" 0008 #include "sink_p.h" 0009 0010 #include "context.h" 0011 #include "context_p.h" 0012 #include "server.h" 0013 0014 #include "device_p.h" 0015 #include "volumeobject_p.h" 0016 0017 namespace PulseAudioQt 0018 { 0019 Sink::Sink(QObject *parent) 0020 : Device(parent) 0021 , d(new SinkPrivate(this)) 0022 { 0023 connect(Context::instance()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged); 0024 } 0025 0026 SinkPrivate::SinkPrivate(Sink *q) 0027 : q(q) 0028 { 0029 } 0030 0031 Sink::~Sink() 0032 { 0033 delete d; 0034 } 0035 0036 void SinkPrivate::update(const pa_sink_info *info) 0037 { 0038 q->Device::d->updateDevice(info); 0039 0040 if (m_monitorIndex != info->monitor_source) { 0041 m_monitorIndex = info->monitor_source; 0042 Q_EMIT q->monitorIndexChanged(); 0043 } 0044 } 0045 0046 void Sink::setVolume(qint64 volume) 0047 { 0048 Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index); 0049 } 0050 0051 void Sink::setMuted(bool muted) 0052 { 0053 Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_sink_mute_by_index); 0054 } 0055 0056 void Sink::setActivePortIndex(quint32 port_index) 0057 { 0058 Port *port = qobject_cast<Port *>(ports().at(port_index)); 0059 if (!port) { 0060 qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index; 0061 return; 0062 } 0063 Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index); 0064 } 0065 0066 void Sink::setChannelVolume(int channel, qint64 volume) 0067 { 0068 Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index); 0069 } 0070 0071 bool Sink::isDefault() const 0072 { 0073 return Context::instance()->server()->defaultSink() == this; 0074 } 0075 0076 void Sink::setDefault(bool enable) 0077 { 0078 if (!isDefault() && enable) { 0079 Context::instance()->server()->setDefaultSink(this); 0080 } 0081 } 0082 0083 quint32 Sink::monitorIndex() const 0084 { 0085 return d->m_monitorIndex; 0086 } 0087 0088 void Sink::setChannelVolumes(const QVector<qint64> &channelVolumes) 0089 { 0090 Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_volume_by_index); 0091 } 0092 0093 } // PulseAudioQt