From c2ff2d8dc8b3eeafa2b16356bceb9916f309dedd Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 13 Apr 2024 20:55:42 +0200 Subject: [PATCH 1/4] Add upgrade for CMT delays Add an upgrade routine for CMT delays. This fix will only work in conjunction with a fix in the CMT delay itself. The CMT delay uses `sprintf` calls to generate the technical names and display names of the delays. These calls are locale dependent. As a consequence for example the feedback delay might have been saved either as "fbdelay_0.1s" (point) or "fbdelay_0,1s" (comma) in a save file. The CMT fix makes sure that all delays use points in their names. Therefore we must upgrade all names that contain commas to ones that contain points. --- include/DataFile.h | 1 + src/core/DataFile.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/DataFile.h b/include/DataFile.h index ce5d4edf4c2..452481a7f00 100644 --- a/include/DataFile.h +++ b/include/DataFile.h @@ -129,6 +129,7 @@ class LMMS_EXPORT DataFile : public QDomDocument void upgrade_midiCCIndexing(); void upgrade_loopsRename(); void upgrade_noteTypes(); + void upgrade_fixCMTDelays(); // List of all upgrade methods static const std::vector UPGRADE_METHODS; diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index eedb7f01d8a..0c86cc803a3 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -83,7 +83,8 @@ const std::vector DataFile::UPGRADE_METHODS = { &DataFile::upgrade_defaultTripleOscillatorHQ, &DataFile::upgrade_mixerRename , &DataFile::upgrade_bbTcoRename, &DataFile::upgrade_sampleAndHold , &DataFile::upgrade_midiCCIndexing, - &DataFile::upgrade_loopsRename , &DataFile::upgrade_noteTypes + &DataFile::upgrade_loopsRename , &DataFile::upgrade_noteTypes, + &DataFile::upgrade_fixCMTDelays }; // Vector of all versions that have upgrade routines. @@ -1684,6 +1685,50 @@ void DataFile::upgrade_noteTypes() } } +void DataFile::upgrade_fixCMTDelays() +{ + QMap nameMap; + nameMap["delay_0,01s"] = "delay_0.01s"; + nameMap["delay_0,1s"] = "delay_0.1s"; + nameMap["fbdelay_0,01s"] = "fbdelay_0.01s"; + nameMap["fbdelay_0,1s"] = "fbdelay_0.1s"; + + const auto effects = elementsByTagName("effect"); + bool generalInfoPrinted = false; + + for (int i = 0; i < effects.size(); ++i) + { + auto effect = effects.item(i).toElement(); + + // We are only interested in LADSPA plugins + if (effect.attribute("name") != "ladspaeffect") continue; + + // Fetch all attributes (LMMS) beneath the LADSPA effect so that we can check the value of the plugin attribute (XML) + auto attributes = effect.elementsByTagName("attribute"); + for (int j = 0; j < attributes.size(); ++j) + { + auto attribute = attributes.item(j).toElement(); + + if (attribute.attribute("name") == "plugin") + { + const auto attributeValue = attribute.attribute("value"); + + QMap::const_iterator it = nameMap.find(attributeValue); + if (it != nameMap.end()) + { + if (!generalInfoPrinted) + { + qInfo() << "Performing data upgrade for CMT delay(s). See LMMS issue #5167 for more details."; + generalInfoPrinted = true; + } + qInfo() << "Replacing" << attributeValue << "with" << *it; + attribute.setAttribute("value", *it); + } + } + } + } +} + /** \brief Note range has been extended to match MIDI specification * From e1899d82755b99a95dee9bf4eebfc1a3f6575373 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 14 Apr 2024 10:14:05 +0200 Subject: [PATCH 2/4] Code review changes * Static map * Braces around continue * Make const_iterator itself const as well * Remove output --- src/core/DataFile.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 0c86cc803a3..cbddc6746dc 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -1687,21 +1687,20 @@ void DataFile::upgrade_noteTypes() void DataFile::upgrade_fixCMTDelays() { - QMap nameMap; + static QMap nameMap; nameMap["delay_0,01s"] = "delay_0.01s"; nameMap["delay_0,1s"] = "delay_0.1s"; nameMap["fbdelay_0,01s"] = "fbdelay_0.01s"; nameMap["fbdelay_0,1s"] = "fbdelay_0.1s"; const auto effects = elementsByTagName("effect"); - bool generalInfoPrinted = false; for (int i = 0; i < effects.size(); ++i) { auto effect = effects.item(i).toElement(); // We are only interested in LADSPA plugins - if (effect.attribute("name") != "ladspaeffect") continue; + if (effect.attribute("name") != "ladspaeffect") { continue; } // Fetch all attributes (LMMS) beneath the LADSPA effect so that we can check the value of the plugin attribute (XML) auto attributes = effect.elementsByTagName("attribute"); @@ -1713,15 +1712,9 @@ void DataFile::upgrade_fixCMTDelays() { const auto attributeValue = attribute.attribute("value"); - QMap::const_iterator it = nameMap.find(attributeValue); + const QMap::const_iterator it = nameMap.find(attributeValue); if (it != nameMap.end()) { - if (!generalInfoPrinted) - { - qInfo() << "Performing data upgrade for CMT delay(s). See LMMS issue #5167 for more details."; - generalInfoPrinted = true; - } - qInfo() << "Replacing" << attributeValue << "with" << *it; attribute.setAttribute("value", *it); } } From 0e3ee2fd312921414c762c521a792e7f9f6ebd33 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 14 Apr 2024 10:19:12 +0200 Subject: [PATCH 3/4] Bump CMT to d8bf8084aa3 Bump the CMT submodule to commit d8bf8084aa3 which contains the fixes for issue #5167. The delays now always report the same name strings. --- plugins/LadspaEffect/cmt/cmt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/LadspaEffect/cmt/cmt b/plugins/LadspaEffect/cmt/cmt index 6e6e291fbad..d8bf8084aa3 160000 --- a/plugins/LadspaEffect/cmt/cmt +++ b/plugins/LadspaEffect/cmt/cmt @@ -1 +1 @@ -Subproject commit 6e6e291fbad1138c808860ba3f140a963b52fa58 +Subproject commit d8bf8084aa3a47497092f5ab99c843a55090d151 From 564f50f2e378d3200f8b92a8239a40dc0dfa878c Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 14 Apr 2024 17:27:25 +0200 Subject: [PATCH 4/4] More code review changes * Map is now const and initialized iIn place * Use `constFind` and `constEnd` when searching for an element --- src/core/DataFile.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index cbddc6746dc..00c6845f34e 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -1687,11 +1687,12 @@ void DataFile::upgrade_noteTypes() void DataFile::upgrade_fixCMTDelays() { - static QMap nameMap; - nameMap["delay_0,01s"] = "delay_0.01s"; - nameMap["delay_0,1s"] = "delay_0.1s"; - nameMap["fbdelay_0,01s"] = "fbdelay_0.01s"; - nameMap["fbdelay_0,1s"] = "fbdelay_0.1s"; + static const QMap nameMap { + { "delay_0,01s", "delay_0.01s" }, + { "delay_0,1s", "delay_0.1s" }, + { "fbdelay_0,01s", "fbdelay_0.01s" }, + { "fbdelay_0,1s", "fbdelay_0.1s" } + }; const auto effects = elementsByTagName("effect"); @@ -1712,8 +1713,8 @@ void DataFile::upgrade_fixCMTDelays() { const auto attributeValue = attribute.attribute("value"); - const QMap::const_iterator it = nameMap.find(attributeValue); - if (it != nameMap.end()) + const auto it = nameMap.constFind(attributeValue); + if (it != nameMap.constEnd()) { attribute.setAttribute("value", *it); }