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"
33 #include "profilesdialog.h"
36 #include <KMessageBox>
40 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
50 m_scene = new CustomTrackScene(doc);
51 m_trackview = new CustomTrackView(doc, m_scene, parent);
52 m_trackview->scale(1, 1);
53 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
54 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
56 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
57 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
58 QHBoxLayout *layout = new QHBoxLayout;
59 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
60 layout->setSpacing(0);
61 m_view.ruler_frame->setLayout(layout);
62 layout->addWidget(m_ruler);
65 QHBoxLayout *sizeLayout = new QHBoxLayout;
66 sizeLayout->setContentsMargins(0, 0, 0, 0);
67 sizeLayout->setSpacing(0);
68 m_view.size_frame->setLayout(sizeLayout);
70 QString style1 = "QToolButton {border-style: none;margin: 0px 3px;padding: 0px;} QToolButton:pressed:hover { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;} QToolButton:hover { background-color: rgba(255, 255, 255, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
72 QToolButton *butSmall = new QToolButton(this);
73 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
74 butSmall->setToolTip(i18n("Smaller tracks"));
75 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
76 sizeLayout->addWidget(butSmall);
78 QToolButton *butLarge = new QToolButton(this);
79 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
80 butLarge->setToolTip(i18n("Bigger tracks"));
81 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
82 sizeLayout->addWidget(butLarge);
83 m_view.size_frame->setStyleSheet(style1);
86 QHBoxLayout *tracksLayout = new QHBoxLayout;
87 tracksLayout->setContentsMargins(0, 0, 0, 0);
88 tracksLayout->setSpacing(0);
89 m_view.tracks_frame->setLayout(tracksLayout);
91 m_view.headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
92 m_view.headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
94 m_headersLayout = new QVBoxLayout;
95 m_headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
96 m_headersLayout->setSpacing(0);
97 m_view.headers_container->setLayout(m_headersLayout);
99 connect(m_view.headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
101 tracksLayout->addWidget(m_trackview);
103 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), m_view.headers_area->verticalScrollBar(), SLOT(setValue(int)));
104 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
106 parseDocument(m_doc->toXml());
107 int error = m_doc->setSceneList();
108 if (error == -1) *ok = false;
110 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
111 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
112 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
113 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
115 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
116 slotSetZone(m_doc->zone());
119 TrackView::~TrackView()
125 int TrackView::duration() const
127 return m_trackview->duration();
130 int TrackView::tracksNumber() const
132 return m_projectTracks - 1;
135 int TrackView::inPoint() const
137 return m_ruler->inPoint();
140 int TrackView::outPoint() const
142 return m_ruler->outPoint();
145 void TrackView::slotSetZone(QPoint p)
150 void TrackView::setDuration(int dur)
152 m_trackview->setDuration(dur);
153 m_ruler->setDuration(dur);
156 void TrackView::parseDocument(QDomDocument doc)
159 m_documentErrors.clear();
161 //kDebug() << "//// DOCUMENT: " << doc.toString();
162 /*QDomNode props = doc.elementsByTagName("properties").item(0);
163 if (!props.isNull()) {
164 cursorPos = props.toElement().attribute("timeline_position").toInt();
167 // parse project tracks
168 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
169 QDomNodeList tracks = doc.elementsByTagName("track");
170 QDomNodeList playlists = doc.elementsByTagName("playlist");
172 m_projectTracks = tracks.count();
173 int trackduration = 0;
177 int pos = m_projectTracks - 1;
178 m_invalidProducers.clear();
179 QDomNodeList producers = doc.elementsByTagName("producer");
180 for (int i = 0; i < producers.count(); i++) {
181 // Check for invalid producers
182 QDomNode n = producers.item(i);
186 // Check for invalid markup
187 QDomNodeList params = e.elementsByTagName("property");
188 for (int j = 0; j < params.count(); j++) {
189 QDomElement p = params.item(j).toElement();
190 if (p.attribute("name") == "markup") {
191 QString val = p.text().toUtf8().data();
192 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
193 //e.setAttribute("value", value);
194 n.removeChild(params.item(j));
200 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
201 int in = e.attribute("in").toInt();
202 int out = e.attribute("out").toInt();
203 if (in > out || in == out) {
204 // invalid producer, remove it
205 QString id = e.attribute("id");
206 m_invalidProducers.append(id);
207 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
208 doc.documentElement().removeChild(producers.at(i));
213 for (int i = 0; i < m_projectTracks; i++) {
214 e = tracks.item(i).toElement();
215 QString playlist_name = e.attribute("producer");
216 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
217 // find playlist related to this track
219 for (int j = 0; j < m_projectTracks; j++) {
220 p = playlists.item(j).toElement();
221 if (p.attribute("id") == playlist_name) break;
223 if (p.attribute("id") != playlist_name) { // then it didn't work.
224 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
226 if (e.attribute("hide") == "video") {
227 m_doc->switchTrackVideo(i - 1, true);
228 } else if (e.attribute("hide") == "audio") {
229 m_doc->switchTrackAudio(i - 1, true);
230 } else if (e.attribute("hide") == "both") {
231 m_doc->switchTrackVideo(i - 1, true);
232 m_doc->switchTrackAudio(i - 1, true);
235 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
237 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
238 if (trackduration > duration) duration = trackduration;
240 // background black track
241 for (int j = 0; j < m_projectTracks; j++) {
242 p = playlists.item(j).toElement();
243 if (p.attribute("id") == playlist_name) break;
245 int black_clips = p.childNodes().count();
246 for (int i = 0; i < black_clips; i++)
247 m_doc->loadingProgressed();
248 qApp->processEvents();
254 QDomNodeList transitions = doc.elementsByTagName("transition");
256 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
257 for (int i = 0; i < transitions.count(); i++) {
258 e = transitions.item(i).toElement();
259 QDomNodeList transitionparams = e.childNodes();
260 bool transitionAdd = true;
263 bool isAutomatic = false;
264 bool forceTrack = false;
265 QString mlt_geometry;
267 QString transitionId;
268 for (int k = 0; k < transitionparams.count(); k++) {
269 p = transitionparams.item(k).toElement();
271 QString paramName = p.attribute("name");
272 // do not add audio mixing transitions
273 if (paramName == "internal_added" && p.text() == "237") {
274 transitionAdd = false;
275 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
277 } else if (paramName == "a_track") a_track = p.text().toInt();
278 else if (paramName == "b_track") b_track = p.text().toInt();
279 else if (paramName == "mlt_service") mlt_service = p.text();
280 else if (paramName == "kdenlive_id") transitionId = p.text();
281 else if (paramName == "geometry") mlt_geometry = p.text();
282 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
283 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
286 if (transitionAdd || mlt_service != "mix") {
287 // Transition should be added to the scene
288 ItemInfo transitionInfo;
289 if (mlt_service == "composite" && transitionId.isEmpty()) {
290 // When adding composite transition, check if it is a wipe transition
291 if (mlt_geometry.count(';') == 1) {
292 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
293 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
294 QString start = mlt_geometry.section(';', 0, 0);
295 start = start.section(':', 0, 1);
296 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
297 QString end = mlt_geometry.section('=', 1, 1);
298 end = end.section(':', 0, 1);
299 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
300 start.append(',' + end);
301 QStringList numbers = start.split(',', QString::SkipEmptyParts);
302 bool isWipeTransition = true;
304 for (int i = 0; i < numbers.size(); ++i) {
305 checkNumber = qAbs(numbers.at(i).toInt());
306 if (checkNumber != 0 && checkNumber != 100) {
307 isWipeTransition = false;
311 if (isWipeTransition) transitionId = "slide";
314 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
316 for (int k = 0; k < transitionparams.count(); k++) {
317 p = transitionparams.item(k).toElement();
319 QString paramName = p.attribute("name");
320 QString paramValue = p.text();
322 QDomNodeList params = base.elementsByTagName("parameter");
323 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
324 QDomElement e = params.item(i).toElement();
325 if (!e.isNull() && e.attribute("tag") == paramName) {
326 if (e.attribute("type") == "double") {
327 QString factor = e.attribute("factor", "1");
330 if (factor.startsWith('%')) {
331 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
332 } else fact = factor.toDouble();
333 double val = paramValue.toDouble() * fact;
334 paramValue = QString::number(val);
337 e.setAttribute("value", paramValue);
345 doc.appendChild(doc.importNode(base, true));
346 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
348 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
349 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
350 transitionInfo.track = m_projectTracks - 1 - b_track;
351 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
352 if (transitionInfo.startPos >= transitionInfo.endPos) {
353 // invalid transition, remove it.
354 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
355 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
356 tractor.removeChild(transitions.item(i));
359 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
360 if (forceTrack) tr->setForcedTrack(true, a_track);
361 m_scene->addItem(tr);
362 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
363 tr->setItemLocked(true);
370 QDomNodeList guides = doc.elementsByTagName("guide");
371 for (int i = 0; i < guides.count(); i++) {
372 e = guides.item(i).toElement();
373 const QString comment = e.attribute("comment");
374 const GenTime pos = GenTime(e.attribute("time").toDouble());
375 m_trackview->addGuide(pos, comment);
379 QDomNodeList groups = doc.elementsByTagName("group");
380 m_trackview->loadGroups(groups);
381 m_trackview->setDuration(duration);
382 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
384 // Remove Kdenlive extra info from xml doc before sending it to MLT
385 QDomElement mlt = doc.firstChildElement("mlt");
386 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
387 mlt.removeChild(infoXml);
389 slotRebuildTrackHeaders();
390 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
391 //m_trackview->setCursorPos(cursorPos);
392 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
395 void TrackView::slotDeleteClip(const QString &clipId)
397 m_trackview->deleteClip(clipId);
400 void TrackView::setCursorPos(int pos)
402 m_trackview->setCursorPos(pos);
405 void TrackView::moveCursorPos(int pos)
407 m_trackview->setCursorPos(pos, false);
410 void TrackView::slotChangeZoom(int horizontal, int vertical)
412 m_ruler->setPixelPerMark(horizontal);
413 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal]; // m_ruler->comboScale[m_currentZoom] /
415 if (vertical == -1) {
417 m_doc->setZoom(horizontal, m_verticalZoom);
418 m_trackview->setScale(m_scale, m_scene->scale().y());
420 m_verticalZoom = vertical;
421 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
422 else m_trackview->setScale(m_scale, m_verticalZoom);
423 adjustTrackHeaders();
427 int TrackView::fitZoom() const
429 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
431 for (i = 0; i < 13; i++)
432 if (m_ruler->comboScale[i] > zoom) break;
436 KdenliveDoc *TrackView::document()
441 void TrackView::refresh()
443 m_trackview->viewport()->update();
446 void TrackView::slotRebuildTrackHeaders()
448 QList <TrackInfo> list = m_doc->tracksList();
450 while ((child = m_headersLayout->takeAt(0)) != 0) {
451 if (child->widget()) delete child->widget();
454 int max = list.count();
455 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
456 for (int i = 0; i < max; i++) {
457 HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), height, this);
458 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
459 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
460 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
462 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
463 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
464 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
465 m_headersLayout->addWidget(header);
470 void TrackView::adjustTrackHeaders()
472 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
474 for (int i = 0; i < m_headersLayout->count(); i++) {
475 child = m_headersLayout->itemAt(i);
476 if (child->widget())(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
480 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
484 QDomNodeList children = xml.childNodes();
485 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
486 QDomNode n = children.item(nodeindex);
487 QDomElement elem = n.toElement();
488 if (elem.tagName() == "blank") {
489 position += elem.attribute("length").toInt();
490 } else if (elem.tagName() == "entry") {
491 m_doc->loadingProgressed();
492 qApp->processEvents();
494 int in = elem.attribute("in").toInt();
495 int out = elem.attribute("out").toInt();
496 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
497 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
498 xml.removeChild(children.at(nodeindex));
502 QString idString = elem.attribute("producer");
503 QString id = idString;
505 if (idString.startsWith("slowmotion")) {
506 id = idString.section(':', 1, 1);
507 speed = idString.section(':', 2, 2).toDouble();
508 } else id = id.section('_', 0, 0);
509 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
511 // The clip in playlist was not listed in the kdenlive producers,
512 // something went wrong, repair required.
513 kWarning() << "CANNOT INSERT CLIP " << id;
515 clip = getMissingProducer(id);
517 // We cannot find the producer, something is really wrong, add
518 // placeholder color clip
520 QDomElement producerXml = doc.createElement("producer");
521 doc.appendChild(producerXml);
522 producerXml.setAttribute("colour", "0xff0000ff");
523 producerXml.setAttribute("mlt_service", "colour");
524 producerXml.setAttribute("length", "15000");
525 producerXml.setAttribute("name", "INVALID");
526 producerXml.setAttribute("type", COLOR);
527 producerXml.setAttribute("id", id);
528 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
529 xml.insertBefore(producerXml, QDomNode());
530 m_doc->clipManager()->addClip(clip);
532 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
534 // Found correct producer
535 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
536 elem.setAttribute("producer", clip->getId());
538 m_doc->setModified(true);
543 clipinfo.startPos = GenTime(position, m_doc->fps());
544 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
545 clipinfo.cropStart = GenTime(in, m_doc->fps());
547 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
548 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, false);
549 if (idString.endsWith("_video")) item->setVideoOnly(true);
550 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
551 m_scene->addItem(item);
552 if (locked) item->setItemLocked(true);
553 clip->addReference();
554 position += (out - in + 1);
556 // parse clip effects
557 QDomNodeList effects = elem.childNodes();
558 for (int ix = 0; ix < effects.count(); ix++) {
559 QDomElement effect = effects.at(ix).toElement();
560 if (effect.tagName() == "filter") {
561 // add effect to clip
565 QString ladspaEffectFile;
566 // Get effect tag & index
567 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
568 // parse effect parameters
569 QDomElement effectparam = n3.toElement();
570 if (effectparam.attribute("name") == "tag") {
571 effecttag = effectparam.text();
572 } else if (effectparam.attribute("name") == "kdenlive_id") {
573 effectid = effectparam.text();
574 } else if (effectparam.attribute("name") == "kdenlive_ix") {
575 effectindex = effectparam.text();
576 } else if (effectparam.attribute("name") == "src") {
577 ladspaEffectFile = effectparam.text();
578 if (!QFile::exists(ladspaEffectFile)) {
579 // If the ladspa effect file is missing, recreate it
580 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
581 ladspaEffectFile = m_doc->getLadspaFile();
582 effectparam.firstChild().setNodeValue(ladspaEffectFile);
583 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
587 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
588 // get effect standard tags
589 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
590 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
591 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
592 if (clipeffect.isNull()) {
593 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
594 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
595 elem.removeChild(effects.at(ix));
598 QDomElement currenteffect = clipeffect.cloneNode().toElement();
599 currenteffect.setAttribute("kdenlive_ix", effectindex);
600 QDomNodeList clipeffectparams = currenteffect.childNodes();
602 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
603 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
604 // effect is key-framable, read all effects to retrieve keyframes
608 QDomNodeList params = currenteffect.elementsByTagName("parameter");
609 for (int i = 0; i < params.count(); i++) {
610 QDomElement e = params.item(i).toElement();
611 if (e.attribute("type") == "keyframe") {
612 starttag = e.attribute("starttag", "start");
613 endtag = e.attribute("endtag", "end");
614 factor = e.attribute("factor", "1");
619 int effectin = effect.attribute("in").toInt();
620 int effectout = effect.attribute("out").toInt();
621 double startvalue = 0;
624 if (factor.isEmpty()) fact = 1;
625 else if (factor.startsWith('%')) {
626 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
627 } else fact = factor.toDouble();
628 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
629 // parse effect parameters
630 QDomElement effectparam = n3.toElement();
631 if (effectparam.attribute("name") == starttag)
632 startvalue = effectparam.text().toDouble() * fact;
633 if (effectparam.attribute("name") == endtag)
634 endvalue = effectparam.text().toDouble() * fact;
636 // add first keyframe
637 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
638 QDomNode lastParsedEffect;
640 QDomNode n2 = effects.at(ix);
641 bool continueParsing = true;
642 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
644 QDomElement kfreffect = n2.toElement();
645 int effectout = kfreffect.attribute("out").toInt();
647 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
648 // parse effect parameters
649 QDomElement subeffectparam = n4.toElement();
650 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
651 //We are not in the same effect, stop parsing
652 lastParsedEffect = n2.previousSibling();
654 continueParsing = false;
656 } else if (subeffectparam.attribute("name") == endtag) {
657 endvalue = subeffectparam.text().toDouble() * fact;
661 if (continueParsing) {
662 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
667 params = currenteffect.elementsByTagName("parameter");
668 for (int i = 0; i < params.count(); i++) {
669 QDomElement e = params.item(i).toElement();
670 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
672 if (!continueParsing) {
673 n2 = lastParsedEffect;
676 // Check if effect has in/out points
677 if (effect.hasAttribute("in")) {
678 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
680 if (effect.hasAttribute("out")) {
681 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
685 // adjust effect parameters
686 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
687 // parse effect parameters
688 QDomElement effectparam = n3.toElement();
689 QString paramname = effectparam.attribute("name");
690 QString paramvalue = effectparam.text();
693 // try to find this parameter in the effect xml
695 for (int k = 0; k < clipeffectparams.count(); k++) {
696 e = clipeffectparams.item(k).toElement();
697 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
698 if (e.attribute("factor", "1") != "1") {
699 QString factor = e.attribute("factor", "1");
701 if (factor.startsWith('%')) {
702 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
703 } else fact = factor.toDouble();
704 e.setAttribute("value", paramvalue.toDouble() * fact);
705 } else e.setAttribute("value", paramvalue);
710 if (effecttag == "ladspa") {
711 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
713 if (!QFile::exists(ladspaEffectFile)) {
714 // If the ladspa effect file is missing, recreate it
715 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
717 currenteffect.setAttribute("src", ladspaEffectFile);
719 item->addEffect(currenteffect, false);
720 item->effectsCounter();
725 //m_clipList.append(clip);
728 //m_trackDuration = position;
731 //documentTracks.insert(ix, track);
732 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
737 DocClipBase *TrackView::getMissingProducer(const QString id) const
739 QDomElement missingXml;
740 QDomDocument doc = m_doc->toXml();
741 QString docRoot = doc.documentElement().attribute("root");
742 if (!docRoot.endsWith('/')) docRoot.append('/');
743 QDomNodeList prods = doc.elementsByTagName("producer");
744 int maxprod = prods.count();
745 for (int i = 0; i < maxprod; i++) {
746 QDomNode m = prods.at(i);
747 QString prodId = m.toElement().attribute("id");
749 missingXml = m.toElement();
753 if (missingXml == QDomElement()) return NULL;
755 QDomNodeList params = missingXml.childNodes();
757 for (int j = 0; j < params.count(); j++) {
758 QDomElement e = params.item(j).toElement();
759 if (e.attribute("name") == "resource") {
760 resource = e.firstChild().nodeValue();
764 // prepend MLT XML document root if no path in clip resource and not a color clip
765 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
766 DocClipBase *missingClip = NULL;
767 if (!resource.isEmpty())
768 missingClip = m_doc->clipManager()->getClipByResource(resource);
772 QGraphicsScene *TrackView::projectScene()
777 CustomTrackView *TrackView::projectView()
782 void TrackView::setEditMode(const QString & editMode)
784 m_editMode = editMode;
787 const QString & TrackView::editMode() const
792 void TrackView::slotChangeTrackLock(int ix, bool lock)
794 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
795 widgets.at(ix)->setLock(lock);
798 void TrackView::slotVerticalZoomDown()
800 if (m_verticalZoom == 0) return;
802 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
803 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
804 else m_trackview->setScale(m_scene->scale().x(), 1);
805 adjustTrackHeaders();
806 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() / 2);
807 m_trackview->checkTrackHeight(false);*/
810 void TrackView::slotVerticalZoomUp()
812 if (m_verticalZoom == 2) return;
814 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
815 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() * 2);
816 m_trackview->checkTrackHeight(false);*/
817 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
818 else m_trackview->setScale(m_scene->scale().x(), 1);
819 adjustTrackHeaders();
822 void TrackView::updateProjectFps()
824 m_ruler->updateProjectFps(m_doc->timecode());
827 #include "trackview.moc"