Skip to content

Commit

Permalink
Modulation Source Menu set up and displayed
Browse files Browse the repository at this point in the history
but doesn't set anything yet. That's next.
  • Loading branch information
baconpaul committed Dec 29, 2024
1 parent 6c270c3 commit eeea48e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/synth/mod_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
*/

#include "mod_matrix.h"
#include "sst/cpputils/constructors.h"
#include <fmt/core.h>

namespace baconpaul::six_sines
{
ModMatrixConfig::ModMatrixConfig()
{
add(OFF, "", "OFF");
add(OFF, "", "Off");
add(CHANNEL_AT, "MIDI", "Channel AT");
add(PITCH_BEND, "MIDI", "Pitch Bend");

for (int cc = 0; cc < 128; ++cc)
add(MIDICC_0 + cc, "MIDI CC", "CC " + std::to_string(cc + 1));
add(MIDICC_0 + cc, "MIDI CC", fmt::format("CC {:03d}", cc + 1));
for (int mc = 0; mc < numMacros; ++mc)
add(MACRO_0 + mc, "Macros", "Macro " + std::to_string(mc + 1));

Expand All @@ -37,8 +37,25 @@ ModMatrixConfig::ModMatrixConfig()

add(MPE_PRESSURE, "MPE", "Pressure");
add(MPE_TIMBRE, "MPE", "Timbre");

std::sort(sources.begin(), sources.end(),
[](const SourceObj &a, const SourceObj &b)
{
if (a.group != b.group)
return a.group < b.group;
if (a.name != b.name)
return a.name < b.name;
return a.id < b.id;
});
for (auto &s : sources)
{
sourceByID[s.id] = s;
}
}

void ModMatrixConfig::add(int s, const std::string &group, const std::string &nm) {}
void ModMatrixConfig::add(int s, const std::string &group, const std::string &nm)
{
sources.push_back({s, group, nm});
}

} // namespace baconpaul::six_sines
8 changes: 8 additions & 0 deletions src/synth/mod_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ struct ModMatrixConfig
ModMatrixConfig();

void add(int s, const std::string &group, const std::string &nm);
struct SourceObj
{
int id;
std::string group;
std::string name;
};
std::vector<SourceObj> sources;
std::unordered_map<uint32_t, SourceObj> sourceByID;
};
} // namespace baconpaul::six_sines
#endif // MOD_MATRIX_H
62 changes: 61 additions & 1 deletion src/ui/modulation-components.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ template <typename Comp, typename Patch> struct ModulationComponents
{
Comp *asComp() { return static_cast<Comp *>(this); }
ModulationComponents() {}

const Patch *patchPtr{nullptr};
void setupModulation(SixSinesEditor &e, const Patch &v)
{
patchPtr = &v;
auto c = asComp();
modTitleLab = std::make_unique<RuledLabel>();
modTitleLab->setText("Modulation");
Expand All @@ -42,6 +45,13 @@ template <typename Comp, typename Patch> struct ModulationComponents
createComponent(e, *c, v.moddepth[i], depthSlider[i], depthSliderD[i]);
sourceMenu[i] = std::make_unique<jcmp::MenuButton>();
resetSourceLabel(i);
sourceMenu[i]->setOnCallback(
[w = juce::Component::SafePointer(asComp())]()
{
if (!w)
return;
w->showSourceMenu();
});
e.componentRefreshByID[v.modsource[i].meta.id] =
[i, w = juce::Component::SafePointer(c)]()
{
Expand All @@ -67,7 +77,25 @@ template <typename Comp, typename Patch> struct ModulationComponents
}
}

void resetSourceLabel(int i) { sourceMenu[i]->setLabel("Src " + std::to_string(i + 1)); }
void resetSourceLabel(int i)
{
if (!patchPtr)
{
sourceMenu[i]->setLabel("");
return;
}
auto v = (uint32_t)std::round(patchPtr->modsource[i].value);

auto p = asComp()->editor.modMatrixConfig.sourceByID.find(v);
if (p != asComp()->editor.modMatrixConfig.sourceByID.end())
{
sourceMenu[i]->setLabel(p->second.name);
}
else
{
sourceMenu[i]->setLabel("UNK " + std::to_string(v));
}
}

void resetTargetLabel(int i) { targetMenu[i]->setLabel("Tgt " + std::to_string(i + 1)); }

Expand All @@ -93,6 +121,38 @@ template <typename Comp, typename Patch> struct ModulationComponents
}
}

void showSourceMenu()
{
SXSNLOG("Show Source Menu");
auto p = juce::PopupMenu();
p.addSectionHeader("Modulation Source");
p.addSeparator();
std::string currCat{};
auto s = juce::PopupMenu();
for (const auto &so : asComp()->editor.modMatrixConfig.sources)
{
if (so.group.empty())
{
p.addItem(so.name, [i = so.id]() { SXSNLOG("With " << i); });
}
else
{
if (so.group != currCat && s.getNumItems() > 0)
{
p.addSubMenu(currCat, s);
s = juce::PopupMenu();
}
currCat = so.group;
s.addItem(so.name, [i = so.id]() { SXSNLOG("With " << i); });
}
}
if (s.getNumItems() > 0)
{
p.addSubMenu(currCat, s);
}
p.showMenuAsync(juce::PopupMenu::Options().withParentComponent(&asComp()->editor));
}

std::unique_ptr<RuledLabel> modTitleLab;

std::array<std::unique_ptr<jcmp::MenuButton>, numModsPer> sourceMenu;
Expand Down
2 changes: 2 additions & 0 deletions src/ui/six-sines-editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct SixSinesJuceLookAndFeel;
struct SixSinesEditor : jcmp::WindowPanel
{
Patch patchCopy;
ModMatrixConfig modMatrixConfig;

Synth::audioToUIQueue_t &audioToUI;
Synth::uiToAudioQueue_T &uiToAudio;
std::function<void()> flushOperator;
Expand Down

0 comments on commit eeea48e

Please sign in to comment.