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.

162 lines
5.9KB

  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. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  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, or nullptr if there
  77. is no such zone. Zones are sorted by insertion order (most recently added
  78. zone last).
  79. */
  80. MPEZone* getZoneByIndex (int index) const noexcept;
  81. /** Returns a pointer to the zone which uses the specified channel (1-16),
  82. or nullptr if there is no such zone.
  83. */
  84. MPEZone* getZoneByChannel (int midiChannel) const noexcept;
  85. /** Returns a pointer to the zone which has the specified channel (1-16)
  86. as its master channel, or nullptr if there is no such zone.
  87. */
  88. MPEZone* getZoneByMasterChannel (int midiChannel) const noexcept;
  89. /** Returns a pointer to the zone which has the specified channel (1-16)
  90. as its first note channel, or nullptr if there is no such zone.
  91. */
  92. MPEZone* getZoneByFirstNoteChannel (int midiChannel) const noexcept;
  93. /** Returns a pointer to the zone which has the specified channel (1-16)
  94. as one of its note channels, or nullptr if there is no such zone.
  95. */
  96. MPEZone* getZoneByNoteChannel (int midiChannel) const noexcept;
  97. //==============================================================================
  98. /** Listener class. Derive from this class to allow your class to be
  99. notified about changes to the zone layout.
  100. */
  101. class Listener
  102. {
  103. public:
  104. /** Destructor. */
  105. virtual ~Listener() {}
  106. /** Implement this callback to be notified about any changes to this
  107. MPEZoneLayout. Will be called whenever a zone is added, zones are
  108. removed, or any zone's master or note pitchbend ranges change.
  109. */
  110. virtual void zoneLayoutChanged (const MPEZoneLayout& layout) = 0;
  111. };
  112. //==============================================================================
  113. /** Adds a listener. */
  114. void addListener (Listener* const listenerToAdd) noexcept;
  115. /** Removes a listener. */
  116. void removeListener (Listener* const listenerToRemove) noexcept;
  117. private:
  118. //==============================================================================
  119. Array<MPEZone> zones;
  120. MidiRPNDetector rpnDetector;
  121. ListenerList<Listener> listeners;
  122. void processRpnMessage (MidiRPNMessage);
  123. void processZoneLayoutRpnMessage (MidiRPNMessage);
  124. void processPitchbendRangeRpnMessage (MidiRPNMessage);
  125. };
  126. } // namespace juce