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.

150 lines
5.4KB

  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 (omniModeEnabled)
  32. paintOmniMode (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 omniModeChanged (bool omniModeShouldBeEnabled, int pitchbendRange) override
  48. {
  49. if (omniModeEnabled == omniModeShouldBeEnabled && omniModePitchbendRange == pitchbendRange)
  50. return;
  51. omniModeEnabled = omniModeShouldBeEnabled;
  52. omniModePitchbendRange = pitchbendRange;
  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 paintOmniMode (Graphics& g)
  95. {
  96. Rectangle<int> zoneRect = getLocalBounds();
  97. zoneRect.removeFromTop (20);
  98. g.setColour (Colours::white);
  99. g.drawRect (zoneRect, 3);
  100. g.drawText ("OMNI", zoneRect.reduced (4, 4), Justification::topLeft, false);
  101. g.drawText ("<>" + String (omniModePitchbendRange), zoneRect.reduced (4, 4), Justification::bottomLeft, false);
  102. }
  103. //==========================================================================
  104. float getChannelRectangleWidth() const noexcept
  105. {
  106. return float (getWidth()) / numMidiChannels;
  107. }
  108. //==========================================================================
  109. MPEZoneLayout zoneLayout;
  110. const ZoneColourPicker& colourPicker;
  111. bool omniModeEnabled = false;
  112. int omniModePitchbendRange = 48;
  113. const int numMidiChannels = 16;
  114. };
  115. #endif // ZONELAYOUTCOMPONENT_H_INCLUDED