LMMS
Loading...
Searching...
No Matches
NotePlayHandle.h
Go to the documentation of this file.
1/*
2 * NotePlayHandle.h - declaration of class NotePlayHandle which manages
3 * playback of a single note by an instrument
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_PLAY_HANDLE_H
27#define LMMS_NOTE_PLAY_HANDLE_H
28
29#include <memory>
30
31#include "BasicFilters.h"
32#include "Note.h"
33#include "PlayHandle.h"
34#include "Track.h"
35
36class QReadWriteLock;
37
38namespace lmms
39{
40
41class InstrumentTrack;
42class NotePlayHandle;
43
44using NotePlayHandleList = QList<NotePlayHandle*>;
45using ConstNotePlayHandleList = QList<const NotePlayHandle*>;
46
47class LMMS_EXPORT NotePlayHandle : public PlayHandle, public Note
48{
49public:
51 std::unique_ptr<BasicFilters<>> m_filter;
52
53 // length of the declicking fade in
55
56 // specifies origin of NotePlayHandle
57 enum class Origin
58 {
60 MidiInput,
61 NoteStacking,
62 Arpeggio,
63 };
64
65 NotePlayHandle( InstrumentTrack* instrumentTrack,
66 const f_cnt_t offset,
67 const f_cnt_t frames,
68 const Note& noteToPlay,
69 NotePlayHandle* parent = nullptr,
70 int midiEventChannel = -1,
71 Origin origin = Origin::MidiClip );
72 ~NotePlayHandle() override;
73
74 void * operator new ( size_t size, void * p )
75 {
76 return p;
77 }
78
79 void setVolume( volume_t volume ) override;
80 void setPanning( panning_t panning ) override;
81
82 int midiKey() const;
83 int midiChannel() const
84 {
85 return m_midiChannel;
86 }
87
92 {
93 return m_totalFramesPlayed == 0
94 ? offset()
95 : 0;
96 }
97
98 const float& frequency() const
99 {
100 return m_frequency;
101 }
102
104 float unpitchedFrequency() const
105 {
107 }
108
110 float currentDetuning() const { return m_baseDetuning->value(); }
111
113 void play( SampleFrame* buffer ) override;
114
116 bool isFinished() const override
117 {
118 return m_released && framesLeft() <= 0;
119 }
120
122 f_cnt_t framesLeft() const;
123
125 f_cnt_t framesLeftForCurrentPeriod() const;
126
128 bool isFromTrack( const Track* _track ) const override;
129
131 void noteOff( const f_cnt_t offset = 0 );
132
135 {
137 }
138
141 {
142 return m_releaseFramesDone;
143 }
144
147 f_cnt_t actualReleaseFramesToDo() const;
148
151 {
152 return m_frames;
153 }
154
156 void setFrames( const f_cnt_t _frames );
157
159 bool isReleased() const
160 {
161 return m_released;
162 }
163
164 bool isReleaseStarted() const
165 {
166 return m_releaseStarted;
167 }
168
171 {
172 return m_totalFramesPlayed;
173 }
174
176 float volumeLevel( const f_cnt_t frame );
177
180 {
181 return m_instrumentTrack;
182 }
183
189
191 bool hasParent() const
192 {
193 return m_hasParent;
194 }
195
198 {
199 return m_origin;
200 }
201
203 bool isMasterNote() const
204 {
205 return m_subNotes.size() > 0 || m_hadChildren;
206 }
207
209 {
210 m_hadChildren = true;
211 setUsesBuffer( false );
212 }
213
215 bool isMuted() const
216 {
217 return m_muted;
218 }
219
221 void mute();
222
226 int index() const;
227
231 static ConstNotePlayHandleList nphsOfInstrumentTrack( const InstrumentTrack* Track, bool allPlayHandles = false );
232
234 bool operator==( const NotePlayHandle & _nph ) const;
235
238 {
239 return m_patternTrack && m_patternTrack->isMuted();
240 }
241
244 {
246 }
247
249 void processTimePos(const TimePos& time, float pitchValue, bool isRecording);
250
252 void resize( const bpm_t newTempo );
253
259
262 {
264 }
265
267 {
269 }
270
271private:
273 {
274 public:
276
277 void setValue( float val )
278 {
279 m_value = val;
280 }
281
282 float value() const
283 {
284 return m_value;
285 }
286
287
288 private:
289 float m_value;
290
291 } ;
292
293 void updateFrequency();
294
295 InstrumentTrack* m_instrumentTrack; // needed for calling
296 // InstrumentTrack::playNote
297 f_cnt_t m_frames; // total frames to play
298 f_cnt_t m_totalFramesPlayed; // total frame-counter - used for
299 // figuring out whether a whole note
300 // has been played
301 f_cnt_t m_framesBeforeRelease; // number of frames after which note
302 // is released
303 f_cnt_t m_releaseFramesToDo; // total numbers of frames to be
304 // played after release
305 f_cnt_t m_releaseFramesDone; // number of frames done after
306 // release of note
307 NotePlayHandleList m_subNotes; // used for chords and arpeggios
308 volatile bool m_released; // indicates whether note is released
311 bool m_hasParent; // indicates whether note has parent
312 NotePlayHandle * m_parent; // parent note
314 bool m_muted; // indicates whether note is muted
315 Track* m_patternTrack; // related pattern track
316
317 // tempo reaction
318 bpm_t m_origTempo; // original tempo
319 f_cnt_t m_origFrames; // original m_frames
320
322
325
328
331
332 bool m_frequencyNeedsUpdate; // used to update pitch
333} ;
334
335
336const int INITIAL_NPH_CACHE = 256;
337const int NPH_CACHE_INCREMENT = 16;
338
340{
341public:
342 static void init();
343 static NotePlayHandle * acquire( InstrumentTrack* instrumentTrack,
344 const f_cnt_t offset,
345 const f_cnt_t frames,
346 const Note& noteToPlay,
347 NotePlayHandle* parent = nullptr,
348 int midiEventChannel = -1,
350 static void release( NotePlayHandle * nph );
351 static void extend( int i );
352 static void free();
353
354private:
356 static QReadWriteLock s_mutex;
357 static std::atomic_int s_availableIndex;
358 static int s_size;
359};
360
361
362} // namespace lmms
363
364#endif // LMMS_NOTE_PLAY_HANDLE_H
Definition DetuningHelper.h:35
Definition InstrumentTrack.h:62
Definition MidiClip.h:46
Definition Note.h:101
const std::shared_ptr< DetuningHelper > & detuning() const
Definition Note.h:251
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
Definition NotePlayHandle.h:273
void setValue(float val)
Definition NotePlayHandle.h:277
BaseDetuning(DetuningHelper *detuning)
Definition NotePlayHandle.cpp:39
float value() const
Definition NotePlayHandle.h:282
float m_value
Definition NotePlayHandle.h:289
Definition NotePlayHandle.h:48
const TimePos & songGlobalParentOffset() const
Definition NotePlayHandle.h:261
bool isPatternTrackMuted()
Definition NotePlayHandle.h:237
bool isReleaseStarted() const
Definition NotePlayHandle.h:164
float m_unpitchedFrequency
Definition NotePlayHandle.h:324
const float & frequency() const
Definition NotePlayHandle.h:98
BaseDetuning * m_baseDetuning
Definition NotePlayHandle.h:326
InstrumentTrack * instrumentTrack()
Definition NotePlayHandle.h:185
const InstrumentTrack * instrumentTrack() const
Definition NotePlayHandle.h:179
InstrumentTrack * m_instrumentTrack
Definition NotePlayHandle.h:295
Origin origin() const
Definition NotePlayHandle.h:197
bool m_hasMidiNote
Definition NotePlayHandle.h:310
int midiChannel() const
Definition NotePlayHandle.h:83
f_cnt_t m_framesBeforeRelease
Definition NotePlayHandle.h:301
std::unique_ptr< BasicFilters<> > m_filter
Definition NotePlayHandle.h:51
f_cnt_t releaseFramesDone() const
Definition NotePlayHandle.h:140
void setFrequencyUpdate()
Definition NotePlayHandle.h:266
f_cnt_t totalFramesPlayed() const
Definition NotePlayHandle.h:170
bool m_muted
Definition NotePlayHandle.h:314
float unpitchedFrequency() const
Definition NotePlayHandle.h:104
void setPatternTrack(Track *t)
Definition NotePlayHandle.h:243
bool m_hadChildren
Definition NotePlayHandle.h:313
NotePlayHandle(InstrumentTrack *instrumentTrack, const f_cnt_t offset, const f_cnt_t frames, const Note &noteToPlay, NotePlayHandle *parent=nullptr, int midiEventChannel=-1, Origin origin=Origin::MidiClip)
Definition NotePlayHandle.cpp:49
NotePlayHandle * m_parent
Definition NotePlayHandle.h:312
bool m_releaseStarted
Definition NotePlayHandle.h:309
int m_midiChannel
Definition NotePlayHandle.h:329
bool isMuted() const
Definition NotePlayHandle.h:215
TimePos m_songGlobalParentOffset
Definition NotePlayHandle.h:327
f_cnt_t m_fadeInLength
Definition NotePlayHandle.h:54
bool isMasterNote() const
Definition NotePlayHandle.h:203
bpm_t m_origTempo
Definition NotePlayHandle.h:318
void * m_pluginData
Definition NotePlayHandle.h:50
NotePlayHandleList m_subNotes
Definition NotePlayHandle.h:307
f_cnt_t m_releaseFramesDone
Definition NotePlayHandle.h:305
f_cnt_t framesLeft() const
Definition NotePlayHandle.cpp:329
float m_frequency
Definition NotePlayHandle.h:323
void setMasterNote()
Definition NotePlayHandle.h:208
f_cnt_t noteOffset() const
Definition NotePlayHandle.h:91
void setSongGlobalParentOffset(const TimePos &offset)
Definition NotePlayHandle.h:255
bool m_hasParent
Definition NotePlayHandle.h:311
bool isFinished() const override
Definition NotePlayHandle.h:116
bool hasParent() const
Definition NotePlayHandle.h:191
volatile bool m_released
Definition NotePlayHandle.h:308
f_cnt_t frames() const
Definition NotePlayHandle.h:150
f_cnt_t m_totalFramesPlayed
Definition NotePlayHandle.h:298
Track * m_patternTrack
Definition NotePlayHandle.h:315
f_cnt_t m_releaseFramesToDo
Definition NotePlayHandle.h:303
float currentDetuning() const
Get the current per-note detuning for this note.
Definition NotePlayHandle.h:110
f_cnt_t m_origFrames
Definition NotePlayHandle.h:319
bool m_frequencyNeedsUpdate
Definition NotePlayHandle.h:332
bool isReleased() const
Definition NotePlayHandle.h:159
Origin
Definition NotePlayHandle.h:58
@ MidiClip
Definition NotePlayHandle.h:59
void updateFrequency()
Definition NotePlayHandle.cpp:520
f_cnt_t m_frames
Definition NotePlayHandle.h:297
f_cnt_t framesBeforeRelease() const
Definition NotePlayHandle.h:134
int m_origBaseNote
Definition NotePlayHandle.h:321
Origin m_origin
Definition NotePlayHandle.h:330
Definition NotePlayHandle.h:340
static int s_size
Definition NotePlayHandle.h:358
static std::atomic_int s_availableIndex
Definition NotePlayHandle.h:357
static NotePlayHandle * acquire(InstrumentTrack *instrumentTrack, const f_cnt_t offset, const f_cnt_t frames, const Note &noteToPlay, NotePlayHandle *parent=nullptr, int midiEventChannel=-1, NotePlayHandle::Origin origin=NotePlayHandle::Origin::MidiClip)
Definition NotePlayHandle.cpp:627
static void release(NotePlayHandle *nph)
Definition NotePlayHandle.cpp:646
static QReadWriteLock s_mutex
Definition NotePlayHandle.h:356
static void extend(int i)
Definition NotePlayHandle.cpp:655
static void free()
Definition NotePlayHandle.cpp:671
static NotePlayHandle ** s_available
Definition NotePlayHandle.h:355
static void init()
Definition NotePlayHandle.cpp:611
PlayHandle(const Type type, f_cnt_t offset=0)
Definition PlayHandle.cpp:36
void setUsesBuffer(const bool b)
Definition PlayHandle.h:132
f_cnt_t offset() const
Definition PlayHandle.h:114
Definition SampleFrame.h:41
Definition TimePos.h:68
Base-class for all tracks.
Definition Track.h:68
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
static uintptr_t parent
Definition pugl.h:1644
int val
Definition jpeglib.h:956
Definition AudioAlsa.cpp:35
QList< const NotePlayHandle * > ConstNotePlayHandleList
Definition NotePlayHandle.h:45
const int NPH_CACHE_INCREMENT
Definition NotePlayHandle.h:337
const int INITIAL_NPH_CACHE
Definition NotePlayHandle.h:336
std::int8_t panning_t
Definition LmmsTypes.h:37
QList< NotePlayHandle * > NotePlayHandleList
Definition NotePlayHandle.h:44
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
bool operator==(const ProjectVersion &v1, const ProjectVersion &v2)
Definition ProjectVersion.h:78
std::uint16_t bpm_t
Definition LmmsTypes.h:45
std::uint8_t volume_t
Definition LmmsTypes.h:36
static float volume(float level)
Definition nekobee_voice_render.c:99
uch * p
Definition crypt.c:594
ulg size
Definition extract.c:2350