]> git.sesse.net Git - kdenlive/blob - src/trackview.cpp
Krazy fixes: cleanup all headers
[kdenlive] / src / trackview.cpp
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 #include "trackview.h"
22 #include "definitions.h"
23 #include "headertrack.h"
24 #include "clipitem.h"
25 #include "transition.h"
26 #include "kdenlivesettings.h"
27 #include "clipmanager.h"
28 #include "customruler.h"
29 #include "kdenlivedoc.h"
30 #include "mainwindow.h"
31 #include "customtrackview.h"
32 #include "initeffects.h"
33
34 #include <KDebug>
35 #include <KMessageBox>
36
37 #include <QScrollBar>
38
39 TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
40         : QWidget(parent), m_doc(doc), m_scale(1.0), m_projectTracks(0) {
41
42     view = new Ui::TimeLine_UI();
43     view->setupUi(this);
44
45     m_scene = new CustomTrackScene(doc);
46     m_trackview = new CustomTrackView(doc, m_scene, parent);
47     m_trackview->scale(1, 1);
48     m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
49     //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
50
51     m_ruler = new CustomRuler(doc->timecode(), m_trackview);
52     connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
53     QHBoxLayout *layout = new QHBoxLayout;
54     view->ruler_frame->setLayout(layout);
55     int left_margin;
56     int right_margin;
57     layout->getContentsMargins(&left_margin, 0, &right_margin, 0);
58     layout->setContentsMargins(left_margin, 0, right_margin, 0);
59     layout->addWidget(m_ruler);
60
61     QHBoxLayout *tracksLayout = new QHBoxLayout;
62     tracksLayout->setContentsMargins(0, 0, 0, 0);
63     view->tracks_frame->setLayout(tracksLayout);
64
65     view->headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66     view->headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67
68     m_headersLayout = new QVBoxLayout;
69     m_headersLayout->setContentsMargins(0, 0, 0, 0);
70     m_headersLayout->setSpacing(0);
71     view->headers_container->setLayout(m_headersLayout);
72
73     connect(view->headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
74
75     tracksLayout->addWidget(m_trackview);
76
77     connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), view->headers_area->verticalScrollBar(), SLOT(setValue(int)));
78     connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
79
80     parseDocument(m_doc->toXml());
81     m_doc->setSceneList();
82     connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
83     connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
84     connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
85     connect(m_trackview, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotTransitionItemSelected(Transition*, bool)));
86     connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
87
88     slotChangeZoom(m_doc->zoom());
89     slotSetZone(m_doc->zone());
90 }
91
92
93 int TrackView::duration() const {
94     return m_trackview->duration();
95 }
96
97 int TrackView::tracksNumber() const {
98     return m_projectTracks - 1;
99 }
100
101 int TrackView::inPoint() const {
102     return m_ruler->inPoint();
103 }
104
105 int TrackView::outPoint() const {
106     return m_ruler->outPoint();
107 }
108
109 void TrackView::slotSetZone(QPoint p) {
110     m_ruler->setZone(p);
111 }
112
113 void TrackView::slotTransitionItemSelected(Transition *t, bool update) {
114     emit transitionItemSelected(t, update);
115 }
116
117 void TrackView::setDuration(int dur) {
118     m_trackview->setDuration(dur);
119     m_ruler->setDuration(dur);
120 }
121
122 void TrackView::parseDocument(QDomDocument doc) {
123     int cursorPos = 0;
124     m_documentErrors.clear();
125     // kDebug() << "//// DOCUMENT: " << doc.toString();
126     /*QDomNode props = doc.elementsByTagName("properties").item(0);
127     if (!props.isNull()) {
128         cursorPos = props.toElement().attribute("timeline_position").toInt();
129     }*/
130
131     // parse project tracks
132     QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
133     QDomNodeList tracks = doc.elementsByTagName("track");
134     QDomNodeList playlists = doc.elementsByTagName("playlist");
135     int duration = 300;
136     m_projectTracks = tracks.count();
137     int trackduration = 0;
138     QDomElement e;
139     QDomElement p;
140
141     int pos = m_projectTracks - 1;
142
143
144     for (int i = 0; i < m_projectTracks; i++) {
145         e = tracks.item(i).toElement();
146         QString playlist_name = e.attribute("producer");
147         if (playlist_name != "black_track" && playlist_name != "playlistmain") {
148             // find playlist related to this track
149             p = QDomElement();
150             for (int j = 0; j < m_projectTracks; j++) {
151                 p = playlists.item(j).toElement();
152                 if (p.attribute("id") == playlist_name) break;
153             }
154             if (p.attribute("id") != playlist_name) { // then it didn't work.
155                 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
156             }
157             if (e.attribute("hide") == "video") {
158                 m_doc->switchTrackVideo(i - 1, true);
159             } else if (e.attribute("hide") == "audio") {
160                 m_doc->switchTrackAudio(i - 1, true);
161             } else if (e.attribute("hide") == "both") {
162                 m_doc->switchTrackVideo(i - 1, true);
163                 m_doc->switchTrackAudio(i - 1, true);
164             }
165             trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
166             pos--;
167             //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
168             if (trackduration > duration) duration = trackduration;
169         } else {
170             // background black track
171             for (int j = 0; j < m_projectTracks; j++) {
172                 p = playlists.item(j).toElement();
173                 if (p.attribute("id") == playlist_name) break;
174             }
175             int black_clips = p.childNodes().count();
176             for (int i = 0; i < black_clips; i++)
177                 m_doc->loadingProgressed();
178             qApp->processEvents();
179             pos--;
180         }
181     }
182
183     // parse transitions
184     QDomNodeList transitions = doc.elementsByTagName("transition");
185
186     //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
187     for (int i = 0; i < transitions.count(); i++) {
188         e = transitions.item(i).toElement();
189         QDomNodeList transitionparams = e.childNodes();
190         bool transitionAdd = true;
191         int a_track = 0;
192         int b_track = 0;
193         bool isAutomatic = false;
194         bool forceTrack = false;
195         QString mlt_geometry;
196         QString mlt_service;
197         for (int k = 0; k < transitionparams.count(); k++) {
198             p = transitionparams.item(k).toElement();
199             if (!p.isNull()) {
200                 QString paramName = p.attribute("name");
201                 // do not add audio mixing transitions
202                 if (paramName == "internal_added" && p.text() == "237") {
203                     transitionAdd = false;
204                     //kDebug() << "//  TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
205                     //break;
206                 } else if (paramName == "a_track") a_track = p.text().toInt();
207                 else if (paramName == "b_track") b_track = p.text().toInt();
208                 else if (paramName == "mlt_service") mlt_service = p.text();
209                 else if (paramName == "geometry") mlt_geometry = p.text();
210                 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
211                 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
212             }
213         }
214         if (transitionAdd || mlt_service != "mix") {
215             // Transition should be added to the scene
216             ItemInfo transitionInfo;
217             QString transitionId;
218             if (mlt_service == "composite") {
219                 // When adding composite transition, check if it is a wipe transition
220                 if (mlt_geometry == "0%,0%:100%x100%") transitionId = "alphatransparency";
221                 else if (mlt_geometry.count(';') == 1) {
222                     mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
223                     mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
224                     QString start = mlt_geometry.section(';', 0, 0);
225                     start = start.section(':', 0, 1);
226                     start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
227                     QString end = mlt_geometry.section('=', 1, 1);
228                     end = end.section(':', 0, 1);
229                     end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
230                     start.append(',' + end);
231                     QStringList numbers = start.split(',', QString::SkipEmptyParts);
232                     bool isWipeTransition = true;
233                     int checkNumber;
234                     for (int i = 0; i < numbers.size(); ++i) {
235                         checkNumber = qAbs(numbers.at(i).toInt());
236                         if (checkNumber != 0 && checkNumber != 100) {
237                             isWipeTransition = false;
238                             break;
239                         }
240                     }
241                     if (isWipeTransition) transitionId = "wipe";
242                 }
243             }
244             QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
245
246             for (int k = 0; k < transitionparams.count(); k++) {
247                 p = transitionparams.item(k).toElement();
248                 if (!p.isNull()) {
249                     QString paramName = p.attribute("name");
250                     QString paramValue = p.text();
251
252                     QDomNodeList params = base.elementsByTagName("parameter");
253                     if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
254                             QDomElement e = params.item(i).toElement();
255                             if (!e.isNull() && e.attribute("tag") == paramName) {
256                                 if (e.attribute("type") == "double") {
257                                     QString factor = e.attribute("factor", "1");
258                                     if (factor != "1") {
259                                         double val = paramValue.toDouble() * factor.toDouble();
260                                         paramValue = QString::number(val);
261                                     }
262                                 }
263                                 e.setAttribute("value", paramValue);
264                                 break;
265                             }
266                         }
267                 }
268             }
269
270             /*QDomDocument doc;
271             doc.appendChild(doc.importNode(base, true));
272             kDebug() << "///////  TRANSITION XML: "<< doc.toString();*/
273
274             transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
275             transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
276             transitionInfo.track = m_projectTracks - 1 - b_track;
277             //kDebug() << "///////////////   +++++++++++  ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
278             if (transitionInfo.startPos >= transitionInfo.endPos) {
279                 // invalid transition, remove it.
280                 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
281                 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
282                 tractor.removeChild(transitions.item(i));
283                 i--;
284             } else {
285                 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
286                 if (forceTrack) tr->setForcedTrack(true, a_track);
287                 m_scene->addItem(tr);
288                 if (m_doc->isTrackLocked(b_track - 1)) {
289                     tr->setItemLocked(true);
290                 }
291             }
292         }
293     }
294
295     // Add guides
296     QDomNodeList guides = doc.elementsByTagName("guide");
297     for (int i = 0; i < guides.count(); i++) {
298         e = guides.item(i).toElement();
299         const QString comment = e.attribute("comment");
300         const GenTime pos = GenTime(e.attribute("time").toDouble());
301         m_trackview->addGuide(pos, comment);
302     }
303
304     m_trackview->setDuration(duration);
305     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
306     slotRebuildTrackHeaders();
307     if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
308     //m_trackview->setCursorPos(cursorPos);
309     //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
310 }
311
312 void TrackView::slotDeleteClip(const QString &clipId) {
313     m_trackview->deleteClip(clipId);
314 }
315
316 void TrackView::setCursorPos(int pos) {
317     m_trackview->setCursorPos(pos);
318 }
319
320 void TrackView::moveCursorPos(int pos) {
321     m_trackview->setCursorPos(pos, false);
322 }
323
324 void TrackView::slotChangeZoom(int factor) {
325     m_doc->setZoom(factor);
326     m_ruler->setPixelPerMark(factor);
327     m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] /
328     m_trackview->setScale(m_scale);
329 }
330
331 int TrackView::fitZoom() const {
332     int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
333     int i;
334     for (i = 0; i < 13; i++)
335         if (m_ruler->comboScale[i] > zoom) break;
336     return i;
337 }
338
339 const double TrackView::zoomFactor() const {
340     return m_scale;
341 }
342
343 const int TrackView::mapLocalToValue(int x) const {
344     return (int)(x * zoomFactor());
345 }
346
347 KdenliveDoc *TrackView::document() {
348     return m_doc;
349 }
350
351 void TrackView::refresh() {
352     m_trackview->viewport()->update();
353 }
354
355 void TrackView::slotRebuildTrackHeaders() {
356     QList <TrackInfo> list = m_doc->tracksList();
357     QList<HeaderTrack *> widgets = this->findChildren<HeaderTrack *>();
358     for (int i = 0; i < widgets.count(); i++)
359         delete widgets.at(i);
360     int max = list.count();
361     for (int i = 0; i < max; i++) {
362         HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), this);
363         connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
364         connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
365         connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
366
367         connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
368         connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
369         connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
370         m_headersLayout->addWidget(header);
371     }
372     view->headers_container->adjustSize();
373 }
374
375
376 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) {
377     int trackTop = KdenliveSettings::trackheight() * ix;
378     // parse track
379     int position = 0;
380     for (QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) {
381         QDomElement elem = n.toElement();
382         if (elem.tagName() == "blank") {
383             position += elem.attribute("length").toInt();
384         } else if (elem.tagName() == "entry") {
385             m_doc->loadingProgressed();
386             qApp->processEvents();
387             // Found a clip
388             int in = elem.attribute("in").toInt();
389             int out = elem.attribute("out").toInt();
390             if (in > out || in == out) {
391                 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
392                 continue;
393             }
394             QString idString = elem.attribute("producer");
395             QString id = idString;
396             double speed = 1.0;
397             if (idString.startsWith("slowmotion")) {
398                 id = idString.section(':', 1, 1);
399                 speed = idString.section(':', 2, 2).toDouble();
400             } else id = id.section('_', 0, 0);
401             DocClipBase *clip = m_doc->clipManager()->getClipById(id);
402             if (clip != NULL) {
403                 ItemInfo clipinfo;
404                 clipinfo.startPos = GenTime(position, m_doc->fps());
405                 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
406                 clipinfo.cropStart = GenTime(in, m_doc->fps());
407                 clipinfo.track = ix;
408                 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
409                 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, false);
410                 m_scene->addItem(item);
411                 if (locked) item->setItemLocked(true);
412                 clip->addReference();
413                 position += (out - in + 1);
414
415                 // parse clip effects
416                 QDomNodeList effects = elem.childNodes();
417                 for (int ix = 0; ix < effects.count(); ix++) {
418                     QDomElement effect = effects.at(ix).toElement();
419                     if (effect.tagName() == "filter") {
420                         // add effect to clip
421                         QString effecttag;
422                         QString effectid;
423                         QString effectindex;
424                         QString ladspaEffectFile;
425                         // Get effect tag & index
426                         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
427                             // parse effect parameters
428                             QDomElement effectparam = n3.toElement();
429                             if (effectparam.attribute("name") == "tag") {
430                                 effecttag = effectparam.text();
431                             } else if (effectparam.attribute("name") == "kdenlive_id") {
432                                 effectid = effectparam.text();
433                             } else if (effectparam.attribute("name") == "kdenlive_ix") {
434                                 effectindex = effectparam.text();
435                             } else if (effectparam.attribute("name") == "src") {
436                                 ladspaEffectFile = effectparam.text();
437                                 if (!QFile::exists(ladspaEffectFile)) {
438                                     // If the ladspa effect file is missing, recreate it
439                                     kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
440                                     ladspaEffectFile = m_doc->getLadspaFile();
441                                     effectparam.firstChild().setNodeValue(ladspaEffectFile);
442                                     kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
443                                 }
444                             }
445                         }
446                         //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
447                         // get effect standard tags
448                         QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
449                         if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
450                         if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
451                         if (clipeffect.isNull()) {
452                             kDebug() << "///  WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
453                             m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
454                             elem.removeChild(effects.at(ix));
455                             ix--;
456                         } else {
457                             QDomElement currenteffect = clipeffect.cloneNode().toElement();
458                             currenteffect.setAttribute("kdenlive_ix", effectindex);
459                             QDomNodeList clipeffectparams = currenteffect.childNodes();
460
461                             if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
462                                 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND  * * * * * * * * * * *";
463                                 // effect is key-framable, read all effects to retrieve keyframes
464                                 double factor;
465                                 QString starttag;
466                                 QString endtag;
467                                 QDomNodeList params = currenteffect.elementsByTagName("parameter");
468                                 for (int i = 0; i < params.count(); i++) {
469                                     QDomElement e = params.item(i).toElement();
470                                     if (e.attribute("type") == "keyframe") {
471                                         starttag = e.attribute("starttag", "start");
472                                         endtag = e.attribute("endtag", "end");
473                                         factor = e.attribute("factor", "1").toDouble();
474                                         break;
475                                     }
476                                 }
477                                 QString keyframes;
478                                 int effectin = effect.attribute("in").toInt();
479                                 int effectout = effect.attribute("out").toInt();
480                                 double startvalue;
481                                 double endvalue;
482                                 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
483                                     // parse effect parameters
484                                     QDomElement effectparam = n3.toElement();
485                                     if (effectparam.attribute("name") == starttag)
486                                         startvalue = effectparam.text().toDouble() * factor;
487                                     if (effectparam.attribute("name") == endtag)
488                                         endvalue = effectparam.text().toDouble() * factor;
489                                 }
490                                 // add first keyframe
491                                 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
492                                 QDomNode lastParsedEffect;
493                                 ix++;
494                                 QDomNode n2 = effects.at(ix);
495                                 bool continueParsing = true;
496                                 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
497                                     // parse all effects
498                                     QDomElement kfreffect = n2.toElement();
499                                     int effectout = kfreffect.attribute("out").toInt();
500
501                                     for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
502                                         // parse effect parameters
503                                         QDomElement subeffectparam = n4.toElement();
504                                         if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
505                                             //We are not in the same effect, stop parsing
506                                             lastParsedEffect = n2.previousSibling();
507                                             ix--;
508                                             continueParsing = false;
509                                             break;
510                                         } else if (subeffectparam.attribute("name") == endtag) {
511                                             endvalue = subeffectparam.text().toDouble() * factor;
512                                             break;
513                                         }
514                                     }
515                                     if (continueParsing) {
516                                         keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
517                                         ix++;
518                                     }
519                                 }
520
521                                 params = currenteffect.elementsByTagName("parameter");
522                                 for (int i = 0; i < params.count(); i++) {
523                                     QDomElement e = params.item(i).toElement();
524                                     if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
525                                 }
526                                 if (!continueParsing) {
527                                     n2 = lastParsedEffect;
528                                 }
529                             } else {
530                                 // Check if effect has in/out points
531                                 if (effect.hasAttribute("in")) {
532                                     EffectsList::setParameter(currenteffect, "in",  effect.attribute("in"));
533                                 }
534                                 if (effect.hasAttribute("out")) {
535                                     EffectsList::setParameter(currenteffect, "out",  effect.attribute("out"));
536                                 }
537                             }
538
539                             // adjust effect parameters
540                             for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
541                                 // parse effect parameters
542                                 QDomElement effectparam = n3.toElement();
543                                 QString paramname = effectparam.attribute("name");
544                                 QString paramvalue = effectparam.text();
545
546
547                                 // try to find this parameter in the effect xml
548                                 QDomElement e;
549                                 for (int k = 0; k < clipeffectparams.count(); k++) {
550                                     e = clipeffectparams.item(k).toElement();
551                                     if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
552                                         double factor = e.attribute("factor", "1").toDouble();
553                                         if (factor != 1) {
554                                             e.setAttribute("value", paramvalue.toDouble() * factor);
555                                         } else e.setAttribute("value", paramvalue);
556                                         break;
557                                     }
558                                 }
559                             }
560                             if (effecttag == "ladspa") {
561                                 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
562
563                                 if (!QFile::exists(ladspaEffectFile)) {
564                                     // If the ladspa effect file is missing, recreate it
565                                     initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
566                                 }
567                                 currenteffect.setAttribute("src", ladspaEffectFile);
568                             }
569                             item->addEffect(currenteffect, false);
570                             item->effectsCounter();
571                         }
572                     }
573                 }
574             } else {
575                 // The clip in playlist was not listed in the kdenlive producers,
576                 // something went wrong, repair required.
577                 kWarning() << "CANNOT INSERT CLIP " << id;
578                 int out = elem.attribute("out").toInt();
579
580                 ItemInfo clipinfo;
581                 clipinfo.startPos = GenTime(position, m_doc->fps());
582                 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
583                 clipinfo.cropStart = GenTime(in, m_doc->fps());
584                 clipinfo.track = ix;
585                 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
586
587                 DocClipBase *missingClip = getMissingProducer(id);
588                 if (!missingClip) {
589                     // We cannot find the producer, something is really wrong, add
590                     // placeholder color clip
591                     QDomElement producerXml;
592                     producerXml.setTagName("producer");
593                     producerXml.setAttribute("resource", "0xff0000ff");
594                     producerXml.setAttribute("mlt_service", "colour");
595                     producerXml.setAttribute("length", "15000");
596                     producerXml.setAttribute("id", id);
597                     missingClip = new DocClipBase(m_doc->clipManager(), producerXml, id);
598                     m_documentErrors.append(i18n("Boken clip producer %1", id) + '\n');
599                 } else m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, missingClip->getId()) + '\n');
600                 ClipItem *item = new ClipItem(missingClip, clipinfo, m_doc->fps(), 1.0, false);
601                 m_scene->addItem(item);
602                 missingClip->addReference();
603                 position += (out - in + 1);
604
605                 m_doc->setModified(true);
606             }
607             //m_clipList.append(clip);
608         }
609     }
610     //m_trackDuration = position;
611
612
613     //documentTracks.insert(ix, track);
614     kDebug() << "*************  ADD DOC TRACK " << ix << ", DURATION: " << position;
615     return position;
616     //track->show();
617 }
618
619 DocClipBase *TrackView::getMissingProducer(const QString id) const {
620     QDomElement missingXml = QDomElement();
621     QDomDocument doc = m_doc->toXml();
622     QString docRoot = doc.documentElement().attribute("root");
623     if (!docRoot.endsWith('/')) docRoot.append('/');
624     QDomNodeList prods = doc.elementsByTagName("producer");
625     int maxprod = prods.count();
626     for (int i = 0; i < maxprod; i++) {
627         QDomNode m = prods.at(i);
628         QString prodId = m.toElement().attribute("id");
629         if (prodId == id) {
630             missingXml =  m.toElement();
631             break;
632         }
633     }
634     if (missingXml == QDomElement()) return NULL;
635
636     QDomNodeList params = missingXml.childNodes();
637     QString resource;
638     QString mlt_service;
639     for (int j = 0; j < params.count(); j++) {
640         QDomElement e = params.item(j).toElement();
641         if (e.attribute("name") == "resource") {
642             resource = e.firstChild().nodeValue();
643         } else if (e.attribute("name") == "mlt_service") {
644             mlt_service = e.firstChild().nodeValue();
645         }
646     }
647     resource.prepend(docRoot);
648     DocClipBase *missingClip = NULL;
649     if (!resource.isEmpty())
650         missingClip = m_doc->clipManager()->getClipByResource(resource);
651     return missingClip;
652 }
653
654 QGraphicsScene *TrackView::projectScene() {
655     return m_scene;
656 }
657
658 CustomTrackView *TrackView::projectView() {
659     return m_trackview;
660 }
661
662 void TrackView::setEditMode(const QString & editMode) {
663     m_editMode = editMode;
664 }
665
666 const QString & TrackView::editMode() const {
667     return m_editMode;
668 }
669
670 void TrackView::slotChangeTrackLock(int ix, bool lock) {
671     QList<HeaderTrack *> widgets = this->findChildren<HeaderTrack *>();
672     widgets.at(ix)->setLock(lock);
673 }
674
675
676 #include "trackview.moc"