hydrogen 1.2.6
Drumkit Class Reference

Drumkit info. More...

#include <Drumkit.h>

Inheritance diagram for Drumkit:
Object< Drumkit > Base

Public Member Functions

 Drumkit ()
 drumkit constructor, does nothing
 
 Drumkit (std::shared_ptr< Drumkit > other)
 copy constructor
 
 ~Drumkit ()
 drumkit destructor, delete __instruments
 
void addComponent (std::shared_ptr< DrumkitComponent > pComponent)
 
void addInstrument (std::shared_ptr< Instrument > pInstrument)
 Adds an instrument and takes care of registering DrumkitComponents missing for contained InstrumentComponents (based on their ID).
 
bool exportTo (const QString &sTargetDir, const QString &sComponentName="", bool bRecentVersion=true, bool *pUtf8Encoded=nullptr, bool bSilent=false)
 Compresses the drumkit into a .h2drumkit file.
 
int findUnusedComponentId () const
 
const QString & get_author () const
 __author accessor
 
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > get_components ()
 
const QString & get_image () const
 __image accessor
 
const Licenseget_image_license () const
 __imageLicense accessor
 
const QString & get_info () const
 __info accessor
 
std::shared_ptr< InstrumentListget_instruments () const
 returns __instruments
 
const Licenseget_license () const
 __license accessor
 
const QString & get_name () const
 __name accessor
 
const QString & get_path () const
 __path accessor
 
std::shared_ptr< DrumkitComponentgetComponent (int nID) const
 
QString getExportName (const QString &sComponentName, bool bRecentVersion) const
 Returns the base name used when exporting the drumkit.
 
QString getFolderName () const
 Returns a version of __name stripped of all whitespaces and other characters which would prevent its use as a valid filename.
 
void load_samples ()
 Calls the InstrumentList::load_samples() member function of __instruments.
 
void propagateLicense ()
 Assign the license stored in #m_license to all samples contained in the kit.
 
const bool samples_loaded () const
 return true if the samples are loaded
 
bool save (const QString &sDrumkitPath="", int nComponentID=-1, bool bRecentVersion=true, bool bSilent=false)
 Save a drumkit to disk.
 
void set_author (const QString &author)
 __author setter
 
void set_components (std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > components)
 
void set_image (const QString &image)
 __image setter
 
void set_image_license (const License &imageLicense)
 __imageLicense setter
 
void set_info (const QString &info)
 __info setter
 
void set_instruments (std::shared_ptr< InstrumentList > instruments)
 set __instruments, delete existing one
 
void set_license (const License &license)
 __license setter
 
void set_name (const QString &name)
 __name setter
 
void set_path (const QString &path)
 __path setter
 
std::vector< std::shared_ptr< InstrumentList::Content > > summarizeContent () const
 Returns vector of lists containing instrument name, component name, file name, the license of all associated samples.
 
QString toQString (const QString &sPrefix="", bool bShort=true) const override
 Formatted string version for debugging purposes.
 
void unload_samples ()
 Calls the InstrumentList::unload_samples() member function of __instruments.
 
- Public Member Functions inherited from Object< Drumkit >
 Object ()
 
 Object (const Object< Drumkit > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void logBacktrace () const
 Print the current stack at point into the debug log.
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 

Static Public Member Functions

static bool install (const QString &sSourcePath, const QString &sTargetPath="", QString *pInstalledPath=nullptr, bool *pEncodingIssuesDetected=nullptr, bool bSilent=false)
 Extract a .h2drumkit file.
 
static std::shared_ptr< Drumkitload (const QString &dk_dir, bool bUpgrade=true, bool *pLegacyFormatEncountered=nullptr, bool bSilent=false)
 Load drumkit information from a directory.
 
static License loadLicenseFrom (const QString &sDrumkitDir, bool bSilent=false)
 Loads the license information of a drumkit contained in directory sDrumkitDir.
 
static bool remove (const QString &sDrumkitDir)
 remove a drumkit from the disk
 
static void upgrade_drumkit (std::shared_ptr< Drumkit > pDrumkit, const QString &dk_path, bool bSilent=false)
 Saves the current drumkit to dk_path, but makes a backup.
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 

Private Member Functions

bool save_image (const QString &dk_dir, bool bSilent=false) const
 save the drumkit image into the new directory
 
bool save_samples (const QString &dk_dir, bool bSilent=false) const
 save a drumkit instruments samples into a directory
 
void save_to (XMLNode *node, int component_id=-1, bool bRecentVersion=true, bool bSilent=false) const
 

Static Private Member Functions

static std::shared_ptr< Drumkitload_from (XMLNode *node, const QString &dk_path, bool *pLegacyFormatEncountered=nullptr, bool bSilent=false)
 load a drumkit from an XMLNode
 
static bool loadDoc (const QString &sDrumkitDir, XMLDoc *pDoc, bool bSilent=false)
 Loads the drumkit stored in sDrumkitDir into pDoc and takes care of all the error handling.
 

Private Attributes

QString __author
 drumkit author
 
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > __components
 list of drumkit component
 
QString __image
 drumkit image filename
 
License __imageLicense
 drumkit image license
 
QString __info
 drumkit free text
 
std::shared_ptr< InstrumentList__instruments
 the list of instruments
 
License __license
 drumkit license description
 
QString __name
 drumkit name
 
QString __path
 absolute drumkit path
 
bool __samples_loaded
 true if the instrument samples are loaded
 

Additional Inherited Members

- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< Drumkit >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 
static bool bLogColors = true
 

Detailed Description

Drumkit info.

Definition at line 44 of file Drumkit.h.

Constructor & Destructor Documentation

◆ Drumkit() [1/2]

Drumkit ( )

drumkit constructor, does nothing

Definition at line 57 of file Drumkit.cpp.

◆ Drumkit() [2/2]

Drumkit ( std::shared_ptr< Drumkit > other)

copy constructor

Definition at line 71 of file Drumkit.cpp.

◆ ~Drumkit()

~Drumkit ( )

drumkit destructor, delete __instruments

Definition at line 90 of file Drumkit.cpp.

Member Function Documentation

◆ addComponent()

void addComponent ( std::shared_ptr< DrumkitComponent > pComponent)

Definition at line 567 of file Drumkit.cpp.

◆ addInstrument()

void addInstrument ( std::shared_ptr< Instrument > pInstrument)

Adds an instrument and takes care of registering DrumkitComponents missing for contained InstrumentComponents (based on their ID).

Definition at line 589 of file Drumkit.cpp.

◆ exportTo()

bool exportTo ( const QString & sTargetDir,
const QString & sComponentName = "",
bool bRecentVersion = true,
bool * pUtf8Encoded = nullptr,
bool bSilent = false )

Compresses the drumkit into a .h2drumkit file.

The name of the created file will be a concatenation of __name and Filesystem::drumkit_ext.

exportTo() ? well, export is a protected name within C++. So, we needed a less obvious name.

Parameters
sTargetDirFolder which will contain the resulting .h2drumkit file.
sComponentNameName of a particular component used in case just a single component should be exported.
bRecentVersionWhether the drumkit format should be supported by Hydrogen 0.9.7 or higher (whether it should be composed of DrumkitComponents).
pUtf8Encodedwill be set to true in case we were able to enforce 'UTF-8' as system locale in libarchive. If this didn't work, export will be done using classic Latin1 encoded filenames.
bSilentWhether debug and info messages should be logged.
Returns
true on success

Definition at line 964 of file Drumkit.cpp.

◆ findUnusedComponentId()

int findUnusedComponentId ( ) const

Definition at line 547 of file Drumkit.cpp.

◆ get_author()

const QString & get_author ( ) const
inline

__author accessor

Definition at line 370 of file Drumkit.h.

◆ get_components()

std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > get_components ( )
inline

Definition at line 420 of file Drumkit.h.

◆ get_image()

const QString & get_image ( ) const
inline

__image accessor

Definition at line 400 of file Drumkit.h.

◆ get_image_license()

const License & get_image_license ( ) const
inline

__imageLicense accessor

Definition at line 410 of file Drumkit.h.

◆ get_info()

const QString & get_info ( ) const
inline

__info accessor

Definition at line 380 of file Drumkit.h.

◆ get_instruments()

std::shared_ptr< InstrumentList > get_instruments ( ) const
inline

returns __instruments

Definition at line 338 of file Drumkit.h.

◆ get_license()

const License & get_license ( ) const
inline

__license accessor

Definition at line 390 of file Drumkit.h.

◆ get_name()

const QString & get_name ( ) const
inline

__name accessor

Definition at line 358 of file Drumkit.h.

◆ get_path()

const QString & get_path ( ) const
inline

__path accessor

Definition at line 348 of file Drumkit.h.

◆ getComponent()

std::shared_ptr< DrumkitComponent > getComponent ( int nID) const

Definition at line 536 of file Drumkit.cpp.

◆ getExportName()

QString getExportName ( const QString & sComponentName,
bool bRecentVersion ) const

Returns the base name used when exporting the drumkit.

Parameters
sComponentNameName of a particular component used in case just a single component should be exported.
bRecentVersionWhether the drumkit format should be supported by Hydrogen 0.9.7 or higher (whether it should be composed of DrumkitComponents).

Definition at line 330 of file Drumkit.cpp.

◆ getFolderName()

QString getFolderName ( ) const

Returns a version of __name stripped of all whitespaces and other characters which would prevent its use as a valid filename.

Attention: The returned string might be used as the name for the associated drumkit folder but it does not have to.

Definition at line 326 of file Drumkit.cpp.

◆ install()

bool install ( const QString & sSourcePath,
const QString & sTargetPath = "",
QString * pInstalledPath = nullptr,
bool * pEncodingIssuesDetected = nullptr,
bool bSilent = false )
static

Extract a .h2drumkit file.

Parameters
sSourcePathAbsolute path to the new drumkit archive
sTargetPathAbsolute path to where the new drumkit should be extracted to. If left empty, the user's drumkit folder will be used.
pInstalledPathWill contain the actual name of the folder the kit was installed to. In most cases this will coincide with a folder within sTargetPath named like the kit itself. But in case the system does not support UTF-8 encoding and sTargetPath contains characters other than those whitelisted in Filesystem::removeUtf8Characters, those might be omitted and the directory and files created using libarchive might differ.
pEncodingIssuesDetectedwill be set to true in case at least one filepath of extracted kit had to be altered in order to not run into UTF-8 issues.
bSilentWhether debug and info messages should be logged.
Returns
true on success

Definition at line 721 of file Drumkit.cpp.

◆ load()

std::shared_ptr< Drumkit > load ( const QString & dk_dir,
bool bUpgrade = true,
bool * pLegacyFormatEncountered = nullptr,
bool bSilent = false )
static

Load drumkit information from a directory.

Parameters
dk_dirA directory containing a drumkit, like those returned by Filesystem::drumkit_dir_search().
bUpgradeWhether the loaded drumkit should be upgraded using upgrade_drumkit() in case it did not comply with the current XSD file.
pLegacyFormatEncounteredwill be set to true is any of the XML elements requires legacy format support and left untouched otherwise.
bSilentif set to true, all log messages except of errors and warnings are suppressed.
Returns
A Drumkit on success, nullptr otherwise.

Definition at line 94 of file Drumkit.cpp.

◆ load_from()

std::shared_ptr< Drumkit > load_from ( XMLNode * node,
const QString & dk_path,
bool * pLegacyFormatEncountered = nullptr,
bool bSilent = false )
staticprivate

load a drumkit from an XMLNode

Parameters
nodethe XMLDode to read from
dk_paththe directory holding the drumkit data
pLegacyFormatEncounteredwill be set to true is any of the XML elements requires legacy format support and left untouched otherwise.
bSilentif set to true, all log messages except of errors and warnings are suppressed.

Definition at line 153 of file Drumkit.cpp.

◆ load_samples()

void load_samples ( )

Calls the InstrumentList::load_samples() member function of __instruments.

Definition at line 234 of file Drumkit.cpp.

◆ loadDoc()

bool loadDoc ( const QString & sDrumkitDir,
XMLDoc * pDoc,
bool bSilent = false )
staticprivate

Loads the drumkit stored in sDrumkitDir into pDoc and takes care of all the error handling.

Returns
true on success.

Definition at line 265 of file Drumkit.cpp.

◆ loadLicenseFrom()

License loadLicenseFrom ( const QString & sDrumkitDir,
bool bSilent = false )
static

Loads the license information of a drumkit contained in directory sDrumkitDir.

Parameters
sDrumkitDirDirectory containing a drumkit.xml file.

Definition at line 243 of file Drumkit.cpp.

◆ propagateLicense()

void propagateLicense ( )

Assign the license stored in #m_license to all samples contained in the kit.

Definition at line 677 of file Drumkit.cpp.

◆ remove()

bool remove ( const QString & sDrumkitDir)
static

remove a drumkit from the disk

Parameters
sDrumkitDirPath to Drumkit
Returns
true on success

Definition at line 704 of file Drumkit.cpp.

◆ samples_loaded()

const bool samples_loaded ( ) const
inline

return true if the samples are loaded

Definition at line 415 of file Drumkit.h.

◆ save()

bool save ( const QString & sDrumkitPath = "",
int nComponentID = -1,
bool bRecentVersion = true,
bool bSilent = false )

Save a drumkit to disk.

It takes care of writing all parameters etc. into a drumkit.xml file as well as copying both associated samples and images.

Parameters
sDrumkitPaththe path (folder) to save the Drumkit into. If left empty, the path stored in __path will be used instead.
nComponentIDto chose the component to save or -1 for all
bSilentif set to true, all log messages except of errors and warnings are suppressed.
Returns
true on success

Definition at line 343 of file Drumkit.cpp.

◆ save_image()

bool save_image ( const QString & dk_dir,
bool bSilent = false ) const
private

save the drumkit image into the new directory

Parameters
dk_dirthe directory to save the image into
bSilentWhether to suppress info and warning log level messages.
Returns
true on success

Definition at line 521 of file Drumkit.cpp.

◆ save_samples()

bool save_samples ( const QString & dk_dir,
bool bSilent = false ) const
private

save a drumkit instruments samples into a directory

Parameters
dk_dirthe directory to save the samples into
bSilentWhether to suppress info and warning log level messages.
Returns
true on success

Definition at line 478 of file Drumkit.cpp.

◆ save_to()

void save_to ( XMLNode * node,
int component_id = -1,
bool bRecentVersion = true,
bool bSilent = false ) const
private

Definition at line 415 of file Drumkit.cpp.

◆ set_author()

void set_author ( const QString & author)
inline

__author setter

Definition at line 363 of file Drumkit.h.

◆ set_components()

void set_components ( std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > components)

Definition at line 672 of file Drumkit.cpp.

◆ set_image()

void set_image ( const QString & image)
inline

__image setter

Definition at line 395 of file Drumkit.h.

◆ set_image_license()

void set_image_license ( const License & imageLicense)
inline

__imageLicense setter

Definition at line 405 of file Drumkit.h.

◆ set_info()

void set_info ( const QString & info)
inline

__info setter

Definition at line 375 of file Drumkit.h.

◆ set_instruments()

void set_instruments ( std::shared_ptr< InstrumentList > instruments)

set __instruments, delete existing one

Definition at line 667 of file Drumkit.cpp.

◆ set_license()

void set_license ( const License & license)
inline

__license setter

Definition at line 385 of file Drumkit.h.

◆ set_name()

void set_name ( const QString & name)
inline

__name setter

Definition at line 353 of file Drumkit.h.

◆ set_path()

void set_path ( const QString & path)
inline

__path setter

Definition at line 343 of file Drumkit.h.

◆ summarizeContent()

std::vector< std::shared_ptr< InstrumentList::Content > > summarizeContent ( ) const

Returns vector of lists containing instrument name, component name, file name, the license of all associated samples.

Definition at line 700 of file Drumkit.cpp.

◆ toQString()

QString toQString ( const QString & sPrefix = "",
bool bShort = true ) const
overridevirtual

Formatted string version for debugging purposes.

Parameters
sPrefixString prefix which will be added in front of every new line
bShortInstead of the whole content of all classes stored as members just a single unique identifier will be displayed without line breaks.
Returns
String presentation of current object.

Reimplemented from Base.

Definition at line 1391 of file Drumkit.cpp.

◆ unload_samples()

void unload_samples ( )

Calls the InstrumentList::unload_samples() member function of __instruments.

Definition at line 317 of file Drumkit.cpp.

◆ upgrade_drumkit()

void upgrade_drumkit ( std::shared_ptr< Drumkit > pDrumkit,
const QString & dk_path,
bool bSilent = false )
static

Saves the current drumkit to dk_path, but makes a backup.

This is used when the drumkit did not comply to our xml schema.

Definition at line 290 of file Drumkit.cpp.

Field Documentation

◆ __author

QString __author
private

drumkit author

Definition at line 275 of file Drumkit.h.

◆ __components

std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent> > > __components
private

list of drumkit component

Definition at line 283 of file Drumkit.h.

◆ __image

QString __image
private

drumkit image filename

Definition at line 278 of file Drumkit.h.

◆ __imageLicense

License __imageLicense
private

drumkit image license

Definition at line 279 of file Drumkit.h.

◆ __info

QString __info
private

drumkit free text

Definition at line 276 of file Drumkit.h.

◆ __instruments

std::shared_ptr<InstrumentList> __instruments
private

the list of instruments

Definition at line 282 of file Drumkit.h.

◆ __license

License __license
private

drumkit license description

Definition at line 277 of file Drumkit.h.

◆ __name

QString __name
private

drumkit name

Definition at line 274 of file Drumkit.h.

◆ __path

QString __path
private

absolute drumkit path

Definition at line 273 of file Drumkit.h.

◆ __samples_loaded

bool __samples_loaded
private

true if the instrument samples are loaded

Definition at line 281 of file Drumkit.h.