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.

173 lines
4.4KB

  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. class Euclidean;
  42. const uint8_t kMaxRegisters = 16;
  43. enum SwitchIndex {
  44. SWITCH_ADD_FRAME,
  45. SWITCH_DELETE_FRAME
  46. };
  47. enum UiMode {
  48. UI_MODE_SPLASH,
  49. UI_MODE_FEATURE_SWITCH,
  50. UI_MODE_NORMAL,
  51. UI_MODE_SAVE_CONFIRMATION,
  52. UI_MODE_ERASE_CONFIRMATION,
  53. UI_MODE_EDIT_RESPONSE,
  54. UI_MODE_EDIT_EASING,
  55. UI_MODE_FACTORY_TESTING,
  56. UI_MODE_EDIT_LENGTH,
  57. UI_MODE_EDIT_SHAPE,
  58. };
  59. class Ui {
  60. public:
  61. Ui() { }
  62. ~Ui() { }
  63. void Init(Keyframer* keyframer, PolyLfo* poly_lfo, Euclidean euclidean[kNumChannels]);
  64. void Poll();
  65. void DoEvents();
  66. void FlushEvents();
  67. void TryCalibration();
  68. inline uint16_t frame() const {
  69. return adc_.value(kFrameAdcChannel);
  70. }
  71. inline uint16_t frame_modulation() const {
  72. return adc_.value(kFrameModulationAdcChannel);
  73. }
  74. inline UiMode mode() const {
  75. return mode_;
  76. }
  77. enum FeatureMode {
  78. FEAT_MODE_KEYFRAMER,
  79. FEAT_MODE_KEYFRAME_LOOPER,
  80. FEAT_MODE_SEQ_MAIN,
  81. FEAT_MODE_SEQ_SHIFT_REGISTER,
  82. FEAT_MODE_SEQ_STEP_EDIT,
  83. FEAT_MODE_POLY_LFO,
  84. FEAT_MODE_EUCLIDEAN,
  85. };
  86. inline FeatureMode feature_mode() const {
  87. return feature_mode_;
  88. }
  89. uint8_t sequencer_step;
  90. uint8_t sequencer_random;
  91. uint8_t step_divider;
  92. uint8_t shift_divider;
  93. uint8_t step_random;
  94. uint8_t shift_random;
  95. uint8_t feedback_random;
  96. uint16_t shift_register[kMaxRegisters];
  97. uint8_t active_registers;
  98. KeyframeLed keyframe_led_;
  99. RgbLed rgb_led_;
  100. private:
  101. void OnSwitchPressed(const stmlib::Event& e);
  102. void OnSwitchReleased(const stmlib::Event& e);
  103. void OnPotChanged(const stmlib::Event& e);
  104. void ParseShiftSequencer(uint16_t control_id, int32_t data);
  105. void ParsePolyLFO(uint16_t control_id, int32_t data);
  106. void ParseEuclidean(uint16_t control_id, int32_t data);
  107. // Force the gain value of the 4 channels to match that of the 4 pots.
  108. void SyncWithPots();
  109. void SyncWithPotsShiftSequencer();
  110. void SyncWithPotsPolyLFO();
  111. void SyncWithPotsEuclidean();
  112. void FindNearestKeyframe();
  113. stmlib::EventQueue<32> queue_;
  114. uint16_t adc_value_[kNumAdcChannels];
  115. uint16_t adc_filtered_value_[kNumAdcChannels];
  116. uint32_t press_time_[kNumSwitches];
  117. bool detect_very_long_press_[kNumSwitches];
  118. ChannelLeds channel_leds_;
  119. Switches switches_;
  120. Adc adc_;
  121. FactoryTestingSwitch factory_testing_switch_;
  122. UiMode mode_;
  123. Keyframer* keyframer_;
  124. PolyLfo* poly_lfo_;
  125. Euclidean* euclidean_;
  126. int16_t active_keyframe_;
  127. int16_t active_channel_;
  128. int16_t active_slot_;
  129. bool active_keyframe_lock_;
  130. FeatureMode feature_mode_;
  131. uint16_t animation_counter_;
  132. uint16_t keyframe_led_pwm_counter_;
  133. uint8_t ignore_releases_;
  134. bool test_led_;
  135. DISALLOW_COPY_AND_ASSIGN(Ui);
  136. };
  137. } // namespace frames
  138. #endif // FRAMES_UI_H_