lmms
Cross-platform music production software
Loading...
Searching...
No Matches
AutomationClip.h
Go to the documentation of this file.
1/*
2 * AutomationClip.h - declaration of class AutomationClip, which contains
3 * all information about an automation clip
4 *
5 * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
7 *
8 * This file is part of LMMS - https://lmms.io
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program (see COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301 USA.
24 *
25 */
26
27#ifndef LMMS_AUTOMATION_CLIP_H
28#define LMMS_AUTOMATION_CLIP_H
29
30#include <QMap>
31#include <QPointer>
32
33#include "AutomationNode.h"
34#include "Clip.h"
35
36
37namespace lmms
38{
39
40class AutomationTrack;
41class TimePos;
42
43namespace gui
44{
47} // namespace gui
48
49
50
51class LMMS_EXPORT AutomationClip : public Clip
52{
53 Q_OBJECT
54public:
55 enum class ProgressionType
56 {
57 Discrete,
58 Linear,
59 CubicHermite
60 } ;
61
62 using timeMap = QMap<int, AutomationNode>;
63 using objectVector = std::vector<QPointer<AutomatableModel>>;
64
65 using TimemapIterator = timeMap::const_iterator;
66
67 AutomationClip( AutomationTrack * _auto_track );
68 ~AutomationClip() override = default;
69
70 bool addObject( AutomatableModel * _obj, bool _search_dup = true );
71
72 const AutomatableModel * firstObject() const;
73 const objectVector& objects() const;
74
75 // progression-type stuff
77 {
78 return m_progressionType;
79 }
80 void setProgressionType( ProgressionType _new_progression_type );
81
82 inline float getTension() const
83 {
84 return m_tension;
85 }
86 void setTension( QString _new_tension );
87
88 TimePos timeMapLength() const;
89 void updateLength() override;
90
100 TimePos putValue(
101 const TimePos& time,
102 const float value,
103 const bool quantPos = true,
104 const bool ignoreSurroundingPoints = true
105 );
106
114 TimePos putValues(
115 const TimePos& time,
116 const float inValue,
117 const float outValue,
118 const bool quantPos = true,
119 const bool ignoreSurroundingPoints = true
120 );
121
122 void removeNode(const TimePos & time);
123
127 void removeNodes(const int tick0, const int tick1);
128
132 void resetNodes(const int tick0, const int tick1);
133
137 void resetTangents(const int tick0, const int tick1);
138
139 void recordValue(TimePos time, float value);
140
151 TimePos setDragValue(
152 const TimePos& time,
153 const float value,
154 const bool quantPos = true,
155 const bool controlKey = false
156 );
157
159 void applyDragValue();
160
161
162 bool isDragging() const
163 {
164 return m_dragging;
165 }
166
167 inline const timeMap & getTimeMap() const
168 {
169 return m_timeMap;
170 }
171
173 {
174 return m_timeMap;
175 }
176
177 inline float getMin() const
178 {
179 return firstObject()->minValue<float>();
180 }
181
182 inline float getMax() const
183 {
184 return firstObject()->maxValue<float>();
185 }
186
187 inline bool hasAutomation() const
188 {
189 return m_timeMap.isEmpty() == false;
190 }
191
193 {
194 // Update function if we have new progression types that support tangent editing
195 return pType == ProgressionType::CubicHermite;
196 }
197
198 inline bool canEditTangents() const
199 {
201 }
202
203 float valueAt( const TimePos & _time ) const;
204 float *valuesAfter( const TimePos & _time ) const;
205
206 QString name() const;
207
208 // settings-management
209 void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
210 void loadSettings( const QDomElement & _this ) override;
211
212 static const QString classNodeName() { return "automationclip"; }
213 QString nodeName() const override { return classNodeName(); }
214
215 gui::ClipView * createView( gui::TrackView * _tv ) override;
216
217
218 static bool isAutomated( const AutomatableModel * _m );
219
222 static std::vector<AutomationClip*> clipsForModel(const AutomatableModel* _m);
223
224 static AutomationClip * globalAutomationClip( AutomatableModel * _m );
225 static void resolveAllIDs();
226
227 bool isRecording() const { return m_isRecording; }
228 void setRecording( const bool b ) { m_isRecording = b; }
229
230 static int quantization() { return s_quantization; }
231 static void setQuantization(int q) { s_quantization = q; }
232
234 {
235 return new AutomationClip(*this);
236 }
237
238 void clearObjects() { m_objects.clear(); }
239
240public slots:
241 void clear();
242 void objectDestroyed( lmms::jo_id_t );
243 void flipY( int min, int max );
244 void flipY();
245 void flipX(int start = -1, int end = -1);
246
247protected:
248 AutomationClip( const AutomationClip & _clip_to_copy );
249
250private:
251 void cleanObjects();
252 void generateTangents();
253 void generateTangents(timeMap::iterator it, int numToGenerate);
254 float valueAt( timeMap::const_iterator v, int offset ) const;
255
263 static std::vector<Track*> combineAllTracks();
264
265 // Mutex to make methods involving automation clips thread safe
266 // Mutable so we can lock it from const objects
267 mutable QRecursiveMutex m_clipMutex;
268
270 std::vector<jo_id_t> m_idsToResolve;
272 timeMap m_timeMap; // actual values
273 timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called.
277
279 bool m_dragKeepOutValue; // Should we keep the current dragged node's outValue?
280 float m_dragOutValue; // The outValue of the dragged node's
281 bool m_dragLockedTan; // If the dragged node has it's tangents locked
282 float m_dragInTan; // The dragged node's inTangent
283 float m_dragOutTan; // The dragged node's outTangent
284
287
288 static int s_quantization;
289
290 static const float DEFAULT_MIN_VALUE;
291 static const float DEFAULT_MAX_VALUE;
292
294 friend class AutomationNode;
296
297} ;
298
299//Short-hand functions to access node values in an automation clip;
300// replacement for CPP macros with the same purpose; could be refactored
301// further in the future.
303{
304 return it->getInValue();
305}
306
308{
309 return it->getOutValue();
310}
311
313{
314 return it->getValueOffset();
315}
316
318{
319 return it->getInTangent();
320}
321
323{
324 return it->getOutTangent();
325}
326
328{
329 return it->lockedTangents();
330}
331
333{
334 return it.key();
335}
336
337
338} // namespace lmms
339
340#endif // LMMS_AUTOMATION_CLIP_H
Definition AutomatableModel.h:77
Definition AutomationClip.h:52
static const float DEFAULT_MAX_VALUE
Definition AutomationClip.h:291
bool m_dragLockedTan
Definition AutomationClip.h:281
QRecursiveMutex m_clipMutex
Definition AutomationClip.h:267
bool addObject(AutomatableModel *_obj, bool _search_dup=true)
Definition AutomationClip.cpp:88
std::vector< jo_id_t > m_idsToResolve
Definition AutomationClip.h:270
QString nodeName() const override
Definition AutomationClip.h:213
~AutomationClip() override=default
AutomationTrack * m_autoTrack
Definition AutomationClip.h:269
timeMap m_oldTimeMap
Definition AutomationClip.h:273
bool isRecording() const
Definition AutomationClip.h:227
static int quantization()
Definition AutomationClip.h:230
static int s_quantization
Definition AutomationClip.h:288
AutomationClip * clone() override
Creates a copy of this clip.
Definition AutomationClip.h:233
bool canEditTangents() const
Definition AutomationClip.h:198
static void setQuantization(int q)
Definition AutomationClip.h:231
float m_lastRecordedValue
Definition AutomationClip.h:286
void clearObjects()
Definition AutomationClip.h:238
timeMap::const_iterator TimemapIterator
Definition AutomationClip.h:65
void setRecording(const bool b)
Definition AutomationClip.h:228
bool isDragging() const
Definition AutomationClip.h:162
timeMap m_timeMap
Definition AutomationClip.h:272
friend class AutomationNode
Definition AutomationClip.h:294
ProgressionType progressionType() const
Definition AutomationClip.h:76
AutomationClip(AutomationTrack *_auto_track)
Definition AutomationClip.cpp:48
bool m_dragging
Definition AutomationClip.h:278
static const QString classNodeName()
Definition AutomationClip.h:212
timeMap & getTimeMap()
Definition AutomationClip.h:172
float m_dragOutTan
Definition AutomationClip.h:283
float getMax() const
Definition AutomationClip.h:182
const timeMap & getTimeMap() const
Definition AutomationClip.h:167
const AutomatableModel * firstObject() const
Definition AutomationClip.cpp:152
std::vector< QPointer< AutomatableModel > > objectVector
Definition AutomationClip.h:63
static const float DEFAULT_MIN_VALUE
Definition AutomationClip.h:290
bool m_hasAutomation
Definition AutomationClip.h:275
QMap< int, AutomationNode > timeMap
Definition AutomationClip.h:62
ProgressionType
Definition AutomationClip.h:56
@ CubicHermite
Definition AutomationClip.h:59
bool m_isRecording
Definition AutomationClip.h:285
float m_dragOutValue
Definition AutomationClip.h:280
const objectVector & objects() const
Definition AutomationClip.cpp:166
bool m_dragKeepOutValue
Definition AutomationClip.h:279
float getMin() const
Definition AutomationClip.h:177
ProgressionType m_progressionType
Definition AutomationClip.h:276
bool hasAutomation() const
Definition AutomationClip.h:187
float getTension() const
Definition AutomationClip.h:82
objectVector m_objects
Definition AutomationClip.h:271
static bool supportsTangentEditing(ProgressionType pType)
Definition AutomationClip.h:192
float m_tension
Definition AutomationClip.h:274
float m_dragInTan
Definition AutomationClip.h:282
Definition AutomationTrack.h:36
Clip(Track *track)
Creates a new clip for the given track track.
Definition Clip.cpp:41
Definition TimePos.h:68
Definition AutomationClipView.h:42
Definition AutomationEditor.h:57
Definition ClipView.h:52
Definition TrackView.h:60
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34
float INTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:317
float INVAL(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:302
int POS(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:332
std::uint32_t jo_id_t
Definition LmmsTypes.h:50
float OUTTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:322
float LOCKEDTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:327
float OUTVAL(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:307
float OFFSET(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:312