Skip to content

Commit

Permalink
RTTTL parser made case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
earlephilhower committed Mar 26, 2018
1 parent 582e6e7 commit 66d1f37
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/AudioGeneratorRTTTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ bool AudioGeneratorRTTTL::ParseHeader()
if (ptr >= len) return false;
if (buff[ptr++] != ':') return false;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != 'd') return false;
if ((buff[ptr] != 'd') && (buff[ptr] != 'D')) return false;
ptr++;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != '=') return false;
if (!ReadInt(&defaultDuration)) return false;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != ',') return false;

if (!SkipWhitespace()) return false;
if (buff[ptr++] != 'o') return false;
if ((buff[ptr] != 'o') && (buff[ptr] != 'O')) return false;
ptr++;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != '=') return false;
if (!ReadInt(&defaultOctave)) return false;
Expand All @@ -147,7 +149,8 @@ bool AudioGeneratorRTTTL::ParseHeader()

int bpm;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != 'b') return false;
if ((buff[ptr] != 'b') && (buff[ptr] != 'B')) return false;
ptr++;
if (!SkipWhitespace()) return false;
if (buff[ptr++] != '=') return false;
if (!ReadInt(&bpm)) return false;
Expand All @@ -156,8 +159,6 @@ bool AudioGeneratorRTTTL::ParseHeader()

wholeNoteMS = (60 * 1000 * 4) / bpm;

//Serial.printf("%d %d %d\n", defaultDuration, defaultOctave, wholeNoteMS);

return true;
}

Expand Down Expand Up @@ -228,14 +229,14 @@ bool AudioGeneratorRTTTL::GetNextNote()
if (ptr >= len) return false;
note = 0;
switch (buff[ptr++]) {
case 'c': note = 1; break;
case 'd': note = 3; break;
case 'e': note = 5; break;
case 'f': note = 6; break;
case 'g': note = 8; break;
case 'a': note = 10; break;
case 'b': note = 12; break;
case 'p': note = 0; break;
case 'c': case 'C': note = 1; break;
case 'd': case 'D': note = 3; break;
case 'e': case 'E': note = 5; break;
case 'f': case 'F': note = 6; break;
case 'g': case 'G': note = 8; break;
case 'a': case 'A': note = 10; break;
case 'b': case 'B': note = 12; break;
case 'p': case 'P': note = 0; break;
default: return false;
}
if ((ptr < len) && (buff[ptr] == '#')) {
Expand Down

0 comments on commit 66d1f37

Please sign in to comment.