From 32366d97753dfe7bd608a9e5ff7433e76e9615eb Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Fri, 19 Aug 2022 01:40:22 -0400 Subject: [PATCH 1/3] Adding method to remove patterns by index. --- src/qpLayer.cpp | 15 +++++++++++++++ src/qpLayer.h | 2 ++ src/qpLinkedList.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/qpLayer.cpp b/src/qpLayer.cpp index 8e7145e..fd2dfd6 100644 --- a/src/qpLayer.cpp +++ b/src/qpLayer.cpp @@ -182,6 +182,21 @@ qpPattern &qpLayer::pattern(byte patternIndex) { return *this->lastReferencedPattern; } +byte qpLayer::numberOfPatterns() { + return this->patterns.numElements; +} + +void qpLayer::removePattern(byte patternIndex) { + qpPattern* pattern = this->patterns.getItem(patternIndex); + if (pattern == nullptr) { + return; + } + if(this->lastReferencedPattern == pattern) { + this->lastReferencedPattern = nullptr; + } + this->patterns.remove(patternIndex); +} + qpPattern &qpLayer::operator()(byte patternIndex) { return this->pattern(patternIndex); diff --git a/src/qpLayer.h b/src/qpLayer.h index f7aea19..c12cc04 100644 --- a/src/qpLayer.h +++ b/src/qpLayer.h @@ -65,6 +65,8 @@ class qpLayer { // Patterns qpPattern &pattern(byte patternIndex); qpPattern &samePattern() { return *this->lastReferencedPattern; } + byte numberOfPatterns(); + void removePattern(byte patternIndex); // Quick access operators qpPattern &operator()(byte patternIndex); diff --git a/src/qpLinkedList.h b/src/qpLinkedList.h index 196fbac..c666757 100644 --- a/src/qpLinkedList.h +++ b/src/qpLinkedList.h @@ -112,6 +112,7 @@ class qpLinkedList { delete current->item; delete current; + numElements--; return true; } From 3c35215faab789426063103aedfe6da973c7b0ac Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Tue, 14 Nov 2023 16:51:17 -0500 Subject: [PATCH 2/3] Fixed a bug where reactivating previously deactivated patterns wasn't working. --- src/qpPattern.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qpPattern.cpp b/src/qpPattern.cpp index b58211c..c5c8f3d 100644 --- a/src/qpPattern.cpp +++ b/src/qpPattern.cpp @@ -101,7 +101,7 @@ bool qpPattern::activate() { this->activations++; - this->nextRenderTick = this->ticks; + this->nextRenderTick = this->ticks + 1; this->onActivate(); From 314a295389c209fa8483ddb84258dd4bfe3b8f68 Mon Sep 17 00:00:00 2001 From: Paul Knopf Date: Thu, 16 Nov 2023 00:00:04 -0500 Subject: [PATCH 3/3] Fixing issue where int would overflow, stopping rendering. --- src/qpPattern.h | 2 +- src/quickPatterns.cpp | 2 +- src/quickPatterns.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qpPattern.h b/src/qpPattern.h index e2694c8..2bc1e09 100644 --- a/src/qpPattern.h +++ b/src/qpPattern.h @@ -17,7 +17,7 @@ class qpPattern { // ~ Animation speed int ticksBetweenFrames = 1; - int nextRenderTick = 1; + unsigned long nextRenderTick = 1; // ~ Periodic activation diff --git a/src/quickPatterns.cpp b/src/quickPatterns.cpp index bea4ae4..0a779f0 100644 --- a/src/quickPatterns.cpp +++ b/src/quickPatterns.cpp @@ -12,7 +12,7 @@ quickPatterns::~quickPatterns() { bool quickPatterns::draw() { - uint32_t currentMillis = millis(); + unsigned long currentMillis = millis(); if(currentMillis >= this->nextTickMillis) { diff --git a/src/quickPatterns.h b/src/quickPatterns.h index 23be060..4aba17e 100644 --- a/src/quickPatterns.h +++ b/src/quickPatterns.h @@ -43,7 +43,7 @@ class quickPatterns { private: short tickLengthInMillis = 25; - uint32_t nextTickMillis = 0; + unsigned long nextTickMillis = 0; qpLightStrand *lightStrand;