hydrogen 1.2.6
Filesystem.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2C_FILESYSTEM_H
24#define H2C_FILESYSTEM_H
25
26#include <core/Object.h>
27#include <QtCore/QString>
28
29#include <vector>
30
31namespace H2Core
32{
33
38 class Filesystem : public H2Core::Object<Filesystem>
39 {
41 public:
50
55 enum class Lookup {
65 user = 1,
68 };
69
88
107
109 static QString AudioFormatToSuffix( const AudioFormat& format,
110 bool bSilent = false );
113 static AudioFormat AudioFormatFromSuffix( const QString& sFile,
114 bool bSilent = false );
115
116
117 static const QString songs_ext;
118 static const QString scripts_ext;
119 static const QString patterns_ext;
120 static const QString playlist_ext;
121 static const QString drumkit_ext;
122 static const QString themes_ext;
123 static const QString songs_filter_name;
124 static const QString themes_filter_name;
125 static const QString scripts_filter_name;
126 static const QString patterns_filter_name;
127 static const QString playlists_filter_name;
128
141 static bool bootstrap( Logger* logger,
142 const QString& sSysDataPath = "",
143 const QString& sUsrDataPath = "",
144 const QString& sUserConfigFile = "",
145 const QString& sLogFile = "" );
146
148 static QString sys_data_path();
150 static QString usr_data_path();
151
153 static QStringList ladspa_paths();
154
156 static QString sys_config_path();
160 static QString usr_config_path();
162 static QString empty_sample_path();
187 static QString empty_song_path();
190 static QString default_song_name();
192 static QString untitled_song_name();
199 static QString click_file_path();
201 static QString usr_click_file_path();
203 static QString drumkit_xsd( );
205 static QString drumkit_xsd_path( );
208 static QStringList drumkit_xsd_legacy_paths( );
210 static QString pattern_xsd_path( );
212 static QString playlist_xsd_path( );
214 static QString log_file_path();
215
217 static QString img_dir();
219 static QString doc_dir();
221 static QString i18n_dir();
223 static QString scripts_dir();
225 static QString songs_dir();
227 static QString song_path( const QString& sg_name );
229 static QString patterns_dir();
231 static QString patterns_dir( const QString& dk_name );
233 static QString pattern_path( const QString& dk_name, const QString& p_name );
235 static QString plugins_dir();
237 static QString sys_drumkits_dir();
239 static QString usr_drumkits_dir();
241 static QString playlists_dir();
243 static QString playlist_path( const QString& pl_name );
245 static QString untitled_playlist_file_name();
247 static QString cache_dir();
249 static QString repositories_cache_dir();
251 static QString demos_dir();
253 static QString xsd_dir();
254 static QString xsd_legacy_dir();
256 static QString tmp_dir();
257 static QString usr_theme_dir();
258 static QString sys_theme_dir();
264 static QString tmp_file_path( const QString& base );
265
266 /* DRUMKIT */
269 static QString prepare_sample_path( const QString& sFilePath );
271 static QStringList sys_drumkit_list( );
273 static QStringList usr_drumkit_list( );
278 static bool drumkit_exists( const QString& dk_name );
283 static QString drumkit_usr_path( const QString& dk_name );
284 static QString drumkit_default_kit();
317 static QString drumkit_path_search( const QString& dk_name, Lookup lookup = Lookup::stacked, bool bSilent = false );
324 static QString drumkit_dir_search( const QString& dk_name, Lookup lookup );
329 static bool drumkit_valid( const QString& dk_path );
334 static QString drumkit_file( const QString& dk_path );
335
339 static QString drumkit_xml();
340
346 static QString drumkit_backup_path( const QString& dk_path );
347
348 /* PATTERNS */
352 static QStringList pattern_drumkits();
356 static QStringList pattern_list();
361 static QStringList pattern_list( const QString& path );
362
363 /* SONGS */
365 static QStringList song_list( );
367 static QStringList song_list_cleared( );
372 static bool song_exists( const QString& sg_name );
373
391 static bool isSongPathValid( const QString& sSongPath, bool bCheckExistance = false );
392
398 static QString validateFilePath( const QString& sPath );
399
400 static QStringList theme_list();
401
403 static void info();
404
405 /* PLAYLISTS */
407 static QStringList playlist_list( );
408
414 static bool file_exists( const QString& path, bool silent=false );
420 static bool file_readable( const QString& path, bool silent=false );
426 static bool file_writable( const QString& path, bool silent=false );
432 static bool file_executable( const QString& path, bool silent=false );
438 static bool dir_exists( const QString& path, bool silent=false );
444 static bool dir_readable( const QString& path, bool silent=false );
450 static bool dir_writable( const QString& path, bool silent=false );
457 static bool path_usable( const QString& path, bool create=true, bool silent=false );
458
462 static QString absolute_path( const QString& sFilename, bool bSilent = false );
468 static QString ensure_session_compatibility( const QString& sPath );
474 static bool write_to_file( const QString& dst, const QString& content );
483 static bool file_copy( const QString& src, const QString& dst, bool overwrite=false, bool bSilent = false );
491 static bool rm( const QString& path, bool recursive=false, bool bSilent = false );
496 static bool mkdir( const QString& path );
497
499 static const QString& getPreferencesOverwritePath();
501 static void setPreferencesOverwritePath( const QString& sPath );
502
507 static DrumkitType determineDrumkitType( const QString& sPath );
508
525 static QString rerouteDrumkitPath( const QString& sDrumkitPath );
526
529 static QString removeUtf8Characters( const QString& sEncodedString );
530
534 static const std::vector<AudioFormat>& supportedAudioFormats();
535
536 private:
537 static Logger* __logger;
538 static bool check_sys_paths();
539 static bool check_usr_paths();
540 static bool rm_fr( const QString& path, bool bSilent = false );
541
550 static QStringList drumkit_list( const QString& path );
557 static bool check_permissions( const QString& path, const int perms, bool silent );
558
582 static QString __sys_data_path;
583 static QString __usr_data_path;
584 static QString __usr_cfg_path;
585 static QString __usr_log_path;
586 static QStringList __ladspa_paths;
587 static std::vector<AudioFormat> m_supportedAudioFormats;
588 };
589
593 inline void Filesystem::setPreferencesOverwritePath( const QString& sPath ) {
595 }
596
597};
598#endif // H2C_FILESYSTEM_H
599
600/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:227
static Logger * logger()
return the logger instance
Definition Object.h:103
Filesystem is a thin layer over QDir, QFile and QFileInfo.
Definition Filesystem.h:39
static QStringList song_list()
returns a list of existing songs
static QString __usr_cfg_path
the path to the user config file
Definition Filesystem.h:584
static bool file_copy(const QString &src, const QString &dst, bool overwrite=false, bool bSilent=false)
copy a source file to a destination
static QString scripts_dir()
returns user scripts path
static const QString patterns_filter_name
Definition Filesystem.h:126
static QString playlist_xsd_path()
returns the path to the playlist pattern XSD (xml schema definition) file
static QString validateFilePath(const QString &sPath)
Takes an arbitrary path, replaces white spaces by underscores and removes all characters apart from l...
static QString demos_dir()
returns system demos path
static QString song_path(const QString &sg_name)
returns user song path, add file extension
static QString ensure_session_compatibility(const QString &sPath)
If Hydrogen is under session management, we support for paths relative to the session folder.
static QString sys_data_path()
returns system data path
static bool dir_readable(const QString &path, bool silent=false)
returns true if the given path is a readable regular directory
file_perms
flags available for check_permissions()
Definition Filesystem.h:43
static std::vector< AudioFormat > m_supportedAudioFormats
Definition Filesystem.h:587
static QString cache_dir()
returns user cache path
static const QString patterns_ext
Definition Filesystem.h:119
static bool drumkit_exists(const QString &dk_name)
returns true if the drumkit exists within usable system or user drumkits
static bool check_usr_paths()
returns true if the user path is consistent
static const QString scripts_filter_name
Definition Filesystem.h:125
static QString removeUtf8Characters(const QString &sEncodedString)
Removes all characters not within the Latin-1 range of sEncodedString.
static bool file_executable(const QString &path, bool silent=false)
returns true if the given path is an existing executable regular file
static AudioFormat AudioFormatFromSuffix(const QString &sFile, bool bSilent=false)
Determines the audio format of the provided filename or path based on its suffix.
static bool isSongPathValid(const QString &sSongPath, bool bCheckExistance=false)
Checks the path pointing to a .h2song.
static bool drumkit_valid(const QString &dk_path)
returns true if the path contains a usable drumkit
static QString playlist_path(const QString &pl_name)
returns user playlist path, add file extension
static QStringList drumkit_list(const QString &path)
static void setPreferencesOverwritePath(const QString &sPath)
Definition Filesystem.h:593
static bool check_permissions(const QString &path, const int perms, bool silent)
static QString usr_config_path()
static QString songs_dir()
returns user songs path
static QString pattern_xsd_path()
returns the path to the pattern XSD (xml schema definition) file
static const QString themes_ext
Definition Filesystem.h:122
static QString playlists_dir()
returns user playlist path
static DrumkitType determineDrumkitType(const QString &sPath)
static QString usr_click_file_path()
returns click file path from user directory if exists, otherwise from system
static bool bootstrap(Logger *logger, const QString &sSysDataPath="", const QString &sUsrDataPath="", const QString &sUserConfigFile="", const QString &sLogFile="")
check user and system filesystem usability
static QString empty_sample_path()
returns system empty sample file path
static QStringList playlist_list()
returns a list of existing playlists
static QString absolute_path(const QString &sFilename, bool bSilent=false)
Convert a direct to an absolute path.
static QString plugins_dir()
returns user plugins path
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)
static QStringList theme_list()
static QString usr_drumkits_dir()
returns user drumkits path
static QString untitled_song_name()
returns untitled song name
static bool check_sys_paths()
returns true if the system path is consistent
static const QString & getPreferencesOverwritePath()
Definition Filesystem.h:590
static QStringList ladspa_paths()
returns user ladspa paths
static QStringList drumkit_xsd_legacy_paths()
static QStringList pattern_list()
returns a list of existing patterns
static QString sys_drumkits_dir()
returns system drumkits path
static bool rm(const QString &path, bool recursive=false, bool bSilent=false)
remove a path
static QString drumkit_backup_path(const QString &dk_path)
Create a backup path from a drumkit path.
static QStringList song_list_cleared()
returns a list of existing songs, excluding the autosaved one
static QString usr_theme_dir()
static QString drumkit_xsd_path()
returns the path to the drumkit XSD (xml schema definition) file
static QString doc_dir()
returns documentation path
static const QString scripts_ext
Definition Filesystem.h:118
static QStringList usr_drumkit_list()
returns list of usable user drumkits ( see Filesystem::drumkit_list )
static QString repositories_cache_dir()
returns user repository cache path
static QString prepare_sample_path(const QString &sFilePath)
Returns the basename if the given path is under an existing user or system drumkit path,...
static bool rm_fr(const QString &path, bool bSilent=false)
recursively remove a path
static bool dir_writable(const QString &path, bool silent=false)
returns true if the given path is a writable regular directory
static QString img_dir()
returns gui image path
static QString rerouteDrumkitPath(const QString &sDrumkitPath)
Reroutes stored drumkit paths pointing to a temporary AppImage system data folder to the current AppI...
static bool file_exists(const QString &path, bool silent=false)
returns true if the given path is an existing regular file
static QString __usr_data_path
the path to the user files
Definition Filesystem.h:583
static const std::vector< AudioFormat > & supportedAudioFormats()
Which format is supported is determined by the libsndfile version Hydrogen is linked against during c...
static QString empty_song_path()
Provides the full path to the current empty song.
AudioFormat
All audio file formats supported by Hydrogen.
Definition Filesystem.h:90
Lookup
Whenever a drumkit is loaded by name a collision between a user and a system drumkit carrying the sam...
Definition Filesystem.h:55
@ system
Only search the system drumkits.
Definition Filesystem.h:67
@ stacked
First, looks in the system drumkits and, afterwards, in the user drumkits.
Definition Filesystem.h:63
@ user
Only search the user drumkits.
Definition Filesystem.h:65
static QString drumkit_dir_search(const QString &dk_name, Lookup lookup)
returns the directory holding the named drumkit searching within user then system drumkits
static QString m_sPreferencesOverwritePath
If this variable is non-empty, its content will be used as an alternative to store and load the prefe...
Definition Filesystem.h:545
static QString click_file_path()
Returns a string containing the path to the click.wav file used in the metronome.
static QStringList sys_drumkit_list()
returns list of usable system drumkits ( see Filesystem::drumkit_list )
static QString drumkit_path_search(const QString &dk_name, Lookup lookup=Lookup::stacked, bool bSilent=false)
Returns the path to a H2Core::Drumkit folder.
static const QString playlists_filter_name
Definition Filesystem.h:127
static QString sys_config_path()
returns system config path
static bool mkdir(const QString &path)
create a path
static QString drumkit_file(const QString &dk_path)
returns the path to the xml file within a supposed drumkit path
static QStringList pattern_drumkits()
returns a list of existing drumkit sub dir into the patterns directory
static QString __sys_data_path
Path to the system files set in Filesystem::bootstrap().
Definition Filesystem.h:582
static QString pattern_path(const QString &dk_name, const QString &p_name)
returns user patterns path, add file extension
static QString __usr_log_path
the path to the log file
Definition Filesystem.h:585
static bool write_to_file(const QString &dst, const QString &content)
writes to a file
static Logger * __logger
a pointer to the logger
Definition Filesystem.h:537
static const QString playlist_ext
Definition Filesystem.h:120
static QString i18n_dir()
returns internationalization path
static const QString songs_filter_name
Definition Filesystem.h:123
static QString xsd_legacy_dir()
static QString tmp_dir()
returns temp path
DrumkitType
Determines were to find a kit and whether it is writable by the current user.
Definition Filesystem.h:72
@ SessionReadWrite
Kit was loaded via a NSM session, OSC command, or CLI option, only persist for the current Hydrogen s...
Definition Filesystem.h:86
@ User
Kit was installed by the user, is automatically loaded, and most probably writable.
Definition Filesystem.h:78
@ System
Kit was installed with Hydrogen, is automatically loaded, and most probably readonly.
Definition Filesystem.h:75
@ SessionReadOnly
Kit was loaded via a NSM session, OSC command, or CLI option, only persist for the current Hydrogen s...
Definition Filesystem.h:82
static void info()
send current settings information to logger with INFO severity
static QString usr_data_path()
returns user data path
static QString log_file_path()
returns the full path (including filename) of the logfile
static QString drumkit_usr_path(const QString &dk_name)
returns path for a drumkit within user drumkit path
static const QString drumkit_ext
Definition Filesystem.h:121
static const QString themes_filter_name
Definition Filesystem.h:124
static const QString songs_ext
Definition Filesystem.h:117
static QString sys_theme_dir()
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
static QString AudioFormatToSuffix(const AudioFormat &format, bool bSilent=false)
Converts format to the default lower case suffix of the format.
static QString drumkit_xml()
Returns filename and extension of the expected drumkit file.
static QString drumkit_xsd()
returns the drumkit XSD (xml schema definition) name
static QString tmp_file_path(const QString &base)
touch a temporary file under tmp_dir() and return it's path.
static QString default_song_name()
Default option to offer the user when saving an empty song to disk.
static QString xsd_dir()
returns system xsd path
static bool song_exists(const QString &sg_name)
returns true if the song file exists
static QStringList __ladspa_paths
paths to laspa plugins
Definition Filesystem.h:586
static QString untitled_playlist_file_name()
returns untitled playlist file name
static bool file_readable(const QString &path, bool silent=false)
returns true if the given path is an existing readable regular file
static bool dir_exists(const QString &path, bool silent=false)
returns true if the given path is a regular directory
static QString drumkit_default_kit()
static QString patterns_dir()
returns user patterns path
Class for writing logs to the console.
Definition Logger.h:41