@@ -85,7 +85,8 @@ const std::vector<DataFile::UpgradeMethod> DataFile::UPGRADE_METHODS = {
8585 &DataFile::upgrade_sampleAndHold , &DataFile::upgrade_midiCCIndexing,
8686 &DataFile::upgrade_loopsRename , &DataFile::upgrade_noteTypes,
8787 &DataFile::upgrade_fixCMTDelays , &DataFile::upgrade_fixBassLoopsTypo,
88- &DataFile::findProblematicLadspaPlugins
88+ &DataFile::findProblematicLadspaPlugins,
89+ &DataFile::upgrade_noHiddenAutomationTracks
8990};
9091
9192// Vector of all versions that have upgrade routines.
@@ -1638,6 +1639,51 @@ void DataFile::upgrade_1_3_0()
16381639 }
16391640}
16401641
1642+ void DataFile::upgrade_noHiddenAutomationTracks ()
1643+ {
1644+ // convert global automation tracks to non-hidden
1645+ QDomElement song = firstChildElement (" lmms-project" )
1646+ .firstChildElement (" song" );
1647+ QDomElement trackContainer = song.firstChildElement (" trackcontainer" );
1648+ QDomElement globalAutomationTrack = song.firstChildElement (" track" );
1649+ if (!globalAutomationTrack.isNull ()
1650+ && globalAutomationTrack.attribute (" type" ).toInt () == static_cast <int >(Track::Type::HiddenAutomation))
1651+ {
1652+ // global automation clips
1653+ QDomNodeList automationClips = globalAutomationTrack.elementsByTagName (" automationclip" );
1654+ QList<QDomNode> tracksToInsert;
1655+ for (int i = 0 ; i < automationClips.length (); ++i)
1656+ {
1657+ QDomElement automationClip = automationClips.item (i).toElement ();
1658+ // If automationClip has time nodes, move it to trackcontainer
1659+ // There are times when an <object> node is present without an
1660+ // object with the same ID in the file, so we ignore that node
1661+ if (automationClip.elementsByTagName (" time" ).length () > 1 )
1662+ {
1663+ QDomElement automationTrackForClip = createElement (" track" );
1664+ automationTrackForClip.setAttribute (" muted" , QString::number (false ));
1665+ automationTrackForClip.setAttribute (" solo" , QString::number (false ));
1666+ automationTrackForClip.setAttribute (" type" ,
1667+ QString::number (static_cast <int >(Track::Type::Automation)));
1668+ automationTrackForClip.setAttribute (" name" ,
1669+ automationClip.attribute (" name" , " Automation Track" ));
1670+ QDomElement at = createElement (" automationtrack" );
1671+ automationTrackForClip.appendChild (at);
1672+ automationTrackForClip.appendChild (automationClips.item (i).cloneNode ());
1673+ tracksToInsert.prepend (automationTrackForClip); // To preserve orders
1674+ }
1675+ }
1676+
1677+ // Insert the tracks at the beginning of trackContainer, preserving their order
1678+ for (const auto & track : tracksToInsert) {
1679+ trackContainer.insertBefore (track, trackContainer.firstChild ());
1680+ }
1681+
1682+ // Remove the track object just in case
1683+ globalAutomationTrack.parentNode ().removeChild (globalAutomationTrack);
1684+ }
1685+ }
1686+
16411687void DataFile::upgrade_noHiddenClipNames ()
16421688{
16431689 QDomNodeList tracks = elementsByTagName (" track" );
0 commit comments