X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftrackview.cpp;h=1947f5dfa86c329392f525a01d1747647a58174e;hb=d1e6242c20436bfa1ac8d1c3a5dc9f55bd8f10ca;hp=b5b2b9efd173d318e5b0a7bb4b14cbc7941663ec;hpb=62b517a3d5fc09dd9288261f9155dfd61a19d72c;p=kdenlive diff --git a/src/trackview.cpp b/src/trackview.cpp index b5b2b9ef..1947f5df 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -189,6 +189,7 @@ void TrackView::parseDocument(QDomDocument doc) { //int cursorPos = 0; m_documentErrors.clear(); + m_replacementProducerIds.clear(); //kDebug() << "//// DOCUMENT: " << doc.toString(); /*QDomNode props = doc.elementsByTagName("properties").item(0); @@ -215,21 +216,6 @@ void TrackView::parseDocument(QDomDocument doc) QDomNode n = producers.item(i); e = n.toElement(); - /* - // Check for invalid markup - QDomNodeList params = e.elementsByTagName("property"); - for (int j = 0; j < params.count(); j++) { - QDomElement p = params.item(j).toElement(); - if (p.attribute("name") == "markup") { - QString val = p.text().toUtf8().data(); - kDebug()<<"//FOUND MARKUP, VAL: "<switchTrackAudio(i - 1, true); } - trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1)); + trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1), producers); pos--; //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration; if (trackduration > duration) duration = trackduration; @@ -346,15 +332,13 @@ void TrackView::parseDocument(QDomDocument doc) // When adding composite transition, check if it is a wipe transition if (mlt_geometry.count(';') == 1) { mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive); - mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive); - QString start = mlt_geometry.section(';', 0, 0); - start = start.section(':', 0, 1); - start.replace(QChar(':'), QChar(','), Qt::CaseInsensitive); - QString end = mlt_geometry.section('=', 1, 1); - end = end.section(':', 0, 1); - end.replace(QChar(':'), QChar(','), Qt::CaseInsensitive); - start.append(',' + end); - QStringList numbers = start.split(',', QString::SkipEmptyParts); + mlt_geometry.replace(QChar('x'), QChar(':'), Qt::CaseInsensitive); + mlt_geometry.replace(QChar(','), QChar(':'), Qt::CaseInsensitive); + mlt_geometry.replace(QChar('/'), QChar(':'), Qt::CaseInsensitive); + + QString start = mlt_geometry.section('=', 0, 0).section(':', 0, -2) + ':'; + start.append(mlt_geometry.section('=', 1, 1).section(':', 0, -2)); + QStringList numbers = start.split(':', QString::SkipEmptyParts); bool isWipeTransition = true; int checkNumber; for (int i = 0; i < numbers.size(); ++i) { @@ -384,7 +368,7 @@ void TrackView::parseDocument(QDomDocument doc) QString factor = e.attribute("factor", "1"); if (factor != "1") { double fact; - if (factor.startsWith('%')) { + if (factor.contains('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); } else fact = factor.toDouble(); double val = paramValue.toDouble() * fact; @@ -591,10 +575,11 @@ void TrackView::adjustTrackHeaders() } } -int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) +int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNodeList producers) { // parse track int position = 0; + QMap producerReplacementIds; QDomNodeList children = xml.childNodes(); for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) { QDomNode n = children.item(nodeindex); @@ -612,12 +597,17 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) continue; } QString idString = elem.attribute("producer"); + if (producerReplacementIds.contains(idString)) { + // replace id + elem.setAttribute("producer", producerReplacementIds.value(idString)); + idString = elem.attribute("producer"); + } QString id = idString; double speed = 1.0; int strobe = 1; if (idString.startsWith("slowmotion")) { id = idString.section(':', 1, 1); - speed = idString.section(':', 2, 2).toDouble(); + speed = m_locale.toDouble(idString.section(':', 2, 2)); strobe = idString.section(':', 3, 3).toInt(); if (strobe == 0) strobe = 1; } @@ -627,30 +617,96 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) // The clip in playlist was not listed in the kdenlive producers, // something went wrong, repair required. kWarning() << "CANNOT INSERT CLIP " << id; - - clip = getMissingProducer(id); - if (!clip) { + QString docRoot = m_doc->toXml().documentElement().attribute("root"); + if (!docRoot.endsWith('/')) docRoot.append('/'); + clip = getMissingProducer(idString); + if (clip) { + // We found the original producer in Kdenlive's producers + // Found correct producer + m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n'); + QString prodId = clip->getId(); + if (clip->clipType() == PLAYLIST || clip->clipType() == AV || clip->clipType() == AUDIO) { + // We need producer for the track + prodId.append("_" + QString::number(ix)); + } + elem.setAttribute("producer", prodId); + producerReplacementIds.insert(idString, prodId); + // now adjust the mlt producer + bool found = false; + for (int i = 0; i < producers.count(); i++) { + QDomElement prod = producers.at(i).toElement(); + if (prod.attribute("id") == prodId) { + // ok, producer already exists + found = true; + break; + } + } + if (!found) { + for (int i = 0; i < producers.count(); i++) { + QDomElement prod = producers.at(i).toElement(); + if (prod.attribute("id") == idString) { + prod.setAttribute("id", prodId); + m_replacementProducerIds.insert(idString, prodId); + found = true; + break; + } + } + } + if (!found) { + // We didn't find the producer for this track, find producer for another track and duplicate + for (int i = 0; i < producers.count(); i++) { + QDomElement prod = producers.at(i).toElement(); + QString mltProdId = prod.attribute("id"); + if (mltProdId == prodId || mltProdId.startsWith(prodId + "_")) { + // Found parent producer, clone it + QDomElement clone = prod.cloneNode().toElement(); + clone.setAttribute("id", prodId); + m_doc->toXml().documentElement().insertBefore(clone, xml); + break; + } + } + } + } + else { // We cannot find the producer, something is really wrong, add // placeholder color clip QDomDocument doc; QDomElement producerXml = doc.createElement("producer"); doc.appendChild(producerXml); - producerXml.setAttribute("colour", "0xff0000ff"); - producerXml.setAttribute("mlt_service", "colour"); - producerXml.setAttribute("length", "15000"); - producerXml.setAttribute("name", "INVALID"); - producerXml.setAttribute("type", COLOR); - producerXml.setAttribute("id", id); - clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id); - xml.insertBefore(producerXml, QDomNode()); - nodeindex++; - m_doc->clipManager()->addClip(clip); - - m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n'); - } else { - // Found correct producer - m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n'); - elem.setAttribute("producer", clip->getId()); + bool foundMltProd = false; + for (int i = 0; i < producers.count(); i++) { + QDomElement prod = producers.at(i).toElement(); + if (prod.attribute("id") == id) { + QString service = EffectsList::property(prod, "mlt_service"); + QString type = EffectsList::property(prod, "mlt_type"); + QString resource = EffectsList::property(prod, "resource"); + if (!resource.startsWith('/') && service != "colour") { + resource.prepend(docRoot); + kDebug()<<"******************\nADJUSTED 1\n*************************"; + } + QString length = EffectsList::property(prod, "length"); + producerXml.setAttribute("mlt_service", service); + producerXml.setAttribute("mlt_type", type); + producerXml.setAttribute("resource", resource); + producerXml.setAttribute("duration", length); + if (service == "colour") producerXml.setAttribute("type", COLOR); + else if (service == "qimage" || service == "pixbuf") producerXml.setAttribute("type", IMAGE); + else if (service == "kdenlivetitle") producerXml.setAttribute("type", TEXT); + else producerXml.setAttribute("type", AV); + clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id); + m_doc->clipManager()->addClip(clip); + m_documentErrors.append(i18n("Broken clip producer %1, recreated base clip: %2", id, resource) + '\n'); + foundMltProd = true; + break; + } + } + if (!foundMltProd) { + // Cannot recover, replace with blank + int duration = elem.attribute("out").toInt() - elem.attribute("in").toInt(); + elem.setAttribute("length", duration); + elem.setTagName("blank"); + m_documentErrors.append(i18n("Broken clip producer %1, removed from project", id) + '\n'); + } } m_doc->setModified(true); } @@ -701,7 +757,6 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo QString effecttag; QString effectid; QString effectindex = QString::number(effectNb); - QString ladspaEffectFile; // Get effect tag & index for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) { // parse effect parameters @@ -716,15 +771,6 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo } else if (effectparam.attribute("name") == "kdenlive_ix") { // Fix effects index effectparam.firstChild().setNodeValue(effectindex); - } else if (effectparam.attribute("name") == "src") { - ladspaEffectFile = effectparam.text(); - if (!QFile::exists(ladspaEffectFile)) { - // If the ladspa effect file is missing, recreate it - kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile; - ladspaEffectFile = m_doc->getLadspaFile(); - effectparam.firstChild().setNodeValue(ladspaEffectFile); - kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile; - } } } //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex; @@ -769,7 +815,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo double endvalue = 0; double fact; if (factor.isEmpty()) fact = 1; - else if (factor.startsWith('%')) { + else if (factor.contains('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); } else fact = factor.toDouble(); for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) { @@ -783,8 +829,8 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo // add first keyframe if (effectout <= effectin) { // there is only one keyframe - keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';'); - } else keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';'); + keyframes.append(QString::number(effectin) + ':' + m_locale.toString(startvalue) + ';'); + } else keyframes.append(QString::number(effectin) + ':' + m_locale.toString(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';'); QDomNode lastParsedEffect; ix++; QDomNode n2 = effects.at(ix); @@ -809,7 +855,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo } } if (continueParsing) { - keyframes.append(QString::number(effectout) + ':' + QString::number(endvalue) + ';'); + keyframes.append(QString::number(effectout) + ':' + m_locale.toString(endvalue) + ';'); ix++; } } @@ -844,41 +890,35 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo for (int k = 0; k < clipeffectparams.count(); k++) { e = clipeffectparams.item(k).toElement(); if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) { + QString type = e.attribute("type"); QString factor = e.attribute("factor", "1"); double fact; - if (factor.startsWith('%')) { + if (factor.contains('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); } else { fact = factor.toDouble(); } - if (e.attribute("type") == "simplekeyframe") { + if (type == "simplekeyframe") { QStringList kfrs = paramvalue.split(";"); for (int l = 0; l < kfrs.count(); l++) { QString fr = kfrs.at(l).section('=', 0, 0); - double val = kfrs.at(l).section('=', 1, 1).toDouble(); - kfrs[l] = fr + ":" + QString::number((int)(val * fact)); + double val = m_locale.toDouble(kfrs.at(l).section('=', 1, 1)); + //kfrs[l] = fr + ":" + m_locale.toString((int)(val * fact)); + kfrs[l] = fr + ":" + QString::number((int) (val * fact)); } e.setAttribute("keyframes", kfrs.join(";")); - } else { + } else if (type == "double" || type == "constant") { bool ok; - e.setAttribute("value", paramvalue.toDouble(&ok) * fact); + e.setAttribute("value", m_locale.toDouble(paramvalue, &ok) * fact); if (!ok) e.setAttribute("value", paramvalue); + } else { + e.setAttribute("value", paramvalue); } break; } } } - // Old LADSPA filter, deprecated - /*if (effecttag == "ladspa") { - //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property"); - - if (!QFile::exists(ladspaEffectFile)) { - // If the ladspa effect file is missing, recreate it - initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect)); - } - currenteffect.setAttribute("src", ladspaEffectFile); - }*/ if (disableeffect) currenteffect.setAttribute("disable", "1"); if (clip) @@ -912,20 +952,36 @@ DocClipBase *TrackView::getMissingProducer(const QString id) const break; } } - if (missingXml == QDomElement()) return NULL; - - QDomNodeList params = missingXml.childNodes(); - QString resource; - for (int j = 0; j < params.count(); j++) { - QDomElement e = params.item(j).toElement(); - if (e.attribute("name") == "resource") { - resource = e.firstChild().nodeValue(); - break; + if (missingXml == QDomElement()) { + // Check if producer id was replaced in another track + if (m_replacementProducerIds.contains(id)) { + QString newId = m_replacementProducerIds.value(id); + slowmotionClip = false; + for (int i = 0; i < maxprod; i++) { + QDomNode m = prods.at(i); + QString prodId = m.toElement().attribute("id"); + if (prodId.startsWith("slowmotion")) { + slowmotionClip = true; + prodId = prodId.section(':', 1, 1); + } + prodId = prodId.section('_', 0, 0); + if (prodId == id) { + missingXml = m.toElement(); + break; + } + } } } + if (missingXml == QDomElement()) return NULL; + QString resource = EffectsList::property(missingXml, "resource"); + QString service = EffectsList::property(missingXml, "mlt_service"); + if (slowmotionClip) resource = resource.section('?', 0, 0); // prepend MLT XML document root if no path in clip resource and not a color clip - if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot); + if (!resource.startsWith('/') && service != "colour") { + resource.prepend(docRoot); + kDebug()<<"******************\nADJUSTED 2\n*************************"; + } DocClipBase *missingClip = NULL; if (!resource.isEmpty()) { QList list = m_doc->clipManager()->getClipByResource(resource);