| 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 | |
|---|
| 29 | |
|---|
| 30 | namespace H2Core |
|---|
| 31 | { |
|---|
| 32 | |
|---|
| 33 | class Instrument; |
|---|
| 34 | |
|---|
| 35 | class NoteKey |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | enum Key { |
|---|
| 39 | C = 0, |
|---|
| 40 | Cs, |
|---|
| 41 | D, |
|---|
| 42 | Ef, |
|---|
| 43 | E, |
|---|
| 44 | F, |
|---|
| 45 | Fs, |
|---|
| 46 | G, |
|---|
| 47 | Af, |
|---|
| 48 | A, |
|---|
| 49 | Bf, |
|---|
| 50 | B, |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | Key m_key; |
|---|
| 54 | int m_nOctave; |
|---|
| 55 | |
|---|
| 56 | NoteKey() { |
|---|
| 57 | m_key = C; |
|---|
| 58 | m_nOctave = 0; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | NoteKey( const NoteKey& key ) { |
|---|
| 62 | m_key = key.m_key; |
|---|
| 63 | m_nOctave = key.m_nOctave; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | |
|---|
| 72 | \brief A note... |
|---|
| 73 | |
|---|
| 74 | */ |
|---|
| 75 | class Note : public Object |
|---|
| 76 | { |
|---|
| 77 | public: |
|---|
| 78 | |
|---|
| 79 | int m_nHumanizeDelay; ///< Used in "humanize" function |
|---|
| 80 | NoteKey m_noteKey; |
|---|
| 81 | |
|---|
| 82 | Note( |
|---|
| 83 | Instrument *pInstrument, |
|---|
| 84 | float fVelocity, |
|---|
| 85 | float fPan_L, |
|---|
| 86 | float fPan_R, |
|---|
| 87 | int nLength, |
|---|
| 88 | float fPitch, |
|---|
| 89 | NoteKey key = NoteKey() |
|---|
| 90 | ); |
|---|
| 91 | |
|---|
| 92 | /// Copy constructor |
|---|
| 93 | Note( const Note* pNote ); |
|---|
| 94 | |
|---|
| 95 | ~Note(); |
|---|
| 96 | |
|---|
| 97 | Note* copy(); |
|---|
| 98 | |
|---|
| 99 | void set_instrument( Instrument* instrument ); |
|---|
| 100 | Instrument* get_instrument() { |
|---|
| 101 | return __instrument; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void dumpInfo(); |
|---|
| 105 | static NoteKey stringToKey( const QString& sKey ); |
|---|
| 106 | static QString keyToString( NoteKey key ); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | /// Return the note velocity |
|---|
| 110 | float get_velocity() const { |
|---|
| 111 | return __velocity; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /// Set the note velocity |
|---|
| 115 | void set_velocity( float velocity ) { |
|---|
| 116 | if ( velocity > 1.0 ) { |
|---|
| 117 | velocity = 1.0; |
|---|
| 118 | } else if ( velocity < 0 ) { |
|---|
| 119 | velocity = 0; |
|---|
| 120 | } |
|---|
| 121 | __velocity = velocity; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | float get_pan_l() const { |
|---|
| 126 | return __pan_l; |
|---|
| 127 | } |
|---|
| 128 | void set_pan_l( float pan ) { |
|---|
| 129 | if ( pan > 0.5 ) { |
|---|
| 130 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 131 | pan = 0.5; |
|---|
| 132 | } |
|---|
| 133 | __pan_l = pan; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | float get_pan_r() const { |
|---|
| 137 | return __pan_r; |
|---|
| 138 | } |
|---|
| 139 | void set_pan_r( float pan ) { |
|---|
| 140 | if ( pan > 0.5 ) { |
|---|
| 141 | INFOLOG( "Pan R > 0.5" ); |
|---|
| 142 | pan = 0.5; |
|---|
| 143 | } |
|---|
| 144 | __pan_r = pan; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | void set_leadlag( float leadlag ) { |
|---|
| 149 | if(leadlag > 1.0) { |
|---|
| 150 | __leadlag = 1.0; |
|---|
| 151 | } else if (leadlag < -1.0) { |
|---|
| 152 | __leadlag = -1.0; |
|---|
| 153 | } else { |
|---|
| 154 | __leadlag = leadlag; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | float get_leadlag() const { |
|---|
| 158 | assert(__leadlag <= 1.0); |
|---|
| 159 | assert(__leadlag >= -1.0); |
|---|
| 160 | return __leadlag; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | void set_length( int length ) { |
|---|
| 164 | __length = length; |
|---|
| 165 | } |
|---|
| 166 | int get_length() const { |
|---|
| 167 | return __length; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | void set_pitch( float pitch ) { |
|---|
| 171 | __pitch = pitch; |
|---|
| 172 | } |
|---|
| 173 | float get_pitch() const { |
|---|
| 174 | return __pitch; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | private: |
|---|
| 179 | Instrument* __instrument; |
|---|
| 180 | float __velocity; ///< Velocity (intensity) of the note [0..1] |
|---|
| 181 | float __pan_l; ///< Pan of the note (left volume) [0..1] |
|---|
| 182 | float __pan_r; ///< Pan of the note (right volume) [0..1] |
|---|
| 183 | float __leadlag; ///< Lead or lag offset of the note |
|---|
| 184 | |
|---|
| 185 | int __length; |
|---|
| 186 | float __pitch; |
|---|
| 187 | }; |
|---|
| 188 | |
|---|
| 189 | }; |
|---|
| 190 | |
|---|
| 191 | #endif |
|---|