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