Clip.h 6.64 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
 *          Yikei Lu    <luyikei.qmltu@gmail.com>
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__

luyikei's avatar
luyikei committed
32
#include "Workflow/Helper.h"
33
#include <QHash>
34
#include <QSharedPointer>
35
#include <QStringList>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
36
#include <QUuid>
37
#include <QXmlStreamWriter>
luyikei's avatar
luyikei committed
38
#include "Backend/IInput.h"
39

40 41
#include <memory>

42
class   Media;
43

luyikei's avatar
luyikei committed
44
class   Clip : public Workflow::Helper
45 46 47 48
{
    Q_OBJECT

    public:
luyikei's avatar
luyikei committed
49 50 51 52 53 54 55 56
        enum    Format
        {
            None          = 0,
            Audio         = 1 << 0,
            Video         = 1 << 1,
        };
        Q_DECLARE_FLAGS( Formats, Format )

57
        static const int DefaultFPS;
58 59 60 61 62 63 64 65 66
        /**
         *  \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.
         */
67
        Clip( QSharedPointer<Media> parent, qint64 begin = 0, qint64 end = Backend::IInput::EndOfMedia, const QString &uuid = QStringLiteral() );
68 69 70 71 72 73 74 75 76
        /**
         *  \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.
         */
luyikei's avatar
luyikei committed
77
        Clip( Clip *creator, qint64 begin = -1, qint64 end = Backend::IInput::EndOfParent, const QString& uuid = QStringLiteral() );
78
        virtual ~Clip();
79

80
        /**
81
            \return         Returns the clip length in seconds.
82
        */
83
        qint64              lengthSecond() const;
84

85
        /**
86
            \return         Returns the Media that the clip was basep uppon.
87
        */
88 89
        QSharedPointer<Media>       media();
        QSharedPointer<const Media> media() const;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
90

luyikei's avatar
luyikei committed
91 92
        Clip                *parent();
        const Clip          *parent() const;
93

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

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

103 104 105 106 107 108 109
        virtual qint64      begin() const override;
        virtual qint64      end() const override;
        virtual void        setBegin( qint64 begin ) override;
        virtual void        setEnd( qint64 end ) override;
        virtual qint64      length() const override;
        virtual void        setBoundaries( qint64 begin, qint64 end ) override;

luyikei's avatar
luyikei committed
110 111 112 113 114 115
        void                setLinkedClipUuid( const QUuid& uuid );
        const QUuid&        linkedClipUuid() const;

        void                setLinked( bool isLinked );
        bool                isLinked() const;

116 117 118
        const QStringList   &metaTags() const;
        void                setMetaTags( const QStringList &tags );
        bool                matchMetaTag( const QString &tag ) const;
119

120 121
        const QString       &notes() const;
        void                setNotes( const QString &notes );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
122

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

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

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

luyikei's avatar
luyikei committed
133 134 135
        QVariant            toVariant() const;
        QVariant            toVariantFull() const;

luyikei's avatar
luyikei committed
136 137 138
        Formats             formats() const;
        void                setFormats( Formats formats );

luyikei's avatar
luyikei committed
139
        Backend::IInput* input();
luyikei's avatar
luyikei committed
140

141 142 143 144 145 146
        static Clip*        fromVariant( const QVariant& v );

    private:
        static Clip*        fromVariant( const QVariant& v, Clip* parent );
        void                loadVariant(const QVariantMap& v );

147
    private:
148 149
        QSharedPointer<Media>               m_media;
        std::unique_ptr<Backend::IInput>    m_input;
luyikei's avatar
luyikei committed
150

151 152
        QStringList         m_metaTags;
        QString             m_notes;
153

154 155 156 157 158 159 160
        /**
         *  \brief          Return the root clip.
         *
         *  The root clip is the base clip for the parent media.
         */
        Clip*               m_rootClip;

161
        QHash<QUuid, Clip*> m_subclips;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
162 163 164

        Clip*               m_parent;

luyikei's avatar
luyikei committed
165 166 167
        QUuid               m_linkedClipUuid;
        bool                m_isLinked;

luyikei's avatar
luyikei committed
168 169
        Formats             m_formats;

170
    signals:
171 172 173 174
        /**
         *  \brief          Act just like QObject::destroyed(), but before the clip deletion.
         */
        void                unloaded( Clip* );
175 176 177 178 179 180 181 182 183 184 185 186 187

        /**
         *  \brief          This signal should be emitted to tell a new sublip have been added
         *  \param Clip     The newly added subclip
         */
        void    subclipAdded( Clip* );
        /**
         *  \brief This signal should be emiteted when a subclip has been removed
         *  This signal pass a QUuid as the clip may be deleted when the signal reaches its
         *  slot.
         *  \param uuid The removed clip uuid
         */
        void    subclipRemoved( const QUuid& );
188 189
};

luyikei's avatar
luyikei committed
190 191
Q_DECLARE_OPERATORS_FOR_FLAGS( Clip::Formats )

192
#endif //CLIP_H__