Warning, file /multimedia/kdenlive/src/definitions.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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