]> git.sesse.net Git - kdenlive/blob - src/audioscopes/audiospectrum.h
Audio scopes: Mouse tracking can be disabled
[kdenlive] / src / audioscopes / audiospectrum.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 /**
12    Displays a spectral power distribution of audio samples.
13    The frequency distribution is calculated by means of a Fast Fourier Transformation.
14    For more information see Wikipedia:FFT and the code comments.
15 */
16
17 #ifndef AUDIOSPECTRUM_H
18 #define AUDIOSPECTRUM_H
19
20 #include <QtCore>
21 #include <QVector>
22 #include <QHash>
23
24 #include "abstractaudioscopewidget.h"
25 #include "ui_audiospectrum_ui.h"
26 #include "tools/kiss_fftr.h"
27 #include "ffttools.h"
28
29 class AudioSpectrum_UI;
30 class AudioSpectrum : public AbstractAudioScopeWidget {
31     Q_OBJECT
32
33 public:
34     AudioSpectrum(QWidget *parent = 0);
35     ~AudioSpectrum();
36
37     // Implemented virtual methods
38     QString widgetName() const;
39
40
41 protected:
42     ///// Implemented methods /////
43     QRect scopeRect();
44     QImage renderHUD(uint accelerationFactor);
45     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
46     QImage renderBackground(uint accelerationFactor);
47     bool isHUDDependingOnInput() const;
48     bool isScopeDependingOnInput() const;
49     bool isBackgroundDependingOnInput() const;
50     virtual void readConfig();
51     void writeConfig();
52
53     virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
54
55 private:
56     Ui::AudioSpectrum_UI *ui;
57
58     QAction *m_aResetHz;
59     QAction *m_aTrackMouse;
60
61     FFTTools m_fftTools;
62     QVector<float> m_lastFFT;
63     QSemaphore m_lastFFTLock;
64
65     /** Contains the plot only; m_scopeRect contains text and widgets as well */
66     QRect m_innerScopeRect;
67
68     /** Lower bound for the dB value to display */
69     int m_dBmin;
70     /** Upper bound (max: 0) */
71     int m_dBmax;
72
73     /** Maximum frequency (limited by the sampling rate if determined automatically).
74         Stored for the painters. */
75     uint m_freqMax;
76     /** The user has chosen a custom frequency. */
77     bool m_customFreq;
78
79     /** This is linear interpolation with the special property that it preserves peaks, which is required
80         for e.g. showing correct Decibel values (where the peak values are of interest).
81         Consider f = {0, 100, 0}
82                  x = {0.5,  1.5}: With default linear interpolation x0 and x1 would both be mapped to 50.
83         This function maps x1 (the first position after the peak) to 100.
84
85         @param in           The source vector containing the data
86         @param targetSize   Number of interpolation nodes between ...
87         @param left         the left array index in the in-vector and ...
88         @param right        the right array index (both inclusive).
89         @param fill         If right lies outside of the array bounds (which is perfectly fine here) then this value
90                             will be used for filling the missing information.
91         */
92     static const QVector<float> interpolatePeakPreserving(const QVector<float> in, const uint targetSize, uint left = 0, uint right = 0, float fill = 0.0);
93
94
95 private slots:
96     void slotResetMaxFreq();
97
98 };
99
100 #endif // AUDIOSPECTRUM_H