Bugfix.
- unloading playlist on playlist apply - optimisations in handlePlaylist()
This commit is contained in:
parent
cbf3ae4db4
commit
c58ad64a28
@ -131,8 +131,6 @@ void deserializeSegment(JsonObject elem, byte it)
|
|||||||
effectSpeed = elem[F("sx")] | effectSpeed;
|
effectSpeed = elem[F("sx")] | effectSpeed;
|
||||||
effectIntensity = elem[F("ix")] | effectIntensity;
|
effectIntensity = elem[F("ix")] | effectIntensity;
|
||||||
effectPalette = elem["pal"] | effectPalette;
|
effectPalette = elem["pal"] | effectPalette;
|
||||||
// it may be a good idea to also stop playlist if effect has changed
|
|
||||||
unloadPlaylist();
|
|
||||||
} else { //permanent
|
} else { //permanent
|
||||||
byte fx = elem["fx"] | seg.mode;
|
byte fx = elem["fx"] | seg.mode;
|
||||||
if (fx != seg.mode && fx < strip.getModeCount()) strip.setMode(id, fx);
|
if (fx != seg.mode && fx < strip.getModeCount()) strip.setMode(id, fx);
|
||||||
|
@ -10,29 +10,29 @@ typedef struct PlaylistEntry {
|
|||||||
uint16_t tr;
|
uint16_t tr;
|
||||||
} ple;
|
} ple;
|
||||||
|
|
||||||
bool playlistEndless = false;
|
bool playlistEndless = false;
|
||||||
int8_t playlistRepeat = 1;
|
int8_t playlistRepeat = 1;
|
||||||
byte playlistEndPreset = 0;
|
byte playlistEndPreset = 0;
|
||||||
byte *playlistEntries = nullptr;
|
PlaylistEntry *playlistEntries = nullptr;
|
||||||
byte playlistLen;
|
byte playlistLen;
|
||||||
int8_t playlistIndex = -1;
|
int8_t playlistIndex = -1;
|
||||||
uint16_t playlistEntryDur = 0;
|
uint16_t playlistEntryDur = 0;
|
||||||
|
|
||||||
|
|
||||||
void shufflePlaylist() {
|
void shufflePlaylist() {
|
||||||
int currentIndex = playlistLen;
|
int currentIndex = playlistLen;
|
||||||
|
PlaylistEntry temporaryValue;
|
||||||
PlaylistEntry temporaryValue, *entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
|
|
||||||
|
|
||||||
// While there remain elements to shuffle...
|
// While there remain elements to shuffle...
|
||||||
while (currentIndex--) {
|
while (currentIndex--) {
|
||||||
// Pick a random element...
|
// Pick a random element...
|
||||||
int randomIndex = random(0, currentIndex);
|
int randomIndex = random(0, currentIndex);
|
||||||
// And swap it with the current element.
|
// And swap it with the current element.
|
||||||
temporaryValue = entries[currentIndex];
|
temporaryValue = playlistEntries[currentIndex];
|
||||||
entries[currentIndex] = entries[randomIndex];
|
playlistEntries[currentIndex] = playlistEntries[randomIndex];
|
||||||
entries[randomIndex] = temporaryValue;
|
playlistEntries[randomIndex] = temporaryValue;
|
||||||
}
|
}
|
||||||
|
DEBUG_PRINTLN(F("Playlist shuffle."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void unloadPlaylist() {
|
void unloadPlaylist() {
|
||||||
@ -42,6 +42,7 @@ void unloadPlaylist() {
|
|||||||
}
|
}
|
||||||
currentPlaylist = playlistIndex = -1;
|
currentPlaylist = playlistIndex = -1;
|
||||||
playlistLen = playlistEntryDur = 0;
|
playlistLen = playlistEntryDur = 0;
|
||||||
|
DEBUG_PRINTLN(F("Playlist unloaded."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadPlaylist(JsonObject playlistObj) {
|
void loadPlaylist(JsonObject playlistObj) {
|
||||||
@ -51,52 +52,51 @@ void loadPlaylist(JsonObject playlistObj) {
|
|||||||
playlistLen = presets.size();
|
playlistLen = presets.size();
|
||||||
if (playlistLen == 0) return;
|
if (playlistLen == 0) return;
|
||||||
if (playlistLen > 100) playlistLen = 100;
|
if (playlistLen > 100) playlistLen = 100;
|
||||||
uint16_t dataSize = sizeof(ple) * playlistLen;
|
playlistEntries = new PlaylistEntry[playlistLen];
|
||||||
playlistEntries = new byte[dataSize];
|
if (playlistEntries == nullptr) return;
|
||||||
PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
|
|
||||||
|
|
||||||
byte it = 0;
|
byte it = 0;
|
||||||
for (int ps : presets) {
|
for (int ps : presets) {
|
||||||
if (it >= playlistLen) break;
|
if (it >= playlistLen) break;
|
||||||
entries[it].preset = ps;
|
playlistEntries[it].preset = ps;
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
it = 0;
|
it = 0;
|
||||||
JsonArray durations = playlistObj["dur"];
|
JsonArray durations = playlistObj["dur"];
|
||||||
if (durations.isNull()) {
|
if (durations.isNull()) {
|
||||||
entries[0].dur = playlistObj["dur"] | 100;
|
playlistEntries[0].dur = playlistObj["dur"] | 100;
|
||||||
it = 1;
|
it = 1;
|
||||||
} else {
|
} else {
|
||||||
for (int dur : durations) {
|
for (int dur : durations) {
|
||||||
if (it >= playlistLen) break;
|
if (it >= playlistLen) break;
|
||||||
entries[it].dur = dur;
|
playlistEntries[it].dur = dur;
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = it; i < playlistLen; i++) entries[i].dur = entries[it -1].dur;
|
for (int i = it; i < playlistLen; i++) playlistEntries[i].dur = playlistEntries[it -1].dur;
|
||||||
|
|
||||||
it = 0;
|
it = 0;
|
||||||
JsonArray tr = playlistObj[F("transition")];
|
JsonArray tr = playlistObj[F("transition")];
|
||||||
if (tr.isNull()) {
|
if (tr.isNull()) {
|
||||||
entries[0].tr = playlistObj[F("transition")] | (transitionDelay / 100);
|
playlistEntries[0].tr = playlistObj[F("transition")] | (transitionDelay / 100);
|
||||||
it = 1;
|
it = 1;
|
||||||
} else {
|
} else {
|
||||||
for (int transition : tr) {
|
for (int transition : tr) {
|
||||||
if (it >= playlistLen) break;
|
if (it >= playlistLen) break;
|
||||||
entries[it].tr = transition;
|
playlistEntries[it].tr = transition;
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = it; i < playlistLen; i++) entries[i].tr = entries[it -1].tr;
|
for (int i = it; i < playlistLen; i++) playlistEntries[i].tr = playlistEntries[it -1].tr;
|
||||||
|
|
||||||
playlistRepeat = playlistObj[F("repeat")] | 0;
|
playlistRepeat = playlistObj[F("repeat")] | 0;
|
||||||
playlistEndPreset = playlistObj[F("end")] | 0;
|
playlistEndPreset = playlistObj[F("end")] | 0;
|
||||||
|
|
||||||
playlistEndless = playlistRepeat < 1;
|
if (playlistRepeat <= 0) playlistRepeat--; // make it endless (-2 == endless & random)
|
||||||
if (playlistEndless && playlistRepeat==0) playlistRepeat = 1; // it will never decrement
|
|
||||||
|
|
||||||
currentPlaylist = 0; //TODO here we need the preset ID where the playlist is saved
|
currentPlaylist = 0; //TODO here we need the preset ID where the playlist is saved
|
||||||
|
DEBUG_PRINTLN(F("Playlist loaded."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,19 +116,17 @@ void handlePlaylist() {
|
|||||||
}
|
}
|
||||||
// playlist roll-over
|
// playlist roll-over
|
||||||
if (!playlistIndex) {
|
if (!playlistIndex) {
|
||||||
if (!playlistEndless) playlistRepeat--; // decrease repeat count on each index reset if not an endless playlist
|
// playlistRepeat < 0 => endless loop
|
||||||
if (playlistRepeat < 0) {// playlistRepeat < 0 => endless loop with shuffling presets
|
if (playlistRepeat > 0) playlistRepeat--; // decrease repeat count on each index reset if not an endless playlist
|
||||||
|
if (playlistRepeat < -1) { // playlistRepeat < -1 => with shuffling presets
|
||||||
shufflePlaylist(); // shuffle playlist and start over
|
shufflePlaylist(); // shuffle playlist and start over
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
|
|
||||||
|
|
||||||
jsonTransitionOnce = true;
|
jsonTransitionOnce = true;
|
||||||
transitionDelayTemp = entries[playlistIndex].tr * 100;
|
transitionDelayTemp = playlistEntries[playlistIndex].tr * 100;
|
||||||
|
playlistEntryDur = playlistEntries[playlistIndex].dur;
|
||||||
applyPreset(entries[playlistIndex].preset);
|
|
||||||
playlistEntryDur = entries[playlistIndex].dur;
|
|
||||||
if (playlistEntryDur == 0) playlistEntryDur = 10;
|
if (playlistEntryDur == 0) playlistEntryDur = 10;
|
||||||
|
applyPreset(playlistEntries[playlistIndex].preset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2106071
|
#define VERSION 2106072
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
Reference in New Issue
Block a user