Round190teCheck.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Round 190te (0.1.33): #356 effects told the song position of their own audio (LYNX extra, core/LatencyTransport.h),
  2. // queue item 58 (a file dropped into LYNX on Linux finishes the XDND drag as accepted: JUCE fix 62), queue item 82
  3. // (the Playlist's Time markers › Delete, as FL's). Included in the app class of Main.cpp; --round190tetest <report>
  4. // and --selftest "round190te".
  5. juce::String round190teCheck (juce::String& log)
  6. {
  7. using namespace lynx;
  8. juce::String result = "OK";
  9. const auto check = [&] (const juce::String& what, bool ok, const juce::String& detail = {}) {
  10. log << (ok ? "ok " : "FAIL ") << what << (detail.isNotEmpty() ? " (" + detail + ")" : juce::String()) << "\n";
  11. if (! ok && result == "OK")
  12. result = "ERROR " + what;
  13. };
  14. // ---- #356: the extra's two switches, their defaults and its engine path ---------------------------------------
  15. {
  16. check ("356 off by default in the Pattern layout, on in Clip-launch and Simple",
  17. ! extras::defaultOn ("plugins.latencyTransport") && extras::defaultOn ("plugins.latencyTransportOther"));
  18. SettingsHooks hooks;
  19. hooks.getGeneral = [] { return GeneralOptions {}; };
  20. AudioEngine offline (false);
  21. const auto patternBefore = latencytransport::patternOn.load(), otherBefore = latencytransport::otherOn.load();
  22. workflowextras::setExtra ("plugins.latencyTransport", true);
  23. workflowextras::setExtra ("plugins.latencyTransportOther", false);
  24. check ("356 the page's switches reach the engine's flags",
  25. latencytransport::patternOn.load() && ! latencytransport::otherOn.load() && lynxExtraOn (offline, hooks, "plugins.latencyTransport")
  26. && ! lynxExtraOn (offline, hooks, "plugins.latencyTransportOther"));
  27. latencytransport::patternOn = patternBefore;
  28. latencytransport::otherOn = otherBefore;
  29. juce::String engineLog;
  30. const auto engine = latencyTransportSelfTest (engineLog);
  31. log << engineLog;
  32. check ("356 LYNX's play head and the JSFX host (in LYNX's process and in a process of its own)", engine == "OK", engine);
  33. }
  34. // ---- #357: Mixer track › Channel routing › Route selected channels starting from this track (Ctrl+Shift+L) ----
  35. // FL routes each selected Channel rack channel to its own insert in a row from the selected one, naming and
  36. // colouring the inserts after the channels; Ctrl+L routes them all to this one. The key with the Mixer
  37. // focused and with the Channel rack focused (keys sent as the system delivers them: Ctrl = the command key,
  38. // ⌘ on macOS), then the menu items.
  39. {
  40. using Panel = workspace::Panel;
  41. AudioEngine offline (false);
  42. auto song = Song::makeDefault();
  43. song.mixer = Song::defaultMixer ((int) song.channels.size() + 8);
  44. for (std::size_t c = 0; c < song.channels.size(); ++c)
  45. {
  46. song.channels[c].colour = 0xff102030u + (std::uint32_t) c * 0x00101010u;
  47. song.channels[c].mixerTrack = 0;
  48. }
  49. offline.setSong (song);
  50. MainComponent ui (offline, false);
  51. ui.setSize (1600, 900);
  52. const auto settle = [&] {
  53. for (int k = 0; k < 3; ++k)
  54. offline.dispatchPendingMessages();
  55. };
  56. settle();
  57. ui.showPanelsForSnapshot ({ Panel::playlist, Panel::channelRack, Panel::mixer });
  58. settle();
  59. const auto reset = [&] {
  60. offline.editSong ([] (Song& s) {
  61. for (auto& c : s.channels)
  62. c.mixerTrack = 0;
  63. for (std::size_t t = 1; t < s.mixer.size(); ++t)
  64. {
  65. s.mixer[t].name = "Insert " + std::to_string (t);
  66. s.mixer[t].colour = 0;
  67. }
  68. });
  69. settle();
  70. };
  71. const auto describe = [&] {
  72. juce::String d;
  73. const auto& s = offline.getSong();
  74. for (std::size_t c = 0; c < s.channels.size(); ++c)
  75. d << juce::String::fromUTF8 (s.channels[c].name.c_str()) << "->" << s.channels[c].mixerTrack << " ";
  76. for (int t = 3; t <= 5 && t < (int) s.mixer.size(); ++t)
  77. d << "| " << t << " " << juce::String::fromUTF8 (s.mixer[(std::size_t) t].name.c_str()) << " " << juce::String::toHexString ((int) s.mixer[(std::size_t) t].colour);
  78. return d;
  79. };
  80. // channels 1 and 2 selected, insert 3 selected: 1 -> 3, 2 -> 4, the inserts named and coloured after them
  81. const auto routedFrom3 = [&] {
  82. const auto& s = offline.getSong();
  83. return s.channels.size() > 2 && s.channels[1].mixerTrack == 3 && s.channels[2].mixerTrack == 4 && s.channels[0].mixerTrack == 0
  84. && s.mixer[3].name == s.channels[1].name && s.mixer[4].name == s.channels[2].name && s.mixer[3].colour == s.channels[1].colour
  85. && s.mixer[4].colour == s.channels[2].colour && s.mixer[5].name == "Insert 5";
  86. };
  87. const auto allTo3 = [&] {
  88. const auto& s = offline.getSong();
  89. return s.channels.size() > 2 && s.channels[1].mixerTrack == 3 && s.channels[2].mixerTrack == 3 && s.channels[0].mixerTrack == 0;
  90. };
  91. const auto prepare = [&] (Panel focused) {
  92. reset();
  93. offline.setChannelSelection ({ 1, 2 }, 1);
  94. ui.selectMixerTrackForSnapshot (3);
  95. ui.workspaceForTest().activate (focused);
  96. settle();
  97. };
  98. const auto press = [&] (bool shift) {
  99. ui.keyPressed (juce::KeyPress ('L', juce::ModifierKeys (juce::ModifierKeys::commandModifier | (shift ? juce::ModifierKeys::shiftModifier : 0)), 0));
  100. settle();
  101. };
  102. prepare (Panel::mixer);
  103. press (true);
  104. check ("357 Ctrl+Shift+L (Mixer focused): each selected channel to its own insert from the selected one, named and coloured after it",
  105. routedFrom3(), describe());
  106. offline.undo();
  107. settle();
  108. check ("357 ... one undo step puts it back", offline.getSong().channels[1].mixerTrack == 0 && offline.getSong().mixer[3].name == "Insert 3", describe());
  109. prepare (Panel::channelRack);
  110. press (true);
  111. // (FL 2026, live check 190te: with the Channel rack focused the key routes nothing; FL's plain L, Pattern / Song,
  112. // takes it there, which LYNX doesn't copy)
  113. check ("357 Ctrl+Shift+L with the Channel rack focused routes nothing, as in FL", ! routedFrom3() && offline.getSong().channels[1].mixerTrack == 0, describe());
  114. prepare (Panel::mixer);
  115. press (false);
  116. check ("357 Ctrl+L (Mixer focused): all selected channels to the selected insert", allTo3(), describe());
  117. // the menu: Mixer track › Channel routing has both items, in FL's order; each runs
  118. prepare (Panel::mixer);
  119. auto& strips = ui.getMixerForSnapshot().getStripsForSnapshot();
  120. auto menu = strips.buildMenu (3);
  121. juce::PopupMenu* routing = nullptr;
  122. for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
  123. if (it.getItem().text == tr ("Channel routing"))
  124. routing = it.getItem().subMenu.get();
  125. juce::StringArray items;
  126. const juce::PopupMenu::Item* from = nullptr;
  127. if (routing != nullptr)
  128. for (juce::PopupMenu::MenuItemIterator it (*routing); it.next();)
  129. {
  130. items.add (it.getItem().text.upToFirstOccurrenceOf ("\t", false, false));
  131. if (it.getItem().text.startsWith (tr ("Route selected channels starting from this track")))
  132. from = &it.getItem();
  133. }
  134. check ("357 Mixer track > Channel routing: Route selected channels to this track, then ... starting from this track",
  135. items.indexOf (tr ("Route selected channels to this track")) == 0 && items.indexOf (tr ("Route selected channels starting from this track")) == 1,
  136. items.joinIntoString (" | "));
  137. if (from != nullptr && from->isEnabled && from->action != nullptr)
  138. from->action();
  139. settle();
  140. check ("357 ... and the menu item routes them", routedFrom3(), describe());
  141. // FL greys "starting from this track" with one channel selected (live check 190te), and its key does nothing then
  142. reset();
  143. offline.setChannelSelection ({ 2 }, 2);
  144. settle();
  145. menu = strips.buildMenu (3);
  146. bool greyed = false;
  147. for (juce::PopupMenu::MenuItemIterator it (menu, true); it.next();)
  148. if (it.getItem().text.startsWith (tr ("Route selected channels starting from this track")))
  149. greyed = ! it.getItem().isEnabled;
  150. ui.selectMixerTrackForSnapshot (3);
  151. ui.workspaceForTest().activate (Panel::mixer);
  152. settle();
  153. press (true);
  154. check ("357 one channel selected: the item is greyed and Ctrl+Shift+L changes nothing, as in FL",
  155. greyed && offline.getSong().channels[2].mixerTrack == 0 && offline.getSong().mixer[3].name == "Insert 3", describe());
  156. #if JUCE_LINUX || JUCE_WINDOWS
  157. // the way the system delivers them: a click on insert 3's header in a window, then the key to the focused
  158. // component's window (as --keyroute190sjtest), with the Channel rack's own key map in front of it
  159. if (juce::Desktop::getInstance().getDisplays().getPrimaryDisplay() != nullptr)
  160. {
  161. reset();
  162. offline.setChannelSelection ({ 1, 2 }, 1);
  163. juce::DocumentWindow window ("round190te #357", juce::Colours::black, 0);
  164. window.setUsingNativeTitleBar (true);
  165. window.setContentNonOwned (&ui, true);
  166. window.setVisible (true);
  167. ui.workspaceForTest().activate (Panel::channelRack);
  168. ui.grabKeyboardFocus(); // (as the app's main window gives it at start)
  169. for (int k = 0; k < 20; ++k)
  170. settle();
  171. // (the peer the Mixer is in: on Windows each panel has a native window of its own inside the main one)
  172. auto* peer = strips.getPeer() != nullptr ? strips.getPeer() : window.getPeer();
  173. if (peer != nullptr && strips.isShowing())
  174. {
  175. const auto at = peer->getComponent().getLocalPoint (&strips, strips.headerAreaForSnapshot (3).getCentre().toFloat());
  176. const auto now = juce::Time::currentTimeMillis();
  177. peer->handleMouseEvent (juce::MouseInputSource::InputSourceType::mouse, at, juce::ModifierKeys (juce::ModifierKeys::leftButtonModifier), 1.0f, 0.0f, now);
  178. peer->handleMouseEvent (juce::MouseInputSource::InputSourceType::mouse, at, {}, 1.0f, 0.0f, now + 40);
  179. settle();
  180. const juce::ModifierKeys mods (juce::ModifierKeys::commandModifier | juce::ModifierKeys::shiftModifier);
  181. auto* focused = juce::Component::getCurrentlyFocusedComponent();
  182. auto* keyPeer = focused != nullptr && focused->getPeer() != nullptr ? focused->getPeer() : peer;
  183. juce::String arrived;
  184. MainComponent::keySeenForCheck = [&arrived] (const juce::KeyPress& k) { arrived << k.getTextDescription() << " "; };
  185. juce::ModifierKeys::currentModifiers = mods;
  186. keyPeer->handleKeyPress (juce::KeyPress ('L', mods, 0));
  187. juce::ModifierKeys::currentModifiers = {};
  188. MainComponent::keySeenForCheck = nullptr;
  189. settle();
  190. juce::String focusPath;
  191. for (auto* c = focused; c != nullptr && focusPath.length() < 200; c = c->getParentComponent())
  192. focusPath << (focusPath.isEmpty() ? "" : " < ") << juce::String (typeid (*c).name()).getLastCharacters (30);
  193. juce::String selectedChannels;
  194. for (auto c : offline.getSelectedChannels())
  195. selectedChannels << c << " ";
  196. log << "info 357 click test: focused " << focusPath << "; the main window got: " << (arrived.isEmpty() ? juce::String ("nothing") : arrived)
  197. << "; selected channels after the click: " << selectedChannels << "\n";
  198. check ("357 a click on insert 3 in a window, then Ctrl+Shift+L as the system sends it: the row is routed",
  199. routedFrom3(), describe() + " (focused panel " + juce::String ((int) ui.workspaceForTest().getFocused()) + ")");
  200. }
  201. else
  202. log << "info 357 the Mixer isn't showing in the window: the click test is skipped\n";
  203. window.setVisible (false);
  204. window.clearContentComponent();
  205. settle();
  206. }
  207. #endif
  208. }
  209. // ---- item 82: the Playlist's Time markers › Delete -----------------------------------------------------------
  210. {
  211. AudioEngine offline (false);
  212. offline.setSong (Song::makeDefault());
  213. PlaylistComponent playlist (offline);
  214. playlist.setSize (1200, 600);
  215. const auto timeMarkersItem = [&] (const juce::String& text) { // (Time markers' own item, not a marker's)
  216. const auto menu = playlist.rulerMenu (300, 4);
  217. for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
  218. if (it.getItem().text == tr ("Time markers") && it.getItem().subMenu != nullptr)
  219. for (juce::PopupMenu::MenuItemIterator sub (*it.getItem().subMenu); sub.next();)
  220. if (sub.getItem().text == text && sub.getItem().action != nullptr)
  221. return std::optional<bool> (sub.getItem().isEnabled);
  222. return std::optional<bool>();
  223. };
  224. const auto state = [] (std::optional<bool> v) { return v.has_value() ? juce::String (*v ? "enabled" : "greyed") : juce::String ("missing"); };
  225. const auto none = timeMarkersItem (tr ("Delete")), noLoop = timeMarkersItem (tr ("Change to marker loop"));
  226. check ("82 with no marker and no time selection, Time markers > Delete and Change to marker loop are enabled, as in FL 2026's Playlist",
  227. none.has_value() && *none && noLoop.has_value() && *noLoop, state (none) + ", " + state (noLoop));
  228. const auto markersBefore = offline.getSong().markers().size();
  229. juce::PopupMenu menu = playlist.rulerMenu (300, 4);
  230. for (juce::PopupMenu::MenuItemIterator it (menu, true); it.next();)
  231. if ((it.getItem().text == tr ("Delete") || it.getItem().text == tr ("Change to marker loop")) && it.getItem().action != nullptr)
  232. it.getItem().action();
  233. offline.dispatchPendingMessages();
  234. check ("82 ... and then they change nothing", offline.getSong().markers().size() == markersBefore && ! offline.getSong().hasLoop());
  235. offline.editSong ([] (Song& s) { s.addMarker ({ 4 * (std::int64_t) ppq, "Verse" }); });
  236. offline.dispatchPendingMessages();
  237. const auto one = timeMarkersItem (tr ("Delete"));
  238. check ("82 ... Delete with a marker", one.has_value() && *one);
  239. }
  240. #if JUCE_LINUX
  241. // ---- item 58: a file dropped into LYNX finishes the drag as accepted, action copy (JUCE fix 62) --------------
  242. // GTK-, Qt- and XWayland-style sources (ui/XdndTestSourceX11, round 190sk / 190sq) drag a file onto a JUCE
  243. // component that takes files, then onto one that refuses them
  244. if (juce::Desktop::getInstance().getDisplays().getPrimaryDisplay() != nullptr && std::getenv ("LYNX_SKIP_XDND190TE") == nullptr)
  245. {
  246. const auto settle = [] (int ms) {
  247. const auto end = juce::Time::getMillisecondCounter() + (juce::uint32) ms;
  248. while (juce::Time::getMillisecondCounter() < end)
  249. {
  250. for (int i = 0; i < 256 && juce::detail::dispatchNextMessageOnSystemQueue (true); ++i) {}
  251. juce::Thread::sleep (2);
  252. }
  253. };
  254. const auto root = juce::File::getSpecialLocation (juce::File::tempDirectory).getChildFile ("lynx-190te-" + juce::String (juce::Random::getSystemRandom().nextInt (1 << 30)));
  255. const auto wav = root.getChildFile ("drop/loop 58.wav");
  256. wav.getParentDirectory().createDirectory();
  257. wav.replaceWithText ("RIFF");
  258. const auto uri = juce::URL (wav).toString (false).toStdString();
  259. struct Target final : juce::Component, juce::FileDragAndDropTarget
  260. {
  261. explicit Target (bool t) : takes (t) {}
  262. const bool takes;
  263. int drops = 0;
  264. juce::StringArray files;
  265. bool isInterestedInFileDrag (const juce::StringArray&) override { return takes; }
  266. void filesDropped (const juce::StringArray& f, int, int) override
  267. {
  268. ++drops;
  269. files = f;
  270. }
  271. void paint (juce::Graphics& g) override { g.fillAll (juce::Colour (takes ? 0xff303038 : 0xff383030)); }
  272. };
  273. struct Host final : juce::Component
  274. {
  275. Target taking { true }, refusing { false };
  276. Host()
  277. {
  278. addAndMakeVisible (taking);
  279. addAndMakeVisible (refusing);
  280. }
  281. void resized() override
  282. {
  283. taking.setBounds (0, 0, getWidth() / 2, getHeight());
  284. refusing.setBounds (getWidth() / 2, 0, getWidth() / 2, getHeight());
  285. }
  286. } host;
  287. host.setSize (800, 300);
  288. juce::DocumentWindow window ("round190te item 58", juce::Colours::black, 0);
  289. window.setUsingNativeTitleBar (true);
  290. window.setContentNonOwned (&host, true);
  291. window.setTopLeftPosition (80, 80);
  292. window.setVisible (true);
  293. settle (400);
  294. auto* peer = window.getPeer();
  295. const auto handle = peer != nullptr ? (unsigned long) (juce::pointer_sized_uint) peer->getNativeHandle() : 0ul;
  296. const auto physical = [] (juce::Point<int> g) { return juce::Desktop::getInstance().getDisplays().logicalToPhysical (g); };
  297. // the XdndActionCopy atom (atoms are the server's: any connection gives the same number)
  298. unsigned long copyAtom = 0;
  299. if (auto* x11 = dlopen ("libX11.so.6", RTLD_NOW))
  300. {
  301. auto open = (void* (*) (const char*)) dlsym (x11, "XOpenDisplay");
  302. auto close = (int (*) (void*)) dlsym (x11, "XCloseDisplay");
  303. auto intern = (unsigned long (*) (void*, const char*, int)) dlsym (x11, "XInternAtom");
  304. if (auto* d = open != nullptr && close != nullptr && intern != nullptr ? open (nullptr) : nullptr)
  305. {
  306. copyAtom = intern (d, "XdndActionCopy", 0);
  307. close (d);
  308. }
  309. }
  310. check ("58 the test window and the XdndActionCopy atom", handle != 0 && copyAtom != 0);
  311. const auto path = [&] (juce::Component& over) {
  312. std::vector<xdndtest::Step> steps;
  313. const auto a = physical (over.localPointToGlobal (juce::Point<int> (20, 20)));
  314. const auto b = physical (over.localPointToGlobal (over.getLocalBounds().getCentre()));
  315. for (int i = 0; i <= 12; ++i)
  316. steps.push_back ({ a.x + (b.x - a.x) * i / 12, a.y + (b.y - a.y) * i / 12, i == 0 || i == 12 ? 300 : 16 });
  317. return steps;
  318. };
  319. const auto runDrag = [&] (const std::vector<xdndtest::Step>& steps, xdndtest::Style style) {
  320. std::atomic<bool> done { false };
  321. xdndtest::PathResult r;
  322. std::thread source ([&] {
  323. r = xdndtest::runPath (handle, steps, uri, style, style == xdndtest::Style::gtk || style == xdndtest::Style::qt ? 0 : 20, true);
  324. done = true;
  325. });
  326. const auto end = juce::Time::getMillisecondCounter() + 20000u;
  327. while (! done.load() && juce::Time::getMillisecondCounter() < end)
  328. settle (4);
  329. source.join();
  330. settle (200);
  331. return r;
  332. };
  333. const auto describe = [] (const xdndtest::PathResult& r) {
  334. return "statuses " + juce::String (r.statusesFromTarget) + " (accepted " + juce::String (r.acceptedFromTarget) + "), finished "
  335. + juce::String (r.finishedFromTarget) + ": flags " + juce::String (r.finishedFlags) + ", action " + juce::String ((juce::int64) r.finishedAction)
  336. + (r.error.empty() ? juce::String() : ", " + juce::String (r.error));
  337. };
  338. if (handle != 0 && copyAtom != 0)
  339. for (const auto& [name, style] : { std::pair { "GTK file manager", xdndtest::Style::gtk }, std::pair { "Qt file manager", xdndtest::Style::qt },
  340. std::pair { "Wayland file manager (XWayland)", xdndtest::Style::xwayland } })
  341. {
  342. host.taking.drops = host.refusing.drops = 0;
  343. auto r = runDrag (path (host.taking), style);
  344. check (juce::String ("58 ") + name + ": a drop LYNX takes finishes as accepted, action copy",
  345. r.ran && host.taking.drops == 1 && host.taking.files.size() == 1 && host.taking.files[0].endsWith ("loop 58.wav")
  346. && r.finishedFromTarget == 1 && (r.finishedFlags & 1) == 1 && (unsigned long) r.finishedAction == copyAtom,
  347. describe (r));
  348. r = runDrag (path (host.refusing), style);
  349. check (juce::String ("58 ") + name + ": a drop nobody takes finishes as not accepted, no action",
  350. r.ran && host.refusing.drops == 0 && host.taking.drops == 1 && r.finishedFromTarget == 1 && (r.finishedFlags & 1) == 0
  351. && r.finishedAction == 0,
  352. describe (r));
  353. }
  354. window.setVisible (false);
  355. window.clearContentComponent();
  356. settle (100);
  357. root.deleteRecursively();
  358. }
  359. else
  360. log << "info 58 skipped: no display\n";
  361. #endif
  362. return result;
  363. }