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