Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lfo display caching #7901

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,17 @@ void SurgeGUIEditor::moveTopLeftTo(float tx, float ty)

void SurgeGUIEditor::resizeWindow(float zf) { setZoomFactor(zf, true); }

/*
Called when compiling the lua code from formula editor.
It is called before the draw call.
*/

void SurgeGUIEditor::forceLfoDisplayRepaint()
{
if (lfoDisplay)
lfoDisplay->forceRepaint = true;
}

void SurgeGUIEditor::setZoomFactor(float zf) { setZoomFactor(zf, false); }

void SurgeGUIEditor::setZoomFactor(float zf, bool resizeWindow)
Expand Down Expand Up @@ -3043,6 +3054,9 @@ void SurgeGUIEditor::setZoomFactor(float zf, bool resizeWindow)
if (oscWaveform)
oscWaveform->setZoomFactor(zoomFactor);

if (lfoDisplay)
lfoDisplay->setZoomFactor(zoomFactor);

setBitmapZoomFactor(zoomFactor);
rezoomOverlays();
}
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,

SurgeSynthesizer *synth = nullptr;

void forceLfoDisplayRepaint();

private:
void openOrRecreateEditor();
std::unique_ptr<Surge::Overlays::OverlayComponent> makeStorePatchDialog();
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/overlays/LuaEditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ void FormulaModulatorEditor::applyCode()
editor->undoManager()->pushFormula(scene, lfo_id, *formulastorage);
formulastorage->setFormula(mainDocument->getAllContent().toStdString());
storage->getPatch().isDirty = true;
editor->forceLfoDisplayRepaint();
updateDebuggerIfNeeded();
editor->repaintFrame();
juce::SystemClipboard::copyTextToClipboard(formulastorage->formulaString);
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/overlays/MSEGEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,7 @@ struct MSEGCanvas : public juce::Component, public Surge::GUI::SkinConsumingComp
storage->getPatch().isDirty = true;
tagForUndo();
}
this->sge->forceLfoDisplayRepaint();
onModelChanged();
repaint();
}
Expand Down
76 changes: 74 additions & 2 deletions src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ LFOAndStepDisplay::LFOAndStepDisplay(SurgeGUIEditor *e)
setAccessible(true);
setFocusContainerType(juce::Component::FocusContainerType::focusContainer);

backingImage = std::make_unique<juce::Image>(juce::Image::PixelFormat::ARGB, 50, 50, true);
waveformIsUpdated = true;

typeLayer = std::make_unique<OverlayAsAccessibleContainer>("LFO Type");
addAndMakeVisible(*typeLayer);
for (int i = 0; i < n_lfo_types; ++i)
Expand Down Expand Up @@ -414,12 +417,81 @@ void LFOAndStepDisplay::paint(juce::Graphics &g)
}
else
{
paintWaveform(g);

if (!paramsHasChanged())
{
g.drawImage(*backingImage, getLocalBounds().toFloat(),
juce::RectanglePlacement::fillDestination);
paintTypeSelector(g);
return;
}
else
{
juce::Colour color =
juce::Colour((unsigned char)0, (unsigned char)0, (unsigned char)0, 0.f);

backingImage->clear(backingImage->getBounds());
}

juce::Graphics gr = juce::Graphics(*backingImage);
float zoomFloat = (float)zoomFactor / 100.f;

gr.addTransform(juce::AffineTransform().scale(zoomFloat * 2.f));

paintWaveform(gr);

g.drawImage(*backingImage, getLocalBounds().toFloat(),
juce::RectanglePlacement::fillDestination);
waveformIsUpdated = false;
}

paintTypeSelector(g);
}

bool LFOAndStepDisplay::paramsHasChanged()
{
bool hasChanged = false;

auto *p = &lfodata->rate; // look in the definition of LFOStorage for which param is first
while (p <= &lfodata->release) // and last
{

if (paramsFromLastDrawCall[p->param_id_in_scene].i != p->val.i)
hasChanged = true;

paramsFromLastDrawCall[p->param_id_in_scene].i = p->val.i;
++p;
};

if (lfoStorageFromLastDrawingCall != lfodata)
hasChanged = true;

if (forceRepaint)
{
hasChanged = true;
forceRepaint = false;
}

lfoStorageFromLastDrawingCall = lfodata;

return hasChanged;
}

void LFOAndStepDisplay::setZoomFactor(int zoom)
{

if (zoomFactor != zoom)
{
float zoomFloat = (float)zoom / 100.f;
forceRepaint = true;
backingImage = std::make_unique<juce::Image>(juce::Image::PixelFormat::ARGB,
outer.getWidth() * zoomFloat * 2,
outer.getHeight() * zoomFloat * 2, true);
}

zoomFactor = zoom;
}

void LFOAndStepDisplay::paintWaveform(juce::Graphics &g)
{
TimeB mainTimer("-- paintWaveform");
Expand Down Expand Up @@ -2440,7 +2512,7 @@ void LFOAndStepDisplay::updateShapeTo(int i)

sge->refresh_mod();
sge->broadcastPluginAutomationChangeFor(&(lfodata->shape));

forceRepaint = true;
repaint();

sge->lfoShapeChanged(prior, i);
Expand Down
12 changes: 12 additions & 0 deletions src/surge-xt/gui/widgets/LFOAndStepDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ struct LFOAndStepDisplay : public juce::Component,
bool isFormula() { return lfodata->shape.val.i == lt_formula; }
bool isUnipolar() { return lfodata->unipolar.val.b; }

void setZoomFactor(int);
int zoomFactor;
std::unique_ptr<juce::Image> backingImage;
bool waveformIsUpdated;
bool forceRepaint;
LFOStorage *lfoStorageFromLastDrawingCall;
pdata paramsFromLastDrawCall[n_scene_params];
int zoomFactorFromLastDrawCall;

bool paramsHasChanged();

void repaintIfIdIsInRange(int id)
{
auto *firstLfoParam = &lfodata->rate;
Expand Down Expand Up @@ -83,6 +94,7 @@ struct LFOAndStepDisplay : public juce::Component,
{
if (isAnythingTemposynced())
{
forceRepaint = true;
repaint();
}
}
Expand Down
Loading