Skip to content

Commit

Permalink
Merge pull request #326 from baconpaul/idontwantnoblanks-282
Browse files Browse the repository at this point in the history
Dont allow blank patch names or categories
  • Loading branch information
baconpaul authored Jan 18, 2019
2 parents 3ebdaa4 + 7a8a8be commit 646c525
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "UserInteractions.h"
#include <set>
#include <numeric>
#include <cctype>
#include <vt_dsp/vt_dsp_endian.h>
#if MAC
#include <cstdlib>
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 8 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
35 changes: 30 additions & 5 deletions src/common/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "vstcontrols.h"
#include "SurgeBitmaps.h"
#include "CNumberField.h"
#include "UserInteractions.h"

#if TARGET_AUDIOUNIT
#include "aulayer.h"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 646c525

Please sign in to comment.