From 97413fda4c8f44c9de214eda2a2e67f6d434b534 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Mon, 6 Dec 2021 21:39:44 -0500 Subject: [PATCH] Store state for new overlays in DES 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 --- src/common/SurgePatch.cpp | 82 ++++++++++++++++++- src/common/SurgeStorage.h | 18 ++++ src/surge-xt/gui/SurgeGUIEditorOverlays.cpp | 3 +- src/surge-xt/gui/overlays/LuaEditors.cpp | 37 +++++++-- src/surge-xt/gui/overlays/LuaEditors.h | 7 +- .../gui/overlays/ModulationEditor.cpp | 53 +++++++++++- src/surge-xt/gui/overlays/TuningOverlays.cpp | 12 +++ src/surge-xt/gui/overlays/TuningOverlays.h | 2 +- 8 files changed, 202 insertions(+), 12 deletions(-) diff --git a/src/common/SurgePatch.cpp b/src/common/SurgePatch.cpp index 7b51745850c..cbbb42e1a71 100644 --- a/src/common/SurgePatch.cpp +++ b/src/common/SurgePatch.cpp @@ -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) @@ -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); diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 2428c216f4f..398ffe19faa 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -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; @@ -775,6 +781,18 @@ struct DAWExtraStateStorage std::pair tearOutPosition{-1, -1}; }; std::vector activeOverlays; + + struct ModulationEditorState + { + int sortOrder = 0; + int filterOn = 0; + std::string filterString{""}; + } modulationEditorState; + + struct TuningOverlayState + { + int editMode = 0; + } tuningOverlayState; } editor; bool mpeEnabled = false; diff --git a/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp b/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp index 445077fae2f..c34a1165fa5 100644 --- a/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorOverlays.cpp @@ -238,7 +238,8 @@ std::unique_ptr SurgeGUIEditor::createOverlay auto fme = std::make_unique( 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"; diff --git a/src/surge-xt/gui/overlays/LuaEditors.cpp b/src/surge-xt/gui/overlays/LuaEditors.cpp index 6a2a0cbfeea..6066a6d29b0 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.cpp +++ b/src/surge-xt/gui/overlays/LuaEditors.cpp @@ -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(); } @@ -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; @@ -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; } @@ -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); @@ -538,10 +542,31 @@ FormulaModulatorEditor::FormulaModulatorEditor(SurgeGUIEditor *ed, SurgeStorage debugPanel = std::make_unique(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(); @@ -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() diff --git a/src/surge-xt/gui/overlays/LuaEditors.h b/src/surge-xt/gui/overlays/LuaEditors.h index 29fd30c9227..26d70897835 100644 --- a/src/surge-xt/gui/overlays/LuaEditors.h +++ b/src/surge-xt/gui/overlays/LuaEditors.h @@ -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 debugPanel; @@ -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 preludeDocument; std::unique_ptr preludeDisplay; diff --git a/src/surge-xt/gui/overlays/ModulationEditor.cpp b/src/surge-xt/gui/overlays/ModulationEditor.cpp index a9501a69fe2..96d1f3f3796 100644 --- a/src/surge-xt/gui/overlays/ModulationEditor.cpp +++ b/src/surge-xt/gui/overlays/ModulationEditor.cpp @@ -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); @@ -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 { @@ -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}; @@ -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; } } @@ -555,6 +592,11 @@ 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) @@ -562,6 +604,11 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC 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; } /* @@ -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; diff --git a/src/surge-xt/gui/overlays/TuningOverlays.cpp b/src/surge-xt/gui/overlays/TuningOverlays.cpp index 691e8a2d277..4ef25a7bdbb 100644 --- a/src/surge-xt/gui/overlays/TuningOverlays.cpp +++ b/src/surge-xt/gui/overlays/TuningOverlays.cpp @@ -1765,6 +1765,9 @@ struct TuningControlArea : public juce::Component, selectS->setColumns(5); selectS->setDraggable(true); selectS->setSkin(skin, associatedBitmapStore); + selectS->setValue( + overlay->storage->getPatch().dawExtraState.editor.tuningOverlayState.editMode / + 4.f); addAndMakeVisible(*selectS); xpos += btnWidth + 10; } @@ -1962,6 +1965,8 @@ TuningOverlay::TuningOverlay() intervalMatrix->setVisible(false); } +void TuningOverlay::setStorage(SurgeStorage *s) { storage = s; } + TuningOverlay::~TuningOverlay() = default; void TuningOverlay::resized() @@ -1991,6 +1996,8 @@ void TuningOverlay::resized() { auto mcoff = Surge::Storage::getUserDefaultValue(storage, Surge::Storage::MiddleC, 1); tuningKeyboardTableModel->setMiddleCOff(mcoff); + + showEditor(storage->getPatch().dawExtraState.editor.tuningOverlayState.editMode); } } @@ -2016,6 +2023,11 @@ void TuningOverlay::showEditor(int which) { intervalMatrix->setRotationMode(); } + + if (storage) + { + storage->getPatch().dawExtraState.editor.tuningOverlayState.editMode = which; + } } void TuningOverlay::onToneChanged(int tone, double newCentsValue) diff --git a/src/surge-xt/gui/overlays/TuningOverlays.h b/src/surge-xt/gui/overlays/TuningOverlays.h index d0ad0e678d1..bcf0958bab7 100644 --- a/src/surge-xt/gui/overlays/TuningOverlays.h +++ b/src/surge-xt/gui/overlays/TuningOverlays.h @@ -65,7 +65,7 @@ struct TuningOverlay : public OverlayComponent, TuningOverlay(); ~TuningOverlay(); - void setStorage(SurgeStorage *s) { storage = s; } + void setStorage(SurgeStorage *s); SurgeGUIEditor *editor{nullptr}; void setEditor(SurgeGUIEditor *ed) { editor = ed; }