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.

168 lines
5.8KB

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