]> git.sesse.net Git - kdenlive/blob - src/trackview.cpp
Debug line added
[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 (p.attribute("id") != playlist_name) { // then it didn't work.
153                 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
154             }
155             if (e.attribute("hide") == "video") {
156                 m_doc->switchTrackVideo(i - 1, true);
157             } else if (e.attribute("hide") == "audio") {
158                 m_doc->switchTrackAudio(i - 1, true);
159             } else if (e.attribute("hide") == "both") {
160                 m_doc->switchTrackVideo(i - 1, true);
161                 m_doc->switchTrackAudio(i - 1, true);
162             }
163             trackduration = slotAddProjectTrack(pos, p);
164             pos--;
165             //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
166             if (trackduration > duration) duration = trackduration;
167         } else {
168             // background black track
169             for (int j = 0; j < m_projectTracks; j++) {
170                 p = playlists.item(j).toElement();
171                 if (p.attribute("id") == playlist_name) break;
172             }
173             int black_clips = p.childNodes().count();
174             for (int i = 0; i < black_clips; i++)
175                 m_doc->loadingProgressed();
176             qApp->processEvents();
177             pos--;
178         }
179     }
180
181     // parse transitions
182     QDomNodeList transitions = doc.elementsByTagName("transition");
183
184     //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
185     for (int i = 0; i < transitions.count(); i++) {
186         e = transitions.item(i).toElement();
187         QDomNodeList transitionparams = e.childNodes();
188         bool transitionAdd = true;
189         int a_track = 0;
190         int b_track = 0;
191         bool isAutomatic = false;
192         bool forceTrack = false;
193         QString mlt_geometry;
194         QString mlt_service;
195         for (int k = 0; k < transitionparams.count(); k++) {
196             p = transitionparams.item(k).toElement();
197             if (!p.isNull()) {
198                 QString paramName = p.attribute("name");
199                 // do not add audio mixing transitions
200                 if (paramName == "internal_added" && p.text() == "237") {
201                     transitionAdd = false;
202                     //kDebug() << "//  TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
203                     //break;
204                 } else if (paramName == "a_track") a_track = p.text().toInt();
205                 else if (paramName == "b_track") b_track = p.text().toInt();
206                 else if (paramName == "mlt_service") mlt_service = p.text();
207                 else if (paramName == "geometry") mlt_geometry = p.text();
208                 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
209                 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
210             }
211         }
212         if (transitionAdd || mlt_service != "mix") {
213             // Transition should be added to the scene
214             ItemInfo transitionInfo;
215             QString transitionId;
216             if (mlt_service == "composite") {
217                 // When adding composite transition, check if it is a wipe transition
218                 if (mlt_geometry == "0%,0%:100%x100%") transitionId = "alphatransparency";
219                 else if (mlt_geometry.count(';') == 1) {
220                     mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
221                     mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
222                     QString start = mlt_geometry.section(';', 0, 0);
223                     start = start.section(':', 0, 1);
224                     start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
225                     QString end = mlt_geometry.section('=', 1, 1);
226                     end = end.section(':', 0, 1);
227                     end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
228                     start.append(',' + end);
229                     QStringList numbers = start.split(',', QString::SkipEmptyParts);
230                     bool isWipeTransition = true;
231                     int checkNumber;
232                     for (int i = 0; i < numbers.size(); ++i) {
233                         checkNumber = qAbs(numbers.at(i).toInt());
234                         if (checkNumber != 0 && checkNumber != 100) {
235                             isWipeTransition = false;
236                             break;
237                         }
238                     }
239                     if (isWipeTransition) transitionId = "wipe";
240                 }
241             }
242             QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
243
244             for (int k = 0; k < transitionparams.count(); k++) {
245                 p = transitionparams.item(k).toElement();
246                 if (!p.isNull()) {
247                     QString paramName = p.attribute("name");
248                     QString paramValue = p.text();
249
250                     QDomNodeList params = base.elementsByTagName("parameter");
251                     if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
252                             QDomElement e = params.item(i).toElement();
253                             if (!e.isNull() && e.attribute("tag") == paramName) {
254                                 if (e.attribute("type") == "double") {
255                                     QString factor = e.attribute("factor", "1");
256                                     if (factor != "1") {
257                                         double val = paramValue.toDouble() * factor.toDouble();
258                                         paramValue = QString::number(val);
259                                     }
260                                 }
261                                 e.setAttribute("value", paramValue);
262                                 break;
263                             }
264                         }
265                 }
266             }
267
268             /*QDomDocument doc;
269             doc.appendChild(doc.importNode(base, true));
270             kDebug() << "///////  TRANSITION XML: "<< doc.toString();*/
271
272             transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
273             transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
274             transitionInfo.track = m_projectTracks - 1 - b_track;
275             //kDebug() << "///////////////   +++++++++++  ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
276             if (transitionInfo.startPos >= transitionInfo.endPos) {
277                 // invalid transition, remove it.
278                 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
279                 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
280                 tractor.removeChild(transitions.item(i));
281                 i--;
282             } else {
283                 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
284                 if (forceTrack) tr->setForcedTrack(true, a_track);
285                 m_scene->addItem(tr);
286             }
287         }
288     }
289
290     // Add guides
291     QDomNodeList guides = doc.elementsByTagName("guide");
292     for (int i = 0; i < guides.count(); i++) {
293         e = guides.item(i).toElement();
294         const QString comment = e.attribute("comment");
295         const GenTime pos = GenTime(e.attribute("time").toDouble());
296         m_trackview->addGuide(pos, comment);
297     }
298
299     m_trackview->setDuration(duration);
300     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
301     slotRebuildTrackHeaders();
302     if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
303     //m_trackview->setCursorPos(cursorPos);
304     //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
305 }
306
307 void TrackView::slotDeleteClip(const QString &clipId) {
308     m_trackview->deleteClip(clipId);
309 }
310
311 void TrackView::setCursorPos(int pos) {
312     m_trackview->setCursorPos(pos);
313 }
314
315 void TrackView::moveCursorPos(int pos) {
316     m_trackview->setCursorPos(pos, false);
317 }
318
319 void TrackView::slotChangeZoom(int factor) {
320     m_doc->setZoom(factor);
321     m_ruler->setPixelPerMark(factor);
322     m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] /
323     m_trackview->setScale(m_scale);
324 }
325
326 int TrackView::fitZoom() const {
327     int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
328     int i;
329     for (i = 0; i < 13; i++)
330         if (m_ruler->comboScale[i] > zoom) break;
331     return i;
332 }
333
334 const double TrackView::zoomFactor() const {
335     return m_scale;
336 }
337
338 const int TrackView::mapLocalToValue(int x) const {
339     return (int)(x * zoomFactor());
340 }
341
342 KdenliveDoc *TrackView::document() {
343     return m_doc;
344 }
345
346 void TrackView::refresh() {
347     m_trackview->viewport()->update();
348 }
349
350 void TrackView::slotRebuildTrackHeaders() {
351     QList <TrackInfo> list = m_doc->tracksList();
352     QList<HeaderTrack *> widgets = this->findChildren<HeaderTrack *>();
353     for (int i = 0; i < widgets.count(); i++)
354         delete widgets.at(i);
355     int max = list.count();
356     for (int i = 0; i < max; i++) {
357         HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), this);
358         connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
359         connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
360
361         connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
362         connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
363         connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
364         m_headersLayout->addWidget(header);
365     }
366     view->headers_container->adjustSize();
367 }
368
369
370 int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
371     int trackTop = KdenliveSettings::trackheight() * ix;
372     // parse track
373     int position = 0;
374     for (QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) {
375         QDomElement elem = n.toElement();
376         if (elem.tagName() == "blank") {
377             position += elem.attribute("length").toInt();
378         } else if (elem.tagName() == "entry") {
379             m_doc->loadingProgressed();
380             qApp->processEvents();
381             // Found a clip
382             int in = elem.attribute("in").toInt();
383             QString idString = elem.attribute("producer");
384             QString id = idString;
385             double speed = 1.0;
386             if (idString.startsWith("slowmotion")) {
387                 id = idString.section(":", 1, 1);
388                 speed = idString.section(":", 2, 2).toDouble();
389             } else id = id.section('_', 0, 0);
390             DocClipBase *clip = m_doc->clipManager()->getClipById(id);
391             if (clip != NULL) {
392                 int out = elem.attribute("out").toInt();
393
394                 ItemInfo clipinfo;
395                 clipinfo.startPos = GenTime(position, m_doc->fps());
396                 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
397                 clipinfo.cropStart = GenTime(in, m_doc->fps());
398                 clipinfo.track = ix;
399                 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
400                 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, false);
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", id) + '\n');
589                 } else m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, missingClip->getId()) + '\n');
590                 ClipItem *item = new ClipItem(missingClip, clipinfo, m_doc->fps(), 1.0, false);
591                 m_scene->addItem(item);
592                 missingClip->addReference();
593                 position += (out - in + 1);
594
595                 m_doc->setModified(true);
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"