feat(modulation): add envelopes, LFOs and modulation matrix

This commit is contained in:
2026-09-08 14:55:21 +02:00
parent fc9d16b302
commit 44960b9acb
6 changed files with 458 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
#include "ModulationMatrix.h"
namespace serum
{
bool ModulationMatrix::addConnection (ModSource source, ModTarget target, float depth, bool bipolar)
{
if (target == ModTarget::None || (int) connections.size() >= kMaxConnections)
return false;
connections.push_back ({ source, target, depth, bipolar });
return true;
}
void ModulationMatrix::removeConnection (int index)
{
if (index >= 0 && index < (int) connections.size())
connections.erase (connections.begin() + index);
}
void ModulationMatrix::removeAllWithTarget (ModTarget target)
{
connections.erase (std::remove_if (connections.begin(), connections.end(),
[target] (const ModConnection& c) { return c.target == target; }),
connections.end());
}
juce::ValueTree ModulationMatrix::toValueTree() const
{
juce::ValueTree tree ("MODMATRIX");
for (const auto& c : connections)
{
juce::ValueTree con ("CONNECTION");
con.setProperty ("source", modSourceToString (c.source), nullptr);
con.setProperty ("target", modTargetToString (c.target), nullptr);
con.setProperty ("depth", c.depth, nullptr);
con.setProperty ("bipolar", c.bipolar, nullptr);
tree.appendChild (con, nullptr);
}
return tree;
}
void ModulationMatrix::fromValueTree (const juce::ValueTree& tree)
{
connections.clear();
if (! tree.isValid())
return;
for (const auto& con : tree)
{
if (! con.hasType ("CONNECTION"))
continue;
ModConnection c;
c.source = modSourceFromString (con.getProperty ("source").toString());
c.target = modTargetFromString (con.getProperty ("target").toString());
c.depth = (float) con.getProperty ("depth", 0.0);
c.bipolar = (bool) con.getProperty ("bipolar", false);
if (c.target != ModTarget::None && (int) connections.size() < kMaxConnections)
connections.push_back (c);
}
}
} // namespace serum