1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "trackview.h"
22 #include "definitions.h"
23 #include "headertrack.h"
25 #include "transition.h"
26 #include "kdenlivesettings.h"
27 #include "clipmanager.h"
28 #include "customruler.h"
29 #include "kdenlivedoc.h"
30 #include "mainwindow.h"
31 #include "customtrackview.h"
32 #include "initeffects.h"
33 #include "profilesdialog.h"
36 #include <KMessageBox>
39 #include <QInputDialog>
41 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
50 // ruler_frame->setMaximumHeight();
51 // size_frame->setMaximumHeight();
52 m_scene = new CustomTrackScene(doc);
53 m_trackview = new CustomTrackView(doc, m_scene, parent);
54 m_trackview->scale(1, 1);
55 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
56 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
58 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
59 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
60 QHBoxLayout *layout = new QHBoxLayout;
61 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
62 layout->setSpacing(0);
63 ruler_frame->setLayout(layout);
64 layout->addWidget(m_ruler);
66 QHBoxLayout *sizeLayout = new QHBoxLayout;
67 sizeLayout->setContentsMargins(0, 0, 0, 0);
68 sizeLayout->setSpacing(0);
69 size_frame->setLayout(sizeLayout);
71 QToolButton *butSmall = new QToolButton(this);
72 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
73 butSmall->setToolTip(i18n("Smaller tracks"));
74 butSmall->setAutoRaise(true);
75 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
76 sizeLayout->addWidget(butSmall);
78 QToolButton *butLarge = new QToolButton(this);
79 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
80 butLarge->setToolTip(i18n("Bigger tracks"));
81 butLarge->setAutoRaise(true);
82 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
83 sizeLayout->addWidget(butLarge);
85 QHBoxLayout *tracksLayout = new QHBoxLayout;
86 tracksLayout->setContentsMargins(0, 0, 0, 0);
87 tracksLayout->setSpacing(0);
88 tracks_frame->setLayout(tracksLayout);
90 headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
91 headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
92 headers_area->setFixedWidth(70);
94 QVBoxLayout *headersLayout = new QVBoxLayout;
95 headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
96 headersLayout->setSpacing(0);
97 headers_container->setLayout(headersLayout);
98 connect(headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
100 tracksLayout->addWidget(m_trackview);
101 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), headers_area->verticalScrollBar(), SLOT(setValue(int)));
102 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
104 parseDocument(m_doc->toXml());
105 int error = m_doc->setSceneList();
106 if (error == -1) *ok = false;
108 connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
109 connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
110 connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
111 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
113 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
114 slotSetZone(m_doc->zone());
117 TrackView::~TrackView()
123 int TrackView::duration() const
125 return m_trackview->duration();
128 int TrackView::tracksNumber() const
130 return m_projectTracks - 1;
133 int TrackView::inPoint() const
135 return m_ruler->inPoint();
138 int TrackView::outPoint() const
140 return m_ruler->outPoint();
143 void TrackView::slotSetZone(QPoint p)
148 void TrackView::setDuration(int dur)
150 m_trackview->setDuration(dur);
151 m_ruler->setDuration(dur);
154 void TrackView::parseDocument(QDomDocument doc)
157 m_documentErrors.clear();
159 //kDebug() << "//// DOCUMENT: " << doc.toString();
160 /*QDomNode props = doc.elementsByTagName("properties").item(0);
161 if (!props.isNull()) {
162 cursorPos = props.toElement().attribute("timeline_position").toInt();
165 // parse project tracks
166 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
167 QDomNodeList tracks = doc.elementsByTagName("track");
168 QDomNodeList playlists = doc.elementsByTagName("playlist");
170 m_projectTracks = tracks.count();
171 int trackduration = 0;
175 int pos = m_projectTracks - 1;
176 m_invalidProducers.clear();
177 QDomNodeList producers = doc.elementsByTagName("producer");
178 for (int i = 0; i < producers.count(); i++) {
179 // Check for invalid producers
180 QDomNode n = producers.item(i);
184 // Check for invalid markup
185 QDomNodeList params = e.elementsByTagName("property");
186 for (int j = 0; j < params.count(); j++) {
187 QDomElement p = params.item(j).toElement();
188 if (p.attribute("name") == "markup") {
189 QString val = p.text().toUtf8().data();
190 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
191 //e.setAttribute("value", value);
192 n.removeChild(params.item(j));
198 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
199 int in = e.attribute("in").toInt();
200 int out = e.attribute("out").toInt();
201 if (in > out || in == out) {
202 // invalid producer, remove it
203 QString id = e.attribute("id");
204 m_invalidProducers.append(id);
205 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
206 doc.documentElement().removeChild(producers.at(i));
211 for (int i = 0; i < m_projectTracks; i++) {
212 e = tracks.item(i).toElement();
213 QString playlist_name = e.attribute("producer");
214 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
215 // find playlist related to this track
217 for (int j = 0; j < m_projectTracks; j++) {
218 p = playlists.item(j).toElement();
219 if (p.attribute("id") == playlist_name) break;
221 if (p.attribute("id") != playlist_name) { // then it didn't work.
222 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
224 if (e.attribute("hide") == "video") {
225 m_doc->switchTrackVideo(i - 1, true);
226 } else if (e.attribute("hide") == "audio") {
227 m_doc->switchTrackAudio(i - 1, true);
228 } else if (e.attribute("hide") == "both") {
229 m_doc->switchTrackVideo(i - 1, true);
230 m_doc->switchTrackAudio(i - 1, true);
233 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
235 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
236 if (trackduration > duration) duration = trackduration;
238 // background black track
239 for (int j = 0; j < m_projectTracks; j++) {
240 p = playlists.item(j).toElement();
241 if (p.attribute("id") == playlist_name) break;
243 int black_clips = p.childNodes().count();
244 for (int i = 0; i < black_clips; i++)
245 m_doc->loadingProgressed();
246 qApp->processEvents();
252 QDomNodeList transitions = doc.elementsByTagName("transition");
254 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
255 for (int i = 0; i < transitions.count(); i++) {
256 e = transitions.item(i).toElement();
257 QDomNodeList transitionparams = e.childNodes();
258 bool transitionAdd = true;
261 bool isAutomatic = false;
262 bool forceTrack = false;
263 QString mlt_geometry;
265 QString transitionId;
266 for (int k = 0; k < transitionparams.count(); k++) {
267 p = transitionparams.item(k).toElement();
269 QString paramName = p.attribute("name");
270 // do not add audio mixing transitions
271 if (paramName == "internal_added" && p.text() == "237") {
272 transitionAdd = false;
273 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
275 } else if (paramName == "a_track") a_track = p.text().toInt();
276 else if (paramName == "b_track") b_track = p.text().toInt();
277 else if (paramName == "mlt_service") mlt_service = p.text();
278 else if (paramName == "kdenlive_id") transitionId = p.text();
279 else if (paramName == "geometry") mlt_geometry = p.text();
280 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
281 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
284 if (transitionAdd || mlt_service != "mix") {
285 // Transition should be added to the scene
286 ItemInfo transitionInfo;
287 if (mlt_service == "composite" && transitionId.isEmpty()) {
288 // When adding composite transition, check if it is a wipe transition
289 if (mlt_geometry.count(';') == 1) {
290 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
291 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
292 QString start = mlt_geometry.section(';', 0, 0);
293 start = start.section(':', 0, 1);
294 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
295 QString end = mlt_geometry.section('=', 1, 1);
296 end = end.section(':', 0, 1);
297 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
298 start.append(',' + end);
299 QStringList numbers = start.split(',', QString::SkipEmptyParts);
300 bool isWipeTransition = true;
302 for (int i = 0; i < numbers.size(); ++i) {
303 checkNumber = qAbs(numbers.at(i).toInt());
304 if (checkNumber != 0 && checkNumber != 100) {
305 isWipeTransition = false;
309 if (isWipeTransition) transitionId = "slide";
312 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
314 for (int k = 0; k < transitionparams.count(); k++) {
315 p = transitionparams.item(k).toElement();
317 QString paramName = p.attribute("name");
318 QString paramValue = p.text();
320 QDomNodeList params = base.elementsByTagName("parameter");
321 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
322 QDomElement e = params.item(i).toElement();
323 if (!e.isNull() && e.attribute("tag") == paramName) {
324 if (e.attribute("type") == "double") {
325 QString factor = e.attribute("factor", "1");
328 if (factor.startsWith('%')) {
329 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
330 } else fact = factor.toDouble();
331 double val = paramValue.toDouble() * fact;
332 paramValue = QString::number(val);
335 e.setAttribute("value", paramValue);
343 doc.appendChild(doc.importNode(base, true));
344 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
346 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
347 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
348 transitionInfo.track = m_projectTracks - 1 - b_track;
349 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
350 if (transitionInfo.startPos >= transitionInfo.endPos) {
351 // invalid transition, remove it.
352 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
353 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
354 tractor.removeChild(transitions.item(i));
357 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
358 if (forceTrack) tr->setForcedTrack(true, a_track);
359 m_scene->addItem(tr);
360 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
361 tr->setItemLocked(true);
368 QDomNodeList guides = doc.elementsByTagName("guide");
369 for (int i = 0; i < guides.count(); i++) {
370 e = guides.item(i).toElement();
371 const QString comment = e.attribute("comment");
372 const GenTime pos = GenTime(e.attribute("time").toDouble());
373 m_trackview->addGuide(pos, comment);
377 QDomNodeList groups = doc.elementsByTagName("group");
378 m_trackview->loadGroups(groups);
379 m_trackview->setDuration(duration);
380 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
382 // Remove Kdenlive extra info from xml doc before sending it to MLT
383 QDomElement mlt = doc.firstChildElement("mlt");
384 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
385 mlt.removeChild(infoXml);
387 slotRebuildTrackHeaders();
388 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
389 //m_trackview->setCursorPos(cursorPos);
390 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
393 void TrackView::slotDeleteClip(const QString &clipId)
395 m_trackview->deleteClip(clipId);
398 void TrackView::setCursorPos(int pos)
400 m_trackview->setCursorPos(pos);
403 void TrackView::moveCursorPos(int pos)
405 m_trackview->setCursorPos(pos, false);
408 void TrackView::slotChangeZoom(int horizontal, int vertical)
410 m_ruler->setPixelPerMark(horizontal);
411 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal]; // m_ruler->comboScale[m_currentZoom] /
413 if (vertical == -1) {
415 m_doc->setZoom(horizontal, m_verticalZoom);
416 m_trackview->setScale(m_scale, m_scene->scale().y());
418 m_verticalZoom = vertical;
419 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
420 else m_trackview->setScale(m_scale, m_verticalZoom);
421 adjustTrackHeaders();
425 int TrackView::fitZoom() const
427 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
429 for (i = 0; i < 13; i++)
430 if (m_ruler->comboScale[i] > zoom) break;
434 KdenliveDoc *TrackView::document()
439 void TrackView::refresh()
441 m_trackview->viewport()->update();
444 void TrackView::slotRebuildTrackHeaders()
446 const QList <TrackInfo> list = m_doc->tracksList();
448 while ((child = headers_container->layout()->takeAt(0)) != 0) {
449 QWidget *wid = child->widget();
451 if (wid) wid->deleteLater();
453 int max = list.count();
454 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
455 HeaderTrack *header = NULL;
456 QFrame *frame = NULL;
457 for (int i = 0; i < max; i++) {
458 frame = new QFrame(headers_container);
459 frame->setFixedHeight(1);
460 frame->setFrameStyle(QFrame::Plain);
461 frame->setFrameShape(QFrame::Box);
462 frame->setLineWidth(1);
463 headers_container->layout()->addWidget(frame);
464 TrackInfo info = list.at(max - i - 1);
465 header = new HeaderTrack(i, info, height, headers_container);
466 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
467 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
468 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
470 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
471 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
472 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
473 connect(header, SIGNAL(renameTrack(int)), this, SLOT(slotRenameTrack(int)));
474 headers_container->layout()->addWidget(header);
476 frame = new QFrame(this);
477 frame->setFixedHeight(1);
478 frame->setFrameStyle(QFrame::Plain);
479 frame->setFrameShape(QFrame::Box);
480 frame->setLineWidth(1);
481 headers_container->layout()->addWidget(frame);
485 void TrackView::adjustTrackHeaders()
487 int height = KdenliveSettings::trackheight() * m_scene->scale().y() - 1;
489 for (int i = 0; i < headers_container->layout()->count(); i++) {
490 child = headers_container->layout()->itemAt(i);
491 if (child->widget() && child->widget()->height() > 5)(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
495 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
499 QDomNodeList children = xml.childNodes();
500 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
501 QDomNode n = children.item(nodeindex);
502 QDomElement elem = n.toElement();
503 if (elem.tagName() == "blank") {
504 position += elem.attribute("length").toInt();
505 } else if (elem.tagName() == "entry") {
506 m_doc->loadingProgressed();
507 qApp->processEvents();
509 int in = elem.attribute("in").toInt();
510 int out = elem.attribute("out").toInt();
511 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
512 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
513 xml.removeChild(children.at(nodeindex));
517 QString idString = elem.attribute("producer");
518 QString id = idString;
521 if (idString.startsWith("slowmotion")) {
522 id = idString.section(':', 1, 1);
523 speed = idString.section(':', 2, 2).toDouble();
524 strobe = idString.section(':', 3, 3).toInt();
525 if (strobe == 0) strobe = 1;
526 } else id = id.section('_', 0, 0);
527 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
529 // The clip in playlist was not listed in the kdenlive producers,
530 // something went wrong, repair required.
531 kWarning() << "CANNOT INSERT CLIP " << id;
533 clip = getMissingProducer(id);
535 // We cannot find the producer, something is really wrong, add
536 // placeholder color clip
538 QDomElement producerXml = doc.createElement("producer");
539 doc.appendChild(producerXml);
540 producerXml.setAttribute("colour", "0xff0000ff");
541 producerXml.setAttribute("mlt_service", "colour");
542 producerXml.setAttribute("length", "15000");
543 producerXml.setAttribute("name", "INVALID");
544 producerXml.setAttribute("type", COLOR);
545 producerXml.setAttribute("id", id);
546 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
547 xml.insertBefore(producerXml, QDomNode());
548 m_doc->clipManager()->addClip(clip);
550 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
552 // Found correct producer
553 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
554 elem.setAttribute("producer", clip->getId());
556 m_doc->setModified(true);
561 clipinfo.startPos = GenTime(position, m_doc->fps());
562 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
563 clipinfo.cropStart = GenTime(in, m_doc->fps());
564 clipinfo.cropDuration = GenTime((int)((clipinfo.endPos - clipinfo.startPos).frames(m_doc->fps()) * speed + 0.5), m_doc->fps());
565 clipinfo.originalcropStart = GenTime((int)((clipinfo.cropStart).frames(m_doc->fps()) * speed + 0.5), m_doc->fps());
568 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
569 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
570 if (idString.endsWith("_video")) item->setVideoOnly(true);
571 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
572 m_scene->addItem(item);
573 if (locked) item->setItemLocked(true);
574 clip->addReference();
575 position += (out - in + 1);
576 kDebug() << "/////////\n\n\n" << "CLIP SPEED: " << speed << ", " << strobe << "\n\n\n/////////////////////";
577 if (speed != 1.0 || strobe > 1) {
578 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
579 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
580 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
581 item->addEffect(speedeffect, false);
582 item->effectsCounter();
585 // parse clip effects
586 QDomNodeList effects = elem.childNodes();
587 for (int ix = 0; ix < effects.count(); ix++) {
588 QDomElement effect = effects.at(ix).toElement();
589 if (effect.tagName() == "filter") {
590 // add effect to clip
594 QString ladspaEffectFile;
595 // Get effect tag & index
596 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
597 // parse effect parameters
598 QDomElement effectparam = n3.toElement();
599 if (effectparam.attribute("name") == "tag") {
600 effecttag = effectparam.text();
601 } else if (effectparam.attribute("name") == "kdenlive_id") {
602 effectid = effectparam.text();
603 } else if (effectparam.attribute("name") == "kdenlive_ix") {
604 effectindex = effectparam.text();
605 } else if (effectparam.attribute("name") == "src") {
606 ladspaEffectFile = effectparam.text();
607 if (!QFile::exists(ladspaEffectFile)) {
608 // If the ladspa effect file is missing, recreate it
609 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
610 ladspaEffectFile = m_doc->getLadspaFile();
611 effectparam.firstChild().setNodeValue(ladspaEffectFile);
612 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
616 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
617 // get effect standard tags
618 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
619 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
620 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
621 if (clipeffect.isNull()) {
622 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
623 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
624 elem.removeChild(effects.at(ix));
627 QDomElement currenteffect = clipeffect.cloneNode().toElement();
628 currenteffect.setAttribute("kdenlive_ix", effectindex);
629 QDomNodeList clipeffectparams = currenteffect.childNodes();
631 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
632 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
633 // effect is key-framable, read all effects to retrieve keyframes
637 QDomNodeList params = currenteffect.elementsByTagName("parameter");
638 for (int i = 0; i < params.count(); i++) {
639 QDomElement e = params.item(i).toElement();
640 if (e.attribute("type") == "keyframe") {
641 starttag = e.attribute("starttag", "start");
642 endtag = e.attribute("endtag", "end");
643 factor = e.attribute("factor", "1");
648 int effectin = effect.attribute("in").toInt();
649 int effectout = effect.attribute("out").toInt();
650 double startvalue = 0;
653 if (factor.isEmpty()) fact = 1;
654 else if (factor.startsWith('%')) {
655 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
656 } else fact = factor.toDouble();
657 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
658 // parse effect parameters
659 QDomElement effectparam = n3.toElement();
660 if (effectparam.attribute("name") == starttag)
661 startvalue = effectparam.text().toDouble() * fact;
662 if (effectparam.attribute("name") == endtag)
663 endvalue = effectparam.text().toDouble() * fact;
665 // add first keyframe
666 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
667 QDomNode lastParsedEffect;
669 QDomNode n2 = effects.at(ix);
670 bool continueParsing = true;
671 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
673 QDomElement kfreffect = n2.toElement();
674 int effectout = kfreffect.attribute("out").toInt();
676 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
677 // parse effect parameters
678 QDomElement subeffectparam = n4.toElement();
679 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
680 //We are not in the same effect, stop parsing
681 lastParsedEffect = n2.previousSibling();
683 continueParsing = false;
685 } else if (subeffectparam.attribute("name") == endtag) {
686 endvalue = subeffectparam.text().toDouble() * fact;
690 if (continueParsing) {
691 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
696 params = currenteffect.elementsByTagName("parameter");
697 for (int i = 0; i < params.count(); i++) {
698 QDomElement e = params.item(i).toElement();
699 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
701 if (!continueParsing) {
702 n2 = lastParsedEffect;
705 // Check if effect has in/out points
706 if (effect.hasAttribute("in")) {
707 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
709 if (effect.hasAttribute("out")) {
710 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
714 // adjust effect parameters
715 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
716 // parse effect parameters
717 QDomElement effectparam = n3.toElement();
718 QString paramname = effectparam.attribute("name");
719 QString paramvalue = effectparam.text();
722 // try to find this parameter in the effect xml
724 for (int k = 0; k < clipeffectparams.count(); k++) {
725 e = clipeffectparams.item(k).toElement();
726 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
727 if (e.attribute("factor", "1") != "1") {
728 QString factor = e.attribute("factor", "1");
730 if (factor.startsWith('%')) {
731 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
732 } else fact = factor.toDouble();
733 e.setAttribute("value", paramvalue.toDouble() * fact);
734 } else e.setAttribute("value", paramvalue);
739 if (effecttag == "ladspa") {
740 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
742 if (!QFile::exists(ladspaEffectFile)) {
743 // If the ladspa effect file is missing, recreate it
744 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
746 currenteffect.setAttribute("src", ladspaEffectFile);
748 item->addEffect(currenteffect, false);
749 item->effectsCounter();
754 //m_clipList.append(clip);
757 //m_trackDuration = position;
760 //documentTracks.insert(ix, track);
761 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
766 DocClipBase *TrackView::getMissingProducer(const QString id) const
768 QDomElement missingXml;
769 QDomDocument doc = m_doc->toXml();
770 QString docRoot = doc.documentElement().attribute("root");
771 if (!docRoot.endsWith('/')) docRoot.append('/');
772 QDomNodeList prods = doc.elementsByTagName("producer");
773 int maxprod = prods.count();
774 for (int i = 0; i < maxprod; i++) {
775 QDomNode m = prods.at(i);
776 QString prodId = m.toElement().attribute("id");
778 missingXml = m.toElement();
782 if (missingXml == QDomElement()) return NULL;
784 QDomNodeList params = missingXml.childNodes();
786 for (int j = 0; j < params.count(); j++) {
787 QDomElement e = params.item(j).toElement();
788 if (e.attribute("name") == "resource") {
789 resource = e.firstChild().nodeValue();
793 // prepend MLT XML document root if no path in clip resource and not a color clip
794 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
795 DocClipBase *missingClip = NULL;
796 if (!resource.isEmpty()) {
797 QList <DocClipBase *> list = m_doc->clipManager()->getClipByResource(resource);
798 if (!list.isEmpty()) missingClip = list.at(0);
803 QGraphicsScene *TrackView::projectScene()
808 CustomTrackView *TrackView::projectView()
813 void TrackView::setEditMode(const QString & editMode)
815 m_editMode = editMode;
818 const QString & TrackView::editMode() const
823 void TrackView::slotChangeTrackLock(int ix, bool lock)
825 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
826 widgets.at(ix)->setLock(lock);
829 void TrackView::slotVerticalZoomDown()
831 if (m_verticalZoom == 0) return;
833 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
834 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
835 else m_trackview->setScale(m_scene->scale().x(), 1);
836 adjustTrackHeaders();
837 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
840 void TrackView::slotVerticalZoomUp()
842 if (m_verticalZoom == 2) return;
844 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
845 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
846 else m_trackview->setScale(m_scene->scale().x(), 1);
847 adjustTrackHeaders();
848 m_trackview->verticalScrollBar()->setValue(headers_area->verticalScrollBar()->value());
851 void TrackView::updateProjectFps()
853 m_ruler->updateProjectFps(m_doc->timecode());
854 m_trackview->updateProjectFps();
857 void TrackView::slotRenameTrack(int ix)
859 int tracknumber = m_doc->tracksCount() - ix;
860 TrackInfo info = m_doc->trackInfoAt(tracknumber - 1);
862 QString newName = QInputDialog::getText(this, i18n("New Track Name"), i18n("Enter new name"), QLineEdit::Normal, info.trackName, &ok);
864 info.trackName = newName;
865 m_doc->setTrackType(tracknumber - 1, info);
866 QTimer::singleShot(300, this, SLOT(slotRebuildTrackHeaders()));
867 m_doc->setModified(true);
872 #include "trackview.moc"