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