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