]> git.sesse.net Git - kdenlive/blob - src/audioscopes/audiospectrum.h
Audio scopes: Caching window functions for better performance
[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 #ifndef AUDIOSPECTRUM_H
12 #define AUDIOSPECTRUM_H
13
14 #include <QtCore>
15 #include <QVector>
16 #include <QHash>
17
18 #include "abstractaudioscopewidget.h"
19 #include "ui_audiospectrum_ui.h"
20 #include "tools/kiss_fftr.h"
21
22 class AudioSpectrum_UI;
23 class AudioSpectrum : public AbstractAudioScopeWidget {
24     Q_OBJECT
25
26 public:
27     AudioSpectrum(QWidget *parent = 0);
28     ~AudioSpectrum();
29
30     // Implemented virtual methods
31     QString widgetName() const;
32
33     static const QString directions[]; // Mainly for debug output
34     enum RescaleDirection { North, Northeast, East, Southeast };
35     enum RescaleDimension { Min_dB, Max_dB, Max_Hz };
36
37
38 protected:
39     ///// Implemented methods /////
40     QRect scopeRect();
41     QImage renderHUD(uint accelerationFactor);
42     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples);
43     QImage renderBackground(uint accelerationFactor);
44     bool isHUDDependingOnInput() const;
45     bool isScopeDependingOnInput() const;
46     bool isBackgroundDependingOnInput() const;
47     virtual void readConfig();
48     void writeConfig();
49
50     void mouseMoveEvent(QMouseEvent *event);
51     void mousePressEvent(QMouseEvent *event);
52     void mouseReleaseEvent(QMouseEvent *event);
53
54 private:
55     Ui::AudioSpectrum_UI *ui;
56     kiss_fftr_cfg m_cfg;
57     QHash<QString, QVector<float> > m_windowFunctions;
58
59     QAction *m_aResetHz;
60
61     // Contains the plot only; m_scopeRect contains text and widgets as well
62     QRect m_innerScopeRect;
63
64     /** Lower bound for the dB value to display */
65     int m_dBmin;
66     /** Upper bound (max: 0) */
67     int m_dBmax;
68
69     /** Maximum frequency (depends on the sampling rate)
70         Stored for the HUD painter */
71     uint m_freqMax;
72     /** The user has chosen a custom frequency. */
73     bool m_customFreq;
74
75
76     ///// Movement detection /////
77     const int m_rescaleMinDist;
78     const float m_rescaleVerticalThreshold;
79
80     bool m_rescaleActive;
81     bool m_rescalePropertiesLocked;
82     bool m_rescaleFirstRescaleDone;
83     short m_rescaleScale;
84     Qt::KeyboardModifiers m_rescaleModifiers;
85     AudioSpectrum::RescaleDirection m_rescaleClockDirection;
86     QPoint m_rescaleStartPoint;
87
88
89
90 private slots:
91     void slotUpdateCfg();
92     void slotResetMaxFreq();
93
94 };
95
96 #endif // AUDIOSPECTRUM_H