ChannelSettings.cpp 278 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419
  1. #include <optional>
  2. #include "ui/WindowOwner.h"
  3. #include "core/NoteNames.h"
  4. #include "ui/ChannelSettings.h"
  5. #include "ui/LayerEditor.h"
  6. #include "ui/DanceView.h"
  7. #include "ui/Controllers164.h"
  8. #include "ui/VoltageEditor.h"
  9. #include "ui/AutomationUi.h"
  10. #include "ui/BrowserComponent.h"
  11. #include "core/MixerOps.h"
  12. #include "core/ClipOps.h"
  13. #include "core/TempoDetect.h"
  14. #include <cstring>
  15. #include <functional>
  16. #include "core/DrumSynthLive.h"
  17. #include "core/FlSynths.h"
  18. #include "core/FlKeys.h"
  19. #include "core/ChannelMiscFx.h"
  20. #include "core/FlpImport.h"
  21. #include "core/Harmor.h"
  22. #include "core/Gms.h"
  23. #include "core/MiniSynth.h"
  24. #include "core/SimSynth.h"
  25. #include "core/Drumaxx.h"
  26. #include "core/DrumControls.h"
  27. #include <map>
  28. #include "core/Granulizer.h"
  29. #include "core/Morphine.h"
  30. #include "core/Ogun.h"
  31. #include "core/Dx10.h"
  32. #include "core/Kepler.h"
  33. #include "core/PoiZone.h"
  34. #include "core/LynxBanks.h"
  35. #include "core/ModelParams.h"
  36. #include "core/BassDrum.h"
  37. #include "core/FruitKick.h"
  38. #include "core/Toxic.h"
  39. #include "core/ThreeOsc.h"
  40. #include "core/BeepMap.h"
  41. #include "core/Sawer.h"
  42. #include "core/TransistorBass.h"
  43. #include "core/Slayer.h"
  44. #include "core/SytrusEngine.h"
  45. #include "core/SynthPresets.h"
  46. #include "core/PluginLayout.h"
  47. #include "engine/SampleLibrary.h"
  48. #include "engine/Text.h"
  49. #include "core/RackOps.h"
  50. #include "core/NativeEngines.h"
  51. #include "core/PresetCycle.h"
  52. #include "ui/ControllerEditors.h"
  53. #include "ui/HintBar.h"
  54. #include "ui/ValueControl.h"
  55. #include "ui/I18n.h"
  56. #include "ui/PluginSkin.h"
  57. #include "ui/Theme.h"
  58. #include "ui/WaveformView.h"
  59. #include "ui/SoundFontEditor.h"
  60. #include "ui/VfxEditors.h"
  61. #include "ui/VideoPlayerView.h"
  62. #include "ui/WaveTravellerEditor.h"
  63. #include "ui/BrowserComponent.h"
  64. #include "engine/SampleLibrary.h"
  65. #include "core/SampleFiles.h"
  66. #include "core/ProjectContents.h"
  67. namespace lynx
  68. {
  69. namespace
  70. {
  71. // Which channel a page edits (round 164f): a Channel Rack channel, or the generator of a Patcher node found through
  72. // `locate` (index −1) — the same pages edit both, so a node opens the editor its engine has on a channel.
  73. struct ChannelRef
  74. {
  75. std::function<ChannelDef* (Song&)> locate;
  76. int index = -1; // the Channel Rack index (automation targets, its windows); −1 = a Patcher node
  77. static ChannelRef rack (int c)
  78. {
  79. return { [c] (Song& s) -> ChannelDef* { return c >= 0 && c < (int) s.channels.size() ? &s.channels[(std::size_t) c] : nullptr; }, c };
  80. }
  81. const ChannelDef* get (const AudioEngine& engine) const { return locate ? locate (const_cast<Song&> (engine.getSong())) : nullptr; }
  82. void edit (AudioEngine& engine, std::function<void (ChannelDef&)> change, bool undoable = true) const
  83. {
  84. engine.editSong ([l = locate, change = std::move (change)] (Song& s) {
  85. if (auto* d = l ? l (s) : nullptr)
  86. change (*d);
  87. }, undoable);
  88. }
  89. };
  90. void showModulationFor (juce::Component& from, AudioEngine& engine, int channel);
  91. // Cutoff and pitch envelopes (FL's channel envelopes), used by the synth and the sampler.
  92. class ModEnvelopeEditor final : public juce::Component
  93. {
  94. public:
  95. std::function<void()> onChange;
  96. static constexpr int preferredHeight = 16 + 2 * 62;
  97. ModEnvelopeEditor()
  98. {
  99. const juce::String titles[] = { tr ("Cutoff env."), tr ("Pitch env.") };
  100. for (int e = 0; e < 2; ++e)
  101. {
  102. auto& row = rows[(std::size_t) e];
  103. row.title.setText (titles[e], juce::dontSendNotification);
  104. row.title.setFont (theme::font (theme::type::small));
  105. addAndMakeVisible (row.title);
  106. knob (row.amount, e == 0 ? -10.0 : -48.0, e == 0 ? 10.0 : 48.0, 0.01, e == 0 ? " oct" : " st");
  107. row.amount.setDoubleClickReturnValue (true, 0.0);
  108. row.amount.setTooltip (tr ("0 = off"));
  109. for (auto* s : { &row.attack, &row.hold, &row.decay, &row.release })
  110. {
  111. knob (*s, 0.0, 10.0, 0.001, " s");
  112. s->setSkewFactorFromMidPoint (0.5);
  113. }
  114. knob (row.sustain, 0.0, 1.0, 0.01, "");
  115. }
  116. const char* names[] = { TR_NOOP ("Amount"), TR_NOOP ("Attack"), TR_NOOP ("Hold"), TR_NOOP ("Decay"), TR_NOOP ("Sustain"), TR_NOOP ("Release") };
  117. for (int i = 0; i < 6; ++i)
  118. {
  119. labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
  120. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  121. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  122. addAndMakeVisible (labels[(std::size_t) i]);
  123. }
  124. }
  125. void resized() override
  126. {
  127. auto area = getLocalBounds();
  128. auto header = area.removeFromTop (16);
  129. header.removeFromLeft (80);
  130. const auto w = header.getWidth() / 6;
  131. for (auto& l : labels)
  132. l.setBounds (header.removeFromLeft (w));
  133. for (auto& row : rows)
  134. {
  135. auto line = area.removeFromTop (62);
  136. row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
  137. for (auto* s : { &row.amount, &row.attack, &row.hold, &row.decay, &row.sustain, &row.release })
  138. s->setBounds (line.removeFromLeft (w));
  139. }
  140. }
  141. void show (const ModEnvelope& filter, const ModEnvelope& pitch)
  142. {
  143. rows[0].show (filter);
  144. rows[1].show (pitch);
  145. }
  146. ModEnvelope filter() const { return rows[0].read(); }
  147. ModEnvelope pitch() const { return rows[1].read(); }
  148. private:
  149. struct Row
  150. {
  151. juce::Label title;
  152. juce::Slider amount, attack, hold, decay, sustain, release;
  153. void show (const ModEnvelope& e)
  154. {
  155. amount.setValue (e.amount, juce::dontSendNotification);
  156. attack.setValue (e.attack, juce::dontSendNotification);
  157. hold.setValue (e.hold, juce::dontSendNotification);
  158. decay.setValue (e.decay, juce::dontSendNotification);
  159. sustain.setValue (e.sustain, juce::dontSendNotification);
  160. release.setValue (e.release, juce::dontSendNotification);
  161. }
  162. ModEnvelope read() const
  163. {
  164. return { (float) amount.getValue(), (float) attack.getValue(), (float) hold.getValue(),
  165. (float) decay.getValue(), (float) sustain.getValue(), (float) release.getValue() };
  166. }
  167. };
  168. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  169. {
  170. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  171. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  172. // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
  173. s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
  174. s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
  175. s.setRange (lo, hi, step);
  176. s.setTextValueSuffix (suffix);
  177. s.onValueChange = [this] {
  178. if (onChange)
  179. onChange();
  180. };
  181. addAndMakeVisible (s);
  182. }
  183. std::array<Row, 2> rows;
  184. std::array<juce::Label, 6> labels;
  185. };
  186. // Channel LFOs (pan, volume, cutoff, pitch), like FL's.
  187. class LfoEditor final : public juce::Component
  188. {
  189. public:
  190. std::function<void()> onChange;
  191. static constexpr int preferredHeight = 18 + lfoTargets * 60;
  192. LfoEditor()
  193. {
  194. const juce::String titles[] = { tr ("Pan LFO"), tr ("Volume LFO"), tr ("Cutoff LFO"), tr ("Pitch LFO") };
  195. const double amountRange[] = { 1.0, 1.0, 8.0, 24.0 };
  196. const char* amountSuffix[] = { "", "", " oct", " st" };
  197. for (int i = 0; i < lfoTargets; ++i)
  198. {
  199. auto& row = rows[(std::size_t) i];
  200. row.title.setText (titles[i], juce::dontSendNotification);
  201. row.title.setFont (theme::font (theme::type::small));
  202. addAndMakeVisible (row.title);
  203. knob (row.amount, -amountRange[i], amountRange[i], 0.01, amountSuffix[i]);
  204. row.amount.setDoubleClickReturnValue (true, 0.0);
  205. row.amount.setTooltip (tr ("0 = off"));
  206. knob (row.period, 0.01, 16.0, 0.001, "");
  207. row.period.setSkewFactorFromMidPoint (0.5);
  208. knob (row.delay, 0.0, 8.0, 0.001, "");
  209. row.delay.setSkewFactorFromMidPoint (0.5);
  210. knob (row.attack, 0.0, 8.0, 0.001, "");
  211. row.attack.setSkewFactorFromMidPoint (0.5);
  212. row.shape.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Pulse") }, 1);
  213. row.shape.onChange = [this] { changed(); };
  214. addAndMakeVisible (row.shape);
  215. row.sync.setButtonText (tr ("Beats"));
  216. row.sync.setTooltip (tr ("Period, delay and fade-in in beats (follows the BPM) instead of seconds"));
  217. row.sync.onClick = [this] { changed(); };
  218. addAndMakeVisible (row.sync);
  219. row.global.setButtonText (tr ("Global"));
  220. row.global.setTooltip (tr ("Phase follows the song position instead of restarting on each note"));
  221. row.global.onClick = [this] { changed(); };
  222. addAndMakeVisible (row.global);
  223. }
  224. const juce::String headers[] = { tr ("Amount"), tr ("Period"), tr ("Shape"), tr ("Delay"), tr ("Fade-in"), tr ("Unit") };
  225. for (int i = 0; i < 6; ++i)
  226. {
  227. labels[(std::size_t) i].setText (headers[i], juce::dontSendNotification);
  228. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  229. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  230. addAndMakeVisible (labels[(std::size_t) i]);
  231. }
  232. }
  233. void resized() override
  234. {
  235. auto area = getLocalBounds();
  236. auto header = area.removeFromTop (18);
  237. header.removeFromLeft (80);
  238. const auto w = header.getWidth() / 6;
  239. for (auto& l : labels)
  240. l.setBounds (header.removeFromLeft (w));
  241. for (auto& row : rows)
  242. {
  243. auto line = area.removeFromTop (60);
  244. row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
  245. row.amount.setBounds (line.removeFromLeft (w));
  246. row.period.setBounds (line.removeFromLeft (w));
  247. row.shape.setBounds (line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 24));
  248. row.delay.setBounds (line.removeFromLeft (w));
  249. row.attack.setBounds (line.removeFromLeft (w));
  250. auto toggles = line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 50);
  251. row.sync.setBounds (toggles.removeFromTop (24));
  252. row.global.setBounds (toggles.removeFromBottom (24));
  253. }
  254. }
  255. void show (const std::array<ChannelLfo, lfoTargets>& lfo)
  256. {
  257. for (std::size_t i = 0; i < lfoTargets; ++i)
  258. {
  259. auto& row = rows[i];
  260. const auto& l = lfo[i];
  261. row.amount.setValue (l.amount, juce::dontSendNotification);
  262. row.period.setValue (l.period, juce::dontSendNotification);
  263. row.delay.setValue (l.delay, juce::dontSendNotification);
  264. row.attack.setValue (l.attack, juce::dontSendNotification);
  265. row.shape.setSelectedId (l.shape + 1, juce::dontSendNotification);
  266. row.sync.setToggleState (l.sync, juce::dontSendNotification);
  267. row.global.setToggleState (l.global, juce::dontSendNotification);
  268. const auto unit = l.sync ? " t" : " s";
  269. for (auto* s : { &row.period, &row.delay, &row.attack })
  270. s->setTextValueSuffix (unit);
  271. }
  272. }
  273. std::array<ChannelLfo, lfoTargets> read() const
  274. {
  275. std::array<ChannelLfo, lfoTargets> lfo {};
  276. for (std::size_t i = 0; i < lfoTargets; ++i)
  277. {
  278. const auto& row = rows[i];
  279. lfo[i] = { (float) row.amount.getValue(), (float) row.period.getValue(), row.sync.getToggleState(),
  280. juce::jlimit (0, 2, row.shape.getSelectedId() - 1), (float) row.delay.getValue(), (float) row.attack.getValue(),
  281. row.global.getToggleState() };
  282. }
  283. return lfo;
  284. }
  285. private:
  286. struct Row
  287. {
  288. juce::Label title;
  289. juce::Slider amount, period, delay, attack;
  290. juce::ComboBox shape;
  291. juce::ToggleButton sync, global;
  292. };
  293. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  294. {
  295. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  296. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  297. // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
  298. s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
  299. s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
  300. s.setRange (lo, hi, step);
  301. s.setTextValueSuffix (suffix);
  302. s.onValueChange = [this] { changed(); };
  303. addAndMakeVisible (s);
  304. }
  305. void changed()
  306. {
  307. if (onChange)
  308. onChange();
  309. }
  310. std::array<Row, lfoTargets> rows;
  311. std::array<juce::Label, 6> labels;
  312. };
  313. // Channel modulation window: cutoff/pitch envelopes and LFOs of the synth or the sampler.
  314. class ModulationPanel final : public juce::Component,
  315. private juce::ChangeListener
  316. {
  317. public:
  318. ModulationPanel (AudioEngine& e, ChannelRef c)
  319. : engine (e),
  320. ref (std::move (c))
  321. {
  322. envelopes.onChange = [this] { apply(); };
  323. lfos.onChange = [this] { apply(); };
  324. addAndMakeVisible (envelopes);
  325. addAndMakeVisible (lfos);
  326. refresh();
  327. engine.addChangeListener (this);
  328. setSize (660, 20 + ModEnvelopeEditor::preferredHeight + 16 + LfoEditor::preferredHeight);
  329. }
  330. ~ModulationPanel() override { engine.removeChangeListener (this); }
  331. void resized() override
  332. {
  333. auto area = getLocalBounds().reduced (10);
  334. envelopes.setBounds (area.removeFromTop (ModEnvelopeEditor::preferredHeight));
  335. area.removeFromTop (16);
  336. lfos.setBounds (area.removeFromTop (LfoEditor::preferredHeight));
  337. }
  338. int getChannel() const noexcept { return ref.index; }
  339. private:
  340. const ChannelDef* current() const
  341. {
  342. return ref.get (engine);
  343. }
  344. bool isSynth() const { return current() != nullptr && current()->instrument == InstrumentKind::synth; }
  345. void refresh()
  346. {
  347. const auto* c = current();
  348. if (c == nullptr)
  349. return;
  350. if (isSynth())
  351. {
  352. envelopes.show (c->synth.filterEnv, c->synth.pitchEnv);
  353. lfos.show (c->synth.lfo);
  354. }
  355. else
  356. {
  357. envelopes.show (c->sampler.filterEnv, c->sampler.pitchEnv);
  358. lfos.show (c->sampler.lfo);
  359. }
  360. // only its own window: as a tab of the channel's window it left that window titled "Modulation - ..." while the
  361. // Sampler page showed (issue #12)
  362. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>(); w != nullptr && w->getContentComponent() == this)
  363. w->setName (tr ("Modulation - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
  364. }
  365. void apply()
  366. {
  367. if (current() == nullptr)
  368. return;
  369. const auto filter = envelopes.filter(), pitch = envelopes.pitch();
  370. const auto lfo = lfos.read();
  371. const auto synth = isSynth();
  372. ref.edit (engine, [synth, filter, pitch, lfo] (ChannelDef& channelDef) {
  373. auto& ch = channelDef;
  374. if (synth)
  375. {
  376. ch.synth.filterEnv = filter;
  377. ch.synth.pitchEnv = pitch;
  378. ch.synth.lfo = lfo;
  379. }
  380. else
  381. {
  382. ch.sampler.filterEnv = filter;
  383. ch.sampler.pitchEnv = pitch;
  384. ch.sampler.lfo = lfo;
  385. }
  386. });
  387. }
  388. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  389. AudioEngine& engine;
  390. ChannelRef ref;
  391. ModEnvelopeEditor envelopes;
  392. LfoEditor lfos;
  393. };
  394. // A Sampler knob: right-click opens its automation menu instead of moving it (issue #12)
  395. class MenuSlider final : public juce::Slider
  396. {
  397. public:
  398. std::function<void()> onMenu;
  399. void mouseDown (const juce::MouseEvent& e) override
  400. {
  401. menuClick = e.mods.isPopupMenu() && onMenu != nullptr;
  402. if (menuClick)
  403. onMenu();
  404. else
  405. juce::Slider::mouseDown (e);
  406. }
  407. void mouseDrag (const juce::MouseEvent& e) override
  408. {
  409. if (! menuClick)
  410. juce::Slider::mouseDrag (e);
  411. }
  412. void mouseUp (const juce::MouseEvent& e) override
  413. {
  414. if (! menuClick)
  415. juce::Slider::mouseUp (e);
  416. menuClick = false;
  417. }
  418. private:
  419. bool menuClick = false;
  420. };
  421. // Physical-model channels (Sakura, Drumpad; REA_rodada28): knobs for the main raw FL parameters (0..1)
  422. class ModelPanel final : public juce::Component,
  423. public juce::DragAndDropTarget,
  424. public juce::FileDragAndDropTarget,
  425. private juce::Timer
  426. {
  427. public:
  428. ModelPanel (AudioEngine& e, ChannelRef c)
  429. : engine (e),
  430. ref (std::move (c))
  431. {
  432. static const ChannelDef none;
  433. const auto* found = ref.get (engine);
  434. const auto& def = found != nullptr ? *found : none;
  435. sakura = def.instrument == InstrumentKind::sakura;
  436. boobass = def.instrument == InstrumentKind::boobass;
  437. drumsynth = def.instrument == InstrumentKind::drumsynth;
  438. harmless = def.instrument == InstrumentKind::harmless;
  439. harmor = def.instrument == InstrumentKind::harmor;
  440. gms = def.instrument == InstrumentKind::gms;
  441. morphine = def.instrument == InstrumentKind::morphine;
  442. autogun = def.instrument == InstrumentKind::autogun;
  443. transistorBass = def.instrument == InstrumentKind::transistorbass;
  444. ogun = def.instrument == InstrumentKind::ogun || autogun; // Autogun: Ogun's parameter layout (REA_rodada57)
  445. miniSynth = def.instrument == InstrumentKind::minisynth;
  446. dx10 = def.instrument == InstrumentKind::dx10;
  447. kepler = def.instrument == InstrumentKind::kepler;
  448. keplerExo = def.instrument == InstrumentKind::keplerExo;
  449. poizone = def.instrument == InstrumentKind::poizone;
  450. fruitkick = def.instrument == InstrumentKind::fruitkick;
  451. bassdrum = def.instrument == InstrumentKind::bassdrum;
  452. toxic = def.instrument == InstrumentKind::toxic;
  453. threeOsc = def.instrument == InstrumentKind::threeosc;
  454. simSynth = def.instrument == InstrumentKind::simsynth;
  455. wasp = def.instrument == InstrumentKind::wasp;
  456. plucked = def.instrument == InstrumentKind::plucked;
  457. beepMap = def.instrument == InstrumentKind::beepmap;
  458. sawer = def.instrument == InstrumentKind::sawer;
  459. flKeys = def.instrument == InstrumentKind::flkeys;
  460. granulizer = def.instrument == InstrumentKind::granulizer;
  461. drumaxx = def.instrument == InstrumentKind::drumaxx;
  462. slayer = def.instrument == InstrumentKind::slayer;
  463. fruityDance = def.instrument == InstrumentKind::fruitydance;
  464. // round 168q: the engines that run FL's own files say so when this computer lacks them
  465. engineFilesMissing = ((kepler || keplerExo) && ! keplerDllUsable (def.samplePath))
  466. || (transistorBass && ! transistorBassDllUsable (def.samplePath))
  467. || (sawer && sawerReadTable (def.samplePath).empty());
  468. sytrus = def.instrument == InstrumentKind::sytrus;
  469. // DrumSynth Live: the patch on the key selected in FL's editor (raw FL values)
  470. if (drumsynth)
  471. {
  472. if (lynx::drumSynthEditorKeyIndex < (int) def.modelParams.size())
  473. editorKey = (int) def.modelParams[(std::size_t) lynx::drumSynthEditorKeyIndex];
  474. if (drumSynthKeyToSlot (editorKey) < 0)
  475. editorKey = 60;
  476. wavesFound = ! def.samplePath.empty();
  477. }
  478. const auto offset = drumsynth ? drumSynthPatchParams * drumSynthKeyToSlot (editorKey) : 0;
  479. static const std::pair<int, const char*> sakuraKnobs[] = {
  480. { 0, "Master" }, { 1, "Tune" }, { 2, "Attack" }, { 3, "Decay" }, { 4, "Sustain" }, { 5, "Release" },
  481. { 6, "Str1 decay" }, { 9, "Str1 damp" }, { 11, "Str2 decay" }, { 14, "Str2 damp" }, { 16, "Saturation" },
  482. { 17, "String mix" }, { 18, "Stereo sep" }, { 19, "Comb ratio" }, { 22, "Comb level" }, { 24, "Lo-cut" },
  483. { 29, "Hi-cut" }, { 30, "Hi-cut res" }, { 31, "Noise level" }, { 32, "Noise rate" } };
  484. static const std::pair<int, const char*> drumpadKnobs[] = {
  485. { 2, "Mallet amp" }, { 3, "Mallet decay" }, { 4, "Mallet noise" }, { 6, "Decay" }, { 7, "Cutoff" },
  486. { 8, "Tension" }, { 9, "Phase" }, { 10, "Material" }, { 11, "Size" }, { 12, "Shape" }, { 13, "Low freq" },
  487. { 18, "Mid freq" }, { 19, "Mid level" }, { 24, "High freq" }, { 25, "High level" }, { 27, "Lo-fi" },
  488. { 28, "Hold" }, { 29, "Pitch" } };
  489. auto add = [&] (int index, const char* name, double low = 0.0, double high = -1.0) {
  490. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  491. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  492. index += offset;
  493. if (high > low)
  494. knob->setRange (low, high, 1.0);
  495. else
  496. knob->setRange (0.0, boobass ? 65535.0 : 1.0, boobass ? 1.0 : 0.001);
  497. knob->setValue (index < (int) def.modelParams.size() ? def.modelParams[(std::size_t) index] : 0.0, juce::dontSendNotification);
  498. knob->setName (name);
  499. knob->onValueChange = [this, index, k = knob.get()] {
  500. ref.edit (engine, [index, v = (float) k->getValue()] (ChannelDef& channelDef) {
  501. auto& params = channelDef.modelParams;
  502. if (index < (int) params.size())
  503. params[(std::size_t) index] = v;
  504. });
  505. };
  506. addAndMakeVisible (*knob);
  507. knobs.push_back (std::move (knob));
  508. };
  509. static const std::pair<int, const char*> booBassKnobs[] = { { 0, "Bass" }, { 1, "Mid" }, { 2, "Treble" } };
  510. struct Ranged { int index; const char* name; double low, high; };
  511. static const Ranged drumSynthKnobs[] = {
  512. { 0, "Level", 0, 128 }, { 1, "Pan", -64, 64 }, { 2, "Tone", -50, 50 }, { 3, "Harmonics", -50, 50 },
  513. { 4, "Osc1 freq", 0, 1000 }, { 7, "Osc1 decay", 0, 127 }, { 8, "Osc1 level", 0, 127 }, { 10, "Osc2 freq", 0, 1000 },
  514. { 13, "Osc2 decay", 0, 127 }, { 14, "Osc2 level", 0, 127 }, { 17, "Wave mix", 0, 127 }, { 21, "Release", 0, 127 },
  515. { 23, "Click", 0, 100 }, { 33, "Ring mod", 0, 127 } };
  516. // Harmless: raw FL values (REA_rodada21/32 ranges)
  517. static const Ranged harmlessKnobs[] = {
  518. { 36, "Volume", 0, 2000 }, { 26, "Attack", 0, 1000 }, { 27, "Decay", 0, 1000 }, { 28, "Release", 0, 1000 },
  519. { 54, "Cutoff", 0, 8192 }, { 59, "Resonance", 0, 1000 }, { 52, "Filter env", -1000, 1000 },
  520. { 31, "Pluck", 0, 1000 }, { 23, "Mask mix", 0, 1000 }, { 65, "Unison", 1, 9 }, { 67, "Uni detune", 0, 256 },
  521. { 25, "Tremolo", 0, 1000 }, { 71, "Phaser mix", 0, 1000 }, { 79, "Harmonizer", 0, 1000 } };
  522. // Harmor: raw FL integers inside the saved state (part A, and the global master / A–B mix; REA_rodada34)
  523. struct HarmorKnob { int part, index; const char* name; double low, high; };
  524. static const HarmorKnob harmorKnobs[] = {
  525. { -1, 12, "Master vol", 0, 2000 }, { -1, 10, "A/B mix", 0, 1000 }, { 0, 11, "A volume", -1000, 1000 },
  526. { 0, 4, "Timbre mix", 0, 1000 }, { 0, 52, "Cutoff", 0, 8192 }, { 0, 57, "Resonance", 0, 1000 },
  527. { 0, 75, "Pluck", 0, 1000 }, { 0, 34, "Unison", 1, 9 }, { 0, 38, "Uni detune", 0, 256 },
  528. { 0, 27, "Harmonizer", 0, 1000 }, { 0, 76, "Phaser mix", 0, 1000 }, { 0, 23, "Harm. blur", 0, 10000 },
  529. { 0, 45, "Vibrato", 0, 1000 }, { 0, 17, "Tremolo", 0, 1000 } };
  530. auto addHarmor = [&] (const HarmorKnob& k) {
  531. const auto at = harmorParamOffset (def.pluginState, k.part, k.index);
  532. if (at < 0)
  533. return;
  534. std::int32_t value = 0;
  535. std::memcpy (&value, def.pluginState.data() + at, 4);
  536. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  537. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  538. knob->setRange (k.low, k.high, 1.0);
  539. knob->setValue (value, juce::dontSendNotification);
  540. knob->setName (k.name);
  541. knob->onValueChange = [this, k, s = knob.get()] {
  542. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  543. auto& st = channelDef.pluginState;
  544. if (const auto o = harmorParamOffset (st, k.part, k.index); o >= 0)
  545. std::memcpy (st.data() + o, &v, 4);
  546. });
  547. };
  548. addAndMakeVisible (*knob);
  549. knobs.push_back (std::move (knob));
  550. };
  551. // GMS / Morphine: the plugin's own 0…1 floats inside the saved state (GMS P[i], Morphine global A[i]; REA_rodada39)
  552. struct FloatKnob { int index; const char* name; };
  553. static const FloatKnob gmsKnobs[] = {
  554. { 0, "Master" }, { 1, "Pan" }, { 8, "Level" }, { 4, "Attack" }, { 5, "Decay" }, { 6, "Sustain" }, { 7, "Release" },
  555. { 12, "Cutoff" }, { 13, "Resonance" }, { 16, "Env1 amount" }, { 50, "Modulation" }, { 48, "Osc2 mix" }, { 49, "Osc3 mix" },
  556. { 45, "Noise" }, { 41, "Unison" }, { 42, "Uni detune" }, { 43, "Stereo" }, { 10, "Slide time" } };
  557. static const FloatKnob morphineKnobs[] = {
  558. { 0, "Master" }, { 9, "Attack" }, { 10, "Decay" }, { 11, "Sustain" }, { 12, "Release" }, { 1, "Glide" }, { 4, "Vel curve" },
  559. { 7, "Overdrive" }, { 14, "Chorus mix" }, { 21, "Delay mix" }, { 25, "Reverb mix" }, { 36, "Noise mix" } };
  560. // BassDrum: its 23 floats 0…1 inside the saved state (REA_rodada15 §12.3 / rodada43 §2.2)
  561. static const FloatKnob bassDrumKnobs[] = {
  562. { 0, "Output" }, { 6, "Base" }, { 7, "Peak" }, { 8, "Slide" }, { 2, "Duration" }, { 5, "Attack" }, { 4, "Drive" },
  563. { 3, "Butt" }, { 15, "Click level" }, { 14, "Click freq" }, { 13, "Click cut" }, { 21, "Noise mix" }, { 22, "Noise filter" },
  564. { 20, "Noise pitch" }, { 19, "Noise start" }, { 1, "Sampling" } };
  565. // MiniSynth: its 43 floats 0…1 inside the saved state (REA_rodada41 §1.2)
  566. static const FloatKnob miniSynthKnobs[] = {
  567. { 5, "Osc kind" }, { 6, "Osc mod" }, { 7, "Noise" }, { 1, "Transpose" }, { 8, "Cutoff" }, { 9, "Resonance" },
  568. { 16, "Filter env" }, { 21, "Attack" }, { 22, "Decay" }, { 23, "Sustain" }, { 24, "Release" }, { 20, "LFO amount" },
  569. { 19, "LFO rate" }, { 2, "Slide time" } };
  570. auto paramOffset = [this] (const std::vector<std::uint8_t>& st, int index) {
  571. return gms ? gmsParamOffset (st, index)
  572. : miniSynth ? miniSynthParamOffset (st, index)
  573. : poizone ? poizoneParamOffset (st, index)
  574. : bassdrum ? bassDrumParamOffset (st, index)
  575. : toxic ? toxicParamOffset (st, index) : morphineParamOffset (st, index);
  576. };
  577. auto addFloat = [&] (const FloatKnob& k) {
  578. const auto at = paramOffset (def.pluginState, k.index);
  579. if (at < 0)
  580. return;
  581. float value = 0.0f;
  582. std::memcpy (&value, def.pluginState.data() + at, 4);
  583. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  584. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  585. knob->setRange (0.0, 1.0, 0.001);
  586. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  587. knob->setName (k.name);
  588. knob->onValueChange = [this, k, paramOffset, s = knob.get()] {
  589. ref.edit (engine, [k, paramOffset, v = (float) s->getValue()] (ChannelDef& channelDef) {
  590. auto& st = channelDef.pluginState;
  591. if (const auto o = paramOffset (st, k.index); o >= 0)
  592. std::memcpy (st.data() + o, &v, 4);
  593. });
  594. };
  595. addAndMakeVisible (*knob);
  596. knobs.push_back (std::move (knob));
  597. };
  598. // SimSynth: its 45 doubles 0…1 at the start of the saved state (REA_rodada64 §1.1)
  599. static const FloatKnob simSynthKnobs[] = {
  600. { 3, "Osc 1 level" }, { 10, "Osc 2 level" }, { 17, "Osc 3 level" }, { 26, "Cutoff" }, { 27, "Resonance" },
  601. { 28, "Filter env" }, { 30, "Key track" }, { 35, "Attack" }, { 36, "Decay" }, { 37, "Sustain" }, { 38, "Release" },
  602. { 22, "LFO rate" }, { 29, "LFO cutoff" }, { 39, "Volume" } };
  603. auto addDouble = [&] (const FloatKnob& k) {
  604. const auto at = 8 * (std::size_t) k.index;
  605. if (! simSynthStateUsable (def.pluginState))
  606. return;
  607. double value = 0.0;
  608. std::memcpy (&value, def.pluginState.data() + at, 8);
  609. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  610. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  611. knob->setRange (0.0, 1.0, 0.001);
  612. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0, 1.0) : 0.0, juce::dontSendNotification);
  613. knob->setName (k.name);
  614. knob->onValueChange = [this, at, s = knob.get()] {
  615. ref.edit (engine, [at, v = s->getValue()] (ChannelDef& channelDef) {
  616. auto& st = channelDef.pluginState;
  617. if (simSynthStateUsable (st))
  618. std::memcpy (st.data() + at, &v, 8);
  619. });
  620. };
  621. addAndMakeVisible (*knob);
  622. knobs.push_back (std::move (knob));
  623. };
  624. // FL Slayer: the 28 parameter integers of the saved state (REA_rodada68 §6.1), ranges of the plugin's controls
  625. static const Ranged slayerKnobs[] = {
  626. { 0, "Strings", 0, 6 }, { 1, "Coils", 0, 2 }, { 2, "Pickup", 0, 65535 }, { 3, "Tone", 0, 65535 }, { 4, "Slap", 0, 65535 },
  627. { 5, "Fret", 0, 65535 }, { 6, "Harmonic", 0, 65535 }, { 7, "Damp", 0, 65535 }, { 8, "Vel volume", 0, 65535 },
  628. { 9, "Vel damp", 0, 65535 }, { 12, "Amp type", 0, 3 }, { 13, "Drive", 0, 65535 }, { 14, "Presence", 0, 65535 },
  629. { 15, "Feedback", 0, 65535 }, { 16, "EQ low", 0, 65535 }, { 17, "EQ mid", 0, 65535 }, { 18, "EQ high", 0, 65535 },
  630. { 19, "Cabinet", 0, 3 }, { 20, "Effect", 0, 15 }, { 21, "FX par 1", 0, 65535 }, { 22, "FX par 2", 0, 65535 },
  631. { 24, "Mode", 0, 5 }, { 25, "Timing", 0, 65535 }, { 26, "Latch", 0, 1 }, { 27, "Glissando", 0, 1 } };
  632. auto addSlayer = [&] (const Ranged& k) {
  633. const auto at = 4 + 4 * (std::size_t) k.index;
  634. if (! slayerStateUsable (def.pluginState) || at + 4 > def.pluginState.size())
  635. return;
  636. std::int32_t value = 0;
  637. std::memcpy (&value, def.pluginState.data() + at, 4);
  638. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  639. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  640. knob->setRange ((double) k.low, (double) k.high, 1.0);
  641. knob->setValue ((double) std::clamp ((int) value, (int) k.low, (int) k.high), juce::dontSendNotification);
  642. knob->setName (k.name);
  643. knob->onValueChange = [this, at, s = knob.get()] {
  644. ref.edit (engine, [at, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  645. auto& st = channelDef.pluginState;
  646. if (slayerStateUsable (st) && at + 4 <= st.size())
  647. std::memcpy (st.data() + at, &v, 4);
  648. });
  649. };
  650. addAndMakeVisible (*knob);
  651. knobs.push_back (std::move (knob));
  652. };
  653. // Sytrus: its "Main settings" page, raw FL integers inside the saved (zlib) state (REA_rodada74 §3)
  654. auto addSytrus = [&] (int setting) {
  655. const auto value = sytrus::settingValue (def.pluginState, setting);
  656. if (! value)
  657. return;
  658. const auto& d = sytrus::settings()[(std::size_t) setting];
  659. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  660. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  661. knob->setRange (d.low, d.high, 1.0);
  662. knob->setValue (std::clamp (*value, d.low, d.high), juce::dontSendNotification);
  663. knob->setName (d.name);
  664. knob->onValueChange = [this, setting, s = knob.get()] {
  665. ref.edit (engine, [setting, v = (int) s->getValue()] (ChannelDef& channelDef) {
  666. sytrus::setSetting (channelDef.pluginState, setting, v);
  667. });
  668. };
  669. addAndMakeVisible (*knob);
  670. knobs.push_back (std::move (knob));
  671. };
  672. // Ogun: raw FL integers P0…P63 inside the saved (zlib) state (REA_rodada37 §1.3)
  673. static const Ranged ogunKnobs[] = {
  674. { 0, "Master vol", 0, 256 }, { 5, "Pre-decay", 0, 1000 }, { 6, "Decay", 0, 10000 }, { 7, "Release", 0, 10000 },
  675. { 8, "Fullness", -1000, 1000 }, { 9, "Morph", 0, 1000 }, { 10, "Seed 1", 0, 1000 }, { 11, "Seed 2", 0, 1000 },
  676. { 52, "Richness", 6, 16 }, { 12, "Unison", 1, 9 }, { 15, "Uni pitch", 0, 256 }, { 17, "Cutoff", 0, 256 },
  677. { 18, "Resonance", 0, 256 }, { 3, "Mod X", 0, 512 }, { 4, "Mod Y", 0, 512 }, { 54, "Quality", 0, 4 } };
  678. static const Ranged autogunKnobs[] = { { 63, "Magic dust", 0, 1000 } };
  679. auto addOgun = [&] (const Ranged& k) {
  680. const auto value = ogunParam (def.pluginState, k.index);
  681. if (! value)
  682. return;
  683. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  684. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  685. knob->setRange (k.low, k.high, 1.0);
  686. knob->setValue (*value, juce::dontSendNotification);
  687. knob->setName (k.name);
  688. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  689. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  690. ogunSetParam (channelDef.pluginState, index, v);
  691. });
  692. };
  693. addAndMakeVisible (*knob);
  694. knobs.push_back (std::move (knob));
  695. };
  696. // Fruit Kick: its six integers (REA_rodada10 §4.2 ranges)
  697. static const Ranged fruitKickKnobs[] = {
  698. { 0, "Max freq", -2400, 3600 }, { 1, "Min freq", -1200, 1200 }, { 2, "Freq decay", 0, 256 }, { 3, "Amp decay", 0, 256 },
  699. { 4, "Click", 0, 64 }, { 5, "Distortion", 0, 128 } };
  700. auto addFruitKick = [&] (const Ranged& k) {
  701. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  702. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  703. knob->setRange (k.low, k.high, 1.0);
  704. knob->setValue (fruitKickParam (def.pluginState, k.index), juce::dontSendNotification);
  705. knob->setName (k.name);
  706. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  707. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  708. fruitKickSetParam (channelDef.pluginState, index, v);
  709. });
  710. };
  711. addAndMakeVisible (*knob);
  712. knobs.push_back (std::move (knob));
  713. };
  714. // Fruity DX10: the 22 raw FL integers of the saved state (REA_rodada42 §1.2)
  715. static const Ranged dx10Knobs[] = {
  716. { 0, "Attack", 0, 65536 }, { 1, "Decay", 0, 65536 }, { 2, "Release", 0, 65536 }, { 21, "Coarse", -3, 3 },
  717. { 11, "Waveform", 0, 65536 }, { 10, "Vibrato", 0, 65536 }, { 13, "LFO rate", 0, 65536 },
  718. { 3, "Mod 1 coarse", 0, 65536 }, { 4, "Mod 1 fine", 0, 65536 }, { 5, "Mod 1 init", 0, 65536 }, { 6, "Mod 1 time", 0, 65536 },
  719. { 7, "Mod 1 sustain", 0, 65536 }, { 8, "Mod 1 release", 0, 65536 }, { 9, "Mod 1 velocity", 0, 65536 },
  720. { 14, "Mod 2 coarse", 0, 65536 }, { 15, "Mod 2 fine", 0, 65536 }, { 16, "Mod 2 init", 0, 65536 }, { 17, "Mod 2 time", 0, 65536 },
  721. { 18, "Mod 2 sustain", 0, 65536 }, { 19, "Mod 2 release", 0, 65536 }, { 20, "Mod 2 velocity", 0, 65536 }, { 12, "Mod thru", 0, 65536 } };
  722. auto addDx10 = [&] (const Ranged& k) {
  723. const auto value = dx10Param (def.pluginState, k.index);
  724. if (! value)
  725. return;
  726. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  727. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  728. knob->setRange (k.low, k.high, 1.0);
  729. knob->setValue (*value, juce::dontSendNotification);
  730. knob->setName (k.name);
  731. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  732. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  733. dx10SetParam (channelDef.pluginState, index, v);
  734. });
  735. };
  736. addAndMakeVisible (*knob);
  737. knobs.push_back (std::move (knob));
  738. };
  739. // 3x Osc: the 21 parameters of the saved state, then invert ×3, AM and HQ (REA_rodada47 §1.1)
  740. static const char* const threeOscNames[] = {
  741. "Osc 1 pan", "Osc 1 shape", "Osc 1 coarse", "Osc 1 fine", "Osc 1 phase", "Osc 1 detune", "Osc 2 mix", "Osc 2 pan",
  742. "Osc 2 shape", "Osc 2 coarse", "Osc 2 fine", "Osc 2 phase", "Osc 2 detune", "Osc 3 mix", "Osc 3 pan", "Osc 3 shape",
  743. "Osc 3 coarse", "Osc 3 fine", "Osc 3 phase", "Osc 3 detune", "Phase rand", "Invert 1", "Invert 2", "Invert 3",
  744. "Osc 3 AM", "HQ" };
  745. auto addThreeOsc = [&] (int index) {
  746. const auto value = threeOscParam (def.pluginState, index);
  747. if (! value)
  748. return;
  749. const auto [low, high] = threeOscParamRange (index);
  750. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  751. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  752. knob->setRange (low, high, 1.0);
  753. knob->setValue (*value, juce::dontSendNotification);
  754. knob->setName (threeOscNames[index]);
  755. knob->onValueChange = [this, index, s = knob.get()] {
  756. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  757. threeOscSetParam (channelDef.pluginState, index, v);
  758. });
  759. };
  760. addAndMakeVisible (*knob);
  761. knobs.push_back (std::move (knob));
  762. };
  763. // Fruity Granulizer: the 12 parameters of the saved state (REA_rodada67 §1)
  764. static const char* const granulizerNames[] = {
  765. "Grain attack", "Grain hold", "Grain spacing", "Wave spacing", "Effect depth", "Effect speed", "Randomness",
  766. "Stereo", "Loop", "Freeze", "Sample start", "Transient hold" };
  767. auto addGranulizer = [&] (int index) {
  768. const auto value = granulizerParam (def.pluginState, index);
  769. if (! value)
  770. return;
  771. const auto [low, high] = granulizerParamRange (index);
  772. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  773. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  774. knob->setRange (low, high, 1.0);
  775. knob->setValue (*value, juce::dontSendNotification);
  776. knob->setName (granulizerNames[index]);
  777. knob->onValueChange = [this, index, s = knob.get()] {
  778. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  779. granulizerSetParam (channelDef.pluginState, index, v);
  780. });
  781. };
  782. addAndMakeVisible (*knob);
  783. knobs.push_back (std::move (knob));
  784. };
  785. // Drumaxx: the master level and the 16 pad volumes, 0…1 floats of the saved state (REA_rodada67 §6)
  786. auto addDrumaxx = [&] (int index, const juce::String& name) {
  787. const auto value = drumaxxParam (def.pluginState, index);
  788. if (! std::isfinite (value))
  789. return;
  790. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  791. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  792. knob->setRange (0.0, 1.0, 0.001);
  793. knob->setValue (std::clamp ((double) value, 0.0, 1.0), juce::dontSendNotification);
  794. knob->setName (name);
  795. knob->onValueChange = [this, index, s = knob.get()] {
  796. ref.edit (engine, [index, v = (float) s->getValue()] (ChannelDef& channelDef) {
  797. drumaxxSetParam (channelDef.pluginState, index, v);
  798. });
  799. };
  800. addAndMakeVisible (*knob);
  801. knobs.push_back (std::move (knob));
  802. };
  803. // Kepler: the panel's 0…1 floats inside the saved state ("Kepler-1" order, REA_rodada46 §1.1)
  804. static const FloatKnob keplerKnobs[] = {
  805. { 33, "Volume" }, { 19, "Cutoff" }, { 20, "Resonance" }, { 22, "Env amount" }, { 26, "Attack" }, { 27, "Decay" },
  806. { 28, "Sustain" }, { 29, "Release" }, { 11, "PW" }, { 16, "Sub level" }, { 17, "Noise" }, { 5, "LFO rate" },
  807. { 10, "Vibrato" }, { 18, "High-pass" }, { 30, "Chorus" } };
  808. // Kepler Exo: the same layout with the "Kepler-2" parameter list (REA_rodada167d §1)
  809. static const FloatKnob keplerExoKnobs[] = {
  810. { 0x48, "Volume" }, { 0x25, "Cutoff" }, { 0x26, "Resonance" }, { 0x2c, "Env amount" }, { 0x3d, "Attack" },
  811. { 0x3e, "Decay" }, { 0x3f, "Sustain" }, { 0x40, "Release" }, { 0x21, "DCO2 level" }, { 0x0e, "DCO2 detune" },
  812. { 0x30, "LFO1 rate" }, { 0x36, "LFO2 rate" }, { 0x50, "Portamento" }, { 0x24, "High-pass" }, { 0x87, "Saturation" },
  813. { 0x70, "Delay amount" }, { 0x73, "Delay feedback" }, { 0x80, "Reverb decay" }, { 0x85, "Reverb wet" },
  814. { 0x93, "Hyper chorus mix" } };
  815. auto addKepler = [&] (const FloatKnob& k) {
  816. const auto at = keplerPanelOffset (def.pluginState, k.index);
  817. if (at < 0)
  818. return;
  819. float value = 0.0f;
  820. std::memcpy (&value, def.pluginState.data() + at, 4);
  821. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  822. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  823. knob->setRange (0.0, 1.0, 0.001);
  824. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  825. knob->setName (k.name);
  826. knob->onValueChange = [this, k, s = knob.get()] {
  827. ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
  828. auto& st = channelDef.pluginState;
  829. if (const auto o = keplerPanelOffset (st, k.index); o >= 0)
  830. std::memcpy (st.data() + o, &v, 4);
  831. });
  832. };
  833. addAndMakeVisible (*knob);
  834. knobs.push_back (std::move (knob));
  835. };
  836. // Plucked!: the five int32 knobs of the saved state (REA_rodada65 §1.1)
  837. static const Ranged pluckedKnobs[] = { { 0, "Decay", 0, 256 }, { 1, "Color", 0, 128 }, { 2, "Normalize", 0, 1 },
  838. { 3, "Gate", 0, 1 }, { 4, "Widen", 0, 1 } };
  839. auto addPlucked = [&] (const Ranged& k) {
  840. if (def.pluginState.size() < 20)
  841. return;
  842. std::int32_t value = 0;
  843. std::memcpy (&value, def.pluginState.data() + 4 * k.index, 4);
  844. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  845. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  846. knob->setRange (k.low, k.high, 1.0);
  847. knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
  848. knob->setName (k.name);
  849. knob->onValueChange = [this, k, s = knob.get()] {
  850. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  851. auto& st = channelDef.pluginState;
  852. if (st.size() >= 20)
  853. std::memcpy (st.data() + 4 * k.index, &v, 4);
  854. });
  855. };
  856. addAndMakeVisible (*knob);
  857. knobs.push_back (std::move (knob));
  858. };
  859. // BeepMap: the int32 settings of the saved state (REA_rodada65 §2.1; Frequency's range not confirmed)
  860. static const Ranged beepMapKnobs[] = { { 0, "Frequency", 0, 9600 }, { 1, "Length", 0, 4096 }, { 2, "Scale", 0, 2 },
  861. { 3, "Use blue", 0, 1 }, { 4, "Grainy", 0, 1 }, { 5, "Loop", 0, 1 }, { 6, "Widen", 0, 1 } };
  862. auto addBeepMap = [&] (const Ranged& k) {
  863. const auto at = beepMapParamOffset (def.pluginState, k.index);
  864. if (at < 0)
  865. return;
  866. std::int32_t value = 0;
  867. std::memcpy (&value, def.pluginState.data() + at, 4);
  868. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  869. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  870. knob->setRange (k.low, k.high, 1.0);
  871. knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
  872. knob->setName (k.name);
  873. knob->onValueChange = [this, k, s = knob.get()] {
  874. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  875. auto& st = channelDef.pluginState;
  876. if (const auto o = beepMapParamOffset (st, k.index); o >= 0)
  877. std::memcpy (st.data() + o, &v, 4);
  878. });
  879. };
  880. addAndMakeVisible (*knob);
  881. knobs.push_back (std::move (knob));
  882. };
  883. // Sawer: 0…1 floats of the saved state (REA_rodada65 §3.3)
  884. static const FloatKnob sawerKnobs[] = {
  885. { 0, "Level" }, { 27, "Cutoff" }, { 28, "Resonance" }, { 36, "EGF amount" }, { 2, "Attack" }, { 3, "Decay" },
  886. { 4, "Sustain" }, { 5, "Release" }, { 19, "Sub level" }, { 18, "Sub harmonic" }, { 26, "Noise" }, { 14, "Unison" },
  887. { 15, "Uni detune" }, { 45, "LFO amount" } };
  888. auto addSawer = [&] (const FloatKnob& k) {
  889. const auto at = sawerParamOffset (def.pluginState, k.index);
  890. if (at < 0)
  891. return;
  892. float value = 0.0f;
  893. std::memcpy (&value, def.pluginState.data() + at, 4);
  894. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  895. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  896. knob->setRange (0.0, 1.0, 0.001);
  897. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  898. knob->setName (k.name);
  899. knob->onValueChange = [this, k, s = knob.get()] {
  900. ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
  901. auto& st = channelDef.pluginState;
  902. if (const auto o = sawerParamOffset (st, k.index); o >= 0)
  903. std::memcpy (st.data() + o, &v, 4);
  904. });
  905. };
  906. addAndMakeVisible (*knob);
  907. knobs.push_back (std::move (knob));
  908. };
  909. // FL Keys: the 15 int32 knobs of the saved state (REA_rodada69 §8.1)
  910. auto addFlKeys = [&] (int index) {
  911. const auto state = flkeys::parseState (def.pluginState);
  912. if (! state)
  913. return;
  914. const auto& r = flkeys::knobRange[index];
  915. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  916. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  917. knob->setRange (r.min, r.max, 1.0);
  918. knob->setValue (std::clamp ((double) state->knobs[(std::size_t) index], (double) r.min, (double) r.max), juce::dontSendNotification);
  919. knob->setName (r.name);
  920. knob->onValueChange = [this, index, s = knob.get()] {
  921. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  922. auto& st = channelDef.pluginState;
  923. if (auto parsed = flkeys::parseState (st))
  924. {
  925. parsed->knobs[(std::size_t) index] = v;
  926. st = flkeys::writeState (*parsed);
  927. }
  928. });
  929. };
  930. addAndMakeVisible (*knob);
  931. knobs.push_back (std::move (knob));
  932. };
  933. // an engine whose parameters are listed (core/ModelParams.h, round 168n): one knob per parameter, automatable
  934. // (right-click: FL's parameter menu; a move is a tweak)
  935. instrumentKind = def.instrument;
  936. modelTable = modelparams::tableOf (def.instrument);
  937. if (modelTable != nullptr && ! modelparams::rawValue (def, modelTable->params->front().index))
  938. modelTable = nullptr; // (a state the engine can't read: the plain page)
  939. if (modelTable != nullptr && (drumaxx || drumsynth))
  940. {
  941. // round 168p: Drumaxx's pad voice / DrumSynth Live's patch: one knob per control, editing the selected
  942. // pad's / key's parameter (the pad buttons / the key display pick the part); the rest as listed
  943. drumPart = drumsynth ? editorKey : drumaxxPadOf (ref.index);
  944. for (const auto& c : drumcontrols::controls (def.instrument))
  945. if (c.perPart)
  946. addPartParam (def, c);
  947. else if (const auto* p = modelparams::find (def.instrument, c.index))
  948. addModelParam (def, *p);
  949. }
  950. else if (modelTable != nullptr)
  951. {
  952. for (const auto& p : *modelTable->params)
  953. addModelParam (def, p);
  954. // Toxic Biohazard without the user's DLL: the drawn wave (0) and the sine (1) only — the built-in waves
  955. // 2…32 are FL's files
  956. if (toxic && ! toxicDllUsable (def.samplePath))
  957. for (auto& k : knobs)
  958. if (k->getName().endsWith (" wave"))
  959. k->setRange (0.0, 1.0, 1.0);
  960. }
  961. else if (flKeys)
  962. for (int i = 0; i < 15; ++i)
  963. addFlKeys (i);
  964. else if (plucked)
  965. for (const auto& k : pluckedKnobs)
  966. addPlucked (k);
  967. else if (beepMap)
  968. for (const auto& k : beepMapKnobs)
  969. addBeepMap (k);
  970. else if (sawer)
  971. for (const auto& k : sawerKnobs)
  972. addSawer (k);
  973. else if (threeOsc)
  974. for (int i = 0; i < threeOscParamCount(); ++i)
  975. addThreeOsc (i);
  976. else if (granulizer)
  977. {
  978. for (int i = 0; i < granulizerParamCount(); ++i)
  979. addGranulizer (i);
  980. setupGranulizerModes (def);
  981. }
  982. else if (drumaxx)
  983. {
  984. addDrumaxx (0x2c1, "Master");
  985. for (int pad = 0; pad < 16; ++pad)
  986. addDrumaxx (pad * 44, "Pad " + juce::String (pad + 1));
  987. }
  988. else if (dx10)
  989. for (const auto& k : dx10Knobs)
  990. addDx10 (k);
  991. else if (kepler)
  992. for (const auto& k : keplerKnobs)
  993. addKepler (k);
  994. else if (keplerExo)
  995. for (const auto& k : keplerExoKnobs)
  996. addKepler (k);
  997. else if (gms)
  998. for (const auto& k : gmsKnobs)
  999. addFloat (k);
  1000. else if (bassdrum)
  1001. for (const auto& k : bassDrumKnobs)
  1002. addFloat (k);
  1003. else if (fruitkick)
  1004. for (const auto& k : fruitKickKnobs)
  1005. addFruitKick (k);
  1006. else if (morphine)
  1007. for (const auto& k : morphineKnobs)
  1008. addFloat (k);
  1009. else if (miniSynth)
  1010. for (const auto& k : miniSynthKnobs)
  1011. addFloat (k);
  1012. else if (simSynth)
  1013. for (const auto& k : simSynthKnobs)
  1014. addDouble (k);
  1015. else if (wasp || fruityDance)
  1016. ;
  1017. else if (slayer)
  1018. for (const auto& k : slayerKnobs)
  1019. addSlayer (k);
  1020. else if (sytrus)
  1021. for (int i = 0; i < (int) sytrus::settings().size(); ++i)
  1022. addSytrus (i);
  1023. else if (ogun)
  1024. {
  1025. for (const auto& k : ogunKnobs)
  1026. addOgun (k);
  1027. if (autogun)
  1028. for (const auto& k : autogunKnobs)
  1029. addOgun (k);
  1030. }
  1031. else if (harmor)
  1032. for (const auto& k : harmorKnobs)
  1033. addHarmor (k);
  1034. else if (harmless)
  1035. for (const auto& k : harmlessKnobs)
  1036. add (k.index, k.name, k.low, k.high);
  1037. else if (drumsynth)
  1038. for (const auto& k : drumSynthKnobs)
  1039. add (k.index, k.name, k.low, k.high);
  1040. else if (boobass)
  1041. for (const auto& [index, name] : booBassKnobs)
  1042. add (index, name);
  1043. else if (sakura)
  1044. for (const auto& [index, name] : sakuraKnobs)
  1045. add (index, name);
  1046. else
  1047. for (const auto& [index, name] : drumpadKnobs)
  1048. add (index, name);
  1049. const auto rows = ((int) knobs.size() + 6) / 7; // the grid of resized()
  1050. setSize (720, std::max (dx10 || threeOsc ? 500 : 384, 46 + rows * 110 + 8 + (granulizerModes ? 64 : 0)));
  1051. // a Granulizer node inside a Patcher (round 165c): no channel to drop a sample on, so its own Sample button
  1052. if (granulizer && ref.index < 0)
  1053. {
  1054. sampleButton.setButtonText (tr ("Sample..."));
  1055. const auto path = juce::String::fromUTF8 (def.samplePath.c_str());
  1056. ui::setHint (sampleButton, path.isEmpty() ? tr ("Choose the sample the Granulizer plays") : path);
  1057. sampleButton.onClick = [this] {
  1058. juce::StringArray patterns;
  1059. for (const auto e : sampleFileExtensions)
  1060. patterns.add ("*." + juce::String (std::string (e)));
  1061. chooser = std::make_unique<juce::FileChooser> (tr ("Sample"), juce::File(), patterns.joinIntoString (";"));
  1062. chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  1063. [safe = juce::Component::SafePointer<ModelPanel> (this)] (const juce::FileChooser& fc) {
  1064. if (safe == nullptr || fc.getResult() == juce::File())
  1065. return;
  1066. safe->loadGranulizerSample (fc.getResult());
  1067. });
  1068. };
  1069. addAndMakeVisible (sampleButton);
  1070. resized(); // (setSize above laid the page out before the button existed)
  1071. }
  1072. // FL's arrangement of the plugin's page (core/PluginLayout.cpp): the knobs at FL's places, faders and
  1073. // switches drawn by the panel
  1074. layout = plugui::instrumentLayout (def.instrument);
  1075. // a state the engine cannot read gives no knobs: keep the plain page then
  1076. if (layout != nullptr && ! wasp && std::none_of (knobs.begin(), knobs.end(), [this] (const auto& k) { return itemFor (k->getName()) != nullptr; }))
  1077. layout = nullptr;
  1078. if (layout != nullptr)
  1079. {
  1080. accent = flKeys ? skin::colour::azure : boobass || transistorBass ? skin::colour::ember : harmor || sytrus ? skin::colour::violet
  1081. : skin::colour::crimson;
  1082. // round 126: the page's own style (FL Keys hardware, BooBass vivid, the synths neon); round 170j: a plugin
  1083. // with its own art (Sakura, Toxic Biohazard, Sytrus, 3x Osc) is Themed
  1084. pageStyle = flKeys ? skin::Style::hardware : boobass || transistorBass ? skin::Style::vivid : skin::Style::neon;
  1085. pageArt = skin::artForInstrument (def.instrument);
  1086. if (pageArt != skin::Art::none)
  1087. {
  1088. pageStyle = skin::Style::themed;
  1089. artLayer = std::make_unique<skin::ArtLayer>();
  1090. addAndMakeVisible (*artLayer);
  1091. artLayer->setArt (pageArt, [this] { return themedNow(); });
  1092. }
  1093. for (auto& k : knobs)
  1094. {
  1095. k->getProperties().set (skin::sliderProperty, (juce::int64) accent.getARGB());
  1096. k->getProperties().set (skin::styleProperty, skin::packStyle (pageStyle, pageArt));
  1097. const auto* item = itemFor (k->getName());
  1098. if (item == nullptr || (item->type != plugui::Item::knob && item->type != plugui::Item::vslider && item->type != plugui::Item::hslider))
  1099. {
  1100. k->setVisible (false); // edited by a switch of the panel (or not shown by FL)
  1101. continue;
  1102. }
  1103. k->setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
  1104. if (item->type == plugui::Item::vslider)
  1105. k->setSliderStyle (juce::Slider::LinearVertical);
  1106. if (item->type == plugui::Item::hslider)
  1107. k->setSliderStyle (juce::Slider::LinearHorizontal);
  1108. k->setPopupDisplayEnabled (true, true, this);
  1109. k->setTooltip (k->getName());
  1110. }
  1111. updateConditional();
  1112. // FL's size × 1.25, at most about 1200 × 760 (big pages such as Harmor's fit a laptop screen)
  1113. const auto f = juce::jmin (layoutScale, 1200.0f / (float) layout->width, 720.0f / (float) layout->height);
  1114. setSize ((int) std::ceil (f * (float) layout->width) + 16, (int) std::ceil (f * (float) layout->height) + layoutTop + 8);
  1115. }
  1116. if (transistorBass && ref.index >= 0)
  1117. startTimerHz (10); // the page follows the program a note selects (round 169g2)
  1118. }
  1119. // Transistor Bass with its sequencer on: a note selects program = key (REA_rodada57 §2.10) and FL's editor shows
  1120. // that program, so its knobs edit what plays. The channel's state takes the playing program (not an undo step)
  1121. // and every knob reads it again (round 169g2)
  1122. void timerCallback() override
  1123. {
  1124. const auto* c = channelNow();
  1125. const auto instrument = engine.getChannelInstrument (ref.index);
  1126. if (c == nullptr || instrument == nullptr)
  1127. return;
  1128. const auto selected = instrument->selectedProgram();
  1129. const auto prog = transistorBassProgram (c->pluginState);
  1130. if (selected < 0 || ! prog || prog->program == selected)
  1131. return;
  1132. auto next = c->pluginState;
  1133. if (! transistorBassSelectProgram (next, selected))
  1134. return;
  1135. ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; }, false);
  1136. syncKnobs (true);
  1137. repaint();
  1138. }
  1139. // a knob of a listed engine parameter (round 168n): raw range of the state, automation target channelParam
  1140. void addModelParam (const ChannelDef& def, const EngineParam& p)
  1141. {
  1142. auto knob = std::make_unique<MenuSlider>();
  1143. knob->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  1144. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  1145. knob->setRange (p.low, p.high, p.stepped ? 1.0 : 0.0);
  1146. knob->setValue (modelparams::rawValue (def, p.index).value_or (p.low), juce::dontSendNotification);
  1147. knob->setDoubleClickReturnValue (false, 0.0);
  1148. knob->setName (juce::String::fromUTF8 (p.name.c_str()));
  1149. const auto index = p.index;
  1150. knob->onValueChange = [this, index, s = knob.get()] {
  1151. ref.edit (engine, [index, v = (float) s->getValue()] (ChannelDef& c) {
  1152. modelparams::setRawValue (c, index, v);
  1153. natives::followControl (c, index, flStudioAccess()); // (Harmless' compression type loads its preset)
  1154. });
  1155. if (instrumentKind == InstrumentKind::transistorbass && index >= tbseq::length) // (a step's note moves its octave)
  1156. syncKnobs();
  1157. if (layout != nullptr)
  1158. {
  1159. updateConditional();
  1160. repaint();
  1161. }
  1162. };
  1163. if (ref.index >= 0) // (a Patcher node: no automation target)
  1164. {
  1165. const auto target = [this, index] { return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, index }; };
  1166. ui::setOwnMenu (*knob);
  1167. knob->onMenu = [this, k = knob.get(), target] { ui::showSliderMenu (*k, &engine, target()); };
  1168. knob->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
  1169. knob->onDragEnd = [this, target] { engine.tweakReleased (target()); };
  1170. }
  1171. addAndMakeVisible (*knob);
  1172. knobs.push_back (std::move (knob));
  1173. }
  1174. // round 168p: a knob of Drumaxx's selected pad / DrumSynth Live's selected key (drumcontrols' per-part control):
  1175. // named as the control (the layout places it), editing and automating the part's engine parameter
  1176. void addPartParam (const ChannelDef& def, const drumcontrols::Control& c)
  1177. {
  1178. auto knob = std::make_unique<MenuSlider>();
  1179. knob->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  1180. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  1181. knob->setRange (c.low, c.high, c.integer ? 1.0 : 0.0);
  1182. knob->setValue (drumcontrols::value (def, c, drumPart).value_or (c.low), juce::dontSendNotification);
  1183. knob->setDoubleClickReturnValue (false, 0.0);
  1184. knob->setName (c.name);
  1185. const auto* control = &c;
  1186. knob->onValueChange = [this, control, s = knob.get()] {
  1187. ref.edit (engine, [control, part = drumPart, v = (float) s->getValue()] (ChannelDef& d) { drumcontrols::setValue (d, *control, v, part); });
  1188. if (layout != nullptr)
  1189. repaint();
  1190. };
  1191. if (ref.index >= 0)
  1192. {
  1193. const auto target = [this, control] {
  1194. return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, drumcontrols::absoluteIndex (instrumentKind, *control, drumPart) };
  1195. };
  1196. ui::setOwnMenu (*knob);
  1197. knob->onMenu = [this, k = knob.get(), target] { ui::showSliderMenu (*k, &engine, target()); };
  1198. knob->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
  1199. knob->onDragEnd = [this, target] { engine.tweakReleased (target()); };
  1200. }
  1201. partKnobs.push_back ({ knob.get(), control });
  1202. addAndMakeVisible (*knob);
  1203. knobs.push_back (std::move (knob));
  1204. }
  1205. // the pad remembered for each Drumaxx channel while LYNX runs (FL's editor keeps it, not the state)
  1206. static int& drumaxxPadOf (int channel)
  1207. {
  1208. static std::map<int, int> pads;
  1209. return pads[channel];
  1210. }
  1211. // another pad / key selected: the part's knobs show its values (no rebuild)
  1212. void selectPart (int part)
  1213. {
  1214. const auto* def = ref.get (engine);
  1215. if (def == nullptr || part == drumPart)
  1216. return;
  1217. drumPart = part;
  1218. if (drumaxx)
  1219. drumaxxPadOf (ref.index) = part;
  1220. if (drumsynth)
  1221. {
  1222. editorKey = part;
  1223. ref.edit (engine, [part] (ChannelDef& d) { // FL keeps the selected key in the state
  1224. if (lynx::drumSynthEditorKeyIndex < (int) d.modelParams.size())
  1225. d.modelParams[(std::size_t) lynx::drumSynthEditorKeyIndex] = (float) part;
  1226. });
  1227. }
  1228. for (const auto& [k, c] : partKnobs)
  1229. k->setValue (drumcontrols::value (*def, *c, drumPart).value_or (c->low), juce::dontSendNotification);
  1230. repaint();
  1231. }
  1232. // the listed parameters' knobs read the channel's state again (an edit that moved other values: Transistor Bass's
  1233. // note / octave, CLEAR, octave buttons; round 168q2)
  1234. void syncKnobs (bool all = false)
  1235. {
  1236. const auto* c = channelNow();
  1237. if (c == nullptr || modelTable == nullptr)
  1238. return;
  1239. for (auto& k : knobs)
  1240. if (const auto* p = modelparams::findByName (instrumentKind, k->getName().toStdString()); p != nullptr && (all || p->index >= tbseq::length))
  1241. if (const auto v = modelparams::rawValue (*c, p->index))
  1242. k->setValue (*v, juce::dontSendNotification);
  1243. }
  1244. // the items shown only while another control is within a range (LayoutItem::whenParam, e.g. an effect slot's
  1245. // fields for its type): their knobs follow
  1246. bool conditionHolds (const plugui::LayoutItem& item) const
  1247. {
  1248. auto holds = [this] (const char* param, float lo, float hi) {
  1249. if (param == nullptr)
  1250. return true;
  1251. const auto* k = knobFor (param);
  1252. if (k == nullptr)
  1253. return true;
  1254. const auto v = normalised (*k); // (0…1 over the knob's range, as the effect layouts' conditions)
  1255. return v >= lo && (v < hi || (hi >= 1.0f && v <= hi));
  1256. };
  1257. return (item.page < 0 || item.page == page) && holds (item.whenParam, item.whenMin, item.whenMax)
  1258. && holds (item.when2Param, item.when2Min, item.when2Max);
  1259. }
  1260. int pageCount() const { return layout != nullptr ? (int) layout->pages.size() : 0; }
  1261. void showPage (int p)
  1262. {
  1263. page = p;
  1264. updateConditional();
  1265. repaint();
  1266. }
  1267. void updateConditional()
  1268. {
  1269. if (layout == nullptr)
  1270. return;
  1271. for (auto& k : knobs)
  1272. if (const auto* item = itemFor (k->getName()); item != nullptr && (item->type == plugui::Item::knob || item->type == plugui::Item::vslider || item->type == plugui::Item::hslider))
  1273. k->setVisible (conditionHolds (*item));
  1274. }
  1275. // --- FL's arrangement ------------------------------------------------------------------------------
  1276. static constexpr float layoutScale = 1.25f;
  1277. static constexpr int layoutTop = 34;
  1278. const plugui::LayoutItem* itemFor (const juce::String& name) const
  1279. {
  1280. if (layout == nullptr)
  1281. return nullptr;
  1282. const plugui::LayoutItem* any = nullptr;
  1283. for (const auto& item : layout->items) // the knob / fader of the parameter first (a pad may share it)
  1284. if (item.param != nullptr && name == item.param)
  1285. {
  1286. if (item.type == plugui::Item::knob || item.type == plugui::Item::vslider)
  1287. return &item;
  1288. if (any == nullptr && item.type != plugui::Item::display)
  1289. any = &item;
  1290. }
  1291. return any;
  1292. }
  1293. juce::Slider* knobFor (const char* name) const
  1294. {
  1295. for (const auto& k : knobs)
  1296. if (name != nullptr && k->getName() == name)
  1297. return k.get();
  1298. return nullptr;
  1299. }
  1300. float layoutFactor() const
  1301. {
  1302. if (layout == nullptr)
  1303. return 1.0f;
  1304. return juce::jmax (0.4f, juce::jmin ((float) (getWidth() - 16) / (float) layout->width, (float) (getHeight() - layoutTop - 8) / (float) layout->height));
  1305. }
  1306. juce::Rectangle<float> layoutRect (const plugui::LayoutItem& item) const
  1307. {
  1308. const auto f = layoutFactor();
  1309. return { 8.0f + item.x * f, (float) layoutTop + item.y * f, item.w * f, item.h * f };
  1310. }
  1311. static float normalised (const juce::Slider& k)
  1312. {
  1313. const auto range = k.getMaximum() - k.getMinimum();
  1314. return range > 0.0 ? (float) ((k.getValue() - k.getMinimum()) / range) : 0.0f;
  1315. }
  1316. static void setNormalised (juce::Slider& k, float v)
  1317. {
  1318. k.setValue (k.getMinimum() + (double) v * (k.getMaximum() - k.getMinimum()), juce::sendNotificationSync);
  1319. }
  1320. // the radio's option cell (grids fill row by row)
  1321. juce::Rectangle<float> optionCell (const plugui::LayoutItem& item, int o, int count) const
  1322. {
  1323. const auto r = layoutRect (item);
  1324. const auto columns = juce::jmax (1, item.columns);
  1325. const auto rows = (count + columns - 1) / columns;
  1326. const auto w = r.getWidth() / (float) columns, h = r.getHeight() / (float) juce::jmax (1, rows);
  1327. return { r.getX() + w * (float) (o % columns), r.getY() + h * (float) (o / columns), w, h };
  1328. }
  1329. // a tabs item's segment o of `count` (left to right)
  1330. juce::Rectangle<float> tabCell (const plugui::LayoutItem& item, int o, int count) const
  1331. {
  1332. const auto r = layoutRect (item);
  1333. const auto w = r.getWidth() / (float) juce::jmax (1, count);
  1334. return { r.getX() + w * (float) o, r.getY(), w, r.getHeight() };
  1335. }
  1336. // a small drawing of an oscillator shape (3x Osc's shape buttons)
  1337. static void drawShape (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& name)
  1338. {
  1339. juce::Path p;
  1340. const auto x0 = r.getX(), w = r.getWidth(), yc = r.getCentreY(), a = r.getHeight() * 0.5f;
  1341. const auto n = 48;
  1342. for (int i = 0; i <= n; ++i)
  1343. {
  1344. const auto t = (float) i / (float) n;
  1345. float y = 0.0f;
  1346. if (name == "Sine") y = std::sin (t * juce::MathConstants<float>::twoPi);
  1347. else if (name == "Square") y = t < 0.5f ? 1.0f : -1.0f;
  1348. else if (name == "Rounded") y = t < 0.46f ? 1.0f - 2.0f * std::pow (0.997f, t * 16384.0f) : (t < 0.83f ? 1.0f : -1.0f);
  1349. else if (name == "Triangle") y = t < 0.25f ? 4.0f * t : (t < 0.75f ? 2.0f - 4.0f * t : 4.0f * t - 4.0f);
  1350. else if (name == "Saw") y = 2.0f * t - 1.0f;
  1351. else if (name == "Noise") y = std::sin ((float) i * 12.9898f) * std::cos ((float) i * 4.1414f) * 1.6f;
  1352. else /* custom */ y = std::sin (t * juce::MathConstants<float>::twoPi * 3.0f) * std::exp (-std::abs (t - 0.5f) * 5.0f);
  1353. y = juce::jlimit (-1.0f, 1.0f, y);
  1354. const juce::Point<float> pt { x0 + w * t, yc - a * y };
  1355. if (i == 0)
  1356. p.startNewSubPath (pt);
  1357. else
  1358. p.lineTo (pt);
  1359. }
  1360. g.strokePath (p, juce::PathStrokeType (1.5f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1361. }
  1362. // round 170j: the page draws its own art right now (Settings may force another style)
  1363. bool themedNow() const { return pageArt != skin::Art::none && skin::resolve (pageStyle, pageArt) == skin::Style::themed; }
  1364. juce::Colour pageAccent() const { return themedNow() ? skin::artAccent (pageArt) : accent; }
  1365. // where the art's moving part lives: next to the plugin's big name (Toxic's trefoil, Sytrus's figure, 3x Osc's
  1366. // scope); Sakura's petals fall in the band of the branch, above the first row of sections (a small area to repaint)
  1367. juce::Rectangle<float> artStage() const
  1368. {
  1369. if (layout == nullptr)
  1370. return {};
  1371. const auto f = layoutFactor();
  1372. if (pageArt == skin::Art::sakura)
  1373. {
  1374. auto top = (float) getHeight();
  1375. for (const auto& item : layout->items)
  1376. if (item.type == plugui::Item::section && layoutRect (item).getY() > (float) getHeight() * 0.18f)
  1377. top = juce::jmin (top, layoutRect (item).getY());
  1378. return { 0.0f, 30.0f, (float) getWidth(), juce::jmax (40.0f, top - 30.0f) };
  1379. }
  1380. for (const auto& item : layout->items)
  1381. if (item.type == plugui::Item::label && item.label != nullptr && (item.style & plugui::dim) != 0 && item.h * f > 30.0f * f
  1382. && juce::String (item.label).length() > 2)
  1383. {
  1384. const auto r = layoutRect (item);
  1385. const auto w = juce::GlyphArrangement::getStringWidth (theme::font (r.getHeight() * 0.6f, true), item.label);
  1386. const auto left = (item.style & plugui::alignLeft) != 0;
  1387. const auto x0 = left ? r.getX() : r.getRight() - juce::jmin (w, r.getWidth());
  1388. if (pageArt == skin::Art::toxic)
  1389. return { x0 - r.getHeight() * 1.5f, r.getY() - r.getHeight() * 0.15f, r.getHeight() * 1.3f, r.getHeight() * 1.3f };
  1390. return { left ? x0 + w + 12.0f : x0 - r.getHeight() * 2.6f - 12.0f, r.getY() - r.getHeight() * 0.1f, r.getHeight() * 2.6f, r.getHeight() * 1.2f };
  1391. }
  1392. return {};
  1393. }
  1394. void paintLayout (juce::Graphics& g)
  1395. {
  1396. using namespace theme;
  1397. const skin::StyleScope styleScope (skin::resolve (pageStyle, pageArt), pageArt);
  1398. const auto accent = pageAccent(); // (the art's own light when Themed)
  1399. const auto f = layoutFactor();
  1400. const auto* found = ref.get (engine);
  1401. if (found == nullptr)
  1402. return;
  1403. const auto& def = *found;
  1404. const auto caption = [&] (const char* text, juce::Rectangle<float> r, bool dimmed, juce::Justification j) {
  1405. if (text == nullptr || *text == 0)
  1406. return;
  1407. g.setColour (dimmed ? colour::textDisabled : colour::textSecondary);
  1408. g.setFont (font (juce::jmax (8.0f, 9.5f * f), true));
  1409. g.drawFittedText (caps (tr (text)), r.toNearestInt(), j, 1, 0.7f);
  1410. };
  1411. for (const auto& item : layout->items)
  1412. {
  1413. if (! conditionHolds (item))
  1414. continue;
  1415. const auto r = layoutRect (item);
  1416. // round 170j: a partial repaint (the art's petals) draws only the items it touches (captions may hang
  1417. // up to ~26 units past an item's sides)
  1418. if (! g.clipRegionIntersects (r.expanded (32.0f * f, 8.0f * f).getSmallestIntegerContainer()))
  1419. continue;
  1420. const auto dimmed = (item.style & plugui::dim) != 0;
  1421. auto* k = knobFor (item.param);
  1422. switch (item.type)
  1423. {
  1424. case plugui::Item::tabs: // a row of segmented buttons (round 168n); pageTabs: the layout's pages
  1425. if ((item.style & plugui::pageTabs) != 0)
  1426. {
  1427. const auto labels = plugui::optionLabels (item);
  1428. for (int o = 0; o < (int) labels.size(); ++o)
  1429. {
  1430. const auto cell = tabCell (item, o, (int) labels.size()).reduced (1.5f * f, 2.0f * f);
  1431. skin::button (g, cell, o == page, false, accent, radius::sm * f);
  1432. g.setColour (o == page ? colour::onAccent : colour::textSecondary);
  1433. g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.62f)), true));
  1434. g.drawFittedText (tr (labels[(std::size_t) o]), cell.reduced (2.0f * f, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1435. }
  1436. }
  1437. else if (k != nullptr)
  1438. {
  1439. const auto labels = plugui::optionLabels (item);
  1440. const auto chosen = plugui::optionAt (item, normalised (*k));
  1441. for (int o = 0; o < (int) labels.size(); ++o)
  1442. {
  1443. const auto cell = tabCell (item, o, (int) labels.size()).reduced (1.5f * f, 2.0f * f);
  1444. skin::button (g, cell, o == chosen, false, accent, radius::sm * f);
  1445. g.setColour (o == chosen ? colour::onAccent : colour::textSecondary);
  1446. g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.62f)), true));
  1447. g.drawFittedText (tr (labels[(std::size_t) o]), cell.reduced (2.0f * f, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
  1448. }
  1449. }
  1450. break;
  1451. case plugui::Item::menu: // a choice list: the current option and ▾ (round 168n)
  1452. if (k != nullptr)
  1453. {
  1454. const auto labels = plugui::optionLabels (item);
  1455. const auto chosen = plugui::optionAt (item, normalised (*k));
  1456. auto box = r;
  1457. if (item.label != nullptr && (item.style & plugui::noCaption) == 0)
  1458. caption (item.label, box.removeFromTop (12.0f * f), dimmed, juce::Justification::centredLeft);
  1459. skin::valuePlate (g, box, radius::sm * f);
  1460. g.setColour (colour::textPrimary);
  1461. g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, box.getHeight() * 0.62f)), true));
  1462. const auto text = juce::isPositiveAndBelow (chosen, (int) labels.size()) ? tr (labels[(std::size_t) chosen]) : juce::String();
  1463. g.drawFittedText (text, box.reduced (4.0f * f, 0.0f).withTrimmedRight (10.0f * f).toNearestInt(), juce::Justification::centredLeft, 1, 0.6f);
  1464. g.setColour (colour::textSecondary);
  1465. g.drawText (juce::String::fromUTF8 ("\xe2\x96\xbe"), box.withTrimmedLeft (box.getWidth() - 12.0f * f), juce::Justification::centred, false);
  1466. }
  1467. break;
  1468. case plugui::Item::value: // the control's value as text (round 168n)
  1469. if (k != nullptr)
  1470. {
  1471. skin::valuePlate (g, r, radius::sm * f);
  1472. g.setColour (colour::textPrimary);
  1473. g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, r.getHeight() * 0.7f)), true));
  1474. g.drawFittedText (k->getTextFromValue (k->getValue()), r.reduced (3.0f * f, 0.0f).toNearestInt(),
  1475. (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centred, 1, 0.6f);
  1476. }
  1477. break;
  1478. case plugui::Item::section:
  1479. skin::section (g, r, radius::lg * f, (item.style & plugui::raised) != 0, accent);
  1480. if (item.label != nullptr && (item.style & plugui::boxed) == 0)
  1481. skin::sectionTitle (g, r.withHeight (16.0f * f).translated (0.0f, 1.0f * f), caps (tr (item.label)), accent, juce::jmax (8.0f, 10.0f * f));
  1482. break;
  1483. case plugui::Item::label:
  1484. if (item.label != nullptr && juce::String (item.label).length() <= 2 && dimmed) // big dim numbers (3x Osc rows)
  1485. {
  1486. g.setColour (colour::bg4);
  1487. g.setFont (font (r.getHeight() * 0.9f, true));
  1488. g.drawText (item.label, r, juce::Justification::centred, false);
  1489. }
  1490. else if (dimmed && r.getHeight() > 30.0f * f) // the plugin's name, big and readable (round 168q2)
  1491. {
  1492. g.setColour (themedNow() ? accent.interpolatedWith (juce::Colours::white, 0.55f) : colour::textSecondary);
  1493. g.setFont (font (r.getHeight() * 0.6f, true));
  1494. g.drawFittedText (item.label, r.toNearestInt(),
  1495. (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centredRight, 1, 0.8f);
  1496. }
  1497. else
  1498. caption (item.label, r, dimmed, (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centred);
  1499. break;
  1500. case plugui::Item::knob: // (a small knob's caption may use some room on both sides, as a fader's does)
  1501. if ((item.style & plugui::noCaption) == 0)
  1502. caption (item.label, r.withTop (r.getBottom() - 12.0f * f).expanded (juce::jmax (0.0f, 52.0f * f - r.getWidth()) * 0.5f, 0.0f), dimmed, juce::Justification::centred);
  1503. break;
  1504. case plugui::Item::vslider:
  1505. case plugui::Item::hslider:
  1506. if ((item.style & plugui::noCaption) == 0)
  1507. caption (item.label, r.withTop (r.getBottom() - 12.0f * f).expanded (16.0f * f, 0.0f), dimmed, juce::Justification::centred);
  1508. break;
  1509. case plugui::Item::radio:
  1510. if (k != nullptr)
  1511. {
  1512. const auto labels = plugui::optionLabels (item);
  1513. const auto chosen = plugui::optionAt (item, normalised (*k));
  1514. for (int o = 0; o < (int) labels.size(); ++o)
  1515. {
  1516. const auto cell = optionCell (item, o, (int) labels.size()).reduced (3.0f * f);
  1517. skin::button (g, cell, o == chosen, false, accent, radius::md * f);
  1518. g.setColour (o == chosen ? accent.brighter (0.5f) : colour::textSecondary);
  1519. if (item.columns > 0)
  1520. drawShape (g, cell.reduced (cell.getWidth() * 0.22f, cell.getHeight() * 0.3f), labels[(std::size_t) o]);
  1521. else
  1522. g.drawFittedText (tr (labels[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1523. }
  1524. }
  1525. break;
  1526. case plugui::Item::toggle:
  1527. if (k != nullptr)
  1528. {
  1529. const auto on = normalised (*k) >= 0.5f;
  1530. if ((item.style & plugui::boxed) != 0)
  1531. {
  1532. const auto box = r.reduced (3.0f * f);
  1533. skin::button (g, box, on, false, accent, radius::md * f);
  1534. g.setColour (on ? colour::onAccent : colour::textSecondary);
  1535. g.setFont (font (juce::jmax (8.0f, 11.0f * f), true));
  1536. g.drawText (item.label != nullptr ? item.label : "", box, juce::Justification::centred, false);
  1537. }
  1538. else
  1539. {
  1540. const auto dot = juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre ({ r.getX() + 6.0f * f, r.getCentreY() });
  1541. if (on)
  1542. {
  1543. g.setColour (accent.withAlpha (0.3f));
  1544. g.fillEllipse (dot.expanded (3.0f * f));
  1545. }
  1546. g.setColour (on ? accent : juce::Colour (0xff0b0c0f));
  1547. g.fillEllipse (dot);
  1548. g.setColour (juce::Colours::white.withAlpha (on ? 0.4f : 0.08f));
  1549. g.drawEllipse (dot.reduced (0.5f), 1.0f);
  1550. caption (item.label, r.withTrimmedLeft (14.0f * f), false, juce::Justification::centredLeft);
  1551. }
  1552. }
  1553. break;
  1554. case plugui::Item::stepper:
  1555. if (k != nullptr)
  1556. {
  1557. auto box = r;
  1558. if (item.label != nullptr)
  1559. caption (item.label, box.removeFromTop (12.0f * f), false, juce::Justification::centred);
  1560. skin::valuePlate (g, box, radius::sm * f);
  1561. g.setColour (colour::textPrimary);
  1562. g.setFont (font (juce::jmax (9.0f, 12.0f * f), true));
  1563. // oversampling orders read as FL shows them (0 → 1x … 3 → 8x)
  1564. // a Transistor Bass step's note reads as a note name (60 = C5, FL's naming; round 168q2)
  1565. static const char* const noteNames[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  1566. const auto whole = (int) std::lround (k->getValue());
  1567. const auto* units = unitParam (*k); // (round 169h: a 0…1 number box in whole units)
  1568. const auto text = units != nullptr ? juce::String (units->unitString (units->unitOf ((float) k->getValue())))
  1569. : juce::String (item.param).containsIgnoreCase ("oversampling") ? juce::String (1 << juce::jlimit (0, 8, (int) k->getValue())) + "x"
  1570. : juce::String (item.param).endsWith (" note") ? juce::String (noteNames[((whole % 12) + 12) % 12]) + juce::String (whole / 12)
  1571. : juce::String (whole);
  1572. g.drawFittedText (text, box.withTrimmedRight (8.0f * f).toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1573. g.setColour (colour::textSecondary);
  1574. g.drawText (juce::String::fromUTF8 ("\xe2\x96\xb4"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withHeight (box.getHeight() * 0.5f), juce::Justification::centred, false);
  1575. g.drawText (juce::String::fromUTF8 ("\xe2\x96\xbe"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withTrimmedTop (box.getHeight() * 0.5f), juce::Justification::centred, false);
  1576. }
  1577. break;
  1578. case plugui::Item::display:
  1579. skin::well (g, r, radius::md * f);
  1580. // round 168q: BeepMap's bitmap, its file row, the Granulizer's sample and grains, Transistor Bass's
  1581. // program and sequence
  1582. if (juce::String (item.display) == "beepmapimage")
  1583. paintBeepMapImage (g, r.reduced (3.0f * f));
  1584. if (juce::String (item.display) == "beepmapfile")
  1585. paintBeepMapFile (g, r, f);
  1586. if (juce::String (item.display) == "granulizerwave")
  1587. paintGranulizerWave (g, r.reduced (4.0f * f), f);
  1588. if (juce::String (item.display) == "granulizergrains")
  1589. paintGranulizerGrains (g, r.reduced (5.0f * f), f);
  1590. if (juce::String (item.display) == "tbprogram")
  1591. paintTransistorBass (g, r, f);
  1592. if (juce::String (item.display) == "tbsteps")
  1593. paintTransistorBassSteps (g, r, f);
  1594. if (juce::String (item.display) == "tbseqtools")
  1595. paintTransistorBassTools (g, r, f);
  1596. if (juce::String (item.display) == "xy")
  1597. if (auto* kx = knobFor (item.param); kx != nullptr)
  1598. if (auto* ky = knobFor (item.param2); ky != nullptr)
  1599. {
  1600. // FL's Ogun pad (TQuickXYZ, round 169h shots fl-ogun-*.png): a 4 × 4 grid and a small ring
  1601. // whose centre is the value, drawn clipped to the pad — at X = 0 only its inner half shows
  1602. const juce::Graphics::ScopedSaveState clip (g);
  1603. g.reduceClipRegion (r.toNearestInt());
  1604. for (int k = 1; k < 4; ++k)
  1605. {
  1606. g.setColour (k == 2 ? colour::gridBar : colour::gridBeat);
  1607. g.drawVerticalLine ((int) (r.getX() + r.getWidth() * (float) k / 4.0f), r.getY(), r.getBottom());
  1608. g.drawHorizontalLine ((int) (r.getY() + r.getHeight() * (float) k / 4.0f), r.getX(), r.getRight());
  1609. }
  1610. const juce::Point<float> pt { r.getX() + r.getWidth() * normalised (*kx), r.getBottom() - r.getHeight() * normalised (*ky) };
  1611. g.setColour (accent);
  1612. g.drawEllipse (juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre (pt), juce::jmax (1.5f, 1.5f * f));
  1613. }
  1614. if (juce::String (item.display) == "toxicwave" && item.param != nullptr) // round 168n: the wave's cycle
  1615. {
  1616. const juce::String name (item.param);
  1617. const auto n = name.fromFirstOccurrenceOf (" ", false, false).getIntValue();
  1618. const auto slot = name.startsWith ("LFO") ? 5 + n : n - 1;
  1619. const auto inner = r.reduced (5.0f * f, 6.0f * f);
  1620. const auto shape = toxicWaveShape (def.pluginState, def.samplePath, slot, 96);
  1621. if (shape.empty())
  1622. {
  1623. g.setColour (colour::textSecondary);
  1624. g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
  1625. g.drawFittedText (tr ("Needs FL Studio's files"), inner.toNearestInt(), juce::Justification::centred, 2, 0.7f);
  1626. }
  1627. else
  1628. {
  1629. g.setColour (colour::gridBeat);
  1630. g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
  1631. juce::Path wave;
  1632. for (int i = 0; i < (int) shape.size(); ++i)
  1633. {
  1634. const juce::Point<float> pt { inner.getX() + inner.getWidth() * (float) i / (float) (shape.size() - 1),
  1635. inner.getCentreY() - inner.getHeight() * 0.5f * shape[(std::size_t) i] };
  1636. if (i == 0)
  1637. wave.startNewSubPath (pt);
  1638. else
  1639. wave.lineTo (pt);
  1640. }
  1641. g.setColour (accent.withAlpha (0.25f));
  1642. g.strokePath (wave, juce::PathStrokeType (3.0f * f));
  1643. g.setColour (accent.brighter (0.3f));
  1644. g.strokePath (wave, juce::PathStrokeType (1.3f * f));
  1645. }
  1646. }
  1647. paintDrumDisplay (g, item, r, def, f);
  1648. // round 168o: the envelopes of the synth group's pages, drawn from their knobs (attack, decay, sustain, release;
  1649. // a missing stage is skipped, a missing sustain is the level the decay falls to: none)
  1650. {
  1651. struct Env
  1652. {
  1653. const char* id;
  1654. const char* a;
  1655. const char* d;
  1656. const char* s;
  1657. const char* r;
  1658. const char* start; // a modulator's initial level (DX10)
  1659. };
  1660. static const Env envs[] = {
  1661. { "dx10amp", "Attack", "Decay", nullptr, "Release", nullptr },
  1662. { "dx10mod1", nullptr, "Mod 1 time", "Mod 1 sustain", "Mod 1 release", "Mod 1 init" },
  1663. { "dx10mod2", nullptr, "Mod 2 time", "Mod 2 sustain", "Mod 2 release", "Mod 2 init" },
  1664. { "simamp", "Attack", "Decay", "Sustain", "Release", nullptr },
  1665. { "simfilt", "Filter attack", "Filter decay", "Filter sustain", "Filter release", nullptr },
  1666. { "ministenv", "Attack", "Decay", "Sustain", "Release", nullptr },
  1667. };
  1668. for (const auto& e : envs)
  1669. if (juce::String (item.display) == e.id)
  1670. {
  1671. const auto value = [&] (const char* name, float otherwise) {
  1672. auto* kn = name != nullptr ? knobFor (name) : nullptr;
  1673. return kn != nullptr ? juce::jlimit (0.0f, 1.0f, normalised (*kn)) : otherwise;
  1674. };
  1675. const auto inner = r.reduced (5.0f * f, 5.0f * f);
  1676. const auto a = value (e.a, 0.0f), d = value (e.d, 0.5f), su = value (e.s, 0.0f), rl = value (e.r, 0.3f);
  1677. const auto peak = e.start != nullptr ? value (e.start, 1.0f) : 1.0f;
  1678. const auto unit = inner.getWidth() / 4.0f;
  1679. const auto y = [&] (float level) { return inner.getBottom() - inner.getHeight() * level; };
  1680. juce::Path env;
  1681. auto x = inner.getX();
  1682. env.startNewSubPath (x, y (e.start != nullptr ? peak : 0.0f));
  1683. x += unit * a;
  1684. env.lineTo (x, y (peak));
  1685. // DX10's amp decay ≥ 0.98 holds the note
  1686. const auto hold = e.s != nullptr ? su : (d >= 0.98f ? peak : 0.0f);
  1687. x += unit * (0.15f + 0.85f * d);
  1688. env.lineTo (x, y (hold));
  1689. env.lineTo (inner.getRight() - unit * (0.15f + 0.85f * rl), y (hold));
  1690. env.lineTo (inner.getRight(), y (0.0f));
  1691. g.setColour (colour::gridBeat);
  1692. g.drawHorizontalLine ((int) inner.getBottom(), inner.getX(), inner.getRight());
  1693. g.setColour (accent.withAlpha (0.25f));
  1694. g.strokePath (env, juce::PathStrokeType (3.0f * f));
  1695. g.setColour (accent.brighter (0.3f));
  1696. g.strokePath (env, juce::PathStrokeType (1.3f * f));
  1697. }
  1698. }
  1699. if (juce::String (item.display) == "gmswaves") // round 168o: GMS's waves are read from FL Studio's folder
  1700. {
  1701. g.setColour (colour::textSecondary);
  1702. g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
  1703. const auto text = def.samplePath.empty() ? tr ("Needs FL Studio's files")
  1704. : juce::File (juce::String::fromUTF8 (def.samplePath.c_str())).getFileName();
  1705. g.drawFittedText (text, r.reduced (6.0f * f).toNearestInt(), juce::Justification::centred, 3, 0.7f);
  1706. }
  1707. if (juce::String (item.display) == "flkeysname")
  1708. if (const auto st = flkeys::parseState (def.pluginState))
  1709. {
  1710. g.setColour (colour::textPrimary);
  1711. g.setFont (font (juce::jmax (9.0f, 11.0f * f)));
  1712. g.drawFittedText (juce::String::fromUTF8 (st->wavetable.c_str()), r.reduced (6.0f * f, 0.0f).toNearestInt(),
  1713. juce::Justification::centredLeft, 1, 0.8f);
  1714. }
  1715. break;
  1716. default:
  1717. break;
  1718. }
  1719. }
  1720. }
  1721. // round 168p: the displays of the drum pages (Drumaxx's kit / pads, BassDrum's noise sample, DrumSynth Live's
  1722. // selected patch and its key display)
  1723. static juce::String keyName (int key) { return juce::String (notenames::keyName (key)); }
  1724. juce::Rectangle<float> dslKeyCell (juce::Rectangle<float> r, int key) const
  1725. {
  1726. // the 120 patch keys in 4 rows of 30 (C0 … B9, FL's octave numbers)
  1727. const auto w = r.getWidth() / 30.0f, h = r.getHeight() / 4.0f;
  1728. return { r.getX() + w * (float) (key % 30), r.getY() + h * (float) (key / 30), w, h };
  1729. }
  1730. void paintDrumDisplay (juce::Graphics& g, const plugui::LayoutItem& item, juce::Rectangle<float> r, const ChannelDef& def, float f)
  1731. {
  1732. using namespace theme;
  1733. const juce::String id (item.display);
  1734. auto text = [&] (const juce::String& t, juce::Colour c, juce::Justification j = juce::Justification::centred) {
  1735. g.setColour (c);
  1736. g.setFont (font (juce::jmax (8.0f, juce::jmin (12.0f * f, r.getHeight() * 0.62f))));
  1737. g.drawFittedText (t, r.reduced (4.0f * f, 1.0f).toNearestInt(), j, 1, 0.7f);
  1738. };
  1739. if (id == "drumaxxkit")
  1740. {
  1741. const auto name = juce::String::fromUTF8 (drumaxxKitName (def.pluginState).c_str());
  1742. text (name.isEmpty() ? tr ("(no kit name)") : name, colour::textPrimary, juce::Justification::centredLeft);
  1743. }
  1744. else if (id == "drumaxxpad")
  1745. {
  1746. const auto pad = item.steps;
  1747. const auto keyValue = drumaxxParam (def.pluginState, 44 * pad + 4);
  1748. const auto key = std::isfinite (keyValue) ? (int) keyValue : -1;
  1749. skin::button (g, r.reduced (2.0f * f), pad == drumPart, false, accent, radius::md * f);
  1750. g.setColour (pad == drumPart ? colour::onAccent : colour::textSecondary);
  1751. g.setFont (font (juce::jmax (8.0f, 10.0f * f), true));
  1752. g.drawFittedText (juce::String (pad + 1) + "\n" + (key >= 0 && key < 128 ? keyName (key) : juce::String()), r.toNearestInt(),
  1753. juce::Justification::centred, 2, 0.7f);
  1754. }
  1755. else if (id == "drumaxxpadname")
  1756. {
  1757. const auto name = juce::String::fromUTF8 (drumaxxPadName (def.pluginState, item.steps).c_str());
  1758. text (name.isEmpty() ? tr ("Pad {0}", { juce::String (item.steps + 1) }) : name, item.steps == drumPart ? accent.brighter (0.4f) : colour::textSecondary,
  1759. juce::Justification::centredLeft);
  1760. }
  1761. else if (id == "bassdrumnoise")
  1762. {
  1763. if (! bassDrumStateUsable (def.pluginState) || def.samplePath.empty())
  1764. text (tr ("Needs FL Studio's files"), colour::textSecondary);
  1765. else
  1766. {
  1767. const auto name = juce::String::fromUTF8 (bassDrumNoiseName (def.pluginState).c_str());
  1768. text (name.isEmpty() ? tr ("(no noise sample)") : name, colour::textPrimary, juce::Justification::centredLeft);
  1769. }
  1770. }
  1771. else if (id == "dslpatch")
  1772. text (keyName (drumPart) + " (" + juce::String (drumPart) + ")", colour::textPrimary);
  1773. else if (id == "dslsend" || id == "dslmorph")
  1774. {
  1775. const auto slot = drumSynthKeyToSlot (drumPart);
  1776. const auto at = drumSynthPatchParams * slot + (id == "dslsend" ? 34 : 36);
  1777. const auto v = slot >= 0 && at < (int) def.modelParams.size() ? (int) std::lround (def.modelParams[(std::size_t) at]) : -1;
  1778. text (id == "dslsend" ? (v < 0 ? juce::String ("-") : juce::String (v)) : (v < 0 || v > 119 ? tr ("(none)") : keyName (v)), colour::textPrimary);
  1779. }
  1780. else if (id == "dslkeys")
  1781. {
  1782. const auto inner = r.reduced (3.0f * f);
  1783. for (int key = 0; key < drumSynthPatches; ++key)
  1784. {
  1785. const auto cell = dslKeyCell (inner, key).reduced (0.5f * f);
  1786. const auto slot = drumSynthKeyToSlot (key);
  1787. const auto level = (std::size_t) (drumSynthPatchParams * slot) < def.modelParams.size() ? def.modelParams[(std::size_t) (drumSynthPatchParams * slot)] : 0.0f;
  1788. static constexpr bool blackKey[12] = { false, true, false, true, false, false, true, false, true, false, true, false };
  1789. const auto black = blackKey[key % 12];
  1790. g.setColour (key == drumPart ? accent : level > 0.0f ? accent.withAlpha (0.35f) : black ? colour::bg1 : colour::bg4);
  1791. g.fillRect (cell);
  1792. if (key % 12 == 0)
  1793. {
  1794. g.setColour (key == drumPart ? colour::onAccent : colour::textSecondary);
  1795. g.setFont (font (juce::jmax (6.5f, juce::jmin (8.0f * f, cell.getHeight() * 0.6f))));
  1796. g.drawText (juce::String (key / 12), cell, juce::Justification::centred, false);
  1797. }
  1798. }
  1799. }
  1800. }
  1801. // a click on a pad button / the key display selects the part the knobs edit; true when handled
  1802. bool clickDrumDisplay (const plugui::LayoutItem& item, juce::Point<float> at)
  1803. {
  1804. if (item.type != plugui::Item::display || item.display == nullptr || ! layoutRect (item).contains (at) || ! conditionHolds (item))
  1805. return false;
  1806. const juce::String id (item.display);
  1807. if (drumaxx && (id == "drumaxxpad" || id == "drumaxxpadname"))
  1808. {
  1809. selectPart (item.steps);
  1810. return true;
  1811. }
  1812. if (drumsynth && id == "dslkeys")
  1813. {
  1814. const auto inner = layoutRect (item).reduced (3.0f * layoutFactor());
  1815. for (int key = 0; key < drumSynthPatches; ++key)
  1816. if (dslKeyCell (inner, key).contains (at))
  1817. {
  1818. selectPart (key);
  1819. return true;
  1820. }
  1821. }
  1822. return false;
  1823. }
  1824. void resizeLayout()
  1825. {
  1826. for (auto& k : knobs)
  1827. {
  1828. const auto* item = itemFor (k->getName());
  1829. if (item == nullptr || ! k->isVisible())
  1830. continue;
  1831. auto r = layoutRect (*item);
  1832. if ((item->type == plugui::Item::vslider || item->type == plugui::Item::hslider) && (item->style & plugui::noCaption) == 0 && item->label != nullptr)
  1833. r.removeFromBottom (13.0f * layoutFactor());
  1834. if (item->type == plugui::Item::knob)
  1835. {
  1836. if ((item->style & plugui::noCaption) == 0)
  1837. r.removeFromBottom (14.0f * layoutFactor());
  1838. const auto d = juce::jmin (r.getWidth(), r.getHeight());
  1839. r = r.withSizeKeepingCentre (d, d).withY (r.getY());
  1840. }
  1841. k->setBounds (r.toNearestInt());
  1842. }
  1843. }
  1844. // a stepper's number moves one unit (the engine's own units for a 0…1 number box, round 169h)
  1845. const EngineParam* unitParam (const juce::Slider& k) const
  1846. {
  1847. const auto* p = modelparams::findByName (instrumentKind, k.getName().toStdString());
  1848. return p != nullptr && p->hasUnits() ? p : nullptr;
  1849. }
  1850. void stepBy (juce::Slider& k, int delta)
  1851. {
  1852. if (const auto* p = unitParam (k))
  1853. k.setValue (p->rawOfUnit (p->unitOf ((float) k.getValue()) + delta), juce::sendNotificationSync);
  1854. else
  1855. k.setValue (k.getValue() + delta, juce::sendNotificationSync);
  1856. }
  1857. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  1858. {
  1859. if (layout != nullptr && wheel.deltaY != 0.0f)
  1860. for (const auto& item : layout->items)
  1861. if (item.type == plugui::Item::stepper && layoutRect (item).contains (e.position) && conditionHolds (item))
  1862. if (auto* k = knobFor (item.param))
  1863. {
  1864. stepBy (*k, wheel.deltaY > 0.0f ? 1 : -1);
  1865. repaint();
  1866. return;
  1867. }
  1868. juce::Component::mouseWheelMove (e, wheel);
  1869. }
  1870. void mouseDrag (const juce::MouseEvent& e) override
  1871. {
  1872. if (stepperDrag != nullptr)
  1873. {
  1874. if (auto* k = knobFor (stepperDrag->param))
  1875. {
  1876. const auto pixels = 6.0f * layoutFactor();
  1877. const auto units = (int) ((stepperDragY - e.position.y) / pixels);
  1878. if (units != stepperDragged)
  1879. {
  1880. stepBy (*k, units - stepperDragged);
  1881. stepperDragged = units;
  1882. repaint();
  1883. }
  1884. }
  1885. return;
  1886. }
  1887. if (xyItem == nullptr)
  1888. return;
  1889. const auto r = layoutRect (*xyItem);
  1890. if (auto* kx = knobFor (xyItem->param))
  1891. setNormalised (*kx, juce::jlimit (0.0f, 1.0f, (e.position.x - r.getX()) / r.getWidth()));
  1892. if (auto* ky = knobFor (xyItem->param2))
  1893. setNormalised (*ky, juce::jlimit (0.0f, 1.0f, (r.getBottom() - e.position.y) / r.getHeight()));
  1894. repaint();
  1895. }
  1896. void mouseUp (const juce::MouseEvent&) override
  1897. {
  1898. xyItem = nullptr;
  1899. stepperDrag = nullptr;
  1900. }
  1901. void mouseDown (const juce::MouseEvent& e) override
  1902. {
  1903. if (layout == nullptr)
  1904. return;
  1905. for (const auto& item : layout->items) // round 168p: Drumaxx's pads, DrumSynth Live's keys
  1906. if (clickDrumDisplay (item, e.position))
  1907. return;
  1908. for (const auto& item : layout->items) // the page switches first (they edit no parameter)
  1909. if (item.type == plugui::Item::tabs && (item.style & plugui::pageTabs) != 0 && layoutRect (item).contains (e.position) && conditionHolds (item))
  1910. {
  1911. const auto count = (int) plugui::optionLabels (item).size();
  1912. for (int o = 0; o < count; ++o)
  1913. if (tabCell (item, o, count).contains (e.position))
  1914. showPage (o);
  1915. return;
  1916. }
  1917. for (const auto& item : layout->items) // round 168q2: Transistor Bass's CLEAR / octave up / octave down
  1918. if (item.type == plugui::Item::display && juce::String (item.display) == "tbseqtools" && layoutRect (item).contains (e.position))
  1919. {
  1920. if (const auto button = transistorBassToolButton (item, e.position); button >= 0)
  1921. transistorBassToolAction (button);
  1922. return;
  1923. }
  1924. for (const auto& item : layout->items) // round 168q: BeepMap's Open / Paste
  1925. if (item.type == plugui::Item::display && juce::String (item.display) == "beepmapfile" && layoutRect (item).contains (e.position))
  1926. {
  1927. if (const auto button = beepMapFileButton (item, e.position); button >= 0)
  1928. beepMapAction (button);
  1929. return;
  1930. }
  1931. for (const auto& item : layout->items)
  1932. {
  1933. auto* k = knobFor (item.param);
  1934. if (k == nullptr || ! layoutRect (item).contains (e.position) || ! conditionHolds (item)
  1935. || item.type == plugui::Item::knob || item.type == plugui::Item::vslider || item.type == plugui::Item::hslider
  1936. || item.type == plugui::Item::section || item.type == plugui::Item::label)
  1937. continue;
  1938. if (e.mods.isPopupMenu() && ref.index >= 0 && modelTable != nullptr) // a switch / tabs: FL's parameter menu
  1939. {
  1940. if (const auto* p = modelparams::findByName (instrumentKind, k->getName().toStdString()))
  1941. ui::showSliderMenu (*k, &engine, AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, p->index });
  1942. return;
  1943. }
  1944. if (item.type == plugui::Item::menu)
  1945. {
  1946. const auto labels = plugui::optionLabels (item);
  1947. const auto chosen = plugui::optionAt (item, normalised (*k));
  1948. juce::PopupMenu menu;
  1949. for (int o = 0; o < (int) labels.size(); ++o)
  1950. menu.addItem (tr (labels[(std::size_t) o]), true, o == chosen,
  1951. [safe = juce::Component::SafePointer<ModelPanel> (this), name = k->getName(), value = plugui::optionValue (item, o)] {
  1952. if (safe == nullptr)
  1953. return;
  1954. if (auto* knob = safe->knobFor (name.toRawUTF8()))
  1955. setNormalised (*knob, value);
  1956. safe->repaint();
  1957. });
  1958. menu.showMenuAsync (juce::PopupMenu::Options().withTargetScreenArea (localAreaToGlobal (layoutRect (item).toNearestInt())));
  1959. return;
  1960. }
  1961. if (item.type == plugui::Item::tabs)
  1962. {
  1963. const auto count = (int) plugui::optionLabels (item).size();
  1964. for (int o = 0; o < count; ++o)
  1965. if (tabCell (item, o, count).contains (e.position))
  1966. setNormalised (*k, plugui::optionValue (item, o));
  1967. repaint();
  1968. return;
  1969. }
  1970. if (item.type == plugui::Item::display && juce::String (item.display) == "xy")
  1971. {
  1972. xyItem = &item;
  1973. mouseDrag (e);
  1974. return;
  1975. }
  1976. if (item.type == plugui::Item::stepper)
  1977. {
  1978. const auto r = layoutRect (item);
  1979. const auto up = e.position.y < r.getY() + (item.label != nullptr ? 12.0f * layoutFactor() : 0.0f) + (r.getHeight() - (item.label != nullptr ? 12.0f * layoutFactor() : 0.0f)) * 0.5f;
  1980. stepBy (*k, up ? 1 : -1);
  1981. stepperDrag = &item; // (round 169h) a vertical drag moves the number too
  1982. stepperDragY = e.position.y;
  1983. stepperDragged = 0;
  1984. }
  1985. else if (item.type == plugui::Item::toggle)
  1986. setNormalised (*k, normalised (*k) >= 0.5f ? 0.0f : 1.0f);
  1987. else if (item.type == plugui::Item::radio)
  1988. {
  1989. const auto count = (int) plugui::optionLabels (item).size();
  1990. for (int o = 0; o < count; ++o)
  1991. if (optionCell (item, o, count).contains (e.position))
  1992. setNormalised (*k, plugui::optionValue (item, o));
  1993. }
  1994. repaint();
  1995. return;
  1996. }
  1997. }
  1998. void paint (juce::Graphics& g) override
  1999. {
  2000. g.fillAll (theme::colour::bg2);
  2001. if (layout != nullptr) // a plugin page in FL's arrangement: the plugin skin's canvas (round 170j: the art's when Themed)
  2002. {
  2003. const skin::StyleScope styleScope (themedNow() ? skin::Style::themed : skin::style(), pageArt);
  2004. skin::canvas (g, getLocalBounds().toFloat(), pageAccent());
  2005. }
  2006. g.setColour (theme::colour::textPrimary);
  2007. g.setFont (theme::font (layout != nullptr ? theme::type::body : theme::type::title));
  2008. if (! engineFilesMissing)
  2009. g.drawFittedText (drumsynth ? tr ("DrumSynth Live — FL's engine, patch on key {0}", { juce::String (editorKey) })
  2010. + (wavesFound ? tr (" (next hit; recorded waves from your FL installation)")
  2011. : tr (" (next hit; recorded waves not found: silent)"))
  2012. : harmless ? tr ("Harmless — FL's additive engine (chorus/delay/reverb/compressor rack off)")
  2013. : harmor ? tr ("Harmor — FL's additive engine (effects rack off; image synthesis not decoded)")
  2014. : gms ? tr ("GMS — FL's engine (waves read from your FL installation)")
  2015. : morphine ? tr ("Morphine — FL's additive engine (new settings restart the voices)")
  2016. : transistorBass ? tr ("Transistor Bass — FL's engine with its sequencer and effects (oscillator cycles read from your FL installation)")
  2017. : autogun ? tr ("Autogun — FL's engine with its effects and Magic Dust (SG.dat read from your FL installation)")
  2018. : ogun ? tr ("Ogun — FL's engine with its effects (Seed 2 Random is a fixed draw per channel)")
  2019. : poizone ? tr ("PoiZone — FL's engine with its gate, chorus, delay and arpeggiator (new settings restart the voices)")
  2020. : miniSynth ? tr ("MiniSynth — FL's engine with its effects (wave tables read from your FL installation)")
  2021. : dx10 ? tr ("Fruity DX10 — FL's FM engine")
  2022. : kepler ? tr ("Kepler — FL's engine (LFO shape and noise read from your FL installation)")
  2023. : keplerExo ? tr ("Kepler Exo — FL's engine with its effects (tables read from your FL installation)")
  2024. : fruitkick ? tr ("Fruit Kick — FL's engine (channel envelopes stepped per tick)")
  2025. : bassdrum ? tr ("BassDrum — FL's engine (table and noise samples read from your FL installation)")
  2026. : toxic ? tr ("Toxic Biohazard — FL's engine with its effects (waves read from your FL installation)")
  2027. : threeOsc ? tr ("3x Osc — FL's engine (custom wave from the channel's sample)")
  2028. : simSynth ? tr ("SimSynth — FL's engine (new settings restart the voices)")
  2029. : wasp ? tr ("Wasp — FL Studio 2026 has no 64-bit Wasp: the channel keeps its settings and stays silent, as in FL")
  2030. : flKeys ? tr ("FL Keys — FL's engine (wavetable read from your FL installation)")
  2031. : plucked ? tr ("Plucked! — FL's plucked-string engine")
  2032. : beepMap ? tr ("BeepMap — FL's engine (plays the bitmap saved with the channel)")
  2033. : sawer ? tr ("Sawer — FL's engine with its effects (oscillator cycle read from your FL installation)")
  2034. : granulizer ? tr ("Fruity Granulizer — FL's engine on the channel's sample")
  2035. : drumaxx ? tr ("Drumaxx — FL's physical drum engine (pads on their keys; patterns not played)")
  2036. : slayer ? tr ("FL Slayer — FL's engine with its effects, amp and cabinet (picks read from your FL installation; new settings restart the voices)")
  2037. : sytrus ? tr ("Sytrus — FL's engine, main settings (operators, filters and effects keep the saved patch)")
  2038. : fruityDance ? tr ("Fruity Dance — a visual plugin: it makes no sound, the channel keeps its settings")
  2039. : boobass ? tr ("BooBass — FL's engine, its sound read from your FL installation (knobs: 3-band EQ)")
  2040. : sakura ? tr ("Sakura — physical strings (FL's engine; new parameters apply to the next note)")
  2041. : tr ("Drumpad — physical drum (FL's engine; new parameters apply to the next hit)"),
  2042. descriptionArea(), juce::Justification::centredLeft, layout != nullptr ? 1 : 2, 0.8f);
  2043. if (engineFilesMissing) // round 168q: an engine that runs FL's own DLL / data file, which this computer lacks
  2044. {
  2045. const auto band = juce::Rectangle<float> (8.0f, 5.0f, (float) getWidth() - 16.0f, 22.0f);
  2046. g.setColour (accent.withAlpha (0.18f));
  2047. g.fillRoundedRectangle (band, 4.0f);
  2048. g.setColour (theme::colour::textPrimary);
  2049. g.setFont (theme::font (theme::type::small));
  2050. g.drawFittedText (tr ("Needs FL Studio's files: the engine file was not found, so the channel stays silent (its settings are kept)."),
  2051. band.reduced (6.0f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.7f);
  2052. }
  2053. if (layout != nullptr)
  2054. {
  2055. paintLayout (g);
  2056. return;
  2057. }
  2058. g.setFont (theme::font (theme::type::small));
  2059. for (const auto& k : knobs)
  2060. g.drawText (k->getName(), k->getBounds().withHeight (14).translated (0, -14), juce::Justification::centred);
  2061. }
  2062. // the engine's one-line description at the top (round 169h: wrapped to a second line above the knob grid, or shrunk a
  2063. // little on a designed page, instead of cut with "…" in a narrow window); clear of the sample button
  2064. juce::Rectangle<int> descriptionArea() const
  2065. {
  2066. const auto right = sampleButton.isVisible() ? getWidth() - 136 : getWidth() - 10;
  2067. return { 10, layout != nullptr ? 6 : 2, juce::jmax (40, right - 10), layout != nullptr ? 20 : 30 }; // (the knob grid's captions start at y 32)
  2068. }
  2069. void resized() override
  2070. {
  2071. if (sampleButton.isVisible())
  2072. sampleButton.setBounds (getWidth() - 128, 4, 120, 24);
  2073. if (layout != nullptr)
  2074. {
  2075. resizeLayout();
  2076. if (artLayer != nullptr)
  2077. {
  2078. artLayer->setBounds (getLocalBounds());
  2079. artLayer->setStage (artStage());
  2080. artLayer->toFront (false);
  2081. }
  2082. return;
  2083. }
  2084. constexpr int columns = 7, w = 96, h = 92;
  2085. for (std::size_t i = 0; i < knobs.size(); ++i)
  2086. knobs[i]->setBounds (12 + (int) (i % columns) * (w + 4), 46 + (int) (i / columns) * (h + 18), w, h);
  2087. if (granulizerModes)
  2088. {
  2089. // FL's KEY TO, TRANSIENTS and TEMPO LOCKED controls, in a row under the knobs
  2090. const auto rows = ((int) knobs.size() + columns - 1) / columns;
  2091. const auto y = 46 + rows * (h + 18) + 4;
  2092. granKeyToLabel.setBounds (12, y, 150, 18);
  2093. granKeyTo.setBounds (12, y + 20, 150, 24);
  2094. granTransientsLabel.setBounds (174, y, 150, 18);
  2095. granTransients.setBounds (174, y + 20, 150, 24);
  2096. granTempoLocked.setBounds (336, y + 20, 140, 24);
  2097. granBeatsLabel.setBounds (488, y, 200, 18);
  2098. granBeats.setBounds (488, y + 20, 200, 24);
  2099. }
  2100. }
  2101. // FL's Granulizer takes a sample dropped on its window (from the Browser or the system) and plays it; before, the
  2102. // drop fell through to the Playlist under the window and made an audio clip (audit 165)
  2103. bool isInterestedInDragSource (const SourceDetails& details) override
  2104. {
  2105. return takesSample() && BrowserComponent::isBrowserDrag (details) && SampleLibrary::isSampleFile (BrowserComponent::draggedFile (details));
  2106. }
  2107. void itemDragEnter (const SourceDetails&) override { setDropHighlight (true); }
  2108. void itemDragExit (const SourceDetails&) override { setDropHighlight (false); }
  2109. void itemDropped (const SourceDetails& details) override
  2110. {
  2111. setDropHighlight (false);
  2112. loadGranulizerSample (BrowserComponent::draggedFile (details));
  2113. }
  2114. bool isInterestedInFileDrag (const juce::StringArray& files) override
  2115. {
  2116. return takesSample() && files.size() == 1 && SampleLibrary::isSampleFile (juce::File (files[0]));
  2117. }
  2118. void fileDragEnter (const juce::StringArray&, int, int) override { setDropHighlight (true); }
  2119. void fileDragExit (const juce::StringArray&) override { setDropHighlight (false); }
  2120. void filesDropped (const juce::StringArray& files, int, int) override
  2121. {
  2122. setDropHighlight (false);
  2123. loadGranulizerSample (juce::File (files[0]));
  2124. }
  2125. void paintOverChildren (juce::Graphics& g) override
  2126. {
  2127. if (dropHighlight)
  2128. {
  2129. g.setColour (theme::colour::accent);
  2130. g.drawRect (getLocalBounds(), 2);
  2131. }
  2132. }
  2133. private:
  2134. bool takesSample() const
  2135. {
  2136. const auto* c = ref.get (engine);
  2137. return c != nullptr && projectcontents::pluginWindowTakesSample (c->instrument);
  2138. }
  2139. void setDropHighlight (bool on)
  2140. {
  2141. if (dropHighlight != on)
  2142. {
  2143. dropHighlight = on;
  2144. repaint();
  2145. }
  2146. }
  2147. // the Granulizer plays the new sample with the same settings (FL keeps the knobs and the channel's name)
  2148. // --- round 168q: the displays of the group-D pages ---------------------------------------------------------
  2149. const ChannelDef* channelNow() const { return ref.get (engine); }
  2150. // BeepMap: the bitmap, stretched to the display (red = left, green = right, as the engine reads it)
  2151. void paintBeepMapImage (juce::Graphics& g, juce::Rectangle<float> r)
  2152. {
  2153. const auto* c = channelNow();
  2154. const auto pic = c != nullptr ? beepMapPicture (c->pluginState) : std::nullopt;
  2155. if (! pic || pic->width <= 0 || pic->height <= 0)
  2156. return;
  2157. if (beepMapCacheState != c->pluginState)
  2158. {
  2159. beepMapCacheState = c->pluginState;
  2160. beepMapCache = juce::Image (juce::Image::RGB, pic->width, pic->height, false);
  2161. for (int y = 0; y < pic->height; ++y)
  2162. for (int x = 0; x < pic->width; ++x)
  2163. {
  2164. const auto* px = pic->bgr.data() + 3 * ((std::size_t) y * (std::size_t) pic->width + (std::size_t) x);
  2165. beepMapCache.setPixelAt (x, y, juce::Colour (px[2], px[1], px[0]));
  2166. }
  2167. }
  2168. g.setImageResamplingQuality (juce::Graphics::lowResamplingQuality);
  2169. g.drawImage (beepMapCache, r, juce::RectanglePlacement::stretchToFit);
  2170. g.setImageResamplingQuality (juce::Graphics::mediumResamplingQuality);
  2171. }
  2172. void paintBeepMapFile (juce::Graphics& g, juce::Rectangle<float> r, float f)
  2173. {
  2174. using namespace theme;
  2175. const auto* c = channelNow();
  2176. const auto pic = c != nullptr ? beepMapPicture (c->pluginState) : std::nullopt;
  2177. auto row = r.reduced (4.0f * f);
  2178. const auto w = row.getWidth() / 3.2f;
  2179. const juce::String caps[] = { tr ("Open..."), tr ("Paste") };
  2180. for (int i = 0; i < 2; ++i)
  2181. {
  2182. const auto cell = row.removeFromLeft (w).reduced (2.0f * f, 0.0f);
  2183. skin::button (g, cell, false, false, accent, radius::sm * f);
  2184. g.setColour (colour::textPrimary);
  2185. g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.5f)), true));
  2186. g.drawFittedText (caps[i], cell.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  2187. }
  2188. g.setColour (colour::textSecondary);
  2189. g.setFont (font (juce::jmax (8.0f, 10.0f * f)));
  2190. const auto text = pic ? tr ("{0} × {1} pixels", { juce::String (pic->width), juce::String (pic->height) }) : tr ("No bitmap");
  2191. g.drawFittedText (text, row.reduced (4.0f * f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 2, 0.7f);
  2192. }
  2193. // which button of the BeepMap file row is under `p` (0 open, 1 paste, −1 none)
  2194. int beepMapFileButton (const plugui::LayoutItem& item, juce::Point<float> p) const
  2195. {
  2196. auto row = layoutRect (item).reduced (4.0f * layoutFactor());
  2197. const auto w = row.getWidth() / 3.2f;
  2198. for (int i = 0; i < 2; ++i)
  2199. if (row.removeFromLeft (w).contains (p))
  2200. return i;
  2201. return -1;
  2202. }
  2203. void setBeepMapBitmap (const std::vector<std::uint8_t>& bmp)
  2204. {
  2205. const auto* c = channelNow();
  2206. if (c == nullptr)
  2207. return;
  2208. auto next = beepMapWithBitmap (c->pluginState, bmp);
  2209. if (next.empty())
  2210. {
  2211. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, juce::String ("BeepMap"),
  2212. tr ("BeepMap reads uncompressed 24- or 32-bit BMP pictures at least 3 pixels high."));
  2213. return;
  2214. }
  2215. ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; });
  2216. repaint();
  2217. }
  2218. void beepMapAction (int button)
  2219. {
  2220. if (button == 1) // a BMP file path or the file itself copied in the clipboard
  2221. {
  2222. const juce::File file (juce::SystemClipboard::getTextFromClipboard().trim().unquoted());
  2223. juce::MemoryBlock data;
  2224. if (file.existsAsFile() && file.loadFileAsData (data))
  2225. setBeepMapBitmap (std::vector<std::uint8_t> ((const std::uint8_t*) data.getData(), (const std::uint8_t*) data.getData() + data.getSize()));
  2226. else
  2227. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, juce::String ("BeepMap"), tr ("Copy a .bmp file's path first, or use Open."));
  2228. return;
  2229. }
  2230. chooser = std::make_unique<juce::FileChooser> (tr ("Open a bitmap"), juce::File(), "*.bmp");
  2231. chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  2232. [safe = juce::Component::SafePointer<ModelPanel> (this)] (const juce::FileChooser& fc) {
  2233. juce::MemoryBlock data;
  2234. if (safe == nullptr || ! fc.getResult().loadFileAsData (data))
  2235. return;
  2236. safe->setBeepMapBitmap (std::vector<std::uint8_t> ((const std::uint8_t*) data.getData(),
  2237. (const std::uint8_t*) data.getData() + data.getSize()));
  2238. });
  2239. }
  2240. // Granulizer: the channel's sample (or how to give it one) with the start point
  2241. void paintGranulizerWave (juce::Graphics& g, juce::Rectangle<float> r, float f)
  2242. {
  2243. using namespace theme;
  2244. const auto* c = channelNow();
  2245. const auto path = c != nullptr ? c->samplePath : std::string();
  2246. if (path.empty())
  2247. {
  2248. g.setColour (colour::textSecondary);
  2249. g.setFont (font (juce::jmax (9.0f, 11.0f * f)));
  2250. g.drawFittedText (tr ("Drop a sample here (or on the channel button)"), r.toNearestInt(), juce::Justification::centred, 2, 0.7f);
  2251. return;
  2252. }
  2253. if (path != granulizerPeaksPath)
  2254. {
  2255. granulizerPeaksPath = path;
  2256. granulizerPeaks.clear();
  2257. if (const auto s = engine.getSampleLibrary().load (juce::String::fromUTF8 (path.c_str())))
  2258. {
  2259. const auto n = (std::int64_t) s->left.size();
  2260. constexpr int columns = 400;
  2261. for (int i = 0; i < columns && n > 0; ++i)
  2262. {
  2263. float peak = 0.0f;
  2264. for (auto k = n * i / columns; k < n * (i + 1) / columns; ++k)
  2265. peak = std::max ({ peak, std::fabs (s->left[(std::size_t) k]), s->right.empty() ? 0.0f : std::fabs (s->right[(std::size_t) k]) });
  2266. granulizerPeaks.push_back (std::min (peak, 1.0f));
  2267. }
  2268. }
  2269. }
  2270. if (granulizerPeaks.empty())
  2271. return;
  2272. const auto mid = r.getCentreY();
  2273. juce::Path wave;
  2274. for (int i = 0; i < (int) granulizerPeaks.size(); ++i)
  2275. {
  2276. const auto x = r.getX() + r.getWidth() * (float) i / (float) (granulizerPeaks.size() - 1);
  2277. wave.addRectangle (x, mid - granulizerPeaks[(std::size_t) i] * r.getHeight() * 0.48f, juce::jmax (1.0f, r.getWidth() / (float) granulizerPeaks.size()),
  2278. juce::jmax (1.0f, granulizerPeaks[(std::size_t) i] * r.getHeight() * 0.96f));
  2279. }
  2280. g.setColour (accent.withAlpha (0.65f));
  2281. g.fillPath (wave);
  2282. if (const auto* k = knobFor ("Sample start"))
  2283. {
  2284. const auto x = r.getX() + r.getWidth() * normalised (*k);
  2285. g.setColour (colour::textPrimary);
  2286. g.drawVerticalLine ((int) x, r.getY(), r.getBottom());
  2287. }
  2288. g.setColour (colour::textSecondary);
  2289. g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
  2290. g.drawFittedText (juce::File (juce::String::fromUTF8 (path.c_str())).getFileName(), r.removeFromTop (14.0f * f).toNearestInt(),
  2291. juce::Justification::topLeft, 1, 0.8f);
  2292. }
  2293. // Granulizer: one grain's envelope (attack, hold, release) and the next grain's start, from the knobs
  2294. void paintGranulizerGrains (juce::Graphics& g, juce::Rectangle<float> r, float)
  2295. {
  2296. using namespace theme;
  2297. const auto* att = knobFor ("Grain attack");
  2298. const auto* hold = knobFor ("Grain hold");
  2299. const auto* spacing = knobFor ("Grain spacing");
  2300. if (att == nullptr || hold == nullptr || spacing == nullptr)
  2301. return;
  2302. const auto a = (float) att->getValue(), h = (float) hold->getValue(), sp = (float) spacing->getValue();
  2303. const auto total = juce::jmax (1.0f, 2.0f * a + h + sp);
  2304. const auto xOf = [&] (float t) { return r.getX() + r.getWidth() * t / total; };
  2305. for (int grain = 0; grain < 2; ++grain)
  2306. {
  2307. const auto t0 = (float) grain * sp;
  2308. juce::Path p;
  2309. p.startNewSubPath (xOf (t0), r.getBottom());
  2310. p.lineTo (xOf (t0 + a), r.getY());
  2311. p.lineTo (xOf (t0 + a + h), r.getY());
  2312. p.lineTo (xOf (t0 + 2.0f * a + h), r.getBottom());
  2313. g.setColour ((grain == 0 ? accent : colour::textSecondary).withAlpha (0.8f));
  2314. g.strokePath (p, juce::PathStrokeType (1.5f));
  2315. }
  2316. }
  2317. // Transistor Bass: the current program and its sequence (16 steps: note, gate, accent, slide)
  2318. void paintTransistorBass (juce::Graphics& g, juce::Rectangle<float> r, float f)
  2319. {
  2320. using namespace theme;
  2321. const auto* c = channelNow();
  2322. const auto prog = c != nullptr ? transistorBassProgram (c->pluginState) : std::nullopt;
  2323. if (! prog)
  2324. return;
  2325. g.setColour (colour::textPrimary);
  2326. g.setFont (font (juce::jmax (9.0f, 11.0f * f), true));
  2327. const auto text = tr ("Program {0}", { juce::String (prog->program + 1) }) + " "
  2328. + (prog->sequencer ? tr ("sequencer on") : tr ("sequencer off"))
  2329. + (prog->transpose != 0 ? " " + tr ("transpose {0}", { juce::String (prog->transpose) }) : juce::String());
  2330. g.drawFittedText (text, r.reduced (6.0f * f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.7f);
  2331. }
  2332. // the step numbers under the sequence, lit up to its length (round 168q2)
  2333. void paintTransistorBassSteps (juce::Graphics& g, juce::Rectangle<float> r, float f)
  2334. {
  2335. using namespace theme;
  2336. const auto* c = channelNow();
  2337. const auto prog = c != nullptr ? transistorBassProgram (c->pluginState) : std::nullopt;
  2338. const auto length = prog ? juce::jlimit (1, 16, prog->length) : 16;
  2339. const auto w = r.getWidth() / 16.0f;
  2340. g.setFont (font (juce::jmax (8.0f, 10.0f * f), true));
  2341. for (int i = 0; i < 16; ++i)
  2342. {
  2343. const auto cell = juce::Rectangle<float> (r.getX() + w * (float) i, r.getY(), w, r.getHeight()).reduced (2.0f * f, 4.0f * f);
  2344. const auto in = i < length;
  2345. g.setColour (in ? accent.withAlpha (0.22f) : colour::bg3);
  2346. g.fillRoundedRectangle (cell, radius::sm * f);
  2347. g.setColour (in ? colour::textPrimary : colour::textDisabled);
  2348. g.drawText (juce::String (i + 1), cell, juce::Justification::centred, false);
  2349. }
  2350. }
  2351. static constexpr int transistorBassTools = 3;
  2352. juce::Rectangle<float> transistorBassToolCell (juce::Rectangle<float> r, int i) const
  2353. {
  2354. const auto h = r.getHeight() / (float) transistorBassTools;
  2355. return juce::Rectangle<float> (r.getX(), r.getY() + h * (float) i, r.getWidth(), h).reduced (2.0f * layoutFactor());
  2356. }
  2357. void paintTransistorBassTools (juce::Graphics& g, juce::Rectangle<float> r, float f)
  2358. {
  2359. using namespace theme;
  2360. const juce::String caps[] = { tr ("Clear"), juce::String::fromUTF8 ("Oct +"), juce::String::fromUTF8 ("Oct \xe2\x88\x92") };
  2361. for (int i = 0; i < transistorBassTools; ++i)
  2362. {
  2363. const auto cell = transistorBassToolCell (r, i);
  2364. skin::button (g, cell, false, false, accent, radius::sm * f);
  2365. g.setColour (colour::textPrimary);
  2366. g.setFont (font (juce::jmax (8.0f, juce::jmin (10.0f * f, cell.getHeight() * 0.45f)), true));
  2367. g.drawFittedText (caps[i], cell.toNearestInt(), juce::Justification::centred, 1, 0.6f);
  2368. }
  2369. }
  2370. int transistorBassToolButton (const plugui::LayoutItem& item, juce::Point<float> p) const
  2371. {
  2372. for (int i = 0; i < transistorBassTools; ++i)
  2373. if (transistorBassToolCell (layoutRect (item), i).contains (p))
  2374. return i;
  2375. return -1;
  2376. }
  2377. // FL's CLEAR (gates, slides and accents off, notes C5) and its octave up / down buttons on the whole sequence
  2378. void transistorBassToolAction (int button)
  2379. {
  2380. const auto* c = channelNow();
  2381. if (c == nullptr)
  2382. return;
  2383. auto next = c->pluginState;
  2384. if (! (button == 0 ? transistorBassClearSequence (next) : transistorBassShiftSequence (next, button == 1 ? 1 : -1)))
  2385. return;
  2386. ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; });
  2387. syncKnobs();
  2388. repaint();
  2389. }
  2390. juce::Image beepMapCache;
  2391. std::vector<std::uint8_t> beepMapCacheState;
  2392. std::string granulizerPeaksPath;
  2393. std::vector<float> granulizerPeaks;
  2394. void loadGranulizerSample (const juce::File& file)
  2395. {
  2396. if (! takesSample() || ! file.existsAsFile())
  2397. return;
  2398. if (engine.getSampleLibrary().load (file.getFullPathName()) == nullptr)
  2399. {
  2400. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Sample"), tr ("Could not read {0}", { file.getFileName() }));
  2401. return;
  2402. }
  2403. ref.edit (engine, [path = file.getFullPathName().toStdString()] (ChannelDef& d) { d.samplePath = path; });
  2404. if (sampleButton.isVisible())
  2405. ui::setHint (sampleButton, file.getFullPathName());
  2406. repaint();
  2407. }
  2408. bool dropHighlight = false;
  2409. // Fruity Granulizer: what the keys move (Key to), where the slices come from (Transients), tempo lock and the beat
  2410. // count it uses (REA_rodada165g-flgran165)
  2411. void setupGranulizerModes (const ChannelDef& def)
  2412. {
  2413. const auto keyMode = granulizerMode (def.pluginState, 1), sliceMode = granulizerMode (def.pluginState, 0),
  2414. sync = granulizerMode (def.pluginState, 2);
  2415. if (! keyMode || ! sliceMode || ! sync)
  2416. return;
  2417. granulizerModes = true;
  2418. auto label = [this] (juce::Label& l, const juce::String& text) {
  2419. l.setText (text, juce::dontSendNotification);
  2420. l.setFont (theme::font (theme::type::small));
  2421. addAndMakeVisible (l);
  2422. };
  2423. label (granKeyToLabel, tr ("Key to"));
  2424. granKeyTo.addItem (tr ("Pitch"), 1);
  2425. granKeyTo.addItem (tr ("Percent"), 2);
  2426. granKeyTo.addItem (tr ("Step"), 3);
  2427. granKeyTo.addItem (tr ("Transient"), 4);
  2428. granKeyTo.setSelectedId (std::clamp (*keyMode, 0, 3) + 1, juce::dontSendNotification);
  2429. granKeyTo.setTooltip (tr ("What the keys do: Pitch = transpose; Percent = start point (sample time, C5 to C7); "
  2430. "Step = start point in 16th notes (song time); Transient = start at the slice of the key"));
  2431. granKeyTo.onChange = [this] {
  2432. const auto v = granKeyTo.getSelectedId() - 1;
  2433. ref.edit (engine, [v] (ChannelDef& d) { granulizerSetMode (d.pluginState, 1, v); });
  2434. if (v == 3 && granTransients.getSelectedId() == 1) // as FL: transient keys switch slice detection on
  2435. granTransients.setSelectedId (3, juce::dontSendNotification);
  2436. };
  2437. addAndMakeVisible (granKeyTo);
  2438. label (granTransientsLabel, tr ("Transients"));
  2439. granTransients.addItem (tr ("Off"), 1);
  2440. granTransients.addItem (tr ("Use regions"), 2);
  2441. granTransients.addItem (tr ("Detect"), 3);
  2442. granTransients.setSelectedId (std::clamp (*sliceMode, 0, 2) + 1, juce::dontSendNotification);
  2443. granTransients.setTooltip (tr ("Transients source: the sample's cue points / regions, or FL's automatic slicing. "
  2444. "Grains then line up with the slices and the Transient hold knob sets how long each "
  2445. "slice's first grain holds"));
  2446. granTransients.onChange = [this] {
  2447. const auto v = granTransients.getSelectedId() - 1;
  2448. ref.edit (engine, [v] (ChannelDef& d) { granulizerSetMode (d.pluginState, 0, v); });
  2449. };
  2450. addAndMakeVisible (granTransients);
  2451. granTempoLocked.setButtonText (tr ("Tempo locked"));
  2452. granTempoLocked.setToggleState (*sync != 0, juce::dontSendNotification);
  2453. granTempoLocked.setTooltip (tr ("Match song tempo: the sample plays once per its length in beats (the WAV's ACID "
  2454. "beats, else Beats below). Loop is always on and Wave spacing has no effect while "
  2455. "locked"));
  2456. granTempoLocked.onClick = [this] {
  2457. const auto on = granTempoLocked.getToggleState();
  2458. ref.edit (engine, [on] (ChannelDef& d) { granulizerSetMode (d.pluginState, 2, on ? 1 : 0); });
  2459. };
  2460. addAndMakeVisible (granTempoLocked);
  2461. label (granBeatsLabel, tr ("Beats (0 = the sample's own)"));
  2462. granBeats.setSliderStyle (juce::Slider::LinearHorizontal);
  2463. granBeats.setTextBoxStyle (juce::Slider::TextBoxRight, false, 56, 20);
  2464. granBeats.setRange (0.0, 1024.0, 0.01);
  2465. granBeats.setValue (def.sampler.stretchBeats, juce::dontSendNotification);
  2466. granBeats.setTooltip (tr ("The sample's length in beats for Tempo locked and the Step keys, as FL's time-stretch "
  2467. "TIME; a WAV with ACID beats uses its own"));
  2468. granBeats.onValueChange = [this] {
  2469. const auto v = (float) granBeats.getValue();
  2470. ref.edit (engine, [v] (ChannelDef& d) { d.sampler.stretchBeats = v; });
  2471. };
  2472. addAndMakeVisible (granBeats);
  2473. }
  2474. bool granulizerModes = false;
  2475. juce::ComboBox granKeyTo, granTransients;
  2476. juce::ToggleButton granTempoLocked;
  2477. juce::Slider granBeats;
  2478. juce::Label granKeyToLabel, granTransientsLabel, granBeatsLabel;
  2479. AudioEngine& engine;
  2480. ChannelRef ref;
  2481. juce::Colour accent { skin::colour::crimson }; // the plugin page's accent (ui/PluginSkin.h)
  2482. skin::Style pageStyle = skin::Style::glow; // the plugin page's automatic style (round 126)
  2483. skin::Art pageArt = skin::Art::none; // its own art (round 170j: Themed)
  2484. std::unique_ptr<skin::ArtLayer> artLayer; // the art's moving part (petals, a glowing trefoil...)
  2485. bool sakura = true, boobass = false, drumsynth = false, harmless = false, harmor = false, gms = false, morphine = false, ogun = false, autogun = false, transistorBass = false, miniSynth = false, dx10 = false, kepler = false, keplerExo = false, poizone = false,
  2486. fruitkick = false, bassdrum = false, toxic = false, threeOsc = false, simSynth = false, wasp = false, plucked = false, beepMap = false,
  2487. sawer = false, flKeys = false, granulizer = false, drumaxx = false, slayer = false, fruityDance = false, sytrus = false, wavesFound = false,
  2488. engineFilesMissing = false;
  2489. int editorKey = 60;
  2490. int drumPart = 0; // round 168p: the Drumaxx pad / DrumSynth Live key the per-part knobs edit
  2491. std::vector<std::pair<juce::Slider*, const drumcontrols::Control*>> partKnobs;
  2492. std::vector<std::unique_ptr<juce::Slider>> knobs;
  2493. const plugui::Layout* layout = nullptr;
  2494. const modelparams::Table* modelTable = nullptr; // the engine's listed parameters (round 168n)
  2495. InstrumentKind instrumentKind = InstrumentKind::synth;
  2496. const plugui::LayoutItem* stepperDrag = nullptr; // (round 169h)
  2497. float stepperDragY = 0.0f;
  2498. int stepperDragged = 0;
  2499. int page = 0; // the layout's page shown (pageTabs items switch it; round 168n)
  2500. const plugui::LayoutItem* xyItem = nullptr; // the pad being dragged
  2501. juce::TextButton sampleButton; // (a Granulizer node: round 165c)
  2502. std::unique_ptr<juce::FileChooser> chooser;
  2503. };
  2504. // FL's Sampler › "Precomputed effects", the loop flags and the declicking mode (REA_rodada167h §1–§3): computed once on
  2505. // the sample when the channel changes (core/SamplePrecompute.h). Opened from the Sampler settings.
  2506. class PrecomputePanel final : public juce::Component
  2507. {
  2508. public:
  2509. PrecomputePanel (AudioEngine& e, ChannelRef c) : engine (e), ref (std::move (c))
  2510. {
  2511. const std::pair<juce::ToggleButton*, const char*> toggles[] = {
  2512. { &removeDc, TR_NOOP ("Remove DC offset") }, { &normalize, TR_NOOP ("Normalize") }, { &polarity, TR_NOOP ("Reverse polarity") },
  2513. { &fadeStereo, TR_NOOP ("Fade stereo") }, { &swapStereo, TR_NOOP ("Swap stereo") },
  2514. { &useLoops, TR_NOOP ("Use loop points") }, { &pingPong, TR_NOOP ("Ping pong loop") } };
  2515. for (auto [b, text] : toggles)
  2516. {
  2517. b->setButtonText (tr (text));
  2518. b->onClick = [this] { apply(); };
  2519. addAndMakeVisible (b);
  2520. }
  2521. normalize.setTooltip (tr ("Raises the sample so its loudest point reaches 0 dB"));
  2522. fadeStereo.setTooltip (tr ("The left channel fades out over the sample while the right one fades in"));
  2523. useLoops.setTooltip (tr ("Plays the loop stored in the sample file (WAV loop points)"));
  2524. pingPong.setTooltip (tr ("The loop plays forward, then backward"));
  2525. const std::tuple<juce::Slider*, juce::Label*, const char*, double> knobs[] = {
  2526. { &fadeIn, &fadeInLabel, TR_NOOP ("Fade in"), 1024.0 }, { &fadeOut, &fadeOutLabel, TR_NOOP ("Fade out"), 1024.0 },
  2527. { &crossfade, &crossfadeLabel, TR_NOOP ("Crossfade"), 2048.0 }, { &trim, &trimLabel, TR_NOOP ("Trim"), 32768.0 } };
  2528. for (auto [k, label, text, hi] : knobs)
  2529. {
  2530. k->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  2531. k->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 18);
  2532. k->setRange (0.0, hi, 1.0);
  2533. k->setDoubleClickReturnValue (true, 0.0);
  2534. k->onValueChange = [this] { apply(); };
  2535. addAndMakeVisible (k);
  2536. label->setText (tr (text), juce::dontSendNotification);
  2537. label->setJustificationType (juce::Justification::centred);
  2538. addAndMakeVisible (label);
  2539. }
  2540. auto percent = [] (double hi) { return [hi] (double v) { return juce::String (v / hi * 100.0, 1) + "%"; }; };
  2541. fadeIn.textFromValueFunction = percent (1024.0);
  2542. fadeOut.textFromValueFunction = percent (1024.0);
  2543. crossfade.textFromValueFunction = percent (2048.0);
  2544. trim.textFromValueFunction = [] (double v) {
  2545. return v <= 0.0 ? tr ("Off") : juce::String (20.0 * std::log10 (v / 32768.0), 1) + " dB";
  2546. };
  2547. fadeIn.setTooltip (tr ("Fades the sample in: 25% ramps over the whole sample, 100% over its last quarter"));
  2548. fadeOut.setTooltip (tr ("Fades the sample out: 25% over the whole sample, 100% within its first quarter"));
  2549. crossfade.setTooltip (tr ("Crossfades the loop's end into its start (a share of the loop), for a smooth loop"));
  2550. trim.setTooltip (tr ("Cuts the silence below this level at the sample's start and end"));
  2551. declickLabel.setText (tr ("Declicking mode"), juce::dontSendNotification);
  2552. addAndMakeVisible (declickLabel);
  2553. declick.addItemList ({ tr ("Out only"), tr ("Transient (no bleeding)"), tr ("Transient"), tr ("Generic"), tr ("Smooth"), tr ("Crossfade") }, 1);
  2554. declick.setTooltip (tr ("How fast a cut note fades out: 10 ms (out only, transient no bleeding), 20 ms (transient, generic), 100 ms (smooth), 200 ms (crossfade)"));
  2555. declick.onChange = [this] { apply(); };
  2556. addAndMakeVisible (declick);
  2557. // FL's legacy effects page (REA_rodada167l §1): FL's knob ranges, defaults and hints
  2558. legacyHeader.setText (tr ("Legacy effects"), juce::dontSendNotification);
  2559. legacyHeader.setFont (juce::FontOptions (13.0f, juce::Font::bold));
  2560. addAndMakeVisible (legacyHeader);
  2561. const std::tuple<juce::Slider*, juce::Label*, const char*, const char*, double, double, double> legacy[] = {
  2562. { &boost, &boostLabel, TR_NOOP ("Boost"), TR_NOOP ("Boosts the gain"), 0.0, 256.0, 0.0 },
  2563. { &eq, &eqLabel, TR_NOOP ("EQ"), TR_NOOP ("Shifts the frequency balance"), 0.0, 256.0, 128.0 },
  2564. { &ringMix, &ringMixLabel, TR_NOOP ("RM mix"), TR_NOOP ("Ring modulation mix"), 0.0, 256.0, 0.0 },
  2565. { &ringFreq, &ringFreqLabel, TR_NOOP ("RM freq"), TR_NOOP ("Ring modulation frequency"), 0.0, 256.0, 128.0 },
  2566. { &pogo, &pogoLabel, TR_NOOP ("Pogo"), TR_NOOP ("Pogo effect"), 0.0, 512.0, 256.0 },
  2567. { &cutoff, &cutoffLabel, TR_NOOP ("Cut"), TR_NOOP ("Filter cutoff"), 16.0, 1024.0, 1024.0 },
  2568. { &resonance, &resonanceLabel, TR_NOOP ("Res"), TR_NOOP ("Filter resonance"), 0.0, 640.0, 0.0 },
  2569. { &stereoDelay, &stereoDelayLabel, TR_NOOP ("Stereo delay"), TR_NOOP ("Stereo delay"), 0.0, 4096.0, 2048.0 },
  2570. { &reverbAmount, &reverbLabel, TR_NOOP ("Reverb"), TR_NOOP ("Reverb amount"), 0.0, 256.0, 0.0 } };
  2571. for (auto [k, label, text, hint, lo, hi, def] : legacy)
  2572. {
  2573. k->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  2574. k->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 56, 18);
  2575. k->setRange (lo, hi, 1.0);
  2576. k->setValue (def, juce::dontSendNotification);
  2577. k->setDoubleClickReturnValue (true, def);
  2578. k->setTooltip (tr (hint));
  2579. k->onValueChange = [this] { apply(); };
  2580. addAndMakeVisible (k);
  2581. label->setText (tr (text), juce::dontSendNotification);
  2582. label->setJustificationType (juce::Justification::centred);
  2583. addAndMakeVisible (label);
  2584. }
  2585. reverbType.addItemList ({ tr ("Type 1"), tr ("Type 2") }, 1);
  2586. reverbType.setTooltip (tr ("Reverb type"));
  2587. reverbType.onChange = [this] { apply(); };
  2588. addAndMakeVisible (reverbType);
  2589. clip.setButtonText (tr ("Clip"));
  2590. clip.setTooltip (tr ("Add clipping at 0dB"));
  2591. clip.onClick = [this] { apply(); };
  2592. addAndMakeVisible (clip);
  2593. load();
  2594. setSize (500, 560);
  2595. }
  2596. void resized() override
  2597. {
  2598. auto area = getLocalBounds().reduced (12);
  2599. auto rows = area.removeFromTop (4 * 26);
  2600. auto left = rows.removeFromLeft (rows.getWidth() / 2);
  2601. for (auto* b : { &removeDc, &normalize, &polarity, &fadeStereo })
  2602. b->setBounds (left.removeFromTop (26));
  2603. for (auto* b : { &swapStereo, &useLoops, &pingPong })
  2604. b->setBounds (rows.removeFromTop (26));
  2605. area.removeFromTop (10);
  2606. auto knobRow = area.removeFromTop (110);
  2607. const auto w = knobRow.getWidth() / 4;
  2608. for (auto [k, label] : { std::pair { &fadeIn, &fadeInLabel }, { &fadeOut, &fadeOutLabel }, { &crossfade, &crossfadeLabel }, { &trim, &trimLabel } })
  2609. {
  2610. auto column = knobRow.removeFromLeft (w);
  2611. label->setBounds (column.removeFromTop (18));
  2612. k->setBounds (column);
  2613. }
  2614. area.removeFromTop (12);
  2615. auto row = area.removeFromTop (26);
  2616. declickLabel.setBounds (row.removeFromLeft (140));
  2617. declick.setBounds (row.removeFromLeft (220));
  2618. area.removeFromTop (14);
  2619. legacyHeader.setBounds (area.removeFromTop (20));
  2620. auto layoutRow = [] (juce::Rectangle<int> r, std::initializer_list<std::pair<juce::Slider*, juce::Label*>> knobs) {
  2621. const auto w = r.getWidth() / 5;
  2622. for (auto [k, label] : knobs)
  2623. {
  2624. auto column = r.removeFromLeft (w);
  2625. label->setBounds (column.removeFromTop (18));
  2626. k->setBounds (column);
  2627. }
  2628. return r;
  2629. };
  2630. layoutRow (area.removeFromTop (96), { { &boost, &boostLabel }, { &eq, &eqLabel }, { &ringMix, &ringMixLabel }, { &ringFreq, &ringFreqLabel }, { &pogo, &pogoLabel } });
  2631. area.removeFromTop (6);
  2632. auto last = layoutRow (area.removeFromTop (96), { { &cutoff, &cutoffLabel }, { &resonance, &resonanceLabel }, { &stereoDelay, &stereoDelayLabel }, { &reverbAmount, &reverbLabel } });
  2633. last.removeFromTop (22);
  2634. reverbType.setBounds (last.removeFromTop (24).reduced (4, 0));
  2635. last.removeFromTop (8);
  2636. clip.setBounds (last.removeFromTop (24).reduced (4, 0));
  2637. }
  2638. private:
  2639. void load()
  2640. {
  2641. const auto* c = ref.get (engine);
  2642. if (c == nullptr)
  2643. return;
  2644. const juce::ScopedValueSetter<bool> guard (loading, true);
  2645. const auto& p = c->sampler.precompute;
  2646. removeDc.setToggleState (p.removeDc, juce::dontSendNotification);
  2647. normalize.setToggleState (p.normalize, juce::dontSendNotification);
  2648. polarity.setToggleState (p.reversePolarity, juce::dontSendNotification);
  2649. fadeStereo.setToggleState (p.fadeStereo, juce::dontSendNotification);
  2650. swapStereo.setToggleState (p.swapStereo, juce::dontSendNotification);
  2651. useLoops.setToggleState (c->sampler.useLoopPoints, juce::dontSendNotification);
  2652. pingPong.setToggleState (p.pingPong, juce::dontSendNotification);
  2653. fadeIn.setValue (p.fadeIn, juce::dontSendNotification);
  2654. fadeOut.setValue (p.fadeOut, juce::dontSendNotification);
  2655. crossfade.setValue (p.crossfade, juce::dontSendNotification);
  2656. trim.setValue (p.trim, juce::dontSendNotification);
  2657. boost.setValue (p.boost, juce::dontSendNotification);
  2658. eq.setValue (p.eq, juce::dontSendNotification);
  2659. ringMix.setValue (p.ringMix, juce::dontSendNotification);
  2660. ringFreq.setValue (p.ringFreq, juce::dontSendNotification);
  2661. pogo.setValue (p.pogo, juce::dontSendNotification);
  2662. cutoff.setValue (p.cutoff, juce::dontSendNotification);
  2663. resonance.setValue (p.resonance, juce::dontSendNotification);
  2664. stereoDelay.setValue (p.stereoDelay, juce::dontSendNotification);
  2665. reverbAmount.setValue (p.reverb, juce::dontSendNotification);
  2666. reverbType.setSelectedId (p.reverbType == 0 ? 1 : 2, juce::dontSendNotification);
  2667. clip.setToggleState (p.clip, juce::dontSendNotification);
  2668. declick.setSelectedId (juce::jlimit (0, 5, c->sampler.declickMode) + 1, juce::dontSendNotification);
  2669. }
  2670. void apply()
  2671. {
  2672. if (loading)
  2673. return;
  2674. SamplePrecompute p;
  2675. p.removeDc = removeDc.getToggleState();
  2676. p.normalize = normalize.getToggleState();
  2677. p.reversePolarity = polarity.getToggleState();
  2678. p.fadeStereo = fadeStereo.getToggleState();
  2679. p.swapStereo = swapStereo.getToggleState();
  2680. p.pingPong = pingPong.getToggleState();
  2681. p.fadeIn = (int) fadeIn.getValue();
  2682. p.fadeOut = (int) fadeOut.getValue();
  2683. p.crossfade = (int) crossfade.getValue();
  2684. p.trim = (int) trim.getValue();
  2685. p.boost = (int) boost.getValue();
  2686. p.eq = (int) eq.getValue();
  2687. p.ringMix = (int) ringMix.getValue();
  2688. p.ringFreq = (int) ringFreq.getValue();
  2689. p.pogo = (int) pogo.getValue();
  2690. p.cutoff = (int) cutoff.getValue();
  2691. p.resonance = (int) resonance.getValue();
  2692. p.stereoDelay = (int) stereoDelay.getValue();
  2693. p.reverb = (int) reverbAmount.getValue();
  2694. p.reverbType = reverbType.getSelectedId() == 1 ? 0 : 1;
  2695. p.clip = clip.getToggleState();
  2696. const auto loops = useLoops.getToggleState();
  2697. const auto mode = juce::jlimit (0, 5, declick.getSelectedId() - 1);
  2698. const auto* c = ref.get (engine);
  2699. if (c == nullptr || (c->sampler.precompute == p && c->sampler.useLoopPoints == loops && c->sampler.declickMode == mode))
  2700. return;
  2701. ref.edit (engine, [p, loops, mode] (ChannelDef& d) {
  2702. d.sampler.precompute = p;
  2703. d.sampler.useLoopPoints = loops;
  2704. d.sampler.declickMode = mode;
  2705. });
  2706. }
  2707. AudioEngine& engine;
  2708. ChannelRef ref;
  2709. bool loading = false;
  2710. juce::ToggleButton removeDc, normalize, polarity, fadeStereo, swapStereo, useLoops, pingPong;
  2711. juce::Slider fadeIn, fadeOut, crossfade, trim;
  2712. juce::Label fadeInLabel, fadeOutLabel, crossfadeLabel, trimLabel, declickLabel;
  2713. juce::ComboBox declick;
  2714. juce::Label legacyHeader;
  2715. juce::Slider boost, eq, ringMix, ringFreq, pogo, cutoff, resonance, stereoDelay, reverbAmount;
  2716. juce::Label boostLabel, eqLabel, ringMixLabel, ringFreqLabel, pogoLabel, cutoffLabel, resonanceLabel, stereoDelayLabel, reverbLabel;
  2717. juce::ComboBox reverbType;
  2718. juce::ToggleButton clip;
  2719. };
  2720. class SettingsPanel final : public juce::Component,
  2721. public juce::DragAndDropTarget,
  2722. public juce::FileDragAndDropTarget,
  2723. private juce::ChangeListener,
  2724. private juce::Timer
  2725. {
  2726. public:
  2727. SettingsPanel (AudioEngine& e, ChannelRef c)
  2728. : engine (e),
  2729. ref (std::move (c))
  2730. {
  2731. setup (pitch, pitchLabel, TR_NOOP ("Pitch"), -24.0, 24.0, 0.01, " st");
  2732. pitch.setTooltip (tr ("The sample's pitch in semitones (0.5 = 50 cents). The Piano Roll's keys play it chromatically around its root note (Misc › Root note, C5 by default); right-click the channel › Pitch... for semitones + cents"));
  2733. setup (gain, gainLabel, TR_NOOP ("Gain"), -24.0, 24.0, 0.1, " dB");
  2734. gain.textFromValueFunction = [] (double v) { return (v > 0.04 ? "+" : "") + juce::String (std::abs (v) < 0.05 ? 0.0 : v, 1) + " dB"; };
  2735. gain.valueFromTextFunction = [] (const juce::String& t) { return t.retainCharacters ("+-0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
  2736. gain.setTooltip (tr ("Sample gain: boosts or cuts the sample's level before the channel volume (-24 to +24 dB, double-click = 0 dB)"));
  2737. gain.setValue (0.0, juce::dontSendNotification);
  2738. setup (attack, attackLabel, TR_NOOP ("Attack"), 0.0, 2.0, 0.001, " s");
  2739. setup (release, releaseLabel, TR_NOOP ("Release"), 0.0, 4.0, 0.001, " s");
  2740. setup (decay, decayLabel, TR_NOOP ("Decay"), 0.0, 10.0, 0.001, " s");
  2741. setup (sustain, sustainLabel, TR_NOOP ("Sustain"), 0.0, 1.0, 0.01, "");
  2742. setup (stretch, stretchLabel, TR_NOOP ("Stretch"), 0.0, 1024.0, 0.01, " beats");
  2743. // issue #32 #7: "Fit to tempo" sets exact lengths (16.45 beats for a loop with a tail, 128 for 32 bars); the knob used
  2744. // to round them to 0.25 and cap them at 64, and every other edit in this panel wrote the rounded value back
  2745. stretch.setSkewFactorFromMidPoint (16.0);
  2746. stretch.addMouseListener (&stretchMenu, false);
  2747. setup (regionStart, regionStartLabel, TR_NOOP ("Start"), 0.0, 1.0, 0.001, "");
  2748. setup (regionEnd, regionEndLabel, TR_NOOP ("End"), 0.0, 1.0, 0.001, "");
  2749. setup (cutoff, cutoffLabel, TR_NOOP ("Cutoff"), 20.0, 20000.0, 1.0, " Hz");
  2750. setup (resonance, resonanceLabel, TR_NOOP ("Resonance"), 0.0, 1.0, 0.01, "");
  2751. cutoff.setSkewFactorFromMidPoint (1000.0);
  2752. cutoff.setDoubleClickReturnValue (true, 20000.0);
  2753. cutoff.setTooltip (tr ("Channel filter cutoff (low-pass at maximum with no resonance = off)"));
  2754. filterType.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
  2755. filterType.onChange = [this] { apply(); };
  2756. addAndMakeVisible (filterType);
  2757. modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
  2758. modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
  2759. addAndMakeVisible (modulationButton);
  2760. precomputeButton.setButtonText (tr ("Precomputed effects..."));
  2761. precomputeButton.setTooltip (tr ("FL's precomputed effects: remove DC, normalize, reverse polarity, fades, swap / fade stereo, trim, loop crossfade, loop points and the declicking mode"));
  2762. precomputeButton.onClick = [this] {
  2763. juce::CallOutBox::launchAsynchronously (std::make_unique<PrecomputePanel> (engine, ref), precomputeButton.getScreenBounds(), nullptr);
  2764. };
  2765. addAndMakeVisible (precomputeButton);
  2766. regionEnd.setDoubleClickReturnValue (true, 1.0);
  2767. regionStart.setTooltip (tr ("Where the sample starts playing (fraction of the file)"));
  2768. sustain.setDoubleClickReturnValue (true, 1.0);
  2769. decay.setSkewFactorFromMidPoint (0.5);
  2770. stretch.setTooltip (tr ("0 = off. Otherwise the whole sample lasts this many beats and follows the BPM (by resampling, like FL's Resample mode)"));
  2771. attack.setSkewFactorFromMidPoint (0.2);
  2772. release.setSkewFactorFromMidPoint (0.4);
  2773. release.setTooltip (tr ("0 = the whole sample plays (one-shot), like FL's steps"));
  2774. keepPitch.setButtonText (tr ("Keep length (stretch engine)"));
  2775. keepPitch.setTooltip (tr ("On: the pitch, the fine tune and the keys change the pitch without changing the length, and \"Stretch\" changes the length without changing the pitch (like FL's Stretch modes). Off: resample, pitch and speed change together"));
  2776. keepPitch.onClick = [this] { apply(); };
  2777. addAndMakeVisible (keepPitch);
  2778. stretchMethod.addItem (tr ("General"), 1);
  2779. stretchMethod.addItem (tr ("Drums / transients"), 2);
  2780. stretchMethod.addItem (tr ("Vocal / mono"), 3);
  2781. stretchMethod.setTooltip (tr ("How the stretch keeping pitch is computed: General for full mixes and chords, Drums for loops and percussive sounds (attacks kept sharp), Vocal for a single voice or instrument"));
  2782. stretchMethod.onChange = [this] { apply(); };
  2783. addAndMakeVisible (stretchMethod);
  2784. reverse.setButtonText (tr ("Reverse"));
  2785. cut.setButtonText (tr ("Cut itself"));
  2786. porta.setButtonText ("Porta");
  2787. porta.setTooltip (tr ("Portamento: the note starts from the previous note's pitch (with Cut itself, the 808 glide)"));
  2788. cut.setTooltip (tr ("A new note cuts the previous one (good for hi-hats and 808s)"));
  2789. for (auto* b : { &reverse, &cut, &porta })
  2790. {
  2791. addAndMakeVisible (b);
  2792. b->onClick = [this] { apply(); };
  2793. }
  2794. // the knobs an automation clip can drive (samplerparam, issue #12): right-click = FL's parameter menu; a move
  2795. // is a tweak (Last tweaked, automation recording)
  2796. for (auto [slider, param] : { std::pair { &attack, (int) samplerparam::attack }, { &decay, (int) samplerparam::decay },
  2797. { &sustain, (int) samplerparam::sustain }, { &release, (int) samplerparam::release },
  2798. { &cutoff, (int) samplerparam::cutoff }, { &resonance, (int) samplerparam::resonance },
  2799. { &regionStart, (int) samplerparam::start }, { &regionEnd, (int) samplerparam::end } })
  2800. {
  2801. if (ref.index < 0) // (a Patcher node: no automation target)
  2802. break;
  2803. const auto target = [this, param] { return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, param }; };
  2804. // one menu, FL's parameter menu (the slider contract's plain value menu used to open beside it)
  2805. ui::setOwnMenu (*slider);
  2806. slider->onMenu = [this, slider, target] { ui::showSliderMenu (*slider, &engine, target()); };
  2807. slider->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
  2808. slider->onDragEnd = [this, target] { engine.tweakReleased (target()); };
  2809. tweakTargets.push_back ({ slider, param });
  2810. }
  2811. wave.setEmptyText (tr ("No sample loaded"));
  2812. wave.setTooltip (tr ("The sample: colours show where it is bass-heavy (warm) or bright (cool); outside Start/End is dimmed"));
  2813. addAndMakeVisible (wave);
  2814. refresh();
  2815. engine.addChangeListener (this);
  2816. setSize (420, 676);
  2817. if (ref.index >= 0)
  2818. startTimerHz (30); // the knobs follow their automation while the song plays (issue #12)
  2819. }
  2820. ~SettingsPanel() override { engine.removeChangeListener (this); }
  2821. void resized() override
  2822. {
  2823. auto area = getLocalBounds().reduced (12);
  2824. wave.setBounds (area.removeFromTop (92));
  2825. area.removeFromTop (8);
  2826. auto place = [] (juce::Rectangle<int> row, std::initializer_list<std::pair<juce::Slider*, juce::Label*>> items) {
  2827. const auto w = row.getWidth() / 3;
  2828. for (auto [slider, label] : items)
  2829. {
  2830. auto column = row.removeFromLeft (w);
  2831. label->setBounds (column.removeFromTop (18));
  2832. slider->setBounds (column);
  2833. }
  2834. };
  2835. auto top = area.removeFromTop (110);
  2836. {
  2837. // Gain, Pitch, Stretch and the keep-pitch switch (a third of the width: its text is long)
  2838. const auto w4 = top.getWidth() * 2 / 9;
  2839. for (auto [slider, label] : { std::pair { &gain, &gainLabel }, { &pitch, &pitchLabel }, { &stretch, &stretchLabel } })
  2840. {
  2841. auto column = top.removeFromLeft (w4);
  2842. label->setBounds (column.removeFromTop (18));
  2843. slider->setBounds (column);
  2844. }
  2845. auto column = top.withSizeKeepingCentre (juce::jmin (top.getWidth(), 140), juce::jmin (top.getHeight(), 64));
  2846. keepPitch.setBounds (column.removeFromTop (column.getHeight() / 2));
  2847. stretchMethod.setBounds (column.withSizeKeepingCentre (column.getWidth(), juce::jmin (column.getHeight(), 24)));
  2848. }
  2849. area.removeFromTop (6);
  2850. auto envelope = area.removeFromTop (110);
  2851. const auto w = envelope.getWidth() / 4;
  2852. for (auto [slider, label] : { std::pair { &attack, &attackLabel }, { &decay, &decayLabel }, { &sustain, &sustainLabel }, { &release, &releaseLabel } })
  2853. {
  2854. auto column = envelope.removeFromLeft (w);
  2855. label->setBounds (column.removeFromTop (18));
  2856. slider->setBounds (column);
  2857. }
  2858. area.removeFromTop (8);
  2859. area.removeFromTop (6);
  2860. place (area.removeFromTop (110), { { &regionStart, &regionStartLabel }, { &regionEnd, &regionEndLabel } });
  2861. area.removeFromTop (6);
  2862. {
  2863. auto filterRow = area.removeFromTop (110);
  2864. filterType.setBounds (filterRow.removeFromRight (filterRow.getWidth() / 3).withSizeKeepingCentre (124, 24));
  2865. place (filterRow.withWidth (filterRow.getWidth() * 3 / 2), { { &cutoff, &cutoffLabel }, { &resonance, &resonanceLabel } });
  2866. }
  2867. {
  2868. auto buttons = area.removeFromBottom (26);
  2869. const auto half = buttons.getWidth() / 2;
  2870. modulationButton.setBounds (buttons.removeFromLeft (half).reduced (4, 0));
  2871. precomputeButton.setBounds (buttons.reduced (4, 0));
  2872. }
  2873. area.removeFromTop (6);
  2874. reverse.setBounds (area.removeFromLeft (150).removeFromTop (24));
  2875. cut.setBounds (area.removeFromLeft (130).removeFromTop (24));
  2876. porta.setBounds (area.removeFromLeft (100).removeFromTop (24));
  2877. }
  2878. int getChannel() const noexcept { return ref.index; }
  2879. // A sample dropped on the waveform (from the Browser or the system) replaces the channel's sample (issue #12)
  2880. bool isInterestedInDragSource (const SourceDetails& details) override
  2881. {
  2882. return BrowserComponent::isBrowserDrag (details) && SampleLibrary::isSampleFile (BrowserComponent::draggedFile (details));
  2883. }
  2884. void itemDragEnter (const SourceDetails&) override { setDropHighlight (true); }
  2885. void itemDragExit (const SourceDetails&) override { setDropHighlight (false); }
  2886. void itemDropped (const SourceDetails& details) override
  2887. {
  2888. setDropHighlight (false);
  2889. replaceSample (BrowserComponent::draggedFile (details));
  2890. }
  2891. bool isInterestedInFileDrag (const juce::StringArray& files) override
  2892. {
  2893. return files.size() == 1 && SampleLibrary::isSampleFile (juce::File (files[0]));
  2894. }
  2895. void fileDragEnter (const juce::StringArray&, int, int) override { setDropHighlight (true); }
  2896. void fileDragExit (const juce::StringArray&) override { setDropHighlight (false); }
  2897. void filesDropped (const juce::StringArray& files, int, int) override
  2898. {
  2899. setDropHighlight (false);
  2900. replaceSample (juce::File (files[0]));
  2901. }
  2902. void paintOverChildren (juce::Graphics& g) override
  2903. {
  2904. if (dropHighlight)
  2905. {
  2906. g.setColour (theme::colour::accent);
  2907. g.drawRect (wave.getBounds().expanded (2), 2);
  2908. }
  2909. }
  2910. private:
  2911. void setDropHighlight (bool on)
  2912. {
  2913. if (dropHighlight != on)
  2914. {
  2915. dropHighlight = on;
  2916. repaint (wave.getBounds().expanded (4));
  2917. }
  2918. }
  2919. // the new sample plays with the same settings; slices of the old one no longer apply, the channel takes its name
  2920. void replaceSample (const juce::File& file)
  2921. {
  2922. if (current() == nullptr || ! file.existsAsFile())
  2923. return;
  2924. if (engine.getSampleLibrary().load (file.getFullPathName()) == nullptr)
  2925. {
  2926. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Sample"), tr ("Could not read {0}", { file.getFileName() }));
  2927. return;
  2928. }
  2929. ref.edit (engine, [path = file.getFullPathName().toStdString(), name = file.getFileNameWithoutExtension().toStdString()] (ChannelDef& d) {
  2930. d.samplePath = path;
  2931. d.zones.clear();
  2932. d.sampler.slices.clear();
  2933. d.name = name;
  2934. });
  2935. }
  2936. void setup (juce::Slider& s, juce::Label& label, const char* name, double lo, double hi, double step, const char* suffix)
  2937. {
  2938. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  2939. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 18);
  2940. s.setRange (lo, hi, step);
  2941. s.setTextValueSuffix (suffix);
  2942. s.setDoubleClickReturnValue (true, 0.0);
  2943. s.onValueChange = [this, &s] { apply (&s); };
  2944. label.setText (tr (name), juce::dontSendNotification);
  2945. label.setJustificationType (juce::Justification::centred);
  2946. addAndMakeVisible (s);
  2947. addAndMakeVisible (label);
  2948. }
  2949. const ChannelDef* current() const
  2950. {
  2951. return ref.get (engine);
  2952. }
  2953. void refresh()
  2954. {
  2955. if (const auto* c = current())
  2956. {
  2957. updating = true;
  2958. pitch.setValue (c->sampler.pitch, juce::dontSendNotification);
  2959. gain.setValue (c->sampler.gainDb, juce::dontSendNotification);
  2960. attack.setValue (c->sampler.attack, juce::dontSendNotification);
  2961. decay.setValue (c->sampler.decay, juce::dontSendNotification);
  2962. sustain.setValue (c->sampler.sustain, juce::dontSendNotification);
  2963. stretch.setValue (c->sampler.stretchBeats, juce::dontSendNotification);
  2964. shownStretch = stretch.getValue();
  2965. keepPitch.setToggleState (c->sampler.keepPitch, juce::dontSendNotification);
  2966. stretchMethod.setSelectedId ((int) c->sampler.stretchMethod + 1, juce::dontSendNotification);
  2967. stretchMethod.setEnabled (c->sampler.keepPitch);
  2968. regionStart.setValue (c->sampler.regionStart, juce::dontSendNotification);
  2969. regionEnd.setValue (c->sampler.regionEnd, juce::dontSendNotification);
  2970. cutoff.setValue (c->sampler.cutoff, juce::dontSendNotification);
  2971. resonance.setValue (c->sampler.resonance, juce::dontSendNotification);
  2972. filterType.setSelectedId (c->sampler.filterType + 1, juce::dontSendNotification);
  2973. release.setValue (c->sampler.release, juce::dontSendNotification);
  2974. reverse.setToggleState (c->sampler.reverse, juce::dontSendNotification);
  2975. cut.setToggleState (c->sampler.cut, juce::dontSendNotification);
  2976. porta.setToggleState (c->sampler.porta, juce::dontSendNotification);
  2977. updating = false;
  2978. showAutomation (true);
  2979. const auto path = juce::String::fromUTF8 ((c->samplePath.empty() && ! c->zones.empty() ? c->zones.front().path : c->samplePath).c_str());
  2980. wave.setFile (path, [&e = engine, path] { return e.getSampleLibrary().load (path); });
  2981. wave.setRegion (c->sampler.regionStart, c->sampler.regionEnd);
  2982. wave.setReversed (c->sampler.reverse);
  2983. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  2984. w->setName (tr ("Sampler settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) })
  2985. + (c->zones.empty() ? juce::String() : tr (" (multi-sample: {0} zones)", { juce::String ((int) c->zones.size()) })));
  2986. }
  2987. }
  2988. // The knobs an automation drives show its value while the song plays, as in FL (issue #12); a knob held by the
  2989. // mouse shows the hand's value. `force`: after refresh() put the Song's values back.
  2990. void showAutomation (bool force)
  2991. {
  2992. const auto* c = current();
  2993. if (c == nullptr || ref.index < 0)
  2994. return;
  2995. const auto& shown = engine.getAutomationDisplay();
  2996. if (! force && shown.getGeneration() == shownGeneration)
  2997. return;
  2998. shownGeneration = shown.getGeneration();
  2999. if (! force && automatedShown.empty() && ! shown.any())
  3000. return;
  3001. std::vector<juce::Slider*> now;
  3002. updating = true;
  3003. for (const auto& [slider, param] : tweakTargets)
  3004. {
  3005. if (slider->isMouseButtonDown())
  3006. continue;
  3007. const auto v = shown.valueOf ({ AutomationTargetKind::channelParam, ref.index, 0, param });
  3008. const auto was = std::find (automatedShown.begin(), automatedShown.end(), slider) != automatedShown.end();
  3009. if (v)
  3010. {
  3011. slider->setValue (samplerparam::toNatural (param, *v), juce::dontSendNotification);
  3012. now.push_back (slider);
  3013. }
  3014. else if (was && ! force)
  3015. slider->setValue (samplerparam::toNatural (param, samplerparam::get (c->sampler, param)), juce::dontSendNotification);
  3016. }
  3017. updating = false;
  3018. automatedShown = std::move (now);
  3019. wave.setRegion ((float) regionStart.getValue(), (float) regionEnd.getValue());
  3020. }
  3021. void timerCallback() override
  3022. {
  3023. if (isShowing())
  3024. showAutomation (false);
  3025. }
  3026. // the Song's value of `param` (a knob that shows its automation must not write the automated value back)
  3027. static void keepSongValue (SamplerSettings& s, const SamplerSettings& song, int param) noexcept
  3028. {
  3029. switch (param)
  3030. {
  3031. case samplerparam::attack: s.attack = song.attack; break;
  3032. case samplerparam::decay: s.decay = song.decay; break;
  3033. case samplerparam::sustain: s.sustain = song.sustain; break;
  3034. case samplerparam::release: s.release = song.release; break;
  3035. case samplerparam::cutoff: s.cutoff = song.cutoff; break;
  3036. case samplerparam::resonance: s.resonance = song.resonance; break;
  3037. case samplerparam::start: s.regionStart = song.regionStart; break;
  3038. case samplerparam::end: s.regionEnd = song.regionEnd; break;
  3039. default: break;
  3040. }
  3041. }
  3042. void apply (juce::Slider* changed = nullptr)
  3043. {
  3044. if (updating || current() == nullptr)
  3045. return;
  3046. auto s = current()->sampler; // keeps what the panel does not show (slices)
  3047. s.pitch = (float) pitch.getValue();
  3048. s.gainDb = std::abs (gain.getValue()) < 0.05 ? 0.0f : (float) gain.getValue();
  3049. s.attack = (float) attack.getValue();
  3050. s.decay = (float) decay.getValue();
  3051. s.sustain = (float) sustain.getValue();
  3052. if (changed == &stretch || stretch.getValue() != shownStretch) // (unmoved: keep the exact value, not the knob's)
  3053. s.stretchBeats = (float) (shownStretch = stretch.getValue());
  3054. s.keepPitch = keepPitch.getToggleState();
  3055. s.stretchMethod = (StretchMethod) juce::jlimit (0, 2, stretchMethod.getSelectedId() - 1);
  3056. stretchMethod.setEnabled (s.keepPitch);
  3057. s.regionStart = (float) regionStart.getValue();
  3058. s.regionEnd = (float) regionEnd.getValue();
  3059. s.release = (float) release.getValue();
  3060. s.reverse = reverse.getToggleState();
  3061. s.cut = cut.getToggleState();
  3062. s.porta = porta.getToggleState();
  3063. s.cutoff = (float) cutoff.getValue();
  3064. s.resonance = (float) resonance.getValue();
  3065. s.filterType = juce::jlimit (0, 3, filterType.getSelectedId() - 1);
  3066. for (const auto& [slider, param] : tweakTargets)
  3067. if (slider != changed && std::find (automatedShown.begin(), automatedShown.end(), slider) != automatedShown.end())
  3068. keepSongValue (s, current()->sampler, param);
  3069. {
  3070. // an ADSR edited by hand replaces FL's imported volume envelope
  3071. const auto& old = current()->sampler;
  3072. auto moved = [] (float a, float b) { return std::abs (a - b) > 1.0e-4f; };
  3073. const auto adsr = moved (s.attack, old.attack) || moved (s.decay, old.decay) || moved (s.sustain, old.sustain) || moved (s.release, old.release);
  3074. if (adsr)
  3075. s.flVolumeEnvelope.clear();
  3076. // so does an edited envelope or filter for FL's whole sampler voice (REA_rodada76)
  3077. if (adsr || moved (s.cutoff, old.cutoff) || moved (s.resonance, old.resonance) || s.filterType != old.filterType)
  3078. s.flChannel.clear();
  3079. }
  3080. if (s == current()->sampler)
  3081. return;
  3082. const auto before = current()->sampler;
  3083. ref.edit (engine, [s] (ChannelDef& channelDef) { channelDef.sampler = s; });
  3084. for (const auto& [slider, param] : tweakTargets)
  3085. if (std::abs (samplerparam::get (before, param) - samplerparam::get (s, param)) > 1.0e-6f)
  3086. engine.noteTweaked ({ AutomationTargetKind::channelParam, ref.index, 0, param });
  3087. }
  3088. void changeListenerCallback (juce::ChangeBroadcaster*) override
  3089. {
  3090. if (current() == nullptr) // channel removed
  3091. {
  3092. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  3093. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
  3094. if (safe != nullptr)
  3095. safe->closeButtonPressed();
  3096. });
  3097. return;
  3098. }
  3099. refresh();
  3100. }
  3101. AudioEngine& engine;
  3102. ChannelRef ref;
  3103. bool updating = false;
  3104. juce::Slider pitch, gain, stretch;
  3105. double shownStretch = 0.0;
  3106. // FL's TIME knob menu (r168s c_f20): (none), Autodetect, Project tempo, 1 beat, 2 beats, 1 bar, 2 bars, 3 bars, 4 bars
  3107. struct StretchMenu final : juce::MouseListener
  3108. {
  3109. explicit StretchMenu (SettingsPanel& p) : panel (p) {}
  3110. void mouseDown (const juce::MouseEvent& e) override
  3111. {
  3112. if (e.mods.isPopupMenu())
  3113. panel.showStretchMenu();
  3114. }
  3115. SettingsPanel& panel;
  3116. } stretchMenu { *this };
  3117. void showStretchMenu()
  3118. {
  3119. const auto* c = current();
  3120. if (c == nullptr)
  3121. return;
  3122. const auto& song = engine.getSong();
  3123. const auto sample = engine.getSampleLibrary().load (juce::String::fromUTF8 (c->samplePath.c_str()));
  3124. const auto now = c->sampler.stretchBeats;
  3125. auto set = [this] (float beats) { ref.edit (engine, [beats] (ChannelDef& d) { d.sampler.stretchBeats = beats; }); };
  3126. juce::PopupMenu m;
  3127. m.addItem (tr ("(none)"), true, now <= 0.0f, [set] { set (0.0f); });
  3128. m.addItem (tr ("Autodetect"), sample != nullptr, false, [set, sample, bpm = song.bpm] { set (tempodetect::fitBeatsOf (sample.get(), bpm)); });
  3129. const auto atTempo = sample != nullptr && sample->sampleRate > 0.0 ? (float) ((double) sample->frames() / sample->sampleRate * song.bpm / 60.0) : 0.0f;
  3130. m.addItem (tr ("Project tempo"), atTempo > 0.0f, false, [set, atTempo] { set (atTempo); });
  3131. for (const auto preset : clipops::timePresetBeats (song.beatsPerBar))
  3132. {
  3133. const auto bars = song.beatsPerBar > 0 && preset >= (float) song.beatsPerBar ? preset / (float) song.beatsPerBar : 0.0f;
  3134. const auto label = bars > 0.0f ? (bars == 1.0f ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars, 0) }))
  3135. : (preset == 1.0f ? tr ("1 beat") : tr ("{0} beats", { juce::String (preset, 0) }));
  3136. m.addItem (label, true, now == preset, [set, preset] { set (preset); });
  3137. }
  3138. m.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&stretch));
  3139. }
  3140. MenuSlider attack, release, decay, sustain, regionStart, regionEnd, cutoff, resonance;
  3141. std::vector<std::pair<MenuSlider*, int>> tweakTargets; // knob -> samplerparam
  3142. std::vector<juce::Slider*> automatedShown; // knobs showing their automation's value now
  3143. std::uint32_t shownGeneration = 0;
  3144. bool dropHighlight = false;
  3145. juce::Label pitchLabel, gainLabel, attackLabel, releaseLabel, decayLabel, sustainLabel, stretchLabel, regionStartLabel, regionEndLabel,
  3146. cutoffLabel, resonanceLabel;
  3147. juce::ToggleButton reverse, cut, keepPitch, porta;
  3148. juce::ComboBox filterType, stretchMethod;
  3149. juce::TextButton modulationButton, precomputeButton;
  3150. ui::WaveformDisplay wave;
  3151. };
  3152. // Built-in synth page: 3 oscillators, envelope and filter.
  3153. class SynthPanel final : public juce::Component,
  3154. private juce::ChangeListener
  3155. {
  3156. public:
  3157. SynthPanel (AudioEngine& e, ChannelRef c)
  3158. : engine (e),
  3159. ref (std::move (c))
  3160. {
  3161. for (int o = 0; o < 3; ++o)
  3162. {
  3163. auto& row = rows[(std::size_t) o];
  3164. row.title.setText (tr ("Osc {0}", { juce::String (o + 1) }), juce::dontSendNotification);
  3165. row.wave.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Saw"), tr ("Square"), tr ("Noise"), tr ("Harmonics") }, 1);
  3166. row.wave.onChange = [this] { apply(); };
  3167. knob (row.octave, -3.0, 3.0, 1.0, " oct");
  3168. knob (row.semitones, -11.0, 11.0, 1.0, " st");
  3169. knob (row.detune, -100.0, 100.0, 1.0, " ct");
  3170. knob (row.pan, -1.0, 1.0, 0.01, "");
  3171. knob (row.level, 0.0, 4.0, 0.01, "");
  3172. row.level.setSkewFactorFromMidPoint (1.0); // above 1: gain (Harmor goes up to +12 dB)
  3173. addAndMakeVisible (row.title);
  3174. addAndMakeVisible (row.wave);
  3175. }
  3176. knob (attack, 0.0, 5.0, 0.001, " s");
  3177. knob (decay, 0.0, 5.0, 0.001, " s");
  3178. knob (sustain, 0.0, 1.0, 0.01, "");
  3179. knob (release, 0.0, 5.0, 0.001, " s");
  3180. knob (cutoff, 20.0, 20000.0, 1.0, " Hz");
  3181. knob (resonance, 0.0, 1.0, 0.01, "");
  3182. knob (fm, 0.0, 8.0, 0.01, "");
  3183. fm.setSkewFactorFromMidPoint (1.0);
  3184. fm.setTooltip (tr ("FM: osc 3 (which stops sounding) modulates the phase of osc 1 and 2; 0 = off"));
  3185. knob (fmDecay, 0.0, 5.0, 0.001, " s");
  3186. fmDecay.setSkewFactorFromMidPoint (0.5);
  3187. fmDecay.setTooltip (tr ("Time for the FM index to decay (0 = constant); the brightness fades like an electric piano"));
  3188. knob (keyTrack, -1.0, 2.0, 0.01, "");
  3189. keyTrack.setTooltip (tr ("Cutoff follows the note: cutoff octaves per note octave, relative to C3 (130.8 Hz)"));
  3190. knob (sweep, 0.0, 100.0, 0.01, "");
  3191. sweep.setSkewFactorFromMidPoint (2.0);
  3192. sweep.setTooltip (tr ("Kick pitch sweep: the note starts (1 + value) times higher and falls"));
  3193. knob (sweepTime, 0.001, 2.0, 0.001, " s");
  3194. sweepTime.setSkewFactorFromMidPoint (0.1);
  3195. sweepTime.setTooltip (tr ("Sweep time constant"));
  3196. for (auto* b : { &bandLow, &bandMid, &bandHigh })
  3197. {
  3198. knob (*b, 0.0, 2.0, 0.01, "");
  3199. b->setTooltip (tr ("3-band tone after the filter (low < 178 Hz < mid < 1.18 kHz < high); 1 = unchanged"));
  3200. }
  3201. ring.setButtonText (tr ("Ring"));
  3202. ring.setTooltip (tr ("With AM on: ring modulation, (osc 1 + 2) × (1 − level + osc 3), like Sytrus's RM"));
  3203. ring.onClick = [this] { apply(); };
  3204. addAndMakeVisible (ring);
  3205. modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
  3206. modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
  3207. addAndMakeVisible (modulationButton);
  3208. for (auto* s : { &attack, &decay, &release })
  3209. s->setSkewFactorFromMidPoint (0.5);
  3210. cutoff.setSkewFactorFromMidPoint (1000.0);
  3211. const char* names[] = { TR_NOOP ("Octave"), TR_NOOP ("Semitone"), TR_NOOP ("Fine"), TR_NOOP ("Pan"), TR_NOOP ("Level"), TR_NOOP ("Attack"), TR_NOOP ("Decay"), TR_NOOP ("Sustain"), TR_NOOP ("Release"), TR_NOOP ("Cutoff"), TR_NOOP ("Resonance"), TR_NOOP ("Porta time"), TR_NOOP ("FM"), TR_NOOP ("FM decay"),
  3212. TR_NOOP ("Keytrack"), TR_NOOP ("Sweep"), TR_NOOP ("Sweep time"), TR_NOOP ("Low"), TR_NOOP ("Mid"), TR_NOOP ("High") };
  3213. for (int i = 0; i < (int) labels.size(); ++i)
  3214. {
  3215. labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
  3216. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  3217. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  3218. addAndMakeVisible (labels[(std::size_t) i]);
  3219. }
  3220. presetBox.setTextWhenNothingSelected (tr ("Presets..."));
  3221. const auto presets = synthPresets();
  3222. for (int i = 0; i < (int) presets.size(); ++i)
  3223. presetBox.addItem (juce::String::fromUTF8 (presets[(std::size_t) i].first.c_str()), i + 1);
  3224. presetBox.onChange = [this] {
  3225. const auto presets = synthPresets();
  3226. const auto index = presetBox.getSelectedId() - 1;
  3227. if (juce::isPositiveAndBelow (index, (int) presets.size()) && current() != nullptr)
  3228. ref.edit (engine, [s = presets[(std::size_t) index].second] (ChannelDef& channelDef) { channelDef.synth = s; });
  3229. presetBox.setSelectedId (0, juce::dontSendNotification);
  3230. };
  3231. addAndMakeVisible (presetBox);
  3232. flPresets.setButtonText (tr ("FL presets..."));
  3233. flPresets.setTooltip (tr ("The 3x Osc channel presets that ship with FL Studio (Patches\\Channel presets\\3x Osc)"));
  3234. flPresets.onClick = [this] { showFlPresets(); };
  3235. addAndMakeVisible (flPresets);
  3236. filterTypeBox.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
  3237. filterTypeBox.setTooltip (tr ("Filter type"));
  3238. filterTypeBox.onChange = [this] { apply(); };
  3239. addAndMakeVisible (filterTypeBox);
  3240. am.setButtonText ("AM");
  3241. am.setTooltip (tr ("Osc 3 modulates the amplitude of osc 1 and 2 (like 3x Osc's AM); its level is the depth"));
  3242. am.onClick = [this] { apply(); };
  3243. addAndMakeVisible (am);
  3244. knob (porta, 0.0, 2.0, 0.005, " t");
  3245. porta.setSkewFactorFromMidPoint (0.25);
  3246. porta.setTooltip (tr ("Portamento time, in beats (applies to the Porta button and to notes marked porta)"));
  3247. portaOn.setButtonText ("Porta");
  3248. portaOn.setTooltip (tr ("Portamento: the new note glides from the previous one (notes marked porta invert this)"));
  3249. portaOn.onClick = [this] { apply(); };
  3250. addAndMakeVisible (portaOn);
  3251. mono.setButtonText ("Mono");
  3252. mono.setTooltip (tr ("Single voice: the new note takes over the one currently sounding (basses and leads)"));
  3253. mono.onClick = [this] { apply(); };
  3254. addAndMakeVisible (mono);
  3255. refresh();
  3256. engine.addChangeListener (this);
  3257. setSize (720, 510);
  3258. }
  3259. ~SynthPanel() override { engine.removeChangeListener (this); }
  3260. int getChannel() const noexcept { return ref.index; }
  3261. void paint (juce::Graphics& g) override // round 170j: the art's canvas behind the controls
  3262. {
  3263. const skin::StyleScope styleScope (skin::resolve (skin::Style::themed, skin::Art::lynxSynth), skin::Art::lynxSynth);
  3264. skin::canvas (g, getLocalBounds().toFloat(), skin::artAccent (skin::Art::lynxSynth));
  3265. }
  3266. void resized() override
  3267. {
  3268. auto area = getLocalBounds().reduced (10);
  3269. auto topRow = area.removeFromTop (24);
  3270. presetBox.setBounds (topRow.removeFromLeft (200));
  3271. mono.setBounds (topRow.removeFromLeft (90).withTrimmedLeft (16));
  3272. am.setBounds (topRow.removeFromLeft (52));
  3273. ring.setBounds (topRow.removeFromLeft (60));
  3274. flPresets.setBounds (topRow.removeFromLeft (130).reduced (4, 0));
  3275. portaOn.setBounds (topRow.removeFromLeft (70));
  3276. filterTypeBox.setBounds (topRow.removeFromRight (140));
  3277. area.removeFromTop (6);
  3278. auto header = area.removeFromTop (16);
  3279. header.removeFromLeft (150);
  3280. for (int i = 0; i < oscKnobs; ++i)
  3281. labels[(std::size_t) i].setBounds (header.removeFromLeft (88));
  3282. for (auto& row : rows)
  3283. {
  3284. auto line = area.removeFromTop (64);
  3285. row.title.setBounds (line.removeFromLeft (50).withSizeKeepingCentre (50, 24));
  3286. row.wave.setBounds (line.removeFromLeft (100).withSizeKeepingCentre (96, 24));
  3287. for (auto* s : { &row.octave, &row.semitones, &row.detune, &row.pan, &row.level })
  3288. s->setBounds (line.removeFromLeft (88));
  3289. }
  3290. area.removeFromTop (10);
  3291. auto names = area.removeFromTop (16);
  3292. const auto w = area.getWidth() / 9;
  3293. for (int i = oscKnobs; i < oscKnobs + 9; ++i)
  3294. labels[(std::size_t) i].setBounds (names.removeFromLeft (w));
  3295. auto knobsRow = area.removeFromTop (80);
  3296. for (auto* s : { &attack, &decay, &sustain, &release, &cutoff, &resonance, &porta, &fm, &fmDecay })
  3297. s->setBounds (knobsRow.removeFromLeft (w));
  3298. area.removeFromTop (6);
  3299. auto names2 = area.removeFromTop (16);
  3300. for (int i = oscKnobs + 9; i < (int) labels.size(); ++i)
  3301. labels[(std::size_t) i].setBounds (names2.removeFromLeft (w));
  3302. auto knobsRow2 = area.removeFromTop (80);
  3303. for (auto* s : { &keyTrack, &sweep, &sweepTime, &bandLow, &bandMid, &bandHigh })
  3304. s->setBounds (knobsRow2.removeFromLeft (w));
  3305. area.removeFromTop (12);
  3306. modulationButton.setBounds (area.removeFromTop (26).withSizeKeepingCentre (260, 26));
  3307. }
  3308. private:
  3309. struct Row
  3310. {
  3311. juce::Label title;
  3312. juce::ComboBox wave;
  3313. juce::Slider octave, semitones, detune, pan, level;
  3314. };
  3315. static constexpr int oscKnobs = 5; // oscillator knob labels come first
  3316. juce::TextButton modulationButton;
  3317. juce::ToggleButton mono, am, portaOn;
  3318. juce::TextButton flPresets;
  3319. // menu with the presets from the FL install for the synths LYNX converts: the 3x Osc channel .fst
  3320. // files (by letter) and, per generator, the "Plugin presets" folders (Sytrus, Harmor, GMS...)
  3321. void showFlPresets()
  3322. {
  3323. const auto roots = findFlStudioRoots();
  3324. const auto patches = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches");
  3325. auto sorted = [] (juce::Array<juce::File> files) {
  3326. std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
  3327. return a.getFileName().compareNatural (b.getFileName()) < 0;
  3328. });
  3329. return files;
  3330. };
  3331. juce::PopupMenu menu;
  3332. // 3x Osc: ~170 presets grouped by first letter
  3333. {
  3334. juce::PopupMenu threeOsc, sub;
  3335. juce::juce_wchar letter = 0;
  3336. for (const auto& f : sorted (patches.getChildFile ("Channel presets/3x Osc").findChildFiles (juce::File::findFiles, false, "*.fst")))
  3337. {
  3338. const auto first = juce::CharacterFunctions::toUpperCase (f.getFileName()[0]);
  3339. if (first != letter && sub.getNumItems() > 0)
  3340. {
  3341. threeOsc.addSubMenu (juce::String::charToString (letter), sub);
  3342. sub = {};
  3343. }
  3344. letter = first;
  3345. sub.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
  3346. }
  3347. if (sub.getNumItems() > 0)
  3348. threeOsc.addSubMenu (juce::String::charToString (letter), sub);
  3349. if (threeOsc.getNumItems() > 0)
  3350. menu.addSubMenu ("3x Osc", threeOsc);
  3351. }
  3352. // a preset folder as a menu: subfolders become submenus
  3353. std::function<juce::PopupMenu (const juce::File&, int)> folderMenu = [&] (const juce::File& folder, int depth) {
  3354. juce::PopupMenu m;
  3355. if (depth < 3)
  3356. for (const auto& dir : sorted (folder.findChildFiles (juce::File::findDirectories, false)))
  3357. if (auto sub = folderMenu (dir, depth + 1); sub.getNumItems() > 0)
  3358. m.addSubMenu (dir.getFileName(), sub);
  3359. for (const auto& f : sorted (folder.findChildFiles (juce::File::findFiles, false, "*.fst;*.gmsynth")))
  3360. m.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
  3361. return m;
  3362. };
  3363. const auto generators = patches.getChildFile ("Plugin presets/Generators");
  3364. for (const auto* name : { "Sytrus", "Harmor", "GMS", "Harmless", "MiniSynth", "Fruity DX10", "Fruit Kick", "Ogun", "Sakura", "Kepler", "Kepler Exo",
  3365. "PoiZone", "Toxic Biohazard", "BassDrum" })
  3366. if (auto sub = folderMenu (generators.getChildFile (name), 0); sub.getNumItems() > 0)
  3367. menu.addSubMenu (name, sub);
  3368. if (menu.getNumItems() == 0)
  3369. {
  3370. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("FL presets"),
  3371. tr ("FL presets not found (install FL Studio or check the Data\\Patches folder)."));
  3372. return;
  3373. }
  3374. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&flPresets));
  3375. }
  3376. void loadFlPreset (const juce::File& file)
  3377. {
  3378. juce::MemoryBlock data;
  3379. if (! file.loadFileAsData (data) || current() == nullptr)
  3380. return;
  3381. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  3382. if (auto synth = synthFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize())))
  3383. ref.edit (engine, [s = *synth] (ChannelDef& channelDef) { channelDef.synth = s; });
  3384. else
  3385. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("FL presets"),
  3386. tr ("This preset is not for a synth LYNX SHARE converts, or it could not be read."));
  3387. }
  3388. juce::Slider porta;
  3389. juce::ComboBox filterTypeBox;
  3390. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  3391. {
  3392. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  3393. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  3394. // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
  3395. s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
  3396. s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
  3397. s.setRange (lo, hi, step);
  3398. s.setTextValueSuffix (suffix);
  3399. s.onValueChange = [this] { apply(); };
  3400. addAndMakeVisible (s);
  3401. }
  3402. const ChannelDef* current() const
  3403. {
  3404. return ref.get (engine);
  3405. }
  3406. void refresh()
  3407. {
  3408. const auto* c = current();
  3409. if (c == nullptr)
  3410. return;
  3411. updating = true;
  3412. const auto& s = c->synth;
  3413. for (std::size_t o = 0; o < 3; ++o)
  3414. {
  3415. rows[o].wave.setSelectedId ((int) s.osc[o].wave + 1, juce::dontSendNotification);
  3416. rows[o].octave.setValue (s.osc[o].octave, juce::dontSendNotification);
  3417. rows[o].detune.setValue (s.osc[o].detune, juce::dontSendNotification);
  3418. rows[o].semitones.setValue (s.osc[o].semitones, juce::dontSendNotification);
  3419. rows[o].pan.setValue (s.osc[o].pan, juce::dontSendNotification);
  3420. rows[o].level.setValue (s.osc[o].level, juce::dontSendNotification);
  3421. }
  3422. attack.setValue (s.attack, juce::dontSendNotification);
  3423. decay.setValue (s.decay, juce::dontSendNotification);
  3424. sustain.setValue (s.sustain, juce::dontSendNotification);
  3425. release.setValue (s.release, juce::dontSendNotification);
  3426. cutoff.setValue (s.cutoff, juce::dontSendNotification);
  3427. resonance.setValue (s.resonance, juce::dontSendNotification);
  3428. mono.setToggleState (s.mono, juce::dontSendNotification);
  3429. am.setToggleState (s.am, juce::dontSendNotification);
  3430. porta.setValue (s.portaBeats, juce::dontSendNotification);
  3431. portaOn.setToggleState (s.porta, juce::dontSendNotification);
  3432. filterTypeBox.setSelectedId (s.filterType + 1, juce::dontSendNotification);
  3433. fm.setValue (s.fm, juce::dontSendNotification);
  3434. fmDecay.setValue (s.fmDecay, juce::dontSendNotification);
  3435. keyTrack.setValue (s.keyTrack, juce::dontSendNotification);
  3436. sweep.setValue (s.sweep, juce::dontSendNotification);
  3437. sweepTime.setValue (s.sweepTime, juce::dontSendNotification);
  3438. bandLow.setValue (s.bandGain[0], juce::dontSendNotification);
  3439. bandMid.setValue (s.bandGain[1], juce::dontSendNotification);
  3440. bandHigh.setValue (s.bandGain[2], juce::dontSendNotification);
  3441. ring.setToggleState (s.ring, juce::dontSendNotification);
  3442. updating = false;
  3443. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  3444. w->setName (tr ("Synth settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
  3445. }
  3446. void apply()
  3447. {
  3448. if (updating || current() == nullptr)
  3449. return;
  3450. auto s = current()->synth; // keeps what this window does not show (envelopes and LFOs)
  3451. for (std::size_t o = 0; o < 3; ++o)
  3452. s.osc[o] = { (Waveform) juce::jlimit (0, 5, rows[o].wave.getSelectedId() - 1), (int) rows[o].octave.getValue(),
  3453. (float) rows[o].detune.getValue(), (float) rows[o].level.getValue(), (int) rows[o].semitones.getValue(),
  3454. (float) rows[o].pan.getValue() };
  3455. s.attack = (float) attack.getValue();
  3456. s.decay = (float) decay.getValue();
  3457. s.sustain = (float) sustain.getValue();
  3458. s.release = (float) release.getValue();
  3459. s.cutoff = (float) cutoff.getValue();
  3460. s.resonance = (float) resonance.getValue();
  3461. s.mono = mono.getToggleState();
  3462. s.am = am.getToggleState();
  3463. s.portaBeats = (float) porta.getValue();
  3464. s.porta = portaOn.getToggleState();
  3465. s.filterType = juce::jlimit (0, 3, filterTypeBox.getSelectedId() - 1);
  3466. s.fm = (float) fm.getValue();
  3467. s.fmDecay = (float) fmDecay.getValue();
  3468. if (s.fmDecay <= 0.0f)
  3469. s.fmSustain = 1.0f;
  3470. s.keyTrack = (float) keyTrack.getValue();
  3471. s.sweep = (float) sweep.getValue();
  3472. s.sweepTime = (float) sweepTime.getValue();
  3473. s.bandGain = { (float) bandLow.getValue(), (float) bandMid.getValue(), (float) bandHigh.getValue() };
  3474. s.ring = ring.getToggleState();
  3475. if (s == current()->synth)
  3476. return;
  3477. ref.edit (engine, [s] (ChannelDef& channelDef) { channelDef.synth = s; });
  3478. }
  3479. void changeListenerCallback (juce::ChangeBroadcaster*) override
  3480. {
  3481. if (current() == nullptr)
  3482. {
  3483. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  3484. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
  3485. if (safe != nullptr)
  3486. safe->closeButtonPressed();
  3487. });
  3488. return;
  3489. }
  3490. refresh();
  3491. }
  3492. AudioEngine& engine;
  3493. ChannelRef ref;
  3494. bool updating = false;
  3495. std::array<Row, 3> rows;
  3496. juce::Slider attack, decay, sustain, release, cutoff, resonance, fm, fmDecay, keyTrack, sweep, sweepTime, bandLow, bandMid, bandHigh;
  3497. juce::ToggleButton ring;
  3498. std::array<juce::Label, 20> labels;
  3499. juce::ComboBox presetBox;
  3500. };
  3501. // --- FL's channel window frame (REA round 143b) --------------------------------------------------------------
  3502. // FL 2026 draws every channel's settings window the same way: a header strip with the channel's tabs on the left
  3503. // (the instrument / plugin page, the wrench "Miscellaneous functions" page) and ON, PAN, VOL and TRACK on the right
  3504. // [EXEC: FL 2026 build 5654, "Detailed settings" of a generator and of a sampler]. LYNX does the same around its own
  3505. // instrument pages, in its own style; the envelopes and LFOs of the synth and the sampler are the "Envelope /
  3506. // instrument" tab instead of a second window.
  3507. // A small rotary control with LYNX's control contract (drag, Ctrl = fine, wheel, Alt / middle-click / double-click
  3508. // reset, right-click menu with automation items when the spec has a target); the hint bar shows its name and value.
  3509. class FrameKnob final : public juce::Component,
  3510. public ui::HintSource,
  3511. private juce::Timer
  3512. {
  3513. public:
  3514. FrameKnob (AudioEngine& e, std::function<ui::ValueSpec()> makeSpec, std::function<double()> get, std::function<void (double)> set,
  3515. juce::String caption)
  3516. : engine (e), specOf (std::move (makeSpec)), getter (std::move (get)), setter (std::move (set)), label (std::move (caption))
  3517. {
  3518. setRepaintsOnMouseActivity (true);
  3519. if (specOf().target)
  3520. startTimerHz (30); // follows its automation while the song plays (issue #12)
  3521. }
  3522. // the value drawn: the automation's while the song plays (pan / volume: the targets these knobs have), else the Song's
  3523. double shownValue (const ui::ValueSpec& spec) const
  3524. {
  3525. if (spec.target && ! isMouseButtonDown())
  3526. if (const auto v = engine.getAutomationDisplay().valueOf (*spec.target))
  3527. return spec.target->kind == AutomationTargetKind::channelPan || spec.target->kind == AutomationTargetKind::mixerPan
  3528. ? (double) *v * 2.0 - 1.0
  3529. : (double) *v;
  3530. return getter();
  3531. }
  3532. void timerCallback() override
  3533. {
  3534. if (! isShowing())
  3535. return;
  3536. if (const auto generation = engine.getAutomationDisplay().getGeneration(); generation != shownGeneration)
  3537. {
  3538. shownGeneration = generation;
  3539. repaint();
  3540. }
  3541. }
  3542. std::uint32_t shownGeneration = 0;
  3543. ui::Hint hintAt (juce::Point<int>) override
  3544. {
  3545. return ui::valueHint (specOf(), getter(), doubleClicked ? tr ("[LMB] drag or [Wheel] changes [2xLMB] show in the Mixer [RMB] menu")
  3546. : ui::valueGestures());
  3547. }
  3548. // FL's number wheel (round 168s, issue #32): the value in a box over the caption instead of a knob; the whole
  3549. // control is the hit area, a notch / 7.5 px of drag = one step (ui::digitWheel). Double-click: `doubleClicked`.
  3550. bool digitBox = false;
  3551. std::function<void()> doubleClicked;
  3552. std::function<void (juce::PopupMenu&)> extraMenuItems;
  3553. void paint (juce::Graphics& g) override
  3554. {
  3555. const auto spec = specOf();
  3556. auto area = getLocalBounds().toFloat();
  3557. const auto caption = area.removeFromBottom (13.0f);
  3558. if (digitBox)
  3559. {
  3560. // FL's digiwheel (c_f14): a display about 22 px high, the value right-aligned before up / down marks; here dark,
  3561. // red only while touched
  3562. const auto box = area.withSizeKeepingCentre (juce::jmin (area.getWidth() - 2.0f, 48.0f), juce::jmin (22.0f, area.getHeight() - 4.0f));
  3563. g.setColour (theme::drawDigitDisplay (g, box, isMouseOverOrDragging() || drag.isActive(), false, true));
  3564. g.setFont (theme::font (13.0f, true));
  3565. g.drawFittedText (spec.text (getter()), box.withTrimmedRight (theme::digitMarksWidth).reduced (3.0f, 0.0f).toNearestInt(),
  3566. juce::Justification::centredRight, 1, 0.6f);
  3567. g.setColour (theme::colour::textSecondary);
  3568. g.setFont (theme::font (theme::type::caption));
  3569. g.drawFittedText (theme::caps (label), caption.toNearestInt(), juce::Justification::centred, 1, 0.65f);
  3570. return;
  3571. }
  3572. const auto valueArea = area.removeFromBottom (13.0f);
  3573. const auto size = juce::jmin (area.getWidth(), area.getHeight());
  3574. const auto shown = shownValue (spec);
  3575. const auto v = (float) juce::jlimit (0.0, 1.0, (shown - spec.minimum) / juce::jmax (1e-9, spec.maximum - spec.minimum));
  3576. theme::drawKnob (g, juce::Rectangle<float> (size, size).withCentre (area.getCentre()), v, spec.minimum < 0.0,
  3577. isMouseOverOrDragging() ? theme::colour::accent : theme::colour::knobArc, isMouseOver());
  3578. g.setFont (theme::font (theme::type::caption));
  3579. g.setColour (theme::colour::textPrimary);
  3580. // squeezed (down to 65 %) before an ellipsis: translated captions are often longer (round 165o)
  3581. g.drawFittedText (spec.text (shown), valueArea.toNearestInt(), juce::Justification::centred, 1, 0.65f);
  3582. g.setColour (theme::colour::textSecondary);
  3583. g.drawFittedText (theme::caps (label), caption.toNearestInt(), juce::Justification::centred, 1, 0.65f);
  3584. }
  3585. void mouseDown (const juce::MouseEvent& e) override
  3586. {
  3587. if (e.mods.isPopupMenu())
  3588. {
  3589. if (! extraMenuItems)
  3590. {
  3591. ui::showValueMenu (*this, &engine, specOf(), getter(), setter);
  3592. return;
  3593. }
  3594. const auto spec = specOf();
  3595. juce::PopupMenu menu;
  3596. menu.addSectionHeader (spec.name + ": " + spec.text (getter()));
  3597. ui::addValueItems (menu, *this, &engine, spec, getter(), setter);
  3598. menu.addSeparator();
  3599. extraMenuItems (menu);
  3600. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  3601. return;
  3602. }
  3603. if (ui::isResetClick (e))
  3604. {
  3605. setter (specOf().defaultValue);
  3606. repaint();
  3607. return;
  3608. }
  3609. drag.begin (e, getter());
  3610. }
  3611. void mouseDrag (const juce::MouseEvent& e) override
  3612. {
  3613. if (! drag.isActive())
  3614. return;
  3615. const auto spec = specOf();
  3616. setter (drag.update (e, spec));
  3617. ui::showValueTip (*this, getLocalBounds(), spec.text (getter()));
  3618. repaint();
  3619. }
  3620. void mouseUp (const juce::MouseEvent&) override
  3621. {
  3622. drag.end();
  3623. ui::hideValueTip();
  3624. }
  3625. void mouseDoubleClick (const juce::MouseEvent&) override
  3626. {
  3627. if (doubleClicked)
  3628. {
  3629. doubleClicked();
  3630. return;
  3631. }
  3632. setter (specOf().defaultValue);
  3633. repaint();
  3634. }
  3635. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  3636. {
  3637. if (const auto v = ui::wheelValue (getter(), e, wheel, specOf()))
  3638. {
  3639. setter (*v);
  3640. ui::flashValueTip (*this, getLocalBounds(), specOf().text (getter()));
  3641. repaint();
  3642. }
  3643. }
  3644. private:
  3645. AudioEngine& engine;
  3646. std::function<ui::ValueSpec()> specOf;
  3647. std::function<double()> getter;
  3648. std::function<void (double)> setter;
  3649. juce::String label;
  3650. ui::ValueDrag drag;
  3651. };
  3652. juce::String channelNameOf (const Song& song, int channel)
  3653. {
  3654. if (channel < 0 || channel >= (int) song.channels.size())
  3655. return "?";
  3656. const auto& n = song.channels[(std::size_t) channel].name;
  3657. return n.empty() ? tr ("Channel {0}", { juce::String (channel + 1) }) : juce::String::fromUTF8 (n.c_str());
  3658. }
  3659. // An integer spec shown as a number, 0 as "--" (FL's empty number boxes).
  3660. ui::ValueSpec countSpec (const juce::String& name, int maximum, int defaultValue, std::function<juce::String (int)> text = {})
  3661. {
  3662. ui::ValueSpec spec;
  3663. spec.name = name;
  3664. spec.maximum = maximum;
  3665. spec.defaultValue = defaultValue;
  3666. spec.interval = 1.0;
  3667. spec.pixelsForRange = juce::jlimit (60.0, 400.0, 5.0 * maximum);
  3668. spec.toText = [text] (double v) {
  3669. const auto i = juce::roundToInt (v);
  3670. if (text)
  3671. return text (i);
  3672. return i == 0 ? juce::String ("--") : juce::String (i);
  3673. };
  3674. spec.fromText = [] (const juce::String& t) -> std::optional<double> {
  3675. const auto digits = t.retainCharacters ("0123456789");
  3676. return digits.isEmpty() ? std::optional<double> (0.0) : std::optional<double> (digits.getDoubleValue());
  3677. };
  3678. return spec;
  3679. }
  3680. // The wrench tab: FL's "Miscellaneous functions" with what LYNX's channels have (Levels, Polyphony, Time, Group,
  3681. // Arpeggiator).
  3682. // FL's Root note keyboard (Misc tab, REA round 149): every key 0…127 (C0…G10, C5 = 60), the channel's root marked;
  3683. // a click sets it. LYNX's own drawing.
  3684. class RootKeyboard final : public juce::Component, public juce::SettableTooltipClient
  3685. {
  3686. public:
  3687. std::function<void (int)> onPick;
  3688. // FL's key region ruler (round 164): a drag on the strip above the keys sets the notes the channel plays,
  3689. // a double-click there gives it the whole keyboard back
  3690. std::function<void (int, int)> onRegion;
  3691. void setRoot (int key)
  3692. {
  3693. root = key;
  3694. repaint();
  3695. }
  3696. void setRegion (int low, int high)
  3697. {
  3698. if (low != regionLow || high != regionHigh)
  3699. {
  3700. regionLow = low;
  3701. regionHigh = high;
  3702. repaint();
  3703. }
  3704. }
  3705. void paint (juce::Graphics& g) override
  3706. {
  3707. using namespace theme;
  3708. const auto w = whiteWidth();
  3709. const auto top = (float) rulerHeight();
  3710. const auto keysH = (float) getHeight() - top;
  3711. if (onRegion)
  3712. {
  3713. const auto ruler = juce::Rectangle<float> (0.0f, 0.0f, (float) getWidth(), top - 2.0f);
  3714. g.setColour (colour::bg0);
  3715. g.fillRect (ruler);
  3716. const auto full = regionLow <= 0 && regionHigh >= 127;
  3717. const auto x0 = keyLeft (regionLow), x1 = keyRight (regionHigh);
  3718. g.setColour (full ? colour::bg5 : colour::accent);
  3719. g.fillRect (juce::Rectangle<float> (x0, 1.0f, juce::jmax (2.0f, x1 - x0), ruler.getHeight() - 2.0f));
  3720. }
  3721. for (int k = 0, white = 0; k < 128; ++k)
  3722. if (! isBlack (k))
  3723. {
  3724. const auto r = juce::Rectangle<float> ((float) (white++) * w, top, w - 1.0f, keysH);
  3725. const auto outside = onRegion && (k < regionLow || k > regionHigh);
  3726. g.setColour (k == root ? colour::accent : k == hover ? juce::Colour (0xffc8ccd4) : outside ? juce::Colour (0xff9a9ea8) : juce::Colour (0xffe6e8ec));
  3727. g.fillRect (r);
  3728. if (k % 12 == 0 && w * 7.0f >= 14.0f) // the octave's C named (FL's C5 = 60)
  3729. {
  3730. g.setColour (k == root ? colour::onAccent : juce::Colour (0xff5a5f6a));
  3731. g.setFont (font (8.5f));
  3732. g.drawText ("C" + juce::String (k / 12), r.withTrimmedTop (r.getHeight() - 11.0f).expanded (6.0f, 0.0f).toNearestInt(),
  3733. juce::Justification::centred);
  3734. }
  3735. }
  3736. for (int k = 0; k < 128; ++k)
  3737. if (isBlack (k))
  3738. {
  3739. const auto x = (float) whitesBefore (k) * w - w * 0.32f;
  3740. g.setColour (k == root ? colour::accent : k == hover ? colour::bg5 : colour::bg0);
  3741. g.fillRect (juce::Rectangle<float> (x, top, w * 0.64f, keysH * 0.6f));
  3742. }
  3743. }
  3744. void mouseMove (const juce::MouseEvent& e) override
  3745. {
  3746. const auto onRuler = onRegion && e.position.y < (float) rulerHeight();
  3747. if (const auto k = keyAt (e.position); k != hover || onRuler != hoverRuler)
  3748. {
  3749. hover = k;
  3750. hoverRuler = onRuler;
  3751. if (onRuler)
  3752. setTooltip (tr ("Key region: {0} to {1} (drag to set, double-click for the whole keyboard)",
  3753. { keyName (regionLow), keyName (regionHigh) }));
  3754. else
  3755. setTooltip (k >= 0 ? tr ("Root note: {0}", { keyName (k) }) : juce::String());
  3756. repaint();
  3757. }
  3758. }
  3759. void mouseExit (const juce::MouseEvent&) override
  3760. {
  3761. hover = -1;
  3762. repaint();
  3763. }
  3764. void mouseDown (const juce::MouseEvent& e) override
  3765. {
  3766. dragFrom = -1;
  3767. if (onRegion && e.position.y < (float) rulerHeight())
  3768. {
  3769. dragFrom = keyAtX (e.position.x);
  3770. if (dragFrom >= 0)
  3771. onRegion (dragFrom, dragFrom);
  3772. return;
  3773. }
  3774. if (const auto k = keyAt (e.position); k >= 0 && onPick)
  3775. onPick (k);
  3776. }
  3777. void mouseDrag (const juce::MouseEvent& e) override
  3778. {
  3779. if (dragFrom < 0 || ! onRegion)
  3780. return;
  3781. const auto k = keyAtX (e.position.x);
  3782. if (k >= 0)
  3783. onRegion (juce::jmin (dragFrom, k), juce::jmax (dragFrom, k));
  3784. }
  3785. void mouseDoubleClick (const juce::MouseEvent& e) override
  3786. {
  3787. if (onRegion && e.position.y < (float) rulerHeight())
  3788. onRegion (0, 127);
  3789. }
  3790. static juce::String keyName (int key)
  3791. {
  3792. return juce::String (notenames::keyName (key)); // Settings › General › Note names (round 165f)
  3793. }
  3794. private:
  3795. static bool isBlack (int k) noexcept
  3796. {
  3797. const auto n = k % 12;
  3798. return n == 1 || n == 3 || n == 6 || n == 8 || n == 10;
  3799. }
  3800. static int whitesBefore (int k) noexcept
  3801. {
  3802. int count = 0;
  3803. for (int i = 0; i < k; ++i)
  3804. count += isBlack (i) ? 0 : 1;
  3805. return count;
  3806. }
  3807. int rulerHeight() const noexcept { return onRegion ? 9 : 0; }
  3808. float whiteWidth() const noexcept { return (float) getWidth() / 75.0f; } // 75 white keys in 0…127
  3809. float keyLeft (int k) const noexcept
  3810. {
  3811. const auto w = whiteWidth();
  3812. return isBlack (k) ? (float) whitesBefore (k) * w - w * 0.32f : (float) whitesBefore (k) * w;
  3813. }
  3814. float keyRight (int k) const noexcept
  3815. {
  3816. const auto w = whiteWidth();
  3817. return isBlack (k) ? keyLeft (k) + w * 0.64f : keyLeft (k) + w;
  3818. }
  3819. // the key under x on the ruler (each key owns its own horizontal span; black keys win where they overlap)
  3820. int keyAtX (float x) const noexcept
  3821. {
  3822. for (int k = 0; k < 128; ++k)
  3823. if (isBlack (k) && x >= keyLeft (k) && x < keyRight (k))
  3824. return k;
  3825. const auto white = (int) std::floor (x / whiteWidth());
  3826. for (int k = 0, n = 0; k < 128; ++k)
  3827. if (! isBlack (k) && n++ == white)
  3828. return k;
  3829. return x < 0.0f ? 0 : 127;
  3830. }
  3831. int keyAt (juce::Point<float> p) const noexcept
  3832. {
  3833. const auto w = whiteWidth();
  3834. const auto top = (float) rulerHeight();
  3835. if (p.y < top)
  3836. return keyAtX (p.x);
  3837. if (p.y < top + ((float) getHeight() - top) * 0.6f)
  3838. for (int k = 0; k < 128; ++k)
  3839. if (isBlack (k))
  3840. {
  3841. const auto x = (float) whitesBefore (k) * w - w * 0.32f;
  3842. if (p.x >= x && p.x < x + w * 0.64f)
  3843. return k;
  3844. }
  3845. const auto white = (int) std::floor (p.x / w);
  3846. for (int k = 0, n = 0; k < 128; ++k)
  3847. if (! isBlack (k) && n++ == white)
  3848. return k;
  3849. return -1;
  3850. }
  3851. int root = 60, hover = -1, dragFrom = -1;
  3852. int regionLow = 0, regionHigh = 127;
  3853. bool hoverRuler = false;
  3854. };
  3855. class MiscPanel final : public juce::Component,
  3856. private juce::ChangeListener
  3857. {
  3858. public:
  3859. static constexpr int preferredWidth = 800, preferredHeight = 360;
  3860. MiscPanel (AudioEngine& e, int c) : engine (e), channel (c)
  3861. {
  3862. const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
  3863. auto knob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get,
  3864. std::function<void (ChannelDef&, double)> set, const char* caption) {
  3865. auto k = std::make_unique<FrameKnob> (
  3866. engine, std::move (spec), [this, get] { return current() != nullptr ? get (*current()) : 0.0; },
  3867. [this, set] (double v) {
  3868. if (current() == nullptr)
  3869. return;
  3870. engine.editSong ([ch = channel, set, v] (Song& s) {
  3871. if (ch < (int) s.channels.size())
  3872. set (s.channels[(std::size_t) ch], v);
  3873. });
  3874. },
  3875. tr (caption));
  3876. addAndMakeVisible (*k);
  3877. knobs.push_back (std::move (k));
  3878. return knobs.back().get();
  3879. };
  3880. // Levels adjustment
  3881. pan = knob ([this, name] {
  3882. auto s = ui::panSpec (name() + " - " + tr ("Pan"));
  3883. s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
  3884. return s;
  3885. },
  3886. [] (const ChannelDef& d) { return (double) d.pan; }, [] (ChannelDef& d, double v) { d.pan = (float) v; }, TR_NOOP ("Pan"));
  3887. volume = knob ([this, name] {
  3888. auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
  3889. s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
  3890. return s;
  3891. },
  3892. [] (const ChannelDef& d) { return (double) d.volume; }, [] (ChannelDef& d, double v) { d.volume = (float) v; },
  3893. TR_NOOP ("Vol"));
  3894. // Polyphony
  3895. maxPoly = knob ([name] { return countSpec (name() + " - " + tr ("Maximum polyphony (-- = no limit)"), 64, 0); },
  3896. [] (const ChannelDef& d) { return (double) d.maxPolyphony; },
  3897. [] (ChannelDef& d, double v) { d.maxPolyphony = juce::jlimit (0, 64, juce::roundToInt (v)); }, TR_NOOP ("Max"));
  3898. slide = knob (
  3899. [name] {
  3900. ui::ValueSpec s;
  3901. s.name = name() + " - " + tr ("Portamento time");
  3902. s.maximum = 2.0;
  3903. s.defaultValue = 0.125;
  3904. s.toText = [] (double v) { return tr ("{0} beats", { juce::String (v, 3) }); };
  3905. s.fromText = [] (const juce::String& t) -> std::optional<double> { return t.retainCharacters ("0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
  3906. return s;
  3907. },
  3908. [] (const ChannelDef& d) { return (double) channelPortamentoBeats (d); },
  3909. [] (ChannelDef& d, double v) { setChannelPortamento (d, channelPortamento (d), (float) v); }, TR_NOOP ("Slide"));
  3910. porta.setButtonText (tr ("Porta"));
  3911. porta.setTooltip (tr ("Portamento: each note glides from the previous one's pitch (the Slide knob sets the time)"));
  3912. porta.onClick = [this] { edit ([on = porta.getToggleState()] (ChannelDef& d) { setChannelPortamento (d, on, channelPortamentoBeats (d)); }); };
  3913. mono.setButtonText (tr ("Mono"));
  3914. mono.setTooltip (tr ("Mono: one voice; a note played over a held one glides to it (Slide time) without a new attack"));
  3915. mono.onClick = [this] { edit ([on = mono.getToggleState()] (ChannelDef& d) { setChannelMono (d, on); }); };
  3916. // Time
  3917. swing = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Swing mix"), 1.0); },
  3918. [] (const ChannelDef& d) { return (double) d.swingMix; }, [] (ChannelDef& d, double v) { d.swingMix = (float) v; },
  3919. TR_NOOP ("Swing"));
  3920. // Levels adjustment: Mod X / Mod Y = the channel filter's cutoff / resonance (sampler, synth)
  3921. modX = knob ([name] {
  3922. ui::ValueSpec s;
  3923. s.name = name() + " - " + tr ("Mod X (filter cutoff)");
  3924. s.defaultValue = 1.0;
  3925. s.toText = [] (double v) { const auto hz = 20.0 * std::pow (1000.0, v); return hz >= 1000.0 ? juce::String (hz / 1000.0, 1) + " kHz" : juce::String (juce::roundToInt (hz)) + " Hz"; };
  3926. return s;
  3927. },
  3928. [] (const ChannelDef& d) {
  3929. const auto hz = d.instrument == InstrumentKind::synth ? d.synth.cutoff : d.sampler.cutoff;
  3930. return juce::jlimit (0.0, 1.0, std::log ((double) hz / 20.0) / std::log (1000.0));
  3931. },
  3932. [] (ChannelDef& d, double v) {
  3933. const auto hz = (float) (20.0 * std::pow (1000.0, v));
  3934. if (d.instrument == InstrumentKind::synth)
  3935. d.synth.cutoff = hz;
  3936. else if (d.instrument == InstrumentKind::sampler)
  3937. {
  3938. d.sampler.cutoff = hz;
  3939. d.sampler.flChannel.clear(); // an edited filter replaces FL's whole sampler voice (REA_rodada76)
  3940. }
  3941. },
  3942. TR_NOOP ("Mod X"));
  3943. modY = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Mod Y (filter resonance)"), 0.0); },
  3944. [] (const ChannelDef& d) { return (double) (d.instrument == InstrumentKind::synth ? d.synth.resonance : d.sampler.resonance); },
  3945. [] (ChannelDef& d, double v) {
  3946. if (d.instrument == InstrumentKind::synth)
  3947. d.synth.resonance = (float) v;
  3948. else if (d.instrument == InstrumentKind::sampler)
  3949. {
  3950. d.sampler.resonance = (float) v;
  3951. d.sampler.flChannel.clear();
  3952. }
  3953. },
  3954. TR_NOOP ("Mod Y"));
  3955. // Time: Gate and Shift on FL's time-knob scale (REA round 146b)
  3956. auto timeSpec = [name] (const char* what, int maximum, int defaultValue, bool offAtMax) {
  3957. ui::ValueSpec s;
  3958. s.name = name() + " - " + tr (what);
  3959. s.maximum = maximum;
  3960. s.defaultValue = defaultValue;
  3961. s.interval = 1.0;
  3962. s.pixelsForRange = 300.0;
  3963. s.toText = [maximum, offAtMax] (double v) {
  3964. const auto i = juce::roundToInt (v);
  3965. if (offAtMax && i >= maximum)
  3966. return tr ("Off");
  3967. // steps:ticks, as FL shows them (24 ticks per step)
  3968. const auto ticks = juce::roundToInt (channelmisc::flTimeKnobBeats (i) * 96.0);
  3969. return juce::String (ticks / 24) + ":" + juce::String (ticks % 24).paddedLeft ('0', 2);
  3970. };
  3971. return s;
  3972. };
  3973. timeGate = knob ([timeSpec] { return timeSpec (TR_NOOP ("Gate: long notes are cut to this length (Off = no limit)"), 1446, 1446, true); },
  3974. [] (const ChannelDef& d) { return d.misc.gateBeats > 0.0f ? (double) channelmisc::flTimeKnobValue (d.misc.gateBeats) : 1446.0; },
  3975. [] (ChannelDef& d, double v) {
  3976. const auto i = juce::roundToInt (v);
  3977. d.misc.gateBeats = i >= 1446 ? 0.0f : (float) std::max (1.0 / 96.0, channelmisc::flTimeKnobBeats (i));
  3978. },
  3979. TR_NOOP ("Gate"));
  3980. timeShift = knob ([timeSpec] { return timeSpec (TR_NOOP ("Fine time shift: delays the notes, up to one step"), 1024, 0, false); },
  3981. [] (const ChannelDef& d) { return (double) channelmisc::flTimeKnobValue (d.misc.shiftBeats); },
  3982. [] (ChannelDef& d, double v) { d.misc.shiftBeats = (float) channelmisc::flTimeKnobBeats (juce::roundToInt (v)); },
  3983. TR_NOOP ("Shift"));
  3984. fullPorta.setButtonText (tr ("Full porta"));
  3985. fullPorta.setTooltip (tr ("Full porta: portamento notes ignore the Gate and play their whole length"));
  3986. fullPorta.onClick = [this] { edit ([on = fullPorta.getToggleState()] (ChannelDef& d) { d.misc.fullPorta = on; }); };
  3987. // Vol / Key tracking
  3988. trackVol.setButtonText (tr ("Vol"));
  3989. trackKey.setButtonText (trc ("@key tracking: Key"));
  3990. for (auto* b : { &trackVol, &trackKey })
  3991. {
  3992. b->setClickingTogglesState (true);
  3993. b->setRadioGroupId (146);
  3994. b->onClick = [this] { repaint(); for (auto& k : knobs) k->repaint(); };
  3995. addAndMakeVisible (b);
  3996. }
  3997. trackVol.setTooltip (tr ("Velocity tracking: the note's velocity moves its pan"));
  3998. trackKey.setTooltip (tr ("Keyboard tracking: the note's key moves its pan"));
  3999. trackKey.setToggleState (true, juce::dontSendNotification);
  4000. auto tracking = [this] (ChannelDef& d) -> NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
  4001. auto trackingOf = [this] (const ChannelDef& d) -> const NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
  4002. trackPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: pan")); },
  4003. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).pan; },
  4004. [tracking] (ChannelDef& d, double v) { tracking (d).pan = (float) v; }, TR_NOOP ("Pan"));
  4005. trackMid = knob ([this, name] {
  4006. const auto key = trackKey.getToggleState();
  4007. auto s = countSpec (name() + " - " + tr ("Tracking: the middle value (no offset)"), key ? 131 : 128, key ? 60 : 100,
  4008. [key] (int v) { return key ? juce::MidiMessage::getMidiNoteName (120 - v, true, true, 5) : juce::String (v); }); // FL: C5 = 60
  4009. return s;
  4010. },
  4011. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).mid; },
  4012. [tracking] (ChannelDef& d, double v) { tracking (d).mid = juce::roundToInt (v); }, TR_NOOP ("Mid"));
  4013. // FL's tracking Mod X / Y (round 151): the notes' Mod X / Y follow the velocity / key like their pan
  4014. trackModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod X (the note's filter cutoff / a plugin's MOD X)")); },
  4015. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modX; },
  4016. [tracking] (ChannelDef& d, double v) { tracking (d).modX = (float) v; }, TR_NOOP ("Mod X"));
  4017. trackModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod Y (the note's filter resonance)")); },
  4018. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modY; },
  4019. [tracking] (ChannelDef& d, double v) { tracking (d).modY = (float) v; }, TR_NOOP ("Mod Y"));
  4020. // Echo delay / fat mode
  4021. echoFeed = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Delay feedback (100% = the echoes as loud as the note)"), 0.0); },
  4022. [] (const ChannelDef& d) { return (double) d.misc.echo.feedback / 2.0; },
  4023. [] (ChannelDef& d, double v) { d.misc.echo.feedback = (float) (2.0 * v); }, TR_NOOP ("Feed"));
  4024. echoPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay pan: each echo moves this much")); },
  4025. [] (const ChannelDef& d) { return (double) d.misc.echo.pan; }, [] (ChannelDef& d, double v) { d.misc.echo.pan = (float) v; },
  4026. TR_NOOP ("Pan"));
  4027. echoModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod X: each echo moves the note's Mod X this much")); },
  4028. [] (const ChannelDef& d) { return (double) d.misc.echo.modX; }, [] (ChannelDef& d, double v) { d.misc.echo.modX = (float) v; },
  4029. TR_NOOP ("Mod X"));
  4030. echoModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod Y: each echo moves the note's Mod Y this much")); },
  4031. [] (const ChannelDef& d) { return (double) d.misc.echo.modY; }, [] (ChannelDef& d, double v) { d.misc.echo.modY = (float) v; },
  4032. TR_NOOP ("Mod Y"));
  4033. echoPitch = knob ([name] {
  4034. ui::ValueSpec s;
  4035. s.name = name() + " - " + tr ("Delay pitch: each echo moves this many cents");
  4036. s.minimum = -1200.0;
  4037. s.maximum = 1200.0;
  4038. s.interval = 1.0;
  4039. s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v)) }); };
  4040. return s;
  4041. },
  4042. [] (const ChannelDef& d) { return (double) d.misc.echo.pitch; }, [] (ChannelDef& d, double v) { d.misc.echo.pitch = (float) v; },
  4043. TR_NOOP ("Pitch"));
  4044. echoTime = knob ([name] {
  4045. ui::ValueSpec s;
  4046. s.name = name() + " - " + tr ("Delay time (steps:ticks)");
  4047. s.minimum = 1.0;
  4048. s.maximum = 192.0 * 4.0;
  4049. s.defaultValue = 144.0;
  4050. s.interval = 1.0;
  4051. s.pixelsForRange = 400.0;
  4052. s.toText = [] (double v) { const auto t = juce::roundToInt (v); return juce::String (t / 48) + ":" + juce::String ((t % 48) / 2).paddedLeft ('0', 2); };
  4053. return s;
  4054. },
  4055. [] (const ChannelDef& d) { return (double) d.misc.echo.timeBeats * 192.0; },
  4056. [] (ChannelDef& d, double v) { d.misc.echo.timeBeats = (float) (juce::roundToInt (v) / 192.0); }, TR_NOOP ("Time"));
  4057. echoCount = knob ([name] { return countSpec (name() + " - " + tr ("Delay number of echoes"), 10, 4); },
  4058. [] (const ChannelDef& d) { return (double) d.misc.echo.echoes; },
  4059. [] (ChannelDef& d, double v) { d.misc.echo.echoes = juce::jlimit (1, 10, juce::roundToInt (v)); }, TR_NOOP ("Echoes"));
  4060. pingPong.setButtonText (tr ("Ping pong"));
  4061. pingPong.setTooltip (tr ("Ping pong: the echoes' pan bounces off the left and right ends"));
  4062. pingPong.onClick = [this] { edit ([on = pingPong.getToggleState()] (ChannelDef& d) { d.misc.echo.pingPong = on; }); };
  4063. fatMode.setButtonText (tr ("Fat mode"));
  4064. fatMode.setTooltip (tr ("Fat mode: a second, mirrored series of echoes (opposite pan and pitch steps), all at the feedback level"));
  4065. fatMode.onClick = [this] { edit ([on = fatMode.getToggleState()] (ChannelDef& d) { d.misc.echo.fat = on; }); };
  4066. // Root note row: main pitch
  4067. mainPitch.setButtonText (tr ("Enable main pitch"));
  4068. mainPitch.setTooltip (tr ("The channel follows the main pitch (the toolbar's master pitch)"));
  4069. mainPitch.onClick = [this] { edit ([on = mainPitch.getToggleState()] (ChannelDef& d) { d.misc.mainPitch = on; }); };
  4070. // FL's Add to key and Root note keyboard (round 149): a sampler's root moves its pitch, other instruments are
  4071. // transposed by (C5 − root) with Add to key
  4072. addToKey.setButtonText (tr ("Add to key"));
  4073. addToKey.setTooltip (tr ("Add to key: the notes are played the root note's distance from C5 away (instruments that are not samplers)"));
  4074. addToKey.onClick = [this] { edit ([on = addToKey.getToggleState()] (ChannelDef& d) { d.misc.addToKey = on; }); };
  4075. // FL's Root note › Fine tune (round 151 [DATA: .flp event 0x8E, cents]): every note of the channel this many
  4076. // cents away
  4077. fineTune = knob ([name] {
  4078. ui::ValueSpec s;
  4079. s.name = name() + " - " + tr ("Fine tuning");
  4080. s.minimum = -100.0;
  4081. s.maximum = 100.0;
  4082. s.interval = 1.0;
  4083. s.toText = [] (double v) { return tr ("{0} cents", { (v > 0.0 ? "+" : "") + juce::String (juce::roundToInt (v)) }); };
  4084. return s;
  4085. },
  4086. [] (const ChannelDef& d) { return (double) d.misc.fineTune; }, [] (ChannelDef& d, double v) { d.misc.fineTune = (float) v; },
  4087. TR_NOOP ("Fine tune"));
  4088. rootReset.setButtonText (tr ("Reset"));
  4089. rootReset.setTooltip (tr ("Reset the root note to C5"));
  4090. rootReset.onClick = [this] { if (rootKeys.onPick) rootKeys.onPick (60); };
  4091. addAndMakeVisible (rootReset);
  4092. rootKeys.onPick = [this] (int key) {
  4093. edit ([key] (ChannelDef& d) {
  4094. if (d.instrument == InstrumentKind::sampler)
  4095. {
  4096. // the sample plays at its own pitch on the root: the pitch moves by the root's change (within ±24)
  4097. const auto pitch = std::clamp (d.sampler.pitch + (float) (d.misc.rootNote - key), -24.0f, 24.0f);
  4098. const auto moved = (int) std::lround (pitch - d.sampler.pitch);
  4099. d.sampler.pitch = pitch;
  4100. d.misc.rootNote = std::clamp (d.misc.rootNote - moved, 0, 127);
  4101. }
  4102. else
  4103. d.misc.rootNote = key;
  4104. });
  4105. };
  4106. rootKeys.onRegion = [this] (int low, int high) {
  4107. edit ([low, high] (ChannelDef& d) {
  4108. d.keyLow = juce::jlimit (0, 127, low);
  4109. d.keyHigh = juce::jlimit (d.keyLow, 127, high);
  4110. });
  4111. };
  4112. addAndMakeVisible (addToKey);
  4113. addAndMakeVisible (rootKeys);
  4114. // Arpeggiator: FL's Slide and Chord
  4115. arpSlide.setButtonText (tr ("Slide"));
  4116. arpSlide.setTooltip (tr ("Slide: the arpeggio glides from note to note (instruments that slide)"));
  4117. arpSlide.onClick = [this] { edit ([on = arpSlide.getToggleState()] (ChannelDef& d) { d.arp.slide = on; }); };
  4118. arpChord.addItem (tr ("Auto (sustain)"), 1);
  4119. arpChord.addItem (tr ("None (octaves)"), 2);
  4120. for (const auto& [chordName, intervals] : arpChords())
  4121. arpChord.addItem (tr (chordName), arpChord.getNumItems() + 1);
  4122. arpChord.setTooltip (tr ("Chord: Auto plays the held notes; a chord plays it on the lowest held note"));
  4123. arpChord.onChange = [this] {
  4124. const auto id = arpChord.getSelectedId();
  4125. if (id <= 0)
  4126. return;
  4127. edit ([id] (ChannelDef& d) {
  4128. if (id == 1)
  4129. d.arp.chord.clear();
  4130. else if (id == 2)
  4131. d.arp.chord = { 0 };
  4132. else if (id - 3 < (int) arpChords().size())
  4133. d.arp.chord = arpChords()[(std::size_t) (id - 3)].second;
  4134. });
  4135. };
  4136. for (auto* b : { &fullPorta, &pingPong, &fatMode, &mainPitch, &arpSlide })
  4137. addAndMakeVisible (b);
  4138. addAndMakeVisible (arpChord);
  4139. // Group
  4140. cut = knob ([this, name] { return countSpec (name() + " - " + tr ("Cut: notes of this channel stop the channels cut by this group"),
  4141. juce::jmax (99, current() != nullptr ? current()->cutGroup : 0), 0,
  4142. [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
  4143. [] (const ChannelDef& d) { return (double) d.cutGroup; }, [] (ChannelDef& d, double v) { d.cutGroup = juce::jmax (0, juce::roundToInt (v)); },
  4144. TR_NOOP ("Cut group"));
  4145. cutBy = knob ([this, name] { return countSpec (name() + " - " + tr ("By: this channel is cut by the channels of this group"),
  4146. juce::jmax (99, current() != nullptr ? current()->cutBy : 0), 0,
  4147. [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
  4148. [] (const ChannelDef& d) { return (double) d.cutBy; }, [] (ChannelDef& d, double v) { d.cutBy = juce::jmax (0, juce::roundToInt (v)); },
  4149. TR_NOOP ("Cut by"));
  4150. cutSelf.setButtonText (tr ("Cut self"));
  4151. cutSelf.setClickingTogglesState (true);
  4152. cutSelf.setTooltip (tr ("Cut self: a new note of this channel stops its own sounding note (hi-hats, 808s)"));
  4153. cutSelf.onClick = [this] { edit ([on = cutSelf.getToggleState(), ch = channel] (ChannelDef& d) { setChannelCutsItself (d, ch, on); }); };
  4154. // Arpeggiator
  4155. arpDirection.addItemList ({ tr ("Off"), tr ("Up"), tr ("Down"), tr ("Up and down"), tr ("Random"), tr ("Up and down (sticky)") }, 1);
  4156. arpDirection.setTooltip (tr ("Arpeggiator direction (Off = the notes play as written)"));
  4157. arpDirection.onChange = [this] { edit ([d = arpDirection.getSelectedId() - 1] (ChannelDef& c) { c.arp.direction = juce::jlimit (0, 5, d); }); };
  4158. for (const auto& [text, beats] : arpSpeeds())
  4159. arpTime.addItem (tr (text), arpTime.getNumItems() + 1);
  4160. arpTime.setTooltip (tr ("Arpeggiator time: the length of each step"));
  4161. arpTime.onChange = [this] {
  4162. const auto i = arpTime.getSelectedId() - 1;
  4163. if (i >= 0 && i < (int) arpSpeeds().size())
  4164. edit ([b = arpSpeeds()[(std::size_t) i].second] (ChannelDef& c) { c.arp.stepBeats = b; });
  4165. };
  4166. arpRange = knob ([name] { return countSpec (name() + " - " + tr ("Arpeggiator range (octaves)"), 4, 1); },
  4167. [] (const ChannelDef& d) { return (double) d.arp.range; },
  4168. [] (ChannelDef& d, double v) { d.arp.range = juce::jlimit (1, 4, juce::roundToInt (v)); }, TR_NOOP ("Range"));
  4169. arpGate = knob ([name] {
  4170. auto s = ui::percentSpec (name() + " - " + tr ("Arpeggio gate (past 100% the next note waits)"), 0.5);
  4171. s.minimum = 0.05;
  4172. s.maximum = 128.0 / 48.0;
  4173. return s;
  4174. },
  4175. [] (const ChannelDef& d) { return (double) d.arp.gate; },
  4176. [] (ChannelDef& d, double v) { d.arp.gate = juce::jlimit (0.05f, 128.0f / 48.0f, (float) v); }, TR_NOOP ("Gate"));
  4177. // FL's Repeat 0 plays the whole chord at once on each step (round 149)
  4178. arpRepeat = knob ([name] { return countSpec (name() + " - " + tr ("Arpeggiator repeat: times the arpeggio plays in an octave before the next one (0: the chord at once)"), 16, 1,
  4179. [] (int i) { return i == 0 ? tr ("Chord") : juce::String (i); }); },
  4180. [] (const ChannelDef& d) { return (double) d.arp.octaveRepeat; },
  4181. [] (ChannelDef& d, double v) { d.arp.octaveRepeat = juce::jlimit (0, 16, juce::roundToInt (v)); }, TR_NOOP ("Repeat"));
  4182. for (auto* b : { &porta, &mono })
  4183. addAndMakeVisible (b);
  4184. addAndMakeVisible (cutSelf);
  4185. addAndMakeVisible (arpDirection);
  4186. addAndMakeVisible (arpTime);
  4187. refresh();
  4188. engine.addChangeListener (this);
  4189. setSize (preferredWidth, preferredHeight);
  4190. }
  4191. ~MiscPanel() override { engine.removeChangeListener (this); }
  4192. void paint (juce::Graphics& g) override
  4193. {
  4194. g.fillAll (theme::colour::bg2);
  4195. for (const auto& [area, title] : sections)
  4196. {
  4197. g.setColour (theme::colour::bg3);
  4198. g.fillRoundedRectangle (area.toFloat(), 4.0f);
  4199. g.setColour (theme::colour::textSecondary);
  4200. g.setFont (theme::font (theme::type::caption, true));
  4201. auto text = theme::caps (title);
  4202. if (&title == &sections[(std::size_t) juce::jmax (0, rootSection)].second && rootSection >= 0 && current() != nullptr)
  4203. text << ": " << RootKeyboard::keyName (current()->misc.rootNote); // FL's "Root note: C5"
  4204. g.drawText (text, area.withHeight (20).reduced (8, 0), juce::Justification::centredLeft);
  4205. }
  4206. }
  4207. void resized() override
  4208. {
  4209. sections.clear();
  4210. auto area = getLocalBounds().reduced (8);
  4211. auto section = [this] (juce::Rectangle<int> r, const juce::String& title) {
  4212. sections.push_back ({ r, title });
  4213. return r.withTrimmedTop (20).reduced (6, 4);
  4214. };
  4215. constexpr int knobW = 50, knobH = 64;
  4216. auto row = [] (juce::Rectangle<int>& r, std::initializer_list<FrameKnob*> ks) {
  4217. auto line = r.removeFromTop (knobH);
  4218. for (auto* k : ks)
  4219. k->setBounds (line.removeFromLeft (knobW));
  4220. };
  4221. auto top = area.removeFromTop (118);
  4222. {
  4223. auto levels = section (top.removeFromLeft (4 * knobW + 12), tr ("Levels adjustment"));
  4224. row (levels, { pan, volume, modX, modY });
  4225. }
  4226. top.removeFromLeft (6);
  4227. {
  4228. auto poly = section (top.removeFromLeft (2 * knobW + 30), tr ("Polyphony"));
  4229. row (poly, { maxPoly, slide });
  4230. auto toggles = poly.removeFromTop (22);
  4231. porta.setBounds (toggles.removeFromLeft (64));
  4232. mono.setBounds (toggles);
  4233. }
  4234. top.removeFromLeft (6);
  4235. {
  4236. auto time = section (top.removeFromLeft (3 * knobW + 12), tr ("Time"));
  4237. row (time, { timeGate, timeShift, swing });
  4238. fullPorta.setBounds (time.removeFromTop (22));
  4239. }
  4240. top.removeFromLeft (6);
  4241. {
  4242. auto track = section (top, tr ("Tracking"));
  4243. auto tabs = track.removeFromTop (0);
  4244. juce::ignoreUnused (tabs);
  4245. const auto title = sections.back().first;
  4246. trackVol.setBounds (title.getRight() - 84, title.getY() + 2, 38, 16);
  4247. trackKey.setBounds (title.getRight() - 44, title.getY() + 2, 38, 16);
  4248. row (track, { trackPan, trackModX, trackModY, trackMid });
  4249. }
  4250. area.removeFromTop (6);
  4251. auto bottom = area.removeFromTop (130);
  4252. {
  4253. auto group = section (bottom.removeFromLeft (2 * knobW + 16), tr ("Group"));
  4254. row (group, { cut, cutBy });
  4255. cutSelf.setBounds (group.removeFromTop (24).reduced (4, 0));
  4256. }
  4257. bottom.removeFromLeft (6);
  4258. {
  4259. auto arp = section (bottom.removeFromLeft (330), tr ("Arpeggiator"));
  4260. auto boxes = arp.removeFromLeft (118);
  4261. arpDirection.setBounds (boxes.removeFromTop (22));
  4262. boxes.removeFromTop (4);
  4263. arpTime.setBounds (boxes.removeFromTop (22));
  4264. boxes.removeFromTop (4);
  4265. arpChord.setBounds (boxes.removeFromTop (22));
  4266. boxes.removeFromTop (4);
  4267. arpSlide.setBounds (boxes.removeFromTop (22));
  4268. arp.removeFromLeft (6);
  4269. row (arp, { arpRange, arpGate, arpRepeat });
  4270. }
  4271. bottom.removeFromLeft (6);
  4272. {
  4273. auto echo = section (bottom, tr ("Echo delay / fat mode"));
  4274. {
  4275. // seven knobs (round 151 added Mod X / Y): narrower when the window is
  4276. auto line = echo.removeFromTop (knobH);
  4277. const auto w = juce::jmin (knobW, line.getWidth() / 7);
  4278. for (auto* k : { echoFeed, echoPan, echoModX, echoModY, echoPitch, echoTime, echoCount })
  4279. k->setBounds (line.removeFromLeft (w));
  4280. }
  4281. auto toggles = echo.removeFromTop (22);
  4282. pingPong.setBounds (toggles.removeFromLeft (100));
  4283. fatMode.setBounds (toggles.removeFromLeft (100));
  4284. }
  4285. area.removeFromTop (6);
  4286. {
  4287. auto rootRow = section (area.removeFromTop (74), tr ("Root note"));
  4288. rootSection = (int) sections.size() - 1;
  4289. const auto resetWidth = theme::buttonWidth (rootReset, 50, 96); // long "Reset" translations
  4290. auto toggles = rootRow.removeFromLeft (100 + resetWidth);
  4291. mainPitch.setBounds (toggles.removeFromTop (22));
  4292. auto line = toggles.removeFromTop (22);
  4293. rootReset.setBounds (line.removeFromRight (resetWidth).reduced (0, 1));
  4294. addToKey.setBounds (line);
  4295. auto fine = rootRow.removeFromLeft (58);
  4296. row (fine, { fineTune });
  4297. rootKeys.setBounds (rootRow.reduced (4, 2));
  4298. }
  4299. }
  4300. private:
  4301. // LYNX's chord choices for the arpeggiator (the piano roll's chord stamps)
  4302. static const std::vector<std::pair<const char*, std::vector<int>>>& arpChords()
  4303. {
  4304. static const std::vector<std::pair<const char*, std::vector<int>>> chords {
  4305. { TR_NOOP ("Major"), { 0, 4, 7 } }, { TR_NOOP ("Minor"), { 0, 3, 7 } }, { "Dim", { 0, 3, 6 } }, { "Aug", { 0, 4, 8 } },
  4306. { "Sus2", { 0, 2, 7 } }, { "Sus4", { 0, 5, 7 } }, { "7", { 0, 4, 7, 10 } }, { "Maj7", { 0, 4, 7, 11 } },
  4307. { "m7", { 0, 3, 7, 10 } }, { "m9", { 0, 3, 7, 10, 14 } }, { TR_NOOP ("Octave"), { 0, 12 } },
  4308. };
  4309. return chords;
  4310. }
  4311. static const std::vector<std::pair<const char*, float>>& arpSpeeds()
  4312. {
  4313. static const std::vector<std::pair<const char*, float>> speeds { { "1/4", 1.0f }, { "1/8", 0.5f },
  4314. { TR_NOOP ("1/8 triplet"), 1.0f / 3.0f }, { "1/16", 0.25f },
  4315. { TR_NOOP ("1/16 triplet"), 1.0f / 6.0f }, { "1/32", 0.125f } };
  4316. return speeds;
  4317. }
  4318. const ChannelDef* current() const
  4319. {
  4320. const auto& channels = engine.getSong().channels;
  4321. return channel >= 0 && channel < (int) channels.size() ? &channels[(std::size_t) channel] : nullptr;
  4322. }
  4323. void edit (std::function<void (ChannelDef&)> change)
  4324. {
  4325. if (updating || current() == nullptr)
  4326. return;
  4327. engine.editSong ([ch = channel, change] (Song& s) {
  4328. if (ch < (int) s.channels.size())
  4329. change (s.channels[(std::size_t) ch]);
  4330. });
  4331. }
  4332. void refresh()
  4333. {
  4334. const auto* c = current();
  4335. if (c == nullptr)
  4336. return;
  4337. updating = true;
  4338. porta.setToggleState (channelPortamento (*c), juce::dontSendNotification);
  4339. porta.setEnabled (channelHasPortamento (*c));
  4340. slide->setEnabled (channelHasPortamento (*c));
  4341. mono.setToggleState (channelMono (*c), juce::dontSendNotification);
  4342. mono.setEnabled (channelHasMono (*c));
  4343. cutSelf.setToggleState (channelCutsItself (*c), juce::dontSendNotification);
  4344. arpDirection.setSelectedId (juce::jlimit (0, 5, c->arp.direction) + 1, juce::dontSendNotification);
  4345. fullPorta.setToggleState (c->misc.fullPorta, juce::dontSendNotification);
  4346. pingPong.setToggleState (c->misc.echo.pingPong, juce::dontSendNotification);
  4347. fatMode.setToggleState (c->misc.echo.fat, juce::dontSendNotification);
  4348. mainPitch.setToggleState (c->misc.mainPitch, juce::dontSendNotification);
  4349. addToKey.setToggleState (c->misc.addToKey, juce::dontSendNotification);
  4350. addToKey.setEnabled (c->instrument != InstrumentKind::sampler);
  4351. rootKeys.setRoot (c->misc.rootNote);
  4352. rootKeys.setRegion (c->keyLow, c->keyHigh);
  4353. arpSlide.setToggleState (c->arp.slide, juce::dontSendNotification);
  4354. const auto filter = c->instrument == InstrumentKind::synth || c->instrument == InstrumentKind::sampler;
  4355. modX->setEnabled (filter);
  4356. modY->setEnabled (filter);
  4357. {
  4358. auto chordId = c->arp.chord.empty() ? 1 : (c->arp.chord == std::vector<int> { 0 } ? 2 : 0);
  4359. for (int i = 0; chordId == 0 && i < (int) arpChords().size(); ++i)
  4360. if (arpChords()[(std::size_t) i].second == c->arp.chord)
  4361. chordId = i + 3;
  4362. arpChord.setSelectedId (chordId, juce::dontSendNotification);
  4363. if (chordId == 0)
  4364. arpChord.setText (tr ("Chord from FL"), juce::dontSendNotification);
  4365. }
  4366. int speed = 0;
  4367. for (int i = 0; i < (int) arpSpeeds().size(); ++i)
  4368. if (std::abs (arpSpeeds()[(std::size_t) i].second - c->arp.stepBeats) < 1e-4f)
  4369. speed = i + 1;
  4370. arpTime.setSelectedId (speed, juce::dontSendNotification);
  4371. if (speed == 0)
  4372. arpTime.setText (tr ("{0} beats", { juce::String (c->arp.stepBeats, 3) }), juce::dontSendNotification);
  4373. updating = false;
  4374. repaint();
  4375. }
  4376. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  4377. AudioEngine& engine;
  4378. int channel;
  4379. bool updating = false;
  4380. std::vector<std::unique_ptr<FrameKnob>> knobs;
  4381. FrameKnob *pan = nullptr, *volume = nullptr, *maxPoly = nullptr, *slide = nullptr, *swing = nullptr, *cut = nullptr, *cutBy = nullptr,
  4382. *arpRange = nullptr, *arpGate = nullptr, *arpRepeat = nullptr, *modX = nullptr, *modY = nullptr, *timeGate = nullptr,
  4383. *timeShift = nullptr, *trackPan = nullptr, *trackMid = nullptr, *echoFeed = nullptr, *echoPan = nullptr, *echoPitch = nullptr,
  4384. *echoTime = nullptr, *echoCount = nullptr, *trackModX = nullptr, *trackModY = nullptr, *echoModX = nullptr, *echoModY = nullptr,
  4385. *fineTune = nullptr;
  4386. juce::ToggleButton porta, mono, fullPorta, pingPong, fatMode, mainPitch, arpSlide, addToKey;
  4387. RootKeyboard rootKeys;
  4388. juce::TextButton rootReset;
  4389. int rootSection = -1;
  4390. juce::TextButton trackVol, trackKey;
  4391. juce::ComboBox arpChord;
  4392. juce::TextButton cutSelf;
  4393. juce::ComboBox arpDirection, arpTime;
  4394. std::vector<std::pair<juce::Rectangle<int>, juce::String>> sections;
  4395. };
  4396. // FL's preset arrows of a generator's window (round 167o, issue #24; FL's TPluginForm NextPrevPreset, FLEngine
  4397. // 0x12b6c70): ◀ name ▶ over the .fst presets of the plugin's folder (FL's factory folder and the user's, subfolders
  4398. // too) in FL's order; no preset yet: ▶ the first, ◀ the last; both wrap. The step loads the preset into the channel
  4399. // (one undo step), names the channel after it and says "n / N" in the hint bar, as FL. A click on the name lists them.
  4400. class ChannelPresetBar final : public juce::Component
  4401. {
  4402. public:
  4403. // after a preset is loaded (the channel's old name, the preset's): the window refreshes its page and title
  4404. std::function<void (const juce::String&, const juce::String&)> onLoaded;
  4405. ChannelPresetBar (AudioEngine& e, int c) : engine (e), channel (c)
  4406. {
  4407. for (auto* b : { &prev, &next })
  4408. {
  4409. b->setTooltip (b == &prev ? tr ("Previous preset") : tr ("Next preset"));
  4410. b->setWantsKeyboardFocus (false);
  4411. addAndMakeVisible (*b);
  4412. }
  4413. prev.onClick = [this] { step (-1); };
  4414. next.onClick = [this] { step (1); };
  4415. ui::setHint (*this, tr ("Presets: [LMB] the list, the arrows load the previous / next one"));
  4416. }
  4417. // Whether this channel's instrument has an FL preset folder (the bar is shown only then)
  4418. static bool wanted (const AudioEngine& engine, int channel)
  4419. {
  4420. const auto& song = engine.getSong();
  4421. if (! juce::isPositiveAndBelow (channel, (int) song.channels.size()))
  4422. return false;
  4423. const auto kind = song.channels[(std::size_t) channel].instrument;
  4424. return ! natives::presetFolderOf (kind).empty() || banks::hasBank (kind);
  4425. }
  4426. void resized() override
  4427. {
  4428. auto r = getLocalBounds();
  4429. prev.setBounds (r.removeFromLeft (24));
  4430. next.setBounds (r.removeFromRight (24));
  4431. nameArea = r.reduced (4, 0);
  4432. }
  4433. void paint (juce::Graphics& g) override
  4434. {
  4435. g.setColour (theme::colour::bg2);
  4436. g.fillRoundedRectangle (nameArea.toFloat(), theme::radius::sm);
  4437. g.setColour (current >= 0 ? theme::colour::textPrimary : theme::colour::textSecondary);
  4438. g.setFont (theme::font (theme::type::body));
  4439. g.drawText (current >= 0 ? currentName : tr ("Presets"), nameArea.reduced (6, 0), juce::Justification::centredLeft, true);
  4440. }
  4441. void mouseUp (const juce::MouseEvent& e) override
  4442. {
  4443. if (nameArea.contains (e.getPosition()) && ! e.mouseWasDraggedSinceMouseDown())
  4444. showMenu();
  4445. }
  4446. private:
  4447. const ChannelDef* def() const
  4448. {
  4449. const auto& song = engine.getSong();
  4450. return juce::isPositiveAndBelow (channel, (int) song.channels.size()) ? &song.channels[(std::size_t) channel] : nullptr;
  4451. }
  4452. const std::vector<presetcycle::Preset>& list()
  4453. {
  4454. const auto* d = def();
  4455. const auto kind = d != nullptr ? d->instrument : InstrumentKind::synth;
  4456. if (! loaded || kind != listedKind)
  4457. {
  4458. const auto folder = natives::presetFolderOf (kind);
  4459. presets = folder.empty() ? std::vector<presetcycle::Preset>()
  4460. : presetcycle::listPresets (presetcycle::pluginPresetFolders (flStudioAccess().roots, true, folder));
  4461. // LYNX's own bank after FL's presets (round 168n): the only presets without FL Studio
  4462. const auto& bank = banks::bankOf (kind);
  4463. for (int i = 0; i < (int) bank.size(); ++i)
  4464. presets.push_back ({ banks::pathOf (i), banks::relativeOf (bank[(std::size_t) i]), bank[(std::size_t) i].name });
  4465. listedKind = kind;
  4466. loaded = true;
  4467. current = d != nullptr ? presetcycle::indexOfName (presets, d->name) : -1; // (a channel named after its preset)
  4468. currentName = current >= 0 ? juce::String::fromUTF8 (presets[(std::size_t) current].name.c_str()) : juce::String();
  4469. }
  4470. return presets;
  4471. }
  4472. void step (int delta)
  4473. {
  4474. const auto& all = list();
  4475. const auto count = (int) all.size();
  4476. // FL's next index; a preset LYNX can't read (an unknown or damaged state) is passed over in the same
  4477. // direction, so the arrows keep going
  4478. auto at = presetcycle::step (current, delta, count);
  4479. for (int tries = 0; at >= 0 && tries < count; ++tries)
  4480. {
  4481. if (load (at, tries == count - 1))
  4482. return;
  4483. at = presetcycle::step (at, delta, count);
  4484. }
  4485. }
  4486. bool load (int index, bool reportFailure = true)
  4487. {
  4488. const auto& all = list();
  4489. const auto* d = def();
  4490. if (d == nullptr || ! juce::isPositiveAndBelow (index, (int) all.size()))
  4491. return false;
  4492. const auto& preset = all[(std::size_t) index];
  4493. const auto bankIndex = banks::indexOfPath (preset.path);
  4494. auto changed = bankIndex >= 0 ? banks::withPreset (*d, bankIndex) : natives::withPreset (*d, preset.path, preset.name, flStudioAccess());
  4495. if (! changed)
  4496. {
  4497. if (reportFailure)
  4498. ui::postHint ({ tr ("This preset could not be read: {0}", { juce::String::fromUTF8 (preset.name.c_str()) }), {} }, 2500);
  4499. current = index; // (the next step goes on from it)
  4500. return false;
  4501. }
  4502. const auto kind = d->instrument;
  4503. const auto oldName = juce::String::fromUTF8 (d->name.c_str());
  4504. engine.editSong ([ch = channel, kind, c = std::move (*changed)] (Song& s) {
  4505. if (ch < (int) s.channels.size() && s.channels[(std::size_t) ch].instrument == kind)
  4506. s.channels[(std::size_t) ch] = c;
  4507. });
  4508. if (onLoaded != nullptr)
  4509. onLoaded (oldName, juce::String::fromUTF8 (preset.name.c_str()));
  4510. current = index;
  4511. currentName = juce::String::fromUTF8 (preset.name.c_str());
  4512. ui::postHint ({ currentName, juce::String (presetcycle::positionText (index, (int) all.size())) }, 2500);
  4513. repaint();
  4514. return true;
  4515. }
  4516. void showMenu()
  4517. {
  4518. const auto& all = list();
  4519. juce::PopupMenu menu;
  4520. std::map<std::string, juce::PopupMenu> folders;
  4521. std::vector<std::string> order;
  4522. for (int i = 0; i < (int) all.size(); ++i)
  4523. {
  4524. const auto& rel = all[(std::size_t) i].relative;
  4525. const auto slash = rel.find_last_of ('/');
  4526. const auto folder = slash == std::string::npos ? std::string() : rel.substr (0, slash);
  4527. if (folders.find (folder) == folders.end())
  4528. order.push_back (folder);
  4529. folders[folder].addItem (juce::String::fromUTF8 (all[(std::size_t) i].name.c_str()), true, i == current, [this, i] { load (i); });
  4530. }
  4531. for (const auto& folder : order)
  4532. if (folder.empty())
  4533. for (juce::PopupMenu::MenuItemIterator it (folders[folder]); it.next();)
  4534. menu.addItem (it.getItem());
  4535. else
  4536. menu.addSubMenu (juce::String::fromUTF8 (folder.c_str()), folders[folder]);
  4537. if (menu.getNumItems() == 0)
  4538. menu.addItem (tr ("No presets found (they come with FL Studio)"), false, false, [] {});
  4539. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
  4540. }
  4541. AudioEngine& engine;
  4542. int channel;
  4543. juce::TextButton prev { juce::String::fromUTF8 ("\xe2\x97\x80") }, next { juce::String::fromUTF8 ("\xe2\x96\xb6") };
  4544. juce::Rectangle<int> nameArea;
  4545. std::vector<presetcycle::Preset> presets;
  4546. InstrumentKind listedKind = InstrumentKind::synth;
  4547. bool loaded = false;
  4548. int current = -1;
  4549. juce::String currentName;
  4550. };
  4551. // The frame: header strip (tabs on the left; ON, PAN, VOL, TRACK on the right) over the page of the selected tab.
  4552. class ChannelFrame final : public juce::Component,
  4553. private juce::ChangeListener
  4554. {
  4555. public:
  4556. static constexpr int headerHeight = 62;
  4557. // c.index < 0 (a Patcher node, round 164f): the instrument's pages alone, without the channel's header and Misc tab
  4558. ChannelFrame (AudioEngine& e, ChannelRef c, std::unique_ptr<juce::Component> instrumentPage, std::unique_ptr<juce::Component> envelopePage)
  4559. : engine (e), channel (c.index), node (c.index < 0)
  4560. {
  4561. auto addPage = [this] (std::unique_ptr<juce::Component> page, const juce::String& title, const juce::String& tip) {
  4562. auto button = std::make_unique<juce::TextButton> (title);
  4563. button->setTooltip (tip);
  4564. button->setClickingTogglesState (true);
  4565. button->setRadioGroupId (1);
  4566. const auto index = (int) pages.size();
  4567. button->onClick = [this, index] { showTab (index); };
  4568. addAndMakeVisible (*button);
  4569. addChildComponent (*page);
  4570. sizes.push_back ({ juce::jmax (1, page->getWidth()), juce::jmax (1, page->getHeight()) });
  4571. tabs.push_back (std::move (button));
  4572. pages.push_back (std::move (page));
  4573. };
  4574. instrumentPageFirst = instrumentPage != nullptr;
  4575. if (instrumentPage != nullptr) // (none: a channel whose instrument has its own window, e.g. a hosted plugin)
  4576. addPage (std::move (instrumentPage), tr ("Plugin"), tr ("The instrument's own settings"));
  4577. if (envelopePage != nullptr)
  4578. addPage (std::move (envelopePage), tr ("Envelope / instrument"), tr ("Envelope / instrument settings: the filter and pitch envelopes and the LFOs"));
  4579. if (node)
  4580. {
  4581. int width = 1, height = 1;
  4582. for (auto& p : pages)
  4583. {
  4584. width = juce::jmax (width, p->getWidth());
  4585. height = juce::jmax (height, p->getHeight());
  4586. }
  4587. setSize (width, headerHeight + height);
  4588. showTab (0);
  4589. return;
  4590. }
  4591. addPage (std::make_unique<MiscPanel> (engine, channel), tr ("Misc"), tr ("Miscellaneous functions: levels, polyphony, time, tracking, cut groups, arpeggiator, echo delay"));
  4592. on.setButtonText (tr ("On"));
  4593. on.setTooltip (tr ("Channel on / off (mute)"));
  4594. on.onClick = [this] {
  4595. const auto muted = ! on.getToggleState();
  4596. engine.editSong ([ch = channel, muted] (Song& s) {
  4597. if (ch < (int) s.channels.size())
  4598. s.channels[(std::size_t) ch].muted = muted;
  4599. });
  4600. };
  4601. addAndMakeVisible (on);
  4602. if (ChannelPresetBar::wanted (engine, channel))
  4603. {
  4604. presetBar = std::make_unique<ChannelPresetBar> (engine, channel);
  4605. presetBar->onLoaded = [this, hasPage = instrumentPageFirst] (const juce::String& oldName, const juce::String& newName) {
  4606. // the plugin page shows the new preset's settings, the window takes the channel's new name (as FL)
  4607. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<ChannelFrame> (this), hasPage, oldName, newName] {
  4608. if (safe != nullptr)
  4609. safe->presetLoaded (hasPage, oldName, newName);
  4610. });
  4611. };
  4612. addAndMakeVisible (*presetBar);
  4613. }
  4614. const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
  4615. auto headerKnob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get, std::function<void (Song&, int, double)> set,
  4616. const char* caption) {
  4617. auto k = std::make_unique<FrameKnob> (
  4618. engine, std::move (spec),
  4619. [this, get] { return channel < (int) engine.getSong().channels.size() ? get (engine.getSong().channels[(std::size_t) channel]) : 0.0; },
  4620. [this, set] (double v) {
  4621. engine.editSong ([ch = channel, set, v] (Song& s) {
  4622. if (ch < (int) s.channels.size())
  4623. set (s, ch, v);
  4624. });
  4625. },
  4626. tr (caption));
  4627. addAndMakeVisible (*k);
  4628. header.push_back (std::move (k));
  4629. };
  4630. headerKnob ([this, name] {
  4631. auto s = ui::panSpec (name() + " - " + tr ("Pan"));
  4632. s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
  4633. return s;
  4634. },
  4635. [] (const ChannelDef& d) { return (double) d.pan; }, [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].pan = (float) v; },
  4636. TR_NOOP ("Pan"));
  4637. headerKnob ([this, name] {
  4638. auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
  4639. s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
  4640. return s;
  4641. },
  4642. [] (const ChannelDef& d) { return (double) d.volume; },
  4643. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].volume = (float) v; }, TR_NOOP ("Vol"));
  4644. // FL's PITCH knob and its RANGE (REA round 146b): the channel's pitch, within ± range semitones
  4645. headerKnob ([this, name] {
  4646. ui::ValueSpec s;
  4647. s.name = name() + " - " + tr ("Pitch (semitones, within the range)");
  4648. const auto range = channel < (int) engine.getSong().channels.size() ? engine.getSong().channels[(std::size_t) channel].misc.pitchRange : 2;
  4649. s.minimum = -juce::jmax (1, range);
  4650. s.maximum = juce::jmax (1, range);
  4651. s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v * 100.0)) }); };
  4652. return s;
  4653. },
  4654. [] (const ChannelDef& d) { return (double) d.sampler.pitch; },
  4655. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].sampler.pitch = (float) juce::jlimit (-24.0, 24.0, v); }, TR_NOOP ("Pitch"));
  4656. headerKnob ([name] { return ui::digitWheel (countSpec (name() + " - " + tr ("Pitch knob range (semitones)"), 48, 2,
  4657. [] (int v) { return juce::String (v); })); },
  4658. [] (const ChannelDef& d) { return (double) d.misc.pitchRange; },
  4659. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].misc.pitchRange = juce::jlimit (0, 48, juce::roundToInt (v)); },
  4660. TR_NOOP ("Range"));
  4661. header.back()->digitBox = true;
  4662. // FL's TRACK digiwheel (round 168s, issue #32 "very small and not accurate"): a wheel notch or 7.5 px of drag = the
  4663. // next insert, double-click shows the insert in the Mixer, the menu has "Assign to free mixer track"
  4664. headerKnob ([this, name] {
  4665. return ui::digitWheel (countSpec (name() + " - " + tr ("Target mixer track"), maxMixerTracks - 1, 0,
  4666. [] (int t) { return t == 0 ? tr ("Master") : juce::String (t); }));
  4667. },
  4668. [] (const ChannelDef& d) { return (double) d.mixerTrack; },
  4669. [] (Song& s, int ch, double v) {
  4670. mixerops::routeChannel (s, ch, juce::roundToInt (v)); // any insert (round 162): missing ones are added
  4671. },
  4672. TR_NOOP ("Track"));
  4673. {
  4674. auto& track = *header.back();
  4675. track.digitBox = true;
  4676. track.doubleClicked = [this] {
  4677. if (channel < (int) engine.getSong().channels.size() && openMixerInsertHandler())
  4678. openMixerInsertHandler() (engine.getSong().channels[(std::size_t) channel].mixerTrack);
  4679. };
  4680. track.extraMenuItems = [this] (juce::PopupMenu& menu) {
  4681. menu.addItem (tr ("Assign to free mixer track"), [this] {
  4682. engine.editSong ([ch = channel] (Song& s) {
  4683. if (ch < (int) s.channels.size())
  4684. s.channels[(std::size_t) ch].mixerTrack = s.claimFreeInsert();
  4685. });
  4686. });
  4687. };
  4688. }
  4689. int width = MiscPanel::preferredWidth, height = MiscPanel::preferredHeight;
  4690. for (auto& p : pages)
  4691. {
  4692. width = juce::jmax (width, p->getWidth());
  4693. height = juce::jmax (height, p->getHeight());
  4694. }
  4695. refresh();
  4696. engine.addChangeListener (this);
  4697. setSize (width, headerHeight + height);
  4698. showTab (0);
  4699. }
  4700. ~ChannelFrame() override
  4701. {
  4702. if (! node)
  4703. engine.removeChangeListener (this);
  4704. }
  4705. void showTab (int index)
  4706. {
  4707. index = juce::jlimit (0, (int) pages.size() - 1, index);
  4708. current = index;
  4709. for (int i = 0; i < (int) pages.size(); ++i)
  4710. {
  4711. pages[(std::size_t) i]->setVisible (i == index);
  4712. tabs[(std::size_t) i]->setToggleState (i == index, juce::dontSendNotification);
  4713. }
  4714. }
  4715. void presetLoaded (bool hasPage, const juce::String& oldName, const juce::String& newName)
  4716. {
  4717. if (hasPage && ! pages.empty())
  4718. if (auto fresh = makeChannelSettingsPanel (engine, channel))
  4719. {
  4720. removeChildComponent (pages.front().get());
  4721. pages.front() = std::move (fresh);
  4722. addChildComponent (*pages.front());
  4723. resized();
  4724. showTab (current);
  4725. }
  4726. if (auto* window = findParentComponentOfClass<juce::DocumentWindow>())
  4727. if (const auto title = window->getName(); oldName.isNotEmpty() && title.startsWith (oldName))
  4728. window->setName (newName + title.substring (oldName.length()));
  4729. }
  4730. int getTab() const noexcept { return current; }
  4731. int tabCount() const noexcept { return (int) pages.size(); }
  4732. void paint (juce::Graphics& g) override
  4733. {
  4734. g.fillAll (theme::colour::bg2);
  4735. g.setColour (theme::colour::bg3);
  4736. g.fillRect (getLocalBounds().removeFromTop (headerHeight));
  4737. g.setColour (theme::colour::border);
  4738. g.drawHorizontalLine (headerHeight - 1, 0.0f, (float) getWidth());
  4739. }
  4740. void resized() override
  4741. {
  4742. auto tabsArea = getLocalBounds().removeFromTop (headerHeight).reduced (8, 6);
  4743. if (presetBar != nullptr) // tabs on the upper row, the preset arrows under them
  4744. {
  4745. presetBar->setBounds (tabsArea.removeFromBottom (22).removeFromLeft (juce::jmin (300, tabsArea.getWidth())));
  4746. tabsArea.removeFromBottom (2);
  4747. }
  4748. for (auto& t : tabs)
  4749. {
  4750. const auto w = juce::jmax (64, (int) juce::GlyphArrangement::getStringWidth (juce::Font (theme::font (theme::type::body)), t->getButtonText()) + 24);
  4751. t->setBounds (tabsArea.removeFromLeft (w).withSizeKeepingCentre (w, juce::jmin (26, tabsArea.getHeight())));
  4752. tabsArea.removeFromLeft (4);
  4753. }
  4754. auto right = getLocalBounds().removeFromTop (headerHeight).reduced (6, 2);
  4755. for (auto it = header.rbegin(); it != header.rend(); ++it)
  4756. (*it)->setBounds (right.removeFromRight (48));
  4757. on.setBounds (right.removeFromRight (52).withSizeKeepingCentre (52, 24));
  4758. // each page keeps its own size (some scale their drawing with it), centred under the header
  4759. const auto body = getLocalBounds().withTrimmedTop (headerHeight);
  4760. for (std::size_t i = 0; i < pages.size(); ++i)
  4761. {
  4762. const auto w = juce::jmin (body.getWidth(), sizes[i].x), h = juce::jmin (body.getHeight(), sizes[i].y);
  4763. pages[i]->setBounds (body.getX() + (body.getWidth() - w) / 2, body.getY(), w, h);
  4764. }
  4765. }
  4766. private:
  4767. void refresh()
  4768. {
  4769. if (channel < (int) engine.getSong().channels.size())
  4770. on.setToggleState (! engine.getSong().channels[(std::size_t) channel].muted, juce::dontSendNotification);
  4771. for (auto& k : header)
  4772. k->repaint();
  4773. }
  4774. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  4775. AudioEngine& engine;
  4776. int channel;
  4777. bool node = false;
  4778. int current = 0;
  4779. std::vector<std::unique_ptr<juce::TextButton>> tabs;
  4780. std::vector<std::unique_ptr<juce::Component>> pages;
  4781. std::vector<juce::Point<int>> sizes;
  4782. std::vector<std::unique_ptr<FrameKnob>> header;
  4783. juce::ToggleButton on;
  4784. std::unique_ptr<ChannelPresetBar> presetBar;
  4785. bool instrumentPageFirst = false;
  4786. };
  4787. bool hasEnvelopeTab (InstrumentKind kind) noexcept
  4788. {
  4789. return kind == InstrumentKind::synth || kind == InstrumentKind::sampler;
  4790. }
  4791. void showModulationFor (juce::Component& from, AudioEngine& engine, int channel)
  4792. {
  4793. if (auto* frame = from.findParentComponentOfClass<ChannelFrame>(); frame != nullptr && frame->tabCount() >= 2)
  4794. frame->showTab (1);
  4795. else if (channel >= 0)
  4796. openChannelModulation (engine, channel);
  4797. }
  4798. bool isModelKind (InstrumentKind kind) noexcept
  4799. {
  4800. return kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
  4801. || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
  4802. || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
  4803. || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
  4804. || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::keplerExo || kind == InstrumentKind::poizone
  4805. || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
  4806. || kind == InstrumentKind::threeosc
  4807. || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
  4808. || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
  4809. || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
  4810. || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
  4811. || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus;
  4812. }
  4813. // The instrument page of a channel or a Patcher node (null: none of its own)
  4814. std::unique_ptr<juce::Component> makeInstrumentPage (AudioEngine& engine, const ChannelRef& ref)
  4815. {
  4816. const auto* def = ref.get (engine);
  4817. if (def == nullptr)
  4818. return nullptr;
  4819. const auto kind = def->instrument;
  4820. if (kind == InstrumentKind::fruitydance && ref.index >= 0)
  4821. return makeDanceEditor (engine, ref.index); // round 165e
  4822. if (kind == InstrumentKind::videoplayer)
  4823. return makeVideoPlayerEditor (engine, ref.locate, ref.index); // round 165g
  4824. if (kind == InstrumentKind::wavetraveller)
  4825. return makeWaveTravellerEditor (engine, ref.locate, ref.index); // round 167f
  4826. if (kind == InstrumentKind::synth)
  4827. return std::make_unique<SynthPanel> (engine, ref);
  4828. if (isModelKind (kind))
  4829. return std::make_unique<ModelPanel> (engine, ref);
  4830. if (kind == InstrumentKind::sampler)
  4831. return std::make_unique<SettingsPanel> (engine, ref);
  4832. return nullptr;
  4833. }
  4834. // Where "Align all channel editors" put every channel editor (FL stores it per channel, so editors opened later come
  4835. // up there too); empty = centred, as before.
  4836. std::optional<juce::Point<int>>& alignedChannelEditorPosition()
  4837. {
  4838. static std::optional<juce::Point<int>> at;
  4839. return at;
  4840. }
  4841. class SettingsWindow final : public juce::DocumentWindow
  4842. {
  4843. public:
  4844. SettingsWindow (AudioEngine& engine, int c, bool modulationWindow)
  4845. : juce::DocumentWindow (tr ("Channel settings"), theme::colour::bg2, DocumentWindow::closeButton),
  4846. channel (c),
  4847. modulation (modulationWindow)
  4848. {
  4849. setUsingNativeTitleBar (true);
  4850. // FL names the window after the channel and its mixer track (REA round 149 [EXEC]: "FL Studio VSTi (Master)",
  4851. // "Synth Bass (Synth Bass)")
  4852. if (const auto& song = engine.getSong(); channel >= 0 && channel < (int) song.channels.size())
  4853. {
  4854. const auto& def = song.channels[(std::size_t) channel];
  4855. const auto t = def.mixerTrack;
  4856. const auto track = t <= 0 || t >= (int) song.mixer.size() ? tr ("Master")
  4857. : song.mixer[(std::size_t) t].name.empty() ? tr ("Insert {0}", { juce::String (t) })
  4858. : juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  4859. setName (juce::String::fromUTF8 (def.name.c_str()) + " (" + track + ")"
  4860. + (modulation ? " - " + tr ("Envelope / instrument") : juce::String()));
  4861. }
  4862. if (modulation)
  4863. setContentOwned (new ModulationPanel (engine, ChannelRef::rack (channel)), true);
  4864. else if (! hasChannelSettings (engine.getSong().channels[(std::size_t) channel].instrument))
  4865. setContentOwned (new ChannelFrame (engine, ChannelRef::rack (channel), nullptr, nullptr), true); // the Misc tab alone
  4866. else
  4867. setContentOwned (makeChannelFrame (engine, channel).release(), true);
  4868. centreWithSize (getWidth(), getHeight());
  4869. if (! modulation)
  4870. if (const auto& at = alignedChannelEditorPosition(); at.has_value())
  4871. setTopLeftPosition (*at); // "Align all channel editors" set every channel's place (round 169k)
  4872. setVisible (true);
  4873. keepAboveMainWindow (*this);
  4874. }
  4875. int getChannel() const { return channel; }
  4876. bool isModulation() const { return modulation; }
  4877. void closeButtonPressed() override;
  4878. private:
  4879. int channel;
  4880. bool modulation;
  4881. };
  4882. std::vector<std::unique_ptr<SettingsWindow>>& windows()
  4883. {
  4884. static std::vector<std::unique_ptr<SettingsWindow>> open;
  4885. return open;
  4886. }
  4887. void SettingsWindow::closeButtonPressed()
  4888. {
  4889. auto* self = this;
  4890. juce::MessageManager::callAsync ([self] {
  4891. auto& open = windows();
  4892. open.erase (std::remove_if (open.begin(), open.end(), [self] (auto& w) { return w.get() == self; }), open.end());
  4893. });
  4894. }
  4895. } // namespace
  4896. namespace
  4897. {
  4898. void openWindow (AudioEngine& engine, int channel, bool modulation)
  4899. {
  4900. for (auto& w : windows())
  4901. if (w->getChannel() == channel && w->isModulation() == modulation)
  4902. {
  4903. w->toFront (true);
  4904. return;
  4905. }
  4906. windows().push_back (std::make_unique<SettingsWindow> (engine, channel, modulation));
  4907. }
  4908. } // namespace
  4909. void alignAllChannelEditors (int selectedChannel)
  4910. {
  4911. // FL's AlignAllChannelEditorsAction (FUN_012317c0, REA_rodada169k §2.4): the focused channel editor (else the
  4912. // selected channel's, else the first open one) gives the place; every channel editor goes there.
  4913. auto& open = windows();
  4914. SettingsWindow* reference = nullptr;
  4915. for (auto& w : open)
  4916. if (! w->isModulation() && w->isActiveWindow())
  4917. reference = w.get();
  4918. for (auto& w : open)
  4919. if (reference == nullptr && ! w->isModulation() && w->getChannel() == selectedChannel)
  4920. reference = w.get();
  4921. for (auto& w : open)
  4922. if (reference == nullptr && ! w->isModulation())
  4923. reference = w.get();
  4924. if (reference == nullptr)
  4925. return;
  4926. const auto at = reference->getPosition();
  4927. alignedChannelEditorPosition() = at;
  4928. for (auto& w : open)
  4929. if (! w->isModulation())
  4930. w->setTopLeftPosition (at);
  4931. reference->toFront (true);
  4932. }
  4933. void openChannelSettings (AudioEngine& engine, int channel)
  4934. {
  4935. openWindow (engine, channel, false);
  4936. }
  4937. void openChannelMisc (AudioEngine& engine, int channel)
  4938. {
  4939. openWindow (engine, channel, false);
  4940. for (auto& w : windows())
  4941. if (w->getChannel() == channel && ! w->isModulation())
  4942. if (auto* frame = dynamic_cast<ChannelFrame*> (w->getContentComponent()))
  4943. frame->showTab (frame->tabCount() - 1);
  4944. }
  4945. void openChannelModulation (AudioEngine& engine, int channel)
  4946. {
  4947. openWindow (engine, channel, true);
  4948. }
  4949. void closeChannelSettings()
  4950. {
  4951. windows().clear();
  4952. }
  4953. bool hasChannelSettings (InstrumentKind kind) noexcept
  4954. {
  4955. switch (kind)
  4956. {
  4957. case InstrumentKind::synth:
  4958. case InstrumentKind::sampler:
  4959. case InstrumentKind::controller:
  4960. case InstrumentKind::midiOut:
  4961. case InstrumentKind::sakura:
  4962. case InstrumentKind::drumpad:
  4963. case InstrumentKind::boobass:
  4964. case InstrumentKind::drumsynth:
  4965. case InstrumentKind::harmless:
  4966. case InstrumentKind::harmor:
  4967. case InstrumentKind::gms:
  4968. case InstrumentKind::morphine:
  4969. case InstrumentKind::ogun:
  4970. case InstrumentKind::minisynth:
  4971. case InstrumentKind::dx10:
  4972. case InstrumentKind::kepler:
  4973. case InstrumentKind::keplerExo:
  4974. case InstrumentKind::poizone:
  4975. case InstrumentKind::fruitkick:
  4976. case InstrumentKind::bassdrum:
  4977. case InstrumentKind::toxic:
  4978. case InstrumentKind::threeosc:
  4979. case InstrumentKind::autogun:
  4980. case InstrumentKind::transistorbass:
  4981. case InstrumentKind::simsynth:
  4982. case InstrumentKind::wasp:
  4983. case InstrumentKind::plucked:
  4984. case InstrumentKind::beepmap:
  4985. case InstrumentKind::sawer:
  4986. case InstrumentKind::flkeys:
  4987. case InstrumentKind::granulizer:
  4988. case InstrumentKind::drumaxx:
  4989. case InstrumentKind::slayer:
  4990. case InstrumentKind::fruitydance:
  4991. case InstrumentKind::sytrus:
  4992. case InstrumentKind::soundfont:
  4993. case InstrumentKind::layer:
  4994. case InstrumentKind::dashboard:
  4995. case InstrumentKind::voltage:
  4996. case InstrumentKind::vfx:
  4997. case InstrumentKind::wavetraveller:
  4998. return true;
  4999. default:
  5000. return false;
  5001. }
  5002. }
  5003. bool isChannelSettingsOpen (int channel)
  5004. {
  5005. return std::any_of (windows().begin(), windows().end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); });
  5006. }
  5007. void closeChannelSettings (int channel)
  5008. {
  5009. auto& open = windows();
  5010. open.erase (std::remove_if (open.begin(), open.end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); }),
  5011. open.end());
  5012. }
  5013. std::unique_ptr<juce::Component> makeChannelModulationPanel (AudioEngine& engine, int channel)
  5014. {
  5015. return std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel));
  5016. }
  5017. std::unique_ptr<juce::Component> makeChannelPrecomputePanel (AudioEngine& engine, int channel)
  5018. {
  5019. return std::make_unique<PrecomputePanel> (engine, ChannelRef::rack (channel));
  5020. }
  5021. int showChannelLayoutPage (juce::Component& frame, int page)
  5022. {
  5023. if (auto* panel = dynamic_cast<ModelPanel*> (&frame); panel != nullptr && panel->pageCount() > 0)
  5024. {
  5025. const auto count = panel->pageCount();
  5026. if (page >= 0 && page < count)
  5027. panel->showPage (page);
  5028. return count;
  5029. }
  5030. for (auto* child : frame.getChildren())
  5031. if (const auto count = showChannelLayoutPage (*child, page); count > 0)
  5032. return count;
  5033. return 0;
  5034. }
  5035. std::unique_ptr<juce::Component> makeChannelFrame (AudioEngine& engine, int channel, int tab)
  5036. {
  5037. const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
  5038. auto frame = std::make_unique<ChannelFrame> (engine, ChannelRef::rack (channel), makeChannelSettingsPanel (engine, channel),
  5039. hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel)) : nullptr);
  5040. frame->showTab (tab < 0 ? frame->tabCount() - 1 : tab);
  5041. return frame;
  5042. }
  5043. std::unique_ptr<juce::Component> makeChannelSettingsPanel (AudioEngine& engine, int channel)
  5044. {
  5045. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::synth)
  5046. return std::make_unique<SynthPanel> (engine, ChannelRef::rack (channel));
  5047. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::controller)
  5048. {
  5049. if (parseKeyboardController (engine.getSong().channels[(std::size_t) channel].controllerState))
  5050. return makeKeyboardControllerEditor (engine, channel); // round 165c (it showed the Envelope Controller's read-only page)
  5051. return makeEnvelopeControllerEditor (engine, channel);
  5052. }
  5053. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::midiOut)
  5054. return makeMidiOutEditor (engine, channel);
  5055. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::soundfont)
  5056. return makeSoundFontEditor (engine, channel);
  5057. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::layer)
  5058. return makeLayerEditor (engine, channel);
  5059. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::dashboard)
  5060. return makeDashboardEditor (engine, channel);
  5061. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::voltage)
  5062. return makeVoltageControllerEditor (engine, channel);
  5063. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::vfx)
  5064. return makeVfxEditor (engine, channel);
  5065. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::fruitydance)
  5066. return makeDanceEditor (engine, channel); // round 165e
  5067. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::videoplayer)
  5068. return makeVideoPlayerEditor (engine, channel); // round 165g
  5069. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::wavetraveller)
  5070. return makeWaveTravellerEditor (engine, channel); // round 167f
  5071. if (const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
  5072. kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
  5073. || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
  5074. || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
  5075. || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
  5076. || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::keplerExo || kind == InstrumentKind::poizone
  5077. || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
  5078. || kind == InstrumentKind::threeosc
  5079. || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
  5080. || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
  5081. || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
  5082. || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
  5083. || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus)
  5084. return std::make_unique<ModelPanel> (engine, ChannelRef::rack (channel));
  5085. return std::make_unique<SettingsPanel> (engine, ChannelRef::rack (channel));
  5086. }
  5087. bool hasNodeEditor (const ChannelDef& channel) noexcept
  5088. {
  5089. return channel.instrument == InstrumentKind::synth || channel.instrument == InstrumentKind::sampler || isModelKind (channel.instrument);
  5090. }
  5091. std::unique_ptr<juce::Component> makeNodeChannelFrame (AudioEngine& engine, std::function<ChannelDef* (Song&)> locate)
  5092. {
  5093. ChannelRef ref { std::move (locate), -1 };
  5094. const auto* def = ref.get (engine);
  5095. if (def == nullptr)
  5096. return nullptr;
  5097. auto page = makeInstrumentPage (engine, ref);
  5098. if (page == nullptr)
  5099. return nullptr;
  5100. const auto kind = def->instrument;
  5101. return std::make_unique<ChannelFrame> (engine, ref, std::move (page), hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ref) : nullptr);
  5102. }
  5103. std::function<void (int)>& openMixerInsertHandler()
  5104. {
  5105. static std::function<void (int)> handler;
  5106. return handler;
  5107. }
  5108. } // namespace lynx