1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2020 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #ifndef GRAPHICSWAVE_H
26 #define GRAPHICSWAVE_H
27 
28 #include <QWidget>
29 #include <QDateTime>
30 class QScrollBar;
31 class QSpinBox;
32 class GraphicsWavePainter;
33 
34 class GraphicsWave : public QWidget
35 {
36     Q_OBJECT
37 public:
38     explicit GraphicsWave(QWidget *parent = nullptr);
39     ~GraphicsWave() override;
40 
41     void setData(QByteArray baData, quint32 sampleRate);
42     void linkSliderX(QScrollBar * qScrollX);
43     void linkSpinBoxes(QSpinBox * spinStart, QSpinBox * spinEnd);
44     void displayMultipleSelection(bool isOn);
45 
46 public slots:
47     void setPosX(int posX);
48     void setStartLoop(int pos, bool repaint = true);
49     void setEndLoop(int pos, bool repaint = true);
50     void setCurrentSample(quint32 pos);
51 
52 signals:
53     void startLoopChanged();
54     void endLoopChanged();
55     void cutOrdered(int start, int end);
56 
57 protected:
58     void paintEvent(QPaintEvent *event) override;
59     void mousePressEvent(QMouseEvent *event) override;
60     void mouseReleaseEvent(QMouseEvent *event) override;
61     void mouseMoveEvent(QMouseEvent *event) override;
62     void wheelEvent(QWheelEvent *event) override;
63 
64 private:
65     int getSamplePosX(double zoomX, double shiftX, double x);
66     void zoom(QPoint point);
67     void drag(QPoint point);
68 
69     GraphicsWavePainter * _wavePainter;
70 
71     // Zoom & position
72     double _x, _y, _zoomX, _zoomY, _posX;
73     double _xInit, _yInit, _zoomXinit, _zoomYinit, _posXinit;
74     bool _zoomFlag;
75     bool _dragFlag;
76     bool _cutFlag;
77     bool _modifiedFlag;
78     double _sizeX;
79 
80     // Input data properties
81     quint32 _sampleSize;
82     quint32 _sampleRate;
83 
84     // Loop, playback position
85     quint32 _startLoop, _endLoop, _currentPosition;
86     QDateTime _lastPositionUpdate;
87 
88     bool _multipleSelection;
89     QScrollBar * _qScrollX;
90     QSpinBox * _spinStart;
91     QSpinBox * _spinEnd;
92     bool _bFromExt;
93 
94     // Style
95     QColor _redColor, _greenColor, _backgroundColor, _textColor;
96     QFont _textFont;
97 
98     static const int TEXT_MARGIN;
99     static const int OVERLAY_SIZE;
100 };
101 
102 #endif // GRAPHICSWAVE_H
103