1/***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20
21#ifndef CLIPITEM_H
22#define CLIPITEM_H
23
24#include "abstractclipitem.h"
25
26#include "definitions.h"
27#include "gentime.h"
28#include "effectslist/effectslist.h"
29
30#include <QTimeLine>
31#include <QGraphicsRectItem>
32#include <QDomElement>
33#include <QGraphicsSceneMouseEvent>
34#include <QTimer>
35#include <QFuture>
36
37class DocClipBase;
38class Transition;
39
40namespace Mlt
41{
42class Producer;
43}
44
45class ClipItem : public AbstractClipItem
46{
47 Q_OBJECT
48
49public:
50 ClipItem(DocClipBase *clip, const ItemInfo &info, double fps, double speed, int strobe, int frame_width, bool generateThumbs = true);
51 virtual ~ ClipItem();
52 virtual void paint(QPainter *painter,
53 const QStyleOptionGraphicsItem *option,
54 QWidget *);
55 virtual int type() const;
56 void resizeStart(int posx, bool size = true, bool emitChange = true);
57 void resizeEnd(int posx, bool emitChange = true);
58 OperationType operationMode(const QPointF &pos);
59 static int itemHeight();
60 const QString clipProducer() const;
61 int clipType() const;
62 DocClipBase *baseClip() const;
63 QString clipName() const;
64 void setClipName(const QString &name);
65 QDomElement xml() const;
66 QDomElement itemXml() const;
67 ClipItem *clone(const ItemInfo &info) const;
68 const EffectsList effectList() const;
69 void setFadeOut(int pos);
70 void setFadeIn(int pos);
71 void setFades(int in, int out);
72
73 /** @brief Gets the clip's effect names.
74 * @return The names of the effects in a string list */
75 QStringList effectNames();
76
77 /** @brief Adds an effect to the clip.
78 * @return The parameters that will be passed to Mlt */
79 EffectsParameterList addEffect(QDomElement effect, bool animate = true);
80
81 /** @brief Deletes the effect with id @param index. */
82 void deleteEffect(const QString &index);
83
84 /** @brief Gets the number of effects in this clip. */
85 int effectsCount();
86
87 /** @brief Gets a unique (?) effect id. */
88 int effectsCounter();
89
90 /** @brief Gets a copy of the xml of an effect.
91 * @param ix The effect's list index (starting from 0)
92 * @return A copy of the effect's xml */
93 QDomElement effect(int ix) const;
94
95 /** @brief Gets a copy of the xml of an effect.
96 * @param ix The effect's index in effectlist (starting from 1)
97 * @return A copy of the effect's xml */
98 QDomElement effectAtIndex(int ix) const;
99
100 /** @brief Gets the xml of an effect.
101 * @param ix The effect's index in effectlist (starting from 1)
102 * @return The effect's xml */
103 QDomElement getEffectAtIndex(int ix) const;
104
105 /** @brief Replaces an effect.
106 * @param ix The effect's index in effectlist
107 * @param effect The new effect */
108 void updateEffect(QDomElement effect);
109 /** @brief Enable / disable a list of effect from their indexes. */
110 void enableEffects(QList <int> indexes, bool disable);
111 bool moveEffect(QDomElement effect, int ix);
112 void flashClip();
113 void addTransition(Transition*);
114
115 /** @brief Regenerates audio and video thumbnails.
116 * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
117 void resetThumbs(bool clearExistingThumbs);
118
119 /** @brief Updates clip properties from base clip.
120 * @param checkDuration whether or not to check for a valid duration.
121 * @param resetThumbs whether or not to recreate the image thumbnails. */
122 void refreshClip(bool checkDuration, bool resetThumbs);
123
124 /** @brief Gets clip's marker times.
125 * @return A list of the times. */
126 QList <GenTime> snapMarkers() const;
127 QList <CommentedTime> commentedSnapMarkers() const;
128
129 /** @brief Gets the position of the fade in effect. */
130 int fadeIn() const;
131
132 /** @brief Gets the position of the fade out effect. */
133 int fadeOut() const;
134 void setSelectedEffect(const int ix);
135 void updateKeyframeEffect();
136 QDomElement selectedEffect();
137 int selectedEffectIndex() const;
138
139 void initEffect(QDomElement effect, int diff = 0, int offset = 0);
140
141 /** @brief Gets all keyframes.
142 * @param index Index of the effect
143 * @return a list of strings of keyframes (one string per param) */
144 QStringList keyframes(const int index);
145
146 /** @brief Adjust all geometry keyframes.
147 * @param index Index of the effect */
148 void resizeGeometries(const int index, int width, int height, int previousDuration, int start, int duration);
149
150 /** @brief Sets params with keyframes and updates the visible keyframes.
151 * @param ix Number of the effect
152 * @param keyframes a list of strings of keyframes (one string per param), which should be used */
153 void setKeyframes(const int ix, const QStringList &keyframes);
154 void setEffectList(const EffectsList &effectList);
155 void setSpeed(const double speed, int strobe);
156 double speed() const;
157 int strobe() const;
158 GenTime maxDuration() const;
159 GenTime speedIndependantCropStart() const;
160 GenTime speedIndependantCropDuration() const;
161 const ItemInfo speedIndependantInfo() const;
162 int hasEffect(const QString &tag, const QString &id) const;
163
164 /** @brief Adjust keyframes to the new clip. */
165 const QString adjustKeyframes(const QString &keyframes, int offset);
166 /** @brief Makes sure all keyframes are in the clip's cropped duration.
167 * @param cutPos the frame number where the new clip starts
168 * @return Whether or not changes were made */
169 bool checkKeyFrames(int width, int height, int previousDuration, int cutPos = -1);
170 QPixmap startThumb() const;
171 QPixmap endThumb() const;
172 void setVideoOnly(bool force);
173 void setAudioOnly(bool force);
174 bool isVideoOnly() const;
175 bool isAudioOnly() const;
176
177 void insertKeyframe(QDomElement effect, int pos, int val);
178 void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
179 void updateKeyframes(QDomElement effect);
180 void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo);
181 bool updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo);
182
183 /** @brief Adjusts effects after a clip duration change. */
184 QMap<int, QDomElement> adjustEffectsToDuration(int width, int height, const ItemInfo &oldInfo);
185
186 /** Returns the necessary (audio, video, general) producer.
187 * @param track Track of the requested producer
188 * @param trackSpecific (default = true) Whether to return general producer for a specific track.
189 * @return Fitting producer
190 * Which producer is returned depends on the type of this clip (audioonly, videoonly, normal) */
191 Mlt::Producer *getProducer(int track, bool trackSpecific = true);
192 void resetFrameWidth(int width);
193 /** @brief Clip is about to be deleted, block thumbs. */
194 void stopThumbs();
195
196 /** @brief Get a free index value for effect group. */
197 int nextFreeEffectGroupIndex() const;
198
199protected:
200 //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
201 void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
202 void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
203 void dropEvent(QGraphicsSceneDragDropEvent *event);
204 //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
205 //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
206 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
207
208private:
209 DocClipBase *m_clip;
210 ItemInfo m_speedIndependantInfo;
211 QString m_producer;
212 ClipType m_clipType;
213 QString m_clipName;
214 QString m_effectNames;
215 int m_startFade;
216 int m_endFade;
217 bool m_audioOnly;
218 bool m_videoOnly;
219 QColor m_baseColor;
220 QColor m_paintColor;
221
222 QPixmap m_startPix;
223 QPixmap m_endPix;
224
225 bool m_hasThumbs;
226 QTimer m_startThumbTimer;
227 QTimer m_endThumbTimer;
228
229 int m_selectedEffect;
230 QTimeLine *m_timeLine;
231 bool m_startThumbRequested;
232 bool m_endThumbRequested;
233 //bool m_hover;
234 double m_speed;
235 int m_strobe;
236
237 EffectsList m_effectList;
238 QList <Transition*> m_transitionsList;
239 QMap<int, QPixmap> m_audioThumbCachePic;
240 bool m_audioThumbReady;
241 double m_framePixelWidth;
242
243 QPixmap m_videoPix;
244 QPixmap m_audioPix;
245 /** @brief Keyframes type can be "keyframe" or "simplekeyframe" which have to be painted differently.
246 * True if keyframe type is "keyframe" */
247 bool m_limitedKeyFrames;
248
249private slots:
250 void slotGetStartThumb();
251 void slotGetEndThumb();
252 void slotGotAudioData();
253 void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels, int pixelHeight);
254 void animate(qreal value);
255 void slotSetStartThumb(const QImage &img);
256 void slotSetEndThumb(const QImage &img);
257 void slotThumbReady(int frame, const QImage &img);
258 /** @brief The thumbnailer has finished to cache all required thumbs. */
259 void slotGotThumbsCache();
260
261public slots:
262 void slotFetchThumbs();
263 void slotSetStartThumb(const QPixmap &pix);
264 void slotSetEndThumb(const QPixmap &pix);
265 void slotUpdateRange();
266
267signals:
268 void prepareAudioThumb(double, int, int, int, int);
269 void updateRange();
270};
271
272#endif
273