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.

151 lines
5.6KB

  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 ZoneLayoutComponent : public Component,
  19. public MPESetupComponent::Listener
  20. {
  21. public:
  22. //==============================================================================
  23. ZoneLayoutComponent (const ZoneColourPicker& zoneColourPicker)
  24. : colourPicker (zoneColourPicker)
  25. {}
  26. //==============================================================================
  27. void paint (Graphics& g) override
  28. {
  29. paintBackground (g);
  30. if (legacyModeEnabled)
  31. paintLegacyMode (g);
  32. else
  33. paintZones (g);
  34. }
  35. //==============================================================================
  36. void zoneAdded (MPEZone newZone) override
  37. {
  38. zoneLayout.addZone (newZone);
  39. repaint();
  40. }
  41. void allZonesCleared() override
  42. {
  43. zoneLayout.clearAllZones();
  44. repaint();
  45. }
  46. void legacyModeChanged (bool legacyModeShouldBeEnabled, int pitchbendRange, Range<int> channelRange) override
  47. {
  48. legacyModeEnabled = legacyModeShouldBeEnabled;
  49. legacyModePitchbendRange = pitchbendRange;
  50. legacyModeChannelRange = channelRange;
  51. repaint();
  52. }
  53. void voiceStealingEnabledChanged (bool) override { /* not interested in this change */ }
  54. void numberOfVoicesChanged (int) override { /* not interested in this change */ }
  55. private:
  56. //==============================================================================
  57. void paintBackground (Graphics& g)
  58. {
  59. g.setColour (Colours::black);
  60. float channelWidth = getChannelRectangleWidth();
  61. for (int i = 0; i < numMidiChannels; ++i)
  62. {
  63. float x = float (i) * channelWidth;
  64. Rectangle<int> channelArea ((int) x, 0, (int) channelWidth, getHeight());
  65. Line<float> line (x, 0.0f, x, float (getHeight()));
  66. g.drawLine (line);
  67. g.drawText (String (i + 1), channelArea.reduced (4, 4), Justification::topLeft, false);
  68. }
  69. }
  70. //==============================================================================
  71. void paintZones (Graphics& g)
  72. {
  73. float channelWidth = getChannelRectangleWidth();
  74. for (int i = 0; i < zoneLayout.getNumZones(); ++i)
  75. {
  76. MPEZone zone = *zoneLayout.getZoneByIndex (i);
  77. Colour zoneColour = colourPicker.getColourForZoneIndex (i);
  78. Rectangle<int> zoneRect (int (getChannelRectangleWidth() * (zone.getMasterChannel() - 1)), 0,
  79. int (getChannelRectangleWidth() * (zone.getNumNoteChannels() + 1)), getHeight());
  80. zoneRect.removeFromTop (20);
  81. g.setColour (zoneColour.withAlpha (0.3f));
  82. g.fillRect (zoneRect.withWidth ((int) channelWidth));
  83. g.setColour (zoneColour);
  84. g.drawRect (zoneRect, 3);
  85. g.drawText ("<>" + String (zone.getPerNotePitchbendRange()), zoneRect.withTrimmedLeft ((int) channelWidth).reduced (4, 4), Justification::bottomLeft, false);
  86. g.setColour (Colours::black);
  87. g.drawText ("ZONE " + String (i + 1), zoneRect.reduced (4, 4), Justification::topLeft, false);
  88. g.drawText ("<>" + String (zone.getMasterPitchbendRange()), zoneRect.reduced (4, 4), Justification::bottomLeft, false);
  89. }
  90. }
  91. //==============================================================================
  92. void paintLegacyMode (Graphics& g)
  93. {
  94. int startChannel = legacyModeChannelRange.getStart() - 1;
  95. int numChannels = legacyModeChannelRange.getEnd() - startChannel - 1;
  96. Rectangle<int> zoneRect (int (getChannelRectangleWidth() * startChannel), 0,
  97. int (getChannelRectangleWidth() * numChannels), getHeight());
  98. zoneRect.removeFromTop (20);
  99. g.setColour (Colours::white);
  100. g.drawRect (zoneRect, 3);
  101. g.drawText ("LGCY", zoneRect.reduced (4, 4), Justification::topLeft, false);
  102. g.drawText ("<>" + String (legacyModePitchbendRange), zoneRect.reduced (4, 4), Justification::bottomLeft, false);
  103. }
  104. //==============================================================================
  105. float getChannelRectangleWidth() const noexcept
  106. {
  107. return float (getWidth()) / numMidiChannels;
  108. }
  109. //==============================================================================
  110. MPEZoneLayout zoneLayout;
  111. const ZoneColourPicker& colourPicker;
  112. bool legacyModeEnabled = false;
  113. int legacyModePitchbendRange = 48;
  114. Range<int> legacyModeChannelRange = { 1, 17 };
  115. const int numMidiChannels = 16;
  116. };