Volume slider works
This commit is contained in:
parent
6d74ef422d
commit
96e1a5cbdb
3 changed files with 64 additions and 3 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <QString>
|
||||
#include <QElapsedTimer>
|
||||
#include <QThread>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
#include <pipewire/keys.h>
|
||||
#include <pipewire/properties.h>
|
||||
#include <pipewire/stream.h>
|
||||
#include <pipewire/node.h>
|
||||
#include <spa/param/props.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
#include <spa/param/audio/raw.h>
|
||||
|
|
@ -444,6 +446,40 @@ float PipeWireController::meterPeak() const
|
|||
return peak;
|
||||
}
|
||||
|
||||
bool PipeWireController::setNodeVolume(uint32_t nodeId, float volume, bool mute)
|
||||
{
|
||||
if (!m_threadLoop || !m_core || !m_registry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nodeId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
volume = std::clamp(volume, 0.0f, 1.0f);
|
||||
|
||||
lock();
|
||||
auto *node = static_cast<struct pw_node*>(
|
||||
pw_registry_bind(m_registry, nodeId, PW_TYPE_INTERFACE_Node, PW_VERSION_NODE, 0));
|
||||
if (!node) {
|
||||
unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t buffer[128];
|
||||
spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
auto *param = reinterpret_cast<const struct spa_pod*>(spa_pod_builder_add_object(
|
||||
&builder,
|
||||
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
|
||||
SPA_PROP_volume, SPA_POD_Float(volume),
|
||||
SPA_PROP_mute, SPA_POD_Bool(mute)));
|
||||
|
||||
pw_node_set_param(node, SPA_PARAM_Props, 0, param);
|
||||
pw_proxy_destroy(reinterpret_cast<struct pw_proxy*>(node));
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
float PipeWireController::nodeMeterPeak(uint32_t nodeId) const
|
||||
{
|
||||
QMutexLocker lock(&m_meterMutex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue