mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-17 11:18:30 -04:00
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:
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "SampleBuffer.h"
|
||||
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@@ -55,11 +54,11 @@
|
||||
#include "Engine.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "Mixer.h"
|
||||
#include "PathUtil.h"
|
||||
|
||||
#include "FileDialog.h"
|
||||
|
||||
|
||||
|
||||
SampleBuffer::SampleBuffer() :
|
||||
m_audioFile( "" ),
|
||||
m_origData( NULL ),
|
||||
@@ -179,7 +178,7 @@ void SampleBuffer::update( bool _keep_settings )
|
||||
}
|
||||
else if( !m_audioFile.isEmpty() )
|
||||
{
|
||||
QString file = tryToMakeAbsolute( m_audioFile );
|
||||
QString file = PathUtil::toAbsolute( m_audioFile );
|
||||
int_sample_t * buf = NULL;
|
||||
sample_t * fbuf = NULL;
|
||||
ch_cnt_t channels = DEFAULT_CHANNELS;
|
||||
@@ -781,7 +780,7 @@ bool SampleBuffer::play( sampleFrame * _ab, handleState * _state,
|
||||
}
|
||||
}
|
||||
|
||||
if( tmp != NULL )
|
||||
if( tmp != NULL )
|
||||
{
|
||||
MM_FREE( tmp );
|
||||
}
|
||||
@@ -1031,7 +1030,7 @@ QString SampleBuffer::openAudioFile() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
return tryToMakeRelative( ofd.selectedFiles()[0] );
|
||||
return PathUtil::toShortestRelative( ofd.selectedFiles()[0] );
|
||||
}
|
||||
|
||||
return QString();
|
||||
@@ -1222,7 +1221,7 @@ SampleBuffer * SampleBuffer::resample( const sample_rate_t _src_sr,
|
||||
|
||||
void SampleBuffer::setAudioFile( const QString & _audio_file )
|
||||
{
|
||||
m_audioFile = tryToMakeRelative( _audio_file );
|
||||
m_audioFile = PathUtil::toShortestRelative( _audio_file );
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1419,60 +1418,6 @@ void SampleBuffer::setReversed( bool _on )
|
||||
|
||||
|
||||
|
||||
QString SampleBuffer::tryToMakeRelative( const QString & file )
|
||||
{
|
||||
if( QFileInfo( file ).isRelative() == false )
|
||||
{
|
||||
// Normalize the path
|
||||
QString f( QDir::cleanPath( file ) );
|
||||
|
||||
// First, look in factory samples
|
||||
// Isolate "samples/" from "data:/samples/"
|
||||
QString samplesSuffix = ConfigManager::inst()->factorySamplesDir().mid( ConfigManager::inst()->dataDir().length() );
|
||||
|
||||
// Iterate over all valid "data:/" searchPaths
|
||||
for ( const QString & path : QDir::searchPaths( "data" ) )
|
||||
{
|
||||
QString samplesPath = QDir::cleanPath( path + samplesSuffix ) + "/";
|
||||
if ( f.startsWith( samplesPath ) )
|
||||
{
|
||||
return QString( f ).mid( samplesPath.length() );
|
||||
}
|
||||
}
|
||||
|
||||
// Next, look in user samples
|
||||
QString usd = ConfigManager::inst()->userSamplesDir();
|
||||
usd.replace( QDir::separator(), '/' );
|
||||
if( f.startsWith( usd ) )
|
||||
{
|
||||
return QString( f ).mid( usd.length() );
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QString SampleBuffer::tryToMakeAbsolute(const QString& file)
|
||||
{
|
||||
QFileInfo f(file);
|
||||
|
||||
if(f.isRelative())
|
||||
{
|
||||
f = QFileInfo(ConfigManager::inst()->userSamplesDir() + file);
|
||||
|
||||
if(! f.exists())
|
||||
{
|
||||
f = QFileInfo(ConfigManager::inst()->factorySamplesDir() + file);
|
||||
}
|
||||
}
|
||||
|
||||
if (f.exists()) {
|
||||
return f.absoluteFilePath();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1488,7 +1433,7 @@ SampleBuffer::handleState::handleState( bool _varying_pitch, int interpolation_m
|
||||
{
|
||||
int error;
|
||||
m_interpolationMode = interpolation_mode;
|
||||
|
||||
|
||||
if( ( m_resamplingData = src_new( interpolation_mode, DEFAULT_CHANNELS, &error ) ) == NULL )
|
||||
{
|
||||
qDebug( "Error: src_new() failed in sample_buffer.cpp!\n" );
|
||||
|
||||
Reference in New Issue
Block a user