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