| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430 |
- #include <optional>
- #include "ui/WindowOwner.h"
- #include "core/NoteNames.h"
- #include "ui/ChannelSettings.h"
- #include "ui/FileChoosers.h"
- #include "ui/LayerEditor.h"
- #include "ui/DanceView.h"
- #include "ui/Controllers164.h"
- #include "ui/VoltageEditor.h"
- #include "ui/AutomationUi.h"
- #include "ui/BrowserComponent.h"
- #include "core/MixerOps.h"
- #include "core/ClipOps.h"
- #include "core/TempoDetect.h"
- #include <cstring>
- #include <functional>
- #include "core/DrumSynthLive.h"
- #include "core/FlSynths.h"
- #include "core/FlKeys.h"
- #include "core/ChannelMiscFx.h"
- #include "core/FlpImport.h"
- #include "core/Harmor.h"
- #include "core/Gms.h"
- #include "core/MiniSynth.h"
- #include "core/SimSynth.h"
- #include "core/Drumaxx.h"
- #include "core/DrumControls.h"
- #include <map>
- #include "core/Granulizer.h"
- #include "core/Morphine.h"
- #include "core/Ogun.h"
- #include "core/Dx10.h"
- #include "core/Kepler.h"
- #include "core/PoiZone.h"
- #include "core/LynxBanks.h"
- #include "core/ModelParams.h"
- #include "core/BassDrum.h"
- #include "core/FruitKick.h"
- #include "core/Toxic.h"
- #include "core/ThreeOsc.h"
- #include "core/BeepMap.h"
- #include "core/Sawer.h"
- #include "core/TransistorBass.h"
- #include "core/Slayer.h"
- #include "core/SytrusEngine.h"
- #include "core/SynthPresets.h"
- #include "core/PluginLayout.h"
- #include "engine/SampleLibrary.h"
- #include "engine/Text.h"
- #include "core/RackOps.h"
- #include "core/NativeEngines.h"
- #include "core/PresetCycle.h"
- #include "ui/ControllerEditors.h"
- #include "ui/HintBar.h"
- #include "ui/ValueControl.h"
- #include "ui/I18n.h"
- #include "ui/PluginSkin.h"
- #include "ui/Theme.h"
- #include "ui/WaveformView.h"
- #include "ui/SoundFontEditor.h"
- #include "ui/VfxEditors.h"
- #include "ui/VideoPlayerView.h"
- #include "ui/WaveTravellerEditor.h"
- #include "ui/BrowserComponent.h"
- #include "engine/SampleLibrary.h"
- #include "core/SampleFiles.h"
- #include "core/ProjectContents.h"
- namespace lynx
- {
- namespace
- {
- // Which channel a page edits (round 164f): a Channel Rack channel, or the generator of a Patcher node found through
- // `locate` (index −1) — the same pages edit both, so a node opens the editor its engine has on a channel.
- struct ChannelRef
- {
- std::function<ChannelDef* (Song&)> locate;
- int index = -1; // the Channel Rack index (automation targets, its windows); −1 = a Patcher node
- static ChannelRef rack (int c)
- {
- return { [c] (Song& s) -> ChannelDef* { return c >= 0 && c < (int) s.channels.size() ? &s.channels[(std::size_t) c] : nullptr; }, c };
- }
- const ChannelDef* get (const AudioEngine& engine) const { return locate ? locate (const_cast<Song&> (engine.getSong())) : nullptr; }
- void edit (AudioEngine& engine, std::function<void (ChannelDef&)> change, bool undoable = true) const
- {
- engine.editSong ([l = locate, change = std::move (change)] (Song& s) {
- if (auto* d = l ? l (s) : nullptr)
- change (*d);
- }, undoable);
- }
- };
- void showModulationFor (juce::Component& from, AudioEngine& engine, int channel);
- // Cutoff and pitch envelopes (FL's channel envelopes), used by the synth and the sampler.
- class ModEnvelopeEditor final : public juce::Component
- {
- public:
- std::function<void()> onChange;
- static constexpr int preferredHeight = 16 + 2 * 62;
- ModEnvelopeEditor()
- {
- const juce::String titles[] = { tr ("Cutoff env."), tr ("Pitch env.") };
- for (int e = 0; e < 2; ++e)
- {
- auto& row = rows[(std::size_t) e];
- row.title.setText (titles[e], juce::dontSendNotification);
- row.title.setFont (theme::font (theme::type::small));
- addAndMakeVisible (row.title);
- knob (row.amount, e == 0 ? -10.0 : -48.0, e == 0 ? 10.0 : 48.0, 0.01, e == 0 ? " oct" : " st");
- row.amount.setDoubleClickReturnValue (true, 0.0);
- row.amount.setTooltip (tr ("0 = off"));
- for (auto* s : { &row.attack, &row.hold, &row.decay, &row.release })
- {
- knob (*s, 0.0, 10.0, 0.001, " s");
- s->setSkewFactorFromMidPoint (0.5);
- }
- knob (row.sustain, 0.0, 1.0, 0.01, "");
- }
- const char* names[] = { TR_NOOP ("Amount"), TR_NOOP ("Attack"), TR_NOOP ("Hold"), TR_NOOP ("Decay"), TR_NOOP ("Sustain"), TR_NOOP ("Release") };
- for (int i = 0; i < 6; ++i)
- {
- labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
- labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
- labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
- addAndMakeVisible (labels[(std::size_t) i]);
- }
- }
- void resized() override
- {
- auto area = getLocalBounds();
- auto header = area.removeFromTop (16);
- header.removeFromLeft (80);
- const auto w = header.getWidth() / 6;
- for (auto& l : labels)
- l.setBounds (header.removeFromLeft (w));
- for (auto& row : rows)
- {
- auto line = area.removeFromTop (62);
- row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
- for (auto* s : { &row.amount, &row.attack, &row.hold, &row.decay, &row.sustain, &row.release })
- s->setBounds (line.removeFromLeft (w));
- }
- }
- void show (const ModEnvelope& filter, const ModEnvelope& pitch)
- {
- rows[0].show (filter);
- rows[1].show (pitch);
- }
- ModEnvelope filter() const { return rows[0].read(); }
- ModEnvelope pitch() const { return rows[1].read(); }
- private:
- struct Row
- {
- juce::Label title;
- juce::Slider amount, attack, hold, decay, sustain, release;
- void show (const ModEnvelope& e)
- {
- amount.setValue (e.amount, juce::dontSendNotification);
- attack.setValue (e.attack, juce::dontSendNotification);
- hold.setValue (e.hold, juce::dontSendNotification);
- decay.setValue (e.decay, juce::dontSendNotification);
- sustain.setValue (e.sustain, juce::dontSendNotification);
- release.setValue (e.release, juce::dontSendNotification);
- }
- ModEnvelope read() const
- {
- return { (float) amount.getValue(), (float) attack.getValue(), (float) hold.getValue(),
- (float) decay.getValue(), (float) sustain.getValue(), (float) release.getValue() };
- }
- };
- void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
- {
- s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
- // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
- s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
- s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
- s.setRange (lo, hi, step);
- s.setTextValueSuffix (suffix);
- s.onValueChange = [this] {
- if (onChange)
- onChange();
- };
- addAndMakeVisible (s);
- }
- std::array<Row, 2> rows;
- std::array<juce::Label, 6> labels;
- };
- // Channel LFOs (pan, volume, cutoff, pitch), like FL's.
- class LfoEditor final : public juce::Component
- {
- public:
- std::function<void()> onChange;
- static constexpr int preferredHeight = 18 + lfoTargets * 60;
- LfoEditor()
- {
- const juce::String titles[] = { tr ("Pan LFO"), tr ("Volume LFO"), tr ("Cutoff LFO"), tr ("Pitch LFO") };
- const double amountRange[] = { 1.0, 1.0, 8.0, 24.0 };
- const char* amountSuffix[] = { "", "", " oct", " st" };
- for (int i = 0; i < lfoTargets; ++i)
- {
- auto& row = rows[(std::size_t) i];
- row.title.setText (titles[i], juce::dontSendNotification);
- row.title.setFont (theme::font (theme::type::small));
- addAndMakeVisible (row.title);
- knob (row.amount, -amountRange[i], amountRange[i], 0.01, amountSuffix[i]);
- row.amount.setDoubleClickReturnValue (true, 0.0);
- row.amount.setTooltip (tr ("0 = off"));
- knob (row.period, 0.01, 16.0, 0.001, "");
- row.period.setSkewFactorFromMidPoint (0.5);
- knob (row.delay, 0.0, 8.0, 0.001, "");
- row.delay.setSkewFactorFromMidPoint (0.5);
- knob (row.attack, 0.0, 8.0, 0.001, "");
- row.attack.setSkewFactorFromMidPoint (0.5);
- row.shape.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Pulse") }, 1);
- row.shape.onChange = [this] { changed(); };
- addAndMakeVisible (row.shape);
- row.sync.setButtonText (tr ("Beats"));
- row.sync.setTooltip (tr ("Period, delay and fade-in in beats (follows the BPM) instead of seconds"));
- row.sync.onClick = [this] { changed(); };
- addAndMakeVisible (row.sync);
- row.global.setButtonText (tr ("Global"));
- row.global.setTooltip (tr ("Phase follows the song position instead of restarting on each note"));
- row.global.onClick = [this] { changed(); };
- addAndMakeVisible (row.global);
- }
- const juce::String headers[] = { tr ("Amount"), tr ("Period"), tr ("Shape"), tr ("Delay"), tr ("Fade-in"), tr ("Unit") };
- for (int i = 0; i < 6; ++i)
- {
- labels[(std::size_t) i].setText (headers[i], juce::dontSendNotification);
- labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
- labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
- addAndMakeVisible (labels[(std::size_t) i]);
- }
- }
- void resized() override
- {
- auto area = getLocalBounds();
- auto header = area.removeFromTop (18);
- header.removeFromLeft (80);
- const auto w = header.getWidth() / 6;
- for (auto& l : labels)
- l.setBounds (header.removeFromLeft (w));
- for (auto& row : rows)
- {
- auto line = area.removeFromTop (60);
- row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
- row.amount.setBounds (line.removeFromLeft (w));
- row.period.setBounds (line.removeFromLeft (w));
- row.shape.setBounds (line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 24));
- row.delay.setBounds (line.removeFromLeft (w));
- row.attack.setBounds (line.removeFromLeft (w));
- auto toggles = line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 50);
- row.sync.setBounds (toggles.removeFromTop (24));
- row.global.setBounds (toggles.removeFromBottom (24));
- }
- }
- void show (const std::array<ChannelLfo, lfoTargets>& lfo)
- {
- for (std::size_t i = 0; i < lfoTargets; ++i)
- {
- auto& row = rows[i];
- const auto& l = lfo[i];
- row.amount.setValue (l.amount, juce::dontSendNotification);
- row.period.setValue (l.period, juce::dontSendNotification);
- row.delay.setValue (l.delay, juce::dontSendNotification);
- row.attack.setValue (l.attack, juce::dontSendNotification);
- row.shape.setSelectedId (l.shape + 1, juce::dontSendNotification);
- row.sync.setToggleState (l.sync, juce::dontSendNotification);
- row.global.setToggleState (l.global, juce::dontSendNotification);
- const auto unit = l.sync ? " t" : " s";
- for (auto* s : { &row.period, &row.delay, &row.attack })
- s->setTextValueSuffix (unit);
- }
- }
- std::array<ChannelLfo, lfoTargets> read() const
- {
- std::array<ChannelLfo, lfoTargets> lfo {};
- for (std::size_t i = 0; i < lfoTargets; ++i)
- {
- const auto& row = rows[i];
- lfo[i] = { (float) row.amount.getValue(), (float) row.period.getValue(), row.sync.getToggleState(),
- juce::jlimit (0, 2, row.shape.getSelectedId() - 1), (float) row.delay.getValue(), (float) row.attack.getValue(),
- row.global.getToggleState() };
- }
- return lfo;
- }
- private:
- struct Row
- {
- juce::Label title;
- juce::Slider amount, period, delay, attack;
- juce::ComboBox shape;
- juce::ToggleButton sync, global;
- };
- void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
- {
- s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
- // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
- s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
- s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
- s.setRange (lo, hi, step);
- s.setTextValueSuffix (suffix);
- s.onValueChange = [this] { changed(); };
- addAndMakeVisible (s);
- }
- void changed()
- {
- if (onChange)
- onChange();
- }
- std::array<Row, lfoTargets> rows;
- std::array<juce::Label, 6> labels;
- };
- // Channel modulation window: cutoff/pitch envelopes and LFOs of the synth or the sampler.
- class ModulationPanel final : public juce::Component,
- private juce::ChangeListener
- {
- public:
- ModulationPanel (AudioEngine& e, ChannelRef c)
- : engine (e),
- ref (std::move (c))
- {
- envelopes.onChange = [this] { apply(); };
- lfos.onChange = [this] { apply(); };
- addAndMakeVisible (envelopes);
- addAndMakeVisible (lfos);
- refresh();
- engine.addChangeListener (this);
- setSize (660, 20 + ModEnvelopeEditor::preferredHeight + 16 + LfoEditor::preferredHeight);
- }
- ~ModulationPanel() override { engine.removeChangeListener (this); }
- void resized() override
- {
- auto area = getLocalBounds().reduced (10);
- envelopes.setBounds (area.removeFromTop (ModEnvelopeEditor::preferredHeight));
- area.removeFromTop (16);
- lfos.setBounds (area.removeFromTop (LfoEditor::preferredHeight));
- }
- int getChannel() const noexcept { return ref.index; }
- private:
- const ChannelDef* current() const
- {
- return ref.get (engine);
- }
- bool isSynth() const { return current() != nullptr && current()->instrument == InstrumentKind::synth; }
- void refresh()
- {
- const auto* c = current();
- if (c == nullptr)
- return;
- if (isSynth())
- {
- envelopes.show (c->synth.filterEnv, c->synth.pitchEnv);
- lfos.show (c->synth.lfo);
- }
- else
- {
- envelopes.show (c->sampler.filterEnv, c->sampler.pitchEnv);
- lfos.show (c->sampler.lfo);
- }
- // only its own window: as a tab of the channel's window it left that window titled "Modulation - ..." while the
- // Sampler page showed (issue #12)
- if (auto* w = findParentComponentOfClass<juce::DocumentWindow>(); w != nullptr && w->getContentComponent() == this)
- w->setName (tr ("Modulation - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
- }
- void apply()
- {
- if (current() == nullptr)
- return;
- const auto filter = envelopes.filter(), pitch = envelopes.pitch();
- const auto lfo = lfos.read();
- const auto synth = isSynth();
- ref.edit (engine, [synth, filter, pitch, lfo] (ChannelDef& channelDef) {
- auto& ch = channelDef;
- if (synth)
- {
- ch.synth.filterEnv = filter;
- ch.synth.pitchEnv = pitch;
- ch.synth.lfo = lfo;
- }
- else
- {
- ch.sampler.filterEnv = filter;
- ch.sampler.pitchEnv = pitch;
- ch.sampler.lfo = lfo;
- }
- });
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
- AudioEngine& engine;
- ChannelRef ref;
- ModEnvelopeEditor envelopes;
- LfoEditor lfos;
- };
- // A Sampler knob: right-click opens its automation menu instead of moving it (issue #12)
- class MenuSlider final : public juce::Slider
- {
- public:
- std::function<void()> onMenu;
- void mouseDown (const juce::MouseEvent& e) override
- {
- menuClick = e.mods.isPopupMenu() && onMenu != nullptr;
- if (menuClick)
- onMenu();
- else
- juce::Slider::mouseDown (e);
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (! menuClick)
- juce::Slider::mouseDrag (e);
- }
- void mouseUp (const juce::MouseEvent& e) override
- {
- if (! menuClick)
- juce::Slider::mouseUp (e);
- menuClick = false;
- }
- private:
- bool menuClick = false;
- };
- // Physical-model channels (Sakura, Drumpad; REA_rodada28): knobs for the main raw FL parameters (0..1)
- class ModelPanel final : public juce::Component,
- public juce::DragAndDropTarget,
- public juce::FileDragAndDropTarget,
- private juce::Timer
- {
- public:
- ModelPanel (AudioEngine& e, ChannelRef c)
- : engine (e),
- ref (std::move (c))
- {
- static const ChannelDef none;
- const auto* found = ref.get (engine);
- const auto& def = found != nullptr ? *found : none;
- sakura = def.instrument == InstrumentKind::sakura;
- boobass = def.instrument == InstrumentKind::boobass;
- drumsynth = def.instrument == InstrumentKind::drumsynth;
- harmless = def.instrument == InstrumentKind::harmless;
- harmor = def.instrument == InstrumentKind::harmor;
- gms = def.instrument == InstrumentKind::gms;
- morphine = def.instrument == InstrumentKind::morphine;
- autogun = def.instrument == InstrumentKind::autogun;
- transistorBass = def.instrument == InstrumentKind::transistorbass;
- ogun = def.instrument == InstrumentKind::ogun || autogun; // Autogun: Ogun's parameter layout (REA_rodada57)
- miniSynth = def.instrument == InstrumentKind::minisynth;
- dx10 = def.instrument == InstrumentKind::dx10;
- kepler = def.instrument == InstrumentKind::kepler;
- keplerExo = def.instrument == InstrumentKind::keplerExo;
- poizone = def.instrument == InstrumentKind::poizone;
- fruitkick = def.instrument == InstrumentKind::fruitkick;
- bassdrum = def.instrument == InstrumentKind::bassdrum;
- toxic = def.instrument == InstrumentKind::toxic;
- threeOsc = def.instrument == InstrumentKind::threeosc;
- simSynth = def.instrument == InstrumentKind::simsynth;
- wasp = def.instrument == InstrumentKind::wasp;
- plucked = def.instrument == InstrumentKind::plucked;
- beepMap = def.instrument == InstrumentKind::beepmap;
- sawer = def.instrument == InstrumentKind::sawer;
- flKeys = def.instrument == InstrumentKind::flkeys;
- granulizer = def.instrument == InstrumentKind::granulizer;
- drumaxx = def.instrument == InstrumentKind::drumaxx;
- slayer = def.instrument == InstrumentKind::slayer;
- fruityDance = def.instrument == InstrumentKind::fruitydance;
- // round 168q: the engines that run FL's own files say so when this computer lacks them
- engineFilesMissing = ((kepler || keplerExo) && ! keplerDllUsable (def.samplePath))
- || (transistorBass && ! transistorBassDllUsable (def.samplePath))
- || (sawer && sawerReadTable (def.samplePath).empty());
- sytrus = def.instrument == InstrumentKind::sytrus;
- // DrumSynth Live: the patch on the key selected in FL's editor (raw FL values)
- if (drumsynth)
- {
- if (lynx::drumSynthEditorKeyIndex < (int) def.modelParams.size())
- editorKey = (int) def.modelParams[(std::size_t) lynx::drumSynthEditorKeyIndex];
- if (drumSynthKeyToSlot (editorKey) < 0)
- editorKey = 60;
- wavesFound = ! def.samplePath.empty();
- }
- const auto offset = drumsynth ? drumSynthPatchParams * drumSynthKeyToSlot (editorKey) : 0;
- static const std::pair<int, const char*> sakuraKnobs[] = {
- { 0, "Master" }, { 1, "Tune" }, { 2, "Attack" }, { 3, "Decay" }, { 4, "Sustain" }, { 5, "Release" },
- { 6, "Str1 decay" }, { 9, "Str1 damp" }, { 11, "Str2 decay" }, { 14, "Str2 damp" }, { 16, "Saturation" },
- { 17, "String mix" }, { 18, "Stereo sep" }, { 19, "Comb ratio" }, { 22, "Comb level" }, { 24, "Lo-cut" },
- { 29, "Hi-cut" }, { 30, "Hi-cut res" }, { 31, "Noise level" }, { 32, "Noise rate" } };
- static const std::pair<int, const char*> drumpadKnobs[] = {
- { 2, "Mallet amp" }, { 3, "Mallet decay" }, { 4, "Mallet noise" }, { 6, "Decay" }, { 7, "Cutoff" },
- { 8, "Tension" }, { 9, "Phase" }, { 10, "Material" }, { 11, "Size" }, { 12, "Shape" }, { 13, "Low freq" },
- { 18, "Mid freq" }, { 19, "Mid level" }, { 24, "High freq" }, { 25, "High level" }, { 27, "Lo-fi" },
- { 28, "Hold" }, { 29, "Pitch" } };
- auto add = [&] (int index, const char* name, double low = 0.0, double high = -1.0) {
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- index += offset;
- if (high > low)
- knob->setRange (low, high, 1.0);
- else
- knob->setRange (0.0, boobass ? 65535.0 : 1.0, boobass ? 1.0 : 0.001);
- knob->setValue (index < (int) def.modelParams.size() ? def.modelParams[(std::size_t) index] : 0.0, juce::dontSendNotification);
- knob->setName (name);
- knob->onValueChange = [this, index, k = knob.get()] {
- ref.edit (engine, [index, v = (float) k->getValue()] (ChannelDef& channelDef) {
- auto& params = channelDef.modelParams;
- if (index < (int) params.size())
- params[(std::size_t) index] = v;
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- static const std::pair<int, const char*> booBassKnobs[] = { { 0, "Bass" }, { 1, "Mid" }, { 2, "Treble" } };
- struct Ranged { int index; const char* name; double low, high; };
- static const Ranged drumSynthKnobs[] = {
- { 0, "Level", 0, 128 }, { 1, "Pan", -64, 64 }, { 2, "Tone", -50, 50 }, { 3, "Harmonics", -50, 50 },
- { 4, "Osc1 freq", 0, 1000 }, { 7, "Osc1 decay", 0, 127 }, { 8, "Osc1 level", 0, 127 }, { 10, "Osc2 freq", 0, 1000 },
- { 13, "Osc2 decay", 0, 127 }, { 14, "Osc2 level", 0, 127 }, { 17, "Wave mix", 0, 127 }, { 21, "Release", 0, 127 },
- { 23, "Click", 0, 100 }, { 33, "Ring mod", 0, 127 } };
- // Harmless: raw FL values (REA_rodada21/32 ranges)
- static const Ranged harmlessKnobs[] = {
- { 36, "Volume", 0, 2000 }, { 26, "Attack", 0, 1000 }, { 27, "Decay", 0, 1000 }, { 28, "Release", 0, 1000 },
- { 54, "Cutoff", 0, 8192 }, { 59, "Resonance", 0, 1000 }, { 52, "Filter env", -1000, 1000 },
- { 31, "Pluck", 0, 1000 }, { 23, "Mask mix", 0, 1000 }, { 65, "Unison", 1, 9 }, { 67, "Uni detune", 0, 256 },
- { 25, "Tremolo", 0, 1000 }, { 71, "Phaser mix", 0, 1000 }, { 79, "Harmonizer", 0, 1000 } };
- // Harmor: raw FL integers inside the saved state (part A, and the global master / A–B mix; REA_rodada34)
- struct HarmorKnob { int part, index; const char* name; double low, high; };
- static const HarmorKnob harmorKnobs[] = {
- { -1, 12, "Master vol", 0, 2000 }, { -1, 10, "A/B mix", 0, 1000 }, { 0, 11, "A volume", -1000, 1000 },
- { 0, 4, "Timbre mix", 0, 1000 }, { 0, 52, "Cutoff", 0, 8192 }, { 0, 57, "Resonance", 0, 1000 },
- { 0, 75, "Pluck", 0, 1000 }, { 0, 34, "Unison", 1, 9 }, { 0, 38, "Uni detune", 0, 256 },
- { 0, 27, "Harmonizer", 0, 1000 }, { 0, 76, "Phaser mix", 0, 1000 }, { 0, 23, "Harm. blur", 0, 10000 },
- { 0, 45, "Vibrato", 0, 1000 }, { 0, 17, "Tremolo", 0, 1000 } };
- auto addHarmor = [&] (const HarmorKnob& k) {
- const auto at = harmorParamOffset (def.pluginState, k.part, k.index);
- if (at < 0)
- return;
- std::int32_t value = 0;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (value, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, s = knob.get()] {
- ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (const auto o = harmorParamOffset (st, k.part, k.index); o >= 0)
- std::memcpy (st.data() + o, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // GMS / Morphine: the plugin's own 0…1 floats inside the saved state (GMS P[i], Morphine global A[i]; REA_rodada39)
- struct FloatKnob { int index; const char* name; };
- static const FloatKnob gmsKnobs[] = {
- { 0, "Master" }, { 1, "Pan" }, { 8, "Level" }, { 4, "Attack" }, { 5, "Decay" }, { 6, "Sustain" }, { 7, "Release" },
- { 12, "Cutoff" }, { 13, "Resonance" }, { 16, "Env1 amount" }, { 50, "Modulation" }, { 48, "Osc2 mix" }, { 49, "Osc3 mix" },
- { 45, "Noise" }, { 41, "Unison" }, { 42, "Uni detune" }, { 43, "Stereo" }, { 10, "Slide time" } };
- static const FloatKnob morphineKnobs[] = {
- { 0, "Master" }, { 9, "Attack" }, { 10, "Decay" }, { 11, "Sustain" }, { 12, "Release" }, { 1, "Glide" }, { 4, "Vel curve" },
- { 7, "Overdrive" }, { 14, "Chorus mix" }, { 21, "Delay mix" }, { 25, "Reverb mix" }, { 36, "Noise mix" } };
- // BassDrum: its 23 floats 0…1 inside the saved state (REA_rodada15 §12.3 / rodada43 §2.2)
- static const FloatKnob bassDrumKnobs[] = {
- { 0, "Output" }, { 6, "Base" }, { 7, "Peak" }, { 8, "Slide" }, { 2, "Duration" }, { 5, "Attack" }, { 4, "Drive" },
- { 3, "Butt" }, { 15, "Click level" }, { 14, "Click freq" }, { 13, "Click cut" }, { 21, "Noise mix" }, { 22, "Noise filter" },
- { 20, "Noise pitch" }, { 19, "Noise start" }, { 1, "Sampling" } };
- // MiniSynth: its 43 floats 0…1 inside the saved state (REA_rodada41 §1.2)
- static const FloatKnob miniSynthKnobs[] = {
- { 5, "Osc kind" }, { 6, "Osc mod" }, { 7, "Noise" }, { 1, "Transpose" }, { 8, "Cutoff" }, { 9, "Resonance" },
- { 16, "Filter env" }, { 21, "Attack" }, { 22, "Decay" }, { 23, "Sustain" }, { 24, "Release" }, { 20, "LFO amount" },
- { 19, "LFO rate" }, { 2, "Slide time" } };
- auto paramOffset = [this] (const std::vector<std::uint8_t>& st, int index) {
- return gms ? gmsParamOffset (st, index)
- : miniSynth ? miniSynthParamOffset (st, index)
- : poizone ? poizoneParamOffset (st, index)
- : bassdrum ? bassDrumParamOffset (st, index)
- : toxic ? toxicParamOffset (st, index) : morphineParamOffset (st, index);
- };
- auto addFloat = [&] (const FloatKnob& k) {
- const auto at = paramOffset (def.pluginState, k.index);
- if (at < 0)
- return;
- float value = 0.0f;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (0.0, 1.0, 0.001);
- knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, paramOffset, s = knob.get()] {
- ref.edit (engine, [k, paramOffset, v = (float) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (const auto o = paramOffset (st, k.index); o >= 0)
- std::memcpy (st.data() + o, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // SimSynth: its 45 doubles 0…1 at the start of the saved state (REA_rodada64 §1.1)
- static const FloatKnob simSynthKnobs[] = {
- { 3, "Osc 1 level" }, { 10, "Osc 2 level" }, { 17, "Osc 3 level" }, { 26, "Cutoff" }, { 27, "Resonance" },
- { 28, "Filter env" }, { 30, "Key track" }, { 35, "Attack" }, { 36, "Decay" }, { 37, "Sustain" }, { 38, "Release" },
- { 22, "LFO rate" }, { 29, "LFO cutoff" }, { 39, "Volume" } };
- auto addDouble = [&] (const FloatKnob& k) {
- const auto at = 8 * (std::size_t) k.index;
- if (! simSynthStateUsable (def.pluginState))
- return;
- double value = 0.0;
- std::memcpy (&value, def.pluginState.data() + at, 8);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (0.0, 1.0, 0.001);
- knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0, 1.0) : 0.0, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, at, s = knob.get()] {
- ref.edit (engine, [at, v = s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (simSynthStateUsable (st))
- std::memcpy (st.data() + at, &v, 8);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // FL Slayer: the 28 parameter integers of the saved state (REA_rodada68 §6.1), ranges of the plugin's controls
- static const Ranged slayerKnobs[] = {
- { 0, "Strings", 0, 6 }, { 1, "Coils", 0, 2 }, { 2, "Pickup", 0, 65535 }, { 3, "Tone", 0, 65535 }, { 4, "Slap", 0, 65535 },
- { 5, "Fret", 0, 65535 }, { 6, "Harmonic", 0, 65535 }, { 7, "Damp", 0, 65535 }, { 8, "Vel volume", 0, 65535 },
- { 9, "Vel damp", 0, 65535 }, { 12, "Amp type", 0, 3 }, { 13, "Drive", 0, 65535 }, { 14, "Presence", 0, 65535 },
- { 15, "Feedback", 0, 65535 }, { 16, "EQ low", 0, 65535 }, { 17, "EQ mid", 0, 65535 }, { 18, "EQ high", 0, 65535 },
- { 19, "Cabinet", 0, 3 }, { 20, "Effect", 0, 15 }, { 21, "FX par 1", 0, 65535 }, { 22, "FX par 2", 0, 65535 },
- { 24, "Mode", 0, 5 }, { 25, "Timing", 0, 65535 }, { 26, "Latch", 0, 1 }, { 27, "Glissando", 0, 1 } };
- auto addSlayer = [&] (const Ranged& k) {
- const auto at = 4 + 4 * (std::size_t) k.index;
- if (! slayerStateUsable (def.pluginState) || at + 4 > def.pluginState.size())
- return;
- std::int32_t value = 0;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange ((double) k.low, (double) k.high, 1.0);
- knob->setValue ((double) std::clamp ((int) value, (int) k.low, (int) k.high), juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, at, s = knob.get()] {
- ref.edit (engine, [at, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (slayerStateUsable (st) && at + 4 <= st.size())
- std::memcpy (st.data() + at, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Sytrus: its "Main settings" page, raw FL integers inside the saved (zlib) state (REA_rodada74 §3)
- auto addSytrus = [&] (int setting) {
- const auto value = sytrus::settingValue (def.pluginState, setting);
- if (! value)
- return;
- const auto& d = sytrus::settings()[(std::size_t) setting];
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (d.low, d.high, 1.0);
- knob->setValue (std::clamp (*value, d.low, d.high), juce::dontSendNotification);
- knob->setName (d.name);
- knob->onValueChange = [this, setting, s = knob.get()] {
- ref.edit (engine, [setting, v = (int) s->getValue()] (ChannelDef& channelDef) {
- sytrus::setSetting (channelDef.pluginState, setting, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Ogun: raw FL integers P0…P63 inside the saved (zlib) state (REA_rodada37 §1.3)
- static const Ranged ogunKnobs[] = {
- { 0, "Master vol", 0, 256 }, { 5, "Pre-decay", 0, 1000 }, { 6, "Decay", 0, 10000 }, { 7, "Release", 0, 10000 },
- { 8, "Fullness", -1000, 1000 }, { 9, "Morph", 0, 1000 }, { 10, "Seed 1", 0, 1000 }, { 11, "Seed 2", 0, 1000 },
- { 52, "Richness", 6, 16 }, { 12, "Unison", 1, 9 }, { 15, "Uni pitch", 0, 256 }, { 17, "Cutoff", 0, 256 },
- { 18, "Resonance", 0, 256 }, { 3, "Mod X", 0, 512 }, { 4, "Mod Y", 0, 512 }, { 54, "Quality", 0, 4 } };
- static const Ranged autogunKnobs[] = { { 63, "Magic dust", 0, 1000 } };
- auto addOgun = [&] (const Ranged& k) {
- const auto value = ogunParam (def.pluginState, k.index);
- if (! value)
- return;
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (*value, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, index = k.index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- ogunSetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Fruit Kick: its six integers (REA_rodada10 §4.2 ranges)
- static const Ranged fruitKickKnobs[] = {
- { 0, "Max freq", -2400, 3600 }, { 1, "Min freq", -1200, 1200 }, { 2, "Freq decay", 0, 256 }, { 3, "Amp decay", 0, 256 },
- { 4, "Click", 0, 64 }, { 5, "Distortion", 0, 128 } };
- auto addFruitKick = [&] (const Ranged& k) {
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (fruitKickParam (def.pluginState, k.index), juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, index = k.index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- fruitKickSetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Fruity DX10: the 22 raw FL integers of the saved state (REA_rodada42 §1.2)
- static const Ranged dx10Knobs[] = {
- { 0, "Attack", 0, 65536 }, { 1, "Decay", 0, 65536 }, { 2, "Release", 0, 65536 }, { 21, "Coarse", -3, 3 },
- { 11, "Waveform", 0, 65536 }, { 10, "Vibrato", 0, 65536 }, { 13, "LFO rate", 0, 65536 },
- { 3, "Mod 1 coarse", 0, 65536 }, { 4, "Mod 1 fine", 0, 65536 }, { 5, "Mod 1 init", 0, 65536 }, { 6, "Mod 1 time", 0, 65536 },
- { 7, "Mod 1 sustain", 0, 65536 }, { 8, "Mod 1 release", 0, 65536 }, { 9, "Mod 1 velocity", 0, 65536 },
- { 14, "Mod 2 coarse", 0, 65536 }, { 15, "Mod 2 fine", 0, 65536 }, { 16, "Mod 2 init", 0, 65536 }, { 17, "Mod 2 time", 0, 65536 },
- { 18, "Mod 2 sustain", 0, 65536 }, { 19, "Mod 2 release", 0, 65536 }, { 20, "Mod 2 velocity", 0, 65536 }, { 12, "Mod thru", 0, 65536 } };
- auto addDx10 = [&] (const Ranged& k) {
- const auto value = dx10Param (def.pluginState, k.index);
- if (! value)
- return;
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (*value, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, index = k.index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- dx10SetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // 3x Osc: the 21 parameters of the saved state, then invert ×3, AM and HQ (REA_rodada47 §1.1)
- static const char* const threeOscNames[] = {
- "Osc 1 pan", "Osc 1 shape", "Osc 1 coarse", "Osc 1 fine", "Osc 1 phase", "Osc 1 detune", "Osc 2 mix", "Osc 2 pan",
- "Osc 2 shape", "Osc 2 coarse", "Osc 2 fine", "Osc 2 phase", "Osc 2 detune", "Osc 3 mix", "Osc 3 pan", "Osc 3 shape",
- "Osc 3 coarse", "Osc 3 fine", "Osc 3 phase", "Osc 3 detune", "Phase rand", "Invert 1", "Invert 2", "Invert 3",
- "Osc 3 AM", "HQ" };
- auto addThreeOsc = [&] (int index) {
- const auto value = threeOscParam (def.pluginState, index);
- if (! value)
- return;
- const auto [low, high] = threeOscParamRange (index);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (low, high, 1.0);
- knob->setValue (*value, juce::dontSendNotification);
- knob->setName (threeOscNames[index]);
- knob->onValueChange = [this, index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- threeOscSetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Fruity Granulizer: the 12 parameters of the saved state (REA_rodada67 §1)
- static const char* const granulizerNames[] = {
- "Grain attack", "Grain hold", "Grain spacing", "Wave spacing", "Effect depth", "Effect speed", "Randomness",
- "Stereo", "Loop", "Freeze", "Sample start", "Transient hold" };
- auto addGranulizer = [&] (int index) {
- const auto value = granulizerParam (def.pluginState, index);
- if (! value)
- return;
- const auto [low, high] = granulizerParamRange (index);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (low, high, 1.0);
- knob->setValue (*value, juce::dontSendNotification);
- knob->setName (granulizerNames[index]);
- knob->onValueChange = [this, index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- granulizerSetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Drumaxx: the master level and the 16 pad volumes, 0…1 floats of the saved state (REA_rodada67 §6)
- auto addDrumaxx = [&] (int index, const juce::String& name) {
- const auto value = drumaxxParam (def.pluginState, index);
- if (! std::isfinite (value))
- return;
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (0.0, 1.0, 0.001);
- knob->setValue (std::clamp ((double) value, 0.0, 1.0), juce::dontSendNotification);
- knob->setName (name);
- knob->onValueChange = [this, index, s = knob.get()] {
- ref.edit (engine, [index, v = (float) s->getValue()] (ChannelDef& channelDef) {
- drumaxxSetParam (channelDef.pluginState, index, v);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Kepler: the panel's 0…1 floats inside the saved state ("Kepler-1" order, REA_rodada46 §1.1)
- static const FloatKnob keplerKnobs[] = {
- { 33, "Volume" }, { 19, "Cutoff" }, { 20, "Resonance" }, { 22, "Env amount" }, { 26, "Attack" }, { 27, "Decay" },
- { 28, "Sustain" }, { 29, "Release" }, { 11, "PW" }, { 16, "Sub level" }, { 17, "Noise" }, { 5, "LFO rate" },
- { 10, "Vibrato" }, { 18, "High-pass" }, { 30, "Chorus" } };
- // Kepler Exo: the same layout with the "Kepler-2" parameter list (REA_rodada167d §1)
- static const FloatKnob keplerExoKnobs[] = {
- { 0x48, "Volume" }, { 0x25, "Cutoff" }, { 0x26, "Resonance" }, { 0x2c, "Env amount" }, { 0x3d, "Attack" },
- { 0x3e, "Decay" }, { 0x3f, "Sustain" }, { 0x40, "Release" }, { 0x21, "DCO2 level" }, { 0x0e, "DCO2 detune" },
- { 0x30, "LFO1 rate" }, { 0x36, "LFO2 rate" }, { 0x50, "Portamento" }, { 0x24, "High-pass" }, { 0x87, "Saturation" },
- { 0x70, "Delay amount" }, { 0x73, "Delay feedback" }, { 0x80, "Reverb decay" }, { 0x85, "Reverb wet" },
- { 0x93, "Hyper chorus mix" } };
- auto addKepler = [&] (const FloatKnob& k) {
- const auto at = keplerPanelOffset (def.pluginState, k.index);
- if (at < 0)
- return;
- float value = 0.0f;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (0.0, 1.0, 0.001);
- knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, s = knob.get()] {
- ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (const auto o = keplerPanelOffset (st, k.index); o >= 0)
- std::memcpy (st.data() + o, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Plucked!: the five int32 knobs of the saved state (REA_rodada65 §1.1)
- static const Ranged pluckedKnobs[] = { { 0, "Decay", 0, 256 }, { 1, "Color", 0, 128 }, { 2, "Normalize", 0, 1 },
- { 3, "Gate", 0, 1 }, { 4, "Widen", 0, 1 } };
- auto addPlucked = [&] (const Ranged& k) {
- if (def.pluginState.size() < 20)
- return;
- std::int32_t value = 0;
- std::memcpy (&value, def.pluginState.data() + 4 * k.index, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, s = knob.get()] {
- ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (st.size() >= 20)
- std::memcpy (st.data() + 4 * k.index, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // BeepMap: the int32 settings of the saved state (REA_rodada65 §2.1; Frequency's range not confirmed)
- static const Ranged beepMapKnobs[] = { { 0, "Frequency", 0, 9600 }, { 1, "Length", 0, 4096 }, { 2, "Scale", 0, 2 },
- { 3, "Use blue", 0, 1 }, { 4, "Grainy", 0, 1 }, { 5, "Loop", 0, 1 }, { 6, "Widen", 0, 1 } };
- auto addBeepMap = [&] (const Ranged& k) {
- const auto at = beepMapParamOffset (def.pluginState, k.index);
- if (at < 0)
- return;
- std::int32_t value = 0;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (k.low, k.high, 1.0);
- knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, s = knob.get()] {
- ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (const auto o = beepMapParamOffset (st, k.index); o >= 0)
- std::memcpy (st.data() + o, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // Sawer: 0…1 floats of the saved state (REA_rodada65 §3.3)
- static const FloatKnob sawerKnobs[] = {
- { 0, "Level" }, { 27, "Cutoff" }, { 28, "Resonance" }, { 36, "EGF amount" }, { 2, "Attack" }, { 3, "Decay" },
- { 4, "Sustain" }, { 5, "Release" }, { 19, "Sub level" }, { 18, "Sub harmonic" }, { 26, "Noise" }, { 14, "Unison" },
- { 15, "Uni detune" }, { 45, "LFO amount" } };
- auto addSawer = [&] (const FloatKnob& k) {
- const auto at = sawerParamOffset (def.pluginState, k.index);
- if (at < 0)
- return;
- float value = 0.0f;
- std::memcpy (&value, def.pluginState.data() + at, 4);
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (0.0, 1.0, 0.001);
- knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
- knob->setName (k.name);
- knob->onValueChange = [this, k, s = knob.get()] {
- ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (const auto o = sawerParamOffset (st, k.index); o >= 0)
- std::memcpy (st.data() + o, &v, 4);
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // FL Keys: the 15 int32 knobs of the saved state (REA_rodada69 §8.1)
- auto addFlKeys = [&] (int index) {
- const auto state = flkeys::parseState (def.pluginState);
- if (! state)
- return;
- const auto& r = flkeys::knobRange[index];
- auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (r.min, r.max, 1.0);
- knob->setValue (std::clamp ((double) state->knobs[(std::size_t) index], (double) r.min, (double) r.max), juce::dontSendNotification);
- knob->setName (r.name);
- knob->onValueChange = [this, index, s = knob.get()] {
- ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
- auto& st = channelDef.pluginState;
- if (auto parsed = flkeys::parseState (st))
- {
- parsed->knobs[(std::size_t) index] = v;
- st = flkeys::writeState (*parsed);
- }
- });
- };
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- };
- // an engine whose parameters are listed (core/ModelParams.h, round 168n): one knob per parameter, automatable
- // (right-click: FL's parameter menu; a move is a tweak)
- instrumentKind = def.instrument;
- modelTable = modelparams::tableOf (def.instrument);
- if (modelTable != nullptr && ! modelparams::rawValue (def, modelTable->params->front().index))
- modelTable = nullptr; // (a state the engine can't read: the plain page)
- if (modelTable != nullptr && (drumaxx || drumsynth))
- {
- // round 168p: Drumaxx's pad voice / DrumSynth Live's patch: one knob per control, editing the selected
- // pad's / key's parameter (the pad buttons / the key display pick the part); the rest as listed
- drumPart = drumsynth ? editorKey : drumaxxPadOf (ref.index);
- for (const auto& c : drumcontrols::controls (def.instrument))
- if (c.perPart)
- addPartParam (def, c);
- else if (const auto* p = modelparams::find (def.instrument, c.index))
- addModelParam (def, *p);
- }
- else if (modelTable != nullptr)
- {
- for (const auto& p : *modelTable->params)
- addModelParam (def, p);
- // Toxic Biohazard without the user's DLL: the drawn wave (0) and the sine (1) only — the built-in waves
- // 2…32 are FL's files
- if (toxic && ! toxicDllUsable (def.samplePath))
- for (auto& k : knobs)
- if (k->getName().endsWith (" wave"))
- k->setRange (0.0, 1.0, 1.0);
- }
- else if (flKeys)
- for (int i = 0; i < 15; ++i)
- addFlKeys (i);
- else if (plucked)
- for (const auto& k : pluckedKnobs)
- addPlucked (k);
- else if (beepMap)
- for (const auto& k : beepMapKnobs)
- addBeepMap (k);
- else if (sawer)
- for (const auto& k : sawerKnobs)
- addSawer (k);
- else if (threeOsc)
- for (int i = 0; i < threeOscParamCount(); ++i)
- addThreeOsc (i);
- else if (granulizer)
- {
- for (int i = 0; i < granulizerParamCount(); ++i)
- addGranulizer (i);
- setupGranulizerModes (def);
- }
- else if (drumaxx)
- {
- addDrumaxx (0x2c1, "Master");
- for (int pad = 0; pad < 16; ++pad)
- addDrumaxx (pad * 44, "Pad " + juce::String (pad + 1));
- }
- else if (dx10)
- for (const auto& k : dx10Knobs)
- addDx10 (k);
- else if (kepler)
- for (const auto& k : keplerKnobs)
- addKepler (k);
- else if (keplerExo)
- for (const auto& k : keplerExoKnobs)
- addKepler (k);
- else if (gms)
- for (const auto& k : gmsKnobs)
- addFloat (k);
- else if (bassdrum)
- for (const auto& k : bassDrumKnobs)
- addFloat (k);
- else if (fruitkick)
- for (const auto& k : fruitKickKnobs)
- addFruitKick (k);
- else if (morphine)
- for (const auto& k : morphineKnobs)
- addFloat (k);
- else if (miniSynth)
- for (const auto& k : miniSynthKnobs)
- addFloat (k);
- else if (simSynth)
- for (const auto& k : simSynthKnobs)
- addDouble (k);
- else if (wasp || fruityDance)
- ;
- else if (slayer)
- for (const auto& k : slayerKnobs)
- addSlayer (k);
- else if (sytrus)
- for (int i = 0; i < (int) sytrus::settings().size(); ++i)
- addSytrus (i);
- else if (ogun)
- {
- for (const auto& k : ogunKnobs)
- addOgun (k);
- if (autogun)
- for (const auto& k : autogunKnobs)
- addOgun (k);
- }
- else if (harmor)
- for (const auto& k : harmorKnobs)
- addHarmor (k);
- else if (harmless)
- for (const auto& k : harmlessKnobs)
- add (k.index, k.name, k.low, k.high);
- else if (drumsynth)
- for (const auto& k : drumSynthKnobs)
- add (k.index, k.name, k.low, k.high);
- else if (boobass)
- for (const auto& [index, name] : booBassKnobs)
- add (index, name);
- else if (sakura)
- for (const auto& [index, name] : sakuraKnobs)
- add (index, name);
- else
- for (const auto& [index, name] : drumpadKnobs)
- add (index, name);
- const auto rows = ((int) knobs.size() + 6) / 7; // the grid of resized()
- setSize (720, std::max (dx10 || threeOsc ? 500 : 384, 46 + rows * 110 + 8 + (granulizerModes ? 64 : 0)));
- // a Granulizer node inside a Patcher (round 165c): no channel to drop a sample on, so its own Sample button
- if (granulizer && ref.index < 0)
- {
- sampleButton.setButtonText (tr ("Sample..."));
- const auto path = juce::String::fromUTF8 (def.samplePath.c_str());
- ui::setHint (sampleButton, path.isEmpty() ? tr ("Choose the sample the Granulizer plays") : path);
- sampleButton.onClick = [this] {
- juce::StringArray patterns;
- for (const auto e : sampleFileExtensions)
- patterns.add ("*." + juce::String (std::string (e)));
- chooser = lynx::ui::makeFileChooser (tr ("Sample"), juce::File(), patterns.joinIntoString (";"));
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
- [safe = juce::Component::SafePointer<ModelPanel> (this)] (const juce::FileChooser& fc) {
- if (safe == nullptr || fc.getResult() == juce::File())
- return;
- safe->loadGranulizerSample (fc.getResult());
- });
- };
- addAndMakeVisible (sampleButton);
- resized(); // (setSize above laid the page out before the button existed)
- }
- // FL's arrangement of the plugin's page (core/PluginLayout.cpp): the knobs at FL's places, faders and
- // switches drawn by the panel
- layout = plugui::instrumentLayout (def.instrument);
- // a state the engine cannot read gives no knobs: keep the plain page then
- if (layout != nullptr && ! wasp && std::none_of (knobs.begin(), knobs.end(), [this] (const auto& k) { return itemFor (k->getName()) != nullptr; }))
- layout = nullptr;
- if (layout != nullptr)
- {
- accent = flKeys ? skin::colour::azure : boobass || transistorBass ? skin::colour::ember : harmor || sytrus ? skin::colour::violet
- : skin::colour::crimson;
- // round 126: the page's own style (FL Keys hardware, BooBass vivid, the synths neon); round 170j: a plugin
- // with its own art (Sakura, Toxic Biohazard, Sytrus, 3x Osc) is Themed
- pageStyle = flKeys ? skin::Style::hardware : boobass || transistorBass ? skin::Style::vivid : skin::Style::neon;
- pageArt = skin::artForInstrument (def.instrument);
- if (pageArt != skin::Art::none)
- {
- pageStyle = skin::Style::themed;
- artLayer = std::make_unique<skin::ArtLayer>();
- addAndMakeVisible (*artLayer);
- artLayer->setArt (pageArt, [this] { return themedNow(); });
- }
- for (auto& k : knobs)
- {
- k->getProperties().set (skin::sliderProperty, (juce::int64) accent.getARGB());
- k->getProperties().set (skin::styleProperty, skin::packStyle (pageStyle, pageArt));
- const auto* item = itemFor (k->getName());
- if (item == nullptr || (item->type != plugui::Item::knob && item->type != plugui::Item::vslider && item->type != plugui::Item::hslider))
- {
- k->setVisible (false); // edited by a switch of the panel (or not shown by FL)
- continue;
- }
- k->setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
- if (item->type == plugui::Item::vslider)
- k->setSliderStyle (juce::Slider::LinearVertical);
- if (item->type == plugui::Item::hslider)
- k->setSliderStyle (juce::Slider::LinearHorizontal);
- k->setPopupDisplayEnabled (true, true, this);
- k->setTooltip (k->getName());
- }
- updateConditional();
- // FL's size × 1.25, at most about 1200 × 760 (big pages such as Harmor's fit a laptop screen)
- const auto f = juce::jmin (layoutScale, 1200.0f / (float) layout->width, 720.0f / (float) layout->height);
- setSize ((int) std::ceil (f * (float) layout->width) + 16, (int) std::ceil (f * (float) layout->height) + layoutTop + 8);
- }
- if (transistorBass && ref.index >= 0)
- startTimerHz (10); // the page follows the program a note selects (round 169g2)
- }
- // Transistor Bass with its sequencer on: a note selects program = key (REA_rodada57 §2.10) and FL's editor shows
- // that program, so its knobs edit what plays. The channel's state takes the playing program (not an undo step)
- // and every knob reads it again (round 169g2)
- void timerCallback() override
- {
- const auto* c = channelNow();
- const auto instrument = engine.getChannelInstrument (ref.index);
- if (c == nullptr || instrument == nullptr)
- return;
- const auto selected = instrument->selectedProgram();
- const auto prog = transistorBassProgram (c->pluginState);
- if (selected < 0 || ! prog || prog->program == selected)
- return;
- auto next = c->pluginState;
- if (! transistorBassSelectProgram (next, selected))
- return;
- ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; }, false);
- syncKnobs (true);
- repaint();
- }
- // a knob of a listed engine parameter (round 168n): raw range of the state, automation target channelParam
- void addModelParam (const ChannelDef& def, const EngineParam& p)
- {
- auto knob = std::make_unique<MenuSlider>();
- knob->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (p.low, p.high, p.stepped ? 1.0 : 0.0);
- knob->setValue (modelparams::rawValue (def, p.index).value_or (p.low), juce::dontSendNotification);
- knob->setDoubleClickReturnValue (false, 0.0);
- knob->setName (juce::String::fromUTF8 (p.name.c_str()));
- const auto index = p.index;
- knob->onValueChange = [this, index, s = knob.get()] {
- ref.edit (engine, [index, v = (float) s->getValue()] (ChannelDef& c) {
- modelparams::setRawValue (c, index, v);
- natives::followControl (c, index, flStudioAccess()); // (Harmless' compression type loads its preset)
- });
- if (instrumentKind == InstrumentKind::transistorbass && index >= tbseq::length) // (a step's note moves its octave)
- syncKnobs();
- if (layout != nullptr)
- {
- updateConditional();
- repaint();
- }
- };
- if (ref.index >= 0) // (a Patcher node: no automation target)
- {
- const auto target = [this, index] { return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, index }; };
- ui::setOwnMenu (*knob);
- knob->onMenu = [this, k = knob.get(), target] { ui::showSliderMenu (*k, &engine, target()); };
- knob->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
- knob->onDragEnd = [this, target] { engine.tweakReleased (target()); };
- }
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- }
- // round 168p: a knob of Drumaxx's selected pad / DrumSynth Live's selected key (drumcontrols' per-part control):
- // named as the control (the layout places it), editing and automating the part's engine parameter
- void addPartParam (const ChannelDef& def, const drumcontrols::Control& c)
- {
- auto knob = std::make_unique<MenuSlider>();
- knob->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
- knob->setRange (c.low, c.high, c.integer ? 1.0 : 0.0);
- knob->setValue (drumcontrols::value (def, c, drumPart).value_or (c.low), juce::dontSendNotification);
- knob->setDoubleClickReturnValue (false, 0.0);
- knob->setName (c.name);
- const auto* control = &c;
- knob->onValueChange = [this, control, s = knob.get()] {
- ref.edit (engine, [control, part = drumPart, v = (float) s->getValue()] (ChannelDef& d) { drumcontrols::setValue (d, *control, v, part); });
- if (layout != nullptr)
- repaint();
- };
- if (ref.index >= 0)
- {
- const auto target = [this, control] {
- return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, drumcontrols::absoluteIndex (instrumentKind, *control, drumPart) };
- };
- ui::setOwnMenu (*knob);
- knob->onMenu = [this, k = knob.get(), target] { ui::showSliderMenu (*k, &engine, target()); };
- knob->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
- knob->onDragEnd = [this, target] { engine.tweakReleased (target()); };
- }
- partKnobs.push_back ({ knob.get(), control });
- addAndMakeVisible (*knob);
- knobs.push_back (std::move (knob));
- }
- // the pad remembered for each Drumaxx channel while LYNX runs (FL's editor keeps it, not the state)
- static int& drumaxxPadOf (int channel)
- {
- static std::map<int, int> pads;
- return pads[channel];
- }
- // another pad / key selected: the part's knobs show its values (no rebuild)
- void selectPart (int part)
- {
- const auto* def = ref.get (engine);
- if (def == nullptr || part == drumPart)
- return;
- drumPart = part;
- if (drumaxx)
- drumaxxPadOf (ref.index) = part;
- if (drumsynth)
- {
- editorKey = part;
- ref.edit (engine, [part] (ChannelDef& d) { // FL keeps the selected key in the state
- if (lynx::drumSynthEditorKeyIndex < (int) d.modelParams.size())
- d.modelParams[(std::size_t) lynx::drumSynthEditorKeyIndex] = (float) part;
- });
- }
- for (const auto& [k, c] : partKnobs)
- k->setValue (drumcontrols::value (*def, *c, drumPart).value_or (c->low), juce::dontSendNotification);
- repaint();
- }
- // the listed parameters' knobs read the channel's state again (an edit that moved other values: Transistor Bass's
- // note / octave, CLEAR, octave buttons; round 168q2)
- void syncKnobs (bool all = false)
- {
- const auto* c = channelNow();
- if (c == nullptr || modelTable == nullptr)
- return;
- for (auto& k : knobs)
- if (const auto* p = modelparams::findByName (instrumentKind, k->getName().toStdString()); p != nullptr && (all || p->index >= tbseq::length))
- if (const auto v = modelparams::rawValue (*c, p->index))
- k->setValue (*v, juce::dontSendNotification);
- }
- // the items shown only while another control is within a range (LayoutItem::whenParam, e.g. an effect slot's
- // fields for its type): their knobs follow
- bool conditionHolds (const plugui::LayoutItem& item) const
- {
- auto holds = [this] (const char* param, float lo, float hi) {
- if (param == nullptr)
- return true;
- const auto* k = knobFor (param);
- if (k == nullptr)
- return true;
- const auto v = normalised (*k); // (0…1 over the knob's range, as the effect layouts' conditions)
- return v >= lo && (v < hi || (hi >= 1.0f && v <= hi));
- };
- return (item.page < 0 || item.page == page) && holds (item.whenParam, item.whenMin, item.whenMax)
- && holds (item.when2Param, item.when2Min, item.when2Max);
- }
- int pageCount() const { return layout != nullptr ? (int) layout->pages.size() : 0; }
- void showPage (int p)
- {
- page = p;
- updateConditional();
- repaint();
- }
- void updateConditional()
- {
- if (layout == nullptr)
- return;
- for (auto& k : knobs)
- if (const auto* item = itemFor (k->getName()); item != nullptr && (item->type == plugui::Item::knob || item->type == plugui::Item::vslider || item->type == plugui::Item::hslider))
- k->setVisible (conditionHolds (*item));
- }
- // --- FL's arrangement ------------------------------------------------------------------------------
- static constexpr float layoutScale = 1.25f;
- static constexpr int layoutTop = 34;
- const plugui::LayoutItem* itemFor (const juce::String& name) const
- {
- if (layout == nullptr)
- return nullptr;
- const plugui::LayoutItem* any = nullptr;
- for (const auto& item : layout->items) // the knob / fader of the parameter first (a pad may share it)
- if (item.param != nullptr && name == item.param)
- {
- if (item.type == plugui::Item::knob || item.type == plugui::Item::vslider)
- return &item;
- if (any == nullptr && item.type != plugui::Item::display)
- any = &item;
- }
- return any;
- }
- juce::Slider* knobFor (const char* name) const
- {
- for (const auto& k : knobs)
- if (name != nullptr && k->getName() == name)
- return k.get();
- return nullptr;
- }
- float layoutFactor() const
- {
- if (layout == nullptr)
- return 1.0f;
- return juce::jmax (0.4f, juce::jmin ((float) (getWidth() - 16) / (float) layout->width, (float) (getHeight() - layoutTop - 8) / (float) layout->height));
- }
- juce::Rectangle<float> layoutRect (const plugui::LayoutItem& item) const
- {
- const auto f = layoutFactor();
- return { 8.0f + item.x * f, (float) layoutTop + item.y * f, item.w * f, item.h * f };
- }
- static float normalised (const juce::Slider& k)
- {
- const auto range = k.getMaximum() - k.getMinimum();
- return range > 0.0 ? (float) ((k.getValue() - k.getMinimum()) / range) : 0.0f;
- }
- static void setNormalised (juce::Slider& k, float v)
- {
- k.setValue (k.getMinimum() + (double) v * (k.getMaximum() - k.getMinimum()), juce::sendNotificationSync);
- }
- // the radio's option cell (grids fill row by row)
- juce::Rectangle<float> optionCell (const plugui::LayoutItem& item, int o, int count) const
- {
- const auto r = layoutRect (item);
- const auto columns = juce::jmax (1, item.columns);
- const auto rows = (count + columns - 1) / columns;
- const auto w = r.getWidth() / (float) columns, h = r.getHeight() / (float) juce::jmax (1, rows);
- return { r.getX() + w * (float) (o % columns), r.getY() + h * (float) (o / columns), w, h };
- }
- // a tabs item's segment o of `count` (left to right)
- juce::Rectangle<float> tabCell (const plugui::LayoutItem& item, int o, int count) const
- {
- const auto r = layoutRect (item);
- const auto w = r.getWidth() / (float) juce::jmax (1, count);
- return { r.getX() + w * (float) o, r.getY(), w, r.getHeight() };
- }
- // a small drawing of an oscillator shape (3x Osc's shape buttons)
- static void drawShape (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& name)
- {
- juce::Path p;
- const auto x0 = r.getX(), w = r.getWidth(), yc = r.getCentreY(), a = r.getHeight() * 0.5f;
- const auto n = 48;
- for (int i = 0; i <= n; ++i)
- {
- const auto t = (float) i / (float) n;
- float y = 0.0f;
- if (name == "Sine") y = std::sin (t * juce::MathConstants<float>::twoPi);
- else if (name == "Square") y = t < 0.5f ? 1.0f : -1.0f;
- 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);
- else if (name == "Triangle") y = t < 0.25f ? 4.0f * t : (t < 0.75f ? 2.0f - 4.0f * t : 4.0f * t - 4.0f);
- else if (name == "Saw") y = 2.0f * t - 1.0f;
- else if (name == "Noise") y = std::sin ((float) i * 12.9898f) * std::cos ((float) i * 4.1414f) * 1.6f;
- else /* custom */ y = std::sin (t * juce::MathConstants<float>::twoPi * 3.0f) * std::exp (-std::abs (t - 0.5f) * 5.0f);
- y = juce::jlimit (-1.0f, 1.0f, y);
- const juce::Point<float> pt { x0 + w * t, yc - a * y };
- if (i == 0)
- p.startNewSubPath (pt);
- else
- p.lineTo (pt);
- }
- g.strokePath (p, juce::PathStrokeType (1.5f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
- }
- // round 170j: the page draws its own art right now (Settings may force another style)
- bool themedNow() const { return pageArt != skin::Art::none && skin::resolve (pageStyle, pageArt) == skin::Style::themed; }
- juce::Colour pageAccent() const { return themedNow() ? skin::artAccent (pageArt) : accent; }
- // where the art's moving part lives: next to the plugin's big name (Toxic's trefoil, Sytrus's figure, 3x Osc's
- // scope); Sakura's petals fall in the band of the branch, above the first row of sections (a small area to repaint)
- juce::Rectangle<float> artStage() const
- {
- if (layout == nullptr)
- return {};
- const auto f = layoutFactor();
- if (pageArt == skin::Art::sakura)
- {
- auto top = (float) getHeight();
- for (const auto& item : layout->items)
- if (item.type == plugui::Item::section && layoutRect (item).getY() > (float) getHeight() * 0.18f)
- top = juce::jmin (top, layoutRect (item).getY());
- return { 0.0f, 30.0f, (float) getWidth(), juce::jmax (40.0f, top - 30.0f) };
- }
- for (const auto& item : layout->items)
- if (item.type == plugui::Item::label && item.label != nullptr && (item.style & plugui::dim) != 0 && item.h * f > 30.0f * f
- && juce::String (item.label).length() > 2)
- {
- const auto r = layoutRect (item);
- const auto w = juce::GlyphArrangement::getStringWidth (theme::font (r.getHeight() * 0.6f, true), item.label);
- const auto left = (item.style & plugui::alignLeft) != 0;
- const auto x0 = left ? r.getX() : r.getRight() - juce::jmin (w, r.getWidth());
- if (pageArt == skin::Art::toxic)
- return { x0 - r.getHeight() * 1.5f, r.getY() - r.getHeight() * 0.15f, r.getHeight() * 1.3f, r.getHeight() * 1.3f };
- return { left ? x0 + w + 12.0f : x0 - r.getHeight() * 2.6f - 12.0f, r.getY() - r.getHeight() * 0.1f, r.getHeight() * 2.6f, r.getHeight() * 1.2f };
- }
- return {};
- }
- void paintLayout (juce::Graphics& g)
- {
- using namespace theme;
- const skin::StyleScope styleScope (skin::resolve (pageStyle, pageArt), pageArt);
- const auto accent = pageAccent(); // (the art's own light when Themed)
- const auto f = layoutFactor();
- const auto* found = ref.get (engine);
- if (found == nullptr)
- return;
- const auto& def = *found;
- const auto caption = [&] (const char* text, juce::Rectangle<float> r, bool dimmed, juce::Justification j) {
- if (text == nullptr || *text == 0)
- return;
- g.setColour (dimmed ? colour::textDisabled : colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 9.5f * f), true));
- g.drawFittedText (caps (tr (text)), r.toNearestInt(), j, 1, 0.7f);
- };
- for (const auto& item : layout->items)
- {
- if (! conditionHolds (item))
- continue;
- const auto r = layoutRect (item);
- // round 170j: a partial repaint (the art's petals) draws only the items it touches (captions may hang
- // up to ~26 units past an item's sides)
- if (! g.clipRegionIntersects (r.expanded (32.0f * f, 8.0f * f).getSmallestIntegerContainer()))
- continue;
- const auto dimmed = (item.style & plugui::dim) != 0;
- auto* k = knobFor (item.param);
- switch (item.type)
- {
- case plugui::Item::tabs: // a row of segmented buttons (round 168n); pageTabs: the layout's pages
- if ((item.style & plugui::pageTabs) != 0)
- {
- const auto labels = plugui::optionLabels (item);
- for (int o = 0; o < (int) labels.size(); ++o)
- {
- const auto cell = tabCell (item, o, (int) labels.size()).reduced (1.5f * f, 2.0f * f);
- skin::button (g, cell, o == page, false, accent, radius::sm * f);
- g.setColour (o == page ? colour::onAccent : colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.62f)), true));
- g.drawFittedText (tr (labels[(std::size_t) o]), cell.reduced (2.0f * f, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
- }
- }
- else if (k != nullptr)
- {
- const auto labels = plugui::optionLabels (item);
- const auto chosen = plugui::optionAt (item, normalised (*k));
- for (int o = 0; o < (int) labels.size(); ++o)
- {
- const auto cell = tabCell (item, o, (int) labels.size()).reduced (1.5f * f, 2.0f * f);
- skin::button (g, cell, o == chosen, false, accent, radius::sm * f);
- g.setColour (o == chosen ? colour::onAccent : colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.62f)), true));
- g.drawFittedText (tr (labels[(std::size_t) o]), cell.reduced (2.0f * f, 0.0f).toNearestInt(), juce::Justification::centred, 1, 0.6f);
- }
- }
- break;
- case plugui::Item::menu: // a choice list: the current option and ▾ (round 168n)
- if (k != nullptr)
- {
- const auto labels = plugui::optionLabels (item);
- const auto chosen = plugui::optionAt (item, normalised (*k));
- auto box = r;
- if (item.label != nullptr && (item.style & plugui::noCaption) == 0)
- caption (item.label, box.removeFromTop (12.0f * f), dimmed, juce::Justification::centredLeft);
- skin::valuePlate (g, box, radius::sm * f);
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, box.getHeight() * 0.62f)), true));
- const auto text = juce::isPositiveAndBelow (chosen, (int) labels.size()) ? tr (labels[(std::size_t) chosen]) : juce::String();
- g.drawFittedText (text, box.reduced (4.0f * f, 0.0f).withTrimmedRight (10.0f * f).toNearestInt(), juce::Justification::centredLeft, 1, 0.6f);
- g.setColour (colour::textSecondary);
- g.drawText (juce::String::fromUTF8 ("\xe2\x96\xbe"), box.withTrimmedLeft (box.getWidth() - 12.0f * f), juce::Justification::centred, false);
- }
- break;
- case plugui::Item::value: // the control's value as text (round 168n)
- if (k != nullptr)
- {
- skin::valuePlate (g, r, radius::sm * f);
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, r.getHeight() * 0.7f)), true));
- g.drawFittedText (k->getTextFromValue (k->getValue()), r.reduced (3.0f * f, 0.0f).toNearestInt(),
- (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centred, 1, 0.6f);
- }
- break;
- case plugui::Item::section:
- skin::section (g, r, radius::lg * f, (item.style & plugui::raised) != 0, accent);
- if (item.label != nullptr && (item.style & plugui::boxed) == 0)
- 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));
- break;
- case plugui::Item::label:
- if (item.label != nullptr && juce::String (item.label).length() <= 2 && dimmed) // big dim numbers (3x Osc rows)
- {
- g.setColour (colour::bg4);
- g.setFont (font (r.getHeight() * 0.9f, true));
- g.drawText (item.label, r, juce::Justification::centred, false);
- }
- else if (dimmed && r.getHeight() > 30.0f * f) // the plugin's name, big and readable (round 168q2)
- {
- g.setColour (themedNow() ? accent.interpolatedWith (juce::Colours::white, 0.55f) : colour::textSecondary);
- g.setFont (font (r.getHeight() * 0.6f, true));
- g.drawFittedText (item.label, r.toNearestInt(),
- (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centredRight, 1, 0.8f);
- }
- else
- caption (item.label, r, dimmed, (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centred);
- break;
- case plugui::Item::knob: // (a small knob's caption may use some room on both sides, as a fader's does)
- if ((item.style & plugui::noCaption) == 0)
- 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);
- break;
- case plugui::Item::vslider:
- case plugui::Item::hslider:
- if ((item.style & plugui::noCaption) == 0)
- caption (item.label, r.withTop (r.getBottom() - 12.0f * f).expanded (16.0f * f, 0.0f), dimmed, juce::Justification::centred);
- break;
- case plugui::Item::radio:
- if (k != nullptr)
- {
- const auto labels = plugui::optionLabels (item);
- const auto chosen = plugui::optionAt (item, normalised (*k));
- for (int o = 0; o < (int) labels.size(); ++o)
- {
- const auto cell = optionCell (item, o, (int) labels.size()).reduced (3.0f * f);
- skin::button (g, cell, o == chosen, false, accent, radius::md * f);
- g.setColour (o == chosen ? accent.brighter (0.5f) : colour::textSecondary);
- if (item.columns > 0)
- drawShape (g, cell.reduced (cell.getWidth() * 0.22f, cell.getHeight() * 0.3f), labels[(std::size_t) o]);
- else
- g.drawFittedText (tr (labels[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, 1, 0.7f);
- }
- }
- break;
- case plugui::Item::toggle:
- if (k != nullptr)
- {
- const auto on = normalised (*k) >= 0.5f;
- if ((item.style & plugui::boxed) != 0)
- {
- const auto box = r.reduced (3.0f * f);
- skin::button (g, box, on, false, accent, radius::md * f);
- g.setColour (on ? colour::onAccent : colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 11.0f * f), true));
- g.drawText (item.label != nullptr ? item.label : "", box, juce::Justification::centred, false);
- }
- else
- {
- const auto dot = juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre ({ r.getX() + 6.0f * f, r.getCentreY() });
- if (on)
- {
- g.setColour (accent.withAlpha (0.3f));
- g.fillEllipse (dot.expanded (3.0f * f));
- }
- g.setColour (on ? accent : juce::Colour (0xff0b0c0f));
- g.fillEllipse (dot);
- g.setColour (juce::Colours::white.withAlpha (on ? 0.4f : 0.08f));
- g.drawEllipse (dot.reduced (0.5f), 1.0f);
- caption (item.label, r.withTrimmedLeft (14.0f * f), false, juce::Justification::centredLeft);
- }
- }
- break;
- case plugui::Item::stepper:
- if (k != nullptr)
- {
- auto box = r;
- if (item.label != nullptr)
- caption (item.label, box.removeFromTop (12.0f * f), false, juce::Justification::centred);
- skin::valuePlate (g, box, radius::sm * f);
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (9.0f, 12.0f * f), true));
- // oversampling orders read as FL shows them (0 → 1x … 3 → 8x)
- // a Transistor Bass step's note reads as a note name (60 = C5, FL's naming; round 168q2)
- static const char* const noteNames[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
- const auto whole = (int) std::lround (k->getValue());
- const auto* units = unitParam (*k); // (round 169h: a 0…1 number box in whole units)
- const auto text = units != nullptr ? juce::String (units->unitString (units->unitOf ((float) k->getValue())))
- : juce::String (item.param).containsIgnoreCase ("oversampling") ? juce::String (1 << juce::jlimit (0, 8, (int) k->getValue())) + "x"
- : juce::String (item.param).endsWith (" note") ? juce::String (noteNames[((whole % 12) + 12) % 12]) + juce::String (whole / 12)
- : juce::String (whole);
- g.drawFittedText (text, box.withTrimmedRight (8.0f * f).toNearestInt(), juce::Justification::centred, 1, 0.7f);
- g.setColour (colour::textSecondary);
- g.drawText (juce::String::fromUTF8 ("\xe2\x96\xb4"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withHeight (box.getHeight() * 0.5f), juce::Justification::centred, false);
- g.drawText (juce::String::fromUTF8 ("\xe2\x96\xbe"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withTrimmedTop (box.getHeight() * 0.5f), juce::Justification::centred, false);
- }
- break;
- case plugui::Item::display:
- skin::well (g, r, radius::md * f);
- // round 168q: BeepMap's bitmap, its file row, the Granulizer's sample and grains, Transistor Bass's
- // program and sequence
- if (juce::String (item.display) == "beepmapimage")
- paintBeepMapImage (g, r.reduced (3.0f * f));
- if (juce::String (item.display) == "beepmapfile")
- paintBeepMapFile (g, r, f);
- if (juce::String (item.display) == "granulizerwave")
- paintGranulizerWave (g, r.reduced (4.0f * f), f);
- if (juce::String (item.display) == "granulizergrains")
- paintGranulizerGrains (g, r.reduced (5.0f * f), f);
- if (juce::String (item.display) == "tbprogram")
- paintTransistorBass (g, r, f);
- if (juce::String (item.display) == "tbsteps")
- paintTransistorBassSteps (g, r, f);
- if (juce::String (item.display) == "tbseqtools")
- paintTransistorBassTools (g, r, f);
- if (juce::String (item.display) == "xy")
- if (auto* kx = knobFor (item.param); kx != nullptr)
- if (auto* ky = knobFor (item.param2); ky != nullptr)
- {
- // FL's Ogun pad (TQuickXYZ, round 169h shots fl-ogun-*.png): a 4 × 4 grid and a small ring
- // whose centre is the value, drawn clipped to the pad — at X = 0 only its inner half shows
- const juce::Graphics::ScopedSaveState clip (g);
- g.reduceClipRegion (r.toNearestInt());
- for (int k = 1; k < 4; ++k)
- {
- g.setColour (k == 2 ? colour::gridBar : colour::gridBeat);
- g.drawVerticalLine ((int) (r.getX() + r.getWidth() * (float) k / 4.0f), r.getY(), r.getBottom());
- g.drawHorizontalLine ((int) (r.getY() + r.getHeight() * (float) k / 4.0f), r.getX(), r.getRight());
- }
- const juce::Point<float> pt { r.getX() + r.getWidth() * normalised (*kx), r.getBottom() - r.getHeight() * normalised (*ky) };
- g.setColour (accent);
- g.drawEllipse (juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre (pt), juce::jmax (1.5f, 1.5f * f));
- }
- if (juce::String (item.display) == "toxicwave" && item.param != nullptr) // round 168n: the wave's cycle
- {
- const juce::String name (item.param);
- const auto n = name.fromFirstOccurrenceOf (" ", false, false).getIntValue();
- const auto slot = name.startsWith ("LFO") ? 5 + n : n - 1;
- const auto inner = r.reduced (5.0f * f, 6.0f * f);
- const auto shape = toxicWaveShape (def.pluginState, def.samplePath, slot, 96);
- if (shape.empty())
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
- g.drawFittedText (tr ("Needs FL Studio's files"), inner.toNearestInt(), juce::Justification::centred, 2, 0.7f);
- }
- else
- {
- g.setColour (colour::gridBeat);
- g.drawHorizontalLine ((int) inner.getCentreY(), inner.getX(), inner.getRight());
- juce::Path wave;
- for (int i = 0; i < (int) shape.size(); ++i)
- {
- const juce::Point<float> pt { inner.getX() + inner.getWidth() * (float) i / (float) (shape.size() - 1),
- inner.getCentreY() - inner.getHeight() * 0.5f * shape[(std::size_t) i] };
- if (i == 0)
- wave.startNewSubPath (pt);
- else
- wave.lineTo (pt);
- }
- g.setColour (accent.withAlpha (0.25f));
- g.strokePath (wave, juce::PathStrokeType (3.0f * f));
- g.setColour (accent.brighter (0.3f));
- g.strokePath (wave, juce::PathStrokeType (1.3f * f));
- }
- }
- paintDrumDisplay (g, item, r, def, f);
- // round 168o: the envelopes of the synth group's pages, drawn from their knobs (attack, decay, sustain, release;
- // a missing stage is skipped, a missing sustain is the level the decay falls to: none)
- {
- struct Env
- {
- const char* id;
- const char* a;
- const char* d;
- const char* s;
- const char* r;
- const char* start; // a modulator's initial level (DX10)
- };
- static const Env envs[] = {
- { "dx10amp", "Attack", "Decay", nullptr, "Release", nullptr },
- { "dx10mod1", nullptr, "Mod 1 time", "Mod 1 sustain", "Mod 1 release", "Mod 1 init" },
- { "dx10mod2", nullptr, "Mod 2 time", "Mod 2 sustain", "Mod 2 release", "Mod 2 init" },
- { "simamp", "Attack", "Decay", "Sustain", "Release", nullptr },
- { "simfilt", "Filter attack", "Filter decay", "Filter sustain", "Filter release", nullptr },
- { "ministenv", "Attack", "Decay", "Sustain", "Release", nullptr },
- };
- for (const auto& e : envs)
- if (juce::String (item.display) == e.id)
- {
- const auto value = [&] (const char* name, float otherwise) {
- auto* kn = name != nullptr ? knobFor (name) : nullptr;
- return kn != nullptr ? juce::jlimit (0.0f, 1.0f, normalised (*kn)) : otherwise;
- };
- const auto inner = r.reduced (5.0f * f, 5.0f * f);
- 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);
- const auto peak = e.start != nullptr ? value (e.start, 1.0f) : 1.0f;
- const auto unit = inner.getWidth() / 4.0f;
- const auto y = [&] (float level) { return inner.getBottom() - inner.getHeight() * level; };
- juce::Path env;
- auto x = inner.getX();
- env.startNewSubPath (x, y (e.start != nullptr ? peak : 0.0f));
- x += unit * a;
- env.lineTo (x, y (peak));
- // DX10's amp decay ≥ 0.98 holds the note
- const auto hold = e.s != nullptr ? su : (d >= 0.98f ? peak : 0.0f);
- x += unit * (0.15f + 0.85f * d);
- env.lineTo (x, y (hold));
- env.lineTo (inner.getRight() - unit * (0.15f + 0.85f * rl), y (hold));
- env.lineTo (inner.getRight(), y (0.0f));
- g.setColour (colour::gridBeat);
- g.drawHorizontalLine ((int) inner.getBottom(), inner.getX(), inner.getRight());
- g.setColour (accent.withAlpha (0.25f));
- g.strokePath (env, juce::PathStrokeType (3.0f * f));
- g.setColour (accent.brighter (0.3f));
- g.strokePath (env, juce::PathStrokeType (1.3f * f));
- }
- }
- if (juce::String (item.display) == "gmswaves") // round 168o: GMS's waves are read from FL Studio's folder
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
- const auto text = def.samplePath.empty() ? tr ("Needs FL Studio's files")
- : juce::File (juce::String::fromUTF8 (def.samplePath.c_str())).getFileName();
- g.drawFittedText (text, r.reduced (6.0f * f).toNearestInt(), juce::Justification::centred, 3, 0.7f);
- }
- if (juce::String (item.display) == "flkeysname")
- if (const auto st = flkeys::parseState (def.pluginState))
- {
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (9.0f, 11.0f * f)));
- g.drawFittedText (juce::String::fromUTF8 (st->wavetable.c_str()), r.reduced (6.0f * f, 0.0f).toNearestInt(),
- juce::Justification::centredLeft, 1, 0.8f);
- }
- break;
- default:
- break;
- }
- }
- }
- // round 168p: the displays of the drum pages (Drumaxx's kit / pads, BassDrum's noise sample, DrumSynth Live's
- // selected patch and its key display)
- static juce::String keyName (int key) { return juce::String (notenames::keyName (key)); }
- juce::Rectangle<float> dslKeyCell (juce::Rectangle<float> r, int key) const
- {
- // the 120 patch keys in 4 rows of 30 (C0 … B9, FL's octave numbers)
- const auto w = r.getWidth() / 30.0f, h = r.getHeight() / 4.0f;
- return { r.getX() + w * (float) (key % 30), r.getY() + h * (float) (key / 30), w, h };
- }
- void paintDrumDisplay (juce::Graphics& g, const plugui::LayoutItem& item, juce::Rectangle<float> r, const ChannelDef& def, float f)
- {
- using namespace theme;
- const juce::String id (item.display);
- auto text = [&] (const juce::String& t, juce::Colour c, juce::Justification j = juce::Justification::centred) {
- g.setColour (c);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (12.0f * f, r.getHeight() * 0.62f))));
- g.drawFittedText (t, r.reduced (4.0f * f, 1.0f).toNearestInt(), j, 1, 0.7f);
- };
- if (id == "drumaxxkit")
- {
- const auto name = juce::String::fromUTF8 (drumaxxKitName (def.pluginState).c_str());
- text (name.isEmpty() ? tr ("(no kit name)") : name, colour::textPrimary, juce::Justification::centredLeft);
- }
- else if (id == "drumaxxpad")
- {
- const auto pad = item.steps;
- const auto keyValue = drumaxxParam (def.pluginState, 44 * pad + 4);
- const auto key = std::isfinite (keyValue) ? (int) keyValue : -1;
- skin::button (g, r.reduced (2.0f * f), pad == drumPart, false, accent, radius::md * f);
- g.setColour (pad == drumPart ? colour::onAccent : colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 10.0f * f), true));
- g.drawFittedText (juce::String (pad + 1) + "\n" + (key >= 0 && key < 128 ? keyName (key) : juce::String()), r.toNearestInt(),
- juce::Justification::centred, 2, 0.7f);
- }
- else if (id == "drumaxxpadname")
- {
- const auto name = juce::String::fromUTF8 (drumaxxPadName (def.pluginState, item.steps).c_str());
- text (name.isEmpty() ? tr ("Pad {0}", { juce::String (item.steps + 1) }) : name, item.steps == drumPart ? accent.brighter (0.4f) : colour::textSecondary,
- juce::Justification::centredLeft);
- }
- else if (id == "bassdrumnoise")
- {
- if (! bassDrumStateUsable (def.pluginState) || def.samplePath.empty())
- text (tr ("Needs FL Studio's files"), colour::textSecondary);
- else
- {
- const auto name = juce::String::fromUTF8 (bassDrumNoiseName (def.pluginState).c_str());
- text (name.isEmpty() ? tr ("(no noise sample)") : name, colour::textPrimary, juce::Justification::centredLeft);
- }
- }
- else if (id == "dslpatch")
- text (keyName (drumPart) + " (" + juce::String (drumPart) + ")", colour::textPrimary);
- else if (id == "dslsend" || id == "dslmorph")
- {
- const auto slot = drumSynthKeyToSlot (drumPart);
- const auto at = drumSynthPatchParams * slot + (id == "dslsend" ? 34 : 36);
- const auto v = slot >= 0 && at < (int) def.modelParams.size() ? (int) std::lround (def.modelParams[(std::size_t) at]) : -1;
- text (id == "dslsend" ? (v < 0 ? juce::String ("-") : juce::String (v)) : (v < 0 || v > 119 ? tr ("(none)") : keyName (v)), colour::textPrimary);
- }
- else if (id == "dslkeys")
- {
- const auto inner = r.reduced (3.0f * f);
- for (int key = 0; key < drumSynthPatches; ++key)
- {
- const auto cell = dslKeyCell (inner, key).reduced (0.5f * f);
- const auto slot = drumSynthKeyToSlot (key);
- const auto level = (std::size_t) (drumSynthPatchParams * slot) < def.modelParams.size() ? def.modelParams[(std::size_t) (drumSynthPatchParams * slot)] : 0.0f;
- static constexpr bool blackKey[12] = { false, true, false, true, false, false, true, false, true, false, true, false };
- const auto black = blackKey[key % 12];
- g.setColour (key == drumPart ? accent : level > 0.0f ? accent.withAlpha (0.35f) : black ? colour::bg1 : colour::bg4);
- g.fillRect (cell);
- if (key % 12 == 0)
- {
- g.setColour (key == drumPart ? colour::onAccent : colour::textSecondary);
- g.setFont (font (juce::jmax (6.5f, juce::jmin (8.0f * f, cell.getHeight() * 0.6f))));
- g.drawText (juce::String (key / 12), cell, juce::Justification::centred, false);
- }
- }
- }
- }
- // a click on a pad button / the key display selects the part the knobs edit; true when handled
- bool clickDrumDisplay (const plugui::LayoutItem& item, juce::Point<float> at)
- {
- if (item.type != plugui::Item::display || item.display == nullptr || ! layoutRect (item).contains (at) || ! conditionHolds (item))
- return false;
- const juce::String id (item.display);
- if (drumaxx && (id == "drumaxxpad" || id == "drumaxxpadname"))
- {
- selectPart (item.steps);
- return true;
- }
- if (drumsynth && id == "dslkeys")
- {
- const auto inner = layoutRect (item).reduced (3.0f * layoutFactor());
- for (int key = 0; key < drumSynthPatches; ++key)
- if (dslKeyCell (inner, key).contains (at))
- {
- selectPart (key);
- return true;
- }
- }
- return false;
- }
- void resizeLayout()
- {
- for (auto& k : knobs)
- {
- const auto* item = itemFor (k->getName());
- if (item == nullptr || ! k->isVisible())
- continue;
- auto r = layoutRect (*item);
- if ((item->type == plugui::Item::vslider || item->type == plugui::Item::hslider) && (item->style & plugui::noCaption) == 0 && item->label != nullptr)
- r.removeFromBottom (13.0f * layoutFactor());
- if (item->type == plugui::Item::knob)
- {
- if ((item->style & plugui::noCaption) == 0)
- r.removeFromBottom (14.0f * layoutFactor());
- const auto d = juce::jmin (r.getWidth(), r.getHeight());
- r = r.withSizeKeepingCentre (d, d).withY (r.getY());
- }
- k->setBounds (r.toNearestInt());
- }
- }
- // a stepper's number moves one unit (the engine's own units for a 0…1 number box, round 169h)
- const EngineParam* unitParam (const juce::Slider& k) const
- {
- const auto* p = modelparams::findByName (instrumentKind, k.getName().toStdString());
- return p != nullptr && p->hasUnits() ? p : nullptr;
- }
- void stepBy (juce::Slider& k, int delta)
- {
- if (const auto* p = unitParam (k))
- k.setValue (p->rawOfUnit (p->unitOf ((float) k.getValue()) + delta), juce::sendNotificationSync);
- else
- k.setValue (k.getValue() + delta, juce::sendNotificationSync);
- }
- void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
- {
- if (layout != nullptr && wheel.deltaY != 0.0f)
- for (const auto& item : layout->items)
- if (item.type == plugui::Item::stepper && layoutRect (item).contains (e.position) && conditionHolds (item))
- if (auto* k = knobFor (item.param))
- {
- stepBy (*k, wheel.deltaY > 0.0f ? 1 : -1);
- repaint();
- return;
- }
- juce::Component::mouseWheelMove (e, wheel);
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (stepperDrag != nullptr)
- {
- if (auto* k = knobFor (stepperDrag->param))
- {
- const auto pixels = 6.0f * layoutFactor();
- const auto units = (int) ((stepperDragY - e.position.y) / pixels);
- if (units != stepperDragged)
- {
- stepBy (*k, units - stepperDragged);
- stepperDragged = units;
- repaint();
- }
- }
- return;
- }
- if (xyItem == nullptr)
- return;
- const auto r = layoutRect (*xyItem);
- if (auto* kx = knobFor (xyItem->param))
- setNormalised (*kx, juce::jlimit (0.0f, 1.0f, (e.position.x - r.getX()) / r.getWidth()));
- if (auto* ky = knobFor (xyItem->param2))
- setNormalised (*ky, juce::jlimit (0.0f, 1.0f, (r.getBottom() - e.position.y) / r.getHeight()));
- repaint();
- }
- void mouseUp (const juce::MouseEvent&) override
- {
- xyItem = nullptr;
- stepperDrag = nullptr;
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- if (layout == nullptr)
- return;
- for (const auto& item : layout->items) // round 168p: Drumaxx's pads, DrumSynth Live's keys
- if (clickDrumDisplay (item, e.position))
- return;
- for (const auto& item : layout->items) // the page switches first (they edit no parameter)
- if (item.type == plugui::Item::tabs && (item.style & plugui::pageTabs) != 0 && layoutRect (item).contains (e.position) && conditionHolds (item))
- {
- const auto count = (int) plugui::optionLabels (item).size();
- for (int o = 0; o < count; ++o)
- if (tabCell (item, o, count).contains (e.position))
- showPage (o);
- return;
- }
- for (const auto& item : layout->items) // round 168q2: Transistor Bass's CLEAR / octave up / octave down
- if (item.type == plugui::Item::display && juce::String (item.display) == "tbseqtools" && layoutRect (item).contains (e.position))
- {
- if (const auto button = transistorBassToolButton (item, e.position); button >= 0)
- transistorBassToolAction (button);
- return;
- }
- for (const auto& item : layout->items) // round 168q: BeepMap's Open / Paste
- if (item.type == plugui::Item::display && juce::String (item.display) == "beepmapfile" && layoutRect (item).contains (e.position))
- {
- if (const auto button = beepMapFileButton (item, e.position); button >= 0)
- beepMapAction (button);
- return;
- }
- for (const auto& item : layout->items)
- {
- auto* k = knobFor (item.param);
- if (k == nullptr || ! layoutRect (item).contains (e.position) || ! conditionHolds (item)
- || item.type == plugui::Item::knob || item.type == plugui::Item::vslider || item.type == plugui::Item::hslider
- || item.type == plugui::Item::section || item.type == plugui::Item::label)
- continue;
- if (e.mods.isPopupMenu() && ref.index >= 0 && modelTable != nullptr) // a switch / tabs: FL's parameter menu
- {
- if (const auto* p = modelparams::findByName (instrumentKind, k->getName().toStdString()))
- ui::showSliderMenu (*k, &engine, AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, p->index });
- return;
- }
- if (item.type == plugui::Item::menu)
- {
- const auto labels = plugui::optionLabels (item);
- const auto chosen = plugui::optionAt (item, normalised (*k));
- juce::PopupMenu menu;
- for (int o = 0; o < (int) labels.size(); ++o)
- menu.addItem (tr (labels[(std::size_t) o]), true, o == chosen,
- [safe = juce::Component::SafePointer<ModelPanel> (this), name = k->getName(), value = plugui::optionValue (item, o)] {
- if (safe == nullptr)
- return;
- if (auto* knob = safe->knobFor (name.toRawUTF8()))
- setNormalised (*knob, value);
- safe->repaint();
- });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetScreenArea (localAreaToGlobal (layoutRect (item).toNearestInt())));
- return;
- }
- if (item.type == plugui::Item::tabs)
- {
- const auto count = (int) plugui::optionLabels (item).size();
- for (int o = 0; o < count; ++o)
- if (tabCell (item, o, count).contains (e.position))
- setNormalised (*k, plugui::optionValue (item, o));
- repaint();
- return;
- }
- if (item.type == plugui::Item::display && juce::String (item.display) == "xy")
- {
- xyItem = &item;
- mouseDrag (e);
- return;
- }
- if (item.type == plugui::Item::stepper)
- {
- const auto r = layoutRect (item);
- 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;
- stepBy (*k, up ? 1 : -1);
- stepperDrag = &item; // (round 169h) a vertical drag moves the number too
- stepperDragY = e.position.y;
- stepperDragged = 0;
- }
- else if (item.type == plugui::Item::toggle)
- setNormalised (*k, normalised (*k) >= 0.5f ? 0.0f : 1.0f);
- else if (item.type == plugui::Item::radio)
- {
- const auto count = (int) plugui::optionLabels (item).size();
- for (int o = 0; o < count; ++o)
- if (optionCell (item, o, count).contains (e.position))
- setNormalised (*k, plugui::optionValue (item, o));
- }
- repaint();
- return;
- }
- }
- void paint (juce::Graphics& g) override
- {
- g.fillAll (theme::colour::bg2);
- if (layout != nullptr) // a plugin page in FL's arrangement: the plugin skin's canvas (round 170j: the art's when Themed)
- {
- const skin::StyleScope styleScope (themedNow() ? skin::Style::themed : skin::style(), pageArt);
- skin::canvas (g, getLocalBounds().toFloat(), pageAccent());
- }
- g.setColour (theme::colour::textPrimary);
- g.setFont (theme::font (layout != nullptr ? theme::type::body : theme::type::title));
- if (! engineFilesMissing)
- g.drawFittedText (drumsynth ? tr ("DrumSynth Live — FL's engine, patch on key {0}", { juce::String (editorKey) })
- + (wavesFound ? tr (" (next hit; recorded waves from your FL installation)")
- : tr (" (next hit; recorded waves not found: silent)"))
- : harmless ? tr ("Harmless — FL's additive engine (chorus/delay/reverb/compressor rack off)")
- : harmor ? tr ("Harmor — FL's additive engine (effects rack off; image synthesis not decoded)")
- : gms ? tr ("GMS — FL's engine (waves read from your FL installation)")
- : morphine ? tr ("Morphine — FL's additive engine (new settings restart the voices)")
- : transistorBass ? tr ("Transistor Bass — FL's engine with its sequencer and effects (oscillator cycles read from your FL installation)")
- : autogun ? tr ("Autogun — FL's engine with its effects and Magic Dust (SG.dat read from your FL installation)")
- : ogun ? tr ("Ogun — FL's engine with its effects (Seed 2 Random is a fixed draw per channel)")
- : poizone ? tr ("PoiZone — FL's engine with its gate, chorus, delay and arpeggiator (new settings restart the voices)")
- : miniSynth ? tr ("MiniSynth — FL's engine with its effects (wave tables read from your FL installation)")
- : dx10 ? tr ("Fruity DX10 — FL's FM engine")
- : kepler ? tr ("Kepler — FL's engine (LFO shape and noise read from your FL installation)")
- : keplerExo ? tr ("Kepler Exo — FL's engine with its effects (tables read from your FL installation)")
- : fruitkick ? tr ("Fruit Kick — FL's engine (channel envelopes stepped per tick)")
- : bassdrum ? tr ("BassDrum — FL's engine (table and noise samples read from your FL installation)")
- : toxic ? tr ("Toxic Biohazard — FL's engine with its effects (waves read from your FL installation)")
- : threeOsc ? tr ("3x Osc — FL's engine (custom wave from the channel's sample)")
- : simSynth ? tr ("SimSynth — FL's engine (new settings restart the voices)")
- : wasp ? tr ("Wasp — FL Studio 2026 has no 64-bit Wasp: the channel keeps its settings and stays silent, as in FL")
- : flKeys ? tr ("FL Keys — FL's engine (wavetable read from your FL installation)")
- : plucked ? tr ("Plucked! — FL's plucked-string engine")
- : beepMap ? tr ("BeepMap — FL's engine (plays the bitmap saved with the channel)")
- : sawer ? tr ("Sawer — FL's engine with its effects (oscillator cycle read from your FL installation)")
- : granulizer ? tr ("Fruity Granulizer — FL's engine on the channel's sample")
- : drumaxx ? tr ("Drumaxx — FL's physical drum engine (pads on their keys; patterns not played)")
- : slayer ? tr ("FL Slayer — FL's engine with its effects, amp and cabinet (picks read from your FL installation; new settings restart the voices)")
- : sytrus ? tr ("Sytrus — FL's engine, main settings (operators, filters and effects keep the saved patch)")
- : fruityDance ? tr ("Fruity Dance — a visual plugin: it makes no sound, the channel keeps its settings")
- : boobass ? tr ("BooBass — FL's engine, its sound read from your FL installation (knobs: 3-band EQ)")
- : sakura ? tr ("Sakura — physical strings (FL's engine; new parameters apply to the next note)")
- : tr ("Drumpad — physical drum (FL's engine; new parameters apply to the next hit)"),
- descriptionArea(), juce::Justification::centredLeft, layout != nullptr ? 1 : 2, 0.8f);
- if (engineFilesMissing) // round 168q: an engine that runs FL's own DLL / data file, which this computer lacks
- {
- const auto band = juce::Rectangle<float> (8.0f, 5.0f, (float) getWidth() - 16.0f, 22.0f);
- g.setColour (accent.withAlpha (0.18f));
- g.fillRoundedRectangle (band, 4.0f);
- g.setColour (theme::colour::textPrimary);
- g.setFont (theme::font (theme::type::small));
- g.drawFittedText (tr ("Needs FL Studio's files: the engine file was not found, so the channel stays silent (its settings are kept)."),
- band.reduced (6.0f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.7f);
- }
- if (layout != nullptr)
- {
- paintLayout (g);
- return;
- }
- g.setFont (theme::font (theme::type::small));
- for (const auto& k : knobs)
- g.drawText (k->getName(), k->getBounds().withHeight (14).translated (0, -14), juce::Justification::centred);
- }
- // the engine's one-line description at the top (round 169h: wrapped to a second line above the knob grid, or shrunk a
- // little on a designed page, instead of cut with "…" in a narrow window); clear of the sample button
- juce::Rectangle<int> descriptionArea() const
- {
- const auto right = sampleButton.isVisible() ? getWidth() - 136 : getWidth() - 10;
- return { 10, layout != nullptr ? 6 : 2, juce::jmax (40, right - 10), layout != nullptr ? 20 : 30 }; // (the knob grid's captions start at y 32)
- }
- void resized() override
- {
- if (sampleButton.isVisible())
- sampleButton.setBounds (getWidth() - 128, 4, 120, 24);
- if (layout != nullptr)
- {
- resizeLayout();
- if (artLayer != nullptr)
- {
- artLayer->setBounds (getLocalBounds());
- artLayer->setStage (artStage());
- artLayer->toFront (false);
- }
- return;
- }
- constexpr int columns = 7, w = 96, h = 92;
- for (std::size_t i = 0; i < knobs.size(); ++i)
- knobs[i]->setBounds (12 + (int) (i % columns) * (w + 4), 46 + (int) (i / columns) * (h + 18), w, h);
- if (granulizerModes)
- {
- // FL's KEY TO, TRANSIENTS and TEMPO LOCKED controls, in a row under the knobs
- const auto rows = ((int) knobs.size() + columns - 1) / columns;
- const auto y = 46 + rows * (h + 18) + 4;
- granKeyToLabel.setBounds (12, y, 150, 18);
- granKeyTo.setBounds (12, y + 20, 150, 24);
- granTransientsLabel.setBounds (174, y, 150, 18);
- granTransients.setBounds (174, y + 20, 150, 24);
- granTempoLocked.setBounds (336, y + 20, 140, 24);
- granBeatsLabel.setBounds (488, y, 200, 18);
- granBeats.setBounds (488, y + 20, 200, 24);
- }
- }
- // FL's Granulizer takes a sample dropped on its window (from the Browser or the system) and plays it; before, the
- // drop fell through to the Playlist under the window and made an audio clip (audit 165)
- bool isInterestedInDragSource (const SourceDetails& details) override
- {
- return takesSample() && BrowserComponent::isBrowserDrag (details) && SampleLibrary::isSampleFile (BrowserComponent::draggedFile (details));
- }
- void itemDragEnter (const SourceDetails&) override { setDropHighlight (true); }
- void itemDragExit (const SourceDetails&) override { setDropHighlight (false); }
- void itemDropped (const SourceDetails& details) override
- {
- setDropHighlight (false);
- loadGranulizerSample (BrowserComponent::draggedFile (details));
- }
- bool isInterestedInFileDrag (const juce::StringArray& files) override
- {
- return takesSample() && files.size() == 1 && SampleLibrary::isSampleFile (juce::File (files[0]));
- }
- void fileDragEnter (const juce::StringArray&, int, int) override { setDropHighlight (true); }
- void fileDragExit (const juce::StringArray&) override { setDropHighlight (false); }
- void filesDropped (const juce::StringArray& files, int, int) override
- {
- setDropHighlight (false);
- loadGranulizerSample (juce::File (files[0]));
- }
- void paintOverChildren (juce::Graphics& g) override
- {
- if (dropHighlight)
- {
- g.setColour (theme::colour::accent);
- g.drawRect (getLocalBounds(), 2);
- }
- }
- private:
- bool takesSample() const
- {
- const auto* c = ref.get (engine);
- return c != nullptr && projectcontents::pluginWindowTakesSample (c->instrument);
- }
- void setDropHighlight (bool on)
- {
- if (dropHighlight != on)
- {
- dropHighlight = on;
- repaint();
- }
- }
- // the Granulizer plays the new sample with the same settings (FL keeps the knobs and the channel's name)
- // --- round 168q: the displays of the group-D pages ---------------------------------------------------------
- const ChannelDef* channelNow() const { return ref.get (engine); }
- // BeepMap: the bitmap, stretched to the display (red = left, green = right, as the engine reads it)
- void paintBeepMapImage (juce::Graphics& g, juce::Rectangle<float> r)
- {
- const auto* c = channelNow();
- const auto pic = c != nullptr ? beepMapPicture (c->pluginState) : std::nullopt;
- if (! pic || pic->width <= 0 || pic->height <= 0)
- return;
- if (beepMapCacheState != c->pluginState)
- {
- beepMapCacheState = c->pluginState;
- beepMapCache = juce::Image (juce::Image::RGB, pic->width, pic->height, false);
- for (int y = 0; y < pic->height; ++y)
- for (int x = 0; x < pic->width; ++x)
- {
- const auto* px = pic->bgr.data() + 3 * ((std::size_t) y * (std::size_t) pic->width + (std::size_t) x);
- beepMapCache.setPixelAt (x, y, juce::Colour (px[2], px[1], px[0]));
- }
- }
- g.setImageResamplingQuality (juce::Graphics::lowResamplingQuality);
- g.drawImage (beepMapCache, r, juce::RectanglePlacement::stretchToFit);
- g.setImageResamplingQuality (juce::Graphics::mediumResamplingQuality);
- }
- void paintBeepMapFile (juce::Graphics& g, juce::Rectangle<float> r, float f)
- {
- using namespace theme;
- const auto* c = channelNow();
- const auto pic = c != nullptr ? beepMapPicture (c->pluginState) : std::nullopt;
- auto row = r.reduced (4.0f * f);
- const auto w = row.getWidth() / 3.2f;
- const juce::String caps[] = { tr ("Open..."), tr ("Paste") };
- for (int i = 0; i < 2; ++i)
- {
- const auto cell = row.removeFromLeft (w).reduced (2.0f * f, 0.0f);
- skin::button (g, cell, false, false, accent, radius::sm * f);
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (11.0f * f, cell.getHeight() * 0.5f)), true));
- g.drawFittedText (caps[i], cell.toNearestInt(), juce::Justification::centred, 1, 0.6f);
- }
- g.setColour (colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 10.0f * f)));
- const auto text = pic ? tr ("{0} × {1} pixels", { juce::String (pic->width), juce::String (pic->height) }) : tr ("No bitmap");
- g.drawFittedText (text, row.reduced (4.0f * f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 2, 0.7f);
- }
- // which button of the BeepMap file row is under `p` (0 open, 1 paste, −1 none)
- int beepMapFileButton (const plugui::LayoutItem& item, juce::Point<float> p) const
- {
- auto row = layoutRect (item).reduced (4.0f * layoutFactor());
- const auto w = row.getWidth() / 3.2f;
- for (int i = 0; i < 2; ++i)
- if (row.removeFromLeft (w).contains (p))
- return i;
- return -1;
- }
- void setBeepMapBitmap (const std::vector<std::uint8_t>& bmp)
- {
- const auto* c = channelNow();
- if (c == nullptr)
- return;
- auto next = beepMapWithBitmap (c->pluginState, bmp);
- if (next.empty())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, juce::String ("BeepMap"),
- tr ("BeepMap reads uncompressed 24- or 32-bit BMP pictures at least 3 pixels high."));
- return;
- }
- ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; });
- repaint();
- }
- void beepMapAction (int button)
- {
- if (button == 1) // a BMP file path or the file itself copied in the clipboard
- {
- const juce::File file (juce::SystemClipboard::getTextFromClipboard().trim().unquoted());
- juce::MemoryBlock data;
- if (file.existsAsFile() && file.loadFileAsData (data))
- setBeepMapBitmap (std::vector<std::uint8_t> ((const std::uint8_t*) data.getData(), (const std::uint8_t*) data.getData() + data.getSize()));
- else
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, juce::String ("BeepMap"), tr ("Copy a .bmp file's path first, or use Open."));
- return;
- }
- chooser = lynx::ui::makeFileChooser (tr ("Open a bitmap"), juce::File(), "*.bmp");
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
- [safe = juce::Component::SafePointer<ModelPanel> (this)] (const juce::FileChooser& fc) {
- juce::MemoryBlock data;
- if (safe == nullptr || ! fc.getResult().loadFileAsData (data))
- return;
- safe->setBeepMapBitmap (std::vector<std::uint8_t> ((const std::uint8_t*) data.getData(),
- (const std::uint8_t*) data.getData() + data.getSize()));
- });
- }
- // Granulizer: the channel's sample (or how to give it one) with the start point
- void paintGranulizerWave (juce::Graphics& g, juce::Rectangle<float> r, float f)
- {
- using namespace theme;
- const auto* c = channelNow();
- const auto path = c != nullptr ? c->samplePath : std::string();
- if (path.empty())
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (juce::jmax (9.0f, 11.0f * f)));
- g.drawFittedText (tr ("Drop a sample here (or on the channel button)"), r.toNearestInt(), juce::Justification::centred, 2, 0.7f);
- return;
- }
- if (path != granulizerPeaksPath)
- {
- granulizerPeaksPath = path;
- granulizerPeaks.clear();
- if (const auto s = engine.getSampleLibrary().load (juce::String::fromUTF8 (path.c_str())))
- {
- const auto n = (std::int64_t) s->left.size();
- constexpr int columns = 400;
- for (int i = 0; i < columns && n > 0; ++i)
- {
- float peak = 0.0f;
- for (auto k = n * i / columns; k < n * (i + 1) / columns; ++k)
- 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]) });
- granulizerPeaks.push_back (std::min (peak, 1.0f));
- }
- }
- }
- if (granulizerPeaks.empty())
- return;
- const auto mid = r.getCentreY();
- juce::Path wave;
- for (int i = 0; i < (int) granulizerPeaks.size(); ++i)
- {
- const auto x = r.getX() + r.getWidth() * (float) i / (float) (granulizerPeaks.size() - 1);
- wave.addRectangle (x, mid - granulizerPeaks[(std::size_t) i] * r.getHeight() * 0.48f, juce::jmax (1.0f, r.getWidth() / (float) granulizerPeaks.size()),
- juce::jmax (1.0f, granulizerPeaks[(std::size_t) i] * r.getHeight() * 0.96f));
- }
- g.setColour (accent.withAlpha (0.65f));
- g.fillPath (wave);
- if (const auto* k = knobFor ("Sample start"))
- {
- const auto x = r.getX() + r.getWidth() * normalised (*k);
- g.setColour (colour::textPrimary);
- g.drawVerticalLine ((int) x, r.getY(), r.getBottom());
- }
- g.setColour (colour::textSecondary);
- g.setFont (font (juce::jmax (8.0f, 9.5f * f)));
- g.drawFittedText (juce::File (juce::String::fromUTF8 (path.c_str())).getFileName(), r.removeFromTop (14.0f * f).toNearestInt(),
- juce::Justification::topLeft, 1, 0.8f);
- }
- // Granulizer: one grain's envelope (attack, hold, release) and the next grain's start, from the knobs
- void paintGranulizerGrains (juce::Graphics& g, juce::Rectangle<float> r, float)
- {
- using namespace theme;
- const auto* att = knobFor ("Grain attack");
- const auto* hold = knobFor ("Grain hold");
- const auto* spacing = knobFor ("Grain spacing");
- if (att == nullptr || hold == nullptr || spacing == nullptr)
- return;
- const auto a = (float) att->getValue(), h = (float) hold->getValue(), sp = (float) spacing->getValue();
- const auto total = juce::jmax (1.0f, 2.0f * a + h + sp);
- const auto xOf = [&] (float t) { return r.getX() + r.getWidth() * t / total; };
- for (int grain = 0; grain < 2; ++grain)
- {
- const auto t0 = (float) grain * sp;
- juce::Path p;
- p.startNewSubPath (xOf (t0), r.getBottom());
- p.lineTo (xOf (t0 + a), r.getY());
- p.lineTo (xOf (t0 + a + h), r.getY());
- p.lineTo (xOf (t0 + 2.0f * a + h), r.getBottom());
- g.setColour ((grain == 0 ? accent : colour::textSecondary).withAlpha (0.8f));
- g.strokePath (p, juce::PathStrokeType (1.5f));
- }
- }
- // Transistor Bass: the current program and its sequence (16 steps: note, gate, accent, slide)
- void paintTransistorBass (juce::Graphics& g, juce::Rectangle<float> r, float f)
- {
- using namespace theme;
- const auto* c = channelNow();
- const auto prog = c != nullptr ? transistorBassProgram (c->pluginState) : std::nullopt;
- if (! prog)
- return;
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (9.0f, 11.0f * f), true));
- const auto text = tr ("Program {0}", { juce::String (prog->program + 1) }) + " "
- + (prog->sequencer ? tr ("sequencer on") : tr ("sequencer off"))
- + (prog->transpose != 0 ? " " + tr ("transpose {0}", { juce::String (prog->transpose) }) : juce::String());
- g.drawFittedText (text, r.reduced (6.0f * f, 0.0f).toNearestInt(), juce::Justification::centredLeft, 1, 0.7f);
- }
- // the step numbers under the sequence, lit up to its length (round 168q2)
- void paintTransistorBassSteps (juce::Graphics& g, juce::Rectangle<float> r, float f)
- {
- using namespace theme;
- const auto* c = channelNow();
- const auto prog = c != nullptr ? transistorBassProgram (c->pluginState) : std::nullopt;
- const auto length = prog ? juce::jlimit (1, 16, prog->length) : 16;
- const auto w = r.getWidth() / 16.0f;
- g.setFont (font (juce::jmax (8.0f, 10.0f * f), true));
- for (int i = 0; i < 16; ++i)
- {
- const auto cell = juce::Rectangle<float> (r.getX() + w * (float) i, r.getY(), w, r.getHeight()).reduced (2.0f * f, 4.0f * f);
- const auto in = i < length;
- g.setColour (in ? accent.withAlpha (0.22f) : colour::bg3);
- g.fillRoundedRectangle (cell, radius::sm * f);
- g.setColour (in ? colour::textPrimary : colour::textDisabled);
- g.drawText (juce::String (i + 1), cell, juce::Justification::centred, false);
- }
- }
- static constexpr int transistorBassTools = 3;
- juce::Rectangle<float> transistorBassToolCell (juce::Rectangle<float> r, int i) const
- {
- const auto h = r.getHeight() / (float) transistorBassTools;
- return juce::Rectangle<float> (r.getX(), r.getY() + h * (float) i, r.getWidth(), h).reduced (2.0f * layoutFactor());
- }
- void paintTransistorBassTools (juce::Graphics& g, juce::Rectangle<float> r, float f)
- {
- using namespace theme;
- const juce::String caps[] = { tr ("Clear"), juce::String::fromUTF8 ("Oct +"), juce::String::fromUTF8 ("Oct \xe2\x88\x92") };
- for (int i = 0; i < transistorBassTools; ++i)
- {
- const auto cell = transistorBassToolCell (r, i);
- skin::button (g, cell, false, false, accent, radius::sm * f);
- g.setColour (colour::textPrimary);
- g.setFont (font (juce::jmax (8.0f, juce::jmin (10.0f * f, cell.getHeight() * 0.45f)), true));
- g.drawFittedText (caps[i], cell.toNearestInt(), juce::Justification::centred, 1, 0.6f);
- }
- }
- int transistorBassToolButton (const plugui::LayoutItem& item, juce::Point<float> p) const
- {
- for (int i = 0; i < transistorBassTools; ++i)
- if (transistorBassToolCell (layoutRect (item), i).contains (p))
- return i;
- return -1;
- }
- // FL's CLEAR (gates, slides and accents off, notes C5) and its octave up / down buttons on the whole sequence
- void transistorBassToolAction (int button)
- {
- const auto* c = channelNow();
- if (c == nullptr)
- return;
- auto next = c->pluginState;
- if (! (button == 0 ? transistorBassClearSequence (next) : transistorBassShiftSequence (next, button == 1 ? 1 : -1)))
- return;
- ref.edit (engine, [next = std::move (next)] (ChannelDef& d) { d.pluginState = next; });
- syncKnobs();
- repaint();
- }
- juce::Image beepMapCache;
- std::vector<std::uint8_t> beepMapCacheState;
- std::string granulizerPeaksPath;
- std::vector<float> granulizerPeaks;
- void loadGranulizerSample (const juce::File& file)
- {
- if (! takesSample() || ! file.existsAsFile())
- return;
- if (engine.getSampleLibrary().load (file.getFullPathName()) == nullptr)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Sample"), tr ("Could not read {0}", { file.getFileName() }));
- return;
- }
- ref.edit (engine, [path = file.getFullPathName().toStdString()] (ChannelDef& d) { d.samplePath = path; });
- if (sampleButton.isVisible())
- ui::setHint (sampleButton, file.getFullPathName());
- repaint();
- }
- bool dropHighlight = false;
- // Fruity Granulizer: what the keys move (Key to), where the slices come from (Transients), tempo lock and the beat
- // count it uses (REA_rodada165g-flgran165)
- void setupGranulizerModes (const ChannelDef& def)
- {
- const auto keyMode = granulizerMode (def.pluginState, 1), sliceMode = granulizerMode (def.pluginState, 0),
- sync = granulizerMode (def.pluginState, 2);
- if (! keyMode || ! sliceMode || ! sync)
- return;
- granulizerModes = true;
- auto label = [this] (juce::Label& l, const juce::String& text) {
- l.setText (text, juce::dontSendNotification);
- l.setFont (theme::font (theme::type::small));
- addAndMakeVisible (l);
- };
- label (granKeyToLabel, tr ("Key to"));
- granKeyTo.addItem (tr ("Pitch"), 1);
- granKeyTo.addItem (tr ("Percent"), 2);
- granKeyTo.addItem (tr ("Step"), 3);
- granKeyTo.addItem (tr ("Transient"), 4);
- granKeyTo.setSelectedId (std::clamp (*keyMode, 0, 3) + 1, juce::dontSendNotification);
- granKeyTo.setTooltip (tr ("What the keys do: Pitch = transpose; Percent = start point (sample time, C5 to C7); "
- "Step = start point in 16th notes (song time); Transient = start at the slice of the key"));
- granKeyTo.onChange = [this] {
- const auto v = granKeyTo.getSelectedId() - 1;
- ref.edit (engine, [v] (ChannelDef& d) { granulizerSetMode (d.pluginState, 1, v); });
- if (v == 3 && granTransients.getSelectedId() == 1) // as FL: transient keys switch slice detection on
- granTransients.setSelectedId (3, juce::dontSendNotification);
- };
- addAndMakeVisible (granKeyTo);
- label (granTransientsLabel, tr ("Transients"));
- granTransients.addItem (tr ("Off"), 1);
- granTransients.addItem (tr ("Use regions"), 2);
- granTransients.addItem (tr ("Detect"), 3);
- granTransients.setSelectedId (std::clamp (*sliceMode, 0, 2) + 1, juce::dontSendNotification);
- granTransients.setTooltip (tr ("Transients source: the sample's cue points / regions, or FL's automatic slicing. "
- "Grains then line up with the slices and the Transient hold knob sets how long each "
- "slice's first grain holds"));
- granTransients.onChange = [this] {
- const auto v = granTransients.getSelectedId() - 1;
- ref.edit (engine, [v] (ChannelDef& d) { granulizerSetMode (d.pluginState, 0, v); });
- };
- addAndMakeVisible (granTransients);
- granTempoLocked.setButtonText (tr ("Tempo locked"));
- granTempoLocked.setToggleState (*sync != 0, juce::dontSendNotification);
- granTempoLocked.setTooltip (tr ("Match song tempo: the sample plays once per its length in beats (the WAV's ACID "
- "beats, else Beats below). Loop is always on and Wave spacing has no effect while "
- "locked"));
- granTempoLocked.onClick = [this] {
- const auto on = granTempoLocked.getToggleState();
- ref.edit (engine, [on] (ChannelDef& d) { granulizerSetMode (d.pluginState, 2, on ? 1 : 0); });
- };
- addAndMakeVisible (granTempoLocked);
- label (granBeatsLabel, tr ("Beats (0 = the sample's own)"));
- granBeats.setSliderStyle (juce::Slider::LinearHorizontal);
- granBeats.setTextBoxStyle (juce::Slider::TextBoxRight, false, 56, 20);
- granBeats.setRange (0.0, 1024.0, 0.01);
- granBeats.setValue (def.sampler.stretchBeats, juce::dontSendNotification);
- granBeats.setTooltip (tr ("The sample's length in beats for Tempo locked and the Step keys, as FL's time-stretch "
- "TIME; a WAV with ACID beats uses its own"));
- granBeats.onValueChange = [this] {
- const auto v = (float) granBeats.getValue();
- ref.edit (engine, [v] (ChannelDef& d) { d.sampler.stretchBeats = v; });
- };
- addAndMakeVisible (granBeats);
- }
- bool granulizerModes = false;
- juce::ComboBox granKeyTo, granTransients;
- juce::ToggleButton granTempoLocked;
- juce::Slider granBeats;
- juce::Label granKeyToLabel, granTransientsLabel, granBeatsLabel;
- AudioEngine& engine;
- ChannelRef ref;
- juce::Colour accent { skin::colour::crimson }; // the plugin page's accent (ui/PluginSkin.h)
- skin::Style pageStyle = skin::Style::glow; // the plugin page's automatic style (round 126)
- skin::Art pageArt = skin::Art::none; // its own art (round 170j: Themed)
- std::unique_ptr<skin::ArtLayer> artLayer; // the art's moving part (petals, a glowing trefoil...)
- 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,
- fruitkick = false, bassdrum = false, toxic = false, threeOsc = false, simSynth = false, wasp = false, plucked = false, beepMap = false,
- sawer = false, flKeys = false, granulizer = false, drumaxx = false, slayer = false, fruityDance = false, sytrus = false, wavesFound = false,
- engineFilesMissing = false;
- int editorKey = 60;
- int drumPart = 0; // round 168p: the Drumaxx pad / DrumSynth Live key the per-part knobs edit
- std::vector<std::pair<juce::Slider*, const drumcontrols::Control*>> partKnobs;
- std::vector<std::unique_ptr<juce::Slider>> knobs;
- const plugui::Layout* layout = nullptr;
- const modelparams::Table* modelTable = nullptr; // the engine's listed parameters (round 168n)
- InstrumentKind instrumentKind = InstrumentKind::synth;
- const plugui::LayoutItem* stepperDrag = nullptr; // (round 169h)
- float stepperDragY = 0.0f;
- int stepperDragged = 0;
- int page = 0; // the layout's page shown (pageTabs items switch it; round 168n)
- const plugui::LayoutItem* xyItem = nullptr; // the pad being dragged
- juce::TextButton sampleButton; // (a Granulizer node: round 165c)
- std::unique_ptr<juce::FileChooser> chooser;
- };
- // FL's Sampler › "Precomputed effects", the loop flags and the declicking mode (REA_rodada167h §1–§3): computed once on
- // the sample when the channel changes (core/SamplePrecompute.h). Opened from the Sampler settings.
- class PrecomputePanel final : public juce::Component
- {
- public:
- PrecomputePanel (AudioEngine& e, ChannelRef c) : engine (e), ref (std::move (c))
- {
- const std::pair<juce::ToggleButton*, const char*> toggles[] = {
- { &removeDc, TR_NOOP ("Remove DC offset") }, { &normalize, TR_NOOP ("Normalize") }, { &polarity, TR_NOOP ("Reverse polarity") },
- { &fadeStereo, TR_NOOP ("Fade stereo") }, { &swapStereo, TR_NOOP ("Swap stereo") },
- { &useLoops, TR_NOOP ("Use loop points") }, { &pingPong, TR_NOOP ("Ping pong loop") } };
- for (auto [b, text] : toggles)
- {
- b->setButtonText (tr (text));
- b->onClick = [this] { apply(); };
- addAndMakeVisible (b);
- }
- normalize.setTooltip (tr ("Raises the sample so its loudest point reaches 0 dB"));
- fadeStereo.setTooltip (tr ("The left channel fades out over the sample while the right one fades in"));
- useLoops.setTooltip (tr ("Plays the loop stored in the sample file (WAV loop points)"));
- pingPong.setTooltip (tr ("The loop plays forward, then backward"));
- const std::tuple<juce::Slider*, juce::Label*, const char*, double> knobs[] = {
- { &fadeIn, &fadeInLabel, TR_NOOP ("Fade in"), 1024.0 }, { &fadeOut, &fadeOutLabel, TR_NOOP ("Fade out"), 1024.0 },
- { &crossfade, &crossfadeLabel, TR_NOOP ("Crossfade"), 2048.0 }, { &trim, &trimLabel, TR_NOOP ("Trim"), 32768.0 } };
- for (auto [k, label, text, hi] : knobs)
- {
- k->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- k->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 18);
- k->setRange (0.0, hi, 1.0);
- k->setDoubleClickReturnValue (true, 0.0);
- k->onValueChange = [this] { apply(); };
- addAndMakeVisible (k);
- label->setText (tr (text), juce::dontSendNotification);
- label->setJustificationType (juce::Justification::centred);
- addAndMakeVisible (label);
- }
- auto percent = [] (double hi) { return [hi] (double v) { return juce::String (v / hi * 100.0, 1) + "%"; }; };
- fadeIn.textFromValueFunction = percent (1024.0);
- fadeOut.textFromValueFunction = percent (1024.0);
- crossfade.textFromValueFunction = percent (2048.0);
- trim.textFromValueFunction = [] (double v) {
- return v <= 0.0 ? tr ("Off") : juce::String (20.0 * std::log10 (v / 32768.0), 1) + " dB";
- };
- fadeIn.setTooltip (tr ("Fades the sample in: 25% ramps over the whole sample, 100% over its last quarter"));
- fadeOut.setTooltip (tr ("Fades the sample out: 25% over the whole sample, 100% within its first quarter"));
- crossfade.setTooltip (tr ("Crossfades the loop's end into its start (a share of the loop), for a smooth loop"));
- trim.setTooltip (tr ("Cuts the silence below this level at the sample's start and end"));
- declickLabel.setText (tr ("Declicking mode"), juce::dontSendNotification);
- addAndMakeVisible (declickLabel);
- declick.addItemList ({ tr ("Out only"), tr ("Transient (no bleeding)"), tr ("Transient"), tr ("Generic"), tr ("Smooth"), tr ("Crossfade") }, 1);
- 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)"));
- declick.onChange = [this] { apply(); };
- addAndMakeVisible (declick);
- // FL's legacy effects page (REA_rodada167l §1): FL's knob ranges, defaults and hints
- legacyHeader.setText (tr ("Legacy effects"), juce::dontSendNotification);
- legacyHeader.setFont (juce::FontOptions (13.0f, juce::Font::bold));
- addAndMakeVisible (legacyHeader);
- const std::tuple<juce::Slider*, juce::Label*, const char*, const char*, double, double, double> legacy[] = {
- { &boost, &boostLabel, TR_NOOP ("Boost"), TR_NOOP ("Boosts the gain"), 0.0, 256.0, 0.0 },
- { &eq, &eqLabel, TR_NOOP ("EQ"), TR_NOOP ("Shifts the frequency balance"), 0.0, 256.0, 128.0 },
- { &ringMix, &ringMixLabel, TR_NOOP ("RM mix"), TR_NOOP ("Ring modulation mix"), 0.0, 256.0, 0.0 },
- { &ringFreq, &ringFreqLabel, TR_NOOP ("RM freq"), TR_NOOP ("Ring modulation frequency"), 0.0, 256.0, 128.0 },
- { &pogo, &pogoLabel, TR_NOOP ("Pogo"), TR_NOOP ("Pogo effect"), 0.0, 512.0, 256.0 },
- { &cutoff, &cutoffLabel, TR_NOOP ("Cut"), TR_NOOP ("Filter cutoff"), 16.0, 1024.0, 1024.0 },
- { &resonance, &resonanceLabel, TR_NOOP ("Res"), TR_NOOP ("Filter resonance"), 0.0, 640.0, 0.0 },
- { &stereoDelay, &stereoDelayLabel, TR_NOOP ("Stereo delay"), TR_NOOP ("Stereo delay"), 0.0, 4096.0, 2048.0 },
- { &reverbAmount, &reverbLabel, TR_NOOP ("Reverb"), TR_NOOP ("Reverb amount"), 0.0, 256.0, 0.0 } };
- for (auto [k, label, text, hint, lo, hi, def] : legacy)
- {
- k->setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- k->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 56, 18);
- k->setRange (lo, hi, 1.0);
- k->setValue (def, juce::dontSendNotification);
- k->setDoubleClickReturnValue (true, def);
- k->setTooltip (tr (hint));
- k->onValueChange = [this] { apply(); };
- addAndMakeVisible (k);
- label->setText (tr (text), juce::dontSendNotification);
- label->setJustificationType (juce::Justification::centred);
- addAndMakeVisible (label);
- }
- reverbType.addItemList ({ tr ("Type 1"), tr ("Type 2") }, 1);
- reverbType.setTooltip (tr ("Reverb type"));
- reverbType.onChange = [this] { apply(); };
- addAndMakeVisible (reverbType);
- clip.setButtonText (tr ("Clip"));
- clip.setTooltip (tr ("Add clipping at 0dB"));
- clip.onClick = [this] { apply(); };
- addAndMakeVisible (clip);
- load();
- setSize (500, 560);
- }
- void resized() override
- {
- auto area = getLocalBounds().reduced (12);
- auto rows = area.removeFromTop (4 * 26);
- auto left = rows.removeFromLeft (rows.getWidth() / 2);
- for (auto* b : { &removeDc, &normalize, &polarity, &fadeStereo })
- b->setBounds (left.removeFromTop (26));
- for (auto* b : { &swapStereo, &useLoops, &pingPong })
- b->setBounds (rows.removeFromTop (26));
- area.removeFromTop (10);
- auto knobRow = area.removeFromTop (110);
- const auto w = knobRow.getWidth() / 4;
- for (auto [k, label] : { std::pair { &fadeIn, &fadeInLabel }, { &fadeOut, &fadeOutLabel }, { &crossfade, &crossfadeLabel }, { &trim, &trimLabel } })
- {
- auto column = knobRow.removeFromLeft (w);
- label->setBounds (column.removeFromTop (18));
- k->setBounds (column);
- }
- area.removeFromTop (12);
- auto row = area.removeFromTop (26);
- declickLabel.setBounds (row.removeFromLeft (140));
- declick.setBounds (row.removeFromLeft (220));
- area.removeFromTop (14);
- legacyHeader.setBounds (area.removeFromTop (20));
- auto layoutRow = [] (juce::Rectangle<int> r, std::initializer_list<std::pair<juce::Slider*, juce::Label*>> knobs) {
- const auto w = r.getWidth() / 5;
- for (auto [k, label] : knobs)
- {
- auto column = r.removeFromLeft (w);
- label->setBounds (column.removeFromTop (18));
- k->setBounds (column);
- }
- return r;
- };
- layoutRow (area.removeFromTop (96), { { &boost, &boostLabel }, { &eq, &eqLabel }, { &ringMix, &ringMixLabel }, { &ringFreq, &ringFreqLabel }, { &pogo, &pogoLabel } });
- area.removeFromTop (6);
- auto last = layoutRow (area.removeFromTop (96), { { &cutoff, &cutoffLabel }, { &resonance, &resonanceLabel }, { &stereoDelay, &stereoDelayLabel }, { &reverbAmount, &reverbLabel } });
- last.removeFromTop (22);
- reverbType.setBounds (last.removeFromTop (24).reduced (4, 0));
- last.removeFromTop (8);
- clip.setBounds (last.removeFromTop (24).reduced (4, 0));
- }
- private:
- void load()
- {
- const auto* c = ref.get (engine);
- if (c == nullptr)
- return;
- const juce::ScopedValueSetter<bool> guard (loading, true);
- const auto& p = c->sampler.precompute;
- removeDc.setToggleState (p.removeDc, juce::dontSendNotification);
- normalize.setToggleState (p.normalize, juce::dontSendNotification);
- polarity.setToggleState (p.reversePolarity, juce::dontSendNotification);
- fadeStereo.setToggleState (p.fadeStereo, juce::dontSendNotification);
- swapStereo.setToggleState (p.swapStereo, juce::dontSendNotification);
- useLoops.setToggleState (c->sampler.useLoopPoints, juce::dontSendNotification);
- pingPong.setToggleState (p.pingPong, juce::dontSendNotification);
- fadeIn.setValue (p.fadeIn, juce::dontSendNotification);
- fadeOut.setValue (p.fadeOut, juce::dontSendNotification);
- crossfade.setValue (p.crossfade, juce::dontSendNotification);
- trim.setValue (p.trim, juce::dontSendNotification);
- boost.setValue (p.boost, juce::dontSendNotification);
- eq.setValue (p.eq, juce::dontSendNotification);
- ringMix.setValue (p.ringMix, juce::dontSendNotification);
- ringFreq.setValue (p.ringFreq, juce::dontSendNotification);
- pogo.setValue (p.pogo, juce::dontSendNotification);
- cutoff.setValue (p.cutoff, juce::dontSendNotification);
- resonance.setValue (p.resonance, juce::dontSendNotification);
- stereoDelay.setValue (p.stereoDelay, juce::dontSendNotification);
- reverbAmount.setValue (p.reverb, juce::dontSendNotification);
- reverbType.setSelectedId (p.reverbType == 0 ? 1 : 2, juce::dontSendNotification);
- clip.setToggleState (p.clip, juce::dontSendNotification);
- declick.setSelectedId (juce::jlimit (0, 5, c->sampler.declickMode) + 1, juce::dontSendNotification);
- }
- void apply()
- {
- if (loading)
- return;
- SamplePrecompute p;
- p.removeDc = removeDc.getToggleState();
- p.normalize = normalize.getToggleState();
- p.reversePolarity = polarity.getToggleState();
- p.fadeStereo = fadeStereo.getToggleState();
- p.swapStereo = swapStereo.getToggleState();
- p.pingPong = pingPong.getToggleState();
- p.fadeIn = (int) fadeIn.getValue();
- p.fadeOut = (int) fadeOut.getValue();
- p.crossfade = (int) crossfade.getValue();
- p.trim = (int) trim.getValue();
- p.boost = (int) boost.getValue();
- p.eq = (int) eq.getValue();
- p.ringMix = (int) ringMix.getValue();
- p.ringFreq = (int) ringFreq.getValue();
- p.pogo = (int) pogo.getValue();
- p.cutoff = (int) cutoff.getValue();
- p.resonance = (int) resonance.getValue();
- p.stereoDelay = (int) stereoDelay.getValue();
- p.reverb = (int) reverbAmount.getValue();
- p.reverbType = reverbType.getSelectedId() == 1 ? 0 : 1;
- p.clip = clip.getToggleState();
- const auto loops = useLoops.getToggleState();
- const auto mode = juce::jlimit (0, 5, declick.getSelectedId() - 1);
- const auto* c = ref.get (engine);
- if (c == nullptr || (c->sampler.precompute == p && c->sampler.useLoopPoints == loops && c->sampler.declickMode == mode))
- return;
- ref.edit (engine, [p, loops, mode] (ChannelDef& d) {
- d.sampler.precompute = p;
- d.sampler.useLoopPoints = loops;
- d.sampler.declickMode = mode;
- });
- }
- AudioEngine& engine;
- ChannelRef ref;
- bool loading = false;
- juce::ToggleButton removeDc, normalize, polarity, fadeStereo, swapStereo, useLoops, pingPong;
- juce::Slider fadeIn, fadeOut, crossfade, trim;
- juce::Label fadeInLabel, fadeOutLabel, crossfadeLabel, trimLabel, declickLabel;
- juce::ComboBox declick;
- juce::Label legacyHeader;
- juce::Slider boost, eq, ringMix, ringFreq, pogo, cutoff, resonance, stereoDelay, reverbAmount;
- juce::Label boostLabel, eqLabel, ringMixLabel, ringFreqLabel, pogoLabel, cutoffLabel, resonanceLabel, stereoDelayLabel, reverbLabel;
- juce::ComboBox reverbType;
- juce::ToggleButton clip;
- };
- class SettingsPanel final : public juce::Component,
- public juce::DragAndDropTarget,
- public juce::FileDragAndDropTarget,
- private juce::ChangeListener,
- private juce::Timer
- {
- public:
- SettingsPanel (AudioEngine& e, ChannelRef c)
- : engine (e),
- ref (std::move (c))
- {
- setup (pitch, pitchLabel, TR_NOOP ("Pitch"), -24.0, 24.0, 0.01, " st");
- 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"));
- setup (gain, gainLabel, TR_NOOP ("Gain"), -24.0, 24.0, 0.1, " dB");
- gain.textFromValueFunction = [] (double v) { return (v > 0.04 ? "+" : "") + juce::String (std::abs (v) < 0.05 ? 0.0 : v, 1) + " dB"; };
- gain.valueFromTextFunction = [] (const juce::String& t) { return t.retainCharacters ("+-0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
- gain.setTooltip (tr ("Sample gain: boosts or cuts the sample's level before the channel volume (-24 to +24 dB, double-click = 0 dB)"));
- gain.setValue (0.0, juce::dontSendNotification);
- setup (attack, attackLabel, TR_NOOP ("Attack"), 0.0, 2.0, 0.001, " s");
- setup (release, releaseLabel, TR_NOOP ("Release"), 0.0, 4.0, 0.001, " s");
- setup (decay, decayLabel, TR_NOOP ("Decay"), 0.0, 10.0, 0.001, " s");
- setup (sustain, sustainLabel, TR_NOOP ("Sustain"), 0.0, 1.0, 0.01, "");
- setup (stretch, stretchLabel, TR_NOOP ("Stretch"), 0.0, 1024.0, 0.01, " beats");
- // 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
- // to round them to 0.25 and cap them at 64, and every other edit in this panel wrote the rounded value back
- stretch.setSkewFactorFromMidPoint (16.0);
- stretch.addMouseListener (&stretchMenu, false);
- setup (regionStart, regionStartLabel, TR_NOOP ("Start"), 0.0, 1.0, 0.001, "");
- setup (regionEnd, regionEndLabel, TR_NOOP ("End"), 0.0, 1.0, 0.001, "");
- setup (cutoff, cutoffLabel, TR_NOOP ("Cutoff"), 20.0, 20000.0, 1.0, " Hz");
- setup (resonance, resonanceLabel, TR_NOOP ("Resonance"), 0.0, 1.0, 0.01, "");
- cutoff.setSkewFactorFromMidPoint (1000.0);
- cutoff.setDoubleClickReturnValue (true, 20000.0);
- cutoff.setTooltip (tr ("Channel filter cutoff (low-pass at maximum with no resonance = off)"));
- filterType.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
- filterType.onChange = [this] { apply(); };
- addAndMakeVisible (filterType);
- modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
- modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
- addAndMakeVisible (modulationButton);
- precomputeButton.setButtonText (tr ("Precomputed effects..."));
- 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"));
- precomputeButton.onClick = [this] {
- juce::CallOutBox::launchAsynchronously (std::make_unique<PrecomputePanel> (engine, ref), precomputeButton.getScreenBounds(), nullptr);
- };
- addAndMakeVisible (precomputeButton);
- regionEnd.setDoubleClickReturnValue (true, 1.0);
- regionStart.setTooltip (tr ("Where the sample starts playing (fraction of the file)"));
- sustain.setDoubleClickReturnValue (true, 1.0);
- decay.setSkewFactorFromMidPoint (0.5);
- stretch.setTooltip (tr ("0 = off. Otherwise the whole sample lasts this many beats and follows the BPM (by resampling, like FL's Resample mode)"));
- attack.setSkewFactorFromMidPoint (0.2);
- release.setSkewFactorFromMidPoint (0.4);
- release.setTooltip (tr ("0 = the whole sample plays (one-shot), like FL's steps"));
- keepPitch.setButtonText (tr ("Keep length (stretch engine)"));
- 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"));
- keepPitch.onClick = [this] { apply(); };
- addAndMakeVisible (keepPitch);
- stretchMethod.addItem (tr ("General"), 1);
- stretchMethod.addItem (tr ("Drums / transients"), 2);
- stretchMethod.addItem (tr ("Vocal / mono"), 3);
- 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"));
- stretchMethod.onChange = [this] { apply(); };
- addAndMakeVisible (stretchMethod);
- reverse.setButtonText (tr ("Reverse"));
- cut.setButtonText (tr ("Cut itself"));
- porta.setButtonText ("Porta");
- porta.setTooltip (tr ("Portamento: the note starts from the previous note's pitch (with Cut itself, the 808 glide)"));
- cut.setTooltip (tr ("A new note cuts the previous one (good for hi-hats and 808s)"));
- for (auto* b : { &reverse, &cut, &porta })
- {
- addAndMakeVisible (b);
- b->onClick = [this] { apply(); };
- }
- // the knobs an automation clip can drive (samplerparam, issue #12): right-click = FL's parameter menu; a move
- // is a tweak (Last tweaked, automation recording)
- for (auto [slider, param] : { std::pair { &attack, (int) samplerparam::attack }, { &decay, (int) samplerparam::decay },
- { &sustain, (int) samplerparam::sustain }, { &release, (int) samplerparam::release },
- { &cutoff, (int) samplerparam::cutoff }, { &resonance, (int) samplerparam::resonance },
- { ®ionStart, (int) samplerparam::start }, { ®ionEnd, (int) samplerparam::end } })
- {
- if (ref.index < 0) // (a Patcher node: no automation target)
- break;
- const auto target = [this, param] { return AutomationTarget { AutomationTargetKind::channelParam, ref.index, 0, param }; };
- // one menu, FL's parameter menu (the slider contract's plain value menu used to open beside it)
- ui::setOwnMenu (*slider);
- slider->onMenu = [this, slider, target] { ui::showSliderMenu (*slider, &engine, target()); };
- slider->onDragStart = [this, target] { engine.noteTweaked (target(), true); };
- slider->onDragEnd = [this, target] { engine.tweakReleased (target()); };
- tweakTargets.push_back ({ slider, param });
- }
- wave.setEmptyText (tr ("No sample loaded"));
- wave.setTooltip (tr ("The sample: colours show where it is bass-heavy (warm) or bright (cool); outside Start/End is dimmed"));
- addAndMakeVisible (wave);
- refresh();
- engine.addChangeListener (this);
- setSize (420, 676);
- if (ref.index >= 0)
- startTimerHz (30); // the knobs follow their automation while the song plays (issue #12)
- }
- ~SettingsPanel() override { engine.removeChangeListener (this); }
- void resized() override
- {
- auto area = getLocalBounds().reduced (12);
- wave.setBounds (area.removeFromTop (92));
- area.removeFromTop (8);
- auto place = [] (juce::Rectangle<int> row, std::initializer_list<std::pair<juce::Slider*, juce::Label*>> items) {
- const auto w = row.getWidth() / 3;
- for (auto [slider, label] : items)
- {
- auto column = row.removeFromLeft (w);
- label->setBounds (column.removeFromTop (18));
- slider->setBounds (column);
- }
- };
- auto top = area.removeFromTop (110);
- {
- // Gain, Pitch, Stretch and the keep-pitch switch (a third of the width: its text is long)
- const auto w4 = top.getWidth() * 2 / 9;
- for (auto [slider, label] : { std::pair { &gain, &gainLabel }, { &pitch, &pitchLabel }, { &stretch, &stretchLabel } })
- {
- auto column = top.removeFromLeft (w4);
- label->setBounds (column.removeFromTop (18));
- slider->setBounds (column);
- }
- auto column = top.withSizeKeepingCentre (juce::jmin (top.getWidth(), 140), juce::jmin (top.getHeight(), 64));
- keepPitch.setBounds (column.removeFromTop (column.getHeight() / 2));
- stretchMethod.setBounds (column.withSizeKeepingCentre (column.getWidth(), juce::jmin (column.getHeight(), 24)));
- }
- area.removeFromTop (6);
- auto envelope = area.removeFromTop (110);
- const auto w = envelope.getWidth() / 4;
- for (auto [slider, label] : { std::pair { &attack, &attackLabel }, { &decay, &decayLabel }, { &sustain, &sustainLabel }, { &release, &releaseLabel } })
- {
- auto column = envelope.removeFromLeft (w);
- label->setBounds (column.removeFromTop (18));
- slider->setBounds (column);
- }
- area.removeFromTop (8);
- area.removeFromTop (6);
- place (area.removeFromTop (110), { { ®ionStart, ®ionStartLabel }, { ®ionEnd, ®ionEndLabel } });
- area.removeFromTop (6);
- {
- auto filterRow = area.removeFromTop (110);
- filterType.setBounds (filterRow.removeFromRight (filterRow.getWidth() / 3).withSizeKeepingCentre (124, 24));
- place (filterRow.withWidth (filterRow.getWidth() * 3 / 2), { { &cutoff, &cutoffLabel }, { &resonance, &resonanceLabel } });
- }
- {
- auto buttons = area.removeFromBottom (26);
- const auto half = buttons.getWidth() / 2;
- modulationButton.setBounds (buttons.removeFromLeft (half).reduced (4, 0));
- precomputeButton.setBounds (buttons.reduced (4, 0));
- }
- area.removeFromTop (6);
- reverse.setBounds (area.removeFromLeft (150).removeFromTop (24));
- cut.setBounds (area.removeFromLeft (130).removeFromTop (24));
- porta.setBounds (area.removeFromLeft (100).removeFromTop (24));
- }
- int getChannel() const noexcept { return ref.index; }
- // A sample dropped on the waveform (from the Browser or the system) replaces the channel's sample (issue #12)
- bool isInterestedInDragSource (const SourceDetails& details) override
- {
- return BrowserComponent::isBrowserDrag (details) && SampleLibrary::isSampleFile (BrowserComponent::draggedFile (details));
- }
- void itemDragEnter (const SourceDetails&) override { setDropHighlight (true); }
- void itemDragExit (const SourceDetails&) override { setDropHighlight (false); }
- void itemDropped (const SourceDetails& details) override
- {
- setDropHighlight (false);
- replaceSample (BrowserComponent::draggedFile (details));
- }
- bool isInterestedInFileDrag (const juce::StringArray& files) override
- {
- return files.size() == 1 && SampleLibrary::isSampleFile (juce::File (files[0]));
- }
- void fileDragEnter (const juce::StringArray&, int, int) override { setDropHighlight (true); }
- void fileDragExit (const juce::StringArray&) override { setDropHighlight (false); }
- void filesDropped (const juce::StringArray& files, int, int) override
- {
- setDropHighlight (false);
- replaceSample (juce::File (files[0]));
- }
- void paintOverChildren (juce::Graphics& g) override
- {
- if (dropHighlight)
- {
- g.setColour (theme::colour::accent);
- g.drawRect (wave.getBounds().expanded (2), 2);
- }
- }
- private:
- void setDropHighlight (bool on)
- {
- if (dropHighlight != on)
- {
- dropHighlight = on;
- repaint (wave.getBounds().expanded (4));
- }
- }
- // the new sample plays with the same settings; slices of the old one no longer apply, the channel takes its name
- void replaceSample (const juce::File& file)
- {
- if (current() == nullptr || ! file.existsAsFile())
- return;
- if (engine.getSampleLibrary().load (file.getFullPathName()) == nullptr)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Sample"), tr ("Could not read {0}", { file.getFileName() }));
- return;
- }
- ref.edit (engine, [path = file.getFullPathName().toStdString(), name = file.getFileNameWithoutExtension().toStdString()] (ChannelDef& d) {
- d.samplePath = path;
- d.zones.clear();
- d.sampler.slices.clear();
- d.name = name;
- });
- }
- void setup (juce::Slider& s, juce::Label& label, const char* name, double lo, double hi, double step, const char* suffix)
- {
- s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 18);
- s.setRange (lo, hi, step);
- s.setTextValueSuffix (suffix);
- s.setDoubleClickReturnValue (true, 0.0);
- s.onValueChange = [this, &s] { apply (&s); };
- label.setText (tr (name), juce::dontSendNotification);
- label.setJustificationType (juce::Justification::centred);
- addAndMakeVisible (s);
- addAndMakeVisible (label);
- }
- const ChannelDef* current() const
- {
- return ref.get (engine);
- }
- void refresh()
- {
- if (const auto* c = current())
- {
- updating = true;
- pitch.setValue (c->sampler.pitch, juce::dontSendNotification);
- gain.setValue (c->sampler.gainDb, juce::dontSendNotification);
- attack.setValue (c->sampler.attack, juce::dontSendNotification);
- decay.setValue (c->sampler.decay, juce::dontSendNotification);
- sustain.setValue (c->sampler.sustain, juce::dontSendNotification);
- stretch.setValue (c->sampler.stretchBeats, juce::dontSendNotification);
- shownStretch = stretch.getValue();
- keepPitch.setToggleState (c->sampler.keepPitch, juce::dontSendNotification);
- stretchMethod.setSelectedId ((int) c->sampler.stretchMethod + 1, juce::dontSendNotification);
- stretchMethod.setEnabled (c->sampler.keepPitch);
- regionStart.setValue (c->sampler.regionStart, juce::dontSendNotification);
- regionEnd.setValue (c->sampler.regionEnd, juce::dontSendNotification);
- cutoff.setValue (c->sampler.cutoff, juce::dontSendNotification);
- resonance.setValue (c->sampler.resonance, juce::dontSendNotification);
- filterType.setSelectedId (c->sampler.filterType + 1, juce::dontSendNotification);
- release.setValue (c->sampler.release, juce::dontSendNotification);
- reverse.setToggleState (c->sampler.reverse, juce::dontSendNotification);
- cut.setToggleState (channelCutsItself (*c), juce::dontSendNotification); // (issue #68: the rack menu's state too)
- porta.setToggleState (c->sampler.porta, juce::dontSendNotification);
- updating = false;
- showAutomation (true);
- const auto path = juce::String::fromUTF8 ((c->samplePath.empty() && ! c->zones.empty() ? c->zones.front().path : c->samplePath).c_str());
- wave.setFile (path, [&e = engine, path] { return e.getSampleLibrary().load (path); });
- wave.setRegion (c->sampler.regionStart, c->sampler.regionEnd);
- wave.setReversed (c->sampler.reverse);
- if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
- w->setName (tr ("Sampler settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) })
- + (c->zones.empty() ? juce::String() : tr (" (multi-sample: {0} zones)", { juce::String ((int) c->zones.size()) })));
- }
- }
- // The knobs an automation drives show its value while the song plays, as in FL (issue #12); a knob held by the
- // mouse shows the hand's value. `force`: after refresh() put the Song's values back.
- void showAutomation (bool force)
- {
- const auto* c = current();
- if (c == nullptr || ref.index < 0)
- return;
- const auto& shown = engine.getAutomationDisplay();
- if (! force && shown.getGeneration() == shownGeneration)
- return;
- shownGeneration = shown.getGeneration();
- if (! force && automatedShown.empty() && ! shown.any())
- return;
- std::vector<juce::Slider*> now;
- updating = true;
- for (const auto& [slider, param] : tweakTargets)
- {
- if (slider->isMouseButtonDown())
- continue;
- const auto v = shown.valueOf ({ AutomationTargetKind::channelParam, ref.index, 0, param });
- const auto was = std::find (automatedShown.begin(), automatedShown.end(), slider) != automatedShown.end();
- if (v)
- {
- slider->setValue (samplerparam::toNatural (param, *v), juce::dontSendNotification);
- now.push_back (slider);
- }
- else if (was && ! force)
- slider->setValue (samplerparam::toNatural (param, samplerparam::get (c->sampler, param)), juce::dontSendNotification);
- }
- updating = false;
- automatedShown = std::move (now);
- wave.setRegion ((float) regionStart.getValue(), (float) regionEnd.getValue());
- }
- void timerCallback() override
- {
- if (isShowing())
- showAutomation (false);
- }
- // the Song's value of `param` (a knob that shows its automation must not write the automated value back)
- static void keepSongValue (SamplerSettings& s, const SamplerSettings& song, int param) noexcept
- {
- switch (param)
- {
- case samplerparam::attack: s.attack = song.attack; break;
- case samplerparam::decay: s.decay = song.decay; break;
- case samplerparam::sustain: s.sustain = song.sustain; break;
- case samplerparam::release: s.release = song.release; break;
- case samplerparam::cutoff: s.cutoff = song.cutoff; break;
- case samplerparam::resonance: s.resonance = song.resonance; break;
- case samplerparam::start: s.regionStart = song.regionStart; break;
- case samplerparam::end: s.regionEnd = song.regionEnd; break;
- default: break;
- }
- }
- void apply (juce::Slider* changed = nullptr)
- {
- if (updating || current() == nullptr)
- return;
- auto s = current()->sampler; // keeps what the panel does not show (slices)
- s.pitch = (float) pitch.getValue();
- s.gainDb = std::abs (gain.getValue()) < 0.05 ? 0.0f : (float) gain.getValue();
- s.attack = (float) attack.getValue();
- s.decay = (float) decay.getValue();
- s.sustain = (float) sustain.getValue();
- if (changed == &stretch || stretch.getValue() != shownStretch) // (unmoved: keep the exact value, not the knob's)
- s.stretchBeats = (float) (shownStretch = stretch.getValue());
- s.keepPitch = keepPitch.getToggleState();
- s.stretchMethod = (StretchMethod) juce::jlimit (0, 2, stretchMethod.getSelectedId() - 1);
- stretchMethod.setEnabled (s.keepPitch);
- s.regionStart = (float) regionStart.getValue();
- s.regionEnd = (float) regionEnd.getValue();
- s.release = (float) release.getValue();
- s.reverse = reverse.getToggleState();
- s.cut = cut.getToggleState();
- const auto cutChanged = s.cut != channelCutsItself (*current()); // (issue #68: the rack menu's cut-itself too)
- s.porta = porta.getToggleState();
- s.cutoff = (float) cutoff.getValue();
- s.resonance = (float) resonance.getValue();
- s.filterType = juce::jlimit (0, 3, filterType.getSelectedId() - 1);
- for (const auto& [slider, param] : tweakTargets)
- if (slider != changed && std::find (automatedShown.begin(), automatedShown.end(), slider) != automatedShown.end())
- keepSongValue (s, current()->sampler, param);
- {
- // an ADSR edited by hand replaces FL's imported volume envelope
- const auto& old = current()->sampler;
- auto moved = [] (float a, float b) { return std::abs (a - b) > 1.0e-4f; };
- const auto adsr = moved (s.attack, old.attack) || moved (s.decay, old.decay) || moved (s.sustain, old.sustain) || moved (s.release, old.release);
- if (adsr)
- s.flVolumeEnvelope.clear();
- // so does an edited envelope or filter for FL's whole sampler voice (REA_rodada76)
- if (adsr || moved (s.cutoff, old.cutoff) || moved (s.resonance, old.resonance) || s.filterType != old.filterType)
- s.flChannel.clear();
- }
- if (s == current()->sampler && ! cutChanged)
- return;
- const auto before = current()->sampler;
- ref.edit (engine, [s, cutChanged, index = ref.index] (ChannelDef& channelDef) {
- channelDef.sampler = s;
- if (cutChanged)
- setChannelCutsItself (channelDef, index, s.cut);
- });
- for (const auto& [slider, param] : tweakTargets)
- if (std::abs (samplerparam::get (before, param) - samplerparam::get (s, param)) > 1.0e-6f)
- engine.noteTweaked ({ AutomationTargetKind::channelParam, ref.index, 0, param });
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override
- {
- if (current() == nullptr) // channel removed
- {
- if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
- juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
- if (safe != nullptr)
- safe->closeButtonPressed();
- });
- return;
- }
- refresh();
- }
- AudioEngine& engine;
- ChannelRef ref;
- bool updating = false;
- juce::Slider pitch, gain, stretch;
- double shownStretch = 0.0;
- // FL's TIME knob menu (r168s c_f20): (none), Autodetect, Project tempo, 1 beat, 2 beats, 1 bar, 2 bars, 3 bars, 4 bars
- struct StretchMenu final : juce::MouseListener
- {
- explicit StretchMenu (SettingsPanel& p) : panel (p) {}
- void mouseDown (const juce::MouseEvent& e) override
- {
- if (e.mods.isPopupMenu())
- panel.showStretchMenu();
- }
- SettingsPanel& panel;
- } stretchMenu { *this };
- void showStretchMenu()
- {
- const auto* c = current();
- if (c == nullptr)
- return;
- const auto& song = engine.getSong();
- const auto sample = engine.getSampleLibrary().load (juce::String::fromUTF8 (c->samplePath.c_str()));
- const auto now = c->sampler.stretchBeats;
- auto set = [this] (float beats) { ref.edit (engine, [beats] (ChannelDef& d) { d.sampler.stretchBeats = beats; }); };
- juce::PopupMenu m;
- m.addItem (tr ("(none)"), true, now <= 0.0f, [set] { set (0.0f); });
- m.addItem (tr ("Autodetect"), sample != nullptr, false, [set, sample, bpm = song.bpm] { set (tempodetect::fitBeatsOf (sample.get(), bpm)); });
- const auto atTempo = sample != nullptr && sample->sampleRate > 0.0 ? (float) ((double) sample->frames() / sample->sampleRate * song.bpm / 60.0) : 0.0f;
- m.addItem (tr ("Project tempo"), atTempo > 0.0f, false, [set, atTempo] { set (atTempo); });
- for (const auto preset : clipops::timePresetBeats (song.beatsPerBar))
- {
- const auto bars = song.beatsPerBar > 0 && preset >= (float) song.beatsPerBar ? preset / (float) song.beatsPerBar : 0.0f;
- const auto label = bars > 0.0f ? (bars == 1.0f ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars, 0) }))
- : (preset == 1.0f ? tr ("1 beat") : tr ("{0} beats", { juce::String (preset, 0) }));
- m.addItem (label, true, now == preset, [set, preset] { set (preset); });
- }
- m.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&stretch));
- }
- MenuSlider attack, release, decay, sustain, regionStart, regionEnd, cutoff, resonance;
- std::vector<std::pair<MenuSlider*, int>> tweakTargets; // knob -> samplerparam
- std::vector<juce::Slider*> automatedShown; // knobs showing their automation's value now
- std::uint32_t shownGeneration = 0;
- bool dropHighlight = false;
- juce::Label pitchLabel, gainLabel, attackLabel, releaseLabel, decayLabel, sustainLabel, stretchLabel, regionStartLabel, regionEndLabel,
- cutoffLabel, resonanceLabel;
- juce::ToggleButton reverse, cut, keepPitch, porta;
- juce::ComboBox filterType, stretchMethod;
- juce::TextButton modulationButton, precomputeButton;
- ui::WaveformDisplay wave;
- };
- // Built-in synth page: 3 oscillators, envelope and filter.
- class SynthPanel final : public juce::Component,
- private juce::ChangeListener
- {
- public:
- SynthPanel (AudioEngine& e, ChannelRef c)
- : engine (e),
- ref (std::move (c))
- {
- for (int o = 0; o < 3; ++o)
- {
- auto& row = rows[(std::size_t) o];
- row.title.setText (tr ("Osc {0}", { juce::String (o + 1) }), juce::dontSendNotification);
- row.wave.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Saw"), tr ("Square"), tr ("Noise"), tr ("Harmonics") }, 1);
- row.wave.onChange = [this] { apply(); };
- knob (row.octave, -3.0, 3.0, 1.0, " oct");
- knob (row.semitones, -11.0, 11.0, 1.0, " st");
- knob (row.detune, -100.0, 100.0, 1.0, " ct");
- knob (row.pan, -1.0, 1.0, 0.01, "");
- knob (row.level, 0.0, 4.0, 0.01, "");
- row.level.setSkewFactorFromMidPoint (1.0); // above 1: gain (Harmor goes up to +12 dB)
- addAndMakeVisible (row.title);
- addAndMakeVisible (row.wave);
- }
- knob (attack, 0.0, 5.0, 0.001, " s");
- knob (decay, 0.0, 5.0, 0.001, " s");
- knob (sustain, 0.0, 1.0, 0.01, "");
- knob (release, 0.0, 5.0, 0.001, " s");
- knob (cutoff, 20.0, 20000.0, 1.0, " Hz");
- knob (resonance, 0.0, 1.0, 0.01, "");
- knob (fm, 0.0, 8.0, 0.01, "");
- fm.setSkewFactorFromMidPoint (1.0);
- fm.setTooltip (tr ("FM: osc 3 (which stops sounding) modulates the phase of osc 1 and 2; 0 = off"));
- knob (fmDecay, 0.0, 5.0, 0.001, " s");
- fmDecay.setSkewFactorFromMidPoint (0.5);
- fmDecay.setTooltip (tr ("Time for the FM index to decay (0 = constant); the brightness fades like an electric piano"));
- knob (keyTrack, -1.0, 2.0, 0.01, "");
- keyTrack.setTooltip (tr ("Cutoff follows the note: cutoff octaves per note octave, relative to C3 (130.8 Hz)"));
- knob (sweep, 0.0, 100.0, 0.01, "");
- sweep.setSkewFactorFromMidPoint (2.0);
- sweep.setTooltip (tr ("Kick pitch sweep: the note starts (1 + value) times higher and falls"));
- knob (sweepTime, 0.001, 2.0, 0.001, " s");
- sweepTime.setSkewFactorFromMidPoint (0.1);
- sweepTime.setTooltip (tr ("Sweep time constant"));
- for (auto* b : { &bandLow, &bandMid, &bandHigh })
- {
- knob (*b, 0.0, 2.0, 0.01, "");
- b->setTooltip (tr ("3-band tone after the filter (low < 178 Hz < mid < 1.18 kHz < high); 1 = unchanged"));
- }
- ring.setButtonText (tr ("Ring"));
- ring.setTooltip (tr ("With AM on: ring modulation, (osc 1 + 2) × (1 − level + osc 3), like Sytrus's RM"));
- ring.onClick = [this] { apply(); };
- addAndMakeVisible (ring);
- modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
- modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
- addAndMakeVisible (modulationButton);
- for (auto* s : { &attack, &decay, &release })
- s->setSkewFactorFromMidPoint (0.5);
- cutoff.setSkewFactorFromMidPoint (1000.0);
- 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"),
- TR_NOOP ("Keytrack"), TR_NOOP ("Sweep"), TR_NOOP ("Sweep time"), TR_NOOP ("Low"), TR_NOOP ("Mid"), TR_NOOP ("High") };
- for (int i = 0; i < (int) labels.size(); ++i)
- {
- labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
- labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
- labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
- addAndMakeVisible (labels[(std::size_t) i]);
- }
- presetBox.setTextWhenNothingSelected (tr ("Presets..."));
- const auto presets = synthPresets();
- for (int i = 0; i < (int) presets.size(); ++i)
- presetBox.addItem (juce::String::fromUTF8 (presets[(std::size_t) i].first.c_str()), i + 1);
- presetBox.onChange = [this] {
- const auto presets = synthPresets();
- const auto index = presetBox.getSelectedId() - 1;
- if (juce::isPositiveAndBelow (index, (int) presets.size()) && current() != nullptr)
- ref.edit (engine, [s = presets[(std::size_t) index].second] (ChannelDef& channelDef) { channelDef.synth = s; });
- presetBox.setSelectedId (0, juce::dontSendNotification);
- };
- addAndMakeVisible (presetBox);
- flPresets.setButtonText (tr ("FL presets..."));
- flPresets.setTooltip (tr ("The 3x Osc channel presets that ship with FL Studio (Patches\\Channel presets\\3x Osc)"));
- flPresets.onClick = [this] { showFlPresets(); };
- addAndMakeVisible (flPresets);
- filterTypeBox.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
- filterTypeBox.setTooltip (tr ("Filter type"));
- filterTypeBox.onChange = [this] { apply(); };
- addAndMakeVisible (filterTypeBox);
- am.setButtonText ("AM");
- am.setTooltip (tr ("Osc 3 modulates the amplitude of osc 1 and 2 (like 3x Osc's AM); its level is the depth"));
- am.onClick = [this] { apply(); };
- addAndMakeVisible (am);
- knob (porta, 0.0, 2.0, 0.005, " t");
- porta.setSkewFactorFromMidPoint (0.25);
- porta.setTooltip (tr ("Portamento time, in beats (applies to the Porta button and to notes marked porta)"));
- portaOn.setButtonText ("Porta");
- portaOn.setTooltip (tr ("Portamento: the new note glides from the previous one (notes marked porta invert this)"));
- portaOn.onClick = [this] { apply(); };
- addAndMakeVisible (portaOn);
- mono.setButtonText ("Mono");
- mono.setTooltip (tr ("Single voice: the new note takes over the one currently sounding (basses and leads)"));
- mono.onClick = [this] { apply(); };
- addAndMakeVisible (mono);
- refresh();
- engine.addChangeListener (this);
- setSize (720, 510);
- }
- ~SynthPanel() override { engine.removeChangeListener (this); }
- int getChannel() const noexcept { return ref.index; }
- void paint (juce::Graphics& g) override // round 170j: the art's canvas behind the controls
- {
- const skin::StyleScope styleScope (skin::resolve (skin::Style::themed, skin::Art::lynxSynth), skin::Art::lynxSynth);
- skin::canvas (g, getLocalBounds().toFloat(), skin::artAccent (skin::Art::lynxSynth));
- }
- void resized() override
- {
- auto area = getLocalBounds().reduced (10);
- auto topRow = area.removeFromTop (24);
- presetBox.setBounds (topRow.removeFromLeft (200));
- mono.setBounds (topRow.removeFromLeft (90).withTrimmedLeft (16));
- am.setBounds (topRow.removeFromLeft (52));
- ring.setBounds (topRow.removeFromLeft (60));
- flPresets.setBounds (topRow.removeFromLeft (130).reduced (4, 0));
- portaOn.setBounds (topRow.removeFromLeft (70));
- filterTypeBox.setBounds (topRow.removeFromRight (140));
- area.removeFromTop (6);
- auto header = area.removeFromTop (16);
- header.removeFromLeft (150);
- for (int i = 0; i < oscKnobs; ++i)
- labels[(std::size_t) i].setBounds (header.removeFromLeft (88));
- for (auto& row : rows)
- {
- auto line = area.removeFromTop (64);
- row.title.setBounds (line.removeFromLeft (50).withSizeKeepingCentre (50, 24));
- row.wave.setBounds (line.removeFromLeft (100).withSizeKeepingCentre (96, 24));
- for (auto* s : { &row.octave, &row.semitones, &row.detune, &row.pan, &row.level })
- s->setBounds (line.removeFromLeft (88));
- }
- area.removeFromTop (10);
- auto names = area.removeFromTop (16);
- const auto w = area.getWidth() / 9;
- for (int i = oscKnobs; i < oscKnobs + 9; ++i)
- labels[(std::size_t) i].setBounds (names.removeFromLeft (w));
- auto knobsRow = area.removeFromTop (80);
- for (auto* s : { &attack, &decay, &sustain, &release, &cutoff, &resonance, &porta, &fm, &fmDecay })
- s->setBounds (knobsRow.removeFromLeft (w));
- area.removeFromTop (6);
- auto names2 = area.removeFromTop (16);
- for (int i = oscKnobs + 9; i < (int) labels.size(); ++i)
- labels[(std::size_t) i].setBounds (names2.removeFromLeft (w));
- auto knobsRow2 = area.removeFromTop (80);
- for (auto* s : { &keyTrack, &sweep, &sweepTime, &bandLow, &bandMid, &bandHigh })
- s->setBounds (knobsRow2.removeFromLeft (w));
- area.removeFromTop (12);
- modulationButton.setBounds (area.removeFromTop (26).withSizeKeepingCentre (260, 26));
- }
- private:
- struct Row
- {
- juce::Label title;
- juce::ComboBox wave;
- juce::Slider octave, semitones, detune, pan, level;
- };
- static constexpr int oscKnobs = 5; // oscillator knob labels come first
- juce::TextButton modulationButton;
- juce::ToggleButton mono, am, portaOn;
- juce::TextButton flPresets;
- // menu with the presets from the FL install for the synths LYNX converts: the 3x Osc channel .fst
- // files (by letter) and, per generator, the "Plugin presets" folders (Sytrus, Harmor, GMS...)
- void showFlPresets()
- {
- const auto roots = findFlStudioRoots();
- const auto patches = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches");
- auto sorted = [] (juce::Array<juce::File> files) {
- std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
- return a.getFileName().compareNatural (b.getFileName()) < 0;
- });
- return files;
- };
- juce::PopupMenu menu;
- // 3x Osc: ~170 presets grouped by first letter
- {
- juce::PopupMenu threeOsc, sub;
- juce::juce_wchar letter = 0;
- for (const auto& f : sorted (patches.getChildFile ("Channel presets/3x Osc").findChildFiles (juce::File::findFiles, false, "*.fst")))
- {
- const auto first = juce::CharacterFunctions::toUpperCase (f.getFileName()[0]);
- if (first != letter && sub.getNumItems() > 0)
- {
- threeOsc.addSubMenu (juce::String::charToString (letter), sub);
- sub = {};
- }
- letter = first;
- sub.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
- }
- if (sub.getNumItems() > 0)
- threeOsc.addSubMenu (juce::String::charToString (letter), sub);
- if (threeOsc.getNumItems() > 0)
- menu.addSubMenu ("3x Osc", threeOsc);
- }
- // a preset folder as a menu: subfolders become submenus
- std::function<juce::PopupMenu (const juce::File&, int)> folderMenu = [&] (const juce::File& folder, int depth) {
- juce::PopupMenu m;
- if (depth < 3)
- for (const auto& dir : sorted (folder.findChildFiles (juce::File::findDirectories, false)))
- if (auto sub = folderMenu (dir, depth + 1); sub.getNumItems() > 0)
- m.addSubMenu (dir.getFileName(), sub);
- for (const auto& f : sorted (folder.findChildFiles (juce::File::findFiles, false, "*.fst;*.gmsynth")))
- m.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
- return m;
- };
- const auto generators = patches.getChildFile ("Plugin presets/Generators");
- for (const auto* name : { "Sytrus", "Harmor", "GMS", "Harmless", "MiniSynth", "Fruity DX10", "Fruit Kick", "Ogun", "Sakura", "Kepler", "Kepler Exo",
- "PoiZone", "Toxic Biohazard", "BassDrum" })
- if (auto sub = folderMenu (generators.getChildFile (name), 0); sub.getNumItems() > 0)
- menu.addSubMenu (name, sub);
- if (menu.getNumItems() == 0)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("FL presets"),
- tr ("FL presets not found (install FL Studio or check the Data\\Patches folder)."));
- return;
- }
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&flPresets));
- }
- void loadFlPreset (const juce::File& file)
- {
- juce::MemoryBlock data;
- if (! file.loadFileAsData (data) || current() == nullptr)
- return;
- const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
- if (auto synth = synthFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize())))
- ref.edit (engine, [s = *synth] (ChannelDef& channelDef) { channelDef.synth = s; });
- else
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("FL presets"),
- tr ("This preset is not for a synth LYNX SHARE converts, or it could not be read."));
- }
- juce::Slider porta;
- juce::ComboBox filterTypeBox;
- void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
- {
- s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
- // round 170j: the plugin kit's knobs in LYNX Synth's own art ("the LYNX lab"), or the forced plugin style
- s.getProperties().set (skin::sliderProperty, (juce::int64) skin::artAccent (skin::Art::lynxSynth).getARGB());
- s.getProperties().set (skin::styleProperty, skin::packStyle (skin::Style::themed, skin::Art::lynxSynth));
- s.setRange (lo, hi, step);
- s.setTextValueSuffix (suffix);
- s.onValueChange = [this] { apply(); };
- addAndMakeVisible (s);
- }
- const ChannelDef* current() const
- {
- return ref.get (engine);
- }
- void refresh()
- {
- const auto* c = current();
- if (c == nullptr)
- return;
- updating = true;
- const auto& s = c->synth;
- for (std::size_t o = 0; o < 3; ++o)
- {
- rows[o].wave.setSelectedId ((int) s.osc[o].wave + 1, juce::dontSendNotification);
- rows[o].octave.setValue (s.osc[o].octave, juce::dontSendNotification);
- rows[o].detune.setValue (s.osc[o].detune, juce::dontSendNotification);
- rows[o].semitones.setValue (s.osc[o].semitones, juce::dontSendNotification);
- rows[o].pan.setValue (s.osc[o].pan, juce::dontSendNotification);
- rows[o].level.setValue (s.osc[o].level, juce::dontSendNotification);
- }
- attack.setValue (s.attack, juce::dontSendNotification);
- decay.setValue (s.decay, juce::dontSendNotification);
- sustain.setValue (s.sustain, juce::dontSendNotification);
- release.setValue (s.release, juce::dontSendNotification);
- cutoff.setValue (s.cutoff, juce::dontSendNotification);
- resonance.setValue (s.resonance, juce::dontSendNotification);
- mono.setToggleState (s.mono, juce::dontSendNotification);
- am.setToggleState (s.am, juce::dontSendNotification);
- porta.setValue (s.portaBeats, juce::dontSendNotification);
- portaOn.setToggleState (s.porta, juce::dontSendNotification);
- filterTypeBox.setSelectedId (s.filterType + 1, juce::dontSendNotification);
- fm.setValue (s.fm, juce::dontSendNotification);
- fmDecay.setValue (s.fmDecay, juce::dontSendNotification);
- keyTrack.setValue (s.keyTrack, juce::dontSendNotification);
- sweep.setValue (s.sweep, juce::dontSendNotification);
- sweepTime.setValue (s.sweepTime, juce::dontSendNotification);
- bandLow.setValue (s.bandGain[0], juce::dontSendNotification);
- bandMid.setValue (s.bandGain[1], juce::dontSendNotification);
- bandHigh.setValue (s.bandGain[2], juce::dontSendNotification);
- ring.setToggleState (s.ring, juce::dontSendNotification);
- updating = false;
- if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
- w->setName (tr ("Synth settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
- }
- void apply()
- {
- if (updating || current() == nullptr)
- return;
- auto s = current()->synth; // keeps what this window does not show (envelopes and LFOs)
- for (std::size_t o = 0; o < 3; ++o)
- s.osc[o] = { (Waveform) juce::jlimit (0, 5, rows[o].wave.getSelectedId() - 1), (int) rows[o].octave.getValue(),
- (float) rows[o].detune.getValue(), (float) rows[o].level.getValue(), (int) rows[o].semitones.getValue(),
- (float) rows[o].pan.getValue() };
- s.attack = (float) attack.getValue();
- s.decay = (float) decay.getValue();
- s.sustain = (float) sustain.getValue();
- s.release = (float) release.getValue();
- s.cutoff = (float) cutoff.getValue();
- s.resonance = (float) resonance.getValue();
- s.mono = mono.getToggleState();
- s.am = am.getToggleState();
- s.portaBeats = (float) porta.getValue();
- s.porta = portaOn.getToggleState();
- s.filterType = juce::jlimit (0, 3, filterTypeBox.getSelectedId() - 1);
- s.fm = (float) fm.getValue();
- s.fmDecay = (float) fmDecay.getValue();
- if (s.fmDecay <= 0.0f)
- s.fmSustain = 1.0f;
- s.keyTrack = (float) keyTrack.getValue();
- s.sweep = (float) sweep.getValue();
- s.sweepTime = (float) sweepTime.getValue();
- s.bandGain = { (float) bandLow.getValue(), (float) bandMid.getValue(), (float) bandHigh.getValue() };
- s.ring = ring.getToggleState();
- if (s == current()->synth)
- return;
- ref.edit (engine, [s] (ChannelDef& channelDef) { channelDef.synth = s; });
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override
- {
- if (current() == nullptr)
- {
- if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
- juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
- if (safe != nullptr)
- safe->closeButtonPressed();
- });
- return;
- }
- refresh();
- }
- AudioEngine& engine;
- ChannelRef ref;
- bool updating = false;
- std::array<Row, 3> rows;
- juce::Slider attack, decay, sustain, release, cutoff, resonance, fm, fmDecay, keyTrack, sweep, sweepTime, bandLow, bandMid, bandHigh;
- juce::ToggleButton ring;
- std::array<juce::Label, 20> labels;
- juce::ComboBox presetBox;
- };
- // --- FL's channel window frame (REA round 143b) --------------------------------------------------------------
- // FL 2026 draws every channel's settings window the same way: a header strip with the channel's tabs on the left
- // (the instrument / plugin page, the wrench "Miscellaneous functions" page) and ON, PAN, VOL and TRACK on the right
- // [EXEC: FL 2026 build 5654, "Detailed settings" of a generator and of a sampler]. LYNX does the same around its own
- // instrument pages, in its own style; the envelopes and LFOs of the synth and the sampler are the "Envelope /
- // instrument" tab instead of a second window.
- // A small rotary control with LYNX's control contract (drag, Ctrl = fine, wheel, Alt / middle-click / double-click
- // reset, right-click menu with automation items when the spec has a target); the hint bar shows its name and value.
- class FrameKnob final : public juce::Component,
- public ui::HintSource,
- private juce::Timer
- {
- public:
- FrameKnob (AudioEngine& e, std::function<ui::ValueSpec()> makeSpec, std::function<double()> get, std::function<void (double)> set,
- juce::String caption)
- : engine (e), specOf (std::move (makeSpec)), getter (std::move (get)), setter (std::move (set)), label (std::move (caption))
- {
- setRepaintsOnMouseActivity (true);
- if (specOf().target)
- startTimerHz (30); // follows its automation while the song plays (issue #12)
- }
- // the value drawn: the automation's while the song plays (pan / volume: the targets these knobs have), else the Song's
- double shownValue (const ui::ValueSpec& spec) const
- {
- if (spec.target && ! isMouseButtonDown())
- if (const auto v = engine.getAutomationDisplay().valueOf (*spec.target))
- return spec.target->kind == AutomationTargetKind::channelPan || spec.target->kind == AutomationTargetKind::mixerPan
- ? (double) *v * 2.0 - 1.0
- : (double) *v;
- return getter();
- }
- void timerCallback() override
- {
- if (! isShowing())
- return;
- if (const auto generation = engine.getAutomationDisplay().getGeneration(); generation != shownGeneration)
- {
- shownGeneration = generation;
- repaint();
- }
- }
- std::uint32_t shownGeneration = 0;
- ui::Hint hintAt (juce::Point<int>) override
- {
- return ui::valueHint (specOf(), getter(), doubleClicked ? tr ("[LMB] drag or [Wheel] changes [2xLMB] show in the Mixer [RMB] menu")
- : ui::valueGestures());
- }
- // FL's number wheel (round 168s, issue #32): the value in a box over the caption instead of a knob; the whole
- // control is the hit area, a notch / 7.5 px of drag = one step (ui::digitWheel). Double-click: `doubleClicked`.
- bool digitBox = false;
- std::function<void()> doubleClicked;
- std::function<void (juce::PopupMenu&)> extraMenuItems;
- void paint (juce::Graphics& g) override
- {
- const auto spec = specOf();
- auto area = getLocalBounds().toFloat();
- const auto caption = area.removeFromBottom (13.0f);
- if (digitBox)
- {
- // FL's digiwheel (c_f14): a display about 22 px high, the value right-aligned before up / down marks; here dark,
- // red only while touched
- const auto box = area.withSizeKeepingCentre (juce::jmin (area.getWidth() - 2.0f, 48.0f), juce::jmin (22.0f, area.getHeight() - 4.0f));
- g.setColour (theme::drawDigitDisplay (g, box, isMouseOverOrDragging() || drag.isActive(), false, true));
- g.setFont (theme::font (13.0f, true));
- g.drawFittedText (spec.text (getter()), box.withTrimmedRight (theme::digitMarksWidth).reduced (3.0f, 0.0f).toNearestInt(),
- juce::Justification::centredRight, 1, 0.6f);
- g.setColour (theme::colour::textSecondary);
- g.setFont (theme::font (theme::type::caption));
- g.drawFittedText (theme::caps (label), caption.toNearestInt(), juce::Justification::centred, 1, 0.65f);
- return;
- }
- const auto valueArea = area.removeFromBottom (13.0f);
- const auto size = juce::jmin (area.getWidth(), area.getHeight());
- const auto shown = shownValue (spec);
- const auto v = (float) juce::jlimit (0.0, 1.0, (shown - spec.minimum) / juce::jmax (1e-9, spec.maximum - spec.minimum));
- theme::drawKnob (g, juce::Rectangle<float> (size, size).withCentre (area.getCentre()), v, spec.minimum < 0.0,
- isMouseOverOrDragging() ? theme::colour::accent : theme::colour::knobArc, isMouseOver());
- g.setFont (theme::font (theme::type::caption));
- g.setColour (theme::colour::textPrimary);
- // squeezed (down to 65 %) before an ellipsis: translated captions are often longer (round 165o)
- g.drawFittedText (spec.text (shown), valueArea.toNearestInt(), juce::Justification::centred, 1, 0.65f);
- g.setColour (theme::colour::textSecondary);
- g.drawFittedText (theme::caps (label), caption.toNearestInt(), juce::Justification::centred, 1, 0.65f);
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- if (e.mods.isPopupMenu())
- {
- if (! extraMenuItems)
- {
- ui::showValueMenu (*this, &engine, specOf(), getter(), setter);
- return;
- }
- const auto spec = specOf();
- juce::PopupMenu menu;
- menu.addSectionHeader (spec.name + ": " + spec.text (getter()));
- ui::addValueItems (menu, *this, &engine, spec, getter(), setter);
- menu.addSeparator();
- extraMenuItems (menu);
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- return;
- }
- if (ui::isResetClick (e))
- {
- setter (specOf().defaultValue);
- repaint();
- return;
- }
- drag.begin (e, getter());
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (! drag.isActive())
- return;
- const auto spec = specOf();
- setter (drag.update (e, spec));
- ui::showValueTip (*this, getLocalBounds(), spec.text (getter()));
- repaint();
- }
- void mouseUp (const juce::MouseEvent&) override
- {
- drag.end();
- ui::hideValueTip();
- }
- void mouseDoubleClick (const juce::MouseEvent&) override
- {
- if (doubleClicked)
- {
- doubleClicked();
- return;
- }
- setter (specOf().defaultValue);
- repaint();
- }
- void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
- {
- if (const auto v = ui::wheelValue (getter(), e, wheel, specOf()))
- {
- setter (*v);
- ui::flashValueTip (*this, getLocalBounds(), specOf().text (getter()));
- repaint();
- }
- }
- private:
- AudioEngine& engine;
- std::function<ui::ValueSpec()> specOf;
- std::function<double()> getter;
- std::function<void (double)> setter;
- juce::String label;
- ui::ValueDrag drag;
- };
- juce::String channelNameOf (const Song& song, int channel)
- {
- if (channel < 0 || channel >= (int) song.channels.size())
- return "?";
- const auto& n = song.channels[(std::size_t) channel].name;
- return n.empty() ? tr ("Channel {0}", { juce::String (channel + 1) }) : juce::String::fromUTF8 (n.c_str());
- }
- // An integer spec shown as a number, 0 as "--" (FL's empty number boxes).
- ui::ValueSpec countSpec (const juce::String& name, int maximum, int defaultValue, std::function<juce::String (int)> text = {})
- {
- ui::ValueSpec spec;
- spec.name = name;
- spec.maximum = maximum;
- spec.defaultValue = defaultValue;
- spec.interval = 1.0;
- spec.pixelsForRange = juce::jlimit (60.0, 400.0, 5.0 * maximum);
- spec.toText = [text] (double v) {
- const auto i = juce::roundToInt (v);
- if (text)
- return text (i);
- return i == 0 ? juce::String ("--") : juce::String (i);
- };
- spec.fromText = [] (const juce::String& t) -> std::optional<double> {
- const auto digits = t.retainCharacters ("0123456789");
- return digits.isEmpty() ? std::optional<double> (0.0) : std::optional<double> (digits.getDoubleValue());
- };
- return spec;
- }
- // The wrench tab: FL's "Miscellaneous functions" with what LYNX's channels have (Levels, Polyphony, Time, Group,
- // Arpeggiator).
- // FL's Root note keyboard (Misc tab, REA round 149): every key 0…127 (C0…G10, C5 = 60), the channel's root marked;
- // a click sets it. LYNX's own drawing.
- class RootKeyboard final : public juce::Component, public juce::SettableTooltipClient
- {
- public:
- std::function<void (int)> onPick;
- // FL's key region ruler (round 164): a drag on the strip above the keys sets the notes the channel plays,
- // a double-click there gives it the whole keyboard back
- std::function<void (int, int)> onRegion;
- void setRoot (int key)
- {
- root = key;
- repaint();
- }
- void setRegion (int low, int high)
- {
- if (low != regionLow || high != regionHigh)
- {
- regionLow = low;
- regionHigh = high;
- repaint();
- }
- }
- void paint (juce::Graphics& g) override
- {
- using namespace theme;
- const auto w = whiteWidth();
- const auto top = (float) rulerHeight();
- const auto keysH = (float) getHeight() - top;
- if (onRegion)
- {
- const auto ruler = juce::Rectangle<float> (0.0f, 0.0f, (float) getWidth(), top - 2.0f);
- g.setColour (colour::bg0);
- g.fillRect (ruler);
- const auto full = regionLow <= 0 && regionHigh >= 127;
- const auto x0 = keyLeft (regionLow), x1 = keyRight (regionHigh);
- g.setColour (full ? colour::bg5 : colour::accent);
- g.fillRect (juce::Rectangle<float> (x0, 1.0f, juce::jmax (2.0f, x1 - x0), ruler.getHeight() - 2.0f));
- }
- for (int k = 0, white = 0; k < 128; ++k)
- if (! isBlack (k))
- {
- const auto r = juce::Rectangle<float> ((float) (white++) * w, top, w - 1.0f, keysH);
- const auto outside = onRegion && (k < regionLow || k > regionHigh);
- g.setColour (k == root ? colour::accent : k == hover ? juce::Colour (0xffc8ccd4) : outside ? juce::Colour (0xff9a9ea8) : juce::Colour (0xffe6e8ec));
- g.fillRect (r);
- if (k % 12 == 0 && w * 7.0f >= 14.0f) // the octave's C named (FL's C5 = 60)
- {
- g.setColour (k == root ? colour::onAccent : juce::Colour (0xff5a5f6a));
- g.setFont (font (8.5f));
- g.drawText ("C" + juce::String (k / 12), r.withTrimmedTop (r.getHeight() - 11.0f).expanded (6.0f, 0.0f).toNearestInt(),
- juce::Justification::centred);
- }
- }
- for (int k = 0; k < 128; ++k)
- if (isBlack (k))
- {
- const auto x = (float) whitesBefore (k) * w - w * 0.32f;
- g.setColour (k == root ? colour::accent : k == hover ? colour::bg5 : colour::bg0);
- g.fillRect (juce::Rectangle<float> (x, top, w * 0.64f, keysH * 0.6f));
- }
- }
- void mouseMove (const juce::MouseEvent& e) override
- {
- const auto onRuler = onRegion && e.position.y < (float) rulerHeight();
- if (const auto k = keyAt (e.position); k != hover || onRuler != hoverRuler)
- {
- hover = k;
- hoverRuler = onRuler;
- if (onRuler)
- setTooltip (tr ("Key region: {0} to {1} (drag to set, double-click for the whole keyboard)",
- { keyName (regionLow), keyName (regionHigh) }));
- else
- setTooltip (k >= 0 ? tr ("Root note: {0}", { keyName (k) }) : juce::String());
- repaint();
- }
- }
- void mouseExit (const juce::MouseEvent&) override
- {
- hover = -1;
- repaint();
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- dragFrom = -1;
- if (onRegion && e.position.y < (float) rulerHeight())
- {
- dragFrom = keyAtX (e.position.x);
- if (dragFrom >= 0)
- onRegion (dragFrom, dragFrom);
- return;
- }
- if (const auto k = keyAt (e.position); k >= 0 && onPick)
- onPick (k);
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (dragFrom < 0 || ! onRegion)
- return;
- const auto k = keyAtX (e.position.x);
- if (k >= 0)
- onRegion (juce::jmin (dragFrom, k), juce::jmax (dragFrom, k));
- }
- void mouseDoubleClick (const juce::MouseEvent& e) override
- {
- if (onRegion && e.position.y < (float) rulerHeight())
- onRegion (0, 127);
- }
- static juce::String keyName (int key)
- {
- return juce::String (notenames::keyName (key)); // Settings › General › Note names (round 165f)
- }
- private:
- static bool isBlack (int k) noexcept
- {
- const auto n = k % 12;
- return n == 1 || n == 3 || n == 6 || n == 8 || n == 10;
- }
- static int whitesBefore (int k) noexcept
- {
- int count = 0;
- for (int i = 0; i < k; ++i)
- count += isBlack (i) ? 0 : 1;
- return count;
- }
- int rulerHeight() const noexcept { return onRegion ? 9 : 0; }
- float whiteWidth() const noexcept { return (float) getWidth() / 75.0f; } // 75 white keys in 0…127
- float keyLeft (int k) const noexcept
- {
- const auto w = whiteWidth();
- return isBlack (k) ? (float) whitesBefore (k) * w - w * 0.32f : (float) whitesBefore (k) * w;
- }
- float keyRight (int k) const noexcept
- {
- const auto w = whiteWidth();
- return isBlack (k) ? keyLeft (k) + w * 0.64f : keyLeft (k) + w;
- }
- // the key under x on the ruler (each key owns its own horizontal span; black keys win where they overlap)
- int keyAtX (float x) const noexcept
- {
- for (int k = 0; k < 128; ++k)
- if (isBlack (k) && x >= keyLeft (k) && x < keyRight (k))
- return k;
- const auto white = (int) std::floor (x / whiteWidth());
- for (int k = 0, n = 0; k < 128; ++k)
- if (! isBlack (k) && n++ == white)
- return k;
- return x < 0.0f ? 0 : 127;
- }
- int keyAt (juce::Point<float> p) const noexcept
- {
- const auto w = whiteWidth();
- const auto top = (float) rulerHeight();
- if (p.y < top)
- return keyAtX (p.x);
- if (p.y < top + ((float) getHeight() - top) * 0.6f)
- for (int k = 0; k < 128; ++k)
- if (isBlack (k))
- {
- const auto x = (float) whitesBefore (k) * w - w * 0.32f;
- if (p.x >= x && p.x < x + w * 0.64f)
- return k;
- }
- const auto white = (int) std::floor (p.x / w);
- for (int k = 0, n = 0; k < 128; ++k)
- if (! isBlack (k) && n++ == white)
- return k;
- return -1;
- }
- int root = 60, hover = -1, dragFrom = -1;
- int regionLow = 0, regionHigh = 127;
- bool hoverRuler = false;
- };
- class MiscPanel final : public juce::Component,
- private juce::ChangeListener
- {
- public:
- static constexpr int preferredWidth = 800, preferredHeight = 360;
- MiscPanel (AudioEngine& e, int c) : engine (e), channel (c)
- {
- const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
- auto knob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get,
- std::function<void (ChannelDef&, double)> set, const char* caption) {
- auto k = std::make_unique<FrameKnob> (
- engine, std::move (spec), [this, get] { return current() != nullptr ? get (*current()) : 0.0; },
- [this, set] (double v) {
- if (current() == nullptr)
- return;
- engine.editSong ([ch = channel, set, v] (Song& s) {
- if (ch < (int) s.channels.size())
- set (s.channels[(std::size_t) ch], v);
- });
- },
- tr (caption));
- addAndMakeVisible (*k);
- knobs.push_back (std::move (k));
- return knobs.back().get();
- };
- // Levels adjustment
- pan = knob ([this, name] {
- auto s = ui::panSpec (name() + " - " + tr ("Pan"));
- s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.pan; }, [] (ChannelDef& d, double v) { d.pan = (float) v; }, TR_NOOP ("Pan"));
- volume = knob ([this, name] {
- auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
- s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.volume; }, [] (ChannelDef& d, double v) { d.volume = (float) v; },
- TR_NOOP ("Vol"));
- // Polyphony
- maxPoly = knob ([name] { return countSpec (name() + " - " + tr ("Maximum polyphony (-- = no limit)"), 64, 0); },
- [] (const ChannelDef& d) { return (double) d.maxPolyphony; },
- [] (ChannelDef& d, double v) { d.maxPolyphony = juce::jlimit (0, 64, juce::roundToInt (v)); }, TR_NOOP ("Max"));
- slide = knob (
- [name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Portamento time");
- s.maximum = 2.0;
- s.defaultValue = 0.125;
- s.toText = [] (double v) { return tr ("{0} beats", { juce::String (v, 3) }); };
- s.fromText = [] (const juce::String& t) -> std::optional<double> { return t.retainCharacters ("0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
- return s;
- },
- [] (const ChannelDef& d) { return (double) channelPortamentoBeats (d); },
- [] (ChannelDef& d, double v) { setChannelPortamento (d, channelPortamento (d), (float) v); }, TR_NOOP ("Slide"));
- porta.setButtonText (tr ("Porta"));
- porta.setTooltip (tr ("Portamento: each note glides from the previous one's pitch (the Slide knob sets the time)"));
- porta.onClick = [this] { edit ([on = porta.getToggleState()] (ChannelDef& d) { setChannelPortamento (d, on, channelPortamentoBeats (d)); }); };
- mono.setButtonText (tr ("Mono"));
- mono.setTooltip (tr ("Mono: one voice; a note played over a held one glides to it (Slide time) without a new attack"));
- mono.onClick = [this] { edit ([on = mono.getToggleState()] (ChannelDef& d) { setChannelMono (d, on); }); };
- // Time
- swing = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Swing mix"), 1.0); },
- [] (const ChannelDef& d) { return (double) d.swingMix; }, [] (ChannelDef& d, double v) { d.swingMix = (float) v; },
- TR_NOOP ("Swing"));
- // Levels adjustment: Mod X / Mod Y = the channel filter's cutoff / resonance (sampler, synth)
- modX = knob ([name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Mod X (filter cutoff)");
- s.defaultValue = 1.0;
- 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"; };
- return s;
- },
- [] (const ChannelDef& d) {
- const auto hz = d.instrument == InstrumentKind::synth ? d.synth.cutoff : d.sampler.cutoff;
- return juce::jlimit (0.0, 1.0, std::log ((double) hz / 20.0) / std::log (1000.0));
- },
- [] (ChannelDef& d, double v) {
- const auto hz = (float) (20.0 * std::pow (1000.0, v));
- if (d.instrument == InstrumentKind::synth)
- d.synth.cutoff = hz;
- else if (d.instrument == InstrumentKind::sampler)
- {
- d.sampler.cutoff = hz;
- d.sampler.flChannel.clear(); // an edited filter replaces FL's whole sampler voice (REA_rodada76)
- }
- },
- TR_NOOP ("Mod X"));
- modY = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Mod Y (filter resonance)"), 0.0); },
- [] (const ChannelDef& d) { return (double) (d.instrument == InstrumentKind::synth ? d.synth.resonance : d.sampler.resonance); },
- [] (ChannelDef& d, double v) {
- if (d.instrument == InstrumentKind::synth)
- d.synth.resonance = (float) v;
- else if (d.instrument == InstrumentKind::sampler)
- {
- d.sampler.resonance = (float) v;
- d.sampler.flChannel.clear();
- }
- },
- TR_NOOP ("Mod Y"));
- // Time: Gate and Shift on FL's time-knob scale (REA round 146b)
- auto timeSpec = [name] (const char* what, int maximum, int defaultValue, bool offAtMax) {
- ui::ValueSpec s;
- s.name = name() + " - " + tr (what);
- s.maximum = maximum;
- s.defaultValue = defaultValue;
- s.interval = 1.0;
- s.pixelsForRange = 300.0;
- s.toText = [maximum, offAtMax] (double v) {
- const auto i = juce::roundToInt (v);
- if (offAtMax && i >= maximum)
- return tr ("Off");
- // steps:ticks, as FL shows them (24 ticks per step)
- const auto ticks = juce::roundToInt (channelmisc::flTimeKnobBeats (i) * 96.0);
- return juce::String (ticks / 24) + ":" + juce::String (ticks % 24).paddedLeft ('0', 2);
- };
- return s;
- };
- timeGate = knob ([timeSpec] { return timeSpec (TR_NOOP ("Gate: long notes are cut to this length (Off = no limit)"), 1446, 1446, true); },
- [] (const ChannelDef& d) { return d.misc.gateBeats > 0.0f ? (double) channelmisc::flTimeKnobValue (d.misc.gateBeats) : 1446.0; },
- [] (ChannelDef& d, double v) {
- const auto i = juce::roundToInt (v);
- d.misc.gateBeats = i >= 1446 ? 0.0f : (float) std::max (1.0 / 96.0, channelmisc::flTimeKnobBeats (i));
- },
- TR_NOOP ("Gate"));
- timeShift = knob ([timeSpec] { return timeSpec (TR_NOOP ("Fine time shift: delays the notes, up to one step"), 1024, 0, false); },
- [] (const ChannelDef& d) { return (double) channelmisc::flTimeKnobValue (d.misc.shiftBeats); },
- [] (ChannelDef& d, double v) { d.misc.shiftBeats = (float) channelmisc::flTimeKnobBeats (juce::roundToInt (v)); },
- TR_NOOP ("Shift"));
- fullPorta.setButtonText (tr ("Full porta"));
- fullPorta.setTooltip (tr ("Full porta: portamento notes ignore the Gate and play their whole length"));
- fullPorta.onClick = [this] { edit ([on = fullPorta.getToggleState()] (ChannelDef& d) { d.misc.fullPorta = on; }); };
- // Vol / Key tracking
- trackVol.setButtonText (tr ("Vol"));
- trackKey.setButtonText (trc ("@key tracking: Key"));
- for (auto* b : { &trackVol, &trackKey })
- {
- b->setClickingTogglesState (true);
- b->setRadioGroupId (146);
- b->onClick = [this] { repaint(); for (auto& k : knobs) k->repaint(); };
- addAndMakeVisible (b);
- }
- trackVol.setTooltip (tr ("Velocity tracking: the note's velocity moves its pan"));
- trackKey.setTooltip (tr ("Keyboard tracking: the note's key moves its pan"));
- trackKey.setToggleState (true, juce::dontSendNotification);
- auto tracking = [this] (ChannelDef& d) -> NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
- auto trackingOf = [this] (const ChannelDef& d) -> const NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
- trackPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: pan")); },
- [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).pan; },
- [tracking] (ChannelDef& d, double v) { tracking (d).pan = (float) v; }, TR_NOOP ("Pan"));
- trackMid = knob ([this, name] {
- const auto key = trackKey.getToggleState();
- auto s = countSpec (name() + " - " + tr ("Tracking: the middle value (no offset)"), key ? 131 : 128, key ? 60 : 100,
- [key] (int v) { return key ? juce::MidiMessage::getMidiNoteName (120 - v, true, true, 5) : juce::String (v); }); // FL: C5 = 60
- return s;
- },
- [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).mid; },
- [tracking] (ChannelDef& d, double v) { tracking (d).mid = juce::roundToInt (v); }, TR_NOOP ("Mid"));
- // FL's tracking Mod X / Y (round 151): the notes' Mod X / Y follow the velocity / key like their pan
- trackModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod X (the note's filter cutoff / a plugin's MOD X)")); },
- [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modX; },
- [tracking] (ChannelDef& d, double v) { tracking (d).modX = (float) v; }, TR_NOOP ("Mod X"));
- trackModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod Y (the note's filter resonance)")); },
- [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modY; },
- [tracking] (ChannelDef& d, double v) { tracking (d).modY = (float) v; }, TR_NOOP ("Mod Y"));
- // Echo delay / fat mode
- echoFeed = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Delay feedback (100% = the echoes as loud as the note)"), 0.0); },
- [] (const ChannelDef& d) { return (double) d.misc.echo.feedback / 2.0; },
- [] (ChannelDef& d, double v) { d.misc.echo.feedback = (float) (2.0 * v); }, TR_NOOP ("Feed"));
- echoPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay pan: each echo moves this much")); },
- [] (const ChannelDef& d) { return (double) d.misc.echo.pan; }, [] (ChannelDef& d, double v) { d.misc.echo.pan = (float) v; },
- TR_NOOP ("Pan"));
- echoModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod X: each echo moves the note's Mod X this much")); },
- [] (const ChannelDef& d) { return (double) d.misc.echo.modX; }, [] (ChannelDef& d, double v) { d.misc.echo.modX = (float) v; },
- TR_NOOP ("Mod X"));
- echoModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod Y: each echo moves the note's Mod Y this much")); },
- [] (const ChannelDef& d) { return (double) d.misc.echo.modY; }, [] (ChannelDef& d, double v) { d.misc.echo.modY = (float) v; },
- TR_NOOP ("Mod Y"));
- echoPitch = knob ([name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Delay pitch: each echo moves this many cents");
- s.minimum = -1200.0;
- s.maximum = 1200.0;
- s.interval = 1.0;
- s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v)) }); };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.misc.echo.pitch; }, [] (ChannelDef& d, double v) { d.misc.echo.pitch = (float) v; },
- TR_NOOP ("Pitch"));
- echoTime = knob ([name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Delay time (steps:ticks)");
- s.minimum = 1.0;
- s.maximum = 192.0 * 4.0;
- s.defaultValue = 144.0;
- s.interval = 1.0;
- s.pixelsForRange = 400.0;
- s.toText = [] (double v) { const auto t = juce::roundToInt (v); return juce::String (t / 48) + ":" + juce::String ((t % 48) / 2).paddedLeft ('0', 2); };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.misc.echo.timeBeats * 192.0; },
- [] (ChannelDef& d, double v) { d.misc.echo.timeBeats = (float) (juce::roundToInt (v) / 192.0); }, TR_NOOP ("Time"));
- echoCount = knob ([name] { return countSpec (name() + " - " + tr ("Delay number of echoes"), 10, 4); },
- [] (const ChannelDef& d) { return (double) d.misc.echo.echoes; },
- [] (ChannelDef& d, double v) { d.misc.echo.echoes = juce::jlimit (1, 10, juce::roundToInt (v)); }, TR_NOOP ("Echoes"));
- pingPong.setButtonText (tr ("Ping pong"));
- pingPong.setTooltip (tr ("Ping pong: the echoes' pan bounces off the left and right ends"));
- pingPong.onClick = [this] { edit ([on = pingPong.getToggleState()] (ChannelDef& d) { d.misc.echo.pingPong = on; }); };
- fatMode.setButtonText (tr ("Fat mode"));
- fatMode.setTooltip (tr ("Fat mode: a second, mirrored series of echoes (opposite pan and pitch steps), all at the feedback level"));
- fatMode.onClick = [this] { edit ([on = fatMode.getToggleState()] (ChannelDef& d) { d.misc.echo.fat = on; }); };
- // Root note row: main pitch
- mainPitch.setButtonText (tr ("Enable main pitch"));
- mainPitch.setTooltip (tr ("The channel follows the main pitch (the toolbar's master pitch)"));
- mainPitch.onClick = [this] { edit ([on = mainPitch.getToggleState()] (ChannelDef& d) { d.misc.mainPitch = on; }); };
- // FL's Add to key and Root note keyboard (round 149): a sampler's root moves its pitch, other instruments are
- // transposed by (C5 − root) with Add to key
- addToKey.setButtonText (tr ("Add to key"));
- addToKey.setTooltip (tr ("Add to key: the notes are played the root note's distance from C5 away (instruments that are not samplers)"));
- addToKey.onClick = [this] { edit ([on = addToKey.getToggleState()] (ChannelDef& d) { d.misc.addToKey = on; }); };
- // FL's Root note › Fine tune (round 151 [DATA: .flp event 0x8E, cents]): every note of the channel this many
- // cents away
- fineTune = knob ([name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Fine tuning");
- s.minimum = -100.0;
- s.maximum = 100.0;
- s.interval = 1.0;
- s.toText = [] (double v) { return tr ("{0} cents", { (v > 0.0 ? "+" : "") + juce::String (juce::roundToInt (v)) }); };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.misc.fineTune; }, [] (ChannelDef& d, double v) { d.misc.fineTune = (float) v; },
- TR_NOOP ("Fine tune"));
- rootReset.setButtonText (tr ("Reset"));
- rootReset.setTooltip (tr ("Reset the root note to C5"));
- rootReset.onClick = [this] { if (rootKeys.onPick) rootKeys.onPick (60); };
- addAndMakeVisible (rootReset);
- rootKeys.onPick = [this] (int key) {
- edit ([key] (ChannelDef& d) {
- if (d.instrument == InstrumentKind::sampler)
- {
- // the sample plays at its own pitch on the root: the pitch moves by the root's change (within ±24)
- const auto pitch = std::clamp (d.sampler.pitch + (float) (d.misc.rootNote - key), -24.0f, 24.0f);
- const auto moved = (int) std::lround (pitch - d.sampler.pitch);
- d.sampler.pitch = pitch;
- d.misc.rootNote = std::clamp (d.misc.rootNote - moved, 0, 127);
- }
- else
- d.misc.rootNote = key;
- });
- };
- rootKeys.onRegion = [this] (int low, int high) {
- edit ([low, high] (ChannelDef& d) {
- d.keyLow = juce::jlimit (0, 127, low);
- d.keyHigh = juce::jlimit (d.keyLow, 127, high);
- });
- };
- addAndMakeVisible (addToKey);
- addAndMakeVisible (rootKeys);
- // Arpeggiator: FL's Slide and Chord
- arpSlide.setButtonText (tr ("Slide"));
- arpSlide.setTooltip (tr ("Slide: the arpeggio glides from note to note (instruments that slide)"));
- arpSlide.onClick = [this] { edit ([on = arpSlide.getToggleState()] (ChannelDef& d) { d.arp.slide = on; }); };
- arpChord.addItem (tr ("Auto (sustain)"), 1);
- arpChord.addItem (tr ("None (octaves)"), 2);
- for (const auto& [chordName, intervals] : arpChords())
- arpChord.addItem (tr (chordName), arpChord.getNumItems() + 1);
- arpChord.setTooltip (tr ("Chord: Auto plays the held notes; a chord plays it on the lowest held note"));
- arpChord.onChange = [this] {
- const auto id = arpChord.getSelectedId();
- if (id <= 0)
- return;
- edit ([id] (ChannelDef& d) {
- if (id == 1)
- d.arp.chord.clear();
- else if (id == 2)
- d.arp.chord = { 0 };
- else if (id - 3 < (int) arpChords().size())
- d.arp.chord = arpChords()[(std::size_t) (id - 3)].second;
- });
- };
- for (auto* b : { &fullPorta, &pingPong, &fatMode, &mainPitch, &arpSlide })
- addAndMakeVisible (b);
- addAndMakeVisible (arpChord);
- // Group
- cut = knob ([this, name] { return countSpec (name() + " - " + tr ("Cut: notes of this channel stop the channels cut by this group"),
- juce::jmax (99, current() != nullptr ? current()->cutGroup : 0), 0,
- [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
- [] (const ChannelDef& d) { return (double) d.cutGroup; }, [] (ChannelDef& d, double v) { d.cutGroup = juce::jmax (0, juce::roundToInt (v)); },
- TR_NOOP ("Cut group"));
- cutBy = knob ([this, name] { return countSpec (name() + " - " + tr ("By: this channel is cut by the channels of this group"),
- juce::jmax (99, current() != nullptr ? current()->cutBy : 0), 0,
- [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
- [] (const ChannelDef& d) { return (double) d.cutBy; }, [] (ChannelDef& d, double v) { d.cutBy = juce::jmax (0, juce::roundToInt (v)); },
- TR_NOOP ("Cut by"));
- cutSelf.setButtonText (tr ("Cut self"));
- cutSelf.setClickingTogglesState (true);
- cutSelf.setTooltip (tr ("Cut self: a new note of this channel stops its own sounding note (hi-hats, 808s)"));
- cutSelf.onClick = [this] { edit ([on = cutSelf.getToggleState(), ch = channel] (ChannelDef& d) { setChannelCutsItself (d, ch, on); }); };
- // Arpeggiator
- arpDirection.addItemList ({ tr ("Off"), tr ("Up"), tr ("Down"), tr ("Up and down"), tr ("Random"), tr ("Up and down (sticky)") }, 1);
- arpDirection.setTooltip (tr ("Arpeggiator direction (Off = the notes play as written)"));
- arpDirection.onChange = [this] { edit ([d = arpDirection.getSelectedId() - 1] (ChannelDef& c) { c.arp.direction = juce::jlimit (0, 5, d); }); };
- for (const auto& [text, beats] : arpSpeeds())
- arpTime.addItem (tr (text), arpTime.getNumItems() + 1);
- arpTime.setTooltip (tr ("Arpeggiator time: the length of each step"));
- arpTime.onChange = [this] {
- const auto i = arpTime.getSelectedId() - 1;
- if (i >= 0 && i < (int) arpSpeeds().size())
- edit ([b = arpSpeeds()[(std::size_t) i].second] (ChannelDef& c) { c.arp.stepBeats = b; });
- };
- arpRange = knob ([name] { return countSpec (name() + " - " + tr ("Arpeggiator range (octaves)"), 4, 1); },
- [] (const ChannelDef& d) { return (double) d.arp.range; },
- [] (ChannelDef& d, double v) { d.arp.range = juce::jlimit (1, 4, juce::roundToInt (v)); }, TR_NOOP ("Range"));
- arpGate = knob ([name] {
- auto s = ui::percentSpec (name() + " - " + tr ("Arpeggio gate (past 100% the next note waits)"), 0.5);
- s.minimum = 0.05;
- s.maximum = 128.0 / 48.0;
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.arp.gate; },
- [] (ChannelDef& d, double v) { d.arp.gate = juce::jlimit (0.05f, 128.0f / 48.0f, (float) v); }, TR_NOOP ("Gate"));
- // FL's Repeat 0 plays the whole chord at once on each step (round 149)
- 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,
- [] (int i) { return i == 0 ? tr ("Chord") : juce::String (i); }); },
- [] (const ChannelDef& d) { return (double) d.arp.octaveRepeat; },
- [] (ChannelDef& d, double v) { d.arp.octaveRepeat = juce::jlimit (0, 16, juce::roundToInt (v)); }, TR_NOOP ("Repeat"));
- for (auto* b : { &porta, &mono })
- addAndMakeVisible (b);
- addAndMakeVisible (cutSelf);
- addAndMakeVisible (arpDirection);
- addAndMakeVisible (arpTime);
- refresh();
- engine.addChangeListener (this);
- setSize (preferredWidth, preferredHeight);
- }
- ~MiscPanel() override { engine.removeChangeListener (this); }
- void paint (juce::Graphics& g) override
- {
- g.fillAll (theme::colour::bg2);
- for (const auto& [area, title] : sections)
- {
- g.setColour (theme::colour::bg3);
- g.fillRoundedRectangle (area.toFloat(), 4.0f);
- g.setColour (theme::colour::textSecondary);
- g.setFont (theme::font (theme::type::caption, true));
- auto text = theme::caps (title);
- if (&title == §ions[(std::size_t) juce::jmax (0, rootSection)].second && rootSection >= 0 && current() != nullptr)
- text << ": " << RootKeyboard::keyName (current()->misc.rootNote); // FL's "Root note: C5"
- g.drawText (text, area.withHeight (20).reduced (8, 0), juce::Justification::centredLeft);
- }
- }
- void resized() override
- {
- sections.clear();
- auto area = getLocalBounds().reduced (8);
- auto section = [this] (juce::Rectangle<int> r, const juce::String& title) {
- sections.push_back ({ r, title });
- return r.withTrimmedTop (20).reduced (6, 4);
- };
- constexpr int knobW = 50, knobH = 64;
- auto row = [] (juce::Rectangle<int>& r, std::initializer_list<FrameKnob*> ks) {
- auto line = r.removeFromTop (knobH);
- for (auto* k : ks)
- k->setBounds (line.removeFromLeft (knobW));
- };
- auto top = area.removeFromTop (118);
- {
- auto levels = section (top.removeFromLeft (4 * knobW + 12), tr ("Levels adjustment"));
- row (levels, { pan, volume, modX, modY });
- }
- top.removeFromLeft (6);
- {
- auto poly = section (top.removeFromLeft (2 * knobW + 30), tr ("Polyphony"));
- row (poly, { maxPoly, slide });
- auto toggles = poly.removeFromTop (22);
- porta.setBounds (toggles.removeFromLeft (64));
- mono.setBounds (toggles);
- }
- top.removeFromLeft (6);
- {
- auto time = section (top.removeFromLeft (3 * knobW + 12), tr ("Time"));
- row (time, { timeGate, timeShift, swing });
- fullPorta.setBounds (time.removeFromTop (22));
- }
- top.removeFromLeft (6);
- {
- auto track = section (top, tr ("Tracking"));
- auto tabs = track.removeFromTop (0);
- juce::ignoreUnused (tabs);
- const auto title = sections.back().first;
- trackVol.setBounds (title.getRight() - 84, title.getY() + 2, 38, 16);
- trackKey.setBounds (title.getRight() - 44, title.getY() + 2, 38, 16);
- row (track, { trackPan, trackModX, trackModY, trackMid });
- }
- area.removeFromTop (6);
- auto bottom = area.removeFromTop (130);
- {
- auto group = section (bottom.removeFromLeft (2 * knobW + 16), tr ("Group"));
- row (group, { cut, cutBy });
- cutSelf.setBounds (group.removeFromTop (24).reduced (4, 0));
- }
- bottom.removeFromLeft (6);
- {
- auto arp = section (bottom.removeFromLeft (330), tr ("Arpeggiator"));
- auto boxes = arp.removeFromLeft (118);
- arpDirection.setBounds (boxes.removeFromTop (22));
- boxes.removeFromTop (4);
- arpTime.setBounds (boxes.removeFromTop (22));
- boxes.removeFromTop (4);
- arpChord.setBounds (boxes.removeFromTop (22));
- boxes.removeFromTop (4);
- arpSlide.setBounds (boxes.removeFromTop (22));
- arp.removeFromLeft (6);
- row (arp, { arpRange, arpGate, arpRepeat });
- }
- bottom.removeFromLeft (6);
- {
- auto echo = section (bottom, tr ("Echo delay / fat mode"));
- {
- // seven knobs (round 151 added Mod X / Y): narrower when the window is
- auto line = echo.removeFromTop (knobH);
- const auto w = juce::jmin (knobW, line.getWidth() / 7);
- for (auto* k : { echoFeed, echoPan, echoModX, echoModY, echoPitch, echoTime, echoCount })
- k->setBounds (line.removeFromLeft (w));
- }
- auto toggles = echo.removeFromTop (22);
- pingPong.setBounds (toggles.removeFromLeft (100));
- fatMode.setBounds (toggles.removeFromLeft (100));
- }
- area.removeFromTop (6);
- {
- auto rootRow = section (area.removeFromTop (74), tr ("Root note"));
- rootSection = (int) sections.size() - 1;
- const auto resetWidth = theme::buttonWidth (rootReset, 50, 96); // long "Reset" translations
- auto toggles = rootRow.removeFromLeft (100 + resetWidth);
- mainPitch.setBounds (toggles.removeFromTop (22));
- auto line = toggles.removeFromTop (22);
- rootReset.setBounds (line.removeFromRight (resetWidth).reduced (0, 1));
- addToKey.setBounds (line);
- auto fine = rootRow.removeFromLeft (58);
- row (fine, { fineTune });
- rootKeys.setBounds (rootRow.reduced (4, 2));
- }
- }
- private:
- // LYNX's chord choices for the arpeggiator (the piano roll's chord stamps)
- static const std::vector<std::pair<const char*, std::vector<int>>>& arpChords()
- {
- static const std::vector<std::pair<const char*, std::vector<int>>> chords {
- { TR_NOOP ("Major"), { 0, 4, 7 } }, { TR_NOOP ("Minor"), { 0, 3, 7 } }, { "Dim", { 0, 3, 6 } }, { "Aug", { 0, 4, 8 } },
- { "Sus2", { 0, 2, 7 } }, { "Sus4", { 0, 5, 7 } }, { "7", { 0, 4, 7, 10 } }, { "Maj7", { 0, 4, 7, 11 } },
- { "m7", { 0, 3, 7, 10 } }, { "m9", { 0, 3, 7, 10, 14 } }, { TR_NOOP ("Octave"), { 0, 12 } },
- };
- return chords;
- }
- static const std::vector<std::pair<const char*, float>>& arpSpeeds()
- {
- static const std::vector<std::pair<const char*, float>> speeds { { "1/4", 1.0f }, { "1/8", 0.5f },
- { TR_NOOP ("1/8 triplet"), 1.0f / 3.0f }, { "1/16", 0.25f },
- { TR_NOOP ("1/16 triplet"), 1.0f / 6.0f }, { "1/32", 0.125f } };
- return speeds;
- }
- const ChannelDef* current() const
- {
- const auto& channels = engine.getSong().channels;
- return channel >= 0 && channel < (int) channels.size() ? &channels[(std::size_t) channel] : nullptr;
- }
- void edit (std::function<void (ChannelDef&)> change)
- {
- if (updating || current() == nullptr)
- return;
- engine.editSong ([ch = channel, change] (Song& s) {
- if (ch < (int) s.channels.size())
- change (s.channels[(std::size_t) ch]);
- });
- }
- void refresh()
- {
- const auto* c = current();
- if (c == nullptr)
- return;
- updating = true;
- porta.setToggleState (channelPortamento (*c), juce::dontSendNotification);
- porta.setEnabled (channelHasPortamento (*c));
- slide->setEnabled (channelHasPortamento (*c));
- mono.setToggleState (channelMono (*c), juce::dontSendNotification);
- mono.setEnabled (channelHasMono (*c));
- cutSelf.setToggleState (channelCutsItself (*c), juce::dontSendNotification);
- arpDirection.setSelectedId (juce::jlimit (0, 5, c->arp.direction) + 1, juce::dontSendNotification);
- fullPorta.setToggleState (c->misc.fullPorta, juce::dontSendNotification);
- pingPong.setToggleState (c->misc.echo.pingPong, juce::dontSendNotification);
- fatMode.setToggleState (c->misc.echo.fat, juce::dontSendNotification);
- mainPitch.setToggleState (c->misc.mainPitch, juce::dontSendNotification);
- addToKey.setToggleState (c->misc.addToKey, juce::dontSendNotification);
- addToKey.setEnabled (c->instrument != InstrumentKind::sampler);
- rootKeys.setRoot (c->misc.rootNote);
- rootKeys.setRegion (c->keyLow, c->keyHigh);
- arpSlide.setToggleState (c->arp.slide, juce::dontSendNotification);
- const auto filter = c->instrument == InstrumentKind::synth || c->instrument == InstrumentKind::sampler;
- modX->setEnabled (filter);
- modY->setEnabled (filter);
- {
- auto chordId = c->arp.chord.empty() ? 1 : (c->arp.chord == std::vector<int> { 0 } ? 2 : 0);
- for (int i = 0; chordId == 0 && i < (int) arpChords().size(); ++i)
- if (arpChords()[(std::size_t) i].second == c->arp.chord)
- chordId = i + 3;
- arpChord.setSelectedId (chordId, juce::dontSendNotification);
- if (chordId == 0)
- arpChord.setText (tr ("Chord from FL"), juce::dontSendNotification);
- }
- int speed = 0;
- for (int i = 0; i < (int) arpSpeeds().size(); ++i)
- if (std::abs (arpSpeeds()[(std::size_t) i].second - c->arp.stepBeats) < 1e-4f)
- speed = i + 1;
- arpTime.setSelectedId (speed, juce::dontSendNotification);
- if (speed == 0)
- arpTime.setText (tr ("{0} beats", { juce::String (c->arp.stepBeats, 3) }), juce::dontSendNotification);
- updating = false;
- repaint();
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
- AudioEngine& engine;
- int channel;
- bool updating = false;
- std::vector<std::unique_ptr<FrameKnob>> knobs;
- FrameKnob *pan = nullptr, *volume = nullptr, *maxPoly = nullptr, *slide = nullptr, *swing = nullptr, *cut = nullptr, *cutBy = nullptr,
- *arpRange = nullptr, *arpGate = nullptr, *arpRepeat = nullptr, *modX = nullptr, *modY = nullptr, *timeGate = nullptr,
- *timeShift = nullptr, *trackPan = nullptr, *trackMid = nullptr, *echoFeed = nullptr, *echoPan = nullptr, *echoPitch = nullptr,
- *echoTime = nullptr, *echoCount = nullptr, *trackModX = nullptr, *trackModY = nullptr, *echoModX = nullptr, *echoModY = nullptr,
- *fineTune = nullptr;
- juce::ToggleButton porta, mono, fullPorta, pingPong, fatMode, mainPitch, arpSlide, addToKey;
- RootKeyboard rootKeys;
- juce::TextButton rootReset;
- int rootSection = -1;
- juce::TextButton trackVol, trackKey;
- juce::ComboBox arpChord;
- juce::TextButton cutSelf;
- juce::ComboBox arpDirection, arpTime;
- std::vector<std::pair<juce::Rectangle<int>, juce::String>> sections;
- };
- // FL's preset arrows of a generator's window (round 167o, issue #24; FL's TPluginForm NextPrevPreset, FLEngine
- // 0x12b6c70): ◀ name ▶ over the .fst presets of the plugin's folder (FL's factory folder and the user's, subfolders
- // too) in FL's order; no preset yet: ▶ the first, ◀ the last; both wrap. The step loads the preset into the channel
- // (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.
- class ChannelPresetBar final : public juce::Component
- {
- public:
- // after a preset is loaded (the channel's old name, the preset's): the window refreshes its page and title
- std::function<void (const juce::String&, const juce::String&)> onLoaded;
- ChannelPresetBar (AudioEngine& e, int c) : engine (e), channel (c)
- {
- for (auto* b : { &prev, &next })
- {
- b->setTooltip (b == &prev ? tr ("Previous preset") : tr ("Next preset"));
- b->setWantsKeyboardFocus (false);
- addAndMakeVisible (*b);
- }
- prev.onClick = [this] { step (-1); };
- next.onClick = [this] { step (1); };
- ui::setHint (*this, tr ("Presets: [LMB] the list, the arrows load the previous / next one"));
- }
- // Whether this channel's instrument has an FL preset folder (the bar is shown only then)
- static bool wanted (const AudioEngine& engine, int channel)
- {
- const auto& song = engine.getSong();
- if (! juce::isPositiveAndBelow (channel, (int) song.channels.size()))
- return false;
- const auto kind = song.channels[(std::size_t) channel].instrument;
- return ! natives::presetFolderOf (kind).empty() || banks::hasBank (kind);
- }
- void resized() override
- {
- auto r = getLocalBounds();
- prev.setBounds (r.removeFromLeft (24));
- next.setBounds (r.removeFromRight (24));
- nameArea = r.reduced (4, 0);
- }
- void paint (juce::Graphics& g) override
- {
- g.setColour (theme::colour::bg2);
- g.fillRoundedRectangle (nameArea.toFloat(), theme::radius::sm);
- g.setColour (current >= 0 ? theme::colour::textPrimary : theme::colour::textSecondary);
- g.setFont (theme::font (theme::type::body));
- g.drawText (current >= 0 ? currentName : tr ("Presets"), nameArea.reduced (6, 0), juce::Justification::centredLeft, true);
- }
- void mouseUp (const juce::MouseEvent& e) override
- {
- if (nameArea.contains (e.getPosition()) && ! e.mouseWasDraggedSinceMouseDown())
- showMenu();
- }
- private:
- const ChannelDef* def() const
- {
- const auto& song = engine.getSong();
- return juce::isPositiveAndBelow (channel, (int) song.channels.size()) ? &song.channels[(std::size_t) channel] : nullptr;
- }
- const std::vector<presetcycle::Preset>& list()
- {
- const auto* d = def();
- const auto kind = d != nullptr ? d->instrument : InstrumentKind::synth;
- if (! loaded || kind != listedKind)
- {
- const auto folder = natives::presetFolderOf (kind);
- presets = folder.empty() ? std::vector<presetcycle::Preset>()
- : presetcycle::listPresets (presetcycle::pluginPresetFolders (flStudioAccess().roots, true, folder));
- // LYNX's own bank after FL's presets (round 168n): the only presets without FL Studio
- const auto& bank = banks::bankOf (kind);
- for (int i = 0; i < (int) bank.size(); ++i)
- presets.push_back ({ banks::pathOf (i), banks::relativeOf (bank[(std::size_t) i]), bank[(std::size_t) i].name });
- listedKind = kind;
- loaded = true;
- current = d != nullptr ? presetcycle::indexOfName (presets, d->name) : -1; // (a channel named after its preset)
- currentName = current >= 0 ? juce::String::fromUTF8 (presets[(std::size_t) current].name.c_str()) : juce::String();
- }
- return presets;
- }
- void step (int delta)
- {
- const auto& all = list();
- const auto count = (int) all.size();
- // FL's next index; a preset LYNX can't read (an unknown or damaged state) is passed over in the same
- // direction, so the arrows keep going
- auto at = presetcycle::step (current, delta, count);
- for (int tries = 0; at >= 0 && tries < count; ++tries)
- {
- if (load (at, tries == count - 1))
- return;
- at = presetcycle::step (at, delta, count);
- }
- }
- bool load (int index, bool reportFailure = true)
- {
- const auto& all = list();
- const auto* d = def();
- if (d == nullptr || ! juce::isPositiveAndBelow (index, (int) all.size()))
- return false;
- const auto& preset = all[(std::size_t) index];
- const auto bankIndex = banks::indexOfPath (preset.path);
- auto changed = bankIndex >= 0 ? banks::withPreset (*d, bankIndex) : natives::withPreset (*d, preset.path, preset.name, flStudioAccess());
- if (! changed)
- {
- if (reportFailure)
- ui::postHint ({ tr ("This preset could not be read: {0}", { juce::String::fromUTF8 (preset.name.c_str()) }), {} }, 2500);
- current = index; // (the next step goes on from it)
- return false;
- }
- const auto kind = d->instrument;
- const auto oldName = juce::String::fromUTF8 (d->name.c_str());
- engine.editSong ([ch = channel, kind, c = std::move (*changed)] (Song& s) {
- if (ch < (int) s.channels.size() && s.channels[(std::size_t) ch].instrument == kind)
- s.channels[(std::size_t) ch] = c;
- });
- if (onLoaded != nullptr)
- onLoaded (oldName, juce::String::fromUTF8 (preset.name.c_str()));
- current = index;
- currentName = juce::String::fromUTF8 (preset.name.c_str());
- ui::postHint ({ currentName, juce::String (presetcycle::positionText (index, (int) all.size())) }, 2500);
- repaint();
- return true;
- }
- void showMenu()
- {
- const auto& all = list();
- juce::PopupMenu menu;
- std::map<std::string, juce::PopupMenu> folders;
- std::vector<std::string> order;
- for (int i = 0; i < (int) all.size(); ++i)
- {
- const auto& rel = all[(std::size_t) i].relative;
- const auto slash = rel.find_last_of ('/');
- const auto folder = slash == std::string::npos ? std::string() : rel.substr (0, slash);
- if (folders.find (folder) == folders.end())
- order.push_back (folder);
- folders[folder].addItem (juce::String::fromUTF8 (all[(std::size_t) i].name.c_str()), true, i == current, [this, i] { load (i); });
- }
- for (const auto& folder : order)
- if (folder.empty())
- for (juce::PopupMenu::MenuItemIterator it (folders[folder]); it.next();)
- menu.addItem (it.getItem());
- else
- menu.addSubMenu (juce::String::fromUTF8 (folder.c_str()), folders[folder]);
- if (menu.getNumItems() == 0)
- menu.addItem (tr ("No presets found (they come with FL Studio)"), false, false, [] {});
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
- }
- AudioEngine& engine;
- int channel;
- juce::TextButton prev { juce::String::fromUTF8 ("\xe2\x97\x80") }, next { juce::String::fromUTF8 ("\xe2\x96\xb6") };
- juce::Rectangle<int> nameArea;
- std::vector<presetcycle::Preset> presets;
- InstrumentKind listedKind = InstrumentKind::synth;
- bool loaded = false;
- int current = -1;
- juce::String currentName;
- };
- // The frame: header strip (tabs on the left; ON, PAN, VOL, TRACK on the right) over the page of the selected tab.
- class ChannelFrame final : public juce::Component,
- private juce::ChangeListener
- {
- public:
- static constexpr int headerHeight = 62;
- // c.index < 0 (a Patcher node, round 164f): the instrument's pages alone, without the channel's header and Misc tab
- ChannelFrame (AudioEngine& e, ChannelRef c, std::unique_ptr<juce::Component> instrumentPage, std::unique_ptr<juce::Component> envelopePage)
- : engine (e), channel (c.index), node (c.index < 0)
- {
- auto addPage = [this] (std::unique_ptr<juce::Component> page, const juce::String& title, const juce::String& tip) {
- auto button = std::make_unique<juce::TextButton> (title);
- button->setTooltip (tip);
- button->setClickingTogglesState (true);
- button->setRadioGroupId (1);
- const auto index = (int) pages.size();
- button->onClick = [this, index] { showTab (index); };
- addAndMakeVisible (*button);
- addChildComponent (*page);
- sizes.push_back ({ juce::jmax (1, page->getWidth()), juce::jmax (1, page->getHeight()) });
- tabs.push_back (std::move (button));
- pages.push_back (std::move (page));
- };
- instrumentPageFirst = instrumentPage != nullptr;
- if (instrumentPage != nullptr) // (none: a channel whose instrument has its own window, e.g. a hosted plugin)
- addPage (std::move (instrumentPage), tr ("Plugin"), tr ("The instrument's own settings"));
- if (envelopePage != nullptr)
- addPage (std::move (envelopePage), tr ("Envelope / instrument"), tr ("Envelope / instrument settings: the filter and pitch envelopes and the LFOs"));
- if (node)
- {
- int width = 1, height = 1;
- for (auto& p : pages)
- {
- width = juce::jmax (width, p->getWidth());
- height = juce::jmax (height, p->getHeight());
- }
- setSize (width, headerHeight + height);
- showTab (0);
- return;
- }
- addPage (std::make_unique<MiscPanel> (engine, channel), tr ("Misc"), tr ("Miscellaneous functions: levels, polyphony, time, tracking, cut groups, arpeggiator, echo delay"));
- on.setButtonText (tr ("On"));
- on.setTooltip (tr ("Channel on / off (mute)"));
- on.onClick = [this] {
- const auto muted = ! on.getToggleState();
- engine.editSong ([ch = channel, muted] (Song& s) {
- if (ch < (int) s.channels.size())
- s.channels[(std::size_t) ch].muted = muted;
- });
- };
- addAndMakeVisible (on);
- if (ChannelPresetBar::wanted (engine, channel))
- {
- presetBar = std::make_unique<ChannelPresetBar> (engine, channel);
- presetBar->onLoaded = [this, hasPage = instrumentPageFirst] (const juce::String& oldName, const juce::String& newName) {
- // the plugin page shows the new preset's settings, the window takes the channel's new name (as FL)
- juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<ChannelFrame> (this), hasPage, oldName, newName] {
- if (safe != nullptr)
- safe->presetLoaded (hasPage, oldName, newName);
- });
- };
- addAndMakeVisible (*presetBar);
- }
- const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
- auto headerKnob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get, std::function<void (Song&, int, double)> set,
- const char* caption) {
- auto k = std::make_unique<FrameKnob> (
- engine, std::move (spec),
- [this, get] { return channel < (int) engine.getSong().channels.size() ? get (engine.getSong().channels[(std::size_t) channel]) : 0.0; },
- [this, set] (double v) {
- engine.editSong ([ch = channel, set, v] (Song& s) {
- if (ch < (int) s.channels.size())
- set (s, ch, v);
- });
- },
- tr (caption));
- addAndMakeVisible (*k);
- header.push_back (std::move (k));
- };
- headerKnob ([this, name] {
- auto s = ui::panSpec (name() + " - " + tr ("Pan"));
- s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.pan; }, [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].pan = (float) v; },
- TR_NOOP ("Pan"));
- headerKnob ([this, name] {
- auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
- s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.volume; },
- [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].volume = (float) v; }, TR_NOOP ("Vol"));
- // FL's PITCH knob and its RANGE (REA round 146b): the channel's pitch, within ± range semitones
- headerKnob ([this, name] {
- ui::ValueSpec s;
- s.name = name() + " - " + tr ("Pitch (semitones, within the range)");
- const auto range = channel < (int) engine.getSong().channels.size() ? engine.getSong().channels[(std::size_t) channel].misc.pitchRange : 2;
- s.minimum = -juce::jmax (1, range);
- s.maximum = juce::jmax (1, range);
- s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v * 100.0)) }); };
- return s;
- },
- [] (const ChannelDef& d) { return (double) d.sampler.pitch; },
- [] (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"));
- headerKnob ([name] { return ui::digitWheel (countSpec (name() + " - " + tr ("Pitch knob range (semitones)"), 48, 2,
- [] (int v) { return juce::String (v); })); },
- [] (const ChannelDef& d) { return (double) d.misc.pitchRange; },
- [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].misc.pitchRange = juce::jlimit (0, 48, juce::roundToInt (v)); },
- TR_NOOP ("Range"));
- header.back()->digitBox = true;
- // FL's TRACK digiwheel (round 168s, issue #32 "very small and not accurate"): a wheel notch or 7.5 px of drag = the
- // next insert, double-click shows the insert in the Mixer, the menu has "Assign to free mixer track"
- headerKnob ([this, name] {
- return ui::digitWheel (countSpec (name() + " - " + tr ("Target mixer track"), maxMixerTracks - 1, 0,
- [] (int t) { return t == 0 ? tr ("Master") : juce::String (t); }));
- },
- [] (const ChannelDef& d) { return (double) d.mixerTrack; },
- [] (Song& s, int ch, double v) {
- mixerops::routeChannel (s, ch, juce::roundToInt (v)); // any insert (round 162): missing ones are added
- },
- TR_NOOP ("Track"));
- {
- auto& track = *header.back();
- track.digitBox = true;
- track.doubleClicked = [this] {
- if (channel < (int) engine.getSong().channels.size() && openMixerInsertHandler())
- openMixerInsertHandler() (engine.getSong().channels[(std::size_t) channel].mixerTrack);
- };
- track.extraMenuItems = [this] (juce::PopupMenu& menu) {
- menu.addItem (tr ("Assign to free mixer track"), [this] {
- engine.editSong ([ch = channel] (Song& s) {
- if (ch < (int) s.channels.size())
- s.channels[(std::size_t) ch].mixerTrack = s.claimFreeInsert();
- });
- });
- };
- }
- int width = MiscPanel::preferredWidth, height = MiscPanel::preferredHeight;
- for (auto& p : pages)
- {
- width = juce::jmax (width, p->getWidth());
- height = juce::jmax (height, p->getHeight());
- }
- refresh();
- engine.addChangeListener (this);
- setSize (width, headerHeight + height);
- showTab (0);
- }
- ~ChannelFrame() override
- {
- if (! node)
- engine.removeChangeListener (this);
- }
- void showTab (int index)
- {
- index = juce::jlimit (0, (int) pages.size() - 1, index);
- current = index;
- for (int i = 0; i < (int) pages.size(); ++i)
- {
- pages[(std::size_t) i]->setVisible (i == index);
- tabs[(std::size_t) i]->setToggleState (i == index, juce::dontSendNotification);
- }
- }
- void presetLoaded (bool hasPage, const juce::String& oldName, const juce::String& newName)
- {
- if (hasPage && ! pages.empty())
- if (auto fresh = makeChannelSettingsPanel (engine, channel))
- {
- removeChildComponent (pages.front().get());
- pages.front() = std::move (fresh);
- addChildComponent (*pages.front());
- resized();
- showTab (current);
- }
- if (auto* window = findParentComponentOfClass<juce::DocumentWindow>())
- if (const auto title = window->getName(); oldName.isNotEmpty() && title.startsWith (oldName))
- window->setName (newName + title.substring (oldName.length()));
- }
- int getTab() const noexcept { return current; }
- int tabCount() const noexcept { return (int) pages.size(); }
- void paint (juce::Graphics& g) override
- {
- g.fillAll (theme::colour::bg2);
- g.setColour (theme::colour::bg3);
- g.fillRect (getLocalBounds().removeFromTop (headerHeight));
- g.setColour (theme::colour::border);
- g.drawHorizontalLine (headerHeight - 1, 0.0f, (float) getWidth());
- }
- void resized() override
- {
- auto tabsArea = getLocalBounds().removeFromTop (headerHeight).reduced (8, 6);
- if (presetBar != nullptr) // tabs on the upper row, the preset arrows under them
- {
- presetBar->setBounds (tabsArea.removeFromBottom (22).removeFromLeft (juce::jmin (300, tabsArea.getWidth())));
- tabsArea.removeFromBottom (2);
- }
- for (auto& t : tabs)
- {
- const auto w = juce::jmax (64, (int) juce::GlyphArrangement::getStringWidth (juce::Font (theme::font (theme::type::body)), t->getButtonText()) + 24);
- t->setBounds (tabsArea.removeFromLeft (w).withSizeKeepingCentre (w, juce::jmin (26, tabsArea.getHeight())));
- tabsArea.removeFromLeft (4);
- }
- auto right = getLocalBounds().removeFromTop (headerHeight).reduced (6, 2);
- for (auto it = header.rbegin(); it != header.rend(); ++it)
- (*it)->setBounds (right.removeFromRight (48));
- on.setBounds (right.removeFromRight (52).withSizeKeepingCentre (52, 24));
- // each page keeps its own size (some scale their drawing with it), centred under the header
- const auto body = getLocalBounds().withTrimmedTop (headerHeight);
- for (std::size_t i = 0; i < pages.size(); ++i)
- {
- const auto w = juce::jmin (body.getWidth(), sizes[i].x), h = juce::jmin (body.getHeight(), sizes[i].y);
- pages[i]->setBounds (body.getX() + (body.getWidth() - w) / 2, body.getY(), w, h);
- }
- }
- private:
- void refresh()
- {
- if (channel < (int) engine.getSong().channels.size())
- on.setToggleState (! engine.getSong().channels[(std::size_t) channel].muted, juce::dontSendNotification);
- for (auto& k : header)
- k->repaint();
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
- AudioEngine& engine;
- int channel;
- bool node = false;
- int current = 0;
- std::vector<std::unique_ptr<juce::TextButton>> tabs;
- std::vector<std::unique_ptr<juce::Component>> pages;
- std::vector<juce::Point<int>> sizes;
- std::vector<std::unique_ptr<FrameKnob>> header;
- juce::ToggleButton on;
- std::unique_ptr<ChannelPresetBar> presetBar;
- bool instrumentPageFirst = false;
- };
- bool hasEnvelopeTab (InstrumentKind kind) noexcept
- {
- return kind == InstrumentKind::synth || kind == InstrumentKind::sampler;
- }
- void showModulationFor (juce::Component& from, AudioEngine& engine, int channel)
- {
- if (auto* frame = from.findParentComponentOfClass<ChannelFrame>(); frame != nullptr && frame->tabCount() >= 2)
- frame->showTab (1);
- else if (channel >= 0)
- openChannelModulation (engine, channel);
- }
- bool isModelKind (InstrumentKind kind) noexcept
- {
- return kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
- || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
- || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
- || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
- || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::keplerExo || kind == InstrumentKind::poizone
- || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
- || kind == InstrumentKind::threeosc
- || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
- || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
- || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
- || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
- || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus;
- }
- // The instrument page of a channel or a Patcher node (null: none of its own)
- std::unique_ptr<juce::Component> makeInstrumentPage (AudioEngine& engine, const ChannelRef& ref)
- {
- const auto* def = ref.get (engine);
- if (def == nullptr)
- return nullptr;
- const auto kind = def->instrument;
- if (kind == InstrumentKind::fruitydance && ref.index >= 0)
- return makeDanceEditor (engine, ref.index); // round 165e
- if (kind == InstrumentKind::videoplayer)
- return makeVideoPlayerEditor (engine, ref.locate, ref.index); // round 165g
- if (kind == InstrumentKind::wavetraveller)
- return makeWaveTravellerEditor (engine, ref.locate, ref.index); // round 167f
- if (kind == InstrumentKind::synth)
- return std::make_unique<SynthPanel> (engine, ref);
- if (isModelKind (kind))
- return std::make_unique<ModelPanel> (engine, ref);
- if (kind == InstrumentKind::sampler)
- return std::make_unique<SettingsPanel> (engine, ref);
- return nullptr;
- }
- // Where "Align all channel editors" put every channel editor (FL stores it per channel, so editors opened later come
- // up there too); empty = centred, as before.
- std::optional<juce::Point<int>>& alignedChannelEditorPosition()
- {
- static std::optional<juce::Point<int>> at;
- return at;
- }
- class SettingsWindow final : public juce::DocumentWindow
- {
- public:
- SettingsWindow (AudioEngine& engine, int c, bool modulationWindow)
- : juce::DocumentWindow (tr ("Channel settings"), theme::colour::bg2, DocumentWindow::closeButton),
- channel (c),
- modulation (modulationWindow)
- {
- setUsingNativeTitleBar (true);
- // FL names the window after the channel and its mixer track (REA round 149 [EXEC]: "FL Studio VSTi (Master)",
- // "Synth Bass (Synth Bass)")
- if (const auto& song = engine.getSong(); channel >= 0 && channel < (int) song.channels.size())
- {
- const auto& def = song.channels[(std::size_t) channel];
- const auto t = def.mixerTrack;
- const auto track = t <= 0 || t >= (int) song.mixer.size() ? tr ("Master")
- : song.mixer[(std::size_t) t].name.empty() ? tr ("Insert {0}", { juce::String (t) })
- : juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
- setName (juce::String::fromUTF8 (def.name.c_str()) + " (" + track + ")"
- + (modulation ? " - " + tr ("Envelope / instrument") : juce::String()));
- }
- if (modulation)
- setContentOwned (new ModulationPanel (engine, ChannelRef::rack (channel)), true);
- else if (! hasChannelSettings (engine.getSong().channels[(std::size_t) channel].instrument))
- setContentOwned (new ChannelFrame (engine, ChannelRef::rack (channel), nullptr, nullptr), true); // the Misc tab alone
- else
- setContentOwned (makeChannelFrame (engine, channel).release(), true);
- centreWithSize (getWidth(), getHeight());
- if (! modulation)
- if (const auto& at = alignedChannelEditorPosition(); at.has_value())
- setTopLeftPosition (*at); // "Align all channel editors" set every channel's place (round 169k)
- setVisible (true);
- keepAboveMainWindow (*this);
- }
- int getChannel() const { return channel; }
- bool isModulation() const { return modulation; }
- void closeButtonPressed() override;
- private:
- int channel;
- bool modulation;
- };
- std::vector<std::unique_ptr<SettingsWindow>>& windows()
- {
- static std::vector<std::unique_ptr<SettingsWindow>> open;
- return open;
- }
- void SettingsWindow::closeButtonPressed()
- {
- auto* self = this;
- juce::MessageManager::callAsync ([self] {
- auto& open = windows();
- open.erase (std::remove_if (open.begin(), open.end(), [self] (auto& w) { return w.get() == self; }), open.end());
- });
- }
- } // namespace
- namespace
- {
- void openWindow (AudioEngine& engine, int channel, bool modulation)
- {
- for (auto& w : windows())
- if (w->getChannel() == channel && w->isModulation() == modulation)
- {
- w->toFront (true);
- return;
- }
- windows().push_back (std::make_unique<SettingsWindow> (engine, channel, modulation));
- }
- } // namespace
- void alignAllChannelEditors (int selectedChannel)
- {
- // FL's AlignAllChannelEditorsAction (FUN_012317c0, REA_rodada169k §2.4): the focused channel editor (else the
- // selected channel's, else the first open one) gives the place; every channel editor goes there.
- auto& open = windows();
- SettingsWindow* reference = nullptr;
- for (auto& w : open)
- if (! w->isModulation() && w->isActiveWindow())
- reference = w.get();
- for (auto& w : open)
- if (reference == nullptr && ! w->isModulation() && w->getChannel() == selectedChannel)
- reference = w.get();
- for (auto& w : open)
- if (reference == nullptr && ! w->isModulation())
- reference = w.get();
- if (reference == nullptr)
- return;
- const auto at = reference->getPosition();
- alignedChannelEditorPosition() = at;
- for (auto& w : open)
- if (! w->isModulation())
- w->setTopLeftPosition (at);
- reference->toFront (true);
- }
- void openChannelSettings (AudioEngine& engine, int channel)
- {
- openWindow (engine, channel, false);
- }
- void openChannelMisc (AudioEngine& engine, int channel)
- {
- openWindow (engine, channel, false);
- for (auto& w : windows())
- if (w->getChannel() == channel && ! w->isModulation())
- if (auto* frame = dynamic_cast<ChannelFrame*> (w->getContentComponent()))
- frame->showTab (frame->tabCount() - 1);
- }
- void openChannelModulation (AudioEngine& engine, int channel)
- {
- openWindow (engine, channel, true);
- }
- void closeChannelSettings()
- {
- windows().clear();
- }
- bool hasChannelSettings (InstrumentKind kind) noexcept
- {
- switch (kind)
- {
- case InstrumentKind::synth:
- case InstrumentKind::sampler:
- case InstrumentKind::controller:
- case InstrumentKind::midiOut:
- case InstrumentKind::sakura:
- case InstrumentKind::drumpad:
- case InstrumentKind::boobass:
- case InstrumentKind::drumsynth:
- case InstrumentKind::harmless:
- case InstrumentKind::harmor:
- case InstrumentKind::gms:
- case InstrumentKind::morphine:
- case InstrumentKind::ogun:
- case InstrumentKind::minisynth:
- case InstrumentKind::dx10:
- case InstrumentKind::kepler:
- case InstrumentKind::keplerExo:
- case InstrumentKind::poizone:
- case InstrumentKind::fruitkick:
- case InstrumentKind::bassdrum:
- case InstrumentKind::toxic:
- case InstrumentKind::threeosc:
- case InstrumentKind::autogun:
- case InstrumentKind::transistorbass:
- case InstrumentKind::simsynth:
- case InstrumentKind::wasp:
- case InstrumentKind::plucked:
- case InstrumentKind::beepmap:
- case InstrumentKind::sawer:
- case InstrumentKind::flkeys:
- case InstrumentKind::granulizer:
- case InstrumentKind::drumaxx:
- case InstrumentKind::slayer:
- case InstrumentKind::fruitydance:
- case InstrumentKind::sytrus:
- case InstrumentKind::soundfont:
- case InstrumentKind::layer:
- case InstrumentKind::dashboard:
- case InstrumentKind::voltage:
- case InstrumentKind::vfx:
- case InstrumentKind::wavetraveller:
- return true;
- default:
- return false;
- }
- }
- bool isChannelSettingsOpen (int channel)
- {
- return std::any_of (windows().begin(), windows().end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); });
- }
- void closeChannelSettings (int channel)
- {
- auto& open = windows();
- open.erase (std::remove_if (open.begin(), open.end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); }),
- open.end());
- }
- std::unique_ptr<juce::Component> makeChannelModulationPanel (AudioEngine& engine, int channel)
- {
- return std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel));
- }
- std::unique_ptr<juce::Component> makeChannelPrecomputePanel (AudioEngine& engine, int channel)
- {
- return std::make_unique<PrecomputePanel> (engine, ChannelRef::rack (channel));
- }
- int showChannelLayoutPage (juce::Component& frame, int page)
- {
- if (auto* panel = dynamic_cast<ModelPanel*> (&frame); panel != nullptr && panel->pageCount() > 0)
- {
- const auto count = panel->pageCount();
- if (page >= 0 && page < count)
- panel->showPage (page);
- return count;
- }
- for (auto* child : frame.getChildren())
- if (const auto count = showChannelLayoutPage (*child, page); count > 0)
- return count;
- return 0;
- }
- int channelFrameHeaderHeight() noexcept
- {
- return ChannelFrame::headerHeight;
- }
- std::unique_ptr<juce::Component> makeChannelFrame (AudioEngine& engine, int channel, int tab)
- {
- const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
- auto frame = std::make_unique<ChannelFrame> (engine, ChannelRef::rack (channel), makeChannelSettingsPanel (engine, channel),
- hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel)) : nullptr);
- frame->showTab (tab < 0 ? frame->tabCount() - 1 : tab);
- return frame;
- }
- std::unique_ptr<juce::Component> makeChannelSettingsPanel (AudioEngine& engine, int channel)
- {
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::synth)
- return std::make_unique<SynthPanel> (engine, ChannelRef::rack (channel));
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::controller)
- {
- if (parseKeyboardController (engine.getSong().channels[(std::size_t) channel].controllerState))
- return makeKeyboardControllerEditor (engine, channel); // round 165c (it showed the Envelope Controller's read-only page)
- return makeEnvelopeControllerEditor (engine, channel);
- }
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::midiOut)
- return makeMidiOutEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::soundfont)
- return makeSoundFontEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::layer)
- return makeLayerEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::dashboard)
- return makeDashboardEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::voltage)
- return makeVoltageControllerEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::vfx)
- return makeVfxEditor (engine, channel);
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::fruitydance)
- return makeDanceEditor (engine, channel); // round 165e
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::videoplayer)
- return makeVideoPlayerEditor (engine, channel); // round 165g
- if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::wavetraveller)
- return makeWaveTravellerEditor (engine, channel); // round 167f
- if (const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
- kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
- || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
- || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
- || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
- || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::keplerExo || kind == InstrumentKind::poizone
- || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
- || kind == InstrumentKind::threeosc
- || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
- || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
- || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
- || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
- || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus)
- return std::make_unique<ModelPanel> (engine, ChannelRef::rack (channel));
- return std::make_unique<SettingsPanel> (engine, ChannelRef::rack (channel));
- }
- bool hasNodeEditor (const ChannelDef& channel) noexcept
- {
- return channel.instrument == InstrumentKind::synth || channel.instrument == InstrumentKind::sampler || isModelKind (channel.instrument);
- }
- std::unique_ptr<juce::Component> makeNodeChannelFrame (AudioEngine& engine, std::function<ChannelDef* (Song&)> locate)
- {
- ChannelRef ref { std::move (locate), -1 };
- const auto* def = ref.get (engine);
- if (def == nullptr)
- return nullptr;
- auto page = makeInstrumentPage (engine, ref);
- if (page == nullptr)
- return nullptr;
- const auto kind = def->instrument;
- return std::make_unique<ChannelFrame> (engine, ref, std::move (page), hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ref) : nullptr);
- }
- std::function<void (int)>& openMixerInsertHandler()
- {
- static std::function<void (int)> handler;
- return handler;
- }
- } // namespace lynx
|