Skip to content

Commit

Permalink
Rename TCO and BB to clip and pattern in save files (#6309)
Browse files Browse the repository at this point in the history
... and clarify how PatternTrack cloning works

- pattern -> midiclip
- automationpattern -> automationclip
- *tco -> *clip
- bb* -> pattern*
- bbtrackcontainer -> patternstore
  • Loading branch information
allejok96 authored Feb 14, 2022
1 parent 77fee49 commit f56fc68
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/AutomationClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class LMMS_EXPORT AutomationClip : public Clip
void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
void loadSettings( const QDomElement & _this ) override;

static const QString classNodeName() { return "automationpattern"; }
static const QString classNodeName() { return "automationclip"; }
QString nodeName() const override { return classNodeName(); }

ClipView * createView( TrackView * _tv ) override;
Expand Down
1 change: 1 addition & 0 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_extendedNoteRange();
void upgrade_defaultTripleOscillatorHQ();
void upgrade_mixerRename();
void upgrade_bbTcoRename();

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;
Expand Down
3 changes: 1 addition & 2 deletions include/MidiClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class LMMS_EXPORT MidiClip : public Clip
void loadSettings( const QDomElement & _this ) override;
inline QString nodeName() const override
{
//TODO: rename to "midiClip"
return "pattern";
return "midiclip";
}

inline InstrumentTrack * instrumentTrack() const
Expand Down
2 changes: 1 addition & 1 deletion include/PatternClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PatternClip : public Clip
void loadSettings( const QDomElement & _this ) override;
inline QString nodeName() const override
{
return( "bbtco" ); // TODO rename to patternclip
return "patternclip";
}

int patternIndex();
Expand Down
2 changes: 1 addition & 1 deletion include/PatternStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LMMS_EXPORT PatternStore : public TrackContainer

inline QString nodeName() const override
{
return "bbtrackcontainer"; // TODO rename to patternstore
return "patternstore";
}

bar_t lengthOfPattern(int pattern) const;
Expand Down
2 changes: 1 addition & 1 deletion include/PatternTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class LMMS_EXPORT PatternTrack : public Track
protected:
inline QString nodeName() const override
{
return( "bbtrack" ); //TODO rename to patterntrack
return "patterntrack";
}


Expand Down
4 changes: 2 additions & 2 deletions include/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SampleClip : public Clip
void loadSettings( const QDomElement & _this ) override;
inline QString nodeName() const override
{
return "sampletco";
return "sampleclip";
}

SampleBuffer* sampleBuffer()
Expand Down Expand Up @@ -89,4 +89,4 @@ public slots:



#endif
#endif
6 changes: 3 additions & 3 deletions plugins/MidiExport/MidiExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
base_volume = LocaleHelper::toDouble(it.attribute("volume", "100"))/100.0;
}

if (n.nodeName() == "pattern") //TODO: rename to "midiClip"
if (n.nodeName() == "midiclip")
{
base_time = n.toElement().attribute("pos", "0").toInt();
writeMidiClip(midiClip, n, base_pitch, base_volume, base_time);
Expand All @@ -160,7 +160,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
for (QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling())
{

if (n.nodeName() == "bbclip") // TODO rename to patternclip
if (n.nodeName() == "patternclip")
{
QDomElement it = n.toElement();
int pos = it.attribute("pos", "0").toInt();
Expand Down Expand Up @@ -211,7 +211,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks,
base_volume = LocaleHelper::toDouble(it.attribute("volume", "100")) / 100.0;
}

if (n.nodeName() == "pattern") //TODO: rename to "midiClip"
if (n.nodeName() == "midiclip")
{
std::vector<std::pair<int,int>> &plist = *itr;

Expand Down
41 changes: 38 additions & 3 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "ProjectVersion.h"
#include "SongEditor.h"
#include "TextFloat.h"
#include "Track.h"
#include "PathUtil.h"

#include "lmmsversion.h"
Expand All @@ -54,7 +55,7 @@ static void findIds(const QDomElement& elem, QList<jo_id_t>& idList);

// QMap with the DOM elements that access file resources
const DataFile::ResourcesMap DataFile::ELEMENTS_WITH_RESOURCES = {
{ "sampletco", {"src"} },
{ "sampleclip", {"src"} },
{ "audiofileprocessor", {"src"} },
};

Expand All @@ -71,7 +72,7 @@ const std::vector<DataFile::UpgradeMethod> DataFile::UPGRADE_METHODS = {
&DataFile::upgrade_1_3_0 , &DataFile::upgrade_noHiddenClipNames,
&DataFile::upgrade_automationNodes , &DataFile::upgrade_extendedNoteRange,
&DataFile::upgrade_defaultTripleOscillatorHQ,
&DataFile::upgrade_mixerRename
&DataFile::upgrade_mixerRename , &DataFile::upgrade_bbTcoRename,
};

// Vector of all versions that have upgrade routines.
Expand All @@ -95,7 +96,7 @@ DataFile::typeDescStruct
{ DataFile::ClipboardData, "clipboard-data" },
{ DataFile::JournalData, "journaldata" },
{ DataFile::EffectSettings, "effectsettings" },
{ DataFile::MidiClip, "pattern" }
{ DataFile::MidiClip, "midiclip" }
} ;


Expand Down Expand Up @@ -1790,6 +1791,40 @@ void DataFile::upgrade_mixerRename()
}


// Rename BB to pattern and TCO to clip
void DataFile::upgrade_bbTcoRename()
{
std::vector<std::pair<const char *, const char *>> names {
{"automationpattern", "automationclip"},
{"bbtco", "patternclip"},
{"pattern", "midiclip"},
{"sampletco", "sampleclip"},
{"bbtrack", "patterntrack"},
{"bbtrackcontainer", "patternstore"},
};
// Replace names of XML tags
for (auto name : names)
{
QDomNodeList elements = elementsByTagName(name.first);
for (int i = 0; !elements.item(i).isNull(); ++i)
{
elements.item(i).toElement().setTagName(name.second);
}
}
// Replace "Beat/Bassline" with "Pattern" in track names
QDomNodeList elements = elementsByTagName("track");
for (int i = 0; !elements.item(i).isNull(); ++i)
{
auto e = elements.item(i).toElement();
static_assert(Track::PatternTrack == 1, "Must be type=1 for backwards compatibility");
if (e.attribute("type").toInt() == Track::PatternTrack)
{
e.setAttribute("name", e.attribute("name").replace("Beat/Bassline", "Pattern"));
}
}
}


void DataFile::upgrade()
{
// Runs all necessary upgrade methods
Expand Down
2 changes: 1 addition & 1 deletion src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ void Song::loadProject( const QString & fileName )
++m_nLoadingTrack;
if (nd.toElement().attribute("type").toInt() == Track::PatternTrack)
{
n += nd.toElement().elementsByTagName("bbtrack").at(0) // TODO rename to patterntrack
n += nd.toElement().elementsByTagName("patterntrack").at(0)
.toElement().firstChildElement().childNodes().count();
}
nd=nd.nextSibling();
Expand Down
3 changes: 2 additions & 1 deletion src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ Track * Track::create( const QDomElement & element, TrackContainer * tc )
*/
Track* Track::clone()
{
// Save track to temporary XML and load it to create a new identical track
QDomDocument doc;
QDomElement parent = doc.createElement("clone");
QDomElement parent = doc.createElement("clonedtrack");
saveState(doc, parent);
Track* t = create(parent.firstChild().toElement(), m_trackContainer);

Expand Down
13 changes: 8 additions & 5 deletions src/tracks/PatternTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ void PatternTrack::saveTrackSpecificSettings(QDomDocument& doc, QDomElement& _th
/* _this.setAttribute( "current", s_infoMap[this] ==
engine::getPatternEditor()->currentPattern() );*/
if( s_infoMap[this] == 0 &&
_this.parentNode().parentNode().nodeName() != "clone" &&
_this.parentNode().parentNode().nodeName() != "clonedtrack" &&
_this.parentNode().parentNode().nodeName() != "journaldata" )
{
Engine::patternStore()->saveState(doc, _this);
}
if( _this.parentNode().parentNode().nodeName() == "clone" )
// If we are creating drag-n-drop data for Track::clone() only save pattern ID, not pattern content
if (_this.parentNode().parentNode().nodeName() == "clonedtrack")
{
_this.setAttribute( "clonebbt", s_infoMap[this] ); // TODO rename bb to pattern
_this.setAttribute("sourcepattern", s_infoMap[this]);
}
}

Expand All @@ -170,9 +171,11 @@ void PatternTrack::loadTrackSpecificSettings(const QDomElement& _this)
m_trackLabel->setPixmapFile( _this.attribute( "icon" ) );
}*/

if( _this.hasAttribute( "clonebbt" ) ) // TODO rename bb to pattern
// If data was created by Track::clone(), do not add any tracks to the pattern(-editor)
// instead create a new copy of the clip on each track
if (_this.hasAttribute("sourcepattern"))
{
const int src = _this.attribute( "clonebbt" ).toInt(); // TODO rename bb to pattern
const int src = _this.attribute("sourcepattern").toInt();
const int dst = s_infoMap[this];
TrackContainer::TrackList tl =
Engine::patternStore()->tracks();
Expand Down

0 comments on commit f56fc68

Please sign in to comment.