1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "trackview.h"
22 #include "definitions.h"
23 #include "headertrack.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"
35 #include <KMessageBox>
39 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
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));
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);
64 QHBoxLayout *sizeLayout = new QHBoxLayout;
65 sizeLayout->setContentsMargins(0, 0, 0, 0);
66 sizeLayout->setSpacing(0);
67 m_view.size_frame->setLayout(sizeLayout);
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;}";
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);
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);
85 QHBoxLayout *tracksLayout = new QHBoxLayout;
86 tracksLayout->setContentsMargins(0, 0, 0, 0);
87 tracksLayout->setSpacing(0);
88 m_view.tracks_frame->setLayout(tracksLayout);
90 m_view.headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
91 m_view.headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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);
98 connect(m_view.headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
100 tracksLayout->addWidget(m_trackview);
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()));
105 parseDocument(m_doc->toXml());
106 int error = m_doc->setSceneList();
107 if (error == -1) *ok = false;
109 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
110 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
111 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
112 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
114 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
115 slotSetZone(m_doc->zone());
118 TrackView::~TrackView()
124 int TrackView::duration() const
126 return m_trackview->duration();
129 int TrackView::tracksNumber() const
131 return m_projectTracks - 1;
134 int TrackView::inPoint() const
136 return m_ruler->inPoint();
139 int TrackView::outPoint() const
141 return m_ruler->outPoint();
144 void TrackView::slotSetZone(QPoint p)
149 void TrackView::setDuration(int dur)
151 m_trackview->setDuration(dur);
152 m_ruler->setDuration(dur);
155 void TrackView::parseDocument(QDomDocument doc)
158 m_documentErrors.clear();
160 //kDebug() << "//// DOCUMENT: " << doc.toString();
161 /*QDomNode props = doc.elementsByTagName("properties").item(0);
162 if (!props.isNull()) {
163 cursorPos = props.toElement().attribute("timeline_position").toInt();
166 // parse project tracks
167 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
168 QDomNodeList tracks = doc.elementsByTagName("track");
169 QDomNodeList playlists = doc.elementsByTagName("playlist");
171 m_projectTracks = tracks.count();
172 int trackduration = 0;
176 int pos = m_projectTracks - 1;
177 m_invalidProducers.clear();
178 QDomNodeList producers = doc.elementsByTagName("producer");
179 for (int i = 0; i < producers.count(); i++) {
180 // Check for invalid producers
181 QDomNode n = producers.item(i);
185 // Check for invalid markup
186 QDomNodeList params = e.elementsByTagName("property");
187 for (int j = 0; j < params.count(); j++) {
188 QDomElement p = params.item(j).toElement();
189 if (p.attribute("name") == "markup") {
190 QString val = p.text().toUtf8().data();
191 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
192 //e.setAttribute("value", value);
193 n.removeChild(params.item(j));
199 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
200 int in = e.attribute("in").toInt();
201 int out = e.attribute("out").toInt();
202 if (in > out || in == out) {
203 // invalid producer, remove it
204 QString id = e.attribute("id");
205 m_invalidProducers.append(id);
206 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
207 doc.documentElement().removeChild(producers.at(i));
212 for (int i = 0; i < m_projectTracks; i++) {
213 e = tracks.item(i).toElement();
214 QString playlist_name = e.attribute("producer");
215 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
216 // find playlist related to this track
218 for (int j = 0; j < m_projectTracks; j++) {
219 p = playlists.item(j).toElement();
220 if (p.attribute("id") == playlist_name) break;
222 if (p.attribute("id") != playlist_name) { // then it didn't work.
223 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
225 if (e.attribute("hide") == "video") {
226 m_doc->switchTrackVideo(i - 1, true);
227 } else if (e.attribute("hide") == "audio") {
228 m_doc->switchTrackAudio(i - 1, true);
229 } else if (e.attribute("hide") == "both") {
230 m_doc->switchTrackVideo(i - 1, true);
231 m_doc->switchTrackAudio(i - 1, true);
234 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
236 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
237 if (trackduration > duration) duration = trackduration;
239 // background black track
240 for (int j = 0; j < m_projectTracks; j++) {
241 p = playlists.item(j).toElement();
242 if (p.attribute("id") == playlist_name) break;
244 int black_clips = p.childNodes().count();
245 for (int i = 0; i < black_clips; i++)
246 m_doc->loadingProgressed();
247 qApp->processEvents();
253 QDomNodeList transitions = doc.elementsByTagName("transition");
255 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
256 for (int i = 0; i < transitions.count(); i++) {
257 e = transitions.item(i).toElement();
258 QDomNodeList transitionparams = e.childNodes();
259 bool transitionAdd = true;
262 bool isAutomatic = false;
263 bool forceTrack = false;
264 QString mlt_geometry;
266 QString transitionId;
267 for (int k = 0; k < transitionparams.count(); k++) {
268 p = transitionparams.item(k).toElement();
270 QString paramName = p.attribute("name");
271 // do not add audio mixing transitions
272 if (paramName == "internal_added" && p.text() == "237") {
273 transitionAdd = false;
274 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
276 } else if (paramName == "a_track") a_track = p.text().toInt();
277 else if (paramName == "b_track") b_track = p.text().toInt();
278 else if (paramName == "mlt_service") mlt_service = p.text();
279 else if (paramName == "kdenlive_id") transitionId = p.text();
280 else if (paramName == "geometry") mlt_geometry = p.text();
281 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
282 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
285 if (transitionAdd || mlt_service != "mix") {
286 // Transition should be added to the scene
287 ItemInfo transitionInfo;
288 if (mlt_service == "composite" && transitionId.isEmpty()) {
289 // When adding composite transition, check if it is a wipe transition
290 if (mlt_geometry.count(';') == 1) {
291 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
292 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
293 QString start = mlt_geometry.section(';', 0, 0);
294 start = start.section(':', 0, 1);
295 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
296 QString end = mlt_geometry.section('=', 1, 1);
297 end = end.section(':', 0, 1);
298 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
299 start.append(',' + end);
300 QStringList numbers = start.split(',', QString::SkipEmptyParts);
301 bool isWipeTransition = true;
303 for (int i = 0; i < numbers.size(); ++i) {
304 checkNumber = qAbs(numbers.at(i).toInt());
305 if (checkNumber != 0 && checkNumber != 100) {
306 isWipeTransition = false;
310 if (isWipeTransition) transitionId = "slide";
313 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
315 for (int k = 0; k < transitionparams.count(); k++) {
316 p = transitionparams.item(k).toElement();
318 QString paramName = p.attribute("name");
319 QString paramValue = p.text();
321 QDomNodeList params = base.elementsByTagName("parameter");
322 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
323 QDomElement e = params.item(i).toElement();
324 if (!e.isNull() && e.attribute("tag") == paramName) {
325 if (e.attribute("type") == "double") {
326 QString factor = e.attribute("factor", "1");
328 double val = paramValue.toDouble() * factor.toDouble();
329 paramValue = QString::number(val);
332 e.setAttribute("value", paramValue);
340 doc.appendChild(doc.importNode(base, true));
341 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
343 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
344 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
345 transitionInfo.track = m_projectTracks - 1 - b_track;
346 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
347 if (transitionInfo.startPos >= transitionInfo.endPos) {
348 // invalid transition, remove it.
349 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
350 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
351 tractor.removeChild(transitions.item(i));
354 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
355 if (forceTrack) tr->setForcedTrack(true, a_track);
356 m_scene->addItem(tr);
357 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
358 tr->setItemLocked(true);
365 QDomNodeList guides = doc.elementsByTagName("guide");
366 for (int i = 0; i < guides.count(); i++) {
367 e = guides.item(i).toElement();
368 const QString comment = e.attribute("comment");
369 const GenTime pos = GenTime(e.attribute("time").toDouble());
370 m_trackview->addGuide(pos, comment);
374 QDomNodeList groups = doc.elementsByTagName("group");
375 m_trackview->loadGroups(groups);
376 m_trackview->setDuration(duration);
377 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
379 // Remove Kdenlive extra info from xml doc before sending it to MLT
380 QDomElement mlt = doc.firstChildElement("mlt");
381 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
382 mlt.removeChild(infoXml);
384 slotRebuildTrackHeaders();
385 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
386 //m_trackview->setCursorPos(cursorPos);
387 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
390 void TrackView::slotDeleteClip(const QString &clipId)
392 m_trackview->deleteClip(clipId);
395 void TrackView::setCursorPos(int pos)
397 m_trackview->setCursorPos(pos);
400 void TrackView::moveCursorPos(int pos)
402 m_trackview->setCursorPos(pos, false);
405 void TrackView::slotChangeZoom(int horizontal, int vertical)
407 m_ruler->setPixelPerMark(horizontal);
408 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal]; // m_ruler->comboScale[m_currentZoom] /
410 if (vertical == -1) {
412 m_doc->setZoom(horizontal, m_verticalZoom);
413 m_trackview->setScale(m_scale, m_scene->scale().y());
415 m_verticalZoom = vertical;
416 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
417 else m_trackview->setScale(m_scale, m_verticalZoom);
418 adjustTrackHeaders();
422 int TrackView::fitZoom() const
424 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
426 for (i = 0; i < 13; i++)
427 if (m_ruler->comboScale[i] > zoom) break;
431 KdenliveDoc *TrackView::document()
436 void TrackView::refresh()
438 m_trackview->viewport()->update();
441 void TrackView::slotRebuildTrackHeaders()
443 QList <TrackInfo> list = m_doc->tracksList();
445 while ((child = m_headersLayout->takeAt(0)) != 0) {
446 if (child->widget()) delete child->widget();
449 int max = list.count();
450 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
451 for (int i = 0; i < max; i++) {
452 HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), height, this);
453 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
454 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
455 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
457 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
458 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
459 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
460 m_headersLayout->addWidget(header);
465 void TrackView::adjustTrackHeaders()
467 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
469 for (int i = 0; i < m_headersLayout->count(); i++) {
470 child = m_headersLayout->itemAt(i);
471 if (child->widget())(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
475 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
479 QDomNodeList children = xml.childNodes();
480 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
481 QDomNode n = children.item(nodeindex);
482 QDomElement elem = n.toElement();
483 if (elem.tagName() == "blank") {
484 position += elem.attribute("length").toInt();
485 } else if (elem.tagName() == "entry") {
486 m_doc->loadingProgressed();
487 qApp->processEvents();
489 int in = elem.attribute("in").toInt();
490 int out = elem.attribute("out").toInt();
491 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
492 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
493 xml.removeChild(children.at(nodeindex));
497 QString idString = elem.attribute("producer");
498 QString id = idString;
500 if (idString.startsWith("slowmotion")) {
501 id = idString.section(':', 1, 1);
502 speed = idString.section(':', 2, 2).toDouble();
503 } else id = id.section('_', 0, 0);
504 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
506 // The clip in playlist was not listed in the kdenlive producers,
507 // something went wrong, repair required.
508 kWarning() << "CANNOT INSERT CLIP " << id;
510 clip = getMissingProducer(id);
512 // We cannot find the producer, something is really wrong, add
513 // placeholder color clip
515 QDomElement producerXml = doc.createElement("producer");
516 doc.appendChild(producerXml);
517 producerXml.setAttribute("colour", "0xff0000ff");
518 producerXml.setAttribute("mlt_service", "colour");
519 producerXml.setAttribute("length", "15000");
520 producerXml.setAttribute("name", "INVALID");
521 producerXml.setAttribute("type", COLOR);
522 producerXml.setAttribute("id", id);
523 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
524 xml.insertBefore(producerXml, QDomNode());
525 m_doc->clipManager()->addClip(clip);
527 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
529 // Found correct producer
530 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
531 elem.setAttribute("producer", clip->getId());
533 m_doc->setModified(true);
538 clipinfo.startPos = GenTime(position, m_doc->fps());
539 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
540 clipinfo.cropStart = GenTime(in, m_doc->fps());
542 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
543 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, false);
544 if (idString.endsWith("_video")) item->setVideoOnly(true);
545 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
546 m_scene->addItem(item);
547 if (locked) item->setItemLocked(true);
548 clip->addReference();
549 position += (out - in + 1);
551 // parse clip effects
552 QDomNodeList effects = elem.childNodes();
553 for (int ix = 0; ix < effects.count(); ix++) {
554 QDomElement effect = effects.at(ix).toElement();
555 if (effect.tagName() == "filter") {
556 // add effect to clip
560 QString ladspaEffectFile;
561 // Get effect tag & index
562 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
563 // parse effect parameters
564 QDomElement effectparam = n3.toElement();
565 if (effectparam.attribute("name") == "tag") {
566 effecttag = effectparam.text();
567 } else if (effectparam.attribute("name") == "kdenlive_id") {
568 effectid = effectparam.text();
569 } else if (effectparam.attribute("name") == "kdenlive_ix") {
570 effectindex = effectparam.text();
571 } else if (effectparam.attribute("name") == "src") {
572 ladspaEffectFile = effectparam.text();
573 if (!QFile::exists(ladspaEffectFile)) {
574 // If the ladspa effect file is missing, recreate it
575 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
576 ladspaEffectFile = m_doc->getLadspaFile();
577 effectparam.firstChild().setNodeValue(ladspaEffectFile);
578 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
582 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
583 // get effect standard tags
584 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
585 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
586 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
587 if (clipeffect.isNull()) {
588 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
589 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
590 elem.removeChild(effects.at(ix));
593 QDomElement currenteffect = clipeffect.cloneNode().toElement();
594 currenteffect.setAttribute("kdenlive_ix", effectindex);
595 QDomNodeList clipeffectparams = currenteffect.childNodes();
597 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
598 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
599 // effect is key-framable, read all effects to retrieve keyframes
603 QDomNodeList params = currenteffect.elementsByTagName("parameter");
604 for (int i = 0; i < params.count(); i++) {
605 QDomElement e = params.item(i).toElement();
606 if (e.attribute("type") == "keyframe") {
607 starttag = e.attribute("starttag", "start");
608 endtag = e.attribute("endtag", "end");
609 factor = e.attribute("factor", "1").toDouble();
614 int effectin = effect.attribute("in").toInt();
615 int effectout = effect.attribute("out").toInt();
616 double startvalue = 0;
618 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
619 // parse effect parameters
620 QDomElement effectparam = n3.toElement();
621 if (effectparam.attribute("name") == starttag)
622 startvalue = effectparam.text().toDouble() * factor;
623 if (effectparam.attribute("name") == endtag)
624 endvalue = effectparam.text().toDouble() * factor;
626 // add first keyframe
627 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
628 QDomNode lastParsedEffect;
630 QDomNode n2 = effects.at(ix);
631 bool continueParsing = true;
632 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
634 QDomElement kfreffect = n2.toElement();
635 int effectout = kfreffect.attribute("out").toInt();
637 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
638 // parse effect parameters
639 QDomElement subeffectparam = n4.toElement();
640 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
641 //We are not in the same effect, stop parsing
642 lastParsedEffect = n2.previousSibling();
644 continueParsing = false;
646 } else if (subeffectparam.attribute("name") == endtag) {
647 endvalue = subeffectparam.text().toDouble() * factor;
651 if (continueParsing) {
652 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
657 params = currenteffect.elementsByTagName("parameter");
658 for (int i = 0; i < params.count(); i++) {
659 QDomElement e = params.item(i).toElement();
660 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
662 if (!continueParsing) {
663 n2 = lastParsedEffect;
666 // Check if effect has in/out points
667 if (effect.hasAttribute("in")) {
668 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
670 if (effect.hasAttribute("out")) {
671 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
675 // adjust effect parameters
676 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
677 // parse effect parameters
678 QDomElement effectparam = n3.toElement();
679 QString paramname = effectparam.attribute("name");
680 QString paramvalue = effectparam.text();
683 // try to find this parameter in the effect xml
685 for (int k = 0; k < clipeffectparams.count(); k++) {
686 e = clipeffectparams.item(k).toElement();
687 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
688 double factor = e.attribute("factor", "1").toDouble();
690 e.setAttribute("value", paramvalue.toDouble() * factor);
691 } else e.setAttribute("value", paramvalue);
696 if (effecttag == "ladspa") {
697 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
699 if (!QFile::exists(ladspaEffectFile)) {
700 // If the ladspa effect file is missing, recreate it
701 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
703 currenteffect.setAttribute("src", ladspaEffectFile);
705 item->addEffect(currenteffect, false);
706 item->effectsCounter();
711 //m_clipList.append(clip);
714 //m_trackDuration = position;
717 //documentTracks.insert(ix, track);
718 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
723 DocClipBase *TrackView::getMissingProducer(const QString id) const
725 QDomElement missingXml;
726 QDomDocument doc = m_doc->toXml();
727 QString docRoot = doc.documentElement().attribute("root");
728 if (!docRoot.endsWith('/')) docRoot.append('/');
729 QDomNodeList prods = doc.elementsByTagName("producer");
730 int maxprod = prods.count();
731 for (int i = 0; i < maxprod; i++) {
732 QDomNode m = prods.at(i);
733 QString prodId = m.toElement().attribute("id");
735 missingXml = m.toElement();
739 if (missingXml == QDomElement()) return NULL;
741 QDomNodeList params = missingXml.childNodes();
743 for (int j = 0; j < params.count(); j++) {
744 QDomElement e = params.item(j).toElement();
745 if (e.attribute("name") == "resource") {
746 resource = e.firstChild().nodeValue();
750 // prepend MLT XML document root if no path in clip resource and not a color clip
751 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
752 DocClipBase *missingClip = NULL;
753 if (!resource.isEmpty())
754 missingClip = m_doc->clipManager()->getClipByResource(resource);
758 QGraphicsScene *TrackView::projectScene()
763 CustomTrackView *TrackView::projectView()
768 void TrackView::setEditMode(const QString & editMode)
770 m_editMode = editMode;
773 const QString & TrackView::editMode() const
778 void TrackView::slotChangeTrackLock(int ix, bool lock)
780 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
781 widgets.at(ix)->setLock(lock);
784 void TrackView::slotVerticalZoomDown()
786 if (m_verticalZoom == 0) return;
788 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
789 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
790 else m_trackview->setScale(m_scene->scale().x(), 1);
791 adjustTrackHeaders();
792 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() / 2);
793 m_trackview->checkTrackHeight(false);*/
796 void TrackView::slotVerticalZoomUp()
798 if (m_verticalZoom == 2) return;
800 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
801 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() * 2);
802 m_trackview->checkTrackHeight(false);*/
803 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
804 else m_trackview->setScale(m_scene->scale().x(), 1);
805 adjustTrackHeaders();
808 #include "trackview.moc"