Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write old format note data, so songs can be loaded in 1.2 and below #3394

Open
wants to merge 5 commits into
base: community
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions src/deluge/model/note/note_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,7 @@

int32_t newBendRange = -1; // Temp variable for this because we can't actually create the expressionParams
// before we know what kind of Drum (if any) we have.

reader.match('{');
while (*(tagName = reader.readNextTagOrAttributeName())) {
// D_PRINTLN(tagName); delayMS(50);
Expand Down Expand Up @@ -3508,13 +3509,15 @@
}

// Notes stored as hex data including lift (V3.2 onwards)
else if (!strcmp(tagName, "noteDataWithLift")) {
else if (song_firmware_version < FirmwareVersion::community({1, 3, 0})

Check failure on line 3512 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

use designated initializer list to initialize 'SemVer' [modernize-use-designated-initializers,-warnings-as-errors]
&& !strcmp(tagName, "noteDataWithLift")) {

Check failure on line 3513 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion,-warnings-as-errors]
noteHexLength = 22;
goto doReadNoteData;
}

// Notes stored as hex data in nightly firmware 1.3 with no custom iterances
else if (!strcmp(tagName, "noteDataWithIteranceAndFill")) {
else if (song_firmware_version < FirmwareVersion::community({1, 3, 0})

Check failure on line 3519 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

use designated initializer list to initialize 'SemVer' [modernize-use-designated-initializers,-warnings-as-errors]
&& !strcmp(tagName, "noteDataWithIteranceAndFill")) {

Check failure on line 3520 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion,-warnings-as-errors]
noteHexLength = 26;
goto doReadNoteData;
}
Expand Down Expand Up @@ -3606,6 +3609,62 @@
writer.write(buffer);
}
writer.write("\"");

// TODO: once we drop retro-compatibility with 1.2 and below, this piece of code
// can be deleted
{
writer.insertCommaIfNeeded();
writer.write("\n");
writer.printIndents();
writer.write("noteDataWithLift=\"0x");
for (int32_t n = 0; n < notes.getNumElements(); n++) {
Note* thisNote = notes.getElement(n);

Check failure on line 3621 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

invalid case style for variable 'thisNote' [readability-identifier-naming,-warnings-as-errors]

char buffer[9];

Check failure on line 3623 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,-warnings-as-errors]

intToHex(thisNote->pos, buffer);
writer.write(buffer);

intToHex(thisNote->getLength(), buffer);
writer.write(buffer);

intToHex(thisNote->getVelocity(), buffer, 2);
writer.write(buffer);

intToHex(thisNote->getLift(), buffer, 2);
writer.write(buffer);

// Do here an attempt to keep the most significant information, in order of priority
// 1st - Iterance preset
// 2nd - Fill/NotFill
// 3rd - Probability
// 4th - Custom iterance (since this does not exist in 1.2 it will be always discarded)
int32_t oldProbability = kNumProbabilityValues; // Defaults to 100% probability

Check failure on line 3642 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

invalid case style for variable 'oldProbability' [readability-identifier-naming,-warnings-as-errors]
int32_t iterancePresetIndex = thisNote->getIterance().toPresetIndex();

Check failure on line 3643 in src/deluge/model/note/note_row.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy: error

invalid case style for variable 'iterancePresetIndex' [readability-identifier-naming,-warnings-as-errors]
int32_t fill = thisNote->getFill();
int32_t probability = thisNote->getProbability();
if (iterancePresetIndex > 0 && iterancePresetIndex != kCustomIterancePreset) {
// We found the note has an iterance preset compatible with 1.2 and backwards, use it
oldProbability = kNumProbabilityValues + iterancePresetIndex;
}
else if (fill != FillMode::OFF) {
// We found the note has a fill mode, use it
if (fill == FillMode::FILL) {
oldProbability = 0; // 0 means FILL
}
else {
oldProbability = 128; // 128 means NOT_FILL
}
}
else if (probability != kNumProbabilityValues) {
// we found the note has a probability different than 100%, use it
oldProbability = probability;
}
intToHex(oldProbability, buffer, 2);
writer.write(buffer);
}
writer.write("\"");
}
}

ExpressionParamSet* expressionParams = paramManager.getExpressionParamSet();
Expand Down
Loading