File indexing completed on 2024-04-28 04:52:26
0001 /* 0002 SPDX-FileCopyrightText: 2017 Jean-Baptiste Mardelle 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #pragma once 0007 0008 #include "assets/model/assetparametermodel.hpp" 0009 #include "moveableItem.hpp" 0010 #include "undohelper.hpp" 0011 #include <memory> 0012 0013 namespace Mlt { 0014 class Transition; 0015 } 0016 class TimelineModel; 0017 class TrackModel; 0018 class KeyframeModel; 0019 0020 /** @brief This class represents a Composition object, as viewed by the backend. 0021 In general, the Gui associated with it will send modification queries (such as resize or move), and this class authorize them or not depending on the 0022 validity of the modifications 0023 */ 0024 class CompositionModel : public MoveableItem<Mlt::Transition>, public AssetParameterModel 0025 { 0026 CompositionModel() = delete; 0027 0028 protected: 0029 /** This constructor is not meant to be called, call the static construct instead */ 0030 CompositionModel(std::weak_ptr<TimelineModel> parent, std::unique_ptr<Mlt::Transition> transition, int id, const QDomElement &transitionXml, 0031 const QString &transitionId, const QString &originalDecimalPoint, const QUuid uuid = QUuid()); 0032 0033 public: 0034 /** @brief Creates a composition, which then registers itself to the parent timeline 0035 Returns the (unique) id of the created composition 0036 @param parent is a pointer to the timeline 0037 @param transitionId is the id of the transition to be inserted 0038 @param id Requested id of the clip. Automatic if -1 0039 */ 0040 static int construct(const std::weak_ptr<TimelineModel> &parent, const QString &transitionId, const QString &originalDecimalPoint, int length = 1, 0041 int id = -1, std::unique_ptr<Mlt::Properties> sourceProperties = nullptr); 0042 0043 friend class TrackModel; 0044 friend class TimelineModel; 0045 0046 /** @brief returns the length of the item on the timeline 0047 */ 0048 int getPlaytime() const override; 0049 0050 /** @brief Returns the id of the second track involved in the composition (a_track in mlt's vocabulary, the b_track being the track where the composition is 0051 inserted) 0052 */ 0053 int getATrack() const; 0054 /** @brief Defines the forced_track property. If true, the a_track will not change when composition 0055 * is moved to another track. When false, the a_track will automatically change to lower video track 0056 */ 0057 void setForceTrack(bool force); 0058 /** @brief Returns the id of the second track involved in the composition (a_track) or -1 if the a_track should be automatically updated when the 0059 * composition changes track 0060 */ 0061 int getForcedTrack() const; 0062 0063 /** @brief Sets the id of the second track involved in the composition*/ 0064 void setATrack(int trackMltPosition, int trackId); 0065 0066 /** @brief returns a property of the current item 0067 */ 0068 const QString getProperty(const QString &name) const override; 0069 0070 /** @brief returns the active effect's keyframe model 0071 */ 0072 KeyframeModel *getEffectKeyframeModel(); 0073 Q_INVOKABLE bool showKeyframes() const; 0074 Q_INVOKABLE void setShowKeyframes(bool show); 0075 const QString &displayName() const; 0076 Mlt::Properties *properties(); 0077 0078 /** @brief Returns an XML representation of the clip with its effects */ 0079 QDomElement toXml(QDomDocument &document); 0080 void setGrab(bool grab) override; 0081 void setSelected(bool sel) override; 0082 0083 protected: 0084 Mlt::Transition *service() const override; 0085 void setInOut(int in, int out) override; 0086 void setCurrentTrackId(int tid, bool finalMove = true) override; 0087 int getOut() const override; 0088 int getIn() const override; 0089 0090 /** @brief Performs a resize of the given composition. 0091 Returns true if the operation succeeded, and otherwise nothing is modified 0092 This method is protected because it shouldn't be called directly. Call the function in the timeline instead. 0093 If a snap point is within reach, the operation will be coerced to use it. 0094 @param size is the new size of the composition 0095 @param right is true if we change the right side of the composition, false otherwise 0096 @param undo Lambda function containing the current undo stack. Will be updated with current operation 0097 @param redo Lambda function containing the current redo queue. Will be updated with current operation 0098 */ 0099 bool requestResize(int size, bool right, Fun &undo, Fun &redo, bool logUndo = true, bool hasMix = false) override; 0100 0101 private: 0102 int m_a_track; 0103 QString m_compositionName; 0104 int m_duration; 0105 };