From 024ec86dc54be20f43a113c97ab8b777e0ac96f0 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 7 Jun 2021 23:45:11 +0200 Subject: [PATCH] Unloading playlist on effect change. --- wled00/fcn_declare.h | 6 +++--- wled00/json.cpp | 14 ++++++++------ wled00/playlist.cpp | 2 +- wled00/presets.cpp | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index 6054b4b6..878f01c5 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -100,8 +100,8 @@ void handleIR(); #include "src/dependencies/json/AsyncJson-v6.h" #include "FX.h" -void deserializeSegment(JsonObject elem, byte it); -bool deserializeState(JsonObject root); +void deserializeSegment(JsonObject elem, byte it, bool fromPlaylist = false); +bool deserializeState(JsonObject root, bool fromPlaylist = false); void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true, uint8_t versionAPI = 1); void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true); void serializeInfo(JsonObject root); @@ -160,7 +160,7 @@ void loadPlaylist(JsonObject playlistObject); void handlePlaylist(); //presets.cpp -bool applyPreset(byte index); +bool applyPreset(byte index, bool fromPlaylist = false); void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject()); void deletePreset(byte index); diff --git a/wled00/json.cpp b/wled00/json.cpp index c6df7ed4..1a5b6c23 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -6,7 +6,7 @@ * JSON API (De)serialization */ -void deserializeSegment(JsonObject elem, byte it) +void deserializeSegment(JsonObject elem, byte it, bool fromPlaylist) { byte id = elem["id"] | it; if (id < strip.getMaxSegments()) @@ -127,6 +127,8 @@ void deserializeSegment(JsonObject elem, byte it) //temporary, strip object gets updated via colorUpdated() if (id == strip.getMainSegmentId()) { + // it may be a good idea to also stop playlist if effect has changed + if (!fromPlaylist && !elem["fx"].isNull()) unloadPlaylist(); effectCurrent = elem["fx"] | effectCurrent; effectSpeed = elem[F("sx")] | effectSpeed; effectIntensity = elem[F("ix")] | effectIntensity; @@ -188,7 +190,7 @@ void deserializeSegment(JsonObject elem, byte it) } } -bool deserializeState(JsonObject root) +bool deserializeState(JsonObject root, bool fromPlaylist) { strip.applyToAllSelected = false; bool stateResponse = root[F("v")] | false; @@ -284,20 +286,20 @@ bool deserializeState(JsonObject root) { if (lowestActive == 99) lowestActive = s; if (sg.isSelected()) { - deserializeSegment(segVar, s); + deserializeSegment(segVar, s, fromPlaylist); didSet = true; } } } - if (!didSet && lowestActive < strip.getMaxSegments()) deserializeSegment(segVar, lowestActive); + if (!didSet && lowestActive < strip.getMaxSegments()) deserializeSegment(segVar, lowestActive, fromPlaylist); } else { //set only the segment with the specified ID - deserializeSegment(segVar, id); + deserializeSegment(segVar, id, fromPlaylist); } } else { JsonArray segs = segVar.as(); for (JsonObject elem : segs) { - deserializeSegment(elem, it); + deserializeSegment(elem, it, fromPlaylist); it++; } } diff --git a/wled00/playlist.cpp b/wled00/playlist.cpp index 190e2fdc..ad526543 100644 --- a/wled00/playlist.cpp +++ b/wled00/playlist.cpp @@ -127,6 +127,6 @@ void handlePlaylist() { jsonTransitionOnce = true; transitionDelayTemp = playlistEntries[playlistIndex].tr * 100; playlistEntryDur = playlistEntries[playlistIndex].dur; - applyPreset(playlistEntries[playlistIndex].preset); + applyPreset(playlistEntries[playlistIndex].preset, true); } } diff --git a/wled00/presets.cpp b/wled00/presets.cpp index a01104de..c77baa60 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -4,7 +4,7 @@ * Methods to handle saving and loading presets to/from the filesystem */ -bool applyPreset(byte index) +bool applyPreset(byte index, bool fromPlaylist) { if (index == 0) return false; if (fileDoc) { // from POST "/json" handler (wled_server.cpp) @@ -14,7 +14,7 @@ bool applyPreset(byte index) #ifdef WLED_DEBUG_FS serializeJson(*fileDoc, Serial); #endif - deserializeState(fdo); + deserializeState(fdo, fromPlaylist); } else { DEBUGFS_PRINTLN(F("Make read buf")); DynamicJsonDocument fDoc(JSON_BUFFER_SIZE); @@ -24,7 +24,7 @@ bool applyPreset(byte index) #ifdef WLED_DEBUG_FS serializeJson(fDoc, Serial); #endif - deserializeState(fdo); + deserializeState(fdo, fromPlaylist); } if (!errorFlag) {