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.

94 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - 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. #ifndef ZONECOLOURPICKER_H_INCLUDED
  18. #define ZONECOLOURPICKER_H_INCLUDED
  19. class ZoneColourPicker
  20. {
  21. public:
  22. //==============================================================================
  23. ZoneColourPicker()
  24. : legacyModeEnabled (false)
  25. {
  26. }
  27. //==============================================================================
  28. Colour getColourForMidiChannel (int midiChannel) const noexcept
  29. {
  30. if (legacyModeEnabled)
  31. return Colours::white;
  32. if (zoneLayout.getNumZones() == 0)
  33. return Colours::transparentBlack;
  34. MPEZone* zone = zoneLayout.getZoneByChannel (midiChannel);
  35. if (zone == nullptr)
  36. return Colours::transparentBlack;
  37. return getColourForZoneIndex (std::distance (zoneLayout.getZoneByIndex (0), zone));
  38. }
  39. //==============================================================================
  40. Colour getColourForZoneIndex (int zoneIndex) const noexcept
  41. {
  42. if (legacyModeEnabled)
  43. return Colours::white;
  44. if (zoneIndex >= zoneLayout.getNumZones())
  45. return Colours::transparentBlack;
  46. static const std::array<Colour, 8> colours = {
  47. Colours::red,
  48. Colours::yellow,
  49. Colours::blue,
  50. Colours::magenta,
  51. Colours::limegreen,
  52. Colours::cyan,
  53. Colours::orange,
  54. Colours::salmon
  55. };
  56. return colours[zoneIndex % colours.size()];
  57. }
  58. //==============================================================================
  59. void setZoneLayout (MPEZoneLayout layout) noexcept { zoneLayout = layout; }
  60. void setLegacyModeEnabled (bool shouldBeEnabled) noexcept { legacyModeEnabled = shouldBeEnabled; }
  61. private:
  62. //==============================================================================
  63. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ZoneColourPicker)
  64. MPEZoneLayout zoneLayout;
  65. bool legacyModeEnabled;
  66. };
  67. #endif // ZONECOLOURPICKER_H_INCLUDED