Design168nTests.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Round 168n (docs/analise/REA_rodada168n.md): designed editors of Toxic Biohazard and PoiZone, their automatable
  2. // parameters (core/ModelParams.h), LYNX's own preset banks (core/LynxBanks.h) and the live parameter queue.
  3. #include "core/EngineParams.h"
  4. #include "core/LynxBanks.h"
  5. #include "core/ModelParams.h"
  6. #include "core/PluginLayout.h"
  7. #include "core/PoiZone.h"
  8. #include "core/Toxic.h"
  9. namespace design168n
  10. {
  11. struct Level
  12. {
  13. float peak = 0.0f;
  14. double rms = 0.0;
  15. bool finite = true;
  16. };
  17. Level measure (const std::vector<float>& interleaved)
  18. {
  19. Level l;
  20. double sum = 0.0;
  21. for (const auto v : interleaved)
  22. {
  23. if (! std::isfinite (v))
  24. l.finite = false;
  25. l.peak = std::max (l.peak, std::fabs (v));
  26. sum += (double) v * v;
  27. }
  28. l.rms = interleaved.empty() ? 0.0 : std::sqrt (sum / (double) interleaved.size());
  29. return l;
  30. }
  31. // a held C3 (and for polyphonic presets an E3 / G3 on top), 2 s, released, 1 s of tail at 48 kHz
  32. template <typename Note>
  33. std::vector<Note> phrase (bool chord)
  34. {
  35. std::vector<Note> notes;
  36. for (const auto key : { 48, 52, 55 })
  37. {
  38. Note n;
  39. n.key = key;
  40. n.start = 0;
  41. n.release = 96000;
  42. notes.push_back (n);
  43. if (! chord)
  44. break;
  45. }
  46. return notes;
  47. }
  48. } // namespace design168n
  49. TEST (design168n_engine_param_tables)
  50. {
  51. using namespace lynx;
  52. for (const auto* table : { &toxicParams(), &poizoneParams() })
  53. {
  54. CHECK (table->size() >= 80);
  55. std::set<std::string> names;
  56. for (std::size_t i = 0; i < table->size(); ++i)
  57. {
  58. const auto& p = (*table)[i];
  59. CHECK (names.insert (p.name).second); // unique names (the knobs' and the clips' names)
  60. CHECK (i == 0 || (*table)[i - 1].index < p.index); // sorted by index
  61. CHECK (p.high > p.low);
  62. CHECK (findEngineParam (*table, p.index) == &p);
  63. }
  64. }
  65. CHECK (findEngineParam (toxicParams(), 294) == nullptr); // (an internal value; round 169h listed the sequencer)
  66. const auto* poly = findEngineParam (toxicParams(), 301);
  67. CHECK (poly != nullptr && poly->stepped && poly->raw (1.0f) == 32.0f && poly->raw (0.5f) == 16.0f);
  68. const auto* unison = findEngineParam (poizoneParams(), 75);
  69. CHECK (unison != nullptr && unison->raw (0.34f) == 2.0f && std::fabs (unison->normalised (3.0f) - 0.5f) < 1e-6f);
  70. }
  71. TEST (design168n_layouts_name_real_parameters)
  72. {
  73. using namespace lynx;
  74. // every value control of the two designed pages edits a listed parameter of its engine
  75. for (const auto kind : { InstrumentKind::toxic, InstrumentKind::poizone })
  76. {
  77. const auto* layout = plugui::instrumentLayout (kind);
  78. CHECK (layout != nullptr);
  79. if (layout == nullptr)
  80. continue;
  81. int controls = 0;
  82. for (const auto& item : layout->items)
  83. {
  84. if (item.param != nullptr && plugui::isValueControl (item.type))
  85. {
  86. ++controls;
  87. const auto* p = modelparams::findByName (kind, item.param);
  88. CHECK (p != nullptr);
  89. if (p == nullptr)
  90. std::printf (" (no parameter \"%s\")\n", item.param);
  91. }
  92. if (item.whenParam != nullptr)
  93. CHECK (modelparams::findByName (kind, item.whenParam) != nullptr);
  94. // inside the page
  95. 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);
  96. }
  97. CHECK (controls > (kind == InstrumentKind::toxic ? 150 : 70));
  98. }
  99. // the FM grid: 36 cells, "FM i to j" = parameter 109 + 6 (j − 1) + (i − 1) (REA_rodada45 §3.6)
  100. const auto* cell = modelparams::findByName (InstrumentKind::toxic, "FM 2 to 1");
  101. CHECK (cell != nullptr && cell->index == 110);
  102. }
  103. TEST (design168n_model_params_read_and_write_the_state)
  104. {
  105. using namespace lynx;
  106. ChannelDef c;
  107. c.instrument = InstrumentKind::toxic;
  108. c.pluginState = toxicDefaultState();
  109. CHECK (modelparams::rawValue (c, 0) == 0.5f); // Gain's constructor value
  110. CHECK (modelparams::rawValue (c, 301) == 8.0f); // polyphony 8
  111. CHECK (modelparams::setValue01 (c, 15, 0.25f) && modelparams::rawValue (c, 15) == 0.25f);
  112. CHECK (modelparams::setValue01 (c, 300, 1.0f) && modelparams::rawValue (c, 300) == 3.0f); // filter mode HP
  113. CHECK (! modelparams::setValue01 (c, 294, 0.5f)); // not listed
  114. // automation clips: the Song reads and writes them like any target
  115. Song s;
  116. s.channels.push_back (c);
  117. const AutomationTarget t { AutomationTargetKind::channelParam, 0, 0, 16 };
  118. CHECK (s.setTargetValue (t, 0.75f));
  119. CHECK (std::fabs (s.targetValue (t) - 0.75f) < 1e-6f);
  120. CHECK (modelparams::rawValue (s.channels[0], 16) == 0.75f);
  121. ChannelDef pz;
  122. pz.instrument = InstrumentKind::poizone;
  123. pz.pluginState = poizoneDefaultState();
  124. CHECK (poizoneStateUsable (pz.pluginState));
  125. CHECK (modelparams::rawValue (pz, 76) == 12.0f); // constructor polyphony
  126. CHECK (modelparams::setValue01 (pz, 18, 0.3f) && poizoneParam (pz.pluginState, 18) == 0.3f);
  127. }
  128. TEST (design168n_live_param_queue)
  129. {
  130. lynx::LiveParamQueue q;
  131. CHECK (q.space() == 1023);
  132. for (int i = 0; i < 1023; ++i)
  133. CHECK (q.push (i, (float) i));
  134. CHECK (! q.push (5000, 1.0f)); // full
  135. int n = 0;
  136. bool ordered = true;
  137. q.drain ([&] (int i, float v) { ordered = ordered && i == n && v == (float) n; ++n; });
  138. CHECK (n == 1023 && ordered && q.space() == 1023);
  139. }
  140. TEST (design168n_banks_play_clean)
  141. {
  142. using namespace lynx;
  143. using namespace design168n;
  144. for (const auto kind : { InstrumentKind::toxic, InstrumentKind::poizone })
  145. {
  146. const auto& bank = banks::bankOf (kind);
  147. CHECK (bank.size() >= 20);
  148. std::set<std::string> names, categories;
  149. for (int i = 0; i < (int) bank.size(); ++i)
  150. {
  151. const auto& preset = bank[(std::size_t) i];
  152. CHECK (names.insert (preset.name).second);
  153. categories.insert (preset.category);
  154. CHECK (! preset.tags.empty());
  155. ChannelDef c;
  156. c.instrument = kind;
  157. c.name = "Mine";
  158. c.volume = 0.6f;
  159. const auto loaded = banks::withPreset (c, i);
  160. CHECK (loaded && loaded->name == preset.name && loaded->volume == 0.6f && loaded->instrument == kind);
  161. if (! loaded)
  162. continue;
  163. std::vector<float> out;
  164. if (kind == InstrumentKind::toxic)
  165. {
  166. CHECK (toxicStateUsable (loaded->pluginState) && ! toxicNeedsDll (loaded->pluginState));
  167. out = toxic::renderReference (loaded->pluginState, phrase<toxic::RefNote> (true), 48000.0, 144000, "");
  168. }
  169. else
  170. {
  171. CHECK (poizoneStateUsable (loaded->pluginState));
  172. out = poizone::renderReference (loaded->pluginState, phrase<poizone::RefNote> (true), 48000.0, 144000);
  173. }
  174. const auto level = measure (out);
  175. const auto clean = level.finite && level.peak < 1.0f && level.rms > 1.0e-3;
  176. CHECK (clean);
  177. if (! clean || std::getenv ("LYNX_BANK_LEVELS") != nullptr)
  178. std::printf (" %s / %s: peak %.3f rms %.4f\n", kind == InstrumentKind::toxic ? "Toxic" : "PoiZone", preset.name.c_str(),
  179. level.peak, level.rms);
  180. }
  181. for (const auto* category : { "Bass", "Lead", "Pad", "Pluck", "Keys", "FX" })
  182. CHECK (categories.count (category) == 1);
  183. }
  184. CHECK (banks::indexOfPath (banks::pathOf (17)) == 17 && banks::indexOfPath ("C:/x.fst") == -1 && banks::indexOfPath ("lynxbank:") == -1);
  185. CHECK (banks::relativeOf (banks::bankOf (InstrumentKind::poizone)[1]) == "LYNX/Bass/Acid Line");
  186. }