Audio plugin host https://kx.studio/carla
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.

165 lines
6.0KB

  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 JUCE_MPEZONELAYOUT_H_INCLUDED
  18. #define JUCE_MPEZONELAYOUT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. This class represents the current MPE zone layout of a device
  22. capable of handling MPE.
  23. Use the MPEMessages helper class to convert the zone layout represented
  24. by this object to MIDI message sequences that you can send to an Expressive
  25. MIDI device to set its zone layout, add zones etc.
  26. @see MPEZone, MPEInstrument
  27. */
  28. class JUCE_API MPEZoneLayout
  29. {
  30. public:
  31. /** Default constructor.
  32. This will create a layout with no MPE zones.
  33. You can add an MPE zone using the method addZone.
  34. */
  35. MPEZoneLayout() noexcept;
  36. /** Copy constuctor.
  37. This will not copy the listeners registered to the MPEZoneLayout.
  38. */
  39. MPEZoneLayout (const MPEZoneLayout& other);
  40. /** Copy assignment operator.
  41. This will not copy the listeners registered to the MPEZoneLayout.
  42. */
  43. MPEZoneLayout& operator= (const MPEZoneLayout& other);
  44. /** Adds a new MPE zone to the layout.
  45. @param newZone The zone to add.
  46. @return true if the zone was added without modifying any other zones
  47. added previously to the same zone layout object (if any);
  48. false if any existing MPE zones had to be truncated
  49. or deleted entirely in order to to add this new zone.
  50. (Note: the zone itself will always be added with the channel bounds
  51. that were specified; this will not fail.)
  52. */
  53. bool addZone (MPEZone newZone);
  54. /** Removes all currently present MPE zones. */
  55. void clearAllZones();
  56. /** Pass incoming MIDI messages to an object of this class if you want the
  57. zone layout to properly react to MPE RPN messages like an
  58. MPE device.
  59. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  60. set the per-note or master pitchbend ranges.
  61. Any other MIDI messages will be ignored by this class.
  62. @see MPEMessages
  63. */
  64. void processNextMidiEvent (const MidiMessage& message);
  65. /** Pass incoming MIDI buffers to an object of this class if you want the
  66. zone layout to properly react to MPE RPN messages like an
  67. MPE device.
  68. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  69. set the per-note or master pitchbend ranges.
  70. Any other MIDI messages will be ignored by this class.
  71. @see MPEMessages
  72. */
  73. void processNextMidiBuffer (const MidiBuffer& buffer);
  74. /** Returns the current number of MPE zones. */
  75. int getNumZones() const noexcept;
  76. /** Returns a pointer to the MPE zone at the given index,
  77. or nullptr if there is no such zone.
  78. */
  79. MPEZone* getZoneByIndex (int index) const noexcept;
  80. /** Returns a pointer to the zone which uses the specified channel (1-16),
  81. or nullptr if there is no such zone.
  82. */
  83. MPEZone* getZoneByChannel (int midiChannel) const noexcept;
  84. /** Returns a pointer to the zone which has the specified channel (1-16)
  85. as its master channel, or nullptr if there is no such zone.
  86. */
  87. MPEZone* getZoneByMasterChannel (int midiChannel) const noexcept;
  88. /** Returns a pointer to the zone which has the specified channel (1-16)
  89. as its first note channel, or nullptr if there is no such zone.
  90. */
  91. MPEZone* getZoneByFirstNoteChannel (int midiChannel) const noexcept;
  92. /** Returns a pointer to the zone which has the specified channel (1-16)
  93. as one of its note channels, or nullptr if there is no such zone.
  94. */
  95. MPEZone* getZoneByNoteChannel (int midiChannel) const noexcept;
  96. //==============================================================================
  97. /** Listener class. Derive from this class to allow your class to be
  98. notified about changes to the zone layout.
  99. */
  100. class Listener
  101. {
  102. public:
  103. /** Destructor. */
  104. virtual ~Listener() {}
  105. /** Implement this callback to be notified about any changes to this
  106. MPEZoneLayout. Will be called whenever a zone is added, zones are
  107. removed, or any zone's master or note pitchbend ranges change.
  108. */
  109. virtual void zoneLayoutChanged (const MPEZoneLayout& layout) = 0;
  110. };
  111. //==============================================================================
  112. /** Adds a listener. */
  113. void addListener (Listener* const listenerToAdd) noexcept;
  114. /** Removes a listener. */
  115. void removeListener (Listener* const listenerToRemove) noexcept;
  116. private:
  117. //==============================================================================
  118. Array<MPEZone> zones;
  119. MidiRPNDetector rpnDetector;
  120. ListenerList<Listener> listeners;
  121. void processRpnMessage (MidiRPNMessage);
  122. void processZoneLayoutRpnMessage (MidiRPNMessage);
  123. void processPitchbendRangeRpnMessage (MidiRPNMessage);
  124. };
  125. #endif // JUCE_MPEZONELAYOUT_H_INCLUDED