Clip.h 6.07 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
 *
 * 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__

luyikei's avatar
luyikei committed
31
#include "Workflow/Helper.h"
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;
luyikei's avatar
luyikei committed
38
class   ClipWorkflow;
39

luyikei's avatar
luyikei committed
40
class   Clip : public Workflow::Helper
41 42 43 44
{
    Q_OBJECT

    public:
luyikei's avatar
luyikei committed
45 46 47 48 49 50 51 52
        enum    Format
        {
            None          = 0,
            Audio         = 1 << 0,
            Video         = 1 << 1,
        };
        Q_DECLARE_FLAGS( Formats, Format )

53
        static const int DefaultFPS;
54 55 56 57 58 59 60 61 62
        /**
         *  \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
63
        Clip( Media *parent, qint64 begin = 0, qint64 end = -1, const QString &uuid = QString() );
64 65 66 67 68 69 70 71 72
        /**
         *  \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
73
        Clip( Clip *creator, qint64 begin = -1, qint64 end = -1, const QString& uuid = QString() );
74
        virtual ~Clip();
75

76
        /**
77
            \return         Returns the clip length in seconds.
78
        */
79
        qint64              lengthSecond() const;
80

81
        /**
82
            \return         Returns the Media that the clip was basep uppon.
83
        */
luyikei's avatar
luyikei committed
84 85
        Media*              media();
        const Media*        media() const;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
86

luyikei's avatar
luyikei committed
87 88
        Clip                *parent();
        const Clip          *parent() const;
89 90
        MediaContainer*     mediaContainer();
        const MediaContainer*     mediaContainer() const;
91 92

        /**
93 94
            \brief          Returns an unique Uuid for this clip (which is NOT the
                            parent's Uuid).
95

96
            \return         The Clip's Uuid as a QUuid
97
        */
98
        const QUuid         &uuid() const;
99
        void                setUuid( const QUuid &uuid );
100

101 102 103
        const QStringList   &metaTags() const;
        void                setMetaTags( const QStringList &tags );
        bool                matchMetaTag( const QString &tag ) const;
104

105 106
        const QString       &notes() const;
        void                setNotes( const QString &notes );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
107

108
        void                computeLength();
109

110 111
        bool                isRootClip() const;
        Clip*               rootClip();
112

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
113 114 115 116 117
        /**
         *  \brief          Clear all the clip subclips recursively.
         */
        void                clear();

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

120 121 122 123 124
        /**
         *  \return         true if the clip is a child of the given clip uuid
         */
        bool                isChild( const QUuid& uuid ) const;

luyikei's avatar
luyikei committed
125 126 127
        QVariant            toVariant() const;
        QVariant            toVariantFull() const;

luyikei's avatar
luyikei committed
128 129 130 131 132 133
        Formats             formats() const;
        void                setFormats( Formats formats );

        ClipWorkflow*       clipWorkflow() const;
        void                setClipWorkflow( ClipWorkflow* cw );

134
    private:
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
135
        Media               *m_media;
136 137 138 139 140 141 142 143
        /**
         *  \brief  This represents the beginning of the Clip in form of [0; 1] float
         */
        float              m_beginPosition;
        /**
         *  \brief  This represents the end of the Clip in form of [0;1] float
         */
        float              m_endPosition;
144 145 146

        /**
         *  \brief  The length in frames
luyikei's avatar
luyikei committed
147
         *     
148
         */
149
        qint64              m_nbFrames;
luyikei's avatar
luyikei committed
150

151 152 153
        /**
         *  \brief  The length in seconds (Be carreful, VLC uses MILLIseconds)
         */
154
        qint64              m_lengthSeconds;
luyikei's avatar
luyikei committed
155

156 157
        QStringList         m_metaTags;
        QString             m_notes;
158

159 160 161 162 163 164 165
        /**
         *  \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
166 167 168 169
        MediaContainer*     m_childs;

        Clip*               m_parent;

luyikei's avatar
luyikei committed
170 171 172 173
        Formats             m_formats;

        ClipWorkflow*       m_clipWorkflow;

174
    private slots:
175
        void                mediaMetadataUpdated();
176

177
    signals:
178 179 180 181
        /**
         *  \brief          Act just like QObject::destroyed(), but before the clip deletion.
         */
        void                unloaded( Clip* );
182 183
};

luyikei's avatar
luyikei committed
184 185
Q_DECLARE_OPERATORS_FOR_FLAGS( Clip::Formats )

186
#endif //CLIP_H__