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 "headertrack.h"
24 #include "transition.h"
25 #include "kdenlivesettings.h"
26 #include "clipmanager.h"
27 #include "customruler.h"
28 #include "kdenlivedoc.h"
29 #include "mainwindow.h"
30 #include "customtrackview.h"
31 #include "initeffects.h"
32 #include "profilesdialog.h"
33 #include "configtrackscommand.h"
36 #include <KMessageBox>
37 #include <KIO/NetAccess>
40 #include <QInputDialog>
42 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
51 // ruler_frame->setMaximumHeight();
52 // size_frame->setMaximumHeight();
53 m_scene = new CustomTrackScene(doc);
54 m_trackview = new CustomTrackView(doc, m_scene, parent);
55 m_trackview->scale(1, 1);
56 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
57 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
59 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
60 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
61 connect(m_ruler, SIGNAL(adjustZoom(int)), this, SIGNAL(setZoom(int)));
62 QHBoxLayout *layout = new QHBoxLayout;
63 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
64 layout->setSpacing(0);
65 ruler_frame->setLayout(layout);
66 layout->addWidget(m_ruler);
68 QHBoxLayout *sizeLayout = new QHBoxLayout;
69 sizeLayout->setContentsMargins(0, 0, 0, 0);
70 sizeLayout->setSpacing(0);
71 size_frame->setLayout(sizeLayout);
73 QToolButton *butSmall = new QToolButton(this);
74 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
75 butSmall->setToolTip(i18n("Smaller tracks"));
76 butSmall->setAutoRaise(true);
77 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
78 sizeLayout->addWidget(butSmall);
80 QToolButton *butLarge = new QToolButton(this);
81 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
82 butLarge->setToolTip(i18n("Bigger tracks"));
83 butLarge->setAutoRaise(true);
84 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
85 sizeLayout->addWidget(butLarge);
87 QHBoxLayout *tracksLayout = new QHBoxLayout;
88 tracksLayout->setContentsMargins(0, 0, 0, 0);
89 tracksLayout->setSpacing(0);
90 tracks_frame->setLayout(tracksLayout);
92 headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93 headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
94 headers_area->setFixedWidth(70);
96 QVBoxLayout *headersLayout = new QVBoxLayout;
97 headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
98 headersLayout->setSpacing(0);
99 headers_container->setLayout(headersLayout);
100 connect(headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
102 tracksLayout->addWidget(m_trackview);
103 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), headers_area->verticalScrollBar(), SLOT(setValue(int)));
104 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
105 connect(m_trackview, SIGNAL(tracksChanged()), this, SLOT(slotReloadTracks()));
106 connect(m_trackview, SIGNAL(updateTrackHeaders()), this, SLOT(slotRepaintTracks()));
107 connect(m_trackview, SIGNAL(showTrackEffects(int, TrackInfo)), this, SIGNAL(showTrackEffects(int, TrackInfo)));
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));
244 for (int i = 0; i < m_projectTracks; i++) {
245 e = tracks.item(i).toElement();
246 QString playlist_name = e.attribute("producer");
247 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
248 // find playlist related to this track
250 for (int j = 0; j < m_projectTracks; j++) {
251 p = playlists.item(j).toElement();
252 if (p.attribute("id") == playlist_name) {
253 // playlist found, check track effects
254 QDomNodeList trackEffects = p.elementsByTagName("filter");
255 kDebug() << "<< PLAYLIST: " << playlist_name << ", effects: " << trackEffects.count() << ", TK IX: " << trackIndex;
256 slotAddProjectEffects(trackEffects, p, NULL, trackIndex++);
260 if (p.attribute("id") != playlist_name) { // then it didn't work.
261 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
263 if (e.attribute("hide") == "video") {
264 m_doc->switchTrackVideo(i - 1, true);
265 } else if (e.attribute("hide") == "audio") {
266 m_doc->switchTrackAudio(i - 1, true);
267 } else if (e.attribute("hide") == "both") {
268 m_doc->switchTrackVideo(i - 1, true);
269 m_doc->switchTrackAudio(i - 1, true);
272 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
274 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
275 if (trackduration > duration) duration = trackduration;
277 // background black track
278 for (int j = 0; j < m_projectTracks; j++) {
279 p = playlists.item(j).toElement();
280 if (p.attribute("id") == playlist_name) break;
287 QDomNodeList transitions = doc.elementsByTagName("transition");
289 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
290 for (int i = 0; i < transitions.count(); i++) {
291 e = transitions.item(i).toElement();
292 QDomNodeList transitionparams = e.childNodes();
293 bool transitionAdd = true;
296 bool isAutomatic = false;
297 bool forceTrack = false;
298 QString mlt_geometry;
300 QString transitionId;
301 for (int k = 0; k < transitionparams.count(); k++) {
302 p = transitionparams.item(k).toElement();
304 QString paramName = p.attribute("name");
305 // do not add audio mixing transitions
306 if (paramName == "internal_added" && p.text() == "237") {
307 transitionAdd = false;
308 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
310 } else if (paramName == "a_track") {
311 a_track = qMax(0, p.text().toInt());
312 a_track = qMin(m_projectTracks - 1, a_track);
313 if (a_track != p.text().toInt()) {
314 // the transition track was out of bounds
315 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), a_track) + '\n');
316 EffectsList::setProperty(e, "a_track", QString::number(a_track));
318 } else if (paramName == "b_track") {
319 b_track = qMax(0, p.text().toInt());
320 b_track = qMin(m_projectTracks - 1, b_track);
321 if (b_track != p.text().toInt()) {
322 // the transition track was out of bounds
323 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), b_track) + '\n');
324 EffectsList::setProperty(e, "b_track", QString::number(b_track));
326 } else if (paramName == "mlt_service") mlt_service = p.text();
327 else if (paramName == "kdenlive_id") transitionId = p.text();
328 else if (paramName == "geometry") mlt_geometry = p.text();
329 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
330 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
333 if (a_track == b_track || b_track == 0) {
334 // invalid transition, remove it
335 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
336 tractor.removeChild(transitions.item(i));
340 if (transitionAdd || mlt_service != "mix") {
341 // Transition should be added to the scene
342 ItemInfo transitionInfo;
343 if (mlt_service == "composite" && transitionId.isEmpty()) {
344 // When adding composite transition, check if it is a wipe transition
345 if (mlt_geometry.count(';') == 1) {
346 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
347 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
348 QString start = mlt_geometry.section(';', 0, 0);
349 start = start.section(':', 0, 1);
350 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
351 QString end = mlt_geometry.section('=', 1, 1);
352 end = end.section(':', 0, 1);
353 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
354 start.append(',' + end);
355 QStringList numbers = start.split(',', QString::SkipEmptyParts);
356 bool isWipeTransition = true;
358 for (int i = 0; i < numbers.size(); ++i) {
359 checkNumber = qAbs(numbers.at(i).toInt());
360 if (checkNumber != 0 && checkNumber != 100) {
361 isWipeTransition = false;
365 if (isWipeTransition) transitionId = "slide";
369 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
371 if (!base.isNull()) for (int k = 0; k < transitionparams.count(); k++) {
372 p = transitionparams.item(k).toElement();
374 QString paramName = p.attribute("name");
375 QString paramValue = p.text();
377 QDomNodeList params = base.elementsByTagName("parameter");
378 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
379 QDomElement e = params.item(i).toElement();
380 if (!e.isNull() && e.attribute("tag") == paramName) {
381 if (e.attribute("type") == "double") {
382 QString factor = e.attribute("factor", "1");
385 if (factor.startsWith('%')) {
386 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
387 } else fact = factor.toDouble();
388 double val = paramValue.toDouble() * fact;
389 paramValue = QString::number(val);
392 e.setAttribute("value", paramValue);
400 doc.appendChild(doc.importNode(base, true));
401 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
403 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
404 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
405 transitionInfo.track = m_projectTracks - 1 - b_track;
407 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
408 if (transitionInfo.startPos >= transitionInfo.endPos || base.isNull()) {
409 // invalid transition, remove it.
410 m_documentErrors.append(i18n("Removed invalid transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
411 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
412 tractor.removeChild(transitions.item(i));
415 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
416 if (forceTrack) tr->setForcedTrack(true, a_track);
417 m_scene->addItem(tr);
418 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
419 tr->setItemLocked(true);
426 QDomNodeList guides = doc.elementsByTagName("guide");
427 for (int i = 0; i < guides.count(); i++) {
428 e = guides.item(i).toElement();
429 const QString comment = e.attribute("comment");
430 const GenTime pos = GenTime(e.attribute("time").toDouble());
431 m_trackview->addGuide(pos, comment);
435 QDomNodeList groups = doc.elementsByTagName("group");
436 m_trackview->loadGroups(groups);
437 m_trackview->setDuration(duration);
438 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
440 // Remove Kdenlive extra info from xml doc before sending it to MLT
441 QDomElement mlt = doc.firstChildElement("mlt");
442 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
443 mlt.removeChild(infoXml);
445 slotRebuildTrackHeaders();
446 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
447 if (infoXml.hasAttribute("upgraded")) {
448 // Our document was upgraded, create a backup copy just in case
449 QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
451 QString backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
452 while (QFile::exists(backupFile)) {
454 backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
456 if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this))
457 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));
459 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));
461 //m_trackview->setCursorPos(cursorPos);
462 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
465 void TrackView::slotDeleteClip(const QString &clipId)
467 m_trackview->deleteClip(clipId);
470 void TrackView::setCursorPos(int pos)
472 m_trackview->setCursorPos(pos);
475 void TrackView::moveCursorPos(int pos)
477 m_trackview->setCursorPos(pos, false);
480 void TrackView::slotChangeZoom(int horizontal, int vertical)
482 m_ruler->setPixelPerMark(horizontal);
483 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal];
485 if (vertical == -1) {
487 m_doc->setZoom(horizontal, m_verticalZoom);
488 m_trackview->setScale(m_scale, m_scene->scale().y());
490 m_verticalZoom = vertical;
491 if (m_verticalZoom == 0)
492 m_trackview->setScale(m_scale, 0.5);
494 m_trackview->setScale(m_scale, m_verticalZoom);
495 adjustTrackHeaders();
499 int TrackView::fitZoom() const
501 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
503 for (i = 0; i < 13; i++)
504 if (m_ruler->comboScale[i] > zoom) break;
508 KdenliveDoc *TrackView::document()
513 void TrackView::refresh()
515 m_trackview->viewport()->update();
518 void TrackView::slotRepaintTracks()
521 for (int i = 0; i < headers_container->layout()->count(); i++) {
522 child = headers_container->layout()->itemAt(i);
523 if (child->widget() && child->widget()->height() > 5) {
524 HeaderTrack *head = static_cast <HeaderTrack *>(child->widget());
525 if (head) head->setSelectedIndex(m_trackview->selectedTrack());
530 void TrackView::slotReloadTracks()
532 slotRebuildTrackHeaders();
533 emit updateTracksInfo();
536 void TrackView::slotRebuildTrackHeaders()
538 const QList <TrackInfo> list = m_doc->tracksList();
540 while ((child = headers_container->layout()->takeAt(0)) != 0) {
541 QWidget *wid = child->widget();
543 if (wid) wid->deleteLater();
545 int max = list.count();
546 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
547 HeaderTrack *header = NULL;
548 QFrame *frame = NULL;
549 for (int i = 0; i < max; i++) {
550 frame = new QFrame(headers_container);
551 frame->setFixedHeight(1);
552 frame->setFrameStyle(QFrame::Plain);
553 frame->setFrameShape(QFrame::Box);
554 frame->setLineWidth(1);
555 headers_container->layout()->addWidget(frame);
556 TrackInfo info = list.at(max - i - 1);
557 header = new HeaderTrack(i, info, height, headers_container);
558 header->setSelectedIndex(m_trackview->selectedTrack());
559 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
560 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
561 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
562 connect(header, SIGNAL(selectTrack(int)), m_trackview, SLOT(slotSelectTrack(int)));
563 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
564 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
565 connect(header, SIGNAL(renameTrack(int, QString)), this, SLOT(slotRenameTrack(int, QString)));
566 connect(header, SIGNAL(configTrack(int)), this, SIGNAL(configTrack(int)));
567 connect(header, SIGNAL(addTrackInfo(const QDomElement, int)), m_trackview, SLOT(slotAddTrackEffect(const QDomElement, int)));
568 connect(header, SIGNAL(showTrackEffects(int)), this, SLOT(slotShowTrackEffects(int)));
569 headers_container->layout()->addWidget(header);
571 frame = new QFrame(this);
572 frame->setFixedHeight(1);
573 frame->setFrameStyle(QFrame::Plain);
574 frame->setFrameShape(QFrame::Box);
575 frame->setLineWidth(1);
576 headers_container->layout()->addWidget(frame);
580 void TrackView::adjustTrackHeaders()
582 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
584 for (int i = 0; i < headers_container->layout()->count(); i++) {
585 child = headers_container->layout()->itemAt(i);
586 if (child->widget() && child->widget()->height() > 5)(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
590 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
594 QDomNodeList children = xml.childNodes();
595 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
596 QDomNode n = children.item(nodeindex);
597 QDomElement elem = n.toElement();
598 if (elem.tagName() == "blank") {
599 position += elem.attribute("length").toInt();
600 } else if (elem.tagName() == "entry") {
602 int in = elem.attribute("in").toInt();
603 int out = elem.attribute("out").toInt();
604 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
605 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
606 xml.removeChild(children.at(nodeindex));
610 QString idString = elem.attribute("producer");
611 QString id = idString;
614 if (idString.startsWith("slowmotion")) {
615 id = idString.section(':', 1, 1);
616 speed = idString.section(':', 2, 2).toDouble();
617 strobe = idString.section(':', 3, 3).toInt();
618 if (strobe == 0) strobe = 1;
619 } else id = id.section('_', 0, 0);
620 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
622 // The clip in playlist was not listed in the kdenlive producers,
623 // something went wrong, repair required.
624 kWarning() << "CANNOT INSERT CLIP " << id;
626 clip = getMissingProducer(id);
628 // We cannot find the producer, something is really wrong, add
629 // placeholder color clip
631 QDomElement producerXml = doc.createElement("producer");
632 doc.appendChild(producerXml);
633 producerXml.setAttribute("colour", "0xff0000ff");
634 producerXml.setAttribute("mlt_service", "colour");
635 producerXml.setAttribute("length", "15000");
636 producerXml.setAttribute("name", "INVALID");
637 producerXml.setAttribute("type", COLOR);
638 producerXml.setAttribute("id", id);
639 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
640 xml.insertBefore(producerXml, QDomNode());
641 m_doc->clipManager()->addClip(clip);
643 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
645 // Found correct producer
646 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
647 elem.setAttribute("producer", clip->getId());
649 m_doc->setModified(true);
654 clipinfo.startPos = GenTime(position, m_doc->fps());
655 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
656 clipinfo.cropStart = GenTime(in, m_doc->fps());
657 clipinfo.cropDuration = clipinfo.endPos - clipinfo.startPos;
660 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
661 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
662 if (idString.endsWith("_video")) item->setVideoOnly(true);
663 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
664 m_scene->addItem(item);
665 if (locked) item->setItemLocked(true);
666 clip->addReference();
667 position += (out - in + 1);
668 if (speed != 1.0 || strobe > 1) {
669 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
670 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
671 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
672 item->addEffect(speedeffect, false);
673 item->effectsCounter();
676 // parse clip effects
677 QDomNodeList effects = elem.elementsByTagName("filter");
678 slotAddProjectEffects(effects, elem, item, -1);
682 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
686 void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parent, ClipItem *clip, int trackIndex)
688 for (int ix = 0; ix < effects.count(); ix++) {
689 bool disableeffect = false;
690 QDomElement effect = effects.at(ix).toElement();
692 // add effect to clip
695 QString effectindex = QString::number(ix + 1);
696 QString ladspaEffectFile;
697 // Get effect tag & index
698 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
699 // parse effect parameters
700 QDomElement effectparam = n3.toElement();
701 if (effectparam.attribute("name") == "tag") {
702 effecttag = effectparam.text();
703 } else if (effectparam.attribute("name") == "kdenlive_id") {
704 effectid = effectparam.text();
705 } else if (effectparam.attribute("name") == "disable" && effectparam.text().toInt() == 1) {
707 disableeffect = true;
708 } else if (effectparam.attribute("name") == "kdenlive_ix") {
710 effectparam.firstChild().setNodeValue(effectindex);
711 } else if (effectparam.attribute("name") == "src") {
712 ladspaEffectFile = effectparam.text();
713 if (!QFile::exists(ladspaEffectFile)) {
714 // If the ladspa effect file is missing, recreate it
715 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
716 ladspaEffectFile = m_doc->getLadspaFile();
717 effectparam.firstChild().setNodeValue(ladspaEffectFile);
718 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
722 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
723 // get effect standard tags
724 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
725 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
726 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
727 if (clipeffect.isNull()) {
728 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
729 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
730 parent.removeChild(effects.at(ix));
733 QDomElement currenteffect = clipeffect.cloneNode().toElement();
734 currenteffect.setAttribute("kdenlive_ix", effectindex);
735 QDomNodeList clipeffectparams = currenteffect.childNodes();
737 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
738 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
739 // effect is key-framable, read all effects to retrieve keyframes
743 QDomNodeList params = currenteffect.elementsByTagName("parameter");
744 for (int i = 0; i < params.count(); i++) {
745 QDomElement e = params.item(i).toElement();
746 if (e.attribute("type") == "keyframe") {
747 starttag = e.attribute("starttag", "start");
748 endtag = e.attribute("endtag", "end");
749 factor = e.attribute("factor", "1");
754 int effectin = effect.attribute("in").toInt();
755 int effectout = effect.attribute("out").toInt();
756 double startvalue = 0;
759 if (factor.isEmpty()) fact = 1;
760 else if (factor.startsWith('%')) {
761 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
762 } else fact = factor.toDouble();
763 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
764 // parse effect parameters
765 QDomElement effectparam = n3.toElement();
766 if (effectparam.attribute("name") == starttag)
767 startvalue = effectparam.text().toDouble() * fact;
768 if (effectparam.attribute("name") == endtag)
769 endvalue = effectparam.text().toDouble() * fact;
771 // add first keyframe
772 if (effectout <= effectin) {
773 //Â there is only one keyframe
774 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';');
775 } else keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
776 QDomNode lastParsedEffect;
778 QDomNode n2 = effects.at(ix);
779 bool continueParsing = true;
780 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
782 QDomElement kfreffect = n2.toElement();
783 int effectout = kfreffect.attribute("out").toInt();
785 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
786 // parse effect parameters
787 QDomElement subeffectparam = n4.toElement();
788 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
789 //We are not in the same effect, stop parsing
790 lastParsedEffect = n2.previousSibling();
792 continueParsing = false;
794 } else if (subeffectparam.attribute("name") == endtag) {
795 endvalue = subeffectparam.text().toDouble() * fact;
799 if (continueParsing) {
800 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
805 params = currenteffect.elementsByTagName("parameter");
806 for (int i = 0; i < params.count(); i++) {
807 QDomElement e = params.item(i).toElement();
808 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
810 if (!continueParsing) {
811 n2 = lastParsedEffect;
814 // Check if effect has in/out points
815 if (effect.hasAttribute("in")) {
816 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
818 if (effect.hasAttribute("out")) {
819 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
823 // adjust effect parameters
824 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
825 // parse effect parameters
826 QDomElement effectparam = n3.toElement();
827 QString paramname = effectparam.attribute("name");
828 QString paramvalue = effectparam.text();
830 // try to find this parameter in the effect xml
832 for (int k = 0; k < clipeffectparams.count(); k++) {
833 e = clipeffectparams.item(k).toElement();
834 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
835 if (e.attribute("factor", "1") != "1") {
836 QString factor = e.attribute("factor", "1");
838 if (factor.startsWith('%')) {
839 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
840 } else fact = factor.toDouble();
841 if (e.attribute("type") == "simplekeyframe") {
842 QStringList kfrs = paramvalue.split(";");
843 for (int l = 0; l < kfrs.count(); l++) {
844 QString fr = kfrs.at(l).section("=", 0, 0);
845 double val = kfrs.at(l).section("=", 1, 1).toDouble();
846 kfrs[l] = fr + ":" + QString::number((int)(val * fact));
848 e.setAttribute("keyframes", kfrs.join(";"));
849 } else e.setAttribute("value", paramvalue.toDouble() * fact);
850 } else e.setAttribute("value", paramvalue);
855 if (effecttag == "ladspa") {
856 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
858 if (!QFile::exists(ladspaEffectFile)) {
859 // If the ladspa effect file is missing, recreate it
860 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
862 currenteffect.setAttribute("src", ladspaEffectFile);
864 if (disableeffect) currenteffect.setAttribute("disable", "1");
865 if (clip) clip->addEffect(currenteffect, false);
867 kDebug() << "<< TRACK: " << trackIndex << ", adding effect";;
868 m_doc->addTrackEffect(trackIndex, currenteffect);
875 DocClipBase *TrackView::getMissingProducer(const QString id) const
877 QDomElement missingXml;
878 QDomDocument doc = m_doc->toXml();
879 QString docRoot = doc.documentElement().attribute("root");
880 if (!docRoot.endsWith('/')) docRoot.append('/');
881 QDomNodeList prods = doc.elementsByTagName("producer");
882 int maxprod = prods.count();
883 for (int i = 0; i < maxprod; i++) {
884 QDomNode m = prods.at(i);
885 QString prodId = m.toElement().attribute("id");
887 missingXml = m.toElement();
891 if (missingXml == QDomElement()) return NULL;
893 QDomNodeList params = missingXml.childNodes();
895 for (int j = 0; j < params.count(); j++) {
896 QDomElement e = params.item(j).toElement();
897 if (e.attribute("name") == "resource") {
898 resource = e.firstChild().nodeValue();
902 // prepend MLT XML document root if no path in clip resource and not a color clip
903 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
904 DocClipBase *missingClip = NULL;
905 if (!resource.isEmpty()) {
906 QList <DocClipBase *> list = m_doc->clipManager()->getClipByResource(resource);
907 if (!list.isEmpty()) missingClip = list.at(0);
912 QGraphicsScene *TrackView::projectScene()
917 CustomTrackView *TrackView::projectView()
922 void TrackView::setEditMode(const QString & editMode)
924 m_editMode = editMode;
927 const QString & TrackView::editMode() const
932 void TrackView::slotChangeTrackLock(int ix, bool lock)
934 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
935 widgets.at(ix)->setLock(lock);
939 void TrackView::slotVerticalZoomDown()
941 if (m_verticalZoom == 0) return;
943 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
944 if (m_verticalZoom == 0)
945 m_trackview->setScale(m_scene->scale().x(), 0.5);
947 m_trackview->setScale(m_scene->scale().x(), 1);
948 adjustTrackHeaders();
949 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
952 void TrackView::slotVerticalZoomUp()
954 if (m_verticalZoom == 2) return;
956 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
957 if (m_verticalZoom == 2)
958 m_trackview->setScale(m_scene->scale().x(), 2);
960 m_trackview->setScale(m_scene->scale().x(), 1);
961 adjustTrackHeaders();
962 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
965 void TrackView::updateProjectFps()
967 m_ruler->updateProjectFps(m_doc->timecode());
968 m_trackview->updateProjectFps();
971 void TrackView::slotRenameTrack(int ix, QString name)
973 int tracknumber = m_doc->tracksCount() - ix;
974 QList <TrackInfo> tracks = m_doc->tracksList();
975 tracks[tracknumber - 1].trackName = name;
976 ConfigTracksCommand *configTracks = new ConfigTracksCommand(m_trackview, m_doc->tracksList(), tracks);
977 m_doc->commandStack()->push(configTracks);
978 m_doc->setModified(true);
981 void TrackView::slotUpdateVerticalScroll(int /*min*/, int max)
984 if (max > 0) height = m_trackview->horizontalScrollBar()->height() - 1;
985 headers_container->layout()->setContentsMargins(0, m_trackview->frameWidth(), 0, height);
988 void TrackView::updateRuler()
993 void TrackView::slotShowTrackEffects(int ix)
995 emit showTrackEffects(m_doc->tracksCount() - ix, m_doc->trackInfoAt(m_doc->tracksCount() - ix - 1));
998 #include "trackview.moc"