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.

juce_MPEValue.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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. namespace juce
  18. {
  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. @tags{Audio}
  27. */
  28. class JUCE_API MPEValue
  29. {
  30. public:
  31. //==============================================================================
  32. /** Default constructor.
  33. Constructs an MPEValue corresponding to the centre value.
  34. */
  35. MPEValue() noexcept;
  36. /** Constructs an MPEValue from an integer between 0 and 127
  37. (using 7-bit precision).
  38. */
  39. static MPEValue from7BitInt (int value) noexcept;
  40. /** Constructs an MPEValue from an integer between 0 and 16383
  41. (using 14-bit precision).
  42. */
  43. static MPEValue from14BitInt (int value) noexcept;
  44. /** Constructs an MPEValue from a float between 0.0f and 1.0f. */
  45. static MPEValue fromUnsignedFloat (float value) noexcept;
  46. /** Constructs an MPEValue from a float between -1.0f and 1.0f. */
  47. static MPEValue fromSignedFloat (float value) noexcept;
  48. /** Constructs an MPEValue corresponding to the centre value. */
  49. static MPEValue centreValue() noexcept;
  50. /** Constructs an MPEValue corresponding to the minimum value. */
  51. static MPEValue minValue() noexcept;
  52. /** Constructs an MPEValue corresponding to the maximum value. */
  53. static MPEValue maxValue() noexcept;
  54. /** Retrieves the current value as an integer between 0 and 127.
  55. Information will be lost if the value was initialised with a precision
  56. higher than 7-bit.
  57. */
  58. int as7BitInt() const noexcept;
  59. /** Retrieves the current value as an integer between 0 and 16383.
  60. Resolution will be lost if the value was initialised with a precision
  61. higher than 14-bit.
  62. */
  63. int as14BitInt() const noexcept;
  64. /** Retrieves the current value mapped to a float between -1.0f and 1.0f. */
  65. float asSignedFloat() const noexcept;
  66. /** Retrieves the current value mapped to a float between 0.0f and 1.0f. */
  67. float asUnsignedFloat() const noexcept;
  68. /** Returns true if two values are equal. */
  69. bool operator== (const MPEValue& other) const noexcept;
  70. /** Returns true if two values are not equal. */
  71. bool operator!= (const MPEValue& other) const noexcept;
  72. private:
  73. //==============================================================================
  74. MPEValue (int normalisedValue);
  75. int normalisedValue = 8192;
  76. };
  77. } // namespace juce