| [3] | 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| [73] | 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| [3] | 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 | |
|---|
| [526] | 26 | #include <cassert> |
|---|
| [3] | 27 | #include <hydrogen/Object.h> |
|---|
| [9] | 28 | #include <hydrogen/adsr.h> |
|---|
| [3] | 29 | |
|---|
| 30 | |
|---|
| [45] | 31 | namespace H2Core |
|---|
| 32 | { |
|---|
| [3] | 33 | |
|---|
| 34 | class ADSR; |
|---|
| 35 | class Instrument; |
|---|
| 36 | |
|---|
| 37 | class NoteKey |
|---|
| 38 | { |
|---|
| [45] | 39 | public: |
|---|
| 40 | enum Key { |
|---|
| [73] | 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, |
|---|
| [45] | 53 | }; |
|---|
| [3] | 54 | |
|---|
| [45] | 55 | Key m_key; |
|---|
| 56 | int m_nOctave; |
|---|
| [3] | 57 | |
|---|
| [73] | 58 | NoteKey() { |
|---|
| [45] | 59 | m_key = C; |
|---|
| 60 | m_nOctave = 0; |
|---|
| 61 | } |
|---|
| [3] | 62 | |
|---|
| [73] | 63 | NoteKey( const NoteKey& key ) { |
|---|
| [45] | 64 | m_key = key.m_key; |
|---|
| 65 | m_nOctave = key.m_nOctave; |
|---|
| 66 | } |
|---|
| [3] | 67 | |
|---|
| 68 | |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| [48] | 72 | /** |
|---|
| [73] | 73 | |
|---|
| [48] | 74 | \brief A note... |
|---|
| [73] | 75 | |
|---|
| [48] | 76 | */ |
|---|
| [3] | 77 | class Note : public Object |
|---|
| 78 | { |
|---|
| [45] | 79 | public: |
|---|
| [53] | 80 | |
|---|
| [466] | 81 | float m_fSamplePosition; ///< Place marker for overlapping process() cycles |
|---|
| [210] | 82 | int m_nHumanizeDelay; ///< Used in "humanize" function |
|---|
| [45] | 83 | NoteKey m_noteKey; |
|---|
| [3] | 84 | |
|---|
| [45] | 85 | ADSR m_adsr; |
|---|
| [3] | 86 | |
|---|
| [45] | 87 | // Low pass resonant filter |
|---|
| 88 | float m_fCutoff; ///< Filter cutoff (0..1) |
|---|
| 89 | float m_fResonance; ///< Filter resonant frequency (0..1) |
|---|
| 90 | float m_fBandPassFilterBuffer_L; ///< Band pass filter buffer |
|---|
| 91 | float m_fBandPassFilterBuffer_R; ///< Band pass filter buffer |
|---|
| 92 | float m_fLowPassFilterBuffer_L; ///< Low pass filter buffer |
|---|
| 93 | float m_fLowPassFilterBuffer_R; ///< Low pass filter buffer |
|---|
| 94 | //~ filter |
|---|
| [3] | 95 | |
|---|
| [45] | 96 | Note( |
|---|
| 97 | Instrument *pInstrument, |
|---|
| 98 | unsigned nPosition, |
|---|
| 99 | float fVelocity, |
|---|
| 100 | float fPan_L, |
|---|
| 101 | float fPan_R, |
|---|
| 102 | int nLength, |
|---|
| 103 | float fPitch, |
|---|
| 104 | NoteKey key = NoteKey() |
|---|
| 105 | ); |
|---|
| [3] | 106 | |
|---|
| [45] | 107 | /// Copy constructor |
|---|
| 108 | Note( const Note* pNote ); |
|---|
| [3] | 109 | |
|---|
| [45] | 110 | ~Note(); |
|---|
| [3] | 111 | |
|---|
| [53] | 112 | Note* copy(); |
|---|
| [3] | 113 | |
|---|
| [53] | 114 | void set_instrument( Instrument* instrument ); |
|---|
| [73] | 115 | Instrument* get_instrument() { |
|---|
| [53] | 116 | return __instrument; |
|---|
| [45] | 117 | } |
|---|
| [3] | 118 | |
|---|
| [45] | 119 | void dumpInfo(); |
|---|
| [127] | 120 | static NoteKey stringToKey( const QString& sKey ); |
|---|
| 121 | static QString keyToString( NoteKey key ); |
|---|
| [3] | 122 | |
|---|
| [53] | 123 | |
|---|
| 124 | /// Return the note position inside a pattern |
|---|
| [73] | 125 | unsigned get_position() const { |
|---|
| [53] | 126 | return __position; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /// Set the note position inside a pattern |
|---|
| [73] | 130 | void set_position( unsigned position ) { |
|---|
| [53] | 131 | __position = position; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /// Return the note velocity |
|---|
| [73] | 135 | float get_velocity() const { |
|---|
| [53] | 136 | return __velocity; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /// Set the note velocity |
|---|
| [73] | 140 | void set_velocity( float velocity ) { |
|---|
| [54] | 141 | if ( velocity > 1.0 ) { |
|---|
| [53] | 142 | velocity = 1.0; |
|---|
| [54] | 143 | } else if ( velocity < 0 ) { |
|---|
| [53] | 144 | velocity = 0; |
|---|
| 145 | } |
|---|
| 146 | __velocity = velocity; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| [73] | 150 | float get_pan_l() const { |
|---|
| [54] | 151 | return __pan_l; |
|---|
| 152 | } |
|---|
| [73] | 153 | void set_pan_l( float pan ) { |
|---|
| [54] | 154 | if ( pan > 0.5 ) { |
|---|
| 155 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 156 | pan = 0.5; |
|---|
| 157 | } |
|---|
| 158 | __pan_l = pan; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| [73] | 161 | float get_pan_r() const { |
|---|
| [54] | 162 | return __pan_r; |
|---|
| 163 | } |
|---|
| [73] | 164 | void set_pan_r( float pan ) { |
|---|
| [54] | 165 | if ( pan > 0.5 ) { |
|---|
| 166 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 167 | pan = 0.5; |
|---|
| 168 | } |
|---|
| 169 | __pan_r = pan; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| [210] | 173 | void set_leadlag( float leadlag ) { |
|---|
| [526] | 174 | if(leadlag > 1.0) { |
|---|
| 175 | __leadlag = 1.0; |
|---|
| 176 | } else if (leadlag < -1.0) { |
|---|
| 177 | __leadlag = -1.0; |
|---|
| 178 | } else { |
|---|
| 179 | __leadlag = leadlag; |
|---|
| 180 | } |
|---|
| [210] | 181 | } |
|---|
| 182 | float get_leadlag() const { |
|---|
| [526] | 183 | assert(__leadlag <= 1.0); |
|---|
| 184 | assert(__leadlag >= -1.0); |
|---|
| [210] | 185 | return __leadlag; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| [73] | 188 | void set_lenght( int lenght ) { |
|---|
| [54] | 189 | __lenght = lenght; |
|---|
| 190 | } |
|---|
| [73] | 191 | int get_lenght() const { |
|---|
| [54] | 192 | return __lenght; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| [73] | 195 | void set_pitch( float pitch ) { |
|---|
| [54] | 196 | __pitch = pitch; |
|---|
| 197 | } |
|---|
| [73] | 198 | float get_pitch() const { |
|---|
| [54] | 199 | return __pitch; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| [45] | 203 | private: |
|---|
| [53] | 204 | Instrument* __instrument; |
|---|
| [54] | 205 | unsigned __position; ///< Note position inside the pattern |
|---|
| [53] | 206 | float __velocity; ///< Velocity (intensity) of the note [0..1] |
|---|
| [54] | 207 | float __pan_l; ///< Pan of the note (left volume) [0..1] |
|---|
| 208 | float __pan_r; ///< Pan of the note (right volume) [0..1] |
|---|
| [210] | 209 | float __leadlag; ///< Lead or lag offset of the note |
|---|
| [54] | 210 | |
|---|
| 211 | int __lenght; |
|---|
| 212 | float __pitch; |
|---|
| 213 | |
|---|
| [3] | 214 | }; |
|---|
| 215 | |
|---|
| 216 | }; |
|---|
| 217 | |
|---|
| 218 | #endif |
|---|