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.

105 lines
3.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. //==============================================================================
  57. struct Renderer : public juce::ReferenceCountedObject
  58. {
  59. virtual ~Renderer();
  60. virtual void renderLEDGrid (LEDGrid&) = 0;
  61. /** The Renderer class is reference-counted, so always use a Renderer::Ptr when
  62. you are keeping references to them.
  63. */
  64. using Ptr = juce::ReferenceCountedObjectPtr<Renderer>;
  65. };
  66. /** Set the visualiser that will create visuals for this block (nullptr for none).
  67. Note that the LEDGrid will NOT take ownership of this object, so the caller
  68. must ensure that it doesn't get deleted while in use here.
  69. */
  70. void setRenderer (Renderer::Ptr newRenderer) noexcept { renderer = newRenderer; }
  71. /** Returns the visualiser currently attached to this block (nullptr for none). */
  72. Renderer::Ptr getRenderer() const noexcept { return renderer; }
  73. /** The device that this LEDGrid belongs to. */
  74. Block& block;
  75. private:
  76. Renderer::Ptr renderer;
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LEDGrid)
  78. };