]> git.sesse.net Git - kdenlive/blob - src/scopes/audioscopes/spectrogram.h
Preparing for scope manager (merge from Granjow's work in refactoring)
[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 #include <QtCore>
29
30 #include "abstractaudioscopewidget.h"
31 #include "ui_spectrogram_ui.h"
32 #include "ffttools.h"
33
34 class Spectrogram_UI;
35 class Spectrogram : public AbstractAudioScopeWidget {
36     Q_OBJECT
37
38 public:
39     Spectrogram(QWidget *parent = 0);
40     ~Spectrogram();
41
42     QString widgetName() const;
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, const int newData);
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     void handleMouseDrag(const QPoint &movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
56     void resizeEvent(QResizeEvent *event);
57
58 private:
59     Ui::Spectrogram_UI *ui;
60     FFTTools m_fftTools;
61     QAction *m_aResetHz;
62     QAction *m_aGrid;
63     QAction *m_aTrackMouse;
64     QAction *m_aHighlightPeaks;
65
66     QList<QVector<float> > m_fftHistory;
67     QImage m_fftHistoryImg;
68
69     int m_dBmin;
70     int m_dBmax;
71
72     int m_freqMax;
73     bool m_customFreq;
74
75     bool m_parameterChanged;
76
77     QRect m_innerScopeRect;
78
79 private slots:
80     void slotResetMaxFreq();
81
82 };
83
84 #endif // SPECTROGRAM_H