1 // Copyright 2016 Emilie Gillet.
2 //
3 // Author: Emilie Gillet (emilie.o.gillet@gmail.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 //
23 // See http://creativecommons.org/licenses/MIT/ for more information.
24 //
25 // -----------------------------------------------------------------------------
26 //
27 // Settings storage.
28 
29 #include "plaits/settings.h"
30 
31 #include <algorithm>
32 
33 #include "stmlib/system/storage.h"
34 
35 namespace plaits {
36 
37 using namespace std;
38 
Init()39 bool Settings::Init() {
40   ChannelCalibrationData* c = persistent_data_.channel_calibration_data;
41   c[CV_ADC_CHANNEL_MODEL].offset = 0.025f;
42   c[CV_ADC_CHANNEL_MODEL].scale = -1.03f;
43   c[CV_ADC_CHANNEL_MODEL].normalization_detection_threshold = 0;
44 
45   c[CV_ADC_CHANNEL_V_OCT].offset = 25.71;
46   c[CV_ADC_CHANNEL_V_OCT].scale = -60.0f;
47   c[CV_ADC_CHANNEL_V_OCT].normalization_detection_threshold = 0;
48 
49   c[CV_ADC_CHANNEL_FM].offset = 0.0f;
50   c[CV_ADC_CHANNEL_FM].scale = -60.0f;
51   c[CV_ADC_CHANNEL_FM].normalization_detection_threshold = -2945;
52 
53   c[CV_ADC_CHANNEL_HARMONICS].offset = 0.0f;
54   c[CV_ADC_CHANNEL_HARMONICS].scale = -1.0f;
55   c[CV_ADC_CHANNEL_HARMONICS].normalization_detection_threshold = 0;
56 
57   c[CV_ADC_CHANNEL_TIMBRE].offset = 0.0f;
58   c[CV_ADC_CHANNEL_TIMBRE].scale = -1.6f;
59   c[CV_ADC_CHANNEL_TIMBRE].normalization_detection_threshold = -2945;
60 
61   c[CV_ADC_CHANNEL_MORPH].offset = 0.0f;
62   c[CV_ADC_CHANNEL_MORPH].scale = -1.6f;
63   c[CV_ADC_CHANNEL_MORPH].normalization_detection_threshold = -2945;
64 
65   c[CV_ADC_CHANNEL_TRIGGER].offset = 0.4f;
66   c[CV_ADC_CHANNEL_TRIGGER].scale = -0.6f;
67   c[CV_ADC_CHANNEL_TRIGGER].normalization_detection_threshold = 13663;
68 
69   c[CV_ADC_CHANNEL_LEVEL].offset = 0.49f;
70   c[CV_ADC_CHANNEL_LEVEL].scale = -0.6f;
71   c[CV_ADC_CHANNEL_LEVEL].normalization_detection_threshold = 21403;
72 
73   state_.engine = 0;
74   state_.lpg_colour = 0;
75   state_.decay = 128;
76   state_.octave = 255;
77   state_.color_blind = 0;
78 
79   bool success = chunk_storage_.Init(&persistent_data_, &state_);
80 
81   CONSTRAIN(state_.engine, 0, 15);
82 
83   return success;
84 }
85 
SavePersistentData()86 void Settings::SavePersistentData() {
87   chunk_storage_.SavePersistentData();
88 }
89 
SaveState()90 void Settings::SaveState() {
91   chunk_storage_.SaveState();
92 }
93 
94 }  // namespace plaits
95