lmms
Cross-platform music production software
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
179 bool isKeyMapped(int key) const;
180
183 int firstKey() const;
184
187 int lastKey() const;
188
191 int baseNote() const;
192
195 float baseFreq() const;
196
198 {
199 return &m_piano;
200 }
201
203 {
204 return &m_microtuner;
205 }
206
207 bool isArpeggioEnabled() const
208 {
209 return m_arpeggio.m_arpEnabledModel.value();
210 }
211
212 // simple helper for removing midiport-XML-node when loading presets
213 static void removeMidiPortNode( DataFile& dataFile );
214
216 {
217 return &m_pitchModel;
218 }
219
221 {
222 return &m_volumeModel;
223 }
224
226 {
227 return &m_panningModel;
228 }
229
231 {
232 return &m_pitchRangeModel;
233 }
234
236 {
237 return &m_mixerChannelModel;
238 }
239
244
245 void setPreviewMode( const bool );
246
247 bool isPreviewMode() const
248 {
249 return m_previewMode;
250 }
251
252 void replaceInstrument(DataFile dataFile);
253
256 void autoAssignMidiDevice(bool assign);
257
259 FloatModel* midiCCModel(int index) const { return m_midiCCModel[index].get(); }
260
261signals:
263 void midiNoteOn( const lmms::Note& );
264 void midiNoteOff( const lmms::Note& );
265 void newNote();
266 void endNote();
267
268protected:
269 QString nodeName() const override
270 {
271 return "instrumenttrack";
272 }
273
274 // get the name of the instrument in the saved data
275 QString getSavedInstrumentName(const QDomElement & thisElement) const;
276
277
278protected slots:
279 void updateBaseNote();
280 void updatePitch();
281 void updatePitchRange();
282 void updateMixerChannel();
283
284
285private:
286 void processCCEvent(int controller);
287
289
292
295
297
299
301
305
308
310
313
315
320
325
327
329
330 std::unique_ptr<BoolModel> m_midiCCEnable;
331 std::unique_ptr<FloatModel> m_midiCCModel[MidiControllerCount];
332
335 friend class NotePlayHandle;
338
339} ;
340
341
342
343} // namespace lmms
344
345#endif // LMMS_INSTRUMENT_TRACK_H
Job between PlayHandle and MixerChannel.
Definition AudioBusHandle.h:55
Definition AutomatableModel.h:502
Definition Clip.h:50
Definition DataFile.h:44
Definition AutomatableModel.h:468
Definition InstrumentFunctions.h:177
Definition InstrumentFunctions.h:51
Definition Instrument.h:54
Definition InstrumentSoundShaping.h:46
bool isPreviewMode() const
Definition InstrumentTrack.h:247
MidiPort * midiPort()
Definition InstrumentTrack.h:151
std::unique_ptr< FloatModel > m_midiCCModel[MidiControllerCount]
Definition InstrumentTrack.h:331
friend class NotePlayHandle
Definition InstrumentTrack.h:335
IntModel * baseNoteModel()
Definition InstrumentTrack.h:161
BoolModel m_useMasterPitchModel
Definition InstrumentTrack.h:319
void processInEvent(const MidiEvent &event, const TimePos &time=TimePos(), f_cnt_t offset=0) override
Definition InstrumentTrack.cpp:308
NotePlayHandleList m_processHandles
Definition InstrumentTrack.h:309
IntModel * firstKeyModel()
Definition InstrumentTrack.h:166
bool isArpeggioEnabled() const
Definition InstrumentTrack.h:207
FloatModel m_panningModel
Definition InstrumentTrack.h:312
void midiNoteOff(const lmms::Note &)
FloatModel * panningModel()
Definition InstrumentTrack.h:225
InstrumentTrack(TrackContainer *tc)
Definition InstrumentTrack.cpp:49
IntModel m_pitchRangeModel
Definition InstrumentTrack.h:317
bool isSustainPedalPressed() const
Definition InstrumentTrack.h:80
FloatModel m_pitchModel
Definition InstrumentTrack.h:316
IntModel m_baseNoteModel
The "A4" or "440 Hz" key (default 69).
Definition InstrumentTrack.h:302
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:294
void processAudioBuffer(SampleFrame *_buf, const f_cnt_t _frames, NotePlayHandle *_n)
Definition InstrumentTrack.cpp:213
bool m_previewMode
Definition InstrumentTrack.h:300
Piano m_piano
Definition InstrumentTrack.h:326
void processOutEvent(const MidiEvent &event, const TimePos &time=TimePos(), f_cnt_t offset=0) override
Definition InstrumentTrack.cpp:453
Microtuner * microtuner()
Definition InstrumentTrack.h:202
QString nodeName() const override
Definition InstrumentTrack.h:269
IntModel m_mixerChannelModel
Definition InstrumentTrack.h:318
NotePlayHandle * m_notes[NumKeys]
Definition InstrumentTrack.h:290
FloatModel * volumeModel()
Definition InstrumentTrack.h:220
MidiPort m_midiPort
Definition InstrumentTrack.h:288
int m_runningMidiNotes[NumKeys]
Definition InstrumentTrack.h:293
void midiNoteOn(const lmms::Note &)
bool m_silentBuffersProcessed
Definition InstrumentTrack.h:298
static InstrumentTrack * s_autoAssignedTrack
Definition InstrumentTrack.h:307
std::unique_ptr< BoolModel > m_midiCCEnable
Definition InstrumentTrack.h:330
FloatModel m_volumeModel
Definition InstrumentTrack.h:311
IntModel * pitchRangeModel()
Definition InstrumentTrack.h:230
Instrument * m_instrument
Definition InstrumentTrack.h:321
NotePlayHandleList m_sustainedNotes
Definition InstrumentTrack.h:291
IntModel m_firstKeyModel
First key the instrument reacts to.
Definition InstrumentTrack.h:303
BoolModel * useMasterPitchModel()
Definition InstrumentTrack.h:240
bool m_hasAutoMidiDev
Definition InstrumentTrack.h:306
FloatModel * pitchModel()
Definition InstrumentTrack.h:215
mapPropertyFromModel(int, getVolume, setVolume, m_volumeModel)
InstrumentFunctionArpeggio m_arpeggio
Definition InstrumentTrack.h:323
InstrumentFunctionNoteStacking m_noteStacking
Definition InstrumentTrack.h:324
AudioBusHandle m_audioBusHandle
Definition InstrumentTrack.h:314
InstrumentSoundShaping m_soundShaping
Definition InstrumentTrack.h:322
const IntModel * baseNoteModel() const
Definition InstrumentTrack.h:156
IntModel m_lastKeyModel
Last key the instrument reacts to.
Definition InstrumentTrack.h:304
Piano * pianoModel()
Definition InstrumentTrack.h:197
IntModel * mixerChannelModel()
Definition InstrumentTrack.h:235
int midiPitch() const
Definition InstrumentTrack.h:113
AudioBusHandle * audioBusHandle()
Definition InstrumentTrack.h:146
bool m_sustainPedalPressed
Definition InstrumentTrack.h:296
FloatModel * midiCCModel(int index) const
Returns a non-owning pointer to the model for the knob at the given index in the track's MIDI CC rack...
Definition InstrumentTrack.h:259
void silenceAllNotes(bool removeIPH=false)
Definition InstrumentTrack.cpp:514
IntModel * lastKeyModel()
Definition InstrumentTrack.h:171
Microtuner m_microtuner
Definition InstrumentTrack.h:328
MidiEvent applyMasterKey(const MidiEvent &event)
Definition InstrumentTrack.cpp:271
Definition AutomatableModel.h:486
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:49
Definition InstrumentTrackView.h:46
Definition InstrumentTrackWindow.h:63
Definition InstrumentTuningView.h:48
Definition MidiCCRackView.h:45
Definition TrackContainerView.h:71
Definition TrackView.h:60
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34
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