docclipbase.h 10 KB
Newer Older
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/***************************************************************************
                          docclipbase.h  -  description
                             -------------------
    begin                : Fri Apr 12 2002
    copyright            : (C) 2002 by Jason Wood
    email                : jasonwood@blueyonder.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DOCCLIPBASE_H
#define DOCCLIPBASE_H

/**DocClip is a class for the various types of clip
  *@author Jason Wood
  */

#include <qdom.h>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
26 27
#include <QPixmap>
#include <QObject>
Marco Gittler's avatar
Marco Gittler committed
28
#include <QTimer>
29 30
#include <QProcess>
#include <QFuture>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
31

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
32
#include <KUrl>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
33 34

#include "gentime.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
35
#include "definitions.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
36 37 38 39 40 41 42 43

/*
class DocTrackBase;
class DocClipAVFile;
class DocClipTextFile;
class DocClipVirtual;
class EffectDescriptionList;*/
class KdenliveDoc;
44 45
class KThumb;
class ClipManager;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
46

47 48
namespace Mlt
{
49 50
class Producer;
};
51

52 53 54 55 56
struct CutZoneInfo {
    QPoint zone;
    QString description;
};

57

58 59
class DocClipBase: public QObject
{
60 61
Q_OBJECT public:
    /** this enum determines the types of "feed" available within this clip. types must be non-exclusive
62
     * - e.g. if you can have audio and video separately, it should be possible to combin the two, as is
63 64 65
     *   done here. If a new clip type is added then it should be possible to combine it with both audio
     *   and video. */

66
    DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id);
67
//    DocClipBase & operator=(const DocClipBase & clip);
68 69 70
    virtual ~ DocClipBase();

    /** returns the name of this clip. */
71
    const QString name() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
72

73
    /** Returns the description of this clip. */
74
    const QString description() const;
75 76
    /** Does this clip need a transparent background (e.g. for titles). */
    bool isTransparent() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
77

78
    /** Returns any property of this clip. */
79
    const QString getProperty(const QString &prop) const;
80
    void setProperty(const QString &key, const QString &value);
81
    void clearProperty(const QString &key);
82

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
83
    /** Returns the internal unique id of the clip. */
84
    const QString &getId() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
85 86

    //KThumb *thumbCreator;
87
    bool audioThumbCreated() const;
88
    /*void getClipMainThumb();*/
89 90

    /** returns the duration of this clip */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
91
    const GenTime & duration() const;
92
    const GenTime maxDuration() const;
93
    /** returns the duration of this clip */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
94
    void setDuration(GenTime dur);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
95

96
    /** returns clip type (audio, text, image,...) */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
97
    const CLIPTYPE & clipType() const;
98
    /** set clip type (audio, text, image,...) */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
99
    void setClipType(CLIPTYPE type);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
100

101
    /** remove tmp file if the clip has one (for example text clips) */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
102
    void removeTmpFile() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
103

104 105 106
    /** Returns a url to a file describing this clip. Exactly what this url is,
    whether it is temporary or not, and whether it provokes a render will
    depend entirely on what the clip consists of. */
107
    KUrl fileURL() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
108

109
    /** Returns true if the clip duration is known, false otherwise. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
110
    bool durationKnown() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
111
    // Returns the number of frames per second that this clip should play at.
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
112
    double framesPerSecond() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
113

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
114
    bool isDocClipAVFile() const {
115 116 117
        return false;
    }

118
    /** Sets producers for the current clip (one for each track due to a limitation in MLT's track mixing */
119
    void setProducer(Mlt::Producer *producer, bool reset = false, bool readPropertiesFromProducer = false);
120
    /** Retrieve a producer for a track */
121
    Mlt::Producer *getProducer(int track = -1);
122
    /** Get a copy of the producer, for use in the clip monitor */
123
    Mlt::Producer *getCloneProducer();
124 125 126
    /** Retrieve the producer that shows only video */
    Mlt::Producer *videoProducer();
    /** Retrieve the producer that shows only audio */
127
    Mlt::Producer *audioProducer(int track);
128

129 130
    /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject,
     * where it returns true. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
131
    bool isProjectClip() const {
132
        return false;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
133 134
    }

135
    /** Reads in the element structure and creates a clip out of it.*/
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
136
    // Returns an XML document that describes part of the current scene.
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
137
    QDomDocument sceneToXML(const GenTime & startTime,
138 139
                            const GenTime & endTime) const;
    /** returns a QString containing all of the XML data required to recreate this clip. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
140
    QDomElement toXML() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
141

142
    /** Returns true if the xml passed matches the values in this clip */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
143
    bool matchesXML(const QDomElement & element) const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
144 145

    void addReference() {
146
        ++m_refcount;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
147 148
    }
    void removeReference() {
149
        --m_refcount;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
150 151
    }
    uint numReferences() const {
152
        return m_refcount;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
153
    }
154 155
    /** Returns true if this clip has a meaningful filesize. */
    bool hasFileSize() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
156

157
    /** Returns the filesize, or 0 if there is no appropriate filesize. */
158
    qulonglong fileSize() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
159

160 161
    /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if
     * it uses it as part of it's own composition. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
162
    bool referencesClip(DocClipBase * clip) const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
163

164
    /** Returns the thumbnail producer used by this clip */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
165 166
    KThumb *thumbProducer();

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
167 168
    /** Cache for every audio Frame with 10 Bytes */
    /** format is frame -> channel ->bytes */
169
    QMap<int, QMap<int, QByteArray> > m_audioFrameCache;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
170

171 172
    /** Free cache data */
    void slotClearAudioCache();
173
    QString getClipHash() const;
174
    void refreshThumbUrl();
175
    const char *producerProperty(const char *name) const;
176
    void setProducerProperty(const char *name, const char *data);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
177
    void resetProducerProperty(const char *name);
178
    void deleteProducers();
179

180 181 182 183 184
    /** Set default play zone for clip monitor */
    void setZone(QPoint zone);
    /** Get default play zone for clip monitor */
    QPoint zone() const;

185 186
    /** Returns true is clip is missing but user wants to keep it as placeholder */
    bool isPlaceHolder() const;
187
    void setValid();
188
    static QString getHash(const QString &path);
189

190
    void addCutZone(int in, int out, QString desc = QString());
191 192
    bool hasCutZone(QPoint p) const;
    void removeCutZone(int in, int out);
193 194
    QList <CutZoneInfo> cutZones() const;
    void updateCutZone(int oldin, int oldout, int in, int out, QString desc = QString());
195

196 197
    bool hasVideoCodec(const QString &codec) const;
    bool hasAudioCodec(const QString &codec) const;
198 199
    bool checkHash() const;
    void setPlaceHolder(bool place);
200
    QImage extractImage(int frame, int width, int height);
201
    void clearThumbProducer();
202
    void reloadThumbProducer();
203 204
    void cleanupProducers();
    bool isClean() const;
205
    bool getAudioThumbs();
206

207
private:   // Private attributes
208

209 210
    /** The number of times this clip is used in the project - the number of references to this clip
     * that exist. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
211
    uint m_refcount;
212
    QList <Mlt::Producer *> m_baseTrackProducers;
213
    QList <Mlt::Producer *> m_audioTrackProducers;
214
    QList <Mlt::Producer *> m_toDeleteProducers;
215
    Mlt::Producer *m_videoOnlyProducer;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
216 217
    CLIPTYPE m_clipType;

218
    /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
219
    QList < CommentedTime > m_snapMarkers;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
220
    GenTime m_duration;
221

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
222
    KThumb *m_thumbProd;
223
    bool m_audioThumbCreated;
224

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
225
    /** a unique numeric id */
226
    QString m_id;
227 228 229 230

    /** Wheter the clip is a placeholder (clip missing but user wants to see it) */
    bool m_placeHolder;

231
    QList <CutZoneInfo> m_cutZones;
232

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
233
    void setAudioThumbCreated(bool isDone);
234
    /** Holds clip infos like fps, size,... */
235
    QMap <QString, QString> m_properties;
236 237
    /** Holds clip metadata like author, copyright,... */
    QMap <QString, QString> m_metadata;
238 239 240
    
    /** Try to make sure we don't delete a producer while using it */
    QMutex m_producerMutex;
241
    QMutex m_replaceMutex;
242

243
    /** Create connections for audio thumbnails */
244
    void slotRefreshProducer();
245
    void setProducerProperty(const char *name, int data);
246
    void setProducerProperty(const char *name, double data);
247
    void getFileHash(const QString &url);
248 249
    /** @brief When duplicating a producer, make sure all manually set properties are passed to it. */
    void adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind);
250 251
    /** @brief Create another instance of a producer. */
    Mlt::Producer *cloneProducer(Mlt::Producer *source);
252

253
   
254
public slots:
255
    void updateAudioThumbnail(const audioByteArray& data);
256 257 258 259 260 261 262 263 264
    QList < CommentedTime > commentedSnapMarkers() const;
    GenTime findNextSnapMarker(const GenTime & currTime);
    GenTime findPreviousSnapMarker(const GenTime & currTime);
    GenTime hasSnapMarkers(const GenTime & time);
    QString deleteSnapMarker(const GenTime & time);
    void editSnapMarker(const GenTime & time, QString comment);
    void addSnapMarker(const GenTime & time, QString comment);
    QList < GenTime > snapMarkers() const;
    QString markerComment(GenTime t);
265 266
    void setClipThumbFrame(const uint &ix);
    uint getClipThumbFrame() const;
267
    void setProperties(QMap <QString, QString> properties);
268
    void setMetadata(QMap <QString, QString> properties);
269
    QMap <QString, QString> properties() const;
270
    QMap <QString, QString> metadata() const;
271
    void slotExtractImage(QList <int> frames);
272

273 274
signals:
    void gotAudioData();
275
    /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */
276
    void createProxy(const QString &id);
277
    /** @brief Abort creation of the proxy clip (lower resolution copy). */
278
    void abortProxy(const QString &id, const QString &proxyPath);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
279 280 281
};

#endif