Controller190awTests.inc 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. // Round 190aw: the MIDI controller layer (core/ControllerProfile.h, core/ControllerSession.h). No hardware: the tests
  2. // feed the bytes a device sends and check what reaches the Surface and which bytes go back.
  3. namespace c190aw
  4. {
  5. using namespace lynx::controller;
  6. // LYNX as the layer sees it, with a log of what was asked of it.
  7. struct FakeSurface final : Surface
  8. {
  9. struct Track
  10. {
  11. std::string name;
  12. float volume = 0.8f, pan = 0.5f;
  13. bool mute = false, solo = false, arm = false;
  14. };
  15. std::vector<Track> tracks; // 0 = Master
  16. std::vector<Track> rack;
  17. std::vector<float> params;
  18. std::vector<bool> stepsOn = std::vector<bool> (16, false);
  19. int selectedTrack = 1, selected = 0;
  20. bool playing = false, recording = false, patternMode = true, click = false;
  21. std::set<std::pair<int, int>> links; // (cc, channel) linked by hand
  22. mutable std::vector<std::string> log;
  23. explicit FakeSurface (int inserts = 20, int channelCount = 4, int paramCount = 20)
  24. {
  25. tracks.resize ((std::size_t) inserts + 1);
  26. tracks[0].name = "Master";
  27. for (int i = 1; i <= inserts; ++i)
  28. tracks[(std::size_t) i].name = "Insert " + std::to_string (i);
  29. rack.resize ((std::size_t) channelCount);
  30. for (int i = 0; i < channelCount; ++i)
  31. rack[(std::size_t) i].name = "Chan " + std::to_string (i + 1);
  32. params.assign ((std::size_t) paramCount, 0.25f);
  33. }
  34. static std::string f (float v)
  35. {
  36. char text[32];
  37. std::snprintf (text, sizeof (text), "%.3f", (double) v);
  38. return text;
  39. }
  40. bool did (const std::string& what) const { return std::find (log.begin(), log.end(), what) != log.end(); }
  41. void command (Command c) override
  42. {
  43. log.push_back ("command " + std::to_string ((int) c));
  44. if (c == Command::play) playing = ! playing;
  45. if (c == Command::stop) playing = false;
  46. if (c == Command::record) recording = ! recording;
  47. if (c == Command::loop) patternMode = ! patternMode;
  48. if (c == Command::metronome) click = ! click;
  49. }
  50. bool lit (Command c) const override
  51. {
  52. switch (c)
  53. {
  54. case Command::play: return playing;
  55. case Command::stop: return ! playing;
  56. case Command::record: return recording;
  57. case Command::loop: return patternMode;
  58. case Command::metronome: return click;
  59. default: return false;
  60. }
  61. }
  62. void jog (int steps) override { log.push_back ("jog " + std::to_string (steps)); }
  63. int mixerTracks() const override { return (int) tracks.size(); }
  64. int selectedMixerTrack() const override { return selectedTrack; }
  65. void selectMixerTrack (int t) override { selectedTrack = t; log.push_back ("select track " + std::to_string (t)); }
  66. std::string mixerName (int t) const override { return tracks[(std::size_t) t].name; }
  67. float mixerValue (int t, Param p) const override { return p == Param::volume ? tracks[(std::size_t) t].volume : tracks[(std::size_t) t].pan; }
  68. void setMixerValue (int t, Param p, float v) override
  69. {
  70. (p == Param::volume ? tracks[(std::size_t) t].volume : tracks[(std::size_t) t].pan) = v;
  71. log.push_back (std::string (p == Param::volume ? "volume " : "pan ") + std::to_string (t) + " " + f (v));
  72. }
  73. bool mixerSwitch (int t, Switch s) const override
  74. {
  75. const auto& k = tracks[(std::size_t) t];
  76. return s == Switch::mute ? k.mute : s == Switch::solo ? k.solo : k.arm;
  77. }
  78. void setMixerSwitch (int t, Switch s, bool on) override
  79. {
  80. auto& k = tracks[(std::size_t) t];
  81. (s == Switch::mute ? k.mute : s == Switch::solo ? k.solo : k.arm) = on;
  82. log.push_back (std::string (s == Switch::mute ? "mute " : s == Switch::solo ? "solo " : "arm ") + std::to_string (t) + (on ? " on" : " off"));
  83. }
  84. int channels() const override { return (int) rack.size(); }
  85. int selectedChannel() const override { return selected; }
  86. void selectChannel (int c) override { selected = c; log.push_back ("select channel " + std::to_string (c)); }
  87. std::string channelName (int c) const override { return rack[(std::size_t) c].name; }
  88. float channelValue (int c, Param p) const override { return p == Param::volume ? rack[(std::size_t) c].volume : rack[(std::size_t) c].pan; }
  89. void setChannelValue (int c, Param p, float v) override
  90. {
  91. (p == Param::volume ? rack[(std::size_t) c].volume : rack[(std::size_t) c].pan) = v;
  92. log.push_back (std::string (p == Param::volume ? "channel volume " : "channel pan ") + std::to_string (c) + " " + f (v));
  93. }
  94. bool channelMuted (int c) const override { return rack[(std::size_t) c].mute; }
  95. void setChannelMuted (int c, bool m) override { rack[(std::size_t) c].mute = m; log.push_back ("channel mute " + std::to_string (c) + (m ? " on" : " off")); }
  96. std::string pluginName() const override { return "Synth"; }
  97. int pluginParams() const override { return (int) params.size(); }
  98. std::string pluginParamName (int i) const override { return "Par " + std::to_string (i + 1); }
  99. float pluginParam (int i) const override { return params[(std::size_t) i]; }
  100. void setPluginParam (int i, float v) override { params[(std::size_t) i] = v; log.push_back ("param " + std::to_string (i) + " " + f (v)); }
  101. void playNote (int key, float velocity, bool on) override { log.push_back (std::string (on ? "note on " : "note off ") + std::to_string (key) + " " + f (velocity)); }
  102. int steps() const override { return (int) stepsOn.size(); }
  103. bool step (int i) const override { return stepsOn[(std::size_t) i]; }
  104. void setStep (int i, bool on) override { stepsOn[(std::size_t) i] = on; log.push_back ("step " + std::to_string (i) + (on ? " on" : " off")); }
  105. bool linkedByHand (int cc, int channel) const override { return links.count ({ cc, channel }) != 0 || links.count ({ cc, -1 }) != 0; }
  106. };
  107. // what was sent to a device, as hex ("90 5E 7F")
  108. struct Wire
  109. {
  110. std::vector<std::string> messages;
  111. Send send()
  112. {
  113. return [this] (const std::uint8_t* bytes, std::size_t size) {
  114. std::string text;
  115. for (std::size_t i = 0; i < size; ++i)
  116. {
  117. char hex[4];
  118. std::snprintf (hex, sizeof (hex), "%02X", bytes[i]);
  119. text += (i != 0 ? " " : "") + std::string (hex);
  120. }
  121. messages.push_back (text);
  122. };
  123. }
  124. bool has (const std::string& m) const { return std::find (messages.begin(), messages.end(), m) != messages.end(); }
  125. int count (const std::string& prefix) const
  126. {
  127. return (int) std::count_if (messages.begin(), messages.end(), [&] (const std::string& m) { return m.rfind (prefix, 0) == 0; });
  128. }
  129. void clear() { messages.clear(); }
  130. };
  131. inline bool feed (Session& s, FakeSurface& surface, Shared& shared, std::initializer_list<int> bytes)
  132. {
  133. std::vector<std::uint8_t> b;
  134. for (const auto v : bytes)
  135. b.push_back ((std::uint8_t) v);
  136. return s.input (b.data(), b.size(), surface, shared);
  137. }
  138. // the text a display sysex carries after its header ("F0 00 00 66 14 12 <pos>")
  139. inline std::string lcdText (const std::string& hexMessage, int headerBytes)
  140. {
  141. std::string out;
  142. std::istringstream in (hexMessage);
  143. std::string byte;
  144. for (int i = 0; in >> byte; ++i)
  145. if (i >= headerBytes && byte != "F7")
  146. out.push_back ((char) std::strtol (byte.c_str(), nullptr, 16));
  147. return out;
  148. }
  149. // A motor-fader surface in the Mackie Control style and a plain knob box, written as profile files.
  150. inline const char* motorProfile = R"(# test profile
  151. [device]
  152. name = Test motor surface
  153. maker = Test
  154. source = written for the tests
  155. match = Test Control*, *Motor*
  156. exclude = *XT*
  157. group = test
  158. strips = 8
  159. layers = pan, plugin
  160. [init]
  161. send = F0 00 00 66 14 00 F7
  162. [exit]
  163. send = F0 00 00 66 14 08 F7
  164. [input]
  165. bend ch 1-8 = mixer.volume
  166. bend ch 9 = master.volume
  167. note 104-111 = mixer.touch
  168. note 112 = master.touch
  169. cc 16-23 ch 1 = mixer.pan mode=sign step=0.02 layer=pan
  170. cc 16-23 ch 1 = plugin.param mode=sign step=0.01 layer=plugin
  171. cc 60 ch 1 = transport.jog mode=sign
  172. note 0-7 ch 1 = mixer.arm
  173. note 8-15 ch 1 = mixer.solo
  174. note 16-23 ch 1 = mixer.mute
  175. note 24-31 ch 1 = mixer.select
  176. note 42 ch 1 = layer pan
  177. note 43 ch 1 = layer plugin
  178. note 46 ch 1 = mixer.bank.left
  179. note 47 ch 1 = mixer.bank.right
  180. note 48 ch 1 = mixer.strip.left
  181. note 49 ch 1 = mixer.strip.right
  182. note 44 ch 1 = plugin.page.left
  183. note 45 ch 1 = plugin.page.right
  184. note 86 ch 1 = transport.loop
  185. note 89 ch 1 = transport.metronome
  186. note 93 ch 1 = transport.stop
  187. note 94 ch 1 = transport.play
  188. note 95 ch 1 = transport.record
  189. [feedback]
  190. mixer.volume = bend ch 1-8
  191. master.volume = bend ch 9
  192. mixer.pan = cc 48-55 ch 1 ring=pan layer=pan
  193. plugin.param = cc 48-55 ch 1 ring=wrap layer=plugin
  194. mixer.arm = note 0-7 ch 1
  195. mixer.solo = note 8-15 ch 1
  196. mixer.mute = note 16-23 ch 1
  197. mixer.select = note 24-31 ch 1
  198. layer pan = note 42 ch 1
  199. layer plugin = note 43 ch 1
  200. transport.loop = note 86 ch 1
  201. transport.metronome = note 89 ch 1
  202. transport.stop = note 93 ch 1
  203. transport.play = note 94 ch 1
  204. transport.record = note 95 ch 1
  205. [display]
  206. write = F0 00 00 66 14 12 {pos} {text} F7
  207. width = 7
  208. cells = 8
  209. row 1 = mixer.name layer=pan
  210. row 2 = mixer.pan layer=pan
  211. row 1 = plugin.param.name layer=plugin
  212. row 2 = plugin.param.value layer=plugin
  213. )";
  214. inline const char* knobProfile = R"([device]
  215. name = Test knob box
  216. match = Knob Box*
  217. [input]
  218. cc 0-7 ch 1 = mixer.volume # sliders
  219. cc 16-23 ch 1 = plugin.param # knobs
  220. cc 32-39 ch 1 = mixer.solo
  221. cc 58 ch 1 = mixer.bank.left
  222. cc 59 ch 1 = mixer.bank.right
  223. cc 41 ch 1 = transport.play
  224. cc 70 = channel.volume selected
  225. note 36-43 ch 10 = pad.step
  226. note 60-67 ch 10 = pad.note key=36
  227. cc 9 ch 16 value 2 = transport.record
  228. note 98 ch 1 = ignore # a shift key
  229. cc 0-127 ch 16 = ignore # everything else on the control channel
  230. [feedback]
  231. mixer.solo = cc 32-39 ch 1
  232. transport.play = cc 41 ch 1
  233. pad.step = note 36-43 ch 10 on=3 off=1
  234. )";
  235. inline std::shared_ptr<const Profile> profileOf (const char* text, const char* id)
  236. {
  237. auto parsed = parseProfile (text, id);
  238. for (const auto& e : parsed.errors)
  239. std::printf (" profile %s: %s\n", id, e.c_str());
  240. return std::make_shared<const Profile> (std::move (parsed.profile));
  241. }
  242. } // namespace c190aw
  243. TEST (controller190aw_profile_file_parses_and_reports_errors_by_line)
  244. {
  245. using namespace c190aw;
  246. const auto parsed = parseProfile (motorProfile, "motor");
  247. CHECK (parsed.ok());
  248. const auto& p = parsed.profile;
  249. CHECK (p.id == "motor" && p.name == "Test motor surface" && p.maker == "Test" && p.group == "test" && p.strips == 8);
  250. CHECK (p.sources.size() == 1 && p.match.size() == 2 && p.exclude.size() == 1 && p.layers.size() == 2);
  251. CHECK (p.init.size() == 1 && p.init[0].size() == 7 && p.init[0][5] == 0x00 && p.exit.size() == 1 && p.exit[0][5] == 0x08);
  252. CHECK (p.bindings.size() == 24 && p.feedback.size() == 15 && p.display.rows.size() == 4);
  253. // ranges: 8 pitch bends over channels, 8 notes over numbers
  254. const auto& faders = p.bindings[0];
  255. CHECK (faders.message.kind == MessageKind::bend && faders.message.channelRange && faders.message.count == 8 && faders.action == Action::mixerVolume);
  256. CHECK (! faders.pickup); // (a pitch-bend fader is a motor fader unless the file says pickup=on)
  257. CHECK (faders.message.element (MessageKind::bend, 3, 0) == 3 && faders.message.element (MessageKind::bend, 8, 0) == -1);
  258. const auto& pots = p.bindings[4];
  259. CHECK (pots.mode == ValueMode::relativeSign && pots.layer == 0 && std::abs (pots.step - 0.02f) < 1e-6f && pots.message.channel == 0);
  260. CHECK (pots.message.element (MessageKind::cc, 0, 18) == 2 && pots.message.element (MessageKind::cc, 1, 18) == -1
  261. && pots.message.element (MessageKind::note, 0, 18) == -1);
  262. CHECK (p.bindings[5].layer == 1 && p.bindings[5].action == Action::pluginParam);
  263. CHECK (p.feedback[2].encoding == Encoding::ringPan && p.feedback[2].layer == 0 && p.feedback[3].encoding == Encoding::ringWrap);
  264. CHECK (p.display.width == 7 && p.display.cells == 8 && p.display.write.size() == 9 && p.display.write[6] == Display::pos
  265. && p.display.write[7] == Display::text && p.display.write[8] == 0xF7);
  266. // the knob box: any channel, a value filter, 'selected', inline comments, LED values
  267. const auto knobs = parseProfile (knobProfile, "knobs");
  268. CHECK (knobs.ok());
  269. CHECK (knobs.profile.bindings.size() == 12 && knobs.profile.group.empty());
  270. CHECK (knobs.profile.bindings[0].pickup && knobs.profile.bindings[0].mode == ValueMode::absolute);
  271. CHECK (knobs.profile.bindings[6].message.channel == -1 && knobs.profile.bindings[6].strip == selectedStrip);
  272. CHECK (knobs.profile.bindings[8].key == 36 && knobs.profile.bindings[9].value == 2 && knobs.profile.bindings[9].message.channel == 15);
  273. CHECK (knobs.profile.feedback[2].on == 3 && knobs.profile.feedback[2].off == 1);
  274. // errors name their line; a file with errors is not a profile
  275. const auto bad = parseProfile ("[device]\nname = Bad\n[input]\ncc 200 = mixer.volume\ncc 7 = mixer.volum\nnote 1-4 ch 1-4 = mixer.mute\n"
  276. "cc 1 = transport.play 3\ncc 2 = mixer.pan mode=fast\ncc 3 = layer nowhere\n[feedback]\nmixer.mute = note 5\n[nonsense]\n",
  277. "bad");
  278. CHECK (! bad.ok());
  279. CHECK (bad.errors.size() == 8);
  280. auto startsWith = [&] (std::size_t i, const char* prefix) { return i < bad.errors.size() && bad.errors[i].rfind (prefix, 0) == 0; };
  281. CHECK (startsWith (0, "line 4:") && startsWith (1, "line 5: unknown action 'mixer.volum'") && startsWith (2, "line 6:") && startsWith (3, "line 7:")
  282. && startsWith (4, "line 8:") && startsWith (5, "line 9:") && startsWith (6, "line 11:") && startsWith (7, "line 12:"));
  283. CHECK (! parseProfile ("", "empty").ok());
  284. CHECK (! parseProfile ("[device]\nmaker = Nobody\n", "noname").ok());
  285. CHECK (! parseProfile ("[device]\nname = X\n[display]\nrow 1 = mixer.name\n", "nowrite").ok());
  286. // a library: the user's file replaces a built-in of the same id; a broken file is left out with its errors;
  287. // extends takes the parent's maps and its own name and patterns
  288. Library lib;
  289. CHECK (lib.add (motorProfile, "motor", false) && lib.add (knobProfile, "knobs", false));
  290. CHECK (! lib.add ("[device]\nname = Broken\n[input]\ncc x = mixer.pan\n", "broken", true) && lib.profiles.size() == 2 && lib.errors.size() == 1
  291. && lib.errors[0].rfind ("broken: line 4:", 0) == 0);
  292. CHECK (lib.add ("[device]\nname = Clone keyboard\nmatch = Clone 49*\nextends = motor\nsource = the clone's manual\n", "clone", true));
  293. const auto clone = lib.find ("clone");
  294. CHECK (clone != nullptr && clone->name == "Clone keyboard" && clone->user && clone->bindings.size() == 24 && clone->match.size() == 1
  295. && clone->match[0] == "Clone 49*" && clone->sources.size() == 2 && clone->group == "test");
  296. CHECK (! lib.add ("[device]\nname = Orphan\nextends = nothing\n", "orphan", true));
  297. CHECK (lib.add (std::string (knobProfile) + "\n[device]\nname = My knob box\n", "knobs", true) && lib.profiles.size() == 3
  298. && lib.find ("knobs")->name == "My knob box" && lib.find ("knobs")->user);
  299. }
  300. TEST (controller190aw_detects_by_port_name_and_follows_the_setting)
  301. {
  302. using namespace c190aw;
  303. Library lib;
  304. lib.add (motorProfile, "motor", false);
  305. lib.add (knobProfile, "knobs", false);
  306. lib.add ("[device]\nname = Motor XT\nmatch = *Control XT*\nextends = motor\n", "motor-xt", false);
  307. CHECK (matchScore ({ "Test Control*" }, "test control usb") > 0 && matchScore ({ "Test Control*" }, "My Test Control") == 0);
  308. CHECK (matchScore ({ "*Motor*", "Big Motor Desk" }, "Big Motor Desk") > matchScore ({ "*Motor*" }, "Big Motor Desk"));
  309. CHECK (matchScore ({}, "anything") == 0 && matchScore ({ "*" }, "anything") > 0);
  310. CHECK (lib.detect ("Test Control") == lib.find ("motor"));
  311. CHECK (lib.detect ("Test Control XT") == lib.find ("motor-xt")); // (excluded by the first, matched by the second)
  312. CHECK (lib.detect ("KNOB BOX 2") == lib.find ("knobs"));
  313. CHECK (lib.detect ("Some Piano") == nullptr);
  314. // the setting: "" detects, "generic" turns the profile off, an id forces it (also on a port that does not match)
  315. CHECK (lib.resolve ("", "Test Control") == lib.find ("motor"));
  316. CHECK (lib.resolve (genericChoice, "Test Control") == nullptr);
  317. CHECK (lib.resolve ("knobs", "Some Piano") == lib.find ("knobs"));
  318. CHECK (lib.resolve ("gone", "Test Control") == nullptr);
  319. // a user profile wins a tie against a built-in one
  320. lib.add ("[device]\nname = Mine\nmatch = Knob Box*\n[input]\ncc 1 = transport.play\n", "mine", true);
  321. CHECK (lib.detect ("Knob Box") == lib.find ("mine"));
  322. // the output port of an input port
  323. const std::vector<std::string> outs { "Launch 49", "MIDIOUT2 (Launch 49)", "Desk DAW In", "Box MIDI In", "Thing Out", "Other" };
  324. CHECK (pairedOutput ("Launch 49", outs) == "Launch 49");
  325. CHECK (pairedOutput ("MIDIIN2 (Launch 49)", outs) == "MIDIOUT2 (Launch 49)");
  326. CHECK (pairedOutput ("Desk DAW Out", outs) == "Desk DAW In");
  327. CHECK (pairedOutput ("Box MIDI Out", outs) == "Box MIDI In");
  328. CHECK (pairedOutput ("Thing In", outs) == "Thing Out");
  329. CHECK (pairedOutput ("Nothing", outs).empty() && pairedOutput ("", outs).empty());
  330. }
  331. TEST (controller190aw_motor_faders_vpots_leds_and_lcd_round_trip)
  332. {
  333. using namespace c190aw;
  334. FakeSurface lynx;
  335. lynx.tracks[2].mute = true;
  336. lynx.tracks[3].pan = 0.0f;
  337. lynx.selectedTrack = 4;
  338. Shared shared;
  339. Session s (profileOf (motorProfile, "motor"), 0);
  340. Wire wire;
  341. // opening: the init message, then every fader, ring, LED and display cell
  342. s.open (lynx, shared, wire.send());
  343. CHECK (! wire.messages.empty() && wire.messages[0] == "F0 00 00 66 14 00 F7");
  344. // insert 1 at 0.8: 0.8 × 1023 = 818 → << 4 = 13088 = 0x3320 → LSB 0x20, MSB 0x66
  345. CHECK (wire.has ("E0 20 66") && wire.has ("E7 20 66") && wire.has ("E8 20 66"));
  346. CHECK (wire.has ("90 11 7F") && wire.has ("90 10 00")); // mute LED of strip 2 on, strip 1 off
  347. CHECK (wire.has ("90 1B 7F") && wire.has ("90 18 00")); // select LED of strip 4
  348. CHECK (wire.has ("B0 30 16") && wire.has ("B0 32 11")); // rings: centre (0x10 | 6), strip 3 hard left (0x10 | 1)
  349. CHECK (wire.has ("90 2A 7F") && wire.has ("90 2B 00")); // the pan layer's LED
  350. CHECK (wire.has ("90 5D 7F") && wire.has ("90 5E 00") && wire.has ("90 56 7F")); // stopped, not playing, pattern mode
  351. CHECK (wire.count ("F0 00 00 66 14 12") == 16);
  352. auto lcd = [&] (int pos) {
  353. char head[40];
  354. std::snprintf (head, sizeof (head), "F0 00 00 66 14 12 %02X ", pos);
  355. for (const auto& m : wire.messages)
  356. if (m.rfind (head, 0) == 0)
  357. return lcdText (m, 7);
  358. return std::string ("<none>");
  359. };
  360. CHECK (lcd (0) == "Insert " && lcd (7) == "Insert " && lcd (56) == "C " && lcd (56 + 14) == "L100 ");
  361. // nothing changed: nothing is sent
  362. wire.clear();
  363. s.refresh (lynx, shared, wire.send());
  364. CHECK (wire.messages.empty());
  365. // a fader moves on the device (touch, move, release): LYNX follows, sends nothing while it is held and the
  366. // position once it is let go
  367. lynx.log.clear();
  368. CHECK (feed (s, lynx, shared, { 0x90, 104, 127 }));
  369. CHECK (feed (s, lynx, shared, { 0xE0, 0x00, 0x40 })); // 8192 / 16383
  370. CHECK (lynx.did ("volume 1 0.500") && std::abs (lynx.tracks[1].volume - 0.50003f) < 1e-3f);
  371. s.refresh (lynx, shared, wire.send());
  372. CHECK (wire.messages.empty());
  373. CHECK (feed (s, lynx, shared, { 0x90, 104, 0 }));
  374. s.refresh (lynx, shared, wire.send());
  375. CHECK (wire.messages.size() == 1 && wire.messages[0] == "E0 00 40"); // 0.50003 × 1023 = 512 → 8192
  376. // a fader moved in LYNX (mouse, automation): the motor follows; the master too
  377. wire.clear();
  378. lynx.tracks[5].volume = 1.0f;
  379. lynx.tracks[0].volume = 0.0f;
  380. s.refresh (lynx, shared, wire.send());
  381. CHECK (wire.messages.size() == 2 && wire.has ("E4 70 7F") && wire.has ("E8 00 00"));
  382. CHECK (feed (s, lynx, shared, { 0xE8, 0x7F, 0x7F }) && lynx.did ("volume 0 1.000"));
  383. // V-Pot: 3 ticks clockwise, then 1 counter-clockwise (bit 6), on strip 2: the pan moves by its step, the ring follows
  384. wire.clear();
  385. lynx.log.clear();
  386. CHECK (feed (s, lynx, shared, { 0xB0, 17, 0x03 }));
  387. CHECK (std::abs (lynx.tracks[2].pan - 0.56f) < 1e-5f);
  388. CHECK (feed (s, lynx, shared, { 0xB0, 17, 0x41 }));
  389. CHECK (std::abs (lynx.tracks[2].pan - 0.54f) < 1e-5f);
  390. lynx.tracks[2].pan = 1.0f;
  391. s.refresh (lynx, shared, wire.send());
  392. CHECK (wire.has ("B0 31 1B")); // hard right: 0x10 | 11
  393. CHECK (wire.count ("F0 00 00 66 14 12 3F") == 1 && lcdText (wire.messages.back(), 7) == "R100 "); // row 2, cell 2: 56 + 7
  394. // buttons: press toggles, release does nothing; the LED shows LYNX's state, also when LYNX changed it
  395. wire.clear();
  396. lynx.log.clear();
  397. CHECK (feed (s, lynx, shared, { 0x90, 16, 127 }) && feed (s, lynx, shared, { 0x90, 16, 0 }) && feed (s, lynx, shared, { 0x80, 16, 64 }));
  398. CHECK (lynx.log.size() == 1 && lynx.did ("mute 1 on"));
  399. CHECK (feed (s, lynx, shared, { 0x90, 8 + 2, 127 }) && lynx.did ("solo 3 on"));
  400. CHECK (feed (s, lynx, shared, { 0x90, 0 + 7, 127 }) && lynx.did ("arm 8 on"));
  401. CHECK (feed (s, lynx, shared, { 0x90, 24 + 5, 127 }) && lynx.did ("select track 6"));
  402. lynx.tracks[2].mute = false; // (unmuted with the mouse)
  403. s.refresh (lynx, shared, wire.send());
  404. CHECK (wire.has ("90 10 7F") && wire.has ("90 11 00") && wire.has ("90 0A 7F") && wire.has ("90 07 7F") && wire.has ("90 1D 7F") && wire.has ("90 1B 00"));
  405. CHECK (wire.messages.size() == 6);
  406. // transport
  407. wire.clear();
  408. lynx.log.clear();
  409. CHECK (feed (s, lynx, shared, { 0x90, 94, 127 }) && feed (s, lynx, shared, { 0x90, 95, 127 }) && feed (s, lynx, shared, { 0x90, 89, 127 })
  410. && feed (s, lynx, shared, { 0x90, 86, 127 }));
  411. CHECK (lynx.playing && lynx.recording && lynx.click && ! lynx.patternMode);
  412. CHECK (feed (s, lynx, shared, { 0xB0, 60, 0x01 }) && feed (s, lynx, shared, { 0xB0, 60, 0x42 }) && lynx.did ("jog 1") && lynx.did ("jog -2"));
  413. s.refresh (lynx, shared, wire.send());
  414. CHECK (wire.has ("90 5E 7F") && wire.has ("90 5D 00") && wire.has ("90 5F 7F") && wire.has ("90 59 7F") && wire.has ("90 56 00") && wire.messages.size() == 5);
  415. CHECK (feed (s, lynx, shared, { 0x90, 93, 127 }) && ! lynx.playing);
  416. // what the profile does not name is not taken (it plays as before)
  417. CHECK (! feed (s, lynx, shared, { 0x90, 60, 100 }) && ! feed (s, lynx, shared, { 0xB0, 1, 64 }) && ! feed (s, lynx, shared, { 0xD0, 50 })
  418. && ! feed (s, lynx, shared, { 0xEA, 0, 64 }));
  419. const Claims claims (s.profile());
  420. const std::uint8_t note60[] { 0x90, 60, 100 }, play[] { 0x90, 94, 127 }, playOff[] { 0x80, 94, 0 }, bend1[] { 0xE0, 0, 64 }, bend11[] { 0xEA, 0, 64 },
  421. pot[] { 0xB0, 16, 1 }, potOther[] { 0xB1, 16, 1 }, pressure[] { 0xD0, 9 };
  422. CHECK (! claims.has (note60, 3) && claims.has (play, 3) && claims.has (playOff, 3) && claims.has (bend1, 3) && ! claims.has (bend11, 3)
  423. && claims.has (pot, 3) && ! claims.has (potOther, 3) && ! claims.has (pressure, 2) && ! claims.has (nullptr, 0));
  424. // closing: LEDs and rings off, the display blank, faders left where they are, then the exit message
  425. wire.clear();
  426. s.close (wire.send());
  427. CHECK (wire.has ("90 10 00") && wire.has ("90 5F 00") && wire.has ("B0 31 00") && wire.count ("E") == 0);
  428. CHECK (wire.count ("F0 00 00 66 14 12") == 16 && wire.messages.back() == "F0 00 00 66 14 08 F7");
  429. wire.clear();
  430. s.refresh (lynx, shared, wire.send());
  431. CHECK (wire.messages.empty());
  432. }
  433. TEST (controller190aw_bank_switching_layers_and_pages)
  434. {
  435. using namespace c190aw;
  436. FakeSurface lynx (20, 4, 20);
  437. lynx.tracks[9].mute = true;
  438. lynx.tracks[9].name = "Voz L\xC3\xAD" "der \xE2\x99\xAA"; // "Voz Líder ♪": an accent and a sign no display has
  439. Shared shared;
  440. Session s (profileOf (motorProfile, "motor"), 0);
  441. Wire wire;
  442. s.open (lynx, shared, wire.send());
  443. // bank right: the strips are inserts 9…16; LEDs and names follow
  444. wire.clear();
  445. CHECK (feed (s, lynx, shared, { 0x90, 47, 127 }) && shared.mixerBank == 8);
  446. s.refresh (lynx, shared, wire.send());
  447. CHECK (wire.has ("90 10 7F")); // strip 1 = insert 9, muted
  448. CHECK (wire.count ("F0 00 00 66 14 12 00") == 1);
  449. for (const auto& m : wire.messages)
  450. if (m.rfind ("F0 00 00 66 14 12 00", 0) == 0)
  451. CHECK (lcdText (m, 7) == "Voz Li ");
  452. lynx.log.clear();
  453. CHECK (feed (s, lynx, shared, { 0x90, 16 + 1, 127 }) && lynx.did ("mute 10 on"));
  454. CHECK (feed (s, lynx, shared, { 0xE2, 0x7F, 0x7F }) && lynx.did ("volume 11 1.000"));
  455. // bank right again: inserts 17…20, the other strips are empty (off, blank, and do nothing)
  456. wire.clear();
  457. lynx.log.clear();
  458. CHECK (feed (s, lynx, shared, { 0x90, 47, 127 }) && shared.mixerBank == 16);
  459. CHECK (feed (s, lynx, shared, { 0x90, 47, 127 }) && shared.mixerBank == 16); // (no further bank)
  460. s.refresh (lynx, shared, wire.send());
  461. CHECK (wire.has ("B0 34 00") && wire.has ("E4 00 00")); // strip 5: ring off, fader down
  462. CHECK (feed (s, lynx, shared, { 0x90, 16 + 4, 127 }) && feed (s, lynx, shared, { 0xE4, 0, 64 }) && lynx.log.empty());
  463. CHECK (feed (s, lynx, shared, { 0x90, 16 + 3, 127 }) && lynx.did ("mute 20 on"));
  464. // one strip left, bank left twice, and no further
  465. CHECK (feed (s, lynx, shared, { 0x90, 48, 127 }) && shared.mixerBank == 15);
  466. CHECK (feed (s, lynx, shared, { 0x90, 46, 127 }) && shared.mixerBank == 7 && feed (s, lynx, shared, { 0x90, 46, 127 }) && shared.mixerBank == 0);
  467. CHECK (feed (s, lynx, shared, { 0x90, 49, 127 }) && shared.mixerBank == 1 && feed (s, lynx, shared, { 0x90, 48, 127 })
  468. && feed (s, lynx, shared, { 0x90, 48, 127 }) && shared.mixerBank == 0);
  469. // the plug-in layer: the V-Pots turn the focused plugin's parameters, the rings and the display show them
  470. wire.clear();
  471. lynx.log.clear();
  472. CHECK (feed (s, lynx, shared, { 0x90, 43, 127 }) && shared.layer == 1);
  473. s.refresh (lynx, shared, wire.send());
  474. CHECK (wire.has ("90 2B 7F") && wire.has ("90 2A 00"));
  475. CHECK (wire.has ("B0 30 24")); // 0.25: wrap mode 0x20 | (1 + round (2.5) = 4)
  476. CHECK (wire.count ("F0 00 00 66 14 12") == 16);
  477. CHECK (feed (s, lynx, shared, { 0xB0, 18, 0x05 }) && lynx.did ("param 2 0.300") && lynx.tracks[3].pan == 0.5f);
  478. // next page: parameters 9…16, then 17…20, and no fourth page
  479. CHECK (feed (s, lynx, shared, { 0x90, 45, 127 }) && shared.page == 1);
  480. CHECK (feed (s, lynx, shared, { 0xB0, 16, 0x41 }) && lynx.did ("param 8 0.240"));
  481. CHECK (feed (s, lynx, shared, { 0x90, 45, 127 }) && shared.page == 2 && feed (s, lynx, shared, { 0x90, 45, 127 }) && shared.page == 2);
  482. lynx.log.clear();
  483. CHECK (feed (s, lynx, shared, { 0xB0, 16 + 5, 0x01 }) && lynx.log.empty()); // (parameter 22 does not exist)
  484. wire.clear();
  485. s.refresh (lynx, shared, wire.send());
  486. CHECK (wire.has ("B0 35 00"));
  487. CHECK (feed (s, lynx, shared, { 0x90, 44, 127 }) && feed (s, lynx, shared, { 0x90, 44, 127 }) && feed (s, lynx, shared, { 0x90, 44, 127 }) && shared.page == 0);
  488. // back to pan
  489. CHECK (feed (s, lynx, shared, { 0x90, 42, 127 }) && shared.layer == 0);
  490. CHECK (feed (s, lynx, shared, { 0xB0, 18, 0x05 }) && std::abs (lynx.tracks[3].pan - 0.6f) < 1e-5f);
  491. CHECK (displayAscii ("A\xC3\xA7\xC3\xA3o \xC3\xA9 \xC3\xB1", 8) == "Acao e n" && displayAscii ("abc", 5) == "abc " && displayAscii ("\xE6\x97\xA5\xE6\x9C\xAC", 3) == "?? " && displayAscii ("x", 0).empty());
  492. CHECK (panText (0.5f) == "C" && panText (0.0f) == "L100" && panText (0.75f) == "R50" && volumeText (0.8f) == "80%");
  493. }
  494. TEST (controller190aw_extender_takes_the_next_strips_and_shares_the_bank)
  495. {
  496. using namespace c190aw;
  497. FakeSurface lynx (40);
  498. for (std::size_t i = 1; i < lynx.tracks.size(); ++i)
  499. lynx.tracks[i].name = "T" + std::to_string (i);
  500. Library lib;
  501. lib.add (motorProfile, "motor", false);
  502. lib.add ("[device]\nname = Motor XT\nmatch = *Control XT*\nextends = motor\n", "motor-xt", false);
  503. lib.add (knobProfile, "knobs", false);
  504. Hub hub;
  505. std::map<std::string, Wire> wires;
  506. Hub::DeviceSend send = [&] (const std::string& input, const std::uint8_t* bytes, std::size_t size) { wires[input].send() (bytes, size); };
  507. auto feedHub = [&] (const std::string& device, std::initializer_list<int> bytes) {
  508. std::vector<std::uint8_t> b;
  509. for (const auto v : bytes)
  510. b.push_back ((std::uint8_t) v);
  511. return hub.input (device, b.data(), b.size(), lynx);
  512. };
  513. hub.configure ({ { "Test Control", lib.detect ("Test Control") }, { "Test Control XT", lib.detect ("Test Control XT") }, { "Piano", lib.detect ("Piano") },
  514. { "Knob Box", lib.detect ("Knob Box") } },
  515. lynx, send);
  516. CHECK (hub.has ("Test Control") && hub.has ("Test Control XT") && hub.has ("Knob Box") && ! hub.has ("Piano"));
  517. CHECK (hub.session ("Test Control")->unitOffset() == 0 && hub.session ("Test Control XT")->unitOffset() == 8);
  518. CHECK (hub.shared ("test") != nullptr && hub.shared ("test")->strips == 16);
  519. CHECK (wires["Test Control"].has ("F0 00 00 66 14 00 F7") && wires["Test Control XT"].has ("F0 00 00 66 14 00 F7") && wires["Piano"].messages.empty());
  520. // a device without a profile (generic) is not taken
  521. CHECK (! feedHub ("Piano", { 0x90, 94, 127 }) && ! feedHub ("Piano", { 0xB0, 16, 1 }) && lynx.log.empty());
  522. // the extender's strip 1 is insert 9
  523. CHECK (feedHub ("Test Control XT", { 0x90, 16, 127 }) && lynx.did ("mute 9 on"));
  524. CHECK (feedHub ("Test Control", { 0x90, 16, 127 }) && lynx.did ("mute 1 on"));
  525. // bank right on the main unit moves both by 16
  526. for (auto& [name, w] : wires)
  527. w.clear();
  528. lynx.log.clear();
  529. CHECK (feedHub ("Test Control", { 0x90, 47, 127 }) && hub.shared ("test")->mixerBank == 16);
  530. CHECK (feedHub ("Test Control XT", { 0x90, 16 + 7, 127 }) && lynx.did ("mute 32 on"));
  531. hub.refresh (lynx, send);
  532. CHECK (wires["Test Control XT"].has ("90 17 7F") && wires["Test Control"].count ("F0 00 00 66 14 12") == 8);
  533. // the knob box has its own bank
  534. CHECK (feedHub ("Knob Box", { 0xB0, 32, 127 }) && lynx.did ("solo 1 on"));
  535. // the extender is unplugged: it gets its closing messages, the main unit keeps its bank
  536. for (auto& [name, w] : wires)
  537. w.clear();
  538. hub.configure ({ { "Test Control", lib.find ("motor") }, { "Knob Box", lib.find ("knobs") } }, lynx, send);
  539. CHECK (! hub.has ("Test Control XT") && wires["Test Control XT"].messages.back() == "F0 00 00 66 14 08 F7" && wires["Test Control"].messages.empty());
  540. CHECK (hub.shared ("test")->mixerBank == 16 && hub.shared ("test")->strips == 8);
  541. // the setting changes to "Generic controller": the session goes
  542. hub.configure ({ { "Knob Box", lib.find ("knobs") } }, lynx, send);
  543. CHECK (! hub.has ("Test Control") && wires["Test Control"].messages.back() == "F0 00 00 66 14 08 F7" && hub.shared ("test") == nullptr);
  544. hub.closeAll (send);
  545. CHECK (! hub.has ("Knob Box"));
  546. }
  547. TEST (controller190aw_soft_takeover_for_knobs_and_sliders_without_motors)
  548. {
  549. using namespace c190aw;
  550. FakeSurface lynx;
  551. Shared shared;
  552. Session s (profileOf (knobProfile, "knobs"), 0);
  553. Wire wire;
  554. s.open (lynx, shared, wire.send());
  555. // slider 1 sits at 20 while insert 1 is at 0.8 (102): it moves nothing until it reaches the value
  556. lynx.log.clear();
  557. CHECK (feed (s, lynx, shared, { 0xB0, 0, 20 }) && feed (s, lynx, shared, { 0xB0, 0, 60 }) && feed (s, lynx, shared, { 0xB0, 0, 90 }));
  558. CHECK (lynx.log.empty() && lynx.tracks[1].volume == 0.8f);
  559. CHECK (feed (s, lynx, shared, { 0xB0, 0, 104 })); // crossed 0.8: caught
  560. CHECK (lynx.did ("volume 1 0.819"));
  561. CHECK (feed (s, lynx, shared, { 0xB0, 0, 30 }) && std::abs (lynx.tracks[1].volume - 30.0f / 127.0f) < 1e-5f); // and it stays caught
  562. // the value moved in LYNX: the slider has to reach it again
  563. lynx.tracks[1].volume = 0.9f;
  564. lynx.log.clear();
  565. CHECK (feed (s, lynx, shared, { 0xB0, 0, 31 }) && lynx.log.empty());
  566. CHECK (feed (s, lynx, shared, { 0xB0, 0, 115 }) && lynx.did ("volume 1 0.906"));
  567. // bank right: slider 1 is now insert 9 (0.8) and must be caught again; a slider that lands on the value is caught at once
  568. CHECK (feed (s, lynx, shared, { 0xB0, 59, 127 }) && shared.mixerBank == 8);
  569. lynx.log.clear();
  570. CHECK (feed (s, lynx, shared, { 0xB0, 0, 120 }) && lynx.log.empty() && lynx.tracks[9].volume == 0.8f);
  571. CHECK (feed (s, lynx, shared, { 0xB0, 0, 101 }) && lynx.did ("volume 9 0.795"));
  572. CHECK (feed (s, lynx, shared, { 0xB0, 1, 102 }) && lynx.did ("volume 10 0.803")); // 102 / 127 is within a step of 0.8
  573. // knobs on the focused plugin's parameters (0.25 = 32): the same rule
  574. lynx.log.clear();
  575. CHECK (feed (s, lynx, shared, { 0xB0, 16, 100 }) && lynx.log.empty());
  576. CHECK (feed (s, lynx, shared, { 0xB0, 16, 31 }) && lynx.did ("param 0 0.244"));
  577. // the selected channel's volume, from any MIDI channel
  578. lynx.selected = 2;
  579. CHECK (feed (s, lynx, shared, { 0xB5, 70, 102 }) && lynx.did ("channel volume 2 0.803"));
  580. // CC buttons with LEDs, pads as steps and as notes, a value filter
  581. wire.clear();
  582. lynx.log.clear();
  583. CHECK (feed (s, lynx, shared, { 0xB0, 41, 127 }) && feed (s, lynx, shared, { 0xB0, 41, 0 }) && lynx.playing);
  584. CHECK (feed (s, lynx, shared, { 0x99, 36 + 4, 90 }) && feed (s, lynx, shared, { 0x89, 36 + 4, 0 }) && lynx.did ("step 4 on") && lynx.stepsOn[4]);
  585. CHECK (feed (s, lynx, shared, { 0x99, 62, 127 }) && lynx.did ("note on 38 1.000") && feed (s, lynx, shared, { 0x89, 62, 0 }) && lynx.did ("note off 38 0.000"));
  586. CHECK (feed (s, lynx, shared, { 0xBF, 9, 1 }) && ! lynx.recording && feed (s, lynx, shared, { 0xBF, 9, 2 }) && lynx.recording);
  587. // ignored controls are taken (they do not play) and do nothing; the first matching line wins
  588. lynx.log.clear();
  589. CHECK (feed (s, lynx, shared, { 0x90, 98, 127 }) && feed (s, lynx, shared, { 0xBF, 74, 127 }) && lynx.log.empty());
  590. CHECK (Claims (s.profile()).has (std::array<std::uint8_t, 3> { 0x90, 98, 127 }.data(), 3) && ! feed (s, lynx, shared, { 0x91, 98, 127 }));
  591. s.refresh (lynx, shared, wire.send());
  592. CHECK (wire.has ("B0 29 7F") && wire.has ("99 28 03") && wire.messages.size() == 2);
  593. }
  594. TEST (controller190aw_links_made_by_hand_come_first)
  595. {
  596. using namespace c190aw;
  597. FakeSurface lynx;
  598. Shared shared;
  599. Session s (profileOf (knobProfile, "knobs"), 0);
  600. Wire wire;
  601. s.open (lynx, shared, wire.send());
  602. // CC 16 on channel 1 is linked by hand (Link to MIDI controller): the profile leaves it to the link
  603. lynx.links.insert ({ 16, 0 });
  604. lynx.log.clear();
  605. CHECK (! feed (s, lynx, shared, { 0xB0, 16, 32 }) && lynx.log.empty());
  606. // the next knob still belongs to the profile
  607. CHECK (feed (s, lynx, shared, { 0xB0, 17, 32 }) && lynx.did ("param 1 0.252"));
  608. // a link on any channel
  609. lynx.links.insert ({ 41, -1 });
  610. CHECK (! feed (s, lynx, shared, { 0xB0, 41, 127 }) && ! lynx.playing);
  611. // the link is removed: the profile has the control again
  612. lynx.links.clear();
  613. CHECK (feed (s, lynx, shared, { 0xB0, 41, 127 }) && lynx.playing);
  614. }
  615. TEST (controller190aw_old_settings_and_generic_devices_behave_as_before)
  616. {
  617. using namespace c190aw;
  618. using namespace lynx::prefs;
  619. // a settings file written before controller types existed: every device detects, nothing else changes
  620. const std::string old = "velocity=soft\npickup=1\nfootPedal=1\ninput=1|2|4|Keystation 49\ninput=0|0|-1|Pads | MPD=218\nlink=7|-1|4|0|0|0\n";
  621. const auto p = MidiPrefs::fromText (old);
  622. CHECK (p.inputs.size() == 2 && p.input ("Keystation 49").controller.empty() && p.input ("Keystation 49").midiChannel == 2
  623. && p.input ("Keystation 49").target == 4 && ! p.input ("Pads | MPD=218").enabled && p.globalLinks.size() == 1 && p.pickup);
  624. CHECK (p.toText() == old); // (and it is written back byte for byte)
  625. CHECK (MidiPrefs::fromText (MidiPrefs {}.toText()) == MidiPrefs {});
  626. // the controller type is kept per device, also for a device with no other setting and a name with '|' and '='
  627. auto q = p;
  628. auto in = q.input ("Keystation 49");
  629. in.controller = "mackie-control";
  630. q.setInput (in);
  631. MidiInputPrefs box;
  632. box.name = "Box | A=B";
  633. box.controller = genericChoice;
  634. q.setInput (box);
  635. CHECK (q.inputs.size() == 3);
  636. const auto back = MidiPrefs::fromText (q.toText());
  637. CHECK (back == q && back.input ("Keystation 49").controller == "mackie-control" && back.input ("Keystation 49").target == 4
  638. && back.input ("Box | A=B").controller == genericChoice && back.input ("Box | A=B").enabled && back.input ("Other").controller.empty());
  639. // back to "detect": the device leaves the list again
  640. box.controller.clear();
  641. q.setInput (box);
  642. CHECK (q.inputs.size() == 2 && q.toText().find ("Box") == std::string::npos);
  643. // (the lines in either order)
  644. CHECK (MidiPrefs::fromText ("controller=knobs|Dev\ninput=1|3|-1|Dev\n").input ("Dev").controller == "knobs"
  645. && MidiPrefs::fromText ("controller=knobs|Dev\ninput=1|3|-1|Dev\n").input ("Dev").midiChannel == 3);
  646. // LYNX ships no profile that takes a plain keyboard: with the built-in library a device nobody knows is generic
  647. const auto builtIn = Library::builtIn();
  648. CHECK (builtIn.errors.empty());
  649. CHECK (builtIn.resolve ("", "Keystation 49") == nullptr && builtIn.resolve ("", "USB MIDI Interface") == nullptr && builtIn.resolve ("", "") == nullptr);
  650. CHECK (builtIn.resolve (genericChoice, "Mackie Control") == nullptr);
  651. // the MIDI thread's test: a generic device's messages are never taken; a profile takes its own controls only, and
  652. // not the controllers a MIDI link uses (those keep moving their parameter exactly as before)
  653. const Claims none;
  654. const std::uint8_t cc7[] { 0xB0, 7, 100 }, cc16[] { 0xB0, 16, 100 }, cc70[] { 0xB3, 70, 1 }, note[] { 0x90, 60, 100 }, bend[] { 0xE0, 0, 64 };
  655. CHECK (! none.takes (cc7, 3, 0, 0) && ! none.takes (note, 3, 0, 0) && ! none.takes (bend, 3, 0, 0));
  656. const Claims knobs (*profileOf (knobProfile, "knobs"));
  657. CHECK (knobs.takes (cc7, 3, 0, 0) && knobs.takes (cc16, 3, 0, 0) && knobs.takes (cc70, 3, 0, 0) && ! knobs.takes (note, 3, 0, 0) && ! knobs.takes (bend, 3, 0, 0));
  658. CHECK (! knobs.takes (cc7, 3, std::uint64_t { 1 } << 7, 0) && knobs.takes (cc16, 3, std::uint64_t { 1 } << 7, 0));
  659. CHECK (! knobs.takes (cc70, 3, 0, std::uint64_t { 1 } << (70 - 64)) && knobs.takes (cc70, 3, std::uint64_t { 1 } << 6, 0));
  660. // a Hub without devices, or with generic ones only, takes nothing and sends nothing
  661. FakeSurface lynx;
  662. Hub hub;
  663. auto sentAny = false;
  664. Hub::DeviceSend send = [&] (const std::string&, const std::uint8_t*, std::size_t) { sentAny = true; };
  665. hub.configure ({ { "Keystation 49", nullptr }, { "Pads", builtIn.resolve ("", "Pads") } }, lynx, send);
  666. hub.refresh (lynx, send);
  667. CHECK (! hub.has ("Keystation 49") && ! hub.input ("Keystation 49", cc7, 3, lynx) && ! hub.input ("Pads", note, 3, lynx) && lynx.log.empty() && ! sentAny);
  668. }