| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653 |
- #include "ui/FlMods.h"
- #include "platform/Paths.h"
- #include "ui/ColourPicker.h"
- #include "ui/FileChoosers.h"
- #include "ui/MixerComponent.h"
- #include "ui/SlotWatch.h"
- #include "core/ValueMath.h"
- #include "ui/UiTrace.h"
- #include "ui/TextCache.h"
- #include "core/Patcherize.h"
- #include "core/FlpImport.h"
- #include "engine/FlStudio.h"
- #include "core/FlEffects.h"
- #include "core/ProjectContents.h"
- #include "core/FruityVocoder.h"
- #include "core/LiveInput.h"
- #include "core/HardwareOutput.h"
- #include "core/MixerOps.h"
- #include "core/ProjectSafety.h"
- #include "core/Templates.h"
- #include "core/RackOps.h"
- #include "ui/AutomationUi.h"
- #include "ui/BrowserComponent.h"
- #include "ui/ExportDialog.h"
- #include <cmath>
- #include <complex>
- #include "core/Biquad.h"
- #include "core/Effects.h"
- #include "engine/Text.h"
- #include "engine/ProjectFile.h"
- #include <numeric>
- #include "ui/FacetEqEditor.h"
- #include "ui/ParametricEqEditor.h"
- #include "ui/PluginEditors.h"
- #include "ui/PluginWindow.h"
- #include "ui/HintBar.h"
- #include "ui/I18n.h"
- #include "core/LynxTune.h"
- #include "core/VocalPitch.h"
- #include "ui/Icons.h"
- #include "ui/ValueControl.h"
- #include "ui/Theme.h"
- #include "ui/AudioEditor.h"
- #include "ui/Dialogs.h"
- #include "ui/QuickPick.h"
- #include "ui/TrackIcons.h"
- #include "core/TrackIcons.h"
- namespace lynx
- {
- namespace
- {
- // strip layout, top to bottom: header (arm, number, icon, a horizontal name), the vertical name column (not in
- // Extra large; low in the strip in the alt layouts), knobs (pan, stereo), mute/solo, meters + fader, the dB read-out,
- // then the routing lane (send switch, send knob, wires). The rows follow FL's Mixer layout (MixerStrips::rows()).
- constexpr int switchHeight = 16;
- constexpr int sendKnobHeight = 26;
- constexpr int wiresHeight = 14;
- constexpr int laneHeight = switchHeight + sendKnobHeight + wiresHeight + 4;
- constexpr int masterScaleWidth = 17; // the dB numbers beside the master meter (round 162, issue #9)
- // Fader 0..1 -> dB, with 0.8 = 0 dB (as in FL).
- juce::String faderToDb (float volume)
- {
- if (volume <= 0.0001f)
- return juce::String::fromUTF8 ("-\xe2\x88\x9e");
- const auto db = juce::Decibels::gainToDecibels (faderGain (volume));
- return (db > 0 ? "+" : "") + juce::String (db, 1);
- }
- // Meter level 0..1 on a dB scale (-60..+6).
- float meterPosition (float gain)
- {
- const auto db = juce::Decibels::gainToDecibels (gain, -60.0f);
- return juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f);
- }
- // Stereo separation: -1 = widest, 0 = normal, +1 = mono (MixerTrack::stereo).
- ui::ValueSpec stereoSpec (const juce::String& name)
- {
- ui::ValueSpec spec;
- spec.name = name;
- spec.minimum = -1.0;
- spec.maximum = 1.0;
- spec.defaultValue = 0.0;
- spec.toText = [] (double v) {
- const auto percent = juce::roundToInt (std::abs (v) * 100.0);
- if (percent == 0)
- return tr ("Normal width");
- if (v > 0.0 && percent >= 100)
- return tr ("Mono");
- return v < 0.0 ? tr ("{0}% wider", { juce::String (percent) }) : tr ("{0}% narrower", { juce::String (percent) });
- };
- spec.fromText = [] (const juce::String& t) -> std::optional<double> {
- const auto lower = t.toLowerCase().trim();
- if (lower.startsWith ("mono"))
- return 1.0;
- if (lower.startsWith ("n") && ! lower.containsAnyOf ("0123456789"))
- return 0.0;
- const auto digits = lower.initialSectionContainingOnly ("+-0123456789.,").replaceCharacter (',', '.');
- if (digits.isEmpty() || digits.containsOnly ("+-."))
- return std::nullopt;
- auto v = digits.getDoubleValue() / 100.0;
- if (lower.contains ("wid") || lower.contains ("larg")) // "50% wider" / "50% mais largo"
- v = -std::abs (v);
- return v;
- };
- return spec;
- }
- // Online Sessions (round 168a): the amber "R" of an insert whose stand-in render plays
- void drawStandInTag (juce::Graphics& g, juce::Rectangle<float> tag)
- {
- theme::fillRoundRect (g, tag, 3.0f, theme::colour::warning.withAlpha (0.85f));
- g.setColour (theme::colour::bg1);
- g.setFont (theme::font (9.0f, true));
- g.drawText ("R", tag, juce::Justification::centred, false);
- }
- ui::ValueSpec sendSpec (const juce::String& name)
- {
- // FL's send knob: the fader curve (0 dB at 80 %, +5.6 dB at the top); the value is the knob position
- auto spec = ui::faderSpec (name, unityFader);
- spec.pixelsForRange = 120.0;
- return spec;
- }
- } // namespace
- MixerStrips::MixerStrips (AudioEngine& e)
- : engine (e)
- {
- setWantsKeyboardFocus (false);
- setMouseClickGrabsKeyboardFocus (false);
- engine.addChangeListener (this);
- engine.getLevelsBroadcaster().addChangeListener (this);
- updateSize();
- // 60 Hz: faders that follow their automation move every frame (round 171c); the meters keep their 30 Hz ballistics
- startTimerHz (60);
- }
- MixerStrips::~MixerStrips()
- {
- engine.getLevelsBroadcaster().removeChangeListener (this);
- engine.removeChangeListener (this);
- }
- void MixerStrips::setVisibleHeight (int height)
- {
- visibleHeight = juce::jmax (300, height);
- updateSize();
- }
- void MixerStrips::updateSize()
- {
- const auto tracks = (int) engine.getSong().mixer.size();
- layoutStrips();
- setSize (contentWidth, visibleHeight);
- levels.resize ((std::size_t) juce::jmax (1, tracks) * 2);
- }
- void MixerStrips::layoutStrips()
- {
- const auto& song = engine.getSong();
- const auto tracks = (int) song.mixer.size();
- stripXs.assign ((std::size_t) tracks + 1, 0);
- // "Show only used inserts" (round 163): unused inserts take no room, except those brought back with "+" (so a new
- // insert shows; selecting another strip doesn't move the strips under the mouse)
- hidden.assign ((std::size_t) tracks + 1, false);
- if (showUsedOnly)
- for (int t = 1; t < tracks; ++t)
- hidden[(std::size_t) t] = revealed.count (t) == 0 && ! song.insertInUse (t);
- dockGaps.clear();
- separatorLines.clear();
- int x = 4;
- bool any = false, afterMaster = false;
- for (auto dock : { MixerDock::left, MixerDock::middle, MixerDock::right })
- {
- const auto d = (int) dock;
- blockStart[d] = x;
- bool first = true;
- for (int t = 0; t < tracks; ++t)
- {
- const auto& track = song.mixer[(std::size_t) t];
- if (track.dock != dock)
- continue;
- if (hidden[(std::size_t) t])
- {
- stripXs[(std::size_t) t] = hiddenX;
- continue;
- }
- if (any && first && dock == MixerDock::right)
- {
- // the gap between two blocks belongs to the pinned block: the right block's is before its strips,
- // the left block's after them (below)
- dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
- x += dockGap;
- }
- else if (! first && track.separator && t > 0)
- {
- separatorLines.push_back ({ x + separatorGap / 2 - 3, dock });
- x += separatorGap;
- }
- else if (afterMaster)
- x += 8;
- stripXs[(std::size_t) t] = x;
- x += stripWidthOf (t);
- any = true;
- first = false;
- afterMaster = t == 0;
- }
- if (dock == MixerDock::middle) // the "+" button ends the middle block
- {
- if (afterMaster)
- x += 8;
- stripXs[(std::size_t) tracks] = x;
- x += spec().stripWidth;
- afterMaster = false;
- any = true;
- }
- blockEnd[d] = x;
- if (dock == MixerDock::left && ! first) // the left block carries its gap to the middle
- {
- dockGaps.push_back ({ x + dockGap / 2 - 2, dock });
- x += dockGap;
- blockEnd[d] = x;
- afterMaster = false;
- }
- }
- contentWidth = x + 8;
- }
- MixerDock MixerStrips::dockOf (int track) const noexcept
- {
- const auto& mixer = engine.getSong().mixer;
- return track >= 0 && track < (int) mixer.size() ? mixer[(std::size_t) track].dock : MixerDock::middle;
- }
- int MixerStrips::pinOffset (MixerDock dock) const noexcept
- {
- auto* parent = getParentComponent();
- if (parent == nullptr || dock == MixerDock::middle)
- return 0;
- const auto scroll = juce::jmax (0, -getX());
- const auto visible = parent->getWidth();
- if (dock == MixerDock::left)
- return blockEnd[0] > blockStart[0] ? juce::jmin (scroll, juce::jmax (0, contentWidth - blockEnd[0])) : 0;
- return blockEnd[2] > blockStart[2] ? juce::jmin (0, scroll + visible - contentWidth) : 0;
- }
- int MixerStrips::stripX (int track) const noexcept
- {
- if (track >= 0 && track < (int) stripXs.size())
- return stripXs[(std::size_t) track] + pinOffset (dockOf (track));
- return track == 0 ? 4 : 4 + spec().masterWidth + 8 + (track - 1) * spec().stripWidth;
- }
- bool MixerStrips::isInterestedInDragSource (const SourceDetails& details)
- {
- if (BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details))
- return true;
- if (! BrowserComponent::isBrowserDrag (details))
- return false;
- // (asked on every mouse move of the drag: the answer for the dragged file is kept)
- static juce::File lastFile;
- static bool lastAnswer = false;
- if (const auto file = BrowserComponent::draggedFile (details); file != lastFile)
- {
- lastFile = file;
- lastAnswer = mixerpresets::isMixerPreset (file);
- }
- return lastAnswer;
- }
- void MixerStrips::itemDropped (const SourceDetails& details)
- {
- const auto t = trackAt (details.localPosition.x);
- const auto tracks = (int) engine.getSong().mixer.size();
- // FL's mixer preset dropped from the Browser (WhatsNew): onto a track it loads there, onto the empty mixer space
- // (or "+") it makes a new track
- if (BrowserComponent::isBrowserDrag (details))
- {
- const auto file = BrowserComponent::draggedFile (details);
- if (! mixerpresets::isMixerPreset (file))
- return;
- if (t >= 0 && t < tracks)
- mixerpresets::loadOnTracks (engine, { t }, file);
- else if (const auto added = mixerpresets::insertTrack (engine, tracks, file); added > 0)
- {
- revealed.insert (added);
- updateSize();
- selectTrack (added);
- }
- return;
- }
- if (t < 0 || t >= tracks)
- return;
- if (auto fx = BrowserComponent::draggedEffect (details); fx && onEffectDropped != nullptr)
- onEffectDropped (t, std::move (*fx));
- else if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr)
- onInstrumentDropped (t, std::move (*c));
- }
- int MixerStrips::trackAt (int x) const noexcept
- {
- const auto tracks = (int) engine.getSong().mixer.size();
- // the pinned blocks lie over the scrolled middle: they are hit first
- for (auto dock : { MixerDock::left, MixerDock::right, MixerDock::middle })
- for (int t = 0; t <= tracks; ++t) // t == tracks = "+" button
- if (dockOf (t) == dock && x >= stripX (t) && x < stripX (t) + stripWidthOf (t))
- return t;
- return -1;
- }
- int MixerStrips::laneTop() const noexcept
- {
- return getHeight() - laneHeight;
- }
- const mixerlayout::Spec& MixerStrips::spec() noexcept
- {
- static mixerlayout::Layout cachedFor = (mixerlayout::Layout) -1;
- static mixerlayout::Spec cached;
- if (cachedFor != layout)
- {
- cached = mixerlayout::specOf (layout);
- cachedFor = layout;
- }
- return cached;
- }
- void MixerStrips::setLayout (mixerlayout::Layout newLayout)
- {
- if (newLayout == layout)
- return;
- layout = newLayout;
- updateSize();
- repaint();
- if (onLayoutChanged)
- onLayoutChanged();
- }
- MixerStrips::Rows MixerStrips::rows() const noexcept
- {
- const auto& sp = spec();
- const auto compact = mixerlayout::isCompact (layout);
- Rows r;
- r.header = sp.verticalName ? 38 : 54;
- // the vertical name column takes what the fader can spare (FL's runs the strip's upper part)
- r.nameHeight = sp.verticalName ? juce::jlimit (40, 110, (getHeight() - 300) / 2) : 0;
- r.knobsHeight = ! sp.stereoKnob ? sp.knobSize + 8 : sp.stackedKnobs ? sp.knobSize + (sp.knobSize - 6) + 10 : 32;
- r.buttonsHeight = compact ? 32 : 20; // compact: mute above solo
- r.readoutHeight = sp.dbReadout ? 16 : 0;
- auto y = r.header;
- if (sp.verticalName && ! sp.nameLow)
- {
- r.nameTop = y;
- y += r.nameHeight;
- }
- r.knobsTop = y;
- r.buttonsTop = r.knobsTop + r.knobsHeight;
- r.faderTop = r.buttonsTop + r.buttonsHeight + 6;
- auto bottom = laneTop() - r.readoutHeight - 4;
- if (compact)
- {
- r.armY = bottom - 14;
- bottom -= 16;
- }
- if (sp.verticalName && sp.nameLow)
- {
- // the alt layouts: the name runs up from the strip's bottom; the dB read-out stays under the fader, above the
- // name (rel 0.1.23: the read-out was drawn over the name's top)
- r.nameTop = bottom + r.readoutHeight - r.nameHeight;
- bottom = r.nameTop - 4 - r.readoutHeight;
- }
- r.faderBottom = juce::jmax (r.faderTop + 40, bottom);
- return r;
- }
- juce::Rectangle<int> MixerStrips::headerArea (int t) const
- {
- return { stripX (t), 0, stripWidthOf (t) - spec().gap, rows().header };
- }
- juce::Rectangle<int> MixerStrips::nameArea (int t) const
- {
- const auto r = rows();
- const auto w = stripWidthOf (t) - spec().gap;
- if (r.nameHeight <= 0) // Extra large: the name row of the header
- return { stripX (t) + 3, 38, w - 6, 14 };
- // the name runs up the strip's left part; the right part shows the meters (as FL's)
- const auto nameWidth = mixerlayout::isCompact (layout) ? w : juce::jmax (14, w - 2 * spec().meterWidth - 8);
- return { stripX (t), r.nameTop, nameWidth, r.nameHeight };
- }
- juce::Rectangle<int> MixerStrips::iconArea (int t) const
- {
- const auto w = stripWidthOf (t) - spec().gap;
- const auto size = juce::jmin (16, w - 2);
- return { stripX (t) + (w - size) / 2, rows().iconY, size, size };
- }
- juce::Rectangle<int> MixerStrips::armArea (int t) const
- {
- const auto r = rows();
- if (r.armY >= 0)
- {
- const auto w = stripWidthOf (t) - spec().gap;
- return { stripX (t) + (w - 13) / 2, r.armY, 13, 13 };
- }
- return { stripX (t) + 4, 4, 13, 13 };
- }
- juce::Rectangle<int> MixerStrips::inputArea (int t) const
- {
- // a thin level bar under the header (inserts with an input source)
- return { stripX (t) + 3, rows().header - 3, stripWidthOf (t) - spec().gap - 6, 3 };
- }
- juce::Rectangle<int> MixerStrips::panArea (int t) const
- {
- const auto r = rows();
- const auto& sp = spec();
- const auto w = stripWidthOf (t) - sp.gap;
- if (! sp.stereoKnob)
- return { stripX (t), r.knobsTop, w, r.knobsHeight };
- if (sp.stackedKnobs)
- return { stripX (t), r.knobsTop, w, sp.knobSize + 4 };
- return { stripX (t), r.knobsTop, w / 2, r.knobsHeight };
- }
- juce::Rectangle<int> MixerStrips::stereoArea (int t) const
- {
- const auto r = rows();
- const auto& sp = spec();
- const auto w = stripWidthOf (t) - sp.gap;
- if (! sp.stereoKnob)
- return {};
- if (sp.stackedKnobs)
- return { stripX (t), r.knobsTop + sp.knobSize + 4, w, r.knobsHeight - sp.knobSize - 4 };
- return { stripX (t) + w / 2, r.knobsTop, w - w / 2, r.knobsHeight };
- }
- juce::Rectangle<int> MixerStrips::muteArea (int t) const
- {
- const auto r = rows();
- const auto w = stripWidthOf (t) - spec().gap;
- if (mixerlayout::isCompact (layout))
- return { stripX (t), r.buttonsTop, w, 16 };
- if (t == 0)
- return { stripX (t) + 4, r.buttonsTop, 24, r.buttonsHeight };
- return { stripX (t) + 2, r.buttonsTop, w / 2 - 2, r.buttonsHeight };
- }
- juce::Rectangle<int> MixerStrips::soloArea (int t) const
- {
- const auto r = rows();
- const auto w = stripWidthOf (t) - spec().gap;
- if (mixerlayout::isCompact (layout))
- return { stripX (t) + (w - 16) / 2, r.buttonsTop + 16, 16, 16 };
- return { stripX (t) + w - juce::jmin (24, w / 2), r.buttonsTop, juce::jmin (24, w / 2), r.buttonsHeight };
- }
- juce::Rectangle<int> MixerStrips::faderArea (int t) const
- {
- const auto r = rows();
- const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
- return { stripX (t) + inset, r.faderTop, stripWidthOf (t) - spec().gap - 2 * inset, r.faderBottom - r.faderTop };
- }
- juce::Rectangle<int> MixerStrips::meterArea (int t) const
- {
- return faderArea (t).withWidth (spec().meterWidth * 2 + 2);
- }
- juce::Rectangle<int> MixerStrips::faderRail (int t) const
- {
- return faderArea (t).withTrimmedLeft (spec().meterWidth * 2 + (mixerlayout::isCompact (layout) ? 3 : 6) + (t == 0 ? masterScaleWidth : 0));
- }
- juce::Rectangle<int> MixerStrips::routeArea (int t) const
- {
- const auto inset = mixerlayout::isCompact (layout) ? 1 : 5;
- return { stripX (t) + inset, laneTop() + 2, stripWidthOf (t) - spec().gap - 2 * inset, switchHeight };
- }
- juce::Rectangle<int> MixerStrips::sendArea (int t) const
- {
- return { stripX (t), laneTop() + 2 + switchHeight, stripWidthOf (t) - spec().gap, sendKnobHeight };
- }
- MixerStrips::Part MixerStrips::partAt (int t, juce::Point<int> p) const
- {
- const auto& song = engine.getSong();
- if (t == (int) song.mixer.size())
- return Part::add;
- if (t < 0 || t > (int) song.mixer.size())
- return Part::none;
- const auto sending = selected > 0 && t != selected && selected < (int) song.mixer.size();
- if (t > 0 && armArea (t).expanded (1).contains (p))
- return Part::arm;
- if (t > 0 && t < (int) engine.getSong().mixer.size() && engine.getSong().mixer[(std::size_t) t].inputChannel >= 0
- && inputArea (t).expanded (0, 2).contains (p))
- return Part::input;
- if (headerArea (t).contains (p) || nameArea (t).contains (p))
- return Part::header;
- if (panArea (t).contains (p))
- return Part::pan;
- if (stereoArea (t).contains (p))
- return Part::stereo;
- if (muteArea (t).contains (p))
- return Part::mute;
- if (t > 0 && soloArea (t).contains (p))
- return Part::solo;
- if (sending && routeArea (t).contains (p) && (song.routes (selected, t) || song.canRoute (selected, t)))
- return Part::route;
- if (sending && sendArea (t).contains (p) && song.routes (selected, t))
- return Part::send;
- if (meterArea (t).contains (p))
- return Part::meter;
- if (faderRail (t).expanded (0, 6).contains (p))
- return Part::fader;
- return Part::body;
- }
- juce::Rectangle<int> MixerStrips::tipArea (Part part, int t) const
- {
- switch (part)
- {
- case Part::pan: return panArea (t);
- case Part::stereo: return stereoArea (t);
- case Part::send: return sendArea (t);
- case Part::route: return routeArea (t);
- case Part::fader:
- {
- const auto rail = faderRail (t);
- const auto& mixer = engine.getSong().mixer;
- const auto v = t >= 0 && t < (int) mixer.size() ? shownVolume (t) : 0.0f;
- const auto capY = rail.getBottom() - (int) (v * (float) rail.getHeight());
- return { rail.getX(), capY - 6, rail.getWidth(), 12 };
- }
- default: return {};
- }
- }
- void MixerStrips::showTip (Part part, int t, bool transient)
- {
- if (t < 0 || t >= (int) engine.getSong().mixer.size())
- return;
- const auto spec = specFor (part, t);
- const auto text = spec.text (valueOf (part, t));
- ui::postHint (ui::valueHint (spec, valueOf (part, t), ui::valueGestures()));
- if (transient)
- ui::flashValueTip (*this, tipArea (part, t), text);
- else
- ui::showValueTip (*this, tipArea (part, t), text);
- }
- void MixerStrips::setHover (Part part, int t)
- {
- if (part == hoverPart && t == hoverTrack)
- return;
- auto dirty = [this] (int track) {
- if (track >= 0)
- repaint (stripX (track) - 2, 0, stripWidthOf (track) + 4, getHeight());
- };
- dirty (hoverTrack);
- hoverPart = part;
- hoverTrack = t;
- dirty (hoverTrack);
- }
- void MixerStrips::mouseMove (const juce::MouseEvent& e)
- {
- const auto t = trackAt (e.x);
- setHover (t >= 0 ? partAt (t, e.getPosition()) : Part::none, t);
- }
- void MixerStrips::mouseExit (const juce::MouseEvent&)
- {
- setHover (Part::none, -1);
- }
- void MixerStrips::paint (juce::Graphics& g)
- {
- const uitrace::Scope trace ("MixerStrips paint", true, g.getClipBounds());
- using namespace theme;
- const auto& song = engine.getSong();
- const auto tracks = (int) song.mixer.size();
- const auto clip = g.getClipBounds();
- g.fillAll (colour::bg1);
- // the routing lane runs under all strips
- g.setColour (colour::bg0.withAlpha (0.55f));
- g.fillRect (0, laneTop() + switchHeight + sendKnobHeight + 2, getWidth(), wiresHeight + 2);
- // FL's separators (a line on the left of the track) and the gaps between the dock blocks (round 146a), drawn
- // per block so the pinned left / right blocks cover the scrolled middle (round 149)
- auto paintDividers = [&] (MixerDock dock) {
- const auto shift = pinOffset (dock);
- g.setColour (colour::borderStrong);
- for (auto [lx, d] : separatorLines)
- if (d == dock)
- theme::fillRoundRect (g, { (float) (lx + shift), 8.0f, 2.0f, (float) laneTop() - 14.0f }, 1.0f, colour::borderStrong);
- g.setColour (colour::bg0);
- for (auto [gx, d] : dockGaps)
- if (d == dock)
- g.fillRect (gx + shift - 3, 0, 6, getHeight());
- };
- for (auto pass : { MixerDock::middle, MixerDock::left, MixerDock::right })
- {
- if (pass == MixerDock::middle)
- {
- // "+" button
- if (tracks < maxMixerTracks)
- {
- const auto add = juce::Rectangle<int> (stripX (tracks), 2, spec().stripWidth - spec().gap, 60).toFloat();
- const auto addHovered = hoverPart == Part::add;
- theme::fillRoundRect (g, add, radius::md, addHovered ? colour::bg4 : colour::bg2);
- g.setColour (addHovered ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (add.reduced (0.5f), radius::md, 1.0f);
- icons::draw (g, Icon::plus, add.withSizeKeepingCentre (22.0f, 22.0f), addHovered ? colour::textPrimary : colour::textSecondary);
- }
- }
- else if (const auto shift = pinOffset (pass); shift != 0) // a pinned block hides what scrolls under it
- {
- const auto d = (int) pass;
- g.setColour (colour::bg1);
- g.fillRect (blockStart[d] + shift, 0, blockEnd[d] - blockStart[d], laneTop());
- g.setColour (colour::bg0.withAlpha (0.55f));
- g.fillRect (blockStart[d] + shift, laneTop(), blockEnd[d] - blockStart[d], getHeight() - laneTop());
- }
- for (int t = 0; t < tracks; ++t)
- {
- if (song.mixer[(std::size_t) t].dock != pass || isHidden (t))
- continue;
- const auto x = stripX (t);
- const auto w = stripWidthOf (t);
- if (x > clip.getRight() || x + w < clip.getX())
- continue;
- const auto& track = song.mixer[(std::size_t) t];
- const auto& sp = spec();
- const auto plateWidth = w - sp.gap;
- const auto compactLayout = mixerlayout::isCompact (layout);
- const auto strip = juce::Rectangle<int> (x, 2, plateWidth, laneTop() - 2);
- const auto isSelected = t == selected;
- const auto inSelection = std::binary_search (selection.begin(), selection.end(), t);
- const auto stripHovered = hoverTrack == t;
- const auto hovered = [this, t] (Part p) { return hoverTrack == t && hoverPart == p; };
- const auto dragging = [this, t] (Part p) { return dragTrack == t && dragPart == p; };
- // the strip is tinted with the insert's colour (FL tints whole strips, so groups read at a glance);
- // kept dark so meters, knobs and text keep their contrast
- auto plate = isSelected || inSelection ? colour::bg4 : (t == 0 ? colour::bg3 : stripHovered ? colour::bg3 : colour::bg2);
- if (track.colour != 0)
- plate = plate.interpolatedWith (tame (juce::Colour (track.colour)), isSelected ? 0.26f : 0.2f);
- theme::fillRoundRect (g, strip.toFloat(), radius::md, plate);
- if (track.colour != 0) // thin colour band at the top
- {
- theme::fillRoundRect (g, strip.toFloat().withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, tame (juce::Colour (track.colour)));
- }
- if (inSelection && ! isSelected)
- {
- g.setColour (colour::accent.withAlpha (0.3f));
- g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
- }
- if (isSelected)
- {
- g.setColour (colour::accent.withAlpha (0.55f));
- g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.0f);
- theme::fillRoundRect (g, strip.toFloat().withHeight (3.0f).reduced (6.0f, 0.0f), 1.5f, colour::accent);
- }
- if (headerDragged && headerDragTrack == t)
- {
- g.setColour (colour::accent);
- g.drawRoundedRectangle (strip.toFloat().reduced (0.5f), radius::md, 1.5f);
- }
- // record arm: the input recording goes through this insert
- if (t > 0)
- {
- const auto armed = engine.isInsertArmed (t);
- const auto r = armArea (t).toFloat().reduced (2.0f);
- g.setColour (armed ? colour::record : hovered (Part::arm) ? colour::bg5 : colour::bg0);
- g.fillEllipse (r);
- g.setColour (armed ? colour::record.brighter (0.3f) : hovered (Part::arm) ? colour::textSecondary : colour::borderStrong);
- g.drawEllipse (r, 1.0f);
- if (track.recordSafe) // record safe: a slash through the arm button
- {
- g.setColour (colour::textDisabled);
- g.drawLine (r.getX() + 1.0f, r.getBottom() - 1.0f, r.getRight() - 1.0f, r.getY() + 1.0f, 1.2f);
- }
- // the input level (inserts with an audio input source)
- if (track.inputChannel >= 0 && (std::size_t) t < inputLevels.size())
- {
- const auto bar = inputArea (t).toFloat();
- theme::fillRoundRect (g, bar, 1.0f, colour::bg0);
- const auto level = inputLevels[(std::size_t) t];
- const auto fill = juce::jlimit (0.0f, 1.0f, (juce::Decibels::gainToDecibels (level, -60.0f) + 60.0f) / 60.0f);
- theme::fillRoundRect (g, bar.withWidth (bar.getWidth() * fill), 1.0f, level >= 0.99f ? colour::record : colour::meterLow);
- }
- }
- // header: number and effect count on one line, the icon under them (FL's place), then the name: on the
- // header's last row (Extra large) or up a column of the strip (round 168h)
- g.setColour (isSelected ? colour::accent : colour::textSecondary);
- g.setFont (font (compactLayout ? 9.5f : type::caption, isSelected));
- textcache::drawFittedText (g, t == 0 ? juce::String ("M") : juce::String (t), juce::Rectangle<int> (x, 4, plateWidth, 13),
- juce::Justification::centred, 1, 0.6f);
- if (const auto icon = trackicons::iconFor (track.icon); icon != trackicons::Icon::none)
- ui::drawTrackIcon (g, icon, iconArea (t).toFloat(), track.muted ? colour::textDisabled : colour::textPrimary.withAlpha (0.88f));
- if (! track.effects.empty() && sp.fxBadge)
- {
- const auto on = mixerops::anyEffectEnabled (song, t);
- g.setColour (on ? colour::info : colour::textDisabled);
- g.setFont (font (9.0f, true));
- if (plateWidth >= 56)
- textcache::drawText (g, "FX" + juce::String ((int) track.effects.size()), x + plateWidth - 26, 4, 23, 13, juce::Justification::centredRight);
- else // narrow strips: a dot at the number's right
- g.fillEllipse ((float) (x + plateWidth) - 7.0f, 8.0f, 4.0f, 4.0f);
- }
- g.setColour (track.muted ? colour::textDisabled : (hovered (Part::header) ? colour::textPrimary : colour::textPrimary.withAlpha (0.9f)));
- g.setFont (font (compactLayout ? 10.0f : type::small, isSelected));
- // Online Sessions (round 168a): a plugin of this insert is not installed here, its stand-in render plays (an
- // amber R before the name)
- const auto standIn = engine.insertPlaysStandIn (t);
- const auto name = juce::String::fromUTF8 (track.name.c_str());
- if (const auto box = nameArea (t); ! sp.verticalName)
- {
- textcache::drawFittedText (g, name, box.withTrimmedLeft (standIn ? 16 : 0), juce::Justification::centred, 1, 0.7f);
- if (standIn)
- drawStandInTag (g, { (float) box.getX() + 1.0f, (float) box.getY() + 0.5f, 13.0f, 13.0f });
- }
- else
- {
- // the name reads bottom to top, as FL's narrow strips do
- auto column = box.reduced (2, 4);
- if (standIn)
- {
- drawStandInTag (g, juce::Rectangle<float> (13.0f, 13.0f).withCentre ({ (float) column.getCentreX(), (float) column.getBottom() - 6.5f }));
- column.removeFromBottom (16);
- }
- juce::Graphics::ScopedSaveState state (g);
- g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) column.getCentreX(), (float) column.getCentreY()));
- const auto rotated = juce::Rectangle<int> (column.getHeight(), column.getWidth()).withCentre (column.getCentre());
- g.drawFittedText (name, rotated, juce::Justification::centredLeft, 1, 0.8f);
- }
- // FL's narrow strips show the level beside the name too: two thin bars (Wide layouts)
- if (sp.verticalName && ! sp.nameLow && ! compactLayout && t > 0)
- {
- const auto box = nameArea (t);
- const auto bars = juce::Rectangle<int> (box.getRight() + 2, box.getY() + 6, plateWidth - box.getWidth() - 6, box.getHeight() - 12);
- theme::fillRoundRect (g, bars.toFloat(), 2.0f, colour::bg0.withAlpha (0.8f));
- for (int ch = 0; ch < 2; ++ch)
- {
- const auto index = (std::size_t) t * 2 + (std::size_t) ch;
- const auto level = index < levels.size() ? levels[index].level : 0.0f;
- const auto bw = (bars.getWidth() - 3) / 2;
- const auto bar = juce::Rectangle<int> (bars.getX() + 1 + ch * (bw + 1), bars.getY() + 1, bw, bars.getHeight() - 2);
- const auto h = (int) (meterPosition (level) * (float) bar.getHeight());
- g.setColour (level >= 1.0f ? colour::meterClip : level >= 0.5f ? colour::meterMid : colour::meterLow);
- g.fillRect (bar.withTop (bar.getBottom() - h));
- }
- }
- // compensated latency (PDC) on the Master
- if (t == 0 && engine.getLatencySamples() > 0 && ! compactLayout)
- {
- const auto ms = 1000.0 * engine.getLatencySamples() / juce::jmax (1.0, engine.getTransport().sampleRate.load());
- g.setColour (colour::textSecondary);
- g.setFont (font (10.0f));
- textcache::drawFittedText (g, "PDC " + juce::String (ms, 1) + " ms", soloArea (t).withX (x + 30).withWidth (w - 36),
- juce::Justification::centredLeft, 1, 0.8f); // the Master has no solo: use its spot
- }
- // pan and stereo separation
- const auto knob = (float) sp.knobSize;
- const auto stereoKnob = sp.stackedKnobs ? knob - 6.0f : 22.0f;
- drawKnob (g, panArea (t).toFloat().withSizeKeepingCentre (knob, knob),
- engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerPan, t }, (track.pan + 1.0f) * 0.5f), true,
- dragging (Part::pan) ? colour::accent : colour::info, hovered (Part::pan) || dragging (Part::pan));
- if (sp.stereoKnob)
- drawKnob (g, stereoArea (t).toFloat().withSizeKeepingCentre (stereoKnob, stereoKnob), (track.stereo + 1.0f) * 0.5f, true,
- dragging (Part::stereo) ? colour::accent : colour::knobArc, hovered (Part::stereo) || dragging (Part::stereo));
- // mute and solo
- {
- const auto led = compactLayout ? 10.0f : 12.0f;
- const auto m = muteArea (t).toFloat().withSizeKeepingCentre (led, led);
- g.setColour (muteLed (track.muted));
- g.fillEllipse (m);
- if (! track.muted || hovered (Part::mute))
- {
- g.setColour (hovered (Part::mute) ? colour::textSecondary : colour::ledOn.withAlpha (0.25f));
- g.drawEllipse (m.expanded (2.0f), 1.0f);
- }
- if (t > 0)
- {
- const auto s = soloArea (t).toFloat().reduced (2.0f);
- theme::fillRoundRect (g, s, radius::sm, track.solo ? colour::accent : hovered (Part::solo) ? colour::bg5 : colour::bg0);
- g.setColour (track.solo ? colour::onAccent : hovered (Part::solo) ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::caption, true));
- textcache::drawText (g, "S", s.toNearestInt(), juce::Justification::centred);
- }
- }
- // meters + fader
- {
- const auto area = faderArea (t);
- const auto meters = meterArea (t);
- const auto fader = faderRail (t);
- for (int ch = 0; ch < 2; ++ch)
- {
- const auto bar = juce::Rectangle<int> (meters.getX() + ch * (sp.meterWidth + 2), meters.getY(), sp.meterWidth, meters.getHeight());
- theme::fillRoundRect (g, bar.toFloat(), 1.5f, colour::bg0);
- const auto index = (std::size_t) t * 2 + (std::size_t) ch;
- const auto meter = index < levels.size() ? levels[index] : meters::PeakHold {};
- const auto h = (int) (meterPosition (meter.level) * (float) bar.getHeight());
- const auto lit = bar.withTop (bar.getBottom() - h);
- juce::ColourGradient gradient (colour::meterClip, (float) bar.getX(), (float) bar.getY(), colour::meterLow, (float) bar.getX(),
- (float) bar.getBottom(), false);
- gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (0.0f)), colour::meterClip); // above 0 dB: clip zone
- gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-6.0f)), colour::meterMid);
- gradient.addColour (1.0 - meterPosition (juce::Decibels::decibelsToGain (-18.0f)), colour::meterLow);
- g.setGradientFill (gradient);
- g.fillRect (lit);
- if (meter.peak > 0.001f) // peak hold line
- {
- const auto peakY = bar.getBottom() - (int) (meterPosition (meter.peak) * (float) bar.getHeight());
- g.setColour (meter.peak >= 1.0f ? colour::meterClip : meter.peak >= 0.5f ? colour::meterMid : colour::textPrimary.withAlpha (0.85f));
- g.fillRect (bar.getX(), juce::jmax (bar.getY(), peakY - 1), bar.getWidth(), 2);
- }
- if (meter.clipped) // clip latch: stays until the meter is clicked
- {
- g.setColour (colour::meterClip);
- g.fillRect (bar.withHeight (4));
- }
- }
- if (hovered (Part::meter))
- {
- g.setColour (colour::textSecondary.withAlpha (0.5f));
- g.drawRect (meters.expanded (1), 1);
- }
- // the master's dB scale (FL prints it beside the master meter): as many values as fit without overlapping
- if (t == 0)
- {
- const auto scaleFont = font (9.0f);
- const auto textHeight = 10.0f;
- const auto left = (float) meters.getRight() + 1.0f;
- g.setFont (scaleFont);
- for (auto db : lynx::meters::scaleMarks ((float) meters.getHeight(), textHeight + 1.0f))
- {
- const auto y = (float) meters.getBottom() - lynx::meters::scalePosition ((float) db) * (float) meters.getHeight();
- g.setColour (db == 0 ? colour::textPrimary : colour::textSecondary);
- g.fillRect (juce::Rectangle<float> (left, y - 0.5f, 2.0f, 1.0f));
- const auto box = juce::Rectangle<float> (left + 2.0f, y - textHeight * 0.5f, (float) masterScaleWidth - 2.0f, textHeight)
- .withY (juce::jlimit ((float) meters.getY(), (float) meters.getBottom() - textHeight, y - textHeight * 0.5f));
- textcache::drawText (g, (db > 0 ? "+" : "") + juce::String (db), box, juce::Justification::centredRight, false);
- }
- }
- // fader track and 0 dB mark
- const auto railX = (float) fader.getCentreX();
- const auto volume = shownVolume (t); // (its automation's value while it plays: the fader moves, issue #12)
- const auto capY = (float) fader.getBottom() - volume * (float) fader.getHeight();
- theme::fillRoundRect (g, { railX - 2.0f, (float) fader.getY(), 4.0f, (float) fader.getHeight() }, 2.0f, colour::bg0);
- 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));
- const auto unityY = (float) fader.getBottom() - unityFader * (float) fader.getHeight();
- g.setColour (colour::textDisabled);
- g.drawHorizontalLine ((int) unityY, (float) fader.getX(), railX - 5.0f);
- g.drawHorizontalLine ((int) unityY, railX + 5.0f, (float) fader.getRight());
- const auto capActive = hovered (Part::fader) || dragging (Part::fader);
- const auto capWidth = juce::jmin ((float) fader.getWidth() + 2.0f, 26.0f);
- const auto cap = juce::Rectangle<float> (capWidth, 12.0f).withCentre ({ railX, capY });
- theme::fillRoundRect (g, cap.translated (0.0f, 1.5f), radius::sm, juce::Colours::black.withAlpha (0.35f));
- // same cap as the LookAndFeel's linear faders
- theme::fillRoundRect (g, cap, radius::sm, capActive ? juce::Colour (0xffffffff) : juce::Colour (0xffd4d7dd));
- g.setColour ((dragging (Part::fader) ? colour::accent : colour::bg0).withAlpha (0.8f));
- g.fillRect (cap.withSizeKeepingCentre (capWidth - 8.0f, 1.5f));
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- if (sp.dbReadout)
- textcache::drawFittedText (g, faderToDb (volume) + " dB", juce::Rectangle<int> (x, area.getBottom() + 3, plateWidth, 14), juce::Justification::centred, 1, 0.7f);
- // a hardware output target (REA round 156, optional): a small badge at the fader's top right
- if (mixeroutput::isCustom (engine, t))
- {
- const auto text = mixeroutput::label (engine, t, true);
- const auto badgeLeft = (float) meterArea (t).getRight() + 3.0f + (t == 0 ? (float) masterScaleWidth : 0.0f);
- const auto badge = juce::Rectangle<float> (badgeLeft, (float) area.getY(), (float) (x + w - 6) - badgeLeft, 12.0f);
- theme::fillRoundRect (g, badge, 3.0f, colour::bg0.withAlpha (0.85f));
- g.setColour (text.endsWith ("?") ? colour::textDisabled : colour::info);
- g.setFont (font (9.0f, true));
- textcache::drawFittedText (g, text, badge.toNearestInt(), juce::Justification::centred, 1, 0.7f);
- }
- }
- // routing lane: send switch from the selected insert to this one, and its level knob
- if (selected > 0 && t != selected && selected < tracks)
- {
- const auto r = routeArea (t).toFloat();
- const auto on = song.routes (selected, t);
- const auto possible = on || song.canRoute (selected, t);
- const auto feedsSelected = t > 0 && song.routes (t, selected);
- if (possible)
- {
- theme::fillRoundRect (g, r, radius::sm, on ? colour::accent : hovered (Part::route) ? colour::bg5 : colour::bg0);
- if (hovered (Part::route))
- {
- g.setColour (on ? colour::accentHover : colour::textSecondary);
- g.drawRoundedRectangle (r.reduced (0.5f), radius::sm, 1.0f);
- }
- g.setColour (on ? colour::onAccent : colour::textSecondary);
- g.setFont (font (10.0f, on));
- textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + (t == 0 ? juce::String ("M") : juce::String (t)), r.toNearestInt(),
- juce::Justification::centred);
- // the route's level knob (FL's route knob), on the routes to inserts and to Master
- if (on)
- drawKnob (g, sendArea (t).toFloat().withSizeKeepingCentre (compactLayout ? 16.0f : 22.0f, compactLayout ? 16.0f : 22.0f),
- engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerSend, selected, t },
- faderPosition (song.routeLevel (selected, t))),
- false,
- dragging (Part::send) ? colour::accent : colour::accentHover, hovered (Part::send) || dragging (Part::send));
- }
- else if (feedsSelected) // this insert sends into the selected one
- {
- theme::fillRoundRect (g, r, radius::sm, colour::info.withAlpha (0.18f));
- g.setColour (colour::info);
- g.setFont (font (10.0f, true));
- textcache::drawText (g, (compactLayout ? juce::String() : juce::String::fromUTF8 ("\xe2\x86\x92 ")) + juce::String (selected), r.toNearestInt(), juce::Justification::centred);
- }
- }
- }
- paintDividers (pass);
- }
- paintRouting (g);
- }
- // Wires in the lane under the strips: from the selected insert to where it sends (accent), and from the
- // inserts that feed it (blue). The Master output is drawn dimmer.
- void MixerStrips::paintRouting (juce::Graphics& g)
- {
- using namespace theme;
- const auto& song = engine.getSong();
- const auto tracks = (int) song.mixer.size();
- if (selected <= 0 || selected >= tracks)
- return;
- const auto top = (float) (laneTop() + switchHeight + sendKnobHeight + 3);
- const auto bottom = top + (float) wiresHeight - 2.0f;
- const auto centre = [this] (int t) { return (float) stripX (t) + (float) (stripWidthOf (t) - 4) * 0.5f; };
- auto wire = [&] (int from, int to, juce::Colour c, float thickness) {
- const auto x0 = centre (from), x1 = centre (to);
- juce::Path p;
- p.startNewSubPath (x0, top);
- p.cubicTo (x0, bottom + 2.0f, x1, bottom + 2.0f, x1, top);
- g.setColour (c);
- g.strokePath (p, juce::PathStrokeType (thickness, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
- g.fillEllipse (x1 - 2.5f, top - 2.5f, 5.0f, 5.0f);
- };
- const auto& from = song.mixer[(std::size_t) selected];
- for (int t = 1; t < tracks; ++t)
- if (t != selected && song.routes (t, selected))
- wire (t, selected, colour::info.withAlpha (0.85f), 1.5f);
- if (from.toMaster)
- wire (selected, 0, colour::accent.withAlpha (0.4f), 1.0f);
- for (const auto& send : from.sends)
- if (send.target > 0 && send.target < tracks)
- wire (selected, send.target, colour::accent.withAlpha (0.5f + 0.5f * juce::jlimit (0.0f, 1.0f, send.level)), 1.8f);
- g.setColour (colour::accent);
- g.fillEllipse (centre (selected) - 3.0f, top - 3.0f, 6.0f, 6.0f);
- }
- void MixerStrips::mouseDown (const juce::MouseEvent& e)
- {
- const auto t = trackAt (e.x);
- if (t < 0)
- return;
- const auto part = partAt (t, e.getPosition());
- headerDragTrack = -1;
- headerDragged = false;
- if (part == Part::add && flmods::popup (e.mods))
- {
- // FL's "+" menu (round 166d [SHOT]): Add one / Add multiple...
- juce::PopupMenu menu;
- const auto count = (int) engine.getSong().mixer.size();
- const auto room = mixerops::roomForInserts (engine.getSong()) > 0;
- menu.addItem (tr ("Add one"), room, false, [this, count] {
- engine.editSong ([count] (Song& s) { mixerops::insertTracks (s, juce::jmax (1, count), 1); });
- revealed.insert (juce::jmax (1, count));
- updateSize();
- selectTrack (juce::jmax (1, count));
- });
- menu.addItem (tr ("Add multiple..."), room, false, [this, count] { askInsertMultiple (juce::jmax (1, count)); });
- // FL's "Add from state" (REA round 167q: AddMixerTracksMenu, FUN_012a87d0 / FUN_012a83b0)
- juce::PopupMenu fromState;
- for (const auto& f : mixerpresets::all())
- fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, count, f] {
- if (const auto added = mixerpresets::insertTrack (engine, juce::jmax (1, count), f); added > 0)
- {
- revealed.insert (added);
- updateSize();
- selectTrack (added);
- }
- });
- menu.addSubMenu (tr ("Add from state"), fromState, room && fromState.getNumItems() > 0);
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- return;
- }
- if (part == Part::add)
- {
- if (showUsedOnly) // the first unused insert (hidden) comes back before a new one is added
- if (const auto free = engine.getSong().nextFreeInsert(); free > 0 && isHidden (free))
- {
- revealed.insert (free);
- updateSize();
- selectTrack (free);
- return;
- }
- const auto added = (int) engine.getSong().mixer.size();
- engine.editSong ([] (Song& s) {
- if (s.mixer.empty())
- s.mixer = Song::defaultMixer (0);
- if ((int) s.mixer.size() >= maxMixerTracks)
- return;
- auto& track = s.mixer.emplace_back();
- track.name = "Insert " + std::to_string (s.mixer.size() - 1);
- });
- if (added < (int) engine.getSong().mixer.size())
- {
- revealed.insert (added); // shown even while unused
- updateSize();
- selectTrack (added);
- }
- return;
- }
- if (part == Part::arm)
- {
- if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a); the input box keeps the input menu
- mixerinput::chooseRecordTo (engine, t);
- else
- mixerinput::toggleArm (engine, t, this);
- repaint();
- return;
- }
- if (part == Part::input)
- {
- mixerinput::showMenu (engine, t, this);
- return;
- }
- if (part == Part::meter && ! flmods::popup (e.mods)) // clears the clip latch and the peak hold, and selects (as FL)
- {
- for (int ch = 0; ch < 2; ++ch)
- if (const auto i = (std::size_t) t * 2 + (std::size_t) ch; i < levels.size())
- levels[i].resetClip();
- repaint (meterArea (t).expanded (2));
- }
- if (part == Part::route && flmods::popup (e.mods))
- {
- showSendMenu (t);
- return;
- }
- if (part == Part::send)
- {
- const auto from = selected;
- if (flmods::popup (e.mods))
- {
- juce::PopupMenu menu;
- const auto spec = specFor (Part::send, t);
- menu.addSectionHeader (spec.name + ": " + spec.text (valueOf (Part::send, t)));
- ui::addValueItems (menu, *this, &engine, spec, valueOf (Part::send, t), [this, t] (double v) { setValue (Part::send, t, v); });
- menu.addSeparator();
- menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
- [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- return;
- }
- if (ui::isResetClick (e))
- {
- setValue (Part::send, t, unityFader); // 0 dB
- showTip (Part::send, t, true);
- return;
- }
- dragPart = Part::send;
- dragTrack = t;
- drag.begin (e, valueOf (Part::send, t));
- showTip (Part::send, t, false);
- return;
- }
- if (part == Part::mute && (flmods::popup (e.mods) || flmods::ctrl (e.mods))) // solo on the same LED
- {
- soloExclusive (t);
- return;
- }
- if (part == Part::route)
- {
- // the selection is the send source: don't change it. FL (round 170b, REA FUN_012aa110): the arrow acts on every
- // selected track; Ctrl = route to this track only, Shift = sidechain, Ctrl+Shift = sidechain only.
- const auto from = selected;
- const auto sources = selection;
- using K = mixerops::RouteKind;
- if (flmods::ctrl (e.mods) || e.mods.isShiftDown())
- {
- routeSelection (t, flmods::ctrl (e.mods) ? (e.mods.isShiftDown() ? K::sidechainOnly : K::routeOnly) : K::sidechain);
- return;
- }
- const auto on = engine.getSong().routes (from, t);
- engine.editSong ([sources, t, on] (Song& s) { mixerops::switchSelectedRoute (s, sources, t, ! on); });
- if (! on && engine.getSong().routes (from, t)) // just enabled (at 0 dB): dragging adjusts the level, like the route knob
- {
- dragPart = Part::send;
- dragTrack = t;
- drag.begin (e, unityFader);
- }
- return;
- }
- if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && flmods::ctrl (e.mods) && t > 0)
- {
- // FL (round 170b, REA FUN_012c5800 / FUN_012c5f60): Ctrl+click (and drag across the strips) selects the tracks
- // from here to the mouse, alone; Ctrl+Shift adds them to the selection, or removes them when the click starts
- // on a selected track
- selectAnchor = t;
- selectAdding = ! e.mods.isShiftDown() || ! std::binary_search (selection.begin(), selection.end(), t);
- selectBase.clear();
- if (e.mods.isShiftDown())
- selectBase = selection;
- dragSelectTo (t);
- return;
- }
- if ((part == Part::body || part == Part::header || part == Part::meter) && ! flmods::popup (e.mods) && e.mods.isShiftDown() && t > 0)
- {
- auto s = selection;
- {
- s.clear();
- for (int i = juce::jmin (selected, t); i <= juce::jmax (selected, t); ++i)
- s.push_back (i);
- }
- setSelection (s, std::find (s.begin(), s.end(), t) != s.end() ? t : s.front());
- return;
- }
- // a plain click on a track outside the selection selects only it; inside, the group stays
- if (! std::binary_search (selection.begin(), selection.end(), t))
- setSelection ({ t }, t);
- else if (selected != t)
- setSelection (selection, t);
- if (part == Part::pan || part == Part::fader || part == Part::stereo)
- {
- if (flmods::popup (e.mods))
- {
- ui::showValueMenu (*this, part == Part::stereo ? nullptr : &engine, specFor (part, t), valueOf (part, t),
- [this, part, t] (double v) { setValue (part, t, v); });
- return;
- }
- if (ui::isResetClick (e))
- {
- setValue (part, t, specFor (part, t).defaultValue);
- showTip (part, t, true);
- return;
- }
- }
- if (flmods::popup (e.mods))
- {
- showMenu (t);
- return;
- }
- const auto& track = engine.getSong().mixer[(std::size_t) t];
- switch (part)
- {
- case Part::mute:
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].muted = ! s.mixer[(std::size_t) t].muted; });
- return;
- case Part::solo:
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].solo = ! s.mixer[(std::size_t) t].solo; });
- return;
- case Part::header:
- if (t > 0)
- headerDragTrack = t; // dragging sideways reorders
- return;
- case Part::stereo:
- dragPart = part;
- dragTrack = t;
- dragStartValue = track.stereo;
- drag.begin (e, dragStartValue);
- groupStart.clear();
- showTip (part, t, false);
- return;
- case Part::pan:
- case Part::fader:
- dragPart = part;
- dragTrack = t;
- dragStartValue = part == Part::pan ? track.pan : track.volume;
- if (part == Part::fader && ! flmods::ctrl (e.mods)) // clicking the track jumps the fader there
- {
- const auto area = faderRail (t);
- const auto capY = area.getBottom() - track.volume * (float) area.getHeight();
- if (std::abs ((float) e.y - capY) > 9.0f)
- {
- dragStartValue = juce::jlimit (0.0f, 1.0f, (float) (area.getBottom() - e.y) / (float) area.getHeight());
- engine.editSong ([t, v = dragStartValue] (Song& s) { s.mixer[(std::size_t) t].volume = v; });
- }
- }
- drag.begin (e, dragStartValue);
- groupStart.clear();
- groupGrab = dragStartValue;
- if (selection.size() > 1) // the selected strips follow, keeping their offsets
- for (auto s : selection)
- if (s != t && s < (int) engine.getSong().mixer.size())
- groupStart.push_back ({ s, part == Part::pan ? engine.getSong().mixer[(std::size_t) s].pan
- : engine.getSong().mixer[(std::size_t) s].volume });
- showTip (part, t, false);
- return;
- case Part::arm:
- case Part::route:
- case Part::send:
- case Part::meter:
- case Part::body:
- case Part::none:
- case Part::add:
- return;
- }
- }
- void MixerStrips::dragSelectTo (int t)
- {
- const auto count = (int) engine.getSong().mixer.size();
- if (selectAnchor < 1 || count < 2)
- return;
- t = juce::jlimit (1, count - 1, t);
- std::set<int> s (selectBase.begin(), selectBase.end());
- for (int i = juce::jmin (selectAnchor, t); i <= juce::jmax (selectAnchor, t); ++i)
- {
- if (isHidden (i) && i != t && i != selectAnchor)
- continue;
- if (selectAdding)
- s.insert (i);
- else
- s.erase (i);
- }
- if (s.empty())
- s.insert (t);
- // the track under the mouse becomes the current one (FL); when removing, a track that stays selected
- auto primary = t;
- if (! s.count (primary))
- primary = s.count (selected) ? selected : *s.rbegin();
- setSelection ({ s.begin(), s.end() }, primary);
- }
- void MixerStrips::mouseDrag (const juce::MouseEvent& e)
- {
- if (selectAnchor > 0)
- {
- if (const auto t = trackAt (juce::jlimit (0, getWidth() - 1, e.x)); t >= 0)
- dragSelectTo (t);
- return;
- }
- if (headerDragTrack > 0)
- {
- if (! headerDragged && std::abs (e.getDistanceFromDragStartX()) < 6)
- return;
- headerDragged = true;
- setMouseCursor (juce::MouseCursor::LeftRightResizeCursor);
- const auto count = (int) engine.getSong().mixer.size();
- const auto target = trackAt (e.x);
- if (target < 1 || target >= count)
- return;
- for (int guard = 0; guard < count && selected != target; ++guard)
- if (! moveSelected (target < selected ? -1 : 1))
- break;
- headerDragTrack = selected;
- repaint();
- return;
- }
- if (dragPart == Part::none)
- return;
- const auto t = dragTrack;
- setValue (dragPart, t, drag.update (e, specFor (dragPart, t)));
- showTip (dragPart, t, false);
- }
- ui::ValueSpec MixerStrips::specFor (Part part, int t) const
- {
- const auto& song = engine.getSong();
- const auto nameOf = [&song] (int track) {
- return track >= 0 && track < (int) song.mixer.size() ? juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) : juce::String();
- };
- const auto name = nameOf (t);
- if (part == Part::pan)
- {
- auto spec = ui::panSpec (name + " - " + tr ("Pan"));
- spec.pixelsForRange = 150.0;
- spec.target = AutomationTarget { AutomationTargetKind::mixerPan, t };
- return spec;
- }
- if (part == Part::stereo)
- return stereoSpec (name + " - " + tr ("Stereo separation"));
- if (part == Part::send)
- {
- auto spec = sendSpec (nameOf (selected) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + name + " - " + (t == 0 ? tr ("Level to Master") : tr ("Send level")));
- spec.target = AutomationTarget { AutomationTargetKind::mixerSend, selected, t }; // automatable (issue #12)
- return spec;
- }
- auto spec = ui::faderSpec (name + " - " + tr ("Volume"), unityFader);
- spec.pixelsForRange = juce::jmax (60, faderRail (juce::jmax (0, t)).getHeight());
- spec.target = AutomationTarget { AutomationTargetKind::mixerVolume, t };
- return spec;
- }
- double MixerStrips::valueOf (Part part, int t) const
- {
- const auto& song = engine.getSong();
- const auto& track = song.mixer[(std::size_t) t];
- if (part == Part::send)
- {
- return faderPosition (song.routeLevel (selected, t));
- }
- return part == Part::pan ? track.pan : part == Part::stereo ? track.stereo : track.volume;
- }
- void MixerStrips::setValue (Part part, int t, double value)
- {
- if (t < 0 || t >= (int) engine.getSong().mixer.size())
- return;
- if (part == Part::send)
- {
- const auto from = selected;
- engine.editSong ([from, t, v = faderGain ((float) value)] (Song& s) { s.setRouteLevel (from, t, v); });
- return;
- }
- if (part == Part::stereo)
- {
- engine.editLevels ([t, v = (float) value] (Song& s) { s.mixer[(std::size_t) t].stereo = v; });
- return;
- }
- // during a drag of a selected strip, the other selected strips move by the same amount
- const auto delta = (float) value - groupGrab;
- const auto group = dragTrack == t && dragPart == part ? groupStart : std::vector<std::pair<int, float>> {};
- if (part == Part::pan)
- engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
- s.mixer[(std::size_t) t].pan = v;
- for (auto [other, start] : group)
- if (other < (int) s.mixer.size())
- s.mixer[(std::size_t) other].pan = juce::jlimit (-1.0f, 1.0f, start + delta);
- });
- else if (part == Part::fader)
- engine.editLevels ([t, v = (float) value, group, delta] (Song& s) {
- s.mixer[(std::size_t) t].volume = v;
- for (auto [other, start] : group)
- if (other < (int) s.mixer.size())
- s.mixer[(std::size_t) other].volume = juce::jlimit (0.0f, 1.0f, start + delta);
- });
- }
- void MixerStrips::setSelection (std::vector<int> tracks, int primary)
- {
- const auto count = (int) engine.getSong().mixer.size();
- tracks.erase (std::remove_if (tracks.begin(), tracks.end(), [count] (int t) { return t < 0 || t >= count; }), tracks.end());
- primary = juce::jlimit (0, juce::jmax (0, count - 1), primary);
- tracks.push_back (primary);
- std::sort (tracks.begin(), tracks.end());
- tracks.erase (std::unique (tracks.begin(), tracks.end()), tracks.end());
- selection = tracks;
- const auto changed = primary != selected;
- selected = primary;
- repaint();
- if (changed && onSelectionChanged)
- onSelectionChanged (selected);
- }
- bool MixerStrips::moveSelected (int delta)
- {
- auto moved = selection;
- bool ok = false;
- engine.editSongStructural ([&] (Song& s) { ok = mixerops::moveTracks (s, moved, delta); });
- if (ok)
- setSelection (moved, juce::jlimit (1, (int) engine.getSong().mixer.size() - 1, selected + (delta < 0 ? -1 : 1)));
- return ok;
- }
- void MixerStrips::linkSelectedChannels (bool startingHere)
- {
- const auto channels = engine.getSelectedChannels();
- engine.editSong ([channels, t = selected, startingHere] (Song& s) { mixerops::linkChannels (s, channels, t, startingHere); });
- }
- void MixerStrips::selectLinkedChannels()
- {
- const auto channels = mixerops::channelsOn (engine.getSong(), selected);
- if (! channels.empty())
- engine.setChannelSelection (channels, channels.front());
- }
- void MixerStrips::soloExclusive (int t)
- {
- if (t <= 0)
- return;
- // solo only this track; again on the only soloed track clears the solo
- engine.editSong ([t] (Song& s) {
- const auto alone = s.mixer[(std::size_t) t].solo
- && std::none_of (s.mixer.begin() + 1, s.mixer.end(), [&] (const MixerTrack& m) { return &m != &s.mixer[(std::size_t) t] && m.solo; });
- for (std::size_t i = 1; i < s.mixer.size(); ++i)
- s.mixer[i].solo = ! alone && (int) i == t;
- });
- }
- void MixerStrips::routeSelection (int t, mixerops::RouteKind kind)
- {
- using K = mixerops::RouteKind;
- int linked = 0;
- engine.editSong ([sources = selection, t, kind, &linked] (Song& s) {
- mixerops::routeSelectedTo (s, sources, t, kind);
- if (t >= 0 && t < (int) s.mixer.size())
- for (const auto& fx : s.mixer[(std::size_t) t].effects)
- linked += std::find (sources.begin(), sources.end(), fx.sidechain) != sources.end() ? 1 : 0;
- });
- if ((kind == K::sidechain || kind == K::sidechainOnly) && t > 0 && linked == 0)
- // (round 170h: in the hint bar, not a box — FL says nothing here; adding the compressor links it)
- ui::postHint ({ tr ("Sidechain") + ": " + tr ("The link was made; add a compressor to this insert to use it."), {} }, 6000);
- }
- void MixerStrips::showSendMenu (int t)
- {
- const auto& song = engine.getSong();
- const auto from = selected;
- if (from <= 0 || from == t)
- return;
- const auto fromName = juce::String::fromUTF8 (song.mixer[(std::size_t) from].name.c_str());
- juce::PopupMenu menu;
- const auto sources = (int) std::count_if (selection.begin(), selection.end(), [t] (int x) { return x > 0 && x != t; });
- menu.addSectionHeader ((sources > 1 ? tr ("{0} selected tracks", { juce::String (sources) }) : fromName)
- + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()));
- // FL's route arrow menu (round 168s, issue #32 [SHOT] r168s c_f10): route / route only / sidechain / sidechain only
- const auto on = song.routes (from, t);
- const auto can = on || song.canRoute (from, t);
- using K = mixerops::RouteKind;
- // FL (round 170b, REA FUN_012aca70): every item acts on all the selected tracks, not only the current one
- auto route = [this, t] (K kind) { routeSelection (t, kind); };
- menu.addItem (tr ("Route to this track"), can && ! on, false, [route] { route (K::route); });
- menu.addItem (tr ("Route to this track only"), can, false, [route] { route (K::routeOnly); });
- menu.addSeparator();
- menu.addItem (tr ("Sidechain to this track"), t > 0 && can, false, [route] { route (K::sidechain); });
- menu.addItem (tr ("Sidechain to this track only"), t > 0 && can, false, [route] { route (K::sidechainOnly); });
- if (on)
- {
- menu.addSeparator();
- menu.addItem (t == 0 ? tr ("Remove the route to Master") : tr ("Remove this send"),
- [this, from, t] { engine.editSong ([from, t] (Song& s) { s.setRoute (from, t, false); }); });
- }
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- }
- void MixerStrips::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
- {
- const auto t = trackAt (e.x);
- if (t > 0 && t < (int) engine.getSong().mixer.size() && e.mods.isShiftDown())
- if (const auto part = partAt (t, e.getPosition()); part == Part::body || part == Part::header)
- {
- if (! std::binary_search (selection.begin(), selection.end(), t))
- setSelection ({ t }, t);
- moveSelected ((wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX) > 0.0f ? -1 : 1);
- return;
- }
- // (a spin that is scrolling the strips goes on scrolling over the faders and knobs, round 169c)
- if (t >= 0 && t < (int) engine.getSong().mixer.size() && ! ui::wheelScrolling())
- if (const auto part = partAt (t, e.getPosition()); part == Part::pan || part == Part::fader || part == Part::stereo || part == Part::send)
- {
- if (const auto v = ui::wheelValue (valueOf (part, t), e, wheel, specFor (part, t)))
- {
- setValue (part, t, *v);
- showTip (part, t, true);
- }
- return;
- }
- ui::noteWheelScroll(); // the wheel scrolls the strips (the viewport)
- juce::Component::mouseWheelMove (e, wheel);
- }
- ui::Hint MixerStrips::hintAt (juce::Point<int> p)
- {
- const auto active = dragPart == Part::pan || dragPart == Part::fader || dragPart == Part::stereo || dragPart == Part::send;
- const auto t = active ? dragTrack : trackAt (p.x);
- const auto& song = engine.getSong();
- ui::Hint h;
- if (t < 0 || t >= (int) song.mixer.size())
- {
- if (t == (int) song.mixer.size())
- h.text = tr ("Add a mixer insert");
- return h;
- }
- const auto part = active ? dragPart : partAt (t, p);
- const auto name = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
- const auto gesture = ui::valueGestures();
- // the channels that play into this insert (FL shows them by the insert; LYNX in the hint)
- auto feeds = [&song, t, tracks = (int) song.mixer.size()] {
- juce::StringArray names;
- for (const auto& c : song.channels)
- if (juce::jlimit (0, tracks - 1, c.mixerTrack) == t)
- names.add (juce::String::fromUTF8 (c.name.c_str()));
- if (names.isEmpty())
- return juce::String();
- const auto shown = names.size() > 6 ? names[0] + ", " + names[1] + ", " + names[2] + " +" + juce::String (names.size() - 3)
- : names.joinIntoString (", ");
- return " " + tr ("Channels: {0}", { shown });
- };
- // FL's "Track latency compensation" label (REA round 165f-mixer): the manual latency and the bypass, when set
- auto latency = [&song, t] {
- const auto& track = song.mixer[(std::size_t) t];
- juce::String text;
- if (track.latencyMs != 0.0f)
- text << " " << tr ("Track latency: {0}", { (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms" });
- if (track.latencyBypass == LatencyBypass::always)
- text << " " << tr ("Bypass track latency compensation") << ": " << tr ("Always");
- else if (track.latencyBypass == LatencyBypass::whenRecordingOrStopped)
- text << " " << tr ("Bypass track latency compensation") << ": " << tr ("When recording or not playing");
- return text;
- };
- switch (part)
- {
- case Part::pan:
- case Part::fader:
- case Part::stereo:
- case Part::send:
- return ui::valueHint (specFor (part, t), valueOf (part, t), gesture);
- case Part::mute: h.text = name + " - " + tr ("Click: mute. Right-click or Ctrl+click: solo"); break;
- case Part::arm: h.text = name + " - " + mixerinput::armHint (engine, t); h.hasMenu = true; break;
- case Part::input: h.text = name + " - " + tr ("Input level of this insert's audio input [LMB] choose the input"); h.hasMenu = true; break;
- case Part::solo: h.text = name + " - " + tr ("Solo"); break;
- case Part::meter: h.text = name + " - " + tr ("Peak meter (left/right) with peak hold [LMB] selects the track and clears the clip light"); break;
- 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;
- case Part::add: h.text = tr ("Add a mixer insert"); break;
- case Part::header:
- 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();
- h.hasMenu = true;
- if (engine.insertPlaysStandIn (t))
- 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)");
- break;
- case Part::body:
- case Part::none:
- 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();
- h.hasMenu = true;
- break;
- }
- return h;
- }
- void MixerStrips::mouseUp (const juce::MouseEvent&)
- {
- if (headerDragged)
- setMouseCursor (juce::MouseCursor::NormalCursor);
- if (dragPart != Part::none || headerDragged)
- repaint();
- headerDragTrack = -1;
- headerDragged = false;
- selectAnchor = -1;
- selectBase.clear();
- dragPart = Part::none;
- dragTrack = -1;
- drag.end();
- ui::hideValueTip();
- ui::clearPostedHint();
- }
- void MixerStrips::mouseDoubleClick (const juce::MouseEvent& e)
- {
- const auto t = trackAt (e.x);
- if (t < 0 || t >= (int) engine.getSong().mixer.size())
- return;
- const auto part = partAt (t, e.getPosition());
- if (part == Part::fader || part == Part::pan || part == Part::stereo || part == Part::send)
- {
- setValue (part, t, specFor (part, t).defaultValue);
- showTip (part, t, true);
- }
- }
- void MixerStrips::selectTrack (int track)
- {
- selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), track);
- selection = { selected };
- repaint();
- if (onSelectionChanged)
- onSelectionChanged (selected);
- }
- namespace
- {
- // The 3 knobs of each band of the track's built-in EQ (gain, frequency, width).
- class TrackEqEditor final : public juce::Component
- {
- public:
- TrackEqEditor (AudioEngine& e, int t)
- : engine (e),
- track (t)
- {
- const juce::String bands[] = { tr ("Low"), tr ("Mid"), tr ("High") };
- const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
- for (int b = 0; b < 3; ++b)
- {
- titles[(std::size_t) b].setText (bands[b], juce::dontSendNotification);
- titles[(std::size_t) b].setJustificationType (juce::Justification::centred);
- addAndMakeVisible (titles[(std::size_t) b]);
- auto& gain = knobs[(std::size_t) b][0];
- setup (gain, -18.0, 18.0, 0.1, " dB", eq.gainDb[(std::size_t) b]);
- gain.setDoubleClickReturnValue (true, 0.0);
- auto& hz = knobs[(std::size_t) b][1];
- setup (hz, 10.0, 16000.0, 1.0, " Hz", eq.hz[(std::size_t) b]);
- hz.setSkewFactorFromMidPoint (1000.0);
- auto& width = knobs[(std::size_t) b][2];
- setup (width, 0.0, 1.0, 0.01, "", eq.width[(std::size_t) b]);
- width.setTooltip (b == 1 ? tr ("Peak width (Q)") : tr ("Shelf slope"));
- }
- setSize (3 * 90, 3 * 74 + 24);
- }
- void resized() override
- {
- auto area = getLocalBounds();
- auto header = area.removeFromTop (20);
- for (int b = 0; b < 3; ++b)
- {
- titles[(std::size_t) b].setBounds (header.removeFromLeft (90));
- auto column = area.removeFromLeft (90);
- for (auto& k : knobs[(std::size_t) b])
- k.setBounds (column.removeFromTop (74));
- }
- }
- private:
- void setup (juce::Slider& s, double lo, double hi, double step, const char* suffix, float value)
- {
- s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 72, 16);
- s.setRange (lo, hi, step);
- s.setTextValueSuffix (suffix);
- s.setValue (value, juce::dontSendNotification);
- s.onValueChange = [this] { apply(); };
- addAndMakeVisible (s);
- }
- void apply()
- {
- TrackEq eq;
- for (std::size_t b = 0; b < 3; ++b)
- {
- eq.gainDb[b] = (float) knobs[b][0].getValue();
- eq.hz[b] = (float) knobs[b][1].getValue();
- eq.width[b] = (float) knobs[b][2].getValue();
- }
- engine.editSong ([t = track, eq] (Song& s) {
- if (t < (int) s.mixer.size())
- s.mixer[(std::size_t) t].eq = eq;
- });
- }
- AudioEngine& engine;
- int track;
- std::array<juce::Label, 3> titles;
- std::array<std::array<juce::Slider, 3>, 3> knobs; // [band][gain, frequency, width]
- };
- } // namespace
- void MixerStrips::showTrackEq (int t)
- {
- auto editor = std::make_unique<TrackEqEditor> (engine, t);
- juce::CallOutBox::launchAsynchronously (std::move (editor), getScreenBounds().withSize (10, 10).translated (getMouseXYRelative().x, getMouseXYRelative().y), nullptr);
- }
- namespace
- {
- juce::File mixerStatesFolder()
- {
- return lynx::platform::documentsFolder().getChildFile ("LYNX/Mixer states");
- }
- std::unique_ptr<juce::FileChooser>& mixerStateChooser()
- {
- static std::unique_ptr<juce::FileChooser> chooser;
- return chooser;
- }
- // --- FL's track latency menu (REA round 165f-mixer: DelayMenu, FUN_012ae090 / FUN_012ad520 / FUN_012acd30) ---------
- double sampleRateOf (const AudioEngine& engine)
- {
- return juce::jmax (1.0, engine.getTransport().sampleRate.load());
- }
- // The track's latency in the current PDC plan (its output: inputs + effects + manual), in ms
- double trackLatencyMs (const AudioEngine& engine, int t)
- {
- const auto& plan = engine.getPdcPlan();
- return t >= 0 && t < (int) plan.outLat.size() ? 1000.0 * plan.outLat[(std::size_t) t] / sampleRateOf (engine) : 0.0;
- }
- // FL's label: "(none)" or "<ms> ms / <samples> smp" of the manual latency
- juce::String manualLatencyText (const AudioEngine& engine, const MixerTrack& track)
- {
- if (track.latencyMs == 0.0f)
- return tr ("(none)");
- const auto samples = manualLatencySamples (track, sampleRateOf (engine));
- return (track.latencyMs > 0.0f ? "+" : "") + juce::String (track.latencyMs, 2) + " ms / " + (samples > 0 ? "+" : "") + juce::String (samples) + " smp";
- }
- void setTrackLatency (AudioEngine& engine, int t, double ms)
- {
- if (t < 0 || t >= (int) engine.getSong().mixer.size() || ! std::isfinite (ms))
- return;
- const auto v = (float) juce::jlimit ((double) -maxTrackLatencyMs, (double) maxTrackLatencyMs, ms);
- engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].latencyMs = v; });
- }
- // "Set in ms / samples / beats": FL's input box, the value in that unit (FUN_012ad520)
- void askTrackLatency (AudioEngine& engine, int t, int unit)
- {
- const auto& track = engine.getSong().mixer[(std::size_t) t];
- const auto rate = sampleRateOf (engine);
- const auto bpm = juce::jmax (1.0, engine.getSong().bpm);
- const juce::String units[] = { tr ("Latency (ms)"), tr ("Latency (samples)"), tr ("Latency (beats)") };
- const auto value = unit == 0 ? juce::String (track.latencyMs, 2)
- : unit == 1 ? juce::String (manualLatencySamples (track, rate))
- : juce::String (track.latencyMs * bpm / 60000.0, 6);
- auto* w = new juce::AlertWindow (tr ("Track latency"),
- tr ("Positive: the other tracks wait for this one (it plays earlier). Negative: this track is delayed."),
- juce::MessageBoxIconType::NoIcon);
- w->addTextEditor ("v", value, units[juce::jlimit (0, 2, unit)]);
- w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([w, &engine, t, unit, rate, bpm] (int result) {
- if (result != 1)
- return;
- const auto text = w->getTextEditorContents ("v").trim().replaceCharacter (',', '.');
- if (! text.containsAnyOf ("0123456789"))
- return;
- const auto v = text.getDoubleValue();
- setTrackLatency (engine, t, unit == 0 ? v : unit == 1 ? v * 1000.0 / rate : v * 60000.0 / bpm);
- }), true);
- }
- juce::PopupMenu trackLatencyMenu (AudioEngine& engine, int t)
- {
- const auto& song = engine.getSong();
- const auto& track = song.mixer[(std::size_t) t];
- juce::PopupMenu menu;
- // FL's hint "^Track latency": "<x>ms (auto) <y>ms (manual)"
- // auto = the plan's latency without the manual part, in samples (no ms rounding left over when no plugin has any)
- const auto total = trackLatencyMs (engine, t);
- const auto rate = sampleRateOf (engine);
- const auto autoMs = total - 1000.0 * lynx::manualLatencySamples (track, rate) / rate;
- menu.addSectionHeader (tr ("Latency {0} ms (auto {1} ms, manual {2} ms)",
- { juce::String (total, 2), juce::String (std::abs (autoMs) < 0.005 ? 0.0 : autoMs, 2), juce::String (track.latencyMs, 2) }));
- menu.addItem (tr ("Reset"), track.latencyMs != 0.0f, false, [&engine, t] { setTrackLatency (engine, t, 0.0); });
- menu.addItem (tr ("Set in ms..."), [&engine, t] { askTrackLatency (engine, t, 0); });
- menu.addItem (tr ("Set in samples..."), [&engine, t] { askTrackLatency (engine, t, 1); });
- menu.addItem (tr ("Set in beats..."), [&engine, t] { askTrackLatency (engine, t, 2); });
- {
- // FL's "Set from": the tracks whose latency is not zero; this track's total becomes theirs (FUN_012acd30)
- juce::PopupMenu from;
- for (int o = 0; o < (int) song.mixer.size(); ++o)
- {
- const auto ms = trackLatencyMs (engine, o);
- if (o == t || std::abs (ms) < 0.005)
- continue;
- const auto name = o == 0 ? tr ("Master") : juce::String (o) + " " + juce::String::fromUTF8 (song.mixer[(std::size_t) o].name.c_str());
- from.addItem (name + " (" + juce::String (ms, 2) + " ms)", [&engine, t, o] {
- const auto manual = (double) engine.getSong().mixer[(std::size_t) t].latencyMs + trackLatencyMs (engine, o) - trackLatencyMs (engine, t);
- if (manual < 0.0)
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Track latency"),
- tr ("The delay introduced by this mixer track is higher than the delay introduced by the source "
- "mixer track. Set a make-up latency on the source track instead."));
- else
- setTrackLatency (engine, t, manual);
- });
- }
- menu.addSubMenu (tr ("Set from"), from, from.getNumItems() > 0);
- }
- menu.addSeparator();
- menu.addItem (tr ("Compensate for master latency"), track.outputChannel >= 0, track.compensateMasterLatency, [&engine, t] {
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].compensateMasterLatency = ! s.mixer[(std::size_t) t].compensateMasterLatency; });
- });
- if (t > 0)
- {
- menu.addSectionHeader (tr ("Bypass track latency compensation"));
- const std::pair<const char*, LatencyBypass> modes[] = { { TR_NOOP ("Never"), LatencyBypass::never },
- { TR_NOOP ("Always"), LatencyBypass::always },
- { TR_NOOP ("When recording or not playing"), LatencyBypass::whenRecordingOrStopped } };
- for (const auto& [label, mode] : modes)
- menu.addItem (tr (label), true, track.latencyBypass == mode, [&engine, t, mode = mode] {
- engine.editSong ([t, mode] (Song& s) { s.mixer[(std::size_t) t].latencyBypass = mode; });
- });
- }
- return menu;
- }
- } // namespace
- bool loadMixerTrackState (AudioEngine& engine, int track, const juce::File& file, bool asNewInsert)
- {
- if (track < 0 || track >= (int) engine.getSong().mixer.size())
- return false;
- if (asNewInsert)
- return mixerpresets::insertTrack (engine, juce::jmax (1, track + 1), file) > 0;
- return mixerpresets::loadOnTracks (engine, { track }, file);
- }
- namespace mixerpresets
- {
- juce::Array<juce::File> folders()
- {
- // FL's browser folder 0x3f8 (REA round 167q, FUN_009db5b0): "Presets\Mixer presets" of the user data folder and
- // "Data\Patches\Mixer presets" of the installation
- static const auto fl = findFlStudio();
- juce::Array<juce::File> out;
- if (fl.userData.isDirectory())
- out.add (fl.userData.getChildFile ("Presets").getChildFile ("Mixer presets"));
- if (fl.installDir.isDirectory())
- out.add (fl.installDir.getChildFile ("Data").getChildFile ("Patches").getChildFile ("Mixer presets"));
- out.add (mixerStatesFolder());
- out.removeIf ([] (const juce::File& f) { return ! f.isDirectory(); });
- return out;
- }
- juce::Array<juce::File> all()
- {
- juce::Array<juce::File> files;
- for (const auto& folder : folders())
- for (const auto& f : folder.findChildFiles (juce::File::findFiles, true, juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension))
- files.add (f);
- std::stable_sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
- return a.getFileNameWithoutExtension().compareNatural (b.getFileNameWithoutExtension()) < 0;
- });
- return files;
- }
- static std::vector<std::uint8_t> bytesOf (const juce::File& file)
- {
- juce::MemoryBlock data;
- if (file.getSize() > 64 * 1024 * 1024 || ! file.loadFileAsData (data))
- return {};
- const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
- return { bytes, bytes + data.getSize() };
- }
- bool isMixerPreset (const juce::File& file)
- {
- if (file.hasFileExtension (ProjectFile::mixerTrackStateExtension))
- return true;
- if (! file.hasFileExtension ("fst"))
- return false;
- for (auto p = file.getParentDirectory(); p != juce::File() && p.getParentDirectory() != p; p = p.getParentDirectory())
- if (p.getFileName().equalsIgnoreCase ("Mixer presets"))
- return true;
- const auto bytes = bytesOf (file);
- return flp::looksLikeMixerPreset (bytes);
- }
- std::optional<MixerTrack> read (const juce::File& file)
- {
- if (file.hasFileExtension ("fst"))
- {
- FlpImportOptions options;
- options.roots = findFlStudioRoots();
- options.fileExists = [] (const std::string& path) { return platform::localFile (path).existsAsFile(); };
- options.readFile = [] (const std::string& path) { return bytesOf (platform::localFile (path)); };
- return mixerTrackFromFlPreset (bytesOf (file), options);
- }
- juce::String error;
- auto state = ProjectFile::mixerTrackStateFromJson (file.loadFileAsString(), error);
- if (state && state->name.empty())
- state->name = file.getFileNameWithoutExtension().toStdString();
- return state;
- }
- bool loadOnTracks (AudioEngine& engine, const std::vector<int>& tracks, const juce::File& file)
- {
- const auto state = read (file);
- if (! state)
- return false;
- // FL's mixer presets restore the track's name and colour (WhatsNew); LYNX's states keep the track's own
- const auto takeName = file.hasFileExtension ("fst") && ! state->name.empty();
- bool any = false;
- engine.editSong ([&] (Song& s) {
- for (const auto t : tracks)
- if (t >= 0 && t < (int) s.mixer.size())
- {
- ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) t], *state, takeName);
- any = true;
- }
- });
- return any;
- }
- int insertTrack (AudioEngine& engine, int at, const juce::File& file)
- {
- auto state = read (file);
- if (! state)
- return -1;
- if (state->name.empty())
- state->name = file.getFileNameWithoutExtension().toStdString();
- at = juce::jlimit (1, (int) engine.getSong().mixer.size(), at);
- bool ok = false;
- engine.editSong ([&] (Song& s) {
- ok = mixerops::insertTrack (s, at);
- if (ok)
- ProjectFile::applyMixerTrackState (s.mixer[(std::size_t) at], *state, true);
- });
- return ok ? at : -1;
- }
- } // namespace mixerpresets
- bool saveMixerTrackState (AudioEngine& engine, int track, const juce::File& file)
- {
- if (track < 0 || track >= (int) engine.getSong().mixer.size())
- return false;
- engine.capturePluginStates(); // the plugins' current settings go into the state
- file.getParentDirectory().createDirectory();
- return file.replaceWithText (ProjectFile::mixerTrackStateToJson (engine.getSong().mixer[(std::size_t) track]));
- }
- // FL's "Auto-create audio clip" (round 167a [SHOT s28–s37]): the rendered files go on the Playlist, one undo step
- static void placeRenderedFiles (AudioEngine& engine, const std::vector<juce::File>& files)
- {
- std::vector<mixerops::RenderedFile> list;
- juce::AudioFormatManager formats;
- formats.registerBasicFormats();
- for (const auto& f : files)
- if (std::unique_ptr<juce::AudioFormatReader> reader (formats.createReaderFor (f)); reader != nullptr)
- list.push_back ({ f.getFullPathName().toStdString(), (double) reader->lengthInSamples, reader->sampleRate });
- if (! list.empty())
- engine.editSong ([list] (Song& s) { mixerops::placeRenderedFiles (s, list); });
- }
- void MixerStrips::askInsertMultiple (int at)
- {
- auto* window = new juce::AlertWindow (tr ("Insert multiple"), tr ("How many blank inserts?"), juce::MessageBoxIconType::NoIcon);
- // FL 2026's box starts at 10, already selected; Ctrl+A selects it again (round 167a [SHOT s13–s15])
- window->addTextEditor ("count", "10");
- if (auto* field = window->getTextEditor ("count"))
- field->setInputRestrictions (4, "0123456789");
- window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- juce::Component::SafePointer<MixerStrips> safe (this);
- window->enterModalState (true, juce::ModalCallbackFunction::create ([safe, at, window] (int result) {
- if (safe == nullptr || result != 1)
- return;
- const auto n = window->getTextEditorContents ("count").getIntValue();
- const auto room = mixerops::roomForInserts (safe->engine.getSong());
- if (n > room) // FL 2026 shows "You can add a maximum of 375 tracks." (round 166d [SHOT]); nothing is added then
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Insert multiple"),
- tr ("You can add a maximum of {0} inserts.", { juce::String (room) }));
- return;
- }
- if (n > 0)
- {
- const auto first = juce::jlimit (1, (int) safe->engine.getSong().mixer.size(), at);
- safe->engine.editSong ([first, n] (Song& s) { mixerops::insertTracks (s, first, n); });
- for (int i = 0; i < n; ++i)
- safe->revealed.insert (first + i); // shown even while unused
- safe->updateSize();
- safe->selectTrack (first);
- }
- }),
- true);
- if (auto* field = window->getTextEditor ("count"))
- {
- field->grabKeyboardFocus();
- field->selectAll();
- }
- }
- void MixerStrips::showMenu (int t)
- {
- buildMenu (t).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- }
- bool MixerStrips::runMenuItem (const juce::String& caption)
- {
- auto menu = buildMenu (getSelectedTrack());
- for (juce::PopupMenu::MenuItemIterator it (menu, true); it.next();)
- {
- const auto& item = it.getItem();
- if (item.isEnabled && item.action != nullptr && item.subMenu == nullptr
- && item.text.upToFirstOccurrenceOf ("\t", false, false).trim() == caption)
- {
- const auto action = item.action; // (the menu goes away first)
- menu = {};
- action();
- return true;
- }
- }
- return false;
- }
- juce::PopupMenu MixerStrips::buildMenu (int t)
- {
- const auto& song = engine.getSong();
- const auto channel = engine.getSelectedChannel();
- juce::PopupMenu menu;
- if (t < 0 || t >= (int) song.mixer.size())
- return menu;
- // the tracks the "selected track(s)" items act on: the selection when the clicked track is in it
- const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
- const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
- auto rename = [this, t] {
- if (t >= (int) engine.getSong().mixer.size())
- return;
- const auto& track = engine.getSong().mixer[(std::size_t) t];
- showNameAndColourDialog (tr ("Rename track"), juce::String::fromUTF8 (track.name.c_str()), track.colour,
- [this, t] (const juce::String& name, std::uint32_t colour) {
- if (t < (int) engine.getSong().mixer.size())
- engine.editSong ([t, n = name.trim().toStdString(), colour] (Song& s) {
- if (! n.empty())
- s.mixer[(std::size_t) t].name = n;
- s.mixer[(std::size_t) t].colour = colour;
- });
- });
- };
- // the title band in the insert's colour (FL tints the whole menu); a double-click on it renames (issue #12)
- ui::addItemHeader (menu, t == 0 ? tr ("Master") : tr ("Mixer track {0}", { juce::String (t) }), trackName,
- song.mixer[(std::size_t) t].colour != 0 ? juce::Colour (song.mixer[(std::size_t) t].colour) : juce::Colour(), rename);
- // FL's first section: name and colour (REA_rodada115)
- menu.addItem (tr ("Rename and color...") + "\tF2", rename);
- menu.addSubMenu (tr ("Change color"), ui::colourMenu (song.mixer[(std::size_t) t].colour, [this, t] (std::uint32_t colour) {
- if (t < (int) engine.getSong().mixer.size())
- engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
- }, juce::Rectangle<int> (juce::Desktop::getMousePosition().x, juce::Desktop::getMousePosition().y, 1, 1)));
- menu.addItem (tr ("Random color"), [this, t] {
- const auto& palette = lynxPalette();
- const auto colour = palette[(std::size_t) juce::Random::getSystemRandom().nextInt ((int) palette.size())];
- engine.editSong ([t, colour] (Song& s) { s.mixer[(std::size_t) t].colour = colour; });
- });
- // FL's "Change icon..." (SetIconMenuClick, REA round 168h: every selected track gets it); LYNX's own icon set
- menu.addItem (tr ("Change icon..."), [this, t, targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t }] {
- 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) {
- engine.editSong ([targets, icon] (Song& s) {
- for (auto track : targets)
- if (track >= 0 && track < (int) s.mixer.size())
- s.mixer[(std::size_t) track].icon = icon;
- });
- });
- });
- menu.addSeparator();
- // FL's "File" submenu (REA round 167q, TFXForm's FileMenu): open/save a state, Browse states and the "States" list
- // of FL's mixer presets (FL's own .fst and the user's) and LYNX's .lynxtrack states, loaded onto every selected
- // track (FUN_012a7440)
- {
- const auto targets = std::find (selection.begin(), selection.end(), t) != selection.end() ? selection : std::vector<int> { t };
- juce::PopupMenu file;
- file.addItem (tr ("Open mixer track state..."), [this, targets] {
- auto& chooser = mixerStateChooser();
- const auto start = mixerpresets::folders().isEmpty() ? mixerStatesFolder() : mixerpresets::folders()[0];
- chooser = lynx::ui::makeFileChooser (tr ("Open mixer track state"), start,
- juce::String ("*.fst;*") + ProjectFile::mixerTrackStateExtension);
- juce::Component::SafePointer<MixerStrips> safe (this);
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [safe, targets] (const juce::FileChooser& fc) {
- if (safe != nullptr && fc.getResult().existsAsFile() && ! mixerpresets::loadOnTracks (safe->engine, targets, fc.getResult()))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Open mixer track state"),
- tr ("This file is not a mixer track state LYNX SHARE can read."));
- });
- });
- file.addItem (tr ("Save mixer track state as...") + "\tCtrl+Shift+S", [this, t, trackName] {
- auto& chooser = mixerStateChooser();
- const auto name = juce::File::createLegalFileName (trackName.isNotEmpty() ? trackName : tr ("Mixer track {0}", { juce::String (t) }));
- chooser = lynx::ui::makeFileChooser (tr ("Save mixer track state"), mixerStatesFolder().getChildFile (name + ProjectFile::mixerTrackStateExtension),
- juce::String ("*") + ProjectFile::mixerTrackStateExtension);
- juce::Component::SafePointer<MixerStrips> safe (this);
- mixerStatesFolder().createDirectory();
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting, [safe, t] (const juce::FileChooser& fc) {
- if (safe != nullptr && fc.getResult() != juce::File())
- saveMixerTrackState (safe->engine, t, fc.getResult().withFileExtension (ProjectFile::mixerTrackStateExtension));
- });
- });
- file.addItem (tr ("Browse states"), [] {
- mixerStatesFolder().createDirectory();
- mixerStatesFolder().startAsProcess();
- });
- const auto states = mixerpresets::all();
- if (! states.isEmpty())
- {
- file.addSectionHeader (tr ("States"));
- for (const auto& f : states)
- file.addItem (f.getFileNameWithoutExtension(), [this, targets, f] { mixerpresets::loadOnTracks (engine, targets, f); });
- }
- menu.addSubMenu (tr ("File"), file);
- }
- if (t > 0)
- {
- const auto& mt = song.mixer[(std::size_t) t];
- const auto current = mt.inputChannel >= 0
- ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str())
- : tr ("none");
- menu.addItem (tr ("Audio input: {0}...", { current }), [this, t] { mixerinput::showMenu (engine, t, this); });
- }
- menu.addItem (tr ("Open audio editor"), [this] { openAudioEditor (engine); });
- menu.addItem (tr ("Reset selected track(s) to default"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetToDefault (s, targets); }); });
- // --- FL's "Routing" section -----------------------------------------------------------------------
- menu.addSectionHeader (tr ("Routing"));
- {
- juce::PopupMenu channels;
- channels.addItem (tr ("Route selected channels to this track") + "\tCtrl+L", [this, t] {
- setSelection (selection, t);
- linkSelectedChannels (false);
- });
- channels.addItem (tr ("Route selected channels starting from this track") + "\tCtrl+Shift+L", [this, t] {
- setSelection (selection, t);
- linkSelectedChannels (true);
- });
- if (channel < (int) song.channels.size())
- channels.addItem (tr ("Route channel \"{0}\" here", { juce::String::fromUTF8 (song.channels[(std::size_t) channel].name.c_str()) }),
- [this, channel, t] { engine.editSong ([channel, t] (Song& s) { s.channels[(std::size_t) channel].mixerTrack = t; }); });
- menu.addSubMenu (tr ("Channel routing"), channels);
- }
- {
- juce::PopupMenu select;
- select.addItem (tr ("Channels routed to this track") + "\tAlt+L", ! mixerops::channelsOn (song, t).empty(), false, [this, t] {
- setSelection (selection, t);
- selectLinkedChannels();
- });
- select.addSeparator();
- const auto destinations = mixerops::destinationsOf (song, t);
- const auto sources = mixerops::sourcesOf (song, t);
- select.addItem (tr ("Tracks this one is routed to"), ! destinations.empty(), false, [this, t, destinations] { setSelection (destinations, t); });
- select.addItem (tr ("Tracks routed to this one"), ! sources.empty(), false, [this, t, sources] { setSelection (sources, t); });
- select.addSeparator();
- select.addItem (tr ("Group"), t > 0, false, [this, t] {
- auto group = mixerops::groupOf (engine.getSong(), t);
- std::sort (group.begin(), group.end());
- setSelection (group, t);
- });
- select.addItem (tr ("All"), [this, t] {
- std::vector<int> all ((std::size_t) engine.getSong().mixer.size());
- std::iota (all.begin(), all.end(), 0);
- setSelection (all, t);
- });
- menu.addSubMenu (tr ("Select"), select);
- }
- menu.addItem (tr ("Reset selected track(s) routing"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::resetRouting (s, targets); }); });
- menu.addItem (tr ("Unroute tracks routed to the selected track(s)"), [this, targets] { engine.editSong ([targets] (Song& s) { mixerops::unrouteInto (s, targets); }); });
- {
- // FL's Routing submenu (REA round 165f-mixer: FUN_012ac520 / FUN_012ac950): selected tracks ⇄ this track
- std::vector<int> others;
- for (auto x : selection)
- if (x != t)
- others.push_back (x);
- const auto any = ! others.empty();
- juce::PopupMenu routing;
- routing.addSectionHeader (tr ("Selected tracks to this track"));
- using K = mixerops::RouteKind;
- auto selToThis = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeSelectedTo (s, others, t, kind); }); };
- auto thisToSel = [this, others, t] (K kind) { engine.editSong ([others, t, kind] (Song& s) { mixerops::routeToSelected (s, t, others, kind); }); };
- routing.addItem (tr ("Route selected to this track"), any, false, [selToThis] { selToThis (K::route); });
- routing.addItem (tr ("Route selected to this track only"), any, false, [selToThis] { selToThis (K::routeOnly); });
- routing.addItem (tr ("Sidechain selected to this track"), any && t > 0, false, [selToThis] { selToThis (K::sidechain); });
- routing.addItem (tr ("Sidechain selected to this track only"), any && t > 0, false, [selToThis] { selToThis (K::sidechainOnly); });
- routing.addSeparator();
- routing.addItem (tr ("Create submix..."), any && t > 0, false, [this, others, t] {
- const auto& track = engine.getSong().mixer[(std::size_t) t];
- const auto name = mixerops::hasDefaultName (engine.getSong(), t) ? juce::String() : juce::String::fromUTF8 (track.name.c_str());
- showNameAndColourDialog (tr ("Create submix"), name, track.colour, [this, others, t] (const juce::String& n, std::uint32_t colour) {
- if (t < (int) engine.getSong().mixer.size())
- engine.editSong ([others, t, n = n.trim().toStdString(), colour] (Song& s) {
- s.mixer[(std::size_t) t].colour = colour;
- mixerops::createSubmix (s, others, t, n);
- });
- });
- });
- const auto thisIsInsert = t > 0;
- routing.addSectionHeader (tr ("This track to selected tracks"));
- routing.addItem (tr ("Route this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::route); });
- routing.addItem (tr ("Route this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::routeOnly); });
- routing.addItem (tr ("Sidechain this track to selected"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechain); });
- routing.addItem (tr ("Sidechain this track to selected only"), any && thisIsInsert, false, [thisToSel] { thisToSel (K::sidechainOnly); });
- menu.addSubMenu (tr ("Selected tracks ⇄ this track"), routing);
- }
- if (selected > 0 && selected != t && (t == 0 || song.canRoute (selected, t) || song.routes (selected, t)))
- menu.addItem (tr ("Send \"{0}\" only to this track", { juce::String::fromUTF8 (song.mixer[(std::size_t) selected].name.c_str()) }),
- [this, from = selected, t] {
- engine.editSong ([from, t] (Song& s) {
- s.mixer[(std::size_t) from].sends.clear();
- s.mixer[(std::size_t) from].toMaster = false;
- s.setRoute (from, t, true);
- });
- });
- menu.addSeparator();
- {
- const auto inserts = [targets] {
- std::vector<int> v;
- for (auto x : targets)
- if (x > 0)
- v.push_back (x);
- return v;
- }();
- // FL's two solo items (REA_rodada167l §4): the plain one mutes the tracks feeding the soloed ones, the alt one
- // keeps them; the same item again clears the solo
- menu.addItem (tr ("Solo selected track(s)") + "\tS", ! inserts.empty(), false, [this, inserts] {
- engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, false); });
- });
- menu.addItem (tr ("Alt solo selected track(s)") + "\tAlt+S", ! inserts.empty(), false, [this, inserts] {
- engine.editSong ([inserts] (Song& s) { mixerops::soloSelected (s, inserts, true); });
- });
- menu.addItem (tr ("Arm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
- for (auto x : inserts)
- if (! engine.isInsertArmed (x))
- mixerinput::toggleArm (engine, x, this);
- });
- menu.addItem (tr ("Disarm selected track(s)"), ! inserts.empty(), false, [this, inserts] {
- for (auto x : inserts)
- if (engine.isInsertArmed (x))
- engine.setInsertArmed (x, false);
- });
- }
- // FL's track latency (the "Track latency compensation" label's menu, REA round 165f-mixer)
- menu.addSubMenu (tr ("Track latency: {0}", { manualLatencyText (engine, song.mixer[(std::size_t) t]) }), trackLatencyMenu (engine, t));
- // --- LYNX's sound items (FL has them on the strip itself) -------------------------------------------
- menu.addSectionHeader (tr ("Sound"));
- {
- const auto& track = song.mixer[(std::size_t) t];
- juce::PopupMenu stereo;
- const std::pair<const char*, float> widths[] = { { TR_NOOP ("Mono"), 1.0f }, { TR_NOOP ("Narrower"), 0.5f }, { TR_NOOP ("Normal"), 0.0f },
- { TR_NOOP ("Wider"), -0.5f }, { TR_NOOP ("Very wide"), -1.0f } };
- for (const auto& [label, value] : widths)
- stereo.addItem (tr (label), true, std::abs (track.stereo - value) < 0.01f,
- [this, t, v = value] { engine.editSong ([t, v] (Song& s) { s.mixer[(std::size_t) t].stereo = v; }); });
- menu.addSubMenu (tr ("Stereo separation"), stereo);
- if (! song.cleanMixer)
- menu.addItem (tr ("Track EQ..."), [this, t] { showTrackEq (t); });
- menu.addItem (tr ("Invert phase"), true, track.invertPhase, [this, t] {
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].invertPhase = ! s.mixer[(std::size_t) t].invertPhase; });
- });
- menu.addItem (tr ("Swap left/right"), true, track.swapChannels, [this, t] {
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].swapChannels = ! s.mixer[(std::size_t) t].swapChannels; });
- });
- if (t > 0)
- menu.addItem (tr ("Render to audio (freeze)..."), [this, t] { bounceInsertToAudio (engine, t); });
- }
- // --- FL's "Group" section (REA round 146a) -----------------------------------------------------------
- if (t > 0)
- {
- menu.addSectionHeader (tr ("Group"));
- const auto on = song.mixer[(std::size_t) t].separator;
- menu.addItem (tr ("Separator"), true, on, [this, targets, on] {
- engine.editSong ([targets, on] (Song& s) { mixerops::setSeparator (s, targets, ! on); });
- });
- menu.addItem (tr ("Create group"), [this, targets, t] { engine.editSong ([targets, t] (Song& s) { mixerops::createGroup (s, targets, t); }); });
- menu.addItem (tr ("Auto color group"), song.mixer[(std::size_t) t].colour != 0, false,
- [this, t] { engine.editSong ([t] (Song& s) { mixerops::autoColorGroup (s, t); }); });
- }
- // --- FL's "Layout" section --------------------------------------------------------------------------
- {
- menu.addSectionHeader (tr ("Layout"));
- juce::PopupMenu dockMenu;
- const auto dock = song.mixer[(std::size_t) t].dock;
- const std::pair<const char*, MixerDock> docks[] = { { TR_NOOP ("Left"), MixerDock::left }, { TR_NOOP ("Middle"), MixerDock::middle },
- { TR_NOOP ("Right"), MixerDock::right } };
- for (const auto& [label, d] : docks)
- dockMenu.addItem (tr (label), true, dock == d, [this, targets, d = d] {
- engine.editSong ([targets, d] (Song& s) { mixerops::dockTracks (s, targets, d); });
- });
- menu.addSubMenu (tr ("Dock to"), dockMenu);
- }
- if (t > 0)
- {
- menu.addItem (tr ("Move left") + "\tAlt+Left", t > 1, false, [this, t] {
- setSelection ({ t }, t);
- moveSelected (-1);
- });
- menu.addItem (tr ("Move right") + "\tAlt+Right", t + 1 < (int) song.mixer.size(), false, [this, t] {
- setSelection ({ t }, t);
- moveSelected (1);
- });
- menu.addSeparator();
- menu.addItem (tr ("Delete") + "\tDel", [this, t] {
- engine.editSong ([t] (Song& s) { mixerops::deleteTrack (s, t); });
- setSelection ({ t }, t);
- });
- const auto room = (int) song.mixer.size() < maxMixerTracks;
- menu.addItem (tr ("Insert one"), room, false, [this, t] {
- engine.editSong ([t] (Song& s) { mixerops::insertTrack (s, t); });
- setSelection ({ t }, t);
- });
- menu.addItem (tr ("Insert multiple..."), room, false, [this, t] { askInsertMultiple (t); });
- juce::PopupMenu fromState;
- for (const auto& f : mixerpresets::all())
- fromState.addItem (f.getFileNameWithoutExtension(), room, false, [this, t, f] {
- if (const auto added = mixerpresets::insertTrack (engine, t, f); added > 0)
- setSelection ({ added }, added);
- });
- menu.addSubMenu (tr ("Insert from state"), fromState, room && fromState.getNumItems() > 0);
- // FL's last section, "CPU" (REA round 134)
- menu.addSectionHeader (tr ("CPU"));
- menu.addItem (tr ("Allow threaded processing"), true, song.mixer[(std::size_t) t].threaded, [this, t] {
- engine.editSong ([t] (Song& s) { s.mixer[(std::size_t) t].threaded = ! s.mixer[(std::size_t) t].threaded; });
- });
- }
- menu.addSectionHeader (tr ("Mixer"));
- {
- // FL's Mixer › Disk recording (REA round 165f-mixer: FUN_012a7a80 / FUN_012a7d80)
- std::vector<int> armed;
- for (int x = 1; x < (int) song.mixer.size(); ++x)
- if (engine.isInsertArmed (x))
- armed.push_back (x);
- juce::PopupMenu disk;
- auto& eng = engine;
- disk.addItem (tr ("Render armed tracks to wave file(s)...") + "\tAlt+R", ! armed.empty(), false, [armed, &eng] {
- if (mixeroptions::renderTracks)
- mixeroptions::renderTracks (armed, [armed, &eng] (const std::vector<juce::File>& files) {
- if (eng.getRecordOptions().unarmAfterRender) // FL's "Auto-unarm" (round 166e)
- for (auto t : armed)
- eng.setInsertArmed (t, false);
- if (eng.getRecordOptions().autoCreateClip) // FL's "Auto-create audio clip" (round 167a)
- placeRenderedFiles (eng, files);
- });
- });
- disk.addItem (tr ("Render selected tracks to wave file(s)...") + "\tShift+Alt+R", ! targets.empty(), false, [targets] {
- if (mixeroptions::renderTracks)
- mixeroptions::renderTracks (targets, {});
- });
- // FL's Disk recording "Options" (round 166e) and LYNX's own disarm after a take (issue #16)
- disk.addSectionHeader (tr ("Options"));
- const auto& ro = engine.getRecordOptions();
- auto setRecord = [&eng] (std::function<void (AudioEngine::RecordOptions&)> change) {
- auto o = eng.getRecordOptions();
- change (o);
- eng.setRecordOptions (o);
- if (mixeroptions::changed)
- mixeroptions::changed();
- };
- disk.addItem (tr ("Auto-unarm (rendering the armed tracks disarms them)"), true, ro.unarmAfterRender,
- [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.unarmAfterRender = ! r.unarmAfterRender; }); });
- disk.addItem (tr ("Auto-create audio clip (the rendered files go on the Playlist)"), true, ro.autoCreateClip,
- [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.autoCreateClip = ! r.autoCreateClip; }); });
- disk.addItem (tr ("Disarm the inserts when recording stops"), true, ro.disarmOnStop,
- [setRecord] { setRecord ([] (AudioEngine::RecordOptions& r) { r.disarmOnStop = ! r.disarmOnStop; }); });
- menu.addSubMenu (tr ("Disk recording"), disk);
- juce::PopupMenu pdc;
- const auto manual = std::count_if (song.mixer.begin(), song.mixer.end(), [] (const MixerTrack& m) { return m.latencyMs != 0.0f; });
- pdc.addItem (tr ("Reset manual latency on all tracks"), manual > 0, false, [this] {
- juce::AlertWindow::showOkCancelBox (juce::MessageBoxIconType::WarningIcon, tr ("Warning"),
- tr ("This will reset manual latency values on all mixer tracks."), tr ("OK"), tr ("Cancel"), nullptr,
- juce::ModalCallbackFunction::create ([this] (int r) {
- if (r == 1)
- engine.editSong ([] (Song& s) { mixerops::resetManualLatency (s); });
- }));
- });
- // FL's Automatic / Compensate automations (REA round 168j, .flp 0x1D / 0x27; FL's AutoPDCMenuClick toggles it)
- pdc.addItem (tr ("Automatic (compensate the plugins' latencies)"), true, song.autoPdc,
- [this] { engine.editSong ([] (Song& s) { s.autoPdc = ! s.autoPdc; }); });
- pdc.addItem (tr ("Compensate automations (delay a plugin's automation with its audio)"), true, song.compensateAutomations,
- [this] { engine.editSong ([] (Song& s) { s.compensateAutomations = ! s.compensateAutomations; }); });
- menu.addSubMenu (tr ("Plugin delay compensation"), pdc);
- }
- menu.addSubMenu (tr ("Mixer layout"), MixerLayoutBox::menu (*this)); // as the title bar's drop-down (issue #52)
- mixeroptions::addItems (menu, engine, false);
- return menu;
- }
- void MixerStrips::changeListenerCallback (juce::ChangeBroadcaster*)
- {
- // only levels moved since the last call (a fader / knob drag, AudioEngine::editLevels; round 171c): repaint just
- // the strips whose fader, pan or separation changed instead of the whole mixer at every mouse move
- const auto& mixer = engine.getSong().mixer;
- if (engine.getPublishCount() == seenPublish && shownLevels.size() == mixer.size())
- {
- for (std::size_t t = 0; t < mixer.size(); ++t)
- {
- const std::array<float, 3> now { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
- if (now != shownLevels[t])
- {
- shownLevels[t] = now;
- repaint (stripX ((int) t), 0, stripWidthOf ((int) t), getHeight());
- }
- }
- return;
- }
- seenPublish = engine.getPublishCount();
- shownLevels.resize (mixer.size());
- for (std::size_t t = 0; t < mixer.size(); ++t)
- shownLevels[t] = { mixer[t].volume, mixer[t].pan, mixer[t].stereo };
- selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), selected);
- const auto count = (int) engine.getSong().mixer.size();
- selection.erase (std::remove_if (selection.begin(), selection.end(), [count] (int t) { return t >= count; }), selection.end());
- if (! std::binary_search (selection.begin(), selection.end(), selected))
- selection = { selected };
- updateSize();
- repaint();
- }
- float MixerStrips::shownVolume (int t) const
- {
- const auto& mixer = engine.getSong().mixer;
- const auto base = t >= 0 && t < (int) mixer.size() ? mixer[(std::size_t) t].volume : 0.0f;
- return engine.getAutomationDisplay().shown (AutomationTarget { AutomationTargetKind::mixerVolume, t }, base);
- }
- void MixerStrips::repaintAutomatedStrips()
- {
- // faders, pan and send knobs follow their automation while the song plays (issue #12): only the strips with an
- // automated control repaint, and only when a shown value changed
- const auto& shown = engine.getAutomationDisplay();
- if (shown.getGeneration() == shownAutomation)
- return;
- shownAutomation = shown.getGeneration();
- std::vector<int> strips;
- for (const auto& t : shown.automatedTargets())
- {
- if (t.kind == AutomationTargetKind::mixerVolume || t.kind == AutomationTargetKind::mixerPan)
- strips.push_back (t.index);
- else if (t.kind == AutomationTargetKind::mixerSend && t.index == selected)
- strips.push_back (t.slot); // (the route knob sits under the destination)
- }
- std::vector<int> all = strips;
- all.insert (all.end(), automatedStrips.begin(), automatedStrips.end());
- automatedStrips = std::move (strips);
- if (! isShowing())
- return;
- std::sort (all.begin(), all.end());
- all.erase (std::unique (all.begin(), all.end()), all.end());
- const auto count = (int) engine.getSong().mixer.size();
- for (const auto t : all)
- if (t >= 0 && t < count)
- repaint (stripX (t), 0, stripWidthOf (t), getHeight());
- }
- void MixerStrips::timerCallback()
- {
- auto& meters = engine.getMeters();
- const auto showing = isShowing();
- repaintAutomatedStrips();
- if ((++timerTicks & 1) != 0) // (the meters and input bars: every other tick, 30 Hz)
- return;
- const auto& mixer = engine.getSong().mixer;
- inputLevels.resize (mixer.size(), 0.0f);
- for (std::size_t t = 1; t < mixer.size(); ++t)
- {
- const auto peak = mixer[t].inputChannel >= 0 ? juce::jmax (engine.takeInputPeak ((int) t, 0), engine.takeInputPeak ((int) t, 1)) : 0.0f;
- auto level = juce::jmax (peak, inputLevels[t] * 0.8f);
- level = level < 1e-4f ? 0.0f : level;
- if (std::abs (level - inputLevels[t]) > 1e-4f)
- {
- inputLevels[t] = level;
- if (showing)
- repaint (inputArea ((int) t).expanded (1));
- }
- }
- for (std::size_t i = 0; i < levels.size(); ++i)
- {
- auto& m = levels[i];
- const auto before = m;
- m.tick (meters.takePeak ((int) (i / 2), (int) (i % 2))); // ~20 dB/s falloff at 30 Hz, 1.5 s peak hold
- // only the meter that changed is repainted
- if (showing && (std::abs (m.level - before.level) > 1e-4f || std::abs (m.peak - before.peak) > 1e-4f || m.clipped != before.clipped))
- repaint (meterArea ((int) (i / 2)).expanded (1));
- }
- }
- // ---------------------------------------------------------------------------
- namespace
- {
- constexpr int panelHeader = 30;
- constexpr int inputRowHeight = 30; // the input row (arm, audio input source) above the slots
- constexpr int slotsTop = panelHeader + inputRowHeight;
- constexpr int slotHeight = 24;
- const EffectKind allEffects[] = { EffectKind::eq, EffectKind::parametricEq, EffectKind::facetEq, EffectKind::compressor, EffectKind::limiter, EffectKind::apexLimiter,
- EffectKind::delay, EffectKind::reverb, EffectKind::chorus, EffectKind::filter,
- EffectKind::distortion, EffectKind::utility, EffectKind::volumeGate,
- EffectKind::pitchShift, EffectKind::freqShift, EffectKind::lofi, EffectKind::effector, EffectKind::crossover, EffectKind::frequencySplitter, EffectKind::autoPan, EffectKind::vocoder, EffectKind::pitchCorrect,
- EffectKind::ridgeStrip, EffectKind::glowLeveler, EffectKind::hushDeEsser, EffectKind::aether, EffectKind::ember, // LYNX's mixing suite
- EffectKind::lynxTune, // LYNX's own pitch corrector
- EffectKind::epochVerb, EffectKind::atrium, EffectKind::foilPlate, EffectKind::nebula, EffectKind::halo, EffectKind::horizon, // LYNX's reverbs
- EffectKind::echoform, EffectKind::spiralEcho, EffectKind::orbit, EffectKind::latticeMod, // LYNX's delay / modulation suite
- EffectKind::crestCompressor, EffectKind::prismMultiband, EffectKind::sentryGate, // LYNX's dynamics suite
- EffectKind::quellDenoiser, EffectKind::geminiDoubler, EffectKind::voiceShift, // LYNX's voice tools
- EffectKind::formulaController, EffectKind::peakController, EffectKind::xyController, EffectKind::xyzController,
- EffectKind::controlSurface, // controllers (link their output to any knob)
- EffectKind::patcher, // FL's Patcher: a graph of effects / instruments / plugins (REA_rodada141)
- EffectKind::hardwareInsert, // outboard gear through device outputs / inputs, pinged round trip (round 164d)
- EffectKind::fruityLimiter, EffectKind::fruityCompressor,
- EffectKind::fruityWaveShaper, EffectKind::fruitySoftClipper,
- EffectKind::reeverb2, EffectKind::reeverb1,
- EffectKind::fruityDelay2, EffectKind::fruityDelay3,
- EffectKind::stereoShaper, EffectKind::stereoEnhancer, EffectKind::transientProcessor,
- EffectKind::spreader, EffectKind::fruityChorus, EffectKind::hyperChorus, EffectKind::vintageChorus,
- EffectKind::fruityPanOMatic, EffectKind::fruityBalance, EffectKind::fruityBloodOverdrive, EffectKind::fruitySend,
- EffectKind::fruityDelayBank, EffectKind::fruityMultiband,
- EffectKind::fruityFastDist, EffectKind::fruityFlangus, EffectKind::fruityFlanger, EffectKind::fruityPhaser, EffectKind::luxeVerb,
- EffectKind::fruityFastLP, EffectKind::fruityFreeFilter, EffectKind::fruityFilter,
- EffectKind::hardcore,
- EffectKind::multibandDelay, EffectKind::emphasizer, EffectKind::flEmphasis, EffectKind::flFrequencyShifter, EffectKind::flLowLifter,
- EffectKind::flPhaseInverter, EffectKind::flCenter, EffectKind::flBassBoost, EffectKind::fl7BandEq, EffectKind::flDelay1, // round 165k
- EffectKind::waveCandy, EffectKind::visualizer, // visual plugins (round 164c)
- EffectKind::fruityMute2, EffectKind::bigClock, EffectKind::tuner, EffectKind::htmlNotebook, // round 165g
- EffectKind::scratcher, // round 165g (flscratch165): FL's turntable
- EffectKind::transmitter, // round 165g (fltrans165): FL's transient / sustain splitter
- EffectKind::flTransporter, // round 167f: FL's transient looper, exact
- // FL engines that need more than their parameters (round 142, issue #5): a new one starts from
- // the plugin's Default preset of the user's FL installation (core/NativeEngines.h)
- EffectKind::maximus, EffectKind::vocodex, EffectKind::equo, EffectKind::distructor, EffectKind::lovePhilter,
- EffectKind::grossBeat, EffectKind::convolver, EffectKind::flPitchShifter, EffectKind::vintagePhaser,
- EffectKind::squeeze, EffectKind::rhythmGain, EffectKind::newtone, EffectKind::newtime };
- } // namespace
- const std::vector<EffectKind>& addableEffects()
- {
- static const std::vector<EffectKind> list (std::begin (allEffects), std::end (allEffects));
- return list;
- }
- bool isFlEffect (EffectKind kind)
- {
- // allEffects lists LYNX's own effects first and FL's from the Formula Controller on (the outboard gear insert is LYNX's)
- const auto& list = addableEffects();
- const auto first = std::find (list.begin(), list.end(), EffectKind::formulaController);
- const auto at = std::find (list.begin(), list.end(), kind);
- return at != list.end() && at >= first && kind != EffectKind::hardwareInsert;
- }
- bool addableEffectAvailable (EffectKind kind)
- {
- const auto* e = natives::effectEngine (kind);
- return e == nullptr || natives::available (*e, flStudioAccess());
- }
- juce::String addableEffectName (EffectKind kind)
- {
- const auto name = juce::String::fromUTF8 (effectInfo (kind).name);
- // LYNX's own pitch / frequency effects sit next to FL's look-alikes (Pitch Shifter, Frequency Shifter, Pitcher)
- // in the lists: tell them apart (round 162, issue #7 review)
- if (kind == EffectKind::pitchShift || kind == EffectKind::freqShift || kind == EffectKind::pitchCorrect)
- return tr ("{0} (LYNX SHARE)", { name });
- if (const auto* e = natives::effectEngine (kind))
- {
- if (! natives::available (*e, flStudioAccess()))
- return tr ("{0} (requires FL Studio)", { name });
- if (e->beta)
- return tr ("{0} (beta)", { name });
- }
- return name;
- }
- std::optional<EffectSlot> newAddableEffect (EffectKind kind, double bpm)
- {
- return natives::newEffect (kind, flStudioAccess(), bpm);
- }
- EffectsPanel::EffectsPanel (AudioEngine& e)
- : engine (e)
- {
- setWantsKeyboardFocus (false);
- setMouseClickGrabsKeyboardFocus (false);
- engine.addChangeListener (this);
- startTimerHz (30);
- }
- EffectsPanel::~EffectsPanel()
- {
- engine.removeChangeListener (this);
- }
- juce::Rectangle<int> EffectsPanel::armBounds() const
- {
- return { 8, panelHeader + 2, 24, inputRowHeight - 8 };
- }
- juce::Rectangle<int> EffectsPanel::inputBoxBounds() const
- {
- return { 38, panelHeader + 2, getWidth() - 46, inputRowHeight - 8 };
- }
- void EffectsPanel::timerCallback()
- {
- // the input level of the shown insert (the strips read their own); decays like a meter
- const auto& mixer = engine.getSong().mixer;
- const auto hasInput = track >= 0 && track < (int) mixer.size() && mixer[(std::size_t) track].inputChannel >= 0;
- auto changed = false;
- for (int side = 0; side < 2; ++side)
- {
- const auto peak = hasInput ? engine.peekInputPeak (track, side) : 0.0f;
- const auto level = juce::jmax (peak, inputLevel[(std::size_t) side] * 0.8f);
- changed = changed || std::abs (level - inputLevel[(std::size_t) side]) > 1e-4f;
- inputLevel[(std::size_t) side] = level < 1e-4f ? 0.0f : level;
- }
- if (changed && isShowing())
- repaint (inputBoxBounds());
- // another effect selected (its controls need another height): fold / unfold the EQ, scroll (round 164)
- if (const auto* s = slots(); s != nullptr && isShowing())
- {
- const auto kind = selectedSlot >= 0 && selectedSlot < (int) s->size() ? (int) (*s)[(std::size_t) selectedSlot].kind : -1;
- if (selectedSlot != fittedSlot || kind != fittedKind)
- {
- fittedSlot = selectedSlot;
- fittedKind = kind;
- refit();
- }
- }
- }
- void EffectsPanel::setTrack (int t)
- {
- track = t;
- const auto* s = slots();
- selectedSlot = s != nullptr && ! s->empty() ? 0 : -1;
- refit();
- repaint();
- }
- const std::vector<EffectSlot>* EffectsPanel::slots() const
- {
- const auto& mixer = engine.getSong().mixer;
- return track >= 0 && track < (int) mixer.size() ? &mixer[(std::size_t) track].effects : nullptr;
- }
- int EffectsPanel::rowOf (int index) const
- {
- const auto* s = slots();
- if (s == nullptr || index < 0 || index >= (int) s->size())
- return -1;
- return mixerops::effectRows (*s)[(std::size_t) index];
- }
- int EffectsPanel::effectIn (int row) const
- {
- const auto* s = slots();
- return s == nullptr ? -1 : mixerops::effectAtRow (*s, row);
- }
- juce::Rectangle<int> EffectsPanel::mixBounds (int slot) const
- {
- return slotBounds (slot).withTrimmedRight (20).removeFromRight (24);
- }
- juce::Rectangle<int> EffectsPanel::ledBounds (int slot) const
- {
- return slotBounds (slot).removeFromRight (20);
- }
- juce::Rectangle<int> EffectsPanel::arrowBounds (int slot) const
- {
- return slotBounds (slot).removeFromLeft (18);
- }
- // --- the insert's built-in EQ and its output (FL's layout under the slots, REA round 104) ---------
- namespace
- {
- constexpr int eqGraphHeight = 84, eqKnobsHeight = 46, outputRowHeight = 30;
- constexpr float eqMinHz = 20.0f, eqMaxHz = 20000.0f, eqRangeDb = 18.0f;
- const char* const eqBandNames[] = { TR_NOOP ("Low shelf"), TR_NOOP ("Peak"), TR_NOOP ("High shelf") };
- juce::Colour eqBandColour (int band)
- {
- return band == 0 ? juce::Colour (0xFFE0A33Au) : band == 1 ? juce::Colour (0xFF5FC27Eu) : juce::Colour (0xFF5B9BE6u);
- }
- // stored 0..1 <-> the band's value
- float eqToValue (const TrackEq& eq, int band, int what)
- {
- const auto b = (std::size_t) band;
- if (what == 0)
- return (eq.gainDb[b] + eqRangeDb) / (2.0f * eqRangeDb);
- if (what == 1)
- return std::log (eq.hz[b] / 10.0f) / std::log (1600.0f);
- return eq.width[b];
- }
- void eqFromValue (TrackEq& eq, int band, int what, float v)
- {
- const auto b = (std::size_t) band;
- v = juce::jlimit (0.0f, 1.0f, v);
- if (what == 0)
- eq.gainDb[b] = std::round ((v * 2.0f * eqRangeDb - eqRangeDb) * 10.0f) / 10.0f;
- else if (what == 1)
- eq.hz[b] = std::round (10.0f * std::pow (1600.0f, v));
- else
- eq.width[b] = v;
- }
- // the EQ's response at `hz` (dB), with the filters the mixer runs (RackRenderer::applyTrackEq)
- float eqResponseDb (const TrackEq& eq, double hz, double sampleRate)
- {
- Biquad bands[3];
- bands[0].shelf (sampleRate, std::min ((double) eq.hz[0], sampleRate * 0.45), eq.gainDb[0], false, TrackEq::shelfSlope (eq.width[0]));
- bands[1].peaking (sampleRate, std::min ((double) eq.hz[1], sampleRate * 0.45), TrackEq::peakQ (eq.width[1]), eq.gainDb[1]);
- bands[2].shelf (sampleRate, std::min ((double) eq.hz[2], sampleRate * 0.45), eq.gainDb[2], true, TrackEq::shelfSlope (eq.width[2]));
- const auto w = juce::MathConstants<double>::twoPi * hz / sampleRate;
- const std::complex<double> z1 = std::polar (1.0, -w), z2 = std::polar (1.0, -2.0 * w);
- double db = 0.0;
- for (int b = 0; b < 3; ++b)
- {
- if (eq.gainDb[(std::size_t) b] == 0.0f)
- continue; // a band at 0 dB is not processed (like FL)
- const auto& f = bands[b];
- const auto h = (f.b0 + f.b1 * z1 + f.b2 * z2) / (1.0 + f.a1 * z1 + f.a2 * z2);
- db += 20.0 * std::log10 (std::max (1e-9, std::abs (h)));
- }
- return (float) db;
- }
- } // namespace
- constexpr int eqFoldBarHeight = 20;
- bool EffectsPanel::eqShown() const
- {
- return ! engine.getSong().cleanMixer; // clean mixer (round 163): no built-in EQ to show
- }
- int EffectsPanel::belowHeight (bool folded) const
- {
- if (! eqShown()) // clean mixer: only the output row
- return outputRowHeight + 8;
- return outputRowHeight + eqFoldBarHeight + (folded ? 4 : eqGraphHeight + eqKnobsHeight + 14);
- }
- int EffectsPanel::bottomTop() const
- {
- return getHeight() - belowHeight (eqFolded);
- }
- juce::Rectangle<int> EffectsPanel::eqFoldBounds() const
- {
- if (! eqShown())
- return {};
- return { 8, bottomTop(), getWidth() - 16, eqFoldBarHeight };
- }
- int EffectsPanel::neededHeight (bool folded) const
- {
- // the slots and the selected effect's controls (round 164: its knobs and their names and values too, they were
- // cut by the EQ at medium heights): when they don't fit with the EQ open, it folds; then the panel scrolls
- return selectedEffectBottom() + 6 + belowHeight (folded);
- }
- void EffectsPanel::fitToView (int w, int h, int scrollBar)
- {
- viewWidth = w;
- viewHeight = h;
- scrollBarThickness = scrollBar;
- refit();
- }
- void EffectsPanel::refit()
- {
- if (viewWidth <= 0 || viewHeight <= 0)
- return;
- const auto folded = eqFoldChoice == 2 || (eqFoldChoice == 0 && viewHeight < neededHeight (false));
- const auto need = neededHeight (folded);
- const auto scrolls = viewHeight < need;
- const auto changed = folded != eqFolded;
- eqFolded = folded;
- const juce::Rectangle<int> size (viewWidth - (scrolls ? scrollBarThickness : 0), juce::jmax (viewHeight, need));
- if (getWidth() != size.getWidth() || getHeight() != size.getHeight())
- setSize (size.getWidth(), size.getHeight());
- else if (changed)
- repaint();
- }
- juce::Rectangle<int> EffectsPanel::eqGraphBounds() const
- {
- return { 8, bottomTop() + eqFoldBarHeight, getWidth() - 16 - 3 * 18 - 6, eqGraphHeight };
- }
- juce::Rectangle<int> EffectsPanel::eqFaderBounds (int band) const
- {
- const auto graph = eqGraphBounds();
- return { graph.getRight() + 6 + band * 18, graph.getY(), 16, graph.getHeight() };
- }
- juce::Rectangle<int> EffectsPanel::eqKnobBounds (int band, int what) const
- {
- const auto fader = eqFaderBounds (band);
- return { fader.getCentreX() - 11, eqGraphBounds().getBottom() + 2 + (what - 1) * 22, 22, 22 };
- }
- juce::Rectangle<int> EffectsPanel::outputBounds() const
- {
- return { 34, getHeight() - outputRowHeight - 2, getWidth() - 42, outputRowHeight - 8 };
- }
- juce::Point<float> EffectsPanel::eqHandle (int band) const
- {
- const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
- const auto& eq = engine.getSong().mixer[(std::size_t) track].eq;
- const auto hz = juce::jlimit (eqMinHz, eqMaxHz, eq.hz[(std::size_t) band]);
- const auto x = graph.getX() + graph.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
- const auto y = graph.getCentreY() - graph.getHeight() * 0.5f * eq.gainDb[(std::size_t) band] / eqRangeDb;
- return { x, y };
- }
- int EffectsPanel::eqControlAt (juce::Point<int> p) const
- {
- if (slots() == nullptr || eqFolded || ! eqShown())
- return 0;
- for (int b = 0; b < 3; ++b)
- {
- if (eqFaderBounds (b).contains (p))
- return eqParamBase - b * 3;
- for (int what = 1; what <= 2; ++what)
- if (eqKnobBounds (b, what).contains (p))
- return eqParamBase - b * 3 - what;
- }
- if (eqGraphBounds().contains (p))
- {
- // the nearest handle (by distance in the graph): FL's "Tweak band N"
- int best = 0;
- float bestDistance = 1e9f;
- for (int b = 0; b < 3; ++b)
- if (const auto d = eqHandle (b).getDistanceFrom (p.toFloat()); d < bestDistance)
- {
- bestDistance = d;
- best = b;
- }
- return eqPointBase - best;
- }
- return 0;
- }
- void EffectsPanel::setEqFromGraph (int band, juce::Point<int> p)
- {
- const auto graph = eqGraphBounds().toFloat().reduced (4.0f);
- const auto fx = juce::jlimit (0.0f, 1.0f, (p.x - graph.getX()) / graph.getWidth());
- const auto hz = juce::jlimit (10.0f, 16000.0f, std::round (eqMinHz * std::pow (eqMaxHz / eqMinHz, fx)));
- const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, std::round ((graph.getCentreY() - p.y) / (graph.getHeight() * 0.5f) * eqRangeDb * 10.0f) / 10.0f);
- engine.editSong ([t = track, band, hz, db] (Song& s) {
- if (t < (int) s.mixer.size())
- {
- s.mixer[(std::size_t) t].eq.hz[(std::size_t) band] = hz;
- s.mixer[(std::size_t) t].eq.gainDb[(std::size_t) band] = db;
- }
- });
- }
- void EffectsPanel::paintEq (juce::Graphics& g)
- {
- using namespace theme;
- const auto& song = engine.getSong();
- if (track < 0 || track >= (int) song.mixer.size())
- return;
- const auto& eq = song.mixer[(std::size_t) track].eq;
- const auto top = bottomTop();
- g.setColour (colour::border);
- g.fillRect (8, top, getWidth() - 16, 1);
- // the title bar: click folds / unfolds the EQ (it folds by itself when the mixer is too short for it)
- if (eqShown())
- {
- const auto bar = eqFoldBounds().toFloat();
- const auto active = eq.gainDb[0] != 0.0f || eq.gainDb[1] != 0.0f || eq.gainDb[2] != 0.0f;
- auto chevron = bar.withWidth (14.0f).withSizeKeepingCentre (12.0f, 12.0f);
- {
- juce::Graphics::ScopedSaveState state (g);
- if (eqFolded)
- g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, chevron.getCentreX(), chevron.getCentreY()));
- icons::draw (g, Icon::chevronDown, chevron, colour::textSecondary);
- }
- g.setFont (font (type::small, true));
- g.setColour (colour::textSecondary);
- textcache::drawText (g, tr ("EQ"), bar.withTrimmedLeft (18.0f).toNearestInt(), juce::Justification::centredLeft);
- if (eqFolded && active) // a folded EQ that still changes the sound says so
- {
- g.setColour (colour::accent);
- g.setFont (font (type::caption));
- textcache::drawText (g, tr ("active"), bar.withTrimmedLeft (44.0f).toNearestInt(), juce::Justification::centredLeft);
- }
- }
- if (! eqFolded && eqShown())
- {
- // the response graph: frequency (log) across, ±18 dB up and down
- const auto graph = eqGraphBounds().toFloat();
- theme::fillRoundRect (g, graph, radius::sm, colour::bg1);
- g.setColour (colour::border);
- g.drawRoundedRectangle (graph.reduced (0.5f), radius::sm, 1.0f);
- const auto inner = graph.reduced (4.0f);
- g.setColour (colour::gridBeat);
- for (float hz : { 100.0f, 1000.0f, 10000.0f })
- {
- const auto x = inner.getX() + inner.getWidth() * std::log (hz / eqMinHz) / std::log (eqMaxHz / eqMinHz);
- g.drawVerticalLine ((int) x, inner.getY(), inner.getBottom());
- }
- g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
- juce::Path curve;
- const auto sampleRate = juce::jmax (8000.0, engine.getTransport().sampleRate.load());
- for (int i = 0; i <= (int) inner.getWidth(); i += 2)
- {
- const auto hz = eqMinHz * std::pow (eqMaxHz / eqMinHz, (float) i / inner.getWidth());
- const auto db = juce::jlimit (-eqRangeDb, eqRangeDb, eqResponseDb (eq, hz, sampleRate));
- const auto y = inner.getCentreY() - inner.getHeight() * 0.5f * db / eqRangeDb;
- if (i == 0)
- curve.startNewSubPath (inner.getX(), y);
- else
- curve.lineTo (inner.getX() + (float) i, y);
- }
- g.setColour (eq.active() ? colour::accent : colour::textSecondary.withAlpha (0.6f));
- g.strokePath (curve, juce::PathStrokeType (1.5f));
- for (int b = 0; b < 3; ++b)
- {
- const auto hot = hoverEq == eqPointBase - b || dragParam == eqPointBase - b;
- const auto handle = eqHandle (b);
- g.setColour (eqBandColour (b).withAlpha (hot ? 1.0f : 0.8f));
- g.fillEllipse (juce::Rectangle<float> (hot ? 10.0f : 8.0f, hot ? 10.0f : 8.0f).withCentre (handle));
- }
- // the gain faders (one per band) and the frequency / width knobs under them
- for (int b = 0; b < 3; ++b)
- {
- const auto fader = eqFaderBounds (b).toFloat();
- const auto hot = hoverEq == eqParamBase - b * 3 || dragParam == eqParamBase - b * 3;
- theme::fillRoundRect (g, fader.withSizeKeepingCentre (3.0f, fader.getHeight() - 6.0f), 1.5f, colour::bg0);
- g.setColour (colour::border);
- g.drawHorizontalLine ((int) fader.getCentreY(), fader.getX() + 2.0f, fader.getRight() - 2.0f);
- const auto v = eqToValue (eq, b, 0);
- const auto y = fader.getBottom() - 6.0f - v * (fader.getHeight() - 12.0f);
- theme::fillRoundRect (g, juce::Rectangle<float> (fader.getWidth() - 2.0f, 7.0f).withCentre ({ fader.getCentreX(), y }), 2.0f, hot ? colour::textPrimary : colour::textSecondary);
- g.setColour (eqBandColour (b));
- g.fillRect (juce::Rectangle<float> (fader.getWidth() - 6.0f, 1.5f).withCentre ({ fader.getCentreX(), y }));
- for (int what = 1; what <= 2; ++what)
- {
- const auto code = eqParamBase - b * 3 - what;
- drawKnob (g, eqKnobBounds (b, what).toFloat().reduced (2.0f), eqToValue (eq, b, what), false, eqBandColour (b),
- hoverEq == code || dragParam == code);
- }
- }
- // the knob captions take the width their (translated) text needs, the title gives way (round 165o)
- const juce::Font captionFont (font (type::caption));
- const auto captionWidth = juce::jlimit (32, 70, (int) std::ceil (juce::jmax (juce::GlyphArrangement::getStringWidth (captionFont, tr ("Freq")),
- juce::GlyphArrangement::getStringWidth (captionFont, tr ("Width")))) + 2);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::title));
- textcache::drawText (g, tr ("Equalizer"), 10, eqGraphBounds().getBottom() + 4, eqKnobBounds (0, 1).getX() - 8 - captionWidth, 20,
- juce::Justification::centredLeft);
- g.setFont (captionFont);
- g.setColour (colour::textDisabled);
- textcache::drawText (g, tr ("Freq"), eqKnobBounds (0, 1).getX() - 2 - captionWidth, eqKnobBounds (0, 1).getY(), captionWidth, 22,
- juce::Justification::centredRight);
- textcache::drawText (g, tr ("Width"), eqKnobBounds (0, 2).getX() - 2 - captionWidth, eqKnobBounds (0, 2).getY(), captionWidth, 22,
- juce::Justification::centredRight);
- }
- // the audio output target
- auto box = outputBounds().toFloat();
- g.setColour (colour::border);
- g.fillRect (8, (int) box.getY() - 5, getWidth() - 16, 1);
- icons::draw (g, Icon::exportAudio, juce::Rectangle<float> (10.0f, box.getY(), 18.0f, box.getHeight()).withSizeKeepingCentre (16.0f, 16.0f),
- colour::textSecondary);
- theme::fillRoundRect (g, box, radius::sm, hoverOutput ? colour::bg4 : colour::bg3);
- g.setColour (hoverOutput ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
- g.setColour (track == 0 ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::body));
- textcache::drawText (g, outputName(), box.withTrimmedLeft (8.0f).withTrimmedRight (18.0f).toNearestInt(), juce::Justification::centredLeft, true);
- icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, 0.0f), colour::textSecondary);
- }
- juce::String EffectsPanel::outputName() const
- {
- if (track == 0 && const_cast<AudioEngine&> (engine).getDeviceManager().getCurrentAudioDevice() == nullptr)
- return tr ("(no audio device)");
- return mixeroutput::label (engine, track);
- }
- void EffectsPanel::showOutputMenu()
- {
- mixeroutput::showMenu (engine, track, this, localAreaToGlobal (outputBounds()));
- }
- namespace mixeroptions
- {
- std::function<void()> changed;
- std::function<void (bool)> setShowUsedOnly;
- std::function<void (std::vector<int>, std::function<void (const std::vector<juce::File>&)>)> renderTracks;
- namespace
- {
- void notifyChanged()
- {
- if (changed)
- changed();
- }
- void askNumber (const juce::String& title, const juce::String& text, int value, int lo, int hi, std::function<void (int)> done)
- {
- auto* w = new juce::AlertWindow (title, text, juce::MessageBoxIconType::NoIcon);
- w->addTextEditor ("n", juce::String (value));
- w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([w, lo, hi, done = std::move (done)] (int result) {
- if (result == 1)
- done (juce::jlimit (lo, hi, w->getTextEditorContents ("n").trim().getIntValue()));
- }), true);
- }
- } // namespace
- void addItems (juce::PopupMenu& menu, AudioEngine& engine, bool newProjects)
- {
- const auto& song = engine.getSong();
- menu.addItem (tr ("Clean mixer: no built-in EQ on the inserts (this project)"), true, song.cleanMixer, [&engine] {
- const auto on = ! engine.getSong().cleanMixer;
- engine.editSong ([on] (Song& s) { s.cleanMixer = on; });
- const auto& mixer = engine.getSong().mixer;
- const auto withEq = std::count_if (mixer.begin(), mixer.end(), [] (const MixerTrack& t) { return t.eq.active(); });
- if (on && withEq > 0) // nothing is lost: switching it off brings the EQ back as it was
- 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);
- });
- menu.addItem (tr ("Show only used inserts"), true, MixerStrips::showUsedOnly, [] {
- const auto on = ! MixerStrips::showUsedOnly;
- if (setShowUsedOnly)
- setShowUsedOnly (on);
- else
- MixerStrips::showUsedOnly = on;
- notifyChanged();
- });
- menu.addItem (tr ("Remove unused inserts at the end"), song.mixer.size() > 1 && ! song.insertInUse ((int) song.mixer.size() - 1), false, [&engine] {
- int removed = 0;
- engine.editSong ([&removed] (Song& s) { removed = mixerops::removeUnusedTrailingInserts (s); });
- ui::postHint ({ tr ("Removed {0} unused insert(s)", { juce::String (removed) }), {}, false, false }, 3000);
- });
- if (! newProjects)
- return;
- auto& d = newProjectDefaults();
- menu.addSectionHeader (tr ("New projects"));
- {
- juce::PopupMenu inserts;
- bool listed = false;
- for (int n : { 0, 1, 2, 4, 8, 12, 16, 24, 32, 48, 64, 100, 125 })
- {
- listed = listed || n == d.inserts;
- inserts.addItem (n == NewProjectDefaults::defaultInserts ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.inserts, [n] {
- newProjectDefaults().inserts = n;
- notifyChanged();
- });
- }
- inserts.addItem (listed ? tr ("Other...") : tr ("Other ({0})...", { juce::String (d.inserts) }), true, ! listed, [] {
- askNumber (tr ("Inserts in new projects"),
- tr ("How many mixer inserts a new project starts with (0 to {0}). More are added when you need them.", { juce::String (maxMixerTracks - 1) }),
- newProjectDefaults().inserts, 0, maxMixerTracks - 1, [] (int n) {
- newProjectDefaults().inserts = n;
- notifyChanged();
- });
- });
- menu.addSubMenu (tr ("Inserts in new projects ({0})", { juce::String (d.inserts) }), inserts);
- }
- {
- juce::PopupMenu chain;
- const std::pair<const char*, MasterChain> chains[] = { { TR_NOOP ("Empty (nothing on the Master)"), MasterChain::empty },
- { TR_NOOP ("Soft clipper only"), MasterChain::clipper },
- { TR_NOOP ("LYNX SHARE default (limiter)"), MasterChain::lynxDefault } };
- for (const auto& [label, c] : chains)
- chain.addItem (tr (label), true, d.master == c, [c = c] {
- newProjectDefaults().master = c;
- notifyChanged();
- });
- menu.addSubMenu (tr ("Master chain in new projects"), chain);
- }
- menu.addItem (tr ("Clean mixer in new projects (no built-in EQ)"), true, d.cleanMixer, [] {
- newProjectDefaults().cleanMixer = ! newProjectDefaults().cleanMixer;
- notifyChanged();
- });
- {
- juce::PopupMenu tracks;
- for (int n : { 4, 8, 16, 24, 32, 64, 100 })
- tracks.addItem (n == 16 ? tr ("{0} (default)", { juce::String (n) }) : juce::String (n), true, n == d.playlistTracks, [n] {
- newProjectDefaults().playlistTracks = n;
- notifyChanged();
- });
- menu.addSubMenu (tr ("Playlist tracks shown ({0})", { juce::String (d.playlistTracks) }), tracks);
- }
- }
- } // namespace mixeroptions
- namespace mixeroutput
- {
- namespace
- {
- juce::String modeSuffix (OutputMode mode)
- {
- switch (mode)
- {
- case OutputMode::stereo: return {};
- case OutputMode::monoSum: return " " + tr ("(mono)");
- case OutputMode::monoLeft: return " " + tr ("(mono, L)");
- case OutputMode::monoRight: return " " + tr ("(mono, R)");
- }
- return {};
- }
- } // namespace
- bool isCustom (const AudioEngine& engine, int track)
- {
- const auto& mixer = engine.getSong().mixer;
- if (track < 0 || track >= (int) mixer.size())
- return false;
- const auto channel = mixer[(std::size_t) track].outputChannel;
- return track == 0 ? channel != outputDefault : channel >= 0;
- }
- juce::String label (const AudioEngine& engine, int track, bool compact)
- {
- const auto& mixer = engine.getSong().mixer;
- if (track < 0 || track >= (int) mixer.size())
- return {};
- const auto& mt = mixer[(std::size_t) track];
- auto channel = mt.outputChannel;
- auto mode = mt.outputMode;
- if (track == 0 && channel == outputDefault)
- channel = 0, mode = OutputMode::stereo;
- if (channel < 0)
- return tr ("(none)");
- const auto names = engine.getOutputChannelNames();
- const auto missing = ! outputAvailable (channel, mode, (int) names.size())
- || ! engine.isOutputChannelOpen (channel) || (mode == OutputMode::stereo && ! engine.isOutputChannelOpen (channel + 1));
- if (compact) // the strip badge: the channel numbers only
- {
- auto text = juce::String::fromUTF8 ("\xe2\x86\x92 ") + juce::String (channel + 1);
- if (mode == OutputMode::stereo)
- text << "-" << (channel + 2);
- else
- text << (mode == OutputMode::monoLeft ? " L" : mode == OutputMode::monoRight ? " R" : " m");
- return missing ? text + " ?" : text;
- }
- auto nameOf = [&] (int c) {
- return c < (int) names.size() ? juce::String::fromUTF8 (names[(std::size_t) c].c_str()) : tr ("Out {0}", { juce::String (c + 1) });
- };
- auto text = mode == OutputMode::stereo ? nameOf (channel) + " - " + nameOf (channel + 1) : nameOf (channel);
- text += modeSuffix (mode);
- if (missing)
- text += " " + tr ("(missing)");
- return text;
- }
- void showMenu (AudioEngine& engine, int track, juce::Component* target, juce::Rectangle<int> screenArea)
- {
- const auto& mixer = engine.getSong().mixer;
- if (track < 0 || track >= (int) mixer.size())
- return;
- const auto& mt = mixer[(std::size_t) track];
- const auto names = engine.getOutputChannelNames();
- const auto custom = isCustom (engine, track);
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Audio output target"));
- auto set = [&engine, track] (int channel, OutputMode mode) {
- return [&engine, track, channel, mode] { engine.setTrackOutput (track, channel, mode); };
- };
- if (track == 0)
- {
- const auto first = names.size() >= 2 ? juce::String::fromUTF8 (names[0].c_str()) + " - " + juce::String::fromUTF8 (names[1].c_str())
- : tr ("first output pair");
- menu.addItem (first + " " + tr ("(default)"), true, mt.outputChannel == outputDefault, set (outputDefault, OutputMode::stereo));
- menu.addItem (tr ("(none)"), true, mt.outputChannel == outputNone, set (outputNone, OutputMode::stereo));
- }
- else
- menu.addItem (tr ("(none) - through the Master only"), true, ! custom, set (outputDefault, OutputMode::stereo));
- if (custom && (track > 0 || mt.outputChannel >= 0))
- menu.addItem (label (engine, track), true, true, nullptr); // the current target (also when missing)
- // the optional direct outputs: stereo pairs, then every channel alone
- juce::PopupMenu direct;
- direct.addItem (track == 0 ? tr ("Optional: send the Master to other outputs of your audio interface")
- : tr ("Optional: also send this insert straight to an output of your audio interface, e.g. a mono output"),
- false, false, nullptr);
- if (names.empty())
- direct.addItem (tr ("No audio device is open"), false, false, nullptr);
- const auto targets = outputTargets (names);
- auto pairsHeader = false, monoHeader = false;
- for (const auto& t : targets)
- {
- const auto name = juce::String::fromUTF8 (t.name.c_str());
- if (t.mode == OutputMode::stereo)
- {
- if (! std::exchange (pairsHeader, true))
- direct.addSectionHeader (tr ("Stereo pair"));
- direct.addItem (name, true, mt.outputChannel == t.channel && mt.outputMode == OutputMode::stereo, set (t.channel, OutputMode::stereo));
- continue;
- }
- if (! std::exchange (monoHeader, true))
- direct.addSectionHeader (tr ("Mono (one output)"));
- const auto here = mt.outputChannel == t.channel && mt.outputMode != OutputMode::stereo;
- juce::PopupMenu modes;
- modes.addItem (tr ("Sum of L + R (mono)"), true, here && mt.outputMode == OutputMode::monoSum, set (t.channel, OutputMode::monoSum));
- modes.addItem (tr ("Left side only"), true, here && mt.outputMode == OutputMode::monoLeft, set (t.channel, OutputMode::monoLeft));
- modes.addItem (tr ("Right side only"), true, here && mt.outputMode == OutputMode::monoRight, set (t.channel, OutputMode::monoRight));
- direct.addSubMenu (name, modes, true, nullptr, here);
- }
- if (! names.empty() && names.size() <= 2)
- direct.addItem (tr ("This audio device has 2 outputs; an interface with more outputs lists all of them here"), false, false, nullptr);
- menu.addSeparator();
- menu.addSubMenu (track == 0 ? tr ("Hardware output") : tr ("Send to hardware output (optional)"), direct, true, nullptr, custom && mt.outputChannel >= 0);
- if (custom)
- menu.addItem (track == 0 ? tr ("Back to the default output") : tr ("Back to Master only"), set (outputDefault, OutputMode::stereo));
- menu.addSeparator();
- menu.addItem (tr ("Audio settings..."), [] {
- if (mixerinput::openAudioSettings)
- mixerinput::openAudioSettings();
- });
- auto options = juce::PopupMenu::Options();
- if (target != nullptr)
- options = options.withTargetComponent (target);
- if (! screenArea.isEmpty())
- options = options.withTargetScreenArea (screenArea);
- else if (target != nullptr)
- options = options.withMousePosition();
- menu.showMenuAsync (options);
- }
- } // namespace mixeroutput
- juce::Rectangle<int> EffectsPanel::slotBounds (int slot) const
- {
- return { 8, slotsTop + slot * slotHeight, getWidth() - 16, slotHeight - 3 };
- }
- namespace
- {
- // parameters shown as knobs: in the rhythmic envelope, only those of the points in use
- int shownParams (const EffectSlot& slot)
- {
- const auto all = (int) effectInfo (slot.kind).params.size();
- if (slot.kind == EffectKind::rhythmGain)
- return std::min (all, 2 + 3 * (int) std::lround (slot.params[1] * 12.0f));
- if (slot.kind == EffectKind::lynxTune) // the note switches are the keyboard strip above the knobs
- return std::min (all, (int) lynxtune::noteC);
- return all;
- }
- } // namespace
- juce::Rectangle<int> EffectsPanel::knobBounds (int param) const
- {
- return knobBoundsIn (param, bottomTop());
- }
- juce::Rectangle<int> EffectsPanel::knobBoundsIn (int param, int areaBottom) const
- {
- auto top = slotsTop + maxEffectSlots * slotHeight + 40;
- // many parameters (Effector: 12): 4 columns and shorter rows to fit the height
- int count = 0;
- if (const auto* s = slots(); ! gateSelected() && s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size())
- count = shownParams ((*s)[(std::size_t) selectedSlot]);
- const auto columns = count > 9 ? 4 : 3;
- const auto w = (getWidth() - 16) / columns;
- const auto rows = juce::jmax (1, (count + columns - 1) / columns);
- const auto rowHeight = count > 9 ? juce::jlimit (64, 86, (areaBottom - top - 4) / rows) : 86;
- // volume gate: the 32 steps are bars (gateStepsBounds); the knobs are mix/attack/release
- if (gateSelected())
- {
- if (param < 32)
- return {};
- param -= 32;
- top = gateStepsBounds().getBottom() + 22;
- }
- if (vocoderSelected()) // the band levels above the knobs
- top = bandLevelsBounds().getBottom() + 22;
- if (tuneSelected()) // LYNX Tune's note keyboard above the knobs
- top = tuneKeysBounds().getBottom() + 22;
- return { 8 + (param % columns) * w, top + (param / columns) * rowHeight, w, rowHeight - 4 };
- }
- int EffectsPanel::selectedEffectBottom() const
- {
- const auto slotsBottom = slotsTop + maxEffectSlots * slotHeight;
- auto bottom = slotsBottom + 64; // the effect's title row
- const auto* s = slots();
- if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
- return bottom;
- const auto& slot = (*s)[(std::size_t) selectedSlot];
- if (slot.kind == EffectKind::plugin || isSoundgoodizerApprox (slot))
- return juce::jmax (bottom, pluginButtonBounds().getBottom() + 34 + 40);
- if (slot.kind == EffectKind::parametricEq || slot.kind == EffectKind::facetEq)
- return juce::jmax (bottom, pluginButtonBounds().getBottom() + 10 + 120);
- if (slot.kind == EffectKind::parallel)
- return juce::jmax (bottom, knobBoundsIn (0, 0).getY() - 28 + 20 + 22 * (int) slot.branches.size());
- const auto count = gateSelected() ? 35 : shownParams (slot);
- for (int p = 0; p < count; ++p)
- if (const auto r = knobBoundsIn (p, 0); ! r.isEmpty()) // (tight grids at their shortest rows)
- bottom = juce::jmax (bottom, r.getY() + juce::jlimit (30, 44, r.getHeight() - 30) + 32); // knob, name, value
- return bottom;
- }
- bool EffectsPanel::gateSelected() const
- {
- const auto* s = slots();
- return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::volumeGate;
- }
- juce::Rectangle<int> EffectsPanel::gateStepsBounds() const
- {
- return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 90 };
- }
- void EffectsPanel::setGateStep (juce::Point<int> p)
- {
- const auto area = gateStepsBounds();
- const auto step = juce::jlimit (0, 31, (int) ((p.x - area.getX()) * 32 / juce::jmax (1, area.getWidth())));
- const auto value = juce::jlimit (0.0f, 1.0f, (float) (area.getBottom() - p.y) / (float) area.getHeight());
- engine.editSong ([t = track, slot = selectedSlot, step, value] (Song& song) {
- song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) step] = value;
- });
- }
- bool EffectsPanel::vocoderSelected() const
- {
- const auto* s = slots();
- return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::vocoder;
- }
- bool EffectsPanel::tuneSelected() const
- {
- const auto* s = slots();
- return s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::lynxTune;
- }
- juce::Rectangle<int> EffectsPanel::tuneKeysBounds() const
- {
- return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 54 };
- }
- namespace
- {
- // LYNX Tune's keyboard strip: one octave, white keys in a row, black keys on top (C … B → key rectangles)
- juce::Rectangle<float> tuneKeyRect (juce::Rectangle<float> area, int pc)
- {
- static constexpr int whiteIndex[12] { 0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, 6 };
- static constexpr float blackAt[12] { 0, 1.0f, 0, 2.0f, 0, 0, 4.0f, 0, 5.0f, 0, 6.0f, 0 };
- const auto w = area.getWidth() / 7.0f;
- if (whiteIndex[pc] >= 0)
- return { area.getX() + whiteIndex[pc] * w, area.getY(), w, area.getHeight() };
- return { area.getX() + blackAt[pc] * w - w * 0.3f, area.getY(), w * 0.6f, area.getHeight() * 0.58f };
- }
- int tuneKeyAt (juce::Rectangle<float> area, juce::Point<float> p)
- {
- for (int pc = 0; pc < 12; ++pc) // black keys first: they lie on top
- if ((pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10) && tuneKeyRect (area, pc).contains (p))
- return pc;
- for (int pc = 0; pc < 12; ++pc)
- if (tuneKeyRect (area, pc).contains (p))
- return pc;
- return -1;
- }
- } // namespace
- void EffectsPanel::toggleTuneNote (juce::Point<int> p)
- {
- const auto pc = tuneKeyAt (tuneKeysBounds().toFloat(), p.toFloat());
- if (pc < 0)
- return;
- engine.editSong ([t = track, slot = selectedSlot, pc] (Song& song) {
- auto& v = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) (lynxtune::noteC + pc)];
- v = v >= 0.5f ? 0.0f : 1.0f;
- });
- }
- juce::Rectangle<int> EffectsPanel::bandLevelsBounds() const
- {
- return { 10, slotsTop + maxEffectSlots * slotHeight + 40, getWidth() - 20, 70 };
- }
- namespace
- {
- // the Fruity Vocoder's state for the slot's current band count (levels kept while the count matches, as FL does)
- fvocoder::State vocoderState (const EffectSlot& slot)
- {
- auto s = fvocoder::parse (slot.state).value_or (fvocoder::State());
- const auto bands = 4 << std::clamp ((int) std::lround (slot.params[0] * 5.0f), 0, 5);
- if (s.bands != bands)
- {
- s.bands = bands;
- s.levels.fill (1.0f);
- }
- s.order = 1 + std::clamp ((int) std::lround (slot.params[1] * 2.0f), 0, 2);
- s.listen = std::clamp ((int) std::lround (slot.params[2] * 2.0f), 0, 2);
- s.swap = slot.params[3] > 0.5f;
- for (int c = 0; c < fvocoder::controls; ++c)
- s.c[(std::size_t) c] = fvocoder::rawFromKnob (slot.params[(std::size_t) (4 + c)], c, s.c[(std::size_t) c]);
- return s;
- }
- constexpr float maxBandLevel = 2.0f; // the strip spans 0…2 (1 = unchanged)
- } // namespace
- void EffectsPanel::setBandLevel (juce::Point<int> p)
- {
- const auto* s = slots();
- if (s == nullptr || ! vocoderSelected())
- return;
- const auto st = vocoderState ((*s)[(std::size_t) selectedSlot]);
- const auto area = bandLevelsBounds();
- const auto band = juce::jlimit (0, st.bands - 1, (int) ((p.x - area.getX()) * st.bands / juce::jmax (1, area.getWidth())));
- auto level = juce::jlimit (0.0f, maxBandLevel, maxBandLevel * (float) (area.getBottom() - p.y) / (float) area.getHeight());
- if (std::abs (level - 1.0f) < 0.04f)
- level = 1.0f; // snaps to the unchanged level
- engine.editSong ([t = track, slot = selectedSlot, band, level] (Song& song) {
- auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
- auto state = vocoderState (fx);
- state.levels[(std::size_t) band] = level;
- fx.state = fvocoder::serialise (state);
- });
- }
- void EffectsPanel::showBandLevelMenu()
- {
- juce::PopupMenu menu;
- auto apply = [this] (float (*level) (int, int)) {
- engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
- auto& fx = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
- auto state = vocoderState (fx);
- for (int k = 0; k < state.bands; ++k)
- state.levels[(std::size_t) k] = level (k, state.bands);
- fx.state = fvocoder::serialise (state);
- });
- };
- menu.addItem (tr ("Reset band levels"), [apply] { apply ([] (int, int) { return 1.0f; }); });
- menu.addItem (tr ("Brighter (tilt up)"), [apply] { apply ([] (int k, int n) { return 0.5f + (float) k / (float) std::max (1, n - 1); }); });
- menu.addItem (tr ("Darker (tilt down)"), [apply] { apply ([] (int k, int n) { return 1.5f - (float) k / (float) std::max (1, n - 1); }); });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- }
- void EffectsPanel::showGatePatterns()
- {
- // ready-made patterns (like Gross Beat's slots): value of step i of 32 (1/8 beat each)
- struct Pattern
- {
- const char* name;
- float (*level) (int);
- };
- static const Pattern patterns[] = {
- { TR_NOOP ("All open"), [] (int) { return 1.0f; } },
- { TR_NOOP ("1/2 beat gate"), [] (int i) { return (i % 4) < 2 ? 1.0f : 0.0f; } },
- { TR_NOOP ("1 beat gate"), [] (int i) { return (i % 8) < 4 ? 1.0f : 0.0f; } },
- { TR_NOOP ("Offbeat"), [] (int i) { return (i % 8) >= 4 ? 1.0f : 0.0f; } },
- { TR_NOOP ("Sidechain (ramp per beat)"), [] (int i) { return std::min (1.0f, 0.15f + (float) (i % 8) / 5.0f); } },
- { TR_NOOP ("Trance gate"), [] (int i) { return (i % 4) == 3 ? 0.0f : (i % 16) >= 12 ? 0.4f : 1.0f; } },
- { TR_NOOP ("Fade-in over the bar"), [] (int i) { return (float) (i + 1) / 32.0f; } },
- { TR_NOOP ("Fade-out over the bar"), [] (int i) { return 1.0f - (float) i / 32.0f; } },
- };
- juce::PopupMenu menu;
- for (const auto& p : patterns)
- menu.addItem (tr (p.name), [this, level = p.level] {
- engine.editSong ([t = track, slot = selectedSlot, level] (Song& song) {
- auto& params = song.mixer[(std::size_t) t].effects[(std::size_t) slot].params;
- for (int i = 0; i < 32; ++i)
- params[(std::size_t) i] = level (i);
- });
- });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- }
- int EffectsPanel::knobAt (juce::Point<int> p) const
- {
- const auto* s = slots();
- if (s == nullptr || selectedSlot < 0 || selectedSlot >= (int) s->size())
- return -1;
- if ((*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq || (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq)
- return -1; // edited in its own window
- const auto count = shownParams ((*s)[(std::size_t) selectedSlot]);
- for (int i = gateSelected() ? 32 : 0; i < count; ++i)
- if (knobBounds (i).contains (p))
- return i;
- return -1;
- }
- void EffectsPanel::paint (juce::Graphics& g)
- {
- const uitrace::Scope trace ("EffectsPanel paint", true, g.getClipBounds());
- using namespace theme;
- g.fillAll (colour::bg2);
- g.setColour (colour::border);
- g.drawVerticalLine (0, 0.0f, (float) getHeight());
- const auto* s = slots();
- if (s == nullptr)
- return;
- const auto& song = engine.getSong();
- g.setColour (colour::textPrimary);
- g.setFont (font (type::title, true));
- textcache::drawText (g, tr ("Effects: {0}", { juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str()) }), 10, 4,
- getWidth() - 70, panelHeader - 8, juce::Justification::centredLeft, true);
- // input row: arm switch (inserts) and the audio input source with its level (the Master has one too, as in FL;
- // REA round 143)
- if (track >= 0 && track < (int) song.mixer.size())
- {
- const auto& mt = song.mixer[(std::size_t) track];
- if (track > 0)
- {
- const auto armed = engine.isInsertArmed (track);
- const auto a = armBounds().toFloat();
- theme::fillRoundRect (g, a, radius::sm, armed ? colour::record.withAlpha (0.25f) : hoverInput == 1 ? colour::bg5 : colour::bg3);
- const auto dot = a.withSizeKeepingCentre (11.0f, 11.0f);
- g.setColour (armed ? colour::record : colour::bg0);
- g.fillEllipse (dot);
- g.setColour (armed ? colour::record.brighter (0.3f) : hoverInput == 1 ? colour::textSecondary : colour::borderStrong);
- g.drawEllipse (dot, 1.0f);
- if (mt.recordSafe)
- {
- g.setColour (colour::textDisabled);
- g.drawLine (dot.getX() + 1.0f, dot.getBottom() - 1.0f, dot.getRight() - 1.0f, dot.getY() + 1.0f, 1.2f);
- }
- }
- auto box = inputBoxBounds().toFloat();
- theme::fillRoundRect (g, box, radius::sm, hoverInput == 2 ? colour::bg4 : colour::bg3);
- g.setColour (hoverInput == 2 ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
- // the level, as a thin bar along the bottom of the box (left over right)
- if (mt.inputChannel >= 0)
- {
- const auto bar = box.reduced (4.0f, 0.0f).withTop (box.getBottom() - 5.0f).withHeight (3.0f);
- g.setColour (colour::bg0);
- g.fillRect (bar);
- for (int side = 0; side < 2; ++side)
- {
- const auto db = juce::Decibels::gainToDecibels (inputLevel[(std::size_t) side], -60.0f);
- const auto fill = juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 60.0f);
- g.setColour (inputLevel[(std::size_t) side] >= 0.99f ? colour::record : colour::meterLow);
- g.fillRect (bar.withHeight (1.5f).translated (0.0f, side * 1.5f).withWidth (bar.getWidth() * fill));
- }
- }
- icons::draw (g, Icon::mic, box.withWidth (18.0f).reduced (2.0f).translated (3.0f, -1.0f), mt.inputChannel >= 0 ? colour::textPrimary : colour::textDisabled);
- const auto names = engine.getInputChannelNames();
- const auto label = mt.inputChannel >= 0 ? juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, names).c_str())
- : tr ("No audio input");
- g.setColour (mt.inputChannel >= 0 ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::body));
- textcache::drawText (g, label, box.withTrimmedLeft (24.0f).withTrimmedRight (18.0f).translated (0.0f, -1.0f).toNearestInt(), juce::Justification::centredLeft, true);
- icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).reduced (4.0f).translated (-2.0f, -1.0f), colour::textSecondary);
- }
- // the insert's effects switch
- if (! s->empty())
- {
- const auto on = mixerops::anyEffectEnabled (song, track);
- const auto r = fxSwitchBounds().toFloat();
- theme::fillRoundRect (g, r, radius::sm, on ? colour::bg5 : colour::bg0);
- g.setColour (muteLed (! on));
- g.fillEllipse (r.withWidth (r.getHeight()).reduced (6.0f).translated (3.0f, 0.0f));
- g.setColour (on ? colour::textPrimary : colour::textDisabled);
- g.setFont (font (type::caption, true));
- textcache::drawText (g, "FX", r.withTrimmedLeft (r.getHeight()).toNearestInt(), juce::Justification::centredLeft);
- }
- g.setFont (font (type::body));
- // the 10 slots, as FL draws them: options arrow, name ("Slot N" when empty), mix knob, LED
- // (rows: FL's slot places, an effect may sit below empty slots, round 170b)
- for (int row = 0; row < maxEffectSlots; ++row)
- {
- const auto i = effectIn (row); // the effect shown here, -1 = empty
- const auto r = slotBounds (row);
- const auto filled = i >= 0;
- const auto isSelected = i == selectedSlot && filled;
- const auto slotHovered = row == hoverSlot && dragSlot < 0;
- theme::fillRoundRect (g, r.toFloat(), radius::sm, isSelected ? colour::bg5 : filled ? (slotHovered ? colour::bg4 : colour::bg3) : (slotHovered ? colour::bg3 : colour::bg2.brighter (0.03f)));
- g.setColour (slotHovered ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (r.toFloat().reduced (0.5f), radius::sm, 1.0f);
- if (isSelected)
- {
- theme::fillRoundRect (g, r.toFloat().withWidth (3.0f).reduced (0.0f, 3.0f), 1.5f, colour::accent);
- }
- {
- const auto a = arrowBounds (row).toFloat().withSizeKeepingCentre (5.0f, 8.0f).translated (1.0f, 0.0f);
- juce::Path tri;
- tri.addTriangle (a.getX(), a.getY(), a.getRight(), a.getCentreY(), a.getX(), a.getBottom());
- g.setColour (slotHovered && hoverArrow ? colour::textPrimary : colour::textSecondary.withAlpha (filled ? 1.0f : 0.6f));
- g.fillPath (tri);
- }
- const auto ledArea = ledBounds (row).toFloat().withSizeKeepingCentre (8.0f, 8.0f);
- const auto textArea = r.withTrimmedLeft (20).withTrimmedRight (46);
- if (filled)
- {
- const auto& slot = (*s)[(std::size_t) i];
- g.setColour (muteLed (! slot.enabled));
- g.fillEllipse (ledArea);
- if (slotHovered && hoverLed)
- {
- g.setColour (colour::textSecondary);
- g.drawEllipse (ledArea.expanded (2.0f), 1.0f);
- }
- g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
- // a LYNX substitute shows the plugin it stands in for, with a "LYNX" badge
- const auto substitute = slot.isSubstitute();
- auto name = quickpick::slotName (engine, slot); // (a plugin renamed in the Plugin database: its new name, round 165c)
- if (slot.sidechain > 0 && slot.sidechain < (int) engine.getSong().mixer.size())
- name << juce::String::fromUTF8 (" \xe2\x86\x90 ") << juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) slot.sidechain].name.c_str());
- auto text = textArea;
- if (substitute)
- {
- const auto badge = text.removeFromRight (34).withSizeKeepingCentre (32, 14).toFloat();
- const auto playing = engine.getSong().slotActive (slot); // off while the project's substitutes are bypassed
- theme::fillRoundRect (g, badge, 3.0f, colour::info.withAlpha (playing ? 0.25f : 0.12f));
- g.setColour (playing ? colour::info : colour::textDisabled);
- const auto keep = g.getCurrentFont();
- g.setFont (font (type::caption, true));
- textcache::drawText (g, "LYNX", badge, juce::Justification::centred);
- g.setFont (keep);
- g.setColour (slot.enabled ? colour::textPrimary : colour::textDisabled);
- }
- textcache::drawText (g, name, text, juce::Justification::centredLeft);
- // slot's dry/wet knob
- const auto mixActive = (hoverParam == mixParam && hoverSlot == row) || (dragParam == mixParam && selectedSlot == i);
- drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), slot.mix, false,
- slot.enabled ? (dragParam == mixParam && selectedSlot == i ? colour::accent : colour::info) : colour::textDisabled, mixActive);
- }
- else
- {
- // an empty slot keeps its controls in place (dimmed), as FL shows them
- g.setColour (muteLed (false).withAlpha (0.3f));
- g.fillEllipse (ledArea);
- drawKnob (g, mixBounds (row).toFloat().withSizeKeepingCentre (18.0f, 18.0f), 1.0f, false, colour::textDisabled.withAlpha (0.5f), false);
- g.setColour (slotHovered ? colour::textSecondary : colour::textDisabled);
- g.setFont (juce::Font (font (type::body)).italicised());
- textcache::drawText (g, tr ("Slot {0}", { juce::String (row + 1) }), textArea, juce::Justification::centredLeft);
- g.setFont (font (type::body));
- }
- }
- paintEq (g);
- g.reduceClipRegion (0, 0, getWidth(), bottomTop() - 6); // the selected effect's knobs stay above the EQ
- if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot)) // where the dragged slot lands (FL: swaps with
- { // the effect there, or takes the empty slot)
- g.setColour (colour::accent);
- g.drawRoundedRectangle (slotBounds (dropSlot).toFloat().reduced (0.5f), radius::sm, 2.0f);
- }
- if (selectedSlot < 0 || selectedSlot >= (int) s->size())
- return;
- const auto& slot = (*s)[(std::size_t) selectedSlot];
- auto drawButton = [&g] (juce::Rectangle<int> button, const juce::String& text, Icon icon) {
- theme::fillRoundRect (g, button.toFloat(), radius::md, colour::bg4);
- const auto f = juce::Font (font (type::body));
- const auto textWidth = juce::GlyphArrangement::getStringWidth (f, text);
- auto content = button.toFloat().withSizeKeepingCentre (juce::jmin ((float) button.getWidth() - 12.0f, textWidth + 22.0f), (float) button.getHeight());
- icons::draw (g, icon, content.removeFromLeft (16.0f).withSizeKeepingCentre (16.0f, 16.0f), colour::textSecondary);
- content.removeFromLeft (6.0f);
- g.setColour (colour::textPrimary);
- g.setFont (f);
- textcache::drawFittedText (g, text, content.toNearestInt(), juce::Justification::centredLeft, 1, 0.85f);
- };
- if (slot.kind == EffectKind::plugin)
- {
- const auto button = pluginButtonBounds();
- drawButton (button, tr ("Open plugin interface"), Icon::plugin);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawText (g, quickpick::slotName (engine, slot), button.translated (0, 34), juce::Justification::centred);
- return;
- }
- if (slot.kind == EffectKind::parametricEq)
- {
- const auto button = pluginButtonBounds();
- drawButton (button, tr ("Open parametric EQ"), Icon::settings);
- const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
- drawParametricEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
- return;
- }
- if (isSoundgoodizerApprox (slot)) // approximated without FL's preset files: its page edits Preset and Amount
- {
- const auto button = pluginButtonBounds();
- drawButton (button, tr ("Open Soundgoodizer"), Icon::settings);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawFittedText (g, tr ("Approximation (FL Studio's Soundgoodizer presets were not found on this computer)"),
- button.translated (0, 34).withHeight (40), juce::Justification::centredTop, 2);
- return;
- }
- if (slot.kind == EffectKind::facetEq)
- {
- const auto button = pluginButtonBounds();
- drawButton (button, tr ("Open Facet EQ"), Icon::settings);
- const auto curve = juce::Rectangle<int> (button.getX(), button.getBottom() + 10, button.getWidth(), 120).toFloat();
- drawFacetEqCurve (g, curve, slot.params, juce::jmax (8000.0, engine.getTransport().sampleRate.load()), slot.enabled);
- return;
- }
- if (slot.kind == EffectKind::parallel) // container: list the branches
- {
- auto y = knobBounds (0).getY() - 28;
- g.setColour (colour::textPrimary);
- g.setFont (font (type::title, true));
- textcache::drawText (g, juce::String::fromUTF8 (effectInfo (slot.kind).name), 10, y, getWidth() - 20, 20, juce::Justification::centredLeft);
- g.setFont (font (type::small));
- for (std::size_t b = 0; b < slot.branches.size(); ++b)
- {
- y += 22;
- juce::String chain;
- if (slot.branches[b].chain.empty())
- chain = tr ("dry");
- for (std::size_t c = 0; c < slot.branches[b].chain.size(); ++c)
- chain += (c > 0 ? " -> " : "") + juce::String::fromUTF8 (effectInfo (slot.branches[b].chain[c].kind).name);
- const auto line = tr ("Branch {0} (x{1}): {2}", { juce::String ((int) b + 1), juce::String (slot.branches[b].gain, 2), chain });
- g.setColour (colour::textSecondary);
- textcache::drawText (g, line, 14, y, getWidth() - 28, 20, juce::Justification::centredLeft, true);
- }
- return;
- }
- const auto& info = effectInfo (slot.kind);
- const auto gate = slot.kind == EffectKind::volumeGate;
- const auto vocoder = slot.kind == EffectKind::vocoder;
- g.setColour (colour::textPrimary);
- g.setFont (font (type::title, true));
- const auto tune = slot.kind == EffectKind::lynxTune;
- const auto editorButton = ! gate && ! vocoder && NativeEffectWindows::canOpen (slot.kind);
- const auto titleY = (gate ? gateStepsBounds().getY() : vocoder ? bandLevelsBounds().getY() : tune ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 28;
- const auto titleRight = getWidth() - 10 - (editorButton ? editorButtonBounds().getWidth() + 6 : 0);
- textcache::drawText (g, juce::String::fromUTF8 (info.name), 10, titleY, titleRight - 10, 20, juce::Justification::centredLeft, true);
- if (slot.isSubstitute()) // which missing plugin this stands in for (the project keeps it)
- {
- const auto titleWidth = juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), juce::String::fromUTF8 (info.name));
- g.setColour (colour::info);
- g.setFont (font (type::caption));
- const auto original = juce::String::fromUTF8 (substituteOriginalName (slot).c_str());
- textcache::drawText (g, engine.getSong().substitutesBypassed ? tr ("LYNX SHARE substitute for {0} (bypassed)", { original }) : tr ("LYNX SHARE substitute for {0}", { original }),
- 10 + titleWidth + 10, titleY,
- juce::jmax (0, titleRight - 20 - titleWidth), 20, juce::Justification::centredLeft, true);
- }
- if (editorButton) // the effect's own window (FL's plugin window)
- {
- const auto b = editorButtonBounds().toFloat();
- const auto hover = getMouseXYRelative().toFloat();
- theme::fillRoundRect (g, b, radius::md, b.contains (hover) ? colour::bg5 : colour::bg4);
- icons::draw (g, Icon::plugin, b.withWidth (22.0f).withSizeKeepingCentre (13.0f, 13.0f).translated (4.0f, 0.0f), colour::textSecondary);
- g.setColour (colour::textPrimary);
- g.setFont (font (type::small));
- textcache::drawFittedText (g, tr ("Editor"), b.withTrimmedLeft (24.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
- }
- if (tune) // the scale's notes on one octave; a note switched off is never a target
- {
- const auto area = tuneKeysBounds().toFloat();
- const auto scaleMask = vocal::scaleMask ((vocal::Scale) lynxtune::scaleIndex (slot.params[lynxtune::scale]), lynxtune::keyIndex (slot.params[lynxtune::key]), 0xfff);
- const auto custom = lynxtune::scaleIndex (slot.params[lynxtune::scale]) == (int) vocal::Scale::custom;
- for (const auto black : { false, true })
- for (int pc = 0; pc < 12; ++pc)
- {
- const auto isBlack = pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10;
- if (isBlack != black)
- continue;
- const auto r = tuneKeyRect (area, pc).reduced (1.0f);
- const auto on = slot.params[(std::size_t) (lynxtune::noteC + pc)] >= 0.5f;
- const auto inScale = custom || (scaleMask & (1u << pc)) != 0;
- auto fill = isBlack ? colour::bg0 : colour::bg2;
- if (inScale && on)
- fill = (slot.enabled ? colour::accent : colour::textDisabled).withAlpha (isBlack ? 0.85f : 0.65f);
- theme::fillRoundRect (g, r, 2.0f, fill);
- g.setColour (colour::gridBar);
- g.drawRoundedRectangle (r, 2.0f, 1.0f);
- if (inScale && ! on) // in the scale but switched off
- {
- g.setColour (colour::textSecondary);
- g.drawLine (r.getX() + 3.0f, r.getBottom() - 3.0f, r.getRight() - 3.0f, r.getBottom() - 14.0f, 1.2f);
- }
- if (! isBlack)
- {
- static const char* names[12] { "C", "", "D", "", "E", "F", "", "G", "", "A", "", "B" };
- g.setColour (inScale && on ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawText (g, names[pc], r.withTrimmedTop (r.getHeight() - 16.0f), juce::Justification::centred);
- }
- }
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawFittedText (g, tr ("Target notes: click a key to switch it off or on"), tuneKeysBounds().withY (tuneKeysBounds().getBottom() + 2).withHeight (14),
- juce::Justification::centredLeft, 1, 0.8f);
- }
- if (vocoder) // the analysis bands' levels, low to high (FL's band level strip)
- {
- const auto st = vocoderState (slot);
- const auto area = bandLevelsBounds().toFloat();
- theme::fillRoundRect (g, area, radius::sm, colour::bg0);
- const auto w = area.getWidth() / (float) st.bands;
- const auto unity = area.getBottom() - area.getHeight() / maxBandLevel;
- for (int k = 0; k < st.bands; ++k)
- {
- const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, st.levels[(std::size_t) k] / maxBandLevel);
- g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha (k % 2 == 0 ? 1.0f : 0.8f));
- 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);
- }
- g.setColour (colour::gridBar);
- g.drawHorizontalLine ((int) unity, area.getX(), area.getRight());
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawFittedText (g, tr ("Band levels: draw them; right-click = presets"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
- juce::Justification::centredLeft, 1, 0.8f);
- }
- if (gate) // 32 steps = 1 bar of 4 beats
- {
- const auto area = gateStepsBounds().toFloat();
- theme::fillRoundRect (g, area, radius::sm, colour::bg0);
- const auto w = area.getWidth() / 32.0f;
- for (int i = 0; i < 32; ++i)
- {
- const auto h = area.getHeight() * juce::jlimit (0.0f, 1.0f, slot.params[(std::size_t) i]);
- g.setColour ((slot.enabled ? colour::accent : colour::textDisabled).withAlpha ((i / 8) % 2 == 0 ? 1.0f : 0.7f));
- g.fillRect (area.getX() + i * w + 1.0f, area.getBottom() - h, w - 2.0f, h);
- }
- g.setColour (colour::gridBar);
- for (int beat = 1; beat < 4; ++beat)
- g.drawVerticalLine ((int) (area.getX() + beat * 8 * w), area.getY(), area.getBottom());
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawFittedText (g, tr ("1 bar: draw the steps; right-click = patterns"), area.withY (area.getBottom() + 2).withHeight (14).toNearestInt(),
- juce::Justification::centredLeft, 1, 0.8f);
- }
- for (int p = gate ? 32 : 0; p < shownParams (slot); ++p)
- {
- const auto r = knobBounds (p);
- const auto value = slot.params[(std::size_t) p];
- // 38 px knob; in tight grids (Effector) it shrinks to fit name and value below
- const auto knobHeight = juce::jlimit (30, 44, r.getHeight() - 30);
- drawKnob (g, r.withHeight (knobHeight).toFloat(), value, false, slot.enabled ? colour::knobArc : colour::textDisabled,
- dragParam == p || (hoverParam == p && hoverSlot < 0));
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- textcache::drawFittedText (g, juce::String::fromUTF8 (info.params[(std::size_t) p].name), r.getX(), r.getY() + knobHeight + 2, r.getWidth(), 14,
- juce::Justification::centred, 1, 0.8f);
- g.setColour (colour::textPrimary);
- textcache::drawText (g, juce::String::fromUTF8 (formatEffectParam (slot.kind, p, value, song.bpm, slot.params).c_str()), r.getX(), r.getY() + knobHeight + 16,
- r.getWidth(), 14, juce::Justification::centred);
- }
- }
- void EffectsPanel::mouseDown (const juce::MouseEvent& e)
- {
- const auto* s = slots();
- if (s == nullptr)
- return;
- if (eqFoldBounds().contains (e.getPosition()) && e.mods.isLeftButtonDown())
- {
- eqFoldChoice = eqFolded ? 1 : 2;
- refit();
- repaint();
- return;
- }
- // the built-in EQ and the output target (bottom section)
- if (outputBounds().contains (e.getPosition()))
- {
- showOutputMenu();
- return;
- }
- if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
- {
- if (isEqPoint (eqControl))
- {
- dragParam = eqControl;
- setEqFromGraph (eqPointBase - eqControl, e.getPosition());
- return;
- }
- if (flmods::popup (e.mods))
- ui::showValueMenu (*this, &engine, specFor (eqControl, -1), valueOf (eqControl, -1), [this, eqControl] (double v) { setValue (eqControl, -1, v); });
- else if (ui::isResetClick (e))
- setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
- else
- {
- dragParam = eqControl;
- drag.begin (e, valueOf (eqControl, -1));
- showTip (eqControl, -1, false);
- }
- return;
- }
- if (track > 0 && armBounds().contains (e.getPosition()))
- {
- if (flmods::popup (e.mods)) // FL: "Record <insert> to" (round 167a)
- mixerinput::chooseRecordTo (engine, track);
- else
- mixerinput::toggleArm (engine, track, this);
- repaint();
- return;
- }
- if (track >= 0 && inputBoxBounds().contains (e.getPosition()))
- {
- mixerinput::showMenu (engine, track, this);
- return;
- }
- if (! s->empty() && fxSwitchBounds().contains (e.getPosition()))
- {
- if (flmods::popup (e.mods))
- toggleAllWindows();
- else
- {
- const auto on = ! mixerops::anyEffectEnabled (engine.getSong(), track);
- engine.editSong ([t = track, on] (Song& song) { mixerops::setAllEffectsEnabled (song, t, on); });
- }
- return;
- }
- for (int row = 0; row < maxEffectSlots; ++row)
- {
- const auto r = slotBounds (row);
- if (! r.contains (e.getPosition()))
- continue;
- const auto i = effectIn (row);
- if (i < 0)
- {
- showAddMenu (row); // (FL: the plugin lands in this slot)
- return;
- }
- if (arrowBounds (row).contains (e.getPosition())) // FL's slot options arrow
- {
- selectedSlot = i;
- repaint();
- showSlotMenu (i);
- return;
- }
- selectedSlot = i;
- repaint();
- if (mixBounds (row).contains (e.getPosition()))
- {
- if (flmods::popup (e.mods))
- ui::showValueMenu (*this, &engine, specFor (mixParam, i), valueOf (mixParam, i), [this, i] (double v) { setValue (mixParam, i, v); });
- else if (ui::isResetClick (e))
- {
- setValue (mixParam, i, 1.0);
- showTip (mixParam, i, true);
- }
- else
- {
- dragParam = mixParam;
- dragStart = (*s)[(std::size_t) i].mix;
- drag.begin (e, dragStart);
- showTip (mixParam, i, false);
- }
- return;
- }
- if (flmods::popup (e.mods) || (e.mods.isShiftDown() && ! ledBounds (row).contains (e.getPosition()))) // (FL: Shift+click = the menu)
- showSlotMenu (i);
- else if (ledBounds (row).contains (e.getPosition())) // LED: bypass
- engine.editSong ([t = track, i] (Song& song) {
- auto& slot = song.mixer[(std::size_t) t].effects[(std::size_t) i];
- slot.enabled = ! slot.enabled;
- });
- else
- dragSlot = i; // dragging the name moves the effect to another slot (a click shows its window)
- return;
- }
- if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::plugin
- && pluginButtonBounds().contains (e.getPosition()))
- {
- openPluginWindow (selectedSlot);
- return;
- }
- if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::parametricEq
- && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
- {
- ParametricEqWindows::open (engine, track, selectedSlot);
- return;
- }
- if (selectedSlot >= 0 && selectedSlot < (int) s->size() && isSoundgoodizerApprox ((*s)[(std::size_t) selectedSlot])
- && pluginButtonBounds().contains (e.getPosition()))
- {
- NativeEffectWindows::open (engine, track, selectedSlot);
- return;
- }
- if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind == EffectKind::facetEq
- && pluginButtonBounds().withHeight (170).contains (e.getPosition()))
- {
- FacetEqWindows::open (engine, track, selectedSlot);
- return;
- }
- if (selectedSlot >= 0 && selectedSlot < (int) s->size() && (*s)[(std::size_t) selectedSlot].kind != EffectKind::volumeGate
- && ! vocoderSelected() && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind)
- && editorButtonBounds().contains (e.getPosition()))
- {
- openEditor (selectedSlot);
- return;
- }
- if (vocoderSelected() && bandLevelsBounds().contains (e.getPosition()))
- {
- if (flmods::popup (e.mods))
- showBandLevelMenu();
- else
- {
- dragParam = bandLevelParam;
- setBandLevel (e.getPosition());
- }
- return;
- }
- if (tuneSelected() && tuneKeysBounds().contains (e.getPosition()))
- {
- toggleTuneNote (e.getPosition());
- return;
- }
- if (gateSelected() && gateStepsBounds().contains (e.getPosition()))
- {
- if (flmods::popup (e.mods))
- showGatePatterns();
- else
- {
- dragParam = gateStepParam;
- setGateStep (e.getPosition());
- }
- return;
- }
- dragParam = knobAt (e.getPosition());
- if (dragParam >= 0 && flmods::popup (e.mods))
- {
- const auto p = dragParam;
- ui::showValueMenu (*this, &engine, specFor (p, selectedSlot), valueOf (p, selectedSlot),
- [this, p, slot = selectedSlot] (double v) { setValue (p, slot, v); });
- dragParam = -1;
- return;
- }
- if (dragParam >= 0 && ui::isResetClick (e))
- {
- setValue (dragParam, selectedSlot, specFor (dragParam, selectedSlot).defaultValue);
- showTip (dragParam, selectedSlot, true);
- dragParam = -1;
- return;
- }
- if (dragParam >= 0)
- {
- dragStart = (*s)[(std::size_t) selectedSlot].params[(std::size_t) dragParam];
- drag.begin (e, dragStart);
- showTip (dragParam, selectedSlot, false);
- }
- }
- ui::ValueSpec EffectsPanel::specFor (int param, int slot) const
- {
- const auto& song = engine.getSong();
- ui::ValueSpec spec;
- spec.pixelsForRange = 150.0;
- if (isEqParam (param)) // the built-in EQ (stored 0..1 here: gain ±18 dB, frequency 10 Hz..16 kHz log, width)
- {
- const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
- const juce::String whatName = what == 0 ? tr ("level") : what == 1 ? tr ("frequency") : tr ("width");
- 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]) })
- + " " + whatName;
- TrackEq defaults;
- spec.defaultValue = eqToValue (defaults, band, what);
- spec.toText = [band, what] (double v) {
- TrackEq eq;
- eqFromValue (eq, band, what, (float) v);
- const auto b = (std::size_t) band;
- return what == 0 ? juce::String (eq.gainDb[b], 1) + " dB"
- : what == 1 ? (eq.hz[b] >= 1000.0f ? juce::String (eq.hz[b] / 1000.0f, 2) + " kHz" : juce::String ((int) eq.hz[b]) + " Hz")
- : juce::String (eq.width[b], 2);
- };
- spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
- return spec;
- }
- if (const auto* s = slots(); s == nullptr || slot < 0 || slot >= (int) s->size())
- return spec;
- const auto& fx = (*slots())[(std::size_t) slot];
- const auto& info = effectInfo (fx.kind);
- const auto trackName = juce::String::fromUTF8 (song.mixer[(std::size_t) track].name.c_str());
- if (param == mixParam)
- {
- spec = ui::percentSpec (trackName + " - " + utf8 (info.name) + " - " + tr ("Mix"), 1.0);
- spec.target = AutomationTarget { AutomationTargetKind::effectMix, track, slot };
- return spec;
- }
- if (param < 0 || param >= (int) info.params.size())
- return spec;
- spec.name = trackName + " - " + utf8 (info.name) + " - " + utf8 (info.params[(std::size_t) param].name);
- spec.defaultValue = info.params[(std::size_t) param].defaultValue;
- 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()); };
- spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
- spec.target = AutomationTarget { AutomationTargetKind::effectParam, track, slot, param };
- return spec;
- }
- double EffectsPanel::valueOf (int param, int slot) const
- {
- if (isEqParam (param))
- return track >= 0 && track < (int) engine.getSong().mixer.size()
- ? eqToValue (engine.getSong().mixer[(std::size_t) track].eq, (eqParamBase - param) / 3, (eqParamBase - param) % 3)
- : 0.0;
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return 0.0;
- const auto& fx = (*s)[(std::size_t) slot];
- return param == mixParam ? fx.mix : (param >= 0 && param < (int) fx.params.size() ? fx.params[(std::size_t) param] : 0.0f);
- }
- void EffectsPanel::setValue (int param, int slot, double value)
- {
- if (isEqParam (param))
- {
- engine.editSong ([t = track, band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3, v = (float) value] (Song& song) {
- if (t < (int) song.mixer.size())
- eqFromValue (song.mixer[(std::size_t) t].eq, band, what, v);
- });
- return;
- }
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return;
- if (param == mixParam)
- engine.editSong ([t = track, slot, v = (float) value] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) slot].mix = v; });
- else if (param >= 0)
- engine.editSong ([t = track, slot, param, v = (float) value] (Song& song) {
- song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) param] = v;
- });
- }
- int EffectsPanel::mixKnobAt (juce::Point<int> p) const
- {
- for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
- if (mixBounds (rowOf (i)).contains (p))
- return i;
- return -1;
- }
- void EffectsPanel::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
- {
- // a spin that is scrolling the mixer goes on scrolling over the EQ, the knobs and the slot names (round 169c)
- if (ui::wheelScrolling())
- {
- ui::noteWheelScroll();
- juce::Component::mouseWheelMove (e, wheel);
- return;
- }
- if (auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
- {
- if (isEqPoint (eqControl)) // the wheel over a handle changes the band's width
- eqControl = eqParamBase - (eqPointBase - eqControl) * 3 - 2;
- if (const auto v = ui::wheelValue (valueOf (eqControl, -1), e, wheel, specFor (eqControl, -1)))
- {
- setValue (eqControl, -1, *v);
- showTip (eqControl, -1, true);
- }
- return;
- }
- if (const auto slot = mixKnobAt (e.getPosition()); slot >= 0)
- {
- if (const auto v = ui::wheelValue (valueOf (mixParam, slot), e, wheel, specFor (mixParam, slot)))
- {
- setValue (mixParam, slot, *v);
- showTip (mixParam, slot, true);
- }
- return;
- }
- if (const auto p = knobAt (e.getPosition()); p >= 0)
- {
- if (const auto v = ui::wheelValue (valueOf (p, selectedSlot), e, wheel, specFor (p, selectedSlot)))
- {
- setValue (p, selectedSlot, *v);
- showTip (p, selectedSlot, true);
- }
- return;
- }
- // FL (REA FUN_012ab750): the wheel over a slot moves its effect one slot up or down (into an empty slot too,
- // wrapping around the 10 slots) and the mouse pointer follows it. A trackpad's small steps add up to one move.
- if (const auto slot = slotAt (e.getPosition()); slot >= 0)
- {
- const auto delta = (wheel.isReversed ? -1.0 : 1.0) * (wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX);
- if (wheelSlot != slot || juce::Time::getMillisecondCounter() - wheelTime > 400)
- wheelAccumulator = 0.0;
- wheelSlot = slot;
- wheelTime = juce::Time::getMillisecondCounter();
- const auto steps = controls::slotWheelSteps (wheelAccumulator, delta, wheel.isSmooth, wheel.isInertial);
- if (steps == 0)
- return;
- int now = -1;
- engine.editSongStructural ([t = track, slot, steps, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, steps > 0 ? -1 : 1); });
- if (now >= 0)
- {
- selectedSlot = wheelSlot = now;
- const auto target = slotBounds (rowOf (now));
- juce::Desktop::getInstance().getMainMouseSource().setScreenPosition (localPointToGlobal (juce::Point<int> (e.x, target.getCentreY())).toFloat());
- }
- repaint();
- return;
- }
- ui::noteWheelScroll();
- juce::Component::mouseWheelMove (e, wheel);
- }
- ui::Hint EffectsPanel::hintAt (juce::Point<int> p)
- {
- const auto gesture = ui::valueGestures();
- if (isEqParam (dragParam))
- return ui::valueHint (specFor (dragParam, -1), valueOf (dragParam, -1), gesture);
- if (const auto eqControl = eqControlAt (p); eqControl != 0)
- {
- if (isEqParam (eqControl))
- return ui::valueHint (specFor (eqControl, -1), valueOf (eqControl, -1), gesture);
- ui::Hint h;
- const auto band = eqPointBase - eqControl;
- h.text = tr ("EQ: [LMB] drag the band's frequency and level [Wheel] width [2xLMB] back to 0 dB");
- h.value = tr ("Band {0}", { juce::String (band + 1) }) + " - " + tr (eqBandNames[band]);
- return h;
- }
- if (slots() != nullptr && eqFoldBounds().contains (p))
- {
- ui::Hint h;
- 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)");
- return h;
- }
- if (outputBounds().contains (p))
- {
- ui::Hint h;
- h.text = track == 0 ? tr ("Audio output target: the outputs of your audio device the Master plays on [LMB] choose")
- : 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");
- h.value = outputName();
- h.hasMenu = true;
- return h;
- }
- if (dragParam == mixParam || (dragParam >= 0 && drag.isActive()))
- return ui::valueHint (specFor (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot),
- valueOf (dragParam, dragParam == mixParam ? juce::jmax (0, selectedSlot) : selectedSlot), gesture);
- if (const auto slot = mixKnobAt (p); slot >= 0)
- return ui::valueHint (specFor (mixParam, slot), valueOf (mixParam, slot), gesture);
- if (const auto param = knobAt (p); param >= 0)
- return ui::valueHint (specFor (param, selectedSlot), valueOf (param, selectedSlot), gesture);
- ui::Hint h;
- if (const auto* s = slots(); s != nullptr && selectedSlot >= 0 && selectedSlot < (int) s->size()
- && NativeEffectWindows::canOpen ((*s)[(std::size_t) selectedSlot].kind) && editorButtonBounds().contains (p))
- {
- h.text = tr ("Open the effect's window (its full controls, as in FL); clicking the slot's name does the same");
- return h;
- }
- if (track > 0 && armBounds().contains (p))
- {
- h.text = mixerinput::armHint (engine, track);
- h.hasMenu = true;
- return h;
- }
- if (track >= 0 && inputBoxBounds().contains (p))
- {
- h.text = track == 0 ? tr ("Audio input source: the microphone or interface input the Master plays (through its effects) [LMB] choose")
- : tr ("Audio input source: the microphone or interface input this insert plays and records [LMB] choose");
- h.hasMenu = true;
- const auto& mt = engine.getSong().mixer[(std::size_t) track];
- if (mt.inputChannel >= 0)
- h.value = juce::String::fromUTF8 (inputSourceName (mt.inputChannel, mt.inputStereo, engine.getInputChannelNames()).c_str());
- return h;
- }
- if (fxSwitchBounds().contains (p) && slots() != nullptr && ! slots()->empty())
- {
- h.text = tr ("All effects of this insert on/off; right-click opens or closes their plugin windows");
- h.hasMenu = true;
- return h;
- }
- for (int i = 0; i < maxEffectSlots; ++i)
- if (slotBounds (i).contains (p))
- {
- const auto used = effectIn (i) >= 0;
- h.text = used ? (arrowBounds (i).contains (p) ? tr ("Effect slot options: replace, move, delete...")
- : 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"))
- : tr ("Empty slot: click to add an effect");
- h.hasMenu = used;
- }
- return h;
- }
- void EffectsPanel::mouseDrag (const juce::MouseEvent& e)
- {
- if (dragSlot >= 0)
- {
- if (e.getDistanceFromDragStart() > 4)
- {
- const auto target = juce::jlimit (0, maxEffectSlots - 1, (e.y - slotsTop) / slotHeight); // (empty slots too, as FL)
- if (target != dropSlot)
- {
- dropSlot = target;
- setMouseCursor (juce::MouseCursor::DraggingHandCursor);
- repaint();
- }
- }
- return;
- }
- if (isEqPoint (dragParam))
- {
- setEqFromGraph (eqPointBase - dragParam, e.getPosition());
- return;
- }
- if (isEqParam (dragParam))
- {
- setValue (dragParam, -1, drag.update (e, specFor (dragParam, -1)));
- showTip (dragParam, -1, false);
- return;
- }
- if (dragParam == gateStepParam)
- {
- setGateStep (e.getPosition());
- return;
- }
- if (dragParam == bandLevelParam)
- {
- setBandLevel (e.getPosition());
- return;
- }
- if (dragParam == mixParam)
- {
- setValue (mixParam, selectedSlot, drag.update (e, specFor (mixParam, selectedSlot)));
- showTip (mixParam, selectedSlot, false);
- return;
- }
- if (dragParam < 0)
- return;
- setValue (dragParam, selectedSlot, drag.update (e, specFor (dragParam, selectedSlot)));
- showTip (dragParam, selectedSlot, false);
- }
- void EffectsPanel::showTip (int param, int slot, bool transient)
- {
- if (isEqParam (param))
- {
- const auto band = (eqParamBase - param) / 3, what = (eqParamBase - param) % 3;
- const auto area = what == 0 ? eqFaderBounds (band) : eqKnobBounds (band, what);
- const auto spec = specFor (param, -1);
- ui::postHint (ui::valueHint (spec, valueOf (param, -1), ui::valueGestures()));
- if (transient)
- ui::flashValueTip (*this, area, spec.text (valueOf (param, -1)));
- else
- ui::showValueTip (*this, area, spec.text (valueOf (param, -1)));
- return;
- }
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return;
- const auto area = param == mixParam ? mixBounds (rowOf (slot)) : knobBounds (param).withHeight (juce::jlimit (30, 44, knobBounds (param).getHeight() - 30));
- const auto text = specFor (param, slot).text (valueOf (param, slot));
- ui::postHint (ui::valueHint (specFor (param, slot), valueOf (param, slot), ui::valueGestures()));
- if (transient)
- ui::flashValueTip (*this, area, text);
- else
- ui::showValueTip (*this, area, text);
- }
- void EffectsPanel::mouseMove (const juce::MouseEvent& e)
- {
- const auto p = e.getPosition();
- auto slot = -1; // (a row)
- auto param = -1;
- auto led = false;
- for (int i = 0; i < maxEffectSlots; ++i)
- if (slotBounds (i).contains (p))
- slot = i;
- if (const auto m = mixKnobAt (p); m >= 0)
- {
- slot = rowOf (m);
- param = mixParam;
- }
- else if (slot < 0)
- param = knobAt (p);
- else
- led = p.x < slotBounds (slot).getX() + 22;
- const auto input = track > 0 && armBounds().contains (p) ? 1 : track >= 0 && inputBoxBounds().contains (p) ? 2 : 0;
- const auto eq = eqControlAt (p);
- const auto output = outputBounds().contains (p);
- auto arrow = false;
- for (int i = 0; i < maxEffectSlots; ++i)
- if (arrowBounds (i).contains (p))
- {
- slot = i;
- arrow = true;
- }
- if (slot >= 0)
- led = ledBounds (slot).contains (p);
- if (slot != hoverSlot || param != hoverParam || led != hoverLed || input != hoverInput || eq != hoverEq || output != hoverOutput || arrow != hoverArrow)
- {
- hoverEq = eq;
- hoverOutput = output;
- hoverArrow = arrow;
- hoverInput = input;
- hoverSlot = slot;
- hoverParam = param;
- hoverLed = led;
- repaint();
- }
- }
- void EffectsPanel::mouseExit (const juce::MouseEvent&)
- {
- if (hoverSlot >= 0 || hoverParam != -1 || hoverInput != 0 || hoverEq != 0 || hoverOutput || hoverArrow)
- {
- hoverEq = 0;
- hoverOutput = hoverArrow = false;
- hoverInput = 0;
- hoverSlot = hoverParam = -1;
- hoverLed = false;
- repaint();
- }
- }
- void EffectsPanel::mouseUp (const juce::MouseEvent& e)
- {
- // a click on the slot's name (not a drag, not the second click of a double-click) shows or hides its window (FL)
- if (dragSlot >= 0 && dropSlot < 0 && ! e.mouseWasDraggedSinceMouseDown() && e.getNumberOfClicks() == 1)
- {
- const auto slot = dragSlot;
- dragSlot = -1;
- toggleEditor (slot);
- }
- if (dragSlot >= 0 && dropSlot >= 0 && dropSlot != rowOf (dragSlot))
- {
- bool moved = false;
- engine.editSongStructural ([t = track, from = dragSlot, to = dropSlot, &moved] (Song& song) { moved = mixerops::moveEffectToRow (song, t, from, to); });
- if (moved)
- selectedSlot = effectIn (dropSlot);
- }
- if (dragSlot >= 0)
- setMouseCursor (juce::MouseCursor::NormalCursor);
- dragSlot = dropSlot = -1;
- repaint();
- dragParam = -1;
- drag.end();
- ui::hideValueTip();
- ui::clearPostedHint();
- }
- void EffectsPanel::mouseDoubleClick (const juce::MouseEvent& e)
- {
- if (const auto eqControl = eqControlAt (e.getPosition()); eqControl != 0)
- {
- if (isEqPoint (eqControl)) // the band back to 0 dB
- setValue (eqParamBase - (eqPointBase - eqControl) * 3, -1, specFor (eqParamBase, -1).defaultValue);
- else
- setValue (eqControl, -1, specFor (eqControl, -1).defaultValue);
- return;
- }
- for (int i = 0; slots() != nullptr && i < (int) slots()->size(); ++i)
- if (mixBounds (rowOf (i)).contains (e.getPosition()))
- {
- engine.editSong ([t = track, i] (Song& song) { song.mixer[(std::size_t) t].effects[(std::size_t) i].mix = 1.0f; });
- return;
- }
- else if (slotBounds (rowOf (i)).contains (e.getPosition()) && ! arrowBounds (rowOf (i)).contains (e.getPosition()) && ! ledBounds (rowOf (i)).contains (e.getPosition()))
- {
- openEditor (i); // (the first click opened it, round 170b): it stays open and comes to the front
- return;
- }
- const auto p = knobAt (e.getPosition());
- if (p < 0)
- return;
- const auto kind = (*slots())[(std::size_t) selectedSlot].kind;
- const auto value = effectInfo (kind).params[(std::size_t) p].defaultValue;
- engine.editSong ([t = track, slot = selectedSlot, p, value] (Song& song) {
- song.mixer[(std::size_t) t].effects[(std::size_t) slot].params[(std::size_t) p] = value;
- });
- }
- bool EffectsPanel::isInterestedInDragSource (const SourceDetails& details)
- {
- return (BrowserComponent::isBrowserDrag (details) && BrowserComponent::draggedFile (details).hasFileExtension ("fst"))
- || BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details);
- }
- void EffectsPanel::itemDropped (const SourceDetails& details)
- {
- if (BrowserComponent::isGeneratorDrag (details))
- {
- if (auto c = BrowserComponent::draggedGenerator (details); c && onInstrumentDropped != nullptr
- && track >= 0 && track < (int) engine.getSong().mixer.size())
- onInstrumentDropped (track, std::move (*c));
- return;
- }
- if (BrowserComponent::isEffectDrag (details))
- {
- if (auto fx = BrowserComponent::draggedEffect (details))
- dropEffect (std::move (*fx), details.localPosition);
- return;
- }
- dropPreset (BrowserComponent::draggedFile (details), details.localPosition);
- }
- bool EffectsPanel::isInterestedInFileDrag (const juce::StringArray& files)
- {
- return files.size() == 1 && juce::File (files[0]).hasFileExtension ("fst");
- }
- void EffectsPanel::filesDropped (const juce::StringArray& files, int x, int y)
- {
- if (! files.isEmpty())
- dropPreset (juce::File (files[0]), { x, y });
- }
- bool EffectsPanel::dropPreset (const juce::File& file, juce::Point<int> position)
- {
- juce::MemoryBlock data;
- if (slots() == nullptr || ! file.loadFileAsData (data))
- return false;
- const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
- const auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm);
- if (! fx)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Preset"),
- tr ("LYNX SHARE can't build an effect from this preset."));
- return false;
- }
- return dropEffect (*fx, position);
- }
- bool EffectsPanel::dropEffect (EffectSlot fx, juce::Point<int> position)
- {
- if (slots() == nullptr)
- return false;
- auto target = -1, emptyRow = -1;
- for (int row = 0; row < maxEffectSlots; ++row)
- if (slotBounds (row).contains (position))
- {
- target = effectIn (row);
- emptyRow = target < 0 ? row : -1;
- }
- if (target < 0 && (int) slots()->size() >= maxEffectSlots)
- return false;
- int added = -1;
- engine.editSong ([t = track, target, emptyRow, &added, fx = std::move (fx)] (Song& song) {
- auto& effects = song.mixer[(std::size_t) t].effects;
- if (target >= 0 && target < (int) effects.size())
- effects[(std::size_t) target] = fx;
- else if (emptyRow >= 0) // dropped on an empty slot: it lands there (FL)
- added = mixerops::insertEffectAtRow (song, t, fx, emptyRow);
- else
- effects.push_back (fx);
- });
- selectedSlot = target >= 0 ? target : added >= 0 ? added : (int) slots()->size() - 1;
- repaint();
- return true;
- }
- juce::Rectangle<int> EffectsPanel::fxSwitchBounds() const
- {
- return { getWidth() - 58, 6, 48, panelHeader - 12 };
- }
- int EffectsPanel::slotAt (juce::Point<int> p) const
- {
- const auto* s = slots();
- for (int i = 0; s != nullptr && i < (int) s->size(); ++i)
- if (const auto row = rowOf (i); slotBounds (row).contains (p) && ! mixBounds (row).contains (p) && ! ledBounds (row).contains (p) && ! arrowBounds (row).contains (p))
- return i;
- return -1;
- }
- void EffectsPanel::toggleAllWindows()
- {
- // opens every plugin effect window of the insert, or closes them all when one is open
- const auto* s = slots();
- if (s == nullptr)
- return;
- bool anyOpen = false;
- for (int i = 0; i < (int) s->size(); ++i)
- if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
- anyOpen = anyOpen || PluginWindows::isOpen (p->getInstance());
- for (int i = 0; i < (int) s->size(); ++i)
- if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, i).get()))
- {
- if (anyOpen)
- PluginWindows::close (p->getInstance());
- else
- openPluginWindow (i);
- }
- }
- juce::Rectangle<int> EffectsPanel::pluginButtonBounds() const
- {
- return { 20, slotsTop + maxEffectSlots * slotHeight + 30, getWidth() - 40, 30 };
- }
- void EffectsPanel::openEditor (int slot)
- {
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return;
- const auto kind = (*s)[(std::size_t) slot].kind;
- if (kind == EffectKind::plugin)
- openPluginWindow (slot);
- else if (kind == EffectKind::parametricEq)
- ParametricEqWindows::open (engine, track, slot);
- else if (NativeEffectWindows::canOpen ((*s)[(std::size_t) slot]))
- NativeEffectWindows::open (engine, track, slot);
- }
- void EffectsPanel::toggleEditor (int slot)
- {
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return;
- // FL (REA FUN_012bde10, the slot name button's click): the plugin's editor is shown, or hidden when it shows
- if ((*s)[(std::size_t) slot].kind == EffectKind::plugin)
- {
- if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()); p != nullptr && PluginWindows::isOpen (p->getInstance()))
- {
- PluginWindows::close (p->getInstance());
- return;
- }
- openPluginWindow (slot);
- return;
- }
- if (! ui::SlotGoneWatcher::closeWindow (engine, track, slot))
- openEditor (slot);
- }
- juce::Rectangle<int> EffectsPanel::editorButtonBounds() const
- {
- // on the title row of the selected effect's knobs
- return { getWidth() - 96, (tuneSelected() ? tuneKeysBounds().getY() : knobBounds (0).getY()) - 29, 86, 20 };
- }
- void EffectsPanel::openPluginWindow (int slot)
- {
- auto effect = engine.getEffect (track, slot);
- if (auto* plugin = dynamic_cast<PluginEffect*> (effect.get()))
- {
- if (plugin->hasCrashed()) // (not called again: its window would call into it)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Plugin"),
- tr ("This plugin crashed and was switched off. Save the project and open it again to reload it."));
- return;
- }
- const auto& s = engine.getSong().mixer[(std::size_t) track].effects[(std::size_t) slot];
- PluginWindows::open (effect, plugin->getInstance(), quickpick::slotName (engine, s), // (its Plugin database name, round 165c)
-
- { &engine, [t = track, slot] (Song& song) -> PluginRef* {
- if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
- return nullptr;
- return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
- } });
- return;
- }
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Plugin"),
- tr ("This plugin could not be loaded (it is not installed or has not been scanned)."));
- }
- void EffectsPanel::showAddMenu (int row)
- {
- juce::PopupMenu menu;
- // the effect lands in the clicked empty slot (FL's slot places, round 170b); returns its index, -1 = not added
- auto place = [this, row] (EffectSlot fx) {
- int at = -1;
- engine.editSong ([t = track, row, &fx, &at] (Song& song) {
- if (t < 0 || t >= (int) song.mixer.size() || (int) song.mixer[(std::size_t) t].effects.size() >= maxEffectSlots)
- return;
- at = mixerops::insertEffectAtRow (song, t, fx, row);
- if (at < 0)
- {
- song.mixer[(std::size_t) t].effects.push_back (std::move (fx));
- at = (int) song.mixer[(std::size_t) t].effects.size() - 1;
- }
- mixerops::linkAddedSidechain (song, t, at); // round 170h: the sole sidechain sender feeds a new compressor
- });
- if (at < 0)
- return at;
- selectedSlot = at;
- if ((*slots())[(std::size_t) at].kind != EffectKind::plugin) // (plugins: their own window, below)
- openEditor (at); // FL opens the effect's window when it is loaded (round 170h, fl-09)
- repaint();
- return at;
- };
- // FL's renamed plugins first (issue #11): "1_EQ" renamed in the Browser's Plugin database is added by typing 1
- auto addFx = [this, place] (EffectSlot fx) {
- const auto at = place (std::move (fx));
- if (at >= 0 && (*slots())[(std::size_t) at].kind == EffectKind::plugin)
- openPluginWindow (at);
- };
- auto picks = quickpick::renamedEffects (engine, addFx);
- quickpick::addPicks (menu, picks);
- // rounds 166f / 170b (Busy Works: "random order"): every effect under its category heading, A-Z, as FL's slot menu
- // (LYNX SHARE first, then FL's Plugin database categories, the user's own folders among them)
- quickpick::addFolderGroups (menu, engine, std::function<void (EffectSlot)> (addFx));
- // LYNX equivalents of well-known third-party effects, with the same default preset a substitute gets
- juce::PopupMenu equivalents;
- for (const auto& entry : pluginSubstitutes())
- if (! entry.instrument)
- equivalents.addItem (juce::String::fromUTF8 (entry.product.c_str()) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + juce::String::fromUTF8 (effectInfo (entry.effect).name),
- [place, entry] { place (makeSubstituteSlot (entry)); });
- if (equivalents.getNumItems() > 0)
- menu.addSubMenu (tr ("LYNX SHARE equivalents"), equivalents);
- juce::PopupMenu plugins;
- addPluginItems (plugins, engine, false, [this, place] (PluginRef ref) {
- EffectSlot slot;
- slot.kind = EffectKind::plugin;
- slot.plugin = ref;
- if (const auto at = place (std::move (slot)); at >= 0)
- openPluginWindow (at);
- }, this);
- menu.addSeparator();
- menu.addSubMenu (tr ("Plugin (VST/VST3/CLAP)"), plugins);
- menu.addSeparator();
- menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
- quickpick::addFolderViewItems (menu, engine); // FL: Categories / Simple / Tree at the bottom
- quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (this).withMousePosition(), std::move (picks));
- }
- void EffectsPanel::showSlotMenu (int slot)
- {
- // the same categories as the empty slot's menu (rounds 166f / 170b)
- juce::PopupMenu replace;
- quickpick::addFolderGroups (replace, engine, std::function<void (EffectSlot)> ([this, slot] (EffectSlot fx) {
- engine.editSong ([t = track, slot, fx] (Song& song) {
- if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
- song.mixer[(std::size_t) t].effects[(std::size_t) slot] = fx;
- });
- if (slot < (int) slots()->size() && (*slots())[(std::size_t) slot].kind == EffectKind::plugin)
- openPluginWindow (slot);
- }));
- quickpick::addFolderViewItems (replace, engine);
- juce::PopupMenu menu;
- menu.addSubMenu (tr ("Replace with"), replace);
- menu.addItem (tr ("Audio editor (record this insert)..."), [this] { openAudioEditorForInsert (engine, track); });
- // FL presets (Plugin presets\Effects\<plugin>) that map to this effect
- {
- juce::PopupMenu presets;
- const auto roots = findFlStudioRoots();
- const auto base = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects");
- for (const auto& plugin : flPluginsForEffect ((*slots())[(std::size_t) slot].kind))
- {
- juce::PopupMenu sub;
- auto files = base.getChildFile (juce::String::fromUTF8 (plugin.c_str())).findChildFiles (juce::File::findFiles, true, "*.fst");
- std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFileName().compareNatural (b.getFileName()) < 0; });
- for (const auto& f : files)
- sub.addItem (f.getFileNameWithoutExtension(), [this, slot, f] {
- juce::MemoryBlock data;
- if (! f.loadFileAsData (data))
- return;
- const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
- if (auto fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm))
- engine.editSong ([t = track, slot, fx = *fx] (Song& song) {
- auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
- const auto enabled = target.enabled;
- const auto mix = target.mix;
- target = fx;
- target.enabled = enabled;
- target.mix = mix;
- });
- });
- if (sub.getNumItems() > 0)
- presets.addSubMenu (juce::String::fromUTF8 (plugin.c_str()), sub);
- }
- if (presets.getNumItems() > 0)
- menu.addSubMenu (tr ("FL presets"), presets);
- }
- // side inputs: another track's output feeds the compressor's detector, or the vocoder's modulator/carrier
- const auto kind = (*slots())[(std::size_t) slot].kind;
- auto sideMenu = [&] (const juce::String& title, bool second) {
- juce::PopupMenu side;
- const auto& fx = (*slots())[(std::size_t) slot];
- const auto current = second ? fx.sidechain2 : fx.sidechain;
- auto assign = [this, slot, second] (int source) {
- engine.editSong ([tk = track, slot, second, source] (Song& s) {
- auto& target = s.mixer[(std::size_t) tk].effects[(std::size_t) slot];
- (second ? target.sidechain2 : target.sidechain) = source;
- if (target.kind == EffectKind::vocoder && source >= 0)
- target.params[16] = 1.0f; // separate inputs (otherwise L = modulator, R = carrier)
- });
- };
- side.addItem (tr ("None"), true, current < 0, [assign] { assign (-1); });
- const auto& song = engine.getSong();
- for (int t = 1; t < (int) song.mixer.size(); ++t)
- if (t != track)
- side.addItem (juce::String (t) + " " + juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()), true, current == t,
- [assign, t] { assign (t); });
- menu.addSubMenu (title, side);
- };
- if (kind == EffectKind::compressor || kind == EffectKind::fruityLimiter || kind == EffectKind::fruityCompressor || kind == EffectKind::facetEq)
- sideMenu (tr ("Sidechain from"), false);
- if (kind == EffectKind::vocoder || kind == EffectKind::vocodex)
- {
- sideMenu (tr ("Modulator from"), false);
- sideMenu (tr ("Carrier from"), true);
- }
- if (kind == EffectKind::newtone || kind == EffectKind::newtime)
- {
- // the sample the plugin plays in slave mode (REA_rodada73): FL's edits are kept in the state but not reproduced
- const auto& fx = (*slots())[(std::size_t) slot];
- const auto current = juce::File (juce::String::fromUTF8 (fx.samplePath.c_str()));
- juce::PopupMenu source;
- source.addItem (fx.samplePath.empty() ? tr ("No sample") : current.getFileName(), false, false, [] {});
- source.addItem (tr ("Choose a sample..."), [this, slot, current] {
- sampleChooser = lynx::ui::makeFileChooser (tr ("Source sample"), current.existsAsFile() ? current : juce::File(),
- "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3");
- lynx::ui::launchChooser (sampleChooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
- [this, slot] (const juce::FileChooser& fc) {
- const auto file = fc.getResult();
- if (file == juce::File())
- return;
- engine.editSong ([t = track, slot, path = file.getFullPathName().toStdString()] (Song& s) {
- if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
- s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath = path;
- });
- });
- });
- source.addItem (tr ("Remove the sample"), ! fx.samplePath.empty(), false, [this, slot] {
- engine.editSong ([t = track, slot] (Song& s) {
- if (t < (int) s.mixer.size() && slot < (int) s.mixer[(std::size_t) t].effects.size())
- s.mixer[(std::size_t) t].effects[(std::size_t) slot].samplePath.clear();
- });
- });
- menu.addSubMenu (tr ("Source sample"), source);
- }
- {
- // A/B compare: keep a copy of the settings, then swap between it and the current ones
- const auto key = std::make_pair (track, slot);
- const auto hasSpare = spare.count (key) > 0 && spare[key].kind == (*slots())[(std::size_t) slot].kind;
- juce::PopupMenu ab;
- ab.addItem (tr ("Store the current settings as B"), [this, key, slot] {
- spare[key] = (*slots())[(std::size_t) slot];
- });
- ab.addItem (tr ("Swap with B"), hasSpare, false, [this, key, slot] {
- const auto stored = spare[key];
- spare[key] = (*slots())[(std::size_t) slot];
- engine.editSong ([t = track, slot, stored] (Song& song) {
- auto& target = song.mixer[(std::size_t) t].effects[(std::size_t) slot];
- const auto enabled = target.enabled;
- target = stored;
- target.enabled = enabled;
- });
- });
- ab.addItem (tr ("Forget B"), hasSpare, false, [this, key] { spare.erase (key); });
- menu.addSubMenu (hasSpare ? tr ("A/B compare (B stored)") : tr ("A/B compare"), ab);
- }
- if ((*slots())[(std::size_t) slot].isSubstitute()) // A/B of every substitute of the project at once (round 113)
- menu.addItem (tr ("Bypass all LYNX SHARE substitutes of this project"), true, engine.getSong().substitutesBypassed, [this] {
- engine.editSong ([] (Song& song) { song.substitutesBypassed = ! song.substitutesBypassed; });
- repaint();
- });
- // FL's slot menu "CPU" section (REA round 139): Allow threaded processing (plugins), Smart disable
- menu.addSectionHeader (tr ("CPU"));
- if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
- menu.addItem (tr ("Allow threaded processing"), true, (*slots())[(std::size_t) slot].plugin.threaded, [this, slot] {
- engine.editSong ([t = track, slot] (Song& song) {
- if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
- 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;
- });
- });
- // FL's per-plugin "Smart disable": skipped while its input and output are silent
- menu.addItem (tr ("Smart disable"), true, (*slots())[(std::size_t) slot].smartDisable, [this, slot] {
- engine.editSong ([t = track, slot] (Song& song) {
- if (t < (int) song.mixer.size() && slot < (int) song.mixer[(std::size_t) t].effects.size())
- song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable = ! song.mixer[(std::size_t) t].effects[(std::size_t) slot].smartDisable;
- });
- });
- menu.addSeparator();
- // FL's Move up / Move down (REA FUN_01233de0 / FUN_01235190): one slot, into an empty one too, wrapping around
- auto move = [this, slot] (int delta) {
- int now = -1;
- engine.editSongStructural ([t = track, slot, delta, &now] (Song& song) { now = mixerops::moveEffectBy (song, t, slot, delta); });
- if (now >= 0)
- selectedSlot = now;
- repaint();
- };
- menu.addItem (tr ("Move up"), [move] { move (-1); });
- menu.addItem (tr ("Move down"), [move] { move (1); });
- if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
- {
- auto* live = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get());
- menu.addSubMenu (tr ("Processing"), pluginProcessingMenu (engine, (*slots())[(std::size_t) slot].plugin, live != nullptr ? &live->getInstance() : nullptr,
- [t = track, slot] (Song& song) -> PluginRef* {
- if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
- return nullptr;
- return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
- }));
- }
- if ((*slots())[(std::size_t) slot].kind == EffectKind::plugin)
- {
- if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (track, slot).get()))
- addPluginParameterItems (menu, engine, p->getInstance(), { AutomationTargetKind::effectParam, track, slot, 0 });
- }
- if ((*slots())[(std::size_t) slot].kind == EffectKind::patcher) // its published parameters (round 171b)
- addPatcherParameterItems (menu, engine, (*slots())[(std::size_t) slot].patcher, { AutomationTargetKind::effectParam, track, slot, 0 });
- // FL's Patcherize / Patcherize all (round 165m): the effect (or the whole chain) into a new Patcher, same sound
- menu.addSeparator();
- menu.addItem (tr ("Patcherize"), patcherize::canPatcherizeSlot (engine.getSong(), track, slot), false, [this, slot] {
- engine.capturePluginStates(); // (the plugins' current settings go with them)
- int placed = -1;
- engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, false); });
- if (placed >= 0)
- selectedSlot = placed;
- repaint();
- });
- menu.addItem (tr ("Patcherize all"), patcherize::slotsForAll (engine.getSong(), track).size() > 1, false, [this, slot] {
- engine.capturePluginStates();
- int placed = -1;
- engine.editSong ([t = track, slot, &placed] (Song& song) { placed = patcherize::patcherizeSlots (song, t, slot, true); });
- if (placed >= 0)
- selectedSlot = placed;
- repaint();
- });
- menu.addSeparator();
- menu.addItem (tr ("Delete") + "\tDel", [this, slot] { deleteSlot (slot); });
- // FL: with the slot's menu open, Delete removes the plugin (issue #11)
- quickpick::showMenu (menu, juce::PopupMenu::Options().withTargetComponent (this).withMousePosition(), {},
- [safe = juce::Component::SafePointer<EffectsPanel> (this), slot] (const juce::KeyPress& key) {
- if (! key.isKeyCode (juce::KeyPress::deleteKey) || safe == nullptr)
- return false;
- juce::MessageManager::callAsync ([safe, slot] {
- if (safe != nullptr)
- safe->deleteSlot (slot);
- });
- return true;
- });
- }
- void EffectsPanel::deleteSlot (int slot)
- {
- const auto* s = slots();
- if (s == nullptr || slot < 0 || slot >= (int) s->size())
- return;
- engine.editSongStructural ([t = track, slot] (Song& song) { mixerops::removeEffectKeepRows (song, t, slot); }); // (FL: the slot stays empty)
- selectedSlot = juce::jmin (slot, (int) slots()->size() - 1);
- repaint();
- }
- void EffectsPanel::changeListenerCallback (juce::ChangeBroadcaster*)
- {
- const auto* s = slots();
- if (s == nullptr)
- track = 0;
- else if (selectedSlot >= (int) s->size())
- selectedSlot = (int) s->size() - 1;
- refit(); // the clean mixer (round 163) changes the height the panel needs
- repaint();
- }
- // ---------------------------------------------------------------------------
- namespace mixerinput
- {
- std::function<void()> openAudioSettings;
- namespace
- {
- juce::String issueText (const AudioEngine::RecordingNotice& notice)
- {
- using I = AudioEngine::InputIssue;
- switch (notice.issue)
- {
- case I::noDevice: return tr ("No audio device is open. Choose one in Settings > Audio.");
- case I::noInputDevice:
- 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.");
- case I::noInputOpen: return tr ("No audio input is open, so nothing can be recorded. Choose an input device in Settings > Audio.");
- case I::armedWithoutInput:
- 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.");
- case I::insertWithoutInput: return tr ("Insert {0} is armed but has no audio input, so it records nothing.", { juce::String (notice.track) });
- case I::failed: return tr ("The audio input could not be used: {0}", { notice.detail });
- case I::lowDisk:
- return tr ("The recordings drive is almost full: about {0} minute(s) of recording left. Free some space or choose another project folder.",
- { notice.detail });
- case I::recordSafe:
- return tr ("Insert {0} is record safe, so it can't be armed. Click its input box and turn \"Record safe\" off first.",
- { juce::String (notice.track) });
- case I::framesLost:
- return tr ("The disk could not keep up while recording: {0} sample(s) became silence (the timing of the take was kept). "
- "Record to a faster drive or close other programs that use the disk.", { notice.detail });
- case I::none: break;
- }
- return {};
- }
- bool aboutTheDevice (AudioEngine::InputIssue issue)
- {
- using I = AudioEngine::InputIssue;
- return issue == I::noDevice || issue == I::noInputDevice || issue == I::noInputOpen || issue == I::failed;
- }
- } // namespace
- void explain (const AudioEngine::RecordingNotice& notice)
- {
- if (notice.issue == AudioEngine::InputIssue::none)
- return;
- using I = AudioEngine::InputIssue;
- const auto aboutRecording = notice.issue == I::lowDisk || notice.issue == I::recordSafe || notice.issue == I::framesLost;
- auto options = juce::MessageBoxOptions()
- .withIconType (juce::MessageBoxIconType::WarningIcon)
- .withTitle (aboutRecording ? tr ("Recording") : tr ("Audio input needed"))
- .withMessage (issueText (notice));
- if (aboutTheDevice (notice.issue) && openAudioSettings)
- {
- options = options.withButton (tr ("Audio settings...")).withButton (tr ("Close"));
- juce::AlertWindow::showAsync (options, [] (int result) {
- if (result == 1 && openAudioSettings)
- openAudioSettings();
- });
- }
- else
- juce::AlertWindow::showAsync (options.withButton (tr ("OK")), nullptr);
- }
- // Round 157 ([DATA] the 0.1.15 projects of a singer who found that "the effects do nothing" on her voice): her
- // microphone was the input of both Insert 1 (with the effects) and the Master. The Master plays its input straight
- // away, without any insert's effects, so the dry voice covered the processed one. When an input is chosen and the
- // Master plays the same device channel as an insert, LYNX says so and offers to take it off the Master.
- void warnDoubleMonitoring (AudioEngine& engine, int track)
- {
- const auto& mixer = engine.getSong().mixer;
- if (mixer.empty() || track < 0 || track >= (int) mixer.size())
- return;
- auto channels = [] (const MixerTrack& t) {
- std::pair<int, int> r { t.inputChannel, t.inputChannel + (t.inputStereo ? 1 : 0) };
- return r;
- };
- auto overlaps = [&] (const MixerTrack& a, const MixerTrack& b) {
- if (a.inputChannel < 0 || b.inputChannel < 0)
- return false;
- const auto [a0, a1] = channels (a);
- const auto [b0, b1] = channels (b);
- return a0 <= b1 && b0 <= a1;
- };
- const auto& master = mixer[0];
- if (master.inputChannel < 0 || master.monitor == InputMonitor::off)
- return;
- int insert = -1;
- for (int t = 1; t < (int) mixer.size() && insert < 0; ++t)
- if ((track == 0 || t == track) && overlaps (master, mixer[(std::size_t) t]))
- insert = t;
- if (insert < 0)
- return;
- const auto name = juce::String::fromUTF8 (mixer[(std::size_t) insert].name.c_str());
- auto options = juce::MessageBoxOptions()
- .withIconType (juce::MessageBoxIconType::WarningIcon)
- .withTitle (tr ("The same input plays twice"))
- .withMessage (tr ("This audio input is the input of the Master and of {0}. The Master plays it straight away, without "
- "{0}'s effects, so you hear the dry sound on top of the processed one (the effects seem to do nothing).\n\n"
- "To hear it through {0}'s effects, take it off the Master.", { name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (insert) }) }))
- .withButton (tr ("Take it off the Master"))
- .withButton (tr ("Keep both"));
- juce::AlertWindow::showAsync (options, [&engine] (int result) {
- if (result == 1)
- engine.setInsertInput (0, -1, true);
- });
- }
- void showMenu (AudioEngine& engine, int track, juce::Component* target, std::function<void()> chosen)
- {
- if (track < 0 || track >= (int) engine.getSong().mixer.size())
- return;
- // the device input opens on demand (only then does Windows show the microphone as in use)
- if (! engine.hasAudioInput())
- if (const auto result = engine.openAudioInput(); result.issue != AudioEngine::InputIssue::none)
- {
- explain (result);
- return;
- }
- const auto& mt = engine.getSong().mixer[(std::size_t) track];
- const auto names = engine.getInputChannelNames();
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Audio input source"));
- menu.addItem (tr ("(none)"), true, mt.inputChannel < 0, [&engine, track] { engine.setInsertInput (track, -1, true); });
- const auto sources = inputSources (names);
- if (sources.empty())
- menu.addItem (tr ("The audio device has no open input channels"), false, false, nullptr);
- for (const auto& source : sources)
- {
- if (! source.stereo && source.channel == 0 && names.size() > 1)
- menu.addSeparator(); // pairs, then single channels
- const auto ticked = mt.inputChannel == source.channel && mt.inputStereo == source.stereo;
- menu.addItem (juce::String::fromUTF8 (source.name.c_str()) + (source.stereo ? "" : " " + tr ("(mono)")), true, ticked,
- [&engine, track, source, chosen] {
- engine.setInsertInput (track, source.channel, source.stereo);
- warnDoubleMonitoring (engine, track);
- if (chosen)
- chosen();
- });
- }
- if (track > 0) // FL's "Record" positions (round 168x, issue #41; FL's AudioRecorderRoutingMenu, in its order)
- {
- menu.addSectionHeader (tr ("Record"));
- const std::pair<RecordSource, const char*> points[] = { { RecordSource::externalInput, TR_NOOP ("External input only") },
- { RecordSource::externalAndMixer, TR_NOOP ("External and mixer input") },
- { RecordSource::postEffects, TR_NOOP ("Post effects") },
- { RecordSource::postEq, TR_NOOP ("Post EQ") },
- { RecordSource::postLevel, TR_NOOP ("Post level and panning") },
- { RecordSource::postTrack, TR_NOOP ("Post track") } };
- for (const auto& [point, label] : points)
- menu.addItem (tr (label), true, mt.recordSource == point, [&engine, track, point = point] { engine.setInsertRecordSource (track, point); });
- // LYNX extra: the dry device input as a second take beside a processed one (DI + amp, for re-amping)
- menu.addItem (tr ("Also record the dry input as a second take (LYNX)"), mt.recordSource != RecordSource::externalInput,
- mt.recordDryToo && mt.recordSource != RecordSource::externalInput,
- [&engine, track, on = mt.recordDryToo] { engine.setInsertRecordDryToo (track, ! on); });
- }
- menu.addSectionHeader (tr ("Monitor external input"));
- const std::pair<InputMonitor, const char*> modes[] = { { InputMonitor::off, TR_NOOP ("Off") },
- { InputMonitor::whenArmed, TR_NOOP ("When armed") },
- { InputMonitor::automatic, TR_NOOP ("Auto (when armed, not while playing back)") },
- { InputMonitor::on, TR_NOOP ("On") } };
- for (const auto& [mode, label] : modes)
- {
- // the Master has no record arm: its input plays unless monitoring is off
- if (track == 0 && (mode == InputMonitor::whenArmed || mode == InputMonitor::automatic))
- continue;
- const auto ticked = track == 0 ? (mode == InputMonitor::off) == (mt.monitor == InputMonitor::off) : mt.monitor == mode;
- menu.addItem (tr (label), true, ticked, [&engine, track, mode = mode] { engine.setInsertMonitor (track, mode); });
- }
- if (track > 0) // record safe (round 163): the insert can't be armed by accident
- {
- menu.addSeparator();
- menu.addItem (tr ("Record safe (can't be armed)"), true, mt.recordSafe,
- [&engine, track, safe = mt.recordSafe] { engine.setInsertRecordSafe (track, ! safe); });
- }
- menu.addSeparator();
- menu.addItem (tr ("Audio settings (input device)..."), openAudioSettings != nullptr, false, [] {
- if (openAudioSettings)
- openAudioSettings();
- });
- auto options = juce::PopupMenu::Options();
- if (target != nullptr)
- options = options.withTargetComponent (target).withMousePosition();
- menu.showMenuAsync (options);
- }
- juce::String armHint (const AudioEngine& engine, int track)
- {
- auto text = tr ("Record arm: Rec + Play records this insert into a Playlist clip [RMB] record to a file");
- if (track <= 0 || track >= (int) engine.getSong().mixer.size())
- return text;
- // FL's hint names the position: "Recording: Post EQ" (round 168x; changed in the input box's menu)
- static const char* const points[] { TR_NOOP ("External input only"), TR_NOOP ("External and mixer input"), TR_NOOP ("Post effects"),
- TR_NOOP ("Post EQ"), TR_NOOP ("Post level and panning"), TR_NOOP ("Post track") };
- const auto& mt = engine.getSong().mixer[(std::size_t) track];
- text = tr ("Recording: {0}", { tr (points[juce::jlimit (0, 5, (int) mt.recordSource)]) })
- + (mt.recordDryToo && mt.recordSource != RecordSource::externalInput ? " + " + tr ("dry input") : juce::String()) + " " + text;
- if (mt.recordTo.empty())
- return text;
- const auto file = juce::File (juce::String::fromUTF8 (engine.getSong().mixer[(std::size_t) track].recordTo.c_str()));
- return tr ("Record to: {0}", { file.getFileName() }) + " " + text;
- }
- void chooseRecordTo (AudioEngine& engine, int track)
- {
- if (track <= 0 || track >= (int) engine.getSong().mixer.size())
- return;
- if (engine.getSong().mixer[(std::size_t) track].recordSafe)
- {
- AudioEngine::RecordingNotice notice;
- notice.issue = AudioEngine::InputIssue::recordSafe;
- notice.track = track;
- explain (notice);
- return;
- }
- const auto insert = juce::String::fromUTF8 (mixerops::insertDisplayName (engine.getSong(), track).c_str());
- const auto& current = engine.getSong().mixer[(std::size_t) track].recordTo;
- juce::File initial;
- if (! current.empty() && juce::File::isAbsolutePath (juce::String::fromUTF8 (current.c_str())))
- initial = juce::File (juce::String::fromUTF8 (current.c_str()));
- else
- {
- // FL's default: Audio\Recorded, "<project title>_YYYY-MM-DD HH-MM-SS_<insert name>"
- auto folder = engine.getRecordingFolder();
- folder.createDirectory();
- const auto now = juce::Time::getCurrentTime();
- const auto name = juce::File::createLegalFileName (juce::String::fromUTF8 (
- safety::recordingName (engine.getRecordingStem().toStdString(), now.getYear(), now.getMonth() + 1, now.getDayOfMonth(), now.getHours(),
- now.getMinutes(), now.getSeconds(), insert.toStdString()).c_str()));
- initial = folder.getChildFile (name + ".wav");
- }
- static std::unique_ptr<juce::FileChooser> chooser;
- chooser = lynx::ui::makeFileChooser (tr ("Record {0} to", { insert }), initial, "*.wav");
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
- [&engine, track] (const juce::FileChooser& fc) {
- auto file = fc.getResult();
- if (file == juce::File() || track >= (int) engine.getSong().mixer.size())
- return;
- if (! file.hasFileExtension (".wav"))
- file = file.withFileExtension (".wav");
- engine.editSong ([track, path = file.getFullPathName().toStdString()] (Song& s) {
- if (track < (int) s.mixer.size())
- s.mixer[(std::size_t) track].recordTo = path;
- });
- if (! engine.isInsertArmed (track)) // FL arms it (and the insert gets selected)
- toggleArm (engine, track, nullptr);
- });
- }
- void toggleArm (AudioEngine& engine, int track, juce::Component* /*target*/)
- {
- if (track < 0 || track >= (int) engine.getSong().mixer.size())
- return;
- // FL 2026: arms at once, also without an input source (the recording start reports a missing input)
- switch (armClick (track, engine.isInsertArmed (track)))
- {
- case ArmClick::none: return;
- case ArmClick::disarm: engine.setInsertArmed (track, false); return;
- case ArmClick::arm:
- engine.setInsertArmed (track, true);
- if (const auto notice = engine.takeRecordingNotice(); notice.issue != AudioEngine::InputIssue::none)
- explain (notice);
- return;
- }
- }
- } // namespace mixerinput
- // ---------------------------------------------------------------------------
- MixerLayoutBox::MixerLayoutBox (MixerStrips& s)
- : strips (s)
- {
- setTooltip (tr ("Mixer layout"));
- setMouseCursor (juce::MouseCursor::PointingHandCursor);
- }
- juce::PopupMenu MixerLayoutBox::menu (MixerStrips& strips)
- {
- juce::PopupMenu m;
- for (int i = 0; i < mixerlayout::layoutCount; ++i)
- {
- const auto l = (mixerlayout::Layout) i;
- m.addItem (tr (juce::String (std::string (mixerlayout::nameOf (l)))), true, MixerStrips::layout == l,
- [&strips, l] { strips.setLayout (l); });
- if (mixerlayout::separatorAfter (l))
- m.addSeparator();
- }
- return m;
- }
- void MixerLayoutBox::paint (juce::Graphics& g)
- {
- using namespace theme;
- const auto hot = isMouseOverOrDragging();
- auto box = getLocalBounds().toFloat().reduced (1.0f, 2.0f);
- theme::fillRoundRect (g, box, radius::sm, hot ? colour::bg4 : colour::bg2);
- g.setColour (hot ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (box.reduced (0.5f), radius::sm, 1.0f);
- // round 170e: the strips icon names what the box is (it showed only "Wide")
- icons::draw (g, Icon::mixer, box.withWidth (24.0f).withSizeKeepingCentre (14.0f, 14.0f), hot ? colour::textPrimary : colour::textSecondary);
- g.setColour (colour::accent);
- g.setFont (font (type::small, true));
- g.drawFittedText (tr (juce::String (std::string (mixerlayout::nameOf (MixerStrips::layout)))), getLocalBounds().reduced (8, 0).withTrimmedLeft (18).withTrimmedRight (14),
- juce::Justification::centredLeft, 1, 0.8f);
- icons::draw (g, Icon::chevronDown, box.removeFromRight (18.0f).withSizeKeepingCentre (12.0f, 12.0f), hot ? colour::textPrimary : colour::textSecondary);
- }
- void MixerLayoutBox::mouseDown (const juce::MouseEvent&)
- {
- menu (strips).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
- }
- MixerComponent::MixerComponent (AudioEngine& e)
- : engine (e),
- strips (e),
- effects (e)
- {
- viewport.setViewedComponent (&strips, false);
- viewport.setScrollBarsShown (false, true);
- addAndMakeVisible (viewport);
- effectsView.setViewedComponent (&effects, false);
- effectsView.setScrollBarsShown (true, false);
- effectsView.setScrollBarThickness (10);
- addAndMakeVisible (effectsView);
- strips.onSelectionChanged = [this] (int track) { effects.setTrack (track); };
- strips.onEffectDropped = [this] (int track, EffectSlot fx) {
- strips.selectTrack (track);
- effects.setTrack (track);
- if (! addEffectToSelected (std::move (fx)))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Plugin database"),
- tr ("The selected insert has no free effect slot."));
- else // FL opens the dropped effect's window (round 171c: the Plugin picker's drag is FL's Browser drag)
- openSlotEditor (track, (int) engine.getSong().mixer[(std::size_t) track].effects.size() - 1);
- };
- strips.onInstrumentDropped = [this] (int track, ChannelDef c) {
- selectTrack (track);
- if (onInstrumentDropped != nullptr)
- onInstrumentDropped (track, std::move (c));
- };
- effects.onInstrumentDropped = strips.onInstrumentDropped;
- }
- bool MixerComponent::runAction (const std::string& id)
- {
- if (id == "mixer.moveLeft")
- strips.moveSelected (-1);
- else if (id == "mixer.moveRight")
- strips.moveSelected (1);
- else if (id == "mixer.linkChannels")
- strips.linkSelectedChannels (false);
- else if (id == "mixer.linkChannelsFrom")
- strips.linkSelectedChannels (true);
- else if (id == "mixer.selectLinkedChannels")
- strips.selectLinkedChannels();
- else if (id == "mixer.rename") // FL's mixer menu keys (round 167k): the menu's own items
- return strips.runMenuItem (tr ("Rename and color..."));
- else if (id == "mixer.soloSelected")
- return strips.runMenuItem (tr ("Solo selected track(s)"));
- else if (id == "mixer.altSoloSelected")
- return strips.runMenuItem (tr ("Alt solo selected track(s)"));
- else if (id == "mixer.renderArmed")
- return strips.runMenuItem (tr ("Render armed tracks to wave file(s)..."));
- else if (id == "mixer.renderSelected")
- return strips.runMenuItem (tr ("Render selected tracks to wave file(s)..."));
- else if (id == "mixer.deleteEffect") // FL: Delete on the selected effect slot (issue #11)
- effects.deleteSlot (effects.getSelectedSlot());
- else
- return false;
- return true;
- }
- bool MixerComponent::loadPresetOnSelection (const juce::File& file)
- {
- return mixerpresets::loadOnTracks (engine, strips.getSelection(), file);
- }
- bool MixerComponent::addEffectToSelected (EffectSlot slot)
- {
- const auto t = strips.getSelectedTrack();
- bool added = false;
- engine.editSong ([t, &slot, &added] (Song& s) {
- if (s.mixer.empty())
- s.mixer = Song::defaultMixer (0);
- if (t < (int) s.mixer.size() && (int) s.mixer[(std::size_t) t].effects.size() < maxEffectSlots)
- {
- s.mixer[(std::size_t) t].effects.push_back (std::move (slot));
- added = true;
- }
- });
- if (added)
- {
- effects.setTrack (t);
- effects.selectSlot ((int) engine.getSong().mixer[(std::size_t) t].effects.size() - 1);
- }
- return added;
- }
- void MixerComponent::selectFirstTrackWithEffects()
- {
- const auto& mixer = engine.getSong().mixer;
- for (int t = 0; t < (int) mixer.size(); ++t)
- if (! mixer[(std::size_t) t].effects.empty())
- {
- strips.selectTrack (t);
- return;
- }
- }
- void MixerComponent::selectTrack (int track)
- {
- strips.selectTrack (track);
- // scroll the strip into view
- const auto t = strips.getSelectedTrack();
- const auto x = strips.stripLeft (t);
- const auto w = strips.widthOf (t);
- const auto view = viewport.getViewArea();
- if (x < view.getX() || x + w > view.getRight())
- viewport.setViewPosition (juce::jmax (0, x - view.getWidth() / 2), 0);
- }
- void MixerComponent::resized()
- {
- auto area = getLocalBounds();
- effectsView.setBounds (area.removeFromRight (effectsWidth));
- effects.fitToView (effectsView.getWidth(), effectsView.getHeight(), effectsView.getScrollBarThickness());
- viewport.setBounds (area);
- strips.setVisibleHeight (area.getHeight() - viewport.getScrollBarThickness());
- }
- } // namespace lynx
|