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