2 * note_play_handle.h - declaration of class notePlayHandle which is needed
5 * Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
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.
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.
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.
27 #ifndef _NOTE_PLAY_HANDLE_H
28 #define _NOTE_PLAY_HANDLE_H
30 #include "lmmsconfig.h"
37 class InstrumentTrack
;
40 template<ch_cnt_t
=DEFAULT_CHANNELS
> class basicFilters
;
41 typedef QList
<notePlayHandle
*> NotePlayHandleList
;
42 typedef QList
<const notePlayHandle
*> ConstNotePlayHandleList
;
45 class EXPORT notePlayHandle
: public playHandle
, public note
49 basicFilters
<> * m_filter
;
51 notePlayHandle( InstrumentTrack
* _instrument_track
,
52 const f_cnt_t _offset
,
53 const f_cnt_t _frames
, const note
& _n
,
54 notePlayHandle
* _parent
= NULL
,
55 const bool _part_of_arp
= false );
56 virtual ~notePlayHandle();
58 virtual void setVolume( const volume_t _volume
= DefaultVolume
);
60 int midiVelocity() const;
63 const float & frequency() const
68 void updateFrequency();
70 // returns frequency without pitch-wheel influence
71 float unpitchedFrequency() const
73 return m_unpitchedFrequency
;
76 virtual void play( sampleFrame
* _working_buffer
);
78 virtual inline bool done() const
80 return m_released
&& framesLeft() <= 0;
83 f_cnt_t
framesLeft() const;
85 inline fpp_t
framesLeftForCurrentPeriod() const
87 return (fpp_t
) qMin
<f_cnt_t
>( framesLeft(),
88 engine::getMixer()->framesPerPeriod() );
92 virtual bool isFromTrack( const track
* _track
) const;
95 void noteOff( const f_cnt_t _s
= 0 );
97 inline f_cnt_t
framesBeforeRelease() const
99 return m_framesBeforeRelease
;
102 inline f_cnt_t
releaseFramesDone() const
104 return m_releaseFramesDone
;
107 f_cnt_t
actualReleaseFramesToDo() const;
110 // returns total numbers of frames to play
111 inline f_cnt_t
frames() const
116 void setFrames( const f_cnt_t _frames
);
118 // returns whether note was released
119 inline bool released() const
124 // returns total numbers of played frames
125 inline f_cnt_t
totalFramesPlayed() const
127 return m_totalFramesPlayed
;
130 // returns volume-level at frame _frame (envelope/LFO)
131 float volumeLevel( const f_cnt_t _frame
);
133 // returns instrument-track this note-play-handle plays
134 const InstrumentTrack
*instrumentTrack() const
136 return m_instrumentTrack
;
139 InstrumentTrack
*instrumentTrack()
141 return m_instrumentTrack
;
144 // returns whether note is a top note, e.g. is not part of an arpeggio
146 inline bool isTopNote() const
151 inline bool isPartOfArpeggio() const
153 return m_partOfArpeggio
;
156 inline void setPartOfArpeggio( const bool _on
)
158 m_partOfArpeggio
= _on
;
161 // returns whether note is base-note for arpeggio
162 bool isArpeggioBaseNote() const;
164 inline bool isMuted() const
171 // returns index of note-play-handle in vector of note-play-handles
172 // belonging to this instrument-track - used by arpeggiator
175 // note-play-handles belonging to given channel, if _all_ph = true,
176 // also released note-play-handles are returned
177 static ConstNotePlayHandleList
nphsOfInstrumentTrack(
178 const InstrumentTrack
* _ct
, bool _all_ph
= false );
180 // return whether given note-play-handle is equal to *this
181 bool operator==( const notePlayHandle
& _nph
) const;
183 inline bool bbTrackMuted()
185 return m_bbTrack
&& m_bbTrack
->isMuted();
187 void setBBTrack( track
* _bb_track
)
189 m_bbTrack
= _bb_track
;
192 void processMidiTime( const midiTime
& _time
);
193 void resize( const bpm_t _new_tempo
);
195 #ifdef LMMS_SINGERBOT_SUPPORT
198 return m_patternIndex
;
201 void setPatternIndex( int _i
)
212 BaseDetuning( DetuningHelper
*detuning
);
214 void setValue( float val
)
226 DetuningHelper
* m_detuning
;
231 InstrumentTrack
* m_instrumentTrack
; // needed for calling
232 // InstrumentTrack::playNote
233 f_cnt_t m_frames
; // total frames to play
234 f_cnt_t m_totalFramesPlayed
; // total frame-counter - used for
235 // figuring out whether a whole note
237 f_cnt_t m_framesBeforeRelease
; // number of frames after which note
239 f_cnt_t m_releaseFramesToDo
; // total numbers of frames to be
240 // played after release
241 f_cnt_t m_releaseFramesDone
; // number of frames done after
243 NotePlayHandleList m_subNotes
; // used for chords and arpeggios
244 volatile bool m_released
; // indicates whether note is released
245 bool m_topNote
; // indicates whether note is a
246 // base-note (i.e. no sub-note)
247 bool m_partOfArpeggio
; // indicates whether note is part of
248 // an arpeggio (either base-note or
250 bool m_muted
; // indicates whether note is muted
251 track
* m_bbTrack
; // related BB track
252 #ifdef LMMS_SINGERBOT_SUPPORT
253 int m_patternIndex
; // position among relevant notes
257 bpm_t m_origTempo
; // original tempo
258 f_cnt_t m_origFrames
; // original m_frames
263 float m_unpitchedFrequency
;
265 BaseDetuning
* m_baseDetuning
;