]> git.sesse.net Git - kdenlive/blobdiff - src/audiosignal.cpp
Stop using 'mlt_profile' in render profiles. Instead use 's' and 'aspect'.
[kdenlive] / src / audiosignal.cpp
index 6a935869b0d97e99ce857711eecef9efc2e38e8f..30471e0bf288b078a183cf2406e3d6a567d647dd 100644 (file)
@@ -18,7 +18,7 @@
  ***************************************************************************/
 
 #include "audiosignal.h"
-#include "kdenlivesettings.h"
+#include "math.h"
 
 #include <KLocale>
 
@@ -42,15 +42,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;
+}
 
-void AudioSignal::slotReceiveAudio(const QVector<int16_t>& data, int freq ,int num_channels ,int samples){
+bool AudioSignal::monitoringEnabled() const
+{
+    return m_aMonitoringEnabled->isChecked();
+}
+
+void AudioSignal::slotReceiveAudio(const QVector<int16_t>& data, int, int num_channels, int samples){
 
     int num_samples = samples > 200 ? 200 : samples;
 
@@ -82,16 +90,35 @@ void AudioSignal::showAudio(const QByteArray arr)
     }
     update();
 }
+
+double AudioSignal::valueToPixel(double in,bool db)
+{
+    if (db)
+    {
+        // ratio db(in)/db(0.01) (means: min db value = -40.0 )
+        return 1.0- log10( in)/log10(0.01);
+    }
+    else
+    {
+        return in;
+    }
+}
+
 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));
     //p.fillRect(0,height()/2,(unsigned char)channels[1]*width()/255,height()/2,QBrush(Qt::SolidPattern));
     int numchan = channels.size();
+    bool db=true; // show values in db(i)
     bool horiz=width() > height();
     for (int i = 0; i < numchan; i++) {
-        int maxx= (unsigned char)channels[i] * (horiz ? width() : height() ) / 127;
+        //int maxx= (unsigned char)channels[i] * (horiz ? width() : height() ) / 127;
+        int maxx= (horiz ? width() : height() ) * valueToPixel((double)(unsigned char)channels[i]/127.0,db);
         int xdelta=(horiz ? width():height() )  /20 ;
         int _y2= (horiz ?  height() :width () ) / numchan - 1  ;
         int _y1=(horiz ? height():width() ) *i/numchan;
@@ -105,15 +132,14 @@ void AudioSignal::paintEvent(QPaintEvent* /*e*/)
                 maxx -= xdelta;
             }
         }
-        int xp=peeks.at(i)*(horiz?width():height())/127-2;
+        int xp=valueToPixel((double)peeks.at(i)/127.0,db)*(horiz?width():height())-2;
         p.fillRect(horiz?xp:_y1,horiz?_y1:height()-xdelta-xp,horiz?3:_y2,horiz?_y2:3,QBrush(Qt::black,Qt::SolidPattern));
     }
     p.end();
 }
 
-void AudioSignal::slotSwitchAudioMonitoring(bool isOn)
+void AudioSignal::slotSwitchAudioMonitoring(bool)
 {
-    KdenliveSettings::setMonitor_audio(isOn);
     emit updateAudioMonitoring();
 }