mirror of
https://codeberg.org/armin/sm-26.git
synced 2026-10-11 17:01:53 +02:00
- Save/load the engine's full parameter set alongside the preset index so knob and menu tweaks survive relaunching a song project - Make the plugin panel black: top/surround laser border and bottom deck (rotary + nav keys) are now #000000 - Extend factory bank to 320 categorized presets and add LCD click-to-open preset category browser
498 lines
19 KiB
C++
498 lines
19 KiB
C++
#include "PluginEditor.h"
|
|
#include "BuildInfo_generated.h"
|
|
|
|
static juce::String padRight (const juce::String& s, int width)
|
|
{
|
|
if (s.length() >= width) return s.substring (0, width);
|
|
return s + juce::String::repeatedString (" ", width - s.length());
|
|
}
|
|
|
|
SM26AudioProcessorEditor::SM26AudioProcessorEditor (SM26AudioProcessor& p)
|
|
: AudioProcessorEditor (p), proc (p)
|
|
{
|
|
setSize (920, 680);
|
|
setResizable (true, false);
|
|
setResizeLimits (760, 620, 1500, 1300);
|
|
|
|
addAndMakeVisible (lcd);
|
|
lcd.onPressed = [this](int) { if (! menu.isOpen()) openPresetMenu(); };
|
|
setupKnobs();
|
|
setupNavButtons();
|
|
|
|
footer.setText (buildGitFooter(), juce::dontSendNotification);
|
|
footer.setJustificationType (juce::Justification::centredLeft);
|
|
footer.setColour (juce::Label::textColourId, juce::Colour (0xFFA0A0A0));
|
|
footer.setFont (juce::Font (juce::FontOptions { juce::Font::getDefaultMonospacedFontName(), 11.0f, juce::Font::plain }));
|
|
addAndMakeVisible (footer);
|
|
|
|
buildRootMenu();
|
|
startTimerHz (20);
|
|
}
|
|
|
|
SM26AudioProcessorEditor::~SM26AudioProcessorEditor()
|
|
{
|
|
stopTimer();
|
|
}
|
|
|
|
juce::String SM26AudioProcessorEditor::buildGitFooter()
|
|
{
|
|
return juce::String ("SM-26 v") + SM26_GIT_VERSION
|
|
+ " | branch " + SM26_GIT_BRANCH
|
|
+ " | built " + SM26_BUILD_TIME
|
|
+ " | arm64";
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::setupKnobs()
|
|
{
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
knobSliders[i].setSliderStyle (juce::Slider::RotaryVerticalDrag);
|
|
knobSliders[i].setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
|
|
knobSliders[i].setRange (0.0, 1.0, 0.001);
|
|
knobSliders[i].setColour (juce::Slider::rotarySliderFillColourId, juce::Colour (0xFFC8C8C8));
|
|
knobSliders[i].setColour (juce::Slider::rotarySliderOutlineColourId, juce::Colour (0xFF2A2A2A));
|
|
knobSliders[i].setColour (juce::Slider::thumbColourId, juce::Colours::transparentBlack);
|
|
knobSliders[i].addListener (this);
|
|
addAndMakeVisible (knobSliders[i]);
|
|
|
|
knobLabels[i].setJustificationType (juce::Justification::centred);
|
|
knobLabels[i].setColour (juce::Label::textColourId, juce::Colour (0xFFA0A0A0));
|
|
knobLabels[i].setFont (juce::Font (juce::FontOptions { juce::Font::getDefaultMonospacedFontName(), 13.0f, juce::Font::plain }));
|
|
addAndMakeVisible (knobLabels[i]);
|
|
|
|
knobValueLabels[i].setJustificationType (juce::Justification::centred);
|
|
knobValueLabels[i].setColour (juce::Label::textColourId, juce::Colour (0xFFD0D0D0));
|
|
knobValueLabels[i].setFont (juce::Font (juce::FontOptions { juce::Font::getDefaultMonospacedFontName(), 14.0f, juce::Font::bold }));
|
|
addAndMakeVisible (knobValueLabels[i]);
|
|
|
|
knobSliders[i].setValue (0.5, juce::dontSendNotification);
|
|
}
|
|
}
|
|
|
|
juce::Font SM26AudioProcessorEditor::NavButtonLookAndFeel::getTextButtonFont (juce::TextButton&, int)
|
|
{
|
|
return juce::Font (juce::FontOptions { juce::Font::getDefaultMonospacedFontName(),
|
|
10.5f, juce::Font::bold });
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::setupNavButtons()
|
|
{
|
|
auto setup = [this](juce::TextButton& btn, juce::Colour bg)
|
|
{
|
|
btn.setLookAndFeel (&navLookAndFeel);
|
|
btn.setColour (juce::TextButton::buttonColourId, bg);
|
|
btn.setColour (juce::TextButton::textColourOffId, juce::Colour (0xFFE0E0E0));
|
|
btn.setColour (juce::ComboBox::outlineColourId, juce::Colour (0xFF444444));
|
|
addAndMakeVisible (btn);
|
|
};
|
|
|
|
setup (navUp, juce::Colour (0xFF000000));
|
|
setup (navDown, juce::Colour (0xFF000000));
|
|
setup (navLeft, juce::Colour (0xFF000000));
|
|
setup (navRight, juce::Colour (0xFF000000));
|
|
setup (navEnter, juce::Colour (0xFF000000));
|
|
setup (navEsc, juce::Colour (0xFF000000));
|
|
|
|
navUp.setTriggeredOnMouseDown (true);
|
|
navUp.setRepeatSpeed (250, 50);
|
|
navDown.setTriggeredOnMouseDown (true);
|
|
navDown.setRepeatSpeed (250, 50);
|
|
navUp.onClick = [this] { if (menu.isOpen()) menu.up(); else cyclePreset (-1); };
|
|
navDown.onClick = [this] { if (menu.isOpen()) menu.down(); else cyclePreset (+1); };
|
|
navLeft.onClick = [this] { menu.left(); };
|
|
navRight.onClick = [this] { menu.right(); };
|
|
navEnter.onClick = [this] { if (menu.isOpen()) menu.enter(); else menu.open(); };
|
|
navEsc.onClick = [this] { if (menu.isOpen()) menu.escape(); else menu.close(); };
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::cyclePreset (int delta)
|
|
{
|
|
const int count = sm26::PresetStore::count();
|
|
if (count <= 0) return;
|
|
const int idx = proc.engine.presetIndex();
|
|
proc.setPresetByIndex ((idx + delta + count) % count);
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::buildRootMenu()
|
|
{
|
|
auto builder = [this]() -> MenuScreen
|
|
{
|
|
MenuScreen s;
|
|
s.title = "SM-26 MAIN MENU";
|
|
s.selected = 0;
|
|
|
|
auto addValue = [&](const char* n, int pid) -> MenuItem
|
|
{
|
|
MenuItem mi;
|
|
mi.label = n;
|
|
mi.kind = MenuItem::Value;
|
|
mi.paramId = pid;
|
|
mi.valueText = [this, pid]() {
|
|
if (pid == sm26::PDTIME && proc.engine.getParam (sm26::PDSYNC) > 0.5f)
|
|
return sm26::formatTimeMs ((float) proc.engine.delayTimeMs());
|
|
return sm26::formatParamReal (pid, proc.engine.getParam (pid));
|
|
};
|
|
mi.onAdjust = [this, pid](float d) {
|
|
float delta = (pid == sm26::PDSTEPS) ? d / 0.02f * (1.0f / 15.0f) : d;
|
|
float cur = proc.engine.getParam (pid);
|
|
proc.engine.setParam (pid, sm26::clamp01 (cur + delta));
|
|
for (int k = 0; k < 4; ++k)
|
|
{
|
|
auto kv = proc.engine.knobView (k);
|
|
if (kv.param == pid)
|
|
proc.setKnob (k, sm26::clamp01 ((proc.engine.getParam (pid) - kv.lo) / (kv.hi - kv.lo + 1e-9f)));
|
|
}
|
|
};
|
|
return mi;
|
|
};
|
|
|
|
auto addHeader = [&](const char* n) {
|
|
MenuItem h;
|
|
h.label = "-- " + juce::String (n) + " --";
|
|
h.kind = MenuItem::Separator;
|
|
s.items.push_back (h);
|
|
};
|
|
|
|
{
|
|
MenuItem m;
|
|
m.label = "PRESETS (" + juce::String (sm26::PresetStore::count()) + ")";
|
|
m.kind = MenuItem::Submenu;
|
|
m.onEnter = [this]() { openPresetMenu(); };
|
|
s.items.push_back (m);
|
|
}
|
|
|
|
addHeader ("OSCILLATORS");
|
|
s.items.push_back (addValue ("OSC1 WAVE", sm26::PO1WAVE));
|
|
s.items.push_back (addValue ("OSC2 WAVE", sm26::PO2WAVE));
|
|
s.items.push_back (addValue ("O1 OCTAVE", sm26::PO1OCT));
|
|
s.items.push_back (addValue ("O1 DETUNE", sm26::PO1CT));
|
|
s.items.push_back (addValue ("O2 OCTAVE", sm26::PO2OCT));
|
|
s.items.push_back (addValue ("O2 DETUNE", sm26::PO2CT));
|
|
s.items.push_back (addValue ("MIX", sm26::PMIX));
|
|
s.items.push_back (addValue ("NOISE", sm26::PNOISE));
|
|
|
|
addHeader ("FILTER");
|
|
s.items.push_back (addValue ("CUTOFF", sm26::PCUTOFF));
|
|
s.items.push_back (addValue ("RES", sm26::PRES));
|
|
s.items.push_back (addValue ("F-ENV", sm26::PFENV));
|
|
s.items.push_back (addValue ("F-TYPE", sm26::PFTYPE));
|
|
|
|
addHeader ("ENVELOPE");
|
|
s.items.push_back (addValue ("ATTACK", sm26::PATK));
|
|
s.items.push_back (addValue ("DECAY", sm26::PDEC));
|
|
s.items.push_back (addValue ("SUSTAIN", sm26::PSUS));
|
|
s.items.push_back (addValue ("RELEASE", sm26::PREL));
|
|
|
|
addHeader ("DELAY");
|
|
s.items.push_back (addValue ("TIME/STEPS", sm26::PDTIME));
|
|
s.items.push_back (addValue ("STEPS", sm26::PDSTEPS));
|
|
s.items.push_back (addValue ("SYNC", sm26::PDSYNC));
|
|
s.items.push_back (addValue ("FEEDBACK", sm26::PDFB));
|
|
s.items.push_back (addValue ("MIX", sm26::PDMIX));
|
|
|
|
addHeader ("SYSTEM");
|
|
s.items.push_back (addValue ("DRIVE", sm26::PDRIVE));
|
|
s.items.push_back (addValue ("GLIDE", sm26::PGLIDE));
|
|
s.items.push_back (addValue ("MASTER", sm26::PMASTER));
|
|
|
|
addHeader ("INFO");
|
|
{
|
|
MenuItem mi;
|
|
mi.label = "ABOUT";
|
|
mi.kind = MenuItem::Action;
|
|
mi.onEnter = [this]() {
|
|
MenuScreen as;
|
|
as.title = "ABOUT";
|
|
as.selected = 0;
|
|
{
|
|
MenuItem m2; m2.label = "SM-26 Sound Module by A. Jenewein"; m2.kind = MenuItem::Action;
|
|
as.items.push_back (m2);
|
|
}
|
|
{
|
|
MenuItem m2;
|
|
m2.label = "Version: " + juce::String (SM26_GIT_VERSION);
|
|
m2.kind = MenuItem::Action;
|
|
as.items.push_back (m2);
|
|
}
|
|
{
|
|
MenuItem m2;
|
|
m2.label = "Built: " + juce::String (SM26_BUILD_TIME);
|
|
m2.kind = MenuItem::Action;
|
|
as.items.push_back (m2);
|
|
}
|
|
{
|
|
MenuItem m2;
|
|
m2.label = "Branch: " + juce::String (SM26_GIT_BRANCH);
|
|
m2.kind = MenuItem::Action;
|
|
as.items.push_back (m2);
|
|
}
|
|
{
|
|
MenuItem m2; m2.label = "---"; m2.kind = MenuItem::Separator;
|
|
as.items.push_back (m2);
|
|
}
|
|
{
|
|
MenuItem m2;
|
|
m2.label = juce::String (sm26::PresetStore::count()) + " presets | VST3 + AU";
|
|
m2.kind = MenuItem::Action;
|
|
as.items.push_back (m2);
|
|
}
|
|
menu.pushScreen (as);
|
|
};
|
|
s.items.push_back (mi);
|
|
}
|
|
|
|
return s;
|
|
};
|
|
|
|
menu.setRootScreenBuilder (builder);
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::openPresetMenu()
|
|
{
|
|
struct Cat { juce::String name; int first; int count; };
|
|
std::vector<Cat> cats;
|
|
const int total = sm26::PresetStore::count();
|
|
for (int i = 0; i < total; ++i)
|
|
{
|
|
const auto* p = sm26::PresetStore::get (i);
|
|
if (cats.empty() || cats.back().name != p->category)
|
|
cats.push_back ({ juce::String (p->category), i, 0 });
|
|
cats.back().count++;
|
|
}
|
|
|
|
MenuScreen s;
|
|
s.title = "SELECT PATCH CATEGORY";
|
|
s.selected = 0;
|
|
|
|
const juce::String curCat = sm26::PresetStore::findByIndex (proc.engine.presetIndex())->category;
|
|
for (int c = 0; c < (int) cats.size(); ++c)
|
|
{
|
|
if (cats[(size_t) c].name == curCat)
|
|
s.selected = c;
|
|
|
|
MenuItem mi;
|
|
mi.label = cats[(size_t) c].name + " (" + juce::String (cats[(size_t) c].count) + ")";
|
|
mi.kind = MenuItem::Submenu;
|
|
mi.onEnter = [this, cats, c]() {
|
|
const Cat& cat = cats[(size_t) c];
|
|
MenuScreen catScreen;
|
|
catScreen.title = "PATCHES: " + cat.name;
|
|
catScreen.selected = 0;
|
|
|
|
const juce::String curName = sm26::PresetStore::findByIndex (proc.engine.presetIndex())->name;
|
|
for (int i = cat.first; i < cat.first + cat.count; ++i)
|
|
{
|
|
const auto* p = sm26::PresetStore::get (i);
|
|
if (juce::String (p->name) == curName)
|
|
catScreen.selected = i - cat.first;
|
|
|
|
MenuItem pi;
|
|
pi.label = p->name;
|
|
pi.kind = MenuItem::Action;
|
|
pi.onEnter = [this, i]() {
|
|
proc.setPresetByIndex (i);
|
|
menu.close();
|
|
};
|
|
catScreen.items.push_back (pi);
|
|
}
|
|
menu.pushScreen (catScreen);
|
|
};
|
|
s.items.push_back (mi);
|
|
}
|
|
|
|
if (! menu.isOpen())
|
|
menu.open();
|
|
menu.pushScreen (s);
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::paint (juce::Graphics& g)
|
|
{
|
|
g.fillAll (juce::Colour (0xFF000000));
|
|
|
|
const float totalW = (float) getWidth();
|
|
const float totalH = (float) getHeight();
|
|
|
|
g.setColour (juce::Colour (0xFF000000));
|
|
g.fillRoundedRectangle (8.0f, 8.0f, totalW - 16.0f, totalH - 16.0f, 6.0f);
|
|
|
|
g.setColour (juce::Colour (0xFF000000));
|
|
g.drawRoundedRectangle (8.0f, 8.0f, totalW - 16.0f, totalH - 16.0f, 6.0f, 1.5f);
|
|
|
|
const float lcdBottom = 16.0f + 302.0f;
|
|
g.setColour (juce::Colour (0xFF000000));
|
|
g.fillRoundedRectangle (8.0f, lcdBottom, totalW - 16.0f,
|
|
juce::jmax (0.0f, totalH - 16.0f - lcdBottom), 6.0f);
|
|
|
|
g.setColour (juce::Colour (0xFFC8C8C8));
|
|
g.setFont (juce::Font (juce::FontOptions { juce::Font::getDefaultMonospacedFontName(), 14.0f, juce::Font::bold }));
|
|
g.drawText ("SM-26", 20.0f, 16.0f, 100.0f, 22.0f, juce::Justification::centredLeft);
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::resized()
|
|
{
|
|
const float totalW = (float) getWidth();
|
|
const float totalH = (float) getHeight();
|
|
|
|
float knobSize = 78.0f;
|
|
float knobGap = 20.0f;
|
|
float knobsW = 4.0f * knobSize + 3.0f * knobGap;
|
|
float knobsX = (totalW - knobsW) / 2.0f;
|
|
float knobsY = juce::jmax (360.0f, totalH - 300.0f);
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
float x = knobsX + (float) i * (knobSize + knobGap);
|
|
knobSliders[i].setBounds ((int) x, (int) knobsY, (int) knobSize, (int) knobSize);
|
|
knobLabels[i].setBounds ((int) x, (int) (knobsY + knobSize + 2), (int) knobSize, 18);
|
|
knobValueLabels[i].setBounds ((int) x, (int) (knobsY + knobSize + 20), (int) knobSize, 16);
|
|
}
|
|
|
|
float navSize = 30.0f;
|
|
float navGap = 3.0f;
|
|
float navCenterX = totalW / 2.0f;
|
|
float legendBottom = knobsY + knobSize + 20.0f + 16.0f;
|
|
float footerTop = totalH - 22.0f;
|
|
float navCenterY = (legendBottom + footerTop) * 0.5f;
|
|
|
|
navUp.setBounds ((int) (navCenterX - navSize / 2), (int) (navCenterY - navSize - navGap),
|
|
(int) navSize, (int) navSize);
|
|
navDown.setBounds ((int) (navCenterX - navSize / 2), (int) (navCenterY + navGap),
|
|
(int) navSize, (int) navSize);
|
|
navLeft.setBounds ((int) (navCenterX - navSize - navGap - navSize / 2), (int) (navCenterY - navSize / 2),
|
|
(int) navSize, (int) navSize);
|
|
navRight.setBounds ((int) (navCenterX + navGap + navSize / 2), (int) (navCenterY - navSize / 2),
|
|
(int) navSize, (int) navSize);
|
|
|
|
navEnter.setBounds ((int) (navCenterX - navSize - navGap), (int) (navCenterY + navSize + navGap),
|
|
(int) navSize, (int) navSize);
|
|
navEsc.setBounds ((int) (navCenterX + navGap), (int) (navCenterY + navSize + navGap),
|
|
(int) navSize, (int) navSize);
|
|
|
|
lcd.setBounds (14, 16, (int) totalW - 28, 302);
|
|
|
|
footer.setBounds (8, (int) totalH - 22, (int) totalW - 16, 16);
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::timerCallback()
|
|
{
|
|
updateLCD();
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
auto kv = proc.engine.knobView (i);
|
|
float val = proc.engine.getParam (kv.param);
|
|
if (! knobDragging[i])
|
|
{
|
|
float pos = sm26::clamp01 ((val - kv.lo) / (kv.hi - kv.lo + 1e-9f));
|
|
knobSliders[i].setValue (pos, juce::dontSendNotification);
|
|
}
|
|
knobLabels[i].setText (kv.name, juce::dontSendNotification);
|
|
knobValueLabels[i].setText (sm26::formatParamReal (kv.param, val), juce::dontSendNotification);
|
|
}
|
|
|
|
if (! menu.isOpen() && menuWasOpen)
|
|
buildRootMenu();
|
|
menuWasOpen = menu.isOpen();
|
|
|
|
repaint();
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::sliderValueChanged (juce::Slider* s)
|
|
{
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
if (s == &knobSliders[i])
|
|
{
|
|
float v = (float) s->getValue();
|
|
auto kv = proc.engine.knobView (i);
|
|
float paramVal = sm26::clamp01 (kv.lo + v * (kv.hi - kv.lo));
|
|
proc.engine.setParam (kv.param, paramVal);
|
|
knobValueLabels[i].setText (sm26::formatParamReal (kv.param, paramVal),
|
|
juce::dontSendNotification);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::sliderDragStarted (juce::Slider* s)
|
|
{
|
|
for (int i = 0; i < 4; ++i)
|
|
if (s == &knobSliders[i])
|
|
knobDragging[i] = true;
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::sliderDragEnded (juce::Slider* s)
|
|
{
|
|
for (int i = 0; i < 4; ++i)
|
|
if (s == &knobSliders[i])
|
|
knobDragging[i] = false;
|
|
}
|
|
|
|
void SM26AudioProcessorEditor::updateLCD()
|
|
{
|
|
if (! menu.isOpen())
|
|
{
|
|
int presetIdx = proc.engine.presetIndex();
|
|
const auto* p = sm26::PresetStore::findByIndex (presetIdx);
|
|
|
|
lcd.setLine (0, juce::String (presetIdx + 1) + "/" + juce::String (sm26::PresetStore::count())
|
|
+ " " + sm26::PresetStore::fullLabel (*p));
|
|
|
|
for (int k = 0; k < 4; ++k)
|
|
{
|
|
auto kv = proc.engine.knobView (k);
|
|
lcd.setLine (1 + k, padRight (kv.name, 20)
|
|
+ sm26::formatParamReal (kv.param, proc.engine.getParam (kv.param)));
|
|
}
|
|
|
|
double bpm = proc.engine.lastBpm();
|
|
juce::String bpmStr = juce::String (bpm, 1) + " BPM";
|
|
int notes = proc.engine.notesPlaying();
|
|
juce::String notesStr = notes > 0 ? "NOTES:" + juce::String (notes) : "";
|
|
|
|
lcd.setLine (6, bpmStr + (notesStr.isNotEmpty() ? " " + notesStr : ""));
|
|
lcd.setLine (7, juce::String ("SM-26") + " UP/DN=PATCH CLICK=BROWSE OK=MENU");
|
|
for (int r = 0; r < LcdDisplay::kRows; ++r)
|
|
lcd.setInverted (r, false);
|
|
lcd.showCursor (false);
|
|
}
|
|
else
|
|
{
|
|
const auto& cs = menu.current();
|
|
|
|
lcd.setLine (0, "== " + cs.title + " ==");
|
|
|
|
for (int r = 0; r < LcdDisplay::kRows; ++r)
|
|
lcd.setInverted (r, false);
|
|
|
|
std::vector<int> shown;
|
|
for (int i = 0; i < (int) cs.items.size(); ++i)
|
|
{
|
|
const auto& it = cs.items[i];
|
|
if (it.kind == MenuItem::Separator && it.label.isEmpty())
|
|
continue;
|
|
shown.push_back (i);
|
|
}
|
|
|
|
int pos = 0;
|
|
for (int i = 0; i < (int) shown.size(); ++i)
|
|
if (shown[i] == cs.selected) { pos = i; break; }
|
|
|
|
int top = juce::jlimit (0, juce::jmax (0, (int) shown.size() - 6), pos - 2);
|
|
for (int row = 0; row < 6 && top + row < (int) shown.size(); ++row)
|
|
{
|
|
int idx = shown[top + row];
|
|
const auto& item = cs.items[idx];
|
|
juce::String line = " " + item.label;
|
|
if (item.kind == MenuItem::Value && item.valueText)
|
|
line = padRight (line, 50) + item.valueText();
|
|
else if (item.kind == MenuItem::Submenu)
|
|
line = line + " [ENTER]";
|
|
else if (item.kind == MenuItem::Separator)
|
|
line = " " + item.label;
|
|
lcd.setLine (1 + row, line);
|
|
lcd.setInverted (1 + row, idx == cs.selected);
|
|
}
|
|
lcd.setLine (7, "UP/DN=SEL L/R=VAL OK=OK ESC=BACK");
|
|
lcd.showCursor (false);
|
|
}
|
|
}
|