Skip to content

Commit

Permalink
refactor rtttl melody loading from DB file, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianoriccardi committed Aug 18, 2022
1 parent bc1bd1f commit 114305d
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 34 deletions.
26 changes: 24 additions & 2 deletions examples/4_load_rtttl_melody/4_load_rtttl_melody.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
int buzzerPin = 4;

String melodyFilePath = "/pokemon.rtttl";
String DBFilePath = "/RingTones.RTTTL.txt";

const char melodyString[] = "Pokemon:d=16,o=5,b=112:32p,f,a#,c6,c#6,c6,c#6,d#6,2f6,a#,c6,8c#6,8f6,"
"8d#6,32c#.6,32d#.6,32c#.6,8c6,8g#.,f,a#,c6,c#6,c6,c#6,d#6,2f6,8a#,c#6,"
Expand All @@ -28,7 +29,9 @@ void setup() {
Melody melody = MelodyFactory.loadRtttlString(melodyString);
if (melody) {
Serial.println("Done!");
Serial.print("Playing... ");
Serial.print("Playing ");
Serial.print(melody.getTitle());
Serial.print("... ");
player.play(melody);
Serial.println("Done!");
} else {
Expand All @@ -47,7 +50,26 @@ void setup() {
Serial.println("Error");
} else {
Serial.println("Done!");
Serial.print("Playing... ");

Serial.print("Playing ");
Serial.print(melody.getTitle());
Serial.print("... ");
player.play(melody);
Serial.println("Done!");
}

delay(1000);
Serial.println();

Serial.print("Loading melody from DB... ");
melody = MelodyFactory.loadRtttlDB(DBFilePath, "Axel");
if (!melody) {
Serial.println("Error");
} else {
Serial.println("Done!");
Serial.print("Playing ");
Serial.print(melody.getTitle());
Serial.print("... ");
player.play(melody);
Serial.println("Done!");
}
Expand Down
Loading

3 comments on commit 114305d

@aaronkirschen
Copy link
Contributor

@aaronkirschen aaronkirschen commented on 114305d Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the loadRtttlDB method and it works great. The example uses a .txt db file instead of .rtttl, but I think that was intentional to indicate that the file does not follow the official rtttl spec.

Thanks, I appreciate you integrating this.

@fabianoriccardi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the loadRtttlDB method and it works great. The example uses a .txt db file instead of .rtttl, but I think that was intentional to indicate that the file does not follow the official rtttl spec.

Yes, I excluded the use of rtttl extension since it is out of specs. Probably txt is too generic, and rtttl.db or rtttll (where the last L stands for "line") is a more suitable alternative.

@fabianoriccardi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just released the update of the library containing this feature, it should be available in few hour on the Library Registry.

Please sign in to comment.