]> git.sesse.net Git - kdenlive/blob - src/definitions.h
definitions.h: initialize TrackInfo [Coverity 13/14] by Mikko Rapeli
[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 <KLocale>
28 #include <QDebug>
29
30 #include <QTreeWidgetItem>
31  #include <QtCore/QString>
32
33 const int MAXCLIPDURATION = 15000;
34
35 namespace Kdenlive {
36   enum MONITORID { noMonitor, clipMonitor, projectMonitor, recordMonitor, stopmotionMonitor, dvdMonitor };
37   /*const QString clipMonitor("clipMonitor");
38   const QString recordMonitor("recordMonitor");
39   const QString projectMonitor("projectMonitor");
40   const QString stopmotionMonitor("stopmotionMonitor");*/
41 }
42
43 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};
44 enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9 };
45
46 enum PROJECTITEMTYPE { PROJECTCLIPTYPE = QTreeWidgetItem::UserType, PROJECTFOLDERTYPE, PROJECTSUBCLIPTYPE };
47
48 enum GRAPHICSRECTITEM { AVWIDGET = 70000 , LABELWIDGET , TRANSITIONWIDGET  , GROUPWIDGET};
49
50 enum PROJECTTOOL { SELECTTOOL = 0 , RAZORTOOL = 1 , SPACERTOOL = 2 };
51
52 enum TRANSITIONTYPE {
53     /** TRANSITIONTYPE: between 0-99: video trans, 100-199: video+audio trans, 200-299: audio trans */
54     LUMA_TRANSITION = 0,
55     COMPOSITE_TRANSITION = 1,
56     PIP_TRANSITION = 2,
57     LUMAFILE_TRANSITION = 3,
58     MIX_TRANSITION = 200
59 };
60
61 enum MessageType {
62     DefaultMessage,
63     OperationCompletedMessage,
64     InformationMessage,
65     ErrorMessage,
66     MltError
67 };
68
69 enum TRACKTYPE { AUDIOTRACK = 0, VIDEOTRACK = 1 };
70
71 enum CLIPJOBSTATUS { NOJOB = 0, JOBWAITING = -1, JOBWORKING = -2, JOBDONE = -3, JOBCRASHED = -4, JOBABORTED = -5};
72
73 class TrackInfo {
74 public:
75     TRACKTYPE type;
76     QString trackName;
77     bool isMute;
78     bool isBlind;
79     bool isLocked;
80     EffectsList effectsList;
81     int duration;
82     TrackInfo() :
83         type(VIDEOTRACK),
84         isMute(0),
85         isBlind(0),
86         isLocked(0),
87         duration(0) {};
88 };
89
90 typedef QMap<QString, QString> stringMap;
91 typedef QMap <int, QMap <int, QByteArray> > audioByteArray;
92
93 class ItemInfo {
94 public:
95     /** startPos is the position where the clip starts on the track */
96     GenTime startPos;
97     /** endPos is the duration where the clip ends on the track */
98     GenTime endPos;
99     /** cropStart is the position where the sub-clip starts, relative to the clip's 0 position */
100     GenTime cropStart;
101     /** cropDuration is the duration of the clip */
102     GenTime cropDuration;
103     int track;
104     ItemInfo() : track(0) {};
105 };
106
107 struct TransitionInfo {
108 /** startPos is the position where the clip starts on the track */
109     GenTime startPos;
110     /** endPos is the duration where the clip ends on the track */
111     GenTime endPos;
112     /** the track on which the transition is (b_track)*/
113     int b_track;
114     /** the track on which the transition is applied (a_track)*/
115     int a_track;
116     /** Does the user request for a special a_track */
117     bool forceTrack;
118 };
119
120 class MltVideoProfile {
121 public:
122     QString path;
123     QString description;
124     int frame_rate_num;
125     int frame_rate_den;
126     int width;
127     int height;
128     bool progressive;
129     int sample_aspect_num;
130     int sample_aspect_den;
131     int display_aspect_num;
132     int display_aspect_den;
133     int colorspace;
134     MltVideoProfile() :
135         frame_rate_num(0),
136         frame_rate_den(0),
137         width(0),
138         height(0),
139         progressive(0),
140         sample_aspect_num(0),
141         sample_aspect_den(0),
142         display_aspect_num(0),
143         display_aspect_den(0),
144         colorspace(0) {};
145     bool operator==(const MltVideoProfile& point) const
146     {
147         if (!description.isEmpty() && point.description  == description) return true;
148         return      point.frame_rate_num == frame_rate_num &&
149                     point.frame_rate_den  == frame_rate_den  &&
150                     point.width == width &&
151                     point.height == height &&
152                     point.progressive == progressive &&
153                     point.sample_aspect_num == sample_aspect_num &&
154                     point.sample_aspect_den == sample_aspect_den &&
155                     point.display_aspect_den == display_aspect_den &&
156                     point.colorspace == colorspace;
157     }
158     bool operator!=(const MltVideoProfile &other) const {
159         return !(*this == other);
160     }
161 };
162
163 /**)
164  * @class EffectInfo
165  * @brief A class holding some meta info for effects widgets, like state (collapsed or not, ...)
166  * @author Jean-Baptiste Mardelle
167  */
168
169 class EffectInfo
170 {
171 public:
172     EffectInfo() {isCollapsed = false; groupIndex = -1; groupIsCollapsed = false;}
173     bool isCollapsed;
174     bool groupIsCollapsed;
175     int groupIndex;
176     QString groupName;
177     QString toString() const {
178         QStringList data;
179         // effect collapsed state: 0 = effect not collapsed, 1 = effect collapsed, 
180         // 2 = group collapsed - effect not, 3 = group and effect collapsed
181         int collapsedState = (int) isCollapsed;
182         if (groupIsCollapsed) collapsedState += 2;
183         data << QString::number(collapsedState) << QString::number(groupIndex) << groupName;
184         return data.join("/");
185     }
186     void fromString(QString value) {
187         if (value.isEmpty()) return;
188         QStringList data = value.split("/");
189         isCollapsed = data.at(0).toInt() == 1 || data.at(0).toInt() == 3;
190         groupIsCollapsed = data.at(0).toInt() >= 2;
191         if (data.count() > 1) groupIndex = data.at(1).toInt();
192         if (data.count() > 2) groupName = data.at(2);
193     }
194 };
195
196 class EffectParameter
197 {
198 public:
199     EffectParameter(const QString &name, const QString &value): m_name(name), m_value(value) {}
200     QString name()   const          {
201         return m_name;
202     }
203     QString value() const          {
204         return m_value;
205     }
206     void setValue(const QString &value) {
207         m_value = value;
208     }
209
210 private:
211     QString m_name;
212     QString m_value;
213 };
214
215 /** Use our own list for effect parameters so that they are not sorted in any ways, because
216     some effects like sox need a precise order
217 */
218 class EffectsParameterList: public QList < EffectParameter >
219 {
220 public:
221     EffectsParameterList(): QList < EffectParameter >() {}
222     bool hasParam(const QString &name) const {
223         for (int i = 0; i < size(); i++)
224             if (at(i).name() == name) return true;
225         return false;
226     }
227     void setParamValue(const QString &name, const QString &value) {
228         bool found = false;
229         for (int i = 0; i < size(); i++)
230             if (at(i).name() == name) {
231                 // update value
232                 replace(i, EffectParameter(name, value));
233                 found = true;
234             }
235         if (!found) addParam(name, value);
236     }
237         
238     QString paramValue(const QString &name, QString defaultValue = QString()) const {
239         for (int i = 0; i < size(); i++) {
240             if (at(i).name() == name) return at(i).value();
241         }
242         return defaultValue;
243     }
244     void addParam(const QString &name, const QString &value) {
245         if (name.isEmpty()) return;
246         append(EffectParameter(name, value));
247     }
248     void removeParam(const QString &name) {
249         for (int i = 0; i < size(); i++)
250             if (at(i).name() == name) {
251                 removeAt(i);
252                 break;
253             }
254     }
255 };
256
257 class CommentedTime
258 {
259 public:
260     CommentedTime(): t(GenTime(0)) {}
261     CommentedTime(const GenTime &time, QString comment)
262         : t(time), c(comment) { }
263
264     QString comment()   const          {
265         return (c.isEmpty() ? i18n("Marker") : c);
266     }
267     GenTime time() const          {
268         return t;
269     }
270     void    setComment(QString comm) {
271         c = comm;
272     }
273
274     /* Implementation of > operator; Works identically as with basic types. */
275     bool operator>(CommentedTime op) const {
276         return t > op.time();
277     }
278     /* Implementation of < operator; Works identically as with basic types. */
279     bool operator<(CommentedTime op) const {
280         return t < op.time();
281     }
282     /* Implementation of >= operator; Works identically as with basic types. */
283     bool operator>=(CommentedTime op) const {
284         return t >= op.time();
285     }
286     /* Implementation of <= operator; Works identically as with basic types. */
287     bool operator<=(CommentedTime op) const {
288         return t <= op.time();
289     }
290     /* Implementation of == operator; Works identically as with basic types. */
291     bool operator==(CommentedTime op) const {
292         return t == op.time();
293     }
294     /* Implementation of != operator; Works identically as with basic types. */
295     bool operator!=(CommentedTime op) const {
296         return t != op.time();
297     }
298
299 private:
300     GenTime t;
301     QString c;
302
303
304 };
305
306 QDebug operator << (QDebug qd, const ItemInfo &info);
307
308
309 #endif