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>
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()));
108 parseDocument(m_doc->toXml());
109 if (m_doc->setSceneList() == -1) *ok = false;
111 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
112 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
113 connect(m_trackview->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(slotUpdateVerticalScroll(int, int)));
114 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
115 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
117 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
118 slotSetZone(m_doc->zone());
121 TrackView::~TrackView()
128 void TrackView::keyPressEvent(QKeyEvent * event)
130 if (event->key() == Qt::Key_Up) {
131 m_trackview->slotTrackUp();
133 } else if (event->key() == Qt::Key_Down) {
134 m_trackview->slotTrackDown();
136 } else QWidget::keyPressEvent(event);
139 int TrackView::duration() const
141 return m_trackview->duration();
144 int TrackView::tracksNumber() const
146 return m_projectTracks - 1;
149 int TrackView::inPoint() const
151 return m_ruler->inPoint();
154 int TrackView::outPoint() const
156 return m_ruler->outPoint();
159 void TrackView::slotSetZone(QPoint p)
164 void TrackView::setDuration(int dur)
166 m_trackview->setDuration(dur);
167 m_ruler->setDuration(dur);
170 void TrackView::parseDocument(QDomDocument doc)
173 m_documentErrors.clear();
175 //kDebug() << "//// DOCUMENT: " << doc.toString();
176 /*QDomNode props = doc.elementsByTagName("properties").item(0);
177 if (!props.isNull()) {
178 cursorPos = props.toElement().attribute("timeline_position").toInt();
181 // parse project tracks
182 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
183 QDomNodeList tracks = doc.elementsByTagName("track");
184 QDomNodeList playlists = doc.elementsByTagName("playlist");
186 m_projectTracks = tracks.count();
187 int trackduration = 0;
191 int pos = m_projectTracks - 1;
192 m_invalidProducers.clear();
193 QDomNodeList producers = doc.elementsByTagName("producer");
194 for (int i = 0; i < producers.count(); i++) {
195 // Check for invalid producers
196 QDomNode n = producers.item(i);
200 // Check for invalid markup
201 QDomNodeList params = e.elementsByTagName("property");
202 for (int j = 0; j < params.count(); j++) {
203 QDomElement p = params.item(j).toElement();
204 if (p.attribute("name") == "markup") {
205 QString val = p.text().toUtf8().data();
206 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
207 //e.setAttribute("value", value);
208 n.removeChild(params.item(j));
214 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
215 int in = e.attribute("in").toInt();
216 int out = e.attribute("out").toInt();
217 if (in > out || in == out) {
218 // invalid producer, remove it
219 QString id = e.attribute("id");
220 m_invalidProducers.append(id);
221 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
222 doc.documentElement().removeChild(producers.at(i));
227 for (int i = 0; i < m_projectTracks; i++) {
228 e = tracks.item(i).toElement();
229 QString playlist_name = e.attribute("producer");
230 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
231 // find playlist related to this track
233 for (int j = 0; j < m_projectTracks; j++) {
234 p = playlists.item(j).toElement();
235 if (p.attribute("id") == playlist_name) break;
237 if (p.attribute("id") != playlist_name) { // then it didn't work.
238 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
240 if (e.attribute("hide") == "video") {
241 m_doc->switchTrackVideo(i - 1, true);
242 } else if (e.attribute("hide") == "audio") {
243 m_doc->switchTrackAudio(i - 1, true);
244 } else if (e.attribute("hide") == "both") {
245 m_doc->switchTrackVideo(i - 1, true);
246 m_doc->switchTrackAudio(i - 1, true);
249 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
251 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
252 if (trackduration > duration) duration = trackduration;
254 // background black track
255 for (int j = 0; j < m_projectTracks; j++) {
256 p = playlists.item(j).toElement();
257 if (p.attribute("id") == playlist_name) break;
264 QDomNodeList transitions = doc.elementsByTagName("transition");
266 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
267 for (int i = 0; i < transitions.count(); i++) {
268 e = transitions.item(i).toElement();
269 QDomNodeList transitionparams = e.childNodes();
270 bool transitionAdd = true;
273 bool isAutomatic = false;
274 bool forceTrack = false;
275 QString mlt_geometry;
277 QString transitionId;
278 for (int k = 0; k < transitionparams.count(); k++) {
279 p = transitionparams.item(k).toElement();
281 QString paramName = p.attribute("name");
282 // do not add audio mixing transitions
283 if (paramName == "internal_added" && p.text() == "237") {
284 transitionAdd = false;
285 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
287 } else if (paramName == "a_track") {
288 a_track = qMax(0, p.text().toInt());
289 a_track = qMin(m_projectTracks - 1, a_track);
290 if (a_track != p.text().toInt()) {
291 // the transition track was out of bounds
292 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), a_track) + '\n');
293 EffectsList::setProperty(e, "a_track", QString::number(a_track));
295 } else if (paramName == "b_track") {
296 b_track = qMax(0, p.text().toInt());
297 b_track = qMin(m_projectTracks - 1, b_track);
298 if (b_track != p.text().toInt()) {
299 // the transition track was out of bounds
300 m_documentErrors.append(i18n("Transition %1 had an invalid track: %2 > %3", e.attribute("id"), p.text().toInt(), b_track) + '\n');
301 EffectsList::setProperty(e, "b_track", QString::number(b_track));
303 } else if (paramName == "mlt_service") mlt_service = p.text();
304 else if (paramName == "kdenlive_id") transitionId = p.text();
305 else if (paramName == "geometry") mlt_geometry = p.text();
306 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
307 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
310 if (a_track == b_track || b_track == 0) {
311 // invalid transition, remove it
312 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
313 tractor.removeChild(transitions.item(i));
317 if (transitionAdd || mlt_service != "mix") {
318 // Transition should be added to the scene
319 ItemInfo transitionInfo;
320 if (mlt_service == "composite" && transitionId.isEmpty()) {
321 // When adding composite transition, check if it is a wipe transition
322 if (mlt_geometry.count(';') == 1) {
323 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
324 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
325 QString start = mlt_geometry.section(';', 0, 0);
326 start = start.section(':', 0, 1);
327 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
328 QString end = mlt_geometry.section('=', 1, 1);
329 end = end.section(':', 0, 1);
330 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
331 start.append(',' + end);
332 QStringList numbers = start.split(',', QString::SkipEmptyParts);
333 bool isWipeTransition = true;
335 for (int i = 0; i < numbers.size(); ++i) {
336 checkNumber = qAbs(numbers.at(i).toInt());
337 if (checkNumber != 0 && checkNumber != 100) {
338 isWipeTransition = false;
342 if (isWipeTransition) transitionId = "slide";
346 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
348 if (!base.isNull()) for (int k = 0; k < transitionparams.count(); k++) {
349 p = transitionparams.item(k).toElement();
351 QString paramName = p.attribute("name");
352 QString paramValue = p.text();
354 QDomNodeList params = base.elementsByTagName("parameter");
355 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
356 QDomElement e = params.item(i).toElement();
357 if (!e.isNull() && e.attribute("tag") == paramName) {
358 if (e.attribute("type") == "double") {
359 QString factor = e.attribute("factor", "1");
362 if (factor.startsWith('%')) {
363 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
364 } else fact = factor.toDouble();
365 double val = paramValue.toDouble() * fact;
366 paramValue = QString::number(val);
369 e.setAttribute("value", paramValue);
377 doc.appendChild(doc.importNode(base, true));
378 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
380 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
381 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
382 transitionInfo.track = m_projectTracks - 1 - b_track;
384 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
385 if (transitionInfo.startPos >= transitionInfo.endPos || base.isNull()) {
386 // invalid transition, remove it.
387 m_documentErrors.append(i18n("Removed invalid transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
388 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
389 tractor.removeChild(transitions.item(i));
392 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
393 if (forceTrack) tr->setForcedTrack(true, a_track);
394 m_scene->addItem(tr);
395 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
396 tr->setItemLocked(true);
403 QDomNodeList guides = doc.elementsByTagName("guide");
404 for (int i = 0; i < guides.count(); i++) {
405 e = guides.item(i).toElement();
406 const QString comment = e.attribute("comment");
407 const GenTime pos = GenTime(e.attribute("time").toDouble());
408 m_trackview->addGuide(pos, comment);
412 QDomNodeList groups = doc.elementsByTagName("group");
413 m_trackview->loadGroups(groups);
414 m_trackview->setDuration(duration);
415 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
417 // Remove Kdenlive extra info from xml doc before sending it to MLT
418 QDomElement mlt = doc.firstChildElement("mlt");
419 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
420 mlt.removeChild(infoXml);
422 slotRebuildTrackHeaders();
423 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
424 if (infoXml.hasAttribute("upgraded")) {
425 // Our document was upgraded, create a backup copy just in case
426 QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
428 QString backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
429 while (QFile::exists(backupFile)) {
431 backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
433 if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this)) 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));
434 else 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));
436 //m_trackview->setCursorPos(cursorPos);
437 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
440 void TrackView::slotDeleteClip(const QString &clipId)
442 m_trackview->deleteClip(clipId);
445 void TrackView::setCursorPos(int pos)
447 m_trackview->setCursorPos(pos);
450 void TrackView::moveCursorPos(int pos)
452 m_trackview->setCursorPos(pos, false);
455 void TrackView::slotChangeZoom(int horizontal, int vertical)
457 m_ruler->setPixelPerMark(horizontal);
458 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal];
460 if (vertical == -1) {
462 m_doc->setZoom(horizontal, m_verticalZoom);
463 m_trackview->setScale(m_scale, m_scene->scale().y());
465 m_verticalZoom = vertical;
466 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
467 else m_trackview->setScale(m_scale, m_verticalZoom);
468 adjustTrackHeaders();
472 int TrackView::fitZoom() const
474 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
476 for (i = 0; i < 13; i++)
477 if (m_ruler->comboScale[i] > zoom) break;
481 KdenliveDoc *TrackView::document()
486 void TrackView::refresh()
488 m_trackview->viewport()->update();
491 void TrackView::slotRepaintTracks()
494 for (int i = 0; i < headers_container->layout()->count(); i++) {
495 child = headers_container->layout()->itemAt(i);
496 if (child->widget() && child->widget()->height() > 5) {
497 HeaderTrack *head = static_cast <HeaderTrack *>(child->widget());
498 if (head) head->setSelectedIndex(m_trackview->selectedTrack());
503 void TrackView::slotReloadTracks()
505 slotRebuildTrackHeaders();
506 emit updateTracksInfo();
509 void TrackView::slotRebuildTrackHeaders()
511 const QList <TrackInfo> list = m_doc->tracksList();
513 while ((child = headers_container->layout()->takeAt(0)) != 0) {
514 QWidget *wid = child->widget();
516 if (wid) wid->deleteLater();
518 int max = list.count();
519 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
520 HeaderTrack *header = NULL;
521 QFrame *frame = NULL;
522 for (int i = 0; i < max; i++) {
523 frame = new QFrame(headers_container);
524 frame->setFixedHeight(1);
525 frame->setFrameStyle(QFrame::Plain);
526 frame->setFrameShape(QFrame::Box);
527 frame->setLineWidth(1);
528 headers_container->layout()->addWidget(frame);
529 TrackInfo info = list.at(max - i - 1);
530 header = new HeaderTrack(i, info, height, headers_container);
531 header->setSelectedIndex(m_trackview->selectedTrack());
532 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
533 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
534 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
535 connect(header, SIGNAL(selectTrack(int)), m_trackview, SLOT(slotSelectTrack(int)));
536 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
537 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
538 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
539 connect(header, SIGNAL(renameTrack(int)), this, SLOT(slotRenameTrack(int)));
540 connect(header, SIGNAL(configTrack(int)), this, SIGNAL(configTrack(int)));
541 headers_container->layout()->addWidget(header);
543 frame = new QFrame(this);
544 frame->setFixedHeight(1);
545 frame->setFrameStyle(QFrame::Plain);
546 frame->setFrameShape(QFrame::Box);
547 frame->setLineWidth(1);
548 headers_container->layout()->addWidget(frame);
552 void TrackView::adjustTrackHeaders()
554 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
556 for (int i = 0; i < headers_container->layout()->count(); i++) {
557 child = headers_container->layout()->itemAt(i);
558 if (child->widget() && child->widget()->height() > 5)(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
562 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
566 QDomNodeList children = xml.childNodes();
567 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
568 QDomNode n = children.item(nodeindex);
569 QDomElement elem = n.toElement();
570 if (elem.tagName() == "blank") {
571 position += elem.attribute("length").toInt();
572 } else if (elem.tagName() == "entry") {
574 int in = elem.attribute("in").toInt();
575 int out = elem.attribute("out").toInt();
576 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
577 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
578 xml.removeChild(children.at(nodeindex));
582 QString idString = elem.attribute("producer");
583 QString id = idString;
586 if (idString.startsWith("slowmotion")) {
587 id = idString.section(':', 1, 1);
588 speed = idString.section(':', 2, 2).toDouble();
589 strobe = idString.section(':', 3, 3).toInt();
590 if (strobe == 0) strobe = 1;
591 } else id = id.section('_', 0, 0);
592 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
594 // The clip in playlist was not listed in the kdenlive producers,
595 // something went wrong, repair required.
596 kWarning() << "CANNOT INSERT CLIP " << id;
598 clip = getMissingProducer(id);
600 // We cannot find the producer, something is really wrong, add
601 // placeholder color clip
603 QDomElement producerXml = doc.createElement("producer");
604 doc.appendChild(producerXml);
605 producerXml.setAttribute("colour", "0xff0000ff");
606 producerXml.setAttribute("mlt_service", "colour");
607 producerXml.setAttribute("length", "15000");
608 producerXml.setAttribute("name", "INVALID");
609 producerXml.setAttribute("type", COLOR);
610 producerXml.setAttribute("id", id);
611 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
612 xml.insertBefore(producerXml, QDomNode());
613 m_doc->clipManager()->addClip(clip);
615 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
617 // Found correct producer
618 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
619 elem.setAttribute("producer", clip->getId());
621 m_doc->setModified(true);
626 clipinfo.startPos = GenTime(position, m_doc->fps());
627 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
628 clipinfo.cropStart = GenTime(in, m_doc->fps());
629 clipinfo.cropDuration = clipinfo.endPos - clipinfo.startPos;
632 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
633 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
634 if (idString.endsWith("_video")) item->setVideoOnly(true);
635 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
636 m_scene->addItem(item);
637 if (locked) item->setItemLocked(true);
638 clip->addReference();
639 position += (out - in + 1);
640 if (speed != 1.0 || strobe > 1) {
641 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
642 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
643 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
644 item->addEffect(speedeffect, false);
645 item->effectsCounter();
648 // parse clip effects
649 QDomNodeList effects = elem.childNodes();
650 for (int ix = 0; ix < effects.count(); ix++) {
651 bool disableeffect = false;
652 QDomElement effect = effects.at(ix).toElement();
653 if (effect.tagName() == "filter") {
654 // add effect to clip
657 QString effectindex = QString::number(ix + 1);
658 QString ladspaEffectFile;
659 // Get effect tag & index
660 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
661 // parse effect parameters
662 QDomElement effectparam = n3.toElement();
663 if (effectparam.attribute("name") == "tag") {
664 effecttag = effectparam.text();
665 } else if (effectparam.attribute("name") == "kdenlive_id") {
666 effectid = effectparam.text();
667 } else if (effectparam.attribute("name") == "disable" && effectparam.text().toInt() == 1) {
669 disableeffect = true;
670 } else if (effectparam.attribute("name") == "kdenlive_ix") {
672 effectparam.firstChild().setNodeValue(effectindex);
673 } else if (effectparam.attribute("name") == "src") {
674 ladspaEffectFile = effectparam.text();
675 if (!QFile::exists(ladspaEffectFile)) {
676 // If the ladspa effect file is missing, recreate it
677 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
678 ladspaEffectFile = m_doc->getLadspaFile();
679 effectparam.firstChild().setNodeValue(ladspaEffectFile);
680 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
684 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
685 // get effect standard tags
686 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
687 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
688 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
689 if (clipeffect.isNull()) {
690 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
691 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
692 elem.removeChild(effects.at(ix));
695 QDomElement currenteffect = clipeffect.cloneNode().toElement();
696 currenteffect.setAttribute("kdenlive_ix", effectindex);
697 QDomNodeList clipeffectparams = currenteffect.childNodes();
699 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
700 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
701 // effect is key-framable, read all effects to retrieve keyframes
705 QDomNodeList params = currenteffect.elementsByTagName("parameter");
706 for (int i = 0; i < params.count(); i++) {
707 QDomElement e = params.item(i).toElement();
708 if (e.attribute("type") == "keyframe") {
709 starttag = e.attribute("starttag", "start");
710 endtag = e.attribute("endtag", "end");
711 factor = e.attribute("factor", "1");
716 int effectin = effect.attribute("in").toInt();
717 int effectout = effect.attribute("out").toInt();
718 double startvalue = 0;
721 if (factor.isEmpty()) fact = 1;
722 else if (factor.startsWith('%')) {
723 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
724 } else fact = factor.toDouble();
725 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
726 // parse effect parameters
727 QDomElement effectparam = n3.toElement();
728 if (effectparam.attribute("name") == starttag)
729 startvalue = effectparam.text().toDouble() * fact;
730 if (effectparam.attribute("name") == endtag)
731 endvalue = effectparam.text().toDouble() * fact;
733 // add first keyframe
734 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
735 QDomNode lastParsedEffect;
737 QDomNode n2 = effects.at(ix);
738 bool continueParsing = true;
739 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
741 QDomElement kfreffect = n2.toElement();
742 int effectout = kfreffect.attribute("out").toInt();
744 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
745 // parse effect parameters
746 QDomElement subeffectparam = n4.toElement();
747 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
748 //We are not in the same effect, stop parsing
749 lastParsedEffect = n2.previousSibling();
751 continueParsing = false;
753 } else if (subeffectparam.attribute("name") == endtag) {
754 endvalue = subeffectparam.text().toDouble() * fact;
758 if (continueParsing) {
759 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
764 params = currenteffect.elementsByTagName("parameter");
765 for (int i = 0; i < params.count(); i++) {
766 QDomElement e = params.item(i).toElement();
767 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
769 if (!continueParsing) {
770 n2 = lastParsedEffect;
773 // Check if effect has in/out points
774 if (effect.hasAttribute("in")) {
775 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
777 if (effect.hasAttribute("out")) {
778 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
782 // adjust effect parameters
783 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
784 // parse effect parameters
785 QDomElement effectparam = n3.toElement();
786 QString paramname = effectparam.attribute("name");
787 QString paramvalue = effectparam.text();
790 // try to find this parameter in the effect xml
792 for (int k = 0; k < clipeffectparams.count(); k++) {
793 e = clipeffectparams.item(k).toElement();
794 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
795 if (e.attribute("factor", "1") != "1") {
796 QString factor = e.attribute("factor", "1");
798 if (factor.startsWith('%')) {
799 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
800 } else fact = factor.toDouble();
801 if (e.attribute("type") == "simplekeyframe") {
802 QStringList kfrs = paramvalue.split(";");
803 for (int l = 0; l < kfrs.count(); l++) {
804 QString fr = kfrs.at(l).section("=", 0, 0);
805 double val = kfrs.at(l).section("=", 1, 1).toDouble();
806 kfrs[l] = fr + ":" + QString::number((int)(val * fact));
808 e.setAttribute("keyframes", kfrs.join(";"));
809 } else e.setAttribute("value", paramvalue.toDouble() * fact);
810 } else e.setAttribute("value", paramvalue);
815 if (effecttag == "ladspa") {
816 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
818 if (!QFile::exists(ladspaEffectFile)) {
819 // If the ladspa effect file is missing, recreate it
820 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
822 currenteffect.setAttribute("src", ladspaEffectFile);
824 if (disableeffect) currenteffect.setAttribute("disable", "1");
825 item->addEffect(currenteffect, false);
830 //m_clipList.append(clip);
833 //m_trackDuration = position;
836 //documentTracks.insert(ix, track);
837 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
842 DocClipBase *TrackView::getMissingProducer(const QString id) const
844 QDomElement missingXml;
845 QDomDocument doc = m_doc->toXml();
846 QString docRoot = doc.documentElement().attribute("root");
847 if (!docRoot.endsWith('/')) docRoot.append('/');
848 QDomNodeList prods = doc.elementsByTagName("producer");
849 int maxprod = prods.count();
850 for (int i = 0; i < maxprod; i++) {
851 QDomNode m = prods.at(i);
852 QString prodId = m.toElement().attribute("id");
854 missingXml = m.toElement();
858 if (missingXml == QDomElement()) return NULL;
860 QDomNodeList params = missingXml.childNodes();
862 for (int j = 0; j < params.count(); j++) {
863 QDomElement e = params.item(j).toElement();
864 if (e.attribute("name") == "resource") {
865 resource = e.firstChild().nodeValue();
869 // prepend MLT XML document root if no path in clip resource and not a color clip
870 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
871 DocClipBase *missingClip = NULL;
872 if (!resource.isEmpty()) {
873 QList <DocClipBase *> list = m_doc->clipManager()->getClipByResource(resource);
874 if (!list.isEmpty()) missingClip = list.at(0);
879 QGraphicsScene *TrackView::projectScene()
884 CustomTrackView *TrackView::projectView()
889 void TrackView::setEditMode(const QString & editMode)
891 m_editMode = editMode;
894 const QString & TrackView::editMode() const
899 void TrackView::slotChangeTrackLock(int ix, bool lock)
901 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
902 widgets.at(ix)->setLock(lock);
906 void TrackView::slotVerticalZoomDown()
908 if (m_verticalZoom == 0) return;
910 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
911 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
912 else m_trackview->setScale(m_scene->scale().x(), 1);
913 adjustTrackHeaders();
914 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
917 void TrackView::slotVerticalZoomUp()
919 if (m_verticalZoom == 2) return;
921 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
922 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
923 else m_trackview->setScale(m_scene->scale().x(), 1);
924 adjustTrackHeaders();
925 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
928 void TrackView::updateProjectFps()
930 m_ruler->updateProjectFps(m_doc->timecode());
931 m_trackview->updateProjectFps();
934 void TrackView::slotRenameTrack(int ix)
936 int tracknumber = m_doc->tracksCount() - ix;
937 TrackInfo info = m_doc->trackInfoAt(tracknumber - 1);
939 QString newName = QInputDialog::getText(this, i18n("New Track Name"), i18n("Enter new name"), QLineEdit::Normal, info.trackName, &ok);
941 info.trackName = newName;
942 m_doc->setTrackType(tracknumber - 1, info);
943 QTimer::singleShot(300, this, SLOT(slotReloadTracks()));
944 m_doc->setModified(true);
948 void TrackView::slotUpdateVerticalScroll(int /*min*/, int max)
951 if (max > 0) height = m_trackview->horizontalScrollBar()->height() - 1;
952 headers_container->layout()->setContentsMargins(0, m_trackview->frameWidth(), 0, height);
955 void TrackView::updateRuler()
960 #include "trackview.moc"