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.

160 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. #pragma once
  18. //==============================================================================
  19. /**
  20. This class represents the current MPE zone layout of a device
  21. capable of handling MPE.
  22. Use the MPEMessages helper class to convert the zone layout represented
  23. by this object to MIDI message sequences that you can send to an Expressive
  24. MIDI device to set its zone layout, add zones etc.
  25. @see MPEZone, MPEInstrument
  26. */
  27. class JUCE_API MPEZoneLayout
  28. {
  29. public:
  30. /** Default constructor.
  31. This will create a layout with no MPE zones.
  32. You can add an MPE zone using the method addZone.
  33. */
  34. MPEZoneLayout() noexcept;
  35. /** Copy constuctor.
  36. This will not copy the listeners registered to the MPEZoneLayout.
  37. */
  38. MPEZoneLayout (const MPEZoneLayout& other);
  39. /** Copy assignment operator.
  40. This will not copy the listeners registered to the MPEZoneLayout.
  41. */
  42. MPEZoneLayout& operator= (const MPEZoneLayout& other);
  43. /** Adds a new MPE zone to the layout.
  44. @param newZone The zone to add.
  45. @return true if the zone was added without modifying any other zones
  46. added previously to the same zone layout object (if any);
  47. false if any existing MPE zones had to be truncated
  48. or deleted entirely in order to to add this new zone.
  49. (Note: the zone itself will always be added with the channel bounds
  50. that were specified; this will not fail.)
  51. */
  52. bool addZone (MPEZone newZone);
  53. /** Removes all currently present MPE zones. */
  54. void clearAllZones();
  55. /** Pass incoming MIDI messages to an object of this class if you want the
  56. zone layout to properly react to MPE RPN messages like an
  57. MPE device.
  58. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  59. set the per-note or master pitchbend ranges.
  60. Any other MIDI messages will be ignored by this class.
  61. @see MPEMessages
  62. */
  63. void processNextMidiEvent (const MidiMessage& message);
  64. /** Pass incoming MIDI buffers to an object of this class if you want the
  65. zone layout to properly react to MPE RPN messages like an
  66. MPE device.
  67. MPEMessages::rpnNumber will add or remove zones; RPN 0 will
  68. set the per-note or master pitchbend ranges.
  69. Any other MIDI messages will be ignored by this class.
  70. @see MPEMessages
  71. */
  72. void processNextMidiBuffer (const MidiBuffer& buffer);
  73. /** Returns the current number of MPE zones. */
  74. int getNumZones() const noexcept;
  75. /** Returns a pointer to the MPE zone at the given index, or nullptr if there
  76. is no such zone. Zones are sorted by insertion order (most recently added
  77. zone last).
  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. };