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.

134 lines
3.3KB

  1. // Copyright 2013 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. // User interface.
  28. #ifndef STREAMS_UI_H_
  29. #define STREAMS_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "streams/audio_cv_meter.h"
  33. #include "streams/cv_scaler.h"
  34. #include "streams/drivers/leds.h"
  35. #include "streams/drivers/switches.h"
  36. namespace streams {
  37. enum DisplayMode {
  38. DISPLAY_MODE_FUNCTION,
  39. DISPLAY_MODE_MONITOR,
  40. DISPLAY_MODE_MONITOR_FUNCTION
  41. };
  42. enum MonitorMode {
  43. MONITOR_MODE_EXCITE_IN,
  44. MONITOR_MODE_VCA_CV,
  45. MONITOR_MODE_AUDIO_IN,
  46. MONITOR_MODE_OUTPUT,
  47. MONITOR_MODE_LAST
  48. };
  49. enum Switch {
  50. SWITCH_MODE_1,
  51. SWITCH_MODE_2,
  52. SWITCH_MONITOR,
  53. SWITCH_LAST
  54. };
  55. struct UiSettings {
  56. uint8_t function[kNumChannels];
  57. uint8_t alternate[kNumChannels];
  58. uint8_t monitor_mode;
  59. uint8_t linked;
  60. uint8_t padding[2];
  61. };
  62. class Processor;
  63. class Ui {
  64. public:
  65. Ui() { }
  66. ~Ui() { }
  67. void Init(Adc* adc, CvScaler* cv_scaler, Processor* processors);
  68. void Poll();
  69. void DoEvents();
  70. void FlushEvents();
  71. inline bool calibrating() const {
  72. return calibrating_;
  73. }
  74. private:
  75. // Synchronize UI state of channels 1 & 2.
  76. void Link(uint8_t channel);
  77. void OnSwitchPressed(const stmlib::Event& e);
  78. void OnSwitchReleased(const stmlib::Event& e);
  79. void OnPotMoved(const stmlib::Event& e);
  80. void SaveState();
  81. void PaintLeds();
  82. void PaintTestStatus();
  83. void PaintMonitor(uint8_t channel);
  84. void PaintAdaptive(uint8_t channel, int32_t sample, int32_t db_offset);
  85. stmlib::EventQueue<16> queue_;
  86. Adc* adc_;
  87. CvScaler* cv_scaler_;
  88. Processor* processor_;
  89. Leds leds_;
  90. Switches switches_;
  91. uint32_t press_time_[kNumSwitches];
  92. DisplayMode display_mode_[kNumChannels];
  93. MonitorMode monitor_mode_;
  94. bool calibrating_;
  95. bool factory_testing_;
  96. uint8_t show_offset_level_;
  97. UiSettings ui_settings_;
  98. uint16_t version_token_;
  99. uint8_t secret_handshake_counter_;
  100. int32_t pot_value_[kNumPots];
  101. int32_t pot_threshold_[kNumPots];
  102. AudioCvMeter meter_[kNumChannels];
  103. uint8_t divider_;
  104. DISALLOW_COPY_AND_ASSIGN(Ui);
  105. };
  106. } // namespace streams
  107. #endif // STREAMS_UI_H_