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 TOOLMIXTURECREATION_PARAMETERS_H
26 #define TOOLMIXTURECREATION_PARAMETERS_H
27 
28 #include "abstracttoolparameters.h"
29 #include <QList>
30 #include <QString>
31 #include "qmath.h"
32 
33 class RankInfo
34 {
35 public:
36     RankInfo(int overtoneType, int octave) :
37         _overtoneType(overtoneType),
38         _octave(octave)
39     {}
40 
41     // 1 is fundamental or octave, 3 is for a fifth (frequency * 3), 5 is approximately a third (frequency * 5), ...
42     int getOvertoneType() { return _overtoneType; }
43     void setOvertoneType(int overtoneType) { _overtoneType = overtoneType; }
44 
45     // 0 is based on the fundamental, 1 one octave higher, -1 one octave lower, ...
46     int getOctave() { return _octave; }
47     void setOctave(int octave) { _octave = octave; }
48 
49     double getOffset()
50     {
51         // Compute multiple of the fundamental frequency
52         double multiple = (double)(2 * _overtoneType + 1) * pow(2.0f, _octave - 3);
53 
54         // Return the number of semi-tones to add to the fundamental for having the harmonic
55         return 12. * qLn(multiple) / 0.69314718056;
56     }
57 
58 private:
59     int _overtoneType;
60     int _octave;
61 };
62 
63 class DivisionInfo
64 {
65 public:
66     DivisionInfo(int minKey, int maxKey) :
67         _minKey(minKey),
68         _maxKey(maxKey)
69     {}
70 
71     // Start of the division
72     int getMinKey() { return _minKey; }
73     void setMinKey(int minKey) { _minKey = minKey; }
74 
75     // End of the division
76     int getMaxKey() { return _maxKey; }
77     void setMaxKey(int maxKey) { _maxKey = maxKey; }
78 
79     // Add / remove a rank
80     void addRank(int overtoneType, int octave)
81     {
82         _ranks << RankInfo(overtoneType, octave);
83     }
84     void removeRank(int number)
85     {
86         _ranks.removeAt(number);
87     }
88 
89     // Get all ranks
90     QList<RankInfo>& getRanks() { return _ranks; }
91 
92 private:
93     int _minKey;
94     int _maxKey;
95     QList<RankInfo> _ranks;
96 };
97 
98 class ToolMixtureCreation_parameters: public AbstractToolParameters
99 {
100 public:
101     /// Load the configuration from the ini file
102     void loadConfiguration() override;
103 
104     /// Save the configuration in the ini file
105     void saveConfiguration() override;
106 
107     QString getInstrumentName() { return _instrumentName; }
108     void setInstrumentName(QString instrumentName) { _instrumentName = instrumentName; }
109 
110     int getDensityType() { return _densityType; }
111     void setDensityType(int densityType) { _densityType = densityType; }
112 
113     bool getStereoSample() { return _stereoSample; }
114     void setStereoSample(bool stereoSample) { _stereoSample = stereoSample; }
115 
116     bool getLoopSample() { return _loopSample; }
117     void setLoopSample(bool loopSample) { _loopSample = loopSample; }
118 
119     QList<DivisionInfo> getDivisions() { return _divisions; }
120     void setDivisions(QList<DivisionInfo> divisions) { _divisions = divisions; }
121 
122 private:
123     QString _instrumentName;
124     int _densityType;
125     bool _stereoSample;
126     bool _loopSample;
127     QList<DivisionInfo> _divisions;
128 };
129 
130 #endif // TOOLMIXTURECREATION_PARAMETERS_H
131