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.

168 lines
6.4KB

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