Layout172aTests.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Round 172a: the FL engines' designed pages — Harmor's page in FL's arrangement with both parts and the global strip,
  2. // Sytrus' FM / RM matrix, and no page with an empty titled panel or a note about what LYNX doesn't edit.
  3. #include <algorithm>
  4. #include <cctype>
  5. #include <cstring>
  6. #include <set>
  7. #include "core/HarmorControls.h"
  8. #include "core/PluginLayoutSynths.h"
  9. namespace layout172a
  10. {
  11. bool inside (const lynx::plugui::LayoutItem& outer, const lynx::plugui::LayoutItem& inner)
  12. {
  13. const auto cx = inner.x + inner.w * 0.5f, cy = inner.y + inner.h * 0.5f;
  14. return cx >= outer.x && cx <= outer.x + outer.w && cy >= outer.y && cy <= outer.y + outer.h;
  15. }
  16. bool samePage (const lynx::plugui::LayoutItem& a, const lynx::plugui::LayoutItem& b)
  17. {
  18. return a.page < 0 || b.page < 0 || a.page == b.page;
  19. }
  20. std::string lower (std::string s)
  21. {
  22. std::transform (s.begin(), s.end(), s.begin(), [] (unsigned char c) { return (char) std::tolower (c); });
  23. return s;
  24. }
  25. } // namespace layout172a
  26. TEST (layout172a_engine_pages_have_no_empty_panels_or_notes)
  27. {
  28. using namespace lynx;
  29. using plugui::Item;
  30. int pages = 0;
  31. for (const auto kind : plugui::instrumentLayoutKinds())
  32. {
  33. const auto* layout = plugui::instrumentLayout (kind);
  34. if (layout == nullptr)
  35. continue;
  36. ++pages;
  37. for (const auto& s : layout->items)
  38. {
  39. // no text about what LYNX leaves as saved / doesn't play / has no presets for
  40. if (s.label != nullptr)
  41. {
  42. const auto text = layout172a::lower (s.label);
  43. for (const char* bad : { "saved patch", "not played", "no lynx presets", "not decoded", "not edited", "not editable" })
  44. {
  45. CHECK (text.find (bad) == std::string::npos);
  46. if (text.find (bad) != std::string::npos)
  47. std::printf (" %s: note on the page: \"%s\"\n", layout->fl, s.label);
  48. }
  49. }
  50. // a titled panel holds a control (or a display) of its own page
  51. if (s.type != Item::section || s.label == nullptr || *s.label == 0)
  52. continue;
  53. const auto filled = std::any_of (layout->items.begin(), layout->items.end(), [&] (const plugui::LayoutItem& i) {
  54. return &i != &s && i.type != Item::section && i.type != Item::label && layout172a::samePage (s, i) && layout172a::inside (s, i);
  55. });
  56. CHECK (filled);
  57. if (! filled)
  58. std::printf (" %s: empty panel \"%s\"\n", layout->fl, s.label);
  59. }
  60. }
  61. CHECK (pages >= 30);
  62. }
  63. TEST (layout172a_harmor_page_edits_both_parts_and_the_global_strip)
  64. {
  65. using namespace lynx;
  66. const auto* layout = plugui::instrumentLayout (InstrumentKind::harmor);
  67. CHECK (layout != nullptr);
  68. if (layout == nullptr)
  69. return;
  70. CHECK (layout->pages.size() == 2u); // part A / part B
  71. std::set<std::string> known, shown;
  72. for (const auto& c : harmorui::controls())
  73. CHECK (known.insert (c.name).second); // unique names (the knobs' names)
  74. for (const auto& item : layout->items)
  75. {
  76. for (const char* p : { item.param, item.param2 })
  77. if (p != nullptr)
  78. {
  79. CHECK (known.count (p) == 1);
  80. shown.insert (p);
  81. }
  82. if (item.param != nullptr && plugui::isValueControl (item.type))
  83. {
  84. // part controls sit on their part's page, global ones on both
  85. const auto part = std::string (item.param).rfind ("A: ", 0) == 0 ? 0 : std::string (item.param).rfind ("B: ", 0) == 0 ? 1 : -1;
  86. CHECK (item.page == part);
  87. }
  88. CHECK (item.x >= 0.0f && item.y >= 0.0f && item.x + item.w <= (float) layout->width + 0.5f && item.y + item.h <= (float) layout->height + 0.5f);
  89. }
  90. CHECK (shown.size() == known.size()); // every control is on the page
  91. CHECK (harmorui::controls().size() > 120);
  92. // every control reads a value of a real state within (or at) FL's range, and writes back into it
  93. // a two-part state: the test patch's part A block (length-prefixed) repeated as part B
  94. auto state = harmorTestState (false);
  95. {
  96. std::uint32_t size = 0;
  97. std::memcpy (&size, state.data() + 8, 4);
  98. const auto partEnd = (std::ptrdiff_t) (8 + 4 + size);
  99. state.insert (state.begin() + partEnd, state.begin() + 8, state.begin() + partEnd);
  100. state[4] = 1 | 2 | 4;
  101. }
  102. for (const auto& c : harmorui::controls())
  103. {
  104. const auto at = harmorParamOffset (state, c.part, c.index);
  105. CHECK (at >= 0);
  106. if (at < 0)
  107. std::printf (" no Harmor parameter for \"%s\"\n", c.name.c_str());
  108. }
  109. const auto cutoffB = harmorParamOffset (state, 1, 52);
  110. CHECK (cutoffB >= 0 && cutoffB != harmorParamOffset (state, 0, 52));
  111. CHECK (harmorui::name (1, 52) != nullptr && std::string (harmorui::name (1, 52)) == "B: Filter 1 frequency");
  112. CHECK (harmorui::name (-1, 12) != nullptr && harmorui::name (0, 3) == nullptr);
  113. }
  114. TEST (layout172a_sytrus_page_shows_the_matrix)
  115. {
  116. using namespace lynx;
  117. const auto* layout = plugui::instrumentLayout (InstrumentKind::sytrus);
  118. CHECK (layout != nullptr);
  119. if (layout == nullptr)
  120. return;
  121. std::set<std::string> settings;
  122. for (const auto& s : sytrus::settings())
  123. settings.insert (s.name);
  124. int cells = 0, fm = 0, rm = 0;
  125. for (const auto& item : layout->items)
  126. if (item.param != nullptr && plugui::isValueControl (item.type))
  127. {
  128. CHECK (settings.count (item.param) == 1); // every control is one of the engine's settings
  129. const std::string p = item.param;
  130. const auto endsWith = [&p] (const char* tail) { const std::string t = tail; return p.size() > t.size() && p.compare (p.size() - t.size(), t.size(), t) == 0; };
  131. const auto opOrFilter = p.rfind ("Op ", 0) == 0 || p.rfind ("Filter ", 0) == 0;
  132. if (p.rfind ("FM ", 0) == 0 || p.rfind ("RM ", 0) == 0 || (opOrFilter && (endsWith (" pan") || endsWith (" FX") || endsWith (" out"))))
  133. {
  134. ++cells;
  135. fm += p.rfind ("FM ", 0) == 0 && item.page == 0 ? 1 : 0;
  136. rm += p.rfind ("RM ", 0) == 0 && item.page == 1 ? 1 : 0;
  137. }
  138. }
  139. CHECK (cells == 81 + 54 && fm == 54 && rm == 54);
  140. CHECK (layout->pages.size() == 2u);
  141. }