4
0

CtlWake.h 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. #pragma once
  2. // Round 173d2 (issue #77, the generators): a control of an FL-native generator that moved nothing in the round-170i3
  3. // pass (tools/CtlAudit.h: the chord pattern, the far end of the control, 6 random contexts) is searched for the
  4. // context that wakes it, the way tools/FxAudit.h does for the effects. A context is a key:
  5. // pat:mono one note, then a second one while it is held (legato / glide / retrigger of a mono patch)
  6. // pat:bend the pitch wheel and the channel's PITCH knob (FL's pitch bend of a generator) up 2 semitones
  7. // pat:mod the mod wheel (CC 1) at full
  8. // pat:vel:x the notes at velocity x
  9. // pat:rel a note-off velocity of 0.1
  10. // pat:long the notes held 3.5 s (slow LFOs, sequencers, long envelopes)
  11. // pat:retrig the same chord hit again while it sounds
  12. // pat:pads every key 36…51 (all 16 pads of a drum engine)
  13. // pat:low / pat:high the chord two octaves down / up (key tracking, ranges)
  14. // pat:bpm a tempo of 97 BPM (tempo-synced times equal free ones at 120)
  15. // pat:offline rendered as an export (the render-quality settings)
  16. // pat:gap a note, a gap, then another note (retriggered LFOs)
  17. // pat:overlap a second note over the first, then the first let go (mono note priority)
  18. // pat:one key 60 alone (a key that picks a program)
  19. // pat:allkeys every key 0…127 (a drum engine's pads wherever they sit)
  20. // pat:vlong the notes held 13 s (every step of a 64-step sequencer)
  21. // set:i:v control i of the editor list (CtlAudit::editorControls) at raw value v
  22. // hint:id a hand-written group of settings per engine (hintsFor; id = hintId of its note)
  23. // rand:k a random setting of every other control (seed 1730 + k; levels and mutes keep their values)
  24. // Keys combine with '+' ("pat:mod+set:3:1"). A control moves when its far end (or either end) changes the new
  25. // instrument's render by more than −60 dB relative RMS against the same context (the effects' rule, round 173d).
  26. #include <chrono>
  27. #include <cstdlib>
  28. #include <map>
  29. #include <sstream>
  30. #include "CtlAudit.h"
  31. #include "core/FmSynth.h"
  32. #include "core/WavetableSynth.h"
  33. #include "core/Braid.h"
  34. #include "core/Morphine.h"
  35. #include "core/TransistorBass.h"
  36. namespace lynx::ctlwake
  37. {
  38. using ctlaudit::Control;
  39. using ctlaudit::Pattern;
  40. using ctlaudit::Samples;
  41. constexpr double wakeDb = -60.0;
  42. struct Hint
  43. {
  44. std::string note;
  45. std::vector<std::pair<int, float>> sets; // (parameter index as Control::index, raw value)
  46. std::string pattern; // "" or a pat: key it goes with
  47. std::function<void (ChannelDef&)> apply; // a state edit the editor list can't make (a part switched on)
  48. std::string scope; // "" or the name prefix of the controls the search tries it on (a pad's)
  49. };
  50. // a hint's key: "hint:" + a hash of its note, so a survey's keys stay valid when hints are added or reordered
  51. inline std::string hintId (const std::string& note)
  52. {
  53. std::uint32_t h = 2166136261u; // FNV-1a
  54. for (const auto ch : note)
  55. h = (h ^ (std::uint8_t) ch) * 16777619u;
  56. char buf[12];
  57. std::snprintf (buf, sizeof buf, "%08x", h);
  58. return buf;
  59. }
  60. // the hint a key's token names: its id, or (older surveys) its index
  61. inline int findHint (const std::vector<Hint>& hints, const std::string& token)
  62. {
  63. for (int i = 0; i < (int) hints.size(); ++i)
  64. if (hintId (hints[(std::size_t) i].note) == token)
  65. return i;
  66. if (! token.empty() && token.size() < 6 && std::all_of (token.begin(), token.end(), [] (char c) { return c >= '0' && c <= '9'; }))
  67. if (const auto i = std::atoi (token.c_str()); i < (int) hints.size())
  68. return i;
  69. return -1;
  70. }
  71. // the groups that wake a section, per engine (the controls are matched by name in the editor list)
  72. inline std::vector<Hint> hintsFor (InstrumentKind kind, const std::vector<Control>& controls)
  73. {
  74. std::vector<Hint> out;
  75. auto idx = [&controls] (const std::string& name) {
  76. for (const auto& k : controls)
  77. if (k.name == name)
  78. return k.index;
  79. return -1;
  80. };
  81. auto named = [&] (std::string note, std::vector<std::pair<std::string, float>> sets, std::string pat = {}) {
  82. Hint h { std::move (note), {}, std::move (pat) };
  83. for (const auto& [n, v] : sets)
  84. if (const auto i = idx (n); i >= 0)
  85. h.sets.push_back ({ i, v });
  86. if (! h.sets.empty() || ! h.pattern.empty() || h.apply)
  87. out.push_back (std::move (h));
  88. };
  89. switch (kind)
  90. {
  91. case InstrumentKind::harmor:
  92. {
  93. // part B on (its enable byte: misc + 0x44 after the part's 386 parameters and 0x30 order bytes)
  94. Hint h { "part B switched on", {}, {} };
  95. h.apply = [] (ChannelDef& d) {
  96. const auto at = harmorParamOffset (d.pluginState, 1, 0);
  97. if (at >= 0 && (std::size_t) at + 4 * 386 + 0x30 + 0x44 < d.pluginState.size())
  98. d.pluginState[(std::size_t) at + 4 * 386 + 0x30 + 0x44] = 1;
  99. };
  100. out.push_back (std::move (h));
  101. break;
  102. }
  103. case InstrumentKind::ogun:
  104. // the delay's tempo sync: P27·0.3125/tempo vs P27/384 are the same time at 120 BPM (Ogun.cpp designDelay)
  105. named ("the delay on at 97 BPM", { { "Delay on", 1.0f } }, "pat:bpm");
  106. break;
  107. case InstrumentKind::kepler:
  108. // the LFO only matters routed (DCO / VCF LFO up); retrig and phase only at a note hit while it runs
  109. named ("the LFO on the pitch, retriggered by a note after a gap", { { "DCO LFO", 1.0f }, { "LFO retrig", 1.0f }, { "LFO rate", 0.6f }, { "LFO phase", 0.5f }, { "LFO sync", 0.0f },
  110. { "LFO trig mode", 0.0f }, { "LFO delay", 0.0f } }, "pat:gap");
  111. break;
  112. case InstrumentKind::slayer:
  113. // FL Slayer's own wheel (parameter 28, sent as CC 1) bends the pitch in glissando mode
  114. named ("glissando on with Slayer's wheel up", { { "Glissando", 1.0f }, { "Pitchbend 2", 127.0f } });
  115. break;
  116. case InstrumentKind::sawer:
  117. // a modulation slot acts with a source LYNX feeds (velocity) and an audible destination (the cutoff)
  118. for (int k = 1; k <= 6; ++k)
  119. {
  120. const auto slot = "Mod " + std::to_string (k);
  121. std::vector<Control> three;
  122. for (const auto& c : controls)
  123. if (c.name == slot + " source" || c.name == slot + " amount" || c.name == slot + " destination")
  124. three.push_back (c);
  125. if (three.size() != 3)
  126. continue;
  127. Hint h { slot + ": velocity to the cutoff at full amount", {}, "pat:vel:0.2" };
  128. h.apply = [three, slot] (ChannelDef& d) {
  129. for (const auto& c : three)
  130. c.set (d, c.name == slot + " source" ? 1.0f : c.name == slot + " amount" ? 1.0f : 27.0f);
  131. };
  132. out.push_back (std::move (h));
  133. }
  134. break;
  135. case InstrumentKind::toxic:
  136. {
  137. // the two effect slots: each type with its slot on (ToxicFx.cpp: 0 delay, 1 chorus, 2 reverb, 3 flanger, 4 phaser,
  138. // 5 lo-fi); the delay's sync only differs from its free time away from 120 BPM
  139. for (int sl = 1; sl <= 2; ++sl)
  140. for (int t = 0; t < 6; ++t)
  141. {
  142. const auto n = "FX " + std::to_string (sl);
  143. named (n + " on as type " + std::to_string (t), { { n + " on", 1.0f }, { n + " type", (float) t } }, t == 0 ? "pat:long+pat:bpm" : "pat:long");
  144. out.back().scope = n + " ";
  145. }
  146. // the flanger's inverted feedback needs feedback; a delay's time is heard with its sync off
  147. for (int sl = 1; sl <= 2; ++sl)
  148. {
  149. const auto n = "FX " + std::to_string (sl);
  150. named (n + " a flanger with feedback", { { n + " on", 1.0f }, { n + " type", 3.0f }, { n + " flanger feedback", 1.0f }, { n + " flanger mix", 1.0f } }, "pat:long");
  151. named (n + " a free-running delay", { { n + " on", 1.0f }, { n + " type", 0.0f }, { n + " delay sync", 0.0f }, { n + " delay mix", 1.0f }, { n + " delay feedback", 0.5f } }, "pat:long");
  152. }
  153. // the SEQ page: FL's Default has every step a rest ("---"), so the sequencer plays silence until a step holds a
  154. // note; a step's own value is heard once another step sounds, the order switches once the steps differ
  155. for (int first = 1; first <= 2; ++first)
  156. {
  157. named ("the sequencer playing, step " + std::to_string (first) + " a note", { { "Seq play", 1.0f }, { "Seq step " + std::to_string (first), 26.0f / 50.0f } }, "pat:vlong");
  158. named ("the sequencer playing 64 steps, step " + std::to_string (first) + " a note", { { "Seq play", 1.0f }, { "Seq steps", 1.0f }, { "Seq step " + std::to_string (first), 26.0f / 50.0f } }, "pat:vlong");
  159. }
  160. {
  161. Hint h { "the sequencer playing 64 rising steps", {}, "pat:vlong" };
  162. h.apply = [controls] (ChannelDef& d) {
  163. for (const auto& k : controls)
  164. {
  165. if (k.name == "Seq play")
  166. k.set (d, 1.0f);
  167. for (int i = 1; i <= 64; ++i)
  168. if (k.name == "Seq step " + std::to_string (i))
  169. k.set (d, (float) (26 + (i * 5) % 24) / 50.0f);
  170. }
  171. };
  172. out.push_back (std::move (h));
  173. }
  174. // a modulation slot: LFO 1 on the cutoff (destination 1 + parameter 15) at +100. (A velocity source acts only
  175. // when its destination is next set: FUN_1800413f0 reads the slots in setParam, the LFOs every chunk)
  176. for (int k = 1; k <= 8; ++k)
  177. {
  178. const auto n = "Mod " + std::to_string (k);
  179. // (the source is set by apply, which a move of the source itself then overrides: its far end, CC 127,
  180. // is never sent, so it is heard against the LFO it replaces)
  181. Hint h { n + ": LFO 1 on the cutoff", {}, "pat:long" };
  182. h.apply = [controls, n] (ChannelDef& d) {
  183. for (const auto& c : controls)
  184. if (c.name == n + " source" || c.name == n + " destination" || c.name == n + " amount" || c.name == "Cutoff" || c.name == "LFO 1 speed")
  185. c.set (d, c.name == n + " source" ? 2.0f : c.name == n + " destination" ? 16.0f : c.name == n + " amount" ? 1.0f : c.name == "Cutoff" ? 0.3f : 0.5f);
  186. };
  187. h.scope = n + " ";
  188. out.push_back (std::move (h));
  189. }
  190. // an operator on its own: its start phase (free run off), its envelope's decay (no sustain)
  191. for (int o = 1; o <= 6; ++o)
  192. {
  193. const auto n = "Osc " + std::to_string (o);
  194. // (a start phase is heard against another operator at the same pitch, both restarting theirs)
  195. const auto m = "Osc " + std::to_string (o % 6 + 1);
  196. named (n + " sounding with " + m + ", both restarting their phase", { { n + " on", 1.0f }, { n + " mix", 1.0f }, { n + " free run", 0.0f },
  197. { m + " on", 1.0f }, { m + " mix", 1.0f }, { m + " free run", 0.0f }, { m + " coarse", 0.5f }, { n + " coarse", 0.5f }, { m + " fine", 0.5f }, { n + " fine", 0.5f } });
  198. named (n + " sounding, decaying to silence", { { n + " on", 1.0f }, { n + " mix", 1.0f }, { n + " attack", 0.0f }, { n + " sustain", 0.0f } }, "pat:long");
  199. out.back().scope = n + " "; // (the pair's hint stays open: it wakes the other operator's phase too)
  200. }
  201. named ("the filter envelope decaying onto a low cutoff", { { "Filter env amount", 1.0f }, { "Filter attack", 0.0f }, { "Filter sustain", 0.0f }, { "Cutoff", 0.2f } }, "pat:long");
  202. // (the LFOs restart while no voice sounds unless free: the release short enough for the gap to be silent)
  203. named ("LFO 1 on the cutoff, a note after a gap", { { "Filter LFO 1 amount", 1.0f }, { "LFO 1 speed", 0.5f }, { "Release", 0.0f } }, "pat:gap");
  204. named ("LFO 2 on the pitch, a note after a gap", { { "LFO 2 to pitch", 1.0f }, { "LFO 2 speed", 0.5f }, { "Release", 0.0f } }, "pat:gap");
  205. break;
  206. }
  207. case InstrumentKind::transistorbass:
  208. {
  209. // with the sequencer on, a note picks the program it plays (key = program, REA_rodada169g2; a chord: its last
  210. // key) and the page edits the state's program: play the edited one alone, its 16 steps gated and on rising notes so each field is heard
  211. auto byName = [controls] (ChannelDef& d, const std::string& name, float v) {
  212. for (const auto& k : controls)
  213. if (k.name == name)
  214. k.set (d, v);
  215. };
  216. auto ranged = [controls] (const std::string& name, float x) {
  217. for (const auto& k : controls)
  218. if (k.name == name)
  219. return k.low + x * (k.high - k.low);
  220. return 0.0f;
  221. };
  222. for (int variant = 0; variant < 3; ++variant)
  223. {
  224. Hint h { variant == 0 ? "the sequencer on, the note playing the edited program"
  225. : variant == 1 ? "the sequencer on, the edited program's 16 steps gated on rising notes"
  226. : "the sequencer on, every step gated and accented",
  227. {}, "pat:one+pat:long" };
  228. h.apply = [byName, ranged, variant] (ChannelDef& d) {
  229. transistorBassSelectProgram (d.pluginState, 60);
  230. byName (d, "Sequencer", 1.0f);
  231. if (variant == 0)
  232. return;
  233. for (int i = 1; i <= 16; ++i)
  234. {
  235. const auto n = "Step " + std::to_string (i);
  236. byName (d, n + " gate", 1.0f);
  237. if (variant == 1)
  238. byName (d, n + " note", ranged (n + " note", (float) (i % 12) / 11.0f * 0.09f));
  239. else
  240. byName (d, n + " accent", 1.0f);
  241. }
  242. };
  243. out.push_back (std::move (h));
  244. }
  245. named ("the delay on, the sequencer off", { { "Sequencer", 0.0f }, { "Delay on", 1.0f } }, "pat:long");
  246. break;
  247. }
  248. case InstrumentKind::drumaxx:
  249. {
  250. // a pad's layers up and every key hit (the Default Kit's pads 11…16 sit outside 36…51), then retriggered and
  251. // with each velocity modulation on a target
  252. for (int pad = 1; pad <= 16; ++pad)
  253. {
  254. const auto n = "Pad " + std::to_string (pad);
  255. const std::vector<std::pair<std::string, float>> up { { n + " volume", 1.0f }, { n + " mute", 0.0f }, { n + " SOF level", 1.0f },
  256. { n + " Mid level", 1.0f }, { n + " High level", 1.0f }, { n + " Mallet amp", 1.0f } };
  257. const auto first = out.size();
  258. named (n + "'s layers up", up, "pat:allkeys");
  259. named (n + "'s layers up, hit again", up, "pat:allkeys+pat:retrig");
  260. // the MID band's envelope (its decay, the "Mid attack" knob) only moves its level / frequency modulation,
  261. // the LOW band's resonance only acts with the band on (frequency above 0), and the mallet noise's seed
  262. // only at a hit with pad 1's Noise Retrig on (the engine reads pad 1's for every pad, REA_rodada67 §6.2)
  263. auto more = up;
  264. for (const auto& kv : std::vector<std::pair<std::string, float>> { { n + " Mid level mod", 1.0f }, { n + " Mid freq mod", 1.0f }, { n + " Low freq", 0.5f },
  265. { n + " Mallet noise", 1.0f }, { "Pad 1 Mallet retrig", 1.0f } })
  266. more.push_back (kv);
  267. named (n + "'s layers up, its MID modulated, LOW on, the noise reseeded", more, "pat:allkeys");
  268. for (int j = 1; j <= 4; ++j)
  269. {
  270. auto v = up;
  271. v.push_back ({ n + " Vel mod " + std::to_string (j) + " target", 28.0f });
  272. v.push_back ({ n + " Vel mod " + std::to_string (j) + " value", 1.0f });
  273. named (n + "'s velocity modulation " + std::to_string (j) + " on its pitch", v, "pat:allkeys+pat:vel:0.2");
  274. }
  275. for (auto i = first; i < out.size(); ++i)
  276. out[i].scope = n + " "; // (only this pad's controls)
  277. }
  278. named ("the master EQ on with bands raised", { { "EQ on", 1.0f }, { "EQ band 1", 1.0f }, { "EQ band 5", 1.0f } }, "pat:allkeys");
  279. named ("the master EQ on", { { "EQ on", 1.0f } }, "pat:allkeys");
  280. named ("the limiter on, hit hard", { { "Limiter on", 1.0f }, { "Master", 1.0f } }, "pat:allkeys+pat:vel:1");
  281. break;
  282. }
  283. case InstrumentKind::keplerExo:
  284. // Release mode: in mono, letting the first note go restarts the envelopes on the one still held (or not);
  285. // heard with the amplifier on envelope 1 and a slow attack
  286. named ("mono on envelope 1 with a slow attack, a second note over the first", { { "Mono", 1.0f }, { "VCA source", 0.0f }, { "Env1 attack", 0.5f } }, "pat:overlap");
  287. // Saturation post moves the saturation after the EQ, chorus, delay and reverb: heard with those on
  288. named ("the saturation on and driven", { { "Saturation on", 1.0f }, { "Saturation", 1.0f } });
  289. named ("the saturation on and driven, the reverb and chorus on", { { "Saturation on", 1.0f }, { "Saturation", 1.0f }, { "Reverb on", 1.0f }, { "Hyper chorus on", 1.0f } }, "pat:long");
  290. named ("the saturation on and driven, high notes", { { "Saturation on", 1.0f }, { "Saturation", 1.0f } }, "pat:high");
  291. named ("the amplifier on envelope 1, snapping", { { "VCA source", 0.0f }, { "Env1 attack", 0.0f }, { "Env1 release", 0.0f } }, "pat:gap");
  292. named ("the high-pass up", { { "High-pass", 1.0f } });
  293. break;
  294. case InstrumentKind::sytrus:
  295. // the modulation matrix (round 172a): FL's Default patch sends only operator 1 out; an operator's pan is heard
  296. // with it sent out, a filter's cells with an operator fed into it and the filter sent out
  297. for (int o = 3; o <= 6; ++o)
  298. named ("operator " + std::to_string (o) + " sent out", { { "Op " + std::to_string (o) + " out", 256.0f } });
  299. for (int f = 1; f <= 3; ++f)
  300. {
  301. const auto n = "filter " + std::to_string (f);
  302. named ("operator 1 through " + n + ", sent out", { { "FM op 1 to " + n, 256.0f }, { "Filter " + std::to_string (f) + " out", 256.0f } });
  303. named ("operator 2 through " + n + ", sent out", { { "FM op 2 to " + n, 256.0f }, { "Op 2 out", 256.0f }, { "Filter " + std::to_string (f) + " out", 256.0f } });
  304. named ("operator 1 through " + n + ", sent out and to the FX", { { "FM op 1 to " + n, 256.0f }, { "Filter " + std::to_string (f) + " out", 256.0f }, { "Filter " + std::to_string (f) + " FX", 256.0f } });
  305. }
  306. break;
  307. case InstrumentKind::poizone:
  308. // PoiZone's Bend range and MW amount / destination act through its own wheels (params 158 / 157, round 173d)
  309. named ("PoiZone's wheels up", { { "Mod wheel", 1.0f }, { "Pitch bend", 1.0f } });
  310. break;
  311. case InstrumentKind::granulizer:
  312. {
  313. // Tempo locked needs the sample's length in beats (an acid sample's beats or the channel's Time stretch
  314. // beats, Granulizer.cpp hostBeats); the measured sample has neither, so the lock has nothing to follow
  315. Hint h { "the sample's length set to 4 beats (Channel settings, Time)", {}, "pat:bpm" };
  316. h.apply = [] (ChannelDef& d) { d.sampler.stretchBeats = 4.0f; };
  317. out.push_back (std::move (h));
  318. break;
  319. }
  320. case InstrumentKind::morphine:
  321. {
  322. // a noise sample loaded (its name in the state and its file in the channel, as FL's Noise browser does):
  323. // the measured preset has none, so the noise section (mix, pan, mute, velocity) is silent without it
  324. Hint h { "a noise sample loaded (Ambient Hit 1.wav)", {}, {} };
  325. h.apply = [] (ChannelDef& d) {
  326. const auto a0 = morphineParamOffset (d.pluginState, 0); // (global A[0] = block byte 4, the name at 172)
  327. const std::string name = "Ambient Hit 1.wav";
  328. if (a0 < 0 || ctlaudit::flAccess == nullptr || (std::size_t) a0 - 4 + 172 + 1024 > d.pluginState.size())
  329. return;
  330. const auto at = a0 - 4 + 172;
  331. std::fill (d.pluginState.begin() + at, d.pluginState.begin() + at + 1024, (std::uint8_t) 0);
  332. std::copy (name.begin(), name.end(), d.pluginState.begin() + at);
  333. d.samplePath = ctlaudit::flAccess->roots.factoryData + "/Plugins/Fruity/Generators/Morphine/Noise Samples/" + name;
  334. };
  335. out.push_back (std::move (h));
  336. break;
  337. }
  338. case InstrumentKind::pocketSuperSaw:
  339. // (round 190cm) FLM's defaults leave most sections off: one oscillator (no stack to detune or spread), no
  340. // pulse, no SuperSync, the filter wide open with its envelope at 0, sustains at full, no slide time, the
  341. // LFO, arpeggiator, delay and mod wheel at 0 (PocketSuperSaw.cpp, docs/analise/REA_rodada190by.md §2…3)
  342. named ("pulse mode on", { { "Osc pulse mode", 1.0f } });
  343. named ("a stack of 12 oscillators", { { "Osc unison", 1.0f } });
  344. named ("a stack of 12 oscillators restarting their phases", { { "Osc unison", 1.0f }, { "Osc re-trig phases", 1.0f } });
  345. named ("SuperSync on, its envelope at full amount decaying into a release",
  346. { { "SuperSync mode", 1.0f }, { "Osc sync", 0.2f }, { "Osc sync EG amount", 1.0f }, { "Osc sync decay", 0.4f }, { "Osc sync sustain", 0.3f }, { "Level EG release", 0.6f } });
  347. named ("the filter closed to 30 %, its envelope at full amount decaying into a release",
  348. { { "Filter cutoff", 0.3f }, { "Filter EG amount", 1.0f }, { "Filter EG decay", 0.4f }, { "Filter EG sustain", 0.2f }, { "Level EG release", 0.6f } });
  349. named ("the level envelope's sustain at 30 %", { { "Level EG sustain", 0.3f } });
  350. // (Slide held mode: heard on a note played after the last one was let go, pat:gap; Static: on any glide)
  351. named ("a slide time of 160 ms", { { "Slide time", 0.8f } });
  352. named ("the LFO at full amount and 4 Hz, the filter half closed", { { "LFO amount", 1.0f }, { "LFO rate", 0.8f }, { "Filter cutoff", 0.5f } });
  353. named ("the LFO at full amount and tempo-synced, the filter half closed", { { "LFO amount", 1.0f }, { "LFO mode", 1.0f }, { "Filter cutoff", 0.5f } });
  354. // (Arp range: heard on one key alone, pat:one, whose second step is the octave above)
  355. named ("the arpeggiator going up", { { "Arp mode", 0.3f } });
  356. named ("the delay mixed in", { { "Delay mix", 0.7f } });
  357. named ("the mod wheel at full on a negative amount", { { "Mod wheel amount", 0.25f } }, "pat:mod");
  358. break;
  359. case InstrumentKind::tetra:
  360. {
  361. // (round 190ix) Tetra's new channel plays operator A alone (B…D off, at the −70 dB floor), with the LFO, the pitch
  362. // envelope and the filter off and every envelope a click attack onto a full sustain (core/FmSynth.cpp defaults):
  363. // a section's controls are heard with it on. Operator's laws keep some of them context-bound: an operator's
  364. // feedback acts only where nothing modulates it, a fixed frequency only with Fixed on, a loop time / repeat
  365. // only in its loop mode, a band-pass circuit only on a band / notch / morph filter.
  366. const char* const ops[] { "A", "B", "C", "D" };
  367. const char* const envs[] { "A Env", "B Env", "C Env", "D Env", "LFO Env", "Pitch Env", "Filter Env" };
  368. std::vector<std::pair<std::string, float>> on;
  369. for (const auto* o : ops)
  370. {
  371. on.push_back ({ std::string (o) + " On", 1.0f });
  372. on.push_back ({ std::string (o) + " Level", 0.5f });
  373. }
  374. auto with = [&on] (std::vector<std::pair<std::string, float>> more) {
  375. auto v = on;
  376. v.insert (v.end(), more.begin(), more.end());
  377. return v;
  378. };
  379. // every envelope slow and shaped (levels from a start to a sustain and on to an end), in a loop mode
  380. auto shaped = [&] (float loopMode) {
  381. std::vector<std::pair<std::string, float>> v;
  382. for (const auto* e : envs)
  383. {
  384. const std::string n = e;
  385. const bool pitch = n == "Pitch Env";
  386. for (const auto& [what, x] : std::vector<std::pair<const char*, float>> {
  387. { " Attack", 150.0f }, { " Initial", pitch ? 12.0f : 0.5f }, { " Decay", 150.0f }, { " Peak", pitch ? -12.0f : 1.0f },
  388. { " Sustain", pitch ? 7.0f : 0.3f }, { " Release", 150.0f }, { " End", pitch ? -7.0f : 0.2f }, { " Loop Mode", loopMode } })
  389. v.push_back ({ n + what, x });
  390. }
  391. for (const auto* o : ops)
  392. {
  393. v.push_back ({ std::string (o) + " Pitch Env On", 1.0f });
  394. v.push_back ({ std::string (o) + " LFO On", 1.0f });
  395. }
  396. for (const auto& kv : std::vector<std::pair<std::string, float>> { { "Pitch Env On", 1.0f }, { "LFO On", 1.0f }, { "LFO Amount", 0.5f },
  397. { "Filter On", 1.0f }, { "Filter Freq", 800.0f }, { "Filter Env Amount", 36.0f },
  398. { "LFO Filter On", 1.0f } })
  399. v.push_back (kv);
  400. return with (v);
  401. };
  402. named ("every operator on at half level, in a chain", on);
  403. named ("every operator on at half level and heard (algorithm 11)", with ({ { "Algorithm", 10.0f } }));
  404. named ("every operator on at half level, at a fixed frequency", with ({ { "A Fixed", 1.0f }, { "B Fixed", 1.0f }, { "C Fixed", 1.0f }, { "D Fixed", 1.0f } }));
  405. named ("every operator on, the chord hit again", with ({ { "A Phase", 25.0f }, { "B Phase", 25.0f }, { "C Phase", 25.0f }, { "D Phase", 25.0f } }), "pat:retrig");
  406. named ("every operator on, the LFO at full on each", with ({ { "LFO On", 1.0f }, { "LFO Amount", 1.0f }, { "A LFO On", 1.0f }, { "B LFO On", 1.0f }, { "C LFO On", 1.0f }, { "D LFO On", 1.0f } }));
  407. named ("every operator on, the LFO at full on each, tempo-synced", with ({ { "LFO On", 1.0f }, { "LFO Amount", 1.0f }, { "LFO Range", 2.0f } }));
  408. named ("every operator on, the LFO at full on each, a note after a gap", with ({ { "LFO On", 1.0f }, { "LFO Amount", 1.0f }, { "LFO Rate", 40.0f } }), "pat:gap");
  409. named ("the LFO at full on the filter", { { "LFO On", 1.0f }, { "LFO Amount", 1.0f }, { "LFO Filter On", 1.0f }, { "Filter On", 1.0f }, { "Filter Freq", 1000.0f } });
  410. named ("every operator on, the pitch envelope on each from an octave up",
  411. with ({ { "Pitch Env On", 1.0f }, { "Pitch Env Initial", 12.0f }, { "Pitch Env Attack", 150.0f }, { "A Pitch Env On", 1.0f }, { "B Pitch Env On", 1.0f },
  412. { "C Pitch Env On", 1.0f }, { "D Pitch Env On", 1.0f } }));
  413. named ("every section on, every envelope slow and shaped", shaped (0.0f));
  414. named ("every section on, every envelope slow and shaped, looping", shaped (1.0f), "pat:long");
  415. named ("every section on, every envelope slow and shaped, in Beat mode", shaped (2.0f), "pat:long");
  416. named ("the filter on as a band pass", { { "Filter On", 1.0f }, { "Filter Type", 2.0f }, { "Filter Freq", 1000.0f }, { "Filter Res", 0.8f } });
  417. named ("the filter on as a morph filter", { { "Filter On", 1.0f }, { "Filter Type", 4.0f }, { "Filter Freq", 1000.0f }, { "Filter Res", 0.8f } });
  418. named ("the filter on at 1 kHz, its envelope at full", { { "Filter On", 1.0f }, { "Filter Freq", 1000.0f }, { "Filter Env Amount", 72.0f }, { "Filter Env Attack", 150.0f } });
  419. named ("the filter on at 1 kHz, its morph at the high pass", { { "Filter On", 1.0f }, { "Filter Freq", 1000.0f }, { "Filter Morph", 0.5f } });
  420. named ("the filter on at 1 kHz, a driven circuit", { { "Filter On", 1.0f }, { "Filter Freq", 1000.0f }, { "Filter Circuit", 1.0f }, { "Filter Res", 0.5f } });
  421. named ("the filter on at 1 kHz with the shaper", { { "Filter On", 1.0f }, { "Filter Freq", 1000.0f }, { "Shaper", 1.0f }, { "Shaper Drive", 12.0f } });
  422. named ("glide on, a legato second note", { { "Glide", 1.0f } }, "pat:mono");
  423. {
  424. // the user wave (no editor knob: the wave editor's 64 partials) as a saw, heard where an operator picks it
  425. named ("every operator on, its user wave a saw", on);
  426. out.back().apply = [] (ChannelDef& d) {
  427. if ((int) d.modelParams.size() < fm::stateSize)
  428. {
  429. const auto def = tetraDefaults();
  430. const auto have = d.modelParams.size();
  431. d.modelParams.resize ((std::size_t) fm::stateSize);
  432. std::copy (def.begin() + (std::ptrdiff_t) have, def.end(), d.modelParams.begin() + (std::ptrdiff_t) have);
  433. }
  434. for (int k = 0; k < fm::opCount; ++k)
  435. for (int i = 0; i < fm::harmonics; ++i)
  436. d.modelParams[(std::size_t) (fm::harmonicsBase + k * fm::harmonics + i)] = 1.0f / (float) (i + 1);
  437. };
  438. }
  439. break;
  440. }
  441. case InstrumentKind::helix:
  442. {
  443. // (rollup 0.1.30, round 190jk) Helix's new channel is Live's default Wavetable (core/WavetableSynth.cpp
  444. // defaults): oscillator 1 alone through filter 1 wide open, the sub and filter 2 off, an empty matrix apart from
  445. // the MIDI rows, so envelopes 2 / 3 and the LFOs move nothing until a matrix cell routes them; the effects'
  446. // modes are heard with their amounts up, a band-pass circuit on a band pass, Morph on the morph type, Drive on
  447. // a driven circuit, Unison's voices / amount with a unison mode, Glide on a Mono voice's legato note
  448. const auto routed = [] (std::vector<std::pair<int, float>> cells) {
  449. return [cells] (ChannelDef& d) {
  450. if ((int) d.modelParams.size() < wt::stateSize)
  451. {
  452. const auto def = helixDefaults();
  453. const auto have = d.modelParams.size();
  454. d.modelParams.resize ((std::size_t) wt::stateSize);
  455. std::copy (def.begin() + (std::ptrdiff_t) have, def.end(), d.modelParams.begin() + (std::ptrdiff_t) have);
  456. }
  457. for (const auto& [cell, v] : cells)
  458. d.modelParams[(std::size_t) cell] = v;
  459. };
  460. };
  461. using namespace wt;
  462. named ("oscillator 2 on, a fifth up", { { "Osc 2 On", 1.0f }, { "Osc 2 Transpose", 7.0f }, { "Osc 2 Gain", 0.7f } });
  463. named ("both oscillators' effects at half, oscillator 2 on", { { "Osc 1 Effect 1", 0.5f }, { "Osc 1 Effect 2", 0.5f }, { "Osc 2 On", 1.0f },
  464. { "Osc 2 Effect Mode", 3.0f }, { "Osc 2 Effect 1", 0.5f }, { "Osc 2 Effect 2", 0.5f } });
  465. named ("the sub on", { { "Sub On", 1.0f }, { "Sub Gain", 0.8f }, { "Sub Tone", 0.5f } });
  466. for (int k = 1; k <= 2; ++k)
  467. {
  468. const auto f = "Filter " + std::to_string (k);
  469. std::vector<std::pair<std::string, float>> at1k { { f + " On", 1.0f }, { f + " Freq", 1000.0f }, { f + " Res", 0.8f } };
  470. auto plus = [&at1k] (std::vector<std::pair<std::string, float>> more) {
  471. auto v = at1k;
  472. v.insert (v.end(), more.begin(), more.end());
  473. return v;
  474. };
  475. named ("filter " + std::to_string (k) + " on at 1 kHz, resonant", at1k);
  476. named ("filter " + std::to_string (k) + " on at 1 kHz as a morph filter", plus ({ { f + " Type", 4.0f } }));
  477. named ("filter " + std::to_string (k) + " on at 1 kHz as a band pass", plus ({ { f + " Type", 2.0f } }));
  478. named ("filter " + std::to_string (k) + " on at 1 kHz, a driven circuit", plus ({ { f + " Circuit", 1.0f }, { f + " Drive", 12.0f } }));
  479. }
  480. named ("both filters on at 1 kHz, filter 2 a high pass", { { "Filter 1 Freq", 1000.0f }, { "Filter 1 Res", 0.8f }, { "Filter 2 On", 1.0f },
  481. { "Filter 2 Type", 1.0f }, { "Filter 2 Freq", 1000.0f }, { "Filter 2 Res", 0.8f } });
  482. // envelopes 2 and 3 slow and shaped, routed to oscillator 1's pitch and filter 1 (at 1 kHz); looping on held notes
  483. for (int k = 2; k <= 3; ++k)
  484. {
  485. const auto e = "Env " + std::to_string (k);
  486. const auto source = k == 2 ? src::env2 : src::env3;
  487. const std::vector<std::pair<std::string, float>> shaped { { e + " Attack", 0.15f }, { e + " Decay", 0.15f }, { e + " Release", 0.2f },
  488. { e + " Sustain", 0.3f }, { e + " Initial", 0.2f }, { e + " Final", 0.5f },
  489. { "Filter 1 Freq", 1000.0f }, { "Filter 1 Res", 0.5f } };
  490. const auto cells = routed ({ { matrixIndex (tgt::oscPitch, source), 0.3f }, { matrixIndex (tgt::filterFreq, source), 0.5f } });
  491. named (e + " slow and shaped, on oscillator 1's pitch and filter 1", shaped);
  492. out.back().apply = cells;
  493. auto looping = shaped;
  494. looping.push_back ({ e + " Loop Mode", 2.0f });
  495. named (e + " slow and shaped, on oscillator 1's pitch and filter 1, looping", looping, "pat:long");
  496. out.back().apply = cells;
  497. }
  498. // the LFOs on oscillator 1's pitch and filter 1: free at 4 Hz, tempo-synced, after a gap
  499. for (int k = 1; k <= 2; ++k)
  500. {
  501. const auto l = "LFO " + std::to_string (k);
  502. const auto source = k == 1 ? src::lfo1 : src::lfo2;
  503. const auto cells = routed ({ { matrixIndex (tgt::oscPitch, source), 0.3f }, { matrixIndex (tgt::filterFreq, source), 0.5f } });
  504. const std::vector<std::pair<std::string, float>> at4 { { l + " Rate", 4.0f }, { l + " Attack", 0.0f }, { "Filter 1 Freq", 1000.0f } };
  505. named (l + " at 4 Hz on oscillator 1's pitch and filter 1", at4);
  506. out.back().apply = cells;
  507. named (l + " tempo-synced on oscillator 1's pitch and filter 1", { { l + " Sync", 1.0f }, { "Filter 1 Freq", 1000.0f } });
  508. out.back().apply = cells;
  509. named (l + " at 4 Hz on oscillator 1's pitch, a note after a gap", at4, "pat:gap");
  510. out.back().apply = cells;
  511. named (l + " at 4 Hz on oscillator 1's pitch, its attack slow", { { l + " Rate", 4.0f }, { l + " Attack", 0.3f } });
  512. out.back().apply = cells;
  513. }
  514. named ("unison on (Classic)", { { "Unison Mode", 1.0f }, { "Unison Amount", 0.5f } });
  515. named ("mono, a legato second note", { { "Poly", 0.0f }, { "Glide", 0.3f } }, "pat:mono");
  516. named ("the amp envelope shaped, held long", { { "Amp Decay", 0.15f }, { "Amp Sustain", 0.3f }, { "Amp Loop Mode", 2.0f } }, "pat:long");
  517. // (round 190mi) Helix+: a second warp needs its amount (and a mode), noise its switch, Unison+ a unison mode,
  518. // the macros and drawn LFOs a matrix cell, the effects' knobs their effect on
  519. named ("Helix+: both second warps Bend + at half, oscillator 2 on", { { "Osc 1 Warp 2", (float) warp::bendPlus }, { "Osc 1 Warp 2 Amount", 0.5f },
  520. { "Osc 2 On", 1.0f }, { "Osc 2 Gain", 0.7f },
  521. { "Osc 2 Warp 2", (float) warp::bendPlus }, { "Osc 2 Warp 2 Amount", 0.5f } });
  522. named ("Helix+: noise on, darker", { { "Noise On", 1.0f }, { "Noise Level", 0.5f }, { "Noise Color", 0.3f } });
  523. named ("Helix+: unison Classic, 6 voices", { { "Unison Mode", 1.0f }, { "Unison Amount", 0.5f }, { "Unison Voices", 6.0f } });
  524. named ("Helix+: filter 2 on at 1 kHz, resonant", { { "Filter 2 On", 1.0f }, { "Filter 2 Freq", 1000.0f }, { "Filter 2 Res", 0.8f } });
  525. named ("Helix+: the four macros on oscillator 1's pitch", { { "Filter 1 Freq", 1000.0f } });
  526. out.back().apply = routed ({ { cellIndex (tgt::oscPitch, src::macro1), 0.2f }, { cellIndex (tgt::oscPitch, src::macro1 + 1), 0.3f },
  527. { cellIndex (tgt::oscPitch, src::macro1 + 2), 0.4f }, { cellIndex (tgt::oscPitch, src::macro1 + 3), 0.5f } });
  528. for (int k = 1; k <= 2; ++k)
  529. {
  530. const auto l = "LFO " + std::to_string (k);
  531. named ("Helix+: " + l + " at 4 Hz on oscillator 1's pitch", { { l + " Rate", 4.0f }, { l + " Attack", 0.0f } });
  532. out.back().apply = routed ({ { matrixIndex (tgt::oscPitch, k == 1 ? src::lfo1 : src::lfo2), 0.3f } });
  533. }
  534. named ("Helix+: distortion on", { { "Distortion On", 1.0f }, { "Distortion Drive", 0.5f }, { "Distortion Mix", 0.7f } });
  535. named ("Helix+: chorus on", { { "Chorus On", 1.0f } });
  536. named ("Helix+: delay on", { { "Delay On", 1.0f }, { "Delay Time", 3.0f }, { "Delay Mix", 0.5f } });
  537. named ("Helix+: reverb on", { { "Reverb On", 1.0f } });
  538. // (round 190ml) Helix+ 2: oscillator 3 and the sample need switching on (the sample a sample in the channel's
  539. // data), their effects / second warps an amount and a mode, macros 5…8 and the chaos sources a matrix cell, the
  540. // shifter / EQ / multiband their switch (the EQ its bands away from 0 dB)
  541. named ("Helix+ 2: oscillator 3 on, a fifth up", { { "Osc 3 On", 1.0f }, { "Osc 3 Gain", 0.7f }, { "Osc 3 Transpose", 7.0f } });
  542. named ("Helix+ 2: oscillator 3's effect at half", { { "Osc 3 On", 1.0f }, { "Osc 3 Gain", 0.7f }, { "Osc 3 Effect Mode", 3.0f },
  543. { "Osc 3 Effect 1", 0.5f }, { "Osc 3 Effect 2", 0.5f } });
  544. named ("Helix+ 2: oscillator 3's second warp Bend + at half", { { "Osc 3 On", 1.0f }, { "Osc 3 Gain", 0.7f },
  545. { "Osc 3 Warp 2", (float) warp::bendPlus }, { "Osc 3 Warp 2 Amount", 0.5f } });
  546. const auto withSample = [] (ChannelDef& d) {
  547. if ((int) d.modelParams.size() < wt::stateSize)
  548. {
  549. const auto def = helixDefaults();
  550. const auto have = d.modelParams.size();
  551. d.modelParams.resize ((std::size_t) wt::stateSize);
  552. std::copy (def.begin() + (std::ptrdiff_t) have, def.end(), d.modelParams.begin() + (std::ptrdiff_t) have);
  553. }
  554. wt::HelixUserData data; // (a 0.3 s tone with a falling pitch: Start, Loop and the pitch all heard)
  555. data.sample.rate = 44100.0;
  556. data.sample.l.resize (13230);
  557. double ph = 0.0;
  558. for (std::size_t i = 0; i < data.sample.l.size(); ++i)
  559. {
  560. ph += (330.0 - 200.0 * (double) i / 13230.0) / 44100.0;
  561. data.sample.l[i] = (float) (0.7 * std::sin (2.0 * 3.14159265358979 * ph));
  562. }
  563. d.pluginState = wt::encodeUserData (data);
  564. };
  565. named ("Helix+ 2: the sample on (a falling tone)", { { "Sample On", 1.0f } });
  566. out.back().apply = withSample;
  567. named ("Helix+ 2: the sample's second warp Sync at half", { { "Sample On", 1.0f }, { "Sample Warp 2", (float) warp::sync },
  568. { "Sample Warp 2 Amount", 0.5f } });
  569. out.back().apply = withSample;
  570. named ("Helix+ 2: macros 5 to 8 on oscillator 1's pitch", { { "Filter 1 Freq", 1000.0f } });
  571. out.back().apply = routed ({ { cellIndex (tgt::oscPitch, src::macro1 + 4), 0.2f }, { cellIndex (tgt::oscPitch, src::macro1 + 5), 0.3f },
  572. { cellIndex (tgt::oscPitch, src::macro1 + 6), 0.4f }, { cellIndex (tgt::oscPitch, src::macro1 + 7), 0.5f } });
  573. for (int k = 1; k <= chaosCount; ++k)
  574. {
  575. const auto c = "Chaos " + std::to_string (k);
  576. named ("Helix+ 2: " + c + " at 4 Hz on oscillator 1's pitch", { { c + " Rate", 4.0f }, { c + " Amount", 1.0f } });
  577. out.back().apply = routed ({ { cellIndex (tgt::oscPitch, src::chaos1 + k - 1), 0.3f } });
  578. }
  579. named ("Helix+ 2: the shifter on", { { "Shift On", 1.0f }, { "Shift", 0.3f }, { "Shift Mix", 1.0f } });
  580. named ("Helix+ 2: the EQ on, its bands moved", { { "EQ On", 1.0f }, { "EQ Low", 6.0f }, { "EQ Mid", -6.0f }, { "EQ High", 6.0f } });
  581. named ("Helix+ 2: the multiband on", { { "Multiband On", 1.0f } });
  582. // (round 190mt) Helix round 3: the granular and spectral oscillators need switching on and a sample in the
  583. // channel's data (the spectral one a rich one, its band narrowed and few partials, so Band, Width and Partials
  584. // are heard); Clean a rich sample played an octave up
  585. const auto withRich = [] (ChannelDef& d) {
  586. if ((int) d.modelParams.size() < wt::stateSize)
  587. {
  588. const auto def = helixDefaults();
  589. const auto have = d.modelParams.size();
  590. d.modelParams.resize ((std::size_t) wt::stateSize);
  591. std::copy (def.begin() + (std::ptrdiff_t) have, def.end(), d.modelParams.begin() + (std::ptrdiff_t) have);
  592. }
  593. wt::HelixUserData data; // (0.4 s of a falling tone with 30 harmonics)
  594. data.sample.rate = 44100.0;
  595. data.sample.l.resize (17640);
  596. double ph = 0.0;
  597. for (std::size_t i = 0; i < data.sample.l.size(); ++i)
  598. {
  599. ph += (330.0 - 150.0 * (double) i / 17640.0) / 44100.0;
  600. double y = 0.0;
  601. for (int h = 1; h <= 30; ++h)
  602. y += std::sin (2.0 * 3.14159265358979 * h * ph) / h;
  603. data.sample.l[i] = (float) (0.4 * y);
  604. }
  605. d.pluginState = wt::encodeUserData (data);
  606. };
  607. named ("Helix 3: the grains on (a falling tone)", { { "Grain On", 1.0f } });
  608. out.back().apply = withSample;
  609. named ("Helix 3: the spectral oscillator on (a rich falling tone), a band of four partials",
  610. { { "Spectral On", 1.0f }, { "Spectral Width", 2.0f }, { "Spectral Partials", 4.0f } });
  611. out.back().apply = withRich;
  612. named ("Helix 3: the sample on an octave up (a rich falling tone)", { { "Sample On", 1.0f }, { "Sample Transpose", 12.0f } });
  613. out.back().apply = withRich;
  614. // (round 190oc) Helix round 4: the granular / spectral oscillators' unison needs them on and voices to detune and
  615. // spread; reverse grains need the grains on
  616. named ("Helix 4: the grains on, five unison voices (a falling tone)", { { "Grain On", 1.0f }, { "Grain Unison", 5.0f } });
  617. out.back().apply = withSample;
  618. named ("Helix 4: the spectral oscillator on, four unison voices (a rich falling tone)", { { "Spectral On", 1.0f }, { "Spectral Unison", 4.0f } });
  619. out.back().apply = withRich;
  620. break;
  621. }
  622. case InstrumentKind::braid:
  623. {
  624. // (rollup 0.1.30 step 7, round 190lc) Braid's new channel is Live's default Meld (core/BraidParams.cpp): both
  625. // engines Basic Shapes as a sine (Shape 0, so Tone has nothing to colour), filters wide open, amp sustain at
  626. // full (Decay / its slope / Loop unheard), and a matrix that routes only the bend, MPE pitch, velocity and the
  627. // voice spread, so each engine's mod envelope, LFO 1 (with its two FX) and LFO 2 move nothing until a matrix
  628. // cell routes them; glide wants a glide time and a mono legato note, Legato a mono patch, Link Envelopes an
  629. // engine B whose own amp envelope differs, Osc Reset a chord hit again while it sounds
  630. const auto routed = [] (std::vector<std::pair<int, float>> cells) {
  631. return [cells] (ChannelDef& d) {
  632. if ((int) d.modelParams.size() < braid::stateSize)
  633. {
  634. const auto def = braidDefaults();
  635. const auto have = d.modelParams.size();
  636. d.modelParams.resize ((std::size_t) braid::stateSize);
  637. std::copy (def.begin() + (std::ptrdiff_t) have, def.end(), d.modelParams.begin() + (std::ptrdiff_t) have);
  638. }
  639. for (const auto& [cell, v] : cells)
  640. d.modelParams[(std::size_t) cell] = v;
  641. };
  642. };
  643. using namespace braid;
  644. for (int k = 0; k < 2; ++k)
  645. {
  646. const std::string e = k == 0 ? "A " : "B ";
  647. const auto t = k * tgt::perEngine;
  648. const auto modEnv = k == 0 ? src::aModEnv : src::bModEnv, lfo1 = k == 0 ? src::aLfo1 : src::bLfo1,
  649. lfo1Fx = k == 0 ? src::aLfo1Fx : src::bLfo1Fx, lfo2 = k == 0 ? src::aLfo2 : src::bLfo2;
  650. // (Basic Shapes' second macro is the pulse width: heard near the square end of Shape)
  651. named (e + "shaped near a square, its filter at 1 kHz", { { e + "Osc Macro 1", 0.9f }, { e + "Filter Freq", 1000.0f },
  652. { e + "Filter Macro 1", 0.5f } });
  653. // (a mono, non-legato voice restarts on the same voice: its phase reset is heard)
  654. named (e + "shaped as a saw, mono, not legato, the chord hit again", { { e + "Osc Macro 1", 0.6f }, { "Poly", 0.0f }, { "Legato", 0.0f } },
  655. "pat:retrig");
  656. const std::vector<std::pair<std::string, float>> amp { { e + "Amp Decay", 0.4f }, { e + "Amp Sustain", 0.3f }, { e + "Amp Attack", 0.05f } };
  657. named (e + "amp envelope decaying to 0.3", amp);
  658. auto ampLoop = amp;
  659. ampLoop.push_back ({ e + "Amp Loop", 1.0f });
  660. named (e + "amp envelope decaying to 0.3, held long", ampLoop, "pat:long");
  661. // the mod envelope slow and shaped, on the engine's filter (at 1 kHz) and pitch
  662. const std::vector<std::pair<std::string, float>> mod { { e + "Filter Freq", 1000.0f }, { e + "Mod Attack", 0.15f }, { e + "Mod Decay", 0.3f },
  663. { e + "Mod Release", 0.3f }, { e + "Mod Initial", 0.1f }, { e + "Mod Peak", 1.0f },
  664. { e + "Mod Sustain", 0.3f }, { e + "Mod Final", 0.2f } };
  665. const auto modCells = routed ({ { matrixIndex (t + tgt::filterFreq, modEnv), 0.6f }, { matrixIndex (t + tgt::pitch, modEnv), 0.3f } });
  666. named (e + "mod envelope slow and shaped, on its filter and pitch", mod);
  667. out.back().apply = modCells;
  668. auto modLoop = mod;
  669. modLoop.push_back ({ e + "Mod Loop", 1.0f });
  670. named (e + "mod envelope slow and shaped, on its filter and pitch, looping", modLoop, "pat:long");
  671. out.back().apply = modCells;
  672. // LFO 1 (and its FX output) and LFO 2 on the engine's filter and pitch: free at 4 Hz, tempo-synced, after a gap
  673. const auto lfoCells = routed ({ { matrixIndex (t + tgt::filterFreq, lfo1), 0.5f }, { matrixIndex (t + tgt::pitch, lfo1Fx), 0.3f },
  674. { matrixIndex (t + tgt::detune, lfo2), 0.8f }, { matrixIndex (t + tgt::filterMacro1, lfo2), 0.5f } });
  675. // (LFO 1 near a square, so its pulse width counts; its second FX a ramp up instead of the neutral Bipolar;
  676. // LFO 2 retriggered, so its phase counts after a gap; the free rates off the synced ones' 4 Hz at 120 BPM)
  677. const std::vector<std::pair<std::string, float>> lfos { { e + "Filter Freq", 1000.0f }, { e + "Filter Macro 1", 0.4f }, { e + "LFO 1 Rate", 3.0f },
  678. { e + "LFO 1 Macro 1", 0.9f }, { e + "LFO 1 FX 1 Macro", 0.5f },
  679. { e + "LFO 1 FX 2", 15.0f }, { e + "LFO 1 FX 2 Macro", 0.5f },
  680. { e + "LFO 2 Rate", 3.0f }, { e + "LFO 2 Retrigger", 1.0f } };
  681. named (e + "LFO 1 / its FX / LFO 2 at 4 Hz on its filter and pitch", lfos);
  682. out.back().apply = lfoCells;
  683. auto synced = lfos;
  684. synced.push_back ({ e + "LFO 1 Sync", 1.0f });
  685. synced.push_back ({ e + "LFO 2 Sync", 1.0f });
  686. named (e + "LFO 1 / its FX / LFO 2 tempo-synced on its filter and pitch", synced);
  687. out.back().apply = lfoCells;
  688. named (e + "LFO 1 / its FX / LFO 2 at 4 Hz on its filter and pitch, a note after a gap", lfos, "pat:gap");
  689. out.back().apply = lfoCells;
  690. named (e + "glide over a legato second note", { { "Poly", 0.0f }, { e + "Glide Time", 0.3f } }, "pat:mono");
  691. }
  692. named ("mono, a second note over the first, a slow attack", { { "Poly", 0.0f }, { "A Amp Attack", 0.2f }, { "B Amp Attack", 0.2f } }, "pat:mono");
  693. named ("engine B's own amp envelope slow", { { "B Amp Attack", 0.5f }, { "B Amp Sustain", 0.3f }, { "B Amp Decay", 0.3f } });
  694. break;
  695. }
  696. default:
  697. break;
  698. }
  699. (void) named;
  700. return out;
  701. }
  702. inline std::vector<std::string> split (const std::string& s, char sep)
  703. {
  704. std::vector<std::string> out;
  705. std::stringstream ss (s);
  706. std::string part;
  707. while (std::getline (ss, part, sep))
  708. out.push_back (part);
  709. return out;
  710. }
  711. // the context of `key`: the channel and the pattern; false when the key doesn't apply
  712. inline bool context (const std::string& key, const ChannelDef& c, const std::vector<Control>& controls, const std::vector<Hint>& hints,
  713. int target, ChannelDef& ctx, Pattern& p, std::string* note = nullptr)
  714. {
  715. ctx = c;
  716. p = ctlaudit::patternFor (c.instrument);
  717. std::string text;
  718. for (const auto& part : split (key, '+'))
  719. {
  720. const auto f = split (part, ':');
  721. if (f.empty())
  722. return false;
  723. if (f[0] == "pat" && f.size() >= 2)
  724. {
  725. if (f[1] == "mono") p.keys = { 60 }, p.keys2 = { 64 }, text += "a legato second note";
  726. else if (f[1] == "bend") p.bend = 2.0f, p.channelPitch = 200.0f, text += "the pitch wheel / PITCH knob up 2 semitones";
  727. else if (f[1] == "mod") p.modWheel = 1.0f, text += "the mod wheel at full";
  728. else if (f[1] == "vel" && f.size() >= 3) p.velocity = (float) std::atof (f[2].c_str()), text += "velocity " + f[2];
  729. else if (f[1] == "rel") p.releaseVelocity = 0.1f, text += "a note-off velocity of 0.1";
  730. else if (f[1] == "long") p.heldBlocks = 300, p.releaseBlocks = 60, text += "the notes held 3.5 s";
  731. else if (f[1] == "gap") p.keys = { 60 }, p.keys2 = { 64 }, p.firstOffBlock = 6, p.secondBlock = 24, text += "a note, a gap, then another note";
  732. else if (f[1] == "offline") p.offline = true, text += "rendered as an export (offline)";
  733. else if (f[1] == "bpm") p.bpm = 97.0, text += "a tempo of 97 BPM (tempo-synced times differ from free ones at 120)";
  734. else if (f[1] == "retrig") p.keys2 = p.keys, p.secondBlock = 4, text += "the chord hit again while it sounds";
  735. else if (f[1] == "pads")
  736. {
  737. p.keys.clear();
  738. for (int k = 36; k <= 51; ++k)
  739. p.keys.push_back (k);
  740. p.keys2 = p.keys, text += "every pad (keys 36…51)";
  741. }
  742. else if (f[1] == "allkeys")
  743. {
  744. p.keys.clear();
  745. for (int k = 0; k < 128; ++k)
  746. p.keys.push_back (k);
  747. p.keys2 = p.keys, text += "every key (0…127: a drum engine's pads wherever they sit)";
  748. }
  749. else if (f[1] == "overlap") p.keys = { 60 }, p.keys2 = { 64 }, p.secondBlock = 6, p.firstOffBlock = 24, text += "a second note over the first, the first let go";
  750. else if (f[1] == "one") p.keys = { 60 }, p.keys2.clear(), text += "one key (60) alone";
  751. else if (f[1] == "vlong") p.heldBlocks = 1100, p.releaseBlocks = 60, text += "the notes held 13 s";
  752. else if (f[1] == "low" || f[1] == "high")
  753. {
  754. const int d = f[1] == "low" ? -24 : 24;
  755. for (auto& k : p.keys) k += d;
  756. for (auto& k : p.keys2) k += d;
  757. text += f[1] == "low" ? "the chord two octaves down" : "the chord two octaves up";
  758. }
  759. else
  760. return false;
  761. }
  762. else if (f[0] == "set" && f.size() >= 3)
  763. {
  764. const int i = std::atoi (f[1].c_str());
  765. if (i < 0 || i >= (int) controls.size() || i == target)
  766. return false;
  767. const auto v = (float) std::atof (f[2].c_str());
  768. if (! controls[(std::size_t) i].set (ctx, v))
  769. return false;
  770. std::ostringstream o;
  771. o << controls[(std::size_t) i].name << " = " << v;
  772. text += o.str();
  773. }
  774. else if (f[0] == "hint" && f.size() >= 2)
  775. {
  776. const int i = findHint (hints, f[1]);
  777. if (i < 0)
  778. return false;
  779. for (const auto& [index, v] : hints[(std::size_t) i].sets)
  780. for (std::size_t j = 0; j < controls.size(); ++j)
  781. if (controls[j].index == index && (int) j != target)
  782. controls[j].set (ctx, v);
  783. if (hints[(std::size_t) i].apply)
  784. hints[(std::size_t) i].apply (ctx);
  785. text += hints[(std::size_t) i].note;
  786. }
  787. else if (f[0] == "rand" && f.size() >= 2)
  788. {
  789. std::uint32_t seed = 1730u + (std::uint32_t) std::atoi (f[1].c_str()) * 7919u;
  790. auto rnd = [&seed] {
  791. seed = seed * 1664525u + 1013904223u;
  792. return (float) ((seed >> 8) & 0xffffff) / 16777216.0f;
  793. };
  794. for (std::size_t j = 0; j < controls.size(); ++j)
  795. {
  796. const auto& k = controls[j];
  797. // (round 190mc) Transistor Bass's program row picks WHICH program / patch / sequence the other controls
  798. // edit (FL's PROGRAM, AF, SEQUENCE, TRANSP., PATCH): a random setting keeps them, and draws no number for
  799. // them, so the other controls get the values they had before the row existed
  800. if (ctx.instrument == InstrumentKind::transistorbass && k.index >= tbprog::program && k.index <= tbprog::patch)
  801. continue;
  802. std::string lower = k.name;
  803. std::transform (lower.begin(), lower.end(), lower.begin(), [] (unsigned char ch) { return (char) std::tolower (ch); });
  804. const auto r = rnd();
  805. if ((int) j == target || lower.find ("master") != std::string::npos || lower == "volume" || lower == "output"
  806. || lower.find ("mute") != std::string::npos)
  807. continue;
  808. k.set (ctx, k.low + r * (k.high - k.low));
  809. }
  810. text += "random setting " + f[1];
  811. }
  812. else
  813. return false;
  814. text += ", ";
  815. }
  816. if (text.size() >= 2)
  817. text.resize (text.size() - 2);
  818. if (note != nullptr)
  819. *note = text;
  820. return true;
  821. }
  822. // the values a control is tried at from its current one: the far end, and the near end when the current value is inside
  823. inline std::vector<float> valuesFrom (const Control& k, float v)
  824. {
  825. std::vector<float> out { ctlaudit::flipped (k, v) };
  826. const auto other = out[0] == k.low ? k.high : k.low;
  827. if (std::abs (other - v) > 1e-6f * std::max (1.0f, std::abs (k.high - k.low)))
  828. out.push_back (other);
  829. // a phase's two ends are the same angle: half a cycle away too (the effects' rule, round 173d). Round 190ix: "Phase"
  830. // too, and Tetra's Filter Morph, whose two ends are both the low pass (Operator's low → band → high → notch → low)
  831. const auto endsWith = [&k] (const char* tail) {
  832. const auto n = std::strlen (tail);
  833. return k.name.size() >= n && k.name.compare (k.name.size() - n, n, tail) == 0;
  834. };
  835. // (rollup 0.1.30: Helix's "Filter 1 Morph" / "Filter 2 Morph", the same cyclic morph filter as Tetra's)
  836. const auto helixMorph = k.name.rfind ("Filter ", 0) == 0 && endsWith (" Morph");
  837. if (endsWith ("phase") || endsWith ("Phase") || endsWith ("Filter Morph") || helixMorph)
  838. out.push_back (0.5f * (k.low + k.high) + (v < 0.5f * (k.low + k.high) ? 0.0f : -0.25f * (k.high - k.low)));
  839. return out;
  840. }
  841. // the largest change of control `target` in this context (dB, −300 = none); `base` the context's own render
  842. inline double moveIn (const ChannelDef& ctx, const Pattern& p, const Samples& s, const Control& k, const std::vector<float>& base)
  843. {
  844. const auto v = k.get (ctx);
  845. if (! v)
  846. return -300.0;
  847. double best = -300.0;
  848. for (const auto to : valuesFrom (k, *v))
  849. {
  850. auto changed = ctx;
  851. if (! k.set (changed, to))
  852. continue;
  853. best = std::max (best, ctlaudit::diffDb (ctlaudit::render (changed, p, s), base));
  854. if (best > wakeDb)
  855. break;
  856. }
  857. return best;
  858. }
  859. struct Verdict
  860. {
  861. int control = 0; // index into the editor list
  862. double plain = -300.0; // the move with the plain pattern
  863. double best = -300.0; // the move in the context that woke it
  864. std::string key, note; // "" = it moves plainly, or it never moved (best ≤ wakeDb)
  865. };
  866. // every control of the list: plain first, then for the silent ones the contexts in order (each context's base render
  867. // is shared by the controls still silent when it doesn't depend on them). `known` (control name → key) is tried first;
  868. // `searchAll` false stops there (the regression test); `only` limits the list (indices into `controls`).
  869. inline std::vector<Verdict> wake (const ChannelDef& c, const std::vector<Control>& controls, const Samples& s,
  870. const std::map<std::string, std::string>& known = {}, bool searchAll = true,
  871. const std::vector<int>& only = {}, double budgetSeconds = 0.0)
  872. {
  873. // (a budget: the slow engines stop searching after it, their silent controls left DEAD for a hint)
  874. const auto t0 = std::chrono::steady_clock::now();
  875. auto overBudget = [&] {
  876. return budgetSeconds > 0.0 && std::chrono::duration<double> (std::chrono::steady_clock::now() - t0).count() > budgetSeconds;
  877. };
  878. std::vector<Verdict> out;
  879. const auto hints = hintsFor (c.instrument, controls);
  880. const auto p0 = ctlaudit::patternFor (c.instrument);
  881. const auto base0 = ctlaudit::render (c, p0, s);
  882. std::vector<int> silent;
  883. for (int i = 0; i < (int) controls.size(); ++i)
  884. {
  885. if (! only.empty() && std::find (only.begin(), only.end(), i) == only.end())
  886. continue;
  887. Verdict v;
  888. v.control = i;
  889. v.plain = v.best = moveIn (c, p0, s, controls[(std::size_t) i], base0);
  890. out.push_back (v);
  891. if (v.plain <= wakeDb)
  892. silent.push_back ((int) out.size() - 1);
  893. }
  894. auto tryKey = [&] (const std::string& key, std::vector<int>& left, bool fromKnown = false) {
  895. // a pattern / set: context is the same for every control (a set: on the control itself is refused), so its
  896. // render is shared; a hint: or rand: context leaves the control itself alone, so it is built per control
  897. const bool shared = key.find ("hint:") == std::string::npos && key.find ("rand:") == std::string::npos;
  898. std::vector<float> base;
  899. bool built = false;
  900. std::vector<int> next;
  901. const auto hintAt = key.rfind ("hint:", 0) == 0 ? findHint (hints, split (key.substr (5), '+').front()) : -1;
  902. const auto* scope = ! fromKnown && hintAt >= 0 && hintAt < (int) hints.size() && ! hints[(std::size_t) hintAt].scope.empty() ? &hints[(std::size_t) hintAt].scope : nullptr;
  903. for (const auto at : left)
  904. {
  905. if (overBudget() || (scope != nullptr && controls[(std::size_t) out[(std::size_t) at].control].name.rfind (*scope, 0) != 0))
  906. {
  907. next.push_back (at);
  908. continue;
  909. }
  910. auto& v = out[(std::size_t) at];
  911. ChannelDef cx;
  912. Pattern px;
  913. std::string nx;
  914. if (! context (key, c, controls, hints, v.control, cx, px, &nx))
  915. {
  916. next.push_back (at);
  917. continue;
  918. }
  919. if (! shared || ! built)
  920. base = ctlaudit::render (cx, px, s), built = true;
  921. static const bool debug = std::getenv ("CTLWAKE_DEBUG") != nullptr;
  922. if (ctlaudit::peak (base) < 1e-5)
  923. {
  924. if (debug)
  925. std::fprintf (stderr, " [%s] %s: silent context\n", controls[(std::size_t) v.control].name.c_str(), key.c_str());
  926. next.push_back (at);
  927. continue;
  928. }
  929. const auto m = moveIn (cx, px, s, controls[(std::size_t) v.control], base);
  930. if (debug)
  931. std::fprintf (stderr, " [%s] %s: peak %.3g, move %.0f dB\n", controls[(std::size_t) v.control].name.c_str(), key.c_str(), ctlaudit::peak (base), m);
  932. if (m > wakeDb)
  933. v.best = m, v.key = key, v.note = nx;
  934. else
  935. next.push_back (at);
  936. }
  937. left = std::move (next);
  938. };
  939. // the known keys first (each control its own)
  940. if (! known.empty())
  941. {
  942. std::vector<int> next;
  943. for (const auto at : silent)
  944. {
  945. const auto it = known.find (controls[(std::size_t) out[(std::size_t) at].control].name);
  946. std::vector<int> one { at };
  947. if (it != known.end())
  948. tryKey (it->second, one, true); // (a known key is tried whatever its hint's search scope)
  949. if (! one.empty())
  950. next.push_back (at);
  951. }
  952. silent = std::move (next);
  953. }
  954. if (! searchAll || silent.empty())
  955. return out;
  956. static const char* const pats[] = { "pat:mono", "pat:bend", "pat:mod", "pat:vel:0.2", "pat:vel:1", "pat:rel", "pat:long",
  957. "pat:retrig", "pat:pads", "pat:low", "pat:high", "pat:bpm", "pat:offline", "pat:gap" };
  958. // the hand-written hints first (they name the context), then each performance alone
  959. for (int h = 0; h < (int) hints.size() && ! silent.empty(); ++h)
  960. {
  961. const std::string key = "hint:" + hintId (hints[(std::size_t) h].note) + (hints[(std::size_t) h].pattern.empty() ? "" : "+" + hints[(std::size_t) h].pattern);
  962. tryKey (key, silent);
  963. }
  964. for (const auto* k : pats)
  965. if (! silent.empty())
  966. tryKey (k, silent);
  967. // one other control alone, at each end (a section on)
  968. for (int j = 0; j < (int) controls.size() && ! silent.empty(); ++j)
  969. {
  970. const auto v = controls[(std::size_t) j].get (c);
  971. if (! v)
  972. continue;
  973. for (const auto to : valuesFrom (controls[(std::size_t) j], *v))
  974. {
  975. std::ostringstream key;
  976. key << "set:" << j << ":" << to;
  977. tryKey (key.str(), silent);
  978. }
  979. }
  980. // random settings, plain and with each performance the controls may need
  981. for (int r = 0; r < 24 && ! silent.empty(); ++r)
  982. for (const char* pat : { "", "+pat:mono", "+pat:mod", "+pat:bend", "+pat:long" })
  983. if (! silent.empty())
  984. tryKey ("rand:" + std::to_string (r) + pat, silent);
  985. // a performance with one other control (the mod wheel's destination needs its amount up)
  986. for (const char* pat : { "pat:mod", "pat:bend", "pat:mono", "pat:long", "pat:vel:0.2", "pat:rel", "pat:bpm" })
  987. for (int j = 0; j < (int) controls.size() && ! silent.empty(); ++j)
  988. {
  989. const auto v = controls[(std::size_t) j].get (c);
  990. if (! v)
  991. continue;
  992. for (const auto to : valuesFrom (controls[(std::size_t) j], *v))
  993. {
  994. std::ostringstream key;
  995. key << pat << "+set:" << j << ":" << to;
  996. tryKey (key.str(), silent);
  997. }
  998. }
  999. return out;
  1000. }
  1001. } // namespace lynx::ctlwake