]> git.sesse.net Git - kdenlive/commitdiff
audito thumbs are cached
authorMarco Gittler <marco@gitma.de>
Sun, 24 Feb 2008 23:49:32 +0000 (23:49 +0000)
committerMarco Gittler <marco@gitma.de>
Sun, 24 Feb 2008 23:49:32 +0000 (23:49 +0000)
svn path=/branches/KDE4/; revision=1929

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

index 84ddcd48c7ab7aace0afe7a79d145052917991c3..e33a293026b17025a4badb8a0dbe0673d7e3f638 100644 (file)
@@ -34,7 +34,7 @@
 #include "kdenlivesettings.h"
 
 ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & rect, int duration)
-    : QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0), m_effectsCounter(0)
+: QGraphicsRectItem(rect), m_clip(clip), m_resizeMode(NONE), m_grabPoint(0), m_maxTrack(0), m_track(track), m_startPos(startpos), m_hasThumbs(false), startThumbTimer(NULL), endThumbTimer(NULL), m_startFade(0), m_endFade(0), m_effectsCounter(0),audioThumbWasDrawn(false)
 {
   //setToolTip(name);
   kDebug()<<"*******  CREATING NEW TML CLIP, DUR: "<<duration;
@@ -247,33 +247,46 @@ int ClipItem::endPos()
                audiopen.setWidth(0);
                painter->setPen(audiopen);
                QRectF re=path.boundingRect();
-
-               QMap<int,QPainterPath > channelPaths;
-               QMap<int,QPainterPath > negativeChannelPaths;
-               for (int i=0;i<channels;i++){
-                       channelPaths[i].moveTo(re.x(),re.y()+re.height()*i/channels+ (re.height()/channels)/2);
-                       negativeChannelPaths[i].moveTo(re.x(),re.y()+re.height()*i/channels+ (re.height()/channels)/2);
+                if (audioThumbCachePic.isNull() || framePixelWidth!=pixelForOneFrame){
+                       audioThumbCachePic=QPixmap(re.width(),re.height());
+                       audioThumbCachePic.fill(QColor(200,200,200,127));
                }
-                
-               for (int samples=re.x();samples<re.x()+re.width();samples++){
-                       double frame=(double)(samples-re.x())/pixelForOneFrame;
-                       int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
-                       if (frame<0 || sample< 0 || sample>19 )
-                               continue;
-                       QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
+                if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){
+                       QMap<int,QPainterPath > positiveChannelPaths;
+                       QMap<int,QPainterPath > negativeChannelPaths;
+                       QPainter pixpainter(&audioThumbCachePic);
+                       pixpainter.setRenderHint(QPainter::Antialiasing,true);
+                       for (int i=0;i<channels;i++){
+
+                               positiveChannelPaths[i].moveTo(0,0+audioThumbCachePic.height()*i/channels+ (audioThumbCachePic.height()/channels)/2);
+                               negativeChannelPaths[i].moveTo(0,0+audioThumbCachePic.height()*i/channels+ (audioThumbCachePic.height()/channels)/2);
+                       }
                        
-                       for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
+                       for (int samples=0;samples<audioThumbCachePic.width();samples++){
+                               double frame=(double)(samples-0)/pixelForOneFrame;
+                               int sample=(frame-(int)(frame))*20 ;// AUDIO_FRAME_SIZE
+                               if (frame<0 || sample< 0 || sample>19 )
+                                       continue;
+                               QMap<int,QByteArray> frame_channel_data=baseClip()->audioFrameChache[(int)frame];
                                
-                               int y=re.y()+re.height()*channel/channels+ (re.height()/channels)/2;
-                               channelPaths[channel].lineTo(samples,y+( (int)frame_channel_data[channel][sample] -127/2 )  * (re.height()/channels) / 64 );    
-                               negativeChannelPaths[channel].lineTo(samples,y-( (int)frame_channel_data[channel][sample] -127/2 )  * (re.height()/channels) / 64 );
+                               for (int channel=0;channel<channels && frame_channel_data[channel].size()> 0;channel++){
+                                       
+                                       int y=audioThumbCachePic.height()*channel/channels+ (/*re.height()*/audioThumbCachePic.height()/channels)/2;
+                                       
+                                       positiveChannelPaths[channel].lineTo(samples,y+( (int)frame_channel_data[channel][sample] -127/2 )  * (audioThumbCachePic.height()/channels) / 64 );    
+                                       negativeChannelPaths[channel].lineTo(samples,y-( (int)frame_channel_data[channel][sample] -127/2 )  * (audioThumbCachePic.height()/channels) / 64 );
+                               }
                        }
-               }
-               for (int i=0;i<channels;i++){
-                       //painter->drawPath(channelPaths[i].united(negativeChannelPaths[i]));//or singleif looks better
-                       painter->drawPath(channelPaths[i]);
-               }
-        }
+                       for (int i=0;i<channels;i++){
+                               pixpainter.fillPath(positiveChannelPaths[i].united(negativeChannelPaths[i]),QBrush(Qt::SolidPattern));//or singleif looks better
+                               //pixpainter.drawPath(positiveChannelPaths[i]);
+                       }
+                        audioThumbWasDrawn=true;
+                        framePixelWidth=pixelForOneFrame;
+                }
+                painter->drawPixmap(re.x(),re.y(),audioThumbCachePic);
+       }
+        
         
         
     // draw start / end fades
index 46252e108261cf7903a66a7d6ffdef13de79a2f4..ba04cadc163a4e2324cd5c375088d64bc85e2f51 100644 (file)
@@ -111,7 +111,9 @@ class ClipItem : public QObject, public QGraphicsRectItem
     int m_effectsCounter;
     
     EffectsList m_effectList;
-
+    QPixmap audioThumbCachePic;
+    bool audioThumbWasDrawn;
+    double framePixelWidth;
   private slots:
     void slotThumbReady(int frame, QPixmap pix);
     void slotFetchThumbs();
index 5e40db6ef58f0e8c6f2782c95b3081f7363a8117..2c0938d2556f8ffcc3096474a129ca81ab454c41 100644 (file)
@@ -76,11 +76,11 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
                Mlt::Producer m_producer(prof, m_url.path().toAscii().data());
                
 
-               /*TODO if (KdenliveSettings::normaliseaudiothumbs()) {
-                   Mlt::Filter m_convert("volume");
+               /*TODO if (KdenliveSettings::normaliseaudiothumbs()) {*/
+                   Mlt::Filter m_convert(prof,"volume");
                    m_convert.set("gain", "normalise");
                    m_producer.attach(m_convert);
-               }*/
+               //}
 
                /*TODO if (qApp->mainWidget()) 
                    QApplication::postEvent(qApp->mainWidget(), new ProgressEvent(-1, 10005));
@@ -142,6 +142,7 @@ KThumb::KThumb(KUrl url, int width, int height, QObject * parent, const char *na
   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";
+  kDebug() << "thumbfile=" << m_thumbFile;
 }
 
 KThumb::~KThumb()