Skip to content

Commit

Permalink
Clean up a bunch of ui; add lfo mul
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Dec 22, 2024
1 parent 0838788 commit 169245b
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 52 deletions.
26 changes: 20 additions & 6 deletions src/dsp/matrix_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ struct MatrixNodeSelf : EnvelopeSupport<Patch::SelfNode>, LFOSupport<Patch::Self
{
OpSource &onto;
SRProvider sr;
const float &fbBase, &lfoToFB, &activeV;
const float &fbBase, &lfoToFB, &activeV, &lfoMulV;
MatrixNodeSelf(const Patch::SelfNode &sn, OpSource &on)
: onto(on), fbBase(sn.fbLevel), lfoToFB(sn.lfoToFB), activeV(sn.active),
EnvelopeSupport(sn), LFOSupport(sn){};
bool active{true};
lfoMulV(sn.envLfoSum), EnvelopeSupport(sn), LFOSupport(sn){};
bool active{true}, lfoMul{false};

void attack()
{
active = activeV > 0.5;
lfoMul = lfoMulV > 0.5;
if (active)
{
envAttack();
Expand All @@ -124,10 +125,23 @@ struct MatrixNodeSelf : EnvelopeSupport<Patch::SelfNode>, LFOSupport<Patch::Self

envProcess(gated);
lfoProcess();
for (int j = 0; j < blockSize; ++j)
if (lfoMul)
{
for (int j = 0; j < blockSize; ++j)
{
onto.feedbackLevel[j] =
(int32_t)((1 << 24) * (env.outputCache[j] * lfoToFB * lfo.outputBlock[j]) *
fbBase);
}
}
else
{
onto.feedbackLevel[j] =
(int32_t)((1 << 24) * (env.outputCache[j] + lfoToFB * lfo.outputBlock[j]) * fbBase);
for (int j = 0; j < blockSize; ++j)
{
onto.feedbackLevel[j] =
(int32_t)((1 << 24) * (env.outputCache[j] + lfoToFB * lfo.outputBlock[j]) *
fbBase);
}
}
}
};
Expand Down
9 changes: 6 additions & 3 deletions src/dsp/op_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct alignas(16) OpSource : public EnvelopeSupport<Patch::SourceNode>,
float output alignas(16)[blockSize];

bool keytrack{true};
const float &ratio, &activeV, &envToRatio, &lfoToRatio; // in frequency multiple
const float &ratio, &activeV, &envToRatio, &lfoToRatio, &lfoByEnv; // in frequency multiple
bool active{false};

// todo waveshape
Expand All @@ -47,7 +47,7 @@ struct alignas(16) OpSource : public EnvelopeSupport<Patch::SourceNode>,

OpSource(const Patch::SourceNode &sn)
: EnvelopeSupport(sn), LFOSupport(sn), ratio(sn.ratio), activeV(sn.active),
envToRatio(sn.envToRatio), lfoToRatio(sn.lfoToRatio)
envToRatio(sn.envToRatio), lfoToRatio(sn.lfoToRatio), lfoByEnv(sn.envLfoSum)
{
reset();
}
Expand Down Expand Up @@ -90,7 +90,10 @@ struct alignas(16) OpSource : public EnvelopeSupport<Patch::SourceNode>,
}
envProcess(gated);
lfoProcess();
auto rf = pow(2.f, ratio + envToRatio * env.output + lfoToRatio * lfo.outputBlock[0]);
auto lfoFac = lfoByEnv > 0.5 ? env.output : 1.f;

auto rf =
pow(2.f, ratio + envToRatio * env.output + lfoFac * lfoToRatio * lfo.outputBlock[0]);

for (int i = 0; i < blockSize; ++i)
{
Expand Down
32 changes: 24 additions & 8 deletions src/synth/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct Patch
attack(floatEnvRateMd()
.withName(name + " Env Attack")
.withGroupName(name)
.withDefault(longAdsr ? -1.f : tsr::etMin)
.withDefault(longAdsr ? -7.f : tsr::etMin)
.withID(id0 + 1)),
hold(floatEnvRateMd()
.withName(name + " Env Hold")
Expand All @@ -198,7 +198,7 @@ struct Patch
decay(floatEnvRateMd()
.withName(name + " Env Decay")
.withGroupName(name)
.withDefault(longAdsr ? 1.f : tsr::etMin)
.withDefault(longAdsr ? 0.f : tsr::etMin)
.withID(id0 + 3)),
sustain(floatMd()
.asPercent()
Expand All @@ -209,7 +209,7 @@ struct Patch
release(floatEnvRateMd()
.withName(name + " Env Release")
.withGroupName(name)
.withDefault(longAdsr ? 0.5f : tsr::etMax)
.withDefault(longAdsr ? -2.f : tsr::etMax)
.withID(id0 + 5)),
envPower(boolMd()
.withName(name + " Env Power")
Expand Down Expand Up @@ -248,7 +248,7 @@ struct Patch
active(boolMd()
.withGroupName(name(idx))
.withName(name(idx) + " Active")
.withDefault(1.0)
.withDefault(idx == 0)
.withID(id(1, idx))),
envToRatio(floatMd()
.withRange(-2, 2)
Expand All @@ -266,6 +266,13 @@ struct Patch
.withDecimalPlaces(4)
.withDefault(0.f)
.withID(id(3, idx))),
envLfoSum(intMd()
.withName(name(idx) + " LFO Env Sum")
.withGroupName(name(idx))
.withID(id(4, idx))
.withRange(0, 1)
.withDefault(0)
.withUnorderedMapFormatting({{0, "+"}, {1, "x"}})),

DAHDSRMixin(name(idx), id(100, idx), false), LFOMixin(name(idx), id(45, idx))
{
Expand All @@ -279,10 +286,11 @@ struct Patch

Param envToRatio;
Param lfoToRatio;
Param envLfoSum;

std::vector<Param *> params()
{
std::vector<Param *> res{&ratio, &active, &envToRatio, &lfoToRatio};
std::vector<Param *> res{&ratio, &active, &envToRatio, &lfoToRatio, &envLfoSum};
appendDAHDSRParams(res);
appendLFOParams(res);
return res;
Expand Down Expand Up @@ -310,19 +318,27 @@ struct Patch
.withName(name(idx) + " LFO to FB Amplitude")
.withGroupName(name(idx))
.withDefault(0.0)
.withID(id(25, idx)))
.withID(id(25, idx))),
envLfoSum(intMd()
.withName(name(idx) + " LFO Env Sum")
.withGroupName(name(idx))
.withID(id(26, idx))
.withRange(0, 1)
.withDefault(0)
.withUnorderedMapFormatting({{0, "+"}, {1, "x"}}))

{
}

std::string name(int idx) const { return "Op " + std::to_string(idx + 1) + " Feedback"; }
uint32_t id(int f, int idx) const { return idBase + idStride * idx + f; }

Param fbLevel, lfoToFB;
Param fbLevel, lfoToFB, envLfoSum;
Param active;

std::vector<Param *> params()
{
std::vector<Param *> res{&fbLevel, &active, &lfoToFB};
std::vector<Param *> res{&fbLevel, &active, &lfoToFB, &envLfoSum};
appendDAHDSRParams(res);
appendLFOParams(res);
return res;
Expand Down
29 changes: 21 additions & 8 deletions src/ui/dahdsr-components.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sst/jucegui/components/Label.h>
#include "patch-data-bindings.h"
#include "ui-constants.h"
#include "ruled-label.h"

namespace baconpaul::six_sines::ui
{
Expand All @@ -40,22 +41,32 @@ template <typename Comp, typename Patch> struct DAHDSRComponents
c->addAndMakeVisible(*slider[idx]);
c->addAndMakeVisible(*lab[idx]);
};
mk(v.delay.meta.id, 0, "del");
mk(v.attack.meta.id, 1, "atk");
mk(v.hold.meta.id, 2, "hld");
mk(v.decay.meta.id, 3, "dcy");
mk(v.sustain.meta.id, 4, "sus");
mk(v.release.meta.id, 5, "rel");
mk(v.delay.meta.id, 0, "D");
mk(v.attack.meta.id, 1, "A");
mk(v.hold.meta.id, 2, "H");
mk(v.decay.meta.id, 3, "D");
mk(v.sustain.meta.id, 4, "S");
mk(v.release.meta.id, 5, "R");

titleLab = std::make_unique<RuledLabel>();
titleLab->setText("Envelope");
asComp()->addAndMakeVisible(*titleLab);
}

juce::Rectangle<int> layoutDAHDSRAt(int x, int y)
{
if (!titleLab)
return {};

auto lh = uicTitleLabelHeight;
auto c = asComp();
auto h = c->getHeight() - y;
auto q = h - uicLabelHeight - uicLabelGap;
auto q = h - uicLabelHeight - uicLabelGap - lh;
auto w = uicSliderWidth;

auto bx = juce::Rectangle<int>(x, y, w, h);
positionTitleLabelAt(x, y, nels * uicSliderWidth, titleLab);

auto bx = juce::Rectangle<int>(x, y + lh, w, h - lh);
for (int i = 0; i < nels; ++i)
{
if (!slider[i])
Expand All @@ -64,13 +75,15 @@ template <typename Comp, typename Patch> struct DAHDSRComponents
lab[i]->setBounds(bx.withTrimmedTop(q + uicLabelGap));
bx = bx.translated(uicSliderWidth, 0);
}
bx = bx.translated(-uicSliderWidth, 0);
return juce::Rectangle<int>(x, y, 0, 0).withLeft(bx.getRight()).withBottom(bx.getBottom());
}

static constexpr int nels{6}; // dahdsr
std::array<std::unique_ptr<jcmp::VSlider>, nels> slider;
std::array<std::unique_ptr<PatchContinuous>, nels> sliderD;
std::array<std::unique_ptr<jcmp::Label>, nels> lab;
std::unique_ptr<RuledLabel> titleLab;
};
} // namespace baconpaul::six_sines::ui
#endif // DAHDSR_COMPONENTS_H
20 changes: 16 additions & 4 deletions src/ui/lfo-components.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sst/jucegui/components/MultiSwitch.h>
#include "patch-data-bindings.h"
#include "ui-constants.h"
#include "ruled-label.h"

namespace baconpaul::six_sines::ui
{
Expand All @@ -47,24 +48,34 @@ template <typename Comp, typename Patch> struct LFOComponents

createComponent(e, *c, v.lfoShape.meta.id, shape, shapeD);
c->addAndMakeVisible(*shape);

titleLab = std::make_unique<RuledLabel>();
titleLab->setText("LFO");
c->addAndMakeVisible(*titleLab);
}

juce::Rectangle<int> layoutLFOAt(int x, int y)
juce::Rectangle<int> layoutLFOAt(int x, int y, int extraWidth = 0)
{
if (!titleLab)
return {};

auto c = asComp();
auto lh = uicTitleLabelHeight;
auto h = c->getHeight() - y;
auto q = h;
auto q = h - lh;
auto w = uicKnobSize * 1.5;

auto bx = juce::Rectangle<int>(x, y, w, h);
positionTitleLabelAt(x, y, w + uicMargin + uicKnobSize + extraWidth, titleLab);

auto bx = juce::Rectangle<int>(x, y + lh, w, h - lh);
shape->setBounds(bx.withHeight(2 * uicLabeledKnobHeight + uicMargin));

bx = bx.translated(w + uicMargin, 0);
positionKnobAndLabel(bx.getX(), bx.getY(), rate, rateL);
positionKnobAndLabel(bx.getX(), bx.getY() + uicLabeledKnobHeight + uicMargin, deform,
deformL);
bx = bx.translated(uicKnobSize + uicMargin, 0);
return juce::Rectangle<int>(x + w + uicKnobSize + uicMargin, y, 0, 0)
return juce::Rectangle<int>(x + w + uicKnobSize + uicMargin + extraWidth, y, 0, 0)
.withBottom(bx.getBottom());
}

Expand All @@ -74,6 +85,7 @@ template <typename Comp, typename Patch> struct LFOComponents

std::unique_ptr<jcmp::MultiSwitch> shape;
std::unique_ptr<PatchDiscrete> shapeD;
std::unique_ptr<RuledLabel> titleLab;
};
} // namespace baconpaul::six_sines::ui
#endif // LFO_COMPONENTS_H
18 changes: 10 additions & 8 deletions src/ui/matrix-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MatrixSubPanel::setSelectedIndex(int idx)

createComponent(editor, *this, m.envLfoSum.meta.id, lfoMul, lfoMulD);
addAndMakeVisible(*lfoMul);
lfoMul->direction = jcmp::MultiSwitch::HORIZONTAL;
lfoMul->direction = jcmp::MultiSwitch::VERTICAL;

resized();

Expand All @@ -47,13 +47,15 @@ void MatrixSubPanel::setSelectedIndex(int idx)
void MatrixSubPanel::resized()
{
auto p = getLocalBounds().reduced(uicMargin, 0);
auto r = layoutDAHDSRAt(p.getX(), p.getY());
r = layoutLFOAt(r.getX() + uicMargin, p.getY());
positionKnobAndLabel(r.getX() + uicMargin, r.getY(), lfoToDepth, lfoToDepthL);

auto bx =
lfoToDepthL->getBounds().translated(0, lfoToDepthL->getHeight() + uicMargin).withHeight(30);
lfoMul->setBounds(bx);
auto pn = layoutDAHDSRAt(p.getX(), p.getY());
auto gh = (pn.getHeight() - 2 * uicPowerButtonSize) / 2;
lfoMul->setBounds(pn.getX() + uicMargin, pn.getY() + gh, uicPowerButtonSize,
2 * uicPowerButtonSize);
pn = pn.translated(2 * uicMargin + uicPowerButtonSize, 0);
auto r = layoutLFOAt(pn.getX(), p.getY(), uicMargin + uicKnobSize);

positionKnobAndLabel(r.getX() - uicKnobSize, r.getY() + uicTitleLabelHeight, lfoToDepth,
lfoToDepthL);
}

} // namespace baconpaul::six_sines::ui
52 changes: 52 additions & 0 deletions src/ui/ruled-label.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Six Sines
*
* A synth with audio rate modulation.
*
* Copyright 2024, Paul Walker and Various authors, as described in the github
* transaction log.
*
* This source repo is released under the MIT license, but has
* GPL3 dependencies, as such the combined work will be
* released under GPL3.
*
* The source code and license are at https://github.com/baconpaul/six-sines
*/

#ifndef BACONPAUL_SIX_SINES_UI_RULED_LABEL_H
#define BACONPAUL_SIX_SINES_UI_RULED_LABEL_H

#include <sst/jucegui/components/Label.h>
#include "ui-constants.h"

// This really belongs in jucegui
namespace baconpaul::six_sines::ui
{
struct RuledLabel : sst::jucegui::components::Label
{
RuledLabel() : sst::jucegui::components::Label()
{
setJustification(juce::Justification::centred);
}

void paint(juce::Graphics &g) override
{
g.setColour(getColour(Styles::labelcolor));
if (!isEnabled())
g.setColour(getColour(Styles::labelcolor).withAlpha(0.5f));
auto ft = getFont(Styles::labelfont);
g.setFont(ft);
g.drawText(text, getLocalBounds(), justification);
auto w = juce::GlyphArrangement::getStringWidth(ft, text);
auto lc =
style()->getColour(sst::jucegui::components::base_styles::Outlined::styleClass,
sst::jucegui::components::base_styles::Outlined::brightoutline);
g.setColour(lc);
g.drawLine(0, getHeight() / 2, getWidth() / 2 - w / 2 - uicMargin, getHeight() / 2);
g.drawLine(getWidth() / 2 + w / 2 + uicMargin, getHeight() / 2, getWidth(),
getHeight() / 2);
}
};

} // namespace baconpaul::six_sines::ui
#endif // RULED_LABEL_H
Loading

0 comments on commit 169245b

Please sign in to comment.