From 8852029296d96a729dec8ba0894797e47c547cc4 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 23 Aug 2021 20:16:28 -0400 Subject: [PATCH] Enough constness for XT (#4899) Final constness changes. No need for an open issue now. Do more as opportunity arriese but Closes #3808 --- src/common/SurgeStorage.cpp | 4 +-- src/common/SurgeStorage.h | 5 ++- src/common/SurgeSynthesizer.cpp | 36 ++++++++++----------- src/common/SurgeSynthesizer.h | 53 +++++++++++++++---------------- src/common/SurgeSynthesizerIO.cpp | 9 +----- 5 files changed, 47 insertions(+), 60 deletions(-) diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index bb1af0d04a4..f9c0f1a00fe 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -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) diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index c611ba68a59..fb653ca4cb6 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -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_list; diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 9d807c86955..ae90af99183 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -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::iterator iter; - iter = voices[s].begin(); + auto iter = voices[s].begin(); while (iter != voices[s].end()) { SurgeVoice *v = *iter; @@ -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::iterator iter; - iter = voices[s].begin(); + auto iter = voices[s].begin(); while (iter != voices[s].end()) { SurgeVoice *v = *iter; @@ -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); } @@ -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())) { @@ -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())) { @@ -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())) { @@ -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())) { @@ -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())) { @@ -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())) { @@ -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()) @@ -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(); diff --git a/src/common/SurgeSynthesizer.h b/src/common/SurgeSynthesizer.h index f6be0c48637..14d6995c9f5 100644 --- a/src/common/SurgeSynthesizer.h +++ b/src/common/SurgeSynthesizer.h @@ -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, 2> voices_array; unsigned int voices_usedby[2][MAX_VOICES]; // 0 indicates no user, 1 is scene A & 2 is scene B @@ -190,31 +190,31 @@ 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) { @@ -222,18 +222,18 @@ class alignas(16) SurgeSynthesizer } 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); } @@ -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(); @@ -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(); diff --git a/src/common/SurgeSynthesizerIO.cpp b/src/common/SurgeSynthesizerIO.cpp index ab594488c7a..9da47c7ac2a 100644 --- a/src/common/SurgeSynthesizerIO.cpp +++ b/src/common/SurgeSynthesizerIO.cpp @@ -483,19 +483,12 @@ void SurgeSynthesizer::loadRaw(const void *data, int size, bool preset) #include #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 {