]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
Cleaning code style of Definitions.
[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 <QtXml/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
57 public:
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
61      *   and video. */
62
63     DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
64 //    DocClipBase & operator=(const DocClipBase & clip);
65     virtual ~ DocClipBase();
66
67     /** returns the name of this clip. */
68     const QString name() const;
69
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;
74
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);
79
80     /** Returns the internal unique id of the clip. */
81     const QString &getId() const;
82
83     bool hasAudioThumb() const;
84     //KThumb *thumbCreator;
85     bool audioThumbCreated() const;
86     /*void getClipMainThumb();*/
87
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);
93
94     /** returns clip type (audio, text, image,...) */
95     const ClipType & clipType() const;
96     /** set clip type (audio, text, image,...) */
97     void setClipType(ClipType type);
98
99     /** remove tmp file if the clip has one (for example text clips) */
100     void removeTmpFile() const;
101
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;
106
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;
111
112     bool isDocClipAVFile() const {
113         return false;
114     }
115
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);
126
127     /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
128      * where it returns true. */
129     bool isProjectClip() const {
130         return false;
131     }
132
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;
139
140     /** Returns true if the xml passed matches the values in this clip */
141     bool matchesXML(const QDomElement & element) const;
142
143     void addReference() {
144         ++m_refcount;
145     }
146     void removeReference() {
147         --m_refcount;
148     }
149     uint numReferences() const {
150         return m_refcount;
151     }
152     /** Returns true if this clip has a meaningful filesize. */
153     bool hasFileSize() const;
154
155     /** Returns the filesize, or 0 if there is no appropriate filesize. */
156     qulonglong fileSize() const;
157
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;
161
162     /** Returns the thumbnail producer used by this clip */
163     KThumb *thumbProducer();
164
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();
173
174     /** Set default play zone for clip monitor */
175     void setZone(const QPoint &zone);
176     /** Get default play zone for clip monitor */
177     QPoint zone() const;
178
179     /** Returns true is clip is missing but user wants to keep it as placeholder */
180     bool isPlaceHolder() const;
181     void setValid();
182     static QString getHash(const QString &path);
183
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());
189
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;
213
214 private:   // Private attributes
215     /** The number of times this clip is used in the project - the number of references to this clip
216      * that exist. */
217     uint m_refcount;
218     QList <Mlt::Producer *> m_baseTrackProducers;
219     QList <Mlt::Producer *> m_videoTrackProducers;
220     QList <Mlt::Producer *> m_audioTrackProducers;
221     QList <Mlt::Producer *> m_toDeleteProducers;
222     ClipType m_clipType;
223
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;
226     GenTime m_duration;
227
228     KThumb *m_thumbProd;
229     bool m_audioThumbCreated;
230
231     /** a unique numeric id */
232     QString m_id;
233
234     /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
235     bool m_placeHolder;
236
237     QList <CutZoneInfo> m_cutZones;
238
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;
246     
247     /** Try to make sure we don't delete a producer while using it */
248     QMutex m_producerMutex;
249     QMutex m_replaceMutex;
250     
251     /** @brief This timer will trigger creation of audio thumbnails. */
252     QTimer m_audioTimer;
253
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);
265
266    
267 public slots:
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);
284
285 signals:
286     void gotAudioData();
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);
291 };
292
293 #endif