Debian Codegraph @

src/context/applets/analyzer/plugin/AnalyzerBase.h

raw
1 /****************************************************************************************
2 * Copyright (c) 2004 Max Howell <[email protected]> *
3 * Copyright (c) 2009 Martin Sandsmark <[email protected]> *
4 * Copyright (c) 2013 Mark Kretschmann <[email protected]> *
5 * *
6 * This program is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License as published by the Free Software *
8 * Foundation; either version 2 of the License, or (at your option) any later *
9 * version. *
10 * *
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License along with *
16 * this program. If not, see <http://www.gnu.org/licenses/>. *
17 ****************************************************************************************/
18
19 #ifndef ANALYZERBASE_H
20 #define ANALYZERBASE_H
21
22 #ifdef __FreeBSD__
23 #include <sys/types.h>
24 #endif
25
26 #include <QMap>
27 #include <QQuickFramebufferObject>
28 #include <QThread>
29 #include <QVector>
30
31 #include <KConfigGroup>
32
33
34 namespace Analyzer
35 {
36 class Worker;
37
38 class Base : public QQuickFramebufferObject
39 {
40 Q_OBJECT
41 Q_PROPERTY(qreal minFrequency READ minFreq WRITE setMinFreq NOTIFY minFreqChanged)
42 Q_PROPERTY(qreal maxFrequency READ maxFreq WRITE setMaxFreq NOTIFY maxFreqChanged)
43 Q_PROPERTY(WindowFunction windowFunction READ windowFunction WRITE setWindowFunction NOTIFY windowFunctionChanged)
44 Q_PROPERTY(qreal minimumFrequency READ minFreq WRITE setMinFreq NOTIFY minFreqChanged)
45 Q_PROPERTY(qreal maximumFrequency READ maxFreq WRITE setMaxFreq NOTIFY maxFreqChanged)
46 Q_PROPERTY(int sampleSize READ sampleSize WRITE setSampleSize NOTIFY sampleSizeChanged)
47
48 public:
49 enum WindowFunction
50 {
51 Rectangular,
52 Hann,
53 Nuttall,
54 Lanczos,
55 Sine
56 };
57 Q_ENUM(WindowFunction)
58
59 static const int DEMO_INTERVAL = 20; // ~50 fps
60
61 ~Base() override;
62
63 qreal maxFreq() const { return m_maxFreq; }
64 void setMaxFreq( qreal maxFreq );
65 qreal minFreq() const { return m_minFreq; }
66 void setMinFreq( qreal minFreq );
67 WindowFunction windowFunction() const;
68 void setWindowFunction( WindowFunction windowFunction );
69 int sampleSize() const;
70 void setSampleSize( uint sampleSize );
71
72 /**
73 * Returns the worker object associated with this analyzer.
74 */
75 const Worker* worker() const;
76
77 Q_SIGNALS:
78 void minFreqChanged();
79 void maxFreqChanged();
80 void scopeSizeChanged( int );
81 void windowFunctionChanged( WindowFunction );
82 void sampleSizeChanged( uint );
83 void calculateExpFactorNeeded( qreal, qreal, int );
84
85 protected:
86 Base( QQuickItem* );
87
88 /**
89 * Creates a new worker instance.
90 * Subclasses must implement this function.
91 * All compute heavy tasks should be offloaded to the created worker.
92 * If you make any connections with your worker, remember to make them queued connections.
93 * Do not set a parent for the worker. Base will take ownership of it.
94 */
95 virtual Worker* createWorker() const = 0;
96
97 /**
98 * Returns the standard KConfigGroup for all analyzers.
99 * You can reimplement this function, if you want your subclass to have a different config.
100 */
101 virtual KConfigGroup config() const;
102
103 /**
104 * Use this function to set the size for the scope computed by the worker.
105 */
106 void setScopeSize( int size );
107
108 /**
109 * Use this function to pause audio data processing and analyzer updating
110 */
111 void drawNeedChanged( const bool );
112 private:
113 void connectSignals();
114 void disconnectSignals();
115 void refreshSampleRate();
116
117 double m_minFreq, m_maxFreq;
118 int m_sampleRate;
119 int m_scopeSize;
120
121 Worker *m_worker;
122 QThread m_workerThread;
123 };
124
125
126 } //END namespace Analyzer
127
128 #endif