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