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"
40 class DocClipTextFile;
42 class EffectDescriptionList;*/
58 class DocClipBase: public QObject
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
66 DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
67 // DocClipBase & operator=(const DocClipBase & clip);
68 virtual ~ DocClipBase();
70 /** returns the name of this clip. */
71 const QString name() const;
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;
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);
83 /** Returns the internal unique id of the clip. */
84 const QString &getId() const;
86 bool hasAudioThumb() const;
87 //KThumb *thumbCreator;
88 bool audioThumbCreated() const;
89 /*void getClipMainThumb();*/
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);
97 /** returns clip type (audio, text, image,...) */
98 const CLIPTYPE & clipType() const;
99 /** set clip type (audio, text, image,...) */
100 void setClipType(CLIPTYPE type);
102 /** remove tmp file if the clip has one (for example text clips) */
103 void removeTmpFile() const;
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;
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;
115 bool isDocClipAVFile() const {
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(int track);
127 /** Retrieve the producer that shows only audio */
128 Mlt::Producer *audioProducer(int track);
130 /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
131 * where it returns true. */
132 bool isProjectClip() const {
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(bool hideTemporaryProperties = false) const;
143 /** Returns true if the xml passed matches the values in this clip */
144 bool matchesXML(const QDomElement & element) const;
146 void addReference() {
149 void removeReference() {
152 uint numReferences() const {
155 /** Returns true if this clip has a meaningful filesize. */
156 bool hasFileSize() const;
158 /** Returns the filesize, or 0 if there is no appropriate filesize. */
159 qulonglong fileSize() const;
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;
165 /** Returns the thumbnail producer used by this clip */
166 KThumb *thumbProducer();
168 /** Free cache data */
169 void slotClearAudioCache();
170 QString getClipHash() const;
171 void refreshThumbUrl();
172 const char *producerProperty(const char *name) const;
173 void setProducerProperty(const char *name, const char *data);
174 void resetProducerProperty(const char *name);
175 void deleteProducers();
177 /** Set default play zone for clip monitor */
178 void setZone(QPoint zone);
179 /** Get default play zone for clip monitor */
182 /** Returns true is clip is missing but user wants to keep it as placeholder */
183 bool isPlaceHolder() const;
185 static QString getHash(const QString &path);
187 void addCutZone(int in, int out, QString desc = QString());
188 bool hasCutZone(QPoint p) const;
189 void removeCutZone(int in, int out);
190 QList <CutZoneInfo> cutZones() const;
191 void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
193 bool hasVideoCodec(const QString &codec) const;
194 bool hasAudioCodec(const QString &codec) const;
195 bool checkHash() const;
196 void setPlaceHolder(bool place);
197 QImage extractImage(int frame, int width, int height);
198 void clearThumbProducer();
199 void reloadThumbProducer();
200 void cleanupProducers();
201 bool isClean() const;
202 bool getAudioThumbs();
203 void setAnalysisData(const QString &name, const QString &data, int offset = 0);
204 QMap <QString, QString> analysisData() const;
205 int lastSeekPosition;
206 /** Cache for every audio Frame with 10 Bytes */
207 /** format is frame -> channel ->bytes */
208 QMap<int, QMap<int, QByteArray> > audioFrameCache;
209 /** Returns all current properties for this clip */
210 QMap <QString, QString> properties() const;
211 /** Return the current values for a set of properties */
212 QMap <QString, QString> currentProperties(QMap <QString, QString> props);
213 QMap <QString, QStringList> metadata() const;
214 /** @brief Returns a short info string about the clip to display in tooltip */
215 const QString shortInfo() const;
217 private: // Private attributes
218 /** The number of times this clip is used in the project - the number of references to this clip
221 QList <Mlt::Producer *> m_baseTrackProducers;
222 QList <Mlt::Producer *> m_videoTrackProducers;
223 QList <Mlt::Producer *> m_audioTrackProducers;
224 QList <Mlt::Producer *> m_toDeleteProducers;
227 /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
228 QList < CommentedTime > m_snapMarkers;
232 bool m_audioThumbCreated;
234 /** a unique numeric id */
237 /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
240 QList <CutZoneInfo> m_cutZones;
242 void setAudioThumbCreated(bool isDone);
243 /** Holds clip infos like fps, size,... */
244 QMap <QString, QString> m_properties;
245 /** Holds clip metadata like author, copyright,... */
246 QMap <QString, QStringList> m_metadata;
247 /** Holds clip analysis data that can be used later to create markers or keyframes */
248 QMap <QString, QString> m_analysisdata;
250 /** Try to make sure we don't delete a producer while using it */
251 QMutex m_producerMutex;
252 QMutex m_replaceMutex;
254 /** @brief This timer will trigger creation of audio thumbnails. */
257 /** Create connections for audio thumbnails */
258 void slotRefreshProducer();
259 void setProducerProperty(const char *name, int data);
260 void setProducerProperty(const char *name, double data);
261 void getFileHash(const QString &url);
262 /** @brief When duplicating a producer, make sure all manually set properties are passed to it. */
263 void adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind);
264 /** @brief Create another instance of a producer. */
265 Mlt::Producer *cloneProducer(Mlt::Producer *source);
266 /** @brief Offset all keyframes of a geometry. */
267 const QString geometryWithOffset(QString data, int offset);
271 void updateAudioThumbnail(const audioByteArray& data);
272 QList < CommentedTime > commentedSnapMarkers() const;
273 GenTime findNextSnapMarker(const GenTime & currTime);
274 GenTime findPreviousSnapMarker(const GenTime & currTime);
275 GenTime hasSnapMarkers(const GenTime & time);
276 QString deleteSnapMarker(const GenTime & time);
277 void editSnapMarker(const GenTime & time, QString comment);
278 void addSnapMarker(const CommentedTime marker);
279 QList < GenTime > snapMarkers() const;
280 QString markerComment(GenTime t) const;
281 CommentedTime markerAt(GenTime t) const;
282 void setClipThumbFrame(const uint &ix);
283 uint getClipThumbFrame() const;
284 void setProperties(QMap <QString, QString> properties);
285 void setMetadata(QMap <QString, QString> properties, QString tool = QString());
286 void slotExtractImage(QList <int> frames);
290 /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */
291 void createProxy(const QString &id);
292 /** @brief Abort creation of the proxy clip (lower resolution copy). */
293 void abortProxy(const QString &id, const QString &proxyPath);