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.

159 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. A simple ARGB colour class for setting LEDs.
  19. */
  20. struct LEDColour
  21. {
  22. LEDColour() noexcept = default;
  23. LEDColour (const LEDColour&) noexcept = default;
  24. LEDColour& operator= (const LEDColour&) noexcept = default;
  25. LEDColour (uint32 argbColour) noexcept : argb (argbColour) {}
  26. template <typename ColourType>
  27. LEDColour (const ColourType& colour) : LEDColour (colour.getARGB()) {}
  28. uint8 getAlpha() const noexcept { return (uint8) (argb >> 24); }
  29. uint8 getRed() const noexcept { return (uint8) (argb >> 16); }
  30. uint8 getGreen() const noexcept { return (uint8) (argb >> 8); }
  31. uint8 getBlue() const noexcept { return (uint8) argb; }
  32. uint32 getARGB() const noexcept { return argb; }
  33. uint32 argb = 0;
  34. };
  35. //==============================================================================
  36. /**
  37. Represents a 2D grid of LEDs on a block device.
  38. */
  39. class LEDGrid
  40. {
  41. public:
  42. LEDGrid (Block&);
  43. /** Destructor. */
  44. virtual ~LEDGrid();
  45. //==============================================================================
  46. /** Returns the number of columns in the LED grid. */
  47. virtual int getNumColumns() const = 0;
  48. /** Returns the number of rows in the LED grid. */
  49. virtual int getNumRows() const = 0;
  50. /** A program that can be loaded onto an LEDGrid.
  51. This class facilitates the execution of a LittleFoot program on a BLOCKS
  52. device with an LEDGrid.
  53. */
  54. struct Program
  55. {
  56. /** Creates a Program for the corresponding LEDGrid. */
  57. Program (LEDGrid&);
  58. /** Destructor. */
  59. virtual ~Program();
  60. /** Returns the LittleFoot program to execute on the BLOCKS device. */
  61. virtual juce::String getLittleFootProgram() = 0;
  62. /** Sets the size of the shared area of memory used to communicate with
  63. the host computer.
  64. */
  65. virtual uint32 getHeapSize() = 0;
  66. LEDGrid& ledGrid;
  67. };
  68. /** Sets the Program to run on this LEDGrid.
  69. The supplied Program's lifetime will be managed by this class, so do not
  70. use the Program in other places in your code.
  71. */
  72. virtual juce::Result setProgram (Program*) = 0;
  73. /** Returns a pointer to the currently loaded program. */
  74. virtual Program* getProgram() const = 0;
  75. /** A message that can be sent to the currently loaded program. */
  76. struct ProgramEventMessage
  77. {
  78. int32 values[2];
  79. };
  80. /** Sends a message to the currently loaded program.
  81. To receive the message the program must provide a function called
  82. handleMessage with the following form:
  83. @code
  84. void handleMessage (int param1, int param2)
  85. {
  86. // Do something with the two integer parameters that the app has sent...
  87. }
  88. @endcode
  89. */
  90. virtual void sendProgramEvent (const ProgramEventMessage&) = 0;
  91. /** Sets a single byte on the heap. */
  92. virtual void setDataByte (size_t offset, uint8 value) = 0;
  93. /** Sets multiple bytes on the heap. */
  94. virtual void setDataBytes (size_t offset, const void* data, size_t num) = 0;
  95. /** Sets multiple bits on the heap. */
  96. virtual void setDataBits (uint32 startBit, uint32 numBits, uint32 value) = 0;
  97. /** Gets a byte from the heap. */
  98. virtual uint8 getDataByte (size_t offset) = 0;
  99. //==============================================================================
  100. struct Renderer
  101. {
  102. virtual ~Renderer();
  103. virtual void renderLEDGrid (LEDGrid&) = 0;
  104. };
  105. /** Set the visualiser that will create visuals for this block (nullptr for none).
  106. Note that the LEDGrid will NOT take ownership of this object, so the caller
  107. must ensure that it doesn't get deleted while in use here.
  108. */
  109. void setRenderer (Renderer* newRenderer) noexcept { renderer = newRenderer; }
  110. /** Returns the visualiser currently attached to this block (nullptr for none). */
  111. Renderer* getRenderer() const noexcept { return renderer; }
  112. /** The device that this LEDGrid belongs to. */
  113. Block& block;
  114. private:
  115. Renderer* renderer = nullptr;
  116. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LEDGrid)
  117. };