ChannelSettings.cpp 279 KB

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