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.

153 lines
5.6KB

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