Log scaling for better vol control
This commit is contained in:
parent
10fe7103da
commit
cb9770a757
2 changed files with 25 additions and 6 deletions
|
|
@ -48,9 +48,20 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
inline float sliderToVolume(int slider) {
|
||||||
|
float x = static_cast<float>(slider) / 100.0f;
|
||||||
|
return x * x * x;
|
||||||
|
}
|
||||||
|
inline int volumeToSlider(float volume) {
|
||||||
|
return static_cast<int>(std::round(std::cbrt(volume) * 100.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DeleteVirtualNodeCommand : public QUndoCommand {
|
class DeleteVirtualNodeCommand : public QUndoCommand {
|
||||||
public:
|
public:
|
||||||
struct Snapshot {
|
struct Snapshot {
|
||||||
|
|
@ -1192,7 +1203,7 @@ void GraphEditorWidget::wireVolumeWidget(QtNodes::NodeId nodeId) {
|
||||||
connect(vol, &NodeVolumeWidget::volumeChanged, this,
|
connect(vol, &NodeVolumeWidget::volumeChanged, this,
|
||||||
[this, capturedId](int value) {
|
[this, capturedId](int value) {
|
||||||
auto state = m_model->nodeVolumeState(capturedId);
|
auto state = m_model->nodeVolumeState(capturedId);
|
||||||
state.volume = static_cast<float>(value) / 100.0f;
|
state.volume = sliderToVolume(value);
|
||||||
m_model->setNodeVolumeState(capturedId, state);
|
m_model->setNodeVolumeState(capturedId, state);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1268,7 +1279,7 @@ void GraphEditorWidget::rebuildMixerStrips() {
|
||||||
auto *slider = new ClickSlider(Qt::Horizontal);
|
auto *slider = new ClickSlider(Qt::Horizontal);
|
||||||
slider->setRange(0, 100);
|
slider->setRange(0, 100);
|
||||||
auto state = m_model->nodeVolumeState(nodeId);
|
auto state = m_model->nodeVolumeState(nodeId);
|
||||||
slider->setValue(static_cast<int>(state.volume * 100.0f));
|
slider->setValue(volumeToSlider(state.volume));
|
||||||
slider->setStyleSheet(QStringLiteral(
|
slider->setStyleSheet(QStringLiteral(
|
||||||
"QSlider::groove:horizontal {"
|
"QSlider::groove:horizontal {"
|
||||||
" background: #1a1a1e; border-radius: 3px; height: 6px; }"
|
" background: #1a1a1e; border-radius: 3px; height: 6px; }"
|
||||||
|
|
@ -1301,7 +1312,7 @@ void GraphEditorWidget::rebuildMixerStrips() {
|
||||||
connect(slider, &QSlider::valueChanged, this,
|
connect(slider, &QSlider::valueChanged, this,
|
||||||
[this, capturedId](int value) {
|
[this, capturedId](int value) {
|
||||||
auto s = m_model->nodeVolumeState(capturedId);
|
auto s = m_model->nodeVolumeState(capturedId);
|
||||||
s.volume = static_cast<float>(value) / 100.0f;
|
s.volume = sliderToVolume(value);
|
||||||
m_model->setNodeVolumeState(capturedId, s);
|
m_model->setNodeVolumeState(capturedId, s);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1330,7 +1341,7 @@ void GraphEditorWidget::rebuildMixerStrips() {
|
||||||
return;
|
return;
|
||||||
QSignalBlocker sb(slider);
|
QSignalBlocker sb(slider);
|
||||||
QSignalBlocker mb(muteBtn);
|
QSignalBlocker mb(muteBtn);
|
||||||
slider->setValue(static_cast<int>(cur.volume * 100.0f));
|
slider->setValue(volumeToSlider(cur.volume));
|
||||||
muteBtn->setChecked(cur.mute);
|
muteBtn->setChecked(cur.mute);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,14 @@
|
||||||
#include <QtNodes/NodeStyle>
|
#include <QtNodes/NodeStyle>
|
||||||
#include <QtNodes/StyleCollection>
|
#include <QtNodes/StyleCollection>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
inline int volumeToSlider(float volume) {
|
||||||
|
return static_cast<int>(std::round(std::cbrt(volume) * 100.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
@ -633,7 +641,7 @@ void WarpGraphModel::refreshFromClient() {
|
||||||
|
|
||||||
float vol = volResult.value.volume;
|
float vol = volResult.value.volume;
|
||||||
bool mute = volResult.value.mute;
|
bool mute = volResult.value.mute;
|
||||||
int sliderVal = static_cast<int>(std::round(vol * 100.0f));
|
int sliderVal = volumeToSlider(vol);
|
||||||
sliderVal = std::clamp(sliderVal, 0, 150);
|
sliderVal = std::clamp(sliderVal, 0, 150);
|
||||||
|
|
||||||
auto stateIt = m_volumeStates.find(qtId);
|
auto stateIt = m_volumeStates.find(qtId);
|
||||||
|
|
@ -820,7 +828,7 @@ void WarpGraphModel::setNodeVolumeState(QtNodes::NodeId nodeId,
|
||||||
if (wIt != m_volumeWidgets.end()) {
|
if (wIt != m_volumeWidgets.end()) {
|
||||||
auto *w = qobject_cast<NodeVolumeWidget *>(wIt->second);
|
auto *w = qobject_cast<NodeVolumeWidget *>(wIt->second);
|
||||||
if (w) {
|
if (w) {
|
||||||
w->setVolume(static_cast<int>(state.volume * 100.0f));
|
w->setVolume(volumeToSlider(state.volume));
|
||||||
w->setMuted(state.mute);
|
w->setMuted(state.mute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue