ChannelSettings.cpp 270 KB

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