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