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.

132 lines
5.7KB

  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 the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. /**
  24. */
  25. struct DrumPadGridProgram : public LEDGrid::Program
  26. {
  27. DrumPadGridProgram (LEDGrid&);
  28. //==============================================================================
  29. /** These let the program dim pads which aren't having gestures performed on them. */
  30. void startTouch (float startX, float startY);
  31. void endTouch (float startX, float startY);
  32. /** Creates trail effects similar to the onscreen pad trails. */
  33. void sendTouch (float x, float y, float z, LEDColour);
  34. //==============================================================================
  35. /** Call this to match animations to the project tempo.
  36. @param padIdx The pad to update. 16 animated pads are supported, so 0 - 15.
  37. @param loopTimeSecs The length of time for the pad's animation to loop in seconds. 0 will stop the animation.
  38. @param currentProgress The starting progress of the animation. 0.0 - 1.0.
  39. */
  40. void setPadAnimationState (uint32 padIdx, double loopTimeSecs, double currentProgress);
  41. /** If the app needs to close down or suspend, use these to pause & dim animations. */
  42. void suspendAnimations();
  43. void resumeAnimations();
  44. //==============================================================================
  45. /** Set how each pad in the grid looks. */
  46. struct GridFill
  47. {
  48. enum FillType : uint8
  49. {
  50. gradient = 0,
  51. filled = 1,
  52. hollow = 2,
  53. hollowPlus = 3,
  54. // Animated pads
  55. dotPulsing = 4,
  56. dotBlinking = 5,
  57. pizzaFilled = 6,
  58. pizzaHollow = 7,
  59. };
  60. LEDColour colour;
  61. FillType fillType;
  62. };
  63. void setGridFills (int numColumns, int numRows,
  64. const juce::Array<GridFill>&);
  65. /** Set up a new pad layout, with a slide animation from the old to the new. */
  66. enum SlideDirection : uint8
  67. {
  68. up = 0,
  69. down = 1,
  70. left = 2,
  71. right = 3,
  72. none = 255
  73. };
  74. void triggerSlideTransition (int newNumColumns, int newNumRows,
  75. const juce::Array<GridFill>& newFills, SlideDirection);
  76. private:
  77. //==============================================================================
  78. /** Shared data heap is laid out as below. There is room for two sets of
  79. pad layouts, colours and fill types to allow animation between two states. */
  80. static constexpr uint32 numColumns0_byte = 0; // 1 byte
  81. static constexpr uint32 numRows0_byte = 1; // 1 byte (ignored for the moment: always square pads to save cycles)
  82. static constexpr uint32 colours0_byte = 2; // 2 byte x 25 (5:6:5 bits for rgb)
  83. static constexpr uint32 fillTypes0_byte = 52; // 1 byte x 25
  84. static constexpr uint32 numColumns1_byte = 78; // 1 byte
  85. static constexpr uint32 numRows1_byte = 79; // 1 byte
  86. static constexpr uint32 colours1_byte = 80; // 2 byte x 25 (5:6:5 bits for rgb)
  87. static constexpr uint32 fillTypes1_byte = 130; // 1 byte x 25
  88. static constexpr uint32 visiblePads_byte = 155; // 1 byte (i.e. which set of colours/fills to use, 0 or 1)
  89. static constexpr uint32 slideDirection_byte = 156; // 1 byte
  90. static constexpr uint32 touchedPads_byte = 158; // 1 byte x 4 (Zero means empty slot, so stores padIdx + 1)
  91. static constexpr uint32 animationTimers_byte = 162; // 4 byte x 16 (16:16 bits counter:increment)
  92. static constexpr uint32 heatMap_byte = 226; // 4 byte x 225
  93. static constexpr uint32 heatDecayMap_byte = 1126; // 1 byte x 225
  94. static constexpr uint32 maxNumPads = 25;
  95. static constexpr uint32 colourSizeBytes = 2;
  96. static constexpr uint32 heatMapSize = 15 * 15 * 4;
  97. static constexpr uint32 heatMapDecaySize = 15 * 15;
  98. static constexpr uint32 totalDataSize = heatDecayMap_byte + heatMapDecaySize;
  99. int getPadIndex (float posX, float posY) const;
  100. void setGridFills (int numColumns, int numRows, const juce::Array<GridFill>& fills, uint32 byteOffset);
  101. juce::String getLittleFootProgram() override;
  102. uint32 getHeapSize() override;
  103. };