LMMS
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
91 TimePos putValue(
92 const TimePos & time,
93 const float value,
94 const bool quantPos = true,
95 const bool ignoreSurroundingPoints = true
96 );
97
98 TimePos putValues(
99 const TimePos & time,
100 const float inValue,
101 const float outValue,
102 const bool quantPos = true,
103 const bool ignoreSurroundingPoints = true
104 );
105
106 void removeNode(const TimePos & time);
107 void removeNodes(const int tick0, const int tick1);
108
109 void resetNodes(const int tick0, const int tick1);
110
116 void resetTangents(const int tick0, const int tick1);
117
118 void recordValue(TimePos time, float value);
119
120 TimePos setDragValue( const TimePos & time,
121 const float value,
122 const bool quantPos = true,
123 const bool controlKey = false );
124
125 void applyDragValue();
126
127
128 bool isDragging() const
129 {
130 return m_dragging;
131 }
132
133 inline const timeMap & getTimeMap() const
134 {
135 return m_timeMap;
136 }
137
139 {
140 return m_timeMap;
141 }
142
143 inline float getMin() const
144 {
145 return firstObject()->minValue<float>();
146 }
147
148 inline float getMax() const
149 {
150 return firstObject()->maxValue<float>();
151 }
152
153 inline bool hasAutomation() const
154 {
155 return m_timeMap.isEmpty() == false;
156 }
157
159 {
160 // Update function if we have new progression types that support tangent editing
161 return pType == ProgressionType::CubicHermite;
162 }
163
164 inline bool canEditTangents() const
165 {
167 }
168
169 float valueAt( const TimePos & _time ) const;
170 float *valuesAfter( const TimePos & _time ) const;
171
172 QString name() const;
173
174 // settings-management
175 void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
176 void loadSettings( const QDomElement & _this ) override;
177
178 static const QString classNodeName() { return "automationclip"; }
179 QString nodeName() const override { return classNodeName(); }
180
181 gui::ClipView * createView( gui::TrackView * _tv ) override;
182
183
184 static bool isAutomated( const AutomatableModel * _m );
185 static std::vector<AutomationClip*> clipsForModel(const AutomatableModel* _m);
186 static AutomationClip * globalAutomationClip( AutomatableModel * _m );
187 static void resolveAllIDs();
188
189 bool isRecording() const { return m_isRecording; }
190 void setRecording( const bool b ) { m_isRecording = b; }
191
192 static int quantization() { return s_quantization; }
193 static void setQuantization(int q) { s_quantization = q; }
194
196 {
197 return new AutomationClip(*this);
198 }
199
200 void clearObjects() { m_objects.clear(); }
201
202public slots:
203 void clear();
204 void objectDestroyed( lmms::jo_id_t );
205 void flipY( int min, int max );
206 void flipY();
207 void flipX(int start = -1, int end = -1);
208
209protected:
210 AutomationClip( const AutomationClip & _clip_to_copy );
211
212private:
213 void cleanObjects();
214 void generateTangents();
215 void generateTangents(timeMap::iterator it, int numToGenerate);
216 float valueAt( timeMap::const_iterator v, int offset ) const;
217
225 static std::vector<Track*> combineAllTracks();
226
227 // Mutex to make methods involving automation clips thread safe
228 // Mutable so we can lock it from const objects
229 mutable QRecursiveMutex m_clipMutex;
230
232 std::vector<jo_id_t> m_idsToResolve;
234 timeMap m_timeMap; // actual values
235 timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called.
239
241 bool m_dragKeepOutValue; // Should we keep the current dragged node's outValue?
242 float m_dragOutValue; // The outValue of the dragged node's
243 bool m_dragLockedTan; // If the dragged node has it's tangents locked
244 float m_dragInTan; // The dragged node's inTangent
245 float m_dragOutTan; // The dragged node's outTangent
246
249
250 static int s_quantization;
251
252 static const float DEFAULT_MIN_VALUE;
253 static const float DEFAULT_MAX_VALUE;
254
256 friend class AutomationNode;
258
259} ;
260
261//Short-hand functions to access node values in an automation clip;
262// replacement for CPP macros with the same purpose; could be refactored
263// further in the future.
265{
266 return it->getInValue();
267}
268
270{
271 return it->getOutValue();
272}
273
275{
276 return it->getValueOffset();
277}
278
280{
281 return it->getInTangent();
282}
283
285{
286 return it->getOutTangent();
287}
288
290{
291 return it->lockedTangents();
292}
293
295{
296 return it.key();
297}
298
299
300} // namespace lmms
301
302#endif // LMMS_AUTOMATION_CLIP_H
Definition AutomatableModel.h:77
Definition AutomationClip.h:52
static const float DEFAULT_MAX_VALUE
Definition AutomationClip.h:253
bool m_dragLockedTan
Definition AutomationClip.h:243
QRecursiveMutex m_clipMutex
Definition AutomationClip.h:229
bool addObject(AutomatableModel *_obj, bool _search_dup=true)
Definition AutomationClip.cpp:88
std::vector< jo_id_t > m_idsToResolve
Definition AutomationClip.h:232
QString nodeName() const override
Definition AutomationClip.h:179
~AutomationClip() override=default
AutomationTrack * m_autoTrack
Definition AutomationClip.h:231
timeMap m_oldTimeMap
Definition AutomationClip.h:235
bool isRecording() const
Definition AutomationClip.h:189
static int quantization()
Definition AutomationClip.h:192
static int s_quantization
Definition AutomationClip.h:250
AutomationClip * clone() override
Definition AutomationClip.h:195
bool canEditTangents() const
Definition AutomationClip.h:164
static void setQuantization(int q)
Definition AutomationClip.h:193
float m_lastRecordedValue
Definition AutomationClip.h:248
void clearObjects()
Definition AutomationClip.h:200
timeMap::const_iterator TimemapIterator
Definition AutomationClip.h:65
void setRecording(const bool b)
Definition AutomationClip.h:190
bool isDragging() const
Definition AutomationClip.h:128
timeMap m_timeMap
Definition AutomationClip.h:234
friend class AutomationNode
Definition AutomationClip.h:256
ProgressionType progressionType() const
Definition AutomationClip.h:76
AutomationClip(AutomationTrack *_auto_track)
Definition AutomationClip.cpp:48
bool m_dragging
Definition AutomationClip.h:240
static const QString classNodeName()
Definition AutomationClip.h:178
timeMap & getTimeMap()
Definition AutomationClip.h:138
float m_dragOutTan
Definition AutomationClip.h:245
float getMax() const
Definition AutomationClip.h:148
const timeMap & getTimeMap() const
Definition AutomationClip.h:133
const AutomatableModel * firstObject() const
Definition AutomationClip.cpp:151
std::vector< QPointer< AutomatableModel > > objectVector
Definition AutomationClip.h:63
static const float DEFAULT_MIN_VALUE
Definition AutomationClip.h:252
bool m_hasAutomation
Definition AutomationClip.h:237
QMap< int, AutomationNode > timeMap
Definition AutomationClip.h:62
ProgressionType
Definition AutomationClip.h:56
@ CubicHermite
Definition AutomationClip.h:59
bool m_isRecording
Definition AutomationClip.h:247
float m_dragOutValue
Definition AutomationClip.h:242
const objectVector & objects() const
Definition AutomationClip.cpp:165
bool m_dragKeepOutValue
Definition AutomationClip.h:241
float getMin() const
Definition AutomationClip.h:143
ProgressionType m_progressionType
Definition AutomationClip.h:238
bool hasAutomation() const
Definition AutomationClip.h:153
float getTension() const
Definition AutomationClip.h:82
objectVector m_objects
Definition AutomationClip.h:233
static bool supportsTangentEditing(ProgressionType pType)
Definition AutomationClip.h:158
float m_tension
Definition AutomationClip.h:236
float m_dragInTan
Definition AutomationClip.h:244
Definition AutomationTrack.h:36
Clip(Track *track)
Create a new Clip.
Definition Clip.cpp:47
Definition TimePos.h:68
Definition AutomationClipView.h:42
Definition AutomationEditor.h:59
Definition ClipView.h:52
Definition TrackView.h:60
unsigned v[N_MAX]
Definition inflate.c:1584
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
virtual ASIOError start()=0
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
float INTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:279
float INVAL(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:264
std::uint32_t jo_id_t
Definition LmmsTypes.h:50
float OUTTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:284
float LOCKEDTAN(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:289
float OUTVAL(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:269
float OFFSET(AutomationClip::TimemapIterator it)
Definition AutomationClip.h:274
#define min(x, y)
Definition os.h:74
#define max(x, y)
Definition os.h:78
#define POS
Definition rtosc.c:956
b
Definition crypt.c:628
register uch * q
Definition fileio.c:817