]> git.sesse.net Git - kdenlive/blob - src/audioscopes/audiospectrum.h
Spectrogram:
[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     static const QString directions[]; // Mainly for debug output
41     enum RescaleDirection { North, Northeast, East, Southeast };
42     enum RescaleDimension { Min_dB, Max_dB, Max_Hz };
43
44
45 protected:
46     ///// Implemented methods /////
47     QRect scopeRect();
48     QImage renderHUD(uint accelerationFactor);
49     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples);
50     QImage renderBackground(uint accelerationFactor);
51     bool isHUDDependingOnInput() const;
52     bool isScopeDependingOnInput() const;
53     bool isBackgroundDependingOnInput() const;
54     virtual void readConfig();
55     void writeConfig();
56
57     void mouseMoveEvent(QMouseEvent *event);
58     void mousePressEvent(QMouseEvent *event);
59     void mouseReleaseEvent(QMouseEvent *event);
60
61 private:
62     Ui::AudioSpectrum_UI *ui;
63
64     QAction *m_aResetHz;
65
66     FFTTools m_fftTools;
67
68     /** Contains the plot only; m_scopeRect contains text and widgets as well */
69     QRect m_innerScopeRect;
70
71     /** Lower bound for the dB value to display */
72     int m_dBmin;
73     /** Upper bound (max: 0) */
74     int m_dBmax;
75
76     /** Maximum frequency (limited by the sampling rate if determined automatically).
77         Stored for the painters. */
78     uint m_freqMax;
79     /** The user has chosen a custom frequency. */
80     bool m_customFreq;
81
82
83     /** Returns a signature for a kiss_fft configuration
84         used as a hash in the cache */
85     static const QString cfgSignature(const int size);
86
87
88     ///// Movement detection /////
89     const int m_rescaleMinDist;
90     const float m_rescaleVerticalThreshold;
91
92     bool m_rescaleActive;
93     bool m_rescalePropertiesLocked;
94     bool m_rescaleFirstRescaleDone;
95     short m_rescaleScale;
96     Qt::KeyboardModifiers m_rescaleModifiers;
97     AudioSpectrum::RescaleDirection m_rescaleClockDirection;
98     QPoint m_rescaleStartPoint;
99
100
101
102 private slots:
103     void slotResetMaxFreq();
104
105 };
106
107 #endif // AUDIOSPECTRUM_H