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