Commit 88ba6bae authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Implement setting per-channel volumes

Backport parts of plasma/plasma-pa@12c07e35
parent 59107018
Pipeline #95888 passed with stage
in 33 seconds
......@@ -807,6 +807,28 @@ void ContextPrivate::setGenericDeviceForStream(
}
}
void ContextPrivate::setGenericVolumes(
quint32 index,
QVector<qint64> channelVolumes,
pa_cvolume cVolume,
const std::function<pa_operation *(pa_context *, uint32_t, const pa_cvolume *, pa_context_success_cb_t, void *)> &pa_set_volume)
{
if (!m_context) {
return;
}
Q_ASSERT(channelVolumes.count() == cVolume.channels);
pa_cvolume newCVolume = cVolume;
for (int i = 0; i < channelVolumes.count(); ++i) {
newCVolume.values[i] = qBound<qint64>(0, channelVolumes.at(i), PA_VOLUME_MAX);
}
if (!PAOperation(pa_set_volume(m_context, index, &newCVolume, nullptr, nullptr))) {
qCWarning(PULSEAUDIOQT) << "pa_set_volume failed";
return;
}
}
void Context::setApplicationId(const QString &applicationId)
{
ContextPrivate::s_applicationId = applicationId;
......
......@@ -70,6 +70,11 @@ public:
void setGenericDeviceForStream(quint32 streamIndex,
quint32 deviceIndex,
const std::function<pa_operation *(pa_context *, uint32_t, uint32_t, pa_context_success_cb_t, void *)> &);
void setGenericVolumes(quint32 index,
QVector<qint64> channelVolumes,
pa_cvolume cVolume,
const std::function<pa_operation *(pa_context *, uint32_t, const pa_cvolume *, pa_context_success_cb_t, void *)> &);
void reset();
void connectToDaemon();
......
......@@ -85,4 +85,9 @@ quint32 Sink::monitorIndex() const
return d->m_monitorIndex;
}
void Sink::setChannelVolumes(const QVector<qint64> &channelVolumes)
{
Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_volume_by_index);
}
} // PulseAudioQt
......@@ -35,6 +35,8 @@ public:
void setDefault(bool enable) override;
void setChannelVolumes(const QVector<qint64> &channelVolumes) override;
/**
* Index of the monitor source for this sink.
*/
......
......@@ -58,4 +58,9 @@ void SinkInput::setChannelVolume(int channel, qint64 volume)
Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_input_volume);
}
void SinkInput::setChannelVolumes(const QVector<qint64> &channelVolumes)
{
Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_input_volume);
}
} // PulseAudioQt
......@@ -27,6 +27,7 @@ public:
void setMuted(bool muted) override;
void setChannelVolume(int channel, qint64 volume) override;
void setDeviceIndex(quint32 deviceIndex) override;
void setChannelVolumes(const QVector<qint64> &channelVolumes) override;
private:
SinkInput(QObject *parent);
......
......@@ -69,6 +69,11 @@ void Source::setDefault(bool enable)
}
}
void Source::setChannelVolumes(const QVector<qint64> &volumes)
{
Context::instance()->d->setGenericVolumes(index(), volumes, VolumeObject::d->m_volume, &pa_context_set_source_volume_by_index);
}
Source::~Source()
{
delete d;
......
......@@ -27,6 +27,7 @@ public:
void setMuted(bool muted) override;
void setActivePortIndex(quint32 port_index) override;
void setChannelVolume(int channel, qint64 volume) override;
void setChannelVolumes(const QVector<qint64> &volumes) override;
bool isDefault() const override;
void setDefault(bool enable) override;
......
......@@ -57,4 +57,9 @@ void SourceOutput::setChannelVolume(int channel, qint64 volume)
Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_source_output_volume);
}
void SourceOutput::setChannelVolumes(const QVector<qint64> &channelVolumes)
{
Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_source_output_volume);
}
} // PulseAudioQt
......@@ -27,6 +27,7 @@ public:
void setMuted(bool muted) override;
void setChannelVolume(int channel, qint64 volume) override;
void setDeviceIndex(quint32 deviceIndex) override;
void setChannelVolumes(const QVector<qint64> &channelVolumes) override;
private:
explicit SourceOutput(QObject *parent);
......
......@@ -57,9 +57,9 @@ QStringList VolumeObject::rawChannels() const
return d->m_rawChannels;
}
QVector<qreal> VolumeObject::channelVolumes() const
QVector<qint64> VolumeObject::channelVolumes() const
{
QVector<qreal> ret;
QVector<qint64> ret;
ret.reserve(d->m_volume.channels);
for (int i = 0; i < d->m_volume.channels; ++i) {
ret << d->m_volume.values[i];
......
......@@ -21,7 +21,7 @@ class PULSEAUDIOQT_EXPORT VolumeObject : public IndexedPulseObject
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(bool volumeWritable READ isVolumeWritable NOTIFY isVolumeWritableChanged)
Q_PROPERTY(QVector<QString> channels READ channels NOTIFY channelsChanged)
Q_PROPERTY(QVector<qreal> channelVolumes READ channelVolumes NOTIFY channelVolumesChanged)
Q_PROPERTY(QVector<qint64> channelVolumes READ channelVolumes WRITE setChannelVolumes NOTIFY channelVolumesChanged)
Q_PROPERTY(QStringList rawChannels READ rawChannels NOTIFY rawChannelsChanged)
public:
......@@ -53,7 +53,8 @@ public:
QVector<QString> channels() const;
QStringList rawChannels() const;
QVector<qreal> channelVolumes() const;
QVector<qint64> channelVolumes() const;
virtual void setChannelVolumes(const QVector<qint64> &channelVolumes) = 0;
Q_INVOKABLE virtual void setChannelVolume(int channel, qint64 volume) = 0;
Q_SIGNALS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment