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"
34 #include "configtrackscommand.h"
37 #include <KMessageBox>
38 #include <KIO/NetAccess>
41 #include <QInputDialog>
43 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
52 // ruler_frame->setMaximumHeight();
53 // size_frame->setMaximumHeight();
54 m_scene = new CustomTrackScene(doc);
55 m_trackview = new CustomTrackView(doc, m_scene, parent);
56 m_trackview->scale(1, 1);
57 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
58 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
60 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
61 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
62 connect(m_ruler, SIGNAL(adjustZoom(int)), this, SIGNAL(setZoom(int)));
63 QHBoxLayout *layout = new QHBoxLayout;
64 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
65 layout->setSpacing(0);
66 ruler_frame->setLayout(layout);
67 layout->addWidget(m_ruler);
69 QHBoxLayout *sizeLayout = new QHBoxLayout;
70 sizeLayout->setContentsMargins(0, 0, 0, 0);
71 sizeLayout->setSpacing(0);
72 size_frame->setLayout(sizeLayout);
74 QToolButton *butSmall = new QToolButton(this);
75 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
76 butSmall->setToolTip(i18n("Smaller tracks"));
77 butSmall->setAutoRaise(true);
78 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
79 sizeLayout->addWidget(butSmall);
81 QToolButton *butLarge = new QToolButton(this);
82 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
83 butLarge->setToolTip(i18n("Bigger tracks"));
84 butLarge->setAutoRaise(true);
85 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
86 sizeLayout->addWidget(butLarge);
88 QHBoxLayout *tracksLayout = new QHBoxLayout;
89 tracksLayout->setContentsMargins(0, 0, 0, 0);
90 tracksLayout->setSpacing(0);
91 tracks_frame->setLayout(tracksLayout);
93 headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
94 headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 headers_area->setFixedWidth(70);
97 QVBoxLayout *headersLayout = new QVBoxLayout;
98 headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
99 headersLayout->setSpacing(0);
100 headers_container->setLayout(headersLayout);
101 connect(headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
103 tracksLayout->addWidget(m_trackview);
104 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), headers_area->verticalScrollBar(), SLOT(setValue(int)));
105 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
106 connect(m_trackview, SIGNAL(tracksChanged()), this, SLOT(slotReloadTracks()));
107 connect(m_trackview, SIGNAL(updateTrackHeaders()), this, SLOT(slotRepaintTracks()));
109 parseDocument(m_doc->toXml());
110 if (m_doc->setSceneList() == -1) *ok = false;
112 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
113 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
114 connect(m_trackview->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(slotUpdateVerticalScroll(int, int)));
115 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
116 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
118 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
119 slotSetZone(m_doc->zone());
122 TrackView::~TrackView()
129 void TrackView::keyPressEvent(QKeyEvent * event)
131 if (event->key() == Qt::Key_Up) {
132 m_trackview->slotTrackUp();
134 } else if (event->key() == Qt::Key_Down) {
135 m_trackview->slotTrackDown();
137 } else QWidget::keyPressEvent(event);
140 int TrackView::duration() const
142 return m_trackview->duration();
145 int TrackView::tracksNumber() const
147 return m_projectTracks - 1;
150 bool TrackView::checkProjectAudio() const
152 bool hasAudio = false;
153 const QList <TrackInfo> list = m_doc->tracksList();
154 int max = list.count();
155 for (int i = 0; i < max; i++) {
156 TrackInfo info = list.at(max - i - 1);
157 if (!info.isMute && m_trackview->hasAudio(i)) {
165 int TrackView::inPoint() const
167 return m_ruler->inPoint();
170 int TrackView::outPoint() const
172 return m_ruler->outPoint();
175 void TrackView::slotSetZone(QPoint p)
180 void TrackView::setDuration(int dur)
182 m_trackview->setDuration(dur);
183 m_ruler->setDuration(dur);
186 void TrackView::parseDocument(QDomDocument doc)
189 m_documentErrors.clear();
191 //kDebug() << "//// DOCUMENT: " << doc.toString();
192 /*QDomNode props = doc.elementsByTagName("properties").item(0);
193 if (!props.isNull()) {
194 cursorPos = props.toElement().attribute("timeline_position").toInt();
197 // parse project tracks
198 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
199 QDomNodeList tracks = doc.elementsByTagName("track");
200 QDomNodeList playlists = doc.elementsByTagName("playlist");
202 m_projectTracks = tracks.count();
203 int trackduration = 0;
207 int pos = m_projectTracks - 1;
208 m_invalidProducers.clear();
209 QDomNodeList producers = doc.elementsByTagName("producer");
210 for (int i = 0; i < producers.count(); i++) {
211 // Check for invalid producers
212 QDomNode n = producers.item(i);
216 // Check for invalid markup
217 QDomNodeList params = e.elementsByTagName("property");
218 for (int j = 0; j < params.count(); j++) {
219 QDomElement p = params.item(j).toElement();
220 if (p.attribute("name") == "markup") {
221 QString val = p.text().toUtf8().data();
222 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
223 //e.setAttribute("value", value);
224 n.removeChild(params.item(j));
230 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
231 int in = e.attribute("in").toInt();
232 int out = e.attribute("out").toInt();
233 if (in > out || in == out) {
234 // invalid producer, remove it
235 QString id = e.attribute("id");
236 m_invalidProducers.append(id);
237 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
238 doc.documentElement().removeChild(producers.at(i));
243 for (int i = 0; i < m_projectTracks; i++) {
244 e = tracks.item(i).toElement();
245 QString playlist_name = e.attribute("producer");
246 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
247 // find playlist related to this track
249 for (int j = 0; j < m_projectTracks; j++) {
250 p = playlists.item(j).toElement();
251 if (p.attribute("id") == playlist_name) break;
253 if (p.attribute("id") != playlist_name) { // then it didn't work.
254 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
256 if (e.attribute("hide") == "video") {
257 m_doc->switchTrackVideo(i - 1, true);
258 } else if (e.attribute("hide") == "audio") {
259 m_doc->switchTrackAudio(i - 1, true);
260 } else if (e.attribute("hide") == "both") {
261 m_doc->switchTrackVideo(i - 1, true);
262 m_doc->switchTrackAudio(i - 1, true);
265 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
267 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
268 if (trackduration > duration) duration = trackduration;
270 // background black track
271 for (int j = 0; j < m_projectTracks; j++) {
272 p = playlists.item(j).toElement();
273 if (p.attribute("id") == playlist_name) break;
280 QDomNodeList transitions = doc.elementsByTagName("transition");
282 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
283 for (int i = 0; i < transitions.count(); i++) {
284 e = transitions.item(i).toElement();
285 QDomNodeList transitionparams = e.childNodes();
286 bool transitionAdd = true;
289 bool isAutomatic = false;
290 bool forceTrack = false;
291 QString mlt_geometry;
293 QString transitionId;
294 for (int k = 0; k < transitionparams.count(); k++) {
295 p = transitionparams.item(k).toElement();
297 QString paramName = p.attribute("name");
298 // do not add audio mixing transitions
299 if (paramName == "internal_added" && p.text() == "237") {
300 transitionAdd = false;
301 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
303 } else if (paramName == "a_track") {
304 a_track = qMax(0, p.text().toInt());
305 a_track = qMin(m_projectTracks - 1, a_track);
306 if (a_track != p.text().toInt()) {
307 // the transition track was out of bounds
308 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), a_track) + '\n');
309 EffectsList::setProperty(e, "a_track", QString::number(a_track));
311 } else if (paramName == "b_track") {
312 b_track = qMax(0, p.text().toInt());
313 b_track = qMin(m_projectTracks - 1, b_track);
314 if (b_track != p.text().toInt()) {
315 // the transition track was out of bounds
316 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), b_track) + '\n');
317 EffectsList::setProperty(e, "b_track", QString::number(b_track));
319 } else if (paramName == "mlt_service") mlt_service = p.text();
320 else if (paramName == "kdenlive_id") transitionId = p.text();
321 else if (paramName == "geometry") mlt_geometry = p.text();
322 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
323 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
326 if (a_track == b_track || b_track == 0) {
327 // invalid transition, remove it
328 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
329 tractor.removeChild(transitions.item(i));
333 if (transitionAdd || mlt_service != "mix") {
334 // Transition should be added to the scene
335 ItemInfo transitionInfo;
336 if (mlt_service == "composite" && transitionId.isEmpty()) {
337 // When adding composite transition, check if it is a wipe transition
338 if (mlt_geometry.count(';') == 1) {
339 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
340 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
341 QString start = mlt_geometry.section(';', 0, 0);
342 start = start.section(':', 0, 1);
343 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
344 QString end = mlt_geometry.section('=', 1, 1);
345 end = end.section(':', 0, 1);
346 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
347 start.append(',' + end);
348 QStringList numbers = start.split(',', QString::SkipEmptyParts);
349 bool isWipeTransition = true;
351 for (int i = 0; i < numbers.size(); ++i) {
352 checkNumber = qAbs(numbers.at(i).toInt());
353 if (checkNumber != 0 && checkNumber != 100) {
354 isWipeTransition = false;
358 if (isWipeTransition) transitionId = "slide";
362 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
364 if (!base.isNull()) for (int k = 0; k < transitionparams.count(); k++) {
365 p = transitionparams.item(k).toElement();
367 QString paramName = p.attribute("name");
368 QString paramValue = p.text();
370 QDomNodeList params = base.elementsByTagName("parameter");
371 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
372 QDomElement e = params.item(i).toElement();
373 if (!e.isNull() && e.attribute("tag") == paramName) {
374 if (e.attribute("type") == "double") {
375 QString factor = e.attribute("factor", "1");
378 if (factor.startsWith('%')) {
379 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
380 } else fact = factor.toDouble();
381 double val = paramValue.toDouble() * fact;
382 paramValue = QString::number(val);
385 e.setAttribute("value", paramValue);
393 doc.appendChild(doc.importNode(base, true));
394 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
396 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
397 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
398 transitionInfo.track = m_projectTracks - 1 - b_track;
400 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
401 if (transitionInfo.startPos >= transitionInfo.endPos || base.isNull()) {
402 // invalid transition, remove it.
403 m_documentErrors.append(i18n("Removed invalid transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
404 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
405 tractor.removeChild(transitions.item(i));
408 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
409 if (forceTrack) tr->setForcedTrack(true, a_track);
410 m_scene->addItem(tr);
411 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
412 tr->setItemLocked(true);
419 QDomNodeList guides = doc.elementsByTagName("guide");
420 for (int i = 0; i < guides.count(); i++) {
421 e = guides.item(i).toElement();
422 const QString comment = e.attribute("comment");
423 const GenTime pos = GenTime(e.attribute("time").toDouble());
424 m_trackview->addGuide(pos, comment);
428 QDomNodeList groups = doc.elementsByTagName("group");
429 m_trackview->loadGroups(groups);
430 m_trackview->setDuration(duration);
431 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
433 // Remove Kdenlive extra info from xml doc before sending it to MLT
434 QDomElement mlt = doc.firstChildElement("mlt");
435 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
436 mlt.removeChild(infoXml);
438 slotRebuildTrackHeaders();
439 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
440 if (infoXml.hasAttribute("upgraded")) {
441 // Our document was upgraded, create a backup copy just in case
442 QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
444 QString backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
445 while (QFile::exists(backupFile)) {
447 backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
449 if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this))
450 KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile));
452 KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version, but it was not possible to create a backup copy.", backupFile));
454 //m_trackview->setCursorPos(cursorPos);
455 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
458 void TrackView::slotDeleteClip(const QString &clipId)
460 m_trackview->deleteClip(clipId);
463 void TrackView::setCursorPos(int pos)
465 m_trackview->setCursorPos(pos);
468 void TrackView::moveCursorPos(int pos)
470 m_trackview->setCursorPos(pos, false);
473 void TrackView::slotChangeZoom(int horizontal, int vertical)
475 m_ruler->setPixelPerMark(horizontal);
476 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal];
478 if (vertical == -1) {
480 m_doc->setZoom(horizontal, m_verticalZoom);
481 m_trackview->setScale(m_scale, m_scene->scale().y());
483 m_verticalZoom = vertical;
484 if (m_verticalZoom == 0)
485 m_trackview->setScale(m_scale, 0.5);
487 m_trackview->setScale(m_scale, m_verticalZoom);
488 adjustTrackHeaders();
492 int TrackView::fitZoom() const
494 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
496 for (i = 0; i < 13; i++)
497 if (m_ruler->comboScale[i] > zoom) break;
501 KdenliveDoc *TrackView::document()
506 void TrackView::refresh()
508 m_trackview->viewport()->update();
511 void TrackView::slotRepaintTracks()
514 for (int i = 0; i < headers_container->layout()->count(); i++) {
515 child = headers_container->layout()->itemAt(i);
516 if (child->widget() && child->widget()->height() > 5) {
517 HeaderTrack *head = static_cast <HeaderTrack *>(child->widget());
518 if (head) head->setSelectedIndex(m_trackview->selectedTrack());
523 void TrackView::slotReloadTracks()
525 slotRebuildTrackHeaders();
526 emit updateTracksInfo();
529 void TrackView::slotRebuildTrackHeaders()
531 const QList <TrackInfo> list = m_doc->tracksList();
533 while ((child = headers_container->layout()->takeAt(0)) != 0) {
534 QWidget *wid = child->widget();
536 if (wid) wid->deleteLater();
538 int max = list.count();
539 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
540 HeaderTrack *header = NULL;
541 QFrame *frame = NULL;
542 for (int i = 0; i < max; i++) {
543 frame = new QFrame(headers_container);
544 frame->setFixedHeight(1);
545 frame->setFrameStyle(QFrame::Plain);
546 frame->setFrameShape(QFrame::Box);
547 frame->setLineWidth(1);
548 headers_container->layout()->addWidget(frame);
549 TrackInfo info = list.at(max - i - 1);
550 header = new HeaderTrack(i, info, height, headers_container);
551 header->setSelectedIndex(m_trackview->selectedTrack());
552 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
553 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
554 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
555 connect(header, SIGNAL(selectTrack(int)), m_trackview, SLOT(slotSelectTrack(int)));
556 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
557 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
558 connect(header, SIGNAL(renameTrack(int, QString)), this, SLOT(slotRenameTrack(int, QString)));
559 connect(header, SIGNAL(configTrack(int)), this, SIGNAL(configTrack(int)));
560 headers_container->layout()->addWidget(header);
562 frame = new QFrame(this);
563 frame->setFixedHeight(1);
564 frame->setFrameStyle(QFrame::Plain);
565 frame->setFrameShape(QFrame::Box);
566 frame->setLineWidth(1);
567 headers_container->layout()->addWidget(frame);
571 void TrackView::adjustTrackHeaders()
573 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
575 for (int i = 0; i < headers_container->layout()->count(); i++) {
576 child = headers_container->layout()->itemAt(i);
577 if (child->widget() && child->widget()->height() > 5)(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
581 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
585 QDomNodeList children = xml.childNodes();
586 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
587 QDomNode n = children.item(nodeindex);
588 QDomElement elem = n.toElement();
589 if (elem.tagName() == "blank") {
590 position += elem.attribute("length").toInt();
591 } else if (elem.tagName() == "entry") {
593 int in = elem.attribute("in").toInt();
594 int out = elem.attribute("out").toInt();
595 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
596 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
597 xml.removeChild(children.at(nodeindex));
601 QString idString = elem.attribute("producer");
602 QString id = idString;
605 if (idString.startsWith("slowmotion")) {
606 id = idString.section(':', 1, 1);
607 speed = idString.section(':', 2, 2).toDouble();
608 strobe = idString.section(':', 3, 3).toInt();
609 if (strobe == 0) strobe = 1;
610 } else id = id.section('_', 0, 0);
611 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
613 // The clip in playlist was not listed in the kdenlive producers,
614 // something went wrong, repair required.
615 kWarning() << "CANNOT INSERT CLIP " << id;
617 clip = getMissingProducer(id);
619 // We cannot find the producer, something is really wrong, add
620 // placeholder color clip
622 QDomElement producerXml = doc.createElement("producer");
623 doc.appendChild(producerXml);
624 producerXml.setAttribute("colour", "0xff0000ff");
625 producerXml.setAttribute("mlt_service", "colour");
626 producerXml.setAttribute("length", "15000");
627 producerXml.setAttribute("name", "INVALID");
628 producerXml.setAttribute("type", COLOR);
629 producerXml.setAttribute("id", id);
630 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
631 xml.insertBefore(producerXml, QDomNode());
632 m_doc->clipManager()->addClip(clip);
634 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
636 // Found correct producer
637 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
638 elem.setAttribute("producer", clip->getId());
640 m_doc->setModified(true);
645 clipinfo.startPos = GenTime(position, m_doc->fps());
646 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
647 clipinfo.cropStart = GenTime(in, m_doc->fps());
648 clipinfo.cropDuration = clipinfo.endPos - clipinfo.startPos;
651 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
652 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
653 if (idString.endsWith("_video")) item->setVideoOnly(true);
654 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
655 m_scene->addItem(item);
656 if (locked) item->setItemLocked(true);
657 clip->addReference();
658 position += (out - in + 1);
659 if (speed != 1.0 || strobe > 1) {
660 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
661 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
662 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
663 item->addEffect(speedeffect, false);
664 item->effectsCounter();
667 // parse clip effects
668 QDomNodeList effects = elem.childNodes();
669 for (int ix = 0; ix < effects.count(); ix++) {
670 bool disableeffect = false;
671 QDomElement effect = effects.at(ix).toElement();
672 if (effect.tagName() == "filter") {
673 // add effect to clip
676 QString effectindex = QString::number(ix + 1);
677 QString ladspaEffectFile;
678 // Get effect tag & index
679 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
680 // parse effect parameters
681 QDomElement effectparam = n3.toElement();
682 if (effectparam.attribute("name") == "tag") {
683 effecttag = effectparam.text();
684 } else if (effectparam.attribute("name") == "kdenlive_id") {
685 effectid = effectparam.text();
686 } else if (effectparam.attribute("name") == "disable" && effectparam.text().toInt() == 1) {
688 disableeffect = true;
689 } else if (effectparam.attribute("name") == "kdenlive_ix") {
691 effectparam.firstChild().setNodeValue(effectindex);
692 } else if (effectparam.attribute("name") == "src") {
693 ladspaEffectFile = effectparam.text();
694 if (!QFile::exists(ladspaEffectFile)) {
695 // If the ladspa effect file is missing, recreate it
696 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
697 ladspaEffectFile = m_doc->getLadspaFile();
698 effectparam.firstChild().setNodeValue(ladspaEffectFile);
699 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
703 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
704 // get effect standard tags
705 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
706 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
707 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
708 if (clipeffect.isNull()) {
709 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
710 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
711 elem.removeChild(effects.at(ix));
714 QDomElement currenteffect = clipeffect.cloneNode().toElement();
715 currenteffect.setAttribute("kdenlive_ix", effectindex);
716 QDomNodeList clipeffectparams = currenteffect.childNodes();
718 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
719 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
720 // effect is key-framable, read all effects to retrieve keyframes
724 QDomNodeList params = currenteffect.elementsByTagName("parameter");
725 for (int i = 0; i < params.count(); i++) {
726 QDomElement e = params.item(i).toElement();
727 if (e.attribute("type") == "keyframe") {
728 starttag = e.attribute("starttag", "start");
729 endtag = e.attribute("endtag", "end");
730 factor = e.attribute("factor", "1");
735 int effectin = effect.attribute("in").toInt();
736 int effectout = effect.attribute("out").toInt();
737 double startvalue = 0;
740 if (factor.isEmpty()) fact = 1;
741 else if (factor.startsWith('%')) {
742 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
743 } else fact = factor.toDouble();
744 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
745 // parse effect parameters
746 QDomElement effectparam = n3.toElement();
747 if (effectparam.attribute("name") == starttag)
748 startvalue = effectparam.text().toDouble() * fact;
749 if (effectparam.attribute("name") == endtag)
750 endvalue = effectparam.text().toDouble() * fact;
752 // add first keyframe
753 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
754 QDomNode lastParsedEffect;
756 QDomNode n2 = effects.at(ix);
757 bool continueParsing = true;
758 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
760 QDomElement kfreffect = n2.toElement();
761 int effectout = kfreffect.attribute("out").toInt();
763 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
764 // parse effect parameters
765 QDomElement subeffectparam = n4.toElement();
766 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
767 //We are not in the same effect, stop parsing
768 lastParsedEffect = n2.previousSibling();
770 continueParsing = false;
772 } else if (subeffectparam.attribute("name") == endtag) {
773 endvalue = subeffectparam.text().toDouble() * fact;
777 if (continueParsing) {
778 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
783 params = currenteffect.elementsByTagName("parameter");
784 for (int i = 0; i < params.count(); i++) {
785 QDomElement e = params.item(i).toElement();
786 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
788 if (!continueParsing) {
789 n2 = lastParsedEffect;
792 // Check if effect has in/out points
793 if (effect.hasAttribute("in")) {
794 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
796 if (effect.hasAttribute("out")) {
797 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
801 // adjust effect parameters
802 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
803 // parse effect parameters
804 QDomElement effectparam = n3.toElement();
805 QString paramname = effectparam.attribute("name");
806 QString paramvalue = effectparam.text();
809 // try to find this parameter in the effect xml
811 for (int k = 0; k < clipeffectparams.count(); k++) {
812 e = clipeffectparams.item(k).toElement();
813 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
814 if (e.attribute("factor", "1") != "1") {
815 QString factor = e.attribute("factor", "1");
817 if (factor.startsWith('%')) {
818 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
819 } else fact = factor.toDouble();
820 if (e.attribute("type") == "simplekeyframe") {
821 QStringList kfrs = paramvalue.split(";");
822 for (int l = 0; l < kfrs.count(); l++) {
823 QString fr = kfrs.at(l).section("=", 0, 0);
824 double val = kfrs.at(l).section("=", 1, 1).toDouble();
825 kfrs[l] = fr + ":" + QString::number((int)(val * fact));
827 e.setAttribute("keyframes", kfrs.join(";"));
828 } else e.setAttribute("value", paramvalue.toDouble() * fact);
829 } else e.setAttribute("value", paramvalue);
834 if (effecttag == "ladspa") {
835 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
837 if (!QFile::exists(ladspaEffectFile)) {
838 // If the ladspa effect file is missing, recreate it
839 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
841 currenteffect.setAttribute("src", ladspaEffectFile);
843 if (disableeffect) currenteffect.setAttribute("disable", "1");
844 item->addEffect(currenteffect, false);
849 //m_clipList.append(clip);
852 //m_trackDuration = position;
855 //documentTracks.insert(ix, track);
856 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
861 DocClipBase *TrackView::getMissingProducer(const QString id) const
863 QDomElement missingXml;
864 QDomDocument doc = m_doc->toXml();
865 QString docRoot = doc.documentElement().attribute("root");
866 if (!docRoot.endsWith('/')) docRoot.append('/');
867 QDomNodeList prods = doc.elementsByTagName("producer");
868 int maxprod = prods.count();
869 for (int i = 0; i < maxprod; i++) {
870 QDomNode m = prods.at(i);
871 QString prodId = m.toElement().attribute("id");
873 missingXml = m.toElement();
877 if (missingXml == QDomElement()) return NULL;
879 QDomNodeList params = missingXml.childNodes();
881 for (int j = 0; j < params.count(); j++) {
882 QDomElement e = params.item(j).toElement();
883 if (e.attribute("name") == "resource") {
884 resource = e.firstChild().nodeValue();
888 // prepend MLT XML document root if no path in clip resource and not a color clip
889 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
890 DocClipBase *missingClip = NULL;
891 if (!resource.isEmpty()) {
892 QList <DocClipBase *> list = m_doc->clipManager()->getClipByResource(resource);
893 if (!list.isEmpty()) missingClip = list.at(0);
898 QGraphicsScene *TrackView::projectScene()
903 CustomTrackView *TrackView::projectView()
908 void TrackView::setEditMode(const QString & editMode)
910 m_editMode = editMode;
913 const QString & TrackView::editMode() const
918 void TrackView::slotChangeTrackLock(int ix, bool lock)
920 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
921 widgets.at(ix)->setLock(lock);
925 void TrackView::slotVerticalZoomDown()
927 if (m_verticalZoom == 0) return;
929 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
930 if (m_verticalZoom == 0)
931 m_trackview->setScale(m_scene->scale().x(), 0.5);
933 m_trackview->setScale(m_scene->scale().x(), 1);
934 adjustTrackHeaders();
935 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
938 void TrackView::slotVerticalZoomUp()
940 if (m_verticalZoom == 2) return;
942 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
943 if (m_verticalZoom == 2)
944 m_trackview->setScale(m_scene->scale().x(), 2);
946 m_trackview->setScale(m_scene->scale().x(), 1);
947 adjustTrackHeaders();
948 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
951 void TrackView::updateProjectFps()
953 m_ruler->updateProjectFps(m_doc->timecode());
954 m_trackview->updateProjectFps();
957 void TrackView::slotRenameTrack(int ix, QString name)
959 int tracknumber = m_doc->tracksCount() - ix;
960 QList <TrackInfo> tracks = m_doc->tracksList();
961 tracks[tracknumber - 1].trackName = name;
962 ConfigTracksCommand *configTracks = new ConfigTracksCommand(m_trackview, m_doc->tracksList(), tracks);
963 m_doc->commandStack()->push(configTracks);
964 m_doc->setModified(true);
967 void TrackView::slotUpdateVerticalScroll(int /*min*/, int max)
970 if (max > 0) height = m_trackview->horizontalScrollBar()->height() - 1;
971 headers_container->layout()->setContentsMargins(0, m_trackview->frameWidth(), 0, height);
974 void TrackView::updateRuler()
979 #include "trackview.moc"