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