From 9be2d2f196f8871c7175526b8a72cd4d0754770b Mon Sep 17 00:00:00 2001 From: Tyson Lloyd Thwaites Date: Wed, 20 Sep 2023 21:24:56 +1000 Subject: [PATCH] Ability to set max banks --- examples/SwitchPreset/SwitchPreset.ino | 2 +- src/interface/AxeSystem.h | 11 ++++++++++- src/interface/private/AxeSystem.cpp | 9 +++++++++ src/interface/private/AxeSystem_Commands.cpp | 4 ++-- src/interface/private/AxeSystem_Handlers.cpp | 2 +- src/interface/private/AxeSystem_Private.h | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/examples/SwitchPreset/SwitchPreset.ino b/examples/SwitchPreset/SwitchPreset.ino index eaa68dd..1edaca7 100644 --- a/examples/SwitchPreset/SwitchPreset.ino +++ b/examples/SwitchPreset/SwitchPreset.ino @@ -15,7 +15,7 @@ void setup() { void loop() { static PresetNumber preset = 0; - if (preset >= AxeSystem::MAX_PRESETS) { + if (preset >= AxeSystem::maxPresets()) { preset = 0; } diff --git a/src/interface/AxeSystem.h b/src/interface/AxeSystem.h index 0a62c39..9189f98 100644 --- a/src/interface/AxeSystem.h +++ b/src/interface/AxeSystem.h @@ -120,6 +120,13 @@ class AxeSystem { void sendProgramChange(byte value, byte channel); void sendSysEx(const byte *sysex, const byte length); + // Used to calculate max presets. Defaults to 4. + // You can set this at any time. + void setMaxBanks(const byte max); + + // Max presets depending on how many banks we have + PresetNumber maxPresets(); + // Well is it, or isn't it? As far as we know! This is pretty accurate // even if you enable/disable the tuner from the front panel. bool isTunerEngaged() { return _tunerEngaged; } @@ -222,12 +229,14 @@ class AxeSystem { // These are values supported by the AxeFX 3, and can't be changed. const static byte BANK_SIZE = 128; - const static byte MAX_BANKS = 4; const static byte MAX_SCENES = 8; const static byte TEMPO_MIN = 24; const static byte TEMPO_MAX = 250; const static byte MIDI_CHANNEL_OMNI = 0; const static byte DEFAULT_MIDI_CHANNEL = MIDI_CHANNEL_OMNI; + + // These are deprecated but still here in case old code is using them + const static byte MAX_BANKS = 4; constexpr static PresetNumber MAX_PRESETS = (MAX_BANKS * BANK_SIZE) - 1; // OK, there ends the tour! Continue on to AxePreset.h, diff --git a/src/interface/private/AxeSystem.cpp b/src/interface/private/AxeSystem.cpp index 00c2db8..fcdb45d 100644 --- a/src/interface/private/AxeSystem.cpp +++ b/src/interface/private/AxeSystem.cpp @@ -75,6 +75,15 @@ int AxeSystem::midiBytesToInt(const byte lsb, const byte msb) { return lsb + (msb * BANK_SIZE); } +void AxeSystem::setMaxBanks(const byte max) { + _maxBanks = max; + _maxPresets = (_maxBanks * BANK_SIZE) - 1; +} + +PresetNumber AxeSystem::maxPresets() { + return _maxPresets; +} + #ifdef AXE_DEBUG_SYSEX void AxeSystem::debugSysex(const byte *sysex, const byte length, const char *message) { char buf[6]; diff --git a/src/interface/private/AxeSystem_Commands.cpp b/src/interface/private/AxeSystem_Commands.cpp index 1ba44b3..d0177df 100644 --- a/src/interface/private/AxeSystem_Commands.cpp +++ b/src/interface/private/AxeSystem_Commands.cpp @@ -131,7 +131,7 @@ void AxeSystem::sendEffectChannelDecrement(const EffectId effectId) { void AxeSystem::sendPresetIncrement() { int number = _preset.getPresetNumber(); if (isValidPresetNumber(number)) { - if (++number > MAX_PRESETS) { + if (++number > maxPresets()) { number = 0; } sendPresetChange(number); @@ -142,7 +142,7 @@ void AxeSystem::sendPresetDecrement() { int number = _preset.getPresetNumber(); if (isValidPresetNumber(number)) { if (number == 0) { - number = MAX_PRESETS; + number = maxPresets(); } else { number--; } diff --git a/src/interface/private/AxeSystem_Handlers.cpp b/src/interface/private/AxeSystem_Handlers.cpp index c16dc68..f3b49c9 100644 --- a/src/interface/private/AxeSystem_Handlers.cpp +++ b/src/interface/private/AxeSystem_Handlers.cpp @@ -242,7 +242,7 @@ void AxeSystem::parseName(const byte *sysex, const byte length, const byte offse } bool AxeSystem::isValidPresetNumber(const PresetNumber preset) { - return preset >= 0 && preset <= MAX_PRESETS; + return preset >= 0 && preset <= maxPresets(); } bool AxeSystem::isValidSceneNumber(const SceneNumber scene) { diff --git a/src/interface/private/AxeSystem_Private.h b/src/interface/private/AxeSystem_Private.h index f9442f9..00575a7 100644 --- a/src/interface/private/AxeSystem_Private.h +++ b/src/interface/private/AxeSystem_Private.h @@ -93,6 +93,8 @@ byte _sysexFractalVersion; byte _tempo; byte _bank; byte _midiChannel; +byte _maxBanks = 4; //default to MkI +PresetNumber _maxPresets = (4 * BANK_SIZE) - 1; //default to MkI bool _firmwareRequested = false; bool _tunerEngaged = false; bool _systemConnected = false;