From 5d65c4efda1ea3e811bf17a1a38909696e381062 Mon Sep 17 00:00:00 2001 From: Vladyslav Heneraliuk Date: Sat, 17 Aug 2024 17:44:00 +0300 Subject: [PATCH] removed FS and SPIFFS load functions --- src/melody_factory.cpp | 51 ---------------------- src/melody_factory.h | 20 --------- src/melody_factory_rtttl.cpp | 84 ------------------------------------ 3 files changed, 155 deletions(-) diff --git a/src/melody_factory.cpp b/src/melody_factory.cpp index fd36d61..000d007 100644 --- a/src/melody_factory.cpp +++ b/src/melody_factory.cpp @@ -26,57 +26,6 @@ static void removeCarriageReturn(String& s) { if (s.charAt(s.length() - 1) == '\r') { s = s.substring(0, s.length() - 1); } } -Melody MelodyFactoryClass::load(String filepath, FS& fs) { - File f = fs.open(filepath, "r"); - f.setTimeout(0); - - if (!f) { - if (debug) Serial.println("Opening file error"); - return Melody(); - } - - // Skip multi-line comments at the begin of the file - String line = f.readStringUntil('\n'); - while (line.charAt(0) == '#') { line = f.readStringUntil('\n'); } - - bool success = false; - success = loadTitle(line); - if (!success) { return Melody(); } - - success = loadTimeUnit(f.readStringUntil('\n')); - if (!success) { return Melody(); } - - success = loadNumberOfNotes(f.readStringUntil('\n')); - if (!success) { return Melody(); } - - NoteFormat noteFormat = loadNoteFormat(f.readStringUntil('\n')); - if (noteFormat == NoteFormat::ERROR) { - return Melody(); - } else { - this->noteFormat = noteFormat; - } - - if (debug) - Serial.println(String("This melody object will take at least: ") + (sizeof(NoteDuration) * nNotes) + "bytes"); - if (nNotes < maxLength) { - notes = std::make_shared>(); - notes->reserve(nNotes); - bool error = false; - while (f.available() && notes->size() < nNotes && !error) { - // get a token - String noteDuration = f.readStringUntil('|'); - error = !loadNote(noteDuration); - } - - if (error) { - if (debug) Serial.println("error during the tokens loading!"); - return Melody(); - } - } - - return Melody(title, timeUnit, notes, true); -} - Melody MelodyFactoryClass::load(String title, unsigned short timeUnit, String notesToLoad[], unsigned short nNotesToLoad, bool autoSilence) { if (title.length() == 0 && timeUnit <= 20) { return Melody(); } diff --git a/src/melody_factory.h b/src/melody_factory.h index 2bc4c13..c1db0cb 100644 --- a/src/melody_factory.h +++ b/src/melody_factory.h @@ -22,28 +22,8 @@ #include "melody.h" -#include -#ifdef ESP32 -#include -#endif - class MelodyFactoryClass { public: - /** - * Load the melody from file in MelodyPlayer format. - */ - Melody load(String filePath, FS& fs = SPIFFS); - - /** - * Load melody from file in RTTTL format. The file must contain only one melody. - */ - Melody loadRtttlFile(String filePath, FS& fs = SPIFFS); - - /** - * Load melody with the given title from a file containing multiple RTTTL melody (one Melody per - * line). - */ - Melody loadRtttlDB(String filepath, String title, FS& fs = SPIFFS); /** * Load melody from string in RTTTL format. diff --git a/src/melody_factory_rtttl.cpp b/src/melody_factory_rtttl.cpp index 65e0733..1315298 100644 --- a/src/melody_factory_rtttl.cpp +++ b/src/melody_factory_rtttl.cpp @@ -90,90 +90,6 @@ const uint16_t sourceNotes[] = { }; // clang-format on -Melody MelodyFactoryClass::loadRtttlFile(String filepath, FS& fs) { - File f = fs.open(filepath, "r"); - f.setTimeout(0); - - if (!f) { - if (debug) Serial.println("Opening file error"); - return Melody(); - } - - String title = f.readStringUntil(':'); - title.trim(); - if (debug) Serial.println(String("Title:") + title); - if (title.length() == 0) { return Melody(); } - - String values = f.readStringUntil(':'); - values.trim(); - if (debug) Serial.println(String("Default values:") + values); - if (values.length() == 0) { return Melody(); } - - parseDefaultValues(values); - - // 32 because it is the shortest note! - int timeUnit = 60 * 1000 * 4 / beat / 32; - - notes = std::make_shared>(); - bool result = true; - while (f.available() && notes->size() < maxLength && result) { - String s = f.readStringUntil(','); - s.trim(); - result = parseRtttlNote(s); - } - if (result && notes->size() > 0) { return Melody(title, timeUnit, notes, false); } - - return Melody(); -} - -Melody MelodyFactoryClass::loadRtttlDB(String filepath, String title, FS& fs) { - File f = fs.open(filepath, "r"); - f.setTimeout(0); - - if (!f) { - if (debug) Serial.println("Opening file error"); - return Melody(); - } - - if (title.length() == 0) { - if (debug) Serial.println("Title length = 0"); - return Melody(); - } - - if (!f.find(title.c_str())) { - if (debug) Serial.println("Unable to find melody with title: " + String(title)); - return Melody(); - } - f.readStringUntil(':'); - - String values = f.readStringUntil(':'); - values.trim(); - if (debug) Serial.println(String("Default values:") + values); - if (values.length() == 0) { return Melody(); } - - parseDefaultValues(values); - - // 32 because it is the shortest note! - int timeUnit = 60 * 1000 * 4 / beat / 32; - - size_t position = f.position(); - int bytesUntilNewLine = f.readStringUntil('\n').length(); - f.seek(position); - - notes = std::make_shared>(); - bool result = true; - while (f.available() && notes->size() < maxLength && result && bytesUntilNewLine > 0) { - String s = f.readStringUntil(','); - if (s.length() > bytesUntilNewLine) { s = s.substring(0, bytesUntilNewLine); } - bytesUntilNewLine -= s.length() + 1; - s.trim(); - result = parseRtttlNote(s); - } - if (result && notes->size() > 0) { return Melody(title, timeUnit, notes, false); } - - return Melody(); -} - Melody MelodyFactoryClass::loadRtttlString(const char rtttlMelody[]) { String title; int i = 0;