]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
Merge branch 'master' of git://anongit.kde.org/kdenlive
[kdenlive] / src / docclipbase.h
1 /***************************************************************************
2                           docclipbase.h  -  description
3                              -------------------
4     begin                : Fri Apr 12 2002
5     copyright            : (C) 2002 by Jason Wood
6     email                : jasonwood@blueyonder.co.uk
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef DOCCLIPBASE_H
19 #define DOCCLIPBASE_H
20
21 /**DocClip is a class for the various types of clip
22   *@author Jason Wood
23   */
24
25 #include <qdom.h>
26 #include <QPixmap>
27 #include <QObject>
28 #include <QTimer>
29 #include <QProcess>
30 #include <QFuture>
31
32 #include <KUrl>
33
34 #include "gentime.h"
35 #include "definitions.h"
36
37 /*
38 class DocTrackBase;
39 class DocClipAVFile;
40 class DocClipTextFile;
41 class DocClipVirtual;
42 class EffectDescriptionList;*/
43 class KdenliveDoc;
44 class KThumb;
45 class ClipManager;
46
47 namespace Mlt
48 {
49 class Producer;
50 };
51
52 struct CutZoneInfo {
53     QPoint zone;
54     QString description;
55 };
56
57
58 class DocClipBase: public QObject
59 {
60 Q_OBJECT public:
61     /** this enum determines the types of "feed" available within this clip. types must be non-exclusive
62      * - e.g. if you can have audio and video separately, it should be possible to combin the two, as is
63      *   done here. If a new clip type is added then it should be possible to combine it with both audio
64      *   and video. */
65
66     DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
67 //    DocClipBase & operator=(const DocClipBase & clip);
68     virtual ~ DocClipBase();
69
70     /** returns the name of this clip. */
71     const QString name() const;
72
73     /** Returns the description of this clip. */
74     const QString description() const;
75     /** Does this clip need a transparent background (e.g. for titles). */
76     bool isTransparent() const;
77
78     /** Returns any property of this clip. */
79     const QString getProperty(const QString &prop) const;
80     void setProperty(const QString &key, const QString &value);
81     void clearProperty(const QString &key);
82
83     /** Returns the internal unique id of the clip. */
84     const QString &getId() const;
85
86     bool hasAudioThumb() const;
87     //KThumb *thumbCreator;
88     bool audioThumbCreated() const;
89     /*void getClipMainThumb();*/
90
91     /** returns the duration of this clip */
92     const GenTime & duration() const;
93     const GenTime maxDuration() const;
94     /** returns the duration of this clip */
95     void setDuration(GenTime dur);
96
97     /** returns clip type (audio, text, image,...) */
98     const CLIPTYPE & clipType() const;
99     /** set clip type (audio, text, image,...) */
100     void setClipType(CLIPTYPE type);
101
102     /** remove tmp file if the clip has one (for example text clips) */
103     void removeTmpFile() const;
104
105     /** Returns a url to a file describing this clip. Exactly what this url is,
106     whether it is temporary or not, and whether it provokes a render will
107     depend entirely on what the clip consists of. */
108     KUrl fileURL() const;
109
110     /** Returns true if the clip duration is known, false otherwise. */
111     bool durationKnown() const;
112     // Returns the number of frames per second that this clip should play at.
113     double framesPerSecond() const;
114
115     bool isDocClipAVFile() const {
116         return false;
117     }
118
119     /** Sets producers for the current clip (one for each track due to a limitation in MLT's track mixing */
120     void setProducer(Mlt::Producer *producer, bool reset = false, bool readPropertiesFromProducer = false);
121     /** Retrieve a producer for a track */
122     Mlt::Producer *getProducer(int track = -1);
123     /** Get a copy of the producer, for use in the clip monitor */
124     Mlt::Producer *getCloneProducer();
125     /** Retrieve the producer that shows only video */
126     Mlt::Producer *videoProducer();
127     /** Retrieve the producer that shows only audio */
128     Mlt::Producer *audioProducer(int track);
129
130     /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
131      * where it returns true. */
132     bool isProjectClip() const {
133         return false;
134     }
135
136     /** Reads in the element structure and creates a clip out of it.*/
137     // Returns an XML document that describes part of the current scene.
138     QDomDocument sceneToXML(const GenTime & startTime,
139                             const GenTime & endTime) const;
140     /** returns a QString containing all of the XML data required to recreate this clip. */
141     QDomElement toXML() const;
142
143     /** Returns true if the xml passed matches the values in this clip */
144     bool matchesXML(const QDomElement & element) const;
145
146     void addReference() {
147         ++m_refcount;
148     }
149     void removeReference() {
150         --m_refcount;
151     }
152     uint numReferences() const {
153         return m_refcount;
154     }
155     /** Returns true if this clip has a meaningful filesize. */
156     bool hasFileSize() const;
157
158     /** Returns the filesize, or 0 if there is no appropriate filesize. */
159     qulonglong fileSize() const;
160
161     /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if
162      * it uses it as part of it's own composition. */
163     bool referencesClip(DocClipBase * clip) const;
164
165     /** Returns the thumbnail producer used by this clip */
166     KThumb *thumbProducer();
167
168     /** Cache for every audio Frame with 10 Bytes */
169     /** format is frame -> channel ->bytes */
170     QMap<int, QMap<int, QByteArray> > m_audioFrameCache;
171
172     /** Free cache data */
173     void slotClearAudioCache();
174     QString getClipHash() const;
175     void refreshThumbUrl();
176     const char *producerProperty(const char *name) const;
177     void setProducerProperty(const char *name, const char *data);
178     void resetProducerProperty(const char *name);
179     void deleteProducers();
180
181     /** Set default play zone for clip monitor */
182     void setZone(QPoint zone);
183     /** Get default play zone for clip monitor */
184     QPoint zone() const;
185
186     /** Returns true is clip is missing but user wants to keep it as placeholder */
187     bool isPlaceHolder() const;
188     void setValid();
189     static QString getHash(const QString &path);
190
191     void addCutZone(int in, int out, QString desc = QString());
192     bool hasCutZone(QPoint p) const;
193     void removeCutZone(int in, int out);
194     QList <CutZoneInfo> cutZones() const;
195     void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
196
197     bool hasVideoCodec(const QString &codec) const;
198     bool hasAudioCodec(const QString &codec) const;
199     bool checkHash() const;
200     void setPlaceHolder(bool place);
201     QImage extractImage(int frame, int width, int height);
202     void clearThumbProducer();
203     void reloadThumbProducer();
204     void cleanupProducers();
205     bool isClean() const;
206     bool getAudioThumbs();
207
208 private:   // Private attributes
209
210     /** The number of times this clip is used in the project - the number of references to this clip
211      * that exist. */
212     uint m_refcount;
213     QList <Mlt::Producer *> m_baseTrackProducers;
214     QList <Mlt::Producer *> m_audioTrackProducers;
215     QList <Mlt::Producer *> m_toDeleteProducers;
216     Mlt::Producer *m_videoOnlyProducer;
217     CLIPTYPE m_clipType;
218
219     /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
220     QList < CommentedTime > m_snapMarkers;
221     GenTime m_duration;
222
223     KThumb *m_thumbProd;
224     bool m_audioThumbCreated;
225
226     /** a unique numeric id */
227     QString m_id;
228
229     /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
230     bool m_placeHolder;
231
232     QList <CutZoneInfo> m_cutZones;
233
234     void setAudioThumbCreated(bool isDone);
235     /** Holds clip infos like fps, size,... */
236     QMap <QString, QString> m_properties;
237     /** Holds clip metadata like author, copyright,... */
238     QMap <QString, QString> m_metadata;
239     
240     /** Try to make sure we don't delete a producer while using it */
241     QMutex m_producerMutex;
242     QMutex m_replaceMutex;
243
244     /** Create connections for audio thumbnails */
245     void slotRefreshProducer();
246     void setProducerProperty(const char *name, int data);
247     void setProducerProperty(const char *name, double data);
248     void getFileHash(const QString &url);
249     /** @brief When duplicating a producer, make sure all manually set properties are passed to it. */
250     void adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind);
251     /** @brief Create another instance of a producer. */
252     Mlt::Producer *cloneProducer(Mlt::Producer *source);
253
254    
255 public slots:
256     void updateAudioThumbnail(const audioByteArray& data);
257     QList < CommentedTime > commentedSnapMarkers() const;
258     GenTime findNextSnapMarker(const GenTime & currTime);
259     GenTime findPreviousSnapMarker(const GenTime & currTime);
260     GenTime hasSnapMarkers(const GenTime & time);
261     QString deleteSnapMarker(const GenTime & time);
262     void editSnapMarker(const GenTime & time, QString comment);
263     void addSnapMarker(const GenTime & time, QString comment);
264     QList < GenTime > snapMarkers() const;
265     QString markerComment(GenTime t);
266     void setClipThumbFrame(const uint &ix);
267     uint getClipThumbFrame() const;
268     void setProperties(QMap <QString, QString> properties);
269     void setMetadata(QMap <QString, QString> properties);
270     /** Returns all current properties for this clip */
271     QMap <QString, QString> properties() const;
272     /** Return the current values for a set of properties */
273     QMap <QString, QString> currentProperties(QMap <QString, QString> props);
274     QMap <QString, QString> metadata() const;
275     void slotExtractImage(QList <int> frames);
276
277 signals:
278     void gotAudioData();
279     /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */
280     void createProxy(const QString &id);
281     /** @brief Abort creation of the proxy clip (lower resolution copy). */
282     void abortProxy(const QString &id, const QString &proxyPath);
283 };
284
285 #endif