MainWorkflow.h 8.9 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * MainWorkflow.h : Will query all of the track workflows to render the final
 *                  image
 *****************************************************************************
5
 * Copyright (C) 2008-2016 VideoLAN
6
 *
7 8
 * Authors: Yikei Lu    <luyikei.qmltu@gmail.com>
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * 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 MAINWORKFLOW_H
#define MAINWORKFLOW_H

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include "Types.h"
33
#include <QJsonObject>
34

35 36
#include <memory>

37
class   Clip;
38
class   EffectsEngine;
39
class   Effect;
40
class   AbstractRenderer;
41
class   SequenceWorkflow;
42

43 44 45 46 47 48
namespace Commands
{
class AbstractUndoStack;
class Generic;
}

49 50
namespace Backend
{
luyikei's avatar
luyikei committed
51
class IMultiTrack;
luyikei's avatar
luyikei committed
52
class IInput;
53 54
}

55
class   Settings;
56

57 58
#include <QObject>
#include <QUuid>
59
#include <QMap>
60

61 62 63
/**
 *  \class  Represent the Timeline backend.
 */
luyikei's avatar
luyikei committed
64
class   MainWorkflow : public QObject
65 66 67 68
{
    Q_OBJECT

    public:
69
        MainWorkflow( Settings* projectSettings, int trackCount = 64 );
70 71
        ~MainWorkflow();

72 73 74 75 76 77 78
        /**
         *  \brief      Mute a track.
         *
         *  A muted track will not be asked for render. It won't even emit endReached
         *  signal. To summerize, a mutted track is an hard deactivated track.
         *  \param  trackId     The id of the track to mute
         *  \param  trackType   The type of the track to mute.
79
         *  \sa     unmuteTrack( unsigned int, Workflow::TrackType );
80
         */
81
        void                    muteTrack( unsigned int trackId, Workflow::TrackType trackType );
82 83 84 85 86
        /**
         *  \brief      Unmute a track.
         *
         *  \param  trackId     The id of the track to unmute
         *  \param  trackType   The type of the track to unmute.
87
         *  \sa     muteTrack( unsigned int, Workflow::TrackType );
88
         */
89
        void                    unmuteTrack( unsigned int trackId, Workflow::TrackType trackType );
90

91 92 93 94 95 96 97
        /**
         *  \brief      Mute a clip.
         *
         *  \param  uuid        The clip's uuid.
         *  \param  trackId     The id of the track containing the clip.
         *  \param  trackType   The type of the track containing the clip.
         */
98
        void                    muteClip( const QUuid& uuid, unsigned int trackId );
99 100 101 102 103 104 105 106

        /**
         *  \brief      Unmute a clip.
         *
         *  \param  uuid        The clip's uuid.
         *  \param  trackId     The id of the track containing the clip.
         *  \param  trackType   The type of the track containing the clip.
         */
107
        void                    unmuteClip( const QUuid& uuid, unsigned int trackId );
108

109 110 111 112 113 114
        /**
         *  \brief              Get the number of track for a specific type
         *
         *  \param  trackType   The type of the tracks to count
         *  \return             The number of track for the type trackType
         */
115
        int                     getTrackCount() const;
116

117 118 119 120 121
        /**
         * \brief   Return the number of track for each track type.
         */
        quint32                 trackCount() const;

luyikei's avatar
luyikei committed
122
        Q_INVOKABLE
123
        void                    addClip( const QString& uuid, quint32 trackId, qint32 pos );
luyikei's avatar
luyikei committed
124 125 126 127

        Q_INVOKABLE
        QJsonObject             clipInfo( const QString& uuid );

128 129 130
        Q_INVOKABLE
        QJsonObject             libraryClipInfo( const QString& uuid );

131
        Q_INVOKABLE
132
        void                    moveClip( const QString& uuid, quint32 trackId, qint64 startFrame );
133

134 135 136 137
        Q_INVOKABLE
        void                    resizeClip( const QString& uuid, qint64 newBegin,
                                            qint64 newEnd, qint64 newPos );

138 139 140
        Q_INVOKABLE
        void                    removeClip( const QString& uuid );

luyikei's avatar
luyikei committed
141 142 143
        Q_INVOKABLE
        void                    splitClip( const QUuid& uuid, qint64 newClipPos, qint64 newClipBegin );

144 145 146
        Q_INVOKABLE
        void                    linkClips( const QString& uuidA, const QString& uuidB );

147 148 149
        Q_INVOKABLE
        void                    unlinkClips( const QString& uuidA, const QString& uuidB );

luyikei's avatar
luyikei committed
150 151 152
        Q_INVOKABLE
        QString                 addEffect( const QString& clipUuid, const QString& effectId );

luyikei's avatar
luyikei committed
153 154 155 156 157 158
        bool                    startRenderToFile( const QString& outputFileName, quint32 width, quint32 height,
                                                   double fps, const QString& ar, quint32 vbitrate, quint32 abitrate,
                                                   quint32 nbChannels, quint32 sampleRate );

        bool                    canRender();

159 160
        void                    trigger( Commands::Generic* command );

161 162
        AbstractRenderer*       renderer();

163 164
        Commands::AbstractUndoStack*       undoStack();

165 166
    private:

167 168 169
        void                    preSave();
        void                    postLoad();

170
    private:
171
        const quint32                   m_trackCount;
172

173 174
        Settings*                       m_settings;

175 176
        AbstractRenderer*               m_renderer;

177
        std::unique_ptr<Commands::AbstractUndoStack> m_undoStack;
178
        std::shared_ptr<SequenceWorkflow>            m_sequenceWorkflow;
179
    public slots:
180 181 182 183 184 185
        /**
         *  \brief      Clear the workflow.
         *
         *  Calling this method will cause every clip workflow to be deleted, along with
         *  the associated Clip.
         *  This method will emit cleared() signal once finished.
186
         *  \sa     reCip( const QUuid&, unsigned int, Workflow::TrackType )
187 188
         *  \sa     cleared()
         */
189
        void                            clear();
190

191 192
        void                            setClean();

193 194
        void                            setPosition( qint64 newFrame );

195 196
        void                            setFps( double fps );

197 198 199
        // FIXME: We can't use #ifdef HAVE_GUI here because qml files can't find them
        //        You'll get:
        //        TypeError: Property 'showEffectStack' of object MainWorkflow is not a function
200
        void                            showEffectStack();
201 202 203
        void                            showEffectStack( quint32 trackId );
        void                            showEffectStack( const QString& uuid );

204
    signals:
205
        /**
206 207 208
         *  \brief      Used to notify a change to the timeline and preview widget cursor
         *
         *  \param      newFrame    The new rendered frame
209
         *  \param      length      The playable length
210
         *  \param      reason      The reason for clipanging frame. Usually, if emitted
211
         *                          from the MainWorkflow, this should be "Renderer"
212
         */
213
        void                    frameChanged( qint64 newFrame,
214
                                              qint64 length,
215
                                              Vlmc::FrameChangedReason reason );
216

217 218 219 220 221 222
        /**
         *  \brief  Emitted when workflow end is reached
         *
         *  Workflow end is reached when tracksEndReached() is called, and no more tracks
         *  are activated (ie. they all reached end)
         */
223
        void                    mainWorkflowEndReached();
224

225 226 227 228 229
        /**
         *  \brief  Emitted when the workflow is cleared.
         *
         *  \sa     clear();
         */
230
        void                    cleared();
231 232 233 234 235 236

        /**
         *  \brief  Emitted when the global length of the workflow changes.
         *
         *  \param  newLength   The new length, in frames
         */
237
        void                    lengthChanged( qint64 length );
238

239 240
        void                    fpsChanged( double fps );

241 242
        void                    cleanChanged( bool isClean );

243 244 245 246
        void                    clipAdded( const QString& uuid );
        void                    clipResized( const QString& uuid );
        void                    clipRemoved( const QString& uuid );
        void                    clipMoved( const QString& uuid );
247
        void                    clipLinked( const QString& uuidA, const QString& uuidB );
248
        void                    clipUnlinked( const QString& uuidA, const QString& uuidB );
249 250

        void                    effectsUpdated( const QString& clipUuid );
251 252 253
};

#endif // MAINWORKFLOW_H