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.

103 lines
3.9KB

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