Skip to content

Commit

Permalink
LFO Raw / Output scaling
Browse files Browse the repository at this point in the history
Allow users to toggle raw outputs scaled by amplitude on an LFO-by-LFO
basis in the hamburger menu.

Closes surge-synthesizer#6674
  • Loading branch information
baconpaul committed Jan 25, 2023
1 parent 2dd21f5 commit e3af551
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,36 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
scene[0].modsources[ms_ctrl1 + i]->reset();
}

{
/*
* Reset to UNSCALED then try and read
*/
for (int sc = 0; sc < n_scenes; sc++)
{
for (int l = 0; l < n_lfos; l++)
{
scene[sc].lfo[l].lfoExtraAmplitude = LFOStorage::UNSCALED;
}
}
auto *el = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("extralfo"));
if (el)
{
auto l = TINYXML_SAFE_TO_ELEMENT(el->FirstChild("lfo"));
while (l)
{
int sc, id, val;
if (l->QueryIntAttribute("scene", &sc) == TIXML_SUCCESS &&
l->QueryIntAttribute("i", &id) == TIXML_SUCCESS &&
l->QueryIntAttribute("extraAmplitude", &val) == TIXML_SUCCESS && sc >= 0 &&
id >= 0 && sc < n_scenes && id < n_lfos)
{
scene[sc].lfo[id].lfoExtraAmplitude = (LFOStorage::LFOExtraOutputAmplitude)val;
}
l = TINYXML_SAFE_TO_ELEMENT(l->NextSiblingElement("lfo"));
}
}
}

TiXmlElement *cc = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("customcontroller"));

if (cc)
Expand Down Expand Up @@ -3181,6 +3211,21 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
}
patch.InsertEndChild(formulae);

TiXmlElement extralfo("extralfo");
for (int sc = 0; sc < n_scenes; sc++)
{
for (int l = 0; l < n_lfos; l++)
{
TiXmlElement p("lfo");
p.SetAttribute("scene", sc);
p.SetAttribute("i", l);

p.SetAttribute("extraAmplitude", scene[sc].lfo[l].lfoExtraAmplitude);
extralfo.InsertEndChild(p);
}
}
patch.InsertEndChild(extralfo);

TiXmlElement cc("customcontroller");
for (int l = 0; l < n_customcontrollers; l++)
{
Expand Down
6 changes: 6 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,12 @@ struct LFOStorage
Parameter rate, shape, start_phase, magnitude, deform;
Parameter trigmode, unipolar;
Parameter delay, hold, attack, decay, sustain, release;

enum LFOExtraOutputAmplitude
{
UNSCALED,
SCALED
} lfoExtraAmplitude{UNSCALED};
};

struct FxStorage
Expand Down
6 changes: 6 additions & 0 deletions src/common/dsp/modulators/LFOModulationSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,12 @@ void LFOModulationSource::process_block()
output_multi[1] = io2;
output_multi[2] = outputEnvVal + useenv0; // env_val;

if (lfo->lfoExtraAmplitude == LFOStorage::SCALED)
{
output_multi[1] *= magnf;
output_multi[2] *= magnf;
}

if (s == lt_envelope)
{
// Additional start mode corrections required
Expand Down
24 changes: 24 additions & 0 deletions src/surge-xt/gui/widgets/ModulationSourceButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ void ModulationSourceButton::buildHamburgerMenu(juce::PopupMenu &menu,

idx++;
}

if (modsource >= ms_lfo1 && modsource <= ms_slfo6)
{
auto &lf =
sge->getStorage()->getPatch().scene[sge->current_scene].lfo[modsource - ms_lfo1];

auto sh = lf.shape.val.i;
if (sh != lt_formula)
{
menu.addSeparator();
bool sc = lf.lfoExtraAmplitude == LFOStorage::SCALED;
menu.addItem(Surge::GUI::toOSCase("Scale Raw / EG By Amplitude"), true, sc,
[sge, modsource] {
auto &lf = sge->getStorage()
->getPatch()
.scene[sge->current_scene]
.lfo[modsource - ms_lfo1];
if (lf.lfoExtraAmplitude == LFOStorage::SCALED)
lf.lfoExtraAmplitude = LFOStorage::UNSCALED;
else
lf.lfoExtraAmplitude = LFOStorage::SCALED;
});
}
}
}
}

Expand Down

0 comments on commit e3af551

Please sign in to comment.