MixerComponent.cpp 382 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196
  1. #include "ui/CleanVoiceMenu.h"
  2. #include "ui/FlMods.h"
  3. #include "platform/Paths.h"
  4. #include "ui/ColourPicker.h"
  5. #include "ui/FileChoosers.h"
  6. #include "ui/ImageReadback.h"
  7. #include "ui/MixerComponent.h"
  8. #include "core/MixSnapshots.h"
  9. #include "ui/PluginOffTag.h"
  10. #include "ui/SlotWatch.h"
  11. #include "core/AlsImport.h"
  12. #include "core/ValueMath.h"
  13. #include "ui/UiTrace.h"
  14. #include "ui/TextCache.h"
  15. #include "core/Patcherize.h"
  16. #include "core/Rack.h"
  17. #include "core/FlpImport.h"
  18. #include "engine/FlStudio.h"
  19. #include "core/FlEffects.h"
  20. #include "core/ProjectContents.h"
  21. #include "core/FruityVocoder.h"
  22. #include "core/LiveInput.h"
  23. #include "core/HardwareOutput.h"
  24. #include "core/MixerOps.h"
  25. #include "ui/PluginHeader.h"
  26. #include "core/ProjectSafety.h"
  27. #include "core/Templates.h"
  28. #include "core/RackOps.h"
  29. #include "ui/AutomationUi.h"
  30. #include "ui/BrowserComponent.h"
  31. #include "ui/ExportDialog.h"
  32. #include <cmath>
  33. #include <complex>
  34. #include "core/Biquad.h"
  35. #include "core/Effects.h"
  36. #include "core/GoalKnobs.h"
  37. #include "engine/Text.h"
  38. #include "engine/ProjectFile.h"
  39. #include <numeric>
  40. #include "ui/FacetEqEditor.h"
  41. #include "ui/ParametricEqEditor.h"
  42. #include "ui/PluginEditors.h"
  43. #include "ui/PluginWindow.h"
  44. #include "ui/HintBar.h"
  45. #include "core/StandIns.h"
  46. #include "ui/I18n.h"
  47. #include "ui/LiveRemoteUi.h"
  48. #include "core/LynxTune.h"
  49. #include "core/VocalPitch.h"
  50. #include "ui/Icons.h"
  51. #include "ui/ValueControl.h"
  52. #include "ui/Theme.h"
  53. #include "ui/LabelFont.h"
  54. #include "ui/AudioEditor.h"
  55. #include "ui/Dialogs.h"
  56. #include "ui/QuickPick.h"
  57. #include "ui/TrackIcons.h"
  58. #include "core/TrackIcons.h"
  59. #include "core/DetailChain.h"
  60. #include "core/MiddleEllipsis.h"
  61. #include "core/MixerRouteArrow.h"
  62. #include "core/StripInserts.h"
  63. namespace lynx
  64. {
  65. namespace
  66. {
  67. // strip layout, top to bottom: header (arm, number, icon, a horizontal name), the vertical name column (not in
  68. // Extra large; low in the strip in the alt layouts), knobs (pan, stereo), mute/solo, meters + fader, the dB read-out,
  69. // then the routing lane (send switch, send knob, wires). The rows follow FL's Mixer layout (MixerStrips::rows()).
  70. constexpr int switchHeight = 16;
  71. constexpr int sendKnobHeight = 26;
  72. constexpr int wiresHeight = 14;
  73. constexpr int laneHeight = switchHeight + sendKnobHeight + wiresHeight + 4;
  74. constexpr int masterScaleWidth = 17; // the dB numbers beside the master meter (round 162, issue #9)
  75. // Fader 0..1 -> dB, with 0.8 = 0 dB (as in FL).
  76. juce::String faderToDb (float volume)
  77. {
  78. if (volume <= 0.0001f)
  79. return juce::String::fromUTF8 ("-\xe2\x88\x9e");
  80. const auto db = juce::Decibels::gainToDecibels (faderGain (volume));
  81. return (db > 0 ? "+" : "") + juce::String (db, 1);
  82. }
  83. // Meter level 0..1 on a dB scale (-60..+6).
  84. float meterPosition (float gain)
  85. {
  86. const auto db = juce::Decibels::gainToDecibels (gain, -60.0f);
  87. return juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f);
  88. }
  89. // Stereo separation: -1 = widest, 0 = normal, +1 = mono (MixerTrack::stereo).
  90. ui::ValueSpec stereoSpec (const juce::String& name)
  91. {
  92. ui::ValueSpec spec;
  93. spec.name = name;
  94. spec.minimum = -1.0;
  95. spec.maximum = 1.0;
  96. spec.defaultValue = 0.0;
  97. spec.toText = [] (double v) {
  98. const auto percent = juce::roundToInt (std::abs (v) * 100.0);
  99. if (percent == 0)
  100. return tr ("Normal width");
  101. if (v > 0.0 && percent >= 100)
  102. return tr ("Mono");
  103. return v < 0.0 ? tr ("{0}% wider", { juce::String (percent) }) : tr ("{0}% narrower", { juce::String (percent) });
  104. };
  105. spec.fromText = [] (const juce::String& t) -> std::optional<double> {
  106. const auto lower = t.toLowerCase().trim();
  107. if (lower.startsWith ("mono"))
  108. return 1.0;
  109. if (lower.startsWith ("n") && ! lower.containsAnyOf ("0123456789"))
  110. return 0.0;
  111. const auto digits = lower.initialSectionContainingOnly ("+-0123456789.,").replaceCharacter (',', '.');
  112. if (digits.isEmpty() || digits.containsOnly ("+-."))
  113. return std::nullopt;
  114. auto v = digits.getDoubleValue() / 100.0;
  115. if (lower.contains ("wid") || lower.contains ("larg")) // "50% wider" / "50% mais largo"
  116. v = -std::abs (v);
  117. return v;
  118. };
  119. return spec;
  120. }
  121. // Online Sessions (round 168a): the amber "R" of an insert whose stand-in render plays
  122. void drawStandInTag (juce::Graphics& g, juce::Rectangle<float> tag)
  123. {
  124. theme::fillRoundRect (g, tag, 3.0f, theme::colour::warning.withAlpha (0.85f));
  125. g.setColour (theme::colour::bg1);
  126. g.setFont (theme::font (9.0f, true));
  127. g.drawText ("R", tag, juce::Justification::centred, false);
  128. }
  129. ui::ValueSpec sendSpec (const juce::String& name)
  130. {
  131. // FL's send knob: the fader curve (0 dB at 80 %, +5.6 dB at the top); the value is the knob position
  132. auto spec = ui::faderSpec (name, unityFader);
  133. spec.pixelsForRange = 120.0;
  134. return spec;
  135. }
  136. } // namespace
  137. // The Mixer strips' picture (round 174e2): JUCE's buffered-to-image cache for the visible part of the strips (they are
  138. // as wide as all the inserts), plus the meter levels drawn over it and the meters' own repaints leaving it valid
  139. class MixerStrips::MeterCache final : public juce::CachedComponentImage
  140. {
  141. public:
  142. explicit MeterCache (MixerStrips& o) : owner (o) {}
  143. void paint (juce::Graphics& g) override
  144. {
  145. const auto scale = g.getInternalContext().getPhysicalPixelScaleFactor();
  146. auto visible = owner.getLocalBounds();
  147. if (auto* parent = owner.getParentComponent())
  148. visible = visible.getIntersection (owner.getLocalArea (parent, parent->getLocalBounds()));
  149. if (visible.isEmpty())
  150. return;
  151. const auto imageSize = (visible.withZeroOrigin().toFloat() * scale).getSmallestIntegerContainer();
  152. // (round 190bm) a window drawn without the GPU gets a software picture; a picture lost with its graphics
  153. // device is painted again; no picture at all (no memory): straight to the window
  154. const auto software = ui::windowDrawnByCpu (owner);
  155. const auto losses = ui::pictureLossCount();
  156. if (visible != shown || image.isNull() || image.getBounds() != imageSize || software != softwareImage || losses != lossesSeen)
  157. {
  158. if (image.isNull() || image.getBounds() != imageSize || software != softwareImage)
  159. image = ui::makePicture (imageSize.getWidth(), imageSize.getHeight(), software);
  160. softwareImage = software;
  161. lossesSeen = losses;
  162. shown = visible;
  163. valid.clear();
  164. }
  165. ui::notePicture ("Mixer", image, scale, softwareImage, owner, noted);
  166. if (image.isNull())
  167. {
  168. owner.paintEntireComponent (g, false);
  169. return;
  170. }
  171. if (! valid.containsRectangle (visible))
  172. {
  173. const ui::ScopedNoImageReadback noReadback (image); // (the picture is normally only drawn to the window)
  174. juce::Graphics imageGraphics (image);
  175. auto& context = imageGraphics.getInternalContext();
  176. context.addTransform (juce::AffineTransform::translation ((float) -visible.getX(), (float) -visible.getY()).scaled (scale));
  177. for (const auto& r : valid)
  178. context.excludeClipRectangle (r);
  179. context.clipToRectangle (visible);
  180. ++owner.pictureRefills;
  181. owner.cachePainting = true;
  182. owner.paintEntireComponent (imageGraphics, true);
  183. owner.cachePainting = false;
  184. }
  185. valid = visible;
  186. g.setColour (juce::Colours::black);
  187. g.drawImageTransformed (image,
  188. juce::AffineTransform::scale ((float) visible.getWidth() / (float) imageSize.getWidth(),
  189. (float) visible.getHeight() / (float) imageSize.getHeight())
  190. .translated ((float) visible.getX(), (float) visible.getY()),
  191. false);
  192. owner.paintMeterLevels (g);
  193. if (ui::pictureLostMeanwhile (lossesSeen, lossRetries))
  194. owner.repaint();
  195. }
  196. bool invalidateAll() override // (JUCE's repaint() of the whole component comes here, not to invalidate())
  197. {
  198. if (! owner.meterRepaintOnly)
  199. {
  200. ++owner.pictureInvalidations;
  201. valid.clear();
  202. }
  203. return true;
  204. }
  205. bool invalidate (const juce::Rectangle<int>& area) override
  206. {
  207. if (! owner.meterRepaintOnly)
  208. {
  209. ++owner.pictureInvalidations;
  210. valid.subtract (area);
  211. }
  212. return true;
  213. }
  214. void releaseResources() override { image = {}; }
  215. private:
  216. MixerStrips& owner;
  217. juce::Image image;
  218. juce::Rectangle<int> shown; // the visible part the picture holds
  219. juce::RectangleList<int> valid;
  220. bool softwareImage = false; // the picture is a software image (the window is drawn without the GPU)
  221. int lossesSeen = 0; // ui::pictureLossCount() when the picture was last known good
  222. int lossRetries = 0;
  223. juce::String noted; // ui::notePicture's memory
  224. };
  225. MixerStrips::MixerStrips (AudioEngine& e)
  226. : engine (e)
  227. {
  228. if (const auto* v = std::getenv ("LYNX_MIXER_CACHE"); v == nullptr || juce::String (v) != "0")
  229. {
  230. setCachedComponentImage (new MeterCache (*this)); // (owned by the component)
  231. meterCacheOn = true;
  232. }
  233. setWantsKeyboardFocus (false);
  234. setMouseClickGrabsKeyboardFocus (false);
  235. engine.addChangeListener (this);
  236. engine.getLevelsBroadcaster().addChangeListener (this);
  237. updateSize();
  238. // (the meters and the automated faders move at the display's refresh: `frames`, round 174e)
  239. }
  240. MixerStrips::~MixerStrips()
  241. {
  242. engine.getLevelsBroadcaster().removeChangeListener (this);
  243. engine.removeChangeListener (this);
  244. }
  245. void MixerStrips::setVisibleHeight (int height)
  246. {
  247. visibleHeight = juce::jmax (300, height);
  248. updateSize();
  249. }
  250. void MixerStrips::updateSize()
  251. {
  252. const auto tracks = (int) engine.getSong().mixer.size();
  253. layoutStrips();
  254. setSize (contentWidth, visibleHeight);
  255. levels.resize ((std::size_t) juce::jmax (1, tracks) * 2);
  256. }
  257. void MixerStrips::layoutStrips()
  258. {
  259. const auto& song = engine.getSong();
  260. const auto tracks = (int) song.mixer.size();
  261. stripXs.assign ((std::size_t) tracks + 1, 0);
  262. // "Show only used inserts" (round 163): unused inserts take no room, except those brought back with "+" (so a new
  263. // insert shows; selecting another strip doesn't move the strips under the mouse)
  264. hidden.assign ((std::size_t) tracks + 1, false);
  265. if (showUsedOnly)
  266. {
  267. // round 190am: the selected inserts stay, and stay after the selection moves on (no strip jumps under the mouse)
  268. revealed.insert (selected);
  269. revealed.insert (selection.begin(), selection.end());
  270. hidden = mixerops::hiddenUnusedInserts (song, revealed);
  271. }
  272. // folded groups (round 177a): nothing is computed unless a group is folded
  273. foldShow.clear();
  274. tabOf.clear();
  275. foldHead.assign ((std::size_t) tracks + 1, false);
  276. for (int t = 1; t < tracks; ++t)
  277. if (song.mixer[(std::size_t) t].separator || (t + 1 < tracks && song.mixer[(std::size_t) t + 1].separator))
  278. {
  279. // the first strip of a group that can fold carries the chevron (a separator sets groups off)
  280. const auto group = mixerops::groupOf (song, t);
  281. if (! group.empty() && group.front() == t && mixerops::canFold (song, t))
  282. foldHead[(std::size_t) t] = true;
  283. }
  284. if (std::any_of (song.mixer.begin() + std::min<std::ptrdiff_t> (1, (std::ptrdiff_t) song.mixer.size()), song.mixer.end(),
  285. [] (const MixerTrack& m) { return m.folded; }))
  286. {
  287. foldShow = mixerops::foldView (song);
  288. tabOf.assign ((std::size_t) tracks, -1);
  289. for (int t = 1; t < tracks; ++t)
  290. {
  291. if (foldShow[(std::size_t) t] == mixerops::FoldShow::hidden)
  292. hidden[(std::size_t) t] = true;
  293. if (foldShow[(std::size_t) t] == mixerops::FoldShow::tab)
  294. for (const auto m : mixerops::groupOf (song, t))
  295. tabOf[(std::size_t) m] = t;
  296. }
  297. for (int t = 1; t < tracks; ++t) // a folded summing group: its bus strip carries the chevron (to unfold it)
  298. if (foldHead[(std::size_t) t] && hidden[(std::size_t) t] && song.mixer[(std::size_t) t].folded)
  299. if (const auto bus = mixerops::groupBus (song, mixerops::groupOf (song, t)); bus > 0)
  300. foldHead[(std::size_t) bus] = true;
  301. }
  302. dockGaps.clear();
  303. separatorLines.clear();
  304. vcaXs.clear();
  305. loudnessX = hiddenX;
  306. int x = 4;
  307. bool any = false, afterMaster = false;
  308. for (auto dock : { MixerDock::left, MixerDock::middle, MixerDock::right })
  309. {
  310. const auto d = (int) dock;
  311. blockStart[d] = x;
  312. bool first = true;
  313. for (int t = 0; t < tracks; ++t)
  314. {
  315. const auto& track = song.mixer[(std::size_t) t];
  316. if (track.dock != dock)
  317. continue;
  318. if (hidden[(std::size_t) t])
  319. {
  320. stripXs[(std::size_t) t] = hiddenX;
  321. continue;
  322. }
  323. if (any && first && dock == MixerDock::right)
  324. {
  325. // the gap between two blocks belongs to the pinned block: the right block's is before its strips,
  326. // the left block's after them (below)
  327. dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
  328. x += dockGap;
  329. }
  330. else if (! first && track.separator && t > 0)
  331. {
  332. separatorLines.push_back ({ x + separatorGap / 2 - 3, dock });
  333. x += separatorGap;
  334. }
  335. else if (afterMaster)
  336. x += 8;
  337. if (t == 0 && ! song.vcas.empty()) // the VCA strips: their own block left of the Master (round 177a)
  338. {
  339. for (std::size_t i = 0; i < song.vcas.size(); ++i)
  340. {
  341. vcaXs.push_back (x);
  342. x += spec().stripWidth;
  343. }
  344. x += 8;
  345. }
  346. stripXs[(std::size_t) t] = x;
  347. x += stripWidthOf (t);
  348. if (t == 0 && showLoudness) // the loudness panel: right of the Master, in its dock (round 190am)
  349. {
  350. loudnessX = x;
  351. x += loudnessWidth;
  352. }
  353. any = true;
  354. first = false;
  355. afterMaster = t == 0;
  356. }
  357. if (dock == MixerDock::middle) // the "+" button ends the middle block
  358. {
  359. if (afterMaster)
  360. x += 8;
  361. stripXs[(std::size_t) tracks] = x;
  362. x += spec().stripWidth;
  363. afterMaster = false;
  364. any = true;
  365. }
  366. blockEnd[d] = x;
  367. if (dock == MixerDock::left && ! first) // the left block carries its gap to the middle
  368. {
  369. dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
  370. x += dockGap;
  371. blockEnd[d] = x;
  372. afterMaster = false;
  373. }
  374. }
  375. contentWidth = x + 8;
  376. }
  377. MixerDock MixerStrips::dockOf (int track) const noexcept
  378. {
  379. const auto& mixer = engine.getSong().mixer;
  380. return track >= 0 && track < (int) mixer.size() ? mixer[(std::size_t) track].dock : MixerDock::middle;
  381. }
  382. int MixerStrips::pinOffset (MixerDock dock) const noexcept
  383. {
  384. auto* parent = getParentComponent();
  385. if (parent == nullptr || dock == MixerDock::middle)
  386. return 0;
  387. const auto scroll = juce::jmax (0, -getX());
  388. const auto visible = parent->getWidth();
  389. if (dock == MixerDock::left)
  390. return blockEnd[0] > blockStart[0] ? juce::jmin (scroll, juce::jmax (0, contentWidth - blockEnd[0])) : 0;
  391. return blockEnd[2] > blockStart[2] ? juce::jmin (0, scroll + visible - contentWidth) : 0;
  392. }
  393. int MixerStrips::stripX (int track) const noexcept
  394. {
  395. if (track <= -2) // a VCA strip (vcaStrip): it follows the Master's dock
  396. {
  397. const auto i = (std::size_t) (-2 - track);
  398. return i < vcaXs.size() ? vcaXs[i] + pinOffset (dockOf (0)) : hiddenX;
  399. }
  400. if (track >= 0 && track < (int) stripXs.size())
  401. return stripXs[(std::size_t) track] + pinOffset (dockOf (track));
  402. return track == 0 ? 4 : 4 + spec().masterWidth + 8 + (track - 1) * spec().stripWidth;
  403. }
  404. bool MixerStrips::isInterestedInDragSource (const SourceDetails& details)
  405. {
  406. if (BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details))
  407. return true;
  408. if (! BrowserComponent::isBrowserDrag (details))
  409. return false;
  410. // (asked on every mouse move of the drag: the answer for the dragged file is kept)
  411. static juce::File lastFile;
  412. static bool lastAnswer = false;
  413. if (const auto file = BrowserComponent::draggedFile (details); file != lastFile)
  414. {
  415. lastFile = file;
  416. lastAnswer = mixerpresets::isMixerPreset (file);
  417. }
  418. return lastAnswer;
  419. }
  420. void MixerStrips::itemDropped (const SourceDetails& details)
  421. {
  422. const auto t = trackAt (details.localPosition.x);
  423. const auto tracks = (int) engine.getSong().mixer.size();
  424. // FL's mixer preset dropped from the Browser (WhatsNew): onto a track it loads there, onto the empty mixer space
  425. // (or "+") it makes a new track
  426. if (BrowserComponent::isBrowserDrag (details))
  427. {
  428. const auto file = BrowserComponent::draggedFile (details);
  429. if (! mixerpresets::isMixerPreset (file))
  430. return;
  431. if (t >= 0 && t < tracks)
  432. mixerpresets::loadOnTracks (engine, { t }, file);
  433. else if (const auto added = mixerpresets::insertTrack (engine, tracks, file); added > 0)
  434. {
  435. revealed.insert (added);
  436. updateSize();
  437. selectTrack (added);
  438. }
  439. return;
  440. }
  441. if (t < 0 || t >= tracks)
  442. return;
  443. if (auto fx = BrowserComponent::draggedEffect (details); fx && onEffectDropped != nullptr)
  444. onEffectDropped (t, std::move (*fx));
  445. else if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr)
  446. onInstrumentDropped (t, std::move (*c));
  447. }
  448. int MixerStrips::trackAt (int x) const noexcept
  449. {
  450. const auto tracks = (int) engine.getSong().mixer.size();
  451. // the pinned blocks lie over the scrolled middle: they are hit first
  452. for (auto dock : { MixerDock::left, MixerDock::right, MixerDock::middle })
  453. for (int t = 0; t <= tracks; ++t) // t == tracks = "+" button
  454. if (dockOf (t) == dock && x >= stripX (t) && x < stripX (t) + stripWidthOf (t))
  455. return t;
  456. return -1;
  457. }
  458. int MixerStrips::laneTop() const noexcept
  459. {
  460. return getHeight() - laneHeight;
  461. }
  462. const mixerlayout::Spec& MixerStrips::spec() noexcept
  463. {
  464. static mixerlayout::Layout cachedFor = (mixerlayout::Layout) -1;
  465. static mixerlayout::Spec cached;
  466. if (cachedFor != layout)
  467. {
  468. cached = mixerlayout::specOf (layout);
  469. cachedFor = layout;
  470. }
  471. return cached;
  472. }
  473. void MixerStrips::setLayout (mixerlayout::Layout newLayout)
  474. {
  475. if (newLayout == layout)
  476. return;
  477. layout = newLayout;
  478. updateSize();
  479. repaint();
  480. if (onLayoutChanged)
  481. onLayoutChanged();
  482. }
  483. MixerStrips::Rows MixerStrips::rows() const noexcept
  484. {
  485. const auto& sp = spec();
  486. const auto compact = mixerlayout::isCompact (layout);
  487. Rows r;
  488. r.header = sp.verticalName ? 38 : 54;
  489. // the vertical name column takes what the fader can spare (FL's runs the strip's upper part)
  490. r.nameHeight = sp.verticalName ? juce::jlimit (40, 110, (getHeight() - 300) / 2) : 0;
  491. r.knobsHeight = ! sp.stereoKnob ? sp.knobSize + 8 : sp.stackedKnobs ? sp.knobSize + (sp.knobSize - 6) + 10 : 32;
  492. r.buttonsHeight = compact ? 32 : 20; // compact: mute above solo
  493. r.readoutHeight = sp.dbReadout ? 16 : 0;
  494. auto y = r.header;
  495. if (showStripInserts && stripinserts::shownIn (layout)) // issue #154 part 2 (round 190io): the effects list under the band
  496. {
  497. r.insertsTop = y + 2;
  498. r.insertsHeight = stripinserts::height (stripinserts::rowsFor (getHeight()));
  499. y += r.insertsHeight + 2;
  500. }
  501. if (sp.verticalName && ! sp.nameLow)
  502. {
  503. r.nameTop = y;
  504. y += r.nameHeight;
  505. }
  506. r.knobsTop = y;
  507. r.buttonsTop = r.knobsTop + r.knobsHeight;
  508. r.faderTop = r.buttonsTop + r.buttonsHeight + 6;
  509. auto bottom = laneTop() - r.readoutHeight - 4 - arrowRowHeight; // (round 190io: FL's route arrow at the strip's foot)
  510. if (flInsertList()) // FL's Extra large (round 190jd): the used slots' names under the fader, above the route arrow
  511. {
  512. r.insertsHeight = stripinserts::height (stripinserts::flExtraLarge, stripinserts::rowsFor (getHeight()));
  513. r.insertsTop = laneTop() - arrowRowHeight - 2 - r.insertsHeight;
  514. bottom = r.insertsTop - r.readoutHeight - 4;
  515. }
  516. if (compact)
  517. {
  518. r.armY = bottom - 14;
  519. bottom -= 16;
  520. }
  521. if (sp.verticalName && sp.nameLow)
  522. {
  523. // the alt layouts: the name runs up from the strip's bottom; the dB read-out stays under the fader, above the
  524. // name (rel 0.1.23: the read-out was drawn over the name's top)
  525. r.nameTop = bottom + r.readoutHeight - r.nameHeight;
  526. bottom = r.nameTop - 4 - r.readoutHeight;
  527. }
  528. r.faderBottom = juce::jmax (r.faderTop + 40, bottom);
  529. return r;
  530. }
  531. juce::Rectangle<int> MixerStrips::foldArea (int t) const
  532. {
  533. // the chevron left of the number on a group's first strip (round 177a)
  534. return { stripX (t) + 1, 3, 12, 15 };
  535. }
  536. float MixerStrips::tabLevel (int t) const noexcept
  537. {
  538. float level = 0.0f;
  539. for (std::size_t m = 0; m < tabOf.size(); ++m)
  540. if (tabOf[m] == t)
  541. for (std::size_t ch = 0; ch < 2; ++ch)
  542. if (const auto i = m * 2 + ch; i < levels.size())
  543. level = juce::jmax (level, levels[i].level);
  544. return level;
  545. }
  546. void MixerStrips::paintFoldTab (juce::Graphics& g, int t)
  547. {
  548. // a folded group without a bus (round 177a): a slim tab in the group's colour with its name, how many inserts it
  549. // holds and the loudest member's level; a click unfolds it. The members are never hidden without a trace.
  550. using namespace theme;
  551. const auto& song = engine.getSong();
  552. const auto& head = song.mixer[(std::size_t) t];
  553. const auto x = stripX (t);
  554. const auto area = juce::Rectangle<int> (x, 2, foldTabWidth - 2, laneTop() - 2).toFloat();
  555. const auto hoveredTab = hoverTrack == t;
  556. auto plate = hoveredTab ? colour::bg3 : colour::bg2;
  557. if (head.colour != 0)
  558. plate = plate.interpolatedWith (tame (juce::Colour (head.colour)), 0.3f);
  559. theme::fillRoundRect (g, area, radius::md, plate);
  560. if (head.colour != 0)
  561. theme::fillRoundRect (g, area.withHeight (3.0f).reduced (3.0f, 0.0f), 1.5f, tame (juce::Colour (head.colour)));
  562. g.setColour (hoveredTab ? colour::borderStrong : colour::border);
  563. g.drawRoundedRectangle (area.reduced (0.5f), radius::md, 1.0f);
  564. icons::draw (g, Icon::chevronDown, juce::Rectangle<float> (12.0f, 12.0f).withCentre ({ area.getCentreX(), 12.0f }).transformedBy (
  565. juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, area.getCentreX(), 12.0f)),
  566. hoveredTab ? colour::textPrimary : colour::textSecondary);
  567. const auto members = (int) mixerops::groupOf (song, t).size();
  568. g.setColour (colour::textSecondary);
  569. g.setFont (font (9.0f, true));
  570. textcache::drawText (g, juce::String (members), (int) area.getX(), 22, (int) area.getWidth(), 12, juce::Justification::centred);
  571. // the loudest member's level: one thin bar along the fader rows
  572. const auto rail = faderRail (t);
  573. const auto bar = juce::Rectangle<float> (area.getRight() - 6.0f, (float) rail.getY(), 3.0f, (float) rail.getHeight());
  574. theme::fillRoundRect (g, bar, 1.0f, colour::bg0);
  575. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  576. paintFoldTabLevel (g, t);
  577. // the group's name, bottom to top
  578. const auto name = juce::String::fromUTF8 (head.name.c_str());
  579. const auto column = juce::Rectangle<int> ((int) area.getX() + 1, 40, (int) area.getWidth() - 8, juce::jmax (20, rail.getY() - 46));
  580. juce::Graphics::ScopedSaveState state (g);
  581. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  582. g.setColour (colour::textPrimary.withAlpha (0.9f));
  583. g.setFont (font (type::small, false));
  584. textcache::drawFittedText (g, name, juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre()),
  585. juce::Justification::centredLeft, 1, 0.8f);
  586. }
  587. void MixerStrips::paintFoldTabLevel (juce::Graphics& g, int t) const
  588. {
  589. using namespace theme;
  590. const auto rail = faderRail (t);
  591. const auto bar = juce::Rectangle<float> ((float) (stripX (t) + foldTabWidth - 2) - 6.0f, (float) rail.getY(), 3.0f, (float) rail.getHeight());
  592. const auto level = tabLevel (t);
  593. g.setColour (level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow);
  594. g.fillRect (bar.withTop (bar.getBottom() - meterPosition (level) * bar.getHeight()));
  595. }
  596. // --- VCA strips (round 177a slice 3; REA_rodada177a §3) ---------------------------------------------------------------
  597. // A VCA strip carries no audio: its fader scales its members' faders, its mute mutes them, its solo solos them. It has
  598. // no slots, pan, EQ or routing; a dashed outline and the "VCA" label set it apart from an insert.
  599. int MixerStrips::vcaAt (int x) const noexcept
  600. {
  601. for (int i = 0; i < (int) vcaXs.size(); ++i)
  602. if (const auto left = stripX (vcaStrip (i)); x >= left && x < left + spec().stripWidth)
  603. return i;
  604. return -1;
  605. }
  606. MixerStrips::Part MixerStrips::vcaPartAt (int i, juce::Point<int> p) const
  607. {
  608. const auto v = vcaStrip (i);
  609. if (headerArea (v).contains (p) || nameArea (v).contains (p))
  610. return Part::header;
  611. if (muteArea (v).contains (p))
  612. return Part::mute;
  613. if (soloArea (v).contains (p))
  614. return Part::solo;
  615. if (meterArea (v).contains (p))
  616. return Part::meter;
  617. if (faderRail (v).expanded (0, 6).contains (p))
  618. return Part::fader;
  619. return Part::body;
  620. }
  621. float MixerStrips::vcaMeter (int i, int channel) const noexcept
  622. {
  623. const auto& song = engine.getSong();
  624. float level = 0.0f;
  625. if (i < 0 || i >= (int) song.vcas.size())
  626. return level;
  627. for (const auto m : mixerops::vcaReach (song, i))
  628. if (const auto index = (std::size_t) m * 2 + (std::size_t) channel; index < levels.size())
  629. level = juce::jmax (level, levels[index].level);
  630. return level;
  631. }
  632. float MixerStrips::vcaShownLevel (int i) const noexcept
  633. {
  634. const auto& vcas = engine.getSong().vcas;
  635. if (i < 0 || i >= (int) vcas.size())
  636. return unityFader;
  637. return engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::vcaLevel, i }, vcas[(std::size_t) i].level);
  638. }
  639. ui::ValueSpec MixerStrips::vcaSpec (int i) const
  640. {
  641. const auto& vcas = engine.getSong().vcas;
  642. const auto name = i >= 0 && i < (int) vcas.size() ? juce::String::fromUTF8 (vcas[(std::size_t) i].name.c_str()) : juce::String();
  643. auto spec = ui::faderSpec (name + " - " + tr ("VCA level"), unityFader);
  644. spec.pixelsForRange = juce::jmax (60, faderRail (vcaStrip (i)).getHeight());
  645. spec.target = AutomationTarget { AutomationTargetKind::vcaLevel, i };
  646. return spec;
  647. }
  648. void MixerStrips::setVcaLevel (int i, double value)
  649. {
  650. if (i < 0 || i >= (int) engine.getSong().vcas.size())
  651. return;
  652. // like an insert's fader: only the live levels move during a drag (the gain path reads them lock-free)
  653. engine.editLevels ([i, v = juce::jlimit (0.0f, 1.0f, (float) value)] (Song& s) {
  654. if (i < (int) s.vcas.size())
  655. s.vcas[(std::size_t) i].level = v;
  656. });
  657. }
  658. void MixerStrips::repaintVca (int i)
  659. {
  660. if (i < 0 || i >= (int) vcaXs.size())
  661. return;
  662. repaint (stripX (vcaStrip (i)) - 2, 0, spec().stripWidth + 4, laneTop());
  663. // the members' ticks (the level that plays) move with it
  664. for (const auto m : mixerops::vcaReach (engine.getSong(), i))
  665. if (m > 0 && m < (int) stripXs.size() && ! isHidden (m))
  666. {
  667. const auto fader = faderArea (m);
  668. repaint (stripX (m), fader.getY() - 9, stripWidthOf (m), fader.getHeight() + 18);
  669. }
  670. }
  671. void MixerStrips::soloVca (int i)
  672. {
  673. const auto reach = mixerops::vcaReach (engine.getSong(), i);
  674. if (! reach.empty())
  675. engine.editSong ([reach] (Song& s) { mixerops::soloSelected (s, reach, false); });
  676. }
  677. juce::String MixerStrips::vcaNote (int track) const
  678. {
  679. const auto& song = engine.getSong();
  680. if (song.vcas.empty() || track <= 0 || track >= (int) song.mixer.size())
  681. return {};
  682. const auto chain = mixerops::vcasOf (song, track);
  683. if (chain.empty())
  684. return {};
  685. juce::StringArray parts;
  686. for (const auto v : chain)
  687. {
  688. const auto& vca = song.vcas[(std::size_t) v];
  689. parts.add ("VCA '" + juce::String::fromUTF8 (vca.name.c_str()) + "' " + faderToDb (vca.level) + " dB" + (vca.muted ? " (" + tr ("Muted") + ")" : juce::String()));
  690. }
  691. const auto playing = faderPosition (faderGain (song.mixer[(std::size_t) track].volume) * mixerops::vcaGain (song, track));
  692. return "(" + parts.joinIntoString (", ") + juce::String::fromUTF8 (" \xe2\x86\x92 ") + faderToDb (playing) + " dB)";
  693. }
  694. ui::Hint MixerStrips::vcaHint (int i, juce::Point<int> p) const
  695. {
  696. ui::Hint h;
  697. const auto& song = engine.getSong();
  698. if (i < 0 || i >= (int) song.vcas.size())
  699. return h;
  700. const auto& vca = song.vcas[(std::size_t) i];
  701. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  702. const auto part = dragVca >= 0 ? Part::fader : vcaPartAt (i, p);
  703. switch (part)
  704. {
  705. case Part::fader:
  706. return ui::valueHint (vcaSpec (i), vcaShownLevel (i), ui::valueGestures());
  707. case Part::mute: h.text = name + " - " + tr ("Click: mute the VCA's members. Right-click or Ctrl+click: solo"); break;
  708. case Part::solo: h.text = name + " - " + tr ("Solo the VCA's members"); break;
  709. case Part::meter: h.text = name + " - " + tr ("The loudest member's level"); break;
  710. default:
  711. h.text = name + " - " + tr ("VCA fader: moves the level of its {0} inserts (they keep their own faders) [LMB] selects them [RMB] VCA menu",
  712. { juce::String ((int) vca.members.size()) });
  713. h.hasMenu = true;
  714. break;
  715. }
  716. return h;
  717. }
  718. void MixerStrips::vcaMouseDown (const juce::MouseEvent& e, int i)
  719. {
  720. const auto& song = engine.getSong();
  721. if (i >= (int) song.vcas.size())
  722. return;
  723. const auto v = vcaStrip (i);
  724. const auto part = vcaPartAt (i, e.getPosition());
  725. if (part == Part::mute && (flmods::popup (e.mods) || flmods::ctrl (e.mods)))
  726. {
  727. soloVca (i);
  728. return;
  729. }
  730. if (flmods::popup (e.mods))
  731. {
  732. showVcaMenu (i);
  733. return;
  734. }
  735. switch (part)
  736. {
  737. case Part::mute:
  738. engine.editSong ([i] (Song& s) {
  739. if (i < (int) s.vcas.size())
  740. s.vcas[(std::size_t) i].muted = ! s.vcas[(std::size_t) i].muted;
  741. });
  742. return;
  743. case Part::solo:
  744. soloVca (i);
  745. return;
  746. case Part::fader:
  747. {
  748. if (ui::isResetClick (e))
  749. {
  750. setVcaLevel (i, unityFader);
  751. return;
  752. }
  753. const auto start = song.vcas[(std::size_t) i].level;
  754. if (! flmods::ctrl (e.mods)) // a press on the rail steps the fader towards the mouse (as an insert's)
  755. {
  756. const auto rail = faderRail (v);
  757. if (std::abs ((float) e.y - ((float) rail.getBottom() - start * (float) rail.getHeight())) > 9.0f)
  758. {
  759. pressRail (v, e.y);
  760. return;
  761. }
  762. }
  763. dragVca = i;
  764. drag.begin (e, start);
  765. ui::showValueTip (*this, faderRail (v), vcaSpec (i).text (start));
  766. return;
  767. }
  768. default:
  769. {
  770. // the header or the body selects the members (so the insert menu's VCA items act on them)
  771. std::vector<int> members;
  772. for (const auto m : song.vcas[(std::size_t) i].members)
  773. if (m > 0 && m < (int) song.mixer.size())
  774. members.push_back (m);
  775. if (! members.empty())
  776. setSelection (members, members.front());
  777. return;
  778. }
  779. }
  780. }
  781. void MixerStrips::showVcaMenu (int i)
  782. {
  783. const auto& song = engine.getSong();
  784. if (i < 0 || i >= (int) song.vcas.size())
  785. return;
  786. const auto& vca = song.vcas[(std::size_t) i];
  787. juce::PopupMenu menu;
  788. auto rename = [this, i] {
  789. if (i >= (int) engine.getSong().vcas.size())
  790. return;
  791. const auto& item = engine.getSong().vcas[(std::size_t) i];
  792. showNameAndColourDialog (tr ("Rename VCA"), juce::String::fromUTF8 (item.name.c_str()), item.colour,
  793. [this, i] (const juce::String& name, std::uint32_t colour) {
  794. engine.editSong ([i, n = name.trim().toStdString(), colour] (Song& s) {
  795. if (i >= (int) s.vcas.size())
  796. return;
  797. if (! n.empty())
  798. s.vcas[(std::size_t) i].name = n;
  799. s.vcas[(std::size_t) i].colour = colour;
  800. });
  801. });
  802. };
  803. ui::addItemHeader (menu, tr ("VCA"), juce::String::fromUTF8 (vca.name.c_str()), vca.colour != 0 ? juce::Colour (vca.colour) : juce::Colour(), rename);
  804. menu.addItem (tr ("Rename and color..."), rename);
  805. // the selected inserts (not the Master) join or leave this VCA
  806. std::vector<int> picked;
  807. for (const auto m : selection)
  808. if (m > 0 && m < (int) song.mixer.size())
  809. picked.push_back (m);
  810. const auto in = [&vca] (int m) { return std::binary_search (vca.members.begin(), vca.members.end(), m); };
  811. menu.addItem (tr ("Assign selected inserts"), ! picked.empty() && ! std::all_of (picked.begin(), picked.end(), in), false, [this, picked, i] {
  812. engine.editSong ([picked, i] (Song& s) { mixerops::assignToVca (s, picked, i); });
  813. });
  814. menu.addItem (tr ("Remove selected inserts"), std::any_of (picked.begin(), picked.end(), in), false, [this, picked, i] {
  815. engine.editSong ([picked, i] (Song& s) { mixerops::removeFromVca (s, picked, i); });
  816. });
  817. // nesting: this VCA follows another one (never one that already follows it)
  818. juce::PopupMenu follow;
  819. follow.addItem (tr ("None"), true, vca.parent < 0, [this, i] {
  820. engine.editSong ([i] (Song& s) {
  821. if (i < (int) s.vcas.size())
  822. s.vcas[(std::size_t) i].parent = -1;
  823. });
  824. });
  825. for (int other = 0; other < (int) song.vcas.size(); ++other)
  826. {
  827. if (other == i)
  828. continue;
  829. bool loops = false; // `other` follows `i` (directly or through others)
  830. for (int up = other, guard = 0; up >= 0 && up < (int) song.vcas.size() && guard <= (int) song.vcas.size(); up = song.vcas[(std::size_t) up].parent, ++guard)
  831. if (up == i)
  832. {
  833. loops = true;
  834. break;
  835. }
  836. follow.addItem (juce::String::fromUTF8 (song.vcas[(std::size_t) other].name.c_str()), ! loops, vca.parent == other, [this, i, other] {
  837. engine.editSong ([i, other] (Song& s) {
  838. if (i < (int) s.vcas.size() && other < (int) s.vcas.size())
  839. s.vcas[(std::size_t) i].parent = other;
  840. });
  841. });
  842. }
  843. menu.addSubMenu (tr ("Follow VCA"), follow, song.vcas.size() > 1);
  844. menu.addSeparator();
  845. menu.addItem (tr ("Merge VCA into members"), ! vca.members.empty(), false, [this, i] {
  846. engine.editSong ([i] (Song& s) { mixerops::mergeVcaIntoMembers (s, i); });
  847. });
  848. menu.addItem (tr ("Delete VCA"), [this, i] {
  849. engine.editSong ([i] (Song& s) { mixerops::deleteVca (s, i); });
  850. updateSize();
  851. });
  852. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  853. }
  854. void MixerStrips::paintVcaMeter (juce::Graphics& g, int i) const
  855. {
  856. using namespace theme;
  857. const auto& sp = spec();
  858. const auto meters = meterArea (vcaStrip (i));
  859. for (int ch = 0; ch < 2; ++ch)
  860. {
  861. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  862. const auto level = vcaMeter (i, ch);
  863. const auto h = (int) (meterPosition (level) * (float) bar.getHeight());
  864. g.setColour ((level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow).withAlpha (0.8f));
  865. g.fillRect (bar.withTop (bar.getBottom() - h));
  866. }
  867. }
  868. void MixerStrips::paintVcaStrip (juce::Graphics& g, int i)
  869. {
  870. using namespace theme;
  871. const auto& song = engine.getSong();
  872. if (i < 0 || i >= (int) song.vcas.size())
  873. return;
  874. const auto& vca = song.vcas[(std::size_t) i];
  875. const auto v = vcaStrip (i);
  876. const auto x = stripX (v);
  877. const auto& sp = spec();
  878. const auto w = sp.stripWidth;
  879. if (! g.clipRegionIntersects ({ x, 0, w, laneTop() }))
  880. return;
  881. const auto plateWidth = w - sp.gap;
  882. const auto compactLayout = mixerlayout::isCompact (layout);
  883. const auto strip = juce::Rectangle<int> (x, 2, plateWidth, laneTop() - 2).toFloat();
  884. const auto hovered = [this, v] (Part p) { return hoverTrack == v && hoverPart == p; };
  885. const auto colourOf = vca.colour != 0 ? tame (juce::Colour (vca.colour)) : colour::info;
  886. auto plate = hoverTrack == v ? colour::bg3 : colour::bg2;
  887. plate = plate.interpolatedWith (colourOf, 0.12f);
  888. theme::fillRoundRect (g, strip, radius::md, plate);
  889. theme::fillRoundRect (g, strip.withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, colourOf);
  890. {
  891. // a dashed outline: this strip carries no audio
  892. juce::Path outline;
  893. outline.addRoundedRectangle (strip.reduced (0.5f), radius::md);
  894. juce::Path dashed;
  895. const float dashes[] = { 3.0f, 3.0f };
  896. juce::PathStrokeType (1.0f).createDashedStroke (dashed, outline, dashes, 2);
  897. g.setColour (colourOf.withAlpha (0.55f));
  898. g.fillPath (dashed);
  899. }
  900. // header: "VCA" where an insert shows its number, the member count under it, the name as on an insert
  901. g.setColour (colour::textSecondary);
  902. g.setFont (font (compactLayout ? 9.5f : type::caption, true));
  903. textcache::drawFittedText (g, "VCA", juce::Rectangle<int> (x, 4, plateWidth, 13), juce::Justification::centred, 1, 0.6f);
  904. g.setFont (font (9.0f));
  905. textcache::drawFittedText (g, juce::String::fromUTF8 ("\xc3\x97") + juce::String ((int) vca.members.size()), iconArea (v),
  906. juce::Justification::centred, 1, 0.6f);
  907. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  908. g.setColour (vca.muted ? colour::textDisabled : colour::textPrimary.withAlpha (0.9f));
  909. g.setFont (font (compactLayout ? 10.0f : type::small));
  910. if (const auto box = nameArea (v); ! sp.verticalName)
  911. textcache::drawFittedText (g, name, box, juce::Justification::centred, 1, 0.7f);
  912. else
  913. {
  914. const auto column = box.reduced (2, 4);
  915. juce::Graphics::ScopedSaveState state (g);
  916. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  917. const auto rotated = juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre());
  918. textcache::drawFittedText (g, name, rotated, juce::Justification::centredLeft, 1, 0.8f);
  919. }
  920. // mute (the members) and solo (the members)
  921. {
  922. const auto led = compactLayout ? 10.0f : 12.0f;
  923. const auto m = muteArea (v).toFloat().withSizeKeepingCentre (led, led);
  924. g.setColour (muteLed (vca.muted));
  925. g.fillEllipse (m);
  926. if (! vca.muted || hovered (Part::mute))
  927. {
  928. g.setColour (hovered (Part::mute) ? colour::textSecondary : colour::ledOn.withAlpha (0.25f));
  929. g.drawEllipse (m.expanded (2.0f), 1.0f);
  930. }
  931. const auto reach = mixerops::vcaReach (song, i);
  932. const auto soloed = ! reach.empty() && std::all_of (reach.begin(), reach.end(), [&song] (int t) {
  933. return t > 0 && t < (int) song.mixer.size() && song.mixer[(std::size_t) t].solo;
  934. });
  935. const auto s = soloArea (v).toFloat().reduced (2.0f);
  936. theme::fillRoundRect (g, s, radius::sm, soloed ? colour::accent : hovered (Part::solo) ? colour::bg5 : colour::bg0);
  937. g.setColour (soloed ? colour::onAccent : hovered (Part::solo) ? colour::textPrimary : colour::textSecondary);
  938. g.setFont (font (type::caption, true));
  939. textcache::drawText (g, "S", s.toNearestInt(), juce::Justification::centred);
  940. }
  941. // the loudest member's meter and the VCA's fader
  942. const auto area = faderArea (v);
  943. const auto meters = meterArea (v);
  944. const auto fader = faderRail (v);
  945. for (int ch = 0; ch < 2; ++ch)
  946. {
  947. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  948. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  949. }
  950. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  951. paintVcaMeter (g, i);
  952. const auto railX = (float) fader.getCentreX();
  953. const auto level = vcaShownLevel (i);
  954. const auto capY = (float) fader.getBottom() - level * (float) fader.getHeight();
  955. theme::fillRoundRect (g, { railX - 2.0f, (float) fader.getY(), 4.0f, (float) fader.getHeight() }, 2.0f, colour::bg0);
  956. theme::fillRoundRect (g, { railX - 2.0f, capY, 4.0f, juce::jmax (0.0f, (float) fader.getBottom() - capY) }, 2.0f, colourOf.withAlpha (vca.muted ? 0.35f : 0.8f));
  957. const auto unityY = (float) fader.getBottom() - unityFader * (float) fader.getHeight();
  958. g.setColour (colour::textDisabled);
  959. g.drawHorizontalLine ((int) unityY, (float) fader.getX(), railX - 5.0f);
  960. g.drawHorizontalLine ((int) unityY, railX + 5.0f, (float) fader.getRight());
  961. const auto capActive = hovered (Part::fader) || dragVca == i;
  962. const auto capWidth = juce::jmin ((float) fader.getWidth() + 2.0f, 26.0f);
  963. const auto cap = juce::Rectangle<float> (capWidth, 12.0f).withCentre ({ railX, capY });
  964. theme::fillRoundRect (g, cap.translated (0.0f, 1.5f), radius::sm, juce::Colours::black.withAlpha (0.35f));
  965. theme::fillRoundRect (g, cap, radius::sm, capActive ? juce::Colour (0xffffffff) : juce::Colour (0xffd4d7dd));
  966. g.setColour (colourOf);
  967. g.fillRect (cap.withSizeKeepingCentre (capWidth - 8.0f, 2.0f));
  968. if (sp.dbReadout)
  969. {
  970. g.setColour (colour::textSecondary);
  971. g.setFont (font (type::caption));
  972. textcache::drawFittedText (g, faderToDb (level) + " dB", juce::Rectangle<int> (x, area.getBottom() + 3, plateWidth, 14), juce::Justification::centred, 1, 0.7f);
  973. }
  974. }
  975. juce::Rectangle<int> MixerStrips::headerArea (int t) const
  976. {
  977. return { stripX (t), 0, stripWidthOf (t) - spec().gap, rows().header };
  978. }
  979. juce::Rectangle<int> MixerStrips::nameArea (int t) const
  980. {
  981. const auto r = rows();
  982. const auto w = stripWidthOf (t) - spec().gap;
  983. if (r.nameHeight <= 0) // Extra large: the name row of the header
  984. return { stripX (t) + 3, 38, w - 6, 14 };
  985. // the name runs up the strip's left part; the right part shows the meters (as FL's)
  986. const auto nameWidth = mixerlayout::isCompact (layout) ? w : juce::jmax (14, w - 2 * spec().meterWidth - 8);
  987. return { stripX (t), r.nameTop, nameWidth, r.nameHeight };
  988. }
  989. juce::Rectangle<int> MixerStrips::iconArea (int t) const
  990. {
  991. const auto w = stripWidthOf (t) - spec().gap;
  992. const auto size = juce::jmin (16, w - 2);
  993. return { stripX (t) + (w - size) / 2, rows().iconY, size, size };
  994. }
  995. juce::Rectangle<int> MixerStrips::armArea (int t) const
  996. {
  997. const auto r = rows();
  998. if (r.armY >= 0)
  999. {
  1000. const auto w = stripWidthOf (t) - spec().gap;
  1001. return { stripX (t) + (w - 13) / 2, r.armY, 13, 13 };
  1002. }
  1003. return { stripX (t) + 4, 4, 13, 13 };
  1004. }
  1005. juce::Rectangle<int> MixerStrips::inputArea (int t) const
  1006. {
  1007. // a thin level bar under the header (inserts with an input source)
  1008. return { stripX (t) + 3, rows().header - 3, stripWidthOf (t) - spec().gap - 6, 3 };
  1009. }
  1010. juce::Rectangle<int> MixerStrips::panArea (int t) const
  1011. {
  1012. const auto r = rows();
  1013. const auto& sp = spec();
  1014. const auto w = stripWidthOf (t) - sp.gap;
  1015. if (! sp.stereoKnob)
  1016. return { stripX (t), r.knobsTop, w, r.knobsHeight };
  1017. if (sp.stackedKnobs)
  1018. return { stripX (t), r.knobsTop, w, sp.knobSize + 4 };
  1019. return { stripX (t), r.knobsTop, w / 2, r.knobsHeight };
  1020. }
  1021. juce::Rectangle<int> MixerStrips::stereoArea (int t) const
  1022. {
  1023. const auto r = rows();
  1024. const auto& sp = spec();
  1025. const auto w = stripWidthOf (t) - sp.gap;
  1026. if (! sp.stereoKnob)
  1027. return {};
  1028. if (sp.stackedKnobs)
  1029. return { stripX (t), r.knobsTop + sp.knobSize + 4, w, r.knobsHeight - sp.knobSize - 4 };
  1030. return { stripX (t) + w / 2, r.knobsTop, w - w / 2, r.knobsHeight };
  1031. }
  1032. juce::Rectangle<int> MixerStrips::muteArea (int t) const
  1033. {
  1034. const auto r = rows();
  1035. const auto w = stripWidthOf (t) - spec().gap;
  1036. if (mixerlayout::isCompact (layout))
  1037. return { stripX (t), r.buttonsTop, w, 16 };
  1038. if (t == 0)
  1039. return { stripX (t) + 4, r.buttonsTop, 24, r.buttonsHeight };
  1040. return { stripX (t) + 2, r.buttonsTop, w / 2 - 2, r.buttonsHeight };
  1041. }
  1042. juce::Rectangle<int> MixerStrips::soloArea (int t) const
  1043. {
  1044. const auto r = rows();
  1045. const auto w = stripWidthOf (t) - spec().gap;
  1046. if (mixerlayout::isCompact (layout))
  1047. return { stripX (t) + (w - 16) / 2, r.buttonsTop + 16, 16, 16 };
  1048. return { stripX (t) + w - juce::jmin (24, w / 2), r.buttonsTop, juce::jmin (24, w / 2), r.buttonsHeight };
  1049. }
  1050. juce::Rectangle<int> MixerStrips::faderArea (int t) const
  1051. {
  1052. const auto r = rows();
  1053. const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
  1054. return { stripX (t) + inset, r.faderTop, stripWidthOf (t) - spec().gap - 2 * inset, r.faderBottom - r.faderTop };
  1055. }
  1056. juce::Rectangle<int> MixerStrips::meterArea (int t) const
  1057. {
  1058. return faderArea (t).withWidth (spec().meterWidth * 2 + 2);
  1059. }
  1060. juce::Rectangle<int> MixerStrips::grArea (int t) const
  1061. {
  1062. // in the gap between the meters and the fader (compact layouts have none: over the right meter's edge)
  1063. const auto meters = meterArea (t);
  1064. return mixerlayout::isCompact (layout) ? meters.withTrimmedLeft (meters.getWidth() - 2) : meters.withX (meters.getRight() + 1).withWidth (3);
  1065. }
  1066. float MixerStrips::gainReduction (int t) const
  1067. {
  1068. const auto& mixer = engine.getSong().mixer;
  1069. if (t <= 0 || t >= (int) mixer.size())
  1070. return -1.0f;
  1071. const auto* times = engine.getProcessTimes();
  1072. auto gr = -1.0f;
  1073. const auto& slots = mixer[(std::size_t) t].effects;
  1074. for (int s = 0; s < (int) slots.size() && s < maxEffectSlots; ++s)
  1075. {
  1076. if (! slots[(std::size_t) s].enabled || ! mixerops::reportsGainReduction (slots[(std::size_t) s].kind))
  1077. continue;
  1078. const auto key = (std::size_t) (t * maxEffectSlots + s) * ProcessTimes::meterOutputs;
  1079. const auto v = times != nullptr && key < times->effectMeters.size() ? times->effectMeters[key].load (std::memory_order_relaxed) : 0.0f;
  1080. gr = juce::jmax (gr, juce::jlimit (0.0f, 1.0f, v));
  1081. }
  1082. return gr;
  1083. }
  1084. juce::Rectangle<int> MixerStrips::faderRail (int t) const
  1085. {
  1086. return faderArea (t).withTrimmedLeft (spec().meterWidth * 2 + (mixerlayout::isCompact (layout) ? 3 : 6) + (t == 0 ? masterScaleWidth : 0));
  1087. }
  1088. juce::Rectangle<int> MixerStrips::routeArea (int t) const
  1089. {
  1090. const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
  1091. return { stripX (t) + inset, laneTop() + 2, stripWidthOf (t) - spec().gap - 2 * inset, switchHeight };
  1092. }
  1093. juce::Rectangle<int> MixerStrips::arrowArea (int t) const
  1094. {
  1095. return { stripX (t), laneTop() - arrowRowHeight - 2, stripWidthOf (t) - spec().gap, arrowRowHeight };
  1096. }
  1097. juce::Rectangle<int> MixerStrips::insertsArea (int t) const
  1098. {
  1099. const auto r = rows();
  1100. if (r.insertsHeight <= 0 || t < 0 || t >= (int) engine.getSong().mixer.size() || isFoldTab (t))
  1101. return {};
  1102. return { stripX (t) + 2, r.insertsTop, stripWidthOf (t) - spec().gap - 4, r.insertsHeight - 4 };
  1103. }
  1104. // --- issue #154 part 2 (round 190io): the strip's insert effects list (the linked track headers' list, round 190ht) ----
  1105. void MixerStrips::setShowStripInserts (bool on)
  1106. {
  1107. showStripInserts = on;
  1108. insertsScroll.clear();
  1109. hoverInsertItem = -1;
  1110. updateSize();
  1111. repaint();
  1112. }
  1113. int MixerStrips::insertsFirst (int t) const
  1114. {
  1115. const auto found = insertsScroll.find (t);
  1116. const auto effects = (int) engine.getSong().mixer[(std::size_t) t].effects.size();
  1117. const auto geo = insertsGeometry();
  1118. return stripinserts::clampFirst (geo, found == insertsScroll.end() ? 0 : found->second, effects, stripinserts::rowsThatFit (geo, insertsArea (t).getHeight()));
  1119. }
  1120. int MixerStrips::insertsItemAt (int t, juce::Point<int> p) const
  1121. {
  1122. const auto box = insertsArea (t);
  1123. if (! box.contains (p))
  1124. return -1;
  1125. const auto effects = (int) engine.getSong().mixer[(std::size_t) t].effects.size();
  1126. const auto geo = insertsGeometry();
  1127. return stripinserts::itemAt (geo, effects, insertsFirst (t), stripinserts::rowsThatFit (geo, box.getHeight()), p.y - box.getY());
  1128. }
  1129. void MixerStrips::paintStripInserts (juce::Graphics& g, int t)
  1130. {
  1131. using namespace theme;
  1132. if (flInsertList())
  1133. return paintFlInsertList (g, t);
  1134. const auto box = insertsArea (t);
  1135. const auto& fx = engine.getSong().mixer[(std::size_t) t].effects;
  1136. const auto effects = (int) fx.size();
  1137. const auto rows = trackinserts::rowsThatFit (box.getHeight());
  1138. const auto first = insertsFirst (t);
  1139. const auto hoveredHere = hoverTrack == t && hoverPart == Part::inserts;
  1140. const auto led = juce::jmin (trackinserts::ledWidth, box.getWidth() / 3);
  1141. // a recessed well, as the Mixer's slot list; one row per effect in chain order, then "+" while a slot is free
  1142. theme::fillRoundRect (g, box.toFloat().expanded (1.0f, 2.0f), radius::sm, colour::bg0.withAlpha (0.7f));
  1143. g.setFont (font (10.0f));
  1144. for (int r = 0; r < rows; ++r)
  1145. {
  1146. const auto item = first + r;
  1147. if (item > effects || (item == effects && effects >= maxEffectSlots))
  1148. break;
  1149. const auto row = juce::Rectangle<int> (box.getX(), box.getY() + r * trackinserts::rowHeight, box.getWidth(), trackinserts::rowHeight);
  1150. const auto isAdd = item == effects;
  1151. const auto under = hoveredHere && hoverInsertItem == (isAdd ? trackinserts::addRow : item);
  1152. const auto dragged = insertsDragging && insertsPressTrack == t && insertsPressItem == item;
  1153. if (under || dragged)
  1154. theme::fillRoundRect (g, row.toFloat().reduced (0.0f, 0.5f), 2.0f, colour::bg5.withAlpha (dragged ? 0.9f : 0.6f));
  1155. if (isAdd)
  1156. {
  1157. g.setColour (under ? colour::textPrimary : colour::textSecondary.withAlpha (0.8f));
  1158. textcache::drawText (g, "+", row.withWidth (led), juce::Justification::centred, false);
  1159. textcache::drawText (g, tr ("Add"), row.withTrimmedLeft (led + 1), juce::Justification::centredLeft, true);
  1160. continue;
  1161. }
  1162. const auto& slot = fx[(std::size_t) item];
  1163. // the on/off dot (the Mixer slot's LED): filled while on, a ring while bypassed
  1164. const auto dot = row.withWidth (led).toFloat().withSizeKeepingCentre (6.0f, 6.0f);
  1165. const auto dotHot = under && hoverInsertLed;
  1166. if (slot.enabled)
  1167. {
  1168. g.setColour (dotHot ? colour::accentHover : colour::accent);
  1169. g.fillEllipse (dot);
  1170. }
  1171. else
  1172. {
  1173. g.setColour (dotHot ? colour::textPrimary : colour::textSecondary.withAlpha (0.7f));
  1174. g.drawEllipse (dot.reduced (0.5f), 1.0f);
  1175. }
  1176. g.setColour (slot.enabled ? colour::textPrimary : colour::textSecondary.withAlpha (0.6f));
  1177. textcache::drawText (g, quickpick::slotName (engine, slot), row.withTrimmedLeft (led + 1).withTrimmedRight (2), juce::Justification::centredLeft, true);
  1178. }
  1179. // more rows than fit: a thin scroll mark at the right edge
  1180. if (const auto items = trackinserts::itemCount (effects); items > rows)
  1181. {
  1182. const auto h = juce::jmax (4.0f, (float) box.getHeight() * (float) rows / (float) items);
  1183. const auto y = (float) box.getY() + ((float) box.getHeight() - h) * (float) first / (float) juce::jmax (1, items - rows);
  1184. theme::fillRoundRect (g, juce::Rectangle<float> ((float) box.getRight() - 2.0f, y, 2.0f, h), 1.0f, colour::textSecondary.withAlpha (0.5f));
  1185. }
  1186. // a drag in progress: where the effect lands
  1187. if (insertsDragging && insertsDropTrack == t && insertsDropAt >= 0)
  1188. {
  1189. const auto y = box.getY() + (insertsDropAt - first) * trackinserts::rowHeight;
  1190. if (y >= box.getY() - 1 && y <= box.getBottom() + 1)
  1191. {
  1192. g.setColour (colour::accent);
  1193. g.fillRect (box.getX() + 1, juce::jlimit (box.getY(), box.getBottom() - 2, y - 1), box.getWidth() - 2, 2);
  1194. }
  1195. }
  1196. }
  1197. // FL's Extra large list (round 190jd, live check 190iw Q6; q6-fl-mixer-extralarge-fxlist-zoom2.png): one 23 px cell per
  1198. // used slot in slot order, a little darker than the strip, the name cut in the middle in FL's light grey-blue; empty
  1199. // cells below (fainter, 1 px lines between them); no bypass dots, icons or "add" row. Hover / drag as the LYNX view.
  1200. void MixerStrips::paintFlInsertList (juce::Graphics& g, int t)
  1201. {
  1202. using namespace theme;
  1203. const auto geo = stripinserts::flExtraLarge;
  1204. const auto box = insertsArea (t);
  1205. const auto& fx = engine.getSong().mixer[(std::size_t) t].effects;
  1206. const auto effects = (int) fx.size();
  1207. const auto rows = stripinserts::rowsThatFit (geo, box.getHeight());
  1208. const auto first = insertsFirst (t);
  1209. const auto hoveredHere = hoverTrack == t && hoverPart == Part::inserts;
  1210. const auto f = font (11.0f);
  1211. g.setFont (f);
  1212. // FL: empty cells (53,37,36) on a (56,40,39) strip with lighter 1 px lines; used cells (47,31,30)
  1213. for (int r = 0; r < rows; ++r)
  1214. {
  1215. const auto item = first + r;
  1216. const auto row = juce::Rectangle<int> (box.getX() - 1, box.getY() + r * geo.rowHeight, box.getWidth() + 2, geo.rowHeight);
  1217. const auto used = item < effects;
  1218. g.setColour (juce::Colours::black.withAlpha (used ? 0.17f : 0.06f));
  1219. g.fillRect (row.withTrimmedTop (1));
  1220. g.setColour (juce::Colours::white.withAlpha (0.025f));
  1221. g.fillRect (row.withHeight (1));
  1222. if (! used)
  1223. continue;
  1224. const auto under = hoveredHere && hoverInsertItem == item;
  1225. const auto dragged = insertsDragging && insertsPressTrack == t && insertsPressItem == item;
  1226. if (under || dragged)
  1227. {
  1228. g.setColour (colour::bg5.withAlpha (dragged ? 0.9f : 0.6f));
  1229. g.fillRect (row.withTrimmedTop (1));
  1230. }
  1231. const auto& slot = fx[(std::size_t) item];
  1232. const auto text = row.withTrimmedLeft (4).withTrimmedRight (2);
  1233. g.setColour (juce::Colour (0xffc6d3d9).withAlpha (slot.enabled ? 1.0f : 0.5f)); // (FL's text; a bypassed one dims, no mark)
  1234. textcache::drawText (g, theme::fitMiddle (quickpick::slotName (engine, slot), f, (float) text.getWidth()), text, juce::Justification::centredLeft, false);
  1235. }
  1236. if (const auto items = stripinserts::itemCount (geo, effects); items > rows)
  1237. {
  1238. const auto h = juce::jmax (4.0f, (float) box.getHeight() * (float) rows / (float) items);
  1239. const auto y = (float) box.getY() + ((float) box.getHeight() - h) * (float) first / (float) juce::jmax (1, items - rows);
  1240. theme::fillRoundRect (g, juce::Rectangle<float> ((float) box.getRight() - 2.0f, y, 2.0f, h), 1.0f, colour::textSecondary.withAlpha (0.5f));
  1241. }
  1242. if (insertsDragging && insertsDropTrack == t && insertsDropAt >= 0)
  1243. {
  1244. const auto y = box.getY() + (insertsDropAt - first) * geo.rowHeight;
  1245. if (y >= box.getY() - 1 && y <= box.getBottom() + 1)
  1246. {
  1247. g.setColour (colour::accent);
  1248. g.fillRect (box.getX() + 1, juce::jlimit (box.getY(), box.getBottom() - 2, y - 1), box.getWidth() - 2, 2);
  1249. }
  1250. }
  1251. }
  1252. EffectsPanel& MixerStrips::insertActions (int insert)
  1253. {
  1254. if (insertActionsPanel == nullptr)
  1255. {
  1256. insertActionsPanel = std::make_unique<EffectsPanel> (engine); // never shown: the Mixer slot's own code
  1257. insertActionsPanel->setMenuTarget (this);
  1258. }
  1259. insertActionsPanel->setTrack (insert);
  1260. return *insertActionsPanel;
  1261. }
  1262. bool MixerStrips::insertsMouseDown (const juce::MouseEvent& e, int t)
  1263. {
  1264. if (! insertsArea (t).contains (e.getPosition()))
  1265. return false;
  1266. const auto item = insertsItemAt (t, e.getPosition());
  1267. insertsPressTrack = insertsPressItem = insertsDropTrack = insertsDropAt = -1;
  1268. insertsDragging = false;
  1269. const auto& fx = engine.getSong().mixer[(std::size_t) t].effects;
  1270. if (flmods::popup (e.mods))
  1271. {
  1272. // the Mixer slot's own menu; on "+" or below the list, the slot's add menu
  1273. auto& actions = insertActions (t);
  1274. if (item >= 0)
  1275. actions.showSlotMenuFor (item);
  1276. else if (fx.size() < (std::size_t) maxEffectSlots)
  1277. actions.showAddMenuFor (trackinserts::nextFreeRow (fx));
  1278. return true;
  1279. }
  1280. if (e.getNumberOfClicks() > 1)
  1281. return true; // (a double click opens nothing twice)
  1282. insertsPressTrack = t;
  1283. insertsPressItem = item;
  1284. return true;
  1285. }
  1286. bool MixerStrips::insertsMouseDrag (const juce::MouseEvent& e)
  1287. {
  1288. if (insertsPressTrack < 0)
  1289. return false;
  1290. if (insertsPressItem >= 0 && (insertsDragging || e.getDistanceFromDragStart() > 4))
  1291. {
  1292. // drag an effect: up / down in its list reorders it, onto another strip's list moves it there (Ctrl: a copy)
  1293. insertsDragging = true;
  1294. const auto over = trackAt (juce::jlimit (0, getWidth() - 1, e.x));
  1295. const auto box = over >= 0 ? insertsArea (over) : juce::Rectangle<int>();
  1296. const auto geo = insertsGeometry();
  1297. if (! box.isEmpty() && e.y >= box.getY() - geo.rowHeight && e.y < box.getBottom() + geo.rowHeight)
  1298. {
  1299. const auto effects = (int) engine.getSong().mixer[(std::size_t) over].effects.size();
  1300. insertsDropTrack = over;
  1301. insertsDropAt = over == insertsPressTrack
  1302. ? stripinserts::dropPosition (geo, effects, insertsFirst (over), stripinserts::rowsThatFit (geo, box.getHeight()), e.y - box.getY())
  1303. : effects;
  1304. }
  1305. else
  1306. insertsDropTrack = insertsDropAt = -1;
  1307. repaint (0, rows().insertsTop - 3, getWidth(), rows().insertsHeight + 4);
  1308. }
  1309. return true;
  1310. }
  1311. bool MixerStrips::insertsMouseUp (const juce::MouseEvent& e)
  1312. {
  1313. if (insertsPressTrack < 0)
  1314. return false;
  1315. const auto insert = insertsPressTrack, item = insertsPressItem, dropTrack = insertsDropTrack, dropAt = insertsDropAt;
  1316. const auto dragged = insertsDragging;
  1317. insertsPressTrack = insertsPressItem = insertsDropTrack = insertsDropAt = -1;
  1318. insertsDragging = false;
  1319. if (insert < 0 || insert >= (int) engine.getSong().mixer.size())
  1320. return true;
  1321. const auto copy = flmods::ctrl (e.mods);
  1322. const auto full = [] { ui::postHint ({ tr ("This insert has no free slot (10 effects)"), {} }, 3000); };
  1323. if (dragged)
  1324. {
  1325. const auto target = item >= 0 ? dropTrack : -1; // (outside a list: nothing changes)
  1326. if (target >= 0 && target != insert)
  1327. {
  1328. auto moved = -1;
  1329. engine.editSongStructural ([insert, item, target, copy, &moved] (Song& s) { moved = detailchain::moveEffectToInsert (s, insert, item, target, copy); });
  1330. if (moved < 0)
  1331. full();
  1332. }
  1333. else if (target == insert && copy)
  1334. {
  1335. if (engine.getSong().mixer[(std::size_t) insert].effects.size() >= (std::size_t) maxEffectSlots)
  1336. full();
  1337. else
  1338. engine.editSong ([insert, item, dropAt] (Song& s) { detailchain::duplicateEffect (s, insert, item, dropAt); });
  1339. }
  1340. else if (target == insert)
  1341. engine.editSongStructural ([insert, item, dropAt] (Song& s) { detailchain::moveEffectBefore (s, insert, item, dropAt); });
  1342. repaint();
  1343. return true;
  1344. }
  1345. if (item == trackinserts::addRow)
  1346. {
  1347. insertActions (insert).showAddMenuFor (trackinserts::nextFreeRow (engine.getSong().mixer[(std::size_t) insert].effects));
  1348. return true;
  1349. }
  1350. if (item < 0)
  1351. return true;
  1352. if (insertsGeometry().dots && e.getMouseDownX() < insertsArea (insert).getX() + juce::jmin (trackinserts::ledWidth, insertsArea (insert).getWidth() / 3) + 1)
  1353. {
  1354. // the dot: the effect on / off (the Mixer slot LED's edit)
  1355. engine.editSong ([insert, item] (Song& s) {
  1356. auto& fx = s.mixer[(std::size_t) insert].effects;
  1357. if (item < (int) fx.size())
  1358. fx[(std::size_t) item].enabled = ! fx[(std::size_t) item].enabled;
  1359. });
  1360. return true;
  1361. }
  1362. insertActions (insert).toggleSlotEditor (item); // the name: its window (as a click on a Mixer slot)
  1363. return true;
  1364. }
  1365. bool MixerStrips::insertsWheel (const juce::MouseEvent& e, float deltaY)
  1366. {
  1367. const auto t = trackAt (e.x);
  1368. if (t < 0 || deltaY == 0.0f)
  1369. return false;
  1370. const auto box = insertsArea (t);
  1371. if (! box.contains (e.getPosition()))
  1372. return false;
  1373. const auto effects = (int) engine.getSong().mixer[(std::size_t) t].effects.size();
  1374. const auto geo = insertsGeometry();
  1375. const auto rows = stripinserts::rowsThatFit (geo, box.getHeight());
  1376. if (stripinserts::itemCount (geo, effects) <= rows)
  1377. return false; // everything shows: the wheel scrolls the Mixer as usual
  1378. insertsScroll[t] = stripinserts::clampFirst (geo, insertsFirst (t) + (deltaY > 0 ? -1 : 1), effects, rows);
  1379. repaint (box.expanded (2));
  1380. return true;
  1381. }
  1382. juce::Rectangle<int> MixerStrips::sendArea (int t) const
  1383. {
  1384. return { stripX (t), laneTop() + 2 + switchHeight, stripWidthOf (t) - spec().gap, sendKnobHeight };
  1385. }
  1386. MixerStrips::Part MixerStrips::partAt (int t, juce::Point<int> p) const
  1387. {
  1388. const auto& song = engine.getSong();
  1389. if (t == (int) song.mixer.size())
  1390. return Part::add;
  1391. if (t < 0 || t > (int) song.mixer.size())
  1392. return Part::none;
  1393. const auto sending = selected > 0 && t != selected && selected < (int) song.mixer.size();
  1394. if (isFoldTab (t))
  1395. return Part::tab;
  1396. if (t > 0 && t < (int) foldHead.size() && foldHead[(std::size_t) t] && foldArea (t).contains (p))
  1397. return Part::fold;
  1398. if (t > 0 && armArea (t).expanded (1).contains (p))
  1399. return Part::arm;
  1400. if (t > 0 && t < (int) engine.getSong().mixer.size() && engine.getSong().mixer[(std::size_t) t].inputChannel >= 0
  1401. && inputArea (t).expanded (0, 2).contains (p))
  1402. return Part::input;
  1403. if (insertsArea (t).contains (p))
  1404. return Part::inserts;
  1405. if (headerArea (t).contains (p) || nameArea (t).contains (p))
  1406. return Part::header;
  1407. // FL's route arrow (round 190io): the Send switch from the selected track, as the "→ n" pill
  1408. if (sending && arrowArea (t).contains (p) && (song.routes (selected, t) || song.canRoute (selected, t)))
  1409. return Part::route;
  1410. if (panArea (t).contains (p))
  1411. return Part::pan;
  1412. if (stereoArea (t).contains (p))
  1413. return Part::stereo;
  1414. if (muteArea (t).contains (p))
  1415. return Part::mute;
  1416. if (t > 0 && soloArea (t).contains (p))
  1417. return Part::solo;
  1418. if (sending && routeArea (t).contains (p) && (song.routes (selected, t) || song.canRoute (selected, t)))
  1419. return Part::route;
  1420. if (sending && sendArea (t).contains (p) && song.routes (selected, t))
  1421. return Part::send;
  1422. if (meterArea (t).contains (p))
  1423. return Part::meter;
  1424. if (faderRail (t).expanded (0, 6).contains (p))
  1425. return Part::fader;
  1426. return Part::body;
  1427. }
  1428. juce::Rectangle<int> MixerStrips::tipArea (Part part, int t) const
  1429. {
  1430. switch (part)
  1431. {
  1432. case Part::pan: return panArea (t);
  1433. case Part::stereo: return stereoArea (t);
  1434. case Part::send: return sendArea (t);
  1435. case Part::route: return routeArea (t);
  1436. case Part::fader:
  1437. {
  1438. const auto rail = faderRail (t);
  1439. const auto& mixer = engine.getSong().mixer;
  1440. const auto v = t >= 0 && t < (int) mixer.size() ? shownVolume (t) : 0.0f;
  1441. const auto capY = rail.getBottom() - (int) (v * (float) rail.getHeight());
  1442. return { rail.getX(), capY - 6, rail.getWidth(), 12 };
  1443. }
  1444. default: return {};
  1445. }
  1446. }
  1447. void MixerStrips::showTip (Part part, int t, bool transient)
  1448. {
  1449. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  1450. return;
  1451. const auto spec = specFor (part, t);
  1452. const auto text = spec.text (valueOf (part, t));
  1453. ui::postHint (ui::valueHint (spec, valueOf (part, t), ui::valueGestures()));
  1454. if (transient)
  1455. ui::flashValueTip (*this, tipArea (part, t), text);
  1456. else
  1457. ui::showValueTip (*this, tipArea (part, t), text);
  1458. }
  1459. void MixerStrips::setHover (Part part, int t)
  1460. {
  1461. if (part == hoverPart && t == hoverTrack)
  1462. return;
  1463. auto dirty = [this] (int track) {
  1464. if (track >= 0 || track <= -2) // (≤ -2: a VCA strip)
  1465. repaint (stripX (track) - 2, 0, stripWidthOf (track) + 4, getHeight());
  1466. };
  1467. dirty (hoverTrack);
  1468. hoverPart = part;
  1469. hoverTrack = t;
  1470. dirty (hoverTrack);
  1471. }
  1472. void MixerStrips::mouseMove (const juce::MouseEvent& e)
  1473. {
  1474. if (const auto i = vcaAt (e.x); i >= 0)
  1475. {
  1476. setHover (vcaPartAt (i, e.getPosition()), vcaStrip (i));
  1477. return;
  1478. }
  1479. if (const auto over = showLoudness && loudnessResetArea().contains (e.getPosition()); over != loudnessResetHovered)
  1480. {
  1481. loudnessResetHovered = over;
  1482. repaint (loudnessResetArea().expanded (2));
  1483. }
  1484. const auto t = trackAt (e.x);
  1485. const auto part = t >= 0 ? partAt (t, e.getPosition()) : Part::none;
  1486. // issue #154 part 2: the effect row (and its dot) under the mouse
  1487. const auto item = part == Part::inserts ? insertsItemAt (t, e.getPosition()) : -1;
  1488. const auto led = item >= 0 && insertsGeometry().dots && e.x < insertsArea (t).getX() + juce::jmin (trackinserts::ledWidth, insertsArea (t).getWidth() / 3) + 1;
  1489. if (item != hoverInsertItem || led != hoverInsertLed)
  1490. {
  1491. hoverInsertItem = item;
  1492. hoverInsertLed = led;
  1493. if (part == Part::inserts && hoverPart == part && hoverTrack == t)
  1494. repaint (insertsArea (t).expanded (2));
  1495. }
  1496. setHover (part, t);
  1497. }
  1498. void MixerStrips::mouseExit (const juce::MouseEvent&)
  1499. {
  1500. if (std::exchange (loudnessResetHovered, false))
  1501. repaint (loudnessResetArea().expanded (2));
  1502. setHover (Part::none, -1);
  1503. }
  1504. void MixerStrips::paint (juce::Graphics& g)
  1505. {
  1506. const uitrace::Scope trace ("MixerStrips paint", true, g.getClipBounds());
  1507. using namespace theme;
  1508. const auto& song = engine.getSong();
  1509. const auto tracks = (int) song.mixer.size();
  1510. const auto clip = g.getClipBounds();
  1511. // round 173f: a frame of the meters' timer repaints only the meter rectangles, but the clip's bounds span every strip
  1512. // between them, so each strip's parts are drawn only where the frame's region (not its bounds) reaches them
  1513. const auto needs = [&g] (juce::Rectangle<int> area) { return g.clipRegionIntersects (area.expanded (3)); };
  1514. g.fillAll (colour::bg1);
  1515. // the routing lane runs under all strips
  1516. g.setColour (colour::bg0.withAlpha (0.55f));
  1517. g.fillRect (0, laneTop() + switchHeight + sendKnobHeight + 2, getWidth(), wiresHeight + 2);
  1518. // FL's separators (a line on the left of the track) and the gaps between the dock blocks (round 146a), drawn
  1519. // per block so the pinned left / right blocks cover the scrolled middle (round 149)
  1520. auto paintDividers = [&] (MixerDock dock) {
  1521. const auto shift = pinOffset (dock);
  1522. g.setColour (colour::borderStrong);
  1523. for (auto [lx, d] : separatorLines)
  1524. if (d == dock)
  1525. theme::fillRoundRect (g, { (float) (lx + shift), 8.0f, 2.0f, (float) laneTop() - 14.0f }, 1.0f, colour::borderStrong);
  1526. g.setColour (colour::bg0);
  1527. for (auto [gx, d] : dockGaps)
  1528. if (d == dock)
  1529. g.fillRect (gx + shift - 3, 0, 6, getHeight());
  1530. };
  1531. for (auto pass : { MixerDock::middle, MixerDock::left, MixerDock::right })
  1532. {
  1533. if (pass == MixerDock::middle)
  1534. {
  1535. // "+" button
  1536. if (tracks < maxMixerTracks)
  1537. {
  1538. const auto add = juce::Rectangle<int> (stripX (tracks), 2, spec().stripWidth - spec().gap, 60).toFloat();
  1539. const auto addHovered = hoverPart == Part::add;
  1540. theme::fillRoundRect (g, add, radius::md, addHovered ? colour::bg4 : colour::bg2);
  1541. g.setColour (addHovered ? colour::borderStrong : colour::border);
  1542. g.drawRoundedRectangle (add.reduced (0.5f), radius::md, 1.0f);
  1543. icons::draw (g, Icon::plus, add.withSizeKeepingCentre (22.0f, 22.0f), addHovered ? colour::textPrimary : colour::textSecondary);
  1544. }
  1545. }
  1546. else if (const auto shift = pinOffset (pass); shift != 0) // a pinned block hides what scrolls under it
  1547. {
  1548. const auto d = (int) pass;
  1549. g.setColour (colour::bg1);
  1550. g.fillRect (blockStart[d] + shift, 0, blockEnd[d] - blockStart[d], laneTop());
  1551. g.setColour (colour::bg0.withAlpha (0.55f));
  1552. g.fillRect (blockStart[d] + shift, laneTop(), blockEnd[d] - blockStart[d], getHeight() - laneTop());
  1553. }
  1554. for (int t = 0; t < tracks; ++t)
  1555. {
  1556. if (song.mixer[(std::size_t) t].dock != pass || isHidden (t))
  1557. continue;
  1558. const auto x = stripX (t);
  1559. const auto w = stripWidthOf (t);
  1560. if (x > clip.getRight() || x + w < clip.getX())
  1561. continue;
  1562. if (isFoldTab (t))
  1563. {
  1564. paintFoldTab (g, t);
  1565. continue;
  1566. }
  1567. const auto& track = song.mixer[(std::size_t) t];
  1568. const auto& sp = spec();
  1569. const auto plateWidth = w - sp.gap;
  1570. const auto compactLayout = mixerlayout::isCompact (layout);
  1571. const auto strip = juce::Rectangle<int> (x, 2, plateWidth, laneTop() - 2);
  1572. const auto isSelected = t == selected;
  1573. const auto inSelection = std::binary_search (selection.begin(), selection.end(), t);
  1574. const auto stripHovered = hoverTrack == t;
  1575. const auto hovered = [this, t] (Part p) { return hoverTrack == t && hoverPart == p; };
  1576. const auto dragging = [this, t] (Part p) { return dragTrack == t && dragPart == p; };
  1577. // the strip is tinted with the insert's colour (FL tints whole strips, so groups read at a glance);
  1578. // kept dark so meters, knobs and text keep their contrast
  1579. auto plate = isSelected || inSelection ? colour::bg4 : (t == 0 ? colour::bg3 : stripHovered ? colour::bg3 : colour::bg2);
  1580. if (track.colour != 0)
  1581. plate = plate.interpolatedWith (tame (juce::Colour (track.colour)), isSelected ? 0.26f : 0.2f);
  1582. theme::fillRoundRect (g, strip.toFloat(), radius::md, plate);
  1583. // FL's header band (round 190io, design190ia FM-30): the top 36 px filled with the insert's colour (FL: #8C1F1C on
  1584. // insert 1), held at a brightness where its marks read; FL's grey for an insert without a colour. Rounded on top.
  1585. const auto band = colourFill (track.colour != 0 ? juce::Colour (track.colour) : juce::Colour (0xff485156), 0.45f, 0.6f)
  1586. .withMultipliedAlpha (track.muted ? 0.55f : 1.0f);
  1587. const auto bandArea = juce::Rectangle<float> ((float) x, 2.0f, (float) plateWidth, (float) rows().header - 2.0f);
  1588. if (needs (bandArea.getSmallestIntegerContainer()))
  1589. fillPlate (g, bandArea, radius::md, band, band, true);
  1590. // the band's marks: FL's dark number (the colour × 0.3) where it reads, else white; the icon in a light tint
  1591. const auto bandInk = [&band] {
  1592. const auto dark = juce::Colour ((juce::uint8) (band.getRed() * 0.3f), (juce::uint8) (band.getGreen() * 0.3f), (juce::uint8) (band.getBlue() * 0.3f));
  1593. return contrast (dark, band) >= 3.0f ? dark : juce::Colours::white.withAlpha (0.92f);
  1594. }();
  1595. if (inSelection && ! isSelected)
  1596. {
  1597. g.setColour (colour::accent.withAlpha (0.3f));
  1598. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
  1599. }
  1600. if (isSelected)
  1601. {
  1602. g.setColour (colour::accent.withAlpha (0.55f));
  1603. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
  1604. theme::fillRoundRect (g, strip.toFloat().withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, colour::accent);
  1605. }
  1606. if (headerDragged && headerDragTrack == t)
  1607. {
  1608. g.setColour (colour::accent);
  1609. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.5f);
  1610. }
  1611. // record arm: the input recording goes through this insert
  1612. if (t > 0 && needs (armArea (t).getUnion (inputArea (t))))
  1613. {
  1614. const auto armed = engine.isInsertArmed (t);
  1615. const auto r = armArea (t).toFloat().reduced (2.0f);
  1616. g.setColour (armed ? colour::record : hovered (Part::arm) ? colour::bg5 : colour::bg0);
  1617. g.fillEllipse (r);
  1618. g.setColour (armed ? colour::record.brighter (0.3f) : hovered (Part::arm) ? colour::textSecondary : colour::borderStrong);
  1619. g.drawEllipse (r, 1.0f);
  1620. if (track.recordSafe) // record safe: a slash through the arm button
  1621. {
  1622. g.setColour (colour::textDisabled);
  1623. g.drawLine (r.getX() + 1.0f, r.getBottom() - 1.0f, r.getRight() - 1.0f, r.getY() + 1.0f, 1.2f);
  1624. }
  1625. // the input level (inserts with an audio input source)
  1626. if (track.inputChannel >= 0 && (std::size_t) t < inputLevels.size())
  1627. {
  1628. const auto bar = inputArea (t).toFloat();
  1629. theme::fillRoundRect (g, bar, 1.0f, colour::bg0);
  1630. const auto level = inputLevels[(std::size_t) t];
  1631. const auto fill = juce::jlimit (0.0f, 1.0f, (juce::Decibels::gainToDecibels (level, -60.0f) + 60.0f) / 60.0f);
  1632. theme::fillRoundRect (g, bar.withWidth (bar.getWidth() * fill), 1.0f, level >= 0.99f ? colour::record : colour::meterLow);
  1633. }
  1634. }
  1635. // header: number and effect count on one line, the icon under them (FL's place), then the name: on the
  1636. // header's last row (Extra large) or up a column of the strip (round 168h)
  1637. if (needs (juce::Rectangle<int> (x, 0, plateWidth, 18).getUnion (iconArea (t))))
  1638. {
  1639. g.setColour (bandInk);
  1640. g.setFont (font (compactLayout ? 10.0f : type::body, true));
  1641. textcache::drawFittedText (g, t == 0 ? juce::String ("M") : juce::String (t), juce::Rectangle<int> (x, 4, plateWidth, 14),
  1642. juce::Justification::centred, 1, 0.6f);
  1643. if (t < (int) foldHead.size() && foldHead[(std::size_t) t]) // round 177a: fold / unfold the group
  1644. {
  1645. const auto folded = mixerops::isFolded (song, t);
  1646. const auto box = foldArea (t).toFloat();
  1647. const auto c = box.getCentre();
  1648. icons::draw (g, Icon::chevronDown,
  1649. juce::Rectangle<float> (10.0f, 10.0f).withCentre (c).transformedBy (
  1650. juce::AffineTransform::rotation ((folded ? -1.0f : 1.0f) * juce::MathConstants<float>::halfPi, c.x, c.y)),
  1651. hovered (Part::fold) ? colour::textPrimary : colour::textSecondary);
  1652. }
  1653. if (const auto icon = trackicons::iconFor (track.icon); icon != trackicons::Icon::none)
  1654. ui::drawTrackIcon (g, icon, iconArea (t).toFloat(),
  1655. track.muted ? bandInk.withAlpha (0.5f)
  1656. : (track.colour != 0 ? juce::Colour (track.colour) : band).withMultipliedSaturation (0.45f).withBrightness (1.0f));
  1657. if (! track.effects.empty() && sp.fxBadge)
  1658. {
  1659. const auto on = mixerops::anyEffectEnabled (song, t);
  1660. g.setColour (bandInk.withAlpha (on ? 1.0f : 0.5f)); // (on the band: its ink)
  1661. g.setFont (font (9.0f, true));
  1662. if (plateWidth >= 56)
  1663. textcache::drawText (g, "FX" + juce::String ((int) track.effects.size()), x + plateWidth - 26, 4, 23, 13, juce::Justification::centredRight);
  1664. else // narrow strips: a dot at the number's right
  1665. g.fillEllipse ((float) (x + plateWidth) - 7.0f, 8.0f, 4.0f, 4.0f);
  1666. }
  1667. }
  1668. if (needs (nameArea (t).withX (x).withWidth (plateWidth)))
  1669. {
  1670. // FL's name in a light tint of the insert's colour ("KICK" red-pink on the red group; round 190io, FM-31), white
  1671. // where the tint would read below 4.5:1, one size up (FL's 10 px glyphs)
  1672. {
  1673. const auto tint = track.colour != 0 ? lightTint (juce::Colour (track.colour), plate, colour::textPrimary) : colour::textPrimary;
  1674. g.setColour (track.muted ? colour::textDisabled : hovered (Part::header) ? tint.brighter (0.2f) : tint.withAlpha (0.95f));
  1675. }
  1676. g.setFont (labelFont (compactLayout ? 10.0f : type::body, isSelected)); // (round 190je: condensed with FL-style labels on)
  1677. // Online Sessions (round 168a): a plugin of this insert is not installed here, its stand-in render plays (an
  1678. // amber R before the name)
  1679. const auto standIn = engine.insertPlaysStandIn (t);
  1680. // round 190ap: opened without third-party plugins, a plugin of this insert is still off (a grey power tag)
  1681. const auto pluginOff = ! standIn && engine.insertPluginOff (t);
  1682. const auto name = juce::String::fromUTF8 (track.name.c_str());
  1683. if (const auto box = nameArea (t); ! sp.verticalName)
  1684. {
  1685. const auto room = box.withTrimmedLeft (standIn || pluginOff ? 16 : 0);
  1686. textcache::drawFittedText (g, fitMiddle (name, g.getCurrentFont(), (float) room.getWidth() / 0.7f), room, juce::Justification::centred, 1, 0.7f);
  1687. if (standIn)
  1688. drawStandInTag (g, { (float) box.getX() + 1.0f, (float) box.getY() + 0.5f, 13.0f, 13.0f });
  1689. else if (pluginOff)
  1690. ui::drawPluginOffTag (g, { (float) box.getX() + 1.0f, (float) box.getY() + 0.5f, 13.0f, 13.0f });
  1691. }
  1692. else
  1693. {
  1694. // the name reads bottom to top, as FL's narrow strips do
  1695. auto column = box.reduced (2, 4);
  1696. if (standIn)
  1697. {
  1698. drawStandInTag (g, juce::Rectangle<float> (13.0f, 13.0f).withCentre ({ (float) column.getCentreX(), (float) column.getBottom() - 6.5f }));
  1699. column.removeFromBottom (16);
  1700. }
  1701. else if (pluginOff)
  1702. {
  1703. ui::drawPluginOffTag (g, juce::Rectangle<float> (13.0f, 13.0f).withCentre ({ (float) column.getCentreX(), (float) column.getBottom() - 6.5f }));
  1704. column.removeFromBottom (16);
  1705. }
  1706. juce::Graphics::ScopedSaveState state (g);
  1707. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  1708. const auto rotated = juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre());
  1709. // FL's middle ellipsis ("CUTLAY..idated)", FM-14) past what squeezing to 80 % fits
  1710. textcache::drawFittedText (g, fitMiddle (name, g.getCurrentFont(), (float) rotated.getWidth() / 0.8f), rotated, juce::Justification::centredLeft, 1,
  1711. 0.8f); // (laid out once: round 173f)
  1712. }
  1713. // FL's narrow strips show the level beside the name too: two thin bars (Wide layouts)
  1714. if (const auto bars = nameBars (t); ! bars.isEmpty())
  1715. {
  1716. theme::fillRoundRect (g, bars.toFloat(), 2.0f, colour::bg0.withAlpha (0.8f));
  1717. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  1718. paintNameBars (g, t);
  1719. }
  1720. }
  1721. // compensated latency (PDC) on the Master
  1722. if (t == 0 && engine.getLatencySamples() > 0 && ! compactLayout && needs (soloArea (t).withX (x).withWidth (w)))
  1723. {
  1724. const auto ms = 1000.0 * engine.getLatencySamples() / juce::jmax (1.0, engine.getTransport().sampleRate.load());
  1725. g.setColour (colour::textSecondary);
  1726. g.setFont (font (10.0f));
  1727. textcache::drawFittedText (g, "PDC " + juce::String (ms, 1) + " ms", soloArea (t).withX (x + 30).withWidth (w - 36),
  1728. juce::Justification::centredLeft, 1, 0.8f); // the Master has no solo: use its spot
  1729. }
  1730. // pan and stereo separation
  1731. const auto knob = (float) sp.knobSize;
  1732. const auto stereoKnob = sp.stackedKnobs ? knob - 6.0f : 22.0f;
  1733. if (needs (panArea (t).getUnion (stereoArea (t))))
  1734. {
  1735. drawKnob (g, panArea (t).toFloat().withSizeKeepingCentre (knob, knob),
  1736. engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerPan, t }, (track.pan + 1.0f) * 0.5f), true,
  1737. dragging (Part::pan) ? colour::accent : colour::info, hovered (Part::pan) || dragging (Part::pan));
  1738. if (sp.stereoKnob)
  1739. drawKnob (g, stereoArea (t).toFloat().withSizeKeepingCentre (stereoKnob, stereoKnob), (track.stereo + 1.0f) * 0.5f, true,
  1740. dragging (Part::stereo) ? colour::accent : colour::knobArc, hovered (Part::stereo) || dragging (Part::stereo));
  1741. }
  1742. // mute and solo
  1743. if (needs (muteArea (t).getUnion (soloArea (t))))
  1744. {
  1745. const auto led = compactLayout ? 10.0f : 12.0f;
  1746. const auto m = muteArea (t).toFloat().withSizeKeepingCentre (led, led);
  1747. g.setColour (muteLed (track.muted));
  1748. g.fillEllipse (m);
  1749. if (! track.muted || hovered (Part::mute))
  1750. {
  1751. g.setColour (hovered (Part::mute) ? colour::textSecondary : colour::ledOn.withAlpha (0.25f));
  1752. g.drawEllipse (m.expanded (2.0f), 1.0f);
  1753. }
  1754. if (t > 0)
  1755. {
  1756. const auto s = soloArea (t).toFloat().reduced (2.0f);
  1757. theme::fillRoundRect (g, s, radius::sm, track.solo ? colour::accent : hovered (Part::solo) ? colour::bg5 : colour::bg0);
  1758. g.setColour (track.solo ? colour::onAccent : hovered (Part::solo) ? colour::textPrimary : colour::textSecondary);
  1759. g.setFont (font (type::caption, true));
  1760. textcache::drawText (g, "S", s.toNearestInt(), juce::Justification::centred);
  1761. }
  1762. }
  1763. // meters + fader
  1764. {
  1765. const auto area = faderArea (t);
  1766. const auto meters = meterArea (t);
  1767. const auto fader = faderRail (t);
  1768. for (int ch = 0; ch < 2; ++ch)
  1769. {
  1770. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  1771. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  1772. if (! cachePainting) // (cached: the levels are drawn over the picture, paintMeterLevels)
  1773. paintMeterLevel (g, t, ch, bar);
  1774. }
  1775. if (hovered (Part::meter))
  1776. {
  1777. g.setColour (colour::textSecondary.withAlpha (0.5f));
  1778. g.drawRect (meters.expanded (1), 1);
  1779. }
  1780. // round 177d: gain reduction of the strip's own dynamics, hanging down from the top (deeper = more)
  1781. if (const auto gr = gainReduction (t); gr >= 0.0f)
  1782. {
  1783. const auto bar = grArea (t);
  1784. g.setColour (colour::bg0.withAlpha (0.6f));
  1785. g.fillRect (bar);
  1786. g.setColour (colour::meterMid);
  1787. g.fillRect (bar.withHeight (juce::roundToInt (gr * (float) bar.getHeight())));
  1788. }
  1789. // the master's dB scale (FL prints it beside the master meter): as many values as fit without overlapping
  1790. if (t == 0)
  1791. {
  1792. const auto scaleFont = font (9.0f);
  1793. const auto textHeight = 10.0f;
  1794. const auto left = (float) meters.getRight() + 1.0f;
  1795. g.setFont (scaleFont);
  1796. for (auto db : lynx::meters::scaleMarks ((float) meters.getHeight(), textHeight + 1.0f))
  1797. {
  1798. const auto y = (float) meters.getBottom() - lynx::meters::scalePosition ((float) db) * (float) meters.getHeight();
  1799. g.setColour (db == 0 ? colour::textPrimary : colour::textSecondary);
  1800. g.fillRect (juce::Rectangle<float> (left, y - 0.5f, 2.0f, 1.0f));
  1801. const auto box = juce::Rectangle<float> (left + 2.0f, y - textHeight * 0.5f, (float) masterScaleWidth - 2.0f, textHeight)
  1802. .withY (juce::jlimit ((float) meters.getY(), (float) meters.getBottom() - textHeight, y - textHeight * 0.5f));
  1803. textcache::drawText (g, (db > 0 ? "+" : "") + juce::String (db), box, juce::Justification::centredRight, false);
  1804. }
  1805. }
  1806. // fader track and 0 dB mark
  1807. const auto railX = (float) fader.getCentreX();
  1808. const auto volume = shownVolume (t); // (its automation's value while it plays: the fader moves, issue #12)
  1809. const auto capY = (float) fader.getBottom() - volume * (float) fader.getHeight();
  1810. theme::fillRoundRect (g, { railX - 2.0f, (float) fader.getY(), 4.0f, (float) fader.getHeight() }, 2.0f, colour::bg0);
  1811. theme::fillRoundRect (g, { railX - 2.0f, capY, 4.0f, juce::jmax (0.0f, (float) fader.getBottom() - capY) }, 2.0f, colour::bg6.brighter (0.15f).withAlpha (track.muted ? 0.4f : 1.0f));
  1812. const auto unityY = (float) fader.getBottom() - unityFader * (float) fader.getHeight();
  1813. g.setColour (colour::textDisabled);
  1814. g.drawHorizontalLine ((int) unityY, (float) fader.getX(), railX - 5.0f);
  1815. g.drawHorizontalLine ((int) unityY, railX + 5.0f, (float) fader.getRight());
  1816. const auto capActive = hovered (Part::fader) || dragging (Part::fader);
  1817. const auto capWidth = juce::jmin ((float) fader.getWidth() + 2.0f, 26.0f);
  1818. const auto cap = juce::Rectangle<float> (capWidth, 12.0f).withCentre ({ railX, capY });
  1819. theme::fillRoundRect (g, cap.translated (0.0f, 1.5f), radius::sm, juce::Colours::black.withAlpha (0.35f));
  1820. // same cap as the LookAndFeel's linear faders
  1821. // FL's fader colours (manual, Mixer › Level faders: "Grey (Default), Green (Selected), Orange (Armed for
  1822. // recording)"; details190if fl-fader-selected-green.png): LYNX's green LED colour and its warning orange
  1823. {
  1824. const auto armedCap = t > 0 && engine.isInsertArmed (t);
  1825. auto capColour = armedCap ? colour::warning : isSelected ? colour::ledOn : juce::Colour (0xffd4d7dd);
  1826. theme::fillRoundRect (g, cap, radius::sm, capActive ? (armedCap || isSelected ? capColour.brighter (0.25f) : juce::Colour (0xffffffff)) : capColour);
  1827. }
  1828. g.setColour ((dragging (Part::fader) ? colour::accent : colour::bg0).withAlpha (0.8f));
  1829. g.fillRect (cap.withSizeKeepingCentre (capWidth - 8.0f, 1.5f));
  1830. // a VCA member (round 177a): a tick where the level that plays sits (the fader times its VCAs)
  1831. if (t > 0 && ! song.vcas.empty())
  1832. if (const auto gain = mixerops::vcaGain (song, t); gain != 1.0f)
  1833. {
  1834. const auto playing = faderPosition (faderGain (volume) * gain);
  1835. const auto tickY = (float) fader.getBottom() - playing * (float) fader.getHeight();
  1836. g.setColour (colour::info);
  1837. g.fillRect (juce::Rectangle<float> (railX - 7.0f, tickY - 1.0f, 14.0f, 2.0f));
  1838. }
  1839. g.setColour (colour::textSecondary);
  1840. g.setFont (font (type::caption));
  1841. if (sp.dbReadout)
  1842. textcache::drawFittedText (g, faderToDb (volume) + " dB", juce::Rectangle<int> (x, area.getBottom() + 3, plateWidth, 14), juce::Justification::centred, 1, 0.7f);
  1843. // a hardware output target (REA round 156, optional): a small badge at the fader's top right
  1844. if (mixeroutput::isCustom (engine, t))
  1845. {
  1846. const auto text = mixeroutput::label (engine, t, true);
  1847. const auto badgeLeft = (float) meterArea (t).getRight() + 3.0f + (t == 0 ? (float) masterScaleWidth : 0.0f);
  1848. const auto badge = juce::Rectangle<float> (badgeLeft, (float) area.getY(), (float) (x + w - 6) - badgeLeft, 12.0f);
  1849. theme::fillRoundRect (g, badge, 3.0f, colour::bg0.withAlpha (0.85f));
  1850. g.setColour (text.endsWith ("?") ? colour::textDisabled : colour::info);
  1851. g.setFont (font (9.0f, true));
  1852. textcache::drawFittedText (g, text, badge.toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1853. }
  1854. }
  1855. // FL's route arrow at the strip's foot (round 190io, design190ia FM-32; FL manual › Routing Iconography): the
  1856. // selected track's downward arrow, a hollow up-arrow where it can send, lit where it sends, greyed where it would
  1857. // loop; the small "Send in use" arrow above it on a track others send into
  1858. if (const auto foot = arrowArea (t); needs (foot))
  1859. {
  1860. const auto state = routearrow::of (song, selected, t);
  1861. const auto c = foot.toFloat().getCentre();
  1862. const auto w = compactLayout ? 9.0f : 11.0f, h = compactLayout ? 7.0f : 8.0f;
  1863. const auto top = (float) foot.getY() + 5.0f;
  1864. juce::Path arrow;
  1865. if (state == routearrow::State::out)
  1866. arrow.addTriangle (c.x - w * 0.5f, top, c.x + w * 0.5f, top, c.x, top + h);
  1867. else
  1868. arrow.addTriangle (c.x - w * 0.5f, top + h, c.x + w * 0.5f, top + h, c.x, top);
  1869. const auto hot = hovered (Part::route);
  1870. switch (state)
  1871. {
  1872. case routearrow::State::out: g.setColour (colour::ledOn); g.fillPath (arrow); break;
  1873. case routearrow::State::routed: g.setColour (hot ? colour::accentHover : colour::accent); g.fillPath (arrow); break;
  1874. case routearrow::State::available:
  1875. g.setColour (hot ? colour::textPrimary : colour::textSecondary.withAlpha (0.75f));
  1876. g.strokePath (arrow, juce::PathStrokeType (1.0f, juce::PathStrokeType::mitered));
  1877. break;
  1878. case routearrow::State::blocked:
  1879. g.setColour (colour::textDisabled.withAlpha (0.45f));
  1880. g.strokePath (arrow, juce::PathStrokeType (1.0f, juce::PathStrokeType::mitered));
  1881. break;
  1882. case routearrow::State::none: break;
  1883. }
  1884. if (state != routearrow::State::none && routearrow::receives (song, t)) // "Send in use"
  1885. {
  1886. juce::Path small;
  1887. small.addTriangle (c.x - 3.0f, top - 1.5f, c.x + 3.0f, top - 1.5f, c.x, top - 4.5f);
  1888. g.setColour (colour::textSecondary);
  1889. g.fillPath (small);
  1890. }
  1891. }
  1892. // issue #154 part 2 (round 190io): the insert's effects under the band, while the view is on
  1893. if (const auto list = insertsArea (t); ! list.isEmpty() && needs (list))
  1894. paintStripInserts (g, t);
  1895. // round 186c's option: the selected insert's sends to deleted inserts, as a greyed dashed chip in its own (empty)
  1896. // route-switch place: the deleted insert's name (or how many); the insert menu's "Disconnected links" acts on them
  1897. if (t == selected && t > 0 && ! song.mixer[(std::size_t) t].lostSends.empty() && needs (routeArea (t)))
  1898. {
  1899. const auto& lost = song.mixer[(std::size_t) t].lostSends;
  1900. const auto r = routeArea (t).toFloat().reduced (0.5f);
  1901. juce::Path outline, dashed;
  1902. outline.addRoundedRectangle (r, radius::sm);
  1903. const float dashes[] = { 2.5f, 2.0f };
  1904. juce::PathStrokeType (1.0f).createDashedStroke (dashed, outline, dashes, 2);
  1905. g.setColour (colour::textDisabled);
  1906. g.fillPath (dashed);
  1907. g.setFont (font (10.0f));
  1908. textcache::drawFittedText (g, juce::String::fromUTF8 ("\xc3\x97 ") + (lost.size() == 1 ? juce::String::fromUTF8 (lost[0].to.c_str()) : juce::String ((int) lost.size())),
  1909. r.toNearestInt().reduced (2, 0), juce::Justification::centred, 1, 0.6f);
  1910. }
  1911. // routing lane: send switch from the selected insert to this one, and its level knob
  1912. if (selected > 0 && t != selected && selected < tracks && needs (routeArea (t).getUnion (sendArea (t))))
  1913. {
  1914. const auto r = routeArea (t).toFloat();
  1915. const auto on = song.routes (selected, t);
  1916. const auto possible = on || song.canRoute (selected, t);
  1917. const auto feedsSelected = t > 0 && song.routes (t, selected);
  1918. if (possible)
  1919. {
  1920. theme::fillRoundRect (g, r, radius::sm, on ? colour::accent : hovered (Part::route) ? colour::bg5 : colour::bg0);
  1921. if (hovered (Part::route))
  1922. {
  1923. g.setColour (on ? colour::accentHover : colour::textSecondary);
  1924. g.drawRoundedRectangle (r.reduced (0.5f), radius::sm, 1.0f);
  1925. }
  1926. g.setColour (on ? colour::onAccent : colour::textSecondary);
  1927. g.setFont (font (10.0f, on));
  1928. textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + (t == 0 ? juce::String ("M") : juce::String (t)), r.toNearestInt(),
  1929. juce::Justification::centred);
  1930. // the route's level knob (FL's route knob), on the routes to inserts and to Master
  1931. if (on)
  1932. drawKnob (g, sendArea (t).toFloat().withSizeKeepingCentre (compactLayout ? 16.0f : 22.0f, compactLayout ? 16.0f : 22.0f),
  1933. engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerSend, selected, t },
  1934. faderPosition (song.routeLevel (selected, t))),
  1935. false,
  1936. dragging (Part::send) ? colour::accent : colour::accentHover, hovered (Part::send) || dragging (Part::send));
  1937. // a pre-fader send (LYNX's switch, round 190aq) is marked beside its knob
  1938. if (on && t > 0 && song.sendPre (selected, t))
  1939. {
  1940. // (its whole text, ending at the knob's left edge: the strip's margin is narrower than "PRE")
  1941. const auto area = sendArea (t);
  1942. const auto mark = compactLayout ? juce::String ("P") : tr ("PRE");
  1943. g.setColour (colour::accentHover);
  1944. g.setFont (font (8.0f, true));
  1945. const auto width = juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), mark) + 2;
  1946. const auto knobLeft = area.getCentreX() - (compactLayout ? 8 : 11);
  1947. textcache::drawText (g, mark, juce::Rectangle<int> (knobLeft - width - 1, area.getY(), width, area.getHeight()),
  1948. juce::Justification::centredRight, false);
  1949. }
  1950. }
  1951. else if (feedsSelected) // this insert sends into the selected one
  1952. {
  1953. theme::fillRoundRect (g, r, radius::sm, colour::info.withAlpha (0.18f));
  1954. g.setColour (colour::info);
  1955. g.setFont (font (10.0f, true));
  1956. textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + juce::String (selected), r.toNearestInt(), juce::Justification::centred);
  1957. }
  1958. }
  1959. }
  1960. if (pass == dockOf (0))
  1961. {
  1962. for (int i = 0; i < (int) vcaXs.size(); ++i)
  1963. paintVcaStrip (g, i);
  1964. if (showLoudness && g.clipRegionIntersects (loudnessArea().expanded (3)))
  1965. {
  1966. paintLoudnessPanel (g);
  1967. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  1968. paintLoudnessValues (g);
  1969. }
  1970. }
  1971. paintDividers (pass);
  1972. }
  1973. paintRouting (g);
  1974. }
  1975. // Wires in the lane under the strips: from the selected insert to where it sends (accent), and from the
  1976. // inserts that feed it (blue). The Master output is drawn dimmer.
  1977. void MixerStrips::paintRouting (juce::Graphics& g)
  1978. {
  1979. using namespace theme;
  1980. const auto& song = engine.getSong();
  1981. const auto tracks = (int) song.mixer.size();
  1982. if (selected <= 0 || selected >= tracks)
  1983. return;
  1984. const auto top = (float) (laneTop() + switchHeight + sendKnobHeight + 3);
  1985. const auto bottom = top + (float) wiresHeight - 2.0f;
  1986. const auto centre = [this] (int t) { return (float) stripX (t) + (float) (stripWidthOf (t) - 4) * 0.5f; };
  1987. auto wire = [&] (int from, int to, juce::Colour c, float thickness) {
  1988. const auto x0 = centre (from), x1 = centre (to);
  1989. juce::Path p;
  1990. p.startNewSubPath (x0, top);
  1991. p.cubicTo (x0, bottom + 2.0f, x1, bottom + 2.0f, x1, top);
  1992. g.setColour (c);
  1993. g.strokePath (p, juce::PathStrokeType (thickness, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1994. g.fillEllipse (x1 - 2.5f, top - 2.5f, 5.0f, 5.0f);
  1995. };
  1996. const auto& from = song.mixer[(std::size_t) selected];
  1997. for (int t = 1; t < tracks; ++t)
  1998. if (t != selected && song.routes (t, selected))
  1999. wire (t, selected, colour::info.withAlpha (0.85f), 1.5f);
  2000. if (from.toMaster)
  2001. wire (selected, 0, colour::accent.withAlpha (0.4f), 1.0f);
  2002. for (const auto& send : from.sends)
  2003. if (send.target > 0 && send.target < tracks)
  2004. wire (selected, send.target, colour::accent.withAlpha (0.5f + 0.5f * juce::jlimit (0.0f, 1.0f, send.level)), 1.8f);
  2005. g.setColour (colour::accent);
  2006. g.fillEllipse (centre (selected) - 3.0f, top - 3.0f, 6.0f, 6.0f);
  2007. }
  2008. void MixerStrips::mouseDown (const juce::MouseEvent& e)
  2009. {
  2010. if (const auto i = vcaAt (e.x); i >= 0)
  2011. {
  2012. vcaMouseDown (e, i);
  2013. return;
  2014. }
  2015. if (showLoudness && loudnessArea().contains (e.getPosition())) // round 190am: Reset, or the panel's menu
  2016. {
  2017. if (flmods::popup (e.mods))
  2018. showLoudnessMenu();
  2019. else if (loudnessResetArea().contains (e.getPosition()))
  2020. resetLoudness();
  2021. return;
  2022. }
  2023. const auto t = trackAt (e.x);
  2024. if (t < 0)
  2025. return;
  2026. const auto part = partAt (t, e.getPosition());
  2027. headerDragTrack = -1;
  2028. headerDragged = false;
  2029. if (part == Part::inserts && insertsMouseDown (e, t)) // issue #154 part 2 (round 190io)
  2030. return;
  2031. if (part == Part::add && flmods::popup (e.mods))
  2032. {
  2033. // FL's "+" menu (round 166d [SHOT]): Add one / Add multiple...
  2034. juce::PopupMenu menu;
  2035. const auto count = (int) engine.getSong().mixer.size();
  2036. const auto room = mixerops::roomForInserts (engine.getSong()) > 0;
  2037. menu.addItem (tr ("Add one"), room, false, [this, count] {
  2038. engine.editSong ([count] (Song& s) { mixerops::insertTracks (s, juce::jmax (1, count), 1); });
  2039. revealed.insert (juce::jmax (1, count));
  2040. updateSize();
  2041. selectTrack (juce::jmax (1, count));
  2042. });
  2043. menu.addItem (tr ("Add multiple..."), room, false, [this, count] { askInsertMultiple (juce::jmax (1, count), true); });
  2044. // FL's third item (Tag -1, round 190fl): the number of inserts to have, the new ones at the end. Round 190gw: FL 2026
  2045. // shows it only on THIS "+" (the one after the last strip): AddMixerTracksMenuBeforePopup 0x12a87d0 sets the
  2046. // item's Visible (TQuickMenuItem.Visible's setter 0x840720) to "the menu was not opened from the toolbar's
  2047. // AddTrackAfterSelectedBtn" — LYNX has no such toolbar button, and FL's track / options menus never had the item
  2048. menu.addItem (tr ("Increase number of tracks to..."), room, false, [this] { askInsertCount(); });
  2049. // FL's "Add from state" (REA round 167q: AddMixerTracksMenu, FUN_012a87d0 / FUN_012a83b0)
  2050. juce::PopupMenu fromState;
  2051. for (const auto& f : mixerpresets::all())
  2052. fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, count, f] {
  2053. if (const auto added = mixerpresets::insertTrack (engine, juce::jmax (1, count), f); added > 0)
  2054. {
  2055. revealed.insert (added);
  2056. updateSize();
  2057. selectTrack (added);
  2058. }
  2059. });
  2060. menu.addSubMenu (tr ("Add from state"), fromState, room && fromState.getNumItems() > 0);
  2061. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  2062. return;
  2063. }
  2064. if (part == Part::add)
  2065. {
  2066. if (showUsedOnly) // the first unused insert (hidden) comes back before a new one is added
  2067. if (const auto free = engine.getSong().nextFreeInsert(); free > 0 && isHidden (free))
  2068. {
  2069. revealed.insert (free);
  2070. updateSize();
  2071. selectTrack (free);
  2072. return;
  2073. }
  2074. const auto added = (int) engine.getSong().mixer.size();
  2075. engine.editSong ([] (Song& s) {
  2076. if (s.mixer.empty())
  2077. s.mixer = Song::defaultMixer (0);
  2078. if ((int) s.mixer.size() >= maxMixerTracks)
  2079. return;
  2080. auto& track = s.mixer.emplace_back();
  2081. track.name = "Insert " + std::to_string (s.mixer.size() - 1);
  2082. });
  2083. if (added < (int) engine.getSong().mixer.size())
  2084. {
  2085. revealed.insert (added); // shown even while unused
  2086. updateSize();
  2087. selectTrack (added);
  2088. }
  2089. return;
  2090. }
  2091. if ((part == Part::fold || part == Part::tab) && ! flmods::popup (e.mods))
  2092. {
  2093. // round 177a: fold / unfold the group; Alt: every group (to the state this one takes)
  2094. const auto all = e.mods.isAltDown();
  2095. engine.editSong ([t, all] (Song& s) {
  2096. const auto folded = mixerops::toggleFold (s, t);
  2097. if (all)
  2098. mixerops::foldAll (s, folded);
  2099. });
  2100. updateSize();
  2101. repaint();
  2102. return;
  2103. }
  2104. if (part == Part::arm)
  2105. {
  2106. if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a); the input box keeps the input menu
  2107. mixerinput::chooseRecordTo (engine, t);
  2108. else
  2109. mixerinput::toggleArm (engine, t, this);
  2110. repaint();
  2111. return;
  2112. }
  2113. if (part == Part::input)
  2114. {
  2115. mixerinput::showMenu (engine, t, this);
  2116. return;
  2117. }
  2118. if (part == Part::meter && ! flmods::popup (e.mods)) // clears the clip latch and the peak hold, and selects (as FL)
  2119. {
  2120. for (int ch = 0; ch < 2; ++ch)
  2121. if (const auto i = (std::size_t) t * 2 + (std::size_t) ch; i < levels.size())
  2122. levels[i].resetClip();
  2123. repaint (meterArea (t).expanded (2));
  2124. }
  2125. if (part == Part::route && flmods::popup (e.mods))
  2126. {
  2127. showSendMenu (t);
  2128. return;
  2129. }
  2130. if (part == Part::send)
  2131. {
  2132. const auto from = selected;
  2133. if (flmods::popup (e.mods))
  2134. {
  2135. juce::PopupMenu menu;
  2136. const auto spec = specFor (Part::send, t);
  2137. menu.addSectionHeader (spec.name + ": " + spec.text (valueOf (Part::send, t)));
  2138. ui::addValueItems (menu, *this, &engine, spec, valueOf (Part::send, t), [this, t] (double v) { setValue (Part::send, t, v); });
  2139. menu.addSeparator();
  2140. addPreFaderItem (menu, from, t);
  2141. menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
  2142. [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
  2143. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  2144. return;
  2145. }
  2146. if (ui::isResetClick (e))
  2147. {
  2148. setValue (Part::send, t, unityFader); // 0 dB
  2149. showTip (Part::send, t, true);
  2150. return;
  2151. }
  2152. dragPart = Part::send;
  2153. dragTrack = t;
  2154. drag.begin (e, valueOf (Part::send, t));
  2155. showTip (Part::send, t, false);
  2156. return;
  2157. }
  2158. if (part == Part::mute && (flmods::popup (e.mods) || flmods::ctrl (e.mods))) // solo on the same LED
  2159. {
  2160. soloExclusive (t);
  2161. return;
  2162. }
  2163. if (part == Part::route)
  2164. {
  2165. // the selection is the send source: don't change it. FL (round 170b, REA FUN_012aa110): the arrow acts on every
  2166. // selected track; Ctrl = route to this track only, Shift = sidechain, Ctrl+Shift = sidechain only.
  2167. const auto from = selected;
  2168. const auto sources = selection;
  2169. using K = mixerops::RouteKind;
  2170. if (flmods::ctrl (e.mods) || e.mods.isShiftDown())
  2171. {
  2172. routeSelection (t, flmods::ctrl (e.mods) ? (e.mods.isShiftDown() ? K::sidechainOnly : K::routeOnly) : K::sidechain);
  2173. return;
  2174. }
  2175. const auto on = engine.getSong().routes (from, t);
  2176. engine.editSong ([sources, t, on] (Song& s) { mixerops::switchSelectedRoute (s, sources, t, ! on); });
  2177. if (! on && engine.getSong().routes (from, t)) // just enabled (at 0 dB): dragging adjusts the level, like the route knob
  2178. {
  2179. dragPart = Part::send;
  2180. dragTrack = t;
  2181. drag.begin (e, unityFader);
  2182. }
  2183. return;
  2184. }
  2185. if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && flmods::ctrl (e.mods) && t > 0)
  2186. {
  2187. // FL (round 170b, REA FUN_012c5800 / FUN_012c5f60): Ctrl+click (and drag across the strips) selects the tracks
  2188. // from here to the mouse, alone; Ctrl+Shift adds them to the selection, or removes them when the click starts
  2189. // on a selected track
  2190. selectAnchor = t;
  2191. selectAdding = ! e.mods.isShiftDown() || ! std::binary_search (selection.begin(), selection.end(), t);
  2192. selectBase.clear();
  2193. if (e.mods.isShiftDown())
  2194. selectBase = selection;
  2195. // LYNX extra (issue #163, owner 2026-11-14; FL has no Ctrl+click toggle): with Ctrl alone the press waits; a drag
  2196. // onto another strip does FL's range from here, a release on this strip adds / removes it
  2197. ctrlClickPending = ! e.mods.isShiftDown();
  2198. if (! ctrlClickPending)
  2199. dragSelectTo (t);
  2200. return;
  2201. }
  2202. if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && e.mods.isShiftDown() && t > 0)
  2203. {
  2204. auto s = selection;
  2205. {
  2206. s.clear();
  2207. for (int i = juce::jmin (selected, t); i <= juce::jmax (selected, t); ++i)
  2208. s.push_back (i);
  2209. }
  2210. setSelection (s, std::find (s.begin(), s.end(), t) != s.end() ? t : s.front());
  2211. return;
  2212. }
  2213. // a plain click on a track outside the selection selects only it; inside, the group stays
  2214. if (! std::binary_search (selection.begin(), selection.end(), t))
  2215. setSelection ({ t }, t);
  2216. else if (selected != t)
  2217. setSelection (selection, t);
  2218. if (part == Part::pan || part == Part::fader || part == Part::stereo)
  2219. {
  2220. if (flmods::popup (e.mods))
  2221. {
  2222. ui::showValueMenu (*this, part == Part::stereo ? nullptr : &engine, specFor (part, t), valueOf (part, t),
  2223. [this, part, t] (double v) { setValue (part, t, v); });
  2224. return;
  2225. }
  2226. if (ui::isResetClick (e))
  2227. {
  2228. setValue (part, t, specFor (part, t).defaultValue);
  2229. showTip (part, t, true);
  2230. return;
  2231. }
  2232. }
  2233. if (flmods::popup (e.mods))
  2234. {
  2235. showMenu (t);
  2236. return;
  2237. }
  2238. const auto& track = engine.getSong().mixer[(std::size_t) t];
  2239. switch (part)
  2240. {
  2241. case Part::mute:
  2242. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].muted = ! s.mixer[(std::size_t) t].muted; });
  2243. return;
  2244. case Part::solo:
  2245. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].solo = ! s.mixer[(std::size_t) t].solo; });
  2246. return;
  2247. case Part::header:
  2248. if (t > 0)
  2249. headerDragTrack = t; // dragging sideways reorders
  2250. return;
  2251. case Part::stereo:
  2252. dragPart = part;
  2253. dragTrack = t;
  2254. dragStartValue = track.stereo;
  2255. drag.begin (e, dragStartValue);
  2256. groupStart.clear();
  2257. showTip (part, t, false);
  2258. return;
  2259. case Part::pan:
  2260. case Part::fader:
  2261. dragPart = part;
  2262. dragTrack = t;
  2263. dragStartValue = part == Part::pan ? track.pan : track.volume;
  2264. groupStart.clear();
  2265. groupGrab = dragStartValue;
  2266. if (selection.size() > 1) // the selected strips follow, keeping their offsets
  2267. for (auto s : selection)
  2268. if (s != t && s < (int) engine.getSong().mixer.size())
  2269. groupStart.push_back ({ s, part == Part::pan ? engine.getSong().mixer[(std::size_t) s].pan
  2270. : engine.getSong().mixer[(std::size_t) s].volume });
  2271. if (part == Part::fader && ! flmods::ctrl (e.mods)) // a press on the rail steps the fader towards the mouse
  2272. {
  2273. const auto area = faderRail (t);
  2274. const auto capY = area.getBottom() - track.volume * (float) area.getHeight();
  2275. if (std::abs ((float) e.y - capY) > 9.0f)
  2276. {
  2277. pressRail (t, e.y);
  2278. showTip (part, t, false);
  2279. return;
  2280. }
  2281. }
  2282. drag.begin (e, dragStartValue);
  2283. showTip (part, t, false);
  2284. return;
  2285. case Part::arm:
  2286. case Part::route:
  2287. case Part::send:
  2288. case Part::meter:
  2289. case Part::body:
  2290. case Part::none:
  2291. case Part::add:
  2292. return;
  2293. }
  2294. }
  2295. void MixerStrips::dragSelectTo (int t)
  2296. {
  2297. const auto count = (int) engine.getSong().mixer.size();
  2298. if (selectAnchor < 1 || count < 2)
  2299. return;
  2300. t = juce::jlimit (1, count - 1, t);
  2301. std::set<int> s (selectBase.begin(), selectBase.end());
  2302. for (int i = juce::jmin (selectAnchor, t); i <= juce::jmax (selectAnchor, t); ++i)
  2303. {
  2304. if (isHidden (i) && i != t && i != selectAnchor)
  2305. continue;
  2306. if (selectAdding)
  2307. s.insert (i);
  2308. else
  2309. s.erase (i);
  2310. }
  2311. if (s.empty())
  2312. s.insert (t);
  2313. // the track under the mouse becomes the current one (FL); when removing, a track that stays selected
  2314. auto primary = t;
  2315. if (! s.count (primary))
  2316. primary = s.count (selected) ? selected : *s.rbegin();
  2317. setSelection ({ s.begin(), s.end() }, primary);
  2318. }
  2319. void MixerStrips::pressRail (int strip, int mouseY)
  2320. {
  2321. railStrip = strip;
  2322. railMouseY = mouseY;
  2323. railPressMs = juce::Time::getMillisecondCounterHiRes();
  2324. stepRailOnce();
  2325. railSteps = 1;
  2326. railRepeat.startTimer (16); // (a poll: the steps themselves follow the time since the press)
  2327. }
  2328. float MixerStrips::railTarget (int strip) const
  2329. {
  2330. const auto rail = faderRail (strip);
  2331. return juce::jlimit (0.0f, 1.0f, (float) (rail.getBottom() - railMouseY) / (float) rail.getHeight());
  2332. }
  2333. void MixerStrips::stepHeldRail()
  2334. {
  2335. if (! railRepeat.isTimerRunning()) // (a direct call, as the offscreen check makes: one step)
  2336. {
  2337. stepRailOnce();
  2338. return;
  2339. }
  2340. // the repeat stops as soon as the button is up, even before the release reaches us
  2341. if (! juce::ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  2342. {
  2343. railRepeat.stopTimer();
  2344. return;
  2345. }
  2346. const auto due = faderRailStepsForHold ((int) (juce::Time::getMillisecondCounterHiRes() - railPressMs));
  2347. for (int guard = 0; railSteps < due && guard < 64; ++guard, ++railSteps)
  2348. stepRailOnce();
  2349. }
  2350. void MixerStrips::stepRailOnce()
  2351. {
  2352. const auto& song = engine.getSong();
  2353. if (railStrip <= vcaStrip (0))
  2354. {
  2355. const auto i = -2 - railStrip;
  2356. if (i < (int) song.vcas.size())
  2357. {
  2358. setVcaLevel (i, faderRailStepTowards (song.vcas[(std::size_t) i].level, railTarget (railStrip)));
  2359. ui::showValueTip (*this, faderRail (railStrip), vcaSpec (i).text (vcaShownLevel (i)));
  2360. }
  2361. }
  2362. else if (railStrip >= 0 && railStrip < (int) song.mixer.size())
  2363. {
  2364. setValue (Part::fader, railStrip, faderRailStepTowards (song.mixer[(std::size_t) railStrip].volume, railTarget (railStrip)));
  2365. showTip (Part::fader, railStrip, false);
  2366. }
  2367. }
  2368. void MixerStrips::mouseDrag (const juce::MouseEvent& e)
  2369. {
  2370. if (insertsMouseDrag (e)) // issue #154 part 2: an effect dragged in / between the strips' lists
  2371. return;
  2372. if (railStrip != railNone) // the cap goes on towards where the mouse is now
  2373. {
  2374. railMouseY = e.y;
  2375. return;
  2376. }
  2377. if (selectAnchor > 0)
  2378. {
  2379. if (const auto t = trackAt (juce::jlimit (0, getWidth() - 1, e.x)); t >= 0 && ! (ctrlClickPending && t == selectAnchor))
  2380. {
  2381. ctrlClickPending = false;
  2382. dragSelectTo (t);
  2383. }
  2384. return;
  2385. }
  2386. if (headerDragTrack > 0)
  2387. {
  2388. if (! headerDragged && std::abs (e.getDistanceFromDragStartX()) < 6)
  2389. return;
  2390. headerDragged = true;
  2391. setMouseCursor (juce::MouseCursor::LeftRightResizeCursor);
  2392. const auto count = (int) engine.getSong().mixer.size();
  2393. const auto target = trackAt (e.x);
  2394. if (target < 1 || target >= count)
  2395. return;
  2396. for (int guard = 0; guard < count && selected != target; ++guard)
  2397. if (! moveSelected (target < selected ? -1 : 1))
  2398. break;
  2399. headerDragTrack = selected;
  2400. repaint();
  2401. return;
  2402. }
  2403. if (dragVca >= 0)
  2404. {
  2405. setVcaLevel (dragVca, drag.update (e, vcaSpec (dragVca)));
  2406. ui::showValueTip (*this, faderRail (vcaStrip (dragVca)), vcaSpec (dragVca).text (vcaShownLevel (dragVca)));
  2407. return;
  2408. }
  2409. if (dragPart == Part::none)
  2410. return;
  2411. const auto t = dragTrack;
  2412. setValue (dragPart, t, drag.update (e, specFor (dragPart, t)));
  2413. showTip (dragPart, t, false);
  2414. }
  2415. ui::ValueSpec MixerStrips::specFor (Part part, int t) const
  2416. {
  2417. const auto& song = engine.getSong();
  2418. const auto nameOf = [&song] (int track) {
  2419. return track >= 0 && track < (int) song.mixer.size() ? juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) : juce::String();
  2420. };
  2421. const auto name = nameOf (t);
  2422. if (part == Part::pan)
  2423. {
  2424. auto spec = ui::panSpec (name + " - " + tr ("Pan"));
  2425. spec.pixelsForRange = 150.0;
  2426. spec.target = AutomationTarget { AutomationTargetKind::mixerPan, t };
  2427. return spec;
  2428. }
  2429. if (part == Part::stereo)
  2430. return stereoSpec (name + " - " + tr ("Stereo separation"));
  2431. if (part == Part::send)
  2432. {
  2433. auto spec = sendSpec (nameOf (selected) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + name + " - "
  2434. + (t == 0 ? tr ("Level to Master") : engine.getSong().sendPre (selected, t) ? tr ("Send level (pre-fader)") : tr ("Send level")));
  2435. spec.target = AutomationTarget { AutomationTargetKind::mixerSend, selected, t }; // automatable (issue #12)
  2436. return spec;
  2437. }
  2438. auto spec = ui::faderSpec (name + " - " + tr ("Volume"), unityFader);
  2439. spec.pixelsForRange = juce::jmax (60, faderRail (juce::jmax (0, t)).getHeight());
  2440. spec.target = AutomationTarget { AutomationTargetKind::mixerVolume, t };
  2441. return spec;
  2442. }
  2443. double MixerStrips::valueOf (Part part, int t) const
  2444. {
  2445. const auto& song = engine.getSong();
  2446. const auto& track = song.mixer[(std::size_t) t];
  2447. if (part == Part::send)
  2448. {
  2449. return faderPosition (song.routeLevel (selected, t));
  2450. }
  2451. return part == Part::pan ? track.pan : part == Part::stereo ? track.stereo : track.volume;
  2452. }
  2453. void MixerStrips::setValue (Part part, int t, double value)
  2454. {
  2455. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  2456. return;
  2457. if (part == Part::send)
  2458. {
  2459. const auto from = selected;
  2460. engine.editSong ([from, t, v = faderGain ((float) value)] (Song& s) { s.setRouteLevel (from, t, v); });
  2461. return;
  2462. }
  2463. if (part == Part::stereo)
  2464. {
  2465. engine.editLevels ([t, v = (float) value] (Song& s) { s.mixer[(std::size_t) t].stereo = v; });
  2466. return;
  2467. }
  2468. // during a drag of a selected strip, the other selected strips move by the same amount
  2469. const auto delta = (float) value - groupGrab;
  2470. const auto group = dragTrack == t && dragPart == part ? groupStart : std::vector<std::pair<int, float>> {};
  2471. if (part == Part::pan)
  2472. engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
  2473. s.mixer[(std::size_t) t].pan = v;
  2474. for (auto [other, start] : group)
  2475. if (other < (int) s.mixer.size())
  2476. s.mixer[(std::size_t) other].pan = juce::jlimit (-1.0f, 1.0f, start + delta);
  2477. });
  2478. else if (part == Part::fader)
  2479. engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
  2480. s.mixer[(std::size_t) t].volume = v;
  2481. for (auto [other, start] : group)
  2482. if (other < (int) s.mixer.size())
  2483. s.mixer[(std::size_t) other].volume = juce::jlimit (0.0f, 1.0f, start + delta);
  2484. });
  2485. }
  2486. void MixerStrips::setSelection (std::vector<int> tracks, int primary)
  2487. {
  2488. const auto count = (int) engine.getSong().mixer.size();
  2489. tracks.erase (std::remove_if (tracks.begin(), tracks.end(), [count] (int t) { return t < 0 || t >= count; }), tracks.end());
  2490. primary = juce::jlimit (0, juce::jmax (0, count - 1), primary);
  2491. tracks.push_back (primary);
  2492. std::sort (tracks.begin(), tracks.end());
  2493. tracks.erase (std::unique (tracks.begin(), tracks.end()), tracks.end());
  2494. selection = tracks;
  2495. const auto changed = primary != selected;
  2496. selected = primary;
  2497. keepSelectionShown();
  2498. repaint();
  2499. if (changed && onSelectionChanged)
  2500. onSelectionChanged (selected);
  2501. }
  2502. bool MixerStrips::moveSelected (int delta)
  2503. {
  2504. auto moved = selection;
  2505. bool ok = false;
  2506. engine.editSongStructural ([&] (Song& s) { ok = mixerops::moveTracks (s, moved, delta); });
  2507. if (ok)
  2508. setSelection (moved, juce::jlimit (1, (int) engine.getSong().mixer.size() - 1, selected + (delta < 0 ? -1 : 1)));
  2509. return ok;
  2510. }
  2511. // FL's "Delete" on the selected mixer tracks (round 186c; REA FUN_012a5b60, FL 2026 checked by hand): an error while
  2512. // audio is being recorded; "Delete tracks|This will |delete| %d selected mixer track(s). Are you sure?" (Yes / No and
  2513. // "Remember my choice": a remembered Yes skips it, No is never remembered; Settings › General › Manage messages shows
  2514. // it again); then, when a Playlist audio / instrument track is linked to one of them, "Playlist tracks" with "Delete
  2515. // tracks and channels" / "Unlink tracks and channels" / "Cancel" (nothing remembered). One undo step.
  2516. void MixerStrips::deleteTracks (std::vector<int> tracks)
  2517. {
  2518. const auto count = (int) engine.getSong().mixer.size();
  2519. tracks.erase (std::remove_if (tracks.begin(), tracks.end(), [count] (int t) { return t < 1 || t >= count; }), tracks.end());
  2520. if (tracks.empty())
  2521. return;
  2522. if (engine.isRecording() && ! engine.getArmedInserts().empty())
  2523. {
  2524. showFlMessage ({ tr ("Error"), tr ("It isn't possible to delete mixer tracks during audio recording."), { tr ("OK") }, false }, nullptr);
  2525. return;
  2526. }
  2527. juce::Component::SafePointer<MixerStrips> safe (this);
  2528. auto run = [safe, tracks] (mixerops::LinkedPlaylistTracks linked) {
  2529. if (safe == nullptr)
  2530. return;
  2531. safe->engine.editSongStructural ([&tracks, linked] (Song& s) { mixerops::deleteTracks (s, tracks, linked, MixerStrips::keepLostLinks); });
  2532. const auto first = juce::jlimit (0, (int) safe->engine.getSong().mixer.size() - 1, *std::min_element (tracks.begin(), tracks.end()));
  2533. safe->setSelection ({ first }, first);
  2534. };
  2535. auto confirmed = [safe, tracks, run] {
  2536. if (safe == nullptr)
  2537. return;
  2538. if (mixerops::playlistTracksLinkedTo (safe->engine.getSong(), tracks).empty())
  2539. {
  2540. run (mixerops::LinkedPlaylistTracks::unlink);
  2541. return;
  2542. }
  2543. showFlMessage ({ tr ("Playlist tracks"),
  2544. tr ("One or more mixer tracks that will be deleted are connected to instrument/audio tracks.") + "\n"
  2545. + tr ("Do you want to unlink the tracks and channels or delete them?"),
  2546. { tr ("Delete tracks and channels"), tr ("Unlink tracks and channels"), tr ("Cancel") }, false },
  2547. [run] (int button, bool) {
  2548. if (button == 1)
  2549. run (mixerops::LinkedPlaylistTracks::deleteToo);
  2550. else if (button == 2)
  2551. run (mixerops::LinkedPlaylistTracks::unlink);
  2552. });
  2553. };
  2554. if (! messages::shown ("DeleteMixerTrack"))
  2555. {
  2556. confirmed();
  2557. return;
  2558. }
  2559. // (FL marks "delete" in its accent colour: the |bars| of its own string)
  2560. showFlMessage ({ tr ("Delete tracks"), tr ("This will |delete| {0} selected mixer track(s). Are you sure?", { juce::String ((int) tracks.size()) }),
  2561. { tr ("Yes"), tr ("No") }, true },
  2562. [confirmed] (int button, bool remember) {
  2563. if (button != 1)
  2564. return;
  2565. if (remember)
  2566. messages::setShown ("DeleteMixerTrack", false);
  2567. confirmed();
  2568. });
  2569. }
  2570. void MixerStrips::linkSelectedChannels (bool startingHere)
  2571. {
  2572. const auto channels = engine.getSelectedChannels();
  2573. engine.editSong ([channels, t = selected, startingHere] (Song& s) { mixerops::linkChannels (s, channels, t, startingHere); });
  2574. }
  2575. void MixerStrips::selectLinkedChannels()
  2576. {
  2577. const auto channels = mixerops::channelsOn (engine.getSong(), selected);
  2578. if (! channels.empty())
  2579. engine.setChannelSelection (channels, channels.front());
  2580. }
  2581. void MixerStrips::soloExclusive (int t)
  2582. {
  2583. if (t <= 0)
  2584. return;
  2585. // solo only this track; again on the only soloed track clears the solo
  2586. engine.editSong ([t] (Song& s) {
  2587. const auto alone = s.mixer[(std::size_t) t].solo
  2588. && std::none_of (s.mixer.begin() + 1, s.mixer.end(), [&] (const MixerTrack& m) { return &m != &s.mixer[(std::size_t) t] && m.solo; });
  2589. for (std::size_t i = 1; i < s.mixer.size(); ++i)
  2590. s.mixer[i].solo = ! alone && (int) i == t;
  2591. });
  2592. }
  2593. void MixerStrips::routeSelection (int t, mixerops::RouteKind kind)
  2594. {
  2595. using K = mixerops::RouteKind;
  2596. int linked = 0;
  2597. engine.editSong ([sources = selection, t, kind, &linked] (Song& s) {
  2598. mixerops::routeSelectedTo (s, sources, t, kind);
  2599. if (t >= 0 && t < (int) s.mixer.size())
  2600. for (const auto& fx : s.mixer[(std::size_t) t].effects)
  2601. linked += std::find (sources.begin(), sources.end(), fx.sidechain) != sources.end() ? 1 : 0;
  2602. });
  2603. if ((kind == K::sidechain || kind == K::sidechainOnly) && t > 0 && linked == 0)
  2604. // (round 170h: in the hint bar, not a box — FL says nothing here; adding the compressor links it)
  2605. ui::postHint ({ tr ("Sidechain") + ": " + tr ("The link was made; add a compressor to this insert to use it."), {} }, 6000);
  2606. }
  2607. // LYNX's pre-fader switch of a send (round 190aq; FL's sends are post-fader, the default): a ticked item in the send
  2608. // knob's and the route arrow's menus. The route to Master has none.
  2609. void MixerStrips::addPreFaderItem (juce::PopupMenu& menu, int from, int t)
  2610. {
  2611. const auto& song = engine.getSong();
  2612. if (t <= 0 || from <= 0 || ! song.routes (from, t))
  2613. return;
  2614. const auto pre = song.sendPre (from, t);
  2615. menu.addItem (tr ("Pre-fader send (not moved by this track's fader)"), true, pre,
  2616. [this, from, t, pre] { engine.editSong ([from, t, pre] (Song& s) { s.setSendPre (from, t, ! pre); }); });
  2617. }
  2618. void MixerStrips::showSendMenu (int t)
  2619. {
  2620. if (selected <= 0 || selected == t)
  2621. return;
  2622. buildSendMenu (t).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  2623. }
  2624. juce::PopupMenu MixerStrips::buildSendMenu (int t)
  2625. {
  2626. const auto& song = engine.getSong();
  2627. const auto from = selected;
  2628. const auto fromName = juce::String::fromUTF8 (song.mixer[(std::size_t) from].name.c_str());
  2629. juce::PopupMenu menu;
  2630. const auto sources = (int) std::count_if (selection.begin(), selection.end(), [t] (int x) { return x > 0 && x != t; });
  2631. menu.addSectionHeader ((sources > 1 ? tr ("{0} selected tracks", { juce::String (sources) }) : fromName)
  2632. + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()));
  2633. // FL's route arrow menu (round 168s, issue #32 [SHOT] r168s c_f10): route / route only / sidechain / sidechain only
  2634. const auto on = song.routes (from, t);
  2635. const auto can = on || song.canRoute (from, t);
  2636. using K = mixerops::RouteKind;
  2637. // FL (round 170b, REA FUN_012aca70): every item acts on all the selected tracks, not only the current one
  2638. auto route = [this, t] (K kind) { routeSelection (t, kind); };
  2639. menu.addItem (tr ("Route to this track"), can && ! on, false, [route] { route (K::route); });
  2640. menu.addItem (tr ("Route to this track only"), can, false, [route] { route (K::routeOnly); });
  2641. menu.addSeparator();
  2642. menu.addItem (tr ("Sidechain to this track"), t > 0 && can, false, [route] { route (K::sidechain); });
  2643. menu.addItem (tr ("Sidechain to this track only"), t > 0 && can, false, [route] { route (K::sidechainOnly); });
  2644. if (on)
  2645. {
  2646. menu.addSeparator();
  2647. addPreFaderItem (menu, from, t);
  2648. menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
  2649. [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
  2650. }
  2651. return menu;
  2652. }
  2653. void MixerStrips::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
  2654. {
  2655. if (const auto i = vcaAt (e.x); i >= 0 && ! ui::wheelScrolling() && vcaPartAt (i, e.getPosition()) == Part::fader)
  2656. {
  2657. if (const auto v = ui::wheelValue (engine.getSong().vcas[(std::size_t) i].level, e, wheel, vcaSpec (i)))
  2658. {
  2659. setVcaLevel (i, *v);
  2660. ui::flashValueTip (*this, faderRail (vcaStrip (i)), vcaSpec (i).text (*v));
  2661. }
  2662. return;
  2663. }
  2664. if (! e.mods.isShiftDown() && insertsWheel (e, wheel.deltaY)) // issue #154 part 2: a long effects list scrolls
  2665. return;
  2666. const auto t = trackAt (e.x);
  2667. if (t > 0 && t < (int) engine.getSong().mixer.size() && e.mods.isShiftDown())
  2668. if (const auto part = partAt (t, e.getPosition()); part == Part::body || part == Part::header)
  2669. {
  2670. if (! std::binary_search (selection.begin(), selection.end(), t))
  2671. setSelection ({ t }, t);
  2672. moveSelected ((wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX) > 0.0f ? -1 : 1);
  2673. return;
  2674. }
  2675. // (a spin that is scrolling the strips goes on scrolling over the faders and knobs, round 169c)
  2676. if (t >= 0 && t < (int) engine.getSong().mixer.size() && ! ui::wheelScrolling())
  2677. if (const auto part = partAt (t, e.getPosition()); part == Part::pan || part == Part::fader || part == Part::stereo || part == Part::send)
  2678. {
  2679. if (const auto v = ui::wheelValue (valueOf (part, t), e, wheel, specFor (part, t)))
  2680. {
  2681. setValue (part, t, *v);
  2682. showTip (part, t, true);
  2683. }
  2684. return;
  2685. }
  2686. ui::noteWheelScroll(); // the wheel scrolls the strips (the viewport)
  2687. juce::Component::mouseWheelMove (e, wheel);
  2688. }
  2689. ui::Hint MixerStrips::hintAt (juce::Point<int> p)
  2690. {
  2691. if (dragVca >= 0)
  2692. return vcaHint (dragVca, p);
  2693. if (const auto i = vcaAt (p.x); i >= 0 && dragPart == Part::none)
  2694. return vcaHint (i, p);
  2695. if (showLoudness && dragPart == Part::none && loudnessArea().contains (p))
  2696. {
  2697. ui::Hint h;
  2698. h.hasMenu = true;
  2699. if (loudnessResetArea().contains (p))
  2700. h.text = tr ("Start the loudness measurement again");
  2701. else
  2702. {
  2703. h.text = tr ("Loudness of the Master: S = short-term (3 s), I = integrated since the last reset (LUFS), TP = true peak (dBTP)");
  2704. h.value = "S " + juce::String (formatLoudness (loudnessShown.shortTerm)) + " I " + juce::String (formatLoudness (loudnessShown.integrated))
  2705. + " TP " + juce::String (formatLoudness (loudnessShown.truePeak));
  2706. }
  2707. return h;
  2708. }
  2709. const auto active = dragPart == Part::pan || dragPart == Part::fader || dragPart == Part::stereo || dragPart == Part::send;
  2710. const auto t = active ? dragTrack : trackAt (p.x);
  2711. const auto& song = engine.getSong();
  2712. ui::Hint h;
  2713. if (t < 0 || t >= (int) song.mixer.size())
  2714. {
  2715. if (t == (int) song.mixer.size())
  2716. h.text = tr ("Add a mixer insert");
  2717. return h;
  2718. }
  2719. const auto part = active ? dragPart : partAt (t, p);
  2720. const auto name = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  2721. const auto gesture = ui::valueGestures();
  2722. // the channels that play into this insert (FL shows them by the insert; LYNX in the hint)
  2723. auto feeds = [&song, t, tracks = (int) song.mixer.size()] {
  2724. juce::StringArray names;
  2725. for (const auto& c : song.channels)
  2726. if (juce::jlimit (0, tracks - 1, c.mixerTrack) == t)
  2727. names.add (juce::String::fromUTF8 (c.name.c_str()));
  2728. if (names.isEmpty())
  2729. return juce::String();
  2730. const auto shown = names.size() > 6 ? names[0] + ", " + names[1] + ", " + names[2] + " +" + juce::String (names.size() - 3)
  2731. : names.joinIntoString (", ");
  2732. return " " + tr ("Channels: {0}", { shown });
  2733. };
  2734. // FL's "Track latency compensation" label (REA round 165f-mixer): the manual latency and the bypass, when set
  2735. auto latency = [&song, t] {
  2736. const auto& track = song.mixer[(std::size_t) t];
  2737. juce::String text;
  2738. if (track.latencyMs != 0.0f)
  2739. text << " " << tr ("Track latency: {0}", { (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms" });
  2740. if (track.latencyBypass == LatencyBypass::always)
  2741. text << " " << tr ("Bypass track latency compensation") << ": " << tr ("Always");
  2742. else if (track.latencyBypass == LatencyBypass::whenRecordingOrStopped)
  2743. text << " " << tr ("Bypass track latency compensation") << ": " << tr ("When recording or not playing");
  2744. return text;
  2745. };
  2746. switch (part)
  2747. {
  2748. case Part::fader:
  2749. if (const auto note = vcaNote (t); note.isNotEmpty())
  2750. {
  2751. h = ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2752. h.text << " " << note;
  2753. return h;
  2754. }
  2755. return ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2756. case Part::pan:
  2757. case Part::stereo:
  2758. case Part::send:
  2759. return ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2760. case Part::mute: h.text = name + " - " + tr ("Click: mute. Right-click or Ctrl+click: solo"); break;
  2761. case Part::arm: h.text = name + " - " + mixerinput::armHint (engine, t); h.hasMenu = true; break;
  2762. case Part::input: h.text = name + " - " + tr ("Input level of this insert's audio input [LMB] choose the input"); h.hasMenu = true; break;
  2763. case Part::solo: h.text = name + " - " + tr ("Solo"); break;
  2764. case Part::meter: h.text = name + " - " + tr ("Peak meter (left/right) with peak hold [LMB] selects the track and clears the clip light"); break;
  2765. case Part::route: h.text = name + " - " + tr ("Route the selected inserts to this one (drag after enabling: level). Ctrl+click: this track only, Shift: sidechain, Ctrl+Shift: sidechain only, right-click: menu"); h.hasMenu = true; break;
  2766. case Part::add: h.text = tr ("Add a mixer insert"); break;
  2767. case Part::inserts: // issue #154 part 2 (round 190io); FL's Extra large list has no dots (round 190jd)
  2768. h.text = name + " - " + (flInsertList() ? tr ("Insert effects: [LMB] opens one drag: reorder or onto another strip, [Ctrl] copies [RMB] slot menu [Wheel] scrolls") : tr ("Insert effects: [LMB] opens one [LMB] on its dot: bypass drag: reorder or onto another strip, [Ctrl] copies [RMB] slot menu [Wheel] scrolls"));
  2769. h.hasMenu = true;
  2770. break;
  2771. case Part::fold:
  2772. h.text = name + " - " + (mixerops::isFolded (song, t) ? tr ("Unfold this group [Alt]+[LMB] all groups")
  2773. : tr ("Fold this group to its bus strip, or to a slim tab [Alt]+[LMB] all groups"));
  2774. break;
  2775. case Part::tab:
  2776. h.text = tr ("Folded group: {0} ({1} inserts) [LMB] unfold", { name, juce::String ((int) mixerops::groupOf (song, t).size()) });
  2777. break;
  2778. case Part::header:
  2779. h.text = name + " - " + tr ("[LMB] selects [Ctrl]+[LMB] or [Ctrl]+[Shift]+[LMB] adds or removes [Ctrl] drag across: range [LMB] drag sideways reorders [RMB] insert menu") + feeds() + latency();
  2780. h.hasMenu = true;
  2781. if (engine.insertPlaysStandIn (t))
  2782. h.text = name + " - " + tr ("Stand-in: a plugin of this insert is not installed on this PC, a render of its sound plays (the plugins' settings are kept)");
  2783. else if (engine.insertPluginOff (t)) // round 190ap
  2784. h.text = name + " - " + tr ("A plugin of this insert is switched off: the project was opened without third-party plugins (its settings are kept; File › Switch plugins back on...)");
  2785. break;
  2786. case Part::body:
  2787. case Part::none:
  2788. h.text = name + " - " + tr ("Click selects the insert (Ctrl+click or Ctrl+Shift+click: add or remove, Ctrl+drag across: range), right-click opens its menu; Alt+Left/Right moves the selection") + feeds() + latency();
  2789. h.hasMenu = true;
  2790. break;
  2791. }
  2792. return h;
  2793. }
  2794. void MixerStrips::mouseUp (const juce::MouseEvent& e)
  2795. {
  2796. if (insertsMouseUp (e)) // issue #154 part 2
  2797. return;
  2798. railRepeat.stopTimer();
  2799. railStrip = railNone;
  2800. if (headerDragged)
  2801. setMouseCursor (juce::MouseCursor::NormalCursor);
  2802. if (dragPart != Part::none || headerDragged || dragVca >= 0)
  2803. repaint();
  2804. dragVca = -1;
  2805. if (ctrlClickPending && selectAnchor > 0)
  2806. {
  2807. // the LYNX Ctrl+click toggle (the last selected track stays: the mixer always has one)
  2808. auto s = selection;
  2809. const auto t = selectAnchor;
  2810. if (const auto it = std::lower_bound (s.begin(), s.end(), t); it != s.end() && *it == t)
  2811. {
  2812. if (s.size() > 1)
  2813. s.erase (it);
  2814. }
  2815. else
  2816. s.insert (std::lower_bound (s.begin(), s.end(), t), t);
  2817. const auto primary = std::binary_search (s.begin(), s.end(), t) ? t : (std::binary_search (s.begin(), s.end(), selected) ? selected : s.back());
  2818. setSelection (s, primary);
  2819. }
  2820. ctrlClickPending = false;
  2821. headerDragTrack = -1;
  2822. headerDragged = false;
  2823. selectAnchor = -1;
  2824. selectBase.clear();
  2825. dragPart = Part::none;
  2826. dragTrack = -1;
  2827. drag.end();
  2828. ui::hideValueTip();
  2829. ui::clearPostedHint();
  2830. }
  2831. void MixerStrips::mouseDoubleClick (const juce::MouseEvent& e)
  2832. {
  2833. if (const auto i = vcaAt (e.x); i >= 0)
  2834. {
  2835. if (vcaPartAt (i, e.getPosition()) == Part::fader)
  2836. setVcaLevel (i, unityFader);
  2837. return;
  2838. }
  2839. const auto t = trackAt (e.x);
  2840. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  2841. return;
  2842. const auto part = partAt (t, e.getPosition());
  2843. if (part == Part::fader || part == Part::pan || part == Part::stereo || part == Part::send)
  2844. {
  2845. setValue (part, t, specFor (part, t).defaultValue);
  2846. showTip (part, t, true);
  2847. }
  2848. }
  2849. void MixerStrips::keepSelectionShown()
  2850. {
  2851. if (! showUsedOnly)
  2852. return;
  2853. const auto wasHidden = std::any_of (selection.begin(), selection.end(), [this] (int t) { return revealed.count (t) == 0 && isHidden (t); })
  2854. || (revealed.count (selected) == 0 && isHidden (selected));
  2855. if (wasHidden) // (selected from the Channel Rack, a menu or the keyboard: its strip comes back)
  2856. updateSize();
  2857. }
  2858. void MixerStrips::selectTrack (int track)
  2859. {
  2860. selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), track);
  2861. selection = { selected };
  2862. keepSelectionShown();
  2863. repaint();
  2864. if (onSelectionChanged)
  2865. onSelectionChanged (selected);
  2866. }
  2867. namespace
  2868. {
  2869. // The 3 knobs of each band of the track's built-in EQ (gain, frequency, width).
  2870. class TrackEqEditor final : public juce::Component
  2871. {
  2872. public:
  2873. TrackEqEditor (AudioEngine& e, int t)
  2874. : engine (e),
  2875. track (t)
  2876. {
  2877. const juce::String bands[] = { tr ("Low"), tr ("Mid"), tr ("High") };
  2878. const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
  2879. for (int b = 0; b < 3; ++b)
  2880. {
  2881. titles[(std::size_t) b].setText (bands[b], juce::dontSendNotification);
  2882. titles[(std::size_t) b].setJustificationType (juce::Justification::centred);
  2883. addAndMakeVisible (titles[(std::size_t) b]);
  2884. auto& gain = knobs[(std::size_t) b][0];
  2885. setup (gain, -18.0, 18.0, 0.1, " dB", eq.gainDb[(std::size_t) b]);
  2886. gain.setDoubleClickReturnValue (true, 0.0);
  2887. auto& hz = knobs[(std::size_t) b][1];
  2888. setup (hz, 10.0, 16000.0, 1.0, " Hz", eq.hz[(std::size_t) b]);
  2889. hz.setSkewFactorFromMidPoint (1000.0);
  2890. auto& width = knobs[(std::size_t) b][2];
  2891. setup (width, 0.0, 1.0, 0.01, "", eq.width[(std::size_t) b]);
  2892. width.setTooltip (b == 1 ? tr ("Peak width (Q)") : tr ("Shelf slope"));
  2893. }
  2894. setSize (3 * 90, 3 * 74 + 24);
  2895. }
  2896. void resized() override
  2897. {
  2898. auto area = getLocalBounds();
  2899. auto header = area.removeFromTop (20);
  2900. for (int b = 0; b < 3; ++b)
  2901. {
  2902. titles[(std::size_t) b].setBounds (header.removeFromLeft (90));
  2903. auto column = area.removeFromLeft (90);
  2904. for (auto& k : knobs[(std::size_t) b])
  2905. k.setBounds (column.removeFromTop (74));
  2906. }
  2907. }
  2908. private:
  2909. void setup (juce::Slider& s, double lo, double hi, double step, const char* suffix, float value)
  2910. {
  2911. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  2912. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 72, 16);
  2913. s.setRange (lo, hi, step);
  2914. s.setTextValueSuffix (suffix);
  2915. s.setValue (value, juce::dontSendNotification);
  2916. s.onValueChange = [this] { apply(); };
  2917. addAndMakeVisible (s);
  2918. }
  2919. void apply()
  2920. {
  2921. TrackEq eq;
  2922. for (std::size_t b = 0; b < 3; ++b)
  2923. {
  2924. eq.gainDb[b] = (float) knobs[b][0].getValue();
  2925. eq.hz[b] = (float) knobs[b][1].getValue();
  2926. eq.width[b] = (float) knobs[b][2].getValue();
  2927. }
  2928. engine.editSong ([t = track, eq] (Song& s) {
  2929. if (t < (int) s.mixer.size())
  2930. s.mixer[(std::size_t) t].eq = eq;
  2931. });
  2932. }
  2933. AudioEngine& engine;
  2934. int track;
  2935. std::array<juce::Label, 3> titles;
  2936. std::array<std::array<juce::Slider, 3>, 3> knobs; // [band][gain, frequency, width]
  2937. };
  2938. } // namespace
  2939. void MixerStrips::showTrackEq (int t)
  2940. {
  2941. auto editor = std::make_unique<TrackEqEditor> (engine, t);
  2942. juce::CallOutBox::launchAsynchronously (std::move (editor), getScreenBounds().withSize (10, 10).translated (getMouseXYRelative().x, getMouseXYRelative().y), nullptr);
  2943. }
  2944. namespace
  2945. {
  2946. juce::File mixerStatesFolder()
  2947. {
  2948. return lynx::platform::documentsFolder().getChildFile ("LYNX/Mixer states");
  2949. }
  2950. std::unique_ptr<juce::FileChooser>& mixerStateChooser()
  2951. {
  2952. static std::unique_ptr<juce::FileChooser> chooser;
  2953. return chooser;
  2954. }
  2955. // --- FL's track latency menu (REA round 165f-mixer: DelayMenu, FUN_012ae090 / FUN_012ad520 / FUN_012acd30) ---------
  2956. double sampleRateOf (const AudioEngine& engine)
  2957. {
  2958. return juce::jmax (1.0, engine.getTransport().sampleRate.load());
  2959. }
  2960. // The track's latency in the current PDC plan (its output: inputs + effects + manual), in ms
  2961. double trackLatencyMs (const AudioEngine& engine, int t)
  2962. {
  2963. const auto& plan = engine.getPdcPlan();
  2964. return t >= 0 && t < (int) plan.outLat.size() ? 1000.0 * plan.outLat[(std::size_t) t] / sampleRateOf (engine) : 0.0;
  2965. }
  2966. // FL's label: "(none)" or "<ms> ms / <samples> smp" of the manual latency
  2967. juce::String manualLatencyText (const AudioEngine& engine, const MixerTrack& track)
  2968. {
  2969. if (track.latencyMs == 0.0f)
  2970. return tr ("(none)");
  2971. const auto samples = manualLatencySamples (track, sampleRateOf (engine));
  2972. return (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms / " + (samples > 0 ? "+" : "") + juce::String (samples) + " smp";
  2973. }
  2974. void setTrackLatency (AudioEngine& engine, int t, double ms)
  2975. {
  2976. if (t < 0 || t >= (int) engine.getSong().mixer.size() || ! std::isfinite (ms))
  2977. return;
  2978. const auto v = (float) juce::jlimit ((double) -maxTrackLatencyMs, (double) maxTrackLatencyMs, ms);
  2979. engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].latencyMs = v; });
  2980. }
  2981. // "Set in ms / samples / beats": FL's input box, the value in that unit (FUN_012ad520)
  2982. void askTrackLatency (AudioEngine& engine, int t, int unit)
  2983. {
  2984. const auto& track = engine.getSong().mixer[(std::size_t) t];
  2985. const auto rate = sampleRateOf (engine);
  2986. const auto bpm = juce::jmax (1.0, engine.getSong().bpm);
  2987. const juce::String units[] = { tr ("Latency (ms)"), tr ("Latency (samples)"), tr ("Latency (beats)") };
  2988. const auto value = unit == 0 ? juce::String (track.latencyMs, 2)
  2989. : unit == 1 ? juce::String (manualLatencySamples (track, rate))
  2990. : juce::String (track.latencyMs * bpm / 60000.0, 6);
  2991. auto* w = new juce::AlertWindow (tr ("Track latency"),
  2992. tr ("Positive: the other tracks wait for this one (it plays earlier). Negative: this track is delayed."),
  2993. juce::MessageBoxIconType::NoIcon);
  2994. w->addTextEditor ("v", value, units[juce::jlimit (0, 2, unit)]);
  2995. w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  2996. w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  2997. w->enterModalState (true, juce::ModalCallbackFunction::create ([w, &engine, t, unit, rate, bpm] (int result) {
  2998. if (result != 1)
  2999. return;
  3000. const auto text = w->getTextEditorContents ("v").trim().replaceCharacter (',', '.');
  3001. if (! text.containsAnyOf ("0123456789"))
  3002. return;
  3003. const auto v = text.getDoubleValue();
  3004. setTrackLatency (engine, t, unit == 0 ? v : unit == 1 ? v * 1000.0 / rate : v * 60000.0 / bpm);
  3005. }), true);
  3006. }
  3007. juce::PopupMenu trackLatencyMenu (AudioEngine& engine, int t)
  3008. {
  3009. const auto& song = engine.getSong();
  3010. const auto& track = song.mixer[(std::size_t) t];
  3011. juce::PopupMenu menu;
  3012. // FL's hint "^Track latency": "<x>ms (auto) <y>ms (manual)"
  3013. // auto = the plan's latency without the manual part, in samples (no ms rounding left over when no plugin has any)
  3014. const auto total = trackLatencyMs (engine, t);
  3015. const auto rate = sampleRateOf (engine);
  3016. const auto autoMs = total - 1000.0 * lynx::manualLatencySamples (track, rate) / rate;
  3017. menu.addSectionHeader (tr ("Latency {0} ms (auto {1} ms, manual {2} ms)",
  3018. { juce::String (total, 2), juce::String (std::abs (autoMs) < 0.005 ? 0.0 : autoMs, 2), juce::String (track.latencyMs, 2) }));
  3019. menu.addItem (tr ("Reset"), track.latencyMs != 0.0f, false, [&engine, t] { setTrackLatency (engine, t, 0.0); });
  3020. menu.addItem (tr ("Set in ms..."), [&engine, t] { askTrackLatency (engine, t, 0); });
  3021. menu.addItem (tr ("Set in samples..."), [&engine, t] { askTrackLatency (engine, t, 1); });
  3022. menu.addItem (tr ("Set in beats..."), [&engine, t] { askTrackLatency (engine, t, 2); });
  3023. {
  3024. // FL's "Set from": the tracks whose latency is not zero; this track's total becomes theirs (FUN_012acd30)
  3025. juce::PopupMenu from;
  3026. for (int o = 0; o < (int) song.mixer.size(); ++o)
  3027. {
  3028. const auto ms = trackLatencyMs (engine, o);
  3029. if (o == t || std::abs (ms) < 0.005)
  3030. continue;
  3031. const auto name = o == 0 ? tr ("Master") : juce::String (o) + " " + juce::String::fromUTF8 (song.mixer[(std::size_t) o].name.c_str());
  3032. from.addItem (name + " (" + juce::String (ms, 2) + " ms)", [&engine, t, o] {
  3033. const auto manual = (double) engine.getSong().mixer[(std::size_t) t].latencyMs + trackLatencyMs (engine, o) - trackLatencyMs (engine, t);
  3034. if (manual < 0.0)
  3035. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Track latency"),
  3036. tr ("The delay introduced by this mixer track is higher than the delay introduced by the source "
  3037. "mixer track. Set a make-up latency on the source track instead."));
  3038. else
  3039. setTrackLatency (engine, t, manual);
  3040. });
  3041. }
  3042. menu.addSubMenu (tr ("Set from"), from, from.getNumItems() > 0);
  3043. }
  3044. menu.addSeparator();
  3045. menu.addItem (tr ("Compensate for master latency"), track.outputChannel >= 0, track.compensateMasterLatency, [&engine, t] {
  3046. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].compensateMasterLatency = ! s.mixer[(std::size_t) t].compensateMasterLatency; });
  3047. });
  3048. if (t > 0)
  3049. {
  3050. menu.addSectionHeader (tr ("Bypass track latency compensation"));
  3051. const std::pair<const char*, LatencyBypass> modes[] = { { TR_NOOP ("Never"), LatencyBypass::never },
  3052. { TR_NOOP ("Always"), LatencyBypass::always },
  3053. { TR_NOOP ("When recording or not playing"), LatencyBypass::whenRecordingOrStopped } };
  3054. for (const auto& [label, mode] : modes)
  3055. menu.addItem (tr (label), true, track.latencyBypass == mode, [&engine, t, mode = mode] {
  3056. engine.editSong ([t, mode] (Song& s) { s.mixer[(std::size_t) t].latencyBypass = mode; });
  3057. });
  3058. }
  3059. return menu;
  3060. }
  3061. } // namespace
  3062. bool loadMixerTrackState (AudioEngine& engine, int track, const juce::File& file, bool asNewInsert)
  3063. {
  3064. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  3065. return false;
  3066. if (asNewInsert)
  3067. return mixerpresets::insertTrack (engine, juce::jmax (1, track + 1), file) > 0;
  3068. return mixerpresets::loadOnTracks (engine, { track }, file);
  3069. }
  3070. namespace mixerpresets
  3071. {
  3072. juce::Array<juce::File> folders()
  3073. {
  3074. // FL's browser folder 0x3f8 (REA round 167q, FUN_009db5b0): "Presets\Mixer presets" of the user data folder and
  3075. // "Data\Patches\Mixer presets" of the installation
  3076. static const auto fl = findFlStudio();
  3077. juce::Array<juce::File> out;
  3078. if (fl.userData.isDirectory())
  3079. out.add (fl.userData.getChildFile ("Presets").getChildFile ("Mixer presets"));
  3080. if (fl.installDir.isDirectory())
  3081. out.add (fl.installDir.getChildFile ("Data").getChildFile ("Patches").getChildFile ("Mixer presets"));
  3082. out.add (mixerStatesFolder());
  3083. out.removeIf ([] (const juce::File& f) { return ! f.isDirectory(); });
  3084. return out;
  3085. }
  3086. juce::Array<juce::File> all()
  3087. {
  3088. juce::Array<juce::File> files;
  3089. for (const auto& folder : folders())
  3090. for (const auto& f : folder.findChildFiles (juce::File::findFiles, true, juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension))
  3091. files.add (f);
  3092. std::stable_sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
  3093. return a.getFileNameWithoutExtension().compareNatural (b.getFileNameWithoutExtension()) < 0;
  3094. });
  3095. return files;
  3096. }
  3097. static std::vector<std::uint8_t> bytesOf (const juce::File& file)
  3098. {
  3099. juce::MemoryBlock data;
  3100. if (file.getSize() > 64 * 1024 * 1024 || ! file.loadFileAsData (data))
  3101. return {};
  3102. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  3103. return { bytes, bytes + data.getSize() };
  3104. }
  3105. bool isMixerPreset (const juce::File& file)
  3106. {
  3107. if (file.hasFileExtension (ProjectFile::mixerTrackStateExtension))
  3108. return true;
  3109. if (! file.hasFileExtension ("fst"))
  3110. return false;
  3111. for (auto p = file.getParentDirectory(); p != juce::File() && p.getParentDirectory() != p; p = p.getParentDirectory())
  3112. if (p.getFileName().equalsIgnoreCase ("Mixer presets"))
  3113. return true;
  3114. const auto bytes = bytesOf (file);
  3115. return flp::looksLikeMixerPreset (bytes);
  3116. }
  3117. std::optional<MixerTrack> read (const juce::File& file)
  3118. {
  3119. if (file.hasFileExtension ("fst"))
  3120. {
  3121. FlpImportOptions options;
  3122. options.roots = findFlStudioRoots();
  3123. options.fileExists = [] (const std::string& path) { return platform::localFile (path).existsAsFile(); };
  3124. options.readFile = [] (const std::string& path) { return bytesOf (platform::localFile (path)); };
  3125. return mixerTrackFromFlPreset (bytesOf (file), options);
  3126. }
  3127. juce::String error;
  3128. auto state = ProjectFile::mixerTrackStateFromJson (file.loadFileAsString(), error);
  3129. if (state && state->name.empty())
  3130. state->name = file.getFileNameWithoutExtension().toStdString();
  3131. return state;
  3132. }
  3133. bool loadOnTracks (AudioEngine& engine, const std::vector<int>& tracks, const juce::File& file)
  3134. {
  3135. const auto state = read (file);
  3136. if (! state)
  3137. return false;
  3138. // FL's mixer presets restore the track's name and colour (WhatsNew); LYNX's states keep the track's own
  3139. const auto takeName = file.hasFileExtension ("fst") && ! state->name.empty();
  3140. bool any = false;
  3141. engine.editSong ([&] (Song& s) {
  3142. for (const auto t : tracks)
  3143. if (t >= 0 && t < (int) s.mixer.size())
  3144. {
  3145. ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) t], *state, takeName);
  3146. any = true;
  3147. }
  3148. });
  3149. return any;
  3150. }
  3151. int insertTrack (AudioEngine& engine, int at, const juce::File& file)
  3152. {
  3153. auto state = read (file);
  3154. if (! state)
  3155. return -1;
  3156. if (state->name.empty())
  3157. state->name = file.getFileNameWithoutExtension().toStdString();
  3158. at = juce::jlimit (1, (int) engine.getSong().mixer.size(), at);
  3159. bool ok = false;
  3160. engine.editSong ([&] (Song& s) {
  3161. ok = mixerops::insertTrack (s, at);
  3162. if (ok)
  3163. ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) at], *state, true);
  3164. });
  3165. return ok ? at : -1;
  3166. }
  3167. } // namespace mixerpresets
  3168. bool saveMixerTrackState (AudioEngine& engine, int track, const juce::File& file)
  3169. {
  3170. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  3171. return false;
  3172. engine.capturePluginStates(); // the plugins' current settings go into the state
  3173. file.getParentDirectory().createDirectory();
  3174. return file.replaceWithText (ProjectFile::mixerTrackStateToJson (engine.getSong().mixer[(std::size_t) track]));
  3175. }
  3176. // FL's "Auto-create audio clip" (round 167a [SHOT s28–s37]): the rendered files go on the Playlist, one undo step
  3177. static void placeRenderedFiles (AudioEngine& engine, const std::vector<juce::File>& files)
  3178. {
  3179. std::vector<mixerops::RenderedFile> list;
  3180. juce::AudioFormatManager formats;
  3181. formats.registerBasicFormats();
  3182. for (const auto& f : files)
  3183. if (std::unique_ptr<juce::AudioFormatReader> reader (formats.createReaderFor (f)); reader != nullptr)
  3184. list.push_back ({ f.getFullPathName().toStdString(), (double) reader->lengthInSamples, reader->sampleRate });
  3185. if (! list.empty())
  3186. engine.editSong ([list] (Song& s) { mixerops::placeRenderedFiles (s, list); });
  3187. }
  3188. std::unique_ptr<juce::AlertWindow> MixerStrips::makeInsertMultipleBox (bool adding)
  3189. {
  3190. auto window = std::make_unique<juce::AlertWindow> (adding ? tr ("Add multiple") : tr ("Insert multiple"),
  3191. adding ? tr ("Enter the number of mixer tracks to add") : tr ("Number of tracks to add"),
  3192. juce::MessageBoxIconType::NoIcon);
  3193. window->addTextEditor ("count", adding ? "10" : "1");
  3194. if (auto* field = window->getTextEditor ("count"))
  3195. field->setInputRestrictions (4, "0123456789");
  3196. window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  3197. window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  3198. return window;
  3199. }
  3200. void MixerStrips::askInsertMultiple (int at, bool adding)
  3201. {
  3202. // FL 2026 (round 190gw; live check 190gu B4, shots reafl/fl-mixer-insert-multiple-*.png; FLEngine
  3203. // InsertMixerTrackMenuItemClick 0x129c990 and AddOneMixerTrackMenuClick 0x12a8bb0 Tag -2): the track menu's
  3204. // "Insert multiple..." asks "Number of tracks to add" (1, selected) and refuses anything outside 1 to the room left
  3205. // ("Please enter a number between 1 and N.", N = 500 - inserts: 377 on a 123-insert project); the new tracks go before
  3206. // the track and are all selected. The "+" menu's "Add multiple..." asks "Enter the number of mixer tracks to add" (10)
  3207. // and refuses more than the room ("You can add a maximum of N tracks."). Nothing is added after an error.
  3208. auto* window = makeInsertMultipleBox (adding).release();
  3209. juce::Component::SafePointer<MixerStrips> safe (this);
  3210. window->enterModalState (true, juce::ModalCallbackFunction::create ([safe, at, adding, window] (int result) {
  3211. if (safe == nullptr || result != 1)
  3212. return;
  3213. const auto n = window->getTextEditorContents ("count").getIntValue();
  3214. const auto& song = safe->engine.getSong();
  3215. const auto room = mixerops::roomForInserts (song);
  3216. if (const auto check = mixerops::checkInsertMultiple (song, n, adding); check != mixerops::InsertCheck::ok)
  3217. {
  3218. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Error"),
  3219. check == mixerops::InsertCheck::outOfRange
  3220. ? tr ("Please enter a number between 1 and {0}.", { juce::String (room) })
  3221. : tr ("You can add a maximum of {0} tracks.", { juce::String (room) }));
  3222. return;
  3223. }
  3224. if (n <= 0)
  3225. return;
  3226. const auto first = juce::jlimit (1, (int) song.mixer.size(), at);
  3227. int added = 0;
  3228. safe->engine.editSong ([first, n, &added] (Song& s) { added = mixerops::insertTracks (s, first, n); });
  3229. std::vector<int> made;
  3230. for (int i = 0; i < added; ++i)
  3231. {
  3232. safe->revealed.insert (first + i); // shown even while unused
  3233. made.push_back (first + i);
  3234. }
  3235. safe->updateSize();
  3236. if (! made.empty())
  3237. safe->setSelection (made, first); // (FL: the new tracks, all selected)
  3238. }),
  3239. true);
  3240. if (auto* field = window->getTextEditor ("count"))
  3241. {
  3242. field->grabKeyboardFocus();
  3243. field->selectAll();
  3244. }
  3245. }
  3246. // FL's "Increase number of tracks to..." (AddOneMixerTrackMenuClick 0x12a8bb0, Tag -1; round 190fl): the box starts at
  3247. // the number of inserts; FL refuses a number below it or above 500 with "Track count must be between N and 500."
  3248. void MixerStrips::askInsertCount()
  3249. {
  3250. const auto now = mixerops::insertCount (engine.getSong());
  3251. auto* window = new juce::AlertWindow (tr ("Increase number of tracks to..."), tr ("Enter the number of mixer tracks"), juce::MessageBoxIconType::NoIcon);
  3252. window->addTextEditor ("count", juce::String (now));
  3253. if (auto* field = window->getTextEditor ("count"))
  3254. field->setInputRestrictions (4, "0123456789");
  3255. window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  3256. window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  3257. juce::Component::SafePointer<MixerStrips> safe (this);
  3258. window->enterModalState (true, juce::ModalCallbackFunction::create ([safe, window] (int result) {
  3259. if (safe == nullptr || result != 1)
  3260. return;
  3261. const auto wanted = window->getTextEditorContents ("count").getIntValue();
  3262. const auto& song = safe->engine.getSong();
  3263. if (! mixerops::validInsertCount (song, wanted))
  3264. {
  3265. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Error"),
  3266. tr ("Track count must be between {0} and {1}.",
  3267. { juce::String (mixerops::insertCount (song)), juce::String (maxMixerTracks - 1) }));
  3268. return;
  3269. }
  3270. const auto first = (int) song.mixer.size();
  3271. int added = 0;
  3272. safe->engine.editSong ([wanted, &added] (Song& s) { added = mixerops::increaseInsertsTo (s, wanted); });
  3273. for (int i = 0; i < added; ++i)
  3274. safe->revealed.insert (first + i); // shown even while unused
  3275. safe->updateSize();
  3276. }),
  3277. true);
  3278. if (auto* field = window->getTextEditor ("count"))
  3279. {
  3280. field->grabKeyboardFocus();
  3281. field->selectAll();
  3282. }
  3283. }
  3284. void MixerStrips::showMenu (int t)
  3285. {
  3286. buildMenu (t).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  3287. }
  3288. bool MixerStrips::runMenuItem (const juce::String& caption)
  3289. {
  3290. auto menu = buildMenu (getSelectedTrack());
  3291. for (juce::PopupMenu::MenuItemIterator it (menu, true); it.next();)
  3292. {
  3293. const auto& item = it.getItem();
  3294. if (item.isEnabled && item.action != nullptr && item.subMenu == nullptr
  3295. && item.text.upToFirstOccurrenceOf ("\t", false, false).trim() == caption)
  3296. {
  3297. const auto action = item.action; // (the menu goes away first)
  3298. menu = {};
  3299. action();
  3300. return true;
  3301. }
  3302. }
  3303. return false;
  3304. }
  3305. juce::PopupMenu MixerStrips::buildMenu (int t)
  3306. {
  3307. const auto& song = engine.getSong();
  3308. const auto channel = engine.getSelectedChannel();
  3309. juce::PopupMenu menu;
  3310. if (t < 0 || t >= (int) song.mixer.size())
  3311. return menu;
  3312. // the tracks the "selected track(s)" items act on: the selection when the clicked track is in it
  3313. const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
  3314. const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  3315. auto rename = [this, t] {
  3316. if (t >= (int) engine.getSong().mixer.size())
  3317. return;
  3318. const auto& track = engine.getSong().mixer[(std::size_t) t];
  3319. showNameAndColourDialog (tr ("Rename track"), juce::String::fromUTF8 (track.name.c_str()), track.colour,
  3320. [this, t] (const juce::String& name, std::uint32_t colour) {
  3321. if (t < (int) engine.getSong().mixer.size())
  3322. engine.editSong ([t, n = name.trim().toStdString(), colour] (Song& s) {
  3323. if (! n.empty())
  3324. s.mixer[(std::size_t) t].name = n;
  3325. s.mixer[(std::size_t) t].colour = colour;
  3326. });
  3327. });
  3328. };
  3329. // the title band in the insert's colour (FL tints the whole menu); a double-click on it renames (issue #12)
  3330. // FL: "Mixer tracks (N selected)" when the menu acts on several tracks
  3331. const auto several = targets.size() > 1;
  3332. ui::addItemHeader (menu, several ? juce::String() : t == 0 ? tr ("Master") : tr ("Mixer track {0}", { juce::String (t) }),
  3333. several ? tr ("Mixer tracks ({0} selected)", { juce::String ((int) targets.size()) }) : trackName,
  3334. song.mixer[(std::size_t) t].colour != 0 ? juce::Colour (song.mixer[(std::size_t) t].colour) : juce::Colour(), rename);
  3335. // FL's first section: name and colour (REA_rodada115)
  3336. menu.addItem (tr ("Rename and color...") + "\tF2", rename);
  3337. menu.addItem (tr ("Change color..."), [this, t] { // (FL: the colour selector at once)
  3338. const auto current = engine.getSong().mixer[(std::size_t) t].colour;
  3339. const auto mouse = juce::Desktop::getMousePosition();
  3340. const auto set = [this, t] (std::uint32_t colour) {
  3341. if (t < (int) engine.getSong().mixer.size())
  3342. engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
  3343. };
  3344. ui::showColourPickerPopup ({ mouse.x, mouse.y, 1, 1 }, tr ("Change color..."), current != 0 ? juce::Colour (current) : juce::Colour (lynxPalette()[0]), {},
  3345. [set] (juce::Colour c) { set (c.getARGB()); }, {}, [set] { set (0); });
  3346. });
  3347. menu.addItem (tr ("Random color"), [this, t] {
  3348. const auto& palette = lynxPalette();
  3349. const auto colour = palette[(std::size_t) juce::Random::getSystemRandom().nextInt ((int) palette.size())];
  3350. engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
  3351. });
  3352. // FL's "Gradient color..." (SetGradientColorMenuClick, REA_rodada177a §5): greyed below two selected tracks; the
  3353. // Gradient editor starts from the first and the last selected track's colours
  3354. menu.addItem (tr ("Gradient color..."), targets.size() > 1, false, [this, targets] {
  3355. auto sorted = targets;
  3356. std::sort (sorted.begin(), sorted.end());
  3357. const auto& mixer = engine.getSong().mixer;
  3358. const auto colourOf = [&mixer] (int track) {
  3359. const auto c = track >= 0 && track < (int) mixer.size() ? mixer[(std::size_t) track].colour : 0u;
  3360. return c != 0 ? juce::Colour (c) : juce::Colour (lynxPalette()[0]);
  3361. };
  3362. showGradientColourDialog (colourOf (sorted.front()), colourOf (sorted.back()), (int) sorted.size(),
  3363. [this, sorted] (juce::Colour first, juce::Colour last) {
  3364. engine.editSong ([sorted, a = first.getARGB(), b = last.getARGB()] (Song& s) {
  3365. mixerops::gradientColour (s, sorted, a, b);
  3366. });
  3367. });
  3368. });
  3369. // FL's "Change icon..." (SetIconMenuClick, REA round 168h: every selected track gets it); LYNX's own icon set
  3370. menu.addItem (tr ("Change icon..."), [this, t, targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t }] {
  3371. ui::showTrackIconPicker (juce::Rectangle<int> (juce::Desktop::getMousePosition().x, juce::Desktop::getMousePosition().y, 1, 1), engine.getSong().mixer[(std::size_t) t].icon, [this, targets] (int icon) {
  3372. engine.editSong ([targets, icon] (Song& s) {
  3373. for (auto track : targets)
  3374. if (track >= 0 && track < (int) s.mixer.size())
  3375. s.mixer[(std::size_t) track].icon = icon;
  3376. });
  3377. });
  3378. });
  3379. // FL's "Assign to new Audio track(s)" / "Unassign from Audio track(s)" (AssignAudiotrackMenuClick, REA_rodada177a §6)
  3380. {
  3381. const auto linked = [&song] (int insert) {
  3382. return std::any_of (song.playlistTracks.begin(), song.playlistTracks.end(), [insert] (const PlaylistTrack& pt) {
  3383. return pt.mode == PlaylistTrackMode::audio && pt.mixerTrack == insert;
  3384. });
  3385. };
  3386. const auto anyLinked = std::any_of (targets.begin(), targets.end(), [&] (int x) { return x > 0 && linked (x); });
  3387. const auto anyFree = std::any_of (targets.begin(), targets.end(), [&] (int x) { return x > 0 && ! linked (x); });
  3388. menu.addItem (tr ("Assign to new Audio track(s)"), anyFree, false,
  3389. [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::assignNewAudioTracks (s, targets); }); });
  3390. menu.addItem (tr ("Unassign from Audio track(s)"), anyLinked, false,
  3391. [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::unassignAudioTracks (s, targets); }); });
  3392. }
  3393. menu.addSeparator();
  3394. // FL's "File" submenu (REA round 167q, TFXForm's FileMenu): open/save a state, Browse states and the "States" list
  3395. // of FL's mixer presets (FL's own .fst and the user's) and LYNX's .lynxtrack states, loaded onto every selected
  3396. // track (FUN_012a7440)
  3397. {
  3398. const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
  3399. juce::PopupMenu file;
  3400. file.addItem (tr ("Open mixer track state..."), [this, targets] {
  3401. auto& chooser = mixerStateChooser();
  3402. const auto start = mixerpresets::folders().isEmpty() ? mixerStatesFolder() : mixerpresets::folders()[0];
  3403. chooser = lynx::ui::makeFileChooser (tr ("Open mixer track state"), start,
  3404. juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension);
  3405. juce::Component::SafePointer<MixerStrips> safe (this);
  3406. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [safe, targets] (const juce::FileChooser& fc) {
  3407. if (safe != nullptr && fc.getResult().existsAsFile() && ! mixerpresets::loadOnTracks (safe->engine, targets, fc.getResult()))
  3408. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Open mixer track state"),
  3409. tr ("This file is not a mixer track state LYNX SHARE can read."));
  3410. });
  3411. });
  3412. file.addItem (tr ("Save mixer track state as...") + "\tCtrl+Shift+S", [this, t, trackName] {
  3413. auto& chooser = mixerStateChooser();
  3414. const auto name = juce::File::createLegalFileName (trackName.isNotEmpty() ? trackName : tr ("Mixer track {0}", { juce::String (t) }));
  3415. chooser = lynx::ui::makeFileChooser (tr ("Save mixer track state"), mixerStatesFolder().getChildFile (name + ProjectFile::mixerTrackStateExtension),
  3416. juce::String ("*") + ProjectFile::mixerTrackStateExtension);
  3417. juce::Component::SafePointer<MixerStrips> safe (this);
  3418. mixerStatesFolder().createDirectory();
  3419. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting, [safe, t] (const juce::FileChooser& fc) {
  3420. if (safe != nullptr && fc.getResult() != juce::File())
  3421. saveMixerTrackState (safe->engine, t, fc.getResult().withFileExtension (ProjectFile::mixerTrackStateExtension));
  3422. });
  3423. });
  3424. file.addItem (tr ("Browse states"), [] {
  3425. mixerStatesFolder().createDirectory();
  3426. mixerStatesFolder().startAsProcess();
  3427. });
  3428. const auto states = mixerpresets::all();
  3429. if (! states.isEmpty())
  3430. {
  3431. file.addSectionHeader (tr ("States"));
  3432. for (const auto& f : states)
  3433. file.addItem (f.getFileNameWithoutExtension(), [this, targets, f] { mixerpresets::loadOnTracks (engine, targets, f); });
  3434. }
  3435. menu.addSubMenu (tr ("File"), file);
  3436. }
  3437. if (t > 0)
  3438. {
  3439. const auto& mt = song.mixer[(std::size_t) t];
  3440. const auto current = mt.inputChannel >= 0
  3441. ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str())
  3442. : tr ("none");
  3443. menu.addItem (tr ("Audio input: {0}...", { current }), [this, t] { mixerinput::showMenu (engine, t, this); });
  3444. }
  3445. // FL: the audio editor is loaded into the track's first empty slot (round 190cd); a full track gets the editor
  3446. // window as before
  3447. menu.addItem (tr ("Open audio editor") + "\tCtrl+E", [this, t] {
  3448. if (const auto at = addEdisonSlot (engine, t); at >= 0)
  3449. openEdisonSlot (engine, t, at);
  3450. else
  3451. openAudioEditor (engine);
  3452. });
  3453. menu.addItem (tr ("Open audio editor and record") + "\tShift+E", [this, t] {
  3454. // FL arms an Edison set to On play, 5 min, Append off, Slave on (live check 190cq, shot edison190cd-05b)
  3455. if (const auto at = addEdisonSlot (engine, t, true); at >= 0)
  3456. openEdisonSlot (engine, t, at, true);
  3457. else
  3458. openAudioEditorRecording (engine);
  3459. });
  3460. menu.addSeparator(); // (FL: a line before Reset)
  3461. menu.addItem (tr ("Reset selected track(s) to default"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetToDefault (s, targets); }); });
  3462. // --- FL's "Routing" section -----------------------------------------------------------------------
  3463. menu.addSectionHeader (tr ("Routing"));
  3464. {
  3465. juce::PopupMenu channels;
  3466. channels.addItem (tr ("Route selected channels to this track") + "\tCtrl+L", [this, t] {
  3467. setSelection (selection, t);
  3468. linkSelectedChannels (false);
  3469. });
  3470. channels.addItem (tr ("Route selected channels starting from this track") + "\tCtrl+Shift+L", [this, t] {
  3471. setSelection (selection, t);
  3472. linkSelectedChannels (true);
  3473. });
  3474. if (channel < (int) song.channels.size())
  3475. channels.addItem (tr ("Route channel \"{0}\" here", { juce::String::fromUTF8 (song.channels[(std::size_t) channel].name.c_str()) }),
  3476. [this, channel, t] { engine.editSong ([channel, t] (Song& s) { s.channels[(std::size_t) channel].mixerTrack = t; }); });
  3477. menu.addSubMenu (tr ("Channel routing"), channels);
  3478. }
  3479. {
  3480. // FL's Routing submenu (REA round 165f-mixer: FUN_012ac520 / FUN_012ac950): selected tracks ⇄ this track
  3481. std::vector<int> others;
  3482. for (auto x : selection)
  3483. if (x != t)
  3484. others.push_back (x);
  3485. const auto any = ! others.empty();
  3486. juce::PopupMenu routing;
  3487. routing.addSectionHeader (tr ("Selected tracks to this track"));
  3488. using K = mixerops::RouteKind;
  3489. auto selToThis = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeSelectedTo (s, others, t, kind); }); };
  3490. auto thisToSel = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeToSelected (s, t, others, kind); }); };
  3491. routing.addItem (tr ("Route selected to this track"), any, false, [selToThis] { selToThis (K::route); });
  3492. routing.addItem (tr ("Route selected to this track only"), any, false, [selToThis] { selToThis (K::routeOnly); });
  3493. routing.addItem (tr ("Sidechain selected to this track"), any && t > 0, false, [selToThis] { selToThis (K::sidechain); });
  3494. routing.addItem (tr ("Sidechain selected to this track only"), any && t > 0, false, [selToThis] { selToThis (K::sidechainOnly); });
  3495. routing.addSeparator();
  3496. routing.addItem (tr ("Create submix..."), any && t > 0, false, [this, others, t] {
  3497. const auto& track = engine.getSong().mixer[(std::size_t) t];
  3498. const auto name = mixerops::hasDefaultName (engine.getSong(), t) ? juce::String() : juce::String::fromUTF8 (track.name.c_str());
  3499. showNameAndColourDialog (tr ("Create submix"), name, track.colour, [this, others, t] (const juce::String& n, std::uint32_t colour) {
  3500. if (t < (int) engine.getSong().mixer.size())
  3501. engine.editSong ([others, t, n = n.trim().toStdString(), colour] (Song& s) {
  3502. s.mixer[(std::size_t) t].colour = colour;
  3503. mixerops::createSubmix (s, others, t, n);
  3504. });
  3505. });
  3506. });
  3507. const auto thisIsInsert = t > 0;
  3508. routing.addSectionHeader (tr ("This track to selected tracks"));
  3509. routing.addItem (tr ("Route this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::route); });
  3510. routing.addItem (tr ("Route this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::routeOnly); });
  3511. routing.addItem (tr ("Sidechain this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechain); });
  3512. routing.addItem (tr ("Sidechain this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechainOnly); });
  3513. menu.addSubMenu (tr ("Track routing"), routing, any);
  3514. // round 186c's option: the sends this insert lost when their insert was deleted (greyed in the routing lane)
  3515. if (t > 0 && ! song.mixer[(std::size_t) t].lostSends.empty())
  3516. {
  3517. juce::PopupMenu lost;
  3518. const auto& lostSends = song.mixer[(std::size_t) t].lostSends;
  3519. for (int i = 0; i < (int) lostSends.size(); ++i)
  3520. {
  3521. juce::PopupMenu one;
  3522. juce::PopupMenu to;
  3523. for (int x = 1; x < (int) song.mixer.size(); ++x)
  3524. if (x != t)
  3525. to.addItem (juce::String (x) + ". " + juce::String::fromUTF8 (song.mixer[(std::size_t) x].name.c_str()), song.routes (t, x) || song.canRoute (t, x),
  3526. false, [this, t, i, x] { engine.editSong ([t, i, x] (Song& s) { mixerops::reconnectLostSend (s, t, i, x); }); });
  3527. one.addSubMenu (tr ("Reconnect to"), to);
  3528. one.addItem (tr ("Remove"), [this, t, i] { engine.editSong ([t, i] (Song& s) { mixerops::removeLostSends (s, t, i); }); });
  3529. lost.addSubMenu (tr ("Send to {0} (deleted)", { juce::String::fromUTF8 (lostSends[(std::size_t) i].to.c_str()) }), one);
  3530. }
  3531. lost.addSeparator();
  3532. lost.addItem (tr ("Remove all"), [this, t] { engine.editSong ([t] (Song& s) { mixerops::removeLostSends (s, t); }); });
  3533. menu.addSubMenu (tr ("Disconnected links"), lost);
  3534. }
  3535. }
  3536. {
  3537. juce::PopupMenu select;
  3538. select.addItem (tr ("Channels routed to this track") + "\tAlt+L", ! mixerops::channelsOn (song, t).empty(), false, [this, t] {
  3539. setSelection (selection, t);
  3540. selectLinkedChannels();
  3541. });
  3542. // FL's second item (SelectLinkedMenuClick 0x129d110, round 190fl): every selected insert's channels and Playlist
  3543. // tracks (audio tracks linked to it, instrument tracks whose channel plays into it); the Playlist shows the first
  3544. {
  3545. const auto channels = mixerops::channelsOn (song, targets);
  3546. const auto tracks = mixerops::playlistTracksOn (song, targets);
  3547. select.addItem (tr ("Channels and playlist tracks routed to this track"), ! channels.empty() || ! tracks.empty(), false,
  3548. [this, channels, tracks] {
  3549. if (! channels.empty())
  3550. engine.setChannelSelection (channels, channels.front());
  3551. if (! tracks.empty() && mixeroptions::selectPlaylistTracks)
  3552. mixeroptions::selectPlaylistTracks (tracks);
  3553. });
  3554. }
  3555. select.addSeparator();
  3556. const auto destinations = mixerops::destinationsOf (song, t);
  3557. const auto sources = mixerops::sourcesOf (song, t);
  3558. select.addItem (tr ("Tracks this one is routed to"), ! destinations.empty(), false, [this, t, destinations] { setSelection (destinations, t); });
  3559. select.addItem (tr ("Tracks routed to this one"), ! sources.empty(), false, [this, t, sources] { setSelection (sources, t); });
  3560. select.addSeparator();
  3561. select.addItem (tr ("Group"), t > 0, false, [this, t] {
  3562. auto group = mixerops::groupOf (engine.getSong(), t);
  3563. std::sort (group.begin(), group.end());
  3564. setSelection (group, t);
  3565. });
  3566. select.addItem (tr ("All"), [this, t] {
  3567. std::vector<int> all ((std::size_t) engine.getSong().mixer.size());
  3568. std::iota (all.begin(), all.end(), 0);
  3569. setSelection (all, t);
  3570. });
  3571. menu.addSubMenu (tr ("Select"), select);
  3572. }
  3573. menu.addItem (tr ("Reset selected track(s) routing"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetRouting (s, targets); }); });
  3574. menu.addItem (tr ("Unroute tracks routed to the selected track(s)"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::unrouteInto (s, targets); }); });
  3575. if (selected > 0 && selected != t && (t == 0 || song.canRoute (selected, t) || song.routes (selected, t)))
  3576. menu.addItem (tr ("Send \"{0}\" only to this track", { juce::String::fromUTF8 (song.mixer[(std::size_t) selected].name.c_str()) }),
  3577. [this, from = selected, t] {
  3578. engine.editSong ([from, t] (Song& s) {
  3579. s.mixer[(std::size_t) from].sends.clear();
  3580. s.mixer[(std::size_t) from].toMaster = false;
  3581. s.setRoute (from, t, true);
  3582. });
  3583. });
  3584. menu.addSeparator();
  3585. {
  3586. const auto inserts = [targets] {
  3587. std::vector<int> v;
  3588. for (auto x : targets)
  3589. if (x > 0)
  3590. v.push_back (x);
  3591. return v;
  3592. }();
  3593. // FL's two solo items (REA_rodada167l §4): the plain one mutes the tracks feeding the soloed ones, the alt one
  3594. // keeps them; the same item again clears the solo
  3595. menu.addItem (tr ("Solo selected track(s)") + "\tS", ! inserts.empty(), false, [this, inserts] {
  3596. engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, false); });
  3597. });
  3598. menu.addItem (tr ("Alt solo selected track(s)") + "\tAlt+S", ! inserts.empty(), false, [this, inserts] {
  3599. engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, true); });
  3600. });
  3601. menu.addItem (tr ("Arm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
  3602. for (auto x : inserts)
  3603. if (! engine.isInsertArmed (x))
  3604. mixerinput::toggleArm (engine, x, this);
  3605. });
  3606. menu.addItem (tr ("Disarm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
  3607. for (auto x : inserts)
  3608. if (engine.isInsertArmed (x))
  3609. engine.setInsertArmed (x, false);
  3610. });
  3611. }
  3612. menu.addItem (tr ("Compensate for master latency"), song.mixer[(std::size_t) t].outputChannel >= 0, song.mixer[(std::size_t) t].compensateMasterLatency, [this, t] {
  3613. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].compensateMasterLatency = ! s.mixer[(std::size_t) t].compensateMasterLatency; });
  3614. });
  3615. // FL's track latency (the "Track latency compensation" label's menu, REA round 165f-mixer)
  3616. menu.addSubMenu (tr ("Track latency: {0}", { manualLatencyText (engine, song.mixer[(std::size_t) t]) }), trackLatencyMenu (engine, t));
  3617. // --- LYNX's sound items (FL has them on the strip itself) -------------------------------------------
  3618. menu.addSectionHeader (tr ("Sound"));
  3619. {
  3620. const auto& track = song.mixer[(std::size_t) t];
  3621. juce::PopupMenu stereo;
  3622. const std::pair<const char*, float> widths[] = { { TR_NOOP ("Mono"), 1.0f }, { TR_NOOP ("Narrower"), 0.5f }, { TR_NOOP ("Normal"), 0.0f },
  3623. { TR_NOOP ("Wider"), -0.5f }, { TR_NOOP ("Very wide"), -1.0f } };
  3624. for (const auto& [label, value] : widths)
  3625. stereo.addItem (tr (label), true, std::abs (track.stereo - value) < 0.01f,
  3626. [this, t, v = value] { engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].stereo = v; }); });
  3627. menu.addSubMenu (tr ("Stereo separation"), stereo);
  3628. if (! song.cleanMixer)
  3629. menu.addItem (tr ("Track EQ..."), [this, t] { showTrackEq (t); });
  3630. menu.addItem (tr ("Invert phase"), true, track.invertPhase, [this, t] {
  3631. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].invertPhase = ! s.mixer[(std::size_t) t].invertPhase; });
  3632. });
  3633. menu.addItem (tr ("Swap left/right"), true, track.swapChannels, [this, t] {
  3634. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].swapChannels = ! s.mixer[(std::size_t) t].swapChannels; });
  3635. });
  3636. if (t > 0)
  3637. menu.addItem (tr ("Render to audio (freeze)..."), [this, t] { bounceInsertToAudio (engine, t); });
  3638. // round 190ch (LYNX's own, not an FL item): the one-click vocal clean-up chain on this insert. Round 190cm: here
  3639. // with LYNX's other sound items, no longer between FL's own "File" and audio input rows
  3640. if (t > 0)
  3641. menu.addSubMenu (tr ("Clean voice"), lynx::ui::cleanVoiceMenu (engine, t));
  3642. }
  3643. // --- FL's "Group" section (REA round 146a) -----------------------------------------------------------
  3644. if (t > 0)
  3645. {
  3646. menu.addSectionHeader (tr ("Group"));
  3647. const auto on = song.mixer[(std::size_t) t].separator;
  3648. menu.addItem (tr ("Separator"), true, on, [this, targets, on] {
  3649. engine.editSong ([targets, on] (Song& s) { mixerops::setSeparator (s, targets, ! on); });
  3650. });
  3651. menu.addItem (tr ("Create group"), [this, targets, t] { engine.editSong ([targets, t] (Song& s) { mixerops::createGroup (s, targets, t); }); });
  3652. menu.addItem (tr ("Auto color group"), song.mixer[(std::size_t) t].colour != 0, false,
  3653. [this, t] { engine.editSong ([t] (Song& s) { mixerops::autoColorGroup (s, t); }); });
  3654. // LYNX's addition (round 177a): a group folds to its bus strip, or to a slim tab when it has no bus
  3655. const auto canFold = mixerops::canFold (song, t);
  3656. const auto folded = mixerops::isFolded (song, t);
  3657. menu.addItem (folded ? tr ("Unfold group") : tr ("Fold group"), canFold, false, [this, t] {
  3658. engine.editSong ([t] (Song& s) { mixerops::toggleFold (s, t); });
  3659. updateSize();
  3660. });
  3661. menu.addItem (tr ("Fold all groups"), [this] {
  3662. engine.editSong ([] (Song& s) { mixerops::foldAll (s, true); });
  3663. updateSize();
  3664. });
  3665. menu.addItem (tr ("Unfold all groups"), [this] {
  3666. engine.editSong ([] (Song& s) { mixerops::foldAll (s, false); });
  3667. updateSize();
  3668. });
  3669. // LYNX's addition (round 177a): VCA faders, their strips left of the Master
  3670. std::vector<int> members;
  3671. for (const auto m : targets)
  3672. if (m > 0)
  3673. members.push_back (m);
  3674. juce::PopupMenu vcaMenu;
  3675. vcaMenu.addItem (tr ("New VCA from selected"), [this, members] {
  3676. engine.editSong ([members] (Song& s) { mixerops::createVca (s, members, {}); });
  3677. updateSize();
  3678. });
  3679. juce::PopupMenu assign, remove;
  3680. for (int i = 0; i < (int) song.vcas.size(); ++i)
  3681. {
  3682. const auto& vca = song.vcas[(std::size_t) i];
  3683. const auto in = [&vca] (int m) { return std::binary_search (vca.members.begin(), vca.members.end(), m); };
  3684. const auto all = std::all_of (members.begin(), members.end(), in);
  3685. const auto any = std::any_of (members.begin(), members.end(), in);
  3686. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  3687. assign.addItem (name, ! all, all, [this, members, i] {
  3688. engine.editSong ([members, i] (Song& s) { mixerops::assignToVca (s, members, i); });
  3689. });
  3690. if (any)
  3691. remove.addItem (name, [this, members, i] {
  3692. engine.editSong ([members, i] (Song& s) { mixerops::removeFromVca (s, members, i); });
  3693. });
  3694. }
  3695. vcaMenu.addSubMenu (tr ("Assign to VCA"), assign, assign.getNumItems() > 0);
  3696. vcaMenu.addSubMenu (tr ("Remove from VCA"), remove, remove.getNumItems() > 0);
  3697. menu.addSubMenu (tr ("VCA"), vcaMenu);
  3698. }
  3699. // --- FL's "Layout" section --------------------------------------------------------------------------
  3700. {
  3701. menu.addSectionHeader (tr ("Layout"));
  3702. juce::PopupMenu dockMenu;
  3703. const auto dock = song.mixer[(std::size_t) t].dock;
  3704. const std::pair<const char*, MixerDock> docks[] = { { TR_NOOP ("Left"), MixerDock::left }, { TR_NOOP ("Middle"), MixerDock::middle },
  3705. { TR_NOOP ("Right"), MixerDock::right } };
  3706. for (const auto& [label, d] : docks)
  3707. dockMenu.addItem (tr (label), true, dock == d, [this, targets, d = d] {
  3708. engine.editSong ([targets, d] (Song& s) { mixerops::dockTracks (s, targets, d); });
  3709. });
  3710. menu.addSubMenu (tr ("Dock to"), dockMenu);
  3711. }
  3712. if (t > 0)
  3713. {
  3714. menu.addItem (tr ("Move left") + "\tAlt+Left", t > 1, false, [this, t] {
  3715. setSelection ({ t }, t);
  3716. moveSelected (-1);
  3717. });
  3718. menu.addItem (tr ("Move right") + "\tAlt+Right", t + 1 < (int) song.mixer.size(), false, [this, t] {
  3719. setSelection ({ t }, t);
  3720. moveSelected (1);
  3721. });
  3722. menu.addSeparator();
  3723. menu.addItem (tr ("Delete") + "\tDel", [this, targets] { deleteTracks (targets); });
  3724. const auto room = (int) song.mixer.size() < maxMixerTracks;
  3725. menu.addItem (tr ("Insert one"), room, false, [this, t] {
  3726. engine.editSong ([t] (Song& s) { mixerops::insertTrack (s, t); });
  3727. setSelection ({ t }, t);
  3728. });
  3729. menu.addItem (tr ("Insert multiple..."), room, false, [this, t] { askInsertMultiple (t); });
  3730. juce::PopupMenu fromState;
  3731. for (const auto& f : mixerpresets::all())
  3732. fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, t, f] {
  3733. if (const auto added = mixerpresets::insertTrack (engine, t, f); added > 0)
  3734. setSelection ({ added }, added);
  3735. });
  3736. menu.addSubMenu (tr ("Insert from state"), fromState, room && fromState.getNumItems() > 0);
  3737. // FL's last section, "CPU" (REA round 134)
  3738. menu.addSectionHeader (tr ("CPU"));
  3739. menu.addItem (tr ("Allow threaded processing"), true, song.mixer[(std::size_t) t].threaded, [this, t] {
  3740. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].threaded = ! s.mixer[(std::size_t) t].threaded; });
  3741. });
  3742. }
  3743. menu.addSectionHeader (tr ("Mixer"));
  3744. {
  3745. // FL's Mixer › Disk recording (REA round 165f-mixer: FUN_012a7a80 / FUN_012a7d80)
  3746. std::vector<int> armed;
  3747. for (int x = 1; x < (int) song.mixer.size(); ++x)
  3748. if (engine.isInsertArmed (x))
  3749. armed.push_back (x);
  3750. juce::PopupMenu disk;
  3751. auto& eng = engine;
  3752. disk.addItem (tr ("Render armed tracks to wave file(s)...") + "\tAlt+R", ! armed.empty(), false, [armed, &eng] {
  3753. if (mixeroptions::renderTracks)
  3754. mixeroptions::renderTracks (armed, [armed, &eng] (const std::vector<juce::File>& files) {
  3755. if (eng.getRecordOptions().unarmAfterRender) // FL's "Auto-unarm" (round 166e)
  3756. for (auto t : armed)
  3757. eng.setInsertArmed (t, false);
  3758. if (eng.getRecordOptions().autoCreateClip) // FL's "Auto-create audio clip" (round 167a)
  3759. placeRenderedFiles (eng, files);
  3760. });
  3761. });
  3762. disk.addItem (tr ("Render selected tracks to wave file(s)...") + "\tShift+Alt+R", ! targets.empty(), false, [targets] {
  3763. if (mixeroptions::renderTracks)
  3764. mixeroptions::renderTracks (targets, {});
  3765. });
  3766. // FL's Disk recording "Options" (round 166e) and LYNX's own disarm after a take (issue #16)
  3767. disk.addSectionHeader (tr ("Options"));
  3768. const auto& ro = engine.getRecordOptions();
  3769. auto setRecord = [&eng] (std::function<void (AudioEngine::RecordOptions&)> change) {
  3770. auto o = eng.getRecordOptions();
  3771. change (o);
  3772. eng.setRecordOptions (o);
  3773. if (mixeroptions::changed)
  3774. mixeroptions::changed();
  3775. };
  3776. disk.addItem (tr ("Auto-unarm (rendering the armed tracks disarms them)"), true, ro.unarmAfterRender,
  3777. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.unarmAfterRender = ! r.unarmAfterRender; }); });
  3778. disk.addItem (tr ("Auto-create audio clip (the rendered files go on the Playlist)"), true, ro.autoCreateClip,
  3779. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.autoCreateClip = ! r.autoCreateClip; }); });
  3780. // FL's "Latency compensation" (RecLatCompMenu, checked by default; round 190dx): off, recorded takes are not moved
  3781. // back by the round trip, the fine adjust and the PDC (Options › Audio › Recording)
  3782. disk.addItem (tr ("Latency compensation"), true, ro.latencyCompensation,
  3783. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.latencyCompensation = ! r.latencyCompensation; }); });
  3784. disk.addItem (tr ("Disarm the inserts when recording stops"), true, ro.disarmOnStop,
  3785. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.disarmOnStop = ! r.disarmOnStop; }); });
  3786. // LYNX's own (round 190aq): also in the record button's menu
  3787. disk.addItem (tr ("Low latency while recording (bypasses effects that add latency on armed or monitored inserts)"), true, ro.lowLatencyRecording,
  3788. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.lowLatencyRecording = ! r.lowLatencyRecording; }); });
  3789. // FL's "Format" group (round 190bf, fl190be bonus shot): the recorded takes' sample format, radio items (the
  3790. // same setting as Options › Audio › Recording › File format)
  3791. disk.addSectionHeader (tr ("Format"));
  3792. {
  3793. const auto now = eng.getRecordingSettings().format;
  3794. const std::pair<takes::SampleFormat, const char*> formats[] { { takes::SampleFormat::pcm16, TR_NOOP ("16Bit int") },
  3795. { takes::SampleFormat::pcm24, TR_NOOP ("24Bit int") },
  3796. { takes::SampleFormat::float32, TR_NOOP ("32Bit float") } };
  3797. for (const auto& [format, name] : formats)
  3798. quickpick::addRadioItem (disk, tr (name), now == format, [&eng, format = format] {
  3799. auto r = eng.getRecordingSettings();
  3800. r.format = format;
  3801. eng.setRecordingSettings (r);
  3802. });
  3803. }
  3804. menu.addSubMenu (tr ("Disk recording"), disk);
  3805. juce::PopupMenu pdc;
  3806. const auto manual = std::count_if (song.mixer.begin(), song.mixer.end(), [] (const MixerTrack& m) { return m.latencyMs != 0.0f; });
  3807. // FL's first item (SetupPDCMenuClick → FUN_012a3880(1, 1), round 190fl): every track's manual latency back to
  3808. // 0 without the warning box; the compensation then comes from the plugins again
  3809. pdc.addItem (tr ("Set for all tracks"), [this] { engine.editSong ([] (Song& s) { mixerops::setPdcForAllTracks (s); }); });
  3810. pdc.addItem (tr ("Reset manual latency on all tracks"), manual > 0, false, [this] {
  3811. juce::AlertWindow::showOkCancelBox (juce::MessageBoxIconType::WarningIcon, tr ("Warning"),
  3812. tr ("This will reset manual latency values on all mixer tracks."), tr ("OK"), tr ("Cancel"), nullptr,
  3813. juce::ModalCallbackFunction::create ([this] (int r) {
  3814. if (r == 1)
  3815. engine.editSong ([] (Song& s) { mixerops::resetManualLatency (s); });
  3816. }));
  3817. });
  3818. // FL's Automatic / Compensate automations (REA round 168j, .flp 0x1D / 0x27; FL's AutoPDCMenuClick toggles it)
  3819. pdc.addItem (tr ("Automatic (compensate the plugins' latencies)"), true, song.autoPdc,
  3820. [this] { engine.editSong ([] (Song& s) { s.autoPdc = ! s.autoPdc; }); });
  3821. pdc.addItem (tr ("Compensate automations (delay a plugin's automation with its audio)"), true, song.compensateAutomations,
  3822. [this] { engine.editSong ([] (Song& s) { s.compensateAutomations = ! s.compensateAutomations; }); });
  3823. // round 190hq (LYNX extra, Song::compensateMixerLevels): the faders, pans, route levels and VCA faders too
  3824. pdc.addItem (tr ("Compensate fader and route automations too (LYNX)"), song.compensateAutomations, song.compensateMixerLevels,
  3825. [this] { engine.editSong ([] (Song& s) { s.compensateMixerLevels = ! s.compensateMixerLevels; }); });
  3826. menu.addSubMenu (tr ("Plugin delay compensation"), pdc);
  3827. }
  3828. menu.addSubMenu (tr ("Mixer layout"), MixerLayoutBox::menu (*this)); // as the title bar's drop-down (issue #52)
  3829. mixeroptions::addItems (menu, engine, false);
  3830. return menu;
  3831. }
  3832. void MixerStrips::changeListenerCallback (juce::ChangeBroadcaster*)
  3833. {
  3834. // only levels moved since the last call (a fader / knob drag, AudioEngine::editLevels; round 171c): repaint just
  3835. // the strips whose fader, pan or separation changed instead of the whole mixer at every mouse move
  3836. const auto& mixer = engine.getSong().mixer;
  3837. if (engine.getPublishCount() == seenPublish && shownLevels.size() == mixer.size())
  3838. {
  3839. const auto& vcas = engine.getSong().vcas;
  3840. if (vcaLevelsShown.size() == vcas.size())
  3841. for (std::size_t i = 0; i < vcas.size(); ++i)
  3842. if (vcas[i].level != vcaLevelsShown[i])
  3843. {
  3844. vcaLevelsShown[i] = vcas[i].level;
  3845. repaintVca ((int) i);
  3846. }
  3847. for (std::size_t t = 0; t < mixer.size(); ++t)
  3848. {
  3849. const std::array<float, 3> now { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
  3850. if (now != shownLevels[t])
  3851. {
  3852. // round 173f: just the control that moved (the fader with its cap and dB read-out, or a knob)
  3853. const auto track = (int) t;
  3854. if (now[0] != shownLevels[t][0])
  3855. {
  3856. const auto fader = faderArea (track);
  3857. repaint (stripX (track), fader.getY() - 9, stripWidthOf (track), fader.getHeight() + 9 + 20);
  3858. }
  3859. if (now[1] != shownLevels[t][1])
  3860. repaint (panArea (track).expanded (2));
  3861. if (now[2] != shownLevels[t][2])
  3862. repaint (stereoArea (track).expanded (2));
  3863. shownLevels[t] = now;
  3864. }
  3865. }
  3866. return;
  3867. }
  3868. seenPublish = engine.getPublishCount();
  3869. // "Mixer groups follow the Playlist" (round 186c): a Playlist group edit regroups the mixer, outside the undo history
  3870. // (an undo of the Playlist edit brings the old groups back through this same path)
  3871. if (followPlaylist && ! followPending)
  3872. {
  3873. if (! mixerops::followsPlaylistGroups (engine.getSong()))
  3874. {
  3875. followPending = true;
  3876. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<MixerStrips> (this)] {
  3877. if (safe == nullptr)
  3878. return;
  3879. safe->engine.editSong ([] (Song& s) { mixerops::followPlaylistGroups (s); }, false);
  3880. safe->followPending = false;
  3881. });
  3882. }
  3883. }
  3884. vcaLevelsShown.clear();
  3885. for (const auto& vca : engine.getSong().vcas)
  3886. vcaLevelsShown.push_back (vca.level);
  3887. shownLevels.resize (mixer.size());
  3888. for (std::size_t t = 0; t < mixer.size(); ++t)
  3889. shownLevels[t] = { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
  3890. selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), selected);
  3891. const auto count = (int) engine.getSong().mixer.size();
  3892. selection.erase (std::remove_if (selection.begin(), selection.end(), [count] (int t) { return t >= count; }), selection.end());
  3893. if (! std::binary_search (selection.begin(), selection.end(), selected))
  3894. selection = { selected };
  3895. updateSize();
  3896. repaint();
  3897. }
  3898. float MixerStrips::shownVolume (int t) const
  3899. {
  3900. const auto& mixer = engine.getSong().mixer;
  3901. const auto base = t >= 0 && t < (int) mixer.size() ? mixer[(std::size_t) t].volume : 0.0f;
  3902. return engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerVolume, t }, base);
  3903. }
  3904. void MixerStrips::repaintAutomatedStrips()
  3905. {
  3906. // faders, pan and send knobs follow their automation while the song plays (issue #12): only the automated controls
  3907. // repaint, and only when the value they show changed (round 174e: just the fader column or the knob, not the strip)
  3908. const auto& shown = engine.getAutomationDisplay();
  3909. if (shown.getGeneration() == shownAutomation)
  3910. return;
  3911. shownAutomation = shown.getGeneration();
  3912. std::vector<int> strips;
  3913. sendAutomatedStrips.clear();
  3914. for (const auto& t : shown.automatedTargets())
  3915. {
  3916. if (t.kind == AutomationTargetKind::mixerVolume || t.kind == AutomationTargetKind::mixerPan)
  3917. strips.push_back (t.index);
  3918. else if (t.kind == AutomationTargetKind::mixerSend && t.index == selected)
  3919. {
  3920. strips.push_back (t.slot); // (the route knob sits under the destination)
  3921. sendAutomatedStrips.push_back (t.slot);
  3922. }
  3923. else if (t.kind == AutomationTargetKind::vcaLevel && isShowing())
  3924. repaintVca (t.index);
  3925. }
  3926. std::vector<int> all = strips;
  3927. all.insert (all.end(), automatedStrips.begin(), automatedStrips.end());
  3928. automatedStrips = std::move (strips);
  3929. if (! isShowing())
  3930. return;
  3931. std::sort (all.begin(), all.end());
  3932. all.erase (std::unique (all.begin(), all.end()), all.end());
  3933. const auto& mixer = engine.getSong().mixer;
  3934. const auto count = (int) mixer.size();
  3935. automatedShown.resize (mixer.size(), { -1.0f, -1.0f });
  3936. for (const auto t : all)
  3937. {
  3938. if (t < 0 || t >= count || isHidden (t) || isFoldTab (t)) // (a folded member has no control on screen to move)
  3939. continue;
  3940. const std::array<float, 2> now { shownVolume (t),
  3941. shown.shown (AutomationTarget { AutomationTargetKind::mixerPan, t }, (mixer[(std::size_t) t].pan + 1.0f) * 0.5f) };
  3942. auto& was = automatedShown[(std::size_t) t];
  3943. if (now[0] != was[0])
  3944. {
  3945. // round 174e2: the cap's rail when the cap moved by an eighth of a pixel, the dB readout when its text changed
  3946. // (not the strip's whole column: the meters beside it stay in the cached picture)
  3947. const auto rail = faderRail (t);
  3948. const auto pixels = [&rail] (float v) { return juce::roundToInt (v * (float) rail.getHeight() * 8.0f); };
  3949. if (was[0] < 0.0f || pixels (now[0]) != pixels (was[0]))
  3950. repaint (rail.getX() - 3, rail.getY() - 9, rail.getWidth() + 6, rail.getHeight() + 18);
  3951. if (spec().dbReadout && (was[0] < 0.0f || faderToDb (now[0]) != faderToDb (was[0])))
  3952. repaint (stripX (t), faderArea (t).getBottom() + 3, stripWidthOf (t) - spec().gap, 14);
  3953. }
  3954. if (now[1] != was[1])
  3955. repaint (panArea (t).expanded (2));
  3956. if (std::find (sendAutomatedStrips.begin(), sendAutomatedStrips.end(), t) != sendAutomatedStrips.end())
  3957. repaint (routeArea (t).expanded (2)); // (a send knob: small; round 174e2: only when a send is automated)
  3958. was = now;
  3959. }
  3960. }
  3961. namespace
  3962. {
  3963. // issue #144: a silenced track's meter colours (FL draws them darker and greyer)
  3964. juce::Colour silencedMeterColour (juce::Colour c) { return c.withMultipliedSaturation (0.55f).withMultipliedBrightness (0.62f); }
  3965. } // namespace
  3966. // The two thin level bars beside a vertical name (Wide layouts); empty when the layout has none
  3967. juce::Rectangle<int> MixerStrips::nameBars (int t) const
  3968. {
  3969. const auto& sp = spec();
  3970. if (! sp.verticalName || sp.nameLow || mixerlayout::isCompact (layout) || t <= 0)
  3971. return {};
  3972. const auto box = nameArea (t);
  3973. const auto plateWidth = stripWidthOf (t) - sp.gap;
  3974. return { box.getRight() + 2, box.getY() + 6, plateWidth - box.getWidth() - 6, box.getHeight() - 12 };
  3975. }
  3976. void MixerStrips::paintNameBars (juce::Graphics& g, int t) const
  3977. {
  3978. using namespace theme;
  3979. const auto bars = nameBars (t);
  3980. for (int ch = 0; ch < 2; ++ch)
  3981. {
  3982. const auto index = (std::size_t) t * 2 + (std::size_t) ch;
  3983. const auto level = index < levels.size() ? levels[index].level : 0.0f;
  3984. const auto bw = (bars.getWidth() - 3) / 2;
  3985. const auto bar = juce::Rectangle<int> (bars.getX() + 1 + ch * (bw + 1), bars.getY() + 1, bw, bars.getHeight() - 2);
  3986. const auto h = (int) (meterPosition (level) * (float) bar.getHeight());
  3987. if (h <= 0)
  3988. continue;
  3989. const auto c = level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow;
  3990. g.setColour (isSilenced (t) ? silencedMeterColour (c) : c); // (issue #144: dimmed while silenced)
  3991. g.fillRect (bar.withTop (bar.getBottom() - h));
  3992. }
  3993. }
  3994. // Issue #144: a silenced track (its mute, a solo elsewhere, a muted VCA) keeps its meter, dimmed, as FL draws it
  3995. bool MixerStrips::isSilenced (int t) const
  3996. {
  3997. const auto& song = engine.getSong();
  3998. if (t < 0 || t >= (int) song.mixer.size())
  3999. return false;
  4000. if (song.mixer[(std::size_t) t].muted)
  4001. return true;
  4002. if (t == 0)
  4003. return false;
  4004. if (mixerops::vcaMuted (song, t))
  4005. return true;
  4006. if (std::none_of (song.mixer.begin(), song.mixer.end(), [] (const MixerTrack& m) { return m.solo; }))
  4007. return false;
  4008. const auto audible = song.soloAudible();
  4009. return (std::size_t) t < audible.size() && ! audible[(std::size_t) t];
  4010. }
  4011. // --- the loudness panel beside the Master (round 190am, LYNX's own; Mixer menu, off by default) -----------------------
  4012. namespace
  4013. {
  4014. constexpr float loudnessBarTop = 0.0f, loudnessBarBottom = -42.0f; // LUFS at the bar's ends
  4015. float loudnessBarPosition (float lufs) noexcept
  4016. {
  4017. return juce::jlimit (0.0f, 1.0f, (lufs - loudnessBarBottom) / (loudnessBarTop - loudnessBarBottom));
  4018. }
  4019. constexpr int loudnessRowsTop = 24, loudnessRowHeight = 16;
  4020. } // namespace
  4021. void MixerStrips::setShowLoudness (bool on)
  4022. {
  4023. showLoudness = on;
  4024. engine.getMeters().loudness.setEnabled (on); // (off: the audio thread measures nothing)
  4025. loudnessShown = {};
  4026. updateSize();
  4027. repaint();
  4028. }
  4029. void MixerStrips::resetLoudness()
  4030. {
  4031. engine.getMeters().loudness.reset();
  4032. loudnessShown = {};
  4033. repaint (loudnessArea());
  4034. }
  4035. juce::Rectangle<int> MixerStrips::loudnessArea() const noexcept
  4036. {
  4037. if (! showLoudness || loudnessX == hiddenX)
  4038. return {};
  4039. return { loudnessX + pinOffset (dockOf (0)), 2, loudnessWidth - spec().gap, laneTop() - 2 };
  4040. }
  4041. juce::Rectangle<int> MixerStrips::loudnessResetArea() const noexcept
  4042. {
  4043. const auto area = loudnessArea();
  4044. if (area.isEmpty())
  4045. return {};
  4046. return { area.getX() + 4, rows().faderBottom + 3, area.getWidth() - 8, 15 };
  4047. }
  4048. juce::Rectangle<int> MixerStrips::loudnessBarArea() const noexcept
  4049. {
  4050. const auto area = loudnessArea();
  4051. const auto r = rows();
  4052. return { area.getX() + 6, r.faderTop, 8, r.faderBottom - r.faderTop };
  4053. }
  4054. void MixerStrips::paintLoudnessPanel (juce::Graphics& g) const
  4055. {
  4056. using namespace theme;
  4057. const auto area = loudnessArea();
  4058. theme::fillRoundRect (g, area.toFloat(), radius::md, colour::bg2);
  4059. g.setColour (colour::border);
  4060. g.drawRoundedRectangle (area.toFloat().reduced (0.5f), radius::md, 1.0f);
  4061. g.setColour (colour::textSecondary);
  4062. g.setFont (font (type::caption, true));
  4063. textcache::drawFittedText (g, "LUFS", juce::Rectangle<int> (area.getX(), 4, area.getWidth(), 13), juce::Justification::centred, 1, 0.7f);
  4064. // the captions of the three values (EBU R 128's letters; the hint bar spells them out)
  4065. g.setFont (font (9.0f, true));
  4066. const char* captions[] = { "S", "I", "TP" };
  4067. for (int i = 0; i < 3; ++i)
  4068. textcache::drawText (g, captions[i], juce::Rectangle<int> (area.getX() + 5, loudnessRowsTop + i * loudnessRowHeight, 14, loudnessRowHeight),
  4069. juce::Justification::centredLeft, false);
  4070. // the short-term bar's well and scale (LUFS, 6 LU apart, as many as fit)
  4071. const auto bar = loudnessBarArea();
  4072. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  4073. g.setFont (font (9.0f));
  4074. const auto textHeight = 10.0f;
  4075. auto lastY = -100.0f;
  4076. for (int lufs = 0; lufs >= (int) loudnessBarBottom; lufs -= 6)
  4077. {
  4078. const auto y = (float) bar.getBottom() - loudnessBarPosition ((float) lufs) * (float) bar.getHeight();
  4079. if (y - lastY < textHeight + 1.0f)
  4080. continue;
  4081. lastY = y;
  4082. g.setColour (colour::textSecondary);
  4083. g.fillRect (juce::Rectangle<float> ((float) bar.getRight() + 1.0f, y - 0.5f, 3.0f, 1.0f));
  4084. const auto box = juce::Rectangle<float> ((float) bar.getRight() + 5.0f, y - textHeight * 0.5f, (float) (area.getRight() - bar.getRight()) - 9.0f, textHeight)
  4085. .withY (juce::jlimit ((float) bar.getY(), (float) bar.getBottom() - textHeight, y - textHeight * 0.5f));
  4086. textcache::drawText (g, juce::String (lufs), box, juce::Justification::centredRight, false);
  4087. }
  4088. // Reset
  4089. const auto reset = loudnessResetArea().toFloat();
  4090. theme::fillRoundRect (g, reset, radius::sm, loudnessResetHovered ? colour::bg5 : colour::bg0);
  4091. g.setColour (loudnessResetHovered ? colour::textPrimary : colour::textSecondary);
  4092. g.setFont (font (type::caption));
  4093. textcache::drawFittedText (g, tr ("Reset"), reset.toNearestInt().reduced (2, 0), juce::Justification::centred, 1, 0.6f);
  4094. }
  4095. void MixerStrips::paintLoudnessValues (juce::Graphics& g) const
  4096. {
  4097. using namespace theme;
  4098. const auto area = loudnessArea();
  4099. const auto& v = loudnessShown;
  4100. const float values[] = { v.shortTerm, v.integrated, v.truePeak };
  4101. g.setFont (font (type::small, true));
  4102. for (int i = 0; i < 3; ++i)
  4103. {
  4104. const auto known = MasterLoudness::measured (values[i]);
  4105. // the true peak warns like the peak meters: amber from -1 dBTP, red above 0 dBTP
  4106. g.setColour (! known ? colour::textDisabled
  4107. : i == 2 && values[i] > 0.0f ? colour::meterClip : i == 2 && values[i] > -1.0f ? colour::meterMid : colour::textPrimary);
  4108. textcache::drawFittedText (g, juce::String (formatLoudness (values[i])),
  4109. juce::Rectangle<int> (area.getX() + 18, loudnessRowsTop + i * loudnessRowHeight, area.getWidth() - 23, loudnessRowHeight),
  4110. juce::Justification::centredRight, 1, 0.7f);
  4111. }
  4112. const auto bar = loudnessBarArea();
  4113. if (MasterLoudness::measured (v.shortTerm))
  4114. {
  4115. const auto h = juce::roundToInt (loudnessBarPosition (v.shortTerm) * (float) bar.getHeight());
  4116. g.setColour (colour::meterLow);
  4117. g.fillRect (bar.withTop (bar.getBottom() - h).reduced (1, 0));
  4118. }
  4119. if (MasterLoudness::measured (v.integrated)) // the integrated loudness: a line across the bar
  4120. {
  4121. const auto y = (float) bar.getBottom() - loudnessBarPosition (v.integrated) * (float) bar.getHeight();
  4122. g.setColour (colour::textPrimary);
  4123. g.fillRect (juce::Rectangle<float> ((float) bar.getX() - 2.0f, y - 1.0f, (float) bar.getWidth() + 4.0f, 2.0f));
  4124. }
  4125. }
  4126. void MixerStrips::showLoudnessMenu()
  4127. {
  4128. juce::PopupMenu menu;
  4129. menu.addItem (tr ("Reset"), [this] { resetLoudness(); });
  4130. menu.addSeparator();
  4131. menu.addItem (tr ("Loudness meter beside the Master (LYNX)"), true, true, [] {
  4132. if (mixeroptions::setShowLoudness)
  4133. mixeroptions::setShowLoudness (false);
  4134. if (mixeroptions::changed)
  4135. mixeroptions::changed();
  4136. });
  4137. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  4138. }
  4139. // One meter's level, peak hold line and clip latch, inside its well (painted with the strip, or over the cached picture)
  4140. void MixerStrips::paintMeterLevel (juce::Graphics& g, int t, int ch, juce::Rectangle<int> bar) const
  4141. {
  4142. using namespace theme;
  4143. const auto index = (std::size_t) t * 2 + (std::size_t) ch;
  4144. const auto meter = index < levels.size() ? levels[index] : meters::PeakHold {};
  4145. const auto h = (int) (meterPosition (meter.level) * (float) bar.getHeight());
  4146. const auto silenced = (h > 0 || meter.peak > 0.001f) && isSilenced (t);
  4147. const auto tone = [silenced] (juce::Colour c) { return silenced ? silencedMeterColour (c) : c; };
  4148. if (h > 0)
  4149. {
  4150. const auto lit = bar.withTop (bar.getBottom() - h);
  4151. // (vertical: every meter of the same height shares one gradient, so JUCE's Direct2D brush cache hits)
  4152. juce::ColourGradient gradient (tone (colour::meterClip), 0.0f, (float) bar.getY(), tone (colour::meterLow), 0.0f, (float) bar.getBottom(), false);
  4153. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (0.0f)), tone (colour::meterClip)); // above 0 dB: clip zone
  4154. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-6.0f)), tone (colour::meterMid));
  4155. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-18.0f)), tone (colour::meterLow));
  4156. g.setGradientFill (gradient);
  4157. g.fillRect (lit);
  4158. }
  4159. if (meter.peak > 0.001f) // peak hold line
  4160. {
  4161. const auto peakY = bar.getBottom() - (int) (meterPosition (meter.peak) * (float) bar.getHeight());
  4162. // FL's peak tick is in the meter's own colour (its lime; details190if fl-mixer-meters-strips-3frames.png; round 190io),
  4163. // orange above about -3 dB (live check 190iw Q6, round 190jd)
  4164. g.setColour (tone (meter.peak >= 1.0f ? colour::meterClip : meter.peak >= meters::flTickOrange ? colour::meterMid : colour::meterLow));
  4165. g.fillRect (bar.getX(), juce::jmax (bar.getY(), peakY - 1), bar.getWidth(), 2);
  4166. }
  4167. if (meter.clipped) // clip latch: stays until the meter is clicked
  4168. {
  4169. g.setColour (colour::meterClip);
  4170. g.fillRect (bar.withHeight (4));
  4171. }
  4172. }
  4173. // The levels over the cached picture: every meter the clip reaches, except where a pinned dock block covers a scrolled
  4174. // strip (paint() draws the pinned blocks over the middle one)
  4175. void MixerStrips::paintMeterLevels (juce::Graphics& g) const
  4176. {
  4177. const auto clip = g.getClipBounds();
  4178. const auto& sp = spec();
  4179. std::vector<juce::Rectangle<int>> pinned;
  4180. for (auto dock : { MixerDock::left, MixerDock::right })
  4181. if (const auto shift = pinOffset (dock); shift != 0)
  4182. {
  4183. const auto d = (int) dock;
  4184. pinned.emplace_back (blockStart[d] + shift, 0, blockEnd[d] - blockStart[d], getHeight());
  4185. }
  4186. const auto tracks = (int) engine.getSong().mixer.size();
  4187. for (int t = 0; t < tracks; ++t)
  4188. {
  4189. if (isHidden (t))
  4190. continue;
  4191. if (isFoldTab (t)) // (a folded group's tab: one bar, and no meter of its own)
  4192. {
  4193. const auto rail = faderRail (t);
  4194. if (const juce::Rectangle<int> bar (stripX (t), rail.getY(), foldTabWidth, rail.getHeight()); bar.intersects (clip))
  4195. {
  4196. const juce::Graphics::ScopedSaveState state (g);
  4197. if (dockOf (t) == MixerDock::middle)
  4198. for (const auto& r : pinned)
  4199. g.excludeClipRegion (r);
  4200. paintFoldTabLevel (g, t);
  4201. }
  4202. continue;
  4203. }
  4204. const auto meters = meterArea (t);
  4205. const auto bars = nameBars (t);
  4206. const auto meterShown = meters.intersects (clip) && g.clipRegionIntersects (meters);
  4207. const auto barsShown = ! bars.isEmpty() && bars.intersects (clip) && g.clipRegionIntersects (bars);
  4208. if (! meterShown && ! barsShown)
  4209. continue;
  4210. const juce::Graphics::ScopedSaveState state (g);
  4211. if (dockOf (t) == MixerDock::middle)
  4212. for (const auto& r : pinned)
  4213. g.excludeClipRegion (r);
  4214. if (meterShown)
  4215. for (int ch = 0; ch < 2; ++ch)
  4216. paintMeterLevel (g, t, ch, juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight()));
  4217. if (barsShown)
  4218. paintNameBars (g, t);
  4219. }
  4220. for (int i = 0; i < (int) vcaXs.size(); ++i)
  4221. if (meterArea (vcaStrip (i)).intersects (clip))
  4222. {
  4223. const juce::Graphics::ScopedSaveState state (g);
  4224. if (dockOf (0) == MixerDock::middle) // (the VCA block sits in the Master's dock)
  4225. for (const auto& r : pinned)
  4226. g.excludeClipRegion (r);
  4227. paintVcaMeter (g, i);
  4228. }
  4229. if (showLoudness && loudnessArea().intersects (clip))
  4230. {
  4231. const juce::Graphics::ScopedSaveState state (g);
  4232. if (dockOf (0) == MixerDock::middle)
  4233. for (const auto& r : pinned)
  4234. g.excludeClipRegion (r);
  4235. paintLoudnessValues (g);
  4236. }
  4237. }
  4238. bool MixerStrips::liveFrame (double nowMs)
  4239. {
  4240. auto& meters = engine.getMeters();
  4241. const auto showing = isShowing();
  4242. repaintAutomatedStrips();
  4243. const auto elapsed = lastFrameMs > 0.0 ? juce::jlimit (0.0, 250.0, nowMs - lastFrameMs) : 1000.0 / 30.0;
  4244. lastFrameMs = nowMs;
  4245. const auto& mixer = engine.getSong().mixer;
  4246. inputLevels.resize (mixer.size(), 0.0f);
  4247. auto moving = engine.getTransport().playing.load (std::memory_order_relaxed);
  4248. const auto inputFall = ui::fallFor (0.8f, elapsed);
  4249. for (std::size_t t = 1; t < mixer.size(); ++t)
  4250. {
  4251. const auto peak = mixer[t].inputChannel >= 0 ? juce::jmax (engine.takeInputPeak ((int) t, 0), engine.takeInputPeak ((int) t, 1)) : 0.0f;
  4252. auto level = juce::jmax (peak, inputLevels[t] * inputFall);
  4253. level = level < 1e-4f ? 0.0f : level;
  4254. if (std::abs (level - inputLevels[t]) > 1e-4f)
  4255. {
  4256. moving = true;
  4257. inputLevels[t] = level;
  4258. if (showing)
  4259. repaint (inputArea ((int) t).expanded (1));
  4260. }
  4261. }
  4262. // round 177d: the gain-reduction meters (strips with one of LYNX's own dynamics only; nothing while hidden)
  4263. if (showing)
  4264. {
  4265. grShown.resize (mixer.size(), -1);
  4266. for (int t = 1; t < (int) mixer.size(); ++t)
  4267. {
  4268. const auto gr = gainReduction (t);
  4269. const auto h = gr < 0.0f ? -1 : juce::roundToInt (gr * (float) grArea (t).getHeight());
  4270. if (h != grShown[(std::size_t) t])
  4271. {
  4272. grShown[(std::size_t) t] = h;
  4273. repaint (grArea (t).expanded (1));
  4274. }
  4275. moving = moving || h > 0;
  4276. }
  4277. }
  4278. // every meter row that changed by a pixel goes into one rectangle, repainted once per frame (round 174e2: the A/B
  4279. // against one repaint per meter favoured the single rectangle, within the noise of the machine)
  4280. juce::Rectangle<int> dirty;
  4281. int woken = -1;
  4282. for (std::size_t i = 0; i < levels.size(); ++i)
  4283. {
  4284. auto& m = levels[i];
  4285. const auto before = m;
  4286. const auto peak = meters.takePeak ((int) (i / 2), (int) (i % 2));
  4287. m.advanceFl (peak, elapsed); // ~20 dB/s bar falloff; FL's 2.6 s peak hold, then an accelerating fall (round 190jd)
  4288. // "Show only used inserts" (round 190am): an insert that receives audio always shows, whatever feeds it
  4289. if (showUsedOnly && peak > 1.0e-4f && i >= 2 && revealed.count ((int) (i / 2)) == 0 && isHidden ((int) (i / 2)))
  4290. woken = (int) (i / 2);
  4291. if (m.level != before.level || m.peak != before.peak)
  4292. moving = true;
  4293. if (! showing)
  4294. continue;
  4295. // only the rows of the meter that changed by a pixel are repainted (round 174e: at the display's rate), and in
  4296. // the Wide layouts the two thin bars beside the name, which follow the same level (round 173f)
  4297. const auto t = (int) (i / 2);
  4298. const auto ch = (int) (i % 2);
  4299. if (t < (int) tabOf.size() && tabOf[(std::size_t) t] > 0 && m.level != before.level) // a folded group's tab
  4300. {
  4301. const auto tab = tabOf[(std::size_t) t];
  4302. const auto rail = faderRail (tab);
  4303. const juce::Rectangle<int> bar (stripX (tab) + foldTabWidth - 10, rail.getY() - 1, 8, rail.getHeight() + 2);
  4304. dirty = dirty.isEmpty() ? bar : dirty.getUnion (bar);
  4305. }
  4306. if (isHidden (t) || isFoldTab (t))
  4307. continue;
  4308. const auto area = meterArea (t);
  4309. const auto& sp = spec();
  4310. const auto rows = meters::dirtyRows (before, m, area.getHeight(), [] (float v) { return meterPosition (v); });
  4311. if (! rows.empty())
  4312. {
  4313. const juce::Rectangle<int> bar (area.getX() + ch * (sp.meterWidth + 2) - 1, area.getY() + rows.top - 1, sp.meterWidth + 2,
  4314. rows.bottom - rows.top + 2);
  4315. dirty = dirty.isEmpty() ? bar : dirty.getUnion (bar);
  4316. // the thin bars beside the name: only the bar that moved, and (cached) over the picture as well (round 174e2)
  4317. if (const auto bars = nameBars (t); ! bars.isEmpty()
  4318. && (int) (meterPosition (m.level) * 64.0f) != (int) (meterPosition (before.level) * 64.0f))
  4319. {
  4320. const auto bw = (bars.getWidth() - 3) / 2;
  4321. dirty = dirty.getUnion ({ bars.getX() + 1 + ch * (bw + 1) - 1, bars.getY(), bw + 2, bars.getHeight() });
  4322. }
  4323. }
  4324. }
  4325. // the VCA strips' meters show their loudest member (round 177a; nothing to do without a VCA)
  4326. if (const auto count = engine.getSong().vcas.size(); count > 0 && showing)
  4327. {
  4328. vcaMetersShown.resize (count * 2, 0.0f);
  4329. for (int i = 0; i < (int) count; ++i)
  4330. for (int ch = 0; ch < 2; ++ch)
  4331. {
  4332. const auto level = vcaMeter (i, ch);
  4333. auto& was = vcaMetersShown[(std::size_t) i * 2 + (std::size_t) ch];
  4334. if ((int) (meterPosition (level) * 256.0f) != (int) (meterPosition (was) * 256.0f))
  4335. {
  4336. const auto area = meterArea (vcaStrip (i)).expanded (1);
  4337. dirty = dirty.isEmpty() ? area : dirty.getUnion (area);
  4338. }
  4339. was = level;
  4340. }
  4341. }
  4342. // the loudness panel (round 190am; nothing while it is off): repainted when a shown number or the bar changes
  4343. if (showLoudness && showing)
  4344. if (const auto now = meters.loudness.read(); ! (now == loudnessShown))
  4345. {
  4346. const auto same = [] (float a, float b) { return formatLoudness (a) == formatLoudness (b); };
  4347. const auto changed = ! same (now.shortTerm, loudnessShown.shortTerm) || ! same (now.integrated, loudnessShown.integrated)
  4348. || ! same (now.truePeak, loudnessShown.truePeak);
  4349. loudnessShown = now;
  4350. if (changed)
  4351. {
  4352. const auto area = loudnessArea();
  4353. dirty = dirty.isEmpty() ? area : dirty.getUnion (area);
  4354. }
  4355. }
  4356. if (! dirty.isEmpty())
  4357. {
  4358. meterRepaintOnly = meterCacheOn; // (the cached picture under the meters stays valid: they are drawn over it)
  4359. repaint (dirty);
  4360. meterRepaintOnly = false;
  4361. }
  4362. if (woken > 0) // (one per frame is enough: the next frame brings the next)
  4363. {
  4364. revealed.insert (woken);
  4365. updateSize();
  4366. repaint();
  4367. }
  4368. return moving;
  4369. }
  4370. // ---------------------------------------------------------------------------
  4371. namespace
  4372. {
  4373. constexpr int panelHeader = 30;
  4374. constexpr int inputRowHeight = 30; // the input row (arm, audio input source) above the slots
  4375. constexpr int slotsTop = panelHeader + inputRowHeight;
  4376. constexpr int slotHeight = 24;
  4377. const EffectKind allEffects[] = { EffectKind::eq, EffectKind::parametricEq, EffectKind::facetEq, EffectKind::compressor, EffectKind::limiter, EffectKind::apexLimiter,
  4378. EffectKind::delay, EffectKind::reverb, EffectKind::chorus, EffectKind::filter,
  4379. EffectKind::distortion, EffectKind::utility, EffectKind::volumeGate,
  4380. EffectKind::pitchShift, EffectKind::freqShift, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::frequencySplitter, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect,
  4381. EffectKind::ridgeStrip, EffectKind::glowLeveler, EffectKind::hushDeEsser, EffectKind::aether, EffectKind::ember, EffectKind::kilnChannel, EffectKind::fretChannel, EffectKind::shellChannel, EffectKind::strikeShaper, EffectKind::anvilBus, EffectKind::corrode, EffectKind::soundboard, EffectKind::platter, // LYNX's mixing suite
  4382. EffectKind::lynxTune, // LYNX's own pitch corrector
  4383. EffectKind::epochVerb, EffectKind::atrium, EffectKind::foilPlate, EffectKind::nebula, EffectKind::halo, EffectKind::horizon, // LYNX's reverbs
  4384. EffectKind::echoform, EffectKind::spiralEcho, EffectKind::orbit, EffectKind::latticeMod, // LYNX's delay / modulation suite
  4385. EffectKind::crestCompressor, EffectKind::prismMultiband, EffectKind::sentryGate, // LYNX's dynamics suite
  4386. EffectKind::quellDenoiser, EffectKind::geminiDoubler, EffectKind::voiceShift, // LYNX's voice tools
  4387. EffectKind::pocketDistortion, EffectKind::pocketLimiterClassic, EffectKind::pocketLimiter, EffectKind::pocketLeveller,
  4388. EffectKind::pocketGate, EffectKind::pocketTranceDelay, EffectKind::pocketTapeDelay, EffectKind::pocketMultiFx, // Pocket: FL Studio Mobile's effects (round 188h)
  4389. EffectKind::pocketAutoduck, EffectKind::pocketChorus, EffectKind::pocketSpacer, EffectKind::pocketStereoizer, // Pocket (round 189h)
  4390. EffectKind::pocketWowFlutter, EffectKind::pocketPhaser, EffectKind::pocketFlanger, EffectKind::pocketTremolo, // Pocket (round 189h)
  4391. EffectKind::pocketWaveshaper, EffectKind::pocketCompressor, EffectKind::pocketSpreader, // Pocket (round 189h)
  4392. EffectKind::pocketComb, // Pocket (round 190by)
  4393. EffectKind::pocketMultiband, // Pocket (round 190by)
  4394. EffectKind::pocketTapeStop, // Pocket (round 190by)
  4395. EffectKind::pocketEq, EffectKind::pocketGraphicEq, EffectKind::pocketFilter, // Pocket (round 190dw)
  4396. EffectKind::pocketReverbClassic, EffectKind::pocketReverb2, EffectKind::pocketReverb, // Pocket (round 190dw)
  4397. EffectKind::formulaController, EffectKind::peakController, EffectKind::xyController, EffectKind::xyzController,
  4398. EffectKind::controlSurface, // controllers (link their output to any knob)
  4399. EffectKind::patcher, // FL's Patcher: a graph of effects / instruments / plugins (REA_rodada141)
  4400. EffectKind::hardwareInsert, // outboard gear through device outputs / inputs, pinged round trip (round 164d)
  4401. EffectKind::fruityLimiter, EffectKind::fruityCompressor,
  4402. EffectKind::fruityWaveShaper, EffectKind::fruitySoftClipper,
  4403. EffectKind::reeverb2, EffectKind::reeverb1,
  4404. EffectKind::fruityDelay2, EffectKind::fruityDelay3,
  4405. EffectKind::stereoShaper, EffectKind::stereoEnhancer, EffectKind::transientProcessor,
  4406. EffectKind::spreader, EffectKind::fruityChorus, EffectKind::hyperChorus, EffectKind::vintageChorus,
  4407. EffectKind::fruityPanOMatic, EffectKind::fruityBalance, EffectKind::fruityBloodOverdrive, EffectKind::fruitySend,
  4408. EffectKind::fruityDelayBank, EffectKind::fruityMultiband,
  4409. EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::fruityPhaser, EffectKind::luxeVerb,
  4410. EffectKind::fruityFastLP, EffectKind::fruityFreeFilter, EffectKind::fruityFilter,
  4411. EffectKind::hardcore,
  4412. EffectKind::multibandDelay, EffectKind::emphasizer, EffectKind::flEmphasis, EffectKind::flFrequencyShifter, EffectKind::flLowLifter,
  4413. EffectKind::flPhaseInverter, EffectKind::flCenter, EffectKind::flBassBoost, EffectKind::fl7BandEq, EffectKind::flDelay1, // round 165k
  4414. EffectKind::waveCandy, EffectKind::visualizer, // visual plugins (round 164c)
  4415. EffectKind::fruityMute2, EffectKind::bigClock, EffectKind::tuner, EffectKind::htmlNotebook, // round 165g
  4416. EffectKind::scratcher, // round 165g (flscratch165): FL's turntable
  4417. EffectKind::transmitter, // round 165g (fltrans165): FL's transient / sustain splitter
  4418. EffectKind::flTransporter, // round 167f: FL's transient looper, exact
  4419. // FL engines that need more than their parameters (round 142, issue #5): a new one starts from
  4420. // the plugin's Default preset of the user's FL installation (core/NativeEngines.h)
  4421. EffectKind::maximus, EffectKind::vocodex, EffectKind::equo, EffectKind::distructor, EffectKind::lovePhilter,
  4422. EffectKind::grossBeat, EffectKind::convolver, EffectKind::flPitchShifter, EffectKind::vintagePhaser,
  4423. EffectKind::squeeze, EffectKind::rhythmGain, EffectKind::newtone, EffectKind::newtime,
  4424. EffectKind::edison }; // round 190cd: FL's audio editor as a slot plugin
  4425. } // namespace
  4426. const std::vector<EffectKind>& addableEffects()
  4427. {
  4428. static const std::vector<EffectKind> list (std::begin (allEffects), std::end (allEffects));
  4429. return list;
  4430. }
  4431. bool isFlEffect (EffectKind kind)
  4432. {
  4433. // allEffects lists LYNX's own effects first and FL's from the Formula Controller on (the outboard gear insert is LYNX's)
  4434. const auto& list = addableEffects();
  4435. const auto first = std::find (list.begin(), list.end(), EffectKind::formulaController);
  4436. const auto at = std::find (list.begin(), list.end(), kind);
  4437. return at != list.end() && at >= first && kind != EffectKind::hardwareInsert;
  4438. }
  4439. bool addableEffectAvailable (EffectKind kind)
  4440. {
  4441. const auto* e = natives::effectEngine (kind);
  4442. return e == nullptr || natives::available (*e, flStudioAccess());
  4443. }
  4444. juce::String addableEffectName (EffectKind kind)
  4445. {
  4446. const auto name = juce::String::fromUTF8 (effectInfo (kind).name);
  4447. // LYNX's own pitch / frequency effects sit next to FL's look-alikes (Pitch Shifter, Frequency Shifter, Pitcher)
  4448. // in the lists: tell them apart (round 162, issue #7 review)
  4449. if (kind == EffectKind::pitchShift || kind == EffectKind::freqShift || kind == EffectKind::pitchCorrect)
  4450. return tr ("{0} (LYNX SHARE)", { name });
  4451. if (const auto* e = natives::effectEngine (kind))
  4452. {
  4453. if (! natives::available (*e, flStudioAccess()))
  4454. return tr ("{0} (requires FL Studio)", { name });
  4455. if (e->beta)
  4456. return tr ("{0} (beta)", { name });
  4457. }
  4458. return name;
  4459. }
  4460. std::optional<EffectSlot> newAddableEffect (EffectKind kind, double bpm)
  4461. {
  4462. return natives::newEffect (kind, flStudioAccess(), bpm);
  4463. }
  4464. EffectsPanel::EffectsPanel (AudioEngine& e)
  4465. : engine (e)
  4466. {
  4467. setWantsKeyboardFocus (false);
  4468. setMouseClickGrabsKeyboardFocus (false);
  4469. engine.addChangeListener (this);
  4470. showingTimer = std::make_unique<ui::TimerWhileShowing> (*this, static_cast<juce::Timer&> (*this), 30); // (stopped while hidden; round 174f)
  4471. }
  4472. EffectsPanel::~EffectsPanel()
  4473. {
  4474. engine.removeChangeListener (this);
  4475. }
  4476. juce::Rectangle<int> EffectsPanel::armBounds() const
  4477. {
  4478. return { 8, panelHeader + 2, 24, inputRowHeight - 8 };
  4479. }
  4480. juce::Rectangle<int> EffectsPanel::inputBoxBounds() const
  4481. {
  4482. return { 38, panelHeader + 2, getWidth() - 46, inputRowHeight - 8 };
  4483. }
  4484. void EffectsPanel::groupIntoRack (int slot, bool all)
  4485. {
  4486. engine.capturePluginStates(); // (the plugins' current settings go with them)
  4487. const auto t = track;
  4488. const auto moved = all ? patcherize::slotsForAll (engine.getSong(), t) : std::vector<int> { slot };
  4489. // a hosted plugin's automated parameter: its value now (node k is moved slot k), so its macro starts there
  4490. auto values = [this, t, moved] (int node, int param) -> float {
  4491. if (node < 0 || node >= (int) moved.size())
  4492. return -1.0f;
  4493. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (t, moved[(std::size_t) node]).get()); p != nullptr && ! p->hasCrashed())
  4494. if (auto& instance = p->getInstance(); param >= 0 && param < instance.getParameters().size())
  4495. return instance.getParameters()[param]->getValue();
  4496. return -1.0f;
  4497. };
  4498. auto trial = engine.getSong();
  4499. const auto at = patcherize::patcherizeSlots (trial, t, slot, all);
  4500. if (at < 0 || ! rack::fromPatcher (trial.mixer[(std::size_t) t].effects[(std::size_t) at].patcher, values))
  4501. {
  4502. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Group into Audio Effect Rack"),
  4503. tr ("These effects can't go into a rack (a side-chain, or more than 16 automated parameters)."));
  4504. return;
  4505. }
  4506. int placed = -1;
  4507. engine.editSong ([t, slot, all, values, &placed] (Song& song) {
  4508. placed = patcherize::patcherizeSlots (song, t, slot, all);
  4509. if (placed >= 0)
  4510. rack::fromPatcher (song.mixer[(std::size_t) t].effects[(std::size_t) placed].patcher, values);
  4511. });
  4512. if (placed >= 0)
  4513. selectedSlot = placed;
  4514. repaint();
  4515. }
  4516. void EffectsPanel::timerCallback()
  4517. {
  4518. // the input level of the shown insert (the strips read their own); decays like a meter
  4519. const auto& mixer = engine.getSong().mixer;
  4520. const auto hasInput = track >= 0 && track < (int) mixer.size() && mixer[(std::size_t) track].inputChannel >= 0;
  4521. auto changed = false;
  4522. for (int side = 0; side < 2; ++side)
  4523. {
  4524. const auto peak = hasInput ? engine.peekInputPeak (track, side) : 0.0f;
  4525. const auto level = juce::jmax (peak, inputLevel[(std::size_t) side] * 0.8f);
  4526. changed = changed || std::abs (level - inputLevel[(std::size_t) side]) > 1e-4f;
  4527. inputLevel[(std::size_t) side] = level < 1e-4f ? 0.0f : level;
  4528. }
  4529. if (changed && isShowing())
  4530. repaint (inputBoxBounds());
  4531. // another effect selected (its controls need another height): fold / unfold the EQ, scroll (round 164)
  4532. if (const auto* s = slots(); s != nullptr && isShowing())
  4533. {
  4534. const auto kind = selectedSlot >= 0 && selectedSlot < (int) s->size() ? (int) (*s)[(std::size_t) selectedSlot].kind : -1;
  4535. if (selectedSlot != fittedSlot || kind != fittedKind)
  4536. {
  4537. fittedSlot = selectedSlot;
  4538. fittedKind = kind;
  4539. refit();
  4540. }
  4541. }
  4542. }
  4543. void EffectsPanel::setTrack (int t)
  4544. {
  4545. track = t;
  4546. const auto* s = slots();
  4547. selectedSlot = s != nullptr && ! s->empty() ? 0 : -1;
  4548. refit();
  4549. repaint();
  4550. }
  4551. const std::vector<EffectSlot>* EffectsPanel::slots() const
  4552. {
  4553. const auto& mixer = engine.getSong().mixer;
  4554. return track >= 0 && track < (int) mixer.size() ? &mixer[(std::size_t) track].effects : nullptr;
  4555. }
  4556. int EffectsPanel::rowOf (int index) const
  4557. {
  4558. const auto* s = slots();
  4559. if (s == nullptr || index < 0 || index >= (int) s->size())
  4560. return -1;
  4561. return mixerops::effectRows (*s)[(std::size_t) index];
  4562. }
  4563. int EffectsPanel::effectIn (int row) const
  4564. {
  4565. const auto* s = slots();
  4566. return s == nullptr ? -1 : mixerops::effectAtRow (*s, row);
  4567. }
  4568. juce::Rectangle<int> EffectsPanel::mixBounds (int slot) const
  4569. {
  4570. return slotBounds (slot).withTrimmedRight (20).removeFromRight (24);
  4571. }
  4572. juce::Rectangle<int> EffectsPanel::ledBounds (int slot) const
  4573. {
  4574. return slotBounds (slot).removeFromRight (20);
  4575. }
  4576. juce::Rectangle<int> EffectsPanel::arrowBounds (int slot) const
  4577. {
  4578. return slotBounds (slot).removeFromLeft (18);
  4579. }
  4580. // --- the insert's built-in EQ and its output (FL's layout under the slots, REA round 104) ---------
  4581. namespace
  4582. {
  4583. constexpr int eqGraphHeight = 84, eqKnobsHeight = 46, outputRowHeight = 30;
  4584. constexpr float eqMinHz = 20.0f, eqMaxHz = 20000.0f, eqRangeDb = 18.0f;
  4585. const char* const eqBandNames[] = { TR_NOOP ("Low shelf"), TR_NOOP ("Peak"), TR_NOOP ("High shelf") };
  4586. juce::Colour eqBandColour (int band)
  4587. {
  4588. return band == 0 ? juce::Colour (0xFFE0A33Au) : band == 1 ? juce::Colour (0xFF5FC27Eu) : juce::Colour (0xFF5B9BE6u);
  4589. }
  4590. // stored 0..1 <-> the band's value
  4591. float eqToValue (const TrackEq& eq, int band, int what)
  4592. {
  4593. const auto b = (std::size_t) band;
  4594. if (what == 0)
  4595. return (eq.gainDb[b] + eqRangeDb) / (2.0f * eqRangeDb);
  4596. if (what == 1)
  4597. return std::log (eq.hz[b] / 10.0f) / std::log (1600.0f);
  4598. return eq.width[b];
  4599. }
  4600. void eqFromValue (TrackEq& eq, int band, int what, float v)
  4601. {
  4602. const auto b = (std::size_t) band;
  4603. v = juce::jlimit (0.0f, 1.0f, v);
  4604. if (what == 0)
  4605. eq.gainDb[b] = std::round ((v * 2.0f * eqRangeDb - eqRangeDb) * 10.0f) / 10.0f;
  4606. else if (what == 1)
  4607. eq.hz[b] = std::round (10.0f * std::pow (1600.0f, v));
  4608. else
  4609. eq.width[b] = v;
  4610. }
  4611. // the EQ's response at `hz` (dB), with the filters the mixer runs (RackRenderer::applyTrackEq)
  4612. float eqResponseDb (const TrackEq& eq, double hz, double sampleRate)
  4613. {
  4614. Biquad bands[3];
  4615. bands[0].shelf (sampleRate, std::min ((double) eq.hz[0], sampleRate * 0.45), eq.gainDb[0], false, TrackEq::shelfSlope (eq.width[0]));
  4616. bands[1].peaking (sampleRate, std::min ((double) eq.hz[1], sampleRate * 0.45), TrackEq::peakQ (eq.width[1]), eq.gainDb[1]);
  4617. bands[2].shelf (sampleRate, std::min ((double) eq.hz[2], sampleRate * 0.45), eq.gainDb[2], true, TrackEq::shelfSlope (eq.width[2]));
  4618. const auto w = juce::MathConstants<double>::twoPi * hz / sampleRate;
  4619. const std::complex<double> z1 = std::polar (1.0, -w), z2 = std::polar (1.0, -2.0 * w);
  4620. double db = 0.0;
  4621. for (int b = 0; b < 3; ++b)
  4622. {
  4623. if (eq.gainDb[(std::size_t) b] == 0.0f)
  4624. continue; // a band at 0 dB is not processed (like FL)
  4625. const auto& f = bands[b];
  4626. const auto h = (f.b0 + f.b1 * z1 + f.b2 * z2) / (1.0 + f.a1 * z1 + f.a2 * z2);
  4627. db += 20.0 * std::log10 (std::max (1e-9, std::abs (h)));
  4628. }
  4629. return (float) db;
  4630. }
  4631. } // namespace
  4632. constexpr int eqFoldBarHeight = 20;
  4633. bool EffectsPanel::eqShown() const
  4634. {
  4635. return ! engine.getSong().cleanMixer; // clean mixer (round 163): no built-in EQ to show
  4636. }
  4637. int EffectsPanel::belowHeight (bool folded) const
  4638. {
  4639. if (! eqShown()) // clean mixer: only the output row
  4640. return outputRowHeight + 8;
  4641. return outputRowHeight + eqFoldBarHeight + (folded ? 4 : eqGraphHeight + eqKnobsHeight + 14);
  4642. }
  4643. int EffectsPanel::bottomTop() const
  4644. {
  4645. return getHeight() - belowHeight (eqFolded);
  4646. }
  4647. juce::Rectangle<int> EffectsPanel::eqFoldBounds() const
  4648. {
  4649. if (! eqShown())
  4650. return {};
  4651. return { 8, bottomTop(), getWidth() - 16, eqFoldBarHeight };
  4652. }
  4653. int EffectsPanel::neededHeight (bool folded) const
  4654. {
  4655. // the slots and the selected effect's controls (round 164: its knobs and their names and values too, they were
  4656. // cut by the EQ at medium heights): when they don't fit with the EQ open, it folds; then the panel scrolls
  4657. return selectedEffectBottom() + 6 + belowHeight (folded);
  4658. }
  4659. void EffectsPanel::fitToView (int w, int h, int scrollBar)
  4660. {
  4661. viewWidth = w;
  4662. viewHeight = h;
  4663. scrollBarThickness = scrollBar;
  4664. refit();
  4665. }
  4666. void EffectsPanel::refit()
  4667. {
  4668. if (viewWidth <= 0 || viewHeight <= 0)
  4669. return;
  4670. const auto folded = eqFoldChoice == 2 || (eqFoldChoice == 0 && viewHeight < neededHeight (false));
  4671. const auto need = neededHeight (folded);
  4672. const auto scrolls = viewHeight < need;
  4673. const auto changed = folded != eqFolded;
  4674. eqFolded = folded;
  4675. const juce::Rectangle<int> size (viewWidth - (scrolls ? scrollBarThickness : 0), juce::jmax (viewHeight, need));
  4676. if (getWidth() != size.getWidth() || getHeight() != size.getHeight())
  4677. setSize (size.getWidth(), size.getHeight());
  4678. else if (changed)
  4679. repaint();
  4680. }
  4681. juce::Rectangle<int> EffectsPanel::eqGraphBounds() const
  4682. {
  4683. return { 8, bottomTop() + eqFoldBarHeight, getWidth() - 16 - 3 * 18 - 6, eqGraphHeight };
  4684. }
  4685. juce::Rectangle<int> EffectsPanel::eqFaderBounds (int band) const
  4686. {
  4687. const auto graph = eqGraphBounds();
  4688. return { graph.getRight() + 6 + band * 18, graph.getY(), 16, graph.getHeight() };
  4689. }
  4690. juce::Rectangle<int> EffectsPanel::eqKnobBounds (int band, int what) const
  4691. {
  4692. const auto fader = eqFaderBounds (band);
  4693. return { fader.getCentreX() - 11, eqGraphBounds().getBottom() + 2 + (what - 1) * 22, 22, 22 };
  4694. }
  4695. juce::Rectangle<int> EffectsPanel::outputBounds() const
  4696. {
  4697. return { 34, getHeight() - outputRowHeight - 2, getWidth() - 42, outputRowHeight - 8 };
  4698. }
  4699. juce::Point<float> EffectsPanel::eqHandle (int band) const
  4700. {
  4701. const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
  4702. const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
  4703. const auto hz = juce::jlimit (eqMinHz, eqMaxHz, eq.hz[(std::size_t) band]);
  4704. const auto x = graph.getX() + graph.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
  4705. const auto y = graph.getCentreY() - graph.getHeight() * 0.5f * eq.gainDb[(std::size_t) band] / eqRangeDb;
  4706. return { x, y };
  4707. }
  4708. int EffectsPanel::eqControlAt (juce::Point<int> p) const
  4709. {
  4710. if (slots() == nullptr || eqFolded || ! eqShown())
  4711. return 0;
  4712. for (int b = 0; b < 3; ++b)
  4713. {
  4714. if (eqFaderBounds (b).contains (p))
  4715. return eqParamBase - b * 3;
  4716. for (int what = 1; what <= 2; ++what)
  4717. if (eqKnobBounds (b, what).contains (p))
  4718. return eqParamBase - b * 3 - what;
  4719. }
  4720. if (eqGraphBounds().contains (p))
  4721. {
  4722. // the nearest handle (by distance in the graph): FL's "Tweak band N"
  4723. int best = 0;
  4724. float bestDistance = 1e9f;
  4725. for (int b = 0; b < 3; ++b)
  4726. if (const auto d = eqHandle (b).getDistanceFrom (p.toFloat()); d < bestDistance)
  4727. {
  4728. bestDistance = d;
  4729. best = b;
  4730. }
  4731. return eqPointBase - best;
  4732. }
  4733. return 0;
  4734. }
  4735. void EffectsPanel::setEqFromGraph (int band, juce::Point<int> p)
  4736. {
  4737. const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
  4738. const auto fx = juce::jlimit (0.0f, 1.0f, (p.x - graph.getX()) / graph.getWidth());
  4739. const auto hz = juce::jlimit (10.0f, 16000.0f, std::round (eqMinHz * std::pow (eqMaxHz / eqMinHz, fx)));
  4740. const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, std::round ((graph.getCentreY() - p.y) / (graph.getHeight() * 0.5f) * eqRangeDb * 10.0f) / 10.0f);
  4741. engine.editSong ([t = track, band, hz, db] (Song& s) {
  4742. if (t < (int) s.mixer.size())
  4743. {
  4744. s.mixer[(std::size_t) t].eq.hz[(std::size_t) band] = hz;
  4745. s.mixer[(std::size_t) t].eq.gainDb[(std::size_t) band] = db;
  4746. }
  4747. });
  4748. }
  4749. void EffectsPanel::paintEq (juce::Graphics& g)
  4750. {
  4751. using namespace theme;
  4752. const auto& song = engine.getSong();
  4753. if (track < 0 || track >= (int) song.mixer.size())
  4754. return;
  4755. const auto& eq = song.mixer[(std::size_t) track].eq;
  4756. const auto top = bottomTop();
  4757. g.setColour (colour::border);
  4758. g.fillRect (8, top, getWidth() - 16, 1);
  4759. // the title bar: click folds / unfolds the EQ (it folds by itself when the mixer is too short for it)
  4760. if (eqShown())
  4761. {
  4762. const auto bar = eqFoldBounds().toFloat();
  4763. const auto active = eq.active();
  4764. auto chevron = bar.withWidth (14.0f).withSizeKeepingCentre (12.0f, 12.0f);
  4765. {
  4766. juce::Graphics::ScopedSaveState state (g);
  4767. if (eqFolded)
  4768. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, chevron.getCentreX(), chevron.getCentreY()));
  4769. icons::draw (g, Icon::chevronDown, chevron, colour::textSecondary);
  4770. }
  4771. g.setFont (font (type::small, true));
  4772. g.setColour (colour::textSecondary);
  4773. textcache::drawText (g, tr ("EQ"), bar.withTrimmedLeft (18.0f).toNearestInt(), juce::Justification::centredLeft);
  4774. if (eq.bypassed && eq.hasBoostOrCut()) // round 177d: bypassed, its settings kept
  4775. {
  4776. g.setColour (colour::textDisabled);
  4777. g.setFont (font (type::caption));
  4778. textcache::drawText (g, tr ("bypassed"), bar.withTrimmedLeft (44.0f).toNearestInt(), juce::Justification::centredLeft);
  4779. }
  4780. else if (eqFolded && active) // a folded EQ that still changes the sound says so
  4781. {
  4782. g.setColour (colour::accent);
  4783. g.setFont (font (type::caption));
  4784. textcache::drawText (g, tr ("active"), bar.withTrimmedLeft (44.0f).toNearestInt(), juce::Justification::centredLeft);
  4785. }
  4786. }
  4787. if (! eqFolded && eqShown())
  4788. {
  4789. // the response graph: frequency (log) across, ±18 dB up and down
  4790. const auto graph = eqGraphBounds().toFloat();
  4791. theme::fillRoundRect (g, graph, radius::sm, colour::bg1);
  4792. g.setColour (colour::border);
  4793. g.drawRoundedRectangle (graph.reduced (0.5f), radius::sm, 1.0f);
  4794. const auto inner = graph.reduced (4.0f);
  4795. g.setColour (colour::gridBeat);
  4796. for (float hz : { 100.0f, 1000.0f, 10000.0f })
  4797. {
  4798. const auto x = inner.getX() + inner.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
  4799. g.drawVerticalLine ((int) x, inner.getY(), inner.getBottom());
  4800. }
  4801. g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
  4802. juce::Path curve;
  4803. const auto sampleRate = juce::jmax (8000.0, engine.getTransport().sampleRate.load());
  4804. for (int i = 0; i <= (int) inner.getWidth(); i += 2)
  4805. {
  4806. const auto hz = eqMinHz * std::pow (eqMaxHz / eqMinHz, (float) i / inner.getWidth());
  4807. const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, eqResponseDb (eq, hz, sampleRate));
  4808. const auto y = inner.getCentreY() - inner.getHeight() * 0.5f * db / eqRangeDb;
  4809. if (i == 0)
  4810. curve.startNewSubPath (inner.getX(), y);
  4811. else
  4812. curve.lineTo (inner.getX() + (float) i, y);
  4813. }
  4814. g.setColour (eq.active() ? colour::accent : colour::textSecondary.withAlpha (0.6f));
  4815. g.strokePath (curve, juce::PathStrokeType (1.5f));
  4816. for (int b = 0; b < 3; ++b)
  4817. {
  4818. const auto hot = hoverEq == eqPointBase - b || dragParam == eqPointBase - b;
  4819. const auto handle = eqHandle (b);
  4820. g.setColour (eqBandColour (b).withAlpha (hot ? 1.0f : 0.8f));
  4821. g.fillEllipse (juce::Rectangle<float> (hot ? 10.0f : 8.0f, hot ? 10.0f : 8.0f).withCentre (handle));
  4822. }
  4823. // the gain faders (one per band) and the frequency / width knobs under them
  4824. for (int b = 0; b < 3; ++b)
  4825. {
  4826. const auto fader = eqFaderBounds (b).toFloat();
  4827. const auto hot = hoverEq == eqParamBase - b * 3 || dragParam == eqParamBase - b * 3;
  4828. theme::fillRoundRect (g, fader.withSizeKeepingCentre (3.0f, fader.getHeight() - 6.0f), 1.5f, colour::bg0);
  4829. g.setColour (colour::border);
  4830. g.drawHorizontalLine ((int) fader.getCentreY(), fader.getX() + 2.0f, fader.getRight() - 2.0f);
  4831. const auto v = eqToValue (eq, b, 0);
  4832. const auto y = fader.getBottom() - 6.0f - v * (fader.getHeight() - 12.0f);
  4833. theme::fillRoundRect (g, juce::Rectangle<float> (fader.getWidth() - 2.0f, 7.0f).withCentre ({ fader.getCentreX(), y }), 2.0f, hot ? colour::textPrimary : colour::textSecondary);
  4834. g.setColour (eqBandColour (b));
  4835. g.fillRect (juce::Rectangle<float> (fader.getWidth() - 6.0f, 1.5f).withCentre ({ fader.getCentreX(), y }));
  4836. for (int what = 1; what <= 2; ++what)
  4837. {
  4838. const auto code = eqParamBase - b * 3 - what;
  4839. drawKnob (g, eqKnobBounds (b, what).toFloat().reduced (2.0f), eqToValue (eq, b, what), false, eqBandColour (b),
  4840. hoverEq == code || dragParam == code);
  4841. }
  4842. }
  4843. // the knob captions take the width their (translated) text needs, the title gives way (round 165o)
  4844. const juce::Font captionFont (font (type::caption));
  4845. const auto captionWidth = juce::jlimit (32, 70, (int) std::ceil (juce::jmax (juce::GlyphArrangement::getStringWidth (captionFont, tr ("Freq")),
  4846. juce::GlyphArrangement::getStringWidth (captionFont, tr ("Width")))) + 2);
  4847. g.setColour (colour::textSecondary);
  4848. g.setFont (font (type::title));
  4849. textcache::drawText (g, tr ("Equalizer"), 10, eqGraphBounds().getBottom() + 4, eqKnobBounds (0, 1).getX() - 8 - captionWidth, 20,
  4850. juce::Justification::centredLeft);
  4851. g.setFont (captionFont);
  4852. g.setColour (colour::textDisabled);
  4853. textcache::drawText (g, tr ("Freq"), eqKnobBounds (0, 1).getX() - 2 - captionWidth, eqKnobBounds (0, 1).getY(), captionWidth, 22,
  4854. juce::Justification::centredRight);
  4855. textcache::drawText (g, tr ("Width"), eqKnobBounds (0, 2).getX() - 2 - captionWidth, eqKnobBounds (0, 2).getY(), captionWidth, 22,
  4856. juce::Justification::centredRight);
  4857. }
  4858. // the audio output target
  4859. auto box = outputBounds().toFloat();
  4860. g.setColour (colour::border);
  4861. g.fillRect (8, (int) box.getY() - 5, getWidth() - 16, 1);
  4862. icons::draw (g, Icon::exportAudio, juce::Rectangle<float> (10.0f, box.getY(), 18.0f, box.getHeight()).withSizeKeepingCentre (16.0f, 16.0f),
  4863. colour::textSecondary);
  4864. theme::fillRoundRect (g, box, radius::sm, hoverOutput ? colour::bg4 : colour::bg3);
  4865. g.setColour (hoverOutput ? colour::borderStrong : colour::border);
  4866. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  4867. g.setColour (track == 0 ? colour::textPrimary : colour::textSecondary);
  4868. g.setFont (font (type::body));
  4869. textcache::drawText (g, outputName(), box.withTrimmedLeft (8.0f).withTrimmedRight (18.0f).toNearestInt(), juce::Justification::centredLeft, true);
  4870. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, 0.0f), colour::textSecondary);
  4871. }
  4872. juce::String EffectsPanel::outputName() const
  4873. {
  4874. if (track == 0 && const_cast<AudioEngine&> (engine).getDeviceManager().getCurrentAudioDevice() == nullptr)
  4875. return tr ("(no audio device)");
  4876. return mixeroutput::label (engine, track);
  4877. }
  4878. void EffectsPanel::showOutputMenu()
  4879. {
  4880. mixeroutput::showMenu (engine, track, this, localAreaToGlobal (outputBounds()));
  4881. }
  4882. namespace mixeroptions
  4883. {
  4884. std::function<void()> changed;
  4885. std::function<void (bool)> setShowUsedOnly;
  4886. std::function<void (bool)> setShowLoudness;
  4887. std::function<void (bool)> setShowStripInserts;
  4888. std::function<void (std::vector<int>, std::function<void (const std::vector<juce::File>&)>)> renderTracks;
  4889. std::function<void (std::vector<int>)> selectPlaylistTracks;
  4890. namespace
  4891. {
  4892. void notifyChanged()
  4893. {
  4894. if (changed)
  4895. changed();
  4896. }
  4897. void askNumber (const juce::String& title, const juce::String& text, int value, int lo, int hi, std::function<void (int)> done)
  4898. {
  4899. auto* w = new juce::AlertWindow (title, text, juce::MessageBoxIconType::NoIcon);
  4900. w->addTextEditor ("n", juce::String (value));
  4901. w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  4902. w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  4903. w->enterModalState (true, juce::ModalCallbackFunction::create ([w, lo, hi, done = std::move (done)] (int result) {
  4904. if (result == 1)
  4905. done (juce::jlimit (lo, hi, w->getTextEditorContents ("n").trim().getIntValue()));
  4906. }), true);
  4907. }
  4908. } // namespace
  4909. juce::PopupMenu snapshotsMenu (AudioEngine& engine)
  4910. {
  4911. // Round 190hp (slice B16 of the 0.1.28 pain report; LYNX's own, core/MixSnapshots.h): take, recall and compare whole
  4912. // mixes. Each change is one undo step.
  4913. const auto& song = engine.getSong();
  4914. juce::PopupMenu menu;
  4915. const auto count = (int) song.mixSnapshots.size();
  4916. const auto full = count >= maxMixSnapshots;
  4917. menu.addItem (full ? tr ("Take snapshot (at most {0})", { juce::String (maxMixSnapshots) }) : tr ("Take snapshot"), ! full, false, [&engine] {
  4918. int made = -1;
  4919. engine.editSong ([&made] (Song& s) { made = mixsnap::take (s, tr ("Snapshot").toStdString()); });
  4920. if (made >= 0)
  4921. ui::postHint ({ tr ("Mix saved as \"{0}\"", { juce::String::fromUTF8 (engine.getSong().mixSnapshots[(std::size_t) made].name.c_str()) }), {}, false, false }, 2500);
  4922. });
  4923. const auto ab = mixsnap::canCompare (song);
  4924. menu.addItem (ab ? tr ("Compare A/B: back to \"{0}\"", { juce::String::fromUTF8 (song.mixSnapshots[(std::size_t) song.mixSnapshotPrevious].name.c_str()) })
  4925. : tr ("Compare A/B"),
  4926. ab, false, [&engine] { engine.editSong ([] (Song& s) { mixsnap::compareAB (s); }); });
  4927. if (count == 0)
  4928. return menu;
  4929. menu.addSeparator();
  4930. for (int i = 0; i < count; ++i)
  4931. {
  4932. const auto& snap = song.mixSnapshots[(std::size_t) i];
  4933. const auto name = juce::String::fromUTF8 (snap.name.c_str());
  4934. // ticked: the mix is this snapshot now
  4935. const auto now = mixsnap::matches (song, snap);
  4936. juce::PopupMenu one;
  4937. one.addItem (tr ("Recall"), true, false, [&engine, i] { engine.editSong ([i] (Song& s) { mixsnap::recall (s, i); }); });
  4938. one.addItem (tr ("Update to the current mix"), ! now, false, [&engine, i] { engine.editSong ([i] (Song& s) { mixsnap::update (s, i); }); });
  4939. one.addItem (tr ("Rename..."), [&engine, i, name] {
  4940. auto* w = new juce::AlertWindow (tr ("Rename snapshot"), {}, juce::MessageBoxIconType::NoIcon);
  4941. w->addTextEditor ("name", name);
  4942. w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  4943. w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  4944. w->enterModalState (true, juce::ModalCallbackFunction::create ([w, &engine, i] (int result) {
  4945. const auto typed = w->getTextEditorContents ("name").trim().toStdString();
  4946. if (result == 1 && ! typed.empty())
  4947. engine.editSong ([i, typed] (Song& s) { mixsnap::rename (s, i, typed); });
  4948. }), true);
  4949. });
  4950. one.addSeparator();
  4951. one.addItem (tr ("Delete"), [&engine, i] { engine.editSong ([i] (Song& s) { mixsnap::remove (s, i); }); });
  4952. menu.addSubMenu (name + (i == song.mixSnapshotCurrent ? " (A)" : i == song.mixSnapshotPrevious ? " (B)" : ""), one, true, juce::Image(), now);
  4953. }
  4954. return menu;
  4955. }
  4956. void addItems (juce::PopupMenu& menu, AudioEngine& engine, bool newProjects)
  4957. {
  4958. const auto& song = engine.getSong();
  4959. menu.addItem (tr ("Clean mixer: no built-in EQ on the inserts (this project)"), true, song.cleanMixer, [&engine] {
  4960. const auto on = ! engine.getSong().cleanMixer;
  4961. engine.editSong ([on] (Song& s) { s.cleanMixer = on; });
  4962. const auto& mixer = engine.getSong().mixer;
  4963. const auto withEq = std::count_if (mixer.begin(), mixer.end(), [] (const MixerTrack& t) { return t.eq.active(); });
  4964. if (on && withEq > 0) // nothing is lost: switching it off brings the EQ back as it was
  4965. ui::postHint ({ tr ("Clean mixer: the EQ of {0} insert(s) is bypassed and hidden (kept in the project)", { juce::String ((int) withEq) }), {}, false, false }, 5000);
  4966. });
  4967. // LYNX option (round 190y): the old cheap mute; FL keeps a muted insert's effects running (and showing its level)
  4968. menu.addItem (tr ("Muted inserts don't process (LYNX, saves CPU; this project)"), true, song.mutedInsertsSkip, [&engine] {
  4969. const auto on = ! engine.getSong().mutedInsertsSkip;
  4970. engine.editSong ([on] (Song& s) { s.mutedInsertsSkip = on; });
  4971. if (on)
  4972. ui::postHint ({ tr ("Muted inserts skip their effects: a Fruity Send or controller in one goes quiet, its meter stops, and its effects start fresh when unmuted (FL keeps them running)"), {}, false, false }, 6000);
  4973. });
  4974. menu.addItem (tr ("Show only used inserts"), true, MixerStrips::showUsedOnly, [] {
  4975. const auto on = ! MixerStrips::showUsedOnly;
  4976. if (setShowUsedOnly)
  4977. setShowUsedOnly (on);
  4978. else
  4979. MixerStrips::showUsedOnly = on;
  4980. notifyChanged();
  4981. });
  4982. // LYNX's own (issue #154 part 2, round 190io; off = FL's mixer): each strip lists its insert's effects
  4983. menu.addItem (tr ("Insert effects on the strips (LYNX)"), true, MixerStrips::showStripInserts, [] {
  4984. const auto on = ! MixerStrips::showStripInserts;
  4985. if (setShowStripInserts)
  4986. setShowStripInserts (on);
  4987. else
  4988. MixerStrips::showStripInserts = on;
  4989. notifyChanged();
  4990. });
  4991. // LYNX's own (round 190am; off = FL's mixer): the Master's loudness in LUFS and its true peak, beside the Master
  4992. menu.addItem (tr ("Loudness meter beside the Master (LYNX)"), true, MixerStrips::showLoudness, [] {
  4993. const auto on = ! MixerStrips::showLoudness;
  4994. if (setShowLoudness)
  4995. setShowLoudness (on);
  4996. else
  4997. MixerStrips::showLoudness = on;
  4998. notifyChanged();
  4999. });
  5000. menu.addSubMenu (tr ("Mix snapshots (LYNX)"), snapshotsMenu (engine));
  5001. menu.addItem (tr ("Remove unused inserts at the end"), song.mixer.size() > 1 && ! song.insertInUse ((int) song.mixer.size() - 1), false, [&engine] {
  5002. int removed = 0;
  5003. engine.editSong ([&removed] (Song& s) { removed = mixerops::removeUnusedTrailingInserts (s); });
  5004. ui::postHint ({ tr ("Removed {0} unused insert(s)", { juce::String (removed) }), {}, false, false }, 3000);
  5005. });
  5006. // LYNX's option (round 186c, pain point 1; off = FL, which drops them): a deleted insert's incoming sends stay greyed
  5007. menu.addItem (tr ("Keep links to deleted inserts, greyed (LYNX)"), true, MixerStrips::keepLostLinks, [] {
  5008. MixerStrips::keepLostLinks = ! MixerStrips::keepLostLinks;
  5009. notifyChanged();
  5010. });
  5011. // LYNX's addition (round 186c, pain point 4; off by default): the mixer's groups mirror the Playlist's track groups
  5012. menu.addItem (tr ("Mixer groups follow the Playlist (LYNX)"), true, MixerStrips::followPlaylist, [&engine] {
  5013. MixerStrips::followPlaylist = ! MixerStrips::followPlaylist;
  5014. if (MixerStrips::followPlaylist)
  5015. engine.editSong ([] (Song& s) { mixerops::followPlaylistGroups (s); });
  5016. notifyChanged();
  5017. });
  5018. menu.addItem (tr ("Arrange inserts like the Playlist"), ! mixerops::playlistOrderInserts (song).empty(), false, [&engine] {
  5019. int moved = 0;
  5020. engine.editSongStructural ([&moved] (Song& s) { moved = mixerops::arrangeLikePlaylist (s); });
  5021. ui::postHint ({ tr ("{0} insert(s) moved to follow the Playlist", { juce::String (moved) }), {}, false, false }, 3000);
  5022. });
  5023. if (! newProjects)
  5024. return;
  5025. auto& d = newProjectDefaults();
  5026. menu.addSectionHeader (tr ("New projects"));
  5027. {
  5028. juce::PopupMenu inserts;
  5029. bool listed = false;
  5030. for (int n : { 0, 1, 2, 4, 8, 12, 16, 24, 32, 48, 64, 100, 125 })
  5031. {
  5032. listed = listed || n == d.inserts;
  5033. inserts.addItem (n == NewProjectDefaults::defaultInserts ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.inserts, [n] {
  5034. newProjectDefaults().inserts = n;
  5035. notifyChanged();
  5036. });
  5037. }
  5038. inserts.addItem (listed ? tr ("Other...") : tr ("Other ({0})...", { juce::String (d.inserts) }), true, ! listed, [] {
  5039. askNumber (tr ("Inserts in new projects"),
  5040. tr ("How many mixer inserts a new project starts with (0 to {0}). More are added when you need them.", { juce::String (maxMixerTracks - 1) }),
  5041. newProjectDefaults().inserts, 0, maxMixerTracks - 1, [] (int n) {
  5042. newProjectDefaults().inserts = n;
  5043. notifyChanged();
  5044. });
  5045. });
  5046. menu.addSubMenu (tr ("Inserts in new projects ({0})", { juce::String (d.inserts) }), inserts);
  5047. }
  5048. {
  5049. juce::PopupMenu chain;
  5050. const std::pair<const char*, MasterChain> chains[] = { { TR_NOOP ("Empty (nothing on the Master)"), MasterChain::empty },
  5051. { TR_NOOP ("Soft clipper only"), MasterChain::clipper },
  5052. { TR_NOOP ("LYNX SHARE default (limiter)"), MasterChain::lynxDefault } };
  5053. for (const auto& [label, c] : chains)
  5054. chain.addItem (tr (label), true, d.master == c, [c = c] {
  5055. newProjectDefaults().master = c;
  5056. notifyChanged();
  5057. });
  5058. menu.addSubMenu (tr ("Master chain in new projects"), chain);
  5059. }
  5060. menu.addItem (tr ("Clean mixer in new projects (no built-in EQ)"), true, d.cleanMixer, [] {
  5061. newProjectDefaults().cleanMixer = ! newProjectDefaults().cleanMixer;
  5062. notifyChanged();
  5063. });
  5064. {
  5065. juce::PopupMenu tracks;
  5066. for (int n : { 4, 8, 16, 24, 32, 64, 100 })
  5067. tracks.addItem (n == 16 ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.playlistTracks, [n] {
  5068. newProjectDefaults().playlistTracks = n;
  5069. notifyChanged();
  5070. });
  5071. menu.addSubMenu (tr ("Playlist tracks shown ({0})", { juce::String (d.playlistTracks) }), tracks);
  5072. }
  5073. }
  5074. } // namespace mixeroptions
  5075. namespace mixeroutput
  5076. {
  5077. namespace
  5078. {
  5079. juce::String modeSuffix (OutputMode mode)
  5080. {
  5081. switch (mode)
  5082. {
  5083. case OutputMode::stereo: return {};
  5084. case OutputMode::monoSum: return " " + tr ("(mono)");
  5085. case OutputMode::monoLeft: return " " + tr ("(mono, L)");
  5086. case OutputMode::monoRight: return " " + tr ("(mono, R)");
  5087. }
  5088. return {};
  5089. }
  5090. } // namespace
  5091. bool isCustom (const AudioEngine& engine, int track)
  5092. {
  5093. const auto& mixer = engine.getSong().mixer;
  5094. if (track < 0 || track >= (int) mixer.size())
  5095. return false;
  5096. const auto channel = mixer[(std::size_t) track].outputChannel;
  5097. return track == 0 ? channel != outputDefault : channel >= 0;
  5098. }
  5099. juce::String label (const AudioEngine& engine, int track, bool compact)
  5100. {
  5101. const auto& mixer = engine.getSong().mixer;
  5102. if (track < 0 || track >= (int) mixer.size())
  5103. return {};
  5104. const auto& mt = mixer[(std::size_t) track];
  5105. auto channel = mt.outputChannel;
  5106. auto mode = mt.outputMode;
  5107. if (track == 0 && channel == outputDefault)
  5108. channel = 0, mode = OutputMode::stereo;
  5109. if (channel < 0)
  5110. return tr ("(none)");
  5111. const auto names = engine.getOutputChannelNames();
  5112. const auto missing = ! outputAvailable (channel, mode, (int) names.size())
  5113. || ! engine.isOutputChannelOpen (channel) || (mode == OutputMode::stereo && ! engine.isOutputChannelOpen (channel + 1));
  5114. if (compact) // the strip badge: the channel numbers only
  5115. {
  5116. auto text = juce::String::fromUTF8 ("\xe2\x86\x92 ") + juce::String (channel + 1);
  5117. if (mode == OutputMode::stereo)
  5118. text << "-" << (channel + 2);
  5119. else
  5120. text << (mode == OutputMode::monoLeft ? " L" : mode == OutputMode::monoRight ? " R" : " m");
  5121. return missing ? text + " ?" : text;
  5122. }
  5123. auto nameOf = [&] (int c) {
  5124. return c < (int) names.size() ? juce::String::fromUTF8 (names[(std::size_t) c].c_str()) : tr ("Out {0}", { juce::String (c + 1) });
  5125. };
  5126. auto text = mode == OutputMode::stereo ? nameOf (channel) + " - " + nameOf (channel + 1) : nameOf (channel);
  5127. text += modeSuffix (mode);
  5128. if (missing)
  5129. text += " " + tr ("(missing)");
  5130. return text;
  5131. }
  5132. void showMenu (AudioEngine& engine, int track, juce::Component* target, juce::Rectangle<int> screenArea)
  5133. {
  5134. const auto& mixer = engine.getSong().mixer;
  5135. if (track < 0 || track >= (int) mixer.size())
  5136. return;
  5137. const auto& mt = mixer[(std::size_t) track];
  5138. const auto names = engine.getOutputChannelNames();
  5139. const auto custom = isCustom (engine, track);
  5140. juce::PopupMenu menu;
  5141. menu.addSectionHeader (tr ("Audio output target"));
  5142. auto set = [&engine, track] (int channel, OutputMode mode) {
  5143. return [&engine, track, channel, mode] { engine.setTrackOutput (track, channel, mode); };
  5144. };
  5145. if (track == 0)
  5146. {
  5147. const auto first = names.size() >= 2 ? juce::String::fromUTF8 (names[0].c_str()) + " - " + juce::String::fromUTF8 (names[1].c_str())
  5148. : tr ("first output pair");
  5149. menu.addItem (first + " " + tr ("(default)"), true, mt.outputChannel == outputDefault, set (outputDefault, OutputMode::stereo));
  5150. menu.addItem (tr ("(none)"), true, mt.outputChannel == outputNone, set (outputNone, OutputMode::stereo));
  5151. }
  5152. else
  5153. menu.addItem (tr ("(none) - through the Master only"), true, ! custom, set (outputDefault, OutputMode::stereo));
  5154. if (custom && (track > 0 || mt.outputChannel >= 0))
  5155. menu.addItem (label (engine, track), true, true, nullptr); // the current target (also when missing)
  5156. // the optional direct outputs: stereo pairs, then every channel alone
  5157. juce::PopupMenu direct;
  5158. direct.addItem (track == 0 ? tr ("Optional: send the Master to other outputs of your audio interface")
  5159. : tr ("Optional: also send this insert straight to an output of your audio interface, e.g. a mono output"),
  5160. false, false, nullptr);
  5161. if (names.empty())
  5162. direct.addItem (tr ("No audio device is open"), false, false, nullptr);
  5163. const auto targets = outputTargets (names);
  5164. auto pairsHeader = false, monoHeader = false;
  5165. for (const auto& t : targets)
  5166. {
  5167. const auto name = juce::String::fromUTF8 (t.name.c_str());
  5168. if (t.mode == OutputMode::stereo)
  5169. {
  5170. if (! std::exchange (pairsHeader, true))
  5171. direct.addSectionHeader (tr ("Stereo pair"));
  5172. direct.addItem (name, true, mt.outputChannel == t.channel && mt.outputMode == OutputMode::stereo, set (t.channel, OutputMode::stereo));
  5173. continue;
  5174. }
  5175. if (! std::exchange (monoHeader, true))
  5176. direct.addSectionHeader (tr ("Mono (one output)"));
  5177. const auto here = mt.outputChannel == t.channel && mt.outputMode != OutputMode::stereo;
  5178. juce::PopupMenu modes;
  5179. modes.addItem (tr ("Sum of L + R (mono)"), true, here && mt.outputMode == OutputMode::monoSum, set (t.channel, OutputMode::monoSum));
  5180. modes.addItem (tr ("Left side only"), true, here && mt.outputMode == OutputMode::monoLeft, set (t.channel, OutputMode::monoLeft));
  5181. modes.addItem (tr ("Right side only"), true, here && mt.outputMode == OutputMode::monoRight, set (t.channel, OutputMode::monoRight));
  5182. direct.addSubMenu (name, modes, true, nullptr, here);
  5183. }
  5184. if (! names.empty() && names.size() <= 2)
  5185. direct.addItem (tr ("This audio device has 2 outputs; an interface with more outputs lists all of them here"), false, false, nullptr);
  5186. menu.addSeparator();
  5187. menu.addSubMenu (track == 0 ? tr ("Hardware output") : tr ("Send to hardware output (optional)"), direct, true, nullptr, custom && mt.outputChannel >= 0);
  5188. if (custom)
  5189. menu.addItem (track == 0 ? tr ("Back to the default output") : tr ("Back to Master only"), set (outputDefault, OutputMode::stereo));
  5190. menu.addSeparator();
  5191. menu.addItem (tr ("Audio settings..."), [] {
  5192. if (mixerinput::openAudioSettings)
  5193. mixerinput::openAudioSettings();
  5194. });
  5195. auto options = juce::PopupMenu::Options();
  5196. if (target != nullptr)
  5197. options = options.withTargetComponent (target);
  5198. if (! screenArea.isEmpty())
  5199. options = options.withTargetScreenArea (screenArea);
  5200. else if (target != nullptr)
  5201. options = options.withMousePosition();
  5202. menu.showMenuAsync (options);
  5203. }
  5204. } // namespace mixeroutput
  5205. juce::Rectangle<int> EffectsPanel::slotBounds (int slot) const
  5206. {
  5207. return { 8, slotsTop + slot * slotHeight, getWidth() - 16, slotHeight - 3 };
  5208. }
  5209. namespace
  5210. {
  5211. // parameters shown as knobs: in the rhythmic envelope, only those of the points in use
  5212. int shownParams (const EffectSlot& slot)
  5213. {
  5214. const auto all = (int) effectInfo (slot.kind).params.size();
  5215. if (slot.kind == EffectKind::rhythmGain)
  5216. return std::min (all, 2 + 3 * (int) std::lround (slot.params[1] * 12.0f));
  5217. if (slot.kind == EffectKind::lynxTune) // the note switches are the keyboard strip above the knobs
  5218. return std::min (all, (int) lynxtune::noteC);
  5219. return all;
  5220. }
  5221. } // namespace
  5222. juce::Rectangle<int> EffectsPanel::knobBounds (int param) const
  5223. {
  5224. return knobBoundsIn (param, bottomTop());
  5225. }
  5226. juce::Rectangle<int> EffectsPanel::knobBoundsIn (int param, int areaBottom) const
  5227. {
  5228. auto top = slotsTop + maxEffectSlots * slotHeight + 40;
  5229. // many parameters (Effector: 12): 4 columns and shorter rows to fit the height
  5230. int count = 0;
  5231. if (const auto* s = slots(); ! gateSelected() && s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size())
  5232. count = shownParams ((*s)[(std::size_t) selectedSlot]);
  5233. const auto columns = count > 9 ? 4 : 3;
  5234. const auto w = (getWidth() - 16) / columns;
  5235. const auto rows = juce::jmax (1, (count + columns - 1) / columns);
  5236. const auto rowHeight = count > 9 ? juce::jlimit (64, 86, (areaBottom - top - 4) / rows) : 86;
  5237. // volume gate: the 32 steps are bars (gateStepsBounds); the knobs are mix/attack/release
  5238. if (gateSelected())
  5239. {
  5240. if (param < 32)
  5241. return {};
  5242. param -= 32;
  5243. top = gateStepsBounds().getBottom() + 22;
  5244. }
  5245. if (vocoderSelected()) // the band levels above the knobs
  5246. top = bandLevelsBounds().getBottom() + 22;
  5247. if (tuneSelected()) // LYNX Tune's note keyboard above the knobs
  5248. top = tuneKeysBounds().getBottom() + 22;
  5249. return { 8 + (param % columns) * w, top + (param / columns) * rowHeight, w, rowHeight - 4 };
  5250. }
  5251. int EffectsPanel::selectedEffectBottom() const
  5252. {
  5253. const auto slotsBottom = slotsTop + maxEffectSlots * slotHeight;
  5254. auto bottom = slotsBottom + 64; // the effect's title row
  5255. const auto* s = slots();
  5256. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
  5257. return bottom;
  5258. const auto& slot = (*s)[(std::size_t) selectedSlot];
  5259. if (slot.kind == EffectKind::plugin || isSoundgoodizerApprox (slot))
  5260. return juce::jmax (bottom, pluginButtonBounds().getBottom() + 34 + 40);
  5261. if (slot.kind == EffectKind::parametricEq || slot.kind == EffectKind::facetEq)
  5262. return juce::jmax (bottom, pluginButtonBounds().getBottom() + 10 + 120);
  5263. if (slot.kind == EffectKind::parallel)
  5264. return juce::jmax (bottom, knobBoundsIn (0, 0).getY() - 28 + 20 + 22 * (int) slot.branches.size());
  5265. const auto count = gateSelected() ? 35 : shownParams (slot);
  5266. for (int p = 0; p < count; ++p)
  5267. if (const auto r = knobBoundsIn (p, 0); ! r.isEmpty()) // (tight grids at their shortest rows)
  5268. bottom = juce::jmax (bottom, r.getY() + juce::jlimit (30, 44, r.getHeight() - 30) + 32); // knob, name, value
  5269. return bottom;
  5270. }
  5271. bool EffectsPanel::gateSelected() const
  5272. {
  5273. const auto* s = slots();
  5274. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::volumeGate;
  5275. }
  5276. juce::Rectangle<int> EffectsPanel::gateStepsBounds() const
  5277. {
  5278. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 90 };
  5279. }
  5280. void EffectsPanel::setGateStep (juce::Point<int> p)
  5281. {
  5282. const auto area = gateStepsBounds();
  5283. const auto step = juce::jlimit (0, 31, (int) ((p.x - area.getX()) * 32 / juce::jmax (1, area.getWidth())));
  5284. const auto value = juce::jlimit (0.0f, 1.0f, (float) (area.getBottom() - p.y) / (float) area.getHeight());
  5285. engine.editSong ([t = track, slot = selectedSlot, step, value] (Song& song) {
  5286. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) step] = value;
  5287. });
  5288. }
  5289. bool EffectsPanel::vocoderSelected() const
  5290. {
  5291. const auto* s = slots();
  5292. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::vocoder;
  5293. }
  5294. bool EffectsPanel::tuneSelected() const
  5295. {
  5296. const auto* s = slots();
  5297. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::lynxTune;
  5298. }
  5299. juce::Rectangle<int> EffectsPanel::tuneKeysBounds() const
  5300. {
  5301. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 54 };
  5302. }
  5303. namespace
  5304. {
  5305. // LYNX Tune's keyboard strip: one octave, white keys in a row, black keys on top (C … B → key rectangles)
  5306. juce::Rectangle<float> tuneKeyRect (juce::Rectangle<float> area, int pc)
  5307. {
  5308. static constexpr int whiteIndex[12] { 0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, 6 };
  5309. static constexpr float blackAt[12] { 0, 1.0f, 0, 2.0f, 0, 0, 4.0f, 0, 5.0f, 0, 6.0f, 0 };
  5310. const auto w = area.getWidth() / 7.0f;
  5311. if (whiteIndex[pc] >= 0)
  5312. return { area.getX() + whiteIndex[pc] * w, area.getY(), w, area.getHeight() };
  5313. return { area.getX() + blackAt[pc] * w - w * 0.3f, area.getY(), w * 0.6f, area.getHeight() * 0.58f };
  5314. }
  5315. int tuneKeyAt (juce::Rectangle<float> area, juce::Point<float> p)
  5316. {
  5317. for (int pc = 0; pc < 12; ++pc) // black keys first: they lie on top
  5318. if ((pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10) && tuneKeyRect (area, pc).contains (p))
  5319. return pc;
  5320. for (int pc = 0; pc < 12; ++pc)
  5321. if (tuneKeyRect (area, pc).contains (p))
  5322. return pc;
  5323. return -1;
  5324. }
  5325. } // namespace
  5326. void EffectsPanel::toggleTuneNote (juce::Point<int> p)
  5327. {
  5328. const auto pc = tuneKeyAt (tuneKeysBounds().toFloat(), p.toFloat());
  5329. if (pc < 0)
  5330. return;
  5331. engine.editSong ([t = track, slot = selectedSlot, pc] (Song& song) {
  5332. auto& v = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) (lynxtune::noteC + pc)];
  5333. v = v >= 0.5f ? 0.0f : 1.0f;
  5334. });
  5335. }
  5336. juce::Rectangle<int> EffectsPanel::bandLevelsBounds() const
  5337. {
  5338. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 70 };
  5339. }
  5340. namespace
  5341. {
  5342. // the Fruity Vocoder's state for the slot's current band count (levels kept while the count matches, as FL does)
  5343. fvocoder::State vocoderState (const EffectSlot& slot)
  5344. {
  5345. auto s = fvocoder::parse (slot.state).value_or (fvocoder::State());
  5346. const auto bands = 4 << std::clamp ((int) std::lround (slot.params[0] * 5.0f), 0, 5);
  5347. if (s.bands != bands)
  5348. {
  5349. s.bands = bands;
  5350. s.levels.fill (1.0f);
  5351. }
  5352. s.order = 1 + std::clamp ((int) std::lround (slot.params[1] * 2.0f), 0, 2);
  5353. s.listen = std::clamp ((int) std::lround (slot.params[2] * 2.0f), 0, 2);
  5354. s.swap = slot.params[3] > 0.5f;
  5355. for (int c = 0; c < fvocoder::controls; ++c)
  5356. s.c[(std::size_t) c] = fvocoder::rawFromKnob (slot.params[(std::size_t) (4 + c)], c, s.c[(std::size_t) c]);
  5357. return s;
  5358. }
  5359. constexpr float maxBandLevel = 2.0f; // the strip spans 0…2 (1 = unchanged)
  5360. } // namespace
  5361. void EffectsPanel::setBandLevel (juce::Point<int> p)
  5362. {
  5363. const auto* s = slots();
  5364. if (s == nullptr || ! vocoderSelected())
  5365. return;
  5366. const auto st = vocoderState ((*s)[(std::size_t) selectedSlot]);
  5367. const auto area = bandLevelsBounds();
  5368. const auto band = juce::jlimit (0, st.bands - 1, (int) ((p.x - area.getX()) * st.bands / juce::jmax (1, area.getWidth())));
  5369. auto level = juce::jlimit (0.0f, maxBandLevel, maxBandLevel * (float) (area.getBottom() - p.y) / (float) area.getHeight());
  5370. if (std::abs (level - 1.0f) < 0.04f)
  5371. level = 1.0f; // snaps to the unchanged level
  5372. engine.editSong ([t = track, slot = selectedSlot, band, level] (Song& song) {
  5373. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  5374. auto state = vocoderState (fx);
  5375. state.levels[(std::size_t) band] = level;
  5376. fx.state = fvocoder::serialise (state);
  5377. });
  5378. }
  5379. void EffectsPanel::showBandLevelMenu()
  5380. {
  5381. juce::PopupMenu menu;
  5382. auto apply = [this] (float (*level) (int, int)) {
  5383. engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
  5384. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  5385. auto state = vocoderState (fx);
  5386. for (int k = 0; k < state.bands; ++k)
  5387. state.levels[(std::size_t) k] = level (k, state.bands);
  5388. fx.state = fvocoder::serialise (state);
  5389. });
  5390. };
  5391. menu.addItem (tr ("Reset band levels"), [apply] { apply ([] (int, int) { return 1.0f; }); });
  5392. menu.addItem (tr ("Brighter (tilt up)"), [apply] { apply ([] (int k, int n) { return 0.5f + (float) k / (float) std::max (1, n - 1); }); });
  5393. menu.addItem (tr ("Darker (tilt down)"), [apply] { apply ([] (int k, int n) { return 1.5f - (float) k / (float) std::max (1, n - 1); }); });
  5394. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  5395. }
  5396. void EffectsPanel::showGatePatterns()
  5397. {
  5398. // ready-made patterns (like Gross Beat's slots): value of step i of 32 (1/8 beat each)
  5399. struct Pattern
  5400. {
  5401. const char* name;
  5402. float (*level) (int);
  5403. };
  5404. static const Pattern patterns[] = {
  5405. { TR_NOOP ("All open"), [] (int) { return 1.0f; } },
  5406. { TR_NOOP ("1/2 beat gate"), [] (int i) { return (i % 4) < 2 ? 1.0f : 0.0f; } },
  5407. { TR_NOOP ("1 beat gate"), [] (int i) { return (i % 8) < 4 ? 1.0f : 0.0f; } },
  5408. { TR_NOOP ("Offbeat"), [] (int i) { return (i % 8) >= 4 ? 1.0f : 0.0f; } },
  5409. { TR_NOOP ("Sidechain (ramp per beat)"), [] (int i) { return std::min (1.0f, 0.15f + (float) (i % 8) / 5.0f); } },
  5410. { TR_NOOP ("Trance gate"), [] (int i) { return (i % 4) == 3 ? 0.0f : (i % 16) >= 12 ? 0.4f : 1.0f; } },
  5411. { TR_NOOP ("Fade-in over the bar"), [] (int i) { return (float) (i + 1) / 32.0f; } },
  5412. { TR_NOOP ("Fade-out over the bar"), [] (int i) { return 1.0f - (float) i / 32.0f; } },
  5413. };
  5414. juce::PopupMenu menu;
  5415. for (const auto& p : patterns)
  5416. menu.addItem (tr (p.name), [this, level = p.level] {
  5417. engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
  5418. auto& params = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params;
  5419. for (int i = 0; i < 32; ++i)
  5420. params[(std::size_t) i] = level (i);
  5421. });
  5422. });
  5423. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  5424. }
  5425. int EffectsPanel::knobAt (juce::Point<int> p) const
  5426. {
  5427. const auto* s = slots();
  5428. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
  5429. return -1;
  5430. if ((*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq || (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq)
  5431. return -1; // edited in its own window
  5432. const auto count = shownParams ((*s)[(std::size_t) selectedSlot]);
  5433. for (int i = gateSelected() ? 32 : 0; i < count; ++i)
  5434. if (knobBounds (i).contains (p))
  5435. return i;
  5436. return -1;
  5437. }
  5438. void EffectsPanel::paint (juce::Graphics& g)
  5439. {
  5440. const uitrace::Scope trace ("EffectsPanel paint", true, g.getClipBounds());
  5441. using namespace theme;
  5442. g.fillAll (colour::bg2);
  5443. g.setColour (colour::border);
  5444. g.drawVerticalLine (0, 0.0f, (float) getHeight());
  5445. const auto* s = slots();
  5446. if (s == nullptr)
  5447. return;
  5448. const auto& song = engine.getSong();
  5449. g.setColour (colour::textPrimary);
  5450. g.setFont (font (type::title, true));
  5451. textcache::drawText (g, tr ("Effects: {0}", { juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) }), 10, 4,
  5452. getWidth() - 70, panelHeader - 8, juce::Justification::centredLeft, true);
  5453. // input row: arm switch (inserts) and the audio input source with its level (the Master has one too, as in FL;
  5454. // REA round 143)
  5455. if (track >= 0 && track < (int) song.mixer.size())
  5456. {
  5457. const auto& mt = song.mixer[(std::size_t) track];
  5458. if (track > 0)
  5459. {
  5460. const auto armed = engine.isInsertArmed (track);
  5461. const auto a = armBounds().toFloat();
  5462. theme::fillRoundRect (g, a, radius::sm, armed ? colour::record.withAlpha (0.25f) : hoverInput == 1 ? colour::bg5 : colour::bg3);
  5463. const auto dot = a.withSizeKeepingCentre (11.0f, 11.0f);
  5464. g.setColour (armed ? colour::record : colour::bg0);
  5465. g.fillEllipse (dot);
  5466. g.setColour (armed ? colour::record.brighter (0.3f) : hoverInput == 1 ? colour::textSecondary : colour::borderStrong);
  5467. g.drawEllipse (dot, 1.0f);
  5468. if (mt.recordSafe)
  5469. {
  5470. g.setColour (colour::textDisabled);
  5471. g.drawLine (dot.getX() + 1.0f, dot.getBottom() - 1.0f, dot.getRight() - 1.0f, dot.getY() + 1.0f, 1.2f);
  5472. }
  5473. }
  5474. auto box = inputBoxBounds().toFloat();
  5475. // round 190ir: armed without an input records nothing (FL arms anyway; at FL's default "Post EQ" the take is the
  5476. // insert's own output, silence when no channel plays into it): the box says so in the record colour
  5477. const auto armedNoInput = mt.inputChannel < 0 && engine.isInsertArmed (track)
  5478. && std::none_of (song.channels.begin(), song.channels.end(), [t = track] (const ChannelDef& c) { return c.mixerTrack == t; });
  5479. theme::fillRoundRect (g, box, radius::sm, hoverInput == 2 ? colour::bg4 : colour::bg3);
  5480. g.setColour (armedNoInput ? colour::record : hoverInput == 2 ? colour::borderStrong : colour::border);
  5481. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  5482. // the level, as a thin bar along the bottom of the box (left over right)
  5483. if (mt.inputChannel >= 0)
  5484. {
  5485. const auto bar = box.reduced (4.0f, 0.0f).withTop (box.getBottom() - 5.0f).withHeight (3.0f);
  5486. g.setColour (colour::bg0);
  5487. g.fillRect (bar);
  5488. for (int side = 0; side < 2; ++side)
  5489. {
  5490. const auto db = juce::Decibels::gainToDecibels (inputLevel[(std::size_t) side], -60.0f);
  5491. const auto fill = juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 60.0f);
  5492. g.setColour (inputLevel[(std::size_t) side] >= 0.99f ? colour::record : colour::meterLow);
  5493. g.fillRect (bar.withHeight (1.5f).translated (0.0f, side * 1.5f).withWidth (bar.getWidth() * fill));
  5494. }
  5495. }
  5496. icons::draw (g, Icon::mic, box.withWidth (18.0f).reduced (2.0f).translated (3.0f, -1.0f), mt.inputChannel >= 0 ? colour::textPrimary : colour::textDisabled);
  5497. const auto names = engine.getInputChannelNames();
  5498. const auto label = mt.inputChannel >= 0 ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, names).c_str())
  5499. : armedNoInput ? tr ("Choose an input to record")
  5500. : tr ("No audio input");
  5501. g.setColour (mt.inputChannel >= 0 ? colour::textPrimary : armedNoInput ? colour::record : colour::textSecondary);
  5502. g.setFont (font (type::body));
  5503. textcache::drawText (g, label, box.withTrimmedLeft (24.0f).withTrimmedRight (18.0f).translated (0.0f, -1.0f).toNearestInt(), juce::Justification::centredLeft, true);
  5504. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, -1.0f), colour::textSecondary);
  5505. }
  5506. // the insert's effects switch
  5507. if (! s->empty())
  5508. {
  5509. const auto on = mixerops::anyEffectEnabled (song, track);
  5510. const auto r = fxSwitchBounds().toFloat();
  5511. theme::fillRoundRect (g, r, radius::sm, on ? colour::bg5 : colour::bg0);
  5512. g.setColour (muteLed (! on));
  5513. g.fillEllipse (r.withWidth (r.getHeight()).reduced (6.0f).translated (3.0f, 0.0f));
  5514. g.setColour (on ? colour::textPrimary : colour::textDisabled);
  5515. g.setFont (font (type::caption, true));
  5516. textcache::drawText (g, "FX", r.withTrimmedLeft (r.getHeight()).toNearestInt(), juce::Justification::centredLeft);
  5517. }
  5518. g.setFont (font (type::body));
  5519. // the 10 slots, as FL draws them: options arrow, name ("Slot N" when empty), mix knob, LED
  5520. // (rows: FL's slot places, an effect may sit below empty slots, round 170b)
  5521. for (int row = 0; row < maxEffectSlots; ++row)
  5522. {
  5523. const auto i = effectIn (row); // the effect shown here, -1 = empty
  5524. const auto r = slotBounds (row);
  5525. const auto filled = i >= 0;
  5526. const auto isSelected = i == selectedSlot && filled;
  5527. const auto slotHovered = row == hoverSlot && dragSlot < 0;
  5528. theme::fillRoundRect (g, r.toFloat(), radius::sm, isSelected ? colour::bg5 : filled ? (slotHovered ? colour::bg4 : colour::bg3) : (slotHovered ? colour::bg3 : colour::bg2.brighter (0.03f)));
  5529. g.setColour (slotHovered ? colour::borderStrong : colour::border);
  5530. g.drawRoundedRectangle (r.toFloat().reduced (0.5f), radius::sm, 1.0f);
  5531. if (isSelected)
  5532. {
  5533. theme::fillRoundRect (g, r.toFloat().withWidth (3.0f).reduced (0.0f, 3.0f), 1.5f, colour::accent);
  5534. }
  5535. {
  5536. const auto a = arrowBounds (row).toFloat().withSizeKeepingCentre (5.0f, 8.0f).translated (1.0f, 0.0f);
  5537. juce::Path tri;
  5538. tri.addTriangle (a.getX(), a.getY(), a.getRight(), a.getCentreY(), a.getX(), a.getBottom());
  5539. g.setColour (slotHovered && hoverArrow ? colour::textPrimary : colour::textSecondary.withAlpha (filled ? 1.0f : 0.6f));
  5540. g.fillPath (tri);
  5541. }
  5542. const auto ledArea = ledBounds (row).toFloat().withSizeKeepingCentre (8.0f, 8.0f);
  5543. const auto textArea = r.withTrimmedLeft (20).withTrimmedRight (46);
  5544. if (filled)
  5545. {
  5546. const auto& slot = (*s)[(std::size_t) i];
  5547. // "Low latency while recording" (round 190aq): a slot it bypasses now keeps its LED's place as an amber
  5548. // ring, its name dims and a badge says why; the slot's own on / off state is untouched
  5549. const auto lowLatency = engine.isSlotLowLatencyBypassed (track, i);
  5550. if (lowLatency)
  5551. {
  5552. g.setColour (colour::warning);
  5553. g.drawEllipse (ledArea.reduced (0.75f), 1.5f);
  5554. }
  5555. else
  5556. {
  5557. g.setColour (muteLed (! slot.enabled));
  5558. g.fillEllipse (ledArea);
  5559. }
  5560. if (slotHovered && hoverLed)
  5561. {
  5562. g.setColour (colour::textSecondary);
  5563. g.drawEllipse (ledArea.expanded (2.0f), 1.0f);
  5564. }
  5565. g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
  5566. // a LYNX substitute shows the plugin it stands in for, with a "LYNX" badge
  5567. const auto substitute = slot.isSubstitute();
  5568. auto name = quickpick::slotName (engine, slot); // (a plugin renamed in the Plugin database: its new name, round 165c)
  5569. if (slot.look != 0) // part of a Master look (round 189k, the Simple workflow's Finish dock)
  5570. name << " " << tr ("(look)");
  5571. if (goals::active (slot)) // a one-knob effect of the Simple workflow's dock (round 190bu): its goal's name too
  5572. name << " (" << (slot.goal == goals::punch ? trc ("@one-knob effect: Punch") : tr (goals::name (slot.goal))) << ")";
  5573. if (slot.sidechain > 0 && slot.sidechain < (int) engine.getSong().mixer.size())
  5574. name << juce::String::fromUTF8 (" \xe2\x86\x90 ") << juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) slot.sidechain].name.c_str());
  5575. auto text = textArea;
  5576. if (substitute)
  5577. {
  5578. const auto badge = text.removeFromRight (34).withSizeKeepingCentre (32, 14).toFloat();
  5579. const auto playing = engine.getSong().slotActive (slot); // off while the project's substitutes are bypassed
  5580. theme::fillRoundRect (g, badge, 3.0f, colour::info.withAlpha (playing ? 0.25f : 0.12f));
  5581. g.setColour (playing ? colour::info : colour::textDisabled);
  5582. const auto keep = g.getCurrentFont();
  5583. g.setFont (font (type::caption, true));
  5584. textcache::drawText (g, "LYNX", badge, juce::Justification::centred);
  5585. g.setFont (keep);
  5586. g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
  5587. }
  5588. if (lowLatency)
  5589. {
  5590. const auto label = tr ("LOW LAT");
  5591. const auto keep = g.getCurrentFont();
  5592. g.setFont (font (type::caption, true));
  5593. const auto width = juce::jmin (text.getWidth() / 2, juce::jmax (30, juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), label) + 8));
  5594. const auto badge = text.removeFromRight (width + 2).withSizeKeepingCentre (width, 14).toFloat();
  5595. theme::fillRoundRect (g, badge, 3.0f, colour::warning.withAlpha (0.22f));
  5596. g.setColour (colour::warning);
  5597. textcache::drawText (g, label, badge, juce::Justification::centred);
  5598. g.setFont (keep);
  5599. g.setColour (colour::textDisabled);
  5600. }
  5601. textcache::drawText (g, name, text, juce::Justification::centredLeft);
  5602. // slot's dry/wet knob
  5603. const auto mixActive = (hoverParam == mixParam && hoverSlot == row) || (dragParam == mixParam && selectedSlot == i);
  5604. drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), slot.mix, false,
  5605. slot.enabled ? (dragParam == mixParam && selectedSlot == i ? colour::accent : colour::info) : colour::textDisabled, mixActive);
  5606. }
  5607. else
  5608. {
  5609. // an empty slot keeps its controls in place (dimmed), as FL shows them
  5610. g.setColour (muteLed (false).withAlpha (0.3f));
  5611. g.fillEllipse (ledArea);
  5612. drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), 1.0f, false, colour::textDisabled.withAlpha (0.5f), false);
  5613. g.setColour (slotHovered ? colour::textSecondary : colour::textDisabled);
  5614. g.setFont (juce::Font (font (type::body)).italicised());
  5615. textcache::drawText (g, tr ("Slot {0}", { juce::String (row + 1) }), textArea, juce::Justification::centredLeft);
  5616. g.setFont (font (type::body));
  5617. }
  5618. }
  5619. paintEq (g);
  5620. g.reduceClipRegion (0, 0, getWidth(), bottomTop() - 6); // the selected effect's knobs stay above the EQ
  5621. if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot)) // where the dragged slot lands (FL: swaps with
  5622. { // the effect there, or takes the empty slot)
  5623. g.setColour (colour::accent);
  5624. g.drawRoundedRectangle (slotBounds (dropSlot).toFloat().reduced (0.5f), radius::sm, 2.0f);
  5625. }
  5626. if (selectedSlot < 0 || selectedSlot >= (int) s->size())
  5627. return;
  5628. const auto& slot = (*s)[(std::size_t) selectedSlot];
  5629. auto drawButton = [&g] (juce::Rectangle<int> button, const juce::String& text, Icon icon) {
  5630. theme::fillRoundRect (g, button.toFloat(), radius::md, colour::bg4);
  5631. const auto f = juce::Font (font (type::body));
  5632. const auto textWidth = juce::GlyphArrangement::getStringWidth (f, text);
  5633. auto content = button.toFloat().withSizeKeepingCentre (juce::jmin ((float) button.getWidth() - 12.0f, textWidth + 22.0f), (float) button.getHeight());
  5634. icons::draw (g, icon, content.removeFromLeft (16.0f).withSizeKeepingCentre (16.0f, 16.0f), colour::textSecondary);
  5635. content.removeFromLeft (6.0f);
  5636. g.setColour (colour::textPrimary);
  5637. g.setFont (f);
  5638. textcache::drawFittedText (g, text, content.toNearestInt(), juce::Justification::centredLeft, 1, 0.85f);
  5639. };
  5640. if (slot.kind == EffectKind::plugin)
  5641. {
  5642. const auto button = pluginButtonBounds();
  5643. drawButton (button, tr ("Open plugin interface"), Icon::plugin);
  5644. g.setColour (colour::textSecondary);
  5645. g.setFont (font (type::caption));
  5646. textcache::drawText (g, quickpick::slotName (engine, slot), button.translated (0, 34), juce::Justification::centred);
  5647. paintSidechainButton (g, slot);
  5648. return;
  5649. }
  5650. if (slot.kind == EffectKind::parametricEq)
  5651. {
  5652. const auto button = pluginButtonBounds();
  5653. drawButton (button, tr ("Open parametric EQ"), Icon::settings);
  5654. const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
  5655. drawParametricEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
  5656. return;
  5657. }
  5658. if (isSoundgoodizerApprox (slot)) // approximated without FL's preset files: its page edits Preset and Amount
  5659. {
  5660. const auto button = pluginButtonBounds();
  5661. drawButton (button, tr ("Open Soundgoodizer"), Icon::settings);
  5662. g.setColour (colour::textSecondary);
  5663. g.setFont (font (type::caption));
  5664. textcache::drawFittedText (g, tr ("Approximation (FL Studio's Soundgoodizer presets were not found on this computer)"),
  5665. button.translated (0, 34).withHeight (40), juce::Justification::centredTop, 2);
  5666. return;
  5667. }
  5668. if (slot.kind == EffectKind::facetEq)
  5669. {
  5670. const auto button = pluginButtonBounds();
  5671. drawButton (button, tr ("Open Facet EQ"), Icon::settings);
  5672. const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
  5673. drawFacetEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
  5674. return;
  5675. }
  5676. if (slot.kind == EffectKind::parallel) // container: list the branches
  5677. {
  5678. auto y = knobBounds (0).getY() - 28;
  5679. g.setColour (colour::textPrimary);
  5680. g.setFont (font (type::title, true));
  5681. textcache::drawText (g, juce::String::fromUTF8 (effectInfo (slot.kind).name), 10, y, getWidth() - 20, 20, juce::Justification::centredLeft);
  5682. g.setFont (font (type::small));
  5683. for (std::size_t b = 0; b < slot.branches.size(); ++b)
  5684. {
  5685. y += 22;
  5686. juce::String chain;
  5687. if (slot.branches[b].chain.empty())
  5688. chain = tr ("dry");
  5689. for (std::size_t c = 0; c < slot.branches[b].chain.size(); ++c)
  5690. chain += (c > 0 ? " -> " : "") + juce::String::fromUTF8 (effectInfo (slot.branches[b].chain[c].kind).name);
  5691. const auto line = tr ("Branch {0} (x{1}): {2}", { juce::String ((int) b + 1), juce::String (slot.branches[b].gain, 2), chain });
  5692. g.setColour (colour::textSecondary);
  5693. textcache::drawText (g, line, 14, y, getWidth() - 28, 20, juce::Justification::centredLeft, true);
  5694. }
  5695. return;
  5696. }
  5697. const auto& info = effectInfo (slot.kind);
  5698. const auto gate = slot.kind == EffectKind::volumeGate;
  5699. const auto vocoder = slot.kind == EffectKind::vocoder;
  5700. g.setColour (colour::textPrimary);
  5701. g.setFont (font (type::title, true));
  5702. const auto tune = slot.kind == EffectKind::lynxTune;
  5703. const auto editorButton = ! gate && ! vocoder && NativeEffectWindows::canOpen (slot.kind);
  5704. const auto titleY = (gate ? gateStepsBounds().getY() : vocoder ? bandLevelsBounds().getY() : tune ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 28;
  5705. const auto scButton = sidechainButtonBounds();
  5706. const auto titleRight = scButton.isEmpty() ? getWidth() - 10 - (editorButton ? editorButtonBounds().getWidth() + 6 : 0) : scButton.getX() - 6;
  5707. textcache::drawText (g, juce::String::fromUTF8 (info.name), 10, titleY, titleRight - 10, 20, juce::Justification::centredLeft, true);
  5708. if (slot.isSubstitute()) // which missing plugin this stands in for (the project keeps it)
  5709. {
  5710. const auto titleWidth = juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), juce::String::fromUTF8 (info.name));
  5711. g.setColour (colour::info);
  5712. g.setFont (font (type::caption));
  5713. const auto original = juce::String::fromUTF8 (substituteOriginalName (slot).c_str());
  5714. textcache::drawText (g, engine.getSong().substitutesBypassed ? tr ("LYNX SHARE substitute for {0} (bypassed)", { original }) : tr ("LYNX SHARE substitute for {0}", { original }),
  5715. 10 + titleWidth + 10, titleY,
  5716. juce::jmax (0, titleRight - 20 - titleWidth), 20, juce::Justification::centredLeft, true);
  5717. }
  5718. if (editorButton) // the effect's own window (FL's plugin window)
  5719. {
  5720. const auto b = editorButtonBounds().toFloat();
  5721. const auto hover = getMouseXYRelative().toFloat();
  5722. theme::fillRoundRect (g, b, radius::md, b.contains (hover) ? colour::bg5 : colour::bg4);
  5723. icons::draw (g, Icon::plugin, b.withWidth (22.0f).withSizeKeepingCentre (13.0f, 13.0f).translated (4.0f, 0.0f), colour::textSecondary);
  5724. g.setColour (colour::textPrimary);
  5725. g.setFont (font (type::small));
  5726. textcache::drawFittedText (g, tr ("Editor"), b.withTrimmedLeft (24.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
  5727. }
  5728. paintSidechainButton (g, slot);
  5729. if (tune) // the scale's notes on one octave; a note switched off is never a target
  5730. {
  5731. const auto area = tuneKeysBounds().toFloat();
  5732. const auto scaleMask = vocal::scaleMask ((vocal::Scale) lynxtune::scaleIndex (slot.params[lynxtune::scale]), lynxtune::keyIndex (slot.params[lynxtune::key]), 0xfff);
  5733. const auto custom = lynxtune::scaleIndex (slot.params[lynxtune::scale]) == (int) vocal::Scale::custom;
  5734. for (const auto black : { false, true })
  5735. for (int pc = 0; pc < 12; ++pc)
  5736. {
  5737. const auto isBlack = pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10;
  5738. if (isBlack != black)
  5739. continue;
  5740. const auto r = tuneKeyRect (area, pc).reduced (1.0f);
  5741. const auto on = slot.params[(std::size_t) (lynxtune::noteC + pc)] >= 0.5f;
  5742. const auto inScale = custom || (scaleMask & (1u << pc)) != 0;
  5743. auto fill = isBlack ? colour::bg0 : colour::bg2;
  5744. if (inScale && on)
  5745. fill = (slot.enabled ? colour::accent : colour::textDisabled).withAlpha (isBlack ? 0.85f : 0.65f);
  5746. theme::fillRoundRect (g, r, 2.0f, fill);
  5747. g.setColour (colour::gridBar);
  5748. g.drawRoundedRectangle (r, 2.0f, 1.0f);
  5749. if (inScale && ! on) // in the scale but switched off
  5750. {
  5751. g.setColour (colour::textSecondary);
  5752. g.drawLine (r.getX() + 3.0f, r.getBottom() - 3.0f, r.getRight() - 3.0f, r.getBottom() - 14.0f, 1.2f);
  5753. }
  5754. if (! isBlack)
  5755. {
  5756. static const char* names[12] { "C", "", "D", "", "E", "F", "", "G", "", "A", "", "B" };
  5757. g.setColour (inScale && on ? colour::textPrimary : colour::textSecondary);
  5758. g.setFont (font (type::caption));
  5759. textcache::drawText (g, names[pc], r.withTrimmedTop (r.getHeight() - 16.0f), juce::Justification::centred);
  5760. }
  5761. }
  5762. g.setColour (colour::textSecondary);
  5763. g.setFont (font (type::caption));
  5764. textcache::drawFittedText (g, tr ("Target notes: click a key to switch it off or on"), tuneKeysBounds().withY (tuneKeysBounds().getBottom() + 2).withHeight (14),
  5765. juce::Justification::centredLeft, 1, 0.8f);
  5766. }
  5767. if (vocoder) // the analysis bands' levels, low to high (FL's band level strip)
  5768. {
  5769. const auto st = vocoderState (slot);
  5770. const auto area = bandLevelsBounds().toFloat();
  5771. theme::fillRoundRect (g, area, radius::sm, colour::bg0);
  5772. const auto w = area.getWidth() / (float) st.bands;
  5773. const auto unity = area.getBottom() - area.getHeight() / maxBandLevel;
  5774. for (int k = 0; k < st.bands; ++k)
  5775. {
  5776. const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, st.levels[(std::size_t) k] / maxBandLevel);
  5777. g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha (k % 2 == 0 ? 1.0f : 0.8f));
  5778. g.fillRect (area.getX() + (float) k * w + (w > 4.0f ? 1.0f : 0.0f), area.getBottom() - h, juce::jmax (1.0f, w - (w > 4.0f ? 2.0f : 0.0f)), h);
  5779. }
  5780. g.setColour (colour::gridBar);
  5781. g.drawHorizontalLine ((int) unity, area.getX(), area.getRight());
  5782. g.setColour (colour::textSecondary);
  5783. g.setFont (font (type::caption));
  5784. textcache::drawFittedText (g, tr ("Band levels: draw them; right-click = presets"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
  5785. juce::Justification::centredLeft, 1, 0.8f);
  5786. }
  5787. if (gate) // 32 steps = 1 bar of 4 beats
  5788. {
  5789. const auto area = gateStepsBounds().toFloat();
  5790. theme::fillRoundRect (g, area, radius::sm, colour::bg0);
  5791. const auto w = area.getWidth() / 32.0f;
  5792. for (int i = 0; i < 32; ++i)
  5793. {
  5794. const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, slot.params[(std::size_t) i]);
  5795. g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha ((i / 8) % 2 == 0 ? 1.0f : 0.7f));
  5796. g.fillRect (area.getX() + i * w + 1.0f, area.getBottom() - h, w - 2.0f, h);
  5797. }
  5798. g.setColour (colour::gridBar);
  5799. for (int beat = 1; beat < 4; ++beat)
  5800. g.drawVerticalLine ((int) (area.getX() + beat * 8 * w), area.getY(), area.getBottom());
  5801. g.setColour (colour::textSecondary);
  5802. g.setFont (font (type::caption));
  5803. textcache::drawFittedText (g, tr ("1 bar: draw the steps; right-click = patterns"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
  5804. juce::Justification::centredLeft, 1, 0.8f);
  5805. }
  5806. for (int p = gate ? 32 : 0; p < shownParams (slot); ++p)
  5807. {
  5808. const auto r = knobBounds (p);
  5809. const auto value = slot.params[(std::size_t) p];
  5810. // 38 px knob; in tight grids (Effector) it shrinks to fit name and value below
  5811. const auto knobHeight = juce::jlimit (30, 44, r.getHeight() - 30);
  5812. drawKnob (g, r.withHeight (knobHeight).toFloat(), value, false, slot.enabled ? colour::knobArc : colour::textDisabled,
  5813. dragParam == p || (hoverParam == p && hoverSlot < 0));
  5814. g.setColour (colour::textSecondary);
  5815. g.setFont (font (type::caption));
  5816. // (round 190fg: through the translation table, as the generated editor page and the Pocket panels show it)
  5817. textcache::drawFittedText (g, tr (info.params[(std::size_t) p].name), r.getX(), r.getY() + knobHeight + 2, r.getWidth(), 14,
  5818. juce::Justification::centred, 1, 0.8f);
  5819. g.setColour (colour::textPrimary);
  5820. textcache::drawText (g, juce::String::fromUTF8 (formatEffectParam (slot.kind, p, value, song.bpm, slot.params).c_str()), r.getX(), r.getY() + knobHeight + 16,
  5821. r.getWidth(), 14, juce::Justification::centred);
  5822. }
  5823. }
  5824. bool EffectsPanel::refuseFrozenSlots (juce::Point<int> p)
  5825. {
  5826. const auto& song = engine.getSong();
  5827. const auto channel = freeze::frozenByInsert (song, track);
  5828. if (channel < 0)
  5829. return false;
  5830. bool inSlots = fxSwitchBounds().contains (p) || sidechainButtonBounds().contains (p) || knobAt (p) >= 0;
  5831. for (int row = 0; row < maxEffectSlots && ! inSlots; ++row)
  5832. inSlots = slotBounds (row).contains (p);
  5833. if (! inSlots)
  5834. return false;
  5835. ui::postNotice ({ tr ("{0} is frozen with its effects: Unfreeze the track to edit them", { juce::String::fromUTF8 (song.channels[(std::size_t) channel].name.c_str()) }), {} },
  5836. 3000);
  5837. return true;
  5838. }
  5839. void EffectsPanel::mouseDown (const juce::MouseEvent& e)
  5840. {
  5841. const auto* s = slots();
  5842. if (s == nullptr)
  5843. return;
  5844. if (refuseFrozenSlots (e.getPosition()))
  5845. return;
  5846. if (const auto sc = sidechainButtonBounds(); ! sc.isEmpty() && sc.contains (e.getPosition()))
  5847. {
  5848. pluginheader::showSidechainPicker (engine, track, selectedSlot, this, sc);
  5849. return;
  5850. }
  5851. // round 177d (LYNX's own; FL's insert EQ has no bypass): right-click the EQ's title bar to bypass it, its settings kept
  5852. if (eqShown() && eqFoldBounds().contains (e.getPosition()) && flmods::popup (e.mods) && track >= 0 && track < (int) engine.getSong().mixer.size())
  5853. {
  5854. const auto bypassed = engine.getSong().mixer[(std::size_t) track].eq.bypassed;
  5855. juce::PopupMenu menu;
  5856. menu.addItem (tr ("Bypass the EQ (its settings are kept)"), true, bypassed, [this, t = track] {
  5857. engine.editSong ([t] (Song& song) {
  5858. if (t >= 0 && t < (int) song.mixer.size())
  5859. song.mixer[(std::size_t) t].eq.bypassed = ! song.mixer[(std::size_t) t].eq.bypassed;
  5860. });
  5861. repaint();
  5862. });
  5863. menu.showMenuAsync (juce::PopupMenu::Options().withMousePosition());
  5864. return;
  5865. }
  5866. if (eqFoldBounds().contains (e.getPosition()) && e.mods.isLeftButtonDown())
  5867. {
  5868. eqFoldChoice = eqFolded ? 1 : 2;
  5869. refit();
  5870. repaint();
  5871. return;
  5872. }
  5873. // the built-in EQ and the output target (bottom section)
  5874. if (outputBounds().contains (e.getPosition()))
  5875. {
  5876. showOutputMenu();
  5877. return;
  5878. }
  5879. if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  5880. {
  5881. if (isEqPoint (eqControl))
  5882. {
  5883. dragParam = eqControl;
  5884. setEqFromGraph (eqPointBase - eqControl, e.getPosition());
  5885. return;
  5886. }
  5887. if (flmods::popup (e.mods))
  5888. ui::showValueMenu (*this, &engine, specFor (eqControl, -1), valueOf (eqControl, -1), [this, eqControl] (double v) { setValue (eqControl, -1, v); });
  5889. else if (ui::isResetClick (e))
  5890. setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
  5891. else
  5892. {
  5893. dragParam = eqControl;
  5894. drag.begin (e, valueOf (eqControl, -1));
  5895. showTip (eqControl, -1, false);
  5896. }
  5897. return;
  5898. }
  5899. if (track > 0 && armBounds().contains (e.getPosition()))
  5900. {
  5901. if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a)
  5902. mixerinput::chooseRecordTo (engine, track);
  5903. else
  5904. mixerinput::toggleArm (engine, track, this);
  5905. repaint();
  5906. return;
  5907. }
  5908. if (track >= 0 && inputBoxBounds().contains (e.getPosition()))
  5909. {
  5910. mixerinput::showMenu (engine, track, this);
  5911. return;
  5912. }
  5913. if (! s->empty() && fxSwitchBounds().contains (e.getPosition()))
  5914. {
  5915. if (flmods::popup (e.mods))
  5916. toggleAllWindows();
  5917. else
  5918. {
  5919. const auto on = ! mixerops::anyEffectEnabled (engine.getSong(), track);
  5920. engine.editSong ([t = track, on] (Song& song) { mixerops::setAllEffectsEnabled (song, t, on); });
  5921. }
  5922. return;
  5923. }
  5924. for (int row = 0; row < maxEffectSlots; ++row)
  5925. {
  5926. const auto r = slotBounds (row);
  5927. if (! r.contains (e.getPosition()))
  5928. continue;
  5929. const auto i = effectIn (row);
  5930. if (i < 0)
  5931. {
  5932. showAddMenu (row); // (FL: the plugin lands in this slot)
  5933. return;
  5934. }
  5935. if (arrowBounds (row).contains (e.getPosition())) // FL's slot options arrow
  5936. {
  5937. selectedSlot = i;
  5938. repaint();
  5939. showSlotMenu (i);
  5940. return;
  5941. }
  5942. selectedSlot = i;
  5943. repaint();
  5944. if (mixBounds (row).contains (e.getPosition()))
  5945. {
  5946. if (flmods::popup (e.mods))
  5947. ui::showValueMenu (*this, &engine, specFor (mixParam, i), valueOf (mixParam, i), [this, i] (double v) { setValue (mixParam, i, v); });
  5948. else if (ui::isResetClick (e))
  5949. {
  5950. setValue (mixParam, i, 1.0);
  5951. showTip (mixParam, i, true);
  5952. }
  5953. else
  5954. {
  5955. dragParam = mixParam;
  5956. dragStart = (*s)[(std::size_t) i].mix;
  5957. drag.begin (e, dragStart);
  5958. showTip (mixParam, i, false);
  5959. }
  5960. return;
  5961. }
  5962. if (flmods::popup (e.mods) || (e.mods.isShiftDown() && ! ledBounds (row).contains (e.getPosition()))) // (FL: Shift+click = the menu)
  5963. showSlotMenu (i);
  5964. else if (ledBounds (row).contains (e.getPosition())) // LED: bypass
  5965. engine.editSong ([t = track, i] (Song& song) {
  5966. auto& slot = song.mixer[(std::size_t) t].effects[(std::size_t) i];
  5967. slot.enabled = ! slot.enabled;
  5968. });
  5969. else
  5970. dragSlot = i; // dragging the name moves the effect to another slot (a click shows its window)
  5971. return;
  5972. }
  5973. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::plugin
  5974. && pluginButtonBounds().contains (e.getPosition()))
  5975. {
  5976. openPluginWindow (selectedSlot);
  5977. return;
  5978. }
  5979. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq
  5980. && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
  5981. {
  5982. ParametricEqWindows::open (engine, track, selectedSlot);
  5983. return;
  5984. }
  5985. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && isSoundgoodizerApprox ((*s)[(std::size_t) selectedSlot])
  5986. && pluginButtonBounds().contains (e.getPosition()))
  5987. {
  5988. NativeEffectWindows::open (engine, track, selectedSlot);
  5989. return;
  5990. }
  5991. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq
  5992. && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
  5993. {
  5994. FacetEqWindows::open (engine, track, selectedSlot);
  5995. return;
  5996. }
  5997. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind != EffectKind::volumeGate
  5998. && ! vocoderSelected() && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind)
  5999. && editorButtonBounds().contains (e.getPosition()))
  6000. {
  6001. openEditor (selectedSlot);
  6002. return;
  6003. }
  6004. if (vocoderSelected() && bandLevelsBounds().contains (e.getPosition()))
  6005. {
  6006. if (flmods::popup (e.mods))
  6007. showBandLevelMenu();
  6008. else
  6009. {
  6010. dragParam = bandLevelParam;
  6011. setBandLevel (e.getPosition());
  6012. }
  6013. return;
  6014. }
  6015. if (tuneSelected() && tuneKeysBounds().contains (e.getPosition()))
  6016. {
  6017. toggleTuneNote (e.getPosition());
  6018. return;
  6019. }
  6020. if (gateSelected() && gateStepsBounds().contains (e.getPosition()))
  6021. {
  6022. if (flmods::popup (e.mods))
  6023. showGatePatterns();
  6024. else
  6025. {
  6026. dragParam = gateStepParam;
  6027. setGateStep (e.getPosition());
  6028. }
  6029. return;
  6030. }
  6031. dragParam = knobAt (e.getPosition());
  6032. if (dragParam >= 0 && flmods::popup (e.mods))
  6033. {
  6034. const auto p = dragParam;
  6035. ui::showValueMenu (*this, &engine, specFor (p, selectedSlot), valueOf (p, selectedSlot),
  6036. [this, p, slot = selectedSlot] (double v) { setValue (p, slot, v); });
  6037. dragParam = -1;
  6038. return;
  6039. }
  6040. if (dragParam >= 0 && ui::isResetClick (e))
  6041. {
  6042. setValue (dragParam, selectedSlot, specFor (dragParam, selectedSlot).defaultValue);
  6043. showTip (dragParam, selectedSlot, true);
  6044. dragParam = -1;
  6045. return;
  6046. }
  6047. if (dragParam >= 0)
  6048. {
  6049. dragStart = (*s)[(std::size_t) selectedSlot].params[(std::size_t) dragParam];
  6050. drag.begin (e, dragStart);
  6051. showTip (dragParam, selectedSlot, false);
  6052. }
  6053. }
  6054. ui::ValueSpec EffectsPanel::specFor (int param, int slot) const
  6055. {
  6056. const auto& song = engine.getSong();
  6057. ui::ValueSpec spec;
  6058. spec.pixelsForRange = 150.0;
  6059. if (isEqParam (param)) // the built-in EQ (stored 0..1 here: gain ±18 dB, frequency 10 Hz..16 kHz log, width)
  6060. {
  6061. const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
  6062. const juce::String whatName = what == 0 ? tr ("level") : what == 1 ? tr ("frequency") : tr ("width");
  6063. spec.name = juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) + " - " + tr ("EQ band {0} ({1})", { juce::String (band + 1), tr (eqBandNames[band]) })
  6064. + " " + whatName;
  6065. TrackEq defaults;
  6066. spec.defaultValue = eqToValue (defaults, band, what);
  6067. spec.toText = [band, what] (double v) {
  6068. TrackEq eq;
  6069. eqFromValue (eq, band, what, (float) v);
  6070. const auto b = (std::size_t) band;
  6071. return what == 0 ? juce::String (eq.gainDb[b], 1) + " dB"
  6072. : what == 1 ? (eq.hz[b] >= 1000.0f ? juce::String (eq.hz[b] / 1000.0f, 2) + " kHz" : juce::String ((int) eq.hz[b]) + " Hz")
  6073. : juce::String (eq.width[b], 2);
  6074. };
  6075. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  6076. return spec;
  6077. }
  6078. if (const auto* s = slots(); s == nullptr || slot < 0 || slot >= (int) s->size())
  6079. return spec;
  6080. const auto& fx = (*slots())[(std::size_t) slot];
  6081. const auto& info = effectInfo (fx.kind);
  6082. const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str());
  6083. if (param == mixParam)
  6084. {
  6085. spec = ui::percentSpec (trackName + " - " + utf8 (info.name) + " - " + tr ("Mix"), 1.0);
  6086. spec.target = AutomationTarget { AutomationTargetKind::effectMix, track, slot };
  6087. return spec;
  6088. }
  6089. if (param < 0 || param >= (int) info.params.size())
  6090. return spec;
  6091. spec.name = trackName + " - " + utf8 (info.name) + " - " + tr (info.params[(std::size_t) param].name); // (as "Mix" above)
  6092. spec.defaultValue = info.params[(std::size_t) param].defaultValue;
  6093. spec.toText = [kind = fx.kind, param, bpm = song.bpm, context = fx.params] (double v) { return utf8 (formatEffectParam (kind, param, (float) v, bpm, context).c_str()); };
  6094. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  6095. spec.target = AutomationTarget { AutomationTargetKind::effectParam, track, slot, param };
  6096. return spec;
  6097. }
  6098. double EffectsPanel::valueOf (int param, int slot) const
  6099. {
  6100. if (isEqParam (param))
  6101. return track >= 0 && track < (int) engine.getSong().mixer.size()
  6102. ? eqToValue (engine.getSong().mixer[(std::size_t) track].eq, (eqParamBase - param) / 3, (eqParamBase - param) % 3)
  6103. : 0.0;
  6104. const auto* s = slots();
  6105. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6106. return 0.0;
  6107. const auto& fx = (*s)[(std::size_t) slot];
  6108. return param == mixParam ? fx.mix : (param >= 0 && param < (int) fx.params.size() ? fx.params[(std::size_t) param] : 0.0f);
  6109. }
  6110. void EffectsPanel::setValue (int param, int slot, double value)
  6111. {
  6112. if (isEqParam (param))
  6113. {
  6114. engine.editSong ([t = track, band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3, v = (float) value] (Song& song) {
  6115. if (t < (int) song.mixer.size())
  6116. eqFromValue (song.mixer[(std::size_t) t].eq, band, what, v);
  6117. });
  6118. return;
  6119. }
  6120. const auto* s = slots();
  6121. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6122. return;
  6123. if (param == mixParam)
  6124. engine.editSong ([t = track, slot, v = (float) value] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) slot].mix = v; });
  6125. else if (param >= 0)
  6126. engine.editSong ([t = track, slot, param, v = (float) value] (Song& song) {
  6127. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) param] = v;
  6128. });
  6129. }
  6130. int EffectsPanel::mixKnobAt (juce::Point<int> p) const
  6131. {
  6132. for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
  6133. if (mixBounds (rowOf (i)).contains (p))
  6134. return i;
  6135. return -1;
  6136. }
  6137. void EffectsPanel::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
  6138. {
  6139. // a spin that is scrolling the mixer goes on scrolling over the EQ, the knobs and the slot names (round 169c)
  6140. if (ui::wheelScrolling())
  6141. {
  6142. ui::noteWheelScroll();
  6143. juce::Component::mouseWheelMove (e, wheel);
  6144. return;
  6145. }
  6146. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (e.getPosition()))
  6147. return;
  6148. if (auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  6149. {
  6150. if (isEqPoint (eqControl)) // the wheel over a handle changes the band's width
  6151. eqControl = eqParamBase - (eqPointBase - eqControl) * 3 - 2;
  6152. if (const auto v = ui::wheelValue (valueOf (eqControl, -1), e, wheel, specFor (eqControl, -1)))
  6153. {
  6154. setValue (eqControl, -1, *v);
  6155. showTip (eqControl, -1, true);
  6156. }
  6157. return;
  6158. }
  6159. if (const auto slot = mixKnobAt (e.getPosition()); slot >= 0)
  6160. {
  6161. if (const auto v = ui::wheelValue (valueOf (mixParam, slot), e, wheel, specFor (mixParam, slot)))
  6162. {
  6163. setValue (mixParam, slot, *v);
  6164. showTip (mixParam, slot, true);
  6165. }
  6166. return;
  6167. }
  6168. if (const auto p = knobAt (e.getPosition()); p >= 0)
  6169. {
  6170. if (const auto v = ui::wheelValue (valueOf (p, selectedSlot), e, wheel, specFor (p, selectedSlot)))
  6171. {
  6172. setValue (p, selectedSlot, *v);
  6173. showTip (p, selectedSlot, true);
  6174. }
  6175. return;
  6176. }
  6177. // FL (REA FUN_012ab750): the wheel over a slot moves its effect one slot up or down (into an empty slot too,
  6178. // wrapping around the 10 slots) and the mouse pointer follows it. A trackpad's small steps add up to one move.
  6179. if (const auto slot = slotAt (e.getPosition()); slot >= 0)
  6180. {
  6181. const auto delta = (wheel.isReversed ? -1.0 : 1.0) * (wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX);
  6182. if (wheelSlot != slot || juce::Time::getMillisecondCounter() - wheelTime > 400)
  6183. wheelAccumulator = 0.0;
  6184. wheelSlot = slot;
  6185. wheelTime = juce::Time::getMillisecondCounter();
  6186. const auto steps = controls::slotWheelSteps (wheelAccumulator, delta, wheel.isSmooth, wheel.isInertial);
  6187. if (steps == 0)
  6188. return;
  6189. int now = -1;
  6190. engine.editSongStructural ([t = track, slot, steps, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, steps > 0 ? -1 : 1); });
  6191. if (now >= 0)
  6192. {
  6193. selectedSlot = wheelSlot = now;
  6194. const auto target = slotBounds (rowOf (now));
  6195. juce::Desktop::getInstance().getMainMouseSource().setScreenPosition (localPointToGlobal (juce::Point<int> (e.x, target.getCentreY())).toFloat());
  6196. }
  6197. repaint();
  6198. return;
  6199. }
  6200. ui::noteWheelScroll();
  6201. juce::Component::mouseWheelMove (e, wheel);
  6202. }
  6203. ui::Hint EffectsPanel::hintAt (juce::Point<int> p)
  6204. {
  6205. const auto gesture = ui::valueGestures();
  6206. if (isEqParam (dragParam))
  6207. return ui::valueHint (specFor (dragParam, -1), valueOf (dragParam, -1), gesture);
  6208. if (const auto eqControl = eqControlAt (p); eqControl != 0)
  6209. {
  6210. if (isEqParam (eqControl))
  6211. return ui::valueHint (specFor (eqControl, -1), valueOf (eqControl, -1), gesture);
  6212. ui::Hint h;
  6213. const auto band = eqPointBase - eqControl;
  6214. h.text = tr ("EQ: [LMB] drag the band's frequency and level [Wheel] width [2xLMB] back to 0 dB");
  6215. h.value = tr ("Band {0}", { juce::String (band + 1) }) + " - " + tr (eqBandNames[band]);
  6216. return h;
  6217. }
  6218. if (slots() != nullptr && eqFoldBounds().contains (p))
  6219. {
  6220. ui::Hint h;
  6221. h.text = (eqFolded ? tr ("Insert EQ (folded): [LMB] unfold it") : tr ("Insert EQ: [LMB] fold it (it folds by itself when the mixer is short)"))
  6222. + " " + tr ("[RMB] bypass");
  6223. return h;
  6224. }
  6225. if (outputBounds().contains (p))
  6226. {
  6227. ui::Hint h;
  6228. h.text = track == 0 ? tr ("Audio output target: the outputs of your audio device the Master plays on [LMB] choose")
  6229. : tr ("Audio output target: through the Master by default; optional: also straight to an output of your audio interface (a mono output too) [LMB] choose");
  6230. h.value = outputName();
  6231. h.hasMenu = true;
  6232. return h;
  6233. }
  6234. if (dragParam == mixParam || (dragParam >= 0 && drag.isActive()))
  6235. return ui::valueHint (specFor (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot),
  6236. valueOf (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot), gesture);
  6237. if (const auto slot = mixKnobAt (p); slot >= 0)
  6238. return ui::valueHint (specFor (mixParam, slot), valueOf (mixParam, slot), gesture);
  6239. if (const auto param = knobAt (p); param >= 0)
  6240. return ui::valueHint (specFor (param, selectedSlot), valueOf (param, selectedSlot), gesture);
  6241. ui::Hint h;
  6242. if (const auto sc = sidechainButtonBounds(); ! sc.isEmpty() && sc.contains (p))
  6243. {
  6244. h.text = tr ("Sidechain input: the insert this effect listens to. Picking one routes it here at level 0; it keeps its own outputs [LMB] choose");
  6245. h.hasMenu = true;
  6246. return h;
  6247. }
  6248. if (const auto* s = slots(); s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size()
  6249. && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind) && editorButtonBounds().contains (p))
  6250. {
  6251. h.text = tr ("Open the effect's window (its full controls, as in FL); clicking the slot's name does the same");
  6252. return h;
  6253. }
  6254. if (track > 0 && armBounds().contains (p))
  6255. {
  6256. h.text = mixerinput::armHint (engine, track);
  6257. h.hasMenu = true;
  6258. return h;
  6259. }
  6260. if (track >= 0 && inputBoxBounds().contains (p))
  6261. {
  6262. h.text = track == 0 ? tr ("Audio input source: the microphone or interface input the Master plays (through its effects) [LMB] choose")
  6263. : tr ("Audio input source: the microphone or interface input this insert plays and records [LMB] choose");
  6264. h.hasMenu = true;
  6265. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  6266. if (mt.inputChannel >= 0)
  6267. h.value = juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str());
  6268. return h;
  6269. }
  6270. if (fxSwitchBounds().contains (p) && slots() != nullptr && ! slots()->empty())
  6271. {
  6272. h.text = tr ("All effects of this insert on/off; right-click opens or closes their plugin windows");
  6273. h.hasMenu = true;
  6274. return h;
  6275. }
  6276. for (int i = 0; i < maxEffectSlots; ++i)
  6277. if (slotBounds (i).contains (p))
  6278. {
  6279. const auto used = effectIn (i) >= 0;
  6280. if (used && engine.isSlotLowLatencyBypassed (track, effectIn (i))) // round 190aq
  6281. {
  6282. const auto ms = 1000.0 * engine.lowLatencyBypassedLatency (track, effectIn (i)) / juce::jmax (1.0, engine.getTransport().sampleRate.load());
  6283. h.text = tr ("Bypassed by \"Low latency while recording\": this effect adds {0} ms of latency and an armed or monitored insert plays through it. It comes back when that insert is disarmed",
  6284. { juce::String (ms, ms < 10.0 ? 1 : 0) });
  6285. h.hasMenu = true;
  6286. return h;
  6287. }
  6288. h.text = used ? (arrowBounds (i).contains (p) ? tr ("Effect slot options: replace, move, delete...")
  6289. : tr ("Effect slot: click shows or hides its window (and its knobs below), the LED bypasses, the wheel or a drag moves it up or down, right-click: options"))
  6290. : tr ("Empty slot: click to add an effect");
  6291. h.hasMenu = used;
  6292. }
  6293. return h;
  6294. }
  6295. void EffectsPanel::mouseDrag (const juce::MouseEvent& e)
  6296. {
  6297. if (dragSlot >= 0)
  6298. {
  6299. if (e.getDistanceFromDragStart() > 4)
  6300. {
  6301. const auto target = juce::jlimit (0, maxEffectSlots - 1, (e.y - slotsTop) / slotHeight); // (empty slots too, as FL)
  6302. if (target != dropSlot)
  6303. {
  6304. dropSlot = target;
  6305. setMouseCursor (juce::MouseCursor::DraggingHandCursor);
  6306. repaint();
  6307. }
  6308. }
  6309. return;
  6310. }
  6311. if (isEqPoint (dragParam))
  6312. {
  6313. setEqFromGraph (eqPointBase - dragParam, e.getPosition());
  6314. return;
  6315. }
  6316. if (isEqParam (dragParam))
  6317. {
  6318. setValue (dragParam, -1, drag.update (e, specFor (dragParam, -1)));
  6319. showTip (dragParam, -1, false);
  6320. return;
  6321. }
  6322. if (dragParam == gateStepParam)
  6323. {
  6324. setGateStep (e.getPosition());
  6325. return;
  6326. }
  6327. if (dragParam == bandLevelParam)
  6328. {
  6329. setBandLevel (e.getPosition());
  6330. return;
  6331. }
  6332. if (dragParam == mixParam)
  6333. {
  6334. setValue (mixParam, selectedSlot, drag.update (e, specFor (mixParam, selectedSlot)));
  6335. showTip (mixParam, selectedSlot, false);
  6336. return;
  6337. }
  6338. if (dragParam < 0)
  6339. return;
  6340. setValue (dragParam, selectedSlot, drag.update (e, specFor (dragParam, selectedSlot)));
  6341. showTip (dragParam, selectedSlot, false);
  6342. }
  6343. void EffectsPanel::showTip (int param, int slot, bool transient)
  6344. {
  6345. if (isEqParam (param))
  6346. {
  6347. const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
  6348. const auto area = what == 0 ? eqFaderBounds (band) : eqKnobBounds (band, what);
  6349. const auto spec = specFor (param, -1);
  6350. ui::postHint (ui::valueHint (spec, valueOf (param, -1), ui::valueGestures()));
  6351. if (transient)
  6352. ui::flashValueTip (*this, area, spec.text (valueOf (param, -1)));
  6353. else
  6354. ui::showValueTip (*this, area, spec.text (valueOf (param, -1)));
  6355. return;
  6356. }
  6357. const auto* s = slots();
  6358. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6359. return;
  6360. const auto area = param == mixParam ? mixBounds (rowOf (slot)) : knobBounds (param).withHeight (juce::jlimit (30, 44, knobBounds (param).getHeight() - 30));
  6361. const auto text = specFor (param, slot).text (valueOf (param, slot));
  6362. ui::postHint (ui::valueHint (specFor (param, slot), valueOf (param, slot), ui::valueGestures()));
  6363. if (transient)
  6364. ui::flashValueTip (*this, area, text);
  6365. else
  6366. ui::showValueTip (*this, area, text);
  6367. }
  6368. void EffectsPanel::mouseMove (const juce::MouseEvent& e)
  6369. {
  6370. const auto p = e.getPosition();
  6371. auto slot = -1; // (a row)
  6372. auto param = -1;
  6373. auto led = false;
  6374. for (int i = 0; i < maxEffectSlots; ++i)
  6375. if (slotBounds (i).contains (p))
  6376. slot = i;
  6377. if (const auto m = mixKnobAt (p); m >= 0)
  6378. {
  6379. slot = rowOf (m);
  6380. param = mixParam;
  6381. }
  6382. else if (slot < 0)
  6383. param = knobAt (p);
  6384. else
  6385. led = p.x < slotBounds (slot).getX() + 22;
  6386. const auto input = track > 0 && armBounds().contains (p) ? 1 : track >= 0 && inputBoxBounds().contains (p) ? 2 : 0;
  6387. const auto eq = eqControlAt (p);
  6388. const auto output = outputBounds().contains (p);
  6389. auto arrow = false;
  6390. for (int i = 0; i < maxEffectSlots; ++i)
  6391. if (arrowBounds (i).contains (p))
  6392. {
  6393. slot = i;
  6394. arrow = true;
  6395. }
  6396. if (slot >= 0)
  6397. led = ledBounds (slot).contains (p);
  6398. if (const auto sc = sidechainButtonBounds(); sc.contains (p) != hoverSidechain) // round 177b
  6399. {
  6400. hoverSidechain = ! hoverSidechain;
  6401. repaint (sc);
  6402. }
  6403. if (slot != hoverSlot || param != hoverParam || led != hoverLed || input != hoverInput || eq != hoverEq || output != hoverOutput || arrow != hoverArrow)
  6404. {
  6405. hoverEq = eq;
  6406. hoverOutput = output;
  6407. hoverArrow = arrow;
  6408. hoverInput = input;
  6409. hoverSlot = slot;
  6410. hoverParam = param;
  6411. hoverLed = led;
  6412. repaint();
  6413. }
  6414. }
  6415. void EffectsPanel::mouseExit (const juce::MouseEvent&)
  6416. {
  6417. if (hoverSlot >= 0 || hoverParam != -1 || hoverInput != 0 || hoverEq != 0 || hoverOutput || hoverArrow)
  6418. {
  6419. hoverEq = 0;
  6420. hoverOutput = hoverArrow = false;
  6421. hoverInput = 0;
  6422. hoverSlot = hoverParam = -1;
  6423. hoverLed = false;
  6424. repaint();
  6425. }
  6426. }
  6427. void EffectsPanel::mouseUp (const juce::MouseEvent& e)
  6428. {
  6429. // a click on the slot's name (not a drag, not the second click of a double-click) shows or hides its window (FL)
  6430. if (dragSlot >= 0 && dropSlot < 0 && ! e.mouseWasDraggedSinceMouseDown() && e.getNumberOfClicks() == 1)
  6431. {
  6432. const auto slot = dragSlot;
  6433. dragSlot = -1;
  6434. toggleEditor (slot);
  6435. }
  6436. if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot))
  6437. {
  6438. bool moved = false;
  6439. engine.editSongStructural ([t = track, from = dragSlot, to = dropSlot, &moved] (Song& song) { moved = mixerops::moveEffectToRow (song, t, from, to); });
  6440. if (moved)
  6441. selectedSlot = effectIn (dropSlot);
  6442. }
  6443. if (dragSlot >= 0)
  6444. setMouseCursor (juce::MouseCursor::NormalCursor);
  6445. dragSlot = dropSlot = -1;
  6446. repaint();
  6447. dragParam = -1;
  6448. drag.end();
  6449. ui::hideValueTip();
  6450. ui::clearPostedHint();
  6451. }
  6452. void EffectsPanel::mouseDoubleClick (const juce::MouseEvent& e)
  6453. {
  6454. if (refuseFrozenSlots (e.getPosition()))
  6455. return;
  6456. if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  6457. {
  6458. if (isEqPoint (eqControl)) // the band back to 0 dB
  6459. setValue (eqParamBase - (eqPointBase - eqControl) * 3, -1, specFor (eqParamBase, -1).defaultValue);
  6460. else
  6461. setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
  6462. return;
  6463. }
  6464. for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
  6465. if (mixBounds (rowOf (i)).contains (e.getPosition()))
  6466. {
  6467. engine.editSong ([t = track, i] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) i].mix = 1.0f; });
  6468. return;
  6469. }
  6470. else if (slotBounds (rowOf (i)).contains (e.getPosition()) && ! arrowBounds (rowOf (i)).contains (e.getPosition()) && ! ledBounds (rowOf (i)).contains (e.getPosition()))
  6471. {
  6472. openEditor (i); // (the first click opened it, round 170b): it stays open and comes to the front
  6473. return;
  6474. }
  6475. const auto p = knobAt (e.getPosition());
  6476. if (p < 0)
  6477. return;
  6478. const auto kind = (*slots())[(std::size_t) selectedSlot].kind;
  6479. const auto value = effectInfo (kind).params[(std::size_t) p].defaultValue;
  6480. engine.editSong ([t = track, slot = selectedSlot, p, value] (Song& song) {
  6481. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) p] = value;
  6482. });
  6483. }
  6484. bool EffectsPanel::isInterestedInDragSource (const SourceDetails& details)
  6485. {
  6486. return (BrowserComponent::isBrowserDrag (details) && BrowserComponent::draggedFile (details).hasFileExtension ("fst;adv;adg"))
  6487. || BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details);
  6488. }
  6489. void EffectsPanel::itemDropped (const SourceDetails& details)
  6490. {
  6491. if (BrowserComponent::isGeneratorDrag (details))
  6492. {
  6493. if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr
  6494. && track >= 0 && track < (int) engine.getSong().mixer.size())
  6495. onInstrumentDropped (track, std::move (*c));
  6496. return;
  6497. }
  6498. if (BrowserComponent::isEffectDrag (details))
  6499. {
  6500. if (auto fx = BrowserComponent::draggedEffect (details))
  6501. dropEffect (std::move (*fx), details.localPosition);
  6502. return;
  6503. }
  6504. dropPreset (BrowserComponent::draggedFile (details), details.localPosition);
  6505. }
  6506. bool EffectsPanel::isInterestedInFileDrag (const juce::StringArray& files)
  6507. {
  6508. // FL presets (.fst) and, round 190fm, Live's device / rack presets the user owns (.adv / .adg, core/AlsImport.h)
  6509. return files.size() == 1 && juce::File (files[0]).hasFileExtension ("fst;adv;adg");
  6510. }
  6511. void EffectsPanel::filesDropped (const juce::StringArray& files, int x, int y)
  6512. {
  6513. if (! files.isEmpty())
  6514. dropPreset (juce::File (files[0]), { x, y });
  6515. }
  6516. bool EffectsPanel::dropPreset (const juce::File& file, juce::Point<int> position)
  6517. {
  6518. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (position))
  6519. return false;
  6520. juce::MemoryBlock data;
  6521. if (slots() == nullptr || ! file.loadFileAsData (data))
  6522. return false;
  6523. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  6524. if (file.hasFileExtension ("adv;adg")) // round 190fm: a Live device or Audio Effect Rack preset → LYNX's own engines
  6525. {
  6526. std::string error;
  6527. if (auto live = importLiveDevicePreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), {}, &error))
  6528. return dropEffect (std::move (live->slot), position);
  6529. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Preset"),
  6530. tr ("LYNX SHARE can't build an effect from this preset."));
  6531. return false;
  6532. }
  6533. const auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm, natives::flDataReader (flStudioAccess()));
  6534. if (! fx)
  6535. {
  6536. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Preset"),
  6537. tr ("LYNX SHARE can't build an effect from this preset."));
  6538. return false;
  6539. }
  6540. return dropEffect (*fx, position);
  6541. }
  6542. bool EffectsPanel::dropEffect (EffectSlot fx, juce::Point<int> position)
  6543. {
  6544. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (position))
  6545. return false;
  6546. if (slots() == nullptr)
  6547. return false;
  6548. auto target = -1, emptyRow = -1;
  6549. for (int row = 0; row < maxEffectSlots; ++row)
  6550. if (slotBounds (row).contains (position))
  6551. {
  6552. target = effectIn (row);
  6553. emptyRow = target < 0 ? row : -1;
  6554. }
  6555. if (target < 0 && (int) slots()->size() >= maxEffectSlots)
  6556. return false;
  6557. int added = -1;
  6558. engine.editSong ([t = track, target, emptyRow, &added, fx = std::move (fx)] (Song& song) {
  6559. auto& effects = song.mixer[(std::size_t) t].effects;
  6560. if (target >= 0 && target < (int) effects.size())
  6561. effects[(std::size_t) target] = fx;
  6562. else if (emptyRow >= 0) // dropped on an empty slot: it lands there (FL)
  6563. added = mixerops::insertEffectAtRow (song, t, fx, emptyRow);
  6564. else
  6565. effects.push_back (fx);
  6566. });
  6567. selectedSlot = target >= 0 ? target : added >= 0 ? added : (int) slots()->size() - 1;
  6568. repaint();
  6569. return true;
  6570. }
  6571. juce::Rectangle<int> EffectsPanel::fxSwitchBounds() const
  6572. {
  6573. return { getWidth() - 58, 6, 48, panelHeader - 12 };
  6574. }
  6575. int EffectsPanel::slotAt (juce::Point<int> p) const
  6576. {
  6577. const auto* s = slots();
  6578. for (int i = 0; s != nullptr && i < (int) s->size(); ++i)
  6579. if (const auto row = rowOf (i); slotBounds (row).contains (p) && ! mixBounds (row).contains (p) && ! ledBounds (row).contains (p) && ! arrowBounds (row).contains (p))
  6580. return i;
  6581. return -1;
  6582. }
  6583. void EffectsPanel::toggleAllWindows()
  6584. {
  6585. // opens every plugin effect window of the insert, or closes them all when one is open
  6586. const auto* s = slots();
  6587. if (s == nullptr)
  6588. return;
  6589. bool anyOpen = false;
  6590. for (int i = 0; i < (int) s->size(); ++i)
  6591. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
  6592. anyOpen = anyOpen || PluginWindows::isOpen (p->getInstance());
  6593. for (int i = 0; i < (int) s->size(); ++i)
  6594. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
  6595. {
  6596. if (anyOpen)
  6597. PluginWindows::close (p->getInstance());
  6598. else
  6599. openPluginWindow (i);
  6600. }
  6601. }
  6602. juce::Rectangle<int> EffectsPanel::pluginButtonBounds() const
  6603. {
  6604. return { 20, slotsTop + maxEffectSlots * slotHeight + 30, getWidth() - 40, 30 };
  6605. }
  6606. void EffectsPanel::openEditor (int slot)
  6607. {
  6608. if (freeze::frozenByInsert (engine.getSong(), track) >= 0) // (round 190ff: its effects are not loaded)
  6609. return;
  6610. const auto* s = slots();
  6611. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6612. return;
  6613. const auto kind = (*s)[(std::size_t) slot].kind;
  6614. if (kind == EffectKind::plugin)
  6615. openPluginWindow (slot);
  6616. else if (kind == EffectKind::parametricEq)
  6617. ParametricEqWindows::open (engine, track, slot);
  6618. else if (NativeEffectWindows::canOpen ((*s)[(std::size_t) slot]))
  6619. NativeEffectWindows::open (engine, track, slot);
  6620. }
  6621. void EffectsPanel::toggleEditor (int slot)
  6622. {
  6623. if (freeze::frozenByInsert (engine.getSong(), track) >= 0) // (round 190ff: its effects are not loaded)
  6624. return;
  6625. const auto* s = slots();
  6626. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6627. return;
  6628. // FL (REA FUN_012bde10, the slot name button's click): the plugin's editor is shown, or hidden when it shows
  6629. if ((*s)[(std::size_t) slot].kind == EffectKind::plugin)
  6630. {
  6631. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()); p != nullptr && PluginWindows::isOpen (p->getInstance()))
  6632. {
  6633. PluginWindows::close (p->getInstance());
  6634. return;
  6635. }
  6636. openPluginWindow (slot);
  6637. return;
  6638. }
  6639. if (! ui::SlotGoneWatcher::closeWindow (engine, track, slot))
  6640. openEditor (slot);
  6641. }
  6642. juce::Rectangle<int> EffectsPanel::editorButtonBounds() const
  6643. {
  6644. // on the title row of the selected effect's knobs
  6645. return { getWidth() - 96, (tuneSelected() ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 29, 86, 20 };
  6646. }
  6647. void EffectsPanel::paintSidechainButton (juce::Graphics& g, const EffectSlot& slot)
  6648. {
  6649. using namespace theme;
  6650. const auto b = sidechainButtonBounds().toFloat();
  6651. if (b.isEmpty())
  6652. return;
  6653. const auto source = pluginheader::sidechainSourceText (engine.getSong(), slot);
  6654. const auto hover = b.contains (getMouseXYRelative().toFloat());
  6655. theme::fillRoundRect (g, b, radius::md, hover ? colour::bg5 : colour::bg4);
  6656. if (source.isNotEmpty()) // linked: the accent edge, as a lit route
  6657. {
  6658. g.setColour (colour::accent.withAlpha (0.8f));
  6659. g.drawRoundedRectangle (b.reduced (0.5f), radius::md, 1.0f);
  6660. }
  6661. icons::draw (g, Icon::link, b.withWidth (22.0f).withSizeKeepingCentre (13.0f, 13.0f).translated (4.0f, 0.0f),
  6662. source.isNotEmpty() ? colour::accent : colour::textSecondary);
  6663. const auto modulator = slot.kind == EffectKind::vocoder || slot.kind == EffectKind::vocodex;
  6664. const auto text = (modulator ? tr ("Modulator") : tr ("SC")) + ": " + (source.isNotEmpty() ? source : tr ("None"));
  6665. g.setColour (source.isNotEmpty() ? colour::textPrimary : colour::textSecondary);
  6666. g.setFont (font (type::small));
  6667. textcache::drawFittedText (g, text, b.withTrimmedLeft (24.0f).withTrimmedRight (14.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
  6668. juce::Path tri; // ▾: it opens a list
  6669. const auto a = juce::Point<float> (b.getRight() - 9.0f, b.getCentreY());
  6670. tri.addTriangle (a.x - 3.5f, a.y - 2.0f, a.x + 3.5f, a.y - 2.0f, a.x, a.y + 2.5f);
  6671. g.setColour (colour::textSecondary);
  6672. g.fillPath (tri);
  6673. }
  6674. int EffectsPanel::titleRowY() const
  6675. {
  6676. return (gateSelected() ? gateStepsBounds().getY() : vocoderSelected() ? bandLevelsBounds().getY()
  6677. : tuneSelected() ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 28;
  6678. }
  6679. juce::Rectangle<int> EffectsPanel::sidechainButtonBounds() const
  6680. {
  6681. const auto* s = slots();
  6682. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size() || track < 0)
  6683. return {};
  6684. const auto& slot = (*s)[(std::size_t) selectedSlot];
  6685. if (slot.kind == EffectKind::facetEq || slot.kind == EffectKind::parametricEq || slot.kind == EffectKind::parallel
  6686. || isSoundgoodizerApprox (slot)) // (Facet EQ: its own picker on its curve page)
  6687. return {};
  6688. if (! pluginheader::takesSidechain (engine, track, selectedSlot))
  6689. return {};
  6690. if (slot.kind == EffectKind::plugin) // under the plugin's name
  6691. {
  6692. const auto button = pluginButtonBounds();
  6693. return { button.getX(), button.getBottom() + 38, button.getWidth(), 22 };
  6694. }
  6695. const auto editorButton = slot.kind != EffectKind::volumeGate && ! vocoderSelected() && NativeEffectWindows::canOpen (slot.kind);
  6696. const auto right = editorButton ? editorButtonBounds().getX() - 6 : getWidth() - 10;
  6697. const auto width = juce::jmin (130, juce::jmax (0, right - 90));
  6698. return width < 60 ? juce::Rectangle<int>() : juce::Rectangle<int> (right - width, titleRowY(), width, 20);
  6699. }
  6700. void EffectsPanel::openPluginWindow (int slot)
  6701. {
  6702. // Online Sessions P5-A1: an effect the session's host plays on this insert opens its parameter editor
  6703. if (liveui::showHostedEditor ({ { live::Kind::insert, (std::uint64_t) juce::jmax (0, track), 0 }, slot }))
  6704. return;
  6705. auto effect = engine.getEffect (track, slot);
  6706. if (auto* plugin = dynamic_cast<PluginEffect*> (effect.get()))
  6707. {
  6708. // round 190ao: crashed inside a call (not called again: its window would call into it), or its separate process
  6709. // died: "Reload" starts it again without reopening the project
  6710. const AudioEngine::HostedSlot where { -1, track, slot };
  6711. auto reopen = [safe = juce::Component::SafePointer<EffectsPanel> (this), where] {
  6712. if (safe == nullptr || safe->track != where.track)
  6713. return;
  6714. if (safe->engine.hostedPluginDown (where))
  6715. PluginWindows::reload (safe->engine, { where });
  6716. if (! safe->engine.hostedPluginDown (where))
  6717. safe->openPluginWindow (where.slot);
  6718. };
  6719. if (engine.hostedPluginDown (where))
  6720. {
  6721. PluginWindows::promptReload (engine, where, [safe = juce::Component::SafePointer<EffectsPanel> (this), where] {
  6722. if (safe != nullptr && safe->track == where.track)
  6723. safe->openPluginWindow (where.slot);
  6724. });
  6725. return;
  6726. }
  6727. const auto& s = engine.getSong().mixer[(std::size_t) track].effects[(std::size_t) slot];
  6728. PluginWindows::WrapperContext context { &engine, [t = track, slot] (Song& song) -> PluginRef* {
  6729. if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
  6730. return nullptr;
  6731. return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
  6732. }, false, track, slot, {}, {} };
  6733. context.reload = reopen;
  6734. context.down = [weak = std::weak_ptr<Effect> (effect)] {
  6735. const auto held = weak.lock();
  6736. auto* p = dynamic_cast<PluginEffect*> (held.get());
  6737. return p != nullptr && p->hasCrashed();
  6738. };
  6739. PluginWindows::open (effect, plugin->getInstance(), quickpick::slotName (engine, s), std::move (context)); // (its Plugin database name, round 165c)
  6740. return;
  6741. }
  6742. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Plugin"),
  6743. tr ("This plugin could not be loaded (it is not installed or has not been scanned)."));
  6744. }
  6745. void EffectsPanel::showAddMenu (int row)
  6746. {
  6747. juce::PopupMenu menu;
  6748. // the effect lands in the clicked empty slot (FL's slot places, round 170b); returns its index, -1 = not added
  6749. auto place = [this, row] (EffectSlot fx) {
  6750. int at = -1;
  6751. engine.editSong ([t = track, row, &fx, &at] (Song& song) {
  6752. if (t < 0 || t >= (int) song.mixer.size() || (int) song.mixer[(std::size_t) t].effects.size() >= maxEffectSlots)
  6753. return;
  6754. at = mixerops::insertEffectAtRow (song, t, fx, row);
  6755. if (at < 0)
  6756. {
  6757. song.mixer[(std::size_t) t].effects.push_back (std::move (fx));
  6758. at = (int) song.mixer[(std::size_t) t].effects.size() - 1;
  6759. }
  6760. mixerops::linkAddedSidechain (song, t, at); // round 170h: the sole sidechain sender feeds a new compressor
  6761. });
  6762. if (at < 0)
  6763. return at;
  6764. selectedSlot = at;
  6765. if ((*slots())[(std::size_t) at].kind != EffectKind::plugin) // (plugins: their own window, below)
  6766. openEditor (at); // FL opens the effect's window when it is loaded (round 170h, fl-09)
  6767. repaint();
  6768. return at;
  6769. };
  6770. // FL's renamed plugins first (issue #11): "1_EQ" renamed in the Browser's Plugin database is added by typing 1
  6771. auto addFx = [this, place] (EffectSlot fx) {
  6772. const auto at = place (std::move (fx));
  6773. if (at >= 0 && (*slots())[(std::size_t) at].kind == EffectKind::plugin)
  6774. openPluginWindow (at);
  6775. };
  6776. auto picks = quickpick::renamedEffects (engine, addFx);
  6777. quickpick::addPicks (menu, picks);
  6778. // rounds 166f / 170b (Busy Works: "random order"): every effect under its category heading, A-Z, as FL's slot menu
  6779. // (LYNX SHARE first, then FL's Plugin database categories, the user's own folders among them)
  6780. quickpick::addFolderGroups (menu, engine, std::function<void (EffectSlot)> (addFx));
  6781. // LYNX equivalents of well-known third-party effects, with the same default preset a substitute gets
  6782. juce::PopupMenu equivalents;
  6783. for (const auto& entry : pluginSubstitutes())
  6784. if (! entry.instrument)
  6785. equivalents.addItem (juce::String::fromUTF8 (entry.product.c_str()) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (effectInfo (entry.effect).name),
  6786. [place, entry] { place (makeSubstituteSlot (entry)); });
  6787. if (equivalents.getNumItems() > 0)
  6788. menu.addSubMenu (tr ("LYNX SHARE equivalents"), equivalents);
  6789. juce::PopupMenu plugins;
  6790. addPluginItems (plugins, engine, false, [this, place] (PluginRef ref) {
  6791. EffectSlot slot;
  6792. slot.kind = EffectKind::plugin;
  6793. slot.plugin = ref;
  6794. if (const auto at = place (std::move (slot)); at >= 0)
  6795. openPluginWindow (at);
  6796. }, this);
  6797. menu.addSeparator();
  6798. menu.addSubMenu (tr ("Plugin (VST/VST3/CLAP)"), plugins);
  6799. menu.addSeparator();
  6800. menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
  6801. quickpick::addFolderViewItems (menu, engine); // FL: Categories / Simple / Tree at the bottom
  6802. quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (menuOwner()).withMousePosition(), std::move (picks));
  6803. }
  6804. void EffectsPanel::showSlotMenu (int slot)
  6805. {
  6806. // the same categories as the empty slot's menu (rounds 166f / 170b)
  6807. juce::PopupMenu replace;
  6808. quickpick::addFolderGroups (replace, engine, std::function<void (EffectSlot)> ([this, slot] (EffectSlot fx) {
  6809. engine.editSong ([t = track, slot, fx] (Song& song) {
  6810. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6811. song.mixer[(std::size_t) t].effects[(std::size_t) slot] = fx;
  6812. });
  6813. if (slot < (int) slots()->size() && (*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6814. openPluginWindow (slot);
  6815. }));
  6816. quickpick::addFolderViewItems (replace, engine);
  6817. juce::PopupMenu menu;
  6818. if (extendSlotMenu != nullptr) // (round 183a: the Device View's card adds Fold / Unfold first; the Mixer adds nothing)
  6819. extendSlotMenu (menu, slot);
  6820. menu.addSubMenu (tr ("Replace with"), replace);
  6821. // round 190ce: hot-swap from the Mixer too (the Device View's card has its own item and button)
  6822. if (extendSlotMenu == nullptr && onHotSwapSlot != nullptr)
  6823. menu.addItem (tr ("Hot-swap in the Browser"), [t = track, slot] {
  6824. if (onHotSwapSlot != nullptr)
  6825. onHotSwapSlot (t, slot);
  6826. });
  6827. menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
  6828. // FL presets (Plugin presets\Effects\<plugin>) that map to this effect
  6829. {
  6830. juce::PopupMenu presets;
  6831. const auto roots = findFlStudioRoots();
  6832. const auto base = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects");
  6833. for (const auto& plugin : flPluginsForEffect ((*slots())[(std::size_t) slot].kind))
  6834. {
  6835. juce::PopupMenu sub;
  6836. auto files = base.getChildFile (juce::String::fromUTF8 (plugin.c_str())).findChildFiles (juce::File::findFiles, true, "*.fst");
  6837. std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFileName().compareNatural (b.getFileName()) < 0; });
  6838. for (const auto& f : files)
  6839. sub.addItem (f.getFileNameWithoutExtension(), [this, slot, f] {
  6840. juce::MemoryBlock data;
  6841. if (! f.loadFileAsData (data))
  6842. return;
  6843. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  6844. if (auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm, natives::flDataReader (flStudioAccess())))
  6845. engine.editSong ([t = track, slot, fx = *fx] (Song& song) {
  6846. auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  6847. const auto enabled = target.enabled;
  6848. const auto mix = target.mix;
  6849. target = fx;
  6850. target.enabled = enabled;
  6851. target.mix = mix;
  6852. });
  6853. });
  6854. if (sub.getNumItems() > 0)
  6855. presets.addSubMenu (juce::String::fromUTF8 (plugin.c_str()), sub);
  6856. }
  6857. if (presets.getNumItems() > 0)
  6858. menu.addSubMenu (tr ("FL presets"), presets);
  6859. }
  6860. // side inputs: another track's output feeds the compressor's detector, or the vocoder's modulator/carrier. Round
  6861. // 177b: every effect with a side input (plugins with a sidechain bus too) gets the picker, which makes the route
  6862. const auto kind = (*slots())[(std::size_t) slot].kind;
  6863. auto sideMenu = [&] (const juce::String& title, bool second) {
  6864. juce::PopupMenu side;
  6865. pluginheader::addSidechainPicker (side, engine, track, slot, second);
  6866. menu.addSubMenu (title, side);
  6867. };
  6868. if (kind == EffectKind::vocoder || kind == EffectKind::vocodex)
  6869. {
  6870. sideMenu (tr ("Modulator from"), false);
  6871. sideMenu (tr ("Carrier from"), true);
  6872. }
  6873. else if (pluginheader::takesSidechain (engine, track, slot))
  6874. sideMenu (tr ("Sidechain from"), false);
  6875. if (kind == EffectKind::newtone || kind == EffectKind::newtime)
  6876. {
  6877. // the sample the plugin plays in slave mode (REA_rodada73): FL's edits are kept in the state but not reproduced
  6878. const auto& fx = (*slots())[(std::size_t) slot];
  6879. const auto current = juce::File (juce::String::fromUTF8 (fx.samplePath.c_str()));
  6880. juce::PopupMenu source;
  6881. source.addItem (fx.samplePath.empty() ? tr ("No sample") : current.getFileName(), false, false, [] {});
  6882. source.addItem (tr ("Choose a sample..."), [this, slot, current] {
  6883. sampleChooser = lynx::ui::makeFileChooser (tr ("Source sample"), current.existsAsFile() ? current : juce::File(),
  6884. "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3");
  6885. lynx::ui::launchChooser (sampleChooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  6886. [this, slot] (const juce::FileChooser& fc) {
  6887. const auto file = fc.getResult();
  6888. if (file == juce::File())
  6889. return;
  6890. engine.editSong ([t = track, slot, path = file.getFullPathName().toStdString()] (Song& s) {
  6891. if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
  6892. s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath = path;
  6893. });
  6894. });
  6895. });
  6896. source.addItem (tr ("Remove the sample"), ! fx.samplePath.empty(), false, [this, slot] {
  6897. engine.editSong ([t = track, slot] (Song& s) {
  6898. if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
  6899. s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath.clear();
  6900. });
  6901. });
  6902. menu.addSubMenu (tr ("Source sample"), source);
  6903. }
  6904. {
  6905. // A/B compare: keep a copy of the settings, then swap between it and the current ones
  6906. const auto key = std::make_pair (track, slot);
  6907. const auto hasSpare = spare.count (key) > 0 && spare[key].kind == (*slots())[(std::size_t) slot].kind;
  6908. juce::PopupMenu ab;
  6909. ab.addItem (tr ("Store the current settings as B"), [this, key, slot] {
  6910. spare[key] = (*slots())[(std::size_t) slot];
  6911. });
  6912. ab.addItem (tr ("Swap with B"), hasSpare, false, [this, key, slot] {
  6913. const auto stored = spare[key];
  6914. spare[key] = (*slots())[(std::size_t) slot];
  6915. engine.editSong ([t = track, slot, stored] (Song& song) {
  6916. auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  6917. const auto enabled = target.enabled;
  6918. target = stored;
  6919. target.enabled = enabled;
  6920. });
  6921. });
  6922. ab.addItem (tr ("Forget B"), hasSpare, false, [key] { spare.erase (key); });
  6923. menu.addSubMenu (hasSpare ? tr ("A/B compare (B stored)") : tr ("A/B compare"), ab);
  6924. }
  6925. if ((*slots())[(std::size_t) slot].isSubstitute()) // A/B of every substitute of the project at once (round 113)
  6926. menu.addItem (tr ("Bypass all LYNX SHARE substitutes of this project"), true, engine.getSong().substitutesBypassed, [this] {
  6927. engine.editSong ([] (Song& song) { song.substitutesBypassed = ! song.substitutesBypassed; });
  6928. repaint();
  6929. });
  6930. // FL's slot menu "CPU" section (REA round 139): Allow threaded processing (plugins), Smart disable
  6931. menu.addSectionHeader (tr ("CPU"));
  6932. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6933. menu.addItem (tr ("Allow threaded processing"), true, (*slots())[(std::size_t) slot].plugin.threaded, [this, slot] {
  6934. engine.editSong ([t = track, slot] (Song& song) {
  6935. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6936. song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin.threaded = ! song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin.threaded;
  6937. });
  6938. });
  6939. // FL's per-plugin "Smart disable": skipped while its input and output are silent
  6940. menu.addItem (tr ("Smart disable"), true, (*slots())[(std::size_t) slot].smartDisable, [this, slot] {
  6941. engine.editSong ([t = track, slot] (Song& song) {
  6942. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6943. song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable = ! song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable;
  6944. });
  6945. });
  6946. menu.addSeparator();
  6947. // FL's Move up / Move down (REA FUN_01233de0 / FUN_01235190): one slot, into an empty one too, wrapping around
  6948. auto move = [this, slot] (int delta) {
  6949. int now = -1;
  6950. engine.editSongStructural ([t = track, slot, delta, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, delta); });
  6951. if (now >= 0)
  6952. selectedSlot = now;
  6953. repaint();
  6954. };
  6955. menu.addItem (tr ("Move up"), [move] { move (-1); });
  6956. menu.addItem (tr ("Move down"), [move] { move (1); });
  6957. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6958. {
  6959. // round 190ao: only while the plugin is down (it crashed, or its separate process died)
  6960. if (engine.hostedPluginDown ({ -1, track, slot }))
  6961. menu.addItem (tr ("Reload crashed plugin"), [this, t = track, slot] { PluginWindows::reload (engine, { { -1, t, slot } }); });
  6962. auto* live = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get());
  6963. menu.addSubMenu (tr ("Processing"), pluginProcessingMenu (engine, (*slots())[(std::size_t) slot].plugin, live != nullptr ? &live->getInstance() : nullptr,
  6964. [t = track, slot] (Song& song) -> PluginRef* {
  6965. if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
  6966. return nullptr;
  6967. return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
  6968. }));
  6969. }
  6970. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6971. {
  6972. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()))
  6973. addPluginParameterItems (menu, engine, p->getInstance(), { AutomationTargetKind::effectParam, track, slot, 0 });
  6974. }
  6975. if ((*slots())[(std::size_t) slot].kind == EffectKind::patcher) // its published parameters (round 171b)
  6976. addPatcherParameterItems (menu, engine, (*slots())[(std::size_t) slot].patcher, { AutomationTargetKind::effectParam, track, slot, 0 });
  6977. // FL's Patcherize / Patcherize all (round 165m): the effect (or the whole chain) into a new Patcher, same sound
  6978. menu.addSeparator();
  6979. menu.addItem (tr ("Patcherize"), patcherize::canPatcherizeSlot (engine.getSong(), track, slot), false, [this, slot] {
  6980. engine.capturePluginStates(); // (the plugins' current settings go with them)
  6981. int placed = -1;
  6982. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, false); });
  6983. if (placed >= 0)
  6984. selectedSlot = placed;
  6985. repaint();
  6986. });
  6987. menu.addItem (tr ("Patcherize all"), patcherize::slotsForAll (engine.getSong(), track).size() > 1, false, [this, slot] {
  6988. engine.capturePluginStates();
  6989. int placed = -1;
  6990. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, true); });
  6991. if (placed >= 0)
  6992. selectedSlot = placed;
  6993. repaint();
  6994. });
  6995. // round 183c: Live's Group (Ctrl+G): the effect (or the whole chain) into a new Audio Effect Rack, same sound; the
  6996. // automation of the moved effects' parameters drives the rack's macros
  6997. menu.addItem (tr ("Group into Audio Effect Rack"), patcherize::canPatcherizeSlot (engine.getSong(), track, slot), false, [this, slot] { groupIntoRack (slot, false); });
  6998. menu.addItem (tr ("Group all into Audio Effect Rack"), patcherize::slotsForAll (engine.getSong(), track).size() > 1, false, [this, slot] { groupIntoRack (slot, true); });
  6999. // Live's Ungroup: a one-chain Audio Effect Rack's devices back into the slots
  7000. if (const auto* list = slots(); list != nullptr && slot < (int) list->size() && rack::isRack ((*list)[(std::size_t) slot]))
  7001. {
  7002. const auto* r = rack::rackOf ((*list)[(std::size_t) slot].patcher);
  7003. const auto canUngroup = r != nullptr && r->kind == RackDoc::Kind::audioEffect && r->chains.size() == 1;
  7004. menu.addItem (tr ("Ungroup"), canUngroup, false, [this, slot] {
  7005. engine.capturePluginStates();
  7006. int placed = -1;
  7007. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = rack::ungroupSlot (song, t, slot); });
  7008. if (placed >= 0)
  7009. selectedSlot = placed;
  7010. repaint();
  7011. });
  7012. }
  7013. menu.addSeparator();
  7014. menu.addItem (tr ("Delete") + "\tDel", [this, slot] { deleteSlot (slot); });
  7015. if (slotMenuForSnapshot != nullptr) // (the shot routes: the menu itself, nothing opens)
  7016. {
  7017. *slotMenuForSnapshot = menu;
  7018. return;
  7019. }
  7020. // FL: with the slot's menu open, Delete removes the plugin (issue #11)
  7021. quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (menuOwner()).withMousePosition(), {},
  7022. [safe = juce::Component::SafePointer<EffectsPanel> (this), slot] (const juce::KeyPress& key) {
  7023. if (! key.isKeyCode (juce::KeyPress::deleteKey) || safe == nullptr)
  7024. return false;
  7025. juce::MessageManager::callAsync ([safe, slot] {
  7026. if (safe != nullptr)
  7027. safe->deleteSlot (slot);
  7028. });
  7029. return true;
  7030. });
  7031. }
  7032. void EffectsPanel::deleteSlot (int slot)
  7033. {
  7034. const auto* s = slots();
  7035. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  7036. return;
  7037. engine.editSongStructural ([t = track, slot] (Song& song) { mixerops::removeEffectKeepRows (song, t, slot); }); // (FL: the slot stays empty)
  7038. selectedSlot = juce::jmin (slot, (int) slots()->size() - 1);
  7039. repaint();
  7040. }
  7041. void EffectsPanel::changeListenerCallback (juce::ChangeBroadcaster*)
  7042. {
  7043. const auto* s = slots();
  7044. if (s == nullptr)
  7045. track = 0;
  7046. else if (selectedSlot >= (int) s->size())
  7047. selectedSlot = (int) s->size() - 1;
  7048. refit(); // the clean mixer (round 163) changes the height the panel needs
  7049. repaint();
  7050. }
  7051. // ---------------------------------------------------------------------------
  7052. namespace mixerinput
  7053. {
  7054. std::function<void()> openAudioSettings;
  7055. namespace
  7056. {
  7057. juce::String issueText (const AudioEngine::RecordingNotice& notice)
  7058. {
  7059. using I = AudioEngine::InputIssue;
  7060. switch (notice.issue)
  7061. {
  7062. case I::noDevice: return tr ("No audio device is open. Choose one in Settings > Audio.");
  7063. case I::noInputDevice:
  7064. return tr ("No audio input device was found. Connect a microphone or an audio interface, then choose it as the input device in Settings > Audio.");
  7065. case I::noInputOpen: return tr ("No audio input is open, so nothing can be recorded. Choose an input device in Settings > Audio.");
  7066. case I::armedWithoutInput:
  7067. return tr ("Please select an audio input first: the armed insert has none. Click the input box above the insert's effect slots in the Mixer.");
  7068. case I::insertWithoutInput: return tr ("Insert {0} is armed but has no audio input, so it records nothing.", { juce::String (notice.track) });
  7069. case I::silentTake:
  7070. return tr ("The recording is silent: the audio input sent nothing but silence. Check that the insert's input is the "
  7071. "channel your microphone or instrument is plugged into (the input box above its effect slots), that the "
  7072. "interface's input is not muted, and that LYNX SHARE may use the microphone (Windows: Settings > Privacy "
  7073. "> Microphone; macOS: System Settings > Privacy & Security > Microphone).");
  7074. case I::failed: return tr ("The audio input could not be used: {0}", { notice.detail });
  7075. case I::lowDisk:
  7076. return tr ("The recordings drive is almost full: about {0} minute(s) of recording left. Free some space or choose another project folder.",
  7077. { notice.detail });
  7078. case I::recordSafe:
  7079. return tr ("Insert {0} is record safe, so it can't be armed. Click its input box and turn \"Record safe\" off first.",
  7080. { juce::String (notice.track) });
  7081. case I::framesLost:
  7082. return tr ("The disk could not keep up while recording: {0} sample(s) became silence (the timing of the take was kept). "
  7083. "Record to a faster drive or close other programs that use the disk.", { notice.detail });
  7084. case I::none: break;
  7085. }
  7086. return {};
  7087. }
  7088. bool aboutTheDevice (AudioEngine::InputIssue issue)
  7089. {
  7090. using I = AudioEngine::InputIssue;
  7091. return issue == I::noDevice || issue == I::noInputDevice || issue == I::noInputOpen || issue == I::failed;
  7092. }
  7093. } // namespace
  7094. void explain (const AudioEngine::RecordingNotice& notice)
  7095. {
  7096. if (notice.issue == AudioEngine::InputIssue::none)
  7097. return;
  7098. using I = AudioEngine::InputIssue;
  7099. const auto aboutRecording = notice.issue == I::lowDisk || notice.issue == I::recordSafe || notice.issue == I::framesLost || notice.issue == I::silentTake;
  7100. auto options = juce::MessageBoxOptions()
  7101. .withIconType (juce::MessageBoxIconType::WarningIcon)
  7102. .withTitle (aboutRecording ? tr ("Recording") : tr ("Audio input needed"))
  7103. .withMessage (issueText (notice));
  7104. if (aboutTheDevice (notice.issue) && openAudioSettings)
  7105. {
  7106. options = options.withButton (tr ("Audio settings...")).withButton (tr ("Close"));
  7107. juce::AlertWindow::showAsync (options, [] (int result) {
  7108. if (result == 1 && openAudioSettings)
  7109. openAudioSettings();
  7110. });
  7111. }
  7112. else
  7113. juce::AlertWindow::showAsync (options.withButton (tr ("OK")), nullptr);
  7114. }
  7115. // Round 157 ([DATA] the 0.1.15 projects of a singer who found that "the effects do nothing" on her voice): her
  7116. // microphone was the input of both Insert 1 (with the effects) and the Master. The Master plays its input straight
  7117. // away, without any insert's effects, so the dry voice covered the processed one. When an input is chosen and the
  7118. // Master plays the same device channel as an insert, LYNX says so and offers to take it off the Master.
  7119. void warnDoubleMonitoring (AudioEngine& engine, int track)
  7120. {
  7121. const auto& mixer = engine.getSong().mixer;
  7122. if (mixer.empty() || track < 0 || track >= (int) mixer.size())
  7123. return;
  7124. auto channels = [] (const MixerTrack& t) {
  7125. std::pair<int, int> r { t.inputChannel, t.inputChannel + (t.inputStereo ? 1 : 0) };
  7126. return r;
  7127. };
  7128. auto overlaps = [&] (const MixerTrack& a, const MixerTrack& b) {
  7129. if (a.inputChannel < 0 || b.inputChannel < 0)
  7130. return false;
  7131. const auto [a0, a1] = channels (a);
  7132. const auto [b0, b1] = channels (b);
  7133. return a0 <= b1 && b0 <= a1;
  7134. };
  7135. const auto& master = mixer[0];
  7136. if (master.inputChannel < 0 || master.monitor == InputMonitor::off)
  7137. return;
  7138. int insert = -1;
  7139. for (int t = 1; t < (int) mixer.size() && insert < 0; ++t)
  7140. if ((track == 0 || t == track) && overlaps (master, mixer[(std::size_t) t]))
  7141. insert = t;
  7142. if (insert < 0)
  7143. return;
  7144. const auto name = juce::String::fromUTF8 (mixer[(std::size_t) insert].name.c_str());
  7145. auto options = juce::MessageBoxOptions()
  7146. .withIconType (juce::MessageBoxIconType::WarningIcon)
  7147. .withTitle (tr ("The same input plays twice"))
  7148. .withMessage (tr ("This audio input is the input of the Master and of {0}. The Master plays it straight away, without "
  7149. "{0}'s effects, so you hear the dry sound on top of the processed one (the effects seem to do nothing).\n\n"
  7150. "To hear it through {0}'s effects, take it off the Master.", { name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (insert) }) }))
  7151. .withButton (tr ("Take it off the Master"))
  7152. .withButton (tr ("Keep both"));
  7153. juce::AlertWindow::showAsync (options, [&engine] (int result) {
  7154. if (result == 1)
  7155. engine.setInsertInput (0, -1, true);
  7156. });
  7157. }
  7158. // FL's question when an external input is chosen on an insert that records more than it (core/LiveInput.h
  7159. // asksExternalInputOnly, issue #152): Yes = "External input only", so the take holds the input alone.
  7160. // Live check 190ew ISS152-1: only when the insert had no input before (`inputBefore`), in FL's message window with its
  7161. // "Remember my choice" box (a remembered Yes switches without asking; Settings › Manage messages shows it again).
  7162. void askExternalInputOnly (AudioEngine& engine, int track, int inputBefore)
  7163. {
  7164. const auto& mixer = engine.getSong().mixer;
  7165. if (track < 0 || track >= (int) mixer.size())
  7166. return;
  7167. const auto& mt = mixer[(std::size_t) track];
  7168. if (! asksExternalInputOnly (track, inputBefore, mt.inputChannel, mt.recordSource))
  7169. return;
  7170. if (! messages::shown ("RecAutoSwitchExternalInput"))
  7171. {
  7172. engine.setInsertRecordSource (track, RecordSource::externalInput);
  7173. return;
  7174. }
  7175. // (FL marks "External input only" in its accent colour: the |bars| of its own string)
  7176. showFlMessage ({ tr ("External input"), tr ("You've selected an external input. Do you want to switch to |External input only| to avoid recording internal audio on this track?"),
  7177. { tr ("Yes"), tr ("No") }, true },
  7178. [&engine, track] (int button, bool remember) {
  7179. if (button != 1)
  7180. return;
  7181. if (remember)
  7182. messages::setShown ("RecAutoSwitchExternalInput", false);
  7183. engine.setInsertRecordSource (track, RecordSource::externalInput);
  7184. });
  7185. }
  7186. void showMenu (AudioEngine& engine, int track, juce::Component* target, std::function<void()> chosen)
  7187. {
  7188. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  7189. return;
  7190. // FL: "The input of a mixer track can't be changed while recording." (a take keeps the channels it started with;
  7191. // issue #152)
  7192. if (engine.isRecordingAudioTakes())
  7193. {
  7194. juce::AlertWindow::showAsync (juce::MessageBoxOptions()
  7195. .withIconType (juce::MessageBoxIconType::WarningIcon)
  7196. .withTitle (tr ("Warning"))
  7197. .withMessage (tr ("The input of a mixer track can't be changed while recording."))
  7198. .withButton (tr ("OK")),
  7199. nullptr);
  7200. return;
  7201. }
  7202. // the device input opens on demand (only then does Windows show the microphone as in use)
  7203. if (! engine.hasAudioInput())
  7204. if (const auto result = engine.openAudioInput(); result.issue != AudioEngine::InputIssue::none)
  7205. {
  7206. explain (result);
  7207. return;
  7208. }
  7209. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  7210. const auto names = engine.getInputChannelNames();
  7211. juce::PopupMenu menu;
  7212. menu.addSectionHeader (tr ("Audio input source"));
  7213. menu.addItem (tr ("(none)"), true, mt.inputChannel < 0, [&engine, track] { engine.setInsertInput (track, -1, true); });
  7214. const auto sources = inputSources (names);
  7215. if (sources.empty())
  7216. menu.addItem (tr ("The audio device has no open input channels"), false, false, nullptr);
  7217. for (const auto& source : sources)
  7218. {
  7219. if (! source.stereo && source.channel == 0 && names.size() > 1)
  7220. menu.addSeparator(); // pairs, then single channels
  7221. const auto ticked = mt.inputChannel == source.channel && mt.inputStereo == source.stereo;
  7222. menu.addItem (juce::String::fromUTF8 (source.name.c_str()) + (source.stereo ? "" : " " + tr ("(mono)")), true, ticked,
  7223. [&engine, track, source, chosen, before = mt.inputChannel] {
  7224. engine.setInsertInput (track, source.channel, source.stereo);
  7225. warnDoubleMonitoring (engine, track);
  7226. askExternalInputOnly (engine, track, before);
  7227. if (chosen)
  7228. chosen();
  7229. });
  7230. }
  7231. if (track > 0) // FL's "Record" positions (round 168x, issue #41; FL's AudioRecorderRoutingMenu, in its order)
  7232. {
  7233. menu.addSectionHeader (tr ("Record"));
  7234. const std::pair<RecordSource, const char*> points[] = { { RecordSource::externalInput, TR_NOOP ("External input only") },
  7235. { RecordSource::externalAndMixer, TR_NOOP ("External and mixer input") },
  7236. { RecordSource::postEffects, TR_NOOP ("Post effects") },
  7237. { RecordSource::postEq, TR_NOOP ("Post EQ") },
  7238. { RecordSource::postLevel, TR_NOOP ("Post level and panning") },
  7239. { RecordSource::postTrack, TR_NOOP ("Post track") } };
  7240. for (const auto& [point, label] : points)
  7241. menu.addItem (tr (label), true, mt.recordSource == point, [&engine, track, point = point] { engine.setInsertRecordSource (track, point); });
  7242. // LYNX extra: the dry device input as a second take beside a processed one (DI + amp, for re-amping)
  7243. menu.addItem (tr ("Also record the dry input as a second take (LYNX)"), mt.recordSource != RecordSource::externalInput,
  7244. mt.recordDryToo && mt.recordSource != RecordSource::externalInput,
  7245. [&engine, track, on = mt.recordDryToo] { engine.setInsertRecordDryToo (track, ! on); });
  7246. }
  7247. menu.addSectionHeader (tr ("Monitor external input"));
  7248. const std::pair<InputMonitor, const char*> modes[] = { { InputMonitor::off, TR_NOOP ("Off") },
  7249. { InputMonitor::whenArmed, TR_NOOP ("When armed") },
  7250. { InputMonitor::automatic, TR_NOOP ("Auto (when armed, not while playing back)") },
  7251. { InputMonitor::on, TR_NOOP ("On") } };
  7252. for (const auto& [mode, label] : modes)
  7253. {
  7254. // the Master has no record arm: its input plays unless monitoring is off
  7255. if (track == 0 && (mode == InputMonitor::whenArmed || mode == InputMonitor::automatic))
  7256. continue;
  7257. const auto ticked = track == 0 ? (mode == InputMonitor::off) == (mt.monitor == InputMonitor::off) : mt.monitor == mode;
  7258. menu.addItem (tr (label), true, ticked, [&engine, track, mode = mode] { engine.setInsertMonitor (track, mode); });
  7259. }
  7260. if (track > 0) // record safe (round 163): the insert can't be armed by accident
  7261. {
  7262. menu.addSeparator();
  7263. menu.addItem (tr ("Record safe (can't be armed)"), true, mt.recordSafe,
  7264. [&engine, track, safe = mt.recordSafe] { engine.setInsertRecordSafe (track, ! safe); });
  7265. }
  7266. menu.addSeparator();
  7267. menu.addItem (tr ("Audio settings (input device)..."), openAudioSettings != nullptr, false, [] {
  7268. if (openAudioSettings)
  7269. openAudioSettings();
  7270. });
  7271. auto options = juce::PopupMenu::Options();
  7272. if (target != nullptr)
  7273. options = options.withTargetComponent (target).withMousePosition();
  7274. menu.showMenuAsync (options);
  7275. }
  7276. juce::String armHint (const AudioEngine& engine, int track)
  7277. {
  7278. auto text = tr ("Record arm: Rec + Play records this insert into a Playlist clip [RMB] record to a file");
  7279. if (track <= 0 || track >= (int) engine.getSong().mixer.size())
  7280. return text;
  7281. // FL's hint names the position: "Recording: Post EQ" (round 168x; changed in the input box's menu)
  7282. static const char* const points[] { TR_NOOP ("External input only"), TR_NOOP ("External and mixer input"), TR_NOOP ("Post effects"),
  7283. TR_NOOP ("Post EQ"), TR_NOOP ("Post level and panning"), TR_NOOP ("Post track") };
  7284. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  7285. text = tr ("Recording: {0}", { tr (points[juce::jlimit (0, 5, (int) mt.recordSource)]) })
  7286. + (mt.recordDryToo && mt.recordSource != RecordSource::externalInput ? " + " + tr ("dry input") : juce::String()) + " " + text;
  7287. if (mt.recordTo.empty())
  7288. return text;
  7289. const auto file = juce::File (juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) track].recordTo.c_str()));
  7290. return tr ("Record to: {0}", { file.getFileName() }) + " " + text;
  7291. }
  7292. void chooseRecordTo (AudioEngine& engine, int track)
  7293. {
  7294. if (track <= 0 || track >= (int) engine.getSong().mixer.size())
  7295. return;
  7296. if (engine.getSong().mixer[(std::size_t) track].recordSafe)
  7297. {
  7298. AudioEngine::RecordingNotice notice;
  7299. notice.issue = AudioEngine::InputIssue::recordSafe;
  7300. notice.track = track;
  7301. explain (notice);
  7302. return;
  7303. }
  7304. const auto insert = juce::String::fromUTF8 (mixerops::insertDisplayName (engine.getSong(), track).c_str());
  7305. const auto& current = engine.getSong().mixer[(std::size_t) track].recordTo;
  7306. juce::File initial;
  7307. if (! current.empty() && juce::File::isAbsolutePath (juce::String::fromUTF8 (current.c_str())))
  7308. initial = juce::File (juce::String::fromUTF8 (current.c_str()));
  7309. else
  7310. {
  7311. // FL's default: Audio\Recorded, "<project title>_YYYY-MM-DD HH-MM-SS_<insert name>"
  7312. auto folder = engine.getRecordingFolder();
  7313. folder.createDirectory();
  7314. const auto now = juce::Time::getCurrentTime();
  7315. const auto name = juce::File::createLegalFileName (juce::String::fromUTF8 (
  7316. safety::recordingName (engine.getRecordingStem().toStdString(), now.getYear(), now.getMonth() + 1, now.getDayOfMonth(), now.getHours(),
  7317. now.getMinutes(), now.getSeconds(), insert.toStdString()).c_str()));
  7318. initial = folder.getChildFile (name + ".wav");
  7319. }
  7320. static std::unique_ptr<juce::FileChooser> chooser;
  7321. chooser = lynx::ui::makeFileChooser (tr ("Record {0} to", { insert }), initial, "*.wav");
  7322. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
  7323. [&engine, track] (const juce::FileChooser& fc) {
  7324. auto file = fc.getResult();
  7325. if (file == juce::File() || track >= (int) engine.getSong().mixer.size())
  7326. return;
  7327. if (! file.hasFileExtension (".wav"))
  7328. file = file.withFileExtension (".wav");
  7329. engine.editSong ([track, path = file.getFullPathName().toStdString()] (Song& s) {
  7330. if (track < (int) s.mixer.size())
  7331. s.mixer[(std::size_t) track].recordTo = path;
  7332. });
  7333. if (! engine.isInsertArmed (track)) // FL arms it (and the insert gets selected)
  7334. toggleArm (engine, track, nullptr);
  7335. });
  7336. }
  7337. void toggleArm (AudioEngine& engine, int track, juce::Component* /*target*/)
  7338. {
  7339. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  7340. return;
  7341. // FL 2026: arms at once, also without an input source (the recording start reports a missing input)
  7342. switch (armClick (track, engine.isInsertArmed (track)))
  7343. {
  7344. case ArmClick::none: return;
  7345. case ArmClick::disarm: engine.setInsertArmed (track, false); return;
  7346. case ArmClick::arm:
  7347. engine.setInsertArmed (track, true);
  7348. if (const auto notice = engine.takeRecordingNotice(); notice.issue != AudioEngine::InputIssue::none)
  7349. explain (notice);
  7350. return;
  7351. }
  7352. }
  7353. } // namespace mixerinput
  7354. // ---------------------------------------------------------------------------
  7355. MixerLayoutBox::MixerLayoutBox (MixerStrips& s)
  7356. : strips (s)
  7357. {
  7358. setTooltip (tr ("Mixer layout"));
  7359. setMouseCursor (juce::MouseCursor::PointingHandCursor);
  7360. }
  7361. juce::PopupMenu MixerLayoutBox::menu (MixerStrips& strips)
  7362. {
  7363. juce::PopupMenu m;
  7364. for (int i = 0; i < mixerlayout::layoutCount; ++i)
  7365. {
  7366. const auto l = (mixerlayout::Layout) i;
  7367. m.addItem (tr (juce::String (std::string (mixerlayout::nameOf (l)))), true, MixerStrips::layout == l,
  7368. [&strips, l] { strips.setLayout (l); });
  7369. if (mixerlayout::separatorAfter (l))
  7370. m.addSeparator();
  7371. }
  7372. return m;
  7373. }
  7374. void MixerLayoutBox::paint (juce::Graphics& g)
  7375. {
  7376. using namespace theme;
  7377. const auto hot = isMouseOverOrDragging();
  7378. auto box = getLocalBounds().toFloat().reduced (1.0f, 2.0f);
  7379. theme::fillRoundRect (g, box, radius::sm, hot ? colour::bg4 : colour::bg2);
  7380. g.setColour (hot ? colour::borderStrong : colour::border);
  7381. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  7382. // round 170e: the strips icon names what the box is (it showed only "Wide")
  7383. icons::draw (g, Icon::mixer, box.withWidth (24.0f).withSizeKeepingCentre (14.0f, 14.0f), hot ? colour::textPrimary : colour::textSecondary);
  7384. g.setColour (colour::accent);
  7385. g.setFont (font (type::small, true));
  7386. g.drawFittedText (tr (juce::String (std::string (mixerlayout::nameOf (MixerStrips::layout)))), getLocalBounds().reduced (8, 0).withTrimmedLeft (18).withTrimmedRight (14),
  7387. juce::Justification::centredLeft, 1, 0.8f);
  7388. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).withSizeKeepingCentre (12.0f, 12.0f), hot ? colour::textPrimary : colour::textSecondary);
  7389. }
  7390. void MixerLayoutBox::mouseDown (const juce::MouseEvent&)
  7391. {
  7392. menu (strips).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
  7393. }
  7394. MixerComponent::MixerComponent (AudioEngine& e)
  7395. : engine (e),
  7396. strips (e),
  7397. effects (e)
  7398. {
  7399. viewport.setViewedComponent (&strips, false);
  7400. viewport.setScrollBarsShown (false, true);
  7401. addAndMakeVisible (viewport);
  7402. effectsView.setViewedComponent (&effects, false);
  7403. effectsView.setScrollBarsShown (true, false);
  7404. effectsView.setScrollBarThickness (10);
  7405. addAndMakeVisible (effectsView);
  7406. strips.onSelectionChanged = [this] (int track) { effects.setTrack (track); };
  7407. strips.onEffectDropped = [this] (int track, EffectSlot fx) {
  7408. strips.selectTrack (track);
  7409. effects.setTrack (track);
  7410. if (! addEffectToSelected (std::move (fx)))
  7411. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Plugin database"),
  7412. tr ("The selected insert has no free effect slot."));
  7413. else // FL opens the dropped effect's window (round 171c: the Plugin picker's drag is FL's Browser drag)
  7414. openSlotEditor (track, (int) engine.getSong().mixer[(std::size_t) track].effects.size() - 1);
  7415. };
  7416. strips.onInstrumentDropped = [this] (int track, ChannelDef c) {
  7417. selectTrack (track);
  7418. if (onInstrumentDropped != nullptr)
  7419. onInstrumentDropped (track, std::move (c));
  7420. };
  7421. effects.onInstrumentDropped = strips.onInstrumentDropped;
  7422. }
  7423. bool MixerComponent::runAction (const std::string& id)
  7424. {
  7425. if (id == "mixer.moveLeft")
  7426. strips.moveSelected (-1);
  7427. else if (id == "mixer.moveRight")
  7428. strips.moveSelected (1);
  7429. else if (id == "mixer.linkChannels")
  7430. strips.linkSelectedChannels (false);
  7431. else if (id == "mixer.linkChannelsFrom")
  7432. strips.linkSelectedChannels (true);
  7433. else if (id == "mixer.selectLinkedChannels")
  7434. strips.selectLinkedChannels();
  7435. else if (id == "mixer.audioEditor")
  7436. return strips.runMenuItem (tr ("Open audio editor"));
  7437. else if (id == "mixer.audioEditorRecord")
  7438. return strips.runMenuItem (tr ("Open audio editor and record"));
  7439. else if (id == "mixer.rename") // FL's mixer menu keys (round 167k): the menu's own items
  7440. return strips.runMenuItem (tr ("Rename and color..."));
  7441. else if (id == "mixer.soloSelected")
  7442. return strips.runMenuItem (tr ("Solo selected track(s)"));
  7443. else if (id == "mixer.altSoloSelected")
  7444. return strips.runMenuItem (tr ("Alt solo selected track(s)"));
  7445. else if (id == "mixer.renderArmed")
  7446. return strips.runMenuItem (tr ("Render armed tracks to wave file(s)..."));
  7447. else if (id == "mixer.renderSelected")
  7448. return strips.runMenuItem (tr ("Render selected tracks to wave file(s)..."));
  7449. else if (id == "mixer.deleteTracks") // FL's Del: the selected mixer tracks, after its question (round 186c)
  7450. strips.deleteSelectedTracks();
  7451. else if (id == "mixer.deleteEffect") // FL: Delete on the selected effect slot (issue #11)
  7452. effects.deleteSlot (effects.getSelectedSlot());
  7453. else
  7454. return false;
  7455. return true;
  7456. }
  7457. bool MixerComponent::loadPresetOnSelection (const juce::File& file)
  7458. {
  7459. return mixerpresets::loadOnTracks (engine, strips.getSelection(), file);
  7460. }
  7461. bool MixerComponent::addEffectToSelected (EffectSlot slot)
  7462. {
  7463. const auto t = strips.getSelectedTrack();
  7464. bool added = false;
  7465. engine.editSong ([t, &slot, &added] (Song& s) {
  7466. if (s.mixer.empty())
  7467. s.mixer = Song::defaultMixer (0);
  7468. if (t < (int) s.mixer.size() && (int) s.mixer[(std::size_t) t].effects.size() < maxEffectSlots)
  7469. {
  7470. s.mixer[(std::size_t) t].effects.push_back (std::move (slot));
  7471. added = true;
  7472. }
  7473. });
  7474. if (added)
  7475. {
  7476. effects.setTrack (t);
  7477. effects.selectSlot ((int) engine.getSong().mixer[(std::size_t) t].effects.size() - 1);
  7478. }
  7479. return added;
  7480. }
  7481. void MixerComponent::selectFirstTrackWithEffects()
  7482. {
  7483. const auto& mixer = engine.getSong().mixer;
  7484. for (int t = 0; t < (int) mixer.size(); ++t)
  7485. if (! mixer[(std::size_t) t].effects.empty())
  7486. {
  7487. strips.selectTrack (t);
  7488. return;
  7489. }
  7490. }
  7491. void MixerComponent::selectTrack (int track)
  7492. {
  7493. strips.selectTrack (track);
  7494. // scroll the strip into view
  7495. const auto t = strips.getSelectedTrack();
  7496. const auto x = strips.stripLeft (t);
  7497. const auto w = strips.widthOf (t);
  7498. const auto view = viewport.getViewArea();
  7499. if (x < view.getX() || x + w > view.getRight())
  7500. viewport.setViewPosition (juce::jmax (0, x - view.getWidth() / 2), 0);
  7501. }
  7502. void MixerComponent::resized()
  7503. {
  7504. auto area = getLocalBounds();
  7505. effectsView.setBounds (area.removeFromRight (effectsWidth));
  7506. effects.fitToView (effectsView.getWidth(), effectsView.getHeight(), effectsView.getScrollBarThickness());
  7507. viewport.setBounds (area);
  7508. strips.setVisibleHeight (area.getHeight() - viewport.getScrollBarThickness());
  7509. }
  7510. } // namespace lynx