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