]> git.sesse.net Git - kdenlive/blobdiff - src/clipmanager.cpp
Merge branch 'master' into bugfix/jogshuttle
[kdenlive] / src / clipmanager.cpp
index c65526969a52eda0b4cee4e613fe0e7c7e7975d5..486050093b77538a89c5feae324a9d234d66e73b 100644 (file)
@@ -26,6 +26,7 @@
 #include "abstractclipitem.h"
 #include "abstractgroupitem.h"
 #include "titledocument.h"
+#include "subprojectitem.h"
 #include "kthumb.h"
 
 #include <mlt++/Mlt.h>
@@ -167,19 +168,42 @@ void ClipManager::slotGetThumbs()
     QMap<QString, int>::const_iterator i;
     int max;
     int done = 0;
+    int thumbType = 0; // 0 = timeline thumb, 1 = project clip zone thumb, 2 = clip properties thumb
+    
     while (!m_requestedThumbs.isEmpty() && !m_abortThumb) {
         m_thumbsMutex.lock();
         i = m_requestedThumbs.constBegin();
         m_processingThumbId = i.key();
         QList<int> 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);
+       }
         m_thumbsMutex.unlock();
         qSort(values);
         DocClipBase *clip = getClipById(m_processingThumbId);
         if (!clip) continue;
         max = m_requestedThumbs.size() + values.count();
+       int pos;
         while (!values.isEmpty() && clip->thumbProducer() && !m_abortThumb) {
-            clip->thumbProducer()->getThumb(values.takeFirst());
+           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);
         }
@@ -228,7 +252,7 @@ void ClipManager::askForAudioThumb(const QString &id)
 void ClipManager::slotGetAudioThumbs()
 {
     Mlt::Profile prof((char*) KdenliveSettings::current_profile().toUtf8().constData());
-    mlt_audio_format audioFormat = mlt_audio_pcm;
+    mlt_audio_format audioFormat = mlt_audio_s16;
     while (!m_abortAudioThumb && !m_audioThumbsQueue.isEmpty()) {
         m_thumbsMutex.lock();
         m_processingAudioThumbId = m_audioThumbsQueue.takeFirst();
@@ -240,11 +264,15 @@ void ClipManager::slotGetAudioThumbs()
         if (hash.isEmpty()) continue;
         QString audioPath = projectFolder() + "/thumbs/" + hash + ".thumb";
         double lengthInFrames = clip->duration().frames(m_doc->fps());
-        //FIXME: should this be hardcoded??
-        int channels = 2;
-        int frequency = 48000;
-        int arrayWidth = 20;
+       int frequency = 48000;
+       int channels = 2;
+       QString data = clip->getProperty("frequency");
+       if (!data.isEmpty()) frequency = data.toInt();
+       data = clip->getProperty("channels");
+       if (!data.isEmpty()) channels = data.toInt();
+       int arrayWidth = 20;
         double frame = 0.0;
+       int maxVolume = 0;
         audioByteArray storeIn;
         QFile f(audioPath);
         if (QFileInfo(audioPath).size() > 0 && f.open(QIODevice::ReadOnly)) {
@@ -266,13 +294,17 @@ void ClipManager::slotGetAudioThumbs()
                     QByteArray audioArray(arrayWidth, '\x00');
                     for (int i = 0; i < arrayWidth; i++) {
                         audioArray[i] = channelarray.at(h2 + h3 + i);
+                       if (audioArray.at(i) > maxVolume) maxVolume = audioArray.at(i);
                     }
                     h3 += arrayWidth;
                     storeIn[z][c] = audioArray;
                 }
                 h2 += h1;
             }
-            if (!m_abortAudioThumb) clip->updateAudioThumbnail(storeIn);
+            if (!m_abortAudioThumb) {
+               clip->setProperty("audio_max", QString::number(maxVolume - 64));
+               clip->updateAudioThumbnail(storeIn);
+           }
             continue;
         } 
         
@@ -295,9 +327,9 @@ void ClipManager::slotGetAudioThumbs()
         producer.set("video_index", "-1");
 
         if (KdenliveSettings::normaliseaudiothumbs()) {
-            Mlt::Filter m_convert(prof, "volume");
+            /*Mlt::Filter m_convert(prof, "volume");
             m_convert.set("gain", "normalise");
-            producer.attach(m_convert);
+            producer.attach(m_convert);*/
         }
 
         int last_val = 0;
@@ -320,7 +352,17 @@ void ClipManager::slotGetAudioThumbs()
                     QByteArray audioArray;
                     audioArray.resize(arrayWidth);
                     for (int i = 0; i < audioArray.size(); i++) {
-                        audioArray[i] = ((*(pcm + c + i * samples / audioArray.size())) >> 9) + 127 / 2 ;
+                       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;
@@ -336,6 +378,7 @@ void ClipManager::slotGetAudioThumbs()
             f.remove();
         } else {
             clip->updateAudioThumbnail(storeIn);
+           clip->setProperty("audio_max", QString::number(maxVolume - 64));
         }
     }
     m_processingAudioThumbId.clear();
@@ -388,12 +431,12 @@ void ClipManager::deleteClip(const QString &clipId)
 {
     for (int i = 0; i < m_clipList.count(); i++) {
         if (m_clipList.at(i)->getId() == clipId) {
-            if (m_clipList.at(i)->clipType() != COLOR && m_clipList.at(i)->clipType() != SLIDESHOW  && !m_clipList.at(i)->fileURL().isEmpty()) {
+           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
-                m_fileWatcher.removeFile(m_clipList.at(i)->fileURL().path());
+                m_fileWatcher.removeFile(clip->fileURL().path());
             }
-            DocClipBase *clip = m_clipList.takeAt(i);
             delete clip;
             clip = NULL;
             break;
@@ -918,5 +961,14 @@ bool ClipManager::isOnRemovableDevice(const KUrl &url)
     return volumeMatch;
 }
 
-
+void ClipManager::projectTreeThumbReady(const QString &id, int frame, QImage img, int type)
+{
+    switch (type) {
+      case 2:
+         emit gotClipPropertyThumbnail(id, img);
+         break;
+      default:
+       emit thumbReady(id, frame, img);
+    }
+}