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