File indexing completed on 2024-09-15 04:55:10
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 0009 #include "context.h" 0010 #include "server.h" 0011 #include "sourceoutput.h" 0012 0013 namespace QPulseAudio 0014 { 0015 Source::Source(QObject *parent) 0016 : Device(parent) 0017 { 0018 connect(context()->server(), &Server::defaultSourceChanged, this, &Source::defaultChanged); 0019 } 0020 0021 void Source::update(const pa_source_info *info) 0022 { 0023 updateDevice(info); 0024 } 0025 0026 void Source::setVolume(qint64 volume) 0027 { 0028 context()->setGenericVolume(index(), -1, volume, cvolume(), &pa_context_set_source_volume_by_index); 0029 } 0030 0031 void Source::setMuted(bool muted) 0032 { 0033 context()->setGenericMute(index(), muted, &pa_context_set_source_mute_by_index); 0034 } 0035 0036 void Source::setActivePortIndex(quint32 port_index) 0037 { 0038 Port *port = qobject_cast<Port *>(ports().at(port_index)); 0039 if (!port) { 0040 qCWarning(PLASMAPA) << "invalid port set request" << port_index; 0041 return; 0042 } 0043 context()->setGenericPort(index(), port->name(), &pa_context_set_source_port_by_index); 0044 } 0045 0046 void Source::setChannelVolume(int channel, qint64 volume) 0047 { 0048 context()->setGenericVolume(index(), channel, volume, cvolume(), &pa_context_set_source_volume_by_index); 0049 } 0050 0051 void Source::setChannelVolumes(const QList<qint64> &volumes) 0052 { 0053 context()->setGenericVolumes(index(), volumes, cvolume(), &pa_context_set_source_volume_by_index); 0054 } 0055 0056 bool Source::isDefault() const 0057 { 0058 return context()->server()->defaultSource() == this; 0059 } 0060 0061 void Source::setDefault(bool enable) 0062 { 0063 if (!isDefault() && enable) { 0064 context()->server()->setDefaultSource(this); 0065 } 0066 } 0067 0068 void Source::switchStreams() 0069 { 0070 auto data = context()->sourceOutputs().data(); 0071 std::for_each(data.begin(), data.end(), [this](SourceOutput *paObj) { 0072 paObj->setDeviceIndex(m_index); 0073 }); 0074 } 0075 0076 } // QPulseAudio