]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
* Fix crash when using razor tool while playing
[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     void clearProperty(const QString &key);
76
77     /** Returns the internal unique id of the clip. */
78     const QString &getId() const;
79     void setId(const QString &newId);
80
81     //KThumb *thumbCreator;
82     bool audioThumbCreated() const;
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     void setProducer(Mlt::Producer *producer);
113     Mlt::Producer *producer();
114
115     /*virtual DocClipAVFile *toDocClipAVFile() {
116     return 0;
117     }
118
119     virtual DocClipTextFile *toDocClipTextFile() {
120         return 0;
121     }
122
123     virtual bool isDocClipTextFile() const {
124         return false;
125     }
126
127     virtual bool isDocClipVirtual() const {
128         return false;
129     }
130
131     virtual DocClipVirtual *toDocClipVirtual() {
132         return 0;
133     }*/
134
135     /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
136      * where it returns true. */
137     bool isProjectClip() const {
138         return false;
139     }
140     // Appends scene times for this clip to the passed vector.
141     /* virtual void populateSceneTimes(QList < GenTime >
142      &toPopulate) const = 0;*/
143
144     /** Reads in the element structure and creates a clip out of it.*/
145     // Returns an XML document that describes part of the current scene.
146     QDomDocument sceneToXML(const GenTime & startTime,
147                             const GenTime & endTime) const;
148     /** returns a QString containing all of the XML data required to recreate this clip. */
149     QDomElement toXML() const;
150
151     /** Returns true if the xml passed matches the values in this clip */
152     bool matchesXML(const QDomElement & element) const;
153
154     void addReference() {
155         ++m_refcount;
156     }
157     void removeReference() {
158         --m_refcount;
159     }
160     uint numReferences() const {
161         return m_refcount;
162     }
163     /** Returns true if this clip has a meaningful filesize. */
164     bool hasFileSize() const;
165
166     /** Returns the filesize, or 0 if there is no appropriate filesize. */
167     uint fileSize() const;
168
169     /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if
170      * it uses it as part of it's own composition. */
171     bool referencesClip(DocClipBase * clip) const;
172
173     /** Sets the thumbnail to be used by this clip */
174     void setThumbnail(const QPixmap & pixmap);
175
176     /** Returns the thumbnail producer used by this clip */
177     KThumb *thumbProducer();
178
179     /** Returns the thumbnail used by this clip */
180     const QPixmap & thumbnail() const;
181
182     static DocClipBase *createClip(KdenliveDoc *doc, const QDomElement & element);
183     /** Cache for every audio Frame with 10 Bytes */
184     /** format is frame -> channel ->bytes */
185     QMap<int, QMap<int, QByteArray> > audioFrameChache;
186
187     /** Clip is ready to get thumbs */
188     void slotRequestAudioThumbs();
189     /** Free cache data */
190     void slotClearAudioCache();
191
192 private:   // Private attributes
193     /** The name of this clip */
194     QString m_name;
195     /** A description of this clip */
196     QString m_description;
197     /** The number of times this clip is used in the project - the number of references to this clip
198      * that exist. */
199     uint m_refcount;
200     Mlt::Producer *m_clipProducer;
201     CLIPTYPE m_clipType;
202
203     /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
204     QList < CommentedTime > m_snapMarkers;
205
206     /** A thumbnail for this clip */
207     QPixmap m_thumbnail;
208     GenTime m_duration;
209
210     QTimer *m_audioTimer;
211     KThumb *m_thumbProd;
212     bool m_audioThumbCreated;
213
214     /** a unique numeric id */
215     QString m_id;
216     void setAudioThumbCreated(bool isDone);
217     /** Holds clip infos like fps, size,... */
218     QMap <QString, QString> m_properties;
219     /** Create connections for audio thumbnails */
220     void slotCreateAudioTimer();
221     void slotRefreshProducer();
222
223 public slots:
224     void updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data);
225     void slotGetAudioThumbs();
226     QList < CommentedTime > commentedSnapMarkers() const;
227     void setSnapMarkers(QList < CommentedTime > markers);
228     GenTime findNextSnapMarker(const GenTime & currTime);
229     GenTime findPreviousSnapMarker(const GenTime & currTime);
230     GenTime hasSnapMarkers(const GenTime & time);
231     QString deleteSnapMarker(const GenTime & time);
232     void editSnapMarker(const GenTime & time, QString comment);
233     void addSnapMarker(const GenTime & time, QString comment);
234     QList < GenTime > snapMarkers() const;
235     QString markerComment(GenTime t);
236     void setClipThumbFrame(const uint &ix);
237     uint getClipThumbFrame() const;
238     void setProperties(QMap <QString, QString> properties);
239     QMap <QString, QString> properties() const;
240
241 signals:
242     void getAudioThumbs();
243     void gotAudioData();
244 };
245
246 #endif