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