Skip to content

Commit

Permalink
Updated Param Value Range for Patch Cables
Browse files Browse the repository at this point in the history
Factored out the constants for Patch Cables

Updated range from -50 to.+50 to -128 to +128 to align with the +128 range displayed for params in the regular menu's
  • Loading branch information
seangoodvibes committed Oct 25, 2023
1 parent b5b276d commit 6c6ce4a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 25 deletions.
14 changes: 11 additions & 3 deletions src/definitions_cxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/deluge/gui/menu_item/arpeggiator/midi_cv/rate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/deluge/gui/menu_item/audio_clip/attack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/deluge/gui/menu_item/midi/default_velocity_to_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/deluge/gui/menu_item/osc/pulse_width.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions src/deluge/gui/menu_item/patch_cable_strength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/deluge/gui/menu_item/patch_cable_strength.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/gui/menu_item/patch_cables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions src/deluge/gui/menu_item/patched_param/integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions src/deluge/gui/menu_item/patched_param/pan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/deluge/gui/menu_item/reverb/pan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
Expand Down
8 changes: 4 additions & 4 deletions src/deluge/gui/menu_item/unpatched_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/deluge/gui/menu_item/unpatched_param/pan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6c6ce4a

Please sign in to comment.