lmms
Cross-platform music production software
Loading...
Searching...
No Matches
Track.h
Go to the documentation of this file.
1/*
2 * Track.h - declaration of Track class
3 *
4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_TRACK_H
26#define LMMS_TRACK_H
27
28#include <vector>
29
30#include <QColor>
31
32#include "AutomatableModel.h"
33#include "JournallingObject.h"
34#include "LmmsTypes.h"
35#include <optional>
36
37
38namespace lmms
39{
40
41class TimePos;
42class TrackContainer;
43class Clip;
44
45
46namespace gui
47{
48
49class TrackView;
51
52}
53
54
59const int MINIMAL_TRACK_HEIGHT = 32;
60const int DEFAULT_TRACK_HEIGHT = 32;
61
62char const *const FILENAME_FILTER = "[\\0000-\x1f\"*/:<>?\\\\|\x7f]";
63
64
66class LMMS_EXPORT Track : public Model, public JournallingObject
67{
68 Q_OBJECT
69 mapPropertyFromModel(bool,isMuted,setMuted,m_mutedModel);
70 mapPropertyFromModel(bool,isSolo,setSolo,m_soloModel);
71public:
72 using clipVector = std::vector<Clip*>;
73
74 enum class Type
75 {
77 Pattern,
79 Event,
80 Video,
81 Automation,
82 HiddenAutomation,
84 } ;
85
92 Track(Type type, TrackContainer* tc);
93
95 ~Track() override;
96
101 static Track* create(Type tt, TrackContainer* tc);
102
107 static Track* create(const QDomElement& element, TrackContainer* tc);
108
110 Track * clone();
111
112
113 // pure virtual functions
114 Type type() const
115 {
116 return m_type;
117 }
118
119 virtual bool play( const TimePos & start, const f_cnt_t frames,
120 const f_cnt_t frameBase, int clipNum = -1 ) = 0;
121
122
123
125 virtual Clip * createClip( const TimePos & pos ) = 0;
126
127 virtual void saveTrackSpecificSettings(QDomDocument& doc, QDomElement& parent, bool presetMode) = 0;
128 virtual void loadTrackSpecificSettings( const QDomElement & element ) = 0;
129
130 // Saving and loading of presets which do not necessarily contain all the track information
131 void savePreset(QDomDocument & doc, QDomElement & element);
132 void loadPreset(const QDomElement & element);
133
134 // Saving and loading of full tracks
135 void saveSettings( QDomDocument & doc, QDomElement & element ) override;
136 void loadSettings( const QDomElement & element ) override;
137
138 // -- for usage by Clip only ---------------
139
142 Clip* addClip(Clip* clip);
143
146 void removeClip(Clip* clip);
147 // -------------------------------------------------------
148
150 void deleteClips();
151
154 int numOfClips() { return m_clips.size(); }
155
165 auto getClip(std::size_t clipNum) -> Clip*;
166
170 int getClipNum(const Clip* clip);
171
172 const clipVector & getClips() const
173 {
174 return m_clips;
175 }
176
185 void getClipsInRange(clipVector& clipV, const TimePos& start, const TimePos& end);
186
194 void swapPositionOfClips( int clipNum1, int clipNum2 );
195
196 void createClipsForPattern(int pattern);
197
198
202 void insertBar(const TimePos& pos);
203
206 void removeBar( const TimePos & pos );
207
212 bar_t length() const;
213
214
216 {
217 return m_trackContainer;
218 }
219
220 // name-stuff
221 virtual const QString & name() const
222 {
223 return m_name;
224 }
225
226 QString displayName() const override
227 {
228 return name();
229 }
230
231 using Model::dataChanged;
232
233 inline int getHeight()
234 {
236 ? m_height
238 }
239 inline void setHeight( int height )
240 {
241 m_height = height;
242 }
243
244 void lock()
245 {
246 m_processingLock.lock();
247 }
248 void unlock()
249 {
250 m_processingLock.unlock();
251 }
252 bool tryLock()
253 {
254 return m_processingLock.tryLock();
255 }
256
257 auto color() const -> const std::optional<QColor>& { return m_color; }
258 void setColor(const std::optional<QColor>& color);
259
260 bool isMutedBeforeSolo() const
261 {
262 return m_mutedBeforeSolo;
263 }
264
265 BoolModel* getMutedModel();
266
267public slots:
268 virtual void setName(const QString& newName);
269
270 void setMutedBeforeSolo(const bool muted)
271 {
272 m_mutedBeforeSolo = muted;
273 }
274
279 void toggleSolo();
280
281private:
292 void saveTrack(QDomDocument& doc, QDomElement& element, bool presetMode);
293
304 void loadTrack(const QDomElement& element, bool presetMode);
305
306private:
309 QString m_name;
311
312protected:
315
316private:
318
320
322
323 std::optional<QColor> m_color;
324
325 friend class gui::TrackView;
326
327
328signals:
333} ;
334
335
336} // namespace lmms
337
338#endif // LMMS_TRACK_H
Definition AutomatableModel.h:502
Definition Clip.h:50
Definition Instrument.h:54
JournallingObject()
Definition JournallingObject.cpp:36
void dataChanged()
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
Definition Sample.h:37
Definition TimePos.h:68
Definition TrackContainer.h:49
Base-class for all tracks.
Definition Track.h:67
void colorChanged()
virtual const QString & name() const
Definition Track.h:221
Clip * addClip(Clip *clip)
Add another Clip into this track.
Definition Track.cpp:286
mapPropertyFromModel(bool, isMuted, setMuted, m_mutedModel)
Track(Type type, TrackContainer *tc)
Create a new (empty) track object.
Definition Track.cpp:49
void removeClip(Clip *clip)
Remove a given Clip from this track.
Definition Track.cpp:298
virtual Clip * createClip(const TimePos &pos)=0
void savePreset(QDomDocument &doc, QDomElement &element)
Definition Track.cpp:261
bool m_mutedBeforeSolo
Definition Track.h:317
bool tryLock()
Definition Track.h:252
mapPropertyFromModel(bool, isSolo, setSolo, m_soloModel)
void saveSettings(QDomDocument &doc, QDomElement &element) override
Definition Track.cpp:271
TrackContainer * m_trackContainer
Definition Track.h:307
TrackContainer * trackContainer() const
Definition Track.h:215
BoolModel m_mutedModel
Definition Track.h:313
virtual gui::TrackView * createView(gui::TrackContainerView *view)=0
Type
Definition Track.h:75
const clipVector & getClips() const
Definition Track.h:172
std::optional< QColor > m_color
Definition Track.h:323
bool isMutedBeforeSolo() const
Definition Track.h:260
QMutex m_processingLock
Definition Track.h:321
int m_height
Definition Track.h:310
BoolModel m_soloModel
Definition Track.h:314
Type type() const
Definition Track.h:114
void loadPreset(const QDomElement &element)
Definition Track.cpp:266
virtual void loadTrackSpecificSettings(const QDomElement &element)=0
int numOfClips()
Return the number of clips we contain.
Definition Track.h:154
virtual void saveTrackSpecificSettings(QDomDocument &doc, QDomElement &parent, bool presetMode)=0
int getHeight()
Definition Track.h:233
void unlock()
Definition Track.h:248
QString displayName() const override
Definition Track.h:226
void lock()
Definition Track.h:244
void nameChanged()
void setHeight(int height)
Definition Track.h:239
void destroyedTrack()
clipVector m_clips
Definition Track.h:319
virtual bool play(const TimePos &start, const f_cnt_t frames, const f_cnt_t frameBase, int clipNum=-1)=0
void deleteClips()
Remove all Clips from this track.
Definition Track.cpp:313
void clipAdded(lmms::Clip *)
std::vector< Clip * > clipVector
Definition Track.h:72
QString m_name
Definition Track.h:309
Type m_type
Definition Track.h:308
void loadSettings(const QDomElement &element) override
Definition Track.cpp:277
void setMutedBeforeSolo(const bool muted)
Definition Track.h:270
auto color() const -> const std::optional< QColor > &
Definition Track.h:257
Definition TrackContainerView.h:71
Definition TrackView.h:60
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34
char const *const FILENAME_FILTER
Definition Track.h:62
std::int32_t bar_t
Definition LmmsTypes.h:34
const int MINIMAL_TRACK_HEIGHT
The minimum track height in pixels.
Definition Track.h:59
const int DEFAULT_TRACK_HEIGHT
Definition Track.h:60
@ Count
Definition Sfxr.h:43
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43