From 2d8ea890a2a175d7053f4e4e9957c1e3411de302 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 8 Mar 2009 11:50:25 +0000 Subject: [PATCH 1/1] Fix display of clip duration in project tree + some cleanup + indent fixes svn path=/trunk/kdenlive/; revision=3119 --- src/docclipbase.cpp | 12 +++++---- src/kdenlivedoc.cpp | 16 +++--------- src/projectitem.cpp | 31 ++++++++++------------ src/projectlist.cpp | 19 ++++++++------ src/renderer.cpp | 60 +++++++++++++++++++------------------------ src/renderwidget.cpp | 2 +- src/slideshowclip.cpp | 4 +-- src/timecode.h | 2 +- 8 files changed, 66 insertions(+), 80 deletions(-) diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index eacbd33c..d60435fc 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -38,13 +38,15 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin KUrl url = KUrl(xml.attribute("resource")); if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path()); - int out = xml.attribute("out").toInt(); - if (out != 0) { - setDuration(GenTime(out, KdenliveSettings::project_fps())); + + if (xml.hasAttribute("duration")) { + setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps())); } else { - out = xml.attribute("duration").toInt(); - if (out != 0) setDuration(GenTime(out, KdenliveSettings::project_fps())); + int out = xml.attribute("out").toInt(); + int in = xml.attribute("in").toInt(); + setDuration(GenTime(out - in, KdenliveSettings::project_fps())); } + if (!m_properties.contains("name")) m_properties.insert("name", url.fileName()); //if (!url.isEmpty() && QFile::exists(url.path())) diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 2f752556..f98a23c8 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -85,10 +85,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup } m_startPos = infoXml.attribute("position").toInt(); m_zoom = infoXml.attribute("zoom", "7").toInt(); - - - - m_zoneEnd = infoXml.attribute("zoneout", "100").toInt(); setProfilePath(profilePath); @@ -113,7 +109,6 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup westley.removeChild(tracksinfo); } - QDomElement orig; QDomNodeList producers = m_document.elementsByTagName("producer"); QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer"); const int max = producers.count(); @@ -142,7 +137,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup if (!e.isNull() && prodId != "black" && !prodId.startsWith("slowmotion") && !m_abortLoading) { e.setTagName("producer"); // Get MLT's original producer properties - + QDomElement orig; for (int j = 0; j < max; j++) { QDomElement o = producers.item(j).cloneNode().toElement(); QString origId = o.attribute("id").section('_', 0, 0); @@ -1262,10 +1257,6 @@ void KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) const QString producerId = clipId.section('_', 0, 0); DocClipBase *clip = m_clipManager->getClipById(producerId); if (clip == NULL) { - /*kDebug()<<"// CLIP "<addClip(clip); } + if (createClipItem) { emit addProjectClip(clip); qApp->processEvents(); @@ -1434,7 +1426,7 @@ void KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId m = m.nextSibling(); } if (!meta.isEmpty()) { - clip = m_clipManager->getClipById(clipId); + if (clip == NULL) clip = m_clipManager->getClipById(clipId); if (clip) clip->setMetadata(meta); } } diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 18211a18..3968c0d4 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -56,6 +56,8 @@ ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) setText(1, name); setText(2, m_clip->description()); if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs(); + GenTime duration = m_clip->duration(); + if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps())); //setFlags(Qt::NoItemFlags); //kDebug() << "Constructed with clipId: " << m_clipId; } @@ -72,6 +74,8 @@ ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) setText(1, name); setText(2, m_clip->description()); if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs(); + GenTime duration = m_clip->duration(); + if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps())); //setFlags(Qt::NoItemFlags); //kDebug() << "Constructed with clipId: " << m_clipId; } @@ -199,9 +203,7 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con if (m_clip == NULL) return; //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled); if (attributes.contains("duration")) { - //if (m_clipType == AUDIO || m_clipType == VIDEO || m_clipType == AV) - //m_clip->setProperty("duration", attributes["duration"]); - GenTime duration = GenTime(attributes["duration"].toInt(), KdenliveSettings::project_fps()); + GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps()); setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps())); m_clip->setDuration(duration); //kDebug() << "//// LOADED CLIP, DURATION SET TO: " << duration.frames(KdenliveSettings::project_fps()); @@ -213,18 +215,13 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con //extend attributes -reh if (m_clipType == UNKNOWN) { - if (attributes.contains("type")) { - if (attributes["type"] == "audio") - m_clipType = AUDIO; - else if (attributes["type"] == "video") - m_clipType = VIDEO; - else if (attributes["type"] == "av") - m_clipType = AV; - else if (attributes["type"] == "playlist") - m_clipType = PLAYLIST; - } else { - m_clipType = AV; - } + QString cliptype = attributes.value("type"); + if (cliptype == "audio") m_clipType = AUDIO; + else if (cliptype == "video") m_clipType = VIDEO; + else if (cliptype == "av") m_clipType = AV; + else if (cliptype == "playlist") m_clipType = PLAYLIST; + else m_clipType = AV; + m_clip->setClipType(m_clipType); slotSetToolTip(); } @@ -234,10 +231,10 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con if (m_clip->description().isEmpty()) { if (metadata.contains("description")) { - m_clip->setProperty("description", metadata["description"]); + m_clip->setProperty("description", metadata.value("description")); setText(2, m_clip->description()); } else if (metadata.contains("comment")) { - m_clip->setProperty("description", metadata["comment"]); + m_clip->setProperty("description", metadata.value("comment")); setText(2, m_clip->description()); } } diff --git a/src/projectlist.cpp b/src/projectlist.cpp index c821e177..533de9d6 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -356,8 +356,8 @@ void ProjectList::selectItemById(const QString &clipId) { void ProjectList::slotDeleteClip(const QString &clipId) { ProjectItem *item = getItemById(clipId); if (!item) { - kDebug()<<"/// Cannot find clip to delete"; - return; + kDebug() << "/// Cannot find clip to delete"; + return; } delete item; } @@ -517,9 +517,12 @@ void ProjectList::updateAllClips() { item->setIcon(0, QPixmap(cachedPixmap)); listView->blockSignals(false); } else requestClipThumbnail(item->clipId()); - listView->blockSignals(true); - item->changeDuration(item->referencedClip()->producer()->get_playtime()); - listView->blockSignals(false); + + if (item->data(1, DurationRole).toString().isEmpty()) { + listView->blockSignals(true); + item->changeDuration(item->referencedClip()->producer()->get_playtime()); + listView->blockSignals(false); + } } listView->blockSignals(true); item->setData(1, UsageRole, QString::number(item->numReferences())); @@ -595,7 +598,7 @@ void ProjectList::slotAddColorClip() { } m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId); - m_doc->setModified(true); + m_doc->setModified(true); } delete dia_ui; delete dia; @@ -622,8 +625,8 @@ void ProjectList::slotAddSlideshowClip() { groupId = item->clipId(); } - m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId); - m_doc->setModified(true); + m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId); + m_doc->setModified(true); } delete dia; } diff --git a/src/renderer.cpp b/src/renderer.cpp index b8dc9502..3f38236a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -463,15 +463,10 @@ void Render::slotSplitView(bool doit) { } void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) { - int height = 50; - int width = (int)(height * m_mltProfile->dar()); - QMap < QString, QString > filePropertyMap; - QMap < QString, QString > metadataPropertyMap; - KUrl url = KUrl(xml.attribute("resource", QString())); Mlt::Producer *producer = NULL; if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) { - emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer); + emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer); return; } if (xml.attribute("type").toInt() == COLOR) { @@ -489,35 +484,9 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp); delete[] tmp; } else { - QString urlpath = url.path(); - /*if (urlpath.contains(':')) { - if (!urlpath.startsWith("file:")) urlpath.prepend("file:"); - char *tmp = decodedString(urlpath); - producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp); - delete[] tmp; - } - else {*/ - char *tmp = decodedString(urlpath); + char *tmp = decodedString(url.path()); producer = new Mlt::Producer(*m_mltProfile, tmp); delete[] tmp; - - if (xml.hasAttribute("force_aspect_ratio")) { - double aspect = xml.attribute("force_aspect_ratio").toDouble(); - if (aspect > 0) producer->set("force_aspect_ratio", aspect); - } - if (xml.hasAttribute("threads")) { - int threads = xml.attribute("threads").toInt(); - if (threads != 1) producer->set("threads", threads); - } - if (xml.hasAttribute("video_index")) { - int vindex = xml.attribute("video_index").toInt(); - if (vindex != 0) producer->set("video_index", vindex); - } - if (xml.hasAttribute("audio_index")) { - int aindex = xml.attribute("audio_index").toInt(); - if (aindex != 0) producer->set("audio_index", aindex); - } - //} } if (producer == NULL || producer->is_blank() || !producer->is_valid()) { @@ -526,11 +495,34 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bo return; } + if (xml.hasAttribute("force_aspect_ratio")) { + double aspect = xml.attribute("force_aspect_ratio").toDouble(); + if (aspect > 0) producer->set("force_aspect_ratio", aspect); + } + if (xml.hasAttribute("threads")) { + int threads = xml.attribute("threads").toInt(); + if (threads != 1) producer->set("threads", threads); + } + if (xml.hasAttribute("video_index")) { + int vindex = xml.attribute("video_index").toInt(); + if (vindex != 0) producer->set("video_index", vindex); + } + if (xml.hasAttribute("audio_index")) { + int aindex = xml.attribute("audio_index").toInt(); + if (aindex != 0) producer->set("audio_index", aindex); + } + if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt()); char *tmp = decodedString(clipId); producer->set("id", tmp); delete[] tmp; + + int height = 50; + int width = (int)(height * m_mltProfile->dar()); + QMap < QString, QString > filePropertyMap; + QMap < QString, QString > metadataPropertyMap; + int frameNumber = xml.attribute("thumbnail", "0").toInt(); if (frameNumber != 0) producer->seek(frameNumber); @@ -2786,7 +2778,7 @@ void Render::fillSlowMotionProducers() { QString id = nprod->get("id"); if (id.startsWith("slowmotion:")) { // this is a slowmotion producer, add it to the list - QString url = QString::fromUtf8(nprod->get("resource")); + QString url = QString::fromUtf8(nprod->get("resource")); if (!m_slowmotionProducers.contains(url)) { m_slowmotionProducers.insert(url, nprod); } diff --git a/src/renderwidget.cpp b/src/renderwidget.cpp index ae29f449..b16c0e34 100644 --- a/src/renderwidget.cpp +++ b/src/renderwidget.cpp @@ -859,7 +859,7 @@ void RenderWidget::parseProfiles(QString meta, QString group, QString profile) { // can also override profiles installed by KNewStuff fileList.removeAll("customprofiles.xml"); foreach(const QString &filename, fileList) - parseFile(exportFolder + '/' + filename, true); + parseFile(exportFolder + '/' + filename, true); if (QFile::exists(exportFolder + "/customprofiles.xml")) parseFile(exportFolder + "/customprofiles.xml", true); if (!meta.isEmpty()) { diff --git a/src/slideshowclip.cpp b/src/slideshowclip.cpp index bd5f12df..9ee89b46 100644 --- a/src/slideshowclip.cpp +++ b/src/slideshowclip.cpp @@ -104,8 +104,8 @@ void SlideshowClip::parseFolder() { QStringList filters; QString filter = m_view.image_type->itemData(m_view.image_type->currentIndex()).toString(); filters << "*." + filter; - // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers - // << "*.jpeg"; + // TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers + // << "*.jpeg"; dir.setNameFilters(filters); const QStringList result = dir.entryList(QDir::Files); diff --git a/src/timecode.h b/src/timecode.h index df31701e..7e384bc4 100644 --- a/src/timecode.h +++ b/src/timecode.h @@ -31,7 +31,7 @@ public: enum Formats { HH_MM_SS_FF, HH_MM_SS_HH, Frames, Seconds }; explicit Timecode(Formats format = HH_MM_SS_FF, int framesPerSecond = - 25, bool dropFrame = false); + 25, bool dropFrame = false); /** Set the current timecode format; this is the output format for this timecode. */ void setFormat(int framesPerSecond, bool dropFrame = false, Formats format = HH_MM_SS_FF) { -- 2.39.2