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>
39 #include <QInputDialog>
41 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
51 m_scene = new CustomTrackScene(doc);
52 m_trackview = new CustomTrackView(doc, m_scene, parent);
53 m_trackview->scale(1, 1);
54 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
55 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
57 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
58 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
59 QHBoxLayout *layout = new QHBoxLayout;
60 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
61 layout->setSpacing(0);
62 m_view.ruler_frame->setLayout(layout);
63 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;}";
73 QToolButton *butSmall = new QToolButton(this);
74 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
75 butSmall->setToolTip(i18n("Smaller tracks"));
76 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
77 sizeLayout->addWidget(butSmall);
79 QToolButton *butLarge = new QToolButton(this);
80 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
81 butLarge->setToolTip(i18n("Bigger tracks"));
82 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
83 sizeLayout->addWidget(butLarge);
84 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);
98 connect(m_view.headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
100 tracksLayout->addWidget(m_trackview);
101 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), m_view.headers_area->verticalScrollBar(), SLOT(setValue(int)));
102 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
104 parseDocument(m_doc->toXml());
105 int error = m_doc->setSceneList();
106 if (error == -1) *ok = false;
108 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
109 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
110 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
111 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
113 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
114 slotSetZone(m_doc->zone());
117 TrackView::~TrackView()
123 int TrackView::duration() const
125 return m_trackview->duration();
128 int TrackView::tracksNumber() const
130 return m_projectTracks - 1;
133 int TrackView::inPoint() const
135 return m_ruler->inPoint();
138 int TrackView::outPoint() const
140 return m_ruler->outPoint();
143 void TrackView::slotSetZone(QPoint p)
148 void TrackView::setDuration(int dur)
150 m_trackview->setDuration(dur);
151 m_ruler->setDuration(dur);
154 void TrackView::parseDocument(QDomDocument doc)
157 m_documentErrors.clear();
159 //kDebug() << "//// DOCUMENT: " << doc.toString();
160 /*QDomNode props = doc.elementsByTagName("properties").item(0);
161 if (!props.isNull()) {
162 cursorPos = props.toElement().attribute("timeline_position").toInt();
165 // parse project tracks
166 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
167 QDomNodeList tracks = doc.elementsByTagName("track");
168 QDomNodeList playlists = doc.elementsByTagName("playlist");
170 m_projectTracks = tracks.count();
171 int trackduration = 0;
175 int pos = m_projectTracks - 1;
176 m_invalidProducers.clear();
177 QDomNodeList producers = doc.elementsByTagName("producer");
178 for (int i = 0; i < producers.count(); i++) {
179 // Check for invalid producers
180 QDomNode n = producers.item(i);
184 // Check for invalid markup
185 QDomNodeList params = e.elementsByTagName("property");
186 for (int j = 0; j < params.count(); j++) {
187 QDomElement p = params.item(j).toElement();
188 if (p.attribute("name") == "markup") {
189 QString val = p.text().toUtf8().data();
190 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
191 //e.setAttribute("value", value);
192 n.removeChild(params.item(j));
198 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
199 int in = e.attribute("in").toInt();
200 int out = e.attribute("out").toInt();
201 if (in > out || in == out) {
202 // invalid producer, remove it
203 QString id = e.attribute("id");
204 m_invalidProducers.append(id);
205 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
206 doc.documentElement().removeChild(producers.at(i));
211 for (int i = 0; i < m_projectTracks; i++) {
212 e = tracks.item(i).toElement();
213 QString playlist_name = e.attribute("producer");
214 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
215 // find playlist related to this track
217 for (int j = 0; j < m_projectTracks; j++) {
218 p = playlists.item(j).toElement();
219 if (p.attribute("id") == playlist_name) break;
221 if (p.attribute("id") != playlist_name) { // then it didn't work.
222 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
224 if (e.attribute("hide") == "video") {
225 m_doc->switchTrackVideo(i - 1, true);
226 } else if (e.attribute("hide") == "audio") {
227 m_doc->switchTrackAudio(i - 1, true);
228 } else if (e.attribute("hide") == "both") {
229 m_doc->switchTrackVideo(i - 1, true);
230 m_doc->switchTrackAudio(i - 1, true);
233 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
235 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
236 if (trackduration > duration) duration = trackduration;
238 // background black track
239 for (int j = 0; j < m_projectTracks; j++) {
240 p = playlists.item(j).toElement();
241 if (p.attribute("id") == playlist_name) break;
243 int black_clips = p.childNodes().count();
244 for (int i = 0; i < black_clips; i++)
245 m_doc->loadingProgressed();
246 qApp->processEvents();
252 QDomNodeList transitions = doc.elementsByTagName("transition");
254 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
255 for (int i = 0; i < transitions.count(); i++) {
256 e = transitions.item(i).toElement();
257 QDomNodeList transitionparams = e.childNodes();
258 bool transitionAdd = true;
261 bool isAutomatic = false;
262 bool forceTrack = false;
263 QString mlt_geometry;
265 QString transitionId;
266 for (int k = 0; k < transitionparams.count(); k++) {
267 p = transitionparams.item(k).toElement();
269 QString paramName = p.attribute("name");
270 // do not add audio mixing transitions
271 if (paramName == "internal_added" && p.text() == "237") {
272 transitionAdd = false;
273 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
275 } else if (paramName == "a_track") a_track = p.text().toInt();
276 else if (paramName == "b_track") b_track = p.text().toInt();
277 else if (paramName == "mlt_service") mlt_service = p.text();
278 else if (paramName == "kdenlive_id") transitionId = p.text();
279 else if (paramName == "geometry") mlt_geometry = p.text();
280 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
281 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
284 if (transitionAdd || mlt_service != "mix") {
285 // Transition should be added to the scene
286 ItemInfo transitionInfo;
287 if (mlt_service == "composite" && transitionId.isEmpty()) {
288 // When adding composite transition, check if it is a wipe transition
289 if (mlt_geometry.count(';') == 1) {
290 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
291 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
292 QString start = mlt_geometry.section(';', 0, 0);
293 start = start.section(':', 0, 1);
294 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
295 QString end = mlt_geometry.section('=', 1, 1);
296 end = end.section(':', 0, 1);
297 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
298 start.append(',' + end);
299 QStringList numbers = start.split(',', QString::SkipEmptyParts);
300 bool isWipeTransition = true;
302 for (int i = 0; i < numbers.size(); ++i) {
303 checkNumber = qAbs(numbers.at(i).toInt());
304 if (checkNumber != 0 && checkNumber != 100) {
305 isWipeTransition = false;
309 if (isWipeTransition) transitionId = "slide";
312 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
314 for (int k = 0; k < transitionparams.count(); k++) {
315 p = transitionparams.item(k).toElement();
317 QString paramName = p.attribute("name");
318 QString paramValue = p.text();
320 QDomNodeList params = base.elementsByTagName("parameter");
321 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
322 QDomElement e = params.item(i).toElement();
323 if (!e.isNull() && e.attribute("tag") == paramName) {
324 if (e.attribute("type") == "double") {
325 QString factor = e.attribute("factor", "1");
328 if (factor.startsWith('%')) {
329 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
330 } else fact = factor.toDouble();
331 double val = paramValue.toDouble() * fact;
332 paramValue = QString::number(val);
335 e.setAttribute("value", paramValue);
343 doc.appendChild(doc.importNode(base, true));
344 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
346 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
347 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
348 transitionInfo.track = m_projectTracks - 1 - b_track;
349 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
350 if (transitionInfo.startPos >= transitionInfo.endPos) {
351 // invalid transition, remove it.
352 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
353 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
354 tractor.removeChild(transitions.item(i));
357 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
358 if (forceTrack) tr->setForcedTrack(true, a_track);
359 m_scene->addItem(tr);
360 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
361 tr->setItemLocked(true);
368 QDomNodeList guides = doc.elementsByTagName("guide");
369 for (int i = 0; i < guides.count(); i++) {
370 e = guides.item(i).toElement();
371 const QString comment = e.attribute("comment");
372 const GenTime pos = GenTime(e.attribute("time").toDouble());
373 m_trackview->addGuide(pos, comment);
377 QDomNodeList groups = doc.elementsByTagName("group");
378 m_trackview->loadGroups(groups);
379 m_trackview->setDuration(duration);
380 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
382 // Remove Kdenlive extra info from xml doc before sending it to MLT
383 QDomElement mlt = doc.firstChildElement("mlt");
384 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
385 mlt.removeChild(infoXml);
387 slotRebuildTrackHeaders();
388 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
389 //m_trackview->setCursorPos(cursorPos);
390 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
393 void TrackView::slotDeleteClip(const QString &clipId)
395 m_trackview->deleteClip(clipId);
398 void TrackView::setCursorPos(int pos)
400 m_trackview->setCursorPos(pos);
403 void TrackView::moveCursorPos(int pos)
405 m_trackview->setCursorPos(pos, false);
408 void TrackView::slotChangeZoom(int horizontal, int vertical)
410 m_ruler->setPixelPerMark(horizontal);
411 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal]; // m_ruler->comboScale[m_currentZoom] /
413 if (vertical == -1) {
415 m_doc->setZoom(horizontal, m_verticalZoom);
416 m_trackview->setScale(m_scale, m_scene->scale().y());
418 m_verticalZoom = vertical;
419 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
420 else m_trackview->setScale(m_scale, m_verticalZoom);
421 adjustTrackHeaders();
425 int TrackView::fitZoom() const
427 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
429 for (i = 0; i < 13; i++)
430 if (m_ruler->comboScale[i] > zoom) break;
434 KdenliveDoc *TrackView::document()
439 void TrackView::refresh()
441 m_trackview->viewport()->update();
444 void TrackView::slotRebuildTrackHeaders()
446 kDebug() << "--------- - - - -REBUILD TLK HEAD";
447 const QList <TrackInfo> list = m_doc->tracksList();
449 m_view.headers_container->hide();
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();
457 for (int i = 0; i < max; i++) {
458 HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), height, this);
459 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
460 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
461 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
463 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
464 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
465 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
466 connect(header, SIGNAL(renameTrack(int)), this, SLOT(slotRenameTrack(int)));
467 m_headersLayout->addWidget(header);
469 m_view.headers_container->show();
473 void TrackView::adjustTrackHeaders()
475 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
477 for (int i = 0; i < m_headersLayout->count(); i++) {
478 child = m_headersLayout->itemAt(i);
479 if (child->widget())(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
483 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
487 QDomNodeList children = xml.childNodes();
488 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
489 QDomNode n = children.item(nodeindex);
490 QDomElement elem = n.toElement();
491 if (elem.tagName() == "blank") {
492 position += elem.attribute("length").toInt();
493 } else if (elem.tagName() == "entry") {
494 m_doc->loadingProgressed();
495 qApp->processEvents();
497 int in = elem.attribute("in").toInt();
498 int out = elem.attribute("out").toInt();
499 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
500 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
501 xml.removeChild(children.at(nodeindex));
505 QString idString = elem.attribute("producer");
506 QString id = idString;
509 if (idString.startsWith("slowmotion")) {
510 id = idString.section(':', 1, 1);
511 speed = idString.section(':', 2, 2).toDouble();
512 strobe = idString.section(':', 3, 3).toInt();
513 if (strobe == 0) strobe = 1;
514 } else id = id.section('_', 0, 0);
515 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
517 // The clip in playlist was not listed in the kdenlive producers,
518 // something went wrong, repair required.
519 kWarning() << "CANNOT INSERT CLIP " << id;
521 clip = getMissingProducer(id);
523 // We cannot find the producer, something is really wrong, add
524 // placeholder color clip
526 QDomElement producerXml = doc.createElement("producer");
527 doc.appendChild(producerXml);
528 producerXml.setAttribute("colour", "0xff0000ff");
529 producerXml.setAttribute("mlt_service", "colour");
530 producerXml.setAttribute("length", "15000");
531 producerXml.setAttribute("name", "INVALID");
532 producerXml.setAttribute("type", COLOR);
533 producerXml.setAttribute("id", id);
534 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
535 xml.insertBefore(producerXml, QDomNode());
536 m_doc->clipManager()->addClip(clip);
538 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
540 // Found correct producer
541 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
542 elem.setAttribute("producer", clip->getId());
544 m_doc->setModified(true);
549 clipinfo.startPos = GenTime(position, m_doc->fps());
550 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
551 clipinfo.cropStart = GenTime(in, m_doc->fps());
553 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
554 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
555 if (idString.endsWith("_video")) item->setVideoOnly(true);
556 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
557 m_scene->addItem(item);
558 if (locked) item->setItemLocked(true);
559 clip->addReference();
560 position += (out - in + 1);
561 kDebug() << "/////////\n\n\n" << "CLIP SPEED: " << speed << ", " << strobe << "\n\n\n/////////////////////";
562 if (speed != 1.0 || strobe > 1) {
563 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
564 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
565 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
566 item->addEffect(speedeffect, false);
567 item->effectsCounter();
570 // parse clip effects
571 QDomNodeList effects = elem.childNodes();
572 for (int ix = 0; ix < effects.count(); ix++) {
573 QDomElement effect = effects.at(ix).toElement();
574 if (effect.tagName() == "filter") {
575 // add effect to clip
579 QString ladspaEffectFile;
580 // Get effect tag & index
581 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
582 // parse effect parameters
583 QDomElement effectparam = n3.toElement();
584 if (effectparam.attribute("name") == "tag") {
585 effecttag = effectparam.text();
586 } else if (effectparam.attribute("name") == "kdenlive_id") {
587 effectid = effectparam.text();
588 } else if (effectparam.attribute("name") == "kdenlive_ix") {
589 effectindex = effectparam.text();
590 } else if (effectparam.attribute("name") == "src") {
591 ladspaEffectFile = effectparam.text();
592 if (!QFile::exists(ladspaEffectFile)) {
593 // If the ladspa effect file is missing, recreate it
594 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
595 ladspaEffectFile = m_doc->getLadspaFile();
596 effectparam.firstChild().setNodeValue(ladspaEffectFile);
597 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
601 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
602 // get effect standard tags
603 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
604 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
605 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
606 if (clipeffect.isNull()) {
607 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
608 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
609 elem.removeChild(effects.at(ix));
612 QDomElement currenteffect = clipeffect.cloneNode().toElement();
613 currenteffect.setAttribute("kdenlive_ix", effectindex);
614 QDomNodeList clipeffectparams = currenteffect.childNodes();
616 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
617 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
618 // effect is key-framable, read all effects to retrieve keyframes
622 QDomNodeList params = currenteffect.elementsByTagName("parameter");
623 for (int i = 0; i < params.count(); i++) {
624 QDomElement e = params.item(i).toElement();
625 if (e.attribute("type") == "keyframe") {
626 starttag = e.attribute("starttag", "start");
627 endtag = e.attribute("endtag", "end");
628 factor = e.attribute("factor", "1");
633 int effectin = effect.attribute("in").toInt();
634 int effectout = effect.attribute("out").toInt();
635 double startvalue = 0;
638 if (factor.isEmpty()) fact = 1;
639 else if (factor.startsWith('%')) {
640 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
641 } else fact = factor.toDouble();
642 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
643 // parse effect parameters
644 QDomElement effectparam = n3.toElement();
645 if (effectparam.attribute("name") == starttag)
646 startvalue = effectparam.text().toDouble() * fact;
647 if (effectparam.attribute("name") == endtag)
648 endvalue = effectparam.text().toDouble() * fact;
650 // add first keyframe
651 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
652 QDomNode lastParsedEffect;
654 QDomNode n2 = effects.at(ix);
655 bool continueParsing = true;
656 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
658 QDomElement kfreffect = n2.toElement();
659 int effectout = kfreffect.attribute("out").toInt();
661 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
662 // parse effect parameters
663 QDomElement subeffectparam = n4.toElement();
664 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
665 //We are not in the same effect, stop parsing
666 lastParsedEffect = n2.previousSibling();
668 continueParsing = false;
670 } else if (subeffectparam.attribute("name") == endtag) {
671 endvalue = subeffectparam.text().toDouble() * fact;
675 if (continueParsing) {
676 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
681 params = currenteffect.elementsByTagName("parameter");
682 for (int i = 0; i < params.count(); i++) {
683 QDomElement e = params.item(i).toElement();
684 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
686 if (!continueParsing) {
687 n2 = lastParsedEffect;
690 // Check if effect has in/out points
691 if (effect.hasAttribute("in")) {
692 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
694 if (effect.hasAttribute("out")) {
695 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
699 // adjust effect parameters
700 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
701 // parse effect parameters
702 QDomElement effectparam = n3.toElement();
703 QString paramname = effectparam.attribute("name");
704 QString paramvalue = effectparam.text();
707 // try to find this parameter in the effect xml
709 for (int k = 0; k < clipeffectparams.count(); k++) {
710 e = clipeffectparams.item(k).toElement();
711 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
712 if (e.attribute("factor", "1") != "1") {
713 QString factor = e.attribute("factor", "1");
715 if (factor.startsWith('%')) {
716 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
717 } else fact = factor.toDouble();
718 e.setAttribute("value", paramvalue.toDouble() * fact);
719 } else e.setAttribute("value", paramvalue);
724 if (effecttag == "ladspa") {
725 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
727 if (!QFile::exists(ladspaEffectFile)) {
728 // If the ladspa effect file is missing, recreate it
729 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
731 currenteffect.setAttribute("src", ladspaEffectFile);
733 item->addEffect(currenteffect, false);
734 item->effectsCounter();
739 //m_clipList.append(clip);
742 //m_trackDuration = position;
745 //documentTracks.insert(ix, track);
746 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
751 DocClipBase *TrackView::getMissingProducer(const QString id) const
753 QDomElement missingXml;
754 QDomDocument doc = m_doc->toXml();
755 QString docRoot = doc.documentElement().attribute("root");
756 if (!docRoot.endsWith('/')) docRoot.append('/');
757 QDomNodeList prods = doc.elementsByTagName("producer");
758 int maxprod = prods.count();
759 for (int i = 0; i < maxprod; i++) {
760 QDomNode m = prods.at(i);
761 QString prodId = m.toElement().attribute("id");
763 missingXml = m.toElement();
767 if (missingXml == QDomElement()) return NULL;
769 QDomNodeList params = missingXml.childNodes();
771 for (int j = 0; j < params.count(); j++) {
772 QDomElement e = params.item(j).toElement();
773 if (e.attribute("name") == "resource") {
774 resource = e.firstChild().nodeValue();
778 // prepend MLT XML document root if no path in clip resource and not a color clip
779 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
780 DocClipBase *missingClip = NULL;
781 if (!resource.isEmpty())
782 missingClip = m_doc->clipManager()->getClipByResource(resource);
786 QGraphicsScene *TrackView::projectScene()
791 CustomTrackView *TrackView::projectView()
796 void TrackView::setEditMode(const QString & editMode)
798 m_editMode = editMode;
801 const QString & TrackView::editMode() const
806 void TrackView::slotChangeTrackLock(int ix, bool lock)
808 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
809 widgets.at(ix)->setLock(lock);
812 void TrackView::slotVerticalZoomDown()
814 if (m_verticalZoom == 0) return;
816 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
817 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
818 else m_trackview->setScale(m_scene->scale().x(), 1);
819 adjustTrackHeaders();
820 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() / 2);
821 m_trackview->checkTrackHeight(false);*/
824 void TrackView::slotVerticalZoomUp()
826 if (m_verticalZoom == 2) return;
828 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
829 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() * 2);
830 m_trackview->checkTrackHeight(false);*/
831 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
832 else m_trackview->setScale(m_scene->scale().x(), 1);
833 adjustTrackHeaders();
836 void TrackView::updateProjectFps()
838 m_ruler->updateProjectFps(m_doc->timecode());
841 void TrackView::slotRenameTrack(int ix)
843 int tracknumber = m_doc->tracksCount() - ix;
844 TrackInfo info = m_doc->trackInfoAt(tracknumber - 1);
846 QString newName = QInputDialog::getText(this, i18n("New Track Name"), i18n("Enter new name"), QLineEdit::Normal, info.trackName, &ok);
848 info.trackName = newName;
849 m_doc->setTrackType(tracknumber - 1, info);
850 QTimer::singleShot(300, this, SLOT(slotRebuildTrackHeaders()));
851 m_doc->setModified(true);
856 #include "trackview.moc"