diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index 715aa27d78d..c37b69653ae 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -7,6 +7,7 @@ #include "UserInteractions.h" #include #include +#include #include #if MAC #include @@ -1000,3 +1001,23 @@ float envelope_rate_linear(float x) return (1 - a) * table_envrate_linear[e & 0x1ff] + a * table_envrate_linear[(e + 1) & 0x1ff]; } + +namespace Surge +{ + namespace Storage + { + bool isValidName(const std::string &patchName) + { + bool valid = false; + + // No need to validate size separately as an empty string won't have visible characters. + for (const char &c : patchName) + if (std::isalnum(c) || std::ispunct(c)) + valid = true; + else if (c != ' ') + return false; + + return valid; + } + } +} diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index bd043e2ae2e..dbe594c32be 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -545,3 +545,11 @@ float lookup_waveshape(int, float); float lookup_waveshape_warp(int, float); float envelope_rate_lpf(float); float envelope_rate_linear(float); + +namespace Surge +{ +namespace Storage +{ + bool isValidName(const std::string &name); +} +} diff --git a/src/common/gui/SurgeGUIEditor.cpp b/src/common/gui/SurgeGUIEditor.cpp index 53933ce00ba..d89342e9fd3 100644 --- a/src/common/gui/SurgeGUIEditor.cpp +++ b/src/common/gui/SurgeGUIEditor.cpp @@ -19,6 +19,7 @@ #include "vstcontrols.h" #include "SurgeBitmaps.h" #include "CNumberField.h" +#include "UserInteractions.h" #if TARGET_AUDIOUNIT #include "aulayer.h" @@ -2127,11 +2128,35 @@ void SurgeGUIEditor::valueChanged(CControl* control) // frame->setModalView(nullptr); frame->setDirty(); - synth->storage.getPatch().name = patchName->getText(); - synth->storage.getPatch().author = patchCreator->getText(); - synth->storage.getPatch().category = patchCategory->getText(); - synth->storage.getPatch().comment = patchComment->getText(); - synth->savePatch(); + /* + ** Don't allow a blank patch + */ + std::string whatIsBlank = ""; + bool haveBlanks = false; + + if (! Surge::Storage::isValidName(patchName->getText().getString())) + { + whatIsBlank = "name"; haveBlanks = true; + } + if (! Surge::Storage::isValidName(patchCategory->getText().getString())) + { + whatIsBlank = whatIsBlank + (haveBlanks? " and category" : "category"); haveBlanks = true; + } + if (haveBlanks) + { + Surge::UserInteractions::promptError(std::string("Unable to store a patch due to invalid ") + + whatIsBlank + ". Please save again and provide a complete " + + whatIsBlank + ".", + "Error saving patch"); + } + else + { + synth->storage.getPatch().name = patchName->getText(); + synth->storage.getPatch().author = patchCreator->getText(); + synth->storage.getPatch().category = patchCategory->getText(); + synth->storage.getPatch().comment = patchComment->getText(); + synth->savePatch(); + } } break; default: