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