SequenceWorkflow.h 5.15 KB
Newer Older
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*****************************************************************************
 * SequenceWorkflow.h : Manages tracks in a single sequence
 *****************************************************************************
 * Copyright (C) 2008-2016 VideoLAN
 *
 * Authors: Yikei Lu    <luyikei.qmltu@gmail.com>
 *
 * 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.
 *****************************************************************************/

#ifndef SEQUENCEWORKFLOW_H
#define SEQUENCEWORKFLOW_H

#include <memory>
#include <tuple>

#include <QUuid>
#include <QMap>

#include "Media/Clip.h"
#include "Types.h"

namespace Backend
{
class IMultiTrack;
class ITrack;
class IInput;
}

namespace ClipTupleIndex
{
    enum {
        Clip,
        TrackId,
        Position
    };
}

class SequenceWorkflow : public QObject
{
    Q_OBJECT

    public:
        SequenceWorkflow( size_t trackCount = 64 );
        ~SequenceWorkflow();

59
        struct ClipInstance
60
        {
61 62
            ClipInstance() = default;
            ClipInstance( QSharedPointer<::Clip> c, const QUuid& uuid, quint32 tId, qint64 p, bool isAudio );
63 64 65 66
            QSharedPointer<::Clip>  clip;
            QUuid                   uuid;
            quint32                 trackId;
            qint64                  pos;
67
            QVector<QUuid>          linkedClips;
68 69
            // true is this instance represents an audio track, false otherwise
            bool                    isAudio;
70 71 72 73 74 75 76 77 78 79 80

            ///
            /// \brief duplicateClipForResize   Duplicates the used clip for enabling it to be resize independently
            /// \param begin        The new begining for this clip
            /// \param end          The new end for this clip
            ///
            bool                    duplicateClipForResize( qint64 begin, qint64 end );

        private:
            // true if this instance now contains its own Clip
            bool                    m_hasClonedClip;
81 82 83 84 85 86 87 88 89 90 91 92 93
        };

        /**
         * @brief addClip   Adds a clip to the sequence workflow
         * @param clip      A library clip's UUID
         * @param trackId   The target track
         * @param pos       Clip's position in the track
         * @param uuid      The new clip instance UUID. If this is a default created UUID, a new UUID
         *                  will be generated.
         * @return          The given instance UUID, or the newly generated one, representing a new
         *                  clip instance in the sequence workflow.
         *                  This instance UUID must be used to manipulate this new clip instance
         */
94
        QUuid                   addClip( QSharedPointer<::Clip> clip, quint32 trackId, qint64 pos,
95
                                         const QUuid& uuid, bool isAudioClip );
96 97 98
        bool                    moveClip( const QUuid& uuid, quint32 trackId, qint64 pos );
        bool                    resizeClip( const QUuid& uuid, qint64 newBegin,
                                            qint64 newEnd, qint64 newPos );
99
        QSharedPointer<ClipInstance>    removeClip( const QUuid& uuid );
100 101 102 103 104 105 106
        bool                    linkClips( const QUuid& uuidA, const QUuid& uuidB );
        bool                    unlinkClips( const QUuid& uuidA, const QUuid& uuidB );

        QVariant                toVariant() const;
        void                    loadFromVariant( const QVariant& variant );
        void                    clear();

107
        QSharedPointer<ClipInstance>    clip( const QUuid& uuid );
108
        quint32                 trackId( const QUuid& uuid );
109
        qint64                  position( const QUuid& uuid );
110 111 112 113 114 115

        Backend::IInput*        input();
        Backend::IInput*        trackInput( quint32 trackId );

    private:

116
        inline std::shared_ptr<Backend::ITrack>         track( quint32 trackId, bool audio );
117

118
        QMap<QUuid, QSharedPointer<ClipInstance>>       m_clips;
119 120 121 122 123

        Backend::IMultiTrack*           m_multitrack;
        QList<std::shared_ptr<Backend::ITrack>>         m_tracks[Workflow::NbTrackType];
        QList<std::shared_ptr<Backend::IMultiTrack>>    m_multiTracks;
        const size_t                    m_trackCount;
124 125 126

    signals:
        void                    clipAdded( QString );
127
        void                    clipRemoved( QString );
128
        void                    clipLinked( QString, QString );
129
        void                    clipUnlinked( QString, QString );
130
        void                    clipMoved( QString );
131
        void                    clipResized( QString );
132 133 134
};

#endif // SEQUENCEWORKFLOW_H