| 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 H2_NOTE_H |
|---|
| 24 | #define H2_NOTE_H |
|---|
| 25 | |
|---|
| 26 | #include <cassert> |
|---|
| 27 | #include <hydrogen/Object.h> |
|---|
| 28 | #include <hydrogen/adsr.h> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | namespace H2Core |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | class ADSR; |
|---|
| 35 | class Instrument; |
|---|
| 36 | |
|---|
| 37 | class NoteKey |
|---|
| 38 | { |
|---|
| 39 | public: |
|---|
| 40 | enum Key { |
|---|
| 41 | C = 0, |
|---|
| 42 | Cs, |
|---|
| 43 | D, |
|---|
| 44 | Ef, |
|---|
| 45 | E, |
|---|
| 46 | F, |
|---|
| 47 | Fs, |
|---|
| 48 | G, |
|---|
| 49 | Af, |
|---|
| 50 | A, |
|---|
| 51 | Bf, |
|---|
| 52 | B, |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | Key m_key; |
|---|
| 56 | int m_nOctave; |
|---|
| 57 | |
|---|
| 58 | NoteKey() { |
|---|
| 59 | m_key = C; |
|---|
| 60 | m_nOctave = 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | NoteKey( const NoteKey& key ) { |
|---|
| 64 | m_key = key.m_key; |
|---|
| 65 | m_nOctave = key.m_nOctave; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | |
|---|
| 74 | \brief A note... |
|---|
| 75 | |
|---|
| 76 | */ |
|---|
| 77 | class Note : public Object |
|---|
| 78 | { |
|---|
| 79 | public: |
|---|
| 80 | |
|---|
| 81 | // These are used exclusively by the Sampler |
|---|
| 82 | uint32_t m_nSilenceOffset; ///< Used when scheduling note start in process() cycle |
|---|
| 83 | uint32_t m_nReleaseOffset; ///< Used when scheduling not lengths. |
|---|
| 84 | float m_fSamplePosition; ///< Place marker for overlapping process() cycles |
|---|
| 85 | unsigned m_uInstrumentIndex; /// For tracking outputs |
|---|
| 86 | NoteKey m_noteKey; |
|---|
| 87 | ADSR m_adsr; |
|---|
| 88 | // Low pass resonant filter |
|---|
| 89 | float m_fCutoff; ///< Filter cutoff (0..1) |
|---|
| 90 | float m_fResonance; ///< Filter resonant frequency (0..1) |
|---|
| 91 | float m_fBandPassFilterBuffer_L; ///< Band pass filter buffer |
|---|
| 92 | float m_fBandPassFilterBuffer_R; ///< Band pass filter buffer |
|---|
| 93 | float m_fLowPassFilterBuffer_L; ///< Low pass filter buffer |
|---|
| 94 | float m_fLowPassFilterBuffer_R; ///< Low pass filter buffer |
|---|
| 95 | //~ filter |
|---|
| 96 | |
|---|
| 97 | // This is used exclusively by the Sequencer (Hydrogen) |
|---|
| 98 | int m_nHumanizeDelay; ///< Used in "humanize" function |
|---|
| 99 | |
|---|
| 100 | #warning "TODO: Check these defaults" |
|---|
| 101 | Note( |
|---|
| 102 | Instrument *pInstrument = 0, |
|---|
| 103 | float fVelocity = 1.0, |
|---|
| 104 | float fPan_L = 0.5, |
|---|
| 105 | float fPan_R = 0.5, |
|---|
| 106 | int nLength = 0, // Length is in *ticks* |
|---|
| 107 | float fPitch = 1.0, |
|---|
| 108 | NoteKey key = NoteKey() |
|---|
| 109 | ); |
|---|
| 110 | |
|---|
| 111 | /// Copy constructor |
|---|
| 112 | Note( const Note* pNote ); |
|---|
| 113 | |
|---|
| 114 | ~Note(); |
|---|
| 115 | |
|---|
| 116 | Note* copy(); |
|---|
| 117 | |
|---|
| 118 | void set_instrument( Instrument* instrument ); |
|---|
| 119 | Instrument* get_instrument() const { |
|---|
| 120 | return __instrument; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | void dumpInfo() const; |
|---|
| 124 | static NoteKey stringToKey( const QString& sKey ); |
|---|
| 125 | static QString keyToString( NoteKey key ); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | /// Return the note velocity |
|---|
| 129 | float get_velocity() const { |
|---|
| 130 | return __velocity; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | /// Set the note velocity |
|---|
| 134 | void set_velocity( float velocity ) { |
|---|
| 135 | if ( velocity > 1.0 ) { |
|---|
| 136 | velocity = 1.0; |
|---|
| 137 | } else if ( velocity < 0 ) { |
|---|
| 138 | velocity = 0; |
|---|
| 139 | } |
|---|
| 140 | __velocity = velocity; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | float get_pan_l() const { |
|---|
| 145 | return __pan_l; |
|---|
| 146 | } |
|---|
| 147 | void set_pan_l( float pan ) { |
|---|
| 148 | if ( pan > 0.5 ) { |
|---|
| 149 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 150 | pan = 0.5; |
|---|
| 151 | } |
|---|
| 152 | __pan_l = pan; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | float get_pan_r() const { |
|---|
| 156 | return __pan_r; |
|---|
| 157 | } |
|---|
| 158 | void set_pan_r( float pan ) { |
|---|
| 159 | if ( pan > 0.5 ) { |
|---|
| 160 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 161 | pan = 0.5; |
|---|
| 162 | } |
|---|
| 163 | __pan_r = pan; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | void set_leadlag( float leadlag ) { |
|---|
| 168 | if(leadlag > 1.0) { |
|---|
| 169 | __leadlag = 1.0; |
|---|
| 170 | } else if (leadlag < -1.0) { |
|---|
| 171 | __leadlag = -1.0; |
|---|
| 172 | } else { |
|---|
| 173 | __leadlag = leadlag; |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | float get_leadlag() const { |
|---|
| 177 | assert(__leadlag <= 1.0); |
|---|
| 178 | assert(__leadlag >= -1.0); |
|---|
| 179 | return __leadlag; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | void set_length( int length ) { |
|---|
| 183 | __length = length; |
|---|
| 184 | } |
|---|
| 185 | int get_length() const { |
|---|
| 186 | return __length; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | void set_pitch( float pitch ) { |
|---|
| 190 | __pitch = pitch; |
|---|
| 191 | } |
|---|
| 192 | float get_pitch() const { |
|---|
| 193 | return __pitch; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | private: |
|---|
| 198 | Instrument* __instrument; |
|---|
| 199 | float __velocity; ///< Velocity (intensity) of the note [0..1] |
|---|
| 200 | float __pan_l; ///< Pan of the note (left volume) [0..1] |
|---|
| 201 | float __pan_r; ///< Pan of the note (right volume) [0..1] |
|---|
| 202 | float __leadlag; ///< Lead or lag offset of the note |
|---|
| 203 | |
|---|
| 204 | int __length; ///< Length in ticks. Used by the sequencer (Hydrogen) |
|---|
| 205 | float __pitch; |
|---|
| 206 | }; // class Note |
|---|
| 207 | |
|---|
| 208 | } // namespace H2Core |
|---|
| 209 | |
|---|
| 210 | #endif |
|---|