Skip to content

Commit

Permalink
Add support for "factorysample:" prefix / Fix "bassloopes" typo (#7236)
Browse files Browse the repository at this point in the history
## Add support for "factorysample:" prefix
Add support to upgrade files with `src` tags that are prefixed with "factorysample:".

## Fix "bassloopes" typo
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.
  • Loading branch information
michaelgregorius authored Jun 14, 2024
1 parent b1ee626 commit beedbc1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 54 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
148 changes: 94 additions & 54 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 @@ -1871,68 +1897,64 @@ void DataFile::upgrade_sampleAndHold()
}


// Change loops' filenames in <sampleclip>s
void DataFile::upgrade_loopsRename()
static QMap<QString, QString> buildReplacementMap()
{
auto createEntry = [](const QString& originalName, const QString& bpm, const QString& extension = "ogg")
{
const QString replacement = originalName + " - " + bpm + " BPM." + extension;
return std::pair{originalName + "." + extension, replacement};
static constexpr auto loopBPMs = std::array{
std::pair{"bassloops/briff01", "140"},
std::pair{"bassloops/briff01", "140"},
std::pair{"bassloops/rave_bass01", "180"},
std::pair{"bassloops/rave_bass02", "180"},
std::pair{"bassloops/tb303_01", "123"},
std::pair{"bassloops/techno_bass01", "140"},
std::pair{"bassloops/techno_bass02", "140"},
std::pair{"bassloops/techno_synth01", "140"},
std::pair{"bassloops/techno_synth02", "140"},
std::pair{"bassloops/techno_synth03", "130"},
std::pair{"bassloops/techno_synth04", "140"},
std::pair{"beats/909beat01", "122"},
std::pair{"beats/break01", "168"},
std::pair{"beats/break02", "141"},
std::pair{"beats/break03", "168"},
std::pair{"beats/electro_beat01", "120"},
std::pair{"beats/electro_beat02", "119"},
std::pair{"beats/house_loop01", "142"},
std::pair{"beats/jungle01", "168"},
std::pair{"beats/rave_hihat01", "180"},
std::pair{"beats/rave_hihat02", "180"},
std::pair{"beats/rave_kick01", "180"},
std::pair{"beats/rave_kick02", "180"},
std::pair{"beats/rave_snare01", "180"},
std::pair{"latin/latin_brass01", "140"},
std::pair{"latin/latin_guitar01", "126"},
std::pair{"latin/latin_guitar02", "140"},
std::pair{"latin/latin_guitar03", "120"},
};

static const QMap<QString, QString> namesToNamesWithBPMsMap {
{ createEntry("bassloops/briff01", "140") },
{ createEntry("bassloops/rave_bass01", "180") },
{ createEntry("bassloops/rave_bass02", "180") },
{ createEntry("bassloops/tb303_01", "123") },
{ createEntry("bassloops/techno_bass01", "140") },
{ createEntry("bassloops/techno_bass02", "140") },
{ createEntry("bassloops/techno_synth01", "140") },
{ createEntry("bassloops/techno_synth02", "140") },
{ createEntry("bassloops/techno_synth03", "130") },
{ createEntry("bassloops/techno_synth04", "140") },
{ createEntry("beats/909beat01", "122") },
{ createEntry("beats/break01", "168") },
{ createEntry("beats/break02", "141") },
{ createEntry("beats/break03", "168") },
{ createEntry("beats/electro_beat01", "120") },
{ createEntry("beats/electro_beat02", "119") },
{ createEntry("beats/house_loop01", "142") },
{ createEntry("beats/jungle01", "168") },
{ createEntry("beats/rave_hihat01", "180") },
{ createEntry("beats/rave_hihat02", "180") },
{ createEntry("beats/rave_kick01", "180") },
{ createEntry("beats/rave_kick02", "180") },
{ createEntry("beats/rave_snare01", "180") },
{ createEntry("latin/latin_brass01", "140") },
{ createEntry("latin/latin_guitar01", "126") },
{ createEntry("latin/latin_guitar02", "140") },
{ createEntry("latin/latin_guitar03", "120") }
};
QMap<QString, QString> namesToNamesWithBPMsMap;

// Replace loop sample names
for (const auto& [elem, srcAttrs] : ELEMENTS_WITH_RESOURCES)
auto insertEntry = [&namesToNamesWithBPMsMap](const QString& originalName, const QString& bpm, const QString& prefix = "", const QString& extension = "ogg")
{
auto elements = elementsByTagName(elem);
const QString original = prefix + originalName + "." + extension;
const QString replacement = prefix + originalName + " - " + bpm + " BPM." + extension;

for (const auto& srcAttr : srcAttrs)
{
for (int i = 0; i < elements.length(); ++i)
{
auto item = elements.item(i).toElement();
namesToNamesWithBPMsMap.insert(original, replacement);
};

if (item.isNull() || !item.hasAttribute(srcAttr)) { continue; }
for (const auto & loopBPM : loopBPMs)
{
insertEntry(loopBPM.first, loopBPM.second);
insertEntry(loopBPM.first, loopBPM.second, "factorysample:");
}

const QString srcVal = item.attribute(srcAttr);
return namesToNamesWithBPMsMap;
}

const auto it = namesToNamesWithBPMsMap.constFind(srcVal);
if (it != namesToNamesWithBPMsMap.constEnd())
{
item.setAttribute(srcAttr, *it);
}
}
}
}
// Change loops' filenames in <sampleclip>s
void DataFile::upgrade_loopsRename()
{
static const QMap<QString, QString> namesToNamesWithBPMsMap = buildReplacementMap();

mapSrcAttributeInElementsWithResources(namesToNamesWithBPMsMap);
}

//! Update MIDI CC indexes, so that they are counted from 0. Older releases of LMMS
Expand All @@ -1957,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 beedbc1

Please sign in to comment.