Improved relative paths (#5117)
* Create PathUtils * Replace old SampleBuffer calls * Fix automatic track names * Fix things * Remove accidental duplicate file * Add includes * More incldues * PhysSong's code review + style * Fix vestige loading? Seems more reasonable to convert from relative on load and to relative on save than vice versa. * Typo fix * More Bases * Enable more bases * Add missing semicolons in prefixes * Nicer sample track tooltip * Use correct directories "userXDir" gives the default dir for ladspa, sf2, and gig. "xDir" gives the user dir. * Make relative to both default and custom locations Part 1 * Make relative to both default and custom locations Part 2 * Typofix * Typofix * Fix upgrade function after base renaming * Fix Tests * Update tests/src/core/RelativePathsTest.cpp Co-Authored-By: Hyunjin Song <tteu.ingog@gmail.com> * Choose UserXBase over DefaultXBase if identical toShortestRelative sticks with the first base found if two bases give the same path length. By placing UserXBase Bases before DefaultXBase Bases in the relativeBases vector, toShortestRelative will prioritize them. * Ensure baseLocation always has trailing slash Otherwise, a user configuring a path without one will break things. * Move loc declaration out of switch * Semicolon * Apply suggestions from code review... * Include PathUtil and sort includes * More granular includes * Apply suggestions from code review Co-Authored-By: Hyunjin Song <tteu.ingog@gmail.com> * Update include/PathUtil.h * Leave empty paths alone * Fix stupid merge * Really fix merge. Hopefully * Switch Base from enum to class enum * Don't pass Base by reference * Use QStringLiteral for static QString allocation in basePrefix method * Make VST loading more similar to previous implementation * Fix tests after enum change * Attempt to fix VST loading, nicer name for sample clips * Fix last review comment Don't append a "/" that will be removed by cleanPath later * Apply suggestions from code review Co-authored-by: Dominic Clark <mrdomclark@gmail.com> Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com> Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "GigPlayer.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <QDebug>
|
||||
@@ -35,18 +36,18 @@
|
||||
#include <QLabel>
|
||||
#include <QDomDocument>
|
||||
|
||||
#include "FileDialog.h"
|
||||
#include "GigPlayer.h"
|
||||
#include "Engine.h"
|
||||
#include "InstrumentTrack.h"
|
||||
#include "InstrumentPlayHandle.h"
|
||||
#include "Mixer.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "Knob.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "Song.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 "PathUtil.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "Song.h"
|
||||
|
||||
#include "PatchesDialog.h"
|
||||
#include "ToolTip.h"
|
||||
@@ -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( ... )
|
||||
{
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "audio_file_processor.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QBitmap>
|
||||
@@ -31,18 +32,18 @@
|
||||
|
||||
#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"
|
||||
#include "interpolation.h"
|
||||
#include "gui_templates.h"
|
||||
#include "ToolTip.h"
|
||||
#include "PathUtil.h"
|
||||
#include "Song.h"
|
||||
#include "StringPairDrag.h"
|
||||
#include "DataFile.h"
|
||||
#include "ToolTip.h"
|
||||
|
||||
#include "embed.h"
|
||||
#include "plugin_export.h"
|
||||
@@ -97,13 +98,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();
|
||||
}
|
||||
|
||||
@@ -237,7 +238,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() );
|
||||
@@ -329,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
|
||||
|
||||
@@ -363,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() )
|
||||
@@ -390,7 +391,7 @@ void audioFileProcessor::startPointChanged( void )
|
||||
{
|
||||
m_endPointModel.setValue( qMin( m_endPointModel.value() + 0.001f, 1.0f ) );
|
||||
}
|
||||
|
||||
|
||||
pointChanged();
|
||||
|
||||
}
|
||||
@@ -1284,7 +1285,3 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main(Model * model, void *)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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");
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -641,8 +640,3 @@ void PatmanView::modelChanged( void )
|
||||
connect( m_pi, SIGNAL( fileChanged() ),
|
||||
this, SLOT( updateFilename() ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sf2_player.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
@@ -30,14 +32,14 @@
|
||||
|
||||
#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"
|
||||
|
||||
@@ -372,8 +374,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();
|
||||
@@ -435,7 +437,7 @@ void sf2Instrument::openFile( const QString & _sf2File, bool updateTrackName )
|
||||
|
||||
if( updateTrackName || instrumentTrack()->displayName() == displayName() )
|
||||
{
|
||||
instrumentTrack()->setName( QFileInfo( _sf2File ).baseName() );
|
||||
instrumentTrack()->setName( PathUtil::cleanName( _sf2File ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1145,7 +1147,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() );
|
||||
}
|
||||
|
||||
@@ -40,24 +40,24 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ConfigManager.h"
|
||||
#include "BufferManager.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "Engine.h"
|
||||
#include "FileDialog.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "gui_templates.h"
|
||||
#include "InstrumentPlayHandle.h"
|
||||
#include "InstrumentTrack.h"
|
||||
#include "LocaleHelper.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Mixer.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "PathUtil.h"
|
||||
#include "PixmapButton.h"
|
||||
#include "SampleBuffer.h"
|
||||
#include "Song.h"
|
||||
#include "StringPairDrag.h"
|
||||
#include "TextFloat.h"
|
||||
#include "ToolTip.h"
|
||||
#include "FileDialog.h"
|
||||
|
||||
|
||||
#include "embed.h"
|
||||
@@ -271,7 +271,7 @@ void vestigeInstrument::reloadPlugin()
|
||||
|
||||
void vestigeInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this )
|
||||
{
|
||||
_this.setAttribute( "plugin", m_pluginDLL );
|
||||
_this.setAttribute( "plugin", PathUtil::toShortestRelative(m_pluginDLL) );
|
||||
m_pluginMutex.lock();
|
||||
if( m_plugin != NULL )
|
||||
{
|
||||
@@ -338,14 +338,14 @@ void vestigeInstrument::loadFile( const QString & _file )
|
||||
|
||||
// if the same is loaded don't load again (for preview)
|
||||
if (instrumentTrack() != NULL && instrumentTrack()->isPreviewMode() &&
|
||||
m_pluginDLL == SampleBuffer::tryToMakeRelative( _file ))
|
||||
m_pluginDLL == PathUtil::toShortestRelative( _file ))
|
||||
return;
|
||||
|
||||
if ( m_plugin != NULL )
|
||||
{
|
||||
closePlugin();
|
||||
}
|
||||
m_pluginDLL = SampleBuffer::tryToMakeRelative( _file );
|
||||
m_pluginDLL = PathUtil::toShortestRelative( _file );
|
||||
TextFloat * tf = NULL;
|
||||
if( gui )
|
||||
{
|
||||
@@ -686,7 +686,7 @@ void VestigeInstrumentView::openPlugin()
|
||||
|
||||
if( m_vi->m_pluginDLL != "" )
|
||||
{
|
||||
QString f = SampleBuffer::tryToMakeAbsolute( m_vi->m_pluginDLL );
|
||||
QString f = PathUtil::toAbsolute( m_vi->m_pluginDLL );
|
||||
ofd.setDirectory( QFileInfo( f ).absolutePath() );
|
||||
ofd.selectFile( QFileInfo( f ).fileName() );
|
||||
}
|
||||
@@ -1233,7 +1233,3 @@ Q_DECL_EXPORT Plugin * lmms_plugin_main( Model *m, void * )
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "LocaleHelper.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Mixer.h"
|
||||
#include "PathUtil.h"
|
||||
#include "Song.h"
|
||||
#include "FileDialog.h"
|
||||
|
||||
@@ -121,7 +122,7 @@ private:
|
||||
|
||||
|
||||
VstPlugin::VstPlugin( const QString & _plugin ) :
|
||||
m_plugin( _plugin ),
|
||||
m_plugin( PathUtil::toAbsolute(_plugin) ),
|
||||
m_pluginWindowID( 0 ),
|
||||
m_embedMethod( gui
|
||||
? ConfigManager::inst()->vstEmbedMethod()
|
||||
@@ -129,11 +130,6 @@ VstPlugin::VstPlugin( const QString & _plugin ) :
|
||||
m_version( 0 ),
|
||||
m_currentProgram()
|
||||
{
|
||||
if( QDir::isRelativePath( m_plugin ) )
|
||||
{
|
||||
m_plugin = ConfigManager::inst()->vstDir() + m_plugin;
|
||||
}
|
||||
|
||||
setSplittedChannels( true );
|
||||
|
||||
PE::MachineType machineType;
|
||||
@@ -804,7 +800,3 @@ QString VstPlugin::embedMethod() const
|
||||
{
|
||||
return m_embedMethod;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user