1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "trackview.h"
22 #include "definitions.h"
23 #include "headertrack.h"
25 #include "transition.h"
26 #include "kdenlivesettings.h"
27 #include "clipmanager.h"
28 #include "customruler.h"
29 #include "kdenlivedoc.h"
30 #include "mainwindow.h"
31 #include "customtrackview.h"
32 #include "initeffects.h"
33 #include "profilesdialog.h"
36 #include <KMessageBox>
39 #include <QInputDialog>
41 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
51 m_scene = new CustomTrackScene(doc);
52 m_trackview = new CustomTrackView(doc, m_scene, parent);
53 m_trackview->scale(1, 1);
54 m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
55 //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));
57 m_ruler = new CustomRuler(doc->timecode(), m_trackview);
58 connect(m_ruler, SIGNAL(zoneMoved(int, int)), this, SIGNAL(zoneMoved(int, int)));
59 QHBoxLayout *layout = new QHBoxLayout;
60 layout->setContentsMargins(m_trackview->frameWidth(), 0, 0, 0);
61 layout->setSpacing(0);
62 m_view.ruler_frame->setLayout(layout);
63 layout->addWidget(m_ruler);
66 QHBoxLayout *sizeLayout = new QHBoxLayout;
67 sizeLayout->setContentsMargins(0, 0, 0, 0);
68 sizeLayout->setSpacing(0);
69 m_view.size_frame->setLayout(sizeLayout);
71 QString style1 = "QToolButton {border-style: none;margin: 0px 3px;padding: 0px;} QToolButton:pressed:hover { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;} QToolButton:hover { background-color: rgba(255, 255, 255, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
73 QToolButton *butSmall = new QToolButton(this);
74 butSmall->setIcon(KIcon("kdenlive-zoom-small"));
75 butSmall->setToolTip(i18n("Smaller tracks"));
76 connect(butSmall, SIGNAL(clicked()), this, SLOT(slotVerticalZoomDown()));
77 sizeLayout->addWidget(butSmall);
79 QToolButton *butLarge = new QToolButton(this);
80 butLarge->setIcon(KIcon("kdenlive-zoom-large"));
81 butLarge->setToolTip(i18n("Bigger tracks"));
82 connect(butLarge, SIGNAL(clicked()), this, SLOT(slotVerticalZoomUp()));
83 sizeLayout->addWidget(butLarge);
84 m_view.size_frame->setStyleSheet(style1);
87 QHBoxLayout *tracksLayout = new QHBoxLayout;
88 tracksLayout->setContentsMargins(0, 0, 0, 0);
89 tracksLayout->setSpacing(0);
90 m_view.tracks_frame->setLayout(tracksLayout);
92 m_view.headers_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
93 m_view.headers_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
95 m_headersLayout = new QVBoxLayout;
96 m_headersLayout->setContentsMargins(0, m_trackview->frameWidth(), 0, 0);
97 m_headersLayout->setSpacing(0);
98 m_view.headers_container->setLayout(m_headersLayout);
100 connect(m_view.headers_area->verticalScrollBar(), SIGNAL(valueChanged(int)), m_trackview->verticalScrollBar(), SLOT(setValue(int)));
102 tracksLayout->addWidget(m_trackview);
104 connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), m_view.headers_area->verticalScrollBar(), SLOT(setValue(int)));
105 connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
107 parseDocument(m_doc->toXml());
108 int error = m_doc->setSceneList();
109 if (error == -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, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
114 connect(m_trackview, SIGNAL(doTrackLock(int, bool)), this, SLOT(slotChangeTrackLock(int, bool)));
116 slotChangeZoom(m_doc->zoom().x(), m_doc->zoom().y());
117 slotSetZone(m_doc->zone());
120 TrackView::~TrackView()
126 int TrackView::duration() const
128 return m_trackview->duration();
131 int TrackView::tracksNumber() const
133 return m_projectTracks - 1;
136 int TrackView::inPoint() const
138 return m_ruler->inPoint();
141 int TrackView::outPoint() const
143 return m_ruler->outPoint();
146 void TrackView::slotSetZone(QPoint p)
151 void TrackView::setDuration(int dur)
153 m_trackview->setDuration(dur);
154 m_ruler->setDuration(dur);
157 void TrackView::parseDocument(QDomDocument doc)
160 m_documentErrors.clear();
162 //kDebug() << "//// DOCUMENT: " << doc.toString();
163 /*QDomNode props = doc.elementsByTagName("properties").item(0);
164 if (!props.isNull()) {
165 cursorPos = props.toElement().attribute("timeline_position").toInt();
168 // parse project tracks
169 QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
170 QDomNodeList tracks = doc.elementsByTagName("track");
171 QDomNodeList playlists = doc.elementsByTagName("playlist");
173 m_projectTracks = tracks.count();
174 int trackduration = 0;
178 int pos = m_projectTracks - 1;
179 m_invalidProducers.clear();
180 QDomNodeList producers = doc.elementsByTagName("producer");
181 for (int i = 0; i < producers.count(); i++) {
182 // Check for invalid producers
183 QDomNode n = producers.item(i);
187 // Check for invalid markup
188 QDomNodeList params = e.elementsByTagName("property");
189 for (int j = 0; j < params.count(); j++) {
190 QDomElement p = params.item(j).toElement();
191 if (p.attribute("name") == "markup") {
192 QString val = p.text().toUtf8().data();
193 kDebug()<<"//FOUND MARKUP, VAL: "<<val;
194 //e.setAttribute("value", value);
195 n.removeChild(params.item(j));
201 if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
202 int in = e.attribute("in").toInt();
203 int out = e.attribute("out").toInt();
204 if (in > out || in == out) {
205 // invalid producer, remove it
206 QString id = e.attribute("id");
207 m_invalidProducers.append(id);
208 m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
209 doc.documentElement().removeChild(producers.at(i));
214 for (int i = 0; i < m_projectTracks; i++) {
215 e = tracks.item(i).toElement();
216 QString playlist_name = e.attribute("producer");
217 if (playlist_name != "black_track" && playlist_name != "playlistmain") {
218 // find playlist related to this track
220 for (int j = 0; j < m_projectTracks; j++) {
221 p = playlists.item(j).toElement();
222 if (p.attribute("id") == playlist_name) break;
224 if (p.attribute("id") != playlist_name) { // then it didn't work.
225 kDebug() << "NO PLAYLIST FOUND FOR TRACK " + pos;
227 if (e.attribute("hide") == "video") {
228 m_doc->switchTrackVideo(i - 1, true);
229 } else if (e.attribute("hide") == "audio") {
230 m_doc->switchTrackAudio(i - 1, true);
231 } else if (e.attribute("hide") == "both") {
232 m_doc->switchTrackVideo(i - 1, true);
233 m_doc->switchTrackAudio(i - 1, true);
236 trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
238 //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
239 if (trackduration > duration) duration = trackduration;
241 // background black track
242 for (int j = 0; j < m_projectTracks; j++) {
243 p = playlists.item(j).toElement();
244 if (p.attribute("id") == playlist_name) break;
246 int black_clips = p.childNodes().count();
247 for (int i = 0; i < black_clips; i++)
248 m_doc->loadingProgressed();
249 qApp->processEvents();
255 QDomNodeList transitions = doc.elementsByTagName("transition");
257 //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
258 for (int i = 0; i < transitions.count(); i++) {
259 e = transitions.item(i).toElement();
260 QDomNodeList transitionparams = e.childNodes();
261 bool transitionAdd = true;
264 bool isAutomatic = false;
265 bool forceTrack = false;
266 QString mlt_geometry;
268 QString transitionId;
269 for (int k = 0; k < transitionparams.count(); k++) {
270 p = transitionparams.item(k).toElement();
272 QString paramName = p.attribute("name");
273 // do not add audio mixing transitions
274 if (paramName == "internal_added" && p.text() == "237") {
275 transitionAdd = false;
276 //kDebug() << "// TRANSITRION " << i << " IS NOT VALID (INTERN ADDED)";
278 } else if (paramName == "a_track") a_track = p.text().toInt();
279 else if (paramName == "b_track") b_track = p.text().toInt();
280 else if (paramName == "mlt_service") mlt_service = p.text();
281 else if (paramName == "kdenlive_id") transitionId = p.text();
282 else if (paramName == "geometry") mlt_geometry = p.text();
283 else if (paramName == "automatic" && p.text() == "1") isAutomatic = true;
284 else if (paramName == "force_track" && p.text() == "1") forceTrack = true;
287 if (transitionAdd || mlt_service != "mix") {
288 // Transition should be added to the scene
289 ItemInfo transitionInfo;
290 if (mlt_service == "composite" && transitionId.isEmpty()) {
291 // When adding composite transition, check if it is a wipe transition
292 if (mlt_geometry.count(';') == 1) {
293 mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
294 mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
295 QString start = mlt_geometry.section(';', 0, 0);
296 start = start.section(':', 0, 1);
297 start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
298 QString end = mlt_geometry.section('=', 1, 1);
299 end = end.section(':', 0, 1);
300 end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive);
301 start.append(',' + end);
302 QStringList numbers = start.split(',', QString::SkipEmptyParts);
303 bool isWipeTransition = true;
305 for (int i = 0; i < numbers.size(); ++i) {
306 checkNumber = qAbs(numbers.at(i).toInt());
307 if (checkNumber != 0 && checkNumber != 100) {
308 isWipeTransition = false;
312 if (isWipeTransition) transitionId = "slide";
315 QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, transitionId).cloneNode().toElement();
317 for (int k = 0; k < transitionparams.count(); k++) {
318 p = transitionparams.item(k).toElement();
320 QString paramName = p.attribute("name");
321 QString paramValue = p.text();
323 QDomNodeList params = base.elementsByTagName("parameter");
324 if (paramName != "a_track" && paramName != "b_track") for (int i = 0; i < params.count(); i++) {
325 QDomElement e = params.item(i).toElement();
326 if (!e.isNull() && e.attribute("tag") == paramName) {
327 if (e.attribute("type") == "double") {
328 QString factor = e.attribute("factor", "1");
331 if (factor.startsWith('%')) {
332 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
333 } else fact = factor.toDouble();
334 double val = paramValue.toDouble() * fact;
335 paramValue = QString::number(val);
338 e.setAttribute("value", paramValue);
346 doc.appendChild(doc.importNode(base, true));
347 kDebug() << "/////// TRANSITION XML: "<< doc.toString();*/
349 transitionInfo.startPos = GenTime(e.attribute("in").toInt(), m_doc->fps());
350 transitionInfo.endPos = GenTime(e.attribute("out").toInt() + 1, m_doc->fps());
351 transitionInfo.track = m_projectTracks - 1 - b_track;
352 //kDebug() << "/////////////// +++++++++++ ADDING TRANSITION ON TRACK: " << b_track << ", TOTAL TRKA: " << m_projectTracks;
353 if (transitionInfo.startPos >= transitionInfo.endPos) {
354 // invalid transition, remove it.
355 m_documentErrors.append(i18n("Removed invalid transition: %1", e.attribute("id")) + '\n');
356 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
357 tractor.removeChild(transitions.item(i));
360 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
361 if (forceTrack) tr->setForcedTrack(true, a_track);
362 m_scene->addItem(tr);
363 if (b_track > 0 && m_doc->isTrackLocked(b_track - 1)) {
364 tr->setItemLocked(true);
371 QDomNodeList guides = doc.elementsByTagName("guide");
372 for (int i = 0; i < guides.count(); i++) {
373 e = guides.item(i).toElement();
374 const QString comment = e.attribute("comment");
375 const GenTime pos = GenTime(e.attribute("time").toDouble());
376 m_trackview->addGuide(pos, comment);
380 QDomNodeList groups = doc.elementsByTagName("group");
381 m_trackview->loadGroups(groups);
382 m_trackview->setDuration(duration);
383 kDebug() << "/////////// TOTAL PROJECT DURATION: " << duration;
385 // Remove Kdenlive extra info from xml doc before sending it to MLT
386 QDomElement mlt = doc.firstChildElement("mlt");
387 QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
388 mlt.removeChild(infoXml);
390 slotRebuildTrackHeaders();
391 if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
392 //m_trackview->setCursorPos(cursorPos);
393 //m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
396 void TrackView::slotDeleteClip(const QString &clipId)
398 m_trackview->deleteClip(clipId);
401 void TrackView::setCursorPos(int pos)
403 m_trackview->setCursorPos(pos);
406 void TrackView::moveCursorPos(int pos)
408 m_trackview->setCursorPos(pos, false);
411 void TrackView::slotChangeZoom(int horizontal, int vertical)
413 m_ruler->setPixelPerMark(horizontal);
414 m_scale = (double) FRAME_SIZE / m_ruler->comboScale[horizontal]; // m_ruler->comboScale[m_currentZoom] /
416 if (vertical == -1) {
418 m_doc->setZoom(horizontal, m_verticalZoom);
419 m_trackview->setScale(m_scale, m_scene->scale().y());
421 m_verticalZoom = vertical;
422 if (m_verticalZoom == 0) m_trackview->setScale(m_scale, 0.5);
423 else m_trackview->setScale(m_scale, m_verticalZoom);
424 adjustTrackHeaders();
428 int TrackView::fitZoom() const
430 int zoom = (int)((duration() + 20 / m_scale) * FRAME_SIZE / m_trackview->width());
432 for (i = 0; i < 13; i++)
433 if (m_ruler->comboScale[i] > zoom) break;
437 KdenliveDoc *TrackView::document()
442 void TrackView::refresh()
444 m_trackview->viewport()->update();
447 void TrackView::slotRebuildTrackHeaders()
449 QList <TrackInfo> list = m_doc->tracksList();
451 while ((child = m_headersLayout->takeAt(0)) != 0) {
452 if (child->widget()) delete child->widget();
455 int max = list.count();
456 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
457 for (int i = 0; i < max; i++) {
458 HeaderTrack *header = new HeaderTrack(i, list.at(max - i - 1), height, this);
459 connect(header, SIGNAL(switchTrackVideo(int)), m_trackview, SLOT(slotSwitchTrackVideo(int)));
460 connect(header, SIGNAL(switchTrackAudio(int)), m_trackview, SLOT(slotSwitchTrackAudio(int)));
461 connect(header, SIGNAL(switchTrackLock(int)), m_trackview, SLOT(slotSwitchTrackLock(int)));
463 connect(header, SIGNAL(deleteTrack(int)), this, SIGNAL(deleteTrack(int)));
464 connect(header, SIGNAL(insertTrack(int)), this, SIGNAL(insertTrack(int)));
465 connect(header, SIGNAL(changeTrack(int)), this, SIGNAL(changeTrack(int)));
466 connect(header, SIGNAL(renameTrack(int)), this, SLOT(slotRenameTrack(int)));
467 m_headersLayout->addWidget(header);
472 void TrackView::adjustTrackHeaders()
474 int height = KdenliveSettings::trackheight() * m_scene->scale().y();
476 for (int i = 0; i < m_headersLayout->count(); i++) {
477 child = m_headersLayout->itemAt(i);
478 if (child->widget())(static_cast <HeaderTrack *>(child->widget()))->adjustSize(height);
482 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
486 QDomNodeList children = xml.childNodes();
487 for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
488 QDomNode n = children.item(nodeindex);
489 QDomElement elem = n.toElement();
490 if (elem.tagName() == "blank") {
491 position += elem.attribute("length").toInt();
492 } else if (elem.tagName() == "entry") {
493 m_doc->loadingProgressed();
494 qApp->processEvents();
496 int in = elem.attribute("in").toInt();
497 int out = elem.attribute("out").toInt();
498 if (in > out || /*in == out ||*/ m_invalidProducers.contains(elem.attribute("producer"))) {
499 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
500 xml.removeChild(children.at(nodeindex));
504 QString idString = elem.attribute("producer");
505 QString id = idString;
508 if (idString.startsWith("slowmotion")) {
509 id = idString.section(':', 1, 1);
510 speed = idString.section(':', 2, 2).toDouble();
511 strobe = idString.section(':', 3, 3).toInt();
512 if (strobe == 0) strobe = 1;
513 } else id = id.section('_', 0, 0);
514 DocClipBase *clip = m_doc->clipManager()->getClipById(id);
516 // The clip in playlist was not listed in the kdenlive producers,
517 // something went wrong, repair required.
518 kWarning() << "CANNOT INSERT CLIP " << id;
520 clip = getMissingProducer(id);
522 // We cannot find the producer, something is really wrong, add
523 // placeholder color clip
525 QDomElement producerXml = doc.createElement("producer");
526 doc.appendChild(producerXml);
527 producerXml.setAttribute("colour", "0xff0000ff");
528 producerXml.setAttribute("mlt_service", "colour");
529 producerXml.setAttribute("length", "15000");
530 producerXml.setAttribute("name", "INVALID");
531 producerXml.setAttribute("type", COLOR);
532 producerXml.setAttribute("id", id);
533 clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
534 xml.insertBefore(producerXml, QDomNode());
535 m_doc->clipManager()->addClip(clip);
537 m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
539 // Found correct producer
540 m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
541 elem.setAttribute("producer", clip->getId());
543 m_doc->setModified(true);
548 clipinfo.startPos = GenTime(position, m_doc->fps());
549 clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
550 clipinfo.cropStart = GenTime(in, m_doc->fps());
552 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
553 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, strobe, false);
554 if (idString.endsWith("_video")) item->setVideoOnly(true);
555 else if (idString.endsWith("_audio")) item->setAudioOnly(true);
556 m_scene->addItem(item);
557 if (locked) item->setItemLocked(true);
558 clip->addReference();
559 position += (out - in + 1);
560 kDebug() << "/////////\n\n\n" << "CLIP SPEED: " << speed << ", " << strobe << "\n\n\n/////////////////////";
561 if (speed != 1.0 || strobe > 1) {
562 QDomElement speedeffect = MainWindow::videoEffects.getEffectByTag(QString(), "speed").cloneNode().toElement();
563 EffectsList::setParameter(speedeffect, "speed", QString::number((int)(100 * speed + 0.5)));
564 EffectsList::setParameter(speedeffect, "strobe", QString::number(strobe));
565 item->addEffect(speedeffect, false);
566 item->effectsCounter();
569 // parse clip effects
570 QDomNodeList effects = elem.childNodes();
571 for (int ix = 0; ix < effects.count(); ix++) {
572 QDomElement effect = effects.at(ix).toElement();
573 if (effect.tagName() == "filter") {
574 // add effect to clip
578 QString ladspaEffectFile;
579 // Get effect tag & index
580 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
581 // parse effect parameters
582 QDomElement effectparam = n3.toElement();
583 if (effectparam.attribute("name") == "tag") {
584 effecttag = effectparam.text();
585 } else if (effectparam.attribute("name") == "kdenlive_id") {
586 effectid = effectparam.text();
587 } else if (effectparam.attribute("name") == "kdenlive_ix") {
588 effectindex = effectparam.text();
589 } else if (effectparam.attribute("name") == "src") {
590 ladspaEffectFile = effectparam.text();
591 if (!QFile::exists(ladspaEffectFile)) {
592 // If the ladspa effect file is missing, recreate it
593 kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
594 ladspaEffectFile = m_doc->getLadspaFile();
595 effectparam.firstChild().setNodeValue(ladspaEffectFile);
596 kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
600 //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
601 // get effect standard tags
602 QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
603 if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
604 if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
605 if (clipeffect.isNull()) {
606 kDebug() << "/// WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
607 m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
608 elem.removeChild(effects.at(ix));
611 QDomElement currenteffect = clipeffect.cloneNode().toElement();
612 currenteffect.setAttribute("kdenlive_ix", effectindex);
613 QDomNodeList clipeffectparams = currenteffect.childNodes();
615 if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
616 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *";
617 // effect is key-framable, read all effects to retrieve keyframes
621 QDomNodeList params = currenteffect.elementsByTagName("parameter");
622 for (int i = 0; i < params.count(); i++) {
623 QDomElement e = params.item(i).toElement();
624 if (e.attribute("type") == "keyframe") {
625 starttag = e.attribute("starttag", "start");
626 endtag = e.attribute("endtag", "end");
627 factor = e.attribute("factor", "1");
632 int effectin = effect.attribute("in").toInt();
633 int effectout = effect.attribute("out").toInt();
634 double startvalue = 0;
637 if (factor.isEmpty()) fact = 1;
638 else if (factor.startsWith('%')) {
639 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
640 } else fact = factor.toDouble();
641 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
642 // parse effect parameters
643 QDomElement effectparam = n3.toElement();
644 if (effectparam.attribute("name") == starttag)
645 startvalue = effectparam.text().toDouble() * fact;
646 if (effectparam.attribute("name") == endtag)
647 endvalue = effectparam.text().toDouble() * fact;
649 // add first keyframe
650 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
651 QDomNode lastParsedEffect;
653 QDomNode n2 = effects.at(ix);
654 bool continueParsing = true;
655 for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
657 QDomElement kfreffect = n2.toElement();
658 int effectout = kfreffect.attribute("out").toInt();
660 for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
661 // parse effect parameters
662 QDomElement subeffectparam = n4.toElement();
663 if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
664 //We are not in the same effect, stop parsing
665 lastParsedEffect = n2.previousSibling();
667 continueParsing = false;
669 } else if (subeffectparam.attribute("name") == endtag) {
670 endvalue = subeffectparam.text().toDouble() * fact;
674 if (continueParsing) {
675 keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';');
680 params = currenteffect.elementsByTagName("parameter");
681 for (int i = 0; i < params.count(); i++) {
682 QDomElement e = params.item(i).toElement();
683 if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
685 if (!continueParsing) {
686 n2 = lastParsedEffect;
689 // Check if effect has in/out points
690 if (effect.hasAttribute("in")) {
691 EffectsList::setParameter(currenteffect, "in", effect.attribute("in"));
693 if (effect.hasAttribute("out")) {
694 EffectsList::setParameter(currenteffect, "out", effect.attribute("out"));
698 // adjust effect parameters
699 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
700 // parse effect parameters
701 QDomElement effectparam = n3.toElement();
702 QString paramname = effectparam.attribute("name");
703 QString paramvalue = effectparam.text();
706 // try to find this parameter in the effect xml
708 for (int k = 0; k < clipeffectparams.count(); k++) {
709 e = clipeffectparams.item(k).toElement();
710 if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
711 if (e.attribute("factor", "1") != "1") {
712 QString factor = e.attribute("factor", "1");
714 if (factor.startsWith('%')) {
715 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
716 } else fact = factor.toDouble();
717 e.setAttribute("value", paramvalue.toDouble() * fact);
718 } else e.setAttribute("value", paramvalue);
723 if (effecttag == "ladspa") {
724 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
726 if (!QFile::exists(ladspaEffectFile)) {
727 // If the ladspa effect file is missing, recreate it
728 initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
730 currenteffect.setAttribute("src", ladspaEffectFile);
732 item->addEffect(currenteffect, false);
733 item->effectsCounter();
738 //m_clipList.append(clip);
741 //m_trackDuration = position;
744 //documentTracks.insert(ix, track);
745 kDebug() << "************* ADD DOC TRACK " << ix << ", DURATION: " << position;
750 DocClipBase *TrackView::getMissingProducer(const QString id) const
752 QDomElement missingXml;
753 QDomDocument doc = m_doc->toXml();
754 QString docRoot = doc.documentElement().attribute("root");
755 if (!docRoot.endsWith('/')) docRoot.append('/');
756 QDomNodeList prods = doc.elementsByTagName("producer");
757 int maxprod = prods.count();
758 for (int i = 0; i < maxprod; i++) {
759 QDomNode m = prods.at(i);
760 QString prodId = m.toElement().attribute("id");
762 missingXml = m.toElement();
766 if (missingXml == QDomElement()) return NULL;
768 QDomNodeList params = missingXml.childNodes();
770 for (int j = 0; j < params.count(); j++) {
771 QDomElement e = params.item(j).toElement();
772 if (e.attribute("name") == "resource") {
773 resource = e.firstChild().nodeValue();
777 // prepend MLT XML document root if no path in clip resource and not a color clip
778 if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
779 DocClipBase *missingClip = NULL;
780 if (!resource.isEmpty())
781 missingClip = m_doc->clipManager()->getClipByResource(resource);
785 QGraphicsScene *TrackView::projectScene()
790 CustomTrackView *TrackView::projectView()
795 void TrackView::setEditMode(const QString & editMode)
797 m_editMode = editMode;
800 const QString & TrackView::editMode() const
805 void TrackView::slotChangeTrackLock(int ix, bool lock)
807 QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
808 widgets.at(ix)->setLock(lock);
811 void TrackView::slotVerticalZoomDown()
813 if (m_verticalZoom == 0) return;
815 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
816 if (m_verticalZoom == 0) m_trackview->setScale(m_scene->scale().x(), 0.5);
817 else m_trackview->setScale(m_scene->scale().x(), 1);
818 adjustTrackHeaders();
819 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() / 2);
820 m_trackview->checkTrackHeight(false);*/
823 void TrackView::slotVerticalZoomUp()
825 if (m_verticalZoom == 2) return;
827 m_doc->setZoom(m_doc->zoom().x(), m_verticalZoom);
828 /*KdenliveSettings::setTrackheight(KdenliveSettings::trackheight() * 2);
829 m_trackview->checkTrackHeight(false);*/
830 if (m_verticalZoom == 2) m_trackview->setScale(m_scene->scale().x(), 2);
831 else m_trackview->setScale(m_scene->scale().x(), 1);
832 adjustTrackHeaders();
835 void TrackView::updateProjectFps()
837 m_ruler->updateProjectFps(m_doc->timecode());
840 void TrackView::slotRenameTrack(int ix)
842 int tracknumber = m_doc->tracksCount() - ix;
843 TrackInfo info = m_doc->trackInfoAt(tracknumber - 1);
845 QString newName = QInputDialog::getText(this, i18n("New Track Name"), i18n("Enter new name"), QLineEdit::Normal, info.trackName, &ok);
847 info.trackName = newName;
848 m_doc->setTrackType(tracknumber - 1, info);
849 QTimer::singleShot(300, this, SLOT(slotRebuildTrackHeaders()));
854 #include "trackview.moc"