Skip to content

Commit

Permalink
WTSE overview class refactor (surge-synthesizer#7755)
Browse files Browse the repository at this point in the history
* WTSE refactor
- Changes WTSE overview class constructor to use similar style as FormulaModulatorEditor
- Renames WavetableEquationEditor class to WavetableScriptEditor
- Renames defaultWavetableFormula string to defaultWavetableScript
- Adds preliminary Prelude to WTSE
- Adds changes to WTSE UI
- Adds WavetableScriptEditState struct to DAWExtraStateStorage and SurgePatch load_xml()/save_xml()
- Increments XML file version to v25

* Fix missing override

* Removes commented out code and adds description to DAWExtraStateStorage struct
  • Loading branch information
nuoun authored Aug 14, 2024
1 parent a0c2e2c commit 8b615f4
Show file tree
Hide file tree
Showing 7 changed files with 579 additions and 223 deletions.
31 changes: 31 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,26 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
}
}
}

for (int osc = 0; osc < n_oscs; osc++)
{
std::string wsns =
"wtse_state_" + std::to_string(sc) + "_" + std::to_string(osc);
auto wss = TINYXML_SAFE_TO_ELEMENT(p->FirstChild(wsns));

if (wss)
{
auto q = &(dawExtraState.editor.wavetableScriptEditState[sc][osc]);
int vv;

q->codeOrPrelude = 0;

if (wss->QueryIntAttribute("codeOrPrelude", &vv) == TIXML_SUCCESS)
{
q->codeOrPrelude = vv;
}
}
}
} // end of scene loop

{
Expand Down Expand Up @@ -3718,6 +3738,17 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
eds.InsertEndChild(fss);
}

for (int os = 0; os < n_oscs; ++os)
{
auto q = &(dawExtraState.editor.wavetableScriptEditState[sc][os]);
std::string wsns = "wtse_state_" + std::to_string(sc) + "_" + std::to_string(os);
TiXmlElement wss(wsns);

wss.SetAttribute("codeOrPrelude", q->codeOrPrelude);

eds.InsertEndChild(wss);
}

TiXmlElement modEd("modulation_editor");
modEd.SetAttribute("sortOrder", dawExtraState.editor.modulationEditorState.sortOrder);
modEd.SetAttribute("filterOn", dawExtraState.editor.modulationEditorState.filterOn);
Expand Down
17 changes: 16 additions & 1 deletion src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ const int FIRoffsetI16 = FIRipolI16_N >> 1;
// added deform option for Release parameter of Filter/Amp EG, which only produces an open gate for the release stage
// 23 -> 24 (XT 1.3.3 nightlies) added actually functioning extend mode to FM2 oscillator's M1/2 Offset parameter
// (old patches load with extend disabled even if they had it enabled)
// 24 -> 25 (XT 1.3.4 nightlies) added storing of Wavetable Script Editor window state
// clang-format on

const int ff_revision = 24;
const int ff_revision = 25;

const int n_scene_params = 273;
const int n_global_params = 11 + n_fx_slots * (n_fx_params + 1); // each param plus a type
Expand Down Expand Up @@ -910,6 +911,11 @@ struct DAWExtraStateStorage
int timeEditMode = 0;
} msegEditState[n_scenes][n_lfos];

/*
* Window state parameters for Formula Editor overlay
* codeOrPrelude: Code editor selected tab
* debuggerOpen: Debug panel toggle
*/
struct FormulaEditState
{
int codeOrPrelude{0};
Expand All @@ -921,6 +927,15 @@ struct DAWExtraStateStorage
bool hasCustomEditor = false;
} oscExtraEditState[n_scenes][n_lfos];

/*
* Window state parameters for WTSE overlay
* codeOrPrelude: Code editor selected tab
*/
struct WavetableScriptEditState
{
int codeOrPrelude{0};
} wavetableScriptEditState[n_scenes][n_oscs];

struct OverlayState
{
int whichOverlay{-1};
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/WavetableScriptEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool constructWavetable(SurgeStorage *storage, const std::string &eqn, int resol
}
return true;
}
std::string defaultWavetableFormula()
std::string defaultWavetableScript()
{
return R"FN(function generate(config)
-- This script serves as the default example for the wavetable script editor. Unlike the formula editor, which executes
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/WavetableScriptEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::vector<float> evaluateScriptAtFrame(SurgeStorage *storage, const std::strin
bool constructWavetable(SurgeStorage *storage, const std::string &eqn, int resolution, int frames,
wt_header &wh, float **wavdata);

std::string defaultWavetableFormula();
std::string defaultWavetableScript();

} // namespace WavetableScript
} // namespace Surge
Expand Down
15 changes: 5 additions & 10 deletions src/surge-xt/gui/SurgeGUIEditorOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay

case WTSCRIPT_EDITOR:
{
/*
int w = 800, h = 520;
auto px = (getWindowSizeX() - w) / 2;
auto py = (getWindowSizeY() - h) / 2;
auto r = juce::Rectangle<int>(px, py, w, h);
*/

auto os = &synth->storage.getPatch().scene[current_scene].osc[current_osc[current_scene]];

Expand All @@ -296,13 +290,14 @@ std::unique_ptr<Surge::Overlays::OverlayComponent> SurgeGUIEditor::createOverlay
return nullptr;
}

auto wtse = std::make_unique<Surge::Overlays::WavetableEquationEditor>(
this, &(this->synth->storage), os, currentSkin);
auto wtse = std::make_unique<Surge::Overlays::WavetableScriptEditor>(
this, &(this->synth->storage), os, current_osc[current_scene], current_scene,
currentSkin);

wtse->setSkin(currentSkin, bitmapStore);
// wtse->setEnclosingParentPosition(juce::Rectangle<int>(px, py, w, h));
std::string title = "Wavetable Script Editor Osc ";
title += std::to_string(current_osc[current_scene] + 1);

wtse->setSkin(currentSkin, bitmapStore);
wtse->setEnclosingParentTitle(title);
wtse->setCanTearOut({true, Surge::Storage::WTScriptOverlayLocationTearOut,
Surge::Storage::WTScriptOverlayTearOutAlwaysOnTop,
Expand Down
Loading

0 comments on commit 8b615f4

Please sign in to comment.