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

You can type in frequencies as note names #3871

Merged
merged 1 commit into from
Feb 11, 2021
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
41 changes: 41 additions & 0 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ void Parameter::set_type(int ctrltype)
displayInfo.b = 1.0f / 12.0f;
displayInfo.decimals = 2;
displayInfo.modulationCap = 880.f * powf(2.0, (val_max.f) / 12.0f);
displayInfo.supportsNoteName = true;
break;

case ct_freq_shift:
Expand Down Expand Up @@ -3281,6 +3282,46 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
}
case ATwoToTheBx:
{
if (displayInfo.supportsNoteName)
{
if ((s[0] >= 'a' && s[0] <= 'g') || (s[0] >= 'A' && s[0] <= 'G'))
{
int oct_offset = 0;
if (storage)
{
oct_offset = Surge::Storage::getUserDefaultValue(storage, "middleC", 1);
}
int note = 0, sf = 0;
if (s[0] >= 'a' && s[0] <= 'g')
{
note = s[0] - 'a';
}

if (s[0] >= 'A' && s[0] <= 'G')
{
note = s[0] - 'A';
}

int octPos = 1;
while (s[octPos] == '#')
{
sf++;
octPos++;
}
while (s[octPos] == 'b')
{
sf--;
octPos++;
}

auto oct = std::atoi(s.c_str() + octPos) + oct_offset;

std::vector<int> df6 = {9, 11, 0, 2, 4, 5, 7};

auto mn = df6[note] + (oct)*12 + sf;
nv = 440.0 * pow(2.0, (mn - 69) / 12.0);
}
}
/*
** v = a 2^bx
** log2(v/a) = bx
Expand Down
2 changes: 2 additions & 0 deletions src/common/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ class Parameter

float modulationCap = -1.f;

bool supportsNoteName = false;

float extendFactor = 1.0,
absoluteFactor = 1.0; // set these to 1 in case we sneak by and divide by accident
} displayInfo;
Expand Down