]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
6ad3894c7a3c8c0bf77f51d15a2335aee543357a
[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 <qdom.h>
26 #include <QPixmap>
27 #include <QObject>
28 #include <QTimer>
29
30 #include <KUrl>
31
32 #include "gentime.h"
33 #include "definitions.h"
34
35 /*
36 class DocTrackBase;
37 class DocClipAVFile;
38 class DocClipTextFile;
39 class DocClipVirtual;
40 class EffectDescriptionList;*/
41 class KdenliveDoc;
42 class KThumb;
43 class ClipManager;
44
45 namespace Mlt
46 {
47 class Producer;
48 };
49
50 struct CutZoneInfo {
51     QPoint zone;
52     QString description;
53 };
54
55
56 class DocClipBase: public QObject
57 {
58 Q_OBJECT public:
59     /** this enum determines the types of "feed" available within this clip. types must be non-exclusive
60      * - e.g. if you can have audio and video separately, it should be possible to combin the two, as is
61      *   done here. If a new clip type is added then it should be possible to combine it with both audio
62      *   and video. */
63
64     DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
65 //    DocClipBase & operator=(const DocClipBase & clip);
66     virtual ~ DocClipBase();
67
68     /** returns the name of this clip. */
69     const QString name() const;
70
71     /** Returns the description of this clip. */
72     const QString description() const;
73     /** Does this clip need a transparent background (e.g. for titles). */
74     bool isTransparent() const;
75
76     /** Returns any property of this clip. */
77     const QString getProperty(const QString prop) const;
78     void setProperty(const QString &key, const QString &value);
79     void clearProperty(const QString &key);
80
81     /** Returns the internal unique id of the clip. */
82     const QString &getId() const;
83     void setId(const QString &newId);
84
85     //KThumb *thumbCreator;
86     bool audioThumbCreated() const;
87     /*void getClipMainThumb();*/
88
89     /** returns the duration of this clip */
90     const GenTime & duration() const;
91     const GenTime maxDuration() const;
92     /** returns the duration of this clip */
93     void setDuration(GenTime dur);
94
95     /** returns clip type (audio, text, image,...) */
96     const CLIPTYPE & clipType() const;
97     /** set clip type (audio, text, image,...) */
98     void setClipType(CLIPTYPE type);
99
100     /** remove tmp file if the clip has one (for example text clips) */
101     void removeTmpFile() const;
102
103     /** Returns a url to a file describing this clip. Exactly what this url is,
104     whether it is temporary or not, and whether it provokes a render will
105     depend entirely on what the clip consists of. */
106     KUrl fileURL() const;
107
108     /** Returns true if the clip duration is known, false otherwise. */
109     bool durationKnown() const;
110     // Returns the number of frames per second that this clip should play at.
111     double framesPerSecond() const;
112
113     bool isDocClipAVFile() const {
114         return false;
115     }
116
117     /** Sets producers for the current clip (one for each track due to a limitation in MLT's track mixing */
118     void setProducer(Mlt::Producer *producer, bool reset = false);
119     /** Retrieve a producer for a track */
120     Mlt::Producer *producer(int track = -1);
121     /** Retrieve the producer that shows only video */
122     Mlt::Producer *videoProducer();
123     /** Retrieve the producer that shows only audio */
124     Mlt::Producer *audioProducer(int track);
125
126     /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
127      * where it returns true. */
128     bool isProjectClip() const {
129         return false;
130     }
131
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() const;
138
139     /** Returns true if the xml passed matches the values in this clip */
140     bool matchesXML(const QDomElement & element) const;
141
142     void addReference() {
143         ++m_refcount;
144     }
145     void removeReference() {
146         --m_refcount;
147     }
148     uint numReferences() const {
149         return m_refcount;
150     }
151     /** Returns true if this clip has a meaningful filesize. */
152     bool hasFileSize() const;
153
154     /** Returns the filesize, or 0 if there is no appropriate filesize. */
155     qulonglong fileSize() const;
156
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;
160
161     /** Sets the thumbnail to be used by this clip */
162     void setThumbnail(const QPixmap & pixmap);
163
164     /** Returns the thumbnail producer used by this clip */
165     KThumb *thumbProducer();
166
167     /** Returns the thumbnail used by this clip */
168     const QPixmap & thumbnail() const;
169
170     /** Cache for every audio Frame with 10 Bytes */
171     /** format is frame -> channel ->bytes */
172     QMap<int, QMap<int, QByteArray> > m_audioFrameCache;
173
174     /** Free cache data */
175     void slotClearAudioCache();
176     void askForAudioThumbs();
177     QString getClipHash() const;
178     void refreshThumbUrl();
179     const char *producerProperty(const char *name) const;
180     void setProducerProperty(const char *name, const char *data);
181     void resetProducerProperty(const char *name);
182     void clearProducers();
183     void deleteProducers(bool clearThumbCreator = true);
184
185     /** Set default play zone for clip monitor */
186     void setZone(QPoint zone);
187     /** Get default play zone for clip monitor */
188     QPoint zone() const;
189
190     /** Returns true is clip is missing but user wants to keep it as placeholder */
191     bool isPlaceHolder() const;
192     void setValid();
193     static QString getHash(const QString &path);
194
195     void addCutZone(int in, int out, QString desc = QString());
196     bool hasCutZone(QPoint p) const;
197     void removeCutZone(int in, int out);
198     QList <CutZoneInfo> cutZones() const;
199     void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
200
201     bool hasVideoCodec(const QString &codec) const;
202     bool hasAudioCodec(const QString &codec) const;
203     bool checkHash() const;
204     void setPlaceHolder(bool place);
205
206 private:   // Private attributes
207
208     /** The number of times this clip is used in the project - the number of references to this clip
209      * that exist. */
210     uint m_refcount;
211     QList <Mlt::Producer *> m_baseTrackProducers;
212     QList <Mlt::Producer *> m_audioTrackProducers;
213     Mlt::Producer *m_videoOnlyProducer;
214     CLIPTYPE m_clipType;
215
216     /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
217     QList < CommentedTime > m_snapMarkers;
218
219     /** A thumbnail for this clip */
220     QPixmap m_thumbnail;
221     GenTime m_duration;
222
223     QTimer *m_audioTimer;
224     KThumb *m_thumbProd;
225     bool m_audioThumbCreated;
226
227     /** a unique numeric id */
228     QString m_id;
229
230     /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
231     bool m_placeHolder;
232
233     QList <CutZoneInfo> m_cutZones;
234
235     void setAudioThumbCreated(bool isDone);
236     /** Holds clip infos like fps, size,... */
237     QMap <QString, QString> m_properties;
238     /** Holds clip metadata like author, copyright,... */
239     QMap <QString, QString> m_metadata;
240     /** Create connections for audio thumbnails */
241     void slotCreateAudioTimer();
242     void slotRefreshProducer();
243     void setProducerProperty(const char *name, int data);
244     void setProducerProperty(const char *name, double data);
245     void getFileHash(const QString url);
246
247 public slots:
248     void updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data);
249     bool slotGetAudioThumbs();
250     QList < CommentedTime > commentedSnapMarkers() const;
251     GenTime findNextSnapMarker(const GenTime & currTime);
252     GenTime findPreviousSnapMarker(const GenTime & currTime);
253     GenTime hasSnapMarkers(const GenTime & time);
254     QString deleteSnapMarker(const GenTime & time);
255     void editSnapMarker(const GenTime & time, QString comment);
256     void addSnapMarker(const GenTime & time, QString comment);
257     QList < GenTime > snapMarkers() const;
258     QString markerComment(GenTime t);
259     void setClipThumbFrame(const uint &ix);
260     uint getClipThumbFrame() const;
261     void setProperties(QMap <QString, QString> properties);
262     void setMetadata(QMap <QString, QString> properties);
263     QMap <QString, QString> properties() const;
264     QMap <QString, QString> metadata() const;
265
266
267 signals:
268     void getAudioThumbs();
269     void gotAudioData();
270 };
271
272 #endif