85 lines
2.3 KiB
C++
85 lines
2.3 KiB
C++
#include "MacroControls.h"
|
|
|
|
namespace serum
|
|
{
|
|
|
|
bool MacroControls::addAssignment (int macro, ModTarget target, float depth)
|
|
{
|
|
macro = juce::jlimit (0, kNumMacros - 1, macro);
|
|
if (target == ModTarget::None || (int) assignments[(size_t) macro].size() >= kMaxAssignments)
|
|
return false;
|
|
assignments[(size_t) macro].push_back ({ target, depth });
|
|
return true;
|
|
}
|
|
|
|
void MacroControls::removeAssignment (int macro, int index)
|
|
{
|
|
macro = juce::jlimit (0, kNumMacros - 1, macro);
|
|
auto& vec = assignments[(size_t) macro];
|
|
if (index >= 0 && index < (int) vec.size())
|
|
vec.erase (vec.begin() + index);
|
|
}
|
|
|
|
void MacroControls::clear()
|
|
{
|
|
for (auto& a : assignments)
|
|
a.clear();
|
|
}
|
|
|
|
juce::String MacroControls::macroName (int index)
|
|
{
|
|
switch (index)
|
|
{
|
|
case 0: return "Energy";
|
|
case 1: return "Width";
|
|
case 2: return "Drive";
|
|
case 3: return "Atmosphere";
|
|
default: return {};
|
|
}
|
|
}
|
|
|
|
juce::ValueTree MacroControls::toValueTree() const
|
|
{
|
|
juce::ValueTree tree ("MACROS");
|
|
for (int m = 0; m < kNumMacros; ++m)
|
|
{
|
|
juce::ValueTree mac ("MACRO");
|
|
mac.setProperty ("index", m, nullptr);
|
|
for (const auto& a : assignments[(size_t) m])
|
|
{
|
|
juce::ValueTree asg ("ASSIGN");
|
|
asg.setProperty ("target", modTargetToString (a.target), nullptr);
|
|
asg.setProperty ("depth", a.depth, nullptr);
|
|
mac.appendChild (asg, nullptr);
|
|
}
|
|
tree.appendChild (mac, nullptr);
|
|
}
|
|
return tree;
|
|
}
|
|
|
|
void MacroControls::fromValueTree (const juce::ValueTree& tree)
|
|
{
|
|
clear();
|
|
if (! tree.isValid())
|
|
return;
|
|
|
|
for (const auto& mac : tree)
|
|
{
|
|
if (! mac.hasType ("MACRO"))
|
|
continue;
|
|
const int index = juce::jlimit (0, kNumMacros - 1, (int) mac.getProperty ("index", 0));
|
|
for (const auto& asg : mac)
|
|
{
|
|
if (! asg.hasType ("ASSIGN"))
|
|
continue;
|
|
MacroAssignment a;
|
|
a.target = modTargetFromString (asg.getProperty ("target").toString());
|
|
a.depth = (float) asg.getProperty ("depth", 0.0);
|
|
if (a.target != ModTarget::None)
|
|
assignments[(size_t) index].push_back (a);
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace serum
|