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.

144 lines
3.8KB

  1. // Copyright 2016 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. // UI and CV processing ("controller" and "view")
  28. #ifndef PLAITS_UI_H_
  29. #define PLAITS_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "plaits/drivers/cv_adc.h"
  32. #include "plaits/drivers/leds.h"
  33. #include "plaits/drivers/normalization_probe.h"
  34. #include "plaits/drivers/pots_adc.h"
  35. #include "plaits/drivers/switches.h"
  36. #include "plaits/dsp/voice.h"
  37. #include "plaits/pot_controller.h"
  38. #include "plaits/settings.h"
  39. namespace plaits {
  40. const int kNumNormalizedChannels = 5;
  41. const int kProbeSequenceDuration = 32;
  42. enum UiMode {
  43. UI_MODE_NORMAL,
  44. UI_MODE_DISPLAY_ALTERNATE_PARAMETERS,
  45. UI_MODE_DISPLAY_OCTAVE,
  46. UI_MODE_CALIBRATION_C1,
  47. UI_MODE_CALIBRATION_C3,
  48. UI_MODE_TEST,
  49. UI_MODE_ERROR
  50. };
  51. enum FactoryTestingCommand {
  52. FACTORY_TESTING_READ_POT,
  53. FACTORY_TESTING_READ_CV,
  54. FACTORY_TESTING_READ_GATE,
  55. FACTORY_TESTING_GENERATE_TEST_SIGNAL,
  56. FACTORY_TESTING_CALIBRATE,
  57. FACTORY_TESTING_READ_NORMALIZATION,
  58. };
  59. class Ui {
  60. public:
  61. Ui() { }
  62. ~Ui() { }
  63. void Init(Patch* patch, Modulations* modulations, Settings* settings);
  64. void Poll();
  65. void set_active_engine(int active_engine) {
  66. active_engine_ = active_engine;
  67. }
  68. inline bool test_mode() const {
  69. return mode_ == UI_MODE_TEST;
  70. }
  71. uint8_t HandleFactoryTestingRequest(uint8_t command);
  72. private:
  73. void UpdateLEDs();
  74. void ReadSwitches();
  75. void ProcessPotsHiddenParameters();
  76. void LoadState();
  77. void SaveState();
  78. void DetectNormalization();
  79. void StartCalibration();
  80. void CalibrateC1();
  81. void CalibrateC3();
  82. void RealignPots() {
  83. pots_[POTS_ADC_CHANNEL_TIMBRE_POT].Realign();
  84. pots_[POTS_ADC_CHANNEL_MORPH_POT].Realign();
  85. pots_[POTS_ADC_CHANNEL_HARMONICS_POT].Realign();
  86. }
  87. UiMode mode_;
  88. CvAdc cv_adc_;
  89. PotsAdc pots_adc_;
  90. Leds leds_;
  91. Switches switches_;
  92. int ui_task_;
  93. float transposition_;
  94. float octave_;
  95. Patch* patch_;
  96. Modulations* modulations_;
  97. NormalizationProbe normalization_probe_;
  98. PotController pots_[POTS_ADC_CHANNEL_LAST];
  99. float pitch_lp_;
  100. float pitch_lp_calibration_;
  101. Settings* settings_;
  102. int normalization_detection_count_;
  103. int normalization_detection_mismatches_[kNumNormalizedChannels];
  104. uint32_t normalization_probe_state_;
  105. int pwm_counter_;
  106. int press_time_[SWITCH_LAST];
  107. bool ignore_release_[SWITCH_LAST];
  108. int active_engine_;
  109. float cv_c1_; // For calibraiton
  110. static const CvAdcChannel normalized_channels_[kNumNormalizedChannels];
  111. DISALLOW_COPY_AND_ASSIGN(Ui);
  112. };
  113. } // namespace plaits
  114. #endif // PLAITS_UI_H_