Skip to content
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ set(LMMS_SRCS
core/ToolPlugin.cpp
core/Track.cpp
core/TrackContainer.cpp
core/UpgradeExtendedNoteRange.h
core/UpgradeExtendedNoteRange.cpp
core/Clip.cpp
core/ValueBuffer.cpp
core/VstSyncController.cpp
Expand Down
71 changes: 3 additions & 68 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "TextFloat.h"
#include "Track.h"
#include "PathUtil.h"
#include "UpgradeExtendedNoteRange.h"

#include "lmmsversion.h"

Expand Down Expand Up @@ -1677,74 +1678,8 @@ void DataFile::upgrade_automationNodes()
*/
void DataFile::upgrade_extendedNoteRange()
{
auto affected = [](const QDomElement& instrument)
{
return instrument.attribute("name") == "zynaddsubfx" ||
instrument.attribute("name") == "vestige" ||
instrument.attribute("name") == "lv2instrument" ||
instrument.attribute("name") == "carlapatchbay" ||
instrument.attribute("name") == "carlarack";
};

if (!elementsByTagName("song").item(0).isNull())
{
// Dealing with a project file, go through all the tracks
QDomNodeList tracks = elementsByTagName("track");
for (int i = 0; !tracks.item(i).isNull(); i++)
{
// Ignore BB container tracks
if (tracks.item(i).toElement().attribute("type").toInt() == 1) { continue; }

QDomNodeList instruments = tracks.item(i).toElement().elementsByTagName("instrument");
if (instruments.isEmpty()) { continue; }
QDomElement instrument = instruments.item(0).toElement();
// Raise the base note of every instrument by 12 to compensate for the change
// of A4 key code from 57 to 69. This ensures that notes are labeled correctly.
instrument.parentNode().toElement().setAttribute(
"basenote",
instrument.parentNode().toElement().attribute("basenote").toInt() + 12);
// Raise the pitch of all notes in patterns assigned to instruments not affected
// by #1857 by an octave. This negates the base note change for normal instruments,
// but leaves the MIDI-based instruments sounding an octave lower, preserving their
// pitch in existing projects.
if (!affected(instrument))
{
QDomNodeList patterns = tracks.item(i).toElement().elementsByTagName("pattern");
for (int i = 0; !patterns.item(i).isNull(); i++)
{
QDomNodeList notes = patterns.item(i).toElement().elementsByTagName("note");
for (int i = 0; !notes.item(i).isNull(); i++)
{
notes.item(i).toElement().setAttribute(
"key",
notes.item(i).toElement().attribute("key").toInt() + 12
);
}
}
}
}
}
else
{
// Dealing with a preset, not a song
QDomNodeList presets = elementsByTagName("instrumenttrack");
if (presets.item(0).isNull()) { return; }
QDomElement preset = presets.item(0).toElement();
// Common correction for all instrument presets (make base notes match the new MIDI range).
// NOTE: Many older presets do not have any basenote defined, assume they were "made for 57".
// (Specifying a default like this also happens to fix a FileBrowser bug where previews of presets
// with undefined basenote always play with the basenote inherited from previously played preview.)
int oldBase = preset.attribute("basenote", "57").toInt();
preset.setAttribute("basenote", oldBase + 12);
// Extra correction for Zyn, VeSTige, LV2 and Carla (to preserve the original buggy behavior).
QDomNodeList instruments = presets.item(0).toElement().elementsByTagName("instrument");
if (instruments.isEmpty()) { return; }
QDomElement instrument = instruments.item(0).toElement();
if (affected(instrument))
{
preset.setAttribute("basenote", preset.attribute("basenote").toInt() + 12);
}
}
auto root = documentElement();
UpgradeExtendedNoteRange upgradeExtendedNoteRange(root);
}


Expand Down
Loading