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.

97 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  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. //==============================================================================
  51. struct Renderer : public juce::ReferenceCountedObject
  52. {
  53. virtual ~Renderer();
  54. virtual void renderLEDGrid (LEDGrid&) = 0;
  55. /** The Renderer class is reference-counted, so always use a Renderer::Ptr when
  56. you are keeping references to them.
  57. */
  58. using Ptr = juce::ReferenceCountedObjectPtr<Renderer>;
  59. };
  60. /** Set the visualiser that will create visuals for this block (nullptr for none).
  61. Note that the LEDGrid will NOT take ownership of this object, so the caller
  62. must ensure that it doesn't get deleted while in use here.
  63. */
  64. void setRenderer (Renderer::Ptr newRenderer) noexcept { renderer = newRenderer; }
  65. /** Returns the visualiser currently attached to this block (nullptr for none). */
  66. Renderer::Ptr getRenderer() const noexcept { return renderer; }
  67. /** The device that this LEDGrid belongs to. */
  68. Block& block;
  69. private:
  70. Renderer::Ptr renderer;
  71. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LEDGrid)
  72. };