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