PluginSubstitutes.cpp 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033
  1. #include "core/PluginSubstitutes.h"
  2. #include "core/VoiceMatch.h"
  3. #include <algorithm>
  4. #include <cctype>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <limits>
  8. #include <map>
  9. #include "core/Effects.h"
  10. #include "core/FabFilterStates.h"
  11. #include "core/FlEffects.h"
  12. #include "core/FlPluginDb.h"
  13. #include "core/FlWrapper.h"
  14. #include "core/LynxTune.h"
  15. #include "core/MixSuite.h"
  16. #include "core/VocalPitch.h"
  17. #include "core/VoiceTools.h"
  18. #include "core/VoiceShift.h"
  19. #include "core/VoxStrip.h"
  20. #include "core/EchoSuite.h"
  21. #include "core/DynamicsSuite.h"
  22. namespace lynx
  23. {
  24. namespace
  25. {
  26. // The built-in table (format: docs/PLUGIN_FALLBACK.md). Seeded with the third-party plugins of tmp/gf/PLUGIN_QUEUE.md
  27. // and common mixing staples, mapped to EXISTING LYNX effects. Identifiers marked [DATA] were read from real projects'
  28. // FL wrapper records; the others match by name. Parameter maps only where the saved state shows the layout and a
  29. // public manual gives the meaning (each one says so). Modules added later (pitch corrector, vocal tools...) append
  30. // their own entries here or through registerPluginSubstitutes.
  31. constexpr std::string_view builtInTable = R"TABLE(
  32. # ---------------------------------------------------------------- reverbs -> LYNX's reverbs (round 100)
  33. # Valhalla DSP: the saved state is a JUCE XML block whose attributes are the plugin's normalised (0..1) VST3 values
  34. # [DATA, round 98]. Round 100 measured each parameter's value -> unit law and enumeration breakpoints on the official
  35. # demos (black-box, REA_rodada100 §0-§6) [EXEC]; LYNX's own reverbs use the same laws, so most maps are identities;
  36. # enumerations use "steps", and Atrium's decay (LYNX's own law) a "curve". The Mix controls are equal-power
  37. # dry / wet inside the effect (measured), so the slot mix stays at 100 %.
  38. [valhalla-vintageverb]
  39. product = ValhallaVintageVerb
  40. vendor = Valhalla DSP
  41. lynx = Epoch Verb
  42. # [DATA] class ID from FL wrapper records of real projects
  43. vst3 = 7654535665657633616c68616c6c6176
  44. names = ValhallaVintageVerb
  45. map = xml:Mix -> Mix
  46. map = xml:PreDelay -> Predelay
  47. map = xml:Decay -> Decay
  48. map = xml:Size -> Size
  49. map = xml:Attack -> Attack
  50. map = xml:BassMult -> Bass mult
  51. map = xml:BassXover -> Bass xover
  52. map = xml:HighShelf -> High shelf
  53. map = xml:HighFreq -> High freq
  54. map = xml:EarlyDiffusion -> Early diffusion
  55. map = xml:LateDiffusion -> Late diffusion
  56. map = xml:ModRate -> Mod rate
  57. map = xml:ModDepth -> Mod depth
  58. map = xml:HighCut -> High cut
  59. map = xml:LowCut -> Low cut
  60. map = xml:ColorMode -> Color | steps 0:0 0.6662:0.5 0.9995:1
  61. map = xml:ReverbMode -> Mode | steps 0:0 0.0828:0.0476 0.1245:0.0952 0.1662:0.1429 0.2078:0.1905 0.2495:0.2381 0.2912:0.2857 0.3328:0.3333 0.3745:0.381 0.4162:0.4286 0.4578:0.4762 0.4995:0.5238 0.5412:0.5714 0.5828:0.619 0.6245:0.6667 0.6662:0.7143 0.7078:0.7619 0.7495:0.8095 0.7912:0.8571 0.8328:0.9048 0.8745:0.9524 0.9162:1 0.9578:0
  62. [valhalla-room]
  63. product = ValhallaRoom
  64. vendor = Valhalla DSP
  65. lynx = Atrium
  66. names = ValhallaRoom
  67. map = xml:mix -> Mix
  68. map = xml:predelay -> Predelay
  69. map = xml:HiCut -> High cut
  70. map = xml:earlyLateMix -> Early/late
  71. map = xml:lateSize -> Late size
  72. map = xml:lateCross -> Late cross
  73. map = xml:lateModRate -> Late mod rate
  74. map = xml:lateModDepth -> Late mod depth
  75. map = xml:RTBassMultiply -> Bass mult
  76. map = xml:RTXover -> Bass xover
  77. map = xml:RTHighMultiply -> High mult
  78. map = xml:RTHighXover -> High xover
  79. map = xml:earlySize -> Early size
  80. map = xml:earlyCross -> Early cross
  81. map = xml:earlyModRate -> Early mod rate
  82. map = xml:earlyModDepth -> Early mod depth
  83. map = xml:earlySend -> Early send
  84. map = xml:diffusion -> Diffusion
  85. map = xml:space -> Space
  86. map = xml:LoCut -> Low cut
  87. map = xml:decay -> Decay | curve 0:0 0.0002:0.2254 0.0005:0.2646 0.001:0.2987 0.002:0.3372 0.004:0.3807 0.008:0.4297 0.012:0.4613 0.019:0.4999 0.03:0.5415 0.05:0.5921 0.08:0.6429 0.13:0.6999 0.2:0.7546 0.3:0.8101 0.45:0.8696 0.65:0.9274 1:1
  88. map = xml:type -> Type | steps 0:0 0.1662:0.0909 0.2495:0.1818 0.3328:0.2727 0.4162:0.3636 0.4995:0.4545 0.5828:0.5455 0.6662:0.6364 0.7495:0.7273 0.8328:0.8182 0.9162:0.9091 0.9995:1
  89. [valhalla-plate]
  90. product = ValhallaPlate
  91. vendor = Valhalla DSP
  92. lynx = Foil Plate
  93. names = ValhallaPlate
  94. map = xml:Mix -> Mix
  95. map = xml:PreDelay -> Predelay
  96. map = xml:Decay -> Decay
  97. map = xml:Size -> Size
  98. map = xml:Width -> Width
  99. map = xml:ModRate -> Mod rate
  100. map = xml:ModDepth -> Mod depth
  101. map = xml:LowEQFreq -> Low EQ freq
  102. map = xml:LowEQGain -> Low EQ gain
  103. map = xml:HighEQFreq -> High EQ freq
  104. map = xml:HighEQGain -> High EQ gain
  105. map = xml:Type -> Type | steps 0:0 0.0828:0.0909 0.1245:0.1818 0.1662:0.2727 0.2078:0.3636 0.2495:0.4545 0.2912:0.5455 0.3328:0.6364 0.3745:0.7273 0.4162:0.8182 0.4578:0.9091 0.4995:1 0.5412:0
  106. [valhalla-supermassive]
  107. product = Valhalla Supermassive
  108. vendor = Valhalla DSP
  109. lynx = Nebula
  110. names = ValhallaSupermassive
  111. map = xml:Mix -> Mix
  112. map = xml:Delay_Ms -> Delay
  113. map = xml:DelayWarp -> Warp
  114. map = xml:Feedback -> Feedback
  115. map = xml:Density -> Density
  116. map = xml:Width -> Width
  117. map = xml:LowCut -> Low cut
  118. map = xml:HighCut -> High cut
  119. map = xml:ModRate -> Mod rate
  120. map = xml:ModDepth -> Mod depth
  121. map = xml:DelaySync -> Sync | steps 0:0 0.4995:0.3333 0.7495:0.6667 0.9995:1
  122. map = xml:DelayNote -> Note | steps 0:0 0.1453:0.1667 0.287:0.3333 0.4287:0.5 0.5745:0.6667 0.7162:0.8333 0.8578:1
  123. map = xml:Mode -> Mode | steps 0:0 0.0828:0.0476 0.1245:0.0952 0.1662:0.1429 0.2078:0.1905 0.2495:0.2381 0.2912:0.2857 0.3328:0.3333 0.3745:0.381 0.4162:0.4286 0.4578:0.4762 0.4995:0.5238 0.5412:0.5714 0.5828:0.619 0.6245:0.6667 0.6662:0.7143 0.7078:0.7619 0.7495:0.8095 0.7912:0.8571 0.8328:0.9048 0.8745:0.9524 0.9162:1 0.9578:0
  124. [valhalla-shimmer]
  125. product = ValhallaShimmer
  126. vendor = Valhalla DSP
  127. lynx = Halo
  128. names = ValhallaShimmer
  129. # the reference saves bare parameterN attributes (0..1); the order is its VST3 parameter list [EXEC]
  130. map = xml:parameter0 -> Mix
  131. map = xml:parameter1 -> Shift
  132. map = xml:parameter2 -> Feedback
  133. map = xml:parameter3 -> Diffusion
  134. map = xml:parameter4 -> Size
  135. map = xml:parameter5 -> Low cut
  136. map = xml:parameter6 -> High cut
  137. map = xml:parameter7 -> Mod rate
  138. map = xml:parameter8 -> Mod depth
  139. # round 135: its four reverb modes (Mono / three stereo sizes, steps at 0.25 / 0.5 / 0.75 [EXEC]) -> Halo's same four
  140. map = xml:parameter9 -> Reverb mode | steps 0:0.125 0.25:0.25 0.5:0.375 0.75:0.625
  141. map = xml:parameter10 -> Shift mode | steps 0:0 0.25:0.25 0.45:0.5 0.65:0.75 0.85:1
  142. map = xml:parameter11 -> Color | steps 0:0 0.525:1
  143. [valhalla-futureverb]
  144. product = ValhallaFutureVerb
  145. vendor = Valhalla DSP
  146. lynx = Horizon
  147. names = ValhallaFutureVerb
  148. map = xml:Mix -> Mix
  149. map = xml:Width -> Width
  150. map = xml:Echo_Ms -> Echo time
  151. map = xml:EchoFeedback -> Echo feedback
  152. map = xml:EchoSpread -> Echo spread
  153. map = xml:EchoDrive -> Echo drive
  154. map = xml:EchoDetune -> Echo detune
  155. map = xml:EchoLevel -> Echo level
  156. map = xml:ReverbDecay -> Decay
  157. map = xml:ReverbSize -> Size
  158. map = xml:ReverbAttack -> Attack
  159. map = xml:ReverbEarlyLate -> Early/late
  160. map = xml:ReverbDensity -> Density
  161. map = xml:ReverbLevel -> Reverb level
  162. map = xml:ModRate -> Mod rate
  163. map = xml:ModDepth -> Mod depth
  164. map = xml:LowEQFreq -> Low EQ freq
  165. map = xml:HighEQFreq -> High EQ freq
  166. map = xml:EchoSync -> Echo sync | steps 0:0 0.4995:0.3333 0.7495:0.6667 0.9995:1
  167. map = xml:EchoNote -> Echo note | steps 0:0 0.1662:0.2 0.3328:0.4 0.4995:0.6 0.6662:0.8 0.8328:1
  168. map = xml:Routing -> Routing | steps 0:0 0.4995:1
  169. map = xml:EchoMode -> Echo mode | steps 0:0 0.0828:0.0909 0.1245:0.1818 0.1662:0.2727 0.2078:0.3636 0.2495:0.4545 0.2912:0.5455 0.3328:0.6364 0.3745:0.7273 0.4162:0.8182 0.4578:0.9091 0.4995:1 0.5412:0
  170. map = xml:ReverbMode -> Reverb mode | steps 0:0 0.0828:0.1429 0.1245:0.2857 0.1662:0.4286 0.2078:0.5714 0.2495:0.7143 0.2912:0.8571 0.3328:1 0.3745:0
  171. map = xml:Color -> Color | steps 0:0 0.1662:0.3333 0.2495:0.6667 0.3328:1
  172. # ---------------------------------------------------------------- other reverbs -> Reeverb 2 / LuxeVerb
  173. [fabfilter-pro-r]
  174. product = FabFilter Pro-R
  175. vendor = FabFilter
  176. lynx = LuxeVerb
  177. names = FabFilter Pro-R; FabFilter Pro-R 2; Pro-R; Pro-R 2
  178. mix = 1
  179. [soundtoys-littleplate]
  180. product = Little Plate
  181. vendor = Soundtoys
  182. lynx = Foil Plate
  183. names = LittlePlate; Little Plate
  184. # round 129 (docs/PARITY.md): LYNX's plate reverb plays a plate's role (was Reeverb 2); its state is encoded: a
  185. # 2 s plate, 100 % wet, at the slot's dry / wet 25 % as before. Round 150: in the measured plate voicing (the
  186. # trial's onset and decay per band, REA_rodada150a §7). Round 152: the editor opens in the one-knob Plate view
  187. preset = Decay=0.3; Mix=1; Voicing=1; View=1
  188. mix = 0.25
  189. [waves-reverbs]
  190. product = Waves reverb (RVerb / H-Reverb / TrueVerb)
  191. vendor = Waves
  192. lynx = Reeverb 2
  193. waves = RVerb; H-Reverb; TrueVerb
  194. preset = Dry=0; Wet=0.8
  195. mix = 0.25
  196. # ---------------------------------------------------------------- delays -> Fruity Delay 3 (FL's "Default" preset)
  197. [waves-h-delay]
  198. product = H-Delay
  199. vendor = Waves
  200. lynx = Echoform
  201. # [DATA] class ID (stereo component) and <PluginName> from real projects. Round 119: LYNX's echo (was Fruity Delay 3
  202. # at FL's default); the RealWorld list is translated (sync host / BPM / ms, note, time, feedback, ping-pong or
  203. # stereo, mix, output, filters), measured on the official trial (docs/analise/REA_rodada119.md §2). Without a
  204. # readable state: a clean quarter-note ping-pong at 30 % feedback
  205. vst3 = 48545356444268532d64656c61792073
  206. waves = H-Delay
  207. translate = waves-h-delay
  208. preset = Mix=1; Style=0.9; Sync L=0.625; Note L=0.45; Sync R=0.625; Note R=0.45; Feedback=0.0465; Mode=0.5417; Age=0; Mod depth=0; Width=1; Pairs=1; Output=0.4611
  209. [waves-supertap]
  210. product = SuperTap
  211. vendor = Waves
  212. lynx = Fruity Delay 3
  213. waves = SuperTap
  214. [soundtoys-echoboy]
  215. product = EchoBoy
  216. vendor = Soundtoys
  217. # round 129 (docs/PARITY.md): LYNX's multi-mode echo plays EchoBoy's role. Round 136: her states play Echoform's Tape
  218. # voicing (the loop structures measured on the official trial, REA_rodada136 §4), recognised by the hash of the encoded
  219. # preset (not decoded here); any other state: round 129's tape echo, 1/4 note at the project tempo, 25 % feedback, 25 % mix
  220. # (round 147: in the Studio reel voicing — EchoBoy's default style, measured black-box, REA_rodada147a)
  221. lynx = Echoform
  222. preset = Mode=0.0415; Sync L=0.6248; Note L=0.4498; Feedback=0.125; Mix=0.25; Echo voicing=0.064516
  223. # [DATA] VST2 unique ID from real projects
  224. vst2 = StEB
  225. names = EchoBoy; EchoBoyJr; EchoBoy Jr
  226. translate = soundtoys-echoboy
  227. [soundtoys-primaltap]
  228. product = PrimalTap
  229. vendor = Soundtoys
  230. # round 129: Echoform (as EchoBoy), a darker lo-fi tape echo
  231. lynx = Echoform
  232. preset = Mode=0.125; Sync L=0.6248; Note L=0.4498; Feedback=0.125; Mix=0.25
  233. names = PrimalTap; Little PrimalTap; LittlePrimalTap
  234. # Valhalla delay / modulation plugins -> LYNX's delay / modulation suite (round 101). Their saved state is a JUCE
  235. # XML block holding every parameter as its normalised value [DATA, EXEC]; the LYNX effects use the same value laws,
  236. # measured black-box on the official demos (docs/analise/REA_rodada101.md §2-§6), so most settings map one to one.
  237. # [derived] VST3 class IDs: Steinberg's VST2-compatible UID ("VST" + the VST2 ID found in the state's FBCh header +
  238. # the first 9 letters of the lower-case name), in FL's byte order; the same rule reproduces ValhallaVintageVerb's ID
  239. # read from real projects.
  240. [valhalla-delay]
  241. product = ValhallaDelay
  242. vendor = Valhalla DSP
  243. lynx = Echoform
  244. vst3 = 64545356614c7679616c68616c6c6164
  245. names = ValhallaDelay
  246. mix = 1
  247. map = xml:Mix -> Mix
  248. # styles: Single, Dual, Ratio, PingPong, Quad onto Echoform's order (Single, Ratio, Quad, Dual, Ping-pong)
  249. map = xml:DelayStyle -> Style | steps 0:0.1 0.19:0.7 0.39:0.3 0.59:0.9 0.79:0.5
  250. map = xml:DelayLSync -> Sync L
  251. map = xml:DelayLNote -> Note L
  252. map = xml:DelayL_Ms -> Time L
  253. map = xml:DelayRSync -> Sync R
  254. map = xml:DelayRNote -> Note R
  255. map = xml:DelayR_Ms -> Time R
  256. map = xml:DelaySpread -> Spread
  257. map = xml:DelaySpacing -> Spacing
  258. map = xml:DelayRatio -> Ratio
  259. # round 137: the quad taps and Repeat / Swell (Echoform has them since round 135w; the same on / off values)
  260. map = xml:TapA -> Tap A
  261. map = xml:TapB -> Tap B
  262. map = xml:TapC -> Tap C
  263. map = xml:TapD -> Tap D
  264. map = xml:RepeatSwell -> Swell
  265. map = xml:Feedback -> Feedback
  266. map = xml:Width -> Width
  267. map = xml:DriveIn -> Drive
  268. map = xml:Age -> Age
  269. map = xml:Diffusion -> Diffusion
  270. map = xml:DiffSize -> Diffusion size
  271. map = xml:LowCut -> Low cut
  272. map = xml:HighCut -> High cut
  273. map = xml:ModRate -> Mod rate
  274. map = xml:ModDepth -> Mod depth
  275. map = xml:Wow -> Wow
  276. map = xml:Flutter -> Flutter
  277. map = xml:FreqShift -> Shift
  278. map = xml:FreqDetune -> Shift detune
  279. map = xml:PitchShift -> Pitch
  280. map = xml:PitchDetune -> Pitch detune
  281. map = xml:Ducking -> Ducking
  282. # round 137: Era (Past below 2/3, Present, Future at the top; measured on the demo's own value texts)
  283. map = xml:Era -> Era | steps 0:0 0.6662:0.5 0.9995:1
  284. # the 17 modes (index floor (24 v)) onto Echoform's 12 characters: Tape, HiFi, BBD, Digital, Ghost (shifter), Pitch,
  285. # RevPitch (reverse), BBDuck (bucket), Clarity (clean), DuckTape (tape), PitchDuck (pitch), LoFi, Quartz (clean),
  286. # PhaserDDL (phaser), RichPitch (detune), ChromeTape (tape), Analog; the "duck" variants' built-in ducking is not kept
  287. map = xml:Mode -> Mode | steps 0:0.041667 0.0828:0.208333 0.1245:0.291667 0.1662:0.458333 0.2078:0.708333 0.2495:0.791667 0.2912:0.875 0.3328:0.291667 0.3745:0.541667 0.4162:0.041667 0.4578:0.791667 0.4995:0.125 0.5412:0.541667 0.5828:0.625 0.6245:0.958333 0.6662:0.041667 0.7078:0.375 0.7495:0.041667
  288. [valhalla-freqecho]
  289. product = ValhallaFreqEcho
  290. vendor = Valhalla DSP
  291. lynx = Spiral Echo
  292. vst3 = 4654535645717668616c68616c6c6166
  293. names = ValhallaFreqEcho
  294. mix = 1
  295. map = xml:wetDryMix -> Mix
  296. map = xml:shift -> Shift
  297. map = xml:delay -> Delay
  298. map = xml:sync -> Sync
  299. map = xml:feedback -> Feedback
  300. map = xml:lowCut -> Low cut
  301. map = xml:highCut -> High cut
  302. map = xml:stereo -> Stereo
  303. [valhalla-spacemodulator]
  304. product = ValhallaSpaceModulator
  305. vendor = Valhalla DSP
  306. lynx = Orbit
  307. vst3 = 535453564d707664616c68616c6c6173
  308. names = ValhallaSpaceModulator
  309. mix = 1
  310. map = xml:wetDry -> Mix
  311. map = xml:rate -> Rate
  312. map = xml:depth -> Depth
  313. map = xml:feedback -> Feedback
  314. map = xml:manual -> Manual
  315. map = xml:Mode -> Mode
  316. [valhalla-ubermod]
  317. product = ValhallaUberMod
  318. vendor = Valhalla DSP
  319. lynx = Lattice Mod
  320. vst3 = 7554535665627672616c68616c6c6175
  321. names = ValhallaUberMod
  322. mix = 1
  323. map = xml:Mix -> Mix
  324. map = xml:Depth -> Depth
  325. map = xml:StereoWidth -> Width
  326. map = xml:Delay -> Delay
  327. map = xml:Feedback -> Feedback
  328. map = xml:Spread -> Spread
  329. map = xml:Slope -> Slope
  330. map = xml:Skew -> Skew
  331. map = xml:Random -> Random
  332. map = xml:TapGain -> Tap gain
  333. map = xml:Diffusion -> Diffusion
  334. map = xml:DiffSize -> Diffusion size
  335. map = xml:DiffModRate -> Diffusion rate
  336. map = xml:DiffModDepth -> Diffusion depth
  337. map = xml:LowCut -> Low cut
  338. map = xml:HighCut -> High cut
  339. map = xml:SpatialXover -> Crossover
  340. map = xml:DetuneRate -> Detune rate
  341. map = xml:DetuneDepth -> Detune depth
  342. map = xml:VibratoRate -> Vibrato rate
  343. map = xml:VibratoDepth -> Vibrato depth
  344. map = xml:OverMod -> Over-mod
  345. map = xml:DriveInGain -> Drive in
  346. map = xml:DriveOutGain -> Drive out
  347. map = xml:DriveNoiseGain -> Noise
  348. map = xml:FeedbackRotate -> Rotate
  349. map = xml:SmoothingTime -> Smoothing
  350. map = xml:ColorMode -> Colour
  351. map = xml:type -> Taps
  352. map = xml:DiffEnable -> Diffusion on
  353. map = xml:Drive -> Drive on
  354. map = xml:DrivePrePost -> Drive post
  355. map = xml:Speed -> Half speed
  356. # round 137: InputPan (0-8, the same value law; its routes measured black-box, REA_rodada137 §4)
  357. map = xml:InputPan -> Input pan
  358. # round 144: DelaySync (floor (17 v): free, straight, dotted, triplet groups — measured, REA_rodada144a §1), the same value law
  359. map = xml:DelaySync -> Delay sync
  360. [fabfilter-timeless]
  361. product = FabFilter Timeless
  362. vendor = FabFilter
  363. lynx = Fruity Delay 3
  364. names = FabFilter Timeless 2; FabFilter Timeless 3; Timeless 2; Timeless 3
  365. # ---------------------------------------------------------------- limiters -> Limiter (ceiling -0.3 dB)
  366. [waves-l-series]
  367. product = Waves L1 / L2 / L3
  368. vendor = Waves
  369. lynx = Limiter
  370. waves = L1; L2; L3; L3-16; L3-LL Multi; L4
  371. [fabfilter-pro-l]
  372. product = FabFilter Pro-L
  373. vendor = FabFilter
  374. lynx = Apex Limiter
  375. names = FabFilter Pro-L; FabFilter Pro-L 2; Pro-L; Pro-L 2
  376. # ---------------------------------------------------------------- compressors -> Compressor
  377. [waves-rcomp]
  378. product = Renaissance Compressor
  379. vendor = Waves
  380. lynx = Compressor
  381. # [DATA] class ID (stereo component) and <PluginName> from real projects
  382. vst3 = 5554535643527253636f6d7072657373
  383. waves = RComp
  384. # round 113: its RealWorld list is translated (threshold, ratio, attack, release, gain; measured on the official
  385. # trial, docs/analise/REA_rodada113.md §3c). Without a readable state: a gentle default (2:1 above -15 dBFS, auto gain)
  386. translate = waves-rcomp
  387. preset = Threshold=0.75; Ratio=0.0526; Auto gain=1
  388. [waves-cla-2a]
  389. product = CLA-2A
  390. vendor = Waves
  391. lynx = Glow Leveler
  392. # [DATA] class ID (stereo component) and <PluginName> from real projects
  393. vst3 = 4c545356324163536c612d3261207374
  394. waves = CLA-2A
  395. # LYNX's optical leveler (round 96). Round 113: gain, peak reduction and comp / limit are translated from the
  396. # RealWorld list (measured on the official trial, REA_rodada113 §3c); without a readable state light leveling
  397. preset = Peak reduction=0.30; Gain=0.067
  398. translate = waves-cla-2a
  399. [waves-cla-76]
  400. product = CLA-76
  401. vendor = Waves
  402. lynx = Crest Compressor
  403. waves = CLA-76
  404. # round 127: LYNX's style compressor fitted to the official trial at her one state (the factory "Start Me Up":
  405. # Input -8.7 dB, Output -16.9 dB, attack 4.3, release 4.31, all buttons, Mix 41.3 %); the RealWorld list is
  406. # translated (REA_rodada127 §3). Without a readable state: a light 4:1 at Waves' defaults
  407. translate = waves-cla-76
  408. preset = Style=0.9; Threshold=0.6; Ratio=0.546; Knee=0.13; Range=0.53; Auto gain=1
  409. [waves-compressors]
  410. product = Waves compressor (CLA-3A / C1 / SSLComp / API-2500)
  411. vendor = Waves
  412. lynx = Compressor
  413. waves = CLA-3A; C1 comp; C1comp; SSLComp; API-2500
  414. preset = Threshold=0.75; Ratio=0.0526; Auto gain=1
  415. [fabfilter-pro-c]
  416. product = FabFilter Pro-C
  417. vendor = FabFilter
  418. lynx = Crest Compressor
  419. names = FabFilter Pro-C 2; FabFilter Pro-C 3; Pro-C 2; Pro-C 3
  420. # LYNX's style compressor (round 108), fitted to our black-box measurements (MEASURE_fabfilter §2); a Pro-C 3 state
  421. # (component state "FFBS", 100 values) is translated: style, threshold, ratio, knee, range, attack, release, hold,
  422. # look-ahead, character, side-chain EQ (3 bands), levels, mix, oversampling. Pro-C 2 states keep the defaults.
  423. translate = pro-c3
  424. # auto gain on by default (round 107): keeps the level when the state is not readable
  425. preset = Auto gain=1
  426. [fabfilter-pro-mb]
  427. product = FabFilter Pro-MB
  428. vendor = FabFilter
  429. lynx = Prism Multiband
  430. names = FabFilter Pro-MB; Pro-MB
  431. # LYNX's 4-band dynamics (round 108, MEASURE_fabfilter §6 / §12.4): the enabled bands are laid out low → high on
  432. # Prism's four bands (gaps become bypassed bands), with threshold, ratio, range, mode, knee, attack / release %,
  433. # level, solo, look-ahead, mix and levels. Without a readable state the bands start at a gentle -12 dB range.
  434. translate = pro-mb
  435. [fabfilter-pro-g]
  436. product = FabFilter Pro-G
  437. vendor = FabFilter
  438. lynx = Sentry Gate
  439. names = FabFilter Pro-G; Pro-G
  440. # LYNX's gate / expander (round 108, MEASURE_fabfilter §7): every setting of the state is translated (style,
  441. # thresholds, ratios, range, attack, release, hold, knee, look-ahead, side-chain filters, wet / dry, output)
  442. translate = pro-g
  443. # ---------------------------------------------------------------- EQs and channel strips -> Parametric EQ (flat)
  444. [waves-ssl-channel]
  445. product = SSL E-Channel
  446. vendor = Waves
  447. lynx = Ridge Strip
  448. # [DATA] class ID (stereo component) and <PluginName> from real projects. Round 123: Ridge Strip's "E" voicing is the
  449. # console measured black-box on the official trial (every EQ band / filter from impulse responses, the feedback
  450. # compressor from stairs, bursts and her takes), so the RealWorld list maps one to one (REA_rodada123.md)
  451. vst3 = 5354535648437353736c6368616e6e65
  452. waves = SSLChannel
  453. translate = waves-ssl-channel
  454. [ssl-native-channel]
  455. product = SSL Native Channel Strip / 4K E
  456. vendor = Solid State Logic
  457. lynx = Ridge Strip
  458. names = SSL Native Channel Strip 2; SSL Native Channel Strip; SSL 4K E; SSL 4K B; Vocalstrip 2; SSL Native Vocalstrip 2
  459. # round 145: a Vocalstrip 2 state (XML, the original's own units) is translated to Ridge's Vocal strip voicing, measured
  460. # black-box on the official trial (de-esser, de-ploser, EQ, compander, order; REA_rodada145 §2); round 148: a 4K E state
  461. # (the same XML form) to Ridge's 4K voicing, measured on the 4K E trial (REA_rodada148 §2); the other strips' states are
  462. # not read (Ridge at its defaults)
  463. translate = ssl-vocalstrip-2
  464. # round 145: the rest of Complete Access (Slate Digital, Solid State Logic, LiquidSonics, sonible, Harrison; official
  465. # trials on this PC) by role only — their states are not read (not in her corpus, not measured): LYNX's effect for
  466. # the same job at its defaults, so a project that used them still plays a sensible chain
  467. [complete-access-strips]
  468. product = channel strips (SSL 4K G, Harrison 32C / MPC, Slate VCC / Virtual Mix Rack)
  469. vendor = Complete Access (role)
  470. lynx = Ridge Strip
  471. names = SSL 4K G; Harrison 32C; Harrison_32ClassicChannelStrip; Harrison 32Classic; Harrison_MPCChannelStrip; VM VCC Channel; Virtual Mix Rack; VBC Rack; SSL Guitarstrip; SSL Native Drumstrip v6
  472. [complete-access-bus-comps]
  473. product = bus / smart compressors (SSL Bus Compressor 2, G3, VBC, sonible smart:comp, pure:comp)
  474. vendor = Complete Access (role)
  475. lynx = Crest Compressor
  476. names = SSL Native Bus Compressor 2; SSL G3 MultiBusComp; SSL 360 Link Bus Compressor; SSL Native X-Comp v6; SSL Fusion HF Compressor; VBC FG-Grey; VBC FG-MU; VBC FG-Red; smartcomp3; smartcomp2; purecomp; learncomp; Harrison_LookaheadCompressor; Harrison_MPCCompressor; VM FG-Stress; VM FG-Bomber
  477. [complete-access-vintage-comps]
  478. product = vintage compressor models (Slate FG-116 / FG-76 / FG-401 / FG-A / FG-Dynamics, SSL X-ValveComp)
  479. vendor = Complete Access (role)
  480. lynx = Compressor
  481. names = VM FG-116; VM FG-116 Modern; VM FG-116 Vintage; VM FG-76; VM FG-401; VM FG-A; VM FG-Dynamics; VM The Monster; SSL Native X-ValveComp v6; MO-TT
  482. [complete-access-optos]
  483. product = optical levelers (Slate FG-2A, SD-3A, Custom Opto)
  484. vendor = Complete Access (role)
  485. lynx = Glow Leveler
  486. names = VM FG-2A; VM SD-3A; VM Custom Opto
  487. [complete-access-limiters]
  488. product = limiters (Slate FG-X 2, SSL X-Limit, sonible smart:limit, pure:limit)
  489. vendor = Complete Access (role)
  490. lynx = Apex Limiter
  491. names = FG-X 2; FG-X; SSL X-Limit; smartlimit; purelimit; learnlimit; Bus Clipper
  492. [complete-access-eqs]
  493. product = EQs (Slate Infinity EQ, FG-73 / FG-N / FG-S / SD-PE1 / CS-EQ, Eiosis AirEQ, SSL X-EQ 2, sonible smart:EQ)
  494. vendor = Complete Access (role)
  495. lynx = Facet EQ
  496. names = Inf EQ; Infinity EQ; VM FG-73; VM FG-N; VM FG-S; VM SD-PE1; VM CS-EQ; VM CS-Lift; VM AirEQ Air; VM AirEQ Earth; Eiosis AirEQ; Eiosis AirEQ 5.1; SSL Native X-EQ 2; SSL Fusion Violet EQ; smartEQ4; smartEQ3; pureeq; learneq; Harrison_LegacyEQ; Harrison_MasteringEQ
  497. [complete-access-deessers]
  498. product = de-essers (SSL DeEss, Slate FG-DS 902, Eiosis E2Deesser, sonible smart:deess)
  499. vendor = Complete Access (role)
  500. lynx = Hush De-esser
  501. names = SSL DeEss; VM FG-DS 902; Eiosis E2Deesser; smartdeess; puredeess; Harrison_De-Esser
  502. [complete-access-gates]
  503. product = gates (SSL X-Gate, Slate Gate Classic / Drums, Harrison Spectral Gate)
  504. vendor = Complete Access (role)
  505. lynx = Sentry Gate
  506. names = SSL X-Gate; VM Gate Classic; VM Gate Drums; Harrison_SpectralGate
  507. [complete-access-reverbs]
  508. product = reverbs (LiquidSonics Lustrous Plates / Seventh Heaven / Cinematic Rooms, Slate VerbSuite Classics, SSL FlexVerb / PlateVerb / SpringVerb, sonible smart:reverb)
  509. vendor = Complete Access (role)
  510. lynx = Foil Plate
  511. names = Lustrous Plates; Seventh Heaven; Seventh Heaven Professional; Cinematic Rooms; Cinematic Rooms Professional; Illusion; VerbSuite Classics; SSL Native FlexVerb; SSL PlateVerb; SSL SpringVerb; SSL GateVerb; smartreverb2; smartreverb; pureverb; learnreverb; Vocal Reverb
  512. preset = Decay=0.3; Mix=1
  513. mix = 0.25
  514. [complete-access-delays]
  515. product = delays (SSL X-Echo / X-Delay, Slate Stellar Echo SD-201, Harrison 3D Delay)
  516. vendor = Complete Access (role)
  517. lynx = Echoform
  518. preset = Mode=0.0415; Sync L=0.6248; Note L=0.4498; Feedback=0.125; Mix=0.25
  519. names = SSL Native X-Echo; SSL X-Delay; Stellar Echo SD-201; Harrison_3DDelay
  520. [complete-access-saturators]
  521. product = saturators (Slate Heatwave / Revival, SSL Fusion Vintage Drive / X-Saturator, Harrison Tape Saturator)
  522. vendor = Complete Access (role)
  523. lynx = Ember Saturator
  524. names = Heatwave; VM Revival; SSL Fusion Vintage Drive; SSL Native X-Saturator v6; SSL Fusion Transformer; Harrison Tape Saturator
  525. [complete-access-tuners]
  526. product = pitch correction (Slate MetaTune)
  527. vendor = Complete Access (role)
  528. lynx = LYNX Tune
  529. names = MetaTune
  530. [waves-s1-imager]
  531. product = S1 Imager
  532. vendor = Waves
  533. lynx = Stereo Shaper
  534. # round 124: the width / rotation / gain matrix measured on the official trial is set exactly on the Stereo Shaper's
  535. # matrix (docs/analise/REA_rodada124_extras.md §4); without a readable state the slot stays neutral
  536. waves = S1 Imager; S1 Imager Stereo
  537. translate = waves-s1-imager
  538. [waves-eqs]
  539. product = Waves EQ (Q10 / Renaissance EQ / SSL EQ)
  540. vendor = Waves
  541. lynx = Parametric EQ
  542. waves = Q10; REQ; SSLEQ
  543. [fabfilter-pro-q]
  544. product = FabFilter Pro-Q
  545. vendor = FabFilter
  546. lynx = Facet EQ
  547. names = FabFilter Pro-Q 2; FabFilter Pro-Q 3; FabFilter Pro-Q 4; Pro-Q 2; Pro-Q 3; Pro-Q 4
  548. # round 124: a Pro-Q 4 state (component state "FFBS", 600 values) is translated band by band (shape, frequency, gain,
  549. # Q, slope; processing mode, gain scale, output) — Facet's shapes are fitted to the official trial, so her curves
  550. # null against the reference (docs/analise/REA_rodada124_extras.md §2). Other versions keep a flat curve.
  551. translate = pro-q4
  552. # ---------------------------------------------------------------- vocal tools -> LYNX's mixing suite (round 96)
  553. [waves-deesser]
  554. product = DeEsser
  555. vendor = Waves
  556. lynx = Hush De-esser
  557. waves = DeEsser; DeEsser Stereo
  558. # round 113: frequency, threshold, split / wideband, side-chain filter and monitor are translated from the RealWorld
  559. # list (measured on the official trial, REA_rodada113 §3c); without a readable state a gentle default (5.5 kHz,
  560. # -20 dBFS, at most 4 dB)
  561. translate = waves-deesser
  562. preset = Frequency=0.487; Threshold=0.667; Range=0.167
  563. [fabfilter-pro-ds]
  564. product = FabFilter Pro-DS
  565. vendor = FabFilter
  566. lynx = Hush De-esser
  567. names = FabFilter Pro-DS; Pro-DS
  568. # round 148: her two states (Single Vocal, wide band) -> Hush's measured vocal voicing (REA_rodada148 §3)
  569. translate = pro-ds
  570. [harrison-deesser]
  571. product = Harrison De-Esser
  572. vendor = Harrison
  573. lynx = Hush De-esser
  574. names = Harrison De-Esser; Harrison DeEsser
  575. [slate-fresh-air]
  576. product = Fresh Air
  577. vendor = Slate Digital
  578. lynx = Aether
  579. names = Fresh Air; FreshAir
  580. # round 113: its two air amounts are read from the state (freshAirAmounts); round 124: they drive Aether's dynamic
  581. # air model, measured black-box on the official trial to match it sample for sample (REA_rodada124 §3)
  582. translate = fresh-air
  583. [soundtoys-decapitator]
  584. product = Decapitator
  585. vendor = Soundtoys
  586. lynx = Ember Saturator
  587. # [DATA] VST2 unique ID from real projects
  588. vst2 = StDc
  589. names = Decapitator
  590. # round 136: Ember's Classic voicing, measured black-box on the official trial (REA_rodada136 §1). Its state is
  591. # encoded (not decoded here); her 63 saved states are known by the hash of the encoded preset and translated to the
  592. # settings the trial reports for them; any other state: style A, drive 2, output -3.2 dB (her usual light drive)
  593. preset = Voicing=1; Classic style=0; Classic drive=0.2; Classic tone=0.5; Classic high cut=1; Classic mix=1; Classic output=0.866667
  594. translate = soundtoys-decapitator
  595. [fabfilter-saturn]
  596. product = FabFilter Saturn
  597. vendor = FabFilter
  598. lynx = Ember Saturator
  599. names = FabFilter Saturn; FabFilter Saturn 2; Saturn 2
  600. preset = Drive=0.15
  601. # a Saturn 2 state ("FFBS", 951 values) sets Ember's multiband mode (round 108): up to four bands with their
  602. # crossovers, style family, drive, mix and level, the global mix and output
  603. translate = saturn2
  604. # ---------------------------------------------------------------- modulation
  605. [soundtoys-panman]
  606. product = PanMan
  607. vendor = Soundtoys
  608. lynx = Auto-pan
  609. # [DATA] VST2 unique ID from real projects
  610. vst2 = StPn
  611. names = PanMan
  612. # round 136: Auto-pan's Rhythm voicing (core/RhythmPan.h), measured black-box on the official trial (REA_rodada136
  613. # §2). Its state is encoded (not decoded here); her 50 saved states are known by the hash of the encoded preset and
  614. # translated to the pattern, rate / beats, width, smoothing, start phase and analog stage measured for them; any other
  615. # state: her most used one (a 3.56 Hz left / right triangle over 151 degrees, analog). (Round 135's rhythmic-panner
  616. # sources — free LFO, rhythm steps — stay available on the same effect; vox138 kept round 136's measured voicing for
  617. # the substitute.)
  618. preset = Depth=0.918; Source=0.5; Rate=0.8505; Smoothing=1; Analog=1; Voicing=1; Rhythm rate=0.8505; Sync=0; Width=0.7171; Offset=0.5; Rhythm smoothing=0.9925; Pattern=0; Amount=0.9981; Start phase=0.9917; Rhythm analog=0.5; Rhythm output=0.5
  619. translate = soundtoys-panman
  620. [soundtoys-littlealterboy]
  621. product = Little AlterBoy
  622. vendor = Soundtoys
  623. lynx = LYNX Tune
  624. # [DATA] VST2 unique ID from real projects
  625. vst2 = StLa
  626. names = Little AlterBoy; LittleAlterBoy; AlterBoy
  627. # round 136 (REA_rodada136 §3): LYNX Tune as the voice shifter — Quantize = chromatic snapping at the fastest retune,
  628. # Transpose = every note bypassed (pitch shift only), the formant shift, the measured Drive stage and the mix. Its
  629. # state is encoded (not decoded here); her 52 saved states are known by the hash of the encoded preset; any other
  630. # state: her most used one (Quantize, formant +1.2 st, drive 4.6). (Round 135's Voice Shift engine — the same role as
  631. # its own effect — stays in LYNX's effect list; the substitute keeps round 136's measured model.)
  632. preset = Scale=0; Retune=0; Humanize=0; Formant preserve=1; Formant shift=0.585714; Transpose=0.5; Mix=1; Drive stage=1; Drive=0.46; Output=0.5
  633. translate = soundtoys-littlealterboy
  634. # ---------------------------------------------------------------- vocal pitch correction -> LYNX Tune (round 95)
  635. [antares-auto-tune]
  636. product = Auto-Tune Pro
  637. vendor = Antares
  638. lynx = LYNX Tune
  639. # [DATA] VST3 class ID from FL wrapper records of real projects (round 98). Round 113: the state's key and scale are
  640. # read (autoTuneProKey); round 120: its retune speed, humanize and flex-tune too (measured on the official trial);
  641. # without a key the project's key (another readable pitch corrector) or, failing that, a gentle chromatic correction
  642. # (50 ms, humanize 50 %) instead of forcing C major
  643. vst3 = 415453563854413175746f2d54756e65
  644. names = Auto-Tune Pro; Auto-Tune Pro X; Auto-Tune Artist; Auto-Tune Access; Auto-Tune EFX+; Auto-Tune Hybrid; Auto-Tune
  645. translate = auto-tune-pro
  646. preset = Scale=0; Retune=0.3536; Humanize=0.5
  647. mix = 1
  648. # ---------------------------------------------------------------- noise suppressor / doubler (round 119)
  649. [waves-ns1]
  650. product = NS1
  651. vendor = Waves
  652. lynx = Quell Denoiser
  653. # LYNX's one-knob noise suppressor, fitted to the official trial (docs/analise/REA_rodada119.md §3); the amount is
  654. # read from the RealWorld list (value 229, %)
  655. waves = NS1
  656. translate = waves-ns1
  657. preset = Amount=0.25
  658. [waves-doubler]
  659. product = Doubler
  660. vendor = Waves
  661. lynx = Gemini Doubler
  662. # LYNX's two-voice doubler, laws measured on the official trial (REA_rodada119 §4); every control of the two-voice
  663. # Doubler is translated from the RealWorld list (voices 3 and 4 of the four-voice one are left out)
  664. waves = Doubler; Doubler2; Doubler4
  665. translate = waves-doubler
  666. [waves-tune]
  667. product = Waves Tune Real-Time
  668. vendor = Waves
  669. lynx = LYNX Tune
  670. waves = WavesTune Real-Time; Waves Tune Real-Time; WavesTune
  671. names = WavesTune Real-Time; Waves Tune Real-Time
  672. # round 120: its saved scale (root + note statuses) and its Note Transition time (= LYNX Tune's retune, measured)
  673. translate = waves-tune
  674. preset = Scale=0; Retune=0.3536; Humanize=0.5
  675. mix = 1
  676. )TABLE";
  677. std::string lowerAscii (std::string s)
  678. {
  679. for (auto& c : s)
  680. c = (char) std::tolower ((unsigned char) c);
  681. return s;
  682. }
  683. std::string trim (std::string_view s)
  684. {
  685. std::size_t a = 0, b = s.size();
  686. while (a < b && std::isspace ((unsigned char) s[a]))
  687. ++a;
  688. while (b > a && std::isspace ((unsigned char) s[b - 1]))
  689. --b;
  690. return std::string (s.substr (a, b - a));
  691. }
  692. std::vector<std::string> splitList (std::string_view s, char separator)
  693. {
  694. std::vector<std::string> out;
  695. std::size_t start = 0;
  696. for (std::size_t i = 0; i <= s.size(); ++i)
  697. if (i == s.size() || s[i] == separator)
  698. {
  699. if (auto item = trim (s.substr (start, i - start)); ! item.empty())
  700. out.push_back (std::move (item));
  701. start = i + 1;
  702. }
  703. return out;
  704. }
  705. // a name key without the channel-layout words Waves and others append ("RComp Stereo", "L2 Mono")
  706. std::string matchKey (const std::string& name)
  707. {
  708. auto key = pluginNameKey (name);
  709. for (bool again = true; again;)
  710. {
  711. again = false;
  712. for (const std::string suffix : { "stereo", "mono" })
  713. if (key.size() >= suffix.size() + 2 && key.compare (key.size() - suffix.size(), suffix.size(), suffix) == 0)
  714. {
  715. key.resize (key.size() - suffix.size());
  716. again = true;
  717. }
  718. }
  719. return key;
  720. }
  721. std::optional<EffectKind> effectKindNamed (const std::string& name)
  722. {
  723. const auto wanted = lowerAscii (trim (name));
  724. for (int k = 0; k <= (int) lastEffectKind; ++k) // the last EffectKind: extend when one is appended
  725. {
  726. const auto kind = (EffectKind) k;
  727. if (kind == EffectKind::plugin || kind == EffectKind::parallel)
  728. continue;
  729. if (lowerAscii (effectInfo (kind).name) == wanted)
  730. return kind;
  731. }
  732. return std::nullopt;
  733. }
  734. int paramNamed (EffectKind kind, const std::string& name)
  735. {
  736. const auto wanted = lowerAscii (trim (name));
  737. const auto& params = effectInfo (kind).params;
  738. for (std::size_t i = 0; i < params.size(); ++i)
  739. if (lowerAscii (params[i].name) == wanted)
  740. return (int) i;
  741. return -1;
  742. }
  743. bool parseFloat (const std::string& s, float& out)
  744. {
  745. try
  746. {
  747. std::size_t used = 0;
  748. out = std::stof (s, &used);
  749. return used == s.size() && std::isfinite (out);
  750. }
  751. catch (...)
  752. {
  753. return false;
  754. }
  755. }
  756. bool parseHex16 (const std::string& s, std::array<std::uint8_t, 16>& out)
  757. {
  758. std::string hex;
  759. for (auto c : s)
  760. if (std::isxdigit ((unsigned char) c))
  761. hex += c;
  762. else if (c != '-' && c != ' ')
  763. return false;
  764. if (hex.size() != 32)
  765. return false;
  766. for (std::size_t i = 0; i < 16; ++i)
  767. out[i] = (std::uint8_t) std::stoul (hex.substr (i * 2, 2), nullptr, 16);
  768. return true;
  769. }
  770. // "StEB" (four characters, as VST2 IDs are usually written) or a number ("0x53744542", "1400128834")
  771. bool parseVst2Id (const std::string& s, std::uint32_t& out)
  772. {
  773. if (s.size() == 4 && ! (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')))
  774. {
  775. out = ((std::uint32_t) (unsigned char) s[0] << 24) | ((std::uint32_t) (unsigned char) s[1] << 16)
  776. | ((std::uint32_t) (unsigned char) s[2] << 8) | (std::uint32_t) (unsigned char) s[3];
  777. return true;
  778. }
  779. try
  780. {
  781. std::size_t used = 0;
  782. const auto v = std::stoull (s, &used, 0);
  783. if (used != s.size() || v > 0xFFFFFFFFull)
  784. return false;
  785. out = (std::uint32_t) v;
  786. return true;
  787. }
  788. catch (...)
  789. {
  790. return false;
  791. }
  792. }
  793. // "<source> -> <target> [| inLo inHi outLo outHi]"; source = vst2:<n> | xml:<attribute> | waves:<n>; target =
  794. // "mix" or a parameter name of the LYNX effect
  795. bool parseMap (const std::string& text, EffectKind kind, SubstituteParamMap& out)
  796. {
  797. const auto arrow = text.find ("->");
  798. if (arrow == std::string::npos)
  799. return false;
  800. const auto source = trim (std::string_view (text).substr (0, arrow));
  801. auto rest = std::string (text.substr (arrow + 2));
  802. std::string range;
  803. if (const auto bar = rest.find ('|'); bar != std::string::npos)
  804. {
  805. range = rest.substr (bar + 1);
  806. rest = rest.substr (0, bar);
  807. }
  808. const auto target = trim (rest);
  809. const auto colon = source.find (':');
  810. if (colon == std::string::npos)
  811. return false;
  812. const auto type = lowerAscii (source.substr (0, colon));
  813. const auto arg = trim (std::string_view (source).substr (colon + 1));
  814. if (arg.empty())
  815. return false;
  816. if (type == "xml")
  817. {
  818. out.source = SubstituteParamMap::Source::xml;
  819. out.attribute = arg;
  820. }
  821. else if (type == "vst2" || type == "waves")
  822. {
  823. out.source = type == "vst2" ? SubstituteParamMap::Source::vst2 : SubstituteParamMap::Source::waves;
  824. float index = 0;
  825. if (! parseFloat (arg, index) || index < 0 || index != std::floor (index))
  826. return false;
  827. out.index = (int) index;
  828. }
  829. else
  830. return false;
  831. if (target == "mix") // lower case: the slot's dry/wet ("Mix" is an effect parameter, e.g. of LYNX's reverbs)
  832. out.toSlotMix = true;
  833. else if ((out.target = paramNamed (kind, target)) < 0)
  834. return false;
  835. if (const auto words = splitList (range, ' '); ! words.empty() && (lowerAscii (words[0]) == "curve" || lowerAscii (words[0]) == "steps"))
  836. {
  837. out.shape = lowerAscii (words[0]) == "curve" ? SubstituteParamMap::Shape::curve : SubstituteParamMap::Shape::steps;
  838. for (std::size_t i = 1; i < words.size(); ++i)
  839. {
  840. const auto colon = words[i].find (':');
  841. float x = 0, y = 0;
  842. if (colon == std::string::npos || ! parseFloat (words[i].substr (0, colon), x) || ! parseFloat (words[i].substr (colon + 1), y))
  843. return false;
  844. if (! out.points.empty() && x <= out.points.back().first)
  845. return false; // x must ascend
  846. out.points.push_back ({ x, y });
  847. }
  848. return out.points.size() >= (out.shape == SubstituteParamMap::Shape::curve ? 2u : 1u);
  849. }
  850. if (! range.empty())
  851. {
  852. std::vector<float> v;
  853. for (const auto& token : splitList (range, ' '))
  854. {
  855. float f = 0;
  856. if (! parseFloat (token, f))
  857. return false;
  858. v.push_back (f);
  859. }
  860. if (v.size() != 4 || v[0] == v[1])
  861. return false;
  862. out.inLo = v[0];
  863. out.inHi = v[1];
  864. out.outLo = v[2];
  865. out.outHi = v[3];
  866. }
  867. return true;
  868. }
  869. std::vector<SubstituteEntry>& registry()
  870. {
  871. static std::vector<SubstituteEntry> entries = parseSubstituteTable (builtInTable);
  872. return entries;
  873. }
  874. std::size_t findBytes (const std::vector<std::uint8_t>& data, std::string_view what, std::size_t from = 0)
  875. {
  876. if (what.empty() || data.size() < what.size())
  877. return std::string::npos;
  878. for (std::size_t i = from; i + what.size() <= data.size(); ++i)
  879. if (std::memcmp (data.data() + i, what.data(), what.size()) == 0)
  880. return i;
  881. return std::string::npos;
  882. }
  883. std::string xmlUnescape (const std::string& s)
  884. {
  885. std::string out;
  886. for (std::size_t i = 0; i < s.size(); ++i)
  887. {
  888. if (s[i] != '&')
  889. {
  890. out += s[i];
  891. continue;
  892. }
  893. const auto end = s.find (';', i);
  894. if (end == std::string::npos)
  895. {
  896. out += s[i];
  897. continue;
  898. }
  899. const auto entity = s.substr (i + 1, end - i - 1);
  900. if (entity == "amp") out += '&';
  901. else if (entity == "lt") out += '<';
  902. else if (entity == "gt") out += '>';
  903. else if (entity == "quot") out += '"';
  904. else if (entity == "apos") out += '\'';
  905. else
  906. {
  907. out += s.substr (i, end - i + 1);
  908. }
  909. i = end;
  910. }
  911. return out;
  912. }
  913. // the text of the active setup's <Parameters> block of a Waves preset chunk
  914. std::string wavesParametersText (const std::vector<std::uint8_t>& state)
  915. {
  916. const auto start = findBytes (state, "<PresetChunkXMLTree");
  917. if (start == std::string::npos)
  918. return {};
  919. const std::string xml (state.begin() + (std::ptrdiff_t) start, state.end());
  920. std::string setup = "SETUP_A";
  921. if (const auto a = xml.find ("<ActiveSetup>"); a != std::string::npos)
  922. if (const auto b = xml.find ("</ActiveSetup>", a); b != std::string::npos)
  923. setup = trim (std::string_view (xml).substr (a + 13, b - a - 13));
  924. const auto data = xml.find ("<PresetData Setup=\"" + setup + "\"");
  925. if (data == std::string::npos)
  926. return {};
  927. const auto params = xml.find ("<Parameters", data);
  928. if (params == std::string::npos)
  929. return {};
  930. const auto open = xml.find ('>', params);
  931. const auto close = xml.find ("</Parameters>", params);
  932. if (open == std::string::npos || close == std::string::npos || close < open)
  933. return {};
  934. return xml.substr (open + 1, close - open - 1);
  935. }
  936. float mapValue (const SubstituteParamMap& m, double value)
  937. {
  938. if (m.shape == SubstituteParamMap::Shape::steps)
  939. {
  940. auto y = m.points.front().second;
  941. for (const auto& [px, py] : m.points)
  942. if (value >= (double) px - 1e-6)
  943. y = py;
  944. return std::clamp (y, 0.0f, 1.0f);
  945. }
  946. if (m.shape == SubstituteParamMap::Shape::curve)
  947. {
  948. const auto& p = m.points;
  949. if (value <= (double) p.front().first)
  950. return std::clamp (p.front().second, 0.0f, 1.0f);
  951. for (std::size_t i = 1; i < p.size(); ++i)
  952. if (value <= (double) p[i].first)
  953. {
  954. const auto t = (value - (double) p[i - 1].first) / ((double) p[i].first - (double) p[i - 1].first);
  955. return std::clamp ((float) ((double) p[i - 1].second + t * ((double) p[i].second - (double) p[i - 1].second)), 0.0f, 1.0f);
  956. }
  957. return std::clamp (p.back().second, 0.0f, 1.0f);
  958. }
  959. auto u = (value - (double) m.inLo) / ((double) m.inHi - (double) m.inLo);
  960. u = std::clamp (u, 0.0, 1.0);
  961. return (float) ((double) m.outLo + u * ((double) m.outHi - (double) m.outLo));
  962. }
  963. // --- binary writer / reader for foreignToText ----------------------------------------------------------------------
  964. void putU32 (std::vector<std::uint8_t>& out, std::uint32_t v)
  965. {
  966. for (int i = 0; i < 4; ++i)
  967. out.push_back ((std::uint8_t) (v >> (8 * i)));
  968. }
  969. void putBytes (std::vector<std::uint8_t>& out, const std::uint8_t* p, std::size_t n)
  970. {
  971. putU32 (out, (std::uint32_t) n);
  972. out.insert (out.end(), p, p + n);
  973. }
  974. void putString (std::vector<std::uint8_t>& out, const std::string& s)
  975. {
  976. putBytes (out, (const std::uint8_t*) s.data(), s.size());
  977. }
  978. struct BinReader
  979. {
  980. const std::vector<std::uint8_t>& d;
  981. std::size_t pos = 0;
  982. bool ok = true;
  983. std::uint32_t u32()
  984. {
  985. if (pos + 4 > d.size())
  986. {
  987. ok = false;
  988. return 0;
  989. }
  990. std::uint32_t v = 0;
  991. for (int i = 0; i < 4; ++i)
  992. v |= (std::uint32_t) d[pos + (std::size_t) i] << (8 * i);
  993. pos += 4;
  994. return v;
  995. }
  996. std::vector<std::uint8_t> bytes()
  997. {
  998. const auto n = u32();
  999. if (! ok || n > d.size() - pos)
  1000. {
  1001. ok = false;
  1002. return {};
  1003. }
  1004. std::vector<std::uint8_t> v (d.begin() + (std::ptrdiff_t) pos, d.begin() + (std::ptrdiff_t) (pos + n));
  1005. pos += n;
  1006. return v;
  1007. }
  1008. std::string str()
  1009. {
  1010. const auto b = bytes();
  1011. return std::string (b.begin(), b.end());
  1012. }
  1013. };
  1014. constexpr std::uint32_t foreignTextMagic = 0x31464C4Cu; // "LLF1"
  1015. // --- translators of states whose layout is readable without a vendor library (round 113) ------------------------
  1016. using RawTranslator = int (*) (const std::vector<std::uint8_t>& state, EffectSlot& slot);
  1017. // Auto-Tune Pro: key and scale (autoTuneProKey) and the Auto-mode controls of its ParamsData (autoTuneProParams;
  1018. // [EXEC] REA round 120 §5: the X<n> entries are the plugin's parameter n in real units — 4 Retune Speed (ms),
  1019. // 61 Humanize, 90 Flex-Tune (0…100)). Measured black-box on the official trial: a held note is pulled to its target
  1020. // along a first-order curve whose time constant is 1.36 × the retune speed − 3 ms (LYNX Tune's retune is that time
  1021. // constant); Humanize and Flex-Tune map 1:1 onto LYNX Tune's (fitted to the same measurements, LynxTune.cpp).
  1022. // Round 127 (docs/specs/auto-tune-pro.md §3, §7.5): the remaining cheap controls, units from the trial's own
  1023. // parameter texts — X3 Detune (cents, A4 = 440·2^(c/1200); LYNX Tune's reference reaches ±39 c), X74 Transpose
  1024. // (semitones), X92 Wet-Dry Mix (%), X10 Input Type (Soprano, Alto-Tenor, Low Male, Instrument, Bass Instrument →
  1025. // LYNX Tune's ranges, the two instrument types on Instrument), X70 Formant Correction off → formants move with the
  1026. // pitch, X71 Throat Length (%: a longer modelled tract lowers the formants, −12·log2(L/100) semitones [model]),
  1027. // X11 Classic mode ("Auto-Tune 5": no formant correction, no Flex-Tune — the manual) and X9 Tracking (50 = LYNX
  1028. // Tune's default strictness; the rest of the law [model]). All 143 states of her main projects use Detune 0,
  1029. // Transpose 0, Mix 100 %, Alto-Tenor, Throat 100 %, Tracking 50 (round 120 §5), so these only matter elsewhere.
  1030. // Without a readable key the slot keeps the entry's gentle preset.
  1031. int translateAutoTuneEfx (const std::vector<std::uint8_t>& state, EffectSlot& slot);
  1032. std::string attributeIn (const std::string& text, std::size_t from, const std::string& name);
  1033. int translateAutoTunePro (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1034. {
  1035. if (slot.kind != EffectKind::lynxTune)
  1036. return 0;
  1037. if (const auto efx = translateAutoTuneEfx (state, slot); efx > 0)
  1038. return efx;
  1039. const auto key = autoTuneProKey (state);
  1040. if (! key)
  1041. return 0;
  1042. slot.params[lynxtune::key] = (float) key->first / 11.0f;
  1043. if (key->second >= vocal::scaleCount) // whole tone / diminished (round 138: modern scale lists): "More scales"
  1044. {
  1045. slot.params[lynxtune::scale] = 0.0f;
  1046. slot.params[lynxtune::moreScales] = key->second == (int) vocal::Scale::wholeTone ? 0.5f : 1.0f;
  1047. }
  1048. else
  1049. slot.params[lynxtune::scale] = (float) key->second / (float) (vocal::scaleCount - 1);
  1050. const auto x = autoTuneProParams (state);
  1051. auto has = [&x] (int n) {
  1052. const auto it = x.find (n);
  1053. return it != x.end() && std::isfinite (it->second);
  1054. };
  1055. auto at = [&x, &has] (int n, double fallback) { return has (n) ? x.at (n) : fallback; };
  1056. int n = 2;
  1057. auto set = [&slot, &n] (int param, double v) {
  1058. slot.params[(std::size_t) param] = (float) std::clamp (v, 0.0, 1.0);
  1059. ++n;
  1060. };
  1061. const auto retune = std::clamp (at (4, 20.0), 0.0, 400.0);
  1062. set (lynxtune::retune, std::sqrt (std::clamp (1.36 * retune - 3.0, 0.0, 400.0) / 400.0));
  1063. set (lynxtune::humanize, at (61, 0.0) / 100.0);
  1064. const auto classic = at (11, 0.0) >= 0.5;
  1065. set (lynxtune::flexTune, classic ? 0.0 : at (90, 0.0) / 100.0);
  1066. if (has (3))
  1067. set (lynxtune::reference, (440.0 * std::exp2 (std::clamp (at (3, 0.0), -100.0, 100.0) / 1200.0) - 430.0) / 20.0);
  1068. if (has (74) && ! classic)
  1069. set (lynxtune::transpose, (std::clamp (std::round (at (74, 0.0)), -12.0, 12.0) + 12.0) / 24.0);
  1070. if (has (92))
  1071. set (lynxtune::mix, at (92, 100.0) / 100.0);
  1072. if (has (10))
  1073. {
  1074. static constexpr int rangeOf[5] { 0, 1, 2, 3, 3 };
  1075. set (lynxtune::range, rangeOf[std::clamp ((int) std::lround (at (10, 1.0)), 0, 4)] / (double) (lynxtune::rangeCount - 1));
  1076. }
  1077. if (has (70) || classic)
  1078. set (lynxtune::formantPreserve, ! classic && at (70, 1.0) >= 0.5 ? 1.0 : 0.0);
  1079. if (has (71) && ! classic && at (70, 1.0) >= 0.5)
  1080. {
  1081. // round 138 (REA_rodada138 §3.4, [EXEC] the vowel envelopes of the official trial at throat 50 … 180 %): the formants
  1082. // move −0.0146·(L − 100)^1.4 semitones for a longer throat (−3.5 at 150 %, −6.8 at 180 %) and about
  1083. // +0.03·(100 − L)^1.4 for a shorter one (+2.7 at 75 %) — about half of the old −12·log2 (L / 100) model
  1084. const auto L = std::clamp (at (71, 100.0), 50.0, 180.0);
  1085. const auto st = L >= 100.0 ? -0.0146 * std::pow (L - 100.0, 1.4) : 0.03 * std::pow (100.0 - L, 1.4);
  1086. set (lynxtune::formantShift, st / 14.0 + 0.5);
  1087. }
  1088. if (has (9))
  1089. set (lynxtune::tracking, std::clamp (at (9, 50.0), 1.0, 100.0) * 0.4 / 50.0);
  1090. // round 128: natural vibrato (X62, dB), ignore vibrato (X44), Create Vibrato (X5 shape, X7 rate, X6 cents, X46 / X50
  1091. // onset delay / rate, ms) and the active scale's per-note Bypass / Remove edits (autoTuneProNoteEdits)
  1092. if (has (62)) set (lynxtune::naturalVibrato, at (62, 0.0) / 24.0 + 0.5);
  1093. if (has (44)) set (lynxtune::ignoreVibrato, at (44, 0.0) >= 0.5 ? 1.0 : 0.0);
  1094. if (has (5)) set (lynxtune::vibratoShape, std::clamp (std::round (at (5, 0.0)), 0.0, 3.0) / 3.0);
  1095. if (has (7)) set (lynxtune::vibratoRate, (at (7, 5.5) - 0.1) / 9.9);
  1096. if (has (6)) set (lynxtune::vibratoDepth, at (6, 18.0) / 100.0);
  1097. if (has (46)) set (lynxtune::vibratoDelay, at (46, 500.0) / 1500.0);
  1098. if (has (50)) set (lynxtune::vibratoOnset, at (50, 500.0) / 1500.0);
  1099. if (const auto edits = autoTuneProNoteEdits (state, key->first, key->second))
  1100. for (int k = 0; k < 12; ++k)
  1101. {
  1102. set (lynxtune::noteC + k, ((edits->second >> k) & 1u) != 0 ? 0.0 : 1.0);
  1103. set (lynxtune::bypassC + k, ((edits->first >> k) & 1u) != 0 ? 1.0 : 0.0);
  1104. }
  1105. return n;
  1106. }
  1107. // Auto-Tune EFX+ (round 127; [DATA] her 6 states, 17 slots): an "<AUTOTUNEEFXPLUS>" element of <PARAM id="p…"
  1108. // value="…"/> in real units. pKey 0…11, pScale (0 Major, 1 Minor, 2 Chromatic — the same list as Auto-Tune Pro: every
  1109. // pScale 2 state has all twelve notes on, every pScale 1 state on key 11 holds B minor's notes), pNoteC … pNoteB = the
  1110. // notes that are targets (absolute pitch classes; one state adds F to B minor), pRetuneSpeed (ms, read with Auto-Tune
  1111. // Pro's law [model: not measured on EFX+]), pHumanize, pPitchShift (semitones), pFormant, pThroatLength (%),
  1112. // pInputType, pDryWetMix (%). Its multi-effect chain (Duet, Tube, Mutate, Vocode, filters) and Auto-Motion patterns
  1113. // have no LYNX Tune equivalent and are left out.
  1114. int translateAutoTuneEfx (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1115. {
  1116. const auto root = findBytes (state, "<AUTOTUNEEFXPLUS");
  1117. if (root == std::string::npos || slot.kind != EffectKind::lynxTune)
  1118. return 0;
  1119. const std::string text (state.begin() + (std::ptrdiff_t) root, state.end());
  1120. std::map<std::string, double> v;
  1121. for (auto p = text.find ("<PARAM "); p != std::string::npos; p = text.find ("<PARAM ", p + 7))
  1122. {
  1123. const auto id = attributeIn (text, p, "id");
  1124. float value = 0;
  1125. if (! id.empty() && parseFloat (attributeIn (text, p, "value"), value) && std::isfinite (value))
  1126. v[id] = value;
  1127. }
  1128. auto at = [&v] (const char* id, double fallback) {
  1129. const auto it = v.find (id);
  1130. return it != v.end() ? it->second : fallback;
  1131. };
  1132. if (v.find ("pKey") == v.end() || v.find ("pScale") == v.end())
  1133. return 0;
  1134. const int key = std::clamp ((int) std::lround (at ("pKey", 0.0)), 0, 11);
  1135. static constexpr const char* notes[12] { "pNoteC", "pNoteC#", "pNoteD", "pNoteD#", "pNoteE", "pNoteF",
  1136. "pNoteF#", "pNoteG", "pNoteG#", "pNoteA", "pNoteA#", "pNoteB" };
  1137. std::uint16_t mask = 0;
  1138. for (int k = 0; k < 12; ++k)
  1139. if (at (notes[k], 1.0) >= 0.5)
  1140. mask = (std::uint16_t) (mask | (1u << k));
  1141. const int theirs = (int) std::lround (at ("pScale", 2.0));
  1142. auto scale = theirs == 0 ? vocal::Scale::major : (theirs == 1 ? vocal::Scale::minor : vocal::Scale::chromatic);
  1143. if (mask == 0)
  1144. mask = 0xfff;
  1145. if (vocal::scaleMask (scale, key) != mask)
  1146. scale = vocal::Scale::custom; // the note switches carry the exact targets
  1147. auto& p = slot.params;
  1148. p[lynxtune::key] = (float) key / 11.0f;
  1149. p[lynxtune::scale] = (float) (int) scale / (float) (vocal::scaleCount - 1);
  1150. for (int k = 0; k < 12; ++k)
  1151. p[(std::size_t) (lynxtune::noteC + k)] = ((mask >> k) & 1u) != 0 ? 1.0f : 0.0f;
  1152. const auto retune = std::clamp (at ("pRetuneSpeed", 20.0), 0.0, 400.0);
  1153. p[lynxtune::retune] = (float) std::sqrt (std::clamp (1.36 * retune - 3.0, 0.0, 400.0) / 400.0);
  1154. p[lynxtune::humanize] = (float) std::clamp (at ("pHumanize", 0.0) / 100.0, 0.0, 1.0);
  1155. p[lynxtune::flexTune] = 0.0f;
  1156. p[lynxtune::transpose] = (float) ((std::clamp (std::round (at ("pPitchShift", 0.0)), -12.0, 12.0) + 12.0) / 24.0);
  1157. const auto formant = at ("pFormant", 1.0) >= 0.5;
  1158. p[lynxtune::formantPreserve] = formant ? 1.0f : 0.0f;
  1159. p[lynxtune::formantShift] = formant ? (float) std::clamp (-12.0 * std::log2 (std::clamp (at ("pThroatLength", 100.0), 50.0, 180.0) / 100.0) / 14.0 + 0.5, 0.0, 1.0) : 0.5f;
  1160. static constexpr int rangeOf[5] { 0, 1, 2, 3, 3 };
  1161. p[lynxtune::range] = (float) rangeOf[std::clamp ((int) std::lround (at ("pInputType", 1.0)), 0, 4)] / (float) (lynxtune::rangeCount - 1);
  1162. p[lynxtune::mix] = (float) std::clamp (at ("pDryWetMix", 100.0) / 100.0, 0.0, 1.0);
  1163. return 23;
  1164. }
  1165. // Waves Tune Real-Time: the key and scale saved in its state (wavesTuneScale; [DATA] every one of the 11 distinct
  1166. // states of her corpus names its scale — "Natural Minor" / "Major" — with the root and the twelve note statuses);
  1167. // a scale LYNX Tune has no name for becomes its custom scale with the same notes. RealWorld 20 = Speed, 21 = Note
  1168. // Transition (ms). [EXEC] Black-box (official trial, REA round 120 §2): a held mistuned note is pulled to the target
  1169. // along a first-order curve whose time constant is the Note Transition time (50 % / 90 % at 12 ms + 0.69 / 2.3 x NT for
  1170. // NT = 21 … 250 ms), which is LYNX Tune's retune law at retune = NT; Speed barely changes anything on sung notes (only
  1171. // below ~5 ms, slightly less vibrato), so it is not translated; no humanize.
  1172. std::optional<double> wavesValue (const std::vector<double>& rw, std::size_t i);
  1173. int translateWavesTune (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1174. {
  1175. if (slot.kind != EffectKind::lynxTune)
  1176. return 0;
  1177. int n = 0;
  1178. if (const auto sc = wavesTuneScale (state))
  1179. {
  1180. slot.params[lynxtune::key] = (float) sc->key / 11.0f;
  1181. slot.params[lynxtune::scale] = (float) sc->scale / (float) (vocal::scaleCount - 1);
  1182. for (int k = 0; k < 12; ++k)
  1183. slot.params[(std::size_t) (lynxtune::noteC + k)] = sc->scale != (int) vocal::Scale::custom || ((sc->mask >> k) & 1u) != 0 ? 1.0f : 0.0f;
  1184. n += 2;
  1185. }
  1186. const auto rw = wavesRealWorldParams (state);
  1187. if (const auto transition = wavesValue (rw, 21); transition && *transition >= 0.0)
  1188. {
  1189. slot.params[lynxtune::retune] = (float) std::sqrt (std::clamp (*transition, 0.0, 400.0) / 400.0);
  1190. slot.params[lynxtune::humanize] = 0.0f;
  1191. n += 2;
  1192. }
  1193. // round 135w: Speed is shown as saved; it only acts (Link off) where the trial showed an effect (below ~5 ms)
  1194. if (const auto speed = wavesValue (rw, 20); speed && *speed > 0.0)
  1195. {
  1196. slot.params[lynxtune::speed] = lynxtune::speedValue (*speed);
  1197. slot.params[lynxtune::speedLink] = *speed < 5.0 ? 0.0f : 1.0f;
  1198. ++n;
  1199. }
  1200. // RealWorld 22 = 100 in every state of her corpus, Correction % by its default [model]
  1201. if (const auto amount = wavesValue (rw, 22); amount && *amount >= 1.0 && *amount <= 100.0)
  1202. slot.params[lynxtune::correction] = (float) (*amount / 100.0);
  1203. return n;
  1204. }
  1205. // Fresh Air: its two air amounts drive Aether's dynamic air model (round 124), which reproduces the official trial
  1206. // measured black-box (docs/analise/REA_rodada124.md §3): the same two parallel compressed high-passed bands, the same
  1207. // amount laws, so the amounts map one to one; Trim (the float at 2526 of the state, -12 … 0 dB) becomes the output.
  1208. // (Round 113 fitted a static shelf; the original is level-dependent: quiet highs get up to +12 dB, loud ones +3.)
  1209. int translateFreshAir (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1210. {
  1211. namespace a = mixsuite::aether;
  1212. const auto air = freshAirAmounts (state);
  1213. if (! air || slot.kind != EffectKind::aether)
  1214. return 0;
  1215. slot.params[a::dynamic] = 1.0f;
  1216. slot.params[a::midAir] = air->first;
  1217. slot.params[a::highAir] = air->second;
  1218. slot.params[a::air] = 0.0f;
  1219. slot.params[a::harmonics] = 0.0f;
  1220. slot.params[a::mix] = 1.0f;
  1221. float trimDb = 0.0f;
  1222. std::memcpy (&trimDb, state.data() + 2526, 4);
  1223. if (! std::isfinite (trimDb) || trimDb < -12.0f || trimDb > 0.0f)
  1224. trimDb = 0.0f;
  1225. slot.params[a::output] = (trimDb + 12.0f) / 24.0f;
  1226. return 3;
  1227. }
  1228. // --- Waves RealWorld lists (round 113). [EXEC] Black-box measurement of the official trials (WaveShell 17.1, tools/
  1229. // fxmeasure, headless): each control was moved alone and the value of the list that followed it (and its text) was
  1230. // recorded; then the plugin at her projects' states and LYNX's substitute were run on the same sine stairs (1 and
  1231. // 6 kHz, -60 .. 0 dBFS) and vocal takes and the substitute fitted (docs/analise/REA_rodada113.md §3c).
  1232. // The value at `i`, or nothing when the list is shorter / holds "*"
  1233. std::optional<double> wavesValue (const std::vector<double>& rw, std::size_t i)
  1234. {
  1235. if (i < rw.size() && std::isfinite (rw[i]))
  1236. return rw[i];
  1237. return std::nullopt;
  1238. }
  1239. float logNorm (double v, double lo, double hi) { return (float) std::clamp (std::log (v / lo) / std::log (hi / lo), 0.0, 1.0); }
  1240. float linNorm (double v, double lo, double hi) { return (float) std::clamp ((v - lo) / (hi - lo), 0.0, 1.0); }
  1241. // Renaissance Compressor (28 values): 0 release ms, 1 threshold dB, 2 gain dB, 8 attack ms, 9 ratio, 17 ARC (0) / manual,
  1242. // 26 mix %, 27 trim dB.
  1243. // Round 123: Compressor's "vintage program" voicing is the compressor measured black-box on the official trial at her
  1244. // state (core/VoiceMatch.h; REA_rodada123 §3), taking threshold, ratio, attack, release and gain as they are.
  1245. int translateWavesRComp (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1246. {
  1247. const auto rw = wavesRealWorldParams (state);
  1248. const auto threshold = wavesValue (rw, 1), ratio = wavesValue (rw, 9);
  1249. if (slot.kind != EffectKind::compressor || ! threshold || ! ratio)
  1250. return 0;
  1251. slot.params[0] = linNorm (*threshold, -60.0, 0.0);
  1252. slot.params[1] = linNorm (*ratio, 1.0, 20.0);
  1253. slot.params[2] = logNorm (wavesValue (rw, 8).value_or (0.5), 0.1, 100.0);
  1254. slot.params[3] = logNorm (wavesValue (rw, 0).value_or (160.0), 10.0, 1000.0);
  1255. slot.params[4] = linNorm (wavesValue (rw, 2).value_or (0.0), 0.0, 24.0);
  1256. slot.params[5] = 0.0f;
  1257. slot.params[6] = (float) std::clamp (wavesValue (rw, 26).value_or (100.0) / 100.0, 0.0, 1.0); // mix %
  1258. slot.params[7] = linNorm (wavesValue (rw, 27).value_or (0.0), -18.0, 18.0); // trim dB
  1259. slot.params[8] = 1.0f; // vintage voicing
  1260. // round 135w: ARC / Manual (17), Electro / Opto (22), Warm / Smooth (16) [EXEC round 113 list]; the output limiter
  1261. // the reference always has
  1262. slot.params[9] = wavesValue (rw, 17).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1263. slot.params[10] = wavesValue (rw, 22).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1264. slot.params[11] = wavesValue (rw, 16).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1265. slot.params[12] = 1.0f;
  1266. // round 150: the reference's own ranges (Compressor's "Ranges = RComp" and its RC parameters, REA_rodada150 §6):
  1267. // ratio 0.5 … 50 (below 1 expands), gain −30 … +30, attack 0.5 … 500 ms, release 5 … 5000 ms, as they are
  1268. const auto r = std::clamp (*ratio, 0.5, 50.0);
  1269. slot.params[13] = 1.0f;
  1270. slot.params[14] = (float) (r >= 1.0 ? 0.625 * (1.0 - std::log (r) / std::log (50.0)) : 0.625 + 0.375 * std::log (r) / std::log (0.5));
  1271. slot.params[15] = linNorm (wavesValue (rw, 2).value_or (0.0), -30.0, 30.0);
  1272. slot.params[16] = logNorm (wavesValue (rw, 8).value_or (16.0), 0.5, 500.0);
  1273. slot.params[17] = logNorm (wavesValue (rw, 0).value_or (160.0), 5.0, 5000.0);
  1274. return 6;
  1275. }
  1276. // DeEsser (15 values): 0 frequency Hz, 2 threshold dB, 10 monitor (1 = side chain), 13 side chain (1 = high pass,
  1277. // 2 = band pass), 14 audio (0 = split, 1 = wideband). Round 123: Hush's "classic split" voicing is the de-esser measured
  1278. // black-box on the official trial (core/VoiceMatch.h; REA_rodada123 §2), so the controls map one to one.
  1279. int translateWavesDeEsser (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1280. {
  1281. namespace h = mixsuite::hush;
  1282. const auto rw = wavesRealWorldParams (state);
  1283. const auto hz = wavesValue (rw, 0);
  1284. if (slot.kind != EffectKind::hushDeEsser || ! hz)
  1285. return 0;
  1286. int n = 1;
  1287. slot.params[h::voicing] = 1.0f;
  1288. slot.params[h::frequency] = logNorm (*hz, 2000.0, 16000.0);
  1289. slot.params[h::output] = 0.5f;
  1290. if (const auto t = wavesValue (rw, 2))
  1291. slot.params[h::threshold] = linNorm (*t, -80.0, 0.0), ++n;
  1292. if (const auto m = wavesValue (rw, 14))
  1293. slot.params[h::mode] = *m >= 0.5 ? 1.0f : 0.0f, ++n;
  1294. if (const auto d = wavesValue (rw, 13))
  1295. // round 165 [EXEC]: the 17.1 trial stores HighPass 1 / BandPass 0 (band-pass states were read as high-pass); 2 =
  1296. // band-pass as before
  1297. slot.params[h::detector] = (*d < 0.5 || *d >= 1.5) ? 1.0f : 0.0f, ++n;
  1298. if (const auto l = wavesValue (rw, 10))
  1299. slot.params[h::listen] = *l >= 0.5 ? 1.0f : 0.0f, ++n;
  1300. return n;
  1301. }
  1302. // CLA-2A (208 values): 38 gain, 74 peak reduction, 112 comp (0) / limit, 153 Hi Freq, 206 trim dB. Round 123: Glow
  1303. // Leveler's "opto classic" voicing is the leveler measured black-box on the official trial (core/VoiceMatch.h;
  1304. // REA_rodada123 §4), where the dials read 0 .. 100 like the original's, so they map one to one.
  1305. int translateWavesCla2a (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1306. {
  1307. namespace g = mixsuite::glow;
  1308. const auto rw = wavesRealWorldParams (state);
  1309. const auto gain = wavesValue (rw, 38), reduction = wavesValue (rw, 74);
  1310. if (slot.kind != EffectKind::glowLeveler || ! gain || ! reduction)
  1311. return 0;
  1312. slot.params[g::voicing] = 1.0f;
  1313. slot.params[g::gain] = (float) std::clamp (*gain / 100.0, 0.0, 1.0);
  1314. slot.params[g::peakReduction] = (float) std::clamp (*reduction / 100.0, 0.0, 1.0);
  1315. slot.params[g::mode] = wavesValue (rw, 112).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1316. slot.params[g::emphasis] = (float) std::clamp (wavesValue (rw, 153).value_or (50.0) / 100.0, 0.0, 1.0);
  1317. slot.params[g::trim] = linNorm (wavesValue (rw, 206).value_or (0.0), -18.0, 18.0);
  1318. // round 152 [EXEC] (REA_rodada152a §2, read back through the trial's own parameters): 204 Mix %, 207 Auto Makeup,
  1319. // 140 Analog (0 = 50 Hz, 1 = 60 Hz, 2 = off)
  1320. slot.params[g::mix] = (float) std::clamp (wavesValue (rw, 204).value_or (100.0) / 100.0, 0.0, 1.0);
  1321. slot.params[g::autoMakeup] = wavesValue (rw, 207).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1322. const auto analog = std::lround (wavesValue (rw, 140).value_or (2.0));
  1323. slot.params[g::analog] = analog == 0 ? 0.5f : analog == 1 ? 1.0f : 0.0f;
  1324. slot.params[g::optoLaw] = 1.0f;
  1325. return 8;
  1326. }
  1327. // CLA-76 (106 values): 0 / 1 Input / Output as positive dB magnitudes (−0 … −∞ dB), 2 / 3 Attack / Release knobs
  1328. // 1 … 7, 59 Ratio (0 = 20, 1 = 12, 2 = 8, 3 = 4, 4 = all buttons), 103 Mix %. [EXEC] Read back through the trial's own
  1329. // parameter API with her state loaded (REA_rodada127 §3). Her only state was rendered on the official trial (mix 0 /
  1330. // 100 / 41.3 %: the mix is a linear dry / wet blend, the dry path is exact) and Crest fitted to its wet path: Bus
  1331. // style, threshold −43.7 dB, 7.1:1, 9.3 dB knee, 31.9 dB range (the FET's gain-reduction ceiling), attack 5.9 ms,
  1332. // release 97 ms, +31.6 dB (the all-buttons wet path's small-signal gain) — on her take the null went from −11.5 dB
  1333. // (2:1 Compressor) to −19.9 dB. Other settings move around that point by the manual's laws [model]: the input level
  1334. // moves the threshold and the wet gain dB for dB, the output the wet gain, attack 800 → 20 µs and release
  1335. // 1100 → 50 ms log-spaced over the knobs 1 … 7, the ratio buttons as labelled; the mix becomes the slot's dry / wet.
  1336. // Round 148 (the Waves trial in full, no demo mutes; REA_rodada148 §5): her state re-rendered on her three whole takes
  1337. // and Crest refitted on them (Nelder–Mead on the waveform null): threshold −55.4 dB, 2.8:1 (all buttons), knee 24.8 dB,
  1338. // range 31.5 dB, attack 1.56 ms, release 2.5 s (Crest's longest: the reference's all-buttons release is slow) — null
  1339. // go / kwe / lu −13.0 / −7.9 / −10.2 → −25.4 / −19.2 / −21.8 dB, 1/3-octave error 3.3–3.9 → 0.5–1.0 dB.
  1340. int translateWavesCla76 (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1341. {
  1342. namespace c = dyn::crest;
  1343. const auto rw = wavesRealWorldParams (state);
  1344. const auto in = wavesValue (rw, 0), out = wavesValue (rw, 1);
  1345. if (slot.kind != EffectKind::crestCompressor || ! in || ! out)
  1346. return 0;
  1347. const auto at = [&] (std::size_t i, double fallback) { return wavesValue (rw, i).value_or (fallback); };
  1348. const auto inDb = -std::clamp (*in, 0.0, 120.0), outDb = -std::clamp (*out, 0.0, 120.0);
  1349. const auto attackKnob = std::clamp (at (2, 3.0), 1.0, 7.0), releaseKnob = std::clamp (at (3, 4.0), 1.0, 7.0);
  1350. const auto attackLaw = [] (double k) { return 0.8 * std::pow (0.02 / 0.8, (k - 1.0) / 6.0); };
  1351. const auto releaseLaw = [] (double k) { return 1100.0 * std::pow (50.0 / 1100.0, (k - 1.0) / 6.0); };
  1352. static constexpr double ratios[5] { 20.0, 12.0, 8.0, 4.0, 2.8 };
  1353. const int ratioIndex = std::clamp ((int) std::lround (at (59, 3.0)), 0, 4);
  1354. auto& p = slot.params;
  1355. p[c::style] = c::styleValue (c::Style::bus);
  1356. p[c::threshold] = linNorm (-55.4 - (inDb + 8.7), -60.0, 0.0);
  1357. p[c::ratio] = c::ratioValue (ratios[ratioIndex]);
  1358. p[c::knee] = linNorm (24.8, 0.0, 72.0);
  1359. p[c::range] = linNorm (31.5, 0.0, 60.0);
  1360. p[c::attack] = c::attackValue (1.56 * attackLaw (attackKnob) / attackLaw (4.3));
  1361. p[c::release] = c::releaseValue (std::min (2500.0, 2500.0 * releaseLaw (releaseKnob) / releaseLaw (4.31)));
  1362. p[c::autoRelease] = 0.0f;
  1363. p[c::autoGain] = 0.0f;
  1364. p[c::mix] = 1.0f;
  1365. p[c::output] = linNorm (31.5 + (inDb + 8.7) + (outDb + 16.9), -36.0, 36.0);
  1366. slot.mix = (float) std::clamp (at (103, 100.0) / 100.0, 0.0, 1.0);
  1367. return 11;
  1368. }
  1369. // SSL Native Vocalstrip 2 (round 145): its state is XML with named parameters in the original's own units
  1370. // (<SSL_PLUGIN_STATE … StateASelected="1"><A><PROCESSOR_STATE><PARAM id="compThreshold" value="-33.2"/> …); the A or B
  1371. // setting that plays maps one to one onto Ridge Strip's Vocal strip voicing, which reproduces the official trial
  1372. // measured black-box (docs/analise/REA_rodada145.md §2). Other SSL Native strips keep Ridge's defaults.
  1373. int translateSslVocalstrip2 (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1374. {
  1375. namespace r = mixsuite::ridge;
  1376. namespace vs = voxstrip;
  1377. const auto root = findBytes (state, "<SSL_PLUGIN_STATE");
  1378. if (root == std::string::npos || slot.kind != EffectKind::ridgeStrip)
  1379. return 0;
  1380. const std::string text (state.begin() + (std::ptrdiff_t) root, state.end());
  1381. const auto plugin = attributeIn (text, 0, "PluginName");
  1382. const bool k4e = plugin.find ("4K E") != std::string::npos;
  1383. if (plugin.find ("Vocalstrip 2") == std::string::npos && ! k4e)
  1384. return 0;
  1385. const bool useB = attributeIn (text, 0, "StateASelected") == "0";
  1386. const auto block = text.find (useB ? "<B" : "<A");
  1387. if (block == std::string::npos)
  1388. return 0;
  1389. const auto blockEnd = text.find (useB ? "</B>" : "</A>", block);
  1390. std::map<std::string, double> v;
  1391. for (auto q = text.find ("<PARAM ", block); q != std::string::npos && q < blockEnd; q = text.find ("<PARAM ", q + 7))
  1392. {
  1393. const auto id = attributeIn (text, q, "id");
  1394. float value = 0;
  1395. if (! id.empty() && parseFloat (attributeIn (text, q, "value"), value) && std::isfinite (value))
  1396. v[id] = value;
  1397. }
  1398. if (v.size() < 10)
  1399. return 0;
  1400. auto at = [&v] (const char* id, double fallback) {
  1401. const auto it = v.find (id);
  1402. return it != v.end() ? it->second : fallback;
  1403. };
  1404. auto sw = [&at] (const char* id, bool fallback) { return at (id, fallback ? 1.0 : 0.0) >= 0.5 ? 1.0f : 0.0f; };
  1405. auto& p = slot.params;
  1406. if (k4e)
  1407. {
  1408. // round 148: SSL 4K E -> Ridge's 4K voicing, the controls in the original's units through Ridge's own laws
  1409. // (EQ and filter frequencies: LF in Hz, the others in kHz; HighPassFreq 10 = out, LowPassFreq 35 = out; CompRatio
  1410. // 40 = infinity; EqColour 0 / 1 / 2 = Brown / Black / Orange; SaturationIn / Amount = the mic pre and its gain).
  1411. // Not read: pan, width, the external key, filters / EQ to the side chain, filters to input, high quality
  1412. p[r::console4k] = 1.0f;
  1413. p[r::voicing] = 0.0f;
  1414. p[r::vocal] = 0.0f;
  1415. p[r::input] = linNorm (at ("InputTrim", 0.0), -20.0, 20.0);
  1416. const auto fader = at ("FaderLevel", 0.0);
  1417. p[r::output] = linNorm (at ("OutputTrim", 0.0) + std::max (fader, -20.0), -20.0, 20.0);
  1418. p[r::phase] = sw ("PhaseInvert", false);
  1419. const auto hp = at ("HighPassFreq", 10.0), lp = at ("LowPassFreq", 35.0);
  1420. p[r::hpf] = hp < 16.5 ? 0.0f : std::max (1e-4f, logNorm (hp, 16.0, 350.0));
  1421. p[r::lpf] = lp > 15.95 ? 0.0f : std::max (1e-4f, logNorm (lp * 1000.0, 22000.0, 3000.0));
  1422. auto gain = [] (double db) { return linNorm (db, -15.0, 15.0); };
  1423. p[r::lfGain] = gain (at ("LowEqGain", 0.0));
  1424. p[r::lfFreq] = logNorm (at ("LowEqFreq", 200.0), 30.0, 450.0);
  1425. p[r::lfBell] = sw ("LowEqBell", false);
  1426. p[r::lmfGain] = gain (at ("LowMidEqGain", 0.0));
  1427. p[r::lmfFreq] = logNorm (at ("LowMidEqFreq", 1.0) * 1000.0, 200.0, 2500.0);
  1428. p[r::lmfQ] = r::k4QValue (at ("LowMidEqQ", 1.5));
  1429. p[r::hmfGain] = gain (at ("HighMidEqGain", 0.0));
  1430. p[r::hmfFreq] = logNorm (at ("HighMidEqFreq", 3.0) * 1000.0, 600.0, 7000.0);
  1431. p[r::hmfQ] = r::k4QValue (at ("HighMidEqQ", 1.5));
  1432. p[r::hfGain] = gain (at ("HighEqGain", 0.0));
  1433. p[r::hfFreq] = logNorm (at ("HighEqFreq", 8.0) * 1000.0, 1500.0, 16000.0);
  1434. p[r::hfBell] = sw ("HighEqBell", false);
  1435. p[r::eqOn] = sw ("EqIn", true);
  1436. p[r::k4Colour] = r::k4ColourValue ((int) std::lround (at ("EqColour", 0.0)));
  1437. const auto ratio = at ("CompRatio", 1.0);
  1438. p[r::compRatio] = ratio <= 1.0005 ? 0.0f : (ratio >= 30.0 ? 1.0f : (float) std::sqrt (std::clamp ((ratio - 1.0) / 19.0, 0.0, 0.996)));
  1439. p[r::compThreshold] = linNorm (at ("CompThreshold", 10.0), -20.0, 10.0);
  1440. p[r::compRelease] = logNorm (at ("CompRelease", 0.4), 0.1, 4.0);
  1441. p[r::compFastAttack] = sw ("CompFastAttack", false);
  1442. p[r::compMix] = (float) std::clamp (at ("CompMix", 100.0) / 100.0, 0.0, 1.0);
  1443. p[r::autoMakeup] = sw ("CompAutoMakeUp", true);
  1444. p[r::k4MakeupOffset] = linNorm (at ("CompAutoMakeUpCompensation", 0.0), -12.0, 12.0);
  1445. p[r::gateRange] = linNorm (at ("GateRange", 0.0), 0.0, 40.0);
  1446. p[r::gateThreshold] = linNorm (at ("GateThreshold", -30.0), -30.0, 10.0);
  1447. p[r::gateRelease] = logNorm (at ("GateRelease", 0.4), 0.1, 4.0);
  1448. p[r::gateFastAttack] = sw ("GateFastAttack", false);
  1449. p[r::expander] = sw ("GateExpander", false);
  1450. p[r::dynOn] = sw ("DynamicsIn", true);
  1451. p[r::order] = sw ("DynamicsPreEq", false);
  1452. p[r::k4Pre] = sw ("SaturationIn", false);
  1453. p[r::k4Mic] = linNorm (at ("SaturationAmount", 0.0), 0.0, 50.0);
  1454. p[r::analog] = sw ("AnalogueVca", true);
  1455. if (at ("Bypass", 0.0) >= 0.5)
  1456. slot.enabled = false;
  1457. return (int) v.size();
  1458. }
  1459. p[r::vocal] = 1.0f;
  1460. p[r::vInput] = vs::gainValue (at ("inputGain", 0.0));
  1461. p[r::vOutput] = vs::gainValue (at ("outputGain", 0.0));
  1462. p[r::vOrder] = (float) std::clamp (at ("processOrder", 0.0), 0.0, 1.0);
  1463. p[r::vDsOn] = sw ("dsOn", false);
  1464. p[r::vDsFreq] = vs::dsFreqValue (at ("dsFreq", 7500.0));
  1465. p[r::vDsThreshold] = vs::thresholdValue (at ("dsThreshold", -24.0));
  1466. p[r::vDsSplit] = sw ("dsSplit", true);
  1467. p[r::vDsLookahead] = sw ("dsLookAhead", false);
  1468. p[r::vDsListen] = sw ("dsAudition", false);
  1469. p[r::vDpOn] = sw ("dpOn", false);
  1470. p[r::vDpFreq] = vs::dpFreqValue (at ("dpFreq", 120.0));
  1471. p[r::vDpThreshold] = vs::thresholdValue (at ("dpThreshold", -24.0));
  1472. p[r::vDpSplit] = sw ("dpSplit", true);
  1473. p[r::vDpLookahead] = sw ("dpLookAhead", false);
  1474. p[r::vDpListen] = sw ("dpAudition", false);
  1475. p[r::vEqOn] = sw ("eqOn", false);
  1476. p[r::vHpfOn] = sw ("hpfOn", true);
  1477. p[r::vHpfFreq] = vs::hpfValue (at ("hpfFreq", 30.0));
  1478. p[r::vNotchOn] = sw ("notchOn", true);
  1479. p[r::vNotchFreq] = vs::notchValue (at ("notchFreq", 200.0));
  1480. p[r::vNotchGain] = vs::notchGainValue (at ("notchGain", 0.0));
  1481. p[r::vHighOn] = sw ("hsOn", true);
  1482. p[r::vHighFreq] = vs::highValue (at ("hsFreq", 1000.0));
  1483. p[r::vHighGain] = vs::highGainValue (at ("hsGain", 0.0));
  1484. p[r::vCompOn] = sw ("compOn", false);
  1485. p[r::vExpThreshold] = vs::expThresholdValue (at ("expThreshold", -96.0));
  1486. p[r::vCompThreshold] = vs::thresholdValue (at ("compThreshold", 0.0));
  1487. p[r::vRatio] = vs::ratioValue (at ("compRatio", 4.0));
  1488. p[r::vAttack] = vs::attackValue (at ("compAttack", 0.1));
  1489. p[r::vRelease] = vs::releaseValue (at ("compRelease", 100.0));
  1490. p[r::vMakeup] = vs::makeupValue (at ("compMakeup", 0.0));
  1491. p[r::vKnee] = sw ("compKnee", false);
  1492. p[r::vDrive] = sw ("compDrive", false);
  1493. if (at ("bypassAll", 0.0) >= 0.5)
  1494. slot.enabled = false;
  1495. return (int) v.size();
  1496. }
  1497. // SSL E-Channel (57 values; RW index: 0 comp threshold dB, 1 ratio, 2 fast (1 = on), 3 release s, 5 expander threshold,
  1498. // 6 range, 7 gate (1) / expander (0), 8 expander fast attack, 9 expander release, 11 dynamics bypass, 12 dynamics to
  1499. // channel out, 13 LF bell, 14/15 LF gain / Hz, 16/17/18 LMF gain / kHz / Q, 19/20/21 HMF, 22 HF bell, 23/24 HF gain / kHz,
  1500. // 25 EQ bypass, 26 EQ to dynamics side chain, 27 HP Hz (< 17 = out), 28 LP kHz (30 = out), 29 filter split (1 = on),
  1501. // 30 output dB, 31 analog, 39 phase, 40 input dB). Round 123: Ridge Strip's "E" voicing (core/VoiceMatch.h) is the
  1502. // console measured black-box on the official trial — every EQ band and filter from its impulse responses, the
  1503. // feedback compressor and expander from sine stairs, tone bursts, noise and her takes — so the controls map one to
  1504. // one in the console's own units (docs/analise/REA_rodada123.md). Round 147b: analog translated (off in every state of
  1505. // her corpus). Round 165: EQ to the dynamics side chain (Dyn S.C., RealWorld 26) translated.
  1506. int translateWavesSslChannel (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1507. {
  1508. namespace r = mixsuite::ridge;
  1509. const auto rw = wavesRealWorldParams (state);
  1510. if (slot.kind != EffectKind::ridgeStrip || rw.size() < 31)
  1511. return 0;
  1512. const auto at = [&] (std::size_t i, double fallback) { return wavesValue (rw, i).value_or (fallback); };
  1513. const auto gain = [] (double db) { return linNorm (db, -15.0, 15.0); };
  1514. auto& p = slot.params;
  1515. p[r::voicing] = 1.0f;
  1516. p[r::curve] = 0.0f;
  1517. p[r::input] = linNorm (at (40, 0.0), -20.0, 20.0);
  1518. p[r::output] = linNorm (at (30, 0.0), -20.0, 20.0);
  1519. p[r::phase] = at (39, 0.0) > 0.5 ? 1.0f : 0.0f;
  1520. const auto hp = at (27, 0.0);
  1521. p[r::hpf] = hp >= 16.5 ? std::max (1e-4f, logNorm (std::min (hp, 350.0), 16.0, 350.0)) : 0.0f;
  1522. const auto lpk = at (28, 30.0);
  1523. // Ridge's low-pass law runs 22 kHz (dial 0) .. 3 kHz (dial 1), log
  1524. p[r::lpf] = lpk < 25.0 ? std::max (1e-4f, (float) std::clamp (std::log (22000.0 / (lpk * 1000.0)) / std::log (22000.0 / 3000.0), 0.0, 1.0)) : 0.0f;
  1525. p[r::lfGain] = gain (at (14, 0.0));
  1526. p[r::lfFreq] = logNorm (at (15, 60.0), 30.0, 450.0);
  1527. p[r::lfBell] = at (13, 0.0) > 0.5 ? 1.0f : 0.0f;
  1528. p[r::lmfGain] = gain (at (16, 0.0));
  1529. p[r::lmfFreq] = logNorm (at (17, 0.5) * 1000.0, 200.0, 2500.0);
  1530. p[r::lmfQ] = (float) (1.0 - vmatch::echannel::dialFromQ (at (18, 2.5)));
  1531. p[r::hmfGain] = gain (at (19, 0.0));
  1532. p[r::hmfFreq] = logNorm (at (20, 3.5) * 1000.0, 600.0, 7000.0);
  1533. p[r::hmfQ] = (float) (1.0 - vmatch::echannel::dialFromQ (at (21, 1.5)));
  1534. p[r::hfGain] = gain (at (23, 0.0));
  1535. p[r::hfFreq] = logNorm (at (24, 8.0) * 1000.0, 1500.0, 16000.0);
  1536. p[r::hfBell] = at (22, 0.0) > 0.5 ? 1.0f : 0.0f;
  1537. p[r::eqOn] = at (25, 0.0) > 0.5 ? 0.0f : 1.0f;
  1538. const auto ratio = std::max (1.0, at (1, 1.0));
  1539. // round 165 [EXEC]: the console's ∞ : 1 is stored as 100 (it played as 20 : 1 here, 3 … 5 dB too loud)
  1540. p[r::compRatio] = ratio >= 99.0 ? 1.0f : (float) std::sqrt (std::clamp ((ratio - 1.0) / 19.0, 0.0, 0.998));
  1541. p[r::compThreshold] = linNorm (at (0, 0.0), -20.0, 10.0);
  1542. p[r::compRelease] = logNorm (std::clamp (at (3, 0.4), 0.1, 4.0), 0.1, 4.0);
  1543. p[r::compFastAttack] = at (2, 2.0) == 1.0 ? 1.0f : 0.0f;
  1544. p[r::gateRange] = linNorm (at (6, 0.0), 0.0, 40.0);
  1545. p[r::gateThreshold] = linNorm (at (5, -30.0), -30.0, 10.0);
  1546. p[r::gateRelease] = logNorm (std::clamp (at (9, 0.2), 0.1, 4.0), 0.1, 4.0);
  1547. p[r::gateFastAttack] = at (8, 0.0) > 0.5 ? 1.0f : 0.0f;
  1548. p[r::expander] = at (7, 0.0) > 0.5 ? 0.0f : 1.0f;
  1549. p[r::dynOn] = at (11, 0.0) > 0.5 ? 0.0f : 1.0f;
  1550. p[r::order] = at (12, 0.0) > 0.5 ? 0.0f : 1.0f; // Ridge: on = dynamics before the EQ
  1551. p[r::filterSplit] = at (29, 1.0) == 1.0 ? 1.0f : 0.0f;
  1552. p[r::filtersToSidechain] = 0.0f;
  1553. p[r::compMix] = 1.0f;
  1554. p[r::analog] = at (31, 0.0) > 0.5 ? 1.0f : 0.0f; // round 147b: ANALOG (its noise floor, measured on the trial)
  1555. p[r::eqToSidechain] = at (26, 0.0) > 0.5 ? 1.0f : 0.0f; // round 165: Dyn S.C. ([EXEC] RealWorld 26 follows the switch)
  1556. return 32;
  1557. }
  1558. // H-Delay (RealWorld list, round 119): 1 sync (0 BPM, 1 host, 2 ms), 2 BPM, 3 delay ms, 4 note (3 per length: triplet,
  1559. // straight, dotted from 1/64; 18 = 1 bar, 19 = 2 bars), 6 mix %, 7 feedback, 10 ping-pong (1) / stereo (0), 14 output dB,
  1560. // 15 low-pass Hz (20100 = off), 17 high-pass Hz (19 = off), 19 / 20 modulation depth % / rate Hz, 23 analog (0 = off).
  1561. // [EXEC] Measured on the official trial: ping-pong sends the mono sum to the left echo, the right side repeats it one
  1562. // time later at nearly the same level (-0.3 dB) and the loop gain per left-right pair is 0.93 x (feedback / 100)^2
  1563. // (feedback 30 / 60 / 90: -20.9 / -9.5 / -2.7 dB); stereo mode feeds each side back at 0.98 x feedback / 100 per
  1564. // repeat; the echoes are flat (+-0.5 dB, 30 Hz-20 kHz); the first echo is +1.1 dB over the mono sum with the analog
  1565. // modes and +2.5 dB without (stereo mode: -1.9 / -0.4 dB over its own side); the mix is an equal-power dry / wet.
  1566. int translateWavesHDelay (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1567. {
  1568. namespace e = echosuite::echoform;
  1569. const auto rw = wavesRealWorldParams (state);
  1570. const auto sync = wavesValue (rw, 1), fb = wavesValue (rw, 7);
  1571. if (slot.kind != EffectKind::echoform || ! sync || ! fb)
  1572. return 0;
  1573. auto& p = slot.params;
  1574. // round 135w: [EXEC] round 119's probe: 1 = PingPong, 2 = Stereo (2 used to read as ping-pong)
  1575. const auto ppValue = wavesValue (rw, 10).value_or (1.0);
  1576. const bool pingPong = ppValue >= 0.5 && ppValue < 1.5;
  1577. const bool analog = wavesValue (rw, 23).value_or (2.0) >= 0.5;
  1578. p[e::style] = e::styleValue (pingPong ? e::Style::pingPong : e::Style::single);
  1579. p[e::pairs] = pingPong ? 1.0f : 0.0f;
  1580. // round 129: phase L / R (RealWorld 8 / 9, round 119 §2 [EXEC]; 1 = inverted)
  1581. p[e::phaseL] = wavesValue (rw, 8).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1582. p[e::phaseR] = wavesValue (rw, 9).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1583. // round 135w: the ping-pong's start side (RealWorld 45: 0 left, 1 right — round 119 probe [EXEC])
  1584. p[e::startSide] = wavesValue (rw, 45).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1585. const auto note = (int) std::lround (wavesValue (rw, 4).value_or (13.0));
  1586. const auto ownTempo = wavesValue (rw, 2);
  1587. // round 135w: H-Delay's own BPM (sync 0) keeps its note and tempo (was folded into milliseconds)
  1588. const bool ownBpmSync = *sync < 0.5 && ownTempo && *ownTempo >= 30.0 && *ownTempo <= 300.0;
  1589. p[e::tempoSource] = ownBpmSync ? 1.0f : 0.0f;
  1590. if (ownBpmSync)
  1591. p[e::ownBpm] = e::bpmValue (*ownTempo);
  1592. if ((ownBpmSync || (*sync >= 0.5 && *sync < 1.5)) && note >= 0 && note <= 19)
  1593. {
  1594. // host tempo (or its own): the note follows that tempo
  1595. const auto index = note >= 18 ? note - 12 : note / 3; // 1/64 … 1/2, 1 bar, 2 bars
  1596. const auto kind = note >= 18 ? 1 : (note % 3 == 0 ? 3 : (note % 3 == 1 ? 1 : 2)); // triplet, straight, dotted
  1597. for (const auto side : { e::syncL, e::syncR })
  1598. p[(std::size_t) side] = ((float) kind + 1.5f) / 4.0f;
  1599. for (const auto side : { e::noteL, e::noteR })
  1600. p[(std::size_t) side] = ((float) index + 0.5f) / 10.0f;
  1601. }
  1602. else
  1603. {
  1604. // its own BPM or milliseconds: the time it computed is in the list
  1605. const auto ms = std::clamp (wavesValue (rw, 3).value_or (375.0), 1.0, 3500.0);
  1606. for (const auto side : { e::syncL, e::syncR })
  1607. p[(std::size_t) side] = 0.0f;
  1608. for (const auto side : { e::timeL, e::timeR })
  1609. p[(std::size_t) side] = e::timeValue (ms);
  1610. }
  1611. const auto f = std::max (0.0, *fb) / 100.0;
  1612. // round 124: the hybrid engine reproduces the trial's loop exactly (REA_rodada124 §5) when the state uses no
  1613. // filter, modulation or lo-fi (every state of her corpus); otherwise the round-119 approximation below
  1614. const auto hp0 = wavesValue (rw, 17).value_or (19.0), lp0 = wavesValue (rw, 15).value_or (20100.0);
  1615. if (hp0 <= 19.5 && lp0 >= 20000.0 && wavesValue (rw, 19).value_or (0.0) <= 0.0 && wavesValue (rw, 21).value_or (0.0) < 0.5)
  1616. {
  1617. p[e::hybrid] = e::hybridValue (analog ? 2 : 1);
  1618. p[e::feedback] = (float) std::clamp (f / 2.0, 0.0, 1.0);
  1619. p[e::mix] = (float) std::clamp (wavesValue (rw, 6).value_or (100.0) / 100.0, 0.0, 1.0);
  1620. p[e::output] = linNorm (wavesValue (rw, 14).value_or (0.0), -18.0, 18.0);
  1621. return 9;
  1622. }
  1623. const auto loop = pingPong ? 0.93 * f * f : 0.98 * f;
  1624. p[e::feedback] = (float) std::clamp (loop / 2.0, 0.0, 1.0);
  1625. p[e::mix] = (float) std::clamp (wavesValue (rw, 6).value_or (100.0) / 100.0, 0.0, 1.0);
  1626. // the analog modes also compress loud input (1 kHz bursts: +3 dB at -34 dBFS, 0 at -10, -2.3 at -4): on her
  1627. // three vocal takes the echoes of the reference are 2.5 dB under the small-signal gain, hence -1.4 instead of +1.1
  1628. const auto level = pingPong ? (analog ? -1.4 : 2.5) : (analog ? -4.4 : -0.4);
  1629. p[e::output] = linNorm (wavesValue (rw, 14).value_or (0.0) + level, -18.0, 18.0);
  1630. p[e::mode] = e::modeValue (e::Mode::clean);
  1631. p[e::age] = 0.0f;
  1632. p[e::drive] = 0.0f;
  1633. p[e::diffusion] = 0.0f;
  1634. p[e::ducking] = 0.0f;
  1635. p[e::width] = 1.0f;
  1636. p[e::spread] = 0.5f;
  1637. // round 137: LoFi (RealWorld 21, on = 1) → Echoform's own LoFi switch (the same in-loop low-pass, spec §4.2)
  1638. p[e::lofi] = wavesValue (rw, 21).value_or (0.0) >= 0.5 ? 1.0f : 0.0f;
  1639. const auto hp = wavesValue (rw, 17).value_or (19.0), lp = wavesValue (rw, 15).value_or (20100.0);
  1640. p[e::lowCut] = hp > 19.5 ? linNorm (hp, 10.0, 2000.0) : 0.0f;
  1641. // Echoform's high cut acts like a one-pole at about half its label below 80 % (REA_rodada101 §3.3)
  1642. p[e::highCut] = lp < 20000.0 ? linNorm (2.0 * lp, 200.0, 20000.0) : 1.0f;
  1643. const auto depth = wavesValue (rw, 19).value_or (0.0);
  1644. p[e::modDepth] = (float) std::clamp (std::sqrt (std::max (0.0, depth) / 100.0), 0.0, 1.0);
  1645. if (depth > 0.0)
  1646. p[e::modRate] = (float) std::clamp (std::pow ((std::clamp (wavesValue (rw, 20).value_or (0.1), 0.01, 10.0) - 0.01) / 9.99, 1.0 / 2.3277), 0.0, 1.0);
  1647. return 8;
  1648. }
  1649. // NS1 (RealWorld list, round 119): value 229 is the one knob, 0 … 100 %; Quell's Amount follows the same scale
  1650. // (fitted to the official trial, docs/analise/REA_rodada119.md §3).
  1651. int translateWavesNs1 (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1652. {
  1653. const auto rw = wavesRealWorldParams (state);
  1654. const auto amount = wavesValue (rw, 229);
  1655. if (slot.kind != EffectKind::quellDenoiser || ! amount)
  1656. return 0;
  1657. slot.params[voicetools::quell::amount] = (float) std::clamp (*amount / 100.0, 0.0, 1.0);
  1658. slot.params[voicetools::quell::matched] = 1.0f; // round 124: the engine fitted to the trial (REA_rodada124 §6)
  1659. return 2;
  1660. }
  1661. // Doubler (RealWorld list, round 119): 0 output dB, 1 direct on, 2 direct gain dB, 3 direct pan deg, 4 align,
  1662. // 9 / 10 / 11 low shelf on / gain dB / Hz, 12 / 13 / 14 high shelf Hz / gain dB / on, 15 feedback high-pass Hz,
  1663. // 16 / 17 voice 1 / 2 source (0 own side, 1 sum, 2 difference), 18 range (0 = 80 Hz), then a block of 10 per voice from
  1664. // 26: on, gain dB, pan deg, octave, detune cents, delay ms, feedback %, depth cents, rate. [EXEC] Gemini's laws are the
  1665. // measured ones (equal-power voice pan, stereo rotation of the direct signal, exact detune, octave down, LFO at
  1666. // rate / 2 Hz, feedback = %/100 per repeat, the aligned direct signal 6.7 ms late), so the values map one to one.
  1667. int translateWavesDoubler (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1668. {
  1669. namespace g = voicetools::gemini;
  1670. const auto rw = wavesRealWorldParams (state);
  1671. if (slot.kind != EffectKind::geminiDoubler || rw.size() < 45 || ! wavesValue (rw, 31))
  1672. return 0;
  1673. const auto at = [&] (std::size_t i, double fallback) { return wavesValue (rw, i).value_or (fallback); };
  1674. const auto flag = [&] (std::size_t i, double fallback) { return at (i, fallback) >= 0.5 ? 1.0f : 0.0f; };
  1675. auto& p = slot.params;
  1676. p[g::output] = linNorm (at (0, 0.0), -24.0, 0.0);
  1677. p[g::directOn] = flag (1, 1.0);
  1678. p[g::directGain] = linNorm (at (2, 0.0), -48.0, 0.0);
  1679. p[g::directPan] = linNorm (at (3, 0.0), -45.0, 45.0);
  1680. p[g::align] = flag (4, 1.0);
  1681. p[g::lowOn] = flag (9, 0.0);
  1682. p[g::lowGain] = linNorm (at (10, 0.0), -30.0, 12.0);
  1683. p[g::lowFreq] = g::freqValue (at (11, 100.0));
  1684. p[g::highFreq] = g::freqValue (at (12, 5000.0));
  1685. p[g::highGain] = linNorm (at (13, 0.0), -30.0, 12.0);
  1686. p[g::highOn] = flag (14, 0.0);
  1687. p[g::feedbackCut] = g::freqValue (at (15, 16.0));
  1688. p[g::range] = flag (18, 0.0);
  1689. // round 135w: a four-voice doubler's voices 3 and 4 (blocks 46 / 56, the same layout as 26 / 36 [model]: a two-voice
  1690. // state carries those blocks too, so they are read only when the state names the four-voice plug-in; their source
  1691. // indices are not probed yet: own side)
  1692. const bool four = wavesPluginName (state).find ("Doubler4") != std::string::npos;
  1693. for (int v = 0; v < (four ? 4 : 2); ++v)
  1694. {
  1695. const auto b = (std::size_t) (26 + 10 * v);
  1696. const auto param = [&] (g::VoiceParam q) -> float& { return p[(std::size_t) g::voiceParam (v, q)]; };
  1697. param (g::vOn) = flag (b, 1.0);
  1698. param (g::vGain) = linNorm (at (b + 1, 0.0), -48.0, 0.0);
  1699. param (g::vPan) = linNorm (at (b + 2, v % 2 == 0 ? -45.0 : 45.0), -45.0, 45.0);
  1700. param (g::vOctave) = flag (b + 3, 0.0);
  1701. param (g::vDetune) = linNorm (at (b + 4, 0.0), -100.0, 100.0);
  1702. param (g::vDelay) = linNorm (at (b + 5, 10.0), 0.0, 100.0);
  1703. param (g::vFeedback) = linNorm (at (b + 6, 0.0), 0.0, 100.0);
  1704. param (g::vDepth) = linNorm (at (b + 7, 0.0), -200.0, 200.0);
  1705. param (g::vRate) = logNorm (std::clamp (at (b + 8, 1.0), 0.1, 400.0), 0.1, 400.0);
  1706. param (g::vSource) = v >= 2 ? 1.0f / 6.0f : ((float) std::clamp ((int) std::lround (at (16 + (std::size_t) v, 0.0)), 0, 2) + 0.5f) / 3.0f;
  1707. }
  1708. return 33;
  1709. }
  1710. // S1 Imager (RealWorld list, round 124): 0 gain dB, 1 width (0 … 3, the plug-in keeps two decimals), 4 rotation deg
  1711. // (±45), 5 asymmetry deg (±90), 13 swap, 14 / 15 invert left / right, 16 M/S input. [EXEC] Black-box on the official
  1712. // trial (REA_rodada124_extras §4): a frequency-flat 2 × 2 matrix, gain · rotation · width · input. Width w below 1
  1713. // scales the side signal (mid 1, side w); above 1 the side / mid ratio is w with mid = √(0.625 + 0.375 / w²) (exact on
  1714. // 41 measured points); rotation φ is the plain rotation [cos −sin; sin cos]. Fruity Stereo Shaper (LYNX's exact engine)
  1715. // holds any 2 × 2 matrix, so the translation nulls the reference. Asymmetry, swap / invert and M/S input are not
  1716. // measured beyond their neutral settings (all neutral in her states): a state that uses them is not translated.
  1717. int translateWavesS1Imager (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1718. {
  1719. const auto rw = wavesRealWorldParams (state);
  1720. const auto width = wavesValue (rw, 1);
  1721. if (slot.kind != EffectKind::stereoShaper || ! width)
  1722. return 0;
  1723. const auto at = [&] (std::size_t i) { return wavesValue (rw, i).value_or (0.0); };
  1724. if (std::abs (at (5)) > 1e-6 || at (13) >= 0.5 || at (14) >= 0.5 || at (15) >= 0.5 || at (16) >= 0.5)
  1725. return 0;
  1726. const auto w = std::clamp (std::round (*width * 100.0) / 100.0, 0.0, 3.0);
  1727. const auto mid = w <= 1.0 ? 1.0 : std::sqrt (0.625 + 0.375 / (w * w));
  1728. const auto side = w * mid;
  1729. const auto a = 0.5 * (mid + side), b = 0.5 * (mid - side);
  1730. const auto phi = std::clamp (at (4), -45.0, 45.0) * 3.14159265358979323846 / 180.0;
  1731. const auto c = std::cos (phi), s = std::sin (phi);
  1732. const auto g = std::pow (10.0, std::clamp (at (0), -24.0, 0.0) / 20.0);
  1733. // rotation · width: [c −s; s c] · [a b; b a]
  1734. const double m00 = g * (c * a - s * b), m01 = g * (c * b - s * a), m10 = g * (s * a + c * b), m11 = g * (s * b + c * a);
  1735. // the Shaper's knob law: |gain| = (3^|x| − 1) / 2 with x = raw / 12800
  1736. const auto raw = [] (double gain) {
  1737. const auto x = std::log (2.0 * std::abs (gain) + 1.0) / std::log (3.0);
  1738. return std::clamp ((int) std::lround ((gain < 0.0 ? -x : x) * 12800.0), -25600, 25600);
  1739. };
  1740. const auto unit = [] (int r) { return (float) (r + 25600) / 51200.0f; };
  1741. auto& p = slot.params;
  1742. p[0] = unit (raw (m01)); // R → L
  1743. p[1] = unit (raw (m00)); // L
  1744. p[2] = unit (raw (m11)); // R
  1745. p[3] = unit (raw (m10)); // L → R
  1746. p[4] = 0.5f; // no delay
  1747. p[5] = 0.5f; // no phase
  1748. p[6] = 0.0f;
  1749. p[7] = 0.0f;
  1750. return 4;
  1751. }
  1752. // --- Soundtoys (round 135): her states, read black-box in the official trials -------------------------------------
  1753. // A Soundtoys state is text ("WIDGET = …; PRESET =<encoded>;"); the payload is NOT decoded. Each state found in her
  1754. // projects was loaded into the official trial through the host API and every parameter read back
  1755. // (docs/analise/REA_rodada135s.md §1); the table maps the payload's FNV-1a hash to those settings in LYNX's units.
  1756. struct KnownState
  1757. {
  1758. std::uint64_t hash;
  1759. std::vector<std::pair<int, float>> values;
  1760. };
  1761. namespace vs = voiceshift;
  1762. namespace em = mixsuite::ember;
  1763. namespace ap = autopan;
  1764. namespace st135
  1765. {
  1766. #include "core/SoundtoysStates.inc"
  1767. }
  1768. std::optional<std::uint64_t> soundtoysPayloadHash (const std::vector<std::uint8_t>& state)
  1769. {
  1770. static constexpr char key[] = "PRESET =";
  1771. const auto* b = state.data();
  1772. const auto n = state.size();
  1773. for (std::size_t i = 0; i + sizeof (key) - 1 <= n; ++i)
  1774. if (std::memcmp (b + i, key, sizeof (key) - 1) == 0)
  1775. {
  1776. auto start = i + sizeof (key) - 1, end = start;
  1777. while (end < n && b[end] != ';') ++end;
  1778. if (end >= n) return std::nullopt;
  1779. while (start < end && std::isspace (b[start])) ++start;
  1780. while (end > start && std::isspace (b[end - 1])) --end;
  1781. std::uint64_t h = 0xcbf29ce484222325ull;
  1782. for (auto k = start; k < end; ++k) { h ^= b[k]; h *= 0x100000001b3ull; }
  1783. return h;
  1784. }
  1785. return std::nullopt;
  1786. }
  1787. template <std::size_t N>
  1788. int translateKnown (const KnownState (&table)[N], EffectKind kind, const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1789. {
  1790. if (slot.kind != kind) return 0;
  1791. const auto h = soundtoysPayloadHash (state);
  1792. if (! h) return 0;
  1793. for (const auto& k : table)
  1794. if (k.hash == *h)
  1795. {
  1796. for (const auto& [p, v] : k.values)
  1797. if (p >= 0 && p < (int) slot.params.size()) slot.params[(std::size_t) p] = v;
  1798. return (int) k.values.size();
  1799. }
  1800. return 0;
  1801. }
  1802. [[maybe_unused]] int translateAlterBoy (const std::vector<std::uint8_t>& s, EffectSlot& slot) { return translateKnown (st135::alterBoyStates, EffectKind::voiceShift, s, slot); }
  1803. [[maybe_unused]] int translateDecapitator (const std::vector<std::uint8_t>& s, EffectSlot& slot) { return translateKnown (st135::decapitatorStates, EffectKind::ember, s, slot); }
  1804. [[maybe_unused]] int translatePanMan (const std::vector<std::uint8_t>& s, EffectSlot& slot) { return translateKnown (st135::panManStates, EffectKind::autoPan, s, slot); }
  1805. } // namespace
  1806. int knownSoundtoysStates() noexcept { return (int) (std::size (st135::alterBoyStates) + std::size (st135::decapitatorStates) + std::size (st135::panManStates)); }
  1807. std::optional<std::uint64_t> soundtoysStateHash (const std::vector<std::uint8_t>& state) { return soundtoysPayloadHash (state); }
  1808. namespace
  1809. {
  1810. // ---- Soundtoys (round 136): the encoded preset is not decoded; her saved states are recognised by its hash
  1811. namespace st136
  1812. {
  1813. #include "core/SoundtoysStates136.inc"
  1814. }
  1815. using namespace st136;
  1816. std::uint64_t presetHash (const std::vector<std::uint8_t>& state)
  1817. {
  1818. const auto at = findBytes (state, "PRESET =");
  1819. if (at == std::string::npos)
  1820. return 0;
  1821. std::size_t end = at + 8;
  1822. while (end < state.size() && state[end] != '\r')
  1823. ++end;
  1824. if (end > at + 8 && state[end - 1] == ';')
  1825. --end;
  1826. std::uint64_t h = 0xcbf29ce484222325ull; // FNV-1a 64
  1827. for (auto i = at + 8; i < end; ++i)
  1828. h = (h ^ state[i]) * 0x100000001b3ull;
  1829. return h;
  1830. }
  1831. int translateSoundtoysDecapitator (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1832. {
  1833. namespace e = mixsuite::ember;
  1834. if (slot.kind != EffectKind::ember)
  1835. return 0;
  1836. const auto h = presetHash (state);
  1837. for (const auto& st : decapitatorStates)
  1838. {
  1839. if (st.hash != h)
  1840. continue;
  1841. static constexpr int order[10] { e::classicStyle, e::classicDrive, e::classicPunish, e::classicLowCut, e::classicThump,
  1842. e::classicTone, e::classicHighCut, e::classicSteep, e::classicMix, e::classicOutput };
  1843. slot.params[(std::size_t) e::voicing] = 1.0f;
  1844. for (int i = 0; i < 10; ++i)
  1845. slot.params[(std::size_t) order[i]] = st.v[i];
  1846. slot.mix = 1.0f;
  1847. return 10;
  1848. }
  1849. return 0;
  1850. }
  1851. int translateSoundtoysPanMan (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1852. {
  1853. if (slot.kind != EffectKind::autoPan || slot.params.size() < (std::size_t) autopan::count + 12)
  1854. return 0;
  1855. const auto h = presetHash (state);
  1856. for (const auto& st : panManStates)
  1857. {
  1858. if (st.hash != h)
  1859. continue;
  1860. for (int i = 0; i < 12; ++i)
  1861. slot.params[(std::size_t) (autopan::count + i)] = st.v[i]; // round 136's Rhythm voicing params
  1862. slot.mix = 1.0f;
  1863. return 12;
  1864. }
  1865. return 0;
  1866. }
  1867. int translateSoundtoysAlterBoy (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1868. {
  1869. namespace t = lynxtune;
  1870. if (slot.kind != EffectKind::lynxTune || slot.params.size() < (std::size_t) t::count)
  1871. return 0;
  1872. const auto h = presetHash (state);
  1873. for (const auto& st : alterBoyStates)
  1874. {
  1875. if (st.hash != h)
  1876. continue;
  1877. const double pitch = -12.0 + 24.0 * st.v[0], formant = -12.0 + 24.0 * st.v[1];
  1878. const int mode = std::clamp ((int) std::lround (st.v[4] * 2.0), 0, 2); // transpose, quantize, robot
  1879. auto& p = slot.params;
  1880. p[(std::size_t) t::scale] = 0.0f; // chromatic
  1881. p[(std::size_t) t::retune] = 0.0f;
  1882. p[(std::size_t) t::humanize] = 0.0f;
  1883. p[(std::size_t) t::flexTune] = 0.0f;
  1884. for (int k = 0; k < 12; ++k)
  1885. {
  1886. p[(std::size_t) (t::noteC + k)] = 1.0f;
  1887. p[(std::size_t) (t::bypassC + k)] = mode == 0 ? 1.0f : 0.0f; // Transpose: no correction
  1888. }
  1889. p[(std::size_t) t::transpose] = (float) ((std::clamp (std::lround (pitch), -12L, 12L) + 12) / 24.0);
  1890. const bool wide = std::abs (formant) > 7.0;
  1891. p[(std::size_t) t::wideFormant] = wide ? 1.0f : 0.0f;
  1892. p[(std::size_t) t::formantShift] = (float) std::clamp (formant / (wide ? 24.0 : 14.0) + 0.5, 0.0, 1.0);
  1893. p[(std::size_t) t::formantPreserve] = st.v[5] >= 0.5f ? 0.0f : 1.0f; // formant link: the formants follow the pitch
  1894. p[(std::size_t) t::driveStage] = 1.0f;
  1895. p[(std::size_t) t::drive] = st.v[2];
  1896. p[(std::size_t) t::mix] = st.v[3];
  1897. p[(std::size_t) t::outputTrim] = 0.5f;
  1898. slot.mix = 1.0f;
  1899. return 8;
  1900. }
  1901. return 0;
  1902. }
  1903. int translateSoundtoysEchoBoy (const std::vector<std::uint8_t>& state, EffectSlot& slot)
  1904. {
  1905. namespace e = echosuite::echoform;
  1906. if (slot.kind != EffectKind::echoform || slot.params.size() < (std::size_t) e::paramCount)
  1907. return 0;
  1908. const auto h = presetHash (state);
  1909. for (const auto& st : echoBoyStates)
  1910. {
  1911. if (st.hash != h)
  1912. continue;
  1913. auto& p = slot.params;
  1914. p[(std::size_t) e::tapeVoicing] = e::tapeVoicingValue (st.voicing);
  1915. p[(std::size_t) e::syncL] = p[(std::size_t) e::syncR] = 0.625f; // a note at the project tempo
  1916. p[(std::size_t) e::noteL] = p[(std::size_t) e::noteR] = st.note;
  1917. p[(std::size_t) e::feedback] = st.loopGain / 2.0f; // feedbackGain = 2 v
  1918. p[(std::size_t) e::mix] = st.mix;
  1919. p[(std::size_t) e::output] = 0.5f;
  1920. slot.mix = 1.0f;
  1921. return 6;
  1922. }
  1923. return 0;
  1924. }
  1925. RawTranslator rawTranslatorNamed (std::string_view name)
  1926. {
  1927. if (name == "soundtoys-echoboy")
  1928. return translateSoundtoysEchoBoy;
  1929. if (name == "soundtoys-littlealterboy")
  1930. return translateSoundtoysAlterBoy;
  1931. if (name == "soundtoys-decapitator")
  1932. return translateSoundtoysDecapitator;
  1933. if (name == "soundtoys-panman")
  1934. return translateSoundtoysPanMan; if (name == "waves-s1-imager")
  1935. return translateWavesS1Imager;
  1936. if (name == "waves-h-delay")
  1937. return translateWavesHDelay;
  1938. if (name == "waves-ns1")
  1939. return translateWavesNs1;
  1940. if (name == "waves-doubler")
  1941. return translateWavesDoubler;
  1942. if (name == "waves-ssl-channel")
  1943. return translateWavesSslChannel;
  1944. if (name == "ssl-vocalstrip-2")
  1945. return translateSslVocalstrip2;
  1946. if (name == "auto-tune-pro")
  1947. return translateAutoTunePro;
  1948. if (name == "waves-tune")
  1949. return translateWavesTune;
  1950. if (name == "fresh-air")
  1951. return translateFreshAir;
  1952. if (name == "waves-rcomp")
  1953. return translateWavesRComp;
  1954. if (name == "waves-deesser")
  1955. return translateWavesDeEsser;
  1956. if (name == "waves-cla-2a")
  1957. return translateWavesCla2a;
  1958. if (name == "waves-cla-76")
  1959. return translateWavesCla76;
  1960. return nullptr;
  1961. }
  1962. // the value of attribute `name` in the element starting at `from` ("" when absent)
  1963. std::string attributeIn (const std::string& text, std::size_t from, const std::string& name)
  1964. {
  1965. const auto end = text.find ('>', from);
  1966. const auto key = " " + name + "=\"";
  1967. const auto at = text.find (key, from);
  1968. if (at == std::string::npos || (end != std::string::npos && at > end))
  1969. return {};
  1970. const auto start = at + key.size();
  1971. const auto close = text.find ('"', start);
  1972. return close == std::string::npos ? std::string() : text.substr (start, close - start);
  1973. }
  1974. } // namespace
  1975. std::optional<std::pair<int, int>> autoTuneProKey (const std::vector<std::uint8_t>& state)
  1976. {
  1977. const auto at = findBytes (state, "<Custom ");
  1978. if (at == std::string::npos || findBytes (state, "<SessionChunkData") == std::string::npos)
  1979. return std::nullopt;
  1980. const std::string text (state.begin() + (std::ptrdiff_t) at, state.begin() + (std::ptrdiff_t) std::min (state.size(), at + 4096));
  1981. float key = -1, scale = -1;
  1982. if (! parseFloat (attributeIn (text, 0, "ScaleGivenKey"), key) || ! parseFloat (attributeIn (text, 0, "ScaleGivenScale"), scale))
  1983. return std::nullopt;
  1984. if (key < 0 || key > 11 || key != std::floor (key))
  1985. return std::nullopt;
  1986. // [EXEC] the scale list's first entries (the official trial's own texts, REA round 120 §5): 0 = Major, 1 = Minor,
  1987. // 2 = Chromatic — as read from her takes in round 113 §2. The other scales (tunings) are not translated.
  1988. // Round 138 (REA_rodada138 §3.1): a state that carries <ModernScales> (saved by a newer Auto-Tune Pro) stores the
  1989. // index of the MODERN scale list instead (0 Chromatic, 1 Major, 2 Minor, 3 Harmonic Minor, 4 Jazz Melodic Minor,
  1990. // 5 Dorian, 6 Phrygian, 7 Lydian, 8 Mixolydian, 9 Locrian, 10 Major Pentatonic, 11 Minor Pentatonic, 12 Blues,
  1991. // 13 Whole Tone, 14 Diminished): [EXEC] her 42 states with "2" load into the official trial as Minor, the one with
  1992. // "1" as Major (the old reading took them for Chromatic / Minor)
  1993. vocal::Scale lynxScale;
  1994. if (findBytes (state, "<ModernScales") != std::string::npos)
  1995. {
  1996. using S = vocal::Scale;
  1997. static constexpr S modern[15] { S::chromatic, S::major, S::minor, S::harmonicMinor, S::melodicMinor, S::dorian, S::phrygian,
  1998. S::lydian, S::mixolydian, S::locrian, S::majorPentatonic, S::minorPentatonic, S::blues,
  1999. S::wholeTone, S::diminished };
  2000. if (scale < 0.0f || scale > 14.0f || scale != std::floor (scale))
  2001. return std::nullopt;
  2002. lynxScale = modern[(int) scale];
  2003. }
  2004. else if (scale == 0.0f)
  2005. lynxScale = vocal::Scale::major;
  2006. else if (scale == 1.0f)
  2007. lynxScale = vocal::Scale::minor;
  2008. else if (scale == 2.0f)
  2009. lynxScale = vocal::Scale::chromatic;
  2010. else
  2011. return std::nullopt; // the other scales: not confirmed
  2012. return std::pair<int, int> { (int) key, (int) lynxScale };
  2013. }
  2014. std::optional<std::pair<std::uint16_t, std::uint16_t>> autoTuneProNoteEdits (const std::vector<std::uint8_t>& state, int key, int lynxScale)
  2015. {
  2016. // [DATA] <Scales><Scale ScaleIndex="n" Length="7|12"><Bypass Values="0100000"/><Remove Values="…"/>: one digit per
  2017. // scale degree (major / minor: 7 degrees above the root; chromatic: 12 semitones above the root)
  2018. // round 138: a <ModernScales> state keeps one 12-digit row per modern scale (semitones above the root; Remove = the
  2019. // notes that are not targets, the scale's own non-members included)
  2020. if (const auto ms = findBytes (state, "<ModernScales"); ms != std::string::npos)
  2021. {
  2022. using S = vocal::Scale;
  2023. static constexpr S modern[15] { S::chromatic, S::major, S::minor, S::harmonicMinor, S::melodicMinor, S::dorian, S::phrygian,
  2024. S::lydian, S::mixolydian, S::locrian, S::majorPentatonic, S::minorPentatonic, S::blues,
  2025. S::wholeTone, S::diminished };
  2026. int mi = -1;
  2027. for (int k = 0; k < 15; ++k)
  2028. if ((int) modern[k] == lynxScale)
  2029. mi = k;
  2030. const auto at = mi < 0 ? std::string::npos : findBytes (state, "<Scale ScaleIndex=\"" + std::to_string (mi) + "\"", ms);
  2031. if (at == std::string::npos)
  2032. return std::nullopt;
  2033. const std::string text (state.begin() + (std::ptrdiff_t) at, state.begin() + (std::ptrdiff_t) std::min (state.size(), at + 600));
  2034. auto mask = [&] (const char* element) -> std::optional<std::uint16_t> {
  2035. const auto e = text.find (element);
  2036. if (e == std::string::npos)
  2037. return std::nullopt;
  2038. const auto v = attributeIn (text, e, "Values");
  2039. if (v.size() != 12u)
  2040. return std::nullopt;
  2041. std::uint16_t m = 0;
  2042. for (int d = 0; d < 12; ++d)
  2043. if (v[(std::size_t) d] == '1')
  2044. m = (std::uint16_t) (m | (1u << ((key + d) % 12)));
  2045. return m;
  2046. };
  2047. const auto bypass = mask ("<Bypass "), remove = mask ("<Remove ");
  2048. if (! bypass || ! remove)
  2049. return std::nullopt;
  2050. return std::pair<std::uint16_t, std::uint16_t> { *bypass, *remove };
  2051. }
  2052. const int index = lynxScale == (int) vocal::Scale::major ? 0 : lynxScale == (int) vocal::Scale::minor ? 1 : lynxScale == (int) vocal::Scale::chromatic ? 2 : -1;
  2053. if (index < 0)
  2054. return std::nullopt;
  2055. const auto at = findBytes (state, "<Scale ScaleIndex=\"" + std::to_string (index) + "\"");
  2056. if (at == std::string::npos)
  2057. return std::nullopt;
  2058. const std::string text (state.begin() + (std::ptrdiff_t) at, state.begin() + (std::ptrdiff_t) std::min (state.size(), at + 600));
  2059. static constexpr int major[7] { 0, 2, 4, 5, 7, 9, 11 }, minor[7] { 0, 2, 3, 5, 7, 8, 10 };
  2060. auto mask = [&] (const char* element) -> std::optional<std::uint16_t> {
  2061. const auto e = text.find (element);
  2062. if (e == std::string::npos)
  2063. return std::nullopt;
  2064. const auto v = attributeIn (text, e, "Values");
  2065. const auto n = index == 2 ? 12u : 7u;
  2066. if (v.size() != n)
  2067. return std::nullopt;
  2068. std::uint16_t m = 0;
  2069. for (std::size_t d = 0; d < n; ++d)
  2070. if (v[d] == '1')
  2071. m = (std::uint16_t) (m | (1u << ((key + (index == 2 ? (int) d : index == 0 ? major[d] : minor[d])) % 12)));
  2072. return m;
  2073. };
  2074. const auto bypass = mask ("<Bypass "), remove = mask ("<Remove ");
  2075. if (! bypass || ! remove)
  2076. return std::nullopt;
  2077. return std::pair<std::uint16_t, std::uint16_t> { *bypass, *remove };
  2078. }
  2079. std::map<int, double> autoTuneProParams (const std::vector<std::uint8_t>& state)
  2080. {
  2081. std::map<int, double> out;
  2082. const auto at = findBytes (state, "ParamsData=\"");
  2083. if (at == std::string::npos || findBytes (state, "<SessionChunkData") == std::string::npos)
  2084. return out;
  2085. const auto start = at + 12;
  2086. const auto end = findBytes (state, "\"", start);
  2087. if (end == std::string::npos)
  2088. return out;
  2089. // JUCE MemoryBlock::toBase64Encoding: "<size>.<chars>", 6 bits per char, least significant bit first
  2090. const std::string text (state.begin() + (std::ptrdiff_t) start, state.begin() + (std::ptrdiff_t) end);
  2091. const auto dot = text.find ('.');
  2092. if (dot == std::string::npos || dot == 0 || dot > 9)
  2093. return out;
  2094. std::size_t size = 0;
  2095. for (std::size_t i = 0; i < dot; ++i)
  2096. {
  2097. if (text[i] < '0' || text[i] > '9')
  2098. return out;
  2099. size = size * 10 + (std::size_t) (text[i] - '0');
  2100. }
  2101. if (size > (1u << 20))
  2102. return out;
  2103. static constexpr const char* alphabet = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2104. std::string raw (size, '\0');
  2105. std::size_t bit = 0;
  2106. for (std::size_t i = dot + 1; i < text.size() && bit < size * 8; ++i)
  2107. {
  2108. const auto* c = std::strchr (alphabet, text[i]);
  2109. if (c == nullptr || text[i] == '\0')
  2110. return {};
  2111. const auto v = (unsigned) (c - alphabet);
  2112. for (int k = 0; k < 6 && bit < size * 8; ++k, ++bit)
  2113. if ((v >> k) & 1u)
  2114. raw[bit >> 3] = (char) (raw[bit >> 3] | (1 << (bit & 7)));
  2115. }
  2116. // <Parameter X<n>="<value>"/> entries
  2117. for (auto p = raw.find (" X"); p != std::string::npos; p = raw.find (" X", p + 2))
  2118. {
  2119. std::size_t q = p + 2;
  2120. int n = 0, digits = 0;
  2121. while (q < raw.size() && raw[q] >= '0' && raw[q] <= '9' && digits < 4)
  2122. n = n * 10 + (raw[q++] - '0'), ++digits;
  2123. if (digits == 0 || q + 1 >= raw.size() || raw[q] != '=' || raw[q + 1] != '"')
  2124. continue;
  2125. const auto close = raw.find ('"', q + 2);
  2126. if (close == std::string::npos)
  2127. break;
  2128. float v = 0;
  2129. if (parseFloat (raw.substr (q + 2, close - q - 2), v))
  2130. out[n] = (double) v;
  2131. }
  2132. return out;
  2133. }
  2134. std::optional<PitchCorrectorScale> wavesTuneScale (const std::vector<std::uint8_t>& state)
  2135. {
  2136. const auto start = findBytes (state, "<PresetChunkXMLTree");
  2137. if (start == std::string::npos)
  2138. return std::nullopt;
  2139. const std::string xml (state.begin() + (std::ptrdiff_t) start, state.end());
  2140. std::string setup = "SETUP_A";
  2141. if (const auto a = xml.find ("<ActiveSetup>"); a != std::string::npos)
  2142. if (const auto b = xml.find ("</ActiveSetup>", a); b != std::string::npos)
  2143. setup = trim (std::string_view (xml).substr (a + 13, b - a - 13));
  2144. const auto data = xml.find ("<PresetData Setup=\"" + setup + "\"");
  2145. if (data == std::string::npos)
  2146. return std::nullopt;
  2147. const auto end = std::min (xml.find ("</PresetData>", data), xml.size());
  2148. const auto scaleAt = xml.find ("<Scale ", data);
  2149. const auto segAt = xml.find ("<NoteSegmentation>", data);
  2150. const auto segEnd = xml.find ("</NoteSegmentation>", data);
  2151. const auto rootAt = xml.find ("<Root>", data);
  2152. if (scaleAt >= end || segAt >= end || segEnd >= end || rootAt >= end)
  2153. return std::nullopt;
  2154. int root = -1;
  2155. try
  2156. {
  2157. root = std::stoi (xml.substr (rootAt + 6, 4));
  2158. }
  2159. catch (...)
  2160. {
  2161. return std::nullopt;
  2162. }
  2163. if (root < 0 || root > 11)
  2164. return std::nullopt;
  2165. // the twelve notes above the root, in order (NoteCents 0, 100 … 1100): "x" = excluded, anything else = a target
  2166. std::uint16_t rel = 0;
  2167. int count = 0;
  2168. for (auto p = xml.find ("<NoteStatus>", segAt); p < segEnd && count < 12; p = xml.find ("<NoteStatus>", p + 1), ++count)
  2169. {
  2170. const auto q = xml.find ("</NoteStatus>", p);
  2171. if (q == std::string::npos || q > segEnd)
  2172. return std::nullopt;
  2173. if (trim (std::string_view (xml).substr (p + 12, q - p - 12)) != "x")
  2174. rel = (std::uint16_t) (rel | (1u << count));
  2175. }
  2176. if (count != 12 || rel == 0)
  2177. return std::nullopt;
  2178. PitchCorrectorScale out;
  2179. out.key = root;
  2180. out.mask = (std::uint16_t) (((rel << root) | (rel >> (12 - root))) & 0xfff);
  2181. out.scale = (int) vocal::Scale::custom;
  2182. for (int s = 0; s < vocal::scaleCount; ++s)
  2183. if (s != (int) vocal::Scale::custom && vocal::scaleMask ((vocal::Scale) s, root) == out.mask)
  2184. {
  2185. out.scale = s;
  2186. break;
  2187. }
  2188. return out;
  2189. }
  2190. std::optional<PitchCorrectorScale> pitchCorrectorScale (const std::vector<std::uint8_t>& state)
  2191. {
  2192. if (const auto k = autoTuneProKey (state))
  2193. return PitchCorrectorScale { k->first, k->second, vocal::scaleMask ((vocal::Scale) k->second, k->first) };
  2194. if (findBytes (state, "<AUTOTUNEEFXPLUS") != std::string::npos) // Auto-Tune EFX+ (round 127)
  2195. {
  2196. EffectSlot tune = makeEffectSlot (EffectKind::lynxTune);
  2197. if (translateAutoTuneEfx (state, tune) == 0)
  2198. return std::nullopt;
  2199. std::uint16_t mask = 0;
  2200. for (int k = 0; k < 12; ++k)
  2201. if (tune.params[(std::size_t) (lynxtune::noteC + k)] >= 0.5f)
  2202. mask = (std::uint16_t) (mask | (1u << k));
  2203. return PitchCorrectorScale { lynxtune::keyIndex (tune.params[lynxtune::key]), lynxtune::scaleIndex (tune.params[lynxtune::scale]), mask };
  2204. }
  2205. return wavesTuneScale (state);
  2206. }
  2207. std::optional<std::pair<float, float>> freshAirAmounts (const std::vector<std::uint8_t>& state)
  2208. {
  2209. // [DATA] the component state of every Fresh Air slot surveyed (round 113): 2530 bytes, u32 1, u32 size − 8, then
  2210. // two floats 0..1 at 1290 / 1294; [EXEC] the official trial saves its "Mid Air" / "High Air" parameters there
  2211. if (state.size() != 2530)
  2212. return std::nullopt;
  2213. auto u32 = [&state] (std::size_t at) {
  2214. std::uint32_t v = 0;
  2215. std::memcpy (&v, state.data() + at, 4);
  2216. return v;
  2217. };
  2218. auto f32 = [&state] (std::size_t at) {
  2219. float v = 0;
  2220. std::memcpy (&v, state.data() + at, 4);
  2221. return v;
  2222. };
  2223. if (u32 (0) != 1 || u32 (4) != (std::uint32_t) state.size() - 8)
  2224. return std::nullopt;
  2225. const auto mid = f32 (1290), high = f32 (1294);
  2226. if (! std::isfinite (mid) || ! std::isfinite (high) || mid < 0.0f || mid > 1.0f || high < 0.0f || high > 1.0f)
  2227. return std::nullopt;
  2228. return std::pair<float, float> { mid, high };
  2229. }
  2230. PluginIdentity pluginIdentity (const ForeignPlugin& plugin)
  2231. {
  2232. PluginIdentity id;
  2233. id.format = plugin.format;
  2234. id.name = plugin.name;
  2235. id.path = plugin.path;
  2236. id.vst2Id = plugin.vst2Id;
  2237. id.classId = plugin.classId;
  2238. id.hasClassId = plugin.hasClassId;
  2239. id.clapId = plugin.clapId;
  2240. if (plugin.format == ForeignPlugin::Format::vst3)
  2241. {
  2242. std::vector<std::uint8_t> component, controller;
  2243. if (splitFlVst3State (plugin.state, component, controller))
  2244. id.state = std::move (component);
  2245. }
  2246. else if (plugin.format == ForeignPlugin::Format::clap)
  2247. {
  2248. if (plugin.state.size() > 4) // u32 0 + the plugin's own state (REA_rodada22 §2.5)
  2249. id.state.assign (plugin.state.begin() + 4, plugin.state.end());
  2250. }
  2251. else
  2252. id.state = plugin.state;
  2253. return id;
  2254. }
  2255. std::vector<SubstituteEntry> parseSubstituteTable (std::string_view text, int* errors)
  2256. {
  2257. std::vector<SubstituteEntry> entries;
  2258. int bad = 0;
  2259. std::optional<SubstituteEntry> current;
  2260. std::string lynxName;
  2261. std::vector<std::string> presetItems, mapItems;
  2262. bool entryBad = false;
  2263. auto finish = [&] {
  2264. if (! current)
  2265. return;
  2266. const auto kind = effectKindNamed (lynxName);
  2267. if (! kind || entryBad || current->key.empty())
  2268. {
  2269. ++bad;
  2270. current.reset();
  2271. return;
  2272. }
  2273. current->effect = *kind;
  2274. for (const auto& item : presetItems)
  2275. {
  2276. const auto eq = item.rfind ('=');
  2277. float v = 0;
  2278. const auto index = eq == std::string::npos ? -1 : paramNamed (*kind, item.substr (0, eq));
  2279. if (index < 0 || ! parseFloat (trim (item.substr (eq + 1)), v))
  2280. {
  2281. ++bad;
  2282. continue;
  2283. }
  2284. current->preset.push_back ({ index, std::clamp (v, 0.0f, 1.0f) });
  2285. }
  2286. for (const auto& item : mapItems)
  2287. {
  2288. SubstituteParamMap m;
  2289. if (parseMap (item, *kind, m))
  2290. current->params.push_back (std::move (m));
  2291. else
  2292. ++bad;
  2293. }
  2294. if (current->product.empty())
  2295. current->product = current->key;
  2296. entries.push_back (std::move (*current));
  2297. current.reset();
  2298. };
  2299. std::size_t start = 0;
  2300. while (start <= text.size())
  2301. {
  2302. auto end = text.find ('\n', start);
  2303. if (end == std::string_view::npos)
  2304. end = text.size();
  2305. const auto line = trim (text.substr (start, end - start));
  2306. start = end + 1;
  2307. if (line.empty() || line[0] == '#')
  2308. continue;
  2309. if (line.front() == '[' && line.back() == ']')
  2310. {
  2311. finish();
  2312. current = SubstituteEntry {};
  2313. current->key = trim (std::string_view (line).substr (1, line.size() - 2));
  2314. lynxName.clear();
  2315. presetItems.clear();
  2316. mapItems.clear();
  2317. entryBad = false;
  2318. continue;
  2319. }
  2320. const auto eq = line.find ('=');
  2321. if (! current || eq == std::string::npos)
  2322. {
  2323. ++bad;
  2324. continue;
  2325. }
  2326. const auto key = lowerAscii (trim (std::string_view (line).substr (0, eq)));
  2327. const auto value = trim (std::string_view (line).substr (eq + 1));
  2328. auto& e = *current;
  2329. if (key == "product")
  2330. e.product = value;
  2331. else if (key == "vendor")
  2332. e.vendor = value;
  2333. else if (key == "role")
  2334. {
  2335. if (lowerAscii (value) == "instrument")
  2336. e.instrument = true;
  2337. else if (lowerAscii (value) != "effect")
  2338. entryBad = true;
  2339. }
  2340. else if (key == "lynx")
  2341. lynxName = value;
  2342. else if (key == "vst2")
  2343. {
  2344. for (const auto& item : splitList (value, ';'))
  2345. {
  2346. std::uint32_t id = 0;
  2347. if (parseVst2Id (item, id))
  2348. e.vst2Ids.push_back (id);
  2349. else
  2350. ++bad;
  2351. }
  2352. }
  2353. else if (key == "vst3")
  2354. {
  2355. for (const auto& item : splitList (value, ';'))
  2356. {
  2357. std::array<std::uint8_t, 16> id {};
  2358. if (parseHex16 (item, id))
  2359. e.vst3ClassIds.push_back (id);
  2360. else
  2361. ++bad;
  2362. }
  2363. }
  2364. else if (key == "clap")
  2365. for (const auto& item : splitList (value, ';'))
  2366. e.clapIds.push_back (item);
  2367. else if (key == "names")
  2368. for (const auto& item : splitList (value, ';'))
  2369. {
  2370. if (auto k = matchKey (item); ! k.empty())
  2371. e.names.push_back (std::move (k));
  2372. }
  2373. else if (key == "waves")
  2374. for (const auto& item : splitList (value, ';'))
  2375. {
  2376. if (auto k = matchKey (item); ! k.empty())
  2377. e.wavesNames.push_back (std::move (k));
  2378. }
  2379. else if (key == "preset")
  2380. for (auto& item : splitList (value, ';'))
  2381. presetItems.push_back (std::move (item));
  2382. else if (key == "mix")
  2383. {
  2384. float v = 1;
  2385. if (parseFloat (value, v))
  2386. e.mix = std::clamp (v, 0.0f, 1.0f);
  2387. else
  2388. ++bad;
  2389. }
  2390. else if (key == "map")
  2391. mapItems.push_back (value);
  2392. else if (key == "translate")
  2393. {
  2394. if (fabfilter::translatorNamed (value) != nullptr || rawTranslatorNamed (value) != nullptr)
  2395. e.translator = value;
  2396. else
  2397. ++bad;
  2398. }
  2399. else if (key == "vst2params")
  2400. {
  2401. float v = 0;
  2402. if (parseFloat (value, v) && v >= 1 && v <= 100000 && v == std::floor (v))
  2403. e.vst2Params = (int) v;
  2404. else
  2405. ++bad;
  2406. }
  2407. else
  2408. ++bad;
  2409. }
  2410. finish();
  2411. if (errors != nullptr)
  2412. *errors = bad;
  2413. return entries;
  2414. }
  2415. const std::vector<SubstituteEntry>& pluginSubstitutes()
  2416. {
  2417. return registry();
  2418. }
  2419. int registerPluginSubstitutes (std::string_view tableText)
  2420. {
  2421. auto added = parseSubstituteTable (tableText);
  2422. auto& entries = registry();
  2423. for (auto& entry : added)
  2424. {
  2425. entries.erase (std::remove_if (entries.begin(), entries.end(), [&] (const SubstituteEntry& e) { return e.key == entry.key; }), entries.end());
  2426. // later registrations win: they go first, so findPluginSubstitute meets them before the built-in ones
  2427. entries.insert (entries.begin(), std::move (entry));
  2428. }
  2429. return (int) added.size();
  2430. }
  2431. const SubstituteEntry* findPluginSubstitute (const PluginIdentity& plugin, bool instrument)
  2432. {
  2433. const auto& entries = registry();
  2434. auto candidates = [&] (auto&& matches) -> const SubstituteEntry* {
  2435. for (const auto& e : entries)
  2436. if (e.instrument == instrument && matches (e))
  2437. return &e;
  2438. return nullptr;
  2439. };
  2440. // 1) format identifiers
  2441. if (plugin.vst2Id != 0 && (plugin.format == ForeignPlugin::Format::vst2 || plugin.format == ForeignPlugin::Format::none))
  2442. if (auto* e = candidates ([&] (const SubstituteEntry& x) { return std::find (x.vst2Ids.begin(), x.vst2Ids.end(), plugin.vst2Id) != x.vst2Ids.end(); }))
  2443. return e;
  2444. if (plugin.hasClassId)
  2445. if (auto* e = candidates ([&] (const SubstituteEntry& x) { return std::find (x.vst3ClassIds.begin(), x.vst3ClassIds.end(), plugin.classId) != x.vst3ClassIds.end(); }))
  2446. return e;
  2447. if (! plugin.clapId.empty())
  2448. if (auto* e = candidates ([&] (const SubstituteEntry& x) { return std::find (x.clapIds.begin(), x.clapIds.end(), plugin.clapId) != x.clapIds.end(); }))
  2449. return e;
  2450. // 2) a WaveShell sub-plugin, by the name its own state carries
  2451. const auto waves = matchKey (wavesPluginName (plugin.state));
  2452. if (! waves.empty())
  2453. if (auto* e = candidates ([&] (const SubstituteEntry& x) { return std::find (x.wavesNames.begin(), x.wavesNames.end(), waves) != x.wavesNames.end(); }))
  2454. return e;
  2455. // 3) names (never the shell's file name: it holds many plugins)
  2456. std::vector<std::string> keys;
  2457. const auto nameKey = matchKey (plugin.name);
  2458. if (nameKey.rfind ("waveshell", 0) == 0)
  2459. return nullptr;
  2460. if (! nameKey.empty())
  2461. keys.push_back (nameKey);
  2462. {
  2463. auto file = plugin.path;
  2464. std::replace (file.begin(), file.end(), '\\', '/');
  2465. if (const auto slash = file.rfind ('/'); slash != std::string::npos)
  2466. file = file.substr (slash + 1);
  2467. if (const auto dot = file.rfind ('.'); dot != std::string::npos)
  2468. file = file.substr (0, dot);
  2469. if (auto k = matchKey (file); ! k.empty() && k.rfind ("waveshell", 0) != 0)
  2470. keys.push_back (std::move (k));
  2471. }
  2472. for (const auto& key : keys)
  2473. if (auto* e = candidates ([&] (const SubstituteEntry& x) {
  2474. return std::find (x.names.begin(), x.names.end(), key) != x.names.end()
  2475. || (! waves.empty() && std::find (x.wavesNames.begin(), x.wavesNames.end(), key) != x.wavesNames.end());
  2476. }))
  2477. return e;
  2478. return nullptr;
  2479. }
  2480. EffectSlot makeSubstituteSlot (const SubstituteEntry& entry, const PluginIdentity* original, int* translated)
  2481. {
  2482. auto slot = makeEffectSlot (entry.effect);
  2483. for (const auto& [index, value] : entry.preset)
  2484. if (index >= 0 && index < maxEffectParams)
  2485. slot.params[(std::size_t) index] = value;
  2486. slot.mix = entry.mix;
  2487. int count = 0;
  2488. if (original != nullptr && ! original->state.empty() && ! entry.params.empty())
  2489. {
  2490. std::optional<FlVst2State> vst2;
  2491. std::vector<std::pair<std::string, std::string>> attributes;
  2492. std::vector<double> waves;
  2493. bool attributesRead = false, wavesRead = false;
  2494. for (const auto& m : entry.params)
  2495. {
  2496. std::optional<double> value;
  2497. switch (m.source)
  2498. {
  2499. case SubstituteParamMap::Source::vst2:
  2500. {
  2501. if (! vst2)
  2502. {
  2503. FlVst2State s;
  2504. vst2 = parseFlVst2State (original->state, s) ? s : FlVst2State {}; // a chunk / unreadable: no params
  2505. }
  2506. if (vst2->params.empty())
  2507. break;
  2508. // all programs saved: the current one's block (needs the plugin's parameter count)
  2509. std::size_t base = 0, perProgram = vst2->params.size();
  2510. if (vst2->allPrograms())
  2511. {
  2512. const auto n = (std::size_t) entry.vst2Params;
  2513. if (n > 0 && vst2->params.size() % n == 0 && (std::size_t) vst2->currentProgram < vst2->params.size() / n)
  2514. {
  2515. perProgram = n;
  2516. base = (std::size_t) std::max (0, vst2->currentProgram) * n;
  2517. }
  2518. else if (n > 0 && vst2->params.size() >= n && vst2->currentProgram == 0)
  2519. perProgram = n;
  2520. else
  2521. break; // which block is current is not known
  2522. }
  2523. if ((std::size_t) m.index < perProgram)
  2524. value = (double) vst2->params[base + (std::size_t) m.index];
  2525. break;
  2526. }
  2527. case SubstituteParamMap::Source::xml:
  2528. {
  2529. if (! attributesRead)
  2530. {
  2531. attributes = juceXmlStateAttributes (original->state);
  2532. attributesRead = true;
  2533. }
  2534. for (const auto& [name, text] : attributes)
  2535. if (name == m.attribute)
  2536. {
  2537. float f = 0;
  2538. if (parseFloat (text, f))
  2539. value = (double) f;
  2540. break;
  2541. }
  2542. break;
  2543. }
  2544. case SubstituteParamMap::Source::waves:
  2545. {
  2546. if (! wavesRead)
  2547. {
  2548. waves = wavesRealWorldParams (original->state);
  2549. wavesRead = true;
  2550. }
  2551. if ((std::size_t) m.index < waves.size() && std::isfinite (waves[(std::size_t) m.index]))
  2552. value = waves[(std::size_t) m.index];
  2553. break;
  2554. }
  2555. }
  2556. if (! value)
  2557. continue;
  2558. const auto v = mapValue (m, *value);
  2559. if (m.toSlotMix)
  2560. slot.mix = v;
  2561. else if (m.target >= 0 && m.target < maxEffectParams)
  2562. slot.params[(std::size_t) m.target] = v;
  2563. ++count;
  2564. }
  2565. }
  2566. if (original != nullptr && ! original->state.empty() && ! entry.translator.empty())
  2567. if (const auto translate = rawTranslatorNamed (entry.translator))
  2568. count += translate (original->state, slot);
  2569. if (original != nullptr && ! original->state.empty() && ! entry.translator.empty())
  2570. if (const auto translate = fabfilter::translatorNamed (entry.translator))
  2571. if (const auto state = fabfilter::parseState (original->state))
  2572. count += translate (*state, slot);
  2573. // round 135: the header shows the original's preset name (LYNX engines only: an FL effect's preset box lists FL's
  2574. // own presets)
  2575. if (original != nullptr && ! original->state.empty() && flPluginsForEffect (slot.kind).empty())
  2576. slot.presetName = originalPresetName (original->state);
  2577. if (translated != nullptr)
  2578. *translated = count;
  2579. return slot;
  2580. }
  2581. std::string originalPresetName (const std::vector<std::uint8_t>& state)
  2582. {
  2583. if (const auto chunk = findBytes (state, "<PresetChunkXMLTree"); chunk != std::string::npos)
  2584. {
  2585. const auto a = findBytes (state, "<Preset Name=\"", chunk);
  2586. if (a == std::string::npos)
  2587. return {};
  2588. const auto start = a + 14;
  2589. const auto b = findBytes (state, "\"", start);
  2590. if (b == std::string::npos || b - start > 200)
  2591. return {};
  2592. return xmlUnescape (trim (std::string (state.begin() + (std::ptrdiff_t) start, state.begin() + (std::ptrdiff_t) b)));
  2593. }
  2594. for (const auto& [name, value] : juceXmlStateAttributes (state))
  2595. if (name == "presetName")
  2596. return trim (value);
  2597. return {};
  2598. }
  2599. bool substituteEffectSlot (EffectSlot& slot, const PluginIdentity& identity)
  2600. {
  2601. return substituteEffectSlot (slot, identity, SubstituteContext {});
  2602. }
  2603. bool substituteEffectSlot (EffectSlot& slot, const PluginIdentity& identity, const SubstituteContext& context)
  2604. {
  2605. if (slot.kind != EffectKind::plugin)
  2606. return false;
  2607. const auto* entry = findPluginSubstitute (identity, false);
  2608. if (entry == nullptr)
  2609. return false;
  2610. int translated = 0;
  2611. auto replacement = makeSubstituteSlot (*entry, &identity, &translated);
  2612. // a pitch corrector whose own key is unknown: the project's key (its other pitch correctors), with the entry's
  2613. // gentle retune; no key anywhere: the entry's chromatic preset
  2614. if (replacement.kind == EffectKind::lynxTune && context.knowsKey() && ! pitchCorrectorScale (identity.state))
  2615. {
  2616. replacement.params[lynxtune::key] = (float) context.key / 11.0f;
  2617. replacement.params[lynxtune::scale] = (float) context.scale / (float) (vocal::scaleCount - 1);
  2618. }
  2619. replacement.enabled = slot.enabled;
  2620. replacement.mix = std::clamp (slot.mix * replacement.mix, 0.0f, 1.0f); // nested dry/wet crossfades multiply
  2621. replacement.sidechain = slot.sidechain;
  2622. replacement.sidechain2 = slot.sidechain2;
  2623. replacement.substituteFor = slot.plugin;
  2624. if (replacement.substituteFor.name.empty())
  2625. replacement.substituteFor.name = identity.name;
  2626. slot = std::move (replacement);
  2627. return true;
  2628. }
  2629. SubstituteContext substituteContextOf (const Song& song)
  2630. {
  2631. std::vector<std::pair<std::pair<int, int>, int>> votes; // (key, scale) -> slots
  2632. auto look = [&votes] (const ForeignPlugin& plugin) {
  2633. if (plugin.format == ForeignPlugin::Format::none)
  2634. return;
  2635. const auto sc = pitchCorrectorScale (pluginIdentity (plugin).state);
  2636. if (sc && sc->scale != (int) vocal::Scale::custom)
  2637. {
  2638. const std::pair<int, int> k { sc->key, sc->scale };
  2639. auto it = std::find_if (votes.begin(), votes.end(), [&] (const auto& v) { return v.first == k; });
  2640. if (it == votes.end())
  2641. votes.push_back ({ k, 1 });
  2642. else
  2643. ++it->second;
  2644. }
  2645. };
  2646. for (const auto& track : song.mixer)
  2647. for (const auto& fx : track.effects)
  2648. {
  2649. look (fx.plugin.foreign);
  2650. look (fx.substituteFor.foreign);
  2651. }
  2652. SubstituteContext context;
  2653. int best = 0;
  2654. for (const auto& [k, n] : votes)
  2655. if (n > best)
  2656. {
  2657. best = n;
  2658. context.key = k.first;
  2659. context.scale = k.second;
  2660. }
  2661. return context;
  2662. }
  2663. bool restoreOriginalPlugin (EffectSlot& slot)
  2664. {
  2665. if (! slot.isSubstitute())
  2666. return false;
  2667. EffectSlot original;
  2668. original.kind = EffectKind::plugin;
  2669. original.enabled = slot.enabled;
  2670. original.mix = 1.0f; // the substitute's own dry/wet doesn't belong to the plugin; FL's slot mix is not kept
  2671. original.sidechain = slot.sidechain;
  2672. original.sidechain2 = slot.sidechain2;
  2673. original.plugin = std::move (slot.substituteFor);
  2674. slot = std::move (original);
  2675. return true;
  2676. }
  2677. std::string substituteOriginalName (const EffectSlot& slot)
  2678. {
  2679. if (! slot.isSubstitute())
  2680. return {};
  2681. if (! slot.substituteFor.name.empty())
  2682. return slot.substituteFor.name;
  2683. if (! slot.substituteFor.foreign.name.empty())
  2684. return slot.substituteFor.foreign.name;
  2685. return slot.substituteFor.id;
  2686. }
  2687. std::vector<std::pair<std::string, std::string>> juceXmlStateAttributes (const std::vector<std::uint8_t>& state)
  2688. {
  2689. std::vector<std::pair<std::string, std::string>> attributes;
  2690. auto start = findBytes (state, "VC2!");
  2691. start = findBytes (state, "<?xml", start == std::string::npos ? 0 : start);
  2692. if (start == std::string::npos)
  2693. return attributes;
  2694. // the first element after the declaration
  2695. std::size_t i = start + 5;
  2696. while (i < state.size() && state[i] != '>')
  2697. ++i;
  2698. while (i < state.size() && state[i] != '<')
  2699. ++i;
  2700. if (i >= state.size())
  2701. return attributes;
  2702. std::size_t end = i;
  2703. char quote = 0;
  2704. for (; end < state.size(); ++end)
  2705. {
  2706. const auto c = (char) state[end];
  2707. if (quote != 0)
  2708. {
  2709. if (c == quote)
  2710. quote = 0;
  2711. }
  2712. else if (c == '"' || c == '\'')
  2713. quote = c;
  2714. else if (c == '>')
  2715. break;
  2716. else if (c == 0)
  2717. return attributes;
  2718. }
  2719. const std::string tag (state.begin() + (std::ptrdiff_t) i + 1, state.begin() + (std::ptrdiff_t) end);
  2720. // skip the element name, then name="value" pairs
  2721. std::size_t p = 0;
  2722. while (p < tag.size() && ! std::isspace ((unsigned char) tag[p]) && tag[p] != '/')
  2723. ++p;
  2724. while (p < tag.size())
  2725. {
  2726. while (p < tag.size() && (std::isspace ((unsigned char) tag[p]) || tag[p] == '/'))
  2727. ++p;
  2728. const auto nameStart = p;
  2729. while (p < tag.size() && tag[p] != '=' && ! std::isspace ((unsigned char) tag[p]))
  2730. ++p;
  2731. const auto name = tag.substr (nameStart, p - nameStart);
  2732. while (p < tag.size() && std::isspace ((unsigned char) tag[p]))
  2733. ++p;
  2734. if (p >= tag.size() || tag[p] != '=')
  2735. break;
  2736. ++p;
  2737. while (p < tag.size() && std::isspace ((unsigned char) tag[p]))
  2738. ++p;
  2739. if (p >= tag.size() || (tag[p] != '"' && tag[p] != '\''))
  2740. break;
  2741. const auto q = tag[p++];
  2742. const auto close = tag.find (q, p);
  2743. if (close == std::string::npos)
  2744. break;
  2745. attributes.push_back ({ name, xmlUnescape (tag.substr (p, close - p)) });
  2746. p = close + 1;
  2747. }
  2748. return attributes;
  2749. }
  2750. std::string wavesPluginName (const std::vector<std::uint8_t>& state)
  2751. {
  2752. const auto chunk = findBytes (state, "<PresetChunkXMLTree");
  2753. if (chunk == std::string::npos)
  2754. return {};
  2755. const auto a = findBytes (state, "<PluginName>", chunk);
  2756. if (a == std::string::npos)
  2757. return {};
  2758. const auto b = findBytes (state, "</PluginName>", a);
  2759. if (b == std::string::npos)
  2760. return {};
  2761. return xmlUnescape (trim (std::string (state.begin() + (std::ptrdiff_t) a + 12, state.begin() + (std::ptrdiff_t) b)));
  2762. }
  2763. std::vector<double> wavesRealWorldParams (const std::vector<std::uint8_t>& state)
  2764. {
  2765. std::vector<double> values;
  2766. const auto text = wavesParametersText (state);
  2767. std::size_t p = 0;
  2768. while (p < text.size())
  2769. {
  2770. while (p < text.size() && std::isspace ((unsigned char) text[p]))
  2771. ++p;
  2772. const auto start = p;
  2773. while (p < text.size() && ! std::isspace ((unsigned char) text[p]))
  2774. ++p;
  2775. if (p == start)
  2776. break;
  2777. const auto token = text.substr (start, p - start);
  2778. if (token == "*")
  2779. {
  2780. values.push_back (std::numeric_limits<double>::quiet_NaN());
  2781. continue;
  2782. }
  2783. try
  2784. {
  2785. std::size_t used = 0;
  2786. const auto v = std::stod (token, &used);
  2787. values.push_back (used == token.size() ? v : std::numeric_limits<double>::quiet_NaN());
  2788. }
  2789. catch (...)
  2790. {
  2791. values.push_back (std::numeric_limits<double>::quiet_NaN());
  2792. }
  2793. }
  2794. return values;
  2795. }
  2796. std::string foreignToText (const ForeignPlugin& plugin)
  2797. {
  2798. std::vector<std::uint8_t> out;
  2799. putU32 (out, foreignTextMagic);
  2800. putU32 (out, (std::uint32_t) plugin.format);
  2801. putU32 (out, plugin.vst2Id);
  2802. out.insert (out.end(), plugin.classId.begin(), plugin.classId.end());
  2803. putU32 (out, plugin.hasClassId ? 1u : 0u);
  2804. putString (out, plugin.clapId);
  2805. putString (out, plugin.name);
  2806. putString (out, plugin.path);
  2807. putBytes (out, plugin.state.data(), plugin.state.size());
  2808. putU32 (out, (std::uint32_t) plugin.midiInPort);
  2809. putU32 (out, (std::uint32_t) plugin.midiOutPort);
  2810. return base64Encode (out.data(), out.size());
  2811. }
  2812. bool foreignFromText (const std::string& text, ForeignPlugin& out)
  2813. {
  2814. std::vector<std::uint8_t> data;
  2815. if (! base64Decode (text, data))
  2816. return false;
  2817. BinReader r { data };
  2818. if (r.u32() != foreignTextMagic)
  2819. return false;
  2820. ForeignPlugin p;
  2821. const auto format = r.u32();
  2822. if (format > (std::uint32_t) ForeignPlugin::Format::other)
  2823. return false;
  2824. p.format = (ForeignPlugin::Format) format;
  2825. p.vst2Id = r.u32();
  2826. if (r.pos + 16 > data.size())
  2827. return false;
  2828. std::copy (data.begin() + (std::ptrdiff_t) r.pos, data.begin() + (std::ptrdiff_t) r.pos + 16, p.classId.begin());
  2829. r.pos += 16;
  2830. p.hasClassId = r.u32() != 0;
  2831. p.clapId = r.str();
  2832. p.name = r.str();
  2833. p.path = r.str();
  2834. p.state = r.bytes();
  2835. p.midiInPort = (int) r.u32();
  2836. p.midiOutPort = (int) r.u32();
  2837. if (! r.ok)
  2838. return false;
  2839. out = std::move (p);
  2840. return true;
  2841. }
  2842. std::string base64Encode (const std::uint8_t* data, std::size_t size)
  2843. {
  2844. static constexpr char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2845. std::string out;
  2846. out.reserve ((size + 2) / 3 * 4);
  2847. for (std::size_t i = 0; i < size; i += 3)
  2848. {
  2849. const std::uint32_t b0 = data[i], b1 = i + 1 < size ? data[i + 1] : 0, b2 = i + 2 < size ? data[i + 2] : 0;
  2850. const auto v = (b0 << 16) | (b1 << 8) | b2;
  2851. out += table[(v >> 18) & 63];
  2852. out += table[(v >> 12) & 63];
  2853. out += i + 1 < size ? table[(v >> 6) & 63] : '=';
  2854. out += i + 2 < size ? table[v & 63] : '=';
  2855. }
  2856. return out;
  2857. }
  2858. bool base64Decode (const std::string& text, std::vector<std::uint8_t>& out)
  2859. {
  2860. out.clear();
  2861. std::uint32_t buffer = 0;
  2862. int bits = 0, padding = 0;
  2863. for (const auto c : text)
  2864. {
  2865. int v;
  2866. if (c >= 'A' && c <= 'Z') v = c - 'A';
  2867. else if (c >= 'a' && c <= 'z') v = c - 'a' + 26;
  2868. else if (c >= '0' && c <= '9') v = c - '0' + 52;
  2869. else if (c == '+') v = 62;
  2870. else if (c == '/') v = 63;
  2871. else if (c == '=') { ++padding; continue; }
  2872. else if (std::isspace ((unsigned char) c)) continue;
  2873. else return false;
  2874. if (padding > 0)
  2875. return false; // data after padding
  2876. buffer = (buffer << 6) | (std::uint32_t) v;
  2877. bits += 6;
  2878. if (bits >= 8)
  2879. {
  2880. bits -= 8;
  2881. out.push_back ((std::uint8_t) (buffer >> bits));
  2882. }
  2883. }
  2884. return padding <= 2;
  2885. }
  2886. std::uint64_t soundtoysPresetHash (const std::vector<std::uint8_t>& state) { return presetHash (state); }
  2887. } // namespace lynx