]> git.sesse.net Git - kdenlive/commitdiff
start of audio thumbs
authorMarco Gittler <marco@gitma.de>
Sat, 23 Feb 2008 22:33:14 +0000 (22:33 +0000)
committerMarco Gittler <marco@gitma.de>
Sat, 23 Feb 2008 22:33:14 +0000 (22:33 +0000)
svn path=/branches/KDE4/; revision=1914

src/clipitem.cpp
src/docclipbase.cpp
src/docclipbase.h
src/kthumb.cpp
src/kthumb.h

index 549d34ef4fa1f9f87ab57c244a8829d525fa3d7d..64be9b5ea042f903afd1f2d080b3ca3925d9ef09 100644 (file)
@@ -174,23 +174,28 @@ int ClipItem::endPos()
  {
     QRectF br = rect();
     painter->setRenderHints(QPainter::Antialiasing);
-    QPainterPath roundRectPath;
+    QPainterPath roundRectPathUpper,roundRectPathLower;
     double roundingY = 20;
     double roundingX = 20;
     double offset = 1;
     painter->setClipRect(option->exposedRect);
     if (roundingX > br.width() / 2) roundingX = br.width() / 2;
     //kDebug()<<"-----PAINTING, SCAL: "<<scale<<", height: "<<br.height();
-    roundRectPath.moveTo(br.x() + br .width() - offset, br.y() + roundingY);
-    roundRectPath.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
-    roundRectPath.lineTo(br.x() + roundingX, br.y());
-    roundRectPath.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
-    roundRectPath.lineTo(br.x() + offset, br.y() + br.height() - roundingY);
-    roundRectPath.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
-    roundRectPath.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
-    roundRectPath.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
-    roundRectPath.closeSubpath();
-    painter->setClipPath(roundRectPath, Qt::IntersectClip);
+        roundRectPathUpper.moveTo(br.x() + br .width() - offset, br.y() + br.height()/2 - offset);
+        roundRectPathUpper.arcTo(br.x() + br .width() - roundingX - offset, br.y(), roundingX, roundingY, 0.0, 90.0);
+        roundRectPathUpper.lineTo(br.x() + roundingX, br.y());
+        roundRectPathUpper.arcTo(br.x() + offset, br.y(), roundingX, roundingY, 90.0, 90.0);
+        roundRectPathUpper.lineTo(br.x() + offset, br.y() + br.height()/2 - offset);
+        roundRectPathUpper.closeSubpath();
+        
+        roundRectPathLower.moveTo(br.x() + offset, br.y() + br.height()/2 - offset);
+        roundRectPathLower.arcTo(br.x() + offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 180.0, 90.0);
+        roundRectPathLower.lineTo(br.x() + br .width() - roundingX, br.y() + br.height() - offset);
+        roundRectPathLower.arcTo(br.x() + br .width() - roundingX - offset, br.y() + br.height() - roundingY - offset, roundingX, roundingY, 270.0, 90.0);
+        roundRectPathLower.lineTo(br.x() + br .width() - offset, br.y()+ br.height()/2 - offset);
+        roundRectPathLower.closeSubpath();
+        
+        painter->setClipPath(roundRectPathUpper.united(roundRectPathLower), Qt::IntersectClip);
     //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
     painter->fillRect(br, brush());
     //painter->fillRect(QRectF(br.x() + br.width() - m_endPix.width(), br.y(), m_endPix.width(), br.height()), QBrush(QColor(Qt::black)));
@@ -211,7 +216,18 @@ int ClipItem::endPos()
       QLineF l2(br.x() + m_startPix.width(), br.y(), br.x() + m_startPix.width(), br.y() + br.height());
       painter->drawLine(l2);
     }
-
+        if (m_clipType == AV || m_clipType==AUDIO ){
+                QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower);
+                painter->fillPath(path,QBrush(QColor(200,200,200,127)));
+                //for test 
+                int channels=2;
+                kDebug() << "audio frames=" << baseClip()->audioFrameChache.size() ;
+                for (int channel=0;channel<channels;channel++){
+                       QRectF re=path.boundingRect();
+                       int y=re.y()+re.height()*channel/channels+ (re.height()/channels)/2;
+                       painter->drawLine(re.x() , y, re.x() + re.width(), y );
+                }
+        }
     // draw start / end fades
     double scale = br.width() / m_cropDuration;
     QBrush fades;
@@ -272,7 +288,7 @@ int ClipItem::endPos()
     pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
     if (isSelected()) painter->setPen(pen);
     painter->setClipRect(option->exposedRect);
-    painter->drawPath(roundRectPath);
+        painter->drawPath(roundRectPathUpper.united(roundRectPathLower));
     //painter->fillRect(QRect(br.x(), br.y(), roundingX, roundingY), QBrush(QColor(Qt::green)));
 
     /*QRectF recta(rect().x(), rect().y(), scale,rect().height());
index 69994887b62b47951c556ddefd233d60e1311b21..38562405cff0c50851fe6c22c5ac7a0f3e36baf0 100644 (file)
@@ -31,8 +31,17 @@ m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0),
   int out = xml.attribute("out").toInt();
   if (out != 0) setDuration(GenTime(out, 25));
   if (m_name.isEmpty()) m_name = url.fileName();
-  if (!url.isEmpty())
+       if (!url.isEmpty()){
     m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
+               connect (m_thumbProd, SIGNAL (audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> > )));
+               connect (this, SIGNAL (getAudioThumbs()), this , SLOT( slotGetAudioThumbs() ) );
+               
+       }
+       kDebug() << "type is video" << (m_clipType==AV) << " " << m_clipType;
+       
+       if (m_clipType == AV || m_clipType==AUDIO ||m_clipType==UNKNOWN){
+               emit getAudioThumbs();
+       }
 }
 
 DocClipBase::DocClipBase(const DocClipBase& clip)
@@ -386,4 +395,9 @@ QString DocClipBase::getTypeName(CLIPTYPE type)
     return result;
 }
 
+void DocClipBase::slotGetAudioThumbs(){
+       kDebug() << "getting audio data";
+       double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
+       m_thumbProd->getAudioThumbs(fileURL(), 1, 0, lengthInFrames, 20);
+}
 
index 1f2aa96f2274cada5fe2e83fcd663b726e279ca2..b39dc0040c1332f2d93af80522ba055e84571897 100644 (file)
@@ -217,9 +217,10 @@ class DocClipBase:public QObject {
     uint m_id;
     uint m_projectThumbFrame;
     void setAudioThumbCreated(bool isDone);
-
+       
   public slots:
        void updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data);
+       void slotGetAudioThumbs();
        QList < CommentedTime > commentedSnapMarkers() const;
        void setSnapMarkers(QList < CommentedTime > markers);
        GenTime findNextSnapMarker(const GenTime & currTime);
@@ -232,6 +233,8 @@ class DocClipBase:public QObject {
        QString markerComment(GenTime t);
        void setProjectThumbFrame( const uint &ix);
        uint getProjectThumbFrame() const;
+       signals:
+               void getAudioThumbs();
 };
 
 #endif
index f778a853c1a7cd73e577b96db4e819236ba251c5..27cb36395898da164841cf675f7f68b66416de68 100644 (file)
@@ -141,7 +141,7 @@ KThumb::KThumb(KUrl url, int width, int height, QObject * parent, const char *na
 KThumb::~KThumb()
 {
     if (m_profile) delete m_profile;
-    //if (thumbProducer.running ()) thumbProducer.exit();
+    if (thumbProducer.isRunning ()) thumbProducer.exit();
 }
 
 
@@ -316,6 +316,7 @@ void KThumb::removeAudioThumb()
 }
 
 void KThumb::getAudioThumbs(KUrl url, int channel, double frame, double frameLength, int arrayWidth){
+       
        if ((thumbProducer.isRunning () && thumbProducer.isWorking()) || channel == 0) {
            return;
        }
@@ -324,13 +325,16 @@ void KThumb::getAudioThumbs(KUrl url, int channel, double frame, double frameLen
        //FIXME: Hardcoded!!! 
        int m_frequency = 48000;
        int m_channels = channel;
+       /*TODO 
        if (m_url != url) {
                m_url = url;
                QCryptographicHash context(QCryptographicHash::Sha1);
                context.addData((KFileItem(m_url,"text/plain", S_IFREG).timeString() + m_url.fileName()).toAscii().data());
                
                m_thumbFile = KdenliveSettings::currenttmpfolder() + context.result().toHex() + ".thumb";
-       }
+               
+       }*/
+       return;
        QFile f(m_thumbFile);
        if (f.open( QIODevice::ReadOnly )) {
                QByteArray channelarray = f.readAll();
index 56ebd56016919f8966b64eca9a3b7c3b2fe31a8a..1e663aa3f371c214cd059096a9ec5f2e9c145168 100644 (file)
@@ -45,7 +45,7 @@ namespace Mlt {
 };
 
 
-  class MyThread : public QThread {
+class MyThread : public QThread {
 
     public:
         virtual void run();