Unloading playlist on effect change.

This commit is contained in:
Blaz Kristan 2021-06-07 23:45:11 +02:00
parent f632ef0de8
commit 024ec86dc5
4 changed files with 15 additions and 13 deletions

View File

@ -100,8 +100,8 @@ void handleIR();
#include "src/dependencies/json/AsyncJson-v6.h" #include "src/dependencies/json/AsyncJson-v6.h"
#include "FX.h" #include "FX.h"
void deserializeSegment(JsonObject elem, byte it); void deserializeSegment(JsonObject elem, byte it, bool fromPlaylist = false);
bool deserializeState(JsonObject root); 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 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 serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true);
void serializeInfo(JsonObject root); void serializeInfo(JsonObject root);
@ -160,7 +160,7 @@ void loadPlaylist(JsonObject playlistObject);
void handlePlaylist(); void handlePlaylist();
//presets.cpp //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 savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
void deletePreset(byte index); void deletePreset(byte index);

View File

@ -6,7 +6,7 @@
* JSON API (De)serialization * JSON API (De)serialization
*/ */
void deserializeSegment(JsonObject elem, byte it) void deserializeSegment(JsonObject elem, byte it, bool fromPlaylist)
{ {
byte id = elem["id"] | it; byte id = elem["id"] | it;
if (id < strip.getMaxSegments()) if (id < strip.getMaxSegments())
@ -127,6 +127,8 @@ void deserializeSegment(JsonObject elem, byte it)
//temporary, strip object gets updated via colorUpdated() //temporary, strip object gets updated via colorUpdated()
if (id == strip.getMainSegmentId()) { 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; effectCurrent = elem["fx"] | effectCurrent;
effectSpeed = elem[F("sx")] | effectSpeed; effectSpeed = elem[F("sx")] | effectSpeed;
effectIntensity = elem[F("ix")] | effectIntensity; 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; strip.applyToAllSelected = false;
bool stateResponse = root[F("v")] | false; bool stateResponse = root[F("v")] | false;
@ -284,20 +286,20 @@ bool deserializeState(JsonObject root)
{ {
if (lowestActive == 99) lowestActive = s; if (lowestActive == 99) lowestActive = s;
if (sg.isSelected()) { if (sg.isSelected()) {
deserializeSegment(segVar, s); deserializeSegment(segVar, s, fromPlaylist);
didSet = true; 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 } else { //set only the segment with the specified ID
deserializeSegment(segVar, id); deserializeSegment(segVar, id, fromPlaylist);
} }
} else { } else {
JsonArray segs = segVar.as<JsonArray>(); JsonArray segs = segVar.as<JsonArray>();
for (JsonObject elem : segs) for (JsonObject elem : segs)
{ {
deserializeSegment(elem, it); deserializeSegment(elem, it, fromPlaylist);
it++; it++;
} }
} }

View File

@ -127,6 +127,6 @@ void handlePlaylist() {
jsonTransitionOnce = true; jsonTransitionOnce = true;
transitionDelayTemp = playlistEntries[playlistIndex].tr * 100; transitionDelayTemp = playlistEntries[playlistIndex].tr * 100;
playlistEntryDur = playlistEntries[playlistIndex].dur; playlistEntryDur = playlistEntries[playlistIndex].dur;
applyPreset(playlistEntries[playlistIndex].preset); applyPreset(playlistEntries[playlistIndex].preset, true);
} }
} }

View File

@ -4,7 +4,7 @@
* Methods to handle saving and loading presets to/from the filesystem * 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 (index == 0) return false;
if (fileDoc) { // from POST "/json" handler (wled_server.cpp) if (fileDoc) { // from POST "/json" handler (wled_server.cpp)
@ -14,7 +14,7 @@ bool applyPreset(byte index)
#ifdef WLED_DEBUG_FS #ifdef WLED_DEBUG_FS
serializeJson(*fileDoc, Serial); serializeJson(*fileDoc, Serial);
#endif #endif
deserializeState(fdo); deserializeState(fdo, fromPlaylist);
} else { } else {
DEBUGFS_PRINTLN(F("Make read buf")); DEBUGFS_PRINTLN(F("Make read buf"));
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE); DynamicJsonDocument fDoc(JSON_BUFFER_SIZE);
@ -24,7 +24,7 @@ bool applyPreset(byte index)
#ifdef WLED_DEBUG_FS #ifdef WLED_DEBUG_FS
serializeJson(fDoc, Serial); serializeJson(fDoc, Serial);
#endif #endif
deserializeState(fdo); deserializeState(fdo, fromPlaylist);
} }
if (!errorFlag) { if (!errorFlag) {