]> git.sesse.net Git - kdenlive/commitdiff
Audio scopes: Only deliver audio when required for better performance when scopes...
authorSimon A. Eugster <simon.eu@gmail.com>
Mon, 13 Dec 2010 08:20:34 +0000 (08:20 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Mon, 13 Dec 2010 08:20:34 +0000 (08:20 +0000)
svn path=/trunk/kdenlive/; revision=5172

src/audioscopes/ffttools.cpp
src/audiosignal.cpp
src/audiosignal.h
src/mainwindow.cpp
src/mainwindow.h
src/monitormanager.h
src/renderer.cpp

index 1464c7ef4ebc3ca311fd7a58e55a27e12b4a43c9..2ede0fa584cb54a89788c6f9985a568d6b5807c8 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "ffttools.h"
 
-// Uncomment for debugging
+// Uncomment for debugging, like writing a GNU Octave .m file to /tmp
 //#define DEBUG_FFTTOOLS
 
 #ifdef DEBUG_FFTTOOLS
index 6a935869b0d97e99ce857711eecef9efc2e38e8f..212e119bc4f981172b39c8df2149195e2d309848 100644 (file)
@@ -18,7 +18,6 @@
  ***************************************************************************/
 
 #include "audiosignal.h"
-#include "kdenlivesettings.h"
 
 #include <KLocale>
 
@@ -42,15 +41,23 @@ AudioSignal::AudioSignal(QWidget *parent): QWidget(parent)
     col << Qt::darkYellow << Qt::darkYellow << Qt::darkYellow;
     col << Qt::red << Qt::red;
     setContextMenuPolicy(Qt::ActionsContextMenu);
-    QAction *showSignal = new QAction(i18n("Monitor audio signal"), this);
-    showSignal->setCheckable(true);
-    showSignal->setChecked(KdenliveSettings::monitor_audio());
-    connect(showSignal, SIGNAL(toggled(bool)), this, SLOT(slotSwitchAudioMonitoring(bool)));
-    addAction(showSignal);
+    m_aMonitoringEnabled = new QAction(i18n("Monitor audio signal"), this);
+    m_aMonitoringEnabled->setCheckable(true);
+    connect(m_aMonitoringEnabled, SIGNAL(toggled(bool)), this, SLOT(slotSwitchAudioMonitoring(bool)));
+    addAction(m_aMonitoringEnabled);
 }
 
+AudioSignal::~AudioSignal()
+{
+    delete m_aMonitoringEnabled;
+}
+
+bool AudioSignal::monitoringEnabled() const
+{
+    return m_aMonitoringEnabled->isChecked();
+}
 
-void AudioSignal::slotReceiveAudio(const QVector<int16_t>& data, int freq ,int num_channels ,int samples){
+void AudioSignal::slotReceiveAudio(const QVector<int16_t>& data, int, int num_channels, int samples){
 
     int num_samples = samples > 200 ? 200 : samples;
 
@@ -84,6 +91,9 @@ void AudioSignal::showAudio(const QByteArray arr)
 }
 void AudioSignal::paintEvent(QPaintEvent* /*e*/)
 {
+    if (!m_aMonitoringEnabled->isChecked()) {
+        return;
+    }
     QPainter p(this);
     //p.begin();
     //p.fillRect(0,0,(unsigned char)channels[0]*width()/255,height()/2,QBrush(Qt::SolidPattern));
@@ -111,9 +121,8 @@ void AudioSignal::paintEvent(QPaintEvent* /*e*/)
     p.end();
 }
 
-void AudioSignal::slotSwitchAudioMonitoring(bool isOn)
+void AudioSignal::slotSwitchAudioMonitoring(bool)
 {
-    KdenliveSettings::setMonitor_audio(isOn);
     emit updateAudioMonitoring();
 }
 
index 5a2680a7d540b81326ae89ee6dae99ab11328007..9034773cf4036e0517d544d1077ac4be083eb719 100644 (file)
@@ -31,19 +31,27 @@ class AudioSignal : public QWidget
     Q_OBJECT
 public:
     AudioSignal(QWidget *parent = 0);
+    ~AudioSignal();
+    /** @brief Used for checking whether audio data needs to be delivered */
+    bool monitoringEnabled() const;
+
 private:
     QLabel* label;
     QByteArray channels,peeks,peekage;
     QList<QColor> col;
+    QAction *m_aMonitoringEnabled;
+
 protected:
     void paintEvent(QPaintEvent*);
+
 public slots:
     void showAudio(const QByteArray);
     void slotReceiveAudio(const QVector<int16_t>&,int,int,int);
 private slots:
-  void slotSwitchAudioMonitoring(bool isOn);
+     void slotSwitchAudioMonitoring(bool isOn);
+
 signals:
-  void updateAudioMonitoring();
+    void updateAudioMonitoring();
 
 };
 
index 238a0fbf78b90ed4acc7b5ff603daec14ae6c21f..1cdb931bee6737290f710e15049ee29cf821eded 100644 (file)
 
 #include <stdlib.h>
 
+// Uncomment for deeper debugging
 //#define DEBUG_MAINW
+
 #ifdef DEBUG_MAINW
 #include <QDebug>
 #endif
@@ -247,9 +249,9 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_vectorscopeDock->setWidget(m_vectorscope);
     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
     connect(m_vectorscopeDock, SIGNAL(visibilityChanged(bool)), m_vectorscope, SLOT(forceUpdate(bool)));
-    connect(m_vectorscopeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    connect(m_vectorscope, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    m_scopesList.append(m_vectorscopeDock);
+    connect(m_vectorscopeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    connect(m_vectorscope, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    m_gfxScopesList.append(m_vectorscopeDock);
 
     m_waveform = new Waveform(m_projectMonitor, m_clipMonitor);
     m_waveformDock = new QDockWidget(i18n("Waveform"), this);
@@ -257,9 +259,9 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_waveformDock->setWidget(m_waveform);
     addDockWidget(Qt::TopDockWidgetArea, m_waveformDock);
     connect(m_waveformDock, SIGNAL(visibilityChanged(bool)), m_waveform, SLOT(forceUpdate(bool)));
-    connect(m_waveformDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    connect(m_waveform, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    m_scopesList.append(m_waveformDock);
+    connect(m_waveformDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    connect(m_waveform, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    m_gfxScopesList.append(m_waveformDock);
 
     m_RGBParade = new RGBParade(m_projectMonitor, m_clipMonitor);
     m_RGBParadeDock = new QDockWidget(i18n("RGB Parade"), this);
@@ -267,9 +269,9 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_RGBParadeDock->setWidget(m_RGBParade);
     addDockWidget(Qt::TopDockWidgetArea, m_RGBParadeDock);
     connect(m_RGBParadeDock, SIGNAL(visibilityChanged(bool)), m_RGBParade, SLOT(forceUpdate(bool)));
-    connect(m_RGBParadeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    connect(m_RGBParade, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    m_scopesList.append(m_RGBParadeDock);
+    connect(m_RGBParadeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    connect(m_RGBParade, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    m_gfxScopesList.append(m_RGBParadeDock);
 
     m_histogram = new Histogram(m_projectMonitor, m_clipMonitor);
     m_histogramDock = new QDockWidget(i18n("Histogram"), this);
@@ -277,9 +279,9 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_histogramDock->setWidget(m_histogram);
     addDockWidget(Qt::TopDockWidgetArea, m_histogramDock);
     connect(m_histogramDock, SIGNAL(visibilityChanged(bool)), m_histogram, SLOT(forceUpdate(bool)));
-    connect(m_histogramDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    connect(m_histogram, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateScopeFrameRequest()));
-    m_scopesList.append(m_histogramDock);
+    connect(m_histogramDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    connect(m_histogram, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
+    m_gfxScopesList.append(m_histogramDock);
 
 
     m_audiosignal = new AudioSignal;
@@ -287,25 +289,27 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString &
     m_audiosignalDock->setObjectName("audiosignal");
     m_audiosignalDock->setWidget(m_audiosignal);
     addDockWidget(Qt::TopDockWidgetArea, m_audiosignalDock);
-    connect(m_audiosignal, SIGNAL(updateAudioMonitoring()), m_monitorManager, SLOT(slotUpdateAudioMonitoring()));
-    /*if (m_projectMonitor) {
-        connect(m_projectMonitor->render, SIGNAL(showAudioSignal(const QByteArray&)), m_audiosignal, SLOT(showAudio(const QByteArray&)));
-    }
-    if (m_clipMonitor) {
-        connect(m_clipMonitor->render, SIGNAL(showAudioSignal(const QByteArray&)), m_audiosignal, SLOT(showAudio(const QByteArray&)));
-    }*/
+//    connect(m_audiosignal, SIGNAL(updateAudioMonitoring()), m_monitorManager, SLOT(slotUpdateAudioMonitoring()));
+    connect(m_audiosignalDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
+    connect(m_audiosignal, SIGNAL(updateAudioMonitoring()), this, SLOT(slotUpdateAudioScopeFrameRequest()));
 
     m_audioSpectrum = new AudioSpectrum();
     m_audioSpectrumDock = new QDockWidget(i18n("AudioSpectrum"), this);
     m_audioSpectrumDock->setObjectName(m_audioSpectrum->widgetName());
     m_audioSpectrumDock->setWidget(m_audioSpectrum);
     addDockWidget(Qt::TopDockWidgetArea, m_audioSpectrumDock);
+    m_audioScopesList.append(m_audioSpectrum);
+    connect(m_audioSpectrumDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
+    connect(m_audioSpectrum, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
 
     m_spectrogram = new Spectrogram();
     m_spectrogramDock = new QDockWidget(i18n("Spectrogram"), this);
     m_spectrogramDock->setObjectName(m_spectrogram->widgetName());
     m_spectrogramDock->setWidget(m_spectrogram);
     addDockWidget(Qt::TopDockWidgetArea, m_spectrogramDock);
+    m_audioScopesList.append(m_spectrogram);
+    connect(m_audioSpectrumDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
+    connect(m_audioSpectrum, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
 
     // Connect the audio signal to the audio scope slots
     bool b = true;
@@ -4001,8 +4005,8 @@ void MainWindow::slotMonitorRequestRenderFrame(bool request)
         m_projectMonitor->render->sendFrameForAnalysis = true;
         return;
     } else {
-        for (int i = 0; i < m_scopesList.count(); i++) {
-            if (m_scopesList.at(i)->isVisible() && tabifiedDockWidgets(m_scopesList.at(i)).isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
+        for (int i = 0; i < m_gfxScopesList.count(); i++) {
+            if (m_gfxScopesList.at(i)->isVisible() && tabifiedDockWidgets(m_gfxScopesList.at(i)).isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
                 request = true;
                 break;
             }
@@ -4016,19 +4020,19 @@ void MainWindow::slotMonitorRequestRenderFrame(bool request)
     }
 }
 
-void MainWindow::slotUpdateScopeFrameRequest()
+void MainWindow::slotUpdateGfxScopeFrameRequest()
 {
     // We need a delay to make sure widgets are hidden after a close event for example
-    QTimer::singleShot(500, this, SLOT(slotDoUpdateScopeFrameRequest()));
+    QTimer::singleShot(500, this, SLOT(slotDoUpdateGfxScopeFrameRequest()));
 }
 
-void MainWindow::slotDoUpdateScopeFrameRequest()
+void MainWindow::slotDoUpdateGfxScopeFrameRequest()
 {
     // Check scopes
     bool request = false;
-    for (int i = 0; i < m_scopesList.count(); i++) {
-        if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
-            kDebug() << "SCOPE VISIBLE: " << static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget())->widgetName();
+    for (int i = 0; i < m_gfxScopesList.count(); i++) {
+        if (!m_gfxScopesList.at(i)->widget()->visibleRegion().isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
+            kDebug() << "SCOPE VISIBLE: " << static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->widgetName();
             request = true;
             break;
         }
@@ -4044,13 +4048,40 @@ void MainWindow::slotDoUpdateScopeFrameRequest()
     }
 }
 
+void MainWindow::slotUpdateAudioScopeFrameRequest()
+{
+    QTimer::singleShot(500, this, SLOT(slotDoUpdateAudioScopeFrameRequest()));
+}
+
+void MainWindow::slotDoUpdateAudioScopeFrameRequest()
+{
+    bool request = false;
+    for (int i = 0; i < m_audioScopesList.count(); i++) {
+        if (!m_audioScopesList.at(i)->visibleRegion().isEmpty() && m_audioScopesList.at(i)->autoRefreshEnabled()) {
+            kDebug() << "AUDIO SCOPE VISIBLE: " << m_audioScopesList.at(i)->widgetName();
+            request = true;
+            break;
+        }
+    }
+    // Handle audio signal separately (no common interface)
+    if (!m_audiosignal->visibleRegion().isEmpty() && m_audiosignal->monitoringEnabled()) {
+        kDebug() << "AUDIO SCOPE VISIBLE: " << "audiosignal";
+        request = true;
+    }
+#ifdef DEBUG_MAINW
+    qDebug() << "Scopes Requesting Audio data: " << request;
+#endif
+    KdenliveSettings::setMonitor_audio(request);
+    m_monitorManager->slotUpdateAudioMonitoring();
+}
+
 void MainWindow::slotUpdateColorScopes()
 {
     bool request = false;
-    for (int i = 0; i < m_scopesList.count(); i++) {
+    for (int i = 0; i < m_gfxScopesList.count(); i++) {
         // Check if we need the renderer to send a new frame for update
-        if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;
-        static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget())->slotActiveMonitorChanged(m_clipMonitor->isActive());
+        if (!m_gfxScopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled())) request = true;
+        static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->slotActiveMonitorChanged(m_clipMonitor->isActive());
     }
     if (request) {
         if (m_clipMonitor->isActive()) m_clipMonitor->render->sendFrameUpdate();
@@ -4063,10 +4094,10 @@ void MainWindow::slotOpenStopmotion()
     if (m_stopmotion == NULL) {
         m_stopmotion = new StopmotionWidget(m_activeDocument->projectFolder(), m_stopmotion_actions->actions(), this);
         connect(m_stopmotion, SIGNAL(addOrUpdateSequence(const QString)), m_projectList, SLOT(slotAddOrUpdateSequence(const QString)));
-        for (int i = 0; i < m_scopesList.count(); i++) {
+        for (int i = 0; i < m_gfxScopesList.count(); i++) {
             // Check if we need the renderer to send a new frame for update
             /*if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;*/
-            connect(m_stopmotion, SIGNAL(gotFrame(QImage)), static_cast<AbstractGfxScopeWidget *>(m_scopesList.at(i)->widget()), SLOT(slotRenderZoneUpdated(QImage)));
+            connect(m_stopmotion, SIGNAL(gotFrame(QImage)), static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget()), SLOT(slotRenderZoneUpdated(QImage)));
             //static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotMonitorCapture();
         }
     }
index 602441b818fac33a9f6a33baf240fffa474ecd29..a5f22924a0ef4645190e8f4f1537ad19e6f4105f 100644 (file)
@@ -70,6 +70,7 @@ class Waveform;
 class RGBParade;
 class KActionCollection;
 class AudioSignal;
+class AbstractAudioScopeWidget;
 class AudioSpectrum;
 class Spectrogram;
 
@@ -193,7 +194,8 @@ private:
     KComboBox *m_timecodeFormat;
 
     /** This list holds all the scopes used in Kdenlive, allowing to manage some global settings */
-    QList <QDockWidget *> m_scopesList;
+    QList <QDockWidget *> m_gfxScopesList;
+    QList <AbstractAudioScopeWidget *> m_audioScopesList;
 
     QMenu *m_videoEffectsMenu;
     QMenu *m_audioEffectsMenu;
@@ -518,9 +520,11 @@ private slots:
     /** @brief The monitor informs that it needs (or not) to have frames sent by the renderer. */
     void slotMonitorRequestRenderFrame(bool request);
     /** @brief Check if someone needs the render frame sent. */
-    void slotUpdateScopeFrameRequest();
+    void slotUpdateGfxScopeFrameRequest();
     /** @brief Check if someone needs the render frame sent. */
-    void slotDoUpdateScopeFrameRequest();
+    void slotDoUpdateGfxScopeFrameRequest();
+    void slotUpdateAudioScopeFrameRequest();
+    void slotDoUpdateAudioScopeFrameRequest();
     /** @brief When switching between monitors, update the visible scopes. */
     void slotUpdateColorScopes();
     /** @brief Switch current monitor to fullscreen. */
index aafcd12dba3775e8b7e4ec7578dea18e85bd7dc4..625bc6bfc98197ea5d2d6b1b5dbb4e2b02129564 100644 (file)
@@ -60,10 +60,10 @@ public slots:
      * @ref activateMonitor
      * @param activateClip whether to activate the clip monitor */
     void slotSwitchMonitors(bool activateClip);
+    void slotUpdateAudioMonitoring();
 
 private slots:
     void slotRefreshCurrentMonitor();
-    void slotUpdateAudioMonitoring();
 
 private:
     Monitor *m_clipMonitor;
index 14730eda81d67eed6ec45e9c0801b7c3546d1904..203cef2b2cdfdbf2fa0764eb91619957c108046c 100644 (file)
@@ -68,7 +68,9 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr
     if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
         self->emitFrameUpdated(frame);
     }
-    if (self->analyseAudio) self->showAudio(frame);
+    if (self->analyseAudio) {
+        self->showAudio(frame);
+    }
     if (frame.get_double("_speed") == 0.0) {
         self->emitConsumerStopped();
     } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
@@ -1466,7 +1468,9 @@ void Render::showFrame(Mlt::Frame& frame)
 
 void Render::showAudio(Mlt::Frame& frame)
 {
-    if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
+    if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
+        return;
+    }
     mlt_audio_format audio_format = mlt_audio_s16;
     int freq = 0;
     int num_channels = 0;