63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#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
|