From 273d72ad806249b1d4d16770ebc96430630b1bb4 Mon Sep 17 00:00:00 2001 From: tresf Date: Sun, 7 May 2017 02:03:30 -0400 Subject: [PATCH 1/3] Patch non-relative samples --- src/core/DataFile.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index dc2b1de5791..110f4456f5d 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -40,6 +40,7 @@ #include "GuiApplication.h" #include "PluginFactory.h" #include "ProjectVersion.h" +#include "SampleBuffer.h" #include "SongEditor.h" #include "TextFloat.h" @@ -1050,6 +1051,39 @@ void DataFile::upgrade() upgrade_1_2_0_rc2_42(); } + // Fix relative samples + QDomNodeList instruments = elementsByTagName( "instrument" ); + for( int i = 0; !instruments.item( i ).isNull(); ++i ) + { + QDomElement child = instruments.item( i ).toElement().firstChildElement(); + while( !child.isNull() ) + { + qDebug() << "##### TAGNAME: " << child.tagName(); + QString src = child.attribute( "src" ); + if ( QFileInfo( src ).isAbsolute() ) { + qDebug() << "##### SRC:" << child.attribute( "src" ); + child.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + } + child = child.nextSiblingElement(); + } + } + + // Fix relative samples for sampletrack edge-case + QDomNodeList sampletracks = elementsByTagName( "sampletco" ); + for( int i = 0; !sampletracks.item( i ).isNull(); ++i ) + { + QDomElement sampletrack = sampletracks.item( i ).toElement(); + qDebug() << "##### TAGNAME: " << sampletrack.tagName(); + if( !sampletrack.isNull() ) + { + qDebug() << "##### SRC:" << sampletrack.attribute( "src" ); + QString src = sampletrack.attribute( "src" ); + if ( QFileInfo( src ).isAbsolute() ) { + sampletrack.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + } + } + } + // update document meta data documentElement().setAttribute( "version", LDF_VERSION_STRING ); documentElement().setAttribute( "type", typeName( type() ) ); From 8e14d6d351f269dfefd0af4f75bdd24052fa68d9 Mon Sep 17 00:00:00 2001 From: tresf Date: Sun, 7 May 2017 11:18:00 -0400 Subject: [PATCH 2/3] Consistent naming --- src/core/DataFile.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 110f4456f5d..030df256940 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -1052,34 +1052,35 @@ void DataFile::upgrade() } // Fix relative samples - QDomNodeList instruments = elementsByTagName( "instrument" ); - for( int i = 0; !instruments.item( i ).isNull(); ++i ) + QDomNodeList list = elementsByTagName( "instrument" ); + for( int i = 0; !list.item( i ).isNull(); ++i ) { - QDomElement child = instruments.item( i ).toElement().firstChildElement(); - while( !child.isNull() ) + QDomElement el = list.item( i ).toElement().firstChildElement(); + qDebug() << "##### PARENT: " << list.item( i ).toElement().tagName(); + while( !el.isNull() ) { - qDebug() << "##### TAGNAME: " << child.tagName(); - QString src = child.attribute( "src" ); + qDebug() << "##### CHILD: " << el.tagName(); + QString src = el.attribute( "src" ); if ( QFileInfo( src ).isAbsolute() ) { - qDebug() << "##### SRC:" << child.attribute( "src" ); - child.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + qDebug() << "##### SRC: " << el.attribute( "src" ); + el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); } - child = child.nextSiblingElement(); + el = el.nextSiblingElement(); } } // Fix relative samples for sampletrack edge-case - QDomNodeList sampletracks = elementsByTagName( "sampletco" ); - for( int i = 0; !sampletracks.item( i ).isNull(); ++i ) + list = elementsByTagName( "sampletco" ); + for( int i = 0; !list.item( i ).isNull(); ++i ) { - QDomElement sampletrack = sampletracks.item( i ).toElement(); - qDebug() << "##### TAGNAME: " << sampletrack.tagName(); - if( !sampletrack.isNull() ) + QDomElement el = list.item( i ).toElement(); + qDebug() << "##### TAGNAME: " << el.tagName(); + if( !el.isNull() ) { - qDebug() << "##### SRC:" << sampletrack.attribute( "src" ); - QString src = sampletrack.attribute( "src" ); + qDebug() << "##### SRC: " << el.attribute( "src" ); + QString src = el.attribute( "src" ); if ( QFileInfo( src ).isAbsolute() ) { - sampletrack.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); } } } From 273a4fefcc7dc5776d1daac1268da03eeecaa3ab Mon Sep 17 00:00:00 2001 From: tresf Date: Sun, 7 May 2017 17:34:35 -0400 Subject: [PATCH 3/3] Remove version check, comment --- include/DataFile.h | 1 + src/core/DataFile.cpp | 76 ++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include/DataFile.h b/include/DataFile.h index 6b6b1a98e6c..de93309657c 100644 --- a/include/DataFile.h +++ b/include/DataFile.h @@ -129,6 +129,7 @@ class EXPORT DataFile : public QDomDocument void upgrade_1_2_0_rc2_42(); void upgrade(); + void fixPaths(); void loadData( const QByteArray & _data, const QString & _sourceFile ); diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 030df256940..1ad9775e9a1 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -1051,40 +1051,6 @@ void DataFile::upgrade() upgrade_1_2_0_rc2_42(); } - // Fix relative samples - QDomNodeList list = elementsByTagName( "instrument" ); - for( int i = 0; !list.item( i ).isNull(); ++i ) - { - QDomElement el = list.item( i ).toElement().firstChildElement(); - qDebug() << "##### PARENT: " << list.item( i ).toElement().tagName(); - while( !el.isNull() ) - { - qDebug() << "##### CHILD: " << el.tagName(); - QString src = el.attribute( "src" ); - if ( QFileInfo( src ).isAbsolute() ) { - qDebug() << "##### SRC: " << el.attribute( "src" ); - el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); - } - el = el.nextSiblingElement(); - } - } - - // Fix relative samples for sampletrack edge-case - list = elementsByTagName( "sampletco" ); - for( int i = 0; !list.item( i ).isNull(); ++i ) - { - QDomElement el = list.item( i ).toElement(); - qDebug() << "##### TAGNAME: " << el.tagName(); - if( !el.isNull() ) - { - qDebug() << "##### SRC: " << el.attribute( "src" ); - QString src = el.attribute( "src" ); - if ( QFileInfo( src ).isAbsolute() ) { - el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); - } - } - } - // update document meta data documentElement().setAttribute( "version", LDF_VERSION_STRING ); documentElement().setAttribute( "type", typeName( type() ) ); @@ -1153,6 +1119,9 @@ void DataFile::loadData( const QByteArray & _data, const QString & _sourceFile ) ProjectVersion createdWith = root.attribute( "creatorversion" ); ProjectVersion openedWith = LMMS_VERSION; + // fix incorrectly saved paths (e.g. incorrectly set lmms working dir) + fixPaths(); + if ( createdWith != openedWith ) { // only one compareType needs to be set, and we can compare on one line because setCompareType returns ProjectVersion @@ -1192,6 +1161,45 @@ void DataFile::loadData( const QByteArray & _data, const QString & _sourceFile ) } + +/* + * Fix project portability by attempting to fix absolute paths. This can happen + * from a misconfigured lmms working directory or any projects created with + * 1.2.0-rc1 or 1.2.0-rc2 + */ +void DataFile::fixPaths() { + // Fix relative instrument samples (AudioFileProcessor, SF2Player...) + QDomNodeList list = elementsByTagName( "instrument" ); + for( int i = 0; i < list.count(); ++i ) + { + QDomElement el = list.item( i ).toElement().firstChildElement(); + while( !el.isNull() ) + { + QString src = el.attribute( "src" ); + if ( QFileInfo( src ).isAbsolute() ) { + el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + } + el = el.nextSiblingElement(); + } + } + + // Fix relative track samples (SampleTrack) + list = elementsByTagName( "sampletco" ); + for( int i = 0; i < list.count(); ++i ) + { + QDomElement el = list.item( i ).toElement(); + if( !el.isNull() ) + { + QString src = el.attribute( "src" ); + if ( QFileInfo( src ).isAbsolute() ) { + el.setAttribute( "src", SampleBuffer::tryToMakeRelative( src ) ); + } + } + } +} + + + void findIds(const QDomElement& elem, QList& idList) { if(elem.hasAttribute("id"))