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