LMMS
Loading...
Searching...
No Matches
InstrumentTrack.h
Go to the documentation of this file.
1/*
2 * InstrumentTrack.h - declaration of class InstrumentTrack, a track which
3 * holds an instrument-plugin
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_INSTRUMENT_TRACK_H
27#define LMMS_INSTRUMENT_TRACK_H
28
29
30#include "AudioBusHandle.h"
31#include "InstrumentFunctions.h"
33#include "Microtuner.h"
34#include "Midi.h"
35#include "MidiEventProcessor.h"
36#include "MidiPort.h"
37#include "NotePlayHandle.h"
38#include "Piano.h"
39#include "Plugin.h"
40#include "Track.h"
41
42
43namespace lmms
44{
45
46
47class Instrument;
48class DataFile;
49
50namespace gui
51{
52
56class MidiCCRackView;
57
58} // namespace gui
59
60
61class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
62{
63 Q_OBJECT
64 mapPropertyFromModel(int,getVolume,setVolume,m_volumeModel);
65public:
67 ~InstrumentTrack() override;
68
69 // used by instrument
70 void processAudioBuffer( SampleFrame* _buf, const f_cnt_t _frames,
71 NotePlayHandle * _n );
72
73 MidiEvent applyMasterKey( const MidiEvent& event );
74
75 void processInEvent( const MidiEvent& event, const TimePos& time = TimePos(), f_cnt_t offset = 0 ) override;
76 void processOutEvent( const MidiEvent& event, const TimePos& time = TimePos(), f_cnt_t offset = 0 ) override;
77 // silence all running notes played by this track
78 void silenceAllNotes( bool removeIPH = false );
79
81 {
83 }
84
85 f_cnt_t beatLen( NotePlayHandle * _n ) const;
86
87
88 // for capturing note-play-events -> need that for arpeggio,
89 // filter and so on
90 void playNote( NotePlayHandle * _n, SampleFrame* _working_buffer );
91
92 QString instrumentName() const;
93 const Instrument *instrument() const
94 {
95 return m_instrument;
96 }
97
99 {
100 return m_instrument;
101 }
102
103 void deleteNotePluginData( NotePlayHandle * _n );
104
105 // name-stuff
106 void setName( const QString & _new_name ) override;
107
108 // translate given key of a note-event to absolute key (i.e.
109 // add global master-pitch and base-note of this instrument track)
110 int masterKey( int _midi_key ) const;
111
112 // translate pitch to midi-pitch [0,16383]
113 int midiPitch() const
114 {
115 return static_cast<int>( ( ( m_pitchModel.value() + m_pitchModel.range()/2 ) * MidiMaxPitchBend ) / m_pitchModel.range() );
116 }
117
119 int midiPitchRange() const
120 {
121 return m_pitchRangeModel.value();
122 }
123
124 // play everything in given frame-range - creates note-play-handles
125 bool play( const TimePos & _start, const f_cnt_t _frames,
126 const f_cnt_t _frame_base, int _clip_num = -1 ) override;
127 // create new view for me
128 gui::TrackView* createView( gui::TrackContainerView* tcv ) override;
129
130 // create new track-content-object = clip
131 Clip* createClip(const TimePos & pos) override;
132
133
134 // called by track
135 void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) override;
136 void loadTrackSpecificSettings( const QDomElement & _this ) override;
137
139
140
141 // load instrument whose name matches given one
142 Instrument * loadInstrument(const QString & _instrument_name,
144 bool keyFromDnd = false);
145
147 {
148 return &m_audioBusHandle;
149 }
150
152 {
153 return &m_midiPort;
154 }
155
156 const IntModel *baseNoteModel() const
157 {
158 return &m_baseNoteModel;
159 }
160
162 {
163 return &m_baseNoteModel;
164 }
165
167 {
168 return &m_firstKeyModel;
169 }
170
172 {
173 return &m_lastKeyModel;
174 }
175
176 bool keyRangeImport() const;
177 bool isKeyMapped(int key) const;
178 int firstKey() const;
179 int lastKey() const;
180 int baseNote() const;
181 float baseFreq() const;
182
184 {
185 return &m_piano;
186 }
187
189 {
190 return &m_microtuner;
191 }
192
193 bool isArpeggioEnabled() const
194 {
195 return m_arpeggio.m_arpEnabledModel.value();
196 }
197
198 // simple helper for removing midiport-XML-node when loading presets
199 static void removeMidiPortNode( DataFile& dataFile );
200
202 {
203 return &m_pitchModel;
204 }
205
207 {
208 return &m_volumeModel;
209 }
210
212 {
213 return &m_panningModel;
214 }
215
217 {
218 return &m_pitchRangeModel;
219 }
220
222 {
223 return &m_mixerChannelModel;
224 }
225
230
231 void setPreviewMode( const bool );
232
233 bool isPreviewMode() const
234 {
235 return m_previewMode;
236 }
237
238 void replaceInstrument(DataFile dataFile);
239
240 void autoAssignMidiDevice( bool );
241
242signals:
244 void midiNoteOn( const lmms::Note& );
245 void midiNoteOff( const lmms::Note& );
246 void newNote();
247 void endNote();
248
249protected:
250 QString nodeName() const override
251 {
252 return "instrumenttrack";
253 }
254
255 // get the name of the instrument in the saved data
256 QString getSavedInstrumentName(const QDomElement & thisElement) const;
257
258
259protected slots:
260 void updateBaseNote();
261 void updatePitch();
262 void updatePitchRange();
263 void updateMixerChannel();
264
265
266private:
267 void processCCEvent(int controller);
268
270
273
276
278
280
282
286
289
291
294
296
301
306
308
310
311 std::unique_ptr<BoolModel> m_midiCCEnable;
312 std::unique_ptr<FloatModel> m_midiCCModel[MidiControllerCount];
313
316 friend class NotePlayHandle;
319
320} ;
321
322
323
324} // namespace lmms
325
326#endif // LMMS_INSTRUMENT_TRACK_H
Controller controller
Definition main.C:5
Job between PlayHandle and MixerChannel.
Definition AudioBusHandle.h:55
Definition AutomatableModel.h:497
Definition Clip.h:50
Definition DataFile.h:44
Definition AutomatableModel.h:463
Definition InstrumentFunctions.h:177
Definition InstrumentFunctions.h:51
Definition Instrument.h:52
Definition InstrumentSoundShaping.h:46
bool isPreviewMode() const
Definition InstrumentTrack.h:233
MidiPort * midiPort()
Definition InstrumentTrack.h:151
std::unique_ptr< FloatModel > m_midiCCModel[MidiControllerCount]
Definition InstrumentTrack.h:312
friend class NotePlayHandle
Definition InstrumentTrack.h:316
IntModel * baseNoteModel()
Definition InstrumentTrack.h:161
BoolModel m_useMasterPitchModel
Definition InstrumentTrack.h:300
void processInEvent(const MidiEvent &event, const TimePos &time=TimePos(), f_cnt_t offset=0) override
Definition InstrumentTrack.cpp:319
NotePlayHandleList m_processHandles
Definition InstrumentTrack.h:290
IntModel * firstKeyModel()
Definition InstrumentTrack.h:166
bool isArpeggioEnabled() const
Definition InstrumentTrack.h:193
FloatModel m_panningModel
Definition InstrumentTrack.h:293
void midiNoteOff(const lmms::Note &)
FloatModel * panningModel()
Definition InstrumentTrack.h:211
InstrumentTrack(TrackContainer *tc)
Definition InstrumentTrack.cpp:49
IntModel m_pitchRangeModel
Definition InstrumentTrack.h:298
bool isSustainPedalPressed() const
Definition InstrumentTrack.h:80
FloatModel m_pitchModel
Definition InstrumentTrack.h:297
IntModel m_baseNoteModel
The "A4" or "440 Hz" key (default 69).
Definition InstrumentTrack.h:283
Instrument * instrument()
Definition InstrumentTrack.h:98
const Instrument * instrument() const
Definition InstrumentTrack.h:93
int midiPitchRange() const
Returns current range for pitch bend in semitones.
Definition InstrumentTrack.h:119
QMutex m_midiNotesMutex
Definition InstrumentTrack.h:275
void processAudioBuffer(SampleFrame *_buf, const f_cnt_t _frames, NotePlayHandle *_n)
Definition InstrumentTrack.cpp:224
bool m_previewMode
Definition InstrumentTrack.h:281
Piano m_piano
Definition InstrumentTrack.h:307
void processOutEvent(const MidiEvent &event, const TimePos &time=TimePos(), f_cnt_t offset=0) override
Definition InstrumentTrack.cpp:464
Microtuner * microtuner()
Definition InstrumentTrack.h:188
QString nodeName() const override
Definition InstrumentTrack.h:250
IntModel m_mixerChannelModel
Definition InstrumentTrack.h:299
NotePlayHandle * m_notes[NumKeys]
Definition InstrumentTrack.h:271
FloatModel * volumeModel()
Definition InstrumentTrack.h:206
MidiPort m_midiPort
Definition InstrumentTrack.h:269
int m_runningMidiNotes[NumKeys]
Definition InstrumentTrack.h:274
void midiNoteOn(const lmms::Note &)
bool m_silentBuffersProcessed
Definition InstrumentTrack.h:279
static InstrumentTrack * s_autoAssignedTrack
Definition InstrumentTrack.h:288
std::unique_ptr< BoolModel > m_midiCCEnable
Definition InstrumentTrack.h:311
FloatModel m_volumeModel
Definition InstrumentTrack.h:292
IntModel * pitchRangeModel()
Definition InstrumentTrack.h:216
Instrument * m_instrument
Definition InstrumentTrack.h:302
NotePlayHandleList m_sustainedNotes
Definition InstrumentTrack.h:272
IntModel m_firstKeyModel
First key the instrument reacts to.
Definition InstrumentTrack.h:284
BoolModel * useMasterPitchModel()
Definition InstrumentTrack.h:226
bool m_hasAutoMidiDev
Definition InstrumentTrack.h:287
FloatModel * pitchModel()
Definition InstrumentTrack.h:201
mapPropertyFromModel(int, getVolume, setVolume, m_volumeModel)
InstrumentFunctionArpeggio m_arpeggio
Definition InstrumentTrack.h:304
InstrumentFunctionNoteStacking m_noteStacking
Definition InstrumentTrack.h:305
AudioBusHandle m_audioBusHandle
Definition InstrumentTrack.h:295
InstrumentSoundShaping m_soundShaping
Definition InstrumentTrack.h:303
const IntModel * baseNoteModel() const
Definition InstrumentTrack.h:156
IntModel m_lastKeyModel
Last key the instrument reacts to.
Definition InstrumentTrack.h:285
Piano * pianoModel()
Definition InstrumentTrack.h:183
IntModel * mixerChannelModel()
Definition InstrumentTrack.h:221
int midiPitch() const
Definition InstrumentTrack.h:113
AudioBusHandle * audioBusHandle()
Definition InstrumentTrack.h:146
bool m_sustainPedalPressed
Definition InstrumentTrack.h:277
void silenceAllNotes(bool removeIPH=false)
Definition InstrumentTrack.cpp:525
IntModel * lastKeyModel()
Definition InstrumentTrack.h:171
Microtuner m_microtuner
Definition InstrumentTrack.h:309
MidiEvent applyMasterKey(const MidiEvent &event)
Definition InstrumentTrack.cpp:282
Definition AutomatableModel.h:481
void setJournalling(const bool _sr)
Definition JournallingObject.h:73
Definition Microtuner.h:36
Definition MidiEvent.h:37
Definition MidiPort.h:56
Definition Note.h:101
Definition NotePlayHandle.h:48
Definition Piano.h:41
Definition SampleFrame.h:41
Definition TimePos.h:68
Definition TrackContainer.h:49
Track(Type type, TrackContainer *tc)
Create a new (empty) track object.
Definition Track.cpp:59
Definition InstrumentTrackView.h:46
Definition InstrumentTrackWindow.h:63
Definition InstrumentTuningView.h:48
Definition MidiCCRackView.h:45
Definition TrackContainerView.h:71
Definition TrackView.h:60
static uintptr_t parent
Definition pugl.h:1644
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
const int MidiControllerCount
Definition Midi.h:128
const int MidiMaxPitchBend
Definition Midi.h:139
QList< NotePlayHandle * > NotePlayHandleList
Definition NotePlayHandle.h:44
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
const int NumKeys
Number of physical keys, limited to MIDI range (valid for both MIDI 1.0 and 2.0).
Definition Note.h:90
ZCONST char * key
Definition crypt.c:587