Skip to content

Commit

Permalink
SoundEditor: change patch cable strength resolution from +/- 50 to +/…
Browse files Browse the repository at this point in the history
…- 50.00

The Sound engine and its XML files already support much higher resolution internally.
Thus this change keeps FULL backward/forward compat of synth XML files.
It is already possible to adjust the strength by editing the XML manually and then
loading it into stock firmware.

This feature is very useful i e when patching note value to osc1/osc2
pitch, to create subtle tuning variations or even faking high-EDO
tunings (although we plan supporting the latter natively as part of the
alternate tuning work).

Use MenuItemDecimal with two decimal places to keep the same effect of
the encoder by default. Then use <|> encoder to select decimals,
just like for the (unmodulated) osc1/2 transpose.
  • Loading branch information
bfredl committed Jun 11, 2023
1 parent c68b613 commit 8e46b97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
26 changes: 17 additions & 9 deletions src/MenuItemPatchCableStrength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
MenuItemPatchCableStrengthRegular patchCableStrengthMenuRegular;
MenuItemPatchCableStrengthRange patchCableStrengthMenuRange;

extern bool movingCursor;

#if HAVE_OLED
void MenuItemPatchCableStrength::renderOLED() {

Expand Down Expand Up @@ -89,13 +91,16 @@ void MenuItemPatchCableStrength::renderOLED() {
TEXT_SPACING_X, TEXT_SIZE_Y_UPDATED);

char buffer[12];
intToString(soundEditor.currentValue, buffer, 1);
OLED::drawStringAlignRight(buffer, extraY + OLED_MAIN_TOPMOST_PIXEL + 4 + destinationDescriptor.isJustAParam(),
OLED::oledMainImage[0], OLED_MAIN_WIDTH_PIXELS, 18, 20);

int marginL = destinationDescriptor.isJustAParam() ? 0 : 80;
int yBar = destinationDescriptor.isJustAParam() ? 36 : 37;
drawBar(yBar, marginL, 0);
const int digitWidth = TEXT_BIG_SPACING_X;
const int digitHeight = TEXT_BIG_SIZE_Y;
intToString(soundEditor.currentValue, buffer, 3);
int textPixelY = extraY + OLED_MAIN_TOPMOST_PIXEL + 10 + destinationDescriptor.isJustAParam();
OLED::drawStringAlignRight(buffer, textPixelY, OLED::oledMainImage[0], OLED_MAIN_WIDTH_PIXELS, digitWidth, digitHeight);

int ourDigitStartX = OLED_MAIN_WIDTH_PIXELS - (soundEditor.numberEditPos+1) * digitWidth;
OLED::setupBlink(ourDigitStartX, digitWidth, 40, 44, movingCursor);
OLED::drawVerticalLine(OLED_MAIN_WIDTH_PIXELS-2*digitWidth, textPixelY+digitHeight+1, textPixelY+digitHeight+3, OLED::oledMainImage);
OLED::drawVerticalLine(OLED_MAIN_WIDTH_PIXELS-2*digitWidth-1, textPixelY+digitHeight+1, textPixelY+digitHeight+3, OLED::oledMainImage);
}
#endif

Expand All @@ -105,7 +110,9 @@ void MenuItemPatchCableStrength::readCurrentValue() {
if (c == 255) soundEditor.currentValue = 0;
else {
int32_t paramValue = patchCableSet->patchCables[c].param.getCurrentValue();
soundEditor.currentValue = ((int64_t)paramValue * 50 + 536870912) >> 30;
// 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.
soundEditor.currentValue = ((int64_t)paramValue * 5000 + (1 << 29)) >> 30;
}
}

Expand All @@ -126,7 +133,8 @@ void MenuItemPatchCableStrength::writeCurrentValue() {
ModelStackWithAutoParam* modelStackWithParam = getModelStack(modelStackMemory, true);
if (!modelStackWithParam->autoParam) return;

int32_t finalValue = soundEditor.currentValue * 21474836;
// 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*soundEditor.currentValue) >> 32;
modelStackWithParam->autoParam->setCurrentValueInResponseToUserInput(finalValue, modelStackWithParam);
}

Expand Down
12 changes: 7 additions & 5 deletions src/MenuItemPatchCableStrength.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
#ifndef MENUITEMPATCHCABLESTRENGTH_H_
#define MENUITEMPATCHCABLESTRENGTH_H_

#include "MenuItemInteger.h"
#include "MenuItemDecimal.h"
#include "MenuItemWithCCLearning.h"

class MenuItemPatchCableStrength : public MenuItemIntegerContinuous, public MenuItemWithCCLearning {
class MenuItemPatchCableStrength : public MenuItemDecimal, public MenuItemWithCCLearning {
public:
MenuItemPatchCableStrength(char const* newName = NULL) : MenuItemIntegerContinuous(newName) {}
MenuItemPatchCableStrength(char const* newName = NULL) : MenuItemDecimal(newName) {}
void readCurrentValue() final;
void writeCurrentValue();
int getMinValue() final { return -50; }
int getMaxValue() final { return 50; }
int getMinValue() final { return -5000; }
int getMaxValue() final { return 5000; }
int getNumDecimalPlaces() final { return 2; }
virtual int getDefaultEditPos() { return 2; }
virtual int checkPermissionToBeginSession(Sound* sound, int whichThing, MultiRange** currentRange);
virtual ParamDescriptor getDestinationDescriptor() = 0;
virtual uint8_t getS() = 0;
Expand Down

0 comments on commit 8e46b97

Please sign in to comment.