hydrogen 1.2.6
Drumkit.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_DRUMKIT_H
24#define H2C_DRUMKIT_H
25
26#include <memory>
27
28#include <core/Object.h>
30#include <core/License.h>
32
33namespace H2Core
34{
35
36class XMLDoc;
37class XMLNode;
39
44class Drumkit : public H2Core::Object<Drumkit>
45{
47 public:
49 Drumkit();
51 Drumkit( std::shared_ptr<Drumkit> other );
53 ~Drumkit();
54
72 static std::shared_ptr<Drumkit> load( const QString& dk_dir,
73 bool bUpgrade = true,
74 bool* pLegacyFormatEncountered = nullptr,
75 bool bSilent = false );
79 void load_samples();
83 void unload_samples();
84
91 static License loadLicenseFrom( const QString& sDrumkitDir, bool bSilent = false );
92
101 QString getFolderName() const;
111 QString getExportName( const QString& sComponentName, bool bRecentVersion ) const;
112
118 static void upgrade_drumkit( std::shared_ptr<Drumkit> pDrumkit,
119 const QString& dk_path,
120 bool bSilent = false );
121
138 bool save( const QString& sDrumkitPath = "",
139 int nComponentID = -1,
140 bool bRecentVersion = true,
141 bool bSilent = false );
142
164 static bool install( const QString& sSourcePath,
165 const QString& sTargetPath = "",
166 QString* pInstalledPath = nullptr,
167 bool* pEncodingIssuesDetected = nullptr,
168 bool bSilent = false );
169
193 bool exportTo( const QString& sTargetDir, const QString& sComponentName = "",
194 bool bRecentVersion = true, bool* pUtf8Encoded = nullptr,
195 bool bSilent = false );
202 static bool remove( const QString& sDrumkitDir );
203
205 void set_instruments( std::shared_ptr<InstrumentList> instruments );
207 std::shared_ptr<InstrumentList> get_instruments() const;
208
210 void set_path( const QString& path );
212 const QString& get_path() const;
214 void set_name( const QString& name );
216 const QString& get_name() const;
218 void set_author( const QString& author );
220 const QString& get_author() const;
222 void set_info( const QString& info );
224 const QString& get_info() const;
226 void set_license( const License& license );
228 const License& get_license() const;
230 void set_image( const QString& image );
232 const QString& get_image() const;
234 void set_image_license( const License& imageLicense );
236 const License& get_image_license() const;
238 const bool samples_loaded() const;
239
240 std::shared_ptr<DrumkitComponent> getComponent( int nID ) const;
241 int findUnusedComponentId() const;
242
243 void addComponent( std::shared_ptr<DrumkitComponent> pComponent );
246 void addInstrument( std::shared_ptr<Instrument> pInstrument );
247
248 std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> get_components();
249 void set_components( std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> components );
250
255 void propagateLicense();
260 std::vector<std::shared_ptr<InstrumentList::Content>> summarizeContent() const;
261
270 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
271
272 private:
273 QString __path;
274 QString __name;
275 QString __author;
276 QString __info;
278 QString __image;
280
282 std::shared_ptr<InstrumentList> __instruments;
283 std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> __components;
284
292 bool save_image( const QString& dk_dir, bool bSilent = false ) const;
300 bool save_samples( const QString& dk_dir, bool bSilent = false ) const;
301 /*
302 * save the drumkit within the given XMLNode
303 * \param node the XMLNode to feed
304 * \param component_id to chose the component to save or -1 for all
305 * \param bRecentVersion Whether the drumkit format should be
306 * supported by Hydrogen 0.9.7 or higher (whether it should be
307 * composed of DrumkitComponents).
308 */
309 void save_to( XMLNode* node, int component_id=-1, bool bRecentVersion = true, bool bSilent = false ) const;
320 static std::shared_ptr<Drumkit> load_from(
321 XMLNode* node,
322 const QString& dk_path,
323 bool* pLegacyFormatEncountered = nullptr,
324 bool bSilent = false );
325
332 static bool loadDoc( const QString& sDrumkitDir, XMLDoc* pDoc, bool bSilent = false );
333
334};
335
336// DEFINITIONS
337
338inline std::shared_ptr<InstrumentList> Drumkit::get_instruments() const
339{
340 return __instruments;
341}
342
343inline void Drumkit::set_path( const QString& path )
344{
345 __path = path;
346}
347
348inline const QString& Drumkit::get_path() const
349{
350 return __path;
351}
352
353inline void Drumkit::set_name( const QString& name )
354{
355 __name = name;
356}
357
358inline const QString& Drumkit::get_name() const
359{
360 return __name;
361}
362
363inline void Drumkit::set_author( const QString& author )
364{
365 __author = author;
366 __license.setCopyrightHolder( author );
367 __imageLicense.setCopyrightHolder( author );
368}
369
370inline const QString& Drumkit::get_author() const
371{
372 return __author;
373}
374
375inline void Drumkit::set_info( const QString& info )
376{
377 __info = info;
378}
379
380inline const QString& Drumkit::get_info() const
381{
382 return __info;
383}
384
385inline void Drumkit::set_license( const License& license )
386{
387 __license = license;
388}
389
390inline const License& Drumkit::get_license() const
391{
392 return __license;
393}
394
395inline void Drumkit::set_image( const QString& image )
396{
397 __image = image;
398}
399
400inline const QString& Drumkit::get_image() const
401{
402 return __image;
403}
404
405inline void Drumkit::set_image_license( const License& imageLicense )
406{
407 __imageLicense = imageLicense;
408}
409
411{
412 return __imageLicense;
413}
414
415inline const bool Drumkit::samples_loaded() const
416{
417 return __samples_loaded;
418}
419
420inline std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> Drumkit::get_components()
421{
422 return __components;
423}
424
425};
426
427#endif // H2C_DRUMKIT_H
428
429/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:227
QString __name
drumkit name
Definition Drumkit.h:274
int findUnusedComponentId() const
Definition Drumkit.cpp:547
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.
Definition Drumkit.cpp:265
const QString & get_info() const
__info accessor
Definition Drumkit.h:380
void set_image_license(const License &imageLicense)
__imageLicense setter
Definition Drumkit.h:405
std::shared_ptr< InstrumentList > get_instruments() const
returns __instruments
Definition Drumkit.h:338
void set_name(const QString &name)
__name setter
Definition Drumkit.h:353
const License & get_license() const
__license accessor
Definition Drumkit.h:390
const QString & get_name() const
__name accessor
Definition Drumkit.h:358
void save_to(XMLNode *node, int component_id=-1, bool bRecentVersion=true, bool bSilent=false) const
Definition Drumkit.cpp:415
static bool install(const QString &sSourcePath, const QString &sTargetPath="", QString *pInstalledPath=nullptr, bool *pEncodingIssuesDetected=nullptr, bool bSilent=false)
Extract a .h2drumkit file.
Definition Drumkit.cpp:721
bool exportTo(const QString &sTargetDir, const QString &sComponentName="", bool bRecentVersion=true, bool *pUtf8Encoded=nullptr, bool bSilent=false)
Compresses the drumkit into a .h2drumkit file.
Definition Drumkit.cpp:964
bool save_image(const QString &dk_dir, bool bSilent=false) const
save the drumkit image into the new directory
Definition Drumkit.cpp:521
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > __components
list of drumkit component
Definition Drumkit.h:283
const QString & get_image() const
__image accessor
Definition Drumkit.h:400
void propagateLicense()
Assign the license stored in #m_license to all samples contained in the kit.
Definition Drumkit.cpp:677
License __imageLicense
drumkit image license
Definition Drumkit.h:279
~Drumkit()
drumkit destructor, delete __instruments
Definition Drumkit.cpp:90
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.
Definition Drumkit.cpp:290
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > get_components()
Definition Drumkit.h:420
std::shared_ptr< InstrumentList > __instruments
the list of instruments
Definition Drumkit.h:282
QString __info
drumkit free text
Definition Drumkit.h:276
void set_info(const QString &info)
__info setter
Definition Drumkit.h:375
void set_path(const QString &path)
__path setter
Definition Drumkit.h:343
bool save_samples(const QString &dk_dir, bool bSilent=false) const
save a drumkit instruments samples into a directory
Definition Drumkit.cpp:478
void load_samples()
Calls the InstrumentList::load_samples() member function of __instruments.
Definition Drumkit.cpp:234
QString __author
drumkit author
Definition Drumkit.h:275
static bool remove(const QString &sDrumkitDir)
remove a drumkit from the disk
Definition Drumkit.cpp:704
static std::shared_ptr< Drumkit > load(const QString &dk_dir, bool bUpgrade=true, bool *pLegacyFormatEncountered=nullptr, bool bSilent=false)
Load drumkit information from a directory.
Definition Drumkit.cpp:94
const QString & get_author() const
__author accessor
Definition Drumkit.h:370
std::shared_ptr< DrumkitComponent > getComponent(int nID) const
Definition Drumkit.cpp:536
void set_license(const License &license)
__license setter
Definition Drumkit.h:385
std::vector< std::shared_ptr< InstrumentList::Content > > summarizeContent() const
Returns vector of lists containing instrument name, component name, file name, the license of all ass...
Definition Drumkit.cpp:700
QString __image
drumkit image filename
Definition Drumkit.h:278
void addComponent(std::shared_ptr< DrumkitComponent > pComponent)
Definition Drumkit.cpp:567
static std::shared_ptr< Drumkit > load_from(XMLNode *node, const QString &dk_path, bool *pLegacyFormatEncountered=nullptr, bool bSilent=false)
load a drumkit from an XMLNode
Definition Drumkit.cpp:153
static License loadLicenseFrom(const QString &sDrumkitDir, bool bSilent=false)
Loads the license information of a drumkit contained in directory sDrumkitDir.
Definition Drumkit.cpp:243
QString getExportName(const QString &sComponentName, bool bRecentVersion) const
Returns the base name used when exporting the drumkit.
Definition Drumkit.cpp:330
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition Drumkit.cpp:1391
void set_image(const QString &image)
__image setter
Definition Drumkit.h:395
const bool samples_loaded() const
return true if the samples are loaded
Definition Drumkit.h:415
void addInstrument(std::shared_ptr< Instrument > pInstrument)
Adds an instrument and takes care of registering DrumkitComponents missing for contained InstrumentCo...
Definition Drumkit.cpp:589
QString __path
absolute drumkit path
Definition Drumkit.h:273
void unload_samples()
Calls the InstrumentList::unload_samples() member function of __instruments.
Definition Drumkit.cpp:317
const QString & get_path() const
__path accessor
Definition Drumkit.h:348
Drumkit()
drumkit constructor, does nothing
Definition Drumkit.cpp:57
bool __samples_loaded
true if the instrument samples are loaded
Definition Drumkit.h:281
bool save(const QString &sDrumkitPath="", int nComponentID=-1, bool bRecentVersion=true, bool bSilent=false)
Save a drumkit to disk.
Definition Drumkit.cpp:343
QString getFolderName() const
Returns a version of __name stripped of all whitespaces and other characters which would prevent its ...
Definition Drumkit.cpp:326
void set_components(std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > components)
Definition Drumkit.cpp:672
void set_instruments(std::shared_ptr< InstrumentList > instruments)
set __instruments, delete existing one
Definition Drumkit.cpp:667
License __license
drumkit license description
Definition Drumkit.h:277
void set_author(const QString &author)
__author setter
Definition Drumkit.h:363
const License & get_image_license() const
__imageLicense accessor
Definition Drumkit.h:410
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
XMLDoc is a subclass of QDomDocument with read and write methods.
Definition Xml.h:182
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39