123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- /*
- * Graph.h - a QT widget for displaying and manipulating waveforms
- *
- * Copyright (c) 2006-2007 Andreas Brandmaier <andy/at/brandmaier/dot/de>
- * 2008 Paul Giblock <drfaygo/at/gmail/dot/com>
- *
- * This file is part of LMMS - https://lmms.io
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program (see COPYING); if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- */
- #ifndef GRAPH_H
- #define GRAPH_H
- #include <QWidget>
- #include <QPixmap>
- #include <QCursor>
- #include "Model.h"
- #include "ModelView.h"
- #include "lmms_basics.h"
- class graphModel;
- class LMMS_EXPORT Graph : public QWidget, public ModelView
- {
- Q_OBJECT
- public:
- enum graphStyle
- {
- NearestStyle, //!< draw as stairs
- LinearStyle, //!< connect each 2 samples with a line, with wrapping
- LinearNonCyclicStyle, //!< LinearStyle without wrapping
- BarStyle, //!< draw thick bars
- NumGraphStyles
- };
- /**
- * @brief Constructor
- * @param _width Pixel width of widget
- * @param _height Pixel height of widget
- */
- Graph( QWidget * _parent, graphStyle _style = Graph::LinearStyle,
- int _width = 132,
- int _height = 104
- );
- virtual ~Graph() = default;
- void setForeground( const QPixmap & _pixmap );
- void setGraphColor( const QColor );
- inline graphModel * model()
- {
- return castModel<graphModel>();
- }
- inline graphStyle getGraphStyle()
- {
- return m_graphStyle;
- }
- inline void setGraphStyle( graphStyle _s )
- {
- m_graphStyle = _s;
- update();
- }
- signals:
- void drawn();
- protected:
- void paintEvent( QPaintEvent * _pe ) override;
- void dropEvent( QDropEvent * _de ) override;
- void dragEnterEvent( QDragEnterEvent * _dee ) override;
- void mousePressEvent( QMouseEvent * _me ) override;
- void mouseMoveEvent( QMouseEvent * _me ) override;
- void mouseReleaseEvent( QMouseEvent * _me ) override;
- protected slots:
- void updateGraph( int _startPos, int _endPos );
- void updateGraph();
- private:
- void modelChanged() override;
- void changeSampleAt( int _x, int _y );
- void drawLineAt( int _x, int _y, int _lastx );
- QPixmap m_foreground;
- QColor m_graphColor;
- graphStyle m_graphStyle;
- bool m_mouseDown;
- int m_lastCursorX;
- } ;
- /**
- @brief 2 dimensional function plot
- Function plot graph with discrete x scale and continous y scale
- This makes it possible to display "#x" samples
- */
- class LMMS_EXPORT graphModel : public Model
- {
- Q_OBJECT
- public:
- /**
- * @brief Constructor
- * @param _min Minimum y value to display
- * @param _max Maximum y value to display
- * @param _size Number of samples (e.g. x value)
- * @param _step Step size on y axis where values snap to, or 0.0f
- * for "no snapping"
- */
- graphModel( float _min,
- float _max,
- int _size,
- :: Model * _parent,
- bool _default_constructed = false,
- float _step = 0.0 );
- virtual ~graphModel() = default;
- // TODO: saveSettings, loadSettings?
- inline float minValue() const
- {
- return( m_minValue );
- }
- inline float maxValue() const
- {
- return( m_maxValue );
- }
- inline int length() const
- {
- return m_length;
- }
- inline const float * samples() const
- {
- return( m_samples.data() );
- }
- //! Make cyclic convolution
- //! @param convolution Samples to convolve with
- //! @param convolutionLength Number of samples to take for each sum
- //! @param centerOffset Offset for resulting values
- void convolve(const float *convolution,
- const int convolutionLength, const int centerOffset);
- public slots:
- //! Set range of y values
- void setRange( float _min, float _max );
- void setLength( int _size );
- //! Update one sample
- void setSampleAt( int x, float val );
- //! Update samples array
- void setSamples( const float * _value );
- void setWaveToSine();
- void setWaveToTriangle();
- void setWaveToSaw();
- void setWaveToSquare();
- void setWaveToNoise();
- QString setWaveToUser( );
- void smooth();
- void smoothNonCyclic();
- void normalize();
- void invert();
- void shiftPhase( int _deg );
- void clear();
- void clearInvisible();
- signals:
- void lengthChanged();
- void samplesChanged( int startPos, int endPos );
- void rangeChanged();
- private:
- void drawSampleAt( int x, float val );
- QVector<float> m_samples;
- int m_length;
- float m_minValue;
- float m_maxValue;
- float m_step;
- friend class Graph;
- };
- #endif
|