Skip to content

Commit

Permalink
Add click to drag wt pos
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Oct 11, 2023
1 parent 1430480 commit 53897dd
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions plugin/Source/Panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 53897dd

Please sign in to comment.