LMMS
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
64 Graph( QWidget * _parent, Style _style = Style::Linear,
65 int _width = 132,
66 int _height = 104
67 );
68 ~Graph() override = default;
69
70 void setForeground( const QPixmap & _pixmap );
71
72
73 void setGraphColor( const QColor );
74
75 inline graphModel * model()
76 {
77 return castModel<graphModel>();
78 }
79
81 {
82 return m_graphStyle;
83 }
84
85
86 inline void setGraphStyle( Style _s )
87 {
88 m_graphStyle = _s;
89 update();
90 }
91
92signals:
93 void drawn();
94protected:
95 void paintEvent( QPaintEvent * _pe ) override;
96 void dropEvent( QDropEvent * _de ) override;
97 void dragEnterEvent( QDragEnterEvent * _dee ) override;
98 void mousePressEvent( QMouseEvent * _me ) override;
99 void mouseMoveEvent( QMouseEvent * _me ) override;
100 void mouseReleaseEvent( QMouseEvent * _me ) override;
101
102protected slots:
103 void updateGraph( int _startPos, int _endPos );
104 void updateGraph();
105
106private:
107 void modelChanged() override;
108
109 void changeSampleAt( int _x, int _y );
110 void drawLineAt( int _x, int _y, int _lastx );
111
112
115
117
120
121} ;
122
123
124} // namespace gui
125
126
133class LMMS_EXPORT graphModel : public Model
134{
135 Q_OBJECT
136public:
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
void normalize(fft_t *freqs)
Definition OscilGen.cpp:68
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
2 dimensional function plot
Definition Graph.h:134
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)
Constructor.
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
void paintEvent(QPaintEvent *_pe) override
Definition Graph.cpp:292
QPixmap m_foreground
Definition Graph.h:113
graphModel * model()
Definition Graph.h:75
void setGraphStyle(Style _s)
Definition Graph.h:86
void setGraphColor(const QColor)
Definition Graph.cpp:68
Style getGraphStyle()
Definition Graph.h:80
QColor m_graphColor
Definition Graph.h:114
bool m_mouseDown
Definition Graph.h:118
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
Graph(QWidget *_parent, Style _style=Style::Linear, int _width=132, int _height=104)
Constructor.
Definition Graph.cpp:40
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:119
Style m_graphStyle
Definition Graph.h:116
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
unsigned x[BMAX+1]
Definition inflate.c:1586
int val
Definition jpeglib.h:956
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35