commit 06022ddf58b85c38d07a60e507cec78cd353cbc7
parent 604db1936832c74266de5a5747258d980568559b
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Tue, 14 Sep 2021 16:53:05 +0200
Better knobs
Diffstat:
4 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/examples/plugins/core-plugin.cc b/examples/plugins/core-plugin.cc
@@ -180,7 +180,7 @@ namespace clap {
auto p = _parameters.getById(paramId);
if (!p)
return;
- p->setValueSmoothed(value.value, 128);
+ p->setValueSmoothed(value.value, std::max<int>(process->frames_count, 128));
clap_event ev;
ev.time = 0;
diff --git a/examples/plugins/gui/parameter-proxy.cc b/examples/plugins/gui/parameter-proxy.cc
@@ -34,7 +34,8 @@ void ParameterProxy::setIsAdjusting(bool isAdjusting) {
if (isAdjusting == _isAdjusting)
return;
- uint32_t flags = CLAP_EVENT_PARAM_SHOULD_RECORD;
+ _isAdjusting = isAdjusting;
+ clap_event_param_flags flags = CLAP_EVENT_PARAM_SHOULD_RECORD;
flags |= isAdjusting ? CLAP_EVENT_PARAM_BEGIN_ADJUST : CLAP_EVENT_PARAM_END_ADJUST;
clap::messages::AdjustRequest rq{_id, _value, flags};
Application::instance().remoteChannel().sendRequestAsync(rq);
@@ -47,7 +48,7 @@ void ParameterProxy::setValueFromUI(double value) {
_value = value;
- clap::messages::AdjustRequest rq{_id, _value, 0};
+ clap::messages::AdjustRequest rq{_id, _value, CLAP_EVENT_PARAM_SHOULD_RECORD};
Application::instance().remoteChannel().sendRequestAsync(rq);
valueChanged();
finalValueChanged();
diff --git a/examples/plugins/gui/parameter-proxy.hh b/examples/plugins/gui/parameter-proxy.hh
@@ -20,6 +20,7 @@ class ParameterProxy : public QObject {
Q_PROPERTY(double maxValue READ getMaxValue NOTIFY maxValueChanged)
Q_PROPERTY(double defaultValue READ getDefaultValue NOTIFY defaultValueChanged)
Q_PROPERTY(bool isAdjusting READ isAdjusting WRITE setIsAdjusting)
+ Q_PROPERTY(bool isHovered READ isHovered WRITE setIsHovered)
public:
explicit ParameterProxy(const clap_param_info &info, QObject *parent = nullptr);
@@ -71,6 +72,9 @@ public:
Q_INVOKABLE void setToDefault();
+ bool isHovered() const { return _isHovered; }
+ void setIsHovered(bool value) { _isHovered = value; }
+
signals:
void nameChanged();
void moduleChanged();
@@ -91,4 +95,5 @@ private:
double _maxValue = 0;
double _defaultValue = 0;
bool _isAdjusting = false;
+ bool _isHovered = false;
};
\ No newline at end of file
diff --git a/examples/plugins/qml/clap/Knob.qml b/examples/plugins/qml/clap/Knob.qml
@@ -5,6 +5,8 @@ Canvas {
property int size: 20;
property string ringColor: "#544d63";
property string knobColor: "#0c002b";
+ property string knobColorAdjusting: "#25008b";
+ property string knobColorHovered: "#1b0064";
property string valueColor: "#ffffff";
property string modulationColor: "#10b1ca"
property double modulationMargin: .05;
@@ -29,20 +31,25 @@ Canvas {
}
MouseArea {
+ id: mouseArea
anchors.fill: parent
drag.axis: Drag.YAxis
property real lastY: 0
+ hoverEnabled: true
+ acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: (mouse) => {
if (mouse.button === Qt.LeftButton) {
lastY = mouse.y;
knob.param.isAdjusting = true;
+ knob.requestPaint();
}
}
onReleased: (mouse) => {
if (mouse.button === Qt.LeftButton) {
knob.param.isAdjusting = false;
+ knob.requestPaint();
}
}
@@ -55,8 +62,25 @@ Canvas {
}
onDoubleClicked: (mouse) => {
- if (mouse.button === Qt.LeftButton)
+ if (mouse.button === Qt.LeftButton) {
knob.param.setToDefault();
+ knob.requestPaint();
+ }
+ }
+
+ onCanceled: (mouse) => {
+ knob.param.isAdjusting = false;
+ knob.requestPaint();
+ }
+
+ onEntered: (mouse) => {
+ knob.param.isHovered = true;
+ knob.requestPaint();
+ }
+
+ onExited: (mouse) => {
+ knob.param.isHovered = false;
+ knob.requestPaint();
}
}
@@ -75,9 +99,10 @@ Canvas {
ctx.translate(size / 2, size / 2, size / 2);
ctx.rotate(ringAngle + Math.PI);
+ var effectiveKnobColor = param.isAdjusting ? knobColorAdjusting : (param.isHovered ? knobColorHovered : knobColor);
ctx.beginPath();
- ctx.arc(0, 0, size / 2, 0, 2 * Math.PI, false);
- ctx.fillStyle = knobColor;
+ ctx.arc(0, 0, size / 2 - 2 * modulationMargin * size, 0, 2 * Math.PI, false);
+ ctx.fillStyle = effectiveKnobColor;
ctx.fill();
ctx.beginPath();
@@ -124,7 +149,10 @@ Canvas {
ctx.beginPath();
var y0 = -size / 2 + size * modulationMargin;
var y1 = y0 + size / 3;
- ctx.rect(-radius, 0, 2 * radius, -size / 2 + size * (modulationMargin + 0.01));
+ ctx.rect(-radius, -size * modulationMargin, 2 * radius, -size / 2 + size * (3 * modulationMargin + 0.01));
+ ctx.fill();
+
+ ctx.arc(0, 0, size * (modulationMargin + 0.03), 0, 2 * Math.PI, false)
ctx.fill();
ctx.restore();