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.

163 lines
6.0KB

  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. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. class ZoneLayoutComponent : public Component,
  21. public MPESetupComponent::Listener
  22. {
  23. public:
  24. //==============================================================================
  25. ZoneLayoutComponent (const ZoneColourPicker& zoneColourPicker)
  26. : colourPicker (zoneColourPicker)
  27. {}
  28. //==============================================================================
  29. void paint (Graphics& g) override
  30. {
  31. paintBackground (g);
  32. if (legacyModeEnabled)
  33. paintLegacyMode (g);
  34. else
  35. paintZones (g);
  36. }
  37. //==============================================================================
  38. void zoneChanged (bool isLowerZone, int numMemberChannels,
  39. int perNotePitchbendRange, int masterPitchbendRange) override
  40. {
  41. if (isLowerZone)
  42. zoneLayout.setLowerZone (numMemberChannels, perNotePitchbendRange, masterPitchbendRange);
  43. else
  44. zoneLayout.setUpperZone (numMemberChannels, perNotePitchbendRange, masterPitchbendRange);
  45. repaint();
  46. }
  47. void allZonesCleared() override
  48. {
  49. zoneLayout.clearAllZones();
  50. repaint();
  51. }
  52. void legacyModeChanged (bool legacyModeShouldBeEnabled, int pitchbendRange, Range<int> channelRange) override
  53. {
  54. legacyModeEnabled = legacyModeShouldBeEnabled;
  55. legacyModePitchbendRange = pitchbendRange;
  56. legacyModeChannelRange = channelRange;
  57. repaint();
  58. }
  59. void voiceStealingEnabledChanged (bool) override { /* not interested in this change */ }
  60. void numberOfVoicesChanged (int) override { /* not interested in this change */ }
  61. private:
  62. //==============================================================================
  63. void paintBackground (Graphics& g)
  64. {
  65. g.setColour (Colours::black);
  66. float channelWidth = getChannelRectangleWidth();
  67. for (int i = 0; i < numMidiChannels; ++i)
  68. {
  69. auto x = float (i) * channelWidth;
  70. Rectangle<int> channelArea ((int) x, 0, (int) channelWidth, getHeight());
  71. g.drawLine ({ x, 0.0f, x, float (getHeight()) });
  72. g.drawText (String (i + 1), channelArea.reduced (4, 4), Justification::topLeft, false);
  73. }
  74. }
  75. //==============================================================================
  76. void paintZones (Graphics& g)
  77. {
  78. auto channelWidth = getChannelRectangleWidth();
  79. Array<MPEZoneLayout::Zone> activeZones;
  80. if (zoneLayout.getLowerZone().isActive()) activeZones.add (zoneLayout.getLowerZone());
  81. if (zoneLayout.getUpperZone().isActive()) activeZones.add (zoneLayout.getUpperZone());
  82. for (auto zone : activeZones)
  83. {
  84. auto zoneColour = colourPicker.getColourForZone (zone.isLowerZone());
  85. auto xPos = zone.isLowerZone() ? 0 : zone.getLastMemberChannel() - 1;
  86. Rectangle<int> zoneRect { int (channelWidth * (xPos)), 20,
  87. int (channelWidth * (zone.numMemberChannels + 1)), getHeight() - 20 };
  88. g.setColour (zoneColour);
  89. g.drawRect (zoneRect, 3);
  90. auto masterRect = zone.isLowerZone() ? zoneRect.removeFromLeft (channelWidth) : zoneRect.removeFromRight (channelWidth);
  91. g.setColour (zoneColour.withAlpha (0.3f));
  92. g.fillRect (masterRect);
  93. g.setColour (zoneColour.contrasting());
  94. g.drawText ("<>" + String (zone.masterPitchbendRange), masterRect.reduced (4), Justification::top, false);
  95. g.drawText ("<>" + String (zone.perNotePitchbendRange), masterRect.reduced (4), Justification::bottom, false);
  96. }
  97. }
  98. //==============================================================================
  99. void paintLegacyMode (Graphics& g)
  100. {
  101. auto startChannel = legacyModeChannelRange.getStart() - 1;
  102. auto numChannels = legacyModeChannelRange.getEnd() - startChannel - 1;
  103. Rectangle<int> zoneRect (int (getChannelRectangleWidth() * startChannel), 0,
  104. int (getChannelRectangleWidth() * numChannels), getHeight());
  105. zoneRect.removeFromTop (20);
  106. g.setColour (Colours::white);
  107. g.drawRect (zoneRect, 3);
  108. g.drawText ("LGCY", zoneRect.reduced (4, 4), Justification::topLeft, false);
  109. g.drawText ("<>" + String (legacyModePitchbendRange), zoneRect.reduced (4, 4), Justification::bottomLeft, false);
  110. }
  111. //==============================================================================
  112. float getChannelRectangleWidth() const noexcept
  113. {
  114. return float (getWidth()) / numMidiChannels;
  115. }
  116. //==============================================================================
  117. MPEZoneLayout zoneLayout;
  118. const ZoneColourPicker& colourPicker;
  119. bool legacyModeEnabled = false;
  120. int legacyModePitchbendRange = 48;
  121. Range<int> legacyModeChannelRange = { 1, 17 };
  122. const int numMidiChannels = 16;
  123. };