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