Skip to content

Commit

Permalink
Store state for new overlays in DES (#5591)
Browse files Browse the repository at this point in the history
DawExtraState gets state for control panels on modulator,
tuning, and formula editor

These items all stream into the DAW Extra State so it persists
across daw sessions.

Closes #5588
  • Loading branch information
baconpaul authored Dec 7, 2021
1 parent b28601f commit bb4998d
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 12 deletions.
82 changes: 81 additions & 1 deletion src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,8 +2182,65 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
q->timeEditMode = vv;
}
}
for (int lf = 0; lf < n_lfos; ++lf)
{
std::string fsns =
"formula_state_" + std::to_string(sc) + "_" + std::to_string(lf);
auto fss = TINYXML_SAFE_TO_ELEMENT(p->FirstChild(fsns));
if (fss)
{
auto q = &(dawExtraState.editor.formulaEditState[sc][lf]);
int vv;
q->codeOrPrelude = 0;
q->debuggerOpen = false;
if (fss->QueryIntAttribute("codeOrPrelude", &vv) == TIXML_SUCCESS)
q->codeOrPrelude = vv;
if (fss->QueryIntAttribute("debuggerOpen", &vv) == TIXML_SUCCESS)
q->debuggerOpen = vv;
}
}
} // end of scene loop

{
auto mes = &(dawExtraState.editor.modulationEditorState);
auto node = TINYXML_SAFE_TO_ELEMENT(p->FirstChild("modulation_editor"));
mes->sortOrder = 0;
mes->filterOn = 0;
mes->filterString = "";
if (node)
{
int val;
if (node->QueryIntAttribute("sortOrder", &val) == TIXML_SUCCESS)
{
mes->sortOrder = val;
}

if (node->QueryIntAttribute("filterOn", &val) == TIXML_SUCCESS)
{
mes->filterOn = val;
}

if (node->Attribute("filterString"))
{
mes->filterString = std::string(node->Attribute("filterString"));
}
}
}
}

{
auto tes = &(dawExtraState.editor.tuningOverlayState);
auto node = TINYXML_SAFE_TO_ELEMENT(p->FirstChild("tuning_overlay"));
tes->editMode = 0;
if (node)
{
int val;
if (node->QueryIntAttribute("editMode", &val) == TIXML_SUCCESS)
{
tes->editMode = val;
}
}
}
} // end of editor populated block

p = TINYXML_SAFE_TO_ELEMENT(de->FirstChild("mpeEnabled"));
if (p && p->QueryIntAttribute("v", &ival) == TIXML_SUCCESS)
Expand Down Expand Up @@ -2717,6 +2774,29 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
eds.InsertEndChild(mss);
}
}

for (int lf = 0; lf < n_lfos; ++lf)
{
auto q = &(dawExtraState.editor.formulaEditState[sc][lf]);
std::string fsns = "formula_state_" + std::to_string(sc) + "_" + std::to_string(lf);
TiXmlElement fss(fsns);

fss.SetAttribute("codeOrPrelude", q->codeOrPrelude);
fss.SetAttribute("debuggerOpen", q->debuggerOpen);

eds.InsertEndChild(fss);
}

TiXmlElement modEd("modulation_editor");
modEd.SetAttribute("sortOrder", dawExtraState.editor.modulationEditorState.sortOrder);
modEd.SetAttribute("filterOn", dawExtraState.editor.modulationEditorState.filterOn);
modEd.SetAttribute("filterString",
dawExtraState.editor.modulationEditorState.filterString.c_str());
eds.InsertEndChild(modEd);

TiXmlElement tunOl("tuning_overlay");
tunOl.SetAttribute("editMode", dawExtraState.editor.tuningOverlayState.editMode);
eds.InsertEndChild(tunOl);
}

dawExtraXML.InsertEndChild(eds);
Expand Down
18 changes: 18 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@ struct DAWExtraStateStorage
int timeEditMode = 0;
} msegEditState[n_scenes][n_lfos];

struct FormulaEditState
{
int codeOrPrelude{0};
bool debuggerOpen{false};
} formulaEditState[n_scenes][n_lfos];

struct
{
bool hasCustomEditor = false;
Expand All @@ -775,6 +781,18 @@ struct DAWExtraStateStorage
std::pair<int, int> tearOutPosition{-1, -1};
};
std::vector<OverlayState> activeOverlays;

struct ModulationEditorState
{
int sortOrder = 0;
int filterOn = 0;
std::string filterString{""};
} modulationEditorState;

struct TuningOverlayState
{
int editMode = 0;
} tuningOverlayState;
} editor;

bool mpeEnabled = false;
Expand Down
3 changes: 2 additions & 1 deletion src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay

auto fme = std::make_unique<Surge::Overlays::FormulaModulatorEditor>(
this, &(this->synth->storage),
&synth->storage.getPatch().scene[current_scene].lfo[lfo_id], fs, lfo_id, currentSkin);
&synth->storage.getPatch().scene[current_scene].lfo[lfo_id], fs, lfo_id, current_scene,
currentSkin);

std::string title = modsource_names[modsource_editor[current_scene]];
title += " Editor";
Expand Down
37 changes: 32 additions & 5 deletions src/surge-xt/gui/overlays/LuaEditors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ struct ExpandingFormulaDebugger : public juce::Component, public Surge::GUI::Ski
void setOpen(bool b)
{
isOpen = b;
editor->getEditState().debuggerOpen = b;
setVisible(b);
editor->resized();
}
Expand Down Expand Up @@ -363,6 +364,7 @@ struct FormulaControlArea : public juce::Component,
codeS->setRows(1);
codeS->setColumns(2);
codeS->setDraggable(true);
codeS->setValue(overlay->getEditState().codeOrPrelude);
codeS->setSkin(skin, associatedBitmapStore);
addAndMakeVisible(*codeS);
marginPos += btnWidth + margin;
Expand Down Expand Up @@ -414,17 +416,18 @@ struct FormulaControlArea : public juce::Component,
return res;
};

showS = ma("Show", tag_debugger_show);
auto isOpen = overlay->debugPanel->isOpen;
showS = ma(isOpen ? "Hide" : "Show", tag_debugger_show);
addAndMakeVisible(*showS);
bpos -= btnWidth + margin;

stepS = ma("Step", tag_debugger_step);
stepS->setVisible(false);
stepS->setVisible(isOpen);
addChildComponent(*stepS);
bpos -= btnWidth + margin;

initS = ma("Init", tag_debugger_init);
initS->setVisible(false);
initS->setVisible(isOpen);
addChildComponent(*initS);
bpos -= btnWidth + margin;
}
Expand Down Expand Up @@ -513,9 +516,10 @@ struct FormulaControlArea : public juce::Component,
};

FormulaModulatorEditor::FormulaModulatorEditor(SurgeGUIEditor *ed, SurgeStorage *s, LFOStorage *ls,
FormulaModulatorStorage *fs, int lid,
FormulaModulatorStorage *fs, int lid, int scene,
Surge::GUI::Skin::ptr_t skin)
: CodeEditorContainerWithApply(ed, s, skin, false), lfos(ls), formulastorage(fs), lfo_id(lid)
: CodeEditorContainerWithApply(ed, s, skin, false), lfos(ls), scene(scene), formulastorage(fs),
lfo_id(lid)
{
mainEditor->setScrollbarThickness(8);

Expand All @@ -538,10 +542,31 @@ FormulaModulatorEditor::FormulaModulatorEditor(SurgeGUIEditor *ed, SurgeStorage
debugPanel = std::make_unique<ExpandingFormulaDebugger>(this);
debugPanel->setVisible(false);
addChildComponent(*debugPanel);

switch (getEditState().codeOrPrelude)
{
case 0:
showModulatorCode();
break;
case 1:
showPreludeCode();
break;
}

if (getEditState().debuggerOpen)
{
debugPanel->setOpen(true);
debugPanel->initializeLfoDebugger();
repaint();
}
}

FormulaModulatorEditor::~FormulaModulatorEditor() = default;

DAWExtraStateStorage::EditorState::FormulaEditState &FormulaModulatorEditor::getEditState()
{
return storage->getPatch().dawExtraState.editor.formulaEditState[scene][lfo_id];
}
void FormulaModulatorEditor::onSkinChanged()
{
CodeEditorContainerWithApply::onSkinChanged();
Expand Down Expand Up @@ -599,12 +624,14 @@ void FormulaModulatorEditor::showModulatorCode()
{
preludeDisplay->setVisible(false);
mainEditor->setVisible(true);
getEditState().codeOrPrelude = 0;
}

void FormulaModulatorEditor::showPreludeCode()
{
preludeDisplay->setVisible(true);
mainEditor->setVisible(false);
getEditState().codeOrPrelude = 1;
}

void FormulaModulatorEditor::escapeKeyPressed()
Expand Down
7 changes: 5 additions & 2 deletions src/surge-xt/gui/overlays/LuaEditors.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct FormulaControlArea;
struct FormulaModulatorEditor : public CodeEditorContainerWithApply
{
FormulaModulatorEditor(SurgeGUIEditor *ed, SurgeStorage *s, LFOStorage *lfos,
FormulaModulatorStorage *fs, int lfoid, Surge::GUI::Skin::ptr_t sk);
FormulaModulatorStorage *fs, int lfoid, int scene,
Surge::GUI::Skin::ptr_t sk);
~FormulaModulatorEditor();

std::unique_ptr<ExpandingFormulaDebugger> debugPanel;
Expand All @@ -91,11 +92,13 @@ struct FormulaModulatorEditor : public CodeEditorContainerWithApply

LFOStorage *lfos{nullptr};
FormulaModulatorStorage *formulastorage{nullptr};
int lfo_id;
int lfo_id, scene;

void onSkinChanged() override;
void setApplyEnabled(bool b) override;

DAWExtraStateStorage::EditorState::FormulaEditState &getEditState();

std::unique_ptr<juce::CodeDocument> preludeDocument;
std::unique_ptr<juce::CodeEditorComponent> preludeDisplay;

Expand Down
53 changes: 51 additions & 2 deletions src/surge-xt/gui/overlays/ModulationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,22 @@ struct ModulationSideControls : public juce::Component,
"Target",
},
tag_sort_by, true);
auto sortOrder =
editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.sortOrder;
sortW->setValue(sortOrder);

filterL = makeL("Filter By");
filterW = makeW({"-"}, tag_filter_by, true);

auto fo =
editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterOn;
if (fo != 0)
{
auto fs = editor->synth->storage.getPatch()
.dawExtraState.editor.modulationEditorState.filterString;
filterW->setLabels({fs});
}

addL = makeL("Add Modulation");
addSourceW = makeW({"Select Source"}, tag_add_source, true);
addTargetW = makeW({"Select Target"}, tag_add_target, false);
Expand Down Expand Up @@ -182,7 +195,28 @@ struct ModulationSideControls : public juce::Component,
struct ModulationListContents : public juce::Component, public Surge::GUI::SkinConsumingComponent
{
ModulationEditor *editor{nullptr};
ModulationListContents(ModulationEditor *e) : editor(e) {}
ModulationListContents(ModulationEditor *e) : editor(e)
{
sortOrder = (SortOrder)e->synth->storage.getPatch()
.dawExtraState.editor.modulationEditorState.sortOrder;

filterOn = (FilterOn)editor->synth->storage.getPatch()
.dawExtraState.editor.modulationEditorState.filterOn;
switch (filterOn)
{
case NONE:
clearFilters();
break;
case SOURCE:
filterBySource(editor->synth->storage.getPatch()
.dawExtraState.editor.modulationEditorState.filterString);
break;
case TARGET:
filterByTarget(editor->synth->storage.getPatch()
.dawExtraState.editor.modulationEditorState.filterString);
break;
}
}

void paint(juce::Graphics &g) override
{
Expand Down Expand Up @@ -528,7 +562,7 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC

enum SortOrder
{
BY_SOURCE,
BY_SOURCE = 0,
BY_TARGET
} sortOrder{BY_SOURCE};

Expand All @@ -547,6 +581,9 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC
{
filterOn = NONE;
rebuildFrom(editor->synth);

editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterOn =
(int)NONE;
}
}

Expand All @@ -555,13 +592,23 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC
filterOn = SOURCE;
filterString = s;
rebuildFrom(editor->synth);

editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterOn =
(int)SOURCE;
editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterString =
s;
}

void filterByTarget(const std::string &s)
{
filterOn = TARGET;
filterString = s;
rebuildFrom(editor->synth);

editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterOn =
(int)TARGET;
editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.filterString =
s;
}

/*
Expand Down Expand Up @@ -818,6 +865,8 @@ void ModulationSideControls::valueChanged(GUI::IComponentTagValue *c)
editor->modContents->sortOrder = ModulationListContents::BY_TARGET;
else
editor->modContents->sortOrder = ModulationListContents::BY_SOURCE;
editor->synth->storage.getPatch().dawExtraState.editor.modulationEditorState.sortOrder =
editor->modContents->sortOrder;
editor->modContents->rebuildFrom(editor->synth);
}
break;
Expand Down
Loading

0 comments on commit bb4998d

Please sign in to comment.