Clip.h 6.3 KB
Newer Older
1
/*****************************************************************************
2
 * Clip.h : Represents a basic container for media informations.
3
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/** \file
  * This file contains the Clip class declaration/definition.
  * It's used by the timeline in order to represent a subset of a media
  */

#ifndef CLIP_H__
# define CLIP_H__

#include <QObject>
32
#include <QStringList>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
33
#include <QUuid>
34
#include <QXmlStreamWriter>
35

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
36
class   MediaContainer;
37
class   Media;
38

39
40
41
42
43
class   Clip : public QObject
{
    Q_OBJECT

    public:
44
        static const int DefaultFPS;
45
46
47
48
49
50
51
52
53
        /**
         *  \brief  Constructs a Clip that is a subpart of a Media.
         *
         *  \param  parent  The media to represent.
         *  \param  begin   The clip beginning (in frames, from the parent's beginning)
         *  \param  end     The end, in frames, from the parent's beginning. If not given,
         *                  the end of the parent will be used.
         *  \param  uuid    A unique identifier. If not given, one will be generated.
         */
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
54
        Clip( Media *parent, qint64 begin = 0, qint64 end = -1, const QString &uuid = QString() );
55
56
57
58
59
60
61
62
63
        /**
         *  \brief  Clones a Clip, potentially with a new begin and end.
         *
         *  \param  creator The clip to clone.
         *  \param  begin   The clip beginning (in frames, from the parent's beginning).
         *                  If not given, 0 is assumed.
         *  \param  end     The end, in frames, from the parent's beginning. If not given,
         *                  the end of the parent will be used.
         */
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
64
        Clip( Clip *creator, qint64 begin = -1, qint64 end = -1, const QString& uuid = QString() );
65
        virtual ~Clip();
66

67
68
69
70
71
72
73
        /**
         *  \return         The clip beginning, in frame, starting at 0
         */
        qint64              begin() const
        {
            return m_begin;
        }
74

75
76
77
78
79
80
81
        /**
         *  \return         The clip end, in frame, starting at 0.
         */
        qint64              end() const
        {
            return m_end;
        }
82

83
        /**
84
            \return         Returns the clip length in frame.
85
        */
86
        qint64              nbFrames() const;
87

88
        /**
89
            \return         Returns the clip length in seconds.
90
        */
91
        qint64              lengthSecond() const;
92

93
        /**
94
            \return         Returns the Media that the clip was basep uppon.
95
        */
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
96
        Media*              getMedia();
97
        const Media*        getMedia() const;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
98
99
100
101
102

        Clip                *getParent();
        const Clip          *getParent() const;
        MediaContainer*     getChilds();
        const MediaContainer*     getChilds() const;
103
104

        /**
105
106
            \brief          Returns an unique Uuid for this clip (which is NOT the
                            parent's Uuid).
107

108
            \return         The Clip's Uuid as a QUuid
109
        */
110
        const QUuid         &uuid() const;
111
        void                setUuid( const QUuid &uuid );
112

113
114
115
        const QStringList   &metaTags() const;
        void                setMetaTags( const QStringList &tags );
        bool                matchMetaTag( const QString &tag ) const;
116

117
118
        const QString       &notes() const;
        void                setNotes( const QString &notes );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
119

120
        void                computeLength();
121

122
123
        bool                isRootClip() const;
        Clip*               rootClip();
124

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
125
126
127
128
129
        /**
         *  \brief          Clear all the clip subclips recursively.
         */
        void                clear();

130
        bool                addSubclip( Clip* clip );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
131

132
133
134
135
136
        /**
         *  \return         true if the clip is a child of the given clip uuid
         */
        bool                isChild( const QUuid& uuid ) const;

luyikei's avatar
luyikei committed
137
138
139
        QVariant            toVariant() const;
        QVariant            toVariantFull() const;

140
    private:
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
141
        Media               *m_media;
142
143
144
145
        /**
         *  \brief  This represents the beginning of the Clip in frames, from the
         *          beginning of the parent Media.
         */
146
        qint64              m_begin;
147
148
149
150
        /**
         *  \brief  This represents the end of the Clip in frames, from the
         *          beginning of the parent Media.
         */
151
        qint64              m_end;
152
153
154
155

        /**
         *  \brief  The length in frames
         */
156
        qint64              m_nbFrames;
157
158
159
        /**
         *  \brief  The length in seconds (Be carreful, VLC uses MILLIseconds)
         */
160
        qint64              m_lengthSeconds;
161
162
163
164
165
        /**
         *  The Clip's timeline UUID. Used to identify the Clip in the
         *  timeline, as a unique object, even if this clip is present more than
         *  once.
         */
166
        QUuid               m_uuid;
167
168
        QStringList         m_metaTags;
        QString             m_notes;
169

170
171
172
173
174
175
176
        /**
         *  \brief          Return the root clip.
         *
         *  The root clip is the base clip for the parent media.
         */
        Clip*               m_rootClip;

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
177
178
179
180
        MediaContainer*     m_childs;

        Clip*               m_parent;

181
    private slots:
182
        void                mediaMetadataUpdated();
183

184
    signals:
185
186
187
188
        /**
         *  \brief          Act just like QObject::destroyed(), but before the clip deletion.
         */
        void                unloaded( Clip* );
189
190

        friend class    ClipHelper;
191
192
193
};

#endif //CLIP_H__