]> git.sesse.net Git - kdenlive/blob - src/definitions.h
67b994406224b9a14e21fe22792e3920fc88c430
[kdenlive] / src / definitions.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #ifndef DEFINITIONS_H
22 #define DEFINITIONS_H
23
24 #include "gentime.h"
25 #include "effectslist.h"
26
27 #include <KLocalizedString>
28 #include <QDebug>
29
30 #include <QTreeWidgetItem>
31 #include <QtCore/QString>
32
33 const int MAXCLIPDURATION = 15000;
34
35
36 namespace Kdenlive {
37 enum MONITORID { noMonitor, clipMonitor, projectMonitor, recordMonitor, stopmotionMonitor, dvdMonitor };
38 const int DefaultThumbHeight = 100;
39 /*const QString clipMonitor("clipMonitor");
40   const QString recordMonitor("recordMonitor");
41   const QString projectMonitor("projectMonitor");
42   const QString stopmotionMonitor("stopmotionMonitor");*/
43 }
44
45 enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN = 4, FADEOUT = 5, TRANSITIONSTART = 6, TRANSITIONEND = 7, MOVEGUIDE = 8, KEYFRAME = 9, SEEK = 10, SPACER = 11, RUBBERSELECTION = 12, SCROLLTIMELINE = 13};
46 enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9 };
47
48 enum PROJECTITEMTYPE { PROJECTCLIPTYPE = QTreeWidgetItem::UserType, PROJECTFOLDERTYPE, PROJECTSUBCLIPTYPE };
49
50 enum GRAPHICSRECTITEM { AVWIDGET = 70000 , LABELWIDGET , TRANSITIONWIDGET  , GROUPWIDGET};
51
52 enum PROJECTTOOL { SELECTTOOL = 0 , RAZORTOOL = 1 , SPACERTOOL = 2 };
53
54 enum TRANSITIONTYPE {
55     /** TRANSITIONTYPE: between 0-99: video trans, 100-199: video+audio trans, 200-299: audio trans */
56     LUMA_TRANSITION = 0,
57     COMPOSITE_TRANSITION = 1,
58     PIP_TRANSITION = 2,
59     LUMAFILE_TRANSITION = 3,
60     MIX_TRANSITION = 200
61 };
62
63 enum MessageType {
64     DefaultMessage,
65     OperationCompletedMessage,
66     InformationMessage,
67     ErrorMessage,
68     MltError
69 };
70
71 enum TRACKTYPE { AUDIOTRACK = 0, VIDEOTRACK = 1 };
72
73 enum CLIPJOBSTATUS { NOJOB = 0, JOBWAITING = -1, JOBWORKING = -2, JOBDONE = -3, JOBCRASHED = -4, JOBABORTED = -5};
74
75 class TrackInfo {
76 public:
77     TRACKTYPE type;
78     QString trackName;
79     bool isMute;
80     bool isBlind;
81     bool isLocked;
82     EffectsList effectsList;
83     int duration;
84     TrackInfo() :
85         type(VIDEOTRACK),
86         isMute(0),
87         isBlind(0),
88         isLocked(0),
89         duration(0) {}
90 };
91
92 typedef QMap<QString, QString> stringMap;
93 typedef QMap <int, QMap <int, QByteArray> > audioByteArray;
94
95 class ItemInfo {
96 public:
97     /** startPos is the position where the clip starts on the track */
98     GenTime startPos;
99     /** endPos is the duration where the clip ends on the track */
100     GenTime endPos;
101     /** cropStart is the position where the sub-clip starts, relative to the clip's 0 position */
102     GenTime cropStart;
103     /** cropDuration is the duration of the clip */
104     GenTime cropDuration;
105     int track;
106     ItemInfo() : track(0) {}
107 };
108
109 class TransitionInfo {
110 public:
111     /** startPos is the position where the clip starts on the track */
112     GenTime startPos;
113     /** endPos is the duration where the clip ends on the track */
114     GenTime endPos;
115     /** the track on which the transition is (b_track)*/
116     int b_track;
117     /** the track on which the transition is applied (a_track)*/
118     int a_track;
119     /** Does the user request for a special a_track */
120     bool forceTrack;
121     TransitionInfo() :
122         b_track(0),
123         a_track(0),
124         forceTrack(0) {}
125 };
126
127 class MltVideoProfile {
128 public:
129     QString path;
130     QString description;
131     int frame_rate_num;
132     int frame_rate_den;
133     int width;
134     int height;
135     bool progressive;
136     int sample_aspect_num;
137     int sample_aspect_den;
138     int display_aspect_num;
139     int display_aspect_den;
140     int colorspace;
141     MltVideoProfile() :
142         frame_rate_num(0),
143         frame_rate_den(0),
144         width(0),
145         height(0),
146         progressive(0),
147         sample_aspect_num(0),
148         sample_aspect_den(0),
149         display_aspect_num(0),
150         display_aspect_den(0),
151         colorspace(0) {}
152     bool operator==(const MltVideoProfile& point) const
153     {
154         if (!description.isEmpty() && point.description  == description) return true;
155         return      point.frame_rate_num == frame_rate_num &&
156                 point.frame_rate_den  == frame_rate_den  &&
157                 point.width == width &&
158                 point.height == height &&
159                 point.progressive == progressive &&
160                 point.sample_aspect_num == sample_aspect_num &&
161                 point.sample_aspect_den == sample_aspect_den &&
162                 point.display_aspect_den == display_aspect_den &&
163                 point.colorspace == colorspace;
164     }
165     bool operator!=(const MltVideoProfile &other) const {
166         return !(*this == other);
167     }
168 };
169
170 /**)
171  * @class EffectInfo
172  * @brief A class holding some meta info for effects widgets, like state (collapsed or not, ...)
173  * @author Jean-Baptiste Mardelle
174  */
175
176 class EffectInfo
177 {
178 public:
179     EffectInfo() {isCollapsed = false; groupIndex = -1; groupIsCollapsed = false;}
180     bool isCollapsed;
181     bool groupIsCollapsed;
182     int groupIndex;
183     QString groupName;
184     QString toString() const {
185         QStringList data;
186         // effect collapsed state: 0 = effect not collapsed, 1 = effect collapsed,
187         // 2 = group collapsed - effect not, 3 = group and effect collapsed
188         int collapsedState = (int) isCollapsed;
189         if (groupIsCollapsed) collapsedState += 2;
190         data << QString::number(collapsedState) << QString::number(groupIndex) << groupName;
191         return data.join(QLatin1String("/"));
192     }
193     void fromString(QString value) {
194         if (value.isEmpty()) return;
195         QStringList data = value.split(QLatin1String("/"));
196         isCollapsed = data.at(0).toInt() == 1 || data.at(0).toInt() == 3;
197         groupIsCollapsed = data.at(0).toInt() >= 2;
198         if (data.count() > 1) groupIndex = data.at(1).toInt();
199         if (data.count() > 2) groupName = data.at(2);
200     }
201 };
202
203 class EffectParameter
204 {
205 public:
206     EffectParameter(const QString &name, const QString &value): m_name(name), m_value(value) {}
207     QString name()   const          {
208         return m_name;
209     }
210     QString value() const          {
211         return m_value;
212     }
213     void setValue(const QString &value) {
214         m_value = value;
215     }
216
217 private:
218     QString m_name;
219     QString m_value;
220 };
221
222 /** Use our own list for effect parameters so that they are not sorted in any ways, because
223     some effects like sox need a precise order
224 */
225 class EffectsParameterList: public QList < EffectParameter >
226 {
227 public:
228     EffectsParameterList(): QList < EffectParameter >() {}
229     bool hasParam(const QString &name) const {
230         for (int i = 0; i < size(); ++i)
231             if (at(i).name() == name) return true;
232         return false;
233     }
234     void setParamValue(const QString &name, const QString &value) {
235         bool found = false;
236         for (int i = 0; i < size(); ++i)
237             if (at(i).name() == name) {
238                 // update value
239                 replace(i, EffectParameter(name, value));
240                 found = true;
241             }
242         if (!found) addParam(name, value);
243     }
244
245     QString paramValue(const QString &name, const QString &defaultValue = QString()) const {
246         for (int i = 0; i < size(); ++i) {
247             if (at(i).name() == name) return at(i).value();
248         }
249         return defaultValue;
250     }
251     void addParam(const QString &name, const QString &value) {
252         if (name.isEmpty()) return;
253         append(EffectParameter(name, value));
254     }
255     void removeParam(const QString &name) {
256         for (int i = 0; i < size(); ++i)
257             if (at(i).name() == name) {
258                 removeAt(i);
259                 break;
260             }
261     }
262 };
263
264 class CommentedTime
265 {
266 public:
267     CommentedTime(): t(GenTime(0)), type(0) {}
268     CommentedTime(const GenTime &time, const QString& comment, int markerType = 0)
269         : t(time), c(comment), type(markerType) { }
270
271     QString comment()   const          {
272         return (c.isEmpty() ? i18n("Marker") : c);
273     }
274     GenTime time() const          {
275         return t;
276     }
277     void    setComment(const QString &comm) {
278         c = comm;
279     }
280     void setMarkerType(int t) {
281         type = t;
282     }
283     int markerType() const {
284         return type;
285     }
286     static QColor markerColor(int type) {
287         switch (type) {
288         case 0:
289             return Qt::red;
290             break;
291         case 1:
292             return Qt::blue;
293             break;
294         case 2:
295             return Qt::green;
296             break;
297         case 3:
298             return Qt::yellow;
299             break;
300         default:
301             return Qt::cyan;
302             break;
303         }
304     }
305
306     /* Implementation of > operator; Works identically as with basic types. */
307     bool operator>(CommentedTime op) const {
308         return t > op.time();
309     }
310     /* Implementation of < operator; Works identically as with basic types. */
311     bool operator<(CommentedTime op) const {
312         return t < op.time();
313     }
314     /* Implementation of >= operator; Works identically as with basic types. */
315     bool operator>=(CommentedTime op) const {
316         return t >= op.time();
317     }
318     /* Implementation of <= operator; Works identically as with basic types. */
319     bool operator<=(CommentedTime op) const {
320         return t <= op.time();
321     }
322     /* Implementation of == operator; Works identically as with basic types. */
323     bool operator==(CommentedTime op) const {
324         return t == op.time();
325     }
326     /* Implementation of != operator; Works identically as with basic types. */
327     bool operator!=(CommentedTime op) const {
328         return t != op.time();
329     }
330
331 private:
332     GenTime t;
333     QString c;
334     int type;
335 };
336
337 QDebug operator << (QDebug qd, const ItemInfo &info);
338
339
340 #endif