LMMS
Loading...
Searching...
No Matches
Note.h
Go to the documentation of this file.
1/*
2 * Note.h - declaration of class note which contains all information about a
3 * note + definitions of several constants and enums
4 *
5 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26#ifndef LMMS_NOTE_H
27#define LMMS_NOTE_H
28
29#include <memory>
30#include <optional>
31#include <vector>
32
33#include "volume.h"
34#include "panning.h"
35#include "SerializingObject.h"
36#include "TimePos.h"
37
38
39namespace lmms
40{
41
42
43class DetuningHelper;
44class AutomationClip;
45
46
47enum class Key : int
48{
49 C = 0,
50 Cis = 1, Des = 1,
51 D = 2,
52 Dis = 3, Es = 3,
53 E = 4, Fes = 4,
54 F = 5,
55 Fis = 6, Ges = 6,
56 G = 7,
57 Gis = 8, As = 8,
58 A = 9,
59 Ais = 10, B = 10,
60 H = 11
61} ;
62
63
64enum class Octave : int
65{
66 Octave_m1, // MIDI standard starts at C-1
76 Octave_9, // incomplete octave, MIDI only goes up to G9
77};
78
79const int FirstOctave = -1;
80const int KeysPerOctave = 12;
81
82constexpr inline auto operator+(Octave octave, Key key) -> int
83{
84 return static_cast<int>(octave) * KeysPerOctave + static_cast<int>(key);
85}
86
90const int NumKeys = 128;
91
94const float DefaultBaseFreq = 440.f;
95
96const float MaxDetuning = 5 * 12.0f;
97
98
99
100class LMMS_EXPORT Note : public SerializingObject
101{
102public:
103 Note( const TimePos & length = TimePos( 0 ),
104 const TimePos & pos = TimePos( 0 ),
105 int key = DefaultKey,
107 panning_t panning = DefaultPanning,
108 std::shared_ptr<DetuningHelper> detuning = nullptr);
109 Note( const Note & note );
110 ~Note() override;
111
112 Note& operator=(const Note& note);
113
115 Note* clone() const;
116
117 // Note types
118 enum class Type
119 {
120 Regular = 0,
121 Step
122 };
123
124 Type type() const { return m_type; }
125 inline void setType(Type t) { m_type = t; }
126
128 enum class ParameterType
129 {
130 Detuning = 0
131 };
132 AutomationClip* parameterCurve(ParameterType paramType);
133
134 // used by GUI
135 inline void setSelected( const bool selected ) { m_selected = selected; }
136 inline void setOldKey( const int oldKey ) { m_oldKey = oldKey; }
137 inline void setOldPos( const TimePos & oldPos ) { m_oldPos = oldPos; }
138
139 inline void setOldLength( const TimePos & oldLength )
140 {
142 }
143 inline void setIsPlaying( const bool isPlaying )
144 {
146 }
147
148
149 void setLength( const TimePos & length );
150 void setPos( const TimePos & pos );
151 void setKey( const int key );
152 virtual void setVolume( volume_t volume );
153 virtual void setPanning( panning_t panning );
154 void quantizeLength( const int qGrid );
155 void quantizePos( const int qGrid );
156
157 static inline bool lessThan( const Note * lhs, const Note * rhs )
158 {
159 // function to compare two notes - must be called explicitly when
160 // using qSort
161 if( (int)( *lhs ).pos() < (int)( *rhs ).pos() )
162 {
163 return true;
164 }
165 else if( (int)( *lhs ).pos() > (int)( *rhs ).pos() )
166 {
167 return false;
168 }
169 return ( (int)( *lhs ).key() > (int)( *rhs ).key() );
170 }
171
172 inline bool selected() const
173 {
174 return m_selected;
175 }
176
177 inline int oldKey() const
178 {
179 return m_oldKey;
180 }
181
182 inline TimePos oldPos() const
183 {
184 return m_oldPos;
185 }
186
187 inline TimePos oldLength() const
188 {
189 return m_oldLength;
190 }
191
192 inline bool isPlaying() const
193 {
194 return m_isPlaying;
195 }
196
197 inline TimePos endPos() const
198 {
199 const int l = length();
200 return pos() + l;
201 }
202
203 inline const TimePos & length() const
204 {
205 return m_length;
206 }
207
208 inline const TimePos & pos() const
209 {
210 return m_pos;
211 }
212
213 inline TimePos pos( TimePos basePos ) const
214 {
215 const int bp = basePos;
216 return m_pos - bp;
217 }
218
219 inline int key() const
220 {
221 return m_key;
222 }
223
224 inline volume_t getVolume() const
225 {
226 return m_volume;
227 }
228
229 int midiVelocity( int midiBaseVelocity ) const
230 {
231 return std::min(MidiMaxVelocity, getVolume() * midiBaseVelocity / DefaultVolume);
232 }
233
234 inline panning_t getPanning() const
235 {
236 return m_panning;
237 }
238
239 static QString classNodeName()
240 {
241 return "note";
242 }
243
244 inline QString nodeName() const override
245 {
246 return classNodeName();
247 }
248
249 static TimePos quantized( const TimePos & m, const int qGrid );
250
251 const std::shared_ptr<DetuningHelper>& detuning() const { return m_detuning; }
252
253 bool hasDetuningInfo() const;
254 bool withinRange(int tickStart, int tickEnd) const;
255
256 void createDetuning();
257
258
259protected:
260 void saveSettings( QDomDocument & doc, QDomElement & parent ) override;
261 void loadSettings( const QDomElement & _this ) override;
262
263
264private:
265 // for piano roll editing
271
272 int m_key;
277 std::shared_ptr<DetuningHelper> m_detuning;
278
280};
281
282using NoteVector = std::vector<Note*>;
283
291
292
293std::optional<NoteBounds> boundsForNotes(const NoteVector& notes);
294
295
296} // namespace lmms
297
298#endif // LMMS_NOTE_H
Definition AutomationClip.h:52
Definition DetuningHelper.h:35
void setSelected(const bool selected)
Definition Note.h:135
void setIsPlaying(const bool isPlaying)
Definition Note.h:143
panning_t m_panning
Definition Note.h:274
int midiVelocity(int midiBaseVelocity) const
Definition Note.h:229
const std::shared_ptr< DetuningHelper > & detuning() const
Definition Note.h:251
void setOldPos(const TimePos &oldPos)
Definition Note.h:137
volume_t getVolume() const
Definition Note.h:224
TimePos pos(TimePos basePos) const
Definition Note.h:213
const TimePos & pos() const
Definition Note.h:208
TimePos oldLength() const
Definition Note.h:187
int oldKey() const
Definition Note.h:177
int key() const
Definition Note.h:219
Note(const TimePos &length=TimePos(0), const TimePos &pos=TimePos(0), int key=DefaultKey, volume_t volume=DefaultVolume, panning_t panning=DefaultPanning, std::shared_ptr< DetuningHelper > detuning=nullptr)
Definition Note.cpp:37
int m_oldKey
Definition Note.h:267
TimePos m_pos
Definition Note.h:276
const TimePos & length() const
Definition Note.h:203
bool isPlaying() const
Definition Note.h:192
bool m_selected
Definition Note.h:266
void setType(Type t)
Definition Note.h:125
int m_key
Definition Note.h:272
static QString classNodeName()
Definition Note.h:239
std::shared_ptr< DetuningHelper > m_detuning
Definition Note.h:277
TimePos endPos() const
Definition Note.h:197
TimePos m_length
Definition Note.h:275
Type
Definition Note.h:119
@ Regular
Definition Note.h:120
TimePos oldPos() const
Definition Note.h:182
bool selected() const
Definition Note.h:172
TimePos m_oldPos
Definition Note.h:268
Type m_type
Definition Note.h:279
Type type() const
Definition Note.h:124
void setOldKey(const int oldKey)
Definition Note.h:136
Note & operator=(const Note &note)
Definition Note.cpp:78
panning_t getPanning() const
Definition Note.h:234
ParameterType
Types of per-note automation. Currently only detuning/pitch bending is supported.
Definition Note.h:129
volume_t m_volume
Definition Note.h:273
QString nodeName() const override
Definition Note.h:244
static bool lessThan(const Note *lhs, const Note *rhs)
Definition Note.h:157
TimePos m_oldLength
Definition Note.h:269
void setOldLength(const TimePos &oldLength)
Definition Note.h:139
bool m_isPlaying
Definition Note.h:270
SerializingObject()
Definition SerializingObject.cpp:32
Definition TimePos.h:68
int * l
Definition inflate.c:1579
unsigned * m
Definition inflate.c:1559
struct huft * t
Definition inflate.c:943
ParameterType
Definition CarlaBackend.h:763
static uintptr_t parent
Definition pugl.h:1644
CARLA_PLUGIN_EXPORT int clone(int(*)(void *), void *, int, void *,...)
Definition interposer-safe.cpp:46
#define A(x)
Definition lice_arc.cpp:13
Definition AudioAlsa.cpp:35
const int FirstOctave
Definition Note.h:79
const int DefaultMiddleKey
Definition Note.h:92
std::optional< NoteBounds > boundsForNotes(const NoteVector &notes)
Get the start/end/bottom/top positions of notes in a vector.
Definition Note.cpp:274
constexpr volume_t DefaultVolume
Definition volume.h:37
std::vector< Note * > NoteVector
Definition Note.h:282
constexpr panning_t DefaultPanning
Definition panning.h:41
Key
Definition Note.h:48
@ C
Definition Note.h:49
@ Fis
Definition Note.h:55
@ Es
Definition Note.h:52
@ As
Definition Note.h:57
@ E
Definition Note.h:53
@ Ges
Definition Note.h:55
@ Cis
Definition Note.h:50
@ A
Definition Note.h:58
@ F
Definition Note.h:54
@ Gis
Definition Note.h:57
@ Fes
Definition Note.h:53
@ Ais
Definition Note.h:59
@ H
Definition Note.h:60
@ Des
Definition Note.h:50
@ Dis
Definition Note.h:52
const float MaxDetuning
Definition Note.h:96
const int DefaultBaseKey
Definition Note.h:93
const int MidiMaxVelocity
Definition Midi.h:130
Octave
Definition Note.h:65
@ Octave_m1
Definition Note.h:66
@ Octave_5
Definition Note.h:72
@ Octave_6
Definition Note.h:73
@ Octave_0
Definition Note.h:67
@ Octave_1
Definition Note.h:68
@ Octave_3
Definition Note.h:70
@ Octave_2
Definition Note.h:69
@ Octave_9
Definition Note.h:76
@ Octave_8
Definition Note.h:75
@ Octave_4
Definition Note.h:71
@ Octave_7
Definition Note.h:74
constexpr auto DefaultOctave
Definition Note.h:87
const int KeysPerOctave
Definition Note.h:80
std::int8_t panning_t
Definition LmmsTypes.h:37
const int DefaultKey
Definition Note.h:88
constexpr auto operator+(Octave octave, Key key) -> int
Definition Note.h:82
const int NumKeys
Number of physical keys, limited to MIDI range (valid for both MIDI 1.0 and 2.0).
Definition Note.h:90
const float DefaultBaseFreq
Definition Note.h:94
std::uint8_t volume_t
Definition LmmsTypes.h:36
static float volume(float level)
Definition nekobee_voice_render.c:99
png_uint_32 length
Definition png.c:2247
Definition Note.h:285
TimePos start
Definition Note.h:286
TimePos end
Definition Note.h:287
int lowest
Definition Note.h:288
int highest
Definition Note.h:289
static float D(float x)
Definition tap_tubewarmth.c:156
ZCONST char * key
Definition crypt.c:587
Uz_Globs G
Definition globals.c:42