]> git.sesse.net Git - kdenlive/blob - src/clipitem.h
Create new (interpolated) keyframes at the in/out points after resize
[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, 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     const QString clipProducer() const;
59     int clipType() const;
60     DocClipBase *baseClip() const;
61     QString clipName() const;
62     void setClipName(const QString &name);
63     QDomElement xml() const;
64     QDomElement itemXml() const;
65     ClipItem *clone(ItemInfo info) const;
66     const EffectsList effectList() const;
67     void setFadeOut(int pos);
68     void setFadeIn(int pos);
69     void setFades(int in, int out);
70
71     /** @brief Gets the clip's effect names.
72     * @return The names of the effects in a string list */
73     QStringList effectNames();
74
75     /** @brief Adds an effect to the clip.
76     * @return The parameters that will be passed to Mlt */
77     EffectsParameterList addEffect(const QDomElement effect, bool animate = true);
78
79     /** @brief Deletes the effect with id @param index. */
80     void deleteEffect(QString index);
81
82     /** @brief Gets the number of effects in this clip. */
83     int effectsCount();
84
85     /** @brief Gets a unique (?) effect id. */
86     int effectsCounter();
87
88     /** @brief Gets a copy of the xml of an effect.
89     * @param ix The effect's index in effectlist
90     * @return A copy of the effect's xml */
91     QDomElement effectAt(int ix) const;
92
93     /** @brief Gets the xml of an effect.
94     * @param ix The effect's index in effectlist
95     * @return The effect's xml */
96     QDomElement getEffectAt(int ix) const;
97
98     /** @brief Replaces an effect.
99     * @param ix The effect's index in effectlist
100     * @param effect The new effect */
101     void setEffectAt(int ix, QDomElement effect);
102     void flashClip();
103     void addTransition(Transition*);
104
105     /** @brief Regenerates audio and video thumbnails.
106     * @param clearExistingThumbs true = regenerate all thumbs, false = only create missing thumbs. */
107     void resetThumbs(bool clearExistingThumbs);
108
109     /** @brief Updates clip properties from base clip.
110     * @param checkDuration whether or not to check for a valid duration. 
111     * @param resetThumbs whether or not to recreate the image thumbnails. */
112     void refreshClip(bool checkDuration, bool resetThumbs);
113
114     /** @brief Gets clip's marker times.
115     * @return A list of the times. */
116     QList <GenTime> snapMarkers() const;
117     QList <CommentedTime> commentedSnapMarkers() const;
118
119     /** @brief Gets the position of the fade in effect. */
120     int fadeIn() const;
121
122     /** @brief Gets the position of the fade out effect. */
123     int fadeOut() const;
124     void setSelectedEffect(const int ix);
125     void updateKeyframeEffect();
126     QDomElement selectedEffect();
127     int selectedEffectIndex() const;
128     void initEffect(QDomElement effect, int diff = 0);
129
130     /** @brief Gets all keyframes.
131     * @param index Number of the effect
132     * @return a list of strings of keyframes (one string per param) */
133     QStringList keyframes(const int index);
134
135     /** @brief Sets params with keyframes and updates the visible keyframes.
136     * @param ix Number of the effect
137     * @param keyframes a list of strings of keyframes (one string per param), which should be used */
138     void setKeyframes(const int ix, const QStringList keyframes);
139     void setEffectList(const EffectsList effectList);
140     void setSpeed(const double speed, int strobe);
141     double speed() const;
142     int strobe() const;
143     GenTime maxDuration() const;
144     GenTime speedIndependantCropStart() const;
145     GenTime speedIndependantCropDuration() const;
146     const ItemInfo speedIndependantInfo() const;
147     int hasEffect(const QString &tag, const QString &id) const;
148
149     /** @brief Makes sure all keyframes are in the clip's cropped duration.
150     * @return Whether or not changes were made */
151     bool checkKeyFrames();
152     QPixmap startThumb() const;
153     QPixmap endThumb() const;
154     void setVideoOnly(bool force);
155     void setAudioOnly(bool force);
156     bool isVideoOnly() const;
157     bool isAudioOnly() const;
158
159     void insertKeyframe(QDomElement effect, int pos, int val);
160     void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value);
161     void updateKeyframes(QDomElement effect);
162     /** @brief Updates the keyframes in the pan and zoom effect to fit the clips cropDuration.
163      * @param width Render width
164      * @param height Render height
165      * @param cut (optional) if clip was cut, cut position relative to the original's clip position
166      * @return List of the pan and zoom effects indexes
167      * 
168      * Can be used for all effects using mlt_geometry with keyframes, but at the moment Pan & Zoom is the only one. */
169     QList <int> updatePanZoom(int width, int height, int cut = 0);
170     void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, int cut = 0);
171     bool updateNormalKeyframes(QDomElement parameter);
172
173     /** @brief Adjusts effects after a clip duration change. */
174     QMap<int, QDomElement> adjustEffectsToDuration(int width, int height, int previous, int current, bool fromStart);
175
176     /** Returns the necessary (audio, video, general) producer.
177      * @param track Track of the requested producer
178      * @param trackSpecific (default = true) Whether to return general producer for a specific track.
179      * @return Fitting producer
180      * Which producer is returned depends on the type of this clip (audioonly, videoonly, normal) */
181     Mlt::Producer *getProducer(int track, bool trackSpecific = true);
182
183 protected:
184     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
185     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
186     virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
187     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
188     //virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
189     //virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
190     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
191
192 private:
193     DocClipBase *m_clip;
194     ItemInfo m_speedIndependantInfo;
195     QString m_producer;
196     CLIPTYPE m_clipType;
197     QString m_clipName;
198     QString m_effectNames;
199     int m_startFade;
200     int m_endFade;
201     bool m_audioOnly;
202     bool m_videoOnly;
203     QColor m_baseColor;
204
205     QPixmap m_startPix;
206     QPixmap m_endPix;
207
208     bool m_hasThumbs;
209     QTimer m_startThumbTimer;
210     QTimer m_endThumbTimer;
211
212     int m_selectedEffect;
213     QTimeLine *m_timeLine;
214     bool m_startThumbRequested;
215     bool m_endThumbRequested;
216     //bool m_hover;
217     double m_speed;
218     int m_strobe;
219
220     EffectsList m_effectList;
221     QList <Transition*> m_transitionsList;
222     QMap<int, QPixmap> m_audioThumbCachePic;
223     bool m_audioThumbReady;
224     double m_framePixelWidth;
225
226     QPixmap m_videoPix;
227     QPixmap m_audioPix;
228     void doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end);
229
230 private slots:
231     void slotGetStartThumb();
232     void slotGetEndThumb();
233     void slotGotAudioData();
234     void slotPrepareAudioThumb(double pixelForOneFrame, int startpixel, int endpixel, int channels);
235     void animate(qreal value);
236     void slotSetStartThumb(QImage img);
237     void slotSetEndThumb(QImage img);
238     void slotThumbReady(int frame, QImage img);
239
240 public slots:
241     void slotFetchThumbs();
242     void slotSetStartThumb(const QPixmap pix);
243     void slotSetEndThumb(const QPixmap pix);
244
245 signals:
246     void getThumb(int, int);
247     void prepareAudioThumb(double, int, int, int);
248 };
249
250 #endif