The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

126 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. */
  19. struct DrumPadGridProgram : public LEDGrid::Program
  20. {
  21. DrumPadGridProgram (LEDGrid&);
  22. //==============================================================================
  23. /** These let the program dim pads which aren't having gestures performed on them. */
  24. void startTouch (float startX, float startY);
  25. void endTouch (float startX, float startY);
  26. /** Creates trail effects similar to the onscreen pad trails. */
  27. void sendTouch (float x, float y, float z, LEDColour);
  28. //==============================================================================
  29. /** Call this to match animations to the project tempo.
  30. @param padIdx The pad to update. 16 animated pads are supported, so 0 - 15.
  31. @param loopTimeSecs The length of time for the pad's animation to loop in seconds. 0 will stop the animation.
  32. @param currentProgress The starting progress of the animation. 0.0 - 1.0.
  33. */
  34. void setPadAnimationState (uint32 padIdx, double loopTimeSecs, double currentProgress);
  35. /** If the app needs to close down or suspend, use these to pause & dim animations. */
  36. void suspendAnimations();
  37. void resumeAnimations();
  38. //==============================================================================
  39. /** Set how each pad in the grid looks. */
  40. struct GridFill
  41. {
  42. enum FillType : uint8
  43. {
  44. gradient = 0,
  45. filled = 1,
  46. hollow = 2,
  47. hollowPlus = 3,
  48. // Animated pads
  49. dotPulsing = 4,
  50. dotBlinking = 5,
  51. pizzaFilled = 6,
  52. pizzaHollow = 7,
  53. };
  54. LEDColour colour;
  55. FillType fillType;
  56. };
  57. void setGridFills (int numColumns, int numRows,
  58. const juce::Array<GridFill>&);
  59. /** Set up a new pad layout, with a slide animation from the old to the new. */
  60. enum SlideDirection : uint8
  61. {
  62. up = 0,
  63. down = 1,
  64. left = 2,
  65. right = 3,
  66. none = 255
  67. };
  68. void triggerSlideTransition (int newNumColumns, int newNumRows,
  69. const juce::Array<GridFill>& newFills, SlideDirection);
  70. private:
  71. //==============================================================================
  72. /** Shared data heap is laid out as below. There is room for two sets of
  73. pad layouts, colours and fill types to allow animation between two states. */
  74. static constexpr uint32 numColumns0_byte = 0; // 1 byte
  75. static constexpr uint32 numRows0_byte = 1; // 1 byte (ignored for the moment: always square pads to save cycles)
  76. static constexpr uint32 colours0_byte = 2; // 2 byte x 25 (5:6:5 bits for rgb)
  77. static constexpr uint32 fillTypes0_byte = 52; // 1 byte x 25
  78. static constexpr uint32 numColumns1_byte = 78; // 1 byte
  79. static constexpr uint32 numRows1_byte = 79; // 1 byte
  80. static constexpr uint32 colours1_byte = 80; // 2 byte x 25 (5:6:5 bits for rgb)
  81. static constexpr uint32 fillTypes1_byte = 130; // 1 byte x 25
  82. static constexpr uint32 visiblePads_byte = 155; // 1 byte (i.e. which set of colours/fills to use, 0 or 1)
  83. static constexpr uint32 slideDirection_byte = 156; // 1 byte
  84. static constexpr uint32 touchedPads_byte = 158; // 1 byte x 4 (Zero means empty slot, so stores padIdx + 1)
  85. static constexpr uint32 animationTimers_byte = 162; // 4 byte x 16 (16:16 bits counter:increment)
  86. static constexpr uint32 heatMap_byte = 226; // 4 byte x 225
  87. static constexpr uint32 heatDecayMap_byte = 1126; // 1 byte x 225
  88. static constexpr uint32 maxNumPads = 25;
  89. static constexpr uint32 colourSizeBytes = 2;
  90. static constexpr uint32 heatMapSize = 15 * 15 * 4;
  91. static constexpr uint32 heatMapDecaySize = 15 * 15;
  92. static constexpr uint32 totalDataSize = heatDecayMap_byte + heatMapDecaySize;
  93. int getPadIndex (float posX, float posY) const;
  94. void setGridFills (int numColumns, int numRows, const juce::Array<GridFill>& fills, uint32 byteOffset);
  95. juce::String getLittleFootProgram() override;
  96. uint32 getHeapSize() override;
  97. };