Loading...
Searching...
No Matches
MidiDeviceMap.hpp
1#pragma once
2
17#include <optional>
18#include <string>
19#include <string_view>
20#include <vector>
21
22namespace Protocols::MIDIDevices
23{
24
25enum class MessageType
26{
27 CC,
28 CC14,
29 NRPN,
30 RPN,
31 Note,
32 PitchBend,
33 Aftertouch,
34 PolyAftertouch,
35 Program
36};
37
38enum class Kind
39{
40 Fader,
41 Knob,
42 Encoder,
43 Button,
44 Pad,
45 Key,
46 Wheel,
47 Ribbon,
48 XY,
49 Parameter,
50 Other
51};
52
53enum class Direction
54{
56 In,
58 Out,
59 Both
60};
61
62enum class ValueMode
63{
64 Absolute,
65 Relative
66};
67
73enum class Encoding
74{
75 TwosComplement,
76 SignedBit,
78 SignedBit2,
79 BinaryOffset
80};
81
84struct Bank
85{
86 int msb{-1};
87 int lsb{-1};
88
89 bool empty() const noexcept { return msb < 0 && lsb < 0; }
90 bool operator==(const Bank&) const noexcept = default;
91};
92
93struct Message
94{
95 MessageType type{MessageType::CC};
96
102 std::vector<int> channels;
103
106 int number{-1};
107
109 int lsb{-1};
110
113
116 int rangeFrom{-1};
117 int rangeTo{-1};
118
119 bool hasRange() const noexcept { return rangeFrom >= 0 && rangeTo >= rangeFrom; }
120};
121
123struct Label
124{
125 int from{};
126 int to{};
127 std::string name;
128};
129
138struct Scale
139{
142 std::optional<double> min;
143 std::optional<double> max;
144
147 std::string from;
148 std::string to;
149
151 std::string unit;
152
153 bool empty() const noexcept
154 {
155 return !min && !max && from.empty() && to.empty();
156 }
157};
158
159struct Value
160{
161 ValueMode mode{ValueMode::Absolute};
162
164 std::optional<Encoding> encoding;
165
167 std::optional<int> min;
168 std::optional<int> max;
169 std::optional<int> def;
170
173 std::vector<int> sends;
174
176 bool bipolar{};
177
180
181 std::vector<Label> labels;
182
185 std::optional<bool> momentary;
186
189 bool inverted{};
190
193 bool pickup{};
194};
195
204struct Layer
205{
207 std::string name;
208
211 std::string of;
212
213 bool empty() const noexcept { return name.empty(); }
214};
215
218{
219 int program{};
220 Bank bank;
221};
222
224{
225 std::string name;
226 Kind kind{Kind::Other};
227
229 std::vector<std::string> group;
230
231 Direction direction{Direction::In};
232
233 Message message;
234
237 std::optional<Message> feedback;
238
239 Value value;
240
243 std::vector<Condition> when;
244
247
248 std::string description;
249};
250
252struct Preset
253{
255 std::string name;
256
263 std::vector<std::string> sysex;
264
265 bool empty() const noexcept { return name.empty() && sysex.empty(); }
266};
267
270struct Source
271{
273 std::string format;
274
276 std::string license;
277
283 std::string redistribution;
284
286 std::vector<std::string> notices;
287
289 std::vector<std::string> authors;
290
292 std::string project;
293 std::string url;
294
296 std::string path;
297};
298
300{
301 std::string manufacturer;
302 std::string model;
303 std::string description;
304
306 std::string requirement;
307
308 Preset preset;
309
311 std::vector<std::string> match;
312
313 Source source;
314
315 std::vector<Control> controls;
316
318 std::vector<std::string> warnings;
319
322 std::string label() const;
323
324 bool empty() const noexcept { return controls.empty(); }
325};
326
338bool isNoteName(const Control& c) noexcept;
339
347bool namesSomething(std::string_view s) noexcept;
348
355std::string deviceNodeName(const DeviceMap& map);
356
358std::pair<int, int> naturalRange(MessageType t) noexcept;
359
362std::pair<int, int> resolvedRange(const Value& v, MessageType t) noexcept;
363
371int decodeRelative(int byte, Encoding e) noexcept;
372
382int encodeRelative(int delta, Encoding e) noexcept;
383
392{
393 std::string manufacturer;
394 std::string model;
395 std::string description;
396 std::string requirement;
397 Preset preset;
398 std::vector<std::string> match;
399
400 std::string label() const;
401};
402
410std::optional<DeviceHeader> parseDeviceMapHeader(std::string_view text);
411
420std::optional<DeviceMap> parseDeviceMap(std::string_view text);
421
422std::string_view toString(Kind) noexcept;
423std::string_view toString(MessageType) noexcept;
424
425}
Definition MidiDeviceMap.hpp:85
The control exists only while this program is selected.
Definition MidiDeviceMap.hpp:218
Definition MidiDeviceMap.hpp:224
std::vector< Condition > when
Definition MidiDeviceMap.hpp:243
Layer layer
Empty unless the control is a modifier layer of another.
Definition MidiDeviceMap.hpp:246
std::vector< std::string > group
Already split into levels, whichever form the file used.
Definition MidiDeviceMap.hpp:229
std::optional< Message > feedback
Definition MidiDeviceMap.hpp:237
Definition MidiDeviceMap.hpp:392
Definition MidiDeviceMap.hpp:300
std::string label() const
Definition MidiDeviceMap.cpp:670
std::vector< std::string > warnings
What the reader could not use, and why.
Definition MidiDeviceMap.hpp:318
std::string requirement
A reconfiguration the map depends on that is not a selectable preset.
Definition MidiDeviceMap.hpp:306
std::vector< std::string > match
Substrings to match against a live port's name, most specific first.
Definition MidiDeviceMap.hpp:311
A named value range. from == to names a single value.
Definition MidiDeviceMap.hpp:124
Definition MidiDeviceMap.hpp:205
std::string of
Definition MidiDeviceMap.hpp:211
std::string name
The modifier as printed on the panel: "Shift", "Shift+Hotcue".
Definition MidiDeviceMap.hpp:207
Definition MidiDeviceMap.hpp:94
Bank bank
program only.
Definition MidiDeviceMap.hpp:112
std::vector< int > channels
Definition MidiDeviceMap.hpp:102
int rangeFrom
Definition MidiDeviceMap.hpp:116
int number
Definition MidiDeviceMap.hpp:106
int lsb
The second CC of a CC14, or the NRPN/RPN parameter LSB.
Definition MidiDeviceMap.hpp:109
What puts the device into the configuration the document describes.
Definition MidiDeviceMap.hpp:253
std::vector< std::string > sysex
Definition MidiDeviceMap.hpp:263
std::string name
The name the user selects on the hardware.
Definition MidiDeviceMap.hpp:255
Definition MidiDeviceMap.hpp:139
std::optional< double > min
Definition MidiDeviceMap.hpp:142
std::string unit
Verbatim as the source wrote it: "%", "dB", "Hz", "semitones".
Definition MidiDeviceMap.hpp:151
std::string from
Definition MidiDeviceMap.hpp:147
Definition MidiDeviceMap.hpp:271
std::vector< std::string > notices
Copyright and permission notices found in the source, verbatim.
Definition MidiDeviceMap.hpp:286
std::string format
ardour-midi-binding-map, midnam, mixxx-controller-mapping, ...
Definition MidiDeviceMap.hpp:273
std::vector< std::string > authors
Everyone credited, as the source credited them.
Definition MidiDeviceMap.hpp:289
std::string redistribution
Definition MidiDeviceMap.hpp:283
std::string project
The project the description was converted from, and where it lives.
Definition MidiDeviceMap.hpp:292
std::string license
An SPDX identifier, or NOASSERTION where no grant was ever made.
Definition MidiDeviceMap.hpp:276
std::string path
The file within that project.
Definition MidiDeviceMap.hpp:296
Definition MidiDeviceMap.hpp:160
std::optional< int > min
Absent means the message type's natural range.
Definition MidiDeviceMap.hpp:167
std::vector< int > sends
Definition MidiDeviceMap.hpp:173
bool inverted
Definition MidiDeviceMap.hpp:189
Scale scale
Empty unless the source says what the numbers mean.
Definition MidiDeviceMap.hpp:179
std::optional< bool > momentary
Definition MidiDeviceMap.hpp:185
bool pickup
Definition MidiDeviceMap.hpp:193
bool bipolar
The midpoint is neutral: pan, detune, pitch bend.
Definition MidiDeviceMap.hpp:176
std::optional< Encoding > encoding
Set whenever mode is Relative; the format requires it there.
Definition MidiDeviceMap.hpp:164