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;
506 if (idString.startsWith("slowmotion")) {
507 id = idString.section(':', 1, 1);
508 speed = idString.section(':', 2, 2).toDouble();
509 strobe = idString.section(':', 3, 3).toInt();
510 if (strobe == 0) strobe = 1;
511 } else id = id.section('_', 0, 0);
512 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
514 // The clip in playlist was not listed in the kdenlive producers,
515 // something went wrong, repair required.
516 kWarning() << "CANNOT INSERT CLIP " << id;
518 clip = getMissingProducer(id);
520 // We cannot find the producer, something is really wrong, add
521 // placeholder color clip
523 QDomElement producerXml = doc.createElement("producer");
524 doc.appendChild(producerXml);
525 producerXml.setAttribute("colour", "0xff0000ff");
526 producerXml.setAttribute("mlt_service", "colour");
527 producerXml.setAttribute("length", "15000");
528 producerXml.setAttribute("name", "INVALID");
529 producerXml.setAttribute("type", COLOR);
530 producerXml.setAttribute("id", id);
531 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
532 xml.insertBefore(producerXml, QDomNode());
533 m_doc->clipManager()->addClip(clip);
535 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
537 // Found correct producer
538 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
539 elem.setAttribute("producer", clip->getId());
541 m_doc->setModified(true);
546 clipinfo.startPos = GenTime(position, m_doc->fps());
547 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
548 clipinfo.cropStart = GenTime(in, m_doc->fps());
550 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
551 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
552 if (idString.endsWith("_video")) item->setVideoOnly(true);
553 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
554 m_scene->addItem(item);
555 if (locked) item->setItemLocked(true);
556 clip->addReference();
557 position += (out - in + 1);
558 kDebug() << "/////////\n\n\n" << "CLIP SPEED: " << speed << ", " << strobe << "\n\n\n/////////////////////";
559 if (speed != 1.0 || strobe > 1) {
560 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
561 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
562 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
563 item->addEffect(speedeffect, false);
564 item->effectsCounter();
567 // parse clip effects
568 QDomNodeList effects = elem.childNodes();
569 for (int ix = 0; ix < effects.count(); ix++) {
570 QDomElement effect = effects.at(ix).toElement();
571 if (effect.tagName() == "filter") {
572 // add effect to clip
576 QString ladspaEffectFile;
577 // Get effect tag & index
578 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
579 // parse effect parameters
580 QDomElement effectparam = n3.toElement();
581 if (effectparam.attribute("name") == "tag") {
582 effecttag = effectparam.text();
583 } else if (effectparam.attribute("name") == "kdenlive_id") {
584 effectid = effectparam.text();
585 } else if (effectparam.attribute("name") == "kdenlive_ix") {
586 effectindex = effectparam.text();
587 } else if (effectparam.attribute("name") == "src") {
588 ladspaEffectFile = effectparam.text();
589 if (!QFile::exists(ladspaEffectFile)) {
590 // If the ladspa effect file is missing, recreate it
591 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
592 ladspaEffectFile = m_doc->getLadspaFile();
593 effectparam.firstChild().setNodeValue(ladspaEffectFile);
594 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
598 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
599 // get effect standard tags
600 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
601 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
602 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
603 if (clipeffect.isNull()) {
604 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
605 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
606 elem.removeChild(effects.at(ix));
609 QDomElement currenteffect = clipeffect.cloneNode().toElement();
610 currenteffect.setAttribute("kdenlive_ix", effectindex);
611 QDomNodeList clipeffectparams = currenteffect.childNodes();
613 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
614 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
615 // effect is key-framable, read all effects to retrieve keyframes
619 QDomNodeList params = currenteffect.elementsByTagName("parameter");
620 for (int i = 0; i < params.count(); i++) {
621 QDomElement e = params.item(i).toElement();
622 if (e.attribute("type") == "keyframe") {
623 starttag = e.attribute("starttag", "start");
624 endtag = e.attribute("endtag", "end");
625 factor = e.attribute("factor", "1");
630 int effectin = effect.attribute("in").toInt();
631 int effectout = effect.attribute("out").toInt();
632 double startvalue = 0;
635 if (factor.isEmpty()) fact = 1;
636 else if (factor.startsWith('%')) {
637 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
638 } else fact = factor.toDouble();
639 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
640 // parse effect parameters
641 QDomElement effectparam = n3.toElement();
642 if (effectparam.attribute("name") == starttag)
643 startvalue = effectparam.text().toDouble() * fact;
644 if (effectparam.attribute("name") == endtag)
645 endvalue = effectparam.text().toDouble() * fact;
647 // add first keyframe
648 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
649 QDomNode lastParsedEffect;
651 QDomNode n2 = effects.at(ix);
652 bool continueParsing = true;
653 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
655 QDomElement kfreffect = n2.toElement();
656 int effectout = kfreffect.attribute("out").toInt();
658 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
659 // parse effect parameters
660 QDomElement subeffectparam = n4.toElement();
661 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
662 //We are not in the same effect, stop parsing
663 lastParsedEffect = n2.previousSibling();
665 continueParsing = false;
667 } else if (subeffectparam.attribute("name") == endtag) {
668 endvalue = subeffectparam.text().toDouble() * fact;
672 if (continueParsing) {
673 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
678 params = currenteffect.elementsByTagName("parameter");
679 for (int i = 0; i < params.count(); i++) {
680 QDomElement e = params.item(i).toElement();
681 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
683 if (!continueParsing) {
684 n2 = lastParsedEffect;
687 // Check if effect has in/out points
688 if (effect.hasAttribute("in")) {
689 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
691 if (effect.hasAttribute("out")) {
692 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
696 // adjust effect parameters
697 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
698 // parse effect parameters
699 QDomElement effectparam = n3.toElement();
700 QString paramname = effectparam.attribute("name");
701 QString paramvalue = effectparam.text();
704 // try to find this parameter in the effect xml
706 for (int k = 0; k < clipeffectparams.count(); k++) {
707 e = clipeffectparams.item(k).toElement();
708 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
709 if (e.attribute("factor", "1") != "1") {
710 QString factor = e.attribute("factor", "1");
712 if (factor.startsWith('%')) {
713 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
714 } else fact = factor.toDouble();
715 e.setAttribute("value", paramvalue.toDouble() * fact);
716 } else e.setAttribute("value", paramvalue);
721 if (effecttag == "ladspa") {
722 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
724 if (!QFile::exists(ladspaEffectFile)) {
725 // If the ladspa effect file is missing, recreate it
726 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
728 currenteffect.setAttribute("src", ladspaEffectFile);
730 item->addEffect(currenteffect, false);
731 item->effectsCounter();
736 //m_clipList.append(clip);
739 //m_trackDuration = position;
742 //documentTracks.insert(ix, track);
743 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
748 DocClipBase *TrackView::getMissingProducer(const QString id) const
750 QDomElement missingXml;
751 QDomDocument doc = m_doc->toXml();
752 QString docRoot = doc.documentElement().attribute("root");
753 if (!docRoot.endsWith('/')) docRoot.append('/');
754 QDomNodeList prods = doc.elementsByTagName("producer");
755 int maxprod = prods.count();
756 for (int i = 0; i < maxprod; i++) {
757 QDomNode m = prods.at(i);
758 QString prodId = m.toElement().attribute("id");
760 missingXml = m.toElement();
764 if (missingXml == QDomElement()) return NULL;
766 QDomNodeList params = missingXml.childNodes();
768 for (int j = 0; j < params.count(); j++) {
769 QDomElement e = params.item(j).toElement();
770 if (e.attribute("name") == "resource") {
771 resource = e.firstChild().nodeValue();
775 // prepend MLT XML document root if no path in clip resource and not a color clip
776 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
777 DocClipBase *missingClip = NULL;
778 if (!resource.isEmpty())
779 missingClip = m_doc->clipManager()->getClipByResource(resource);
783 QGraphicsScene *TrackView::projectScene()
788 CustomTrackView *TrackView::projectView()
793 void TrackView::setEditMode(const QString & editMode)
795 m_editMode = editMode;
798 const QString & TrackView::editMode() const
803 void TrackView::slotChangeTrackLock(int ix, bool lock)
805 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
806 widgets.at(ix)->setLock(lock);
809 void TrackView::slotVerticalZoomDown()
811 if (m_verticalZoom == 0) return;
813 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
814 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
815 else m_trackview->setScale(m_scene->scale().x(), 1);
816 adjustTrackHeaders();
817 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() / 2);
818 m_trackview->checkTrackHeight(false);*/
821 void TrackView::slotVerticalZoomUp()
823 if (m_verticalZoom == 2) return;
825 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
826 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() * 2);
827 m_trackview->checkTrackHeight(false);*/
828 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
829 else m_trackview->setScale(m_scene->scale().x(), 1);
830 adjustTrackHeaders();
833 void TrackView::updateProjectFps()
835 m_ruler->updateProjectFps(m_doc->timecode());
838 #include "trackview.moc"