From 53897dd461448a2a25aadefd5f813365d035286d Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Tue, 10 Oct 2023 19:08:02 -0700 Subject: [PATCH] Add click to drag wt pos --- plugin/Source/Panels.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/plugin/Source/Panels.h b/plugin/Source/Panels.h index 28a33bc..e9e2f55 100644 --- a/plugin/Source/Panels.h +++ b/plugin/Source/Panels.h @@ -43,6 +43,7 @@ class OscillatorBox : public gin::ParamBox, wt->setName ("wt"); wt->setWavetables (idx == 0 ? &proc.osc1Tables : &proc.osc2Tables); wt->onFileDrop = [this] (const juce::File& f) { loadUserWavetable (f); }; + wt->addMouseListener (this, false); addControl (wt); auto addButton = new gin::SVGButton ("add", gin::Assets::add); @@ -83,7 +84,7 @@ class OscillatorBox : public gin::ParamBox, else proc.osc2Table.removeListener (this); } - + void loadUserWavetable (const juce::File& f) { auto sz = gin::getWavetableSize (f); @@ -111,11 +112,36 @@ class OscillatorBox : public gin::ParamBox, proc.loadUserWavetable (idx, f, -1); } } + + void mouseDown (const juce::MouseEvent& e) override + { + if (e.originalComponent != wt) return; + + auto& pos = *proc.oscParams[idx].pos; + pos.beginUserAction(); + + mouseDownValue = pos.getUserValue(); + } + + void mouseDrag (const juce::MouseEvent& e) override + { + if (e.originalComponent != wt) return; + + auto& pos = *proc.oscParams[idx].pos; + + pos.setUserValue (mouseDownValue - e.getDistanceFromDragStartY()); + } void mouseUp (const juce::MouseEvent& e) override { auto& h = getHeader(); - if (e.originalComponent == &h && e.mouseWasClicked() && e.x >= prevButton.getRight() && e.x <= nextButton.getX()) + + if (e.originalComponent == wt) + { + auto& pos = *proc.oscParams[idx].pos; + pos.endUserAction(); + } + else if (e.originalComponent == &h && e.mouseWasClicked() && e.x >= prevButton.getRight() && e.x <= nextButton.getX()) { juce::StringArray tables; for (auto i = 0; i < BinaryData::namedResourceListSize; i++) @@ -186,6 +212,7 @@ class OscillatorBox : public gin::ParamBox, int idx = 0; gin::ParamComponent::Ptr detune, spread; gin::WavetableComponent* wt; + float mouseDownValue; gin::CoalescedTimer timer;