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