hydrogen 1.2.3
InstrumentComponent.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_INSTRUMENTCOMPONENT_H
24#define H2C_INSTRUMENTCOMPONENT_H
25
26#include <cassert>
27#include <vector>
28#include <memory>
29
30#include <core/Object.h>
31#include <core/License.h>
32
33namespace H2Core
34{
35
36class XMLNode;
37class ADSR;
38class Drumkit;
39class InstrumentLayer;
40class DrumkitComponent;
41
43class InstrumentComponent : public H2Core::Object<InstrumentComponent>
44{
46 public:
47 InstrumentComponent( int related_drumkit_componentID );
48 InstrumentComponent( std::shared_ptr<InstrumentComponent> other );
50
51 void save_to( XMLNode* node, int component_id, bool bRecentVersion = true, bool bFull = false );
52 static std::shared_ptr<InstrumentComponent> load_from( XMLNode* pNode,
53 const QString& sDrumkitPath,
54 const License& drumkitLicense = License(),
55 bool bSilent = false );
56
57 std::shared_ptr<InstrumentLayer> operator[]( int ix );
58 std::shared_ptr<InstrumentLayer> get_layer( int idx );
59 void set_layer( std::shared_ptr<InstrumentLayer> layer, int idx );
60
61 void set_drumkit_componentID( int related_drumkit_componentID );
63
64 void set_gain( float gain );
65 float get_gain() const;
66
68 static int getMaxLayers();
70 static void setMaxLayers( int layers );
71
73 std::vector<std::shared_ptr<InstrumentLayer>>::iterator begin();
74 std::vector<std::shared_ptr<InstrumentLayer>>::iterator end();
75
84 QString toQString( const QString& sPrefix = "", bool bShort = true ) const override;
85
86 private:
91 float __gain;
92
100 static int m_nMaxLayers;
101 std::vector<std::shared_ptr<InstrumentLayer>> __layers;
102};
103
104// DEFINITIONS
107inline void InstrumentComponent::set_drumkit_componentID( int related_drumkit_componentID )
108{
109 __related_drumkit_componentID = related_drumkit_componentID;
110}
117
118inline void InstrumentComponent::set_gain( float gain )
119{
120 __gain = gain;
121}
122
124{
125 return __gain;
126}
127
128inline std::shared_ptr<InstrumentLayer> InstrumentComponent::operator[]( int idx )
129{
130 assert( idx >= 0 && idx < m_nMaxLayers );
131 return __layers[ idx ];
132}
133
134inline std::shared_ptr<InstrumentLayer> InstrumentComponent::get_layer( int idx )
135{
136 assert( idx >= 0 && idx < m_nMaxLayers );
137 return __layers[ idx ];
138}
139
140};
141
142
143#endif
#define H2_OBJECT(name)
Definition Object.h:224
static std::shared_ptr< InstrumentComponent > load_from(XMLNode *pNode, const QString &sDrumkitPath, const License &drumkitLicense=License(), bool bSilent=false)
std::vector< std::shared_ptr< InstrumentLayer > > __layers
std::vector< std::shared_ptr< InstrumentLayer > >::iterator begin()
Iteration.
int get_drumkit_componentID()
Returns the component ID of the drumkit.
static int m_nMaxLayers
Maximum number of layers to be used in the Instrument editor.
InstrumentComponent(int related_drumkit_componentID)
static void setMaxLayers(int layers)
int __related_drumkit_componentID
Component ID of the drumkit.
std::vector< std::shared_ptr< InstrumentLayer > >::iterator end()
std::shared_ptr< InstrumentLayer > operator[](int ix)
void set_layer(std::shared_ptr< InstrumentLayer > layer, int idx)
QString toQString(const QString &sPrefix="", bool bShort=true) const override
Formatted string version for debugging purposes.
std::shared_ptr< InstrumentLayer > get_layer(int idx)
void save_to(XMLNode *node, int component_id, bool bRecentVersion=true, bool bFull=false)
void set_drumkit_componentID(int related_drumkit_componentID)
Sets the component ID __related_drumkit_componentID.
Wrapper class to help Hydrogen deal with the license information specified in a drumkit.
Definition License.h:48
XMLNode is a subclass of QDomNode with read and write values methods.
Definition Xml.h:39