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.

90 lines
2.9KB

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