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