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 ENVELOP_H
26 #define ENVELOP_H
27 
28 #include <QMap>
29 #include <QColor>
30 class QCPGraph;
31 
32 class Envelop
33 {
34 public:
35     enum ValueType {
36         DELAY,
37         ATTACK,
38         HOLD,
39         DECAY,
40         SUSTAIN,
41         RELEASE,
42         KEYNUM_TO_HOLD,
43         KEYNUM_TO_DECAY,
44         KEY_MIN,
45         KEY_MAX
46     };
47 
48     Envelop(QCPGraph * graph1, QCPGraph *graph2);
49 
50     // Set a property of the envelop
51     void set(ValueType type, double value, bool defined);
52 
53     // Set the color of the envelop
setColor(QColor color)54     void setColor(QColor color) { _color = color; }
55 
56     // True if the envelop is thick
setThick(bool isThick)57     void setThick(bool isThick) { _isThick = isThick; }
58 
59     // Get the graph used by the envelop
graph1()60     QCPGraph * graph1() { return _graph1; }
graph2()61     QCPGraph * graph2() { return _graph2; }
62 
63     // Get the attack duration (delay + attack + hold + decay)
64     double getAttackDuration();
65 
66     // Get the release duration
67     double getReleaseDuration();
68 
69     // Draw the envelop on the graph
70     void draw(double triggeredKeyDuration, double releasedKeyDuration);
71 
72 private:
73     double getValueForKey(double value, double keyModifier, int key);
74     QMap<ValueType, double> _values;
75     QMap<ValueType, bool> _defined;
76     QColor _color;
77     bool _isThick;
78     QCPGraph * _graph1, * _graph2;
79 };
80 
81 #endif // ENVELOP_H
82