Undo volume
This commit is contained in:
parent
debc7f1853
commit
adab645c86
7 changed files with 237 additions and 41 deletions
|
|
@ -18,6 +18,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSlider>
|
||||
#include "gui/ClickSlider.h"
|
||||
#include <QSizePolicy>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
|
@ -26,6 +27,7 @@
|
|||
#include <QtNodes/StyleCollection>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -137,7 +139,7 @@ QWidget *PipeWireGraphModel::nodeWidget(QtNodes::NodeId nodeId) const
|
|||
muteButton->setFixedSize(20, 20);
|
||||
muteButton->setToolTip(QString("Mute"));
|
||||
|
||||
auto *slider = new QSlider(Qt::Horizontal, widget);
|
||||
auto *slider = new ClickSlider(Qt::Horizontal, widget);
|
||||
slider->setRange(0, 100);
|
||||
slider->setValue(100);
|
||||
slider->setFixedHeight(18);
|
||||
|
|
@ -155,8 +157,10 @@ QWidget *PipeWireGraphModel::nodeWidget(QtNodes::NodeId nodeId) const
|
|||
return;
|
||||
}
|
||||
const float volume = static_cast<float>(slider->value()) / 100.0f;
|
||||
m_controller->setNodeVolume(pipewireId, volume, muteButton->isChecked());
|
||||
m_nodeVolumeState.insert(pipewireId, NodeVolumeState{volume, muteButton->isChecked()});
|
||||
const NodeVolumeState state{volume, muteButton->isChecked()};
|
||||
m_controller->setNodeVolume(pipewireId, volume, state.mute);
|
||||
auto *self = const_cast<PipeWireGraphModel*>(this);
|
||||
self->setNodeVolumeState(pipewireId, state, true);
|
||||
};
|
||||
|
||||
QObject::connect(slider, &QSlider::valueChanged, widget, [applyVolume](int) { applyVolume(); });
|
||||
|
|
@ -802,36 +806,14 @@ void PipeWireGraphModel::applyVolumeStates(const QHash<QString, NodeVolumeState>
|
|||
continue;
|
||||
}
|
||||
const NodeVolumeState state = states.value(node.stableId);
|
||||
m_nodeVolumeState.insert(node.id, state);
|
||||
setNodeVolumeState(node.id, state, false);
|
||||
m_controller->setNodeVolume(node.id, state.volume, state.mute);
|
||||
|
||||
auto nodeIt = m_pwToNode.find(node.id);
|
||||
if (nodeIt == m_pwToNode.end()) {
|
||||
continue;
|
||||
}
|
||||
auto widgetIt = m_nodeWidgets.find(nodeIt->second);
|
||||
if (widgetIt == m_nodeWidgets.end()) {
|
||||
continue;
|
||||
}
|
||||
QWidget *widget = widgetIt->second;
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
if (auto *slider = widget->findChild<QSlider*>()) {
|
||||
slider->blockSignals(true);
|
||||
slider->setValue(static_cast<int>(state.volume * 100.0f));
|
||||
slider->blockSignals(false);
|
||||
}
|
||||
if (auto *button = widget->findChild<QToolButton*>()) {
|
||||
button->blockSignals(true);
|
||||
button->setChecked(state.mute);
|
||||
button->blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PipeWireGraphModel::setNodeVolumeState(uint32_t nodeId, const NodeVolumeState &state)
|
||||
void PipeWireGraphModel::setNodeVolumeState(uint32_t nodeId, const NodeVolumeState &state, bool notify)
|
||||
{
|
||||
const NodeVolumeState previous = m_nodeVolumeState.value(nodeId, NodeVolumeState{});
|
||||
m_nodeVolumeState.insert(nodeId, state);
|
||||
|
||||
auto nodeIt = m_pwToNode.find(nodeId);
|
||||
|
|
@ -858,6 +840,13 @@ void PipeWireGraphModel::setNodeVolumeState(uint32_t nodeId, const NodeVolumeSta
|
|||
button->setChecked(state.mute);
|
||||
button->blockSignals(false);
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
const bool changedVolume = std::abs(previous.volume - state.volume) > 0.0001f;
|
||||
if (changedVolume || previous.mute != state.mute) {
|
||||
Q_EMIT nodeVolumeChanged(nodeId, previous, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PipeWireGraphModel::nodeVolumeState(uint32_t nodeId, NodeVolumeState &state) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue