]> git.sesse.net Git - kdenlive/commitdiff
Fix audio thumbs progress info when window was not focused
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 2 Mar 2008 16:32:25 +0000 (16:32 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 2 Mar 2008 16:32:25 +0000 (16:32 +0000)
svn path=/branches/KDE4/; revision=1974

13 files changed:
src/clipitem.cpp
src/clipmanager.cpp
src/clipmanager.h
src/docclipbase.cpp
src/docclipbase.h
src/events.h
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/kthumb.cpp
src/kthumb.h
src/mainwindow.cpp
src/mainwindow.h
src/projectitem.cpp

index 4413c3fc546cca054a8c02957aee924d48316bc5..e40b1eaada6d210cf0b700decfdf7b0169c5c05f 100644 (file)
@@ -33,6 +33,7 @@
 #include <mlt++/Mlt.h>
 
 #include "clipitem.h"
+#include "customtrackview.h"
 #include "renderer.h"
 #include "events.h"
 #include "kdenlivesettings.h"
@@ -87,6 +88,9 @@ ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & re
   else if (m_clipType == IMAGE) {
     m_startPix = KThumb::getImage(KUrl(m_xml.attribute("resource")), 50 * KdenliveSettings::project_display_ratio(), 50);
   }
+  else if (m_clipType == AUDIO) {
+    connect(clip, SIGNAL (gotAudioData()), this, SLOT (slotGotAudioData()));
+  }
 }
 
 
@@ -705,14 +709,13 @@ void ClipItem::dropEvent ( QGraphicsSceneDragDropEvent * event )
     QDomDocument doc;
     doc.setContent(effects, true);
     QDomElement e = doc.documentElement();
-    if (QApplication::activeWindow()) 
-       QApplication::postEvent(QApplication::activeWindow(), new EffectEvent(GenTime(m_startPos, 25), m_track, e, (QEvent::Type)10010));
+    CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
+    if (view) view->slotAddEffect(e, GenTime(m_startPos, 25), m_track);
 }
 
 //virtual
 void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
 {
-  kDebug()<<"DRAG EVNET, FORMAT: "<<event->mimeData()->formats();
   event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
 }
 
index cf0812f4f2f21c85a19a66c81a02e2de3fc55292..67f933cc3ad51a72521911e78c57b2e9024e3c92 100644 (file)
@@ -22,7 +22,7 @@
 #include "addclipcommand.h"
 #include "kdenlivesettings.h"
 #include "clipmanager.h"
-
+#include "docclipbase.h"
 
 ClipManager::ClipManager(KdenliveDoc *doc):m_doc(doc)
 {
@@ -33,6 +33,12 @@ ClipManager::~ClipManager()
 {
 }
 
+void ClipManager::setThumbsProgress(KUrl url, int progress)
+{
+  m_doc->setThumbsProgress(url, progress);
+}
+
+
 void ClipManager::addClip(DocClipBase *clip)
 {
   m_clipList.append(clip);
index 30dfd24c9360f90852056c46a3b3b42f7b4e2706..4580cdaa14e8216ee0aa812af4c4aa6b0a537231 100644 (file)
 
 #include "gentime.h"
 #include "definitions.h"
-#include "docclipbase.h"
 
-class KdenliveDoc;
 
+class KdenliveDoc;
+class DocClipBase;
 
 class ClipManager:public QObject {
   Q_OBJECT public:
@@ -52,6 +52,7 @@ class ClipManager:public QObject {
     void slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group);
     DocClipBase *getClipById(int clipId);
     void slotDeleteClip(uint clipId);
+    void setThumbsProgress(KUrl url, int progress);
 
   private:                     // Private attributes
     /** the list of clips in the document */
index 32beb352a694b841989b1dcaf1443caded11df79..4f5f5d4162b273b0db7e187b19c21f01ea5780c9 100644 (file)
@@ -20,7 +20,7 @@
 #include "kdenlivesettings.h"
 #include "docclipbase.h"
 
-DocClipBase::DocClipBase(QDomElement xml, uint id):
+DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id):
 m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL)
 {
   int type = xml.attribute("type").toInt();
@@ -32,7 +32,7 @@ m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0),
   if (out != 0) setDuration(GenTime(out, 25));
   if (m_name.isEmpty()) m_name = url.fileName();
   if (!url.isEmpty()){
-    m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
+    m_thumbProd = new KThumb(clipManager, 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() ) );
                
@@ -42,11 +42,11 @@ m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0),
   if (m_clipType == AV || m_clipType==AUDIO || m_clipType==UNKNOWN){
     m_audioTimer = new QTimer( this );
     connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
-    //TODO disabled until the crash cause is found 
-    emit getAudioThumbs();
   }
 }
 
+
+
 DocClipBase::DocClipBase(const DocClipBase& clip)
 {
     m_xml = clip.toXML();
@@ -74,6 +74,11 @@ DocClipBase::~DocClipBase()
   //if (m_thumbProd) delete m_thumbProd;
 }
 
+void DocClipBase::slotRequestAudioThumbs()
+{
+  emit getAudioThumbs();
+}
+
 KThumb *DocClipBase::thumbProducer()
 {
   return m_thumbProd;
@@ -239,6 +244,7 @@ const QPixmap & DocClipBase::thumbnail() const
 
 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
 {
+    kDebug()<<"CLIPBASE RECIEDVED AUDIO DATA*********************************************";
     audioFrameChache = data;
     m_audioThumbCreated = true;
     emit gotAudioData();
@@ -419,3 +425,5 @@ void DocClipBase::slotGetAudioThumbs(){
        }
 }
 
+
+
index 2de28b88e6a8a907ab0c5e6ad77b0a4ec8de84cb..c91934f4c67cdf520ef7b9c929df58a58b475f46 100644 (file)
@@ -31,6 +31,7 @@
 #include <klocale.h>
 
 #include "gentime.h"
+#include "clipmanager.h"
 #include "definitions.h"
  #include "kthumb.h"
 
@@ -66,7 +67,7 @@ class DocClipBase:public QObject {
         *   done here. If a new clip type is added then it should be possible to combine it with both audio
         *   and video. */
 
-     DocClipBase(QDomElement xml, uint id);
+     DocClipBase(ClipManager *clipManager, QDomElement xml, uint id);
      DocClipBase(const DocClipBase& clip);
      DocClipBase & operator=(const DocClipBase & clip);
      virtual ~ DocClipBase();
@@ -193,6 +194,10 @@ class DocClipBase:public QObject {
        /** return english name for clip type */
     static QString getTypeName(CLIPTYPE type);
 
+      /** Clip is ready to get thumbs */ 
+    void slotRequestAudioThumbs();
+
+
   private:                     // Private attributes
        /** The name of this clip */
     QString m_name;
@@ -236,8 +241,9 @@ class DocClipBase:public QObject {
        QString markerComment(GenTime t);
        void setProjectThumbFrame( const uint &ix);
        uint getProjectThumbFrame() const;
-       signals:
-               void getAudioThumbs();
+
+  signals:
+       void getAudioThumbs();
        void gotAudioData();
 };
 
index 0f7743d549cba151667cac65df39ac1e17e42881..af35d76967611a3c47107f32393d16616089bd27 100644 (file)
@@ -33,21 +33,4 @@ private:
 };
 
 
-class EffectEvent : public QEvent {
-public:
-       EffectEvent( GenTime pos, int track, QDomElement xml, QEvent::Type eventType  )
-               : QEvent( eventType ), m_pos( pos ), m_track(track), m_xml(xml) {
-       if (xml.isNull()) kDebug()<<"--- ERROR, TRYING TO APPEND NULL EFFECT EVENT";    
-       if (m_xml.isNull()) kDebug()<<"--- ERROR, TRYING TO APPEND NULL EFFECT EVENT 2";
-       };
-       GenTime pos() const { return m_pos; };
-       int track() const { return m_track; };
-       QDomElement xml() const { return m_xml; };
-private:
-       GenTime m_pos;
-       int m_track;
-       QDomElement m_xml;
-       
-};
-
 #endif
index 94166e984abdb5b971e75858f03e6d35ccd70dc8..49aabf69da7f564b68519967971d1de85df91000 100644 (file)
@@ -26,6 +26,7 @@
 
 
 #include "kdenlivedoc.h"
+#include "docclipbase.h"
 
 KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL), m_commandStack(new KUndoStack())
 {
@@ -120,6 +121,11 @@ ClipManager *KdenliveDoc::clipManager()
   return m_clipManager;
 }
 
+void KdenliveDoc::setThumbsProgress(KUrl url, int progress)
+{
+  emit thumbsProgress(url, progress);
+}
+
 KUndoStack *KdenliveDoc::commandStack()
 {
   return m_commandStack;
@@ -270,7 +276,7 @@ KUrl KdenliveDoc::url()
 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId)
 {
   kDebug()<<"/////////  DOCUM, CREATING NEW CLIP, ID:"<<clipId;
-  DocClipBase *clip = new DocClipBase(elem, clipId);
+  DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
   m_clipManager->addClip(clip);
   emit addProjectClip(clip);
 }
index 4f285f3f4cd0392c798b92074e45b4744b5ba274..b62aebe4b704c15f5218e010981788d65cd5170c 100644 (file)
@@ -64,6 +64,8 @@ class KdenliveDoc:public QObject {
     DocClipBase *getBaseClip(int clipId);
     void updateClip(int id);
     void deleteProjectClip(const uint clipId);
+    /** Inform application of the audio thumbnails generation progress */
+    void setThumbsProgress(KUrl url, int progress);
 
   private:
     KUrl m_url;
@@ -85,6 +87,7 @@ class KdenliveDoc:public QObject {
     void signalDeleteProjectClip(int);
     void updateClipDisplay(int);
     void deletTimelineClip(int);
+    void thumbsProgress(KUrl, int);
 };
 
 #endif
index d905aa728601c10854bb43f76e63f01a25ea91d2..2358fc7fee225140ae9ae87902bb13a72ee2bc5b 100644 (file)
 #include <QApplication>
 #include <QCryptographicHash>
 
-
+#include "clipmanager.h"
 #include "renderer.h"
 #include "kthumb.h"
 #include "kdenlivesettings.h"
 #include "events.h"
-void MyThread::init(KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth)
+
+void MyThread::init(QObject *parent, KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth)
     {
        stop_me = false;
+       m_parent = parent;
        m_isWorking = false;
        f.setFileName(target);
        m_url = url;
@@ -54,7 +56,6 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
        m_frequency = frequency;
        m_channels = channels;
        m_arrayWidth = arrayWidth;
-
     }
 
     bool MyThread::isWorking()
@@ -72,8 +73,8 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
                        return;
                }
                m_isWorking = true;
-               Mlt::Profile prof((char*) KdenliveSettings::current_profile().data());
-               Mlt::Producer m_producer(prof, m_url.path().toAscii().data());
+               Mlt::Profile prof((char*) qstrdup(KdenliveSettings::current_profile().toUtf8()));
+               Mlt::Producer m_producer(prof, m_url.path().toUtf8().data());
                
 
                /*TODO if (KdenliveSettings::normaliseaudiothumbs()) {
@@ -82,8 +83,7 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
                    m_producer.attach(m_convert);
                }*/
 
-               if (QApplication::activeWindow()) 
-                       QApplication::postEvent(QApplication::activeWindow(), new ProgressEvent(-1, (QEvent::Type)10005));
+               //QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005));
        
                int last_val = 0;
                int val = 0;
@@ -92,13 +92,13 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
                        if (stop_me) break;
                        val=(int)((z-m_frame)/(m_frame+m_frameLength)*100.0);
                        if (last_val!=val & val > 1){
-                               QApplication::postEvent(QApplication::activeWindow(), new ProgressEvent(val, (QEvent::Type)10005));
+                               QApplication::postEvent(m_parent, new ProgressEvent(val, (QEvent::Type)10005));
                                
                                last_val=val;
                        }
                                m_producer.seek( z );
                                Mlt::Frame *mlt_frame = m_producer.get_frame();
-                               if ( mlt_frame->is_valid() )
+                               if ( mlt_frame && mlt_frame->is_valid() )
                                {
                                        double m_framesPerSecond = mlt_producer_get_fps( m_producer.get_producer() ); //mlt_frame->get_double( "fps" );
                                        int m_samples = mlt_sample_calculator( m_framesPerSecond, m_frequency, mlt_frame_get_position(mlt_frame->get_frame()) );
@@ -126,10 +126,10 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
                m_isWorking = false;
                if (stop_me) {
                    f.remove();
-                        QApplication::postEvent(QApplication::activeWindow(), new ProgressEvent(-1, (QEvent::Type)10005));
+                   QApplication::postEvent(m_parent, new ProgressEvent(-1, (QEvent::Type)10005));
                   
                }
-               QApplication::postEvent(QApplication::activeWindow(), new ProgressEvent(0, (QEvent::Type)10005));
+               QApplication::postEvent(m_parent, new ProgressEvent(0, (QEvent::Type)10005));
                
     }
 
@@ -139,10 +139,10 @@ void MyThread::init(KUrl url, QString target, double frame, double frameLength,
 #define _G(y,u,v) (0x2568*(y) - 0x0c92*(v) - 0x1a1e*(u)) /0x2000
 #define _B(y,u,v) (0x2568*(y) + 0x40cf*(v))                                          /0x2000
 
-KThumb::KThumb(KUrl url, int width, int height, QObject * parent, const char *name):QObject(parent), m_url(url), m_width(width), m_height(height)
+KThumb::KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent, const char *name):QObject(parent), m_clipManager(clipManager), m_url(url), m_width(width), m_height(height)
 {
-  kDebug()<<"+++++++++++  CREATING THMB PROD FOR: "<<url;
-  m_profile = new Mlt::Profile((char*) qstrdup(KdenliveSettings::current_profile().toUtf8()));
+
+  m_profile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
   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";
@@ -328,7 +328,7 @@ void KThumb::removeAudioThumb()
 
 void KThumb::getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth){
        
-       if ((thumbProducer.isRunning () && thumbProducer.isWorking()) || channel == 0) {
+       if ((thumbProducer.isRunning() && thumbProducer.isWorking()) || channel == 0) {
            return;
        }
        
@@ -359,10 +359,20 @@ void KThumb::getAudioThumbs(int channel, double frame, double frameLength, int a
        }
        else {
                if (thumbProducer.isRunning()) return;
-               thumbProducer.init(m_url, m_thumbFile, frame, frameLength, m_frequency, m_channels, arrayWidth);
+               thumbProducer.init(this, m_url, m_thumbFile, frame, frameLength, m_frequency, m_channels, arrayWidth);
                thumbProducer.start(QThread::LowestPriority );
+               kDebug() << "STARTING GENERATE THMB FOR: "<<m_url<<" ................................";
        }
 }
 
+void KThumb::customEvent ( QEvent * event ){
+       if (event->type()==10005){
+               ProgressEvent* p=(ProgressEvent*) event;
+               m_clipManager->setThumbsProgress(m_url, p->value());
+       }
+}
+
+
 
+#include "kthumb.moc"
 
index ffdf310a1ccd8a96f1a8f073a83735ac5df65805..fb94122382153da29d8aa7762cdabddfe8eadd46 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <mlt++/Mlt.h>
 
+
 /**KRender encapsulates the client side of the interface to a renderer.
 From Kdenlive's point of view, you treat the KRender object as the
 renderer, and simply use it as if it was local. Calls are asyncrhonous -
@@ -44,12 +45,13 @@ namespace Mlt {
     class Profile;
 };
 
+class ClipManager;
 
 class MyThread : public QThread {
 
     public:
         virtual void run();
-       void init(KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth);
+       void init(QObject *parent, KUrl url, QString target, double frame, double frameLength, int frequency, int channels, int arrayWidth);
        bool isWorking();
        bool stop_me;
 
@@ -62,6 +64,7 @@ class MyThread : public QThread {
        int m_channels;
        int m_arrayWidth;
        bool m_isWorking;
+       QObject *m_parent;
     };
 
 
@@ -69,7 +72,7 @@ class KThumb:public QObject {
   Q_OBJECT public:
 
 
-     KThumb(KUrl url, int width, int height, QObject * parent = 0, const char *name = 0);
+     KThumb(ClipManager *clipManager, KUrl url, int width, int height, QObject * parent = 0, const char *name = 0);
     ~KThumb();
 
 public slots:
@@ -81,6 +84,9 @@ public slots:
        void removeAudioThumb();
        void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth);
 
+protected:
+    virtual void customEvent ( QEvent * event );
+
 private:
        MyThread thumbProducer;
        KUrl m_url;
@@ -88,6 +94,7 @@ private:
        int m_width;
        int m_height;
        Mlt::Profile *m_profile;
+       ClipManager *m_clipManager;
 
 signals:
        void thumbReady(int frame, QPixmap pm);
index a9025b9de08887ac49a7da0f15f00149245d0556..8004e65b6584cb73d8b2e961394eb86911624d10 100644 (file)
@@ -467,6 +467,8 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
   connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
   connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
   connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
+  connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
+
   connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
   connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
   connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
@@ -515,23 +517,17 @@ void MainWindow::slotPreferences()
   //connect( dialog, SIGNAL(settingsChanged()), this, SLOT(updateConfiguration()) );
   dialog->show();
 }
-void MainWindow::customEvent ( QEvent * event ){
-       if (event->type()==10005){
-               ProgressEvent* p=(ProgressEvent*) event;
-               statusProgressBar->setValue(p->value());
-               if (p->value()>0) {
-                       statusLabel->setText(tr("Creating Audio Thumbs"));
-                       statusProgressBar->setVisible(true);
-               }
-               else {
-                       statusLabel->setText("");
-                       statusProgressBar->setVisible(false);
-               }
-       }
-       if (event->type()==10010){
-               EffectEvent* p=(EffectEvent*) event;
-               slotAddEffect(p->xml(), p->pos(), p->track());
-       }
 
+void MainWindow::slotGotProgressInfo( KUrl url, int progress) {
+  statusProgressBar->setValue(progress);
+  if (progress>0) {
+    statusLabel->setText(tr("Creating Audio Thumbs"));
+    statusProgressBar->setVisible(true);
+  }
+  else {
+    statusLabel->setText("");
+    statusProgressBar->setVisible(false);
+  }
 }
+
 #include "mainwindow.moc"
index 5be8803f05dd0ccc6acc7913056bc21c3744f0bd..d38d9561874a0fcff03488c420d063dc08dc2311 100644 (file)
@@ -53,7 +53,7 @@ class MainWindow : public KXmlGuiWindow
     MainWindow(QWidget *parent=0);
 
     void parseProfiles();
-    void customEvent ( QEvent * event );
+
   protected:
     virtual bool queryClose();
   
@@ -124,6 +124,7 @@ class MainWindow : public KXmlGuiWindow
     void slotEditProfiles();
     void slotEditProjectSettings();
     void slotDisplayActionMessage( QAction *a);
+    void slotGotProgressInfo( KUrl url, int progress);
 };
  
 #endif
index d58e23614e7298533448ffcb41ba64dd5c86b078..287c27ba3a1f753c0b9f2c7c6d7afee7866a0181 100644 (file)
@@ -229,15 +229,16 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
          }
        m_clip->setClipType(m_clipType);
        }
-       slotSetToolTip();
+  slotSetToolTip();
+  if (m_element.isNull()) {
+    QDomDocument doc;
+    m_element = doc.createElement("producer");
+  }
+  if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
+  m_element.setAttribute("resource", attributes["filename"]);
+  m_element.setAttribute("type", (int) m_clipType);
 
-       if (m_element.isNull()) {
-         QDomDocument doc;
-         m_element = doc.createElement("producer");
-       }
-       if (m_element.attribute("duration") == QString::null) m_element.setAttribute("duration", attributes["duration"].toInt());
-       m_element.setAttribute("resource", attributes["filename"]);
-       m_element.setAttribute("type", (int) m_clipType);
+  m_clip->slotRequestAudioThumbs();
 /*
        if (attributes.contains("height")) {
            m_height = attributes["height"].toInt();