1 /* 2 SPDX-FileCopyrightText: 2007 Jean-Baptiste Mardelle <jb@kdenlive.org> 3 4 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 5 */ 6 7 #ifndef DEFINITIONS_H 8 #define DEFINITIONS_H 9 10 #include "gentime.h" 11 12 #include "kdenlive_debug.h" 13 14 #include <QDomElement> 15 #include <QHash> 16 #include <QPersistentModelIndex> 17 #include <QString> 18 #include <cassert> 19 #include <memory> 20 21 const int MAXCLIPDURATION = 15000; 22 23 namespace Kdenlive { 24 25 enum MonitorId { NoMonitor = 0x01, ClipMonitor = 0x02, ProjectMonitor = 0x04, RecordMonitor = 0x08, StopMotionMonitor = 0x10 }; 26 27 const int DefaultThumbHeight = 100; 28 } // namespace Kdenlive 29 30 enum class GroupType { 31 Normal, 32 Selection, // in that case, the group is used to emulate a selection 33 AVSplit, // in that case, the group links the audio and video of the same clip 34 Leaf // This is a leaf (clip or composition) 35 }; 36 37 const QString groupTypeToStr(GroupType t); 38 GroupType groupTypeFromStr(const QString &s); 39 40 enum class ObjectType { TimelineClip, TimelineComposition, TimelineTrack, TimelineMix, TimelineSubtitle, BinClip, Master, NoItem }; 41 using ObjectId = std::pair<ObjectType, int>; 42 43 enum class MixAlignment { AlignNone, AlignLeft, AlignRight, AlignCenter }; 44 45 enum OperationType { 46 None = 0, 47 WaitingForConfirm, 48 MoveOperation, 49 ResizeStart, 50 ResizeEnd, 51 RollingStart, 52 RollingEnd, 53 RippleStart, 54 RippleEnd, 55 FadeIn, 56 FadeOut, 57 TransitionStart, 58 TransitionEnd, 59 MoveGuide, 60 KeyFrame, 61 Seek, 62 Spacer, 63 RubberSelection, 64 ScrollTimeline, 65 ZoomTimeline 66 }; 67 68 namespace PlaylistState { 69 Q_NAMESPACE 70 enum ClipState { VideoOnly = 1, AudioOnly = 2, Disabled = 3, Unknown = 4 }; 71 Q_ENUM_NS(ClipState) 72 } // namespace PlaylistState 73 74 namespace FileStatus { 75 Q_NAMESPACE 76 enum ClipStatus { StatusReady = 0, StatusProxy, StatusMissing, StatusWaiting, StatusDeleting, StatusProxyOnly }; 77 Q_ENUM_NS(ClipStatus) 78 } // namespace PlaylistState 79 80 // returns a pair corresponding to (video, audio) 81 std::pair<bool, bool> stateToBool(PlaylistState::ClipState state); 82 PlaylistState::ClipState stateFromBool(std::pair<bool, bool> av); 83 84 namespace TimelineMode { 85 enum EditMode { NormalEdit = 0, OverwriteEdit = 1, InsertEdit = 2 }; 86 } 87 88 namespace AssetListType { 89 Q_NAMESPACE 90 enum AssetType { Preferred, Video, Audio, Custom, CustomAudio, Favorites, AudioComposition, VideoShortComposition, VideoComposition, AudioTransition, VideoTransition, Text, Hidden = -1 }; 91 Q_ENUM_NS(AssetType) 92 } 93 94 namespace ClipType { 95 Q_NAMESPACE 96 enum ProducerType { 97 Unknown = 0, 98 Audio = 1, 99 Video = 2, 100 AV = 3, 101 Color = 4, 102 Image = 5, 103 Text = 6, 104 SlideShow = 7, 105 Virtual = 8, 106 Playlist = 9, 107 WebVfx = 10, 108 TextTemplate = 11, 109 QText = 12, 110 Composition = 13, 111 Track = 14, 112 Qml = 15 113 }; 114 Q_ENUM_NS(ProducerType) 115 } // namespace ClipType 116 117 enum ProjectItemType { ProjectClipType = 0, ProjectFolderType, ProjectSubclipType }; 118 119 enum GraphicsRectItem { AVWidget = 70000, LabelWidget, TransitionWidget, GroupWidget }; 120 121 namespace ToolType { 122 Q_NAMESPACE 123 enum ProjectTool { 124 SelectTool = 0, 125 RazorTool = 1, 126 SpacerTool = 2, 127 RippleTool = 3, 128 RollTool = 4, 129 SlipTool = 5, 130 SlideTool = 6, 131 MulticamTool = 7 132 }; 133 Q_ENUM_NS(ProjectTool) 134 } 135 136 enum MonitorSceneType { 137 MonitorSceneNone = 0, 138 MonitorSceneDefault, 139 MonitorSceneGeometry, 140 MonitorSceneCorners, 141 MonitorSceneRoto, 142 MonitorSceneSplit, 143 MonitorSceneTrimming, 144 MonitorSplitTrack 145 }; 146 147 enum MessageType { DefaultMessage, ProcessingJobMessage, OperationCompletedMessage, InformationMessage, ErrorMessage, MltError, TooltipMessage }; 148 149 namespace BinMessage { 150 enum BinCategory { NoMessage = 0, ProfileMessage, StreamsMessage, InformationMessage }; 151 } 152 153 enum TrackType { AudioTrack = 0, VideoTrack = 1, AnyTrack = 2 }; 154 155 enum CacheType { SystemCacheRoot = -1, CacheRoot = 0, CacheBase = 1, CachePreview = 2, CacheProxy = 3, CacheAudio = 4, CacheThumbs = 5 }; 156 157 enum TrimMode { NormalTrim, RippleTrim, RollingTrim, SlipTrim, SlideTrim }; 158 159 class TrackInfo 160 { 161 162 public: 163 TrackType type; 164 QString trackName; 165 bool isMute; 166 bool isBlind; 167 bool isLocked; 168 int duration; 169 /*EffectsList effectsList; 170 TrackInfo() 171 : type(VideoTrack) 172 , isMute(0) 173 , isBlind(0) 174 , isLocked(0) 175 , duration(0) 176 , effectsList(true) 177 { 178 }*/ 179 }; 180 181 struct requestClipInfo 182 { 183 QDomElement xml; 184 QString clipId; 185 int imageHeight; 186 bool replaceProducer; 187 188 bool operator==(const requestClipInfo &a) const { return clipId == a.clipId; } 189 }; 190 191 typedef QMap<QString, QString> stringMap; 192 typedef QMap<int, QMap<int, QByteArray>> audioByteArray; 193 using audioShortVector = QVector<qint16>; 194 195 class ItemInfo 196 { 197 public: 198 /** startPos is the position where the clip starts on the track */ 199 GenTime startPos; 200 /** endPos is the duration where the clip ends on the track */ 201 GenTime endPos; 202 /** cropStart is the position where the sub-clip starts, relative to the clip's 0 position */ 203 GenTime cropStart; 204 /** cropDuration is the duration of the clip */ 205 GenTime cropDuration; 206 /** Track number */ 207 int track{0}; 208 ItemInfo() = default; isValid()209 bool isValid() const { return startPos != endPos; } contains(GenTime pos)210 bool contains(GenTime pos) const 211 { 212 if (startPos == endPos) { 213 return true; 214 } 215 return (pos <= endPos && pos >= startPos); 216 } 217 bool operator==(const ItemInfo &a) const { return startPos == a.startPos && endPos == a.endPos && track == a.track && cropStart == a.cropStart; } 218 }; 219 220 class TransitionInfo 221 { 222 public: 223 /** startPos is the position where the clip starts on the track */ 224 GenTime startPos; 225 /** endPos is the duration where the clip ends on the track */ 226 GenTime endPos; 227 /** the track on which the transition is (b_track)*/ 228 int b_track{0}; 229 /** the track on which the transition is applied (a_track)*/ 230 int a_track{0}; 231 /** Does the user request for a special a_track */ 232 bool forceTrack{false}; 233 TransitionInfo() = default; 234 }; 235 236 class CommentedTime 237 { 238 public: 239 CommentedTime(); 240 CommentedTime(const GenTime &time, QString comment, int markerType = 0); 241 CommentedTime(const QString &hash, const GenTime &time); 242 243 QString comment() const; 244 GenTime time() const; 245 /** @brief Returns a string containing infos needed to store marker info. string equals marker type + QLatin1Char(':') + marker comment */ 246 QString hash() const; 247 void setComment(const QString &comm); 248 void setTime(const GenTime &t); 249 void setMarkerType(int t); 250 int markerType() const; 251 252 /* Implementation of > operator; Works identically as with basic types. */ 253 bool operator>(const CommentedTime &op) const; 254 /* Implementation of < operator; Works identically as with basic types. */ 255 bool operator<(const CommentedTime &op) const; 256 /* Implementation of >= operator; Works identically as with basic types. */ 257 bool operator>=(const CommentedTime &op) const; 258 /* Implementation of <= operator; Works identically as with basic types. */ 259 bool operator<=(const CommentedTime &op) const; 260 /* Implementation of == operator; Works identically as with basic types. */ 261 bool operator==(const CommentedTime &op) const; 262 /* Implementation of != operator; Works identically as with basic types. */ 263 bool operator!=(const CommentedTime &op) const; 264 265 private: 266 GenTime m_time; 267 QString m_comment; 268 int m_type{0}; 269 }; 270 271 class SubtitledTime 272 { 273 public: 274 SubtitledTime(); 275 SubtitledTime(const GenTime &start, QString sub, const GenTime &end); 276 277 QString subtitle() const; 278 GenTime start() const; 279 GenTime end() const; 280 281 void setSubtitle(const QString &sub); 282 void setEndTime(const GenTime &end); 283 284 /* Implementation of > operator; Works identically as with basic types. */ 285 bool operator>(const SubtitledTime &op) const; 286 /* Implementation of < operator; Works identically as with basic types. */ 287 bool operator<(const SubtitledTime &op) const; 288 /* Implementation of == operator; Works identically as with basic types. */ 289 bool operator==(const SubtitledTime &op) const; 290 /* Implementation of != operator; Works identically as with basic types. */ 291 bool operator!=(const SubtitledTime &op) const; 292 293 private: 294 GenTime m_starttime; 295 QString m_subtitle; 296 GenTime m_endtime; 297 }; 298 299 QDebug operator<<(QDebug qd, const ItemInfo &info); 300 301 // we provide hash function for qstring and QPersistentModelIndex 302 namespace std { 303 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) 304 template <> struct hash<QString> 305 { 306 std::size_t operator()(const QString &k) const { return qHash(k); } 307 }; 308 #endif 309 template <> struct hash<QPersistentModelIndex> 310 { 311 std::size_t operator()(const QPersistentModelIndex &k) const { return qHash(k); } 312 }; 313 } // namespace std 314 315 // The following is a hack that allows one to use shared_from_this in the case of a multiple inheritance. 316 // Credit: https://stackoverflow.com/questions/14939190/boost-shared-from-this-and-multiple-inheritance 317 template <typename T> struct enable_shared_from_this_virtual; 318 319 class enable_shared_from_this_virtual_base : public std::enable_shared_from_this<enable_shared_from_this_virtual_base> 320 { 321 using base_type = std::enable_shared_from_this<enable_shared_from_this_virtual_base>; 322 template <typename T> friend struct enable_shared_from_this_virtual; 323 324 std::shared_ptr<enable_shared_from_this_virtual_base> shared_from_this() { return base_type::shared_from_this(); } 325 std::shared_ptr<enable_shared_from_this_virtual_base const> shared_from_this() const { return base_type::shared_from_this(); } 326 }; 327 328 template <typename T> struct enable_shared_from_this_virtual : virtual enable_shared_from_this_virtual_base 329 { 330 using base_type = enable_shared_from_this_virtual_base; 331 332 public: 333 std::shared_ptr<T> shared_from_this() 334 { 335 std::shared_ptr<T> result(base_type::shared_from_this(), static_cast<T *>(this)); 336 return result; 337 } 338 339 std::shared_ptr<T const> shared_from_this() const 340 { 341 std::shared_ptr<T const> result(base_type::shared_from_this(), static_cast<T const *>(this)); 342 return result; 343 } 344 }; 345 346 // This is a small trick to have a QAbstractItemModel with shared_from_this enabled without multiple inheritance 347 // 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 348 template <class T> class QAbstractItemModel_shared_from_this : public QAbstractItemModel 349 { 350 protected: 351 QAbstractItemModel_shared_from_this() 352 : QAbstractItemModel() 353 { 354 } 355 356 public: 357 std::shared_ptr<T> shared_from_this() 358 { 359 std::shared_ptr<T> p(weak_this_); 360 assert(p.get() == this); 361 return p; 362 } 363 364 std::shared_ptr<T const> shared_from_this() const 365 { 366 std::shared_ptr<T const> p(weak_this_); 367 assert(p.get() == this); 368 return p; 369 } 370 371 public: // actually private, but avoids compiler template friendship issues 372 mutable std::weak_ptr<T> weak_this_; 373 }; 374 #endif 375