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 SPINBOXRANGE_H
26 #define SPINBOXRANGE_H
27 
28 #include <QAbstractSpinBox>
29 
30 class SpinBoxRange : public QAbstractSpinBox
31 {
32     Q_OBJECT
33 
34 public:
35     SpinBoxRange(QWidget * parent);
36     ~SpinBoxRange() {}
37 
38     // QAbstractSpinBox virtual members
39     virtual void stepBy(int steps);
40     virtual QValidator::State validate(QString& input, int& pos) const;
41 
42     int getValMin();
43     int getValMax();
44     void setText(QString text);
45 
46     static QString SEPARATOR;
47 
48 public slots:
49     virtual void clear();
50 
51 signals:
52     void valueChanged();
53 
54 protected:
55     virtual StepEnabled stepEnabled() const;
56     virtual QString getText(int value) const = 0;
57     virtual int getValue(QString &text, bool &ok) const = 0;
58     void formatText();
59 
60 private slots:
61     void updateValue();
62     void onKeyPlayed(int key, int vel);
63 
64 private:
65     enum SpinboxSection
66     {
67         SectionMin,
68         SectionMax,
69         SectionNone
70     };
71     SpinboxSection getCurrentSection() const;
72     void stringToRange(QString input, int &valMin, int &valMax, QValidator::State &state) const;
73     static int MINI;
74     static int MAXI;
75     int _valMin, _valMax;
76     int _firstMidiKey;
77 };
78 
79 class SpinBoxVelocityRange : public SpinBoxRange
80 {
81     Q_OBJECT
82 
83 public:
84     SpinBoxVelocityRange(QWidget * parent) : SpinBoxRange(parent) {formatText();}
85     ~SpinBoxVelocityRange() {}
86 
87 protected:
88     virtual QString getText(int value) const;
89     virtual int getValue(QString &text, bool &ok) const;
90 };
91 
92 class SpinBoxKeyRange : public SpinBoxRange
93 {
94     Q_OBJECT
95 
96 public:
97     SpinBoxKeyRange(QWidget * parent) : SpinBoxRange(parent) {formatText();}
98     ~SpinBoxKeyRange() {}
99 
100 protected:
101     virtual QString getText(int value) const;
102     virtual int getValue(QString &text, bool &ok) const;
103 };
104 
105 #endif // SPINBOXRANGE_H
106