Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some precision gotchas #7967

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2439,12 +2439,13 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
{
#define ITXT_SIZE 1024

const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const auto isHighPrecision = Surge::Storage::getValueDisplayIsHighPrecision(storage);
const auto displayPrecision = Surge::Storage::getValueDisplayPrecision(storage);

if (basicBlocksParamMetaData.has_value() && basicBlocksParamMetaData->supportsStringConversion)
{
auto fs = sst::basic_blocks::params::ParamMetaData::FeatureState()
.withHighPrecision(detailedMode)
.withHighPrecision(displayPrecision)
.withTemposync(can_temposync() && temposync)
.withAbsolute(can_be_absolute() && absolute)
.withExtended(can_extend_range() && extend_range);
Expand Down Expand Up @@ -2485,7 +2486,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
}
}

int dp = (detailedMode ? 6 : displayInfo.decimals);
int dp = (isHighPrecision ? 6 : displayInfo.decimals);

const char *lowersep = "<", *uppersep = ">";

Expand Down Expand Up @@ -2592,7 +2593,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
{
if (temposync)
{
dp = (detailedMode ? 6 : 2);
dp = (isHighPrecision ? 6 : 2);

switch (displaymode)
{
Expand Down Expand Up @@ -2660,7 +2661,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
{
dval *= 1000.f;
vu = "ms";
vdp = detailedMode ? 2 : 1;
vdp = isHighPrecision ? 2 : 1;
dmp *= 1000.f;
dmn *= 1000.f;
diffFac = 1000.f;
Expand Down Expand Up @@ -2870,7 +2871,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
auto freq = 440.0 * pow(2.0, (note - 69.0) / 12);
auto frequp = 440.0 * pow(2.0, (noteup - 69.0) / 12);
auto freqdn = 440.0 * pow(2.0, (notedn - 69.0) / 12);
int dp = (detailedMode ? 6 : 2);
int dp = (isHighPrecision ? 6 : 2);

switch (displaymode)
{
Expand Down Expand Up @@ -2921,7 +2922,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
}

float exmf = qq;
int dp = (detailedMode ? 6 : 2);
int dp = (isHighPrecision ? 6 : 2);

switch (displaymode)
{
Expand Down Expand Up @@ -3038,7 +3039,7 @@ void Parameter::get_display_of_modulation_depth(char *txt, float modulationDepth
{
if (temposync)
{
dp = (detailedMode ? 6 : 2);
dp = (isHighPrecision ? 6 : 2);

auto mp = modulationDepth;
auto mn = -modulationDepth;
Expand Down Expand Up @@ -3280,7 +3281,8 @@ void Parameter::get_display_alt(char *txt, bool external, float ef) const
}
}

const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const auto isHighPrecision = Surge::Storage::getValueDisplayIsHighPrecision(storage);
const auto displayPrecision = Surge::Storage::getValueDisplayPrecision(storage);

txt[0] = 0;
switch (ctrltype)
Expand All @@ -3290,7 +3292,7 @@ void Parameter::get_display_alt(char *txt, bool external, float ef) const
{
float f = val.f;
float fInv = 0.f;
int dec = detailedMode ? 6 : displayInfo.decimals;
int dec = isHighPrecision ? 6 : displayInfo.decimals;
std::string u = "s";

fInv = 1.f / (displayInfo.a * powf(2.0f, f * displayInfo.b));
Expand Down Expand Up @@ -3447,7 +3449,8 @@ std::string Parameter::get_display(bool external, float ef) const
float f;
bool b;

const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const auto isHighPrecision = Surge::Storage::getValueDisplayIsHighPrecision(storage);
const auto displayPrecision = Surge::Storage::getValueDisplayPrecision(storage);

if (basicBlocksParamMetaData.has_value() && basicBlocksParamMetaData->supportsStringConversion)
{
Expand All @@ -3460,7 +3463,7 @@ std::string Parameter::get_display(bool external, float ef) const
bbf = basicBlocksParamMetaData->normalized01ToNatural(ef);

auto fs = sst::basic_blocks::params::ParamMetaData::FeatureState()
.withHighPrecision(detailedMode)
.withHighPrecision(displayPrecision)
.withTemposync(can_temposync() && temposync)
.withAbsolute(can_be_absolute() && absolute)
.withExtended(can_extend_range() && extend_range);
Expand Down Expand Up @@ -3529,7 +3532,7 @@ std::string Parameter::get_display(bool external, float ef) const
}

txt = fmt::format("{:.{}f} {:s}", displayInfo.scale * f,
(detailedMode ? 6 : displayInfo.decimals), u);
(isHighPrecision ? 6 : displayInfo.decimals), u);

if (f >= val_max.f &&
(displayInfo.customFeatures & ParamDisplayFeatures::kHasCustomMaxString))
Expand Down Expand Up @@ -3570,15 +3573,15 @@ std::string Parameter::get_display(bool external, float ef) const
getSemitonesOrKeys(u);

float dval = displayInfo.a * powf(2.0f, f * displayInfo.b);
int dec = detailedMode ? 6 : displayInfo.decimals;
int dec = isHighPrecision ? 6 : displayInfo.decimals;

if (displayInfo.customFeatures & ParamDisplayFeatures::kSwitchesFromSecToMillisec)
{
if (dval < 1.f)
{
dval *= 1000.f;
u = "ms";
dec = detailedMode ? 3 : 1;
dec = isHighPrecision ? 3 : 1;
}
}

Expand Down Expand Up @@ -3622,7 +3625,7 @@ std::string Parameter::get_display(bool external, float ef) const
}
else
{
txt = fmt::format("{:.{}f} dB", amp_to_db(f), (detailedMode ? 6 : 2));
txt = fmt::format("{:.{}f} dB", amp_to_db(f), (isHighPrecision ? 6 : 2));
}

return txt;
Expand All @@ -3640,26 +3643,27 @@ std::string Parameter::get_display(bool external, float ef) const
auto note = 69 + 69 * bpv;
auto freq = 440.0 * pow(2.0, (note - 69.0) / 12);

txt = fmt::format("{:.{}f} Hz", freq, (detailedMode ? 6 : 2));
txt = fmt::format("{:.{}f} Hz", freq, (isHighPrecision ? 6 : 2));
}
else
{
auto q = get_extended(f);

if (extend_range && q < 0)
{
txt = fmt::format("C : 1 / {:.{}f}", -get_extended(f), (detailedMode ? 6 : 2));
txt =
fmt::format("C : 1 / {:.{}f}", -get_extended(f), (isHighPrecision ? 6 : 2));
}
else
{
txt = fmt::format("C : {:.{}f}", get_extended(f), (detailedMode ? 6 : 2));
txt = fmt::format("C : {:.{}f}", get_extended(f), (isHighPrecision ? 6 : 2));
}
}
break;
}
case ct_chow_ratio:
{
txt = fmt::format("1 : {:.{}f}", f, (detailedMode ? 6 : 2));
txt = fmt::format("1 : {:.{}f}", f, (isHighPrecision ? 6 : 2));
break;
}
case ct_float_toggle:
Expand All @@ -3668,7 +3672,7 @@ std::string Parameter::get_display(bool external, float ef) const
break;
}
default:
txt = fmt::format("{:.{}f}", f, (detailedMode ? 6 : 2));
txt = fmt::format("{:.{}f}", f, (isHighPrecision ? 6 : 2));
break;
}
break;
Expand Down
14 changes: 10 additions & 4 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3498,14 +3498,20 @@ std::string base64_decode(std::string const &encoded_string)
return ret;
}

bool getValueDispPrecision(SurgeStorage *storage)
int getValueDisplayPrecision(SurgeStorage *storage)
{
return getValueDisplayIsHighPrecision(storage) ? 6 : 2;
}

bool getValueDisplayIsHighPrecision(SurgeStorage *storage)
{
bool isHigh{false};
if (storage)
{
return getUserDefaultValue(storage, HighPrecisionReadouts, false);
isHigh = getUserDefaultValue(storage, HighPrecisionReadouts, false);
}

return false;
return isHigh;
;
}

} // namespace Storage
Expand Down
3 changes: 2 additions & 1 deletion src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,8 @@ bool is_base64(unsigned char c);
std::string base64_encode(unsigned char const *bytes_to_encode, unsigned int in_len);
std::string base64_decode(std::string const &encoded_string);

bool getValueDispPrecision(SurgeStorage *storage);
int getValueDisplayPrecision(SurgeStorage *storage);
bool getValueDisplayIsHighPrecision(SurgeStorage *storage);

} // namespace Storage
} // namespace Surge
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/effects/airwindows/AirWindowsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void AirWindowsEffect::process(float *dataL, float *dataR)
void AirWindowsEffect::setupSubFX(int sfx, bool useStreamedValues)
{
const auto &r = fxreg[sfx];
const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const bool detailedMode = Surge::Storage::getValueDisplayIsHighPrecision(storage);
int dp = detailedMode ? 6 : 2;

airwin = r.create(r.id, storage->dsamplerate, dp); // FIXME
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/effects/airwindows/AirWindowsEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class alignas(16) AirWindowsEffect : public Effect
}

fx->airwin->displayPrecision =
Surge::Storage::getValueDispPrecision(fx->storage) ? 6 : 2;
Surge::Storage::getValueDisplayPrecision(fx->storage);
fx->airwin->getParameterLabel(idx, lab);
fx->airwin->getParameterDisplay(idx, dis, value, true);
}
Expand Down
5 changes: 3 additions & 2 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3435,12 +3435,13 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i
}
else
{
const bool detailedMode = Surge::Storage::getValueDispPrecision(&(this->synth->storage));
const int displayPrecision =
Surge::Storage::getValueDisplayPrecision(&(this->synth->storage));
auto cms = ((ControllerModulationSource *)synth->storage.getPatch()
.scene[current_scene]
.modsources[ms]);

ptxt3 = fmt::format("{:.{}f} %", 100.0 * cms->get_output(0), (detailedMode ? 6 : 2));
ptxt3 = fmt::format("{:.{}f} %", 100.0 * cms->get_output(0), displayPrecision);
strncpy(txt, ptxt3.c_str(), TXT_SIZE - 1);
ptxt1 = fmt::format("current: {:s}", txt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/surge-xt/gui/SurgeGUIEditorMenuStructures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,8 @@ juce::PopupMenu SurgeGUIEditor::makeValueDisplaysMenu(const juce::Point<int> &wh
{
auto dispDefMenu = juce::PopupMenu();

const bool detailedMode = Surge::Storage::getValueDispPrecision(&(this->synth->storage));
const bool detailedMode =
Surge::Storage::getValueDisplayIsHighPrecision(&(this->synth->storage));

dispDefMenu.addItem(Surge::GUI::toOSCase("High Precision Value Readouts"), true, detailedMode,
[this, detailedMode]() {
Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
bool cancellearn = false;
int ccid = 0;
const bool detailedMode =
Surge::Storage::getValueDispPrecision(&(this->synth->storage));
Surge::Storage::getValueDisplayIsHighPrecision(&(this->synth->storage));

// should start at 0, but it started at 1 before
// there might be a reason but I don't remember why
Expand Down
6 changes: 3 additions & 3 deletions src/surge-xt/gui/overlays/MSEGEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ struct MSEGCanvas : public juce::Component, public Surge::GUI::SkinConsumingComp
g.fillRect(r);
};

const int detailedMode = Surge::Storage::getValueDispPrecision(storage) ? 6 : 2;
const int detailedMode = Surge::Storage::getValueDisplayPrecision(storage);

g.setFont(skin->fontManager->lfoTypeFont);

Expand Down Expand Up @@ -2469,7 +2469,7 @@ struct MSEGCanvas : public juce::Component, public Surge::GUI::SkinConsumingComp
return;
}

const int detailedMode = Surge::Storage::getValueDispPrecision(storage) ? 6 : 2;
const int detailedMode = Surge::Storage::getValueDisplayPrecision(storage);

auto handleTypein = [this, i, prop, propValue, propName](const std::string &s) {
auto divPos = s.find('/');
Expand Down Expand Up @@ -2555,7 +2555,7 @@ struct MSEGCanvas : public juce::Component, public Surge::GUI::SkinConsumingComp

contextMenu.addSeparator();

const int detailedMode = Surge::Storage::getValueDispPrecision(storage) ? 6 : 2;
const int detailedMode = Surge::Storage::getValueDisplayPrecision(storage);

contextMenu.addItem(
fmt::format("Duration: {:.{}f}", ms->segments[tts].duration, detailedMode), true, false,
Expand Down
19 changes: 10 additions & 9 deletions src/surge-xt/gui/widgets/LFOAndStepDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,11 +1461,12 @@ void LFOAndStepDisplay::paintStepSeq(juce::Graphics &g)
// Finally draw the drag label
if (dragMode == VALUES && draggedStep >= 0 && draggedStep < n_stepseqsteps)
{
const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const int displayPrecision = Surge::Storage::getValueDisplayPrecision(storage);

g.setFont(skin->fontManager->lfoTypeFont);

std::string txt = fmt::format("{:.{}f} %", ss->steps[draggedStep] * 100.f, detailedMode);
std::string txt =
fmt::format("{:.{}f} %", ss->steps[draggedStep] * 100.f, displayPrecision);

int sw = SST_STRING_WIDTH_INT(g.getCurrentFont(), txt);

Expand Down Expand Up @@ -2661,10 +2662,9 @@ void LFOAndStepDisplay::showStepRMB(int i)

contextMenu.addSeparator();

const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const int precision = Surge::Storage::getValueDisplayPrecision(storage);

auto msg =
fmt::format("Edit Step {} Value: {:.{}f} %", i + 1, ss->steps[i] * 100.f, detailedMode);
auto msg = fmt::format("Edit Step {} Value: {:.{}f} %", i + 1, ss->steps[i] * 100.f, precision);

contextMenu.addItem(Surge::GUI::toOSCase(msg), true, false, [this, i]() { showStepTypein(i); });

Expand All @@ -2673,7 +2673,8 @@ void LFOAndStepDisplay::showStepRMB(int i)

void LFOAndStepDisplay::showStepTypein(int i)
{
const bool detailedMode = Surge::Storage::getValueDispPrecision(storage);
const bool isDetailed = Surge::Storage::getValueDisplayIsHighPrecision(storage);
const int precision = Surge::Storage::getValueDisplayPrecision(storage);

auto handleTypein = [this, i](const std::string &s) {
auto divPos = s.find('/');
Expand Down Expand Up @@ -2713,10 +2714,10 @@ void LFOAndStepDisplay::showStepTypein(int i)

stepEditor->callback = handleTypein;
stepEditor->setMainLabel(fmt::format("Edit Step {} Value", std::to_string(i + 1)));
stepEditor->setValueLabels(
fmt::format("current: {:.{}f} %", ss->steps[i] * 100.f, detailedMode), "");
stepEditor->setValueLabels(fmt::format("current: {:.{}f} %", ss->steps[i] * 100.f, precision),
"");
stepEditor->setSkin(skin, associatedBitmapStore);
stepEditor->setEditableText(fmt::format("{:.{}f} %", ss->steps[i] * 100.f, detailedMode));
stepEditor->setEditableText(fmt::format("{:.{}f} %", ss->steps[i] * 100.f, precision));
stepEditor->setReturnFocusTarget(stepSliderOverlays[i].get());

auto topOfControl = getY();
Expand Down
Loading