From 19c350d247358bccf9a0547d79a5fdd802d9d729 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Wed, 15 Dec 2021 20:09:39 -0500 Subject: [PATCH] Acc Bugs; Reset storage state when resetting init patch The init patch updated prefs but not the in memory image. Oops! Closes #5637 Also initialize storage in Switch; and add the key handlers for MultiSwitch. Addresses #4616 --- src/surge-xt/gui/SurgeGUIEditor.cpp | 4 +-- src/surge-xt/gui/widgets/MultiSwitch.cpp | 30 ++++++++++++++++++++++ src/surge-xt/gui/widgets/MultiSwitch.h | 1 + src/surge-xt/gui/widgets/PatchSelector.cpp | 7 +++++ src/surge-xt/gui/widgets/Switch.h | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/surge-xt/gui/SurgeGUIEditor.cpp b/src/surge-xt/gui/SurgeGUIEditor.cpp index e4e20a2228b..e7fabd2a381 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.cpp +++ b/src/surge-xt/gui/SurgeGUIEditor.cpp @@ -2067,7 +2067,7 @@ void SurgeGUIEditor::controlBeginEdit(Surge::GUI::IComponentTagValue *control) } else { - jassert(false); + // jassert(false); } } @@ -2088,7 +2088,7 @@ void SurgeGUIEditor::controlEndEdit(Surge::GUI::IComponentTagValue *control) } else { - jassert(false); + // jassert(false); } } diff --git a/src/surge-xt/gui/widgets/MultiSwitch.cpp b/src/surge-xt/gui/widgets/MultiSwitch.cpp index 7090ecc239b..6452d618db8 100644 --- a/src/surge-xt/gui/widgets/MultiSwitch.cpp +++ b/src/surge-xt/gui/widgets/MultiSwitch.cpp @@ -221,6 +221,36 @@ void MultiSwitch::mouseWheelMove(const juce::MouseEvent &event, } } +bool MultiSwitch::keyPressed(const juce::KeyPress &key) +{ + if (!Surge::GUI::allowKeyboardEdits(storage)) + return false; + + bool got{false}; + int dir = 1; + if (key.getKeyCode() == juce::KeyPress::leftKey || key.getKeyCode() == juce::KeyPress::downKey) + { + got = true; + dir = -1; + } + if (key.getKeyCode() == juce::KeyPress::rightKey || key.getKeyCode() == juce::KeyPress::upKey) + { + got = true; + } + + if (got) + { + auto iv = limit_range(getIntegerValue() + dir, 0, rows * columns - 1); + + setValue(1.f * iv / (rows * columns - 1)); + notifyBeginEdit(); + notifyValueChanged(); + notifyEndEdit(); + repaint(); + } + return got; +} + #if SURGE_JUCE_ACCESSIBLE struct MultiSwitchRadioButton : public juce::Component diff --git a/src/surge-xt/gui/widgets/MultiSwitch.h b/src/surge-xt/gui/widgets/MultiSwitch.h index a4511efd4ae..42576f4d37a 100644 --- a/src/surge-xt/gui/widgets/MultiSwitch.h +++ b/src/surge-xt/gui/widgets/MultiSwitch.h @@ -88,6 +88,7 @@ struct MultiSwitch : public juce::Component, public WidgetBaseMixin endHover(); repaint(); } + bool keyPressed(const juce::KeyPress &key) override; Surge::GUI::WheelAccumulationHelper wheelHelper; void mouseWheelMove(const juce::MouseEvent &event, const juce::MouseWheelDetails &wheel) override; diff --git a/src/surge-xt/gui/widgets/PatchSelector.cpp b/src/surge-xt/gui/widgets/PatchSelector.cpp index 0719ed22d91..740b6a13a92 100644 --- a/src/surge-xt/gui/widgets/PatchSelector.cpp +++ b/src/surge-xt/gui/widgets/PatchSelector.cpp @@ -544,6 +544,13 @@ void PatchSelector::showClassicMenu(bool single_category) Surge::Storage::updateUserDefaultValue( storage, Surge::Storage::InitialPatchCategoryType, storage->patch_category[current_category].isFactory ? "Factory" : "User"); + + storage->initPatchName = Surge::Storage::getUserDefaultValue( + storage, Surge::Storage::InitialPatchName, "Init Saw"); + storage->initPatchCategory = Surge::Storage::getUserDefaultValue( + storage, Surge::Storage::InitialPatchCategory, "Templates"); + storage->initPatchCategoryType = Surge::Storage::getUserDefaultValue( + storage, Surge::Storage::InitialPatchCategoryType, "Factory"); }); contextMenu.addSeparator(); diff --git a/src/surge-xt/gui/widgets/Switch.h b/src/surge-xt/gui/widgets/Switch.h index 198cb635c79..02cce2b11a1 100644 --- a/src/surge-xt/gui/widgets/Switch.h +++ b/src/surge-xt/gui/widgets/Switch.h @@ -94,7 +94,7 @@ struct Switch : public juce::Component, public WidgetBaseMixin repaint(); } - SurgeStorage *storage; + SurgeStorage *storage{nullptr}; void setStorage(SurgeStorage *s) { storage = s; } Surge::GUI::WheelAccumulationHelper wheelHelper;