From b9b885c1481d9c6c4e0d0d84cce9aec98cf6a0d9 Mon Sep 17 00:00:00 2001 From: George Reales Date: Mon, 28 Feb 2022 18:22:16 +0100 Subject: [PATCH] Oscillator octave lock using shift and mouse --- Source/Gui/Knob.h | 15 +++++++++++++++ Source/PluginEditor.cpp | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Source/Gui/Knob.h b/Source/Gui/Knob.h index 08e7df3..fbced57 100644 --- a/Source/Gui/Knob.h +++ b/Source/Gui/Knob.h @@ -94,6 +94,19 @@ public: } Slider::mouseDown(event); } + + void mouseDrag(const MouseEvent& event) override + { + Slider::mouseDrag(event); + if (event.mods.isShiftDown()) + { + if (shiftDragCallback) + { + setValue(shiftDragCallback(getValue()), sendNotificationAsync); + } + } + } + // Source: https://git.iem.at/audioplugins/IEMPluginSuite/-/blob/master/resources/customComponents/ReverseSlider.h public: class KnobAttachment : public juce::AudioProcessorValueTreeState::SliderAttachment @@ -147,6 +160,8 @@ public: shouldResetOnShiftClick = value; resetActionMessage = identifier; } + + std::function shiftDragCallback; private: Image kni; int fh, numFr; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 86b61da..95c5981 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -210,6 +210,14 @@ void ObxdAudioProcessorEditor::loadSkin (ObxdAudioProcessor& ownerFilter) } if (name == "osc1PitchKnob"){ osc1PitchKnob = addKnob (x, y, d, ownerFilter, OSC1P, "Osc1Pitch", 0); + osc1PitchKnob->shiftDragCallback = [](double value) + { + if (value < 0.125) return 0.0; + if (value < 0.375) return 0.25; + if (value < 0.625) return 0.5; + if (value < 0.875) return 0.75; + return 1.0; + }; mappingComps["osc1PitchKnob"] = osc1PitchKnob; } if (name == "pulseWidthKnob"){ @@ -218,6 +226,14 @@ void ObxdAudioProcessorEditor::loadSkin (ObxdAudioProcessor& ownerFilter) } if (name == "osc2PitchKnob"){ osc2PitchKnob = addKnob (x, y, d, ownerFilter, OSC2P, "Osc2Pitch", 0); + osc2PitchKnob->shiftDragCallback = [](double value) + { + if (value < 0.125) return 0.0; + if (value < 0.375) return 0.25; + if (value < 0.625) return 0.5; + if (value < 0.875) return 0.75; + return 1.0; + }; mappingComps["osc2PitchKnob"] = osc2PitchKnob; }