From: Jean-Baptiste Mardelle Date: Sun, 2 Mar 2008 16:32:25 +0000 (+0000) Subject: Fix audio thumbs progress info when window was not focused X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=aa1fa33654ce7a6568c41df395f5ce5cb5bf7a12;p=kdenlive Fix audio thumbs progress info when window was not focused svn path=/branches/KDE4/; revision=1974 --- diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 4413c3fc..e40b1eaa 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -33,6 +33,7 @@ #include #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: "<mimeData()->formats(); event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist")); } diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index cf0812f4..67f933cc 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -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); diff --git a/src/clipmanager.h b/src/clipmanager.h index 30dfd24c..4580cdaa 100644 --- a/src/clipmanager.h +++ b/src/clipmanager.h @@ -34,10 +34,10 @@ #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 */ diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 32beb352..4f5f5d41 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -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 >)), this , SLOT(updateAudioThumbnail(QMap > ))); 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 > data) { + kDebug()<<"CLIPBASE RECIEDVED AUDIO DATA*********************************************"; audioFrameChache = data; m_audioThumbCreated = true; emit gotAudioData(); @@ -419,3 +425,5 @@ void DocClipBase::slotGetAudioThumbs(){ } } + + diff --git a/src/docclipbase.h b/src/docclipbase.h index 2de28b88..c91934f4 100644 --- a/src/docclipbase.h +++ b/src/docclipbase.h @@ -31,6 +31,7 @@ #include #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(); }; diff --git a/src/events.h b/src/events.h index 0f7743d5..af35d769 100644 --- a/src/events.h +++ b/src/events.h @@ -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 diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 94166e98..49aabf69 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -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:"<addClip(clip); emit addProjectClip(clip); } diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 4f285f3f..b62aebe4 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -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 diff --git a/src/kthumb.cpp b/src/kthumb.cpp index d905aa72..2358fc7f 100644 --- a/src/kthumb.cpp +++ b/src/kthumb.cpp @@ -38,14 +38,16 @@ #include #include - +#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: "<type()==10005){ + ProgressEvent* p=(ProgressEvent*) event; + m_clipManager->setThumbsProgress(m_url, p->value()); + } +} + + +#include "kthumb.moc" diff --git a/src/kthumb.h b/src/kthumb.h index ffdf310a..fb941223 100644 --- a/src/kthumb.h +++ b/src/kthumb.h @@ -27,6 +27,7 @@ #include + /**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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a9025b9d..8004e65b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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" diff --git a/src/mainwindow.h b/src/mainwindow.h index 5be8803f..d38d9561 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 diff --git a/src/projectitem.cpp b/src/projectitem.cpp index d58e2361..287c27ba 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -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();