Effects.cpp 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332
  1. #include "core/Patcher.h"
  2. #include "core/Effects.h"
  3. #include "core/Rack.h"
  4. #include "core/FormulaController.h"
  5. #include "core/RhythmPan.h"
  6. #include "core/MixSuite.h"
  7. #include "core/VoiceMatch.h"
  8. #include "core/EchoSuite.h"
  9. #include "core/LynxTune.h"
  10. #include "core/PeakShapes.h"
  11. #include "core/LynxVerbs.h"
  12. #include "core/LimiterLaw.h"
  13. #include "core/Effector.h"
  14. #include "core/PitcherDsp.h"
  15. #include "core/Reeverb2.h"
  16. #include "core/LuxeVerb.h"
  17. #include "core/ConvolverFx.h"
  18. #include "core/VintagePhaser.h"
  19. #include "core/EmphasisFx.h"
  20. #include "core/EmphasizerFx.h"
  21. #include "core/FlLegacyFx.h"
  22. #include "core/PocketFx.h"
  23. #include "core/FreqShifterFl.h"
  24. #include "core/LowLifterFl.h"
  25. #include "core/Vocodex.h"
  26. #include "core/FruityVocoder.h"
  27. #include "core/MaximusFx.h"
  28. #include "core/ParametricEqFl.h"
  29. #include "core/EquoFx.h"
  30. #include "core/DistructorFx.h"
  31. #include "core/MultibandDelayFx.h"
  32. #include "core/PitchShifterFl.h"
  33. #include "core/FruityDynamics.h"
  34. #include "core/FruityShapers.h"
  35. #include "core/FruityBasicFx.h"
  36. #include "core/FruityFilters.h"
  37. #include "core/NewtoneFx.h"
  38. #include "core/EdisonFx.h"
  39. #include "core/FruityDelay.h"
  40. #include "core/FrequencySplitter.h"
  41. #include "core/HardcoreFx.h"
  42. #include "core/StereoFx.h"
  43. #include "core/ChorusFx.h"
  44. #include "core/GrossBeat.h"
  45. #include "core/LovePhilter.h"
  46. #include "core/FruityDelayBank.h"
  47. #include "core/FruityMultiband.h"
  48. #include "core/FlangusFastDist.h"
  49. #include "core/FruityPhaser.h"
  50. #include "core/Biquad.h"
  51. #include "core/FacetEq.h"
  52. #include "core/ApexLimiter.h"
  53. #include "core/DynamicsSuite.h"
  54. #include "core/VoiceTools.h"
  55. #include "core/VoiceShift.h"
  56. #include "core/VisualFx.h"
  57. #include "core/FlExtraFx.h"
  58. #include "core/Scratcher.h"
  59. #include "core/Transmitter.h"
  60. #include "core/TransporterFl.h"
  61. #include "core/XyController.h"
  62. #include "core/ControlSurface.h"
  63. #include "core/HardwareInsert.h"
  64. #include <algorithm>
  65. #include <atomic>
  66. #include <limits>
  67. #include <cmath>
  68. #include <complex>
  69. #include <cstdio>
  70. #include <cstdint>
  71. #include <type_traits>
  72. #include <cstring>
  73. namespace lynx
  74. {
  75. namespace
  76. {
  77. constexpr double pi = 3.141592653589793;
  78. constexpr double maxSampleRate = 192000.0;
  79. float dbToGain (float db) noexcept { return std::pow (10.0f, db / 20.0f); }
  80. // approximate tanh (Padé), saturating at ±1: much cheaper than std::tanh per sample
  81. inline float fastTanh (float x) noexcept
  82. {
  83. if (x > 3.0f)
  84. return 1.0f;
  85. if (x < -3.0f)
  86. return -1.0f;
  87. const auto x2 = x * x;
  88. return x * (27.0f + x2) / (27.0f + 9.0f * x2);
  89. }
  90. // sine of a phase in turns (0..1) via refined parabola (error < 0.1%), for LFOs
  91. inline float sinTurns (double phase) noexcept
  92. {
  93. const auto x = (float) (phase < 0.5 ? phase : phase - 1.0) * 2.0f;
  94. const auto y = 4.0f * x * (1.0f - std::abs (x));
  95. return 0.225f * (y * std::abs (y) - y) + y;
  96. }
  97. float gainToDb (float g) noexcept { return 20.0f * std::log10 (std::max (g, 1e-9f)); }
  98. // 0..1 -> logarithmic range [lo, hi]
  99. float logRange (float v, float lo, float hi) noexcept { return lo * std::pow (hi / lo, std::clamp (v, 0.0f, 1.0f)); }
  100. // ---------------------------------------------------------------------------
  101. // Parameter mapping (shared by the DSP and the UI text)
  102. float eqGainDb (float v) { return (v - 0.5f) * 36.0f; } // -18..+18 dB
  103. float eqMidHz (float v) { return logRange (v, 200.0f, 5000.0f); }
  104. float compThresholdDb (float v) { return -60.0f + v * 60.0f; }
  105. float compRatio (float v) { return 1.0f + v * 19.0f; }
  106. float compAttackMs (float v) { return logRange (v, 0.1f, 100.0f); }
  107. float compReleaseMs (float v) { return logRange (v, 10.0f, 1000.0f); }
  108. float compMakeupDb (float v) { return v * 24.0f; }
  109. // round 150 (REA_rodada150 §6): the Renaissance Compressor's own ranges, read black-box from the trial's parameter
  110. // texts — ratio 50 … 1 … 0.5 (log-linear: 50 at 0, 1.00 at 0.625, 0.5 at 1; below 1 = expansion), gain −30 … +30 dB,
  111. // attack 0.5 … 500 ms and release 5 … 5000 ms (0.5 · 1000^v, 5 · 1000^v)
  112. float rcRatio (float v)
  113. {
  114. const auto x = (double) std::clamp (v, 0.0f, 1.0f);
  115. return (float) (x <= 0.625 ? std::exp (std::log (50.0) * (1.0 - x / 0.625)) : std::exp (std::log (0.5) * (x - 0.625) / 0.375));
  116. }
  117. float rcRatioValue (double ratio)
  118. {
  119. const auto r = std::clamp (ratio, 0.5, 50.0);
  120. return (float) (r >= 1.0 ? 0.625 * (1.0 - std::log (r) / std::log (50.0)) : 0.625 + 0.375 * std::log (r) / std::log (0.5));
  121. }
  122. float rcAttackMs (float v) { return logRange (v, 0.5f, 500.0f); }
  123. float rcReleaseMs (float v) { return logRange (v, 5.0f, 5000.0f); }
  124. float rcGainDb (float v) { return -30.0f + 60.0f * std::clamp (v, 0.0f, 1.0f); }
  125. // BPM-synced Delay divisions, in beats (quarter notes).
  126. constexpr std::array<double, 8> delayDivisions { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0 };
  127. constexpr std::array<const char*, 8> delayNames { "1/16", "1/8", "1/8 dot.", "1/4", "1/4 dot.", "1/2", "1/2 dot.", "1 bar" };
  128. int delayIndex (float v) { return std::clamp ((int) (v * (float) delayDivisions.size()), 0, (int) delayDivisions.size() - 1); }
  129. float reverbLowCutHz (float v) { return logRange (v, 20.0f, 3000.0f); } // 0 = off
  130. float reverbHighCutHz (float v) { return logRange (v, 500.0f, 22000.0f); } // 1 = off
  131. float limiterCeilingDb (float v) { return -12.0f + v * 12.0f; }
  132. float limiterGainDb (float v) { return v * 24.0f; }
  133. float limiterReleaseMs (float v) { return logRange (v, 10.0f, 1000.0f); }
  134. int filterType (float v) { return std::clamp ((int) (v * 3.0f), 0, 2); } // low-pass, high-pass, band-pass
  135. constexpr std::array<const char*, 3> filterNames { "Low-pass", "High-pass", "Band-pass" };
  136. float filterHz (float v) { return logRange (v, 20.0f, 20000.0f); }
  137. float filterQ (float v) { return logRange (v, 0.5f, 12.0f); }
  138. bool filterSteep (float v) { return v >= 0.5f; } // round 190da: the appended Slope (0 = 12 dB/oct, the old filter; 1 = 24)
  139. float distortionDriveDb (float v) { return v * 36.0f; }
  140. float distortionToneHz (float v) { return logRange (v, 800.0f, 20000.0f); }
  141. float chorusRateHz (float v) { return logRange (v, 0.05f, 5.0f); }
  142. float chorusDepthMs (float v) { return v * 8.0f; }
  143. // ---------------------------------------------------------------------------
  144. // Round 190gp: how far a declared tail lets a built-in's state fall (from far above full scale to far below −120 dBFS)
  145. constexpr double tailDecayDb = 180.0;
  146. int tailOf (double samples) noexcept { return samples < 1.0e9 ? (int) std::ceil (samples) : std::numeric_limits<int>::max() / 2; }
  147. double tailOf (const Biquad& b) noexcept { return biquadTailSamples (b.a1, b.a2, tailDecayDb); }
  148. class Eq final : public Effect
  149. {
  150. public:
  151. void prepare (double sr) noexcept override
  152. {
  153. sampleRate = sr;
  154. lastParams.fill (-1.0f); // force recalculation
  155. reset();
  156. }
  157. void reset() noexcept override
  158. {
  159. for (auto& b : bands)
  160. b.reset();
  161. }
  162. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  163. {
  164. if (params != lastParams)
  165. {
  166. lastParams = params;
  167. bands[0].shelf (sampleRate, 120.0, eqGainDb (params[0]), false);
  168. bands[1].peaking (sampleRate, eqMidHz (params[2]), 0.8, eqGainDb (params[1]));
  169. bands[2].shelf (sampleRate, 8000.0, eqGainDb (params[3]), true);
  170. output = dbToGain (eqGainDb (params[4]));
  171. tail = tailOf (tailOf (bands[0]) + tailOf (bands[1]) + tailOf (bands[2])); // (round 190gp: three IIR sections in a row)
  172. }
  173. for (int i = 0; i < n; ++i)
  174. {
  175. auto a = l[i], b = r[i];
  176. for (auto& band : bands)
  177. {
  178. a = band.process (a, 0);
  179. b = band.process (b, 1);
  180. }
  181. l[i] = a * output;
  182. r[i] = b * output;
  183. }
  184. }
  185. int tailSamples() const noexcept override { return tail; }
  186. private:
  187. double sampleRate = 44100.0;
  188. std::array<Biquad, 3> bands;
  189. std::array<float, maxEffectParams> lastParams {};
  190. float output = 1.0f;
  191. int tail = -1;
  192. };
  193. // ---------------------------------------------------------------------------
  194. class Compressor final : public Effect
  195. {
  196. public:
  197. // `initial` (may be null): the slot's parameters, so the voicing's latency is known after prepare(), before the
  198. // first block (issue #113: a Patcher plans its delay compensation right after building its nodes)
  199. explicit Compressor (const EffectParams* initial = nullptr) : vintageAtStart (initial != nullptr && (*initial)[8] >= 0.5f) {}
  200. void prepare (double sr) noexcept override
  201. {
  202. sampleRate = sr;
  203. vintage.prepare (sr);
  204. reset();
  205. if (vintageAtStart)
  206. latency.store (vintage.latency(), std::memory_order_relaxed);
  207. }
  208. void reset() noexcept override
  209. {
  210. envelopeDb = 0.0f;
  211. inPower = outPower = 0.0f;
  212. autoGain = 1.0f;
  213. vintage.reset();
  214. }
  215. // round 123: voicing 1 = the measured program-dependent compressor (core/VoiceMatch.h); it delays the audio
  216. int latencySamples() const noexcept override { return latency.load (std::memory_order_relaxed); }
  217. // round 129: the editor's meters (Effect::controlOutput): 0 = gain reduction (0..1 over 0..30 dB), 2 / 3 = input /
  218. // output peak — the level meters the compressors it stands in for show (Renaissance Compressor's three meters)
  219. float controlOutput (int k) const noexcept override
  220. {
  221. return k == 0 ? meterGr.load (std::memory_order_relaxed) : k == 2 ? meterIn.load (std::memory_order_relaxed)
  222. : k == 3 ? meterOut.load (std::memory_order_relaxed) : k == 4 ? meterLimit.load (std::memory_order_relaxed)
  223. : k == 5 ? meterChange.load (std::memory_order_relaxed) : 0.0f; // round 152: 5 = the signed gain change in dB
  224. }
  225. // round 135w: the reference's built-in 0 dBFS output limiter — the gain drops at once to keep every sample at or
  226. // under 0 dBFS and recovers over 50 ms; meter 4 = its reduction this block (0..1 over 0..12 dB), the activity pill
  227. void outputLimit (float* l, float* r, int n) noexcept
  228. {
  229. const auto rel = (float) (1.0 - std::exp (-1.0 / (0.05 * sampleRate)));
  230. float most = 1.0f;
  231. for (int i = 0; i < n; ++i)
  232. {
  233. const auto peak = std::max (std::abs (l[i]), std::abs (r[i]));
  234. limitGain += rel * (1.0f - limitGain);
  235. if (peak * limitGain > 1.0f)
  236. limitGain = 1.0f / peak;
  237. l[i] *= limitGain;
  238. r[i] *= limitGain;
  239. most = std::min (most, limitGain);
  240. }
  241. meterLimit.store (std::clamp (-20.0f * std::log10 (std::max (most, 1e-6f)) / 12.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  242. }
  243. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  244. {
  245. if (params[8] >= 0.5f)
  246. {
  247. tail = -1; // (round 190gp: the measured voicing keeps the fixed hold)
  248. latency.store (vintage.latency(), std::memory_order_relaxed);
  249. float peakIn = 0.0f, peakOut = 0.0f;
  250. for (int i = 0; i < n; ++i)
  251. peakIn = std::max (peakIn, std::max (std::abs (l[i]), std::abs (r[i])));
  252. vmatch::progcomp::Settings v;
  253. const bool rc = params[13] >= 0.5f; // round 150: the RComp ranges
  254. v.thresholdDb = compThresholdDb (params[0]);
  255. v.ratio = rc ? rcRatio (params[14]) : compRatio (params[1]);
  256. v.attackMs = rc ? rcAttackMs (params[16]) : compAttackMs (params[2]);
  257. v.releaseMs = rc ? rcReleaseMs (params[17]) : compReleaseMs (params[3]);
  258. v.gainDb = rc ? rcGainDb (params[15]) : compMakeupDb (params[4]);
  259. v.mix = std::clamp ((double) params[6], 0.0, 1.0);
  260. v.trimDb = -18.0 + 36.0 * std::clamp ((double) params[7], 0.0, 1.0);
  261. v.manual = params[9] >= 0.5f;
  262. v.opto = params[10] >= 0.5f;
  263. v.smooth = params[11] >= 0.5f;
  264. v.measuredStatic = params[18] >= 0.5f; // round 152
  265. vintage.process (l, r, n, v);
  266. if (params[12] >= 0.5f)
  267. outputLimit (l, r, n);
  268. else
  269. meterLimit.store (0.0f, std::memory_order_relaxed);
  270. for (int i = 0; i < n; ++i)
  271. peakOut = std::max (peakOut, std::max (std::abs (l[i]), std::abs (r[i])));
  272. useSidechain = false;
  273. meterGr.store (std::clamp (vintage.reductionDb() / 30.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  274. meterChange.store (vintage.changeDb(), std::memory_order_relaxed);
  275. meterIn.store (std::min (peakIn, 1.0f), std::memory_order_relaxed);
  276. meterOut.store (std::min (peakOut, 1.0f), std::memory_order_relaxed);
  277. return;
  278. }
  279. latency.store (0, std::memory_order_relaxed);
  280. // round 190gp: its declared tail — the output is the input times a gain (silence in, silence out); what settles
  281. // is the envelope, which falls with the release until it snaps to 0 (under 1e-4 dB of a reduction under 200 dB:
  282. // 15 time constants), and the output limiter's gain (50 ms). Auto gain follows its powers for seconds: the
  283. // fixed hold then.
  284. {
  285. const auto releaseSamples = (params[13] >= 0.5f ? rcReleaseMs (params[17]) : compReleaseMs (params[3])) * 0.001 * sampleRate;
  286. const auto limitSamples = params[12] >= 0.5f ? 0.05 * sampleRate : 0.0;
  287. tail = params[5] >= 0.5f ? -1 : tailOf (16.0 * std::max (releaseSamples, limitSamples) + 64.0);
  288. }
  289. // "Auto gain" (round 107): the long-term level stays where it was (slow in/out power match, ±12 dB), so the
  290. // compressor shapes the dynamics without making the track quieter. Used where its settings are a guess (a
  291. // substitute for a missing plugin, whose own makeup gain is unknown).
  292. const auto levelMatch = params[5] >= 0.5f;
  293. const auto powerCoeff = (float) std::exp (-1.0 / (1.5 * sampleRate));
  294. const auto gainCoeff = (float) std::exp (-1.0 / (0.05 * sampleRate));
  295. const bool rc = params[13] >= 0.5f; // round 150: the RComp ranges (ratio below 1 = upward expansion)
  296. const auto threshold = compThresholdDb (params[0]);
  297. const auto ratio = rc ? rcRatio (params[14]) : compRatio (params[1]);
  298. const auto attack = (float) std::exp (-1.0 / ((rc ? rcAttackMs (params[16]) : compAttackMs (params[2])) * 0.001 * sampleRate));
  299. const auto release = (float) std::exp (-1.0 / ((rc ? rcReleaseMs (params[17]) : compReleaseMs (params[3])) * 0.001 * sampleRate));
  300. const auto makeup = dbToGain (rc ? rcGainDb (params[15]) : compMakeupDb (params[4]));
  301. const bool expand = ratio < 1.0f;
  302. const auto slope = expand ? 1.0f / ratio - 1.0f : 1.0f - 1.0f / ratio; // dB of change per dB over the threshold
  303. const auto thresholdGain = dbToGain (threshold);
  304. // round 190ar: the classic voicing's FET law (off by default: nothing changes for existing projects). Measured
  305. // black-box on FET-style compressors' tone-burst probes: a 5 dB knee, and a recovery that is not one time
  306. // constant — deep reduction comes back fast, the last decibels slowly. Per second the reduction G (dB) falls by
  307. // G / tail + G² / (10 dB · release), tail = the release time (at most 2.7 s): the classic exponential for
  308. // small reductions, 2 × as fast at 10 dB, 3 × at 20 dB.
  309. const bool fet = params[19] >= 0.5f && ! expand;
  310. const auto fetReleaseS = (rc ? rcReleaseMs (params[17]) : compReleaseMs (params[3])) * 0.001;
  311. const auto fetTail = (float) (1.0 / (std::min (fetReleaseS, 2.7) * sampleRate));
  312. const auto fetDeep = (float) (1.0 / (10.0 * fetReleaseS * sampleRate));
  313. constexpr float fetKnee = 5.0f;
  314. const auto fetKneeGain = dbToGain (threshold - 0.5f * fetKnee);
  315. const auto sidechain = useSidechain;
  316. useSidechain = false;
  317. float peakIn = 0.0f, peakOut = 0.0f, maxGr = 0.0f;
  318. // round 129: parallel mix (dry with the compressed signal) and a trim after it (±18 dB); older projects load
  319. // 100 % / 0 dB
  320. const auto wetMix = std::clamp (params[6], 0.0f, 1.0f);
  321. const auto trim = dbToGain (-18.0f + 36.0f * std::clamp (params[7], 0.0f, 1.0f));
  322. for (int i = 0; i < n; ++i)
  323. {
  324. peakIn = std::max (peakIn, std::max (std::abs (l[i]), std::abs (r[i])));
  325. // linked stereo peak detector, "hard knee" curve; below the threshold the log is not needed.
  326. // With sidechain, the detector listens to the other track (kick ducking)
  327. const auto peak = sidechain ? (sideL != nullptr ? std::max (std::abs (sideL[i]), std::abs (sideR[i])) : 0.0f)
  328. : std::max (std::abs (l[i]), std::abs (r[i]));
  329. float reductionDb;
  330. if (fet)
  331. {
  332. reductionDb = 0.0f;
  333. if (peak > fetKneeGain)
  334. {
  335. const auto over = gainToDb (peak) - threshold;
  336. reductionDb = slope * (over >= 0.5f * fetKnee ? over : (over + 0.5f * fetKnee) * (over + 0.5f * fetKnee) / (2.0f * fetKnee));
  337. }
  338. if (reductionDb > envelopeDb)
  339. envelopeDb = reductionDb + attack * (envelopeDb - reductionDb);
  340. else
  341. envelopeDb = std::max (reductionDb, envelopeDb - envelopeDb * (fetTail + envelopeDb * fetDeep));
  342. }
  343. else
  344. {
  345. reductionDb = peak > thresholdGain ? (gainToDb (peak) - threshold) * slope : 0.0f; // the change (≥ 0)
  346. // the envelope rises with the attack and falls with the release
  347. const auto coeff = reductionDb > envelopeDb ? attack : release;
  348. envelopeDb = reductionDb + coeff * (envelopeDb - reductionDb);
  349. }
  350. if (envelopeDb < 1.0e-4f)
  351. envelopeDb = 0.0f; // no audible reduction: skip the pow
  352. auto gain = envelopeDb > 0.0f ? dbToGain (expand ? envelopeDb : -envelopeDb) * makeup : makeup;
  353. if (levelMatch)
  354. {
  355. const auto in = 0.5f * (l[i] * l[i] + r[i] * r[i]);
  356. inPower = in + powerCoeff * (inPower - in);
  357. const auto out = in * gain * gain;
  358. outPower = out + powerCoeff * (outPower - out);
  359. // follow only while there is signal (silence keeps the last match)
  360. const auto target = inPower > 1.0e-8f && outPower > 1.0e-12f ? std::clamp (std::sqrt (inPower / outPower), 0.25f, 4.0f) : autoGain;
  361. autoGain = target + gainCoeff * (autoGain - target);
  362. gain *= autoGain;
  363. }
  364. l[i] = (l[i] * gain * wetMix + l[i] * (1.0f - wetMix)) * trim;
  365. r[i] = (r[i] * gain * wetMix + r[i] * (1.0f - wetMix)) * trim;
  366. maxGr = std::max (maxGr, envelopeDb);
  367. }
  368. if (params[12] >= 0.5f)
  369. outputLimit (l, r, n);
  370. else
  371. meterLimit.store (0.0f, std::memory_order_relaxed);
  372. for (int i = 0; i < n; ++i)
  373. peakOut = std::max (peakOut, std::max (std::abs (l[i]), std::abs (r[i])));
  374. meterGr.store (std::clamp ((expand ? 0.0f : maxGr) / 30.0f, 0.0f, 1.0f), std::memory_order_relaxed);
  375. meterChange.store (expand ? maxGr : -maxGr, std::memory_order_relaxed); // round 152: signed (the expansion's boost > 0)
  376. meterIn.store (std::min (peakIn, 1.0f), std::memory_order_relaxed);
  377. meterOut.store (std::min (peakOut, 1.0f), std::memory_order_relaxed);
  378. }
  379. void setSidechain (const float* left, const float* right) noexcept override
  380. {
  381. sideL = left;
  382. sideR = right;
  383. useSidechain = true;
  384. }
  385. int tailSamples() const noexcept override { return tail; }
  386. private:
  387. int tail = -1;
  388. std::atomic<float> meterGr { 0.0f }, meterIn { 0.0f }, meterOut { 0.0f }, meterLimit { 0.0f }, meterChange { 0.0f };
  389. float limitGain = 1.0f;
  390. std::atomic<int> latency { 0 };
  391. vmatch::progcomp::Compressor vintage;
  392. bool vintageAtStart = false;
  393. double sampleRate = 44100.0;
  394. float envelopeDb = 0.0f;
  395. float inPower = 0.0f, outPower = 0.0f, autoGain = 1.0f;
  396. const float* sideL = nullptr;
  397. const float* sideR = nullptr;
  398. bool useSidechain = false;
  399. };
  400. // ---------------------------------------------------------------------------
  401. // Round 190kg (perf): the basic Delay's glide over one chunk whose reads all lie before its writes — the same
  402. // operations per sample as Delay::process's own glide (the length steps toward the target and snaps within 0.001
  403. // sample; the line read between samples; the feedback low-pass), the two sides in one loop. Returns the samples it
  404. // glided (fewer than m when the glide lands). GCC's straight-line vectoriser paired the two sides into half-filled
  405. // vectors with more shuffles than work here, so it is off for this function (no effect on the results: the same
  406. // IEEE operations either way)
  407. #if defined(__GNUC__) && ! defined(__clang__)
  408. __attribute__ ((optimize ("no-tree-slp-vectorize")))
  409. #endif
  410. int delayGlideChunk (double& cur, double target, double glideK, const float* bufL, const float* bufR, std::size_t size,
  411. std::size_t at, int m, float dampCoeff, float& dampL, float& dampR, float* eL, float* eR) noexcept
  412. {
  413. auto c = cur;
  414. auto lpL = dampL, lpR = dampR;
  415. int k = 0;
  416. // flat: no position of the chunk wraps — its writes end before the line's end, and every read (≥ 1 sample after
  417. // the line's start: the lengths are ≤ the larger of `c` and `target`) lies after the start; the read positions are
  418. // then plain differences, the same ones the wrapping arithmetic gives
  419. const auto longest = (std::size_t) (std::int64_t) std::max (c, target);
  420. if (at + (std::size_t) m <= size && at >= longest + 1)
  421. {
  422. for (; k < m && c != target; ++k, ++at)
  423. {
  424. const auto diff = target - c;
  425. c = std::abs (diff) < 0.001 ? target : c + diff * glideK;
  426. const auto wholeSigned = (std::int64_t) c;
  427. const auto frac = (float) (c - (double) wholeSigned);
  428. const auto from = at - (std::size_t) wholeSigned;
  429. const auto xL = bufL[from], xR = bufR[from];
  430. lpL += dampCoeff * ((xL + (bufL[from - 1] - xL) * frac) - lpL);
  431. lpR += dampCoeff * ((xR + (bufR[from - 1] - xR) * frac) - lpR);
  432. eL[k] = lpL;
  433. eR[k] = lpR;
  434. }
  435. }
  436. else
  437. for (; k < m && c != target; ++k)
  438. {
  439. const auto diff = target - c;
  440. c = std::abs (diff) < 0.001 ? target : c + diff * glideK;
  441. const auto wholeSigned = (std::int64_t) c; // (≥ 1 and < size)
  442. const auto whole = (std::size_t) wholeSigned;
  443. const auto frac = (float) (c - (double) wholeSigned);
  444. const auto from = at >= whole ? at - whole : at + size - whole, before = from == 0 ? size - 1 : from - 1;
  445. const auto xL = bufL[from], xR = bufR[from];
  446. lpL += dampCoeff * ((xL + (bufL[before] - xL) * frac) - lpL);
  447. lpR += dampCoeff * ((xR + (bufR[before] - xR) * frac) - lpR);
  448. eL[k] = lpL;
  449. eR[k] = lpR;
  450. if (++at == size)
  451. at = 0;
  452. }
  453. cur = c;
  454. dampL = lpL;
  455. dampR = lpR;
  456. return k;
  457. }
  458. class Delay final : public Effect
  459. {
  460. public:
  461. static constexpr double maxSeconds = 3.0;
  462. // Round 190ie (issue #185): a tempo change glides the delay to its new length in this time, as FL's Fruity Delay 3
  463. // does at its default Time smoothing (REA_rodada52 §3.2, REA_rodada190ie): d ← d + (target − d)·k per sample with
  464. // k = 1 − 0.01^(1 / (T·rate)), snapped onto the target within 0.001 sample, read between samples (linear)
  465. static constexpr double glideSeconds = 0.5;
  466. Delay()
  467. {
  468. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 4;
  469. buffer[0].assign (size, 0.0f);
  470. buffer[1].assign (size, 0.0f);
  471. }
  472. void prepare (double sr) noexcept override
  473. {
  474. sampleRate = sr;
  475. glideK = 1.0 - std::pow (0.01, 1.0 / (glideSeconds * sr));
  476. reset();
  477. }
  478. void reset() noexcept override
  479. {
  480. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  481. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  482. damp[0] = damp[1] = 0.0f;
  483. write = 0;
  484. settled = false;
  485. }
  486. void process (float* l, float* r, int n, const EffectParams& params, double bpm) noexcept override
  487. {
  488. const auto index = delayIndex (params[0]);
  489. const auto beats = delayDivisions[(std::size_t) index];
  490. const auto seconds = std::min (maxSeconds - 0.01, beats * 60.0 / std::max (bpm, 20.0));
  491. const auto delaySamples = std::max<std::size_t> (1, (std::size_t) (seconds * sampleRate));
  492. const auto feedback = params[1] * 0.95f;
  493. const auto mix = params[2];
  494. const auto pingPong = params[3] > 0.5f;
  495. const auto dampCoeff = 1.0f - params[4] * 0.9f; // 1 = no filter in the feedback path
  496. const auto size = buffer[0].size();
  497. // the first block and a move of the Time knob take the new length at once (as before round 190ie); only a
  498. // tempo change glides (the renderer steps the tempo at every block of a tempo clip: each step was a jump of
  499. // the read position, a click at the block rate that the feedback kept)
  500. const auto target = (double) delaySamples;
  501. if (! settled || index != lastIndex)
  502. current = target;
  503. settled = true;
  504. lastIndex = index;
  505. // round 190kg (perf, bit for bit): the same arithmetic in the same order per sample, arranged for fewer
  506. // instructions. The state lives in locals (the buffers' floats could alias the float members: every sample
  507. // stored and reloaded them); positions wrap by a compare instead of a division; the glide's conversions are
  508. // signed (the length is ≥ 1 and < 2^53: the same values, without the unsigned conversions' slow paths). And
  509. // when the line is longer than a chunk, no sample of the chunk can read what the chunk writes, so the chunk
  510. // runs in two passes: the echoes as the line holds them through the feedback low-pass (serial), then the line's
  511. // writes and the outputs (independent per sample: vectorisable, still one IEEE operation each, in the same order)
  512. float* const bufL = buffer[0].data();
  513. float* const bufR = buffer[1].data();
  514. auto w = write;
  515. auto dampL = damp[0], dampR = damp[1];
  516. auto cur = current;
  517. const auto steadyPos = [&] (std::size_t at) noexcept { return (at + size - delaySamples) % size; };
  518. // one glide step, then the echo read between samples at write position `at`
  519. const auto glideRead = [&] (std::size_t at0, float& echoL, float& echoR) noexcept {
  520. const auto diff = target - cur;
  521. cur = std::abs (diff) < 0.001 ? target : cur + diff * glideK;
  522. const auto wholeSigned = (std::int64_t) cur; // (≥ 1 and < size)
  523. const auto whole = (std::size_t) wholeSigned;
  524. const auto frac = (float) (cur - (double) wholeSigned);
  525. const auto at = at0 >= whole ? at0 - whole : at0 + size - whole, before = at == 0 ? size - 1 : at - 1;
  526. echoL = bufL[at] + (bufL[before] - bufL[at]) * frac;
  527. echoR = bufR[at] + (bufR[before] - bufR[at]) * frac;
  528. };
  529. const auto run = [&] (auto pingPongOn) noexcept {
  530. constexpr bool pp = decltype (pingPongOn)::value;
  531. // one sample as before round 190kg's passes (the chunks a short line could read back)
  532. const auto sample = [&] (int i, float echoL, float echoR) noexcept {
  533. // 1-pole low-pass in the feedback path: repeats get darker
  534. dampL += dampCoeff * (echoL - dampL);
  535. dampR += dampCoeff * (echoR - dampR);
  536. echoL = dampL;
  537. echoR = dampR;
  538. const auto inL = l[i], inR = r[i];
  539. if constexpr (pp) // mono input on the left side, repeats alternate
  540. {
  541. bufL[w] = 0.5f * (inL + inR) + echoR * feedback;
  542. bufR[w] = echoL * feedback;
  543. }
  544. else
  545. {
  546. bufL[w] = inL + echoL * feedback;
  547. bufR[w] = inR + echoR * feedback;
  548. }
  549. l[i] = inL + mix * echoL;
  550. r[i] = inR + mix * echoR;
  551. if (++w == size)
  552. w = 0;
  553. };
  554. constexpr int chunk = 64;
  555. float eL[chunk], eR[chunk];
  556. for (int i = 0; i < n;)
  557. {
  558. const int m = std::min (chunk, n - i);
  559. // (the glide moves monotonically between `cur` and `target`: every length read in the chunk is ≥ the
  560. // smaller one's whole part)
  561. if (std::min (cur, target) <= (double) (m + 1))
  562. {
  563. for (const int end = i + m; i < end; ++i)
  564. {
  565. float echoL, echoR;
  566. if (cur != target) // gliding toward the new tempo's length
  567. glideRead (w, echoL, echoR);
  568. else // the steady length: whole samples, bit for bit as before
  569. {
  570. const auto readPos = steadyPos (w);
  571. echoL = bufL[readPos];
  572. echoR = bufR[readPos];
  573. }
  574. sample (i, echoL, echoR);
  575. }
  576. continue;
  577. }
  578. // 1. the echoes through the feedback path's low-pass: read between samples while the glide moves
  579. // (nothing the chunk writes is read: every length is > m), then whole samples at the steady length
  580. const int g = cur != target ? delayGlideChunk (cur, target, glideK, bufL, bufR, size, w, m, dampCoeff, dampL, dampR, eL, eR) : 0;
  581. if (g < m) // (one loop per side: no shuffles between them)
  582. {
  583. auto at = w + (std::size_t) g;
  584. if (at >= size)
  585. at -= size;
  586. const auto from = steadyPos (at);
  587. const auto steady = [&] (const float* line, float& lp, float* e) noexcept {
  588. auto readPos = from;
  589. for (int k = g; k < m; ++k)
  590. {
  591. lp += dampCoeff * (line[readPos] - lp);
  592. e[k] = lp;
  593. if (++readPos == size)
  594. readPos = 0;
  595. }
  596. };
  597. steady (bufL, dampL, eL);
  598. steady (bufR, dampR, eR);
  599. }
  600. // 2. the line's writes and the outputs, in runs up to the line's end
  601. for (int done = 0; done < m;)
  602. {
  603. const int seg = (int) std::min<std::size_t> ((std::size_t) (m - done), size - w);
  604. float* const outL = l + i + done;
  605. float* const outR = r + i + done;
  606. float* const lineL = bufL + w;
  607. float* const lineR = bufR + w;
  608. const float* const echoL = eL + done;
  609. const float* const echoR = eR + done;
  610. for (int k = 0; k < seg; ++k)
  611. {
  612. const auto inL = outL[k], inR = outR[k];
  613. if constexpr (pp)
  614. {
  615. lineL[k] = 0.5f * (inL + inR) + echoR[k] * feedback;
  616. lineR[k] = echoL[k] * feedback;
  617. }
  618. else
  619. {
  620. lineL[k] = inL + echoL[k] * feedback;
  621. lineR[k] = inR + echoR[k] * feedback;
  622. }
  623. outL[k] = inL + mix * echoL[k];
  624. outR[k] = inR + mix * echoR[k];
  625. }
  626. done += seg;
  627. w += (std::size_t) seg;
  628. if (w == size)
  629. w = 0;
  630. }
  631. i += m;
  632. }
  633. };
  634. if (pingPong)
  635. run (std::true_type {});
  636. else
  637. run (std::false_type {});
  638. current = cur;
  639. write = w;
  640. damp[0] = dampL;
  641. damp[1] = dampR;
  642. }
  643. private:
  644. double sampleRate = 44100.0;
  645. double glideK = 1.0;
  646. double current = 0.0; // the length read now (samples), gliding toward the tempo's
  647. int lastIndex = -1;
  648. bool settled = false;
  649. std::array<std::vector<float>, 2> buffer;
  650. std::size_t write = 0;
  651. float damp[2] {};
  652. };
  653. // ---------------------------------------------------------------------------
  654. // Schroeder/Moorer-style reverb (the "Freeverb" structure, public domain):
  655. // 8 comb filters with low-pass in the feedback + 4 all-passes per side.
  656. class Reverb final : public Effect
  657. {
  658. public:
  659. Reverb()
  660. {
  661. const auto scale = maxSampleRate / 44100.0;
  662. for (int ch = 0; ch < 2; ++ch)
  663. {
  664. for (std::size_t i = 0; i < combTunings.size(); ++i)
  665. combs[ch][i].buffer.assign ((std::size_t) ((combTunings[i] + stereoSpread) * scale) + 2, 0.0f);
  666. for (std::size_t i = 0; i < allpassTunings.size(); ++i)
  667. allpasses[ch][i].buffer.assign ((std::size_t) ((allpassTunings[i] + stereoSpread) * scale) + 2, 0.0f);
  668. }
  669. predelayBuffer.assign ((std::size_t) (maxPredelaySeconds * maxSampleRate) + 4, 0.0f);
  670. }
  671. static constexpr double maxPredelaySeconds = 1.0;
  672. void prepare (double sr) noexcept override
  673. {
  674. sampleRate = sr;
  675. lastLowCut = lastHighCut = -1.0f;
  676. const auto scale = sr / 44100.0;
  677. for (int ch = 0; ch < 2; ++ch)
  678. {
  679. const auto spread = ch == 1 ? stereoSpread : 0;
  680. for (std::size_t i = 0; i < combTunings.size(); ++i)
  681. combs[ch][i].length = std::min (combs[ch][i].buffer.size(), (std::size_t) ((combTunings[i] + spread) * scale));
  682. for (std::size_t i = 0; i < allpassTunings.size(); ++i)
  683. allpasses[ch][i].length = std::min (allpasses[ch][i].buffer.size(), (std::size_t) ((allpassTunings[i] + spread) * scale));
  684. }
  685. reset();
  686. }
  687. void reset() noexcept override
  688. {
  689. for (auto& side : combs)
  690. for (auto& c : side)
  691. {
  692. std::fill (c.buffer.begin(), c.buffer.end(), 0.0f);
  693. c.index = 0;
  694. c.store = 0.0f;
  695. }
  696. for (auto& side : allpasses)
  697. for (auto& a : side)
  698. {
  699. std::fill (a.buffer.begin(), a.buffer.end(), 0.0f);
  700. a.index = 0;
  701. }
  702. std::fill (predelayBuffer.begin(), predelayBuffer.end(), 0.0f);
  703. predelayWrite = 0;
  704. lowCut.reset();
  705. highCut.reset();
  706. }
  707. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  708. {
  709. const auto feedback = 0.7f + params[0] * 0.28f; // room size
  710. const auto damping = params[1] * 0.4f;
  711. const auto width = params[2];
  712. const auto mix = params[3];
  713. const auto dry = params[4]; // 0 = reverb only (reverb on a send)
  714. const auto wet1 = width / 2.0f + 0.5f;
  715. const auto wet2 = (1.0f - width) / 2.0f;
  716. constexpr float inputGain = 0.015f;
  717. // at the wet input: low/high cut (at the extremes = off) and predelay
  718. const auto lowCutHz = params[5], highCutHz = params[6];
  719. const auto useLowCut = lowCutHz > 0.001f, useHighCut = highCutHz < 0.999f;
  720. if (lowCutHz != lastLowCut || highCutHz != lastHighCut)
  721. {
  722. lastLowCut = lowCutHz;
  723. lastHighCut = highCutHz;
  724. lowCut.filter (sampleRate, 1, reverbLowCutHz (lowCutHz), 0.7071);
  725. highCut.filter (sampleRate, 0, reverbHighCutHz (highCutHz), 0.7071);
  726. }
  727. const auto predelay = std::min ((int) (params[7] * maxPredelaySeconds * sampleRate), (int) predelayBuffer.size() - 1);
  728. const auto predelayLength = (int) predelayBuffer.size();
  729. // filter by filter over a chunk (each comb/allpass fully in cache), with the same summing
  730. // order as sample-by-sample processing
  731. constexpr int span = 256;
  732. float input[span], out[2][span];
  733. for (int start = 0; start < n; start += span)
  734. {
  735. const auto m = std::min (span, n - start);
  736. auto* bl = l + start;
  737. auto* br = r + start;
  738. for (int i = 0; i < m; ++i)
  739. {
  740. auto x = (bl[i] + br[i]) * inputGain;
  741. if (useLowCut)
  742. x = lowCut.process (x, 0);
  743. if (useHighCut)
  744. x = highCut.process (x, 0);
  745. if (predelay > 0)
  746. {
  747. predelayBuffer[(std::size_t) predelayWrite] = x;
  748. auto read = predelayWrite - predelay;
  749. if (read < 0)
  750. read += predelayLength;
  751. x = predelayBuffer[(std::size_t) read];
  752. if (++predelayWrite == predelayLength)
  753. predelayWrite = 0;
  754. }
  755. input[i] = x;
  756. }
  757. for (int ch = 0; ch < 2; ++ch)
  758. {
  759. std::fill (out[ch], out[ch] + m, 0.0f);
  760. // 4 combs per loop: the feedback chains are independent and the CPU interleaves
  761. // them (a single comb is bound by the damping filter's latency)
  762. for (std::size_t c = 0; c + 4 <= combs[ch].size(); c += 4)
  763. Comb::process4 (&combs[ch][c], input, out[ch], m, feedback, damping);
  764. for (auto& a : allpasses[ch])
  765. a.process (out[ch], m);
  766. }
  767. for (int i = 0; i < m; ++i)
  768. {
  769. bl[i] = bl[i] * dry + mix * (out[0][i] * wet1 + out[1][i] * wet2);
  770. br[i] = br[i] * dry + mix * (out[1][i] * wet1 + out[0][i] * wet2);
  771. }
  772. }
  773. }
  774. private:
  775. struct Comb
  776. {
  777. std::vector<float> buffer;
  778. std::size_t length = 1, index = 0;
  779. float store = 0.0f;
  780. // four combs at once; sums into `out` in the same order as one by one
  781. static void process4 (Comb* c, const float* input, float* out, int n, float feedback, float damping) noexcept
  782. {
  783. float* buf[4] = { c[0].buffer.data(), c[1].buffer.data(), c[2].buffer.data(), c[3].buffer.data() };
  784. std::size_t idx[4] = { c[0].index, c[1].index, c[2].index, c[3].index };
  785. const std::size_t len[4] = { c[0].length, c[1].length, c[2].length, c[3].length };
  786. float st[4] = { c[0].store, c[1].store, c[2].store, c[3].store };
  787. const auto keep = 1.0f - damping;
  788. for (int i = 0; i < n; ++i)
  789. {
  790. float o[4];
  791. for (int k = 0; k < 4; ++k)
  792. {
  793. o[k] = buf[k][idx[k]];
  794. st[k] = o[k] * keep + st[k] * damping;
  795. buf[k][idx[k]] = input[i] + st[k] * feedback;
  796. if (++idx[k] == len[k])
  797. idx[k] = 0;
  798. }
  799. out[i] = out[i] + o[0] + o[1] + o[2] + o[3];
  800. }
  801. for (int k = 0; k < 4; ++k)
  802. {
  803. c[k].index = idx[k];
  804. c[k].store = st[k];
  805. }
  806. }
  807. };
  808. struct Allpass
  809. {
  810. std::vector<float> buffer;
  811. std::size_t length = 1, index = 0;
  812. void process (float* io, int n) noexcept
  813. {
  814. auto* buf = buffer.data();
  815. auto idx = index;
  816. const auto len = length;
  817. for (int i = 0; i < n; ++i)
  818. {
  819. const auto input = io[i];
  820. const auto delayed = buf[idx];
  821. io[i] = delayed - input;
  822. buf[idx] = input + delayed * 0.5f;
  823. if (++idx == len)
  824. idx = 0;
  825. }
  826. index = idx;
  827. }
  828. };
  829. static constexpr std::array<int, 8> combTunings { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 };
  830. static constexpr std::array<int, 4> allpassTunings { 556, 441, 341, 225 };
  831. static constexpr int stereoSpread = 23;
  832. std::array<std::array<Comb, 8>, 2> combs;
  833. std::array<std::array<Allpass, 4>, 2> allpasses;
  834. double sampleRate = 44100.0;
  835. Biquad lowCut, highCut;
  836. float lastLowCut = -1.0f, lastHighCut = -1.0f;
  837. std::vector<float> predelayBuffer;
  838. int predelayWrite = 0;
  839. };
  840. // ---------------------------------------------------------------------------
  841. // Lookahead limiter: gain starts dropping before the peak arrives (1.5 ms delay,
  842. // reported as latency so PDC aligns it with the other tracks).
  843. class Limiter final : public Effect
  844. {
  845. public:
  846. static constexpr double lookaheadSeconds = 0.0015;
  847. // (rollup step 9: `l2` = the slot's settings run round 190lf's L2 law, so the latency PDC reads before the first block
  848. // is the law's window, as after it: issue #113's rule, tests/Pdc188eTests.inc)
  849. explicit Limiter (bool l2 = false) : l2Active (l2)
  850. {
  851. const auto size = (std::size_t) (lookaheadSeconds * maxSampleRate) + 4;
  852. delay[0].assign (size, 0.0f);
  853. delay[1].assign (size, 0.0f);
  854. maxValues.assign (size, 0.0f);
  855. maxTimes.assign (size, 0);
  856. // round 190lf: the L2 law's buffers, sized for 192 kHz (no allocation in prepare / process)
  857. const auto l2Size = (std::size_t) std::ceil (limiterlaw::windowAt48k * maxSampleRate / 48000.0) + 2;
  858. l2Delay[0].assign (l2Size, 0.0);
  859. l2Delay[1].assign (l2Size, 0.0);
  860. l2MinValues.assign (l2Size + 1, 1.0);
  861. l2MinTimes.assign (l2Size + 1, 0);
  862. l2BoxA.assign (l2Size, 1.0);
  863. l2BoxB.assign (l2Size, 1.0);
  864. }
  865. void prepare (double sr) noexcept override
  866. {
  867. sampleRate = sr;
  868. // (never past the delay line: it holds 1.5 ms at 192 kHz, and a device above that rate wrote past its end —
  869. // issue #134: the default project has this limiter on its Master)
  870. lookahead = std::clamp ((int) std::lround (lookaheadSeconds * sr), 1, (int) delay[0].size());
  871. attack = (float) (1.0 - std::exp (-1.0 / (lookahead * 0.3)));
  872. // round 190lf: the L2 law's window and smoothing, scaled from 48 kHz (window = boxA + boxB - 1)
  873. const auto scale = sr / 48000.0;
  874. l2BoxALength = std::clamp ((int) std::lround (limiterlaw::boxAAt48k * scale), 1, (int) l2BoxA.size());
  875. l2BoxBLength = std::clamp ((int) std::lround (limiterlaw::boxBAt48k * scale), 1, (int) l2BoxB.size());
  876. l2Window = std::clamp (l2BoxALength + l2BoxBLength - 1, 1, (int) l2Delay[0].size());
  877. l2Attack = 1.0 - std::exp (-1.0 / (limiterlaw::arcFollowAttackS * sr));
  878. l2Release = 1.0 - std::exp (-1.0 / (limiterlaw::arcFollowReleaseS * sr));
  879. reset();
  880. }
  881. void reset() noexcept override
  882. {
  883. std::fill (delay[0].begin(), delay[0].end(), 0.0f);
  884. std::fill (delay[1].begin(), delay[1].end(), 0.0f);
  885. position = 0;
  886. gain = 1.0f;
  887. clock = 0;
  888. // the window starts full of zeros: a single 0 candidate covers all of them
  889. head = 0;
  890. count = 1;
  891. maxValues[0] = 0.0f;
  892. maxTimes[0] = -1;
  893. resetL2();
  894. }
  895. int latencySamples() const noexcept override { return l2Active.load (std::memory_order_relaxed) ? l2Window : lookahead; }
  896. int tailSamples() const noexcept override { return tail; }
  897. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  898. {
  899. if (limiterlaw::isL2 (params[(std::size_t) limiterlaw::lawParam]))
  900. {
  901. processL2 (l, r, n, params);
  902. return;
  903. }
  904. if (l2Active.load (std::memory_order_relaxed))
  905. l2Active.store (false, std::memory_order_relaxed);
  906. const auto ceiling = dbToGain (limiterCeilingDb (params[0]));
  907. const auto input = dbToGain (limiterGainDb (params[1]));
  908. const auto release = (float) (1.0 - std::exp (-1.0 / (limiterReleaseMs (params[2]) * 0.001 * sampleRate)));
  909. // round 190gp: its declared tail — the look-ahead line empties, then the gain climbs back to where it stops
  910. // moving (16 release time constants)
  911. tail = tailOf (lookahead + 16.0 * limiterReleaseMs (params[2]) * 0.001 * sampleRate + 64.0);
  912. for (int i = 0; i < n; ++i)
  913. {
  914. const auto a = l[i] * input, b = r[i] * input;
  915. const auto peak = std::max (std::abs (a), std::abs (b));
  916. // largest peak among the last `lookahead` samples (sliding maximum with a monotonic queue)
  917. const auto capacity = (int) maxValues.size();
  918. while (count > 0 && maxValues[(std::size_t) ((head + count - 1) % capacity)] <= peak)
  919. --count;
  920. const auto slot = (std::size_t) ((head + count) % capacity);
  921. maxValues[slot] = peak;
  922. maxTimes[slot] = clock;
  923. ++count;
  924. if (maxTimes[(std::size_t) head] <= clock - lookahead)
  925. {
  926. head = (head + 1) % capacity;
  927. --count;
  928. }
  929. ++clock;
  930. const auto ahead = maxValues[(std::size_t) head];
  931. const auto target = ahead > ceiling ? ceiling / ahead : 1.0f;
  932. gain += (target - gain) * (target < gain ? attack : release);
  933. const auto outL = delay[0][(std::size_t) position] * gain;
  934. const auto outR = delay[1][(std::size_t) position] * gain;
  935. delay[0][(std::size_t) position] = a;
  936. delay[1][(std::size_t) position] = b;
  937. if (++position == lookahead)
  938. position = 0;
  939. // safety: never exceed the ceiling
  940. l[i] = std::clamp (outL, -ceiling, ceiling);
  941. r[i] = std::clamp (outR, -ceiling, ceiling);
  942. }
  943. }
  944. private:
  945. // round 190lf: the L2 law (core/LimiterLaw.h, docs/analise/REA_rodada190lf.md §2). The Gain knob is the make-up
  946. // (an L2 threshold t and ceiling c: gain = c − t), the input limited at ceiling / gain: the gain each sample needs, its
  947. // minimum over the window, ARC's follower of that minimum and its release (or the Release knob's), two moving
  948. // averages; the audio delayed by the window. Every constant is LYNX's own fit on our Waves-demo probes.
  949. void processL2 (float* l, float* r, int n, const EffectParams& params) noexcept
  950. {
  951. namespace ll = limiterlaw;
  952. if (! l2Active.load (std::memory_order_relaxed))
  953. {
  954. resetL2();
  955. l2Active.store (true, std::memory_order_relaxed);
  956. }
  957. const double ceiling = std::pow (10.0, limiterCeilingDb (params[0]) / 20.0);
  958. const double gainDb = (double) limiterGainDb (params[1]) - 24.0 * (double) params[(std::size_t) ll::trimParam];
  959. const double threshold = ceiling / std::pow (10.0, gainDb / 20.0);
  960. const double makeup = std::min (ceiling, ll::ceilingMax) / threshold;
  961. const bool arc = params[(std::size_t) ll::arcParam] >= 0.5f;
  962. const double releaseS = limiterReleaseMs (params[2]) * 0.001 * ll::manualTimeScale;
  963. const double manual = std::exp (-1.0 / (releaseS * sampleRate));
  964. tail = tailOf (l2Window + 16.0 * (arc ? ll::arcFollowReleaseS : releaseS) * sampleRate + 64.0);
  965. const int capacity = (int) l2MinValues.size();
  966. for (int i = 0; i < n; ++i)
  967. {
  968. const double a = l[i], b = r[i];
  969. const double peak = std::max (std::abs (a), std::abs (b));
  970. const double need = peak > threshold ? threshold / peak : 1.0;
  971. // the smallest need over the last l2Window samples (sliding minimum with a monotonic queue)
  972. while (l2Count > 0 && l2MinValues[(std::size_t) ((l2Head + l2Count - 1) % capacity)] >= need)
  973. --l2Count;
  974. const auto slot = (std::size_t) ((l2Head + l2Count) % capacity);
  975. l2MinValues[slot] = need;
  976. l2MinTimes[slot] = l2Clock;
  977. ++l2Count;
  978. if (l2MinTimes[(std::size_t) l2Head] <= l2Clock - l2Window)
  979. {
  980. l2Head = (l2Head + 1) % capacity;
  981. --l2Count;
  982. }
  983. ++l2Clock;
  984. const double least = l2MinValues[(std::size_t) l2Head];
  985. double g = least;
  986. if (arc)
  987. {
  988. l2Follow += (least - l2Follow) * (least < l2Follow ? l2Attack : l2Release);
  989. g = std::min (least, l2Follow);
  990. }
  991. if (g <= l2Gain)
  992. l2Gain = g;
  993. else
  994. {
  995. auto keep = manual;
  996. if (arc)
  997. {
  998. const double u = std::max (std::log (std::max (l2Gain, 1.0e-12)), ll::arcDepthFloor);
  999. const double v = std::clamp ((l2Follow - l2Gain) / std::max (l2Follow, 1.0e-9), 0.0, 1.0);
  1000. const auto& q = ll::arcLaw;
  1001. const double rate = std::exp (std::min (q[0] + q[1] * u + q[2] * v + q[3] * u * v + q[4] * u * u + q[5] * v * v, 12.0));
  1002. keep = std::exp (-rate / sampleRate);
  1003. }
  1004. l2Gain = g + (l2Gain - g) * keep;
  1005. }
  1006. // two moving averages (their running sums recomputed at every wrap: no drift)
  1007. l2SumA += l2Gain - l2BoxA[(std::size_t) l2IndexA];
  1008. l2BoxA[(std::size_t) l2IndexA] = l2Gain;
  1009. if (++l2IndexA == l2BoxALength)
  1010. {
  1011. l2IndexA = 0;
  1012. l2SumA = 0.0;
  1013. for (int k = 0; k < l2BoxALength; ++k)
  1014. l2SumA += l2BoxA[(std::size_t) k];
  1015. }
  1016. const double first = l2SumA / l2BoxALength;
  1017. l2SumB += first - l2BoxB[(std::size_t) l2IndexB];
  1018. l2BoxB[(std::size_t) l2IndexB] = first;
  1019. if (++l2IndexB == l2BoxBLength)
  1020. {
  1021. l2IndexB = 0;
  1022. l2SumB = 0.0;
  1023. for (int k = 0; k < l2BoxBLength; ++k)
  1024. l2SumB += l2BoxB[(std::size_t) k];
  1025. }
  1026. const double smooth = l2SumB / l2BoxBLength * makeup;
  1027. const auto p = (std::size_t) l2Position;
  1028. const double outL = l2Delay[0][p] * smooth, outR = l2Delay[1][p] * smooth;
  1029. l2Delay[0][p] = a;
  1030. l2Delay[1][p] = b;
  1031. if (++l2Position >= l2Window)
  1032. l2Position = 0;
  1033. l[i] = (float) outL;
  1034. r[i] = (float) outR;
  1035. }
  1036. }
  1037. void resetL2() noexcept
  1038. {
  1039. std::fill (l2Delay[0].begin(), l2Delay[0].end(), 0.0);
  1040. std::fill (l2Delay[1].begin(), l2Delay[1].end(), 0.0);
  1041. std::fill (l2BoxA.begin(), l2BoxA.end(), 1.0);
  1042. std::fill (l2BoxB.begin(), l2BoxB.end(), 1.0);
  1043. l2SumA = (double) l2BoxALength;
  1044. l2SumB = (double) l2BoxBLength;
  1045. l2IndexA = l2IndexB = l2Position = 0;
  1046. l2Follow = l2Gain = 1.0;
  1047. l2Clock = 0;
  1048. l2Head = 0;
  1049. l2Count = 1;
  1050. l2MinValues[0] = 1.0;
  1051. l2MinTimes[0] = -1;
  1052. }
  1053. double sampleRate = 44100.0;
  1054. int lookahead = 64, position = 0;
  1055. float attack = 0.1f, gain = 1.0f;
  1056. std::array<std::vector<float>, 2> delay;
  1057. std::vector<float> maxValues; // monotonic (decreasing) queue for the sliding maximum
  1058. std::vector<std::int64_t> maxTimes;
  1059. int head = 0, count = 0;
  1060. std::int64_t clock = 0;
  1061. int tail = -1;
  1062. std::atomic<bool> l2Active { false };
  1063. int l2Window = 64, l2BoxALength = 27, l2BoxBLength = 38, l2Position = 0, l2IndexA = 0, l2IndexB = 0;
  1064. double l2Attack = 0.0, l2Release = 0.0, l2Follow = 1.0, l2Gain = 1.0, l2SumA = 27.0, l2SumB = 38.0;
  1065. std::array<std::vector<double>, 2> l2Delay;
  1066. std::vector<double> l2MinValues, l2BoxA, l2BoxB; // monotonic (increasing) queue for the sliding minimum; the averages
  1067. std::vector<std::int64_t> l2MinTimes;
  1068. int l2Head = 0, l2Count = 0;
  1069. std::int64_t l2Clock = 0;
  1070. };
  1071. // ---------------------------------------------------------------------------
  1072. class Filter final : public Effect
  1073. {
  1074. public:
  1075. void prepare (double sr) noexcept override
  1076. {
  1077. sampleRate = sr;
  1078. last.fill (-1.0f);
  1079. reset();
  1080. }
  1081. void reset() noexcept override
  1082. {
  1083. biquad.reset();
  1084. second.reset();
  1085. }
  1086. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  1087. {
  1088. if (params[0] != last[0] || params[1] != last[1] || params[2] != last[2] || params[4] != last[4])
  1089. {
  1090. const auto wasSteep = filterSteep (last[4]);
  1091. last = params;
  1092. const auto q = filterQ (params[2]);
  1093. biquad.filter (sampleRate, filterType (params[0]), filterHz (params[1]), q);
  1094. steep = filterSteep (params[4]);
  1095. if (steep)
  1096. {
  1097. second.filter (sampleRate, filterType (params[0]), filterHz (params[1]), filterSecondStageQ (q));
  1098. if (! wasSteep)
  1099. second.reset();
  1100. }
  1101. tail = tailOf (tailOf (biquad) + (steep ? tailOf (second) : 0.0)); // (round 190gp)
  1102. }
  1103. const auto mix = params[3];
  1104. if (steep)
  1105. {
  1106. for (int i = 0; i < n; ++i)
  1107. {
  1108. l[i] += (second.process (biquad.process (l[i], 0), 0) - l[i]) * mix;
  1109. r[i] += (second.process (biquad.process (r[i], 1), 1) - r[i]) * mix;
  1110. }
  1111. return;
  1112. }
  1113. for (int i = 0; i < n; ++i)
  1114. {
  1115. l[i] += (biquad.process (l[i], 0) - l[i]) * mix;
  1116. r[i] += (biquad.process (r[i], 1) - r[i]) * mix;
  1117. }
  1118. }
  1119. int tailSamples() const noexcept override { return tail; }
  1120. private:
  1121. double sampleRate = 44100.0;
  1122. Biquad biquad, second;
  1123. bool steep = false;
  1124. EffectParams last {};
  1125. int tail = -1;
  1126. };
  1127. // ---------------------------------------------------------------------------
  1128. class Distortion final : public Effect
  1129. {
  1130. public:
  1131. void prepare (double sr) noexcept override
  1132. {
  1133. sampleRate = sr;
  1134. lastTone = -1.0f;
  1135. reset();
  1136. }
  1137. void reset() noexcept override { tone.reset(); }
  1138. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  1139. {
  1140. if (params[1] != lastTone)
  1141. {
  1142. lastTone = params[1];
  1143. tone.filter (sampleRate, 0, distortionToneHz (params[1]), 0.707);
  1144. tail = tailOf (tailOf (tone)); // (round 190gp: the shaper has no memory; the tone filter rings out)
  1145. }
  1146. const auto drive = dbToGain (distortionDriveDb (params[0]));
  1147. const auto mix = params[2];
  1148. const auto output = dbToGain ((params[3] - 0.5f) * 24.0f);
  1149. // compensate the drive gain so the volume doesn't blow up
  1150. const auto compensate = 1.0f / fastTanh (std::max (drive, 1.0f));
  1151. for (int i = 0; i < n; ++i)
  1152. {
  1153. const auto wl = tone.process (fastTanh (l[i] * drive) * compensate, 0);
  1154. const auto wr = tone.process (fastTanh (r[i] * drive) * compensate, 1);
  1155. l[i] = (l[i] + (wl - l[i]) * mix) * output;
  1156. r[i] = (r[i] + (wr - r[i]) * mix) * output;
  1157. }
  1158. }
  1159. int tailSamples() const noexcept override { return tail; }
  1160. private:
  1161. double sampleRate = 44100.0;
  1162. Biquad tone;
  1163. float lastTone = -1.0f;
  1164. int tail = -1;
  1165. };
  1166. // ---------------------------------------------------------------------------
  1167. // Chorus: an LFO-modulated delay line, with opposite phases on L and R.
  1168. class Chorus final : public Effect
  1169. {
  1170. public:
  1171. static constexpr double maxSeconds = 0.05;
  1172. Chorus()
  1173. {
  1174. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 4;
  1175. buffer[0].assign (size, 0.0f);
  1176. buffer[1].assign (size, 0.0f);
  1177. }
  1178. void prepare (double sr) noexcept override
  1179. {
  1180. sampleRate = sr;
  1181. length = (int) std::min<std::size_t> (buffer[0].size(), (std::size_t) (maxSeconds * sr) + 4);
  1182. reset();
  1183. }
  1184. void reset() noexcept override
  1185. {
  1186. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  1187. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  1188. write = 0;
  1189. phase = 0.0;
  1190. }
  1191. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  1192. {
  1193. const auto rate = chorusRateHz (params[0]);
  1194. const auto depth = chorusDepthMs (params[1]) * 0.001 * sampleRate;
  1195. const auto mix = params[2];
  1196. const auto feedback = params[3] * 0.7f;
  1197. const auto base = 0.012 * sampleRate; // 12 ms
  1198. const auto step = rate / sampleRate;
  1199. for (int i = 0; i < n; ++i)
  1200. {
  1201. float* io[2] = { l + i, r + i };
  1202. const auto s = sinTurns (phase); // L and R in opposite phases: the same sine with flipped sign
  1203. for (int ch = 0; ch < 2; ++ch)
  1204. {
  1205. const auto lfo = ch == 0 ? s : -s;
  1206. const auto delaySamples = base + depth * 0.5 * (1.0 + lfo);
  1207. auto readPos = (double) write - delaySamples;
  1208. while (readPos < 0.0)
  1209. readPos += length;
  1210. const auto i0 = (int) readPos;
  1211. const auto frac = (float) (readPos - i0);
  1212. const auto& buf = buffer[(std::size_t) ch];
  1213. const auto next = i0 + 1 == length ? 0 : i0 + 1;
  1214. const auto delayed = buf[(std::size_t) i0] + frac * (buf[(std::size_t) next] - buf[(std::size_t) i0]);
  1215. buffer[(std::size_t) ch][(std::size_t) write] = *io[ch] + delayed * feedback;
  1216. *io[ch] += (delayed - *io[ch]) * mix * 0.5f;
  1217. }
  1218. if (++write == length)
  1219. write = 0;
  1220. phase += step;
  1221. if (phase >= 1.0)
  1222. phase -= 1.0;
  1223. }
  1224. }
  1225. private:
  1226. double sampleRate = 44100.0;
  1227. std::array<std::vector<float>, 2> buffer;
  1228. int length = 1, write = 0;
  1229. double phase = 0.0;
  1230. };
  1231. // ---------------------------------------------------------------------------
  1232. // 7-band parametric EQ: each band is a cookbook biquad (or up to 4 in series for the cuts,
  1233. // with the Qs of a Butterworth of the requested order).
  1234. constexpr std::array<std::array<double, 4>, 4> butterworthQ { { { 0.70710678, 0, 0, 0 },
  1235. { 0.54119610, 1.30656296, 0, 0 },
  1236. { 0.51763809, 0.70710678, 1.93185165, 0 },
  1237. { 0.50979558, 0.60134489, 0.89997622, 2.56291545 } } };
  1238. // Stage coefficients of a band; returns the number of stages (0 = band off/transparent).
  1239. int bandStages (const EffectParams& p, int band, double sr, std::array<Biquad, 4>& out) noexcept
  1240. {
  1241. const auto t = peq::type (p[(std::size_t) peq::param (band, 0)]);
  1242. const auto hz = std::min (peq::hz (p[(std::size_t) peq::param (band, 1)]), sr * 0.45);
  1243. const auto db = peq::gainDb (p[(std::size_t) peq::param (band, 2)]);
  1244. const auto q = peq::q (p[(std::size_t) peq::param (band, 3)]);
  1245. switch (t)
  1246. {
  1247. case peq::BandType::off: return 0;
  1248. case peq::BandType::peak:
  1249. if (std::abs (db) < 0.01)
  1250. return 0;
  1251. out[0].peaking (sr, hz, q, db);
  1252. return 1;
  1253. case peq::BandType::lowShelf:
  1254. case peq::BandType::highShelf:
  1255. if (std::abs (db) < 0.01)
  1256. return 0;
  1257. out[0].shelf (sr, hz, db, t == peq::BandType::highShelf, std::clamp (q, 0.1, 4.0)); // Q = shelf slope S
  1258. return 1;
  1259. case peq::BandType::lowCut:
  1260. case peq::BandType::highCut:
  1261. {
  1262. // cascaded: the Qs of a Butterworth of that order, scaled by the band Q (0.707 = Butterworth)
  1263. const auto stages = peq::slopeStages (p[(std::size_t) (peq::slopeParam + band)]);
  1264. const auto& qs = butterworthQ[(std::size_t) (stages - 1)];
  1265. for (int s = 0; s < stages; ++s)
  1266. out[(std::size_t) s].filter (sr, t == peq::BandType::lowCut ? 1 : 0, hz, stages == 1 ? q : qs[(std::size_t) s] * q / 0.70710678);
  1267. return stages;
  1268. }
  1269. case peq::BandType::bandPass:
  1270. out[0].filter (sr, 2, hz, q);
  1271. return 1;
  1272. case peq::BandType::notch:
  1273. {
  1274. const auto w = 2.0 * pi * hz / sr;
  1275. const auto alpha = std::sin (w) / (2.0 * q);
  1276. out[0].set (1, -2 * std::cos (w), 1, 1 + alpha, -2 * std::cos (w), 1 - alpha);
  1277. return 1;
  1278. }
  1279. }
  1280. return 0;
  1281. }
  1282. class ParametricEq final : public Effect
  1283. {
  1284. public:
  1285. ParametricEq() = default;
  1286. // a slot imported from FL: its engine is set up at once, so the latency is known before the first block
  1287. explicit ParametricEq (const EffectParams& params)
  1288. {
  1289. if (peq::flLaw (params))
  1290. {
  1291. lastParams = params;
  1292. flMode = true;
  1293. fl.set (peqfl::fromParams (params));
  1294. }
  1295. }
  1296. void prepare (double sr) noexcept override
  1297. {
  1298. sampleRate = sr;
  1299. if (! flMode)
  1300. lastParams.fill (-1.0f);
  1301. fl.prepare (sr);
  1302. reset();
  1303. }
  1304. void reset() noexcept override
  1305. {
  1306. for (auto& band : stages)
  1307. for (auto& s : band)
  1308. s.reset();
  1309. fl.reset();
  1310. }
  1311. int latencySamples() const noexcept override { return flMode ? fl.latencySamples() : 0; }
  1312. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  1313. {
  1314. if (peq::flLaw (params))
  1315. {
  1316. // FL's Parametric EQ 2 / Parametric EQ, exact (core/ParametricEqFl.h)
  1317. if (params != lastParams || ! flMode)
  1318. {
  1319. lastParams = params;
  1320. flMode = true;
  1321. fl.set (peqfl::fromParams (params));
  1322. }
  1323. fl.process (l, r, n);
  1324. tail = -1;
  1325. listen (l, r, n, params);
  1326. return;
  1327. }
  1328. flMode = false;
  1329. if (params != lastParams)
  1330. {
  1331. lastParams = params;
  1332. active = 0;
  1333. for (int b = 0; b < peq::bands; ++b)
  1334. {
  1335. std::array<Biquad, 4> fresh;
  1336. const auto count = bandStages (params, b, sampleRate, fresh);
  1337. // keep the state of filters that remain (no click when turning a knob)
  1338. for (int s = 0; s < count; ++s)
  1339. {
  1340. auto& stage = stages[(std::size_t) b][(std::size_t) s];
  1341. stage.b0 = fresh[(std::size_t) s].b0; stage.b1 = fresh[(std::size_t) s].b1; stage.b2 = fresh[(std::size_t) s].b2;
  1342. stage.a1 = fresh[(std::size_t) s].a1; stage.a2 = fresh[(std::size_t) s].a2;
  1343. }
  1344. for (int s = count; s < 4; ++s)
  1345. stages[(std::size_t) b][(std::size_t) s].reset();
  1346. for (int s = 0; s < count; ++s)
  1347. order[(std::size_t) active++] = &stages[(std::size_t) b][(std::size_t) s];
  1348. }
  1349. output = (float) std::pow (10.0, peq::gainDb (params[peq::outputParam]) / 20.0);
  1350. double samples = 0.0; // (round 190gp: its sections in a row; FL's engines keep the fixed hold)
  1351. for (int k = 0; k < active; ++k)
  1352. samples += tailOf (*order[(std::size_t) k]);
  1353. tail = tailOf (samples);
  1354. }
  1355. for (int k = 0; k < active; ++k)
  1356. order[(std::size_t) k]->processBlock (l, r, n);
  1357. if (output != 1.0f)
  1358. for (int i = 0; i < n; ++i)
  1359. {
  1360. l[i] *= output;
  1361. r[i] *= output;
  1362. }
  1363. listen (l, r, n, params);
  1364. }
  1365. // round 190ih: the momentary band solo (peq::setSoloBand)
  1366. std::atomic<int> solo { -1 };
  1367. private:
  1368. // after the EQ (its latency and sound kept), only the soloed band's region passes
  1369. void listen (float* l, float* r, int n, const EffectParams& params) noexcept
  1370. {
  1371. const auto band = solo.load (std::memory_order_relaxed);
  1372. if (band < 0 || band >= peq::bands)
  1373. {
  1374. soloShown = -1;
  1375. return;
  1376. }
  1377. const auto hz = params[(std::size_t) peq::param (band, 1)];
  1378. const auto width = params[(std::size_t) peq::param (band, 3)];
  1379. if (band != soloShown || hz != soloHz || width != soloWidth)
  1380. {
  1381. if (band != soloShown)
  1382. soloFilter.reset();
  1383. soloShown = band;
  1384. soloHz = hz;
  1385. soloWidth = width;
  1386. EffectParams bp {};
  1387. bp[(std::size_t) peq::param (0, 0)] = peq::typeValue (peq::BandType::bandPass);
  1388. bp[(std::size_t) peq::param (0, 1)] = hz;
  1389. bp[(std::size_t) peq::param (0, 3)] = peq::qValue (peq::soloQ (params, band));
  1390. std::array<Biquad, 4> fresh;
  1391. if (bandStages (bp, 0, sampleRate, fresh) > 0)
  1392. {
  1393. soloFilter.b0 = fresh[0].b0; soloFilter.b1 = fresh[0].b1; soloFilter.b2 = fresh[0].b2;
  1394. soloFilter.a1 = fresh[0].a1; soloFilter.a2 = fresh[0].a2;
  1395. }
  1396. }
  1397. soloFilter.processBlock (l, r, n);
  1398. }
  1399. Biquad soloFilter;
  1400. int soloShown = -1;
  1401. float soloHz = -1.0f, soloWidth = -1.0f;
  1402. double sampleRate = 44100.0;
  1403. std::array<std::array<Biquad, 4>, peq::bands> stages;
  1404. std::array<Biquad*, peq::bands * 4> order {};
  1405. int active = 0;
  1406. float output = 1.0f;
  1407. EffectParams lastParams {};
  1408. peqfl::Engine fl;
  1409. bool flMode = false;
  1410. int tail = -1;
  1411. public:
  1412. int tailSamples() const noexcept override { return tail; }
  1413. };
  1414. // ---------------------------------------------------------------------------
  1415. // Utility: stereo matrix (L->L, R->L, L->R, R->R), balance and gain.
  1416. float utilityGainDb (float v) { return (v - 0.5f) * 48.0f; } // ±24 dB
  1417. float utilityMatrix (float v) { return v * 4.0f - 2.0f; } // −2..2 (0.75 = 1.0)
  1418. // Volume gate: 32 steps per 4-beat bar (Gross Beat's "volume"). Per-step gain,
  1419. // mix with the original signal and attack/release smoothing.
  1420. namespace gate
  1421. {
  1422. constexpr int steps = 32;
  1423. constexpr int mixParam = 32, attackParam = 33, releaseParam = 34;
  1424. inline double attackMs (float v) { return std::pow (501.0, (double) v) - 1.0; }
  1425. inline double releaseMs (float v) { return 2.0 * (std::pow (501.0, (double) v) - 1.0); }
  1426. } // namespace gate
  1427. class VolumeGate final : public Effect
  1428. {
  1429. public:
  1430. void prepare (double sr) noexcept override { sampleRate = sr; }
  1431. void reset() noexcept override { gain = 1.0f; }
  1432. void setSongPosition (double ticks) noexcept override { tick = ticks; }
  1433. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1434. {
  1435. const auto mix = std::clamp (p[gate::mixParam], 0.0f, 1.0f);
  1436. const auto up = (float) (1.0 - std::exp (-1.0 / (std::max (0.05, gate::attackMs (p[gate::attackParam])) * 0.001 * sampleRate)));
  1437. const auto down = (float) (1.0 - std::exp (-1.0 / (std::max (0.05, gate::releaseMs (p[gate::releaseParam])) * 0.001 * sampleRate)));
  1438. const auto ticksPerSample = std::max (1.0, bpm) / 60.0 * ppq / sampleRate;
  1439. const auto bar = 4.0 * ppq;
  1440. auto position = std::fmod (std::max (0.0, tick), bar);
  1441. for (int i = 0; i < n; ++i)
  1442. {
  1443. const auto step = std::clamp ((int) (position / bar * gate::steps), 0, gate::steps - 1);
  1444. const auto target = 1.0f - mix + mix * std::clamp (p[(std::size_t) step], 0.0f, 1.0f);
  1445. gain += (target - gain) * (target > gain ? up : down);
  1446. l[i] *= gain;
  1447. r[i] *= gain;
  1448. position += ticksPerSample;
  1449. if (position >= bar)
  1450. position -= bar;
  1451. }
  1452. tick += ticksPerSample * n;
  1453. }
  1454. private:
  1455. double sampleRate = 44100.0, tick = 0.0;
  1456. float gain = 1.0f;
  1457. };
  1458. // Real-time pitch shift: two read heads on a delay line whose delay varies as a sawtooth
  1459. // (the "rotating tape"); when one head wraps around, the other is mid-window and the
  1460. // sine/cosine crossfade hides the jump. Parameters: semitones (±24), cents (±100), mix, window.
  1461. namespace pitch
  1462. {
  1463. inline double semitones (float v) { return std::round ((std::clamp ((double) v, 0.0, 1.0) - 0.5) * 48.0); }
  1464. inline double cents (float v) { return (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 200.0; }
  1465. inline double windowMs (float v) { return 20.0 + 100.0 * std::clamp ((double) v, 0.0, 1.0); }
  1466. } // namespace pitch
  1467. class PitchShift final : public Effect
  1468. {
  1469. public:
  1470. static constexpr double maxSeconds = 0.13;
  1471. PitchShift()
  1472. {
  1473. const auto size = (std::size_t) (maxSeconds * maxSampleRate) + 8;
  1474. buffer[0].assign (size, 0.0f);
  1475. buffer[1].assign (size, 0.0f);
  1476. }
  1477. void prepare (double sr) noexcept override
  1478. {
  1479. sampleRate = sr;
  1480. length = (int) std::min<std::size_t> (buffer[0].size(), (std::size_t) (maxSeconds * sr) + 8);
  1481. reset();
  1482. }
  1483. void reset() noexcept override
  1484. {
  1485. std::fill (buffer[0].begin(), buffer[0].end(), 0.0f);
  1486. std::fill (buffer[1].begin(), buffer[1].end(), 0.0f);
  1487. write = 0;
  1488. phase = 0.0;
  1489. }
  1490. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1491. {
  1492. const auto ratio = std::pow (2.0, (pitch::semitones (p[0]) + pitch::cents (p[1]) / 100.0) / 12.0);
  1493. const auto mix = std::clamp (p[2], 0.0f, 1.0f);
  1494. const auto window = std::min (pitch::windowMs (p[3]) * 0.001 * sampleRate, (double) length - 4.0);
  1495. const auto step = (1.0 - ratio) / window; // the delay grows (pitch down) or shrinks (pitch up)
  1496. for (int i = 0; i < n; ++i)
  1497. {
  1498. float* io[2] = { l + i, r + i };
  1499. buffer[0][(std::size_t) write] = *io[0];
  1500. buffer[1][(std::size_t) write] = *io[1];
  1501. const auto phaseB = phase + 0.5 >= 1.0 ? phase - 0.5 : phase + 0.5;
  1502. const auto gainA = (float) std::sin (3.141592653589793 * phase);
  1503. const auto gainB = (float) std::sin (3.141592653589793 * phaseB);
  1504. for (int c = 0; c < 2; ++c)
  1505. {
  1506. const auto shifted = gainA * read (c, 1.0 + phase * window) + gainB * read (c, 1.0 + phaseB * window);
  1507. *io[c] += (shifted - *io[c]) * mix;
  1508. }
  1509. phase += step;
  1510. phase -= std::floor (phase);
  1511. if (++write >= length)
  1512. write = 0;
  1513. }
  1514. }
  1515. private:
  1516. float read (int c, double delay) const noexcept
  1517. {
  1518. auto position = (double) write - delay;
  1519. while (position < 0.0)
  1520. position += length;
  1521. const auto i0 = (int) position;
  1522. const auto frac = (float) (position - i0);
  1523. const auto i1 = i0 + 1 >= length ? 0 : i0 + 1;
  1524. const auto& b = buffer[(std::size_t) c];
  1525. return b[(std::size_t) i0] + (b[(std::size_t) i1] - b[(std::size_t) i0]) * frac;
  1526. }
  1527. std::array<std::vector<float>, 2> buffer;
  1528. double sampleRate = 44100.0, phase = 0.0;
  1529. int length = 1, write = 0;
  1530. };
  1531. // Frequency shifter: the analytic signal (quadrature pair from two chains of 2nd-order allpasses
  1532. // in z², a ~90° "Hilbert transformer" over the useful range) multiplied by a complex oscillator.
  1533. // Parameters: shift (±2 kHz, quadratic curve around the center), mix, stereo spread
  1534. // (the right side shifts the opposite way).
  1535. namespace fshift
  1536. {
  1537. inline double hz (float v)
  1538. {
  1539. const auto x = (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 2.0;
  1540. return 2000.0 * x * std::abs (x);
  1541. }
  1542. } // namespace fshift
  1543. // Lo-fi: holds each sample for 128·t³ + 1 samples and quantizes to 65536/(2048·b² + 1) levels
  1544. // (the laws of FL Effector's Lo-fi, REA_rodada18 §3.2); linear dry/wet mix.
  1545. namespace lofi
  1546. {
  1547. int holdSamples (float v) { return (int) (128.0f * v * v * v) + 1; }
  1548. double levels (float v) { return 65536.0 / (2048.0 * v * v + 1.0); }
  1549. } // namespace lofi
  1550. // Crossover (a band of FL's Frequency Splitter, REA_rodada17 §1.2): high-pass and/or low-pass with the
  1551. // structure of each slope — 6 dB: 1st order; 12: 1 biquad Q 0.5 (inverted HP); 18: Butterworth 3
  1552. // (in FL it is an undocumented all-pass structure: approximation); 24: 2× Q 0.707; 36: Q 0.5412/1.3066/
  1553. // 0.7070 (inverted HP); 48: Butterworth 4 squared; 72: Butterworth 6 squared; 96: Butterworth 8
  1554. // squared. Parameters: 0 HP on, 1 HP cutoff, 2 HP slope, 3 LP on, 4 LP cutoff, 5 LP slope.
  1555. namespace xover
  1556. {
  1557. double hz (float v) { return 30.0 * std::pow (2.0, 9.0589 * std::clamp (v, 0.0f, 1.0f)); }
  1558. int combo (float v) { return std::clamp ((int) std::lround (v * 7.0f), 0, 7); }
  1559. constexpr int dbPerOctave[8] { 6, 12, 18, 24, 36, 48, 72, 96 };
  1560. struct Design
  1561. {
  1562. std::vector<double> qs; // 2nd-order biquads
  1563. bool firstOrder = false;
  1564. bool invertHighPass = false;
  1565. };
  1566. Design design (int c)
  1567. {
  1568. switch (c)
  1569. {
  1570. case 0: return { {}, true, false };
  1571. case 1: return { { 0.5 }, false, true };
  1572. case 2: return { { 1.0 }, true, false };
  1573. case 3: return { { 0.7071, 0.7071 }, false, false };
  1574. case 4: return { { 0.5412, 1.3066, 0.7070 }, false, true };
  1575. case 5: return { { 0.5412, 1.3066, 0.5412, 1.3066 }, false, false };
  1576. case 6: return { { 0.5176, 0.7071, 1.9319, 0.5176, 0.7071, 1.9319 }, false, false };
  1577. default: return { { 0.5098, 0.6013, 0.9000, 2.5629, 0.5098, 0.6013, 0.9000, 2.5629 }, false, false };
  1578. }
  1579. }
  1580. } // namespace xover
  1581. class Crossover final : public Effect
  1582. {
  1583. public:
  1584. void prepare (double sr) noexcept override
  1585. {
  1586. sampleRate = sr;
  1587. last.fill (-1.0f);
  1588. reset();
  1589. }
  1590. void reset() noexcept override
  1591. {
  1592. for (auto& side : sides)
  1593. {
  1594. for (auto& b : side.biquads)
  1595. b.reset();
  1596. side.firstState[0] = side.firstState[1] = 0.0;
  1597. side.firstIn[0] = side.firstIn[1] = 0.0;
  1598. }
  1599. }
  1600. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1601. {
  1602. if (p[0] != last[0] || p[1] != last[1] || p[2] != last[2] || p[3] != last[3] || p[4] != last[4] || p[5] != last[5])
  1603. {
  1604. for (int i = 0; i < 6; ++i)
  1605. last[(std::size_t) i] = p[(std::size_t) i];
  1606. configure (sides[0], p[0] > 0.5f, true, xover::hz (p[1]), xover::combo (p[2]));
  1607. configure (sides[1], p[3] > 0.5f, false, xover::hz (p[4]), xover::combo (p[5]));
  1608. }
  1609. for (auto& side : sides)
  1610. if (side.active)
  1611. for (int i = 0; i < n; ++i)
  1612. {
  1613. l[i] = (float) side.process (l[i], 0);
  1614. r[i] = (float) side.process (r[i], 1);
  1615. }
  1616. }
  1617. private:
  1618. struct Side
  1619. {
  1620. bool active = false, highPass = false, firstOrder = false;
  1621. double sign = 1.0;
  1622. std::array<Biquad, 8> biquads;
  1623. int count = 0;
  1624. double a = 0.0; // 1st order (bilinear transform)
  1625. double firstState[2] {}, firstIn[2] {};
  1626. double process (double x, int ch) noexcept
  1627. {
  1628. if (firstOrder)
  1629. {
  1630. // 1st-order low-pass: y = a·(x + x[n−1]) + (1 − 2a)·y[n−1]; the high-pass is the complement
  1631. const auto lp = a * (x + firstIn[ch]) + (1.0 - 2.0 * a) * firstState[ch];
  1632. firstIn[ch] = x;
  1633. firstState[ch] = lp;
  1634. x = highPass ? x - lp : lp;
  1635. }
  1636. for (int i = 0; i < count; ++i)
  1637. x = biquads[(std::size_t) i].process (x, ch);
  1638. return sign * x;
  1639. }
  1640. };
  1641. void configure (Side& side, bool on, bool highPass, double hz, int combo)
  1642. {
  1643. side.active = on;
  1644. if (! on)
  1645. return;
  1646. const auto d = xover::design (combo);
  1647. side.highPass = highPass;
  1648. side.firstOrder = d.firstOrder;
  1649. side.sign = highPass && d.invertHighPass ? -1.0 : 1.0;
  1650. side.count = (int) d.qs.size();
  1651. const auto f = std::clamp (hz, 10.0, 0.49 * sampleRate);
  1652. const auto k = std::tan (3.141592653589793 * f / sampleRate);
  1653. side.a = k / (1.0 + k);
  1654. for (int i = 0; i < side.count; ++i)
  1655. side.biquads[(std::size_t) i].filter (sampleRate, highPass ? 1 : 0, f, d.qs[(std::size_t) i]);
  1656. }
  1657. double sampleRate = 44100.0;
  1658. std::array<Side, 2> sides {};
  1659. std::array<float, 6> last {};
  1660. };
  1661. // Rhythmic envelope (REA_rodada20 §1.2/§1.3): period in beats, up to 12 points (position 0..1 in the period, level,
  1662. // tension); the value between two points follows the curve of the destination point. Parameters: 0 period/64 beats,
  1663. // 1 point count/12, then 3 per point (position, level, (tension + 1)/2).
  1664. namespace rhythm
  1665. {
  1666. constexpr int maxPoints = 12;
  1667. double curve (double x, double t) noexcept
  1668. {
  1669. if (std::abs (t) < 1e-6)
  1670. return x;
  1671. const auto q = std::pow (1000001.0, std::abs (t)) - 1.0;
  1672. return t > 0.0 ? 1.0 - (std::pow (1.0 + q, 1.0 - x) - 1.0) / q : (std::pow (1.0 + q, x) - 1.0) / q;
  1673. }
  1674. double valueAt (const EffectParams& p, double u) noexcept
  1675. {
  1676. const auto count = std::clamp ((int) std::lround (p[1] * maxPoints), 0, maxPoints);
  1677. if (count == 0)
  1678. return 1.0;
  1679. auto prevX = 0.0, prevY = (double) p[3];
  1680. for (int k = 0; k < count; ++k)
  1681. {
  1682. const auto x = (double) p[(std::size_t) (2 + 3 * k)], y = (double) p[(std::size_t) (3 + 3 * k)];
  1683. if (u < x)
  1684. {
  1685. const auto f = x > prevX ? (u - prevX) / (x - prevX) : 1.0;
  1686. return prevY + (y - prevY) * curve (f, 2.0 * p[(std::size_t) (4 + 3 * k)] - 1.0);
  1687. }
  1688. prevX = x;
  1689. prevY = y;
  1690. }
  1691. return prevY;
  1692. }
  1693. } // namespace rhythm
  1694. class RhythmGain final : public Effect
  1695. {
  1696. public:
  1697. void prepare (double sr) noexcept override { sampleRate = sr; }
  1698. void reset() noexcept override {}
  1699. void setSongPosition (double ticks) noexcept override { beats = ticks / 960.0; }
  1700. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1701. {
  1702. const auto period = std::max (1e-3, (double) p[0] * 64.0);
  1703. const auto step = std::max (bpm, 1.0) / 60.0 / sampleRate;
  1704. if (p[38] > 0.5f) // control only: the value becomes a live automation source, audio passes through untouched
  1705. {
  1706. const auto t = beats + step * n;
  1707. current = (float) rhythm::valueAt (p, (t - std::floor (t / period) * period) / period);
  1708. return;
  1709. }
  1710. for (int i = 0; i < n; ++i)
  1711. {
  1712. const auto t = beats + step * i;
  1713. const auto g = (float) rhythm::valueAt (p, (t - std::floor (t / period) * period) / period);
  1714. l[i] *= g;
  1715. r[i] *= g;
  1716. current = g;
  1717. }
  1718. }
  1719. float controlOutput (int) const noexcept override { return current; }
  1720. private:
  1721. double sampleRate = 44100.0, beats = 0.0;
  1722. float current = 1.0f;
  1723. };
  1724. // Auto-pan (REA_rodada20 §1.5): triangle (+1 at φ = 0, −1 at 0.5) with phase 0.75 + offset + beats/period.
  1725. // Parameters: 0 period/64 beats, 1 depth ((a + 1)/2, a = maximum pan excursion), 2 phase
  1726. // offset (cycles), 3 fixed pan ((p + 1)/2). Pan law: the utility's balance (FL's has not been decoded).
  1727. } // namespace
  1728. namespace peq
  1729. {
  1730. void setSoloBand (Effect* effect, int band) noexcept
  1731. {
  1732. if (auto* eq = dynamic_cast<ParametricEq*> (effect))
  1733. eq->solo.store (band >= 0 && band < bands ? band : -1, std::memory_order_relaxed);
  1734. }
  1735. int soloBand (const Effect* effect) noexcept
  1736. {
  1737. const auto* eq = dynamic_cast<const ParametricEq*> (effect);
  1738. return eq != nullptr ? eq->solo.load (std::memory_order_relaxed) : -1;
  1739. }
  1740. double soloQ (const EffectParams& params, int band) noexcept
  1741. {
  1742. const auto v = params[(std::size_t) param (std::clamp (band, 0, bands - 1), 3)];
  1743. return std::clamp (q (flLaw (params) ? 1.0f - v : v), 0.5, 18.0); // (FL's bandwidth grows with the value; LYNX's Q shrinks)
  1744. }
  1745. } // namespace peq
  1746. // FL's mode-0 pan law (REA_rodada27 §3.1): G_L = √2·cos((1 + pan)π/4), G_R = √2·sin((1 + pan)π/4) (unit volume),
  1747. // the near side keeps 1 − f/2 of its input and gets f/2 of the other, f = 1 − (far gain); no clamp of pan
  1748. void flPanMatrix (double pan, float& ll, float& rl, float& lr, float& rr) noexcept
  1749. {
  1750. const auto angle = (1.0 + pan) * 3.141592653589793 / 4.0;
  1751. const auto gl = std::sqrt (2.0) * std::cos (angle), gr = std::sqrt (2.0) * std::sin (angle);
  1752. ll = (float) gl, rr = (float) gr, rl = lr = 0.0f;
  1753. if (pan < 0.0)
  1754. {
  1755. const auto f = 1.0 - gr;
  1756. ll = (float) (gl * (1.0 - f / 2.0));
  1757. rl = (float) (gl * f / 2.0);
  1758. }
  1759. else if (pan > 0.0)
  1760. {
  1761. const auto f = 1.0 - gl;
  1762. rr = (float) (gr * (1.0 - f / 2.0));
  1763. lr = (float) (gr * f / 2.0);
  1764. }
  1765. }
  1766. namespace
  1767. {
  1768. // Fruity Squeeze (REA_rodada29 §2), float32 like FL: silence bypass per block → (filter, pre) → quantiser
  1769. // Lq = 32768^(1 − Steps/32768) → periodic gate Impact/Preserve (samples at 44.1 kHz × fs/44100) → (filter, post)
  1770. // → (dry·(128 − Mix) + wet·Mix)/128 × Volume/127. The SVF (2 passes per sample, LP/HP/BP/notch/peak) is always
  1771. // designed for 44.1 kHz, whatever the rate (as FL does). Parameters are FL's raw values divided by their maximum.
  1772. } // namespace
  1773. const std::array<float, 12> squeezeMax { 160, 128, 32768, 1, 4, 65536, 65536, 1, 3, 44100, 44100, 65536 };
  1774. namespace
  1775. {
  1776. class Squeeze final : public Effect
  1777. {
  1778. public:
  1779. void prepare (double sr) noexcept override
  1780. {
  1781. rate = (float) (sr / 44100.0);
  1782. reset();
  1783. }
  1784. void reset() noexcept override
  1785. {
  1786. for (auto& f : filters)
  1787. f.low = f.band = 0.0f;
  1788. counterA = counterB = 0.0f;
  1789. gateOn = false;
  1790. last.fill (-1.0f);
  1791. }
  1792. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  1793. {
  1794. bool changed = false;
  1795. for (std::size_t i = 0; i < 12; ++i)
  1796. if (p[i] != last[i])
  1797. last[i] = p[i], changed = true;
  1798. if (changed)
  1799. configure (p);
  1800. bool silent = true;
  1801. for (int i = 0; i < n && silent; ++i)
  1802. silent = std::abs (l[i]) <= 1e-6f && std::abs (r[i]) <= 1e-6f;
  1803. if (silent)
  1804. return; // FL leaves (near-)silent blocks untouched
  1805. for (int i = 0; i < n; ++i)
  1806. {
  1807. const float dryL = l[i], dryR = r[i];
  1808. float x[2] { l[i], r[i] };
  1809. if (! post && filterOn)
  1810. for (int c = 0; c < 2; ++c)
  1811. x[c] = filters[(std::size_t) c].tick (x[c], type, coefF, coefQ);
  1812. if (steps < 32768.0f)
  1813. for (auto& v : x)
  1814. v = (float) std::nearbyint (v * steps) / steps; // round half to even, like the DLL
  1815. if (impact > 0.0f)
  1816. {
  1817. float w0, w1;
  1818. if (! gateOn)
  1819. {
  1820. if (counterA <= preserve)
  1821. counterA += 1.0f, w1 = 0.0f, w0 = 1.0f;
  1822. else
  1823. {
  1824. gateOn = true;
  1825. const auto fr = counterA - preserve;
  1826. w1 = fr, w0 = 1.0f - fr, counterB = fr, counterA = 0.0f;
  1827. }
  1828. }
  1829. else if (counterB <= impact)
  1830. counterB += 1.0f, w1 = 1.0f, w0 = 0.0f;
  1831. else
  1832. {
  1833. gateOn = false;
  1834. const auto fr = counterB - impact;
  1835. w1 = 1.0f - fr, w0 = fr, counterB = 0.0f, counterA = fr;
  1836. }
  1837. const auto g = (float) (amountRaw * 1.52587890625e-05 * w1);
  1838. for (auto& v : x)
  1839. v = g * v + w0 * v;
  1840. }
  1841. if (post && filterOn)
  1842. for (int c = 0; c < 2; ++c)
  1843. x[c] = filters[(std::size_t) c].tick (x[c], type, coefF, coefQ);
  1844. l[i] = (dryL * dry + x[0] * wet) * gain;
  1845. r[i] = (dryR * dry + x[1] * wet) * gain;
  1846. }
  1847. }
  1848. private:
  1849. struct Svf
  1850. {
  1851. float low = 0.0f, band = 0.0f;
  1852. float tick (float in, int mode, float f, float q) noexcept
  1853. {
  1854. constexpr float tiny = 1.1754943508222875e-38f;
  1855. if (std::abs (in) < tiny)
  1856. in = 0.0f;
  1857. float acc[5] {};
  1858. for (int k = 0; k < 2; ++k)
  1859. {
  1860. auto t = in - q * band;
  1861. if (std::abs (t) < tiny)
  1862. t = 0.0f;
  1863. low = low + f * band;
  1864. const auto high = t - low;
  1865. band = f * high + band;
  1866. const float values[5] { low, band, high, t, low - high };
  1867. for (int i = 0; i < 5; ++i)
  1868. acc[i] += values[i] * 0.5f;
  1869. }
  1870. static constexpr int pick[5] { 0, 2, 1, 3, 4 }; // FL's types: LP, HP, BP, notch, peak
  1871. return acc[pick[std::clamp (mode, 0, 4)]];
  1872. }
  1873. };
  1874. int raw (const EffectParams& p, int k) const noexcept { return (int) std::lround (std::clamp (p[(std::size_t) k], 0.0f, 1.0f) * squeezeMax[(std::size_t) k]); }
  1875. void configure (const EffectParams& p) noexcept
  1876. {
  1877. gain = (float) raw (p, 0) * (1.0f / 127.0f);
  1878. const auto mix = (float) raw (p, 1);
  1879. dry = (128.0f - mix) / 128.0f;
  1880. wet = mix / 128.0f;
  1881. steps = std::pow (32768.0f, 1.0f - (float) raw (p, 2) / 32768.0f);
  1882. filterOn = raw (p, 3) != 0;
  1883. type = raw (p, 4);
  1884. post = raw (p, 7) == 1;
  1885. amountRaw = raw (p, 11);
  1886. auto gateLength = [this] (int v) { return (std::pow (44101.0f, (float) v / 44100.0f) - 1.0f) * rate; };
  1887. const auto preserveRaw = raw (p, 10);
  1888. auto impactRaw = raw (p, 9);
  1889. switch (raw (p, 8)) // Relation: Impact follows Preserve
  1890. {
  1891. case 1: impactRaw = preserveRaw; break;
  1892. case 2: impactRaw = preserveRaw * 2; break;
  1893. case 3: impactRaw = preserveRaw >> 1; break;
  1894. default: break;
  1895. }
  1896. impact = gateLength (impactRaw);
  1897. preserve = gateLength (preserveRaw);
  1898. // SVF at 44.1 kHz: cutoff exp-mapped between 50 Hz and 0.75·44100, q = min(2, 2/f − f/2, 2(1 − res^0.25))
  1899. const float fs = 44100.0f, lo = 50.0f, hi = fs * 0.75f;
  1900. const auto x = (float) raw (p, 6) / 65536.0f, res = (float) raw (p, 5) / 65536.0f;
  1901. auto hz = std::exp (x * (std::log (hi) - std::log (lo)) + std::log (lo));
  1902. hz = std::clamp (hz, lo, hi);
  1903. const auto ratio = std::min (hz / (fs * 2.0f), 0.25f);
  1904. coefF = (float) (std::sin (ratio * 3.141592653589793) * 2.0);
  1905. const auto a = (1.0f - std::pow (res, 0.25f)) * 2.0f;
  1906. coefQ = std::min (std::min (2.0f / coefF - coefF * 0.5f, 2.0f), a);
  1907. }
  1908. float rate = 1.0f, gain = 1.0f, dry = 0.5f, wet = 0.5f, steps = 32768.0f, impact = 0.0f, preserve = 0.0f;
  1909. float coefF = 0.5f, coefQ = 1.0f, counterA = 0.0f, counterB = 0.0f;
  1910. int type = 0, amountRaw = 0;
  1911. bool filterOn = false, post = false, gateOn = false;
  1912. std::array<Svf, 2> filters {};
  1913. std::array<float, 12> last {};
  1914. };
  1915. class AutoPan final : public Effect
  1916. {
  1917. public:
  1918. void prepare (double sr) noexcept override { sampleRate = sr; rhythm.prepare (sr); dcA = (float) std::exp (-2.0 * 3.14159265358979323846 * 8.0 / sr); }
  1919. void reset() noexcept override { rhythm.reset(); lfo = 0.0; smooth = 0.0; dcX[0] = dcX[1] = dcY[0] = dcY[1] = 0.0f; }
  1920. void setSongPosition (double ticks) noexcept override { beats = ticks / 960.0; }
  1921. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  1922. {
  1923. constexpr int rb = autopan::count; // round 136's Rhythm voicing params follow round 135's panner params
  1924. if (p.size() > rb + 11 && p[rb] > 0.5f) // round 136: the Rhythm voicing (core/RhythmPan.h)
  1925. {
  1926. rhythmpan::Settings s;
  1927. s.rateHz = rhythmpan::rateHz (p[rb + 1]);
  1928. s.sync = p[rb + 2] > 0.5f;
  1929. s.beats = rhythmpan::beats (p[rb + 3]);
  1930. s.width = 210.0 * std::clamp ((double) p[rb + 4], 0.0, 1.0);
  1931. s.offset = -105.0 + 210.0 * std::clamp ((double) p[rb + 5], 0.0, 1.0);
  1932. s.smoothing = std::clamp ((double) p[rb + 6], 0.0, 1.0);
  1933. s.pattern = p[rb + 7] < 0.25f ? 0 : p[rb + 7] < 0.625f ? 2 : p[rb + 7] < 0.875f ? 3 : 1; // left / right, ramp ◀ / ▶ (round tp172d), 8 steps
  1934. s.amount = std::clamp ((double) p[rb + 8], 0.0, 1.0);
  1935. s.phase = std::clamp ((double) p[rb + 9], 0.0, 1.0);
  1936. s.analog = p[rb + 10] < 0.25f ? 0 : (p[rb + 10] < 0.75f ? 1 : 2); // off / analog / hot
  1937. s.outputDb = -24.0 + 48.0 * std::clamp ((double) p[rb + 11], 0.0, 1.0);
  1938. // round 150: the Tweak page (envelope → rate / offset / width), Feel / Groove, past the speakers (appended)
  1939. s.rateMod = -3.0 + 6.0 * std::clamp ((double) p[rb + 12], 0.0, 1.0);
  1940. s.offsetMod = -180.0 + 360.0 * std::clamp ((double) p[rb + 13], 0.0, 1.0);
  1941. s.widthMod = -180.0 + 360.0 * std::clamp ((double) p[rb + 14], 0.0, 1.0);
  1942. s.envThresholdDb = -60.0 + 60.0 * std::clamp ((double) p[rb + 15], 0.0, 1.0);
  1943. s.envRangeDb = 1.0 + 39.0 * std::clamp ((double) p[rb + 16], 0.0, 1.0);
  1944. s.feel = -0.25 + 0.5 * std::clamp ((double) p[rb + 17], 0.0, 1.0);
  1945. s.groove = -0.25 + 0.5 * std::clamp ((double) p[rb + 18], 0.0, 1.0);
  1946. s.beyond = p[rb + 19] >= 0.5f;
  1947. if (p.size() > rb + 26) // round 152: the trigger sources and the Random source (appended)
  1948. {
  1949. s.trigger = p[rb + 20] < 0.25f ? 0 : (p[rb + 20] < 0.75f ? 1 : 2);
  1950. s.trigAudio = p[rb + 21] < 0.999f; // fully up = no audio trigger (the manual one still works)
  1951. s.trigThresholdDb = -60.0 + 60.0 * std::clamp ((double) p[rb + 21], 0.0, 1.0);
  1952. s.divider = 1 + (int) std::lround (11.0 * std::clamp ((double) p[rb + 22], 0.0, 1.0));
  1953. s.trigFilter = p[rb + 23] < 0.25f ? 0 : (p[rb + 23] < 0.75f ? 1 : 2);
  1954. s.trigFreqHz = 20.0 * std::pow (1000.0, std::clamp ((double) p[rb + 24], 0.0, 1.0));
  1955. s.manual = p[rb + 25];
  1956. s.randomSteps = p[rb + 26] >= 0.5f;
  1957. }
  1958. if (! (s == rhythmSet))
  1959. {
  1960. rhythm.set (s);
  1961. rhythmSet = s;
  1962. }
  1963. // round tp172d (look slice): PanMan's INPUT (-24 … +24 dB, 0 dB at the default) ahead of the panner and its analog stage
  1964. if (const auto gIn = (float) std::pow (10.0, autopan::inputDb (p[autopan::inputGain]) / 20.0); std::abs (gIn - 1.0f) > 1.0e-6f)
  1965. for (int i = 0; i < n; ++i)
  1966. {
  1967. l[i] *= gIn;
  1968. r[i] *= gIn;
  1969. }
  1970. rhythm.process (l, r, n, beats, bpm);
  1971. current = rhythm.currentPan();
  1972. position.store (current, std::memory_order_relaxed);
  1973. beats += n * std::max (bpm, 1.0) / 60.0 / sampleRate;
  1974. return;
  1975. }
  1976. if (autopan::sourceOf (p[autopan::source]) != autopan::Source::fl)
  1977. {
  1978. processPanner (l, r, n, p, bpm);
  1979. return;
  1980. }
  1981. const auto period = std::max (1e-3, (double) p[0] * 64.0);
  1982. const auto depth = 2.0 * p[1] - 1.0, fixed = 2.0 * p[3] - 1.0;
  1983. const auto step = std::max (bpm, 1.0) / 60.0 / sampleRate / period;
  1984. auto phase = 0.75 + p[2] + beats / period;
  1985. {
  1986. const auto f = phase + step * n - std::floor (phase + step * n);
  1987. current = (float) ((f < 0.5 ? 1.0 - 4.0 * f : -3.0 + 4.0 * f) + 1.0) * 0.5f; // wave in 0..1
  1988. }
  1989. position.store (0.5f * (float) (std::clamp (fixed + depth * (2.0 * current - 1.0), -1.0, 1.0) + 1.0), std::memory_order_relaxed);
  1990. if (p[4] > 0.5f) // control only (live automation source)
  1991. return;
  1992. // LFO tension (Love Philter, REA_rodada27 §3.3): applied to |w| with the sign kept, T = 256·(p6 − 0.5)
  1993. const auto tension = 256.0 * (p[6] - 0.5);
  1994. const auto q = tension == 0.0 ? 0.0 : (tension > 0.0 ? 1.0 : -1.0) * (std::pow (1e18, 0.05 * (std::pow (21.0, std::abs (tension) / 128.0) - 1.0)) - 1.0);
  1995. const auto flLaw = p[5] > 0.5f;
  1996. for (int i = 0; i < n; ++i, phase += step)
  1997. {
  1998. const auto f = phase - std::floor (phase);
  1999. auto w = f < 0.5 ? 1.0 - 4.0 * f : -3.0 + 4.0 * f;
  2000. if (q != 0.0)
  2001. {
  2002. const auto y = std::abs (w);
  2003. const auto shaped = q > 0.0 ? 1.0 - (std::pow (1.0 + q, 1.0 - y) - 1.0) / q : (std::pow (1.0 - q, y) - 1.0) / -q;
  2004. w = w < 0.0 ? -shaped : shaped;
  2005. }
  2006. if (flLaw) // FL's mode-0 pan law with the far side folded into the near one (REA_rodada27 §3.1)
  2007. {
  2008. float ll, rl, lr, rr;
  2009. flPanMatrix (fixed + depth * w, ll, rl, lr, rr);
  2010. const auto a = l[i], b = r[i];
  2011. l[i] = ll * a + rl * b;
  2012. r[i] = lr * a + rr * b;
  2013. continue;
  2014. }
  2015. const auto pan = std::clamp (fixed + depth * w, -1.0, 1.0);
  2016. l[i] *= (float) (pan > 0.0 ? 1.0 - pan : 1.0);
  2017. r[i] *= (float) (pan < 0.0 ? 1.0 + pan : 1.0);
  2018. }
  2019. }
  2020. // 0: the wave (0..1), 1: the pan position (0 = left, 0.5 = centre, 1 = right; round 135's display)
  2021. float controlOutput (int o) const noexcept override
  2022. {
  2023. switch (o)
  2024. {
  2025. case 1: return position.load (std::memory_order_relaxed);
  2026. case 2: return peakIn.load (std::memory_order_relaxed);
  2027. case 3: return peakOut.load (std::memory_order_relaxed);
  2028. default: return current;
  2029. }
  2030. }
  2031. private:
  2032. // round 135: the rhythmic panner's sources (the PanMan role), measured black-box on the official trial
  2033. // (docs/analise/REA_rodada135s.md §3): an equal-power balance (centre −3 dB per side, the far side silent at the
  2034. // extremes), a free LFO in Hz or steps on the beat grid swept back and forth or one way, Smoothing from a hard
  2035. // square / jump to a soft sine / glide, input and output gains and an "analog" stage (asymmetric soft saturation:
  2036. // H2 −36 dBc and H3 −54 dBc at −18 dBFS, H2 −25 / H3 −30 at −6 dBFS)
  2037. void processPanner (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept
  2038. {
  2039. using namespace autopan;
  2040. const auto src = sourceOf (p[source]);
  2041. const auto dir = directionOf (p[direction]);
  2042. const auto soft = std::clamp ((double) p[smoothing], 0.0, 1.0);
  2043. const auto depth = 2.0 * p[1] - 1.0, fixed = 2.0 * p[3] - 1.0;
  2044. const auto gIn = (float) std::pow (10.0, inputDb (p[inputGain]) / 20.0);
  2045. const auto gOut = (float) std::pow (10.0, inputDb (p[outputGain]) / 20.0);
  2046. const auto analog = p[analogStage] >= 0.5f;
  2047. const auto k = 0.05 + 12.0 * (1.0 - soft) * (1.0 - soft); // the sine's hardness (soft = a sine, hard ≈ a square)
  2048. const auto tk = std::tanh (k);
  2049. const auto steps = stepCount (p[stepsParam]);
  2050. // the period of one cycle: the free rate (Hz), or the steps on the beat grid
  2051. double inc;
  2052. if (src == Source::lfo)
  2053. inc = rateHz (p[rate]) / sampleRate;
  2054. else
  2055. inc = std::max (bpm, 1.0) / 60.0 / sampleRate / (stepBeats (p[stepNote]) * (dir == Direction::both ? 2.0 * (steps - 1) : steps));
  2056. // rhythm steps follow the song position (like the FL source); the LFO runs freely
  2057. if (src == Source::steps && beats != syncedBeats) // a new song position: back on the grid
  2058. {
  2059. lfo = beats / (stepBeats (p[stepNote]) * (dir == Direction::both ? 2.0 * (steps - 1) : steps));
  2060. syncedBeats = beats;
  2061. }
  2062. // steps glide over up to a third of a step (Smoothing 100 %), or jump (0 %)
  2063. const auto stepSec = stepBeats (p[stepNote]) * 60.0 / std::max (bpm, 1.0);
  2064. const auto glide = 1.0 - std::exp (-1.0 / (sampleRate * (0.0005 + 0.35 * soft * stepSec)));
  2065. float pos = 0.0f, pin = 0.0f, pout = 0.0f;
  2066. for (int i = 0; i < n; ++i, lfo += inc)
  2067. {
  2068. const auto f = lfo - std::floor (lfo);
  2069. double w; // −1 … +1
  2070. if (src == Source::lfo)
  2071. {
  2072. if (dir == Direction::both)
  2073. w = std::tanh (k * std::sin (2.0 * 3.14159265358979323846 * f)) / tk;
  2074. else
  2075. w = dir == Direction::right ? 2.0 * f - 1.0 : 1.0 - 2.0 * f;
  2076. smooth = w;
  2077. }
  2078. else
  2079. {
  2080. int s;
  2081. if (dir == Direction::both)
  2082. {
  2083. const auto span = 2 * (steps - 1);
  2084. const auto at = (int) std::floor (f * span);
  2085. s = at < steps ? at : span - at;
  2086. }
  2087. else
  2088. {
  2089. s = std::min (steps - 1, (int) std::floor (f * steps));
  2090. if (dir == Direction::left) s = steps - 1 - s;
  2091. }
  2092. const auto target = steps > 1 ? -1.0 + 2.0 * s / (steps - 1) : 0.0;
  2093. smooth += glide * (target - smooth);
  2094. w = smooth;
  2095. }
  2096. const auto pan = std::clamp (fixed + depth * w, -1.0, 1.0);
  2097. const auto th = (pan + 1.0) * 0.25 * 3.14159265358979323846;
  2098. pin = std::max (pin, std::max (std::abs (l[i]), std::abs (r[i])));
  2099. float a = l[i] * gIn, b = r[i] * gIn;
  2100. if (analog)
  2101. {
  2102. a = analogCurve (a, 0);
  2103. b = analogCurve (b, 1);
  2104. }
  2105. l[i] = (float) (a * std::cos (th)) * gOut;
  2106. r[i] = (float) (b * std::sin (th)) * gOut;
  2107. pout = std::max (pout, std::max (std::abs (l[i]), std::abs (r[i])));
  2108. pos = (float) pan;
  2109. }
  2110. lfo -= std::floor (lfo);
  2111. current = (float) (0.5 * (smooth + 1.0));
  2112. position.store (0.5f * (pos + 1.0f), std::memory_order_relaxed);
  2113. peakIn.store (pin, std::memory_order_relaxed);
  2114. peakOut.store (pout, std::memory_order_relaxed);
  2115. }
  2116. float analogCurve (float x, int c) noexcept
  2117. {
  2118. const auto u = std::clamp (x, -1.2f, 1.2f);
  2119. const auto y = u + 0.25f * u * u - 0.45f * u * u * u; // fitted on the trial's harmonics; DC removed after it
  2120. dcY[c] = y - dcX[c] + dcA * dcY[c];
  2121. dcX[c] = y;
  2122. return dcY[c];
  2123. }
  2124. double sampleRate = 44100.0, beats = 0.0, lfo = 0.0, smooth = 0.0, syncedBeats = -1.0;
  2125. float current = 0.5f, dcA = 0.999f, dcX[2] {}, dcY[2] {};
  2126. std::atomic<float> position { 0.5f }, peakIn { 0.0f }, peakOut { 0.0f };
  2127. rhythmpan::Engine rhythm; // round 136
  2128. rhythmpan::Settings rhythmSet;
  2129. };
  2130. // Vocoder = FL's Fruity Vocoder, exact engine (core/FruityVocoder.h, REA_rodada70; laws first read in REA_rodada20
  2131. // §4.1). Parameters (0..1): 0 bands (4 << round(5v)), 1 order (1 + round(2v)), 2 listen (0 modulator, 1 carrier,
  2132. // 2 mix), 3 swap L/R, then FL's twelve controls as (raw − min) / (max − min): 4/5 FreqMin/Max (0…65536), 6 FreqScale
  2133. // (0…128), 7 invert, 8 Formant (−1200…1200 cents), 9 band width (5…200 %), 10/11 attack/release (10…1000 ms),
  2134. // 12 hold, 13/14/15 modulator/carrier/wet levels (0…160); 16 LYNX's side-input mode. The per-band levels of the
  2135. // analysis bank travel in EffectSlot::state (FL's saved state); they apply while the band count matches.
  2136. namespace vocoder
  2137. {
  2138. int bands (float v) { return 4 << std::clamp ((int) std::lround (v * 5.0f), 0, 5); }
  2139. int order (float v) { return 1 + std::clamp ((int) std::lround (v * 2.0f), 0, 2); }
  2140. int raw (const EffectParams& p, int control)
  2141. {
  2142. const auto lo = fvocoder::controlMin (control), hi = fvocoder::controlMax (control);
  2143. return lo + (int) std::lround (std::clamp (p[(std::size_t) (4 + control)], 0.0f, 1.0f) * (float) (hi - lo));
  2144. }
  2145. int raw (float v, int control)
  2146. {
  2147. const auto lo = fvocoder::controlMin (control), hi = fvocoder::controlMax (control);
  2148. return lo + (int) std::lround (std::clamp (v, 0.0f, 1.0f) * (float) (hi - lo));
  2149. }
  2150. } // namespace vocoder
  2151. class Vocoder final : public Effect
  2152. {
  2153. public:
  2154. explicit Vocoder (const std::vector<std::uint8_t>& state)
  2155. {
  2156. if (auto s = fvocoder::parse (state))
  2157. saved = *s;
  2158. last.fill (-1.0f);
  2159. }
  2160. void prepare (double sr) noexcept override
  2161. {
  2162. engine.prepare (sr);
  2163. reset();
  2164. }
  2165. void reset() noexcept override { engine.reset(); }
  2166. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  2167. {
  2168. bool changed = false;
  2169. for (std::size_t i = 0; i < 16; ++i)
  2170. if (p[i] != last[i])
  2171. {
  2172. last[i] = p[i];
  2173. changed = true;
  2174. }
  2175. if (changed)
  2176. {
  2177. auto s = engine.state();
  2178. s.bands = vocoder::bands (p[0]);
  2179. s.order = vocoder::order (p[1]);
  2180. s.listen = std::clamp ((int) std::lround (p[2] * 2.0f), 0, 2);
  2181. s.swap = p[3] > 0.5f;
  2182. for (int c = 0; c < fvocoder::controls; ++c)
  2183. s.c[(std::size_t) c] = fvocoder::rawFromKnob (p[(std::size_t) (4 + c)], c, saved.c[(std::size_t) c]);
  2184. if (s.bands == saved.bands)
  2185. s.levels = saved.levels;
  2186. else
  2187. s.levels.fill (1.0f);
  2188. engine.setState (s);
  2189. }
  2190. // "Side inputs" (Vocodex-style): modulator = side input 1 or the own input, carrier = side input 2 or the own
  2191. // input, each in mono (L + R)/2; a configured side input that is silent gives silence
  2192. const auto separate = p[16] > 0.5f;
  2193. const bool modSide = useSide[0], carSide = useSide[1];
  2194. useSide = { false, false };
  2195. if (! separate)
  2196. {
  2197. engine.processStereo (l, r, n);
  2198. return;
  2199. }
  2200. for (int done = 0; done < n;)
  2201. {
  2202. const auto len = std::min (n - done, fvocoder::blockFrames);
  2203. for (int i = 0; i < len; ++i)
  2204. {
  2205. const auto k = (std::size_t) i, j = (std::size_t) (done + i);
  2206. const auto own = 0.5f * (l[j] + r[j]);
  2207. mod[k] = modSide ? (side[0][0] != nullptr ? 0.5f * (side[0][0][j] + side[0][1][j]) : 0.0f) : own;
  2208. car[k] = carSide ? (side[1][0] != nullptr ? 0.5f * (side[1][0][j] + side[1][1][j]) : 0.0f) : own;
  2209. }
  2210. engine.process (mod.data(), car.data(), l + done, len);
  2211. std::copy (l + done, l + done + len, r + done);
  2212. done += len;
  2213. }
  2214. }
  2215. void setSidechain (const float* left, const float* right) noexcept override
  2216. {
  2217. side[0] = { left, right };
  2218. useSide[0] = true;
  2219. }
  2220. void setSidechain2 (const float* left, const float* right) noexcept override
  2221. {
  2222. side[1] = { left, right };
  2223. useSide[1] = true;
  2224. }
  2225. // round 190ld (DP-32): the band display's live levels — FL's bands display animates each analysis band's level.
  2226. // Up to 32 columns (more bands: the loudest of each group), 6 bits each (−60…0 dB in 63 steps), four columns per
  2227. // output 0…7 packed as an exact integer in the float (vocoder::bandColumn decodes). Nothing while no editor shows them.
  2228. float controlOutput (int output) const noexcept override
  2229. {
  2230. if (! metersShown || output < 0 || output >= 8)
  2231. return 0.0f;
  2232. const auto bands = engine.state().bands;
  2233. const auto columns = std::min (bands, 32), per = std::max (1, bands / std::max (1, columns));
  2234. std::uint32_t packed = 0;
  2235. for (int c = 0; c < 4; ++c)
  2236. {
  2237. const auto column = output * 4 + c;
  2238. if (column >= columns)
  2239. break;
  2240. float peak = 0.0f;
  2241. for (int b = column * per; b < (column + 1) * per; ++b)
  2242. peak = std::max (peak, engine.bandMeter (b));
  2243. const auto q = peak > 0.001f ? std::clamp ((int) std::lround ((20.0f * std::log10 (peak) + 60.0f) * (63.0f / 60.0f)), 0, 63) : 0;
  2244. packed |= (std::uint32_t) q << (6 * c);
  2245. }
  2246. return (float) packed;
  2247. }
  2248. void setMetersShown (bool shown) noexcept override { metersShown = shown; }
  2249. private:
  2250. bool metersShown = false; // (an editor counts itself in ProcessTimes::metersWanted)
  2251. fvocoder::Engine engine;
  2252. fvocoder::State saved;
  2253. std::array<float, 16> last {};
  2254. std::array<std::array<const float*, 2>, 2> side {};
  2255. std::array<bool, 2> useSide { false, false };
  2256. std::array<float, fvocoder::blockFrames> mod {}, car {};
  2257. };
  2258. // Pitch correction (FL's Pitcher; laws in REA_rodada15 §1, rodada19 §6 and rodada30 §2). Parameters: 0 Correction
  2259. // Speed, 1 Fine Tune, 2 Bypass All, 3 Note A Freq, 4 range (index/5: min f 220/170/110/80/55/25 Hz), 5…16 note
  2260. // mask C…B (1 = allowed), 17…28 Key Bypass C…B, 29 Formant, 30 Gender, 31 Pitch Reference (0 left, 0.5
  2261. // independent, 1 right), 32 Stereo, 33 Harmonize, 34 MIDI, 35 Octaves, 36 Replace/Mix, 37 Vel, 38…41 Voice 1…4 pan.
  2262. // The DSP is FL's (core/PitcherDsp.h). Round 190ee: 42 MIDI port (FL's raw parameter 33: port = int(256 v) − 1, −1 =
  2263. // none; REA_rodada16 §1, REA_rodada30 §2.8), 43 Port routing — on (every new and FL-imported Pitcher) the notes come
  2264. // from the MIDI Out channels on that port, as in FL; off (projects saved before round 190ee, through
  2265. // upgradeLoadedEffectParams) the notes held on any Channel Rack channel, as round 173d made it.
  2266. namespace pcorr
  2267. {
  2268. constexpr int midiPortParam = 42, portRoutingParam = 43;
  2269. int midiPort (float v) noexcept { return v > 0.0f ? std::min (255, (int) (v * 256.0f) - 1) : -1; }
  2270. float midiPortValue (int port) noexcept { return port < 0 ? 0.0f : std::min (1.0f, ((float) port + 1.5f) / 256.0f); }
  2271. constexpr double minHz[6] { 220.0, 170.0, 110.0, 80.0, 55.0, 25.0 };
  2272. int range (float v) { return std::clamp ((int) std::lround (v * 5.0f), 0, 5); }
  2273. double noteA (float v) { return 55.0 * std::pow (2.0, (2.0 * v - 1.0) / 12.0); } // ×8 = A 440 at v = 0.5
  2274. } // namespace pcorr
  2275. class PitchCorrect final : public Effect
  2276. {
  2277. public:
  2278. // `initial` (may be null): the slot's parameters, so the formant path's latency is known before the first block
  2279. explicit PitchCorrect (const EffectParams* initial = nullptr)
  2280. {
  2281. dsp.reserve (maxSampleRate);
  2282. if (initial != nullptr)
  2283. latency.store ((*initial)[29] > 0.5f ? 257 : 9, std::memory_order_relaxed); // (pitcher::Pitcher::latency())
  2284. }
  2285. void prepare (double sr) noexcept override { dsp.prepare (sr); }
  2286. void reset() noexcept override
  2287. {
  2288. dsp.reset();
  2289. dsp.allNotesOff();
  2290. sounding = {};
  2291. }
  2292. // round 173d: the notes held on the Channel Rack reach the MIDI / Harmonize modes (before, nothing ever called
  2293. // the DSP's noteOn: MIDI, Octaves, Vel and the four voice pans did nothing)
  2294. void setHeldNotes (const NoteMask* channels, int count) noexcept override
  2295. {
  2296. held = channels;
  2297. heldCount = count;
  2298. }
  2299. bool followsHeldNotes() const noexcept override { return true; } // (round 190kz)
  2300. bool followsHeldNotesWith (const EffectParams& p) const noexcept override // (process(): unless the MIDI port routes its notes)
  2301. {
  2302. return ! (p[(std::size_t) pcorr::portRoutingParam] > 0.5f);
  2303. }
  2304. // round 190ee: a note from the MIDI Out channels on the Pitcher's port (FL: note in 0x180007a40, velocity / 127)
  2305. void midiNote (int key, int velocity, int) noexcept override
  2306. {
  2307. if (portRouting)
  2308. dsp.noteOn (key, velocity);
  2309. }
  2310. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  2311. {
  2312. const auto routed = p[(std::size_t) pcorr::portRoutingParam] > 0.5f;
  2313. if (routed != portRouting)
  2314. {
  2315. dsp.allNotesOff();
  2316. sounding = {};
  2317. portRouting = routed;
  2318. }
  2319. NoteMask now {};
  2320. for (int c = 0; ! portRouting && held != nullptr && c < heldCount; ++c)
  2321. now[0] |= held[c][0], now[1] |= held[c][1];
  2322. if (! portRouting && now != sounding)
  2323. {
  2324. for (int k = 0; k < 128; ++k)
  2325. {
  2326. const auto bit = 1ull << (k & 63);
  2327. const bool was = (sounding[(std::size_t) (k >> 6)] & bit) != 0, is = (now[(std::size_t) (k >> 6)] & bit) != 0;
  2328. if (is && ! was)
  2329. dsp.noteOn (k, 100); // (the Channel Rack's held notes carry no velocity: FL's default 100)
  2330. else if (was && ! is)
  2331. dsp.noteOff (k);
  2332. }
  2333. sounding = now;
  2334. }
  2335. auto on = [&p] (int i) { return p[(std::size_t) i] > 0.5f; };
  2336. pitcher::Params q;
  2337. q.speed = std::clamp (p[0], 0.0f, 1.0f);
  2338. q.fine = p[1];
  2339. q.bypassAll = on (2);
  2340. q.aRef = p[3];
  2341. q.range = pcorr::range (p[4]);
  2342. for (int k = 0; k < 12; ++k)
  2343. {
  2344. q.scale[(std::size_t) k] = on (5 + k);
  2345. q.keyBypass[(std::size_t) k] = on (17 + k);
  2346. }
  2347. q.formant = on (29);
  2348. q.gender = p[30];
  2349. q.pitchRef = p[31];
  2350. q.stereo = p[32];
  2351. q.harmonize = on (33);
  2352. q.midi = on (34);
  2353. q.octaves = on (35);
  2354. q.mix = on (36);
  2355. q.vel = on (37);
  2356. for (int j = 0; j < 4; ++j)
  2357. q.voicePan[(std::size_t) j] = p[(std::size_t) (38 + j)];
  2358. dsp.process (l, r, n, q);
  2359. latency.store (dsp.latency(), std::memory_order_relaxed);
  2360. }
  2361. // The DSP's own delay: 9 samples on the plain path, 257 on the formant path (its pass-through delay; voiced
  2362. // PSOLA grains are placed about one period + 70 samples back). FL's reported PDC latency is not confirmed.
  2363. int latencySamples() const noexcept override { return latency.load (std::memory_order_relaxed); }
  2364. private:
  2365. pitcher::Pitcher dsp;
  2366. std::atomic<int> latency { 9 };
  2367. const NoteMask* held = nullptr;
  2368. int heldCount = 0;
  2369. NoteMask sounding {};
  2370. bool portRouting = true;
  2371. };
  2372. class LoFi final : public Effect
  2373. {
  2374. public:
  2375. void prepare (double) noexcept override { reset(); }
  2376. void reset() noexcept override
  2377. {
  2378. held[0] = held[1] = 0.0f;
  2379. countdown = 0;
  2380. }
  2381. void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
  2382. {
  2383. const auto hold = lofi::holdSamples (params[0]);
  2384. const auto step = (float) (2.0 / lofi::levels (params[1]));
  2385. const auto mix = params[2];
  2386. auto quantize = [step] (float x) { return step * std::floor (x / step + 0.5f); };
  2387. for (int i = 0; i < n; ++i)
  2388. {
  2389. if (--countdown <= 0)
  2390. {
  2391. countdown = hold;
  2392. held[0] = quantize (l[i]);
  2393. held[1] = quantize (r[i]);
  2394. }
  2395. l[i] += mix * (held[0] - l[i]);
  2396. r[i] += mix * (held[1] - r[i]);
  2397. }
  2398. }
  2399. private:
  2400. float held[2] {};
  2401. int countdown = 0;
  2402. };
  2403. class FreqShift final : public Effect
  2404. {
  2405. public:
  2406. void prepare (double sr) noexcept override
  2407. {
  2408. sampleRate = sr;
  2409. reset();
  2410. }
  2411. void reset() noexcept override
  2412. {
  2413. for (auto& c : chains)
  2414. c = {};
  2415. phase = 0.0;
  2416. }
  2417. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  2418. {
  2419. const auto shift = fshift::hz (p[0]);
  2420. const auto mix = std::clamp (p[1], 0.0f, 1.0f);
  2421. const auto spread = std::clamp (p[2], 0.0f, 1.0f);
  2422. const auto step = shift / sampleRate;
  2423. for (int i = 0; i < n; ++i)
  2424. {
  2425. const auto angle = 2.0 * 3.141592653589793 * phase;
  2426. const auto cosA = (float) std::cos (angle), sinA = (float) std::sin (angle);
  2427. float* io[2] = { l + i, r + i };
  2428. for (int c = 0; c < 2; ++c)
  2429. {
  2430. float re = 0.0f, im = 0.0f;
  2431. chains[(std::size_t) c].analytic (*io[c], re, im);
  2432. // right side: between the same direction (0) and the opposite (1)
  2433. const auto sign = c == 0 ? 1.0f : 1.0f - 2.0f * spread;
  2434. const auto shifted = re * cosA + sign * im * sinA;
  2435. *io[c] += (shifted - *io[c]) * mix;
  2436. }
  2437. phase += step;
  2438. phase -= std::floor (phase);
  2439. }
  2440. }
  2441. private:
  2442. // 4 2nd-order allpasses in z² per branch; the real branch has 1 extra sample of delay
  2443. struct Chain
  2444. {
  2445. static constexpr float a[4] = { 0.6923878f, 0.9360654322959f, 0.9882295226860f, 0.9987488452737f };
  2446. static constexpr float b[4] = { 0.4021921162426f, 0.8561710882420f, 0.9722909545651f, 0.9952884791278f };
  2447. std::array<float, 4> ax1 {}, ax2 {}, ay1 {}, ay2 {}, bx1 {}, bx2 {}, by1 {}, by2 {};
  2448. float delayed = 0.0f;
  2449. static float stage (float k, float x, float& x1, float& x2, float& y1, float& y2) noexcept
  2450. {
  2451. const auto y = k * k * (x + y2) - x2;
  2452. x2 = x1;
  2453. x1 = x;
  2454. y2 = y1;
  2455. y1 = y;
  2456. return y;
  2457. }
  2458. void analytic (float x, float& re, float& im) noexcept
  2459. {
  2460. auto u = x, v = x;
  2461. for (std::size_t k = 0; k < 4; ++k)
  2462. {
  2463. u = stage (a[k], u, ax1[k], ax2[k], ay1[k], ay2[k]);
  2464. v = stage (b[k], v, bx1[k], bx2[k], by1[k], by2[k]);
  2465. }
  2466. re = delayed;
  2467. im = v;
  2468. delayed = u;
  2469. }
  2470. };
  2471. std::array<Chain, 2> chains {};
  2472. double sampleRate = 44100.0, phase = 0.0;
  2473. };
  2474. // Parallel-branch container (FL's Patcher): each branch processes a copy of the input through its
  2475. // chain of built-in effects and the output is the gain-weighted sum of the branches.
  2476. class ParallelEffect final : public Effect
  2477. {
  2478. public:
  2479. static constexpr int capacity = 4096; // samples per chunk (larger blocks are split)
  2480. explicit ParallelEffect (const EffectSlot& slot)
  2481. {
  2482. for (const auto& b : slot.branches)
  2483. {
  2484. Branch branch;
  2485. branch.gain = b.gain;
  2486. for (const auto& child : b.chain)
  2487. if (child.kind != EffectKind::plugin) // nested containers too (Patcher series-parallel graphs)
  2488. branch.chain.push_back ({ makeEffect (child), child });
  2489. branches.push_back (std::move (branch));
  2490. }
  2491. for (const auto& link : slot.links)
  2492. if (link.branch >= 0 && link.branch < (int) branches.size() && link.curve.size() >= 2)
  2493. {
  2494. const auto& chain = branches[(std::size_t) link.branch].chain;
  2495. if (link.source >= 0 && link.source < (int) chain.size() && link.target >= 0 && link.target < (int) chain.size()
  2496. && link.param >= 0 && link.param < maxEffectParams)
  2497. links.push_back (link);
  2498. }
  2499. for (auto& buffer : scratch)
  2500. buffer.assign ((std::size_t) capacity, 0.0f);
  2501. }
  2502. void prepare (double sr) noexcept override
  2503. {
  2504. for (auto& b : branches)
  2505. for (auto& c : b.chain)
  2506. c.effect->prepare (sr);
  2507. }
  2508. void reset() noexcept override
  2509. {
  2510. for (auto& b : branches)
  2511. for (auto& c : b.chain)
  2512. c.effect->reset();
  2513. }
  2514. void setSongPosition (double ticks) noexcept override
  2515. {
  2516. for (auto& b : branches)
  2517. for (auto& c : b.chain)
  2518. c.effect->setSongPosition (ticks);
  2519. }
  2520. void setPlaying (bool playing) noexcept override
  2521. {
  2522. for (auto& b : branches)
  2523. for (auto& c : b.chain)
  2524. c.effect->setPlaying (playing);
  2525. }
  2526. void setHeldNotes (const NoteMask* channels, int count) noexcept override
  2527. {
  2528. for (auto& b : branches)
  2529. for (auto& c : b.chain)
  2530. c.effect->setHeldNotes (channels, count);
  2531. }
  2532. bool followsHeldNotes() const noexcept override // (round 190kz)
  2533. {
  2534. for (const auto& b : branches)
  2535. for (const auto& c : b.chain)
  2536. if (c.effect != nullptr && c.effect->followsHeldNotes())
  2537. return true;
  2538. return false;
  2539. }
  2540. void process (float* l, float* r, int n, const EffectParams&, double bpm) noexcept override
  2541. {
  2542. for (int done = 0; done < n; done += capacity)
  2543. processPiece (l + done, r + done, std::min (capacity, n - done), bpm);
  2544. }
  2545. // the longest branch's latency (the branches themselves are not aligned; FL's Patcher PDC is not confirmed)
  2546. int latencySamples() const noexcept override
  2547. {
  2548. int longest = 0;
  2549. for (const auto& b : branches)
  2550. {
  2551. int sum = 0;
  2552. for (const auto& c : b.chain)
  2553. if (c.slot.enabled && c.slot.mix > 0.0f)
  2554. sum += c.effect->latencySamples();
  2555. longest = std::max (longest, sum);
  2556. }
  2557. return longest;
  2558. }
  2559. private:
  2560. struct Child
  2561. {
  2562. std::unique_ptr<Effect> effect;
  2563. EffectSlot slot;
  2564. };
  2565. struct Branch
  2566. {
  2567. std::vector<Child> chain;
  2568. float gain = 1.0f;
  2569. };
  2570. void processPiece (float* l, float* r, int n, double bpm) noexcept
  2571. {
  2572. auto* inL = scratch[0].data();
  2573. auto* inR = scratch[1].data();
  2574. auto* sumL = scratch[2].data();
  2575. auto* sumR = scratch[3].data();
  2576. auto* wL = scratch[4].data();
  2577. auto* wR = scratch[5].data();
  2578. auto* dryL = scratch[6].data();
  2579. auto* dryR = scratch[7].data();
  2580. std::copy (l, l + n, inL);
  2581. std::copy (r, r + n, inR);
  2582. std::fill (sumL, sumL + n, 0.0f);
  2583. std::fill (sumR, sumR + n, 0.0f);
  2584. // inner links: the control child's latest output sets the target's parameter (one block of lag)
  2585. for (const auto& link : links)
  2586. {
  2587. auto& chain = branches[(std::size_t) link.branch].chain;
  2588. const auto x = std::clamp (chain[(std::size_t) link.source].effect->controlOutput (0), 0.0f, 1.0f) * (float) (link.curve.size() - 1);
  2589. const auto i = std::min ((std::size_t) x, link.curve.size() - 2);
  2590. const auto f = x - (float) i;
  2591. chain[(std::size_t) link.target].slot.params[(std::size_t) link.param] = link.curve[i] + (link.curve[i + 1] - link.curve[i]) * f;
  2592. }
  2593. for (auto& b : branches)
  2594. {
  2595. std::copy (inL, inL + n, wL);
  2596. std::copy (inR, inR + n, wR);
  2597. for (auto& c : b.chain)
  2598. {
  2599. if (! c.slot.enabled || c.slot.mix <= 0.0f)
  2600. continue;
  2601. const auto partial = c.slot.mix < 0.999f;
  2602. if (partial)
  2603. {
  2604. std::copy (wL, wL + n, dryL);
  2605. std::copy (wR, wR + n, dryR);
  2606. }
  2607. c.effect->process (wL, wR, n, c.slot.params, bpm);
  2608. if (partial)
  2609. for (int i = 0; i < n; ++i)
  2610. {
  2611. wL[i] = dryL[i] + (wL[i] - dryL[i]) * c.slot.mix;
  2612. wR[i] = dryR[i] + (wR[i] - dryR[i]) * c.slot.mix;
  2613. }
  2614. }
  2615. for (int i = 0; i < n; ++i)
  2616. {
  2617. sumL[i] += wL[i] * b.gain;
  2618. sumR[i] += wR[i] * b.gain;
  2619. }
  2620. }
  2621. std::copy (sumL, sumL + n, l);
  2622. std::copy (sumR, sumR + n, r);
  2623. }
  2624. std::vector<Branch> branches;
  2625. std::vector<EffectLink> links;
  2626. std::array<std::vector<float>, 8> scratch;
  2627. };
  2628. // Peak Controller (REA_rodada17 §5): audio passes straight through. Detector with instant attack (block peak)
  2629. // and LINEAR decay in musical time: (10001^(D/128) − 1)·0.0192 per quarter note. Peak output =
  2630. // base + a·shape(p) with a = ±0.4·(6^(|A|/256) − 1) and FL's tension; output 0 = Peak + LFO, 1 = Peak,
  2631. // 2 = LFO (its LFO is not generated yet: the LFO base is used). Parameters = FL raw values, normalized.
  2632. class PeakController final : public Effect
  2633. {
  2634. // FL's Fruity Peak Controller (REA_rodada17 §5, REA_rodada168r §4): the peak detector (instantaneous attack, linear
  2635. // decay per quarter note), its base / amount / tension, and the LFO (base, amount, tension, speed in quarter notes,
  2636. // shape, phase) running on FL's host ticks (96 per quarter note): locked to the song position while it plays, free
  2637. // otherwise. Ramp limits each output's change to 1/8 of the range per tick; Mute silences the audio it passes.
  2638. public:
  2639. void prepare (double sr) noexcept override { sampleRate = sr; }
  2640. void reset() noexcept override
  2641. {
  2642. detector = 0.0;
  2643. freePhase = 0.0;
  2644. for (auto& o : out)
  2645. o = -1.0f;
  2646. }
  2647. void setSongPosition (double ticks) noexcept override { songBeats = ticks / (double) ppq; }
  2648. void setPlaying (bool on) noexcept override { playing = on; }
  2649. // shaped value of x (0…1) with FL's tension t (raw −128…128): the X-Y curve, divided back by k
  2650. static double tension (double x, double t) noexcept
  2651. {
  2652. if (std::abs (t) < 1e-9)
  2653. return x;
  2654. const auto k = (std::pow (1001.0, std::abs (t) / 128.0) - 1.0) * 0.1;
  2655. const auto y = t > 0.0 ? k - (std::pow (k + 1.0, 1.0 - x) - 1.0) : std::pow (k + 1.0, x) - 1.0;
  2656. return y / k;
  2657. }
  2658. // FL's LFO period in quarter notes from the speed control (raw 200…65536)
  2659. static double periodBeats (double speedRaw) noexcept { return std::max (3.0 / 96.0, (std::pow (1001.0, speedRaw / 65536.0) - 1.0) * 0.128); }
  2660. // the LFO's wave at phase φ (0…1) as 0…1. FL reads the host's LFO tables (sine, triangle, square, saw; LFOShape.bmp
  2661. // shows their shapes); Random steps to a new value every period
  2662. static double wave (int shape, double phase, std::uint32_t period) noexcept
  2663. {
  2664. constexpr auto twoPi = 6.283185307179586;
  2665. double w = 0.0;
  2666. switch (shape)
  2667. {
  2668. case 1: w = 1.0 - 2.0 * std::abs (2.0 * phase - 1.0); w = -w; break; // triangle: low, up to the top at ½, low
  2669. case 2: w = phase < 0.5 ? 1.0 : -1.0; break;
  2670. case 3: w = 2.0 * phase - 1.0; break;
  2671. case 4:
  2672. {
  2673. auto h = period * 2654435761u;
  2674. h ^= h >> 15;
  2675. h *= 2246822519u;
  2676. h ^= h >> 13;
  2677. w = (double) (h & 0xffffff) / (double) 0x800000 - 1.0;
  2678. break;
  2679. }
  2680. default: w = std::sin (twoPi * phase); break;
  2681. }
  2682. return (w + 1.0) * 0.5;
  2683. }
  2684. void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
  2685. {
  2686. const auto amountRaw = (std::clamp ((double) p[1], 0.0, 1.0) * 2.0 - 1.0) * 256.0;
  2687. const auto tensionRaw = (std::clamp ((double) p[2], 0.0, 1.0) * 2.0 - 1.0) * 128.0;
  2688. const auto decayRaw = 5.0 + 123.0 * std::clamp ((double) p[3], 0.0, 1.0);
  2689. const auto perBeat = (std::pow (10001.0, decayRaw / 128.0) - 1.0) * 0.0192;
  2690. const auto beats = std::max (1.0, bpm) / 60.0 * n / sampleRate;
  2691. float blockPeak = 0.0f;
  2692. for (int i = 0; i < n; ++i)
  2693. blockPeak = std::max ({ blockPeak, std::abs (l[i]), std::abs (r[i]) });
  2694. detector = std::max (0.0, detector - perBeat * beats);
  2695. detector = std::max (detector, (double) blockPeak);
  2696. const auto amount = (amountRaw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (amountRaw) / 256.0) - 1.0) * 0.4;
  2697. const auto peak = std::clamp (p[0] + amount * tension (detector, tensionRaw), 0.0, 1.0);
  2698. // the LFO
  2699. const auto lfoAmountRaw = (std::clamp ((double) p[5], 0.0, 1.0) * 2.0 - 1.0) * 256.0;
  2700. const auto lfoTension = (std::clamp ((double) p[6], 0.0, 1.0) * 2.0 - 1.0) * 128.0;
  2701. const auto period = periodBeats (200.0 + std::clamp ((double) p[7], 0.0, 1.0) * 65336.0);
  2702. const auto shape = std::clamp ((int) std::lround (p[8] * 4.0f), 0, 4);
  2703. const auto phaseOffset = std::clamp ((double) p[9], 0.0, 1.0);
  2704. double cycles = 0.0;
  2705. if (playing)
  2706. cycles = songBeats / period;
  2707. else
  2708. {
  2709. freePhase += beats / period;
  2710. cycles = freePhase;
  2711. }
  2712. cycles += phaseOffset;
  2713. if (playing)
  2714. songBeats += beats;
  2715. const auto whole = std::floor (cycles);
  2716. const auto lfoAmount = (lfoAmountRaw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (lfoAmountRaw) / 256.0) - 1.0) * 0.2;
  2717. // round 190kl (issue #197): LYNX's extra shapes (core/PeakShapes.h) when one is picked; none = FL's shape, as before
  2718. const auto extra = peakshapes::idOf (p[peakshapes::extraShapeParam]);
  2719. const auto shaped = extra != 0 ? peakshapes::wave (extra, cycles - whole, (std::uint32_t) (std::int64_t) whole)
  2720. : wave (shape, cycles - whole, (std::uint32_t) (std::int64_t) whole);
  2721. const auto lfo = std::clamp (p[4] + lfoAmount * tension (shaped, lfoTension), 0.0, 1.0);
  2722. // outputs 0 = peak + LFO, 1 = peak, 2 = LFO; Ramp: at most 1/8 of the range per host tick (96 per quarter note)
  2723. const double targets[3] { std::min (1.0, peak + lfo), peak, lfo };
  2724. const auto ramp = p[11] >= 0.5f;
  2725. const auto step = (float) (beats * 96.0 * 0.125);
  2726. for (int o = 0; o < 3; ++o)
  2727. {
  2728. const auto t = (float) targets[o];
  2729. out[o] = ! ramp || out[o] < 0.0f ? t : std::clamp (t, out[o] - step, out[o] + step);
  2730. }
  2731. if (p[10] >= 0.5f) // Mute
  2732. {
  2733. std::fill (l, l + n, 0.0f);
  2734. std::fill (r, r + n, 0.0f);
  2735. }
  2736. }
  2737. float controlOutput (int output) const noexcept override { return std::max (0.0f, out[(std::size_t) std::clamp (output, 0, 2)]); }
  2738. private:
  2739. double sampleRate = 44100.0, detector = 0.0, songBeats = 0.0, freePhase = 0.0;
  2740. bool playing = false;
  2741. float out[3] { -1.0f, -1.0f, -1.0f };
  2742. };
  2743. class Utility final : public Effect
  2744. {
  2745. public:
  2746. void prepare (double) noexcept override {}
  2747. void reset() noexcept override {}
  2748. void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
  2749. {
  2750. if (p[0] != lastGainParam) // pow only when the parameter changes (Patchers have dozens of utilities)
  2751. {
  2752. lastGainParam = p[0];
  2753. cachedGain = p[0] <= 0.0f ? 0.0f : std::pow (10.0f, utilityGainDb (p[0]) / 20.0f); // at the bottom = mute
  2754. }
  2755. const auto gain = cachedGain;
  2756. const auto pan = std::clamp (p[1] * 2.0f - 1.0f, -1.0f, 1.0f);
  2757. const auto gl = gain * (pan > 0.0f ? 1.0f - pan : 1.0f); // balance: lowers the opposite side
  2758. const auto gr = gain * (pan < 0.0f ? 1.0f + pan : 1.0f);
  2759. const auto ll = utilityMatrix (p[2]), rl = utilityMatrix (p[3]), lr = utilityMatrix (p[4]), rr = utilityMatrix (p[5]);
  2760. // shortcuts: identity (common in Patchers' PanOMatic/Stereo Shaper) and mute
  2761. if (gl == 0.0f && gr == 0.0f)
  2762. {
  2763. std::fill (l, l + n, 0.0f);
  2764. std::fill (r, r + n, 0.0f);
  2765. return;
  2766. }
  2767. if (rl == 0.0f && lr == 0.0f)
  2768. {
  2769. const auto fl = ll * gl, fr = rr * gr;
  2770. if (fl == 1.0f && fr == 1.0f)
  2771. return;
  2772. for (int i = 0; i < n; ++i)
  2773. {
  2774. l[i] *= fl;
  2775. r[i] *= fr;
  2776. }
  2777. return;
  2778. }
  2779. for (int i = 0; i < n; ++i)
  2780. {
  2781. const auto a = l[i], b = r[i];
  2782. l[i] = (ll * a + rl * b) * gl;
  2783. r[i] = (lr * a + rr * b) * gr;
  2784. }
  2785. }
  2786. int tailSamples() const noexcept override { return 0; } // (round 190gp: no memory)
  2787. private:
  2788. float lastGainParam = -1.0f, cachedGain = 1.0f;
  2789. };
  2790. } // namespace
  2791. namespace peq
  2792. {
  2793. BandType type (float v) noexcept { return (BandType) std::clamp ((int) std::lround (v * (bandTypes - 1)), 0, bandTypes - 1); }
  2794. float typeValue (BandType t) noexcept { return (float) (int) t / (float) (bandTypes - 1); }
  2795. double hz (float v) noexcept { return 20.0 * std::pow (1000.0, std::clamp ((double) v, 0.0, 1.0)); }
  2796. float hzValue (double f) noexcept { return (float) std::clamp (std::log (std::max (f, 1.0) / 20.0) / std::log (1000.0), 0.0, 1.0); }
  2797. double gainDb (float v) noexcept { return (std::clamp ((double) v, 0.0, 1.0) - 0.5) * 36.0; }
  2798. float gainValue (double db) noexcept { return (float) std::clamp (db / 36.0 + 0.5, 0.0, 1.0); }
  2799. double q (float v) noexcept { return 0.1 * std::pow (180.0, std::clamp ((double) v, 0.0, 1.0)); }
  2800. float qValue (double value) noexcept { return (float) std::clamp (std::log (std::max (value, 0.01) / 0.1) / std::log (180.0), 0.0, 1.0); }
  2801. int slopeStages (float v) noexcept { return 1 + (int) std::lround (std::clamp (v, 0.0f, 1.0f) * 3.0f); }
  2802. float slopeValue (int stages) noexcept { return (float) (std::clamp (stages, 1, 4) - 1) / 3.0f; }
  2803. const char* typeName (BandType t) noexcept
  2804. {
  2805. static constexpr const char* names[] = { "Off", "Peak", "Low shelf", "High shelf", "Low cut",
  2806. "High cut", "Band-pass", "Notch" };
  2807. return names[(int) t];
  2808. }
  2809. double responseDb (const EffectParams& params, double sr, double f)
  2810. {
  2811. if (flLaw (params))
  2812. return peqfl::responseDb (peqfl::fromParams (params), sr, f);
  2813. // |H(e^jw)| of each stage, summed in dB
  2814. const auto w = 2.0 * pi * std::clamp (f, 1.0, sr * 0.499) / sr;
  2815. const std::complex<double> z1 = std::polar (1.0, -w), z2 = std::polar (1.0, -2.0 * w);
  2816. auto total = gainDb (params[outputParam]);
  2817. for (int b = 0; b < bands; ++b)
  2818. {
  2819. std::array<Biquad, 4> st;
  2820. const auto count = bandStages (params, b, sr, st);
  2821. for (int s = 0; s < count; ++s)
  2822. {
  2823. const auto& c = st[(std::size_t) s];
  2824. const auto h = (c.b0 + c.b1 * z1 + c.b2 * z2) / (1.0 + c.a1 * z1 + c.a2 * z2);
  2825. const auto magnitude = std::abs (h);
  2826. if (std::isfinite (magnitude)) // (the editor draws this: never NaN)
  2827. total += 20.0 * std::log10 (std::max (magnitude, 1.0e-9));
  2828. }
  2829. }
  2830. return total;
  2831. }
  2832. bool flLaw (const EffectParams& params) noexcept { return peqfl::lawOf (params) != peqfl::Law::lynx; }
  2833. std::string orderText (const EffectParams& params, int band)
  2834. {
  2835. const auto v = params[(std::size_t) (slopeParam + band)];
  2836. if (! flLaw (params))
  2837. return std::to_string (12 * slopeStages (v)) + " dB/oct";
  2838. if (peqfl::lawOf (params) == peqfl::Law::peq1)
  2839. return "12 dB/oct";
  2840. // FL's order texts, −3…+3 (REA_rodada7 §1.4)
  2841. static constexpr const char* names[7] = { "Steep 8", "Steep 6", "Steep 4", "2", "Gentle 4", "Gentle 6", "Gentle 8" };
  2842. return names[std::clamp ((int) std::lround (v * 6.0f), 0, 6)];
  2843. }
  2844. std::string widthText (const EffectParams& params, int band)
  2845. {
  2846. const auto v = params[(std::size_t) param (band, 3)];
  2847. char text[32];
  2848. if (flLaw (params))
  2849. std::snprintf (text, sizeof (text), "BW %.0f%%", (double) v * 100.0);
  2850. else
  2851. std::snprintf (text, sizeof (text), "Q %.2f", q (v));
  2852. return text;
  2853. }
  2854. } // namespace peq
  2855. namespace autopan
  2856. {
  2857. Source sourceOf (float v) noexcept { return (Source) std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 2.0f), 0, 2); }
  2858. Direction directionOf (float v) noexcept { return (Direction) std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 2.0f), 0, 2); }
  2859. double rateHz (float v) noexcept { return 0.01 * std::pow (1000.0, (double) std::clamp (v, 0.0f, 1.0f)); }
  2860. float rateValue (double hz) noexcept { return (float) std::clamp (std::log (std::max (hz, 1e-6) / 0.01) / std::log (1000.0), 0.0, 1.0); }
  2861. int stepCount (float v) noexcept { return 2 + std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 6.0f), 0, 6); }
  2862. double stepBeats (float v) noexcept { return 4.0 / (double) (1 << std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 5.0f), 0, 5)); }
  2863. double inputDb (float v) noexcept { return -24.0 + 48.0 * (double) std::clamp (v, 0.0f, 1.0f); }
  2864. std::string paramText (int param, float v)
  2865. {
  2866. char t[32];
  2867. switch (param)
  2868. {
  2869. case source: { static const char* const n[3] { "FL LFO", "LFO", "Rhythm steps" }; return n[(int) sourceOf (v)]; }
  2870. case rate:
  2871. {
  2872. const auto hz = rateHz (v);
  2873. if (hz < 1.0) std::snprintf (t, sizeof t, "%.1f s", 1.0 / hz);
  2874. else std::snprintf (t, sizeof t, "%.2f Hz", hz);
  2875. return t;
  2876. }
  2877. case direction: { static const char* const n[3] { "Back and forth", "Left to right", "Right to left" }; return n[(int) directionOf (v)]; }
  2878. case smoothing: std::snprintf (t, sizeof t, "%.0f%%", 100.0 * std::clamp (v, 0.0f, 1.0f)); return t;
  2879. case stepsParam: return std::to_string (stepCount (v));
  2880. case stepNote: { static const char* const n[6] { "1/1", "1/2", "1/4", "1/8", "1/16", "1/32" }; return n[std::clamp ((int) std::lround (std::clamp (v, 0.0f, 1.0f) * 5.0f), 0, 5)]; }
  2881. case inputGain:
  2882. case outputGain: std::snprintf (t, sizeof t, "%+.1f dB", inputDb (v)); return t;
  2883. case analogStage: return v >= 0.5f ? "Analog" : "Digital";
  2884. default: std::snprintf (t, sizeof t, "%.2f", (double) v); return t;
  2885. }
  2886. }
  2887. } // namespace autopan
  2888. namespace
  2889. {
  2890. const EffectInfo& effectInfoOf (EffectKind kind);
  2891. }
  2892. // Round 190ge: one table lookup. effectInfoOf below passes the guard of each of its ~120 local statics before its switch
  2893. // on every call, and the renderer asks for a slot's info every block (0.8 % of a big project's render on its own).
  2894. const EffectInfo& effectInfo (EffectKind kind)
  2895. {
  2896. static const auto table = [] {
  2897. std::array<const EffectInfo*, 256> t {};
  2898. for (std::size_t k = 0; k < t.size(); ++k)
  2899. t[k] = &effectInfoOf ((EffectKind) k); // (a value past the last kind: EQ's, as effectInfoOf answers)
  2900. return t;
  2901. }();
  2902. static_assert (sizeof (EffectKind) == 1);
  2903. return *table[(std::size_t) kind];
  2904. }
  2905. namespace
  2906. {
  2907. const EffectInfo& effectInfoOf (EffectKind kind)
  2908. {
  2909. static const EffectInfo eq { "EQ", { { "Low", 0.5f }, { "Mid", 0.5f }, { "Mid freq.", 0.5f }, { "High", 0.5f }, { "Output", 0.5f } } };
  2910. static const EffectInfo comp { "Compressor", { { "Threshold", 0.7f }, { "Ratio", 3.0f / 19.0f }, { "Attack", 0.67f }, { "Release", 0.54f }, { "Makeup", 0.0f }, { "Auto gain", 0.0f },
  2911. { "Mix", 1.0f }, { "Trim", 0.5f }, { "Voicing", 0.0f },
  2912. // round 135w: the RComp role's switches (the vintage voicing's ARC / Electro / Warm
  2913. // by default, as fitted) and its 0 dBFS output limiter (off: older projects unchanged)
  2914. { "Release mode", 0.0f }, { "Release curve", 0.0f }, { "Character", 0.0f }, { "Limiter", 0.0f },
  2915. // round 150: the RComp role's own ranges (off: LYNX's, older projects unchanged) —
  2916. // ratio 1.00 : 1, gain 0 dB, attack 16 ms, release 160 ms (the reference's defaults)
  2917. { "Ranges", 0.0f }, { "RC ratio", 0.625f }, { "RC gain", 0.5f }, { "RC attack", 0.5f }, { "RC release", 0.5f },
  2918. // round 152: the vintage voicing's static curve measured at every ratio (on for new
  2919. // instances; projects saved before keep the round-150 curve: upgradeLoadedEffectParams)
  2920. { "Vintage curve", 1.0f },
  2921. // round 190ar: the classic voicing's law — clean (as before) or FET
  2922. // (5 dB knee, program-dependent release); off: every project unchanged
  2923. { "Classic law", 0.0f } } };
  2924. static const EffectInfo delay { "Delay", { { "Time", 0.3f }, { "Feedback", 0.42f }, { "Mix", 0.3f }, { "Ping-pong", 0.0f }, { "Damping", 0.3f } } };
  2925. static const EffectInfo reverb { "Reverb", { { "Room", 0.6f }, { "Damping", 0.5f }, { "Width", 1.0f }, { "Mix", 0.25f }, { "Dry", 1.0f },
  2926. { "Low cut", 0.0f }, { "High cut", 1.0f }, { "Predelay", 0.0f } } };
  2927. static const EffectInfo plugin { "Plugin", {} };
  2928. static const EffectInfo limiter { "Limiter", { { "Ceiling", 0.975f }, { "Gain", 0.0f }, { "Release", 0.5f } } };
  2929. // round 190da: Slope appended (0 = 12 dB/oct, the filter every older project has)
  2930. static const EffectInfo filter { "Filter", { { "Type", 0.0f }, { "Cutoff", 0.75f }, { "Reso.", 0.2f }, { "Mix", 1.0f }, { "Slope", 0.0f } } };
  2931. static const EffectInfo distortion { "Distortion", { { "Drive", 0.4f }, { "Tone", 0.7f }, { "Mix", 1.0f }, { "Output", 0.5f } } };
  2932. static const EffectInfo chorus { "Chorus", { { "Rate", 0.45f }, { "Depth", 0.4f }, { "Mix", 0.5f }, { "Feedback", 0.0f } } };
  2933. static const EffectInfo utility { "Utility", { { "Gain", 0.5f }, { "Balance", 0.5f }, { "L -> L", 0.75f }, { "R -> L", 0.5f },
  2934. { "L -> R", 0.5f }, { "R -> R", 0.75f } } };
  2935. static const EffectInfo volumeGate = [] {
  2936. static const char* names[] = { "Step 1", "Step 2", "Step 3", "Step 4", "Step 5", "Step 6", "Step 7", "Step 8",
  2937. "Step 9", "Step 10", "Step 11", "Step 12", "Step 13", "Step 14", "Step 15", "Step 16",
  2938. "Step 17", "Step 18", "Step 19", "Step 20", "Step 21", "Step 22", "Step 23", "Step 24",
  2939. "Step 25", "Step 26", "Step 27", "Step 28", "Step 29", "Step 30", "Step 31", "Step 32" };
  2940. EffectInfo info { "Volume gate", {} };
  2941. for (int i = 0; i < gate::steps; ++i)
  2942. info.params.push_back ({ names[i], (i % 8) < 4 ? 1.0f : 0.0f }); // default: half a beat on, half off
  2943. info.params.push_back ({ "Mix", 1.0f });
  2944. info.params.push_back ({ "Attack", 0.1765f }); // ~2 ms
  2945. info.params.push_back ({ "Release", 0.5f }); // ~43 ms
  2946. return info;
  2947. }();
  2948. static const EffectInfo pitchShift { "Pitch shift", { { "Semitones", 0.5f }, { "Cents", 0.5f }, { "Mix", 1.0f }, { "Window", 0.4f } } };
  2949. static const EffectInfo freqShift { "Frequency shifter", { { "Shift", 0.5f }, { "Mix", 1.0f }, { "Stereo", 0.0f } } };
  2950. static const EffectInfo parallelInfo { "Patcher (parallel)", {} };
  2951. static const EffectInfo patcherInfo { "Patcher", {} };
  2952. static const EffectInfo crossoverInfo { "Crossover", { { "High-pass", 0.0f }, { "HP cutoff", 0.3f }, { "HP slope", 3.0f / 7.0f },
  2953. { "Low-pass", 0.0f }, { "LP cutoff", 0.7f }, { "LP slope", 3.0f / 7.0f } } };
  2954. static const EffectInfo rhythmInfo = [] {
  2955. EffectInfo info { "Rhythmic envelope", { { "Period", 1.0f / 64.0f }, { "Points", 0.0f } } };
  2956. static const char* names[] = { "P1 pos", "P1 level", "P1 tension", "P2 pos", "P2 level", "P2 tension", "P3 pos", "P3 level", "P3 tension",
  2957. "P4 pos", "P4 level", "P4 tension", "P5 pos", "P5 level", "P5 tension", "P6 pos", "P6 level", "P6 tension",
  2958. "P7 pos", "P7 level", "P7 tension", "P8 pos", "P8 level", "P8 tension", "P9 pos", "P9 level", "P9 tension",
  2959. "P10 pos", "P10 level", "P10 tension", "P11 pos", "P11 level", "P11 tension", "P12 pos", "P12 level", "P12 tension" };
  2960. for (int i = 0; i < 36; ++i)
  2961. info.params.push_back ({ names[i], i % 3 == 2 ? 0.5f : 1.0f });
  2962. info.params.push_back ({ "Control only", 0.0f });
  2963. return info;
  2964. }();
  2965. static const EffectInfo autoPanInfo { "Auto-pan", { { "Period", 1.0f / 64.0f }, { "Depth", 0.75f }, { "Phase", 0.0f }, { "Pan", 0.5f }, { "Control only", 0.0f },
  2966. { "FL pan law", 0.0f }, { "Tension", 0.5f },
  2967. // round 135 (the PanMan role; the FL source stays the default)
  2968. { "Source", 0.0f }, { "Rate", 0.46598f }, { "Direction", 0.0f }, { "Smoothing", 1.0f },
  2969. { "Steps", 1.0f / 6.0f }, { "Step note", 0.4f }, { "Input", 0.5f }, { "Output", 0.5f },
  2970. { "Analog", 0.0f },
  2971. // round 136: the Rhythm voicing (core/RhythmPan.h, measured), off = the engines above
  2972. { "Voicing", 0.0f }, { "Rhythm rate", 0.4659f /* 0.25 Hz */ }, { "Sync", 0.0f },
  2973. { "Beats", 0.4f /* 1 beat */ }, { "Width", 180.0f / 210.0f }, { "Offset", 0.5f },
  2974. { "Rhythm smoothing", 1.0f }, { "Pattern", 0.0f }, { "Amount", 1.0f }, { "Start phase", 0.0f },
  2975. { "Rhythm analog", 0.5f }, { "Rhythm output", 0.5f },
  2976. // round 150: the Tweak page, Feel / Groove, past the speakers (appended;
  2977. // a project saved before round 150 keeps the clipped angle)
  2978. { "Rate mod", 0.5f }, { "Offset mod", 0.5f }, { "Width mod", 0.5f },
  2979. { "Env threshold", 40.0f / 60.0f }, { "Env range", 10.0f / 39.0f },
  2980. { "Feel", 0.5f }, { "Groove", 0.5f }, { "Beyond speakers", 1.0f },
  2981. // round 152: the trigger sources (Ping-pong / Random step), their
  2982. // threshold, divider, filter and manual trigger; the Random source
  2983. { "Trigger", 0.0f }, { "Trig threshold", 40.0f / 60.0f }, { "Divider", 0.0f },
  2984. { "Trig filter", 0.0f }, { "Trig freq", 0.5f }, { "Manual trigger", 0.0f },
  2985. { "Random steps", 0.0f } } };
  2986. static const EffectInfo vocoderInfo { "Vocoder", { { "Bands", 0.4f }, { "Order", 0.5f }, { "Listen", 1.0f }, { "Swap L/R", 0.0f },
  2987. { "Min freq.", 0.0f }, { "Max freq.", 1.0f }, { "Scale", 0.5f }, { "Invert", 0.0f },
  2988. { "Formant", 0.5f }, { "Width", 45.0f / 195.0f }, { "Attack", 10.0f / 990.0f },
  2989. { "Release", 90.0f / 990.0f }, { "Hold", 0.0f }, { "Modulator", 0.0f },
  2990. { "Carrier", 0.0f }, { "Wet", 0.8f }, { "Side inputs", 0.0f } } };
  2991. static const EffectInfo vocodexInfo { "Vocodex", {} }; // everything comes from FL's raw state (EffectSlot::state)
  2992. static const EffectInfo maximusInfo { "Maximus", {} }; // the engine's state travels in EffectSlot::state (core/MaximusFx.h)
  2993. // Distructor: each module's input volume, mix and output volume (FL's 0…10000 / 10000), the final clipper; the
  2994. // modules themselves come from FL's state (core/DistructorFx.h)
  2995. static const EffectInfo distructorInfo { "Distructor", { { "M1 In", 0.5f }, { "M1 Mix", 1.0f }, { "M1 Out", 0.5f },
  2996. { "M2 In", 0.5f }, { "M2 Mix", 1.0f }, { "M2 Out", 0.5f },
  2997. { "M3 In", 0.5f }, { "M3 Mix", 1.0f }, { "M3 Out", 0.5f },
  2998. { "M4 In", 0.5f }, { "M4 Mix", 1.0f }, { "M4 Out", 0.5f },
  2999. { "Clipper", 1.0f } } };
  3000. // Multiband Delay: FL's twelve global controls (raw − min) / range; the banks come from FL's state (core/MultibandDelayFx.h)
  3001. static const EffectInfo multibandDelayInfo = [] {
  3002. EffectParams p {};
  3003. mbdelay::toParams (mbdelay::State {}, p);
  3004. EffectInfo info { "Multiband Delay", {} };
  3005. const char* const names[mbdelay::numGlobals] = { "Delay scale", "Delay x0.1", "Feedback", "Smoothing", "Filter mode", "Keep pitch",
  3006. "Morph", "Mix", "Harmonic scale", "Weighting", "High pass", "Saturation" };
  3007. for (int i = 0; i < mbdelay::numGlobals; ++i)
  3008. info.params.push_back ({ names[i], p[(std::size_t) i] });
  3009. return info;
  3010. }();
  3011. // EQUO: FL's knobs (raw − min) / range and options; the bands come from FL's state (core/EquoFx.h)
  3012. static const EffectInfo equoInfo { "EQUO", { { "Band shift", 0.5f }, { "Band mix", 1.0f }, { "Morph", 0.0f },
  3013. { "Smoothness", 170.0f / 1024.0f }, { "Volume", 0.5f },
  3014. { "Bandwidth", 70.0f / 420.0f }, { "Oversample", 0.0f }, { "Add mode", 0.0f },
  3015. { "Send only", 0.0f } } };
  3016. // FL's Pitch Shifter: its 13 knobs (raw − min) / range, then engine, detector, tempo sync; defaults = a new FL instance
  3017. static const EffectInfo flPitchShifterInfo = [] {
  3018. EffectParams p {};
  3019. psfl::toParams (psfl::State {}, p);
  3020. EffectInfo info { "Pitch Shifter", {} };
  3021. const char* const names[psfl::numParams] = { "Pitch", "Formant", "Channel", "Mix", "Duration", "Density", "Jitter",
  3022. "Random", "Delay", "Feedback", "Delay mode", "Formant correction",
  3023. "Pitch mode", "Granular", "Accurate detector", "Tempo sync" };
  3024. for (int i = 0; i < psfl::numParams; ++i)
  3025. info.params.push_back ({ names[i], p[(std::size_t) i] });
  3026. return info;
  3027. }();
  3028. // FL's raw controls normalised over their ranges (core/FruityDynamics.h); defaults = a new FL instance
  3029. static const EffectInfo fruityLimiterInfo = [] {
  3030. EffectInfo info { "Fruity Limiter", {} };
  3031. for (int i = 0; i < fldyn::limiterControls; ++i)
  3032. info.params.push_back ({ fldyn::limiterParamName (i), fldyn::normalised (fldyn::limiterDefault[(std::size_t) i], fldyn::limiterMin[(std::size_t) i], fldyn::limiterMax[(std::size_t) i]) });
  3033. info.params.push_back ({ fldyn::limiterParamName (fldyn::limiterControls), 0.0f });
  3034. return info;
  3035. }();
  3036. static const EffectInfo fruityCompressorInfo = [] {
  3037. EffectInfo info { "Fruity Compressor", {} };
  3038. for (int i = 0; i < fldyn::compressorControls; ++i)
  3039. info.params.push_back ({ fldyn::compressorParamName (i), fldyn::normalised (fldyn::compressorDefault[(std::size_t) i], fldyn::compressorMin[(std::size_t) i], fldyn::compressorMax[(std::size_t) i]) });
  3040. info.params.push_back ({ fldyn::compressorParamName (fldyn::compressorControls), 1.0f });
  3041. return info;
  3042. }();
  3043. // FL's controls over their ranges (core/FruityShapers.h); defaults = a new FL instance; the curve is in EffectSlot::state
  3044. static const EffectInfo waveShaperInfo { "Fruity WaveShaper", { { "Pre amp", 0.5f }, { "Mix", 1.0f }, { "Post gain", 1.0f },
  3045. { "Oversampling", 0.0f }, { "HQ", 0.0f }, { "Smooth", 0.0f },
  3046. { "Center", 0.0f }, { "Unipolar", 0.0f } } };
  3047. static const EffectInfo softClipperInfo { "Fruity Soft Clipper", { { "Threshold", 99.0f / 126.0f }, { "Post", 128.0f / 160.0f } } };
  3048. // FL's controls over their ranges (core/FruityBasicFx.h); defaults = a new FL instance
  3049. static const EffectInfo panOMaticInfo { "Fruity PanOMatic", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "LFO shape", 0.0f },
  3050. { "LFO target", 0.0f }, { "LFO amount", 0.5f }, { "LFO speed", 0.5f } } };
  3051. static const EffectInfo balanceInfo { "Fruity Balance", { { "Balance", 0.5f }, { "Volume", 0.8f } } };
  3052. static const EffectInfo bloodOverdriveInfo { "Fruity Blood Overdrive", { { "Pre band", 0.0f }, { "Color", 0.5f }, { "Pre amp", 0.0f },
  3053. { "x100", 0.0f }, { "Post filter", 0.0f }, { "Post gain", 1.0f } } };
  3054. // FL's controls as (raw − min) / range (core/Reeverb2.h); defaults = FL's
  3055. static const EffectInfo reeverb2Info = [] {
  3056. EffectInfo info { "Reeverb 2", { { "Low cut", 0 }, { "High cut", 0 }, { "Predelay", 0 }, { "Room size", 0 }, { "Diffusion", 0 },
  3057. { "Decay", 0 }, { "High damping", 0 }, { "Bass mult.", 0 }, { "Crossover", 0 }, { "Stereo sep.", 0 },
  3058. { "Dry", 0 }, { "Early ref.", 0 }, { "Wet", 0 }, { "Mod speed", 0 }, { "Mod depth", 0 },
  3059. { "Tempo predelay", 0 }, { "Mid/side input", 0 } } };
  3060. EffectParams p {};
  3061. reeverb2::toParams (reeverb2::Settings {}, p);
  3062. for (std::size_t i = 0; i < info.params.size(); ++i)
  3063. info.params[i].defaultValue = p[i];
  3064. return info;
  3065. }();
  3066. // FL's 49 controls as (raw − min) / range + the 4 sync switches (core/LuxeVerb.h); defaults = a new FL instance
  3067. static const EffectInfo luxeVerbInfo = [] {
  3068. EffectInfo info { "LuxeVerb", {} };
  3069. EffectParams p {};
  3070. luxeverb::toParams (luxeverb::Settings {}, p);
  3071. for (std::size_t i = 0; i < (std::size_t) luxeVerbParamCount; ++i)
  3072. info.params.push_back ({ luxeverb::names[i], p[i] });
  3073. for (std::size_t i = 0; i < (std::size_t) luxeVerbSpaceCount; ++i) // round tp172b: the Space engine (off)
  3074. info.params.push_back ({ luxeverb::sp::names[i], luxeverb::sp::defaults[i] });
  3075. return info;
  3076. }();
  3077. // FL's 4 automatable controls as (raw − min) / range (core/ConvolverFx.h); the impulse response is in the slot's state
  3078. static const EffectInfo convolverInfo { "Fruity Convolver", { { "Dry", 1.0f }, { "Wet", 1.0f }, { "Input separation", 0.5f },
  3079. { "Wet separation", 0.5f } } };
  3080. // FL's controls as raw / max (core/Reeverb2.h); defaults = the plugin's own (1250, 10800, 0, 26000, 65536, 20, 4700,
  3081. // 10800, 65536, 13120)
  3082. static const EffectInfo reeverb1Info { "Reeverb", { { "Low cut", 1250.0f / 65536 }, { "High cut", 10800.0f / 65536 }, { "Predelay", 0.0f },
  3083. { "Room size", 26000.0f / 65536 }, { "Diffusion", 1.0f }, { "Color", 0.5f },
  3084. { "Decay", 4700.0f / 65536 }, { "High damping", 10800.0f / 65536 }, { "Dry", 1.0f },
  3085. { "Wet", 13120.0f / 65536 } } };
  3086. // FL's raw controls normalised over their ranges (core/FruityDelay.h); defaults = FL's "Default" presets
  3087. static const EffectInfo fruityDelay2Info = [] {
  3088. EffectInfo info { "Fruity Delay 2", {} };
  3089. for (int i = 0; i < fldelay::delay2Controls; ++i)
  3090. info.params.push_back ({ fldelay::delay2ParamName (i), (float) (fldelay::delay2Default[(std::size_t) i] - fldelay::delay2Min[(std::size_t) i])
  3091. / (float) (fldelay::delay2Max[(std::size_t) i] - fldelay::delay2Min[(std::size_t) i]) });
  3092. return info;
  3093. }();
  3094. static const EffectInfo fruityDelay3Info = [] {
  3095. EffectInfo info { "Fruity Delay 3", {} };
  3096. for (int i = 0; i < fldelay::delay3Controls; ++i)
  3097. info.params.push_back ({ fldelay::delay3ParamName (i), (float) (fldelay::delay3Default[(std::size_t) i] - fldelay::delay3Min[(std::size_t) i])
  3098. / (float) (fldelay::delay3Max[(std::size_t) i] - fldelay::delay3Min[(std::size_t) i]) });
  3099. return info;
  3100. }();
  3101. // FL's controls over their ranges (core/StereoFx.h); defaults = a new FL instance
  3102. static const EffectInfo stereoShaperInfo { "Stereo Shaper", { { "R > L", 0.5f }, { "Left", 0.75f }, { "Right", 0.75f }, { "L > R", 0.5f },
  3103. { "Delay", 0.5f }, { "Phase", 0.5f }, { "Effects post", 0.0f },
  3104. { "Difference", 0.0f } } };
  3105. static const EffectInfo stereoEnhancerInfo { "Stereo Enhancer", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "Separation", 0.5f },
  3106. { "Phase offset", 0.5f }, { "Effects post", 1.0f }, { "Invert", 0.0f } } };
  3107. static const EffectInfo transientProcessorInfo { "Transient Processor", { { "Attack", 0.5f }, { "Drive", 0.0f }, { "Release", 0.5f },
  3108. { "Gain", 0.5f }, { "Attack shape", 0.5f }, { "Release shape", 0.5f },
  3109. { "Split freq.", 0.5f }, { "Split balance", 0.5f }, { "On", 1.0f } } };
  3110. static const EffectInfo spreaderInfo { "Spreader", { { "Width", 0.5f }, { "Separation", 0.5f }, { "Low bypass", 9990.0f / 999000.0f },
  3111. { "Mono bass", 0.0f }, { "Enable", 1.0f } } };
  3112. // FL's controls over their ranges (core/FruityFilters.h); defaults = a new FL instance
  3113. static const EffectInfo fastLPInfo { "Fruity Fast LP", { { "Cutoff", 1.0f }, { "Resonance", 0.0f } } };
  3114. static const EffectInfo freeFilterInfo { "Fruity Free Filter", { { "Type", 0.0f }, { "Frequency", 0.5f }, { "Q", 169.0f / 1024.0f },
  3115. { "Gain", 676.0f / 1024.0f }, { "Center", 0.0f } } };
  3116. // FL's Newtone / Newtime: the sample and its edits travel in EffectSlot::state / samplePath (core/NewtoneFx.h)
  3117. static const EffectInfo newtoneInfo { "Newtone", { { "Slave to host playback", 0.0f } } };
  3118. static const EffectInfo newtimeInfo { "Newtime", { { "Slave to host playback", 0.0f } } };
  3119. static const EffectInfo fruityFilterInfo { "Fruity Filter", { { "Cutoff", 1.0f }, { "Resonance", 205.0f / 1024.0f }, { "Low pass", 1.0f },
  3120. { "Band pass", 0.0f }, { "High pass", 0.5f }, { "x2", 0.0f }, { "Center", 0.0f } } };
  3121. // FL's eight Gross Beat parameters (core/GrossBeat.h); the slots' envelopes travel in EffectSlot::state
  3122. static const EffectInfo grossBeatInfo { "Gross Beat", { { "Time slot", 0.0f }, { "Volume slot", 0.0f }, { "Time mix", 1.0f },
  3123. { "Volume mix", 1.0f }, { "Attack", 0.1765f }, { "Release", 0.5f },
  3124. { "Tension", 0.5f }, { "Hold", 0.0f } } };
  3125. // FL's state travels in EffectSlot::state; the four global controls are the editable parameters (raw / 128)
  3126. static const EffectInfo fruityDelayBankInfo { "Fruity Delay Bank", { { "Dry", 1.0f }, { "Output", 1.0f }, { "Input", 1.0f }, { "Feedback", 1.0f } } };
  3127. // FL's raw controls normalised over their ranges (core/FruityMultiband.h); defaults = a new FL instance
  3128. static const EffectInfo fruityMultibandInfo = [] {
  3129. EffectInfo info { "Fruity Multiband Compressor", {} };
  3130. for (int i = 0; i < flmb::controls; ++i)
  3131. info.params.push_back ({ flmb::paramName (i), flmb::normalised (flmb::controlDefault[(std::size_t) i], flmb::controlMin[(std::size_t) i], flmb::controlMax[(std::size_t) i]) });
  3132. return info;
  3133. }();
  3134. // FL's controls over their ranges (core/FlangusFastDist.h); defaults = a new FL instance
  3135. static const EffectInfo fastDistInfo { "Fruity Fast Dist", { { "Pre amp", 0.5f }, { "Threshold", 1.0f }, { "Type", 0.0f },
  3136. { "Mix", 1.0f }, { "Post gain", 1.0f } } };
  3137. static const EffectInfo flangusInfo { "Fruity Flangus", { { "Order", 3.0f / 8.0f }, { "Depth", 0.5f }, { "Speed", 0.75f },
  3138. { "Delay", 8.0f / 128.0f }, { "Spread", 1.0f }, { "Cross", 96.0f / 256.0f },
  3139. { "Dry", 224.0f / 256.0f }, { "Wet", 224.0f / 256.0f } } };
  3140. static const EffectInfo flangerInfo { "Fruity Flanger", { { "Delay", 0.0f }, { "Depth", 0.4f }, { "Rate", 0.4f }, { "Phase", 118.0f / 360.0f },
  3141. { "Damp", 0.0f }, { "Shape", 0.0f }, { "Feed", 0.23f }, { "Invert feed", 0.0f },
  3142. { "Invert wet", 1.0f }, { "Dry", 0.7f }, { "Wet", 0.6f }, { "Cross", 0.5f } } };
  3143. // raw FL values / max (the names are FL's controls, REA_rodada29 §2.1)
  3144. static const EffectInfo squeezeInfo { "Squeeze", { { "Volume", 127.0f / 160.0f }, { "Mix", 0.5f }, { "Steps", 1.0f / 32768.0f },
  3145. { "Filter", 0.0f }, { "Filter type", 0.0f }, { "Resonance", 0.5f },
  3146. { "Cutoff", 0.5f }, { "Filter post", 0.0f }, { "Relation", 0.0f },
  3147. { "Impact", 0.0f }, { "Preserve", 7500.0f / 44100.0f }, { "Amount", 0.0f } } };
  3148. // the engine's normalised values in core order (VST 22/23 swapped); defaults = the front-end's new instance
  3149. static const EffectInfo vintagePhaserInfo { "Vintage Phaser", {
  3150. { "Min freq.", 0.4375f }, { "Max freq.", 0.7758789f }, { "Feedback", 0.5f }, { "Manual", 0.0f }, { "Manual freq.", 0.0f },
  3151. { "HQ", 0.0f }, { "LFO speed", 0.0f }, { "Tempo sync", 0.0f }, { "Sine", 0.0f }, { "Tension", 0.0f }, { "Start phase", 0.0f },
  3152. { "L/R phase", 0.0f }, { "Delay", 0.0f }, { "Keep pitch", 0.0f }, { "Delay mix", 0.0f }, { "Delay stereo", 0.5f },
  3153. { "Delay time", 0.0f }, { "Delay sync", 0.0f }, { "Delay fdbk", 0.0f }, { "Delay LP", 0.0f }, { "Delay HP", 0.0f },
  3154. { "Mix", 0.5f }, { "Noise", 0.0f }, { "Mono input", 0.0f }, { "Gate", 0.0f }, { "Colour gain", 0.0f }, { "Colour freq.", 0.0f },
  3155. { "Input HP", 0.0f }, { "Fdbk HP", 0.0f }, { "Rate 1", 0.0f }, { "Rate 2", 1.0f }, { "Depth scale", 1.0f },
  3156. { "Pull-down", 0.0f }, { "Engine V2", 1.0f }, { "Drive", 0.0f }, { "Invert fdbk", 0.0f } } };
  3157. static const EffectInfo pitchCorrectInfo = [] {
  3158. EffectInfo info { "Pitch correction", { { "Speed", 1.0f }, { "Fine", 0.5f }, { "Bypass all", 0.0f }, { "A freq.", 0.5f },
  3159. { "Range", 0.4f } } };
  3160. static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  3161. for (const auto* name : names)
  3162. info.params.push_back ({ name, 1.0f });
  3163. static const char* bypass[] = { "C off", "C# off", "D off", "D# off", "E off", "F off", "F# off", "G off", "G# off", "A off", "A# off", "B off" };
  3164. for (const auto* name : bypass)
  3165. info.params.push_back ({ name, 0.0f });
  3166. // added later (REA round 30); the defaults keep older projects as they were: plain shifter, no harmony
  3167. info.params.insert (info.params.end(), { { "Formant", 0.0f }, { "Gender", 0.5f }, { "Pitch ref.", 0.0f }, { "Stereo", 1.0f },
  3168. { "Harmonize", 0.0f }, { "MIDI", 0.0f }, { "Octaves", 0.0f }, { "Mix", 0.0f },
  3169. { "Vel", 0.0f }, { "Voice 1 pan", 0.5f }, { "Voice 2 pan", 0.5f },
  3170. { "Voice 3 pan", 0.5f }, { "Voice 4 pan", 0.5f } });
  3171. // round 190ee: FL's MIDI port (none by default) and how notes arrive (older projects: Port routing off)
  3172. info.params.insert (info.params.end(), { { "MIDI port", 0.0f }, { "Port routing", 1.0f } });
  3173. return info;
  3174. }();
  3175. static const EffectInfo lofiInfo { "Lo-fi", { { "Rate", 0.0f }, { "Bits", 0.0f }, { "Mix", 1.0f } } };
  3176. // FL's Fruity Phaser: its nine raw controls / max (core/FruityPhaser.h); defaults = a new FL instance
  3177. static const EffectInfo fruityPhaserInfo = [] {
  3178. EffectInfo info { "Fruity Phaser", {} };
  3179. float p[phaserfx::params] {};
  3180. phaserfx::toParams (phaserfx::defaults, p);
  3181. for (int i = 0; i < phaserfx::params; ++i)
  3182. info.params.push_back ({ phaserfx::paramName (i), p[i] });
  3183. return info;
  3184. }();
  3185. // FL's Fruity Send: pan, volume, dry over their ranges and the insert it sends to (core/FruityBasicFx.h)
  3186. static const EffectInfo fruitySendInfo { "Fruity Send", { { "Pan", 0.5f }, { "Volume", 0.8f }, { "Dry", 1.0f }, { "Send to", 0.0f } } };
  3187. static const EffectInfo effectorInfo { "Effector", { { "Type", 0.0f }, { "Bypass", 0.0f }, { "Wet", 1.0f }, { "X", 0.5f }, { "Y", 0.5f },
  3188. { "Mod rate", 0.5f }, { "Tempo red.", 0.0f }, { "Mod X", 0.5f }, { "Mod Y", 0.5f },
  3189. { "LFO shape", 0.0f }, { "Input", 1.0f }, { "Output", 0.5f } } };
  3190. static const EffectInfo formulaControllerInfo { "Formula Controller", { { "a", 0.0f }, { "b", 0.0f }, { "c", 0.0f } } };
  3191. // round 168r: FL's LFO controls, Mute and Ramp after the round-17 five (FL's own order: the state's 10 ints + 2 flags)
  3192. static const EffectInfo peakController { "Peak Controller", { { "Base", 0.0f }, { "Amount", 0.8496f }, { "Tension", 0.5f },
  3193. { "Decay", 0.4959f }, { "LFO base", 0.0f }, { "LFO amount", 0.5f },
  3194. { "LFO tension", 0.5f }, { "LFO speed", 32750.0f / 65336.0f },
  3195. { "LFO shape", 0.0f }, { "LFO phase", 0.0f }, { "Mute", 0.0f },
  3196. { "Ramp", 0.0f } } };
  3197. static const EffectInfo parametric = [] {
  3198. // bands as in a mixing EQ: low shelf, 5 peaks and high shelf, all at 0 dB
  3199. constexpr peq::BandType types[] = { peq::BandType::lowShelf, peq::BandType::peak, peq::BandType::peak, peq::BandType::peak,
  3200. peq::BandType::peak, peq::BandType::peak, peq::BandType::highShelf };
  3201. constexpr double freqs[] = { 80.0, 200.0, 500.0, 1200.0, 3000.0, 6000.0, 12000.0 };
  3202. static const char* names[peq::bands][4] = {
  3203. { "B1 type", "B1 freq.", "B1 gain", "B1 Q" }, { "B2 type", "B2 freq.", "B2 gain", "B2 Q" },
  3204. { "B3 type", "B3 freq.", "B3 gain", "B3 Q" }, { "B4 type", "B4 freq.", "B4 gain", "B4 Q" },
  3205. { "B5 type", "B5 freq.", "B5 gain", "B5 Q" }, { "B6 type", "B6 freq.", "B6 gain", "B6 Q" },
  3206. { "B7 type", "B7 freq.", "B7 gain", "B7 Q" } };
  3207. static const char* slopes[peq::bands] = { "B1 slope", "B2 slope", "B3 slope", "B4 slope", "B5 slope", "B6 slope", "B7 slope" };
  3208. EffectInfo info { "Parametric EQ", {} };
  3209. for (int b = 0; b < peq::bands; ++b)
  3210. {
  3211. info.params.push_back ({ names[b][0], peq::typeValue (types[b]) });
  3212. info.params.push_back ({ names[b][1], peq::hzValue (freqs[b]) });
  3213. info.params.push_back ({ names[b][2], 0.5f });
  3214. // Q 1.0 on shelves = shelf slope S 1; on cuts, 0.707 = Butterworth
  3215. info.params.push_back ({ names[b][3], peq::qValue (types[b] == peq::BandType::lowCut || types[b] == peq::BandType::highCut ? 0.70710678 : 1.0) });
  3216. }
  3217. info.params.push_back ({ "Output", 0.5f });
  3218. for (int b = 0; b < peq::bands; ++b)
  3219. info.params.push_back ({ slopes[b], 0.0f });
  3220. return info;
  3221. }();
  3222. switch (kind)
  3223. {
  3224. case EffectKind::eq: return eq;
  3225. case EffectKind::compressor: return comp;
  3226. case EffectKind::delay: return delay;
  3227. case EffectKind::reverb: return reverb;
  3228. case EffectKind::plugin: return plugin;
  3229. case EffectKind::limiter: return limiter;
  3230. case EffectKind::filter: return filter;
  3231. case EffectKind::distortion: return distortion;
  3232. case EffectKind::chorus: return chorus;
  3233. case EffectKind::parametricEq: return parametric;
  3234. case EffectKind::utility: return utility;
  3235. case EffectKind::volumeGate: return volumeGate;
  3236. case EffectKind::peakController: return peakController;
  3237. case EffectKind::pitchShift: return pitchShift;
  3238. case EffectKind::freqShift: return freqShift;
  3239. case EffectKind::parallel: return parallelInfo;
  3240. case EffectKind::patcher: return patcherInfo;
  3241. case EffectKind::lofi: return lofiInfo;
  3242. case EffectKind::effector: return effectorInfo;
  3243. case EffectKind::crossover: return crossoverInfo;
  3244. case EffectKind::rhythmGain: return rhythmInfo;
  3245. case EffectKind::autoPan: return autoPanInfo;
  3246. case EffectKind::vocoder: return vocoderInfo;
  3247. case EffectKind::pitchCorrect: return pitchCorrectInfo;
  3248. case EffectKind::squeeze: return squeezeInfo;
  3249. case EffectKind::vintagePhaser: return vintagePhaserInfo;
  3250. case EffectKind::vocodex: return vocodexInfo;
  3251. case EffectKind::maximus: return maximusInfo;
  3252. case EffectKind::fruityLimiter: return fruityLimiterInfo;
  3253. case EffectKind::fruityCompressor: return fruityCompressorInfo;
  3254. case EffectKind::fruityWaveShaper: return waveShaperInfo;
  3255. case EffectKind::fruitySoftClipper: return softClipperInfo;
  3256. case EffectKind::fruityPanOMatic: return panOMaticInfo;
  3257. case EffectKind::fruityBalance: return balanceInfo;
  3258. case EffectKind::fruityBloodOverdrive: return bloodOverdriveInfo;
  3259. case EffectKind::reeverb2: return reeverb2Info;
  3260. case EffectKind::reeverb1: return reeverb1Info;
  3261. case EffectKind::fruityDelay2: return fruityDelay2Info;
  3262. case EffectKind::fruityDelay3: return fruityDelay3Info;
  3263. case EffectKind::stereoShaper: return stereoShaperInfo;
  3264. case EffectKind::stereoEnhancer: return stereoEnhancerInfo;
  3265. case EffectKind::transientProcessor: return transientProcessorInfo;
  3266. case EffectKind::spreader: return spreaderInfo;
  3267. case EffectKind::fruityChorus: return fruitychorusfx::info();
  3268. case EffectKind::hyperChorus: return hyperchorusfx::info();
  3269. case EffectKind::vintageChorus: return vintagechorusfx::info();
  3270. case EffectKind::grossBeat: return grossBeatInfo;
  3271. case EffectKind::lovePhilter: return philter::info();
  3272. case EffectKind::luxeVerb: return luxeVerbInfo;
  3273. case EffectKind::convolver: return convolverInfo;
  3274. case EffectKind::fruityDelayBank: return fruityDelayBankInfo;
  3275. case EffectKind::fruityMultiband: return fruityMultibandInfo;
  3276. case EffectKind::fruityFastDist: return fastDistInfo;
  3277. case EffectKind::fruityFlangus: return flangusInfo;
  3278. case EffectKind::fruityFlanger: return flangerInfo;
  3279. case EffectKind::equo: return equoInfo;
  3280. case EffectKind::flPitchShifter: return flPitchShifterInfo;
  3281. case EffectKind::multibandDelay: return multibandDelayInfo;
  3282. case EffectKind::frequencySplitter: return fsplit::info();
  3283. case EffectKind::fruityFastLP: return fastLPInfo;
  3284. case EffectKind::fruityFreeFilter: return freeFilterInfo;
  3285. case EffectKind::fruityFilter: return fruityFilterInfo;
  3286. case EffectKind::hardcore: return hardcore::info();
  3287. case EffectKind::distructor: return distructorInfo;
  3288. case EffectKind::newtone: return newtoneInfo;
  3289. case EffectKind::newtime: return newtimeInfo;
  3290. case EffectKind::facetEq: return facet::info();
  3291. case EffectKind::apexLimiter: return apex::info();
  3292. case EffectKind::ridgeStrip: return mixsuite::ridgeInfo();
  3293. case EffectKind::glowLeveler: return mixsuite::glowInfo();
  3294. case EffectKind::hushDeEsser: return mixsuite::hushInfo();
  3295. case EffectKind::aether: return mixsuite::aetherInfo();
  3296. case EffectKind::ember: return mixsuite::emberInfo();
  3297. case EffectKind::kilnChannel: return mixsuite::kilnInfo();
  3298. case EffectKind::fretChannel: return mixsuite::fretInfo();
  3299. case EffectKind::shellChannel: return mixsuite::shellInfo();
  3300. case EffectKind::pocketDistortion:
  3301. {
  3302. // FL Studio Mobile's own values and defaults (round 188h)
  3303. static const EffectInfo info { "Pocket Distortion", { { "Drive", 0.25f }, { "BitCrush", 0.0f }, { "Gain", 1.0f },
  3304. { "Stereo", 0.5f }, { "Kind", 0.0f }, { "Bias", 0.5f } } };
  3305. return info;
  3306. }
  3307. case EffectKind::pocketLimiterClassic:
  3308. {
  3309. static const EffectInfo info { "Pocket Limiter Classic", { { "Threshold", 1.0f }, { "Release", 0.7f },
  3310. { "Output gain", 2.0f / 3.0f } } };
  3311. return info;
  3312. }
  3313. case EffectKind::pocketLimiter:
  3314. {
  3315. static const EffectInfo info { "Pocket Limiter", { { "In gain", 0.5f }, { "Out gain", 0.5f }, { "Release", 0.2f },
  3316. { "Threshold", 1.0f } } };
  3317. return info;
  3318. }
  3319. case EffectKind::pocketLeveller:
  3320. {
  3321. static const EffectInfo info { "Pocket Leveller", { { "Gain", 0.7379573f }, { "Pan", 0.5f } } };
  3322. return info;
  3323. }
  3324. case EffectKind::pocketGate:
  3325. {
  3326. static const EffectInfo info { "Pocket Gate", { { "Threshold", 0.0f }, { "Asymmetry", 0.0f }, { "Attack", 0.01f },
  3327. { "Attack curve", 0.0f }, { "Release", 0.25f }, { "Release curve", 1.0f },
  3328. { "Mix", 1.0f }, { "Hold", 0.25f } } };
  3329. return info;
  3330. }
  3331. case EffectKind::pocketTranceDelay:
  3332. {
  3333. static const EffectInfo info { "Pocket Trance Delay", { { "Time", 0.775f }, { "Feedback", 0.4f }, { "Mix", 1.0f },
  3334. { "Filter", 0.5f }, { "Mode", 0.0f }, { "Input pan", 0.5f },
  3335. { "Dry pan", 0.0f } } };
  3336. return info;
  3337. }
  3338. case EffectKind::pocketTapeDelay:
  3339. {
  3340. static const EffectInfo info { "Pocket Tape Delay", { { "Time", 0.6f }, { "Feedback", 0.6f }, { "Async", 0.5f },
  3341. { "Mix", 0.4f } } };
  3342. return info;
  3343. }
  3344. case EffectKind::pocketMultiFx:
  3345. {
  3346. static const EffectInfo info { "Pocket MultiFX", { { "FX kind", 0.0f }, { "X", 0.5f }, { "Y", 0.5f }, { "LFO rate", 0.61f },
  3347. { "LFO amount", 0.0f }, { "LFO shape", 0.0f } } };
  3348. return info;
  3349. }
  3350. case EffectKind::strikeShaper: return mixsuite::strikeInfo();
  3351. case EffectKind::anvilBus: return mixsuite::anvilInfo();
  3352. case EffectKind::corrode: return mixsuite::corrodeInfo();
  3353. case EffectKind::soundboard: return mixsuite::soundboardInfo();
  3354. case EffectKind::platter: return mixsuite::platterInfo();
  3355. case EffectKind::timeprism: return mixsuite::timeprismInfo();
  3356. case EffectKind::harmonia: return mixsuite::harmoniaInfo();
  3357. case EffectKind::pocketAutoduck:
  3358. {
  3359. static const EffectInfo info { "Pocket Autoduck", { { "Ducking", 0.501f }, { "Attack", 0.1f }, { "Curve", 0.501f }, { "Time", 1.0f },
  3360. { "Shift", 0.5f }, { "Hold", 0.0f }, { "Shape", 0.0f } } };
  3361. return info;
  3362. }
  3363. case EffectKind::pocketChorus:
  3364. {
  3365. static const EffectInfo info { "Pocket Chorus", { { "Rate", 0.4f }, { "Depth", 0.6f }, { "Stereo", 1.0f }, { "Mix", 0.6f } } };
  3366. return info;
  3367. }
  3368. case EffectKind::pocketSpacer:
  3369. {
  3370. static const EffectInfo info { "Pocket Spacer", { { "L/R delay", 0.5f }, { "Pan", 0.5f }, { "Separation", 0.5f },
  3371. { "L/R inversion", 0.0f }, { "M/S delay", 0.5f }, { "M/S inversion", 0.0f },
  3372. { "Stereo mode", 0.0f } } };
  3373. return info;
  3374. }
  3375. case EffectKind::pocketStereoizer:
  3376. {
  3377. static const EffectInfo info { "Pocket Stereoizer", { { "Strength", 0.7f }, { "Timbre", 0.52f }, { "Focus", 0.75f },
  3378. { "L/R delay", 0.5f }, { "Pan", 0.5f } } };
  3379. return info;
  3380. }
  3381. case EffectKind::pocketWowFlutter:
  3382. {
  3383. // FL Studio Mobile's own values and defaults (round 189h); FLM names each rate knob and its sync menu alike
  3384. static const EffectInfo info { "Pocket Wow & Flutter", { { "Wow rate", 0.184564f }, { "Wow sync", 0.2f }, { "Wow amount", 0.25f },
  3385. { "Flutter rate", 0.066818f }, { "Flutter sync", 0.1f },
  3386. { "Flutter amount", 0.25f }, { "Sync", 0.0f }, { "Random rate", 0.08952f },
  3387. { "Random sync", 0.8f }, { "Random amount", 0.25f } } };
  3388. return info;
  3389. }
  3390. case EffectKind::pocketPhaser:
  3391. {
  3392. static const EffectInfo info { "Pocket Phaser", { { "LFO rate", 0.112222f }, { "LFO amount", 0.25f }, { "Feedback", 0.1f },
  3393. { "Frequency", 0.25f }, { "Mix", 1.0f }, { "Sync", 1.0f }, { "LFO speed", 0.0f },
  3394. { "LFO shape", 0.0f }, { "Stereo", 1.0f } } };
  3395. return info;
  3396. }
  3397. case EffectKind::pocketFlanger:
  3398. {
  3399. static const EffectInfo info { "Pocket Flanger", { { "LFO rate", 0.4f }, { "Sync", 0.0f }, { "LFO speed", 0.55f }, { "LFO shape", 0.0f },
  3400. { "LFO amount", 1.0f }, { "Delay", 0.25f }, { "Feedback", 0.75f },
  3401. { "Invert feedback", 1.0f }, { "Stereo", 0.0f }, { "Mix", 1.0f }, { "Invert mix", 1.0f } } };
  3402. return info;
  3403. }
  3404. case EffectKind::pocketTremolo:
  3405. {
  3406. static const EffectInfo info { "Pocket Tremolo", { { "Rate", 0.045467f }, { "Rate sync", 0.0f }, { "Amount max", 1.0f },
  3407. { "Amount min", 0.0f }, { "Phase offset", 0.0f }, { "Stereo offset", 0.0f },
  3408. { "Sync", 0.0f }, { "Shape", 0.5f }, { "Smooth", 1.0f }, { "Skew", 0.5f }, { "Width", 0.5f } } };
  3409. return info;
  3410. }
  3411. case EffectKind::pocketWaveshaper:
  3412. {
  3413. // FL Studio Mobile's own values and defaults (round 189h)
  3414. static const EffectInfo info { "Pocket Waveshaper", { { "Shape", 0.0f }, { "Auto-gain", 0.0f }, { "X", 0.5f }, { "Y", 0.5f },
  3415. { "Drive", 0.0f }, { "Post gain", 0.5f }, { "Stereo spread", 0.0f },
  3416. { "Mix", 1.0f }, { "High cut", 1.0f }, { "Low cut", 0.0f }, { "Bass", 0.5f },
  3417. { "Mid freq", 0.5f }, { "Mid gain", 0.5f }, { "Treble", 0.5f },
  3418. { "LFO shape", 0.0f }, { "LFO sync", 0.0f }, { "LFO rate", 0.5f },
  3419. { "LFO rate free", 0.0f }, { "LFO to X", 0.0f }, { "LFO to Y", 0.0f } } };
  3420. return info;
  3421. }
  3422. case EffectKind::pocketCompressor:
  3423. {
  3424. static const EffectInfo info { "Pocket Compressor", { { "Thresh", 0.499f }, { "Ratio", 0.0f }, { "Attack", 0.6f }, { "Release", 0.6f },
  3425. { "Level", 0.5001f }, { "Hold", 0.0f }, { "Auto gain", 1.0f },
  3426. { "Input gain", 0.5f }, { "RMS", 0.0f } } };
  3427. return info;
  3428. }
  3429. case EffectKind::pocketSpreader:
  3430. {
  3431. static const EffectInfo info { "Pocket Spreader", { { "Width", 0.0f }, { "Low bypass", 0.0f }, { "Mono bass", 0.0f },
  3432. { "Separation", 0.5f } } };
  3433. return info;
  3434. }
  3435. case EffectKind::pocketComb: // round 190by
  3436. {
  3437. static const EffectInfo info { "Pocket Comb Filter", { { "Mode", 0.0f }, { "Pitch", 0.33f }, { "Feedback", 0.8f }, { "Mix", 0.75f },
  3438. { "Offset", 0.5f }, { "Smoothing", 0.25f }, { "Snap", 1.0f },
  3439. { "Polarity", 0.0f }, { "Asymmetry", 0.5f }, { "Pitch oct", 0.5f },
  3440. { "Pitch note", 0.4f } } };
  3441. return info;
  3442. }
  3443. case EffectKind::pocketMultiband: // round 190by
  3444. {
  3445. static const EffectInfo info { "Pocket Multiband Compressor",
  3446. { { "Master gain", 0.5f }, { "Low crossover", 0.3f }, { "High crossover", 0.7f }, { "Solo", 0.0f },
  3447. { "Dry mix", 0.0f },
  3448. { "Low input gain", 0.5f }, { "Low threshold", 1.0f }, { "Low ratio", 0.0f }, { "Low attack", 0.3f },
  3449. { "Low release", 0.3f }, { "Low gain", 0.5f }, { "Low state", 0.0f },
  3450. { "Mid input gain", 0.5f }, { "Mid threshold", 1.0f }, { "Mid ratio", 0.0f }, { "Mid attack", 0.3f },
  3451. { "Mid release", 0.3f }, { "Mid gain", 0.5f }, { "Mid state", 0.0f },
  3452. { "High input gain", 0.5f }, { "High threshold", 1.0f }, { "High ratio", 0.0f }, { "High attack", 0.3f },
  3453. { "High release", 0.3f }, { "High gain", 0.5f }, { "High state", 0.0f },
  3454. { "Low width", 0.5f }, { "Mid width", 0.5f }, { "High width", 0.5f }, { "Width mode", 0.0f } } };
  3455. return info;
  3456. }
  3457. case EffectKind::pocketTapeStop: // round 190by
  3458. {
  3459. static const EffectInfo info { "Pocket Tape Stop", { { "Stop time", 0.2f }, { "Start time", 0.2f }, { "Stop time synced", 1.0f / 3.0f },
  3460. { "Start time synced", 1.0f / 3.0f }, { "Play", 1.0f }, { "Warp", 0.5f },
  3461. { "Sync", 0.0f } } };
  3462. return info;
  3463. }
  3464. // --- round 190dw: FLM's own defaults (each module's default-value function, REA_rodada182c / FLM_FORMAT §7.1)
  3465. case EffectKind::pocketEq:
  3466. {
  3467. static const EffectInfo info { "Pocket EQ", { { "Gain 1", 0.5f }, { "Frequency 1", 0.2f }, { "Bandwidth 1", 0.5f }, { "Kind 1", 0.51f },
  3468. { "Gain 2", 0.5f }, { "Frequency 2", 0.4f }, { "Bandwidth 2", 0.5f }, { "Kind 2", 0.51f },
  3469. { "Gain 3", 0.5f }, { "Frequency 3", 0.6f }, { "Bandwidth 3", 0.5f }, { "Kind 3", 0.51f },
  3470. { "Gain 4", 0.5f }, { "Frequency 4", 0.8f }, { "Bandwidth 4", 0.5f }, { "Kind 4", 0.51f },
  3471. { "Channel 1", 0.0f }, { "Channel 2", 0.0f }, { "Channel 3", 0.0f }, { "Channel 4", 0.0f } } };
  3472. return info;
  3473. }
  3474. case EffectKind::pocketGraphicEq:
  3475. {
  3476. static const EffectInfo info { "Pocket Graphic EQ", { { "80 Hz", 0.5f }, { "160 Hz", 0.5f }, { "375 Hz", 0.5f }, { "750 Hz", 0.5f },
  3477. { "1.5 kHz", 0.5f }, { "3 kHz", 0.5f }, { "6 kHz", 0.5f }, { "12 kHz", 0.5f } } };
  3478. return info;
  3479. }
  3480. case EffectKind::pocketFilter:
  3481. {
  3482. static const EffectInfo info { "Pocket Filter", { { "Frequency", 0.7f }, { "Q", 0.0f }, { "Type", 0.0f }, { "Slope", 0.5f } } };
  3483. return info;
  3484. }
  3485. case EffectKind::pocketReverbClassic:
  3486. {
  3487. static const EffectInfo info { "Pocket Reverb Classic",
  3488. { { "Decay", 0.4f }, { "High damping", 0.8f }, { "Mix", 0.4f }, { "Predelay", 0.0f }, { "Room size", 1.0f },
  3489. { "Diffusion", 1.0f }, { "Width", 1.0f }, { "Low cut", 0.0f }, { "High cut", 1.0f }, { "Input", 1.0f },
  3490. { "ER", 0.25f }, { "Dry level", 0.0f }, { "Input off", 0.0f }, { "Dry off", 0.0f },
  3491. { "ER off", 0.0f }, { "Wet off", 0.0f }, { "Bass mult", 0.0f }, { "Crossover", 0.0f },
  3492. { "Mod rate", 0.499f }, { "Mod depth", 0.0f } } };
  3493. return info;
  3494. }
  3495. case EffectKind::pocketReverb2:
  3496. {
  3497. static const EffectInfo info { "Pocket Reverb 2",
  3498. { { "High cut", 0.16f }, { "Low cut", 0.0187f }, { "Size", 0.5f }, { "Decay", 0.068f }, { "Diffusion", 1.0f },
  3499. { "Damping", 0.16f }, { "Dry", 0.8f }, { "ER", 0.8f }, { "Wet", 0.56f }, { "Side input", 0.0f },
  3500. { "Delay", 0.0f }, { "Tempo", 0.0f }, { "Mod", 0.0f }, { "Bass", 0.28f }, { "Separation", 0.5f },
  3501. { "Speed", 0.33f }, { "Crossover", 0.2405f }, { "Pan", 0.5f } } };
  3502. return info;
  3503. }
  3504. case EffectKind::pocketReverb:
  3505. {
  3506. static const EffectInfo info { "Pocket Reverb",
  3507. { { "Decay", 0.4f }, { "High damping", 0.8f }, { "Mix", 0.4f }, { "Pan", 0.5f }, { "ER", 0.25f },
  3508. { "Predelay", 0.0f }, { "Room size", 1.0f }, { "Diffusion", 1.0f }, { "Width", 1.0f }, { "Low cut", 0.0f },
  3509. { "High cut", 1.0f }, { "Mod rate", 0.499f }, { "Mod depth", 0.0f }, { "Wet gain", 1.0f },
  3510. { "Dry level", 1.0f } } };
  3511. return info;
  3512. }
  3513. // --- end of round 190dw
  3514. case EffectKind::rackMixer:
  3515. {
  3516. static const EffectInfo rackMixerInfo { "Chain mixer", { { "Volume", rack::unityVolume }, { "Pan", 0.5f }, { "Chain select", 1.0f } } };
  3517. return rackMixerInfo;
  3518. }
  3519. case EffectKind::edison: return edisonfx::info();
  3520. case EffectKind::lynxTune: return lynxtune::info();
  3521. case EffectKind::fruityPhaser: return fruityPhaserInfo;
  3522. case EffectKind::epochVerb:
  3523. case EffectKind::atrium:
  3524. case EffectKind::foilPlate:
  3525. case EffectKind::nebula:
  3526. case EffectKind::halo:
  3527. case EffectKind::horizon: return verbs::info (kind);
  3528. case EffectKind::echoform: return echosuite::echoformInfo();
  3529. case EffectKind::spiralEcho: return echosuite::spiralInfo();
  3530. case EffectKind::orbit: return echosuite::orbitInfo();
  3531. case EffectKind::latticeMod: return echosuite::latticeInfo();
  3532. case EffectKind::fruitySend: return fruitySendInfo;
  3533. case EffectKind::crestCompressor: return dyn::crestInfo();
  3534. case EffectKind::prismMultiband: return dyn::prismInfo();
  3535. case EffectKind::sentryGate: return dyn::sentryInfo();
  3536. case EffectKind::quellDenoiser: return voicetools::quellInfo();
  3537. case EffectKind::geminiDoubler: return voicetools::geminiInfo();
  3538. case EffectKind::formulaController: return formulaControllerInfo;
  3539. case EffectKind::voiceShift: return voiceshift::info();
  3540. case EffectKind::emphasizer:
  3541. {
  3542. static const EffectInfo info { "Emphasizer", { { "Input gain", 0.0f }, { "Emphasis", 0.5013f }, { "Soft clipping", 0.0f },
  3543. { "Level matching", 0.0f }, { "Bypass", 0.0f }, { "Output", 1.0f } } };
  3544. return info;
  3545. }
  3546. case EffectKind::flEmphasis:
  3547. {
  3548. // FL's controls and a new instance's values (the "Default" preset)
  3549. static const EffectInfo info { "Emphasis", { { "Bypass", 0.0f }, { "Delta", 0.0f }, { "Envelope order", 0.0f },
  3550. { "True peak", 0.0f }, { "Channel mode", 0.0f }, { "Mode", 0.0f },
  3551. { "Input gain", 0.0f }, { "Linking", 1.0f }, { "Emphasis", 1.0f },
  3552. { "Ceiling", 0.9912f }, { "Level matching", 0.0f }, { "Oversampling", 0.5f },
  3553. { "Hardness", 7.0f / 9.0f }, { "Loudness compensation", 0.0f },
  3554. { "Instant recovery", 1.0f }, { "DC block", 1.0f } } };
  3555. return info;
  3556. }
  3557. case EffectKind::flFrequencyShifter:
  3558. {
  3559. // FL's controls and defaults (a new instance: Mix 100 %, Frequency shifter, +200 Hz in the 200 Hz range)
  3560. static const EffectInfo info { "Frequency Shifter", { { "Mix", 1.0f }, { "Type", 0.5f }, { "Frequency", 1.0f },
  3561. { "L/R phase offset", 0.0f }, { "L shape", 1.0f }, { "R shape", 1.0f },
  3562. { "Feedback", 0.5f }, { "Mono/stereo", 1.0f }, { "Range", 0.5f },
  3563. { "Left phase offset", 0.5f } } };
  3564. return info;
  3565. }
  3566. case EffectKind::flPhaseInverter:
  3567. {
  3568. static const EffectInfo info { "Fruity Phase Inverter", { { "Invert", 1.0f } } };
  3569. return info;
  3570. }
  3571. case EffectKind::flCenter:
  3572. {
  3573. static const EffectInfo info { "Fruity Center", { { "On", 1.0f } } };
  3574. return info;
  3575. }
  3576. case EffectKind::flBassBoost:
  3577. {
  3578. static const EffectInfo info { "Fruity Bass Boost", { { "Frequency", 0.5f }, { "Amount", 0.75f } } };
  3579. return info;
  3580. }
  3581. case EffectKind::fl7BandEq:
  3582. {
  3583. static const EffectInfo info { "Fruity 7 Band EQ", { { "63 Hz", 0.5f }, { "250 Hz", 0.5f }, { "500 Hz", 0.5f },
  3584. { "1.5 kHz", 0.5f }, { "3 kHz", 0.5f }, { "5 kHz", 0.5f },
  3585. { "8 kHz", 0.5f } } };
  3586. return info;
  3587. }
  3588. case EffectKind::flDelay1:
  3589. {
  3590. // FL's defaults: input 338, feedback 512, cutoff 1024, host tempo, 3 sixteenths, normal
  3591. static const EffectInfo info { "Fruity Delay", { { "Input", 338.0f / 1024.0f }, { "Feedback", 0.5f }, { "Cutoff", 1.0f },
  3592. { "Tempo", 0.0f }, { "Time", 2.0f / 15.0f }, { "Mode", 0.0f } } };
  3593. return info;
  3594. }
  3595. case EffectKind::flLowLifter:
  3596. {
  3597. // FL's controls; defaults = the plug-in's Default preset (as a new instance in FL)
  3598. static const EffectInfo info { "Low Lifter", { { "On", 1.0f }, { "Dry/Wet", 1.0f }, { "Low band gain", 0.4999f },
  3599. { "Slope", 0.6993f }, { "Look-ahead", 1.0f }, { "Invert polarity", 0.0f },
  3600. { "Pre gain", 0.4998f }, { "Diffuser mix", 0.0f }, { "Diffuser depth", 0.5f },
  3601. { "High band gain", 1.0f }, { "Crossover", 0.892f }, { "Low cut", 0.0f },
  3602. { "Multiband", 0.0f }, { "High band", 1.0f }, { "Low band", 1.0f } } };
  3603. return info;
  3604. }
  3605. case EffectKind::hardwareInsert:
  3606. {
  3607. // round 164d: no channels chosen at first (nothing reaches a device output before the user picks one)
  3608. static const EffectInfo info { "Hardware Insert", { { "Send", 0.5f }, { "Return", 0.5f }, { "Dry/wet", 1.0f }, { "Invert", 0.0f },
  3609. { "Output", 0.0f }, { "Output mono", 0.0f }, { "Input", 0.0f },
  3610. { "Input stereo", 1.0f }, { "Round trip", 0.0f }, { "Ping", 0.0f } } };
  3611. return info;
  3612. }
  3613. case EffectKind::fruityMute2:
  3614. {
  3615. // round 165g: a new Fruity Mute 2 lets the sound through (Mute = On means sound on, FL's labels), both sides selected
  3616. static const EffectInfo info { "Fruity Mute 2", { { "Mute", 1.0f }, { "Channel", 1.0f / 3.0f } } };
  3617. return info;
  3618. }
  3619. case EffectKind::bigClock:
  3620. {
  3621. static const EffectInfo info { "Fruity Big Clock", { { "Display", 0.0f } } };
  3622. return info;
  3623. }
  3624. case EffectKind::tuner:
  3625. {
  3626. // FL's Default preset: 440 Hz, fast, bass off, Dial
  3627. static const EffectInfo info { "Tuner", { { "Reference", 0.5f }, { "Reactivity", 1.0f }, { "Bass", 0.0f }, { "Visual", 1.0f } } };
  3628. return info;
  3629. }
  3630. case EffectKind::htmlNotebook:
  3631. {
  3632. static const EffectInfo info { "Fruity HTML NoteBook", {} };
  3633. return info;
  3634. }
  3635. case EffectKind::scratcher:
  3636. {
  3637. // FL's defaults (its editor's DFM): platter at 690 / 30000, 1x, stopped, Hold off, Volume 199 / 255
  3638. static const EffectInfo info = [] {
  3639. const auto d = scratcher::defaults();
  3640. return EffectInfo { "Fruity Scratcher",
  3641. { { "Wave position", d[0] }, { "Mute", d[1] }, { "Speed", d[2] }, { "Acceleration", d[3] },
  3642. { "Pan", d[4] }, { "Volume", d[5] }, { "Hold", d[6] }, { "Sensitivity", d[7] },
  3643. { "Transport", d[8] }, { "Smooth 1", d[9] }, { "Smooth 2", d[10] }, { "Smooth 3", d[11] },
  3644. { "Smooth 4", d[12] }, { "Rotations", d[13] }, { "Timecode type", 0.0f },
  3645. { "RIAA preamp", 0.0f } } };
  3646. }();
  3647. return info;
  3648. }
  3649. case EffectKind::flTransporter:
  3650. {
  3651. // FL's controls over their ranges, then the state's source / stereo / send; defaults = FL's Default preset
  3652. static const EffectInfo info = [] {
  3653. float d[transporter::numParams] {};
  3654. transporter::toParams (transporter::State {}, d);
  3655. static const char* const names[transporter::numParams] {
  3656. "Dry level", "Loop A level", "Loop B level", "Reverse probability", "Octave shift probability", "Octave down/up probability",
  3657. "Spread / auto-pan", "Minimum length A", "A/B ratio", "Transient sensitivity", "Bouncing rate", "Freeze", "Flush",
  3658. "Loop mode", "Bypass", "Update loop A", "Update loop B", "Update loops A/B", "Deterministic", "Tempo length",
  3659. "Tempo trigger", "Ignore probability", "Source", "Stereo", "Send to" };
  3660. EffectInfo e { "Transporter", {} };
  3661. for (int k = 0; k < transporter::numParams; ++k)
  3662. e.params.push_back ({ names[k], d[k] });
  3663. return e;
  3664. }();
  3665. return info;
  3666. }
  3667. case EffectKind::transmitter:
  3668. {
  3669. // FL's Default preset (core/Transmitter.h: the 42 controls in FL's order, each over its range)
  3670. static const EffectInfo info = [] {
  3671. const auto d = transmitter::defaults();
  3672. return EffectInfo { "Transmitter",
  3673. {
  3674. { "Sensitivity", d[0] },
  3675. { "Hold", d[1] },
  3676. { "Release", d[2] },
  3677. { "Transient level", d[3] },
  3678. { "Sustain level", d[4] },
  3679. { "Transient tilt", d[5] },
  3680. { "Sustain tilt", d[6] },
  3681. { "Transient diffusion mix", d[7] },
  3682. { "Transient diffusion depth", d[8] },
  3683. { "Transient diffusion delay", d[9] },
  3684. { "Sustain diffusion mix", d[10] },
  3685. { "Sustain diffusion depth", d[11] },
  3686. { "Sustain diffusion delay", d[12] },
  3687. { "Transient saturation mix", d[13] },
  3688. { "Transient saturation drive", d[14] },
  3689. { "Transient saturation warmth", d[15] },
  3690. { "Sustain saturation mix", d[16] },
  3691. { "Sustain saturation drive", d[17] },
  3692. { "Sustain saturation warmth", d[18] },
  3693. { "Transient bounce mix", d[19] },
  3694. { "Transient bounce amplitude curve", d[20] },
  3695. { "Transient bounce delay curve", d[21] },
  3696. { "Sustain bounce mix", d[22] },
  3697. { "Sustain bounce amplitude curve", d[23] },
  3698. { "Sustain bounce delay curve", d[24] },
  3699. { "Transient delay mix", d[25] },
  3700. { "Transient delay time", d[26] },
  3701. { "Transient delay synced time", d[27] },
  3702. { "Transient delay feedback", d[28] },
  3703. { "Sustain delay mix", d[29] },
  3704. { "Sustain delay time", d[30] },
  3705. { "Sustain delay synced time", d[31] },
  3706. { "Sustain delay feedback", d[32] },
  3707. { "Lookahead", d[33] },
  3708. { "Stereo link", d[34] },
  3709. { "Mode", d[35] },
  3710. { "Transient on", d[36] },
  3711. { "Sustain on", d[37] },
  3712. { "Transient effect", d[38] },
  3713. { "Sustain effect", d[39] },
  3714. { "Transient delay tempo sync", d[40] },
  3715. { "Sustain delay tempo sync", d[41] } } };
  3716. }();
  3717. return info;
  3718. }
  3719. case EffectKind::waveCandy:
  3720. {
  3721. // round 164c (core/VisualFx.h wavecandy::Param): a new one shows the spectrum, like FL's Default preset's analyser
  3722. static const EffectInfo info { "Wave Candy", { { "Mode", visualfx::wavecandy::modeValue (visualfx::wavecandy::Mode::spectrum) },
  3723. { "Gain", 0.5f }, { "Hold", 0.0f }, { "Scope window", 0.5f }, { "Separation", 0.0f },
  3724. { "Sync", 1.0f }, { "Speed", 0.35f }, { "Range", 0.5f }, { "Scale", 1.0f },
  3725. { "Weighting", 1.0f }, { "Resolution", 0.5f }, { "Meter mode", 0.0f },
  3726. { "Peak hold", 0.3f }, { "Decay", 0.5f }, { "Meter scale", 0.5f },
  3727. { "Persistence", 0.5f }, { "Thickness", 0.3f }, { "Colour", 0.97f } } };
  3728. return info;
  3729. }
  3730. case EffectKind::visualizer:
  3731. {
  3732. static const EffectInfo info { "Visualizer", { { "Sensitivity", 0.5f }, { "Beat threshold", 0.4f }, { "Hue shift", 0.0f },
  3733. { "Brightness", 1.0f }, { "Zoom", 0.5f }, { "Speed", 0.5f } } };
  3734. return info;
  3735. }
  3736. case EffectKind::xyController:
  3737. case EffectKind::xyzController:
  3738. {
  3739. // round 164: per axis level / min / max / tension, then speed and acceleration (core/XyController.h)
  3740. static const auto make = [] (EffectKind k) {
  3741. EffectInfo info { k == EffectKind::xyController ? "X-Y Controller" : "X-Y-Z Controller", {} };
  3742. static const char* names[3][4] = { { "X level", "X min", "X max", "X tension" },
  3743. { "Y level", "Y min", "Y max", "Y tension" },
  3744. { "Z level", "Z min", "Z max", "Z tension" } };
  3745. const auto d = xy::defaults (k);
  3746. for (int a = 0; a < xy::axesOf (k); ++a)
  3747. for (int i = 0; i < 4; ++i)
  3748. info.params.push_back ({ names[a][i], d[(std::size_t) (4 * a + i)] });
  3749. info.params.push_back ({ "Speed", d[(std::size_t) xy::speed (k)] });
  3750. info.params.push_back ({ "Acceleration", d[(std::size_t) xy::acceleration (k)] });
  3751. if (k == EffectKind::xyzController) // round 165: each axis' output curve mode (FL's point modes)
  3752. for (const auto* n : { "X curve", "Y curve", "Z curve" })
  3753. info.params.push_back ({ n, 0.0f });
  3754. return info;
  3755. };
  3756. static const EffectInfo xyInfo = make (EffectKind::xyController), xyzInfo = make (EffectKind::xyzController);
  3757. return kind == EffectKind::xyController ? xyInfo : xyzInfo;
  3758. }
  3759. case EffectKind::controlSurface:
  3760. {
  3761. // round 164: one parameter per control output (the panel's controls name them, core/ControlSurface.h)
  3762. static const EffectInfo info = [] {
  3763. EffectInfo i { "Control Surface", {} };
  3764. static std::vector<std::string> names;
  3765. for (int k = 0; k < surface::maxSurfaceOutputs; ++k)
  3766. names.push_back ("Control " + std::to_string (k + 1));
  3767. for (const auto& n : names)
  3768. i.params.push_back ({ n.c_str(), 0.0f });
  3769. return i;
  3770. }();
  3771. return info;
  3772. }
  3773. }
  3774. return eq;
  3775. }
  3776. } // namespace
  3777. std::string formatEffectParam (EffectKind kind, int param, float v, double bpm, const EffectParams& context)
  3778. {
  3779. if (kind == EffectKind::pocketCompressor && param == 4) // round 189h: FLM's Level reads 20 dB less with Auto gain on
  3780. return pocket::compressorLevelText (v, context[6] >= 0.5f);
  3781. if (kind == EffectKind::ridgeStrip && param == mixsuite::ridge::driveAmount) // round tp172c6: the model's own dial
  3782. {
  3783. const auto model = mixsuite::ridge::driveModelIndex (context[(std::size_t) mixsuite::ridge::driveModel]);
  3784. const auto u = mixsuite::ridge::driveAmountUnits (model, v);
  3785. char text[32];
  3786. if (model >= mixsuite::ridge::driveGuitarAmp)
  3787. std::snprintf (text, sizeof text, "%.2f", u);
  3788. else
  3789. std::snprintf (text, sizeof text, model == mixsuite::ridge::driveSaturate ? "%+.1f dB" : "%.1f dB", u);
  3790. return text;
  3791. }
  3792. if (kind == EffectKind::ridgeStrip && mixsuite::ridge::modernVoicing (context)) // round tp172c: the Modern voicing's
  3793. return mixsuite::ridge::modernParamText (param, v);
  3794. if (kind == EffectKind::ridgeStrip && mixsuite::ridge::k4Voicing (context)) // round 148: the 4K console's scales
  3795. return mixsuite::ridge::k4ParamText (param, v);
  3796. if (kind == EffectKind::ridgeStrip && mixsuite::ridge::eVoicing (context)) // round 123: the console's own scales
  3797. return mixsuite::ridge::eParamText (param, v);
  3798. if (kind == EffectKind::ridgeStrip && mixsuite::ridge::h32Voicing (context)) // round 190le: the 32C's own dials
  3799. return mixsuite::ridge::h32ParamText (param, v, context);
  3800. if (kind == EffectKind::ridgeStrip && (param == mixsuite::ridge::lfGain || param == mixsuite::ridge::lmfGain
  3801. || param == mixsuite::ridge::hmfGain || param == mixsuite::ridge::hfGain))
  3802. {
  3803. // round 165: Ridge's own engine shows the gain of the curve in use (it showed both: "+6.0 dB / +7.2")
  3804. char text[32];
  3805. std::snprintf (text, sizeof text, "%+.1f dB", mixsuite::ridge::bandGainDb (v, context[(std::size_t) mixsuite::ridge::curve] > 0.5f));
  3806. return text;
  3807. }
  3808. if (kind == EffectKind::geminiDoubler && (param == voicetools::gemini::lowGain || param == voicetools::gemini::highGain)
  3809. && ! voicetools::gemini::measuredEq (context)) // round 165w: round 124's shelves read −30 … +12 dB
  3810. {
  3811. char text[32];
  3812. std::snprintf (text, sizeof text, "%+.1f dB", voicetools::gemini::shelfDb (v, false));
  3813. return text;
  3814. }
  3815. if (kind == EffectKind::glowLeveler && mixsuite::glow::classic (context))
  3816. return mixsuite::glow::classicParamText (param, v);
  3817. if (kind == EffectKind::hushDeEsser && mixsuite::hush::classic (context))
  3818. return mixsuite::hush::classicParamText (param, v);
  3819. if (kind == EffectKind::hushDeEsser && ! mixsuite::hush::extended (context)) // round 165x: the old ranges
  3820. return mixsuite::hush::oldLawText (param, v);
  3821. if (kind == EffectKind::pocketAutoduck && param == 5) // Hold is a share of Time
  3822. return pocket::autoduckHoldText (v, context[3]);
  3823. if (kind == EffectKind::fruityPhaser && param == 0) // the sweep rate follows the frequency range switch
  3824. return phaserfx::sweepText (v, context[3] > 0.5f);
  3825. if (kind == EffectKind::parametricEq && peq::flLaw (context) && param >= 0 && param < peq::slopeParam + peq::bands)
  3826. {
  3827. auto p = context;
  3828. p[(std::size_t) param] = v;
  3829. if (param > peq::outputParam)
  3830. return peq::orderText (p, param - peq::slopeParam);
  3831. if (param < peq::outputParam && param % 4 == 3)
  3832. return peq::widthText (p, param / 4);
  3833. }
  3834. return formatEffectParam (kind, param, v, bpm);
  3835. }
  3836. std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
  3837. {
  3838. char text[48];
  3839. switch (kind)
  3840. {
  3841. case EffectKind::eq:
  3842. if (param == 2)
  3843. std::snprintf (text, sizeof (text), "%.0f Hz", eqMidHz (v));
  3844. else
  3845. std::snprintf (text, sizeof (text), "%+.1f dB", eqGainDb (v));
  3846. return text;
  3847. case EffectKind::compressor:
  3848. switch (param)
  3849. {
  3850. case 0: std::snprintf (text, sizeof (text), "%.1f dB", std::abs (compThresholdDb (v)) < 0.05f ? 0.0f : compThresholdDb (v)); break;
  3851. case 1: std::snprintf (text, sizeof (text), "%.1f:1", compRatio (v)); break;
  3852. case 2: std::snprintf (text, sizeof (text), "%.1f ms", compAttackMs (v)); break;
  3853. case 3: std::snprintf (text, sizeof (text), "%.0f ms", compReleaseMs (v)); break;
  3854. case 5: return v >= 0.5f ? "on" : "off";
  3855. case 6: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  3856. case 7: std::snprintf (text, sizeof (text), "%+.1f dB", -18.0f + 36.0f * v); break;
  3857. case 8: return v >= 0.5f ? "vintage program" : "classic";
  3858. case 9: return v >= 0.5f ? "manual" : "ARC";
  3859. case 10: return v >= 0.5f ? "opto" : "electro";
  3860. case 11: return v >= 0.5f ? "smooth" : "warm";
  3861. case 12: return v >= 0.5f ? "on" : "off";
  3862. case 13: return v >= 0.5f ? "RComp" : "LYNX";
  3863. case 14: std::snprintf (text, sizeof (text), "%.2f:1", rcRatio (v)); break;
  3864. case 15: std::snprintf (text, sizeof (text), "%+.1f dB", rcGainDb (v)); break;
  3865. case 16: std::snprintf (text, sizeof (text), rcAttackMs (v) < 10.0f ? "%.2f ms" : "%.1f ms", rcAttackMs (v)); break;
  3866. case 17: std::snprintf (text, sizeof (text), rcReleaseMs (v) < 100.0f ? "%.1f ms" : "%.0f ms", rcReleaseMs (v)); break;
  3867. case 18: return v >= 0.5f ? "measured" : "round 150";
  3868. case 19: return v >= 0.5f ? "FET" : "clean";
  3869. default: std::snprintf (text, sizeof (text), "+%.1f dB", compMakeupDb (v)); break;
  3870. }
  3871. return text;
  3872. case EffectKind::delay:
  3873. if (param == 0)
  3874. {
  3875. const auto index = delayIndex (v);
  3876. std::snprintf (text, sizeof (text), "%s (%.0f ms)", delayNames[(std::size_t) index],
  3877. delayDivisions[(std::size_t) index] * 60000.0 / std::max (bpm, 20.0));
  3878. return text;
  3879. }
  3880. if (param == 3)
  3881. return v > 0.5f ? "on" : "off";
  3882. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  3883. return text;
  3884. case EffectKind::reverb:
  3885. if (param == 5)
  3886. return v <= 0.001f ? std::string ("off") : (std::snprintf (text, sizeof (text), "%.0f Hz", reverbLowCutHz (v)), std::string (text));
  3887. if (param == 6)
  3888. return v >= 0.999f ? std::string ("off") : (std::snprintf (text, sizeof (text), "%.1f kHz", reverbHighCutHz (v) / 1000.0f), std::string (text));
  3889. if (param == 7)
  3890. std::snprintf (text, sizeof (text), "%.0f ms", v * 1000.0f);
  3891. else
  3892. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  3893. return text;
  3894. case EffectKind::limiter:
  3895. switch (param)
  3896. {
  3897. case 0: std::snprintf (text, sizeof (text), "%.1f dB", limiterCeilingDb (v)); break;
  3898. case 1: std::snprintf (text, sizeof (text), "+%.1f dB", limiterGainDb (v)); break;
  3899. default: std::snprintf (text, sizeof (text), "%.0f ms", limiterReleaseMs (v)); break;
  3900. }
  3901. return text;
  3902. case EffectKind::filter:
  3903. switch (param)
  3904. {
  3905. case 0: return filterNames[(std::size_t) filterType (v)];
  3906. case 1: std::snprintf (text, sizeof (text), "%.0f Hz", filterHz (v)); break;
  3907. case 2: std::snprintf (text, sizeof (text), "Q %.2f", filterQ (v)); break;
  3908. case 4: return filterSteep (v) ? "24 dB/oct" : "12 dB/oct";
  3909. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  3910. }
  3911. return text;
  3912. case EffectKind::distortion:
  3913. switch (param)
  3914. {
  3915. case 0: std::snprintf (text, sizeof (text), "+%.1f dB", distortionDriveDb (v)); break;
  3916. case 1: std::snprintf (text, sizeof (text), "%.0f Hz", distortionToneHz (v)); break;
  3917. case 2: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  3918. default: std::snprintf (text, sizeof (text), "%+.1f dB", (v - 0.5f) * 24.0f); break;
  3919. }
  3920. return text;
  3921. case EffectKind::chorus:
  3922. switch (param)
  3923. {
  3924. case 0: std::snprintf (text, sizeof (text), "%.2f Hz", chorusRateHz (v)); break;
  3925. case 1: std::snprintf (text, sizeof (text), "%.1f ms", chorusDepthMs (v)); break;
  3926. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  3927. }
  3928. return text;
  3929. case EffectKind::parametricEq:
  3930. {
  3931. if (param == peq::outputParam)
  3932. std::snprintf (text, sizeof (text), "%+.1f dB", peq::gainDb (v));
  3933. else if (param > peq::outputParam)
  3934. std::snprintf (text, sizeof (text), "%d dB/oct", 12 * peq::slopeStages (v));
  3935. else
  3936. switch (param % 4)
  3937. {
  3938. case 0: return peq::typeName (peq::type (v));
  3939. case 1:
  3940. {
  3941. const auto f = peq::hz (v);
  3942. if (f >= 1000.0)
  3943. std::snprintf (text, sizeof (text), "%.2f kHz", f / 1000.0);
  3944. else
  3945. std::snprintf (text, sizeof (text), "%.0f Hz", f);
  3946. break;
  3947. }
  3948. case 2: std::snprintf (text, sizeof (text), "%+.1f dB", peq::gainDb (v)); break;
  3949. default: std::snprintf (text, sizeof (text), "Q %.2f", peq::q (v)); break;
  3950. }
  3951. return text;
  3952. }
  3953. case EffectKind::edison:
  3954. return edisonfx::paramText (param, v);
  3955. case EffectKind::rackMixer: // (round 183c: Live's chain units)
  3956. if (param == rack::mixerVolume)
  3957. {
  3958. const auto g = rack::volumeGain (v);
  3959. if (g <= 0.0f)
  3960. return "-inf dB";
  3961. std::snprintf (text, sizeof (text), "%.1f dB", 20.0f * std::log10 (g));
  3962. }
  3963. else if (param == rack::mixerPan)
  3964. {
  3965. const auto pan = (int) std::lround ((v * 2.0f - 1.0f) * 50.0f);
  3966. if (pan == 0)
  3967. return "C";
  3968. std::snprintf (text, sizeof (text), "%d%s", std::abs (pan), pan < 0 ? "L" : "R");
  3969. }
  3970. else
  3971. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  3972. return text;
  3973. case EffectKind::utility:
  3974. if (param == 0)
  3975. {
  3976. if (v <= 0.0f)
  3977. return "mute";
  3978. std::snprintf (text, sizeof (text), "%+.1f dB", utilityGainDb (v));
  3979. }
  3980. else if (param == 1)
  3981. {
  3982. const auto pan = v * 2.0f - 1.0f;
  3983. if (std::abs (pan) < 0.005f)
  3984. return "center";
  3985. std::snprintf (text, sizeof (text), "%.0f%% %s", std::abs (pan) * 100.0f, pan < 0.0f ? "L" : "R");
  3986. }
  3987. else
  3988. std::snprintf (text, sizeof (text), "%.2f", utilityMatrix (v));
  3989. return text;
  3990. case EffectKind::volumeGate:
  3991. if (param < gate::steps || param == gate::mixParam)
  3992. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  3993. else
  3994. std::snprintf (text, sizeof (text), "%.1f ms", param == gate::attackParam ? gate::attackMs (v) : gate::releaseMs (v));
  3995. return text;
  3996. case EffectKind::pitchShift:
  3997. switch (param)
  3998. {
  3999. case 0: std::snprintf (text, sizeof (text), "%+.0f st", pitch::semitones (v)); break;
  4000. case 1: std::snprintf (text, sizeof (text), "%+.0f ct", pitch::cents (v)); break;
  4001. case 3: std::snprintf (text, sizeof (text), "%.0f ms", pitch::windowMs (v)); break;
  4002. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  4003. }
  4004. return text;
  4005. case EffectKind::freqShift:
  4006. if (param == 0)
  4007. std::snprintf (text, sizeof (text), "%+.1f Hz", fshift::hz (v));
  4008. else
  4009. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  4010. return text;
  4011. case EffectKind::peakController:
  4012. if (param == 1)
  4013. {
  4014. const auto raw = (v * 2.0 - 1.0) * 256.0;
  4015. std::snprintf (text, sizeof (text), "%+.0f%%", (raw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (raw) / 256.0) - 1.0) * 40.0);
  4016. }
  4017. else if (param == 3)
  4018. std::snprintf (text, sizeof (text), "%.2f / beat", (std::pow (10001.0, (5.0 + 123.0 * v) / 128.0) - 1.0) * 0.0192);
  4019. else if (param == 2 || param == 6)
  4020. std::snprintf (text, sizeof (text), "%+.0f", (v * 2.0f - 1.0f) * 128.0f);
  4021. else if (param == 5)
  4022. {
  4023. const auto raw = (v * 2.0 - 1.0) * 256.0;
  4024. std::snprintf (text, sizeof (text), "%+.0f%%", (raw < 0.0 ? -1.0 : 1.0) * (std::pow (6.0, std::abs (raw) / 256.0) - 1.0) * 20.0);
  4025. }
  4026. else if (param == 7)
  4027. {
  4028. const auto beats = std::max (3.0 / 96.0, (std::pow (1001.0, (200.0 + v * 65336.0) / 65536.0) - 1.0) * 0.128);
  4029. if (beats >= 4.0)
  4030. std::snprintf (text, sizeof (text), "%.1f bars", beats / 4.0);
  4031. else
  4032. std::snprintf (text, sizeof (text), "%.2f beats", beats);
  4033. }
  4034. else if (param == 8)
  4035. {
  4036. static const char* const shapes[5] = { "Sine", "Triangle", "Square", "Saw", "Random" };
  4037. return shapes[std::clamp ((int) std::lround (v * 4.0f), 0, 4)];
  4038. }
  4039. else if (param == 9)
  4040. std::snprintf (text, sizeof (text), "%.0f\xc2\xb0", v * 360.0f);
  4041. else if (param >= 10)
  4042. return v >= 0.5f ? "on" : "off";
  4043. else
  4044. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  4045. return text;
  4046. case EffectKind::lofi:
  4047. if (param == 0)
  4048. std::snprintf (text, sizeof (text), "%.0f Hz", 44100.0 / lofi::holdSamples (v));
  4049. else if (param == 1)
  4050. std::snprintf (text, sizeof (text), "%.1f bits", std::log2 (lofi::levels (v)));
  4051. else
  4052. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  4053. return text;
  4054. case EffectKind::effector:
  4055. return effector::formatParam (param, v, bpm);
  4056. case EffectKind::pitchCorrect:
  4057. switch (param)
  4058. {
  4059. case 0:
  4060. {
  4061. const auto u = 1.0 - v;
  4062. if (u < 0.01)
  4063. return "instant";
  4064. std::snprintf (text, sizeof (text), "%.1f ms", (3.0 * u * u * u + 0.001) / 8.82 * 1000.0);
  4065. break;
  4066. }
  4067. case 1: std::snprintf (text, sizeof (text), "%+.0f ct", (2.0f * v - 1.0f) * 100.0f); break;
  4068. case 3: std::snprintf (text, sizeof (text), "%.1f Hz", pcorr::noteA (v) * 8.0); break;
  4069. case 4: std::snprintf (text, sizeof (text), "%.0f Hz min.", pcorr::minHz[pcorr::range (v)]); break;
  4070. case 30: std::snprintf (text, sizeof (text), "x%.2f", std::pow (2.0, 2.0 * v - 1.0)); break;
  4071. case 31: return (int) (v + v) == 0 ? "left" : ((int) (v + v) == 1 ? "independent" : "right");
  4072. case 32: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  4073. case 36: return v > 0.5f ? "mix" : "replace";
  4074. case 38: case 39: case 40: case 41:
  4075. std::snprintf (text, sizeof (text), "%+.0f%%", (2.0f * v - 1.0f) * 100.0f);
  4076. break;
  4077. default:
  4078. if (param >= 29)
  4079. return v > 0.5f ? "on" : "off";
  4080. return v > 0.5f ? (param >= 17 ? "bypassed" : "yes") : (param >= 17 ? "-" : "no");
  4081. }
  4082. return text;
  4083. case EffectKind::squeeze:
  4084. std::snprintf (text, sizeof (text), "%d", (int) std::lround (v * squeezeMax[(std::size_t) std::clamp (param, 0, 11)]));
  4085. return text;
  4086. case EffectKind::reeverb2: return reeverb2ParamText (param, v);
  4087. case EffectKind::luxeVerb: return luxeVerbParamText (param, v);
  4088. case EffectKind::convolver: return convolverParamText (param, v);
  4089. case EffectKind::reeverb1: return reeverb1ParamText (param, v);
  4090. case EffectKind::fruityChorus: return fruitychorusfx::paramText (param, v);
  4091. case EffectKind::hyperChorus: return hyperchorusfx::paramText (param, v);
  4092. case EffectKind::vintageChorus: return vintagechorusfx::paramText (param, v);
  4093. case EffectKind::vintagePhaser:
  4094. switch (param)
  4095. {
  4096. case 0: case 1: case 4: std::snprintf (text, sizeof (text), "%.0f Hz", 1.25 * std::pow (2.0, 14.0 * v)); break;
  4097. case 3: case 5: case 7: case 12: case 13: case 17: case 23: case 24: case 33: case 35: return v >= 0.5f ? "on" : "off";
  4098. case 8: return v >= 0.5f ? "sine" : "triangle";
  4099. case 25: std::snprintf (text, sizeof (text), "%.1f dB", 30.0f * v); break;
  4100. case 26: std::snprintf (text, sizeof (text), "%.0f Hz", 50.0f + 600.0f * v); break;
  4101. case 27: case 28: std::snprintf (text, sizeof (text), "%.0f Hz", 195.0f * v * v * v + 5.0f); break;
  4102. case 34: std::snprintf (text, sizeof (text), "%+.1f dB", 30.0f * v - 15.0f); break;
  4103. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  4104. }
  4105. return text;
  4106. case EffectKind::vocoder:
  4107. switch (param)
  4108. {
  4109. case 0: std::snprintf (text, sizeof (text), "%d", vocoder::bands (v)); break;
  4110. case 1: std::snprintf (text, sizeof (text), "%d", vocoder::order (v)); break;
  4111. case 2: return std::array<const char*, 3> { "modulator", "carrier", "mix" }[(std::size_t) std::clamp ((int) std::lround (v * 2.0f), 0, 2)];
  4112. case 3: case 7: case 12: case 16: return v > 0.5f ? "on" : "off";
  4113. case 4: case 5: std::snprintf (text, sizeof (text), "%.0f Hz", (double) fvocoder::edgeHz (vocoder::raw (v, param - 4))); break;
  4114. case 8: std::snprintf (text, sizeof (text), "%+.0f ct", v * 2400.0f - 1200.0f); break;
  4115. case 9: std::snprintf (text, sizeof (text), "%.0f%%", 5.0f + 195.0f * v); break;
  4116. case 10: case 11: std::snprintf (text, sizeof (text), "%d ms", vocoder::raw (v, param - 4)); break;
  4117. case 13: case 14: case 15: std::snprintf (text, sizeof (text), "%.2f", (double) fvocoder::mixLevel (vocoder::raw (v, param - 4))); break;
  4118. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  4119. }
  4120. return text;
  4121. case EffectKind::autoPan:
  4122. if (param >= autopan::source && param < autopan::count)
  4123. return autopan::paramText (param, v);
  4124. [[fallthrough]];
  4125. case EffectKind::rhythmGain:
  4126. if (param == 0)
  4127. std::snprintf (text, sizeof (text), "%.3g beats", v * 64.0f);
  4128. else if (kind == EffectKind::rhythmGain && param == 1)
  4129. std::snprintf (text, sizeof (text), "%d", (int) std::lround (v * rhythm::maxPoints));
  4130. else if (kind == EffectKind::autoPan && (param == 1 || param == 3))
  4131. std::snprintf (text, sizeof (text), "%+.0f%%", (2.0f * v - 1.0f) * 100.0f);
  4132. else if (kind == EffectKind::autoPan && param >= autopan::count) // round 136: the Rhythm voicing (after round 135's panner)
  4133. {
  4134. switch (param - autopan::count + 7)
  4135. {
  4136. case 7: return v > 0.5f ? "Rhythm" : "Classic";
  4137. case 8: std::snprintf (text, sizeof (text), "%.2f Hz", rhythmpan::rateHz (v)); break;
  4138. case 9: return v > 0.5f ? "beats" : "Hz";
  4139. case 10: std::snprintf (text, sizeof (text), "%.3g beats", rhythmpan::beats (v)); break;
  4140. case 11: std::snprintf (text, sizeof (text), "%.1f deg", 210.0f * v); break;
  4141. case 12: std::snprintf (text, sizeof (text), "%+.1f deg", -105.0f + 210.0f * v); break;
  4142. case 14: return v < 0.25f ? "left / right" : v < 0.625f ? "ramp" : v < 0.875f ? "ramp right" : "8 steps";
  4143. case 17: return v < 0.25f ? "digital" : (v < 0.75f ? "analog" : "analog (hot)");
  4144. case 18: std::snprintf (text, sizeof (text), "%+.1f dB", -24.0f + 48.0f * v); break;
  4145. case 19: std::snprintf (text, sizeof (text), "%+.2f oct", -3.0f + 6.0f * v); break;
  4146. case 20: case 21: std::snprintf (text, sizeof (text), "%+.0f deg", -180.0f + 360.0f * v); break;
  4147. case 22: std::snprintf (text, sizeof (text), "%.1f dB", -60.0f + 60.0f * v); break;
  4148. case 23: std::snprintf (text, sizeof (text), "%.1f dB", 1.0f + 39.0f * v); break;
  4149. case 24: case 25: std::snprintf (text, sizeof (text), "%+.3f", -0.25f + 0.5f * v); break;
  4150. case 26: return v >= 0.5f ? "fold" : "clip";
  4151. case 27: return v < 0.25f ? "off (clock)" : (v < 0.75f ? "ping-pong" : "random step");
  4152. case 28: if (v >= 0.999f) return "off (manual only)";
  4153. std::snprintf (text, sizeof (text), "%.1f dB", -60.0f + 60.0f * v); break;
  4154. case 29: std::snprintf (text, sizeof (text), "%d", 1 + (int) std::lround (11.0f * v)); break;
  4155. case 30: return v < 0.25f ? "off" : (v < 0.75f ? "high pass" : "low pass");
  4156. case 31: std::snprintf (text, sizeof (text), "%.0f Hz", 20.0 * std::pow (1000.0, (double) v)); break;
  4157. case 32: return "Trigger";
  4158. case 33: return v >= 0.5f ? "on" : "off";
  4159. default: std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f); break;
  4160. }
  4161. }
  4162. else
  4163. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  4164. return text;
  4165. case EffectKind::fruityFastDist:
  4166. return fastdistfx::paramText (param, v);
  4167. case EffectKind::fruityFlangus:
  4168. return flangusfx::paramText (param, v);
  4169. case EffectKind::fruityFlanger:
  4170. return flangerfx::paramText (param, v);
  4171. case EffectKind::crossover:
  4172. if (param == 0 || param == 3)
  4173. return v > 0.5f ? "on" : "off";
  4174. if (param == 1 || param == 4)
  4175. std::snprintf (text, sizeof (text), "%.0f Hz", xover::hz (v));
  4176. else
  4177. std::snprintf (text, sizeof (text), "%d dB/oct", xover::dbPerOctave[xover::combo (v)]);
  4178. return text;
  4179. case EffectKind::fruityLimiter:
  4180. return fldyn::limiterParamText (param, v);
  4181. case EffectKind::fruityCompressor:
  4182. return fldyn::compressorParamText (param, v);
  4183. case EffectKind::fruityWaveShaper:
  4184. return flshape::waveShaperParamText (param, v);
  4185. case EffectKind::fruitySoftClipper:
  4186. return flshape::softClipperParamText (param, v);
  4187. case EffectKind::stereoShaper:
  4188. return stereofx::stereoShaperParamText (param, v);
  4189. case EffectKind::stereoEnhancer:
  4190. return stereofx::stereoEnhancerParamText (param, v);
  4191. case EffectKind::transientProcessor:
  4192. return stereofx::transientProcessorParamText (param, v);
  4193. case EffectKind::spreader:
  4194. return stereofx::spreaderParamText (param, v);
  4195. case EffectKind::fruityDelayBank:
  4196. return fldbank::globalText (param, v);
  4197. case EffectKind::fruityMultiband:
  4198. return flmb::paramText (param, v);
  4199. case EffectKind::frequencySplitter:
  4200. return fsplit::paramText (param, v);
  4201. case EffectKind::hardcore:
  4202. return hardcore::paramText (param, v);
  4203. case EffectKind::fruityPanOMatic:
  4204. return flbasic::panOMaticParamText (param, v);
  4205. case EffectKind::fruityBalance:
  4206. return flbasic::balanceParamText (param, v);
  4207. case EffectKind::fruitySend:
  4208. return flbasic::sendParamText (param, v);
  4209. case EffectKind::fruityBloodOverdrive:
  4210. return flbasic::bloodOverdriveParamText (param, v);
  4211. case EffectKind::equo:
  4212. return equofx::paramText (param, v);
  4213. case EffectKind::distructor:
  4214. return distructor::paramText (param, v);
  4215. case EffectKind::flPitchShifter:
  4216. return psfl::paramText (param, v);
  4217. case EffectKind::fruityFastLP:
  4218. return flfilter::fastLPParamText (param, v);
  4219. case EffectKind::fruityFreeFilter:
  4220. return flfilter::freeFilterParamText (param, v);
  4221. case EffectKind::fruityFilter:
  4222. return flfilter::filterParamText (param, v);
  4223. case EffectKind::multibandDelay:
  4224. return mbdelay::paramText (param, v);
  4225. case EffectKind::newtone:
  4226. case EffectKind::newtime:
  4227. return newtonefx::paramText (param, v);
  4228. case EffectKind::facetEq:
  4229. return facet::paramText (param, v);
  4230. case EffectKind::apexLimiter:
  4231. return apex::paramText (param, v);
  4232. case EffectKind::ridgeStrip:
  4233. case EffectKind::glowLeveler:
  4234. case EffectKind::hushDeEsser:
  4235. case EffectKind::aether:
  4236. case EffectKind::ember:
  4237. case EffectKind::kilnChannel:
  4238. case EffectKind::fretChannel:
  4239. case EffectKind::shellChannel:
  4240. case EffectKind::strikeShaper:
  4241. case EffectKind::anvilBus:
  4242. case EffectKind::corrode:
  4243. case EffectKind::soundboard:
  4244. case EffectKind::platter:
  4245. case EffectKind::timeprism:
  4246. case EffectKind::harmonia:
  4247. return mixsuite::paramText (kind, param, v);
  4248. case EffectKind::lynxTune:
  4249. return lynxtune::paramText (param, v);
  4250. case EffectKind::fruityPhaser:
  4251. return phaserfx::paramText (param, v);
  4252. case EffectKind::epochVerb:
  4253. case EffectKind::atrium:
  4254. case EffectKind::foilPlate:
  4255. case EffectKind::nebula:
  4256. case EffectKind::halo:
  4257. case EffectKind::horizon:
  4258. return verbs::paramText (kind, param, v, bpm);
  4259. case EffectKind::echoform:
  4260. case EffectKind::spiralEcho:
  4261. case EffectKind::orbit:
  4262. case EffectKind::latticeMod:
  4263. return echosuite::paramText (kind, param, v);
  4264. case EffectKind::crestCompressor:
  4265. case EffectKind::prismMultiband:
  4266. case EffectKind::sentryGate:
  4267. return dyn::paramText (kind, param, v);
  4268. case EffectKind::quellDenoiser:
  4269. case EffectKind::geminiDoubler:
  4270. return voicetools::paramText (kind, param, v);
  4271. case EffectKind::voiceShift:
  4272. return voiceshift::paramText (param, v);
  4273. case EffectKind::emphasizer:
  4274. return emphasizer::paramText (param, v);
  4275. case EffectKind::flEmphasis:
  4276. return emphasis::paramText (param, v);
  4277. case EffectKind::flFrequencyShifter:
  4278. return fsfl::paramText (param, v);
  4279. case EffectKind::flLowLifter:
  4280. return lowlifter::paramText (param, v);
  4281. case EffectKind::flPhaseInverter:
  4282. return fllegacy::phaseInverterParamText (param, v);
  4283. case EffectKind::flCenter:
  4284. return fllegacy::centerParamText (param, v);
  4285. case EffectKind::flBassBoost:
  4286. return fllegacy::bassBoostParamText (param, v);
  4287. case EffectKind::fl7BandEq:
  4288. return fllegacy::eq7ParamText (param, v);
  4289. case EffectKind::flDelay1:
  4290. return fllegacy::delay1ParamText (param, v);
  4291. case EffectKind::pocketDistortion:
  4292. return pocket::distortionParamText (param, v);
  4293. case EffectKind::pocketLimiterClassic:
  4294. return pocket::limiterClassicParamText (param, v);
  4295. case EffectKind::pocketLimiter:
  4296. return pocket::limiterParamText (param, v);
  4297. case EffectKind::pocketLeveller:
  4298. return pocket::levellerParamText (param, v);
  4299. case EffectKind::pocketGate:
  4300. return pocket::gateParamText (param, v);
  4301. case EffectKind::pocketTranceDelay:
  4302. return pocket::tranceDelayParamText (param, v);
  4303. case EffectKind::pocketTapeDelay:
  4304. return pocket::tapeDelayParamText (param, v);
  4305. case EffectKind::pocketMultiFx:
  4306. return pocket::multiFxParamText (param, v);
  4307. case EffectKind::pocketAutoduck:
  4308. return pocket::autoduckParamText (param, v, bpm);
  4309. case EffectKind::pocketChorus:
  4310. return pocket::chorusParamText (param, v);
  4311. case EffectKind::pocketSpacer:
  4312. return pocket::spacerParamText (param, v);
  4313. case EffectKind::pocketStereoizer:
  4314. return pocket::stereoizerParamText (param, v);
  4315. case EffectKind::pocketWowFlutter:
  4316. return pocket::wowFlutterParamText (param, v);
  4317. case EffectKind::pocketPhaser:
  4318. return pocket::phaserParamText (param, v);
  4319. case EffectKind::pocketFlanger:
  4320. return pocket::flangerParamText (param, v);
  4321. case EffectKind::pocketTremolo:
  4322. return pocket::tremoloParamText (param, v);
  4323. case EffectKind::pocketWaveshaper:
  4324. return pocket::waveshaperParamText (param, v);
  4325. case EffectKind::pocketCompressor:
  4326. return pocket::compressorParamText (param, v);
  4327. case EffectKind::pocketSpreader:
  4328. return pocket::spreaderParamText (param, v);
  4329. case EffectKind::pocketComb:
  4330. return pocket::combParamText (param, v);
  4331. case EffectKind::pocketMultiband:
  4332. return pocket::multibandParamText (param, v);
  4333. case EffectKind::pocketTapeStop:
  4334. return pocket::tapeStopParamText (param, v);
  4335. case EffectKind::pocketEq: return pocket::eqParamText (param, v); // round 190dw
  4336. case EffectKind::pocketGraphicEq: return pocket::graphicEqParamText (param, v);
  4337. case EffectKind::pocketFilter: return pocket::filterParamText (param, v);
  4338. case EffectKind::pocketReverbClassic: return pocket::reverbClassicParamText (param, v);
  4339. case EffectKind::pocketReverb2: return pocket::reverb2ParamText (param, v);
  4340. case EffectKind::pocketReverb: return pocket::reverbParamText (param, v);
  4341. case EffectKind::hardwareInsert:
  4342. return hwinsert::paramText (param, v);
  4343. case EffectKind::fruityMute2:
  4344. return flextra::mute2::paramText (param, v);
  4345. case EffectKind::bigClock:
  4346. return flextra::bigclock::paramText (param, v);
  4347. case EffectKind::tuner:
  4348. return flextra::tuner::paramText (param, v);
  4349. case EffectKind::htmlNotebook:
  4350. return {};
  4351. case EffectKind::scratcher:
  4352. return scratcher::paramText (param, v);
  4353. case EffectKind::transmitter:
  4354. return transmitter::paramText (param, v);
  4355. case EffectKind::flTransporter:
  4356. return transporter::paramText (param, v);
  4357. case EffectKind::waveCandy:
  4358. return visualfx::wavecandy::paramText (param, v);
  4359. case EffectKind::visualizer:
  4360. return visualfx::visualizer::paramText (param, v);
  4361. case EffectKind::xyController:
  4362. case EffectKind::xyzController:
  4363. return xy::paramText (kind, param, v);
  4364. case EffectKind::controlSurface:
  4365. std::snprintf (text, sizeof (text), "%.0f%%", v * 100.0f);
  4366. return text;
  4367. case EffectKind::fruityDelay2:
  4368. return fldelay::delay2ParamText (param, v);
  4369. case EffectKind::fruityDelay3:
  4370. return fldelay::delay3ParamText (param, v, bpm);
  4371. case EffectKind::lovePhilter:
  4372. return philter::paramText (param, v);
  4373. case EffectKind::grossBeat:
  4374. {
  4375. const auto raw = grossbeat::rawFromParam (param, v);
  4376. if (param < 2)
  4377. std::snprintf (text, sizeof (text), "slot %d", raw + 1);
  4378. else if (param == 2 || param == 3)
  4379. std::snprintf (text, sizeof (text), "%.0f%%", raw / 2.56);
  4380. else if (param == 4 || param == 5) // 0…500 ms attack, 0…1000 ms release (REA_rodada14 §2.2)
  4381. std::snprintf (text, sizeof (text), "%.1f ms", (std::pow (501.0, raw / 10000.0) - 1.0) * (param == 5 ? 2.0 : 1.0));
  4382. else if (param == 6)
  4383. std::snprintf (text, sizeof (text), "%.0f%%", raw / 2.56);
  4384. else
  4385. return raw != 0 ? "on" : "off";
  4386. return text;
  4387. }
  4388. case EffectKind::formulaController: // the knobs a, b, c as the formula sees them
  4389. std::snprintf (text, sizeof (text), "%.3f", v);
  4390. return text;
  4391. case EffectKind::plugin:
  4392. case EffectKind::parallel:
  4393. case EffectKind::patcher:
  4394. case EffectKind::vocodex:
  4395. case EffectKind::maximus:
  4396. break;
  4397. }
  4398. return {};
  4399. }
  4400. double filterSecondStageQ (double q) noexcept
  4401. {
  4402. const auto x = std::clamp ((q - 0.5) / (q + 1.5), 0.0, 0.999);
  4403. return 0.5 + x / (1.0 + x);
  4404. }
  4405. namespace
  4406. {
  4407. std::atomic<bool> declaredTailsFlag { true };
  4408. }
  4409. void setDeclaredTails (bool on) noexcept { declaredTailsFlag.store (on, std::memory_order_relaxed); }
  4410. bool declaredTails() noexcept { return declaredTailsFlag.load (std::memory_order_relaxed); }
  4411. double biquadTailSamples (double a1, double a2, double db) noexcept
  4412. {
  4413. const auto disc = a1 * a1 - 4.0 * a2;
  4414. double radius = 0.0;
  4415. if (disc < 0.0)
  4416. radius = std::sqrt (std::max (0.0, a2)); // complex poles: |p|² = a2
  4417. else
  4418. {
  4419. const auto s = std::sqrt (disc);
  4420. radius = 0.5 * std::max (std::abs (-a1 + s), std::abs (-a1 - s));
  4421. }
  4422. if (! (radius < 1.0))
  4423. return std::numeric_limits<double>::infinity();
  4424. if (radius < 1.0e-9)
  4425. return 4.0;
  4426. const auto tau = -1.0 / std::log (radius); // samples per neper of decay
  4427. return db / 8.685889638065035 * tau + 8.0 * tau + 4.0;
  4428. }
  4429. EffectSlot makeEffectSlot (EffectKind kind)
  4430. {
  4431. EffectSlot slot;
  4432. slot.kind = kind;
  4433. const auto& info = effectInfo (kind);
  4434. for (std::size_t i = 0; i < info.params.size() && i < slot.params.size(); ++i)
  4435. slot.params[i] = info.params[i].defaultValue;
  4436. if (kind == EffectKind::patcher) // a new Patcher passes its input through, as FL's
  4437. slot.patcher.wires.push_back ({});
  4438. if (kind == EffectKind::visualizer) // round 164c: LYNX's default scene
  4439. slot.state = visualfx::scene::toState (visualfx::scene::defaultScene());
  4440. if (kind == EffectKind::grossBeat) // round 168m: a new Gross Beat starts with LYNX's factory slots (FL loads its default bank)
  4441. slot.state = grossbeat::factoryContainer();
  4442. if (kind == EffectKind::spiralEcho) // round 190fy: a new Spiral Echo runs the measured loop's revision 1 (hidden parameter)
  4443. slot.params[(std::size_t) echosuite::spiral::revision] = 1.0f;
  4444. if (kind == EffectKind::voiceShift) // round 190ho: a new Voice Shift runs the Measured law's revision 1 (hidden parameter)
  4445. slot.params[(std::size_t) voiceshift::revision] = 1.0f;
  4446. if (kind == EffectKind::hushDeEsser) // round 190iq: a new Hush runs the measured Allround timing (hidden)
  4447. slot.params[(std::size_t) mixsuite::hush::timing] = 1.0f;
  4448. if (kind == EffectKind::hushDeEsser) // round 190js: … and Single Vocal's "stands out" revision (hidden)
  4449. slot.params[(std::size_t) mixsuite::hush::vocalRevision] = 1.0f;
  4450. if (kind == EffectKind::echoform) // round 190is: a new Echoform runs the echo voicings' revision 1 (hidden parameter)
  4451. slot.params[(std::size_t) echosuite::echoform::revision] = 1.0f;
  4452. if (kind == EffectKind::crestCompressor) // round 190kw: a new Crest runs the V1 styles' revision 1 (hidden parameter)
  4453. slot.params[(std::size_t) dyn::crest::revision] = 1.0f;
  4454. if (kind == EffectKind::ember) // round 190kw: a new Ember runs the Saturn styles' own laws (hidden parameter)
  4455. slot.params[(std::size_t) mixsuite::ember::revision] = 1.0f;
  4456. // round 190it: a new Epoch Verb / Atrium / Foil Plate / Halo runs the 0.1.30 revision of the Measured law (hidden)
  4457. if (kind == EffectKind::epochVerb) slot.params[(std::size_t) verbs::epoch::revision] = 1.0f;
  4458. if (kind == EffectKind::epochVerb) // round 190kw: … and Epoch's level the reference's loop law (hidden)
  4459. slot.params[(std::size_t) verbs::epoch::loopLaw] = 1.0f;
  4460. if (kind == EffectKind::atrium) slot.params[(std::size_t) verbs::atrium::revision] = 1.0f;
  4461. if (kind == EffectKind::foilPlate) slot.params[(std::size_t) verbs::foil::revision] = 1.0f;
  4462. if (kind == EffectKind::foilPlate) // round 190ln: … and Foil Plate the reference's EQ / bass-decay laws (hidden)
  4463. slot.params[(std::size_t) verbs::foil::reaLaw] = 1.0f;
  4464. if (kind == EffectKind::halo) slot.params[(std::size_t) verbs::halo::revision] = 1.0f;
  4465. if (kind == EffectKind::latticeMod) // round 190it: … and a new Lattice Mod its tap network's revision 1 (hidden)
  4466. slot.params[(std::size_t) echosuite::lattice::revision] = 1.0f;
  4467. return slot;
  4468. }
  4469. std::size_t savedEffectParamCount (const EffectSlot& slot) noexcept
  4470. {
  4471. if (slot.kind == EffectKind::plugin)
  4472. return 0;
  4473. auto count = std::min (effectInfo (slot.kind).params.size(), slot.params.size());
  4474. for (auto i = slot.params.size(); i > count; --i)
  4475. if (slot.params[i - 1] != 0.0f)
  4476. return i;
  4477. return count;
  4478. }
  4479. namespace
  4480. {
  4481. struct HiddenParam
  4482. {
  4483. EffectKind kind;
  4484. int index;
  4485. const char* name;
  4486. };
  4487. const HiddenParam kHiddenWithControl[] {
  4488. { EffectKind::ridgeStrip, (int) mixsuite::ridge::h32, "32C voicing" }, // round 190le
  4489. };
  4490. } // namespace
  4491. int hiddenEffectParamIndex (EffectKind kind, const char* name) noexcept
  4492. {
  4493. if (name != nullptr)
  4494. for (const auto& h : kHiddenWithControl)
  4495. if (h.kind == kind && std::strcmp (h.name, name) == 0)
  4496. return h.index;
  4497. return -1;
  4498. }
  4499. const char* hiddenEffectParamName (EffectKind kind, int index) noexcept
  4500. {
  4501. for (const auto& h : kHiddenWithControl)
  4502. if (h.kind == kind && h.index == index)
  4503. return h.name;
  4504. return nullptr;
  4505. }
  4506. double savedEffectParamValue (float v) noexcept
  4507. {
  4508. const auto rounded = std::round ((double) v * 10000.0) / 10000.0;
  4509. if ((float) rounded == v)
  4510. return rounded;
  4511. for (int digits = 6; digits <= 9; ++digits)
  4512. {
  4513. char text[40];
  4514. std::snprintf (text, sizeof (text), "%.*g", digits, (double) v);
  4515. const auto d = std::strtod (text, nullptr);
  4516. if ((float) d == v)
  4517. return d;
  4518. }
  4519. return (double) v;
  4520. }
  4521. bool effectHasMidiPort (EffectKind kind) noexcept { return kind == EffectKind::grossBeat || kind == EffectKind::pitchCorrect; }
  4522. int effectMidiInPort (const EffectSlot& slot) noexcept
  4523. {
  4524. if (slot.kind == EffectKind::grossBeat)
  4525. return std::clamp (slot.plugin.midiInPort, -1, 255);
  4526. if (slot.kind == EffectKind::pitchCorrect && slot.params[(std::size_t) pcorr::portRoutingParam] > 0.5f)
  4527. return pcorr::midiPort (slot.params[(std::size_t) pcorr::midiPortParam]);
  4528. return -1;
  4529. }
  4530. void setEffectMidiInPort (EffectSlot& slot, int port) noexcept
  4531. {
  4532. port = std::clamp (port, -1, 255);
  4533. if (slot.kind == EffectKind::grossBeat)
  4534. slot.plugin.midiInPort = port;
  4535. else if (slot.kind == EffectKind::pitchCorrect)
  4536. {
  4537. slot.params[(std::size_t) pcorr::midiPortParam] = pcorr::midiPortValue (port);
  4538. slot.params[(std::size_t) pcorr::portRoutingParam] = 1.0f; // (an older project's Pitcher moves to FL's routing)
  4539. }
  4540. }
  4541. void upgradeLoadedEffectParams (EffectSlot& slot, std::size_t savedCount) noexcept
  4542. {
  4543. // round 190ee: a Pitcher saved before its MIDI port keeps taking the notes held on the Channel Rack (round 173d)
  4544. if (slot.kind == EffectKind::pitchCorrect && savedCount <= (std::size_t) pcorr::portRoutingParam)
  4545. slot.params[(std::size_t) pcorr::portRoutingParam] = 0.0f;
  4546. // round 173d3: a Love Philter saved before its units' L / B / H / shaper / IN / NEXT became parameters takes them from its state
  4547. if (slot.kind == EffectKind::lovePhilter)
  4548. philter::upgradeParams (slot, savedCount);
  4549. // round 147: Prism Multiband saved before its measured Dynamic phase engine keeps the round-108 construction
  4550. if (slot.kind == EffectKind::prismMultiband && savedCount <= (std::size_t) dyn::prism::dynamicEngine)
  4551. slot.params[(std::size_t) dyn::prism::dynamicEngine] = 0.0f;
  4552. // round 150: … and before its measured detector keeps the round-108 detector
  4553. if (slot.kind == EffectKind::prismMultiband && savedCount <= (std::size_t) dyn::prism::detectorLaw)
  4554. slot.params[(std::size_t) dyn::prism::detectorLaw] = 0.0f;
  4555. // round 152: … and before the gain-stage attack keeps round 150's level-follower attack
  4556. if (slot.kind == EffectKind::prismMultiband && savedCount <= (std::size_t) dyn::prism::rev152)
  4557. slot.params[(std::size_t) dyn::prism::rev152] = 0.0f;
  4558. // round 190lg: … and before revision 1 (Pro-MB's own band compander graph) keeps the measured detector (bit for bit)
  4559. if (slot.kind == EffectKind::prismMultiband && savedCount <= (std::size_t) dyn::prism::revision)
  4560. slot.params[(std::size_t) dyn::prism::revision] = slot.params[(std::size_t) dyn::prism::lookaheadSwitch] = 0.0f;
  4561. // round 190v: Crest saved before its two-way / vari-mu refit keeps round 108's laws, Sentry saved before its Vocal
  4562. // noise reduction has none
  4563. if (slot.kind == EffectKind::crestCompressor && savedCount <= (std::size_t) dyn::crest::law)
  4564. slot.params[(std::size_t) dyn::crest::law] = 0.0f;
  4565. // round 190kw: … and one saved before the V1 styles' revision keeps the fitted Clean / Classic / Opto (bit for bit)
  4566. if (slot.kind == EffectKind::crestCompressor && savedCount <= (std::size_t) dyn::crest::revision)
  4567. slot.params[(std::size_t) dyn::crest::revision] = 0.0f;
  4568. // round 190lg: a Facet saved before keeps round 190jh / 190js's automatic-threshold law (bit for bit)
  4569. if (slot.kind == EffectKind::facetEq && savedCount <= (std::size_t) facet::autoRevisionParam)
  4570. slot.params[(std::size_t) facet::autoRevisionParam] = 0.0f;
  4571. if (slot.kind == EffectKind::sentryGate && savedCount <= (std::size_t) dyn::sentry::law)
  4572. slot.params[(std::size_t) dyn::sentry::law] = 0.0f;
  4573. // round 150: Auto-pan saved before the Tweak block keeps the Rhythm voicing's clipped angle
  4574. if (slot.kind == EffectKind::autoPan && savedCount <= (std::size_t) autopan::count + 19)
  4575. slot.params[(std::size_t) autopan::count + 19] = 0.0f;
  4576. // round 150: Echoform saved before the voicings' measured stereo behaviour keeps the round-147 voicings
  4577. // round 152: Ember saved before the effect characters' measured law keeps the static stand-ins
  4578. if (slot.kind == EffectKind::ember && savedCount <= (std::size_t) mixsuite::ember::effectLaw)
  4579. slot.params[(std::size_t) mixsuite::ember::effectLaw] = 0.0f;
  4580. // round 165: … and before Punish's measured law keeps round 136's Classic Punish
  4581. if (slot.kind == EffectKind::ember && savedCount <= (std::size_t) mixsuite::ember::classicLaw)
  4582. slot.params[(std::size_t) mixsuite::ember::classicLaw] = 0.0f;
  4583. // round 190ar: … and before the Classic voicing's high-drive coupling keeps round trial187b's high-drive tables
  4584. if (slot.kind == EffectKind::ember && savedCount <= (std::size_t) mixsuite::ember::classicHot)
  4585. slot.params[(std::size_t) mixsuite::ember::classicHot] = 0.0f;
  4586. // round 190fj: … and before the measured tape core keeps the Classic tape curve
  4587. if (slot.kind == EffectKind::ember && savedCount <= (std::size_t) mixsuite::ember::law)
  4588. slot.params[(std::size_t) mixsuite::ember::law] = 0.0f;
  4589. if (slot.kind == EffectKind::echoform && savedCount <= (std::size_t) echosuite::echoform::voicingStereo
  4590. && slot.params.size() > (std::size_t) echosuite::echoform::voicingStereo)
  4591. slot.params[(std::size_t) echosuite::echoform::voicingStereo] = 0.0f;
  4592. // round 190dl: … and before the measured tape stage keeps the classic tape characters, bit for bit
  4593. if (slot.kind == EffectKind::echoform && savedCount <= (std::size_t) echosuite::echoform::engineLaw
  4594. && slot.params.size() > (std::size_t) echosuite::echoform::engineLaw)
  4595. slot.params[(std::size_t) echosuite::echoform::engineLaw] = 0.0f;
  4596. // round 152: a Glow Leveler saved before the measured opto law keeps the round-123 Limit and no classic auto make-up
  4597. if (slot.kind == EffectKind::glowLeveler && savedCount <= (std::size_t) mixsuite::glow::optoLaw)
  4598. slot.params[(std::size_t) mixsuite::glow::optoLaw] = 0.0f;
  4599. // round 190dp: a Quell saved before the matched engine's noise-floor tracker keeps round 124's fixed thresholds
  4600. if (slot.kind == EffectKind::quellDenoiser && savedCount <= (std::size_t) voicetools::quell::law)
  4601. slot.params[(std::size_t) voicetools::quell::law] = 0.0f;
  4602. // round 190dp: a Voice Shift saved before the measured unvoiced path keeps the classic one (unvoiced passes through)
  4603. if (slot.kind == EffectKind::voiceShift && savedCount <= (std::size_t) voiceshift::law)
  4604. slot.params[(std::size_t) voiceshift::law] = 0.0f;
  4605. // round 190ho: … and one saved before the law's revision (0.1.27 … 0.1.29: Law, no hidden revision) keeps round 190dp's grains
  4606. if (slot.kind == EffectKind::voiceShift && savedCount <= (std::size_t) voiceshift::revision)
  4607. slot.params[(std::size_t) voiceshift::revision] = 0.0f;
  4608. // round 165w: a Gemini Doubler saved before the measured shelves keeps round 124's (−30 … +12 dB, first order)
  4609. if (slot.kind == EffectKind::geminiDoubler && savedCount <= (std::size_t) voicetools::gemini::eqLaw)
  4610. slot.params[(std::size_t) voicetools::gemini::eqLaw] = 0.0f;
  4611. // round 165w: … and before the measured release keeps round 123's
  4612. if (slot.kind == EffectKind::glowLeveler && savedCount <= (std::size_t) mixsuite::glow::releaseLaw)
  4613. slot.params[(std::size_t) mixsuite::glow::releaseLaw] = 0.0f;
  4614. // round 165x: a Hush De-esser saved before the extended law keeps ±12 dB levels, the 2 … 16 kHz high-pass, its own link
  4615. if (slot.kind == EffectKind::hushDeEsser && savedCount <= (std::size_t) mixsuite::hush::rangeLaw)
  4616. slot.params[(std::size_t) mixsuite::hush::rangeLaw] = 0.0f;
  4617. // issue #77 (round tp172c): the dynamic air model became Aether's default; an Aether saved before it existed
  4618. // (round 124) keeps the shelf + exciter it was set up with
  4619. if (slot.kind == EffectKind::aether && savedCount <= (std::size_t) mixsuite::aether::dynamic)
  4620. slot.params[(std::size_t) mixsuite::aether::dynamic] = 0.0f;
  4621. // round 190bz: a LYNX reverb saved before the 0.1.27 engine law (per-band decay, tone corrector, onset network)
  4622. // keeps the classic engine, bit for bit
  4623. {
  4624. int law = -1;
  4625. switch (slot.kind)
  4626. {
  4627. case EffectKind::epochVerb: law = verbs::epoch::engineLaw; break;
  4628. case EffectKind::atrium: law = verbs::atrium::engineLaw; break;
  4629. case EffectKind::foilPlate: law = verbs::foil::engineLaw; break;
  4630. case EffectKind::halo: law = verbs::halo::engineLaw; break;
  4631. case EffectKind::horizon: law = verbs::horizon::engineLaw; break;
  4632. default: break;
  4633. }
  4634. if (law >= 0 && savedCount <= (std::size_t) law)
  4635. slot.params[(std::size_t) law] = 0.0f;
  4636. // round 190it: one saved before the 0.1.30 revision keeps the 0.1.27 Measured law, bit for bit
  4637. int rev = -1;
  4638. switch (slot.kind)
  4639. {
  4640. case EffectKind::epochVerb: rev = verbs::epoch::revision; break;
  4641. case EffectKind::atrium: rev = verbs::atrium::revision; break;
  4642. case EffectKind::foilPlate: rev = verbs::foil::revision; break;
  4643. case EffectKind::halo: rev = verbs::halo::revision; break;
  4644. default: break;
  4645. }
  4646. if (rev >= 0 && savedCount <= (std::size_t) rev)
  4647. slot.params[(std::size_t) rev] = 0.0f;
  4648. // round 190kw: an Epoch Verb saved before the loop law keeps revision 1 as it was (or revision 0), bit for bit
  4649. if (slot.kind == EffectKind::epochVerb && savedCount <= (std::size_t) verbs::epoch::loopLaw)
  4650. slot.params[(std::size_t) verbs::epoch::loopLaw] = 0.0f;
  4651. // round 190ln: a Foil Plate saved before the reference's EQ / bass-decay laws keeps revision 1 as it was, bit for bit
  4652. if (slot.kind == EffectKind::foilPlate && savedCount <= (std::size_t) verbs::foil::reaLaw)
  4653. slot.params[(std::size_t) verbs::foil::reaLaw] = 0.0f;
  4654. }
  4655. // round 152: a Compressor saved before the measured vintage curve keeps the round-150 curve
  4656. if (slot.kind == EffectKind::compressor && savedCount <= 18 && slot.params.size() > 18)
  4657. slot.params[18] = 0.0f;
  4658. // round 190do: a Gemini Doubler saved before the measured read head keeps the two crossfaded taps
  4659. if (slot.kind == EffectKind::geminiDoubler && savedCount <= (std::size_t) voicetools::gemini::headLaw)
  4660. slot.params[(std::size_t) voicetools::gemini::headLaw] = 0.0f;
  4661. // round 190do: an Orbit saved before the measured sweep keeps the classic voices
  4662. if (slot.kind == EffectKind::orbit && savedCount <= (std::size_t) echosuite::orbit::law)
  4663. slot.params[(std::size_t) echosuite::orbit::law] = 0.0f;
  4664. // round 190do: a Lattice Mod saved before the measured detune depth keeps the classic one
  4665. if (slot.kind == EffectKind::latticeMod && savedCount <= (std::size_t) echosuite::lattice::law)
  4666. slot.params[(std::size_t) echosuite::lattice::law] = 0.0f;
  4667. // round 190it: … and one saved before the tap network's revision keeps the summed loop
  4668. if (slot.kind == EffectKind::latticeMod && savedCount <= (std::size_t) echosuite::lattice::revision)
  4669. slot.params[(std::size_t) echosuite::lattice::revision] = 0.0f;
  4670. // round 190do: a Spiral Echo saved before the measured loop keeps the classic one
  4671. if (slot.kind == EffectKind::spiralEcho && savedCount <= (std::size_t) echosuite::spiral::law)
  4672. slot.params[(std::size_t) echosuite::spiral::law] = 0.0f;
  4673. // round 190fy: … and one saved before the loop timing's revision (0.1.27: Law, no hidden revision) keeps round 190do's loop
  4674. if (slot.kind == EffectKind::spiralEcho && savedCount <= (std::size_t) echosuite::spiral::revision)
  4675. slot.params[(std::size_t) echosuite::spiral::revision] = 0.0f;
  4676. // round 190iq: a Hush saved before the measured Allround timing keeps tp172b's (bit for bit)
  4677. if (slot.kind == EffectKind::hushDeEsser && savedCount <= (std::size_t) mixsuite::hush::timing)
  4678. slot.params[(std::size_t) mixsuite::hush::timing] = 0.0f;
  4679. // round 190js: … and one saved before Single Vocal's revision keeps round 148's Single Vocal (bit for bit)
  4680. if (slot.kind == EffectKind::hushDeEsser && savedCount <= (std::size_t) mixsuite::hush::vocalRevision)
  4681. slot.params[(std::size_t) mixsuite::hush::vocalRevision] = 0.0f;
  4682. // round 190kw: an Ember saved before the Saturn styles' laws keeps round 150's measured characters (bit for bit)
  4683. if (slot.kind == EffectKind::ember && savedCount <= (std::size_t) mixsuite::ember::revision)
  4684. slot.params[(std::size_t) mixsuite::ember::revision] = 0.0f;
  4685. // round 190is: an Echoform saved before the voicings' revision keeps rounds 147 / 150's voicings
  4686. if (slot.kind == EffectKind::echoform && savedCount <= (std::size_t) echosuite::echoform::revision)
  4687. slot.params[(std::size_t) echosuite::echoform::revision] = 0.0f;
  4688. // round 190kw: … and one saved before the line law (hidden, set only by a translated Timeless 3 state) keeps the engine
  4689. if (slot.kind == EffectKind::echoform && savedCount <= (std::size_t) echosuite::echoform::lineLaw)
  4690. slot.params[(std::size_t) echosuite::echoform::lineLaw] = 0.0f;
  4691. // round 190ca: a Nebula saved before the cloud law keeps the classic engine in every mode
  4692. if (slot.kind == EffectKind::nebula && savedCount <= (std::size_t) verbs::nebula::law)
  4693. slot.params[(std::size_t) verbs::nebula::law] = 0.0f;
  4694. }
  4695. std::unique_ptr<Effect> makeParallelEffect (const EffectSlot& slot)
  4696. {
  4697. return std::make_unique<ParallelEffect> (slot);
  4698. }
  4699. std::unique_ptr<Effect> makeEffect (const EffectSlot& slot)
  4700. {
  4701. if (slot.kind == EffectKind::parallel)
  4702. return makeParallelEffect (slot);
  4703. if (slot.kind == EffectKind::patcher) // built-in nodes only; the rack builds it with its plugins (core/Patcher.h)
  4704. {
  4705. return patcher::makeEffect (slot, 44100.0, patcher::builtInFactories (44100.0));
  4706. }
  4707. if (slot.kind == EffectKind::formulaController)
  4708. return formula::makeEffect (slot.state);
  4709. if (slot.kind == EffectKind::vocodex)
  4710. return vocodex::make (slot.state);
  4711. if (slot.kind == EffectKind::maximus)
  4712. return maximusfx::make (slot.state, slot.engineRev);
  4713. if (slot.kind == EffectKind::multibandDelay)
  4714. return mbdelay::make (slot.state, &slot.params); // (#113: the mode's latency known at once)
  4715. if (slot.kind == EffectKind::vocoder)
  4716. return std::make_unique<Vocoder> (slot.state);
  4717. if (slot.kind == EffectKind::equo)
  4718. return equofx::make (slot.state);
  4719. if (slot.kind == EffectKind::hardcore)
  4720. return hardcore::make (slot);
  4721. if (slot.kind == EffectKind::distructor)
  4722. return distructor::make (slot.state);
  4723. if (slot.kind == EffectKind::fruityWaveShaper)
  4724. return flshape::makeWaveShaper (slot.state);
  4725. if (slot.kind == EffectKind::parametricEq && peq::flLaw (slot.params))
  4726. return std::make_unique<ParametricEq> (slot.params);
  4727. if (slot.kind == EffectKind::frequencySplitter)
  4728. return fsplit::make (slot.params);
  4729. if (slot.kind == EffectKind::limiter) // (rollup step 9: the L2 law's latency known at once)
  4730. return std::make_unique<Limiter> (limiterlaw::isL2 (slot.params[(std::size_t) limiterlaw::lawParam]));
  4731. if (slot.kind == EffectKind::hardwareInsert) // its round trip (latency) known before the first block (round 164d)
  4732. return std::make_unique<hwinsert::HardwareInsertFx> (&slot.params);
  4733. if (slot.kind == EffectKind::flEmphasis) // its look-ahead / oversampling latency known before the first block (round 167f)
  4734. return emphasis::make (&slot.params);
  4735. if (slot.kind == EffectKind::flLowLifter) // its look-ahead (latency) known before the first block (round 154)
  4736. return lowlifter::make (slot.params[4] >= 0.5f);
  4737. if (slot.kind == EffectKind::hushDeEsser) // its look-ahead (latency) known before the first block (round 128)
  4738. return mixsuite::makeHush (&slot.params);
  4739. if (slot.kind == EffectKind::facetEq) // its phase mode (latency) known before the first block
  4740. return facet::make (&slot.params);
  4741. if (slot.kind == EffectKind::ember) // round 152: its processing mode (linear phase: latency) known before the first block
  4742. return mixsuite::makeEmber (&slot.params);
  4743. if (dyn::isDynKind (slot.kind)) // their look-ahead / oversampling latency known before the first block
  4744. return dyn::make (slot.kind, &slot.params);
  4745. if (slot.kind == EffectKind::apexLimiter) // round 135: the oversampling latency known before the first block
  4746. return apex::make (&slot.params);
  4747. if (slot.kind == EffectKind::ridgeStrip) // issue #113: its Vocal voicing / DRIVE latency known before the first block
  4748. return mixsuite::makeRidge (&slot.params);
  4749. if (slot.kind == EffectKind::aether) // issue #113: its model (the exciter's oversampling latency) known before the first block
  4750. return mixsuite::makeAether (&slot.params);
  4751. if (slot.kind == EffectKind::lynxTune) // issue #113: its range / low-latency path known before the first block
  4752. return lynxtune::make (&slot.params);
  4753. if (slot.kind == EffectKind::transmitter) // issue #113: its look-ahead (latency) known before the first block
  4754. return transmitter::make (&slot.params);
  4755. if (slot.kind == EffectKind::flPitchShifter) // issue #113: its engine (latency) known before the first block
  4756. return psfl::make (&slot.params);
  4757. if (slot.kind == EffectKind::compressor) // issue #113: its voicing's latency known before the first block
  4758. return std::make_unique<Compressor> (&slot.params);
  4759. if (slot.kind == EffectKind::pitchCorrect) // issue #113: its formant path's latency known before the first block
  4760. return std::make_unique<PitchCorrect> (&slot.params);
  4761. if (slot.kind == EffectKind::fruityLimiter) // issue #113: its look-ahead (latency) known before the first block
  4762. return fldyn::makeLimiter (&slot.params);
  4763. if (slot.kind == EffectKind::fruityCompressor) // its reported look-ahead known before the first block
  4764. return fldyn::makeCompressor (&slot.params);
  4765. if (slot.kind == EffectKind::hyperChorus)
  4766. return hyperchorusfx::make (hyperchorusfx::instanceOf (slot.state));
  4767. if (slot.kind == EffectKind::vintageChorus)
  4768. return vintagechorusfx::make (hyperchorusfx::instanceOf (slot.state));
  4769. if (slot.kind == EffectKind::grossBeat)
  4770. return grossbeat::make (slot.state);
  4771. if (slot.kind == EffectKind::lovePhilter)
  4772. return philter::make (slot);
  4773. if (slot.kind == EffectKind::convolver)
  4774. return makeConvolver (slot.state);
  4775. if (slot.kind == EffectKind::fruityDelayBank)
  4776. return fldbank::make (slot.state);
  4777. if (slot.kind == EffectKind::fruityMultiband)
  4778. return slot.state.empty() ? flmb::make (&slot.params) : flmb::make (slot.state, &slot.params); // (#113: latency known at once)
  4779. return makeEffect (slot.kind);
  4780. }
  4781. std::unique_ptr<Effect> makeEffect (EffectKind kind)
  4782. {
  4783. switch (kind)
  4784. {
  4785. case EffectKind::eq: return std::make_unique<Eq>();
  4786. case EffectKind::compressor: return std::make_unique<Compressor>();
  4787. case EffectKind::delay: return std::make_unique<Delay>();
  4788. case EffectKind::reverb: return std::make_unique<Reverb>();
  4789. case EffectKind::limiter: return std::make_unique<Limiter>();
  4790. case EffectKind::filter: return std::make_unique<Filter>();
  4791. case EffectKind::distortion: return std::make_unique<Distortion>();
  4792. case EffectKind::chorus: return std::make_unique<Chorus>();
  4793. case EffectKind::parametricEq: return std::make_unique<ParametricEq>();
  4794. case EffectKind::utility: return std::make_unique<Utility>();
  4795. case EffectKind::volumeGate: return std::make_unique<VolumeGate>();
  4796. case EffectKind::peakController: return std::make_unique<PeakController>();
  4797. case EffectKind::pitchShift: return std::make_unique<PitchShift>();
  4798. case EffectKind::freqShift: return std::make_unique<FreqShift>();
  4799. case EffectKind::parallel: return std::make_unique<ParallelEffect> (EffectSlot {}); // empty: use makeParallelEffect
  4800. case EffectKind::patcher: return makeEffect (makeEffectSlot (EffectKind::patcher)); // empty graph: silence
  4801. case EffectKind::lofi: return std::make_unique<LoFi>();
  4802. case EffectKind::effector: return effector::make();
  4803. case EffectKind::crossover: return std::make_unique<Crossover>();
  4804. case EffectKind::rhythmGain: return std::make_unique<RhythmGain>();
  4805. case EffectKind::autoPan: return std::make_unique<AutoPan>();
  4806. case EffectKind::vocoder: return std::make_unique<Vocoder> (std::vector<std::uint8_t> {}); // use makeEffect (slot) for the band levels
  4807. case EffectKind::squeeze: return std::make_unique<Squeeze>();
  4808. case EffectKind::vintagePhaser: return makeVintagePhaser();
  4809. case EffectKind::vocodex: return vocodex::make ({}); // without a state: passes the signal; use makeEffect (slot)
  4810. case EffectKind::maximus: return maximusfx::make ({}); // without a state: passes the signal; use makeEffect (slot)
  4811. case EffectKind::fruityLimiter: return fldyn::makeLimiter();
  4812. case EffectKind::fruityCompressor: return fldyn::makeCompressor();
  4813. case EffectKind::fruityWaveShaper: return flshape::makeWaveShaper ({}); // FL's default curve; use makeEffect (slot)
  4814. case EffectKind::fruitySoftClipper: return flshape::makeSoftClipper();
  4815. case EffectKind::fruityPanOMatic: return flbasic::makePanOMatic();
  4816. case EffectKind::fruityBalance: return flbasic::makeBalance();
  4817. case EffectKind::fruitySend: return flbasic::makeSend(); // FL's Fruity Send (REA_rodada105_send)
  4818. case EffectKind::fruityBloodOverdrive: return flbasic::makeBloodOverdrive();
  4819. case EffectKind::fruityFastLP: return flfilter::makeFastLP();
  4820. case EffectKind::fruityFreeFilter: return flfilter::makeFreeFilter();
  4821. case EffectKind::fruityFilter: return flfilter::makeFilter();
  4822. case EffectKind::reeverb2: return makeReeverb2();
  4823. case EffectKind::luxeVerb: return makeLuxeVerb();
  4824. case EffectKind::convolver: return makeConvolver(); // no impulse response: dry only; use makeEffect (slot)
  4825. case EffectKind::reeverb1: return makeReeverb1();
  4826. case EffectKind::fruityDelay2: return fldelay::makeDelay2();
  4827. case EffectKind::fruityDelay3: return fldelay::makeDelay3();
  4828. case EffectKind::stereoShaper: return stereofx::makeStereoShaper();
  4829. case EffectKind::stereoEnhancer: return stereofx::makeStereoEnhancer();
  4830. case EffectKind::transientProcessor: return stereofx::makeTransientProcessor();
  4831. case EffectKind::spreader: return stereofx::makeSpreader();
  4832. case EffectKind::fruityChorus: return fruitychorusfx::make();
  4833. case EffectKind::hyperChorus: return hyperchorusfx::make();
  4834. case EffectKind::vintageChorus: return vintagechorusfx::make();
  4835. case EffectKind::grossBeat: return grossbeat::make ({}); // without a state: LYNX's factory bank (round 168m); use makeEffect (slot)
  4836. case EffectKind::lovePhilter: return philter::make (EffectSlot {}); // without a state: passes the signal
  4837. case EffectKind::fruityDelayBank: return fldbank::make ({}); // a new FL instance; use makeEffect (slot) for a state
  4838. case EffectKind::fruityMultiband: return flmb::make();
  4839. case EffectKind::equo: return equofx::make ({}); // FL's default EQUO; use makeEffect (slot)
  4840. case EffectKind::flPitchShifter: return psfl::make();
  4841. case EffectKind::frequencySplitter: return fsplit::make();
  4842. case EffectKind::hardcore: return hardcore::make (makeEffectSlot (EffectKind::hardcore)); // no cabinet impulses; use makeEffect (slot)
  4843. case EffectKind::distructor: return distructor::make ({}); // without a state: passes the signal; use makeEffect (slot)
  4844. case EffectKind::multibandDelay: return mbdelay::make ({}); // FL's default Multiband Delay; use makeEffect (slot)
  4845. case EffectKind::pitchCorrect: return std::make_unique<PitchCorrect>();
  4846. case EffectKind::fruityFastDist: return fastdistfx::make();
  4847. case EffectKind::fruityFlangus: return flangusfx::make();
  4848. case EffectKind::fruityFlanger: return flangerfx::make();
  4849. case EffectKind::newtone:
  4850. case EffectKind::newtime: return newtonefx::make (nullptr); // without its sample: a pass-through
  4851. case EffectKind::facetEq: return facet::make();
  4852. case EffectKind::apexLimiter: return apex::make();
  4853. case EffectKind::ridgeStrip:
  4854. case EffectKind::glowLeveler:
  4855. case EffectKind::hushDeEsser:
  4856. case EffectKind::aether:
  4857. case EffectKind::ember:
  4858. case EffectKind::kilnChannel:
  4859. case EffectKind::fretChannel:
  4860. case EffectKind::shellChannel:
  4861. case EffectKind::strikeShaper:
  4862. case EffectKind::anvilBus:
  4863. case EffectKind::corrode:
  4864. case EffectKind::soundboard:
  4865. case EffectKind::platter:
  4866. case EffectKind::timeprism:
  4867. case EffectKind::harmonia: return mixsuite::make (kind); // LYNX's own mixing suite (REA_rodada96)
  4868. case EffectKind::rackMixer: return rack::makeChainMixer(); // a rack chain's mixer (round 183c)
  4869. case EffectKind::edison: return std::make_unique<edisonfx::Processor>(); // without its slot: nothing to play (round 190cd)
  4870. case EffectKind::lynxTune: return lynxtune::make(); // LYNX's own pitch corrector (REA_rodada95)
  4871. case EffectKind::fruityPhaser: return phaserfx::make(); // FL's Fruity Phaser, exact (REA_rodada105_phaser)
  4872. case EffectKind::epochVerb:
  4873. case EffectKind::atrium:
  4874. case EffectKind::foilPlate:
  4875. case EffectKind::nebula:
  4876. case EffectKind::halo:
  4877. case EffectKind::horizon: return verbs::make (kind); // LYNX's own reverbs (REA_rodada100)
  4878. case EffectKind::echoform:
  4879. case EffectKind::spiralEcho:
  4880. case EffectKind::orbit:
  4881. case EffectKind::latticeMod: return echosuite::make (kind); // LYNX's delay / modulation suite (REA_rodada101)
  4882. case EffectKind::crestCompressor:
  4883. case EffectKind::prismMultiband:
  4884. case EffectKind::sentryGate: return dyn::make (kind); // LYNX's dynamics suite (REA_rodada108)
  4885. case EffectKind::quellDenoiser:
  4886. case EffectKind::geminiDoubler: return voicetools::make (kind); // LYNX's voice tools (REA_rodada119)
  4887. case EffectKind::formulaController: return formula::makeEffect ({});
  4888. case EffectKind::voiceShift: return voiceshift::make(); // round 135
  4889. case EffectKind::emphasizer: return emphasizer::make(); // round 154
  4890. case EffectKind::flEmphasis: return emphasis::make(); // round 167f
  4891. case EffectKind::flFrequencyShifter: return fsfl::make(); // round 154
  4892. case EffectKind::flLowLifter: return lowlifter::make(); // round 154
  4893. case EffectKind::flPhaseInverter: return fllegacy::makePhaseInverter(); // round 165k
  4894. case EffectKind::flCenter: return fllegacy::makeCenter();
  4895. case EffectKind::flBassBoost: return fllegacy::makeBassBoost();
  4896. case EffectKind::fl7BandEq: return fllegacy::makeEq7();
  4897. case EffectKind::flDelay1: return fllegacy::makeDelay1();
  4898. case EffectKind::pocketDistortion: return pocket::makeDistortion(); // round 188h (FL Studio Mobile)
  4899. case EffectKind::pocketLimiterClassic: return pocket::makeLimiterClassic();
  4900. case EffectKind::pocketLimiter: return pocket::makeLimiter();
  4901. case EffectKind::pocketLeveller: return pocket::makeLeveller();
  4902. case EffectKind::pocketGate: return pocket::makeGate();
  4903. case EffectKind::pocketTranceDelay: return pocket::makeTranceDelay();
  4904. case EffectKind::pocketTapeDelay: return pocket::makeTapeDelay();
  4905. case EffectKind::pocketMultiFx: return pocket::makeMultiFx();
  4906. case EffectKind::pocketAutoduck: return pocket::makeAutoduck(); // round 189h (FL Studio Mobile)
  4907. case EffectKind::pocketChorus: return pocket::makeChorus();
  4908. case EffectKind::pocketSpacer: return pocket::makeSpacer();
  4909. case EffectKind::pocketStereoizer: return pocket::makeStereoizer();
  4910. case EffectKind::pocketWowFlutter: return pocket::makeWowFlutter(); // round 189h (FL Studio Mobile)
  4911. case EffectKind::pocketPhaser: return pocket::makePhaser();
  4912. case EffectKind::pocketFlanger: return pocket::makeFlanger();
  4913. case EffectKind::pocketTremolo: return pocket::makeTremolo();
  4914. case EffectKind::pocketWaveshaper: return pocket::makeWaveshaper(); // round 189h
  4915. case EffectKind::pocketCompressor: return pocket::makeCompressor();
  4916. case EffectKind::pocketSpreader: return pocket::makeSpreader();
  4917. case EffectKind::pocketComb: return pocket::makeComb(); // round 190by
  4918. case EffectKind::pocketMultiband: return pocket::makeMultiband();
  4919. case EffectKind::pocketTapeStop: return pocket::makeTapeStop();
  4920. case EffectKind::pocketEq: return pocket::makeEq(); // round 190dw
  4921. case EffectKind::pocketGraphicEq: return pocket::makeGraphicEq();
  4922. case EffectKind::pocketFilter: return pocket::makeFilter();
  4923. case EffectKind::pocketReverbClassic: return pocket::makeReverbClassic();
  4924. case EffectKind::pocketReverb2: return pocket::makeReverb2();
  4925. case EffectKind::pocketReverb: return pocket::makeReverb();
  4926. case EffectKind::hardwareInsert: return std::make_unique<hwinsert::HardwareInsertFx>(); // round 164d
  4927. case EffectKind::fruityMute2: return flextra::mute2::make(); // round 165g
  4928. case EffectKind::bigClock:
  4929. case EffectKind::tuner:
  4930. case EffectKind::htmlNotebook: return visualfx::make(); // round 165g: pass the sound, feed the editor's tap
  4931. case EffectKind::scratcher: return scratcher::make (nullptr); // (with its sample: RackRenderer's buildEffect)
  4932. case EffectKind::transmitter: return transmitter::make();
  4933. case EffectKind::flTransporter: return transporter::make(); // round 167f
  4934. case EffectKind::waveCandy:
  4935. case EffectKind::visualizer: return visualfx::make(); // round 164c: passes the sound, feeds the editor's display
  4936. case EffectKind::xyController:
  4937. case EffectKind::xyzController: return xy::makeEffect (kind); // round 164
  4938. case EffectKind::controlSurface: return surface::makeEffect(); // round 164
  4939. case EffectKind::plugin: break; // created by the app (RackState::Factories)
  4940. }
  4941. return std::make_unique<Eq>();
  4942. }
  4943. } // namespace lynx