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 //KThumb *thumbCreator;
87 bool audioThumbCreated() const;
88 /*void getClipMainThumb();*/
90 /** returns the duration of this clip */
91 const GenTime & duration() const;
92 const GenTime maxDuration() const;
93 /** returns the duration of this clip */
94 void setDuration(GenTime dur);
96 /** returns clip type (audio, text, image,...) */
97 const CLIPTYPE & clipType() const;
98 /** set clip type (audio, text, image,...) */
99 void setClipType(CLIPTYPE type);
101 /** remove tmp file if the clip has one (for example text clips) */
102 void removeTmpFile() const;
104 /** Returns a url to a file describing this clip. Exactly what this url is,
105 whether it is temporary or not, and whether it provokes a render will
106 depend entirely on what the clip consists of. */
107 KUrl fileURL() const;
109 /** Returns true if the clip duration is known, false otherwise. */
110 bool durationKnown() const;
111 // Returns the number of frames per second that this clip should play at.
112 double framesPerSecond() const;
114 bool isDocClipAVFile() const {
118 /** Sets producers for the current clip (one for each track due to a limitation in MLT's track mixing */
119 void setProducer(Mlt::Producer *producer, bool reset = false, bool readPropertiesFromProducer = false);
120 /** Retrieve a producer for a track */
121 Mlt::Producer *getProducer(int track = -1);
122 /** Get a copy of the producer, for use in the clip monitor */
123 Mlt::Producer *getCloneProducer();
124 /** Retrieve the producer that shows only video */
125 Mlt::Producer *videoProducer();
126 /** Retrieve the producer that shows only audio */
127 Mlt::Producer *audioProducer(int track);
129 /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
130 * where it returns true. */
131 bool isProjectClip() const {
135 /** Reads in the element structure and creates a clip out of it.*/
136 // Returns an XML document that describes part of the current scene.
137 QDomDocument sceneToXML(const GenTime & startTime,
138 const GenTime & endTime) const;
139 /** returns a QString containing all of the XML data required to recreate this clip. */
140 QDomElement toXML() const;
142 /** Returns true if the xml passed matches the values in this clip */
143 bool matchesXML(const QDomElement & element) const;
145 void addReference() {
148 void removeReference() {
151 uint numReferences() const {
154 /** Returns true if this clip has a meaningful filesize. */
155 bool hasFileSize() const;
157 /** Returns the filesize, or 0 if there is no appropriate filesize. */
158 qulonglong fileSize() const;
160 /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if
161 * it uses it as part of it's own composition. */
162 bool referencesClip(DocClipBase * clip) const;
164 /** Returns the thumbnail producer used by this clip */
165 KThumb *thumbProducer();
167 /** Cache for every audio Frame with 10 Bytes */
168 /** format is frame -> channel ->bytes */
169 QMap<int, QMap<int, QByteArray> > m_audioFrameCache;
171 /** Free cache data */
172 void slotClearAudioCache();
173 QString getClipHash() const;
174 void refreshThumbUrl();
175 const char *producerProperty(const char *name) const;
176 void setProducerProperty(const char *name, const char *data);
177 void resetProducerProperty(const char *name);
178 void deleteProducers();
180 /** Set default play zone for clip monitor */
181 void setZone(QPoint zone);
182 /** Get default play zone for clip monitor */
185 /** Returns true is clip is missing but user wants to keep it as placeholder */
186 bool isPlaceHolder() const;
188 static QString getHash(const QString &path);
190 void addCutZone(int in, int out, QString desc = QString());
191 bool hasCutZone(QPoint p) const;
192 void removeCutZone(int in, int out);
193 QList <CutZoneInfo> cutZones() const;
194 void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
196 bool hasVideoCodec(const QString &codec) const;
197 bool hasAudioCodec(const QString &codec) const;
198 bool checkHash() const;
199 void setPlaceHolder(bool place);
200 QImage extractImage(int frame, int width, int height);
201 void clearThumbProducer();
202 void reloadThumbProducer();
203 void cleanupProducers();
204 bool isClean() const;
205 bool getAudioThumbs();
207 private: // Private attributes
209 /** The number of times this clip is used in the project - the number of references to this clip
212 QList <Mlt::Producer *> m_baseTrackProducers;
213 QList <Mlt::Producer *> m_audioTrackProducers;
214 QList <Mlt::Producer *> m_toDeleteProducers;
215 Mlt::Producer *m_videoOnlyProducer;
218 /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
219 QList < CommentedTime > m_snapMarkers;
223 bool m_audioThumbCreated;
225 /** a unique numeric id */
228 /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
231 QList <CutZoneInfo> m_cutZones;
233 void setAudioThumbCreated(bool isDone);
234 /** Holds clip infos like fps, size,... */
235 QMap <QString, QString> m_properties;
236 /** Holds clip metadata like author, copyright,... */
237 QMap <QString, QString> m_metadata;
239 /** Try to make sure we don't delete a producer while using it */
240 QMutex m_producerMutex;
241 QMutex m_replaceMutex;
243 /** Create connections for audio thumbnails */
244 void slotRefreshProducer();
245 void setProducerProperty(const char *name, int data);
246 void setProducerProperty(const char *name, double data);
247 void getFileHash(const QString &url);
248 /** @brief When duplicating a producer, make sure all manually set properties are passed to it. */
249 void adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind);
250 /** @brief Create another instance of a producer. */
251 Mlt::Producer *cloneProducer(Mlt::Producer *source);
255 void updateAudioThumbnail(const audioByteArray& data);
256 QList < CommentedTime > commentedSnapMarkers() const;
257 GenTime findNextSnapMarker(const GenTime & currTime);
258 GenTime findPreviousSnapMarker(const GenTime & currTime);
259 GenTime hasSnapMarkers(const GenTime & time);
260 QString deleteSnapMarker(const GenTime & time);
261 void editSnapMarker(const GenTime & time, QString comment);
262 void addSnapMarker(const GenTime & time, QString comment);
263 QList < GenTime > snapMarkers() const;
264 QString markerComment(GenTime t);
265 void setClipThumbFrame(const uint &ix);
266 uint getClipThumbFrame() const;
267 void setProperties(QMap <QString, QString> properties);
268 void setMetadata(QMap <QString, QString> properties);
269 /** Returns all current properties for this clip */
270 QMap <QString, QString> properties() const;
271 /** Return the current values for a set of properties */
272 QMap <QString, QString> currentProperties(QMap <QString, QString> props);
273 QMap <QString, QString> metadata() const;
274 void slotExtractImage(QList <int> frames);
278 /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */
279 void createProxy(const QString &id);
280 /** @brief Abort creation of the proxy clip (lower resolution copy). */
281 void abortProxy(const QString &id, const QString &proxyPath);