Commands.h 11.7 KB
Newer Older
1 2 3
/*****************************************************************************
 * Commands.h: Contains all the implementation of VLMC commands.
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7
 *          Ludovic Fauvet <etix@l0cal.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 *****************************************************************************/

24 25
#ifndef COMMANDS_H
#define COMMANDS_H
26

27
#include "config.h"
28
#include "Workflow/SequenceWorkflow.h"
29

30
#ifdef HAVE_GUI
31 32
# include <QUndoCommand>
#endif
33
#include <QObject>
34
#include <QUuid>
35 36
#include <QSharedPointer>

37 38
#include <memory>

39
class   Clip;
luyikei's avatar
luyikei committed
40 41 42

namespace Backend
{
luyikei's avatar
luyikei committed
43
class IInput;
luyikei's avatar
luyikei committed
44 45
}
class   EffectHelper;
46
class   MarkerManager;
47 48 49

namespace Commands
{
50 51 52 53

    enum class Id
    {
        Move,
54
        Resize,
55
        Remove,
56 57
    };

58
#ifdef HAVE_GUI
59
    class       Generic : public QObject, public QUndoCommand
60
#else
61
    class       Generic : public QObject
62 63
#endif
    {
64 65
        Q_OBJECT

66
        public:
67
            Generic();
68 69 70 71
            virtual void    internalRedo() = 0;
            virtual void    internalUndo() = 0;
            void            redo();
            void            undo();
72
            bool            isValid() const;
73
#ifndef HAVE_GUI
74 75 76
            void            setText( const QString& text ) ;
            QString         text() const;
#endif
77 78
        private:
            bool            m_valid;
79
            QString         m_text;
80
        protected slots:
81
            virtual void    retranslate() = 0;
82 83 84
            void            invalidate();
        signals:
            void            invalidated();
85 86
    };

87
    namespace   Clip
88
    {
89
        class   Add : public Generic
90 91
        {
            public:
92
                Add( std::shared_ptr<SequenceWorkflow> const& workflow, const QUuid& uuid, quint32 trackId, qint32 pos );
93 94
                virtual void    internalRedo();
                virtual void    internalUndo();
95
                virtual void    retranslate();
96

97
            private:
98
                std::shared_ptr<SequenceWorkflow> m_workflow;
99
                QUuid                       m_libraryUuid;
100 101
                QUuid                       m_audioInstanceUuid;
                QUuid                       m_videoInstanceUuid;
102
                quint32                     m_trackId;
103
                qint64                      m_pos;
104
        };
105

106
        class   Move : public Generic
107 108
        {
            public:
109
                Move( std::shared_ptr<SequenceWorkflow> const& workflow, const QString& uuid, quint32 trackId, qint64 pos );
110 111
                virtual void    internalRedo();
                virtual void    internalUndo();
112
                virtual void    retranslate();
113
                virtual int     id() const;
114
                virtual bool    mergeWith( const Generic* command );
115 116

            private:
117
                std::shared_ptr<SequenceWorkflow> m_workflow;
118 119 120 121 122 123 124 125 126
                struct Info
                {
                    QUuid           uuid;
                    quint32         newTrackId;
                    quint32         oldTrackId;
                    qint64          newPos;
                    qint64          oldPos;
                };
                QVector<Info>       m_infos;
127
        };
128

129
        class   Remove : public Generic
130 131
        {
            public:
132
                Remove( std::shared_ptr<SequenceWorkflow> const& workflow, const QUuid& uuid );
133 134
                virtual void internalRedo();
                virtual void internalUndo();
135
                virtual void    retranslate();
136
                virtual int     id() const;
137
                virtual bool    mergeWith( const Generic* command );
138 139

            private:
140
                std::shared_ptr<SequenceWorkflow>       m_workflow;
141
                QVector<QSharedPointer<SequenceWorkflow::ClipInstance>>     m_clips;
142
        };
143

144 145 146 147 148 149 150
        /**
         *  \brief  This command is used to resize a clip.
         *  \param  newBegin: The clip's new beginning
         *  \param  newEnd: The clip's new end
         *  \param  newPos: if the clip was resized from the beginning, it is moved
         *                  so we have to know its new position
        */
151
        class   Resize : public Generic
152 153
        {
            public:
154 155
                Resize( std::shared_ptr<SequenceWorkflow> const& workflow,
                        const QUuid& uuid, qint64 newBegin, qint64 newEnd, qint64 newPos );
156 157
                virtual void    internalRedo();
                virtual void    internalUndo();
158
                virtual void    retranslate();
159
                virtual bool    mergeWith( const Generic* cmd );
160
                virtual int     id() const;
161

162
            private:
163
                std::shared_ptr<SequenceWorkflow> m_workflow;
164 165 166 167 168 169 170 171 172 173 174
                struct Info
                {
                    QSharedPointer<SequenceWorkflow::ClipInstance>  clip;
                    qint64                      newBegin;
                    qint64                      oldBegin;
                    qint64                      newEnd;
                    qint64                      oldEnd;
                    qint64                      newPos;
                    qint64                      oldPos;
                };
                QVector<Info>                   m_infos;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
175
        };
176

177
        class   Split : public Generic
178 179
        {
            public:
180 181
                Split( std::shared_ptr<SequenceWorkflow> const& workflow,
                       const QUuid& uuid, qint64 newClipPos, qint64 newClipBegin );
182 183
                virtual void    internalRedo();
                virtual void    internalUndo();
184
                virtual void    retranslate();
185
            private:
186
                std::shared_ptr<SequenceWorkflow> m_workflow;
187
                QSharedPointer<SequenceWorkflow::ClipInstance>  m_toSplit;
188
                quint32                           m_trackId;
189
                QSharedPointer<::Clip>      m_newClip;
190
                QUuid                       m_newClipInstanceUuid;
191 192
                qint64                      m_newClipPos;
                qint64                      m_newClipBegin;
193
                qint64                      m_oldEnd;
194
        };
195 196 197 198

        class   Link : public Generic
        {
            public:
199 200
                Link( std::shared_ptr<SequenceWorkflow> const& workflow,
                      const QUuid& clipA, const QUuid& clipB );
201 202 203 204
                virtual void    internalRedo();
                virtual void    internalUndo();
                virtual void    retranslate();
            private:
205 206 207
                std::shared_ptr<SequenceWorkflow> m_workflow;
                QUuid     m_clipA;
                QUuid     m_clipB;
208
        };
209 210 211 212 213 214 215 216 217 218 219 220 221 222

        class   Unlink : public Generic
        {
            public:
                Unlink( std::shared_ptr<SequenceWorkflow> const& workflow,
                      const QUuid& clipA, const QUuid& clipB );
                virtual void    internalRedo();
                virtual void    internalUndo();
                virtual void    retranslate();
            private:
                std::shared_ptr<SequenceWorkflow> m_workflow;
                QUuid     m_clipA;
                QUuid     m_clipB;
        };
223
    }
224

225 226
    namespace   Effect
    {
227
        class   Add : public Generic
228 229
        {
            public:
luyikei's avatar
luyikei committed
230
                Add( std::shared_ptr<EffectHelper> const& helper, Backend::IInput* target );
231 232
                virtual void    internalRedo();
                virtual void    internalUndo();
233
                virtual void    retranslate();
234
            private:
235
                std::shared_ptr<EffectHelper>   m_helper;
luyikei's avatar
luyikei committed
236
                Backend::IInput*      m_target;
237 238
        };

239
        class   Move : public Generic
240 241
        {
            public:
luyikei's avatar
luyikei committed
242
                Move( std::shared_ptr<EffectHelper> const& helper, std::shared_ptr<Backend::IInput> const& from, Backend::IInput* to, qint64 pos );
243 244
                virtual void    internalRedo();
                virtual void    internalUndo();
245
                virtual void    retranslate();
246
            private:
luyikei's avatar
luyikei committed
247 248 249
                std::shared_ptr<EffectHelper>       m_helper;
                std::shared_ptr<Backend::IInput>    m_from;
                Backend::IInput      *m_to;
250 251
                qint64          m_oldPos;
                qint64          m_newPos;
252 253
                qint64          m_newEnd;
                qint64          m_oldEnd;
254
        };
255

256
        class   Resize : public Generic
257 258
        {
            public:
259
                Resize( std::shared_ptr<EffectHelper> const& helper, qint64 newBegin, qint64 newEnd );
260 261
                virtual void        internalRedo();
                virtual void        internalUndo();
262
                virtual void        retranslate();
263
            private:
264
                std::shared_ptr<EffectHelper>       m_helper;
265 266 267 268 269
                qint64              m_newBegin;
                qint64              m_newEnd;
                qint64              m_oldBegin;
                qint64              m_oldEnd;
        };
270

271
        class   Remove : public Generic
272 273
        {
            public:
274
                Remove( std::shared_ptr<EffectHelper> const& helper );
275 276
                virtual void    internalRedo();
                virtual void    internalUndo();
277
                virtual void    retranslate();
278
            private:
279
                std::shared_ptr<EffectHelper>       m_helper;
280
                std::shared_ptr<Backend::IInput>    m_target;
281
        };
282
    }
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

#ifdef HAVE_GUI
    // Gui commands
    namespace   Marker
    {
        class   Add : public Generic
        {
            public:
                // We use a raw pointer because it will only be accessed from Timeline itself.
                // Plus, Timeline is a QObject and has a parent so we don't worry about memory leak :)
                Add( QSharedPointer<MarkerManager> markerManager, quint64 pos );
                virtual void    internalRedo();
                virtual void    internalUndo();
                virtual void    retranslate();

            private:
                QSharedPointer<MarkerManager>   m_markerManager;
                quint64                         m_pos;
        };

        class   Move : public Generic
        {
            public:
                Move( QSharedPointer<MarkerManager> markerManager, quint64 oldPos, quint64 newPos );
                virtual void    internalRedo();
                virtual void    internalUndo();
                virtual void    retranslate();

            private:
                QSharedPointer<MarkerManager>   m_markerManager;
                quint64                         m_oldPos;
                quint64                         m_newPos;
        };

        class   Remove : public Generic
        {
            public:
                Remove( QSharedPointer<MarkerManager> markerManager, quint64 pos );
                virtual void    internalRedo();
                virtual void    internalUndo();
                virtual void    retranslate();

            private:
                QSharedPointer<MarkerManager>   m_markerManager;
                quint64                         m_pos;
        };
    }
#endif
331 332
}

333
#endif // COMMANDS_H