diff --git a/src/definitions_cxx.hpp b/src/definitions_cxx.hpp index e98c5ff70b..5cc16da3cc 100644 --- a/src/definitions_cxx.hpp +++ b/src/definitions_cxx.hpp @@ -358,12 +358,20 @@ constexpr PatchSource kFirstLocalSource = PatchSource::ENVELOPE_0; //Menu Min Max Values -constexpr int32_t kMinMenuPanValue = -64; -constexpr int32_t kMaxMenuPanValue = 64; -constexpr int32_t kMinMenuValue = 0; +//regular menu range e.g. 0 - 50 or 0 - 128 constexpr int32_t kMaxMenuValue = 128; +constexpr int32_t kMinMenuValue = 0; constexpr int32_t kMidMenuValue = kMinMenuValue + ((kMaxMenuValue - kMinMenuValue) / 2); +//pan menu range e.g. -32 to +32 or -64 to +64 +constexpr int32_t kMaxMenuPanValue = kMaxMenuValue / 2; +constexpr int32_t kMinMenuPanValue = -1 * kMaxMenuPanValue; + +//patch cable menu range e.g. -50 to 50 or -128 to +128 +constexpr int32_t kMaxMenuPatchCableValue = kMaxMenuValue * 100; +constexpr int32_t kMinMenuPatchCableValue = -1 * kMaxMenuPatchCableValue; +// + //Automation View constants constexpr int32_t kNoSelection = 255; constexpr int32_t kNumNonKitAffectEntireParamsForAutomation = 55; diff --git a/src/deluge/gui/menu_item/arpeggiator/midi_cv/rate.h b/src/deluge/gui/menu_item/arpeggiator/midi_cv/rate.h index 2394dbbb71..a5915d049f 100644 --- a/src/deluge/gui/menu_item/arpeggiator/midi_cv/rate.h +++ b/src/deluge/gui/menu_item/arpeggiator/midi_cv/rate.h @@ -26,7 +26,8 @@ class Rate final : public Integer { using Integer::Integer; void readCurrentValue() override { this->setValue( - (((int64_t)(static_cast<InstrumentClip*>(currentSong->currentClip))->arpeggiatorRate + 2147483648) * kMaxMenuValue + (((int64_t)(static_cast<InstrumentClip*>(currentSong->currentClip))->arpeggiatorRate + 2147483648) + * kMaxMenuValue + 2147483648) >> 32); } diff --git a/src/deluge/gui/menu_item/audio_clip/attack.h b/src/deluge/gui/menu_item/audio_clip/attack.h index 2fb4ee524d..bb356778de 100644 --- a/src/deluge/gui/menu_item/audio_clip/attack.h +++ b/src/deluge/gui/menu_item/audio_clip/attack.h @@ -27,7 +27,8 @@ class Attack final : public Integer { void readCurrentValue() override { this->setValue( - (((int64_t)(static_cast<AudioClip*>(currentSong->currentClip))->attack + 2147483648) * kMaxMenuValue + 2147483648) + (((int64_t)(static_cast<AudioClip*>(currentSong->currentClip))->attack + 2147483648) * kMaxMenuValue + + 2147483648) >> 32); } void writeCurrentValue() override { diff --git a/src/deluge/gui/menu_item/midi/default_velocity_to_level.h b/src/deluge/gui/menu_item/midi/default_velocity_to_level.h index 4a7ad67679..36702de590 100644 --- a/src/deluge/gui/menu_item/midi/default_velocity_to_level.h +++ b/src/deluge/gui/menu_item/midi/default_velocity_to_level.h @@ -26,7 +26,8 @@ class DefaultVelocityToLevel final : public IntegerWithOff { using IntegerWithOff::IntegerWithOff; [[nodiscard]] int32_t getMaxValue() const override { return kMaxMenuValue; } void readCurrentValue() override { - this->setValue(((int64_t)soundEditor.currentMIDIDevice->defaultVelocityToLevel * kMaxMenuValue + 536870912) >> 30); + this->setValue(((int64_t)soundEditor.currentMIDIDevice->defaultVelocityToLevel * kMaxMenuValue + 536870912) + >> 30); } void writeCurrentValue() override { soundEditor.currentMIDIDevice->defaultVelocityToLevel = this->getValue() * (2147483648 / (kMaxMenuValue * 2)); diff --git a/src/deluge/gui/menu_item/osc/pulse_width.h b/src/deluge/gui/menu_item/osc/pulse_width.h index 80d3f11a75..8242e56363 100644 --- a/src/deluge/gui/menu_item/osc/pulse_width.h +++ b/src/deluge/gui/menu_item/osc/pulse_width.h @@ -43,7 +43,8 @@ class PulseWidth final : public menu_item::source::PatchedParam, public Formatte void readCurrentValue() override { this->setValue( - ((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) * (kMaxMenuValue * 2) + 2147483648) + ((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) * (kMaxMenuValue * 2) + + 2147483648) >> 32); } diff --git a/src/deluge/gui/menu_item/patch_cable_strength.cpp b/src/deluge/gui/menu_item/patch_cable_strength.cpp index 3c7059e588..5498af8467 100644 --- a/src/deluge/gui/menu_item/patch_cable_strength.cpp +++ b/src/deluge/gui/menu_item/patch_cable_strength.cpp @@ -112,7 +112,7 @@ void PatchCableStrength::renderOLED() { char buffer[12]; if (preferBarDrawing) { - int32_t rounded = (this->getValue() + 50 * (this->getValue() > 0 ? 1 : -1)) / 100; + int32_t rounded = this->getValue() / 100; intToString(rounded, buffer, 1); deluge::hid::display::OLED::drawStringAlignRight( buffer, extraY + OLED_MAIN_TOPMOST_PIXEL + 4 + destinationDescriptor.isJustAParam(), @@ -152,7 +152,7 @@ void PatchCableStrength::readCurrentValue() { int32_t paramValue = patchCableSet->patchCables[c].param.getCurrentValue(); // the internal values are stored in the range -(2^30) to 2^30. // rescale them to the range -5000 to 5000 and round to nearest. - this->setValue(((int64_t)paramValue * 5000 + (1 << 29)) >> 30); + this->setValue(((int64_t)paramValue * kMaxMenuPatchCableValue + (1 << 29)) >> 30); } } @@ -175,8 +175,9 @@ void PatchCableStrength::writeCurrentValue() { return; } - // rescale from 5000 to 2**30. The magic constant is ((2^30)/5000), shifted 32 bits for precision ((1<<(30+32))/5000) - int32_t finalValue = ((int64_t)922337203685477 * this->getValue()) >> 32; + //rescale from 5000 to 2^30. The magic constant is ((2^30)/5000), shifted 32 bits for precision ((1<<(30+32))/5000) + int64_t magicConstant = (922337203685477 * 5000) / kMaxMenuPatchCableValue; + int32_t finalValue = (magicConstant * this->getValue()) >> 32; modelStackWithParam->autoParam->setCurrentValueInResponseToUserInput(finalValue, modelStackWithParam); } diff --git a/src/deluge/gui/menu_item/patch_cable_strength.h b/src/deluge/gui/menu_item/patch_cable_strength.h index ba0892d83f..c36b37f7c3 100644 --- a/src/deluge/gui/menu_item/patch_cable_strength.h +++ b/src/deluge/gui/menu_item/patch_cable_strength.h @@ -27,8 +27,8 @@ class PatchCableStrength : public Decimal, public MenuItemWithCCLearning { void beginSession(MenuItem* navigatedBackwardFrom) final; void readCurrentValue() final; void writeCurrentValue() override; - [[nodiscard]] int32_t getMinValue() const final { return -5000; } - [[nodiscard]] int32_t getMaxValue() const final { return 5000; } + [[nodiscard]] int32_t getMinValue() const final { return kMinMenuPatchCableValue; } + [[nodiscard]] int32_t getMaxValue() const final { return kMaxMenuPatchCableValue; } [[nodiscard]] int32_t getNumDecimalPlaces() const final { return 2; } virtual int32_t getDefaultEditPos() { return 2; } MenuPermission checkPermissionToBeginSession(Sound* sound, int32_t whichThing, MultiRange** currentRange) override; diff --git a/src/deluge/gui/menu_item/patch_cables.cpp b/src/deluge/gui/menu_item/patch_cables.cpp index acc269baf5..c5bf5f4aed 100644 --- a/src/deluge/gui/menu_item/patch_cables.cpp +++ b/src/deluge/gui/menu_item/patch_cables.cpp @@ -79,7 +79,7 @@ void PatchCables::renderOptions() { } int32_t param_value = cable->param.getCurrentValue(); - int32_t level = ((int64_t)param_value * 5000 + (1 << 29)) >> 30; + int32_t level = ((int64_t)param_value * kMaxMenuPatchCableValue + (1 << 29)) >> 30; floatToString((float)level / 100, buf + off + 5, 2, 2); //fmt::vformat_to_n(buf + off + 5, 5, "{:4}", fmt::make_format_args(); diff --git a/src/deluge/gui/menu_item/patched_param/integer.cpp b/src/deluge/gui/menu_item/patched_param/integer.cpp index f985b3a9f0..19785c6cc3 100644 --- a/src/deluge/gui/menu_item/patched_param/integer.cpp +++ b/src/deluge/gui/menu_item/patched_param/integer.cpp @@ -21,9 +21,10 @@ namespace deluge::gui::menu_item::patched_param { void Integer::readCurrentValue() { - this->setValue((((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) + 2147483648) * kMaxMenuValue - + 2147483648) - >> 32); + this->setValue( + (((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) + 2147483648) * kMaxMenuValue + + 2147483648) + >> 32); } void Integer::writeCurrentValue() { diff --git a/src/deluge/gui/menu_item/patched_param/pan.cpp b/src/deluge/gui/menu_item/patched_param/pan.cpp index 2d1477eebe..178e7d59d6 100644 --- a/src/deluge/gui/menu_item/patched_param/pan.cpp +++ b/src/deluge/gui/menu_item/patched_param/pan.cpp @@ -59,7 +59,9 @@ int32_t Pan::getFinalValue() { } void Pan::readCurrentValue() { - this->setValue(((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) * (kMaxMenuPanValue * 2) + 2147483648) - >> 32); + this->setValue( + ((int64_t)soundEditor.currentParamManager->getPatchedParamSet()->getValue(getP()) * (kMaxMenuPanValue * 2) + + 2147483648) + >> 32); } } // namespace deluge::gui::menu_item::patched_param diff --git a/src/deluge/gui/menu_item/reverb/pan.h b/src/deluge/gui/menu_item/reverb/pan.h index dda12bec53..3c52c02b1f 100644 --- a/src/deluge/gui/menu_item/reverb/pan.h +++ b/src/deluge/gui/menu_item/reverb/pan.h @@ -43,7 +43,9 @@ class Pan final : public Integer { void writeCurrentValue() override { AudioEngine::reverbPan = ((int32_t)this->getValue() * 33554432); } - void readCurrentValue() override { this->setValue(((int64_t)AudioEngine::reverbPan * (kMaxMenuPanValue * 4) + 2147483648) >> 32); } + void readCurrentValue() override { + this->setValue(((int64_t)AudioEngine::reverbPan * (kMaxMenuPanValue * 4) + 2147483648) >> 32); + } [[nodiscard]] int32_t getMaxValue() const override { return kMaxMenuPanValue; } [[nodiscard]] int32_t getMinValue() const override { return kMinMenuPanValue; } }; diff --git a/src/deluge/gui/menu_item/unpatched_param.cpp b/src/deluge/gui/menu_item/unpatched_param.cpp index 36514c2690..f87d584ae3 100644 --- a/src/deluge/gui/menu_item/unpatched_param.cpp +++ b/src/deluge/gui/menu_item/unpatched_param.cpp @@ -31,10 +31,10 @@ extern "C" { namespace deluge::gui::menu_item { void UnpatchedParam::readCurrentValue() { - this->setValue( - (((int64_t)soundEditor.currentParamManager->getUnpatchedParamSet()->getValue(getP()) + 2147483648) * kMaxMenuValue - + 2147483648) - >> 32); + this->setValue((((int64_t)soundEditor.currentParamManager->getUnpatchedParamSet()->getValue(getP()) + 2147483648) + * kMaxMenuValue + + 2147483648) + >> 32); } ModelStackWithAutoParam* UnpatchedParam::getModelStack(void* memory) { diff --git a/src/deluge/gui/menu_item/unpatched_param/pan.cpp b/src/deluge/gui/menu_item/unpatched_param/pan.cpp index 13ae64b8d6..dd19bff0d5 100644 --- a/src/deluge/gui/menu_item/unpatched_param/pan.cpp +++ b/src/deluge/gui/menu_item/unpatched_param/pan.cpp @@ -55,7 +55,9 @@ int32_t Pan::getFinalValue() { void Pan::readCurrentValue() { this->setValue( - ((int64_t)soundEditor.currentParamManager->getUnpatchedParamSet()->getValue(getP()) * (kMaxMenuPanValue * 2) + 2147483648) >> 32); + ((int64_t)soundEditor.currentParamManager->getUnpatchedParamSet()->getValue(getP()) * (kMaxMenuPanValue * 2) + + 2147483648) + >> 32); } } // namespace deluge::gui::menu_item::unpatched_param