clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit df99f4d0758f1eb7ede5cf5fd532ceef2feb71d3
parent 9dea9dd24966da3508d6fc8d85aa87961751dc3a
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Fri, 10 Sep 2021 11:22:27 +0200

Improved knob

Diffstat:
Mexamples/plugins/gui/parameter-proxy.cc | 11+++++++++++
Mexamples/plugins/gui/parameter-proxy.hh | 2++
Mexamples/plugins/qml/clap/Knob.qml | 22+++++++++++++---------
3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/examples/plugins/gui/parameter-proxy.cc b/examples/plugins/gui/parameter-proxy.cc @@ -92,4 +92,15 @@ void ParameterProxy::setDefaultValueFromPlugin(double defaultValue) { _defaultValue = defaultValue; defaultValueChanged(); +} + +void ParameterProxy::setToDefault() +{ + bool wasAdjusting = _isAdjusting; + + if (!wasAdjusting) + setIsAdjusting(true); + setValueFromUI(_defaultValue); + if (!wasAdjusting) + setIsAdjusting(false); } \ No newline at end of file diff --git a/examples/plugins/gui/parameter-proxy.hh b/examples/plugins/gui/parameter-proxy.hh @@ -69,6 +69,8 @@ public: return _minValue + value * delta; } + Q_INVOKABLE void setToDefault(); + signals: void nameChanged(); void moduleChanged(); diff --git a/examples/plugins/qml/clap/Knob.qml b/examples/plugins/qml/clap/Knob.qml @@ -9,6 +9,7 @@ Canvas { property string valueColor: "#ffffff"; property string modulationColor: "#10b1ca" property double modulationMargin: .05; + property double ringAngle: Math.PI * 5 / 3; id: knob width: size @@ -56,7 +57,7 @@ Canvas { onDoubleClicked: (mouse) => { if (mouse.button === Qt.LeftButton) - knob.param.value = knob.param.defaultValue; + knob.param.setToDefault(); } } @@ -70,18 +71,21 @@ Canvas { function drawBackground(ctx) { ctx.save() - - ctx.fillStyle = ringColor; ctx.strokeStyle = "black"; + ctx.translate(size / 2, size / 2, size / 2); + ctx.rotate(ringAngle + Math.PI); + ctx.beginPath(); - ctx.arc(size / 2, size / 2, size / 2, 0, 2 * Math.PI, false); + ctx.arc(0, 0, size / 2, 0, 2 * Math.PI, false); + ctx.fillStyle = backgroundColor; ctx.fill(); ctx.stroke(); ctx.beginPath(); - ctx.arc(size / 2, size / 2, size / 2 - size * modulationMargin, 0, 2 * Math.PI, false); - ctx.fillStyle = backgroundColor; + ctx.arc(0, 0, size / 2 - size * modulationMargin, 0, ringAngle, false); + ctx.arc(0, 0, size / 2, ringAngle, 0, true); + ctx.fillStyle = ringColor; ctx.fill(); ctx.stroke(); @@ -99,9 +103,9 @@ Canvas { ctx.strokeStyle = "black"; ctx.beginPath(); - ctx.rotate((param.normalizedValue - .5) * Math.PI * 4 / 3 - Math.PI / 2); + ctx.rotate((param.normalizedValue - .5) * ringAngle - Math.PI / 2); - var finalValueAngle = (param.normalizedFinalValue - param.normalizedValue) * Math.PI * 4 / 3; + var finalValueAngle = (param.normalizedFinalValue - param.normalizedValue) * ringAngle; ctx.arc(0, 0, size / 2, 0, finalValueAngle, finalValueAngle < 0); ctx.arc(0, 0, size / 2 - size * modulationMargin, finalValueAngle, 0, finalValueAngle > 0); //ctx.arc(0, 0, size / 2, finalValueAngle, 0, true); @@ -120,7 +124,7 @@ Canvas { ctx.fillStyle = valueColor; ctx.strokeStyle = "black"; - ctx.rotate((param.normalizedValue - .5) * Math.PI * 4 / 3); + ctx.rotate((param.normalizedValue - .5) * ringAngle); ctx.beginPath(); var y0 = -size / 2 + size * modulationMargin; var y1 = y0 + size / 3;