Skip to content

Commit

Permalink
MSEG and Formula can Tear Out
Browse files Browse the repository at this point in the history
1. Address the scale issue so zoom works
2. Handle the fact that these are swapable single views so the
   right thing generally happens when you change from an mseg to a formula

Closes surge-synthesizer#5219
  • Loading branch information
baconpaul committed Oct 10, 2021
1 parent a057761 commit b0d5279
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/surge-xt/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
}
bool isAnyOverlayOpenAtAll() { return !juceOverlays.empty(); }
juce::Component *getOverlayIfOpen(OverlayTags tag);
Surge::Overlays::OverlayWrapper *getOverlayWrapperIfOpen(OverlayTags tag);

void updateWaveshaperOverlay(); // this is the only overlay which updates from patch values

Expand Down
13 changes: 13 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("MSEG"));

mse->setEnclosingParentTitle(title);
mse->setCanTearOut(true);
locationForMSFR(mse.get());
return mse;
}
Expand All @@ -184,6 +185,7 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
Surge::Storage::findReplaceSubstring(title, std::string("LFO"), std::string("Formula"));

pt->setEnclosingParentTitle(title);
pt->setCanTearOut(true);
locationForMSFR(pt.get());
return pt;
}
Expand Down Expand Up @@ -487,6 +489,17 @@ juce::Component *SurgeGUIEditor::getOverlayIfOpen(OverlayTags tag)
return juceOverlays[tag]->primaryChild.get();
}

Surge::Overlays::OverlayWrapper *SurgeGUIEditor::getOverlayWrapperIfOpen(OverlayTags tag)
{
if (juceOverlays.find(tag) == juceOverlays.end())
return nullptr;

if (!juceOverlays[tag])
return nullptr;

return dynamic_cast<Surge::Overlays::OverlayWrapper *>(juceOverlays[tag].get());
}

void SurgeGUIEditor::updateWaveshaperOverlay()
{
auto wso =
Expand Down
42 changes: 32 additions & 10 deletions src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2553,27 +2553,49 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control)
}

bool hadExtendedOverlay = false;
if (isAnyOverlayPresent(MSEG_EDITOR))
bool wasTornOut = false;
juce::Point<int> tearOutLoc;
for (auto otag : {MSEG_EDITOR, FORMULA_EDITOR})
{
closeOverlay(SurgeGUIEditor::MSEG_EDITOR);
hadExtendedOverlay = true;
}
if (isAnyOverlayPresent(FORMULA_EDITOR))
{
closeOverlay(FORMULA_EDITOR);
hadExtendedOverlay = true;
if (isAnyOverlayPresent(otag))
{
auto c = getOverlayWrapperIfOpen(otag);
if (c)
{
wasTornOut = c->isTornOut();
tearOutLoc = c->currentTearOutLocation();
}
closeOverlay(otag);
hadExtendedOverlay = true;
}
}

if (hadExtendedOverlay)
{
auto ld = &(synth->storage.getPatch().scene[current_scene].lfo[newsource -
ms_lfo1]);
auto tag = MSEG_EDITOR;
bool go = false;
if (ld->shape.val.i == lt_mseg)
{
showOverlay(SurgeGUIEditor::MSEG_EDITOR);
go = true;
}
if (ld->shape.val.i == lt_formula)
{
showOverlay(FORMULA_EDITOR);
tag = FORMULA_EDITOR;
go = true;
}
if (go)
{
showOverlay(tag);
if (wasTornOut)
{
auto c = getOverlayWrapperIfOpen(tag);
if (c)
{
c->doTearOut(tearOutLoc);
}
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/surge-xt/gui/overlays/LuaEditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,21 @@ void FormulaModulatorEditor::applyCode()

void FormulaModulatorEditor::resized()
{
auto t = getTransform().inverted();
auto h = getHeight();
auto w = getWidth();
t.transformPoint(w, h);

int efdWidth = 14;
if (efd->isOpen)
{
efdWidth = 200;
}
tabs->setTabBarDepth(14);
tabs->setBounds(2, 2, getWidth() - 8 - efdWidth, getHeight() - 4);
tabs->setBounds(2, 2, w - 8 - efdWidth, h - 4);
auto b = tabs->getTabbedButtonBar().getLocalBounds();
applyButton->setBounds(b.getWidth() - 80, 2, 80 - 2, b.getHeight() - 4);
efd->setBounds(getWidth() - 4 - efdWidth, 2, efdWidth, getHeight() - 4);
efd->setBounds(w - 4 - efdWidth, 2, efdWidth, h - 4);
}

struct WavetablePreviewComponent : juce::Component
Expand Down
9 changes: 8 additions & 1 deletion src/surge-xt/gui/overlays/MSEGEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3257,11 +3257,18 @@ void MSEGEditor::paint(juce::Graphics &g) { g.fillAll(juce::Colours::orchid); }
void MSEGEditor::resized()
{
int controlHeight = 35;
auto r = getLocalBounds();

auto t = getTransform().inverted();
auto h = getHeight();
auto w = getWidth();
t.transformPoint(w, h);
auto r = getLocalBounds().withWidth(w).withHeight(h);

auto cvr = r.withTrimmedBottom(controlHeight);
auto ctr = r.withTop(cvr.getBottom());

canvas->setBounds(cvr);
canvas->recalcHotZones(juce::Point<int>(0, 0));
controls->setBounds(ctr);
// mained setbounds
}
Expand Down
12 changes: 11 additions & 1 deletion src/surge-xt/gui/overlays/OverlayWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void OverlayWrapper::supressInteriorDecoration()
primaryChild->setBounds(getLocalBounds());
}

void OverlayWrapper::doTearOut()
void OverlayWrapper::doTearOut(const juce::Point<int> &showAt)
{
parentBeforeTearOut = getParentComponent();
locationBeforeTearOut = getBoundsInParent();
Expand Down Expand Up @@ -187,12 +187,22 @@ void OverlayWrapper::doTearOut()
dw->setContentNonOwned(this, false);
dw->setContentComponentSize(w, h);
dw->setVisible(true);
if (showAt.x >= 0 && showAt.y >= 0)
dw->setTopLeftPosition(showAt.x, showAt.y);
dw->toFront(true);
dw->wrapping = this;
supressInteriorDecoration();
tearOutParent = std::move(dw);
}

juce::Point<int> OverlayWrapper::currentTearOutLocation()
{
if (!isTornOut())
return juce::Point<int>(-1, -1);

return tearOutParent->getPosition();
}

void OverlayWrapper::doTearIn()
{
if (!isTornOut() || !parentBeforeTearOut)
Expand Down
3 changes: 2 additions & 1 deletion src/surge-xt/gui/overlays/OverlayWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ struct OverlayWrapper : public juce::Component,

bool canTearOut{false};
void setCanTearOut(bool b) { canTearOut = b; }
void doTearOut();
void doTearOut(const juce::Point<int> &showAt = juce::Point<int>(-1, -1));
void doTearIn();
bool isTornOut();
juce::Point<int> currentTearOutLocation();
juce::Rectangle<int> locationBeforeTearOut, childLocationBeforeTearOut;
juce::Component *parentBeforeTearOut{nullptr};

Expand Down
1 change: 0 additions & 1 deletion src/surge-xt/gui/overlays/TuningOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ struct IntervalMatrix : public juce::Component

void resized() override
{
std::cout << "IM Resized " << getLocalBounds().toString() << std::endl;
viewport->setBounds(getLocalBounds().reduced(2).withTrimmedBottom(20));
intervalPainter->setSizeFromTuning();

Expand Down

0 comments on commit b0d5279

Please sign in to comment.