Add click to drag wt pos

This commit is contained in:
Roland Rabien 2023-10-10 19:08:02 -07:00
commit 53897dd461

View file

@ -43,6 +43,7 @@ public:
wt->setName ("wt"); wt->setName ("wt");
wt->setWavetables (idx == 0 ? &proc.osc1Tables : &proc.osc2Tables); wt->setWavetables (idx == 0 ? &proc.osc1Tables : &proc.osc2Tables);
wt->onFileDrop = [this] (const juce::File& f) { loadUserWavetable (f); }; wt->onFileDrop = [this] (const juce::File& f) { loadUserWavetable (f); };
wt->addMouseListener (this, false);
addControl (wt); addControl (wt);
auto addButton = new gin::SVGButton ("add", gin::Assets::add); auto addButton = new gin::SVGButton ("add", gin::Assets::add);
@ -112,10 +113,35 @@ public:
} }
} }
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 void mouseUp (const juce::MouseEvent& e) override
{ {
auto& h = getHeader(); 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; juce::StringArray tables;
for (auto i = 0; i < BinaryData::namedResourceListSize; i++) for (auto i = 0; i < BinaryData::namedResourceListSize; i++)
@ -186,6 +212,7 @@ public:
int idx = 0; int idx = 0;
gin::ParamComponent::Ptr detune, spread; gin::ParamComponent::Ptr detune, spread;
gin::WavetableComponent* wt; gin::WavetableComponent* wt;
float mouseDownValue;
gin::CoalescedTimer timer; gin::CoalescedTimer timer;