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.

142 lines
3.5KB

  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. // Settings
  28. #ifndef FRAMES_UI_H_
  29. #define FRAMES_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "frames/drivers/adc.h"
  33. #include "frames/drivers/channel_leds.h"
  34. #include "frames/drivers/factory_testing_switch.h"
  35. #include "frames/drivers/keyframe_led.h"
  36. #include "frames/drivers/rgb_led.h"
  37. #include "frames/drivers/switches.h"
  38. namespace frames {
  39. class Keyframer;
  40. class PolyLfo;
  41. enum SwitchIndex {
  42. SWITCH_ADD_FRAME,
  43. SWITCH_DELETE_FRAME
  44. };
  45. enum UiMode {
  46. UI_MODE_SPLASH,
  47. UI_MODE_NORMAL,
  48. UI_MODE_SAVE_CONFIRMATION,
  49. UI_MODE_ERASE_CONFIRMATION,
  50. UI_MODE_EDIT_RESPONSE,
  51. UI_MODE_EDIT_EASING,
  52. UI_MODE_FACTORY_TESTING
  53. };
  54. class Ui {
  55. public:
  56. Ui() { }
  57. ~Ui() { }
  58. void Init(Keyframer* keyframer, PolyLfo* poly_lfo);
  59. void Poll();
  60. void DoEvents();
  61. void FlushEvents();
  62. void TryCalibration();
  63. inline uint16_t frame() const {
  64. return adc_.value(kFrameAdcChannel);
  65. }
  66. inline uint16_t frame_modulation() const {
  67. return adc_.value(kFrameModulationAdcChannel);
  68. }
  69. inline UiMode mode() const {
  70. return mode_;
  71. }
  72. inline bool sequencer_mode() const {
  73. return sequencer_mode_;
  74. }
  75. inline bool poly_lfo_mode() const {
  76. return poly_lfo_mode_;
  77. }
  78. private:
  79. void OnSwitchPressed(const stmlib::Event& e);
  80. void OnSwitchReleased(const stmlib::Event& e);
  81. void OnPotChanged(const stmlib::Event& e);
  82. // Force the gain value of the 4 channels to match that of the 4 pots.
  83. void SyncWithPots();
  84. void FindNearestKeyframe();
  85. stmlib::EventQueue<32> queue_;
  86. uint16_t adc_value_[kNumAdcChannels];
  87. uint16_t adc_filtered_value_[kNumAdcChannels];
  88. uint32_t press_time_[kNumSwitches];
  89. bool detect_very_long_press_[kNumSwitches];
  90. ChannelLeds channel_leds_;
  91. KeyframeLed keyframe_led_;
  92. RgbLed rgb_led_;
  93. Switches switches_;
  94. Adc adc_;
  95. FactoryTestingSwitch factory_testing_switch_;
  96. UiMode mode_;
  97. Keyframer* keyframer_;
  98. PolyLfo* poly_lfo_;
  99. int16_t active_keyframe_;
  100. int16_t active_channel_;
  101. bool active_keyframe_lock_;
  102. bool poly_lfo_mode_;
  103. bool sequencer_mode_;
  104. int8_t secret_handshake_counter_;
  105. uint16_t animation_counter_;
  106. uint16_t keyframe_led_pwm_counter_;
  107. bool test_led_;
  108. DISALLOW_COPY_AND_ASSIGN(Ui);
  109. };
  110. } // namespace frames
  111. #endif // FRAMES_UI_H_