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 #include "toolglobalsettings_parameters.h"
26 #include "basetypes.h"
27 
loadConfiguration()28 void ToolGlobalSettings_parameters::loadConfiguration()
29 {
30     // Pattern
31     _instPattern = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "pattern", 0).toInt();
32     _prstPattern = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "pattern", 0).toInt();
33 
34     // Pattern parameter
35     _instParam = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "param", 50.).toDouble();
36     _prstParam = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "param", 50.).toDouble();
37 
38     // Min / max
39     _instMin = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "min", 0.).toDouble();
40     _prstMin = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "min", 0.).toDouble();
41     _instMax = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "max", 1.).toDouble();
42     _prstMax = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "max", 1.).toDouble();
43     _instMinX = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "minX", 0).toInt();
44     _prstMinX = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "minX", 0).toInt();
45     _instMaxX = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "maxX", 127).toInt();
46     _prstMaxX = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "maxX", 127).toInt();
47 
48     // Curve
49     _instValues = getStoredValues(ConfManager::TOOL_TYPE_INSTRUMENT);
50     _prstValues = getStoredValues(ConfManager::TOOL_TYPE_PRESET);
51 
52     // Modification type
53     _instModifType = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "modification", 0).toInt();
54     _prstModifType = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "modification", 0).toInt();
55 
56     // Attribute to change
57     _instAttribute = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "attribute", champ_initialAttenuation).toInt();
58     _prstAttribute = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "attribute", champ_initialAttenuation).toInt();
59 
60     // Min / max velocity
61     _instMinVel = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "minVel", 0).toInt();
62     _prstMinVel = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "minVel", 0).toInt();
63     _instMaxVel = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "maxVel", 127).toInt();
64     _prstMaxVel = ContextManager::configuration()->getToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "maxVel", 127).toInt();
65 }
66 
saveConfiguration()67 void ToolGlobalSettings_parameters::saveConfiguration()
68 {
69     // Pattern
70     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "pattern", _instPattern);
71     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "pattern", _prstPattern);
72 
73     // Pattern parameter
74     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "param", _instParam);
75     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "param", _prstParam);
76 
77     // Min / max
78     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "min", _instMin);
79     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "min", _prstMin);
80     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "max", _instMax);
81     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "max", _prstMax);
82     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "minX", _instMinX);
83     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "minX", _prstMinX);
84     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "maxX", _instMaxX);
85     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "maxX", _prstMaxX);
86 
87     // Curve
88     storeValues(_instValues, ConfManager::TOOL_TYPE_INSTRUMENT);
89     storeValues(_prstValues, ConfManager::TOOL_TYPE_PRESET);
90 
91     // Modification type
92     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "modification", _instModifType);
93     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "modification", _prstModifType);
94 
95     // Attribute to change
96     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "attribute", _instAttribute);
97     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "attribute", _prstAttribute);
98 
99     // Min / max velocity
100     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "minVel", _instMinVel);
101     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "minVel", _prstMinVel);
102     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_INSTRUMENT, "global", "maxVel", _instMaxVel);
103     ContextManager::configuration()->setToolValue(ConfManager::TOOL_TYPE_PRESET, "global", "maxVel", _prstMaxVel);
104 }
105 
getStoredValues(ConfManager::ToolType toolType)106 QVector<double> ToolGlobalSettings_parameters::getStoredValues(ConfManager::ToolType toolType)
107 {
108     QList<QVariant> listTmp = ContextManager::configuration()->getToolValue(toolType, "global", "values", QList<QVariant>()).toList();
109     QVector<double> vectRet;
110     vectRet.resize(listTmp.size());
111     for (int i = 0; i < listTmp.size(); i++)
112         vectRet[i] = listTmp.at(i).toDouble();
113     return vectRet;
114 }
115 
storeValues(QVector<double> values,ConfManager::ToolType toolType)116 void ToolGlobalSettings_parameters::storeValues(QVector<double> values, ConfManager::ToolType toolType)
117 {
118     QVariantList listTmp;
119     for (int i = 0; i < values.size(); i++)
120         listTmp << values.at(i);
121     ContextManager::configuration()->setToolValue(toolType, "global", "values", listTmp);
122 }
123