]> git.sesse.net Git - kdenlive/blob - src/scopes/audioscopes/audiospectrum.h
Preparing for scope manager (merge from Granjow's work in refactoring)
[kdenlive] / src / scopes / 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 // Enables debugging
21 //#define DEBUG_AUDIOSPEC
22
23 // Show overmodulation
24 #define DETECT_OVERMODULATION
25
26 #include <QtCore>
27 #include <QVector>
28 #include <QHash>
29
30 #include "abstractaudioscopewidget.h"
31 #include "ui_audiospectrum_ui.h"
32 #include "kiss_fft/tools/kiss_fftr.h"
33 #include "ffttools.h"
34
35 class AudioSpectrum_UI;
36 class AudioSpectrum : public AbstractAudioScopeWidget {
37     Q_OBJECT
38
39 public:
40     AudioSpectrum(QWidget *parent = 0);
41     ~AudioSpectrum();
42
43     // Implemented virtual methods
44     QString widgetName() const;
45
46
47 protected:
48     ///// Implemented methods /////
49     QRect scopeRect();
50     QImage renderHUD(uint accelerationFactor);
51     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
52     QImage renderBackground(uint accelerationFactor);
53     bool isHUDDependingOnInput() const;
54     bool isScopeDependingOnInput() const;
55     bool isBackgroundDependingOnInput() const;
56     virtual void readConfig();
57     void writeConfig();
58
59     virtual void handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
60
61 private:
62     Ui::AudioSpectrum_UI *ui;
63
64     QAction *m_aResetHz;
65     QAction *m_aTrackMouse;
66     QAction *m_aShowMax;
67
68     FFTTools m_fftTools;
69     QVector<float> m_lastFFT;
70     QSemaphore m_lastFFTLock;
71
72     QVector<float> m_peaks;
73     QVector<float> m_peakMap;
74
75     /** Contains the plot only; m_scopeRect contains text and widgets as well */
76     QRect m_innerScopeRect;
77
78     /** Lower bound for the dB value to display */
79     int m_dBmin;
80     /** Upper bound (max: 0) */
81     int m_dBmax;
82
83     /** Maximum frequency (limited by the sampling rate if determined automatically).
84         Stored for the painters. */
85     int m_freqMax;
86     /** The user has chosen a custom frequency. */
87     bool m_customFreq;
88
89     float colorizeFactor;
90
91 #ifdef DEBUG_AUDIOSPEC
92     long m_timeTotal;
93     long m_showTotal;
94 #endif
95
96
97 private slots:
98     void slotResetMaxFreq();
99
100 };
101
102 #endif // AUDIOSPECTRUM_H