| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352 |
- #include "ui/ThemeSettings.h"
- #include "ui/ColourPicker.h"
- #include "core/NoteNames.h"
- #include "ui/ProjectLoading.h"
- #include "ui/UiTrace.h"
- #include "core/LoadTrace.h"
- #include "ui/MainComponent.h"
- #include "core/Performance.h"
- #include "core/TransportEdit.h"
- #include "ui/CrashReporter.h"
- #include "ui/DanceView.h"
- #include "engine/AudioLogger.h"
- #include "ui/PluginSkin.h"
- #include "platform/Paths.h"
- #include "ui/SetupWizard.h"
- #include "core/FlPluginDb.h"
- #include "core/Preferences.h"
- #include "core/EditorPolish.h"
- #include "ui/HistoryPanel.h"
- #include "ui/MissingFilesDialog.h"
- #include "ui/SettingsDialog.h"
- #include "ui/PluginManager.h"
- #include "ui/ShortcutManager.h"
- #include "ui/WaveformView.h"
- #include "ui/QuickAddPalette.h"
- #include "ui/PatcherEditor.h"
- #include "ui/ToolWindow.h"
- #include "ui/LoopStarterWindow.h"
- #include "ui/WindowOwner.h"
- #include "engine/PluginSandbox.h"
- #include "platform/FileTypes.h"
- #include "platform/CrashGuard.h"
- #include "platform/LinuxRealtime.h"
- #include "platform/Package.h"
- #include "engine/Text.h"
- #include "core/MetronomeVoice.h"
- #include "core/RackOps.h"
- #include "core/Templates.h"
- #include "ui/NewProjectDialog.h"
- #include "ui/PluginMonitorWindow.h"
- #include "ui/TouchKeyboard.h"
- #include "engine/MidiFileIo.h"
- #include "engine/ProjectFile.h"
- #include "engine/ProjectPackage.h"
- #include "core/ProjectSafety.h"
- #include "core/MissingFiles.h"
- #include "ui/AutomationUi.h"
- #include "ui/ChannelSettings.h"
- #include "ui/Dialogs.h"
- #include "ui/EditorTools.h"
- #include "ui/AudioEditor.h"
- #include "ui/TempoTapper.h"
- #include "ui/ExportDialog.h"
- #include "ui/ParametricEqEditor.h"
- #include "ui/PluginWindow.h"
- #include "ui/I18n.h"
- #include "ui/Theme.h"
- #include "ui/WaveformView.h"
- #include "core/HintMarkup.h"
- #include "core/SongStats.h"
- namespace lynx
- {
- namespace
- {
- using workspace::Panel;
- constexpr Panel panelOrder[] = { Panel::playlist, Panel::channelRack, Panel::pianoRoll, Panel::mixer, Panel::browser };
- const char* panelAction (Panel p)
- {
- switch (p)
- {
- case Panel::playlist: return "panel.playlist";
- case Panel::channelRack: return "panel.channelRack";
- case Panel::pianoRoll: return "panel.pianoRoll";
- case Panel::mixer: return "panel.mixer";
- case Panel::browser: return "panel.browser";
- }
- return "";
- }
- juce::String panelName (Panel p)
- {
- switch (p)
- {
- case Panel::playlist: return "Playlist";
- case Panel::channelRack: return "Channel Rack";
- case Panel::pianoRoll: return "Piano Roll";
- case Panel::mixer: return "Mixer";
- case Panel::browser: return "Browser";
- }
- return {};
- }
- } // namespace
- MainComponent::MainComponent (AudioEngine& e, bool restoreUserSettings)
- : persistent (restoreUserSettings),
- engine (e),
- rack (e),
- pianoRoll (e),
- playlist (e),
- mixer (e),
- browser (e)
- {
- heldKeys.setSender ([this] (int channel, int key, float velocity, bool on) { engine.sendLiveNote (channel, key, velocity, on, true); });
- connectBrowser (browser);
- addChildComponent (updateBar);
- updateBar.onVisibilityChanged = [this] { resized(); };
- if (restoreUserSettings) // (the real window: Update saves the project as on quit and reopens it)
- updater::setHost ({ [safe = juce::Component::SafePointer<MainComponent> (this)] (std::function<void()> then) {
- if (safe != nullptr)
- safe->confirmDiscard (std::move (then));
- },
- [safe = juce::Component::SafePointer<MainComponent> (this)] {
- return safe != nullptr ? safe->currentFile : juce::File();
- } });
- mixeroptions::changed = [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr)
- {
- safe->saveUiSettings();
- safe->playlist.repaint();
- }
- };
- mixeroptions::setShowUsedOnly = [safe = juce::Component::SafePointer<MainComponent> (this)] (bool on) {
- if (safe != nullptr)
- safe->mixer.getStripsForSnapshot().setShowUsedOnly (on);
- };
- mixeroptions::renderTracks = [safe = juce::Component::SafePointer<MainComponent> (this)] (std::vector<int> tracks,
- std::function<void (const std::vector<juce::File>&)> done) {
- if (safe != nullptr)
- showExportDialogForTracks (safe->engine, safe->currentFile.getParentDirectory(), safe->projectName, tracks, std::move (done));
- };
- if (persistent)
- {
- loadUiSettings();
- // the start-up song follows Options › Mixer too (round 163) and the automatic crossfades of new projects (166e)
- engine.setSong (makeNewProject());
- skin::onStyleSettingsChanged = [safe = juce::Component::SafePointer<MainComponent> (this)] { // an editor's own style was picked
- if (safe != nullptr) safe->saveUiSettings();
- };
- loadKeyMap();
- startSession();
- if (BrowserComponent::sampleBrowserWasOpen()) // it was open when LYNX closed (round 163)
- juce::Timer::callAfterDelay (800, [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr && findToolWindow ("sampleBrowser") == nullptr)
- safe->openSampleBrowser();
- });
- EditorGlobals::get().onOptionsChanged = [safe = juce::Component::SafePointer<MainComponent> (this)] { // Follow on/off
- if (safe != nullptr) safe->saveUiSettings();
- };
- }
- PianoRollComponent::shortcutText = [this] (const std::string& id) { return shortcutText (id.c_str()); };
- newButton.setTooltip (tr ("New project") + " (Ctrl+N)");
- newButton.onClick = [this] { newProject(); };
- openButton.setTooltip (tr ("Open project") + " (Ctrl+O)");
- openButton.onClick = [this] { chooseFileToOpen(); };
- saveButton.setTooltip (tr ("Save project") + " (Ctrl+S)");
- saveButton.onClick = [this] { save (false); };
- exportButton.setTooltip (tr ("Export audio: WAV, FLAC or OGG") + " (Ctrl+R)");
- exportButton.onClick = [this] { exportAudio(); };
- auto withKey = [this] (const juce::String& text, const char* id) {
- const auto key = shortcutText (id).trim();
- return key.isEmpty() ? text : text + " (" + key + ")";
- };
- undoButton.setTooltip (withKey (tr ("Undo"), "edit.undo"));
- undoButton.onClick = [this] { flUndo(); }; // FL's toolbar Undo is its Edit › Undo (UndoAction)
- undoButton.onRightClick = [this] { showHistory(); };
- redoButton.setTooltip (withKey (tr ("Redo"), "edit.redo"));
- redoButton.onClick = [this] { undoRedo (true); };
- redoButton.onRightClick = [this] { showHistory(); };
- pluginPickerButton.setTooltip (withKey (tr ("Plugin picker: add an instrument or plugin as a new channel"), "panel.quickAdd"));
- pluginPickerButton.onClick = [this] { showQuickAdd(); };
- // transport: Play toggles play / stop-and-back; Stop returns to the start; double-click Stop = all notes off
- playButton.setTooltip (tr ("Play; pressed again, stops and goes back to where it started") + " (Space; Ctrl+Space pauses)");
- playButton.onClick = [this] { playStop(); };
- stopButton.setTooltip (tr ("Stop and return to the start (double-click: back to the start and all notes off)"));
- stopButton.onClick = [this] { stopAndRewind(); };
- stopButton.onDoubleClick = [this] { // FL-like: a double Stop goes back to the very start (and silences hanging notes)
- engine.panic();
- stopAndRewind (true);
- };
- stopButton.onRightClick = [this] { showStopMenu(); };
- output.onModeChanged = [this] { saveUiSettings(); };
- recordButton.setOnColour (theme::colour::record);
- recordButton.setIconColour (theme::colour::record.withMultipliedSaturation (0.8f));
- recordButton.onClick = [this] { toggleRecording(); };
- recordMenuButton.setTooltip (tr ("Recording options: what to record"));
- recordMenuButton.onClick = [this] { showRecordMenu(); };
- recordButton.onRightClick = [this] { showRecordMenu(); };
- // Pattern / Song: a two-segment switch (L toggles); right-click shows the matching panel
- // as in FL, a two-line switch in front of the transport buttons: pattern on top, song below
- patternModeButton.setText (tr ("Pattern"));
- songModeButton.setText (tr ("Song"));
- for (auto* b : { &patternModeButton, &songModeButton })
- {
- b->setOnColour (theme::colour::bg6);
- b->setIconColourWhenOn (theme::colour::textPrimary);
- }
- patternModeButton.setTooltip (tr ("Pattern mode: plays the current pattern in a loop") + " (L)\n" + tr ("Right-click: show the Channel Rack"));
- songModeButton.setTooltip (tr ("Song mode: plays the Playlist arrangement") + " (L)\n" + tr ("Right-click: show the Playlist"));
- patternModeButton.onClick = [this] {
- if (engine.getSong().mode != PlayMode::pattern)
- toggleMode();
- };
- songModeButton.onClick = [this] {
- if (engine.getSong().mode != PlayMode::song)
- toggleMode();
- };
- patternModeButton.onRightClick = [this] { showPanel (Panel::channelRack); };
- songModeButton.onRightClick = [this] { showPanel (Panel::playlist); };
- metronomeButton.setClickingTogglesState (true);
- metronomeButton.setOnColour (theme::colour::bg6);
- metronomeButton.setIconColourWhenOn (theme::colour::accent);
- metronomeButton.setTooltip (tr ("Metronome"));
- metronomeButton.onClick = [this] { engine.getTransport().metronome.store (metronomeButton.getToggleState()); };
- midiLight.onReconnect = [this] {
- engine.reconnectMidiInputs();
- midiInputTicks = 0; // shows the reopened inputs at the next tick
- };
- metronomeButton.onRightClick = [this] { showMetronomeMenu(); };
- typingPianoButton.setOnColour (theme::colour::bg6);
- typingPianoButton.setIconColourWhenOn (theme::colour::accent);
- typingPianoButton.onClick = [this] { setTypingPiano (! typingPiano); };
- // count-in and wait-for-input switches next to the metronome, as in FL's recording panel
- for (auto* b : { &countInButton, &waitInputButton })
- {
- b->setOnColour (theme::colour::bg6);
- b->setIconColourWhenOn (theme::colour::accent);
- }
- countInButton.onClick = [this] { runAction ("record.countIn"); };
- waitInputButton.onClick = [this] { runAction ("record.waitForInput"); };
- for (int i = 0; i < workspace::panelCount; ++i)
- {
- const auto panel = (Panel) i;
- auto& b = panelButtons[(std::size_t) i];
- b.setFlat (true);
- b.setOnColour (theme::colour::bg5);
- b.setIconColourWhenOn (theme::colour::textPrimary);
- b.setTooltip (panelName (panel) + " (" + keys::toString (keyMap.chordsFor (panelAction (panel)).empty() ? keys::Chord {}
- : keyMap.chordsFor (panelAction (panel)).front()) + ")\n"
- + tr ("Click: show, focus or hide. Right-click: show maximized"));
- b.onClick = [this, panel] { togglePanel (panel); };
- b.onRightClick = [this, panel] {
- showPanel (panel);
- if (! workspace.isMaximised (panel) && ! workspace.isDetached (panel))
- workspace.toggleMaximised (panel);
- refreshPanelButtons();
- };
- }
- patternBox.setTooltip (tr ("Current pattern (Numpad +/-: next/previous, F4: next empty, F2: rename)"));
- patternBox.setScrollWheelEnabled (true);
- gridBox.setScrollWheelEnabled (true);
- patternBox.onChange = [this]
- {
- const auto index = patternBox.getSelectedItemIndex();
- if (index >= 0 && index != engine.getSong().currentPattern)
- selectPattern (index);
- };
- newPatternButton.setTooltip (tr ("New pattern"));
- newPatternButton.onClick = [this]
- {
- engine.editSong ([] (Song& s) {
- Pattern p;
- p.name = newPatternName (s);
- s.patterns.push_back (std::move (p));
- s.currentPattern = (int) s.patterns.size() - 1;
- });
- };
- swingSlider.setRange (0.0, 1.0, 0.01);
- swingSlider.setDoubleClickReturnValue (true, 0.0);
- swingSlider.setValue (engine.getSong().swing, juce::dontSendNotification);
- swingSlider.textFromValueFunction = [] (double v) { return juce::String (juce::roundToInt (v * 100.0)) + "%"; };
- swingSlider.valueFromTextFunction = [] (const juce::String& t) { return t.retainCharacters ("0123456789.").getDoubleValue() / 100.0; };
- swingSlider.onValueChange = [this] { engine.editSong ([v = (float) swingSlider.getValue()] (Song& s) { s.swing = v; }); };
- swingSlider.setTooltip (tr ("Swing of the Channel Rack (all channels)"));
- swingSlider.setMouseClickGrabsKeyboardFocus (false);
- swingSlider.setWantsKeyboardFocus (false);
- patternMenuButton.setTooltip (tr ("Pattern: rename, color, clone, insert, split, length, delete"));
- patternMenuButton.onClick = [this] { showPatternMenu(); };
- // the workspace panels
- rack.onOpenPianoRoll = [this] { openPianoRoll(); };
- mixerinput::openAudioSettings = [this] { openSettings ((int) SettingsPage::audio); };
- PatcherWindows::onBrowsePluginDatabase = [this] (bool) {
- showPanel (Panel::browser);
- browser.showPluginDatabaseForSnapshot(); // (its Generators and Effects folders open)
- if (auto* w = getTopLevelComponent())
- w->toFront (true);
- };
- rack.onOpenMixerInsert = [this] (int insert) { // double-click on a channel's route box
- showPanel (Panel::mixer);
- mixer.selectTrack (insert);
- };
- mixer.onInstrumentDropped = [this] (int insert, ChannelDef c) { rack.addChannel (std::move (c), true, insert); };
- rackViewport.setViewedComponent (&rack, false);
- rackViewport.setScrollBarsShown (true, true);
- workspace.setContent (Panel::playlist, playlistArea, "Playlist", Icon::playlist);
- workspace.setContent (Panel::channelRack, rackViewport, "Channel Rack", Icon::channelRack);
- workspace.setContent (Panel::pianoRoll, pianoRoll, "Piano Roll", Icon::pianoRoll);
- workspace.setContent (Panel::mixer, mixer, "Mixer", Icon::mixer);
- workspace.setContent (Panel::browser, browser, "Browser", Icon::browser);
- workspace.setTitleTooltip (Panel::channelRack, tr ("Shift+wheel here changes the pattern"));
- // FL keeps the channel filter, the global swing and the graph editor switch in the rack's title bar
- rackFilterBox.text = rack.filterName();
- rackFilterBox.onClick = [this] { rack.showFilterMenu (&rackFilterBox); };
- rack.onFilterChanged = [this] {
- rackFilterBox.text = rack.filterName();
- rackFilterBox.repaint();
- rackGraphButton.setToggleState (rack.areGraphLanesShown(), juce::dontSendNotification);
- rackPianoRollButton.setToggleState (rack.isPianoRollView(), juce::dontSendNotification);
- rackLoopButton.setToggleState (rack.isLoopingOn(), juce::dontSendNotification);
- };
- rackGraphButton.setClickingTogglesState (false);
- rackGraphButton.onClick = [this] { rack.toggleGraphLanes(); };
- // the step sequencer / piano-roll view switch (FL keeps it in the rack's title bar too)
- rackPianoRollButton.setClickingTogglesState (false);
- rackPianoRollButton.setOnColour (theme::colour::bg6);
- rackPianoRollButton.setIconColourWhenOn (theme::colour::accent);
- rackPianoRollButton.onClick = [this] { runAction ("rack.pianoRollView"); };
- ui::setHint (rackPianoRollButton, tr ("Piano-roll view: every channel shows its notes as a miniature piano roll (click one to edit it) "
- "instead of the step buttons; click again for the steps"));
- rackTitleTools.addAndMakeVisible (rackPianoRollButton);
- // Follow (issue #12): a long pattern pages along with the playing step
- rackFollowButton.setClickingTogglesState (false);
- rackFollowButton.setOnColour (theme::colour::bg6);
- rackFollowButton.setIconColourWhenOn (theme::colour::accent);
- rackFollowButton.setWantsKeyboardFocus (false);
- rackFollowButton.setMouseClickGrabsKeyboardFocus (false);
- rackFollowButton.setToggleState (EditorGlobals::get().isFollowingView (EditorGlobals::FollowView::channelRack), juce::dontSendNotification);
- rackFollowButton.setTooltip (tr ("Follow: a pattern longer than the Channel Rack pages along with the playing step; off, it stays where you scrolled"));
- ui::setQuickTip (rackFollowButton, tr ("Follow the playhead"));
- rackFollowButton.onClick = [this] { runAction ("rack.follow"); };
- rackTitleTools.addAndMakeVisible (rackFollowButton);
- // FL's Loop button (round 165f-rack): click switches the pattern's channel looping, right-click its loop type and burns
- rackLoopButton.setClickingTogglesState (false);
- rackLoopButton.setOnColour (theme::colour::bg6);
- rackLoopButton.setIconColourWhenOn (theme::colour::accent);
- rackLoopButton.onClick = [this] { rack.toggleLooping(); };
- rackLoopButton.onRightClick = [this] { rack.showLoopMenu (&rackLoopButton); };
- ui::setHint (rackLoopButton, tr ("Channel looping: channels shorter than the pattern repeat to its end (polyrhythms) [LMB] on / off "
- "[RMB] loop type (step channels, all channels, advanced) and Burn to pattern"));
- rackTitleTools.addAndMakeVisible (rackLoopButton);
- // Loop Starter (round 168b; FL 25's dice in the Channel Rack): a drum loop of the genre's kit, re-rolled with dice
- rackLoopStarterButton.setWantsKeyboardFocus (false);
- rackLoopStarterButton.onClick = [this] { loopstarterui::open (engine); };
- ui::setHint (rackLoopStarterButton, tr ("Loop Starter: pick a genre and get a drum loop (kit channels with steps) to re-roll and send to the Playlist"));
- rackTitleTools.addAndMakeVisible (rackLoopStarterButton);
- // the pattern selector (issue #9): change the pattern the rack edits right from its title bar
- rackPatternSelector.onStep = [this] (int delta) { selectPattern (stepPattern (engine.getSong(), delta)); };
- rackPatternSelector.onMenu = [this] { showRackPatternList(); };
- ui::setHint (rackPatternSelector, tr ("Pattern the Channel Rack edits: [LMB] on the name: the list of patterns, on the arrows: previous / next [Wheel] step"));
- rackTitleTools.addAndMakeVisible (rackPatternSelector);
- rackTitleTools.addAndMakeVisible (rackFilterBox);
- rackTitleTools.addAndMakeVisible (swingSlider);
- // the pattern length in bars (issue #12)
- rackLengthBox.onSet = [this] (int bars) {
- const auto index = engine.getSong().currentPattern;
- const auto ticks = (std::int64_t) juce::jlimit (0, 999, bars) * ppq * juce::jmax (1, engine.getSong().beatsPerBar);
- if (index >= 0 && index < (int) engine.getSong().patterns.size() && engine.getSong().patterns[(std::size_t) index].lengthTicks != ticks)
- engine.editSong ([index, ticks] (Song& s) { s.patterns[(std::size_t) index].lengthTicks = ticks; });
- refreshRackLengthBox();
- };
- rackLengthBox.onMenu = [this] { showPatternLengthMenu(); };
- ui::setHint (rackLengthBox, tr ("Pattern length in bars: [LMB] drag or [Wheel] change it [2xLMB] automatic (from the notes) [RMB] menu"));
- rackTitleTools.addAndMakeVisible (rackLengthBox);
- rackTitleTools.addAndMakeVisible (rackGraphButton);
- rackTitleTools.layout = [this] {
- auto r = rackTitleTools.getLocalBounds();
- rackPatternSelector.setBounds (r.removeFromLeft (rackPatternSelectorWidth).reduced (0, 3));
- r.removeFromLeft (6);
- rackFilterBox.setBounds (r.removeFromLeft (96).reduced (0, 3));
- r.removeFromLeft (4);
- swingSlider.setBounds (r.removeFromLeft (26));
- r.removeFromLeft (4);
- rackLengthBox.setBounds (r.removeFromLeft (rackLengthBoxWidth).reduced (0, 3));
- r.removeFromLeft (4);
- rackGraphButton.setBounds (r.removeFromLeft (24).reduced (0, 1));
- r.removeFromLeft (4);
- rackPianoRollButton.setBounds (r.removeFromLeft (24).reduced (0, 1));
- r.removeFromLeft (4);
- rackFollowButton.setBounds (r.removeFromLeft (24).reduced (0, 1));
- r.removeFromLeft (4);
- rackLoopButton.setBounds (r.removeFromLeft (24).reduced (0, 1));
- r.removeFromLeft (4);
- rackLoopStarterButton.setBounds (r.removeFromLeft (24).reduced (0, 1));
- };
- workspace.setTitleAccessory (Panel::channelRack, &rackTitleTools, rackTitleToolsWidth);
- workspace.onPanelMenu = [this] (Panel panel, juce::PopupMenu& menu) { addPanelMenuItems (panel, menu); };
- workspace.onFocusChanged = [this] (Panel panel) {
- refreshPanelButtons();
- // another panel took over (a click, F5..F9): the Browser's search box gives the keys back (issue #9)
- if (panel != Panel::browser)
- browser.leaveSearchBox();
- };
- workspace.onKeyInDetachedWindow = [this] (const juce::KeyPress& key) { return keyPressed (key); };
- workspace.onTitleWheel = [this] (Panel panel, const juce::MouseEvent& ev, const juce::MouseWheelDetails& wheel) {
- if (panel == Panel::channelRack && ev.mods.isShiftDown())
- selectPattern (stepPattern (engine.getSong(), (wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX) > 0.0f ? -1 : 1));
- };
- workspace.onTitleRightClick = [this] (Panel panel, const juce::MouseEvent&) {
- if (panel == Panel::channelRack)
- showPatternMenu();
- };
- workspace.onDefaultLayout = [this] { fitChannelRack (true); };
- workspace.setPersistent (persistent);
- playlist.onOpenPattern = [this] { showPanel (Panel::channelRack); };
- playlist.onOpenPianoRoll = [this] {
- // edit a channel that plays in this pattern
- const auto& song = engine.getSong();
- const auto& notes = song.patterns[(std::size_t) song.currentPattern].notes;
- const auto channel = engine.getSelectedChannel();
- if (! notes.empty() && std::none_of (notes.begin(), notes.end(), [channel] (const Note& n) { return n.channel == channel; }))
- engine.setSelectedChannel (notes.front().channel);
- openPianoRoll();
- };
- picker.onOpenPattern = [this] { showPanel (Panel::channelRack); };
- picker.onPatternMenu = [this] { makePatternMenu().showMenuAsync (juce::PopupMenu::Options().withMousePosition()); };
- picker.onNewPattern = [this] { newPatternButton.onClick(); };
- playlist.onRenamePattern = [this] (int p) { showRenamePattern (p); };
- playlist.onOpenInSampler = [this] (int channel) {
- // the audio clip's file in a new Sampler channel (to play it from notes), its settings open
- const auto& song = engine.getSong();
- if (channel < 0 || channel >= (int) song.channels.size())
- return;
- ChannelDef c;
- c.name = song.channels[(std::size_t) channel].name;
- c.instrument = InstrumentKind::sampler;
- c.samplePath = song.channels[(std::size_t) channel].samplePath;
- c.colour = song.channels[(std::size_t) channel].colour;
- const auto added = rack.addChannel (c, false);
- showPanel (Panel::channelRack);
- rack.toggleEditor (added, false);
- };
- ui::setHint (pianoRoll, tr ("Piano Roll: [LMB] add a note, drag to move [RMB] delete [Ctrl][LMB] drag to select [Ctrl][Wheel] zoom"));
- ui::setHint (playlist, tr ("Playlist: [LMB] paint the current pattern [RMB] delete [Ctrl][LMB] drag to select [Ctrl][Wheel] zoom"));
- // recent files (stored in %APPDATA%\LYNX)
- recent.setMaxNumberOfItems (12);
- recent.restoreFromString (PluginHost::settingsFolder().getChildFile ("recentes.txt").loadFileAsString());
- addAndMakeVisible (menuBar);
- for (auto* c : std::initializer_list<juce::Component*> { &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton, &playButton, &stopButton,
- &recordButton, &recordMenuButton, &patternModeButton, &songModeButton, &metronomeButton, &typingPianoButton, &countInButton, &waitInputButton,
- &tempoDisplay, &patternBox, &newPatternButton, &patternMenuButton, &pluginPickerButton, &timeDisplay,
- &songPosition, &masterVolume, &masterPitch, &perfMeter, &output, &hintBar, &tweakReadout, &workspace, &midiLight })
- {
- addAndMakeVisible (c);
- c->setMouseClickGrabsKeyboardFocus (false); // the PC keyboard stays with the main window
- }
- // the dancers of the project's dance channels (FL's Fruity Dance) over the workspace (round 165e)
- danceStage = std::make_unique<DanceStage> (engine);
- danceStage->setMouseClickGrabsKeyboardFocus (false);
- addAndMakeVisible (*danceStage);
- for (auto& b : panelButtons)
- {
- addAndMakeVisible (b);
- b.setMouseClickGrabsKeyboardFocus (false);
- b.setWantsKeyboardFocus (false);
- }
- for (auto* b : std::initializer_list<juce::Component*> { &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton, &playButton, &stopButton,
- &recordButton, &recordMenuButton, &patternModeButton, &songModeButton, &metronomeButton, &typingPianoButton, &countInButton, &waitInputButton,
- &newPatternButton, &patternMenuButton, &pluginPickerButton })
- b->setWantsKeyboardFocus (false);
- for (auto* b : { &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton, &recordMenuButton, &newPatternButton, &patternMenuButton,
- &pluginPickerButton, &metronomeButton, &typingPianoButton, &countInButton, &waitInputButton })
- b->setFlat (true);
- // a light header: every toolbar button is flat; "on" is a faint wash, in the accent for the states that
- // matter while working (playing, recording, metronome, recording options)
- {
- using namespace theme;
- const auto onWash = colour::accent.withAlpha (0.16f), onIcon = colour::accentHover;
- for (auto* b : { &playButton, &stopButton, &recordButton, &patternModeButton, &songModeButton })
- b->setFlat (true);
- playButton.setOnColour (onWash);
- playButton.setIconColourWhenOn (onIcon);
- recordButton.setOnColour (colour::record.withAlpha (0.2f));
- recordButton.setIconColourWhenOn (colour::record);
- for (auto* b : { &metronomeButton, &typingPianoButton, &countInButton, &waitInputButton, &patternModeButton, &songModeButton })
- {
- b->setOnColour (onWash);
- b->setIconColourWhenOn (onIcon);
- }
- for (auto& b : panelButtons)
- {
- b.setOnColour (colour::textPrimary.withAlpha (0.08f));
- b.setIconColourWhenOn (colour::textPrimary);
- }
- }
- quickTips = std::make_unique<ui::QuickTipWindow>();
- ui::installSliderContract();
- // FL's Last tweaked and automation recording (REA round 143): every automatable control reports its moves
- ui::onTweak = [this] (const AutomationTarget& t) { engine.noteTweaked (t); };
- // Options › Theme › Startup sound: its Play button (issue #12)
- themeui::previewStartupSound = [this] (const juce::String& path) {
- std::shared_ptr<const SampleData> sound;
- if (path.isNotEmpty() && juce::File (path).existsAsFile())
- sound = engine.getSampleLibrary().load (path);
- engine.previewSample (sound != nullptr ? sound : makeStartupSample());
- };
- // the toolbar's last-tweaked read-out opens the parameter's own menu (FL's Tools › Last tweaked; round 162d)
- tweakReadout.onClick = [this] {
- makeLastTweakedMenu (0).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&tweakReadout));
- };
- // FL's "Edit events in piano roll" (REA round 146): the channel's own parameter selects its channel
- onEditEventsInPianoRoll = [this] (const AutomationTarget& t) {
- const auto onChannel = t.kind == AutomationTargetKind::channelVolume || t.kind == AutomationTargetKind::channelPan
- || t.kind == AutomationTargetKind::channelParam;
- if (onChannel && t.index >= 0 && t.index < (int) engine.getSong().channels.size())
- engine.setSelectedChannel (t.index);
- openPianoRoll();
- pianoRoll.showEventLane (t);
- };
- PluginWindows::onGesture = [this] (const juce::AudioPluginInstance& plugin, int param, bool starting) {
- if (const auto t = engine.targetOfPlugin (plugin, param))
- {
- if (starting)
- engine.noteTweaked (*t, true);
- else
- engine.tweakReleased (*t);
- }
- };
- engine.nameAutomation = [this] (const AutomationTarget& t) { return describeAutomationTarget (engine, t).toStdString(); };
- addAndMakeVisible (gridBox); // global grid (editors)
- engine.addChangeListener (this);
- setTypingPiano (typingPiano);
- refreshRecordOptionButtons();
- refreshToolbar();
- refreshPanelButtons();
- setToolbarLayout (toolbarLayout, false); // icon sizes and row height (loaded with the UI options)
- if (persistent && toolbarLayout.uiScale != 100)
- juce::Desktop::getInstance().setGlobalScaleFactor ((float) toolbarLayout.uiScale / 100.0f);
- setControlHints();
- fittedChannelCount = (int) engine.getSong().channels.size();
- hintBar.setHint ({ idleHint(), {}, false, false });
- setWantsKeyboardFocus (true);
- installDialogTextFocus(); // dialogs open with their text field focused (round 165q)
- setSize (1180, 642);
- startTimerHz (30);
- uiTraceMonitor.start ([this, last = std::make_shared<RtStats::Snapshot>()] {
- // the audio side of the second (the watchdog thread: atomics only)
- const auto rt = engine.getRtStats().snapshot();
- const auto calls = rt.callbacks - last->callbacks;
- juce::String text;
- text << "audio: callbacks " << juce::String ((juce::int64) calls) << ", over deadline " << juce::String ((juce::int64) (rt.overBudget - last->overBudget))
- << ", late " << juce::String ((juce::int64) (rt.lateCalls - last->lateCalls)) << ", max load since start " << juce::String (rt.maxLoad * 100.0, 0)
- << "%, cpu " << juce::String (engine.getDeviceManager().getCpuUsage() * 100.0, 1) << "%";
- *last = rt;
- return text;
- });
- // new or updated plugins since the last run: an incremental scan in the background (unchanged files are
- // skipped), a few seconds after start so it doesn't compete with loading; the first run asks in the wizard
- if (persistent && setupWizardDone() && backgroundScanAtStart() && platform::testMode())
- platform::testModeLog ("background plugin scan at start");
- else if (persistent && setupWizardDone() && backgroundScanAtStart())
- juce::Timer::callAfterDelay (4000, [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr)
- safe->engine.getPluginHost().startBackgroundScan();
- });
- // the keys a secondary window (tool, plugin, channel window) leaves unused run the global shortcuts, as in FL
- setSecondaryWindowKeyHandler ([safe = juce::Component::SafePointer<MainComponent> (this)] (const juce::KeyPress& key) {
- return safe != nullptr && safe->keyFromSecondaryWindow (key);
- });
- }
- MainComponent::~MainComponent()
- {
- setSecondaryWindowKeyHandler (nullptr);
- cancelProjectLoad(); // an open in progress uses the engine from its thread
- if (sessionLock != nullptr) // a clean exit: no "LYNX did not close properly" next time
- sessionMarker.deleteFile();
- mixerinput::openAudioSettings = nullptr;
- PatcherWindows::onBrowsePluginDatabase = nullptr;
- EditorGlobals::get().onOptionsChanged = nullptr;
- PianoRollComponent::shortcutText = nullptr;
- saveUiSettings();
- workspace.saveState();
- ui::uninstallSliderContract();
- ui::onTweak = nullptr;
- themeui::previewStartupSound = nullptr;
- onEditEventsInPianoRoll = nullptr;
- PluginWindows::onGesture = nullptr;
- removeDialogTextFocus();
- engine.nameAutomation = nullptr;
- PluginWindows::closeAll(); // plugin UIs before the engine
- ParametricEqWindows::closeAll();
- closeAutomationEditors();
- closeChannelSettings();
- closeAllToolWindows(); // note tools, history, quick-add (they edit the song)
- engine.removeChangeListener (this);
- stopTimer();
- }
- void MainComponent::paint (juce::Graphics& g)
- {
- const uitrace::Scope trace ("MainComponent paint", true, g.getClipBounds());
- using namespace theme;
- g.fillAll (colour::bg1);
- // the toolbar: one band, its panels separated by hairlines
- const auto bar = juce::Rectangle<int> (0, 0, getWidth(), toolbarHeight);
- g.setColour (colour::bg3);
- g.fillRect (bar);
- g.setColour (colour::border);
- g.fillRect (bar.withHeight (1).withY (bar.getBottom() - 1));
- g.setColour (colour::border.brighter (0.08f));
- if (toolbarLayout.separators) // (the toolbar menu's "Separators")
- for (auto x : dividers)
- g.fillRect (x, bar.getY() + 12, 1, bar.getHeight() - 24);
- // play, stop and record share one quiet well
- if (! transportArea.isEmpty())
- {
- g.setColour (colour::bg2);
- g.fillRoundedRectangle (transportArea.toFloat(), radius::lg);
- g.setColour (colour::border);
- g.drawRoundedRectangle (transportArea.toFloat().reduced (0.5f), radius::lg, 1.0f);
- }
- // the hint bar sits in an inset well under the menu
- if (! hintBar.getBounds().isEmpty())
- {
- g.setColour (colour::bg1);
- g.fillRoundedRectangle (hintBar.getBounds().toFloat(), radius::md);
- }
- // the project name, beside the menus (FL's title/hint panel: the title above the hint bar)
- if (! titleArea.isEmpty())
- {
- const auto name = projectName.isNotEmpty() ? projectName : tr ("Untitled");
- g.setFont (font (type::small, true));
- g.setColour (colour::textSecondary);
- g.drawFittedText ((engine.isModified() ? juce::String ("* ") : juce::String()) + name, titleArea, juce::Justification::centredRight, 1, 0.8f);
- }
- // captions that name the snap and pattern selectors
- g.setFont (font (type::caption - 1.0f, true));
- g.setColour (colour::textDisabled);
- if (! snapLabelArea.isEmpty())
- g.drawText (tr ("SNAP"), snapLabelArea, juce::Justification::centredLeft, true);
- if (! patternLabelArea.isEmpty())
- g.drawText (tr ("PATTERN"), patternLabelArea, juce::Justification::centredLeft, true);
- }
- void MainComponent::resized()
- {
- using toolbarlayout::Group;
- dividers.clear();
- const auto bar = juce::Rectangle<int> (0, 0, getWidth(), toolbarHeight);
- auto toolbar = bar.reduced (8, 3);
- const auto row1 = toolbar.getY(), row2 = toolbar.getY() + rowHeight + 2, h = rowHeight;
- const auto big = h + 6; // transport buttons: one slim row, centred on both
- const auto bigWidth = h + 4;
- constexpr int gap = 17; // a divider and the space around it
- const auto grow = h - toolbarlayout::rowHeight (toolbarlayout::IconSize::medium); // wider panels for bigger rows
- // panel widths
- auto& lf = getLookAndFeel();
- auto measureMenu = [&] {
- int w = 0;
- for (const auto& name : getMenuBarNames())
- w += lf.getMenuBarItemWidth (menuBar, 0, name);
- return w;
- };
- menuBar.getProperties().set ("lynxTightMenuBar", false);
- int menuWidth = measureMenu();
- if (menuWidth > 390) // translated menu titles (German, Russian...): English stays as it was
- {
- menuBar.getProperties().set ("lynxTightMenuBar", true);
- menuWidth = measureMenu();
- }
- const auto modeWidth = juce::jmax (patternModeButton.getIdealWidth (h - 2), songModeButton.getIdealWidth (h - 2));
- const int tempoWidth = 90 + grow, timeWidth = 110 + grow, captionWidth = 50, gridWidth = 148;
- std::array<int, toolbarlayout::groupCount> widths {};
- widths[(std::size_t) Group::transport] = modeWidth + 8 + 3 * (bigWidth + 4) + 4 + tempoWidth + 6 + timeWidth;
- widths[(std::size_t) Group::master] = 92;
- widths[(std::size_t) Group::record] = 3 * h + 4;
- widths[(std::size_t) Group::snap] = captionWidth + gridWidth;
- widths[(std::size_t) Group::windows] = 3 * h + 4;
- widths[(std::size_t) Group::file] = 3 * h + 4;
- widths[(std::size_t) Group::meters] = 118;
- widths[(std::size_t) Group::output] = 116 + grow * 2;
- const auto room = toolbar.getWidth();
- const auto minHint = juce::jmax (menuWidth + 8, 320), maxHint = 620; // room for most hints on two lines
- auto visible = toolbarlayout::fit (toolbarLayout, widths, gap, room, minHint);
- if (! toolbarLayout.visible) // Ctrl+F11: only the menu and the hint bar, on one row
- visible.fill (false);
- panelBounds = {};
- int used = 0;
- for (int i = 0; i < toolbarlayout::groupCount; ++i)
- used += visible[(std::size_t) i] ? widths[(std::size_t) i] + gap : 0;
- const auto hintWidth = juce::jlimit (juce::jmin (minHint, juce::jmax (160, room - used)), maxHint, room - used);
- // the spare room goes before the first of the meters / output in the toolbar order (they sit on the right)
- auto spare = juce::jmax (0, room - used - hintWidth);
- auto take = [&toolbar] (int width) { return toolbar.removeFromLeft (juce::jmin (width, toolbar.getWidth())); };
- auto divide = [&] {
- take (8);
- dividers.push_back (toolbar.getX());
- take (9);
- };
- auto hide = [] (std::initializer_list<juce::Component*> components) {
- for (auto* c : components)
- {
- c->setVisible (false);
- c->setBounds ({});
- }
- };
- auto put = [] (juce::Component& c, juce::Rectangle<int> r) {
- c.setVisible (true);
- c.setBounds (r);
- };
- // a block of icon buttons, three per row on both rows
- auto grid = [&] (juce::Rectangle<int> panel, std::initializer_list<juce::Component*> buttons) {
- int i = 0;
- for (auto* b : buttons)
- {
- const auto x = panel.getX() + (i % 3) * (h + 2);
- put (*b, juce::Rectangle<int> (x, i < 3 ? row1 : row2, h, h));
- ++i;
- }
- };
- // 1. the menu (and the project name beside it) over the hint bar; always first
- if (! toolbarLayout.visible)
- {
- const auto row = toolbar.withHeight (h);
- const auto menu = row.withWidth (juce::jmin (menuWidth + 8, row.getWidth()));
- put (menuBar, menu);
- titleArea = {};
- placeHintBar (row.withTrimmedLeft (menu.getWidth() + 12).withWidth (juce::jmin (900, row.getWidth() - menu.getWidth() - 12)).reduced (0, 1));
- fixedToolbarArea = bar;
- }
- else
- {
- auto column = take (hintWidth);
- const auto menu = column.withY (row1).withHeight (h).removeFromLeft (juce::jmin (menuWidth + 8, column.getWidth()));
- put (menuBar, menu);
- titleArea = column.withY (row1).withHeight (h).withTrimmedLeft (menu.getWidth() + 12).withTrimmedRight (4);
- if (titleArea.getWidth() < 60)
- titleArea = {};
- placeHintBar (column.withY (row2).withHeight (h).reduced (0, 1));
- fixedToolbarArea = juce::Rectangle<int> (column.getX() - 4, 0, column.getWidth() + 8, toolbarHeight);
- }
- snapLabelArea = patternLabelArea = transportArea = {};
- for (const auto& entry : toolbarLayout.entries)
- {
- const auto group = entry.group;
- if (! visible[(std::size_t) group])
- {
- switch (group)
- {
- case Group::transport:
- hide ({ &patternModeButton, &songModeButton, &playButton, &stopButton, &recordButton, &tempoDisplay, &timeDisplay, &songPosition });
- break;
- case Group::master: hide ({ &masterVolume, &masterPitch }); break;
- case Group::record: hide ({ &metronomeButton, &typingPianoButton, &recordMenuButton, &countInButton, &waitInputButton, &midiLight }); break;
- case Group::snap: hide ({ &gridBox, &patternBox, &newPatternButton, &patternMenuButton }); break;
- case Group::windows:
- for (auto& b : panelButtons)
- hide ({ &b });
- hide ({ &pluginPickerButton });
- break;
- case Group::file: hide ({ &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton }); break;
- case Group::meters: hide ({ &perfMeter }); break;
- case Group::output: hide ({ &output }); break;
- case Group::count_: break;
- }
- continue;
- }
- if (toolbarlayout::rightAligned (group) && spare > 0)
- {
- take (spare);
- spare = 0;
- }
- divide();
- auto panel = take (widths[(std::size_t) group]);
- panelBounds[(std::size_t) group] = juce::Rectangle<int> (panel.getX() - 5, 0, panel.getWidth() + 10, toolbarHeight);
- switch (group)
- {
- case Group::transport: // Pattern/Song switch, play, stop, record, tempo, time display with the song position under it
- {
- auto mode = panel.removeFromLeft (modeWidth);
- put (patternModeButton, mode.withY (row1).withHeight (h).reduced (0, 1));
- put (songModeButton, mode.withY (row2).withHeight (h).reduced (0, 1));
- panel.removeFromLeft (8);
- const auto y = panel.getCentreY() - big / 2;
- transportArea = juce::Rectangle<int> (panel.getX(), y, 3 * bigWidth + 2 * 4, big);
- for (auto* b : { &playButton, &stopButton, &recordButton })
- {
- put (*b, juce::Rectangle<int> (panel.getX(), y, bigWidth, big).reduced (0, 3));
- panel.removeFromLeft (bigWidth + 4);
- }
- panel.removeFromLeft (4);
- const auto displays = juce::Rectangle<int> (panel.getX(), row1 + 3, panel.getWidth(), 2 * h - 6);
- const auto displayHeight = displays.getHeight() - 10;
- put (tempoDisplay, displays.withWidth (tempoWidth).withHeight (displayHeight));
- put (timeDisplay, displays.withTrimmedLeft (tempoWidth + 6).withWidth (timeWidth).withHeight (displayHeight));
- put (songPosition, displays.withTop (displays.getY() + displayHeight + 1).withWidth (tempoWidth + 6 + timeWidth));
- break;
- }
- case Group::master: // master volume over master pitch
- put (masterVolume, panel.withY (row1).withHeight (h).reduced (0, 1));
- put (masterPitch, panel.withY (row2).withHeight (h).reduced (0, 1));
- break;
- case Group::record: // metronome, count-in and wait for input over "what to record", typing piano and the MIDI light
- grid (panel, { &metronomeButton, &countInButton, &waitInputButton, &recordMenuButton, &typingPianoButton, &midiLight });
- break;
- case Group::snap: // global snap over the pattern selector, each with its name
- {
- auto first = juce::Rectangle<int> (panel.getX(), row1, panel.getWidth(), h);
- snapLabelArea = first.removeFromLeft (captionWidth);
- put (gridBox, first.reduced (0, 1));
- auto second = juce::Rectangle<int> (panel.getX(), row2, panel.getWidth(), h);
- patternLabelArea = second.removeFromLeft (captionWidth);
- put (patternMenuButton, second.removeFromRight (h));
- put (newPatternButton, second.removeFromRight (h));
- second.removeFromRight (2);
- put (patternBox, second.reduced (0, 1));
- break;
- }
- case Group::windows: // the windows and the plugin picker
- grid (panel, { &panelButtons[(std::size_t) Panel::playlist], &panelButtons[(std::size_t) Panel::channelRack],
- &panelButtons[(std::size_t) Panel::pianoRoll], &panelButtons[(std::size_t) Panel::mixer],
- &panelButtons[(std::size_t) Panel::browser], &pluginPickerButton });
- break;
- case Group::file: // new, open, save over export, undo, redo
- grid (panel, { &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton });
- break;
- case Group::meters: put (perfMeter, panel.withY (row1).withHeight (2 * h + 2)); break;
- case Group::output: put (output, panel.withY (row1).withHeight (2 * h + 2)); break;
- case Group::count_: break;
- }
- }
- // the toolbar's edit mode: its overlay over the toolbar, and its tray between the toolbar and the windows
- const auto tray = toolbarEditor != nullptr ? toolbar::EditOverlay::trayHeight : 0;
- if (toolbarEditor != nullptr)
- {
- toolbarEditor->setBounds (0, 0, getWidth(), toolbarHeight + tray);
- toolbarEditor->setToolbarHeight (toolbarHeight);
- toolbarEditor->toFront (false);
- }
- auto below = getLocalBounds().withTrimmedTop (toolbarHeight + tray);
- if (updateBar.isVisible())
- updateBar.setBounds (below.removeFromTop (updater::UpdateBar::height));
- workspace.setBounds (below);
- if (danceStage != nullptr)
- {
- danceStage->setBounds (getLocalBounds());
- danceStage->toFront (false);
- }
- if (setupOverlay != nullptr)
- {
- setupOverlay->setBounds (getLocalBounds());
- setupOverlay->toFront (false);
- }
- }
- // --- toolbar layout ------------------------------------------------------------------------------
- void MainComponent::setToolbarLayout (const toolbarlayout::Layout& layout, bool save)
- {
- const auto scaleChanged = layout.uiScale != toolbarLayout.uiScale;
- toolbarLayout = layout;
- const auto size = toolbarLayout.iconSize;
- rowHeight = toolbarlayout::rowHeight (size);
- toolbarHeight = toolbarLayout.visible ? 2 * rowHeight + 8 : rowHeight + 6;
- const auto fraction = toolbarlayout::iconFraction (size), maxPx = toolbarlayout::iconMaxPx (size);
- for (auto* b : { &newButton, &openButton, &saveButton, &exportButton, &undoButton, &redoButton, &recordMenuButton, &newPatternButton,
- &patternMenuButton, &pluginPickerButton, &metronomeButton, &typingPianoButton, &countInButton, &waitInputButton })
- b->setIconSizing (fraction, maxPx);
- for (auto& b : panelButtons)
- b.setIconSizing (fraction, maxPx);
- for (auto* b : { &playButton, &stopButton, &recordButton }) // solid transport glyphs, a little smaller than the line icons
- b->setIconSizing (0.5f, maxPx - 2.0f);
- ToolStrip::iconSize = size;
- pianoRoll.resized();
- playlist.resized();
- if (save && scaleChanged)
- {
- juce::Desktop::getInstance().setGlobalScaleFactor ((float) toolbarLayout.uiScale / 100.0f);
- // the windows grow with the zoom: keep their title bars and close buttons on the screen (round 163)
- juce::Timer::callAfterDelay (200, [] { fitAllWindowsOnScreen(); });
- }
- resized();
- repaint();
- if (toolbarEditor != nullptr)
- toolbarEditor->layoutChanged();
- if (save)
- saveUiSettings();
- }
- juce::PopupMenu MainComponent::makeToolbarMenu()
- {
- using toolbarlayout::Group;
- juce::PopupMenu menu;
- // FL's toolbar menu (Edit, Separators, Hide, Presets), then LYNX's direct switches per panel
- menu.addSectionHeader (tr ("Toolbar"));
- menu.addItem (tr ("Edit toolbar (drag panels to move, add or remove them)"), true, toolbarEditor != nullptr,
- [this] { setToolbarEditing (toolbarEditor == nullptr); });
- menu.addItem (tr ("Separators"), true, toolbarLayout.separators, [this] {
- auto layout = toolbarLayout;
- layout.separators = ! layout.separators;
- setToolbarLayout (layout);
- });
- menu.addItem (tr ("Hide the toolbar panels") + shortcutText ("view.toolbar"), true, ! toolbarLayout.visible, [this] {
- auto layout = toolbarLayout;
- layout.visible = ! layout.visible;
- setToolbarLayout (layout);
- });
- juce::PopupMenu presets;
- const auto current = toolbarlayout::matchingPreset (toolbarLayout);
- for (int p = 0; p < toolbarlayout::presetCount; ++p)
- presets.addItem (tr (toolbarlayout::presetName ((toolbarlayout::Preset) p)), true, current == p, [this, p] {
- auto layout = toolbarlayout::applyPreset (toolbarLayout, (toolbarlayout::Preset) p);
- layout.visible = true;
- setToolbarLayout (layout);
- });
- menu.addSubMenu (tr ("Presets"), presets);
- menu.addSectionHeader (tr ("Panels"));
- for (const auto& entry : toolbarLayout.entries)
- {
- const auto group = entry.group;
- menu.addItem (tr (toolbarlayout::groupName (group)), true, entry.shown, [this, group] {
- auto layout = toolbarLayout;
- layout.setShown (group, ! layout.isShown (group));
- layout.visible = true;
- setToolbarLayout (layout);
- });
- }
- menu.addSeparator();
- juce::PopupMenu sizes;
- const char* sizeNames[] = { TR_NOOP ("Small icons"), TR_NOOP ("Medium icons"), TR_NOOP ("Large icons") };
- for (int i = 0; i < 3; ++i)
- sizes.addItem (tr (sizeNames[i]), true, (int) toolbarLayout.iconSize == i, [this, i] {
- auto layout = toolbarLayout;
- layout.iconSize = (toolbarlayout::IconSize) i;
- setToolbarLayout (layout);
- });
- menu.addSubMenu (tr ("Icon size"), sizes);
- juce::PopupMenu scales;
- for (auto percent : toolbarlayout::uiScales)
- scales.addItem (juce::String (percent) + "%", true, toolbarLayout.uiScale == percent, [this, percent] {
- auto layout = toolbarLayout;
- layout.uiScale = percent;
- setToolbarLayout (layout);
- });
- menu.addSubMenu (tr ("UI scale"), scales);
- menu.addSeparator();
- menu.addItem (tr ("Customize toolbar..."), [this] { showCustomizeToolbar(); });
- menu.addItem (tr ("Reset toolbar to default"), ! toolbarLayout.isDefault(), false, [this] {
- setToolbarLayout (toolbarlayout::Layout::makeDefault());
- });
- return menu;
- }
- void MainComponent::setToolbarEditing (bool editing)
- {
- if (editing == (toolbarEditor != nullptr))
- return;
- if (! editing)
- {
- removeChildComponent (toolbarEditor.get());
- toolbarEditor.reset();
- resized();
- repaint();
- return;
- }
- if (! toolbarLayout.visible) // editing shows the panels
- {
- auto layout = toolbarLayout;
- layout.visible = true;
- setToolbarLayout (layout);
- }
- toolbar::EditOverlay::Host host;
- host.layout = [this] { return toolbarLayout; };
- host.setLayout = [this] (const toolbarlayout::Layout& layout) { setToolbarLayout (layout); };
- host.panels = [this] { return panelBounds; };
- host.fixedArea = [this] { return fixedToolbarArea; };
- host.snapshot = [this] (juce::Rectangle<int> area) {
- // the panel as it looks, without the edit overlay on it
- if (toolbarEditor != nullptr)
- toolbarEditor->setVisible (false);
- auto image = createComponentSnapshot (area, true);
- if (toolbarEditor != nullptr)
- toolbarEditor->setVisible (true);
- return image;
- };
- host.done = [safe = juce::Component::SafePointer<MainComponent> (this)] {
- // after the click that asked for it
- juce::MessageManager::callAsync ([safe] {
- if (safe != nullptr)
- safe->setToolbarEditing (false);
- });
- };
- toolbarEditor = std::make_unique<toolbar::EditOverlay> (std::move (host), toolbarHeight);
- addAndMakeVisible (*toolbarEditor);
- resized();
- repaint();
- if (isShowing())
- toolbarEditor->grabKeyboardFocus();
- }
- void MainComponent::flUndo()
- {
- if (alternateUndo)
- undoRedo (false);
- else
- undoRedo (engine.canRedo()); // something undone: Ctrl+Z redoes the next step (FL: "undo/redo on the same shortcut")
- }
- void MainComponent::undoRedo (bool redo)
- {
- // FL says in the hint bar what was undone and the undo level ("Undone: ... Level 2/3")
- if (redo ? ! engine.canRedo() : ! engine.canUndo())
- return;
- const auto label = engine.getHistoryLabel (engine.getHistoryPosition() + (redo ? 1 : 0));
- if (redo)
- engine.redo();
- else
- engine.undo();
- ui::Hint h;
- h.text = (redo ? tr ("Redone: {0}", { tr (label.text, { juce::String::fromUTF8 (label.arg.c_str()) }) })
- : tr ("Undone: {0}", { tr (label.text, { juce::String::fromUTF8 (label.arg.c_str()) }) }));
- h.value = tr ("Level {0}/{1}", { juce::String (engine.getHistoryPosition() + 1), juce::String (engine.getHistorySize()) });
- ui::postHint (h, 2500);
- }
- ui::Hint MainComponent::hintAt (juce::Point<int> p)
- {
- ui::Hint h;
- if (p.y < toolbarHeight)
- {
- h.text = tr ("Toolbar: [RMB] toolbar menu (edit the panels: move, add, remove; presets; hide with Ctrl+F11)");
- h.hasMenu = true;
- }
- return h;
- }
- void MainComponent::showToolbarMenu()
- {
- makeToolbarMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- }
- void MainComponent::showCustomizeToolbar()
- {
- auto panel = std::make_unique<toolbar::CustomizePanel> (toolbarLayout);
- panel->onChange = [safe = juce::Component::SafePointer<MainComponent> (this)] (const toolbarlayout::Layout& layout) {
- if (safe != nullptr)
- safe->setToolbarLayout (layout);
- };
- juce::DialogWindow::LaunchOptions options;
- options.content.setOwned (fitContentToScreen (std::move (panel)).release());
- options.dialogTitle = tr ("Customize toolbar");
- options.dialogBackgroundColour = theme::colour::bg2;
- options.useNativeTitleBar = true;
- options.resizable = false;
- options.escapeKeyTriggersCloseButton = true;
- if (auto* dialog = options.launchAsync())
- keepAboveMainWindow (*dialog);
- }
- void MainComponent::mouseDown (const juce::MouseEvent& e)
- {
- // a right-click on the toolbar's background (between the panels): show / hide groups, icon size, customize
- if (e.mods.isPopupMenu() && e.y < toolbarHeight)
- showToolbarMenu();
- }
- juce::Rectangle<int> MainComponent::getToolStripAreaForSnapshot (bool playlistStrip)
- {
- auto& editor = playlistStrip ? (juce::Component&) playlist : (juce::Component&) pianoRoll;
- if (! editor.isVisible() || editor.getParentComponent() == nullptr || ! isParentOf (&editor))
- return {};
- const auto area = getLocalArea (&editor, editor.getLocalBounds());
- return area.withHeight (40).withWidth (juce::jmin (area.getWidth(), 900)).getIntersection (getLocalBounds());
- }
- // --- keys --------------------------------------------------------------------------------------
- keys::Context MainComponent::focusContext() const
- {
- switch (workspace.getFocused())
- {
- case Panel::playlist: return keys::Context::playlist;
- case Panel::channelRack: return keys::Context::channelRack;
- case Panel::pianoRoll: return keys::Context::pianoRoll;
- case Panel::mixer: return keys::Context::mixer;
- case Panel::browser: return keys::Context::browser;
- }
- return keys::Context::global;
- }
- void MainComponent::dragOperationStarted (const juce::DragAndDropTarget::SourceDetails&)
- {
- // a drop on a window above this one (the Sampler's waveform, a plugin...) lands there, not on the panel under it
- matchWindowOrderToScreen();
- }
- bool MainComponent::keyPressed (const juce::KeyPress& key)
- {
- const auto chord = chordFromKeyPress (key);
- // 1. the typing piano (its keys win over plain-letter shortcuts while it is on)
- if (keys::KeyMap::playsNote (chord, typingPiano))
- {
- const auto note = keys::typingPianoNote (chord.key);
- if (! heldKeys.hasTag (key.getKeyCode())) // key repeat: the note is already sounding
- for (auto c : engine.getSelectedChannels())
- heldKeys.press (c, note, 0.8f, key.getKeyCode());
- return true;
- }
- // 2. a key the user gave an action himself (Options › Shortcuts) wins over the panels' built-in keys
- // (issue #12: Metronome on 'C' did nothing while the Playlist, whose Knife is 'C', had the focus)
- if (const auto own = keyMap.findUserBound (chord, focusContext(), typingPiano); ! own.empty() && runAction (own))
- return true;
- // 3. the focused panel's own keys
- const auto focused = workspace.getFocused();
- const auto panelShown = workspace.isPanelVisible (focused);
- if (panelShown && focused == Panel::pianoRoll && pianoRoll.handleKey (key))
- return true;
- if (panelShown && focused == Panel::playlist && playlist.handleKey (key))
- return true;
- // 4. the key map
- const auto action = keyMap.find (chord, focusContext(), typingPiano);
- return ! action.empty() && runAction (action);
- }
- bool MainComponent::keyFromSecondaryWindow (const juce::KeyPress& key)
- {
- // (round 165q / issue #12) a text field keeps its typing keys; the rest runs the global actions
- const auto typingIntoText = dynamic_cast<juce::TextEditor*> (juce::Component::getCurrentlyFocusedComponent()) != nullptr;
- const auto action = keyMap.findFromSecondaryWindow (chordFromKeyPress (key), typingIntoText, typingPiano);
- return ! action.empty() && runAction (action);
- }
- bool MainComponent::runAction (const std::string& id)
- {
- auto is = [&id] (const char* name) { return id == name; };
- if (id == "rack.follow")
- {
- auto& g = EditorGlobals::get();
- g.setFollowingView (EditorGlobals::FollowView::channelRack, ! g.isFollowingView (EditorGlobals::FollowView::channelRack));
- rackFollowButton.setToggleState (g.isFollowingView (EditorGlobals::FollowView::channelRack), juce::dontSendNotification);
- return true;
- }
- if (id.rfind ("pianoRoll.", 0) == 0 && pianoRoll.runKeyAction (id)) return true; // tools, slide, channel keys
- if (id.rfind ("playlist.tool.", 0) == 0 && playlist.runKeyAction (id)) return true;
- if (is ("transport.playStop")) playStop();
- else if (is ("transport.pause")) playPause();
- else if (is ("transport.playFromStart")) playFromStart();
- else if (is ("transport.toggleMode")) toggleMode();
- else if (is ("transport.nextMarker")) engine.jumpToNextMarker (true);
- else if (is ("transport.previousMarker")) engine.jumpToNextMarker (false);
- else if (is ("view.typingPiano")) setTypingPiano (! typingPiano);
- else if (is ("view.toolbar"))
- {
- auto layout = toolbarLayout;
- layout.visible = ! layout.visible;
- setToolbarLayout (layout);
- }
- else if (is ("panel.playlist")) togglePanel (Panel::playlist);
- else if (is ("panel.channelRack")) togglePanel (Panel::channelRack);
- else if (is ("panel.pianoRoll"))
- {
- togglePanel (Panel::pianoRoll);
- if (workspace.isPanelVisible (Panel::pianoRoll))
- pianoRoll.scrollToNotes();
- }
- else if (is ("panel.browser")) togglePanel (Panel::browser);
- else if (is ("panel.mixer")) togglePanel (Panel::mixer);
- else if (is ("panel.maximisePlaylist"))
- {
- workspace.toggleMaximised (Panel::playlist);
- refreshPanelButtons();
- }
- else if (is ("pattern.next")) selectPattern (stepPattern (engine.getSong(), 1));
- else if (is ("pattern.previous")) selectPattern (stepPattern (engine.getSong(), -1));
- else if (is ("pattern.nextEmpty")) nextEmptyPattern();
- else if (is ("pattern.firstEmpty")) { engine.editSong ([] (Song& s) { gotoFirstEmptyPattern (s); }); showRenamePattern (engine.getSong().currentPattern); }
- else if (is ("pattern.nextEmptyNoName")) engine.editSong ([] (Song& s) { gotoNextEmptyPattern (s); });
- else if (is ("pattern.delete")) deleteCurrentPattern();
- else if (is ("pattern.rename")) showRenamePattern (engine.getSong().currentPattern);
- else if (is ("pattern.insert")) insertPatternHere();
- else if (is ("pattern.clone")) clonePatternNow();
- else if (is ("pattern.moveUp")) movePatternNow (-1);
- else if (is ("pattern.moveDown")) movePatternNow (1);
- else if (id.rfind ("pattern.select", 0) == 0) selectPattern (std::stoi (id.substr (14)) - 1);
- else if (is ("panel.quickAdd"))
- {
- // FL's F8 opens the plugin picker or closes it (FLEngine 0xebf510, round 167o)
- if (auto* open = findToolWindow ("quickadd"))
- closeToolWindowOf (*open->getContentComponent());
- else
- showQuickAdd();
- }
- else if (is ("edit.history")) showHistory();
- else if (is ("browser.search"))
- {
- showPanel (Panel::browser);
- browser.focusSearch();
- }
- else if (is ("transport.record")) toggleRecording();
- else if (is ("record.quickAudio")) quickRecordAudio();
- else if (is ("transport.metronome"))
- {
- engine.getTransport().metronome.store (! engine.getTransport().metronome.load());
- refreshModeButton();
- }
- else if (is ("record.countIn"))
- {
- auto o = engine.getRecordOptions();
- o.countInBars = o.countInBars > 0 ? 0 : 1;
- engine.setRecordOptions (o);
- refreshRecordOptionButtons();
- }
- else if (is ("record.waitForInput"))
- {
- auto o = engine.getRecordOptions();
- o.waitForInput = ! o.waitForInput;
- engine.setRecordOptions (o);
- refreshRecordOptionButtons();
- }
- else if (is ("rack.graphEditor")) rack.toggleGraphLanes();
- else if (is ("rack.pianoRollView"))
- {
- rack.setPianoRollView (! rack.isPianoRollView());
- saveUiSettings();
- }
- else if (is ("view.audioEditor")) openAudioEditorForSelection();
- else if (is ("view.tempoTapper")) openTempoTapper (engine);
- else if (is ("view.sampleBrowser")) toggleSampleBrowser();
- else if (is ("view.pluginDatabase"))
- {
- showPanel (Panel::browser);
- browser.showPluginDatabase();
- }
- else if (is ("view.midiSettings") || is ("view.projectInfo"))
- {
- // FL's F10 / F11 (round 167o, issue #23): the same key closes Settings showing that page; on another page it
- // switches in place
- const auto page = is ("view.midiSettings") ? SettingsPage::midi : SettingsPage::info;
- const auto shown = shownSettingsPage();
- switch (keys::settingsKeyPress (shown >= 0, shown, (int) page))
- {
- case keys::SettingsKey::close: closeSettings(); break;
- case keys::SettingsKey::switchPage: switchSettingsPage (page); break;
- case keys::SettingsKey::open: openSettings ((int) page); break;
- }
- }
- else if (is ("view.closeUnfocusedWindows")) closeUnfocusedWindows();
- else if (is ("view.touchKeyboard")) toggleTouchKeyboard (engine);
- else if (is ("view.closePluginWindows") || is ("view.closeWindows"))
- {
- PluginWindows::closeAll();
- ParametricEqWindows::closeAll(); // every native effect / controller editor
- if (is ("view.closeWindows")) // FL's F12: the editors and tool windows too (LYNX's docked panels stay)
- {
- closeAutomationEditors();
- closeChannelSettings();
- closeAllToolWindows();
- closeHelp();
- }
- }
- else if (is ("rack.groupSelected")) rack.groupSelected();
- else if (is ("rack.rotateLeft")) rack.rotateSelected (-1);
- else if (is ("rack.rotateRight")) rack.rotateSelected (1);
- else if (is ("browser.previous")) browser.step (-1, false);
- else if (is ("browser.next")) browser.step (1, false);
- else if (is ("browser.swapPrevious")) browser.step (-1, true);
- else if (is ("browser.swapNext")) browser.step (1, true);
- else if (is ("browser.load")) browser.loadSelected();
- else if (is ("browser.closeFolder")) browser.openFolder (false);
- else if (is ("browser.openFolder")) browser.openFolder (true);
- else if (is ("browser.rename"))
- {
- if (! browser.renameSelectedPlugin()) // not a plugin: F2's global action (rename the pattern)
- showRenamePattern (engine.getSong().currentPattern);
- }
- else if (id.rfind ("pianoRoll.", 0) == 0) return pianoRoll.runAction (id);
- else if (id.rfind ("playlist.", 0) == 0) return playlist.runAction (id);
- else if (id.rfind ("mixer.", 0) == 0) return mixer.runAction (id);
- else if (is ("file.new")) newProject();
- else if (is ("file.open")) chooseFileToOpen();
- else if (is ("file.save")) save (false);
- else if (is ("file.saveAs")) save (true);
- else if (is ("file.saveNewVersion")) saveNewVersion();
- else if (is ("file.export")) exportAudio();
- else if (is ("file.exportMp3")) exportAudio (1);
- else if (is ("file.exportMidi")) exportMidiFile();
- else if (is ("edit.undo")) flUndo();
- else if (is ("edit.undoBackwards")) undoRedo (false);
- else if (is ("edit.redo")) undoRedo (true);
- else if (is ("help.shortcuts"))
- {
- if (helpWindow != nullptr) // F1 again closes the sheet (issue #23)
- closeHelp();
- else
- showHelp();
- }
- else if (is ("rack.selectPrevious")) rack.selectRelative (-1, false);
- else if (is ("rack.selectNext")) rack.selectRelative (1, false);
- else if (is ("rack.extendUp")) rack.selectRelative (-1, true);
- else if (is ("rack.extendDown")) rack.selectRelative (1, true);
- else if (is ("rack.moveUp")) rack.moveSelected (-1);
- else if (is ("rack.moveDown")) rack.moveSelected (1);
- else if (is ("rack.selectAll")) rack.selectAll();
- else if (is ("rack.clone")) rack.cloneSelected();
- else if (is ("rack.deleteSelected")) rack.deleteSelected();
- else if (is ("rack.sendToInserts")) rack.sendSelectedToInserts();
- else if (id.rfind ("rack.mute", 0) == 0) rack.toggleMute (std::stoi (id.substr (9)) - 1);
- else if (id.rfind ("rack.solo", 0) == 0) rack.solo (std::stoi (id.substr (9)) - 1);
- else
- return false;
- return true;
- }
- bool MainComponent::keyStateChanged (bool)
- {
- // JUCE has no per-key "keyReleased"; check which held keys were released (each held note remembers its
- // channel and key, so the selection changing meanwhile can't leave one sounding)
- std::vector<int> released;
- heldKeys.forEachTag ([&released] (int code) {
- if (! juce::KeyPress::isKeyCurrentlyDown (code))
- released.push_back (code);
- });
- for (auto code : released)
- heldKeys.releaseTag (code);
- return false;
- }
- juce::String MainComponent::shortcutText (const char* actionId) const
- {
- const auto& chords = keyMap.chordsFor (actionId);
- return chords.empty() ? juce::String() : "\t" + juce::String (keys::toString (chords.front()));
- }
- void MainComponent::setTypingPiano (bool on)
- {
- typingPiano = on;
- EditorGlobals::get().typingPiano = on; // the editors' single-letter tool keys only work while it is off
- typingPianoButton.setToggleState (on, juce::dontSendNotification);
- typingPianoButton.setTooltip ((on ? tr ("Typing keyboard as a piano: on (Z..M and Q..P play the selected channels)")
- : tr ("Typing keyboard as a piano: off (letter and number keys are shortcuts)"))
- + juce::String (" (") + juce::String (keys::toString (keyMap.chordsFor ("view.typingPiano").empty() ? keys::Chord {}
- : keyMap.chordsFor ("view.typingPiano").front()))
- + ")");
- // release anything still sounding from the keyboard
- heldKeys.releaseAll();
- }
- void MainComponent::loadKeyMap()
- {
- keyMap.resetToDefaults();
- const auto file = PluginHost::settingsFolder().getChildFile ("keys.json");
- if (file.existsAsFile())
- {
- std::vector<std::string> errors;
- if (! keyMap.loadJson (file.loadFileAsString().toStdString(), &errors))
- juce::Logger::writeToLog ("keys.json is not a JSON object; using the default keys");
- for (const auto& e : errors)
- juce::Logger::writeToLog ("keys.json: " + juce::String (e));
- }
- auto keyOf = [this] (const std::string& id) {
- const auto& chords = keyMap.chordsFor (id);
- return chords.empty() ? juce::String() : juce::String (keys::toString (chords.front()));
- };
- pianoRoll.refreshToolKeys (keyOf);
- playlist.refreshToolKeys (keyOf);
- }
- // --- Browsers ------------------------------------------------------------------------------------
- // The main Browser and the separate Sample browser window (round 163) act on the project the same way.
- void MainComponent::connectBrowser (BrowserComponent& b)
- {
- b.onOpenProject = [this] (const juce::File& file) { confirmDiscard ([this, file] { openFile (file); }); };
- b.onLoadIntoChannel = [this] (const juce::File& file) { return rack.loadSampleIntoSelected (file); };
- b.onOpenMixerPreset = [this] (const juce::File& file) {
- if (! mixerpresets::isMixerPreset (file))
- return false;
- if (! mixer.loadPresetOnSelection (file))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Open mixer track state"),
- tr ("This file is not a mixer track state LYNX SHARE can read."));
- return true;
- };
- // the Browser's "Current project" items (REA_rodada115)
- b.onOpenPattern = [this] (int pattern) {
- selectPattern (pattern);
- openPianoRoll();
- };
- b.onPatternMenu = [this] (int pattern) {
- selectPattern (pattern);
- makePatternMenu().showMenuAsync (juce::PopupMenu::Options().withMousePosition());
- };
- b.onOpenChannel = [this] (int channel) {
- engine.setSelectedChannel (channel);
- rack.toggleEditor (channel, true);
- };
- b.onOpenEffect = [this] (int track, int slot) {
- showPanel (Panel::mixer);
- mixer.openSlotEditor (track, slot);
- };
- b.onShowInsert = [this] (int track) {
- showPanel (Panel::mixer);
- mixer.selectTrack (track);
- };
- b.onOpenAutomation = [this] (int automation) { openAutomationEditor (engine, automation); };
- // the Browser's Plugin database (round 142): the same targets as the quick-add palette
- b.onAddInstrument = [this] (ChannelDef c) {
- if (PatcherWindows::takeInstrumentFromBrowser (c)) // a Patcher's Add plugin › Browse plugin database (round 162)
- return;
- rack.addChannel (std::move (c), true);
- showPanel (Panel::channelRack);
- };
- b.onAddEffect = [this] (EffectSlot slot) {
- if (PatcherWindows::takeEffectFromBrowser (slot))
- return;
- if (! mixer.addEffectToSelected (std::move (slot)))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Plugin database"),
- tr ("The selected insert has no free effect slot."));
- else
- showPanel (Panel::mixer);
- };
- b.onPreviewVolumeChanged = [this] { saveUiSettings(); };
- b.onSendToPlaylist = [this] (const juce::File& file) {
- playlist.addAudioClipAtPlayhead (file);
- showPanel (Panel::playlist);
- };
- b.onToggleSampleBrowser = [this] { toggleSampleBrowser(); };
- }
- void MainComponent::toggleSampleBrowser()
- {
- if (auto* w = findToolWindow ("sampleBrowser"))
- {
- w->closeButtonPressed(); // (hidden, then deleted: remembered as closed)
- return;
- }
- openSampleBrowser();
- }
- void MainComponent::openSampleBrowser()
- {
- auto* window = openToolWindow (BrowserComponent::makeSampleBrowserContent (engine, [this] (BrowserComponent& b) { connectBrowser (b); }),
- tr ("Sample browser"), "sampleBrowser");
- if (window == nullptr)
- return;
- window->setResizable (true, false);
- window->setResizeLimits (240, 260, 4000, 4000);
- const auto saved = BrowserComponent::sampleBrowserBounds();
- const auto area = juce::Desktop::getInstance().getDisplays().getTotalBounds (true);
- if (saved.getWidth() >= 240 && saved.getHeight() >= 260 && area.intersects (saved))
- window->setBounds (saved);
- else if (auto* top = getTopLevelComponent())
- window->setBounds (top->getScreenBounds().getRight() - 360, top->getScreenY() + 80, 340, juce::jmax (400, top->getHeight() - 160));
- }
- // --- UI options ----------------------------------------------------------------------------------
- juce::File MainComponent::uiSettingsFile() const
- {
- return PluginHost::settingsFolder().getChildFile ("ui-options.txt");
- }
- void MainComponent::loadUiSettings()
- {
- juce::StringArray lines;
- lines.addLines (uiSettingsFile().loadFileAsString());
- // the sound in FL's order (0.1.20) wins over the old key, wherever each line is
- const auto flMetronomeSound = std::any_of (lines.begin(), lines.end(), [] (const juce::String& l) { return l.trim().startsWith ("metronomeSoundFl"); });
- for (const auto& line : lines)
- {
- const auto key = line.upToFirstOccurrenceOf ("=", false, false).trim();
- const auto on = line.fromFirstOccurrenceOf ("=", false, false).trim() == "1";
- if (key == "typingPiano")
- typingPiano = on;
- else if (key == "keepEditorsOpen")
- ChannelRackComponent::keepEditorsOpen = on;
- else if (key == "selFirstChanPatChanges")
- ChannelRackComponent::selectFirstChannelWithNotes = on;
- else if (key == "alternateUndo")
- alternateUndo = on;
- else if (key == "waveSpectral") // ("waveColours", the old spectral-by-default key, is ignored)
- ui::WaveformCache::spectral = on;
- else if (key == "pluginStyle") // "Automatic" or a style forced on every plugin
- {
- const auto v = line.fromFirstOccurrenceOf ("=", false, false).trim();
- skin::setForcedStyle (v.equalsIgnoreCase ("Automatic") || v.isEmpty() ? -1 : (int) skin::styleFromName (v));
- }
- else if (key == "pluginStyleOverrides")
- skin::overridesFromString (line.fromFirstOccurrenceOf ("=", false, false).trim());
- else if (key == "reducedEffects")
- skin::setReducedEffects (on);
- else if (key == "waveStereo")
- ui::WaveformCache::stereo = on;
- else if (key == "noteNames")
- notenames::currentStyle.store (juce::jlimit (0, 2, line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue()));
- else if (key == "noteFlats")
- notenames::currentFlats.store (on);
- else if (key == "rememberSeek")
- EditorGlobals::get().rememberSeek = on;
- else if (key == "followPlaylist" || key == "followPianoRoll")
- EditorGlobals::get().setFollowing (key == "followPianoRoll", on, false);
- else if (key == "followChannelRack" || key == "followAudioEditor")
- EditorGlobals::get().setFollowingView (key == "followChannelRack" ? EditorGlobals::FollowView::channelRack
- : EditorGlobals::FollowView::audioEditor, on, false);
- else if (key == "scopeMode")
- toolbar::OutputMonitor::mode = juce::jlimit (0, toolbar::OutputMonitor::modeCount - 1,
- line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "toolbarGroups")
- toolbarLayout.orderFromString (line.fromFirstOccurrenceOf ("=", false, false).trim().toStdString());
- else if (key == "toolbarIcons")
- toolbarLayout.iconSize = toolbarlayout::Layout::iconSizeFromString (line.fromFirstOccurrenceOf ("=", false, false).trim().toStdString());
- else if (key == "toolbarSeparators")
- toolbarLayout.separators = on;
- else if (key == "toolbarVisible")
- toolbarLayout.visible = on;
- else if (key == "menuDensity")
- theme::menus::setCompact (line.fromFirstOccurrenceOf ("=", false, false).trim() != "comfortable");
- else if (key == "uiScale")
- toolbarLayout.uiScale = toolbarlayout::clampScale (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "editPatternsIn")
- PlaylistComponent::editPatternsIn = juce::jlimit (0, 2, line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "autosaveMinutes")
- autosaveMinutes = prefs::clampAutosaveMinutes (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "askUnusedRecordings")
- askUnusedRecordings = on;
- else if (key == "autosaveKeep")
- autosaveKeep = prefs::clampAutosaveKeep (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "metronomeSound" && ! flMetronomeSound) // (before 0.1.20: 0 LYNX click, 1..5 hi-hat..pulse)
- engine.getTransport().metronomeSound.store (metronome::soundFromLegacy (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue()));
- else if (key == "metronomeSoundFl") // FL's order: 0 Hi-hat, 1 Tick, 2 Beep, 3 Cowbell, 4 Pulse
- engine.getTransport().metronomeSound.store (metronome::clampSound (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue()));
- else if (key == "metronomeTrack")
- engine.getTransport().metronomeTrack.store (juce::jlimit (0, maxMixerTracks - 1, line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue()));
- else if (key == "playTruncatedOnTransport")
- engine.getTransport().playTruncatedOnTransport.store (on);
- else if (key == "resetPluginsOnTransport")
- engine.getTransport().resetPluginsOnTransport.store (on);
- else if (key == "metronomeVolume")
- engine.getTransport().metronomeVolume.store ((float) controls::clampUtilityVolume (line.fromFirstOccurrenceOf ("=", false, false).trim().getDoubleValue()));
- else if (key == "previewVolume")
- engine.setPreviewVolume (line.fromFirstOccurrenceOf ("=", false, false).trim().getDoubleValue());
- else if (key == "editorVolume")
- engine.setEditorVolume (line.fromFirstOccurrenceOf ("=", false, false).trim().getDoubleValue());
- else if (key == "rackPianoRollView")
- rack.setPianoRollView (on);
- else if (key == "undoLevels")
- engine.setUndoLevels (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else if (key == "askWhatToRecord" || key == "recordNotes" || key == "recordAudio" || key == "recordStartsPlayback" || key == "disarmOnStop"
- || key == "recordOffOnStop" || key == "unarmAfterRender" || key == "renderAutoClip")
- {
- auto o = engine.getRecordOptions();
- (key == "askWhatToRecord" ? o.askWhatToRecord : key == "recordNotes" ? o.recordNotes : key == "recordAudio" ? o.recordAudio
- : key == "disarmOnStop" ? o.disarmOnStop : key == "recordOffOnStop" ? o.recordOffOnStop : key == "unarmAfterRender" ? o.unarmAfterRender
- : key == "renderAutoClip" ? o.autoCreateClip
- : o.startsPlayback) = on;
- engine.setRecordOptions (o);
- }
- else if (key == "recordAutomation" || key == "recordQuantiseAutomation" || key == "recordClips")
- {
- auto o = engine.getRecordOptions();
- (key == "recordAutomation" ? o.recordAutomation : key == "recordClips" ? o.recordClips : o.quantiseAutomation) = on;
- engine.setRecordOptions (o);
- }
- else if (key == "recordToStepSequencer" || key == "recordingMarkers" || key == "recordNoteEnd")
- {
- auto o = engine.getRecordOptions();
- if (key == "recordNoteEnd")
- o.noteEnd = (NoteEnd) juce::jlimit (0, 2, line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
- else
- (key == "recordToStepSequencer" ? o.toStepSequencer : o.recordingMarkers) = on;
- engine.setRecordOptions (o);
- }
- else if (key == "recordPunchLoop" || key == "recordPreRoll" || key == "recordPostRoll")
- {
- auto o = engine.getRecordOptions();
- const auto v = line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue();
- if (key == "recordPunchLoop")
- o.punchLoopRegion = v != 0;
- else
- (key == "recordPreRoll" ? o.preRollBars : o.postRollBars) = juce::jlimit (0, 8, v);
- engine.setRecordOptions (o);
- }
- else if (key == "recordQuantiseStarts")
- {
- recordQuantiseOn = on;
- updateRecordQuantise();
- }
- else if (key == "newInserts" || key == "newMasterChain" || key == "newCleanMixer" || key == "playlistTracks" || key == "newAutoCrossfades")
- newProjectDefaults().readKey (key.toStdString(), line.fromFirstOccurrenceOf ("=", false, false).trim().toStdString());
- else if (key == "mixerUsedOnly")
- MixerStrips::showUsedOnly = on;
- else if (key == "quantizeSongJumps")
- engine.quantizeSongJumps.store (juce::jlimit (0, 5, line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue()));
- }
- startup = StartupOptions::load();
- browser.refreshPreviewVolume();
- }
- void MainComponent::saveUiSettings()
- {
- if (! persistent)
- return;
- uiSettingsFile().replaceWithText ("typingPiano=" + juce::String (typingPiano ? 1 : 0) + "\nkeepEditorsOpen="
- + juce::String (ChannelRackComponent::keepEditorsOpen ? 1 : 0)
- + "\nselFirstChanPatChanges=" + juce::String (ChannelRackComponent::selectFirstChannelWithNotes ? 1 : 0)
- + "\nalternateUndo=" + juce::String (alternateUndo ? 1 : 0)
- + "\neditPatternsIn="
- + juce::String (PlaylistComponent::editPatternsIn) + "\nsplash=" + juce::String (startup.splash ? 1 : 0)
- + "\nstartupSound=" + juce::String (startup.sound ? 1 : 0)
- + "\nwaveSpectral=" + juce::String (ui::WaveformCache::spectral ? 1 : 0)
- + "\nwaveStereo=" + juce::String (ui::WaveformCache::stereo ? 1 : 0)
- + "\nnoteNames=" + juce::String (notenames::currentStyle.load())
- + "\nnoteFlats=" + juce::String (notenames::currentFlats.load() ? 1 : 0)
- + "\nreducedEffects=" + juce::String (skin::reducedEffects() ? 1 : 0)
- + "\npluginStyle=" + juce::String (skin::forcedStyle() < 0 ? "Automatic" : skin::styleName ((skin::Style) skin::forcedStyle()))
- + "\npluginStyleOverrides=" + skin::overridesToString()
- + "\nrememberSeek=" + juce::String (EditorGlobals::get().rememberSeek ? 1 : 0)
- + "\nfollowPlaylist=" + juce::String (EditorGlobals::get().isFollowing (false) ? 1 : 0)
- + "\nfollowPianoRoll=" + juce::String (EditorGlobals::get().isFollowing (true) ? 1 : 0)
- + "\nfollowChannelRack=" + juce::String (EditorGlobals::get().isFollowingView (EditorGlobals::FollowView::channelRack) ? 1 : 0)
- + "\nfollowAudioEditor=" + juce::String (EditorGlobals::get().isFollowingView (EditorGlobals::FollowView::audioEditor) ? 1 : 0)
- + "\nscopeMode=" + juce::String (toolbar::OutputMonitor::mode)
- + "\ntoolbarGroups=" + juce::String (toolbarLayout.orderToString())
- + "\ntoolbarIcons=" + toolbarlayout::Layout::iconSizeId (toolbarLayout.iconSize)
- + "\nuiScale=" + juce::String (toolbarLayout.uiScale)
- + "\nmenuDensity=" + juce::String (theme::menus::compact() ? "compact" : "comfortable")
- + "\ntoolbarSeparators=" + juce::String (toolbarLayout.separators ? 1 : 0)
- + "\ntoolbarVisible=" + juce::String (toolbarLayout.visible ? 1 : 0)
- + "\nautosaveMinutes=" + juce::String (autosaveMinutes) + "\nautosaveKeep=" + juce::String (autosaveKeep)
- + "\naskUnusedRecordings=" + juce::String (askUnusedRecordings ? 1 : 0)
- + "\nundoLevels=" + juce::String (engine.getUndoLevels())
- + "\nmetronomeVolume=" + juce::String (engine.getTransport().metronomeVolume.load(), 2)
- + "\nmetronomeSoundFl=" + juce::String (metronome::clampSound (engine.getTransport().metronomeSound.load()))
- + "\nmetronomeTrack=" + juce::String (engine.getTransport().metronomeTrack.load())
- + "\nplayTruncatedOnTransport=" + juce::String (engine.getTransport().playTruncatedOnTransport.load() ? 1 : 0)
- + "\nresetPluginsOnTransport=" + juce::String (engine.getTransport().resetPluginsOnTransport.load() ? 1 : 0)
- + "\npreviewVolume=" + juce::String (engine.getPreviewVolume(), 2)
- + "\neditorVolume=" + juce::String (engine.getEditorVolume(), 2)
- + "\nrackPianoRollView=" + juce::String (rack.isPianoRollView() ? 1 : 0)
- + "\naskWhatToRecord=" + juce::String (engine.getRecordOptions().askWhatToRecord ? 1 : 0)
- + "\nrecordNotes=" + juce::String (engine.getRecordOptions().recordNotes ? 1 : 0)
- + "\nrecordAudio=" + juce::String (engine.getRecordOptions().recordAudio ? 1 : 0)
- + "\nrecordStartsPlayback=" + juce::String (engine.getRecordOptions().startsPlayback ? 1 : 0)
- + "\ndisarmOnStop=" + juce::String (engine.getRecordOptions().disarmOnStop ? 1 : 0)
- + "\nrecordOffOnStop=" + juce::String (engine.getRecordOptions().recordOffOnStop ? 1 : 0)
- + "\nunarmAfterRender=" + juce::String (engine.getRecordOptions().unarmAfterRender ? 1 : 0)
- + "\nrenderAutoClip=" + juce::String (engine.getRecordOptions().autoCreateClip ? 1 : 0)
- + "\nrecordQuantiseStarts=" + juce::String (recordQuantiseOn ? 1 : 0)
- + "\nrecordNoteEnd=" + juce::String ((int) engine.getRecordOptions().noteEnd)
- + "\nrecordToStepSequencer=" + juce::String (engine.getRecordOptions().toStepSequencer ? 1 : 0)
- + "\nrecordingMarkers=" + juce::String (engine.getRecordOptions().recordingMarkers ? 1 : 0)
- + "\nrecordAutomation=" + juce::String (engine.getRecordOptions().recordAutomation ? 1 : 0)
- + "\nrecordClips=" + juce::String (engine.getRecordOptions().recordClips ? 1 : 0)
- + "\nrecordQuantiseAutomation=" + juce::String (engine.getRecordOptions().quantiseAutomation ? 1 : 0)
- + "\nrecordPunchLoop=" + juce::String (engine.getRecordOptions().punchLoopRegion ? 1 : 0)
- + "\nrecordPreRoll=" + juce::String (engine.getRecordOptions().preRollBars)
- + "\nrecordPostRoll=" + juce::String (engine.getRecordOptions().postRollBars) + "\nmixerUsedOnly=" + juce::String (MixerStrips::showUsedOnly ? 1 : 0)
- + "\nquantizeSongJumps=" + juce::String (engine.quantizeSongJumps.load()) + "\n"
- + juce::String (newProjectDefaults().toText()));
- }
- // --- transport -----------------------------------------------------------------------------------
- void MainComponent::playStop()
- {
- auto& transport = engine.getTransport();
- if (engine.isWaitingForInput() || engine.isCountingIn()) // pressed again: cancel
- {
- engine.stop();
- return;
- }
- if (transport.playing.load())
- {
- engine.stop();
- engine.seek (playStartTicks); // back to where playback started
- }
- else
- {
- playStartTicks = transport.positionTicks.load();
- engine.startPlayback();
- }
- }
- void MainComponent::playPause()
- {
- if (engine.getTransport().playing.load() || engine.isWaitingForInput() || engine.isCountingIn())
- engine.stop();
- else
- {
- playStartTicks = engine.getTransport().positionTicks.load();
- engine.startPlayback();
- }
- }
- void MainComponent::playFromStart()
- {
- // FL 2026's Shift+Space (measured in FL, issue #11): playing, recording, waiting or counting in -> stop at the start
- // of the time selection (Song mode) or else of the song / pattern; stopped -> play from the current position, as
- // Space does (a later Space goes back there).
- const auto wasPlaying = engine.getTransport().playing.load() || engine.isWaitingForInput() || engine.isCountingIn();
- if (! wasPlaying)
- {
- playStop();
- return;
- }
- engine.stop();
- const auto& song = engine.getSong();
- const auto target = transportedit::shiftSpaceStopTarget (song.mode == PlayMode::song, song.hasLoop(), song.loopStart);
- if (target > 0)
- engine.seek ((double) target);
- else
- engine.rewind();
- playStartTicks = (double) target;
- }
- void MainComponent::stopAndRewind (bool toStart)
- {
- // Stop while nothing plays (the second press, or a double click) goes back to the very start even when
- // "Remember seek time" sends the first Stop to the ruler mark (round 162, issue #9)
- const auto alreadyStopped = toStart || ! (engine.getTransport().playing.load() || engine.isWaitingForInput() || engine.isCountingIn());
- engine.stop();
- // FL: the transport's Stop also ends a Browser sample preview (issue #11)
- browser.stopPreview(); // (the engine's one preview voice: the Sample browser window's preview stops too)
- const auto& globals = EditorGlobals::get();
- const auto back = transportedit::stopTarget (alreadyStopped, globals.rememberSeek && engine.getSong().mode == PlayMode::song, globals.seekMark);
- if (back > 0) // "Remember seek time": back to the position clicked on the Playlist ruler
- engine.seek ((double) back);
- else
- engine.rewind();
- playStartTicks = (double) back;
- }
- void MainComponent::showStopMenu()
- {
- auto& globals = EditorGlobals::get();
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Stop"));
- menu.addItem (tr ("Remember seek time: Stop goes back to the position clicked on the Playlist ruler"), true, globals.rememberSeek, [this] {
- EditorGlobals::get().rememberSeek = ! EditorGlobals::get().rememberSeek;
- saveUiSettings();
- });
- menu.addSeparator();
- menu.addItem (tr ("All notes off (panic)") + "\t" + tr ("double-click"), [this] { engine.panic(); });
- menu.addItem (tr ("Back to the start"), [this] { stopAndRewind (true); });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&stopButton));
- }
- void MainComponent::toggleMode()
- {
- engine.editSong ([] (Song& s) { s.mode = s.mode == PlayMode::song ? PlayMode::pattern : PlayMode::song; }, false);
- }
- // --- panels --------------------------------------------------------------------------------------
- void MainComponent::togglePanel (Panel panel)
- {
- workspace.toggle (panel);
- refreshPanelButtons();
- }
- void MainComponent::fitChannelRack (bool width)
- {
- rack.updateSize();
- const auto scrollbar = rackViewport.getScrollBarThickness();
- // compact like FL's rack: at most two bars of steps are shown, longer patterns scroll sideways, so the
- // rack does not cover the Playlist after a project with long patterns is opened
- const auto maxWidth = juce::jmin (juce::jmax (300, workspace.getWidth() - 2 * 16 - 260), rack.widthForSteps (32));
- const auto contentWidth = juce::jmin (rack.naturalWidth(), maxWidth); // the ghost steps only fill a wider rack
- const auto needsHorizontal = rack.naturalWidth() > contentWidth;
- workspace.fitPanelContent (Panel::channelRack, width ? contentWidth + scrollbar : 0, rack.getHeight() + (needsHorizontal ? scrollbar : 0));
- fittedChannelCount = (int) engine.getSong().channels.size();
- }
- void MainComponent::showPanel (Panel panel)
- {
- workspace.show (panel);
- refreshPanelButtons();
- }
- void MainComponent::refreshPanelButtons()
- {
- for (int i = 0; i < workspace::panelCount; ++i)
- panelButtons[(std::size_t) i].setToggleState (workspace.isPanelVisible ((Panel) i), juce::dontSendNotification);
- }
- void MainComponent::openPianoRoll()
- {
- showPanel (Panel::pianoRoll);
- pianoRoll.scrollToNotes();
- }
- void MainComponent::saveLayoutAs()
- {
- auto* window = new juce::AlertWindow (tr ("Save layout as"), tr ("Name of the layout:"), juce::MessageBoxIconType::NoIcon);
- window->addTextEditor ("name", tr ("My layout"));
- window->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- window->enterModalState (true, juce::ModalCallbackFunction::create ([this, window] (int result) {
- const auto name = window->getTextEditorContents ("name").trim();
- if (result == 1 && name.isNotEmpty())
- workspace.saveLayoutAs (name);
- }),
- true);
- keepAboveMainWindow (*window);
- }
- juce::PopupMenu MainComponent::layoutsMenu()
- {
- juce::PopupMenu menu;
- auto files = Workspace::layoutsFolder().findChildFiles (juce::File::findFiles, false, "*.txt");
- files.sort();
- for (const auto& file : files)
- menu.addItem (file.getFileNameWithoutExtension(), [this, file] {
- workspace.loadLayout (file);
- refreshPanelButtons();
- });
- if (files.isEmpty())
- menu.addItem (tr ("(none saved yet)"), false, false, [] {});
- menu.addSeparator();
- menu.addItem (tr ("Open layouts folder"), [] {
- Workspace::layoutsFolder().createDirectory();
- Workspace::layoutsFolder().startAsProcess();
- });
- return menu;
- }
- void MainComponent::selectTabForSnapshot (int tab)
- {
- const Panel panels[] = { Panel::channelRack, Panel::pianoRoll, Panel::playlist, Panel::mixer };
- const auto panel = panels[juce::jlimit (0, 3, tab)];
- if (panel == Panel::pianoRoll)
- {
- const auto& song = engine.getSong();
- std::vector<int> counts (song.channels.size(), 0);
- for (const auto& n : song.patterns[(std::size_t) song.currentPattern].notes)
- if (n.channel >= 0 && n.channel < (int) counts.size())
- ++counts[(std::size_t) n.channel];
- if (! counts.empty())
- engine.setSelectedChannel ((int) (std::max_element (counts.begin(), counts.end()) - counts.begin()));
- }
- // each view on its own: the panel maximized over the workspace
- workspace.resetLayout();
- workspace.show (panel);
- workspace.toggleMaximised (panel);
- refreshPanelButtons();
- if (panel == Panel::pianoRoll)
- pianoRoll.scrollToNotes();
- if (panel == Panel::playlist)
- playlist.resized(); // update the scrollbars for the loaded song
- if (panel == Panel::mixer)
- mixer.selectFirstTrackWithEffects();
- }
- void MainComponent::showDesktopForSnapshot (bool extraPanels)
- {
- workspace.resetLayout();
- if (auto* stage = dynamic_cast<DanceStage*> (danceStage.get()))
- stage->update(); // (the project's dancers now: no timer runs before the picture)
- if (extraPanels)
- {
- workspace.show (Panel::mixer);
- workspace.show (Panel::pianoRoll);
- pianoRoll.scrollToNotes();
- workspace.show (Panel::channelRack);
- }
- refreshPanelButtons();
- }
- // --- patterns ------------------------------------------------------------------------------------
- void MainComponent::selectPattern (int index)
- {
- if (index >= 0 && index < (int) engine.getSong().patterns.size() && index != engine.getSong().currentPattern)
- engine.editSong ([index] (Song& s) { s.currentPattern = index; }, false);
- }
- void MainComponent::nextEmptyPattern()
- {
- engine.editSong ([] (Song& s) { gotoNextEmptyPattern (s); });
- showRenamePattern (engine.getSong().currentPattern);
- }
- void MainComponent::deleteCurrentPattern()
- {
- // FL's Patterns › Delete (Ctrl+Shift+Del); the last pattern stays
- if (engine.getSong().patterns.size() > 1)
- engine.editSong ([] (Song& s) { s.removePattern (s.currentPattern); });
- }
- void MainComponent::insertPatternHere()
- {
- engine.editSong ([] (Song& s) { insertPattern (s, s.currentPattern, newPatternName (s)); });
- }
- // --- window menus ------------------------------------------------------------------------------
- // Each window's own items, at the top of the menu in its title bar (FL keeps an editor's options in the
- // small menu at the left of its title bar). Items run the key map's actions, so they show their keys.
- void MainComponent::addPanelMenuItems (Panel panel, juce::PopupMenu& menu)
- {
- auto action = [this] (juce::PopupMenu& m, const char* id, const juce::String& text, bool enabled = true, bool ticked = false) {
- m.addItem (text + shortcutText (id), enabled, ticked, [this, id] { runAction (id); });
- };
- auto zoomMenu = [&action] (const juce::String& prefix) {
- juce::PopupMenu zoom;
- const std::pair<const char*, const char*> items[] = {
- { "zoomIn", TR_NOOP ("Zoom in") }, { "zoomOut", TR_NOOP ("Zoom out") }, { "zoom1", TR_NOOP ("Zoom: one bar") },
- { "zoom2", TR_NOOP ("Zoom: four bars") }, { "zoom3", TR_NOOP ("Zoom: sixteen bars") },
- { "zoomAll", TR_NOOP ("Zoom to show everything") }, { "zoomSelection", TR_NOOP ("Zoom to the selection") },
- { "centrePlayhead", TR_NOOP ("Centre the view on the playhead") }
- };
- for (const auto& [id, text] : items)
- if (const auto* a = keys::findAction ((prefix + id).toStdString())) // the key map holds the id strings
- action (zoom, a->id, tr (text));
- return zoom;
- };
- switch (panel)
- {
- case Panel::channelRack:
- {
- menu.addSubMenu (tr ("Pattern"), makePatternMenu());
- menu.addSeparator();
- action (menu, "rack.graphEditor", tr ("Graph lanes (velocity, pan, pitch...)"), true, rack.areGraphLanesShown());
- action (menu, "rack.pianoRollView", tr ("Piano-roll view of all channels"), true, rack.isPianoRollView());
- action (menu, "rack.rotateLeft", tr ("Rotate the selected channels' steps left"));
- action (menu, "rack.rotateRight", tr ("Rotate the selected channels' steps right"));
- juce::PopupMenu sort;
- sort.addItem (tr ("By name"), [this] { rack.sortChannels (ChannelSort::name); });
- sort.addItem (tr ("By color"), [this] { rack.sortChannels (ChannelSort::colour); });
- sort.addItem (tr ("By mixer insert"), [this] { rack.sortChannels (ChannelSort::insert); });
- sort.addItem (tr ("By type"), [this] { rack.sortChannels (ChannelSort::type); });
- menu.addSubMenu (tr ("Sort channels"), sort);
- menu.addItem (tr ("Select unused channels"), [this] { rack.selectUnused(); });
- action (menu, "rack.groupSelected", tr ("Group selected..."));
- break;
- }
- case Panel::playlist:
- menu.addItem (tr ("Maximize or restore the Playlist") + shortcutText ("panel.maximisePlaylist"), [this] {
- workspace.toggleMaximised (Panel::playlist);
- refreshPanelButtons();
- });
- menu.addSeparator();
- action (menu, "playlist.ripple", tr ("Ripple editing (resizing and deleting move the later clips)"), true, playlist.isRippleOn());
- action (menu, "playlist.rippleDelete", tr ("Delete the selected clips and close the gaps"));
- action (menu, "playlist.autoCrossfades", tr ("Automatic crossfades (current project)"), true, engine.getSong().autoCrossfades);
- action (menu, "playlist.follow", tr ("Follow the playhead (auto scrolling)"), true, EditorGlobals::get().isFollowing (false));
- action (menu, "playlist.pitchClipsDown", tr ("Pitch selected audio clips one semitone down"));
- action (menu, "playlist.pitchClipsUp", tr ("Pitch selected audio clips one semitone up"));
- action (menu, "playlist.reverseClips", tr ("Reverse selected audio clips"));
- action (menu, "playlist.quantizeStarts", tr ("Quantize the clips' starts"));
- action (menu, "playlist.quantizeHalf", tr ("Quantize the clips' starts 50% (halfway to the grid)"));
- menu.addSubMenu (tr ("Zoom"), zoomMenu ("playlist."));
- menu.addSeparator();
- // FL's Performance mode (round 165m)
- action (menu, "playlist.performanceMode", tr ("Performance mode"), true, engine.getSong().performanceMode);
- action (menu, "playlist.zoomPerformance", tr ("Zoom on performance clips"), engine.getSong().performanceZoneEnd() > 0);
- action (menu, "playlist.perfClipProgress", tr ("Performance clip progress"), true, playlist.clipProgressShown());
- action (menu, "playlist.perfTrackProgress", tr ("Performance track progress"), true, playlist.trackProgressShown());
- break;
- case Panel::pianoRoll:
- {
- juce::PopupMenu tools;
- for (const auto* id : { "pianoRoll.riffMachine", "pianoRoll.chordProgression", "pianoRoll.articulate", "pianoRoll.quantize",
- "pianoRoll.chop", "pianoRoll.arpeggiate", "pianoRoll.strum", "pianoRoll.flam", "pianoRoll.claw",
- "pianoRoll.limit", "pianoRoll.flip", "pianoRoll.randomise", "pianoRoll.scaleLevels", "pianoRoll.lfo" })
- if (const auto* a = keys::findAction (id))
- action (tools, a->id, tr (a->description));
- menu.addSubMenu (tr ("Tools"), tools);
- action (menu, "pianoRoll.quickQuantize", tr ("Quick quantize (starts and lengths)"));
- action (menu, "pianoRoll.quantizeStarts", tr ("Quantize starts"));
- action (menu, "pianoRoll.quantizeHalf", tr ("Quantize starts 50% (halfway to the grid)"));
- action (menu, "pianoRoll.follow", tr ("Follow the playhead (auto scrolling)"), true, EditorGlobals::get().isFollowing (true));
- menu.addSubMenu (tr ("Zoom"), zoomMenu ("pianoRoll."));
- menu.addItem (tr ("Snap notes to the scale"), pianoRoll.hasScale(), pianoRoll.isScaleSnapOn(),
- [this] { pianoRoll.setScaleSnap (! pianoRoll.isScaleSnapOn()); });
- break;
- }
- case Panel::mixer:
- action (menu, "mixer.moveLeft", tr ("Move the selected inserts left"));
- action (menu, "mixer.moveRight", tr ("Move the selected inserts right"));
- menu.addSeparator();
- action (menu, "mixer.linkChannels", tr ("Link the selected channels to the selected insert"));
- action (menu, "mixer.linkChannelsFrom", tr ("Link the selected channels to inserts starting from the selected one"));
- action (menu, "mixer.selectLinkedChannels", tr ("Select the channels linked to the selected insert"));
- break;
- case Panel::browser:
- action (menu, "browser.search", tr ("Search the Browser"));
- browser.addViewItems (menu); // what it lists, which folders it shows (round 163)
- menu.addItem (tr ("Add folder..."), [this] { browser.addUserFolder(); });
- action (menu, "view.sampleBrowser", tr ("Sample browser (separate window)"));
- menu.addSeparator();
- // the search index (round 162, issue #9): searches read it; it follows changed folders by itself
- menu.addSectionHeader (browser.searchIndexStatus());
- menu.addItem (tr ("Refresh search index"), [this] { browser.refreshSearchIndex (false); });
- menu.addItem (tr ("Rebuild search index"), [this] { browser.refreshSearchIndex (true); });
- break;
- default:
- break;
- }
- }
- // --- quick-add palette and history -------------------------------------------------------------
- void MainComponent::showQuickAdd()
- {
- QuickAddTargets targets;
- targets.effectsFirst = workspace.getFocused() == Panel::mixer;
- targets.addInstrument = [this] (ChannelDef c) {
- rack.addChannel (std::move (c), true);
- showPanel (Panel::channelRack);
- };
- targets.addEffect = [this] (EffectSlot slot) {
- if (! mixer.addEffectToSelected (std::move (slot)))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Quick-add palette"),
- tr ("The selected insert has no free effect slot."));
- else
- showPanel (Panel::mixer);
- };
- openToolWindow (makeQuickAddPalette (engine, std::move (targets)), tr ("Quick-add palette"), "quickadd");
- }
- std::unique_ptr<juce::Component> MainComponent::makeQuickAddForSnapshot()
- {
- QuickAddTargets targets;
- targets.addInstrument = [] (ChannelDef) {};
- targets.addEffect = [] (EffectSlot) {};
- return makeQuickAddPalette (engine, std::move (targets));
- }
- void MainComponent::showHistory()
- {
- if (auto* open = findToolWindow ("history"))
- {
- open->toFront (true);
- return;
- }
- openToolWindow (makeHistoryPanel (engine), tr ("Undo history"), "history");
- }
- // --- recording options ---------------------------------------------------------------------------
- void MainComponent::updateRecordQuantise()
- {
- // the global grid sets the record quantise; "none" and the zoom-dependent grids record as played
- std::int64_t ticks = 0;
- // (the grid is kept even with "Note start time" off: "Note end time" uses it too)
- {
- const auto& option = grid::options()[(std::size_t) juce::jlimit (0, (int) grid::options().size() - 1, EditorGlobals::get().getGridOption())];
- if (option.kind == grid::Kind::ticks)
- ticks = option.ticks;
- else if (option.kind == grid::Kind::bar)
- ticks = (std::int64_t) ppq * juce::jmax (1, engine.getSong().beatsPerBar);
- }
- if (engine.getRecordOptions().quantise != ticks || engine.getRecordOptions().quantiseStarts != recordQuantiseOn)
- {
- auto o = engine.getRecordOptions();
- o.quantise = ticks;
- o.quantiseStarts = recordQuantiseOn;
- engine.setRecordOptions (o);
- }
- }
- void MainComponent::addRecordQuantizeItems (juce::PopupMenu& menu)
- {
- const auto o = engine.getRecordOptions();
- auto set = [this] (std::function<void (AudioEngine::RecordOptions&)> change) {
- auto options = engine.getRecordOptions();
- change (options);
- engine.setRecordOptions (options);
- saveUiSettings();
- };
- // FL's record menu "Quantize" items (REA round 139), to the global snap
- menu.addItem (tr ("Note start time"), ! o.toStepSequencer, recordQuantiseOn && ! o.toStepSequencer, [this] {
- recordQuantiseOn = ! recordQuantiseOn;
- updateRecordQuantise();
- saveUiSettings();
- });
- menu.addItem (tr ("Note end time"), ! o.toStepSequencer, o.noteEnd == NoteEnd::quantize && ! o.toStepSequencer, [set] {
- set ([] (AudioEngine::RecordOptions& r) { r.noteEnd = r.noteEnd == NoteEnd::quantize ? NoteEnd::keepEnd : NoteEnd::quantize; });
- });
- menu.addItem (tr ("Leave note duration"), ! o.toStepSequencer, o.noteEnd == NoteEnd::keepLength && ! o.toStepSequencer, [set] {
- set ([] (AudioEngine::RecordOptions& r) { r.noteEnd = r.noteEnd == NoteEnd::keepLength ? NoteEnd::keepEnd : NoteEnd::keepLength; });
- });
- menu.addItem (tr ("Record to step sequencer"), true, o.toStepSequencer,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.toStepSequencer = ! r.toStepSequencer; }); });
- // FL's "Automations" (RecQuantizeAutomationsMenu, setting QuantizeAutomations; REA round 143): recorded automation
- // points go to the snap
- menu.addItem (tr ("Automations"), true, o.quantiseAutomation,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.quantiseAutomation = ! r.quantiseAutomation; }); });
- }
- void MainComponent::addRecordOptions (juce::PopupMenu& menu)
- {
- const auto o = engine.getRecordOptions();
- auto set = [this] (std::function<void (AudioEngine::RecordOptions&)> change) {
- auto options = engine.getRecordOptions();
- change (options);
- engine.setRecordOptions (options);
- refreshRecordOptionButtons();
- saveUiSettings();
- };
- juce::PopupMenu countIn;
- countIn.addItem (tr ("Off"), true, o.countInBars == 0, [set] { set ([] (AudioEngine::RecordOptions& r) { r.countInBars = 0; }); });
- for (int bars : { 1, 2, 4 })
- countIn.addItem (bars == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars) }), true, o.countInBars == bars,
- [set, bars] { set ([bars] (AudioEngine::RecordOptions& r) { r.countInBars = bars; }); });
- menu.addSubMenu (tr ("Count-in") + shortcutText ("record.countIn"), countIn);
- menu.addItem (tr ("Wait for the first note to start") + shortcutText ("record.waitForInput"), true, o.waitForInput,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.waitForInput = ! r.waitForInput; }); });
- // round 163: punch in/out on the loop region, pre-roll and post-roll (bars)
- {
- auto bars = [&set] (juce::PopupMenu& m, int now, std::function<void (AudioEngine::RecordOptions&, int)> apply) {
- m.addItem (tr ("Off"), true, now == 0, [set, apply] { set ([apply] (AudioEngine::RecordOptions& r) { apply (r, 0); }); });
- for (int n : { 1, 2, 4 })
- m.addItem (n == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (n) }), true, now == n,
- [set, apply, n] { set ([apply, n] (AudioEngine::RecordOptions& r) { apply (r, n); }); });
- };
- juce::PopupMenu pre, post;
- bars (pre, o.preRollBars, [] (AudioEngine::RecordOptions& r, int n) { r.preRollBars = n; });
- bars (post, o.postRollBars, [] (AudioEngine::RecordOptions& r, int n) { r.postRollBars = n; });
- menu.addItem (tr ("Audio: punch in/out on the loop region (plays through it, keeps only the region)"), true, o.punchLoopRegion,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.punchLoopRegion = ! r.punchLoopRegion; }); });
- menu.addSubMenu (tr ("Audio: pre-roll (plays before the punch-in or the start position)"), pre);
- menu.addSubMenu (tr ("Audio: post-roll (plays after the punch-out, then stops)"), post);
- }
- menu.addSeparator();
- menu.addItem (tr ("Overdub: add to the pattern"), true, o.mode == RecordMode::overdub,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.mode = RecordMode::overdub; }); });
- menu.addItem (tr ("Replace: a recorded channel's old notes are cleared"), true, o.mode == RecordMode::replace,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.mode = RecordMode::replace; }); });
- menu.addSeparator();
- {
- juce::PopupMenu quantize;
- addRecordQuantizeItems (quantize);
- menu.addSubMenu (tr ("Quantize recorded notes to the global snap"), quantize);
- }
- menu.addItem (tr ("Song mode: place a pattern clip where recording starts"), true, o.placeSongClip,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.placeSongClip = ! r.placeSongClip; }); });
- }
- void MainComponent::toggleRecording()
- {
- if (engine.isRecording())
- {
- engine.setRecording (false);
- return;
- }
- if (! engine.getRecordOptions().askWhatToRecord || ! persistent)
- {
- engine.setRecording (true);
- if (engine.getRecordOptions().startsPlayback && ! engine.getTransport().playing.load()) // FL's "Recording starts playback"
- engine.startPlayback();
- return;
- }
- juce::Component::SafePointer<MainComponent> safe (this);
- showRecordChoiceDialog ([safe] (int choice, bool dontAsk) {
- if (safe == nullptr)
- return;
- if (choice == recordChoiceAudioEditor)
- {
- openAudioEditorRecording (safe->engine);
- if (! safe->engine.getTransport().playing.load())
- safe->engine.play();
- return;
- }
- auto o = safe->engine.getRecordOptions();
- o.recordNotes = choice != recordChoiceAudio;
- o.recordAudio = choice != recordChoiceNotes;
- o.recordAutomation = choice != recordChoiceAudio;
- if (dontAsk)
- o.askWhatToRecord = false;
- safe->engine.setRecordOptions (o);
- if (dontAsk)
- safe->saveUiSettings();
- if (choice == recordChoiceAudio && safe->engine.getArmedInserts().empty())
- safe->armSelectedInsertForAudio();
- safe->engine.setRecording (true);
- if (o.startsPlayback && ! safe->engine.getTransport().playing.load()) // FL's "Recording starts playback"
- safe->engine.startPlayback();
- });
- }
- // Round 163: the fastest way from "press record" to a clip on the Playlist — one key arms the selected insert (or the
- // one with an input), records audio only (no question) and starts playback (count-in / pre-roll as set); pressed
- // again it stops, and the take is on the Playlist.
- void MainComponent::quickRecordAudio()
- {
- auto& transport = engine.getTransport();
- if (engine.isRecording() && (transport.playing.load() || engine.isCountingIn() || engine.isWaitingForInput()))
- {
- engine.stop();
- engine.setRecording (false);
- return;
- }
- if (engine.getArmedInserts().empty())
- armSelectedInsertForAudio();
- if (engine.getArmedInserts().empty()) // no input yet: its menu is open, nothing to record
- return;
- if (auto o = engine.getRecordOptions(); ! o.recordAudio)
- {
- o.recordAudio = true;
- engine.setRecordOptions (o);
- }
- engine.setRecording (true);
- if (! transport.playing.load())
- engine.startPlayback();
- }
- void MainComponent::armSelectedInsertForAudio()
- {
- const auto& mixer = engine.getSong().mixer;
- // the selected insert, else the first one with an input, else a free one
- auto target = this->mixer.getStripsForSnapshot().getSelectedTrack();
- for (int t = 1; target <= 0 && t < (int) mixer.size(); ++t)
- if (mixer[(std::size_t) t].inputChannel >= 0)
- target = t;
- if (target <= 0)
- target = engine.getSong().nextFreeInsert();
- if (target <= 0 || target >= (int) mixer.size())
- return;
- showPanel (Panel::mixer);
- this->mixer.selectTrack (target);
- if (engine.isInsertArmed (target))
- return;
- // this menu item says "(choose its input)": without one, the input menu comes first and arms after the choice
- if (mixer[(std::size_t) target].inputChannel < 0)
- mixerinput::showMenu (engine, target, &this->mixer, [this, target] { engine.setInsertArmed (target, true); });
- else
- mixerinput::toggleArm (engine, target, &this->mixer);
- }
- void MainComponent::showMetronomeMenu()
- {
- // FL 2026's right-click on the metronome button, as it is (REA round 165z-a2): the "Metronome sound" choice only,
- // in FL's order. The volume trim is in Options, the count-in has its own button and the track the click plays
- // through is in Settings › Audio › Mixer.
- auto& transport = engine.getTransport();
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Metronome sound"));
- for (int i = 0; i < metronome::soundCount; ++i)
- menu.addItem (tr (metronome::soundName (i)), true, metronome::clampSound (transport.metronomeSound.load()) == i, [this, i] {
- engine.getTransport().metronomeSound.store (i);
- saveUiSettings();
- });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&metronomeButton));
- }
- void MainComponent::dumpScoreLog (int minutes)
- {
- const auto& song = engine.getSong();
- scorelog::DumpOptions options;
- options.minutes = minutes;
- options.bpm = song.bpm;
- options.beatsPerBar = song.beatsPerBar;
- auto notes = scorelog::dump (engine.scoreLogSnapshot(), options);
- // (channels deleted since the notes were played are left out)
- notes.erase (std::remove_if (notes.begin(), notes.end(), [&song] (const Note& n) { return n.channel < 0 || n.channel >= (int) song.channels.size(); }),
- notes.end());
- if (notes.empty())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Score logger"),
- tr ("The score log is empty: no notes were played on a MIDI keyboard or the typing keyboard in that time."));
- return;
- }
- auto apply = [this] (std::vector<Note> logged, bool replace) {
- const auto count = logged.size();
- engine.editSong ([&logged, replace] (Song& s) {
- if (s.patterns.empty())
- s.patterns.emplace_back();
- s.currentPattern = juce::jlimit (0, (int) s.patterns.size() - 1, s.currentPattern);
- auto& pattern = s.patterns[(std::size_t) s.currentPattern];
- if (replace)
- pattern.notes.clear();
- pattern.notes.insert (pattern.notes.end(), logged.begin(), logged.end());
- pattern.sortNotes();
- });
- ui::postHint ({ tr ("Score log: {0} notes put in the pattern", { juce::String ((int) count) }), {}, false, false }, 4000);
- };
- const auto& patterns = song.patterns;
- const auto current = song.currentPattern;
- if (current < 0 || current >= (int) patterns.size() || patterns[(std::size_t) current].notes.empty())
- {
- apply (std::move (notes), false);
- return;
- }
- auto box = juce::MessageBoxOptions()
- .withIconType (juce::MessageBoxIconType::QuestionIcon)
- .withTitle (tr ("Score logger"))
- .withMessage (tr ("The current pattern isn't empty. Do you want the score log to be merged, or to replace the current content?"))
- .withButton (tr ("Merge"))
- .withButton (tr ("Replace"))
- .withButton (tr ("Cancel"));
- juce::AlertWindow::showAsync (box, [apply, notes] (int result) mutable {
- if (result == 1 || result == 2)
- apply (std::move (notes), result == 2);
- });
- }
- void MainComponent::showMetronomeVolume()
- {
- // a callout with the volume knob; the click plays at the new level at once (Transport::metronomeVolume)
- struct VolumePanel final : public juce::Component
- {
- VolumePanel (MainComponent& m) : owner (m)
- {
- title.setText (tr ("Metronome volume"), juce::dontSendNotification);
- title.setJustificationType (juce::Justification::centred);
- addAndMakeVisible (title);
- knob.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
- knob.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 120, 18);
- knob.setRange (0.0, controls::maxUtilityVolume, 0.01);
- knob.setDoubleClickReturnValue (true, 1.0);
- knob.textFromValueFunction = [] (double v) { return ui::utilityVolumeText (v); };
- knob.valueFromTextFunction = [] (const juce::String& t) { return t.retainCharacters ("0123456789.").getDoubleValue() / 100.0; };
- knob.setValue (owner.engine.getTransport().metronomeVolume.load(), juce::dontSendNotification);
- knob.onValueChange = [this] { owner.engine.getTransport().metronomeVolume.store ((float) knob.getValue()); };
- knob.onDragEnd = [this] { owner.saveUiSettings(); };
- ui::setHint (knob, tr ("Metronome volume: 100% is the default click level, up to 125% [2xLMB] 100%"));
- addAndMakeVisible (knob);
- setSize (170, 150);
- }
- ~VolumePanel() override { owner.saveUiSettings(); }
- void resized() override
- {
- auto r = getLocalBounds().reduced (8);
- title.setBounds (r.removeFromTop (20));
- knob.setBounds (r);
- }
- MainComponent& owner;
- juce::Label title;
- juce::Slider knob;
- };
- juce::CallOutBox::launchAsynchronously (std::make_unique<VolumePanel> (*this), metronomeButton.getScreenBounds(), nullptr);
- }
- void MainComponent::openAudioEditorForSelection()
- {
- const auto& song = engine.getSong();
- const auto channel = engine.getSelectedChannel();
- if (juce::isPositiveAndBelow (channel, (int) song.channels.size()))
- {
- const auto& c = song.channels[(std::size_t) channel];
- if ((c.instrument == InstrumentKind::sampler || c.instrument == InstrumentKind::audioClip) && ! c.samplePath.empty())
- {
- openAudioEditorForChannel (engine, channel);
- return;
- }
- }
- openAudioEditor (engine);
- }
- void MainComponent::showRecordMenu()
- {
- const auto o = engine.getRecordOptions();
- auto set = [this] (std::function<void (AudioEngine::RecordOptions&)> change) {
- auto options = engine.getRecordOptions();
- change (options);
- engine.setRecordOptions (options);
- saveUiSettings();
- };
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Recording filter"));
- // FL's filter order (RecMenu, REA round 143): Automation, Notes, Audio
- menu.addItem (tr ("Automation (the controls you move: automation clips in song mode, pattern events in pattern mode)"), true,
- o.recordAutomation, [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordAutomation = ! r.recordAutomation; }); });
- menu.addItem (tr ("Notes (MIDI and PC keyboard) into the current pattern"), true, o.recordNotes,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordNotes = ! r.recordNotes; }); });
- menu.addItem (tr ("Audio of the armed mixer inserts (becomes Playlist clips)"), true, o.recordAudio,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordAudio = ! r.recordAudio; }); });
- menu.addItem (tr ("Clips (Performance mode: the launched clips are written into the arrangement)"), true, o.recordClips,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordClips = ! r.recordClips; }); });
- menu.addItem (tr ("Ask what to record when recording starts"), true, o.askWhatToRecord,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.askWhatToRecord = ! r.askWhatToRecord; }); });
- // FL's "Options" section (REA round 134)
- menu.addSectionHeader (tr ("Options"));
- menu.addItem (tr ("Recording starts playback"), true, o.startsPlayback,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.startsPlayback = ! r.startsPlayback; }); });
- menu.addItem (tr ("Disarm on stop (recording switches off when playback stops)"), true, o.recordOffOnStop,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordOffOnStop = ! r.recordOffOnStop; }); });
- // LYNX's own (issue #16; FL has no such option): also in Mixer › Disk recording
- menu.addItem (tr ("Disarm the inserts when recording stops"), true, o.disarmOnStop,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.disarmOnStop = ! r.disarmOnStop; }); });
- menu.addItem (tr ("Enable recording markers (Start / Stop recording markers in the Playlist)"), true, o.recordingMarkers,
- [set] { set ([] (AudioEngine::RecordOptions& r) { r.recordingMarkers = ! r.recordingMarkers; }); });
- // FL's "Quantize" section (REA round 139): to the global snap
- menu.addSectionHeader (tr ("Quantize"));
- addRecordQuantizeItems (menu);
- menu.addItem (tr ("Record into the audio editor..."), [this] { openAudioEditor (engine); });
- menu.addSeparator();
- menu.addItem (tr ("Arm the selected mixer insert for audio (choose its input)..."), [this] { armSelectedInsertForAudio(); });
- menu.addItem (tr ("Audio settings (input device)..."), [this] { openSettings ((int) SettingsPage::audio); });
- menu.addItem (tr ("Open recordings folder"), [this] {
- const auto folder = engine.getRecordingFolder();
- folder.createDirectory();
- folder.startAsProcess();
- });
- menu.addItem (tr ("Delete unused recordings and save..."), [this] { deleteUnusedRecordingsAndSave(); });
- menu.addSeparator();
- addRecordOptions (menu);
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (recordMenuButton.isVisible() ? (juce::Component*) &recordMenuButton
- : (juce::Component*) &recordButton));
- }
- void MainComponent::refreshRecordOptionButtons()
- {
- auto withKey = [this] (const juce::String& text, const char* id) {
- const auto key = shortcutText (id).trim();
- return key.isEmpty() ? text : text + " (" + key + ")";
- };
- const auto o = engine.getRecordOptions();
- countInButton.setToggleState (o.countInBars > 0, juce::dontSendNotification);
- countInButton.setTooltip (withKey (o.countInBars > 0 ? tr ("Count-in before recording: {0} bar(s)", { juce::String (o.countInBars) })
- : tr ("Count-in before recording: off"),
- "record.countIn"));
- waitInputButton.setToggleState (o.waitForInput, juce::dontSendNotification);
- waitInputButton.setTooltip (withKey (o.waitForInput ? tr ("Recording waits for the first note: on") : tr ("Recording waits for the first note: off"),
- "record.waitForInput"));
- }
- void MainComponent::clonePatternNow()
- {
- engine.editSong ([] (Song& s) { clonePattern (s, s.currentPattern); });
- }
- void MainComponent::movePatternNow (int delta)
- {
- engine.editSong ([delta] (Song& s) { movePattern (s, s.currentPattern, delta); });
- }
- void MainComponent::splitPatternByChannelNow()
- {
- int created = 0;
- engine.editSong ([&created] (Song& s) { created = splitPatternByChannel (s, s.currentPattern); });
- if (created == 0)
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Split by channel"), tr ("This pattern has no notes."));
- }
- void MainComponent::showRenamePattern (int index)
- {
- if (index < 0 || index >= (int) engine.getSong().patterns.size())
- return;
- const auto& p = engine.getSong().patterns[(std::size_t) index];
- showNameAndColourDialog (tr ("Rename pattern"), juce::String::fromUTF8 (p.name.c_str()), p.colour,
- [this, index] (const juce::String& name, std::uint32_t colour) {
- if (index < (int) engine.getSong().patterns.size())
- engine.editSong ([index, n = name.toStdString(), colour] (Song& s) {
- s.patterns[(std::size_t) index].name = n;
- s.patterns[(std::size_t) index].colour = colour;
- });
- });
- }
- void MainComponent::refreshToolbar()
- {
- const auto& song = engine.getSong();
- patternBox.clear (juce::dontSendNotification);
- for (std::size_t i = 0; i < song.patterns.size(); ++i)
- patternBox.addItem (juce::String::fromUTF8 (song.patterns[i].name.c_str()), (int) i + 1);
- patternBox.setSelectedItemIndex (song.currentPattern, juce::dontSendNotification);
- swingSlider.setValue (song.swing, juce::dontSendNotification);
- tempoDisplay.repaint();
- refreshModeButton();
- refreshRackPatternSelector();
- refreshRackLengthBox();
- }
- void MainComponent::refreshRackPatternSelector()
- {
- const auto& song = engine.getSong();
- const auto valid = song.currentPattern >= 0 && song.currentPattern < (int) song.patterns.size();
- const auto text = valid ? juce::String::fromUTF8 (song.patterns[(std::size_t) song.currentPattern].name.c_str()) : juce::String();
- const auto colour = valid ? PlaylistComponent::patternColour (song, song.currentPattern) : juce::Colour();
- if (text != rackPatternSelector.text || colour != rackPatternSelector.colour)
- {
- rackPatternSelector.text = text;
- rackPatternSelector.colour = colour;
- rackPatternSelector.repaint();
- }
- }
- void MainComponent::showRackPatternList()
- {
- const auto& song = engine.getSong();
- juce::PopupMenu menu;
- for (int i = 0; i < (int) song.patterns.size(); ++i)
- menu.addItem (juce::String::fromUTF8 (song.patterns[(std::size_t) i].name.c_str()), true, i == song.currentPattern, [this, i] { selectPattern (i); });
- menu.addSeparator();
- menu.addItem (tr ("New pattern"), [this] { newPatternButton.onClick(); });
- menu.addItem (tr ("Rename and color the pattern") + shortcutText ("pattern.rename"), [this] { runAction ("pattern.rename"); });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&rackPatternSelector));
- }
- // --- the Channel Rack's pattern length box (issue #12) ---------------------------------------------------------
- int MainComponent::PatternLengthBox::stepBars (int value, int delta)
- {
- static const int steps[] = { 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64 };
- constexpr int count = (int) (sizeof (steps) / sizeof (steps[0]));
- int i = 0;
- while (i + 1 < count && steps[i + 1] <= value)
- ++i;
- if (delta < 0 && steps[i] < value) // between two steps: going down lands on the lower one
- ++delta;
- return steps[juce::jlimit (0, count - 1, i + delta)];
- }
- void MainComponent::PatternLengthBox::paint (juce::Graphics& g)
- {
- using namespace theme;
- const auto area = getLocalBounds().toFloat();
- g.setColour (hovered ? colour::bg3 : colour::bg1);
- g.fillRoundedRectangle (area, radius::sm);
- g.setColour (hovered ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (area.reduced (0.5f), radius::sm, 1.0f);
- auto r = getLocalBounds().reduced (3, 0);
- g.setFont (font (type::caption - 1.0f, true));
- g.setColour (colour::textSecondary);
- g.drawText (automatic ? "A" : "L", r.removeFromLeft (9), juce::Justification::centred, false);
- g.setFont (font (type::small, true));
- g.setColour (automatic ? colour::textSecondary : colour::textPrimary);
- g.drawText (juce::String (bars), r, juce::Justification::centred, false);
- }
- void MainComponent::PatternLengthBox::mouseDown (const juce::MouseEvent& e)
- {
- dragStartBars = bars;
- if (e.mods.isPopupMenu() && onMenu)
- onMenu();
- }
- void MainComponent::PatternLengthBox::mouseDrag (const juce::MouseEvent& e)
- {
- if (e.mods.isPopupMenu() || onSet == nullptr)
- return;
- // one step of the list per 14 px up (as the rack's insert number box: drag up = more)
- const auto delta = -e.getDistanceFromDragStartY() / 14;
- const auto value = delta == 0 ? dragStartBars : stepBars (dragStartBars, delta);
- if (value != bars || automatic)
- if (delta != 0)
- onSet (value);
- }
- void MainComponent::PatternLengthBox::mouseWheelMove (const juce::MouseEvent&, const juce::MouseWheelDetails& wheel)
- {
- if (onSet != nullptr && wheel.deltaY != 0.0f)
- onSet (stepBars (bars, wheel.deltaY > 0.0f ? 1 : -1));
- }
- void MainComponent::refreshRackLengthBox()
- {
- const auto& song = engine.getSong();
- if (song.currentPattern < 0 || song.currentPattern >= (int) song.patterns.size())
- return;
- const auto& pattern = song.patterns[(std::size_t) song.currentPattern];
- const auto bar = (std::int64_t) ppq * juce::jmax (1, song.beatsPerBar);
- const auto bars = (int) juce::jmax<std::int64_t> (1, (pattern.effectiveLength (song.beatsPerBar) + bar - 1) / bar);
- const auto automatic = pattern.lengthTicks == 0;
- if (bars != rackLengthBox.bars || automatic != rackLengthBox.automatic)
- {
- rackLengthBox.bars = bars;
- rackLengthBox.automatic = automatic;
- rackLengthBox.setTooltip (automatic ? tr ("Pattern length: {0} (automatic, from the notes)", { bars == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars) }) })
- : tr ("Pattern length: {0}", { bars == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars) }) }));
- rackLengthBox.repaint();
- }
- }
- void MainComponent::showPatternLengthMenu()
- {
- const auto& song = engine.getSong();
- const auto& pattern = song.patterns[(std::size_t) song.currentPattern];
- const auto bar = (std::int64_t) ppq * juce::jmax (1, song.beatsPerBar);
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Pattern length"));
- menu.addItem (tr ("Automatic (from notes)"), true, pattern.lengthTicks == 0, [this] { rackLengthBox.onSet (0); });
- for (int bars : { 1, 2, 4, 8, 16, 32 })
- menu.addItem (bars == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars) }), true, pattern.lengthTicks == bars * bar,
- [this, bars] { rackLengthBox.onSet (bars); });
- menu.addSeparator();
- menu.addItem (tr ("Type value..."), [this] {
- ui::ValueSpec spec;
- spec.name = tr ("Pattern length (bars, 0 = automatic)");
- spec.minimum = 0.0;
- spec.maximum = 999.0;
- spec.interval = 1.0;
- ui::typeValue (rackLengthBox, spec, rackLengthBox.automatic ? 0.0 : (double) rackLengthBox.bars,
- [this] (double v) { rackLengthBox.onSet (juce::roundToInt (v)); });
- });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&rackLengthBox));
- }
- void MainComponent::PatternSelector::paint (juce::Graphics& g)
- {
- using namespace theme;
- auto area = getLocalBounds().toFloat();
- g.setColour (hoveredPart >= 0 ? colour::bg3 : colour::bg1);
- g.fillRoundedRectangle (area, radius::sm);
- g.setColour (hoveredPart >= 0 ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (area.reduced (0.5f), radius::sm, 1.0f);
- // the pattern's colour as a thin stripe at the left of the name
- if (! colour.isTransparent())
- {
- g.setColour (colour);
- g.fillRect (juce::Rectangle<float> ((float) arrowWidth + 1.0f, 4.0f, 3.0f, (float) getHeight() - 8.0f));
- }
- auto arrow = [&g, this] (int part, bool left) {
- const auto box = juce::Rectangle<float> (left ? 0.0f : (float) (getWidth() - arrowWidth), 0.0f, (float) arrowWidth, (float) getHeight());
- const auto c = box.getCentre();
- juce::Path p;
- if (left)
- p.addTriangle (c.x + 2.5f, c.y - 4.0f, c.x + 2.5f, c.y + 4.0f, c.x - 2.5f, c.y);
- else
- p.addTriangle (c.x - 2.5f, c.y - 4.0f, c.x - 2.5f, c.y + 4.0f, c.x + 2.5f, c.y);
- g.setColour (hoveredPart == part ? colour::textPrimary : colour::textSecondary);
- g.fillPath (p);
- };
- arrow (0, true);
- arrow (2, false);
- g.setColour (colour::textPrimary);
- g.setFont (font (type::small, true));
- const auto name = getLocalBounds().withTrimmedLeft (arrowWidth + 7).withTrimmedRight (arrowWidth + 14);
- g.drawText (text, name, juce::Justification::centredLeft, true);
- icons::draw (g, Icon::chevronDown, juce::Rectangle<float> ((float) (getWidth() - arrowWidth - 14), 0.0f, 12.0f, (float) getHeight()).reduced (1.0f, 4.0f),
- hoveredPart == 1 ? colour::textPrimary : colour::textSecondary);
- g.setColour (colour::border);
- g.fillRect (arrowWidth, 3, 1, getHeight() - 6);
- g.fillRect (getWidth() - arrowWidth - 1, 3, 1, getHeight() - 6);
- }
- void MainComponent::PatternSelector::mouseDown (const juce::MouseEvent& e)
- {
- const auto part = partAt (e.x);
- if (part == 1 || e.mods.isPopupMenu())
- {
- if (onMenu)
- onMenu();
- }
- else if (onStep)
- onStep (part == 0 ? -1 : 1);
- }
- void MainComponent::PatternSelector::mouseWheelMove (const juce::MouseEvent&, const juce::MouseWheelDetails& wheel)
- {
- const auto delta = wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX;
- if (delta != 0.0f && onStep)
- onStep (delta > 0.0f ? -1 : 1);
- }
- juce::PopupMenu MainComponent::makePatternMenu()
- {
- const auto& song = engine.getSong();
- const auto index = song.currentPattern;
- const auto& pattern = song.patterns[(std::size_t) index];
- auto colours = ui::colourMenu (pattern.colour, [this, index] (std::uint32_t c) {
- if (index < (int) engine.getSong().patterns.size())
- engine.editSong ([index, c] (Song& s) { s.patterns[(std::size_t) index].colour = c; });
- }, juce::Rectangle<int> (juce::Desktop::getMousePosition().x, juce::Desktop::getMousePosition().y, 1, 1));
- juce::PopupMenu lengths;
- lengths.addItem (tr ("Automatic (from notes)"), true, pattern.lengthTicks == 0,
- [this, index] { engine.editSong ([index] (Song& s) { s.patterns[(std::size_t) index].lengthTicks = 0; }); });
- for (int bars : { 1, 2, 4, 8, 16, 32 })
- {
- const auto ticks = (std::int64_t) bars * ppq * juce::jmax (1, song.beatsPerBar);
- lengths.addItem (bars == 1 ? tr ("1 bar") : tr ("{0} bars", { juce::String (bars) }), true, pattern.lengthTicks == ticks,
- [this, index, ticks] { engine.editSong ([index, ticks] (Song& s) { s.patterns[(std::size_t) index].lengthTicks = ticks; }); });
- }
- juce::PopupMenu menu;
- // a double-click on the title renames the pattern (issue #12)
- ui::addItemHeader (menu, tr ("Pattern"), juce::String::fromUTF8 (pattern.name.c_str()), PlaylistComponent::patternColour (song, index),
- [this, index] { showRenamePattern (index); });
- menu.addItem (tr ("Next pattern") + shortcutText ("pattern.next"), index + 1 < (int) song.patterns.size(), false,
- [this] { selectPattern (stepPattern (engine.getSong(), 1)); });
- menu.addItem (tr ("Previous pattern") + shortcutText ("pattern.previous"), index > 0, false,
- [this] { selectPattern (stepPattern (engine.getSong(), -1)); });
- menu.addItem (tr ("First empty pattern (and name it)") + shortcutText ("pattern.firstEmpty"), [this] { runAction ("pattern.firstEmpty"); });
- menu.addItem (tr ("Next empty pattern (and name it)") + shortcutText ("pattern.nextEmpty"), [this] { nextEmptyPattern(); });
- menu.addItem (tr ("Next empty pattern (no naming)") + shortcutText ("pattern.nextEmptyNoName"), [this] { runAction ("pattern.nextEmptyNoName"); });
- menu.addSeparator();
- menu.addItem (tr ("Rename and color...") + shortcutText ("pattern.rename"), [this, index] { showRenamePattern (index); });
- menu.addSubMenu (tr ("Color"), colours);
- menu.addSubMenu (tr ("Length"), lengths);
- menu.addItem (tr ("Insert an empty pattern before this one") + shortcutText ("pattern.insert"), [this] { insertPatternHere(); });
- menu.addItem (tr ("Clone") + shortcutText ("pattern.clone"), [this] { clonePatternNow(); });
- menu.addItem (tr ("Move up") + shortcutText ("pattern.moveUp"), index > 0, false, [this] { movePatternNow (-1); });
- menu.addItem (tr ("Move down") + shortcutText ("pattern.moveDown"), index + 1 < (int) song.patterns.size(), false, [this] { movePatternNow (1); });
- menu.addItem (tr ("Split by channel (one new pattern per channel)"), ! pattern.notes.empty(), false, [this] { splitPatternByChannelNow(); });
- juce::PopupMenu signatures;
- for (int beats : { 2, 3, 4, 5, 6, 7, 8, 9, 12 })
- signatures.addItem (juce::String (beats) + "/4", true, song.beatsPerBar == beats,
- [this, beats] { engine.editSong ([beats] (Song& s) { s.beatsPerBar = beats; }); });
- menu.addSubMenu (tr ("Song time signature"), signatures);
- menu.addSeparator();
- menu.addItem (tr ("Delete pattern") + shortcutText ("pattern.delete"), song.patterns.size() > 1, false,
- [this, index] { engine.editSong ([index] (Song& s) { s.removePattern (index); }); });
- return menu;
- }
- void MainComponent::showPatternMenu()
- {
- makePatternMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&patternMenuButton));
- }
- void MainComponent::refreshModeButton()
- {
- const auto recording = engine.isRecording();
- recordButton.setToggleState (recording, juce::dontSendNotification);
- const auto inputs = engine.getActiveMidiInputs();
- recordButton.setTooltip ((engine.isAudioRecordingArmed() ? tr ("Record while playing: notes (PC keyboard and MIDI) and input audio")
- : tr ("Record while playing: notes (PC keyboard and MIDI)"))
- + "\n" + tr ("MIDI inputs: {0}", { inputs.isEmpty() ? tr ("none") : inputs.joinIntoString (", ") }));
- recordMenuButton.setToggleState (engine.isAudioRecordingArmed(), juce::dontSendNotification);
- recordMenuButton.setOnColour (theme::colour::accentMuted);
- const auto songMode = engine.getSong().mode == PlayMode::song;
- patternModeButton.setToggleState (! songMode, juce::dontSendNotification);
- songModeButton.setToggleState (songMode, juce::dontSendNotification);
- metronomeButton.setToggleState (engine.getTransport().metronome.load(), juce::dontSendNotification);
- }
- void MainComponent::changeListenerCallback (juce::ChangeBroadcaster*)
- {
- if (const auto notice = engine.takeRecordingNotice(); notice.issue != AudioEngine::InputIssue::none && persistent)
- mixerinput::explain (notice);
- // round 165c: hardware inserts measured for another device setup (the device or its buffer size changed, or the project
- // was measured elsewhere): a prompt that pings them on request, nothing pinged by itself (pings make clicks)
- if (auto stale = engine.takeHardwareInsertNotice(); ! stale.empty() && persistent)
- {
- const auto count = (int) stale.size();
- auto options = juce::MessageBoxOptions()
- .withIconType (juce::MessageBoxIconType::InfoIcon)
- .withTitle (tr ("Hardware Insert"))
- .withMessage ((count == 1 ? tr ("The round trip of a hardware insert was measured for another audio setup (the device or its "
- "buffer size changed), so its return is no longer lined up with the rest of the mix.")
- : tr ("The round trip of {0} hardware inserts was measured for another audio setup (the device or its "
- "buffer size changed), so their returns are no longer lined up with the rest of the mix.",
- { juce::String (count) }))
- + "\n\n" + tr ("Ping now? Each one sends a few clicks out to its gear and listens for them on its return."))
- .withButton (tr ("Ping now"))
- .withButton (tr ("Later"));
- juce::AlertWindow::showAsync (options, [safe = juce::Component::SafePointer<MainComponent> (this), stale = std::move (stale)] (int result) {
- if (result == 1 && safe != nullptr)
- safe->engine.pingHardwareInserts (stale);
- });
- }
- const auto& song = engine.getSong();
- // FL's "Select first channel with notes when the pattern changes" (Settings › General, REA round 167j §5)
- if (song.currentPattern != lastCurrentPattern)
- {
- const auto changedPattern = lastCurrentPattern >= 0;
- lastCurrentPattern = song.currentPattern;
- if (changedPattern && ChannelRackComponent::selectFirstChannelWithNotes)
- if (const auto first = firstChannelWithNotes (song, song.currentPattern); first >= 0 && first != engine.getSelectedChannel())
- engine.setSelectedChannel (first);
- }
- bool namesChanged = patternBox.getNumItems() != (int) song.patterns.size();
- for (int i = 0; ! namesChanged && i < patternBox.getNumItems(); ++i)
- namesChanged = patternBox.getItemText (i) != juce::String::fromUTF8 (song.patterns[(std::size_t) i].name.c_str());
- refreshModeButton();
- tempoDisplay.repaint();
- // a project with other filter groups (or none): the rack's filter falls back to "All"
- if (rack.getFilterGroup() >= (int) song.channelGroups.size())
- rack.setFilterGroup (-1);
- if (rackFilterBox.text != rack.filterName())
- {
- rackFilterBox.text = rack.filterName();
- rackFilterBox.repaint();
- }
- if (rackLoopButton.getToggleState() != rack.isLoopingOn()) // (another pattern, undo)
- rackLoopButton.setToggleState (rack.isLoopingOn(), juce::dontSendNotification);
- if ((int) song.channels.size() != fittedChannelCount && fittedChannelCount >= 0) // a row was added or removed
- fitChannelRack (false);
- if (namesChanged || patternBox.getSelectedItemIndex() != song.currentPattern || std::abs (swingSlider.getValue() - song.swing) > 1e-6)
- refreshToolbar();
- else
- {
- refreshRackPatternSelector(); // a new pattern colour
- refreshRackLengthBox(); // (notes added: the automatic length grows)
- }
- }
- // --- tempo display -------------------------------------------------------------------------------
- ui::ValueSpec MainComponent::TempoDisplay::spec() const
- {
- ui::ValueSpec s;
- s.name = tr ("Tempo");
- s.minimum = minTempo;
- s.maximum = maxTempo;
- s.defaultValue = 130.0;
- s.toText = [] (double v) { return juce::String (v, 3) + " BPM"; };
- s.target = AutomationTarget { AutomationTargetKind::tempo, 0 };
- return s;
- }
- void MainComponent::TempoDisplay::setBpm (double bpm)
- {
- bpm = controls::clampTempo (bpm);
- if (std::abs (bpm - engine.getSong().bpm) > 1e-9)
- engine.editSong ([bpm] (Song& s) { s.bpm = bpm; });
- repaint();
- }
- bool MainComponent::TempoDisplay::isOnDecimals (int x) const
- {
- return decimalX > 0 && x > decimalX;
- }
- void MainComponent::TempoDisplay::paint (juce::Graphics& g)
- {
- using namespace theme;
- const auto area = getLocalBounds().toFloat();
- g.setColour (colour::bg1);
- g.fillRoundedRectangle (area, radius::md);
- if (dragging)
- {
- g.setColour (colour::accent.withAlpha (0.6f));
- g.drawRoundedRectangle (area.reduced (0.5f), radius::md, 1.0f);
- }
- const auto bpm = engine.getSong().bpm;
- const auto whole = juce::String ((int) std::floor (bpm + 1e-9));
- const auto fraction = juce::String (bpm - std::floor (bpm + 1e-9), 3).fromFirstOccurrenceOf (".", false, false).paddedRight ('0', 3).substring (0, 3);
- const juce::Font big (monoFont (18.0f)), small (monoFont (11.0f)), caption (font (type::caption - 1.0f));
- const auto wholeWidth = juce::GlyphArrangement::getStringWidth (big, whole);
- const auto fracWidth = juce::GlyphArrangement::getStringWidth (small, "." + fraction);
- const auto unitWidth = juce::GlyphArrangement::getStringWidth (caption, "BPM");
- auto x = area.getCentreX() - (wholeWidth + fracWidth + 6.0f + unitWidth) / 2.0f;
- const auto baseline = area.getCentreY() + 5.0f;
- g.setColour (colour::textPrimary);
- g.setFont (big);
- g.drawSingleLineText (whole, juce::roundToInt (x), juce::roundToInt (baseline));
- x += wholeWidth;
- decimalX = juce::roundToInt (x);
- g.setColour (dragOnDecimals && dragging ? colour::textPrimary : colour::textSecondary);
- g.setFont (small);
- g.drawSingleLineText ("." + fraction, juce::roundToInt (x), juce::roundToInt (baseline));
- x += fracWidth + 6.0f;
- g.setColour (colour::textDisabled);
- g.setFont (caption);
- g.drawSingleLineText ("BPM", juce::roundToInt (x), juce::roundToInt (baseline));
- }
- void MainComponent::TempoDisplay::mouseDown (const juce::MouseEvent& e)
- {
- if (e.mods.isPopupMenu())
- {
- showMenu();
- return;
- }
- if (ui::isResetClick (e))
- {
- setBpm (spec().defaultValue);
- return;
- }
- startBpm = engine.getSong().bpm;
- dragOnDecimals = isOnDecimals (e.x);
- dragging = true;
- repaint();
- }
- void MainComponent::TempoDisplay::mouseDrag (const juce::MouseEvent& e)
- {
- if (dragging)
- {
- engine.noteTweaked ({ AutomationTargetKind::tempo, 0 });
- setBpm (controls::tempoDrag (startBpm, -e.getDistanceFromDragStartY(), dragOnDecimals, e.mods.isCtrlDown()));
- }
- }
- void MainComponent::TempoDisplay::mouseUp (const juce::MouseEvent&)
- {
- dragging = false;
- repaint();
- }
- void MainComponent::TempoDisplay::mouseDoubleClick (const juce::MouseEvent& e)
- {
- if (! e.mods.isPopupMenu())
- ui::typeValue (*this, spec(), engine.getSong().bpm, [this] (double v) { setBpm (v); });
- }
- void MainComponent::TempoDisplay::mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel)
- {
- const auto delta = wheel.deltaY != 0.0f ? wheel.deltaY : -wheel.deltaX;
- if (delta == 0.0f)
- return;
- const auto step = isOnDecimals (e.x) ? 0.01 : 1.0;
- engine.noteTweaked ({ AutomationTargetKind::tempo, 0 });
- setBpm (engine.getSong().bpm + (delta > 0.0f ? 1.0 : -1.0) * step * (e.mods.isCtrlDown() ? 0.1 : 1.0));
- }
- ui::Hint MainComponent::TempoDisplay::hintAt (juce::Point<int> p)
- {
- return ui::valueHint (spec(), engine.getSong().bpm,
- isOnDecimals (p.x) ? tr ("[LMB] drag the decimals for fine changes [Wheel] 0.01 [2xLMB] type [RMB] tap tempo, half, double")
- : tr ("[LMB] drag the whole number [Ctrl] fine [Wheel] 1 BPM [2xLMB] type [RMB] tap tempo, half, double"));
- }
- void MainComponent::TempoDisplay::showMenu()
- {
- const auto bpm = engine.getSong().bpm;
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("Tempo") + ": " + juce::String (bpm, 3) + " BPM");
- menu.addItem (tr ("Type value..."), [this, bpm] { ui::typeValue (*this, spec(), bpm, [this] (double v) { setBpm (v); }); });
- menu.addItem (tr ("Tempo tapper..."), [this] { showTap(); });
- menu.addItem (tr ("Half ({0} BPM)", { juce::String (controls::halfTempo (bpm), 2) }), [this, bpm] { setBpm (controls::halfTempo (bpm)); });
- menu.addItem (tr ("Double ({0} BPM)", { juce::String (controls::doubleTempo (bpm), 2) }), [this, bpm] { setBpm (controls::doubleTempo (bpm)); });
- menu.addItem (tr ("Reset ({0})", { "130 BPM" }), [this] { setBpm (130.0); });
- menu.addSeparator();
- addAutomationItem (menu, engine, { AutomationTargetKind::tempo, 0 });
- menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
- }
- void MainComponent::TempoDisplay::showTap()
- {
- openTempoTapper (engine); // FL's tempo menu opens its tempo tapper too
- }
- // --- hint bar ------------------------------------------------------------------------------------
- juce::String MainComponent::idleHint() const
- {
- if (engine.isWaitingForInput())
- return tr ("Recording: waiting for the first note ([Space] cancels)");
- if (engine.isCountingIn())
- return tr ("Recording: count-in...");
- if (const auto scan = engine.getPluginHost().backgroundScan(); scan.running)
- return tr ("Scanning for plugins in the background: {0}% {1}", { juce::String (juce::roundToInt (scan.progress * 100.0f)), scan.file });
- return tr ("Point at anything to see what it does here. [F1] shortcuts [F5]-[F9] windows [Space] play/stop "
- "[Ctrl][T] typing piano: {0}", { typingPiano ? tr ("on") : tr ("off") });
- }
- juce::String MainComponent::keyMarkup (const char* actionId) const
- {
- const auto& chords = keyMap.chordsFor (actionId);
- if (chords.empty())
- return {};
- // "Ctrl+Shift+S" -> "[Ctrl][Shift][S]"; a key name that is not markup stays as text
- const auto text = juce::String (keys::toString (chords.front()));
- juce::String out;
- for (const auto& part : juce::StringArray::fromTokens (text, "+", ""))
- {
- if (! hintmarkup::isToken (part.toStdString()))
- return "(" + text + ")";
- out << "[" << part << "]";
- }
- return out;
- }
- void MainComponent::setControlHints()
- {
- auto with = [this] (const juce::String& text, const char* actionId) {
- const auto key = keyMarkup (actionId);
- return key.isEmpty() ? text : text + " " + key;
- };
- ui::setHint (newButton, with (tr ("New project"), "file.new"));
- ui::setHint (openButton, with (tr ("Open a project (.lynx, FL Studio .flp, MIDI)"), "file.open"));
- ui::setHint (saveButton, with (tr ("Save the project"), "file.save") + " " + tr ("save as:") + " " + keyMarkup ("file.saveAs"));
- ui::setHint (exportButton, with (tr ("Export audio: WAV, FLAC or OGG"), "file.export"));
- ui::setHint (undoButton, with (tr ("Undo the last edit"), "edit.undo") + " " + tr ("[RMB] undo history"), true);
- ui::setHint (redoButton, with (tr ("Redo"), "edit.redo") + " " + tr ("[RMB] undo history"), true);
- ui::setHint (pluginPickerButton, with (tr ("Plugin picker: add an instrument or an effect by name"), "panel.quickAdd"));
- ui::setHint (playButton, with (tr ("Play: [LMB] play; again: stop and go back to where it started"), "transport.playStop")
- + " " + keyMarkup ("transport.pause") + " " + tr ("pause"));
- ui::setHint (stopButton, tr ("Stop: [LMB] stop and go back to the start (or the remembered position; again: the start) "
- "[2xLMB] back to the start and all notes off (panic) [RMB] remember seek time"),
- true);
- ui::setHint (recordButton, with (tr ("Record: [LMB] arm, then play to record notes (and audio, when armed) [RMB] what to record"), "transport.record"),
- true);
- ui::setHint (recordMenuButton, tr ("What to record: notes, input audio, count-in, overdub or replace, quantise [LMB] menu"), true);
- ui::setHint (patternModeButton, with (tr ("Pattern mode: plays the current pattern in a loop [RMB] show the Channel Rack"), "transport.toggleMode"));
- ui::setHint (songModeButton, with (tr ("Song mode: plays the Playlist arrangement [RMB] show the Playlist"), "transport.toggleMode"));
- ui::setHint (metronomeButton, with (tr ("Metronome: clicks on every beat while playing [RMB] volume and options"), "transport.metronome"), true);
- ui::setHint (countInButton, with (tr ("Count-in: one bar of clicks before recording starts (the menu has more lengths)"), "record.countIn"));
- ui::setHint (waitInputButton, with (tr ("Wait for input: recording starts with the first note you play"), "record.waitForInput"));
- ui::setHint (typingPianoButton, with (tr ("Typing keyboard as a piano: Z..M and Q..P play the selected channels; letter shortcuts pause"),
- "view.typingPiano"));
- ui::setHint (gridBox, tr ("Global snap: the grid of the Piano Roll and Playlist (when they follow it) and the quantise of recorded notes "
- "[LMB] choose [Wheel] step [RMB] length of new notes [Backspace] snap on/off [Alt] while dragging: no snap"),
- true);
- ui::setHint (patternBox, tr ("Current pattern: what the Channel Rack and Piano Roll edit and Pattern mode plays [LMB] choose [Wheel] step "
- "[F4] next empty [F2] rename"));
- ui::setHint (newPatternButton, tr ("New pattern: an empty pattern after the last one"));
- ui::setHint (patternMenuButton, tr ("Pattern menu: rename, color, length, clone, insert, split by channel, delete"), true);
- const char* panelHelp[] = { TR_NOOP ("the arrangement: clips of patterns, audio and automation on tracks"),
- TR_NOOP ("the instruments and their step sequencer"),
- TR_NOOP ("the notes of the selected channel in the current pattern"),
- TR_NOOP ("inserts, effects and routing"),
- TR_NOOP ("samples, presets, plugins and projects to drag in") };
- for (int i = 0; i < workspace::panelCount; ++i)
- ui::setHint (panelButtons[(std::size_t) i],
- with (panelName ((Panel) i) + ": " + tr (panelHelp[i]) + " " + tr ("[LMB] show, focus or hide [RMB] maximized"),
- panelAction ((Panel) i)));
- setQuickTips();
- }
- std::vector<std::pair<juce::Rectangle<int>, juce::String>> MainComponent::getQuickTipsForSnapshot()
- {
- std::vector<std::pair<juce::Rectangle<int>, juce::String>> tips;
- std::function<void (juce::Component&)> visit = [&] (juce::Component& c) {
- for (auto* child : c.getChildren())
- {
- if (! child->isVisible())
- continue;
- if (const auto tip = ui::quickTipOf (*child); tip.isNotEmpty() && ! child->getBounds().isEmpty())
- tips.emplace_back (getLocalArea (child->getParentComponent(), child->getBounds()), tip);
- visit (*child);
- }
- };
- visit (*this);
- return tips;
- }
- // the small name bubble of every toolbar control (the hint bar keeps the full description)
- void MainComponent::setQuickTips()
- {
- auto tip = [this] (juce::Component& c, const juce::String& name, const char* actionId = nullptr) {
- ui::setQuickTip (c, name, actionId != nullptr ? shortcutText (actionId).trim() : juce::String());
- };
- tip (newButton, tr ("New project"), "file.new");
- tip (openButton, tr ("Open project"), "file.open");
- tip (saveButton, tr ("Save project"), "file.save");
- tip (exportButton, tr ("Export audio"), "file.export");
- tip (undoButton, tr ("Undo"), "edit.undo");
- tip (redoButton, tr ("Redo"), "edit.redo");
- tip (pluginPickerButton, tr ("Plugin picker"), "panel.quickAdd");
- tip (playButton, tr ("Play"), "transport.playStop");
- tip (stopButton, tr ("Stop"));
- tip (recordButton, tr ("Record"), "transport.record");
- tip (recordMenuButton, tr ("Recording options"));
- tip (patternModeButton, tr ("Pattern mode"), "transport.toggleMode");
- tip (songModeButton, tr ("Song mode"), "transport.toggleMode");
- tip (metronomeButton, tr ("Metronome"), "transport.metronome");
- tip (countInButton, tr ("Count-in"), "record.countIn");
- tip (waitInputButton, tr ("Wait for input"), "record.waitForInput");
- tip (typingPianoButton, tr ("Typing keyboard to piano"), "view.typingPiano");
- tip (tempoDisplay, tr ("Tempo (BPM)"));
- tip (timeDisplay, tr ("Song time"));
- tip (songPosition, tr ("Song position"));
- tip (masterVolume, tr ("Master volume"));
- tip (masterPitch, tr ("Master pitch"));
- tip (gridBox, tr ("Snap"));
- tip (patternBox, tr ("Pattern"));
- tip (newPatternButton, tr ("New pattern"));
- tip (patternMenuButton, tr ("Pattern options"));
- tip (perfMeter, tr ("CPU, memory and polyphony"));
- tip (output, tr ("Output monitor"));
- tip (swingSlider, tr ("Swing"));
- tip (rackFilterBox, tr ("Channel filter group"));
- tip (rackGraphButton, tr ("Graph editor"));
- tip (rackPianoRollButton, tr ("Piano-roll view"), "rack.pianoRollView");
- tip (rackLoopButton, tr ("Channel looping"));
- tip (rackLoopStarterButton, tr ("Loop Starter"));
- for (int i = 0; i < workspace::panelCount; ++i)
- tip (panelButtons[(std::size_t) i], tr (panelName ((Panel) i)), panelAction ((Panel) i));
- }
- void MainComponent::timerCallback()
- {
- const uitrace::Scope trace ("MainComponent timer", false);
- {
- const uitrace::Scope part ("timer: toolbar displays", false);
- output.update();
- timeDisplay.update();
- songPosition.update();
- masterVolume.update();
- masterPitch.update();
- updateRecordQuantise();
- }
- if (engine.isModified() != lastModified)
- {
- const uitrace::Scope part ("timer: title", false);
- lastModified = engine.isModified();
- updateTitle();
- }
- // the Browser's "Project folder" follows the project's file (.lynx, or the .flp it was imported from)
- const uitrace::Scope partFolders ("timer: project folder / recording target", false);
- browser.setProjectFile (currentFile != juce::File() ? currentFile : importedFlpFile);
- // and so does where audio is recorded ("<project folder>/Audio/Recorded", FL-like take names)
- engine.setRecordingTarget (recordingFolderFor (currentFile != juce::File() ? currentFile : importedFlpFile),
- projectName.isNotEmpty() ? juce::File::createLegalFileName (projectName) : juce::String());
- // a backup copy every few minutes (Settings › General) when there are changes
- // (not in the middle of a recording: FL also postpones the timed backup until the transport is free)
- if (autosaveMinutes > 0 && ++autosaveTicks >= 30 * 60 * autosaveMinutes && ! engine.isRecording())
- {
- autosaveTicks = 0;
- if (engine.isModified())
- autosave();
- }
- if (const auto scan = engine.getPluginHost().backgroundScan(); scan.finished != scansSeen)
- {
- scansSeen = scan.finished;
- ui::postHint ({ scan.found == 1 ? tr ("Plugin scan finished: 1 new plugin.")
- : tr ("Plugin scan finished: {0} new plugins.", { juce::String (scan.found) }), {}, false, false },
- 6000);
- }
- // a hosted plugin crashed inside a call: it was switched off (bypassed / silent) and LYNX kept running
- if (const auto crashes = pluginCrashCount(); crashes != pluginCrashesSeen)
- {
- pluginCrashesSeen = crashes;
- juce::StringArray names, lines;
- for (const auto& c : pluginCrashes())
- {
- const auto name = juce::String::fromUTF8 (c.plugin.c_str());
- names.addIfNotAlreadyThere (name);
- lines.add (juce::Time::getCurrentTime().toISO8601 (true) + " " + name + " " + crashguard::describe (c.code) + " 0x"
- + juce::String::toHexString ((juce::int64) c.code));
- }
- PluginHost::settingsFolder().getChildFile ("plugin-crashes.log").appendText (lines[lines.size() - 1] + "\n");
- juce::AlertWindow::showMessageBoxAsync (
- juce::MessageBoxIconType::WarningIcon, tr ("Plugin crashed"),
- tr ("The plugin \"{0}\" crashed and was switched off, so LYNX SHARE and your project kept running (the effect is bypassed, an "
- "instrument stays silent). Save your project; the plugin loads again the next time you open it.",
- { names[names.size() - 1] }));
- }
- auto& transport = engine.getTransport();
- if (! heldKeys.empty())
- {
- if (! juce::Process::isForegroundProcess()) // switched to another app with keys down: no key-up will come
- heldKeys.releaseAll();
- else // keys released while another window (a detached panel, a dialog) had the focus
- keyStateChanged (false);
- }
- // hint bar: a gesture's own posted hint, else the control under the mouse (while it is dragged, the
- // control that was pressed, at the point it was pressed, so its value updates live); MIDI learn and
- // recording states first
- if (! hintsFrozen)
- {
- const uitrace::Scope part ("timer: hint", false);
- ui::Hint hint;
- bool live = false;
- if (engine.isLearningMidi())
- hint.text = tr ("Move a knob/fader on the MIDI controller to link it to the parameter...");
- else if (engine.isWaitingForInput() || engine.isCountingIn())
- hint.text = idleHint();
- else if (auto posted = ui::postedHint())
- {
- hint = *posted;
- live = true;
- }
- else if (isShowing())
- {
- const auto source = juce::Desktop::getInstance().getMainMouseSource();
- if (auto* under = source.getComponentUnderMouse())
- {
- live = source.isDragging();
- const auto at = live ? source.getLastMouseDownPosition() : source.getScreenPosition();
- hint = ui::hintFor (under, under->getLocalPoint (nullptr, at).roundToInt());
- }
- }
- if (hint.isEmpty())
- {
- hint.text = idleHint();
- live = false;
- }
- hintBar.setHint (hint, live && hint.value.isNotEmpty());
- if (++tweakTicks >= 3) // 10 times a second
- {
- tweakTicks = 0;
- refreshTweakReadout();
- }
- }
- const auto playing = transport.playing.load();
- playButton.setToggleState (playing, juce::dontSendNotification);
- // CPU / memory / polyphony, a few times a second
- if (++meterTicks >= 8 && perfMeter.isVisible() && ! hintsFrozen)
- {
- const uitrace::Scope part ("timer: performance meter", false);
- meterTicks = 0;
- const auto held = (int) heldKeys.size();
- const auto notes = playing ? songstats::soundingNotes (engine.getSong(), transport.positionTicks.load()) : 0;
- perfMeter.setValues (engine.getDeviceManager().getCpuUsage(), toolbar::PerformanceMeter::processMemoryBytes(), notes + held);
- const auto rt = engine.getRtStats().snapshot();
- juce::StringArray heaviest;
- for (const auto& u : engine.getHeaviestUnits())
- if (heaviest.size() < 3 && u.load >= 0.01)
- heaviest.add (u.name + " " + juce::String (juce::roundToInt (u.load * 100.0)) + "%");
- auto* device = engine.getDeviceManager().getCurrentAudioDevice();
- perfMeter.setRealtime (rt.overBudget, rt.lateCalls, engine.getRtStats().takeWindowMaxLoad(), heaviest,
- device != nullptr ? device->getXRunCount() : -1);
- // dropouts on Windows shared mode: suggest the interface's ASIO driver (round 160), worked out once per device type
- if (device != nullptr && (rt.overBudget > 0 || rt.lateCalls > 0) && device->getTypeName() != driverTipType)
- {
- driverTipType = device->getTypeName();
- std::vector<std::string> asio;
- for (auto* type : engine.getDeviceManager().getAvailableDeviceTypes())
- if (type->getTypeName() == "ASIO")
- for (const auto& name : type->getDeviceNames())
- asio.push_back (name.toStdString());
- perfMeter.setDriverTip (juce::String::fromUTF8 (prefs::suggestedAsioDriver (driverTipType.toStdString(), asio).c_str()));
- }
- // Linux: the first dropouts without real-time priority explain how to get it, once per installation (round 161)
- if (device != nullptr && ! realtimeHintChecked && (rt.overBudget > 0 || device->getXRunCount() > 0)
- && lynx::rt::status() == lynx::rt::Status::denied)
- {
- realtimeHintChecked = true;
- if (lynx::rt::shouldShowHint (PluginHost::settingsFolder().getChildFile ("realtime-hint-shown")))
- juce::AlertWindow::showMessageBoxAsync (
- juce::MessageBoxIconType::InfoIcon, tr ("Real-time priority"),
- tr ("The sound broke up, and Linux runs LYNX SHARE's audio thread at normal priority. Real-time priority makes dropouts much rarer:\n\n"
- "- install rtkit (package \"rtkit\"; most desktops already have it), or\n"
- "- add yourself to the \"audio\" group with an rtprio limit in /etc/security/limits.d (as for JACK),\n\n"
- "then log out and in again. LYNX SHARE never needs root. Options > Audio settings shows the current state."));
- }
- }
- if (++midiInputTicks % 30 == 1) // the open MIDI inputs, once a second
- midiLightInputs = engine.getActiveMidiInputs();
- midiLight.update (engine.getMidiActivity(), midiLightInputs);
- // If a closed dialog left the main window without a focused component, take it back so the PC keyboard
- // keeps playing. Only while the main window itself is the active one: another LYNX window (Audio editor,
- // Quick-add palette, a plugin's editor, a detached panel) keeps its focus (issue #4: grabbing it here, 30
- // times a second, pulled the main window to the front and closed the plugins' drop-down menus).
- if (shouldReclaimKeyboardFocus())
- grabKeyboardFocus();
- }
- bool MainComponent::shouldReclaimKeyboardFocus()
- {
- auto* peer = getPeer();
- return ! hasKeyboardFocus (true) && isShowing() && peer != nullptr && peer->isFocused() && juce::Process::isForegroundProcess()
- && juce::Component::getCurrentlyModalComponent() == nullptr && ! workspace.isDetachedWindowActive();
- }
- void MainComponent::updateTitle()
- {
- repaint (titleArea); // the project name in the toolbar
- if (! engine.isModified()) // what is on disk now: the reference for "unused recordings" after a Discard
- savedSamples = safety::referencedSamples (engine.getSong());
- if (auto* window = getTopLevelComponent())
- window->setName ((engine.isModified() ? "* " : "")
- + (projectName.isNotEmpty() ? "LYNX SHARE - " + projectName : juce::String ("LYNX SHARE")) + importedSuffix);
- }
- std::unique_ptr<juce::AlertWindow> MainComponent::makeConfirmDiscardWindow()
- {
- auto window = std::make_unique<juce::AlertWindow> (tr ("Save changes?"), tr ("The project has unsaved changes."),
- juce::MessageBoxIconType::QuestionIcon);
- window->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (tr ("Discard"), 2);
- window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- return window;
- }
- void MainComponent::confirmDiscard (std::function<void()> then)
- {
- if (! engine.isModified())
- {
- offerToDeleteUnusedRecordings (true, std::move (then));
- return;
- }
- auto* window = makeConfirmDiscardWindow().release();
- window->enterModalState (true, juce::ModalCallbackFunction::create ([this, then] (int result) {
- if (result == 1)
- {
- save (false);
- if (! engine.isModified()) // saved (did not cancel "save as")
- offerToDeleteUnusedRecordings (true, then);
- }
- else if (result == 2)
- offerToDeleteUnusedRecordings (false, then);
- }),
- true);
- }
- juce::File MainComponent::recordingFolderFor (const juce::File& projectFile) const
- {
- // FL records into the project data folder's "Audio\Recorded" (REA round 134); LYNX's data folder is the folder of
- // the project file. Unsaved projects record into the global recordings folder.
- return projectFile == juce::File() ? AudioEngine::defaultRecordingFolder()
- : projectFile.getParentDirectory().getChildFile (safety::recordedSubfolder);
- }
- namespace
- {
- // FL's Keep / Delete question about recorded files nothing uses (FLEngine FUN_00ed1380, REA round 134)
- void askKeepOrDelete (const juce::String& message, const std::vector<juce::File>& files, std::function<void (bool)> done)
- {
- juce::String list;
- for (std::size_t i = 0; i < files.size() && i < 8; ++i)
- list << "\n " << files[i].getFileName();
- if (files.size() > 8)
- list << "\n " << tr ("...and {0} more", { juce::String ((int) files.size() - 8) });
- auto* w = new juce::AlertWindow (tr ("Unused recordings"), message + list, juce::MessageBoxIconType::QuestionIcon);
- w->addButton (tr ("Keep"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->addButton (tr ("Delete"), 1);
- w->enterModalState (true, juce::ModalCallbackFunction::create ([done] (int result) { done (result == 1); }), true);
- }
- // to the recycle bin when the system has one (FL's "Delete recorded files to recycle bin")
- int removeFiles (const std::vector<juce::File>& files)
- {
- int removed = 0;
- for (const auto& f : files)
- removed += f.existsAsFile() && (f.moveToTrash() || f.deleteFile());
- return removed;
- }
- } // namespace
- void MainComponent::offerToDeleteUnusedRecordings (bool keepsCurrentState, std::function<void()> then)
- {
- // the takes of this session the project on disk will not use: deleted takes, undone recordings, a project closed
- // without saving (FL: "You created ... sample file(s) that are no longer used if the project isn't saved")
- std::vector<std::string> recorded;
- for (const auto& f : engine.getSessionRecordings())
- if (f.existsAsFile())
- recorded.push_back (f.getFullPathName().toStdString());
- const auto referenced = keepsCurrentState ? safety::referencedSamples (engine.getSong()) : savedSamples;
- std::vector<juce::File> unused;
- for (const auto& path : safety::unusedRecordings (recorded, referenced))
- unused.emplace_back (juce::String::fromUTF8 (path.c_str()));
- if (unused.empty() || ! askUnusedRecordings || ! persistent)
- {
- then();
- return;
- }
- askKeepOrDelete (unused.size() == 1 ? tr ("You recorded 1 audio file that this project will not use.")
- : tr ("You recorded {0} audio files that this project will not use.", { juce::String ((int) unused.size()) }),
- unused, [safe = juce::Component::SafePointer<MainComponent> (this), unused, then] (bool remove) {
- if (safe == nullptr)
- return;
- if (remove)
- removeFiles (unused);
- safe->engine.forgetRecordings (unused); // asked once per file
- then();
- });
- }
- void MainComponent::deleteUnusedRecordingsAndSave()
- {
- // FL's Tools › Macros "Delete unused files and save project", for the files this project recorded: every take in
- // its recording folder (and this session's takes elsewhere) that no channel or clip uses
- if (currentFile == juce::File())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Delete unused recordings"),
- tr ("Save the project first: its recordings are kept next to it, in {0}.", { juce::String (safety::recordedSubfolder) }));
- return;
- }
- std::vector<std::string> recorded;
- const auto stem = currentFile.getFileNameWithoutExtension() + "_";
- for (const auto& f : recordingFolderFor (currentFile).findChildFiles (juce::File::findFiles, false, "*.wav"))
- if (f.getFileName().startsWithIgnoreCase (stem)) // other projects in the same folder record there too
- recorded.push_back (f.getFullPathName().toStdString());
- for (const auto& f : engine.getSessionRecordings())
- if (f.existsAsFile())
- recorded.push_back (f.getFullPathName().toStdString());
- std::vector<juce::File> unused;
- for (const auto& path : safety::unusedRecordings (recorded, safety::referencedSamples (engine.getSong())))
- unused.emplace_back (juce::String::fromUTF8 (path.c_str()));
- if (unused.empty())
- {
- save (false);
- ui::postHint ({ tr ("No unused recordings. Project saved."), {}, false, false }, 4000);
- return;
- }
- askKeepOrDelete (tr ("This project has {0} unused recording(s). Deleting them cannot be undone (they go to the recycle bin).",
- { juce::String ((int) unused.size()) }),
- unused, [safe = juce::Component::SafePointer<MainComponent> (this), unused] (bool remove) {
- if (safe == nullptr)
- return;
- if (remove)
- {
- const auto n = removeFiles (unused);
- safe->engine.forgetRecordings (unused);
- ui::postHint ({ tr ("Deleted {0} unused recording(s).", { juce::String (n) }), {}, false, false }, 4000);
- }
- safe->save (false);
- });
- }
- namespace
- {
- juce::String projectStem (const juce::String& projectName)
- {
- return projectName.isNotEmpty() ? juce::File::createLegalFileName (projectName) : juce::String ("untitled");
- }
- // the backup folder's projects with their modification times (for rotation and "revert to last backup")
- std::vector<safety::BackupFile> backupFiles (const juce::File& folder)
- {
- std::vector<safety::BackupFile> files;
- for (const auto& f : folder.findChildFiles (juce::File::findFiles, false, juce::String ("*") + ProjectFile::extension))
- files.push_back ({ f.getFileNameWithoutExtension().toStdString(), f.getLastModificationTime().toMilliseconds() });
- return files;
- }
- // "Song (autosaved on 2026-10-20 at 14h19)" in `folder`, "_2"... when that minute is taken (FL's naming, REA round 118)
- juce::File newBackupFile (const juce::File& folder, const juce::String& stem, safety::BackupKind kind)
- {
- const auto now = juce::Time::getCurrentTime();
- const auto name = safety::backupName (stem.toStdString(), kind, now.getYear(), now.getMonth() + 1, now.getDayOfMonth(), now.getHours(), now.getMinutes());
- const auto unique = safety::uniqueName (name, [&folder] (const std::string& n) {
- return folder.getChildFile (juce::String::fromUTF8 (n.c_str()) + ProjectFile::extension).exists();
- });
- return folder.getChildFile (juce::String::fromUTF8 (unique.c_str()) + ProjectFile::extension);
- }
- } // namespace
- void MainComponent::autosave()
- {
- // backup copy of the open project, so work isn't lost if something crashes ("Song (autosaved on 2026-10-20 at
- // 14h19).lynx" in the backup folder, like FL's Backup folder); only the newest few of each project are kept
- // The plugins' settings are read here (they answer on the message thread); writing the file (the big part:
- // every plugin's state, encoded) runs on a thread of its own, so the timed backup no longer freezes the screen
- // (round 151: 180 ms every two minutes on a project with 71 plugins). One at a time.
- if (autosaveRunning->load())
- return;
- const auto folder = autosaveFolder();
- folder.createDirectory();
- const auto stem = projectStem (projectName);
- {
- const uitrace::Scope trace ("autosave: plugin states", false);
- engine.capturePluginStates();
- }
- auto copy = std::make_shared<Song> (engine.getSong());
- const auto file = newBackupFile (folder, stem, safety::BackupKind::autosaved);
- autosaveRunning->store (true);
- juce::Thread::launch ([copy, file, running = autosaveRunning, safe = juce::Component::SafePointer<MainComponent> (this), stem] {
- juce::String error;
- const auto ok = ProjectFile::save (*copy, file, error);
- running->store (false);
- juce::MessageManager::callAsync ([safe, ok, error, stem] {
- if (safe == nullptr)
- return;
- if (! ok)
- ui::postHint ({ tr ("Autosave failed: {0}", { error }), {}, false, false }, 6000);
- else
- safe->rotateBackups (stem);
- });
- });
- }
- void MainComponent::rotateBackups (const juce::String& stem)
- {
- const auto folder = autosaveFolder();
- for (const auto& old : safety::backupsToRemove (backupFiles (folder), stem.toStdString(), autosaveKeep))
- {
- const auto f = folder.getChildFile (juce::String::fromUTF8 (old.c_str()) + ProjectFile::extension);
- f.setReadOnly (false); // (FL clears the read-only flag before deleting an old backup too)
- f.deleteFile();
- }
- }
- void MainComponent::keepOverwrittenCopy (const juce::File& file)
- {
- // FL moves the file a save replaces into its Backup folder as "Song (overwritten on ... at ...)"; LYNX copies it
- // (the save itself still goes through a temporary file and a rename)
- const auto folder = autosaveFolder();
- if (! file.existsAsFile() || file.isAChildOf (folder))
- return;
- folder.createDirectory();
- const auto stem = projectStem (file.getFileNameWithoutExtension());
- if (file.copyFileTo (newBackupFile (folder, stem, safety::BackupKind::overwritten)))
- rotateBackups (stem);
- }
- void MainComponent::saveNewVersion()
- {
- // FL's "Save new version": Song.flp -> Song_2.flp -> Song_3.flp, next to the current file
- if (currentFile == juce::File())
- {
- save (true);
- return;
- }
- const auto folder = currentFile.getParentDirectory();
- const auto name = safety::nextVersionName (currentFile.getFileNameWithoutExtension().toStdString(), [&folder] (const std::string& n) {
- return folder.getChildFile (juce::String::fromUTF8 (n.c_str()) + ProjectFile::extension).exists();
- });
- const auto file = folder.getChildFile (juce::String::fromUTF8 (name.c_str()) + ProjectFile::extension);
- juce::String error;
- engine.capturePluginStates();
- if (! ProjectFile::save (engine.getSong(), file, error))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- return;
- }
- engine.markSaved();
- rememberRecent (file);
- currentFile = file;
- projectName = file.getFileNameWithoutExtension();
- importedSuffix = {};
- updateTitle();
- ui::postHint ({ tr ("Saved as a new version: {0}", { file.getFileName() }), {}, false, false }, 5000);
- }
- void MainComponent::revertToLastBackup()
- {
- const auto stem = projectStem (projectName);
- const auto name = safety::newestBackup (backupFiles (autosaveFolder()), stem.toStdString());
- if (name.empty())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Revert to last backup"),
- tr ("There is no backup of this project yet."));
- return;
- }
- const auto backup = autosaveFolder().getChildFile (juce::String::fromUTF8 (name.c_str()) + ProjectFile::extension);
- const auto when = backup.getLastModificationTime().formatted ("%Y-%m-%d %H:%M");
- auto* w = new juce::AlertWindow (tr ("Revert to last backup"),
- tr ("Replace the open project with its backup from {0}?\n{1}\n\nThe project file itself only changes when you save.",
- { when, backup.getFileName() }),
- juce::MessageBoxIconType::QuestionIcon);
- w->addButton (tr ("Revert"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([safe = juce::Component::SafePointer<MainComponent> (this), backup] (int result) {
- if (safe == nullptr || result != 1)
- return;
- juce::String error;
- auto song = ProjectFile::load (backup, error);
- if (! song)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- safe->engine.getPluginHost().applySubstitutes (*song);
- safe->engine.stop();
- safe->engine.rewind();
- safe->engine.setSong (std::move (*song));
- safe->engine.markModified(); // Save writes it back to the project's own file
- safe->updateTitle();
- safe->playlist.showSongAfterOpen();
- }),
- true);
- }
- void MainComponent::exportPackage()
- {
- // FL's zipped loop package: the project and every sample it uses in one .zip
- const auto stem = projectStem (projectName);
- const auto start = (currentFile != juce::File() ? currentFile.getParentDirectory()
- : juce::File::getSpecialLocation (juce::File::userDocumentsDirectory))
- .getChildFile (stem + ".zip");
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Export project with samples"), start, "*.zip");
- fileChooser->launchAsync (juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
- [safe = juce::Component::SafePointer<MainComponent> (this), stem] (const juce::FileChooser& chooser) {
- auto zip = chooser.getResult();
- if (safe == nullptr || zip == juce::File())
- return;
- zip = zip.withFileExtension (".zip");
- safe->engine.capturePluginStates();
- ProjectPackage::Result result;
- juce::String error;
- if (! ProjectPackage::exportZip (safe->engine.getSong(), stem, zip, result, error))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- return;
- }
- auto text = tr ("{0} saved with {1} samples.", { zip.getFileName(), juce::String (result.files) });
- if (! result.missing.isEmpty())
- text << "\n\n" << tr ("Not on this PC (left out):") << "\n" << result.missing.joinIntoString ("\n");
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Export project with samples"), text);
- });
- }
- void MainComponent::collectSamples()
- {
- // FL's "Export project data files": copy the samples the project uses into one folder (and use the copies)
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Copy the project's samples to..."),
- currentFile != juce::File() ? currentFile.getParentDirectory()
- : juce::File::getSpecialLocation (juce::File::userDocumentsDirectory));
- fileChooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
- [safe = juce::Component::SafePointer<MainComponent> (this)] (const juce::FileChooser& chooser) {
- const auto folder = chooser.getResult();
- if (safe == nullptr || folder == juce::File())
- return;
- std::map<std::string, std::string> relink;
- ProjectPackage::Result result;
- juce::String error;
- if (! ProjectPackage::collectSamples (safe->engine.getSong(), folder, relink, result, error))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not copy"), error);
- return;
- }
- safe->engine.editSong ([&relink] (Song& song) { applyRelocations (song, relink); });
- auto text = tr ("{0} samples copied to {1}. The project now uses the copies.", { juce::String (result.files), folder.getFullPathName() });
- if (! result.missing.isEmpty())
- text << "\n\n" << tr ("Not on this PC (left out):") << "\n" << result.missing.joinIntoString ("\n");
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("Collect project samples"), text);
- });
- }
- void MainComponent::saveToNewProjectFolder()
- {
- // FL's "Save to new project folder...": <chosen name>/<name>.lynx, so the project gets its own data folder (its
- // recordings go to <name>/Audio/Recorded). This session's takes still in the global recordings folder move along
- // (copied there, the project uses the copies; the originals are then offered for deletion as unused).
- const auto start = currentFile != juce::File() ? currentFile.getParentDirectory()
- : lynx::platform::documentsFolder().getChildFile ("LYNX/Projects");
- start.createDirectory();
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Save to new project folder"),
- start.getChildFile (projectName.isNotEmpty() ? juce::File::createLegalFileName (projectName) : juce::String ("untitled")),
- juce::String ("*") + ProjectFile::extension);
- fileChooser->launchAsync (juce::FileBrowserComponent::saveMode, [safe = juce::Component::SafePointer<MainComponent> (this)] (const juce::FileChooser& chooser) {
- const auto chosen = chooser.getResult();
- if (safe == nullptr || chosen == juce::File())
- return;
- const auto name = chosen.getFileNameWithoutExtension();
- auto folder = chosen.getParentDirectory().getChildFile (name);
- if (folder.exists() && ! folder.findChildFiles (juce::File::findFilesAndDirectories, false).isEmpty())
- folder = folder.getNonexistentSibling (false);
- if (! folder.createDirectory())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"),
- tr ("Could not create the folder {0}", { folder.getFullPathName() }));
- return;
- }
- auto& self = *safe;
- const auto recorded = folder.getChildFile (safety::recordedSubfolder);
- std::map<std::string, std::string> relink;
- const auto used = safety::referencedSamples (self.engine.getSong());
- for (const auto& take : self.engine.getSessionRecordings())
- if (take.existsAsFile() && take.isAChildOf (AudioEngine::defaultRecordingFolder())
- && std::any_of (used.begin(), used.end(), [&take] (const std::string& p) { return safety::samePath (p, take.getFullPathName().toStdString()); }))
- {
- recorded.createDirectory();
- const auto copy = recorded.getNonexistentChildFile (take.getFileNameWithoutExtension(), take.getFileExtension(), false);
- if (take.copyFileTo (copy))
- relink[take.getFullPathName().toStdString()] = copy.getFullPathName().toStdString();
- }
- if (! relink.empty())
- self.engine.editSong ([&relink] (Song& song) { applyRelocations (song, relink); });
- const auto file = folder.getChildFile (name + ProjectFile::extension);
- juce::String error;
- self.engine.capturePluginStates();
- if (! ProjectFile::save (self.engine.getSong(), file, error))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- return;
- }
- self.engine.markSaved();
- self.rememberRecent (file);
- self.currentFile = file;
- self.projectName = name;
- self.importedSuffix = {};
- self.updateTitle();
- ui::postHint ({ tr ("Saved in its own folder: {0}", { folder.getFullPathName() }), {}, false, false }, 5000);
- });
- }
- void MainComponent::startSession()
- {
- // Like FL's backup on crash: a marker exists while LYNX runs; finding one at start means the last session
- // ended without closing (crash, power loss), so the newest backup written during it is offered.
- sessionLock = std::make_unique<juce::InterProcessLock> ("LYNX-ui-session");
- if (! sessionLock->enter (0))
- {
- sessionLock.reset(); // another LYNX window is running: it owns the marker
- return;
- }
- sessionMarker = lynx::platform::settingsFile ("session-running.txt");
- if (sessionMarker.existsAsFile())
- {
- const auto previousStart = juce::Time (sessionMarker.loadFileAsString().trim().getLargeIntValue());
- juce::Timer::callAfterDelay (2500, [safe = juce::Component::SafePointer<MainComponent> (this), previousStart] {
- if (safe != nullptr)
- safe->checkPreviousSession (previousStart);
- });
- }
- sessionMarker.getParentDirectory().createDirectory();
- sessionMarker.replaceWithText (juce::String (juce::Time::getCurrentTime().toMilliseconds()));
- // takes that were recording when LYNX stopped (crash, power loss, closed while recording): after the backup offer
- juce::Timer::callAfterDelay (4000, [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr)
- safe->checkInterruptedTakes();
- });
- }
- void MainComponent::checkInterruptedTakes()
- {
- if (juce::Component::getCurrentlyModalComponent() != nullptr) // a dialog is open (the backup offer): ask later
- {
- juce::Timer::callAfterDelay (2000, [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr)
- safe->checkInterruptedTakes();
- });
- return;
- }
- std::vector<juce::File> folders { engine.getRecordingFolder() };
- const auto takes = engine.recoverInterruptedTakes (folders);
- if (takes.empty())
- return;
- juce::StringArray names;
- for (const auto& j : takes)
- names.add (juce::File (juce::String::fromUTF8 (j.wav.c_str())).getFileName());
- const auto folder = juce::File (juce::String::fromUTF8 (takes.front().wav.c_str())).getParentDirectory();
- auto* w = new juce::AlertWindow (tr ("Recordings recovered"),
- tr ("LYNX SHARE was recording when it stopped. These takes were saved and repaired:\n{0}\n\nPut them on the Playlist "
- "where they were recorded?", { names.joinIntoString ("\n") }),
- juce::MessageBoxIconType::InfoIcon);
- w->addButton (tr ("Put them on the Playlist"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Show the folder"), 2);
- w->addButton (tr ("Keep the files only"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([safe = juce::Component::SafePointer<MainComponent> (this), takes, folder] (int result) {
- if (safe == nullptr)
- return;
- if (result == 1)
- {
- const auto placed = safe->engine.placeRecoveredTakes (takes);
- ui::postHint ({ tr ("{0} recovered take(s) placed on the Playlist", { juce::String (placed) }), {}, false, false }, 5000);
- }
- else
- {
- if (result == 2)
- folder.startAsProcess();
- safe->engine.forgetInterruptedTakes (takes);
- }
- }),
- true);
- }
- void MainComponent::checkPreviousSession (juce::Time sessionStart)
- {
- if (juce::Component::getCurrentlyModalComponent() != nullptr) // the setup wizard or another dialog: ask later
- {
- juce::Timer::callAfterDelay (2000, [safe = juce::Component::SafePointer<MainComponent> (this), sessionStart] {
- if (safe != nullptr)
- safe->checkPreviousSession (sessionStart);
- });
- return;
- }
- const auto folder = autosaveFolder();
- const auto name = safety::crashRecoveryCandidate (backupFiles (folder), sessionStart.toMilliseconds());
- if (name.empty())
- return; // nothing was saved in that session
- const auto backup = folder.getChildFile (juce::String::fromUTF8 (name.c_str()) + ProjectFile::extension);
- auto* w = new juce::AlertWindow (tr ("LYNX SHARE did not close properly"),
- tr ("The last session ended unexpectedly. Open the newest backup it saved?\n{0} ({1})",
- { backup.getFileName(), backup.getLastModificationTime().formatted ("%Y-%m-%d %H:%M") }),
- juce::MessageBoxIconType::WarningIcon);
- w->addButton (tr ("Open backup"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Open backup folder"), 2);
- w->addButton (tr ("Ignore"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([safe = juce::Component::SafePointer<MainComponent> (this), backup, folder] (int result) {
- if (safe == nullptr)
- return;
- if (result == 1)
- safe->confirmDiscard ([safe, backup] {
- if (safe != nullptr)
- safe->openLynxProject (backup);
- });
- else if (result == 2)
- folder.startAsProcess();
- }),
- true);
- }
- void MainComponent::newProject (bool askAlways)
- {
- confirmDiscard ([this, askAlways] {
- if (! askAlways && ! newProjectDialogEnabled())
- {
- startNewProject (makeNewProject(), {});
- return;
- }
- showNewProjectDialog ([safe = juce::Component::SafePointer<MainComponent> (this)] (Song song, juce::File file) {
- if (safe != nullptr)
- safe->startNewProject (std::move (song), file);
- });
- });
- }
- void MainComponent::startNewProject (Song song, const juce::File& file)
- {
- engine.stop();
- engine.rewind();
- engine.setSong (std::move (song));
- engine.markCreatedNow(); // Project info › created (a template's own date is kept, as FL does)
- currentFile = juce::File();
- projectName = {};
- importedSuffix = {};
- if (file != juce::File())
- {
- juce::String error;
- file.getParentDirectory().createDirectory();
- if (ProjectFile::save (engine.getSong(), file, error))
- {
- engine.markSaved();
- rememberRecent (file);
- currentFile = file;
- projectName = file.getFileNameWithoutExtension();
- }
- else
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- }
- updateTitle();
- }
- void MainComponent::saveAsTemplate()
- {
- auto* w = new juce::AlertWindow (tr ("Save as template"), tr ("The template appears in File › New project... (saved in {0})", { userTemplatesFolder().getFullPathName() }),
- juce::MessageBoxIconType::NoIcon);
- w->addTextEditor ("name", projectName.isNotEmpty() ? projectName : tr ("My template"));
- w->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([w, safe = juce::Component::SafePointer<MainComponent> (this)] (int result) {
- if (result != 1 || safe == nullptr)
- return;
- safe->engine.capturePluginStates();
- juce::String error;
- if (! saveUserTemplate (safe->engine.getSong(), w->getTextEditorContents ("name"), error))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- }), true);
- }
- void MainComponent::chooseFileToOpen()
- {
- confirmDiscard ([this] { chooseFileToOpenNow(); });
- }
- void MainComponent::chooseFileToOpenNow()
- {
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Open project"), currentFile.getParentDirectory(),
- juce::String ("*") + ProjectFile::extension + ";*.dawproj;*.flp;*.zip;*.mid;*.midi");
- fileChooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
- [this] (const juce::FileChooser& chooser) {
- if (chooser.getResult().existsAsFile())
- openFile (chooser.getResult());
- });
- }
- void MainComponent::openFile (const juce::File& file)
- {
- juce::String error;
- crashguard::note (("opening project " + file.getFileName()).toStdString()); // session breadcrumb (round 111)
- if (file.hasFileExtension ("zip"))
- {
- // a project package (File › Export project with samples, or FL's zipped loop package): extracted into a
- // folder of its own, then the project inside is opened (its samples are found next to it)
- const auto project = ProjectPackage::extractZip (file, ProjectPackage::defaultExtractRoot(), error);
- if (project == juce::File())
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- openFile (project);
- return;
- }
- if (file.hasFileExtension ("mid;midi"))
- {
- auto song = MidiFileIo::loadSong (file, error);
- if (! song)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- engine.stop();
- engine.rewind();
- engine.setSong (std::move (*song));
- currentFile = juce::File(); // imported: "Save" asks where to write the .lynx
- projectName = file.getFileNameWithoutExtension();
- rememberRecent (file);
- importedSuffix = " " + tr ("(imported from MIDI)");
- updateTitle();
- return;
- }
- if (file.hasFileExtension ("flp"))
- {
- if (! persistent) // (command-line modes open synchronously, without scanning)
- {
- importFlp (file);
- return;
- }
- // behind a progress panel (round 112): the project's unknown plugins get a targeted scan of just their files,
- // the samples are decoded off the message thread, the hosted plugins are created one by one with their names
- // shown; the panel's bar never sits still at 0 %
- if (projectLoadRunning())
- return;
- openFlpWithProgress (*this, engine, file, [safe = juce::Component::SafePointer<MainComponent> (this), file] (bool ok, const juce::String& error) {
- if (safe == nullptr)
- return;
- if (! ok)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- safe->flpImported (file);
- });
- return;
- }
- openLynxProject (file);
- }
- void MainComponent::importFlp (const juce::File& file)
- {
- juce::String error;
- loadtrace::begin (file.getFullPathName().toStdString());
- const auto ok = engine.importFlpFile (file, error);
- loadtrace::end();
- if (! ok)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- flpImported (file);
- }
- void MainComponent::flpImported (const juce::File& file)
- {
- {
- currentFile = juce::File(); // imported: "Save" asks where to write the .lynx
- importedFlpFile = file;
- projectName = file.getFileNameWithoutExtension();
- rememberRecent (file);
- importedSuffix = " " + tr ("(imported from FL Studio)");
- updateTitle();
- playlist.showSongAfterOpen();
- showMissingFiles (true);
- // FL opens Project info when the project's "Show on opening" box is on (event 0x0A, REA round 167g)
- if (engine.getSong().info.showOnOpen && platform::testMode())
- platform::testModeLog ("project info shown on open");
- else if (engine.getSong().info.showOnOpen)
- openSettings ((int) SettingsPage::info);
- }
- }
- void MainComponent::openLynxProject (const juce::File& file)
- {
- juce::String error;
- auto song = ProjectFile::load (file, error);
- if (! song)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- return;
- }
- // missing plugins get their LYNX substitute; substitutes whose original is installed now go back to it
- engine.getPluginHost().applySubstitutes (*song);
- engine.stop();
- engine.rewind();
- engine.setSong (std::move (*song));
- currentFile = file;
- importedFlpFile = juce::File();
- projectName = file.getFileNameWithoutExtension();
- importedSuffix = {};
- rememberRecent (file);
- updateTitle();
- playlist.showSongAfterOpen();
- if (persistent)
- {
- showMissingFiles (true);
- if (engine.getSong().info.showOnOpen && platform::testMode())
- platform::testModeLog ("project info shown on open");
- else if (engine.getSong().info.showOnOpen)
- openSettings (1);
- }
- }
- void MainComponent::openSettings (int page)
- {
- const juce::Component::SafePointer<MainComponent> safe (this);
- SettingsHooks hooks;
- hooks.browserFoldersChanged = [safe] {
- if (safe != nullptr)
- safe->browser.reloadUserFolders();
- };
- hooks.getGeneral = [safe] {
- GeneralOptions o;
- if (safe == nullptr)
- return o;
- o.language = i18n::saved();
- o.uiScale = safe->toolbarLayout.uiScale;
- o.compactMenus = theme::menus::compact();
- o.waveSpectral = ui::WaveformCache::spectral;
- o.waveStereo = ui::WaveformCache::stereo;
- o.noteNames = notenames::currentStyle.load();
- o.noteFlats = notenames::currentFlats.load();
- o.reducedEffects = skin::reducedEffects();
- o.gpuRendering = gpuRenderingEnabled();
- o.pluginStyle = skin::forcedStyle();
- o.splash = safe->startup.splash;
- o.startupSound = safe->startup.sound;
- o.scanAtStart = backgroundScanAtStart();
- o.typingPiano = safe->typingPiano;
- o.keepEditorsOpen = ChannelRackComponent::keepEditorsOpen;
- o.selectFirstChannelWithNotes = ChannelRackComponent::selectFirstChannelWithNotes;
- o.alternateUndo = safe->alternateUndo;
- o.rememberSeek = EditorGlobals::get().rememberSeek;
- o.editPatternsIn = PlaylistComponent::editPatternsIn;
- o.undoLevels = safe->engine.getUndoLevels();
- o.autosaveMinutes = safe->autosaveMinutes;
- o.autosaveKeep = safe->autosaveKeep;
- o.askUnusedRecordings = safe->askUnusedRecordings;
- o.crossfadesInNewProjects = newProjectDefaults().autoCrossfades;
- o.pluginSandbox = pluginSandboxEnabled();
- o.menuEntry = appImageMenuEntryInstalled();
- o.pluginSubstitutes = pluginSubstitutesEnabled();
- o.crashReports = (int) crashreporter::consent();
- o.checkUpdates = updater::automatic();
- return o;
- };
- hooks.setGeneral = [safe] (const GeneralOptions& o) {
- if (safe == nullptr)
- return;
- auto& self = *safe;
- if (o.uiScale != self.toolbarLayout.uiScale)
- {
- auto layout = self.toolbarLayout;
- layout.uiScale = toolbarlayout::clampScale (o.uiScale);
- self.setToolbarLayout (layout, true);
- }
- theme::menus::setCompact (o.compactMenus);
- if (o.reducedEffects != skin::reducedEffects() || o.pluginStyle != skin::forcedStyle())
- {
- skin::setReducedEffects (o.reducedEffects);
- skin::setForcedStyle (o.pluginStyle);
- for (int i = 0; i < juce::Desktop::getInstance().getNumComponents(); ++i) // open editors redraw at once
- if (auto* c = juce::Desktop::getInstance().getComponent (i)) c->repaint();
- }
- if (o.noteNames != notenames::currentStyle.load() || o.noteFlats != notenames::currentFlats.load())
- {
- notenames::currentStyle.store (juce::jlimit (0, 2, o.noteNames));
- notenames::currentFlats.store (o.noteFlats);
- for (int i = 0; i < juce::Desktop::getInstance().getNumComponents(); ++i) // the keyboards redraw with the new names
- if (auto* c = juce::Desktop::getInstance().getComponent (i)) c->repaint();
- }
- if (o.gpuRendering != gpuRenderingEnabled())
- setGpuRenderingEnabled (o.gpuRendering);
- if (o.waveSpectral != ui::WaveformCache::spectral || o.waveStereo != ui::WaveformCache::stereo)
- {
- ui::WaveformCache::spectral = o.waveSpectral;
- ui::WaveformCache::stereo = o.waveStereo;
- ui::WaveformCache::getInstance()->settingsChanged();
- }
- if (o.typingPiano != self.typingPiano)
- self.setTypingPiano (o.typingPiano);
- if (o.scanAtStart != backgroundScanAtStart())
- setBackgroundScanAtStart (o.scanAtStart);
- if (o.pluginSandbox != pluginSandboxEnabled())
- setPluginSandboxEnabled (o.pluginSandbox);
- if (runningAsAppImage() && o.menuEntry != appImageMenuEntryInstalled())
- setAppImageMenuEntry (o.menuEntry);
- if (o.pluginSubstitutes != pluginSubstitutesEnabled())
- setPluginSubstitutesEnabled (o.pluginSubstitutes);
- if (o.crashReports != (int) crashreporter::consent())
- crashreporter::setConsent ((crashreport::Consent) juce::jlimit (0, 2, o.crashReports));
- updater::setAutomatic (o.checkUpdates);
- ChannelRackComponent::keepEditorsOpen = o.keepEditorsOpen;
- ChannelRackComponent::selectFirstChannelWithNotes = o.selectFirstChannelWithNotes;
- self.alternateUndo = o.alternateUndo;
- EditorGlobals::get().rememberSeek = o.rememberSeek;
- PlaylistComponent::editPatternsIn = juce::jlimit (0, 2, o.editPatternsIn);
- self.startup.splash = o.splash;
- self.startup.sound = o.startupSound;
- self.engine.setUndoLevels (o.undoLevels);
- self.autosaveMinutes = prefs::clampAutosaveMinutes (o.autosaveMinutes);
- self.autosaveKeep = prefs::clampAutosaveKeep (o.autosaveKeep);
- self.askUnusedRecordings = o.askUnusedRecordings;
- newProjectDefaults().autoCrossfades = o.crossfadesInNewProjects;
- self.autosaveTicks = 0;
- self.saveUiSettings();
- if (o.language != i18n::saved())
- self.showLanguageChoice (o.language);
- };
- hooks.manageShortcuts = [safe] {
- if (safe != nullptr)
- safe->showShortcutManager();
- };
- hooks.managePlugins = [safe] {
- if (safe != nullptr)
- safe->showPluginManager();
- };
- showSettings (engine, (SettingsPage) juce::jlimit (0, (int) SettingsPage::theme, page), std::move (hooks)); // (Theme was clamped to MIDI)
- }
- void MainComponent::showPluginManager()
- {
- lynx::showPluginManager (engine, [safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe != nullptr)
- safe->openSettings ((int) SettingsPage::files);
- });
- }
- void MainComponent::showShortcutManager()
- {
- lynx::showShortcutManager ([safe = juce::Component::SafePointer<MainComponent> (this)] {
- if (safe == nullptr)
- return;
- safe->loadKeyMap();
- safe->setControlHints();
- safe->menuItemsChanged();
- });
- }
- void MainComponent::showMissingFiles (bool afterOpening)
- {
- if (afterOpening && platform::testMode()) // (LYNX_TEST_MODE: nothing waits for a click)
- {
- platform::testModeLog ("Missing files dialog after opening " + projectName);
- return;
- }
- MissingFilesInfo info;
- info.projectName = projectName;
- const auto fromFlp = importedFlpFile.existsAsFile() && currentFile == juce::File();
- const auto exists = [] (const std::string& path) { return juce::File::isAbsolutePath (juce::String::fromUTF8 (path.c_str())) && juce::File (juce::String::fromUTF8 (path.c_str())).existsAsFile(); };
- if (fromFlp)
- {
- // the import dropped the samples it couldn't find: its report keeps them (minus the ones located since)
- const auto& report = engine.getImportReport();
- for (const auto& m : report.missingFiles)
- info.files.push_back (m);
- info.plugins = engine.getMissingPluginDetails();
- info.autoRelocated = report.relocatedFiles;
- info.searchFolders.add (importedFlpFile.getParentDirectory().getFullPathName());
- }
- else
- {
- const auto& song = engine.getSong();
- info.files = findMissingSamples (song, exists);
- auto& host = engine.getPluginHost();
- auto addPlugin = [&info] (const PluginRef& ref, const std::string& user, const char* replacement) {
- const auto name = ref.name.empty() ? ref.id : ref.name;
- auto it = std::find_if (info.plugins.begin(), info.plugins.end(), [&] (const MissingPlugin& p) { return p.name == name; });
- if (it == info.plugins.end())
- it = info.plugins.insert (info.plugins.end(), MissingPlugin { name, {}, replacement });
- if (std::find (it->usedBy.begin(), it->usedBy.end(), user) == it->usedBy.end())
- it->usedBy.push_back (user);
- };
- for (const auto& c : song.channels)
- if (c.instrument == InstrumentKind::plugin && ! c.plugin.id.empty() && host.find (juce::String::fromUTF8 (c.plugin.id.c_str())) == nullptr)
- addPlugin (c.plugin, c.name, "Silence: the channel keeps the plugin's settings until it is installed");
- for (std::size_t t = 0; t < song.mixer.size(); ++t)
- for (const auto& fx : song.mixer[t].effects)
- if (fx.kind == EffectKind::plugin && ! fx.plugin.id.empty() && host.find (juce::String::fromUTF8 (fx.plugin.id.c_str())) == nullptr)
- addPlugin (fx.plugin, song.mixer[t].name.empty() ? (t == 0 ? std::string ("Master") : "Insert " + std::to_string (t)) : song.mixer[t].name,
- "Bypassed: the slot keeps the plugin's settings until it is installed");
- // played by a LYNX substitute until the original is installed
- for (std::size_t t = 0; t < song.mixer.size(); ++t)
- for (const auto& fx : song.mixer[t].effects)
- if (fx.isSubstitute())
- {
- const auto name = substituteOriginalName (fx);
- auto it = std::find_if (info.plugins.begin(), info.plugins.end(), [&] (const MissingPlugin& p) { return p.name == name; });
- if (it == info.plugins.end())
- it = info.plugins.insert (info.plugins.end(),
- MissingPlugin { name, {}, TR_NOOP ("LYNX SHARE substitute: {0} (the original plugin is used again once it is installed). FL Studio plays a missing plugin's slot unprocessed: a substitute slot's menu › Bypass all LYNX SHARE substitutes of this project does the same"),
- effectInfo (fx.kind).name });
- const auto user = song.mixer[t].name.empty() ? (t == 0 ? std::string ("Master") : "Insert " + std::to_string (t)) : song.mixer[t].name;
- if (std::find (it->usedBy.begin(), it->usedBy.end(), user) == it->usedBy.end())
- it->usedBy.push_back (user);
- }
- // installed, but failed to load: they play silence / are bypassed
- for (const auto& line : host.getLoadFailures())
- if (std::none_of (info.plugins.begin(), info.plugins.end(), [&] (const MissingPlugin& p) { return p.name == line.toStdString(); }))
- info.plugins.push_back ({ line.toStdString(), {}, "Silence: the plugin is installed but did not load" });
- if (currentFile.existsAsFile())
- info.searchFolders.add (currentFile.getParentDirectory().getFullPathName());
- }
- if (afterOpening && info.files.empty() && info.plugins.empty())
- {
- if (fromFlp)
- showImportReport();
- return;
- }
- auto safe = juce::Component::SafePointer<MainComponent> (this);
- const auto flp = fromFlp ? importedFlpFile : juce::File();
- showMissingFilesDialog (
- std::move (info),
- [safe, flp] (const std::map<std::string, std::string>& relocations) {
- if (safe == nullptr)
- return;
- if (flp != juce::File())
- {
- // FL import: imported again with the located samples (the channels become samplers, slices are read...)
- juce::String error;
- if (! safe->engine.importFlpFile (flp, error, relocations, true))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not open"), error);
- }
- else
- safe->engine.editSong ([&relocations] (Song& s) { applyRelocations (s, relocations); });
- safe->updateTitle();
- },
- [safe, afterOpening, fromFlp] {
- if (safe != nullptr && afterOpening && fromFlp)
- safe->showImportReport();
- });
- }
- void MainComponent::switchSmartDisableForAll()
- {
- // FL's Tools › Macros › "Switch smart disable for all plugins" (FLEngine FUN_0124d430, REA round 139): every
- // effect slot of every insert is set to smart disable
- engine.editSong ([] (Song& s) {
- for (auto& track : s.mixer)
- for (auto& slot : track.effects)
- slot.smartDisable = true;
- });
- }
- void MainComponent::exportAudio (int format)
- {
- showExportDialog (engine, currentFile.getParentDirectory(), projectName, format);
- }
- void MainComponent::importMidiFile()
- {
- const auto folder = currentFile.existsAsFile() ? currentFile.getParentDirectory() : juce::File::getSpecialLocation (juce::File::userMusicDirectory);
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Import MIDI file"), folder, "*.mid;*.midi");
- juce::Component::SafePointer<MainComponent> safe (this);
- fileChooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [safe] (const juce::FileChooser& fc) {
- const auto file = fc.getResult();
- if (safe == nullptr || file == juce::File())
- return;
- juce::String error;
- const auto midi = MidiFileIo::parseFile (file, error);
- if (! midi)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not import"), error);
- return;
- }
- static MidiFileIo::ImportOptions remembered; // FL keeps the window's choices
- showMidiImportDialog (file.getFileName(), *midi, remembered, false, [safe, file] (const MidiFileIo::ImportOptions& o) {
- remembered = o;
- if (safe != nullptr)
- safe->importMidiFile (file, o);
- });
- });
- }
- void MainComponent::importMidiFile (const juce::File& file, const MidiFileIo::ImportOptions& o)
- {
- juce::String error;
- if (o.newProject)
- {
- confirmDiscard ([this, file, o] {
- Song song;
- juce::String err;
- if (! MidiFileIo::importInto (song, file, o, err))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not import"), err);
- return;
- }
- engine.stop();
- engine.rewind();
- engine.setSong (std::move (song));
- currentFile = juce::File();
- projectName = file.getFileNameWithoutExtension();
- importedSuffix = " " + tr ("(imported from MIDI)");
- updateTitle();
- });
- return;
- }
- auto song = engine.getSong();
- if (! MidiFileIo::importInto (song, file, o, error))
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not import"), error);
- return;
- }
- engine.editSong ([&song] (Song& s) { s = std::move (song); });
- showPanel (Panel::channelRack);
- }
- void MainComponent::exportMidiFile()
- {
- // FL's File › Export › "MIDI file...": the arrangement's notes (or the current pattern's) as a Standard MIDI File
- const auto folder = currentFile.existsAsFile() ? currentFile.getParentDirectory() : juce::File::getSpecialLocation (juce::File::userMusicDirectory);
- const auto name = projectName.isNotEmpty() ? projectName : juce::String ("LYNX SHARE");
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Export MIDI file"), folder.getChildFile (name + ".mid"), "*.mid");
- juce::Component::SafePointer<MainComponent> safe (this);
- fileChooser->launchAsync (juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
- [safe] (const juce::FileChooser& fc) {
- auto file = fc.getResult();
- if (safe == nullptr || file == juce::File())
- return;
- if (! file.hasFileExtension (".mid;.midi"))
- file = file.withFileExtension (".mid");
- juce::String error;
- if (! MidiFileIo::saveSong (safe->engine.getSong(), file, error))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not export"), error);
- else
- file.revealToUser();
- });
- }
- void MainComponent::save (bool askForFile)
- {
- auto write = [this] (juce::File file) {
- if (! file.hasFileExtension (ProjectFile::extension))
- file = file.withFileExtension (ProjectFile::extension);
- juce::String error;
- engine.capturePluginStates(); // plugin state lives in the plugins; copy it before saving
- keepOverwrittenCopy (file); // the version this save replaces goes to the backup folder (like FL)
- if (ProjectFile::save (engine.getSong(), file, error))
- {
- engine.markSaved();
- rememberRecent (file);
- currentFile = file;
- projectName = file.getFileNameWithoutExtension();
- importedSuffix = {};
- updateTitle();
- }
- else
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
- };
- // a project opened from the backup folder is saved somewhere else (old backups there are deleted)
- if (! askForFile && currentFile != juce::File() && ! currentFile.isAChildOf (autosaveFolder()))
- {
- write (currentFile);
- return;
- }
- const auto startFolder = currentFile.isAChildOf (autosaveFolder()) ? juce::File::getSpecialLocation (juce::File::userDocumentsDirectory)
- : currentFile.getParentDirectory();
- fileChooser = std::make_unique<juce::FileChooser> (tr ("Save project"), startFolder, juce::String ("*") + ProjectFile::extension);
- fileChooser->launchAsync (juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
- [write] (const juce::FileChooser& chooser) {
- const auto file = chooser.getResult();
- if (file == juce::File())
- return;
- if (! file.isAChildOf (autosaveFolder()))
- {
- write (file);
- return;
- }
- // FL warns the same way: the backup folder is cleaned up as new backups arrive
- auto* w = new juce::AlertWindow (tr ("Save in the backup folder?"),
- tr ("This folder keeps LYNX SHARE's automatic backups and old ones are deleted as new "
- "ones arrive, so a project saved here can be lost. If you opened a backup, save it "
- "somewhere else."),
- juce::MessageBoxIconType::WarningIcon);
- w->addButton (tr ("Save anyway"), 1);
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([write, file] (int r) {
- if (r == 1)
- write (file);
- }),
- true);
- });
- }
- void MainComponent::placeHintBar (juce::Rectangle<int> row)
- {
- // the read-out takes the right part of the hint row once something was tweaked (2/5 of it, 170..280 px), and
- // only when the hint keeps at least 220 px
- const auto readoutWidth = juce::jlimit (170, 280, row.getWidth() * 2 / 5);
- if (tweakReadout.hasContent() && row.getWidth() - readoutWidth - 6 >= 220)
- {
- tweakReadout.setBounds (row.removeFromRight (readoutWidth));
- tweakReadout.setVisible (true);
- row.removeFromRight (6);
- }
- else
- {
- tweakReadout.setVisible (false);
- tweakReadout.setBounds ({});
- }
- hintBar.setVisible (true);
- hintBar.setBounds (row);
- }
- void MainComponent::refreshTweakReadout()
- {
- const auto had = tweakReadout.hasContent();
- if (const auto t = engine.getLastTweaked (0))
- tweakReadout.setContent (describeAutomationTarget (engine, *t), describeTargetValue (engine, *t));
- else
- tweakReadout.setContent ({}, {});
- if (had != tweakReadout.hasContent())
- resized(); // the read-out appears (or goes, with its target)
- }
- juce::PopupMenu MainComponent::makeLastTweakedMenu (int which)
- {
- juce::PopupMenu menu;
- const auto target = engine.getLastTweaked (which);
- if (! target)
- {
- menu.addItem (tr ("No parameter"), false, false, [] {});
- return menu;
- }
- // as FL: the parameter's name, then the items of its own menu (events, automation clip, remote control, value)
- const auto valueNow = describeTargetValue (engine, *target); // (round 162d: with its value, as the read-out shows it)
- ui::addItemHeader (menu, tr ("Parameter"), describeAutomationTarget (engine, *target) + (valueNow.isNotEmpty() ? ": " + valueNow : juce::String()),
- juce::Colours::transparentBlack);
- const auto& song = engine.getSong();
- int clip = -1;
- for (int a = 0; a < (int) song.automations.size(); ++a)
- if (song.automations[(std::size_t) a].target == *target)
- clip = a;
- juce::ignoreUnused (clip);
- addAutomationItem (menu, engine, *target, true);
- menu.addSectionHeader (tr ("Value"));
- const auto value = engine.currentTargetValue (*target);
- menu.addItem (tr ("Copy value"), value >= 0.0f, false, [value] { lastTweakedClipboard() = value; });
- menu.addItem (tr ("Paste value"), lastTweakedClipboard() >= 0.0f, false, [this, t = *target] { setTweakedValue (t, lastTweakedClipboard()); });
- menu.addItem (tr ("Type in value..."), value >= 0.0f, false, [this, t = *target, value] {
- auto spec = ui::percentSpec (describeAutomationTarget (engine, t), value);
- ui::typeValue (*this, spec, value, [this, t] (double v) { setTweakedValue (t, (float) v); });
- });
- return menu;
- }
- float& MainComponent::lastTweakedClipboard()
- {
- static float copied = -1.0f;
- return copied;
- }
- void MainComponent::setTweakedValue (const AutomationTarget& target, float value)
- {
- value = juce::jlimit (0.0f, 1.0f, value);
- auto plugin = false;
- engine.editSong ([&] (Song& s) { plugin = ! s.setTargetValue (target, value); });
- if (plugin)
- {
- if (target.kind == AutomationTargetKind::channelParam)
- if (auto* p = dynamic_cast<PluginInstrument*> (engine.getChannelInstrument (target.index).get()))
- p->setParameterFromUi (target.param, value);
- if (target.kind == AutomationTargetKind::effectParam)
- if (auto* p = dynamic_cast<PluginEffect*> (engine.getEffect (target.index, target.slot).get()))
- p->setParameterFromUi (target.param, value);
- }
- engine.noteTweaked (target);
- }
- juce::StringArray MainComponent::getMenuBarNames()
- {
- // FL's menu bar order (REA round 139): FILE EDIT ADD PATTERNS VIEW OPTIONS TOOLS HELP
- return { tr ("File"), tr ("Edit"), tr ("Add"), tr ("Patterns"), tr ("View"), tr ("Options"), tr ("Tools"), tr ("Help") };
- }
- juce::PopupMenu MainComponent::getMenuForIndex (int barIndex, const juce::String&)
- {
- juce::PopupMenu menu;
- // the bar's position → the menu built below (0 File, 1 Edit, 2 View, 3 Patterns, 4 Options, 5 Help, 10 Add, 11 Tools)
- static constexpr int menus[] = { 0, 1, 10, 3, 2, 4, 11, 5 };
- const auto index = juce::isPositiveAndBelow (barIndex, (int) std::size (menus)) ? menus[barIndex] : 5;
- if (index == 10)
- {
- // FL's ADD menu: a channel (LYNX's instruments and the installed plugins), a pattern, the plugin tools
- menu.addSectionHeader (tr ("Channel"));
- rack.addInstrumentItems (menu, -1);
- menu.addSectionHeader (tr ("Other"));
- // FL's "Automation for last tweaked parameter" (Add_AutoLastMenu → FUN_01231100, REA round 143)
- const auto last = engine.getLastTweaked (0);
- menu.addItem (last ? tr ("Automation for last tweaked parameter ({0})", { describeAutomationTarget (engine, *last) })
- : tr ("Automation for last tweaked parameter"),
- last.has_value(), false, [this] {
- if (const auto t = engine.getLastTweaked (0))
- createAutomationClip (engine, *t);
- });
- menu.addItem (tr ("Pattern"), [this] { newPatternButton.onClick(); });
- menu.addItem (tr ("Plugin manager..."), [this] { showPluginManager(); });
- return menu;
- }
- if (index == 11)
- {
- // FL's TOOLS menu, with the tools LYNX has (REA round 139)
- menu.addItem (tr ("Browser find") + shortcutText ("browser.search"), [this] {
- showPanel (Panel::browser);
- browser.focusSearch();
- });
- menu.addItem (tr ("One-click audio recording: arm the selected insert..."), [this] { armSelectedInsertForAudio(); });
- menu.addItem (tr ("Plugin performance monitor..."), [this] { showPluginMonitor (engine); });
- // FL's "Last tweaked parameters" section (LastTweaked1Menu / LastTweaked2Menu → FUN_0123d1d0, REA round 143):
- // the parameter's own menu for the last two moved controls
- menu.addSectionHeader (tr ("Last tweaked parameters"));
- menu.addSubMenu (tr ("Last tweaked"), makeLastTweakedMenu (0), engine.getLastTweaked (0).has_value());
- menu.addSubMenu (tr ("Next to last tweaked"), makeLastTweakedMenu (1), engine.getLastTweaked (1).has_value());
- menu.addSectionHeader (tr ("Macros"));
- menu.addItem (tr ("Stop sound (all notes off)"), [this] { engine.panic(); });
- menu.addItem (tr ("Select unused channels"), [this] {
- showPanel (Panel::channelRack);
- rack.selectUnused();
- });
- menu.addItem (tr ("Switch smart disable for all plugins"), [this] { switchSmartDisableForAll(); });
- menu.addItem (tr ("Prepare for performance mode..."), [this] { prepareForPerformance(); });
- menu.addItem (tr ("Delete unused recordings and save project..."), [this] { deleteUnusedRecordingsAndSave(); });
- menu.addItem (tr ("Collect project samples into a folder..."), [this] { collectSamples(); });
- return menu;
- }
- if (index == 0)
- {
- menu.addItem (tr ("New") + shortcutText ("file.new"), [this] { newProject(); });
- menu.addItem (tr ("New project..."), [this] { newProject (true); });
- juce::PopupMenu templates;
- const auto names = templateNames();
- for (int i = 0; i < (int) names.size(); ++i)
- templates.addItem (juce::String::fromUTF8 (names[(std::size_t) i].c_str()), [this, i] {
- confirmDiscard ([this, i] {
- engine.stop();
- engine.rewind();
- engine.setSong (makeNewProject (i));
- currentFile = juce::File();
- projectName = {};
- importedSuffix = {};
- updateTitle();
- });
- });
- menu.addSubMenu (tr ("New from template"), templates);
- menu.addItem (tr ("Open...") + shortcutText ("file.open"), [this] { chooseFileToOpen(); });
- menu.addSeparator();
- // FL's order (REA round 139): saving, then Export, then the recent projects listed in the menu itself
- menu.addItem (tr ("Save") + shortcutText ("file.save"), [this] { save (false); });
- menu.addItem (tr ("Save as...") + shortcutText ("file.saveAs"), [this] { save (true); });
- menu.addItem (tr ("Save new version") + shortcutText ("file.saveNewVersion"), [this] { saveNewVersion(); });
- menu.addItem (tr ("Save to new project folder..."), [this] { saveToNewProjectFolder(); });
- menu.addItem (tr ("Save as template..."), [this] { saveAsTemplate(); });
- menu.addItem (tr ("Delete unused recordings and save..."), [this] { deleteUnusedRecordingsAndSave(); });
- menu.addSeparator();
- {
- // FL's File › Import (ImportMenu › ImportMIDIMenu → FileImportMIDIFileAction, REA round 143)
- juce::PopupMenu imports;
- imports.addItem (tr ("MIDI file..."), [this] { importMidiFile(); });
- menu.addSubMenu (tr ("Import"), imports);
- }
- {
- // FL's File › Export (REA round 139): one entry per format, then the formats of the last export
- juce::PopupMenu exports;
- exports.addItem (tr ("Wave file..."), [this] { exportAudio (0); });
- exports.addItem (tr ("MP3 file...") + shortcutText ("file.exportMp3"), [this] { exportAudio (1); });
- exports.addItem (tr ("OGG file..."), [this] { exportAudio (2); });
- exports.addItem (tr ("FLAC file..."), [this] { exportAudio (3); });
- exports.addItem (tr ("MIDI file...") + shortcutText ("file.exportMidi"), [this] { exportMidiFile(); });
- exports.addItem (tr ("Last exported format(s)...") + shortcutText ("file.export"), [this] { exportAudio(); });
- exports.addSeparator();
- exports.addItem (tr ("Project with samples (.zip)..."), [this] { exportPackage(); });
- exports.addItem (tr ("Project data files (collect the samples into a folder)..."), [this] { collectSamples(); });
- menu.addSubMenu (tr ("Export"), exports);
- }
- menu.addSectionHeader (tr ("Recent projects"));
- const auto shown = juce::jmin (recent.getNumFiles(), 10);
- for (int i = 0; i < shown; ++i)
- {
- const auto file = recent.getFile (i);
- juce::PopupMenu::Item item (file.getFileName());
- item.shortcutKeyDescription = file.getParentDirectory().getFileName(); // its folder on the right
- item.setEnabled (file.existsAsFile()).setAction ([this, file] { confirmDiscard ([this, file] { openFile (file); }); });
- menu.addItem (std::move (item));
- }
- if (recent.getNumFiles() > shown)
- {
- juce::PopupMenu more;
- for (int i = shown; i < recent.getNumFiles(); ++i)
- {
- const auto file = recent.getFile (i);
- more.addItem (file.getFileName() + " (" + file.getParentDirectory().getFullPathName() + ")", file.existsAsFile(),
- false, [this, file] { confirmDiscard ([this, file] { openFile (file); }); });
- }
- menu.addSubMenu (tr ("More recent projects"), more);
- }
- if (recent.getNumFiles() == 0)
- menu.addItem (tr ("(none)"), false, false, [] {});
- menu.addSeparator();
- menu.addItem (tr ("Revert to last backup..."), [this] { revertToLastBackup(); });
- menu.addItem (tr ("Open autosave folder"), [] {
- autosaveFolder().createDirectory();
- autosaveFolder().startAsProcess();
- });
- menu.addSeparator();
- menu.addItem (tr ("Exit"), [] { juce::JUCEApplication::getInstance()->systemRequestedQuit(); });
- }
- else if (index == 1)
- {
- // FL's Edit menu: "Undo backwards" (Ctrl+Alt+Z) above "Undo" (Ctrl+Z: undo, or redo after an undo)
- menu.addItem (tr ("Undo backwards") + shortcutText ("edit.undoBackwards"), engine.canUndo(), false, [this] { undoRedo (false); });
- menu.addItem ((alternateUndo || ! engine.canRedo() ? tr ("Undo") : tr ("Undo (redo)")) + shortcutText ("edit.undo"),
- engine.canUndo() || engine.canRedo(), false, [this] { flUndo(); });
- menu.addItem (tr ("Redo") + shortcutText ("edit.redo"), engine.canRedo(), false, [this] { undoRedo (true); });
- menu.addItem (tr ("Undo history...") + shortcutText ("edit.history"), [this] { showHistory(); });
- menu.addItem (tr ("Audio editor..."), [this] { openAudioEditor (engine); });
- menu.addSeparator();
- menu.addItem (tr ("Quick-add palette...") + shortcutText ("panel.quickAdd"), [this] { showQuickAdd(); });
- menu.addItem (tr ("Search the Browser") + shortcutText ("browser.search"), [this] {
- showPanel (Panel::browser);
- browser.focusSearch();
- });
- }
- else if (index == 2)
- {
- for (auto panel : panelOrder)
- menu.addItem (panelName (panel) + shortcutText (panelAction (panel)), true, workspace.isPanelVisible (panel), [this, panel] { togglePanel (panel); });
- menu.addSeparator();
- menu.addItem (tr ("Maximize or restore the Playlist") + shortcutText ("panel.maximisePlaylist"), [this] {
- workspace.toggleMaximised (Panel::playlist);
- refreshPanelButtons();
- });
- {
- juce::PopupMenu detach;
- for (auto panel : panelOrder)
- detach.addItem (panelName (panel), true, workspace.isDetached (panel), [this, panel] {
- workspace.setDetached (panel, ! workspace.isDetached (panel));
- refreshPanelButtons();
- });
- menu.addSubMenu (tr ("Detached panels (own window)"), detach);
- }
- menu.addSeparator();
- menu.addItem (tr ("Reset layout"), [this] {
- workspace.resetLayout();
- refreshPanelButtons();
- });
- menu.addItem (tr ("Save layout as..."), [this] { saveLayoutAs(); });
- menu.addSubMenu (tr ("Load layout"), layoutsMenu());
- menu.addItem (tr ("Bring back off-screen panels"), [this] { workspace.bringBackOffscreen(); });
- menu.addItem (tr ("Close all windows (plugins, channel settings, tools)") + shortcutText ("view.closeWindows"), [this] { runAction ("view.closeWindows"); });
- menu.addItem (tr ("Close all plugin windows") + shortcutText ("view.closePluginWindows"), [this] { runAction ("view.closePluginWindows"); });
- menu.addItem (tr ("Close all windows except the focused one") + shortcutText ("view.closeUnfocusedWindows"), [this] { runAction ("view.closeUnfocusedWindows"); });
- menu.addSeparator();
- menu.addItem (tr ("Plugin database (in the Browser)") + shortcutText ("view.pluginDatabase"), [this] { runAction ("view.pluginDatabase"); });
- menu.addItem (tr ("Audio editor") + shortcutText ("view.audioEditor"), [this] { openAudioEditorForSelection(); });
- menu.addItem (tr ("Tempo tapper") + shortcutText ("view.tempoTapper"), [this] { openTempoTapper (engine); });
- menu.addItem (tr ("Sample browser (separate window)") + shortcutText ("view.sampleBrowser"), true, findToolWindow ("sampleBrowser") != nullptr,
- [this] { toggleSampleBrowser(); });
- menu.addSeparator();
- menu.addItem (tr ("Typing keyboard as a piano") + shortcutText ("view.typingPiano"), true, typingPiano, [this] { setTypingPiano (! typingPiano); });
- menu.addItem (tr ("Touch keyboard") + shortcutText ("view.touchKeyboard"), true, isTouchKeyboardOpen(), [this] { toggleTouchKeyboard (engine); });
- {
- // FL's View › Background (audit round 165z-a): the workspace image and colour of Options › Theme
- juce::PopupMenu background;
- background.addItem (tr ("Set image wallpaper..."), [] { themeui::setImageWallpaper(); });
- background.addItem (tr ("Remove image wallpaper"), ! themeui::current().image.empty(), false, [] { themeui::removeImageWallpaper(); });
- background.addItem (tr ("Set background color..."), [this] { openSettings ((int) SettingsPage::theme); });
- menu.addSubMenu (tr ("Background"), background);
- }
- menu.addSeparator();
- // FL's "Auto scrolling" (round 162, issue #9)
- menu.addItem (tr ("Playlist follows the playhead (auto scrolling)") + shortcutText ("playlist.follow"), true,
- EditorGlobals::get().isFollowing (false), [this] { runAction ("playlist.follow"); });
- menu.addItem (tr ("Piano Roll follows the playhead (auto scrolling)") + shortcutText ("pianoRoll.follow"), true,
- EditorGlobals::get().isFollowing (true), [this] { runAction ("pianoRoll.follow"); });
- }
- else if (index == 3)
- {
- menu = makePatternMenu();
- }
- else if (index == 4)
- {
- // the Settings window's pages (Settings › General gathers the app options that were menu items here)
- menu.addItem (tr ("Audio settings..."), [this] { openSettings ((int) SettingsPage::audio); });
- menu.addItem (tr ("MIDI settings...") + shortcutText ("view.midiSettings"), [this] { openSettings ((int) SettingsPage::midi); });
- menu.addItem (tr ("General settings..."), [this] { openSettings ((int) SettingsPage::general); });
- menu.addItem (tr ("Theme (colors, background)..."), [this] { openSettings ((int) SettingsPage::theme); });
- menu.addItem (tr ("File settings (search folders)..."), [this] { openSettings ((int) SettingsPage::files); });
- menu.addItem (tr ("Project settings (tempo, time signature)..."), [this] { openSettings ((int) SettingsPage::project); });
- menu.addItem (tr ("Project info...") + shortcutText ("view.projectInfo"), [this] { openSettings ((int) SettingsPage::info); });
- {
- juce::PopupMenu mixerMenu; // round 163: clean mixer, inserts and Master chain of new projects
- mixeroptions::addItems (mixerMenu, engine, true);
- menu.addSubMenu (tr ("Mixer"), mixerMenu);
- }
- menu.addSeparator();
- menu.addItem (tr ("Plugin manager..."), [this] { showPluginManager(); });
- const auto scanning = engine.getPluginHost().backgroundScan().running;
- menu.addItem (scanning ? tr ("Stop the plugin scan") : tr ("Scan for plugins ({0})", { platform::pluginFormatNames() }), [this, scanning] {
- if (scanning)
- engine.getPluginHost().cancelBackgroundScan();
- else
- engine.getPluginHost().startBackgroundScan(); // progress in the hint bar; LYNX stays usable
- });
- menu.addItem (tr ("Manage shortcuts..."), [this] { showShortcutManager(); });
- menu.addItem (tr ("Plugin performance monitor..."), [this] { showPluginMonitor (engine); });
- menu.addSeparator();
- menu.addItem (tr ("Record input audio"), true, engine.isAudioRecordingArmed(), [this] {
- engine.setAudioRecordingArmed (! engine.isAudioRecordingArmed());
- });
- menu.addItem (tr ("Metronome") + shortcutText ("transport.metronome"), true, engine.getTransport().metronome.load(), [this] {
- metronomeButton.setToggleState (! metronomeButton.getToggleState(), juce::sendNotification);
- });
- menu.addItem (tr ("Metronome volume ({0})...", { ui::utilityVolumeText (engine.getTransport().metronomeVolume.load()) }),
- [this] { showMetronomeVolume(); });
- {
- // FL's Options › "Auto scrolling" (audit round 165z-a): one switch for every editor's Follow (Playlist,
- // Piano roll, Channel rack, Audio editor); each window's own Follow button still sets just that window
- auto& globals = EditorGlobals::get();
- const auto on = globals.isFollowing (false) && globals.isFollowing (true);
- menu.addItem (tr ("Auto scrolling"), true, on, [on] {
- auto& g = EditorGlobals::get();
- for (auto v : { EditorGlobals::FollowView::playlist, EditorGlobals::FollowView::pianoRoll,
- EditorGlobals::FollowView::channelRack, EditorGlobals::FollowView::audioEditor })
- g.setFollowingView (v, ! on);
- });
- }
- {
- juce::PopupMenu recording;
- addRecordOptions (recording);
- menu.addSubMenu (tr ("Recording"), recording);
- }
- {
- // FL 2026's Audio Logger (REA round 153): everything the Master plays goes to a WAV in the background
- auto& logger = engine.getAudioLogger();
- menu.addItem (tr ("Audio logger (record everything the Master plays)"), true, logger.isLogging(), [this] {
- auto& log = engine.getAudioLogger();
- if (log.isLogging())
- {
- const auto file = log.currentFile();
- const auto seconds = log.secondsWritten();
- log.stop();
- ui::postHint ({ tr ("Audio logger: saved {0} ({1} s)", { file.getFileName(), juce::String (seconds, 1) }), {}, false, false }, 5000);
- }
- else if (! log.start (AudioLogger::defaultFolder(), engine.getTransport().sampleRate.load()))
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Audio logger"),
- tr ("Could not create a file in {0}", { AudioLogger::defaultFolder().getFullPathName() }));
- else
- ui::postHint ({ tr ("Audio logger: recording the Master to {0}", { log.currentFile().getFileName() }), {}, false, false }, 5000);
- });
- menu.addItem (tr ("Show the audio logger's files"), [] {
- const auto folder = AudioLogger::defaultFolder();
- folder.createDirectory();
- folder.startAsProcess();
- });
- }
- {
- // FL's score logger (REA round 165f): the notes played lately, recording or not, into the current pattern
- juce::PopupMenu dumpMenu;
- for (const auto minutes : { 2, 5, 10, 20, 30 })
- dumpMenu.addItem (tr ("Last {0} minutes", { juce::String (minutes) }), [this, minutes] { dumpScoreLog (minutes); });
- menu.addSubMenu (tr ("Dump score log to selected pattern"), dumpMenu);
- menu.addItem (tr ("Clear score log"), ! engine.scoreLogEmpty(), false, [this] {
- auto options = juce::MessageBoxOptions()
- .withIconType (juce::MessageBoxIconType::WarningIcon)
- .withTitle (tr ("Score logger"))
- .withMessage (tr ("This will clear all logged notes!"))
- .withButton (tr ("Clear log"))
- .withButton (tr ("Cancel"));
- juce::AlertWindow::showAsync (options, [this] (int result) {
- if (result == 1)
- engine.clearScoreLog();
- });
- });
- }
- menu.addSubMenu (tr ("Toolbar"), makeToolbarMenu());
- menu.addSeparator();
- menu.addItem (tr ("Setup wizard (language, audio, plugin folders)..."), [this] { showSetupWizard(); });
- }
- else
- {
- menu.addItem (tr ("Shortcuts") + shortcutText ("help.shortcuts"), [this] { showHelp(); });
- menu.addItem (tr ("Missing files..."), [this] { showMissingFiles (false); });
- menu.addItem (tr ("Last FL Studio import report"), [this] {
- const auto& r = engine.getImportReport();
- if (r.converted.empty() && r.approximated.empty() && r.unsupported.empty() && r.droppedEffects.empty() && r.partialEffects.empty() && r.missingSamples == 0
- && engine.getMissingPlugins().isEmpty() && engine.getMatchedPlugins().isEmpty() && engine.getPluginsWithoutState().isEmpty()
- && engine.getPluginHost().getLoadFailures().isEmpty())
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("FL Studio import"),
- tr ("Nothing to report (no .flp imported in this session, or everything was converted)."));
- else
- showImportReport();
- });
- menu.addItem (tr ("Built-in plugins (online list)..."), [] {
- juce::URL ("https://github.com/Ka1-S/LYNX-SHARE/blob/main/docs/PLUGINS.md").launchInDefaultBrowser();
- });
- menu.addItem (tr ("Report a problem..."), [this] { crashreporter::showManualReport (&engine.getDeviceManager()); });
- if (updater::offered()) // (not in the Store build: the Store updates it)
- menu.addItem (tr ("Check for updates..."), [] { updater::checkNow(); });
- menu.addItem (tr ("About LYNX SHARE"), [] {
- auto* window = makeAboutWindow().release();
- window->enterModalState (true, nullptr, true);
- keepAboveMainWindow (*window);
- });
- }
- return menu;
- }
- std::unique_ptr<juce::AlertWindow> MainComponent::makeAboutWindow()
- {
- struct Logo final : juce::Component
- {
- Logo() { setSize (300, 150); }
- void paint (juce::Graphics& g) override
- {
- g.drawImageWithin (logoImage(), 0, 0, getWidth(), getHeight(), juce::RectanglePlacement::centred);
- }
- };
- struct About final : juce::AlertWindow
- {
- About()
- : juce::AlertWindow ("LYNX SHARE " JUCE_APPLICATION_VERSION_STRING,
- tr ("Lightweight C++/JUCE DAW with the FL Studio workflow.\n"
- "Independent implementation: no Image-Line code was copied."),
- juce::MessageBoxIconType::NoIcon)
- {
- addCustomComponent (&logo);
- }
- Logo logo;
- };
- auto window = std::make_unique<About>();
- window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- return std::unique_ptr<juce::AlertWindow> (window.release());
- }
- void MainComponent::showLanguageChoice (const juce::String& id)
- {
- if (id == i18n::saved())
- return;
- i18n::save (id);
- const auto restart = [this] {
- confirmDiscard ([] {
- lynx::platform::relaunchApp(); // through the package in the Store build (platform/Package.h)
- juce::JUCEApplication::quit();
- });
- };
- // the message is shown in the language just chosen
- const auto table = i18n::tableText (id);
- const juce::LocalisedStrings strings (table, false);
- auto say = [&] (const char* text) { return table.isEmpty() ? juce::String::fromUTF8 (text) : strings.translate (juce::String::fromUTF8 (text)); };
- auto* window = new juce::AlertWindow (say (TR_NOOP ("Language")), say (TR_NOOP ("The new language is applied when LYNX SHARE restarts.")),
- juce::MessageBoxIconType::InfoIcon);
- window->addButton (say (TR_NOOP ("Restart now")), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (say (TR_NOOP ("Later")), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- window->enterModalState (true, juce::ModalCallbackFunction::create ([restart] (int result) {
- if (result == 1)
- restart();
- }),
- true);
- }
- void MainComponent::rememberRecent (const juce::File& file)
- {
- recent.addFile (file);
- PluginHost::settingsFolder().getChildFile ("recentes.txt").replaceWithText (recent.toString());
- menuItemsChanged();
- }
- std::unique_ptr<juce::Component> MainComponent::makeHelpContent (const keys::KeyMap* keyMapIn)
- {
- // shortcut sheet: sections of "keys - action" rows, in two columns
- struct Row
- {
- const char* keys;
- const char* action;
- };
- struct Section
- {
- const char* title;
- std::vector<Row> rows;
- };
- static const std::vector<Section> sections {
- { TR_NOOP ("General"),
- { { TR_NOOP ("Space"), TR_NOOP ("Play / stop (back to where playback started)") },
- { "Ctrl+Space", TR_NOOP ("Play / pause") },
- { "Ctrl+Z / Ctrl+Y", TR_NOOP ("Undo / redo") },
- { "Ctrl+N / Ctrl+O", TR_NOOP ("New project / open") },
- { "Ctrl+S / Ctrl+Shift+S", TR_NOOP ("Save / save as") },
- { "Ctrl+R", TR_NOOP ("Export audio") },
- { "Enter", TR_NOOP ("Maximize or restore the Playlist") },
- { "L", TR_NOOP ("Pattern / song mode") },
- { "Ctrl+T", TR_NOOP ("Typing keyboard as a piano on/off") },
- { "Z..M Q..P", TR_NOOP ("PC keyboard as a piano (selected channels)") },
- { "Numpad +/-", TR_NOOP ("Next / previous pattern") },
- { "Ctrl+Shift+Ins", TR_NOOP ("Insert an empty pattern before the current one") } } },
- { TR_NOOP ("Workspace"),
- { { TR_NOOP ("Drag a panel title"), TR_NOOP ("Move (snaps; Alt: free)") },
- { TR_NOOP ("Double-click a title"), TR_NOOP ("Maximize / restore") },
- { TR_NOOP ("Title buttons"), TR_NOOP ("Detach into a window, maximize, close") },
- { TR_NOOP ("View menu"), TR_NOOP ("Reset, save and load layouts") } } },
- { TR_NOOP ("Channel Rack and Mixer"),
- { { TR_NOOP ("Click the name"), TR_NOOP ("Open/close the editor (Alt keeps others open)") },
- { TR_NOOP ("Ctrl+click the name"), TR_NOOP ("Audition the channel") },
- { TR_NOOP ("Selector / Up, Down"), TR_NOOP ("Select (Ctrl: add, Shift: range)") },
- { "Alt+Up / Alt+Down", TR_NOOP ("Move the selected channels") },
- { "Alt+C / Alt+Del", TR_NOOP ("Clone / delete the selected channels") },
- { "Ctrl+L", TR_NOOP ("Send the selected channels to free mixer inserts") },
- { TR_NOOP ("1..0 / Ctrl+1..0"), TR_NOOP ("Mute / solo channels 1-10 (typing piano off)") },
- { TR_NOOP ("Knobs and faders"), TR_NOOP ("Drag (Ctrl: fine), wheel, Alt+click or middle-click resets") },
- { TR_NOOP ("Right-click a knob/fader"), TR_NOOP ("Type value, reset, automation, MIDI link") },
- { TR_NOOP ("Right-click Pattern / Song"), TR_NOOP ("Show the Channel Rack / Playlist") },
- { TR_NOOP ("Double-click Stop"), TR_NOOP ("All notes off") } } },
- { "Piano Roll",
- { { TR_NOOP ("Click"), TR_NOOP ("Create a note (or chord, via the selector)") },
- { TR_NOOP ("Drag"), TR_NOOP ("Move; the right edge changes the length") },
- { TR_NOOP ("Right-click"), TR_NOOP ("Delete") },
- { TR_NOOP ("Ctrl+drag"), TR_NOOP ("Select (Ctrl+click adds to the selection)") },
- { TR_NOOP ("Shift+drag"), TR_NOOP ("Copy") },
- { "Ctrl+A/C/X/V", TR_NOOP ("Select all, copy, cut, paste") },
- { "Ctrl+B / Ctrl+Q", TR_NOOP ("Duplicate / quantize") },
- { "Alt+M / Shift+Alt+M", TR_NOOP ("Mute / unmute") },
- { "Ctrl+P / Ctrl+D", TR_NOOP ("Portamento / deselect") },
- { TR_NOOP ("Shift+arrows"), TR_NOOP ("Transpose a semitone / move by the grid (Ctrl+Up/Down: an octave)") },
- { TR_NOOP ("Alt / Ctrl+wheel"), TR_NOOP ("Disable snap / zoom") } } },
- { "Playlist",
- { { TR_NOOP ("Click"), TR_NOOP ("Paint the current pattern") },
- { TR_NOOP ("Drag on the ruler"), TR_NOOP ("Set the loop (right-click clears)") },
- { TR_NOOP ("Right-click a clip name"), TR_NOOP ("Split, make unique...") },
- { TR_NOOP ("Track LED"), TR_NOOP ("Mute the track") },
- { "Ctrl+A/C/X/V Ctrl+B", TR_NOOP ("Edit and duplicate") } } },
- };
- // the fourth column: every F-key of the live key map (issue #23: the sheet listed no F-keys), custom keys included
- const keys::KeyMap defaults;
- const auto& map = keyMapIn != nullptr ? *keyMapIn : defaults;
- std::vector<std::pair<juce::String, juce::String>> functionKeys;
- for (const auto& b : map.functionKeyBindings())
- if (const auto* action = keys::findAction (b.actionId))
- {
- auto text = tr (action->description);
- if (b.context != keys::Context::global)
- text << " (" << tr (b.context == keys::Context::browser ? "Browser"
- : b.context == keys::Context::mixer ? "Mixer"
- : b.context == keys::Context::playlist ? "Playlist"
- : b.context == keys::Context::pianoRoll ? "Piano Roll"
- : "Channel Rack")
- << ")";
- functionKeys.push_back ({ juce::String (keys::toString (b.chord)), text });
- }
- struct Sheet final : juce::Component
- {
- explicit Sheet (std::vector<std::pair<juce::String, juce::String>> f) : fkeys (std::move (f))
- {
- setSize (1500, juce::jmax (520, 20 + 28 + (int) fkeys.size() * 22 + 20));
- }
- void paint (juce::Graphics& g) override
- {
- using namespace theme;
- g.fillAll (colour::bg2);
- const auto columnWidth = (getWidth() - 5 * 24) / 4;
- int column = 0, y = 20;
- for (std::size_t i = 0; i < sections.size(); ++i)
- {
- if (i == 2 || i == 3) // next column
- {
- ++column;
- y = 20;
- }
- const auto x = 24 + column * (columnWidth + 24);
- const auto& section = sections[i];
- g.setColour (colour::accent);
- g.fillRoundedRectangle ((float) x, (float) y + 4.0f, 3.0f, 12.0f, 1.5f);
- g.setColour (colour::textPrimary);
- g.setFont (font (type::title, true));
- g.drawText (tr (section.title), x + 10, y, columnWidth - 10, 20, juce::Justification::centredLeft);
- y += 28;
- for (const auto& row : section.rows)
- {
- const auto keys = tr (row.keys);
- g.setFont (font (type::small, true));
- const auto keyWidth = juce::roundToInt (juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), keys)) + 14;
- g.setColour (colour::bg4);
- g.fillRoundedRectangle ((float) x, (float) y + 1.0f, (float) keyWidth, 18.0f, radius::sm);
- g.setColour (colour::textPrimary);
- g.drawText (keys, x, y + 1, keyWidth, 18, juce::Justification::centred);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::body));
- g.drawFittedText (tr (row.action), x + keyWidth + 10, y, columnWidth - keyWidth - 10, 20, juce::Justification::centredLeft, 1, 0.85f);
- y += 24;
- }
- y += 14;
- }
- // Function keys
- const auto x = 24 + 3 * (columnWidth + 24);
- y = 20;
- g.setColour (colour::accent);
- g.fillRoundedRectangle ((float) x, (float) y + 4.0f, 3.0f, 12.0f, 1.5f);
- g.setColour (colour::textPrimary);
- g.setFont (font (type::title, true));
- g.drawText (tr ("Function keys"), x + 10, y, columnWidth - 10, 20, juce::Justification::centredLeft);
- y += 28;
- g.setFont (font (type::small, true));
- int keyWidth = 0;
- for (const auto& [keys, text] : fkeys)
- keyWidth = juce::jmax (keyWidth, juce::roundToInt (juce::GlyphArrangement::getStringWidth (g.getCurrentFont(), keys)) + 14);
- for (const auto& [keys, text] : fkeys)
- {
- g.setFont (font (type::small, true));
- g.setColour (colour::bg4);
- g.fillRoundedRectangle ((float) x, (float) y + 1.0f, (float) keyWidth, 18.0f, radius::sm);
- g.setColour (colour::textPrimary);
- g.drawText (keys, x, y + 1, keyWidth, 18, juce::Justification::centred);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::body));
- g.drawFittedText (text, x + keyWidth + 10, y, columnWidth - keyWidth - 10, 20, juce::Justification::centredLeft, 1, 0.8f);
- y += 22;
- }
- }
- std::vector<std::pair<juce::String, juce::String>> fkeys;
- };
- return std::make_unique<Sheet> (std::move (functionKeys));
- }
- void MainComponent::showHelp()
- {
- juce::DialogWindow::LaunchOptions options;
- options.content.setOwned (makeHelpContent (&keyMap).release());
- options.dialogTitle = tr ("LYNX SHARE shortcuts");
- options.dialogBackgroundColour = theme::colour::bg2;
- options.useNativeTitleBar = true;
- options.resizable = true;
- options.escapeKeyTriggersCloseButton = true;
- if (auto* dialog = options.launchAsync())
- {
- keepAboveMainWindow (*dialog);
- helpWindow = dialog;
- }
- }
- void MainComponent::closeHelp()
- {
- // (the key may come from the sheet itself: delete it after this call stack)
- if (helpWindow == nullptr)
- return;
- helpWindow->setVisible (false);
- juce::MessageManager::callAsync ([w = helpWindow] { delete w.getComponent(); });
- helpWindow = nullptr;
- }
- void MainComponent::closeUnfocusedWindows()
- {
- // FL's Ctrl+F12 (CloseAllUnfocusedWindowsAction, round 167o): every window but the focused one closes. LYNX's
- // docked or detached panels and dialogs that wait for an answer stay, as for F12.
- auto* focused = juce::TopLevelWindow::getActiveTopLevelWindow();
- auto* main = getTopLevelComponent();
- juce::Array<juce::Component::SafePointer<juce::DocumentWindow>> close;
- for (int i = 0; i < juce::TopLevelWindow::getNumTopLevelWindows(); ++i)
- if (auto* w = dynamic_cast<juce::DocumentWindow*> (juce::TopLevelWindow::getTopLevelWindow (i)))
- if (w != focused && w != main && w->isVisible() && ! w->isCurrentlyModal() && ! (bool) w->getProperties()["lynxPanel"])
- close.add (w);
- for (auto& w : close)
- if (w != nullptr)
- w->closeButtonPressed();
- }
- void MainComponent::showSetupWizard()
- {
- // on top of the main window (round 140), so the DAW is visible behind it from the first start on
- if (setupOverlay != nullptr)
- return;
- auto safe = juce::Component::SafePointer<MainComponent> (this);
- setupOverlay = lynx::makeSetupWizardOverlay (
- engine,
- [safe] (const juce::String& language) {
- if (safe != nullptr)
- safe->showLanguageChoice (language);
- },
- [safe] {
- juce::MessageManager::callAsync ([safe] { // the overlay's own button is still running
- if (safe != nullptr)
- safe->setupOverlay.reset();
- });
- });
- addAndMakeVisible (*setupOverlay);
- setupOverlay->setBounds (getLocalBounds());
- setupOverlay->toFront (true);
- }
- void MainComponent::showImportReport()
- {
- // summary of what the .flp had that LYNX doesn't reproduce exactly (only when there is something to say)
- const auto& r = engine.getImportReport();
- const auto& missing = engine.getMissingPlugins();
- auto list = [] (const std::map<std::string, int>& items) {
- std::vector<std::pair<int, std::string>> sorted;
- for (const auto& [name, count] : items)
- sorted.push_back ({ count, name });
- std::sort (sorted.rbegin(), sorted.rend());
- juce::StringArray lines;
- for (const auto& [count, name] : sorted)
- lines.add (" " + juce::String::fromUTF8 (name.c_str()) + (count > 1 ? " (" + juce::String (count) + ")" : juce::String()));
- return lines.joinIntoString ("\n");
- };
- juce::String text;
- if (! r.approximated.empty())
- text << tr ("Approximated by the built-in synth:") << "\n" << list (r.approximated) << "\n\n";
- if (! r.unsupported.empty())
- text << tr ("No equivalent (played with a synth preset):") << "\n" << list (r.unsupported) << "\n\n";
- if (const auto& matched = engine.getMatchedPlugins(); ! matched.isEmpty())
- text << tr ("Plugins found on this PC:") << "\n " << matched.joinIntoString ("\n ") << "\n\n";
- if (! missing.isEmpty())
- text << tr ("Plugins not installed on this PC (or in a folder LYNX SHARE doesn't scan; Options > Setup wizard):") << "\n "
- << missing.joinIntoString ("\n ") << "\n\n";
- if (const auto& lost = engine.getPluginsWithoutState(); ! lost.isEmpty())
- text << tr ("Plugins found but playing their default settings (the project saved them for the other format, VST2/VST3):") << "\n "
- << lost.joinIntoString ("\n ") << "\n\n";
- if (const auto failed = engine.getPluginHost().getLoadFailures(); ! failed.isEmpty())
- text << tr ("Plugins installed but not loaded (silent):") << "\n " << failed.joinIntoString ("\n ") << "\n\n";
- if (! r.droppedEffects.empty())
- text << tr ("Effects with no equivalent (left out):") << "\n" << list (r.droppedEffects) << "\n\n";
- if (! r.partialEffects.empty())
- text << tr ("Effects kept but approximated or partly reproduced:") << "\n" << list (r.partialEffects) << "\n\n";
- if (r.missingSamples > 0)
- text << tr ("Samples missing on this machine: {0}", { juce::String (r.missingSamples) }) << "\n";
- if (r.relocatedSamples > 0)
- text << tr ("Samples found in another folder than the project says (FL Studio's folders or next to the project): {0}",
- { juce::String (r.relocatedSamples) }) << "\n";
- if (text.isNotEmpty())
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("FL Studio import"), text.trimEnd());
- }
- void MainComponent::showAudioSettings()
- {
- openSettings ((int) SettingsPage::audio);
- }
- // --- the Channel Rack's filter box ---------------------------------------------------------------
- void MainComponent::FilterBox::paint (juce::Graphics& g)
- {
- using namespace theme;
- auto area = getLocalBounds().toFloat();
- g.setColour (hovered ? colour::bg3 : colour::bg1);
- g.fillRoundedRectangle (area, radius::sm);
- g.setColour (hovered ? colour::borderStrong : colour::border);
- g.drawRoundedRectangle (area.reduced (0.5f), radius::sm, 1.0f);
- g.setColour (colour::textPrimary);
- g.setFont (font (type::small));
- g.drawText (text, getLocalBounds().withTrimmedLeft (7).withTrimmedRight (16), juce::Justification::centredLeft, true);
- icons::draw (g, Icon::chevronDown, area.removeFromRight (16.0f).reduced (3.0f).translated (-2.0f, 0.0f), colour::textSecondary);
- }
- // FL's Tools › Macros › Prepare for performance mode ([DECOMP] FUN_0122d010, its "Marker settings" dialog: marker count
- // 4 / 8 / 16 / 32 / 64, default 16; spacing 1…128 steps, default 16 = a bar): room for a launch grid before the song,
- // a marker per column, a Start marker, Performance mode on, the zone in view. FL warns it can't be undone; in LYNX it
- // is one undo step.
- void MainComponent::prepareForPerformance()
- {
- auto* window = new juce::AlertWindow (tr ("Prepare for performance mode"),
- tr ("Inserts empty columns before the song for the clips to launch, a marker on each, and a Start "
- "marker where the song begins; Performance mode is turned on."),
- juce::MessageBoxIconType::NoIcon);
- window->addComboBox ("count", { "4", "8", "16", "32", "64" }, tr ("Marker count"));
- window->addComboBox ("spacing", { tr ("1 step"), tr ("2 steps"), tr ("1 beat"), tr ("2 beats"), tr ("1 bar"), tr ("2 bars"), tr ("4 bars"), tr ("8 bars") },
- tr ("Spacing"));
- if (auto* c = window->getComboBoxComponent ("count"))
- c->setSelectedItemIndex (2, juce::dontSendNotification);
- if (auto* c = window->getComboBoxComponent ("spacing"))
- c->setSelectedItemIndex (4, juce::dontSendNotification);
- window->addButton (tr ("Accept"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- window->enterModalState (true, juce::ModalCallbackFunction::create ([this, window] (int result) {
- if (result != 1)
- return;
- const auto count = 4 << juce::jlimit (0, 4, window->getComboBoxComponent ("count")->getSelectedItemIndex());
- const auto steps = 1 << juce::jlimit (0, 7, window->getComboBoxComponent ("spacing")->getSelectedItemIndex());
- engine.editSong ([count, steps] (Song& s) { perf::prepareForPerformance (s, count, (std::int64_t) steps * (ppq / 4)); });
- showPanel (Panel::playlist);
- playlist.runAction ("playlist.zoomPerformance");
- }),
- true);
- keepAboveMainWindow (*window);
- }
- } // namespace lynx
|