-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathClip.cpp
More file actions
233 lines (189 loc) · 4.85 KB
/
Clip.cpp
File metadata and controls
233 lines (189 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Clip.cpp - implementation of Clip class
*
* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "Clip.h"
#include <QDomDocument>
#include "AutomationEditor.h"
#include "AutomationClip.h"
#include "Engine.h"
#include "GuiApplication.h"
#include "Song.h"
#include "Track.h"
#include "TrackContainer.h"
namespace lmms
{
/*! \brief Create a new Clip
*
* Creates a new clip for the given track.
*
* \param _track The track that will contain the new object
*/
Clip::Clip( Track * track ) :
Model( track ),
m_track( track ),
m_startPosition(),
m_length(),
m_loopCount(0),
m_mutedModel( false, this, tr( "Mute" ) ),
m_selectViewOnCreate{false}
{
if( getTrack() )
{
getTrack()->addClip( this );
}
setJournalling( false );
movePosition( 0 );
changeLength( 0 );
setJournalling( true );
}
/*! \brief Copy a Clip
*
* Creates a duplicate clip of the one provided.
*
* \param other The clip object which will be copied.
*/
Clip::Clip(const Clip& other):
Model(other.m_track),
m_track(other.m_track),
m_name(other.m_name),
m_startPosition(other.m_startPosition),
m_length(other.m_length),
m_startTimeOffset(other.m_startTimeOffset),
m_loopCount(0),
m_mutedModel(other.m_mutedModel.value(), this, tr( "Mute" )),
m_autoResize(other.m_autoResize),
m_selectViewOnCreate{other.m_selectViewOnCreate},
m_color(other.m_color)
{
if (getTrack())
{
getTrack()->addClip(this);
}
}
/*! \brief Destroy a Clip
*
* Destroys the given clip.
*
*/
Clip::~Clip()
{
emit destroyedClip();
if( getTrack() )
{
getTrack()->removeClip( this );
}
}
/*! \brief Move this Clip's position in time
*
* If the clip has moved, update its position. We
* also add a journal entry for undo and update the display.
*
* \param _pos The new position of the clip.
*/
void Clip::movePosition( const TimePos & pos )
{
TimePos newPos = std::max(0, pos.getTicks());
if (m_startPosition != newPos)
{
Engine::audioEngine()->requestChangeInModel();
m_startPosition = newPos;
Engine::audioEngine()->doneChangeInModel();
Engine::getSong()->updateLength();
emit positionChanged();
}
}
/*! \brief Change the length of this Clip
*
* If the clip's length has changed, update it. We
* also add a journal entry for undo and update the display.
*
* \param _length The new length of the clip.
*/
void Clip::changeLength( const TimePos & length )
{
m_length = length;
Engine::getSong()->updateLength();
emit lengthChanged();
}
bool Clip::comparePosition(const Clip *a, const Clip *b)
{
return a->startPosition() < b->startPosition();
}
/*! \brief Copies the state of a Clip to another Clip
*
* This method copies the state of a Clip to another Clip
*/
void Clip::copyStateTo( Clip *src, Clip *dst )
{
// If the node names match we copy the state
if( src->nodeName() == dst->nodeName() ){
QDomDocument doc;
QDomElement parent = doc.createElement( "StateCopy" );
src->saveState( doc, parent );
const TimePos pos = dst->startPosition();
dst->restoreState( parent.firstChild().toElement() );
dst->movePosition( pos );
AutomationClip::resolveAllIDs();
gui::getGUI()->automationEditor()->m_editor->updateAfterClipChange();
}
}
bool Clip::hasTrackContainer() const
{
return getTrack() != nullptr && getTrack()->trackContainer() != nullptr;
}
bool Clip::isInPattern() const
{
return hasTrackContainer()
&& getTrack()->trackContainer()->type() == TrackContainer::Type::Pattern;
}
bool Clip::manuallyResizable() const
{
return !isInPattern();
}
/*! \brief Mutes this Clip
*
* Restore the previous state of this clip. This will
* restore the position or the length of the clip
* depending on what was changed.
*
* \param _je The journal entry to undo
*/
void Clip::toggleMute()
{
m_mutedModel.setValue( !m_mutedModel.value() );
emit dataChanged();
}
TimePos Clip::startTimeOffset() const
{
return m_startTimeOffset;
}
void Clip::setStartTimeOffset( const TimePos &startTimeOffset )
{
m_startTimeOffset = startTimeOffset;
}
void Clip::setColor(const std::optional<QColor>& color)
{
m_color = color;
emit colorChanged();
}
} // namespace lmms