1 /*
2  * Hydrogen
3  * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4  *
5  * http://www.hydrogen-music.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY, without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 #ifndef H2C_INSTRUMENT_LAYER_H
24 #define H2C_INSTRUMENT_LAYER_H
25 
26 #include <hydrogen/object.h>
27 
28 namespace H2Core
29 {
30 
31 	class XMLNode;
32 	class Sample;
33 
34 	/**
35 	 * InstrumentLayer is part of an instrument
36 	 * <br>each layer has it's own :
37 	 * <br><b>gain</b> which is the ration between the input sample and the output signal,
38 	 * <br><b>pitch</b> which allows you to play the sample at a faster or lower frequency,
39 	 * <br><b>start velocity</b> and <b>end velocity</b> which allows you to chose between a layer or another within an instrument
40 	 * by changing the velocity of the played note. so the only layer of an instrument should start at 0.0 and end at 1.0.
41 	 */
42 	class InstrumentLayer : public H2Core::Object
43 	{
44 		H2_OBJECT
45 		public:
46 		/** constructor
47 		 * \param sample the sample to use
48 		 * */
49 		InstrumentLayer( Sample* sample );
50 		/** copy constructor, will be initialized with an empty sample
51 		 * \param other the instrument layer to copy from
52 		 */
53 		InstrumentLayer( InstrumentLayer* other );
54 		/** copy constructor
55 		 * \param other the instrument layer to copy from
56 		 * \param sample the sample to use
57 		 */
58 		InstrumentLayer( InstrumentLayer* other, Sample* sample );
59 		/** destructor */
60 		~InstrumentLayer();
61 
62 		/** set the gain of the layer */
63 		void set_gain( float gain );
64 		/** get the gain of the layer */
65 		float get_gain() const;
66 		/** set the pitch of the layer */
67 		void set_pitch( float pitch );
68 		/** get the pitch of the layer */
69 		float get_pitch() const;
70 
71 		/** set the start ivelocity of the layer */
72 		void set_start_velocity( float start );
73 		/** get the start velocity of the layer */
74 		float get_start_velocity() const;
75 		/** set the end velocity of the layer */
76 		void set_end_velocity( float end );
77 		/** get the end velocity of the layer */
78 		float get_end_velocity() const;
79 		/** set the sample of the layer */
80 		void set_sample( Sample* sample );
81 		/** get the sample of the layer */
82 		Sample* get_sample() const;
83 
84 		/**
85 		 * Calls the #H2Core::Sample::load()
86 		 * member function of #__sample.
87 		 */
88 		void load_sample();
89 		/*
90 		 * unload sample and replace it with an empty one
91 		 */
92 		void unload_sample();
93 
94 		/**
95 		 * save the instrument layer within the given XMLNode
96 		 * \param node the XMLNode to feed
97 		 */
98 		void save_to( XMLNode* node );
99 		/**
100 		 * load an instrument layer from an XMLNode
101 		 * \param node the XMLDode to read from
102 		 * \param dk_path the directory holding the drumkit data
103 		 * \return a new InstrumentLayer instance
104 		 */
105 		static InstrumentLayer* load_from( XMLNode* node, const QString& dk_path );
106 
107 	private:
108 		float __gain;               ///< ratio between the input sample and the output signal, 1.0 by default
109 		float __pitch;              ///< the frequency of the sample, 0.0 by default which means output pitch is the same as input pitch
110 		float __start_velocity;     ///< the start velocity of the sample, 0.0 by default
111 		float __end_velocity;       ///< the end velocity of the sample, 1.0 by default
112 		Sample* __sample;           ///< the underlaying sample
113 	};
114 
115 	// DEFINITIONS
116 
set_gain(float gain)117 	inline void InstrumentLayer::set_gain( float gain )
118 	{
119 		__gain = gain;
120 	}
121 
get_gain()122 	inline float InstrumentLayer::get_gain() const
123 	{
124 		return __gain;
125 	}
126 
set_pitch(float pitch)127 	inline void InstrumentLayer::set_pitch( float pitch )
128 	{
129 		__pitch = pitch;
130 	}
131 
get_pitch()132 	inline float InstrumentLayer::get_pitch() const
133 	{
134 		return __pitch;
135 	}
136 
set_start_velocity(float start)137 	inline void InstrumentLayer::set_start_velocity( float start )
138 	{
139 		__start_velocity = start;
140 	}
141 
get_start_velocity()142 	inline float InstrumentLayer::get_start_velocity() const
143 	{
144 		return __start_velocity;
145 	}
146 
set_end_velocity(float end)147 	inline void InstrumentLayer::set_end_velocity( float end )
148 	{
149 		__end_velocity = end;
150 	}
151 
get_end_velocity()152 	inline float InstrumentLayer::get_end_velocity() const
153 	{
154 		return __end_velocity;
155 	}
156 
get_sample()157 	inline Sample* InstrumentLayer::get_sample() const
158 	{
159 		return __sample;
160 	}
161 
162 };
163 
164 #endif // H2C_INSTRUMENT_LAYER_H
165 
166 /* vim: set softtabstop=4 noexpandtab: */
167