X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fclipmanager.cpp;h=b5932d6dddd3e0c1ea38e0020dc6d31ba9576f29;hb=86e06b615e11677bf2b1e83d1f46754946006e41;hp=b764ee725986a73d17c95baf02f7353ce6a6b514;hpb=3d9ff40b713934e307b6ac7808bd8d56d0bd66f7;p=kdenlive diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index b764ee72..b5932d6d 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -123,7 +123,7 @@ void ClipManager::clearCache() #endif } -void ClipManager::slotRequestThumbs(const QString id, QList frames) +void ClipManager::slotRequestThumbs(const QString &id, const QList & frames) { m_thumbsMutex.lock(); foreach (int frame, frames) { @@ -176,34 +176,34 @@ void ClipManager::slotGetThumbs() m_processingThumbId = i.key(); QList values = m_requestedThumbs.values(m_processingThumbId); m_requestedThumbs.remove(m_processingThumbId); - if (m_processingThumbId.startsWith("?")) { - // if id starts with ?, it means the request comes from a clip property widget - thumbType = 2; - m_processingThumbId.remove(0, 1); - } - if (m_processingThumbId.startsWith("#")) { - // if id starts with #, it means the request comes from project tree - thumbType = 1; - m_processingThumbId.remove(0, 1); - } + if (m_processingThumbId.startsWith("?")) { + // if id starts with ?, it means the request comes from a clip property widget + thumbType = 2; + m_processingThumbId.remove(0, 1); + } + if (m_processingThumbId.startsWith("#")) { + // if id starts with #, it means the request comes from project tree + thumbType = 1; + m_processingThumbId.remove(0, 1); + } m_thumbsMutex.unlock(); qSort(values); DocClipBase *clip = getClipById(m_processingThumbId); if (!clip) continue; max = m_requestedThumbs.size() + values.count(); - int pos; + int pos; while (!values.isEmpty() && clip->thumbProducer() && !m_abortThumb) { - pos = values.takeFirst(); - switch (thumbType) { - case 1: - clip->thumbProducer()->getGenericThumb(pos, SubProjectItem::itemDefaultHeight(), thumbType); - break; - case 2: - clip->thumbProducer()->getGenericThumb(pos, 180, thumbType); - break; - default: - clip->thumbProducer()->getThumb(pos); - } + pos = values.takeFirst(); + switch (thumbType) { + case 1: + clip->thumbProducer()->getGenericThumb(pos, SubProjectItem::itemDefaultHeight(), thumbType); + break; + case 2: + clip->thumbProducer()->getGenericThumb(pos, 180, thumbType); + break; + default: + clip->thumbProducer()->getThumb(pos); + } done++; if (max > 3) emit displayMessage(i18n("Loading thumbnails"), 100 * done / max); } @@ -227,7 +227,7 @@ void ClipManager::checkAudioThumbs() } m_thumbsMutex.lock(); - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { DocClipBase *clip = m_clipList.at(i); if (clip->hasAudioThumb() && !clip->audioThumbCreated()) m_audioThumbsQueue.append(m_clipList.at(i)->getId()); @@ -264,17 +264,17 @@ void ClipManager::slotGetAudioThumbs() if (hash.isEmpty()) continue; QString audioPath = projectFolder() + "/thumbs/" + hash + ".thumb"; double lengthInFrames = clip->duration().frames(m_doc->fps()); - int frequency = 0; - int channels = 0; - QString data = clip->getProperty("frequency"); - if (!data.isEmpty()) frequency = data.toInt(); - if (frequency <= 0) frequency = 48000; - data = clip->getProperty("channels"); - if (!data.isEmpty()) channels = data.toInt(); - if (channels <= 0) channels = 2; - int arrayWidth = 20; + int frequency = 0; + int channels = 0; + QString data = clip->getProperty("frequency"); + if (!data.isEmpty()) frequency = data.toInt(); + if (frequency <= 0) frequency = 48000; + data = clip->getProperty("channels"); + if (!data.isEmpty()) channels = data.toInt(); + if (channels <= 0) channels = 2; + int arrayWidth = 20; double frame = 0.0; - int maxVolume = 0; + int maxVolume = 0; audioByteArray storeIn; QFile f(audioPath); if (QFileInfo(audioPath).size() > 0 && f.open(QIODevice::ReadOnly)) { @@ -294,9 +294,9 @@ void ClipManager::slotGetAudioThumbs() h3 = 0; for (int c = 0; c < channels; c++) { QByteArray audioArray(arrayWidth, '\x00'); - for (int i = 0; i < arrayWidth; i++) { + for (int i = 0; i < arrayWidth; ++i) { audioArray[i] = channelarray.at(h2 + h3 + i); - if (audioArray.at(i) > maxVolume) maxVolume = audioArray.at(i); + if (audioArray.at(i) > maxVolume) maxVolume = audioArray.at(i); } h3 += arrayWidth; storeIn[z][c] = audioArray; @@ -304,11 +304,11 @@ void ClipManager::slotGetAudioThumbs() h2 += h1; } if (!m_abortAudioThumb) { - clip->setProperty("audio_max", QString::number(maxVolume - 64)); - clip->updateAudioThumbnail(storeIn); - } + clip->setProperty("audio_max", QString::number(maxVolume - 64)); + clip->updateAudioThumbnail(storeIn); + } continue; - } + } if (!f.open(QIODevice::WriteOnly)) { kDebug() << "++++++++ ERROR WRITING TO FILE: " << audioPath; @@ -335,12 +335,11 @@ void ClipManager::slotGetAudioThumbs() } int last_val = 0; - int val = 0; double framesPerSecond = mlt_producer_get_fps(producer.get_producer()); Mlt::Frame *mlt_frame; for (int z = (int) frame; z < (int)(frame + lengthInFrames) && producer.is_valid() && !m_abortAudioThumb; z++) { - val = (int)((z - frame) / (frame + lengthInFrames) * 100.0); + int val = (int)((z - frame) / (frame + lengthInFrames) * 100.0); if (last_val != val && val > 1) { setThumbsProgress(i18n("Creating audio thumbnail for %1", url.fileName()), val); last_val = val; @@ -353,18 +352,18 @@ void ClipManager::slotGetAudioThumbs() for (int c = 0; c < channels; c++) { QByteArray audioArray; audioArray.resize(arrayWidth); - for (int i = 0; i < audioArray.size(); i++) { - double pcmval = *(pcm + c + i * samples / audioArray.size()); - if (pcmval >= 0) { - pcmval = sqrt(pcmval) / 2.83 + 64; - audioArray[i] = pcmval; - if (pcmval > maxVolume) maxVolume = pcmval; - } - else { - pcmval = -sqrt(-pcmval) / 2.83 + 64; - audioArray[i] = pcmval; - if (-pcmval > maxVolume) maxVolume = -pcmval; - } + for (int i = 0; i < audioArray.size(); ++i) { + double pcmval = *(pcm + c + i * samples / audioArray.size()); + if (pcmval >= 0) { + pcmval = sqrt(pcmval) / 2.83 + 64; + audioArray[i] = pcmval; + if (pcmval > maxVolume) maxVolume = pcmval; + } + else { + pcmval = -sqrt(-pcmval) / 2.83 + 64; + audioArray[i] = pcmval; + if (-pcmval > maxVolume) maxVolume = -pcmval; + } } f.write(audioArray); storeIn[z][c] = audioArray; @@ -380,7 +379,7 @@ void ClipManager::slotGetAudioThumbs() f.remove(); } else { clip->updateAudioThumbnail(storeIn); - clip->setProperty("audio_max", QString::number(maxVolume - 64)); + clip->setProperty("audio_max", QString::number(maxVolume - 64)); } } m_processingAudioThumbId.clear(); @@ -420,7 +419,7 @@ void ClipManager::slotDeleteClips(QStringList ids) QUndoCommand *delClips = new QUndoCommand(); delClips->setText(i18np("Delete clip", "Delete clips", ids.size())); - for (int i = 0; i < ids.size(); i++) { + for (int i = 0; i < ids.size(); ++i) { DocClipBase *clip = getClipById(ids.at(i)); if (clip) { new AddClipCommand(m_doc, clip->toXML(), ids.at(i), false, delClips); @@ -431,9 +430,9 @@ void ClipManager::slotDeleteClips(QStringList ids) void ClipManager::deleteClip(const QString &clipId) { - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { if (m_clipList.at(i)->getId() == clipId) { - DocClipBase *clip = m_clipList.takeAt(i); + DocClipBase *clip = m_clipList.takeAt(i); if (clip->clipType() != COLOR && clip->clipType() != SLIDESHOW && !clip->fileURL().isEmpty()) { //if (m_clipList.at(i)->clipType() == IMAGE || m_clipList.at(i)->clipType() == AUDIO || (m_clipList.at(i)->clipType() == TEXT && !m_clipList.at(i)->fileURL().isEmpty())) { // listen for file change @@ -455,7 +454,7 @@ DocClipBase *ClipManager::getClipById(QString clipId) { //kDebug() << "++++ CLIP MAN, LOOKING FOR CLIP ID: " << clipId; clipId = clipId.section('_', 0, 0); - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { if (m_clipList.at(i)->getId() == clipId) { //kDebug() << "++++ CLIP MAN, FOUND FOR CLIP ID: " << clipId; return m_clipList.at(i); @@ -469,7 +468,7 @@ const QList ClipManager::getClipByResource(const QString &resour QList list; QString clipResource; QString proxyResource; - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { clipResource = m_clipList.at(i)->getProperty("resource"); proxyResource = m_clipList.at(i)->getProperty("proxy"); if (clipResource.isEmpty()) clipResource = m_clipList.at(i)->getProperty("colour"); @@ -483,14 +482,14 @@ const QList ClipManager::getClipByResource(const QString &resour void ClipManager::clearUnusedProducers() { - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { if (m_clipList.at(i)->numReferences() == 0) m_clipList.at(i)->deleteProducers(); } } void ClipManager::resetProducersList(const QList prods, bool displayRatioChanged, bool fpsChanged) { - for (int i = 0; i < m_clipList.count(); i++) { + for (int i = 0; i < m_clipList.count(); ++i) { if (m_clipList.at(i)->numReferences() > 0 || displayRatioChanged || fpsChanged) { m_clipList.at(i)->deleteProducers(); } @@ -498,7 +497,7 @@ void ClipManager::resetProducersList(const QList prods, bool d QString id; Mlt::Producer *prod; QStringList brokenClips; - for (int i = 0; i < prods.count(); i++) { + for (int i = 0; i < prods.count(); ++i) { prod = prods.at(i); id = prod->get("id"); if (id.contains('_')) id = id.section('_', 0, 0); @@ -527,7 +526,7 @@ void ClipManager::slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst) slotAddClipList(KUrl::List () << dst, data); } -void ClipManager::slotAddClipList(const KUrl::List urls, QMap data) +void ClipManager::slotAddClipList(const KUrl::List &urls, const QMap &data) { QUndoCommand *addClips = new QUndoCommand(); // Update list of removable volumes @@ -540,23 +539,23 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap continue; } if (isOnRemovableDevice(file)) { - int answer = KMessageBox::warningYesNoCancel(kapp->activeWindow(), i18n("Clip %1
is on a removable device, will not be available when device is unplugged", file.path()), i18n("File on a Removable Device"), KGuiItem(i18n("Copy file to project folder")), KGuiItem(i18n("Continue")), KStandardGuiItem::cancel(), QString("copyFilesToProjectFolder")); - if (answer == KMessageBox::Cancel) continue; - else if (answer == KMessageBox::Yes) { - // Copy files to project folder - QString sourcesFolder = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "clips/"; - KIO::NetAccess::mkdir(sourcesFolder, kapp->activeWindow()); - //KIO::filesize_t m_requestedSize; - KIO::CopyJob *copyjob = KIO::copy (file, KUrl(sourcesFolder)); - //TODO: for some reason, passing metadata does not work... - copyjob->addMetaData("group", data.value("group")); - copyjob->addMetaData("groupId", data.value("groupId")); - copyjob->addMetaData("comment", data.value("comment")); - copyjob->ui()->setWindow(kapp->activeWindow()); - connect(copyjob, SIGNAL(copyingDone(KIO::Job*,KUrl,KUrl,time_t,bool,bool)), this, SLOT(slotAddClip(KIO::Job*,KUrl,KUrl))); - continue; - } - } + int answer = KMessageBox::warningYesNoCancel(kapp->activeWindow(), i18n("Clip %1
is on a removable device, will not be available when device is unplugged", file.path()), i18n("File on a Removable Device"), KGuiItem(i18n("Copy file to project folder")), KGuiItem(i18n("Continue")), KStandardGuiItem::cancel(), QString("copyFilesToProjectFolder")); + if (answer == KMessageBox::Cancel) continue; + else if (answer == KMessageBox::Yes) { + // Copy files to project folder + QString sourcesFolder = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "clips/"; + KIO::NetAccess::mkdir(sourcesFolder, kapp->activeWindow()); + //KIO::filesize_t m_requestedSize; + KIO::CopyJob *copyjob = KIO::copy (file, KUrl(sourcesFolder)); + //TODO: for some reason, passing metadata does not work... + copyjob->addMetaData("group", data.value("group")); + copyjob->addMetaData("groupId", data.value("groupId")); + copyjob->addMetaData("comment", data.value("comment")); + copyjob->ui()->setWindow(kapp->activeWindow()); + connect(copyjob, SIGNAL(copyingDone(KIO::Job*,KUrl,KUrl,time_t,bool,bool)), this, SLOT(slotAddClip(KIO::Job*,KUrl,KUrl))); + continue; + } + } kDebug() << "Adding clip: " << file.path(); QDomDocument doc; QDomElement prod = doc.createElement("producer"); @@ -570,8 +569,8 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap prod.setAttribute("groupid", data.value("groupId")); } if (data.contains("video_index")) prod.setAttribute("video_index", data.value("video_index")); - if (data.contains("audio_index")) prod.setAttribute("audio_index", data.value("audio_index")); - + if (data.contains("audio_index")) prod.setAttribute("audio_index", data.value("audio_index")); + KMimeType::Ptr type = KMimeType::findByUrl(file); if (type->name().startsWith("image/")) { prod.setAttribute("type", (int) IMAGE); @@ -583,12 +582,12 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap KFileMetaInfo metaInfo(file.path(), QString("image/jpeg"), KFileMetaInfo::TechnicalInfo); const QHash metaInfoItems = metaInfo.items(); foreach(const KFileMetaInfoItem & metaInfoItem, metaInfoItems) { - QDomElement meta = doc.createElement("metaproperty"); - meta.setAttribute("name", "meta.attr." + metaInfoItem.name().section('#', 1)); - QDomText value = doc.createTextNode(metaInfoItem.value().toString()); - meta.setAttribute("tool", "KDE Metadata"); - meta.appendChild(value); - prod.appendChild(meta); + QDomElement meta = doc.createElement("metaproperty"); + meta.setAttribute("name", "meta.attr." + metaInfoItem.name().section('#', 1)); + QDomText value = doc.createTextNode(metaInfoItem.value().toString()); + meta.setAttribute("tool", "KDE Metadata"); + meta.appendChild(value); + prod.appendChild(meta); } } } else if (type->is("application/x-kdenlivetitle")) { @@ -600,7 +599,7 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap prod.setAttribute("type", (int) TEXT); // extract embeded images QDomNodeList items = txtdoc.elementsByTagName("content"); - for (int i = 0; i < items.count() ; i++) { + for (int i = 0; i < items.count() ; ++i) { QDomElement content = items.item(i).toElement(); if (content.hasAttribute("base64")) { QString titlesFolder = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/"; @@ -613,20 +612,20 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap } prod.setAttribute("transparency", 1); prod.setAttribute("in", 0); - if (!txtdoc.documentElement().hasAttribute("out")) { - prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); - txtdoc.documentElement().setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); - } - else { - int out = txtdoc.documentElement().attribute("out").toInt(); - if (out >= 0) - prod.setAttribute("out", out); - else { - prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); - txtdoc.documentElement().setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); - } - } - QString titleData = txtdoc.toString(); + if (!txtdoc.documentElement().hasAttribute("out")) { + prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); + txtdoc.documentElement().setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); + } + else { + int out = txtdoc.documentElement().attribute("out").toInt(); + if (out >= 0) + prod.setAttribute("out", out); + else { + prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); + txtdoc.documentElement().setAttribute("out", m_doc->getFramePos(KdenliveSettings::title_duration()) - 1); + } + } + QString titleData = txtdoc.toString(); prod.setAttribute("xmldata", titleData); } else txtfile.close(); @@ -641,7 +640,7 @@ void ClipManager::slotAddClipList(const KUrl::List urls, QMap } } -void ClipManager::slotAddClipFile(const KUrl &url, QMap data) +void ClipManager::slotAddClipFile(const KUrl &url, const QMap &data) { slotAddClipList(KUrl::List(url), data); } @@ -750,13 +749,13 @@ void ClipManager::slotAddTextTemplateClip(QString titleName, const KUrl &path, c QFile txtfile(path.path()); if (txtfile.open(QIODevice::ReadOnly) && titledoc.setContent(&txtfile)) { txtfile.close(); - if (titledoc.documentElement().hasAttribute("duration")) { - duration = titledoc.documentElement().attribute("duration").toInt(); - } + if (titledoc.documentElement().hasAttribute("duration")) { + duration = titledoc.documentElement().attribute("duration").toInt(); + } else { - // keep some time for backwards compatibility - 26/12/12 - duration = titledoc.documentElement().attribute("out").toInt(); - } + // keep some time for backwards compatibility - 26/12/12 + duration = titledoc.documentElement().attribute("out").toInt(); + } } else txtfile.close(); if (duration == 0) duration = m_doc->getFramePos(KdenliveSettings::title_duration()); @@ -813,7 +812,7 @@ QDomElement ClipManager::groupsXml() const QDomDocument doc; QDomElement groups = doc.createElement("groups"); doc.appendChild(groups); - for (int i = 0; i < m_groupsList.count(); i++) { + for (int i = 0; i < m_groupsList.count(); ++i) { QDomElement group = doc.createElement("group"); groups.appendChild(group); QList children = m_groupsList.at(i)->childItems(); @@ -843,7 +842,7 @@ void ClipManager::slotClipModified(const QString &path) { //kDebug() << "// CLIP: " << path << " WAS MODIFIED"; const QList list = getClipByResource(path); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { DocClipBase *clip = list.at(i); if (clip != NULL) { QString id = clip->getId(); @@ -875,7 +874,7 @@ void ClipManager::slotClipMissing(const QString &path) { // kDebug() << "// CLIP: " << path << " WAS MISSING"; const QList list = getClipByResource(path); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { DocClipBase *clip = list.at(i); if (clip != NULL) emit missingClip(clip->getId()); } @@ -885,7 +884,7 @@ void ClipManager::slotClipAvailable(const QString &path) { // kDebug() << "// CLIP: " << path << " WAS ADDED"; const QList list = getClipByResource(path); - for (int i = 0; i < list.count(); i++) { + for (int i = 0; i < list.count(); ++i) { DocClipBase *clip = list.at(i); if (clip != NULL) emit availableClip(clip->getId()); } @@ -929,7 +928,7 @@ void ClipManager::listRemovableVolumes() continue; Solid::StorageDrive *drive = driveDevice.as(); - if (!drive->isRemovable()) continue; + if (!drive->isRemovable()) continue; // check for StorageVolume Solid::Device volumeDevice; @@ -960,7 +959,7 @@ void ClipManager::listRemovableVolumes() bool ClipManager::isOnRemovableDevice(const KUrl &url) { - SolidVolumeInfo volume; + //SolidVolumeInfo volume; QString path = url.path(KUrl::RemoveTrailingSlash); int volumeMatch = 0; @@ -974,7 +973,7 @@ bool ClipManager::isOnRemovableDevice(const KUrl &url) if (length > volumeMatch) { volumeMatch = v.path.length(); - volume = v; + //volume = v; } } } @@ -985,11 +984,13 @@ bool ClipManager::isOnRemovableDevice(const KUrl &url) void ClipManager::projectTreeThumbReady(const QString &id, int frame, const QImage &img, int type) { switch (type) { - case 2: - emit gotClipPropertyThumbnail(id, img); - break; - default: - emit thumbReady(id, frame, img); + case 2: + emit gotClipPropertyThumbnail(id, img); + break; + default: + emit thumbReady(id, frame, img); } } + +#include "clipmanager.moc"