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