Skip to content

Commit

Permalink
Enough constness for XT
Browse files Browse the repository at this point in the history
Final constness changes. No need for an open issue now. Do more
as opportunity arriese but Closes surge-synthesizer#3808
  • Loading branch information
baconpaul committed Aug 23, 2021
1 parent 4ba47fd commit ee59e7e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ bool SurgeStorage::load_wt_wt_mem(const char *data, size_t dataSize, Wavetable *
return wasBuilt;
}

int SurgeStorage::get_clipboard_type() { return clipboard_type; }
int SurgeStorage::get_clipboard_type() const { return clipboard_type; }

int SurgeStorage::getAdjacentWaveTable(int id, bool nextPrev)
int SurgeStorage::getAdjacentWaveTable(int id, bool nextPrev) const
{
int n = wt_list.size();
if (!n)
Expand Down
5 changes: 2 additions & 3 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,8 @@ class alignas(16) SurgeStorage
std::string export_wt_wav_portable(std::string fbase, Wavetable *wt);
void clipboard_copy(int type, int scene, int entry);
void clipboard_paste(int type, int scene, int entry);
int get_clipboard_type();

int getAdjacentWaveTable(int id, bool nextPrev);
int get_clipboard_type() const;
int getAdjacentWaveTable(int id, bool nextPrev) const;

// The in-memory patch database.
std::vector<Patch> patch_list;
Expand Down
36 changes: 17 additions & 19 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,11 @@ void SurgeSynthesizer::enforcePolyphonyLimit(int s, int margin)
}
}

int SurgeSynthesizer::getNonUltrareleaseVoices(int s)
int SurgeSynthesizer::getNonUltrareleaseVoices(int s) const
{
int count = 0;

list<SurgeVoice *>::iterator iter;
iter = voices[s].begin();
auto iter = voices[s].begin();
while (iter != voices[s].end())
{
SurgeVoice *v = *iter;
Expand All @@ -488,12 +487,11 @@ int SurgeSynthesizer::getNonUltrareleaseVoices(int s)
return count;
}

int SurgeSynthesizer::getNonReleasedVoices(int s)
int SurgeSynthesizer::getNonReleasedVoices(int s) const
{
int count = 0;

list<SurgeVoice *>::iterator iter;
iter = voices[s].begin();
auto iter = voices[s].begin();
while (iter != voices[s].end())
{
SurgeVoice *v = *iter;
Expand Down Expand Up @@ -2882,7 +2880,7 @@ bool SurgeSynthesizer::setModulation(long ptag, modsources modsource, int index,
return true;
}

float SurgeSynthesizer::getMacroParameter01(long macroNum)
float SurgeSynthesizer::getMacroParameter01(long macroNum) const
{
return storage.getPatch().scene[0].modsources[ms_ctrl1 + macroNum]->get_output01(0);
}
Expand All @@ -2893,14 +2891,14 @@ void SurgeSynthesizer::setMacroParameter01(long macroNum, float val)
->set_target01(val, true);
}

float SurgeSynthesizer::getParameter01(long index)
float SurgeSynthesizer::getParameter01(long index) const
{
if (index >= 0 && index < storage.getPatch().param_ptr.size())
return storage.getPatch().param_ptr[index]->get_value_f01();
return 0.f;
}

void SurgeSynthesizer::getParameterDisplay(long index, char *text)
void SurgeSynthesizer::getParameterDisplay(long index, char *text) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2912,7 +2910,7 @@ void SurgeSynthesizer::getParameterDisplay(long index, char *text)
}
}

void SurgeSynthesizer::getParameterDisplayAlt(long index, char *text)
void SurgeSynthesizer::getParameterDisplayAlt(long index, char *text) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2924,7 +2922,7 @@ void SurgeSynthesizer::getParameterDisplayAlt(long index, char *text)
}
}

void SurgeSynthesizer::getParameterDisplay(long index, char *text, float x)
void SurgeSynthesizer::getParameterDisplay(long index, char *text, float x) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2934,7 +2932,7 @@ void SurgeSynthesizer::getParameterDisplay(long index, char *text, float x)
snprintf(text, TXT_SIZE, "-");
}

void SurgeSynthesizer::getParameterName(long index, char *text)
void SurgeSynthesizer::getParameterName(long index, char *text) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2949,7 +2947,7 @@ void SurgeSynthesizer::getParameterName(long index, char *text)
snprintf(text, TXT_SIZE, "-");
}

void SurgeSynthesizer::getParameterAccessibleName(long index, char *text)
void SurgeSynthesizer::getParameterAccessibleName(long index, char *text) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2964,7 +2962,7 @@ void SurgeSynthesizer::getParameterAccessibleName(long index, char *text)
snprintf(text, TXT_SIZE, "-");
}

void SurgeSynthesizer::getParameterMeta(long index, parametermeta &pm)
void SurgeSynthesizer::getParameterMeta(long index, parametermeta &pm) const
{
if ((index >= 0) && (index < storage.getPatch().param_ptr.size()))
{
Expand All @@ -2989,28 +2987,28 @@ void SurgeSynthesizer::getParameterMeta(long index, parametermeta &pm)
}
}

float SurgeSynthesizer::getParameter(long index)
float SurgeSynthesizer::getParameter(long index) const
{
if (index >= 0 && index < storage.getPatch().param_ptr.size())
return storage.getPatch().param_ptr[index]->get_value_f01();
return 0.f;
}

float SurgeSynthesizer::normalizedToValue(long index, float value)
float SurgeSynthesizer::normalizedToValue(long index, float value) const
{
if (index >= 0 && index < storage.getPatch().param_ptr.size())
return storage.getPatch().param_ptr[index]->normalized_to_value(value);
return 0.f;
}

float SurgeSynthesizer::valueToNormalized(long index, float value)
float SurgeSynthesizer::valueToNormalized(long index, float value) const
{
if (index >= 0 && index < storage.getPatch().param_ptr.size())
return storage.getPatch().param_ptr[index]->value_to_normalized(value);
return 0.f;
}

bool SurgeSynthesizer::stringToNormalizedValue(const ID &index, std::string s, float &outval)
bool SurgeSynthesizer::stringToNormalizedValue(const ID &index, std::string s, float &outval) const
{
int id = index.getSynthSideId();
if (id < 0 || id >= storage.getPatch().param_ptr.size())
Expand Down Expand Up @@ -4037,7 +4035,7 @@ void SurgeSynthesizer::reorderFx(int source, int target, FXReorderMode m)
refresh_editor = true;
}

bool SurgeSynthesizer::getParameterIsBoolean(const ID &id)
bool SurgeSynthesizer::getParameterIsBoolean(const ID &id) const
{
auto index = id.getSynthSideId();

Expand Down
53 changes: 25 additions & 28 deletions src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class alignas(16) SurgeSynthesizer
int calculateChannelMask(int channel, int key);
void softkillVoice(int scene);
void enforcePolyphonyLimit(int scene, int margin);
int getNonUltrareleaseVoices(int scene);
int getNonReleasedVoices(int scene);
int getNonUltrareleaseVoices(int scene) const;
int getNonReleasedVoices(int scene) const;

SurgeVoice *getUnusedVoice(int scene);
SurgeVoice *getUnusedVoice(int scene); // not const since it updates voice state
void freeVoice(SurgeVoice *);
std::array<std::array<SurgeVoice, MAX_VOICES>, 2> voices_array;
unsigned int voices_usedby[2][MAX_VOICES]; // 0 indicates no user, 1 is scene A & 2 is scene B
Expand Down Expand Up @@ -190,50 +190,50 @@ class alignas(16) SurgeSynthesizer
return i;
}

void getParameterDisplay(const ID &index, char *text)
void getParameterDisplay(const ID &index, char *text) const
{
getParameterDisplay(index.getSynthSideId(), text);
}
void getParameterDisplay(const ID &index, char *text, float x)
void getParameterDisplay(const ID &index, char *text, float x) const
{
getParameterDisplay(index.getSynthSideId(), text);
}
void getParameterDisplayAlt(const ID &index, char *text)
void getParameterDisplayAlt(const ID &index, char *text) const
{
getParameterDisplayAlt(index.getSynthSideId(), text);
}
void getParameterName(const ID &index, char *text)
void getParameterName(const ID &index, char *text) const
{
getParameterName(index.getSynthSideId(), text);
}
void getParameterAccessibleName(const ID &index, char *text)
void getParameterAccessibleName(const ID &index, char *text) const
{
getParameterAccessibleName(index.getSynthSideId(), text);
}
void getParameterMeta(const ID &index, parametermeta &pm)
void getParameterMeta(const ID &index, parametermeta &pm) const
{
getParameterMeta(index.getSynthSideId(), pm);
}
float getParameter01(const ID &index) { return getParameter01(index.getSynthSideId()); }
float getParameter01(const ID &index) const { return getParameter01(index.getSynthSideId()); }
bool setParameter01(const ID &index, float value, bool external = false,
bool force_integer = false)
{
return setParameter01(index.getSynthSideId(), value, external, force_integer);
}

void setMacroParameter01(long macroNum, float val);
float getMacroParameter01(long macroNum);
float getMacroParameter01(long macroNum) const;

bool getParameterIsBoolean(const ID &index);
bool getParameterIsBoolean(const ID &index) const;

bool stringToNormalizedValue(const ID &index, std::string s, float &outval);
bool stringToNormalizedValue(const ID &index, std::string s, float &outval) const;

float normalizedToValue(const ID &index, float val)
float normalizedToValue(const ID &index, float val) const
{
return normalizedToValue(index.getSynthSideId(), val);
}

float valueToNormalized(const ID &index, float val)
float valueToNormalized(const ID &index, float val) const
{
return valueToNormalized(index.getSynthSideId(), val);
}
Expand All @@ -246,16 +246,16 @@ class alignas(16) SurgeSynthesizer
private:
bool setParameter01(long index, float value, bool external = false, bool force_integer = false);
void sendParameterAutomation(long index, float value);
float getParameter01(long index);
float getParameter(long index);
float normalizedToValue(long parameterIndex, float value);
float valueToNormalized(long parameterIndex, float value);
void getParameterDisplay(long index, char *text);
void getParameterDisplay(long index, char *text, float x);
void getParameterDisplayAlt(long index, char *text);
void getParameterName(long index, char *text);
void getParameterAccessibleName(long index, char *text);
void getParameterMeta(long index, parametermeta &pm);
float getParameter01(long index) const;
float getParameter(long index) const;
float normalizedToValue(long parameterIndex, float value) const;
float valueToNormalized(long parameterIndex, float value) const;
void getParameterDisplay(long index, char *text) const;
void getParameterDisplay(long index, char *text, float x) const;
void getParameterDisplayAlt(long index, char *text) const;
void getParameterName(long index, char *text) const;
void getParameterAccessibleName(long index, char *text) const;
void getParameterMeta(long index, parametermeta &pm) const;

public:
void updateDisplay();
Expand Down Expand Up @@ -297,9 +297,6 @@ class alignas(16) SurgeSynthesizer

void swapMetaControllers(int ct1, int ct2);

std::string getUserPatchDirectory();
std::string getLegacyUserPatchDirectory();

void savePatchToPath(fs::path p);
void savePatch();
void updateUsedState();
Expand Down
9 changes: 1 addition & 8 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,12 @@ void SurgeSynthesizer::loadRaw(const void *data, int size, bool preset)
#include <sys/stat.h>
#endif

string SurgeSynthesizer::getUserPatchDirectory() { return storage.userDataPath; }
string SurgeSynthesizer::getLegacyUserPatchDirectory()
{
return storage.datapath + "patches_user" + PATH_SEPARATOR;
}

void SurgeSynthesizer::savePatch()
{
if (storage.getPatch().category.empty())
storage.getPatch().category = "Default";

fs::path savepath =
string_to_path(getUserPatchDirectory() + PATH_SEPARATOR + "Patches" + PATH_SEPARATOR);
fs::path savepath = string_to_path(storage.userPatchesPath);

try
{
Expand Down

0 comments on commit ee59e7e

Please sign in to comment.