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