diff --git a/Magical8bitPlug2.jucer b/Magical8bitPlug2.jucer index a4db363..a8b4e52 100644 --- a/Magical8bitPlug2.jucer +++ b/Magical8bitPlug2.jucer @@ -10,6 +10,10 @@ pluginDesc="8bit sound generator 2nd ver. by YMCK" displaySplashScreen="1" jucerFormatVersion="1" version="1.0.1"> + + + FrameSequenceParser::parseSegment (const String& input, return retval; } -FrameSequenceParser::SegmentIndexes FrameSequenceParser::findSegment(const String& input) { +SegmentIndexes FrameSequenceParser::findSegment(const String& input) { int releaseBlockIndex = -1; int repeatStartIndex = -1; int repeatEndIndex = -1; @@ -359,112 +359,11 @@ FrameSequence FrameSequenceParser::parse (const String& input, // // Overall structure // + SegmentIndexes si = findSegment(trimmed); - int releaseBlockIndex = -1; - int repeatStartIndex = -1; - int repeatEndIndex = -1; - int openBracketCount = 0; - int closeBracketCount = 0; - - // loop by character - for (int i = 0; i < trimmed.length(); i++) - { - if (trimmed[i] == '|') // found "|": - { - if (releaseBlockIndex >= 0) - { - // if releaseBlockIndex is already determined: Duplication Error - *error = kParseErrorDuplicatedReleaseDelimiter; - return fs; - } - - // if(repeatStartIndex >= 0) { - // // if appeard before "[" or "]": Repetition After Release Error - // throw new FrameSequenceParseException(TRANS("You cannot repeat in release phase"), true); - // } - // set releaseBlockIndex - releaseBlockIndex = i + 1; - - if (repeatEndIndex < 0) - { - // if "]" is omitted: Also set repeatEndIndex - repeatEndIndex = i; - } - } - - if (trimmed[i] == '[') /// found "[": - { - openBracketCount++; - - if (openBracketCount > 1) - { - // Duplication Error - *error = kParseErrorDuplicatedOpenBracket; - return fs; - } - - if (releaseBlockIndex >= 0) - { - // if repeat end is already defined: Repetition After Release Error - *error = kParseErrorRepeatingInReleaseBlock; - return fs; - } - - if (repeatEndIndex >= 0) - { - // if repeat end is already defined: Repetition After Release Error - *error = kParseErrorDuplicatedOpenBracket; - return fs; - } - - // set repeatStartIndex - repeatStartIndex = i + 1; - } - - if (trimmed[i] == ']') // found "]": - { - closeBracketCount++; - - if (closeBracketCount > 1) - { - // Duplication Error - *error = kParseErrorDuplicatedCloseBracket; - return fs; - } - - if (repeatStartIndex < 0) - { - // if repeatStartIndex hasn't set: Syntax Error - *error = kParseErrorUnmatchingCloseBracket; - return fs; - } - - if (releaseBlockIndex >= 0) - { - // if repeat end is already defined: Repetition After Release Error - *error = kParseErrorRepeatingInReleaseBlock; - return fs; - } - - repeatEndIndex = i; - } - } - - // if (releaseBlockIndex < 0) { // "|" didn't explicitly specified - // releaseBlockIndex = trimmed.length(); - // } - - if (openBracketCount != closeBracketCount) - { - *error = kParseErrorUnmatchingBracketNumber; - return fs; - } - - if (releaseBlockIndex - repeatEndIndex > 1) - { - // throw new FrameSequenceParseException(TRANS("Elements between repeat block and release block will be ignored"), false); - // FiXME: non-fatal exceptionをどう扱うか - } + int releaseBlockIndex = si.releaseBlockIndex; + int repeatStartIndex = si.repeatStartIndex; + int repeatEndIndex = si.repeatEndIndex; // Just for convenience bool hasRelease = (releaseBlockIndex >= 0); diff --git a/Source/FrameSequenceParser.h b/Source/FrameSequenceParser.h index 15ca5d5..dccc77a 100644 --- a/Source/FrameSequenceParser.h +++ b/Source/FrameSequenceParser.h @@ -13,6 +13,15 @@ #include "FrameSequence.h" #include "FrameSequenceParseErrors.h" +struct SegmentIndexes { + static const int NONE = -1; + + int releaseBlockIndex = NONE; + int repeatStartIndex = NONE; + int repeatEndIndex = NONE; + ParseError error; +}; + struct FrameSequenceParser { /* @@ -23,15 +32,6 @@ struct FrameSequenceParser /* Semantically private (leave them open for unit testing) */ - struct SegmentIndexes { - const int NONE = -1; - - int releaseBlockIndex = NONE; - int repeatStartIndex = NONE; - int repeatEndIndex = NONE; - ParseError error; - }; - std::vector parseSlope (const String& input, int minValue, int maxValue, diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 270ea3b..27b41f7 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -14,6 +14,7 @@ #include "TriangleVoice.h" #include "NoiseVoice.h" #include "FrameSequenceParseErrors.h" +#include "EnvelopeParserTest.h" //============================================================================== Magical8bitPlug2AudioProcessor::Magical8bitPlug2AudioProcessor() @@ -114,7 +115,7 @@ Magical8bitPlug2AudioProcessor::Magical8bitPlug2AudioProcessor() std::make_unique ("isPitchSequenceEnabled_raw", "Enabled", false), std::make_unique ("isDutySequenceEnabled_raw", "Enabled", false), std::make_unique ("pitchSequenceMode_raw", "Mode", StringArray ({"Coarse", "Fine"}), 0) -} + } ) , settingRefs (¶meters) #ifndef JucePlugin_PreferredChannelConfigurations @@ -132,6 +133,12 @@ Magical8bitPlug2AudioProcessor::Magical8bitPlug2AudioProcessor() setupVoice(); synth.addSound (new GenericSound()); + +#if JUCE_DEBUG + EnvelopeParserTest test; + UnitTestRunner runner; + runner.runAllTests(); +#endif } Magical8bitPlug2AudioProcessor::~Magical8bitPlug2AudioProcessor()