ChannelSettings.cpp 269 KB

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