OpenShot Library | OpenShotAudio 0.2.2
juce_MidiRPN.h
1
2/** @weakgroup juce_audio_basics-midi
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/** Represents a MIDI RPN (registered parameter number) or NRPN (non-registered
32 parameter number) message.
33
34 @tags{Audio}
35*/
37{
38 /** Midi channel of the message, in the range 1 to 16. */
40
41 /** The 14-bit parameter index, in the range 0 to 16383 (0x3fff). */
43
44 /** The parameter value, in the range 0 to 16383 (0x3fff).
45 If the message contains no value LSB, the value will be in the range
46 0 to 127 (0x7f).
47 */
48 int value;
49
50 /** True if this message is an NRPN; false if it is an RPN. */
51 bool isNRPN;
52
53 /** True if the value uses 14-bit resolution (LSB + MSB); false if
54 the value is 7-bit (MSB only).
55 */
57};
58
59//==============================================================================
60/**
61 Parses a stream of MIDI data to assemble RPN and NRPN messages from their
62 constituent MIDI CC messages.
63
64 The detector uses the following parsing rules: the parameter number
65 LSB/MSB can be sent/received in either order and must both come before the
66 parameter value; for the parameter value, LSB always has to be sent/received
67 before the value MSB, otherwise it will be treated as 7-bit (MSB only).
68
69 @tags{Audio}
70*/
72{
73public:
74 /** Constructor. */
75 MidiRPNDetector() noexcept;
76
77 /** Destructor. */
78 ~MidiRPNDetector() noexcept;
79
80 /** Resets the RPN detector's internal state, so that it forgets about
81 previously received MIDI CC messages.
82 */
83 void reset() noexcept;
84
85 //==============================================================================
86 /** Takes the next in a stream of incoming MIDI CC messages and returns true
87 if it forms the last of a sequence that makes an RPN or NPRN.
88
89 If this returns true, then the RPNMessage object supplied will be
90 filled-out with the message's details.
91 (If it returns false then the RPNMessage object will be unchanged).
92 */
93 bool parseControllerMessage (int midiChannel,
94 int controllerNumber,
95 int controllerValue,
96 MidiRPNMessage& result) noexcept;
97
98private:
99 //==============================================================================
100 struct ChannelState
101 {
102 ChannelState() noexcept;
103 bool handleController (int channel, int controllerNumber,
104 int value, MidiRPNMessage&) noexcept;
105 void resetValue() noexcept;
106 bool sendIfReady (int channel, MidiRPNMessage&) noexcept;
107
108 uint8 parameterMSB, parameterLSB, valueMSB, valueLSB;
109 bool isNRPN;
110 };
111
112 //==============================================================================
113 ChannelState states[16];
114
115 JUCE_LEAK_DETECTOR (MidiRPNDetector)
116};
117
118//==============================================================================
119/**
120 Generates an appropriate sequence of MIDI CC messages to represent an RPN
121 or NRPN message.
122
123 This sequence (as a MidiBuffer) can then be directly sent to a MidiOutput.
124
125 @tags{Audio}
126*/
128{
129public:
130 //==============================================================================
131 /** Generates a MIDI sequence representing the given RPN or NRPN message. */
132 static MidiBuffer generate (MidiRPNMessage message);
133
134 //==============================================================================
135 /** Generates a MIDI sequence representing an RPN or NRPN message with the
136 given parameters.
137
138 @param channel The MIDI channel of the RPN/NRPN message.
139
140 @param parameterNumber The parameter number, in the range 0 to 16383.
141
142 @param value The parameter value, in the range 0 to 16383, or
143 in the range 0 to 127 if sendAs14BitValue is false.
144
145 @param isNRPN Whether you need a MIDI RPN or NRPN sequence (RPN is default).
146
147 @param use14BitValue If true (default), the value will have 14-bit precision
148 (two MIDI bytes). If false, instead the value will have
149 7-bit precision (a single MIDI byte).
150 */
151 static MidiBuffer generate (int channel,
152 int parameterNumber,
153 int value,
154 bool isNRPN = false,
155 bool use14BitValue = true);
156};
157
158} // namespace juce
159
160/** @}*/
Holds a sequence of time-stamped midi events.
Parses a stream of MIDI data to assemble RPN and NRPN messages from their constituent MIDI CC message...
Definition: juce_MidiRPN.h:72
Generates an appropriate sequence of MIDI CC messages to represent an RPN or NRPN message.
Definition: juce_MidiRPN.h:128
bool isNRPN
True if this message is an NRPN; false if it is an RPN.
Definition: juce_MidiRPN.h:51
bool is14BitValue
True if the value uses 14-bit resolution (LSB + MSB); false if the value is 7-bit (MSB only).
Definition: juce_MidiRPN.h:56
int channel
Midi channel of the message, in the range 1 to 16.
Definition: juce_MidiRPN.h:39
int parameterNumber
The 14-bit parameter index, in the range 0 to 16383 (0x3fff).
Definition: juce_MidiRPN.h:42
int value
The parameter value, in the range 0 to 16383 (0x3fff).
Definition: juce_MidiRPN.h:48
Represents a MIDI RPN (registered parameter number) or NRPN (non-registered parameter number) message...
Definition: juce_MidiRPN.h:37
#define JUCE_API
This macro is added to all JUCE public class declarations.