Skip to content

Commit

Permalink
Filesystem : add methods to handle sample filepath
Browse files Browse the repository at this point in the history
int get_basename_idx_within_drumkit(QString) returns the index of the
basename of the sample if the given path is under an existing drumkit
path, otherwise returns -1. The existence of the sample path is not checked !!

bool file_is_within_drumkit(QString) is a wrapper over the previous function

QString prepare_sample_path(fname) returns the basename if the given
path is under an existing drumkit, otherwise the given path.
  • Loading branch information
jeremyz committed Aug 27, 2018
1 parent 27d1ac1 commit 5664d28
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/core/include/hydrogen/helpers/filesystem.h
Original file line number Diff line number Diff line change
@@ -116,8 +116,12 @@ class Filesystem : public H2Core::Object
static QString tmp_file_path( const QString& base );

/* DRUMKIT */
/** Checks if a given file is part of a kit in the soundlibrary or external */
static bool file_is_partof_drumkit( const QString& fname);
/** Returns the basename if the given path is under an existing user or system drumkit path, otherwise the given fname */
static QString prepare_sample_path( const QString& fname );
/** Checks if the given filepath is under an existing user or system drumkit path, not the existence of the file */
static bool file_is_under_drumkit( const QString& fname);
/** Returns the index of the basename if the given path is under an existing user or system drumkit path, otherwise -1 */
static int get_basename_idx_under_drumkit( const QString& fname);
/** returns list of usable system drumkits ( see Filesystem::drumkit_list ) */
static QStringList sys_drumkit_list( );
/** returns list of usable user drumkits ( see Filesystem::drumkit_list ) */
23 changes: 19 additions & 4 deletions src/core/src/helpers/filesystem.cpp
Original file line number Diff line number Diff line change
@@ -529,25 +529,40 @@ QStringList Filesystem::usr_drumkit_list( )
return drumkit_list( usr_drumkits_dir() ) ;
}

bool Filesystem::file_is_partof_drumkit( const QString& fname )
QString Filesystem::prepare_sample_path( const QString& fname )
{
int idx = get_basename_idx_under_drumkit( fname );
if ( idx >= 0 )
return fname.midRef( idx ).toString();
return fname;
}

bool Filesystem::file_is_under_drumkit( const QString& fname )
{
return get_basename_idx_under_drumkit( fname ) != -1;
}

int Filesystem::get_basename_idx_under_drumkit( const QString& fname )
{
if( fname.startsWith( usr_drumkits_dir() ) )
{
int start = usr_drumkits_dir().size();
int index = fname.indexOf( "/", start );
QString dk_name = fname.midRef( start , index - start).toString();
return usr_drumkit_list().contains( dk_name );
if ( usr_drumkit_list().contains( dk_name ) )
return index + 1;
}

if( fname.startsWith( sys_drumkits_dir() ) )
{
int start = sys_drumkits_dir().size();
int index = fname.indexOf( "/", start);
QString dk_name = fname.midRef( start, index - start).toString();
return sys_drumkit_list().contains( dk_name );
if ( sys_drumkit_list().contains( dk_name ) )
return index + 1;
}

return false;
return -1;
}


0 comments on commit 5664d28

Please sign in to comment.