hydrogen 1.1.1
Filesystem Class Reference

Filesystem is a thin layer over QDir, QFile and QFileInfo. More...

#include <Filesystem.h>

Inheritance diagram for Filesystem:
Object

Public Types

enum  file_perms {
  is_dir =0x01 , is_file =0x02 , is_readable =0x04 , is_writable =0x08 ,
  is_executable =0x10
}
 flags available for check_permissions() More...
 
enum class  Lookup { stacked = 0 , user = 1 , system = 2 }
 Whenever a drumkit is loaded by name a collision between a user and a system drumkit carrying the same name can occur. More...
 

Static Public Member Functions

static bool bootstrap (Logger *logger, const QString &sys_path=nullptr)
 check user and system filesystem usability More...
 
static QString sys_data_path ()
 returns system data path More...
 
static QString usr_data_path ()
 returns user data path More...
 
static QStringList ladspa_paths ()
 returns user ladspa paths More...
 
static QString sys_config_path ()
 returns system config path More...
 
static QString usr_config_path ()
 returns user config path More...
 
static QString empty_sample_path ()
 returns system empty sample file path More...
 
static QString empty_song_path ()
 returns system empty song file path More...
 
static QString untitled_song_file_name ()
 returns untitled song file name More...
 
static QString click_file_path ()
 Returns a string containing the path to the click.wav file used in the metronome. More...
 
static QString usr_click_file_path ()
 returns click file path from user directory if exists, otherwise from system More...
 
static QString drumkit_xsd_path ()
 returns the path to the drumkit XSD (xml schema definition) file More...
 
static QString pattern_xsd_path ()
 returns the path to the pattern XSD (xml schema definition) file More...
 
static QString playlist_xsd_path ()
 returns the path to the playlist pattern XSD (xml schema definition) file More...
 
static QString log_file_path ()
 returns the full path (including filename) of the logfile More...
 
static QString img_dir ()
 returns gui image path More...
 
static QString doc_dir ()
 returns documentation path More...
 
static QString i18n_dir ()
 returns internationalization path More...
 
static QString scripts_dir ()
 returns user scripts path More...
 
static QString songs_dir ()
 returns user songs path More...
 
static QString song_path (const QString &sg_name)
 returns user song path, add file extension More...
 
static QString patterns_dir ()
 returns user patterns path More...
 
static QString patterns_dir (const QString &dk_name)
 returns user patterns path for a specific drumkit More...
 
static QString pattern_path (const QString &dk_name, const QString &p_name)
 returns user patterns path, add file extension More...
 
static QString plugins_dir ()
 returns user plugins path More...
 
static QString sys_drumkits_dir ()
 returns system drumkits path More...
 
static QString usr_drumkits_dir ()
 returns user drumkits path More...
 
static QString playlists_dir ()
 returns user playlist path More...
 
static QString playlist_path (const QString &pl_name)
 returns user playlist path, add file extension More...
 
static QString untitled_playlist_file_name ()
 returns untitled playlist file name More...
 
static QString cache_dir ()
 returns user cache path More...
 
static QString repositories_cache_dir ()
 returns user repository cache path More...
 
static QString demos_dir ()
 returns system demos path More...
 
static QString xsd_dir ()
 returns system xsd path More...
 
static QString tmp_dir ()
 returns temp path More...
 
static QString tmp_file_path (const QString &base)
 touch a temporary file under tmp_dir() and return it's path. More...
 
static QString prepare_sample_path (const QString &fname)
 Returns the basename if the given path is under an existing user or system drumkit path, otherwise the given fname. More...
 
static bool file_is_under_drumkit (const QString &fname)
 Checks if the given filepath is under an existing user or system drumkit path, not the existence of the file. More...
 
static int get_basename_idx_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. More...
 
static QStringList sys_drumkit_list ()
 returns list of usable system drumkits ( see Filesystem::drumkit_list ) More...
 
static QStringList usr_drumkit_list ()
 returns list of usable user drumkits ( see Filesystem::drumkit_list ) More...
 
static bool drumkit_exists (const QString &dk_name)
 returns true if the drumkit exists within usable system or user drumkits More...
 
static QString drumkit_usr_path (const QString &dk_name)
 returns path for a drumkit within user drumkit path More...
 
static QString drumkit_path_search (const QString &dk_name, Lookup lookup=Lookup::stacked, bool bSilent=false)
 Returns the path to a H2Core::Drumkit folder. More...
 
static QString drumkit_dir_search (const QString &dk_name, Lookup lookup)
 returns the directory holding the named drumkit searching within user then system drumkits More...
 
static bool drumkit_valid (const QString &dk_path)
 returns true if the path contains a usable drumkit More...
 
static QString drumkit_file (const QString &dk_path)
 returns the path to the xml file within a supposed drumkit path More...
 
static QStringList pattern_drumkits ()
 returns a list of existing drumkit sub dir into the patterns directory More...
 
static QStringList pattern_list ()
 returns a list of existing patterns More...
 
static QStringList pattern_list (const QString &path)
 returns a list of existing patterns More...
 
static QStringList song_list ()
 returns a list of existing songs More...
 
static QStringList song_list_cleared ()
 returns a list of existing songs, excluding the autosaved one More...
 
static bool song_exists (const QString &sg_name)
 returns true if the song file exists More...
 
static void info ()
 send current settings information to logger with INFO severity More...
 
static QStringList playlist_list ()
 returns a list of existing playlists More...
 
static bool file_exists (const QString &path, bool silent=false)
 returns true if the given path is an existing regular file More...
 
static bool file_readable (const QString &path, bool silent=false)
 returns true if the given path is an existing readable regular file More...
 
static bool file_writable (const QString &path, bool silent=false)
 returns true if the given path is a possibly writable file (may exist or not) More...
 
static bool file_executable (const QString &path, bool silent=false)
 returns true if the given path is an existing executable regular file More...
 
static bool dir_readable (const QString &path, bool silent=false)
 returns true if the given path is a readable regular directory More...
 
static bool dir_writable (const QString &path, bool silent=false)
 returns true if the given path is a writable regular directory More...
 
static bool path_usable (const QString &path, bool create=true, bool silent=false)
 returns true if the path is a readable and writable regular directory, create if it not exists More...
 
static bool write_to_file (const QString &dst, const QString &content)
 writes to a file More...
 
static bool file_copy (const QString &src, const QString &dst, bool overwrite=false)
 copy a source file to a destination More...
 
static bool rm (const QString &path, bool recursive=false)
 remove a path More...
 
static bool mkdir (const QString &path)
 create a path More...
 
static const QString & getPreferencesOverwritePath ()
 
static void setPreferencesOverwritePath (const QString &sPath)
 
- Static Public Member Functions inherited from Object
static void set_count (bool flag)
 enable/disable class instances counting More...
 
static bool count_active ()
 return true if class instances counting is enabled More...
 
static unsigned objects_count ()
 return the number of objects More...
 
static void write_objects_map_to (std::ostream &out)
 output the full objects map to a given ostream More...
 
static void write_objects_map_to_cerr ()
 output objects map to stderr More...
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation ! More...
 
static Loggerlogger ()
 return the logger instance More...
 

Static Public Attributes

static const QString songs_ext = ".h2song"
 
static const QString scripts_ext = ".sh"
 
static const QString patterns_ext = ".h2pattern"
 
static const QString playlist_ext = ".h2playlist"
 
static const QString drumkit_ext = ".h2drumkit"
 
static const QString songs_filter_name = "Hydrogen Songs (*.h2song)"
 
static const QString scripts_filter_name = "Hydrogen Scripts (*.sh)"
 
static const QString patterns_filter_name = "Hydrogen Patterns (*.h2pattern)"
 
static const QString playlists_filter_name = "Hydrogen Playlists (*.h2playlist)"
 
- Static Public Attributes inherited from Object
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes. More...
 

Static Private Member Functions

static bool check_sys_paths ()
 returns true if the system path is consistent More...
 
static bool check_usr_paths ()
 returns true if the user path is consistent More...
 
static bool rm_fr (const QString &path)
 recursively remove a path More...
 
static QStringList drumkit_list (const QString &path)
 
static bool check_permissions (const QString &path, const int perms, bool silent)
 

Static Private Attributes

static Logger__logger = nullptr
 a pointer to the logger More...
 
static QString m_sPreferencesOverwritePath = ""
 If this variable is non-empty, its content will be used as an alternative to store and load the preferences. More...
 
static QString __sys_data_path
 Path to the system files set in Filesystem::bootstrap(). More...
 
static QString __usr_data_path
 the path to the user files More...
 
static QString __usr_cfg_path
 the path to the user config file More...
 
static QString __usr_log_path = QDir::homePath().append( "/" H2_USR_PATH "/" LOG_FILE)
 the path to the log file More...
 
static QStringList __ladspa_paths
 paths to laspa plugins More...
 

Additional Inherited Members

- Public Member Functions inherited from Object
 ~Object ()
 destructor More...
 
 Object (const Object &obj)
 copy constructor More...
 
 Object (const char *class_name)
 constructor More...
 
const char * class_name () const
 return the class name More...
 
virtual QString toQString (const QString &sPrefix, bool bShort=true) const
 Formatted string version for debugging purposes. More...
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG. More...
 
- Static Protected Attributes inherited from Object
static Logger__logger = nullptr
 logger instance pointer More...
 

Detailed Description

Filesystem is a thin layer over QDir, QFile and QFileInfo.

Member Enumeration Documentation

◆ file_perms

enum file_perms

flags available for check_permissions()

Enumerator
is_dir 
is_file 
is_readable 
is_writable 
is_executable 

◆ Lookup

enum class Lookup
strong

Whenever a drumkit is loaded by name a collision between a user and a system drumkit carrying the same name can occur.

Enumerator
stacked 

First, looks in the system drumkits and, afterwards, in the user drumkits.

In case both sets contain a member sharing the requested name, the user one will override the system one.

This is the way Hydrogen <= 1.1 were handling all look ups.

user 

Only search the user drumkits.

system 

Only search the system drumkits.

Member Function Documentation

◆ bootstrap()

bool bootstrap ( Logger logger,
const QString &  sys_path = nullptr 
)
static

check user and system filesystem usability

Parameters
loggeris a pointer to the logger instance which will be used
sys_pathan alternate system data path

◆ cache_dir()

QString cache_dir ( )
static

returns user cache path

◆ check_permissions()

bool check_permissions ( const QString &  path,
const int  perms,
bool  silent 
)
staticprivate
Returns
true if all the asked permissions are ok
Parameters
paththe path to the file to check
permsbit mask of file_perms
silentoutput not messages if set to true

◆ check_sys_paths()

bool check_sys_paths ( )
staticprivate

returns true if the system path is consistent

◆ check_usr_paths()

bool check_usr_paths ( )
staticprivate

returns true if the user path is consistent

◆ click_file_path()

QString click_file_path ( )
static

Returns a string containing the path to the click.wav file used in the metronome.

  It is a concatenation of #__sys_data_path and
  #CLICK_SAMPLE.

◆ demos_dir()

QString demos_dir ( )
static

returns system demos path

◆ dir_readable()

bool dir_readable ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is a readable regular directory

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ dir_writable()

bool dir_writable ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is a writable regular directory

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ doc_dir()

QString doc_dir ( )
static

returns documentation path

◆ drumkit_dir_search()

QString drumkit_dir_search ( const QString &  dk_name,
Lookup  lookup 
)
static

returns the directory holding the named drumkit searching within user then system drumkits

Parameters
dk_namethe drumkit name
lookupWhere to search (system/user folder or both) for the drumkit.

◆ drumkit_exists()

bool drumkit_exists ( const QString &  dk_name)
static

returns true if the drumkit exists within usable system or user drumkits

Parameters
dk_namethe drumkit name

◆ drumkit_file()

QString drumkit_file ( const QString &  dk_path)
static

returns the path to the xml file within a supposed drumkit path

Parameters
dk_paththe path to the drumkit

◆ drumkit_list()

QStringList drumkit_list ( const QString &  path)
staticprivate
Returns
a list of usable drumkits, which means having a readable drumkit.xml file
Parameters
paththe path to search in for drumkits

◆ drumkit_path_search()

QString drumkit_path_search ( const QString &  dk_name,
Lookup  lookup = Lookup::stacked,
bool  bSilent = false 
)
static

Returns the path to a H2Core::Drumkit folder.

The search will first be performed within user-level drumkits system drumkits using usr_drumkit_list() and usr_drumkits_dir() and later, in case the H2Core::Drumkit could not be found, within the system-level drumkits using sys_drumkit_list() and sys_drumkits_dir().

When under session management (see NsmClient::m_bUnderSessionManagement) the function will first look for a "drumkit" symlink or folder within NsmClient::m_sSessionFolderPath. If it either is not a valid H2Core::Drumkit or the not the one corresponding to dk_name, the user- and system-level drumkits will be searched instead.

Parameters
dk_nameName of the H2Core::Drumkit. In the user-level and system-level lookup it has to correspond to the name of the folder holding the samples and the DRUMKIT_XML file. For the usage of a local H2Core::Drumkit under session management it has to match the second-level "name" node within the DRUMKIT_XML file.
lookupWhere to search (system/user folder or both) for the drumkit.
bSilentwhether the function should trigger log messages. If set to true, the calling function is expected to handle the log messages instead.
Returns
Full path to the folder containing the samples of the H2Core::Drumkit corresponding to dk_name.

◆ drumkit_usr_path()

QString drumkit_usr_path ( const QString &  dk_name)
static

returns path for a drumkit within user drumkit path

Parameters
dk_namethe drumkit name

◆ drumkit_valid()

bool drumkit_valid ( const QString &  dk_path)
static

returns true if the path contains a usable drumkit

Parameters
dk_paththe root drumkit location

◆ drumkit_xsd_path()

QString drumkit_xsd_path ( )
static

returns the path to the drumkit XSD (xml schema definition) file

◆ empty_sample_path()

QString empty_sample_path ( )
static

returns system empty sample file path

◆ empty_song_path()

QString empty_song_path ( )
static

returns system empty song file path

◆ file_copy()

bool file_copy ( const QString &  src,
const QString &  dst,
bool  overwrite = false 
)
static

copy a source file to a destination

Parameters
srcsource file path
dstdestination file path
overwriteallow to overwrite an existing file if set to true

◆ file_executable()

bool file_executable ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is an existing executable regular file

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ file_exists()

bool file_exists ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is an existing regular file

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ file_is_under_drumkit()

bool file_is_under_drumkit ( const QString &  fname)
static

Checks if the given filepath is under an existing user or system drumkit path, not the existence of the file.

◆ file_readable()

bool file_readable ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is an existing readable regular file

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ file_writable()

bool file_writable ( const QString &  path,
bool  silent = false 
)
static

returns true if the given path is a possibly writable file (may exist or not)

Parameters
paththe path to the file to check
silentoutput not messages if set to true

◆ get_basename_idx_under_drumkit()

int get_basename_idx_under_drumkit ( const QString &  fname)
static

Returns the index of the basename if the given path is under an existing user or system drumkit path, otherwise -1.

◆ getPreferencesOverwritePath()

const QString & getPreferencesOverwritePath ( )
inlinestatic
Returns
m_sPreferencesOverwritePath

◆ i18n_dir()

QString i18n_dir ( )
static

returns internationalization path

◆ img_dir()

QString img_dir ( )
static

returns gui image path

◆ info()

void info ( )
static

send current settings information to logger with INFO severity

◆ ladspa_paths()

QStringList ladspa_paths ( )
static

returns user ladspa paths

◆ log_file_path()

QString log_file_path ( )
static

returns the full path (including filename) of the logfile

◆ mkdir()

bool mkdir ( const QString &  path)
static

create a path

Parameters
paththe path to the directory to be created

◆ path_usable()

bool path_usable ( const QString &  path,
bool  create = true,
bool  silent = false 
)
static

returns true if the path is a readable and writable regular directory, create if it not exists

Parameters
paththe path to the file to check
createwill try to create path if not exists and set to true
silentoutput not messages if set to true

◆ pattern_drumkits()

QStringList pattern_drumkits ( )
static

returns a list of existing drumkit sub dir into the patterns directory

◆ pattern_list() [1/2]

QStringList pattern_list ( )
static

returns a list of existing patterns

◆ pattern_list() [2/2]

QStringList pattern_list ( const QString &  path)
static

returns a list of existing patterns

Parameters
paththe path to look for patterns in

◆ pattern_path()

QString pattern_path ( const QString &  dk_name,
const QString &  p_name 
)
static

returns user patterns path, add file extension

◆ pattern_xsd_path()

QString pattern_xsd_path ( )
static

returns the path to the pattern XSD (xml schema definition) file

◆ patterns_dir() [1/2]

QString patterns_dir ( )
static

returns user patterns path

◆ patterns_dir() [2/2]

QString patterns_dir ( const QString &  dk_name)
static

returns user patterns path for a specific drumkit

◆ playlist_list()

QStringList playlist_list ( )
static

returns a list of existing playlists

◆ playlist_path()

QString playlist_path ( const QString &  pl_name)
static

returns user playlist path, add file extension

◆ playlist_xsd_path()

QString playlist_xsd_path ( )
static

returns the path to the playlist pattern XSD (xml schema definition) file

◆ playlists_dir()

QString playlists_dir ( )
static

returns user playlist path

◆ plugins_dir()

QString plugins_dir ( )
static

returns user plugins path

◆ prepare_sample_path()

QString prepare_sample_path ( const QString &  fname)
static

Returns the basename if the given path is under an existing user or system drumkit path, otherwise the given fname.

◆ repositories_cache_dir()

QString repositories_cache_dir ( )
static

returns user repository cache path

◆ rm()

bool rm ( const QString &  path,
bool  recursive = false 
)
static

remove a path

Parameters
paththe path to be removed
recursiveperform recursive removal if set to true

◆ rm_fr()

bool rm_fr ( const QString &  path)
staticprivate

recursively remove a path

◆ scripts_dir()

QString scripts_dir ( )
static

returns user scripts path

◆ setPreferencesOverwritePath()

void setPreferencesOverwritePath ( const QString &  sPath)
inlinestatic
Parameters
sPathSets m_sPreferencesOverwritePath

◆ song_exists()

bool song_exists ( const QString &  sg_name)
static

returns true if the song file exists

Parameters
sg_namethe song name

◆ song_list()

QStringList song_list ( )
static

returns a list of existing songs

◆ song_list_cleared()

QStringList song_list_cleared ( )
static

returns a list of existing songs, excluding the autosaved one

◆ song_path()

QString song_path ( const QString &  sg_name)
static

returns user song path, add file extension

◆ songs_dir()

QString songs_dir ( )
static

returns user songs path

◆ sys_config_path()

QString sys_config_path ( )
static

returns system config path

◆ sys_data_path()

QString sys_data_path ( )
static

returns system data path

◆ sys_drumkit_list()

QStringList sys_drumkit_list ( )
static

returns list of usable system drumkits ( see Filesystem::drumkit_list )

◆ sys_drumkits_dir()

QString sys_drumkits_dir ( )
static

returns system drumkits path

◆ tmp_dir()

QString tmp_dir ( )
static

returns temp path

◆ tmp_file_path()

QString tmp_file_path ( const QString &  base)
static

touch a temporary file under tmp_dir() and return it's path.

if base has a suffix it will be preserved, spaces will be replaced by underscores.

Parameters
basepart of the path

◆ untitled_playlist_file_name()

QString untitled_playlist_file_name ( )
static

returns untitled playlist file name

◆ untitled_song_file_name()

QString untitled_song_file_name ( )
static

returns untitled song file name

◆ usr_click_file_path()

QString usr_click_file_path ( )
static

returns click file path from user directory if exists, otherwise from system

◆ usr_config_path()

QString usr_config_path ( )
static

returns user config path

◆ usr_data_path()

QString usr_data_path ( )
static

returns user data path

◆ usr_drumkit_list()

QStringList usr_drumkit_list ( )
static

returns list of usable user drumkits ( see Filesystem::drumkit_list )

◆ usr_drumkits_dir()

QString usr_drumkits_dir ( )
static

returns user drumkits path

◆ write_to_file()

bool write_to_file ( const QString &  dst,
const QString &  content 
)
static

writes to a file

Parameters
dstthe destination path
contentthen string to write

◆ xsd_dir()

QString xsd_dir ( )
static

returns system xsd path

Field Documentation

◆ __ladspa_paths

QStringList __ladspa_paths
staticprivate

paths to laspa plugins

◆ __logger

Logger * __logger = nullptr
staticprivate

a pointer to the logger

◆ __sys_data_path

QString __sys_data_path
staticprivate

Path to the system files set in Filesystem::bootstrap().

If Q_OSMACX is set, it will be a concatenation of QCoreApplication::applicationDirPath() and "/../Resources/data/" (H2CORE_HAVE_BUNDLE defined) or "/data/" (else). If, instead, WIN32 is set, it is a concatenation of QCoreApplication::applicationDirPath() and "/data/". In case the application is neither run on Mac or Windows, it is set to a concatenation of H2_SYS_PATH and "/data/".

If Filesystem::bootstrap() was called with the sys_path argument preset, it will overwrite all the choices above.

Finally, if the variable doesn't point to a readable directory afterwards, it is set to a concatenation of QCoreApplication::applicationDirPath(), "/", and LOCAL_DATA_PATH. the path to the system files

◆ __usr_cfg_path

QString __usr_cfg_path
staticprivate

the path to the user config file

◆ __usr_data_path

QString __usr_data_path
staticprivate

the path to the user files

◆ __usr_log_path

QString __usr_log_path = QDir::homePath().append( "/" H2_USR_PATH "/" LOG_FILE)
staticprivate

the path to the log file

◆ drumkit_ext

const QString drumkit_ext = ".h2drumkit"
static

◆ m_sPreferencesOverwritePath

QString m_sPreferencesOverwritePath = ""
staticprivate

If this variable is non-empty, its content will be used as an alternative to store and load the preferences.

◆ patterns_ext

const QString patterns_ext = ".h2pattern"
static

◆ patterns_filter_name

const QString patterns_filter_name = "Hydrogen Patterns (*.h2pattern)"
static

◆ playlist_ext

const QString playlist_ext = ".h2playlist"
static

◆ playlists_filter_name

const QString playlists_filter_name = "Hydrogen Playlists (*.h2playlist)"
static

◆ scripts_ext

const QString scripts_ext = ".sh"
static

◆ scripts_filter_name

const QString scripts_filter_name = "Hydrogen Scripts (*.sh)"
static

◆ songs_ext

const QString songs_ext = ".h2song"
static

◆ songs_filter_name

const QString songs_filter_name = "Hydrogen Songs (*.h2song)"
static