1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    The code included in this file is provided under the terms of the ISC license
11    http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12    To use, copy, modify, and/or distribute this software for any purpose with or
13    without fee is hereby granted provided that the above copyright notice and
14    this permission notice appear in all copies.
15 
16    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18    DISCLAIMED.
19 
20   ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 //==============================================================================
27 /**
28     This class represents a single value for any of the MPE
29     dimensions of control. It supports values with 7-bit or 14-bit resolutions
30     (corresponding to 1 or 2 MIDI bytes, respectively). It also offers helper
31     functions to query the value in a variety of representations that can be
32     useful in an audio or MIDI context.
33 
34     @tags{Audio}
35 */
36 class JUCE_API  MPEValue
37 {
38 public:
39     //==============================================================================
40     /** Default constructor.
41 
42         Constructs an MPEValue corresponding to the centre value.
43     */
44     MPEValue() noexcept;
45 
46     /** Constructs an MPEValue from an integer between 0 and 127
47         (using 7-bit precision).
48     */
49     static MPEValue from7BitInt (int value) noexcept;
50 
51     /** Constructs an MPEValue from an integer between 0 and 16383
52         (using 14-bit precision).
53     */
54     static MPEValue from14BitInt (int value) noexcept;
55 
56     /** Constructs an MPEValue corresponding to the centre value. */
57     static MPEValue centreValue() noexcept;
58 
59     /** Constructs an MPEValue corresponding to the minimum value. */
60     static MPEValue minValue() noexcept;
61 
62     /** Constructs an MPEValue corresponding to the maximum value. */
63     static MPEValue maxValue() noexcept;
64 
65     /** Retrieves the current value as an integer between 0 and 127.
66 
67         Information will be lost if the value was initialised with a precision
68         higher than 7-bit.
69     */
70     int as7BitInt() const noexcept;
71 
72     /** Retrieves the current value as an integer between 0 and 16383.
73 
74         Resolution will be lost if the value was initialised with a precision
75         higher than 14-bit.
76     */
77     int as14BitInt() const noexcept;
78 
79     /** Retrieves the current value mapped to a float between -1.0f and 1.0f. */
80     float asSignedFloat() const noexcept;
81 
82     /** Retrieves the current value mapped to a float between 0.0f and 1.0f. */
83     float asUnsignedFloat() const noexcept;
84 
85     /** Returns true if two values are equal. */
86     bool operator== (const MPEValue& other) const noexcept;
87 
88     /** Returns true if two values are not equal. */
89     bool operator!= (const MPEValue& other) const noexcept;
90 
91 private:
92     //==============================================================================
93     MPEValue (int normalisedValue);
94     int normalisedValue = 8192;
95 };
96 
97 } // namespace juce
98