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