lmms
Cross-platform music production software
Loading...
Searching...
No Matches
Graph.h
Go to the documentation of this file.
1/*
2 * Graph.h - a QT widget for displaying and manipulating waveforms
3 *
4 * Copyright (c) 2006-2007 Andreas Brandmaier <andy/at/brandmaier/dot/de>
5 * 2008 Paul Giblock <drfaygo/at/gmail/dot/com>
6 *
7 * This file is part of LMMS - https://lmms.io
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program (see COPYING); if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA.
23 *
24 */
25
26#ifndef LMMS_GUI_GRAPH_H
27#define LMMS_GUI_GRAPH_H
28
29#include <QWidget>
30#include <QPixmap>
31#include <QCursor>
32
33#include "Model.h"
34#include "ModelView.h"
35#include "LmmsTypes.h"
36
37namespace lmms
38{
39
40
41class graphModel;
42
43namespace gui
44{
45
46
47class LMMS_EXPORT Graph : public QWidget, public ModelView
48{
49 Q_OBJECT
50public:
51 enum class Style
52 {
53 Nearest,
54 Linear,
55 LinearNonCyclic,
56 Bar,
57 };
58
63 Graph(
64 QWidget* parent,
65 Style style = Style::Linear,
66 int width = 132,
67 int height = 104
68 );
69 ~Graph() override = default;
70
71 void setForeground( const QPixmap & _pixmap );
72
73
74 void setGraphColor( const QColor );
75
76 inline graphModel * model()
77 {
78 return castModel<graphModel>();
79 }
80
82 {
83 return m_graphStyle;
84 }
85
86
87 inline void setGraphStyle( Style _s )
88 {
89 m_graphStyle = _s;
90 update();
91 }
92
93signals:
94 void drawn();
95protected:
96 void paintEvent( QPaintEvent * _pe ) override;
97 void dropEvent( QDropEvent * _de ) override;
98 void dragEnterEvent( QDragEnterEvent * _dee ) override;
99 void mousePressEvent( QMouseEvent * _me ) override;
100 void mouseMoveEvent( QMouseEvent * _me ) override;
101 void mouseReleaseEvent( QMouseEvent * _me ) override;
102
103protected slots:
104 void updateGraph( int _startPos, int _endPos );
105 void updateGraph();
106
107private:
108 void modelChanged() override;
109
110 void changeSampleAt( int _x, int _y );
111 void drawLineAt( int _x, int _y, int _lastx );
112
113
116
118
121
122} ;
123
124
125} // namespace gui
126
127
134class LMMS_EXPORT graphModel : public Model
135{
136 Q_OBJECT
137public:
143 // TODO: @param _parent
144 // TODO: @param _default_constructed
145 graphModel( float _min,
146 float _max,
147 int _size,
148 Model * _parent,
149 bool _default_constructed = false,
150 float _step = 0.0 );
151
152 ~graphModel() override = default;
153
154 // TODO: saveSettings, loadSettings?
155
156 inline float minValue() const
157 {
158 return( m_minValue );
159 }
160
161 inline float maxValue() const
162 {
163 return( m_maxValue );
164 }
165
166 inline int length() const
167 {
168 return m_length;
169 }
170
171 inline const float * samples() const
172 {
173 return( m_samples.data() );
174 }
175
180 void convolve(const float *convolution,
181 const int convolutionLength, const int centerOffset);
182
183public slots:
185 void setRange(float ymin, float ymax);
186
187 void setLength( int _size );
189 void setSampleAt( int x, float val );
191 void setSamples( const float * _value );
192
193 void setWaveToSine();
194 void setWaveToTriangle();
195 void setWaveToSaw();
196 void setWaveToSquare();
197 void setWaveToNoise();
198 QString setWaveToUser();
199
200 void smooth();
201 void smoothNonCyclic();
202 void normalize();
203 void invert();
204 void shiftPhase( int _deg );
205 void clear();
206 void clearInvisible();
207
208signals:
210 void samplesChanged( int startPos, int endPos );
212
213private:
214 void drawSampleAt( int x, float val );
215
216 QVector<float> m_samples;
220 float m_step;
221
222 friend class gui::Graph;
223
224};
225
226
227} // namespace lmms
228
229#endif // LMMS_GUI_GRAPH_H
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
2 dimensional function plot
Definition Graph.h:135
float m_step
Definition Graph.h:220
void drawSampleAt(int x, float val)
Definition Graph.cpp:731
const float * samples() const
Definition Graph.h:171
QVector< float > m_samples
Definition Graph.h:216
float m_maxValue
Definition Graph.h:219
float m_minValue
Definition Graph.h:218
void samplesChanged(int startPos, int endPos)
float minValue() const
Definition Graph.h:156
graphModel(float _min, float _max, int _size, Model *_parent, bool _default_constructed=false, float _step=0.0)
Definition Graph.cpp:466
int length() const
Definition Graph.h:166
float maxValue() const
Definition Graph.h:161
~graphModel() override=default
int m_length
Definition Graph.h:217
Definition Graph.h:48
void drawLineAt(int _x, int _y, int _lastx)
Definition Graph.cpp:186
Graph(QWidget *parent, Style style=Style::Linear, int width=132, int height=104)
Definition Graph.cpp:40
void paintEvent(QPaintEvent *_pe) override
Definition Graph.cpp:292
QPixmap m_foreground
Definition Graph.h:114
graphModel * model()
Definition Graph.h:76
void setGraphStyle(Style _s)
Definition Graph.h:87
void setGraphColor(const QColor)
Definition Graph.cpp:68
Style getGraphStyle()
Definition Graph.h:81
QColor m_graphColor
Definition Graph.h:115
bool m_mouseDown
Definition Graph.h:119
void modelChanged() override
Definition Graph.cpp:439
void setForeground(const QPixmap &_pixmap)
Definition Graph.cpp:63
void mouseMoveEvent(QMouseEvent *_me) override
Definition Graph.cpp:101
void mousePressEvent(QMouseEvent *_me) override
Definition Graph.cpp:150
void updateGraph(int _startPos, int _endPos)
Definition Graph.cpp:451
void dragEnterEvent(QDragEnterEvent *_dee) override
Definition Graph.cpp:428
Style
Definition Graph.h:52
void mouseReleaseEvent(QMouseEvent *_me) override
Definition Graph.cpp:278
void dropEvent(QDropEvent *_de) override
Definition Graph.cpp:415
int m_lastCursorX
Definition Graph.h:120
Style m_graphStyle
Definition Graph.h:117
void changeSampleAt(int _x, int _y)
Definition Graph.cpp:251
~Graph() override=default
ModelView(Model *model, QWidget *widget)
Definition ModelView.cpp:33
T * castModel()
Definition ModelView.h:54
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34
int normalize(const float *abs_spectrum, float *norm_spectrum, unsigned int bin_count, unsigned int block_size)
Definition fft_helpers.cpp:65