root/branches/transport_redesign/libs/hydrogen/include/hydrogen/note.h @ 871

Revision 871, 3.2 KB (checked in by gabriel@…, 4 years ago)

Remove extra info from H2Core::Note (including get_position(), ADSR, and filter params)

Note had a lot of information in it that probably didn't belong there.
A note should simply be pitch, velocity, duration. However, this
implementation has the Note loaded down with it's pattern position
(which is redundant -- the pattern tracks the notes position), ADSR
parameters (this should be managed by the sampler/synth... not on a
per-note basis), and parameters for a low pass resonant filter (again,
this belongs in the sample/synth). Pan L/R was left in because the
pattern editor supports them.

Some of these parameters could be used to make a really complex type
of sampler/synth... but they're not currently supported by any
editors, song files, or sampler... and they bog down H2Core::Note,
which should be as lightweight as possible.

Line 
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
30namespace H2Core
31{
32
33class Instrument;
34
35class NoteKey
36{
37public:
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*/
75class Note : public Object
76{
77public:
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
178private:
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
Note: See TracBrowser for help on using the browser.