Skip to content

Commit

Permalink
Rescaler in place for many depth-like knobs (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul authored Jan 2, 2025
1 parent 18c4ca5 commit ec08ccc
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 30 deletions.
2 changes: 1 addition & 1 deletion libs/sst/sst-jucegui
4 changes: 2 additions & 2 deletions src/ui/finetune-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ FineTuneSubPanel::FineTuneSubPanel(SixSinesEditor &e) : HasEditor(e)
depTitle->setText("Tune");
addAndMakeVisible(*depTitle);

createComponent(editor, *this, on.envDepth, envDepth, envDepthD);
createRescaledComponent(editor, *this, on.envDepth, envDepth, envDepthDA);
addAndMakeVisible(*envDepth);
envDepthLL = std::make_unique<jcmp::Label>();
envDepthLL->setText(std::string() + "Env " + u8"\U00002192");
addAndMakeVisible(*envDepthLL);

createComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepD);
createRescaledComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepDA);
addAndMakeVisible(*lfoDep);
lfoDepL = std::make_unique<jcmp::Label>();
lfoDepL->setText(std::string() + "LFO " + u8"\U00002192");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/finetune-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct FineTuneSubPanel : juce::Component,
void beginEdit() {}

std::unique_ptr<jcmp::Knob> envDepth;
std::unique_ptr<PatchContinuous> envDepthD;
std::unique_ptr<PatchContinuous::cubic_t> envDepthDA;
std::unique_ptr<jcmp::Label> envDepthLL;

std::unique_ptr<jcmp::Knob> lfoDep;
std::unique_ptr<PatchContinuous> lfoDepD;
std::unique_ptr<PatchContinuous::cubic_t> lfoDepDA;
std::unique_ptr<jcmp::Label> lfoDepL;

std::unique_ptr<RuledLabel> depTitle;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/main-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MainSubPanel::MainSubPanel(SixSinesEditor &e)
velSenL->setText("Vel Sens");
addAndMakeVisible(*velSenL);

createComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepD);
createRescaledComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepDA);
addAndMakeVisible(*lfoDep);
lfoDepL = std::make_unique<jcmp::Label>();
lfoDepL->setText(std::string() + "LFO " + u8"\U00002192");
Expand Down
3 changes: 2 additions & 1 deletion src/ui/main-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct MainSubPanel : juce::Component,
std::unique_ptr<jcmp::Label> velSenL;

std::unique_ptr<jcmp::Knob> lfoDep;
std::unique_ptr<PatchContinuous> lfoDepD;
std::unique_ptr<PatchContinuous::cubic_t> lfoDepDA;

std::unique_ptr<jcmp::Label> lfoDepL;

std::unique_ptr<RuledLabel> velTitle;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/mainpan-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ MainPanSubPanel::MainPanSubPanel(SixSinesEditor &e) : HasEditor(e)
depTitle->setText("Pan");
addAndMakeVisible(*depTitle);

createComponent(editor, *this, on.envDepth, envDepth, envDepthD);
createRescaledComponent(editor, *this, on.envDepth, envDepth, envDepthDA);
addAndMakeVisible(*envDepth);
envDepthLL = std::make_unique<jcmp::Label>();
envDepthLL->setText(std::string() + "Env " + u8"\U00002192");
addAndMakeVisible(*envDepthLL);

createComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepD);
createRescaledComponent(editor, *this, on.lfoDepth, lfoDep, lfoDepDA);
addAndMakeVisible(*lfoDep);
lfoDepL = std::make_unique<jcmp::Label>();
lfoDepL->setText(std::string() + "LFO " + u8"\U00002192");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/mainpan-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct MainPanSubPanel : juce::Component,
void beginEdit() {}

std::unique_ptr<jcmp::Knob> envDepth;
std::unique_ptr<PatchContinuous> envDepthD;
std::unique_ptr<PatchContinuous::cubic_t> envDepthDA;
std::unique_ptr<jcmp::Label> envDepthLL;

std::unique_ptr<jcmp::Knob> lfoDep;
std::unique_ptr<PatchContinuous> lfoDepD;
std::unique_ptr<PatchContinuous::cubic_t> lfoDepDA;
std::unique_ptr<jcmp::Label> lfoDepL;

std::unique_ptr<RuledLabel> depTitle;
Expand Down
8 changes: 4 additions & 4 deletions src/ui/matrix-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MatrixPanel::MatrixPanel(SixSinesEditor &e) : jcmp::NamedPanel("Matrix"), HasEdi
auto &mn = editor.patchCopy.selfNodes;
for (auto i = 0U; i < numOps; ++i)
{
createComponent(editor, *this, mn[i].fbLevel, Sknobs[i], SknobsData[i], i, true);
createRescaledComponent(editor, *this, mn[i].fbLevel, Sknobs[i], SknobsData[i], i, true);
Sknobs[i]->setDrawLabel(false);
addAndMakeVisible(*Sknobs[i]);

Expand All @@ -39,7 +39,7 @@ MatrixPanel::MatrixPanel(SixSinesEditor &e) : jcmp::NamedPanel("Matrix"), HasEdi
Slabels[i]->setText("Op " + std::to_string(i + 1) + " " + u8"\U000021A9");
addAndMakeVisible(*Slabels[i]);

SknobsData[i]->onPullFromMin = [i, w = juce::Component::SafePointer(this)]()
SknobsData[i]->under->onPullFromMin = [i, w = juce::Component::SafePointer(this)]()
{
if (!w)
return;
Expand All @@ -54,7 +54,7 @@ MatrixPanel::MatrixPanel(SixSinesEditor &e) : jcmp::NamedPanel("Matrix"), HasEdi
auto &mx = editor.patchCopy.matrixNodes;
for (auto i = 0U; i < matrixSize; ++i)
{
createComponent(editor, *this, mx[i].level, Mknobs[i], MknobsData[i], i, false);
createRescaledComponent(editor, *this, mx[i].level, Mknobs[i], MknobsData[i], i, false);
Mknobs[i]->setDrawLabel(false);
addAndMakeVisible(*Mknobs[i]);

Expand All @@ -76,7 +76,7 @@ MatrixPanel::MatrixPanel(SixSinesEditor &e) : jcmp::NamedPanel("Matrix"), HasEdi
Mlabels[i]->setText("Op " + std::to_string(si + 1) + " " + glyph);
addAndMakeVisible(*Mlabels[i]);

MknobsData[i]->onPullFromMin = [i, si, w = juce::Component::SafePointer(this)]()
MknobsData[i]->under->onPullFromMin = [i, si, w = juce::Component::SafePointer(this)]()
{
if (!w)
return;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/matrix-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ struct MatrixPanel : jcmp::NamedPanel, HasEditor
}

std::array<std::unique_ptr<jcmp::Knob>, numOps> Sknobs;
std::array<std::unique_ptr<PatchContinuous>, numOps> SknobsData;
std::array<std::unique_ptr<PatchContinuous::cubic_t>, numOps> SknobsData;
std::array<std::unique_ptr<jcmp::ToggleButton>, numOps> Spower;
std::array<std::unique_ptr<PatchDiscrete>, numOps> SpowerData;
std::array<std::unique_ptr<jcmp::Label>, numOps> Slabels;

std::array<std::unique_ptr<jcmp::Knob>, matrixSize> Mknobs;
std::array<std::unique_ptr<PatchContinuous>, matrixSize> MknobsData;
std::array<std::unique_ptr<PatchContinuous::cubic_t>, matrixSize> MknobsData;
std::array<std::unique_ptr<jcmp::ToggleButton>, matrixSize> Mpower;
std::array<std::unique_ptr<PatchDiscrete>, matrixSize> MpowerData;
std::array<std::unique_ptr<jcmp::MultiSwitch>, matrixSize> Mpmrm;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/matrix-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void MatrixSubPanel::setSelectedIndex(int idx)
setupLFO(editor, m);
setupModulation(editor, m);

createComponent(editor, *this, m.lfoToDepth, lfoToDepth, lfoToDepthD);
createRescaledComponent(editor, *this, m.lfoToDepth, lfoToDepth, lfoToDepthDA);
addAndMakeVisible(*lfoToDepth);
lfoToDepthL = std::make_unique<jcmp::Label>();
lfoToDepthL->setText("Depth");
addAndMakeVisible(*lfoToDepthL);

createComponent(editor, *this, m.envToLevel, envToLev, envToLevD);
createRescaledComponent(editor, *this, m.envToLevel, envToLev, envToLevDA);
addAndMakeVisible(*envToLev);
envToLevL = std::make_unique<jcmp::Label>();
envToLevL->setText("Level");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/matrix-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ struct MatrixSubPanel : juce::Component,
void setSelectedIndex(int idx);

std::unique_ptr<jcmp::Knob> lfoToDepth;
std::unique_ptr<PatchContinuous> lfoToDepthD;
std::unique_ptr<PatchContinuous::cubic_t> lfoToDepthDA;
std::unique_ptr<jcmp::Label> lfoToDepthL;

std::unique_ptr<RuledLabel> modLabelE, modLabelL;
std::unique_ptr<jcmp::Knob> envToLev;
std::unique_ptr<PatchContinuous> envToLevD;
std::unique_ptr<PatchContinuous::cubic_t> envToLevDA;
std::unique_ptr<jcmp::Label> envToLevL;

std::unique_ptr<jcmp::MultiSwitch> envMul;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/mixer-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ void MixerSubPanel::setSelectedIndex(int idx)
setupLFO(editor, sn);
setupModulation(editor, sn);

createComponent(editor, *this, sn.lfoToLevel, lfoToLevel, lfoToLevelD);
createRescaledComponent(editor, *this, sn.lfoToLevel, lfoToLevel, lfoToLevelDA);
addAndMakeVisible(*lfoToLevel);
lfoToLevelL = std::make_unique<jcmp::Label>();
lfoToLevelL->setText("Level");
addAndMakeVisible(*lfoToLevelL);

createComponent(editor, *this, sn.lfoToPan, lfoToPan, lfoToPanD);
createRescaledComponent(editor, *this, sn.lfoToPan, lfoToPan, lfoToPanDA);
addAndMakeVisible(*lfoToPan);
lfoToPanL = std::make_unique<jcmp::Label>();
lfoToPanL->setText("Pan");
addAndMakeVisible(*lfoToPanL);

createComponent(editor, *this, sn.envToLevel, envToLev, envToLevD);
createRescaledComponent(editor, *this, sn.envToLevel, envToLev, envToLevDA);
addAndMakeVisible(*envToLev);
envToLevL = std::make_unique<jcmp::Label>();
envToLevL->setText("Level");
Expand Down
6 changes: 4 additions & 2 deletions src/ui/mixer-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ struct MixerSubPanel : juce::Component,
void setSelectedIndex(int i);

std::unique_ptr<jcmp::Knob> lfoToLevel;
std::unique_ptr<PatchContinuous> lfoToLevelD;
std::unique_ptr<PatchContinuous::cubic_t> lfoToLevelDA;

std::unique_ptr<jcmp::Label> lfoToLevelL;

std::unique_ptr<jcmp::Knob> lfoToPan;
std::unique_ptr<PatchContinuous> lfoToPanD;
std::unique_ptr<PatchContinuous::cubic_t> lfoToPanDA;
std::unique_ptr<jcmp::Label> lfoToPanL;

std::unique_ptr<RuledLabel> modLabelE, modLabelL;
std::unique_ptr<jcmp::Knob> envToLev;
std::unique_ptr<PatchContinuous> envToLevD;
std::unique_ptr<PatchContinuous::cubic_t> envToLevDA;
std::unique_ptr<jcmp::Label> envToLevL;

std::unique_ptr<jcmp::MultiSwitch> envMul;
Expand Down
39 changes: 39 additions & 0 deletions src/ui/patch-data-bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cstdint>
#include "sst/jucegui/data/Continuous.h"
#include "sst/jucegui/data/Discrete.h"
#include <sst/jucegui/component-adapters/ThrowRescaler.h>

#include "sst/jucegui/components/Knob.h"
#include "sst/jucegui/components/DraggableTextEditableValue.h"

Expand Down Expand Up @@ -103,6 +105,8 @@ struct PatchContinuous : jdat::Continuous
void setTemposyncPowerPartner(jdat::Discrete *d) { tsPowerPartner = d; }

std::function<void()> onPullFromMin{nullptr};

using cubic_t = sst::jucegui::component_adapters::CubicThrowRescaler<PatchContinuous>;
};

struct PatchDiscrete : jdat::Discrete
Expand Down Expand Up @@ -197,5 +201,40 @@ void createComponent(SixSinesEditor &e, P &panel, const Param &parm, std::unique
e.componentByID[id] = juce::Component::SafePointer<juce::Component>(cm.get());
}

template <typename P, typename T, typename Rescaler, typename... Args>
void createRescaledComponent(SixSinesEditor &e, P &panel, const Param &parm, std::unique_ptr<T> &cm,
std::unique_ptr<Rescaler> &rc, Args... args)
{
auto id = parm.meta.id;
auto pc = std::make_unique<PatchContinuous>(e, id);
rc = std::make_unique<Rescaler>(std::move(pc));
cm = std::make_unique<T>();

if constexpr (!std::is_same_v<T, jcmp::DraggableTextEditableValue>) // hack
{
cm->onPopupMenu = [&e, ptr = cm.get()](auto &mods)
{
e.hideTooltip();
e.popupMenuForContinuous(ptr);
};
}
cm->onBeginEdit = [&e, &cm, &rc, args..., id, &panel]()
{
e.uiToAudio.push({Synth::UIToAudioMsg::Action::BEGIN_EDIT, id});
e.updateTooltip(rc.get());
e.showTooltipOn(cm.get());

panel.beginEdit(args...);
};
cm->onEndEdit = [&e, id, &panel]()
{
e.uiToAudio.push({Synth::UIToAudioMsg::Action::END_EDIT, id});
e.hideTooltip();
};
cm->setSource(rc.get());

e.componentByID[id] = juce::Component::SafePointer<juce::Component>(cm.get());
}

} // namespace baconpaul::six_sines::ui
#endif // PATCH_CONTINUOUS_H
4 changes: 2 additions & 2 deletions src/ui/self-sub-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ void SelfSubPanel::setSelectedIndex(int idx)
setupLFO(editor, editor.patchCopy.selfNodes[idx]);
setupModulation(editor, editor.patchCopy.selfNodes[idx]);

createComponent(editor, *this, n.lfoToFB, lfoToFb, lfoToFbD);
createRescaledComponent(editor, *this, n.lfoToFB, lfoToFb, lfoToFbDA);
addAndMakeVisible(*lfoToFb);
lfoToFbL = std::make_unique<jcmp::Label>();
lfoToFbL->setText("Depth");
addAndMakeVisible(*lfoToFbL);

createComponent(editor, *this, n.envToFB, envToLev, envToLevD);
createRescaledComponent(editor, *this, n.envToFB, envToLev, envToLevDA);
addAndMakeVisible(*envToLev);
envToLevL = std::make_unique<jcmp::Label>();
envToLevL->setText("Level");
Expand Down
4 changes: 2 additions & 2 deletions src/ui/self-sub-panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ struct SelfSubPanel : juce::Component,
void setSelectedIndex(int idx);

std::unique_ptr<jcmp::Knob> lfoToFb;
std::unique_ptr<PatchContinuous> lfoToFbD;
std::unique_ptr<PatchContinuous::cubic_t> lfoToFbDA;
std::unique_ptr<jcmp::Label> lfoToFbL;

std::unique_ptr<RuledLabel> modLabelE, modLabelL;
std::unique_ptr<jcmp::Knob> envToLev;
std::unique_ptr<PatchContinuous> envToLevD;
std::unique_ptr<PatchContinuous::cubic_t> envToLevDA;
std::unique_ptr<jcmp::Label> envToLevL;

std::unique_ptr<jcmp::MultiSwitch> envMul;
Expand Down

0 comments on commit ec08ccc

Please sign in to comment.