PluginSubstitutes.cpp 111 KB

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