Skip to content

Commit

Permalink
keira: liltracker: remove unused trailing patterns on save
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Apr 12, 2024
1 parent 95c9c7a commit 19b8322
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion firmware/keira/src/apps/liltracker/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ int32_t Track::writeToBuffer(uint8_t* data) {
// Write BPM
WRITE_TO_BUFFER(data, bpm);

// Find largest index of pattern that is used in a page.
// We won't write trailing patterns that are not used.
int16_t largestUsedPatternIndex = 0; // There is always at least one pattern
for (int16_t i = 0; i < getPageCount(); i++) {
for (int8_t j = 0; j < CHANNEL_COUNT; j++) {
largestUsedPatternIndex = MAX(largestUsedPatternIndex, getPage(i)->patternIndices[j]);
}
}

// Write patterns
int16_t patternCount = getPatternCount();
int16_t patternCount = largestUsedPatternIndex + 1;
WRITE_TO_BUFFER(data, patternCount);
for (int16_t i = 0; i < patternCount; i++) {
offset += getPattern(i)->writeToBuffer(&data[offset]);
Expand Down

0 comments on commit 19b8322

Please sign in to comment.