]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
9b76a2e72c8e11f8dce673866f5a47f104807dc4
[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();
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     static QString getHash(const QString &path);
193
194     void addCutZone(int in, int out, QString desc = QString());
195     bool hasCutZone(QPoint p) const;
196     void removeCutZone(int in, int out);
197     QList <CutZoneInfo> cutZones() const;
198     void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
199
200     bool hasVideoCodec(const QString &codec) const;
201     bool hasAudioCodec(const QString &codec) const;
202
203 private:   // Private attributes
204
205     /** The number of times this clip is used in the project - the number of references to this clip
206      * that exist. */
207     uint m_refcount;
208     QList <Mlt::Producer *> m_baseTrackProducers;
209     QList <Mlt::Producer *> m_audioTrackProducers;
210     Mlt::Producer *m_videoOnlyProducer;
211     CLIPTYPE m_clipType;
212
213     /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
214     QList < CommentedTime > m_snapMarkers;
215
216     /** A thumbnail for this clip */
217     QPixmap m_thumbnail;
218     GenTime m_duration;
219
220     QTimer *m_audioTimer;
221     KThumb *m_thumbProd;
222     bool m_audioThumbCreated;
223
224     /** a unique numeric id */
225     QString m_id;
226
227     /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
228     bool m_placeHolder;
229
230     QList <CutZoneInfo> m_cutZones;
231
232     void setAudioThumbCreated(bool isDone);
233     /** Holds clip infos like fps, size,... */
234     QMap <QString, QString> m_properties;
235     /** Holds clip metadata like author, copyright,... */
236     QMap <QString, QString> m_metadata;
237     /** Create connections for audio thumbnails */
238     void slotCreateAudioTimer();
239     void slotRefreshProducer();
240     void setProducerProperty(const char *name, int data);
241     void setProducerProperty(const char *name, double data);
242     void getFileHash(const QString url);
243
244 public slots:
245     void updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data);
246     bool slotGetAudioThumbs();
247     QList < CommentedTime > commentedSnapMarkers() const;
248     void setSnapMarkers(QList < CommentedTime > markers);
249     GenTime findNextSnapMarker(const GenTime & currTime);
250     GenTime findPreviousSnapMarker(const GenTime & currTime);
251     GenTime hasSnapMarkers(const GenTime & time);
252     QString deleteSnapMarker(const GenTime & time);
253     void editSnapMarker(const GenTime & time, QString comment);
254     void addSnapMarker(const GenTime & time, QString comment);
255     QList < GenTime > snapMarkers() const;
256     QString markerComment(GenTime t);
257     void setClipThumbFrame(const uint &ix);
258     uint getClipThumbFrame() const;
259     void setProperties(QMap <QString, QString> properties);
260     void setMetadata(QMap <QString, QString> properties);
261     QMap <QString, QString> properties() const;
262     QMap <QString, QString> metadata() const;
263
264
265 signals:
266     void getAudioThumbs();
267     void gotAudioData();
268 };
269
270 #endif