Keys96Tests.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include "core/HostKeyGate.h"
  2. #include "core/FlWrapper.h"
  3. #include "core/FlpExport.h"
  4. TEST (keys96_gate_keeps_a_taken_key_whole)
  5. {
  6. lynx::HostKeyGate gate;
  7. int asked = 0;
  8. auto yes = [&asked] { ++asked; return true; };
  9. auto no = [&asked] { ++asked; return false; };
  10. // taken: the press, its repeats and its key-up all stay away from the plugin; asked once
  11. CHECK (gate.message ('Q', true, false, yes));
  12. CHECK (gate.message ('Q', true, true, yes));
  13. CHECK (gate.message ('Q', true, true, no));
  14. CHECK (asked == 1);
  15. CHECK (gate.message ('Q', false, false, no));
  16. CHECK (asked == 1);
  17. // released: nothing is left behind, the next key-up is the plugin's
  18. CHECK (! gate.message ('Q', false, false, no));
  19. // left alone: the plugin gets the whole key
  20. CHECK (! gate.message ('W', true, false, no));
  21. CHECK (asked == 2);
  22. CHECK (! gate.message ('W', true, true, yes));
  23. CHECK (asked == 2);
  24. CHECK (! gate.message ('W', false, false, yes));
  25. // a repeat of a key pressed before the plugin had the focus isn't a new press
  26. CHECK (! gate.message ('E', true, true, yes));
  27. CHECK (asked == 2);
  28. // two keys at once are independent
  29. CHECK (gate.message ('A', true, false, yes));
  30. CHECK (! gate.message ('S', true, false, no));
  31. CHECK (! gate.message ('S', false, false, no));
  32. CHECK (gate.message ('A', false, false, no));
  33. // out of range never touches anything
  34. CHECK (! gate.message (300, true, false, yes));
  35. CHECK (! gate.message (300, false, false, yes));
  36. }
  37. TEST (keys187a_a_taken_key_repeats_for_the_host)
  38. {
  39. // round 187a: a held key the host took repeats as over the main window (a shortcut runs again); one the plugin
  40. // got repeats for the plugin only
  41. lynx::HostKeyGate gate;
  42. int asked = 0, again = 0;
  43. auto yes = [&asked] { ++asked; return true; };
  44. auto no = [&asked] { ++asked; return false; };
  45. auto rep = [&again] { ++again; };
  46. CHECK (gate.message (0x20, true, false, yes, rep)); // Space
  47. CHECK (gate.holds (0x20));
  48. CHECK (gate.message (0x20, true, true, yes, rep));
  49. CHECK (gate.message (0x20, true, true, no, rep));
  50. CHECK (asked == 1 && again == 2);
  51. CHECK (gate.message (0x20, false, false, no, rep));
  52. CHECK (! gate.holds (0x20) && again == 2);
  53. CHECK (! gate.message (0x26, true, false, no, rep)); // Up, left to the plugin
  54. CHECK (! gate.message (0x26, true, true, yes, rep));
  55. CHECK (asked == 2 && again == 2);
  56. CHECK (! gate.message (0x26, false, false, yes, rep));
  57. // a repeat of a press made before the focus came here is nobody's new press
  58. CHECK (! gate.message (0x27, true, true, yes, rep));
  59. CHECK (asked == 2 && again == 2);
  60. }
  61. TEST (keys96_options_off_for_a_new_plugin)
  62. {
  63. // FL: the Troubleshooting box is off for a new plugin [UI: E:\lynx-work\pain181c\shots\d21.png]; the plugin gets
  64. // keys first ("Typing keyboard priority" on: FL's General option "Disable typing keyboard priority by default" is
  65. // off, its registry value 0 on the study install, 2026-11-09)
  66. lynx::PluginRef ref;
  67. CHECK (! ref.allowHostKeys);
  68. CHECK (! ref.hostKeysFirst);
  69. auto other = ref;
  70. other.allowHostKeys = true;
  71. CHECK (! (ref == other)); // a project with it on differs (undo, modified)
  72. other = ref;
  73. other.hostKeysFirst = true;
  74. CHECK (! (ref == other));
  75. }
  76. TEST (keys96_option_reads_from_fl_wrapper_flags)
  77. {
  78. // FL 2026: the same project saved with the option off and on differs in this one bit of the second flags word
  79. // (+21; E:\lynx-work\pain181c\flp\off.flp, on.flp, byte 45291: 00 -> 08)
  80. lynx::ForeignPlugin f;
  81. lynx::PluginRef ref;
  82. f.hasWrapperOptions = true;
  83. f.wrapperVersion = 12;
  84. f.wrapperFlags = 0xB4007D8Cu;
  85. f.hasWrapperFlags2 = true;
  86. f.wrapperFlags2 = 0;
  87. lynx::applyFlWrapperOptions (f, ref);
  88. CHECK (! ref.allowHostKeys);
  89. f.wrapperFlags2 = 0x800u;
  90. lynx::applyFlWrapperOptions (f, ref);
  91. CHECK (ref.allowHostKeys && ref.allNotesOffOnStop); // its neighbour 0x1000 untouched
  92. }
  93. TEST (keys96_option_writes_to_fl_wrapper_flags)
  94. {
  95. using namespace lynx;
  96. ForeignPlugin p;
  97. p.format = ForeignPlugin::Format::vst3;
  98. p.name = "Synth";
  99. p.path = "C:/x/Synth.vst3";
  100. p.hasClassId = true;
  101. p.classId[0] = 0xAB;
  102. p.state = flpexport::flVst3State ({ 1, 2, 3 }, { 4 });
  103. for (const bool notesOff : { true, false })
  104. {
  105. PluginRef ref;
  106. ref.allNotesOffOnStop = notesOff;
  107. ForeignPlugin back;
  108. CHECK (parseFlWrapper (flpexport::writeWrapper (p, true, &ref), back) && back.hasWrapperFlags2);
  109. CHECK ((back.wrapperFlags2 & 0x800u) == 0); // off: FL's default record
  110. CHECK (((back.wrapperFlags2 & 0x1000u) != 0) == ! notesOff);
  111. ref.allowHostKeys = true;
  112. CHECK (parseFlWrapper (flpexport::writeWrapper (p, true, &ref), back) && back.hasWrapperFlags2);
  113. CHECK ((back.wrapperFlags2 & 0x800u) != 0);
  114. CHECK (((back.wrapperFlags2 & 0x1000u) != 0) == ! notesOff); // its neighbour untouched
  115. PluginRef read;
  116. applyFlWrapperOptions (back, read);
  117. CHECK (read.allowHostKeys);
  118. }
  119. }
  120. TEST (keys187a_typing_keyboard_priority_is_fl_wrapper_flag_0x01000000)
  121. {
  122. // FL 2026: one project saved with the plugin window's keyboard button on and off differs in this bit only
  123. // (E:\lynx-work\flgap187a\fl\kb-on.flp / kb-off2.flp: wrapper flags 0xB4007D8C -> 0xB5007D8C)
  124. lynx::ForeignPlugin f;
  125. lynx::PluginRef ref;
  126. f.hasWrapperOptions = true;
  127. f.wrapperVersion = 12;
  128. f.wrapperFlags = 0xB4007D8Cu;
  129. lynx::applyFlWrapperOptions (f, ref);
  130. CHECK (! ref.hostKeysFirst);
  131. f.wrapperFlags = 0xB5007D8Cu;
  132. lynx::applyFlWrapperOptions (f, ref);
  133. CHECK (ref.hostKeysFirst && ref.resetOnFlush); // its neighbour 0x02000000 untouched
  134. using namespace lynx;
  135. ForeignPlugin p;
  136. p.format = ForeignPlugin::Format::vst3;
  137. p.name = "Synth";
  138. p.path = "C:/x/Synth.vst3";
  139. p.hasClassId = true;
  140. p.classId[0] = 0xAB;
  141. p.state = flpexport::flVst3State ({ 1, 2, 3 }, { 4 });
  142. for (const bool hostFirst : { false, true })
  143. {
  144. PluginRef r;
  145. r.hostKeysFirst = hostFirst;
  146. ForeignPlugin back;
  147. CHECK (parseFlWrapper (flpexport::writeWrapper (p, true, &r), back) && back.hasWrapperOptions);
  148. CHECK (((back.wrapperFlags & 0x01000000u) != 0) == hostFirst);
  149. PluginRef read;
  150. applyFlWrapperOptions (back, read);
  151. CHECK (read.hostKeysFirst == hostFirst);
  152. }
  153. }
  154. TEST (keys187a_new_plugins_follow_disable_typing_keyboard_priority)
  155. {
  156. // FL's General option (DisablePlugFocusDefaultBox, off): on, a new plugin starts with LYNX first
  157. CHECK (! lynx::pluginkeys::newPluginsHostFirst().load());
  158. CHECK (! lynx::PluginRef {}.hostKeysFirst);
  159. lynx::pluginkeys::newPluginsHostFirst() = true;
  160. const lynx::PluginRef fresh;
  161. lynx::pluginkeys::newPluginsHostFirst() = false;
  162. CHECK (fresh.hostKeysFirst);
  163. CHECK (! lynx::PluginRef {}.hostKeysFirst);
  164. }