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