From 9d621354296fcf1d4fc45f396495371ea0742170 Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Sat, 23 Feb 2008 22:33:14 +0000 Subject: [PATCH] start of audio thumbs svn path=/branches/KDE4/; revision=1914 --- src/clipitem.cpp | 42 +++++++++++++++++++++++++++++------------- src/docclipbase.cpp | 16 +++++++++++++++- src/docclipbase.h | 5 ++++- src/kthumb.cpp | 8 ++++++-- src/kthumb.h | 2 +- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 549d34ef..64be9b5e 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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: "<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;channeldrawLine(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()); diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 69994887..38562405 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -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 >)), this , SLOT(updateAudioThumbnail(QMap > ))); + 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); +} diff --git a/src/docclipbase.h b/src/docclipbase.h index 1f2aa96f..b39dc004 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -217,9 +217,10 @@ class DocClipBase:public QObject { uint m_id; uint m_projectThumbFrame; void setAudioThumbCreated(bool isDone); - + public slots: void updateAudioThumbnail(QMap > 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 diff --git a/src/kthumb.cpp b/src/kthumb.cpp index f778a853..27cb3639 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -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(); diff --git a/src/kthumb.h b/src/kthumb.h index 56ebd560..1e663aa3 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -45,7 +45,7 @@ namespace Mlt { }; - class MyThread : public QThread { +class MyThread : public QThread { public: virtual void run(); -- 2.39.5