22
22
23
23
namespace midi2 {
24
24
25
+ // / \brief Converts MIDI 2.0 UMP (Universal MIDI Packet) messages to MIDI 1.0 UMP.
26
+ // /
27
+ // / This class provides functionality to convert UMP messages to MIDI 1.0 messages.
28
+ // / It maintains a context that includes a cache for per-note controllers and a FIFO
29
+ // / for output messages.
25
30
class ump_to_midi1 {
26
31
public:
32
+ // / \brief The type of input UMP message.
27
33
using input_type = std::uint32_t ;
34
+ // / \brief The type of output MIDI 1.0 message.
28
35
using output_type = std::uint32_t ;
29
36
30
- // / Checks if the output is empty
37
+ // / \brief Checks if the output is empty
38
+ // / \return True if the output FIFO is empty, false otherwise.
31
39
[[nodiscard]] constexpr bool empty () const { return context_.output .empty (); }
40
+
41
+ // / \brief Pops the front message from the output FIFO.
42
+ // / \return The first message in the output FIFO.
43
+ // / \note This method asserts that the output FIFO is not empty.
32
44
[[nodiscard]] constexpr output_type pop () {
33
45
assert (!empty ());
34
46
return context_.output .pop_front ();
35
47
}
36
48
49
+ // / \brief Pushes an input UMP message for processing.
50
+ // / \param ump The input UMP message.
37
51
void push (input_type const ump) { p_.process_ump (ump); }
38
52
39
53
private:
@@ -47,11 +61,16 @@ class ump_to_midi1 {
47
61
});
48
62
}
49
63
64
+ // / \brief Represents a key for the per-note controller cache.
50
65
struct pn_cache_key {
51
66
constexpr bool operator ==(pn_cache_key const &) const noexcept = default ;
52
67
68
+ // / The group number
53
69
std::uint8_t group : 4 = 0 ;
70
+ // / The channel number
54
71
std::uint8_t channel : 4 = 0 ;
72
+ // / true if the controller is RPN (Registered Parameter Number), false if it represents an NRPN (Non-Registered
73
+ // / Parameter Number).
55
74
bool is_rpn = false ;
56
75
};
57
76
@@ -123,16 +142,43 @@ class ump_to_midi1 {
123
142
}
124
143
static constexpr void sysex7_end (context_type *const ctxt, ump::data64::sysex7_end const &in) { ctxt->push (in); }
125
144
};
126
- // m2cvm messages are translated to m1cvm messages.
145
+
146
+ // / \brief Translated MIDI 2.0 Channel Voice Messages (m2cvm) and translates them to m1cvm messages.
127
147
class m2cvm {
128
148
public:
149
+ // / \brief Translates a MIDI 2.0 note off message to a MIDI 1.0 note off message.
150
+ // / \param ctxt The context for the conversion process.
151
+ // / \param in The input MIDI 2.0 note off message.
129
152
static void note_off (context_type *ctxt, ump::m2cvm::note_off const &in);
153
+
154
+ // / \brief Translates a MIDI 2.0 note on message to a MIDI 1.0 note on message.
155
+ // / \param ctxt The context for the conversion process.
156
+ // / \param in The input MIDI 2.0 note on message.
130
157
static void note_on (context_type *ctxt, ump::m2cvm::note_on const &in);
158
+
159
+ // / \brief Translates a MIDI 2.0 poly pressure message to a MIDI 1.0 poly pressure message.
160
+ // / \param ctxt The context for the conversion process.
161
+ // / \param in The input MIDI 2.0 poly pressure message.
131
162
static void poly_pressure (context_type *ctxt, ump::m2cvm::poly_pressure const &in);
163
+
164
+ // / \brief Translates a MIDI 2.0 program change message to a MIDI 1.0 program change message.
165
+ // / \param ctxt The context for the conversion process.
166
+ // / \param in The input MIDI 2.0 program change message.
132
167
static void program_change (context_type *ctxt, ump::m2cvm::program_change const &in);
133
- static void channel_pressure (context_type *ctxt, ump::m2cvm::channel_pressure const &);
134
168
169
+ // / \brief Translates a MIDI 2.0 channel pressure message to a MIDI 1.0 channel pressure message.
170
+ // / \param ctxt The context for the conversion process.
171
+ // / \param in The input MIDI 2.0 channel pressure message.
172
+ static void channel_pressure (context_type *ctxt, ump::m2cvm::channel_pressure const &in);
173
+
174
+ // / \brief Translates a MIDI 2.0 RPN controller message to a MIDI 1.0 controller message.
175
+ // / \param ctxt The context for the conversion process.
176
+ // / \param in The input MIDI 2.0 RPN controller message.
135
177
static void rpn_controller (context_type *ctxt, ump::m2cvm::rpn_controller const &in);
178
+
179
+ // / \brief Translates a MIDI 2.0 NRPN controller message to a MIDI 1.0 controller message.
180
+ // / \param ctxt The context for the conversion process.
181
+ // / \param in The input MIDI 2.0 NRPN controller message.
136
182
static void nrpn_controller (context_type *ctxt, ump::m2cvm::nrpn_controller const &in);
137
183
138
184
static constexpr void rpn_per_note_controller (context_type const *,
@@ -154,14 +200,27 @@ class ump_to_midi1 {
154
200
static constexpr void per_note_management (context_type const *, ump::m2cvm::per_note_management const &) {
155
201
// do nothing: cannot be translated to MIDI 1
156
202
}
157
- static void control_change (context_type *ctxt, ump::m2cvm::control_change const &);
158
- static void pitch_bend (context_type *ctxt, ump::m2cvm::pitch_bend const &);
203
+
204
+ // / \brief Translates a MIDI 2.0 control change message to a MIDI 1.0 control change message.
205
+ // / \param ctxt The context for the conversion process.
206
+ // / \param in The input MIDI 2.0 control change message.
207
+ static void control_change (context_type *ctxt, ump::m2cvm::control_change const &in);
208
+
209
+ // / @brief Translates a MIDI 2.0 pitch bend message to a MIDI 1.0 pitch bend message.
210
+ // / @param ctxt The context for the conversion process.
211
+ // / @param in The input MIDI 2.0 pitch bend message.
212
+ static void pitch_bend (context_type *ctxt, ump::m2cvm::pitch_bend const &in);
159
213
160
214
static constexpr void per_note_pitch_bend (context_type const *, ump::m2cvm::per_note_pitch_bend const &) {
161
215
// do nothing: cannot be translated to MIDI 1
162
216
}
163
217
164
218
private:
219
+ // / \brief Handles per-note controller messages.
220
+ // / \param ctxt The context for the conversion process.
221
+ // / \param key The key for the per-note controller cache.
222
+ // / \param controller_number The controller number.
223
+ // / \param value The value of the controller.
165
224
static void pn_message (context_type *ctxt, context_type::pn_cache_key const &key,
166
225
std::pair<std::uint8_t , std::uint8_t > const &controller_number, std::uint32_t value);
167
226
};
0 commit comments