]> git.sesse.net Git - kdenlive/blob - src/docclipbase.h
fadb38ca28c16ba6a664626f3327a6d0fff5d1da
[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 <qobject.h>
27 #include <qpixmap.h>
28
29 #include <kurl.h>
30 #include <klocale.h>
31
32 #include "gentime.h"
33 // #include "kthumb.h"
34
35 /*
36 class DocTrackBase;
37 class DocClipAVFile;
38 class DocClipTextFile;
39 class DocClipVirtual;
40 class EffectDescriptionList;*/
41 class KdenliveDoc;
42
43 class CommentedTime
44     {
45     public:
46         CommentedTime(): t(GenTime(0)) {}
47         CommentedTime( const GenTime time, QString comment)
48             : t( time ), c( comment )
49         { }
50
51         QString comment()   const          { return (c.isEmpty() ? i18n("Marker") : c);}
52         GenTime time() const          { return t; }
53         void    setComment( QString comm) { c = comm; }
54     private:
55         GenTime t;
56         QString c;
57     };
58
59
60 class DocClipBase:public QObject {
61   Q_OBJECT public:
62         /** this enum determines the types of "feed" available within this clip. types must be non-exclusive
63          * - e.g. if you can have audio and video seperately, it should be possible to combin the two, as is
64          *   done here. If a new clip type is added then it should be possible to combine it with both audio
65          *   and video. */
66     enum CLIPTYPE { NONE = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR =
67             4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9};
68
69      DocClipBase();
70      virtual ~ DocClipBase();
71
72         /** sets the name of this clip. */
73     void setName(const QString name);
74
75         /** returns the name of this clip. */
76     const QString & name() const;
77
78         /** Sets the description for this clip. */
79     void setDescription(const QString & descripton);
80
81         /** Returns the description of this clip. */
82     const QString & description() const;
83
84     /** Returns the internal unique id of the clip. */
85     uint getId() const;
86     void setId( const uint &newId);
87
88     //KThumb *thumbCreator;
89     bool audioThumbCreated;
90     
91         /** returns the duration of this clip */
92     virtual const GenTime & duration() const = 0;
93
94         /** returns clip type (audio, text, image,...) */
95     virtual const DocClipBase::CLIPTYPE & clipType() const = 0;
96
97         /** remove tmp file if the clip has one (for example text clips) */
98     virtual void removeTmpFile() const = 0;
99
100         /** Returns a url to a file describing this clip. Exactly what this url is,
101         whether it is temporary or not, and whether it provokes a render will
102         depend entirely on what the clip consists of. */
103     virtual const KUrl & fileURL() const = 0;
104
105         /** Returns true if the clip duration is known, false otherwise. */
106     virtual bool durationKnown() const = 0;
107     // Returns the number of frames per second that this clip should play at.
108     virtual double framesPerSecond() const = 0;
109
110     virtual bool isDocClipAVFile() const {
111         return false;
112     } 
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     virtual 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     virtual QDomDocument sceneToXML(const GenTime & startTime,
146         const GenTime & endTime) const = 0;
147         /** returns a QString containing all of the XML data required to recreate this clip. */
148     virtual QDomDocument toXML() const;
149     virtual QDomDocument generateSceneList(bool addProducers = true, bool rendering = false) const;
150
151         /** Returns true if the xml passed matches the values in this clip */
152     virtual bool matchesXML(const QDomElement & element) const = 0;
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         virtual bool hasFileSize() const = 0;
165
166         /** Returns the filesize, or 0 if there is no appropriate filesize. */
167     virtual uint fileSize() const = 0;
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     virtual bool referencesClip(DocClipBase * clip) const = 0;
172
173         /** Sets the thumbnail to be used by this clip */
174     void setThumbnail(const QPixmap & pixmap);
175
176         /** Returns the thumbnail used by this clip */
177     const QPixmap & thumbnail() const;
178
179     static DocClipBase *createClip(KdenliveDoc *doc, const QDomElement & element);
180     /** Cache for every audio Frame with 10 Bytes */
181     /** format is frame -> channel ->bytes */
182     QMap<int,QMap<int,QByteArray> > audioFrameChache;
183
184         /** return english name for clip type */
185     static QString getTypeName(CLIPTYPE type);
186
187   private:                      // Private attributes
188         /** The name of this clip */
189     QString m_name;
190         /** A description of this clip */
191     QString m_description;
192         /** The number of times this clip is used in the project - the number of references to this clip
193          * that exist. */
194     uint m_refcount;
195
196         /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
197     QList < CommentedTime > m_snapMarkers;
198
199
200         /** A thumbnail for this clip */
201     QPixmap m_thumbnail;
202     
203     /** a unique numeric id */
204     uint m_id;
205     uint m_projectThumbFrame;
206     void setAudioThumbCreated(bool isDone);
207
208   public slots:
209         void updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data);
210         QList < CommentedTime > commentedSnapMarkers() const;
211         void setSnapMarkers(QList < CommentedTime > markers);
212         GenTime findNextSnapMarker(const GenTime & currTime);
213         GenTime findPreviousSnapMarker(const GenTime & currTime);
214         GenTime hasSnapMarkers(const GenTime & time);
215         QString deleteSnapMarker(const GenTime & time);
216         void editSnapMarker(const GenTime & time, QString comment);
217         void addSnapMarker(const GenTime & time, QString comment);
218         QList < GenTime > snapMarkers() const;
219         QString markerComment(GenTime t);
220         void setProjectThumbFrame( const uint &ix);
221         uint getProjectThumbFrame() const;
222 };
223
224 #endif