Skip to content

Commit

Permalink
Const Sweep First Step (#4764)
Browse files Browse the repository at this point in the history
this change changes std::string args to const std::string & args
most places I see them incorrect. Still to do is the get arguments
get a const signature and stuff but that can come later

Addresses #3808
  • Loading branch information
baconpaul authored Jul 20, 2021
1 parent 93b26ad commit 0216133
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/common/DebugHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Surge::Debug::stackTraceToStdout(int depth)
}

static std::atomic<int> lcdepth(0);
Surge::Debug::LifeCycleToConsole::LifeCycleToConsole(std::string st) : s(st)
Surge::Debug::LifeCycleToConsole::LifeCycleToConsole(const std::string &st) : s(st)
{
lcdepth++;
for (int i = 0; i < lcdepth; ++i)
Expand Down
2 changes: 1 addition & 1 deletion src/common/DebugHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void stackTraceToStdout(int depth = -1); // no-op on Windows; shows stack trace

struct LifeCycleToConsole
{ // simple class which printfs in ctor and dtor
LifeCycleToConsole(std::string s);
LifeCycleToConsole(const std::string &s);
~LifeCycleToConsole();
std::string s;
};
Expand Down
4 changes: 2 additions & 2 deletions src/common/FilterConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ struct FilterSelectorMapper : public ParameterDiscreteIndexRemapper
{
std::vector<std::pair<int, std::string>> mapping;
std::unordered_map<int, int> inverseMapping;
void p(int i, std::string s) { mapping.push_back(std::make_pair(i, s)); }
void p(int i, const std::string &s) { mapping.push_back(std::make_pair(i, s)); }
FilterSelectorMapper()
{
p(fut_none, "");
Expand Down Expand Up @@ -475,7 +475,7 @@ struct WaveShaperSelectorMapper : public ParameterDiscreteIndexRemapper
{
std::vector<std::pair<int, std::string>> mapping;
std::unordered_map<int, int> inverseMapping;
void p(int i, std::string s) { mapping.emplace_back(i, s); }
void p(int i, const std::string &s) { mapping.emplace_back(i, s); }
WaveShaperSelectorMapper()
{
// Obviously improve this
Expand Down
39 changes: 22 additions & 17 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3758,9 +3758,12 @@ bool Parameter::can_setvalue_from_string()
return false;
}

bool Parameter::set_value_from_string(std::string s) { return set_value_from_string_onto(s, val); }
bool Parameter::set_value_from_string(const std::string &s)
{
return set_value_from_string_onto(s, val);
}

bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
bool Parameter::set_value_from_string_onto(const std::string &s, pdata &ontoThis)
{
const char *c = s.c_str();

Expand Down Expand Up @@ -3811,13 +3814,14 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
int neg = 1;

// convert string to lowercase
std::for_each(s.begin(), s.end(),
auto lowerS = s;
std::for_each(lowerS.begin(), lowerS.end(),
[](char &c) { c = ::tolower(static_cast<unsigned char>(c)); });

// find the unmodified note
for (int i = 0; i < 7; i++)
{
n = s.find(notes[i]);
n = lowerS.find(notes[i]);
if (n != std::string::npos)
{
val = pitches[i];
Expand All @@ -3827,31 +3831,32 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)

// check if the following character is sharp or flat, adjust val if so
n++;
if ((m = s.find("#", n, 1)) != std::string::npos)
if ((m = lowerS.find("#", n, 1)) != std::string::npos)
{
val += 1;
n++;
}
else if ((m = s.find("b", n, 1)) != std::string::npos)
else if ((m = lowerS.find("b", n, 1)) != std::string::npos)
{
val -= 1;
n++;
}

// if neither note modifiers are found, check for minus
if ((m = s.find("-", n, 1)) != std::string::npos)
if ((m = lowerS.find("-", n, 1)) != std::string::npos)
{
neg = -1;
n++;
}

// finally, octave number
s = s.substr(n, s.length() - n); // trim the fat to the left of current char
auto q = lowerS.substr(n, lowerS.length() -
n); // trim the fat to the left of current char

int oct;
try
{
oct = std::stoi(s);
oct = std::stoi(q);
}
catch (std::invalid_argument const &)
{
Expand All @@ -3873,7 +3878,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)

if (ni >= val_min.i && ni <= val_max.i)
{
onto.i = ni;
ontoThis.i = ni;
return true;
}

Expand All @@ -3895,7 +3900,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
float f;
if (ef->stringToValue(this, c, f))
{
onto.f = limit_range(f, val_min.f, val_max.f);
ontoThis.f = limit_range(f, val_min.f, val_max.f);
return true;
}
}
Expand All @@ -3921,7 +3926,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
return false;
}

onto.f = res;
ontoThis.f = res;
return true;

break;
Expand Down Expand Up @@ -3980,7 +3985,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
{
return false;
}
onto.f = res;
ontoThis.f = res;
return true;
break;
}
Expand All @@ -4004,7 +4009,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
return false;
}

onto.f = nv;
ontoThis.f = nv;
return true;
}
break;
Expand All @@ -4018,7 +4023,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
{
return false;
}
onto.f = nv;
ontoThis.f = nv;
return true;
}
break;
Expand All @@ -4029,7 +4034,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
float uv = std::atof(c) / 440.f;
float n = log2(uv) * 12 + 69;
float bpv = (n - 69) / 69.f;
onto.f = bpv * 16 + 16;
ontoThis.f = bpv * 16 + 16;
}
else
{
Expand Down Expand Up @@ -4071,7 +4076,7 @@ bool Parameter::set_value_from_string_onto(std::string s, pdata &onto)
nv = (nv - 1) * 16.f / 31.f + 16;
}
}
onto.f = nv;
ontoThis.f = nv;
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/common/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ class Parameter
float value_to_normalized(float value);
float get_default_value_f01();
void set_value_f01(float v, bool force_integer = false);
bool set_value_from_string(std::string s);
bool set_value_from_string_onto(std::string s, pdata &ontoThis);
bool set_value_from_string(const std::string &s);
bool set_value_from_string_onto(const std::string &s, pdata &ontoThis);

/*
* These two functions convert the modulation depth to a -1,1 range appropriate
Expand Down
4 changes: 2 additions & 2 deletions src/common/SkinColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Skin
{
struct Color
{
Color(std::string name, int r, int g, int b);
Color(std::string name, int r, int g, int b, int a);
Color(const std::string &name, int r, int g, int b);
Color(const std::string &name, int r, int g, int b, int a);

static Color colorByName(const std::string &name);
static std::vector<Color> getAllColors();
Expand Down
2 changes: 1 addition & 1 deletion src/common/SkinModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ struct Connector

Connector &asJogPlusMinus() noexcept;

Connector &withProperty(Component::Properties p, std::string v)
Connector &withProperty(Component::Properties p, const std::string &v)
{
payload->properties[p] = v;
return *this;
Expand Down
5 changes: 3 additions & 2 deletions src/common/SkinModelImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,13 @@ std::vector<Connector> Connector::connectorsByComponentType(const Component &c)
return res;
}

Color::Color(std::string name, int r, int g, int b) : name(name), r(r), g(g), b(b), a(255)
Color::Color(const std::string &name, int r, int g, int b) : name(name), r(r), g(g), b(b), a(255)
{
guaranteeMap();
colMap->insert(std::make_pair(name, *this));
}
Color::Color(std::string name, int r, int g, int b, int a) : name(name), r(r), g(g), b(b), a(a)
Color::Color(const std::string &name, int r, int g, int b, int a)
: name(name), r(r), g(g), b(b), a(a)
{
guaranteeMap();
colMap->insert(std::make_pair(name, *this));
Expand Down
2 changes: 1 addition & 1 deletion src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

using namespace std;

SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, std::string suppliedDataPath)
SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, const std::string &suppliedDataPath)
: storage(suppliedDataPath), hpA(&storage), hpB(&storage), _parent(parent), halfbandA(6, true),
halfbandB(6, true), halfbandIN(6, true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class alignas(16) SurgeSynthesizer
virtual void surgeParameterUpdated(const ID &, float) = 0;
virtual void surgeMacroUpdated(long macroNum, float) = 0;
};
SurgeSynthesizer(PluginLayer *parent, std::string suppliedDataPath = "");
SurgeSynthesizer(PluginLayer *parent, const std::string &suppliedDataPath = "");
virtual ~SurgeSynthesizer();
void playNote(char channel, char key, char velocity, char detune);
void releaseNote(char channel, char key, char velocity);
Expand Down
9 changes: 6 additions & 3 deletions src/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,10 @@ bool Skin::reloadSkin(std::shared_ptr<SurgeImageStore> bitmapStore)
return true;
}

bool Skin::setAllCapsProperty(std::string propertyValue)
bool Skin::setAllCapsProperty(const std::string &propertyValueA)
{
// make the property value not case sensitive
auto propertyValue = propertyValueA;
std::transform(propertyValue.begin(), propertyValue.end(), propertyValue.begin(),
[](unsigned char c) { return std::tolower(c); });

Expand All @@ -742,9 +743,10 @@ bool Skin::setAllCapsProperty(std::string propertyValue)
}
}

juce::Font::FontStyleFlags Skin::setFontStyleProperty(std::string propertyValue)
juce::Font::FontStyleFlags Skin::setFontStyleProperty(const std::string &propertyValueA)
{
// make the property value not case sensitive
auto propertyValue = propertyValueA;
std::transform(propertyValue.begin(), propertyValue.end(), propertyValue.begin(),
[](unsigned char c) { return std::tolower(c); });

Expand All @@ -766,9 +768,10 @@ juce::Font::FontStyleFlags Skin::setFontStyleProperty(std::string propertyValue)
}
}

juce::Justification Skin::setJuceTextAlignProperty(std::string propertyValue)
juce::Justification Skin::setJuceTextAlignProperty(const std::string &propertyValueA)
{
// make the property value not case sensitive
auto propertyValue = propertyValueA;
std::transform(propertyValue.begin(), propertyValue.end(), propertyValue.begin(),
[](unsigned char c) { return std::tolower(c); });

Expand Down
12 changes: 6 additions & 6 deletions src/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class Skin
#endif
}

static bool setAllCapsProperty(std::string propertyValue);
static juce::Font::FontStyleFlags setFontStyleProperty(std::string propertyValue);
static juce::Justification setJuceTextAlignProperty(std::string propertyValue);
static bool setAllCapsProperty(const std::string &propertyValue);
static juce::Font::FontStyleFlags setFontStyleProperty(const std::string &propertyValue);
static juce::Justification setJuceTextAlignProperty(const std::string &propertyValue);

std::string root;
std::string name;
Expand Down Expand Up @@ -385,9 +385,9 @@ class Skin

Type type;
ColorStore() : type(COLOR), color(juce::Colours::black) {}
ColorStore(juce::Colour c) : type(COLOR), color(c) {}
ColorStore(std::string a) : type(ALIAS), alias(a) {}
ColorStore(std::string a, Type t) : type(t), alias(a) {}
ColorStore(const juce::Colour &c) : type(COLOR), color(c) {}
ColorStore(const std::string &a) : type(ALIAS), alias(a) {}
ColorStore(const std::string &a, Type t) : type(t), alias(a) {}
};
std::unordered_map<std::string, ColorStore> colors;
std::unordered_map<std::string, int> imageStringToId;
Expand Down
16 changes: 8 additions & 8 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ void SurgeGUIEditor::showTuningMenu(const juce::Point<int> &where,
});
}

void SurgeGUIEditor::scaleFileDropped(std::string fn)
void SurgeGUIEditor::scaleFileDropped(const string &fn)
{
try
{
Expand All @@ -1778,7 +1778,7 @@ void SurgeGUIEditor::scaleFileDropped(std::string fn)
}
}

void SurgeGUIEditor::mappingFileDropped(std::string fn)
void SurgeGUIEditor::mappingFileDropped(const string &fn)
{
try
{
Expand Down Expand Up @@ -3517,23 +3517,23 @@ std::string SurgeGUIEditor::helpURLFor(Parameter *p)
return "";
}

std::string SurgeGUIEditor::helpURLForSpecial(std::string key)
std::string SurgeGUIEditor::helpURLForSpecial(const string &special)
{
auto storage = &(synth->storage);
return helpURLForSpecial(storage, key);
return helpURLForSpecial(storage, special);
}

std::string SurgeGUIEditor::helpURLForSpecial(SurgeStorage *storage, std::string key)
std::string SurgeGUIEditor::helpURLForSpecial(SurgeStorage *storage, const std::string &special)
{
if (storage->helpURL_specials.find(key) != storage->helpURL_specials.end())
if (storage->helpURL_specials.find(special) != storage->helpURL_specials.end())
{
auto r = storage->helpURL_specials[key];
auto r = storage->helpURL_specials[special];
if (r != "")
return r;
}
return "";
}
std::string SurgeGUIEditor::fullyResolvedHelpURL(std::string helpurl)
std::string SurgeGUIEditor::fullyResolvedHelpURL(const string &helpurl)
{
std::string lurl = helpurl;
if (helpurl[0] == '#')
Expand Down
13 changes: 7 additions & 6 deletions src/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,

void toggleMPE();
void toggleTuning();
void scaleFileDropped(std::string fn);
void mappingFileDropped(std::string fn);
void scaleFileDropped(const std::string &fn);
void mappingFileDropped(const std::string &fn);
std::string tuningToHtml();

void modSourceButtonDroppedAt(Surge::Widgets::ModulationSourceButton *msb,
Expand Down Expand Up @@ -356,7 +356,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,

std::string getDisplayForTag(long tag);

void queuePatchFileLoad(std::string file)
void queuePatchFileLoad(const std::string &file)
{
strncpy(synth->patchid_file, file.c_str(), FILENAME_MAX);
synth->has_patchid_file = true;
Expand Down Expand Up @@ -589,10 +589,11 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,

public:
std::string helpURLFor(Parameter *p); // this requires internal state so doesn't have statics
std::string helpURLForSpecial(std::string special); // these can be either this way or static
std::string
helpURLForSpecial(const std::string &special); // these can be either this way or static

static std::string helpURLForSpecial(SurgeStorage *, std::string special);
static std::string fullyResolvedHelpURL(std::string helpurl);
static std::string helpURLForSpecial(SurgeStorage *storage, const std::string &special);
static std::string fullyResolvedHelpURL(const std::string &helpurl);

private:
void promptForUserValueEntry(Parameter *p, juce::Component *c, int modulationSource = -1);
Expand Down
Loading

0 comments on commit 0216133

Please sign in to comment.