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.

97 lines
3.4KB

  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_MPEVALUE_H_INCLUDED
  18. #define JUCE_MPEVALUE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. This class represents a single value for any of the MPE
  22. dimensions of control. It supports values with 7-bit or 14-bit resolutions
  23. (corresponding to 1 or 2 MIDI bytes, respectively). It also offers helper
  24. functions to query the value in a variety of representations that can be
  25. useful in an audio or MIDI context.
  26. */
  27. class JUCE_API MPEValue
  28. {
  29. public:
  30. //==============================================================================
  31. /** Default constructor. Constructs an MPEValue corresponding
  32. to the centre value.
  33. */
  34. MPEValue() noexcept;
  35. /** Constructs an MPEValue from an integer between 0 and 127
  36. (using 7-bit precision).
  37. */
  38. static MPEValue from7BitInt (int value) noexcept;
  39. /** Constructs an MPEValue from an integer between 0 and 16383
  40. (using 14-bit precision).
  41. */
  42. static MPEValue from14BitInt (int value) noexcept;
  43. /** Constructs an MPEValue corresponding to the centre value. */
  44. static MPEValue centreValue() noexcept;
  45. /** Constructs an MPEValue corresponding to the minimum value. */
  46. static MPEValue minValue() noexcept;
  47. /** Constructs an MPEValue corresponding to the maximum value. */
  48. static MPEValue maxValue() noexcept;
  49. /** Retrieves the current value as an integer between 0 and 127.
  50. Information will be lost if the value was initialised with a precision
  51. higher than 7-bit.
  52. */
  53. int as7BitInt() const noexcept;
  54. /** Retrieves the current value as an integer between 0 and 16383.
  55. Resolution will be lost if the value was initialised with a precision
  56. higher than 14-bit.
  57. */
  58. int as14BitInt() const noexcept;
  59. /** Retrieves the current value mapped to a float between -1.0f and 1.0f. */
  60. float asSignedFloat() const noexcept;
  61. /** Retrieves the current value mapped to a float between 0.0f and 1.0f. */
  62. float asUnsignedFloat() const noexcept;
  63. /** Returns true if two values are equal. */
  64. bool operator== (const MPEValue& other) const noexcept;
  65. /** Returns true if two values are not equal. */
  66. bool operator!= (const MPEValue& other) const noexcept;
  67. private:
  68. //==============================================================================
  69. MPEValue (int normalisedValue);
  70. int normalisedValue;
  71. };
  72. #endif // JUCE_MPEVALUE_H_INCLUDED