Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-relative samples #3540

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
43 changes: 43 additions & 0 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "GuiApplication.h"
#include "PluginFactory.h"
#include "ProjectVersion.h"
#include "SampleBuffer.h"
#include "SongEditor.h"
#include "TextFloat.h"

Expand Down Expand Up @@ -1118,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
Expand Down Expand Up @@ -1157,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<jo_id_t>& idList)
{
if(elem.hasAttribute("id"))
Expand Down