PluginEditors.cpp 326 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009
  1. #include "ui/SlotWatch.h"
  2. #include "ui/FrameTicker.h"
  3. #include "ui/PatcherEditor.h"
  4. #include "ui/ControllerEditors.h"
  5. #include "ui/Controllers164.h"
  6. #include "ui/NewtoneEditor.h"
  7. #include "ui/AudioEditor.h"
  8. #include "ui/VisualEditors.h"
  9. #include "ui/FlExtraEditors.h"
  10. #include "ui/PluginEditors.h"
  11. #include "core/EditorScale.h"
  12. #include "core/EditorLimit.h"
  13. #include "core/LuxeVerb.h"
  14. #include "core/PresetCycle.h"
  15. #include "core/ShownEffectSlot.h"
  16. #include <cstring>
  17. #include <map>
  18. #include <array>
  19. #include <optional>
  20. #include "core/Effects.h"
  21. #include "core/FlEffects.h"
  22. #include "core/Transmitter.h"
  23. #include "core/TransporterFl.h"
  24. #include "core/FruityShapers.h"
  25. #include "core/FlCurve.h"
  26. #include "core/GrossBeat.h"
  27. #include "core/LynxTune.h"
  28. #include "core/MaximusFx.h"
  29. #include "core/MixSuite.h"
  30. #include "core/EchoSuite.h"
  31. #include "core/VoiceTools.h"
  32. #include "core/ParametricEqFl.h"
  33. #include "core/VocalPitch.h"
  34. #include "core/FruityBasicFx.h"
  35. #include "core/PluginLayout.h"
  36. #include "core/StateParams.h"
  37. #include "core/ConvolverFx.h"
  38. #include "core/EquoFx.h"
  39. #include "core/MultibandDelayFx.h"
  40. #include "core/Vocodex.h"
  41. #include "core/LovePhilter.h"
  42. #include "core/HardwareInsert.h"
  43. #include "engine/Text.h"
  44. #include "ui/DynamicsDisplays.h"
  45. #include "ui/HintBar.h"
  46. #include "ui/I18n.h"
  47. #include "ui/Icons.h"
  48. #include "ui/FacetEqEditor.h"
  49. #include "ui/ProEditors.h"
  50. #include "ui/ParametricEqEditor.h"
  51. #include "core/EffectPresets.h"
  52. #include "ui/PluginHeader.h"
  53. #include "ui/PluginSkin.h"
  54. #include "ui/Theme.h"
  55. #include "ui/ValueControl.h"
  56. #include "ui/WindowOwner.h"
  57. #include "ui/DesignDisplays.inc" // round 168r: the graphs of the designed editors
  58. namespace lynx
  59. {
  60. namespace
  61. {
  62. bool demoDisplays = false; // --plugui: live displays show a synthetic signal
  63. using plugui::Item;
  64. using plugui::LayoutItem;
  65. constexpr float headerHeight = 26.0f; // the presets bar (not scaled with the body)
  66. bool hasStyle (const LayoutItem& item, std::uint32_t flag) noexcept
  67. {
  68. return (item.style & flag) != 0;
  69. }
  70. // a row of tabs drawn as a column (taller than wide: Maximus' band selector)
  71. bool isVertical (const LayoutItem& item) noexcept
  72. {
  73. return item.type == Item::tabs && item.h > item.w * 1.2f;
  74. }
  75. // --- the editor ----------------------------------------------------------------------------------
  76. class NativeEffectEditor final : public juce::Component,
  77. public ui::HintSource,
  78. private juce::ChangeListener,
  79. private juce::Timer
  80. {
  81. public:
  82. // `node` (round 165c): the editor of an effect node inside a Patcher instead of a mixer slot — `node.locate` finds its
  83. // slot in the song, `node.running` its running instance (the live meters); no presets bar, no automation targets
  84. struct NodeTarget
  85. {
  86. std::function<EffectSlot* (Song&)> locate;
  87. std::function<std::shared_ptr<Effect>()> running;
  88. juce::String name;
  89. };
  90. NativeEffectEditor (AudioEngine& e, int t, int s, float initialScale, int initialPage, NodeTarget nodeTarget = {})
  91. : engine (e),
  92. track (t),
  93. slot (s),
  94. node (std::move (nodeTarget))
  95. {
  96. if (const auto* fx = current())
  97. {
  98. kind = fx->kind;
  99. layout = &plugui::layoutFor (kind);
  100. if (kind == EffectKind::ember) // round 165: this window only opens for the Classic voicing — its one-screen
  101. { // panel, not the 1110-unit multiband page around it
  102. static const auto classic = [] { auto l = plugui::layoutFor (EffectKind::ember); l.height = 380; return l; }(); // (tp172d: 760 × 380)
  103. layout = &classic;
  104. }
  105. if (kind == EffectKind::maximus) // Soundgoodizer runs on the Maximus engine: its own page
  106. if (const auto blob = maximusfx::unpack (fx->state); blob && blob->build == hlfx::MaximusBuild::soundgoodizer)
  107. layout = &plugui::soundgoodizerLayout();
  108. if (isSoundgoodizerApprox (*fx)) // without FL's preset files: the same page drives the approximation
  109. {
  110. sgApprox = true;
  111. layout = &plugui::soundgoodizerLayout();
  112. }
  113. }
  114. accent = skin::accentFor (sgApprox ? EffectKind::maximus : kind);
  115. familyAccent = accent;
  116. if (skin::artForEffect (kind) != skin::Art::none && ! sgApprox) // round 170j: its own art (Themed)
  117. {
  118. artLayer = std::make_unique<skin::ArtLayer>();
  119. addAndMakeVisible (*artLayer);
  120. artLayer->setArt (skin::artForEffect (kind), [this] { return editorStyle() == skin::Style::themed; });
  121. }
  122. if (kind == EffectKind::ember || kind == EffectKind::kilnChannel) // round 165: the Classic voicing's VU shows the output level, as the reference's
  123. vuMode = 2;
  124. anim.onFrame = [this] { repaint(); };
  125. page = initialPage;
  126. if (kind == EffectKind::equo && initialPage == 0)
  127. page = 3; // bank 1, volume (FL opens EQUO on its first bank)
  128. if (kind == EffectKind::luxeVerb && initialPage == 0) // round tp172b: open on the engine in use
  129. if (const auto* fx = current())
  130. page = fx->params[(std::size_t) luxeVerbSpaceFirst] >= 0.5f ? 1 : 0;
  131. if (kind == EffectKind::maximus && stateBacked() && initialPage == 0)
  132. if (const auto* fx = current())
  133. page = maximusfx::selectedBand (fx->state); // FL reopens Maximus on the band selected when it was saved
  134. engine.addChangeListener (this);
  135. const auto& l = activeLayout();
  136. for (const auto& item : l.items) // live meters and graphs (mixing suite, LYNX Tune's pitch, round 108's dynamics): 30 Hz
  137. if (item.type == Item::display && item.display != nullptr
  138. && (std::strcmp (item.display, "grmeter") == 0 || std::strcmp (item.display, "grleds") == 0 || std::strcmp (item.display, "vumeter") == 0 || std::strcmp (item.display, "iometer") == 0 || std::strcmp (item.display, "outmeter") == 0 || std::strcmp (item.display, "limitpill") == 0 || std::strcmp (item.display, "gcmeter") == 0
  139. || std::strcmp (item.display, "pitchgraph") == 0 || std::strcmp (item.display, "panpos") == 0 || std::strcmp (item.display, "hwping") == 0
  140. || std::strcmp (item.display, "pitchtrace") == 0 || std::strcmp (item.display, "pitchring") == 0 || std::strcmp (item.display, "tssenvelope") == 0
  141. || dynui::isLive (item.display) || designui::isLive (item.display)))
  142. {
  143. liveDisplays = true;
  144. break;
  145. }
  146. for (const auto& item : l.items) // round 170c: a level meter well shows the slot's live input / output peaks
  147. if (item.type == Item::display && item.display != nullptr && levelDisplay (item.display))
  148. levelMeter = true;
  149. levelTrail.fill ({ -60.0f, -60.0f });
  150. if (levelMeter && ! node.locate)
  151. if (auto* times = engine.getProcessTimes(); times != nullptr && levelKey() < times->levelWanted.size())
  152. times->levelWanted[levelKey()].fetch_add (1, std::memory_order_relaxed);
  153. if (! node.locate)
  154. startTimerHz (30); // live displays, and the controls following their automation (cheap while nothing moves)
  155. else if (liveDisplays)
  156. startTimerHz (30);
  157. // round 170k2: never narrower than its header needs to show the whole name (the body keeps its scale)
  158. setSize (juce::jmax ((int) std::ceil ((float) l.width * initialScale), minimumWidth()),
  159. (int) std::ceil ((float) l.height * initialScale + headerHeight + footerHeight()));
  160. }
  161. ~NativeEffectEditor() override
  162. {
  163. stopTimer();
  164. if (levelMeter && ! node.locate)
  165. if (auto* times = engine.getProcessTimes(); times != nullptr && levelKey() < times->levelWanted.size())
  166. times->levelWanted[levelKey()].fetch_sub (1, std::memory_order_relaxed);
  167. engine.removeChangeListener (this);
  168. ui::hideValueTip();
  169. }
  170. // the design size (for the window's aspect ratio)
  171. juce::Point<int> designSize() const { return { activeLayout().width, activeLayout().height }; }
  172. juce::String headerName() const { return layout == &plugui::soundgoodizerLayout() ? juce::String ("Soundgoodizer") : utf8 (effectInfo (kind).name); }
  173. // round 170k2: the narrowest window whose header still shows the plugin's whole name (the bar at its narrowest)
  174. int minimumWidth() const
  175. {
  176. const auto name = headerName();
  177. const auto left = menuButton().getRight() + 40.0f; // the arrow, LYNX's mark and the LED
  178. const auto right = usesBar() ? pluginheader::PresetBar::narrowWidth() : 22.0f + 26.0f + 90.0f + 4.0f + 6.0f; // prev, next, preset box
  179. return juce::roundToInt (std::ceil (left + skin::titleMinWidth (name, headerHeight) + right));
  180. }
  181. // The slot as shown: while the song plays, its automated parameters at their automation's value (issue #11 comment 4:
  182. // Parametric EQ 2's handles, Fruity Filter's knobs... move with the automation, as in FL). Edits always go through
  183. // setParams, so they change the Song's values.
  184. const EffectSlot* current() const
  185. {
  186. const auto* fx = stored();
  187. return node.locate ? fx : shownSlot.get (engine.getAutomationDisplay(), fx, track, slot, juce::ModifierKeys::currentModifiers.isAnyMouseButtonDown());
  188. }
  189. // the slot in the Song (or the Patcher node)
  190. const EffectSlot* stored() const
  191. {
  192. if (node.locate)
  193. {
  194. const auto* fx = node.locate (const_cast<Song&> (engine.getSong()));
  195. return fx != nullptr && (layout == nullptr || fx->kind == kind) ? fx : nullptr;
  196. }
  197. const auto& mixer = engine.getSong().mixer;
  198. if (track < 0 || track >= (int) mixer.size() || slot < 0 || slot >= (int) mixer[(std::size_t) track].effects.size())
  199. return nullptr;
  200. const auto& fx = mixer[(std::size_t) track].effects[(std::size_t) slot];
  201. return layout == nullptr || fx.kind == kind ? &fx : nullptr;
  202. }
  203. // --- geometry ----------------------------------------------------------------------------------
  204. const plugui::Layout& activeLayout() const
  205. {
  206. static const plugui::Layout empty { "", 360, 120, {} };
  207. return layout != nullptr ? *layout : empty;
  208. }
  209. float scale() const
  210. {
  211. const auto& l = activeLayout();
  212. return juce::jmax (0.25f, juce::jmin ((float) getWidth() / (float) l.width, ((float) getHeight() - headerHeight - footerHeight()) / (float) l.height));
  213. }
  214. // LYNX's own engines show a one-line description of the control under the mouse at the bottom (the reference
  215. // reverbs' description line, round 129)
  216. bool hasHelpLine() const
  217. {
  218. return layout != nullptr && layout != &plugui::soundgoodizerLayout()
  219. && (std::find (plugui::ownLayoutKinds().begin(), plugui::ownLayoutKinds().end(), kind) != plugui::ownLayoutKinds().end()
  220. || kind == EffectKind::lynxTune); // round 135: LYNX Tune's panel too
  221. }
  222. float footerHeight() const { return hasHelpLine() ? 20.0f : 0.0f; }
  223. void paintHelpLine (juce::Graphics& g)
  224. {
  225. using namespace theme;
  226. const auto area = juce::Rectangle<float> (0.0f, (float) getHeight() - footerHeight(), (float) getWidth(), footerHeight());
  227. g.setColour (colour::bg0.withAlpha (0.55f));
  228. g.fillRect (area);
  229. juce::String text;
  230. if (hoverItem >= 0 && hoverItem < (int) activeLayout().items.size())
  231. {
  232. const auto& item = activeLayout().items[(std::size_t) hoverItem];
  233. if (const auto p = paramOf (item); p >= 0)
  234. {
  235. const auto what = pluginheader::describe (kind, effectInfo (kind).params[(std::size_t) p].name);
  236. text = (item.label != nullptr && *item.label != 0 ? tr (item.label) : utf8 (effectInfo (kind).params[(std::size_t) p].name))
  237. + (what.isNotEmpty() ? juce::String::fromUTF8 (" \xe2\x80\x94 ") + what : juce::String());
  238. }
  239. }
  240. // round 135: nothing under the mouse -> what the current mode is (the reference's summary of the algorithm)
  241. if (text.isEmpty())
  242. if (const auto* fx = current())
  243. text = pluginheader::modeLine (kind, fx->params, engine.getSong().bpm);
  244. g.setColour (colour::textSecondary);
  245. g.setFont (font (type::small));
  246. g.drawFittedText (text, area.reduced (10.0f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.85f);
  247. }
  248. // round 135: the MIX caption of a LYNX engine toggles the mix lock (the reference reverbs: click the MIX label)
  249. bool isMixItem (const LayoutItem& item) const
  250. {
  251. const auto p = paramOf (item);
  252. return (item.type == Item::knob || (item.type == Item::vslider && ! hasStyle (item, plugui::captionLeft))) && p >= 0 && hasHelpLine()
  253. && item.label != nullptr && ! hasStyle (item, plugui::noCaption) && juce::String (effectInfo (kind).params[(std::size_t) p].name) == "Mix";
  254. }
  255. juce::Rectangle<float> captionArea (const LayoutItem& item) const
  256. {
  257. const auto r = rectOf (item);
  258. const auto s = scale();
  259. if (item.type == Item::vslider)
  260. return r.withTop (r.getBottom() - 13.0f * s);
  261. if (hasStyle (item, plugui::captionAbove))
  262. return r.withHeight (14.0f * s);
  263. const auto circle = knobCircle (item);
  264. return r.withTop (circle.getBottom()).withHeight (13.0f * s);
  265. }
  266. juce::Rectangle<float> rectOf (const LayoutItem& item) const
  267. {
  268. const auto s = scale();
  269. return { item.x * s, headerHeight + item.y * s, item.w * s, item.h * s };
  270. }
  271. // round tp172c: the art drawn now — Ridge Strip's 4K voicing has its own (dark) console look
  272. skin::Art artNow() const
  273. {
  274. const auto art = skin::artForEffect (kind);
  275. if (art == skin::Art::luxe) // round tp172b4: the Space page has the Pro-R role's own look
  276. return page == 1 ? skin::Art::luxeSpace : art;
  277. if (art != skin::Art::ridge) return art;
  278. const auto* fx = current();
  279. if (fx == nullptr) return art;
  280. const auto on = [&] (const char* name) {
  281. const auto i = plugui::paramIndex (kind, name);
  282. return i >= 0 && i < (int) fx->params.size() && fx->params[(std::size_t) i] >= 0.5f;
  283. };
  284. return on ("4K voicing") && ! on ("Modern voicing") && ! on ("Vocal strip") ? skin::Art::ridge4k : art;
  285. }
  286. bool visible (const LayoutItem& item) const
  287. {
  288. const auto* fx = current();
  289. return fx != nullptr && plugui::isShown (kind, item, page, fx->params, &fx->state);
  290. }
  291. // the destination-insert menus: Fruity Send's "Send to", the Transporter's loop send (round 167n)
  292. bool isSendTarget (int p) const
  293. {
  294. return (kind == EffectKind::fruitySend && p == 3) || (kind == EffectKind::flTransporter && p == transporter::sendParam);
  295. }
  296. // wide option menus of LYNX's own panels get step arrows at both ends (round 114)
  297. bool hasStepArrows (const LayoutItem& item) const
  298. {
  299. return item.type == Item::menu && item.w >= 110.0f && ! hasStyle (item, plugui::plainMenu) && kind != EffectKind::parametricEq && kind != EffectKind::fruitySend && kind != EffectKind::hardwareInsert
  300. && kind != EffectKind::flTransporter
  301. && std::find (plugui::ownLayoutKinds().begin(), plugui::ownLayoutKinds().end(), kind) != plugui::ownLayoutKinds().end();
  302. }
  303. // the knob's circle inside its cell (the caption takes the rest)
  304. juce::Rectangle<float> knobCircle (const LayoutItem& item) const
  305. {
  306. auto r = rectOf (item);
  307. const auto s = scale();
  308. if (hasStyle (item, plugui::valueAbove))
  309. r.removeFromTop (16.0f * s);
  310. if (hasStyle (item, plugui::captionAbove))
  311. {
  312. r.removeFromTop (14.0f * s);
  313. r.removeFromBottom (13.0f * s);
  314. }
  315. else if (! hasStyle (item, plugui::noCaption))
  316. r.removeFromBottom ((hasStyle (item, plugui::showValue) || hasStyle (item, plugui::hoverValue) ? 26.0f : 14.0f) * s);
  317. const auto d = juce::jmin (r.getWidth(), r.getHeight());
  318. return r.withSizeKeepingCentre (d, d).withY (r.getY());
  319. }
  320. int itemAt (juce::Point<float> p) const
  321. {
  322. const auto& items = activeLayout().items;
  323. for (int i = (int) items.size(); --i >= 0;)
  324. {
  325. const auto& item = items[(std::size_t) i];
  326. if (! visible (item) || item.type == Item::section || item.type == Item::label)
  327. continue;
  328. if (item.type == Item::display && rectOf (item).contains (p)
  329. && (plugui::displayTakesMouse (item.display) // round 168x: the list lives in PluginLayout (Maximus' curve added)
  330. || isBars (item) || isRhythmEdit (item) || isRhythmPatterns (item)
  331. || isGbAny (item))) // round 168m: Gross Beat's editor parts
  332. return i;
  333. if (item.type == Item::display || (item.param == nullptr && ! hasStyle (item, plugui::pageTabs)))
  334. continue;
  335. if (rectOf (item).contains (p))
  336. return i;
  337. }
  338. return -1;
  339. }
  340. int paramOf (const LayoutItem& item) const { return item.param != nullptr ? plugui::paramIndex (kind, item.param) : -1; }
  341. // --- values --------------------------------------------------------------------------------------
  342. // Controls stored in the slot's state (core/StateParams.h: Maximus' bands, Delay Bank's banks, band tables...)
  343. // edit those bytes instead of EffectSlot::params
  344. // the header's undo / A-B / preset bar (round 129): every editor whose setting is its parameters
  345. bool usesBar() const { return ! node.locate && ! stateBacked() && layout != &plugui::soundgoodizerLayout() && layout != nullptr; }
  346. // an edit of this editor's slot (a mixer slot or a Patcher node's)
  347. void editSlot (std::function<void (EffectSlot&)> change)
  348. {
  349. if (node.locate)
  350. {
  351. engine.editSong ([l = node.locate, change = std::move (change)] (Song& song) {
  352. if (auto* fx = l (song))
  353. change (*fx);
  354. });
  355. return;
  356. }
  357. engine.editSong ([t = track, sl = slot, change = std::move (change)] (Song& song) {
  358. if (t >= 0 && t < (int) song.mixer.size() && sl >= 0 && sl < (int) song.mixer[(std::size_t) t].effects.size())
  359. change (song.mixer[(std::size_t) t].effects[(std::size_t) sl]);
  360. });
  361. }
  362. bool stateBacked() const { return plugui::usesStateParams (kind) && layout != &plugui::soundgoodizerLayout(); }
  363. bool isStateParam (int param) const { return stateBacked() && plugui::stateIndex (kind, param) >= 0; }
  364. const stateparams::Table& stateTable() const { return *stateparams::tableFor (kind); }
  365. float valueOf (int param) const
  366. {
  367. const auto* fx = current();
  368. if (isStateParam (param))
  369. return fx != nullptr ? plugui::stateValue01 (kind, param, fx->state) : 0.0f;
  370. return fx != nullptr && param >= 0 && param < maxEffectParams ? fx->params[(std::size_t) param] : 0.0f;
  371. }
  372. void setValue (int param, float value)
  373. {
  374. if (isStateParam (param))
  375. {
  376. const auto* fx = current();
  377. if (fx == nullptr)
  378. return;
  379. const auto s = plugui::stateIndex (kind, param);
  380. const auto raw = plugui::stateRaw (kind, param, value);
  381. if (stateTable().get (fx->state, s) == raw)
  382. return;
  383. editSlot ([bytes = stateTable().with (fx->state, s, raw)] (EffectSlot& target) { target.state = bytes; });
  384. return;
  385. }
  386. if (current() == nullptr || param < 0 || param >= maxEffectParams)
  387. return;
  388. if (kind == EffectKind::echoform) // round 135w: Filter link moves the low and high cut together
  389. if (const auto edits = echosuite::echoform::linkedEdit (current()->params, param, value); edits.size() > 1)
  390. {
  391. setParams (edits);
  392. return;
  393. }
  394. if (kind == EffectKind::glowLeveler) // round 165x: AUTO MAKEUP's reference point and its make-up kept when off
  395. if (const auto edits = mixsuite::glow::linkedEdit (current()->params, param, value); edits.size() > 1)
  396. {
  397. setParams (edits);
  398. return;
  399. }
  400. if (kind == EffectKind::ridgeStrip) // round 190le: the 32C voicing and the console voicings exclude each other
  401. if (const auto edits = mixsuite::ridge::linkedEdit (current()->params, param, value); edits.size() > 1)
  402. {
  403. setParams (edits);
  404. return;
  405. }
  406. if (kind == EffectKind::ember) // round 165: the Classic voicing's Auto moves Output with Drive
  407. if (const auto edits = mixsuite::ember::linkedEdit (current()->params, param, value); edits.size() > 1)
  408. {
  409. setParams (edits);
  410. return;
  411. }
  412. if (usesBar())
  413. bar.willEdit();
  414. editSlot ([param, v = juce::jlimit (0.0f, 1.0f, value)] (EffectSlot& target) { target.params[(std::size_t) param] = v; });
  415. // round tp172d: "Advanced" (the Voicing off) swaps this Classic panel for Ember's multiband page
  416. if (kind == EffectKind::ember && param == (int) mixsuite::ember::voicing && value < 0.5f && track >= 0 && node.locate == nullptr)
  417. NativeEffectWindows::switchEmberEditor (engine, track, slot, false);
  418. }
  419. juce::String valueText (int param, float value) const
  420. {
  421. const auto* fx = current();
  422. if (fx == nullptr || param < 0)
  423. return {};
  424. if (isStateParam (param))
  425. return utf8 (stateTable().text (fx->state, plugui::stateIndex (kind, param), plugui::stateRaw (kind, param, value)).c_str());
  426. if (isSendTarget (param))
  427. return flbasic::sendTrack (value) > 0 ? insertName (flbasic::sendTrack (value)) : tr ("None");
  428. if (kind == EffectKind::hardwareInsert && (param == hwinsert::output || param == hwinsert::input))
  429. return hwChannelText (param == hwinsert::output, fx->params);
  430. return utf8 (formatEffectParam (kind, param, value, engine.getSong().bpm, fx->params).c_str());
  431. }
  432. // the hardware insert's output / input as the device names it ("Out 3 - Out 4", "In 2"; "None")
  433. juce::String hwChannelText (bool out, const EffectParams& p) const
  434. {
  435. const auto channel = hwinsert::channelOf (p[out ? hwinsert::output : hwinsert::input]);
  436. if (channel < 0)
  437. return tr ("None");
  438. if (out)
  439. {
  440. const auto mode = hwinsert::outputModeOf (p);
  441. const auto names = engine.getOutputChannelNames();
  442. auto text = juce::String::fromUTF8 (outputTargetName (channel, mode, names, false).c_str());
  443. return text.replace ("(mono)", tr ("(mono)")).replace ("(missing)", tr ("(missing)"));
  444. }
  445. const auto stereo = p[hwinsert::inputStereo] >= 0.5f;
  446. const auto names = engine.getInputChannelNames();
  447. return juce::String::fromUTF8 (inputSourceName (channel, stereo, names).c_str());
  448. }
  449. // the hardware insert's channel menus: the device's pairs, then every channel alone (as the mixer lists them)
  450. void showHwChannelMenu (bool out, juce::Rectangle<float> r)
  451. {
  452. const auto* fx = current();
  453. if (fx == nullptr)
  454. return;
  455. juce::PopupMenu menu;
  456. const auto chosen = hwinsert::channelOf (fx->params[out ? hwinsert::output : hwinsert::input]);
  457. const auto apply = [this] (std::vector<std::pair<int, float>> changes) {
  458. setParams (changes);
  459. engine.openHardwareInsertIo(); // (the device opens the channels: no trip to Audio settings)
  460. };
  461. if (out)
  462. {
  463. const auto mono = fx->params[hwinsert::outputMono] >= 0.5f;
  464. menu.addItem (tr ("None"), true, chosen < 0, [apply] { apply ({ { hwinsert::output, 0.0f } }); });
  465. const auto names = engine.getOutputChannelNames();
  466. if (names.empty())
  467. menu.addItem (tr ("No audio device is open"), false, false, [] {});
  468. for (const auto& t : outputTargets (names))
  469. {
  470. const auto isMono = t.mode != OutputMode::stereo;
  471. const auto busy = t.channel < 2 && engine.getSong().mixer[0].outputChannel == outputDefault; // the Master's own pair
  472. auto name = juce::String::fromUTF8 (t.name.c_str()) + (isMono ? " " + tr ("(mono)") : juce::String());
  473. if (busy)
  474. name += " " + tr ("(the Master plays here)");
  475. menu.addItem (name, true, chosen == t.channel && mono == isMono,
  476. [apply, t, isMono] { apply ({ { hwinsert::output, hwinsert::channelValue (t.channel) }, { hwinsert::outputMono, isMono ? 1.0f : 0.0f } }); });
  477. }
  478. }
  479. else
  480. {
  481. const auto stereo = fx->params[hwinsert::inputStereo] >= 0.5f;
  482. menu.addItem (tr ("None"), true, chosen < 0, [apply] { apply ({ { hwinsert::input, 0.0f } }); });
  483. const auto names = engine.getInputChannelNames();
  484. if (names.empty())
  485. menu.addItem (tr ("Open the audio input"), true, false, [this] {
  486. if (const auto result = engine.openAudioInput(); result.issue != AudioEngine::InputIssue::none)
  487. ui::flashValueTip (*this, getLocalBounds().withHeight (40), tr ("No audio input could be opened (Options > Audio settings)"));
  488. repaint();
  489. });
  490. for (const auto& source : inputSources (names))
  491. menu.addItem (juce::String::fromUTF8 (source.name.c_str()), true, chosen == source.channel && stereo == source.stereo,
  492. [apply, source] { apply ({ { hwinsert::input, hwinsert::channelValue (source.channel) }, { hwinsert::inputStereo, source.stereo ? 1.0f : 0.0f } }); });
  493. }
  494. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  495. }
  496. // an insert's name as the mixer shows it
  497. juce::String insertName (int t) const
  498. {
  499. const auto& mixer = engine.getSong().mixer;
  500. const auto name = t > 0 && t < (int) mixer.size() ? juce::String::fromUTF8 (mixer[(std::size_t) t].name.c_str()) : juce::String();
  501. return name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (t) });
  502. }
  503. juce::String trackName() const
  504. {
  505. if (node.locate)
  506. return node.name;
  507. const auto& mixer = engine.getSong().mixer;
  508. if (track == 0)
  509. return tr ("Master");
  510. const auto name = track < (int) mixer.size() ? juce::String::fromUTF8 (mixer[(std::size_t) track].name.c_str()) : juce::String();
  511. return name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (track) });
  512. }
  513. ui::ValueSpec specFor (const LayoutItem& item) const
  514. {
  515. ui::ValueSpec spec;
  516. const auto param = paramOf (item);
  517. const auto& info = effectInfo (kind);
  518. if (isStateParam (param))
  519. {
  520. // not automatable (the values live in the state): drag, wheel, reset and type-in only
  521. const auto& p = stateTable().params[(std::size_t) plugui::stateIndex (kind, param)];
  522. spec.name = trackName() + " - " + utf8 (info.name) + " - " + utf8 (p.name.c_str());
  523. spec.defaultValue = p.maximum > p.minimum ? (double) (p.defaultValue - p.minimum) / (double) (p.maximum - p.minimum) : 0.0;
  524. spec.pixelsForRange = item.type == Item::hslider ? juce::jmax (60.0, (double) rectOf (item).getWidth())
  525. : item.type == Item::vslider ? juce::jmax (60.0, (double) rectOf (item).getHeight())
  526. : 180.0;
  527. if (item.steps > 0)
  528. spec.interval = 1.0 / item.steps;
  529. else if (p.maximum - p.minimum <= 16)
  530. spec.interval = 1.0 / juce::jmax (1, p.maximum - p.minimum);
  531. spec.toText = [this, param] (double v) { return valueText (param, (float) v); };
  532. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  533. return spec;
  534. }
  535. if (param < 0 || param >= (int) info.params.size())
  536. return spec;
  537. spec.name = trackName() + " - " + utf8 (info.name) + " - " + utf8 (info.params[(std::size_t) param].name);
  538. spec.defaultValue = info.params[(std::size_t) param].defaultValue;
  539. spec.pixelsForRange = item.type == Item::hslider ? juce::jmax (60.0, (double) rectOf (item).getWidth())
  540. : item.type == Item::vslider ? juce::jmax (60.0, (double) rectOf (item).getHeight())
  541. : 180.0;
  542. if (item.steps > 0)
  543. spec.interval = 1.0 / item.steps;
  544. spec.toText = [this, param] (double v) { return valueText (param, (float) v); };
  545. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  546. if (! node.locate)
  547. spec.target = AutomationTarget { AutomationTargetKind::effectParam, track, slot, param };
  548. return spec;
  549. }
  550. // --- painting ------------------------------------------------------------------------------------
  551. // this editor's style (round 126: one per plugin, alternating; Settings may force one)
  552. int styleKey() const { return skin::styleKey (kind, layout == &plugui::soundgoodizerLayout()); }
  553. skin::Style editorStyle() const { return skin::styleFor (kind, layout == &plugui::soundgoodizerLayout()); }
  554. // round 170j: the art's moving part (Nebula's twinkling stars) lives in the free strip right of the last menu
  555. juce::Rectangle<float> artStage() const
  556. {
  557. const LayoutItem* last = nullptr;
  558. for (const auto& item : activeLayout().items)
  559. if (item.type == Item::menu && (last == nullptr || item.y >= last->y))
  560. last = &item;
  561. if (last == nullptr)
  562. return {};
  563. const auto r = rectOf (*last);
  564. return { r.getRight() + 16.0f, r.getY() - 4.0f, juce::jmax (0.0f, (float) getWidth() - r.getRight() - 28.0f), r.getHeight() + 8.0f };
  565. }
  566. void resized() override
  567. {
  568. if (artLayer == nullptr)
  569. return;
  570. artLayer->setBounds (getLocalBounds());
  571. artLayer->setStage (artStage());
  572. artLayer->toFront (false);
  573. }
  574. void paint (juce::Graphics& g) override
  575. {
  576. using namespace theme;
  577. const skin::StyleScope styleScope (editorStyle(), artNow());
  578. accent = editorStyle() == skin::Style::themed ? skin::artAccent (artNow()) : familyAccent;
  579. skin::canvas (g, getLocalBounds().toFloat(), accent);
  580. const auto* fx = current();
  581. if (fx == nullptr)
  582. {
  583. g.setColour (colour::textSecondary);
  584. g.setFont (font (type::body));
  585. g.drawText (tr ("The effect was removed from this slot."), getLocalBounds(), juce::Justification::centred);
  586. return;
  587. }
  588. paintHeader (g, *fx);
  589. const auto& items = activeLayout().items;
  590. for (int i = 0; i < (int) items.size(); ++i)
  591. if (visible (items[(std::size_t) i])
  592. && (artLayer == nullptr || g.clipRegionIntersects (rectOf (items[(std::size_t) i]).expanded (40.0f, 24.0f).getSmallestIntegerContainer())))
  593. {
  594. // round 170j: a partial repaint of the art draws only what it touches; round 170c: a control another mode bypasses is drawn dimmed
  595. const auto idle = plugui::isIdle (kind, items[(std::size_t) i], fx->params);
  596. if (idle) g.beginTransparencyLayer (0.35f);
  597. skin::setOnDarkFill (onDarkFill (i)); // round tp172d
  598. paintItem (g, items[(std::size_t) i], i, *fx);
  599. skin::setOnDarkFill (false);
  600. if (idle) g.endTransparencyLayer();
  601. }
  602. if (hasHelpLine())
  603. paintHelpLine (g);
  604. }
  605. juce::Rectangle<float> headerArea() const { return { 0.0f, 0.0f, (float) getWidth(), headerHeight }; }
  606. juce::Rectangle<float> menuButton() const { return { 4.0f, 3.0f, 22.0f, 20.0f }; }
  607. juce::Rectangle<float> nextButton() const { return { (float) getWidth() - 26.0f, 3.0f, 20.0f, 20.0f }; }
  608. juce::Rectangle<float> prevButton() const { return nextButton().translated (-22.0f, 0.0f); }
  609. juce::Rectangle<float> presetBox() const
  610. {
  611. // round 170k2: the box gives way to the title (never below 90 px)
  612. const auto name = headerName();
  613. const auto room = prevButton().getX() - 4.0f - 6.0f - (menuButton().getRight() + 40.0f) - skin::titleMinWidth (name, headerHeight);
  614. const auto w = juce::jlimit (90.0f, juce::jmax (90.0f, room), juce::jlimit (90.0f, 220.0f, (float) getWidth() * 0.32f));
  615. return { prevButton().getX() - w - 4.0f, 3.0f, w, 20.0f };
  616. }
  617. void paintHeader (juce::Graphics& g, const EffectSlot& fx)
  618. {
  619. using namespace theme;
  620. const auto area = headerArea();
  621. skin::headerBar (g, area, accent);
  622. // options menu (FL's arrow at the left of the plugin's title)
  623. drawArrow (g, menuButton(), 0.0f, hoverHeader == 1 ? accent : colour::textSecondary);
  624. // LYNX's mark, bypass LED, name, where it is
  625. skin::brandMark (g, juce::Rectangle<float> (menuButton().getRight() + 2.0f, 0.0f, 18.0f, area.getHeight()));
  626. const auto ledC = juce::Point<float> (menuButton().getRight() + 30.0f, area.getCentreY());
  627. skin::powerLed (g, ledC, 7.0f, fx.enabled);
  628. const auto name = headerName();
  629. auto text = area.withLeft (ledC.x + 10.0f).withRight (presetBox().getX() - 6.0f);
  630. if (usesBar())
  631. text = bar.place (area, true, ledC.x + 10.0f - area.getX() + skin::titleMinWidth (name, area.getHeight())).withLeft (ledC.x + 10.0f);
  632. const auto nameWidth = skin::titleText (g, text.withHeight (area.getHeight()), name, accent);
  633. text.removeFromLeft (nameWidth);
  634. // round 177b: the "Sidechain from" picker at the right end of the title space (when it fits)
  635. sidechainChip = {};
  636. if (showsSidechain())
  637. if (constexpr float w = 118.0f; text.getWidth() >= w + 14.0f)
  638. {
  639. sidechainChip = { text.getRight() - w, 3.0f, w, 20.0f };
  640. text.setRight (sidechainChip.getX() - 4.0f);
  641. paintSidechainChip (g, fx);
  642. }
  643. g.setFont (font (type::small));
  644. g.setColour (colour::textSecondary);
  645. // where it is: only when it fits whole (round 170k2: no "(I…" stub beside the name)
  646. if (const auto where = "(" + trackName() + ")"; ! plugui::hostedElsewhere && juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), where) <= text.getWidth() - 9.0f)
  647. g.drawText (where, text.withTrimmedLeft (8.0f), juce::Justification::centredLeft, false);
  648. if (usesBar())
  649. {
  650. bar.paint (g, accent);
  651. return;
  652. }
  653. // presets: name, previous, next
  654. const auto box = presetBox();
  655. skin::valuePlate (g, box, radius::md);
  656. if (hoverHeader == 2)
  657. {
  658. g.setColour (accent.withAlpha (0.5f));
  659. g.drawRoundedRectangle (box.reduced (0.5f), radius::md, 1.0f);
  660. }
  661. g.setColour (presetName.isNotEmpty() ? colour::textPrimary : colour::textSecondary);
  662. ui::drawFittingText (g, presetName.isNotEmpty() ? presetName : tr ("(no preset)"), box.reduced (8.0f, 0.0f), juce::Justification::centredRight,
  663. font (type::small, presetName.isNotEmpty()), 8.0f, 0.0f, 0.75f);
  664. drawArrow (g, prevButton(), juce::MathConstants<float>::pi, hoverHeader == 3 ? accent : colour::textSecondary);
  665. drawArrow (g, nextButton(), 0.0f, hoverHeader == 4 ? accent : colour::textSecondary);
  666. }
  667. // round 177b: a mixer slot's effect with a side input shows its "Sidechain from" picker in the header
  668. bool showsSidechain() const { return ! node.locate && pluginheader::takesSidechain (engine, track, slot); }
  669. void paintSidechainChip (juce::Graphics& g, const EffectSlot& fx)
  670. {
  671. using namespace theme;
  672. const auto box = sidechainChip;
  673. const auto source = pluginheader::sidechainSourceText (engine.getSong(), fx);
  674. skin::valuePlate (g, box, radius::md);
  675. if (hoverHeader == 6 || source.isNotEmpty())
  676. {
  677. g.setColour (accent.withAlpha (hoverHeader == 6 ? 0.7f : 0.45f));
  678. g.drawRoundedRectangle (box.reduced (0.5f), radius::md, 1.0f);
  679. }
  680. const auto modulator = kind == EffectKind::vocoder || kind == EffectKind::vocodex;
  681. const auto text = (modulator ? tr ("Modulator") : tr ("SC")) + ": " + (source.isNotEmpty() ? source : tr ("None"));
  682. g.setColour (source.isNotEmpty() ? colour::textPrimary : colour::textSecondary);
  683. ui::drawFittingText (g, text, box.reduced (7.0f, 0.0f).withTrimmedRight (9.0f), juce::Justification::centredLeft,
  684. font (type::small, source.isNotEmpty()), 8.0f, 0.0f, 0.75f);
  685. drawArrow (g, { box.getRight() - 14.0f, box.getY(), 10.0f, box.getHeight() }, juce::MathConstants<float>::halfPi,
  686. hoverHeader == 6 ? accent : colour::textSecondary);
  687. }
  688. juce::Rectangle<float> sidechainChip; // where the header drew it (empty: not shown)
  689. static void drawArrow (juce::Graphics& g, juce::Rectangle<float> r, float angle, juce::Colour c)
  690. {
  691. juce::Path p;
  692. p.addTriangle (-3.0f, -5.0f, -3.0f, 5.0f, 4.0f, 0.0f);
  693. p.applyTransform (juce::AffineTransform::rotation (angle).translated (r.getCentreX(), r.getCentreY()));
  694. g.setColour (c);
  695. g.fillPath (p);
  696. }
  697. juce::Colour arcColour (const EffectSlot& fx, int colourIndex = -1) const
  698. {
  699. if (! fx.enabled)
  700. return theme::colour::textDisabled;
  701. return colourIndex >= 0 ? peqview::bandColour (colourIndex) : accent;
  702. }
  703. void caption (juce::Graphics& g, const LayoutItem& item, juce::Rectangle<float> r, juce::Justification j = juce::Justification::centred)
  704. {
  705. using namespace theme;
  706. if (item.label == nullptr || *item.label == 0)
  707. return;
  708. const auto locked = isMixItem (item) && pluginheader::isMixLocked (kind);
  709. if (locked) // round 135: the locked MIX caption is boxed in the accent colour
  710. {
  711. const auto w = juce::jmin (r.getWidth(), juce::GlyphArrangement::getStringWidth (font (juce::jmax (8.0f, 9.5f * scale()), true), caps (tr (item.label))) + 10.0f);
  712. g.setColour (accent.withAlpha (0.25f));
  713. g.fillRoundedRectangle (r.withSizeKeepingCentre (w, r.getHeight()), 3.0f);
  714. g.setColour (accent);
  715. g.drawRoundedRectangle (r.withSizeKeepingCentre (w, r.getHeight()), 3.0f, 1.0f);
  716. }
  717. g.setColour (locked ? theme::colour::textPrimary : hasStyle (item, plugui::dim) ? colour::textDisabled : skin::captionColour());
  718. // tp172d (look slice): a printed scale word with a unit ("20 Hz", "-24 dB") keeps its case
  719. const auto text = tr (item.label);
  720. const auto printedUnit = hasStyle (item, plugui::dim) && text.containsAnyOf ("0123456789");
  721. ui::drawFittingText (g, skin::lowerCaptions() ? text.toLowerCase() : printedUnit ? text : caps (text), r.expanded (0.0f, (skin::captionScale() - 1.0f) * 6.0f * scale()), j,
  722. font (juce::jmax (8.0f, 9.5f * scale() * skin::captionScale()), true), 7.0f); // (round 165: fit, no "..."; tp172d: themed size)
  723. }
  724. // round tp172d: does item `index` sit on a top-level section the theme fills dark (the last one under its centre)?
  725. bool onDarkFill (int index) const
  726. {
  727. const auto& items = activeLayout().items;
  728. const auto& it = items[(std::size_t) index];
  729. if (it.type == Item::section)
  730. return false;
  731. const juce::Point<float> c { it.x + it.w * 0.5f, it.y + it.h * 0.5f };
  732. int ordinal = 0, under = -1;
  733. for (int k = 0; k < (int) items.size(); ++k)
  734. {
  735. const auto& s = items[(std::size_t) k];
  736. if (s.type != Item::section || hasStyle (s, plugui::raised) || ! visible (s))
  737. continue;
  738. if (juce::Rectangle<float> (s.x, s.y, s.w, s.h).contains (c))
  739. under = ordinal;
  740. ++ordinal;
  741. }
  742. return skin::sectionFillIsDark (under);
  743. }
  744. void paintItem (juce::Graphics& g, const LayoutItem& item, int index, const EffectSlot& fx)
  745. {
  746. using namespace theme;
  747. const auto r = rectOf (item);
  748. const auto s = scale();
  749. const auto param = paramOf (item);
  750. const auto value = valueOf (param);
  751. const auto hot = index == hoverItem || index == dragItem;
  752. const auto glow = index == dragItem ? 1.0f : anim.level (index);
  753. switch (item.type)
  754. {
  755. case Item::section:
  756. {
  757. {
  758. int ordinal = 0; // round tp172d: the section's place among the top-level ones (a theme's own fills)
  759. const auto& items = activeLayout().items;
  760. for (int k = 0; k < index && k < (int) items.size(); ++k)
  761. if (items[(std::size_t) k].type == Item::section && ! hasStyle (items[(std::size_t) k], plugui::raised) && visible (items[(std::size_t) k]))
  762. ++ordinal;
  763. skin::setSectionOrdinal (hasStyle (item, plugui::raised) ? -1 : ordinal);
  764. }
  765. skin::section (g, r, radius::lg * s, hasStyle (item, plugui::raised), fx.enabled ? accent : juce::Colours::transparentBlack);
  766. skin::setSectionOrdinal (-1);
  767. if (item.label != nullptr && *item.label != 0 && ! hasStyle (item, plugui::boxed))
  768. skin::sectionTitle (g, r.withHeight (16.0f * s).translated (0.0f, 1.0f * s), caps (tr (item.label)), accent, juce::jmax (8.0f, 10.0f * s));
  769. break;
  770. }
  771. case Item::label:
  772. if (hasStyle (item, plugui::bigCaption) && item.label != nullptr) // round tp172d (slice 8): a hardware strip's big
  773. { // caption, or (big) the model name plate
  774. const auto heavy = hasStyle (item, plugui::big);
  775. auto f = juce::Font (font (r.getHeight() * (heavy ? 0.92f : 0.62f), heavy));
  776. if (heavy)
  777. {
  778. f.setHorizontalScale (0.82f); // a condensed, stencil-like plate
  779. f.setExtraKerningFactor (0.04f);
  780. g.setFont (f);
  781. g.setColour (juce::Colours::white.withAlpha (0.35f)); // the engraving's lit lower edge
  782. g.drawText (caps (tr (item.label)), r.translated (0.0f, 1.0f * s), juce::Justification::centred, false);
  783. g.setColour (juce::Colour (0xff2c2d2f).withAlpha (fx.enabled ? 1.0f : 0.6f));
  784. g.drawText (caps (tr (item.label)), r, juce::Justification::centred, false);
  785. break;
  786. }
  787. g.setColour (skin::captionColour().withAlpha (fx.enabled ? 0.92f : 0.5f));
  788. ui::drawFittingText (g, caps (tr (item.label)), r, juce::Justification::centredRight, f, 7.0f);
  789. break;
  790. }
  791. if (hasStyle (item, plugui::wordmark) && item.label != nullptr) // round tp172d: a wide-spaced title in two tones
  792. {
  793. const auto text = juce::String (item.label);
  794. const auto first = text.upToFirstOccurrenceOf ("|", false, false), second = text.fromFirstOccurrenceOf ("|", false, false);
  795. auto f = juce::Font (font (r.getHeight() * 0.78f, false));
  796. f.setExtraKerningFactor (0.55f);
  797. const auto gap = r.getHeight() * 0.35f;
  798. const auto w1 = juce::GlyphArrangement::getStringWidth (f, first), w2 = juce::GlyphArrangement::getStringWidth (f, second);
  799. auto x = r.getCentreX() - (w1 + gap + w2) * 0.5f;
  800. g.setFont (f);
  801. g.setColour (skin::captionColour().withAlpha (0.42f));
  802. g.drawText (first, juce::Rectangle<float> (x, r.getY(), w1 + 4.0f, r.getHeight()), juce::Justification::centredLeft, false);
  803. g.setColour (skin::captionColour());
  804. g.drawText (second, juce::Rectangle<float> (x + w1 + gap, r.getY(), w2 + 4.0f, r.getHeight()), juce::Justification::centredLeft, false);
  805. break;
  806. }
  807. if (hasStyle (item, plugui::dim) && ! hasStyle (item, plugui::boxed) && item.h > 30.0f && item.label != nullptr)
  808. {
  809. // the plugin's name, big and readable (FL's logos are not reproduced; round 168q2)
  810. g.setColour (skin::captionScale() > 1.0f ? skin::captionColour() : colour::textSecondary); // (tp172d: a themed panel's type)
  811. if (skin::titleRules()) // round tp172d (look slice): the name centred between two rules (a hardware title bar)
  812. {
  813. juce::Font f (font (r.getHeight() * 0.62f, true));
  814. f.setExtraKerningFactor (0.12f);
  815. const auto tw = juce::jmin (r.getWidth() * 0.7f, juce::GlyphArrangement::getStringWidth (f, item.label));
  816. g.setFont (f);
  817. g.drawText (item.label, r, juce::Justification::centred, false);
  818. const auto gap = 8.0f * s, y = r.getCentreY() - 1.0f * s;
  819. g.fillRect (juce::Rectangle<float> (r.getX(), y, juce::jmax (0.0f, (r.getWidth() - tw) * 0.5f - gap), 2.0f * s));
  820. g.fillRect (juce::Rectangle<float> (r.getCentreX() + tw * 0.5f + gap, y, juce::jmax (0.0f, (r.getWidth() - tw) * 0.5f - gap), 2.0f * s));
  821. break;
  822. }
  823. ui::drawFittingText (g, item.label, r, hasStyle (item, plugui::alignLeft) ? juce::Justification::centredLeft : juce::Justification::centredRight,
  824. font (r.getHeight() * 0.62f, true), r.getHeight() * 0.25f, 0.0f, 0.8f); // (smaller, never "Wav...")
  825. break;
  826. }
  827. if (hasStyle (item, plugui::boxed))
  828. skin::section (g, r, radius::sm * s, true);
  829. caption (g, item, r, hasStyle (item, plugui::captionLeft | plugui::alignLeft) ? juce::Justification::centredLeft : juce::Justification::centred);
  830. break;
  831. case Item::value:
  832. if (hasStyle (item, plugui::boxed) && skin::ledReadouts()) // round tp172d: a red LED read-out
  833. {
  834. ledReadout (g, r, valueText (param, value), s, fx.enabled);
  835. break;
  836. }
  837. if (hasStyle (item, plugui::boxed)) // a read-out plate (FL's value boxes)
  838. skin::valuePlate (g, r, radius::sm * s);
  839. g.setColour (hot ? accent : (fx.enabled ? (skin::captionScale() > 1.0f ? skin::valueColour (false) : colour::textPrimary) : colour::textDisabled));
  840. g.setFont (hasStyle (item, plugui::big) ? font (juce::jmax (12.0f, 19.0f * s)) // round tp172b4: a big read-out (LuxeVerb's Space time)
  841. : font (juce::jmax (8.0f, 11.0f * s * juce::jmin (1.25f, skin::captionScale())), skin::captionScale() > 1.0f));
  842. g.drawFittedText (valueText (param, value), r.toNearestInt(),
  843. hasStyle (item, plugui::alignLeft) ? juce::Justification::centredLeft : juce::Justification::centred, 1, 0.7f);
  844. break;
  845. case Item::knob:
  846. {
  847. const auto circle = knobCircle (item);
  848. skin::KnobLook look;
  849. look.value = value;
  850. look.bipolar = hasStyle (item, plugui::bipolar);
  851. look.accent = item.colour >= 0 ? peqview::bandColour (item.colour) : accent;
  852. look.hover = glow;
  853. look.active = index == dragItem;
  854. look.enabled = fx.enabled;
  855. look.capTint = skin::capTintFor (item.param);
  856. skin::knob (g, circle, look);
  857. auto below = r.withTop (circle.getBottom() + 1.0f * s);
  858. if (hasStyle (item, plugui::valueAbove))
  859. {
  860. const auto box = r.withHeight (13.0f * s).reduced (juce::jmax (0.0f, (r.getWidth() - 40.0f * s) * 0.5f), 0.0f);
  861. skin::valuePlate (g, box, radius::sm);
  862. g.setColour (hot ? colour::textPrimary : colour::textSecondary);
  863. g.setFont (font (juce::jmax (8.0f, 9.0f * s)));
  864. g.drawFittedText (valueText (param, value), box.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  865. }
  866. if (hasStyle (item, plugui::captionAbove))
  867. {
  868. caption (g, item, r.withHeight (13.0f * s).expanded (10.0f * s, 0.0f));
  869. if (! hasStyle (item, plugui::showValue)) // round tp172d: the value only while dragged (its tip), as PanMan does
  870. break;
  871. g.setColour (hot ? look.accent.brighter (0.3f) : skin::valueColour (false));
  872. g.setFont (font (juce::jmax (8.0f, 10.5f * s * skin::captionScale()), skin::captionScale() > 1.0f));
  873. g.drawFittedText (valueText (param, value), below.withHeight (13.0f * s * skin::captionScale()).expanded (10.0f * s, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.7f);
  874. }
  875. else if (hasStyle (item, plugui::hoverValue)) // round tp172b5: the caption, the value under it on hover / drag
  876. {
  877. caption (g, item, below.withHeight (12.0f * s));
  878. if (hot || index == dragItem)
  879. {
  880. g.setColour (hot ? look.accent.brighter (0.3f) : skin::valueColour (true));
  881. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  882. g.drawFittedText (valueText (param, value), below.withTrimmedTop (12.0f * s).withHeight (13.0f * s).expanded (12.0f * s, 0.0f).toNearestInt(),
  883. juce::Justification::centred, 1, 0.7f);
  884. }
  885. }
  886. else if (! hasStyle (item, plugui::noCaption))
  887. {
  888. caption (g, item, below.withHeight (12.0f * s));
  889. if (hasStyle (item, plugui::showValue))
  890. {
  891. g.setColour (hot ? look.accent.brighter (0.3f) : skin::valueColour (false));
  892. g.setFont (font (juce::jmax (8.0f, 10.5f * s * skin::captionScale()), skin::captionScale() > 1.0f));
  893. g.drawFittedText (valueText (param, value), below.withTrimmedTop (12.0f * s).withHeight (13.0f * s * skin::captionScale()).toNearestInt(),
  894. juce::Justification::centred, 1, 0.7f);
  895. }
  896. }
  897. break;
  898. }
  899. case Item::hslider:
  900. case Item::vslider:
  901. {
  902. const auto vertical = item.type == Item::vslider;
  903. auto area = r;
  904. if (item.label != nullptr && ! hasStyle (item, plugui::noCaption))
  905. {
  906. if (hasStyle (item, plugui::captionLeft))
  907. caption (g, item, area.removeFromLeft (area.getWidth() * 0.4f), juce::Justification::centredLeft);
  908. else if (vertical)
  909. caption (g, item, area.removeFromBottom (13.0f * s).expanded (18.0f * s, 0.0f));
  910. else
  911. caption (g, item, area.removeFromBottom (12.0f * s));
  912. }
  913. const auto thick = juce::jmax (3.0f, 4.0f * s);
  914. const auto trackRect = vertical ? area.withSizeKeepingCentre (thick, area.getHeight() - 10.0f * s)
  915. : area.withSizeKeepingCentre (area.getWidth() - 8.0f * s, thick);
  916. skin::slider (g, trackRect, value, vertical, hasStyle (item, plugui::bipolar), item.colour >= 0 ? peqview::bandColour (item.colour) : accent,
  917. hot, fx.enabled, vertical ? juce::jmin (area.getWidth(), 20.0f * s) : juce::jmin (area.getHeight(), 16.0f * s), 9.0f * s);
  918. break;
  919. }
  920. case Item::radio:
  921. {
  922. const auto labels = plugui::optionLabels (item);
  923. const auto chosen = plugui::optionAt (item, value);
  924. const auto texts = optionTexts (item);
  925. if (item.columns > 0) // a grid of named cells (Gross Beat's slots)
  926. {
  927. const auto cellAccent = item.colour >= 0 ? colour::info : accent;
  928. g.setFont (font (juce::jmax (8.0f, 10.0f * s)));
  929. for (int o = 0; o < (int) texts.size(); ++o)
  930. {
  931. const auto cell = gridCell (item, o, (int) texts.size()).reduced (0.5f);
  932. g.setColour (o == chosen ? cellAccent.withAlpha (0.22f) : ((o / item.columns) % 2 == 0 ? colour::bg0 : colour::bg1));
  933. g.fillRect (cell);
  934. if (o == chosen)
  935. {
  936. g.setColour (fx.enabled ? cellAccent : colour::textSecondary);
  937. g.drawRect (cell, 1.0f);
  938. }
  939. g.setColour (o == chosen ? colour::textPrimary : colour::textSecondary);
  940. if (! drawWaveGlyph (g, cell.reduced (cell.getWidth() * 0.25f, cell.getHeight() * 0.28f), juce::String::fromUTF8 (labels[(std::size_t) o].c_str())))
  941. g.drawFittedText (texts[(std::size_t) o], cell.reduced (2.0f, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  942. }
  943. break;
  944. }
  945. const auto rowH = r.getHeight() / (float) juce::jmax (1, (int) labels.size());
  946. if (skin::hwKeys()) // round tp172d: a column of square keys, each with its caption (the originals' mode keys)
  947. {
  948. for (int o = 0; o < (int) labels.size(); ++o)
  949. {
  950. const auto row = juce::Rectangle<float> (r.getX(), r.getY() + rowH * (float) o, r.getWidth(), rowH);
  951. const auto k = juce::jmin (rowH * 0.7f, 24.0f * s);
  952. skin::hwKey (g, juce::Rectangle<float> (k, k).withCentre ({ row.getX() + k * 0.5f + 2.0f * s, row.getCentreY() }), o == chosen && fx.enabled, hot);
  953. g.setColour (skin::captionColour());
  954. ui::drawFittingText (g, caps (texts[(std::size_t) o]), row.withTrimmedLeft (k + 10.0f * s), juce::Justification::centredLeft,
  955. font (juce::jmax (8.0f, 11.0f * s * skin::captionScale()), true), 7.0f);
  956. }
  957. break;
  958. }
  959. for (int o = 0; o < (int) labels.size(); ++o)
  960. {
  961. const auto row = juce::Rectangle<float> (r.getX(), r.getY() + rowH * (float) o, r.getWidth(), rowH);
  962. const auto dot = juce::Rectangle<float> (7.0f * s, 7.0f * s).withCentre ({ row.getX() + 5.0f * s, row.getCentreY() });
  963. if (o == chosen && fx.enabled)
  964. {
  965. g.setColour (accent.withAlpha (0.3f));
  966. g.fillEllipse (dot.expanded (2.5f * s));
  967. }
  968. g.setColour (o == chosen ? (fx.enabled ? accent : colour::textSecondary) : juce::Colour (0xff0b0c0f));
  969. g.fillEllipse (dot);
  970. if (o != chosen)
  971. {
  972. g.setColour (colour::borderStrong);
  973. g.drawEllipse (dot, 1.0f);
  974. }
  975. g.setColour (o == chosen ? colour::textPrimary : (hot ? colour::textSecondary : colour::textDisabled));
  976. g.setFont (font (juce::jmax (8.0f, 9.5f * s)));
  977. g.drawFittedText (texts[(std::size_t) o], row.withTrimmedLeft (12.0f * s).toNearestInt(),
  978. juce::Justification::centredLeft, 1, 0.7f);
  979. }
  980. break;
  981. }
  982. case Item::tabs:
  983. {
  984. const auto labels = plugui::optionLabels (item);
  985. const auto texts = optionTexts (item);
  986. const auto chosen = hasStyle (item, plugui::pageTabs) ? (item.steps > 0 ? (page / item.steps) % juce::jmax (1, (int) labels.size()) : page)
  987. : plugui::optionAt (item, value);
  988. const auto vertical = isVertical (item);
  989. const auto count = (float) juce::jmax (1, (int) labels.size());
  990. const auto w = vertical ? r.getWidth() : r.getWidth() / count;
  991. const auto h = vertical ? r.getHeight() / count : r.getHeight();
  992. if (hasStyle (item, plugui::batToggle) && texts.size() >= 2) // round tp172d (slice 8): COMPRESS / LIMIT — a bat toggle,
  993. { // option 0 above (lever up), option 1 under; the chosen word lit
  994. const auto line = juce::jmin (13.0f * s, r.getHeight() * 0.2f);
  995. const auto f = font (juce::jmax (8.0f, 10.5f * s * skin::captionScale()), true);
  996. for (int o = 0; o < 2; ++o)
  997. {
  998. const auto band = o == 0 ? r.withHeight (line) : r.withTop (r.getBottom() - line);
  999. g.setColour (o == chosen && fx.enabled ? accent : skin::captionColour());
  1000. ui::drawFittingText (g, caps (texts[(std::size_t) o]), band.expanded (14.0f * s, 0.0f), juce::Justification::centred, f, 7.0f);
  1001. }
  1002. const auto body = r.withTrimmedTop (line).withTrimmedBottom (line);
  1003. skin::batToggle (g, juce::Rectangle<float> (body.getHeight() * 0.36f, body.getHeight() * 0.36f).withCentre (body.getCentre()), chosen == 0, hot, fx.enabled);
  1004. break;
  1005. }
  1006. if (hasStyle (item, plugui::rotarySelector) && ! texts.empty()) // round tp172d (slice 8): VU DISPLAY — a black pointer
  1007. { // knob, its options printed round it, the chosen one lit
  1008. const auto line = 12.0f * s;
  1009. const auto knobArea = selectorKnobArea (item);
  1010. const auto f = font (juce::jmax (8.0f, 10.0f * s * skin::captionScale()), true);
  1011. const auto n = (int) texts.size();
  1012. for (int o = 0; o < n; ++o)
  1013. {
  1014. const auto a = selectorAngle (o, n);
  1015. const auto q = knobArea.getCentre() + juce::Point<float> { std::sin (a), -std::cos (a) } * (knobArea.getWidth() * 0.5f + 9.0f * s);
  1016. auto band = juce::Rectangle<float> (r.getWidth() * 0.5f, line).withCentre (q);
  1017. auto j = juce::Justification::centred;
  1018. if (std::sin (a) < -0.3f) { band = band.withRightX (q.x + 8.0f * s); j = juce::Justification::centredRight; }
  1019. if (std::sin (a) > 0.3f) { band = band.withX (q.x - 8.0f * s); j = juce::Justification::centredLeft; }
  1020. band = band.translated (0.0f, std::abs (std::sin (a)) > 0.3f ? -line * 0.9f : -2.0f * s);
  1021. g.setColour (o == chosen && fx.enabled ? accent : skin::captionColour());
  1022. ui::drawFittingText (g, caps (texts[(std::size_t) o]), band, j, f, 7.0f);
  1023. }
  1024. skin::selectorKnob (g, knobArea, selectorAngle (juce::jmax (0, chosen), n), hot, fx.enabled);
  1025. break;
  1026. }
  1027. if (skin::goldKeys() && ! vertical) // round tp172d (slice 8): the opto leveler's strip — gold keys side by side
  1028. {
  1029. for (int o = 0; o < (int) labels.size(); ++o)
  1030. {
  1031. const auto cell = juce::Rectangle<float> (r.getX() + w * (float) o, r.getY(), w, h).reduced (1.5f * s, 0.0f);
  1032. const auto lit = o == chosen && fx.enabled;
  1033. skin::goldKey (g, cell, lit, hot);
  1034. g.setColour (juce::Colour (0xff23211a));
  1035. g.setFont (font (juce::jmax (7.0f, juce::jmin (h * 0.58f, 11.0f * s)), false));
  1036. g.drawFittedText (texts[(std::size_t) o].toUpperCase() == texts[(std::size_t) o] || texts[(std::size_t) o].containsAnyOf ("0123456789") ? texts[(std::size_t) o] : caps (texts[(std::size_t) o]),
  1037. cell.toNearestInt(), juce::Justification::centred, 1, 0.7f); // ("50Hz" as printed, "OFF" in caps)
  1038. }
  1039. break;
  1040. }
  1041. if (skin::hwKeys() && ! vertical) // round tp172d: a row of square keys joined by a line (or wide keys for words)
  1042. {
  1043. bool letters = true; // A / E / N / T / P: square keys; words: wide keys
  1044. for (const auto& t : texts) letters = letters && t.length() <= 2;
  1045. // round tp172d (look slice): PanMan's direction keys — "<", "< >", ">" draw as vector arrows on
  1046. // square amber-lit keys, side by side (no joining line); a short word among them ("8") shares the style
  1047. bool arrows = false;
  1048. for (const auto& t : labels) arrows = arrows || t == "< >";
  1049. if (arrows)
  1050. {
  1051. const auto amber = juce::Colour (0xffe8a632);
  1052. const auto side = juce::jmin (w - 6.0f * s, h);
  1053. for (int o = 0; o < (int) labels.size(); ++o)
  1054. {
  1055. const auto cell = juce::Rectangle<float> (side, side).withCentre ({ r.getX() + w * ((float) o + 0.5f), r.getCentreY() });
  1056. const auto lit = o == chosen && fx.enabled;
  1057. skin::hwKey (g, cell, lit, hot, amber);
  1058. const juce::String raw (labels[(std::size_t) o]);
  1059. const auto ink = lit ? juce::Colour (0xff2a1a04) : juce::Colours::white.withAlpha (0.9f);
  1060. const auto tri = side * 0.22f;
  1061. auto arrow = [&] (juce::Point<float> c, bool left)
  1062. {
  1063. juce::Path p;
  1064. const auto d = left ? -1.0f : 1.0f;
  1065. p.addTriangle (c.x + d * tri, c.y, c.x - d * tri * 0.75f, c.y - tri, c.x - d * tri * 0.75f, c.y + tri);
  1066. g.fillPath (p);
  1067. };
  1068. g.setColour (ink);
  1069. const auto c = cell.getCentre();
  1070. if (raw == "<")
  1071. arrow (c, true);
  1072. else if (raw == ">")
  1073. arrow (c, false);
  1074. else if (raw == "< >")
  1075. {
  1076. arrow (c.translated (-tri * 0.95f, 0.0f), true);
  1077. arrow (c.translated (tri * 0.95f, 0.0f), false);
  1078. }
  1079. else
  1080. {
  1081. g.setFont (font (juce::jmax (8.0f, side * 0.42f), true));
  1082. g.drawText (caps (texts[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, false);
  1083. }
  1084. }
  1085. break;
  1086. }
  1087. const auto key = juce::jmin (w * 0.62f, h);
  1088. if (letters)
  1089. {
  1090. g.setColour (skin::captionColour().withAlpha (0.8f));
  1091. g.fillRect (juce::Rectangle<float> (r.getX() + w * 0.5f, r.getCentreY() - 1.0f * s, w * (count - 1.0f), 2.0f * s));
  1092. }
  1093. for (int o = 0; o < (int) labels.size(); ++o)
  1094. {
  1095. const auto centre = juce::Point<float> (r.getX() + w * ((float) o + 0.5f), r.getCentreY());
  1096. const auto cell = letters ? juce::Rectangle<float> (key, key).withCentre (centre)
  1097. : juce::Rectangle<float> (w - 4.0f * s, h).withCentre (centre);
  1098. skin::hwKey (g, cell, o == chosen && fx.enabled, hot);
  1099. if (hasStyle (item, plugui::compactKeys)) // round tp172d (slice 8): LYNX's extras on a hardware face — small,
  1100. { // muted until hovered, the chosen key lit
  1101. if (o != chosen && ! hot)
  1102. {
  1103. g.setColour (juce::Colour (0xffc8cbce).withAlpha (0.55f)); // (a veil of the light faceplate it sits on)
  1104. g.fillRoundedRectangle (cell, 2.0f * s);
  1105. }
  1106. g.setColour (o == chosen && fx.enabled ? juce::Colours::white : juce::Colours::white.withAlpha (hot ? 0.95f : 0.75f));
  1107. g.setFont (font (juce::jmax (7.0f, juce::jmin (h * 0.58f, 8.5f * s)), true));
  1108. g.drawFittedText (caps (texts[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1109. continue;
  1110. }
  1111. g.setColour (juce::Colours::black.withAlpha (0.5f));
  1112. g.setFont (font (letters ? juce::jmax (8.0f, key * 0.46f) : juce::jmax (7.0f, juce::jmin (h * 0.5f, 10.0f * s)), true));
  1113. g.drawText (caps (texts[(std::size_t) o]), cell.translated (0.0f, 1.0f).toNearestInt(), juce::Justification::centred, false);
  1114. g.setColour (juce::Colours::white);
  1115. g.drawText (caps (texts[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, false);
  1116. }
  1117. break;
  1118. }
  1119. skin::valuePlate (g, r, radius::md);
  1120. for (int o = 0; o < (int) labels.size(); ++o)
  1121. {
  1122. const auto cell = (vertical ? juce::Rectangle<float> (r.getX(), r.getY() + h * (float) o, w, h)
  1123. : juce::Rectangle<float> (r.getX() + w * (float) o, r.getY(), w, h)).reduced (1.0f);
  1124. if (vertical) // a band selector (Maximus): the band's colour on the left edge
  1125. {
  1126. g.setColour (peqview::bandColour (o).withAlpha (o == chosen ? 1.0f : 0.45f));
  1127. g.fillRect (cell.withWidth (juce::jmax (2.0f, 3.0f * s)));
  1128. }
  1129. if (o == chosen)
  1130. skin::button (g, vertical ? cell.withTrimmedLeft (juce::jmax (2.0f, 3.0f * s)) : cell, true, false,
  1131. vertical ? peqview::bandColour (o) : (fx.enabled ? accent : colour::textSecondary), radius::sm);
  1132. g.setColour (o == chosen ? colour::textPrimary : colour::textSecondary);
  1133. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  1134. g.drawFittedText (caps (texts[(std::size_t) o]), cell.toNearestInt(),
  1135. juce::Justification::centred, 1, 0.7f);
  1136. }
  1137. break;
  1138. }
  1139. case Item::toggle:
  1140. {
  1141. const auto on = (value >= 0.5f) != hasStyle (item, plugui::inverted) && ! hasStyle (item, plugui::momentary);
  1142. if (hasStyle (item, plugui::batToggle)) // round tp172d (slice 8): AUTO MAKEUP — a bat toggle, the caption above
  1143. { // (lit while on, lever up), OFF under it (lit while off)
  1144. const auto f = font (juce::jmax (8.0f, 10.5f * s * skin::captionScale()), true);
  1145. const auto line = juce::jmin (13.0f * s, r.getHeight() * 0.16f);
  1146. const auto top = r.withHeight (line * 2.0f);
  1147. g.setColour (on && fx.enabled ? accent : skin::captionColour());
  1148. if (item.label != nullptr)
  1149. {
  1150. g.setFont (f);
  1151. g.drawFittedText (caps (tr (item.label)), top.expanded (14.0f * s, 0.0f).toNearestInt(), juce::Justification::centredBottom, 2, 0.8f);
  1152. }
  1153. g.setColour (! on && fx.enabled ? accent : skin::captionColour());
  1154. ui::drawFittingText (g, caps (tr ("Off")), r.withTop (r.getBottom() - line), juce::Justification::centred, f, 7.0f);
  1155. const auto body = r.withTrimmedTop (line * 2.0f).withTrimmedBottom (line);
  1156. skin::batToggle (g, juce::Rectangle<float> (body.getHeight() * 0.38f, body.getHeight() * 0.38f).withCentre (body.getCentre()), on, hot, fx.enabled);
  1157. break;
  1158. }
  1159. if (hasStyle (item, plugui::boxed) || hasStyle (item, plugui::momentary)) // a small lit button with its letter (FL's T / L buttons)
  1160. {
  1161. if (on)
  1162. {
  1163. const auto c = fx.enabled ? accent : colour::textSecondary;
  1164. g.setColour (c.withAlpha (0.3f));
  1165. g.fillRoundedRectangle (r.expanded (1.5f), radius::sm + 1.5f);
  1166. g.setGradientFill (juce::ColourGradient (c.brighter (0.2f), 0.0f, r.getY(), c.darker (0.15f), 0.0f, r.getBottom(), false));
  1167. g.fillRoundedRectangle (r, radius::sm);
  1168. }
  1169. else
  1170. skin::button (g, r, false, hot, accent, radius::sm);
  1171. g.setColour (on ? colour::onAccent : colour::textSecondary);
  1172. if (item.label != nullptr)
  1173. ui::drawFittingText (g, caps (tr (item.label)), r, juce::Justification::centred, font (juce::jmax (8.0f, r.getHeight() * 0.8f), true), 6.5f);
  1174. break;
  1175. }
  1176. if (skin::hwKeys() && hasStyle (item, plugui::captionAbove)) // round tp172d (look slice): Little AlterBoy's LINK —
  1177. { // a small square key joined to its neighbours by a line, the caption under it
  1178. const auto k = juce::jmin (r.getHeight() * 0.5f, 22.0f * s);
  1179. const auto key = juce::Rectangle<float> (k, k).withCentre ({ r.getCentreX(), r.getY() + k * 0.5f + 2.0f * s });
  1180. g.setColour (juce::Colours::black.withAlpha (0.75f));
  1181. g.fillRect (juce::Rectangle<float> (r.getX(), key.getCentreY() - 1.0f * s, r.getWidth(), 2.0f * s));
  1182. skin::hwKey (g, key, on && fx.enabled, hot);
  1183. g.setColour (skin::captionColour().getAlpha() > 0 ? skin::captionColour() : colour::textPrimary);
  1184. if (item.label != nullptr)
  1185. ui::drawFittingText (g, caps (tr (item.label)), r.withTop (key.getBottom() + 3.0f * s), juce::Justification::centredTop,
  1186. font (juce::jmax (8.0f, 10.0f * s * skin::captionScale()), true), 7.0f);
  1187. break;
  1188. }
  1189. if (skin::hwKeys()) // round tp172d: a square key (lit when on), its caption beside it
  1190. {
  1191. const auto k = juce::jmin (r.getHeight(), 26.0f * s);
  1192. const auto key = juce::Rectangle<float> (k * 1.3f, k).withCentre ({ r.getX() + k * 0.65f, r.getCentreY() });
  1193. skin::hwKey (g, key, on && fx.enabled, hot);
  1194. g.setColour (on ? juce::Colours::white : juce::Colours::white.withAlpha (0.7f));
  1195. g.setFont (font (juce::jmax (7.0f, k * 0.4f), true));
  1196. g.drawFittedText (on ? tr ("ON") : tr ("OFF"), key.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1197. g.setColour (skin::captionColour().getAlpha() > 0 ? skin::captionColour() : colour::textPrimary);
  1198. if (item.label != nullptr)
  1199. ui::drawFittingText (g, caps (tr (item.label)), r.withTrimmedLeft (k * 1.3f + 6.0f * s), juce::Justification::centredLeft,
  1200. font (juce::jmax (8.0f, 10.5f * s * skin::captionScale()), true), 7.0f);
  1201. break;
  1202. }
  1203. const auto box = juce::Rectangle<float> (16.0f * s, 9.0f * s).withCentre ({ r.getX() + 9.0f * s, r.getCentreY() });
  1204. skin::switchPill (g, box, on, accent, fx.enabled);
  1205. auto text = r.withTrimmedLeft (21.0f * s);
  1206. const auto offLabel = skin::offLabelColour(); // round tp172c: a theme's own (readable on its panels)
  1207. g.setColour (on ? (offLabel.isTransparent() || offLabel.getPerceivedBrightness() > 0.5f ? colour::textPrimary
  1208. : offLabel.darker (0.6f)) // a light panel: lit = darker
  1209. : (! offLabel.isTransparent() ? (hot ? offLabel.brighter (0.3f) : offLabel)
  1210. : (hot ? colour::textSecondary : colour::textDisabled)));
  1211. if (item.label != nullptr)
  1212. ui::drawFittingText (g, caps (tr (item.label)), text, juce::Justification::centredLeft, font (juce::jmax (8.0f, 9.5f * s), true), 7.0f);
  1213. break;
  1214. }
  1215. case Item::stepper:
  1216. {
  1217. auto box = r;
  1218. if (item.label != nullptr && ! hasStyle (item, plugui::noCaption))
  1219. caption (g, item, box.removeFromTop (12.0f * s));
  1220. skin::valuePlate (g, box, radius::sm);
  1221. if (hot)
  1222. {
  1223. g.setColour (accent.withAlpha (0.5f));
  1224. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  1225. }
  1226. auto arrows = box.removeFromRight (juce::jmin (12.0f * s, box.getWidth() * 0.4f));
  1227. g.setColour (colour::textSecondary);
  1228. drawSmallArrow (g, arrows.removeFromTop (arrows.getHeight() * 0.5f), true);
  1229. drawSmallArrow (g, arrows, false);
  1230. g.setColour (colour::textPrimary);
  1231. g.setFont (font (juce::jmax (8.0f, 11.0f * s), true));
  1232. // (Love Philter's type box: FL's short names; the hint and the list keep the long ones)
  1233. g.drawFittedText (kind == EffectKind::lovePhilter && juce::String (item.param).endsWith (" type")
  1234. ? juce::String (philter::typeShortName (juce::roundToInt (value * 11.0f)))
  1235. : valueText (param, value),
  1236. box.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1237. break;
  1238. }
  1239. case Item::display:
  1240. paintDisplay (g, item, r, fx);
  1241. break;
  1242. case Item::menu:
  1243. {
  1244. if (kind == EffectKind::flTransporter && param == transporter::sendParam) // the loops' send (round 167n)
  1245. {
  1246. const auto target = flbasic::sendTrack (value);
  1247. g.setColour ((target > 0 ? accent : colour::accentMuted).withAlpha (hot ? 1.0f : 0.85f));
  1248. g.fillRoundedRectangle (r, radius::sm * s);
  1249. g.setColour (target > 0 ? colour::onAccent : colour::textSecondary);
  1250. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  1251. g.drawFittedText (target > 0 ? tr ("Send to {0}", { juce::String (target) + " " + insertName (target) })
  1252. : tr ("Send to") + juce::String (juce::CharPointer_UTF8 (" \xe2\x80\xa6")),
  1253. r.reduced (4.0f * s, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1254. break;
  1255. }
  1256. if (kind == EffectKind::fruitySend) // the destination insert (FL's tinted box; "…" = none)
  1257. {
  1258. const auto target = flbasic::sendTrack (value);
  1259. g.setColour ((target > 0 ? accent : colour::accentMuted).withAlpha (hot ? 1.0f : 0.85f));
  1260. g.fillRoundedRectangle (r, radius::sm * s);
  1261. g.setColour (target > 0 ? colour::onAccent : colour::textSecondary);
  1262. g.setFont (font (juce::jmax (8.0f, 9.0f * s), true));
  1263. g.drawFittedText (target > 0 ? insertName (target) : juce::String (juce::CharPointer_UTF8 ("\xe2\x80\xa6")),
  1264. r.reduced (2.0f * s, 0.0f).toNearestInt(), juce::Justification::centred, 2, 0.6f);
  1265. break;
  1266. }
  1267. const auto chosen = plugui::optionAt (item, value);
  1268. if (hasStyle (item, plugui::plainMenu)) // round tp172d: the value as plain text (a click opens the menu)
  1269. {
  1270. const auto labels = plugui::optionLabels (item);
  1271. auto t = chosen < (int) labels.size() ? tr (labels[(std::size_t) chosen]) : valueText (param, value);
  1272. if (skin::lowerCaptions())
  1273. t = t.toLowerCase();
  1274. g.setColour (skin::captionColour().withAlpha (hot ? 0.85f : 0.55f));
  1275. g.setFont (font (juce::jmax (9.0f, r.getHeight() * 0.62f), false));
  1276. g.drawFittedText (t, r.toNearestInt(), juce::Justification::centredLeft, 1, 0.7f);
  1277. if (hot)
  1278. g.fillRect (juce::Rectangle<float> (r.getX(), r.getBottom() - 2.0f * s, juce::jmin (r.getWidth(), juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), t)), 1.0f * s));
  1279. break;
  1280. }
  1281. if (skin::ledReadouts() && hasStepArrows (item)) // round tp172d: EchoBoy's style display — a red LED window, step arrows left
  1282. {
  1283. const auto labels = plugui::optionLabels (item);
  1284. const auto arrows = r.withWidth (14.0f * s);
  1285. for (const auto up : { true, false })
  1286. {
  1287. const auto half = up ? arrows.withTrimmedBottom (arrows.getHeight() * 0.5f) : arrows.withTrimmedTop (arrows.getHeight() * 0.5f);
  1288. skin::hwKey (g, half.reduced (1.0f * s), false, half.contains (mouseAt));
  1289. g.setColour (juce::Colours::white.withAlpha (0.85f));
  1290. drawSmallArrow (g, half.reduced (3.0f * s), up);
  1291. }
  1292. ledReadout (g, r.withTrimmedLeft (16.0f * s), chosen < (int) labels.size() ? tr (juce::String::fromUTF8 (labels[(std::size_t) chosen].c_str())) : valueText (param, value),
  1293. s, fx.enabled, juce::Justification::centredLeft);
  1294. break;
  1295. }
  1296. const auto off = chosen == 0 && kind == EffectKind::parametricEq;
  1297. if (item.colour >= 0)
  1298. {
  1299. const auto c = peqview::bandColour (item.colour);
  1300. g.setColour ((fx.enabled && ! off ? c : c.withSaturation (0.0f).darker (0.6f)).withAlpha (hot ? 1.0f : 0.85f));
  1301. g.fillRoundedRectangle (r, radius::sm * s);
  1302. }
  1303. else
  1304. skin::selector (g, r, hot, radius::md * s);
  1305. g.setColour (colour::bg0);
  1306. if (kind == EffectKind::parametricEq)
  1307. drawBandShape (g, r.reduced (2.0f * s, 4.0f * s), chosen);
  1308. else
  1309. {
  1310. // round 114: readable mode names (light on the control, bigger), arrows to step on wide menus
  1311. const auto labels = plugui::optionLabels (item);
  1312. auto textArea = r;
  1313. if (hasStepArrows (item))
  1314. {
  1315. const auto edge = 18.0f * s;
  1316. for (const auto left : { true, false })
  1317. {
  1318. const auto a = left ? r.withWidth (edge) : r.withLeft (r.getRight() - edge);
  1319. const auto c0 = a.getCentre();
  1320. juce::Path tri;
  1321. const auto h = 4.0f * s;
  1322. if (left) tri.addTriangle (c0.x + h * 0.7f, c0.y - h, c0.x + h * 0.7f, c0.y + h, c0.x - h * 0.7f, c0.y);
  1323. else tri.addTriangle (c0.x - h * 0.7f, c0.y - h, c0.x - h * 0.7f, c0.y + h, c0.x + h * 0.7f, c0.y);
  1324. g.setColour (a.contains (mouseAt) ? colour::textPrimary : colour::textSecondary);
  1325. g.fillPath (tri);
  1326. }
  1327. textArea = r.reduced (edge, 0.0f);
  1328. }
  1329. g.setColour (colour::textPrimary);
  1330. g.setFont (font (juce::jmax (9.0f, juce::jmin (12.0f * s, r.getHeight() * 0.55f)), true));
  1331. if (kind == EffectKind::lynxTune && param == lynxtune::scale && fx.params[lynxtune::moreScales] >= 0.25f)
  1332. g.drawFittedText (tr (fx.params[lynxtune::moreScales] >= 0.75f ? "Diminished" : "Whole tone"), textArea.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1333. else if (kind == EffectKind::hardwareInsert) // the device's channel names (round 164d)
  1334. g.drawFittedText (valueText (param, value), textArea.reduced (4.0f * s, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1335. else if (chosen < (int) labels.size())
  1336. g.drawFittedText (tr (juce::String::fromUTF8 (labels[(std::size_t) chosen].c_str())), textArea.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1337. }
  1338. break;
  1339. }
  1340. }
  1341. }
  1342. // round tp172d (slice 8): a rotary selector's knob (the lower part of its box, under the top option's word) and the
  1343. // angle of option k of n (spread over ±75 degrees round the top)
  1344. juce::Rectangle<float> selectorKnobArea (const LayoutItem& item) const
  1345. {
  1346. const auto r = rectOf (item);
  1347. const auto d = juce::jmin (r.getWidth() * 0.44f, r.getHeight() - 26.0f * scale());
  1348. return juce::Rectangle<float> (d, d).withCentre ({ r.getCentreX(), r.getBottom() - d * 0.5f - 2.0f * scale() });
  1349. }
  1350. static float selectorAngle (int k, int n)
  1351. {
  1352. if (n <= 1) return 0.0f;
  1353. const auto span = juce::degreesToRadians (150.0f);
  1354. return -span * 0.5f + span * (float) k / (float) (n - 1);
  1355. }
  1356. // round tp172d (look slice): a red LED read-out (EchoBoy's time, tempo and style displays): a black window, a faint
  1357. // ghost of unlit segments, the text in lit red
  1358. static void ledReadout (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& text, float s, bool enabled, juce::Justification j = juce::Justification::centred)
  1359. {
  1360. g.setColour (juce::Colour (0xff050505));
  1361. g.fillRoundedRectangle (r, 2.0f * s);
  1362. g.setColour (juce::Colour (0xff2a0a08));
  1363. g.fillRoundedRectangle (r.reduced (2.0f * s), 1.5f * s);
  1364. g.setColour (juce::Colours::black.withAlpha (0.8f));
  1365. g.drawRoundedRectangle (r.reduced (0.5f), 2.0f * s, 1.0f);
  1366. juce::Font f (juce::FontOptions (juce::Font::getDefaultMonospacedFontName(), juce::jmax (8.0f, r.getHeight() * 0.62f), juce::Font::bold));
  1367. g.setFont (f);
  1368. const auto area = r.reduced (5.0f * s, 0.0f).toNearestInt();
  1369. g.setColour (juce::Colour (0xffff3020).withAlpha (enabled ? 1.0f : 0.45f));
  1370. g.drawFittedText (text, area, j, 1, 0.6f);
  1371. }
  1372. // a small drawing of an EQ band's response (peak, shelves, cuts, band-pass, notch)
  1373. static void drawBandShape (juce::Graphics& g, juce::Rectangle<float> r, int type)
  1374. {
  1375. juce::Path p;
  1376. const auto x0 = r.getX(), x1 = r.getRight(), xm = r.getCentreX(), y0 = r.getY(), y1 = r.getBottom(), ym = r.getCentreY();
  1377. switch (type)
  1378. {
  1379. case 1: p.startNewSubPath (x0, ym); p.quadraticTo (xm, y0 - (y1 - y0) * 0.3f, x1, ym); break; // peak
  1380. case 2: p.startNewSubPath (x0, y0); p.lineTo (xm - 2, y0); p.lineTo (xm + 2, ym); p.lineTo (x1, ym); break; // low shelf
  1381. case 3: p.startNewSubPath (x0, ym); p.lineTo (xm - 2, ym); p.lineTo (xm + 2, y0); p.lineTo (x1, y0); break; // high shelf
  1382. case 4: p.startNewSubPath (x0 + 2, y1); p.quadraticTo (xm - 1, y0, x1, y0); break; // low cut
  1383. case 5: p.startNewSubPath (x0, y0); p.quadraticTo (xm + 1, y0, x1 - 2, y1); break; // high cut
  1384. case 6: p.startNewSubPath (x0, y1); p.quadraticTo (xm, y0 - (y1 - y0) * 0.6f, x1, y1); break; // band-pass
  1385. case 7: p.startNewSubPath (x0, y0); p.quadraticTo (xm, y1 + (y1 - y0) * 0.6f, x1, y0); break; // notch
  1386. default: p.startNewSubPath (x0, ym); p.lineTo (x1, ym); break; // off
  1387. }
  1388. g.strokePath (p, juce::PathStrokeType (1.4f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1389. }
  1390. // a small drawing of an LFO / oscillator wave named in English (false: not a wave name)
  1391. static bool drawWaveGlyph (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& name)
  1392. {
  1393. if (name != "Sine" && name != "Triangle" && name != "Square" && name != "Saw")
  1394. return false;
  1395. juce::Path p;
  1396. constexpr int n = 32;
  1397. for (int i = 0; i <= n; ++i)
  1398. {
  1399. const auto t = (float) i / (float) n;
  1400. const auto y = name == "Sine" ? std::sin (t * juce::MathConstants<float>::twoPi)
  1401. : name == "Triangle" ? (t < 0.25f ? 4.0f * t : (t < 0.75f ? 2.0f - 4.0f * t : 4.0f * t - 4.0f))
  1402. : name == "Square" ? (t < 0.5f ? 1.0f : -1.0f)
  1403. : 2.0f * t - 1.0f;
  1404. const juce::Point<float> pt { r.getX() + r.getWidth() * t, r.getCentreY() - r.getHeight() * 0.5f * y };
  1405. if (i == 0)
  1406. p.startNewSubPath (pt);
  1407. else
  1408. p.lineTo (pt);
  1409. }
  1410. g.strokePath (p, juce::PathStrokeType (1.5f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1411. return true;
  1412. }
  1413. static void drawSmallArrow (juce::Graphics& g, juce::Rectangle<float> r, bool up)
  1414. {
  1415. const auto c = r.getCentre();
  1416. const auto w = juce::jmin (r.getWidth(), r.getHeight() * 2.0f) * 0.32f;
  1417. juce::Path p;
  1418. if (up)
  1419. p.addTriangle (c.x - w, c.y + w * 0.5f, c.x + w, c.y + w * 0.5f, c.x, c.y - w * 0.5f);
  1420. else
  1421. p.addTriangle (c.x - w, c.y - w * 0.5f, c.x + w, c.y - w * 0.5f, c.x, c.y + w * 0.5f);
  1422. g.fillPath (p);
  1423. }
  1424. // --- displays (graphs drawn from the parameters; FL's live analysers are not reproduced) -------------
  1425. float param01 (const char* name) const { return valueOf (plugui::paramIndex (kind, name)); }
  1426. // LYNX Tune's live display: the read-out on the left (note, cents, Hz, target, correction meter), the last 8 s of
  1427. // sung (white) and corrected (accent) pitch on the right over the key's note lines
  1428. void paintPitchDisplay (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx, bool readout = true)
  1429. {
  1430. using namespace theme;
  1431. const auto s = scale();
  1432. static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  1433. auto noteText = [] (int n) { return juce::String (names[((n % 12) + 12) % 12]) + juce::String (n / 12 - 1); };
  1434. std::vector<PitchPoint> history = pitchHistory;
  1435. if (demoDisplays && history.empty()) // a sung phrase with vibrato and scoops, corrected toward the scale
  1436. for (std::size_t i = 0; i < pitchHistoryLength; ++i)
  1437. {
  1438. const auto t = (float) i / 30.0f;
  1439. const auto phrase = std::fmod (t, 2.7f);
  1440. const auto base = t < 2.7f ? 64.0f : t < 5.4f ? 67.0f : 69.0f;
  1441. const auto sung = phrase < 0.15f ? 0.0f : base - 0.6f * std::exp (-phrase * 5.0f) + 0.35f * std::sin (t * 20.0f) * juce::jmin (1.0f, phrase) + 0.18f;
  1442. const auto shift = sung > 0.0f ? (base - sung) * (1.0f - std::exp (-phrase * 12.0f)) : 0.0f;
  1443. history.push_back ({ sung, sung > 0.0f ? base : 0.0f, shift });
  1444. }
  1445. const auto last = history.empty() ? PitchPoint { 0.0f, 0.0f, 0.0f } : history.back();
  1446. [[maybe_unused]] const auto voiced = last.sung > 0.5f;
  1447. [[maybe_unused]] const auto ref = lynxtune::referenceHz (fx.params[(std::size_t) lynxtune::reference]);
  1448. if (readout)
  1449. {
  1450. // --- read-out
  1451. auto left = r.removeFromLeft (juce::jmin (176.0f * s, r.getWidth() * 0.34f)).reduced (8.0f * s, 6.0f * s);
  1452. const auto noteArea = left.removeFromTop (left.getHeight() * 0.42f);
  1453. g.setFont (font (juce::jmax (12.0f, 34.0f * s), true));
  1454. g.setColour (voiced ? colour::textPrimary : colour::textDisabled);
  1455. const auto nearest = (int) std::lround (last.sung);
  1456. g.drawText (voiced ? noteText (nearest) : juce::String ("--"), noteArea.withTrimmedRight (noteArea.getWidth() * 0.4f), juce::Justification::centredLeft);
  1457. g.setFont (font (juce::jmax (8.0f, 12.0f * s)));
  1458. g.setColour (colour::textSecondary);
  1459. if (voiced)
  1460. {
  1461. const auto cents = (int) std::lround ((last.sung - (float) nearest) * 100.0f);
  1462. const auto hzNow = ref * std::exp2 ((last.sung - 69.0f) / 12.0f);
  1463. const auto side = noteArea.withTrimmedLeft (noteArea.getWidth() * 0.6f);
  1464. g.drawText ((cents > 0 ? "+" : "") + juce::String (cents) + " c", side.withHeight (side.getHeight() * 0.5f), juce::Justification::bottomLeft);
  1465. g.drawText (juce::String (hzNow, 1) + " Hz", side.withTrimmedTop (side.getHeight() * 0.5f), juce::Justification::topLeft);
  1466. }
  1467. auto row = [&] (const juce::String& caption, const juce::String& value, juce::Colour c) {
  1468. auto line = left.removeFromTop (juce::jmax (12.0f, 18.0f * s));
  1469. g.setColour (colour::textDisabled);
  1470. g.setFont (font (juce::jmax (7.0f, 10.0f * s), true));
  1471. g.drawText (caption, line, juce::Justification::centredLeft);
  1472. g.setColour (c);
  1473. g.setFont (font (juce::jmax (8.0f, 12.0f * s), true));
  1474. g.drawText (value, line, juce::Justification::centredRight);
  1475. };
  1476. row (caps (tr ("Target")), voiced && last.target > 0.5f ? noteText ((int) std::lround (last.target)) : juce::String ("--"), accent);
  1477. const auto corrCents = (int) std::lround (last.shift * 100.0f);
  1478. row (caps (tr ("Correction")), voiced ? (corrCents > 0 ? "+" : "") + juce::String (corrCents) + " c" : juce::String ("--"), colour::textPrimary);
  1479. // the correction meter: ±100 cents from the centre
  1480. auto bar = left.removeFromTop (juce::jmax (6.0f, 9.0f * s)).reduced (0.0f, 1.0f);
  1481. skin::valuePlate (g, bar, radius::sm);
  1482. g.setColour (colour::gridBar);
  1483. g.drawVerticalLine ((int) bar.getCentreX(), bar.getY() - 2.0f, bar.getBottom() + 2.0f);
  1484. if (voiced)
  1485. {
  1486. const auto amount = juce::jlimit (-1.0f, 1.0f, last.shift);
  1487. const auto x0 = bar.getCentreX(), x1 = bar.getCentreX() + bar.getWidth() * 0.5f * amount;
  1488. g.setColour ((fx.enabled ? accent : colour::textDisabled).withAlpha (0.9f));
  1489. g.fillRoundedRectangle (juce::Rectangle<float> (juce::jmin (x0, x1), bar.getY(), std::abs (x1 - x0) + 1.0f, bar.getHeight()), radius::sm);
  1490. }
  1491. }
  1492. // --- graph
  1493. auto graph = r.reduced (6.0f * s, 6.0f * s);
  1494. skin::well (g, graph, radius::md * s, fx.enabled ? accent : juce::Colours::transparentBlack);
  1495. // vertical range: ±7 semitones around the recent pitch (follows the voice)
  1496. float centre = 0.0f;
  1497. int count = 0;
  1498. for (auto i = history.size() > 60 ? history.size() - 60 : 0; i < history.size(); ++i)
  1499. if (history[i].sung > 0.5f) { centre += history[i].sung; ++count; }
  1500. centre = count > 0 ? std::round (centre / (float) count) : (displayCentre > 0.0f ? displayCentre : 60.0f);
  1501. displayCentre = displayCentre <= 0.0f ? centre : displayCentre + 0.15f * (centre - displayCentre);
  1502. const auto span = 7.5f;
  1503. auto yFor = [&] (float note) { return graph.getCentreY() - (note - displayCentre) / span * graph.getHeight() * 0.5f; };
  1504. // note lanes: the scale's notes brighter, C labelled
  1505. const auto mask = vocal::scaleMask ((vocal::Scale) lynxtune::scaleIndex (fx.params[(std::size_t) lynxtune::scale]),
  1506. lynxtune::keyIndex (fx.params[(std::size_t) lynxtune::key]), 0xfff);
  1507. g.saveState();
  1508. g.reduceClipRegion (graph.toNearestInt());
  1509. g.setFont (font (juce::jmax (7.0f, 9.0f * s)));
  1510. for (int n = (int) std::floor (displayCentre - span) - 1; n <= (int) std::ceil (displayCentre + span) + 1; ++n)
  1511. {
  1512. const auto inScale = ((mask >> (((n % 12) + 12) % 12)) & 1) != 0;
  1513. const auto on = fx.params[(std::size_t) (lynxtune::noteC + ((n % 12) + 12) % 12)] >= 0.5f;
  1514. const auto y = yFor ((float) n);
  1515. g.setColour (inScale && on ? colour::gridBar : colour::gridStep);
  1516. g.drawHorizontalLine ((int) y, graph.getX(), graph.getRight());
  1517. if (inScale && on)
  1518. {
  1519. g.setColour (colour::textDisabled);
  1520. g.drawText (noteText (n), juce::Rectangle<float> (graph.getX() + 3.0f, y - 7.0f, 30.0f * s, 12.0f), juce::Justification::centredLeft);
  1521. }
  1522. }
  1523. // the curves, newest on the right
  1524. const auto stepX = graph.getWidth() / (float) (pitchHistoryLength - 1);
  1525. const auto x0 = graph.getRight() - stepX * (float) (history.size() - 1);
  1526. for (int which = 0; which < 2; ++which)
  1527. {
  1528. juce::Path p;
  1529. bool open = false;
  1530. for (std::size_t i = 0; i < history.size(); ++i)
  1531. {
  1532. const auto& h = history[i];
  1533. if (h.sung <= 0.5f) { open = false; continue; }
  1534. const auto x = x0 + stepX * (float) i;
  1535. const auto y = yFor (which == 0 ? h.sung : h.sung + h.shift);
  1536. if (! open) p.startNewSubPath (x, y);
  1537. else p.lineTo (x, y);
  1538. open = true;
  1539. }
  1540. if (which == 0)
  1541. {
  1542. g.setColour (colour::textSecondary.withAlpha (0.8f));
  1543. g.strokePath (p, juce::PathStrokeType (1.2f * s));
  1544. }
  1545. else
  1546. {
  1547. skin::glowStroke (g, p, fx.enabled ? accent : colour::textDisabled, 2.0f * s, fx.enabled ? 1.0f : 0.0f);
  1548. // round 126: the newest corrected pitch as a lit bead
  1549. if (fx.enabled && ! history.empty() && history.back().sung > 0.5f)
  1550. {
  1551. const juce::Point<float> head { x0 + stepX * (float) (history.size() - 1), yFor (history.back().sung + history.back().shift) };
  1552. skin::bloom (g, head, 14.0f * s, accent, 0.6f);
  1553. g.setColour (juce::Colours::white);
  1554. g.fillEllipse (juce::Rectangle<float> (5.0f * s, 5.0f * s).withCentre (head));
  1555. }
  1556. }
  1557. }
  1558. g.restoreState();
  1559. if (history.empty() || std::none_of (history.begin(), history.end(), [] (const PitchPoint& h) { return h.sung > 0.5f; }))
  1560. {
  1561. g.setColour (colour::textDisabled);
  1562. g.setFont (font (juce::jmax (8.0f, 12.0f * s)));
  1563. g.drawText (tr ("Play a voice or an instrument through the insert to see its pitch"), graph, juce::Justification::centred, true);
  1564. }
  1565. // legend
  1566. g.setFont (font (juce::jmax (7.0f, 9.0f * s)));
  1567. g.setColour (colour::textSecondary);
  1568. g.drawText (tr ("input"), graph.removeFromTop (14.0f * s).removeFromRight (120.0f * s).withTrimmedRight (6.0f), juce::Justification::centredLeft);
  1569. g.setColour (accent);
  1570. g.drawText (tr ("corrected"), graph.withHeight (14.0f * s).withY (graph.getY() - 14.0f * s).removeFromRight (64.0f * s), juce::Justification::centredLeft);
  1571. }
  1572. // LYNX Tune's correction meter (round 120, the centre of the auto-mode workflow): a ring of segments from −100 to
  1573. // +100 cents lit from the top toward the correction being applied, the target note's name in the middle and the
  1574. // sung pitch's offset under it
  1575. void paintPitchRing (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx)
  1576. {
  1577. using namespace theme;
  1578. const auto s = scale();
  1579. static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  1580. PitchPoint last { 0.0f, 0.0f, 0.0f };
  1581. if (tuneHold)
  1582. last = holdPoint; // HOLD: the read-out frozen where it was clicked (round 128)
  1583. else if (! pitchHistory.empty())
  1584. last = pitchHistory.back();
  1585. else if (demoDisplays)
  1586. last = { 63.62f, 64.0f, 0.38f };
  1587. const auto voiced = last.sung > 0.5f;
  1588. const auto side = juce::jmin (r.getWidth(), r.getHeight());
  1589. auto dial = r.withSizeKeepingCentre (side, side).reduced (4.0f * s);
  1590. const auto c = dial.getCentre();
  1591. const auto outer = dial.getWidth() * 0.5f, inner = outer * 0.74f;
  1592. // round 126: the ring is the hero of the editor: a bloom of the accent behind it (stronger with the
  1593. // correction), a deep bezel, a lit glass face
  1594. const auto voicedCorr = voiced ? juce::jmin (1.0f, std::abs (last.shift)) : 0.0f;
  1595. if (fx.enabled)
  1596. skin::bloom (g, c, outer * 1.55f, accent, 0.5f + 0.3f * voicedCorr);
  1597. g.setColour (juce::Colours::black.withAlpha (0.55f));
  1598. g.fillEllipse (dial.expanded (3.0f).translated (0.0f, 2.0f));
  1599. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff3a3e48), c.x, dial.getY() - 3.0f, juce::Colour (0xff111216), c.x, dial.getBottom() + 3.0f, false));
  1600. g.fillEllipse (dial.expanded (3.0f));
  1601. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff050608), 0.0f, dial.getY(), juce::Colour (0xff121319), 0.0f, dial.getBottom(), false));
  1602. g.fillEllipse (dial);
  1603. if (fx.enabled && ! skin::reducedEffects())
  1604. {
  1605. juce::ColourGradient face (accent.withAlpha (0.10f + 0.12f * voicedCorr), c.x, c.y, accent.withAlpha (0.0f), c.x + inner, c.y, true);
  1606. g.setGradientFill (face);
  1607. g.fillEllipse (juce::Rectangle<float> (inner * 2.0f, inner * 2.0f).withCentre (c));
  1608. }
  1609. g.setColour (juce::Colours::black.withAlpha (0.7f));
  1610. g.drawEllipse (dial.reduced (0.5f), 1.0f);
  1611. g.setColour (juce::Colours::white.withAlpha (0.06f));
  1612. g.drawEllipse (juce::Rectangle<float> (inner * 2.0f - 6.0f, inner * 2.0f - 6.0f).withCentre (c), 1.0f);
  1613. // 50 segments over 300° (−100 … +100 c), the top = 0
  1614. constexpr int segments = 50;
  1615. const auto sweep = juce::MathConstants<float>::pi * 5.0f / 3.0f;
  1616. const auto corr = juce::jlimit (-1.0f, 1.0f, voiced ? last.shift : 0.0f);
  1617. for (int k = 0; k < segments; ++k)
  1618. {
  1619. const auto u = ((float) k + 0.5f) / (float) segments * 2.0f - 1.0f; // −1 … +1
  1620. const auto a = u * sweep * 0.5f;
  1621. const auto lit = voiced && ((corr > 0.0f && u > 0.0f && u <= corr) || (corr < 0.0f && u < 0.0f && u >= corr));
  1622. juce::Path seg;
  1623. const auto w = sweep / (float) segments * 0.35f;
  1624. seg.addCentredArc (c.x, c.y, (outer + inner) * 0.5f, (outer + inner) * 0.5f, 0.0f, a - w, a + w, true);
  1625. const auto tipSeg = lit && std::abs (u) + 1.0f / (float) segments > std::abs (corr);
  1626. if (lit && fx.enabled && ! skin::reducedEffects()) // a lit segment glows
  1627. {
  1628. g.setColour (accent.withAlpha (0.16f));
  1629. g.strokePath (seg, juce::PathStrokeType ((outer - inner) * 1.5f));
  1630. g.setColour (accent.withAlpha (0.3f));
  1631. g.strokePath (seg, juce::PathStrokeType ((outer - inner) * 1.05f));
  1632. }
  1633. // lit: brighter toward the tip of the correction (the tip white-hot); unlit: dim glass LEDs
  1634. const auto litColour = accent.interpolatedWith (juce::Colours::white, tipSeg ? 0.55f : 0.12f * std::abs (u));
  1635. g.setColour (lit ? (fx.enabled ? litColour : colour::textDisabled) : juce::Colour (0xff22252c));
  1636. g.strokePath (seg, juce::PathStrokeType ((outer - inner) * 0.8f));
  1637. }
  1638. g.setColour (colour::gridBar);
  1639. g.drawLine (c.x, c.y - outer, c.x, c.y - inner, 1.5f);
  1640. // scale marks
  1641. g.setFont (font (juce::jmax (7.0f, 9.0f * s)));
  1642. g.setColour (colour::textDisabled);
  1643. for (const int m : { -100, -50, 0, 50, 100 })
  1644. {
  1645. const auto a = (float) m / 100.0f * sweep * 0.5f;
  1646. const auto rr = outer + 9.0f * s;
  1647. const juce::Point<float> pt { c.x + rr * std::sin (a), c.y - rr * std::cos (a) };
  1648. g.drawText ((m > 0 ? "+" : "") + juce::String (m), juce::Rectangle<float> (28.0f * s, 12.0f * s).withCentre (pt), juce::Justification::centred);
  1649. }
  1650. // the note and the offset
  1651. const auto target = (int) std::lround (last.target);
  1652. g.setFont (font (juce::jmax (14.0f, inner * 0.66f), true));
  1653. {
  1654. const auto noteBox = juce::Rectangle<float> (inner * 1.6f, inner * 0.8f).withCentre (c.translated (0.0f, -inner * 0.08f));
  1655. const auto noteName = voiced && last.target > 0.5f ? juce::String (names[((target % 12) + 12) % 12]) : juce::String ("--");
  1656. if (voiced && fx.enabled && ! skin::reducedEffects()) // the note glows
  1657. {
  1658. g.setColour (accent.withAlpha (0.2f));
  1659. for (const auto& o : { juce::Point<float> { -2.0f, 0.0f }, { 2.0f, 0.0f }, { 0.0f, -2.0f }, { 0.0f, 2.0f } })
  1660. g.drawText (noteName, noteBox.translated (o.x, o.y), juce::Justification::centred);
  1661. }
  1662. g.setColour (voiced ? (fx.enabled ? accent.interpolatedWith (juce::Colours::white, 0.3f) : colour::textSecondary) : colour::textDisabled);
  1663. g.drawText (noteName, noteBox, juce::Justification::centred);
  1664. }
  1665. g.setFont (font (juce::jmax (8.0f, 11.0f * s)));
  1666. g.setColour (colour::textSecondary);
  1667. if (voiced)
  1668. {
  1669. const auto cents = (int) std::lround ((last.sung - (float) target) * 100.0f);
  1670. g.drawText ((cents > 0 ? "+" : "") + juce::String (cents) + " c " + juce::String (target / 12 - 1),
  1671. juce::Rectangle<float> (inner * 1.4f, 16.0f * s).withCentre (c.translated (0.0f, inner * 0.5f)), juce::Justification::centred);
  1672. }
  1673. else
  1674. g.drawText (tr ("no pitch"), juce::Rectangle<float> (inner * 1.4f, 16.0f * s).withCentre (c.translated (0.0f, inner * 0.5f)), juce::Justification::centred);
  1675. // HOLD (round 128): click the meter to freeze its read-out
  1676. g.setFont (font (juce::jmax (7.0f, 9.0f * s), true));
  1677. g.setColour (tuneHold ? accent : colour::textDisabled);
  1678. g.drawText (tr ("HOLD"), juce::Rectangle<float> (inner, 12.0f * s).withCentre (c.translated (0.0f, inner * 0.78f)), juce::Justification::centred);
  1679. }
  1680. // --- LYNX Tune's keyboard (round 128; round 147: the Waves Tune Real-Time role's keyboard) ----------------------
  1681. // A key edits its note name in every octave (the reference's Group Octaves, always on here): in BYPASS mode it
  1682. // switches "pass uncorrected" (still a target, no correction), in REMOVE mode a click cycles the note's status like
  1683. // the reference's — legal → illegal (to the nearest legal note) → illegal, pitch up → illegal, pitch down → legal.
  1684. // LATCH off = the edit lasts only while the key is held (live use). Round 147: the view's navigation (− / + = fewer
  1685. // / more octaves, ◀ / ▶ = scroll), the range bar over the keys (click or drag near a boundary: the notes outside
  1686. // the range pass uncorrected), the range presets and Reset scale.
  1687. int tuneFirstOctave = 2, tuneShownOctaves = 4; // the view: C2 … B5 by default (the editor's own, not saved)
  1688. int tuneRangeDrag = -1; // 0 = the low boundary, 1 = the high one
  1689. int tuneSendFlash = 0; // round 150: Send lit for a few repaints after a click
  1690. enum TuneButton { tbBypass, tbRemove, tbReset, tbRange0, tbZoomOut = tbRange0 + lynxtune::rangePresets, tbZoomIn, tbLeft, tbRight, tbLatch,
  1691. tbSend, tbReceive, tbGroup, tbCount }; // round 150: Send / Receive; round 152: Group octaves
  1692. juce::Rectangle<float> tuneKeysStrip (juce::Rectangle<float> r) const { return r.withHeight (22.0f * scale()); }
  1693. juce::Rectangle<float> tuneKeysBed (juce::Rectangle<float> r) const { return r.withTrimmedTop (36.0f * scale()).reduced (2.0f * scale(), 2.0f * scale()); }
  1694. juce::Rectangle<float> tuneRangeBar (juce::Rectangle<float> r) const
  1695. {
  1696. const auto s = scale();
  1697. const auto bed = tuneKeysBed (r);
  1698. return { bed.getX(), bed.getY() - 10.0f * s, bed.getWidth(), 8.0f * s };
  1699. }
  1700. juce::Rectangle<float> tuneModeButton (juce::Rectangle<float> r, int which) const
  1701. {
  1702. const auto s = scale();
  1703. const auto strip = tuneKeysStrip (r).reduced (2.0f * s, 2.0f * s);
  1704. auto at = [&] (float x, float w) { return juce::Rectangle<float> (strip.getX() + x * s, strip.getY(), w * s, strip.getHeight()); };
  1705. // round 152: narrower buttons so Group octaves fits left of LATCH
  1706. if (which == tbBypass) return at (0.0f, 58.0f);
  1707. if (which == tbRemove) return at (62.0f, 58.0f);
  1708. if (which == tbReset) return at (124.0f, 44.0f);
  1709. if (which == tbSend) return at (172.0f, 40.0f); // round 150
  1710. if (which == tbReceive) return at (216.0f, 50.0f);
  1711. if (which >= tbRange0 && which < tbZoomOut) return at (270.0f + 42.0f * (float) (which - tbRange0), 40.0f);
  1712. if (which >= tbZoomOut && which <= tbRight) return at (568.0f + 22.0f * (float) (which - tbZoomOut), 20.0f);
  1713. if (which == tbGroup) return at (658.0f, 46.0f); // round 152
  1714. return strip.withLeft (strip.getRight() - 62.0f * s); // LATCH
  1715. }
  1716. int tuneVisibleWhites() const { return 7 * tuneShownOctaves; }
  1717. int tuneFirstNote() const { return 12 * (tuneFirstOctave + 1); } // MIDI note of the first C shown (C4 = 60)
  1718. float tuneNoteX (juce::Rectangle<float> bed, int note) const // the left edge of a note's white key column
  1719. {
  1720. static const int whiteOf[12] { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
  1721. const auto rel = note - tuneFirstNote();
  1722. const auto oct = (int) std::floor ((double) rel / 12.0);
  1723. const auto w = 7 * oct + whiteOf[((rel % 12) + 12) % 12];
  1724. return bed.getX() + bed.getWidth() * (float) w / (float) tuneVisibleWhites();
  1725. }
  1726. // the MIDI note of the key under p, −1 = none
  1727. int tuneKeyAt (juce::Rectangle<float> r, juce::Point<float> p) const
  1728. {
  1729. const auto bed = tuneKeysBed (r);
  1730. if (! bed.contains (p))
  1731. return -1;
  1732. static const int whitePc[7] { 0, 2, 4, 5, 7, 9, 11 };
  1733. const auto n = tuneVisibleWhites();
  1734. const auto ww = bed.getWidth() / (float) n;
  1735. if (p.y < bed.getY() + bed.getHeight() * 0.6f) // black keys first (on top)
  1736. for (int w = 0; w < n; ++w)
  1737. {
  1738. const auto pc = whitePc[w % 7];
  1739. if (pc == 4 || pc == 11)
  1740. continue;
  1741. const auto bx = bed.getX() + ww * (float) (w + 1) - ww * 0.3f;
  1742. if (p.x >= bx && p.x < bx + ww * 0.6f)
  1743. return tuneFirstNote() + 12 * (w / 7) + pc + 1;
  1744. }
  1745. const auto w = juce::jlimit (0, n - 1, (int) ((p.x - bed.getX()) / ww));
  1746. return tuneFirstNote() + 12 * (w / 7) + whitePc[w % 7];
  1747. }
  1748. // the note under x in the range bar (the nearest white-key column), clamped to the view
  1749. int tuneNoteAtX (juce::Rectangle<float> r, float x) const
  1750. {
  1751. const auto bed = tuneKeysBed (r);
  1752. static const int whitePc[7] { 0, 2, 4, 5, 7, 9, 11 };
  1753. const auto n = tuneVisibleWhites();
  1754. const auto w = juce::jlimit (0, n - 1, (int) ((x - bed.getX()) / (bed.getWidth() / (float) n)));
  1755. return tuneFirstNote() + 12 * (w / 7) + whitePc[w % 7];
  1756. }
  1757. void paintTuneKeys (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx)
  1758. {
  1759. using namespace theme;
  1760. const auto s = scale();
  1761. const auto& p = fx.params;
  1762. const auto sc = (vocal::Scale) lynxtune::effectiveScale (p[lynxtune::scale], p[lynxtune::moreScales]);
  1763. const auto inScale = vocal::scaleMask (sc, lynxtune::keyIndex (p[lynxtune::key]), 0xfff);
  1764. const auto lowNote = lynxtune::rangeNote (p[lynxtune::rangeLow]), highNote = lynxtune::rangeNote (p[lynxtune::rangeHigh]);
  1765. // the strip: modes, Reset scale, the range presets, the view's navigation, latch
  1766. for (int b = 0; b < tbCount; ++b)
  1767. {
  1768. const auto br = tuneModeButton (r, b);
  1769. bool lit = false;
  1770. juce::String name;
  1771. if (b == tbBypass) { lit = ! tuneRemove; name = tr ("Bypass"); }
  1772. else if (b == tbRemove) { lit = tuneRemove; name = tr ("Remove"); }
  1773. else if (b == tbReset) name = tr ("Reset");
  1774. else if (b == tbSend) { lit = tuneSendFlash > 0; name = tr ("Send"); }
  1775. else if (b == tbReceive) { lit = p[lynxtune::receiveScale] >= 0.5f; name = tr ("Receive"); }
  1776. else if (b == tbGroup) { lit = lynxtune::groupOctavesOn (p.data()); name = tr ("Group"); }
  1777. else if (b >= tbRange0 && b < tbZoomOut)
  1778. {
  1779. const auto [lo, hi] = lynxtune::rangePresetNotes (b - tbRange0);
  1780. lit = lo == lowNote && hi == highNote;
  1781. name = tr (lynxtune::rangePresetName (b - tbRange0));
  1782. }
  1783. else if (b == tbZoomOut) name = "-";
  1784. else if (b == tbZoomIn) name = "+";
  1785. else if (b == tbLeft) name = "<";
  1786. else if (b == tbRight) name = ">";
  1787. else { lit = tuneLatch; name = tr ("Latch"); }
  1788. skin::button (g, br, lit, br.contains (mouseAt), b == tbBypass ? juce::Colour (0xffe0a040) : accent, radius::sm * s);
  1789. g.setColour (lit ? colour::textPrimary : colour::textSecondary);
  1790. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  1791. g.drawText (name, br, juce::Justification::centred);
  1792. }
  1793. // the range bar: the notes inside the range lit, the two boundaries as handles
  1794. const auto bed = tuneKeysBed (r);
  1795. {
  1796. const auto rb = tuneRangeBar (r);
  1797. g.setColour (colour::bg0);
  1798. g.fillRoundedRectangle (rb, 2.0f * s);
  1799. const auto x0 = juce::jlimit (rb.getX(), rb.getRight(), tuneNoteX (bed, lowNote));
  1800. const auto x1 = juce::jlimit (rb.getX(), rb.getRight(), tuneNoteX (bed, highNote + 1));
  1801. if (x1 > x0)
  1802. {
  1803. g.setColour (accent.withAlpha (fx.enabled ? 0.55f : 0.25f));
  1804. g.fillRoundedRectangle (juce::Rectangle<float> (x0, rb.getY(), x1 - x0, rb.getHeight()), 2.0f * s);
  1805. }
  1806. g.setColour (colour::textPrimary);
  1807. for (const auto x : { x0, x1 })
  1808. if (x > rb.getX() && x < rb.getRight())
  1809. g.fillRect (juce::Rectangle<float> (3.0f * s, rb.getHeight() + 4.0f * s).withCentre ({ x, rb.getCentreY() }));
  1810. }
  1811. // keys
  1812. const auto n = tuneVisibleWhites();
  1813. const auto ww = bed.getWidth() / (float) n;
  1814. static const int whitePc[7] { 0, 2, 4, 5, 7, 9, 11 };
  1815. const auto sungNote = pitchHistory.empty() || pitchHistory.back().sung < 0.5f ? -1 : (int) std::lround (pitchHistory.back().target);
  1816. // round 152: each key's status in effect (its own when Group octaves is off)
  1817. const auto mask = tuneMask (p);
  1818. auto status = [&] (int note) { return lynxtune::noteStatus (p.data(), note, mask); };
  1819. auto legalNote = [&] (int note) { const auto st = status (note); return st == lynxtune::KeyStatus::legal || st == lynxtune::KeyStatus::bypass; };
  1820. auto keyColour = [&] (int note, bool black) {
  1821. const auto bypassed = status (note) == lynxtune::KeyStatus::bypass;
  1822. auto c = black ? juce::Colour (0xff1c1e24) : juce::Colour (0xffd9dbe0);
  1823. if (! legalNote (note))
  1824. c = black ? juce::Colour (0xff101114) : juce::Colour (0xff5a5d66); // removed / not in the scale
  1825. else if (bypassed)
  1826. c = black ? juce::Colour (0xff6b4d16) : juce::Colour (0xffe6be6e);
  1827. if (note < lowNote || note > highNote) // outside the range: passes uncorrected
  1828. c = c.interpolatedWith (colour::bg0, 0.55f);
  1829. return c;
  1830. };
  1831. auto mark = [&] (juce::Rectangle<float> k, int note) {
  1832. const auto pc = note % 12;
  1833. const auto inRange = note >= lowNote && note <= highNote;
  1834. const auto st = status (note);
  1835. const bool own = ! lynxtune::groupOctavesOn (p.data()) && lynxtune::keyOverride (p.data(), note) != lynxtune::KeyStatus::follow;
  1836. if (legalNote (note) && fx.enabled && inRange) // a target: the accent line at the key's top
  1837. {
  1838. g.setColour (st == lynxtune::KeyStatus::bypass ? juce::Colour (0xffe0a040) : accent);
  1839. g.fillRect (k.withHeight (3.0f * s));
  1840. }
  1841. if (own) // round 152: a key with its own status (Group octaves off): an outline
  1842. {
  1843. g.setColour (accent.withAlpha (0.8f));
  1844. g.drawRoundedRectangle (k.reduced (1.0f * s), 2.0f * s, 1.2f * s);
  1845. }
  1846. if (! legalNote (note))
  1847. {
  1848. const auto dir = st == lynxtune::KeyStatus::removedUp ? lynxtune::NoteDir::up
  1849. : (st == lynxtune::KeyStatus::removedDown ? lynxtune::NoteDir::down : lynxtune::NoteDir::nearest);
  1850. const auto x = juce::Rectangle<float> (7.0f * s, 7.0f * s).withCentre ({ k.getCentreX(), k.getY() + 10.0f * s });
  1851. g.setColour (accent.withAlpha (0.9f));
  1852. if (dir != lynxtune::NoteDir::nearest) // illegal, pitch up / down: an arrow
  1853. {
  1854. juce::Path a;
  1855. const auto up = dir == lynxtune::NoteDir::up;
  1856. a.addTriangle (x.getX(), up ? x.getBottom() : x.getY(), x.getRight(), up ? x.getBottom() : x.getY(), x.getCentreX(), up ? x.getY() : x.getBottom());
  1857. g.fillPath (a);
  1858. }
  1859. else if (((inScale >> pc) & 1u) != 0 || own) // removed by hand: a cross
  1860. {
  1861. g.drawLine (x.getX(), x.getY(), x.getRight(), x.getBottom(), 1.5f * s);
  1862. g.drawLine (x.getRight(), x.getY(), x.getX(), x.getBottom(), 1.5f * s);
  1863. }
  1864. }
  1865. if (note == sungNote && fx.enabled)
  1866. {
  1867. g.setColour (accent.withAlpha (0.55f));
  1868. g.fillEllipse (juce::Rectangle<float> (7.0f * s, 7.0f * s).withCentre ({ k.getCentreX(), k.getBottom() - 9.0f * s }));
  1869. }
  1870. };
  1871. for (int w = 0; w < n; ++w)
  1872. {
  1873. const auto note = tuneFirstNote() + 12 * (w / 7) + whitePc[w % 7];
  1874. const auto k = juce::Rectangle<float> (bed.getX() + ww * (float) w, bed.getY(), ww - 1.0f, bed.getHeight());
  1875. g.setColour (keyColour (note, false));
  1876. g.fillRoundedRectangle (k, 2.0f * s);
  1877. mark (k, note);
  1878. if (note % 12 == 0)
  1879. {
  1880. g.setColour (juce::Colour (0xff3a3d45));
  1881. g.setFont (font (juce::jmax (7.0f, 9.0f * s)));
  1882. g.drawText ("C" + juce::String (note / 12 - 1), k.withTrimmedBottom (2.0f * s).withTop (k.getBottom() - 14.0f * s), juce::Justification::centred);
  1883. }
  1884. }
  1885. for (int w = 0; w < n; ++w)
  1886. {
  1887. const auto pc = whitePc[w % 7];
  1888. if (pc == 4 || pc == 11)
  1889. continue;
  1890. const auto note = tuneFirstNote() + 12 * (w / 7) + pc + 1;
  1891. const auto k = juce::Rectangle<float> (bed.getX() + ww * (float) (w + 1) - ww * 0.3f, bed.getY(), ww * 0.6f, bed.getHeight() * 0.6f);
  1892. g.setColour (keyColour (note, true));
  1893. g.fillRoundedRectangle (k, 2.0f * s);
  1894. mark (k, note);
  1895. }
  1896. }
  1897. void tuneSetRangeAt (juce::Rectangle<float> r, float x, bool pickNearer)
  1898. {
  1899. const auto* fx = current();
  1900. if (fx == nullptr)
  1901. return;
  1902. const auto note = tuneNoteAtX (r, x);
  1903. const auto lo = lynxtune::rangeNote (fx->params[lynxtune::rangeLow]), hi = lynxtune::rangeNote (fx->params[lynxtune::rangeHigh]);
  1904. if (pickNearer)
  1905. tuneRangeDrag = std::abs (note - lo) <= std::abs (note - hi) ? 0 : 1;
  1906. if (tuneRangeDrag == 0)
  1907. setParams ({ { lynxtune::rangeLow, lynxtune::rangeNoteValue (juce::jmin (note, hi)) } });
  1908. else if (tuneRangeDrag == 1)
  1909. setParams ({ { lynxtune::rangeHigh, lynxtune::rangeNoteValue (juce::jmax (note, lo)) } });
  1910. const auto shown = tuneRangeDrag == 0 ? lynxtune::rangeLow : lynxtune::rangeHigh;
  1911. ui::showValueTip (*this, tuneRangeBar (r).toNearestInt(), tr ("Range") + " " + juce::String (lynxtune::paramText (shown, current()->params[(std::size_t) shown])));
  1912. }
  1913. // round 152: the pitch classes that are targets (the scale on the key, minus the notes switched off)
  1914. static std::uint16_t tuneMask (const EffectParams& p)
  1915. {
  1916. std::uint16_t notes = 0;
  1917. for (int k = 0; k < 12; ++k)
  1918. if (p[(std::size_t) (lynxtune::noteC + k)] >= 0.5f) notes = (std::uint16_t) (notes | (1u << k));
  1919. const auto sc = (vocal::Scale) lynxtune::effectiveScale (p[lynxtune::scale], p[lynxtune::moreScales]);
  1920. return (std::uint16_t) (vocal::scaleMask (sc, lynxtune::keyIndex (p[lynxtune::key]), notes) & notes);
  1921. }
  1922. void tuneKeyClick (juce::Rectangle<float> r, juce::Point<float> at)
  1923. {
  1924. const auto* fx = current();
  1925. if (fx == nullptr)
  1926. return;
  1927. for (int b = 0; b < tbCount; ++b)
  1928. if (tuneModeButton (r, b).contains (at))
  1929. {
  1930. if (b == tbLatch)
  1931. tuneLatch = ! tuneLatch;
  1932. else if (b == tbSend) // round 150: this scale to every other LYNX Tune with Receive on
  1933. {
  1934. engine.editSong ([t = track, sl = slot] (Song& song) { lynxtune::sendScaleToAll (song, t, sl); });
  1935. tuneSendFlash = 8;
  1936. }
  1937. else if (b == tbReceive) // on: take the scale sent last now, and the ones sent later
  1938. {
  1939. const bool nowOn = fx->params[lynxtune::receiveScale] < 0.5f;
  1940. std::vector<std::pair<int, float>> c { { lynxtune::receiveScale, nowOn ? 1.0f : 0.0f } };
  1941. lynxtune::SharedScale sh;
  1942. if (nowOn && lynxtune::publishedScale (sh))
  1943. for (std::size_t i = 0; i < sh.values.size(); ++i)
  1944. c.push_back ({ lynxtune::sharedScaleList()[i], sh.values[i] });
  1945. setParams (c);
  1946. }
  1947. else if (b == tbBypass || b == tbRemove)
  1948. tuneRemove = b == tbRemove;
  1949. else if (b == tbGroup) // round 152: Group octaves on / off (the keys' own statuses are kept)
  1950. setParams ({ { lynxtune::groupOctaves, lynxtune::groupOctavesOn (fx->params.data()) ? 0.0f : 1.0f } });
  1951. else if (b == tbReset) // every note of the scale legal again, nothing bypassed, no direction
  1952. {
  1953. std::vector<std::pair<int, float>> c;
  1954. for (int k = 0; k < lynxtune::keyMapParams; ++k) // round 152: and no key of its own
  1955. c.push_back ({ lynxtune::keyMap1 + k, 0.0f });
  1956. for (int k = 0; k < 12; ++k)
  1957. {
  1958. c.push_back ({ lynxtune::noteC + k, 1.0f });
  1959. c.push_back ({ lynxtune::bypassC + k, 0.0f });
  1960. c.push_back ({ lynxtune::noteDirC + k, 0.0f });
  1961. }
  1962. setParams (c);
  1963. }
  1964. else if (b >= tbRange0 && b < tbZoomOut)
  1965. {
  1966. // a range preset: the keyboard's range, and the detector's input type that covers it
  1967. const auto k = b - tbRange0;
  1968. const auto [lo, hi] = lynxtune::rangePresetNotes (k);
  1969. std::vector<std::pair<int, float>> c { { lynxtune::rangeLow, lynxtune::rangeNoteValue (lo) }, { lynxtune::rangeHigh, lynxtune::rangeNoteValue (hi) } };
  1970. static constexpr float inputType[lynxtune::rangePresets] { 2.0f / 3.0f, 2.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f, 0.0f, 0.0f, -1.0f };
  1971. if (inputType[k] >= 0.0f)
  1972. c.push_back ({ lynxtune::range, inputType[k] });
  1973. setParams (c);
  1974. }
  1975. else if (b == tbZoomOut) tuneShownOctaves = juce::jmin (7, tuneShownOctaves + 1);
  1976. else if (b == tbZoomIn) tuneShownOctaves = juce::jmax (2, tuneShownOctaves - 1);
  1977. else if (b == tbLeft) tuneFirstOctave = juce::jmax (0, tuneFirstOctave - 1);
  1978. else if (b == tbRight) tuneFirstOctave = juce::jmin (9 - tuneShownOctaves, tuneFirstOctave + 1);
  1979. tuneFirstOctave = juce::jlimit (0, juce::jmax (0, 9 - tuneShownOctaves), tuneFirstOctave);
  1980. repaint();
  1981. return;
  1982. }
  1983. if (tuneRangeBar (r).expanded (0.0f, 2.0f * scale()).contains (at))
  1984. {
  1985. tuneSetRangeAt (r, at.x, true);
  1986. return;
  1987. }
  1988. const auto note = tuneKeyAt (r, at);
  1989. if (note < 0)
  1990. return;
  1991. if (! lynxtune::groupOctavesOn (fx->params.data())) // round 152: Group octaves off — this key alone
  1992. {
  1993. auto copy = fx->params;
  1994. const auto st = lynxtune::noteStatus (copy.data(), note, tuneMask (copy));
  1995. const auto next = tuneRemove ? lynxtune::nextRemoveStatus (st)
  1996. : (st == lynxtune::KeyStatus::bypass ? lynxtune::KeyStatus::legal : lynxtune::KeyStatus::bypass);
  1997. const auto mp = lynxtune::keyMap1 + juce::jlimit (0, lynxtune::keyMapParams - 1, (note - lynxtune::keyMapFirst) / lynxtune::keyMapPerParam);
  1998. tuneHeldMap = tuneLatch ? -1 : mp;
  1999. tuneHeldMapValue = copy[(std::size_t) mp];
  2000. lynxtune::setKeyOverride (copy.data(), note, next);
  2001. setParams ({ { mp, copy[(std::size_t) mp] } });
  2002. return;
  2003. }
  2004. const auto pc = note % 12;
  2005. const auto onP = lynxtune::noteC + pc, byP = lynxtune::bypassC + pc, dirP = lynxtune::noteDirC + pc;
  2006. const auto on = fx->params[(std::size_t) onP] >= 0.5f, by = fx->params[(std::size_t) byP] >= 0.5f;
  2007. const auto dir = lynxtune::noteDir (fx->params[(std::size_t) dirP]);
  2008. tuneHeld = tuneLatch ? -1 : pc;
  2009. tuneHeldValues = { fx->params[(std::size_t) onP], fx->params[(std::size_t) byP] };
  2010. tuneHeldDir = fx->params[(std::size_t) dirP];
  2011. if (tuneRemove)
  2012. {
  2013. // the reference's status cycle: legal → illegal → illegal, pitch up → illegal, pitch down → legal (a note
  2014. // outside the scale stays illegal: only its direction cycles)
  2015. const auto sc = (vocal::Scale) lynxtune::effectiveScale (fx->params[lynxtune::scale], fx->params[lynxtune::moreScales]);
  2016. const bool scaleNote = ((vocal::scaleMask (sc, lynxtune::keyIndex (fx->params[lynxtune::key]), 0xfff) >> pc) & 1u) != 0;
  2017. const auto nextDir = dir == lynxtune::NoteDir::nearest ? 0.5f : (dir == lynxtune::NoteDir::up ? 1.0f : 0.0f);
  2018. if (scaleNote && on)
  2019. setParams ({ { onP, 0.0f }, { byP, 0.0f }, { dirP, 0.0f } });
  2020. else if (scaleNote && dir == lynxtune::NoteDir::down)
  2021. setParams ({ { onP, 1.0f }, { byP, 0.0f }, { dirP, 0.0f } });
  2022. else
  2023. setParams ({ { onP, on ? 1.0f : 0.0f }, { byP, 0.0f }, { dirP, nextDir } });
  2024. }
  2025. else
  2026. setParams ({ { onP, 1.0f }, { byP, by && on ? 0.0f : 1.0f }, { dirP, 0.0f } });
  2027. }
  2028. void tuneKeyRelease()
  2029. {
  2030. if (tuneRangeDrag >= 0)
  2031. {
  2032. tuneRangeDrag = -1;
  2033. ui::hideValueTip();
  2034. }
  2035. if (tuneHeldMap >= 0) // round 152
  2036. {
  2037. setParams ({ { tuneHeldMap, tuneHeldMapValue } });
  2038. tuneHeldMap = -1;
  2039. }
  2040. if (tuneHeld < 0)
  2041. return;
  2042. setParams ({ { lynxtune::noteC + tuneHeld, tuneHeldValues.first }, { lynxtune::bypassC + tuneHeld, tuneHeldValues.second },
  2043. { lynxtune::noteDirC + tuneHeld, tuneHeldDir } });
  2044. tuneHeld = -1;
  2045. }
  2046. juce::String tuneKeysHint (juce::Rectangle<float> r, juce::Point<float> at) const
  2047. {
  2048. for (int b = 0; b < tbCount; ++b)
  2049. if (tuneModeButton (r, b).contains (at))
  2050. {
  2051. if (b == tbBypass) return tr ("Bypass mode: a key switches its note between corrected and passed as sung");
  2052. if (b == tbRemove) return tr ("Remove mode: a key cycles its note: legal, illegal (to the nearest note), illegal pitch up, illegal pitch down");
  2053. if (b == tbReset) return tr ("Reset scale: every note of the scale legal again, nothing bypassed");
  2054. if (b == tbSend) return tr ("Send: copy this key, scale and keyboard to every other LYNX Tune whose Receive is on");
  2055. if (b == tbReceive) return tr ("Receive: take the scale another LYNX Tune sends (switching it on takes the last one sent)");
  2056. if (b == tbGroup) return tr ("Group octaves: on = a key edits its note in every octave; off = each key keeps its own status");
  2057. if (b >= tbRange0 && b < tbZoomOut) return tr ("Range preset: notes sung outside the range pass uncorrected (Generic: the whole keyboard)");
  2058. if (b == tbZoomOut || b == tbZoomIn) return tr ("Keyboard view: show more / fewer octaves");
  2059. if (b == tbLeft || b == tbRight) return tr ("Keyboard view: scroll down / up an octave");
  2060. return tr ("Latch: off = a key's edit lasts only while it is held");
  2061. }
  2062. if (tuneRangeBar (r).expanded (0.0f, 2.0f * scale()).contains (at))
  2063. return tr ("Range: drag a boundary; notes sung outside it pass uncorrected");
  2064. if (current() != nullptr && ! lynxtune::groupOctavesOn (current()->params.data())) // round 152
  2065. return tuneRemove ? tr ("Click a key: change the status of this key only") : tr ("Click a key: bypass / correct this key only");
  2066. return tuneRemove ? tr ("Click a key: change that note's status in every octave") : tr ("Click a key: bypass / correct that note in every octave");
  2067. }
  2068. // the hardware insert's round-trip read-out (round 164d): the delay in samples and ms, then what the ping says or what
  2069. // is missing for the insert to work
  2070. void paintHwPing (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx)
  2071. {
  2072. using namespace theme;
  2073. const auto s = scale();
  2074. g.setColour (colour::bg0);
  2075. g.fillRoundedRectangle (r, radius::sm * s);
  2076. auto area = r.reduced (8.0f * s, 6.0f * s);
  2077. const auto samples = hwinsert::roundTripOf (fx.params[hwinsert::roundTrip]);
  2078. const auto rate = engine.getTransport().sampleRate.load();
  2079. g.setColour (samples > 0 ? colour::textPrimary : colour::textSecondary);
  2080. g.setFont (font (juce::jmax (12.0f, 22.0f * s), true));
  2081. g.drawText (juce::String (samples) + " " + tr ("smp"), area.removeFromTop (28.0f * s), juce::Justification::centred, false);
  2082. g.setColour (colour::textSecondary);
  2083. g.setFont (font (juce::jmax (8.0f, 11.0f * s)));
  2084. g.drawText (rate > 0.0 ? juce::String (1000.0 * samples / rate, 2) + " ms" : juce::String(), area.removeFromTop (16.0f * s), juce::Justification::centred, false);
  2085. // the state (newest first): the ping running or its outcome, then what the routing lacks
  2086. const auto ping = liveMeter (hwinsert::pingState);
  2087. const auto flags = juce::roundToInt (liveMeter (hwinsert::status) * 16.0f);
  2088. const auto outCh = hwinsert::channelOf (fx.params[hwinsert::output]), inCh = hwinsert::channelOf (fx.params[hwinsert::input]);
  2089. juce::String text;
  2090. auto warn = false;
  2091. if (engine.getTransport().sampleRate.load() <= 0.0 || engine.getOutputChannelNames().empty())
  2092. text = tr ("No audio device is open"), warn = true;
  2093. else if (outCh < 0 || inCh < 0)
  2094. text = tr ("Choose the output and the input your gear is wired to"), warn = true;
  2095. else if ((flags & 2) != 0)
  2096. text = tr ("The output is not open on this device"), warn = true;
  2097. else if ((flags & 4) != 0)
  2098. text = tr ("The input is not open on this device"), warn = true;
  2099. else if (ping > 0.2f && ping < 0.3f)
  2100. text = tr ("Pinging...");
  2101. else if (ping > 0.6f && ping < 0.7f)
  2102. text = tr ("Ping failed: no click came back (check the cable and the return level)"), warn = true;
  2103. else if (ping > 0.7f && ping < 0.8f)
  2104. text = tr ("Ping failed: clicks were missing"), warn = true;
  2105. else if (ping > 0.8f)
  2106. text = tr ("Ping failed: the round trip was not stable"), warn = true;
  2107. else if (samples == 0)
  2108. text = tr ("Not measured yet: press Ping"), warn = true;
  2109. else if (const auto measured = hwinsert::measuredSetup (fx); ! measured.empty() && measured != engine.currentSetupKey())
  2110. text = tr ("Measured for another audio setup (the device or the buffer size changed): press Ping"), warn = true; // round 165c
  2111. else if (ping > 0.4f && ping < 0.6f)
  2112. text = tr ("Measured: delay compensated");
  2113. else
  2114. text = tr ("Delay compensated (PDC)");
  2115. g.setColour (warn ? juce::Colour (0xffe5a03b) : colour::textSecondary);
  2116. g.setFont (font (juce::jmax (8.0f, 10.0f * s)));
  2117. g.drawFittedText (text, area.toNearestInt(), juce::Justification::centred, 3, 0.8f);
  2118. }
  2119. // shows a ping's result once (AudioEngine makes it the slot's delay: undoable, saved with the project)
  2120. void hwPingTick()
  2121. {
  2122. const auto serial = juce::roundToInt (liveMeter (hwinsert::pingSerial) * 1024.0f);
  2123. if (hwSerial < 0)
  2124. {
  2125. hwSerial = serial;
  2126. return;
  2127. }
  2128. if (serial == hwSerial)
  2129. return;
  2130. hwSerial = serial;
  2131. if (std::abs (liveMeter (hwinsert::pingState) - 0.5f) < 0.01f)
  2132. {
  2133. // (the engine applies the result to the slot, with the device setup it belongs to: round 165c)
  2134. const auto samples = hwinsert::roundTripOf (liveMeter (hwinsert::pingSamples));
  2135. for (const auto& item : activeLayout().items)
  2136. if (item.type == Item::display && item.display != nullptr && std::strcmp (item.display, "hwping") == 0)
  2137. ui::flashValueTip (*this, rectOf (item).toNearestInt(), tr ("Round trip: {0} samples", { juce::String (samples) }));
  2138. }
  2139. repaint();
  2140. }
  2141. int hwSerial = -1; // the last ping result seen (−1: not read yet)
  2142. void paintAutoKey (juce::Graphics& g, juce::Rectangle<float> r)
  2143. {
  2144. using namespace theme;
  2145. const auto s = scale();
  2146. skin::button (g, r, autoKeyFlash > 0, r.contains (mouseAt), accent, radius::sm * s);
  2147. g.setColour (colour::textPrimary);
  2148. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  2149. g.drawText (tr ("Auto Key"), r, juce::Justification::centred);
  2150. }
  2151. // LEARN (round 135): while LYNX Tune's "Learn scale" is on, every pitch class held on its MIDI channel joins the
  2152. // custom scale (switching learning on starts a new scale)
  2153. void learnScaleFromMidi()
  2154. {
  2155. const auto* fx = current();
  2156. if (fx == nullptr || fx->kind != EffectKind::lynxTune)
  2157. return;
  2158. const bool on = fx->params[(std::size_t) lynxtune::learnMidi] >= 0.5f;
  2159. if (! on)
  2160. {
  2161. learning = false;
  2162. return;
  2163. }
  2164. if (! learning)
  2165. {
  2166. learning = true;
  2167. learned = 0;
  2168. }
  2169. const auto held = (unsigned) std::lround (liveMeter (5) * 4096.0f) & 0xfffu;
  2170. if ((held & ~learned) == 0)
  2171. return;
  2172. learned |= held;
  2173. std::vector<std::pair<int, float>> changes { { lynxtune::scale, (float) (int) vocal::Scale::custom / (float) (vocal::scaleCount - 1) },
  2174. { lynxtune::moreScales, 0.0f } };
  2175. for (int pc = 0; pc < 12; ++pc)
  2176. {
  2177. changes.push_back ({ lynxtune::noteC + pc, ((learned >> pc) & 1u) != 0 ? 1.0f : 0.0f });
  2178. changes.push_back ({ lynxtune::bypassC + pc, 0.0f });
  2179. }
  2180. setParams (changes);
  2181. }
  2182. bool learning = false;
  2183. unsigned learned = 0;
  2184. // AUTO KEY: the key and major / minor scale of what was sung while the editor was open (time per pitch class)
  2185. void autoKey (juce::Rectangle<float> r)
  2186. {
  2187. double total = 0.0;
  2188. for (const auto x : keyHistogram)
  2189. total += x;
  2190. if (total < 30.0) // about a second of voiced singing
  2191. {
  2192. ui::flashValueTip (*this, r.toNearestInt(), tr ("Play the vocal for a few seconds first"));
  2193. return;
  2194. }
  2195. const auto [k, mode] = vocal::detectKey (keyHistogram);
  2196. if (k < 0)
  2197. return;
  2198. std::vector<std::pair<int, float>> changes { { lynxtune::key, (float) k / 11.0f },
  2199. { lynxtune::scale, (float) (int) mode / (float) (vocal::scaleCount - 1) },
  2200. { lynxtune::moreScales, 0.0f } };
  2201. for (int pc = 0; pc < 12; ++pc)
  2202. {
  2203. changes.push_back ({ lynxtune::noteC + pc, 1.0f });
  2204. changes.push_back ({ lynxtune::bypassC + pc, 0.0f });
  2205. }
  2206. setParams (changes);
  2207. autoKeyFlash = 20;
  2208. static const char* names[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  2209. ui::flashValueTip (*this, r.toNearestInt(), juce::String (names[k]) + " " + tr (mode == vocal::Scale::major ? "Major" : "Minor"));
  2210. }
  2211. // the live meter `output` of this slot's effect (published by the audio thread; 0 when not playing)
  2212. float liveMeter (int output) const
  2213. {
  2214. if (node.running)
  2215. {
  2216. const auto fx = node.running();
  2217. return fx != nullptr ? fx->controlOutput (output) : 0.0f;
  2218. }
  2219. const auto* times = engine.getProcessTimes();
  2220. const auto key = (std::size_t) (track * maxEffectSlots + slot) * ProcessTimes::meterOutputs + (std::size_t) juce::jlimit (0, ProcessTimes::meterOutputs - 1, output);
  2221. return times != nullptr && key < times->effectMeters.size() ? times->effectMeters[key].load (std::memory_order_relaxed) : 0.0f;
  2222. }
  2223. // the captions of a radio's options (Gross Beat: the slot names saved in the state)
  2224. std::vector<juce::String> optionTexts (const LayoutItem& item) const
  2225. {
  2226. std::vector<juce::String> out;
  2227. const auto labels = plugui::optionLabels (item);
  2228. // the whole list is one translation ("Mono|Stereo|Ping pong|Off"); single words are translated alone
  2229. const auto whole = juce::StringArray::fromTokens (tr (juce::String::fromUTF8 (item.options != nullptr ? item.options : "")), "|", "");
  2230. for (std::size_t o = 0; o < labels.size(); ++o)
  2231. out.push_back (whole.size() == (int) labels.size() ? whole[(int) o] : tr (juce::String::fromUTF8 (labels[o].c_str())));
  2232. if (kind == EffectKind::grossBeat && item.columns > 0)
  2233. if (const auto* fx = current())
  2234. {
  2235. const auto names = grossbeat::slotNames (fx->state, std::strcmp (item.param, "Volume slot") == 0);
  2236. for (std::size_t i = 0; i < names.size() && i < out.size(); ++i)
  2237. if (! names[i].empty())
  2238. out[i] = juce::String::fromUTF8 (names[i].c_str());
  2239. }
  2240. return out;
  2241. }
  2242. // the cell of option `o` in a radio grid
  2243. juce::Rectangle<float> gridCell (const LayoutItem& item, int o, int count) const
  2244. {
  2245. const auto r = rectOf (item);
  2246. const auto rows = (count + item.columns - 1) / item.columns;
  2247. const auto w = r.getWidth() / (float) item.columns, h = r.getHeight() / (float) juce::jmax (1, rows);
  2248. return { r.getX() + w * (float) (o % item.columns), r.getY() + h * (float) (o / item.columns), w, h };
  2249. }
  2250. // --- round 167b: the Transmitter's envelope view and its transient / sustain sends (REA_rodada167b §1, §3)
  2251. std::shared_ptr<Effect> runningEffect() const
  2252. {
  2253. if (node.running)
  2254. return node.running();
  2255. return engine.getEffect (track, slot);
  2256. }
  2257. // FL's envelope view: the last columns of the detector, newest on the right. Per column: the output's peak (grey,
  2258. // mirrored around the middle), the transient envelope e (accent) and the sustain envelope 1 − e (light line).
  2259. void paintTransmitterEnvelope (juce::Graphics& g, juce::Rectangle<float> area, const EffectSlot& fx)
  2260. {
  2261. using namespace theme;
  2262. const auto s = scale();
  2263. const auto running = runningEffect();
  2264. const auto* view = transmitter::envelopeOf (running.get());
  2265. const auto columns = juce::jmax (8, (int) area.getWidth());
  2266. std::vector<transmitter::EnvelopeColumn> shown ((std::size_t) columns);
  2267. if (view != nullptr)
  2268. {
  2269. const auto written = view->written.load (std::memory_order_acquire);
  2270. const auto have = (int) juce::jmin<std::uint32_t> (written, (std::uint32_t) juce::jmin (columns, (int) transmitter::EnvelopeView::size - 1));
  2271. for (int k = 0; k < have; ++k)
  2272. shown[(std::size_t) (columns - have + k)] = view->columns[(written - (std::uint32_t) have + (std::uint32_t) k) % transmitter::EnvelopeView::size];
  2273. }
  2274. else if (demoDisplays) // a drum loop's envelopes, for the snapshots
  2275. for (int k = 0; k < columns; ++k)
  2276. {
  2277. const auto t = std::fmod ((float) k / 46.0f, 1.0f);
  2278. const auto e = std::exp (-t * 9.0f);
  2279. shown[(std::size_t) k] = { 0.15f + 0.75f * std::exp (-t * 4.0f), e, 1.0f - e };
  2280. }
  2281. const auto x0 = area.getX(), w = area.getWidth() / (float) columns;
  2282. const auto mid = area.getCentreY(), half = area.getHeight() * 0.5f;
  2283. // the output, as a mirrored peak outline
  2284. juce::Path wave;
  2285. for (int k = 0; k < columns; ++k)
  2286. {
  2287. const auto y = mid - half * juce::jlimit (0.0f, 1.0f, shown[(std::size_t) k].output);
  2288. if (k == 0) wave.startNewSubPath (x0, y); else wave.lineTo (x0 + w * (float) k, y);
  2289. }
  2290. for (int k = columns - 1; k >= 0; --k)
  2291. wave.lineTo (x0 + w * (float) k, mid + half * juce::jlimit (0.0f, 1.0f, shown[(std::size_t) k].output));
  2292. wave.closeSubPath();
  2293. g.setColour (colour::textDisabled.withAlpha (fx.enabled ? 0.45f : 0.25f));
  2294. g.fillPath (wave);
  2295. auto line = [&] (float transmitter::EnvelopeColumn::* field, juce::Colour c) {
  2296. juce::Path p;
  2297. for (int k = 0; k < columns; ++k)
  2298. {
  2299. const auto y = area.getBottom() - area.getHeight() * juce::jlimit (0.0f, 1.0f, shown[(std::size_t) k].*field);
  2300. if (k == 0) p.startNewSubPath (x0, y); else p.lineTo (x0 + w * (float) k, y);
  2301. }
  2302. skin::glowStroke (g, p, c, juce::jmax (1.2f, 1.6f * s), fx.enabled ? 1.0f : 0.0f);
  2303. };
  2304. line (&transmitter::EnvelopeColumn::sustain, (fx.enabled ? colour::textSecondary : colour::textDisabled).withAlpha (0.8f));
  2305. line (&transmitter::EnvelopeColumn::transient, fx.enabled ? accent : colour::textDisabled);
  2306. // the legend
  2307. g.setFont (font (juce::jmax (7.0f, 9.0f * s), true));
  2308. auto legend = area.reduced (4.0f * s, 2.0f * s).removeFromTop (12.0f * s);
  2309. g.setColour (fx.enabled ? accent : colour::textDisabled);
  2310. g.drawText (caps (tr ("Transient")), legend.removeFromLeft (80.0f * s), juce::Justification::centredLeft);
  2311. g.setColour (colour::textSecondary);
  2312. g.drawText (caps (tr ("Sustain")), legend.removeFromLeft (80.0f * s), juce::Justification::centredLeft);
  2313. }
  2314. // the send box of a part: FL's "send to mixer track" menu (… = not sent)
  2315. void paintTransmitterSend (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx, int part)
  2316. {
  2317. using namespace theme;
  2318. const auto s = scale();
  2319. const auto target = fx.sendTracks[(std::size_t) part];
  2320. g.setColour (target > 0 ? accent : colour::accentMuted);
  2321. g.fillRoundedRectangle (r, radius::sm * s);
  2322. g.setColour (target > 0 ? colour::onAccent : colour::textSecondary);
  2323. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  2324. const auto text = target > 0 ? tr ("Send to {0}", { juce::String (target) + " " + insertName (target) }) : tr ("Send to") + juce::String (juce::CharPointer_UTF8 (" \xe2\x80\xa6"));
  2325. g.drawFittedText (text, r.reduced (4.0f * s, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  2326. }
  2327. void showTransmitterSendMenu (int part, juce::Rectangle<float> r)
  2328. {
  2329. const auto* fx = current();
  2330. if (fx == nullptr || node.locate) // (a Patcher node has no insert to send from)
  2331. return;
  2332. juce::PopupMenu menu;
  2333. const auto chosen = fx->sendTracks[(std::size_t) part];
  2334. auto choose = [this, part] (int t) {
  2335. editSlot ([part, t] (EffectSlot& e) {
  2336. e.sendTracks[(std::size_t) part] = t;
  2337. if (e.kind == EffectKind::equo) // (EQUO keeps its send track in its state too, as FL saves it)
  2338. equofx::setSendInsert (e.state, t);
  2339. });
  2340. };
  2341. const auto& mixer = engine.getSong().mixer;
  2342. if (fx->kind == EffectKind::equo) // FL's EQUO send box: (none) and the tracks this insert routes to (round 173d3)
  2343. {
  2344. menu.addItem ("(" + tr ("none") + ")", true, chosen <= 0, [choose] { choose (0); });
  2345. for (int t = 1; t < (int) mixer.size(); ++t)
  2346. if (t != track && (engine.getSong().routes (track, t) || t == chosen))
  2347. menu.addItem (insertName (t), true, t == chosen, [choose, t] { choose (t); });
  2348. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  2349. return;
  2350. }
  2351. menu.addItem (tr ("None"), true, chosen <= 0, [choose] { choose (0); });
  2352. for (int t = 1; t < (int) mixer.size(); ++t)
  2353. if (t != track)
  2354. menu.addItem (juce::String (t) + " " + insertName (t), engine.getSong().canRoute (track, t) || t == chosen, t == chosen, [choose, t] { choose (t); });
  2355. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  2356. }
  2357. // round tp172b4: the Space engine's decay-rate EQ, the reference reverb's main display: the decay rate (100 % =
  2358. // the SPACE time) from 20 Hz to 20 kHz on a log grid, shaped by the low and high decay multipliers past their
  2359. // frequencies; percent on the left, hertz along the bottom
  2360. void paintDecayEq (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx)
  2361. {
  2362. using namespace theme;
  2363. namespace sp = luxeverb::sp;
  2364. const auto s = scale();
  2365. const auto at = [&] (int i) { return valueOf (luxeVerbSpaceFirst + i); };
  2366. const auto plot = r.withTrimmedLeft (44.0f * s).withTrimmedRight (14.0f * s).withTrimmedTop (22.0f * s).withTrimmedBottom (20.0f * s);
  2367. const auto lo = std::log (20.0), hi = std::log (20000.0);
  2368. const auto xOf = [&] (double hz) { return plot.getX() + plot.getWidth() * (float) ((std::log (hz) - lo) / (hi - lo)); };
  2369. constexpr float topOct = 1.5f, bottomOct = -3.4f; // log2 of the rate: 283 % … 9.5 %
  2370. const auto yOf = [&] (double rate) {
  2371. const auto o = (float) std::log2 (juce::jmax (1.0e-3, rate));
  2372. return plot.getY() + plot.getHeight() * juce::jlimit (0.0f, 1.0f, (topOct - o) / (topOct - bottomOct));
  2373. };
  2374. const auto blue = skin::artAccent2 (skin::art());
  2375. g.setFont (font (juce::jmax (8.0f, 10.5f * s)));
  2376. // the frequency grid (1-2-5 marks a decade, the labelled ones brighter)
  2377. for (double dec = 10.0; dec <= 10000.0; dec *= 10.0)
  2378. for (int m = 1; m <= 9; ++m)
  2379. {
  2380. const auto hz = dec * m;
  2381. if (hz < 20.0 || hz > 20000.0) continue;
  2382. const auto x = xOf (hz);
  2383. const auto major = m == 1 || m == 2 || m == 5;
  2384. g.setColour (juce::Colours::white.withAlpha (major ? 0.05f : 0.022f));
  2385. g.drawVerticalLine ((int) x, plot.getY(), plot.getBottom());
  2386. if (major)
  2387. {
  2388. g.setColour (colour::textDisabled);
  2389. g.drawText (hz >= 1000.0 ? juce::String ((int) (hz / 1000.0)) + "k" : juce::String ((int) hz),
  2390. juce::Rectangle<float> (x - 20.0f * s, plot.getBottom() + 3.0f * s, 40.0f * s, 14.0f * s), juce::Justification::centred, false);
  2391. }
  2392. }
  2393. // the rate grid: an octave a line, labelled on the left
  2394. for (int o = 1; o >= -3; --o)
  2395. {
  2396. const auto y = yOf (std::pow (2.0, o));
  2397. g.setColour (juce::Colours::white.withAlpha (0.05f));
  2398. g.drawHorizontalLine ((int) y, plot.getX(), plot.getRight());
  2399. g.setColour (blue.withAlpha (0.85f));
  2400. g.drawText (juce::String ((int) std::lround (100.0 * std::pow (2.0, o))) + "%", juce::Rectangle<float> (r.getX() + 2.0f * s, y - 7.0f * s, 38.0f * s, 14.0f * s),
  2401. juce::Justification::centredLeft, false);
  2402. }
  2403. g.setColour (blue);
  2404. g.setFont (font (juce::jmax (8.0f, 11.0f * s)));
  2405. g.drawText (tr ("Decay EQ"), juce::Rectangle<float> (r.getX() + 2.0f * s, r.getY() + 2.0f * s, 200.0f * s, 16.0f * s), juce::Justification::centredLeft, false);
  2406. // the curve: the rate, times a smooth shelf to the low multiplier under the low frequency and to the high one over
  2407. // the high frequency (half an octave of transition)
  2408. const auto rate = sp::rateOf (at (sp::rate));
  2409. const auto lowMult = sp::multOf (at (sp::lowMult)), highMult = sp::multOf (at (sp::highMult));
  2410. const auto lowHz = sp::lowHz (at (sp::lowFreq)), highHz = sp::highHz (at (sp::highFreq));
  2411. const auto shelf = [] (double hz, double corner, double mult, bool below) {
  2412. const auto o = std::log2 (hz / corner) * (below ? -1.0 : 1.0);
  2413. const auto w = 1.0 / (1.0 + std::exp (-o * 4.0));
  2414. return std::pow (mult, w);
  2415. };
  2416. juce::Path curve;
  2417. const auto steps = juce::jmax (64, (int) (plot.getWidth() / (3.0f * s)));
  2418. for (int i = 0; i <= steps; ++i)
  2419. {
  2420. const auto hz = std::exp (lo + (hi - lo) * (double) i / (double) steps);
  2421. const auto y = yOf (rate * shelf (hz, lowHz, lowMult, true) * shelf (hz, highHz, highMult, false));
  2422. const auto x = plot.getX() + plot.getWidth() * (float) i / (float) steps;
  2423. if (i == 0) curve.startNewSubPath (x, y);
  2424. else curve.lineTo (x, y);
  2425. }
  2426. auto fill = curve;
  2427. fill.lineTo (plot.getRight(), plot.getBottom());
  2428. fill.lineTo (plot.getX(), plot.getBottom());
  2429. fill.closeSubPath();
  2430. const auto line = fx.enabled ? blue : colour::textDisabled;
  2431. g.setGradientFill (juce::ColourGradient (line.withAlpha (0.10f), 0.0f, plot.getY(), line.withAlpha (0.0f), 0.0f, plot.getBottom(), false));
  2432. g.fillPath (fill);
  2433. g.setColour (line);
  2434. g.strokePath (curve, juce::PathStrokeType (juce::jmax (1.2f, 1.5f * s)));
  2435. // the two corner frequencies, as handles on the curve
  2436. for (const auto hz : { lowHz, highHz })
  2437. {
  2438. const auto x = xOf (hz);
  2439. const auto y = yOf (rate * shelf (hz, lowHz, lowMult, true) * shelf (hz, highHz, highMult, false));
  2440. g.setColour (line.withAlpha (0.25f));
  2441. g.fillEllipse (juce::Rectangle<float> (14.0f * s, 14.0f * s).withCentre ({ x, y }));
  2442. g.setColour (line);
  2443. g.drawEllipse (juce::Rectangle<float> (9.0f * s, 9.0f * s).withCentre ({ x, y }), 1.4f);
  2444. }
  2445. }
  2446. void paintDisplay (juce::Graphics& g, const LayoutItem& item, juce::Rectangle<float> r, const EffectSlot& fx)
  2447. {
  2448. using namespace theme;
  2449. const auto s = scale();
  2450. const juce::String id (item.display != nullptr ? item.display : "");
  2451. if (id != "faderscale" && id != "decayeq" && id != "pitchport") // round 137: the fader scale is bare text beside its fader (tp172b4: the decay EQ lies on the field)
  2452. skin::well (g, r, radius::md * s, fx.enabled ? accent : juce::Colours::transparentBlack);
  2453. const auto curveColour = fx.enabled ? accent : colour::textDisabled;
  2454. const auto inner = r.reduced (6.0f * s);
  2455. if (dynui::paint (g, id, r, s, fx, [this] (int k) { return liveMeter (k); }, dynHistory)) // the dynamics suite
  2456. return;
  2457. if (designui::paint (g, id, r, s, fx, accent, designHistory, demoDisplays, item.param)) // round 168r
  2458. return;
  2459. if (id == "tssenvelope")
  2460. {
  2461. paintTransmitterEnvelope (g, inner, fx);
  2462. return;
  2463. }
  2464. if (id == "pitchport") // round 190ez: Pitcher's bottom line, FL's "MIDI Input Port Number: ..." ("..." = none)
  2465. {
  2466. const auto port = effectMidiInPort (fx);
  2467. const juce::Font f (theme::font (juce::jmax (8.0f, 11.0f * scale())));
  2468. const auto caption = tr ("MIDI Input Port Number:");
  2469. const auto w = juce::GlyphArrangement::getStringWidth (f, caption) + 6.0f * scale();
  2470. g.setFont (f);
  2471. g.setColour (theme::colour::textSecondary);
  2472. g.drawText (caption, r.withWidth (w).toNearestInt(), juce::Justification::centredLeft, false);
  2473. g.setFont (theme::font (juce::jmax (8.0f, 11.0f * scale()), true));
  2474. g.setColour (fx.enabled ? theme::colour::textPrimary : theme::colour::textDisabled);
  2475. g.drawText (port >= 0 ? juce::String (port) : juce::String ("..."), r.withTrimmedLeft (w).toNearestInt(), juce::Justification::centredLeft, false);
  2476. return;
  2477. }
  2478. if (id == "equosend") // FL's send track box: "---" (none) or the insert's number, with its up / down marks
  2479. {
  2480. const auto t = fx.sendTracks[0];
  2481. g.setColour (theme::colour::bg0.withAlpha (0.35f));
  2482. g.fillRect (r);
  2483. g.setColour (t > 0 ? theme::colour::textPrimary : theme::colour::textSecondary);
  2484. g.setFont (theme::font (juce::jmax (8.0f, 10.0f * scale())));
  2485. g.drawText (t > 0 ? juce::String (t) : juce::String ("---"), r.withTrimmedRight (9.0f * scale()).toNearestInt(), juce::Justification::centredRight, false);
  2486. const auto ar = r.removeFromRight (9.0f * scale()).reduced (1.5f * scale(), r.getHeight() * 0.22f);
  2487. juce::Path up, down;
  2488. up.addTriangle (ar.getX(), ar.getCentreY() - 1.0f, ar.getRight(), ar.getCentreY() - 1.0f, ar.getCentreX(), ar.getY());
  2489. down.addTriangle (ar.getX(), ar.getCentreY() + 1.0f, ar.getRight(), ar.getCentreY() + 1.0f, ar.getCentreX(), ar.getBottom());
  2490. g.fillPath (up);
  2491. g.fillPath (down);
  2492. return;
  2493. }
  2494. if (id == "tsssend0" || id == "tsssend1")
  2495. {
  2496. paintTransmitterSend (g, r, fx, id == "tsssend0" ? 0 : 1);
  2497. return;
  2498. }
  2499. auto grid = [&] (int columns, int rows) {
  2500. g.setColour (colour::gridBeat);
  2501. for (int i = 1; i < columns; ++i)
  2502. g.drawVerticalLine ((int) (inner.getX() + inner.getWidth() * (float) i / (float) columns), inner.getY(), inner.getBottom());
  2503. for (int i = 1; i < rows; ++i)
  2504. g.drawHorizontalLine ((int) (inner.getY() + inner.getHeight() * (float) i / (float) rows), inner.getX(), inner.getRight());
  2505. };
  2506. auto strokeCurve = [&] (const std::function<float (float)>& f, juce::Rectangle<float> area, bool fillBelow) {
  2507. juce::Path p;
  2508. const auto steps = juce::jmax (16, (int) area.getWidth() / 2);
  2509. for (int i = 0; i <= steps; ++i)
  2510. {
  2511. const auto x = (float) i / (float) steps;
  2512. const auto y = juce::jlimit (0.0f, 1.0f, f (x));
  2513. const juce::Point<float> pt { area.getX() + area.getWidth() * x, area.getBottom() - area.getHeight() * y };
  2514. if (i == 0)
  2515. p.startNewSubPath (pt);
  2516. else
  2517. p.lineTo (pt);
  2518. }
  2519. if (fillBelow)
  2520. {
  2521. auto fill = p;
  2522. fill.lineTo (area.getRight(), area.getBottom());
  2523. fill.lineTo (area.getX(), area.getBottom());
  2524. fill.closeSubPath();
  2525. g.setGradientFill (juce::ColourGradient (curveColour.withAlpha (0.28f), 0.0f, area.getY(), curveColour.withAlpha (0.02f), 0.0f, area.getBottom(), false));
  2526. g.fillPath (fill);
  2527. }
  2528. skin::glowStroke (g, p, curveColour, juce::jmax (1.5f, 2.0f * s), fx.enabled ? 1.0f : 0.0f);
  2529. };
  2530. if (id == "limiter" || id == "compressor" || id == "dynamics")
  2531. {
  2532. // static transfer curve: input level (x, −60…0 dB) to output level (y)
  2533. grid (6, 4);
  2534. const auto threshold01 = id == "limiter" ? param01 ("Ceiling") : param01 (id == "compressor" ? "Threshold" : "Comp. threshold");
  2535. const auto ratio01 = id == "limiter" ? 1.0f : param01 ("Ratio");
  2536. const auto t = juce::jlimit (0.05f, 1.0f, threshold01);
  2537. const auto ratio = 1.0f + ratio01 * 19.0f;
  2538. strokeCurve ([t, ratio] (float x) { return x <= t ? x : t + (x - t) / ratio; }, inner, true);
  2539. g.setColour (colour::gridBar);
  2540. g.drawHorizontalLine ((int) (inner.getBottom() - inner.getHeight() * t), inner.getX(), inner.getRight());
  2541. // round 170c (the "shell" audit: FL's display is live, this one was a still picture): the signal's
  2542. // input → output peaks of the last ~1.5 s as a fading trail of dots on the curve's axes (−60 … 0 dB)
  2543. if (! node.locate)
  2544. for (int k = 0; k < (int) levelTrail.size(); ++k)
  2545. {
  2546. const auto& [inDb, outDb] = levelTrail[(std::size_t) ((levelTrailAt + k) % (int) levelTrail.size())];
  2547. if (inDb <= -59.5f) continue;
  2548. const auto x = juce::jlimit (0.0f, 1.0f, (inDb + 60.0f) / 60.0f), y = juce::jlimit (0.0f, 1.0f, (outDb + 60.0f) / 60.0f);
  2549. const auto age = (float) (k + 1) / (float) levelTrail.size(); // 1 = newest
  2550. const auto d = (k == (int) levelTrail.size() - 1 ? 7.0f : 3.0f) * s;
  2551. g.setColour ((k == (int) levelTrail.size() - 1 ? colour::textPrimary : curveColour).withAlpha (0.15f + 0.85f * age * age));
  2552. g.fillEllipse (juce::Rectangle<float> (d, d).withCentre ({ inner.getX() + inner.getWidth() * x, inner.getBottom() - inner.getHeight() * y }));
  2553. }
  2554. }
  2555. else if (id == "shaper") // the feedback saturation: drive from the level, knee and symmetry
  2556. {
  2557. grid (4, 4);
  2558. const auto drive = 1.0f + 5.0f * param01 (item.param != nullptr ? item.param : "Distortion");
  2559. const auto knee = 0.5f + 3.0f * param01 ("Hardness");
  2560. const auto bias = (param01 ("Symmetry") - 0.5f) * 0.6f;
  2561. strokeCurve ([drive, knee, bias] (float x) {
  2562. const auto u = (x * 2.0f - 1.0f) * drive + bias;
  2563. const auto y = u / std::pow (1.0f + std::pow (std::abs (u), knee * 2.0f), 1.0f / (knee * 2.0f));
  2564. return 0.5f + 0.5f * y;
  2565. }, inner, false);
  2566. }
  2567. else if (id == "multiband")
  2568. {
  2569. // the three bands between the crossovers
  2570. grid (8, 4);
  2571. const auto low = param01 ("Low crossover"), high = param01 ("High crossover");
  2572. const juce::Colour bandColours[] = { peqview::bandColour (0), peqview::bandColour (2), peqview::bandColour (5) };
  2573. const float edges[] = { 0.0f, juce::jlimit (0.05f, 0.95f, low), juce::jlimit (0.05f, 0.95f, juce::jmax (low + 0.02f, high)), 1.0f };
  2574. for (int b = 0; b < 3; ++b)
  2575. {
  2576. const auto band = juce::Rectangle<float> (inner.getX() + inner.getWidth() * edges[b], inner.getY() + inner.getHeight() * 0.35f,
  2577. inner.getWidth() * (edges[b + 1] - edges[b]), inner.getHeight() * 0.65f);
  2578. g.setColour (bandColours[b].withAlpha (fx.enabled ? 0.18f : 0.06f));
  2579. g.fillRect (band);
  2580. g.setColour (bandColours[b].withAlpha (fx.enabled ? 0.9f : 0.3f));
  2581. g.drawHorizontalLine ((int) band.getY(), band.getX(), band.getRight());
  2582. }
  2583. }
  2584. else if (id == "decayeq") // round tp172b4: LuxeVerb's Space engine — the decay time across the spectrum
  2585. {
  2586. paintDecayEq (g, r, fx);
  2587. return;
  2588. }
  2589. else if (id == "envelope") // decay shape of a reverb / delay tail
  2590. {
  2591. grid (8, 4);
  2592. const auto decay = 0.15f + param01 (item.param != nullptr ? item.param : "Decay") * 3.0f;
  2593. strokeCurve ([decay] (float x) { return std::exp (-x * 4.0f / decay) * 0.9f; }, inner, true);
  2594. }
  2595. else if (id == "meter") // level meter well: the slot's live input and output peaks (round 170c; before: an empty grid)
  2596. {
  2597. g.setColour (colour::gridBeat);
  2598. for (int i = 1; i < 12; ++i)
  2599. g.drawHorizontalLine ((int) (r.getY() + r.getHeight() * (float) i / 12.0f), r.getX() + 2.0f, r.getRight() - 2.0f);
  2600. const auto to01 = [] (float db) { return juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f); };
  2601. const auto vertical = r.getHeight() >= r.getWidth();
  2602. auto area = r.reduced (3.0f);
  2603. const auto gap = 2.0f;
  2604. for (int k = 0; k < 2; ++k)
  2605. {
  2606. const auto bar = vertical ? juce::Rectangle<float> (area.getX() + (area.getWidth() + gap) * 0.5f * (float) k, area.getY(), (area.getWidth() - gap) * 0.5f, area.getHeight())
  2607. : juce::Rectangle<float> (area.getX(), area.getY() + (area.getHeight() + gap) * 0.5f * (float) k, area.getWidth(), (area.getHeight() - gap) * 0.5f);
  2608. skin::meter (g, bar, to01 (levelDb[(std::size_t) k]), to01 (levelHoldDb[(std::size_t) k]), vertical);
  2609. }
  2610. }
  2611. else if (id == "clip") // hard / soft clipping at the threshold
  2612. {
  2613. grid (4, 4);
  2614. const auto t = juce::jlimit (0.02f, 1.0f, param01 (item.param != nullptr ? item.param : "Threshold"));
  2615. const auto soft = param01 ("Type") >= 0.5f;
  2616. const auto pre = 1.0f + 30.0f * param01 ("Pre amp") * param01 ("Pre amp");
  2617. const auto post = 0.25f + 0.75f * param01 ("Post gain");
  2618. strokeCurve ([t, soft, pre, post] (float x) {
  2619. const auto u = x * pre;
  2620. return post * (soft ? t * std::tanh (u / t) : juce::jmin (u, t));
  2621. }, inner, false);
  2622. }
  2623. else if (id == "softclip") // linear up to the threshold, then a soft knee into the ceiling
  2624. {
  2625. grid (4, 4);
  2626. const auto t = juce::jlimit (0.05f, 0.98f, 0.3f + 0.7f * param01 ("Threshold"));
  2627. const auto post = 0.4f + 0.6f * param01 ("Post");
  2628. strokeCurve ([t, post] (float x) {
  2629. const auto y = x <= t ? x : t + (1.0f - t) * std::tanh ((x - t) / (1.0f - t));
  2630. return y * post;
  2631. }, inner, false);
  2632. }
  2633. else if (id == "sgamount" || id == "sgpresets")
  2634. {
  2635. paintSoundgoodizer (g, id, r, fx);
  2636. return;
  2637. }
  2638. else if (id == "geminipan") // Gemini Doubler: where the voices and the direct signal sit (half circle, gain = radius)
  2639. {
  2640. using namespace voicetools::gemini;
  2641. const auto c = juce::Point<float> (inner.getCentreX(), inner.getBottom() - 4.0f * s);
  2642. const auto radius = juce::jmin (inner.getWidth() * 0.5f, inner.getHeight()) - 8.0f * s;
  2643. g.setColour (colour::gridBeat);
  2644. for (int k = 1; k <= 3; ++k)
  2645. {
  2646. juce::Path arc;
  2647. arc.addCentredArc (c.x, c.y, radius * (float) k / 3.0f, radius * (float) k / 3.0f, 0.0f, -juce::MathConstants<float>::halfPi, juce::MathConstants<float>::halfPi, true);
  2648. g.strokePath (arc, juce::PathStrokeType (1.0f));
  2649. }
  2650. for (const auto deg : { -45.0f, 45.0f })
  2651. {
  2652. const auto a = juce::degreesToRadians (deg);
  2653. g.drawLine (c.x, c.y, c.x + radius * std::sin (a), c.y - radius * std::cos (a), 1.0f);
  2654. }
  2655. // gain −48 … 0 dB → radius 0 … 1; the dot's angle is its pan (±45° = the hard sides)
  2656. auto dot = [&] (float pan01, float gain01, bool active, juce::Colour col, const juce::String& text) {
  2657. const auto a = juce::degreesToRadians ((float) panDegrees (pan01)); // ±45° = the diagonals
  2658. const auto rr = radius * juce::jlimit (0.05f, 1.0f, gain01);
  2659. const auto pt = juce::Point<float> (c.x + rr * std::sin (a), c.y - rr * std::cos (a));
  2660. g.setColour (active ? col : colour::textDisabled);
  2661. g.fillEllipse (juce::Rectangle<float> (14.0f * s, 14.0f * s).withCentre (pt));
  2662. g.setColour (colour::bg0);
  2663. g.setFont (font (9.0f * s, true));
  2664. g.drawText (text, juce::Rectangle<float> (14.0f * s, 14.0f * s).withCentre (pt), juce::Justification::centred, false);
  2665. };
  2666. dot (param01 ("Direct pan"), param01 ("Direct gain"), param01 ("Direct") >= 0.5f, colour::textPrimary, "D");
  2667. dot (param01 ("V1 pan"), param01 ("V1 gain"), param01 ("V1 on") >= 0.5f, curveColour, "1");
  2668. dot (param01 ("V2 pan"), param01 ("V2 gain"), param01 ("V2 on") >= 0.5f, curveColour.withRotatedHue (0.12f), "2");
  2669. // round 135w: voices 3 and 4 (shown when on)
  2670. if (param01 ("V3 on") >= 0.5f)
  2671. dot (param01 ("V3 pan"), param01 ("V3 gain"), true, curveColour.withRotatedHue (0.24f), "3");
  2672. if (param01 ("V4 on") >= 0.5f)
  2673. dot (param01 ("V4 pan"), param01 ("V4 gain"), true, curveColour.withRotatedHue (0.36f), "4");
  2674. }
  2675. else if (id == "geminimap") // Gemini Doubler: each voice's delay (across, 0 … 100 ms) against its detune (up, ±100 c)
  2676. {
  2677. grid (5, 4);
  2678. g.setColour (colour::gridBar);
  2679. g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
  2680. g.setColour (colour::textSecondary);
  2681. g.setFont (font (8.5f * s));
  2682. for (int k = 0; k <= 5; ++k)
  2683. g.drawText (juce::String (k * 20), juce::Rectangle<float> (inner.getX() + inner.getWidth() * (float) k / 5.0f - 12.0f * s, inner.getBottom() - 11.0f * s, 24.0f * s, 10.0f * s),
  2684. juce::Justification::centred, false);
  2685. // round 137: the detune scale up the left side (+100 / 0 / −100 cents)
  2686. static const std::pair<float, const char*> centsMarks[] { { 0.0f, "+100" }, { 0.5f, "0" }, { 1.0f, "-100" } };
  2687. for (const auto& [frac, text] : centsMarks)
  2688. g.drawText (text, juce::Rectangle<float> (inner.getX() + 1.0f * s, inner.getY() + inner.getHeight() * frac - (frac > 0.9f ? 22.0f : frac > 0.1f ? 5.0f : 0.0f) * s, 30.0f * s, 10.0f * s),
  2689. juce::Justification::centredLeft, false);
  2690. for (int k = 0; k < 4; ++k) // round 135w: four voices (3 and 4 only when on)
  2691. {
  2692. const juce::String pre = "V" + juce::String (k + 1) + " ";
  2693. if (k >= 2 && param01 ((pre + "on").toRawUTF8()) < 0.5f)
  2694. continue;
  2695. const auto x = inner.getX() + inner.getWidth() * param01 ((pre + "delay").toRawUTF8());
  2696. const auto y = inner.getBottom() - inner.getHeight() * param01 ((pre + "detune").toRawUTF8());
  2697. const auto col = curveColour.withRotatedHue (0.12f * (float) k);
  2698. g.setColour ((param01 ((pre + "on").toRawUTF8()) >= 0.5f ? col : colour::textDisabled));
  2699. // the LFO's reach on the pitch as a bar through the dot
  2700. const auto depth = std::abs (param01 ((pre + "depth").toRawUTF8()) - 0.5f) * 2.0f * inner.getHeight();
  2701. if (depth > 1.0f)
  2702. g.fillRect (juce::Rectangle<float> (3.0f * s, depth).withCentre ({ x, y }));
  2703. g.fillEllipse (juce::Rectangle<float> (12.0f * s, 12.0f * s).withCentre ({ x, y }));
  2704. }
  2705. }
  2706. else if (id == "geminieq") // Gemini Doubler: the voices' low / high shelves
  2707. {
  2708. using namespace voicetools::gemini;
  2709. grid (4, 4);
  2710. const bool lo = param01 ("Low shelf") >= 0.5f, hi = param01 ("High shelf") >= 0.5f;
  2711. // round 165w: the law's range over the height (measured: −88 … +12 dB; round 124's: −30 … +12) and its shapes
  2712. const bool measured = param01 ("EQ law") >= 0.5f;
  2713. const auto floorDb = measured ? -88.0 : -30.0, spanDb = measured ? 100.0 : 42.0;
  2714. const auto lg = lo ? shelfDb (param01 ("Low gain"), measured) : 0.0, hg = hi ? shelfDb (param01 ("High gain"), measured) : 0.0;
  2715. const auto lf = freqHz (param01 ("Low freq")), hf = freqHz (param01 ("High freq"));
  2716. strokeCurve ([=] (float x) {
  2717. const auto f = 20.0 * std::pow (1000.0, (double) x);
  2718. const auto db = shelfResponseDb (f, lf, lg, false, measured) + shelfResponseDb (f, hf, hg, true, measured);
  2719. return (float) std::clamp ((db - floorDb) / spanDb, 0.0, 1.0);
  2720. }, inner, true);
  2721. // round 137: the L / H markers (drag: frequency / gain; double-click: on / off) and the frequency labels
  2722. g.setFont (font (8.5f * s));
  2723. g.setColour (colour::textSecondary);
  2724. static const std::pair<double, const char*> freqMarks[] { { 62.0, "62" }, { 250.0, "250" }, { 1000.0, "1K" }, { 4000.0, "4K" } };
  2725. for (const auto& [hz, text] : freqMarks)
  2726. {
  2727. const auto x = inner.getX() + inner.getWidth() * (float) (std::log (hz / 20.0) / std::log (1000.0));
  2728. g.drawText (text, juce::Rectangle<float> (x - 12.0f * s, inner.getBottom() - 11.0f * s, 24.0f * s, 10.0f * s), juce::Justification::centred, false);
  2729. }
  2730. const auto zero = inner.getBottom() - inner.getHeight() * (float) (-floorDb / spanDb);
  2731. g.drawText ("0", juce::Rectangle<float> (inner.getX() + 1.0f * s, zero - 5.0f * s, 14.0f * s, 10.0f * s), juce::Justification::centredLeft, false);
  2732. for (const auto& h : geminiHandles (item))
  2733. {
  2734. const bool isLow = h.on == lowOn, onNow = valueOf (h.on) >= 0.5f;
  2735. const auto box = juce::Rectangle<float> (14.0f * s, 14.0f * s).withCentre (h.at);
  2736. g.setColour (onNow ? curveColour : colour::textDisabled);
  2737. g.fillEllipse (box);
  2738. g.setColour (colour::bg0);
  2739. g.setFont (font (9.0f * s, true));
  2740. g.drawText (isLow ? "L" : "H", box, juce::Justification::centred, false);
  2741. }
  2742. }
  2743. else if (id == "xy") // a pad: `param` across, `param2` up (drag the point)
  2744. {
  2745. grid (4, 4);
  2746. const auto x = inner.getX() + inner.getWidth() * param01 (item.param);
  2747. const auto y = inner.getBottom() - inner.getHeight() * param01 (item.param2);
  2748. g.setColour (curveColour);
  2749. g.drawEllipse (juce::Rectangle<float> (10.0f * s, 10.0f * s).withCentre ({ x, y }), juce::jmax (1.5f, 2.0f * s));
  2750. }
  2751. else if (id == "voices") // the chorus voices spread across the stereo field (a static picture)
  2752. {
  2753. g.setColour (colour::gridBeat);
  2754. g.drawVerticalLine ((int) inner.getCentreX(), inner.getY(), inner.getBottom());
  2755. const auto spread = 0.2f + 0.8f * param01 ("Movement");
  2756. for (int i = 0; i < 8; ++i)
  2757. {
  2758. const auto t = (float) i / 7.0f;
  2759. const auto x = inner.getCentreX() + (t - 0.5f) * inner.getWidth() * spread;
  2760. g.setColour (curveColour.withAlpha (0.35f + 0.5f * (1.0f - std::abs (t - 0.5f))));
  2761. g.fillRoundedRectangle (juce::Rectangle<float> (3.0f * s, inner.getHeight() * (0.3f + 0.4f * std::abs (std::sin ((float) i * 1.7f)))).withCentre ({ x, inner.getCentreY() }), 1.5f);
  2762. }
  2763. }
  2764. else if (id == "panpad") // pan (x) and volume (y) as a crosshair
  2765. {
  2766. grid (6, 6);
  2767. const auto x = inner.getX() + inner.getWidth() * param01 ("Pan");
  2768. const auto y = inner.getBottom() - inner.getHeight() * param01 ("Volume");
  2769. g.setColour (curveColour);
  2770. g.drawVerticalLine ((int) x, inner.getY(), inner.getBottom());
  2771. g.drawHorizontalLine ((int) y, inner.getX(), inner.getRight());
  2772. g.fillEllipse (juce::Rectangle<float> (7.0f * s, 7.0f * s).withCentre ({ x, y }));
  2773. }
  2774. else if (id == "waveshaper") // round 165: FL's point editor (the map: input across, level up)
  2775. {
  2776. grid (8, 8);
  2777. g.setColour (colour::gridBar);
  2778. g.drawLine ({ inner.getBottomLeft(), inner.getTopRight() }, 1.0f); // the identity, for reference
  2779. const auto ws = wsState();
  2780. const auto& table = wsTable (ws.points, wsUnipolar());
  2781. strokeCurve ([&table, uni = wsUnipolar()] (float x) { return flshape::waveShaperLevelAt (table, uni, x); }, inner, false);
  2782. const auto times = flshape::waveShaperTimes (ws.points);
  2783. // tension handles (hollow, between the points), then the points
  2784. for (std::size_t i = 1; i < ws.points.size(); ++i)
  2785. if (const auto h = wsHandlePos (inner, ws, times, (int) i); h.x > -1.0f)
  2786. {
  2787. const auto hot = (int) i == wsHoverHandle || (int) i == wsTension;
  2788. g.setColour (hot ? colour::textPrimary : curveColour.withAlpha (0.85f));
  2789. g.drawEllipse (juce::Rectangle<float> (8.0f * s, 8.0f * s).withCentre (h), juce::jmax (1.0f, 1.3f * s));
  2790. }
  2791. for (std::size_t i = 0; i < ws.points.size(); ++i)
  2792. {
  2793. const auto at = wsPos (inner, times[i], ws.points[i].y);
  2794. const auto hot = (int) i == wsHoverPoint || (int) i == wsPoint;
  2795. g.setColour (colour::bg0);
  2796. g.fillEllipse (juce::Rectangle<float> (11.0f * s, 11.0f * s).withCentre (at));
  2797. g.setColour (hot ? colour::textPrimary : curveColour);
  2798. g.fillEllipse (juce::Rectangle<float> (7.0f * s, 7.0f * s).withCentre (at));
  2799. }
  2800. }
  2801. else if (id == "room") // nested walls: the room size and the decay
  2802. {
  2803. const auto size = 0.25f + 0.7f * param01 (item.param != nullptr ? item.param : "Room size");
  2804. const auto c = inner.getCentre();
  2805. for (int i = 0; i < 6; ++i)
  2806. {
  2807. const auto k = size * (1.0f - 0.14f * (float) i);
  2808. const auto box = juce::Rectangle<float> (inner.getWidth() * k, inner.getHeight() * k * 0.8f).withCentre (c);
  2809. g.setColour (curveColour.withAlpha (0.75f - 0.11f * (float) i));
  2810. g.drawRoundedRectangle (box, 4.0f * s, juce::jmax (1.0f, 1.5f * s));
  2811. }
  2812. }
  2813. else if (id == "maxcurve") // Maximus: the selected band's compression curve, edited with FL's gestures (round 168x)
  2814. paintMaximusCurve (g, inner, fx);
  2815. else if (id == "lpcurve" || id == "cvcurve" || id == "vxcurve") // Love Philter's articulators, Convolver's EQ, Vocodex's maps (round 173d3)
  2816. paintPhilterCurve (g, inner, fx);
  2817. else if (id == "vxmapsel") // Vocodex: the map shown (round 173d3)
  2818. paintVxMapSelector (g, r);
  2819. else if (id == "maxbands") // Maximus: the three bands over 20 Hz…20 kHz with their crossovers and the low cut
  2820. {
  2821. const auto raw = [&] (int p) { return maximusfx::stateParam (fx.state, p).value_or (maximusfx::stateParams()[(std::size_t) p].defaultValue); };
  2822. const auto xOf = [&] (double hz) { return inner.getX() + inner.getWidth() * (float) (std::log (juce::jlimit (20.0, 20000.0, hz) / 20.0) / std::log (1000.0)); };
  2823. auto lo = 30.0 * std::pow (533.33, raw (0) / 65536.0), hi = 30.0 * std::pow (533.33, raw (2) / 65536.0);
  2824. if (lo > hi)
  2825. std::swap (lo, hi);
  2826. const float edges[4] { inner.getX(), xOf (lo), xOf (hi), inner.getRight() };
  2827. static const char* names[3] { "Low", "Mid", "High" };
  2828. for (int b = 0; b < 3; ++b)
  2829. {
  2830. const auto mode = raw (7 + 13 * b);
  2831. const auto area = juce::Rectangle<float> (edges[b], inner.getY(), edges[b + 1] - edges[b], inner.getHeight());
  2832. const auto c = peqview::bandColour (b);
  2833. g.setColour (c.withAlpha (! fx.enabled || mode >= 2 ? 0.05f : (b == page ? 0.24f : 0.12f)));
  2834. g.fillRect (area);
  2835. g.setColour (b == page ? colour::textPrimary : colour::textSecondary);
  2836. g.setFont (font (juce::jmax (8.0f, 10.0f * s), true));
  2837. g.drawFittedText (caps (tr (names[b])) + (mode == 2 ? " · " + tr ("Muted") : mode == 3 ? " · " + tr ("Off") : juce::String()),
  2838. area.reduced (2.0f * s).withHeight (14.0f * s).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  2839. }
  2840. g.setColour (colour::textSecondary);
  2841. for (int k = 1; k <= 2; ++k)
  2842. g.drawVerticalLine ((int) edges[k], inner.getY(), inner.getBottom());
  2843. if (raw (6) >= 0) // low cut
  2844. {
  2845. const auto x = xOf (5.0 * std::pow (16.0, raw (6) / 65536.0));
  2846. g.setColour (accent.withAlpha (0.6f));
  2847. g.drawVerticalLine ((int) x, inner.getY(), inner.getBottom());
  2848. }
  2849. g.setColour (colour::textDisabled);
  2850. g.setFont (font (juce::jmax (8.0f, 9.0f * s)));
  2851. for (const auto hz : { 100.0, 1000.0, 10000.0 })
  2852. g.drawText (hz >= 1000.0 ? juce::String ((int) (hz / 1000.0)) + "k" : juce::String ((int) hz),
  2853. juce::Rectangle<float> (30.0f * s, 12.0f * s).withCentre ({ xOf (hz), inner.getBottom() - 6.0f * s }).toNearestInt(),
  2854. juce::Justification::centred, false);
  2855. }
  2856. else if (id == "eq")
  2857. {
  2858. paintEq (g, r, fx);
  2859. return;
  2860. }
  2861. else if (id == "grossbeat" || id.startsWith ("gb"))
  2862. {
  2863. paintGrossBeat (g, id, r, fx, item);
  2864. return;
  2865. }
  2866. else if (id == "eqinfo") // the selected band, or how to use the graph
  2867. {
  2868. g.setColour (colour::bg1);
  2869. g.fillRect (r);
  2870. g.setFont (font (juce::jmax (9.0f, 11.0f * s)));
  2871. if (eqSelected >= 0)
  2872. {
  2873. g.setColour (peqview::bandColour (eqSelected));
  2874. g.drawFittedText (peqview::bandText (fx.params, eqSelected), r.reduced (4.0f * s, 0.0f).toNearestInt(), juce::Justification::centredLeft, 2, 0.8f);
  2875. }
  2876. else
  2877. {
  2878. g.setColour (colour::textSecondary);
  2879. g.drawFittedText (tr ("Drag a handle (frequency and gain); mouse wheel = Q; right-click = type; double-click = 0 dB"),
  2880. r.reduced (4.0f * s, 0.0f).toNearestInt(), juce::Justification::centredLeft, 2, 0.8f);
  2881. }
  2882. return;
  2883. }
  2884. else if (id == "filter")
  2885. {
  2886. grid (8, 4);
  2887. const auto cutoff = param01 ("Cutoff");
  2888. const auto reso = param01 ("Resonance");
  2889. strokeCurve ([cutoff, reso] (float x) {
  2890. const auto d = (x - cutoff) * 8.0f;
  2891. const auto bump = reso * 0.35f * std::exp (-d * d);
  2892. return 0.6f + bump - (x > cutoff ? (x - cutoff) * 2.2f : 0.0f);
  2893. }, inner, true);
  2894. }
  2895. else if (id == "pitchgraph") // LYNX Tune: detected pitch, target, correction and the scrolling pitch graph
  2896. {
  2897. paintPitchDisplay (g, r, fx);
  2898. return;
  2899. }
  2900. else if (id == "pitchtrace") // LYNX Tune (round 120): the scrolling pitch graph alone
  2901. {
  2902. paintPitchDisplay (g, r, fx, false);
  2903. return;
  2904. }
  2905. else if (id == "pitchring") // LYNX Tune (round 120): the correction meter
  2906. {
  2907. paintPitchRing (g, r, fx);
  2908. return;
  2909. }
  2910. else if (id == "tunekeys") // LYNX Tune (round 128): the keyboard with BYPASS / REMOVE and LATCH
  2911. {
  2912. paintTuneKeys (g, r, fx);
  2913. return;
  2914. }
  2915. else if (id == "tuneautokey") // LYNX Tune (round 128): AUTO KEY
  2916. {
  2917. paintAutoKey (g, r);
  2918. return;
  2919. }
  2920. else if (id == "hwping") // the hardware insert (round 164d): the round trip, the ping's state, what is missing
  2921. {
  2922. paintHwPing (g, r, fx);
  2923. return;
  2924. }
  2925. else if (id == "grleds") // round 165: a ladder of reduction LEDs (Ridge Strip: the console's 3 / 6 / 10 / 14 / 20 dB)
  2926. {
  2927. const auto db = juce::jlimit (0.0f, 1.0f, liveMeter (item.steps)) * 30.0f;
  2928. auto area = r.reduced (1.0f * s);
  2929. const auto caption = area.removeFromBottom (14.0f * s);
  2930. static const int steps[] { 20, 14, 10, 6, 3 };
  2931. const auto h = area.getHeight() / 5.0f;
  2932. g.setFont (font (juce::jmax (7.0f, 8.5f * s)));
  2933. for (int k = 0; k < 5; ++k)
  2934. {
  2935. const auto cell = juce::Rectangle<float> (area.getX(), area.getY() + h * (float) k, area.getWidth(), h);
  2936. // round tp172c: the LED keeps to the ladder's width (a tall ladder kept growing it over its numbers)
  2937. const auto d = juce::jmin (cell.getHeight() * 0.5f, cell.getWidth() * 0.34f);
  2938. const auto led = juce::Rectangle<float> (d, d).withCentre ({ cell.getX() + 2.0f * s + d * 0.5f, cell.getCentreY() });
  2939. const bool lit = fx.enabled && db >= (float) steps[k] - 0.05f;
  2940. g.setColour (lit ? accent : colour::gridBeat);
  2941. g.fillEllipse (led);
  2942. if (lit)
  2943. {
  2944. g.setColour (accent.withAlpha (0.35f));
  2945. g.drawEllipse (led.expanded (1.5f * s), 1.0f * s);
  2946. }
  2947. g.setColour (colour::textSecondary);
  2948. g.drawText (juce::String (steps[k]), cell.withTrimmedLeft (led.getRight() - cell.getX() + 2.0f * s), juce::Justification::centredLeft, false);
  2949. }
  2950. if (item.label != nullptr && *item.label != 0)
  2951. {
  2952. g.setColour (colour::textSecondary);
  2953. g.drawText (caps (tr (item.label)), caption, juce::Justification::centred, false);
  2954. }
  2955. return;
  2956. }
  2957. else if (id == "grmeter") // live gain reduction of the mixing suite (0..30 dB, from the right like a VU's GR)
  2958. {
  2959. const auto amount = juce::jlimit (0.0f, 1.0f, liveMeter (item.steps));
  2960. const auto bar = r.reduced (1.5f * s);
  2961. if (bar.getHeight() > 2.0f * bar.getWidth()) // a tall meter (Quell): the reduction grows downwards, 0 dB at the top
  2962. {
  2963. if (editorStyle() == skin::Style::themed && kind == EffectKind::quellDenoiser)
  2964. {
  2965. // round tp172d: the reference's meter — a dark recessed well, a thin soft light bar, the scale
  2966. // printed on both sides, the held reduction in a small orange read-out
  2967. const auto box = bar.withTrimmedBottom (22.0f * s);
  2968. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff2c3035), box.getX(), box.getY(), juce::Colour (0xff15171a), box.getX(), box.getBottom(), false));
  2969. g.fillRoundedRectangle (box, 6.0f * s);
  2970. g.setColour (juce::Colours::black.withAlpha (0.6f));
  2971. g.drawRoundedRectangle (box, 6.0f * s, 1.2f);
  2972. const auto well = box.reduced (box.getWidth() * 0.36f, 12.0f * s);
  2973. g.setColour (juce::Colour (0xff050607));
  2974. g.fillRoundedRectangle (well.expanded (3.0f * s), 3.0f * s);
  2975. g.setFont (font (juce::jmax (6.5f, 8.0f * s)));
  2976. for (int db = 0; db <= 30; db += 6)
  2977. {
  2978. const auto y = well.getY() + well.getHeight() * (float) db / 30.0f;
  2979. g.setColour (juce::Colour (0xffb9bec4));
  2980. g.drawHorizontalLine ((int) y, box.getX() + 4.0f * s, well.getX() - 6.0f * s);
  2981. g.drawHorizontalLine ((int) y, well.getRight() + 6.0f * s, box.getRight() - 4.0f * s);
  2982. g.drawText (juce::String (-db), juce::Rectangle<float> (box.getX() + 2.0f * s, y - 10.0f * s, well.getX() - box.getX() - 8.0f * s, 9.0f * s), juce::Justification::centredRight, false);
  2983. g.drawText (juce::String (-db), juce::Rectangle<float> (well.getRight() + 6.0f * s, y - 10.0f * s, box.getRight() - well.getRight() - 8.0f * s, 9.0f * s), juce::Justification::centredLeft, false);
  2984. }
  2985. const auto fill = well.reduced (well.getWidth() * 0.25f, 0.0f).withHeight (well.getHeight() * amount);
  2986. g.setGradientFill (juce::ColourGradient (juce::Colour (0xffe8ecef).withAlpha (fx.enabled ? 0.75f : 0.3f), fill.getX(), 0.0f, juce::Colour (0xff8a9096).withAlpha (fx.enabled ? 0.6f : 0.25f), fill.getRight(), 0.0f, false));
  2987. g.fillRect (fill);
  2988. grHold = juce::jmax (grHold, amount);
  2989. const auto readout = juce::Rectangle<float> (bar.getCentreX() - 22.0f * s, bar.getBottom() - 18.0f * s, 44.0f * s, 16.0f * s);
  2990. g.setColour (juce::Colour (0xff070809));
  2991. g.fillRoundedRectangle (readout, 3.0f * s);
  2992. g.setColour (skin::valueColour (false));
  2993. g.drawText (grHold > 0.0005f ? juce::String (-grHold * 30.0f, 1) : juce::String ("0.0"), readout, juce::Justification::centred, false);
  2994. return;
  2995. }
  2996. const auto well = bar.reduced (0.0f, 4.0f * s).withTrimmedBottom (14.0f * s);
  2997. g.setColour (colour::gridBeat);
  2998. g.setFont (font (8.5f * s));
  2999. for (int db = 0; db <= 30; db += 6)
  3000. {
  3001. const auto y = well.getY() + well.getHeight() * (float) db / 30.0f;
  3002. g.setColour (colour::gridBeat);
  3003. g.drawHorizontalLine ((int) y, well.getX(), well.getRight());
  3004. g.setColour (colour::textSecondary);
  3005. g.drawText (juce::String (-db), juce::Rectangle<float> (well.getX(), y - 10.0f * s, 22.0f * s, 10.0f * s), juce::Justification::centredLeft, false);
  3006. }
  3007. g.setColour ((fx.enabled ? accent : colour::textDisabled).withAlpha (0.85f));
  3008. g.fillRoundedRectangle (well.withTrimmedLeft (well.getWidth() * 0.35f).withHeight (well.getHeight() * amount), radius::sm);
  3009. // round 137: the read-out holds the deepest reduction (the reference's peak box; click the meter = reset)
  3010. grHold = juce::jmax (grHold, amount);
  3011. g.setColour (colour::textSecondary);
  3012. g.drawText ((grHold > 0.0005f ? juce::String (-grHold * 30.0f, 1) : juce::String ("0.0")) + " dB", bar.withTop (bar.getBottom() - 14.0f * s), juce::Justification::centred, false);
  3013. return;
  3014. }
  3015. g.setColour (colour::gridBeat);
  3016. for (int db = 3; db < 30; db += 3)
  3017. g.drawVerticalLine ((int) (bar.getRight() - bar.getWidth() * (float) db / 30.0f), bar.getY(), bar.getBottom());
  3018. g.setColour ((fx.enabled ? accent : colour::textDisabled).withAlpha (0.85f));
  3019. g.fillRoundedRectangle (bar.withLeft (bar.getRight() - bar.getWidth() * amount), radius::sm);
  3020. if (item.label != nullptr && *item.label != 0)
  3021. {
  3022. g.setColour (colour::textSecondary);
  3023. g.setFont (font (juce::jmax (7.0f, juce::jmin (10.0f * s, bar.getHeight() * 0.95f)), true));
  3024. g.drawText (caps (tr (item.label)) + " " + juce::String (amount * 30.0f, 1) + " dB", bar.reduced (3.0f * s, 0.0f),
  3025. juce::Justification::centredLeft, false);
  3026. }
  3027. return;
  3028. }
  3029. else if (id == "faderscale") // round 137: a 0 … 100 scale beside a tall fader (the reference prints it on both sides)
  3030. {
  3031. auto area = r.withTrimmedBottom (13.0f * s);
  3032. const auto top = area.getY() + 5.0f * s, bottom = area.getBottom() - 5.0f * s;
  3033. g.setFont (font (juce::jmax (7.0f, 8.5f * s)));
  3034. for (int k = 0; k <= 100; k += 10)
  3035. {
  3036. const auto y = bottom - (bottom - top) * (float) k / 100.0f;
  3037. const auto right = item.steps == 1; // round tp172d: the scale on the fader's right side, mirrored
  3038. g.setColour (colour::gridBeat);
  3039. if (right) g.drawHorizontalLine ((int) y, area.getX(), area.getX() + 6.0f * s);
  3040. else g.drawHorizontalLine ((int) y, area.getRight() - 6.0f * s, area.getRight());
  3041. g.setColour (skin::captionColour().getAlpha() > 0 && editorStyle() == skin::Style::themed ? skin::captionColour().withAlpha (0.75f) : colour::textSecondary);
  3042. g.drawText (juce::String (k), juce::Rectangle<float> (right ? area.getX() + 8.0f * s : area.getX(), y - 5.0f * s, area.getWidth() - 8.0f * s, 10.0f * s),
  3043. right ? juce::Justification::centredLeft : juce::Justification::centredRight, false);
  3044. }
  3045. return;
  3046. }
  3047. else if (id == "panpos") // round 135: where the panner has the sound now (the rhythmic panners' L … C … R strip)
  3048. {
  3049. const auto at = juce::jlimit (0.0f, 1.0f, liveMeter (1));
  3050. constexpr int segments = 29;
  3051. const auto area = r.reduced (2.0f * s);
  3052. g.setColour (colour::bg0);
  3053. g.fillRoundedRectangle (area, 3.0f * s);
  3054. const auto w = area.getWidth() / (float) segments;
  3055. for (int k = 0; k < segments; ++k)
  3056. {
  3057. const auto centre = ((float) k + 0.5f) / (float) segments;
  3058. const auto d = std::abs (centre - at) * (float) segments;
  3059. const auto glow = juce::jlimit (0.0f, 1.0f, 1.0f - d / 2.5f);
  3060. const auto cell = juce::Rectangle<float> (area.getX() + w * (float) k, area.getY(), w, area.getHeight()).reduced (1.0f * s, 3.0f * s);
  3061. g.setColour (accent.withAlpha (0.10f + 0.90f * glow * glow));
  3062. g.fillRoundedRectangle (cell, 1.5f * s);
  3063. }
  3064. g.setColour (colour::textSecondary.withAlpha (0.5f));
  3065. g.drawVerticalLine ((int) area.getCentreX(), area.getY(), area.getBottom());
  3066. return;
  3067. }
  3068. else if (id == "iometer") // round 129: input and output peak meters with peak holds and read-outs (−48 … 0 dBFS)
  3069. {
  3070. // the originals' level meters (SSL E-Channel's IN / OUT meter, RComp's input and output, Doubler's output)
  3071. const auto fracOf = [] (float linear) { return juce::jlimit (0.0f, 1.0f, (20.0f * std::log10 (juce::jmax (1e-6f, linear)) + 48.0f) / 48.0f); };
  3072. const auto base = item.steps > 0 ? item.steps : 2; // round 135w: the engine's meter outputs (LYNX Tune: 3 / 4)
  3073. const auto only = item.colour; // round tp172c7: 0 / 1 = the input or the output bar alone (Kiln's side columns)
  3074. if (only != 1) ioMeters[0].update (fracOf (liveMeter (base)), 0.02f);
  3075. if (only != 0) ioMeters[1].update (fracOf (liveMeter (base + 1)), 0.02f);
  3076. ioClip = ioClip || liveMeter (base + 1) >= 0.999f; // round 135w: the clip lamp (Doubler's), click to reset
  3077. const auto labelH = 13.0f * s, readH = 13.0f * s;
  3078. auto area = r.reduced (2.0f * s);
  3079. const auto top = area.removeFromTop (labelH), bottom = area.removeFromBottom (readH);
  3080. const auto scaleW = 18.0f * s;
  3081. auto bars = area.withTrimmedLeft (scaleW);
  3082. g.setFont (font (juce::jmax (7.0f, 8.0f * s)));
  3083. for (int db = 0; db >= -48; db -= 12)
  3084. {
  3085. const auto y = bars.getY() + bars.getHeight() * (float) -db / 48.0f;
  3086. g.setColour (colour::gridBeat);
  3087. g.drawHorizontalLine ((int) y, bars.getX(), bars.getRight());
  3088. g.setColour (colour::textSecondary);
  3089. g.drawText (juce::String (db), juce::Rectangle<float> (area.getX(), y - 6.0f * s, scaleW - 2.0f * s, 12.0f * s), juce::Justification::centredRight, false);
  3090. }
  3091. const auto w = bars.getWidth() / (only == 0 || only == 1 ? 1.0f : 2.0f);
  3092. const char* names[] = { TR_NOOP ("In"), TR_NOOP ("Out") };
  3093. if (kind == EffectKind::hardwareInsert) // round 164d: what goes to the gear and what comes back
  3094. names[0] = TR_NOOP ("Send"), names[1] = TR_NOOP ("Return");
  3095. for (int k = (only == 1 ? 1 : 0); k < (only == 0 ? 1 : 2); ++k)
  3096. {
  3097. const auto bar = juce::Rectangle<float> (bars.getX() + w * (float) (only == 1 ? 0 : k), bars.getY(), w, bars.getHeight()).reduced (3.0f * s, 0.0f);
  3098. skin::meter (g, bar, ioMeters[(std::size_t) k].level, ioMeters[(std::size_t) k].peak, true);
  3099. const auto column = juce::Rectangle<float> (bar.getX() - 4.0f * s, 0.0f, bar.getWidth() + 8.0f * s, 0.0f);
  3100. g.setColour (colour::textSecondary);
  3101. g.setFont (font (juce::jmax (7.0f, 8.5f * s), true));
  3102. if (k == 1 && ioClip) // round 135w: the output clipped since the last click
  3103. {
  3104. g.setColour (juce::Colour (0xffe5383b));
  3105. g.fillRoundedRectangle (column.withY (top.getY()).withHeight (labelH).reduced (4.0f * s, 1.0f * s), radius::sm);
  3106. g.setColour (colour::textPrimary);
  3107. }
  3108. g.drawText (caps (tr (names[k])), column.withY (top.getY()).withHeight (labelH), juce::Justification::centred, false);
  3109. const auto peakDb = ioMeters[(std::size_t) k].peak * 48.0f - 48.0f;
  3110. g.setColour (peakDb > -0.1f ? juce::Colour (0xffe5383b) : colour::textPrimary);
  3111. g.setFont (font (juce::jmax (7.0f, 8.5f * s)));
  3112. g.drawText (ioMeters[(std::size_t) k].peak > 0.001f ? juce::String (peakDb, 1) : juce::String ("-inf"),
  3113. column.withY (bottom.getY()).withHeight (readH), juce::Justification::centred, false);
  3114. }
  3115. return;
  3116. }
  3117. else if (id == "gcmeter") // round 152: RComp's bipolar gain-change meter (+6 … 0 … −12, deeper reductions compressed)
  3118. {
  3119. // the engine's control output 5 = the block's signed gain change in dB (negative = reduction, positive = the
  3120. // upward expansion below 1 : 1); the bar grows from the 0 dB line, the read-out holds the largest change
  3121. const auto change = liveMeter (5);
  3122. gcLevel = std::abs (change) > std::abs (gcLevel) ? change : gcLevel + 0.25f * (change - gcLevel);
  3123. if (std::abs (change) > std::abs (gcHold))
  3124. gcHold = change;
  3125. static constexpr float dbs[] { 9.0f, 6.0f, 3.0f, 0.0f, -3.0f, -6.0f, -12.0f, -24.0f, -30.0f };
  3126. static constexpr float fracs[] { 0.0f, 0.08f, 0.20f, 0.38f, 0.53f, 0.66f, 0.80f, 0.94f, 1.0f };
  3127. const auto fracOf = [] (float db)
  3128. {
  3129. db = juce::jlimit (-30.0f, 9.0f, db);
  3130. for (int k = 0; k + 1 < 9; ++k)
  3131. if (db >= dbs[k + 1])
  3132. return fracs[k] + (fracs[k + 1] - fracs[k]) * (dbs[k] - db) / (dbs[k] - dbs[k + 1]);
  3133. return 1.0f;
  3134. };
  3135. const auto readH = 14.0f * s;
  3136. auto area = r.reduced (2.0f * s);
  3137. const auto bottom = area.removeFromBottom (readH);
  3138. g.setColour (colour::bg3);
  3139. g.fillRoundedRectangle (area, radius::sm * s);
  3140. const auto scaleW = 20.0f * s;
  3141. const auto well = area.withTrimmedLeft (scaleW).reduced (3.0f * s, 4.0f * s);
  3142. g.setFont (font (juce::jmax (7.0f, 8.0f * s)));
  3143. for (const auto db : { 6, 3, 0, -3, -6, -12, -24 })
  3144. {
  3145. const auto y = well.getY() + well.getHeight() * fracOf ((float) db);
  3146. g.setColour (db == 0 ? colour::textSecondary.withAlpha (0.6f) : colour::gridBeat);
  3147. g.drawHorizontalLine ((int) y, well.getX(), well.getRight());
  3148. g.setColour (colour::textSecondary);
  3149. g.drawText (juce::String (db), juce::Rectangle<float> (area.getX(), y - 5.0f * s, scaleW - 2.0f * s, 10.0f * s), juce::Justification::centredRight, false);
  3150. }
  3151. const auto y0 = well.getY() + well.getHeight() * fracOf (0.0f), y1 = well.getY() + well.getHeight() * fracOf (gcLevel);
  3152. g.setColour ((fx.enabled ? accent : colour::textDisabled).withAlpha (gcLevel > 0.0f ? 0.55f : 0.85f));
  3153. g.fillRoundedRectangle (juce::Rectangle<float> (well.getX() + well.getWidth() * 0.2f, std::min (y0, y1), well.getWidth() * 0.6f, std::abs (y1 - y0)), radius::sm);
  3154. g.setColour (colour::textPrimary);
  3155. g.setFont (font (juce::jmax (7.0f, 9.0f * s)));
  3156. g.drawText (std::abs (gcHold) > 0.05f ? juce::String (gcHold, 1) : juce::String ("0.0"), bottom, juce::Justification::centred, false);
  3157. return;
  3158. }
  3159. else if (id == "limitpill") // round 135w: the output limiter's activity pill (RComp's), lit while it limits
  3160. {
  3161. const auto active = liveMeter (4) > 0.001f;
  3162. g.setColour (active ? juce::Colour (0xffe5383b) : colour::bg3);
  3163. g.fillRoundedRectangle (r.reduced (1.0f * s), r.getHeight() * 0.5f);
  3164. return;
  3165. }
  3166. else if (id == "outmeter") // round 135w: an output peak meter with a clip lamp and the highest peak (click: reset)
  3167. {
  3168. // H-Delay's output meter (0 … −48 dB) and peak lamp, DeEsser's output meter (−30 … 0, `steps` = 30)
  3169. const auto range = (float) (item.steps > 0 ? item.steps : 48);
  3170. const auto peakNow = liveMeter (3);
  3171. const auto fracOf = [range] (float linear) { return juce::jlimit (0.0f, 1.0f, (20.0f * std::log10 (juce::jmax (1e-6f, linear)) + range) / range); };
  3172. outMeter.update (fracOf (peakNow), 0.02f);
  3173. outMax = juce::jmax (outMax, peakNow);
  3174. outClip = outClip || peakNow >= 0.999f;
  3175. const auto lampH = 10.0f * s, readH = 13.0f * s;
  3176. auto area = r.reduced (2.0f * s);
  3177. const auto lamp = area.removeFromTop (lampH).withSizeKeepingCentre (juce::jmin (area.getWidth(), 16.0f * s), lampH - 2.0f * s);
  3178. area.removeFromTop (2.0f * s);
  3179. const auto bottom = area.removeFromBottom (readH);
  3180. g.setColour (outClip ? juce::Colour (0xffe5383b) : colour::bg3);
  3181. g.fillRoundedRectangle (lamp, radius::sm);
  3182. const auto scaleW = juce::jmin (16.0f * s, area.getWidth() * 0.45f);
  3183. auto bar = area.withTrimmedLeft (scaleW).reduced (2.0f * s, 0.0f);
  3184. g.setFont (font (juce::jmax (6.5f, 7.5f * s)));
  3185. const int stepDb = range > 36.0f ? 12 : 6;
  3186. for (int db = 0; db >= -(int) range; db -= stepDb)
  3187. {
  3188. const auto y = bar.getY() + bar.getHeight() * (float) -db / range;
  3189. g.setColour (colour::gridBeat);
  3190. g.drawHorizontalLine ((int) y, bar.getX(), bar.getRight());
  3191. g.setColour (colour::textSecondary);
  3192. g.drawText (juce::String (db), juce::Rectangle<float> (area.getX(), y - 5.0f * s, scaleW - 1.0f * s, 10.0f * s), juce::Justification::centredRight, false);
  3193. }
  3194. skin::meter (g, bar, outMeter.level, outMeter.peak, true);
  3195. const auto maxDb = 20.0f * std::log10 (juce::jmax (1e-6f, outMax));
  3196. g.setColour (maxDb > -0.1f ? juce::Colour (0xffe5383b) : colour::textPrimary);
  3197. g.setFont (font (juce::jmax (7.0f, 8.5f * s)));
  3198. g.drawText (outMax > 1e-5f ? juce::String (maxDb, 1) : juce::String ("-inf"), bottom, juce::Justification::centred, false);
  3199. return;
  3200. }
  3201. else if (id == "taptempo") // round 129: a tap pad (H-Delay's TAP): tap twice or more to set the delay time
  3202. {
  3203. const auto lit = juce::Time::getMillisecondCounter() - lastTap < 150;
  3204. if (skin::ledReadouts()) // round tp172d: EchoBoy's TAP TEMPO — a square key and the tempo on a red LED read-out
  3205. {
  3206. const auto key = r.withWidth (r.getHeight());
  3207. skin::hwKey (g, key, lit, false);
  3208. auto bpm = tapBpm;
  3209. if (bpm <= 0.0)
  3210. {
  3211. const auto timeParam = plugui::paramIndex (kind, item.param);
  3212. const auto t = timeParam >= 0 ? valueText (timeParam, fx.params[(std::size_t) timeParam]) : juce::String();
  3213. const auto ms = t.endsWith (" ms") ? t.getDoubleValue() : t.endsWith (" s") ? t.getDoubleValue() * 1000.0 : 0.0;
  3214. bpm = ms > 0.0 ? 60000.0 / ms : 0.0;
  3215. }
  3216. ledReadout (g, r.withTrimmedLeft (key.getWidth() + 4.0f * s).reduced (0.0f, r.getHeight() * 0.18f),
  3217. bpm > 0.0 ? juce::String (bpm, 1) + " bpm" : juce::String ("--- bpm"), s, fx.enabled);
  3218. return;
  3219. }
  3220. skin::button (g, r, lit, false, accent, radius::sm * s);
  3221. g.setColour (lit ? colour::textPrimary : colour::textSecondary);
  3222. g.setFont (font (juce::jmax (7.0f, 10.0f * s), true));
  3223. g.drawText (tapBpm > 0.0 ? caps (tr ("Tap")) + " " + juce::String (tapBpm, 1) : caps (tr ("Tap")), r, juce::Justification::centred, false);
  3224. return;
  3225. }
  3226. else if (id == "vumeter") // round 114: an analog-style VU needle showing the gain reduction (the optical leveler)
  3227. {
  3228. // gain reduction (needle down from 0 VU) or the output level (0 VU = −18 dBFS), like the reference's selector
  3229. // round 129: input / gain reduction / output, like the reference's VU DISPLAY selector (round 165x: the "VU display" parameter)
  3230. syncVuMode();
  3231. const auto level = liveMeter (vuMode == 1 ? 2 : 3);
  3232. const auto target = vuMode != 0 ? -juce::jlimit (-3.0f, 30.0f, -(20.0f * std::log10 (juce::jmax (1e-6f, level)) + 18.0f))
  3233. : -juce::jlimit (0.0f, 1.0f, liveMeter (item.steps)) * 30.0f;
  3234. vuNeedle += (-target - vuNeedle) * 0.35f; // a meter's inertia (~300 ms at the 30 Hz refresh)
  3235. auto face = r.reduced (2.0f * s);
  3236. if (skin::vuBezel()) // round tp172d (look slice): a chrome bezel round the meter window
  3237. {
  3238. g.setColour (juce::Colours::black.withAlpha (0.6f));
  3239. g.fillRoundedRectangle (r.translated (0.0f, 2.0f * s), 10.0f * s);
  3240. const auto dark = skin::vuBezelDark(); // (slice 8: an opto leveler's gunmetal frame)
  3241. g.setGradientFill (juce::ColourGradient (juce::Colour (dark ? 0xff5a5c60 : 0xffe6e8ea), 0.0f, r.getY(), juce::Colour (dark ? 0xff1c1d1f : 0xff4a4c50), 0.0f, r.getBottom(), false));
  3242. g.fillRoundedRectangle (r, 10.0f * s);
  3243. g.setGradientFill (juce::ColourGradient (juce::Colour (dark ? 0xff202124 : 0xff2e3034), 0.0f, r.getY(), juce::Colour (dark ? 0xff4b4d51 : 0xffb8babe), 0.0f, r.getBottom(), false));
  3244. g.fillRoundedRectangle (r.reduced (4.0f * s), 8.0f * s);
  3245. g.setColour (juce::Colour (0xff101010));
  3246. g.fillRoundedRectangle (r.reduced (6.0f * s), 7.0f * s);
  3247. face = r.reduced (9.0f * s);
  3248. }
  3249. g.setColour (juce::Colour (0xffd9cfb4).withAlpha (fx.enabled ? 1.0f : 0.5f));
  3250. g.fillRoundedRectangle (face, radius::lg * s);
  3251. if (kind == EffectKind::kilnChannel) // round tp172c7: the console's lamp-lit amber face, warmer in the middle
  3252. {
  3253. g.setGradientFill (juce::ColourGradient (juce::Colour (0xfff6c66a).withAlpha (fx.enabled ? 1.0f : 0.5f), face.getCentreX(), face.getCentreY(),
  3254. juce::Colour (0xffb8822e).withAlpha (fx.enabled ? 1.0f : 0.5f), face.getX(), face.getY(), true));
  3255. g.fillRoundedRectangle (face, radius::lg * s);
  3256. }
  3257. g.setColour (colour::bg0);
  3258. g.drawRoundedRectangle (face, radius::lg * s, 2.0f * s);
  3259. const juce::Point<float> pivot { face.getCentreX(), face.getBottom() + face.getHeight() * 0.18f };
  3260. const auto radiusV = face.getHeight() * 0.92f;
  3261. const auto fracOf = [] (float db) { // the VU scale: −20 … +3 on a linear-voltage law
  3262. const auto lo = std::pow (10.0f, -1.0f), hi = std::pow (10.0f, 3.0f / 20.0f);
  3263. return juce::jlimit (0.0f, 1.0f, (std::pow (10.0f, db / 20.0f) - lo) / (hi - lo));
  3264. };
  3265. const auto angleOf = [&] (float db) { return juce::MathConstants<float>::pi * (-0.27f + 0.54f * fracOf (db)); };
  3266. g.setFont (font (juce::jmax (7.0f, 9.0f * s), true));
  3267. for (const auto db : { -20.0f, -10.0f, -7.0f, -5.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f })
  3268. {
  3269. const auto a = angleOf (db);
  3270. const juce::Point<float> dir { std::sin (a), -std::cos (a) };
  3271. g.setColour (db > 0.0f ? juce::Colour (0xffb3261e) : juce::Colour (0xff2a2622));
  3272. g.drawLine ({ pivot + dir * (radiusV * 0.86f), pivot + dir * (radiusV * 0.95f) }, 1.4f * s);
  3273. if (db == -20.0f || db == -10.0f || db == -5.0f || db == -3.0f || db == 0.0f || db == 3.0f)
  3274. g.drawText (db > 0.0f ? "+" + juce::String ((int) db) : juce::String ((int) db),
  3275. juce::Rectangle<float> (24.0f * s, 12.0f * s).withCentre (pivot + dir * (radiusV * 1.04f)).toNearestInt(), juce::Justification::centred, false);
  3276. }
  3277. g.setColour (juce::Colour (0xffb3261e).withAlpha (0.8f));
  3278. juce::Path redArc;
  3279. redArc.addCentredArc (pivot.x, pivot.y, radiusV * 0.9f, radiusV * 0.9f, 0.0f, angleOf (0.0f), angleOf (3.0f), true);
  3280. g.strokePath (redArc, juce::PathStrokeType (3.0f * s));
  3281. g.setColour (juce::Colour (0xff2a2622));
  3282. g.setFont (font (juce::jmax (8.0f, 11.0f * s), true));
  3283. g.drawText ("VU", face.withTop (face.getY() + face.getHeight() * 0.5f).withHeight (16.0f * s).toNearestInt(), juce::Justification::centred, false);
  3284. g.setFont (font (juce::jmax (7.0f, 8.5f * s)));
  3285. g.drawText ((vuMode == 2 ? tr ("Output") : vuMode == 1 ? tr ("Input") : tr ("Gain reduction")) + " " + juce::String (-vuNeedle, 1) + (vuMode != 0 ? " VU" : " dB"), face.withTop (face.getBottom() - 16.0f * s).toNearestInt(), juce::Justification::centred, false);
  3286. // the needle
  3287. const auto a = angleOf (-vuNeedle);
  3288. const juce::Point<float> dir { std::sin (a), -std::cos (a) };
  3289. g.saveState();
  3290. g.reduceClipRegion (face.toNearestInt());
  3291. g.setColour (juce::Colour (0xff141210));
  3292. g.drawLine ({ pivot + dir * (radiusV * 0.25f), pivot + dir * (radiusV * 0.97f) }, 1.6f * s);
  3293. g.restoreState();
  3294. return;
  3295. }
  3296. else if (id == "ridgeeq") // the strip's EQ + filters (20 Hz .. 20 kHz, ±20 dB)
  3297. {
  3298. grid (10, 4);
  3299. const auto params = fx.params;
  3300. strokeCurve ([&params] (float x) {
  3301. const auto hz = 20.0 * std::pow (1000.0, (double) x);
  3302. return 0.5f + (float) mixsuite::ridge::responseDb (params, 48000.0, hz) / 40.0f;
  3303. }, inner, false);
  3304. }
  3305. else if (id == "ridgecomp") // compressor's static curve (−60 .. 0 dB in and out)
  3306. {
  3307. grid (6, 4);
  3308. const auto params = fx.params;
  3309. strokeCurve ([&params] (float x) {
  3310. return 1.0f + (float) mixsuite::ridge::compressorCurveDb (params, (double) (x - 1.0f) * 60.0) / 60.0f;
  3311. }, inner, true);
  3312. }
  3313. else if (id == "hushband") // the detector's filter (high-pass or band) at the frequency, 1 .. 20 kHz
  3314. {
  3315. grid (8, 4);
  3316. const auto f0 = mixsuite::hush::hpHz (param01 ("Frequency"), param01 ("Range law") >= 0.5f && param01 ("Voicing") < 0.5f); // round 165x
  3317. const auto band = param01 ("Band detector") >= 0.5f;
  3318. strokeCurve ([f0, band] (float x) {
  3319. const auto u = 1000.0 * std::pow (20.0, (double) x) / f0;
  3320. const auto u2 = u * u;
  3321. const auto mag = band ? (u / 1.4) / std::sqrt ((1.0 - u2) * (1.0 - u2) + u2 / (1.4 * 1.4))
  3322. : u2 / std::sqrt ((1.0 - u2) * (1.0 - u2) + 2.0 * u2);
  3323. return 0.9f + (float) (20.0 * std::log10 (std::max (1e-6, mag))) / 40.0f;
  3324. }, inner, true);
  3325. }
  3326. else if (id == "embercurve") // the style's transfer curve at the drive (x = ±1: the peaks of a −12 dBFS sine)
  3327. {
  3328. grid (4, 4);
  3329. const auto style = mixsuite::ember::styleOf (param01 ("Style"));
  3330. const auto drive = 0.25f * (float) std::pow (10.0, mixsuite::ember::driveDb (param01 ("Drive")) / 20.0);
  3331. const auto norm = 1.0f / juce::jmax (0.05f, std::abs (mixsuite::ember::shape (style, drive)));
  3332. strokeCurve ([style, drive, norm] (float x) {
  3333. return 0.5f + 0.5f * juce::jlimit (-1.0f, 1.0f, mixsuite::ember::shape (style, (x * 2.0f - 1.0f) * drive) * norm);
  3334. }, inner, false);
  3335. }
  3336. else if (id == "echotrain" || id == "lattice") // the echoes / taps on a time axis: left up, right down
  3337. {
  3338. grid (8, 2);
  3339. const auto params = fx.params;
  3340. const auto bpm = engine.getSong().bpm > 1.0 ? engine.getSong().bpm : 120.0;
  3341. struct Tick { double ms; double level; bool right; };
  3342. std::vector<Tick> ticks;
  3343. double window = 50.0;
  3344. if (id == "echotrain")
  3345. {
  3346. using namespace echosuite::echoform;
  3347. const auto st = styleOf (params[style]);
  3348. auto tL = sideMs (params, false, bpm), tR = sideMs (params, true, bpm);
  3349. if (st == Style::single || st == Style::quad)
  3350. tR = tL;
  3351. else if (st == Style::ratio)
  3352. tR = tL * (0.01 + 0.99 * (double) params[ratio]);
  3353. const auto gain = juce::jlimit (0.0, 1.0, feedbackGain (params[feedback]));
  3354. window = juce::jmax (50.0, 4.5 * juce::jmax (tL, tR));
  3355. if (params[rhythm] >= 0.5f) // round 137: the Rhythm pattern, three passes of it (left and right alike)
  3356. {
  3357. double slot0 = 0.0;
  3358. const auto taps = rhythmTaps (params, bpm, &slot0);
  3359. const auto length = rhythmLengthMs (params, bpm);
  3360. window = 3.0 * length * 1.02;
  3361. auto level = 1.0;
  3362. for (int pass = 0; pass < 3; ++pass, level *= gain)
  3363. for (int c = 0; c < 2; ++c)
  3364. {
  3365. if (pass > 0)
  3366. ticks.push_back ({ length * pass, slot0 * level, c == 1 });
  3367. for (const auto& t : taps)
  3368. ticks.push_back ({ length * pass + t.ms, t.level * level, c == 1 });
  3369. }
  3370. }
  3371. else if (st == Style::pingPong)
  3372. {
  3373. auto t = tL, level = 1.0;
  3374. for (int k = 0; k < 24 && t <= window; ++k)
  3375. {
  3376. ticks.push_back ({ t, level, (k % 2) == 1 });
  3377. t += (k % 2) == 0 ? tR : tL;
  3378. level *= params[pairs] >= 0.5f ? ((k % 2) == 1 ? gain : 1.0) : std::sqrt (gain); // round 119: pairs
  3379. }
  3380. }
  3381. else
  3382. for (int c = 0; c < 2; ++c)
  3383. {
  3384. const auto t = c == 0 ? tL : tR;
  3385. auto level = 1.0;
  3386. for (int k = 1; k <= 24 && t > 0.0 && t * k <= window; ++k, level *= gain)
  3387. {
  3388. if (st == Style::quad)
  3389. for (int q = 1; q < 4; ++q)
  3390. ticks.push_back ({ t * (k - 1 + q / 4.0), 0.5 * level, c == 1 });
  3391. ticks.push_back ({ t * k, st == Style::quad ? 0.5 * level : level, c == 1 });
  3392. }
  3393. }
  3394. }
  3395. else
  3396. {
  3397. using namespace echosuite::lattice;
  3398. const auto n = tapCount (params[taps]);
  3399. double longest = 1.0;
  3400. for (int k = 0; k < n; ++k)
  3401. for (int c = 0; c < 2; ++c)
  3402. {
  3403. const auto t = tapMs (params, k, n, c == 1);
  3404. longest = juce::jmax (longest, t);
  3405. ticks.push_back ({ t, std::abs (tapLevel (params, k, n)) * std::sqrt ((double) n), c == 1 });
  3406. }
  3407. window = longest * 1.15;
  3408. }
  3409. const auto mid = inner.getCentreY();
  3410. g.setColour (colour::gridBar);
  3411. g.drawHorizontalLine ((int) mid, inner.getX(), inner.getRight());
  3412. g.setColour (curveColour);
  3413. for (const auto& t : ticks)
  3414. {
  3415. if (t.level < 0.01)
  3416. continue;
  3417. const auto x = inner.getX() + inner.getWidth() * (float) (t.ms / window);
  3418. const auto h = inner.getHeight() * 0.48f * (float) juce::jlimit (0.0, 1.0, t.level);
  3419. g.fillRect (juce::Rectangle<float> (x - 1.0f * s, t.right ? mid : mid - h, juce::jmax (1.5f, 2.0f * s), h));
  3420. }
  3421. g.setColour (colour::textDisabled);
  3422. g.setFont (font (juce::jmax (8.0f, 9.0f * s), true));
  3423. g.drawText (juce::String (window >= 1000.0 ? juce::String (window / 1000.0, 2) + " s" : juce::String ((int) window) + " ms"),
  3424. inner.reduced (2.0f * s), juce::Justification::bottomRight); if (id == "echotrain") // round 137: the delay read-out (H-Delay's central display): the note and its tempo, or the ms
  3425. {
  3426. using namespace echosuite::echoform;
  3427. const auto kindL = syncKind (params[syncL]);
  3428. juce::String text;
  3429. if (kindL == 0)
  3430. text = juce::String (juce::roundToInt (sideMs (params, false, bpm))) + " ms";
  3431. else
  3432. text = juce::String (formatEffectParam (EffectKind::echoform, noteL, params[noteL], bpm)) + (kindL == 2 ? " D" : kindL == 3 ? " T" : "")
  3433. + " " + juce::String (tempoFor (params, bpm), 1) + " BPM";
  3434. g.setColour (colour::textSecondary);
  3435. g.drawText (text, inner.reduced (2.0f * s), juce::Justification::topRight);
  3436. }
  3437. }
  3438. else if (paintFxDisplay (g, id, item, inner, fx))
  3439. {
  3440. }
  3441. else // a plain well with the plugin's name (FL's scopes / animations are not reproduced)
  3442. {
  3443. g.setColour (colour::bg2);
  3444. g.setFont (font (juce::jmax (10.0f, juce::jmin (28.0f, r.getHeight() * 0.22f)), true));
  3445. g.drawFittedText (caps (utf8 (effectInfo (kind).name)), r.toNearestInt(), juce::Justification::centred, 1, 0.8f);
  3446. }
  3447. if (item.label != nullptr && *item.label != 0)
  3448. {
  3449. g.setColour (colour::textDisabled);
  3450. g.setFont (font (juce::jmax (8.0f, 9.0f * s), true));
  3451. g.drawText (caps (tr (item.label)), inner.withHeight (12.0f * s), juce::Justification::topLeft);
  3452. }
  3453. }
  3454. #include "ui/PluginEditorsFx.inc"
  3455. #include "ui/GrossBeatEditor.inc"
  3456. #include "ui/MaximusCurveEditor.inc"
  3457. #include "ui/LovePhilterEditor.inc"
  3458. // --- the parametric EQ's graph (FL's Parametric EQ 2 arrangement) -----------------------------------
  3459. static constexpr double eqRange = 18.0; // FL's graph spans ±18 dB
  3460. // rows above the graph (octaves, band names), frequencies under it, dB scale at its right
  3461. juce::Rectangle<float> eqGraph (juce::Rectangle<float> r) const
  3462. {
  3463. const auto s = scale();
  3464. return r.withTrimmedTop (29.0f * s).withTrimmedBottom (16.0f * s).withTrimmedRight (22.0f * s);
  3465. }
  3466. void paintEq (juce::Graphics& g, juce::Rectangle<float> r, const EffectSlot& fx)
  3467. {
  3468. using namespace theme;
  3469. const auto s = scale();
  3470. const auto graph = eqGraph (r);
  3471. g.setFont (font (juce::jmax (7.5f, 9.0f * s), true));
  3472. // octave marks (C1…C9) and the usual band names, on plates like FL's
  3473. const auto octaveRow = juce::Rectangle<float> (graph.getX(), r.getY() + 1.0f * s, graph.getWidth(), 11.0f * s);
  3474. for (int o = 1; o <= 9; ++o)
  3475. {
  3476. const auto x = peqview::xForHz (graph, 32.703 * std::pow (2.0, o - 1));
  3477. const auto next = peqview::xForHz (graph, 32.703 * std::pow (2.0, o));
  3478. const auto plate = juce::Rectangle<float> (x, octaveRow.getY(), juce::jmin (next, graph.getRight()) - x - 1.0f, octaveRow.getHeight());
  3479. g.setColour (colour::bg2);
  3480. g.fillRect (plate);
  3481. g.setColour (colour::textDisabled);
  3482. g.drawText ("C" + juce::String (o), plate.withTrimmedLeft (2.0f), juce::Justification::centredLeft, false);
  3483. }
  3484. struct Range { double lo, hi; const char* name; };
  3485. static const Range ranges[] = { { 20, 60, TR_NOOP ("Sub") }, { 60, 250, TR_NOOP ("Bass") }, { 250, 500, TR_NOOP ("Low mid") },
  3486. { 500, 2000, TR_NOOP ("Mid") }, { 2000, 4000, TR_NOOP ("High mid") }, { 4000, 6000, TR_NOOP ("Prs") },
  3487. { 6000, 20000, TR_NOOP ("Treble") } };
  3488. for (const auto& range : ranges)
  3489. {
  3490. const auto x0 = peqview::xForHz (graph, range.lo), x1 = peqview::xForHz (graph, range.hi);
  3491. const auto plate = juce::Rectangle<float> (x0, r.getY() + 15.0f * s, x1 - x0 - 1.0f, 11.0f * s);
  3492. g.setColour (colour::bg3);
  3493. g.fillRect (plate);
  3494. g.setColour (colour::textSecondary);
  3495. g.drawFittedText (caps (tr (range.name)), plate.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  3496. }
  3497. drawParametricEqCurve (g, graph, fx.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), fx.enabled, eqSelected, eqRange, false,
  3498. node.locate ? nullptr : &eqAnalyser); // round 166f: FL's spectrum and heatmap
  3499. // frequencies under the graph, dB at its right
  3500. g.setColour (colour::textDisabled);
  3501. for (auto [hz, text] : { std::pair { 20.0, "20" }, { 50.0, "50" }, { 100.0, "100" }, { 200.0, "200" }, { 500.0, "500" },
  3502. { 1000.0, "1k" }, { 2000.0, "2k" }, { 5000.0, "5k" }, { 10000.0, "10k" } })
  3503. g.drawText (text, juce::Rectangle<float> (peqview::xForHz (graph, hz) + 2.0f, graph.getBottom() + 2.0f * s, 40.0f * s, 11.0f * s),
  3504. juce::Justification::centredLeft, false);
  3505. for (int db = -18; db <= 18; db += 6)
  3506. g.drawText ((db > 0 ? "+" : "") + juce::String (db),
  3507. juce::Rectangle<float> (graph.getRight() + 1.0f, peqview::yForDb (graph, db, eqRange) - 6.0f * s, 21.0f * s, 12.0f * s),
  3508. juce::Justification::centredRight, false);
  3509. // the band handles
  3510. for (int b = 0; b < peq::bands; ++b)
  3511. {
  3512. if (peq::type (fx.params[(std::size_t) peq::param (b, 0)]) == peq::BandType::off)
  3513. continue;
  3514. const auto centre = peqview::handlePosition (graph, fx.params, b, eqRange);
  3515. const auto d = juce::jmax (12.0f, 16.0f * s);
  3516. const auto h = juce::Rectangle<float> (d, d).withCentre (centre);
  3517. const auto c = peqview::bandColour (b);
  3518. if (b == eqSelected)
  3519. {
  3520. g.setColour (c.withAlpha (0.25f));
  3521. g.fillEllipse (h.expanded (4.0f));
  3522. }
  3523. g.setColour (colour::bg0.withAlpha (0.7f));
  3524. g.fillEllipse (h);
  3525. g.setColour (c.withAlpha (fx.enabled ? 1.0f : 0.4f));
  3526. g.drawEllipse (h.reduced (1.0f), juce::jmax (1.5f, 2.0f * s));
  3527. g.setFont (font (juce::jmax (8.0f, 9.5f * s), true));
  3528. g.drawText (juce::String (b + 1), h, juce::Justification::centred);
  3529. }
  3530. }
  3531. void setParams (const std::vector<std::pair<int, float>>& changes)
  3532. {
  3533. if (current() == nullptr)
  3534. return;
  3535. if (usesBar())
  3536. bar.willEdit();
  3537. editSlot ([changes] (EffectSlot& target) {
  3538. for (auto [p, v] : changes)
  3539. if (p >= 0 && p < maxEffectParams)
  3540. target.params[(std::size_t) p] = juce::jlimit (0.0f, 1.0f, v);
  3541. });
  3542. }
  3543. bool eqMouseDown (const juce::MouseEvent& e, const LayoutItem& item)
  3544. {
  3545. const auto* fx = current();
  3546. const auto graph = eqGraph (rectOf (item));
  3547. const auto band = peqview::bandAt (graph, fx->params, e.position, eqRange);
  3548. eqSelected = band;
  3549. repaint();
  3550. if (band < 0 && e.mods.isPopupMenu() && ! node.locate) // round 166f: the display (FL's Options › Histogram / Heatmap)
  3551. {
  3552. juce::PopupMenu menu;
  3553. peqview::addDisplayItems (menu, [safe = juce::Component::SafePointer<juce::Component> (this)] {
  3554. if (safe != nullptr) safe->repaint();
  3555. });
  3556. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  3557. return true;
  3558. }
  3559. if (band < 0)
  3560. return true;
  3561. if (e.mods.isPopupMenu())
  3562. {
  3563. peqview::showBandMenu (*this, fx->params, band, [this] (std::vector<std::pair<int, float>> changes) { setParams (changes); });
  3564. return true;
  3565. }
  3566. eqDragOffset = peqview::handlePosition (graph, fx->params, band, eqRange) - e.position;
  3567. eqDragging = true;
  3568. return true;
  3569. }
  3570. void eqMouseDrag (const juce::MouseEvent& e)
  3571. {
  3572. const auto* fx = current();
  3573. if (fx == nullptr || eqSelected < 0 || dragItem < 0)
  3574. return;
  3575. const auto graph = eqGraph (rectOf (activeLayout().items[(std::size_t) dragItem]));
  3576. const auto p = e.position + eqDragOffset;
  3577. std::vector<std::pair<int, float>> changes { { peq::param (eqSelected, 1), peq::hzValue (peqview::hzForX (graph, p.x)) } };
  3578. if (peqview::hasGain (fx->params, eqSelected))
  3579. changes.push_back ({ peq::param (eqSelected, 2), peq::gainValue (peqview::dbForY (graph, p.y, eqRange)) });
  3580. setParams (changes);
  3581. ui::showValueTip (*this, juce::Rectangle<int> (6, 6).withCentre (e.getPosition()), peqview::bandText (fx->params, eqSelected));
  3582. }
  3583. // --- Soundgoodizer: Amount and the preset A–D live in the slot's state ---------------------------------
  3584. std::optional<maximusfx::Blob> soundgoodizerBlob() const
  3585. {
  3586. const auto* fx = current();
  3587. return fx != nullptr ? maximusfx::unpack (fx->state) : std::nullopt;
  3588. }
  3589. // the approximation keeps the plugin's own state (version, preset, amount); edits rebuild its chain
  3590. std::optional<maximusfx::SoundgoodizerState> soundgoodizerApproxState() const
  3591. {
  3592. const auto* fx = current();
  3593. return fx != nullptr && sgApprox ? maximusfx::parseSoundgoodizer (fx->state) : std::nullopt;
  3594. }
  3595. void writeSoundgoodizerApprox (int preset, int amount)
  3596. {
  3597. engine.editSong ([t = track, sl = slot, rebuilt = soundgoodizerApproxSlot (preset, amount)] (Song& song) {
  3598. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) sl];
  3599. fx.branches = rebuilt.branches;
  3600. fx.state = rebuilt.state;
  3601. });
  3602. }
  3603. float soundgoodizerAmount() const
  3604. {
  3605. if (sgApprox)
  3606. {
  3607. const auto sg = soundgoodizerApproxState();
  3608. return sg ? (float) sg->amount / 1000.0f : 0.6f;
  3609. }
  3610. const auto blob = soundgoodizerBlob();
  3611. return blob && blob->mix >= 0 ? (float) blob->mix / 1000.0f : 0.6f;
  3612. }
  3613. void writeSoundgoodizer (const maximusfx::Blob& blob)
  3614. {
  3615. engine.editSong ([t = track, sl = slot, bytes = maximusfx::pack (blob)] (Song& song) {
  3616. song.mixer[(std::size_t) t].effects[(std::size_t) sl].state = bytes;
  3617. });
  3618. }
  3619. void setSoundgoodizerAmount (float v)
  3620. {
  3621. if (sgApprox)
  3622. {
  3623. if (const auto sg = soundgoodizerApproxState())
  3624. writeSoundgoodizerApprox (sg->preset, juce::roundToInt (v * 1000.0f));
  3625. return;
  3626. }
  3627. if (auto blob = soundgoodizerBlob())
  3628. {
  3629. blob->mix = juce::roundToInt (v * 1000.0f);
  3630. writeSoundgoodizer (*blob);
  3631. }
  3632. }
  3633. const std::vector<std::uint8_t>& soundgoodizerPresetBytes (int preset)
  3634. {
  3635. auto& bytes = sgPresets[(std::size_t) preset];
  3636. if (bytes.empty())
  3637. {
  3638. const auto roots = findFlStudioRoots();
  3639. juce::MemoryBlock data;
  3640. if (! roots.factoryData.empty()
  3641. && juce::File (juce::String::fromUTF8 (roots.factoryData.c_str()))
  3642. .getChildFile ("Plugins/Fruity/Effects/Soundgoodizer/Data/Presets")
  3643. .getChildFile (maximusfx::soundgoodizerPresetFile (preset))
  3644. .loadFileAsData (data))
  3645. {
  3646. const auto* b = static_cast<const std::uint8_t*> (data.getData());
  3647. bytes.assign (b, b + data.getSize());
  3648. }
  3649. }
  3650. return bytes;
  3651. }
  3652. int soundgoodizerPreset()
  3653. {
  3654. if (sgApprox)
  3655. {
  3656. const auto sg = soundgoodizerApproxState();
  3657. return sg ? sg->preset : -1;
  3658. }
  3659. const auto blob = soundgoodizerBlob();
  3660. for (int p = 0; blob && p < 4; ++p)
  3661. if (const auto& bytes = soundgoodizerPresetBytes (p); ! bytes.empty() && bytes == blob->state)
  3662. return p;
  3663. return -1;
  3664. }
  3665. void setSoundgoodizerPreset (int preset)
  3666. {
  3667. if (sgApprox)
  3668. {
  3669. if (const auto sg = soundgoodizerApproxState())
  3670. writeSoundgoodizerApprox (preset, sg->amount);
  3671. return;
  3672. }
  3673. auto blob = soundgoodizerBlob();
  3674. const auto& bytes = soundgoodizerPresetBytes (preset);
  3675. if (! blob || bytes.empty())
  3676. return;
  3677. blob->state = bytes;
  3678. writeSoundgoodizer (*blob);
  3679. }
  3680. void paintSoundgoodizer (juce::Graphics& g, const juce::String& id, juce::Rectangle<float> r, const EffectSlot& fx)
  3681. {
  3682. using namespace theme;
  3683. const auto s = scale();
  3684. if (id == "sgamount")
  3685. {
  3686. const auto amount = soundgoodizerAmount();
  3687. drawKnob (g, r, amount, false, fx.enabled ? accent : colour::textDisabled, sgDragging);
  3688. const auto body = r.reduced (r.getWidth() * 0.16f);
  3689. g.setGradientFill (juce::ColourGradient (colour::bg6, body.getCentreX(), body.getY(), colour::bg4, body.getCentreX(), body.getBottom(), false));
  3690. g.fillEllipse (body);
  3691. g.setColour (colour::borderStrong);
  3692. g.drawEllipse (body, 1.0f);
  3693. g.setColour (colour::textPrimary);
  3694. g.setFont (font (juce::jmax (10.0f, 18.0f * s), true));
  3695. g.drawText (juce::String (amount * 100.0f, 0) + "%", body, juce::Justification::centred, false);
  3696. return;
  3697. }
  3698. const auto chosen = soundgoodizerPreset();
  3699. for (int p = 0; p < 4; ++p)
  3700. {
  3701. const auto cell = juce::Rectangle<float> (r.getX() + r.getWidth() * (float) p / 4.0f, r.getY(), r.getWidth() / 4.0f, r.getHeight());
  3702. const auto led = juce::Rectangle<float> (8.0f * s, 8.0f * s).withCentre ({ cell.getCentreX(), cell.getY() + 8.0f * s });
  3703. g.setColour (p == chosen ? (fx.enabled ? accent : colour::textSecondary) : colour::ledOff);
  3704. g.fillEllipse (led);
  3705. g.setColour (p == chosen ? colour::textPrimary : colour::textSecondary);
  3706. g.setFont (font (juce::jmax (10.0f, 20.0f * s), true));
  3707. g.drawText (juce::String::charToString ((juce::juce_wchar) ('A' + p)), cell.withTrimmedTop (16.0f * s), juce::Justification::centred, false);
  3708. }
  3709. }
  3710. // a pad sets two parameters at once
  3711. // --- round 137: Gemini Doubler's graphs are editable (the reference: "Gain, Pan, Delay and Detune can be controlled
  3712. // using the graphs"): drag a voice on the pan / gain half circle or on the delay / detune map, drag the EQ's L / H
  3713. // markers (frequency across, gain up), double-click a marker = that shelf on / off
  3714. static bool isGeminiGraph (const LayoutItem& item)
  3715. {
  3716. return item.type == Item::display && item.display != nullptr
  3717. && (std::strcmp (item.display, "geminipan") == 0 || std::strcmp (item.display, "geminimap") == 0 || std::strcmp (item.display, "geminieq") == 0);
  3718. }
  3719. // the handles of a graph: (parameter across / around, parameter up / out, position on screen)
  3720. struct GeminiHandle { int px = -1, py = -1, on = -1; juce::Point<float> at; };
  3721. std::vector<GeminiHandle> geminiHandles (const LayoutItem& item) const
  3722. {
  3723. using namespace voicetools::gemini;
  3724. std::vector<GeminiHandle> out;
  3725. const auto s = scale();
  3726. const auto inner = rectOf (item).reduced (6.0f * s);
  3727. const juce::String id (item.display);
  3728. if (id == "geminipan")
  3729. {
  3730. const auto c = juce::Point<float> (inner.getCentreX(), inner.getBottom() - 4.0f * s);
  3731. const auto radius = juce::jmin (inner.getWidth() * 0.5f, inner.getHeight()) - 8.0f * s;
  3732. auto add = [&] (int panP, int gainP, int onP) {
  3733. const auto a = juce::degreesToRadians ((float) panDegrees (valueOf (panP)));
  3734. const auto rr = radius * juce::jlimit (0.05f, 1.0f, valueOf (gainP));
  3735. out.push_back ({ panP, gainP, onP, { c.x + rr * std::sin (a), c.y - rr * std::cos (a) } });
  3736. };
  3737. add (directPan, directGain, directOn);
  3738. for (int v = 0; v < voices; ++v)
  3739. if (v < 2 || valueOf (voiceParam (v, vOn)) >= 0.5f)
  3740. add (voiceParam (v, vPan), voiceParam (v, vGain), voiceParam (v, vOn));
  3741. }
  3742. else if (id == "geminimap")
  3743. {
  3744. for (int v = 0; v < voices; ++v)
  3745. if (v < 2 || valueOf (voiceParam (v, vOn)) >= 0.5f)
  3746. out.push_back ({ voiceParam (v, vDelay), voiceParam (v, vDetune), voiceParam (v, vOn),
  3747. { inner.getX() + inner.getWidth() * valueOf (voiceParam (v, vDelay)),
  3748. inner.getBottom() - inner.getHeight() * valueOf (voiceParam (v, vDetune)) } });
  3749. }
  3750. else
  3751. {
  3752. auto add = [&] (int freqP, int gainP, int onP) {
  3753. const auto hz = freqHz (valueOf (freqP));
  3754. const auto x = (float) (std::log (juce::jlimit (20.0, 20000.0, hz) / 20.0) / std::log (1000.0));
  3755. const bool measured = valueOf (eqLaw) >= 0.5f; // round 165w: the height is the gain's own scale
  3756. const auto y = valueOf (onP) >= 0.5f ? valueOf (gainP) : shelfValue (0.0, measured);
  3757. out.push_back ({ freqP, gainP, onP, { inner.getX() + inner.getWidth() * x, inner.getBottom() - inner.getHeight() * y } });
  3758. };
  3759. add (lowFreq, lowGain, lowOn);
  3760. add (highFreq, highGain, highOn);
  3761. }
  3762. return out;
  3763. }
  3764. int geminiNearest (const LayoutItem& item, juce::Point<float> p) const
  3765. {
  3766. const auto handles = geminiHandles (item);
  3767. int best = -1;
  3768. auto bestD = 18.0f * scale();
  3769. for (int k = 0; k < (int) handles.size(); ++k)
  3770. if (const auto d = handles[(std::size_t) k].at.getDistanceFrom (p); d < bestD)
  3771. best = k, bestD = d;
  3772. return best;
  3773. }
  3774. void geminiMouse (const juce::MouseEvent& e, const LayoutItem& item)
  3775. {
  3776. using namespace voicetools::gemini;
  3777. const auto handles = geminiHandles (item);
  3778. if (geminiHandle < 0 || geminiHandle >= (int) handles.size())
  3779. return;
  3780. const auto& h = handles[(std::size_t) geminiHandle];
  3781. const auto s = scale();
  3782. const auto inner = rectOf (item).reduced (6.0f * s);
  3783. const juce::String id (item.display);
  3784. float x = 0.0f, y = 0.0f;
  3785. if (id == "geminipan")
  3786. {
  3787. const auto c = juce::Point<float> (inner.getCentreX(), inner.getBottom() - 4.0f * s);
  3788. const auto radius = juce::jmax (1.0f, juce::jmin (inner.getWidth() * 0.5f, inner.getHeight()) - 8.0f * s);
  3789. const auto deg = juce::jlimit (-45.0f, 45.0f, juce::radiansToDegrees (std::atan2 (e.position.x - c.x, juce::jmax (0.001f, c.y - e.position.y))));
  3790. x = (deg + 45.0f) / 90.0f;
  3791. y = juce::jlimit (0.0f, 1.0f, e.position.getDistanceFrom (c) / radius);
  3792. }
  3793. else if (id == "geminimap")
  3794. {
  3795. x = juce::jlimit (0.0f, 1.0f, (e.position.x - inner.getX()) / juce::jmax (1.0f, inner.getWidth()));
  3796. y = juce::jlimit (0.0f, 1.0f, (inner.getBottom() - e.position.y) / juce::jmax (1.0f, inner.getHeight()));
  3797. }
  3798. else
  3799. {
  3800. const auto fx = juce::jlimit (0.0f, 1.0f, (e.position.x - inner.getX()) / juce::jmax (1.0f, inner.getWidth()));
  3801. x = freqValue (20.0 * std::pow (1000.0, (double) fx));
  3802. y = juce::jlimit (0.0f, 1.0f, (inner.getBottom() - e.position.y) / juce::jmax (1.0f, inner.getHeight()));
  3803. }
  3804. std::vector<std::pair<int, float>> changes { { h.px, x }, { h.py, y } };
  3805. if (id == "geminieq" && valueOf (h.on) < 0.5f) // dragging a marker turns its shelf on
  3806. changes.push_back ({ h.on, 1.0f });
  3807. setParams (changes);
  3808. ui::showValueTip (*this, rectOf (item).toNearestInt(), valueText (h.px, x) + " / " + valueText (h.py, y));
  3809. }
  3810. int geminiHandle = -1;
  3811. float grHold = 0.0f; // round 137: the tall reduction meter's held value
  3812. float gcLevel = 0.0f, gcHold = 0.0f; // round 152: the bipolar gain-change meter (dB, signed) and its held change
  3813. bool geminiDragging = false;
  3814. void xyMouse (const juce::MouseEvent& e, const LayoutItem& item)
  3815. {
  3816. const auto inner = rectOf (item).reduced (6.0f * scale());
  3817. const auto px = plugui::paramIndex (kind, item.param), py = plugui::paramIndex (kind, item.param2);
  3818. const auto x = juce::jlimit (0.0f, 1.0f, (e.position.x - inner.getX()) / inner.getWidth());
  3819. const auto y = juce::jlimit (0.0f, 1.0f, (inner.getBottom() - e.position.y) / inner.getHeight());
  3820. setParams ({ { px, x }, { py, y } });
  3821. ui::showValueTip (*this, rectOf (item).toNearestInt(), valueText (px, x) + " / " + valueText (py, y));
  3822. }
  3823. // --- Fruity WaveShaper's curve (round 165: FL's point editor) ---------------------------------------
  3824. // FL's gestures: right-click adds a point (hold and drag to place it), left-drag moves one (Shift keeps its
  3825. // level, Ctrl its position), Alt+click or right-click › Delete removes it, the hollow handle between two points
  3826. // bends the segment (Ctrl: fine; right-click: straight again); right-click a point for its shape and value.
  3827. static bool isWaveShaperGraph (const LayoutItem& item) { return item.type == Item::display && juce::String (item.display) == "waveshaper"; }
  3828. bool wsUnipolar() const { return valueOf (plugui::paramIndex (kind, "Unipolar")) >= 0.5f; }
  3829. flshape::WaveShaperState wsState() const
  3830. {
  3831. const auto* fx = current();
  3832. if (fx == nullptr)
  3833. return flshape::waveShaperForEditing ({});
  3834. auto s = flshape::waveShaperForEditing (fx->state, fx->params.data());
  3835. if (wsDragState)
  3836. s.points = wsDragPoints; // shown at once while the edit travels to the engine
  3837. return s;
  3838. }
  3839. const std::vector<std::int16_t>& wsTable (const std::vector<flshape::WsPoint>& points, bool unipolar) const
  3840. {
  3841. // the curve as the engine shapes it (one table per change of the points)
  3842. auto same = wsCacheUni == unipolar && wsCachePoints.size() == points.size();
  3843. for (std::size_t i = 0; same && i < points.size(); ++i)
  3844. same = wsCachePoints[i].dt == points[i].dt && wsCachePoints[i].y == points[i].y && wsCachePoints[i].tension == points[i].tension
  3845. && wsCachePoints[i].mode == points[i].mode;
  3846. if (! same || wsCacheTable.empty())
  3847. {
  3848. wsCachePoints = points;
  3849. wsCacheUni = unipolar;
  3850. wsCacheTable = flshape::shaperTable (points, unipolar);
  3851. }
  3852. return wsCacheTable;
  3853. }
  3854. juce::Rectangle<float> wsArea (const LayoutItem& item) const { return rectOf (item).reduced (6.0f * scale()); }
  3855. static juce::Point<float> wsPos (juce::Rectangle<float> area, float x, float y)
  3856. {
  3857. return { area.getX() + area.getWidth() * x, area.getBottom() - area.getHeight() * y };
  3858. }
  3859. // the tension handle of the segment that ends at point i (x < 0: none — a hold, or too narrow to grab)
  3860. juce::Point<float> wsHandlePos (juce::Rectangle<float> area, const flshape::WaveShaperState& ws, const std::vector<float>& times, int i) const
  3861. {
  3862. if (i < 1 || i >= (int) ws.points.size() || ws.points[(std::size_t) i].mode == 2)
  3863. return { -2.0f, -2.0f };
  3864. const auto x0 = times[(std::size_t) i - 1], x1 = times[(std::size_t) i];
  3865. if ((x1 - x0) * area.getWidth() < 16.0f * scale())
  3866. return { -2.0f, -2.0f };
  3867. const auto xm = 0.5f * (x0 + x1);
  3868. return wsPos (area, xm, flshape::waveShaperLevelAt (wsTable (ws.points, wsUnipolar()), wsUnipolar(), xm));
  3869. }
  3870. int wsPointAt (const LayoutItem& item, juce::Point<float> p) const
  3871. {
  3872. const auto ws = wsState();
  3873. const auto times = flshape::waveShaperTimes (ws.points);
  3874. const auto area = wsArea (item);
  3875. int best = -1;
  3876. auto bestD = 8.0f * scale();
  3877. for (std::size_t i = 0; i < ws.points.size(); ++i)
  3878. if (const auto d = wsPos (area, times[i], ws.points[i].y).getDistanceFrom (p); d <= bestD)
  3879. best = (int) i, bestD = d;
  3880. return best;
  3881. }
  3882. int wsHandleAt (const LayoutItem& item, juce::Point<float> p) const
  3883. {
  3884. const auto ws = wsState();
  3885. const auto times = flshape::waveShaperTimes (ws.points);
  3886. const auto area = wsArea (item);
  3887. for (int i = 1; i < (int) ws.points.size(); ++i)
  3888. if (const auto h = wsHandlePos (area, ws, times, i); h.x > -1.0f && h.getDistanceFrom (p) <= 7.0f * scale())
  3889. return i;
  3890. return -1;
  3891. }
  3892. juce::Point<float> wsMouseValue (const LayoutItem& item, juce::Point<float> p) const
  3893. {
  3894. const auto area = wsArea (item);
  3895. return { juce::jlimit (0.0f, 1.0f, (p.x - area.getX()) / juce::jmax (1.0f, area.getWidth())),
  3896. juce::jlimit (0.0f, 1.0f, (area.getBottom() - p.y) / juce::jmax (1.0f, area.getHeight())) };
  3897. }
  3898. void wsWrite (std::vector<flshape::WsPoint> points)
  3899. {
  3900. const auto* fx = current();
  3901. if (fx == nullptr)
  3902. return;
  3903. auto s = flshape::waveShaperForEditing (fx->state, fx->params.data());
  3904. s.points = std::move (points);
  3905. s.unipolar = wsUnipolar();
  3906. if (usesBar())
  3907. bar.willEdit();
  3908. engine.editSong ([t = track, sl = slot, bytes = flshape::writeWaveShaper (s, fx->state)] (Song& song) {
  3909. song.mixer[(std::size_t) t].effects[(std::size_t) sl].state = bytes;
  3910. });
  3911. repaint();
  3912. }
  3913. juce::String wsValueText (float y) const
  3914. {
  3915. // the level as FL's hint shows it: percent of the map (bipolar 0…100 %, unipolar −100…100 %)
  3916. return wsUnipolar() ? juce::String (juce::roundToInt ((y * 2.0f - 1.0f) * 100.0f)) + "%" : juce::String (juce::roundToInt (y * 100.0f)) + "%";
  3917. }
  3918. void wsShowTip (const LayoutItem& item, float x, float y)
  3919. {
  3920. ui::showValueTip (*this, rectOf (item).toNearestInt(), tr ("In") + " " + juce::String (juce::roundToInt (x * 100.0f)) + "% " + tr ("Out") + " " + wsValueText (y));
  3921. }
  3922. // mouse down on the graph; true = a drag follows
  3923. bool wsMouseDown (const juce::MouseEvent& e, const LayoutItem& item)
  3924. {
  3925. auto points = wsState().points;
  3926. const auto point = wsPointAt (item, e.position);
  3927. const auto handle = point < 0 ? wsHandleAt (item, e.position) : -1;
  3928. const auto v = wsMouseValue (item, e.position);
  3929. wsDownMods = e.mods;
  3930. if (e.mods.isPopupMenu())
  3931. {
  3932. if (point >= 0)
  3933. wsPointMenu (point);
  3934. else if (handle >= 0) // straight again
  3935. {
  3936. points[(std::size_t) handle].tension = 0.0f;
  3937. wsWrite (points);
  3938. }
  3939. else // FL: a new point at the mouse, dragged while the button is held
  3940. {
  3941. wsPoint = flshape::addWaveShaperPoint (points, v.x, v.y);
  3942. wsDragPoints = points;
  3943. wsDragState = true;
  3944. wsWrite (points);
  3945. wsShowTip (item, v.x, v.y);
  3946. return true;
  3947. }
  3948. return false;
  3949. }
  3950. if (point >= 0 && e.mods.isAltDown()) // FL: Alt+click deletes
  3951. {
  3952. if (flshape::removeWaveShaperPoint (points, point))
  3953. wsWrite (points);
  3954. return false;
  3955. }
  3956. if (point >= 0)
  3957. {
  3958. wsPoint = point;
  3959. wsDragPoints = points;
  3960. wsDragState = true;
  3961. const auto t = flshape::waveShaperTimes (points);
  3962. wsShowTip (item, t[(std::size_t) point], points[(std::size_t) point].y);
  3963. return true;
  3964. }
  3965. if (handle >= 0)
  3966. {
  3967. // which way the tension bends this segment: the handle follows the mouse up and down
  3968. wsTension = handle;
  3969. wsTensionStart = points[(std::size_t) handle].tension;
  3970. auto bent = points;
  3971. bent[(std::size_t) handle].tension = juce::jlimit (-1.0f, 1.0f, wsTensionStart + (wsTensionStart > 0.8f ? -0.1f : 0.1f));
  3972. const auto times = flshape::waveShaperTimes (points);
  3973. const auto xm = 0.5f * (times[(std::size_t) handle - 1] + times[(std::size_t) handle]);
  3974. const auto uni = wsUnipolar();
  3975. const auto a = flshape::waveShaperLevelAt (flshape::shaperTable (points, uni), uni, xm);
  3976. const auto b = flshape::waveShaperLevelAt (flshape::shaperTable (bent, uni), uni, xm);
  3977. const auto up = (b - a) * (bent[(std::size_t) handle].tension - wsTensionStart);
  3978. wsTensionSign = up < 0.0f ? -1.0f : 1.0f;
  3979. wsDragPoints = points;
  3980. wsDragState = true;
  3981. return true;
  3982. }
  3983. return false;
  3984. }
  3985. void wsMouseDrag (const juce::MouseEvent& e, const LayoutItem& item)
  3986. {
  3987. if (! wsDragState)
  3988. return;
  3989. auto points = wsDragPoints;
  3990. if (wsTension >= 0 && wsTension < (int) points.size())
  3991. {
  3992. const auto dy = -(float) e.getDistanceFromDragStartY() / ((e.mods.isCtrlDown() ? 600.0f : 150.0f) * scale());
  3993. points[(std::size_t) wsTension].tension = juce::jlimit (-1.0f, 1.0f, wsTensionStart + wsTensionSign * dy);
  3994. ui::showValueTip (*this, rectOf (item).toNearestInt(), tr ("Tension") + " " + juce::String (juce::roundToInt (points[(std::size_t) wsTension].tension * 100.0f)) + "%");
  3995. }
  3996. else if (wsPoint >= 0 && wsPoint < (int) points.size())
  3997. {
  3998. const auto t = flshape::waveShaperTimes (points);
  3999. auto v = wsMouseValue (item, e.position);
  4000. // FL: Shift keeps the level, Ctrl keeps the position
  4001. if (e.mods.isShiftDown() && ! wsDownMods.isShiftDown())
  4002. v.y = points[(std::size_t) wsPoint].y;
  4003. if (e.mods.isCtrlDown())
  4004. v.x = t[(std::size_t) wsPoint];
  4005. flshape::moveWaveShaperPoint (points, wsPoint, v.x, v.y);
  4006. const auto moved = flshape::waveShaperTimes (points);
  4007. wsShowTip (item, moved[(std::size_t) wsPoint], points[(std::size_t) wsPoint].y);
  4008. }
  4009. else
  4010. return;
  4011. wsDragPoints = points;
  4012. wsWrite (points);
  4013. }
  4014. void wsMouseUp()
  4015. {
  4016. wsDragState = false;
  4017. wsPoint = wsTension = -1;
  4018. ui::hideValueTip();
  4019. repaint();
  4020. }
  4021. void wsPointMenu (int point)
  4022. {
  4023. const auto ws = wsState();
  4024. if (point < 0 || point >= (int) ws.points.size())
  4025. return;
  4026. const auto& p = ws.points[(std::size_t) point];
  4027. juce::PopupMenu menu;
  4028. menu.addSectionHeader (tr ("Out") + " " + wsValueText (p.y));
  4029. const auto inner = point > 0 && point + 1 < (int) ws.points.size();
  4030. menu.addItem (tr ("Delete"), inner, false, [this, point] {
  4031. auto pts = wsState().points;
  4032. if (flshape::removeWaveShaperPoint (pts, point))
  4033. wsWrite (pts);
  4034. });
  4035. if (point > 0) // the shape of the segment that ends here (FL's modes)
  4036. {
  4037. menu.addSectionHeader (tr ("Mode"));
  4038. for (const auto& m : flshape::waveShaperModes())
  4039. menu.addItem (tr (m.name), true, p.mode == m.mode, [this, point, mode = m.mode] {
  4040. auto pts = wsState().points;
  4041. if (point < (int) pts.size())
  4042. {
  4043. pts[(std::size_t) point].mode = mode;
  4044. wsWrite (pts);
  4045. }
  4046. });
  4047. }
  4048. menu.addSeparator();
  4049. menu.addItem (tr ("Copy value"), [y = p.y] { wsCopiedValue = y; });
  4050. menu.addItem (tr ("Paste value"), wsCopiedValue >= 0.0f, false, [this, point] {
  4051. auto pts = wsState().points;
  4052. if (point < (int) pts.size())
  4053. {
  4054. pts[(std::size_t) point].y = wsCopiedValue;
  4055. wsWrite (pts);
  4056. }
  4057. });
  4058. menu.addItem (tr ("Type in value..."), [this, point] { wsTypeValue (point); });
  4059. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  4060. }
  4061. void wsTypeValue (int point)
  4062. {
  4063. const auto ws = wsState();
  4064. if (point < 0 || point >= (int) ws.points.size())
  4065. return;
  4066. const auto uni = wsUnipolar();
  4067. const auto y = ws.points[(std::size_t) point].y;
  4068. auto* window = new juce::AlertWindow (tr ("Point value"), uni ? tr ("Percent (-100 to 100)") : tr ("Percent (0 to 100)"), juce::MessageBoxIconType::NoIcon);
  4069. window->addTextEditor ("value", juce::String (uni ? (y * 2.0f - 1.0f) * 100.0f : y * 100.0f, 1));
  4070. window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  4071. window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  4072. juce::Component::SafePointer<NativeEffectEditor> self (this);
  4073. window->enterModalState (true, juce::ModalCallbackFunction::create ([self, window, point, uni] (int result) {
  4074. if (result != 1 || self == nullptr)
  4075. return;
  4076. const auto typed = window->getTextEditorContents ("value").getFloatValue() / 100.0f;
  4077. auto pts = self->wsState().points;
  4078. if (point < (int) pts.size())
  4079. {
  4080. pts[(std::size_t) point].y = juce::jlimit (0.0f, 1.0f, uni ? (typed + 1.0f) * 0.5f : typed);
  4081. self->wsWrite (pts);
  4082. }
  4083. }),
  4084. true);
  4085. }
  4086. juce::String wsHint (const LayoutItem& item, juce::Point<float> p) const
  4087. {
  4088. if (wsPointAt (item, p) >= 0)
  4089. return tr ("Point: [LMB] drag moves ([Shift] keeps the level, [Ctrl] the position) [Alt][LMB] delete [RMB] shape, value, delete");
  4090. if (wsHandleAt (item, p) >= 0)
  4091. return tr ("Tension: [LMB] drag up / down bends the segment ([Ctrl] fine) [RMB] straight");
  4092. return tr ("Shaping curve: [RMB] add a point (hold and drag to place it) [LMB] drag a point [Alt][LMB] delete a point");
  4093. }
  4094. int wsPoint = -1, wsTension = -1, wsHoverPoint = -1, wsHoverHandle = -1;
  4095. float wsTensionStart = 0.0f, wsTensionSign = 1.0f;
  4096. bool wsDragState = false;
  4097. std::vector<flshape::WsPoint> wsDragPoints;
  4098. juce::ModifierKeys wsDownMods;
  4099. mutable std::vector<flshape::WsPoint> wsCachePoints;
  4100. mutable std::vector<std::int16_t> wsCacheTable;
  4101. mutable bool wsCacheUni = false;
  4102. static inline float wsCopiedValue = -1.0f;
  4103. // --- mouse -----------------------------------------------------------------------------------------
  4104. int headerItemAt (juce::Point<float> p) const
  4105. {
  4106. if (! headerArea().contains (p))
  4107. return 0;
  4108. if (menuButton().expanded (2.0f).contains (p))
  4109. return 1;
  4110. if (! sidechainChip.isEmpty() && sidechainChip.contains (p))
  4111. return 6;
  4112. if (usesBar())
  4113. return bar.contains (p) ? 5 : 0;
  4114. if (presetBox().contains (p))
  4115. return 2;
  4116. if (prevButton().contains (p))
  4117. return 3;
  4118. if (nextButton().contains (p))
  4119. return 4;
  4120. return 0;
  4121. }
  4122. void mouseMove (const juce::MouseEvent& e) override
  4123. {
  4124. const auto p = e.position;
  4125. const auto h = headerItemAt (p);
  4126. const auto i = h == 0 ? itemAt (p) : -1;
  4127. if (i >= 0 && (hasStepArrows (activeLayout().items[(std::size_t) i]) || isRhythmEdit (activeLayout().items[(std::size_t) i])))
  4128. {
  4129. mouseAt = p; // the menu's arrows light under the mouse
  4130. repaint();
  4131. }
  4132. if (usesBar() && bar.hover (p))
  4133. repaint();
  4134. if (h != hoverHeader || i != hoverItem)
  4135. {
  4136. hoverHeader = h;
  4137. hoverItem = i;
  4138. anim.setHot (i);
  4139. repaint();
  4140. }
  4141. if (kind == EffectKind::grossBeat && i >= 0 && gbMouseMove (activeLayout().items[(std::size_t) i], p)) // round 168m
  4142. return;
  4143. if (kind == EffectKind::maximus && mxMouseMove (i >= 0 ? activeLayout().items[(std::size_t) i] : LayoutItem {}, p)) // round 168x
  4144. return;
  4145. if ((kind == EffectKind::lovePhilter || kind == EffectKind::convolver || kind == EffectKind::vocodex) && lpMouseMove (i >= 0 ? activeLayout().items[(std::size_t) i] : LayoutItem {}, p)) // round 173d3
  4146. return;
  4147. if (i >= 0 && isWaveShaperGraph (activeLayout().items[(std::size_t) i])) // round 165: points and handles light up
  4148. {
  4149. const auto& item = activeLayout().items[(std::size_t) i];
  4150. const auto point = wsPointAt (item, p), handle = point < 0 ? wsHandleAt (item, p) : -1;
  4151. if (point != wsHoverPoint || handle != wsHoverHandle)
  4152. {
  4153. wsHoverPoint = point;
  4154. wsHoverHandle = handle;
  4155. repaint();
  4156. }
  4157. setMouseCursor (point >= 0 ? juce::MouseCursor::DraggingHandCursor
  4158. : handle >= 0 ? juce::MouseCursor::UpDownResizeCursor : juce::MouseCursor::CrosshairCursor);
  4159. return;
  4160. }
  4161. if (wsHoverPoint >= 0 || wsHoverHandle >= 0)
  4162. {
  4163. wsHoverPoint = wsHoverHandle = -1;
  4164. repaint();
  4165. }
  4166. setMouseCursor (i >= 0 || h > 0 ? juce::MouseCursor::PointingHandCursor : juce::MouseCursor::NormalCursor);
  4167. }
  4168. void mouseExit (const juce::MouseEvent&) override
  4169. {
  4170. bar.hoverExit();
  4171. hoverHeader = 0;
  4172. hoverItem = -1;
  4173. anim.setHot (-1);
  4174. mouseAt = { -1.0f, -1.0f };
  4175. repaint();
  4176. }
  4177. void mouseDown (const juce::MouseEvent& e) override
  4178. {
  4179. if (current() == nullptr)
  4180. return;
  4181. if (const auto h = headerItemAt (e.position); h > 0)
  4182. {
  4183. if (h == 6)
  4184. {
  4185. pluginheader::showSidechainPicker (engine, track, slot, this, sidechainChip.getSmallestIntegerContainer());
  4186. return;
  4187. }
  4188. if (h == 5)
  4189. {
  4190. const auto flFiles = presetFiles(); // round 168r: ◀ ▶ also run through FL's presets after LYNX's bank
  4191. const pluginheader::PresetBar::FlPresets fl {
  4192. [this] (juce::PopupMenu& m) { addFlPresets (m); }, [this] (int delta) { stepPreset (delta); }, [this] { return presetName; },
  4193. [flFiles] { return flFiles.size(); },
  4194. [this, flFiles] {
  4195. const auto* fx = current();
  4196. for (int i = 0; i < flFiles.size(); ++i)
  4197. if (flFiles[i].getFileNameWithoutExtension() == presetName && fx != nullptr && fx->presetName == presetName.toStdString())
  4198. return i;
  4199. return -1;
  4200. },
  4201. [this, flFiles] (int i) {
  4202. if (i >= 0 && i < flFiles.size())
  4203. {
  4204. loadPreset (flFiles[i]);
  4205. ui::postHint ({ presetName, juce::String (presetcycle::positionText (i, flFiles.size())) }, 2500);
  4206. }
  4207. } };
  4208. bar.click (bar.partAt (e.position), *this, &fl);
  4209. return;
  4210. }
  4211. if (h == 1 || h == 2 || e.mods.isPopupMenu())
  4212. showOptionsMenu (h == 2);
  4213. else
  4214. stepPreset (h == 3 ? -1 : 1);
  4215. return;
  4216. }
  4217. const auto index = itemAt (e.position);
  4218. if (index < 0)
  4219. return;
  4220. bar.beginGesture();
  4221. const auto& item = activeLayout().items[(std::size_t) index];
  4222. const auto r = rectOf (item);
  4223. if (kind == EffectKind::grossBeat && gbMouseDown (e, item, index)) // round 168m: the envelope editor and slot settings
  4224. return;
  4225. if (! e.mods.isPopupMenu() && isMixItem (item) && captionArea (item).contains (e.position))
  4226. {
  4227. pluginheader::toggleMixLock (kind);
  4228. repaint();
  4229. return;
  4230. }
  4231. if (hasStyle (item, plugui::pageTabs))
  4232. {
  4233. const auto n = juce::jmax (1, (int) plugui::optionLabels (item).size());
  4234. const auto along = isVertical (item) ? (e.position.y - r.getY()) / r.getHeight() : (e.position.x - r.getX()) / r.getWidth();
  4235. const auto o = juce::jlimit (0, n - 1, (int) (along * (float) n));
  4236. if (item.steps > 0) // one digit of the page (EQUO: target ×1, bank ×3)
  4237. page += (o - (page / item.steps) % n) * item.steps;
  4238. else
  4239. page = o;
  4240. if (const auto p = paramOf (item); p >= 0) // round tp172b: page tabs that also choose a value (LuxeVerb's engine)
  4241. setValue (p, n > 1 ? (float) o / (float) (n - 1) : 0.0f);
  4242. hoverItem = -1;
  4243. repaint();
  4244. return;
  4245. }
  4246. if (isWaveShaperGraph (item)) // round 165: FL's point editor
  4247. {
  4248. if (wsMouseDown (e, item))
  4249. dragItem = index;
  4250. return;
  4251. }
  4252. if (isMaximusCurve (item)) // round 168x: FL's envelope editor on Maximus' In/Out graph (issue #40)
  4253. {
  4254. if (mxMouseDown (e, item))
  4255. dragItem = index;
  4256. return;
  4257. }
  4258. if (isPhilterCurve (item)) // round 173d3: Love Philter's articulator editor
  4259. {
  4260. if (lpMouseDown (e, item))
  4261. dragItem = index;
  4262. return;
  4263. }
  4264. if (item.type == Item::display && juce::String (item.display) == "vxmapsel") // round 173d3: Vocodex's map dropdown
  4265. {
  4266. vxMapMenu (rectOf (item));
  4267. return;
  4268. }
  4269. if (item.type == Item::display && juce::String (item.display) == "pitchport") // round 190ez: drag up / down = port
  4270. {
  4271. if (! e.mods.isPopupMenu() && current() != nullptr)
  4272. {
  4273. portDragStart = effectMidiInPort (*current());
  4274. portDragY = e.position.y;
  4275. dragItem = index;
  4276. }
  4277. return;
  4278. }
  4279. if (item.type == Item::display && juce::String (item.display) == "equosend") // round 173d3: EQUO's send box
  4280. {
  4281. showTransmitterSendMenu (0, rectOf (item));
  4282. return;
  4283. }
  4284. if (item.type == Item::display && (juce::String (item.display) == "tsssend0" || juce::String (item.display) == "tsssend1"))
  4285. {
  4286. showTransmitterSendMenu (juce::String (item.display) == "tsssend0" ? 0 : 1, rectOf (item));
  4287. return;
  4288. }
  4289. if (item.type == Item::display && juce::String (item.display) == "tunekeys")
  4290. {
  4291. tuneKeyClick (rectOf (item), e.position);
  4292. return;
  4293. }
  4294. if (item.type == Item::display && juce::String (item.display) == "tuneautokey")
  4295. {
  4296. autoKey (rectOf (item));
  4297. return;
  4298. }
  4299. if (item.type == Item::display && juce::String (item.display) == "pitchring") // HOLD
  4300. {
  4301. tuneHold = ! tuneHold;
  4302. if (tuneHold && ! pitchHistory.empty())
  4303. holdPoint = pitchHistory.back();
  4304. repaint();
  4305. return;
  4306. }
  4307. if (item.type == Item::display && juce::String (item.display) == "vumeter") // the VU's selector: gain reduction / output / input
  4308. {
  4309. setVuMode ((vuMode + 1) % 3);
  4310. repaint();
  4311. return;
  4312. }
  4313. if (item.type == Item::display && juce::String (item.display) == "iometer") // round 135w: reset the peaks and the clip lamp
  4314. {
  4315. ioMeters = {};
  4316. ioClip = false;
  4317. repaint();
  4318. return;
  4319. }
  4320. if (item.type == Item::display && juce::String (item.display) == "gcmeter") // round 152: reset the held change
  4321. {
  4322. gcHold = 0.0f;
  4323. repaint();
  4324. return;
  4325. }
  4326. if (item.type == Item::display && juce::String (item.display) == "grmeter") // round 137: reset the held reduction
  4327. {
  4328. grHold = 0.0f;
  4329. repaint();
  4330. return;
  4331. }
  4332. if (item.type == Item::display && juce::String (item.display) == "outmeter") // round 135w: reset the peak and the clip lamp
  4333. {
  4334. outMax = 0.0f;
  4335. outClip = false;
  4336. repaint();
  4337. return;
  4338. }
  4339. if (item.type == Item::display && juce::String (item.display) == "taptempo") // round 129: the tap pad
  4340. {
  4341. const auto now = juce::Time::getMillisecondCounter();
  4342. if (now - lastTap > 2000)
  4343. tapIntervals.clear();
  4344. else
  4345. {
  4346. tapIntervals.push_back ((double) (now - lastTap));
  4347. if (tapIntervals.size() > 4)
  4348. tapIntervals.erase (tapIntervals.begin());
  4349. double sum = 0.0;
  4350. for (const auto t : tapIntervals) sum += t;
  4351. const auto msAvg = sum / (double) tapIntervals.size();
  4352. tapBpm = 60000.0 / msAvg;
  4353. const auto timeParam = plugui::paramIndex (kind, item.param), syncParam = plugui::paramIndex (kind, item.param2);
  4354. std::vector<std::pair<int, float>> changes;
  4355. if (const auto sync = presets::valueFromText (kind, syncParam, "ms"); sync && syncParam >= 0)
  4356. changes.push_back ({ syncParam, *sync });
  4357. if (const auto t = presets::valueFromText (kind, timeParam, juce::String (msAvg, 1).toStdString() + " ms"); t && timeParam >= 0)
  4358. changes.push_back ({ timeParam, *t });
  4359. bar.beginGesture();
  4360. setParams (changes);
  4361. }
  4362. lastTap = now;
  4363. repaint();
  4364. return;
  4365. }
  4366. if (item.type == Item::display && juce::String (item.display) == "sgpresets")
  4367. {
  4368. const auto r = rectOf (item);
  4369. setSoundgoodizerPreset (juce::jlimit (0, 3, (int) ((e.position.x - r.getX()) / r.getWidth() * 4.0f)));
  4370. return;
  4371. }
  4372. if (item.type == Item::display && juce::String (item.display) == "sgamount")
  4373. {
  4374. dragItem = index;
  4375. sgDragging = true;
  4376. sgStart = soundgoodizerAmount();
  4377. ui::showValueTip (*this, rectOf (item).toNearestInt(), juce::String (sgStart * 100.0f, 0) + "%");
  4378. return;
  4379. }
  4380. if (item.type == Item::display && (juce::String (item.display) == "prismbands" || juce::String (item.display) == "emberbands"))
  4381. {
  4382. // band displays (round 108): drag a crossover line, or click a band to edit it (its page)
  4383. const auto* fx = current();
  4384. if (const auto p = dynui::crossoverNear (*fx, r, e.position.x, 6.0f * scale()); p >= 0)
  4385. {
  4386. dragItem = index;
  4387. crossoverDrag = p;
  4388. return;
  4389. }
  4390. if (! activeLayout().pages.empty())
  4391. {
  4392. page = juce::jlimit (0, (int) activeLayout().pages.size() - 1, dynui::bandAt (*fx, r, e.position.x));
  4393. repaint();
  4394. }
  4395. return;
  4396. }
  4397. if (isGeminiGraph (item)) // round 137
  4398. {
  4399. geminiHandle = geminiNearest (item, e.position);
  4400. if (geminiHandle >= 0)
  4401. {
  4402. dragItem = index;
  4403. geminiDragging = true;
  4404. bar.beginGesture();
  4405. }
  4406. return;
  4407. }
  4408. if (item.type == Item::display && juce::String (item.display) == "xy")
  4409. {
  4410. dragItem = index;
  4411. xyDragging = true;
  4412. xyMouse (e, item);
  4413. return;
  4414. }
  4415. if (isRhythmPatterns (item)) // round 144: the rhythm editor's pattern menu
  4416. {
  4417. rhythmPatternsMenu (item);
  4418. return;
  4419. }
  4420. if (isRhythmEdit (item))
  4421. {
  4422. if (e.mods.isPopupMenu())
  4423. {
  4424. rhythmPatternsMenu (item);
  4425. return;
  4426. }
  4427. dragItem = index;
  4428. rhythmMouse (e, item, true);
  4429. return;
  4430. }
  4431. if (isBars (item))
  4432. {
  4433. dragItem = index;
  4434. barsDragging = true;
  4435. barsMouse (e, item, true);
  4436. return;
  4437. }
  4438. if (item.type == Item::display) // the EQ graph
  4439. {
  4440. if (eqMouseDown (e, item) && eqDragging)
  4441. dragItem = index;
  4442. return;
  4443. }
  4444. const auto param = paramOf (item);
  4445. if (param < 0)
  4446. return;
  4447. const auto spec = specFor (item);
  4448. if (item.type == Item::menu && ! ui::isResetClick (e))
  4449. {
  4450. if (kind == EffectKind::parametricEq && item.colour >= 0)
  4451. {
  4452. eqSelected = item.colour;
  4453. repaint();
  4454. peqview::showBandMenu (*this, current()->params, item.colour, [this] (std::vector<std::pair<int, float>> changes) { setParams (changes); });
  4455. return;
  4456. }
  4457. if (kind == EffectKind::hardwareInsert && (param == hwinsert::output || param == hwinsert::input))
  4458. {
  4459. showHwChannelMenu (param == hwinsert::output, r);
  4460. return;
  4461. }
  4462. if (isSendTarget (param)) // FL's list: no destination, then every other insert by name (+ Transporter's send, round 167n)
  4463. {
  4464. juce::PopupMenu menu;
  4465. const auto chosen = flbasic::sendTrack (valueOf (param));
  4466. menu.addItem (tr ("None"), true, chosen <= 0, [this, param] { setValue (param, 0.0f); });
  4467. const auto& mixer = engine.getSong().mixer;
  4468. for (int t = 1; t < (int) mixer.size(); ++t)
  4469. if (t != track)
  4470. menu.addItem (juce::String (t) + " " + insertName (t), engine.getSong().canRoute (track, t) || t == chosen, t == chosen,
  4471. [this, param, t] { setValue (param, flbasic::sendTrackValue (t)); });
  4472. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  4473. return;
  4474. }
  4475. if (kind == EffectKind::lynxTune && param == lynxtune::scale) // round 128: + whole tone, diminished
  4476. {
  4477. const auto* fx = current();
  4478. const auto more = fx != nullptr ? juce::roundToInt (fx->params[lynxtune::moreScales] * 2.0f) : 0;
  4479. juce::PopupMenu menu;
  4480. const auto labels = plugui::optionLabels (item);
  4481. const auto chosen = plugui::optionAt (item, valueOf (param));
  4482. for (int o = 0; o < (int) labels.size(); ++o)
  4483. menu.addItem (optionTexts (item)[(std::size_t) o], true, more == 0 && o == chosen,
  4484. [this, param, v = plugui::optionValue (item, o)] { setParams ({ { param, v }, { lynxtune::moreScales, 0.0f } }); });
  4485. menu.addSeparator();
  4486. menu.addItem (tr ("Whole tone"), true, more == 1, [this] { setParams ({ { lynxtune::moreScales, 0.5f } }); });
  4487. menu.addItem (tr ("Diminished"), true, more == 2, [this] { setParams ({ { lynxtune::moreScales, 1.0f } }); });
  4488. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  4489. return;
  4490. }
  4491. const auto labels = plugui::optionLabels (item);
  4492. const auto chosen = plugui::optionAt (item, valueOf (param));
  4493. // round 114: wide mode menus step with the arrows at their ends (the reference reverbs' ◀ ▶), the middle opens the list
  4494. if (hasStepArrows (item) && ! labels.empty())
  4495. {
  4496. const auto edge = 18.0f * scale();
  4497. const auto dir = e.position.x < r.getX() + edge ? -1 : e.position.x > r.getRight() - edge ? 1 : 0;
  4498. if (dir != 0)
  4499. {
  4500. const auto n = (int) labels.size();
  4501. const auto next = (chosen + dir + n) % n;
  4502. setValue (param, plugui::optionValue (item, next));
  4503. ui::flashValueTip (*this, r.toNearestInt(), optionTexts (item)[(std::size_t) next]);
  4504. return;
  4505. }
  4506. }
  4507. juce::PopupMenu menu;
  4508. for (int o = 0; o < (int) labels.size(); ++o)
  4509. menu.addItem (optionTexts (item)[(std::size_t) o], true, o == chosen,
  4510. [this, param, v = plugui::optionValue (item, o)] { setValue (param, v); });
  4511. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (r.toNearestInt())));
  4512. return;
  4513. }
  4514. if (e.mods.isPopupMenu() && listedStepper (item)) // round 170c (#14): its values, then the parameter items
  4515. {
  4516. showStepperMenu (item, true);
  4517. return;
  4518. }
  4519. if (e.mods.isPopupMenu())
  4520. {
  4521. ui::showValueMenu (*this, &engine, spec, valueOf (param), [this, param] (double v) { setValue (param, (float) v); });
  4522. return;
  4523. }
  4524. if (ui::isResetClick (e))
  4525. {
  4526. setValue (param, (float) spec.defaultValue);
  4527. ui::flashValueTip (*this, r.toNearestInt(), spec.text (spec.defaultValue));
  4528. return;
  4529. }
  4530. switch (item.type)
  4531. {
  4532. case Item::radio:
  4533. case Item::tabs:
  4534. {
  4535. const auto n = juce::jmax (1, (int) plugui::optionLabels (item).size());
  4536. auto o = item.type == Item::radio || isVertical (item) ? (int) ((e.position.y - r.getY()) / r.getHeight() * (float) n)
  4537. : (int) ((e.position.x - r.getX()) / r.getWidth() * (float) n);
  4538. if (hasStyle (item, plugui::batToggle) && n == 2) // round tp172d (slice 8): a click flips the bat toggle
  4539. o = plugui::optionAt (item, valueOf (param)) == 0 ? 1 : 0;
  4540. if (hasStyle (item, plugui::rotarySelector)) // ... and turns the selector to the printed option nearest the click
  4541. {
  4542. const auto c = selectorKnobArea (item).getCentre();
  4543. const auto a = std::atan2 (e.position.x - c.x, c.y - e.position.y);
  4544. auto best = 1e9f;
  4545. for (int k = 0; k < n; ++k)
  4546. if (const auto d = std::abs (a - selectorAngle (k, n)); d < best)
  4547. best = d, o = k;
  4548. }
  4549. if (item.type == Item::radio && item.columns > 0)
  4550. for (int k = 0; k < n; ++k)
  4551. if (gridCell (item, k, n).contains (e.position))
  4552. o = k;
  4553. setValue (param, plugui::optionValue (item, juce::jlimit (0, n - 1, o)));
  4554. return;
  4555. }
  4556. case Item::toggle:
  4557. setValue (param, valueOf (param) >= 0.5f ? 0.0f : 1.0f);
  4558. return;
  4559. case Item::stepper:
  4560. // round 170c (#14): the arrows' halves split at the value box's centre (the caption above it moved the
  4561. // split down before), and a small stepper's arrows get a 10 px hit area
  4562. if (const auto arrow = stepperArrowAt (item, e.position); arrow != 0)
  4563. {
  4564. stepStepper (item, arrow);
  4565. return;
  4566. }
  4567. stepperDragIndex = listedStepper (item) ? stepperIndex (item, valueOf (param)) : -1;
  4568. stepperMoved = false;
  4569. break;
  4570. case Item::hslider:
  4571. case Item::vslider:
  4572. case Item::knob:
  4573. case Item::value:
  4574. case Item::menu:
  4575. case Item::section:
  4576. case Item::label:
  4577. case Item::display:
  4578. break;
  4579. }
  4580. dragItem = index;
  4581. drag.begin (e, valueOf (param));
  4582. ui::showValueTip (*this, r.toNearestInt(), spec.text (valueOf (param)));
  4583. repaint();
  4584. }
  4585. void mouseDrag (const juce::MouseEvent& e) override
  4586. {
  4587. if (mxDragging && dragItem >= 0) // round 168x: Maximus' curve
  4588. {
  4589. mxMouseDrag (e, activeLayout().items[(std::size_t) dragItem]);
  4590. return;
  4591. }
  4592. if (lpDragging && dragItem >= 0) // round 173d3: Love Philter's articulator curve
  4593. {
  4594. lpMouseDrag (e, activeLayout().items[(std::size_t) dragItem]);
  4595. return;
  4596. }
  4597. if (wsDragState && dragItem >= 0) // round 165: the WaveShaper's curve
  4598. {
  4599. wsMouseDrag (e, activeLayout().items[(std::size_t) dragItem]);
  4600. return;
  4601. }
  4602. if (gbDragging && dragItem >= 0) // round 168m: Gross Beat's envelope
  4603. {
  4604. gbEnvelopeDrag (e, activeLayout().items[(std::size_t) dragItem]);
  4605. return;
  4606. }
  4607. if (portDragStart >= -1 && dragItem >= 0) // round 190ez: Pitcher's MIDI port, one number per 11 px (FL: 33 px up
  4608. { // took "..." to 2, live FL check 190ew)
  4609. const auto port = juce::jlimit (-1, 255, portDragStart + (int) std::floor ((portDragY - e.position.y) / 11.0f));
  4610. if (current() != nullptr && port != effectMidiInPort (*current()))
  4611. editSlot ([port] (EffectSlot& target) { setEffectMidiInPort (target, port); });
  4612. return;
  4613. }
  4614. if (crossoverDrag >= 0 && dragItem >= 0)
  4615. {
  4616. const auto r = rectOf (activeLayout().items[(std::size_t) dragItem]);
  4617. const auto v = dynui::crossoverValueAt (*current(), r, e.position.x);
  4618. setValue (crossoverDrag, v);
  4619. ui::showValueTip (*this, r.toNearestInt(), valueText (crossoverDrag, v));
  4620. return;
  4621. }
  4622. if (eqDragging)
  4623. {
  4624. eqMouseDrag (e);
  4625. return;
  4626. }
  4627. if (sgDragging && dragItem >= 0)
  4628. {
  4629. const auto v = juce::jlimit (0.0f, 1.0f, sgStart - (float) e.getDistanceFromDragStartY() / (e.mods.isCtrlDown() ? 800.0f : 200.0f));
  4630. setSoundgoodizerAmount (v);
  4631. ui::showValueTip (*this, rectOf (activeLayout().items[(std::size_t) dragItem]).toNearestInt(), juce::String (v * 100.0f, 0) + "%");
  4632. return;
  4633. }
  4634. if (xyDragging && dragItem >= 0)
  4635. {
  4636. xyMouse (e, activeLayout().items[(std::size_t) dragItem]);
  4637. return;
  4638. }
  4639. if (geminiDragging && dragItem >= 0) // round 137
  4640. {
  4641. geminiMouse (e, activeLayout().items[(std::size_t) dragItem]);
  4642. return;
  4643. }
  4644. if (barsDragging && dragItem >= 0)
  4645. {
  4646. barsMouse (e, activeLayout().items[(std::size_t) dragItem], false);
  4647. return;
  4648. }
  4649. if (rhythmDrag >= 0 && dragItem >= 0) // round 144
  4650. {
  4651. rhythmMouse (e, activeLayout().items[(std::size_t) dragItem], false);
  4652. return;
  4653. }
  4654. if (tuneRangeDrag >= 0) // round 147: LYNX Tune's range boundary
  4655. {
  4656. for (const auto& it : activeLayout().items)
  4657. if (it.type == Item::display && juce::String (it.display) == "tunekeys")
  4658. tuneSetRangeAt (rectOf (it), e.position.x, false);
  4659. return;
  4660. }
  4661. if (dragItem < 0 || ! drag.isActive())
  4662. return;
  4663. const auto& item = activeLayout().items[(std::size_t) dragItem];
  4664. const auto param = paramOf (item);
  4665. const auto spec = specFor (item);
  4666. if (listedStepper (item) && stepperDragIndex >= 0) // round 170c (#14): one value per stepperDragPixels
  4667. {
  4668. stepperMoved = stepperMoved || std::abs (e.getDistanceFromDragStartY()) >= 3;
  4669. const auto v = stepperValue (item, stepperDragIndex + (int) std::trunc (-(float) e.getDistanceFromDragStartY() / stepperDragPixels));
  4670. setValue (param, v);
  4671. ui::showValueTip (*this, rectOf (item).toNearestInt(), spec.text (v));
  4672. return;
  4673. }
  4674. auto v = drag.update (e, spec);
  4675. if (item.type == Item::hslider) // horizontal sliders follow the mouse sideways too
  4676. {
  4677. const auto r = rectOf (item);
  4678. v = juce::jlimit (0.0, 1.0, (double) ((e.position.x - r.getX() - 4.0f * scale()) / juce::jmax (1.0f, r.getWidth() - 8.0f * scale())));
  4679. if (e.mods.isCtrlDown())
  4680. v = drag.update (e, spec);
  4681. }
  4682. setValue (param, (float) v);
  4683. ui::showValueTip (*this, rectOf (item).toNearestInt(), spec.text (v));
  4684. }
  4685. void mouseUp (const juce::MouseEvent& e) override
  4686. {
  4687. eqDragging = false;
  4688. if (portDragStart >= -1) // round 190ez
  4689. {
  4690. portDragStart = -2;
  4691. dragItem = -1;
  4692. }
  4693. if (wsDragState) // round 165
  4694. {
  4695. wsMouseUp();
  4696. dragItem = -1;
  4697. }
  4698. if (mxDragging) // round 168x
  4699. {
  4700. mxMouseUp();
  4701. dragItem = -1;
  4702. }
  4703. if (lpDragging) // round 173d3
  4704. {
  4705. lpMouseUp();
  4706. dragItem = -1;
  4707. }
  4708. if (gbDragging) // round 168m
  4709. {
  4710. gbEnvelopeUp();
  4711. dragItem = -1;
  4712. }
  4713. tuneKeyRelease(); // LYNX Tune's keyboard without LATCH: the edit lasts while the key is held
  4714. if (crossoverDrag >= 0)
  4715. {
  4716. crossoverDrag = -1;
  4717. dragItem = -1;
  4718. ui::hideValueTip();
  4719. }
  4720. if (geminiDragging) // round 137
  4721. {
  4722. geminiDragging = false;
  4723. geminiHandle = -1;
  4724. dragItem = -1;
  4725. ui::hideValueTip();
  4726. }
  4727. if (rhythmDrag >= 0 || (dragItem >= 0 && isRhythmEdit (activeLayout().items[(std::size_t) dragItem]))) // round 144
  4728. {
  4729. rhythmDrag = -1;
  4730. dragItem = -1;
  4731. ui::hideValueTip();
  4732. repaint();
  4733. }
  4734. if (xyDragging || sgDragging || barsDragging)
  4735. {
  4736. xyDragging = sgDragging = barsDragging = false;
  4737. dragItem = -1;
  4738. ui::hideValueTip();
  4739. }
  4740. if (dragItem >= 0)
  4741. {
  4742. drag.end();
  4743. // round 170c (issue #14: "Oversampling: Off" could not be changed): a click on a stepper's value (no drag)
  4744. // lists its values, as FL's value selectors do; the arrows step, a drag or the wheel moves it
  4745. stepperDragIndex = -1;
  4746. if (const auto& item = activeLayout().items[(std::size_t) dragItem];
  4747. listedStepper (item) && ! stepperMoved && ! e.mods.isPopupMenu())
  4748. {
  4749. dragItem = -1;
  4750. ui::hideValueTip();
  4751. ++stepperMenusShown;
  4752. showStepperMenu (item, false);
  4753. repaint();
  4754. return;
  4755. }
  4756. dragItem = -1;
  4757. ui::hideValueTip();
  4758. repaint();
  4759. }
  4760. }
  4761. void mouseDoubleClick (const juce::MouseEvent& e) override
  4762. {
  4763. const auto index = itemAt (e.position);
  4764. if (index < 0)
  4765. return;
  4766. const auto& item = activeLayout().items[(std::size_t) index];
  4767. if (isRhythmEdit (item)) // round 144: add / remove a tap
  4768. {
  4769. rhythmDoubleClick (e, item);
  4770. return;
  4771. }
  4772. if (isRhythmPatterns (item) || isWaveShaperGraph (item) || isGbAny (item) || isMaximusCurve (item) || isPhilterCurve (item))
  4773. return;
  4774. if (isGeminiGraph (item)) // round 137: an EQ marker = its shelf on / off
  4775. {
  4776. if (juce::String (item.display) == "geminieq")
  4777. if (const auto k = geminiNearest (item, e.position); k >= 0)
  4778. {
  4779. const auto h = geminiHandles (item)[(std::size_t) k];
  4780. setParams ({ { h.on, valueOf (h.on) >= 0.5f ? 0.0f : 1.0f } });
  4781. }
  4782. return;
  4783. }
  4784. if (item.type == Item::display) // EQ graph: the band under the mouse back to 0 dB
  4785. {
  4786. if (const auto* fx = current(); fx != nullptr)
  4787. if (const auto b = peqview::bandAt (eqGraph (rectOf (item)), fx->params, e.position, eqRange); b >= 0)
  4788. setParams ({ { peq::param (b, 2), 0.5f } });
  4789. return;
  4790. }
  4791. if (item.type == Item::radio || item.type == Item::tabs || item.type == Item::toggle || item.type == Item::menu || paramOf (item) < 0)
  4792. return;
  4793. const auto spec = specFor (item);
  4794. setValue (paramOf (item), (float) spec.defaultValue);
  4795. }
  4796. // --- steppers (round 170c, issue #14: "Oversampling: Off" could not be changed on a Mac) --------------------
  4797. // A stepper with a short list of values (its `steps` = the last value's index, 1…64) works like FL's value selectors:
  4798. // the arrows step one value, a click on the value lists them all (a menu; the right-click menu lists them too, above
  4799. // the usual parameter items), a vertical drag moves one value per stepperDragPixels, the wheel one value per notch and a
  4800. // trackpad one value per stepperTrackpadDelta of accumulated scroll (a Mac trackpad sends many tiny smooth deltas).
  4801. static constexpr float stepperDragPixels = 10.0f, stepperTrackpadDelta = 0.12f;
  4802. static bool listedStepper (const LayoutItem& item) noexcept { return item.type == Item::stepper && item.steps > 0 && item.steps <= 64; }
  4803. juce::Rectangle<float> stepperBox (const LayoutItem& item) const
  4804. {
  4805. auto box = rectOf (item);
  4806. if (item.label != nullptr && ! hasStyle (item, plugui::noCaption))
  4807. box.removeFromTop (12.0f * scale());
  4808. return box;
  4809. }
  4810. juce::Rectangle<float> stepperArrows (const LayoutItem& item) const
  4811. {
  4812. auto box = stepperBox (item);
  4813. return box.removeFromRight (juce::jmin (12.0f * scale(), box.getWidth() * 0.4f));
  4814. }
  4815. // the arrows' hit area: at least 10 px wide (the drawn arrows of a small stepper are narrower), never the whole box
  4816. int stepperArrowAt (const LayoutItem& item, juce::Point<float> p) const
  4817. {
  4818. const auto box = stepperBox (item);
  4819. const auto drawn = stepperArrows (item);
  4820. const auto hit = box.withLeft (juce::jmax (box.getX() + box.getWidth() * 0.5f, juce::jmin (drawn.getX(), box.getRight() - 10.0f * scale())));
  4821. if (! hit.contains (p))
  4822. return 0;
  4823. return p.y < box.getCentreY() ? 1 : -1;
  4824. }
  4825. float stepperValue (const LayoutItem& item, int index) const { return juce::jlimit (0.0f, 1.0f, (float) index / (float) item.steps); }
  4826. int stepperIndex (const LayoutItem& item, float value) const { return juce::jlimit (0, item.steps, juce::roundToInt (value * (float) item.steps)); }
  4827. void stepStepper (const LayoutItem& item, int delta)
  4828. {
  4829. const auto param = paramOf (item);
  4830. if (param < 0 || delta == 0)
  4831. return;
  4832. const auto step = item.steps > 0 ? 1.0f / (float) item.steps : 0.01f;
  4833. const auto v = listedStepper (item) ? stepperValue (item, stepperIndex (item, valueOf (param)) + delta)
  4834. : juce::jlimit (0.0f, 1.0f, valueOf (param) + (float) delta * step);
  4835. setValue (param, v);
  4836. ui::reportTweak (specFor (item));
  4837. ui::flashValueTip (*this, rectOf (item).toNearestInt(), valueText (param, valueOf (param)));
  4838. }
  4839. // every value of a listed stepper, the current one ticked (FL's value selectors list theirs)
  4840. juce::PopupMenu stepperMenu (const LayoutItem& item)
  4841. {
  4842. juce::PopupMenu menu;
  4843. const auto param = paramOf (item);
  4844. if (param < 0 || ! listedStepper (item))
  4845. return menu;
  4846. const auto now = stepperIndex (item, valueOf (param));
  4847. for (int k = 0; k <= item.steps; ++k)
  4848. menu.addItem (valueText (param, stepperValue (item, k)), true, k == now,
  4849. [safe = juce::Component::SafePointer<NativeEffectEditor> (this), param, v = stepperValue (item, k)] {
  4850. if (safe != nullptr)
  4851. safe->setValue (param, v);
  4852. });
  4853. return menu;
  4854. }
  4855. void showStepperMenu (const LayoutItem& item, bool withParameterItems)
  4856. {
  4857. auto menu = stepperMenu (item);
  4858. if (menu.getNumItems() == 0)
  4859. return;
  4860. const auto param = paramOf (item);
  4861. const auto spec = specFor (item);
  4862. if (withParameterItems)
  4863. {
  4864. menu.addSeparator();
  4865. ui::addValueItems (menu, *this, &engine, spec, valueOf (param), [safe = juce::Component::SafePointer<NativeEffectEditor> (this), param] (double v) {
  4866. if (safe != nullptr)
  4867. safe->setValue (param, (float) v);
  4868. });
  4869. }
  4870. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (stepperBox (item).toNearestInt())));
  4871. }
  4872. public:
  4873. // Round 170c (#14): every stepper of the current page driven by synthetic input — a click on each arrow, a click on
  4874. // the value (its menu), a drag up and down, wheel notches, trackpad scrolls. One line per stepper: OK / FAIL and why.
  4875. juce::String stepperSelfTest()
  4876. {
  4877. juce::String report;
  4878. const auto source = juce::Desktop::getInstance().getMainMouseSource();
  4879. const auto& items = activeLayout().items;
  4880. for (std::size_t i = 0; i < items.size(); ++i)
  4881. {
  4882. const auto& item = items[i];
  4883. if (item.type != Item::stepper || ! visible (item))
  4884. continue;
  4885. const auto param = paramOf (item);
  4886. juce::String line = juce::String (effectInfo (kind).name) + " / " + (item.param != nullptr ? item.param : "?") + " (steps " + juce::String (item.steps) + "): ";
  4887. if (param < 0)
  4888. {
  4889. report << line << "FAIL no parameter\n";
  4890. continue;
  4891. }
  4892. // a control kept in FL's state (Maximus, Vocodex...) is editable only once the slot has FL's state
  4893. if (isStateParam (param) && current() != nullptr && ! stateTable().get (current()->state, plugui::stateIndex (kind, param)))
  4894. {
  4895. report << line << "SKIP state-backed, the slot has no FL state\n";
  4896. continue;
  4897. }
  4898. juce::StringArray fails;
  4899. const auto now = juce::Time::getCurrentTime();
  4900. auto event = [&] (juce::Point<float> p, juce::ModifierKeys mods, std::optional<juce::Point<float>> down = {}) {
  4901. return juce::MouseEvent (source, p, mods, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, this, this, now, down.value_or (p), now, 1, false);
  4902. };
  4903. const auto left = juce::ModifierKeys (juce::ModifierKeys::leftButtonModifier);
  4904. // (a state parameter's edit reaches the slot through the engine's message queue)
  4905. auto settle = [this] { engine.dispatchPendingMessages(); };
  4906. auto set = [&] (float v) { setValue (param, v); settle(); };
  4907. auto click = [&] (juce::Point<float> p) {
  4908. mouseDown (event (p, left));
  4909. mouseUp (event (p, juce::ModifierKeys()));
  4910. juce::PopupMenu::dismissAllActiveMenus();
  4911. settle();
  4912. };
  4913. const auto box = stepperBox (item);
  4914. const auto arrows = stepperArrows (item);
  4915. const auto upAt = juce::Point<float> (arrows.getCentreX(), box.getY() + box.getHeight() * 0.25f);
  4916. const auto downAt = juce::Point<float> (arrows.getCentreX(), box.getY() + box.getHeight() * 0.75f);
  4917. const auto body = juce::Point<float> (box.getX() + juce::jmax (2.0f, (arrows.getX() - box.getX()) * 0.5f), box.getCentreY());
  4918. const auto start = valueOf (param);
  4919. const auto low = 0.0f;
  4920. // arrows: from the lowest value, up then down
  4921. set (low);
  4922. click (upAt);
  4923. const auto afterUp = valueOf (param);
  4924. if (! (afterUp > low))
  4925. fails.add ("up arrow");
  4926. click (downAt);
  4927. if (std::abs (valueOf (param) - low) > 1.0e-4f)
  4928. fails.add ("down arrow (" + valueText (param, low) + " -> " + valueText (param, afterUp) + " -> " + valueText (param, valueOf (param))
  4929. + ", raw " + juce::String (afterUp, 4) + " / " + juce::String (valueOf (param), 4) + ")");
  4930. if (listedStepper (item))
  4931. {
  4932. // the value's menu: every value, choosing the last one sets it
  4933. auto menu = stepperMenu (item);
  4934. if (menu.getNumItems() != item.steps + 1)
  4935. fails.add ("menu has " + juce::String (menu.getNumItems()) + " items");
  4936. std::function<void()> last;
  4937. for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
  4938. last = it.getItem().action;
  4939. if (last)
  4940. last();
  4941. settle();
  4942. if (std::abs (valueOf (param) - 1.0f) > 1.0e-4f)
  4943. fails.add ("menu choice");
  4944. // a click on the value opens it (and changes nothing by itself)
  4945. set (low);
  4946. stepperMenusShown = 0;
  4947. click (body);
  4948. if (stepperMenusShown != 1)
  4949. fails.add ("click on the value shows no menu");
  4950. if (std::abs (valueOf (param) - low) > 1.0e-4f)
  4951. fails.add ("click on the value changed it");
  4952. // drag up three values, then back down
  4953. set (low);
  4954. mouseDown (event (body, left));
  4955. mouseDrag (event (body.translated (0.0f, -3.4f * stepperDragPixels), left, body));
  4956. settle();
  4957. const auto dragged = stepperIndex (item, valueOf (param));
  4958. mouseDrag (event (body, left, body));
  4959. mouseUp (event (body, juce::ModifierKeys(), body));
  4960. juce::PopupMenu::dismissAllActiveMenus();
  4961. settle();
  4962. if (dragged != juce::jmin (3, item.steps))
  4963. fails.add ("drag up gave value " + juce::String (dragged));
  4964. if (stepperIndex (item, valueOf (param)) != 0)
  4965. fails.add ("drag back");
  4966. // a wheel notch up, then a trackpad scroll (many small smooth deltas) up
  4967. set (low);
  4968. juce::MouseWheelDetails notch { 0.0f, 0.15f, false, false, false };
  4969. mouseWheelMove (event (body, juce::ModifierKeys()), notch);
  4970. settle();
  4971. if (stepperIndex (item, valueOf (param)) != 1)
  4972. fails.add ("wheel notch gave value " + juce::String (stepperIndex (item, valueOf (param))));
  4973. set (low);
  4974. stepperWheel = 0.0f;
  4975. juce::MouseWheelDetails pad { 0.0f, 0.02f, false, true, false };
  4976. for (int k = 0; k < 7; ++k)
  4977. {
  4978. mouseWheelMove (event (body, juce::ModifierKeys()), pad);
  4979. settle();
  4980. }
  4981. if (stepperIndex (item, valueOf (param)) != 1)
  4982. fails.add ("trackpad scroll gave value " + juce::String (stepperIndex (item, valueOf (param))));
  4983. }
  4984. set (start);
  4985. report << line << (fails.isEmpty() ? juce::String ("OK") : "FAIL " + fails.joinIntoString (", ")) << "\n";
  4986. }
  4987. return report;
  4988. }
  4989. private:
  4990. int stepperMenusShown = 0; // (the self-test counts the menus a click opens)
  4991. float stepperWheel = 0.0f; // a trackpad's accumulated scroll over a listed stepper
  4992. int stepperDragIndex = -1; // the value a drag started from (-1 = no stepper drag)
  4993. int portDragStart = -2; // round 190ez: Pitcher's MIDI port when its drag started (-2 = no drag)
  4994. float portDragY = 0.0f;
  4995. bool stepperMoved = false; // that drag moved (then its mouse-up opens no menu)
  4996. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  4997. {
  4998. const auto index = itemAt (e.position);
  4999. if (index < 0)
  5000. return;
  5001. const auto& item = activeLayout().items[(std::size_t) index];
  5002. if (isWaveShaperGraph (item) || isGbAny (item) || isMaximusCurve (item) || isPhilterCurve (item))
  5003. return;
  5004. if (item.type == Item::display && juce::String (item.display) == "tssenvelope") // FL's envelope view speed
  5005. {
  5006. if (auto* view = const_cast<transmitter::EnvelopeView*> (transmitter::envelopeOf (runningEffect().get())))
  5007. {
  5008. const auto speed = juce::jlimit (0, 100, view->speed.load() + (wheel.deltaY > 0 ? 2 : -2));
  5009. view->speed.store (speed);
  5010. view->columnLength.store (transmitter::columnSamples (juce::jmax (1.0, engine.getTransport().sampleRate.load()), speed));
  5011. repaint();
  5012. }
  5013. return;
  5014. }
  5015. if (item.type == Item::display) // EQ graph: Q / bandwidth of the band under the mouse (or the selected one)
  5016. {
  5017. const auto* fx = current();
  5018. if (fx == nullptr)
  5019. return;
  5020. auto b = peqview::bandAt (eqGraph (rectOf (item)), fx->params, e.position, eqRange);
  5021. if (b < 0)
  5022. b = eqSelected;
  5023. if (b < 0)
  5024. return;
  5025. eqSelected = b;
  5026. const auto q = fx->params[(std::size_t) peq::param (b, 3)];
  5027. // wheel up = narrower; FL's width grows the other way
  5028. const auto step = peq::flLaw (fx->params) ? -wheel.deltaY * 0.15f : wheel.deltaY * 0.15f;
  5029. setParams ({ { peq::param (b, 3), q + step } });
  5030. return;
  5031. }
  5032. const auto param = paramOf (item);
  5033. if (param < 0)
  5034. return;
  5035. auto spec = specFor (item);
  5036. if (item.type == Item::radio || item.type == Item::tabs)
  5037. {
  5038. const auto n = (int) plugui::optionLabels (item).size();
  5039. const auto o = plugui::optionAt (item, valueOf (param)) + (wheel.deltaY > 0 ? (item.type == Item::radio ? -1 : 1) : (item.type == Item::radio ? 1 : -1));
  5040. setValue (param, plugui::optionValue (item, juce::jlimit (0, n - 1, o)));
  5041. return;
  5042. }
  5043. if (listedStepper (item)) // round 170c (#14): one value per notch; a trackpad's small deltas add up to one
  5044. {
  5045. const auto delta = std::abs (wheel.deltaY) >= std::abs (wheel.deltaX) ? wheel.deltaY : -wheel.deltaX;
  5046. if (delta == 0.0f || ui::wheelScrolling())
  5047. return;
  5048. const auto sign = wheel.isReversed ? -1.0f : 1.0f;
  5049. if (! wheel.isSmooth)
  5050. {
  5051. stepStepper (item, delta * sign > 0.0f ? 1 : -1);
  5052. return;
  5053. }
  5054. stepperWheel += delta * sign;
  5055. if (std::abs (stepperWheel) >= stepperTrackpadDelta)
  5056. {
  5057. stepStepper (item, stepperWheel > 0.0f ? 1 : -1);
  5058. stepperWheel = 0.0f;
  5059. }
  5060. return;
  5061. }
  5062. if (item.type == Item::stepper && item.steps > 1000 && wheel.deltaY != 0.0f) // a fine count (the hardware insert's delay in samples): one per notch, Shift ×10
  5063. {
  5064. const auto step = (e.mods.isShiftDown() ? 10.0f : 1.0f) / (float) item.steps;
  5065. setValue (param, juce::jlimit (0.0f, 1.0f, valueOf (param) + (wheel.deltaY > 0.0f ? step : -step)));
  5066. ui::flashValueTip (*this, rectOf (item).toNearestInt(), valueText (param, valueOf (param)));
  5067. return;
  5068. }
  5069. if (const auto v = ui::wheelValue (valueOf (param), e, wheel, spec))
  5070. {
  5071. setValue (param, (float) *v);
  5072. ui::flashValueTip (*this, rectOf (item).toNearestInt(), spec.text (*v));
  5073. }
  5074. }
  5075. ui::Hint hintAt (juce::Point<int> position) override
  5076. {
  5077. const auto p = position.toFloat();
  5078. switch (headerItemAt (p))
  5079. {
  5080. case 1: return { tr ("Options: presets, reset, bypass"), {}, false, true };
  5081. case 2: return { tr ("Preset: click for the list of FL presets of this plugin"), presetName, false, true };
  5082. case 3: return { tr ("Previous preset"), {}, false, false };
  5083. case 4: return { tr ("Next preset"), {}, false, false };
  5084. case 5: return { bar.hintFor (bar.partAt (p)), bar.presetLabel(), false, true };
  5085. case 6: return { tr ("Sidechain input: the insert this effect listens to. Picking one routes it here at level 0; it keeps its own outputs [LMB] choose"),
  5086. {}, false, true };
  5087. default: break;
  5088. }
  5089. const auto index = itemAt (p);
  5090. if (index < 0)
  5091. return {};
  5092. const auto& item = activeLayout().items[(std::size_t) index];
  5093. if (item.type == Item::display && juce::String (item.display) == "sgamount")
  5094. return { tr ("Amount: drag up or down (Ctrl: fine)"), juce::String (soundgoodizerAmount() * 100.0f, 0) + "%", false, false };
  5095. if (item.type == Item::display && juce::String (item.display) == "sgpresets")
  5096. return { sgApprox ? tr ("Soundgoodizer preset A to D (approximated: FL Studio's preset files were not found)")
  5097. : tr ("Soundgoodizer preset A to D (read from your FL installation)"), {}, false, false };
  5098. if (item.type == Item::display && juce::String (item.display) == "vumeter")
  5099. return { tr ("VU meter: click to show the gain reduction, the output or the input level"), vuMode == 2 ? tr ("Output") : vuMode == 1 ? tr ("Input") : tr ("Gain reduction"), false, false };
  5100. if (item.type == Item::display && juce::String (item.display) == "taptempo")
  5101. return { tr ("Tap tempo: click in time (two taps or more) to set the delay"), tapBpm > 0.0 ? juce::String (tapBpm, 1) + " BPM" : juce::String(), false, false };
  5102. if (item.type == Item::display && juce::String (item.display) == "iometer")
  5103. return { tr ("Input and output level (peak, dBFS); the numbers hold the highest peak; OUT turns red when the output clips; click to reset"), {}, false, false };
  5104. if (item.type == Item::display && juce::String (item.display) == "gcmeter")
  5105. return { tr ("Gain change (dB): down = reduction, up = the expansion's boost below 1:1; the number holds the largest change; click to reset"), {}, false, false };
  5106. if (item.type == Item::display && juce::String (item.display) == "limitpill")
  5107. return { tr ("Output limiter: lit while it keeps the output under 0 dBFS"), {}, false, false };
  5108. if (item.type == Item::display && juce::String (item.display) == "outmeter")
  5109. return { tr ("Output level (peak, dBFS): the lamp lights when the output clips, the number holds the highest peak; click to reset"), {}, false, false };
  5110. if (item.type == Item::display && juce::String (item.display) == "xy")
  5111. return { tr ("Drag the point: both values at once"), {}, false, false };
  5112. if (item.type == Item::display && juce::String (item.display) == "tunekeys") // round 147
  5113. return { tuneKeysHint (rectOf (item), p), {}, false, false };
  5114. if (isRhythmEdit (item)) // round 144
  5115. return { tr ("Rhythm taps: drag up / down = level, sideways = time; double-click = add or remove a tap; right-click = patterns"), {}, false, false };
  5116. if (isRhythmPatterns (item))
  5117. return { tr ("Load a tap pattern (LYNX SHARE's own), or go back to even spacing"), {}, false, false };
  5118. if (isWaveShaperGraph (item)) // round 165
  5119. return { wsHint (item, p), {}, false, true };
  5120. if (isMaximusCurve (item)) // round 168x
  5121. return { mxHint (item, p), {}, false, true };
  5122. if (isPhilterCurve (item)) // round 173d3
  5123. return { lpHint (item, p), {}, false, true };
  5124. if (item.type == Item::display && juce::String (item.display) == "pitchport") // round 190ez
  5125. return { tr ("MIDI input port number: drag up / down (\"...\" = none). The MIDI Out channels on this port play Pitcher's MIDI mode and Harmonize"), {}, false, false };
  5126. if (item.type == Item::display && juce::String (item.display) == "equosend") // round 173d3: FL's hint
  5127. return { tr ("Send track number"), current() != nullptr && current()->sendTracks[0] > 0 ? insertName (current()->sendTracks[0]) : juce::String ("---"), false, false };
  5128. if (isGbAny (item)) // round 168m
  5129. return { gbHint (item, p), {}, false, true };
  5130. if (item.type == Item::display)
  5131. return { tr ("Drag a handle (frequency and gain); mouse wheel = Q; right-click = type; double-click = 0 dB"), {}, false, true };
  5132. if (hasStyle (item, plugui::pageTabs))
  5133. return { tr ("Page: switch the controls shown"), {}, false, false };
  5134. if (isMixItem (item) && captionArea (item).contains (p))
  5135. return { tr ("MIX label: click to keep the Mix while presets change (mix lock)"), pluginheader::isMixLocked (kind) ? tr ("locked") : tr ("unlocked"), false, false };
  5136. const auto spec = specFor (item);
  5137. if (const auto* fx = current(); fx != nullptr && plugui::isIdle (kind, item, fx->params)) // round 170c
  5138. return { juce::String (spec.name) + ": " + tr ("no effect with the current mode (another engine is in use)"), spec.text (valueOf (paramOf (item))), false, false };
  5139. if (item.type == Item::stepper && item.steps > 0 && item.steps <= 64) // round 170c (issue #14)
  5140. return { juce::String (spec.name) + ": " + tr ("arrows step, click for the list, drag or mouse wheel to change"), spec.text (valueOf (paramOf (item))), false, false };
  5141. return ui::valueHint (spec, valueOf (paramOf (item)));
  5142. }
  5143. // --- presets ---------------------------------------------------------------------------------------
  5144. juce::Array<juce::File> presetFiles() const
  5145. {
  5146. juce::Array<juce::File> all;
  5147. const auto roots = findFlStudioRoots();
  5148. if (roots.data.empty() || layout == &plugui::soundgoodizerLayout()) // Soundgoodizer: its presets A–D are on the page
  5149. return all;
  5150. // FL's list and order (round 167o, FLEngine 0x12b6c70 / 0x662a40): FL's folder and the user's merged, a
  5151. // folder's own presets before its subfolders, numbers as numbers
  5152. for (const auto& plugin : flPluginsForEffect (kind))
  5153. for (const auto& p : presetcycle::listPresets (presetcycle::pluginPresetFolders (roots, false, plugin)))
  5154. all.add (juce::File (juce::String::fromUTF8 (p.path.c_str())));
  5155. return all;
  5156. }
  5157. void loadPreset (const juce::File& f)
  5158. {
  5159. juce::MemoryBlock data;
  5160. if (! f.loadFileAsData (data))
  5161. return;
  5162. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  5163. auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm, natives::flDataReader (flStudioAccess()));
  5164. if (! fx || fx->kind != kind)
  5165. return;
  5166. presetName = f.getFileNameWithoutExtension();
  5167. if (usesBar())
  5168. {
  5169. bar.beginGesture();
  5170. bar.willEdit();
  5171. fx->presetName = presetName.toStdString();
  5172. }
  5173. engine.editSong ([t = track, s = slot, fx = *fx] (Song& song) {
  5174. auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) s];
  5175. const auto enabled = target.enabled;
  5176. const auto mix = target.mix;
  5177. target = fx;
  5178. target.enabled = enabled;
  5179. target.mix = mix;
  5180. });
  5181. repaint();
  5182. }
  5183. void stepPreset (int delta)
  5184. {
  5185. const auto files = presetFiles();
  5186. if (files.isEmpty())
  5187. return;
  5188. auto at = -1;
  5189. for (int i = 0; i < files.size(); ++i)
  5190. if (files[i].getFileNameWithoutExtension() == presetName)
  5191. at = i;
  5192. at = presetcycle::step (at, delta, files.size());
  5193. loadPreset (files[at]);
  5194. ui::postHint ({ presetName, juce::String (presetcycle::positionText (at, files.size())) }, 2500); // FL's "n / N"
  5195. }
  5196. // FL's factory presets of this plugin, in folders (the header's preset menu)
  5197. void addFlPresets (juce::PopupMenu& presets)
  5198. {
  5199. const auto files = presetFiles();
  5200. std::map<juce::String, juce::PopupMenu> folders;
  5201. for (const auto& f : files)
  5202. folders[f.getParentDirectory().getFileName()].addItem (f.getFileNameWithoutExtension(), true, f.getFileNameWithoutExtension() == presetName,
  5203. [this, f] { loadPreset (f); });
  5204. if (folders.size() == 1)
  5205. presets = folders.begin()->second;
  5206. else
  5207. for (auto& [name, menu] : folders)
  5208. presets.addSubMenu (name, menu);
  5209. }
  5210. void showOptionsMenu (bool presetsOnly)
  5211. {
  5212. juce::PopupMenu presets;
  5213. const auto files = presetFiles();
  5214. std::map<juce::String, juce::PopupMenu> folders;
  5215. const auto roots = findFlStudioRoots();
  5216. for (const auto& f : files)
  5217. {
  5218. const auto folder = f.getParentDirectory().getFileName();
  5219. auto& menu = folders[folder];
  5220. menu.addItem (f.getFileNameWithoutExtension(), true, f.getFileNameWithoutExtension() == presetName, [this, f] { loadPreset (f); });
  5221. }
  5222. if (folders.size() == 1)
  5223. presets = folders.begin()->second;
  5224. else
  5225. for (auto& [name, menu] : folders)
  5226. presets.addSubMenu (name, menu);
  5227. if (presetsOnly)
  5228. {
  5229. if (presets.getNumItems() == 0)
  5230. presets.addItem (tr ("No FL presets found for this plugin"), false, false, [] {});
  5231. presets.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (presetBox().toNearestInt())));
  5232. return;
  5233. }
  5234. juce::PopupMenu menu;
  5235. if (presets.getNumItems() > 0)
  5236. menu.addSubMenu (tr ("Presets"), presets);
  5237. if (showsSidechain()) // round 177b
  5238. {
  5239. juce::PopupMenu side;
  5240. pluginheader::addSidechainPicker (side, engine, track, slot);
  5241. menu.addSubMenu (kind == EffectKind::vocoder || kind == EffectKind::vocodex ? tr ("Modulator from") : tr ("Sidechain from"), side);
  5242. }
  5243. skin::addStyleMenu (menu, styleKey(), [safe = juce::Component::SafePointer<NativeEffectEditor> (this)] {
  5244. if (safe != nullptr) safe->repaint();
  5245. });
  5246. menu.addItem (tr ("Reset to defaults"), [this] {
  5247. const auto& info = effectInfo (kind);
  5248. presetName = {};
  5249. if (usesBar())
  5250. {
  5251. bar.beginGesture();
  5252. bar.willEdit();
  5253. }
  5254. auto bytes = current() != nullptr ? current()->state : std::vector<std::uint8_t> {};
  5255. if (stateBacked())
  5256. {
  5257. const auto& table = stateTable();
  5258. for (int p = 0; p < (int) table.params.size(); ++p)
  5259. bytes = table.with (bytes, p, table.params[(std::size_t) p].defaultValue);
  5260. }
  5261. engine.editSong ([t = track, s = slot, info, bytes, state = stateBacked()] (Song& song) {
  5262. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) s];
  5263. for (std::size_t i = 0; i < info.params.size() && i < fx.params.size(); ++i)
  5264. fx.params[i] = info.params[i].defaultValue;
  5265. fx.presetName.clear();
  5266. if (state)
  5267. fx.state = bytes;
  5268. });
  5269. });
  5270. // switches that FL keeps out of the panel (in its own menus): on / off here
  5271. if (! activeLayout().menuSwitches.empty())
  5272. {
  5273. menu.addSeparator();
  5274. for (const auto* name : activeLayout().menuSwitches)
  5275. if (const auto p = plugui::paramIndex (kind, name); p >= 0)
  5276. {
  5277. const auto on = valueOf (p) >= 0.5f;
  5278. menu.addItem (utf8 (name), true, on, [this, p, on] { setValue (p, on ? 0.0f : 1.0f); });
  5279. }
  5280. menu.addSeparator();
  5281. }
  5282. const auto* fx = current();
  5283. // (round 190ez: the MIDI input port of the effects that take notes left this menu, as FL 2026's wrapper menu
  5284. // has none: Pitcher sets it in its own panel's bottom line, Gross Beat in its Options menu, live FL check 190ew)
  5285. menu.addItem (tr ("Bypass"), true, fx != nullptr && ! fx->enabled, [this] {
  5286. editSlot ([] (EffectSlot& target) { target.enabled = ! target.enabled; });
  5287. });
  5288. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withTargetScreenArea (localAreaToGlobal (menuButton().toNearestInt())));
  5289. }
  5290. // None, Port 0 … 31 (the plugin wrapper menu's list; a port set higher, e.g. by an FL project, is listed too)
  5291. juce::PopupMenu midiPortMenu()
  5292. {
  5293. const auto* fx = current();
  5294. const auto now = fx != nullptr ? effectMidiInPort (*fx) : -1;
  5295. juce::PopupMenu ports;
  5296. auto set = [this] (int port) { editSlot ([port] (EffectSlot& target) { setEffectMidiInPort (target, port); }); };
  5297. ports.addItem (tr ("None"), true, now < 0, [set] { set (-1); });
  5298. for (int port = 0; port < 32; ++port)
  5299. ports.addItem (tr ("Port {0}", { juce::String (port) }), true, now == port, [set, port] { set (port); });
  5300. if (now >= 32)
  5301. ports.addItem (tr ("Port {0}", { juce::String (now) }), true, true, [] {});
  5302. return ports;
  5303. }
  5304. private:
  5305. void changeListenerCallback (juce::ChangeBroadcaster*) override { repaint(); }
  5306. public:
  5307. // round 166f: the analyser part of the timer, for off-screen pictures (--eq166fshot)
  5308. void tickDisplaysForSnapshot()
  5309. {
  5310. if (kind == EffectKind::parametricEq && ! node.locate)
  5311. for (const auto& item : activeLayout().items)
  5312. if (item.type == Item::display && item.display != nullptr && std::strcmp (item.display, "eq") == 0)
  5313. eqAnalyser.update (engine, track, slot, true, eqGraph (rectOf (item)));
  5314. }
  5315. private:
  5316. void timerCallback() override
  5317. {
  5318. if (! isShowing()) return; // a hidden editor costs nothing
  5319. if (! node.locate && shownSlot.changed (engine.getAutomationDisplay(), track, slot)) // the controls follow their automation
  5320. repaint();
  5321. if (levelMeter && ! node.locate) // the dynamics curves' live trail (the wells themselves: levelFrame)
  5322. {
  5323. levelTrail[(std::size_t) levelTrailAt] = { levelDb[0], levelDb[1] };
  5324. levelTrailAt = (levelTrailAt + 1) % (int) levelTrail.size();
  5325. }
  5326. if (kind == EffectKind::parametricEq && ! node.locate) // round 166f: the spectrum / heatmap of the EQ's output
  5327. for (const auto& item : activeLayout().items)
  5328. if (item.type == Item::display && item.display != nullptr && std::strcmp (item.display, "eq") == 0)
  5329. {
  5330. const auto graph = eqGraph (rectOf (item));
  5331. if (eqAnalyser.update (engine, track, slot, isMouseOver (true) || hasKeyboardFocus (true), graph))
  5332. repaint (graph.getSmallestIntegerContainer().expanded (2));
  5333. }
  5334. if (! liveDisplays) return;
  5335. learnScaleFromMidi();
  5336. if (kind == EffectKind::hardwareInsert)
  5337. hwPingTick();
  5338. if (kind == EffectKind::transmitter) // the envelope view scrolls while columns arrive
  5339. {
  5340. const auto* view = transmitter::envelopeOf (runningEffect().get());
  5341. const auto written = view != nullptr ? view->written.load (std::memory_order_relaxed) : 0u;
  5342. if (written != envelopeSeen)
  5343. {
  5344. envelopeSeen = written;
  5345. for (const auto& item : activeLayout().items)
  5346. if (item.type == Item::display && item.display != nullptr && std::strcmp (item.display, "tssenvelope") == 0 && visible (item))
  5347. repaint (rectOf (item).getSmallestIntegerContainer());
  5348. }
  5349. return;
  5350. }
  5351. // an idle display (silent track: meters unchanged for longer than the longest history) is not redrawn
  5352. float meters = 0.0f;
  5353. for (int k = 0; k < 6; ++k) meters += liveMeter (k) * (float) (k + 1);
  5354. quietFrames = std::abs (meters - lastMeters) > 1e-6f ? 0 : quietFrames + 1;
  5355. lastMeters = meters;
  5356. if (quietFrames > 300 && ! demoDisplays) return;
  5357. bool history = false;
  5358. for (const auto& item : activeLayout().items)
  5359. {
  5360. if (item.type == Item::display && item.display != nullptr && (std::strcmp (item.display, "pitchgraph") == 0 || std::strcmp (item.display, "pitchtrace") == 0
  5361. || (std::strcmp (item.display, "pitchring") == 0 && ! pitchTraced())) && visible (item))
  5362. {
  5363. if (std::strcmp (item.display, "pitchring") == 0 || std::strcmp (item.display, "pitchtrace") == 0)
  5364. {
  5365. // round 128: what is sung, for AUTO KEY (time per pitch class, fading over ~30 s)
  5366. for (auto& x : keyHistogram)
  5367. x *= 0.999;
  5368. if (const auto sungNote = liveMeter (0) * 127.0f; sungNote > 0.5f)
  5369. keyHistogram[(std::size_t) (((int) std::lround (sungNote) % 12 + 12) % 12)] += 1.0;
  5370. if (autoKeyFlash > 0)
  5371. --autoKeyFlash;
  5372. if (tuneSendFlash > 0 && --tuneSendFlash == 0) // round 150
  5373. repaint();
  5374. }
  5375. // LYNX Tune's pitch history (30 points a second)
  5376. pitchHistory.push_back ({ liveMeter (0) * 127.0f, liveMeter (1) * 127.0f, (liveMeter (2) - 0.5f) * 4.0f });
  5377. if (pitchHistory.size() > pitchHistoryLength)
  5378. pitchHistory.erase (pitchHistory.begin(), pitchHistory.begin() + (std::ptrdiff_t) (pitchHistory.size() - pitchHistoryLength));
  5379. repaint (rectOf (item).getSmallestIntegerContainer());
  5380. }
  5381. if (item.type == Item::display && item.display != nullptr && (std::strcmp (item.display, "grmeter") == 0 || std::strcmp (item.display, "grleds") == 0 || std::strcmp (item.display, "vumeter") == 0 || std::strcmp (item.display, "iometer") == 0 || std::strcmp (item.display, "outmeter") == 0 || std::strcmp (item.display, "limitpill") == 0 || std::strcmp (item.display, "gcmeter") == 0 || std::strcmp (item.display, "pitchring") == 0 || dynui::isLive (item.display)) && visible (item))
  5382. {
  5383. history = history || std::strcmp (item.display, "grhistory") == 0;
  5384. repaint (rectOf (item).getSmallestIntegerContainer());
  5385. }
  5386. }
  5387. if (history)
  5388. dynHistory.push (liveMeter (0), liveMeter (2), liveMeter (3));
  5389. for (const auto& item : activeLayout().items) // round 168r: the Peak Controller's outputs scroll
  5390. if (item.type == Item::display && designui::isLive (item.display) && visible (item))
  5391. {
  5392. designHistory.push (liveMeter (0), liveMeter (1), liveMeter (2));
  5393. repaint (rectOf (item).getSmallestIntegerContainer());
  5394. break;
  5395. }
  5396. }
  5397. designui::History designHistory; // round 168r: the Peak Controller's outputs (peakmeter)
  5398. std::uint32_t envelopeSeen = 0; // the Transmitter's envelope columns already drawn
  5399. AudioEngine& engine;
  5400. int track, slot;
  5401. NodeTarget node;
  5402. EffectKind kind = EffectKind::eq;
  5403. const plugui::Layout* layout = nullptr;
  5404. int page = 0;
  5405. int hoverItem = -1, hoverHeader = 0, dragItem = -1;
  5406. juce::Colour accent { skin::colour::crimson }; // the plugin family's accent (ui/PluginSkin.h); the art's when Themed
  5407. juce::Colour familyAccent { skin::colour::crimson };
  5408. std::unique_ptr<skin::ArtLayer> artLayer; // round 170j: the art's moving part
  5409. skin::Animator anim; // hover fades (runs only while something moves)
  5410. int quietFrames = 1000; // frames since the live meters last moved (the displays start at rest)
  5411. float lastMeters = 0.0f;
  5412. bool liveDisplays = false; // the layout has live meters / graphs (redrawn by the timer)
  5413. // round 170c: the "meter" wells' live levels (dBFS: input, output), their holds and the slot's key
  5414. bool levelMeter = false;
  5415. std::array<float, 2> levelDb { -60.0f, -60.0f }, levelHoldDb { -60.0f, -60.0f };
  5416. std::array<double, 2> levelHoldMs { 0.0, 0.0 };
  5417. std::array<std::pair<float, float>, 45> levelTrail {};
  5418. int levelTrailAt = 0;
  5419. double levelFrameMs = 0.0;
  5420. // round 170c: the level meter wells (input / output peaks, held 1 s, falling 24 dB/s); round 174e: at the display's
  5421. // refresh (they were on the 30 Hz timer), only the wells
  5422. bool levelFrame (double nowMs)
  5423. {
  5424. if (! levelMeter || node.locate)
  5425. return false;
  5426. auto* times = engine.getProcessTimes();
  5427. if (times == nullptr || levelKey() >= times->levelWanted.size())
  5428. return false;
  5429. const auto elapsed = levelFrameMs > 0.0 ? juce::jlimit (0.0, 250.0, nowMs - levelFrameMs) : 1000.0 / 30.0;
  5430. levelFrameMs = nowMs;
  5431. const auto fall = (float) (24.0 * elapsed / 1000.0);
  5432. bool moved = false;
  5433. for (int k = 0; k < 2; ++k)
  5434. {
  5435. const auto peak = times->slotLevels[levelKey() * 2 + (std::size_t) k].exchange (0.0f, std::memory_order_relaxed);
  5436. const auto db = juce::jlimit (-60.0f, 6.0f, juce::Decibels::gainToDecibels (peak, -100.0f));
  5437. auto& shown = levelDb[(std::size_t) k];
  5438. auto& hold = levelHoldDb[(std::size_t) k];
  5439. const auto before = shown, holdBefore = hold;
  5440. shown = db >= shown ? db : juce::jmax (db, shown - fall);
  5441. if (db >= hold)
  5442. {
  5443. hold = db;
  5444. levelHoldMs[(std::size_t) k] = 1000.0;
  5445. }
  5446. else if ((levelHoldMs[(std::size_t) k] -= elapsed) < 0.0)
  5447. hold = juce::jmax (shown, hold - fall);
  5448. moved = moved || std::abs (shown - before) > 0.01f || std::abs (hold - holdBefore) > 0.01f;
  5449. }
  5450. if (moved)
  5451. for (const auto& item : activeLayout().items)
  5452. if (item.type == Item::display && item.display != nullptr && levelDisplay (item.display) && visible (item))
  5453. repaint (rectOf (item).getSmallestIntegerContainer().expanded (2));
  5454. return moved;
  5455. }
  5456. static bool levelDisplay (const char* id)
  5457. {
  5458. return std::strcmp (id, "meter") == 0 || std::strcmp (id, "limiter") == 0 || std::strcmp (id, "compressor") == 0 || std::strcmp (id, "dynamics") == 0;
  5459. }
  5460. std::size_t levelKey() const { return (std::size_t) juce::jmax (0, track) * (std::size_t) maxEffectSlots + (std::size_t) juce::jmax (0, slot); }
  5461. mutable ShownEffectSlot shownSlot; // the slot with its automation's values (current())
  5462. ui::ValueDrag drag;
  5463. ui::FrameTicker levelFrames { *this, [this] (double ms) { return levelFrame (ms); } };
  5464. juce::String presetName;
  5465. pluginheader::PresetBar bar { engine, track, slot }; // undo / redo, A / B, presets (round 129)
  5466. peqview::Analyser eqAnalyser; // round 166f: Parametric EQ 2's spectrum and heatmap
  5467. int eqSelected = -1;
  5468. bool eqDragging = false, xyDragging = false, sgDragging = false;
  5469. struct PitchPoint { float sung, target, shift; }; // MIDI note numbers (0 = none) and the applied correction in semitones
  5470. static constexpr std::size_t pitchHistoryLength = 240; // 8 s
  5471. std::vector<PitchPoint> pitchHistory;
  5472. // LYNX Tune (round 128): HOLD, the keyboard's mode / latch, AUTO KEY's histogram
  5473. bool tuneHold = false, tuneRemove = true, tuneLatch = true;
  5474. int tuneHeldMap = -1; // round 152: the key-map parameter held while the key is down (latch off)
  5475. float tuneHeldMapValue = 0.0f;
  5476. PitchPoint holdPoint { 0.0f, 0.0f, 0.0f };
  5477. int tuneHeld = -1, autoKeyFlash = 0;
  5478. std::pair<float, float> tuneHeldValues { 1.0f, 0.0f };
  5479. float tuneHeldDir = 0.0f; // round 147
  5480. std::array<double, 12> keyHistogram {};
  5481. // is the scrolling pitch trace on the current page? (it then feeds the history; else the ring does)
  5482. bool pitchTraced() const
  5483. {
  5484. for (const auto& item : activeLayout().items)
  5485. if (item.type == Item::display && item.display != nullptr && std::strcmp (item.display, "pitchtrace") == 0 && visible (item))
  5486. return true;
  5487. return false;
  5488. }
  5489. float displayCentre = 0.0f;
  5490. float sgStart = 0.0f;
  5491. std::array<std::vector<std::uint8_t>, 4> sgPresets {}; // the installation's preset files A–D (read on demand)
  5492. bool sgApprox = false; // a Soundgoodizer approximation container (no FL preset files) shown on the Soundgoodizer page
  5493. juce::Point<float> eqDragOffset;
  5494. dynui::History dynHistory; // the dynamics suite's scrolling gain-reduction graph
  5495. int crossoverDrag = -1; // the crossover parameter being dragged on a band display
  5496. float vuNeedle = 0.0f; // the VU display's needle (dB below 0 VU, with inertia)
  5497. std::array<skin::Ballistics, 2> ioMeters {};
  5498. bool ioClip = false; // the "iometer" display's clip lamp (round 135w)
  5499. skin::Ballistics outMeter; // the "outmeter" display (round 135w): level, highest peak since the last click, clip lamp
  5500. float outMax = 0.0f;
  5501. bool outClip = false;
  5502. juce::uint32 lastTap = 0; // the tap pad (round 129)
  5503. std::vector<double> tapIntervals;
  5504. double tapBpm = 0.0; // the "iometer" display: input and output (round 129)
  5505. int vuMode = 0; // what the VU shows: 0 gain reduction, 1 input level, 2 output level (0 VU = −18 dBFS)
  5506. // round 165x: Glow keeps the VU display as a parameter (saved with the project, translated from the reference's state)
  5507. void syncVuMode()
  5508. {
  5509. if (kind == EffectKind::glowLeveler)
  5510. if (const auto* fx = current(); fx != nullptr && fx->params.size() > (std::size_t) mixsuite::glow::vuDisplay)
  5511. vuMode = mixsuite::glow::vuModeOf (fx->params[(std::size_t) mixsuite::glow::vuDisplay]);
  5512. }
  5513. void setVuMode (int mode)
  5514. {
  5515. vuMode = mode;
  5516. if (kind == EffectKind::glowLeveler && current() != nullptr)
  5517. setParams ({ { mixsuite::glow::vuDisplay, mode == 1 ? 0.5f : mode == 2 ? 1.0f : 0.0f } });
  5518. }
  5519. juce::Point<float> mouseAt { -1.0f, -1.0f };
  5520. };
  5521. // --- the window ------------------------------------------------------------------------------------
  5522. class NativeEffectWindow final : public juce::DocumentWindow
  5523. {
  5524. public:
  5525. NativeEffectWindow (AudioEngine& engine, int track, int slot, const juce::String& title)
  5526. : DocumentWindow (title, theme::colour::bg1, DocumentWindow::closeButton | DocumentWindow::minimiseButton),
  5527. gone (engine, track, slot, [this] { closeButtonPressed(); })
  5528. {
  5529. setUsingNativeTitleBar (true);
  5530. auto* editor = new NativeEffectEditor (engine, track, slot, 1.25f, 0);
  5531. const auto design = editor->designSize();
  5532. designWidth = design.x;
  5533. designHeight = design.y;
  5534. fixedHeight = editor->getHeight() - (int) std::ceil ((float) design.y * 1.25f); // (header and footer)
  5535. setContentOwned (editor, true);
  5536. setResizable (true, false);
  5537. // keep FL's proportions while resizing (the presets bar has a fixed height)
  5538. if (auto* c = getConstrainer())
  5539. {
  5540. c->setMinimumSize (juce::jmax (design.x / 2, editor->minimumWidth()), design.y / 2); // round 170k2: the name fits
  5541. c->setMaximumSize (design.x * 3, design.y * 3 + 200);
  5542. }
  5543. centreWithSize (getWidth(), getHeight());
  5544. setVisible (true);
  5545. markLinkedWindow (*this, -1, track); // FL's Auto select linked modules (round 187a)
  5546. dockOrKeepAbove (*this); // FL's docked plugin window (round 190ev)
  5547. skin::playOpenAnimation (*editor, editor->editorStyle()); // round 126: fade / scale in
  5548. }
  5549. ~NativeEffectWindow() override { editorlimit::forget (this); }
  5550. void closeButtonPressed() override;
  5551. // FL's plugin menu › Scaling (round 190he, core/EditorScale.h): 100 % … 400 % of the plugin's design size; LYNX opens
  5552. // it at 125 %. A right-click on the docked window's title bar (LYNX's own bar) shows it; the edge still sizes it freely.
  5553. void mouseDown (const juce::MouseEvent& e) override
  5554. {
  5555. if (e.mods.isPopupMenu() && e.eventComponent == this && ! isUsingNativeTitleBar() && e.y < getTitleBarHeight())
  5556. {
  5557. juce::PopupMenu sizes;
  5558. const auto* content = getContentComponent();
  5559. const auto now = content != nullptr ? editorscale::percentForWidth (content->getWidth(), (int) std::ceil (designWidth * 1.25)) : 0;
  5560. // FL's items (System left out: LYNX's interface already follows the display's scale); Host = LYNX's 125 %
  5561. sizes.addItem (tr ("Host"), true, false, [safe = juce::Component::SafePointer<NativeEffectWindow> (this)] {
  5562. if (safe != nullptr)
  5563. safe->setScalePercent (editorscale::defaultPercent);
  5564. });
  5565. for (const auto percent : editorscale::menuPercents)
  5566. sizes.addItem (juce::String (percent) + "%", true, percent == now, [safe = juce::Component::SafePointer<NativeEffectWindow> (this), percent] {
  5567. if (safe != nullptr)
  5568. safe->setScalePercent (percent);
  5569. });
  5570. juce::PopupMenu menu;
  5571. menu.addSubMenu (tr ("Scaling"), sizes);
  5572. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  5573. return;
  5574. }
  5575. juce::DocumentWindow::mouseDown (e);
  5576. }
  5577. void setScalePercent (int percent)
  5578. {
  5579. const auto f = (double) percent / 100.0;
  5580. setContentComponentSize (juce::roundToInt (designWidth * f), juce::roundToInt (designHeight * f) + fixedHeight);
  5581. }
  5582. void activeWindowStatusChanged() override
  5583. {
  5584. DocumentWindow::activeWindowStatusChanged();
  5585. if (isActiveWindow())
  5586. editorlimit::touch (this);
  5587. }
  5588. private:
  5589. ui::SlotGoneWatcher gone;
  5590. int designWidth = 1, designHeight = 1, fixedHeight = 0;
  5591. };
  5592. std::map<std::pair<int, int>, std::unique_ptr<NativeEffectWindow>>& windows()
  5593. {
  5594. static std::map<std::pair<int, int>, std::unique_ptr<NativeEffectWindow>> open;
  5595. return open;
  5596. }
  5597. void NativeEffectWindow::closeButtonPressed()
  5598. {
  5599. for (auto& [key, window] : windows())
  5600. if (window.get() == this)
  5601. {
  5602. juce::MessageManager::callAsync ([k = key] { windows().erase (k); });
  5603. return;
  5604. }
  5605. }
  5606. } // namespace
  5607. void setNativeEditorDemo (bool on)
  5608. {
  5609. demoDisplays = on;
  5610. }
  5611. juce::Point<int> nativeEditorMinimumSize (juce::Component& editor)
  5612. {
  5613. // as NativeEffectWindow's constrainer (the editor there is made at 1.25, its design size is the layout's)
  5614. auto* native = dynamic_cast<NativeEffectEditor*> (&editor);
  5615. if (native == nullptr) return {};
  5616. const auto design = native->designSize();
  5617. return { juce::jmax (design.x / 2, native->minimumWidth()), design.y / 2 };
  5618. }
  5619. bool tickNativeEffectEditor (juce::Component& editor)
  5620. {
  5621. auto* native = dynamic_cast<NativeEffectEditor*> (&editor);
  5622. if (native == nullptr) return false;
  5623. native->tickDisplaysForSnapshot();
  5624. return true;
  5625. }
  5626. std::unique_ptr<juce::Component> makeNativeEffectEditor (AudioEngine& engine, int track, int slot, float scale, int page)
  5627. {
  5628. return std::make_unique<NativeEffectEditor> (engine, track, slot, scale, page);
  5629. }
  5630. juce::String stepperSelfTest (AudioEngine& engine, int track, int slot, int pages)
  5631. {
  5632. juce::String report;
  5633. for (int page = 0; page < juce::jmax (1, pages); ++page)
  5634. {
  5635. NativeEffectEditor editor (engine, track, slot, 1.0f, page);
  5636. report << editor.stepperSelfTest();
  5637. }
  5638. return report;
  5639. }
  5640. std::unique_ptr<juce::Component> makeNodeEffectEditor (AudioEngine& engine, std::function<EffectSlot* (Song&)> locate,
  5641. std::function<std::shared_ptr<Effect>()> running, const juce::String& name, float scale)
  5642. {
  5643. return std::make_unique<NativeEffectEditor> (engine, -1, -1, scale, 0, NativeEffectEditor::NodeTarget { std::move (locate), std::move (running), name });
  5644. }
  5645. namespace NativeEffectWindows
  5646. {
  5647. bool canOpen (EffectKind kind)
  5648. {
  5649. return kind != EffectKind::plugin && kind != EffectKind::parallel;
  5650. }
  5651. bool canOpen (const EffectSlot& slot)
  5652. {
  5653. return canOpen (slot.kind) || isSoundgoodizerApprox (slot);
  5654. }
  5655. void open (AudioEngine& engine, int track, int slot)
  5656. {
  5657. const auto& mixer = engine.getSong().mixer;
  5658. if (track < 0 || track >= (int) mixer.size() || slot < 0 || slot >= (int) mixer[(std::size_t) track].effects.size())
  5659. return;
  5660. const auto& fxSlot = mixer[(std::size_t) track].effects[(std::size_t) slot];
  5661. const auto kind = fxSlot.kind;
  5662. if (kind == EffectKind::patcher) // its node graph editor (REA_rodada141)
  5663. {
  5664. PatcherWindows::openSlot (engine, track, slot);
  5665. return;
  5666. }
  5667. if (VisualWindows::handles (kind)) // Wave Candy / Visualizer: displays fed by the slot's tap (round 164c)
  5668. {
  5669. VisualWindows::open (engine, track, slot);
  5670. return;
  5671. }
  5672. if (FlExtraWindows::handles (kind)) // Big Clock, Tuner, HTML NoteBook (round 165g)
  5673. {
  5674. FlExtraWindows::open (engine, track, slot);
  5675. return;
  5676. }
  5677. if (! canOpen (fxSlot))
  5678. return;
  5679. if (kind == EffectKind::formulaController) // the formula, its knobs and a monitor (REA round 133)
  5680. {
  5681. FormulaControllerWindows::open (engine, track, slot);
  5682. return;
  5683. }
  5684. if (Controller164Windows::handles (kind)) // the X-Y / X-Y-Z pad, the Control Surface's panel (round 164)
  5685. {
  5686. Controller164Windows::open (engine, track, slot);
  5687. return;
  5688. }
  5689. if (kind == EffectKind::edison) // the audio editor as the slot's plugin window (round 190cd)
  5690. {
  5691. openEdisonSlot (engine, track, slot);
  5692. return;
  5693. }
  5694. if (NewtoneWindows::handles (kind)) // load a sample, edit its notes / warp markers, hear it (round 142)
  5695. {
  5696. NewtoneWindows::open (engine, track, slot);
  5697. return;
  5698. }
  5699. // (the Parametric EQ opens here, in its layout editor: ParametricEqWindows::open forwards to this function, so
  5700. // forwarding back to it was an endless loop — every way of opening the Parametric EQ froze LYNX; round 157a)
  5701. if (kind == EffectKind::facetEq) // its own editor (analyser, nodes, dynamics; REA round 103)
  5702. {
  5703. FacetEqWindows::open (engine, track, slot);
  5704. return;
  5705. }
  5706. // round 136: Ember in its Classic voicing opens the layout editor (the Classic controls); the Pro editor is Ember's own
  5707. const bool emberClassic = kind == EffectKind::ember && fxSlot.params.size() > (std::size_t) mixsuite::ember::voicing
  5708. && fxSlot.params[(std::size_t) mixsuite::ember::voicing] > 0.5f;
  5709. if (ProEditorWindows::handles (kind) && ! emberClassic) // display-first editors of the dynamics / saturation engines (REA round 114)
  5710. {
  5711. ProEditorWindows::open (engine, track, slot);
  5712. return;
  5713. }
  5714. auto& open = windows();
  5715. const auto key = std::make_pair (track, slot);
  5716. if (auto it = open.find (key); it != open.end())
  5717. {
  5718. if (it->second->getContentComponent() != nullptr && static_cast<NativeEffectEditor*> (it->second->getContentComponent())->current() != nullptr)
  5719. {
  5720. it->second->toFront (true);
  5721. editorlimit::touch (it->second.get());
  5722. return;
  5723. }
  5724. open.erase (it); // the slot now holds another effect
  5725. }
  5726. const auto name = track == 0 ? tr ("Master") : juce::String::fromUTF8 (mixer[(std::size_t) track].name.c_str());
  5727. const auto title = utf8 (isSoundgoodizerApprox (fxSlot) ? "Soundgoodizer" : effectInfo (kind).name) + " - " + (name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (track) })) + " ("
  5728. + tr ("slot {0}", { juce::String (slot + 1) }) + ")";
  5729. open[key] = std::make_unique<NativeEffectWindow> (engine, track, slot, title);
  5730. // FL's "Limit the number of open plugin editors" (round 189o, core/EditorLimit.h): LYNX's own effect windows count too
  5731. auto* window = open[key].get();
  5732. editorlimit::opened (window, [window] {
  5733. editorlimit::forget (window);
  5734. juce::MessageManager::callAsync ([window] {
  5735. auto& all = windows();
  5736. for (auto it = all.begin(); it != all.end(); ++it)
  5737. if (it->second.get() == window)
  5738. {
  5739. all.erase (it);
  5740. return;
  5741. }
  5742. });
  5743. });
  5744. }
  5745. void switchEmberEditor (AudioEngine& engine, int track, int slot, bool classic)
  5746. {
  5747. juce::MessageManager::callAsync ([&engine, track, slot, classic]
  5748. {
  5749. if (classic)
  5750. {
  5751. ProEditorWindows::close (track, slot);
  5752. open (engine, track, slot);
  5753. }
  5754. else
  5755. {
  5756. windows().erase ({ track, slot });
  5757. ProEditorWindows::open (engine, track, slot);
  5758. }
  5759. });
  5760. }
  5761. void closeAll()
  5762. {
  5763. windows().clear();
  5764. FormulaControllerWindows::closeAll();
  5765. Controller164Windows::closeAll();
  5766. NewtoneWindows::closeAll();
  5767. VisualWindows::closeAll();
  5768. FlExtraWindows::closeAll();
  5769. FacetEqWindows::closeAll();
  5770. ProEditorWindows::closeAll();
  5771. }
  5772. } // namespace NativeEffectWindows
  5773. } // namespace lynx