4
0

Design168pTests.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // Round 168p: the designed pages of FL's drum and physical-model generators and LYNX's own banks for them.
  2. #include "core/BankStates.h"
  3. #include "core/DrumControls.h"
  4. #include "core/DrumParamRanges.h"
  5. namespace design168p
  6. {
  7. const lynx::InstrumentKind kinds[] = { lynx::InstrumentKind::fruitkick, lynx::InstrumentKind::plucked, lynx::InstrumentKind::drumpad,
  8. lynx::InstrumentKind::drumaxx, lynx::InstrumentKind::bassdrum, lynx::InstrumentKind::drumsynth,
  9. lynx::InstrumentKind::sakura, lynx::InstrumentKind::slayer };
  10. } // namespace design168p
  11. TEST (design168p_every_drum_engine_has_fl_arrangement)
  12. {
  13. using namespace lynx;
  14. for (const auto kind : design168p::kinds)
  15. {
  16. const auto* layout = plugui::instrumentLayout (kind);
  17. CHECK (layout != nullptr);
  18. if (layout == nullptr)
  19. continue;
  20. CHECK (*layout->fl != 0);
  21. CHECK (std::find (plugui::instrumentLayoutKinds().begin(), plugui::instrumentLayoutKinds().end(), kind) != plugui::instrumentLayoutKinds().end());
  22. for (const auto& item : layout->items)
  23. {
  24. // inside the page (FL's panel size)
  25. CHECK (item.x >= -1.0f && item.y >= -1.0f);
  26. CHECK (item.x + item.w <= (float) layout->width + 1.0f);
  27. CHECK (item.y + item.h <= (float) layout->height + 1.0f);
  28. CHECK (item.page < (int) std::max<std::size_t> (1, layout->pages.size()));
  29. }
  30. }
  31. }
  32. TEST (design168p_layout_controls_match_the_engine_tables)
  33. {
  34. using namespace lynx;
  35. for (const auto kind : design168p::kinds)
  36. {
  37. const auto* layout = plugui::instrumentLayout (kind);
  38. if (layout == nullptr)
  39. continue;
  40. const auto& table = drumcontrols::controls (kind);
  41. CHECK (! table.empty());
  42. // every value item edits a control of the engine, at most once per page
  43. std::set<std::pair<int, std::string>> seen;
  44. for (const auto& item : layout->items)
  45. {
  46. if (! plugui::isValueControl (item.type) || item.param == nullptr)
  47. continue;
  48. const auto* c = drumcontrols::find (kind, item.param);
  49. CHECK (c != nullptr);
  50. if (c == nullptr)
  51. std::printf (" no control '%s'\n", item.param);
  52. CHECK (seen.insert ({ item.page, item.param }).second);
  53. // menus / steppers / radios: one option per whole value of the control
  54. if (c != nullptr && (item.type == plugui::Item::menu || item.type == plugui::Item::radio))
  55. CHECK ((int) plugui::optionLabels (item).size() == (int) (c->high - c->low) + 1);
  56. }
  57. // every control of the engine is reachable on the page (the panel's displays edit none)
  58. for (const auto& c : table)
  59. {
  60. const auto shown = std::any_of (layout->items.begin(), layout->items.end(),
  61. [&c] (const plugui::LayoutItem& i) { return i.param != nullptr && std::strcmp (i.param, c.name) == 0; });
  62. CHECK (shown);
  63. if (! shown)
  64. std::printf (" '%s' not on the page\n", c.name);
  65. }
  66. }
  67. }
  68. TEST (design168p_controls_read_and_write_their_storage)
  69. {
  70. using namespace lynx;
  71. // Fruit Kick (version-0 state built by the bank code)
  72. auto kick = bankstates::channelFor ("fruitkick", { 100, -500, 70, 130, 20, 5 });
  73. CHECK (kick && kick->instrument == InstrumentKind::fruitkick && fruitKickStateUsable (kick->pluginState));
  74. const auto* minFreq = drumcontrols::find (InstrumentKind::fruitkick, "Min freq");
  75. CHECK (minFreq != nullptr && drumcontrols::value (*kick, *minFreq) == -500.0f);
  76. CHECK (drumcontrols::setValue (*kick, *minFreq, -5000.0f)); // clamped to the knob's range
  77. CHECK (fruitKickParam (kick->pluginState, 1) == -1200);
  78. // Plucked!: a fresh channel (no state) shows the engine's defaults and gets a state on the first edit
  79. ChannelDef empty;
  80. empty.instrument = InstrumentKind::plucked;
  81. CHECK (drumcontrols::value (empty, *drumcontrols::find (InstrumentKind::plucked, "Decay")) == 128.0f);
  82. CHECK (drumcontrols::setValue (empty, *drumcontrols::find (InstrumentKind::plucked, "Gate"), 1.0f));
  83. CHECK (pluckedStateUsable (empty.pluginState) && drumcontrols::value (empty, *drumcontrols::find (InstrumentKind::plucked, "Color")) == 64.0f);
  84. auto pluck = bankstates::channelFor ("plucked", { 200, 30, 1, 0, 1 });
  85. CHECK (pluck && pluckedStateUsable (pluck->pluginState));
  86. CHECK (drumcontrols::value (*pluck, *drumcontrols::find (InstrumentKind::plucked, "Color")) == 30.0f);
  87. // Drumaxx: the selected pad's voice is at pad·44 + 5 + Drumpad's index
  88. std::vector<bankstates::DrumaxxPad> pads (3);
  89. pads[2].voice.assign (38, 0.25f);
  90. pads[2].voice[29] = 0.75f; // pitch
  91. ChannelDef maxx;
  92. maxx.instrument = InstrumentKind::drumaxx;
  93. maxx.pluginState = bankstates::drumaxxState ("LYNX test", pads);
  94. CHECK (drumaxxStateUsable (maxx.pluginState));
  95. CHECK (drumaxxKitName (maxx.pluginState) == "LYNX test");
  96. const auto* pitch = drumcontrols::find (InstrumentKind::drumaxx, "Pitch");
  97. CHECK (pitch != nullptr && pitch->perPart);
  98. CHECK (drumcontrols::value (maxx, *pitch, 2) == 0.75f);
  99. CHECK (drumcontrols::value (maxx, *pitch, 0) == 0.0f);
  100. CHECK (drumcontrols::setValue (maxx, *pitch, 0.4f, 1));
  101. CHECK (drumaxxParam (maxx.pluginState, 44 + 5 + 29) == 0.4f);
  102. CHECK (drumcontrols::value (maxx, *drumcontrols::find (InstrumentKind::drumaxx, "Pad 3 volume")) == 0.8f);
  103. // DrumSynth Live: the editor key's patch
  104. std::vector<bankstates::DrumSynthPatch> patches (1);
  105. patches[0].key = 50;
  106. patches[0].values.assign (38, 10);
  107. ChannelDef dsl;
  108. dsl.instrument = InstrumentKind::drumsynth;
  109. dsl.modelParams = bankstates::drumSynthParams (patches);
  110. CHECK (drumcontrols::defaultPart (dsl) == 50);
  111. const auto* level = drumcontrols::find (InstrumentKind::drumsynth, "Level");
  112. CHECK (drumcontrols::value (dsl, *level, 50) == 10.0f);
  113. CHECK (drumcontrols::value (dsl, *level, 51) == 0.0f);
  114. CHECK (drumcontrols::setValue (dsl, *level, 200.0f, 51) && drumcontrols::value (dsl, *level, 51) == 128.0f);
  115. }
  116. namespace design168p
  117. {
  118. lynx::drumranges::Range rangeOf (lynx::InstrumentKind kind, int index)
  119. {
  120. using K = lynx::InstrumentKind;
  121. namespace r = lynx::drumranges;
  122. switch (kind)
  123. {
  124. case K::fruitkick: return r::fruitKick (index);
  125. case K::plucked: return r::plucked (index);
  126. case K::drumpad: return r::drumpad (index);
  127. case K::drumaxx: return r::drumaxx (index);
  128. case K::bassdrum: return r::bassDrum (index);
  129. case K::drumsynth: return r::drumSynth (index);
  130. case K::sakura: return r::sakura (index);
  131. default: return r::none;
  132. }
  133. }
  134. } // namespace design168p
  135. TEST (design168p_automation_tables_match_the_engines)
  136. {
  137. using namespace lynx;
  138. for (const auto kind : design168p::kinds)
  139. {
  140. const auto* table = modelparams::tableOf (kind);
  141. CHECK (table != nullptr && table->params != nullptr && ! table->params->empty());
  142. if (table == nullptr || table->params == nullptr)
  143. continue;
  144. const auto& params = *table->params;
  145. std::set<std::string> names;
  146. for (std::size_t i = 0; i < params.size(); ++i)
  147. {
  148. const auto& p = params[i];
  149. CHECK (i == 0 || params[i - 1].index < p.index); // sorted, unique
  150. CHECK (names.insert (p.name).second);
  151. CHECK (modelparams::find (kind, p.index) == &p);
  152. if (kind == InstrumentKind::slayer)
  153. continue; // (Slayer's ranges live in its engine: slayerParamMax)
  154. // the engine maps automation over the same range as the knob
  155. const auto r = design168p::rangeOf (kind, p.index);
  156. CHECK (r.valid && r.low == p.low && r.high == p.high && r.integer == p.stepped);
  157. if (! (r.valid && r.low == p.low && r.high == p.high && r.integer == p.stepped))
  158. std::printf (" %s: range differs\n", p.name.c_str());
  159. }
  160. }
  161. CHECK (modelparams::tableOf (InstrumentKind::drumaxx)->params->size() == 16 * 42 + 13);
  162. CHECK (modelparams::findByName (InstrumentKind::drumaxx, "Pad 3 Pitch")->index == 2 * 44 + 5 + 29);
  163. CHECK (modelparams::findByName (InstrumentKind::drumsynth, "C5 Level")->index == drumSynthPatchParams * drumSynthKeyToSlot (60));
  164. CHECK (modelparams::tableOf (InstrumentKind::drumsynth)->params->size() == (std::size_t) (120 * 36));
  165. // values through the shared API: 0…1 over the range
  166. auto kick = *bankstates::channelFor ("fruitkick", { 100, -500, 70, 130, 20, 5 });
  167. CHECK (modelparams::setValue01 (kick, 5, 0.5f) && fruitKickParam (kick.pluginState, 5) == 64);
  168. CHECK (std::abs (*modelparams::value01 (kick, 0) - 2500.0f / 6000.0f) < 1e-6f);
  169. }
  170. TEST (design168p_engines_take_automation_while_playing)
  171. {
  172. using namespace lynx;
  173. // a Fruit Kick hit keeps sounding when its knobs move (live parameter, no engine restart)
  174. auto def = *bankstates::channelFor ("fruitkick", { 600, -300, 90, 140, 16, 0 });
  175. auto inst = makeInstrument (InstrumentKind::fruitkick);
  176. inst->prepare (48000.0);
  177. inst->configure (def, 120.0);
  178. std::vector<float> l (4800), r (4800);
  179. inst->render (l.data(), r.data(), 480, 1.0f, 1.0f);
  180. inst->noteOn (60, 0.8f);
  181. inst->render (l.data(), r.data(), 2400, 1.0f, 1.0f);
  182. auto edited = def;
  183. CHECK (drumcontrols::setRawValue (edited, 5, 100.0f));
  184. inst->configure (edited, 120.0);
  185. inst->setParameter (3, 0.9f);
  186. std::fill (l.begin(), l.end(), 0.0f);
  187. inst->render (l.data(), r.data(), 2400, 1.0f, 1.0f);
  188. float peak = 0.0f;
  189. for (int i = 0; i < 2400; ++i)
  190. peak = std::max (peak, std::abs (l[(std::size_t) i]));
  191. CHECK (peak > 0.01f); // (a restart would have dropped the hit)
  192. // every engine accepts every parameter of its table without trouble
  193. for (const auto kind : design168p::kinds)
  194. {
  195. auto e = makeInstrument (kind);
  196. e->prepare (48000.0);
  197. for (const auto& p : *modelparams::tableOf (kind)->params)
  198. e->setParameter (p.index, 0.5f);
  199. e->setParameter (-1, 0.5f);
  200. e->setParameter (100000, 0.5f);
  201. }
  202. }
  203. TEST (design168p_banks_play_clean)
  204. {
  205. using namespace lynx;
  206. // LYNX's own banks of the drum / physical-model engines: every preset loads, keeps the channel's own settings and
  207. // sounds (not silent, no clipping) at the channel's default volume
  208. for (const auto kind : { InstrumentKind::fruitkick, InstrumentKind::plucked, InstrumentKind::drumpad, InstrumentKind::sakura,
  209. InstrumentKind::drumaxx, InstrumentKind::drumsynth })
  210. {
  211. const auto& bank = banks::bankOf (kind);
  212. CHECK (bank.size() >= 2);
  213. CHECK (! bank.empty() && (bank.front().name == "Init" || kind == InstrumentKind::drumaxx || kind == InstrumentKind::drumsynth));
  214. std::set<std::string> names;
  215. for (int i = 0; i < (int) bank.size(); ++i)
  216. {
  217. CHECK (names.insert (bank[(std::size_t) i].name).second);
  218. ChannelDef c;
  219. c.instrument = kind;
  220. c.name = "Mine";
  221. c.samplePath = "keep";
  222. const auto loaded = banks::withPreset (c, i);
  223. CHECK (loaded && loaded->instrument == kind && loaded->samplePath == "keep");
  224. if (! loaded)
  225. continue;
  226. auto def = *loaded;
  227. def.samplePath.clear();
  228. CHECK (modelparams::rawValue (def, modelparams::tableOf (kind)->params->front().index).has_value()); // the page has knobs
  229. auto inst = makeInstrument (kind);
  230. inst->prepare (48000.0);
  231. inst->configure (def, 120.0);
  232. const auto gain = channelGain (def.volume);
  233. std::vector<float> l (48000 * 2), r (48000 * 2);
  234. const int keys[] = { 36, 38, 42, 60 };
  235. float peak = 0.0f;
  236. double sum = 0.0;
  237. for (int block = 0; block < (int) l.size() / 512; ++block)
  238. {
  239. if (block % 24 == 0 && block / 24 < 4)
  240. inst->noteOn (kind == InstrumentKind::drumsynth ? 48 + 2 * (block / 24) : keys[block / 24], 0.8f);
  241. if (block % 24 == 12 && block / 24 < 4)
  242. inst->noteOff (kind == InstrumentKind::drumsynth ? 48 + 2 * (block / 24) : keys[block / 24]);
  243. inst->render (l.data() + 512 * block, r.data() + 512 * block, 512, gain, gain);
  244. }
  245. for (std::size_t s = 0; s < l.size(); ++s)
  246. {
  247. peak = std::max ({ peak, std::abs (l[s]), std::abs (r[s]) });
  248. sum += (double) l[s] * l[s];
  249. }
  250. const auto clean = std::isfinite (peak) && peak < 0.95f && sum / (double) l.size() > 1.0e-7;
  251. CHECK (clean);
  252. if (! clean)
  253. std::printf (" %d / %s: peak %.3f ms %.3g\n", (int) kind, bank[(std::size_t) i].name.c_str(), peak, sum / (double) l.size());
  254. }
  255. }
  256. }