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

Improved relative paths #5117

Merged
merged 44 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cd15286
Create PathUtils
Spekular Aug 5, 2019
decd9a9
Replace old SampleBuffer calls
Spekular Aug 7, 2019
51328b0
Fix automatic track names
Spekular Aug 7, 2019
a2dc1dd
Fix things
Spekular Aug 10, 2019
7a193ac
Remove accidental duplicate file
Spekular Aug 10, 2019
b9951a9
Add includes
Spekular Aug 10, 2019
7a1bc2f
More incldues
Spekular Aug 10, 2019
316b7b7
PhysSong's code review + style
Spekular Aug 11, 2019
5baff4c
Fix vestige loading?
Spekular Aug 11, 2019
332b422
Typo fix
Spekular Aug 11, 2019
009ea38
More Bases
Spekular Aug 15, 2019
133cd13
Enable more bases
Spekular Aug 15, 2019
334a90a
Add missing semicolons in prefixes
Spekular Aug 15, 2019
a001977
Nicer sample track tooltip
Spekular Aug 15, 2019
bcdecc2
Use correct directories
Spekular Aug 18, 2019
d3ccf3c
Make relative to both default and custom locations
Spekular Aug 18, 2019
39c1dc1
Make relative to both default and custom locations
Spekular Aug 18, 2019
0ac89bf
Typofix
Spekular Aug 18, 2019
7dc359d
Typofix
Spekular Aug 18, 2019
bf24a9b
Fix upgrade function after base renaming
Spekular Aug 18, 2019
8f9dc7a
Fix Tests
Spekular Aug 18, 2019
1147abf
Update tests/src/core/RelativePathsTest.cpp
Spekular Aug 18, 2019
34c6fc2
Choose UserXBase over DefaultXBase if identical
Spekular Aug 19, 2019
c0ac743
Ensure baseLocation always has trailing slash
Spekular Aug 19, 2019
de4fc5f
Move loc declaration out of switch
Spekular Aug 19, 2019
3cebac8
Semicolon
Spekular Aug 19, 2019
97a35a8
Apply suggestions from code review...
Spekular Aug 19, 2019
ca0e46d
Include PathUtil and sort includes
Spekular Aug 23, 2019
455452e
More granular includes
Spekular Aug 23, 2019
fa78dc8
Apply suggestions from code review
Spekular Sep 22, 2019
b7c038e
Update include/PathUtil.h
Spekular Nov 7, 2019
9f386cd
Leave empty paths alone
Spekular Nov 8, 2019
6853aec
Merge branch 'qdir' of https://github.com/Spekular/lmms into qdir
Spekular Nov 8, 2019
3dbcfae
Merge with master
Spekular Jul 9, 2020
436c993
Fix stupid merge
Spekular Jul 9, 2020
8b73a4c
Really fix merge. Hopefully
Spekular Jul 9, 2020
9295500
Switch Base from enum to class enum
Spekular Jul 10, 2020
d4b3318
Don't pass Base by reference
Spekular Jul 10, 2020
0bd5e5e
Use QStringLiteral for static QString allocation in basePrefix method
Spekular Jul 10, 2020
f3773d8
Make VST loading more similar to previous implementation
Spekular Jul 10, 2020
4d8818c
Fix tests after enum change
Spekular Jul 10, 2020
70221d8
Attempt to fix VST loading, nicer name for sample clips
Spekular Jul 12, 2020
e55e34c
Fix last review comment
Spekular Jul 21, 2020
4274c22
Apply suggestions from code review
Spekular Jul 27, 2020
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
30 changes: 30 additions & 0 deletions include/PathUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef PATHUTIL_H
#define PATHUTIL_H

#include "lmms_export.h"

#include <QDir>

namespace PathUtil
{
enum Base { AbsoluteBase, ProjectDirBase, FactorySampleBase, UserSampleBase, UserVSTBase, PresetBase,
DefaultLADSPABase, UserLADSPABase, DefaultSoundfontBase, UserSoundfontBase, DefaultGIGBase, UserGIGBase };
Spekular marked this conversation as resolved.
Show resolved Hide resolved

QString LMMS_EXPORT baseLocation(Base base);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
QDir LMMS_EXPORT baseQDir (Base base);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
QString LMMS_EXPORT basePrefix(Base base);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
Base LMMS_EXPORT baseLookup(QString path);
Spekular marked this conversation as resolved.
Show resolved Hide resolved

QString LMMS_EXPORT stripPrefix(QString path);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
QString LMMS_EXPORT cleanName(QString path);
Spekular marked this conversation as resolved.
Show resolved Hide resolved

QString LMMS_EXPORT oldRelativeUpgrade(QString input);
Spekular marked this conversation as resolved.
Show resolved Hide resolved

QString LMMS_EXPORT toAbsolute(QString input);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
QString LMMS_EXPORT relativeOrAbsolute(QString input, Base base);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
QString LMMS_EXPORT toShortestRelative(QString input);
Spekular marked this conversation as resolved.
Show resolved Hide resolved

// QString LMMS_EXPORT toPreferredRelative(QString, std::vector<Base>);
Spekular marked this conversation as resolved.
Show resolved Hide resolved
}

#endif
6 changes: 2 additions & 4 deletions include/SampleBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "lmms_math.h"
#include "shared_object.h"
#include "MemoryManager.h"
#include "PathUtil.h"
Spekular marked this conversation as resolved.
Show resolved Hide resolved
Spekular marked this conversation as resolved.
Show resolved Hide resolved


class QPainter;
Expand Down Expand Up @@ -84,7 +85,7 @@ class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
{
m_isBackwards = _backwards;
}

int interpolationMode() const
{
return m_interpolationMode;
Expand Down Expand Up @@ -251,9 +252,6 @@ class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
m_varLock.unlock();
}

static QString tryToMakeRelative( const QString & _file );
static QString tryToMakeAbsolute(const QString & file);


public slots:
void setAudioFile( const QString & _audio_file );
Expand Down
19 changes: 10 additions & 9 deletions plugins/GigPlayer/GigPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,26 @@
*
*/

#include "GigPlayer.h"

#include <cstring>
#include <QDebug>
#include <QLayout>
#include <QLabel>
#include <QDomDocument>

#include "FileDialog.h"
#include "GigPlayer.h"
#include "ConfigManager.h"
#include "endian_handling.h"
#include "Engine.h"
#include "FileDialog.h"
#include "InstrumentTrack.h"
#include "InstrumentPlayHandle.h"
#include "Knob.h"
#include "Mixer.h"
#include "NotePlayHandle.h"
#include "Knob.h"
#include "PathUtil.h"
#include "SampleBuffer.h"
#include "Song.h"
#include "ConfigManager.h"
#include "endian_handling.h"

#include "PatchesDialog.h"
#include "ToolTip.h"
Expand Down Expand Up @@ -211,8 +212,8 @@ void GigInstrument::openFile( const QString & _gigFile, bool updateTrackName )

try
{
m_instance = new GigInstance( SampleBuffer::tryToMakeAbsolute( _gigFile ) );
m_filename = SampleBuffer::tryToMakeRelative( _gigFile );
m_instance = new GigInstance( PathUtil::toAbsolute( _gigFile ) );
m_filename = PathUtil::toShortestRelative( _gigFile );
}
catch( ... )
{
Expand All @@ -225,7 +226,7 @@ void GigInstrument::openFile( const QString & _gigFile, bool updateTrackName )

if( updateTrackName == true )
{
instrumentTrack()->setName( QFileInfo( _gigFile ).baseName() );
instrumentTrack()->setName(PathUtil::cleanName( _gigFile ) );
updatePatch();
}
}
Expand Down Expand Up @@ -1057,7 +1058,7 @@ void GigInstrumentView::showFileDialog()

if( k->m_filename != "" )
{
QString f = SampleBuffer::tryToMakeAbsolute( k->m_filename );
QString f = PathUtil::toAbsolute( k->m_filename );
ofd.setDirectory( QFileInfo( f ).absolutePath() );
ofd.selectFile( QFileInfo( f ).fileName() );
}
Expand Down
28 changes: 12 additions & 16 deletions plugins/audio_file_processor/audio_file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/

#include "audio_file_processor.h"

#include <QPainter>
#include <QBitmap>
Expand All @@ -31,18 +32,17 @@

#include <samplerate.h>

#include "audio_file_processor.h"
#include "ConfigManager.h"
#include "DataFile.h"
#include "Engine.h"
#include "Song.h"
#include "gui_templates.h"
#include "InstrumentTrack.h"
#include "interpolation.h"
#include "Mixer.h"
#include "NotePlayHandle.h"
Spekular marked this conversation as resolved.
Show resolved Hide resolved
#include "interpolation.h"
#include "gui_templates.h"
#include "ToolTip.h"
#include "Song.h"
#include "StringPairDrag.h"
#include "DataFile.h"
#include "ToolTip.h"

#include "embed.h"
#include "plugin_export.h"
Expand Down Expand Up @@ -97,13 +97,13 @@ audioFileProcessor::audioFileProcessor( InstrumentTrack * _instrument_track ) :
this, SLOT( loopPointChanged() ) );
connect( &m_stutterModel, SIGNAL( dataChanged() ),
this, SLOT( stutterModelChanged() ) );

//interpolation modes
m_interpolationModel.addItem( tr( "None" ) );
m_interpolationModel.addItem( tr( "Linear" ) );
m_interpolationModel.addItem( tr( "Sinc" ) );
m_interpolationModel.setValue( 1 );

pointChanged();
}

Expand Down Expand Up @@ -237,7 +237,7 @@ void audioFileProcessor::loadSettings( const QDomElement & _this )
{
setAudioFile( _this.attribute( "src" ), false );

QString absolutePath = m_sampleBuffer.tryToMakeAbsolute( m_sampleBuffer.audioFile() );
QString absolutePath = PathUtil::toAbsolute( m_sampleBuffer.audioFile() );
if ( !QFileInfo( absolutePath ).exists() )
{
QString message = tr( "Sample not found: %1" ).arg( m_sampleBuffer.audioFile() );
Expand Down Expand Up @@ -330,7 +330,7 @@ void audioFileProcessor::setAudioFile( const QString & _audio_file,
m_sampleBuffer.audioFile().isEmpty() ) )
{
// then set it to new one
instrumentTrack()->setName( QFileInfo( _audio_file).fileName() );
instrumentTrack()->setName( PathUtil::cleanName( _audio_file ) );
}
// else we don't touch the track-name, because the user named it self

Expand Down Expand Up @@ -364,7 +364,7 @@ void audioFileProcessor::stutterModelChanged()
}


void audioFileProcessor::startPointChanged( void )
void audioFileProcessor::startPointChanged( void )
{
// check if start is over end and swap values if so
if( m_startPointModel.value() > m_endPointModel.value() )
Expand All @@ -391,7 +391,7 @@ void audioFileProcessor::startPointChanged( void )
{
m_endPointModel.setValue( qMin( m_endPointModel.value() + 0.001f, 1.0f ) );
}

pointChanged();

}
Expand Down Expand Up @@ -1285,7 +1285,3 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main(Model * model, void *)


}




22 changes: 8 additions & 14 deletions plugins/patman/patman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 2007-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
* Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -32,15 +32,15 @@
#include "ConfigManager.h"
#include "endian_handling.h"
#include "Engine.h"
#include "FileDialog.h"
#include "gui_templates.h"
#include "InstrumentTrack.h"
#include "NotePlayHandle.h"
#include "PathUtil.h"
#include "PixmapButton.h"
#include "Song.h"
#include "StringPairDrag.h"
#include "ToolTip.h"
#include "FileDialog.h"
#include "ConfigManager.h"

#include "embed.h"

Expand Down Expand Up @@ -192,14 +192,13 @@ void patmanInstrument::setFile( const QString & _patch_file, bool _rename )
m_patchFile == "" ) )
{
// then set it to new one
instrumentTrack()->setName( QFileInfo( _patch_file
).fileName() );
instrumentTrack()->setName( PathUtil::cleanName( _patch_file ) );
}
// else we don't touch the instrument-track-name, because the user
// named it self

m_patchFile = SampleBuffer::tryToMakeRelative( _patch_file );
LoadErrors error = loadPatch( SampleBuffer::tryToMakeAbsolute( _patch_file ) );
m_patchFile = PathUtil::toShortestRelative( _patch_file );
LoadErrors error = loadPatch( PathUtil::toAbsolute( _patch_file ) );
if( error )
{
printf("Load error\n");
Expand Down Expand Up @@ -625,8 +624,8 @@ void PatmanView::paintEvent( QPaintEvent * )
QPainter p( this );

p.setFont( pointSize<8>( font() ) );
p.drawText( 8, 116, 235, 16,
Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter,
p.drawText( 8, 116, 235, 16,
Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter,
m_displayFilename );
}

Expand All @@ -641,8 +640,3 @@ void PatmanView::modelChanged( void )
connect( m_pi, SIGNAL( fileChanged() ),
this, SLOT( updateFilename() ) );
}





17 changes: 8 additions & 9 deletions plugins/sf2_player/sf2_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
*
*/

#include "sf2_player.h"

#include <QDebug>
#include <QLayout>
#include <QLabel>
#include <QDomDocument>

#include "ConfigManager.h"
#include "FileDialog.h"
#include "sf2_player.h"
#include "ConfigManager.h"
#include "Engine.h"
#include "InstrumentTrack.h"
#include "InstrumentPlayHandle.h"
#include "Knob.h"
#include "Mixer.h"
#include "NotePlayHandle.h"
#include "Knob.h"
#include "PathUtil.h"
#include "SampleBuffer.h"
#include "Song.h"

Expand Down Expand Up @@ -335,8 +337,8 @@ void sf2Instrument::openFile( const QString & _sf2File, bool updateTrackName )
emit fileLoading();

// Used for loading file
char * sf2Ascii = qstrdup( qPrintable( SampleBuffer::tryToMakeAbsolute( _sf2File ) ) );
QString relativePath = SampleBuffer::tryToMakeRelative( _sf2File );
char * sf2Ascii = qstrdup( qPrintable( PathUtil::toAbsolute( _sf2File ) ) );
QString relativePath = PathUtil::toShortestRelative( _sf2File );

// free reference to soundfont if one is selected
freeFont();
Expand Down Expand Up @@ -392,7 +394,7 @@ void sf2Instrument::openFile( const QString & _sf2File, bool updateTrackName )

if( updateTrackName || instrumentTrack()->displayName() == displayName() )
{
instrumentTrack()->setName( QFileInfo( _sf2File ).baseName() );
instrumentTrack()->setName( PathUtil::cleanName( _sf2File ) );
}
}

Expand Down Expand Up @@ -1106,7 +1108,7 @@ void sf2InstrumentView::showFileDialog()

if( k->m_filename != "" )
{
QString f = SampleBuffer::tryToMakeAbsolute( k->m_filename );
QString f = PathUtil::toAbsolute( k->m_filename );
ofd.setDirectory( QFileInfo( f ).absolutePath() );
ofd.selectFile( QFileInfo( f ).fileName() );
}
Expand Down Expand Up @@ -1157,6 +1159,3 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model *m, void * )


}



Loading