File indexing completed on 2024-04-21 04:52:34

0001 /*
0002     SPDX-FileCopyrightText: 2007 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "utils/gentime.h"
0010 
0011 #include "kdenlive_debug.h"
0012 
0013 #include <QDomElement>
0014 #include <QHash>
0015 #include <QPersistentModelIndex>
0016 #include <QString>
0017 #include <QUuid>
0018 #include <cassert>
0019 #include <memory>
0020 
0021 const int MAXCLIPDURATION = 15000;
0022 
0023 namespace Kdenlive {
0024 
0025 enum MonitorId { NoMonitor = 0x01, ClipMonitor = 0x02, ProjectMonitor = 0x04, RecordMonitor = 0x08, StopMotionMonitor = 0x10, RenderMonitor = 0x20 };
0026 enum ConfigPage {
0027     PageMisc = 0,
0028     PageEnv,
0029     PageTimeline,
0030     PageTools,
0031     PageCapture,
0032     PageJogShuttle,
0033     PagePlayback,
0034     PageTranscode,
0035     PageProjectDefaults,
0036     PageColorsGuides,
0037     PageSpeech,
0038     NoPage
0039 };
0040 
0041 const int DefaultThumbHeight = 100;
0042 } // namespace Kdenlive
0043 
0044 enum class GroupType {
0045     Normal,
0046     Selection, // in that case, the group is used to emulate a selection
0047     AVSplit,   // in that case, the group links the audio and video of the same clip
0048     Leaf       // This is a leaf (clip or composition)
0049 };
0050 
0051 const QString groupTypeToStr(GroupType t);
0052 GroupType groupTypeFromStr(const QString &s);
0053 
0054 // We can not use just ObjectType as name because that causes conflicts with Xcode on macOS
0055 enum class KdenliveObjectType { TimelineClip, TimelineComposition, TimelineTrack, TimelineMix, TimelineSubtitle, BinClip, Master, NoItem };
0056 // using ObjectId = std::pair<ObjectType, std::pair<int, QUuid>>;
0057 struct ObjectId
0058 {
0059     KdenliveObjectType type;
0060     int itemId;
0061     QUuid uuid;
0062     explicit constexpr ObjectId(const KdenliveObjectType tp = KdenliveObjectType::NoItem, int id = -1, const QUuid uid = QUuid())
0063         : type(tp)
0064         , itemId(id)
0065         , uuid(uid)
0066     {
0067     }
0068     /*inline ObjectId &operator=(const ObjectId &a)
0069     {
0070         type = a.type;
0071         itemId = a.itemId;
0072         uuid = a.uuid;
0073         return *this;
0074     }*/
0075     inline bool operator==(const ObjectId &a) const
0076     {
0077         if (a.type == type && a.itemId == itemId && a.uuid == uuid)
0078             return true;
0079         else
0080             return false;
0081     }
0082     inline bool operator!=(const ObjectId &a) const
0083     {
0084         if (a.type != type || a.itemId != itemId || a.uuid != uuid)
0085             return true;
0086         else
0087             return false;
0088     }
0089 };
0090 
0091 enum class MixAlignment { AlignNone, AlignLeft, AlignRight, AlignCenter };
0092 
0093 enum OperationType {
0094     None = 0,
0095     WaitingForConfirm,
0096     MoveOperation,
0097     ResizeStart,
0098     ResizeEnd,
0099     RollingStart,
0100     RollingEnd,
0101     RippleStart,
0102     RippleEnd,
0103     FadeIn,
0104     FadeOut,
0105     TransitionStart,
0106     TransitionEnd,
0107     MoveGuide,
0108     KeyFrame,
0109     Seek,
0110     Spacer,
0111     RubberSelection,
0112     ScrollTimeline,
0113     ZoomTimeline
0114 };
0115 
0116 namespace PlaylistState {
0117 Q_NAMESPACE
0118 enum ClipState { VideoOnly = 1, AudioOnly = 2, Disabled = 3, Unknown = 4 };
0119 Q_ENUM_NS(ClipState)
0120 } // namespace PlaylistState
0121 
0122 namespace FileStatus {
0123 Q_NAMESPACE
0124 enum ClipStatus { StatusReady = 0, StatusProxy, StatusMissing, StatusWaiting, StatusDeleting, StatusProxyOnly };
0125 Q_ENUM_NS(ClipStatus)
0126 } // namespace PlaylistState
0127 
0128 // returns a pair corresponding to (video, audio)
0129 std::pair<bool, bool> stateToBool(PlaylistState::ClipState state);
0130 PlaylistState::ClipState stateFromBool(std::pair<bool, bool> av);
0131 
0132 namespace TimelineMode {
0133 enum EditMode { NormalEdit = 0, OverwriteEdit = 1, InsertEdit = 2 };
0134 }
0135 
0136 namespace AssetListType {
0137 Q_NAMESPACE
0138 enum AssetType { Preferred, Video, Audio, Custom, CustomAudio, Template, TemplateAudio, Favorites, AudioComposition, VideoShortComposition, VideoComposition, AudioTransition, VideoTransition, Text, Hidden = -1 };
0139 Q_ENUM_NS(AssetType)
0140 }
0141 
0142 namespace ClipType {
0143 Q_NAMESPACE
0144 enum ProducerType {
0145     Unknown = 0,
0146     Audio = 1,
0147     Video = 2,
0148     AV = 3,
0149     Color = 4,
0150     Image = 5,
0151     Text = 6,
0152     SlideShow = 7,
0153     Virtual = 8,
0154     Playlist = 9,
0155     WebVfx = 10,
0156     TextTemplate = 11,
0157     QText = 12,
0158     Composition = 13,
0159     Track = 14,
0160     Qml = 15,
0161     Animation = 16,
0162     Timeline = 17
0163 };
0164 Q_ENUM_NS(ProducerType)
0165 } // namespace ClipType
0166 
0167 enum ProjectItemType { ProjectClipType = 0, ProjectFolderType, ProjectSubclipType };
0168 
0169 enum GraphicsRectItem { AVWidget = 70000, LabelWidget, TransitionWidget, GroupWidget };
0170 
0171 namespace ToolType {
0172 Q_NAMESPACE
0173 enum ProjectTool {
0174     SelectTool = 0,
0175     RazorTool = 1,
0176     SpacerTool = 2,
0177     RippleTool = 3,
0178     RollTool = 4,
0179     SlipTool = 5,
0180     SlideTool = 6,
0181     MulticamTool = 7
0182 };
0183 Q_ENUM_NS(ProjectTool)
0184 }
0185 
0186 enum MonitorSceneType {
0187     MonitorSceneNone = 0,
0188     MonitorSceneDefault,
0189     MonitorSceneGeometry,
0190     MonitorSceneCorners,
0191     MonitorSceneRoto,
0192     MonitorSceneSplit,
0193     MonitorSceneTrimming,
0194     MonitorSplitTrack
0195 };
0196 
0197 enum MessageType { DefaultMessage, ProcessingJobMessage, OperationCompletedMessage, InformationMessage, ErrorMessage, MltError, TooltipMessage };
0198 
0199 namespace BinMessage {
0200 enum BinCategory { NoMessage = 0, ProfileMessage, StreamsMessage, InformationMessage, UpdateMessage };
0201 }
0202 
0203 enum TrackType { AudioTrack = 0, VideoTrack = 1, AnyTrack = 2, SubtitleTrack = 3 };
0204 
0205 enum CacheType {
0206     SystemCacheRoot = -1,
0207     CacheRoot = 0,
0208     CacheBase = 1,
0209     CachePreview = 2,
0210     CacheProxy = 3,
0211     CacheAudio = 4,
0212     CacheThumbs = 5,
0213     CacheSequence = 6,
0214     CacheTmpWorkFiles = 7
0215 };
0216 
0217 enum TrimMode { NormalTrim, RippleTrim, RollingTrim, SlipTrim, SlideTrim };
0218 
0219 class TrackInfo
0220 {
0221 
0222 public:
0223     TrackType type;
0224     QString trackName;
0225     bool isMute;
0226     bool isBlind;
0227     bool isLocked;
0228     int duration;
0229     /*EffectsList effectsList;
0230     TrackInfo()
0231         : type(VideoTrack)
0232         , isMute(0)
0233         , isBlind(0)
0234         , isLocked(0)
0235         , duration(0)
0236         , effectsList(true)
0237     {
0238     }*/
0239 };
0240 
0241 struct requestClipInfo
0242 {
0243     QDomElement xml;
0244     QString clipId;
0245     int imageHeight;
0246     bool replaceProducer;
0247 
0248     bool operator==(const requestClipInfo &a) const { return clipId == a.clipId; }
0249 };
0250 
0251 typedef QMap<QString, QString> stringMap;
0252 typedef QMap<int, QMap<int, QByteArray>> audioByteArray;
0253 using audioShortVector = QVector<qint16>;
0254 
0255 class ItemInfo
0256 {
0257 public:
0258     /** startPos is the position where the clip starts on the track */
0259     GenTime startPos;
0260     /** endPos is the duration where the clip ends on the track */
0261     GenTime endPos;
0262     /** cropStart is the position where the sub-clip starts, relative to the clip's 0 position */
0263     GenTime cropStart;
0264     /** cropDuration is the duration of the clip */
0265     GenTime cropDuration;
0266     /** Track number */
0267     int track{0};
0268     ItemInfo() = default;
0269     bool isValid() const { return startPos != endPos; }
0270     bool contains(GenTime pos) const
0271     {
0272         if (startPos == endPos) {
0273             return true;
0274         }
0275         return (pos <= endPos && pos >= startPos);
0276     }
0277     bool operator==(const ItemInfo &a) const { return startPos == a.startPos && endPos == a.endPos && track == a.track && cropStart == a.cropStart; }
0278 };
0279 
0280 class TransitionInfo
0281 {
0282 public:
0283     /** startPos is the position where the clip starts on the track */
0284     GenTime startPos;
0285     /** endPos is the duration where the clip ends on the track */
0286     GenTime endPos;
0287     /** the track on which the transition is (b_track)*/
0288     int b_track{0};
0289     /** the track on which the transition is applied (a_track)*/
0290     int a_track{0};
0291     /** Does the user request for a special a_track */
0292     bool forceTrack{false};
0293     TransitionInfo() = default;
0294 };
0295 
0296 class CommentedTime
0297 {
0298 public:
0299     CommentedTime();
0300     CommentedTime(const GenTime &time, QString comment, int markerType = 0);
0301     CommentedTime(const QString &hash, const GenTime &time);
0302 
0303     QString comment() const;
0304     GenTime time() const;
0305     /** @brief Returns a string containing infos needed to store marker info. string equals marker type + QLatin1Char(':') + marker comment */
0306     QString hash() const;
0307     void setComment(const QString &comm);
0308     void setTime(const GenTime &t);
0309     void setMarkerType(int t);
0310     int markerType() const;
0311 
0312     /* Implementation of > operator; Works identically as with basic types. */
0313     bool operator>(const CommentedTime &op) const;
0314     /* Implementation of < operator; Works identically as with basic types. */
0315     bool operator<(const CommentedTime &op) const;
0316     /* Implementation of >= operator; Works identically as with basic types. */
0317     bool operator>=(const CommentedTime &op) const;
0318     /* Implementation of <= operator; Works identically as with basic types. */
0319     bool operator<=(const CommentedTime &op) const;
0320     /* Implementation of == operator; Works identically as with basic types. */
0321     bool operator==(const CommentedTime &op) const;
0322     /* Implementation of != operator; Works identically as with basic types. */
0323     bool operator!=(const CommentedTime &op) const;
0324 
0325 private:
0326     GenTime m_time;
0327     QString m_comment;
0328     int m_type{0};
0329 };
0330 
0331 class SubtitledTime
0332 {
0333 public:
0334     SubtitledTime();
0335     SubtitledTime(const GenTime &start, QString sub, const GenTime &end);
0336     
0337     QString subtitle() const;
0338     GenTime start() const;
0339     GenTime end() const;
0340     
0341     void setSubtitle(const QString &sub);
0342     void setEndTime(const GenTime &end);
0343     
0344     /* Implementation of > operator; Works identically as with basic types. */
0345     bool operator>(const SubtitledTime &op) const;
0346     /* Implementation of < operator; Works identically as with basic types. */
0347     bool operator<(const SubtitledTime &op) const;
0348     /* Implementation of == operator; Works identically as with basic types. */
0349     bool operator==(const SubtitledTime &op) const;
0350     /* Implementation of != operator; Works identically as with basic types. */
0351     bool operator!=(const SubtitledTime &op) const;
0352     
0353 private:
0354     GenTime m_starttime;
0355     QString m_subtitle;
0356     GenTime m_endtime;
0357 };
0358 
0359 QDebug operator<<(QDebug qd, const ItemInfo &info);
0360 
0361 // we provide hash function for qstring and QPersistentModelIndex
0362 namespace std {
0363 template <> struct hash<QPersistentModelIndex>
0364 {
0365     std::size_t operator()(const QPersistentModelIndex &k) const { return qHash(k); }
0366 };
0367 } // namespace std
0368 
0369 // The following is a hack that allows one to use shared_from_this in the case of a multiple inheritance.
0370 // Credit: https://stackoverflow.com/questions/14939190/boost-shared-from-this-and-multiple-inheritance
0371 template <typename T> struct enable_shared_from_this_virtual;
0372 
0373 class enable_shared_from_this_virtual_base : public std::enable_shared_from_this<enable_shared_from_this_virtual_base>
0374 {
0375     using base_type = std::enable_shared_from_this<enable_shared_from_this_virtual_base>;
0376     template <typename T> friend struct enable_shared_from_this_virtual;
0377 
0378     std::shared_ptr<enable_shared_from_this_virtual_base> shared_from_this() { return base_type::shared_from_this(); }
0379     std::shared_ptr<enable_shared_from_this_virtual_base const> shared_from_this() const { return base_type::shared_from_this(); }
0380 };
0381 
0382 template <typename T> struct enable_shared_from_this_virtual : virtual enable_shared_from_this_virtual_base
0383 {
0384     using base_type = enable_shared_from_this_virtual_base;
0385 
0386 public:
0387     std::shared_ptr<T> shared_from_this()
0388     {
0389         std::shared_ptr<T> result(base_type::shared_from_this(), static_cast<T *>(this));
0390         return result;
0391     }
0392 
0393     std::shared_ptr<T const> shared_from_this() const
0394     {
0395         std::shared_ptr<T const> result(base_type::shared_from_this(), static_cast<T const *>(this));
0396         return result;
0397     }
0398 };
0399 
0400 // This is a small trick to have a QAbstractItemModel with shared_from_this enabled without multiple inheritance
0401 // Be careful, if you use this class, you have to make sure to init weak_this_ when you construct a shared_ptr to your object
0402 template <class T> class QAbstractItemModel_shared_from_this : public QAbstractItemModel
0403 {
0404 protected:
0405     QAbstractItemModel_shared_from_this()
0406         : QAbstractItemModel()
0407     {
0408     }
0409 
0410 public:
0411     std::shared_ptr<T> shared_from_this()
0412     {
0413         std::shared_ptr<T> p(weak_this_);
0414         assert(p.get() == this);
0415         return p;
0416     }
0417 
0418     std::shared_ptr<T const> shared_from_this() const
0419     {
0420         std::shared_ptr<T const> p(weak_this_);
0421         assert(p.get() == this);
0422         return p;
0423     }
0424 
0425 public: // actually private, but avoids compiler template friendship issues
0426     mutable std::weak_ptr<T> weak_this_;
0427 };