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.

155 lines
5.7KB

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