Skip to content

Commit

Permalink
Fix "bassloopes" typo
Browse files Browse the repository at this point in the history
Fix projects that still reference files with the typo "bassloopes" in their name.

The upgrade is implemented in its own method because it is unrelated to the BPM renaming even if it is technically very similar in its solution.

Introduce the helper method `mapSrcAttributeInElementsWithResources` which replaces the `src` attribute in elements with resources (samples and AFP) if it can be found in a map.

Remove hidden tabs.
  • Loading branch information
michaelgregorius committed May 1, 2024
1 parent 20136cf commit d1fa6dd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
3 changes: 3 additions & 0 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class LMMS_EXPORT DataFile : public QDomDocument

void cleanMetaNodes( QDomElement de );

void mapSrcAttributeInElementsWithResources(const QMap<QString, QString>& map);

// helper upgrade routines
void upgrade_0_2_1_20070501();
void upgrade_0_2_1_20070508();
Expand Down Expand Up @@ -130,6 +132,7 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_loopsRename();
void upgrade_noteTypes();
void upgrade_fixCMTDelays();
void upgrade_fixBassLoopsTypo();

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;
Expand Down
72 changes: 47 additions & 25 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const std::vector<DataFile::UpgradeMethod> DataFile::UPGRADE_METHODS = {
&DataFile::upgrade_mixerRename , &DataFile::upgrade_bbTcoRename,
&DataFile::upgrade_sampleAndHold , &DataFile::upgrade_midiCCIndexing,
&DataFile::upgrade_loopsRename , &DataFile::upgrade_noteTypes,
&DataFile::upgrade_fixCMTDelays
&DataFile::upgrade_fixCMTDelays , &DataFile::upgrade_fixBassLoopsTypo,
};

// Vector of all versions that have upgrade routines.
Expand Down Expand Up @@ -640,6 +640,32 @@ void DataFile::cleanMetaNodes( QDomElement _de )
}
}

void DataFile::mapSrcAttributeInElementsWithResources(const QMap<QString, QString>& map)
{
for (const auto& [elem, srcAttrs] : ELEMENTS_WITH_RESOURCES)
{
auto elements = elementsByTagName(elem);

for (const auto& srcAttr : srcAttrs)
{
for (int i = 0; i < elements.length(); ++i)
{
auto item = elements.item(i).toElement();

if (item.isNull() || !item.hasAttribute(srcAttr)) { continue; }

const QString srcVal = item.attribute(srcAttr);

const auto it = map.constFind(srcVal);
if (it != map.constEnd())
{
item.setAttribute(srcAttr, *it);
}
}
}
}
}


void DataFile::upgrade_0_2_1_20070501()
{
Expand Down Expand Up @@ -1910,7 +1936,7 @@ static QMap<QString, QString> buildReplacementMap()
{
const QString original = prefix + originalName + "." + extension;
const QString replacement = prefix + originalName + " - " + bpm + " BPM." + extension;

namesToNamesWithBPMsMap.insert(original, replacement);
};

Expand All @@ -1928,29 +1954,7 @@ void DataFile::upgrade_loopsRename()
{
static const QMap<QString, QString> namesToNamesWithBPMsMap = buildReplacementMap();

// Replace loop sample names
for (const auto& [elem, srcAttrs] : ELEMENTS_WITH_RESOURCES)
{
auto elements = elementsByTagName(elem);

for (const auto& srcAttr : srcAttrs)
{
for (int i = 0; i < elements.length(); ++i)
{
auto item = elements.item(i).toElement();

if (item.isNull() || !item.hasAttribute(srcAttr)) { continue; }

const QString srcVal = item.attribute(srcAttr);

const auto it = namesToNamesWithBPMsMap.constFind(srcVal);
if (it != namesToNamesWithBPMsMap.constEnd())
{
item.setAttribute(srcAttr, *it);
}
}
}
}
mapSrcAttributeInElementsWithResources(namesToNamesWithBPMsMap);
}

//! Update MIDI CC indexes, so that they are counted from 0. Older releases of LMMS
Expand All @@ -1975,6 +1979,24 @@ void DataFile::upgrade_midiCCIndexing()
}
}

void DataFile::upgrade_fixBassLoopsTypo()
{
static const QMap<QString, QString> replacementMap = {
{ "bassloopes/briff01.ogg", "bassloops/briff01 - 140 BPM.ogg" },
{ "bassloopes/rave_bass01.ogg", "bassloops/rave_bass01 - 180 BPM.ogg" },
{ "bassloopes/rave_bass02.ogg", "bassloops/rave_bass02 - 180 BPM.ogg" },
{ "bassloopes/tb303_01.ogg","bassloops/tb303_01 - 123 BPM.ogg" },
{ "bassloopes/techno_bass01.ogg", "bassloops/techno_bass01 - 140 BPM.ogg" },
{ "bassloopes/techno_bass02.ogg", "bassloops/techno_bass02 - 140 BPM.ogg" },
{ "bassloopes/techno_synth01.ogg", "bassloops/techno_synth01 - 140 BPM.ogg" },
{ "bassloopes/techno_synth02.ogg", "bassloops/techno_synth02 - 140 BPM.ogg" },
{ "bassloopes/techno_synth03.ogg", "bassloops/techno_synth03 - 130 BPM.ogg" },
{ "bassloopes/techno_synth04.ogg", "bassloops/techno_synth04 - 140 BPM.ogg" }
};

mapSrcAttributeInElementsWithResources(replacementMap);
}

void DataFile::upgrade()
{
// Runs all necessary upgrade methods
Expand Down

0 comments on commit d1fa6dd

Please sign in to comment.