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 GRAPHICSVIEWENVELOPS_H
26 #define GRAPHICSVIEWENVELOPS_H
27 
28 #include "qcustomplot.h"
29 #include "soundfontmanager.h"
30 #include "envelop.h"
31 
32 class GraphicsViewEnvelop : public QCustomPlot
33 {
34     Q_OBJECT
35 
36 public:
37     explicit GraphicsViewEnvelop(QWidget *parent = nullptr);
38     ~GraphicsViewEnvelop();
39 
40     // Link the scroll bar
41     void linkSliderX(QScrollBar * _qScrollX);
42 
43     // Clear all envelops
44     void clearEnvelops();
45 
46     // Prepare an envelop and return the index
47     int addEnvelop();
48 
49     // Set the value of an envelop
50     void setValue(int index, Envelop::ValueType type, double value, bool isDefined = true);
51     void setKeyRange(int index, int keyMin, int keyMax);
52     void setSample(QVector<double> data, int sampleRate, int loopMode, int startLoop, int endLoop);
53 
54     // Set the style of an envelop
55     void setEnvelopStyle(int index, bool isGlobal, bool isVolume, bool isMain);
56 
57     // Compute all points of all envelops
58     void drawEnvelops();
59     void zoomDrag();
60 
61 public slots:
62     void setPosX(int _posX);
63 
64 signals:
65     void valueChanged(int index, int type, double value, bool isDefined);
66 
67 protected:
68     void paintEvent(QPaintEvent *event);
69     void mousePressEvent(QMouseEvent *event);
70     void mouseReleaseEvent(QMouseEvent *event);
71     void mouseMoveEvent(QMouseEvent *event);
mouseDoubleClickEvent(QMouseEvent *)72     void mouseDoubleClickEvent(QMouseEvent *) {}
73     void wheelEvent(QWheelEvent *event);
74     void resizeEvent(QResizeEvent *event);
75 
76 private:
77     int _index;
78     QMap<int, Envelop *> _envelops;
79     bool _dontRememberScroll;
80     double _triggeredKeyDuration, _releasedKeyDuration;
81     int _posReleaseLine;
82     QPen _releaseLinePen;
83     QImage _imageNoteOn, _imageNoteOff;
84 
85     double _sizeX;
86     bool _zoomFlag;
87     bool _dragFlag;
88     double _xInit, _yInit;
89     double _zoomX, _posX;
90     double _zoomXinit, _posXinit;
91     bool _bFromExt;
92     QScrollBar * _qScrollX;
93     QCPItemText * _textPositionL;
94     QCPItemText * _textPositionR;
95     QSharedPointer<QCPAxisTickerFixed> _fixedTicker;
96 
97     double getTickStep();
98     void updateStyle();
99     void zoom(QPoint point);
100     void drag(QPoint point);
101     void setZoomLine(double x1, double y1, double x2, double y2);
102     void displayCurrentRange();
103 };
104 
105 #endif // GRAPHICSVIEWENVELOPS_H
106