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.

172 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_MPEZONELAYOUT_H_INCLUDED
  24. #define JUCE_MPEZONELAYOUT_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. This class represents the current MPE zone layout of a device
  28. capable of handling MPE.
  29. Use the MPEMessages helper class to convert the zone layout represented
  30. by this object to MIDI message sequences that you can send to an Expressive
  31. MIDI device to set its zone layout, add zones etc.
  32. @see MPEZone, MPEInstrument
  33. */
  34. class JUCE_API MPEZoneLayout
  35. {
  36. public:
  37. /** Default constructor.
  38. This will create a layout with no MPE zones.
  39. You can add an MPE zone using the method addZone.
  40. */
  41. MPEZoneLayout() noexcept;
  42. /** Copy constuctor.
  43. This will not copy the listeners registered to the MPEZoneLayout.
  44. */
  45. MPEZoneLayout (const MPEZoneLayout& other);
  46. /** Copy assignment operator.
  47. This will not copy the listeners registered to the MPEZoneLayout.
  48. */
  49. MPEZoneLayout& operator= (const MPEZoneLayout& other);
  50. /** Adds a new MPE zone to the layout.
  51. @param newZone The zone to add.
  52. @return true if the zone was added without modifying any other zones
  53. added previously to the same zone layout object (if any);
  54. false if any existing MPE zones had to be truncated
  55. or deleted entirely in order to to add this new zone.
  56. (Note: the zone itself will always be added with the channel bounds
  57. that were specified; this will not fail.)
  58. */
  59. bool addZone (MPEZone newZone);
  60. /** Removes all currently present MPE zones. */
  61. void clearAllZones();
  62. /** Pass incoming MIDI messages to an object of this class if you want the
  63. zone layout to properly react to MPE RPN messages like an
  64. MPE device.
  65. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  66. set the per-note or master pitchbend ranges.
  67. Any other MIDI messages will be ignored by this class.
  68. @see MPEMessages
  69. */
  70. void processNextMidiEvent (const MidiMessage& message);
  71. /** Pass incoming MIDI buffers to an object of this class if you want the
  72. zone layout to properly react to MPE RPN messages like an
  73. MPE device.
  74. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  75. set the per-note or master pitchbend ranges.
  76. Any other MIDI messages will be ignored by this class.
  77. @see MPEMessages
  78. */
  79. void processNextMidiBuffer (const MidiBuffer& buffer);
  80. /** Returns the current number of MPE zones. */
  81. int getNumZones() const noexcept;
  82. /** Returns a pointer to the MPE zone at the given index, or nullptr if there
  83. is no such zone. Zones are sorted by insertion order (most recently added
  84. zone last).
  85. */
  86. MPEZone* getZoneByIndex (int index) const noexcept;
  87. /** Returns a pointer to the zone which uses the specified channel (1-16),
  88. or nullptr if there is no such zone.
  89. */
  90. MPEZone* getZoneByChannel (int midiChannel) const noexcept;
  91. /** Returns a pointer to the zone which has the specified channel (1-16)
  92. as its master channel, or nullptr if there is no such zone.
  93. */
  94. MPEZone* getZoneByMasterChannel (int midiChannel) const noexcept;
  95. /** Returns a pointer to the zone which has the specified channel (1-16)
  96. as its first note channel, or nullptr if there is no such zone.
  97. */
  98. MPEZone* getZoneByFirstNoteChannel (int midiChannel) const noexcept;
  99. /** Returns a pointer to the zone which has the specified channel (1-16)
  100. as one of its note channels, or nullptr if there is no such zone.
  101. */
  102. MPEZone* getZoneByNoteChannel (int midiChannel) const noexcept;
  103. //==============================================================================
  104. /** Listener class. Derive from this class to allow your class to be
  105. notified about changes to the zone layout.
  106. */
  107. class Listener
  108. {
  109. public:
  110. /** Destructor. */
  111. virtual ~Listener() {}
  112. /** Implement this callback to be notified about any changes to this
  113. MPEZoneLayout. Will be called whenever a zone is added, zones are
  114. removed, or any zone's master or note pitchbend ranges change.
  115. */
  116. virtual void zoneLayoutChanged (const MPEZoneLayout& layout) = 0;
  117. };
  118. //==============================================================================
  119. /** Adds a listener. */
  120. void addListener (Listener* const listenerToAdd) noexcept;
  121. /** Removes a listener. */
  122. void removeListener (Listener* const listenerToRemove) noexcept;
  123. private:
  124. //==============================================================================
  125. Array<MPEZone> zones;
  126. MidiRPNDetector rpnDetector;
  127. ListenerList<Listener> listeners;
  128. void processRpnMessage (MidiRPNMessage);
  129. void processZoneLayoutRpnMessage (MidiRPNMessage);
  130. void processPitchbendRangeRpnMessage (MidiRPNMessage);
  131. };
  132. #endif // JUCE_MPEZONELAYOUT_H_INCLUDED