Updated SWH plugins and added missing hermes_filter plugin
[lmms/mlankhorst.git] / include / graph.h
blob9be552f33c4663fa7177ec85ef4109dd7a4e1443
1 /*
2 * graph.h - a QT widget for displaying and manipulating waveforms
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 Linux MultiMedia Studio - http://lmms.sourceforge.net
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.
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.
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.
27 #ifndef _GRAPH_H
28 #define _GRAPH_H
30 #include <QtGui/QWidget>
31 #include <QtGui/QPixmap>
32 #include <QtGui/QCursor>
34 #include "Model.h"
35 #include "ModelView.h"
36 #include "lmms_basics.h"
38 class graphModel;
41 class EXPORT graph : public QWidget, public ModelView
43 Q_OBJECT
44 public:
45 enum graphStyle
47 NearestStyle,
48 LinearStyle,
49 NumGraphStyles
52 graph( QWidget * _parent, graphStyle _style = graph::LinearStyle );
53 virtual ~graph();
55 void setForeground( const QPixmap & _pixmap );
57 void setGraphColor( const QColor );
59 inline graphModel * model()
61 return castModel<graphModel>();
64 inline graphStyle getGraphStyle()
66 return m_graphStyle;
69 inline void setGraphStyle( graphStyle _s )
71 m_graphStyle = _s;
72 update();
76 protected:
77 virtual void paintEvent( QPaintEvent * _pe );
78 virtual void dropEvent( QDropEvent * _de );
79 virtual void dragEnterEvent( QDragEnterEvent * _dee );
80 virtual void mousePressEvent( QMouseEvent * _me );
81 virtual void mouseMoveEvent( QMouseEvent * _me );
82 virtual void mouseReleaseEvent( QMouseEvent * _me );
84 protected slots:
85 void updateGraph( int _startPos, int _endPos );
86 void updateGraph();
88 private:
89 virtual void modelChanged();
91 void changeSampleAt(int _x, int _y);
94 QPixmap m_foreground;
95 QColor m_graphColor;
97 graphModel * m_graphModel;
98 graphStyle m_graphStyle;
100 bool m_mouseDown;
101 int m_lastCursorX;
106 class EXPORT graphModel : public Model
108 Q_OBJECT
109 public:
110 graphModel( float _min,
111 float _max,
112 int _size,
113 :: Model * _parent,
114 bool _default_constructed = false,
115 float _step = 0.0 );
117 virtual ~graphModel();
119 // TODO: saveSettings, loadSettings?
121 inline float minValue() const
123 return( m_minValue );
126 inline float maxValue() const
128 return( m_maxValue );
131 inline int length() const
133 return( m_samples.count() );
136 inline const float * samples() const
138 return( m_samples.data() );
141 public slots:
142 void setRange( float _min, float _max );
144 void setLength( int _size );
146 void setSampleAt( int _samplePos, float _value );
147 void setSamples( const float * _value );
149 void setWaveToSine();
150 void setWaveToTriangle();
151 void setWaveToSaw();
152 void setWaveToSquare();
153 void setWaveToNoise();
154 //void setWaveToUser( );
156 void smooth();
157 void normalize();
159 signals:
160 void lengthChanged();
161 void samplesChanged( int startPos, int endPos );
162 void rangeChanged();
164 private:
166 QVector<float> m_samples;
167 float m_minValue;
168 float m_maxValue;
169 float m_step;
171 friend class graph;
175 #endif