]> git.sesse.net Git - kdenlive/blob - src/scopes/audioscopes/spectrogram.h
Fix includes
[kdenlive] / src / scopes / audioscopes / spectrogram.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 /** This Spectrogram shows the spectral power distribution of incoming audio samples
12     over time. See http://en.wikipedia.org/wiki/Spectrogram.
13
14     The Spectrogram makes use of two caches:
15     * A cached image where only the most recent line needs to be appended instead of
16       having to recalculate the whole image. A typical speedup factor is 10x.
17     * A FFT cache storing a history of previous spectral power distributions (i.e.
18       the Fourier-transformed audio signals). This is used if the user adjusts parameters
19       like the maximum frequency to display or minimum/maximum signal strength in dB.
20       All required information is preserved in the FFT history, which would not be the
21       case for an image (consider re-sizing the widget to 100x100 px and then back to
22       800x400 px -- lost is lost).
23 */
24
25 #ifndef SPECTROGRAM_H
26 #define SPECTROGRAM_H
27
28
29 #include "abstractaudioscopewidget.h"
30 #include "ui_spectrogram_ui.h"
31 #include "lib/audio/fftTools.h"
32
33 class Spectrogram_UI;
34 class Spectrogram : public AbstractAudioScopeWidget {
35     Q_OBJECT
36
37 public:
38     Spectrogram(QWidget *parent = 0);
39     ~Spectrogram();
40
41     QString widgetName() const;
42
43 protected:
44     ///// Implemented methods /////
45     QRect scopeRect();
46     QImage renderHUD(uint accelerationFactor);
47     QImage renderAudioScope(uint accelerationFactor, const QVector<int16_t> &audioFrame, const int freq, const int num_channels, const int num_samples, const int newData);
48     QImage renderBackground(uint accelerationFactor);
49     bool isHUDDependingOnInput() const;
50     bool isScopeDependingOnInput() const;
51     bool isBackgroundDependingOnInput() const;
52     virtual void readConfig();
53     void writeConfig();
54     void handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
55     void resizeEvent(QResizeEvent *event);
56
57 private:
58     Ui::Spectrogram_UI *ui;
59     FFTTools m_fftTools;
60     QAction *m_aResetHz;
61     QAction *m_aGrid;
62     QAction *m_aTrackMouse;
63     QAction *m_aHighlightPeaks;
64
65     QList<QVector<float> > m_fftHistory;
66     QImage m_fftHistoryImg;
67
68     int m_dBmin;
69     int m_dBmax;
70
71     int m_freqMax;
72     bool m_customFreq;
73
74     bool m_parameterChanged;
75
76     QRect m_innerScopeRect;
77
78 private slots:
79     void slotResetMaxFreq();
80
81 };
82
83 #endif // SPECTROGRAM_H