Skip to content

Commit

Permalink
Add bipolar to unipolar mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Feb 27, 2024
1 parent b768d6c commit eb923a7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modules/gin_plugin/components/gin_assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ juce::String disk = "M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H38
juce::String pencil = "M410.3 231l11.3-11.3-33.9-33.9-62.1-62.1L291.7 89.8l-11.3 11.3-22.6 22.6L58.6 322.9c-10.4 10.4-18 23.3-22.2 37.4L1 480.7c-2.5 8.4-.2 17.5 6.1 23.7s15.3 8.5 23.7 6.1l120.3-35.4c14.1-4.2 27-11.8 37.4-22.2L387.7 253.7 410.3 231zM160 399.4l-9.1 22.7c-4 3.1-8.5 5.4-13.3 6.9L59.4 452l23-78.1c1.4-4.9 3.8-9.4 6.9-13.3l22.7-9.1v32c0 8.8 7.2 16 16 16h32zM362.7 18.7L348.3 33.2 325.7 55.8 314.3 67.1l33.9 33.9 62.1 62.1 33.9 33.9 11.3-11.3 22.6-22.6 14.5-14.5c25-25 25-65.5 0-90.5L453.3 18.7c-25-25-65.5-25-90.5 0zm-47.4 168l-144 144c-6.2 6.2-16.4 6.2-22.6 0s-6.2-16.4 0-22.6l144-144c6.2-6.2 16.4-6.2 22.6 0s6.2 16.4 0 22.6z";
juce::String undo = "M48.5 224H40c-13.3 0-24-10.7-24-24V72c0-9.7 5.8-18.5 14.8-22.2s19.3-1.7 26.2 5.2L98.6 96.6c87.6-86.5 228.7-86.2 315.8 1c87.5 87.5 87.5 229.3 0 316.8s-229.3 87.5-316.8 0c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0c62.5 62.5 163.8 62.5 226.3 0s62.5-163.8 0-226.3c-62.2-62.2-162.7-62.5-225.3-1L185 183c6.9 6.9 8.9 17.2 5.2 26.2s-12.5 14.8-22.2 14.8H48.5z";
juce::String redo = "M463.5 224H472c13.3 0 24-10.7 24-24V72c0-9.7-5.8-18.5-14.8-22.2s-19.3-1.7-26.2 5.2L413.4 96.6c-87.6-86.5-228.7-86.2-315.8 1c-87.5 87.5-87.5 229.3 0 316.8s229.3 87.5 316.8 0c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0c-62.5 62.5-163.8 62.5-226.3 0s-62.5-163.8 0-226.3c62.2-62.2 162.7-62.5 225.3-1L327 183c-6.9 6.9-8.9 17.2-5.2 26.2s12.5 14.8 22.2 14.8H463.5z";

juce::String bipolar = "M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm144-64L256 96l112 96v32H144V192zm0 96h32H336h32v32L256 416 144 320V288zm112 85.9L318.8 320H193.2L256 373.9z";
}
1 change: 1 addition & 0 deletions modules/gin_plugin/components/gin_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ extern juce::String disk;
extern juce::String pencil;
extern juce::String undo;
extern juce::String redo;
extern juce::String bipolar;
}
27 changes: 25 additions & 2 deletions modules/gin_plugin/components/gin_modulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class ModCurveButton : public juce::Button
juce::Path p;
for (auto x = 0.0f; x <= rc.getWidth(); x += 0.5f)
{
auto y = (1.0f - ModMatrix::shape (x / rc.getWidth(), curve, false)) * rc.getHeight();
auto y = (1.0f - ModMatrix::shape (x / rc.getWidth(), curve, false, false)) * rc.getHeight();

if (x == 0.0f)
p.startNewSubPath (rc.getX() + x, rc.getY() + y);
Expand Down Expand Up @@ -424,12 +424,14 @@ class ModMatrixBox : public juce::ListBox,
addAndMakeVisible (enableButton);
addAndMakeVisible (deleteButton);
addAndMakeVisible (curveButton);
addAndMakeVisible (biUniButton);
addAndMakeVisible (depth);
addAndMakeVisible (src);
addAndMakeVisible (dst);

depth.setRange (-1.0, 1.0, 0.01);
depth.getProperties().set ("fromCentre", true);
depth.getProperties().set ("fullRect", true);
depth.addListener (this);
depth.setSliderSnapsToMousePosition (false);
depth.setMouseDragSensitivity (750);
Expand All @@ -447,6 +449,18 @@ class ModMatrixBox : public juce::ListBox,
enableButton.setToggleState (! e, juce::dontSendNotification);
}
};

biUniButton.onClick = [this]
{
if (row >= 0 && row < owner.assignments.size())
{
auto& a = owner.assignments.getReference (row);

auto e = owner.modMatrix.getModBiToUni (a.src, ModDstId (a.dst->getModIndex()));
owner.modMatrix.setModBiToUni (a.src, ModDstId (a.dst->getModIndex()), ! e);
biUniButton.setToggleState (! e, juce::dontSendNotification);
}
};

deleteButton.onClick = [this]
{
Expand Down Expand Up @@ -521,6 +535,10 @@ class ModMatrixBox : public juce::ListBox,
auto e = owner.modMatrix.getModEnable (a.src, ModDstId (a.dst->getModIndex()));
enableButton.setToggleState (e, juce::dontSendNotification);

auto b = owner.modMatrix.getModBiToUni (a.src, ModDstId (a.dst->getModIndex()));
biUniButton.setToggleState (b, juce::dontSendNotification);
biUniButton.setVisible (owner.modMatrix.getModSrcBipolar (a.src));

depth.setValue (owner.modMatrix.getModDepth (a.src, ModDstId (a.dst->getModIndex())));
curveButton.setCurve (owner.modMatrix.getModFunction (a.src, ModDstId (a.dst->getModIndex())));
}
Expand All @@ -539,9 +557,13 @@ class ModMatrixBox : public juce::ListBox,
int h = rc.getHeight();

enableButton.setBounds (rc.removeFromLeft (h));
rc.removeFromLeft (4);
deleteButton.setBounds (rc.removeFromRight (h));
rc.removeFromLeft (2);
depth.setBounds (rc.removeFromLeft (owner.depthWidth));
rc.removeFromLeft (4);
biUniButton.setBounds (rc.removeFromLeft (h));
rc.removeFromLeft (2);
curveButton.setBounds (rc.removeFromLeft (h));

int w = rc.getWidth() / 2;
Expand All @@ -558,8 +580,9 @@ class ModMatrixBox : public juce::ListBox,
juce::Label dst;

ModCurveButton curveButton;
SVGButton biUniButton { "biuni", Assets::bipolar };

SVGButton enableButton { "enable", Assets::power };
SVGButton enableButton { "enable", Assets::power, 1 };
SVGButton deleteButton { "delete", Assets::del };
};

Expand Down
23 changes: 23 additions & 0 deletions modules/gin_plugin/plugin/gin_modmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void ModMatrix::stateUpdated (const juce::ValueTree& vt)
auto f = float (c.getProperty ("depth", 0.0f));
auto e = bool (c.getProperty ("enabled", true));
auto z = strToFunc (c.getProperty ("function", "linear"));
auto b = bool (c.getProperty ("biPolarToUniPolar", false));

if (src.isNotEmpty() && dst.isNotEmpty())
{
Expand All @@ -103,6 +104,7 @@ void ModMatrix::stateUpdated (const juce::ValueTree& vt)
s.depth = f;
s.enabled = e;
s.function = z;
s.biPolarToUniPolar = b;

auto foundParam = false;
for (auto& pi : parameters)
Expand Down Expand Up @@ -142,6 +144,7 @@ void ModMatrix::updateState (juce::ValueTree& vt)
c.setProperty ("enabled", src.enabled, nullptr);
c.setProperty ("dstId", pi.parameter->getUid(), nullptr);
c.setProperty ("function", funcToStr (src.function), nullptr);
c.setProperty ("biPolarToUniPolar", src.depth, nullptr);

mm.addChild (c, -1, nullptr);
}
Expand Down Expand Up @@ -269,6 +272,26 @@ void ModMatrix::setModEnable (ModSrcId src, ModDstId param, bool b)
listeners.call ([&] (Listener& l) { l.modMatrixChanged(); });
}

bool ModMatrix::getModBiToUni (ModSrcId src, ModDstId param)
{
auto& pi = parameters.getReference (param.id);
for (auto& si : pi.sources)
if (si.id == src)
return si.biPolarToUniPolar;

return false;
}

void ModMatrix::setModBiToUni (ModSrcId src, ModDstId param, bool b)
{
auto& pi = parameters.getReference (param.id);
for (auto& si : pi.sources)
if (si.id == src)
si.biPolarToUniPolar = b;

listeners.call ([&] (Listener& l) { l.modMatrixChanged(); });
}

float ModMatrix::getModDepth (ModSrcId src, ModDstId param)
{
auto& pi = parameters.getReference (param.id);
Expand Down
32 changes: 19 additions & 13 deletions modules/gin_plugin/plugin/gin_modmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ class ModMatrix
invExponentialOut,
};

static float shape (float v, Function f, bool bipolar)
static float shape (float v, Function f, bool bipolar, bool biPolarToUniPolar)
{
if (bipolar)
if (biPolarToUniPolar)
v = (v + 1.0f) * 2.0f;
else if (bipolar)
v = juce::jmap (v, -1.0f, 1.0f, 0.0f, 1.0f);

switch (f)
Expand Down Expand Up @@ -189,7 +191,7 @@ class ModMatrix
break;
}

if (bipolar)
if (! biPolarToUniPolar && bipolar)
v = juce::jmap (v, 0.0f, 1.0f, -1.0f, 1.0f);

return v;
Expand All @@ -208,9 +210,9 @@ class ModMatrix
if (src.enabled)
{
if (src.poly && activeVoice != nullptr)
base += shape (activeVoice->values[src.id.id], src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (activeVoice->values[src.id.id], src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
else if (! src.poly)
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
}
}

Expand Down Expand Up @@ -241,9 +243,9 @@ class ModMatrix
if (src.enabled)
{
if (src.poly)
base += shape (voice.values[src.id.id], src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (voice.values[src.id.id], src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
else
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
}
}

Expand Down Expand Up @@ -284,9 +286,9 @@ class ModMatrix
if (src.enabled)
{
if (src.poly)
base += shape (v->values[src.id.id], src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (v->values[src.id.id], src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
else
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
ok = true;
}
}
Expand All @@ -308,7 +310,7 @@ class ModMatrix
{
if (src.enabled && ! src.poly)
{
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
ok = true;
}
}
Expand All @@ -335,12 +337,12 @@ class ModMatrix
if (src.poly && v != nullptr)
{
ok = true;
base += shape (v->values[src.id.id], src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (v->values[src.id.id], src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
}
else if (! src.poly)
{
ok = true;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar) * src.depth;
base += shape (sources[src.id.id].monoValue, src.function, sources[src.id.id].bipolar, src.biPolarToUniPolar) * src.depth;
}
}
}
Expand Down Expand Up @@ -409,9 +411,12 @@ class ModMatrix

Function getModFunction (ModSrcId src, ModDstId param);
void setModFunction (ModSrcId src, ModDstId param, Function f);

bool getModEnable (ModSrcId src, ModDstId param);
void setModEnable (ModSrcId src, ModDstId param, bool b);

bool getModBiToUni (ModSrcId src, ModDstId param);
void setModBiToUni (ModSrcId src, ModDstId param, bool b);

//==============================================================================
bool shouldShowLiveModValues()
Expand Down Expand Up @@ -469,6 +474,7 @@ class ModMatrix
bool poly = false;
bool enabled = true;
float depth = 0.0f;
bool biPolarToUniPolar = false;
Function function = ModMatrix::Function::linear;
};

Expand Down

0 comments on commit eb923a7

Please sign in to comment.