| 1 | |
|---|
| 2 | /* |
|---|
| 3 | * Hydrogen |
|---|
| 4 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.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, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | * |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #ifndef INSTRUMENT_H |
|---|
| 25 | #define INSTRUMENT_H |
|---|
| 26 | |
|---|
| 27 | #include <QtCore/QString> |
|---|
| 28 | #include <hydrogen/globals.h> |
|---|
| 29 | #include <hydrogen/Object.h> |
|---|
| 30 | #include <cassert> |
|---|
| 31 | |
|---|
| 32 | namespace H2Core |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | class ADSR; |
|---|
| 36 | class Sample; |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | |
|---|
| 40 | \brief A layer... |
|---|
| 41 | |
|---|
| 42 | */ |
|---|
| 43 | class InstrumentLayer : public Object |
|---|
| 44 | { |
|---|
| 45 | public: |
|---|
| 46 | InstrumentLayer( Sample *sample ); |
|---|
| 47 | ~InstrumentLayer(); |
|---|
| 48 | |
|---|
| 49 | void set_start_velocity( float vel ) { |
|---|
| 50 | __start_velocity = vel; |
|---|
| 51 | } |
|---|
| 52 | float get_start_velocity() { |
|---|
| 53 | return __start_velocity; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | void set_end_velocity( float vel ) { |
|---|
| 57 | __end_velocity = vel; |
|---|
| 58 | } |
|---|
| 59 | float get_end_velocity() { |
|---|
| 60 | return __end_velocity; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | void set_pitch( float pitch ) { |
|---|
| 64 | __pitch = pitch; |
|---|
| 65 | } |
|---|
| 66 | float get_pitch() { |
|---|
| 67 | return __pitch; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void set_gain( float gain ) { |
|---|
| 71 | __gain = gain; |
|---|
| 72 | } |
|---|
| 73 | float get_gain() { |
|---|
| 74 | return __gain; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | void set_sample( Sample* sample ) { |
|---|
| 78 | __sample = sample; |
|---|
| 79 | } |
|---|
| 80 | Sample* get_sample() { |
|---|
| 81 | return __sample; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | private: |
|---|
| 85 | float __start_velocity; ///< Start velocity |
|---|
| 86 | float __end_velocity; ///< End velocity |
|---|
| 87 | float __pitch; |
|---|
| 88 | float __gain; |
|---|
| 89 | Sample *__sample; |
|---|
| 90 | }; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | |
|---|
| 96 | \brief Instrument class |
|---|
| 97 | |
|---|
| 98 | */ |
|---|
| 99 | class Instrument : public Object |
|---|
| 100 | { |
|---|
| 101 | public: |
|---|
| 102 | Instrument( |
|---|
| 103 | const QString& id, |
|---|
| 104 | const QString& name, |
|---|
| 105 | ADSR* adsr |
|---|
| 106 | ); |
|---|
| 107 | |
|---|
| 108 | /// create a new object without anything in it. |
|---|
| 109 | static Instrument * create_empty(); |
|---|
| 110 | ~Instrument(); |
|---|
| 111 | |
|---|
| 112 | /// creates a new object; loads samples from drumkit/instrument. |
|---|
| 113 | static Instrument* load_instrument( |
|---|
| 114 | const QString& drumkit_name, |
|---|
| 115 | const QString& instrument_name |
|---|
| 116 | ); |
|---|
| 117 | |
|---|
| 118 | /// loads state _and_ samples into an Instrument from a `placeholder` instrument |
|---|
| 119 | /// (i.e. an Instrument that has everything but the actal samples.) |
|---|
| 120 | void load_from_placeholder( Instrument* placeholder, bool is_live = true ); |
|---|
| 121 | |
|---|
| 122 | /// loads instrument from path into a `live` Instrument object. |
|---|
| 123 | void load_from_name( |
|---|
| 124 | const QString& drumkit_name, |
|---|
| 125 | const QString& instrument_name, |
|---|
| 126 | bool is_live = true |
|---|
| 127 | ); |
|---|
| 128 | |
|---|
| 129 | /// Returns a layer in the list |
|---|
| 130 | /// See below for definition. |
|---|
| 131 | inline InstrumentLayer* get_layer( int index ); |
|---|
| 132 | |
|---|
| 133 | /// Sets a layer in the list |
|---|
| 134 | void set_layer( InstrumentLayer* layer, unsigned index ); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | void set_name( const QString& name ) { |
|---|
| 138 | __name = name; |
|---|
| 139 | } |
|---|
| 140 | const QString& get_name() { |
|---|
| 141 | return __name; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | void set_id( const QString& id ) { |
|---|
| 145 | __id = id; |
|---|
| 146 | } |
|---|
| 147 | inline const QString& get_id() { |
|---|
| 148 | return __id; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | void set_adsr( ADSR* adsr ); |
|---|
| 152 | ADSR* get_adsr() { |
|---|
| 153 | return __adsr; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | void set_mute_group( int group ) { |
|---|
| 157 | __mute_group = group; |
|---|
| 158 | } |
|---|
| 159 | inline int get_mute_group() { |
|---|
| 160 | return __mute_group; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | void set_muted( bool muted ) { |
|---|
| 164 | __muted = muted; |
|---|
| 165 | } |
|---|
| 166 | inline bool is_muted() { |
|---|
| 167 | return __muted; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | inline float get_pan_l() { |
|---|
| 171 | return __pan_l; |
|---|
| 172 | } |
|---|
| 173 | void set_pan_l( float val ) { |
|---|
| 174 | __pan_l = val; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | inline float get_pan_r() { |
|---|
| 178 | return __pan_r; |
|---|
| 179 | } |
|---|
| 180 | void set_pan_r( float val ) { |
|---|
| 181 | __pan_r = val; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | inline float get_gain() { |
|---|
| 185 | return __gain; |
|---|
| 186 | } |
|---|
| 187 | void set_gain( float gain ) { |
|---|
| 188 | __gain = gain; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | inline float get_volume() { |
|---|
| 192 | return __volume; |
|---|
| 193 | } |
|---|
| 194 | void set_volume( float volume ) { |
|---|
| 195 | __volume = volume; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | inline bool is_filter_active() { |
|---|
| 199 | return __filter_active; |
|---|
| 200 | } |
|---|
| 201 | void set_filter_active( bool active ) { |
|---|
| 202 | __filter_active = active; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | inline float get_filter_resonance() { |
|---|
| 206 | return __filter_resonance; |
|---|
| 207 | } |
|---|
| 208 | void set_filter_resonance( float val ) { |
|---|
| 209 | __filter_resonance = val; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | inline float get_filter_cutoff() { |
|---|
| 213 | return __filter_cutoff; |
|---|
| 214 | } |
|---|
| 215 | void set_filter_cutoff( float val ) { |
|---|
| 216 | __filter_cutoff = val; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | inline float get_peak_l() { |
|---|
| 220 | return __peak_l; |
|---|
| 221 | } |
|---|
| 222 | void set_peak_l( float val ) { |
|---|
| 223 | __peak_l = val; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | inline float get_peak_r() { |
|---|
| 227 | return __peak_r; |
|---|
| 228 | } |
|---|
| 229 | void set_peak_r( float val ) { |
|---|
| 230 | __peak_r = val; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | inline float get_fx_level( int index ) { |
|---|
| 234 | return __fx_level[index]; |
|---|
| 235 | } |
|---|
| 236 | void set_fx_level( float level, int index ) { |
|---|
| 237 | __fx_level[index] = level; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | inline float get_random_pitch_factor() { |
|---|
| 241 | return __random_pitch_factor; |
|---|
| 242 | } |
|---|
| 243 | void set_random_pitch_factor( float val ) { |
|---|
| 244 | __random_pitch_factor = val; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | void set_drumkit_name( const QString& name ) { |
|---|
| 248 | __drumkit_name = name; |
|---|
| 249 | } |
|---|
| 250 | const QString& get_drumkit_name() { |
|---|
| 251 | return __drumkit_name; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | inline bool is_active() { |
|---|
| 255 | return __active; |
|---|
| 256 | } |
|---|
| 257 | void set_active( bool active ) { |
|---|
| 258 | __active = active; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | inline bool is_soloed() { |
|---|
| 262 | return __soloed; |
|---|
| 263 | } |
|---|
| 264 | void set_soloed( bool soloed ) { |
|---|
| 265 | __soloed = soloed; |
|---|
| 266 | } |
|---|
| 267 | inline void enqueue() { |
|---|
| 268 | __queued++; |
|---|
| 269 | } |
|---|
| 270 | inline void dequeue() { |
|---|
| 271 | assert( __queued > 0 ); |
|---|
| 272 | __queued--; |
|---|
| 273 | } |
|---|
| 274 | inline int is_queued() { |
|---|
| 275 | return __queued; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | inline bool is_stop_notes() { |
|---|
| 279 | return __stop_notes; |
|---|
| 280 | } |
|---|
| 281 | void set_stop_note( bool stopnotes ) { |
|---|
| 282 | __stop_notes = stopnotes; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | private: |
|---|
| 288 | int __queued; |
|---|
| 289 | InstrumentLayer* __layer_list[MAX_LAYERS]; |
|---|
| 290 | ADSR* __adsr; |
|---|
| 291 | bool __muted; |
|---|
| 292 | QString __name; ///< Instrument name |
|---|
| 293 | float __pan_l; ///< Pan of the instrument (left) |
|---|
| 294 | float __pan_r; ///< Pan of the instrument (right) |
|---|
| 295 | float __gain; |
|---|
| 296 | float __volume; ///< Volume of the instrument |
|---|
| 297 | float __filter_resonance; ///< Filter resonant frequency (0..1) |
|---|
| 298 | float __filter_cutoff; ///< Filter cutoff (0..1) |
|---|
| 299 | float __peak_l; ///< current peak value (left) |
|---|
| 300 | float __peak_r; ///< current peak value (right) |
|---|
| 301 | float __fx_level[MAX_FX]; ///< Ladspa FX level |
|---|
| 302 | float __random_pitch_factor; |
|---|
| 303 | QString __id; ///< ID of the instrument |
|---|
| 304 | QString __drumkit_name; ///< Drumkit name |
|---|
| 305 | bool __filter_active; ///< Is filter active? |
|---|
| 306 | int __mute_group; ///< Mute group |
|---|
| 307 | |
|---|
| 308 | bool __active; ///< is the instrument active? |
|---|
| 309 | bool __soloed; |
|---|
| 310 | bool __stop_notes; /// |
|---|
| 311 | }; |
|---|
| 312 | |
|---|
| 313 | inline InstrumentLayer* Instrument::get_layer( int nLayer ) |
|---|
| 314 | { |
|---|
| 315 | if ( nLayer < 0 ) { |
|---|
| 316 | ERRORLOG( QString( "nLayer < 0 (nLayer=%1)" ).arg( nLayer ) ); |
|---|
| 317 | return NULL; |
|---|
| 318 | } |
|---|
| 319 | if ( nLayer >= MAX_LAYERS ) { |
|---|
| 320 | ERRORLOG( QString( "nLayer > MAX_LAYERS (nLayer=%1)" ).arg( nLayer ) ); |
|---|
| 321 | return NULL; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | return __layer_list[ nLayer ]; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | /** |
|---|
| 329 | |
|---|
| 330 | \brief Instrument List |
|---|
| 331 | |
|---|
| 332 | */ |
|---|
| 333 | class InstrumentList : public Object |
|---|
| 334 | { |
|---|
| 335 | public: |
|---|
| 336 | InstrumentList(); |
|---|
| 337 | ~InstrumentList(); |
|---|
| 338 | |
|---|
| 339 | void add( Instrument* pInstrument ); |
|---|
| 340 | Instrument* get( unsigned int pos ); |
|---|
| 341 | int get_pos( Instrument* inst ); |
|---|
| 342 | unsigned get_size(); |
|---|
| 343 | |
|---|
| 344 | void del( int pos ); |
|---|
| 345 | |
|---|
| 346 | void replace( Instrument* pNewInstr, unsigned nPos ); |
|---|
| 347 | |
|---|
| 348 | private: |
|---|
| 349 | std::vector<Instrument*> m_list; |
|---|
| 350 | std::map<Instrument*, unsigned> m_posmap; |
|---|
| 351 | }; |
|---|
| 352 | |
|---|
| 353 | }; |
|---|
| 354 | |
|---|
| 355 | #endif |
|---|
| 356 | |
|---|
| 357 | |
|---|