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
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
62 DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
63 // DocClipBase & operator=(const DocClipBase & clip);
64 virtual ~ DocClipBase();
66 /** returns the name of this clip. */
67 const QString name() const;
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;
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);
79 /** Returns the internal unique id of the clip. */
80 const QString &getId() const;
82 bool hasAudioThumb() const;
83 //KThumb *thumbCreator;
84 bool audioThumbCreated() const;
85 /*void getClipMainThumb();*/
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);
93 /** returns clip type (audio, text, image,...) */
94 const CLIPTYPE & clipType() const;
95 /** set clip type (audio, text, image,...) */
96 void setClipType(CLIPTYPE type);
98 /** remove tmp file if the clip has one (for example text clips) */
99 void removeTmpFile() const;
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;
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;
111 bool isDocClipAVFile() const {
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);
126 /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
127 * where it returns true. */
128 bool isProjectClip() const {
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;
139 /** Returns true if the xml passed matches the values in this clip */
140 bool matchesXML(const QDomElement & element) const;
142 void addReference() {
145 void removeReference() {
148 uint numReferences() const {
151 /** Returns true if this clip has a meaningful filesize. */
152 bool hasFileSize() const;
154 /** Returns the filesize, or 0 if there is no appropriate filesize. */
155 qulonglong fileSize() const;
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;
161 /** Returns the thumbnail producer used by this clip */
162 KThumb *thumbProducer();
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();
173 /** Set default play zone for clip monitor */
174 void setZone(QPoint zone);
175 /** Get default play zone for clip monitor */
178 /** Returns true is clip is missing but user wants to keep it as placeholder */
179 bool isPlaceHolder() const;
181 static QString getHash(const QString &path);
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());
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;
213 private: // Private attributes
214 /** The number of times this clip is used in the project - the number of references to this clip
217 QList <Mlt::Producer *> m_baseTrackProducers;
218 QList <Mlt::Producer *> m_videoTrackProducers;
219 QList <Mlt::Producer *> m_audioTrackProducers;
220 QList <Mlt::Producer *> m_toDeleteProducers;
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;
228 bool m_audioThumbCreated;
230 /** a unique numeric id */
233 /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
236 QList <CutZoneInfo> m_cutZones;
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;
246 /** Try to make sure we don't delete a producer while using it */
247 QMutex m_producerMutex;
248 QMutex m_replaceMutex;
250 /** @brief This timer will trigger creation of audio thumbnails. */
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);
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);
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);