KeySheetCheck190sj.inc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. // Round 190sj (issue #327, 0.1.32). Included in the app class of Main.cpp; --keysheet190sjtest <report> and --selftest
  2. // "keysheet190sj". Every key of the F1 shortcut sheet (keys::sheet::rows) is pressed in the main window
  3. // (MainComponent::keyPressed, as a key the system delivers) with the panel it belongs to focused, the typing keyboard off
  4. // and on: the action the key map gives it there must be the one that runs (seen by MainComponent::actionFilterForCheck,
  5. // which keeps file choosers and dialogs from opening). A General key is pressed with every panel focused; where a panel
  6. // has its own action on it (FL's Ctrl+T in the Playlist and the Piano roll: Add auto marker) that one must run. Then the
  7. // keys the issue named do what they say, a remapped key moves with its action, and the sheet shows the remapped key.
  8. juce::String keySheet190sjCheck (juce::String& log)
  9. {
  10. using namespace lynx;
  11. using Panel = workspace::Panel;
  12. juce::String result = "OK";
  13. const auto check = [&] (const juce::String& what, bool ok, const juce::String& detail = {}) {
  14. log << (ok ? "ok " : "FAIL ") << what << (detail.isNotEmpty() ? " [" + detail + "]" : juce::String()) << "\n";
  15. if (! ok && result == "OK")
  16. result = "ERROR " + what + " " + detail;
  17. };
  18. struct Keep
  19. {
  20. layoutstyle::Style was = layoutstyle::current();
  21. ~Keep()
  22. {
  23. layoutstyle::setCurrent (was);
  24. MainComponent::actionFilterForCheck = nullptr;
  25. }
  26. } keep;
  27. AudioEngine offline (false);
  28. MainComponent ui (offline, false);
  29. ui.setSize (1600, 900);
  30. ui.setLayoutStyle (layoutstyle::Style::pattern);
  31. const auto settle = [&] {
  32. for (int k = 0; k < 3; ++k)
  33. offline.dispatchPendingMessages();
  34. };
  35. settle();
  36. ui.showPanelsForSnapshot ({ Panel::playlist, Panel::channelRack, Panel::pianoRoll, Panel::mixer, Panel::browser });
  37. settle();
  38. const auto focus = [&] (Panel p) {
  39. ui.workspaceForTest().activate (p);
  40. settle();
  41. };
  42. // a key as JUCE hands it over: letters by their upper-case code, the others by JUCE's key codes
  43. const auto keyPressOf = [] (const keys::Chord& c) {
  44. int code = c.key;
  45. struct Pair { int key, juce; };
  46. static const Pair specials[] = {
  47. { keys::space, juce::KeyPress::spaceKey }, { keys::enter, juce::KeyPress::returnKey }, { keys::escape, juce::KeyPress::escapeKey },
  48. { keys::tab, juce::KeyPress::tabKey }, { keys::backspace, juce::KeyPress::backspaceKey }, { keys::del, juce::KeyPress::deleteKey },
  49. { keys::insert, juce::KeyPress::insertKey }, { keys::up, juce::KeyPress::upKey }, { keys::down, juce::KeyPress::downKey },
  50. { keys::left, juce::KeyPress::leftKey }, { keys::right, juce::KeyPress::rightKey }, { keys::pageUp, juce::KeyPress::pageUpKey },
  51. { keys::pageDown, juce::KeyPress::pageDownKey }, { keys::home, juce::KeyPress::homeKey }, { keys::end, juce::KeyPress::endKey },
  52. { keys::numpadPlus, juce::KeyPress::numberPadAdd }, { keys::numpadMinus, juce::KeyPress::numberPadSubtract },
  53. { keys::numpadMultiply, juce::KeyPress::numberPadMultiply }, { keys::numpadDivide, juce::KeyPress::numberPadDivide },
  54. };
  55. for (const auto& p : specials)
  56. if (p.key == c.key)
  57. code = p.juce;
  58. if (c.key >= keys::f1 && c.key <= keys::f12)
  59. code = juce::KeyPress::F1Key + (c.key - keys::f1);
  60. const auto mods = ((c.mods & keys::ctrl) ? juce::ModifierKeys::commandModifier : 0) | ((c.mods & keys::shift) ? juce::ModifierKeys::shiftModifier : 0)
  61. | ((c.mods & keys::alt) ? juce::ModifierKeys::altModifier : 0);
  62. const auto character = c.key > ' ' && c.key < 0x7f && (c.mods & (keys::ctrl | keys::alt)) == 0 ? (juce::juce_wchar) c.key : (juce::juce_wchar) 0;
  63. return juce::KeyPress (code, juce::ModifierKeys (mods), character);
  64. };
  65. const auto contextOf = [] (Panel p) {
  66. return p == Panel::playlist ? keys::Context::playlist : p == Panel::channelRack ? keys::Context::channelRack
  67. : p == Panel::pianoRoll ? keys::Context::pianoRoll : p == Panel::mixer ? keys::Context::mixer : keys::Context::browser;
  68. };
  69. const auto panelName = [] (Panel p) {
  70. return juce::String (p == Panel::playlist ? "Playlist" : p == Panel::channelRack ? "Channel rack" : p == Panel::pianoRoll ? "Piano roll"
  71. : p == Panel::mixer ? "Mixer" : "Browser");
  72. };
  73. const auto& map = ui.getKeyMapForSnapshot();
  74. // 1. every key of the sheet, dry (the action is seen, not run)
  75. std::vector<std::string> ran;
  76. MainComponent::actionFilterForCheck = [&ran] (const std::string& id) {
  77. ran.push_back (id);
  78. return false;
  79. };
  80. int pressed = 0, rowsWithKeys = 0;
  81. std::set<std::string> panelOwn; // a General key that a focused panel uses for its own action
  82. for (const auto piano : { false, true })
  83. {
  84. ui.setTypingPianoForTest (piano);
  85. for (const auto& row : keys::sheet::rows())
  86. {
  87. if (row.actions.empty())
  88. {
  89. check (juce::String ("a row without keys is a mouse row: ") + row.gesture, juce::String (row.gesture).isNotEmpty());
  90. continue;
  91. }
  92. ++rowsWithKeys;
  93. const auto ctx = keys::sheet::sectionContext (row.section);
  94. for (const auto& id : keys::sheet::shownActions (row, map))
  95. {
  96. const auto* action = keys::findAction (id);
  97. check (juce::String ("the sheet's action exists: ") + id, action != nullptr);
  98. if (action == nullptr)
  99. continue;
  100. check (juce::String (id) + " has a key", ! map.chordsFor (id).empty());
  101. check (juce::String (id) + " belongs to its section's panel", action->context == ctx || action->context == keys::Context::global);
  102. const auto panels = action->context == keys::Context::global
  103. ? std::vector<Panel> { Panel::channelRack, Panel::mixer, Panel::browser, Panel::playlist, Panel::pianoRoll }
  104. : std::vector<Panel> { action->context == keys::Context::pianoRoll ? Panel::pianoRoll
  105. : action->context == keys::Context::playlist ? Panel::playlist : Panel::channelRack };
  106. for (const auto& chord : map.chordsFor (id))
  107. {
  108. // the typing keyboard on: a plain letter / digit is its (a note, or nothing), unless the action works then
  109. const auto plain = (chord.mods & (keys::ctrl | keys::alt | keys::shift)) == 0 && chord.isPrintable();
  110. if (piano && plain && (! action->whilePiano || keys::typingPianoKey (chord.key, keys::typingpiano::defaultOctave, 0, keys::typingpiano::pianoLayout()).taken))
  111. continue;
  112. for (const auto p : panels)
  113. {
  114. focus (p);
  115. const auto expected = map.find (chord, contextOf (p), piano);
  116. ran.clear();
  117. ui.keyPressed (keyPressOf (chord));
  118. settle();
  119. ++pressed;
  120. const auto got = ran.empty() ? std::string ("(nothing)") : ran.front();
  121. const auto what = juce::String (keys::toString (chord)) + " (" + id + "), " + panelName (p) + " focused, typing keyboard "
  122. + (piano ? "on" : "off");
  123. check (what + " runs " + expected, got == expected, got);
  124. if (expected != id)
  125. {
  126. log << " (that panel's own key: " << expected << ")\n";
  127. panelOwn.insert (id + " @ " + panelName (p).toStdString() + " = " + expected);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. MainComponent::actionFilterForCheck = nullptr;
  135. log << " " << pressed << " key presses, " << rowsWithKeys << " rows with keys\n";
  136. // the General keys a panel keeps for itself, all FL's: Ctrl+T in the Playlist / Piano roll (Add auto marker, REA 168t2),
  137. // Ctrl+Shift+S in the Mixer (Save the mixer track state), Enter in the Browser (load the selected file)
  138. {
  139. const std::set<std::string> known { "view.typingPiano @ Playlist = playlist.markerAuto", "view.typingPiano @ Piano roll = pianoRoll.markerAuto",
  140. "file.saveAs @ Mixer = mixer.saveTrackState", "panel.maximisePlaylist @ Browser = browser.load" };
  141. juce::String got;
  142. for (const auto& k : panelOwn)
  143. got << k << "; ";
  144. check ("the General keys a panel takes for itself are FL's (and only those)", panelOwn == known, got);
  145. }
  146. // 2. what the issue named, run for real
  147. ui.setTypingPianoForTest (false);
  148. for (const auto p : { Panel::channelRack, Panel::mixer, Panel::browser })
  149. {
  150. focus (p);
  151. ui.keyPressed (juce::KeyPress ('T', juce::ModifierKeys::commandModifier, 0));
  152. settle();
  153. check ("Ctrl+T switches the typing keyboard on, " + panelName (p) + " focused", ui.typingPianoForCheck());
  154. ui.keyPressed (juce::KeyPress ('T', juce::ModifierKeys::commandModifier, 0));
  155. settle();
  156. check ("Ctrl+T switches it off again, " + panelName (p) + " focused", ! ui.typingPianoForCheck());
  157. }
  158. {
  159. focus (Panel::playlist);
  160. const auto markers = offline.getSong().markers().size();
  161. ui.keyPressed (juce::KeyPress ('T', juce::ModifierKeys::commandModifier, 0));
  162. settle();
  163. check ("Ctrl+T with the Playlist focused adds an Auto time marker, as FL (REA 168t2)",
  164. offline.getSong().markers().size() == markers + 1 && ! ui.typingPianoForCheck());
  165. }
  166. const auto channel = offline.getSelectedChannel();
  167. offline.editSong ([channel] (Song& s) {
  168. auto& pat = s.patterns[(std::size_t) s.currentPattern];
  169. pat.notes.clear();
  170. for (int i = 0; i < 3; ++i)
  171. {
  172. Note n;
  173. n.channel = channel;
  174. n.key = 60 + 2 * i;
  175. n.start = i * ppq;
  176. n.length = ppq / 2;
  177. pat.notes.push_back (n);
  178. }
  179. });
  180. settle();
  181. focus (Panel::pianoRoll);
  182. auto& roll = ui.getPianoRollForSnapshot();
  183. const auto firstKey = [&] { return offline.getSong().patterns[(std::size_t) offline.getSong().currentPattern].notes.front().key; };
  184. const auto firstStart = [&] { return offline.getSong().patterns[(std::size_t) offline.getSong().currentPattern].notes.front().start; };
  185. ui.keyPressed (juce::KeyPress ('A', juce::ModifierKeys::commandModifier, 0));
  186. settle();
  187. check ("Piano roll: Ctrl+A selects every note", roll.selectionForTests().size() == 3, juce::String ((int) roll.selectionForTests().size()));
  188. struct Move
  189. {
  190. const char* name;
  191. int code, mods, keys, steps;
  192. };
  193. const auto cmd = juce::ModifierKeys::commandModifier, shift = juce::ModifierKeys::shiftModifier;
  194. for (const auto& m : { Move { "Shift+Up", juce::KeyPress::upKey, shift, 1, 0 }, Move { "Shift+Down", juce::KeyPress::downKey, shift, -1, 0 },
  195. Move { "Ctrl+Up", juce::KeyPress::upKey, cmd, 12, 0 }, Move { "Ctrl+Down", juce::KeyPress::downKey, cmd, -12, 0 },
  196. Move { "Shift+Right", juce::KeyPress::rightKey, shift, 0, 1 }, Move { "Shift+Left", juce::KeyPress::leftKey, shift, 0, -1 } })
  197. {
  198. const auto key = firstKey();
  199. const auto start = firstStart();
  200. ui.keyPressed (juce::KeyPress (m.code, juce::ModifierKeys (m.mods), 0));
  201. settle();
  202. check (juce::String ("Piano roll: ") + m.name + " moves the selected notes", firstKey() == key + m.keys
  203. && firstStart() == start + m.steps * roll.gridTicksForSnapshot(),
  204. juce::String (key) + " -> " + juce::String (firstKey()));
  205. }
  206. ui.keyPressed (juce::KeyPress ('D', juce::ModifierKeys::commandModifier, 0));
  207. settle();
  208. check ("Piano roll: Ctrl+D deselects", roll.selectionForTests().empty());
  209. {
  210. const auto key = firstKey();
  211. ui.keyPressed (juce::KeyPress (juce::KeyPress::upKey, juce::ModifierKeys (shift), 0));
  212. settle();
  213. check ("Piano roll: Shift+Up with nothing selected moves nothing", firstKey() == key);
  214. }
  215. // 3. remapped: the octave on Alt+Shift+Up, in Manage shortcuts' map; Ctrl+Up no longer moves; the sheet says so
  216. ui.keyMapForCheck().setChords ("pianoRoll.octaveUp", { keys::Chord { keys::up, (std::uint8_t) (keys::alt | keys::shift) } });
  217. roll.setSelectionForSnapshot ({ 0, 1, 2 });
  218. {
  219. const auto key = firstKey();
  220. ui.keyPressed (juce::KeyPress (juce::KeyPress::upKey, juce::ModifierKeys (cmd), 0));
  221. settle();
  222. check ("remapped: Ctrl+Up no longer transposes", firstKey() == key);
  223. ui.keyPressed (juce::KeyPress (juce::KeyPress::upKey, juce::ModifierKeys (juce::ModifierKeys::altModifier | shift), 0));
  224. settle();
  225. check ("remapped: Alt+Shift+Up transposes an octave", firstKey() == key + 12);
  226. const auto& rows = keys::sheet::rows();
  227. const auto octave = std::find_if (rows.begin(), rows.end(), [] (const keys::sheet::Row& r) {
  228. return ! r.actions.empty() && r.actions.front() == "pianoRoll.octaveUp";
  229. });
  230. const auto text = octave == rows.end() ? std::string() : keys::sheet::keysText (*octave, ui.getKeyMapForSnapshot(), modmap::Os::windows);
  231. check ("the sheet shows the remapped key", text == "Shift+Alt+Up / Ctrl+Down", text);
  232. }
  233. ui.keyMapForCheck().resetToDefaults();
  234. return result;
  235. }
  236. // --keyroute190sjtest report.txt (round 190sj, issue #327): the same keys as the user presses them, in a window. Each step
  237. // clicks as the system would (through the native window under the point) and presses the key where the system sends it
  238. // (Windows: posted to the window with the system's focus, the modifiers in the thread's keyboard state; elsewhere the
  239. // focused component's native window). Shows a window (Windows: GUI lock).
  240. void runKeyRoute190sj (const juce::String& reportPath)
  241. {
  242. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  243. struct RouteTest final : juce::Timer
  244. {
  245. juce::String reportPath, report;
  246. bool ok = true;
  247. int stepIndex = 0;
  248. std::unique_ptr<lynx::AudioEngine> engine;
  249. lynx::MainComponent* ui = nullptr;
  250. std::unique_ptr<juce::DocumentWindow> main;
  251. std::function<void()> done;
  252. void line (const juce::String& text)
  253. {
  254. report << text << "\n";
  255. juce::File (reportPath).replaceWithText (report);
  256. }
  257. void check (const juce::String& what, bool passed, const juce::String& detail = {})
  258. {
  259. line ((passed ? "ok " : "FAIL ") + what + (detail.isNotEmpty() ? " [" + detail + "]" : juce::String()));
  260. ok = ok && passed;
  261. }
  262. static juce::String describe (juce::Component* c)
  263. {
  264. if (c == nullptr)
  265. return "nothing";
  266. juce::String path;
  267. for (auto* p = c; p != nullptr && path.length() < 160; p = p->getParentComponent())
  268. {
  269. auto name = p->getComponentID().isNotEmpty() ? p->getComponentID() : p->getName();
  270. if (name.isEmpty())
  271. name = juce::String (typeid (*p).name()).fromLastOccurrenceOf ("::", false, false).substring (0, 28);
  272. path << (path.isEmpty() ? "" : " < ") << name;
  273. }
  274. return path;
  275. }
  276. void click (juce::Component& c, juce::Point<int> local, juce::ModifierKeys mods = {})
  277. {
  278. auto* peer = c.getPeer();
  279. if (peer == nullptr)
  280. {
  281. line (" (no native window for the click)");
  282. return;
  283. }
  284. const auto at = peer->getComponent().getLocalPoint (&c, local.toFloat());
  285. line (" click at " + local.toString() + " -> " + describe (peer->getComponent().getComponentAt (at.roundToInt())));
  286. const auto now = juce::Time::currentTimeMillis();
  287. peer->handleMouseEvent (juce::MouseInputSource::InputSourceType::mouse, at, mods.withFlags (juce::ModifierKeys::leftButtonModifier), 1.0f, 0.0f, now);
  288. peer->handleMouseEvent (juce::MouseInputSource::InputSourceType::mouse, at, mods, 1.0f, 0.0f, now + 40);
  289. }
  290. // a key where the system sends it
  291. void press (int code, int mods, juce::juce_wchar character = 0)
  292. {
  293. const juce::ModifierKeys m (mods);
  294. juce::String arrived;
  295. lynx::MainComponent::keySeenForCheck = [&arrived] (const juce::KeyPress& k) { arrived << k.getTextDescription() << " "; };
  296. const juce::ScopeGuard report { [&] {
  297. lynx::MainComponent::keySeenForCheck = nullptr;
  298. line (" pressed " + juce::KeyPress (code, m, character).getTextDescription() + ", the main window got: "
  299. + (arrived.isEmpty() ? juce::String ("nothing") : arrived));
  300. } };
  301. #if JUCE_WINDOWS
  302. // a plain key: posted to the window with the system's focus (Windows makes the character, as for a real key).
  303. // With modifiers: JUCE reads them from the hardware (GetAsyncKeyState), which only real input sets, so the key
  304. // goes to the JUCE peer of that same window instead (the routing from there on is the real one)
  305. if (! m.isAnyModifierKeyDown())
  306. {
  307. int vk = code;
  308. if (code == juce::KeyPress::upKey) vk = 0x26; // (VK_UP)
  309. else if (code == juce::KeyPress::downKey) vk = 0x28; // (VK_DOWN)
  310. else if (code == juce::KeyPress::leftKey) vk = 0x25; // (VK_LEFT)
  311. else if (code == juce::KeyPress::rightKey) vk = 0x27; // (VK_RIGHT)
  312. else if (code >= 'a' && code <= 'z') vk = code - 'a' + 'A';
  313. if (lynx::nativechild::pressKeyForTest (main->getWindowHandle(), vk, false, false, false))
  314. return;
  315. }
  316. juce::ComponentPeer* systemPeer = nullptr;
  317. if (auto* window = lynx::nativechild::focusedWindowForTest())
  318. for (int i = 0; i < juce::ComponentPeer::getNumPeers(); ++i)
  319. if (auto* candidate = juce::ComponentPeer::getPeer (i); candidate != nullptr && candidate->getNativeHandle() == window)
  320. systemPeer = candidate;
  321. line (" (the system's focus: " + (systemPeer != nullptr ? describe (&systemPeer->getComponent()) : juce::String ("not a LYNX window: the main one")) + ")");
  322. #endif
  323. auto* focused = juce::Component::getCurrentlyFocusedComponent();
  324. auto* peer = focused != nullptr && focused->getPeer() != nullptr ? focused->getPeer() : main->getPeer();
  325. #if JUCE_WINDOWS
  326. peer = systemPeer != nullptr ? systemPeer : main->getPeer();
  327. #endif
  328. juce::ModifierKeys::currentModifiers = m;
  329. if (peer != nullptr)
  330. peer->handleKeyPress (juce::KeyPress (code, m, character));
  331. juce::ModifierKeys::currentModifiers = {};
  332. }
  333. juce::String keysNow() const
  334. {
  335. juce::String k;
  336. const auto& s = engine->getSong();
  337. for (const auto& n : s.patterns[(std::size_t) s.currentPattern].notes)
  338. k << n.key << " ";
  339. return k.trim();
  340. }
  341. void transposeCase (const juce::String& after)
  342. {
  343. auto& roll = ui->getPianoRollForSnapshot();
  344. line (" keys at: " + describe (juce::Component::getCurrentlyFocusedComponent()) + ", panel focus "
  345. + juce::String ((int) ui->workspaceForTest().getFocused()));
  346. press ('A', juce::ModifierKeys::commandModifier, 'a');
  347. check ("Ctrl+A selects the notes (" + after + ")", roll.selectionForTests().size() == 3, juce::String ((int) roll.selectionForTests().size()));
  348. struct Step
  349. {
  350. const char* name;
  351. int code, mods, delta;
  352. };
  353. for (const auto& s : { Step { "Shift+Up", juce::KeyPress::upKey, juce::ModifierKeys::shiftModifier, 1 },
  354. Step { "Shift+Down", juce::KeyPress::downKey, juce::ModifierKeys::shiftModifier, -1 },
  355. Step { "Ctrl+Up", juce::KeyPress::upKey, juce::ModifierKeys::commandModifier, 12 },
  356. Step { "Ctrl+Down", juce::KeyPress::downKey, juce::ModifierKeys::commandModifier, -12 } })
  357. {
  358. const auto before = engine->getSong().patterns[(std::size_t) engine->getSong().currentPattern].notes.front().key;
  359. const auto text = keysNow();
  360. press (s.code, s.mods);
  361. const auto now = engine->getSong().patterns[(std::size_t) engine->getSong().currentPattern].notes.front().key;
  362. check (juce::String (s.name) + " moves the selected notes (" + after + ")", now == before + s.delta, text + " -> " + keysNow());
  363. }
  364. }
  365. void timerCallback() override
  366. {
  367. auto& roll = ui->getPianoRollForSnapshot();
  368. switch (stepIndex++)
  369. {
  370. case 0:
  371. {
  372. ui->setLayoutStyle (lynx::layoutstyle::Style::pattern);
  373. const auto channel = engine->getSelectedChannel();
  374. engine->editSong ([channel] (lynx::Song& s) {
  375. auto& pat = s.patterns[(std::size_t) s.currentPattern];
  376. pat.notes.clear();
  377. for (int i = 0; i < 3; ++i)
  378. {
  379. lynx::Note n;
  380. n.channel = channel;
  381. n.key = 60 + 2 * i;
  382. n.start = i * lynx::ppq;
  383. n.length = lynx::ppq / 2;
  384. pat.notes.push_back (n);
  385. }
  386. });
  387. ui->setTypingPianoForTest (false);
  388. ui->grabKeyboardFocus();
  389. break;
  390. }
  391. case 1:
  392. if (! ui->workspaceForTest().isPanelVisible (lynx::workspace::Panel::pianoRoll))
  393. ui->runActionForSnapshot ("panel.pianoRoll");
  394. break;
  395. case 2:
  396. {
  397. check ("the Piano roll shows", roll.isShowing());
  398. const auto grid = roll.gridAreaForSnapshot();
  399. click (roll, { grid.getRight() - 30, grid.getBottom() - 30 }); // (an empty spot: no note made, Draw tool)
  400. break;
  401. }
  402. case 3:
  403. engine->editSong ([] (lynx::Song& s) { // (the click may have drawn a note: the three are kept)
  404. auto& notes = s.patterns[(std::size_t) s.currentPattern].notes;
  405. if (notes.size() > 3)
  406. notes.resize (3);
  407. });
  408. // the control: a plain Space, as --simplekeytest presses it (playback starts)
  409. press (juce::KeyPress::spaceKey, 0, ' ');
  410. check ("control: Space plays", engine->getTransport().playing.load());
  411. engine->stop();
  412. transposeCase ("after a click in the Piano roll");
  413. break;
  414. case 4:
  415. {
  416. // the Browser's search box clicked, then the Piano roll again
  417. juce::TextEditor* field = nullptr;
  418. std::function<void (juce::Component&)> look = [&] (juce::Component& c) {
  419. if (auto* t = dynamic_cast<juce::TextEditor*> (&c); t != nullptr && t->isShowing() && field == nullptr)
  420. field = t;
  421. for (auto* child : c.getChildren())
  422. look (*child);
  423. };
  424. look (ui->getBrowserForSnapshot());
  425. line (" Browser search box found=" + juce::String ((int) (field != nullptr)));
  426. if (field != nullptr)
  427. click (*field, field->getLocalBounds().getCentre());
  428. break;
  429. }
  430. case 5:
  431. {
  432. const auto grid = roll.gridAreaForSnapshot();
  433. click (roll, { grid.getRight() - 30, grid.getBottom() - 30 });
  434. break;
  435. }
  436. case 6:
  437. engine->editSong ([] (lynx::Song& s) {
  438. auto& notes = s.patterns[(std::size_t) s.currentPattern].notes;
  439. if (notes.size() > 3)
  440. notes.resize (3);
  441. });
  442. transposeCase ("after a click in the Browser's search box, then the Piano roll");
  443. break;
  444. case 7:
  445. {
  446. // Windows: a real click on the Piano roll's native child window may give it the system's focus
  447. #if JUCE_WINDOWS
  448. if (auto* frame = roll.getPeer(); frame != nullptr && frame != main->getPeer())
  449. {
  450. lynx::nativechild::focusWindowForTest (frame->getNativeHandle());
  451. engine->editSong ([] (lynx::Song& s) {
  452. auto& notes = s.patterns[(std::size_t) s.currentPattern].notes;
  453. if (notes.size() > 3)
  454. notes.resize (3);
  455. });
  456. transposeCase ("with the system's focus in the Piano roll's own native window");
  457. }
  458. #endif
  459. break;
  460. }
  461. case 8:
  462. {
  463. // Ctrl+T after a click in each panel
  464. using Panel = lynx::workspace::Panel;
  465. for (const auto p : { Panel::channelRack, Panel::playlist, Panel::pianoRoll })
  466. {
  467. juce::Component* c = p == Panel::pianoRoll ? (juce::Component*) &roll
  468. : p == Panel::playlist ? (juce::Component*) &ui->getPlaylistForSnapshot()
  469. : nullptr;
  470. if (p == Panel::channelRack)
  471. ui->workspaceForTest().activate (p);
  472. else if (c != nullptr && c->isShowing())
  473. click (*c, { c->getWidth() - 40, c->getHeight() - 40 });
  474. const auto before = ui->typingPianoForCheck();
  475. const auto markers = engine->getSong().markers().size();
  476. press ('T', juce::ModifierKeys::commandModifier, 't');
  477. line (" Ctrl+T, panel " + juce::String ((int) p) + " focused (" + juce::String ((int) ui->workspaceForTest().getFocused())
  478. + "): typing keyboard " + juce::String ((int) before) + " -> " + juce::String ((int) ui->typingPianoForCheck())
  479. + ", song markers " + juce::String ((int) markers) + " -> " + juce::String ((int) engine->getSong().markers().size()));
  480. if (ui->typingPianoForCheck() != before)
  481. ui->setTypingPianoForTest (before);
  482. }
  483. finish();
  484. break;
  485. }
  486. default:
  487. break;
  488. }
  489. }
  490. void finish()
  491. {
  492. line (ok ? "result=OK" : "result=FAILED");
  493. stopTimer();
  494. done();
  495. }
  496. };
  497. auto* test = new RouteTest();
  498. test->reportPath = reportPath;
  499. startFocusTestWindow (*test);
  500. #if JUCE_WINDOWS
  501. test->main->setAlwaysOnTop (true);
  502. #endif
  503. test->startTimer (700);
  504. }