You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3KB

  1. // Copyright 2015 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.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. #include "rings/settings.h"
  29. #include "stmlib/system/storage.h"
  30. namespace rings {
  31. stmlib::Storage<1> storage;
  32. void Settings::Init() {
  33. freshly_baked_ = false;
  34. if (!storage.ParsimoniousLoad(&data_, &version_token_)) {
  35. data_.calibration_data.pitch_offset = 66.67f;
  36. data_.calibration_data.pitch_scale = -84.26f;
  37. for (size_t i = 0; i < ADC_CHANNEL_NUM_OFFSETS; ++i) {
  38. data_.calibration_data.offset[i] = 0.505f;
  39. }
  40. data_.state.polyphony = 1;
  41. data_.state.model = 0;
  42. data_.state.easter_egg = 0;
  43. data_.calibration_data.normalization_detection_threshold = 0.75f;
  44. freshly_baked_ = true;
  45. Save();
  46. }
  47. if (data_.calibration_data.normalization_detection_threshold < 0.7f ||
  48. data_.calibration_data.normalization_detection_threshold > 0.8f) {
  49. data_.calibration_data.normalization_detection_threshold = 0.75f;
  50. }
  51. CONSTRAIN(data_.state.polyphony, 1, 4);
  52. CONSTRAIN(data_.state.model, 0, 5);
  53. }
  54. void Settings::Save() {
  55. storage.ParsimoniousSave(data_, &version_token_);
  56. }
  57. } // namespace rings