hydrogen 1.2.3
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-2024 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;
38class DrumkitComponent;
39
44class Drumkit : public H2Core::Object<Drumkit>
45{
47 public:
49 Drumkit();
51 Drumkit( std::shared_ptr<Drumkit> other );
53 ~Drumkit();
54
69 static std::shared_ptr<Drumkit> load( const QString& dk_dir,
70 bool bUpgrade = true,
71 bool bSilent = false );
75 void load_samples();
79 void unload_samples();
80
87 static License loadLicenseFrom( const QString& sDrumkitDir, bool bSilent = false );
88
97 QString getFolderName() const;
107 QString getExportName( const QString& sComponentName, bool bRecentVersion ) const;
108
114 static void upgrade_drumkit( std::shared_ptr<Drumkit> pDrumkit,
115 const QString& dk_path,
116 bool bSilent = false );
117
134 bool save( const QString& sDrumkitPath = "",
135 int nComponentID = -1,
136 bool bRecentVersion = true,
137 bool bSilent = false );
138
151 static bool install( const QString& sSourcePath, const QString& sTargetPath = "", bool bSilent = false );
152
174 bool exportTo( const QString& sTargetDir, const QString& sComponentName = "", bool bRecentVersion = true, bool bSilent = false );
181 static bool remove( const QString& sDrumkitDir );
182
184 void set_instruments( std::shared_ptr<InstrumentList> instruments );
186 std::shared_ptr<InstrumentList> get_instruments() const;
187
189 void set_path( const QString& path );
191 const QString& get_path() const;
193 void set_name( const QString& name );
195 const QString& get_name() const;
197 void set_author( const QString& author );
199 const QString& get_author() const;
201 void set_info( const QString& info );
203 const QString& get_info() const;
205 void set_license( const License& license );
207 const License& get_license() const;
209 void set_image( const QString& image );
211 const QString& get_image() const;
213 void set_image_license( const License& imageLicense );
215 const License& get_image_license() const;
217 const bool samples_loaded() const;
218
219 std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> get_components();
220 void set_components( std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> components );
221
226 void propagateLicense();
231 std::vector<std::shared_ptr<InstrumentList::Content>> summarizeContent() const;
232
241 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
242
243 private:
244 QString __path;
245 QString __name;
246 QString __author;
247 QString __info;
249 QString __image;
251
253 std::shared_ptr<InstrumentList> __instruments;
254 std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> __components;
255
263 bool save_image( const QString& dk_dir, bool bSilent = false ) const;
271 bool save_samples( const QString& dk_dir, bool bSilent = false ) const;
272 /*
273 * save the drumkit within the given XMLNode
274 * \param node the XMLNode to feed
275 * \param component_id to chose the component to save or -1 for all
276 * \param bRecentVersion Whether the drumkit format should be
277 * supported by Hydrogen 0.9.7 or higher (whether it should be
278 * composed of DrumkitComponents).
279 */
280 void save_to( XMLNode* node, int component_id=-1, bool bRecentVersion = true, bool bSilent = false ) const;
288 static std::shared_ptr<Drumkit> load_from( XMLNode* node,
289 const QString& dk_path,
290 bool bSilent = false );
291
298 static bool loadDoc( const QString& sDrumkitDir, XMLDoc* pDoc, bool bSilent = false );
299
300};
301
302// DEFINITIONS
303
304inline std::shared_ptr<InstrumentList> Drumkit::get_instruments() const
305{
306 return __instruments;
307}
308
309inline void Drumkit::set_path( const QString& path )
310{
311 __path = path;
312}
313
314inline const QString& Drumkit::get_path() const
315{
316 return __path;
317}
318
319inline void Drumkit::set_name( const QString& name )
320{
321 __name = name;
322}
323
324inline const QString& Drumkit::get_name() const
325{
326 return __name;
327}
328
329inline void Drumkit::set_author( const QString& author )
330{
331 __author = author;
334}
335
336inline const QString& Drumkit::get_author() const
337{
338 return __author;
339}
340
341inline void Drumkit::set_info( const QString& info )
342{
343 __info = info;
344}
345
346inline const QString& Drumkit::get_info() const
347{
348 return __info;
349}
350
351inline void Drumkit::set_license( const License& license )
352{
353 __license = license;
354}
355
356inline const License& Drumkit::get_license() const
357{
358 return __license;
359}
360
361inline void Drumkit::set_image( const QString& image )
362{
363 __image = image;
364}
365
366inline const QString& Drumkit::get_image() const
367{
368 return __image;
369}
370
371inline void Drumkit::set_image_license( const License& imageLicense )
372{
373 __imageLicense = imageLicense;
374}
375
377{
378 return __imageLicense;
379}
380
381inline const bool Drumkit::samples_loaded() const
382{
383 return __samples_loaded;
384}
385
386inline std::shared_ptr<std::vector<std::shared_ptr<DrumkitComponent>>> Drumkit::get_components()
387{
388 return __components;
389}
390
391};
392
393#endif // H2C_DRUMKIT_H
394
395/* vim: set softtabstop=4 noexpandtab: */
#define H2_OBJECT(name)
Definition Object.h:224
Drumkit info.
Definition Drumkit.h:45
QString __name
drumkit name
Definition Drumkit.h:245
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:235
const QString & get_info() const
__info accessor
Definition Drumkit.h:346
void set_image_license(const License &imageLicense)
__imageLicense setter
Definition Drumkit.h:371
std::shared_ptr< InstrumentList > get_instruments() const
returns __instruments
Definition Drumkit.h:304
void set_name(const QString &name)
__name setter
Definition Drumkit.h:319
const License & get_license() const
__license accessor
Definition Drumkit.h:356
const QString & get_name() const
__name accessor
Definition Drumkit.h:324
void save_to(XMLNode *node, int component_id=-1, bool bRecentVersion=true, bool bSilent=false) const
Definition Drumkit.cpp:392
static std::shared_ptr< Drumkit > load_from(XMLNode *node, const QString &dk_path, bool bSilent=false)
load a drumkit from an XMLNode
Definition Drumkit.cpp:134
bool save_image(const QString &dk_dir, bool bSilent=false) const
save the drumkit image into the new directory
Definition Drumkit.cpp:496
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > __components
list of drumkit component
Definition Drumkit.h:254
const QString & get_image() const
__image accessor
Definition Drumkit.h:366
void propagateLicense()
Assign the license stored in #m_license to all samples contained in the kit.
Definition Drumkit.cpp:521
License __imageLicense
drumkit image license
Definition Drumkit.h:250
~Drumkit()
drumkit destructor, delete __instruments
Definition Drumkit.cpp:86
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:267
std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > get_components()
Definition Drumkit.h:386
std::shared_ptr< InstrumentList > __instruments
the list of instruments
Definition Drumkit.h:253
QString __info
drumkit free text
Definition Drumkit.h:247
void set_info(const QString &info)
__info setter
Definition Drumkit.h:341
void set_path(const QString &path)
__path setter
Definition Drumkit.h:309
bool save_samples(const QString &dk_dir, bool bSilent=false) const
save a drumkit instruments samples into a directory
Definition Drumkit.cpp:455
void load_samples()
Calls the InstrumentList::load_samples() member function of __instruments.
Definition Drumkit.cpp:204
QString __author
drumkit author
Definition Drumkit.h:246
static bool remove(const QString &sDrumkitDir)
remove a drumkit from the disk
Definition Drumkit.cpp:548
const QString & get_author() const
__author accessor
Definition Drumkit.h:336
void set_license(const License &license)
__license setter
Definition Drumkit.h:351
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:544
QString __image
drumkit image filename
Definition Drumkit.h:249
static std::shared_ptr< Drumkit > load(const QString &dk_dir, bool bUpgrade=true, bool bSilent=false)
Load drumkit information from a directory.
Definition Drumkit.cpp:90
static License loadLicenseFrom(const QString &sDrumkitDir, bool bSilent=false)
Loads the license information of a drumkit contained in directory sDrumkitDir.
Definition Drumkit.cpp:213
QString getExportName(const QString &sComponentName, bool bRecentVersion) const
Returns the base name used when exporting the drumkit.
Definition Drumkit.cpp:307
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
Definition Drumkit.cpp:1042
void set_image(const QString &image)
__image setter
Definition Drumkit.h:361
const bool samples_loaded() const
return true if the samples are loaded
Definition Drumkit.h:381
QString __path
absolute drumkit path
Definition Drumkit.h:244
bool exportTo(const QString &sTargetDir, const QString &sComponentName="", bool bRecentVersion=true, bool bSilent=false)
Compresses the drumkit into a .h2drumkit file.
Definition Drumkit.cpp:718
void unload_samples()
Calls the InstrumentList::unload_samples() member function of __instruments.
Definition Drumkit.cpp:294
static bool install(const QString &sSourcePath, const QString &sTargetPath="", bool bSilent=false)
Extract a .h2drumkit file.
Definition Drumkit.cpp:565
const QString & get_path() const
__path accessor
Definition Drumkit.h:314
Drumkit()
drumkit constructor, does nothing
Definition Drumkit.cpp:53
bool __samples_loaded
true if the instrument samples are loaded
Definition Drumkit.h:252
bool save(const QString &sDrumkitPath="", int nComponentID=-1, bool bRecentVersion=true, bool bSilent=false)
Save a drumkit to disk.
Definition Drumkit.cpp:320
QString getFolderName() const
Returns a version of __name stripped of all whitespaces and other characters which would prevent its ...
Definition Drumkit.cpp:303
void set_components(std::shared_ptr< std::vector< std::shared_ptr< DrumkitComponent > > > components)
Definition Drumkit.cpp:516
void set_instruments(std::shared_ptr< InstrumentList > instruments)
set __instruments, delete existing one
Definition Drumkit.cpp:511
License __license
drumkit license description
Definition Drumkit.h:248
void set_author(const QString &author)
__author setter
Definition Drumkit.h:329
const License & get_image_license() const
__imageLicense accessor
Definition Drumkit.h:376
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
void setCopyrightHolder(const QString &sCopyrightHolder)
Definition License.h:152
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