#pragma once extern std::vector melody_steps; void setMelodyAttributes(JsonDocument doc); void loadMelodyInRAM(std::vector &melody_steps); void setMelodyAttributes(JsonDocument doc){ melody.name = doc["name"].as(); // Convert to std::string "name" : "eortastiko" melody.id = doc["id"].as(); melody.duration = doc["duration"].as(); melody.infinite_play = doc["infinite"].as(); melody.interval = doc["interval"].as(); melody.speed = doc["speed"].as(); melody.loop_duration = doc["loop_dur"].as(); // Print Just for Debugging Purposes Serial.printf("Name: %s, ID: %d, Total Duration: %lu, Loop Duration: %lu, Interval: %d, Speed: %d, Inf: %s\n", melody.name.c_str(), melody.id, melody.duration, melody.loop_duration, melody.interval, melody.speed, melody.infinite_play ? "true" : "false" ); } void loadMelodyInRAM(std::vector &melody_steps) { // read the file and save in RAM std::string filePath = "/" + melody.name + ".bin"; Serial.println("New Melody Selected !!!"); Serial.println("Reading data from file..."); //Serial.println(filePath); File bin_file = SPIFFS.open(filePath.c_str(), "r"); if (!bin_file) { Serial.println("Failed to Open File"); return; } size_t fileSize = bin_file.size(); size_t steps = fileSize / 2; melody_steps.resize(steps); Serial.print("Opened File ! Size: "); Serial.print(fileSize); Serial.print(" Steps: "); Serial.println(steps); for (size_t i=0; i