4
0

MixerComponent.cpp 348 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590
  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 "ui/PluginOffTag.h"
  9. #include "ui/SlotWatch.h"
  10. #include "core/ValueMath.h"
  11. #include "ui/UiTrace.h"
  12. #include "ui/TextCache.h"
  13. #include "core/Patcherize.h"
  14. #include "core/Rack.h"
  15. #include "core/FlpImport.h"
  16. #include "engine/FlStudio.h"
  17. #include "core/FlEffects.h"
  18. #include "core/ProjectContents.h"
  19. #include "core/FruityVocoder.h"
  20. #include "core/LiveInput.h"
  21. #include "core/HardwareOutput.h"
  22. #include "core/MixerOps.h"
  23. #include "ui/PluginHeader.h"
  24. #include "core/ProjectSafety.h"
  25. #include "core/Templates.h"
  26. #include "core/RackOps.h"
  27. #include "ui/AutomationUi.h"
  28. #include "ui/BrowserComponent.h"
  29. #include "ui/ExportDialog.h"
  30. #include <cmath>
  31. #include <complex>
  32. #include "core/Biquad.h"
  33. #include "core/Effects.h"
  34. #include "core/GoalKnobs.h"
  35. #include "engine/Text.h"
  36. #include "engine/ProjectFile.h"
  37. #include <numeric>
  38. #include "ui/FacetEqEditor.h"
  39. #include "ui/ParametricEqEditor.h"
  40. #include "ui/PluginEditors.h"
  41. #include "ui/PluginWindow.h"
  42. #include "ui/HintBar.h"
  43. #include "core/StandIns.h"
  44. #include "ui/I18n.h"
  45. #include "ui/LiveRemoteUi.h"
  46. #include "core/LynxTune.h"
  47. #include "core/VocalPitch.h"
  48. #include "ui/Icons.h"
  49. #include "ui/ValueControl.h"
  50. #include "ui/Theme.h"
  51. #include "ui/AudioEditor.h"
  52. #include "ui/Dialogs.h"
  53. #include "ui/QuickPick.h"
  54. #include "ui/TrackIcons.h"
  55. #include "core/TrackIcons.h"
  56. namespace lynx
  57. {
  58. namespace
  59. {
  60. // strip layout, top to bottom: header (arm, number, icon, a horizontal name), the vertical name column (not in
  61. // Extra large; low in the strip in the alt layouts), knobs (pan, stereo), mute/solo, meters + fader, the dB read-out,
  62. // then the routing lane (send switch, send knob, wires). The rows follow FL's Mixer layout (MixerStrips::rows()).
  63. constexpr int switchHeight = 16;
  64. constexpr int sendKnobHeight = 26;
  65. constexpr int wiresHeight = 14;
  66. constexpr int laneHeight = switchHeight + sendKnobHeight + wiresHeight + 4;
  67. constexpr int masterScaleWidth = 17; // the dB numbers beside the master meter (round 162, issue #9)
  68. // Fader 0..1 -> dB, with 0.8 = 0 dB (as in FL).
  69. juce::String faderToDb (float volume)
  70. {
  71. if (volume <= 0.0001f)
  72. return juce::String::fromUTF8 ("-\xe2\x88\x9e");
  73. const auto db = juce::Decibels::gainToDecibels (faderGain (volume));
  74. return (db > 0 ? "+" : "") + juce::String (db, 1);
  75. }
  76. // Meter level 0..1 on a dB scale (-60..+6).
  77. float meterPosition (float gain)
  78. {
  79. const auto db = juce::Decibels::gainToDecibels (gain, -60.0f);
  80. return juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f);
  81. }
  82. // Stereo separation: -1 = widest, 0 = normal, +1 = mono (MixerTrack::stereo).
  83. ui::ValueSpec stereoSpec (const juce::String& name)
  84. {
  85. ui::ValueSpec spec;
  86. spec.name = name;
  87. spec.minimum = -1.0;
  88. spec.maximum = 1.0;
  89. spec.defaultValue = 0.0;
  90. spec.toText = [] (double v) {
  91. const auto percent = juce::roundToInt (std::abs (v) * 100.0);
  92. if (percent == 0)
  93. return tr ("Normal width");
  94. if (v > 0.0 && percent >= 100)
  95. return tr ("Mono");
  96. return v < 0.0 ? tr ("{0}% wider", { juce::String (percent) }) : tr ("{0}% narrower", { juce::String (percent) });
  97. };
  98. spec.fromText = [] (const juce::String& t) -> std::optional<double> {
  99. const auto lower = t.toLowerCase().trim();
  100. if (lower.startsWith ("mono"))
  101. return 1.0;
  102. if (lower.startsWith ("n") && ! lower.containsAnyOf ("0123456789"))
  103. return 0.0;
  104. const auto digits = lower.initialSectionContainingOnly ("+-0123456789.,").replaceCharacter (',', '.');
  105. if (digits.isEmpty() || digits.containsOnly ("+-."))
  106. return std::nullopt;
  107. auto v = digits.getDoubleValue() / 100.0;
  108. if (lower.contains ("wid") || lower.contains ("larg")) // "50% wider" / "50% mais largo"
  109. v = -std::abs (v);
  110. return v;
  111. };
  112. return spec;
  113. }
  114. // Online Sessions (round 168a): the amber "R" of an insert whose stand-in render plays
  115. void drawStandInTag (juce::Graphics& g, juce::Rectangle<float> tag)
  116. {
  117. theme::fillRoundRect (g, tag, 3.0f, theme::colour::warning.withAlpha (0.85f));
  118. g.setColour (theme::colour::bg1);
  119. g.setFont (theme::font (9.0f, true));
  120. g.drawText ("R", tag, juce::Justification::centred, false);
  121. }
  122. ui::ValueSpec sendSpec (const juce::String& name)
  123. {
  124. // FL's send knob: the fader curve (0 dB at 80 %, +5.6 dB at the top); the value is the knob position
  125. auto spec = ui::faderSpec (name, unityFader);
  126. spec.pixelsForRange = 120.0;
  127. return spec;
  128. }
  129. } // namespace
  130. // The Mixer strips' picture (round 174e2): JUCE's buffered-to-image cache for the visible part of the strips (they are
  131. // as wide as all the inserts), plus the meter levels drawn over it and the meters' own repaints leaving it valid
  132. class MixerStrips::MeterCache final : public juce::CachedComponentImage
  133. {
  134. public:
  135. explicit MeterCache (MixerStrips& o) : owner (o) {}
  136. void paint (juce::Graphics& g) override
  137. {
  138. const auto scale = g.getInternalContext().getPhysicalPixelScaleFactor();
  139. auto visible = owner.getLocalBounds();
  140. if (auto* parent = owner.getParentComponent())
  141. visible = visible.getIntersection (owner.getLocalArea (parent, parent->getLocalBounds()));
  142. if (visible.isEmpty())
  143. return;
  144. const auto imageSize = (visible.withZeroOrigin().toFloat() * scale).getSmallestIntegerContainer();
  145. // (round 190bm) a window drawn without the GPU gets a software picture; a picture lost with its graphics
  146. // device is painted again; no picture at all (no memory): straight to the window
  147. const auto software = ui::windowDrawnByCpu (owner);
  148. const auto losses = ui::pictureLossCount();
  149. if (visible != shown || image.isNull() || image.getBounds() != imageSize || software != softwareImage || losses != lossesSeen)
  150. {
  151. if (image.isNull() || image.getBounds() != imageSize || software != softwareImage)
  152. image = ui::makePicture (imageSize.getWidth(), imageSize.getHeight(), software);
  153. softwareImage = software;
  154. lossesSeen = losses;
  155. shown = visible;
  156. valid.clear();
  157. }
  158. ui::notePicture ("Mixer", image, scale, softwareImage, owner, noted);
  159. if (image.isNull())
  160. {
  161. owner.paintEntireComponent (g, false);
  162. return;
  163. }
  164. if (! valid.containsRectangle (visible))
  165. {
  166. const ui::ScopedNoImageReadback noReadback (image); // (the picture is normally only drawn to the window)
  167. juce::Graphics imageGraphics (image);
  168. auto& context = imageGraphics.getInternalContext();
  169. context.addTransform (juce::AffineTransform::translation ((float) -visible.getX(), (float) -visible.getY()).scaled (scale));
  170. for (const auto& r : valid)
  171. context.excludeClipRectangle (r);
  172. context.clipToRectangle (visible);
  173. ++owner.pictureRefills;
  174. owner.cachePainting = true;
  175. owner.paintEntireComponent (imageGraphics, true);
  176. owner.cachePainting = false;
  177. }
  178. valid = visible;
  179. g.setColour (juce::Colours::black);
  180. g.drawImageTransformed (image,
  181. juce::AffineTransform::scale ((float) visible.getWidth() / (float) imageSize.getWidth(),
  182. (float) visible.getHeight() / (float) imageSize.getHeight())
  183. .translated ((float) visible.getX(), (float) visible.getY()),
  184. false);
  185. owner.paintMeterLevels (g);
  186. if (ui::pictureLostMeanwhile (lossesSeen, lossRetries))
  187. owner.repaint();
  188. }
  189. bool invalidateAll() override // (JUCE's repaint() of the whole component comes here, not to invalidate())
  190. {
  191. if (! owner.meterRepaintOnly)
  192. {
  193. ++owner.pictureInvalidations;
  194. valid.clear();
  195. }
  196. return true;
  197. }
  198. bool invalidate (const juce::Rectangle<int>& area) override
  199. {
  200. if (! owner.meterRepaintOnly)
  201. {
  202. ++owner.pictureInvalidations;
  203. valid.subtract (area);
  204. }
  205. return true;
  206. }
  207. void releaseResources() override { image = {}; }
  208. private:
  209. MixerStrips& owner;
  210. juce::Image image;
  211. juce::Rectangle<int> shown; // the visible part the picture holds
  212. juce::RectangleList<int> valid;
  213. bool softwareImage = false; // the picture is a software image (the window is drawn without the GPU)
  214. int lossesSeen = 0; // ui::pictureLossCount() when the picture was last known good
  215. int lossRetries = 0;
  216. juce::String noted; // ui::notePicture's memory
  217. };
  218. MixerStrips::MixerStrips (AudioEngine& e)
  219. : engine (e)
  220. {
  221. if (const auto* v = std::getenv ("LYNX_MIXER_CACHE"); v == nullptr || juce::String (v) != "0")
  222. {
  223. setCachedComponentImage (new MeterCache (*this)); // (owned by the component)
  224. meterCacheOn = true;
  225. }
  226. setWantsKeyboardFocus (false);
  227. setMouseClickGrabsKeyboardFocus (false);
  228. engine.addChangeListener (this);
  229. engine.getLevelsBroadcaster().addChangeListener (this);
  230. updateSize();
  231. // (the meters and the automated faders move at the display's refresh: `frames`, round 174e)
  232. }
  233. MixerStrips::~MixerStrips()
  234. {
  235. engine.getLevelsBroadcaster().removeChangeListener (this);
  236. engine.removeChangeListener (this);
  237. }
  238. void MixerStrips::setVisibleHeight (int height)
  239. {
  240. visibleHeight = juce::jmax (300, height);
  241. updateSize();
  242. }
  243. void MixerStrips::updateSize()
  244. {
  245. const auto tracks = (int) engine.getSong().mixer.size();
  246. layoutStrips();
  247. setSize (contentWidth, visibleHeight);
  248. levels.resize ((std::size_t) juce::jmax (1, tracks) * 2);
  249. }
  250. void MixerStrips::layoutStrips()
  251. {
  252. const auto& song = engine.getSong();
  253. const auto tracks = (int) song.mixer.size();
  254. stripXs.assign ((std::size_t) tracks + 1, 0);
  255. // "Show only used inserts" (round 163): unused inserts take no room, except those brought back with "+" (so a new
  256. // insert shows; selecting another strip doesn't move the strips under the mouse)
  257. hidden.assign ((std::size_t) tracks + 1, false);
  258. if (showUsedOnly)
  259. {
  260. // round 190am: the selected inserts stay, and stay after the selection moves on (no strip jumps under the mouse)
  261. revealed.insert (selected);
  262. revealed.insert (selection.begin(), selection.end());
  263. hidden = mixerops::hiddenUnusedInserts (song, revealed);
  264. }
  265. // folded groups (round 177a): nothing is computed unless a group is folded
  266. foldShow.clear();
  267. tabOf.clear();
  268. foldHead.assign ((std::size_t) tracks + 1, false);
  269. for (int t = 1; t < tracks; ++t)
  270. if (song.mixer[(std::size_t) t].separator || (t + 1 < tracks && song.mixer[(std::size_t) t + 1].separator))
  271. {
  272. // the first strip of a group that can fold carries the chevron (a separator sets groups off)
  273. const auto group = mixerops::groupOf (song, t);
  274. if (! group.empty() && group.front() == t && mixerops::canFold (song, t))
  275. foldHead[(std::size_t) t] = true;
  276. }
  277. if (std::any_of (song.mixer.begin() + std::min<std::ptrdiff_t> (1, (std::ptrdiff_t) song.mixer.size()), song.mixer.end(),
  278. [] (const MixerTrack& m) { return m.folded; }))
  279. {
  280. foldShow = mixerops::foldView (song);
  281. tabOf.assign ((std::size_t) tracks, -1);
  282. for (int t = 1; t < tracks; ++t)
  283. {
  284. if (foldShow[(std::size_t) t] == mixerops::FoldShow::hidden)
  285. hidden[(std::size_t) t] = true;
  286. if (foldShow[(std::size_t) t] == mixerops::FoldShow::tab)
  287. for (const auto m : mixerops::groupOf (song, t))
  288. tabOf[(std::size_t) m] = t;
  289. }
  290. for (int t = 1; t < tracks; ++t) // a folded summing group: its bus strip carries the chevron (to unfold it)
  291. if (foldHead[(std::size_t) t] && hidden[(std::size_t) t] && song.mixer[(std::size_t) t].folded)
  292. if (const auto bus = mixerops::groupBus (song, mixerops::groupOf (song, t)); bus > 0)
  293. foldHead[(std::size_t) bus] = true;
  294. }
  295. dockGaps.clear();
  296. separatorLines.clear();
  297. vcaXs.clear();
  298. loudnessX = hiddenX;
  299. int x = 4;
  300. bool any = false, afterMaster = false;
  301. for (auto dock : { MixerDock::left, MixerDock::middle, MixerDock::right })
  302. {
  303. const auto d = (int) dock;
  304. blockStart[d] = x;
  305. bool first = true;
  306. for (int t = 0; t < tracks; ++t)
  307. {
  308. const auto& track = song.mixer[(std::size_t) t];
  309. if (track.dock != dock)
  310. continue;
  311. if (hidden[(std::size_t) t])
  312. {
  313. stripXs[(std::size_t) t] = hiddenX;
  314. continue;
  315. }
  316. if (any && first && dock == MixerDock::right)
  317. {
  318. // the gap between two blocks belongs to the pinned block: the right block's is before its strips,
  319. // the left block's after them (below)
  320. dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
  321. x += dockGap;
  322. }
  323. else if (! first && track.separator && t > 0)
  324. {
  325. separatorLines.push_back ({ x + separatorGap / 2 - 3, dock });
  326. x += separatorGap;
  327. }
  328. else if (afterMaster)
  329. x += 8;
  330. if (t == 0 && ! song.vcas.empty()) // the VCA strips: their own block left of the Master (round 177a)
  331. {
  332. for (std::size_t i = 0; i < song.vcas.size(); ++i)
  333. {
  334. vcaXs.push_back (x);
  335. x += spec().stripWidth;
  336. }
  337. x += 8;
  338. }
  339. stripXs[(std::size_t) t] = x;
  340. x += stripWidthOf (t);
  341. if (t == 0 && showLoudness) // the loudness panel: right of the Master, in its dock (round 190am)
  342. {
  343. loudnessX = x;
  344. x += loudnessWidth;
  345. }
  346. any = true;
  347. first = false;
  348. afterMaster = t == 0;
  349. }
  350. if (dock == MixerDock::middle) // the "+" button ends the middle block
  351. {
  352. if (afterMaster)
  353. x += 8;
  354. stripXs[(std::size_t) tracks] = x;
  355. x += spec().stripWidth;
  356. afterMaster = false;
  357. any = true;
  358. }
  359. blockEnd[d] = x;
  360. if (dock == MixerDock::left && ! first) // the left block carries its gap to the middle
  361. {
  362. dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
  363. x += dockGap;
  364. blockEnd[d] = x;
  365. afterMaster = false;
  366. }
  367. }
  368. contentWidth = x + 8;
  369. }
  370. MixerDock MixerStrips::dockOf (int track) const noexcept
  371. {
  372. const auto& mixer = engine.getSong().mixer;
  373. return track >= 0 && track < (int) mixer.size() ? mixer[(std::size_t) track].dock : MixerDock::middle;
  374. }
  375. int MixerStrips::pinOffset (MixerDock dock) const noexcept
  376. {
  377. auto* parent = getParentComponent();
  378. if (parent == nullptr || dock == MixerDock::middle)
  379. return 0;
  380. const auto scroll = juce::jmax (0, -getX());
  381. const auto visible = parent->getWidth();
  382. if (dock == MixerDock::left)
  383. return blockEnd[0] > blockStart[0] ? juce::jmin (scroll, juce::jmax (0, contentWidth - blockEnd[0])) : 0;
  384. return blockEnd[2] > blockStart[2] ? juce::jmin (0, scroll + visible - contentWidth) : 0;
  385. }
  386. int MixerStrips::stripX (int track) const noexcept
  387. {
  388. if (track <= -2) // a VCA strip (vcaStrip): it follows the Master's dock
  389. {
  390. const auto i = (std::size_t) (-2 - track);
  391. return i < vcaXs.size() ? vcaXs[i] + pinOffset (dockOf (0)) : hiddenX;
  392. }
  393. if (track >= 0 && track < (int) stripXs.size())
  394. return stripXs[(std::size_t) track] + pinOffset (dockOf (track));
  395. return track == 0 ? 4 : 4 + spec().masterWidth + 8 + (track - 1) * spec().stripWidth;
  396. }
  397. bool MixerStrips::isInterestedInDragSource (const SourceDetails& details)
  398. {
  399. if (BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details))
  400. return true;
  401. if (! BrowserComponent::isBrowserDrag (details))
  402. return false;
  403. // (asked on every mouse move of the drag: the answer for the dragged file is kept)
  404. static juce::File lastFile;
  405. static bool lastAnswer = false;
  406. if (const auto file = BrowserComponent::draggedFile (details); file != lastFile)
  407. {
  408. lastFile = file;
  409. lastAnswer = mixerpresets::isMixerPreset (file);
  410. }
  411. return lastAnswer;
  412. }
  413. void MixerStrips::itemDropped (const SourceDetails& details)
  414. {
  415. const auto t = trackAt (details.localPosition.x);
  416. const auto tracks = (int) engine.getSong().mixer.size();
  417. // FL's mixer preset dropped from the Browser (WhatsNew): onto a track it loads there, onto the empty mixer space
  418. // (or "+") it makes a new track
  419. if (BrowserComponent::isBrowserDrag (details))
  420. {
  421. const auto file = BrowserComponent::draggedFile (details);
  422. if (! mixerpresets::isMixerPreset (file))
  423. return;
  424. if (t >= 0 && t < tracks)
  425. mixerpresets::loadOnTracks (engine, { t }, file);
  426. else if (const auto added = mixerpresets::insertTrack (engine, tracks, file); added > 0)
  427. {
  428. revealed.insert (added);
  429. updateSize();
  430. selectTrack (added);
  431. }
  432. return;
  433. }
  434. if (t < 0 || t >= tracks)
  435. return;
  436. if (auto fx = BrowserComponent::draggedEffect (details); fx && onEffectDropped != nullptr)
  437. onEffectDropped (t, std::move (*fx));
  438. else if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr)
  439. onInstrumentDropped (t, std::move (*c));
  440. }
  441. int MixerStrips::trackAt (int x) const noexcept
  442. {
  443. const auto tracks = (int) engine.getSong().mixer.size();
  444. // the pinned blocks lie over the scrolled middle: they are hit first
  445. for (auto dock : { MixerDock::left, MixerDock::right, MixerDock::middle })
  446. for (int t = 0; t <= tracks; ++t) // t == tracks = "+" button
  447. if (dockOf (t) == dock && x >= stripX (t) && x < stripX (t) + stripWidthOf (t))
  448. return t;
  449. return -1;
  450. }
  451. int MixerStrips::laneTop() const noexcept
  452. {
  453. return getHeight() - laneHeight;
  454. }
  455. const mixerlayout::Spec& MixerStrips::spec() noexcept
  456. {
  457. static mixerlayout::Layout cachedFor = (mixerlayout::Layout) -1;
  458. static mixerlayout::Spec cached;
  459. if (cachedFor != layout)
  460. {
  461. cached = mixerlayout::specOf (layout);
  462. cachedFor = layout;
  463. }
  464. return cached;
  465. }
  466. void MixerStrips::setLayout (mixerlayout::Layout newLayout)
  467. {
  468. if (newLayout == layout)
  469. return;
  470. layout = newLayout;
  471. updateSize();
  472. repaint();
  473. if (onLayoutChanged)
  474. onLayoutChanged();
  475. }
  476. MixerStrips::Rows MixerStrips::rows() const noexcept
  477. {
  478. const auto& sp = spec();
  479. const auto compact = mixerlayout::isCompact (layout);
  480. Rows r;
  481. r.header = sp.verticalName ? 38 : 54;
  482. // the vertical name column takes what the fader can spare (FL's runs the strip's upper part)
  483. r.nameHeight = sp.verticalName ? juce::jlimit (40, 110, (getHeight() - 300) / 2) : 0;
  484. r.knobsHeight = ! sp.stereoKnob ? sp.knobSize + 8 : sp.stackedKnobs ? sp.knobSize + (sp.knobSize - 6) + 10 : 32;
  485. r.buttonsHeight = compact ? 32 : 20; // compact: mute above solo
  486. r.readoutHeight = sp.dbReadout ? 16 : 0;
  487. auto y = r.header;
  488. if (sp.verticalName && ! sp.nameLow)
  489. {
  490. r.nameTop = y;
  491. y += r.nameHeight;
  492. }
  493. r.knobsTop = y;
  494. r.buttonsTop = r.knobsTop + r.knobsHeight;
  495. r.faderTop = r.buttonsTop + r.buttonsHeight + 6;
  496. auto bottom = laneTop() - r.readoutHeight - 4;
  497. if (compact)
  498. {
  499. r.armY = bottom - 14;
  500. bottom -= 16;
  501. }
  502. if (sp.verticalName && sp.nameLow)
  503. {
  504. // the alt layouts: the name runs up from the strip's bottom; the dB read-out stays under the fader, above the
  505. // name (rel 0.1.23: the read-out was drawn over the name's top)
  506. r.nameTop = bottom + r.readoutHeight - r.nameHeight;
  507. bottom = r.nameTop - 4 - r.readoutHeight;
  508. }
  509. r.faderBottom = juce::jmax (r.faderTop + 40, bottom);
  510. return r;
  511. }
  512. juce::Rectangle<int> MixerStrips::foldArea (int t) const
  513. {
  514. // the chevron left of the number on a group's first strip (round 177a)
  515. return { stripX (t) + 1, 3, 12, 15 };
  516. }
  517. float MixerStrips::tabLevel (int t) const noexcept
  518. {
  519. float level = 0.0f;
  520. for (std::size_t m = 0; m < tabOf.size(); ++m)
  521. if (tabOf[m] == t)
  522. for (std::size_t ch = 0; ch < 2; ++ch)
  523. if (const auto i = m * 2 + ch; i < levels.size())
  524. level = juce::jmax (level, levels[i].level);
  525. return level;
  526. }
  527. void MixerStrips::paintFoldTab (juce::Graphics& g, int t)
  528. {
  529. // a folded group without a bus (round 177a): a slim tab in the group's colour with its name, how many inserts it
  530. // holds and the loudest member's level; a click unfolds it. The members are never hidden without a trace.
  531. using namespace theme;
  532. const auto& song = engine.getSong();
  533. const auto& head = song.mixer[(std::size_t) t];
  534. const auto x = stripX (t);
  535. const auto area = juce::Rectangle<int> (x, 2, foldTabWidth - 2, laneTop() - 2).toFloat();
  536. const auto hoveredTab = hoverTrack == t;
  537. auto plate = hoveredTab ? colour::bg3 : colour::bg2;
  538. if (head.colour != 0)
  539. plate = plate.interpolatedWith (tame (juce::Colour (head.colour)), 0.3f);
  540. theme::fillRoundRect (g, area, radius::md, plate);
  541. if (head.colour != 0)
  542. theme::fillRoundRect (g, area.withHeight (3.0f).reduced (3.0f, 0.0f), 1.5f, tame (juce::Colour (head.colour)));
  543. g.setColour (hoveredTab ? colour::borderStrong : colour::border);
  544. g.drawRoundedRectangle (area.reduced (0.5f), radius::md, 1.0f);
  545. icons::draw (g, Icon::chevronDown, juce::Rectangle<float> (12.0f, 12.0f).withCentre ({ area.getCentreX(), 12.0f }).transformedBy (
  546. juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, area.getCentreX(), 12.0f)),
  547. hoveredTab ? colour::textPrimary : colour::textSecondary);
  548. const auto members = (int) mixerops::groupOf (song, t).size();
  549. g.setColour (colour::textSecondary);
  550. g.setFont (font (9.0f, true));
  551. textcache::drawText (g, juce::String (members), (int) area.getX(), 22, (int) area.getWidth(), 12, juce::Justification::centred);
  552. // the loudest member's level: one thin bar along the fader rows
  553. const auto rail = faderRail (t);
  554. const auto bar = juce::Rectangle<float> (area.getRight() - 6.0f, (float) rail.getY(), 3.0f, (float) rail.getHeight());
  555. theme::fillRoundRect (g, bar, 1.0f, colour::bg0);
  556. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  557. paintFoldTabLevel (g, t);
  558. // the group's name, bottom to top
  559. const auto name = juce::String::fromUTF8 (head.name.c_str());
  560. const auto column = juce::Rectangle<int> ((int) area.getX() + 1, 40, (int) area.getWidth() - 8, juce::jmax (20, rail.getY() - 46));
  561. juce::Graphics::ScopedSaveState state (g);
  562. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  563. g.setColour (colour::textPrimary.withAlpha (0.9f));
  564. g.setFont (font (type::small, false));
  565. textcache::drawFittedText (g, name, juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre()),
  566. juce::Justification::centredLeft, 1, 0.8f);
  567. }
  568. void MixerStrips::paintFoldTabLevel (juce::Graphics& g, int t) const
  569. {
  570. using namespace theme;
  571. const auto rail = faderRail (t);
  572. const auto bar = juce::Rectangle<float> ((float) (stripX (t) + foldTabWidth - 2) - 6.0f, (float) rail.getY(), 3.0f, (float) rail.getHeight());
  573. const auto level = tabLevel (t);
  574. g.setColour (level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow);
  575. g.fillRect (bar.withTop (bar.getBottom() - meterPosition (level) * bar.getHeight()));
  576. }
  577. // --- VCA strips (round 177a slice 3; REA_rodada177a §3) ---------------------------------------------------------------
  578. // A VCA strip carries no audio: its fader scales its members' faders, its mute mutes them, its solo solos them. It has
  579. // no slots, pan, EQ or routing; a dashed outline and the "VCA" label set it apart from an insert.
  580. int MixerStrips::vcaAt (int x) const noexcept
  581. {
  582. for (int i = 0; i < (int) vcaXs.size(); ++i)
  583. if (const auto left = stripX (vcaStrip (i)); x >= left && x < left + spec().stripWidth)
  584. return i;
  585. return -1;
  586. }
  587. MixerStrips::Part MixerStrips::vcaPartAt (int i, juce::Point<int> p) const
  588. {
  589. const auto v = vcaStrip (i);
  590. if (headerArea (v).contains (p) || nameArea (v).contains (p))
  591. return Part::header;
  592. if (muteArea (v).contains (p))
  593. return Part::mute;
  594. if (soloArea (v).contains (p))
  595. return Part::solo;
  596. if (meterArea (v).contains (p))
  597. return Part::meter;
  598. if (faderRail (v).expanded (0, 6).contains (p))
  599. return Part::fader;
  600. return Part::body;
  601. }
  602. float MixerStrips::vcaMeter (int i, int channel) const noexcept
  603. {
  604. const auto& song = engine.getSong();
  605. float level = 0.0f;
  606. if (i < 0 || i >= (int) song.vcas.size())
  607. return level;
  608. for (const auto m : mixerops::vcaReach (song, i))
  609. if (const auto index = (std::size_t) m * 2 + (std::size_t) channel; index < levels.size())
  610. level = juce::jmax (level, levels[index].level);
  611. return level;
  612. }
  613. float MixerStrips::vcaShownLevel (int i) const noexcept
  614. {
  615. const auto& vcas = engine.getSong().vcas;
  616. if (i < 0 || i >= (int) vcas.size())
  617. return unityFader;
  618. return engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::vcaLevel, i }, vcas[(std::size_t) i].level);
  619. }
  620. ui::ValueSpec MixerStrips::vcaSpec (int i) const
  621. {
  622. const auto& vcas = engine.getSong().vcas;
  623. const auto name = i >= 0 && i < (int) vcas.size() ? juce::String::fromUTF8 (vcas[(std::size_t) i].name.c_str()) : juce::String();
  624. auto spec = ui::faderSpec (name + " - " + tr ("VCA level"), unityFader);
  625. spec.pixelsForRange = juce::jmax (60, faderRail (vcaStrip (i)).getHeight());
  626. spec.target = AutomationTarget { AutomationTargetKind::vcaLevel, i };
  627. return spec;
  628. }
  629. void MixerStrips::setVcaLevel (int i, double value)
  630. {
  631. if (i < 0 || i >= (int) engine.getSong().vcas.size())
  632. return;
  633. // like an insert's fader: only the live levels move during a drag (the gain path reads them lock-free)
  634. engine.editLevels ([i, v = juce::jlimit (0.0f, 1.0f, (float) value)] (Song& s) {
  635. if (i < (int) s.vcas.size())
  636. s.vcas[(std::size_t) i].level = v;
  637. });
  638. }
  639. void MixerStrips::repaintVca (int i)
  640. {
  641. if (i < 0 || i >= (int) vcaXs.size())
  642. return;
  643. repaint (stripX (vcaStrip (i)) - 2, 0, spec().stripWidth + 4, laneTop());
  644. // the members' ticks (the level that plays) move with it
  645. for (const auto m : mixerops::vcaReach (engine.getSong(), i))
  646. if (m > 0 && m < (int) stripXs.size() && ! isHidden (m))
  647. {
  648. const auto fader = faderArea (m);
  649. repaint (stripX (m), fader.getY() - 9, stripWidthOf (m), fader.getHeight() + 18);
  650. }
  651. }
  652. void MixerStrips::soloVca (int i)
  653. {
  654. const auto reach = mixerops::vcaReach (engine.getSong(), i);
  655. if (! reach.empty())
  656. engine.editSong ([reach] (Song& s) { mixerops::soloSelected (s, reach, false); });
  657. }
  658. juce::String MixerStrips::vcaNote (int track) const
  659. {
  660. const auto& song = engine.getSong();
  661. if (song.vcas.empty() || track <= 0 || track >= (int) song.mixer.size())
  662. return {};
  663. const auto chain = mixerops::vcasOf (song, track);
  664. if (chain.empty())
  665. return {};
  666. juce::StringArray parts;
  667. for (const auto v : chain)
  668. {
  669. const auto& vca = song.vcas[(std::size_t) v];
  670. parts.add ("VCA '" + juce::String::fromUTF8 (vca.name.c_str()) + "' " + faderToDb (vca.level) + " dB" + (vca.muted ? " (" + tr ("Muted") + ")" : juce::String()));
  671. }
  672. const auto playing = faderPosition (faderGain (song.mixer[(std::size_t) track].volume) * mixerops::vcaGain (song, track));
  673. return "(" + parts.joinIntoString (", ") + juce::String::fromUTF8 (" \xe2\x86\x92 ") + faderToDb (playing) + " dB)";
  674. }
  675. ui::Hint MixerStrips::vcaHint (int i, juce::Point<int> p) const
  676. {
  677. ui::Hint h;
  678. const auto& song = engine.getSong();
  679. if (i < 0 || i >= (int) song.vcas.size())
  680. return h;
  681. const auto& vca = song.vcas[(std::size_t) i];
  682. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  683. const auto part = dragVca >= 0 ? Part::fader : vcaPartAt (i, p);
  684. switch (part)
  685. {
  686. case Part::fader:
  687. return ui::valueHint (vcaSpec (i), vcaShownLevel (i), ui::valueGestures());
  688. case Part::mute: h.text = name + " - " + tr ("Click: mute the VCA's members. Right-click or Ctrl+click: solo"); break;
  689. case Part::solo: h.text = name + " - " + tr ("Solo the VCA's members"); break;
  690. case Part::meter: h.text = name + " - " + tr ("The loudest member's level"); break;
  691. default:
  692. h.text = name + " - " + tr ("VCA fader: moves the level of its {0} inserts (they keep their own faders) [LMB] selects them [RMB] VCA menu",
  693. { juce::String ((int) vca.members.size()) });
  694. h.hasMenu = true;
  695. break;
  696. }
  697. return h;
  698. }
  699. void MixerStrips::vcaMouseDown (const juce::MouseEvent& e, int i)
  700. {
  701. const auto& song = engine.getSong();
  702. if (i >= (int) song.vcas.size())
  703. return;
  704. const auto v = vcaStrip (i);
  705. const auto part = vcaPartAt (i, e.getPosition());
  706. if (part == Part::mute && (flmods::popup (e.mods) || flmods::ctrl (e.mods)))
  707. {
  708. soloVca (i);
  709. return;
  710. }
  711. if (flmods::popup (e.mods))
  712. {
  713. showVcaMenu (i);
  714. return;
  715. }
  716. switch (part)
  717. {
  718. case Part::mute:
  719. engine.editSong ([i] (Song& s) {
  720. if (i < (int) s.vcas.size())
  721. s.vcas[(std::size_t) i].muted = ! s.vcas[(std::size_t) i].muted;
  722. });
  723. return;
  724. case Part::solo:
  725. soloVca (i);
  726. return;
  727. case Part::fader:
  728. {
  729. if (ui::isResetClick (e))
  730. {
  731. setVcaLevel (i, unityFader);
  732. return;
  733. }
  734. const auto start = song.vcas[(std::size_t) i].level;
  735. if (! flmods::ctrl (e.mods)) // a press on the rail steps the fader towards the mouse (as an insert's)
  736. {
  737. const auto rail = faderRail (v);
  738. if (std::abs ((float) e.y - ((float) rail.getBottom() - start * (float) rail.getHeight())) > 9.0f)
  739. {
  740. pressRail (v, e.y);
  741. return;
  742. }
  743. }
  744. dragVca = i;
  745. drag.begin (e, start);
  746. ui::showValueTip (*this, faderRail (v), vcaSpec (i).text (start));
  747. return;
  748. }
  749. default:
  750. {
  751. // the header or the body selects the members (so the insert menu's VCA items act on them)
  752. std::vector<int> members;
  753. for (const auto m : song.vcas[(std::size_t) i].members)
  754. if (m > 0 && m < (int) song.mixer.size())
  755. members.push_back (m);
  756. if (! members.empty())
  757. setSelection (members, members.front());
  758. return;
  759. }
  760. }
  761. }
  762. void MixerStrips::showVcaMenu (int i)
  763. {
  764. const auto& song = engine.getSong();
  765. if (i < 0 || i >= (int) song.vcas.size())
  766. return;
  767. const auto& vca = song.vcas[(std::size_t) i];
  768. juce::PopupMenu menu;
  769. auto rename = [this, i] {
  770. if (i >= (int) engine.getSong().vcas.size())
  771. return;
  772. const auto& item = engine.getSong().vcas[(std::size_t) i];
  773. showNameAndColourDialog (tr ("Rename VCA"), juce::String::fromUTF8 (item.name.c_str()), item.colour,
  774. [this, i] (const juce::String& name, std::uint32_t colour) {
  775. engine.editSong ([i, n = name.trim().toStdString(), colour] (Song& s) {
  776. if (i >= (int) s.vcas.size())
  777. return;
  778. if (! n.empty())
  779. s.vcas[(std::size_t) i].name = n;
  780. s.vcas[(std::size_t) i].colour = colour;
  781. });
  782. });
  783. };
  784. ui::addItemHeader (menu, tr ("VCA"), juce::String::fromUTF8 (vca.name.c_str()), vca.colour != 0 ? juce::Colour (vca.colour) : juce::Colour(), rename);
  785. menu.addItem (tr ("Rename and color..."), rename);
  786. // the selected inserts (not the Master) join or leave this VCA
  787. std::vector<int> picked;
  788. for (const auto m : selection)
  789. if (m > 0 && m < (int) song.mixer.size())
  790. picked.push_back (m);
  791. const auto in = [&vca] (int m) { return std::binary_search (vca.members.begin(), vca.members.end(), m); };
  792. menu.addItem (tr ("Assign selected inserts"), ! picked.empty() && ! std::all_of (picked.begin(), picked.end(), in), false, [this, picked, i] {
  793. engine.editSong ([picked, i] (Song& s) { mixerops::assignToVca (s, picked, i); });
  794. });
  795. menu.addItem (tr ("Remove selected inserts"), std::any_of (picked.begin(), picked.end(), in), false, [this, picked, i] {
  796. engine.editSong ([picked, i] (Song& s) { mixerops::removeFromVca (s, picked, i); });
  797. });
  798. // nesting: this VCA follows another one (never one that already follows it)
  799. juce::PopupMenu follow;
  800. follow.addItem (tr ("None"), true, vca.parent < 0, [this, i] {
  801. engine.editSong ([i] (Song& s) {
  802. if (i < (int) s.vcas.size())
  803. s.vcas[(std::size_t) i].parent = -1;
  804. });
  805. });
  806. for (int other = 0; other < (int) song.vcas.size(); ++other)
  807. {
  808. if (other == i)
  809. continue;
  810. bool loops = false; // `other` follows `i` (directly or through others)
  811. 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)
  812. if (up == i)
  813. {
  814. loops = true;
  815. break;
  816. }
  817. follow.addItem (juce::String::fromUTF8 (song.vcas[(std::size_t) other].name.c_str()), ! loops, vca.parent == other, [this, i, other] {
  818. engine.editSong ([i, other] (Song& s) {
  819. if (i < (int) s.vcas.size() && other < (int) s.vcas.size())
  820. s.vcas[(std::size_t) i].parent = other;
  821. });
  822. });
  823. }
  824. menu.addSubMenu (tr ("Follow VCA"), follow, song.vcas.size() > 1);
  825. menu.addSeparator();
  826. menu.addItem (tr ("Merge VCA into members"), ! vca.members.empty(), false, [this, i] {
  827. engine.editSong ([i] (Song& s) { mixerops::mergeVcaIntoMembers (s, i); });
  828. });
  829. menu.addItem (tr ("Delete VCA"), [this, i] {
  830. engine.editSong ([i] (Song& s) { mixerops::deleteVca (s, i); });
  831. updateSize();
  832. });
  833. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  834. }
  835. void MixerStrips::paintVcaMeter (juce::Graphics& g, int i) const
  836. {
  837. using namespace theme;
  838. const auto& sp = spec();
  839. const auto meters = meterArea (vcaStrip (i));
  840. for (int ch = 0; ch < 2; ++ch)
  841. {
  842. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  843. const auto level = vcaMeter (i, ch);
  844. const auto h = (int) (meterPosition (level) * (float) bar.getHeight());
  845. g.setColour ((level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow).withAlpha (0.8f));
  846. g.fillRect (bar.withTop (bar.getBottom() - h));
  847. }
  848. }
  849. void MixerStrips::paintVcaStrip (juce::Graphics& g, int i)
  850. {
  851. using namespace theme;
  852. const auto& song = engine.getSong();
  853. if (i < 0 || i >= (int) song.vcas.size())
  854. return;
  855. const auto& vca = song.vcas[(std::size_t) i];
  856. const auto v = vcaStrip (i);
  857. const auto x = stripX (v);
  858. const auto& sp = spec();
  859. const auto w = sp.stripWidth;
  860. if (! g.clipRegionIntersects ({ x, 0, w, laneTop() }))
  861. return;
  862. const auto plateWidth = w - sp.gap;
  863. const auto compactLayout = mixerlayout::isCompact (layout);
  864. const auto strip = juce::Rectangle<int> (x, 2, plateWidth, laneTop() - 2).toFloat();
  865. const auto hovered = [this, v] (Part p) { return hoverTrack == v && hoverPart == p; };
  866. const auto colourOf = vca.colour != 0 ? tame (juce::Colour (vca.colour)) : colour::info;
  867. auto plate = hoverTrack == v ? colour::bg3 : colour::bg2;
  868. plate = plate.interpolatedWith (colourOf, 0.12f);
  869. theme::fillRoundRect (g, strip, radius::md, plate);
  870. theme::fillRoundRect (g, strip.withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, colourOf);
  871. {
  872. // a dashed outline: this strip carries no audio
  873. juce::Path outline;
  874. outline.addRoundedRectangle (strip.reduced (0.5f), radius::md);
  875. juce::Path dashed;
  876. const float dashes[] = { 3.0f, 3.0f };
  877. juce::PathStrokeType (1.0f).createDashedStroke (dashed, outline, dashes, 2);
  878. g.setColour (colourOf.withAlpha (0.55f));
  879. g.fillPath (dashed);
  880. }
  881. // header: "VCA" where an insert shows its number, the member count under it, the name as on an insert
  882. g.setColour (colour::textSecondary);
  883. g.setFont (font (compactLayout ? 9.5f : type::caption, true));
  884. textcache::drawFittedText (g, "VCA", juce::Rectangle<int> (x, 4, plateWidth, 13), juce::Justification::centred, 1, 0.6f);
  885. g.setFont (font (9.0f));
  886. textcache::drawFittedText (g, juce::String::fromUTF8 ("\xc3\x97") + juce::String ((int) vca.members.size()), iconArea (v),
  887. juce::Justification::centred, 1, 0.6f);
  888. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  889. g.setColour (vca.muted ? colour::textDisabled : colour::textPrimary.withAlpha (0.9f));
  890. g.setFont (font (compactLayout ? 10.0f : type::small));
  891. if (const auto box = nameArea (v); ! sp.verticalName)
  892. textcache::drawFittedText (g, name, box, juce::Justification::centred, 1, 0.7f);
  893. else
  894. {
  895. const auto column = box.reduced (2, 4);
  896. juce::Graphics::ScopedSaveState state (g);
  897. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  898. const auto rotated = juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre());
  899. textcache::drawFittedText (g, name, rotated, juce::Justification::centredLeft, 1, 0.8f);
  900. }
  901. // mute (the members) and solo (the members)
  902. {
  903. const auto led = compactLayout ? 10.0f : 12.0f;
  904. const auto m = muteArea (v).toFloat().withSizeKeepingCentre (led, led);
  905. g.setColour (muteLed (vca.muted));
  906. g.fillEllipse (m);
  907. if (! vca.muted || hovered (Part::mute))
  908. {
  909. g.setColour (hovered (Part::mute) ? colour::textSecondary : colour::ledOn.withAlpha (0.25f));
  910. g.drawEllipse (m.expanded (2.0f), 1.0f);
  911. }
  912. const auto reach = mixerops::vcaReach (song, i);
  913. const auto soloed = ! reach.empty() && std::all_of (reach.begin(), reach.end(), [&song] (int t) {
  914. return t > 0 && t < (int) song.mixer.size() && song.mixer[(std::size_t) t].solo;
  915. });
  916. const auto s = soloArea (v).toFloat().reduced (2.0f);
  917. theme::fillRoundRect (g, s, radius::sm, soloed ? colour::accent : hovered (Part::solo) ? colour::bg5 : colour::bg0);
  918. g.setColour (soloed ? colour::onAccent : hovered (Part::solo) ? colour::textPrimary : colour::textSecondary);
  919. g.setFont (font (type::caption, true));
  920. textcache::drawText (g, "S", s.toNearestInt(), juce::Justification::centred);
  921. }
  922. // the loudest member's meter and the VCA's fader
  923. const auto area = faderArea (v);
  924. const auto meters = meterArea (v);
  925. const auto fader = faderRail (v);
  926. for (int ch = 0; ch < 2; ++ch)
  927. {
  928. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  929. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  930. }
  931. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  932. paintVcaMeter (g, i);
  933. const auto railX = (float) fader.getCentreX();
  934. const auto level = vcaShownLevel (i);
  935. const auto capY = (float) fader.getBottom() - level * (float) fader.getHeight();
  936. theme::fillRoundRect (g, { railX - 2.0f, (float) fader.getY(), 4.0f, (float) fader.getHeight() }, 2.0f, colour::bg0);
  937. 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));
  938. const auto unityY = (float) fader.getBottom() - unityFader * (float) fader.getHeight();
  939. g.setColour (colour::textDisabled);
  940. g.drawHorizontalLine ((int) unityY, (float) fader.getX(), railX - 5.0f);
  941. g.drawHorizontalLine ((int) unityY, railX + 5.0f, (float) fader.getRight());
  942. const auto capActive = hovered (Part::fader) || dragVca == i;
  943. const auto capWidth = juce::jmin ((float) fader.getWidth() + 2.0f, 26.0f);
  944. const auto cap = juce::Rectangle<float> (capWidth, 12.0f).withCentre ({ railX, capY });
  945. theme::fillRoundRect (g, cap.translated (0.0f, 1.5f), radius::sm, juce::Colours::black.withAlpha (0.35f));
  946. theme::fillRoundRect (g, cap, radius::sm, capActive ? juce::Colour (0xffffffff) : juce::Colour (0xffd4d7dd));
  947. g.setColour (colourOf);
  948. g.fillRect (cap.withSizeKeepingCentre (capWidth - 8.0f, 2.0f));
  949. if (sp.dbReadout)
  950. {
  951. g.setColour (colour::textSecondary);
  952. g.setFont (font (type::caption));
  953. textcache::drawFittedText (g, faderToDb (level) + " dB", juce::Rectangle<int> (x, area.getBottom() + 3, plateWidth, 14), juce::Justification::centred, 1, 0.7f);
  954. }
  955. }
  956. juce::Rectangle<int> MixerStrips::headerArea (int t) const
  957. {
  958. return { stripX (t), 0, stripWidthOf (t) - spec().gap, rows().header };
  959. }
  960. juce::Rectangle<int> MixerStrips::nameArea (int t) const
  961. {
  962. const auto r = rows();
  963. const auto w = stripWidthOf (t) - spec().gap;
  964. if (r.nameHeight <= 0) // Extra large: the name row of the header
  965. return { stripX (t) + 3, 38, w - 6, 14 };
  966. // the name runs up the strip's left part; the right part shows the meters (as FL's)
  967. const auto nameWidth = mixerlayout::isCompact (layout) ? w : juce::jmax (14, w - 2 * spec().meterWidth - 8);
  968. return { stripX (t), r.nameTop, nameWidth, r.nameHeight };
  969. }
  970. juce::Rectangle<int> MixerStrips::iconArea (int t) const
  971. {
  972. const auto w = stripWidthOf (t) - spec().gap;
  973. const auto size = juce::jmin (16, w - 2);
  974. return { stripX (t) + (w - size) / 2, rows().iconY, size, size };
  975. }
  976. juce::Rectangle<int> MixerStrips::armArea (int t) const
  977. {
  978. const auto r = rows();
  979. if (r.armY >= 0)
  980. {
  981. const auto w = stripWidthOf (t) - spec().gap;
  982. return { stripX (t) + (w - 13) / 2, r.armY, 13, 13 };
  983. }
  984. return { stripX (t) + 4, 4, 13, 13 };
  985. }
  986. juce::Rectangle<int> MixerStrips::inputArea (int t) const
  987. {
  988. // a thin level bar under the header (inserts with an input source)
  989. return { stripX (t) + 3, rows().header - 3, stripWidthOf (t) - spec().gap - 6, 3 };
  990. }
  991. juce::Rectangle<int> MixerStrips::panArea (int t) const
  992. {
  993. const auto r = rows();
  994. const auto& sp = spec();
  995. const auto w = stripWidthOf (t) - sp.gap;
  996. if (! sp.stereoKnob)
  997. return { stripX (t), r.knobsTop, w, r.knobsHeight };
  998. if (sp.stackedKnobs)
  999. return { stripX (t), r.knobsTop, w, sp.knobSize + 4 };
  1000. return { stripX (t), r.knobsTop, w / 2, r.knobsHeight };
  1001. }
  1002. juce::Rectangle<int> MixerStrips::stereoArea (int t) const
  1003. {
  1004. const auto r = rows();
  1005. const auto& sp = spec();
  1006. const auto w = stripWidthOf (t) - sp.gap;
  1007. if (! sp.stereoKnob)
  1008. return {};
  1009. if (sp.stackedKnobs)
  1010. return { stripX (t), r.knobsTop + sp.knobSize + 4, w, r.knobsHeight - sp.knobSize - 4 };
  1011. return { stripX (t) + w / 2, r.knobsTop, w - w / 2, r.knobsHeight };
  1012. }
  1013. juce::Rectangle<int> MixerStrips::muteArea (int t) const
  1014. {
  1015. const auto r = rows();
  1016. const auto w = stripWidthOf (t) - spec().gap;
  1017. if (mixerlayout::isCompact (layout))
  1018. return { stripX (t), r.buttonsTop, w, 16 };
  1019. if (t == 0)
  1020. return { stripX (t) + 4, r.buttonsTop, 24, r.buttonsHeight };
  1021. return { stripX (t) + 2, r.buttonsTop, w / 2 - 2, r.buttonsHeight };
  1022. }
  1023. juce::Rectangle<int> MixerStrips::soloArea (int t) const
  1024. {
  1025. const auto r = rows();
  1026. const auto w = stripWidthOf (t) - spec().gap;
  1027. if (mixerlayout::isCompact (layout))
  1028. return { stripX (t) + (w - 16) / 2, r.buttonsTop + 16, 16, 16 };
  1029. return { stripX (t) + w - juce::jmin (24, w / 2), r.buttonsTop, juce::jmin (24, w / 2), r.buttonsHeight };
  1030. }
  1031. juce::Rectangle<int> MixerStrips::faderArea (int t) const
  1032. {
  1033. const auto r = rows();
  1034. const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
  1035. return { stripX (t) + inset, r.faderTop, stripWidthOf (t) - spec().gap - 2 * inset, r.faderBottom - r.faderTop };
  1036. }
  1037. juce::Rectangle<int> MixerStrips::meterArea (int t) const
  1038. {
  1039. return faderArea (t).withWidth (spec().meterWidth * 2 + 2);
  1040. }
  1041. juce::Rectangle<int> MixerStrips::grArea (int t) const
  1042. {
  1043. // in the gap between the meters and the fader (compact layouts have none: over the right meter's edge)
  1044. const auto meters = meterArea (t);
  1045. return mixerlayout::isCompact (layout) ? meters.withTrimmedLeft (meters.getWidth() - 2) : meters.withX (meters.getRight() + 1).withWidth (3);
  1046. }
  1047. float MixerStrips::gainReduction (int t) const
  1048. {
  1049. const auto& mixer = engine.getSong().mixer;
  1050. if (t <= 0 || t >= (int) mixer.size())
  1051. return -1.0f;
  1052. const auto* times = engine.getProcessTimes();
  1053. auto gr = -1.0f;
  1054. const auto& slots = mixer[(std::size_t) t].effects;
  1055. for (int s = 0; s < (int) slots.size() && s < maxEffectSlots; ++s)
  1056. {
  1057. if (! slots[(std::size_t) s].enabled || ! mixerops::reportsGainReduction (slots[(std::size_t) s].kind))
  1058. continue;
  1059. const auto key = (std::size_t) (t * maxEffectSlots + s) * ProcessTimes::meterOutputs;
  1060. const auto v = times != nullptr && key < times->effectMeters.size() ? times->effectMeters[key].load (std::memory_order_relaxed) : 0.0f;
  1061. gr = juce::jmax (gr, juce::jlimit (0.0f, 1.0f, v));
  1062. }
  1063. return gr;
  1064. }
  1065. juce::Rectangle<int> MixerStrips::faderRail (int t) const
  1066. {
  1067. return faderArea (t).withTrimmedLeft (spec().meterWidth * 2 + (mixerlayout::isCompact (layout) ? 3 : 6) + (t == 0 ? masterScaleWidth : 0));
  1068. }
  1069. juce::Rectangle<int> MixerStrips::routeArea (int t) const
  1070. {
  1071. const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
  1072. return { stripX (t) + inset, laneTop() + 2, stripWidthOf (t) - spec().gap - 2 * inset, switchHeight };
  1073. }
  1074. juce::Rectangle<int> MixerStrips::sendArea (int t) const
  1075. {
  1076. return { stripX (t), laneTop() + 2 + switchHeight, stripWidthOf (t) - spec().gap, sendKnobHeight };
  1077. }
  1078. MixerStrips::Part MixerStrips::partAt (int t, juce::Point<int> p) const
  1079. {
  1080. const auto& song = engine.getSong();
  1081. if (t == (int) song.mixer.size())
  1082. return Part::add;
  1083. if (t < 0 || t > (int) song.mixer.size())
  1084. return Part::none;
  1085. const auto sending = selected > 0 && t != selected && selected < (int) song.mixer.size();
  1086. if (isFoldTab (t))
  1087. return Part::tab;
  1088. if (t > 0 && t < (int) foldHead.size() && foldHead[(std::size_t) t] && foldArea (t).contains (p))
  1089. return Part::fold;
  1090. if (t > 0 && armArea (t).expanded (1).contains (p))
  1091. return Part::arm;
  1092. if (t > 0 && t < (int) engine.getSong().mixer.size() && engine.getSong().mixer[(std::size_t) t].inputChannel >= 0
  1093. && inputArea (t).expanded (0, 2).contains (p))
  1094. return Part::input;
  1095. if (headerArea (t).contains (p) || nameArea (t).contains (p))
  1096. return Part::header;
  1097. if (panArea (t).contains (p))
  1098. return Part::pan;
  1099. if (stereoArea (t).contains (p))
  1100. return Part::stereo;
  1101. if (muteArea (t).contains (p))
  1102. return Part::mute;
  1103. if (t > 0 && soloArea (t).contains (p))
  1104. return Part::solo;
  1105. if (sending && routeArea (t).contains (p) && (song.routes (selected, t) || song.canRoute (selected, t)))
  1106. return Part::route;
  1107. if (sending && sendArea (t).contains (p) && song.routes (selected, t))
  1108. return Part::send;
  1109. if (meterArea (t).contains (p))
  1110. return Part::meter;
  1111. if (faderRail (t).expanded (0, 6).contains (p))
  1112. return Part::fader;
  1113. return Part::body;
  1114. }
  1115. juce::Rectangle<int> MixerStrips::tipArea (Part part, int t) const
  1116. {
  1117. switch (part)
  1118. {
  1119. case Part::pan: return panArea (t);
  1120. case Part::stereo: return stereoArea (t);
  1121. case Part::send: return sendArea (t);
  1122. case Part::route: return routeArea (t);
  1123. case Part::fader:
  1124. {
  1125. const auto rail = faderRail (t);
  1126. const auto& mixer = engine.getSong().mixer;
  1127. const auto v = t >= 0 && t < (int) mixer.size() ? shownVolume (t) : 0.0f;
  1128. const auto capY = rail.getBottom() - (int) (v * (float) rail.getHeight());
  1129. return { rail.getX(), capY - 6, rail.getWidth(), 12 };
  1130. }
  1131. default: return {};
  1132. }
  1133. }
  1134. void MixerStrips::showTip (Part part, int t, bool transient)
  1135. {
  1136. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  1137. return;
  1138. const auto spec = specFor (part, t);
  1139. const auto text = spec.text (valueOf (part, t));
  1140. ui::postHint (ui::valueHint (spec, valueOf (part, t), ui::valueGestures()));
  1141. if (transient)
  1142. ui::flashValueTip (*this, tipArea (part, t), text);
  1143. else
  1144. ui::showValueTip (*this, tipArea (part, t), text);
  1145. }
  1146. void MixerStrips::setHover (Part part, int t)
  1147. {
  1148. if (part == hoverPart && t == hoverTrack)
  1149. return;
  1150. auto dirty = [this] (int track) {
  1151. if (track >= 0 || track <= -2) // (≤ -2: a VCA strip)
  1152. repaint (stripX (track) - 2, 0, stripWidthOf (track) + 4, getHeight());
  1153. };
  1154. dirty (hoverTrack);
  1155. hoverPart = part;
  1156. hoverTrack = t;
  1157. dirty (hoverTrack);
  1158. }
  1159. void MixerStrips::mouseMove (const juce::MouseEvent& e)
  1160. {
  1161. if (const auto i = vcaAt (e.x); i >= 0)
  1162. {
  1163. setHover (vcaPartAt (i, e.getPosition()), vcaStrip (i));
  1164. return;
  1165. }
  1166. if (const auto over = showLoudness && loudnessResetArea().contains (e.getPosition()); over != loudnessResetHovered)
  1167. {
  1168. loudnessResetHovered = over;
  1169. repaint (loudnessResetArea().expanded (2));
  1170. }
  1171. const auto t = trackAt (e.x);
  1172. setHover (t >= 0 ? partAt (t, e.getPosition()) : Part::none, t);
  1173. }
  1174. void MixerStrips::mouseExit (const juce::MouseEvent&)
  1175. {
  1176. if (std::exchange (loudnessResetHovered, false))
  1177. repaint (loudnessResetArea().expanded (2));
  1178. setHover (Part::none, -1);
  1179. }
  1180. void MixerStrips::paint (juce::Graphics& g)
  1181. {
  1182. const uitrace::Scope trace ("MixerStrips paint", true, g.getClipBounds());
  1183. using namespace theme;
  1184. const auto& song = engine.getSong();
  1185. const auto tracks = (int) song.mixer.size();
  1186. const auto clip = g.getClipBounds();
  1187. // round 173f: a frame of the meters' timer repaints only the meter rectangles, but the clip's bounds span every strip
  1188. // between them, so each strip's parts are drawn only where the frame's region (not its bounds) reaches them
  1189. const auto needs = [&g] (juce::Rectangle<int> area) { return g.clipRegionIntersects (area.expanded (3)); };
  1190. g.fillAll (colour::bg1);
  1191. // the routing lane runs under all strips
  1192. g.setColour (colour::bg0.withAlpha (0.55f));
  1193. g.fillRect (0, laneTop() + switchHeight + sendKnobHeight + 2, getWidth(), wiresHeight + 2);
  1194. // FL's separators (a line on the left of the track) and the gaps between the dock blocks (round 146a), drawn
  1195. // per block so the pinned left / right blocks cover the scrolled middle (round 149)
  1196. auto paintDividers = [&] (MixerDock dock) {
  1197. const auto shift = pinOffset (dock);
  1198. g.setColour (colour::borderStrong);
  1199. for (auto [lx, d] : separatorLines)
  1200. if (d == dock)
  1201. theme::fillRoundRect (g, { (float) (lx + shift), 8.0f, 2.0f, (float) laneTop() - 14.0f }, 1.0f, colour::borderStrong);
  1202. g.setColour (colour::bg0);
  1203. for (auto [gx, d] : dockGaps)
  1204. if (d == dock)
  1205. g.fillRect (gx + shift - 3, 0, 6, getHeight());
  1206. };
  1207. for (auto pass : { MixerDock::middle, MixerDock::left, MixerDock::right })
  1208. {
  1209. if (pass == MixerDock::middle)
  1210. {
  1211. // "+" button
  1212. if (tracks < maxMixerTracks)
  1213. {
  1214. const auto add = juce::Rectangle<int> (stripX (tracks), 2, spec().stripWidth - spec().gap, 60).toFloat();
  1215. const auto addHovered = hoverPart == Part::add;
  1216. theme::fillRoundRect (g, add, radius::md, addHovered ? colour::bg4 : colour::bg2);
  1217. g.setColour (addHovered ? colour::borderStrong : colour::border);
  1218. g.drawRoundedRectangle (add.reduced (0.5f), radius::md, 1.0f);
  1219. icons::draw (g, Icon::plus, add.withSizeKeepingCentre (22.0f, 22.0f), addHovered ? colour::textPrimary : colour::textSecondary);
  1220. }
  1221. }
  1222. else if (const auto shift = pinOffset (pass); shift != 0) // a pinned block hides what scrolls under it
  1223. {
  1224. const auto d = (int) pass;
  1225. g.setColour (colour::bg1);
  1226. g.fillRect (blockStart[d] + shift, 0, blockEnd[d] - blockStart[d], laneTop());
  1227. g.setColour (colour::bg0.withAlpha (0.55f));
  1228. g.fillRect (blockStart[d] + shift, laneTop(), blockEnd[d] - blockStart[d], getHeight() - laneTop());
  1229. }
  1230. for (int t = 0; t < tracks; ++t)
  1231. {
  1232. if (song.mixer[(std::size_t) t].dock != pass || isHidden (t))
  1233. continue;
  1234. const auto x = stripX (t);
  1235. const auto w = stripWidthOf (t);
  1236. if (x > clip.getRight() || x + w < clip.getX())
  1237. continue;
  1238. if (isFoldTab (t))
  1239. {
  1240. paintFoldTab (g, t);
  1241. continue;
  1242. }
  1243. const auto& track = song.mixer[(std::size_t) t];
  1244. const auto& sp = spec();
  1245. const auto plateWidth = w - sp.gap;
  1246. const auto compactLayout = mixerlayout::isCompact (layout);
  1247. const auto strip = juce::Rectangle<int> (x, 2, plateWidth, laneTop() - 2);
  1248. const auto isSelected = t == selected;
  1249. const auto inSelection = std::binary_search (selection.begin(), selection.end(), t);
  1250. const auto stripHovered = hoverTrack == t;
  1251. const auto hovered = [this, t] (Part p) { return hoverTrack == t && hoverPart == p; };
  1252. const auto dragging = [this, t] (Part p) { return dragTrack == t && dragPart == p; };
  1253. // the strip is tinted with the insert's colour (FL tints whole strips, so groups read at a glance);
  1254. // kept dark so meters, knobs and text keep their contrast
  1255. auto plate = isSelected || inSelection ? colour::bg4 : (t == 0 ? colour::bg3 : stripHovered ? colour::bg3 : colour::bg2);
  1256. if (track.colour != 0)
  1257. plate = plate.interpolatedWith (tame (juce::Colour (track.colour)), isSelected ? 0.26f : 0.2f);
  1258. theme::fillRoundRect (g, strip.toFloat(), radius::md, plate);
  1259. if (track.colour != 0) // thin colour band at the top
  1260. {
  1261. theme::fillRoundRect (g, strip.toFloat().withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, tame (juce::Colour (track.colour)));
  1262. }
  1263. if (inSelection && ! isSelected)
  1264. {
  1265. g.setColour (colour::accent.withAlpha (0.3f));
  1266. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
  1267. }
  1268. if (isSelected)
  1269. {
  1270. g.setColour (colour::accent.withAlpha (0.55f));
  1271. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
  1272. theme::fillRoundRect (g, strip.toFloat().withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, colour::accent);
  1273. }
  1274. if (headerDragged && headerDragTrack == t)
  1275. {
  1276. g.setColour (colour::accent);
  1277. g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.5f);
  1278. }
  1279. // record arm: the input recording goes through this insert
  1280. if (t > 0 && needs (armArea (t).getUnion (inputArea (t))))
  1281. {
  1282. const auto armed = engine.isInsertArmed (t);
  1283. const auto r = armArea (t).toFloat().reduced (2.0f);
  1284. g.setColour (armed ? colour::record : hovered (Part::arm) ? colour::bg5 : colour::bg0);
  1285. g.fillEllipse (r);
  1286. g.setColour (armed ? colour::record.brighter (0.3f) : hovered (Part::arm) ? colour::textSecondary : colour::borderStrong);
  1287. g.drawEllipse (r, 1.0f);
  1288. if (track.recordSafe) // record safe: a slash through the arm button
  1289. {
  1290. g.setColour (colour::textDisabled);
  1291. g.drawLine (r.getX() + 1.0f, r.getBottom() - 1.0f, r.getRight() - 1.0f, r.getY() + 1.0f, 1.2f);
  1292. }
  1293. // the input level (inserts with an audio input source)
  1294. if (track.inputChannel >= 0 && (std::size_t) t < inputLevels.size())
  1295. {
  1296. const auto bar = inputArea (t).toFloat();
  1297. theme::fillRoundRect (g, bar, 1.0f, colour::bg0);
  1298. const auto level = inputLevels[(std::size_t) t];
  1299. const auto fill = juce::jlimit (0.0f, 1.0f, (juce::Decibels::gainToDecibels (level, -60.0f) + 60.0f) / 60.0f);
  1300. theme::fillRoundRect (g, bar.withWidth (bar.getWidth() * fill), 1.0f, level >= 0.99f ? colour::record : colour::meterLow);
  1301. }
  1302. }
  1303. // header: number and effect count on one line, the icon under them (FL's place), then the name: on the
  1304. // header's last row (Extra large) or up a column of the strip (round 168h)
  1305. if (needs (juce::Rectangle<int> (x, 0, plateWidth, 18).getUnion (iconArea (t))))
  1306. {
  1307. g.setColour (isSelected ? colour::accent : colour::textSecondary);
  1308. g.setFont (font (compactLayout ? 9.5f : type::caption, isSelected));
  1309. textcache::drawFittedText (g, t == 0 ? juce::String ("M") : juce::String (t), juce::Rectangle<int> (x, 4, plateWidth, 13),
  1310. juce::Justification::centred, 1, 0.6f);
  1311. if (t < (int) foldHead.size() && foldHead[(std::size_t) t]) // round 177a: fold / unfold the group
  1312. {
  1313. const auto folded = mixerops::isFolded (song, t);
  1314. const auto box = foldArea (t).toFloat();
  1315. const auto c = box.getCentre();
  1316. icons::draw (g, Icon::chevronDown,
  1317. juce::Rectangle<float> (10.0f, 10.0f).withCentre (c).transformedBy (
  1318. juce::AffineTransform::rotation ((folded ? -1.0f : 1.0f) * juce::MathConstants<float>::halfPi, c.x, c.y)),
  1319. hovered (Part::fold) ? colour::textPrimary : colour::textSecondary);
  1320. }
  1321. if (const auto icon = trackicons::iconFor (track.icon); icon != trackicons::Icon::none)
  1322. ui::drawTrackIcon (g, icon, iconArea (t).toFloat(), track.muted ? colour::textDisabled : colour::textPrimary.withAlpha (0.88f));
  1323. if (! track.effects.empty() && sp.fxBadge)
  1324. {
  1325. const auto on = mixerops::anyEffectEnabled (song, t);
  1326. g.setColour (on ? colour::info : colour::textDisabled);
  1327. g.setFont (font (9.0f, true));
  1328. if (plateWidth >= 56)
  1329. textcache::drawText (g, "FX" + juce::String ((int) track.effects.size()), x + plateWidth - 26, 4, 23, 13, juce::Justification::centredRight);
  1330. else // narrow strips: a dot at the number's right
  1331. g.fillEllipse ((float) (x + plateWidth) - 7.0f, 8.0f, 4.0f, 4.0f);
  1332. }
  1333. }
  1334. if (needs (nameArea (t).withX (x).withWidth (plateWidth)))
  1335. {
  1336. g.setColour (track.muted ? colour::textDisabled : (hovered (Part::header) ? colour::textPrimary : colour::textPrimary.withAlpha (0.9f)));
  1337. g.setFont (font (compactLayout ? 10.0f : type::small, isSelected));
  1338. // Online Sessions (round 168a): a plugin of this insert is not installed here, its stand-in render plays (an
  1339. // amber R before the name)
  1340. const auto standIn = engine.insertPlaysStandIn (t);
  1341. // round 190ap: opened without third-party plugins, a plugin of this insert is still off (a grey power tag)
  1342. const auto pluginOff = ! standIn && engine.insertPluginOff (t);
  1343. const auto name = juce::String::fromUTF8 (track.name.c_str());
  1344. if (const auto box = nameArea (t); ! sp.verticalName)
  1345. {
  1346. textcache::drawFittedText (g, name, box.withTrimmedLeft (standIn || pluginOff ? 16 : 0), juce::Justification::centred, 1, 0.7f);
  1347. if (standIn)
  1348. drawStandInTag (g, { (float) box.getX() + 1.0f, (float) box.getY() + 0.5f, 13.0f, 13.0f });
  1349. else if (pluginOff)
  1350. ui::drawPluginOffTag (g, { (float) box.getX() + 1.0f, (float) box.getY() + 0.5f, 13.0f, 13.0f });
  1351. }
  1352. else
  1353. {
  1354. // the name reads bottom to top, as FL's narrow strips do
  1355. auto column = box.reduced (2, 4);
  1356. if (standIn)
  1357. {
  1358. drawStandInTag (g, juce::Rectangle<float> (13.0f, 13.0f).withCentre ({ (float) column.getCentreX(), (float) column.getBottom() - 6.5f }));
  1359. column.removeFromBottom (16);
  1360. }
  1361. else if (pluginOff)
  1362. {
  1363. ui::drawPluginOffTag (g, juce::Rectangle<float> (13.0f, 13.0f).withCentre ({ (float) column.getCentreX(), (float) column.getBottom() - 6.5f }));
  1364. column.removeFromBottom (16);
  1365. }
  1366. juce::Graphics::ScopedSaveState state (g);
  1367. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
  1368. const auto rotated = juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre());
  1369. textcache::drawFittedText (g, name, rotated, juce::Justification::centredLeft, 1, 0.8f); // (laid out once: round 173f)
  1370. }
  1371. // FL's narrow strips show the level beside the name too: two thin bars (Wide layouts)
  1372. if (const auto bars = nameBars (t); ! bars.isEmpty())
  1373. {
  1374. theme::fillRoundRect (g, bars.toFloat(), 2.0f, colour::bg0.withAlpha (0.8f));
  1375. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  1376. paintNameBars (g, t);
  1377. }
  1378. }
  1379. // compensated latency (PDC) on the Master
  1380. if (t == 0 && engine.getLatencySamples() > 0 && ! compactLayout && needs (soloArea (t).withX (x).withWidth (w)))
  1381. {
  1382. const auto ms = 1000.0 * engine.getLatencySamples() / juce::jmax (1.0, engine.getTransport().sampleRate.load());
  1383. g.setColour (colour::textSecondary);
  1384. g.setFont (font (10.0f));
  1385. textcache::drawFittedText (g, "PDC " + juce::String (ms, 1) + " ms", soloArea (t).withX (x + 30).withWidth (w - 36),
  1386. juce::Justification::centredLeft, 1, 0.8f); // the Master has no solo: use its spot
  1387. }
  1388. // pan and stereo separation
  1389. const auto knob = (float) sp.knobSize;
  1390. const auto stereoKnob = sp.stackedKnobs ? knob - 6.0f : 22.0f;
  1391. if (needs (panArea (t).getUnion (stereoArea (t))))
  1392. {
  1393. drawKnob (g, panArea (t).toFloat().withSizeKeepingCentre (knob, knob),
  1394. engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerPan, t }, (track.pan + 1.0f) * 0.5f), true,
  1395. dragging (Part::pan) ? colour::accent : colour::info, hovered (Part::pan) || dragging (Part::pan));
  1396. if (sp.stereoKnob)
  1397. drawKnob (g, stereoArea (t).toFloat().withSizeKeepingCentre (stereoKnob, stereoKnob), (track.stereo + 1.0f) * 0.5f, true,
  1398. dragging (Part::stereo) ? colour::accent : colour::knobArc, hovered (Part::stereo) || dragging (Part::stereo));
  1399. }
  1400. // mute and solo
  1401. if (needs (muteArea (t).getUnion (soloArea (t))))
  1402. {
  1403. const auto led = compactLayout ? 10.0f : 12.0f;
  1404. const auto m = muteArea (t).toFloat().withSizeKeepingCentre (led, led);
  1405. g.setColour (muteLed (track.muted));
  1406. g.fillEllipse (m);
  1407. if (! track.muted || hovered (Part::mute))
  1408. {
  1409. g.setColour (hovered (Part::mute) ? colour::textSecondary : colour::ledOn.withAlpha (0.25f));
  1410. g.drawEllipse (m.expanded (2.0f), 1.0f);
  1411. }
  1412. if (t > 0)
  1413. {
  1414. const auto s = soloArea (t).toFloat().reduced (2.0f);
  1415. theme::fillRoundRect (g, s, radius::sm, track.solo ? colour::accent : hovered (Part::solo) ? colour::bg5 : colour::bg0);
  1416. g.setColour (track.solo ? colour::onAccent : hovered (Part::solo) ? colour::textPrimary : colour::textSecondary);
  1417. g.setFont (font (type::caption, true));
  1418. textcache::drawText (g, "S", s.toNearestInt(), juce::Justification::centred);
  1419. }
  1420. }
  1421. // meters + fader
  1422. {
  1423. const auto area = faderArea (t);
  1424. const auto meters = meterArea (t);
  1425. const auto fader = faderRail (t);
  1426. for (int ch = 0; ch < 2; ++ch)
  1427. {
  1428. const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
  1429. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  1430. if (! cachePainting) // (cached: the levels are drawn over the picture, paintMeterLevels)
  1431. paintMeterLevel (g, t, ch, bar);
  1432. }
  1433. if (hovered (Part::meter))
  1434. {
  1435. g.setColour (colour::textSecondary.withAlpha (0.5f));
  1436. g.drawRect (meters.expanded (1), 1);
  1437. }
  1438. // round 177d: gain reduction of the strip's own dynamics, hanging down from the top (deeper = more)
  1439. if (const auto gr = gainReduction (t); gr >= 0.0f)
  1440. {
  1441. const auto bar = grArea (t);
  1442. g.setColour (colour::bg0.withAlpha (0.6f));
  1443. g.fillRect (bar);
  1444. g.setColour (colour::meterMid);
  1445. g.fillRect (bar.withHeight (juce::roundToInt (gr * (float) bar.getHeight())));
  1446. }
  1447. // the master's dB scale (FL prints it beside the master meter): as many values as fit without overlapping
  1448. if (t == 0)
  1449. {
  1450. const auto scaleFont = font (9.0f);
  1451. const auto textHeight = 10.0f;
  1452. const auto left = (float) meters.getRight() + 1.0f;
  1453. g.setFont (scaleFont);
  1454. for (auto db : lynx::meters::scaleMarks ((float) meters.getHeight(), textHeight + 1.0f))
  1455. {
  1456. const auto y = (float) meters.getBottom() - lynx::meters::scalePosition ((float) db) * (float) meters.getHeight();
  1457. g.setColour (db == 0 ? colour::textPrimary : colour::textSecondary);
  1458. g.fillRect (juce::Rectangle<float> (left, y - 0.5f, 2.0f, 1.0f));
  1459. const auto box = juce::Rectangle<float> (left + 2.0f, y - textHeight * 0.5f, (float) masterScaleWidth - 2.0f, textHeight)
  1460. .withY (juce::jlimit ((float) meters.getY(), (float) meters.getBottom() - textHeight, y - textHeight * 0.5f));
  1461. textcache::drawText (g, (db > 0 ? "+" : "") + juce::String (db), box, juce::Justification::centredRight, false);
  1462. }
  1463. }
  1464. // fader track and 0 dB mark
  1465. const auto railX = (float) fader.getCentreX();
  1466. const auto volume = shownVolume (t); // (its automation's value while it plays: the fader moves, issue #12)
  1467. const auto capY = (float) fader.getBottom() - volume * (float) fader.getHeight();
  1468. theme::fillRoundRect (g, { railX - 2.0f, (float) fader.getY(), 4.0f, (float) fader.getHeight() }, 2.0f, colour::bg0);
  1469. 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));
  1470. const auto unityY = (float) fader.getBottom() - unityFader * (float) fader.getHeight();
  1471. g.setColour (colour::textDisabled);
  1472. g.drawHorizontalLine ((int) unityY, (float) fader.getX(), railX - 5.0f);
  1473. g.drawHorizontalLine ((int) unityY, railX + 5.0f, (float) fader.getRight());
  1474. const auto capActive = hovered (Part::fader) || dragging (Part::fader);
  1475. const auto capWidth = juce::jmin ((float) fader.getWidth() + 2.0f, 26.0f);
  1476. const auto cap = juce::Rectangle<float> (capWidth, 12.0f).withCentre ({ railX, capY });
  1477. theme::fillRoundRect (g, cap.translated (0.0f, 1.5f), radius::sm, juce::Colours::black.withAlpha (0.35f));
  1478. // same cap as the LookAndFeel's linear faders
  1479. theme::fillRoundRect (g, cap, radius::sm, capActive ? juce::Colour (0xffffffff) : juce::Colour (0xffd4d7dd));
  1480. g.setColour ((dragging (Part::fader) ? colour::accent : colour::bg0).withAlpha (0.8f));
  1481. g.fillRect (cap.withSizeKeepingCentre (capWidth - 8.0f, 1.5f));
  1482. // a VCA member (round 177a): a tick where the level that plays sits (the fader times its VCAs)
  1483. if (t > 0 && ! song.vcas.empty())
  1484. if (const auto gain = mixerops::vcaGain (song, t); gain != 1.0f)
  1485. {
  1486. const auto playing = faderPosition (faderGain (volume) * gain);
  1487. const auto tickY = (float) fader.getBottom() - playing * (float) fader.getHeight();
  1488. g.setColour (colour::info);
  1489. g.fillRect (juce::Rectangle<float> (railX - 7.0f, tickY - 1.0f, 14.0f, 2.0f));
  1490. }
  1491. g.setColour (colour::textSecondary);
  1492. g.setFont (font (type::caption));
  1493. if (sp.dbReadout)
  1494. textcache::drawFittedText (g, faderToDb (volume) + " dB", juce::Rectangle<int> (x, area.getBottom() + 3, plateWidth, 14), juce::Justification::centred, 1, 0.7f);
  1495. // a hardware output target (REA round 156, optional): a small badge at the fader's top right
  1496. if (mixeroutput::isCustom (engine, t))
  1497. {
  1498. const auto text = mixeroutput::label (engine, t, true);
  1499. const auto badgeLeft = (float) meterArea (t).getRight() + 3.0f + (t == 0 ? (float) masterScaleWidth : 0.0f);
  1500. const auto badge = juce::Rectangle<float> (badgeLeft, (float) area.getY(), (float) (x + w - 6) - badgeLeft, 12.0f);
  1501. theme::fillRoundRect (g, badge, 3.0f, colour::bg0.withAlpha (0.85f));
  1502. g.setColour (text.endsWith ("?") ? colour::textDisabled : colour::info);
  1503. g.setFont (font (9.0f, true));
  1504. textcache::drawFittedText (g, text, badge.toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1505. }
  1506. }
  1507. // round 186c's option: the selected insert's sends to deleted inserts, as a greyed dashed chip in its own (empty)
  1508. // route-switch place: the deleted insert's name (or how many); the insert menu's "Disconnected links" acts on them
  1509. if (t == selected && t > 0 && ! song.mixer[(std::size_t) t].lostSends.empty() && needs (routeArea (t)))
  1510. {
  1511. const auto& lost = song.mixer[(std::size_t) t].lostSends;
  1512. const auto r = routeArea (t).toFloat().reduced (0.5f);
  1513. juce::Path outline, dashed;
  1514. outline.addRoundedRectangle (r, radius::sm);
  1515. const float dashes[] = { 2.5f, 2.0f };
  1516. juce::PathStrokeType (1.0f).createDashedStroke (dashed, outline, dashes, 2);
  1517. g.setColour (colour::textDisabled);
  1518. g.fillPath (dashed);
  1519. g.setFont (font (10.0f));
  1520. textcache::drawFittedText (g, juce::String::fromUTF8 ("\xc3\x97 ") + (lost.size() == 1 ? juce::String::fromUTF8 (lost[0].to.c_str()) : juce::String ((int) lost.size())),
  1521. r.toNearestInt().reduced (2, 0), juce::Justification::centred, 1, 0.6f);
  1522. }
  1523. // routing lane: send switch from the selected insert to this one, and its level knob
  1524. if (selected > 0 && t != selected && selected < tracks && needs (routeArea (t).getUnion (sendArea (t))))
  1525. {
  1526. const auto r = routeArea (t).toFloat();
  1527. const auto on = song.routes (selected, t);
  1528. const auto possible = on || song.canRoute (selected, t);
  1529. const auto feedsSelected = t > 0 && song.routes (t, selected);
  1530. if (possible)
  1531. {
  1532. theme::fillRoundRect (g, r, radius::sm, on ? colour::accent : hovered (Part::route) ? colour::bg5 : colour::bg0);
  1533. if (hovered (Part::route))
  1534. {
  1535. g.setColour (on ? colour::accentHover : colour::textSecondary);
  1536. g.drawRoundedRectangle (r.reduced (0.5f), radius::sm, 1.0f);
  1537. }
  1538. g.setColour (on ? colour::onAccent : colour::textSecondary);
  1539. g.setFont (font (10.0f, on));
  1540. textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + (t == 0 ? juce::String ("M") : juce::String (t)), r.toNearestInt(),
  1541. juce::Justification::centred);
  1542. // the route's level knob (FL's route knob), on the routes to inserts and to Master
  1543. if (on)
  1544. drawKnob (g, sendArea (t).toFloat().withSizeKeepingCentre (compactLayout ? 16.0f : 22.0f, compactLayout ? 16.0f : 22.0f),
  1545. engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerSend, selected, t },
  1546. faderPosition (song.routeLevel (selected, t))),
  1547. false,
  1548. dragging (Part::send) ? colour::accent : colour::accentHover, hovered (Part::send) || dragging (Part::send));
  1549. // a pre-fader send (LYNX's switch, round 190aq) is marked beside its knob
  1550. if (on && t > 0 && song.sendPre (selected, t))
  1551. {
  1552. // (its whole text, ending at the knob's left edge: the strip's margin is narrower than "PRE")
  1553. const auto area = sendArea (t);
  1554. const auto mark = compactLayout ? juce::String ("P") : tr ("PRE");
  1555. g.setColour (colour::accentHover);
  1556. g.setFont (font (8.0f, true));
  1557. const auto width = juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), mark) + 2;
  1558. const auto knobLeft = area.getCentreX() - (compactLayout ? 8 : 11);
  1559. textcache::drawText (g, mark, juce::Rectangle<int> (knobLeft - width - 1, area.getY(), width, area.getHeight()),
  1560. juce::Justification::centredRight, false);
  1561. }
  1562. }
  1563. else if (feedsSelected) // this insert sends into the selected one
  1564. {
  1565. theme::fillRoundRect (g, r, radius::sm, colour::info.withAlpha (0.18f));
  1566. g.setColour (colour::info);
  1567. g.setFont (font (10.0f, true));
  1568. textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + juce::String (selected), r.toNearestInt(), juce::Justification::centred);
  1569. }
  1570. }
  1571. }
  1572. if (pass == dockOf (0))
  1573. {
  1574. for (int i = 0; i < (int) vcaXs.size(); ++i)
  1575. paintVcaStrip (g, i);
  1576. if (showLoudness && g.clipRegionIntersects (loudnessArea().expanded (3)))
  1577. {
  1578. paintLoudnessPanel (g);
  1579. if (! cachePainting) // (cached: drawn over the picture, paintMeterLevels)
  1580. paintLoudnessValues (g);
  1581. }
  1582. }
  1583. paintDividers (pass);
  1584. }
  1585. paintRouting (g);
  1586. }
  1587. // Wires in the lane under the strips: from the selected insert to where it sends (accent), and from the
  1588. // inserts that feed it (blue). The Master output is drawn dimmer.
  1589. void MixerStrips::paintRouting (juce::Graphics& g)
  1590. {
  1591. using namespace theme;
  1592. const auto& song = engine.getSong();
  1593. const auto tracks = (int) song.mixer.size();
  1594. if (selected <= 0 || selected >= tracks)
  1595. return;
  1596. const auto top = (float) (laneTop() + switchHeight + sendKnobHeight + 3);
  1597. const auto bottom = top + (float) wiresHeight - 2.0f;
  1598. const auto centre = [this] (int t) { return (float) stripX (t) + (float) (stripWidthOf (t) - 4) * 0.5f; };
  1599. auto wire = [&] (int from, int to, juce::Colour c, float thickness) {
  1600. const auto x0 = centre (from), x1 = centre (to);
  1601. juce::Path p;
  1602. p.startNewSubPath (x0, top);
  1603. p.cubicTo (x0, bottom + 2.0f, x1, bottom + 2.0f, x1, top);
  1604. g.setColour (c);
  1605. g.strokePath (p, juce::PathStrokeType (thickness, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1606. g.fillEllipse (x1 - 2.5f, top - 2.5f, 5.0f, 5.0f);
  1607. };
  1608. const auto& from = song.mixer[(std::size_t) selected];
  1609. for (int t = 1; t < tracks; ++t)
  1610. if (t != selected && song.routes (t, selected))
  1611. wire (t, selected, colour::info.withAlpha (0.85f), 1.5f);
  1612. if (from.toMaster)
  1613. wire (selected, 0, colour::accent.withAlpha (0.4f), 1.0f);
  1614. for (const auto& send : from.sends)
  1615. if (send.target > 0 && send.target < tracks)
  1616. wire (selected, send.target, colour::accent.withAlpha (0.5f + 0.5f * juce::jlimit (0.0f, 1.0f, send.level)), 1.8f);
  1617. g.setColour (colour::accent);
  1618. g.fillEllipse (centre (selected) - 3.0f, top - 3.0f, 6.0f, 6.0f);
  1619. }
  1620. void MixerStrips::mouseDown (const juce::MouseEvent& e)
  1621. {
  1622. if (const auto i = vcaAt (e.x); i >= 0)
  1623. {
  1624. vcaMouseDown (e, i);
  1625. return;
  1626. }
  1627. if (showLoudness && loudnessArea().contains (e.getPosition())) // round 190am: Reset, or the panel's menu
  1628. {
  1629. if (flmods::popup (e.mods))
  1630. showLoudnessMenu();
  1631. else if (loudnessResetArea().contains (e.getPosition()))
  1632. resetLoudness();
  1633. return;
  1634. }
  1635. const auto t = trackAt (e.x);
  1636. if (t < 0)
  1637. return;
  1638. const auto part = partAt (t, e.getPosition());
  1639. headerDragTrack = -1;
  1640. headerDragged = false;
  1641. if (part == Part::add && flmods::popup (e.mods))
  1642. {
  1643. // FL's "+" menu (round 166d [SHOT]): Add one / Add multiple...
  1644. juce::PopupMenu menu;
  1645. const auto count = (int) engine.getSong().mixer.size();
  1646. const auto room = mixerops::roomForInserts (engine.getSong()) > 0;
  1647. menu.addItem (tr ("Add one"), room, false, [this, count] {
  1648. engine.editSong ([count] (Song& s) { mixerops::insertTracks (s, juce::jmax (1, count), 1); });
  1649. revealed.insert (juce::jmax (1, count));
  1650. updateSize();
  1651. selectTrack (juce::jmax (1, count));
  1652. });
  1653. menu.addItem (tr ("Add multiple..."), room, false, [this, count] { askInsertMultiple (juce::jmax (1, count)); });
  1654. // FL's "Add from state" (REA round 167q: AddMixerTracksMenu, FUN_012a87d0 / FUN_012a83b0)
  1655. juce::PopupMenu fromState;
  1656. for (const auto& f : mixerpresets::all())
  1657. fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, count, f] {
  1658. if (const auto added = mixerpresets::insertTrack (engine, juce::jmax (1, count), f); added > 0)
  1659. {
  1660. revealed.insert (added);
  1661. updateSize();
  1662. selectTrack (added);
  1663. }
  1664. });
  1665. menu.addSubMenu (tr ("Add from state"), fromState, room && fromState.getNumItems() > 0);
  1666. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  1667. return;
  1668. }
  1669. if (part == Part::add)
  1670. {
  1671. if (showUsedOnly) // the first unused insert (hidden) comes back before a new one is added
  1672. if (const auto free = engine.getSong().nextFreeInsert(); free > 0 && isHidden (free))
  1673. {
  1674. revealed.insert (free);
  1675. updateSize();
  1676. selectTrack (free);
  1677. return;
  1678. }
  1679. const auto added = (int) engine.getSong().mixer.size();
  1680. engine.editSong ([] (Song& s) {
  1681. if (s.mixer.empty())
  1682. s.mixer = Song::defaultMixer (0);
  1683. if ((int) s.mixer.size() >= maxMixerTracks)
  1684. return;
  1685. auto& track = s.mixer.emplace_back();
  1686. track.name = "Insert " + std::to_string (s.mixer.size() - 1);
  1687. });
  1688. if (added < (int) engine.getSong().mixer.size())
  1689. {
  1690. revealed.insert (added); // shown even while unused
  1691. updateSize();
  1692. selectTrack (added);
  1693. }
  1694. return;
  1695. }
  1696. if ((part == Part::fold || part == Part::tab) && ! flmods::popup (e.mods))
  1697. {
  1698. // round 177a: fold / unfold the group; Alt: every group (to the state this one takes)
  1699. const auto all = e.mods.isAltDown();
  1700. engine.editSong ([t, all] (Song& s) {
  1701. const auto folded = mixerops::toggleFold (s, t);
  1702. if (all)
  1703. mixerops::foldAll (s, folded);
  1704. });
  1705. updateSize();
  1706. repaint();
  1707. return;
  1708. }
  1709. if (part == Part::arm)
  1710. {
  1711. if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a); the input box keeps the input menu
  1712. mixerinput::chooseRecordTo (engine, t);
  1713. else
  1714. mixerinput::toggleArm (engine, t, this);
  1715. repaint();
  1716. return;
  1717. }
  1718. if (part == Part::input)
  1719. {
  1720. mixerinput::showMenu (engine, t, this);
  1721. return;
  1722. }
  1723. if (part == Part::meter && ! flmods::popup (e.mods)) // clears the clip latch and the peak hold, and selects (as FL)
  1724. {
  1725. for (int ch = 0; ch < 2; ++ch)
  1726. if (const auto i = (std::size_t) t * 2 + (std::size_t) ch; i < levels.size())
  1727. levels[i].resetClip();
  1728. repaint (meterArea (t).expanded (2));
  1729. }
  1730. if (part == Part::route && flmods::popup (e.mods))
  1731. {
  1732. showSendMenu (t);
  1733. return;
  1734. }
  1735. if (part == Part::send)
  1736. {
  1737. const auto from = selected;
  1738. if (flmods::popup (e.mods))
  1739. {
  1740. juce::PopupMenu menu;
  1741. const auto spec = specFor (Part::send, t);
  1742. menu.addSectionHeader (spec.name + ": " + spec.text (valueOf (Part::send, t)));
  1743. ui::addValueItems (menu, *this, &engine, spec, valueOf (Part::send, t), [this, t] (double v) { setValue (Part::send, t, v); });
  1744. menu.addSeparator();
  1745. addPreFaderItem (menu, from, t);
  1746. menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
  1747. [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
  1748. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  1749. return;
  1750. }
  1751. if (ui::isResetClick (e))
  1752. {
  1753. setValue (Part::send, t, unityFader); // 0 dB
  1754. showTip (Part::send, t, true);
  1755. return;
  1756. }
  1757. dragPart = Part::send;
  1758. dragTrack = t;
  1759. drag.begin (e, valueOf (Part::send, t));
  1760. showTip (Part::send, t, false);
  1761. return;
  1762. }
  1763. if (part == Part::mute && (flmods::popup (e.mods) || flmods::ctrl (e.mods))) // solo on the same LED
  1764. {
  1765. soloExclusive (t);
  1766. return;
  1767. }
  1768. if (part == Part::route)
  1769. {
  1770. // the selection is the send source: don't change it. FL (round 170b, REA FUN_012aa110): the arrow acts on every
  1771. // selected track; Ctrl = route to this track only, Shift = sidechain, Ctrl+Shift = sidechain only.
  1772. const auto from = selected;
  1773. const auto sources = selection;
  1774. using K = mixerops::RouteKind;
  1775. if (flmods::ctrl (e.mods) || e.mods.isShiftDown())
  1776. {
  1777. routeSelection (t, flmods::ctrl (e.mods) ? (e.mods.isShiftDown() ? K::sidechainOnly : K::routeOnly) : K::sidechain);
  1778. return;
  1779. }
  1780. const auto on = engine.getSong().routes (from, t);
  1781. engine.editSong ([sources, t, on] (Song& s) { mixerops::switchSelectedRoute (s, sources, t, ! on); });
  1782. if (! on && engine.getSong().routes (from, t)) // just enabled (at 0 dB): dragging adjusts the level, like the route knob
  1783. {
  1784. dragPart = Part::send;
  1785. dragTrack = t;
  1786. drag.begin (e, unityFader);
  1787. }
  1788. return;
  1789. }
  1790. if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && flmods::ctrl (e.mods) && t > 0)
  1791. {
  1792. // FL (round 170b, REA FUN_012c5800 / FUN_012c5f60): Ctrl+click (and drag across the strips) selects the tracks
  1793. // from here to the mouse, alone; Ctrl+Shift adds them to the selection, or removes them when the click starts
  1794. // on a selected track
  1795. selectAnchor = t;
  1796. selectAdding = ! e.mods.isShiftDown() || ! std::binary_search (selection.begin(), selection.end(), t);
  1797. selectBase.clear();
  1798. if (e.mods.isShiftDown())
  1799. selectBase = selection;
  1800. dragSelectTo (t);
  1801. return;
  1802. }
  1803. if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && e.mods.isShiftDown() && t > 0)
  1804. {
  1805. auto s = selection;
  1806. {
  1807. s.clear();
  1808. for (int i = juce::jmin (selected, t); i <= juce::jmax (selected, t); ++i)
  1809. s.push_back (i);
  1810. }
  1811. setSelection (s, std::find (s.begin(), s.end(), t) != s.end() ? t : s.front());
  1812. return;
  1813. }
  1814. // a plain click on a track outside the selection selects only it; inside, the group stays
  1815. if (! std::binary_search (selection.begin(), selection.end(), t))
  1816. setSelection ({ t }, t);
  1817. else if (selected != t)
  1818. setSelection (selection, t);
  1819. if (part == Part::pan || part == Part::fader || part == Part::stereo)
  1820. {
  1821. if (flmods::popup (e.mods))
  1822. {
  1823. ui::showValueMenu (*this, part == Part::stereo ? nullptr : &engine, specFor (part, t), valueOf (part, t),
  1824. [this, part, t] (double v) { setValue (part, t, v); });
  1825. return;
  1826. }
  1827. if (ui::isResetClick (e))
  1828. {
  1829. setValue (part, t, specFor (part, t).defaultValue);
  1830. showTip (part, t, true);
  1831. return;
  1832. }
  1833. }
  1834. if (flmods::popup (e.mods))
  1835. {
  1836. showMenu (t);
  1837. return;
  1838. }
  1839. const auto& track = engine.getSong().mixer[(std::size_t) t];
  1840. switch (part)
  1841. {
  1842. case Part::mute:
  1843. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].muted = ! s.mixer[(std::size_t) t].muted; });
  1844. return;
  1845. case Part::solo:
  1846. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].solo = ! s.mixer[(std::size_t) t].solo; });
  1847. return;
  1848. case Part::header:
  1849. if (t > 0)
  1850. headerDragTrack = t; // dragging sideways reorders
  1851. return;
  1852. case Part::stereo:
  1853. dragPart = part;
  1854. dragTrack = t;
  1855. dragStartValue = track.stereo;
  1856. drag.begin (e, dragStartValue);
  1857. groupStart.clear();
  1858. showTip (part, t, false);
  1859. return;
  1860. case Part::pan:
  1861. case Part::fader:
  1862. dragPart = part;
  1863. dragTrack = t;
  1864. dragStartValue = part == Part::pan ? track.pan : track.volume;
  1865. groupStart.clear();
  1866. groupGrab = dragStartValue;
  1867. if (selection.size() > 1) // the selected strips follow, keeping their offsets
  1868. for (auto s : selection)
  1869. if (s != t && s < (int) engine.getSong().mixer.size())
  1870. groupStart.push_back ({ s, part == Part::pan ? engine.getSong().mixer[(std::size_t) s].pan
  1871. : engine.getSong().mixer[(std::size_t) s].volume });
  1872. if (part == Part::fader && ! flmods::ctrl (e.mods)) // a press on the rail steps the fader towards the mouse
  1873. {
  1874. const auto area = faderRail (t);
  1875. const auto capY = area.getBottom() - track.volume * (float) area.getHeight();
  1876. if (std::abs ((float) e.y - capY) > 9.0f)
  1877. {
  1878. pressRail (t, e.y);
  1879. showTip (part, t, false);
  1880. return;
  1881. }
  1882. }
  1883. drag.begin (e, dragStartValue);
  1884. showTip (part, t, false);
  1885. return;
  1886. case Part::arm:
  1887. case Part::route:
  1888. case Part::send:
  1889. case Part::meter:
  1890. case Part::body:
  1891. case Part::none:
  1892. case Part::add:
  1893. return;
  1894. }
  1895. }
  1896. void MixerStrips::dragSelectTo (int t)
  1897. {
  1898. const auto count = (int) engine.getSong().mixer.size();
  1899. if (selectAnchor < 1 || count < 2)
  1900. return;
  1901. t = juce::jlimit (1, count - 1, t);
  1902. std::set<int> s (selectBase.begin(), selectBase.end());
  1903. for (int i = juce::jmin (selectAnchor, t); i <= juce::jmax (selectAnchor, t); ++i)
  1904. {
  1905. if (isHidden (i) && i != t && i != selectAnchor)
  1906. continue;
  1907. if (selectAdding)
  1908. s.insert (i);
  1909. else
  1910. s.erase (i);
  1911. }
  1912. if (s.empty())
  1913. s.insert (t);
  1914. // the track under the mouse becomes the current one (FL); when removing, a track that stays selected
  1915. auto primary = t;
  1916. if (! s.count (primary))
  1917. primary = s.count (selected) ? selected : *s.rbegin();
  1918. setSelection ({ s.begin(), s.end() }, primary);
  1919. }
  1920. void MixerStrips::pressRail (int strip, int mouseY)
  1921. {
  1922. railStrip = strip;
  1923. railMouseY = mouseY;
  1924. railPressMs = juce::Time::getMillisecondCounterHiRes();
  1925. stepRailOnce();
  1926. railSteps = 1;
  1927. railRepeat.startTimer (16); // (a poll: the steps themselves follow the time since the press)
  1928. }
  1929. float MixerStrips::railTarget (int strip) const
  1930. {
  1931. const auto rail = faderRail (strip);
  1932. return juce::jlimit (0.0f, 1.0f, (float) (rail.getBottom() - railMouseY) / (float) rail.getHeight());
  1933. }
  1934. void MixerStrips::stepHeldRail()
  1935. {
  1936. if (! railRepeat.isTimerRunning()) // (a direct call, as the offscreen check makes: one step)
  1937. {
  1938. stepRailOnce();
  1939. return;
  1940. }
  1941. // the repeat stops as soon as the button is up, even before the release reaches us
  1942. if (! juce::ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  1943. {
  1944. railRepeat.stopTimer();
  1945. return;
  1946. }
  1947. const auto due = faderRailStepsForHold ((int) (juce::Time::getMillisecondCounterHiRes() - railPressMs));
  1948. for (int guard = 0; railSteps < due && guard < 64; ++guard, ++railSteps)
  1949. stepRailOnce();
  1950. }
  1951. void MixerStrips::stepRailOnce()
  1952. {
  1953. const auto& song = engine.getSong();
  1954. if (railStrip <= vcaStrip (0))
  1955. {
  1956. const auto i = -2 - railStrip;
  1957. if (i < (int) song.vcas.size())
  1958. {
  1959. setVcaLevel (i, faderRailStepTowards (song.vcas[(std::size_t) i].level, railTarget (railStrip)));
  1960. ui::showValueTip (*this, faderRail (railStrip), vcaSpec (i).text (vcaShownLevel (i)));
  1961. }
  1962. }
  1963. else if (railStrip >= 0 && railStrip < (int) song.mixer.size())
  1964. {
  1965. setValue (Part::fader, railStrip, faderRailStepTowards (song.mixer[(std::size_t) railStrip].volume, railTarget (railStrip)));
  1966. showTip (Part::fader, railStrip, false);
  1967. }
  1968. }
  1969. void MixerStrips::mouseDrag (const juce::MouseEvent& e)
  1970. {
  1971. if (railStrip != railNone) // the cap goes on towards where the mouse is now
  1972. {
  1973. railMouseY = e.y;
  1974. return;
  1975. }
  1976. if (selectAnchor > 0)
  1977. {
  1978. if (const auto t = trackAt (juce::jlimit (0, getWidth() - 1, e.x)); t >= 0)
  1979. dragSelectTo (t);
  1980. return;
  1981. }
  1982. if (headerDragTrack > 0)
  1983. {
  1984. if (! headerDragged && std::abs (e.getDistanceFromDragStartX()) < 6)
  1985. return;
  1986. headerDragged = true;
  1987. setMouseCursor (juce::MouseCursor::LeftRightResizeCursor);
  1988. const auto count = (int) engine.getSong().mixer.size();
  1989. const auto target = trackAt (e.x);
  1990. if (target < 1 || target >= count)
  1991. return;
  1992. for (int guard = 0; guard < count && selected != target; ++guard)
  1993. if (! moveSelected (target < selected ? -1 : 1))
  1994. break;
  1995. headerDragTrack = selected;
  1996. repaint();
  1997. return;
  1998. }
  1999. if (dragVca >= 0)
  2000. {
  2001. setVcaLevel (dragVca, drag.update (e, vcaSpec (dragVca)));
  2002. ui::showValueTip (*this, faderRail (vcaStrip (dragVca)), vcaSpec (dragVca).text (vcaShownLevel (dragVca)));
  2003. return;
  2004. }
  2005. if (dragPart == Part::none)
  2006. return;
  2007. const auto t = dragTrack;
  2008. setValue (dragPart, t, drag.update (e, specFor (dragPart, t)));
  2009. showTip (dragPart, t, false);
  2010. }
  2011. ui::ValueSpec MixerStrips::specFor (Part part, int t) const
  2012. {
  2013. const auto& song = engine.getSong();
  2014. const auto nameOf = [&song] (int track) {
  2015. return track >= 0 && track < (int) song.mixer.size() ? juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) : juce::String();
  2016. };
  2017. const auto name = nameOf (t);
  2018. if (part == Part::pan)
  2019. {
  2020. auto spec = ui::panSpec (name + " - " + tr ("Pan"));
  2021. spec.pixelsForRange = 150.0;
  2022. spec.target = AutomationTarget { AutomationTargetKind::mixerPan, t };
  2023. return spec;
  2024. }
  2025. if (part == Part::stereo)
  2026. return stereoSpec (name + " - " + tr ("Stereo separation"));
  2027. if (part == Part::send)
  2028. {
  2029. auto spec = sendSpec (nameOf (selected) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + name + " - "
  2030. + (t == 0 ? tr ("Level to Master") : engine.getSong().sendPre (selected, t) ? tr ("Send level (pre-fader)") : tr ("Send level")));
  2031. spec.target = AutomationTarget { AutomationTargetKind::mixerSend, selected, t }; // automatable (issue #12)
  2032. return spec;
  2033. }
  2034. auto spec = ui::faderSpec (name + " - " + tr ("Volume"), unityFader);
  2035. spec.pixelsForRange = juce::jmax (60, faderRail (juce::jmax (0, t)).getHeight());
  2036. spec.target = AutomationTarget { AutomationTargetKind::mixerVolume, t };
  2037. return spec;
  2038. }
  2039. double MixerStrips::valueOf (Part part, int t) const
  2040. {
  2041. const auto& song = engine.getSong();
  2042. const auto& track = song.mixer[(std::size_t) t];
  2043. if (part == Part::send)
  2044. {
  2045. return faderPosition (song.routeLevel (selected, t));
  2046. }
  2047. return part == Part::pan ? track.pan : part == Part::stereo ? track.stereo : track.volume;
  2048. }
  2049. void MixerStrips::setValue (Part part, int t, double value)
  2050. {
  2051. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  2052. return;
  2053. if (part == Part::send)
  2054. {
  2055. const auto from = selected;
  2056. engine.editSong ([from, t, v = faderGain ((float) value)] (Song& s) { s.setRouteLevel (from, t, v); });
  2057. return;
  2058. }
  2059. if (part == Part::stereo)
  2060. {
  2061. engine.editLevels ([t, v = (float) value] (Song& s) { s.mixer[(std::size_t) t].stereo = v; });
  2062. return;
  2063. }
  2064. // during a drag of a selected strip, the other selected strips move by the same amount
  2065. const auto delta = (float) value - groupGrab;
  2066. const auto group = dragTrack == t && dragPart == part ? groupStart : std::vector<std::pair<int, float>> {};
  2067. if (part == Part::pan)
  2068. engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
  2069. s.mixer[(std::size_t) t].pan = v;
  2070. for (auto [other, start] : group)
  2071. if (other < (int) s.mixer.size())
  2072. s.mixer[(std::size_t) other].pan = juce::jlimit (-1.0f, 1.0f, start + delta);
  2073. });
  2074. else if (part == Part::fader)
  2075. engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
  2076. s.mixer[(std::size_t) t].volume = v;
  2077. for (auto [other, start] : group)
  2078. if (other < (int) s.mixer.size())
  2079. s.mixer[(std::size_t) other].volume = juce::jlimit (0.0f, 1.0f, start + delta);
  2080. });
  2081. }
  2082. void MixerStrips::setSelection (std::vector<int> tracks, int primary)
  2083. {
  2084. const auto count = (int) engine.getSong().mixer.size();
  2085. tracks.erase (std::remove_if (tracks.begin(), tracks.end(), [count] (int t) { return t < 0 || t >= count; }), tracks.end());
  2086. primary = juce::jlimit (0, juce::jmax (0, count - 1), primary);
  2087. tracks.push_back (primary);
  2088. std::sort (tracks.begin(), tracks.end());
  2089. tracks.erase (std::unique (tracks.begin(), tracks.end()), tracks.end());
  2090. selection = tracks;
  2091. const auto changed = primary != selected;
  2092. selected = primary;
  2093. keepSelectionShown();
  2094. repaint();
  2095. if (changed && onSelectionChanged)
  2096. onSelectionChanged (selected);
  2097. }
  2098. bool MixerStrips::moveSelected (int delta)
  2099. {
  2100. auto moved = selection;
  2101. bool ok = false;
  2102. engine.editSongStructural ([&] (Song& s) { ok = mixerops::moveTracks (s, moved, delta); });
  2103. if (ok)
  2104. setSelection (moved, juce::jlimit (1, (int) engine.getSong().mixer.size() - 1, selected + (delta < 0 ? -1 : 1)));
  2105. return ok;
  2106. }
  2107. // FL's "Delete" on the selected mixer tracks (round 186c; REA FUN_012a5b60, FL 2026 checked by hand): an error while
  2108. // audio is being recorded; "Delete tracks|This will |delete| %d selected mixer track(s). Are you sure?" (Yes / No and
  2109. // "Remember my choice": a remembered Yes skips it, No is never remembered; Settings › General › Manage messages shows
  2110. // it again); then, when a Playlist audio / instrument track is linked to one of them, "Playlist tracks" with "Delete
  2111. // tracks and channels" / "Unlink tracks and channels" / "Cancel" (nothing remembered). One undo step.
  2112. void MixerStrips::deleteTracks (std::vector<int> tracks)
  2113. {
  2114. const auto count = (int) engine.getSong().mixer.size();
  2115. tracks.erase (std::remove_if (tracks.begin(), tracks.end(), [count] (int t) { return t < 1 || t >= count; }), tracks.end());
  2116. if (tracks.empty())
  2117. return;
  2118. if (engine.isRecording() && ! engine.getArmedInserts().empty())
  2119. {
  2120. showFlMessage ({ tr ("Error"), tr ("It isn't possible to delete mixer tracks during audio recording."), { tr ("OK") }, false }, nullptr);
  2121. return;
  2122. }
  2123. juce::Component::SafePointer<MixerStrips> safe (this);
  2124. auto run = [safe, tracks] (mixerops::LinkedPlaylistTracks linked) {
  2125. if (safe == nullptr)
  2126. return;
  2127. safe->engine.editSongStructural ([&tracks, linked] (Song& s) { mixerops::deleteTracks (s, tracks, linked, MixerStrips::keepLostLinks); });
  2128. const auto first = juce::jlimit (0, (int) safe->engine.getSong().mixer.size() - 1, *std::min_element (tracks.begin(), tracks.end()));
  2129. safe->setSelection ({ first }, first);
  2130. };
  2131. auto confirmed = [safe, tracks, run] {
  2132. if (safe == nullptr)
  2133. return;
  2134. if (mixerops::playlistTracksLinkedTo (safe->engine.getSong(), tracks).empty())
  2135. {
  2136. run (mixerops::LinkedPlaylistTracks::unlink);
  2137. return;
  2138. }
  2139. showFlMessage ({ tr ("Playlist tracks"),
  2140. tr ("One or more mixer tracks that will be deleted are connected to instrument/audio tracks.") + "\n"
  2141. + tr ("Do you want to unlink the tracks and channels or delete them?"),
  2142. { tr ("Delete tracks and channels"), tr ("Unlink tracks and channels"), tr ("Cancel") }, false },
  2143. [run] (int button, bool) {
  2144. if (button == 1)
  2145. run (mixerops::LinkedPlaylistTracks::deleteToo);
  2146. else if (button == 2)
  2147. run (mixerops::LinkedPlaylistTracks::unlink);
  2148. });
  2149. };
  2150. if (! messages::shown ("DeleteMixerTrack"))
  2151. {
  2152. confirmed();
  2153. return;
  2154. }
  2155. // (FL marks "delete" in its accent colour: the |bars| of its own string)
  2156. showFlMessage ({ tr ("Delete tracks"), tr ("This will |delete| {0} selected mixer track(s). Are you sure?", { juce::String ((int) tracks.size()) }),
  2157. { tr ("Yes"), tr ("No") }, true },
  2158. [confirmed] (int button, bool remember) {
  2159. if (button != 1)
  2160. return;
  2161. if (remember)
  2162. messages::setShown ("DeleteMixerTrack", false);
  2163. confirmed();
  2164. });
  2165. }
  2166. void MixerStrips::linkSelectedChannels (bool startingHere)
  2167. {
  2168. const auto channels = engine.getSelectedChannels();
  2169. engine.editSong ([channels, t = selected, startingHere] (Song& s) { mixerops::linkChannels (s, channels, t, startingHere); });
  2170. }
  2171. void MixerStrips::selectLinkedChannels()
  2172. {
  2173. const auto channels = mixerops::channelsOn (engine.getSong(), selected);
  2174. if (! channels.empty())
  2175. engine.setChannelSelection (channels, channels.front());
  2176. }
  2177. void MixerStrips::soloExclusive (int t)
  2178. {
  2179. if (t <= 0)
  2180. return;
  2181. // solo only this track; again on the only soloed track clears the solo
  2182. engine.editSong ([t] (Song& s) {
  2183. const auto alone = s.mixer[(std::size_t) t].solo
  2184. && std::none_of (s.mixer.begin() + 1, s.mixer.end(), [&] (const MixerTrack& m) { return &m != &s.mixer[(std::size_t) t] && m.solo; });
  2185. for (std::size_t i = 1; i < s.mixer.size(); ++i)
  2186. s.mixer[i].solo = ! alone && (int) i == t;
  2187. });
  2188. }
  2189. void MixerStrips::routeSelection (int t, mixerops::RouteKind kind)
  2190. {
  2191. using K = mixerops::RouteKind;
  2192. int linked = 0;
  2193. engine.editSong ([sources = selection, t, kind, &linked] (Song& s) {
  2194. mixerops::routeSelectedTo (s, sources, t, kind);
  2195. if (t >= 0 && t < (int) s.mixer.size())
  2196. for (const auto& fx : s.mixer[(std::size_t) t].effects)
  2197. linked += std::find (sources.begin(), sources.end(), fx.sidechain) != sources.end() ? 1 : 0;
  2198. });
  2199. if ((kind == K::sidechain || kind == K::sidechainOnly) && t > 0 && linked == 0)
  2200. // (round 170h: in the hint bar, not a box — FL says nothing here; adding the compressor links it)
  2201. ui::postHint ({ tr ("Sidechain") + ": " + tr ("The link was made; add a compressor to this insert to use it."), {} }, 6000);
  2202. }
  2203. // LYNX's pre-fader switch of a send (round 190aq; FL's sends are post-fader, the default): a ticked item in the send
  2204. // knob's and the route arrow's menus. The route to Master has none.
  2205. void MixerStrips::addPreFaderItem (juce::PopupMenu& menu, int from, int t)
  2206. {
  2207. const auto& song = engine.getSong();
  2208. if (t <= 0 || from <= 0 || ! song.routes (from, t))
  2209. return;
  2210. const auto pre = song.sendPre (from, t);
  2211. menu.addItem (tr ("Pre-fader send (not moved by this track's fader)"), true, pre,
  2212. [this, from, t, pre] { engine.editSong ([from, t, pre] (Song& s) { s.setSendPre (from, t, ! pre); }); });
  2213. }
  2214. void MixerStrips::showSendMenu (int t)
  2215. {
  2216. if (selected <= 0 || selected == t)
  2217. return;
  2218. buildSendMenu (t).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  2219. }
  2220. juce::PopupMenu MixerStrips::buildSendMenu (int t)
  2221. {
  2222. const auto& song = engine.getSong();
  2223. const auto from = selected;
  2224. const auto fromName = juce::String::fromUTF8 (song.mixer[(std::size_t) from].name.c_str());
  2225. juce::PopupMenu menu;
  2226. const auto sources = (int) std::count_if (selection.begin(), selection.end(), [t] (int x) { return x > 0 && x != t; });
  2227. menu.addSectionHeader ((sources > 1 ? tr ("{0} selected tracks", { juce::String (sources) }) : fromName)
  2228. + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()));
  2229. // FL's route arrow menu (round 168s, issue #32 [SHOT] r168s c_f10): route / route only / sidechain / sidechain only
  2230. const auto on = song.routes (from, t);
  2231. const auto can = on || song.canRoute (from, t);
  2232. using K = mixerops::RouteKind;
  2233. // FL (round 170b, REA FUN_012aca70): every item acts on all the selected tracks, not only the current one
  2234. auto route = [this, t] (K kind) { routeSelection (t, kind); };
  2235. menu.addItem (tr ("Route to this track"), can && ! on, false, [route] { route (K::route); });
  2236. menu.addItem (tr ("Route to this track only"), can, false, [route] { route (K::routeOnly); });
  2237. menu.addSeparator();
  2238. menu.addItem (tr ("Sidechain to this track"), t > 0 && can, false, [route] { route (K::sidechain); });
  2239. menu.addItem (tr ("Sidechain to this track only"), t > 0 && can, false, [route] { route (K::sidechainOnly); });
  2240. if (on)
  2241. {
  2242. menu.addSeparator();
  2243. addPreFaderItem (menu, from, t);
  2244. menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
  2245. [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
  2246. }
  2247. return menu;
  2248. }
  2249. void MixerStrips::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
  2250. {
  2251. if (const auto i = vcaAt (e.x); i >= 0 && ! ui::wheelScrolling() && vcaPartAt (i, e.getPosition()) == Part::fader)
  2252. {
  2253. if (const auto v = ui::wheelValue (engine.getSong().vcas[(std::size_t) i].level, e, wheel, vcaSpec (i)))
  2254. {
  2255. setVcaLevel (i, *v);
  2256. ui::flashValueTip (*this, faderRail (vcaStrip (i)), vcaSpec (i).text (*v));
  2257. }
  2258. return;
  2259. }
  2260. const auto t = trackAt (e.x);
  2261. if (t > 0 && t < (int) engine.getSong().mixer.size() && e.mods.isShiftDown())
  2262. if (const auto part = partAt (t, e.getPosition()); part == Part::body || part == Part::header)
  2263. {
  2264. if (! std::binary_search (selection.begin(), selection.end(), t))
  2265. setSelection ({ t }, t);
  2266. moveSelected ((wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX) > 0.0f ? -1 : 1);
  2267. return;
  2268. }
  2269. // (a spin that is scrolling the strips goes on scrolling over the faders and knobs, round 169c)
  2270. if (t >= 0 && t < (int) engine.getSong().mixer.size() && ! ui::wheelScrolling())
  2271. if (const auto part = partAt (t, e.getPosition()); part == Part::pan || part == Part::fader || part == Part::stereo || part == Part::send)
  2272. {
  2273. if (const auto v = ui::wheelValue (valueOf (part, t), e, wheel, specFor (part, t)))
  2274. {
  2275. setValue (part, t, *v);
  2276. showTip (part, t, true);
  2277. }
  2278. return;
  2279. }
  2280. ui::noteWheelScroll(); // the wheel scrolls the strips (the viewport)
  2281. juce::Component::mouseWheelMove (e, wheel);
  2282. }
  2283. ui::Hint MixerStrips::hintAt (juce::Point<int> p)
  2284. {
  2285. if (dragVca >= 0)
  2286. return vcaHint (dragVca, p);
  2287. if (const auto i = vcaAt (p.x); i >= 0 && dragPart == Part::none)
  2288. return vcaHint (i, p);
  2289. if (showLoudness && dragPart == Part::none && loudnessArea().contains (p))
  2290. {
  2291. ui::Hint h;
  2292. h.hasMenu = true;
  2293. if (loudnessResetArea().contains (p))
  2294. h.text = tr ("Start the loudness measurement again");
  2295. else
  2296. {
  2297. h.text = tr ("Loudness of the Master: S = short-term (3 s), I = integrated since the last reset (LUFS), TP = true peak (dBTP)");
  2298. h.value = "S " + juce::String (formatLoudness (loudnessShown.shortTerm)) + " I " + juce::String (formatLoudness (loudnessShown.integrated))
  2299. + " TP " + juce::String (formatLoudness (loudnessShown.truePeak));
  2300. }
  2301. return h;
  2302. }
  2303. const auto active = dragPart == Part::pan || dragPart == Part::fader || dragPart == Part::stereo || dragPart == Part::send;
  2304. const auto t = active ? dragTrack : trackAt (p.x);
  2305. const auto& song = engine.getSong();
  2306. ui::Hint h;
  2307. if (t < 0 || t >= (int) song.mixer.size())
  2308. {
  2309. if (t == (int) song.mixer.size())
  2310. h.text = tr ("Add a mixer insert");
  2311. return h;
  2312. }
  2313. const auto part = active ? dragPart : partAt (t, p);
  2314. const auto name = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  2315. const auto gesture = ui::valueGestures();
  2316. // the channels that play into this insert (FL shows them by the insert; LYNX in the hint)
  2317. auto feeds = [&song, t, tracks = (int) song.mixer.size()] {
  2318. juce::StringArray names;
  2319. for (const auto& c : song.channels)
  2320. if (juce::jlimit (0, tracks - 1, c.mixerTrack) == t)
  2321. names.add (juce::String::fromUTF8 (c.name.c_str()));
  2322. if (names.isEmpty())
  2323. return juce::String();
  2324. const auto shown = names.size() > 6 ? names[0] + ", " + names[1] + ", " + names[2] + " +" + juce::String (names.size() - 3)
  2325. : names.joinIntoString (", ");
  2326. return " " + tr ("Channels: {0}", { shown });
  2327. };
  2328. // FL's "Track latency compensation" label (REA round 165f-mixer): the manual latency and the bypass, when set
  2329. auto latency = [&song, t] {
  2330. const auto& track = song.mixer[(std::size_t) t];
  2331. juce::String text;
  2332. if (track.latencyMs != 0.0f)
  2333. text << " " << tr ("Track latency: {0}", { (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms" });
  2334. if (track.latencyBypass == LatencyBypass::always)
  2335. text << " " << tr ("Bypass track latency compensation") << ": " << tr ("Always");
  2336. else if (track.latencyBypass == LatencyBypass::whenRecordingOrStopped)
  2337. text << " " << tr ("Bypass track latency compensation") << ": " << tr ("When recording or not playing");
  2338. return text;
  2339. };
  2340. switch (part)
  2341. {
  2342. case Part::fader:
  2343. if (const auto note = vcaNote (t); note.isNotEmpty())
  2344. {
  2345. h = ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2346. h.text << " " << note;
  2347. return h;
  2348. }
  2349. return ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2350. case Part::pan:
  2351. case Part::stereo:
  2352. case Part::send:
  2353. return ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
  2354. case Part::mute: h.text = name + " - " + tr ("Click: mute. Right-click or Ctrl+click: solo"); break;
  2355. case Part::arm: h.text = name + " - " + mixerinput::armHint (engine, t); h.hasMenu = true; break;
  2356. case Part::input: h.text = name + " - " + tr ("Input level of this insert's audio input [LMB] choose the input"); h.hasMenu = true; break;
  2357. case Part::solo: h.text = name + " - " + tr ("Solo"); break;
  2358. case Part::meter: h.text = name + " - " + tr ("Peak meter (left/right) with peak hold [LMB] selects the track and clears the clip light"); break;
  2359. 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;
  2360. case Part::add: h.text = tr ("Add a mixer insert"); break;
  2361. case Part::fold:
  2362. h.text = name + " - " + (mixerops::isFolded (song, t) ? tr ("Unfold this group [Alt]+[LMB] all groups")
  2363. : tr ("Fold this group to its bus strip, or to a slim tab [Alt]+[LMB] all groups"));
  2364. break;
  2365. case Part::tab:
  2366. h.text = tr ("Folded group: {0} ({1} inserts) [LMB] unfold", { name, juce::String ((int) mixerops::groupOf (song, t).size()) });
  2367. break;
  2368. case Part::header:
  2369. h.text = name + " - " + tr ("[LMB] selects [Ctrl]+[LMB] or drag across: range [Ctrl]+[Shift]+[LMB] adds or removes [LMB] drag sideways reorders [RMB] insert menu") + feeds() + latency();
  2370. h.hasMenu = true;
  2371. if (engine.insertPlaysStandIn (t))
  2372. 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)");
  2373. else if (engine.insertPluginOff (t)) // round 190ap
  2374. 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...)");
  2375. break;
  2376. case Part::body:
  2377. case Part::none:
  2378. h.text = name + " - " + tr ("Click selects the insert (Ctrl+click or drag across: range, Ctrl+Shift: add or remove), right-click opens its menu; Alt+Left/Right moves the selection") + feeds() + latency();
  2379. h.hasMenu = true;
  2380. break;
  2381. }
  2382. return h;
  2383. }
  2384. void MixerStrips::mouseUp (const juce::MouseEvent&)
  2385. {
  2386. railRepeat.stopTimer();
  2387. railStrip = railNone;
  2388. if (headerDragged)
  2389. setMouseCursor (juce::MouseCursor::NormalCursor);
  2390. if (dragPart != Part::none || headerDragged || dragVca >= 0)
  2391. repaint();
  2392. dragVca = -1;
  2393. headerDragTrack = -1;
  2394. headerDragged = false;
  2395. selectAnchor = -1;
  2396. selectBase.clear();
  2397. dragPart = Part::none;
  2398. dragTrack = -1;
  2399. drag.end();
  2400. ui::hideValueTip();
  2401. ui::clearPostedHint();
  2402. }
  2403. void MixerStrips::mouseDoubleClick (const juce::MouseEvent& e)
  2404. {
  2405. if (const auto i = vcaAt (e.x); i >= 0)
  2406. {
  2407. if (vcaPartAt (i, e.getPosition()) == Part::fader)
  2408. setVcaLevel (i, unityFader);
  2409. return;
  2410. }
  2411. const auto t = trackAt (e.x);
  2412. if (t < 0 || t >= (int) engine.getSong().mixer.size())
  2413. return;
  2414. const auto part = partAt (t, e.getPosition());
  2415. if (part == Part::fader || part == Part::pan || part == Part::stereo || part == Part::send)
  2416. {
  2417. setValue (part, t, specFor (part, t).defaultValue);
  2418. showTip (part, t, true);
  2419. }
  2420. }
  2421. void MixerStrips::keepSelectionShown()
  2422. {
  2423. if (! showUsedOnly)
  2424. return;
  2425. const auto wasHidden = std::any_of (selection.begin(), selection.end(), [this] (int t) { return revealed.count (t) == 0 && isHidden (t); })
  2426. || (revealed.count (selected) == 0 && isHidden (selected));
  2427. if (wasHidden) // (selected from the Channel Rack, a menu or the keyboard: its strip comes back)
  2428. updateSize();
  2429. }
  2430. void MixerStrips::selectTrack (int track)
  2431. {
  2432. selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), track);
  2433. selection = { selected };
  2434. keepSelectionShown();
  2435. repaint();
  2436. if (onSelectionChanged)
  2437. onSelectionChanged (selected);
  2438. }
  2439. namespace
  2440. {
  2441. // The 3 knobs of each band of the track's built-in EQ (gain, frequency, width).
  2442. class TrackEqEditor final : public juce::Component
  2443. {
  2444. public:
  2445. TrackEqEditor (AudioEngine& e, int t)
  2446. : engine (e),
  2447. track (t)
  2448. {
  2449. const juce::String bands[] = { tr ("Low"), tr ("Mid"), tr ("High") };
  2450. const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
  2451. for (int b = 0; b < 3; ++b)
  2452. {
  2453. titles[(std::size_t) b].setText (bands[b], juce::dontSendNotification);
  2454. titles[(std::size_t) b].setJustificationType (juce::Justification::centred);
  2455. addAndMakeVisible (titles[(std::size_t) b]);
  2456. auto& gain = knobs[(std::size_t) b][0];
  2457. setup (gain, -18.0, 18.0, 0.1, " dB", eq.gainDb[(std::size_t) b]);
  2458. gain.setDoubleClickReturnValue (true, 0.0);
  2459. auto& hz = knobs[(std::size_t) b][1];
  2460. setup (hz, 10.0, 16000.0, 1.0, " Hz", eq.hz[(std::size_t) b]);
  2461. hz.setSkewFactorFromMidPoint (1000.0);
  2462. auto& width = knobs[(std::size_t) b][2];
  2463. setup (width, 0.0, 1.0, 0.01, "", eq.width[(std::size_t) b]);
  2464. width.setTooltip (b == 1 ? tr ("Peak width (Q)") : tr ("Shelf slope"));
  2465. }
  2466. setSize (3 * 90, 3 * 74 + 24);
  2467. }
  2468. void resized() override
  2469. {
  2470. auto area = getLocalBounds();
  2471. auto header = area.removeFromTop (20);
  2472. for (int b = 0; b < 3; ++b)
  2473. {
  2474. titles[(std::size_t) b].setBounds (header.removeFromLeft (90));
  2475. auto column = area.removeFromLeft (90);
  2476. for (auto& k : knobs[(std::size_t) b])
  2477. k.setBounds (column.removeFromTop (74));
  2478. }
  2479. }
  2480. private:
  2481. void setup (juce::Slider& s, double lo, double hi, double step, const char* suffix, float value)
  2482. {
  2483. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  2484. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 72, 16);
  2485. s.setRange (lo, hi, step);
  2486. s.setTextValueSuffix (suffix);
  2487. s.setValue (value, juce::dontSendNotification);
  2488. s.onValueChange = [this] { apply(); };
  2489. addAndMakeVisible (s);
  2490. }
  2491. void apply()
  2492. {
  2493. TrackEq eq;
  2494. for (std::size_t b = 0; b < 3; ++b)
  2495. {
  2496. eq.gainDb[b] = (float) knobs[b][0].getValue();
  2497. eq.hz[b] = (float) knobs[b][1].getValue();
  2498. eq.width[b] = (float) knobs[b][2].getValue();
  2499. }
  2500. engine.editSong ([t = track, eq] (Song& s) {
  2501. if (t < (int) s.mixer.size())
  2502. s.mixer[(std::size_t) t].eq = eq;
  2503. });
  2504. }
  2505. AudioEngine& engine;
  2506. int track;
  2507. std::array<juce::Label, 3> titles;
  2508. std::array<std::array<juce::Slider, 3>, 3> knobs; // [band][gain, frequency, width]
  2509. };
  2510. } // namespace
  2511. void MixerStrips::showTrackEq (int t)
  2512. {
  2513. auto editor = std::make_unique<TrackEqEditor> (engine, t);
  2514. juce::CallOutBox::launchAsynchronously (std::move (editor), getScreenBounds().withSize (10, 10).translated (getMouseXYRelative().x, getMouseXYRelative().y), nullptr);
  2515. }
  2516. namespace
  2517. {
  2518. juce::File mixerStatesFolder()
  2519. {
  2520. return lynx::platform::documentsFolder().getChildFile ("LYNX/Mixer states");
  2521. }
  2522. std::unique_ptr<juce::FileChooser>& mixerStateChooser()
  2523. {
  2524. static std::unique_ptr<juce::FileChooser> chooser;
  2525. return chooser;
  2526. }
  2527. // --- FL's track latency menu (REA round 165f-mixer: DelayMenu, FUN_012ae090 / FUN_012ad520 / FUN_012acd30) ---------
  2528. double sampleRateOf (const AudioEngine& engine)
  2529. {
  2530. return juce::jmax (1.0, engine.getTransport().sampleRate.load());
  2531. }
  2532. // The track's latency in the current PDC plan (its output: inputs + effects + manual), in ms
  2533. double trackLatencyMs (const AudioEngine& engine, int t)
  2534. {
  2535. const auto& plan = engine.getPdcPlan();
  2536. return t >= 0 && t < (int) plan.outLat.size() ? 1000.0 * plan.outLat[(std::size_t) t] / sampleRateOf (engine) : 0.0;
  2537. }
  2538. // FL's label: "(none)" or "<ms> ms / <samples> smp" of the manual latency
  2539. juce::String manualLatencyText (const AudioEngine& engine, const MixerTrack& track)
  2540. {
  2541. if (track.latencyMs == 0.0f)
  2542. return tr ("(none)");
  2543. const auto samples = manualLatencySamples (track, sampleRateOf (engine));
  2544. return (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms / " + (samples > 0 ? "+" : "") + juce::String (samples) + " smp";
  2545. }
  2546. void setTrackLatency (AudioEngine& engine, int t, double ms)
  2547. {
  2548. if (t < 0 || t >= (int) engine.getSong().mixer.size() || ! std::isfinite (ms))
  2549. return;
  2550. const auto v = (float) juce::jlimit ((double) -maxTrackLatencyMs, (double) maxTrackLatencyMs, ms);
  2551. engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].latencyMs = v; });
  2552. }
  2553. // "Set in ms / samples / beats": FL's input box, the value in that unit (FUN_012ad520)
  2554. void askTrackLatency (AudioEngine& engine, int t, int unit)
  2555. {
  2556. const auto& track = engine.getSong().mixer[(std::size_t) t];
  2557. const auto rate = sampleRateOf (engine);
  2558. const auto bpm = juce::jmax (1.0, engine.getSong().bpm);
  2559. const juce::String units[] = { tr ("Latency (ms)"), tr ("Latency (samples)"), tr ("Latency (beats)") };
  2560. const auto value = unit == 0 ? juce::String (track.latencyMs, 2)
  2561. : unit == 1 ? juce::String (manualLatencySamples (track, rate))
  2562. : juce::String (track.latencyMs * bpm / 60000.0, 6);
  2563. auto* w = new juce::AlertWindow (tr ("Track latency"),
  2564. tr ("Positive: the other tracks wait for this one (it plays earlier). Negative: this track is delayed."),
  2565. juce::MessageBoxIconType::NoIcon);
  2566. w->addTextEditor ("v", value, units[juce::jlimit (0, 2, unit)]);
  2567. w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  2568. w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  2569. w->enterModalState (true, juce::ModalCallbackFunction::create ([w, &engine, t, unit, rate, bpm] (int result) {
  2570. if (result != 1)
  2571. return;
  2572. const auto text = w->getTextEditorContents ("v").trim().replaceCharacter (',', '.');
  2573. if (! text.containsAnyOf ("0123456789"))
  2574. return;
  2575. const auto v = text.getDoubleValue();
  2576. setTrackLatency (engine, t, unit == 0 ? v : unit == 1 ? v * 1000.0 / rate : v * 60000.0 / bpm);
  2577. }), true);
  2578. }
  2579. juce::PopupMenu trackLatencyMenu (AudioEngine& engine, int t)
  2580. {
  2581. const auto& song = engine.getSong();
  2582. const auto& track = song.mixer[(std::size_t) t];
  2583. juce::PopupMenu menu;
  2584. // FL's hint "^Track latency": "<x>ms (auto) <y>ms (manual)"
  2585. // auto = the plan's latency without the manual part, in samples (no ms rounding left over when no plugin has any)
  2586. const auto total = trackLatencyMs (engine, t);
  2587. const auto rate = sampleRateOf (engine);
  2588. const auto autoMs = total - 1000.0 * lynx::manualLatencySamples (track, rate) / rate;
  2589. menu.addSectionHeader (tr ("Latency {0} ms (auto {1} ms, manual {2} ms)",
  2590. { juce::String (total, 2), juce::String (std::abs (autoMs) < 0.005 ? 0.0 : autoMs, 2), juce::String (track.latencyMs, 2) }));
  2591. menu.addItem (tr ("Reset"), track.latencyMs != 0.0f, false, [&engine, t] { setTrackLatency (engine, t, 0.0); });
  2592. menu.addItem (tr ("Set in ms..."), [&engine, t] { askTrackLatency (engine, t, 0); });
  2593. menu.addItem (tr ("Set in samples..."), [&engine, t] { askTrackLatency (engine, t, 1); });
  2594. menu.addItem (tr ("Set in beats..."), [&engine, t] { askTrackLatency (engine, t, 2); });
  2595. {
  2596. // FL's "Set from": the tracks whose latency is not zero; this track's total becomes theirs (FUN_012acd30)
  2597. juce::PopupMenu from;
  2598. for (int o = 0; o < (int) song.mixer.size(); ++o)
  2599. {
  2600. const auto ms = trackLatencyMs (engine, o);
  2601. if (o == t || std::abs (ms) < 0.005)
  2602. continue;
  2603. const auto name = o == 0 ? tr ("Master") : juce::String (o) + " " + juce::String::fromUTF8 (song.mixer[(std::size_t) o].name.c_str());
  2604. from.addItem (name + " (" + juce::String (ms, 2) + " ms)", [&engine, t, o] {
  2605. const auto manual = (double) engine.getSong().mixer[(std::size_t) t].latencyMs + trackLatencyMs (engine, o) - trackLatencyMs (engine, t);
  2606. if (manual < 0.0)
  2607. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Track latency"),
  2608. tr ("The delay introduced by this mixer track is higher than the delay introduced by the source "
  2609. "mixer track. Set a make-up latency on the source track instead."));
  2610. else
  2611. setTrackLatency (engine, t, manual);
  2612. });
  2613. }
  2614. menu.addSubMenu (tr ("Set from"), from, from.getNumItems() > 0);
  2615. }
  2616. menu.addSeparator();
  2617. menu.addItem (tr ("Compensate for master latency"), track.outputChannel >= 0, track.compensateMasterLatency, [&engine, t] {
  2618. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].compensateMasterLatency = ! s.mixer[(std::size_t) t].compensateMasterLatency; });
  2619. });
  2620. if (t > 0)
  2621. {
  2622. menu.addSectionHeader (tr ("Bypass track latency compensation"));
  2623. const std::pair<const char*, LatencyBypass> modes[] = { { TR_NOOP ("Never"), LatencyBypass::never },
  2624. { TR_NOOP ("Always"), LatencyBypass::always },
  2625. { TR_NOOP ("When recording or not playing"), LatencyBypass::whenRecordingOrStopped } };
  2626. for (const auto& [label, mode] : modes)
  2627. menu.addItem (tr (label), true, track.latencyBypass == mode, [&engine, t, mode = mode] {
  2628. engine.editSong ([t, mode] (Song& s) { s.mixer[(std::size_t) t].latencyBypass = mode; });
  2629. });
  2630. }
  2631. return menu;
  2632. }
  2633. } // namespace
  2634. bool loadMixerTrackState (AudioEngine& engine, int track, const juce::File& file, bool asNewInsert)
  2635. {
  2636. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  2637. return false;
  2638. if (asNewInsert)
  2639. return mixerpresets::insertTrack (engine, juce::jmax (1, track + 1), file) > 0;
  2640. return mixerpresets::loadOnTracks (engine, { track }, file);
  2641. }
  2642. namespace mixerpresets
  2643. {
  2644. juce::Array<juce::File> folders()
  2645. {
  2646. // FL's browser folder 0x3f8 (REA round 167q, FUN_009db5b0): "Presets\Mixer presets" of the user data folder and
  2647. // "Data\Patches\Mixer presets" of the installation
  2648. static const auto fl = findFlStudio();
  2649. juce::Array<juce::File> out;
  2650. if (fl.userData.isDirectory())
  2651. out.add (fl.userData.getChildFile ("Presets").getChildFile ("Mixer presets"));
  2652. if (fl.installDir.isDirectory())
  2653. out.add (fl.installDir.getChildFile ("Data").getChildFile ("Patches").getChildFile ("Mixer presets"));
  2654. out.add (mixerStatesFolder());
  2655. out.removeIf ([] (const juce::File& f) { return ! f.isDirectory(); });
  2656. return out;
  2657. }
  2658. juce::Array<juce::File> all()
  2659. {
  2660. juce::Array<juce::File> files;
  2661. for (const auto& folder : folders())
  2662. for (const auto& f : folder.findChildFiles (juce::File::findFiles, true, juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension))
  2663. files.add (f);
  2664. std::stable_sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
  2665. return a.getFileNameWithoutExtension().compareNatural (b.getFileNameWithoutExtension()) < 0;
  2666. });
  2667. return files;
  2668. }
  2669. static std::vector<std::uint8_t> bytesOf (const juce::File& file)
  2670. {
  2671. juce::MemoryBlock data;
  2672. if (file.getSize() > 64 * 1024 * 1024 || ! file.loadFileAsData (data))
  2673. return {};
  2674. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  2675. return { bytes, bytes + data.getSize() };
  2676. }
  2677. bool isMixerPreset (const juce::File& file)
  2678. {
  2679. if (file.hasFileExtension (ProjectFile::mixerTrackStateExtension))
  2680. return true;
  2681. if (! file.hasFileExtension ("fst"))
  2682. return false;
  2683. for (auto p = file.getParentDirectory(); p != juce::File() && p.getParentDirectory() != p; p = p.getParentDirectory())
  2684. if (p.getFileName().equalsIgnoreCase ("Mixer presets"))
  2685. return true;
  2686. const auto bytes = bytesOf (file);
  2687. return flp::looksLikeMixerPreset (bytes);
  2688. }
  2689. std::optional<MixerTrack> read (const juce::File& file)
  2690. {
  2691. if (file.hasFileExtension ("fst"))
  2692. {
  2693. FlpImportOptions options;
  2694. options.roots = findFlStudioRoots();
  2695. options.fileExists = [] (const std::string& path) { return platform::localFile (path).existsAsFile(); };
  2696. options.readFile = [] (const std::string& path) { return bytesOf (platform::localFile (path)); };
  2697. return mixerTrackFromFlPreset (bytesOf (file), options);
  2698. }
  2699. juce::String error;
  2700. auto state = ProjectFile::mixerTrackStateFromJson (file.loadFileAsString(), error);
  2701. if (state && state->name.empty())
  2702. state->name = file.getFileNameWithoutExtension().toStdString();
  2703. return state;
  2704. }
  2705. bool loadOnTracks (AudioEngine& engine, const std::vector<int>& tracks, const juce::File& file)
  2706. {
  2707. const auto state = read (file);
  2708. if (! state)
  2709. return false;
  2710. // FL's mixer presets restore the track's name and colour (WhatsNew); LYNX's states keep the track's own
  2711. const auto takeName = file.hasFileExtension ("fst") && ! state->name.empty();
  2712. bool any = false;
  2713. engine.editSong ([&] (Song& s) {
  2714. for (const auto t : tracks)
  2715. if (t >= 0 && t < (int) s.mixer.size())
  2716. {
  2717. ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) t], *state, takeName);
  2718. any = true;
  2719. }
  2720. });
  2721. return any;
  2722. }
  2723. int insertTrack (AudioEngine& engine, int at, const juce::File& file)
  2724. {
  2725. auto state = read (file);
  2726. if (! state)
  2727. return -1;
  2728. if (state->name.empty())
  2729. state->name = file.getFileNameWithoutExtension().toStdString();
  2730. at = juce::jlimit (1, (int) engine.getSong().mixer.size(), at);
  2731. bool ok = false;
  2732. engine.editSong ([&] (Song& s) {
  2733. ok = mixerops::insertTrack (s, at);
  2734. if (ok)
  2735. ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) at], *state, true);
  2736. });
  2737. return ok ? at : -1;
  2738. }
  2739. } // namespace mixerpresets
  2740. bool saveMixerTrackState (AudioEngine& engine, int track, const juce::File& file)
  2741. {
  2742. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  2743. return false;
  2744. engine.capturePluginStates(); // the plugins' current settings go into the state
  2745. file.getParentDirectory().createDirectory();
  2746. return file.replaceWithText (ProjectFile::mixerTrackStateToJson (engine.getSong().mixer[(std::size_t) track]));
  2747. }
  2748. // FL's "Auto-create audio clip" (round 167a [SHOT s28–s37]): the rendered files go on the Playlist, one undo step
  2749. static void placeRenderedFiles (AudioEngine& engine, const std::vector<juce::File>& files)
  2750. {
  2751. std::vector<mixerops::RenderedFile> list;
  2752. juce::AudioFormatManager formats;
  2753. formats.registerBasicFormats();
  2754. for (const auto& f : files)
  2755. if (std::unique_ptr<juce::AudioFormatReader> reader (formats.createReaderFor (f)); reader != nullptr)
  2756. list.push_back ({ f.getFullPathName().toStdString(), (double) reader->lengthInSamples, reader->sampleRate });
  2757. if (! list.empty())
  2758. engine.editSong ([list] (Song& s) { mixerops::placeRenderedFiles (s, list); });
  2759. }
  2760. void MixerStrips::askInsertMultiple (int at)
  2761. {
  2762. auto* window = new juce::AlertWindow (tr ("Insert multiple"), tr ("How many blank inserts?"), juce::MessageBoxIconType::NoIcon);
  2763. // FL 2026's box starts at 10, already selected; Ctrl+A selects it again (round 167a [SHOT s13–s15])
  2764. window->addTextEditor ("count", "10");
  2765. if (auto* field = window->getTextEditor ("count"))
  2766. field->setInputRestrictions (4, "0123456789");
  2767. window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  2768. window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  2769. juce::Component::SafePointer<MixerStrips> safe (this);
  2770. window->enterModalState (true, juce::ModalCallbackFunction::create ([safe, at, window] (int result) {
  2771. if (safe == nullptr || result != 1)
  2772. return;
  2773. const auto n = window->getTextEditorContents ("count").getIntValue();
  2774. const auto room = mixerops::roomForInserts (safe->engine.getSong());
  2775. if (n > room) // FL 2026 shows "You can add a maximum of 375 tracks." (round 166d [SHOT]); nothing is added then
  2776. {
  2777. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Insert multiple"),
  2778. tr ("You can add a maximum of {0} inserts.", { juce::String (room) }));
  2779. return;
  2780. }
  2781. if (n > 0)
  2782. {
  2783. const auto first = juce::jlimit (1, (int) safe->engine.getSong().mixer.size(), at);
  2784. safe->engine.editSong ([first, n] (Song& s) { mixerops::insertTracks (s, first, n); });
  2785. for (int i = 0; i < n; ++i)
  2786. safe->revealed.insert (first + i); // shown even while unused
  2787. safe->updateSize();
  2788. safe->selectTrack (first);
  2789. }
  2790. }),
  2791. true);
  2792. if (auto* field = window->getTextEditor ("count"))
  2793. {
  2794. field->grabKeyboardFocus();
  2795. field->selectAll();
  2796. }
  2797. }
  2798. void MixerStrips::showMenu (int t)
  2799. {
  2800. buildMenu (t).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  2801. }
  2802. bool MixerStrips::runMenuItem (const juce::String& caption)
  2803. {
  2804. auto menu = buildMenu (getSelectedTrack());
  2805. for (juce::PopupMenu::MenuItemIterator it (menu, true); it.next();)
  2806. {
  2807. const auto& item = it.getItem();
  2808. if (item.isEnabled && item.action != nullptr && item.subMenu == nullptr
  2809. && item.text.upToFirstOccurrenceOf ("\t", false, false).trim() == caption)
  2810. {
  2811. const auto action = item.action; // (the menu goes away first)
  2812. menu = {};
  2813. action();
  2814. return true;
  2815. }
  2816. }
  2817. return false;
  2818. }
  2819. juce::PopupMenu MixerStrips::buildMenu (int t)
  2820. {
  2821. const auto& song = engine.getSong();
  2822. const auto channel = engine.getSelectedChannel();
  2823. juce::PopupMenu menu;
  2824. if (t < 0 || t >= (int) song.mixer.size())
  2825. return menu;
  2826. // the tracks the "selected track(s)" items act on: the selection when the clicked track is in it
  2827. const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
  2828. const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  2829. auto rename = [this, t] {
  2830. if (t >= (int) engine.getSong().mixer.size())
  2831. return;
  2832. const auto& track = engine.getSong().mixer[(std::size_t) t];
  2833. showNameAndColourDialog (tr ("Rename track"), juce::String::fromUTF8 (track.name.c_str()), track.colour,
  2834. [this, t] (const juce::String& name, std::uint32_t colour) {
  2835. if (t < (int) engine.getSong().mixer.size())
  2836. engine.editSong ([t, n = name.trim().toStdString(), colour] (Song& s) {
  2837. if (! n.empty())
  2838. s.mixer[(std::size_t) t].name = n;
  2839. s.mixer[(std::size_t) t].colour = colour;
  2840. });
  2841. });
  2842. };
  2843. // the title band in the insert's colour (FL tints the whole menu); a double-click on it renames (issue #12)
  2844. // FL: "Mixer tracks (N selected)" when the menu acts on several tracks
  2845. const auto several = targets.size() > 1;
  2846. ui::addItemHeader (menu, several ? juce::String() : t == 0 ? tr ("Master") : tr ("Mixer track {0}", { juce::String (t) }),
  2847. several ? tr ("Mixer tracks ({0} selected)", { juce::String ((int) targets.size()) }) : trackName,
  2848. song.mixer[(std::size_t) t].colour != 0 ? juce::Colour (song.mixer[(std::size_t) t].colour) : juce::Colour(), rename);
  2849. // FL's first section: name and colour (REA_rodada115)
  2850. menu.addItem (tr ("Rename and color...") + "\tF2", rename);
  2851. menu.addItem (tr ("Change color..."), [this, t] { // (FL: the colour selector at once)
  2852. const auto current = engine.getSong().mixer[(std::size_t) t].colour;
  2853. const auto mouse = juce::Desktop::getMousePosition();
  2854. const auto set = [this, t] (std::uint32_t colour) {
  2855. if (t < (int) engine.getSong().mixer.size())
  2856. engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
  2857. };
  2858. ui::showColourPickerPopup ({ mouse.x, mouse.y, 1, 1 }, tr ("Change color..."), current != 0 ? juce::Colour (current) : juce::Colour (lynxPalette()[0]), {},
  2859. [set] (juce::Colour c) { set (c.getARGB()); }, {}, [set] { set (0); });
  2860. });
  2861. menu.addItem (tr ("Random color"), [this, t] {
  2862. const auto& palette = lynxPalette();
  2863. const auto colour = palette[(std::size_t) juce::Random::getSystemRandom().nextInt ((int) palette.size())];
  2864. engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
  2865. });
  2866. // FL's "Gradient color..." (SetGradientColorMenuClick, REA_rodada177a §5): greyed below two selected tracks; the
  2867. // Gradient editor starts from the first and the last selected track's colours
  2868. menu.addItem (tr ("Gradient color..."), targets.size() > 1, false, [this, targets] {
  2869. auto sorted = targets;
  2870. std::sort (sorted.begin(), sorted.end());
  2871. const auto& mixer = engine.getSong().mixer;
  2872. const auto colourOf = [&mixer] (int track) {
  2873. const auto c = track >= 0 && track < (int) mixer.size() ? mixer[(std::size_t) track].colour : 0u;
  2874. return c != 0 ? juce::Colour (c) : juce::Colour (lynxPalette()[0]);
  2875. };
  2876. showGradientColourDialog (colourOf (sorted.front()), colourOf (sorted.back()), (int) sorted.size(),
  2877. [this, sorted] (juce::Colour first, juce::Colour last) {
  2878. engine.editSong ([sorted, a = first.getARGB(), b = last.getARGB()] (Song& s) {
  2879. mixerops::gradientColour (s, sorted, a, b);
  2880. });
  2881. });
  2882. });
  2883. // FL's "Change icon..." (SetIconMenuClick, REA round 168h: every selected track gets it); LYNX's own icon set
  2884. menu.addItem (tr ("Change icon..."), [this, t, targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t }] {
  2885. 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) {
  2886. engine.editSong ([targets, icon] (Song& s) {
  2887. for (auto track : targets)
  2888. if (track >= 0 && track < (int) s.mixer.size())
  2889. s.mixer[(std::size_t) track].icon = icon;
  2890. });
  2891. });
  2892. });
  2893. // FL's "Assign to new Audio track(s)" / "Unassign from Audio track(s)" (AssignAudiotrackMenuClick, REA_rodada177a §6)
  2894. {
  2895. const auto linked = [&song] (int insert) {
  2896. return std::any_of (song.playlistTracks.begin(), song.playlistTracks.end(), [insert] (const PlaylistTrack& pt) {
  2897. return pt.mode == PlaylistTrackMode::audio && pt.mixerTrack == insert;
  2898. });
  2899. };
  2900. const auto anyLinked = std::any_of (targets.begin(), targets.end(), [&] (int x) { return x > 0 && linked (x); });
  2901. const auto anyFree = std::any_of (targets.begin(), targets.end(), [&] (int x) { return x > 0 && ! linked (x); });
  2902. menu.addItem (tr ("Assign to new Audio track(s)"), anyFree, false,
  2903. [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::assignNewAudioTracks (s, targets); }); });
  2904. menu.addItem (tr ("Unassign from Audio track(s)"), anyLinked, false,
  2905. [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::unassignAudioTracks (s, targets); }); });
  2906. }
  2907. menu.addSeparator();
  2908. // FL's "File" submenu (REA round 167q, TFXForm's FileMenu): open/save a state, Browse states and the "States" list
  2909. // of FL's mixer presets (FL's own .fst and the user's) and LYNX's .lynxtrack states, loaded onto every selected
  2910. // track (FUN_012a7440)
  2911. {
  2912. const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
  2913. juce::PopupMenu file;
  2914. file.addItem (tr ("Open mixer track state..."), [this, targets] {
  2915. auto& chooser = mixerStateChooser();
  2916. const auto start = mixerpresets::folders().isEmpty() ? mixerStatesFolder() : mixerpresets::folders()[0];
  2917. chooser = lynx::ui::makeFileChooser (tr ("Open mixer track state"), start,
  2918. juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension);
  2919. juce::Component::SafePointer<MixerStrips> safe (this);
  2920. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [safe, targets] (const juce::FileChooser& fc) {
  2921. if (safe != nullptr && fc.getResult().existsAsFile() && ! mixerpresets::loadOnTracks (safe->engine, targets, fc.getResult()))
  2922. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Open mixer track state"),
  2923. tr ("This file is not a mixer track state LYNX SHARE can read."));
  2924. });
  2925. });
  2926. file.addItem (tr ("Save mixer track state as...") + "\tCtrl+Shift+S", [this, t, trackName] {
  2927. auto& chooser = mixerStateChooser();
  2928. const auto name = juce::File::createLegalFileName (trackName.isNotEmpty() ? trackName : tr ("Mixer track {0}", { juce::String (t) }));
  2929. chooser = lynx::ui::makeFileChooser (tr ("Save mixer track state"), mixerStatesFolder().getChildFile (name + ProjectFile::mixerTrackStateExtension),
  2930. juce::String ("*") + ProjectFile::mixerTrackStateExtension);
  2931. juce::Component::SafePointer<MixerStrips> safe (this);
  2932. mixerStatesFolder().createDirectory();
  2933. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting, [safe, t] (const juce::FileChooser& fc) {
  2934. if (safe != nullptr && fc.getResult() != juce::File())
  2935. saveMixerTrackState (safe->engine, t, fc.getResult().withFileExtension (ProjectFile::mixerTrackStateExtension));
  2936. });
  2937. });
  2938. file.addItem (tr ("Browse states"), [] {
  2939. mixerStatesFolder().createDirectory();
  2940. mixerStatesFolder().startAsProcess();
  2941. });
  2942. const auto states = mixerpresets::all();
  2943. if (! states.isEmpty())
  2944. {
  2945. file.addSectionHeader (tr ("States"));
  2946. for (const auto& f : states)
  2947. file.addItem (f.getFileNameWithoutExtension(), [this, targets, f] { mixerpresets::loadOnTracks (engine, targets, f); });
  2948. }
  2949. menu.addSubMenu (tr ("File"), file);
  2950. }
  2951. if (t > 0)
  2952. {
  2953. const auto& mt = song.mixer[(std::size_t) t];
  2954. const auto current = mt.inputChannel >= 0
  2955. ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str())
  2956. : tr ("none");
  2957. menu.addItem (tr ("Audio input: {0}...", { current }), [this, t] { mixerinput::showMenu (engine, t, this); });
  2958. }
  2959. // FL: the audio editor is loaded into the track's first empty slot (round 190cd); a full track gets the editor
  2960. // window as before
  2961. menu.addItem (tr ("Open audio editor") + "\tCtrl+E", [this, t] {
  2962. if (const auto at = addEdisonSlot (engine, t); at >= 0)
  2963. openEdisonSlot (engine, t, at);
  2964. else
  2965. openAudioEditor (engine);
  2966. });
  2967. menu.addItem (tr ("Open audio editor and record") + "\tShift+E", [this, t] {
  2968. // FL arms an Edison set to On play, 5 min, Append off, Slave on (live check 190cq, shot edison190cd-05b)
  2969. if (const auto at = addEdisonSlot (engine, t, true); at >= 0)
  2970. openEdisonSlot (engine, t, at, true);
  2971. else
  2972. openAudioEditorRecording (engine);
  2973. });
  2974. menu.addSeparator(); // (FL: a line before Reset)
  2975. menu.addItem (tr ("Reset selected track(s) to default"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetToDefault (s, targets); }); });
  2976. // --- FL's "Routing" section -----------------------------------------------------------------------
  2977. menu.addSectionHeader (tr ("Routing"));
  2978. {
  2979. juce::PopupMenu channels;
  2980. channels.addItem (tr ("Route selected channels to this track") + "\tCtrl+L", [this, t] {
  2981. setSelection (selection, t);
  2982. linkSelectedChannels (false);
  2983. });
  2984. channels.addItem (tr ("Route selected channels starting from this track") + "\tCtrl+Shift+L", [this, t] {
  2985. setSelection (selection, t);
  2986. linkSelectedChannels (true);
  2987. });
  2988. if (channel < (int) song.channels.size())
  2989. channels.addItem (tr ("Route channel \"{0}\" here", { juce::String::fromUTF8 (song.channels[(std::size_t) channel].name.c_str()) }),
  2990. [this, channel, t] { engine.editSong ([channel, t] (Song& s) { s.channels[(std::size_t) channel].mixerTrack = t; }); });
  2991. menu.addSubMenu (tr ("Channel routing"), channels);
  2992. }
  2993. {
  2994. // FL's Routing submenu (REA round 165f-mixer: FUN_012ac520 / FUN_012ac950): selected tracks ⇄ this track
  2995. std::vector<int> others;
  2996. for (auto x : selection)
  2997. if (x != t)
  2998. others.push_back (x);
  2999. const auto any = ! others.empty();
  3000. juce::PopupMenu routing;
  3001. routing.addSectionHeader (tr ("Selected tracks to this track"));
  3002. using K = mixerops::RouteKind;
  3003. auto selToThis = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeSelectedTo (s, others, t, kind); }); };
  3004. auto thisToSel = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeToSelected (s, t, others, kind); }); };
  3005. routing.addItem (tr ("Route selected to this track"), any, false, [selToThis] { selToThis (K::route); });
  3006. routing.addItem (tr ("Route selected to this track only"), any, false, [selToThis] { selToThis (K::routeOnly); });
  3007. routing.addItem (tr ("Sidechain selected to this track"), any && t > 0, false, [selToThis] { selToThis (K::sidechain); });
  3008. routing.addItem (tr ("Sidechain selected to this track only"), any && t > 0, false, [selToThis] { selToThis (K::sidechainOnly); });
  3009. routing.addSeparator();
  3010. routing.addItem (tr ("Create submix..."), any && t > 0, false, [this, others, t] {
  3011. const auto& track = engine.getSong().mixer[(std::size_t) t];
  3012. const auto name = mixerops::hasDefaultName (engine.getSong(), t) ? juce::String() : juce::String::fromUTF8 (track.name.c_str());
  3013. showNameAndColourDialog (tr ("Create submix"), name, track.colour, [this, others, t] (const juce::String& n, std::uint32_t colour) {
  3014. if (t < (int) engine.getSong().mixer.size())
  3015. engine.editSong ([others, t, n = n.trim().toStdString(), colour] (Song& s) {
  3016. s.mixer[(std::size_t) t].colour = colour;
  3017. mixerops::createSubmix (s, others, t, n);
  3018. });
  3019. });
  3020. });
  3021. const auto thisIsInsert = t > 0;
  3022. routing.addSectionHeader (tr ("This track to selected tracks"));
  3023. routing.addItem (tr ("Route this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::route); });
  3024. routing.addItem (tr ("Route this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::routeOnly); });
  3025. routing.addItem (tr ("Sidechain this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechain); });
  3026. routing.addItem (tr ("Sidechain this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechainOnly); });
  3027. menu.addSubMenu (tr ("Track routing"), routing, any);
  3028. // round 186c's option: the sends this insert lost when their insert was deleted (greyed in the routing lane)
  3029. if (t > 0 && ! song.mixer[(std::size_t) t].lostSends.empty())
  3030. {
  3031. juce::PopupMenu lost;
  3032. const auto& lostSends = song.mixer[(std::size_t) t].lostSends;
  3033. for (int i = 0; i < (int) lostSends.size(); ++i)
  3034. {
  3035. juce::PopupMenu one;
  3036. juce::PopupMenu to;
  3037. for (int x = 1; x < (int) song.mixer.size(); ++x)
  3038. if (x != t)
  3039. 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),
  3040. false, [this, t, i, x] { engine.editSong ([t, i, x] (Song& s) { mixerops::reconnectLostSend (s, t, i, x); }); });
  3041. one.addSubMenu (tr ("Reconnect to"), to);
  3042. one.addItem (tr ("Remove"), [this, t, i] { engine.editSong ([t, i] (Song& s) { mixerops::removeLostSends (s, t, i); }); });
  3043. lost.addSubMenu (tr ("Send to {0} (deleted)", { juce::String::fromUTF8 (lostSends[(std::size_t) i].to.c_str()) }), one);
  3044. }
  3045. lost.addSeparator();
  3046. lost.addItem (tr ("Remove all"), [this, t] { engine.editSong ([t] (Song& s) { mixerops::removeLostSends (s, t); }); });
  3047. menu.addSubMenu (tr ("Disconnected links"), lost);
  3048. }
  3049. }
  3050. {
  3051. juce::PopupMenu select;
  3052. select.addItem (tr ("Channels routed to this track") + "\tAlt+L", ! mixerops::channelsOn (song, t).empty(), false, [this, t] {
  3053. setSelection (selection, t);
  3054. selectLinkedChannels();
  3055. });
  3056. select.addSeparator();
  3057. const auto destinations = mixerops::destinationsOf (song, t);
  3058. const auto sources = mixerops::sourcesOf (song, t);
  3059. select.addItem (tr ("Tracks this one is routed to"), ! destinations.empty(), false, [this, t, destinations] { setSelection (destinations, t); });
  3060. select.addItem (tr ("Tracks routed to this one"), ! sources.empty(), false, [this, t, sources] { setSelection (sources, t); });
  3061. select.addSeparator();
  3062. select.addItem (tr ("Group"), t > 0, false, [this, t] {
  3063. auto group = mixerops::groupOf (engine.getSong(), t);
  3064. std::sort (group.begin(), group.end());
  3065. setSelection (group, t);
  3066. });
  3067. select.addItem (tr ("All"), [this, t] {
  3068. std::vector<int> all ((std::size_t) engine.getSong().mixer.size());
  3069. std::iota (all.begin(), all.end(), 0);
  3070. setSelection (all, t);
  3071. });
  3072. menu.addSubMenu (tr ("Select"), select);
  3073. }
  3074. menu.addItem (tr ("Reset selected track(s) routing"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetRouting (s, targets); }); });
  3075. menu.addItem (tr ("Unroute tracks routed to the selected track(s)"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::unrouteInto (s, targets); }); });
  3076. if (selected > 0 && selected != t && (t == 0 || song.canRoute (selected, t) || song.routes (selected, t)))
  3077. menu.addItem (tr ("Send \"{0}\" only to this track", { juce::String::fromUTF8 (song.mixer[(std::size_t) selected].name.c_str()) }),
  3078. [this, from = selected, t] {
  3079. engine.editSong ([from, t] (Song& s) {
  3080. s.mixer[(std::size_t) from].sends.clear();
  3081. s.mixer[(std::size_t) from].toMaster = false;
  3082. s.setRoute (from, t, true);
  3083. });
  3084. });
  3085. menu.addSeparator();
  3086. {
  3087. const auto inserts = [targets] {
  3088. std::vector<int> v;
  3089. for (auto x : targets)
  3090. if (x > 0)
  3091. v.push_back (x);
  3092. return v;
  3093. }();
  3094. // FL's two solo items (REA_rodada167l §4): the plain one mutes the tracks feeding the soloed ones, the alt one
  3095. // keeps them; the same item again clears the solo
  3096. menu.addItem (tr ("Solo selected track(s)") + "\tS", ! inserts.empty(), false, [this, inserts] {
  3097. engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, false); });
  3098. });
  3099. menu.addItem (tr ("Alt solo selected track(s)") + "\tAlt+S", ! inserts.empty(), false, [this, inserts] {
  3100. engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, true); });
  3101. });
  3102. menu.addItem (tr ("Arm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
  3103. for (auto x : inserts)
  3104. if (! engine.isInsertArmed (x))
  3105. mixerinput::toggleArm (engine, x, this);
  3106. });
  3107. menu.addItem (tr ("Disarm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
  3108. for (auto x : inserts)
  3109. if (engine.isInsertArmed (x))
  3110. engine.setInsertArmed (x, false);
  3111. });
  3112. }
  3113. menu.addItem (tr ("Compensate for master latency"), song.mixer[(std::size_t) t].outputChannel >= 0, song.mixer[(std::size_t) t].compensateMasterLatency, [this, t] {
  3114. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].compensateMasterLatency = ! s.mixer[(std::size_t) t].compensateMasterLatency; });
  3115. });
  3116. // FL's track latency (the "Track latency compensation" label's menu, REA round 165f-mixer)
  3117. menu.addSubMenu (tr ("Track latency: {0}", { manualLatencyText (engine, song.mixer[(std::size_t) t]) }), trackLatencyMenu (engine, t));
  3118. // --- LYNX's sound items (FL has them on the strip itself) -------------------------------------------
  3119. menu.addSectionHeader (tr ("Sound"));
  3120. {
  3121. const auto& track = song.mixer[(std::size_t) t];
  3122. juce::PopupMenu stereo;
  3123. const std::pair<const char*, float> widths[] = { { TR_NOOP ("Mono"), 1.0f }, { TR_NOOP ("Narrower"), 0.5f }, { TR_NOOP ("Normal"), 0.0f },
  3124. { TR_NOOP ("Wider"), -0.5f }, { TR_NOOP ("Very wide"), -1.0f } };
  3125. for (const auto& [label, value] : widths)
  3126. stereo.addItem (tr (label), true, std::abs (track.stereo - value) < 0.01f,
  3127. [this, t, v = value] { engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].stereo = v; }); });
  3128. menu.addSubMenu (tr ("Stereo separation"), stereo);
  3129. if (! song.cleanMixer)
  3130. menu.addItem (tr ("Track EQ..."), [this, t] { showTrackEq (t); });
  3131. menu.addItem (tr ("Invert phase"), true, track.invertPhase, [this, t] {
  3132. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].invertPhase = ! s.mixer[(std::size_t) t].invertPhase; });
  3133. });
  3134. menu.addItem (tr ("Swap left/right"), true, track.swapChannels, [this, t] {
  3135. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].swapChannels = ! s.mixer[(std::size_t) t].swapChannels; });
  3136. });
  3137. if (t > 0)
  3138. menu.addItem (tr ("Render to audio (freeze)..."), [this, t] { bounceInsertToAudio (engine, t); });
  3139. // round 190ch (LYNX's own, not an FL item): the one-click vocal clean-up chain on this insert. Round 190cm: here
  3140. // with LYNX's other sound items, no longer between FL's own "File" and audio input rows
  3141. if (t > 0)
  3142. menu.addSubMenu (tr ("Clean voice"), lynx::ui::cleanVoiceMenu (engine, t));
  3143. }
  3144. // --- FL's "Group" section (REA round 146a) -----------------------------------------------------------
  3145. if (t > 0)
  3146. {
  3147. menu.addSectionHeader (tr ("Group"));
  3148. const auto on = song.mixer[(std::size_t) t].separator;
  3149. menu.addItem (tr ("Separator"), true, on, [this, targets, on] {
  3150. engine.editSong ([targets, on] (Song& s) { mixerops::setSeparator (s, targets, ! on); });
  3151. });
  3152. menu.addItem (tr ("Create group"), [this, targets, t] { engine.editSong ([targets, t] (Song& s) { mixerops::createGroup (s, targets, t); }); });
  3153. menu.addItem (tr ("Auto color group"), song.mixer[(std::size_t) t].colour != 0, false,
  3154. [this, t] { engine.editSong ([t] (Song& s) { mixerops::autoColorGroup (s, t); }); });
  3155. // LYNX's addition (round 177a): a group folds to its bus strip, or to a slim tab when it has no bus
  3156. const auto canFold = mixerops::canFold (song, t);
  3157. const auto folded = mixerops::isFolded (song, t);
  3158. menu.addItem (folded ? tr ("Unfold group") : tr ("Fold group"), canFold, false, [this, t] {
  3159. engine.editSong ([t] (Song& s) { mixerops::toggleFold (s, t); });
  3160. updateSize();
  3161. });
  3162. menu.addItem (tr ("Fold all groups"), [this] {
  3163. engine.editSong ([] (Song& s) { mixerops::foldAll (s, true); });
  3164. updateSize();
  3165. });
  3166. menu.addItem (tr ("Unfold all groups"), [this] {
  3167. engine.editSong ([] (Song& s) { mixerops::foldAll (s, false); });
  3168. updateSize();
  3169. });
  3170. // LYNX's addition (round 177a): VCA faders, their strips left of the Master
  3171. std::vector<int> members;
  3172. for (const auto m : targets)
  3173. if (m > 0)
  3174. members.push_back (m);
  3175. juce::PopupMenu vcaMenu;
  3176. vcaMenu.addItem (tr ("New VCA from selected"), [this, members] {
  3177. engine.editSong ([members] (Song& s) { mixerops::createVca (s, members, {}); });
  3178. updateSize();
  3179. });
  3180. juce::PopupMenu assign, remove;
  3181. for (int i = 0; i < (int) song.vcas.size(); ++i)
  3182. {
  3183. const auto& vca = song.vcas[(std::size_t) i];
  3184. const auto in = [&vca] (int m) { return std::binary_search (vca.members.begin(), vca.members.end(), m); };
  3185. const auto all = std::all_of (members.begin(), members.end(), in);
  3186. const auto any = std::any_of (members.begin(), members.end(), in);
  3187. const auto name = juce::String::fromUTF8 (vca.name.c_str());
  3188. assign.addItem (name, ! all, all, [this, members, i] {
  3189. engine.editSong ([members, i] (Song& s) { mixerops::assignToVca (s, members, i); });
  3190. });
  3191. if (any)
  3192. remove.addItem (name, [this, members, i] {
  3193. engine.editSong ([members, i] (Song& s) { mixerops::removeFromVca (s, members, i); });
  3194. });
  3195. }
  3196. vcaMenu.addSubMenu (tr ("Assign to VCA"), assign, assign.getNumItems() > 0);
  3197. vcaMenu.addSubMenu (tr ("Remove from VCA"), remove, remove.getNumItems() > 0);
  3198. menu.addSubMenu (tr ("VCA"), vcaMenu);
  3199. }
  3200. // --- FL's "Layout" section --------------------------------------------------------------------------
  3201. {
  3202. menu.addSectionHeader (tr ("Layout"));
  3203. juce::PopupMenu dockMenu;
  3204. const auto dock = song.mixer[(std::size_t) t].dock;
  3205. const std::pair<const char*, MixerDock> docks[] = { { TR_NOOP ("Left"), MixerDock::left }, { TR_NOOP ("Middle"), MixerDock::middle },
  3206. { TR_NOOP ("Right"), MixerDock::right } };
  3207. for (const auto& [label, d] : docks)
  3208. dockMenu.addItem (tr (label), true, dock == d, [this, targets, d = d] {
  3209. engine.editSong ([targets, d] (Song& s) { mixerops::dockTracks (s, targets, d); });
  3210. });
  3211. menu.addSubMenu (tr ("Dock to"), dockMenu);
  3212. }
  3213. if (t > 0)
  3214. {
  3215. menu.addItem (tr ("Move left") + "\tAlt+Left", t > 1, false, [this, t] {
  3216. setSelection ({ t }, t);
  3217. moveSelected (-1);
  3218. });
  3219. menu.addItem (tr ("Move right") + "\tAlt+Right", t + 1 < (int) song.mixer.size(), false, [this, t] {
  3220. setSelection ({ t }, t);
  3221. moveSelected (1);
  3222. });
  3223. menu.addSeparator();
  3224. menu.addItem (tr ("Delete") + "\tDel", [this, targets] { deleteTracks (targets); });
  3225. const auto room = (int) song.mixer.size() < maxMixerTracks;
  3226. menu.addItem (tr ("Insert one"), room, false, [this, t] {
  3227. engine.editSong ([t] (Song& s) { mixerops::insertTrack (s, t); });
  3228. setSelection ({ t }, t);
  3229. });
  3230. menu.addItem (tr ("Insert multiple..."), room, false, [this, t] { askInsertMultiple (t); });
  3231. juce::PopupMenu fromState;
  3232. for (const auto& f : mixerpresets::all())
  3233. fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, t, f] {
  3234. if (const auto added = mixerpresets::insertTrack (engine, t, f); added > 0)
  3235. setSelection ({ added }, added);
  3236. });
  3237. menu.addSubMenu (tr ("Insert from state"), fromState, room && fromState.getNumItems() > 0);
  3238. // FL's last section, "CPU" (REA round 134)
  3239. menu.addSectionHeader (tr ("CPU"));
  3240. menu.addItem (tr ("Allow threaded processing"), true, song.mixer[(std::size_t) t].threaded, [this, t] {
  3241. engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].threaded = ! s.mixer[(std::size_t) t].threaded; });
  3242. });
  3243. }
  3244. menu.addSectionHeader (tr ("Mixer"));
  3245. {
  3246. // FL's Mixer › Disk recording (REA round 165f-mixer: FUN_012a7a80 / FUN_012a7d80)
  3247. std::vector<int> armed;
  3248. for (int x = 1; x < (int) song.mixer.size(); ++x)
  3249. if (engine.isInsertArmed (x))
  3250. armed.push_back (x);
  3251. juce::PopupMenu disk;
  3252. auto& eng = engine;
  3253. disk.addItem (tr ("Render armed tracks to wave file(s)...") + "\tAlt+R", ! armed.empty(), false, [armed, &eng] {
  3254. if (mixeroptions::renderTracks)
  3255. mixeroptions::renderTracks (armed, [armed, &eng] (const std::vector<juce::File>& files) {
  3256. if (eng.getRecordOptions().unarmAfterRender) // FL's "Auto-unarm" (round 166e)
  3257. for (auto t : armed)
  3258. eng.setInsertArmed (t, false);
  3259. if (eng.getRecordOptions().autoCreateClip) // FL's "Auto-create audio clip" (round 167a)
  3260. placeRenderedFiles (eng, files);
  3261. });
  3262. });
  3263. disk.addItem (tr ("Render selected tracks to wave file(s)...") + "\tShift+Alt+R", ! targets.empty(), false, [targets] {
  3264. if (mixeroptions::renderTracks)
  3265. mixeroptions::renderTracks (targets, {});
  3266. });
  3267. // FL's Disk recording "Options" (round 166e) and LYNX's own disarm after a take (issue #16)
  3268. disk.addSectionHeader (tr ("Options"));
  3269. const auto& ro = engine.getRecordOptions();
  3270. auto setRecord = [&eng] (std::function<void (AudioEngine::RecordOptions&)> change) {
  3271. auto o = eng.getRecordOptions();
  3272. change (o);
  3273. eng.setRecordOptions (o);
  3274. if (mixeroptions::changed)
  3275. mixeroptions::changed();
  3276. };
  3277. disk.addItem (tr ("Auto-unarm (rendering the armed tracks disarms them)"), true, ro.unarmAfterRender,
  3278. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.unarmAfterRender = ! r.unarmAfterRender; }); });
  3279. disk.addItem (tr ("Auto-create audio clip (the rendered files go on the Playlist)"), true, ro.autoCreateClip,
  3280. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.autoCreateClip = ! r.autoCreateClip; }); });
  3281. // FL's "Latency compensation" (RecLatCompMenu, checked by default; round 190dx): off, recorded takes are not moved
  3282. // back by the round trip, the fine adjust and the PDC (Options › Audio › Recording)
  3283. disk.addItem (tr ("Latency compensation"), true, ro.latencyCompensation,
  3284. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.latencyCompensation = ! r.latencyCompensation; }); });
  3285. disk.addItem (tr ("Disarm the inserts when recording stops"), true, ro.disarmOnStop,
  3286. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.disarmOnStop = ! r.disarmOnStop; }); });
  3287. // LYNX's own (round 190aq): also in the record button's menu
  3288. disk.addItem (tr ("Low latency while recording (bypasses effects that add latency on armed or monitored inserts)"), true, ro.lowLatencyRecording,
  3289. [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.lowLatencyRecording = ! r.lowLatencyRecording; }); });
  3290. // FL's "Format" group (round 190bf, fl190be bonus shot): the recorded takes' sample format, radio items (the
  3291. // same setting as Options › Audio › Recording › File format)
  3292. disk.addSectionHeader (tr ("Format"));
  3293. {
  3294. const auto now = eng.getRecordingSettings().format;
  3295. const std::pair<takes::SampleFormat, const char*> formats[] { { takes::SampleFormat::pcm16, TR_NOOP ("16Bit int") },
  3296. { takes::SampleFormat::pcm24, TR_NOOP ("24Bit int") },
  3297. { takes::SampleFormat::float32, TR_NOOP ("32Bit float") } };
  3298. for (const auto& [format, name] : formats)
  3299. quickpick::addRadioItem (disk, tr (name), now == format, [&eng, format = format] {
  3300. auto r = eng.getRecordingSettings();
  3301. r.format = format;
  3302. eng.setRecordingSettings (r);
  3303. });
  3304. }
  3305. menu.addSubMenu (tr ("Disk recording"), disk);
  3306. juce::PopupMenu pdc;
  3307. const auto manual = std::count_if (song.mixer.begin(), song.mixer.end(), [] (const MixerTrack& m) { return m.latencyMs != 0.0f; });
  3308. pdc.addItem (tr ("Reset manual latency on all tracks"), manual > 0, false, [this] {
  3309. juce::AlertWindow::showOkCancelBox (juce::MessageBoxIconType::WarningIcon, tr ("Warning"),
  3310. tr ("This will reset manual latency values on all mixer tracks."), tr ("OK"), tr ("Cancel"), nullptr,
  3311. juce::ModalCallbackFunction::create ([this] (int r) {
  3312. if (r == 1)
  3313. engine.editSong ([] (Song& s) { mixerops::resetManualLatency (s); });
  3314. }));
  3315. });
  3316. // FL's Automatic / Compensate automations (REA round 168j, .flp 0x1D / 0x27; FL's AutoPDCMenuClick toggles it)
  3317. pdc.addItem (tr ("Automatic (compensate the plugins' latencies)"), true, song.autoPdc,
  3318. [this] { engine.editSong ([] (Song& s) { s.autoPdc = ! s.autoPdc; }); });
  3319. pdc.addItem (tr ("Compensate automations (delay a plugin's automation with its audio)"), true, song.compensateAutomations,
  3320. [this] { engine.editSong ([] (Song& s) { s.compensateAutomations = ! s.compensateAutomations; }); });
  3321. menu.addSubMenu (tr ("Plugin delay compensation"), pdc);
  3322. }
  3323. menu.addSubMenu (tr ("Mixer layout"), MixerLayoutBox::menu (*this)); // as the title bar's drop-down (issue #52)
  3324. mixeroptions::addItems (menu, engine, false);
  3325. return menu;
  3326. }
  3327. void MixerStrips::changeListenerCallback (juce::ChangeBroadcaster*)
  3328. {
  3329. // only levels moved since the last call (a fader / knob drag, AudioEngine::editLevels; round 171c): repaint just
  3330. // the strips whose fader, pan or separation changed instead of the whole mixer at every mouse move
  3331. const auto& mixer = engine.getSong().mixer;
  3332. if (engine.getPublishCount() == seenPublish && shownLevels.size() == mixer.size())
  3333. {
  3334. const auto& vcas = engine.getSong().vcas;
  3335. if (vcaLevelsShown.size() == vcas.size())
  3336. for (std::size_t i = 0; i < vcas.size(); ++i)
  3337. if (vcas[i].level != vcaLevelsShown[i])
  3338. {
  3339. vcaLevelsShown[i] = vcas[i].level;
  3340. repaintVca ((int) i);
  3341. }
  3342. for (std::size_t t = 0; t < mixer.size(); ++t)
  3343. {
  3344. const std::array<float, 3> now { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
  3345. if (now != shownLevels[t])
  3346. {
  3347. // round 173f: just the control that moved (the fader with its cap and dB read-out, or a knob)
  3348. const auto track = (int) t;
  3349. if (now[0] != shownLevels[t][0])
  3350. {
  3351. const auto fader = faderArea (track);
  3352. repaint (stripX (track), fader.getY() - 9, stripWidthOf (track), fader.getHeight() + 9 + 20);
  3353. }
  3354. if (now[1] != shownLevels[t][1])
  3355. repaint (panArea (track).expanded (2));
  3356. if (now[2] != shownLevels[t][2])
  3357. repaint (stereoArea (track).expanded (2));
  3358. shownLevels[t] = now;
  3359. }
  3360. }
  3361. return;
  3362. }
  3363. seenPublish = engine.getPublishCount();
  3364. // "Mixer groups follow the Playlist" (round 186c): a Playlist group edit regroups the mixer, outside the undo history
  3365. // (an undo of the Playlist edit brings the old groups back through this same path)
  3366. if (followPlaylist && ! followPending)
  3367. {
  3368. if (! mixerops::followsPlaylistGroups (engine.getSong()))
  3369. {
  3370. followPending = true;
  3371. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<MixerStrips> (this)] {
  3372. if (safe == nullptr)
  3373. return;
  3374. safe->engine.editSong ([] (Song& s) { mixerops::followPlaylistGroups (s); }, false);
  3375. safe->followPending = false;
  3376. });
  3377. }
  3378. }
  3379. vcaLevelsShown.clear();
  3380. for (const auto& vca : engine.getSong().vcas)
  3381. vcaLevelsShown.push_back (vca.level);
  3382. shownLevels.resize (mixer.size());
  3383. for (std::size_t t = 0; t < mixer.size(); ++t)
  3384. shownLevels[t] = { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
  3385. selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), selected);
  3386. const auto count = (int) engine.getSong().mixer.size();
  3387. selection.erase (std::remove_if (selection.begin(), selection.end(), [count] (int t) { return t >= count; }), selection.end());
  3388. if (! std::binary_search (selection.begin(), selection.end(), selected))
  3389. selection = { selected };
  3390. updateSize();
  3391. repaint();
  3392. }
  3393. float MixerStrips::shownVolume (int t) const
  3394. {
  3395. const auto& mixer = engine.getSong().mixer;
  3396. const auto base = t >= 0 && t < (int) mixer.size() ? mixer[(std::size_t) t].volume : 0.0f;
  3397. return engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerVolume, t }, base);
  3398. }
  3399. void MixerStrips::repaintAutomatedStrips()
  3400. {
  3401. // faders, pan and send knobs follow their automation while the song plays (issue #12): only the automated controls
  3402. // repaint, and only when the value they show changed (round 174e: just the fader column or the knob, not the strip)
  3403. const auto& shown = engine.getAutomationDisplay();
  3404. if (shown.getGeneration() == shownAutomation)
  3405. return;
  3406. shownAutomation = shown.getGeneration();
  3407. std::vector<int> strips;
  3408. sendAutomatedStrips.clear();
  3409. for (const auto& t : shown.automatedTargets())
  3410. {
  3411. if (t.kind == AutomationTargetKind::mixerVolume || t.kind == AutomationTargetKind::mixerPan)
  3412. strips.push_back (t.index);
  3413. else if (t.kind == AutomationTargetKind::mixerSend && t.index == selected)
  3414. {
  3415. strips.push_back (t.slot); // (the route knob sits under the destination)
  3416. sendAutomatedStrips.push_back (t.slot);
  3417. }
  3418. else if (t.kind == AutomationTargetKind::vcaLevel && isShowing())
  3419. repaintVca (t.index);
  3420. }
  3421. std::vector<int> all = strips;
  3422. all.insert (all.end(), automatedStrips.begin(), automatedStrips.end());
  3423. automatedStrips = std::move (strips);
  3424. if (! isShowing())
  3425. return;
  3426. std::sort (all.begin(), all.end());
  3427. all.erase (std::unique (all.begin(), all.end()), all.end());
  3428. const auto& mixer = engine.getSong().mixer;
  3429. const auto count = (int) mixer.size();
  3430. automatedShown.resize (mixer.size(), { -1.0f, -1.0f });
  3431. for (const auto t : all)
  3432. {
  3433. if (t < 0 || t >= count || isHidden (t) || isFoldTab (t)) // (a folded member has no control on screen to move)
  3434. continue;
  3435. const std::array<float, 2> now { shownVolume (t),
  3436. shown.shown (AutomationTarget { AutomationTargetKind::mixerPan, t }, (mixer[(std::size_t) t].pan + 1.0f) * 0.5f) };
  3437. auto& was = automatedShown[(std::size_t) t];
  3438. if (now[0] != was[0])
  3439. {
  3440. // round 174e2: the cap's rail when the cap moved by an eighth of a pixel, the dB readout when its text changed
  3441. // (not the strip's whole column: the meters beside it stay in the cached picture)
  3442. const auto rail = faderRail (t);
  3443. const auto pixels = [&rail] (float v) { return juce::roundToInt (v * (float) rail.getHeight() * 8.0f); };
  3444. if (was[0] < 0.0f || pixels (now[0]) != pixels (was[0]))
  3445. repaint (rail.getX() - 3, rail.getY() - 9, rail.getWidth() + 6, rail.getHeight() + 18);
  3446. if (spec().dbReadout && (was[0] < 0.0f || faderToDb (now[0]) != faderToDb (was[0])))
  3447. repaint (stripX (t), faderArea (t).getBottom() + 3, stripWidthOf (t) - spec().gap, 14);
  3448. }
  3449. if (now[1] != was[1])
  3450. repaint (panArea (t).expanded (2));
  3451. if (std::find (sendAutomatedStrips.begin(), sendAutomatedStrips.end(), t) != sendAutomatedStrips.end())
  3452. repaint (routeArea (t).expanded (2)); // (a send knob: small; round 174e2: only when a send is automated)
  3453. was = now;
  3454. }
  3455. }
  3456. namespace
  3457. {
  3458. // issue #144: a silenced track's meter colours (FL draws them darker and greyer)
  3459. juce::Colour silencedMeterColour (juce::Colour c) { return c.withMultipliedSaturation (0.55f).withMultipliedBrightness (0.62f); }
  3460. } // namespace
  3461. // The two thin level bars beside a vertical name (Wide layouts); empty when the layout has none
  3462. juce::Rectangle<int> MixerStrips::nameBars (int t) const
  3463. {
  3464. const auto& sp = spec();
  3465. if (! sp.verticalName || sp.nameLow || mixerlayout::isCompact (layout) || t <= 0)
  3466. return {};
  3467. const auto box = nameArea (t);
  3468. const auto plateWidth = stripWidthOf (t) - sp.gap;
  3469. return { box.getRight() + 2, box.getY() + 6, plateWidth - box.getWidth() - 6, box.getHeight() - 12 };
  3470. }
  3471. void MixerStrips::paintNameBars (juce::Graphics& g, int t) const
  3472. {
  3473. using namespace theme;
  3474. const auto bars = nameBars (t);
  3475. for (int ch = 0; ch < 2; ++ch)
  3476. {
  3477. const auto index = (std::size_t) t * 2 + (std::size_t) ch;
  3478. const auto level = index < levels.size() ? levels[index].level : 0.0f;
  3479. const auto bw = (bars.getWidth() - 3) / 2;
  3480. const auto bar = juce::Rectangle<int> (bars.getX() + 1 + ch * (bw + 1), bars.getY() + 1, bw, bars.getHeight() - 2);
  3481. const auto h = (int) (meterPosition (level) * (float) bar.getHeight());
  3482. if (h <= 0)
  3483. continue;
  3484. const auto c = level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow;
  3485. g.setColour (isSilenced (t) ? silencedMeterColour (c) : c); // (issue #144: dimmed while silenced)
  3486. g.fillRect (bar.withTop (bar.getBottom() - h));
  3487. }
  3488. }
  3489. // Issue #144: a silenced track (its mute, a solo elsewhere, a muted VCA) keeps its meter, dimmed, as FL draws it
  3490. bool MixerStrips::isSilenced (int t) const
  3491. {
  3492. const auto& song = engine.getSong();
  3493. if (t < 0 || t >= (int) song.mixer.size())
  3494. return false;
  3495. if (song.mixer[(std::size_t) t].muted)
  3496. return true;
  3497. if (t == 0)
  3498. return false;
  3499. if (mixerops::vcaMuted (song, t))
  3500. return true;
  3501. if (std::none_of (song.mixer.begin(), song.mixer.end(), [] (const MixerTrack& m) { return m.solo; }))
  3502. return false;
  3503. const auto audible = song.soloAudible();
  3504. return (std::size_t) t < audible.size() && ! audible[(std::size_t) t];
  3505. }
  3506. // --- the loudness panel beside the Master (round 190am, LYNX's own; Mixer menu, off by default) -----------------------
  3507. namespace
  3508. {
  3509. constexpr float loudnessBarTop = 0.0f, loudnessBarBottom = -42.0f; // LUFS at the bar's ends
  3510. float loudnessBarPosition (float lufs) noexcept
  3511. {
  3512. return juce::jlimit (0.0f, 1.0f, (lufs - loudnessBarBottom) / (loudnessBarTop - loudnessBarBottom));
  3513. }
  3514. constexpr int loudnessRowsTop = 24, loudnessRowHeight = 16;
  3515. } // namespace
  3516. void MixerStrips::setShowLoudness (bool on)
  3517. {
  3518. showLoudness = on;
  3519. engine.getMeters().loudness.setEnabled (on); // (off: the audio thread measures nothing)
  3520. loudnessShown = {};
  3521. updateSize();
  3522. repaint();
  3523. }
  3524. void MixerStrips::resetLoudness()
  3525. {
  3526. engine.getMeters().loudness.reset();
  3527. loudnessShown = {};
  3528. repaint (loudnessArea());
  3529. }
  3530. juce::Rectangle<int> MixerStrips::loudnessArea() const noexcept
  3531. {
  3532. if (! showLoudness || loudnessX == hiddenX)
  3533. return {};
  3534. return { loudnessX + pinOffset (dockOf (0)), 2, loudnessWidth - spec().gap, laneTop() - 2 };
  3535. }
  3536. juce::Rectangle<int> MixerStrips::loudnessResetArea() const noexcept
  3537. {
  3538. const auto area = loudnessArea();
  3539. if (area.isEmpty())
  3540. return {};
  3541. return { area.getX() + 4, rows().faderBottom + 3, area.getWidth() - 8, 15 };
  3542. }
  3543. juce::Rectangle<int> MixerStrips::loudnessBarArea() const noexcept
  3544. {
  3545. const auto area = loudnessArea();
  3546. const auto r = rows();
  3547. return { area.getX() + 6, r.faderTop, 8, r.faderBottom - r.faderTop };
  3548. }
  3549. void MixerStrips::paintLoudnessPanel (juce::Graphics& g) const
  3550. {
  3551. using namespace theme;
  3552. const auto area = loudnessArea();
  3553. theme::fillRoundRect (g, area.toFloat(), radius::md, colour::bg2);
  3554. g.setColour (colour::border);
  3555. g.drawRoundedRectangle (area.toFloat().reduced (0.5f), radius::md, 1.0f);
  3556. g.setColour (colour::textSecondary);
  3557. g.setFont (font (type::caption, true));
  3558. textcache::drawFittedText (g, "LUFS", juce::Rectangle<int> (area.getX(), 4, area.getWidth(), 13), juce::Justification::centred, 1, 0.7f);
  3559. // the captions of the three values (EBU R 128's letters; the hint bar spells them out)
  3560. g.setFont (font (9.0f, true));
  3561. const char* captions[] = { "S", "I", "TP" };
  3562. for (int i = 0; i < 3; ++i)
  3563. textcache::drawText (g, captions[i], juce::Rectangle<int> (area.getX() + 5, loudnessRowsTop + i * loudnessRowHeight, 14, loudnessRowHeight),
  3564. juce::Justification::centredLeft, false);
  3565. // the short-term bar's well and scale (LUFS, 6 LU apart, as many as fit)
  3566. const auto bar = loudnessBarArea();
  3567. theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
  3568. g.setFont (font (9.0f));
  3569. const auto textHeight = 10.0f;
  3570. auto lastY = -100.0f;
  3571. for (int lufs = 0; lufs >= (int) loudnessBarBottom; lufs -= 6)
  3572. {
  3573. const auto y = (float) bar.getBottom() - loudnessBarPosition ((float) lufs) * (float) bar.getHeight();
  3574. if (y - lastY < textHeight + 1.0f)
  3575. continue;
  3576. lastY = y;
  3577. g.setColour (colour::textSecondary);
  3578. g.fillRect (juce::Rectangle<float> ((float) bar.getRight() + 1.0f, y - 0.5f, 3.0f, 1.0f));
  3579. const auto box = juce::Rectangle<float> ((float) bar.getRight() + 5.0f, y - textHeight * 0.5f, (float) (area.getRight() - bar.getRight()) - 9.0f, textHeight)
  3580. .withY (juce::jlimit ((float) bar.getY(), (float) bar.getBottom() - textHeight, y - textHeight * 0.5f));
  3581. textcache::drawText (g, juce::String (lufs), box, juce::Justification::centredRight, false);
  3582. }
  3583. // Reset
  3584. const auto reset = loudnessResetArea().toFloat();
  3585. theme::fillRoundRect (g, reset, radius::sm, loudnessResetHovered ? colour::bg5 : colour::bg0);
  3586. g.setColour (loudnessResetHovered ? colour::textPrimary : colour::textSecondary);
  3587. g.setFont (font (type::caption));
  3588. textcache::drawFittedText (g, tr ("Reset"), reset.toNearestInt().reduced (2, 0), juce::Justification::centred, 1, 0.6f);
  3589. }
  3590. void MixerStrips::paintLoudnessValues (juce::Graphics& g) const
  3591. {
  3592. using namespace theme;
  3593. const auto area = loudnessArea();
  3594. const auto& v = loudnessShown;
  3595. const float values[] = { v.shortTerm, v.integrated, v.truePeak };
  3596. g.setFont (font (type::small, true));
  3597. for (int i = 0; i < 3; ++i)
  3598. {
  3599. const auto known = MasterLoudness::measured (values[i]);
  3600. // the true peak warns like the peak meters: amber from -1 dBTP, red above 0 dBTP
  3601. g.setColour (! known ? colour::textDisabled
  3602. : i == 2 && values[i] > 0.0f ? colour::meterClip : i == 2 && values[i] > -1.0f ? colour::meterMid : colour::textPrimary);
  3603. textcache::drawFittedText (g, juce::String (formatLoudness (values[i])),
  3604. juce::Rectangle<int> (area.getX() + 18, loudnessRowsTop + i * loudnessRowHeight, area.getWidth() - 23, loudnessRowHeight),
  3605. juce::Justification::centredRight, 1, 0.7f);
  3606. }
  3607. const auto bar = loudnessBarArea();
  3608. if (MasterLoudness::measured (v.shortTerm))
  3609. {
  3610. const auto h = juce::roundToInt (loudnessBarPosition (v.shortTerm) * (float) bar.getHeight());
  3611. g.setColour (colour::meterLow);
  3612. g.fillRect (bar.withTop (bar.getBottom() - h).reduced (1, 0));
  3613. }
  3614. if (MasterLoudness::measured (v.integrated)) // the integrated loudness: a line across the bar
  3615. {
  3616. const auto y = (float) bar.getBottom() - loudnessBarPosition (v.integrated) * (float) bar.getHeight();
  3617. g.setColour (colour::textPrimary);
  3618. g.fillRect (juce::Rectangle<float> ((float) bar.getX() - 2.0f, y - 1.0f, (float) bar.getWidth() + 4.0f, 2.0f));
  3619. }
  3620. }
  3621. void MixerStrips::showLoudnessMenu()
  3622. {
  3623. juce::PopupMenu menu;
  3624. menu.addItem (tr ("Reset"), [this] { resetLoudness(); });
  3625. menu.addSeparator();
  3626. menu.addItem (tr ("Loudness meter beside the Master (LYNX)"), true, true, [] {
  3627. if (mixeroptions::setShowLoudness)
  3628. mixeroptions::setShowLoudness (false);
  3629. if (mixeroptions::changed)
  3630. mixeroptions::changed();
  3631. });
  3632. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  3633. }
  3634. // One meter's level, peak hold line and clip latch, inside its well (painted with the strip, or over the cached picture)
  3635. void MixerStrips::paintMeterLevel (juce::Graphics& g, int t, int ch, juce::Rectangle<int> bar) const
  3636. {
  3637. using namespace theme;
  3638. const auto index = (std::size_t) t * 2 + (std::size_t) ch;
  3639. const auto meter = index < levels.size() ? levels[index] : meters::PeakHold {};
  3640. const auto h = (int) (meterPosition (meter.level) * (float) bar.getHeight());
  3641. const auto silenced = (h > 0 || meter.peak > 0.001f) && isSilenced (t);
  3642. const auto tone = [silenced] (juce::Colour c) { return silenced ? silencedMeterColour (c) : c; };
  3643. if (h > 0)
  3644. {
  3645. const auto lit = bar.withTop (bar.getBottom() - h);
  3646. // (vertical: every meter of the same height shares one gradient, so JUCE's Direct2D brush cache hits)
  3647. juce::ColourGradient gradient (tone (colour::meterClip), 0.0f, (float) bar.getY(), tone (colour::meterLow), 0.0f, (float) bar.getBottom(), false);
  3648. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (0.0f)), tone (colour::meterClip)); // above 0 dB: clip zone
  3649. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-6.0f)), tone (colour::meterMid));
  3650. gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-18.0f)), tone (colour::meterLow));
  3651. g.setGradientFill (gradient);
  3652. g.fillRect (lit);
  3653. }
  3654. if (meter.peak > 0.001f) // peak hold line
  3655. {
  3656. const auto peakY = bar.getBottom() - (int) (meterPosition (meter.peak) * (float) bar.getHeight());
  3657. g.setColour (tone (meter.peak >= 1.0f ? colour::meterClip : meter.peak >= 0.5f ? colour::meterMid : colour::textPrimary.withAlpha (0.85f)));
  3658. g.fillRect (bar.getX(), juce::jmax (bar.getY(), peakY - 1), bar.getWidth(), 2);
  3659. }
  3660. if (meter.clipped) // clip latch: stays until the meter is clicked
  3661. {
  3662. g.setColour (colour::meterClip);
  3663. g.fillRect (bar.withHeight (4));
  3664. }
  3665. }
  3666. // The levels over the cached picture: every meter the clip reaches, except where a pinned dock block covers a scrolled
  3667. // strip (paint() draws the pinned blocks over the middle one)
  3668. void MixerStrips::paintMeterLevels (juce::Graphics& g) const
  3669. {
  3670. const auto clip = g.getClipBounds();
  3671. const auto& sp = spec();
  3672. std::vector<juce::Rectangle<int>> pinned;
  3673. for (auto dock : { MixerDock::left, MixerDock::right })
  3674. if (const auto shift = pinOffset (dock); shift != 0)
  3675. {
  3676. const auto d = (int) dock;
  3677. pinned.emplace_back (blockStart[d] + shift, 0, blockEnd[d] - blockStart[d], getHeight());
  3678. }
  3679. const auto tracks = (int) engine.getSong().mixer.size();
  3680. for (int t = 0; t < tracks; ++t)
  3681. {
  3682. if (isHidden (t))
  3683. continue;
  3684. if (isFoldTab (t)) // (a folded group's tab: one bar, and no meter of its own)
  3685. {
  3686. const auto rail = faderRail (t);
  3687. if (const juce::Rectangle<int> bar (stripX (t), rail.getY(), foldTabWidth, rail.getHeight()); bar.intersects (clip))
  3688. {
  3689. const juce::Graphics::ScopedSaveState state (g);
  3690. if (dockOf (t) == MixerDock::middle)
  3691. for (const auto& r : pinned)
  3692. g.excludeClipRegion (r);
  3693. paintFoldTabLevel (g, t);
  3694. }
  3695. continue;
  3696. }
  3697. const auto meters = meterArea (t);
  3698. const auto bars = nameBars (t);
  3699. const auto meterShown = meters.intersects (clip) && g.clipRegionIntersects (meters);
  3700. const auto barsShown = ! bars.isEmpty() && bars.intersects (clip) && g.clipRegionIntersects (bars);
  3701. if (! meterShown && ! barsShown)
  3702. continue;
  3703. const juce::Graphics::ScopedSaveState state (g);
  3704. if (dockOf (t) == MixerDock::middle)
  3705. for (const auto& r : pinned)
  3706. g.excludeClipRegion (r);
  3707. if (meterShown)
  3708. for (int ch = 0; ch < 2; ++ch)
  3709. paintMeterLevel (g, t, ch, juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight()));
  3710. if (barsShown)
  3711. paintNameBars (g, t);
  3712. }
  3713. for (int i = 0; i < (int) vcaXs.size(); ++i)
  3714. if (meterArea (vcaStrip (i)).intersects (clip))
  3715. {
  3716. const juce::Graphics::ScopedSaveState state (g);
  3717. if (dockOf (0) == MixerDock::middle) // (the VCA block sits in the Master's dock)
  3718. for (const auto& r : pinned)
  3719. g.excludeClipRegion (r);
  3720. paintVcaMeter (g, i);
  3721. }
  3722. if (showLoudness && loudnessArea().intersects (clip))
  3723. {
  3724. const juce::Graphics::ScopedSaveState state (g);
  3725. if (dockOf (0) == MixerDock::middle)
  3726. for (const auto& r : pinned)
  3727. g.excludeClipRegion (r);
  3728. paintLoudnessValues (g);
  3729. }
  3730. }
  3731. bool MixerStrips::liveFrame (double nowMs)
  3732. {
  3733. auto& meters = engine.getMeters();
  3734. const auto showing = isShowing();
  3735. repaintAutomatedStrips();
  3736. const auto elapsed = lastFrameMs > 0.0 ? juce::jlimit (0.0, 250.0, nowMs - lastFrameMs) : 1000.0 / 30.0;
  3737. lastFrameMs = nowMs;
  3738. const auto& mixer = engine.getSong().mixer;
  3739. inputLevels.resize (mixer.size(), 0.0f);
  3740. auto moving = engine.getTransport().playing.load (std::memory_order_relaxed);
  3741. const auto inputFall = ui::fallFor (0.8f, elapsed);
  3742. for (std::size_t t = 1; t < mixer.size(); ++t)
  3743. {
  3744. const auto peak = mixer[t].inputChannel >= 0 ? juce::jmax (engine.takeInputPeak ((int) t, 0), engine.takeInputPeak ((int) t, 1)) : 0.0f;
  3745. auto level = juce::jmax (peak, inputLevels[t] * inputFall);
  3746. level = level < 1e-4f ? 0.0f : level;
  3747. if (std::abs (level - inputLevels[t]) > 1e-4f)
  3748. {
  3749. moving = true;
  3750. inputLevels[t] = level;
  3751. if (showing)
  3752. repaint (inputArea ((int) t).expanded (1));
  3753. }
  3754. }
  3755. // round 177d: the gain-reduction meters (strips with one of LYNX's own dynamics only; nothing while hidden)
  3756. if (showing)
  3757. {
  3758. grShown.resize (mixer.size(), -1);
  3759. for (int t = 1; t < (int) mixer.size(); ++t)
  3760. {
  3761. const auto gr = gainReduction (t);
  3762. const auto h = gr < 0.0f ? -1 : juce::roundToInt (gr * (float) grArea (t).getHeight());
  3763. if (h != grShown[(std::size_t) t])
  3764. {
  3765. grShown[(std::size_t) t] = h;
  3766. repaint (grArea (t).expanded (1));
  3767. }
  3768. moving = moving || h > 0;
  3769. }
  3770. }
  3771. // every meter row that changed by a pixel goes into one rectangle, repainted once per frame (round 174e2: the A/B
  3772. // against one repaint per meter favoured the single rectangle, within the noise of the machine)
  3773. juce::Rectangle<int> dirty;
  3774. int woken = -1;
  3775. for (std::size_t i = 0; i < levels.size(); ++i)
  3776. {
  3777. auto& m = levels[i];
  3778. const auto before = m;
  3779. const auto peak = meters.takePeak ((int) (i / 2), (int) (i % 2));
  3780. m.advance (peak, elapsed); // ~20 dB/s falloff, 1.5 s peak hold
  3781. // "Show only used inserts" (round 190am): an insert that receives audio always shows, whatever feeds it
  3782. if (showUsedOnly && peak > 1.0e-4f && i >= 2 && revealed.count ((int) (i / 2)) == 0 && isHidden ((int) (i / 2)))
  3783. woken = (int) (i / 2);
  3784. if (m.level != before.level || m.peak != before.peak)
  3785. moving = true;
  3786. if (! showing)
  3787. continue;
  3788. // only the rows of the meter that changed by a pixel are repainted (round 174e: at the display's rate), and in
  3789. // the Wide layouts the two thin bars beside the name, which follow the same level (round 173f)
  3790. const auto t = (int) (i / 2);
  3791. const auto ch = (int) (i % 2);
  3792. if (t < (int) tabOf.size() && tabOf[(std::size_t) t] > 0 && m.level != before.level) // a folded group's tab
  3793. {
  3794. const auto tab = tabOf[(std::size_t) t];
  3795. const auto rail = faderRail (tab);
  3796. const juce::Rectangle<int> bar (stripX (tab) + foldTabWidth - 10, rail.getY() - 1, 8, rail.getHeight() + 2);
  3797. dirty = dirty.isEmpty() ? bar : dirty.getUnion (bar);
  3798. }
  3799. if (isHidden (t) || isFoldTab (t))
  3800. continue;
  3801. const auto area = meterArea (t);
  3802. const auto& sp = spec();
  3803. const auto rows = meters::dirtyRows (before, m, area.getHeight(), [] (float v) { return meterPosition (v); });
  3804. if (! rows.empty())
  3805. {
  3806. const juce::Rectangle<int> bar (area.getX() + ch * (sp.meterWidth + 2) - 1, area.getY() + rows.top - 1, sp.meterWidth + 2,
  3807. rows.bottom - rows.top + 2);
  3808. dirty = dirty.isEmpty() ? bar : dirty.getUnion (bar);
  3809. // the thin bars beside the name: only the bar that moved, and (cached) over the picture as well (round 174e2)
  3810. if (const auto bars = nameBars (t); ! bars.isEmpty()
  3811. && (int) (meterPosition (m.level) * 64.0f) != (int) (meterPosition (before.level) * 64.0f))
  3812. {
  3813. const auto bw = (bars.getWidth() - 3) / 2;
  3814. dirty = dirty.getUnion ({ bars.getX() + 1 + ch * (bw + 1) - 1, bars.getY(), bw + 2, bars.getHeight() });
  3815. }
  3816. }
  3817. }
  3818. // the VCA strips' meters show their loudest member (round 177a; nothing to do without a VCA)
  3819. if (const auto count = engine.getSong().vcas.size(); count > 0 && showing)
  3820. {
  3821. vcaMetersShown.resize (count * 2, 0.0f);
  3822. for (int i = 0; i < (int) count; ++i)
  3823. for (int ch = 0; ch < 2; ++ch)
  3824. {
  3825. const auto level = vcaMeter (i, ch);
  3826. auto& was = vcaMetersShown[(std::size_t) i * 2 + (std::size_t) ch];
  3827. if ((int) (meterPosition (level) * 256.0f) != (int) (meterPosition (was) * 256.0f))
  3828. {
  3829. const auto area = meterArea (vcaStrip (i)).expanded (1);
  3830. dirty = dirty.isEmpty() ? area : dirty.getUnion (area);
  3831. }
  3832. was = level;
  3833. }
  3834. }
  3835. // the loudness panel (round 190am; nothing while it is off): repainted when a shown number or the bar changes
  3836. if (showLoudness && showing)
  3837. if (const auto now = meters.loudness.read(); ! (now == loudnessShown))
  3838. {
  3839. const auto same = [] (float a, float b) { return formatLoudness (a) == formatLoudness (b); };
  3840. const auto changed = ! same (now.shortTerm, loudnessShown.shortTerm) || ! same (now.integrated, loudnessShown.integrated)
  3841. || ! same (now.truePeak, loudnessShown.truePeak);
  3842. loudnessShown = now;
  3843. if (changed)
  3844. {
  3845. const auto area = loudnessArea();
  3846. dirty = dirty.isEmpty() ? area : dirty.getUnion (area);
  3847. }
  3848. }
  3849. if (! dirty.isEmpty())
  3850. {
  3851. meterRepaintOnly = meterCacheOn; // (the cached picture under the meters stays valid: they are drawn over it)
  3852. repaint (dirty);
  3853. meterRepaintOnly = false;
  3854. }
  3855. if (woken > 0) // (one per frame is enough: the next frame brings the next)
  3856. {
  3857. revealed.insert (woken);
  3858. updateSize();
  3859. repaint();
  3860. }
  3861. return moving;
  3862. }
  3863. // ---------------------------------------------------------------------------
  3864. namespace
  3865. {
  3866. constexpr int panelHeader = 30;
  3867. constexpr int inputRowHeight = 30; // the input row (arm, audio input source) above the slots
  3868. constexpr int slotsTop = panelHeader + inputRowHeight;
  3869. constexpr int slotHeight = 24;
  3870. const EffectKind allEffects[] = { EffectKind::eq, EffectKind::parametricEq, EffectKind::facetEq, EffectKind::compressor, EffectKind::limiter, EffectKind::apexLimiter,
  3871. EffectKind::delay, EffectKind::reverb, EffectKind::chorus, EffectKind::filter,
  3872. EffectKind::distortion, EffectKind::utility, EffectKind::volumeGate,
  3873. EffectKind::pitchShift, EffectKind::freqShift, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::frequencySplitter, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect,
  3874. EffectKind::ridgeStrip, EffectKind::glowLeveler, EffectKind::hushDeEsser, EffectKind::aether, EffectKind::ember, EffectKind::kilnChannel, EffectKind::fretChannel, EffectKind::shellChannel, EffectKind::strikeShaper, // LYNX's mixing suite
  3875. EffectKind::lynxTune, // LYNX's own pitch corrector
  3876. EffectKind::epochVerb, EffectKind::atrium, EffectKind::foilPlate, EffectKind::nebula, EffectKind::halo, EffectKind::horizon, // LYNX's reverbs
  3877. EffectKind::echoform, EffectKind::spiralEcho, EffectKind::orbit, EffectKind::latticeMod, // LYNX's delay / modulation suite
  3878. EffectKind::crestCompressor, EffectKind::prismMultiband, EffectKind::sentryGate, // LYNX's dynamics suite
  3879. EffectKind::quellDenoiser, EffectKind::geminiDoubler, EffectKind::voiceShift, // LYNX's voice tools
  3880. EffectKind::pocketDistortion, EffectKind::pocketLimiterClassic, EffectKind::pocketLimiter, EffectKind::pocketLeveller,
  3881. EffectKind::pocketGate, EffectKind::pocketTranceDelay, EffectKind::pocketTapeDelay, EffectKind::pocketMultiFx, // Pocket: FL Studio Mobile's effects (round 188h)
  3882. EffectKind::pocketAutoduck, EffectKind::pocketChorus, EffectKind::pocketSpacer, EffectKind::pocketStereoizer, // Pocket (round 189h)
  3883. EffectKind::pocketWowFlutter, EffectKind::pocketPhaser, EffectKind::pocketFlanger, EffectKind::pocketTremolo, // Pocket (round 189h)
  3884. EffectKind::pocketWaveshaper, EffectKind::pocketCompressor, EffectKind::pocketSpreader, // Pocket (round 189h)
  3885. EffectKind::pocketComb, // Pocket (round 190by)
  3886. EffectKind::pocketMultiband, // Pocket (round 190by)
  3887. EffectKind::pocketTapeStop, // Pocket (round 190by)
  3888. EffectKind::pocketEq, EffectKind::pocketGraphicEq, EffectKind::pocketFilter, // Pocket (round 190dw)
  3889. EffectKind::pocketReverbClassic, EffectKind::pocketReverb2, EffectKind::pocketReverb, // Pocket (round 190dw)
  3890. EffectKind::formulaController, EffectKind::peakController, EffectKind::xyController, EffectKind::xyzController,
  3891. EffectKind::controlSurface, // controllers (link their output to any knob)
  3892. EffectKind::patcher, // FL's Patcher: a graph of effects / instruments / plugins (REA_rodada141)
  3893. EffectKind::hardwareInsert, // outboard gear through device outputs / inputs, pinged round trip (round 164d)
  3894. EffectKind::fruityLimiter, EffectKind::fruityCompressor,
  3895. EffectKind::fruityWaveShaper, EffectKind::fruitySoftClipper,
  3896. EffectKind::reeverb2, EffectKind::reeverb1,
  3897. EffectKind::fruityDelay2, EffectKind::fruityDelay3,
  3898. EffectKind::stereoShaper, EffectKind::stereoEnhancer, EffectKind::transientProcessor,
  3899. EffectKind::spreader, EffectKind::fruityChorus, EffectKind::hyperChorus, EffectKind::vintageChorus,
  3900. EffectKind::fruityPanOMatic, EffectKind::fruityBalance, EffectKind::fruityBloodOverdrive, EffectKind::fruitySend,
  3901. EffectKind::fruityDelayBank, EffectKind::fruityMultiband,
  3902. EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::fruityPhaser, EffectKind::luxeVerb,
  3903. EffectKind::fruityFastLP, EffectKind::fruityFreeFilter, EffectKind::fruityFilter,
  3904. EffectKind::hardcore,
  3905. EffectKind::multibandDelay, EffectKind::emphasizer, EffectKind::flEmphasis, EffectKind::flFrequencyShifter, EffectKind::flLowLifter,
  3906. EffectKind::flPhaseInverter, EffectKind::flCenter, EffectKind::flBassBoost, EffectKind::fl7BandEq, EffectKind::flDelay1, // round 165k
  3907. EffectKind::waveCandy, EffectKind::visualizer, // visual plugins (round 164c)
  3908. EffectKind::fruityMute2, EffectKind::bigClock, EffectKind::tuner, EffectKind::htmlNotebook, // round 165g
  3909. EffectKind::scratcher, // round 165g (flscratch165): FL's turntable
  3910. EffectKind::transmitter, // round 165g (fltrans165): FL's transient / sustain splitter
  3911. EffectKind::flTransporter, // round 167f: FL's transient looper, exact
  3912. // FL engines that need more than their parameters (round 142, issue #5): a new one starts from
  3913. // the plugin's Default preset of the user's FL installation (core/NativeEngines.h)
  3914. EffectKind::maximus, EffectKind::vocodex, EffectKind::equo, EffectKind::distructor, EffectKind::lovePhilter,
  3915. EffectKind::grossBeat, EffectKind::convolver, EffectKind::flPitchShifter, EffectKind::vintagePhaser,
  3916. EffectKind::squeeze, EffectKind::rhythmGain, EffectKind::newtone, EffectKind::newtime,
  3917. EffectKind::edison }; // round 190cd: FL's audio editor as a slot plugin
  3918. } // namespace
  3919. const std::vector<EffectKind>& addableEffects()
  3920. {
  3921. static const std::vector<EffectKind> list (std::begin (allEffects), std::end (allEffects));
  3922. return list;
  3923. }
  3924. bool isFlEffect (EffectKind kind)
  3925. {
  3926. // allEffects lists LYNX's own effects first and FL's from the Formula Controller on (the outboard gear insert is LYNX's)
  3927. const auto& list = addableEffects();
  3928. const auto first = std::find (list.begin(), list.end(), EffectKind::formulaController);
  3929. const auto at = std::find (list.begin(), list.end(), kind);
  3930. return at != list.end() && at >= first && kind != EffectKind::hardwareInsert;
  3931. }
  3932. bool addableEffectAvailable (EffectKind kind)
  3933. {
  3934. const auto* e = natives::effectEngine (kind);
  3935. return e == nullptr || natives::available (*e, flStudioAccess());
  3936. }
  3937. juce::String addableEffectName (EffectKind kind)
  3938. {
  3939. const auto name = juce::String::fromUTF8 (effectInfo (kind).name);
  3940. // LYNX's own pitch / frequency effects sit next to FL's look-alikes (Pitch Shifter, Frequency Shifter, Pitcher)
  3941. // in the lists: tell them apart (round 162, issue #7 review)
  3942. if (kind == EffectKind::pitchShift || kind == EffectKind::freqShift || kind == EffectKind::pitchCorrect)
  3943. return tr ("{0} (LYNX SHARE)", { name });
  3944. if (const auto* e = natives::effectEngine (kind))
  3945. {
  3946. if (! natives::available (*e, flStudioAccess()))
  3947. return tr ("{0} (requires FL Studio)", { name });
  3948. if (e->beta)
  3949. return tr ("{0} (beta)", { name });
  3950. }
  3951. return name;
  3952. }
  3953. std::optional<EffectSlot> newAddableEffect (EffectKind kind, double bpm)
  3954. {
  3955. return natives::newEffect (kind, flStudioAccess(), bpm);
  3956. }
  3957. EffectsPanel::EffectsPanel (AudioEngine& e)
  3958. : engine (e)
  3959. {
  3960. setWantsKeyboardFocus (false);
  3961. setMouseClickGrabsKeyboardFocus (false);
  3962. engine.addChangeListener (this);
  3963. showingTimer = std::make_unique<ui::TimerWhileShowing> (*this, static_cast<juce::Timer&> (*this), 30); // (stopped while hidden; round 174f)
  3964. }
  3965. EffectsPanel::~EffectsPanel()
  3966. {
  3967. engine.removeChangeListener (this);
  3968. }
  3969. juce::Rectangle<int> EffectsPanel::armBounds() const
  3970. {
  3971. return { 8, panelHeader + 2, 24, inputRowHeight - 8 };
  3972. }
  3973. juce::Rectangle<int> EffectsPanel::inputBoxBounds() const
  3974. {
  3975. return { 38, panelHeader + 2, getWidth() - 46, inputRowHeight - 8 };
  3976. }
  3977. void EffectsPanel::groupIntoRack (int slot, bool all)
  3978. {
  3979. engine.capturePluginStates(); // (the plugins' current settings go with them)
  3980. const auto t = track;
  3981. const auto moved = all ? patcherize::slotsForAll (engine.getSong(), t) : std::vector<int> { slot };
  3982. // a hosted plugin's automated parameter: its value now (node k is moved slot k), so its macro starts there
  3983. auto values = [this, t, moved] (int node, int param) -> float {
  3984. if (node < 0 || node >= (int) moved.size())
  3985. return -1.0f;
  3986. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (t, moved[(std::size_t) node]).get()); p != nullptr && ! p->hasCrashed())
  3987. if (auto& instance = p->getInstance(); param >= 0 && param < instance.getParameters().size())
  3988. return instance.getParameters()[param]->getValue();
  3989. return -1.0f;
  3990. };
  3991. auto trial = engine.getSong();
  3992. const auto at = patcherize::patcherizeSlots (trial, t, slot, all);
  3993. if (at < 0 || ! rack::fromPatcher (trial.mixer[(std::size_t) t].effects[(std::size_t) at].patcher, values))
  3994. {
  3995. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Group into Audio Effect Rack"),
  3996. tr ("These effects can't go into a rack (a side-chain, or more than 16 automated parameters)."));
  3997. return;
  3998. }
  3999. int placed = -1;
  4000. engine.editSong ([t, slot, all, values, &placed] (Song& song) {
  4001. placed = patcherize::patcherizeSlots (song, t, slot, all);
  4002. if (placed >= 0)
  4003. rack::fromPatcher (song.mixer[(std::size_t) t].effects[(std::size_t) placed].patcher, values);
  4004. });
  4005. if (placed >= 0)
  4006. selectedSlot = placed;
  4007. repaint();
  4008. }
  4009. void EffectsPanel::timerCallback()
  4010. {
  4011. // the input level of the shown insert (the strips read their own); decays like a meter
  4012. const auto& mixer = engine.getSong().mixer;
  4013. const auto hasInput = track >= 0 && track < (int) mixer.size() && mixer[(std::size_t) track].inputChannel >= 0;
  4014. auto changed = false;
  4015. for (int side = 0; side < 2; ++side)
  4016. {
  4017. const auto peak = hasInput ? engine.peekInputPeak (track, side) : 0.0f;
  4018. const auto level = juce::jmax (peak, inputLevel[(std::size_t) side] * 0.8f);
  4019. changed = changed || std::abs (level - inputLevel[(std::size_t) side]) > 1e-4f;
  4020. inputLevel[(std::size_t) side] = level < 1e-4f ? 0.0f : level;
  4021. }
  4022. if (changed && isShowing())
  4023. repaint (inputBoxBounds());
  4024. // another effect selected (its controls need another height): fold / unfold the EQ, scroll (round 164)
  4025. if (const auto* s = slots(); s != nullptr && isShowing())
  4026. {
  4027. const auto kind = selectedSlot >= 0 && selectedSlot < (int) s->size() ? (int) (*s)[(std::size_t) selectedSlot].kind : -1;
  4028. if (selectedSlot != fittedSlot || kind != fittedKind)
  4029. {
  4030. fittedSlot = selectedSlot;
  4031. fittedKind = kind;
  4032. refit();
  4033. }
  4034. }
  4035. }
  4036. void EffectsPanel::setTrack (int t)
  4037. {
  4038. track = t;
  4039. const auto* s = slots();
  4040. selectedSlot = s != nullptr && ! s->empty() ? 0 : -1;
  4041. refit();
  4042. repaint();
  4043. }
  4044. const std::vector<EffectSlot>* EffectsPanel::slots() const
  4045. {
  4046. const auto& mixer = engine.getSong().mixer;
  4047. return track >= 0 && track < (int) mixer.size() ? &mixer[(std::size_t) track].effects : nullptr;
  4048. }
  4049. int EffectsPanel::rowOf (int index) const
  4050. {
  4051. const auto* s = slots();
  4052. if (s == nullptr || index < 0 || index >= (int) s->size())
  4053. return -1;
  4054. return mixerops::effectRows (*s)[(std::size_t) index];
  4055. }
  4056. int EffectsPanel::effectIn (int row) const
  4057. {
  4058. const auto* s = slots();
  4059. return s == nullptr ? -1 : mixerops::effectAtRow (*s, row);
  4060. }
  4061. juce::Rectangle<int> EffectsPanel::mixBounds (int slot) const
  4062. {
  4063. return slotBounds (slot).withTrimmedRight (20).removeFromRight (24);
  4064. }
  4065. juce::Rectangle<int> EffectsPanel::ledBounds (int slot) const
  4066. {
  4067. return slotBounds (slot).removeFromRight (20);
  4068. }
  4069. juce::Rectangle<int> EffectsPanel::arrowBounds (int slot) const
  4070. {
  4071. return slotBounds (slot).removeFromLeft (18);
  4072. }
  4073. // --- the insert's built-in EQ and its output (FL's layout under the slots, REA round 104) ---------
  4074. namespace
  4075. {
  4076. constexpr int eqGraphHeight = 84, eqKnobsHeight = 46, outputRowHeight = 30;
  4077. constexpr float eqMinHz = 20.0f, eqMaxHz = 20000.0f, eqRangeDb = 18.0f;
  4078. const char* const eqBandNames[] = { TR_NOOP ("Low shelf"), TR_NOOP ("Peak"), TR_NOOP ("High shelf") };
  4079. juce::Colour eqBandColour (int band)
  4080. {
  4081. return band == 0 ? juce::Colour (0xFFE0A33Au) : band == 1 ? juce::Colour (0xFF5FC27Eu) : juce::Colour (0xFF5B9BE6u);
  4082. }
  4083. // stored 0..1 <-> the band's value
  4084. float eqToValue (const TrackEq& eq, int band, int what)
  4085. {
  4086. const auto b = (std::size_t) band;
  4087. if (what == 0)
  4088. return (eq.gainDb[b] + eqRangeDb) / (2.0f * eqRangeDb);
  4089. if (what == 1)
  4090. return std::log (eq.hz[b] / 10.0f) / std::log (1600.0f);
  4091. return eq.width[b];
  4092. }
  4093. void eqFromValue (TrackEq& eq, int band, int what, float v)
  4094. {
  4095. const auto b = (std::size_t) band;
  4096. v = juce::jlimit (0.0f, 1.0f, v);
  4097. if (what == 0)
  4098. eq.gainDb[b] = std::round ((v * 2.0f * eqRangeDb - eqRangeDb) * 10.0f) / 10.0f;
  4099. else if (what == 1)
  4100. eq.hz[b] = std::round (10.0f * std::pow (1600.0f, v));
  4101. else
  4102. eq.width[b] = v;
  4103. }
  4104. // the EQ's response at `hz` (dB), with the filters the mixer runs (RackRenderer::applyTrackEq)
  4105. float eqResponseDb (const TrackEq& eq, double hz, double sampleRate)
  4106. {
  4107. Biquad bands[3];
  4108. bands[0].shelf (sampleRate, std::min ((double) eq.hz[0], sampleRate * 0.45), eq.gainDb[0], false, TrackEq::shelfSlope (eq.width[0]));
  4109. bands[1].peaking (sampleRate, std::min ((double) eq.hz[1], sampleRate * 0.45), TrackEq::peakQ (eq.width[1]), eq.gainDb[1]);
  4110. bands[2].shelf (sampleRate, std::min ((double) eq.hz[2], sampleRate * 0.45), eq.gainDb[2], true, TrackEq::shelfSlope (eq.width[2]));
  4111. const auto w = juce::MathConstants<double>::twoPi * hz / sampleRate;
  4112. const std::complex<double> z1 = std::polar (1.0, -w), z2 = std::polar (1.0, -2.0 * w);
  4113. double db = 0.0;
  4114. for (int b = 0; b < 3; ++b)
  4115. {
  4116. if (eq.gainDb[(std::size_t) b] == 0.0f)
  4117. continue; // a band at 0 dB is not processed (like FL)
  4118. const auto& f = bands[b];
  4119. const auto h = (f.b0 + f.b1 * z1 + f.b2 * z2) / (1.0 + f.a1 * z1 + f.a2 * z2);
  4120. db += 20.0 * std::log10 (std::max (1e-9, std::abs (h)));
  4121. }
  4122. return (float) db;
  4123. }
  4124. } // namespace
  4125. constexpr int eqFoldBarHeight = 20;
  4126. bool EffectsPanel::eqShown() const
  4127. {
  4128. return ! engine.getSong().cleanMixer; // clean mixer (round 163): no built-in EQ to show
  4129. }
  4130. int EffectsPanel::belowHeight (bool folded) const
  4131. {
  4132. if (! eqShown()) // clean mixer: only the output row
  4133. return outputRowHeight + 8;
  4134. return outputRowHeight + eqFoldBarHeight + (folded ? 4 : eqGraphHeight + eqKnobsHeight + 14);
  4135. }
  4136. int EffectsPanel::bottomTop() const
  4137. {
  4138. return getHeight() - belowHeight (eqFolded);
  4139. }
  4140. juce::Rectangle<int> EffectsPanel::eqFoldBounds() const
  4141. {
  4142. if (! eqShown())
  4143. return {};
  4144. return { 8, bottomTop(), getWidth() - 16, eqFoldBarHeight };
  4145. }
  4146. int EffectsPanel::neededHeight (bool folded) const
  4147. {
  4148. // the slots and the selected effect's controls (round 164: its knobs and their names and values too, they were
  4149. // cut by the EQ at medium heights): when they don't fit with the EQ open, it folds; then the panel scrolls
  4150. return selectedEffectBottom() + 6 + belowHeight (folded);
  4151. }
  4152. void EffectsPanel::fitToView (int w, int h, int scrollBar)
  4153. {
  4154. viewWidth = w;
  4155. viewHeight = h;
  4156. scrollBarThickness = scrollBar;
  4157. refit();
  4158. }
  4159. void EffectsPanel::refit()
  4160. {
  4161. if (viewWidth <= 0 || viewHeight <= 0)
  4162. return;
  4163. const auto folded = eqFoldChoice == 2 || (eqFoldChoice == 0 && viewHeight < neededHeight (false));
  4164. const auto need = neededHeight (folded);
  4165. const auto scrolls = viewHeight < need;
  4166. const auto changed = folded != eqFolded;
  4167. eqFolded = folded;
  4168. const juce::Rectangle<int> size (viewWidth - (scrolls ? scrollBarThickness : 0), juce::jmax (viewHeight, need));
  4169. if (getWidth() != size.getWidth() || getHeight() != size.getHeight())
  4170. setSize (size.getWidth(), size.getHeight());
  4171. else if (changed)
  4172. repaint();
  4173. }
  4174. juce::Rectangle<int> EffectsPanel::eqGraphBounds() const
  4175. {
  4176. return { 8, bottomTop() + eqFoldBarHeight, getWidth() - 16 - 3 * 18 - 6, eqGraphHeight };
  4177. }
  4178. juce::Rectangle<int> EffectsPanel::eqFaderBounds (int band) const
  4179. {
  4180. const auto graph = eqGraphBounds();
  4181. return { graph.getRight() + 6 + band * 18, graph.getY(), 16, graph.getHeight() };
  4182. }
  4183. juce::Rectangle<int> EffectsPanel::eqKnobBounds (int band, int what) const
  4184. {
  4185. const auto fader = eqFaderBounds (band);
  4186. return { fader.getCentreX() - 11, eqGraphBounds().getBottom() + 2 + (what - 1) * 22, 22, 22 };
  4187. }
  4188. juce::Rectangle<int> EffectsPanel::outputBounds() const
  4189. {
  4190. return { 34, getHeight() - outputRowHeight - 2, getWidth() - 42, outputRowHeight - 8 };
  4191. }
  4192. juce::Point<float> EffectsPanel::eqHandle (int band) const
  4193. {
  4194. const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
  4195. const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
  4196. const auto hz = juce::jlimit (eqMinHz, eqMaxHz, eq.hz[(std::size_t) band]);
  4197. const auto x = graph.getX() + graph.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
  4198. const auto y = graph.getCentreY() - graph.getHeight() * 0.5f * eq.gainDb[(std::size_t) band] / eqRangeDb;
  4199. return { x, y };
  4200. }
  4201. int EffectsPanel::eqControlAt (juce::Point<int> p) const
  4202. {
  4203. if (slots() == nullptr || eqFolded || ! eqShown())
  4204. return 0;
  4205. for (int b = 0; b < 3; ++b)
  4206. {
  4207. if (eqFaderBounds (b).contains (p))
  4208. return eqParamBase - b * 3;
  4209. for (int what = 1; what <= 2; ++what)
  4210. if (eqKnobBounds (b, what).contains (p))
  4211. return eqParamBase - b * 3 - what;
  4212. }
  4213. if (eqGraphBounds().contains (p))
  4214. {
  4215. // the nearest handle (by distance in the graph): FL's "Tweak band N"
  4216. int best = 0;
  4217. float bestDistance = 1e9f;
  4218. for (int b = 0; b < 3; ++b)
  4219. if (const auto d = eqHandle (b).getDistanceFrom (p.toFloat()); d < bestDistance)
  4220. {
  4221. bestDistance = d;
  4222. best = b;
  4223. }
  4224. return eqPointBase - best;
  4225. }
  4226. return 0;
  4227. }
  4228. void EffectsPanel::setEqFromGraph (int band, juce::Point<int> p)
  4229. {
  4230. const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
  4231. const auto fx = juce::jlimit (0.0f, 1.0f, (p.x - graph.getX()) / graph.getWidth());
  4232. const auto hz = juce::jlimit (10.0f, 16000.0f, std::round (eqMinHz * std::pow (eqMaxHz / eqMinHz, fx)));
  4233. const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, std::round ((graph.getCentreY() - p.y) / (graph.getHeight() * 0.5f) * eqRangeDb * 10.0f) / 10.0f);
  4234. engine.editSong ([t = track, band, hz, db] (Song& s) {
  4235. if (t < (int) s.mixer.size())
  4236. {
  4237. s.mixer[(std::size_t) t].eq.hz[(std::size_t) band] = hz;
  4238. s.mixer[(std::size_t) t].eq.gainDb[(std::size_t) band] = db;
  4239. }
  4240. });
  4241. }
  4242. void EffectsPanel::paintEq (juce::Graphics& g)
  4243. {
  4244. using namespace theme;
  4245. const auto& song = engine.getSong();
  4246. if (track < 0 || track >= (int) song.mixer.size())
  4247. return;
  4248. const auto& eq = song.mixer[(std::size_t) track].eq;
  4249. const auto top = bottomTop();
  4250. g.setColour (colour::border);
  4251. g.fillRect (8, top, getWidth() - 16, 1);
  4252. // the title bar: click folds / unfolds the EQ (it folds by itself when the mixer is too short for it)
  4253. if (eqShown())
  4254. {
  4255. const auto bar = eqFoldBounds().toFloat();
  4256. const auto active = eq.active();
  4257. auto chevron = bar.withWidth (14.0f).withSizeKeepingCentre (12.0f, 12.0f);
  4258. {
  4259. juce::Graphics::ScopedSaveState state (g);
  4260. if (eqFolded)
  4261. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, chevron.getCentreX(), chevron.getCentreY()));
  4262. icons::draw (g, Icon::chevronDown, chevron, colour::textSecondary);
  4263. }
  4264. g.setFont (font (type::small, true));
  4265. g.setColour (colour::textSecondary);
  4266. textcache::drawText (g, tr ("EQ"), bar.withTrimmedLeft (18.0f).toNearestInt(), juce::Justification::centredLeft);
  4267. if (eq.bypassed && eq.hasBoostOrCut()) // round 177d: bypassed, its settings kept
  4268. {
  4269. g.setColour (colour::textDisabled);
  4270. g.setFont (font (type::caption));
  4271. textcache::drawText (g, tr ("bypassed"), bar.withTrimmedLeft (44.0f).toNearestInt(), juce::Justification::centredLeft);
  4272. }
  4273. else if (eqFolded && active) // a folded EQ that still changes the sound says so
  4274. {
  4275. g.setColour (colour::accent);
  4276. g.setFont (font (type::caption));
  4277. textcache::drawText (g, tr ("active"), bar.withTrimmedLeft (44.0f).toNearestInt(), juce::Justification::centredLeft);
  4278. }
  4279. }
  4280. if (! eqFolded && eqShown())
  4281. {
  4282. // the response graph: frequency (log) across, ±18 dB up and down
  4283. const auto graph = eqGraphBounds().toFloat();
  4284. theme::fillRoundRect (g, graph, radius::sm, colour::bg1);
  4285. g.setColour (colour::border);
  4286. g.drawRoundedRectangle (graph.reduced (0.5f), radius::sm, 1.0f);
  4287. const auto inner = graph.reduced (4.0f);
  4288. g.setColour (colour::gridBeat);
  4289. for (float hz : { 100.0f, 1000.0f, 10000.0f })
  4290. {
  4291. const auto x = inner.getX() + inner.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
  4292. g.drawVerticalLine ((int) x, inner.getY(), inner.getBottom());
  4293. }
  4294. g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
  4295. juce::Path curve;
  4296. const auto sampleRate = juce::jmax (8000.0, engine.getTransport().sampleRate.load());
  4297. for (int i = 0; i <= (int) inner.getWidth(); i += 2)
  4298. {
  4299. const auto hz = eqMinHz * std::pow (eqMaxHz / eqMinHz, (float) i / inner.getWidth());
  4300. const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, eqResponseDb (eq, hz, sampleRate));
  4301. const auto y = inner.getCentreY() - inner.getHeight() * 0.5f * db / eqRangeDb;
  4302. if (i == 0)
  4303. curve.startNewSubPath (inner.getX(), y);
  4304. else
  4305. curve.lineTo (inner.getX() + (float) i, y);
  4306. }
  4307. g.setColour (eq.active() ? colour::accent : colour::textSecondary.withAlpha (0.6f));
  4308. g.strokePath (curve, juce::PathStrokeType (1.5f));
  4309. for (int b = 0; b < 3; ++b)
  4310. {
  4311. const auto hot = hoverEq == eqPointBase - b || dragParam == eqPointBase - b;
  4312. const auto handle = eqHandle (b);
  4313. g.setColour (eqBandColour (b).withAlpha (hot ? 1.0f : 0.8f));
  4314. g.fillEllipse (juce::Rectangle<float> (hot ? 10.0f : 8.0f, hot ? 10.0f : 8.0f).withCentre (handle));
  4315. }
  4316. // the gain faders (one per band) and the frequency / width knobs under them
  4317. for (int b = 0; b < 3; ++b)
  4318. {
  4319. const auto fader = eqFaderBounds (b).toFloat();
  4320. const auto hot = hoverEq == eqParamBase - b * 3 || dragParam == eqParamBase - b * 3;
  4321. theme::fillRoundRect (g, fader.withSizeKeepingCentre (3.0f, fader.getHeight() - 6.0f), 1.5f, colour::bg0);
  4322. g.setColour (colour::border);
  4323. g.drawHorizontalLine ((int) fader.getCentreY(), fader.getX() + 2.0f, fader.getRight() - 2.0f);
  4324. const auto v = eqToValue (eq, b, 0);
  4325. const auto y = fader.getBottom() - 6.0f - v * (fader.getHeight() - 12.0f);
  4326. theme::fillRoundRect (g, juce::Rectangle<float> (fader.getWidth() - 2.0f, 7.0f).withCentre ({ fader.getCentreX(), y }), 2.0f, hot ? colour::textPrimary : colour::textSecondary);
  4327. g.setColour (eqBandColour (b));
  4328. g.fillRect (juce::Rectangle<float> (fader.getWidth() - 6.0f, 1.5f).withCentre ({ fader.getCentreX(), y }));
  4329. for (int what = 1; what <= 2; ++what)
  4330. {
  4331. const auto code = eqParamBase - b * 3 - what;
  4332. drawKnob (g, eqKnobBounds (b, what).toFloat().reduced (2.0f), eqToValue (eq, b, what), false, eqBandColour (b),
  4333. hoverEq == code || dragParam == code);
  4334. }
  4335. }
  4336. // the knob captions take the width their (translated) text needs, the title gives way (round 165o)
  4337. const juce::Font captionFont (font (type::caption));
  4338. const auto captionWidth = juce::jlimit (32, 70, (int) std::ceil (juce::jmax (juce::GlyphArrangement::getStringWidth (captionFont, tr ("Freq")),
  4339. juce::GlyphArrangement::getStringWidth (captionFont, tr ("Width")))) + 2);
  4340. g.setColour (colour::textSecondary);
  4341. g.setFont (font (type::title));
  4342. textcache::drawText (g, tr ("Equalizer"), 10, eqGraphBounds().getBottom() + 4, eqKnobBounds (0, 1).getX() - 8 - captionWidth, 20,
  4343. juce::Justification::centredLeft);
  4344. g.setFont (captionFont);
  4345. g.setColour (colour::textDisabled);
  4346. textcache::drawText (g, tr ("Freq"), eqKnobBounds (0, 1).getX() - 2 - captionWidth, eqKnobBounds (0, 1).getY(), captionWidth, 22,
  4347. juce::Justification::centredRight);
  4348. textcache::drawText (g, tr ("Width"), eqKnobBounds (0, 2).getX() - 2 - captionWidth, eqKnobBounds (0, 2).getY(), captionWidth, 22,
  4349. juce::Justification::centredRight);
  4350. }
  4351. // the audio output target
  4352. auto box = outputBounds().toFloat();
  4353. g.setColour (colour::border);
  4354. g.fillRect (8, (int) box.getY() - 5, getWidth() - 16, 1);
  4355. icons::draw (g, Icon::exportAudio, juce::Rectangle<float> (10.0f, box.getY(), 18.0f, box.getHeight()).withSizeKeepingCentre (16.0f, 16.0f),
  4356. colour::textSecondary);
  4357. theme::fillRoundRect (g, box, radius::sm, hoverOutput ? colour::bg4 : colour::bg3);
  4358. g.setColour (hoverOutput ? colour::borderStrong : colour::border);
  4359. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  4360. g.setColour (track == 0 ? colour::textPrimary : colour::textSecondary);
  4361. g.setFont (font (type::body));
  4362. textcache::drawText (g, outputName(), box.withTrimmedLeft (8.0f).withTrimmedRight (18.0f).toNearestInt(), juce::Justification::centredLeft, true);
  4363. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, 0.0f), colour::textSecondary);
  4364. }
  4365. juce::String EffectsPanel::outputName() const
  4366. {
  4367. if (track == 0 && const_cast<AudioEngine&> (engine).getDeviceManager().getCurrentAudioDevice() == nullptr)
  4368. return tr ("(no audio device)");
  4369. return mixeroutput::label (engine, track);
  4370. }
  4371. void EffectsPanel::showOutputMenu()
  4372. {
  4373. mixeroutput::showMenu (engine, track, this, localAreaToGlobal (outputBounds()));
  4374. }
  4375. namespace mixeroptions
  4376. {
  4377. std::function<void()> changed;
  4378. std::function<void (bool)> setShowUsedOnly;
  4379. std::function<void (bool)> setShowLoudness;
  4380. std::function<void (std::vector<int>, std::function<void (const std::vector<juce::File>&)>)> renderTracks;
  4381. namespace
  4382. {
  4383. void notifyChanged()
  4384. {
  4385. if (changed)
  4386. changed();
  4387. }
  4388. void askNumber (const juce::String& title, const juce::String& text, int value, int lo, int hi, std::function<void (int)> done)
  4389. {
  4390. auto* w = new juce::AlertWindow (title, text, juce::MessageBoxIconType::NoIcon);
  4391. w->addTextEditor ("n", juce::String (value));
  4392. w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  4393. w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  4394. w->enterModalState (true, juce::ModalCallbackFunction::create ([w, lo, hi, done = std::move (done)] (int result) {
  4395. if (result == 1)
  4396. done (juce::jlimit (lo, hi, w->getTextEditorContents ("n").trim().getIntValue()));
  4397. }), true);
  4398. }
  4399. } // namespace
  4400. void addItems (juce::PopupMenu& menu, AudioEngine& engine, bool newProjects)
  4401. {
  4402. const auto& song = engine.getSong();
  4403. menu.addItem (tr ("Clean mixer: no built-in EQ on the inserts (this project)"), true, song.cleanMixer, [&engine] {
  4404. const auto on = ! engine.getSong().cleanMixer;
  4405. engine.editSong ([on] (Song& s) { s.cleanMixer = on; });
  4406. const auto& mixer = engine.getSong().mixer;
  4407. const auto withEq = std::count_if (mixer.begin(), mixer.end(), [] (const MixerTrack& t) { return t.eq.active(); });
  4408. if (on && withEq > 0) // nothing is lost: switching it off brings the EQ back as it was
  4409. 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);
  4410. });
  4411. // LYNX option (round 190y): the old cheap mute; FL keeps a muted insert's effects running (and showing its level)
  4412. menu.addItem (tr ("Muted inserts don't process (LYNX, saves CPU; this project)"), true, song.mutedInsertsSkip, [&engine] {
  4413. const auto on = ! engine.getSong().mutedInsertsSkip;
  4414. engine.editSong ([on] (Song& s) { s.mutedInsertsSkip = on; });
  4415. if (on)
  4416. 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);
  4417. });
  4418. menu.addItem (tr ("Show only used inserts"), true, MixerStrips::showUsedOnly, [] {
  4419. const auto on = ! MixerStrips::showUsedOnly;
  4420. if (setShowUsedOnly)
  4421. setShowUsedOnly (on);
  4422. else
  4423. MixerStrips::showUsedOnly = on;
  4424. notifyChanged();
  4425. });
  4426. // LYNX's own (round 190am; off = FL's mixer): the Master's loudness in LUFS and its true peak, beside the Master
  4427. menu.addItem (tr ("Loudness meter beside the Master (LYNX)"), true, MixerStrips::showLoudness, [] {
  4428. const auto on = ! MixerStrips::showLoudness;
  4429. if (setShowLoudness)
  4430. setShowLoudness (on);
  4431. else
  4432. MixerStrips::showLoudness = on;
  4433. notifyChanged();
  4434. });
  4435. menu.addItem (tr ("Remove unused inserts at the end"), song.mixer.size() > 1 && ! song.insertInUse ((int) song.mixer.size() - 1), false, [&engine] {
  4436. int removed = 0;
  4437. engine.editSong ([&removed] (Song& s) { removed = mixerops::removeUnusedTrailingInserts (s); });
  4438. ui::postHint ({ tr ("Removed {0} unused insert(s)", { juce::String (removed) }), {}, false, false }, 3000);
  4439. });
  4440. // LYNX's option (round 186c, pain point 1; off = FL, which drops them): a deleted insert's incoming sends stay greyed
  4441. menu.addItem (tr ("Keep links to deleted inserts, greyed (LYNX)"), true, MixerStrips::keepLostLinks, [] {
  4442. MixerStrips::keepLostLinks = ! MixerStrips::keepLostLinks;
  4443. notifyChanged();
  4444. });
  4445. // LYNX's addition (round 186c, pain point 4; off by default): the mixer's groups mirror the Playlist's track groups
  4446. menu.addItem (tr ("Mixer groups follow the Playlist (LYNX)"), true, MixerStrips::followPlaylist, [&engine] {
  4447. MixerStrips::followPlaylist = ! MixerStrips::followPlaylist;
  4448. if (MixerStrips::followPlaylist)
  4449. engine.editSong ([] (Song& s) { mixerops::followPlaylistGroups (s); });
  4450. notifyChanged();
  4451. });
  4452. menu.addItem (tr ("Arrange inserts like the Playlist"), ! mixerops::playlistOrderInserts (song).empty(), false, [&engine] {
  4453. int moved = 0;
  4454. engine.editSongStructural ([&moved] (Song& s) { moved = mixerops::arrangeLikePlaylist (s); });
  4455. ui::postHint ({ tr ("{0} insert(s) moved to follow the Playlist", { juce::String (moved) }), {}, false, false }, 3000);
  4456. });
  4457. if (! newProjects)
  4458. return;
  4459. auto& d = newProjectDefaults();
  4460. menu.addSectionHeader (tr ("New projects"));
  4461. {
  4462. juce::PopupMenu inserts;
  4463. bool listed = false;
  4464. for (int n : { 0, 1, 2, 4, 8, 12, 16, 24, 32, 48, 64, 100, 125 })
  4465. {
  4466. listed = listed || n == d.inserts;
  4467. inserts.addItem (n == NewProjectDefaults::defaultInserts ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.inserts, [n] {
  4468. newProjectDefaults().inserts = n;
  4469. notifyChanged();
  4470. });
  4471. }
  4472. inserts.addItem (listed ? tr ("Other...") : tr ("Other ({0})...", { juce::String (d.inserts) }), true, ! listed, [] {
  4473. askNumber (tr ("Inserts in new projects"),
  4474. tr ("How many mixer inserts a new project starts with (0 to {0}). More are added when you need them.", { juce::String (maxMixerTracks - 1) }),
  4475. newProjectDefaults().inserts, 0, maxMixerTracks - 1, [] (int n) {
  4476. newProjectDefaults().inserts = n;
  4477. notifyChanged();
  4478. });
  4479. });
  4480. menu.addSubMenu (tr ("Inserts in new projects ({0})", { juce::String (d.inserts) }), inserts);
  4481. }
  4482. {
  4483. juce::PopupMenu chain;
  4484. const std::pair<const char*, MasterChain> chains[] = { { TR_NOOP ("Empty (nothing on the Master)"), MasterChain::empty },
  4485. { TR_NOOP ("Soft clipper only"), MasterChain::clipper },
  4486. { TR_NOOP ("LYNX SHARE default (limiter)"), MasterChain::lynxDefault } };
  4487. for (const auto& [label, c] : chains)
  4488. chain.addItem (tr (label), true, d.master == c, [c = c] {
  4489. newProjectDefaults().master = c;
  4490. notifyChanged();
  4491. });
  4492. menu.addSubMenu (tr ("Master chain in new projects"), chain);
  4493. }
  4494. menu.addItem (tr ("Clean mixer in new projects (no built-in EQ)"), true, d.cleanMixer, [] {
  4495. newProjectDefaults().cleanMixer = ! newProjectDefaults().cleanMixer;
  4496. notifyChanged();
  4497. });
  4498. {
  4499. juce::PopupMenu tracks;
  4500. for (int n : { 4, 8, 16, 24, 32, 64, 100 })
  4501. tracks.addItem (n == 16 ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.playlistTracks, [n] {
  4502. newProjectDefaults().playlistTracks = n;
  4503. notifyChanged();
  4504. });
  4505. menu.addSubMenu (tr ("Playlist tracks shown ({0})", { juce::String (d.playlistTracks) }), tracks);
  4506. }
  4507. }
  4508. } // namespace mixeroptions
  4509. namespace mixeroutput
  4510. {
  4511. namespace
  4512. {
  4513. juce::String modeSuffix (OutputMode mode)
  4514. {
  4515. switch (mode)
  4516. {
  4517. case OutputMode::stereo: return {};
  4518. case OutputMode::monoSum: return " " + tr ("(mono)");
  4519. case OutputMode::monoLeft: return " " + tr ("(mono, L)");
  4520. case OutputMode::monoRight: return " " + tr ("(mono, R)");
  4521. }
  4522. return {};
  4523. }
  4524. } // namespace
  4525. bool isCustom (const AudioEngine& engine, int track)
  4526. {
  4527. const auto& mixer = engine.getSong().mixer;
  4528. if (track < 0 || track >= (int) mixer.size())
  4529. return false;
  4530. const auto channel = mixer[(std::size_t) track].outputChannel;
  4531. return track == 0 ? channel != outputDefault : channel >= 0;
  4532. }
  4533. juce::String label (const AudioEngine& engine, int track, bool compact)
  4534. {
  4535. const auto& mixer = engine.getSong().mixer;
  4536. if (track < 0 || track >= (int) mixer.size())
  4537. return {};
  4538. const auto& mt = mixer[(std::size_t) track];
  4539. auto channel = mt.outputChannel;
  4540. auto mode = mt.outputMode;
  4541. if (track == 0 && channel == outputDefault)
  4542. channel = 0, mode = OutputMode::stereo;
  4543. if (channel < 0)
  4544. return tr ("(none)");
  4545. const auto names = engine.getOutputChannelNames();
  4546. const auto missing = ! outputAvailable (channel, mode, (int) names.size())
  4547. || ! engine.isOutputChannelOpen (channel) || (mode == OutputMode::stereo && ! engine.isOutputChannelOpen (channel + 1));
  4548. if (compact) // the strip badge: the channel numbers only
  4549. {
  4550. auto text = juce::String::fromUTF8 ("\xe2\x86\x92 ") + juce::String (channel + 1);
  4551. if (mode == OutputMode::stereo)
  4552. text << "-" << (channel + 2);
  4553. else
  4554. text << (mode == OutputMode::monoLeft ? " L" : mode == OutputMode::monoRight ? " R" : " m");
  4555. return missing ? text + " ?" : text;
  4556. }
  4557. auto nameOf = [&] (int c) {
  4558. return c < (int) names.size() ? juce::String::fromUTF8 (names[(std::size_t) c].c_str()) : tr ("Out {0}", { juce::String (c + 1) });
  4559. };
  4560. auto text = mode == OutputMode::stereo ? nameOf (channel) + " - " + nameOf (channel + 1) : nameOf (channel);
  4561. text += modeSuffix (mode);
  4562. if (missing)
  4563. text += " " + tr ("(missing)");
  4564. return text;
  4565. }
  4566. void showMenu (AudioEngine& engine, int track, juce::Component* target, juce::Rectangle<int> screenArea)
  4567. {
  4568. const auto& mixer = engine.getSong().mixer;
  4569. if (track < 0 || track >= (int) mixer.size())
  4570. return;
  4571. const auto& mt = mixer[(std::size_t) track];
  4572. const auto names = engine.getOutputChannelNames();
  4573. const auto custom = isCustom (engine, track);
  4574. juce::PopupMenu menu;
  4575. menu.addSectionHeader (tr ("Audio output target"));
  4576. auto set = [&engine, track] (int channel, OutputMode mode) {
  4577. return [&engine, track, channel, mode] { engine.setTrackOutput (track, channel, mode); };
  4578. };
  4579. if (track == 0)
  4580. {
  4581. const auto first = names.size() >= 2 ? juce::String::fromUTF8 (names[0].c_str()) + " - " + juce::String::fromUTF8 (names[1].c_str())
  4582. : tr ("first output pair");
  4583. menu.addItem (first + " " + tr ("(default)"), true, mt.outputChannel == outputDefault, set (outputDefault, OutputMode::stereo));
  4584. menu.addItem (tr ("(none)"), true, mt.outputChannel == outputNone, set (outputNone, OutputMode::stereo));
  4585. }
  4586. else
  4587. menu.addItem (tr ("(none) - through the Master only"), true, ! custom, set (outputDefault, OutputMode::stereo));
  4588. if (custom && (track > 0 || mt.outputChannel >= 0))
  4589. menu.addItem (label (engine, track), true, true, nullptr); // the current target (also when missing)
  4590. // the optional direct outputs: stereo pairs, then every channel alone
  4591. juce::PopupMenu direct;
  4592. direct.addItem (track == 0 ? tr ("Optional: send the Master to other outputs of your audio interface")
  4593. : tr ("Optional: also send this insert straight to an output of your audio interface, e.g. a mono output"),
  4594. false, false, nullptr);
  4595. if (names.empty())
  4596. direct.addItem (tr ("No audio device is open"), false, false, nullptr);
  4597. const auto targets = outputTargets (names);
  4598. auto pairsHeader = false, monoHeader = false;
  4599. for (const auto& t : targets)
  4600. {
  4601. const auto name = juce::String::fromUTF8 (t.name.c_str());
  4602. if (t.mode == OutputMode::stereo)
  4603. {
  4604. if (! std::exchange (pairsHeader, true))
  4605. direct.addSectionHeader (tr ("Stereo pair"));
  4606. direct.addItem (name, true, mt.outputChannel == t.channel && mt.outputMode == OutputMode::stereo, set (t.channel, OutputMode::stereo));
  4607. continue;
  4608. }
  4609. if (! std::exchange (monoHeader, true))
  4610. direct.addSectionHeader (tr ("Mono (one output)"));
  4611. const auto here = mt.outputChannel == t.channel && mt.outputMode != OutputMode::stereo;
  4612. juce::PopupMenu modes;
  4613. modes.addItem (tr ("Sum of L + R (mono)"), true, here && mt.outputMode == OutputMode::monoSum, set (t.channel, OutputMode::monoSum));
  4614. modes.addItem (tr ("Left side only"), true, here && mt.outputMode == OutputMode::monoLeft, set (t.channel, OutputMode::monoLeft));
  4615. modes.addItem (tr ("Right side only"), true, here && mt.outputMode == OutputMode::monoRight, set (t.channel, OutputMode::monoRight));
  4616. direct.addSubMenu (name, modes, true, nullptr, here);
  4617. }
  4618. if (! names.empty() && names.size() <= 2)
  4619. direct.addItem (tr ("This audio device has 2 outputs; an interface with more outputs lists all of them here"), false, false, nullptr);
  4620. menu.addSeparator();
  4621. menu.addSubMenu (track == 0 ? tr ("Hardware output") : tr ("Send to hardware output (optional)"), direct, true, nullptr, custom && mt.outputChannel >= 0);
  4622. if (custom)
  4623. menu.addItem (track == 0 ? tr ("Back to the default output") : tr ("Back to Master only"), set (outputDefault, OutputMode::stereo));
  4624. menu.addSeparator();
  4625. menu.addItem (tr ("Audio settings..."), [] {
  4626. if (mixerinput::openAudioSettings)
  4627. mixerinput::openAudioSettings();
  4628. });
  4629. auto options = juce::PopupMenu::Options();
  4630. if (target != nullptr)
  4631. options = options.withTargetComponent (target);
  4632. if (! screenArea.isEmpty())
  4633. options = options.withTargetScreenArea (screenArea);
  4634. else if (target != nullptr)
  4635. options = options.withMousePosition();
  4636. menu.showMenuAsync (options);
  4637. }
  4638. } // namespace mixeroutput
  4639. juce::Rectangle<int> EffectsPanel::slotBounds (int slot) const
  4640. {
  4641. return { 8, slotsTop + slot * slotHeight, getWidth() - 16, slotHeight - 3 };
  4642. }
  4643. namespace
  4644. {
  4645. // parameters shown as knobs: in the rhythmic envelope, only those of the points in use
  4646. int shownParams (const EffectSlot& slot)
  4647. {
  4648. const auto all = (int) effectInfo (slot.kind).params.size();
  4649. if (slot.kind == EffectKind::rhythmGain)
  4650. return std::min (all, 2 + 3 * (int) std::lround (slot.params[1] * 12.0f));
  4651. if (slot.kind == EffectKind::lynxTune) // the note switches are the keyboard strip above the knobs
  4652. return std::min (all, (int) lynxtune::noteC);
  4653. return all;
  4654. }
  4655. } // namespace
  4656. juce::Rectangle<int> EffectsPanel::knobBounds (int param) const
  4657. {
  4658. return knobBoundsIn (param, bottomTop());
  4659. }
  4660. juce::Rectangle<int> EffectsPanel::knobBoundsIn (int param, int areaBottom) const
  4661. {
  4662. auto top = slotsTop + maxEffectSlots * slotHeight + 40;
  4663. // many parameters (Effector: 12): 4 columns and shorter rows to fit the height
  4664. int count = 0;
  4665. if (const auto* s = slots(); ! gateSelected() && s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size())
  4666. count = shownParams ((*s)[(std::size_t) selectedSlot]);
  4667. const auto columns = count > 9 ? 4 : 3;
  4668. const auto w = (getWidth() - 16) / columns;
  4669. const auto rows = juce::jmax (1, (count + columns - 1) / columns);
  4670. const auto rowHeight = count > 9 ? juce::jlimit (64, 86, (areaBottom - top - 4) / rows) : 86;
  4671. // volume gate: the 32 steps are bars (gateStepsBounds); the knobs are mix/attack/release
  4672. if (gateSelected())
  4673. {
  4674. if (param < 32)
  4675. return {};
  4676. param -= 32;
  4677. top = gateStepsBounds().getBottom() + 22;
  4678. }
  4679. if (vocoderSelected()) // the band levels above the knobs
  4680. top = bandLevelsBounds().getBottom() + 22;
  4681. if (tuneSelected()) // LYNX Tune's note keyboard above the knobs
  4682. top = tuneKeysBounds().getBottom() + 22;
  4683. return { 8 + (param % columns) * w, top + (param / columns) * rowHeight, w, rowHeight - 4 };
  4684. }
  4685. int EffectsPanel::selectedEffectBottom() const
  4686. {
  4687. const auto slotsBottom = slotsTop + maxEffectSlots * slotHeight;
  4688. auto bottom = slotsBottom + 64; // the effect's title row
  4689. const auto* s = slots();
  4690. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
  4691. return bottom;
  4692. const auto& slot = (*s)[(std::size_t) selectedSlot];
  4693. if (slot.kind == EffectKind::plugin || isSoundgoodizerApprox (slot))
  4694. return juce::jmax (bottom, pluginButtonBounds().getBottom() + 34 + 40);
  4695. if (slot.kind == EffectKind::parametricEq || slot.kind == EffectKind::facetEq)
  4696. return juce::jmax (bottom, pluginButtonBounds().getBottom() + 10 + 120);
  4697. if (slot.kind == EffectKind::parallel)
  4698. return juce::jmax (bottom, knobBoundsIn (0, 0).getY() - 28 + 20 + 22 * (int) slot.branches.size());
  4699. const auto count = gateSelected() ? 35 : shownParams (slot);
  4700. for (int p = 0; p < count; ++p)
  4701. if (const auto r = knobBoundsIn (p, 0); ! r.isEmpty()) // (tight grids at their shortest rows)
  4702. bottom = juce::jmax (bottom, r.getY() + juce::jlimit (30, 44, r.getHeight() - 30) + 32); // knob, name, value
  4703. return bottom;
  4704. }
  4705. bool EffectsPanel::gateSelected() const
  4706. {
  4707. const auto* s = slots();
  4708. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::volumeGate;
  4709. }
  4710. juce::Rectangle<int> EffectsPanel::gateStepsBounds() const
  4711. {
  4712. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 90 };
  4713. }
  4714. void EffectsPanel::setGateStep (juce::Point<int> p)
  4715. {
  4716. const auto area = gateStepsBounds();
  4717. const auto step = juce::jlimit (0, 31, (int) ((p.x - area.getX()) * 32 / juce::jmax (1, area.getWidth())));
  4718. const auto value = juce::jlimit (0.0f, 1.0f, (float) (area.getBottom() - p.y) / (float) area.getHeight());
  4719. engine.editSong ([t = track, slot = selectedSlot, step, value] (Song& song) {
  4720. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) step] = value;
  4721. });
  4722. }
  4723. bool EffectsPanel::vocoderSelected() const
  4724. {
  4725. const auto* s = slots();
  4726. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::vocoder;
  4727. }
  4728. bool EffectsPanel::tuneSelected() const
  4729. {
  4730. const auto* s = slots();
  4731. return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::lynxTune;
  4732. }
  4733. juce::Rectangle<int> EffectsPanel::tuneKeysBounds() const
  4734. {
  4735. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 54 };
  4736. }
  4737. namespace
  4738. {
  4739. // LYNX Tune's keyboard strip: one octave, white keys in a row, black keys on top (C … B → key rectangles)
  4740. juce::Rectangle<float> tuneKeyRect (juce::Rectangle<float> area, int pc)
  4741. {
  4742. static constexpr int whiteIndex[12] { 0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, 6 };
  4743. static constexpr float blackAt[12] { 0, 1.0f, 0, 2.0f, 0, 0, 4.0f, 0, 5.0f, 0, 6.0f, 0 };
  4744. const auto w = area.getWidth() / 7.0f;
  4745. if (whiteIndex[pc] >= 0)
  4746. return { area.getX() + whiteIndex[pc] * w, area.getY(), w, area.getHeight() };
  4747. return { area.getX() + blackAt[pc] * w - w * 0.3f, area.getY(), w * 0.6f, area.getHeight() * 0.58f };
  4748. }
  4749. int tuneKeyAt (juce::Rectangle<float> area, juce::Point<float> p)
  4750. {
  4751. for (int pc = 0; pc < 12; ++pc) // black keys first: they lie on top
  4752. if ((pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10) && tuneKeyRect (area, pc).contains (p))
  4753. return pc;
  4754. for (int pc = 0; pc < 12; ++pc)
  4755. if (tuneKeyRect (area, pc).contains (p))
  4756. return pc;
  4757. return -1;
  4758. }
  4759. } // namespace
  4760. void EffectsPanel::toggleTuneNote (juce::Point<int> p)
  4761. {
  4762. const auto pc = tuneKeyAt (tuneKeysBounds().toFloat(), p.toFloat());
  4763. if (pc < 0)
  4764. return;
  4765. engine.editSong ([t = track, slot = selectedSlot, pc] (Song& song) {
  4766. auto& v = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) (lynxtune::noteC + pc)];
  4767. v = v >= 0.5f ? 0.0f : 1.0f;
  4768. });
  4769. }
  4770. juce::Rectangle<int> EffectsPanel::bandLevelsBounds() const
  4771. {
  4772. return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 70 };
  4773. }
  4774. namespace
  4775. {
  4776. // the Fruity Vocoder's state for the slot's current band count (levels kept while the count matches, as FL does)
  4777. fvocoder::State vocoderState (const EffectSlot& slot)
  4778. {
  4779. auto s = fvocoder::parse (slot.state).value_or (fvocoder::State());
  4780. const auto bands = 4 << std::clamp ((int) std::lround (slot.params[0] * 5.0f), 0, 5);
  4781. if (s.bands != bands)
  4782. {
  4783. s.bands = bands;
  4784. s.levels.fill (1.0f);
  4785. }
  4786. s.order = 1 + std::clamp ((int) std::lround (slot.params[1] * 2.0f), 0, 2);
  4787. s.listen = std::clamp ((int) std::lround (slot.params[2] * 2.0f), 0, 2);
  4788. s.swap = slot.params[3] > 0.5f;
  4789. for (int c = 0; c < fvocoder::controls; ++c)
  4790. s.c[(std::size_t) c] = fvocoder::rawFromKnob (slot.params[(std::size_t) (4 + c)], c, s.c[(std::size_t) c]);
  4791. return s;
  4792. }
  4793. constexpr float maxBandLevel = 2.0f; // the strip spans 0…2 (1 = unchanged)
  4794. } // namespace
  4795. void EffectsPanel::setBandLevel (juce::Point<int> p)
  4796. {
  4797. const auto* s = slots();
  4798. if (s == nullptr || ! vocoderSelected())
  4799. return;
  4800. const auto st = vocoderState ((*s)[(std::size_t) selectedSlot]);
  4801. const auto area = bandLevelsBounds();
  4802. const auto band = juce::jlimit (0, st.bands - 1, (int) ((p.x - area.getX()) * st.bands / juce::jmax (1, area.getWidth())));
  4803. auto level = juce::jlimit (0.0f, maxBandLevel, maxBandLevel * (float) (area.getBottom() - p.y) / (float) area.getHeight());
  4804. if (std::abs (level - 1.0f) < 0.04f)
  4805. level = 1.0f; // snaps to the unchanged level
  4806. engine.editSong ([t = track, slot = selectedSlot, band, level] (Song& song) {
  4807. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  4808. auto state = vocoderState (fx);
  4809. state.levels[(std::size_t) band] = level;
  4810. fx.state = fvocoder::serialise (state);
  4811. });
  4812. }
  4813. void EffectsPanel::showBandLevelMenu()
  4814. {
  4815. juce::PopupMenu menu;
  4816. auto apply = [this] (float (*level) (int, int)) {
  4817. engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
  4818. auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  4819. auto state = vocoderState (fx);
  4820. for (int k = 0; k < state.bands; ++k)
  4821. state.levels[(std::size_t) k] = level (k, state.bands);
  4822. fx.state = fvocoder::serialise (state);
  4823. });
  4824. };
  4825. menu.addItem (tr ("Reset band levels"), [apply] { apply ([] (int, int) { return 1.0f; }); });
  4826. menu.addItem (tr ("Brighter (tilt up)"), [apply] { apply ([] (int k, int n) { return 0.5f + (float) k / (float) std::max (1, n - 1); }); });
  4827. menu.addItem (tr ("Darker (tilt down)"), [apply] { apply ([] (int k, int n) { return 1.5f - (float) k / (float) std::max (1, n - 1); }); });
  4828. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  4829. }
  4830. void EffectsPanel::showGatePatterns()
  4831. {
  4832. // ready-made patterns (like Gross Beat's slots): value of step i of 32 (1/8 beat each)
  4833. struct Pattern
  4834. {
  4835. const char* name;
  4836. float (*level) (int);
  4837. };
  4838. static const Pattern patterns[] = {
  4839. { TR_NOOP ("All open"), [] (int) { return 1.0f; } },
  4840. { TR_NOOP ("1/2 beat gate"), [] (int i) { return (i % 4) < 2 ? 1.0f : 0.0f; } },
  4841. { TR_NOOP ("1 beat gate"), [] (int i) { return (i % 8) < 4 ? 1.0f : 0.0f; } },
  4842. { TR_NOOP ("Offbeat"), [] (int i) { return (i % 8) >= 4 ? 1.0f : 0.0f; } },
  4843. { TR_NOOP ("Sidechain (ramp per beat)"), [] (int i) { return std::min (1.0f, 0.15f + (float) (i % 8) / 5.0f); } },
  4844. { TR_NOOP ("Trance gate"), [] (int i) { return (i % 4) == 3 ? 0.0f : (i % 16) >= 12 ? 0.4f : 1.0f; } },
  4845. { TR_NOOP ("Fade-in over the bar"), [] (int i) { return (float) (i + 1) / 32.0f; } },
  4846. { TR_NOOP ("Fade-out over the bar"), [] (int i) { return 1.0f - (float) i / 32.0f; } },
  4847. };
  4848. juce::PopupMenu menu;
  4849. for (const auto& p : patterns)
  4850. menu.addItem (tr (p.name), [this, level = p.level] {
  4851. engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
  4852. auto& params = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params;
  4853. for (int i = 0; i < 32; ++i)
  4854. params[(std::size_t) i] = level (i);
  4855. });
  4856. });
  4857. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  4858. }
  4859. int EffectsPanel::knobAt (juce::Point<int> p) const
  4860. {
  4861. const auto* s = slots();
  4862. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
  4863. return -1;
  4864. if ((*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq || (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq)
  4865. return -1; // edited in its own window
  4866. const auto count = shownParams ((*s)[(std::size_t) selectedSlot]);
  4867. for (int i = gateSelected() ? 32 : 0; i < count; ++i)
  4868. if (knobBounds (i).contains (p))
  4869. return i;
  4870. return -1;
  4871. }
  4872. void EffectsPanel::paint (juce::Graphics& g)
  4873. {
  4874. const uitrace::Scope trace ("EffectsPanel paint", true, g.getClipBounds());
  4875. using namespace theme;
  4876. g.fillAll (colour::bg2);
  4877. g.setColour (colour::border);
  4878. g.drawVerticalLine (0, 0.0f, (float) getHeight());
  4879. const auto* s = slots();
  4880. if (s == nullptr)
  4881. return;
  4882. const auto& song = engine.getSong();
  4883. g.setColour (colour::textPrimary);
  4884. g.setFont (font (type::title, true));
  4885. textcache::drawText (g, tr ("Effects: {0}", { juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) }), 10, 4,
  4886. getWidth() - 70, panelHeader - 8, juce::Justification::centredLeft, true);
  4887. // input row: arm switch (inserts) and the audio input source with its level (the Master has one too, as in FL;
  4888. // REA round 143)
  4889. if (track >= 0 && track < (int) song.mixer.size())
  4890. {
  4891. const auto& mt = song.mixer[(std::size_t) track];
  4892. if (track > 0)
  4893. {
  4894. const auto armed = engine.isInsertArmed (track);
  4895. const auto a = armBounds().toFloat();
  4896. theme::fillRoundRect (g, a, radius::sm, armed ? colour::record.withAlpha (0.25f) : hoverInput == 1 ? colour::bg5 : colour::bg3);
  4897. const auto dot = a.withSizeKeepingCentre (11.0f, 11.0f);
  4898. g.setColour (armed ? colour::record : colour::bg0);
  4899. g.fillEllipse (dot);
  4900. g.setColour (armed ? colour::record.brighter (0.3f) : hoverInput == 1 ? colour::textSecondary : colour::borderStrong);
  4901. g.drawEllipse (dot, 1.0f);
  4902. if (mt.recordSafe)
  4903. {
  4904. g.setColour (colour::textDisabled);
  4905. g.drawLine (dot.getX() + 1.0f, dot.getBottom() - 1.0f, dot.getRight() - 1.0f, dot.getY() + 1.0f, 1.2f);
  4906. }
  4907. }
  4908. auto box = inputBoxBounds().toFloat();
  4909. theme::fillRoundRect (g, box, radius::sm, hoverInput == 2 ? colour::bg4 : colour::bg3);
  4910. g.setColour (hoverInput == 2 ? colour::borderStrong : colour::border);
  4911. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  4912. // the level, as a thin bar along the bottom of the box (left over right)
  4913. if (mt.inputChannel >= 0)
  4914. {
  4915. const auto bar = box.reduced (4.0f, 0.0f).withTop (box.getBottom() - 5.0f).withHeight (3.0f);
  4916. g.setColour (colour::bg0);
  4917. g.fillRect (bar);
  4918. for (int side = 0; side < 2; ++side)
  4919. {
  4920. const auto db = juce::Decibels::gainToDecibels (inputLevel[(std::size_t) side], -60.0f);
  4921. const auto fill = juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 60.0f);
  4922. g.setColour (inputLevel[(std::size_t) side] >= 0.99f ? colour::record : colour::meterLow);
  4923. g.fillRect (bar.withHeight (1.5f).translated (0.0f, side * 1.5f).withWidth (bar.getWidth() * fill));
  4924. }
  4925. }
  4926. icons::draw (g, Icon::mic, box.withWidth (18.0f).reduced (2.0f).translated (3.0f, -1.0f), mt.inputChannel >= 0 ? colour::textPrimary : colour::textDisabled);
  4927. const auto names = engine.getInputChannelNames();
  4928. const auto label = mt.inputChannel >= 0 ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, names).c_str())
  4929. : tr ("No audio input");
  4930. g.setColour (mt.inputChannel >= 0 ? colour::textPrimary : colour::textSecondary);
  4931. g.setFont (font (type::body));
  4932. textcache::drawText (g, label, box.withTrimmedLeft (24.0f).withTrimmedRight (18.0f).translated (0.0f, -1.0f).toNearestInt(), juce::Justification::centredLeft, true);
  4933. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, -1.0f), colour::textSecondary);
  4934. }
  4935. // the insert's effects switch
  4936. if (! s->empty())
  4937. {
  4938. const auto on = mixerops::anyEffectEnabled (song, track);
  4939. const auto r = fxSwitchBounds().toFloat();
  4940. theme::fillRoundRect (g, r, radius::sm, on ? colour::bg5 : colour::bg0);
  4941. g.setColour (muteLed (! on));
  4942. g.fillEllipse (r.withWidth (r.getHeight()).reduced (6.0f).translated (3.0f, 0.0f));
  4943. g.setColour (on ? colour::textPrimary : colour::textDisabled);
  4944. g.setFont (font (type::caption, true));
  4945. textcache::drawText (g, "FX", r.withTrimmedLeft (r.getHeight()).toNearestInt(), juce::Justification::centredLeft);
  4946. }
  4947. g.setFont (font (type::body));
  4948. // the 10 slots, as FL draws them: options arrow, name ("Slot N" when empty), mix knob, LED
  4949. // (rows: FL's slot places, an effect may sit below empty slots, round 170b)
  4950. for (int row = 0; row < maxEffectSlots; ++row)
  4951. {
  4952. const auto i = effectIn (row); // the effect shown here, -1 = empty
  4953. const auto r = slotBounds (row);
  4954. const auto filled = i >= 0;
  4955. const auto isSelected = i == selectedSlot && filled;
  4956. const auto slotHovered = row == hoverSlot && dragSlot < 0;
  4957. theme::fillRoundRect (g, r.toFloat(), radius::sm, isSelected ? colour::bg5 : filled ? (slotHovered ? colour::bg4 : colour::bg3) : (slotHovered ? colour::bg3 : colour::bg2.brighter (0.03f)));
  4958. g.setColour (slotHovered ? colour::borderStrong : colour::border);
  4959. g.drawRoundedRectangle (r.toFloat().reduced (0.5f), radius::sm, 1.0f);
  4960. if (isSelected)
  4961. {
  4962. theme::fillRoundRect (g, r.toFloat().withWidth (3.0f).reduced (0.0f, 3.0f), 1.5f, colour::accent);
  4963. }
  4964. {
  4965. const auto a = arrowBounds (row).toFloat().withSizeKeepingCentre (5.0f, 8.0f).translated (1.0f, 0.0f);
  4966. juce::Path tri;
  4967. tri.addTriangle (a.getX(), a.getY(), a.getRight(), a.getCentreY(), a.getX(), a.getBottom());
  4968. g.setColour (slotHovered && hoverArrow ? colour::textPrimary : colour::textSecondary.withAlpha (filled ? 1.0f : 0.6f));
  4969. g.fillPath (tri);
  4970. }
  4971. const auto ledArea = ledBounds (row).toFloat().withSizeKeepingCentre (8.0f, 8.0f);
  4972. const auto textArea = r.withTrimmedLeft (20).withTrimmedRight (46);
  4973. if (filled)
  4974. {
  4975. const auto& slot = (*s)[(std::size_t) i];
  4976. // "Low latency while recording" (round 190aq): a slot it bypasses now keeps its LED's place as an amber
  4977. // ring, its name dims and a badge says why; the slot's own on / off state is untouched
  4978. const auto lowLatency = engine.isSlotLowLatencyBypassed (track, i);
  4979. if (lowLatency)
  4980. {
  4981. g.setColour (colour::warning);
  4982. g.drawEllipse (ledArea.reduced (0.75f), 1.5f);
  4983. }
  4984. else
  4985. {
  4986. g.setColour (muteLed (! slot.enabled));
  4987. g.fillEllipse (ledArea);
  4988. }
  4989. if (slotHovered && hoverLed)
  4990. {
  4991. g.setColour (colour::textSecondary);
  4992. g.drawEllipse (ledArea.expanded (2.0f), 1.0f);
  4993. }
  4994. g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
  4995. // a LYNX substitute shows the plugin it stands in for, with a "LYNX" badge
  4996. const auto substitute = slot.isSubstitute();
  4997. auto name = quickpick::slotName (engine, slot); // (a plugin renamed in the Plugin database: its new name, round 165c)
  4998. if (slot.look != 0) // part of a Master look (round 189k, the Simple workflow's Finish dock)
  4999. name << " " << tr ("(look)");
  5000. if (goals::active (slot)) // a one-knob effect of the Simple workflow's dock (round 190bu): its goal's name too
  5001. name << " (" << (slot.goal == goals::punch ? trc ("@one-knob effect: Punch") : tr (goals::name (slot.goal))) << ")";
  5002. if (slot.sidechain > 0 && slot.sidechain < (int) engine.getSong().mixer.size())
  5003. name << juce::String::fromUTF8 (" \xe2\x86\x90 ") << juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) slot.sidechain].name.c_str());
  5004. auto text = textArea;
  5005. if (substitute)
  5006. {
  5007. const auto badge = text.removeFromRight (34).withSizeKeepingCentre (32, 14).toFloat();
  5008. const auto playing = engine.getSong().slotActive (slot); // off while the project's substitutes are bypassed
  5009. theme::fillRoundRect (g, badge, 3.0f, colour::info.withAlpha (playing ? 0.25f : 0.12f));
  5010. g.setColour (playing ? colour::info : colour::textDisabled);
  5011. const auto keep = g.getCurrentFont();
  5012. g.setFont (font (type::caption, true));
  5013. textcache::drawText (g, "LYNX", badge, juce::Justification::centred);
  5014. g.setFont (keep);
  5015. g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
  5016. }
  5017. if (lowLatency)
  5018. {
  5019. const auto label = tr ("LOW LAT");
  5020. const auto keep = g.getCurrentFont();
  5021. g.setFont (font (type::caption, true));
  5022. const auto width = juce::jmin (text.getWidth() / 2, juce::jmax (30, juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), label) + 8));
  5023. const auto badge = text.removeFromRight (width + 2).withSizeKeepingCentre (width, 14).toFloat();
  5024. theme::fillRoundRect (g, badge, 3.0f, colour::warning.withAlpha (0.22f));
  5025. g.setColour (colour::warning);
  5026. textcache::drawText (g, label, badge, juce::Justification::centred);
  5027. g.setFont (keep);
  5028. g.setColour (colour::textDisabled);
  5029. }
  5030. textcache::drawText (g, name, text, juce::Justification::centredLeft);
  5031. // slot's dry/wet knob
  5032. const auto mixActive = (hoverParam == mixParam && hoverSlot == row) || (dragParam == mixParam && selectedSlot == i);
  5033. drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), slot.mix, false,
  5034. slot.enabled ? (dragParam == mixParam && selectedSlot == i ? colour::accent : colour::info) : colour::textDisabled, mixActive);
  5035. }
  5036. else
  5037. {
  5038. // an empty slot keeps its controls in place (dimmed), as FL shows them
  5039. g.setColour (muteLed (false).withAlpha (0.3f));
  5040. g.fillEllipse (ledArea);
  5041. drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), 1.0f, false, colour::textDisabled.withAlpha (0.5f), false);
  5042. g.setColour (slotHovered ? colour::textSecondary : colour::textDisabled);
  5043. g.setFont (juce::Font (font (type::body)).italicised());
  5044. textcache::drawText (g, tr ("Slot {0}", { juce::String (row + 1) }), textArea, juce::Justification::centredLeft);
  5045. g.setFont (font (type::body));
  5046. }
  5047. }
  5048. paintEq (g);
  5049. g.reduceClipRegion (0, 0, getWidth(), bottomTop() - 6); // the selected effect's knobs stay above the EQ
  5050. if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot)) // where the dragged slot lands (FL: swaps with
  5051. { // the effect there, or takes the empty slot)
  5052. g.setColour (colour::accent);
  5053. g.drawRoundedRectangle (slotBounds (dropSlot).toFloat().reduced (0.5f), radius::sm, 2.0f);
  5054. }
  5055. if (selectedSlot < 0 || selectedSlot >= (int) s->size())
  5056. return;
  5057. const auto& slot = (*s)[(std::size_t) selectedSlot];
  5058. auto drawButton = [&g] (juce::Rectangle<int> button, const juce::String& text, Icon icon) {
  5059. theme::fillRoundRect (g, button.toFloat(), radius::md, colour::bg4);
  5060. const auto f = juce::Font (font (type::body));
  5061. const auto textWidth = juce::GlyphArrangement::getStringWidth (f, text);
  5062. auto content = button.toFloat().withSizeKeepingCentre (juce::jmin ((float) button.getWidth() - 12.0f, textWidth + 22.0f), (float) button.getHeight());
  5063. icons::draw (g, icon, content.removeFromLeft (16.0f).withSizeKeepingCentre (16.0f, 16.0f), colour::textSecondary);
  5064. content.removeFromLeft (6.0f);
  5065. g.setColour (colour::textPrimary);
  5066. g.setFont (f);
  5067. textcache::drawFittedText (g, text, content.toNearestInt(), juce::Justification::centredLeft, 1, 0.85f);
  5068. };
  5069. if (slot.kind == EffectKind::plugin)
  5070. {
  5071. const auto button = pluginButtonBounds();
  5072. drawButton (button, tr ("Open plugin interface"), Icon::plugin);
  5073. g.setColour (colour::textSecondary);
  5074. g.setFont (font (type::caption));
  5075. textcache::drawText (g, quickpick::slotName (engine, slot), button.translated (0, 34), juce::Justification::centred);
  5076. paintSidechainButton (g, slot);
  5077. return;
  5078. }
  5079. if (slot.kind == EffectKind::parametricEq)
  5080. {
  5081. const auto button = pluginButtonBounds();
  5082. drawButton (button, tr ("Open parametric EQ"), Icon::settings);
  5083. const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
  5084. drawParametricEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
  5085. return;
  5086. }
  5087. if (isSoundgoodizerApprox (slot)) // approximated without FL's preset files: its page edits Preset and Amount
  5088. {
  5089. const auto button = pluginButtonBounds();
  5090. drawButton (button, tr ("Open Soundgoodizer"), Icon::settings);
  5091. g.setColour (colour::textSecondary);
  5092. g.setFont (font (type::caption));
  5093. textcache::drawFittedText (g, tr ("Approximation (FL Studio's Soundgoodizer presets were not found on this computer)"),
  5094. button.translated (0, 34).withHeight (40), juce::Justification::centredTop, 2);
  5095. return;
  5096. }
  5097. if (slot.kind == EffectKind::facetEq)
  5098. {
  5099. const auto button = pluginButtonBounds();
  5100. drawButton (button, tr ("Open Facet EQ"), Icon::settings);
  5101. const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
  5102. drawFacetEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
  5103. return;
  5104. }
  5105. if (slot.kind == EffectKind::parallel) // container: list the branches
  5106. {
  5107. auto y = knobBounds (0).getY() - 28;
  5108. g.setColour (colour::textPrimary);
  5109. g.setFont (font (type::title, true));
  5110. textcache::drawText (g, juce::String::fromUTF8 (effectInfo (slot.kind).name), 10, y, getWidth() - 20, 20, juce::Justification::centredLeft);
  5111. g.setFont (font (type::small));
  5112. for (std::size_t b = 0; b < slot.branches.size(); ++b)
  5113. {
  5114. y += 22;
  5115. juce::String chain;
  5116. if (slot.branches[b].chain.empty())
  5117. chain = tr ("dry");
  5118. for (std::size_t c = 0; c < slot.branches[b].chain.size(); ++c)
  5119. chain += (c > 0 ? " -> " : "") + juce::String::fromUTF8 (effectInfo (slot.branches[b].chain[c].kind).name);
  5120. const auto line = tr ("Branch {0} (x{1}): {2}", { juce::String ((int) b + 1), juce::String (slot.branches[b].gain, 2), chain });
  5121. g.setColour (colour::textSecondary);
  5122. textcache::drawText (g, line, 14, y, getWidth() - 28, 20, juce::Justification::centredLeft, true);
  5123. }
  5124. return;
  5125. }
  5126. const auto& info = effectInfo (slot.kind);
  5127. const auto gate = slot.kind == EffectKind::volumeGate;
  5128. const auto vocoder = slot.kind == EffectKind::vocoder;
  5129. g.setColour (colour::textPrimary);
  5130. g.setFont (font (type::title, true));
  5131. const auto tune = slot.kind == EffectKind::lynxTune;
  5132. const auto editorButton = ! gate && ! vocoder && NativeEffectWindows::canOpen (slot.kind);
  5133. const auto titleY = (gate ? gateStepsBounds().getY() : vocoder ? bandLevelsBounds().getY() : tune ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 28;
  5134. const auto scButton = sidechainButtonBounds();
  5135. const auto titleRight = scButton.isEmpty() ? getWidth() - 10 - (editorButton ? editorButtonBounds().getWidth() + 6 : 0) : scButton.getX() - 6;
  5136. textcache::drawText (g, juce::String::fromUTF8 (info.name), 10, titleY, titleRight - 10, 20, juce::Justification::centredLeft, true);
  5137. if (slot.isSubstitute()) // which missing plugin this stands in for (the project keeps it)
  5138. {
  5139. const auto titleWidth = juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), juce::String::fromUTF8 (info.name));
  5140. g.setColour (colour::info);
  5141. g.setFont (font (type::caption));
  5142. const auto original = juce::String::fromUTF8 (substituteOriginalName (slot).c_str());
  5143. textcache::drawText (g, engine.getSong().substitutesBypassed ? tr ("LYNX SHARE substitute for {0} (bypassed)", { original }) : tr ("LYNX SHARE substitute for {0}", { original }),
  5144. 10 + titleWidth + 10, titleY,
  5145. juce::jmax (0, titleRight - 20 - titleWidth), 20, juce::Justification::centredLeft, true);
  5146. }
  5147. if (editorButton) // the effect's own window (FL's plugin window)
  5148. {
  5149. const auto b = editorButtonBounds().toFloat();
  5150. const auto hover = getMouseXYRelative().toFloat();
  5151. theme::fillRoundRect (g, b, radius::md, b.contains (hover) ? colour::bg5 : colour::bg4);
  5152. icons::draw (g, Icon::plugin, b.withWidth (22.0f).withSizeKeepingCentre (13.0f, 13.0f).translated (4.0f, 0.0f), colour::textSecondary);
  5153. g.setColour (colour::textPrimary);
  5154. g.setFont (font (type::small));
  5155. textcache::drawFittedText (g, tr ("Editor"), b.withTrimmedLeft (24.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
  5156. }
  5157. paintSidechainButton (g, slot);
  5158. if (tune) // the scale's notes on one octave; a note switched off is never a target
  5159. {
  5160. const auto area = tuneKeysBounds().toFloat();
  5161. const auto scaleMask = vocal::scaleMask ((vocal::Scale) lynxtune::scaleIndex (slot.params[lynxtune::scale]), lynxtune::keyIndex (slot.params[lynxtune::key]), 0xfff);
  5162. const auto custom = lynxtune::scaleIndex (slot.params[lynxtune::scale]) == (int) vocal::Scale::custom;
  5163. for (const auto black : { false, true })
  5164. for (int pc = 0; pc < 12; ++pc)
  5165. {
  5166. const auto isBlack = pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10;
  5167. if (isBlack != black)
  5168. continue;
  5169. const auto r = tuneKeyRect (area, pc).reduced (1.0f);
  5170. const auto on = slot.params[(std::size_t) (lynxtune::noteC + pc)] >= 0.5f;
  5171. const auto inScale = custom || (scaleMask & (1u << pc)) != 0;
  5172. auto fill = isBlack ? colour::bg0 : colour::bg2;
  5173. if (inScale && on)
  5174. fill = (slot.enabled ? colour::accent : colour::textDisabled).withAlpha (isBlack ? 0.85f : 0.65f);
  5175. theme::fillRoundRect (g, r, 2.0f, fill);
  5176. g.setColour (colour::gridBar);
  5177. g.drawRoundedRectangle (r, 2.0f, 1.0f);
  5178. if (inScale && ! on) // in the scale but switched off
  5179. {
  5180. g.setColour (colour::textSecondary);
  5181. g.drawLine (r.getX() + 3.0f, r.getBottom() - 3.0f, r.getRight() - 3.0f, r.getBottom() - 14.0f, 1.2f);
  5182. }
  5183. if (! isBlack)
  5184. {
  5185. static const char* names[12] { "C", "", "D", "", "E", "F", "", "G", "", "A", "", "B" };
  5186. g.setColour (inScale && on ? colour::textPrimary : colour::textSecondary);
  5187. g.setFont (font (type::caption));
  5188. textcache::drawText (g, names[pc], r.withTrimmedTop (r.getHeight() - 16.0f), juce::Justification::centred);
  5189. }
  5190. }
  5191. g.setColour (colour::textSecondary);
  5192. g.setFont (font (type::caption));
  5193. textcache::drawFittedText (g, tr ("Target notes: click a key to switch it off or on"), tuneKeysBounds().withY (tuneKeysBounds().getBottom() + 2).withHeight (14),
  5194. juce::Justification::centredLeft, 1, 0.8f);
  5195. }
  5196. if (vocoder) // the analysis bands' levels, low to high (FL's band level strip)
  5197. {
  5198. const auto st = vocoderState (slot);
  5199. const auto area = bandLevelsBounds().toFloat();
  5200. theme::fillRoundRect (g, area, radius::sm, colour::bg0);
  5201. const auto w = area.getWidth() / (float) st.bands;
  5202. const auto unity = area.getBottom() - area.getHeight() / maxBandLevel;
  5203. for (int k = 0; k < st.bands; ++k)
  5204. {
  5205. const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, st.levels[(std::size_t) k] / maxBandLevel);
  5206. g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha (k % 2 == 0 ? 1.0f : 0.8f));
  5207. 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);
  5208. }
  5209. g.setColour (colour::gridBar);
  5210. g.drawHorizontalLine ((int) unity, area.getX(), area.getRight());
  5211. g.setColour (colour::textSecondary);
  5212. g.setFont (font (type::caption));
  5213. textcache::drawFittedText (g, tr ("Band levels: draw them; right-click = presets"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
  5214. juce::Justification::centredLeft, 1, 0.8f);
  5215. }
  5216. if (gate) // 32 steps = 1 bar of 4 beats
  5217. {
  5218. const auto area = gateStepsBounds().toFloat();
  5219. theme::fillRoundRect (g, area, radius::sm, colour::bg0);
  5220. const auto w = area.getWidth() / 32.0f;
  5221. for (int i = 0; i < 32; ++i)
  5222. {
  5223. const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, slot.params[(std::size_t) i]);
  5224. g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha ((i / 8) % 2 == 0 ? 1.0f : 0.7f));
  5225. g.fillRect (area.getX() + i * w + 1.0f, area.getBottom() - h, w - 2.0f, h);
  5226. }
  5227. g.setColour (colour::gridBar);
  5228. for (int beat = 1; beat < 4; ++beat)
  5229. g.drawVerticalLine ((int) (area.getX() + beat * 8 * w), area.getY(), area.getBottom());
  5230. g.setColour (colour::textSecondary);
  5231. g.setFont (font (type::caption));
  5232. textcache::drawFittedText (g, tr ("1 bar: draw the steps; right-click = patterns"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
  5233. juce::Justification::centredLeft, 1, 0.8f);
  5234. }
  5235. for (int p = gate ? 32 : 0; p < shownParams (slot); ++p)
  5236. {
  5237. const auto r = knobBounds (p);
  5238. const auto value = slot.params[(std::size_t) p];
  5239. // 38 px knob; in tight grids (Effector) it shrinks to fit name and value below
  5240. const auto knobHeight = juce::jlimit (30, 44, r.getHeight() - 30);
  5241. drawKnob (g, r.withHeight (knobHeight).toFloat(), value, false, slot.enabled ? colour::knobArc : colour::textDisabled,
  5242. dragParam == p || (hoverParam == p && hoverSlot < 0));
  5243. g.setColour (colour::textSecondary);
  5244. g.setFont (font (type::caption));
  5245. // (round 190fg: through the translation table, as the generated editor page and the Pocket panels show it)
  5246. textcache::drawFittedText (g, tr (info.params[(std::size_t) p].name), r.getX(), r.getY() + knobHeight + 2, r.getWidth(), 14,
  5247. juce::Justification::centred, 1, 0.8f);
  5248. g.setColour (colour::textPrimary);
  5249. textcache::drawText (g, juce::String::fromUTF8 (formatEffectParam (slot.kind, p, value, song.bpm, slot.params).c_str()), r.getX(), r.getY() + knobHeight + 16,
  5250. r.getWidth(), 14, juce::Justification::centred);
  5251. }
  5252. }
  5253. bool EffectsPanel::refuseFrozenSlots (juce::Point<int> p)
  5254. {
  5255. const auto& song = engine.getSong();
  5256. const auto channel = freeze::frozenByInsert (song, track);
  5257. if (channel < 0)
  5258. return false;
  5259. bool inSlots = fxSwitchBounds().contains (p) || sidechainButtonBounds().contains (p) || knobAt (p) >= 0;
  5260. for (int row = 0; row < maxEffectSlots && ! inSlots; ++row)
  5261. inSlots = slotBounds (row).contains (p);
  5262. if (! inSlots)
  5263. return false;
  5264. 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()) }), {} },
  5265. 3000);
  5266. return true;
  5267. }
  5268. void EffectsPanel::mouseDown (const juce::MouseEvent& e)
  5269. {
  5270. const auto* s = slots();
  5271. if (s == nullptr)
  5272. return;
  5273. if (refuseFrozenSlots (e.getPosition()))
  5274. return;
  5275. if (const auto sc = sidechainButtonBounds(); ! sc.isEmpty() && sc.contains (e.getPosition()))
  5276. {
  5277. pluginheader::showSidechainPicker (engine, track, selectedSlot, this, sc);
  5278. return;
  5279. }
  5280. // 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
  5281. if (eqShown() && eqFoldBounds().contains (e.getPosition()) && flmods::popup (e.mods) && track >= 0 && track < (int) engine.getSong().mixer.size())
  5282. {
  5283. const auto bypassed = engine.getSong().mixer[(std::size_t) track].eq.bypassed;
  5284. juce::PopupMenu menu;
  5285. menu.addItem (tr ("Bypass the EQ (its settings are kept)"), true, bypassed, [this, t = track] {
  5286. engine.editSong ([t] (Song& song) {
  5287. if (t >= 0 && t < (int) song.mixer.size())
  5288. song.mixer[(std::size_t) t].eq.bypassed = ! song.mixer[(std::size_t) t].eq.bypassed;
  5289. });
  5290. repaint();
  5291. });
  5292. menu.showMenuAsync (juce::PopupMenu::Options().withMousePosition());
  5293. return;
  5294. }
  5295. if (eqFoldBounds().contains (e.getPosition()) && e.mods.isLeftButtonDown())
  5296. {
  5297. eqFoldChoice = eqFolded ? 1 : 2;
  5298. refit();
  5299. repaint();
  5300. return;
  5301. }
  5302. // the built-in EQ and the output target (bottom section)
  5303. if (outputBounds().contains (e.getPosition()))
  5304. {
  5305. showOutputMenu();
  5306. return;
  5307. }
  5308. if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  5309. {
  5310. if (isEqPoint (eqControl))
  5311. {
  5312. dragParam = eqControl;
  5313. setEqFromGraph (eqPointBase - eqControl, e.getPosition());
  5314. return;
  5315. }
  5316. if (flmods::popup (e.mods))
  5317. ui::showValueMenu (*this, &engine, specFor (eqControl, -1), valueOf (eqControl, -1), [this, eqControl] (double v) { setValue (eqControl, -1, v); });
  5318. else if (ui::isResetClick (e))
  5319. setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
  5320. else
  5321. {
  5322. dragParam = eqControl;
  5323. drag.begin (e, valueOf (eqControl, -1));
  5324. showTip (eqControl, -1, false);
  5325. }
  5326. return;
  5327. }
  5328. if (track > 0 && armBounds().contains (e.getPosition()))
  5329. {
  5330. if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a)
  5331. mixerinput::chooseRecordTo (engine, track);
  5332. else
  5333. mixerinput::toggleArm (engine, track, this);
  5334. repaint();
  5335. return;
  5336. }
  5337. if (track >= 0 && inputBoxBounds().contains (e.getPosition()))
  5338. {
  5339. mixerinput::showMenu (engine, track, this);
  5340. return;
  5341. }
  5342. if (! s->empty() && fxSwitchBounds().contains (e.getPosition()))
  5343. {
  5344. if (flmods::popup (e.mods))
  5345. toggleAllWindows();
  5346. else
  5347. {
  5348. const auto on = ! mixerops::anyEffectEnabled (engine.getSong(), track);
  5349. engine.editSong ([t = track, on] (Song& song) { mixerops::setAllEffectsEnabled (song, t, on); });
  5350. }
  5351. return;
  5352. }
  5353. for (int row = 0; row < maxEffectSlots; ++row)
  5354. {
  5355. const auto r = slotBounds (row);
  5356. if (! r.contains (e.getPosition()))
  5357. continue;
  5358. const auto i = effectIn (row);
  5359. if (i < 0)
  5360. {
  5361. showAddMenu (row); // (FL: the plugin lands in this slot)
  5362. return;
  5363. }
  5364. if (arrowBounds (row).contains (e.getPosition())) // FL's slot options arrow
  5365. {
  5366. selectedSlot = i;
  5367. repaint();
  5368. showSlotMenu (i);
  5369. return;
  5370. }
  5371. selectedSlot = i;
  5372. repaint();
  5373. if (mixBounds (row).contains (e.getPosition()))
  5374. {
  5375. if (flmods::popup (e.mods))
  5376. ui::showValueMenu (*this, &engine, specFor (mixParam, i), valueOf (mixParam, i), [this, i] (double v) { setValue (mixParam, i, v); });
  5377. else if (ui::isResetClick (e))
  5378. {
  5379. setValue (mixParam, i, 1.0);
  5380. showTip (mixParam, i, true);
  5381. }
  5382. else
  5383. {
  5384. dragParam = mixParam;
  5385. dragStart = (*s)[(std::size_t) i].mix;
  5386. drag.begin (e, dragStart);
  5387. showTip (mixParam, i, false);
  5388. }
  5389. return;
  5390. }
  5391. if (flmods::popup (e.mods) || (e.mods.isShiftDown() && ! ledBounds (row).contains (e.getPosition()))) // (FL: Shift+click = the menu)
  5392. showSlotMenu (i);
  5393. else if (ledBounds (row).contains (e.getPosition())) // LED: bypass
  5394. engine.editSong ([t = track, i] (Song& song) {
  5395. auto& slot = song.mixer[(std::size_t) t].effects[(std::size_t) i];
  5396. slot.enabled = ! slot.enabled;
  5397. });
  5398. else
  5399. dragSlot = i; // dragging the name moves the effect to another slot (a click shows its window)
  5400. return;
  5401. }
  5402. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::plugin
  5403. && pluginButtonBounds().contains (e.getPosition()))
  5404. {
  5405. openPluginWindow (selectedSlot);
  5406. return;
  5407. }
  5408. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq
  5409. && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
  5410. {
  5411. ParametricEqWindows::open (engine, track, selectedSlot);
  5412. return;
  5413. }
  5414. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && isSoundgoodizerApprox ((*s)[(std::size_t) selectedSlot])
  5415. && pluginButtonBounds().contains (e.getPosition()))
  5416. {
  5417. NativeEffectWindows::open (engine, track, selectedSlot);
  5418. return;
  5419. }
  5420. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq
  5421. && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
  5422. {
  5423. FacetEqWindows::open (engine, track, selectedSlot);
  5424. return;
  5425. }
  5426. if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind != EffectKind::volumeGate
  5427. && ! vocoderSelected() && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind)
  5428. && editorButtonBounds().contains (e.getPosition()))
  5429. {
  5430. openEditor (selectedSlot);
  5431. return;
  5432. }
  5433. if (vocoderSelected() && bandLevelsBounds().contains (e.getPosition()))
  5434. {
  5435. if (flmods::popup (e.mods))
  5436. showBandLevelMenu();
  5437. else
  5438. {
  5439. dragParam = bandLevelParam;
  5440. setBandLevel (e.getPosition());
  5441. }
  5442. return;
  5443. }
  5444. if (tuneSelected() && tuneKeysBounds().contains (e.getPosition()))
  5445. {
  5446. toggleTuneNote (e.getPosition());
  5447. return;
  5448. }
  5449. if (gateSelected() && gateStepsBounds().contains (e.getPosition()))
  5450. {
  5451. if (flmods::popup (e.mods))
  5452. showGatePatterns();
  5453. else
  5454. {
  5455. dragParam = gateStepParam;
  5456. setGateStep (e.getPosition());
  5457. }
  5458. return;
  5459. }
  5460. dragParam = knobAt (e.getPosition());
  5461. if (dragParam >= 0 && flmods::popup (e.mods))
  5462. {
  5463. const auto p = dragParam;
  5464. ui::showValueMenu (*this, &engine, specFor (p, selectedSlot), valueOf (p, selectedSlot),
  5465. [this, p, slot = selectedSlot] (double v) { setValue (p, slot, v); });
  5466. dragParam = -1;
  5467. return;
  5468. }
  5469. if (dragParam >= 0 && ui::isResetClick (e))
  5470. {
  5471. setValue (dragParam, selectedSlot, specFor (dragParam, selectedSlot).defaultValue);
  5472. showTip (dragParam, selectedSlot, true);
  5473. dragParam = -1;
  5474. return;
  5475. }
  5476. if (dragParam >= 0)
  5477. {
  5478. dragStart = (*s)[(std::size_t) selectedSlot].params[(std::size_t) dragParam];
  5479. drag.begin (e, dragStart);
  5480. showTip (dragParam, selectedSlot, false);
  5481. }
  5482. }
  5483. ui::ValueSpec EffectsPanel::specFor (int param, int slot) const
  5484. {
  5485. const auto& song = engine.getSong();
  5486. ui::ValueSpec spec;
  5487. spec.pixelsForRange = 150.0;
  5488. if (isEqParam (param)) // the built-in EQ (stored 0..1 here: gain ±18 dB, frequency 10 Hz..16 kHz log, width)
  5489. {
  5490. const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
  5491. const juce::String whatName = what == 0 ? tr ("level") : what == 1 ? tr ("frequency") : tr ("width");
  5492. 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]) })
  5493. + " " + whatName;
  5494. TrackEq defaults;
  5495. spec.defaultValue = eqToValue (defaults, band, what);
  5496. spec.toText = [band, what] (double v) {
  5497. TrackEq eq;
  5498. eqFromValue (eq, band, what, (float) v);
  5499. const auto b = (std::size_t) band;
  5500. return what == 0 ? juce::String (eq.gainDb[b], 1) + " dB"
  5501. : what == 1 ? (eq.hz[b] >= 1000.0f ? juce::String (eq.hz[b] / 1000.0f, 2) + " kHz" : juce::String ((int) eq.hz[b]) + " Hz")
  5502. : juce::String (eq.width[b], 2);
  5503. };
  5504. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  5505. return spec;
  5506. }
  5507. if (const auto* s = slots(); s == nullptr || slot < 0 || slot >= (int) s->size())
  5508. return spec;
  5509. const auto& fx = (*slots())[(std::size_t) slot];
  5510. const auto& info = effectInfo (fx.kind);
  5511. const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str());
  5512. if (param == mixParam)
  5513. {
  5514. spec = ui::percentSpec (trackName + " - " + utf8 (info.name) + " - " + tr ("Mix"), 1.0);
  5515. spec.target = AutomationTarget { AutomationTargetKind::effectMix, track, slot };
  5516. return spec;
  5517. }
  5518. if (param < 0 || param >= (int) info.params.size())
  5519. return spec;
  5520. spec.name = trackName + " - " + utf8 (info.name) + " - " + tr (info.params[(std::size_t) param].name); // (as "Mix" above)
  5521. spec.defaultValue = info.params[(std::size_t) param].defaultValue;
  5522. 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()); };
  5523. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  5524. spec.target = AutomationTarget { AutomationTargetKind::effectParam, track, slot, param };
  5525. return spec;
  5526. }
  5527. double EffectsPanel::valueOf (int param, int slot) const
  5528. {
  5529. if (isEqParam (param))
  5530. return track >= 0 && track < (int) engine.getSong().mixer.size()
  5531. ? eqToValue (engine.getSong().mixer[(std::size_t) track].eq, (eqParamBase - param) / 3, (eqParamBase - param) % 3)
  5532. : 0.0;
  5533. const auto* s = slots();
  5534. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  5535. return 0.0;
  5536. const auto& fx = (*s)[(std::size_t) slot];
  5537. return param == mixParam ? fx.mix : (param >= 0 && param < (int) fx.params.size() ? fx.params[(std::size_t) param] : 0.0f);
  5538. }
  5539. void EffectsPanel::setValue (int param, int slot, double value)
  5540. {
  5541. if (isEqParam (param))
  5542. {
  5543. engine.editSong ([t = track, band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3, v = (float) value] (Song& song) {
  5544. if (t < (int) song.mixer.size())
  5545. eqFromValue (song.mixer[(std::size_t) t].eq, band, what, v);
  5546. });
  5547. return;
  5548. }
  5549. const auto* s = slots();
  5550. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  5551. return;
  5552. if (param == mixParam)
  5553. engine.editSong ([t = track, slot, v = (float) value] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) slot].mix = v; });
  5554. else if (param >= 0)
  5555. engine.editSong ([t = track, slot, param, v = (float) value] (Song& song) {
  5556. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) param] = v;
  5557. });
  5558. }
  5559. int EffectsPanel::mixKnobAt (juce::Point<int> p) const
  5560. {
  5561. for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
  5562. if (mixBounds (rowOf (i)).contains (p))
  5563. return i;
  5564. return -1;
  5565. }
  5566. void EffectsPanel::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
  5567. {
  5568. // a spin that is scrolling the mixer goes on scrolling over the EQ, the knobs and the slot names (round 169c)
  5569. if (ui::wheelScrolling())
  5570. {
  5571. ui::noteWheelScroll();
  5572. juce::Component::mouseWheelMove (e, wheel);
  5573. return;
  5574. }
  5575. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (e.getPosition()))
  5576. return;
  5577. if (auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  5578. {
  5579. if (isEqPoint (eqControl)) // the wheel over a handle changes the band's width
  5580. eqControl = eqParamBase - (eqPointBase - eqControl) * 3 - 2;
  5581. if (const auto v = ui::wheelValue (valueOf (eqControl, -1), e, wheel, specFor (eqControl, -1)))
  5582. {
  5583. setValue (eqControl, -1, *v);
  5584. showTip (eqControl, -1, true);
  5585. }
  5586. return;
  5587. }
  5588. if (const auto slot = mixKnobAt (e.getPosition()); slot >= 0)
  5589. {
  5590. if (const auto v = ui::wheelValue (valueOf (mixParam, slot), e, wheel, specFor (mixParam, slot)))
  5591. {
  5592. setValue (mixParam, slot, *v);
  5593. showTip (mixParam, slot, true);
  5594. }
  5595. return;
  5596. }
  5597. if (const auto p = knobAt (e.getPosition()); p >= 0)
  5598. {
  5599. if (const auto v = ui::wheelValue (valueOf (p, selectedSlot), e, wheel, specFor (p, selectedSlot)))
  5600. {
  5601. setValue (p, selectedSlot, *v);
  5602. showTip (p, selectedSlot, true);
  5603. }
  5604. return;
  5605. }
  5606. // FL (REA FUN_012ab750): the wheel over a slot moves its effect one slot up or down (into an empty slot too,
  5607. // wrapping around the 10 slots) and the mouse pointer follows it. A trackpad's small steps add up to one move.
  5608. if (const auto slot = slotAt (e.getPosition()); slot >= 0)
  5609. {
  5610. const auto delta = (wheel.isReversed ? -1.0 : 1.0) * (wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX);
  5611. if (wheelSlot != slot || juce::Time::getMillisecondCounter() - wheelTime > 400)
  5612. wheelAccumulator = 0.0;
  5613. wheelSlot = slot;
  5614. wheelTime = juce::Time::getMillisecondCounter();
  5615. const auto steps = controls::slotWheelSteps (wheelAccumulator, delta, wheel.isSmooth, wheel.isInertial);
  5616. if (steps == 0)
  5617. return;
  5618. int now = -1;
  5619. engine.editSongStructural ([t = track, slot, steps, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, steps > 0 ? -1 : 1); });
  5620. if (now >= 0)
  5621. {
  5622. selectedSlot = wheelSlot = now;
  5623. const auto target = slotBounds (rowOf (now));
  5624. juce::Desktop::getInstance().getMainMouseSource().setScreenPosition (localPointToGlobal (juce::Point<int> (e.x, target.getCentreY())).toFloat());
  5625. }
  5626. repaint();
  5627. return;
  5628. }
  5629. ui::noteWheelScroll();
  5630. juce::Component::mouseWheelMove (e, wheel);
  5631. }
  5632. ui::Hint EffectsPanel::hintAt (juce::Point<int> p)
  5633. {
  5634. const auto gesture = ui::valueGestures();
  5635. if (isEqParam (dragParam))
  5636. return ui::valueHint (specFor (dragParam, -1), valueOf (dragParam, -1), gesture);
  5637. if (const auto eqControl = eqControlAt (p); eqControl != 0)
  5638. {
  5639. if (isEqParam (eqControl))
  5640. return ui::valueHint (specFor (eqControl, -1), valueOf (eqControl, -1), gesture);
  5641. ui::Hint h;
  5642. const auto band = eqPointBase - eqControl;
  5643. h.text = tr ("EQ: [LMB] drag the band's frequency and level [Wheel] width [2xLMB] back to 0 dB");
  5644. h.value = tr ("Band {0}", { juce::String (band + 1) }) + " - " + tr (eqBandNames[band]);
  5645. return h;
  5646. }
  5647. if (slots() != nullptr && eqFoldBounds().contains (p))
  5648. {
  5649. ui::Hint h;
  5650. 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)"))
  5651. + " " + tr ("[RMB] bypass");
  5652. return h;
  5653. }
  5654. if (outputBounds().contains (p))
  5655. {
  5656. ui::Hint h;
  5657. h.text = track == 0 ? tr ("Audio output target: the outputs of your audio device the Master plays on [LMB] choose")
  5658. : 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");
  5659. h.value = outputName();
  5660. h.hasMenu = true;
  5661. return h;
  5662. }
  5663. if (dragParam == mixParam || (dragParam >= 0 && drag.isActive()))
  5664. return ui::valueHint (specFor (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot),
  5665. valueOf (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot), gesture);
  5666. if (const auto slot = mixKnobAt (p); slot >= 0)
  5667. return ui::valueHint (specFor (mixParam, slot), valueOf (mixParam, slot), gesture);
  5668. if (const auto param = knobAt (p); param >= 0)
  5669. return ui::valueHint (specFor (param, selectedSlot), valueOf (param, selectedSlot), gesture);
  5670. ui::Hint h;
  5671. if (const auto sc = sidechainButtonBounds(); ! sc.isEmpty() && sc.contains (p))
  5672. {
  5673. 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");
  5674. h.hasMenu = true;
  5675. return h;
  5676. }
  5677. if (const auto* s = slots(); s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size()
  5678. && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind) && editorButtonBounds().contains (p))
  5679. {
  5680. h.text = tr ("Open the effect's window (its full controls, as in FL); clicking the slot's name does the same");
  5681. return h;
  5682. }
  5683. if (track > 0 && armBounds().contains (p))
  5684. {
  5685. h.text = mixerinput::armHint (engine, track);
  5686. h.hasMenu = true;
  5687. return h;
  5688. }
  5689. if (track >= 0 && inputBoxBounds().contains (p))
  5690. {
  5691. h.text = track == 0 ? tr ("Audio input source: the microphone or interface input the Master plays (through its effects) [LMB] choose")
  5692. : tr ("Audio input source: the microphone or interface input this insert plays and records [LMB] choose");
  5693. h.hasMenu = true;
  5694. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  5695. if (mt.inputChannel >= 0)
  5696. h.value = juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str());
  5697. return h;
  5698. }
  5699. if (fxSwitchBounds().contains (p) && slots() != nullptr && ! slots()->empty())
  5700. {
  5701. h.text = tr ("All effects of this insert on/off; right-click opens or closes their plugin windows");
  5702. h.hasMenu = true;
  5703. return h;
  5704. }
  5705. for (int i = 0; i < maxEffectSlots; ++i)
  5706. if (slotBounds (i).contains (p))
  5707. {
  5708. const auto used = effectIn (i) >= 0;
  5709. if (used && engine.isSlotLowLatencyBypassed (track, effectIn (i))) // round 190aq
  5710. {
  5711. const auto ms = 1000.0 * engine.lowLatencyBypassedLatency (track, effectIn (i)) / juce::jmax (1.0, engine.getTransport().sampleRate.load());
  5712. 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",
  5713. { juce::String (ms, ms < 10.0 ? 1 : 0) });
  5714. h.hasMenu = true;
  5715. return h;
  5716. }
  5717. h.text = used ? (arrowBounds (i).contains (p) ? tr ("Effect slot options: replace, move, delete...")
  5718. : 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"))
  5719. : tr ("Empty slot: click to add an effect");
  5720. h.hasMenu = used;
  5721. }
  5722. return h;
  5723. }
  5724. void EffectsPanel::mouseDrag (const juce::MouseEvent& e)
  5725. {
  5726. if (dragSlot >= 0)
  5727. {
  5728. if (e.getDistanceFromDragStart() > 4)
  5729. {
  5730. const auto target = juce::jlimit (0, maxEffectSlots - 1, (e.y - slotsTop) / slotHeight); // (empty slots too, as FL)
  5731. if (target != dropSlot)
  5732. {
  5733. dropSlot = target;
  5734. setMouseCursor (juce::MouseCursor::DraggingHandCursor);
  5735. repaint();
  5736. }
  5737. }
  5738. return;
  5739. }
  5740. if (isEqPoint (dragParam))
  5741. {
  5742. setEqFromGraph (eqPointBase - dragParam, e.getPosition());
  5743. return;
  5744. }
  5745. if (isEqParam (dragParam))
  5746. {
  5747. setValue (dragParam, -1, drag.update (e, specFor (dragParam, -1)));
  5748. showTip (dragParam, -1, false);
  5749. return;
  5750. }
  5751. if (dragParam == gateStepParam)
  5752. {
  5753. setGateStep (e.getPosition());
  5754. return;
  5755. }
  5756. if (dragParam == bandLevelParam)
  5757. {
  5758. setBandLevel (e.getPosition());
  5759. return;
  5760. }
  5761. if (dragParam == mixParam)
  5762. {
  5763. setValue (mixParam, selectedSlot, drag.update (e, specFor (mixParam, selectedSlot)));
  5764. showTip (mixParam, selectedSlot, false);
  5765. return;
  5766. }
  5767. if (dragParam < 0)
  5768. return;
  5769. setValue (dragParam, selectedSlot, drag.update (e, specFor (dragParam, selectedSlot)));
  5770. showTip (dragParam, selectedSlot, false);
  5771. }
  5772. void EffectsPanel::showTip (int param, int slot, bool transient)
  5773. {
  5774. if (isEqParam (param))
  5775. {
  5776. const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
  5777. const auto area = what == 0 ? eqFaderBounds (band) : eqKnobBounds (band, what);
  5778. const auto spec = specFor (param, -1);
  5779. ui::postHint (ui::valueHint (spec, valueOf (param, -1), ui::valueGestures()));
  5780. if (transient)
  5781. ui::flashValueTip (*this, area, spec.text (valueOf (param, -1)));
  5782. else
  5783. ui::showValueTip (*this, area, spec.text (valueOf (param, -1)));
  5784. return;
  5785. }
  5786. const auto* s = slots();
  5787. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  5788. return;
  5789. const auto area = param == mixParam ? mixBounds (rowOf (slot)) : knobBounds (param).withHeight (juce::jlimit (30, 44, knobBounds (param).getHeight() - 30));
  5790. const auto text = specFor (param, slot).text (valueOf (param, slot));
  5791. ui::postHint (ui::valueHint (specFor (param, slot), valueOf (param, slot), ui::valueGestures()));
  5792. if (transient)
  5793. ui::flashValueTip (*this, area, text);
  5794. else
  5795. ui::showValueTip (*this, area, text);
  5796. }
  5797. void EffectsPanel::mouseMove (const juce::MouseEvent& e)
  5798. {
  5799. const auto p = e.getPosition();
  5800. auto slot = -1; // (a row)
  5801. auto param = -1;
  5802. auto led = false;
  5803. for (int i = 0; i < maxEffectSlots; ++i)
  5804. if (slotBounds (i).contains (p))
  5805. slot = i;
  5806. if (const auto m = mixKnobAt (p); m >= 0)
  5807. {
  5808. slot = rowOf (m);
  5809. param = mixParam;
  5810. }
  5811. else if (slot < 0)
  5812. param = knobAt (p);
  5813. else
  5814. led = p.x < slotBounds (slot).getX() + 22;
  5815. const auto input = track > 0 && armBounds().contains (p) ? 1 : track >= 0 && inputBoxBounds().contains (p) ? 2 : 0;
  5816. const auto eq = eqControlAt (p);
  5817. const auto output = outputBounds().contains (p);
  5818. auto arrow = false;
  5819. for (int i = 0; i < maxEffectSlots; ++i)
  5820. if (arrowBounds (i).contains (p))
  5821. {
  5822. slot = i;
  5823. arrow = true;
  5824. }
  5825. if (slot >= 0)
  5826. led = ledBounds (slot).contains (p);
  5827. if (const auto sc = sidechainButtonBounds(); sc.contains (p) != hoverSidechain) // round 177b
  5828. {
  5829. hoverSidechain = ! hoverSidechain;
  5830. repaint (sc);
  5831. }
  5832. if (slot != hoverSlot || param != hoverParam || led != hoverLed || input != hoverInput || eq != hoverEq || output != hoverOutput || arrow != hoverArrow)
  5833. {
  5834. hoverEq = eq;
  5835. hoverOutput = output;
  5836. hoverArrow = arrow;
  5837. hoverInput = input;
  5838. hoverSlot = slot;
  5839. hoverParam = param;
  5840. hoverLed = led;
  5841. repaint();
  5842. }
  5843. }
  5844. void EffectsPanel::mouseExit (const juce::MouseEvent&)
  5845. {
  5846. if (hoverSlot >= 0 || hoverParam != -1 || hoverInput != 0 || hoverEq != 0 || hoverOutput || hoverArrow)
  5847. {
  5848. hoverEq = 0;
  5849. hoverOutput = hoverArrow = false;
  5850. hoverInput = 0;
  5851. hoverSlot = hoverParam = -1;
  5852. hoverLed = false;
  5853. repaint();
  5854. }
  5855. }
  5856. void EffectsPanel::mouseUp (const juce::MouseEvent& e)
  5857. {
  5858. // a click on the slot's name (not a drag, not the second click of a double-click) shows or hides its window (FL)
  5859. if (dragSlot >= 0 && dropSlot < 0 && ! e.mouseWasDraggedSinceMouseDown() && e.getNumberOfClicks() == 1)
  5860. {
  5861. const auto slot = dragSlot;
  5862. dragSlot = -1;
  5863. toggleEditor (slot);
  5864. }
  5865. if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot))
  5866. {
  5867. bool moved = false;
  5868. engine.editSongStructural ([t = track, from = dragSlot, to = dropSlot, &moved] (Song& song) { moved = mixerops::moveEffectToRow (song, t, from, to); });
  5869. if (moved)
  5870. selectedSlot = effectIn (dropSlot);
  5871. }
  5872. if (dragSlot >= 0)
  5873. setMouseCursor (juce::MouseCursor::NormalCursor);
  5874. dragSlot = dropSlot = -1;
  5875. repaint();
  5876. dragParam = -1;
  5877. drag.end();
  5878. ui::hideValueTip();
  5879. ui::clearPostedHint();
  5880. }
  5881. void EffectsPanel::mouseDoubleClick (const juce::MouseEvent& e)
  5882. {
  5883. if (refuseFrozenSlots (e.getPosition()))
  5884. return;
  5885. if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
  5886. {
  5887. if (isEqPoint (eqControl)) // the band back to 0 dB
  5888. setValue (eqParamBase - (eqPointBase - eqControl) * 3, -1, specFor (eqParamBase, -1).defaultValue);
  5889. else
  5890. setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
  5891. return;
  5892. }
  5893. for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
  5894. if (mixBounds (rowOf (i)).contains (e.getPosition()))
  5895. {
  5896. engine.editSong ([t = track, i] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) i].mix = 1.0f; });
  5897. return;
  5898. }
  5899. else if (slotBounds (rowOf (i)).contains (e.getPosition()) && ! arrowBounds (rowOf (i)).contains (e.getPosition()) && ! ledBounds (rowOf (i)).contains (e.getPosition()))
  5900. {
  5901. openEditor (i); // (the first click opened it, round 170b): it stays open and comes to the front
  5902. return;
  5903. }
  5904. const auto p = knobAt (e.getPosition());
  5905. if (p < 0)
  5906. return;
  5907. const auto kind = (*slots())[(std::size_t) selectedSlot].kind;
  5908. const auto value = effectInfo (kind).params[(std::size_t) p].defaultValue;
  5909. engine.editSong ([t = track, slot = selectedSlot, p, value] (Song& song) {
  5910. song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) p] = value;
  5911. });
  5912. }
  5913. bool EffectsPanel::isInterestedInDragSource (const SourceDetails& details)
  5914. {
  5915. return (BrowserComponent::isBrowserDrag (details) && BrowserComponent::draggedFile (details).hasFileExtension ("fst"))
  5916. || BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details);
  5917. }
  5918. void EffectsPanel::itemDropped (const SourceDetails& details)
  5919. {
  5920. if (BrowserComponent::isGeneratorDrag (details))
  5921. {
  5922. if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr
  5923. && track >= 0 && track < (int) engine.getSong().mixer.size())
  5924. onInstrumentDropped (track, std::move (*c));
  5925. return;
  5926. }
  5927. if (BrowserComponent::isEffectDrag (details))
  5928. {
  5929. if (auto fx = BrowserComponent::draggedEffect (details))
  5930. dropEffect (std::move (*fx), details.localPosition);
  5931. return;
  5932. }
  5933. dropPreset (BrowserComponent::draggedFile (details), details.localPosition);
  5934. }
  5935. bool EffectsPanel::isInterestedInFileDrag (const juce::StringArray& files)
  5936. {
  5937. return files.size() == 1 && juce::File (files[0]).hasFileExtension ("fst");
  5938. }
  5939. void EffectsPanel::filesDropped (const juce::StringArray& files, int x, int y)
  5940. {
  5941. if (! files.isEmpty())
  5942. dropPreset (juce::File (files[0]), { x, y });
  5943. }
  5944. bool EffectsPanel::dropPreset (const juce::File& file, juce::Point<int> position)
  5945. {
  5946. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (position))
  5947. return false;
  5948. juce::MemoryBlock data;
  5949. if (slots() == nullptr || ! file.loadFileAsData (data))
  5950. return false;
  5951. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  5952. const auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm, natives::flDataReader (flStudioAccess()));
  5953. if (! fx)
  5954. {
  5955. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Preset"),
  5956. tr ("LYNX SHARE can't build an effect from this preset."));
  5957. return false;
  5958. }
  5959. return dropEffect (*fx, position);
  5960. }
  5961. bool EffectsPanel::dropEffect (EffectSlot fx, juce::Point<int> position)
  5962. {
  5963. if (freeze::frozenByInsert (engine.getSong(), track) >= 0 && refuseFrozenSlots (position))
  5964. return false;
  5965. if (slots() == nullptr)
  5966. return false;
  5967. auto target = -1, emptyRow = -1;
  5968. for (int row = 0; row < maxEffectSlots; ++row)
  5969. if (slotBounds (row).contains (position))
  5970. {
  5971. target = effectIn (row);
  5972. emptyRow = target < 0 ? row : -1;
  5973. }
  5974. if (target < 0 && (int) slots()->size() >= maxEffectSlots)
  5975. return false;
  5976. int added = -1;
  5977. engine.editSong ([t = track, target, emptyRow, &added, fx = std::move (fx)] (Song& song) {
  5978. auto& effects = song.mixer[(std::size_t) t].effects;
  5979. if (target >= 0 && target < (int) effects.size())
  5980. effects[(std::size_t) target] = fx;
  5981. else if (emptyRow >= 0) // dropped on an empty slot: it lands there (FL)
  5982. added = mixerops::insertEffectAtRow (song, t, fx, emptyRow);
  5983. else
  5984. effects.push_back (fx);
  5985. });
  5986. selectedSlot = target >= 0 ? target : added >= 0 ? added : (int) slots()->size() - 1;
  5987. repaint();
  5988. return true;
  5989. }
  5990. juce::Rectangle<int> EffectsPanel::fxSwitchBounds() const
  5991. {
  5992. return { getWidth() - 58, 6, 48, panelHeader - 12 };
  5993. }
  5994. int EffectsPanel::slotAt (juce::Point<int> p) const
  5995. {
  5996. const auto* s = slots();
  5997. for (int i = 0; s != nullptr && i < (int) s->size(); ++i)
  5998. if (const auto row = rowOf (i); slotBounds (row).contains (p) && ! mixBounds (row).contains (p) && ! ledBounds (row).contains (p) && ! arrowBounds (row).contains (p))
  5999. return i;
  6000. return -1;
  6001. }
  6002. void EffectsPanel::toggleAllWindows()
  6003. {
  6004. // opens every plugin effect window of the insert, or closes them all when one is open
  6005. const auto* s = slots();
  6006. if (s == nullptr)
  6007. return;
  6008. bool anyOpen = false;
  6009. for (int i = 0; i < (int) s->size(); ++i)
  6010. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
  6011. anyOpen = anyOpen || PluginWindows::isOpen (p->getInstance());
  6012. for (int i = 0; i < (int) s->size(); ++i)
  6013. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
  6014. {
  6015. if (anyOpen)
  6016. PluginWindows::close (p->getInstance());
  6017. else
  6018. openPluginWindow (i);
  6019. }
  6020. }
  6021. juce::Rectangle<int> EffectsPanel::pluginButtonBounds() const
  6022. {
  6023. return { 20, slotsTop + maxEffectSlots * slotHeight + 30, getWidth() - 40, 30 };
  6024. }
  6025. void EffectsPanel::openEditor (int slot)
  6026. {
  6027. if (freeze::frozenByInsert (engine.getSong(), track) >= 0) // (round 190ff: its effects are not loaded)
  6028. return;
  6029. const auto* s = slots();
  6030. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6031. return;
  6032. const auto kind = (*s)[(std::size_t) slot].kind;
  6033. if (kind == EffectKind::plugin)
  6034. openPluginWindow (slot);
  6035. else if (kind == EffectKind::parametricEq)
  6036. ParametricEqWindows::open (engine, track, slot);
  6037. else if (NativeEffectWindows::canOpen ((*s)[(std::size_t) slot]))
  6038. NativeEffectWindows::open (engine, track, slot);
  6039. }
  6040. void EffectsPanel::toggleEditor (int slot)
  6041. {
  6042. if (freeze::frozenByInsert (engine.getSong(), track) >= 0) // (round 190ff: its effects are not loaded)
  6043. return;
  6044. const auto* s = slots();
  6045. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6046. return;
  6047. // FL (REA FUN_012bde10, the slot name button's click): the plugin's editor is shown, or hidden when it shows
  6048. if ((*s)[(std::size_t) slot].kind == EffectKind::plugin)
  6049. {
  6050. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()); p != nullptr && PluginWindows::isOpen (p->getInstance()))
  6051. {
  6052. PluginWindows::close (p->getInstance());
  6053. return;
  6054. }
  6055. openPluginWindow (slot);
  6056. return;
  6057. }
  6058. if (! ui::SlotGoneWatcher::closeWindow (engine, track, slot))
  6059. openEditor (slot);
  6060. }
  6061. juce::Rectangle<int> EffectsPanel::editorButtonBounds() const
  6062. {
  6063. // on the title row of the selected effect's knobs
  6064. return { getWidth() - 96, (tuneSelected() ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 29, 86, 20 };
  6065. }
  6066. void EffectsPanel::paintSidechainButton (juce::Graphics& g, const EffectSlot& slot)
  6067. {
  6068. using namespace theme;
  6069. const auto b = sidechainButtonBounds().toFloat();
  6070. if (b.isEmpty())
  6071. return;
  6072. const auto source = pluginheader::sidechainSourceText (engine.getSong(), slot);
  6073. const auto hover = b.contains (getMouseXYRelative().toFloat());
  6074. theme::fillRoundRect (g, b, radius::md, hover ? colour::bg5 : colour::bg4);
  6075. if (source.isNotEmpty()) // linked: the accent edge, as a lit route
  6076. {
  6077. g.setColour (colour::accent.withAlpha (0.8f));
  6078. g.drawRoundedRectangle (b.reduced (0.5f), radius::md, 1.0f);
  6079. }
  6080. icons::draw (g, Icon::link, b.withWidth (22.0f).withSizeKeepingCentre (13.0f, 13.0f).translated (4.0f, 0.0f),
  6081. source.isNotEmpty() ? colour::accent : colour::textSecondary);
  6082. const auto modulator = slot.kind == EffectKind::vocoder || slot.kind == EffectKind::vocodex;
  6083. const auto text = (modulator ? tr ("Modulator") : tr ("SC")) + ": " + (source.isNotEmpty() ? source : tr ("None"));
  6084. g.setColour (source.isNotEmpty() ? colour::textPrimary : colour::textSecondary);
  6085. g.setFont (font (type::small));
  6086. textcache::drawFittedText (g, text, b.withTrimmedLeft (24.0f).withTrimmedRight (14.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
  6087. juce::Path tri; // ▾: it opens a list
  6088. const auto a = juce::Point<float> (b.getRight() - 9.0f, b.getCentreY());
  6089. tri.addTriangle (a.x - 3.5f, a.y - 2.0f, a.x + 3.5f, a.y - 2.0f, a.x, a.y + 2.5f);
  6090. g.setColour (colour::textSecondary);
  6091. g.fillPath (tri);
  6092. }
  6093. int EffectsPanel::titleRowY() const
  6094. {
  6095. return (gateSelected() ? gateStepsBounds().getY() : vocoderSelected() ? bandLevelsBounds().getY()
  6096. : tuneSelected() ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 28;
  6097. }
  6098. juce::Rectangle<int> EffectsPanel::sidechainButtonBounds() const
  6099. {
  6100. const auto* s = slots();
  6101. if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size() || track < 0)
  6102. return {};
  6103. const auto& slot = (*s)[(std::size_t) selectedSlot];
  6104. if (slot.kind == EffectKind::facetEq || slot.kind == EffectKind::parametricEq || slot.kind == EffectKind::parallel
  6105. || isSoundgoodizerApprox (slot)) // (Facet EQ: its own picker on its curve page)
  6106. return {};
  6107. if (! pluginheader::takesSidechain (engine, track, selectedSlot))
  6108. return {};
  6109. if (slot.kind == EffectKind::plugin) // under the plugin's name
  6110. {
  6111. const auto button = pluginButtonBounds();
  6112. return { button.getX(), button.getBottom() + 38, button.getWidth(), 22 };
  6113. }
  6114. const auto editorButton = slot.kind != EffectKind::volumeGate && ! vocoderSelected() && NativeEffectWindows::canOpen (slot.kind);
  6115. const auto right = editorButton ? editorButtonBounds().getX() - 6 : getWidth() - 10;
  6116. const auto width = juce::jmin (130, juce::jmax (0, right - 90));
  6117. return width < 60 ? juce::Rectangle<int>() : juce::Rectangle<int> (right - width, titleRowY(), width, 20);
  6118. }
  6119. void EffectsPanel::openPluginWindow (int slot)
  6120. {
  6121. // Online Sessions P5-A1: an effect the session's host plays on this insert opens its parameter editor
  6122. if (liveui::showHostedEditor ({ { live::Kind::insert, (std::uint64_t) juce::jmax (0, track), 0 }, slot }))
  6123. return;
  6124. auto effect = engine.getEffect (track, slot);
  6125. if (auto* plugin = dynamic_cast<PluginEffect*> (effect.get()))
  6126. {
  6127. // round 190ao: crashed inside a call (not called again: its window would call into it), or its separate process
  6128. // died: "Reload" starts it again without reopening the project
  6129. const AudioEngine::HostedSlot where { -1, track, slot };
  6130. auto reopen = [safe = juce::Component::SafePointer<EffectsPanel> (this), where] {
  6131. if (safe == nullptr || safe->track != where.track)
  6132. return;
  6133. if (safe->engine.hostedPluginDown (where))
  6134. PluginWindows::reload (safe->engine, { where });
  6135. if (! safe->engine.hostedPluginDown (where))
  6136. safe->openPluginWindow (where.slot);
  6137. };
  6138. if (engine.hostedPluginDown (where))
  6139. {
  6140. PluginWindows::promptReload (engine, where, [safe = juce::Component::SafePointer<EffectsPanel> (this), where] {
  6141. if (safe != nullptr && safe->track == where.track)
  6142. safe->openPluginWindow (where.slot);
  6143. });
  6144. return;
  6145. }
  6146. const auto& s = engine.getSong().mixer[(std::size_t) track].effects[(std::size_t) slot];
  6147. PluginWindows::WrapperContext context { &engine, [t = track, slot] (Song& song) -> PluginRef* {
  6148. if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
  6149. return nullptr;
  6150. return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
  6151. }, false, track, slot, {}, {} };
  6152. context.reload = reopen;
  6153. context.down = [weak = std::weak_ptr<Effect> (effect)] {
  6154. const auto held = weak.lock();
  6155. auto* p = dynamic_cast<PluginEffect*> (held.get());
  6156. return p != nullptr && p->hasCrashed();
  6157. };
  6158. PluginWindows::open (effect, plugin->getInstance(), quickpick::slotName (engine, s), std::move (context)); // (its Plugin database name, round 165c)
  6159. return;
  6160. }
  6161. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Plugin"),
  6162. tr ("This plugin could not be loaded (it is not installed or has not been scanned)."));
  6163. }
  6164. void EffectsPanel::showAddMenu (int row)
  6165. {
  6166. juce::PopupMenu menu;
  6167. // the effect lands in the clicked empty slot (FL's slot places, round 170b); returns its index, -1 = not added
  6168. auto place = [this, row] (EffectSlot fx) {
  6169. int at = -1;
  6170. engine.editSong ([t = track, row, &fx, &at] (Song& song) {
  6171. if (t < 0 || t >= (int) song.mixer.size() || (int) song.mixer[(std::size_t) t].effects.size() >= maxEffectSlots)
  6172. return;
  6173. at = mixerops::insertEffectAtRow (song, t, fx, row);
  6174. if (at < 0)
  6175. {
  6176. song.mixer[(std::size_t) t].effects.push_back (std::move (fx));
  6177. at = (int) song.mixer[(std::size_t) t].effects.size() - 1;
  6178. }
  6179. mixerops::linkAddedSidechain (song, t, at); // round 170h: the sole sidechain sender feeds a new compressor
  6180. });
  6181. if (at < 0)
  6182. return at;
  6183. selectedSlot = at;
  6184. if ((*slots())[(std::size_t) at].kind != EffectKind::plugin) // (plugins: their own window, below)
  6185. openEditor (at); // FL opens the effect's window when it is loaded (round 170h, fl-09)
  6186. repaint();
  6187. return at;
  6188. };
  6189. // FL's renamed plugins first (issue #11): "1_EQ" renamed in the Browser's Plugin database is added by typing 1
  6190. auto addFx = [this, place] (EffectSlot fx) {
  6191. const auto at = place (std::move (fx));
  6192. if (at >= 0 && (*slots())[(std::size_t) at].kind == EffectKind::plugin)
  6193. openPluginWindow (at);
  6194. };
  6195. auto picks = quickpick::renamedEffects (engine, addFx);
  6196. quickpick::addPicks (menu, picks);
  6197. // rounds 166f / 170b (Busy Works: "random order"): every effect under its category heading, A-Z, as FL's slot menu
  6198. // (LYNX SHARE first, then FL's Plugin database categories, the user's own folders among them)
  6199. quickpick::addFolderGroups (menu, engine, std::function<void (EffectSlot)> (addFx));
  6200. // LYNX equivalents of well-known third-party effects, with the same default preset a substitute gets
  6201. juce::PopupMenu equivalents;
  6202. for (const auto& entry : pluginSubstitutes())
  6203. if (! entry.instrument)
  6204. equivalents.addItem (juce::String::fromUTF8 (entry.product.c_str()) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (effectInfo (entry.effect).name),
  6205. [place, entry] { place (makeSubstituteSlot (entry)); });
  6206. if (equivalents.getNumItems() > 0)
  6207. menu.addSubMenu (tr ("LYNX SHARE equivalents"), equivalents);
  6208. juce::PopupMenu plugins;
  6209. addPluginItems (plugins, engine, false, [this, place] (PluginRef ref) {
  6210. EffectSlot slot;
  6211. slot.kind = EffectKind::plugin;
  6212. slot.plugin = ref;
  6213. if (const auto at = place (std::move (slot)); at >= 0)
  6214. openPluginWindow (at);
  6215. }, this);
  6216. menu.addSeparator();
  6217. menu.addSubMenu (tr ("Plugin (VST/VST3/CLAP)"), plugins);
  6218. menu.addSeparator();
  6219. menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
  6220. quickpick::addFolderViewItems (menu, engine); // FL: Categories / Simple / Tree at the bottom
  6221. quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (menuOwner()).withMousePosition(), std::move (picks));
  6222. }
  6223. void EffectsPanel::showSlotMenu (int slot)
  6224. {
  6225. // the same categories as the empty slot's menu (rounds 166f / 170b)
  6226. juce::PopupMenu replace;
  6227. quickpick::addFolderGroups (replace, engine, std::function<void (EffectSlot)> ([this, slot] (EffectSlot fx) {
  6228. engine.editSong ([t = track, slot, fx] (Song& song) {
  6229. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6230. song.mixer[(std::size_t) t].effects[(std::size_t) slot] = fx;
  6231. });
  6232. if (slot < (int) slots()->size() && (*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6233. openPluginWindow (slot);
  6234. }));
  6235. quickpick::addFolderViewItems (replace, engine);
  6236. juce::PopupMenu menu;
  6237. if (extendSlotMenu != nullptr) // (round 183a: the Device View's card adds Fold / Unfold first; the Mixer adds nothing)
  6238. extendSlotMenu (menu, slot);
  6239. menu.addSubMenu (tr ("Replace with"), replace);
  6240. // round 190ce: hot-swap from the Mixer too (the Device View's card has its own item and button)
  6241. if (extendSlotMenu == nullptr && onHotSwapSlot != nullptr)
  6242. menu.addItem (tr ("Hot-swap in the Browser"), [t = track, slot] {
  6243. if (onHotSwapSlot != nullptr)
  6244. onHotSwapSlot (t, slot);
  6245. });
  6246. menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
  6247. // FL presets (Plugin presets\Effects\<plugin>) that map to this effect
  6248. {
  6249. juce::PopupMenu presets;
  6250. const auto roots = findFlStudioRoots();
  6251. const auto base = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects");
  6252. for (const auto& plugin : flPluginsForEffect ((*slots())[(std::size_t) slot].kind))
  6253. {
  6254. juce::PopupMenu sub;
  6255. auto files = base.getChildFile (juce::String::fromUTF8 (plugin.c_str())).findChildFiles (juce::File::findFiles, true, "*.fst");
  6256. std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFileName().compareNatural (b.getFileName()) < 0; });
  6257. for (const auto& f : files)
  6258. sub.addItem (f.getFileNameWithoutExtension(), [this, slot, f] {
  6259. juce::MemoryBlock data;
  6260. if (! f.loadFileAsData (data))
  6261. return;
  6262. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  6263. if (auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm, natives::flDataReader (flStudioAccess())))
  6264. engine.editSong ([t = track, slot, fx = *fx] (Song& song) {
  6265. auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  6266. const auto enabled = target.enabled;
  6267. const auto mix = target.mix;
  6268. target = fx;
  6269. target.enabled = enabled;
  6270. target.mix = mix;
  6271. });
  6272. });
  6273. if (sub.getNumItems() > 0)
  6274. presets.addSubMenu (juce::String::fromUTF8 (plugin.c_str()), sub);
  6275. }
  6276. if (presets.getNumItems() > 0)
  6277. menu.addSubMenu (tr ("FL presets"), presets);
  6278. }
  6279. // side inputs: another track's output feeds the compressor's detector, or the vocoder's modulator/carrier. Round
  6280. // 177b: every effect with a side input (plugins with a sidechain bus too) gets the picker, which makes the route
  6281. const auto kind = (*slots())[(std::size_t) slot].kind;
  6282. auto sideMenu = [&] (const juce::String& title, bool second) {
  6283. juce::PopupMenu side;
  6284. pluginheader::addSidechainPicker (side, engine, track, slot, second);
  6285. menu.addSubMenu (title, side);
  6286. };
  6287. if (kind == EffectKind::vocoder || kind == EffectKind::vocodex)
  6288. {
  6289. sideMenu (tr ("Modulator from"), false);
  6290. sideMenu (tr ("Carrier from"), true);
  6291. }
  6292. else if (pluginheader::takesSidechain (engine, track, slot))
  6293. sideMenu (tr ("Sidechain from"), false);
  6294. if (kind == EffectKind::newtone || kind == EffectKind::newtime)
  6295. {
  6296. // the sample the plugin plays in slave mode (REA_rodada73): FL's edits are kept in the state but not reproduced
  6297. const auto& fx = (*slots())[(std::size_t) slot];
  6298. const auto current = juce::File (juce::String::fromUTF8 (fx.samplePath.c_str()));
  6299. juce::PopupMenu source;
  6300. source.addItem (fx.samplePath.empty() ? tr ("No sample") : current.getFileName(), false, false, [] {});
  6301. source.addItem (tr ("Choose a sample..."), [this, slot, current] {
  6302. sampleChooser = lynx::ui::makeFileChooser (tr ("Source sample"), current.existsAsFile() ? current : juce::File(),
  6303. "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3");
  6304. lynx::ui::launchChooser (sampleChooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  6305. [this, slot] (const juce::FileChooser& fc) {
  6306. const auto file = fc.getResult();
  6307. if (file == juce::File())
  6308. return;
  6309. engine.editSong ([t = track, slot, path = file.getFullPathName().toStdString()] (Song& s) {
  6310. if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
  6311. s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath = path;
  6312. });
  6313. });
  6314. });
  6315. source.addItem (tr ("Remove the sample"), ! fx.samplePath.empty(), false, [this, slot] {
  6316. engine.editSong ([t = track, slot] (Song& s) {
  6317. if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
  6318. s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath.clear();
  6319. });
  6320. });
  6321. menu.addSubMenu (tr ("Source sample"), source);
  6322. }
  6323. {
  6324. // A/B compare: keep a copy of the settings, then swap between it and the current ones
  6325. const auto key = std::make_pair (track, slot);
  6326. const auto hasSpare = spare.count (key) > 0 && spare[key].kind == (*slots())[(std::size_t) slot].kind;
  6327. juce::PopupMenu ab;
  6328. ab.addItem (tr ("Store the current settings as B"), [this, key, slot] {
  6329. spare[key] = (*slots())[(std::size_t) slot];
  6330. });
  6331. ab.addItem (tr ("Swap with B"), hasSpare, false, [this, key, slot] {
  6332. const auto stored = spare[key];
  6333. spare[key] = (*slots())[(std::size_t) slot];
  6334. engine.editSong ([t = track, slot, stored] (Song& song) {
  6335. auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
  6336. const auto enabled = target.enabled;
  6337. target = stored;
  6338. target.enabled = enabled;
  6339. });
  6340. });
  6341. ab.addItem (tr ("Forget B"), hasSpare, false, [key] { spare.erase (key); });
  6342. menu.addSubMenu (hasSpare ? tr ("A/B compare (B stored)") : tr ("A/B compare"), ab);
  6343. }
  6344. if ((*slots())[(std::size_t) slot].isSubstitute()) // A/B of every substitute of the project at once (round 113)
  6345. menu.addItem (tr ("Bypass all LYNX SHARE substitutes of this project"), true, engine.getSong().substitutesBypassed, [this] {
  6346. engine.editSong ([] (Song& song) { song.substitutesBypassed = ! song.substitutesBypassed; });
  6347. repaint();
  6348. });
  6349. // FL's slot menu "CPU" section (REA round 139): Allow threaded processing (plugins), Smart disable
  6350. menu.addSectionHeader (tr ("CPU"));
  6351. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6352. menu.addItem (tr ("Allow threaded processing"), true, (*slots())[(std::size_t) slot].plugin.threaded, [this, slot] {
  6353. engine.editSong ([t = track, slot] (Song& song) {
  6354. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6355. 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;
  6356. });
  6357. });
  6358. // FL's per-plugin "Smart disable": skipped while its input and output are silent
  6359. menu.addItem (tr ("Smart disable"), true, (*slots())[(std::size_t) slot].smartDisable, [this, slot] {
  6360. engine.editSong ([t = track, slot] (Song& song) {
  6361. if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
  6362. song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable = ! song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable;
  6363. });
  6364. });
  6365. menu.addSeparator();
  6366. // FL's Move up / Move down (REA FUN_01233de0 / FUN_01235190): one slot, into an empty one too, wrapping around
  6367. auto move = [this, slot] (int delta) {
  6368. int now = -1;
  6369. engine.editSongStructural ([t = track, slot, delta, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, delta); });
  6370. if (now >= 0)
  6371. selectedSlot = now;
  6372. repaint();
  6373. };
  6374. menu.addItem (tr ("Move up"), [move] { move (-1); });
  6375. menu.addItem (tr ("Move down"), [move] { move (1); });
  6376. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6377. {
  6378. // round 190ao: only while the plugin is down (it crashed, or its separate process died)
  6379. if (engine.hostedPluginDown ({ -1, track, slot }))
  6380. menu.addItem (tr ("Reload crashed plugin"), [this, t = track, slot] { PluginWindows::reload (engine, { { -1, t, slot } }); });
  6381. auto* live = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get());
  6382. menu.addSubMenu (tr ("Processing"), pluginProcessingMenu (engine, (*slots())[(std::size_t) slot].plugin, live != nullptr ? &live->getInstance() : nullptr,
  6383. [t = track, slot] (Song& song) -> PluginRef* {
  6384. if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
  6385. return nullptr;
  6386. return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
  6387. }));
  6388. }
  6389. if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
  6390. {
  6391. if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()))
  6392. addPluginParameterItems (menu, engine, p->getInstance(), { AutomationTargetKind::effectParam, track, slot, 0 });
  6393. }
  6394. if ((*slots())[(std::size_t) slot].kind == EffectKind::patcher) // its published parameters (round 171b)
  6395. addPatcherParameterItems (menu, engine, (*slots())[(std::size_t) slot].patcher, { AutomationTargetKind::effectParam, track, slot, 0 });
  6396. // FL's Patcherize / Patcherize all (round 165m): the effect (or the whole chain) into a new Patcher, same sound
  6397. menu.addSeparator();
  6398. menu.addItem (tr ("Patcherize"), patcherize::canPatcherizeSlot (engine.getSong(), track, slot), false, [this, slot] {
  6399. engine.capturePluginStates(); // (the plugins' current settings go with them)
  6400. int placed = -1;
  6401. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, false); });
  6402. if (placed >= 0)
  6403. selectedSlot = placed;
  6404. repaint();
  6405. });
  6406. menu.addItem (tr ("Patcherize all"), patcherize::slotsForAll (engine.getSong(), track).size() > 1, false, [this, slot] {
  6407. engine.capturePluginStates();
  6408. int placed = -1;
  6409. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, true); });
  6410. if (placed >= 0)
  6411. selectedSlot = placed;
  6412. repaint();
  6413. });
  6414. // round 183c: Live's Group (Ctrl+G): the effect (or the whole chain) into a new Audio Effect Rack, same sound; the
  6415. // automation of the moved effects' parameters drives the rack's macros
  6416. menu.addItem (tr ("Group into Audio Effect Rack"), patcherize::canPatcherizeSlot (engine.getSong(), track, slot), false, [this, slot] { groupIntoRack (slot, false); });
  6417. menu.addItem (tr ("Group all into Audio Effect Rack"), patcherize::slotsForAll (engine.getSong(), track).size() > 1, false, [this, slot] { groupIntoRack (slot, true); });
  6418. // Live's Ungroup: a one-chain Audio Effect Rack's devices back into the slots
  6419. if (const auto* list = slots(); list != nullptr && slot < (int) list->size() && rack::isRack ((*list)[(std::size_t) slot]))
  6420. {
  6421. const auto* r = rack::rackOf ((*list)[(std::size_t) slot].patcher);
  6422. const auto canUngroup = r != nullptr && r->kind == RackDoc::Kind::audioEffect && r->chains.size() == 1;
  6423. menu.addItem (tr ("Ungroup"), canUngroup, false, [this, slot] {
  6424. engine.capturePluginStates();
  6425. int placed = -1;
  6426. engine.editSong ([t = track, slot, &placed] (Song& song) { placed = rack::ungroupSlot (song, t, slot); });
  6427. if (placed >= 0)
  6428. selectedSlot = placed;
  6429. repaint();
  6430. });
  6431. }
  6432. menu.addSeparator();
  6433. menu.addItem (tr ("Delete") + "\tDel", [this, slot] { deleteSlot (slot); });
  6434. if (slotMenuForSnapshot != nullptr) // (the shot routes: the menu itself, nothing opens)
  6435. {
  6436. *slotMenuForSnapshot = menu;
  6437. return;
  6438. }
  6439. // FL: with the slot's menu open, Delete removes the plugin (issue #11)
  6440. quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (menuOwner()).withMousePosition(), {},
  6441. [safe = juce::Component::SafePointer<EffectsPanel> (this), slot] (const juce::KeyPress& key) {
  6442. if (! key.isKeyCode (juce::KeyPress::deleteKey) || safe == nullptr)
  6443. return false;
  6444. juce::MessageManager::callAsync ([safe, slot] {
  6445. if (safe != nullptr)
  6446. safe->deleteSlot (slot);
  6447. });
  6448. return true;
  6449. });
  6450. }
  6451. void EffectsPanel::deleteSlot (int slot)
  6452. {
  6453. const auto* s = slots();
  6454. if (s == nullptr || slot < 0 || slot >= (int) s->size())
  6455. return;
  6456. engine.editSongStructural ([t = track, slot] (Song& song) { mixerops::removeEffectKeepRows (song, t, slot); }); // (FL: the slot stays empty)
  6457. selectedSlot = juce::jmin (slot, (int) slots()->size() - 1);
  6458. repaint();
  6459. }
  6460. void EffectsPanel::changeListenerCallback (juce::ChangeBroadcaster*)
  6461. {
  6462. const auto* s = slots();
  6463. if (s == nullptr)
  6464. track = 0;
  6465. else if (selectedSlot >= (int) s->size())
  6466. selectedSlot = (int) s->size() - 1;
  6467. refit(); // the clean mixer (round 163) changes the height the panel needs
  6468. repaint();
  6469. }
  6470. // ---------------------------------------------------------------------------
  6471. namespace mixerinput
  6472. {
  6473. std::function<void()> openAudioSettings;
  6474. namespace
  6475. {
  6476. juce::String issueText (const AudioEngine::RecordingNotice& notice)
  6477. {
  6478. using I = AudioEngine::InputIssue;
  6479. switch (notice.issue)
  6480. {
  6481. case I::noDevice: return tr ("No audio device is open. Choose one in Settings > Audio.");
  6482. case I::noInputDevice:
  6483. 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.");
  6484. case I::noInputOpen: return tr ("No audio input is open, so nothing can be recorded. Choose an input device in Settings > Audio.");
  6485. case I::armedWithoutInput:
  6486. 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.");
  6487. case I::insertWithoutInput: return tr ("Insert {0} is armed but has no audio input, so it records nothing.", { juce::String (notice.track) });
  6488. case I::failed: return tr ("The audio input could not be used: {0}", { notice.detail });
  6489. case I::lowDisk:
  6490. return tr ("The recordings drive is almost full: about {0} minute(s) of recording left. Free some space or choose another project folder.",
  6491. { notice.detail });
  6492. case I::recordSafe:
  6493. return tr ("Insert {0} is record safe, so it can't be armed. Click its input box and turn \"Record safe\" off first.",
  6494. { juce::String (notice.track) });
  6495. case I::framesLost:
  6496. return tr ("The disk could not keep up while recording: {0} sample(s) became silence (the timing of the take was kept). "
  6497. "Record to a faster drive or close other programs that use the disk.", { notice.detail });
  6498. case I::none: break;
  6499. }
  6500. return {};
  6501. }
  6502. bool aboutTheDevice (AudioEngine::InputIssue issue)
  6503. {
  6504. using I = AudioEngine::InputIssue;
  6505. return issue == I::noDevice || issue == I::noInputDevice || issue == I::noInputOpen || issue == I::failed;
  6506. }
  6507. } // namespace
  6508. void explain (const AudioEngine::RecordingNotice& notice)
  6509. {
  6510. if (notice.issue == AudioEngine::InputIssue::none)
  6511. return;
  6512. using I = AudioEngine::InputIssue;
  6513. const auto aboutRecording = notice.issue == I::lowDisk || notice.issue == I::recordSafe || notice.issue == I::framesLost;
  6514. auto options = juce::MessageBoxOptions()
  6515. .withIconType (juce::MessageBoxIconType::WarningIcon)
  6516. .withTitle (aboutRecording ? tr ("Recording") : tr ("Audio input needed"))
  6517. .withMessage (issueText (notice));
  6518. if (aboutTheDevice (notice.issue) && openAudioSettings)
  6519. {
  6520. options = options.withButton (tr ("Audio settings...")).withButton (tr ("Close"));
  6521. juce::AlertWindow::showAsync (options, [] (int result) {
  6522. if (result == 1 && openAudioSettings)
  6523. openAudioSettings();
  6524. });
  6525. }
  6526. else
  6527. juce::AlertWindow::showAsync (options.withButton (tr ("OK")), nullptr);
  6528. }
  6529. // Round 157 ([DATA] the 0.1.15 projects of a singer who found that "the effects do nothing" on her voice): her
  6530. // microphone was the input of both Insert 1 (with the effects) and the Master. The Master plays its input straight
  6531. // away, without any insert's effects, so the dry voice covered the processed one. When an input is chosen and the
  6532. // Master plays the same device channel as an insert, LYNX says so and offers to take it off the Master.
  6533. void warnDoubleMonitoring (AudioEngine& engine, int track)
  6534. {
  6535. const auto& mixer = engine.getSong().mixer;
  6536. if (mixer.empty() || track < 0 || track >= (int) mixer.size())
  6537. return;
  6538. auto channels = [] (const MixerTrack& t) {
  6539. std::pair<int, int> r { t.inputChannel, t.inputChannel + (t.inputStereo ? 1 : 0) };
  6540. return r;
  6541. };
  6542. auto overlaps = [&] (const MixerTrack& a, const MixerTrack& b) {
  6543. if (a.inputChannel < 0 || b.inputChannel < 0)
  6544. return false;
  6545. const auto [a0, a1] = channels (a);
  6546. const auto [b0, b1] = channels (b);
  6547. return a0 <= b1 && b0 <= a1;
  6548. };
  6549. const auto& master = mixer[0];
  6550. if (master.inputChannel < 0 || master.monitor == InputMonitor::off)
  6551. return;
  6552. int insert = -1;
  6553. for (int t = 1; t < (int) mixer.size() && insert < 0; ++t)
  6554. if ((track == 0 || t == track) && overlaps (master, mixer[(std::size_t) t]))
  6555. insert = t;
  6556. if (insert < 0)
  6557. return;
  6558. const auto name = juce::String::fromUTF8 (mixer[(std::size_t) insert].name.c_str());
  6559. auto options = juce::MessageBoxOptions()
  6560. .withIconType (juce::MessageBoxIconType::WarningIcon)
  6561. .withTitle (tr ("The same input plays twice"))
  6562. .withMessage (tr ("This audio input is the input of the Master and of {0}. The Master plays it straight away, without "
  6563. "{0}'s effects, so you hear the dry sound on top of the processed one (the effects seem to do nothing).\n\n"
  6564. "To hear it through {0}'s effects, take it off the Master.", { name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (insert) }) }))
  6565. .withButton (tr ("Take it off the Master"))
  6566. .withButton (tr ("Keep both"));
  6567. juce::AlertWindow::showAsync (options, [&engine] (int result) {
  6568. if (result == 1)
  6569. engine.setInsertInput (0, -1, true);
  6570. });
  6571. }
  6572. // FL's question when an external input is chosen on an insert that records more than it (core/LiveInput.h
  6573. // asksExternalInputOnly, issue #152): Yes = "External input only", so the take holds the input alone.
  6574. // Live check 190ew ISS152-1: only when the insert had no input before (`inputBefore`), in FL's message window with its
  6575. // "Remember my choice" box (a remembered Yes switches without asking; Settings › Manage messages shows it again).
  6576. void askExternalInputOnly (AudioEngine& engine, int track, int inputBefore)
  6577. {
  6578. const auto& mixer = engine.getSong().mixer;
  6579. if (track < 0 || track >= (int) mixer.size())
  6580. return;
  6581. const auto& mt = mixer[(std::size_t) track];
  6582. if (! asksExternalInputOnly (track, inputBefore, mt.inputChannel, mt.recordSource))
  6583. return;
  6584. if (! messages::shown ("RecAutoSwitchExternalInput"))
  6585. {
  6586. engine.setInsertRecordSource (track, RecordSource::externalInput);
  6587. return;
  6588. }
  6589. // (FL marks "External input only" in its accent colour: the |bars| of its own string)
  6590. 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?"),
  6591. { tr ("Yes"), tr ("No") }, true },
  6592. [&engine, track] (int button, bool remember) {
  6593. if (button != 1)
  6594. return;
  6595. if (remember)
  6596. messages::setShown ("RecAutoSwitchExternalInput", false);
  6597. engine.setInsertRecordSource (track, RecordSource::externalInput);
  6598. });
  6599. }
  6600. void showMenu (AudioEngine& engine, int track, juce::Component* target, std::function<void()> chosen)
  6601. {
  6602. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  6603. return;
  6604. // FL: "The input of a mixer track can't be changed while recording." (a take keeps the channels it started with;
  6605. // issue #152)
  6606. if (engine.isRecordingAudioTakes())
  6607. {
  6608. juce::AlertWindow::showAsync (juce::MessageBoxOptions()
  6609. .withIconType (juce::MessageBoxIconType::WarningIcon)
  6610. .withTitle (tr ("Warning"))
  6611. .withMessage (tr ("The input of a mixer track can't be changed while recording."))
  6612. .withButton (tr ("OK")),
  6613. nullptr);
  6614. return;
  6615. }
  6616. // the device input opens on demand (only then does Windows show the microphone as in use)
  6617. if (! engine.hasAudioInput())
  6618. if (const auto result = engine.openAudioInput(); result.issue != AudioEngine::InputIssue::none)
  6619. {
  6620. explain (result);
  6621. return;
  6622. }
  6623. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  6624. const auto names = engine.getInputChannelNames();
  6625. juce::PopupMenu menu;
  6626. menu.addSectionHeader (tr ("Audio input source"));
  6627. menu.addItem (tr ("(none)"), true, mt.inputChannel < 0, [&engine, track] { engine.setInsertInput (track, -1, true); });
  6628. const auto sources = inputSources (names);
  6629. if (sources.empty())
  6630. menu.addItem (tr ("The audio device has no open input channels"), false, false, nullptr);
  6631. for (const auto& source : sources)
  6632. {
  6633. if (! source.stereo && source.channel == 0 && names.size() > 1)
  6634. menu.addSeparator(); // pairs, then single channels
  6635. const auto ticked = mt.inputChannel == source.channel && mt.inputStereo == source.stereo;
  6636. menu.addItem (juce::String::fromUTF8 (source.name.c_str()) + (source.stereo ? "" : " " + tr ("(mono)")), true, ticked,
  6637. [&engine, track, source, chosen, before = mt.inputChannel] {
  6638. engine.setInsertInput (track, source.channel, source.stereo);
  6639. warnDoubleMonitoring (engine, track);
  6640. askExternalInputOnly (engine, track, before);
  6641. if (chosen)
  6642. chosen();
  6643. });
  6644. }
  6645. if (track > 0) // FL's "Record" positions (round 168x, issue #41; FL's AudioRecorderRoutingMenu, in its order)
  6646. {
  6647. menu.addSectionHeader (tr ("Record"));
  6648. const std::pair<RecordSource, const char*> points[] = { { RecordSource::externalInput, TR_NOOP ("External input only") },
  6649. { RecordSource::externalAndMixer, TR_NOOP ("External and mixer input") },
  6650. { RecordSource::postEffects, TR_NOOP ("Post effects") },
  6651. { RecordSource::postEq, TR_NOOP ("Post EQ") },
  6652. { RecordSource::postLevel, TR_NOOP ("Post level and panning") },
  6653. { RecordSource::postTrack, TR_NOOP ("Post track") } };
  6654. for (const auto& [point, label] : points)
  6655. menu.addItem (tr (label), true, mt.recordSource == point, [&engine, track, point = point] { engine.setInsertRecordSource (track, point); });
  6656. // LYNX extra: the dry device input as a second take beside a processed one (DI + amp, for re-amping)
  6657. menu.addItem (tr ("Also record the dry input as a second take (LYNX)"), mt.recordSource != RecordSource::externalInput,
  6658. mt.recordDryToo && mt.recordSource != RecordSource::externalInput,
  6659. [&engine, track, on = mt.recordDryToo] { engine.setInsertRecordDryToo (track, ! on); });
  6660. }
  6661. menu.addSectionHeader (tr ("Monitor external input"));
  6662. const std::pair<InputMonitor, const char*> modes[] = { { InputMonitor::off, TR_NOOP ("Off") },
  6663. { InputMonitor::whenArmed, TR_NOOP ("When armed") },
  6664. { InputMonitor::automatic, TR_NOOP ("Auto (when armed, not while playing back)") },
  6665. { InputMonitor::on, TR_NOOP ("On") } };
  6666. for (const auto& [mode, label] : modes)
  6667. {
  6668. // the Master has no record arm: its input plays unless monitoring is off
  6669. if (track == 0 && (mode == InputMonitor::whenArmed || mode == InputMonitor::automatic))
  6670. continue;
  6671. const auto ticked = track == 0 ? (mode == InputMonitor::off) == (mt.monitor == InputMonitor::off) : mt.monitor == mode;
  6672. menu.addItem (tr (label), true, ticked, [&engine, track, mode = mode] { engine.setInsertMonitor (track, mode); });
  6673. }
  6674. if (track > 0) // record safe (round 163): the insert can't be armed by accident
  6675. {
  6676. menu.addSeparator();
  6677. menu.addItem (tr ("Record safe (can't be armed)"), true, mt.recordSafe,
  6678. [&engine, track, safe = mt.recordSafe] { engine.setInsertRecordSafe (track, ! safe); });
  6679. }
  6680. menu.addSeparator();
  6681. menu.addItem (tr ("Audio settings (input device)..."), openAudioSettings != nullptr, false, [] {
  6682. if (openAudioSettings)
  6683. openAudioSettings();
  6684. });
  6685. auto options = juce::PopupMenu::Options();
  6686. if (target != nullptr)
  6687. options = options.withTargetComponent (target).withMousePosition();
  6688. menu.showMenuAsync (options);
  6689. }
  6690. juce::String armHint (const AudioEngine& engine, int track)
  6691. {
  6692. auto text = tr ("Record arm: Rec + Play records this insert into a Playlist clip [RMB] record to a file");
  6693. if (track <= 0 || track >= (int) engine.getSong().mixer.size())
  6694. return text;
  6695. // FL's hint names the position: "Recording: Post EQ" (round 168x; changed in the input box's menu)
  6696. static const char* const points[] { TR_NOOP ("External input only"), TR_NOOP ("External and mixer input"), TR_NOOP ("Post effects"),
  6697. TR_NOOP ("Post EQ"), TR_NOOP ("Post level and panning"), TR_NOOP ("Post track") };
  6698. const auto& mt = engine.getSong().mixer[(std::size_t) track];
  6699. text = tr ("Recording: {0}", { tr (points[juce::jlimit (0, 5, (int) mt.recordSource)]) })
  6700. + (mt.recordDryToo && mt.recordSource != RecordSource::externalInput ? " + " + tr ("dry input") : juce::String()) + " " + text;
  6701. if (mt.recordTo.empty())
  6702. return text;
  6703. const auto file = juce::File (juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) track].recordTo.c_str()));
  6704. return tr ("Record to: {0}", { file.getFileName() }) + " " + text;
  6705. }
  6706. void chooseRecordTo (AudioEngine& engine, int track)
  6707. {
  6708. if (track <= 0 || track >= (int) engine.getSong().mixer.size())
  6709. return;
  6710. if (engine.getSong().mixer[(std::size_t) track].recordSafe)
  6711. {
  6712. AudioEngine::RecordingNotice notice;
  6713. notice.issue = AudioEngine::InputIssue::recordSafe;
  6714. notice.track = track;
  6715. explain (notice);
  6716. return;
  6717. }
  6718. const auto insert = juce::String::fromUTF8 (mixerops::insertDisplayName (engine.getSong(), track).c_str());
  6719. const auto& current = engine.getSong().mixer[(std::size_t) track].recordTo;
  6720. juce::File initial;
  6721. if (! current.empty() && juce::File::isAbsolutePath (juce::String::fromUTF8 (current.c_str())))
  6722. initial = juce::File (juce::String::fromUTF8 (current.c_str()));
  6723. else
  6724. {
  6725. // FL's default: Audio\Recorded, "<project title>_YYYY-MM-DD HH-MM-SS_<insert name>"
  6726. auto folder = engine.getRecordingFolder();
  6727. folder.createDirectory();
  6728. const auto now = juce::Time::getCurrentTime();
  6729. const auto name = juce::File::createLegalFileName (juce::String::fromUTF8 (
  6730. safety::recordingName (engine.getRecordingStem().toStdString(), now.getYear(), now.getMonth() + 1, now.getDayOfMonth(), now.getHours(),
  6731. now.getMinutes(), now.getSeconds(), insert.toStdString()).c_str()));
  6732. initial = folder.getChildFile (name + ".wav");
  6733. }
  6734. static std::unique_ptr<juce::FileChooser> chooser;
  6735. chooser = lynx::ui::makeFileChooser (tr ("Record {0} to", { insert }), initial, "*.wav");
  6736. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
  6737. [&engine, track] (const juce::FileChooser& fc) {
  6738. auto file = fc.getResult();
  6739. if (file == juce::File() || track >= (int) engine.getSong().mixer.size())
  6740. return;
  6741. if (! file.hasFileExtension (".wav"))
  6742. file = file.withFileExtension (".wav");
  6743. engine.editSong ([track, path = file.getFullPathName().toStdString()] (Song& s) {
  6744. if (track < (int) s.mixer.size())
  6745. s.mixer[(std::size_t) track].recordTo = path;
  6746. });
  6747. if (! engine.isInsertArmed (track)) // FL arms it (and the insert gets selected)
  6748. toggleArm (engine, track, nullptr);
  6749. });
  6750. }
  6751. void toggleArm (AudioEngine& engine, int track, juce::Component* /*target*/)
  6752. {
  6753. if (track < 0 || track >= (int) engine.getSong().mixer.size())
  6754. return;
  6755. // FL 2026: arms at once, also without an input source (the recording start reports a missing input)
  6756. switch (armClick (track, engine.isInsertArmed (track)))
  6757. {
  6758. case ArmClick::none: return;
  6759. case ArmClick::disarm: engine.setInsertArmed (track, false); return;
  6760. case ArmClick::arm:
  6761. engine.setInsertArmed (track, true);
  6762. if (const auto notice = engine.takeRecordingNotice(); notice.issue != AudioEngine::InputIssue::none)
  6763. explain (notice);
  6764. return;
  6765. }
  6766. }
  6767. } // namespace mixerinput
  6768. // ---------------------------------------------------------------------------
  6769. MixerLayoutBox::MixerLayoutBox (MixerStrips& s)
  6770. : strips (s)
  6771. {
  6772. setTooltip (tr ("Mixer layout"));
  6773. setMouseCursor (juce::MouseCursor::PointingHandCursor);
  6774. }
  6775. juce::PopupMenu MixerLayoutBox::menu (MixerStrips& strips)
  6776. {
  6777. juce::PopupMenu m;
  6778. for (int i = 0; i < mixerlayout::layoutCount; ++i)
  6779. {
  6780. const auto l = (mixerlayout::Layout) i;
  6781. m.addItem (tr (juce::String (std::string (mixerlayout::nameOf (l)))), true, MixerStrips::layout == l,
  6782. [&strips, l] { strips.setLayout (l); });
  6783. if (mixerlayout::separatorAfter (l))
  6784. m.addSeparator();
  6785. }
  6786. return m;
  6787. }
  6788. void MixerLayoutBox::paint (juce::Graphics& g)
  6789. {
  6790. using namespace theme;
  6791. const auto hot = isMouseOverOrDragging();
  6792. auto box = getLocalBounds().toFloat().reduced (1.0f, 2.0f);
  6793. theme::fillRoundRect (g, box, radius::sm, hot ? colour::bg4 : colour::bg2);
  6794. g.setColour (hot ? colour::borderStrong : colour::border);
  6795. g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
  6796. // round 170e: the strips icon names what the box is (it showed only "Wide")
  6797. icons::draw (g, Icon::mixer, box.withWidth (24.0f).withSizeKeepingCentre (14.0f, 14.0f), hot ? colour::textPrimary : colour::textSecondary);
  6798. g.setColour (colour::accent);
  6799. g.setFont (font (type::small, true));
  6800. g.drawFittedText (tr (juce::String (std::string (mixerlayout::nameOf (MixerStrips::layout)))), getLocalBounds().reduced (8, 0).withTrimmedLeft (18).withTrimmedRight (14),
  6801. juce::Justification::centredLeft, 1, 0.8f);
  6802. icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).withSizeKeepingCentre (12.0f, 12.0f), hot ? colour::textPrimary : colour::textSecondary);
  6803. }
  6804. void MixerLayoutBox::mouseDown (const juce::MouseEvent&)
  6805. {
  6806. menu (strips).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
  6807. }
  6808. MixerComponent::MixerComponent (AudioEngine& e)
  6809. : engine (e),
  6810. strips (e),
  6811. effects (e)
  6812. {
  6813. viewport.setViewedComponent (&strips, false);
  6814. viewport.setScrollBarsShown (false, true);
  6815. addAndMakeVisible (viewport);
  6816. effectsView.setViewedComponent (&effects, false);
  6817. effectsView.setScrollBarsShown (true, false);
  6818. effectsView.setScrollBarThickness (10);
  6819. addAndMakeVisible (effectsView);
  6820. strips.onSelectionChanged = [this] (int track) { effects.setTrack (track); };
  6821. strips.onEffectDropped = [this] (int track, EffectSlot fx) {
  6822. strips.selectTrack (track);
  6823. effects.setTrack (track);
  6824. if (! addEffectToSelected (std::move (fx)))
  6825. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Plugin database"),
  6826. tr ("The selected insert has no free effect slot."));
  6827. else // FL opens the dropped effect's window (round 171c: the Plugin picker's drag is FL's Browser drag)
  6828. openSlotEditor (track, (int) engine.getSong().mixer[(std::size_t) track].effects.size() - 1);
  6829. };
  6830. strips.onInstrumentDropped = [this] (int track, ChannelDef c) {
  6831. selectTrack (track);
  6832. if (onInstrumentDropped != nullptr)
  6833. onInstrumentDropped (track, std::move (c));
  6834. };
  6835. effects.onInstrumentDropped = strips.onInstrumentDropped;
  6836. }
  6837. bool MixerComponent::runAction (const std::string& id)
  6838. {
  6839. if (id == "mixer.moveLeft")
  6840. strips.moveSelected (-1);
  6841. else if (id == "mixer.moveRight")
  6842. strips.moveSelected (1);
  6843. else if (id == "mixer.linkChannels")
  6844. strips.linkSelectedChannels (false);
  6845. else if (id == "mixer.linkChannelsFrom")
  6846. strips.linkSelectedChannels (true);
  6847. else if (id == "mixer.selectLinkedChannels")
  6848. strips.selectLinkedChannels();
  6849. else if (id == "mixer.audioEditor")
  6850. return strips.runMenuItem (tr ("Open audio editor"));
  6851. else if (id == "mixer.audioEditorRecord")
  6852. return strips.runMenuItem (tr ("Open audio editor and record"));
  6853. else if (id == "mixer.rename") // FL's mixer menu keys (round 167k): the menu's own items
  6854. return strips.runMenuItem (tr ("Rename and color..."));
  6855. else if (id == "mixer.soloSelected")
  6856. return strips.runMenuItem (tr ("Solo selected track(s)"));
  6857. else if (id == "mixer.altSoloSelected")
  6858. return strips.runMenuItem (tr ("Alt solo selected track(s)"));
  6859. else if (id == "mixer.renderArmed")
  6860. return strips.runMenuItem (tr ("Render armed tracks to wave file(s)..."));
  6861. else if (id == "mixer.renderSelected")
  6862. return strips.runMenuItem (tr ("Render selected tracks to wave file(s)..."));
  6863. else if (id == "mixer.deleteTracks") // FL's Del: the selected mixer tracks, after its question (round 186c)
  6864. strips.deleteSelectedTracks();
  6865. else if (id == "mixer.deleteEffect") // FL: Delete on the selected effect slot (issue #11)
  6866. effects.deleteSlot (effects.getSelectedSlot());
  6867. else
  6868. return false;
  6869. return true;
  6870. }
  6871. bool MixerComponent::loadPresetOnSelection (const juce::File& file)
  6872. {
  6873. return mixerpresets::loadOnTracks (engine, strips.getSelection(), file);
  6874. }
  6875. bool MixerComponent::addEffectToSelected (EffectSlot slot)
  6876. {
  6877. const auto t = strips.getSelectedTrack();
  6878. bool added = false;
  6879. engine.editSong ([t, &slot, &added] (Song& s) {
  6880. if (s.mixer.empty())
  6881. s.mixer = Song::defaultMixer (0);
  6882. if (t < (int) s.mixer.size() && (int) s.mixer[(std::size_t) t].effects.size() < maxEffectSlots)
  6883. {
  6884. s.mixer[(std::size_t) t].effects.push_back (std::move (slot));
  6885. added = true;
  6886. }
  6887. });
  6888. if (added)
  6889. {
  6890. effects.setTrack (t);
  6891. effects.selectSlot ((int) engine.getSong().mixer[(std::size_t) t].effects.size() - 1);
  6892. }
  6893. return added;
  6894. }
  6895. void MixerComponent::selectFirstTrackWithEffects()
  6896. {
  6897. const auto& mixer = engine.getSong().mixer;
  6898. for (int t = 0; t < (int) mixer.size(); ++t)
  6899. if (! mixer[(std::size_t) t].effects.empty())
  6900. {
  6901. strips.selectTrack (t);
  6902. return;
  6903. }
  6904. }
  6905. void MixerComponent::selectTrack (int track)
  6906. {
  6907. strips.selectTrack (track);
  6908. // scroll the strip into view
  6909. const auto t = strips.getSelectedTrack();
  6910. const auto x = strips.stripLeft (t);
  6911. const auto w = strips.widthOf (t);
  6912. const auto view = viewport.getViewArea();
  6913. if (x < view.getX() || x + w > view.getRight())
  6914. viewport.setViewPosition (juce::jmax (0, x - view.getWidth() / 2), 0);
  6915. }
  6916. void MixerComponent::resized()
  6917. {
  6918. auto area = getLocalBounds();
  6919. effectsView.setBounds (area.removeFromRight (effectsWidth));
  6920. effects.fitToView (effectsView.getWidth(), effectsView.getHeight(), effectsView.getScrollBarThickness());
  6921. viewport.setBounds (area);
  6922. strips.setVisibleHeight (area.getHeight() - viewport.getScrollBarThickness());
  6923. }
  6924. } // namespace lynx