Main.cpp 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003
  1. #include <juce_gui_basics/juce_gui_basics.h>
  2. #include "platform/Paths.h"
  3. #include "core/Effects.h"
  4. #include "core/FlEffects.h"
  5. #include "core/FlpImport.h"
  6. #include "core/NoteEdit.h"
  7. #include "core/MaximusFx.h"
  8. #include "core/Harmor.h"
  9. #include "flp/Flp.h"
  10. #include "core/SynthPresets.h"
  11. #include "core/FlWrapper.h"
  12. #include "engine/AudioEngine.h"
  13. #include "engine/DllAsioDevice.h"
  14. #include "engine/Exporter.h"
  15. #include "engine/MidiFileIo.h"
  16. #include "engine/PluginHost.h"
  17. #include "engine/PluginSandbox.h"
  18. #include "engine/ProjectFile.h"
  19. #include "engine/SampleLibrary.h"
  20. #include "engine/Text.h"
  21. #include "platform/FileTypes.h"
  22. #include "ui/ClipProperties.h"
  23. #include "ui/NewProjectDialog.h"
  24. #include "ui/PluginMonitorWindow.h"
  25. #include "ui/TouchKeyboard.h"
  26. #include "ui/AutomationUi.h"
  27. #include "ui/ChannelSettings.h"
  28. #include "ui/Dialogs.h"
  29. #include "core/RackOps.h"
  30. #include "ui/ExportDialog.h"
  31. #include "ui/I18n.h"
  32. #include "ui/MainComponent.h"
  33. #include "ui/SetupWizard.h"
  34. #include "engine/FlStudio.h"
  35. #include "ui/HistoryPanel.h"
  36. #include "ui/MissingFilesDialog.h"
  37. #include "ui/SettingsDialog.h"
  38. #include "ui/PluginManager.h"
  39. #include "ui/ShortcutManager.h"
  40. #include "ui/NoteToolDialogs.h"
  41. #include "ui/EventEditor.h"
  42. #include "ui/AudioEditor.h"
  43. #include "core/EventEdit.h"
  44. #include "core/FacetEq.h"
  45. #include "ui/FacetEqEditor.h"
  46. #include "ui/ParametricEqEditor.h"
  47. #include "ui/PluginEditors.h"
  48. #include "core/PluginLayout.h"
  49. #include "ui/Splash.h"
  50. #include "ui/Theme.h"
  51. #include "ui/WaveformView.h"
  52. #include "ui/WindowOwner.h"
  53. namespace
  54. {
  55. lynx::AudioEngine* crashEngine = nullptr;
  56. // Crashed: try to save the project and write the backtrace (like FL's "emergency save").
  57. void onCrash (void*)
  58. {
  59. const auto folder = lynx::platform::settingsFile ("autosave");
  60. folder.createDirectory();
  61. const auto stamp = juce::Time::getCurrentTime().formatted ("%Y-%m-%d %H-%M-%S");
  62. folder.getChildFile ("crash " + stamp + ".txt").replaceWithText (juce::SystemStats::getStackBacktrace());
  63. if (crashEngine != nullptr)
  64. {
  65. juce::String error;
  66. lynx::ProjectFile::save (crashEngine->getSong(), folder.getChildFile ("recovered " + stamp + lynx::ProjectFile::extension), error);
  67. }
  68. }
  69. } // namespace
  70. class LynxApplication final : public juce::JUCEApplication
  71. {
  72. public:
  73. const juce::String getApplicationName() override { return JUCE_APPLICATION_NAME_STRING; }
  74. const juce::String getApplicationVersion() override { return JUCE_APPLICATION_VERSION_STRING; }
  75. // the plugin scan runs copies of LYNX as child processes
  76. bool moreThanOneInstanceAllowed() override { return true; }
  77. void initialise (const juce::String& commandLine) override
  78. {
  79. // a crash in any mode (UI, command line) writes its backtrace to %APPDATA%\LYNX\autosave
  80. juce::SystemStats::setApplicationCrashHandler (onCrash);
  81. // child process of a sandboxed plugin: no window or audio of its own
  82. if (lynx::runPluginSandboxWorker (commandLine))
  83. return;
  84. const auto args = juce::StringArray::fromTokens (commandLine, true);
  85. // interface language: saved in %APPDATA%\LYNX\language.txt; --lang pt-BR overrides it for this run
  86. lynx::i18n::initialise (args);
  87. if (args.contains ("--showcase"))
  88. {
  89. // LYNX's own demo project (README screenshots): --showcase output.lynx [pattern]
  90. const auto i = args.indexOf ("--showcase");
  91. runShowcase (args[i + 1].unquoted(), args[i + 2].getIntValue());
  92. return;
  93. }
  94. if (args.contains ("--sandboxtest"))
  95. {
  96. const auto i = args.indexOf ("--sandboxtest");
  97. runSandboxTest (args[i + 1].unquoted(), args[i + 2].unquoted());
  98. return;
  99. }
  100. if (args.contains ("--rtstress"))
  101. {
  102. // LYNX.exe --rtstress project.(flp|lynx) report.txt [seconds] [--buffer N] [--type "driver type"] [--device "output"]
  103. // [--no-window] [--record take.wav]: the real app (window, audio device) plays the project and reports the callbacks
  104. // that missed their deadline (REA round 87); --type/--device pick another driver for this run only (round 97);
  105. // --record also records the input during the run, like Rec + Play, and moves the take to take.wav (round 106)
  106. const auto i = args.indexOf ("--rtstress");
  107. const auto seconds = args[i + 3].getDoubleValue();
  108. const auto buffer = args.contains ("--buffer") ? args[args.indexOf ("--buffer") + 1].getIntValue() : 0;
  109. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  110. const auto option = [&args] (const char* name) { return args.contains (name) ? args[args.indexOf (name) + 1].unquoted() : juce::String(); };
  111. runRealtimeStress (juce::File (args[i + 1].unquoted()), juce::File (args[i + 2].unquoted()), seconds > 0.0 ? seconds : 30.0, buffer,
  112. option ("--type"), option ("--device"), option ("--record"));
  113. return;
  114. }
  115. if (args.contains ("--selftest"))
  116. {
  117. const auto i = args.indexOf ("--selftest");
  118. runSelfTest (args[i + 1].unquoted(), args[i + 2].unquoted());
  119. return;
  120. }
  121. if (args.contains ("--scan-one"))
  122. {
  123. // child process of the plugin scan (see PluginHost::scan)
  124. const auto i = args.indexOf ("--scan-one");
  125. lynx::PluginHost::scanOneFile (args[i + 1].unquoted(), args[i + 2].unquoted(), juce::File (args[i + 3].unquoted()));
  126. setApplicationReturnValue (0);
  127. quit();
  128. return;
  129. }
  130. if (args.contains ("--paths"))
  131. {
  132. // diagnostics: folders LYNX searches
  133. const auto programs = juce::File::getSpecialLocation (juce::File::globalApplicationsDirectory);
  134. juce::String report;
  135. report << "programs=" << programs.getFullPathName() << "\n";
  136. for (const auto& dir : programs.getChildFile ("Image-Line").findChildFiles (juce::File::findDirectories, false, "FL Studio*"))
  137. report << "fl=" << dir.getFullPathName() << " packs=" << (int) dir.getChildFile ("Data").getChildFile ("Patches").getChildFile ("Packs").isDirectory() << "\n";
  138. juce::File (args[args.indexOf ("--paths") + 1].unquoted()).replaceWithText (report);
  139. quit();
  140. return;
  141. }
  142. if (args.contains ("--fldb"))
  143. {
  144. // diagnostics: LYNX.exe --fldb report.txt [project.flp]: the FL Studio installation, its plugin database,
  145. // the suggested plugin folders and, for a project, how each of its plugins resolves (read-only)
  146. const auto i = args.indexOf ("--fldb");
  147. const auto fl = lynx::findFlStudio();
  148. lynx::PluginHost host (false);
  149. juce::String report;
  150. report << "install=" << fl.installDir.getFullPathName() << "\nuserdata=" << fl.userData.getFullPathName() << "\n";
  151. for (const auto& f : fl.vstFolders)
  152. report << "flvstfolder=" << f << "\n";
  153. report << "dbfiles=" << host.flPluginDatabaseFiles() << " entries=" << (int) host.flPluginDatabase().entries().size() << "\n";
  154. for (const auto& e : host.flPluginDatabase().entries())
  155. report << " entry: " << juce::String::fromUTF8 (e.name.c_str()) << " | " << juce::String::fromUTF8 (e.path.c_str()) << " | role=" << e.role << "\n";
  156. const auto suggested = host.suggestedFolders();
  157. for (int k = 0; k < suggested.getNumPaths(); ++k)
  158. report << "folder=" << suggested[k].getFullPathName() << "\n";
  159. if (const juce::File project (args[i + 2].unquoted()); project.existsAsFile())
  160. {
  161. juce::MemoryBlock data;
  162. project.loadFileAsData (data);
  163. try
  164. {
  165. for (const auto& use : lynx::flpForeignPlugins (flp::parseProject ({ static_cast<const std::uint8_t*> (data.getData()), data.getSize() })))
  166. {
  167. juce::String how;
  168. const auto d = host.findForeign (use.plugin, use.instrument, &how);
  169. const auto* entry = host.flPluginDatabase().match (use.plugin, use.instrument);
  170. report << "plugin: " << juce::String::fromUTF8 (use.plugin.name.c_str()) << " -> "
  171. << (d ? d->fileOrIdentifier + " (" + how + ")" : juce::String ("not known"))
  172. << (entry != nullptr ? " | fl db: " + juce::String::fromUTF8 (entry->path.c_str()) : juce::String()) << "\n";
  173. }
  174. const auto uses = lynx::flpForeignPlugins (flp::parseProject ({ static_cast<const std::uint8_t*> (data.getData()), data.getSize() }));
  175. const auto candidates = host.filesToScanFor (uses);
  176. report << "scan_candidates=" << candidates.joinIntoString (";") << "\n";
  177. if (args.contains ("--scan"))
  178. {
  179. // the targeted scan an open would run (child processes; the user's plugin list is not touched)
  180. report << "scanned_new=" << host.scanFiles (candidates, {}) << "\n";
  181. for (const auto& use : uses)
  182. {
  183. juce::String how;
  184. const auto d = host.findForeign (use.plugin, use.instrument, &how);
  185. report << "after_scan: " << juce::String::fromUTF8 (use.plugin.name.c_str()) << " -> "
  186. << (d ? d->fileOrIdentifier + " (" + how + ")" : juce::String ("not known")) << "\n";
  187. }
  188. }
  189. }
  190. catch (const flp::Error& e)
  191. {
  192. report << "error=" << e.what() << "\n";
  193. }
  194. }
  195. juce::File (args[i + 1].unquoted()).replaceWithText (report);
  196. quit();
  197. return;
  198. }
  199. if (args.contains ("--devices") || args.contains ("--dispositivos")) // --dispositivos: legacy alias
  200. {
  201. // diagnostics: driver types and output devices JUCE offers (without opening any)
  202. juce::AudioDeviceManager manager;
  203. juce::String report;
  204. for (auto* type : manager.getAvailableDeviceTypes())
  205. {
  206. type->scanForDevices();
  207. report << "type=" << type->getTypeName() << "\n";
  208. for (const auto& name : type->getDeviceNames (false))
  209. report << " output=" << name << "\n";
  210. for (const auto& name : type->getDeviceNames (true))
  211. report << " input=" << name << "\n";
  212. }
  213. const auto flag = args.contains ("--devices") ? args.indexOf ("--devices") : args.indexOf ("--dispositivos");
  214. juce::File (args[flag + 1].unquoted()).replaceWithText (report);
  215. quit();
  216. return;
  217. }
  218. if (args.contains ("--devicetest"))
  219. {
  220. // LYNX.exe --devicetest "type" "device" report.txt ["input device"]: opens that output device (and, with the
  221. // 4th argument, an input: "*" = the same device / the driver's default input), receives 1 s of callbacks
  222. // writing silence, closes it and reports rate, block size, latency, callbacks and the input channels with
  223. // their peak level (driver check, no sound)
  224. const auto i = args.indexOf ("--devicetest");
  225. const auto typeName = args[i + 1].unquoted(), deviceName = args[i + 2].unquoted();
  226. auto inputName = args.size() > i + 4 && ! args[i + 4].startsWith ("--") ? args[i + 4].unquoted() : juce::String();
  227. const auto wantInput = inputName.isNotEmpty();
  228. juce::String report;
  229. const juce::File reportFile (args[i + 3].unquoted());
  230. auto step = [&] (const juce::String& line) { report << line << "\n"; reportFile.replaceWithText (report); }; // progress survives a driver that ends the process
  231. step ("step=start");
  232. juce::AudioDeviceManager manager;
  233. std::unique_ptr<juce::AudioIODevice> device;
  234. for (auto* type : manager.getAvailableDeviceTypes())
  235. if (type->getTypeName() == typeName)
  236. {
  237. type->scanForDevices();
  238. if (wantInput && type->hasSeparateInputsAndOutputs())
  239. {
  240. const auto inputs = type->getDeviceNames (true);
  241. if (inputName == "*" || ! inputs.contains (inputName))
  242. {
  243. const auto index = type->getDefaultDeviceIndex (true);
  244. inputName = juce::isPositiveAndBelow (index, inputs.size()) ? inputs[index] : juce::String();
  245. }
  246. for (const auto& n : inputs)
  247. step ("input_device=" + n);
  248. step ("input_chosen=" + inputName);
  249. }
  250. else if (wantInput)
  251. inputName = deviceName;
  252. step ("step=create");
  253. device.reset (type->createDevice (deviceName, type->hasSeparateInputsAndOutputs() ? inputName : juce::String()));
  254. step ("step=created");
  255. }
  256. struct Silence final : juce::AudioIODeviceCallback
  257. {
  258. std::atomic<int> calls { 0 }, inputs { 0 };
  259. std::array<std::atomic<float>, 64> peaks {};
  260. void audioDeviceIOCallbackWithContext (const float* const* in, int numIn, float* const* out, int channels, int n,
  261. const juce::AudioIODeviceCallbackContext&) override
  262. {
  263. for (int c = 0; c < channels; ++c)
  264. if (out[c] != nullptr)
  265. juce::FloatVectorOperations::clear (out[c], n);
  266. inputs.store (numIn);
  267. for (int c = 0; c < juce::jmin (numIn, 64); ++c)
  268. if (in[c] != nullptr)
  269. {
  270. const auto range = juce::FloatVectorOperations::findMinAndMax (in[c], n);
  271. const auto peak = juce::jmax (std::abs (range.getStart()), std::abs (range.getEnd()));
  272. if (peak > peaks[(std::size_t) c].load())
  273. peaks[(std::size_t) c].store (peak);
  274. }
  275. ++calls;
  276. }
  277. void audioDeviceAboutToStart (juce::AudioIODevice*) override {}
  278. void audioDeviceStopped() override {}
  279. } silence;
  280. bool ok = false;
  281. if (device == nullptr)
  282. step ("error=device not found");
  283. else
  284. {
  285. step ("step=open");
  286. juce::BigInteger outputs;
  287. outputs.setRange (0, 2, true);
  288. const auto rates = device->getAvailableSampleRates();
  289. const auto rate = device->getCurrentSampleRate() > 0 ? device->getCurrentSampleRate()
  290. : rates.contains (48000.0) ? 48000.0 : rates.isEmpty() ? 44100.0 : rates[0];
  291. step ("rates=" + juce::String (rates.size()) + " chosen=" + juce::String (rate) + " default_block=" + juce::String (device->getDefaultBufferSize()));
  292. juce::BigInteger inputs;
  293. if (wantInput)
  294. {
  295. const auto names = device->getInputChannelNames();
  296. step ("input_channels=" + juce::String (names.size()));
  297. for (int c = 0; c < names.size(); ++c)
  298. step (" in" + juce::String (c + 1) + "=" + names[c]);
  299. inputs.setRange (0, juce::jmin (64, names.size()), true);
  300. }
  301. // --buffer N: ask for that block size (REA round 97 latency survey); default: the driver's default
  302. const auto wantedBlock = args.contains ("--buffer") ? args[args.indexOf ("--buffer") + 1].getIntValue() : 0;
  303. const auto error = device->open (inputs, outputs, rate, wantedBlock > 0 ? wantedBlock : device->getDefaultBufferSize());
  304. if (error.isNotEmpty())
  305. step ("error=" + error);
  306. else
  307. {
  308. step ("step=start_callbacks");
  309. device->start (&silence);
  310. juce::Thread::sleep (1000);
  311. device->stop();
  312. report << "rate=" << device->getCurrentSampleRate() << "\n"
  313. << "block=" << device->getCurrentBufferSizeSamples() << "\n"
  314. << "output_latency=" << device->getOutputLatencyInSamples() << "\n"
  315. << "callbacks=" << silence.calls.load() << "\n";
  316. if (wantInput)
  317. {
  318. report << "input_latency=" << device->getInputLatencyInSamples() << "\n"
  319. << "active_inputs=" << device->getActiveInputChannels().countNumberOfSetBits() << "\n"
  320. << "callback_inputs=" << silence.inputs.load() << "\n";
  321. for (int c = 0; c < juce::jmin (64, silence.inputs.load()); ++c)
  322. report << " peak_in" << (c + 1) << "=" << juce::Decibels::gainToDecibels (silence.peaks[(std::size_t) c].load(), -150.0f) << " dB\n";
  323. }
  324. ok = silence.calls.load() > 0 && (! wantInput || silence.inputs.load() > 0);
  325. device->close();
  326. }
  327. }
  328. step (juce::String ("result=") + (ok ? "OK" : "FAILED"));
  329. setApplicationReturnValue (ok ? 0 : 1);
  330. quit();
  331. return;
  332. }
  333. if (args.contains ("--scantest"))
  334. {
  335. // LYNX.exe --scantest folder report.txt: scan (in child processes) without touching the user's list
  336. const auto i = args.indexOf ("--scantest");
  337. lynx::PluginHost host (false);
  338. const auto found = host.scan (juce::FileSearchPath (args[i + 1].unquoted()), {});
  339. juce::String report;
  340. report << "found=" << found << "\n";
  341. for (const auto& t : host.getKnownPlugins().getTypes())
  342. report << " " << (t.isInstrument ? "instrument: " : "effect: ") << t.name << "\n";
  343. for (const auto& f : host.getKnownPlugins().getBlacklistedFiles())
  344. report << " blacklisted: " << f << "\n";
  345. juce::File (args[i + 2].unquoted()).replaceWithText (report);
  346. setApplicationReturnValue (found > 0 ? 0 : 1);
  347. quit();
  348. return;
  349. }
  350. if (args.contains ("--vst2test"))
  351. {
  352. const auto i = args.indexOf ("--vst2test");
  353. runVst2Test (args[i + 1].unquoted(), args[i + 2].unquoted());
  354. return;
  355. }
  356. if (args.contains ("--wrappertest"))
  357. {
  358. const auto i = args.indexOf ("--wrappertest");
  359. runWrapperTest (args[i + 1].unquoted(), args[i + 2].unquoted());
  360. return;
  361. }
  362. if (args.contains ("--plugintest"))
  363. {
  364. const auto i = args.indexOf ("--plugintest");
  365. runPluginTest (args[i + 1].unquoted(), args[i + 2].unquoted());
  366. return;
  367. }
  368. if (args.contains ("--plugui"))
  369. {
  370. // LYNX.exe --plugui <folder>: the native effect editors at FL's size (one PNG per editor and page), each
  371. // loaded with the FL plugin's Default preset when the FL installation has one
  372. const auto i = args.indexOf ("--plugui");
  373. runPluginEditorSnapshots (args[i + 1].unquoted());
  374. return;
  375. }
  376. if (args.contains ("--snapshot"))
  377. {
  378. const auto i = args.indexOf ("--snapshot");
  379. runSnapshot (args[i + 1].unquoted(), args[i + 2].unquoted());
  380. return;
  381. }
  382. if (args.contains ("--stems"))
  383. {
  384. // LYNX.exe --stems project base.wav: one WAV per insert that has sound (like "Export stems")
  385. const auto i = args.indexOf ("--stems");
  386. juce::String error, report;
  387. int written = 0;
  388. {
  389. lynx::AudioEngine loader (false);
  390. const juce::File input (args[i + 1].unquoted()), base (args[i + 2].unquoted());
  391. auto ok = input.hasFileExtension ("flp") ? loader.importFlpFile (input, error) : false;
  392. if (! input.hasFileExtension ("flp"))
  393. if (auto song = lynx::ProjectFile::load (input, error))
  394. {
  395. loader.setSong (std::move (*song));
  396. ok = true;
  397. }
  398. const auto& song = loader.getSong();
  399. for (int t = 1; ok && t < (int) song.mixer.size(); ++t)
  400. {
  401. if (std::none_of (song.channels.begin(), song.channels.end(), [t] (const lynx::ChannelDef& c) { return c.mixerTrack == t; }))
  402. continue;
  403. const auto file = base.getSiblingFile (base.getFileNameWithoutExtension() + " - " + juce::String (t) + ".wav");
  404. lynx::ExportSettings settings;
  405. lynx::ExportJob job (lynx::makeBounceSong (song, t), settings, file);
  406. if (job.run ({}, error))
  407. {
  408. ++written;
  409. report << file.getFileName() << " peak=" << job.getPeak() << "\n";
  410. }
  411. }
  412. }
  413. report << "stems=" << written << "\n";
  414. juce::File (args[i + 2].unquoted() + ".txt").replaceWithText (report);
  415. setApplicationReturnValue (written > 0 ? 0 : 1);
  416. quit();
  417. return;
  418. }
  419. if (args.contains ("--export"))
  420. {
  421. const auto i = args.indexOf ("--export");
  422. const auto insert = args.contains ("--insert") ? args[args.indexOf ("--insert") + 1].getIntValue() : 0;
  423. runExport (args[i + 1].unquoted(), args[i + 2].unquoted(), args.contains ("--pattern"), insert);
  424. return;
  425. }
  426. if (args.contains ("--render"))
  427. {
  428. const auto i = args.indexOf ("--render");
  429. runRender (args[i + 1].unquoted(), args[i + 2].unquoted(), args[i + 3].getDoubleValue());
  430. return;
  431. }
  432. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  433. startupOptions = lynx::StartupOptions::load();
  434. lynx::registerFileTypes();
  435. // Double-clicking a .lynx/.flp opens LYNX with the file as an argument.
  436. if (args.size() > 0 && juce::File::isAbsolutePath (args[0].unquoted()))
  437. fileToOpen = juce::File (args[0].unquoted());
  438. if (! startupOptions.splash)
  439. {
  440. startEngine();
  441. createMainWindow();
  442. mainWindow->reveal();
  443. openStartupFile();
  444. return;
  445. }
  446. // the splash first, so it is on screen while the audio device opens; the main window is built
  447. // once the pepper has landed (the scene is still for a moment then) and shown when the splash ends
  448. splash = std::make_unique<lynx::SplashScreen>();
  449. splash->showOnDesktop();
  450. juce::Timer::callAfterDelay (40, [this] {
  451. startEngine();
  452. if (splash == nullptr) // quit meanwhile
  453. return;
  454. splash->setStatus (lynx::tr ("Loading the workspace..."));
  455. splash->startClock();
  456. juce::Timer::callAfterDelay (1050, [this] {
  457. if (splash == nullptr || engine == nullptr)
  458. return;
  459. createMainWindow();
  460. const auto wait = juce::jmax (0.0, lynx::SplashScreen::minimumDuration - splash->getElapsed());
  461. juce::Timer::callAfterDelay ((int) (wait * 1000.0), [this] {
  462. if (splash == nullptr || mainWindow == nullptr)
  463. return;
  464. mainWindow->reveal();
  465. splash->toFront (false);
  466. splash->finish ([this] { splash = nullptr; });
  467. openStartupFile();
  468. // first run: language, audio, plugin folders (FL Studio's included) and a background scan
  469. if (! lynx::setupWizardDone())
  470. mainWindow->showSetupWizard();
  471. });
  472. });
  473. });
  474. }
  475. void startEngine()
  476. {
  477. engine = std::make_unique<lynx::AudioEngine>();
  478. crashEngine = engine.get();
  479. addDriverFileDeviceType();
  480. if (startupOptions.sound)
  481. engine->previewSample (lynx::makeStartupSample());
  482. }
  483. void createMainWindow()
  484. {
  485. mainWindow = std::make_unique<MainWindow> (getApplicationName(), *engine);
  486. lynx::setMainWindowForOwnership (mainWindow.get());
  487. }
  488. void openStartupFile()
  489. {
  490. if (fileToOpen != juce::File() && mainWindow != nullptr)
  491. mainWindow->openFile (fileToOpen);
  492. }
  493. void shutdown() override
  494. {
  495. lynx::shutdownPluginSandboxWorker();
  496. splash = nullptr;
  497. mainWindow = nullptr; // the UI goes before the engine
  498. crashEngine = nullptr;
  499. engine = nullptr;
  500. juce::LookAndFeel::setDefaultLookAndFeel (nullptr);
  501. }
  502. void systemRequestedQuit() override
  503. {
  504. if (mainWindow != nullptr)
  505. mainWindow->confirmDiscard ([] { juce::JUCEApplication::quit(); });
  506. else
  507. quit();
  508. }
  509. private:
  510. // LYNX.exe --selftest report.txt: renders 2 s without a sound card and writes the result.
  511. // Exit code 0 = audio came out, 1 = silence.
  512. void runSelfTest (const juce::String& reportPath, const juce::String& demoProjectPath)
  513. {
  514. lynx::AudioEngine offline (false);
  515. const auto peak = offline.renderOffline (2.0, 48000.0);
  516. const auto audioOk = peak > 0.01f && peak < 10.0f;
  517. // project format round trip, with accents in the name
  518. auto original = lynx::Song::makeDefault();
  519. original.channels[0].name = "Bumbo ação";
  520. original.playlist.push_back ({ 0, 2, 3840, 1920, 960 });
  521. original.mode = lynx::PlayMode::song;
  522. original.mixer[3].effects.push_back (lynx::makeEffectSlot (lynx::EffectKind::delay));
  523. original.mixer[3].effects[0].params[1] = 0.25f;
  524. lynx::Automation automation;
  525. automation.name = "Pan";
  526. automation.target = { lynx::AutomationTargetKind::effectParam, 3, 0, 1 };
  527. automation.points = { { 0, 0.25f, 0.5f }, { 3840, 1.0f, 0.0f } };
  528. original.automations.push_back (automation);
  529. lynx::Clip automationClip;
  530. automationClip.kind = lynx::ClipKind::automation;
  531. automationClip.automation = 0;
  532. automationClip.track = 4;
  533. automationClip.length = 3840;
  534. original.playlist.push_back (automationClip);
  535. original.loopStart = 960;
  536. original.loopEnd = 7680;
  537. original.playlistTracks.resize (3);
  538. original.playlistTracks[2].colour = 0xFF2A6FDB; // a track colour (round 90)
  539. original.playlistTracks[2].grouped = true; // track groups and rack filter groups (round 104)
  540. original.playlistTracks[1].collapsed = true;
  541. original.channelGroups = { "Drums", "Keys" };
  542. original.channels[1].group = 1;
  543. juce::String error;
  544. if (demoProjectPath.isNotEmpty()) // sample project for checking the UI with --snapshot
  545. lynx::ProjectFile::save (original, juce::File (demoProjectPath), error);
  546. const auto reloaded = lynx::ProjectFile::fromJson (lynx::ProjectFile::toJson (original), error);
  547. const auto projectOk = reloaded && reloaded->channels.size() == original.channels.size()
  548. && reloaded->channels[0].name == original.channels[0].name
  549. && reloaded->patterns[0].notes.size() == original.patterns[0].notes.size()
  550. && reloaded->patterns[0].notes[3].start == original.patterns[0].notes[3].start
  551. && reloaded->mode == lynx::PlayMode::song && reloaded->playlist.size() == 2
  552. && reloaded->playlist[1].kind == lynx::ClipKind::automation && reloaded->playlist[1].automation == 0
  553. && reloaded->automations.size() == 1 && reloaded->automations[0].target == automation.target
  554. && reloaded->automations[0].points.size() == 2 && reloaded->automations[0].points[0].tension == 0.5f
  555. && reloaded->automations[0].points[1].tick == 3840
  556. && reloaded->loopStart == 960 && reloaded->loopEnd == 7680
  557. && reloaded->playlistTracks.size() == 3 && reloaded->playlistTracks[2].colour == 0xFF2A6FDB
  558. && reloaded->playlistTracks[1].colour == 0
  559. && reloaded->playlistTracks[2].grouped && reloaded->playlistTracks[1].collapsed && ! reloaded->playlistTracks[1].grouped
  560. && reloaded->channelGroups == original.channelGroups && reloaded->channels[1].group == 1 && reloaded->channels[0].group == -1
  561. && reloaded->playlist[0].offset == 960 && reloaded->playlist[0].track == 2
  562. && reloaded->mixer[3].effects.size() == 1
  563. && reloaded->mixer[3].effects[0].kind == lynx::EffectKind::delay
  564. && reloaded->mixer[3].effects[0].params[1] == 0.25f;
  565. // round trip of the newer features: synth/sampler with modulation, EQs, utility, markers
  566. auto rich = lynx::Song::makeDefault();
  567. auto& synth = rich.channels[4].synth;
  568. synth.osc[1] = { lynx::Waveform::square, -1, 7.0f, 0.4f, 5, -0.25f };
  569. synth.filterType = 2;
  570. synth.mono = true;
  571. synth.portaBeats = 0.125f;
  572. synth.am = true;
  573. synth.filterEnv = { 3.0f, 0.01f, 0.02f, 0.3f, 0.25f, 0.4f };
  574. synth.lfo[lynx::lfoPitch] = { 0.5f, 0.25f, true, 1, 0.1f, 0.2f };
  575. auto& sampler = rich.channels[0].sampler;
  576. sampler.cutoff = 1200.0f;
  577. sampler.resonance = 0.3f;
  578. sampler.filterType = 1;
  579. sampler.pitchEnv = { -12.0f, 0.0f, 0.0f, 0.05f, 0.0f, 0.1f };
  580. sampler.lfo[lynx::lfoVolume] = { 0.5f, 0.5f, false, 2, 0.0f, 0.0f };
  581. rich.mixer[2].eq.gainDb = { 3.0f, -2.5f, 1.0f };
  582. rich.mixer[2].eq.hz[1] = 2200.0f;
  583. auto peqSlot = lynx::makeEffectSlot (lynx::EffectKind::parametricEq);
  584. peqSlot.params[(std::size_t) lynx::peq::param (2, 2)] = lynx::peq::gainValue (6.0);
  585. peqSlot.params[(std::size_t) (lynx::peq::slopeParam + 0)] = lynx::peq::slopeValue (3);
  586. rich.mixer[2].effects.push_back (peqSlot);
  587. auto utilitySlot = lynx::makeEffectSlot (lynx::EffectKind::utility);
  588. utilitySlot.params[1] = 0.2f;
  589. rich.mixer[2].effects.push_back (utilitySlot);
  590. auto vocodexSlot = lynx::makeEffectSlot (lynx::EffectKind::vocodex); // FL's raw state travels as base64
  591. for (int i = 0; i < 300; ++i)
  592. vocodexSlot.state.push_back ((std::uint8_t) (i * 37));
  593. vocodexSlot.sidechain = 1;
  594. vocodexSlot.sidechain2 = 2;
  595. rich.mixer[3].effects.push_back (vocodexSlot);
  596. rich.addMarker ({ 3840, "Refrão", 0, 4 });
  597. rich.addMarker ({ 7680, {}, 7, 8 });
  598. const auto richBack = lynx::ProjectFile::fromJson (lynx::ProjectFile::toJson (rich), error);
  599. auto paramsClose = [] (const lynx::EffectParams& a, const lynx::EffectParams& b) {
  600. for (std::size_t i = 0; i < a.size(); ++i)
  601. if (std::abs (a[i] - b[i]) > 1.0e-3f)
  602. return false;
  603. return true;
  604. };
  605. const auto richOk = richBack && richBack->channels[4].synth == synth && richBack->channels[0].sampler == sampler
  606. && richBack->mixer[2].eq == rich.mixer[2].eq && richBack->mixer[2].effects.size() == 2
  607. && richBack->mixer[2].effects[0].kind == lynx::EffectKind::parametricEq
  608. && paramsClose (richBack->mixer[2].effects[0].params, peqSlot.params)
  609. && richBack->mixer[2].effects[1].kind == lynx::EffectKind::utility
  610. && paramsClose (richBack->mixer[2].effects[1].params, utilitySlot.params)
  611. && richBack->mixer[3].effects.size() == 1 && richBack->mixer[3].effects[0].kind == lynx::EffectKind::vocodex
  612. && richBack->mixer[3].effects[0].state == vocodexSlot.state && richBack->mixer[3].effects[0].sidechain2 == 2
  613. && richBack->markers() == rich.markers();
  614. // LYNX substitutes (round 98): a missing plugin's slot plays a built-in equivalent and the project keeps the
  615. // original reference byte for byte (.flp record and LYNX plugin state)
  616. bool substituteOk = false;
  617. {
  618. auto song = lynx::Song::makeDefault();
  619. lynx::ForeignPlugin vv; // an .flp VST3 record (ValhallaVintageVerb's class ID), opaque state
  620. vv.format = lynx::ForeignPlugin::Format::vst3;
  621. const std::uint8_t cid[] = { 0x76, 0x54, 0x53, 0x56, 0x65, 0x65, 0x76, 0x33, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x61, 0x76 };
  622. std::copy (std::begin (cid), std::end (cid), vv.classId.begin());
  623. vv.hasClassId = true;
  624. vv.name = "ValhallaVintageVerb";
  625. vv.path = "C:\\x\\ValhallaVintageVerb.vst3";
  626. for (int i = 0; i < 777; ++i)
  627. vv.state.push_back ((std::uint8_t) (i * 13 + 1));
  628. lynx::EffectSlot fromFlp;
  629. fromFlp.kind = lynx::EffectKind::plugin;
  630. fromFlp.plugin.foreign = vv;
  631. lynx::EffectSlot fromLynx; // a LYNX reference whose plugin isn't installed here
  632. fromLynx.kind = lynx::EffectKind::plugin;
  633. fromLynx.plugin.id = "VST3-FabFilter Pro-Q 3-1a2b3c4d-5e6f7a8b";
  634. fromLynx.plugin.name = "FabFilter Pro-Q 3";
  635. fromLynx.plugin.state = "AAECAwQFBgcICQ==";
  636. const auto flpRef = fromFlp.plugin, lynxRef = fromLynx.plugin;
  637. song.mixer[1].effects = { fromFlp, fromLynx };
  638. const auto substitutesOn = lynx::pluginSubstitutesEnabled();
  639. const auto changed = offline.getPluginHost().applySubstitutes (song);
  640. auto& fx = song.mixer[1].effects;
  641. // only the LYNX reference is substituted here (an .flp record is the import's job); do the .flp one directly
  642. const auto flpSubstituted = lynx::substituteEffectSlot (fx[0], lynx::pluginIdentity (vv));
  643. const auto back = lynx::ProjectFile::fromJson (lynx::ProjectFile::toJson (song), error);
  644. substituteOk = flpSubstituted && fx[0].kind == lynx::EffectKind::epochVerb
  645. && (! substitutesOn || (changed == 1 && fx[1].kind == lynx::EffectKind::facetEq && fx[1].substituteFor == lynxRef))
  646. && back && back->mixer[1].effects.size() == 2 && back->mixer[1].effects[0].kind == lynx::EffectKind::epochVerb
  647. && back->mixer[1].effects[0].substituteFor == flpRef && back->mixer[1].effects[0].substituteFor.foreign.state == vv.state
  648. && back->mixer[1].effects[1].kind == fx[1].kind && back->mixer[1].effects[1].substituteFor == fx[1].substituteFor;
  649. }
  650. // undo/redo
  651. offline.editSong ([] (lynx::Song& s) { s.bpm = 99.0; });
  652. offline.editSong ([] (lynx::Song& s) { s.bpm = 101.0; });
  653. offline.undo();
  654. const auto afterUndo = offline.getSong().bpm;
  655. offline.redo();
  656. const auto undoOk = afterUndo == 99.0 && offline.getSong().bpm == 101.0 && offline.canUndo() && ! offline.canRedo()
  657. && offline.isModified();
  658. // recording from the PC keyboard: a one-beat note lands in the pattern, in a single undo step
  659. const auto notesBefore = offline.getSong().patterns[0].notes.size();
  660. offline.setRecording (true);
  661. offline.play();
  662. offline.getTransport().positionTicks.store (960.0);
  663. offline.sendLiveNote (2, 72, 0.9f, true, true);
  664. offline.getTransport().positionTicks.store (1920.0);
  665. offline.sendLiveNote (2, 72, 0.0f, false, true);
  666. offline.setRecording (false);
  667. offline.stop();
  668. const auto& recorded = offline.getSong().patterns[0].notes;
  669. const auto recordOk = recorded.size() == notesBefore + 1
  670. && std::any_of (recorded.begin(), recorded.end(), [] (const lynx::Note& n) {
  671. return n.key == 72 && n.channel == 2 && n.length == 960 && n.start >= 960 && n.start < 3840;
  672. });
  673. offline.undo();
  674. const auto recordUndoOk = offline.getSong().patterns[0].notes.size() == notesBefore;
  675. // MIDI: exporting the pattern and importing it back gives the same notes
  676. bool midiOk = false;
  677. {
  678. auto source = lynx::Song::makeDefault();
  679. source.patterns[0].notes.push_back ({ 1000, 480, 4, 67, 0.5f });
  680. source.patterns[0].sortNotes();
  681. const auto midiFile = juce::File::getSpecialLocation (juce::File::tempDirectory).getChildFile ("lynx-selftest.mid");
  682. juce::String midiError;
  683. const auto saved = lynx::MidiFileIo::savePattern (source, 0, midiFile, midiError);
  684. const auto song = saved ? lynx::MidiFileIo::loadSong (midiFile, midiError) : std::nullopt;
  685. midiFile.deleteFile();
  686. if (song && song->patterns.size() == 1 && song->patterns[0].notes.size() == source.patterns[0].notes.size()
  687. && std::abs (song->bpm - source.bpm) < 0.01)
  688. {
  689. midiOk = true;
  690. const auto& a = source.patterns[0].notes;
  691. const auto& b = song->patterns[0].notes;
  692. for (std::size_t i = 0; i < a.size(); ++i)
  693. midiOk = midiOk && a[i].start == b[i].start && a[i].key == b[i].key && a[i].length == b[i].length;
  694. }
  695. }
  696. // WavPack: a .wv from the FL packs (if installed) opens through the sample loader
  697. juce::String wavpack = "NO_FL";
  698. {
  699. const auto roots = lynx::findFlStudioRoots();
  700. const auto packs = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Packs");
  701. const auto found = packs.isDirectory() ? packs.findChildFiles (juce::File::findFiles, true, "*.wv") : juce::Array<juce::File> {};
  702. if (! found.isEmpty())
  703. {
  704. lynx::SampleLibrary library;
  705. const auto sample = library.load (found.getFirst().getFullPathName());
  706. float peakWv = 0.0f;
  707. if (sample != nullptr)
  708. for (std::size_t i = 0; i < sample->frames(); ++i)
  709. peakWv = std::max (peakWv, std::abs (sample->leftData()[i]));
  710. wavpack = sample != nullptr && sample->frames() > 0 && peakWv > 1e-4f ? "OK" : "ERROR";
  711. }
  712. }
  713. const auto ok = audioOk && projectOk && richOk && substituteOk && undoOk && recordOk && recordUndoOk && midiOk && wavpack != "ERROR";
  714. juce::String report;
  715. report << "connections=" << offline.getNumGraphConnections() << "\n"
  716. << "peak=" << peak << "\n"
  717. << "project=" << (projectOk ? "OK" : "ERROR " + error) << "\n"
  718. << "project_features=" << (richOk ? "OK" : "ERROR") << "\n"
  719. << "plugin_substitutes=" << (substituteOk ? "OK" : "ERROR") << "\n"
  720. << "undo=" << (undoOk ? "OK" : "ERROR") << "\n"
  721. << "recording=" << (recordOk && recordUndoOk ? "OK" : "ERROR") << "\n"
  722. << "midi=" << (midiOk ? "OK" : "ERROR") << "\n"
  723. << "wavpack=" << wavpack << "\n"
  724. << "result=" << (ok ? "OK" : "FAILED") << "\n";
  725. if (reportPath.isNotEmpty())
  726. juce::File (reportPath).replaceWithText (report);
  727. setApplicationReturnValue (ok ? 0 : 1);
  728. quit();
  729. }
  730. // LYNX.exe --plugintest plugin.vst3 report.txt: loads the plugin, plays notes if it is an
  731. // instrument (and runs audio through it if it is an effect) and measures the audio.
  732. void runPluginTest (const juce::String& pluginPath, const juce::String& reportPath)
  733. {
  734. juce::String report;
  735. bool ok = false;
  736. {
  737. lynx::AudioEngine offline (false);
  738. auto& host = offline.getPluginHost();
  739. const auto added = host.addPluginFile (juce::File (pluginPath));
  740. report << "plugins_in_file=" << added << "\n";
  741. juce::PluginDescription instrument, effect;
  742. bool hasInstrument = false, hasEffect = false;
  743. for (const auto& type : host.getKnownPlugins().getTypes())
  744. {
  745. if (juce::File (type.fileOrIdentifier).getFileName() != juce::File (pluginPath).getFileName())
  746. continue;
  747. report << " " << (type.isInstrument ? "instrument: " : "effect: ") << type.name << " (" << type.manufacturerName
  748. << ") in " << type.fileOrIdentifier << "\n";
  749. if (type.isInstrument && ! hasInstrument) { instrument = type; hasInstrument = true; }
  750. if (! type.isInstrument && ! hasEffect) { effect = type; hasEffect = true; }
  751. }
  752. auto song = lynx::Song::makeDefault();
  753. if (hasInstrument)
  754. {
  755. auto& c = song.channels[4]; // the "Synth" channel becomes the plugin
  756. c.instrument = lynx::InstrumentKind::plugin;
  757. c.plugin.id = instrument.createIdentifierString().toStdString();
  758. c.plugin.name = instrument.name.toStdString();
  759. c.volume = 1.0f;
  760. for (int i = 0; i < 4; ++i) // one chord per beat
  761. for (int key : { 60, 64, 67 })
  762. song.patterns[0].notes.push_back ({ (std::int64_t) i * lynx::ppq, lynx::ppq / 2, 4, key, 0.9f });
  763. song.patterns[0].sortNotes();
  764. }
  765. if (hasEffect)
  766. {
  767. lynx::EffectSlot slot;
  768. slot.kind = lynx::EffectKind::plugin;
  769. slot.plugin.id = effect.createIdentifierString().toStdString();
  770. slot.plugin.name = effect.name.toStdString();
  771. song.mixer[0].effects.push_back (slot);
  772. }
  773. offline.setSong (song);
  774. const auto* loadedInstrument = dynamic_cast<lynx::PluginInstrument*> (offline.getChannelInstrument (4).get());
  775. const auto* loadedEffect = dynamic_cast<lynx::PluginEffect*> (offline.getEffect (0, 0).get());
  776. report << "instrument_loaded=" << (loadedInstrument != nullptr ? "yes" : "no") << "\n"
  777. << "effect_loaded=" << (loadedEffect != nullptr ? "yes" : "no") << "\n";
  778. const auto peak = offline.renderOffline (3.0, 48000.0);
  779. report << "peak=" << peak << "\n";
  780. offline.capturePluginStates();
  781. const auto stateSize = hasInstrument ? offline.getSong().channels[4].plugin.state.size() : (size_t) 0;
  782. report << "state_bytes_base64=" << (int) stateSize << "\n";
  783. ok = (hasInstrument || hasEffect) && (! hasInstrument || loadedInstrument != nullptr)
  784. && (! hasEffect || loadedEffect != nullptr) && peak > 0.001f && peak < 10.0f;
  785. }
  786. report << "result=" << (ok ? "OK" : "FAILED") << "\n";
  787. juce::File (reportPath).replaceWithText (report);
  788. setApplicationReturnValue (ok ? 0 : 1);
  789. quit();
  790. }
  791. // LYNX.exe --vst2test "LYNX Test Synth.dll" report.txt (tools/testplugin/lynx_test_vst2.c): LYNX's own VST2 host.
  792. // Scans the DLL, imports it the way an .flp holds it (Fruity Wrapper VST2 state with a chunk, REA_rodada89 §2),
  793. // renders with two saved gains (the level must follow the restored state) and checks the plugin saw the song tempo.
  794. void runVst2Test (const juce::String& pluginPath, const juce::String& reportPath)
  795. {
  796. juce::String report;
  797. bool ok = false;
  798. {
  799. lynx::AudioEngine offline (false);
  800. auto& host = offline.getPluginHost();
  801. report << "plugins_in_file=" << host.addPluginFile (juce::File (pluginPath)) << "\n";
  802. std::optional<juce::PluginDescription> vst2;
  803. for (const auto& type : host.getKnownPlugins().getTypes())
  804. if (type.pluginFormatName == "VST")
  805. vst2 = type;
  806. auto render = [&] (float gain, float& tempoSeen, int& adopted) {
  807. lynx::FlVst2State state;
  808. state.flags = 8;
  809. state.chunk = { 'L', 'X', 'V', '2', 0, 0, 0, 0 };
  810. std::memcpy (state.chunk.data() + 4, &gain, 4);
  811. auto song = lynx::Song::makeDefault();
  812. song.bpm = 137.0;
  813. auto& f = song.channels[4].plugin.foreign;
  814. f.format = lynx::ForeignPlugin::Format::vst2;
  815. f.vst2Id = (std::uint32_t) vst2->uniqueId;
  816. f.name = "Some other name"; // found by the VST2 ID
  817. f.state = lynx::writeFlVst2State (state);
  818. song.channels[4].volume = 1.0f;
  819. song.patterns[0].notes.clear();
  820. song.patterns[0].notes.push_back ({ 0, 4 * lynx::ppq, 4, 69, 1.0f });
  821. for (std::size_t c = 0; c < song.channels.size(); ++c)
  822. if (c != 4)
  823. song.channels[c].muted = true;
  824. adopted = host.adoptFlPlugins (song);
  825. offline.setSong (song);
  826. const auto peak = offline.renderOffline (1.0, 48000.0);
  827. offline.capturePluginStates();
  828. juce::MemoryBlock saved;
  829. saved.fromBase64Encoding (juce::String (offline.getSong().channels[4].plugin.state));
  830. lynx::FlVst2State back;
  831. tempoSeen = 0.0f;
  832. if (lynx::parseFlVst2State (std::vector<std::uint8_t> ((const std::uint8_t*) saved.getData(), (const std::uint8_t*) saved.getData() + saved.getSize()), back)
  833. && back.chunk.size() >= 12)
  834. std::memcpy (&tempoSeen, back.chunk.data() + 8, 4);
  835. return peak;
  836. };
  837. if (vst2)
  838. {
  839. report << "plugin=" << vst2->name << " id=" << vst2->uniqueId << " instrument=" << (int) vst2->isInstrument << "\n";
  840. float tempoA = 0, tempoB = 0;
  841. int adoptedA = 0, adoptedB = 0;
  842. const auto quiet = render (0.1f, tempoA, adoptedA);
  843. const auto loud = render (0.4f, tempoB, adoptedB);
  844. report << "adopted=" << adoptedA << "," << adoptedB << " peak_gain_0.1=" << quiet << " peak_gain_0.4=" << loud
  845. << " tempo_seen=" << tempoB * 1000.0f << "\n";
  846. ok = adoptedA == 1 && adoptedB == 1 && quiet > 0.01f && std::abs (loud / quiet - 4.0f) < 0.2f
  847. && std::abs (tempoB * 1000.0f - 137.0f) < 0.01f;
  848. }
  849. }
  850. report << "result=" << (ok ? "OK" : "FAILED") << "\n";
  851. juce::File (reportPath).replaceWithText (report);
  852. setApplicationReturnValue (ok ? 0 : 1);
  853. quit();
  854. }
  855. // LYNX.exe --wrappertest plugin.vst3 report.txt: builds a VST3 state the way FL's Fruity
  856. // Wrapper stores it (REA_rodada5 §3.2), runs it through the import (adoptFlPlugins) and checks
  857. // that the plugin comes back with the changed parameter.
  858. void runWrapperTest (const juce::String& pluginPath, const juce::String& reportPath)
  859. {
  860. juce::String report;
  861. bool ok = false;
  862. {
  863. lynx::AudioEngine offline (false);
  864. auto& host = offline.getPluginHost();
  865. host.addPluginFile (juce::File (pluginPath));
  866. const juce::PluginDescription* vst3 = nullptr;
  867. const auto types = host.getKnownPlugins().getTypes(); // copy: the pointer below points into it
  868. for (const auto& type : types)
  869. if (type.pluginFormatName == "VST3" && type.isInstrument)
  870. vst3 = &type;
  871. if (vst3 != nullptr)
  872. {
  873. juce::String error;
  874. auto plugin = host.getFormats().createPluginInstance (*vst3, 48000.0, 512, error);
  875. auto* parameter = plugin != nullptr && ! plugin->getParameters().isEmpty() ? plugin->getParameters()[0] : nullptr;
  876. if (parameter != nullptr)
  877. {
  878. const auto target = parameter->getValue() > 0.5f ? 0.13f : 0.87f;
  879. parameter->setValueNotifyingHost (target);
  880. juce::MemoryBlock juceState;
  881. plugin->getStateInformation (juceState);
  882. report << "parameter=" << parameter->getName (64) << " target=" << target << "\n";
  883. // JUCE state -> FL container: u32 1 + records 1 (flags), 3 (component), 2 (controller)
  884. std::vector<std::uint8_t> flState;
  885. auto put32 = [&] (std::uint32_t v) { for (int b = 0; b < 4; ++b) flState.push_back ((std::uint8_t) (v >> (8 * b))); };
  886. auto record = [&] (std::uint32_t id, const juce::MemoryBlock& data) {
  887. put32 (id);
  888. put32 ((std::uint32_t) data.getSize());
  889. put32 (0);
  890. flState.insert (flState.end(), (const std::uint8_t*) data.getData(), (const std::uint8_t*) data.getData() + data.getSize());
  891. };
  892. put32 (1);
  893. record (1, juce::MemoryBlock (64, true));
  894. // record 4 (REA_rodada22 §2.3): slots 0/1 hold the ParamIDs of parameters 2 and 0, so FL's
  895. // automations k = 0, 1, 2 mean positions 2, 0 and 1 (the first parameter without a slot)
  896. juce::MemoryBlock slots;
  897. const auto paramId = [&] (int i) {
  898. const auto* hosted = dynamic_cast<const juce::HostedAudioProcessorParameter*> (plugin->getParameters()[i]);
  899. return hosted != nullptr ? (std::uint32_t) hosted->getParameterID().getLargeIntValue() : 0u;
  900. };
  901. const bool reorder = plugin->getParameters().size() >= 3;
  902. if (reorder)
  903. {
  904. for (auto v : { 2u, paramId (2), paramId (0) })
  905. slots.append (&v, 4);
  906. report << "slot_param_ids=" << (juce::int64) paramId (2) << "," << (juce::int64) paramId (0) << "\n";
  907. }
  908. if (auto xml = juce::AudioProcessor::getXmlFromBinary (juceState.getData(), (int) juceState.getSize()))
  909. for (auto [tag, id] : { std::pair { "IComponent", 3u }, { "IEditController", 2u } })
  910. if (auto* child = xml->getChildByName (tag))
  911. {
  912. juce::MemoryBlock data;
  913. data.fromBase64Encoding (child->getAllSubText());
  914. record (id, data);
  915. report << tag << "_bytes=" << (int) data.getSize() << "\n";
  916. }
  917. if (reorder)
  918. record (4, slots);
  919. plugin.reset();
  920. auto song = lynx::Song::makeDefault();
  921. auto& f = song.channels[4].plugin.foreign;
  922. f.format = lynx::ForeignPlugin::Format::vst3;
  923. f.name = vst3->name.toStdString(); // no class ID: find it by name (fallback)
  924. f.state = flState;
  925. {
  926. std::vector<std::uint8_t> comp, ctrl;
  927. report << "split=" << (int) lynx::splitFlVst3State (flState, comp, ctrl) << " component=" << (int) comp.size()
  928. << " saved_slots=" << (int) lynx::flVst3ParamSlots (flState).size() << "\n";
  929. }
  930. for (int k = 0; k < 3; ++k)
  931. {
  932. lynx::Automation a;
  933. a.target = { lynx::AutomationTargetKind::channelParam, 4, 0, k };
  934. song.automations.push_back (a);
  935. }
  936. const auto adopted = host.adoptFlPlugins (song);
  937. report << "adopted=" << adopted << "\n";
  938. juce::String mapped;
  939. for (const auto& a : song.automations)
  940. if (a.target.kind == lynx::AutomationTargetKind::channelParam && a.target.index == 4)
  941. mapped << (mapped.isEmpty() ? "" : ",") << a.target.param;
  942. report << "slot_positions=" << mapped << "\n";
  943. const auto slotsOk = ! reorder || mapped == "2,0,1";
  944. offline.setSong (song);
  945. if (auto* loaded = dynamic_cast<lynx::PluginInstrument*> (offline.getChannelInstrument (4).get()))
  946. {
  947. const auto value = loaded->getInstance().getParameters()[0]->getValue();
  948. report << "restored_value=" << value << "\n";
  949. ok = adopted == 1 && std::abs (value - target) < 0.02f && slotsOk;
  950. }
  951. }
  952. }
  953. }
  954. report << "result=" << (ok ? "OK" : "FAILED") << "\n";
  955. juce::File (reportPath).replaceWithText (report);
  956. setApplicationReturnValue (ok ? 0 : 1);
  957. quit();
  958. }
  959. void runShowcase (const juce::String& outputPath, int currentPattern)
  960. {
  961. using namespace lynx;
  962. Song song;
  963. song.bpm = 124.0;
  964. song.mixer = Song::defaultMixer();
  965. const auto presets = synthPresets();
  966. auto preset = [&] (const char* name) {
  967. for (const auto& [n, sset] : presets)
  968. if (n == name)
  969. return sset;
  970. return SynthSettings {};
  971. };
  972. auto channel = [&] (const char* name, InstrumentKind kind, float volume, int track, std::uint32_t colour) {
  973. ChannelDef c;
  974. c.name = name;
  975. c.instrument = kind;
  976. c.volume = volume;
  977. c.mixerTrack = track;
  978. c.colour = colour;
  979. song.channels.push_back (c);
  980. return (int) song.channels.size() - 1;
  981. };
  982. const auto kick = channel ("Kick", InstrumentKind::kick, 0.9f, 1, 0xffd9534f);
  983. const auto clap = channel ("Clap", InstrumentKind::clap, 0.75f, 2, 0xfff0ad4e);
  984. const auto hat = channel ("Hat", InstrumentKind::hat, 0.6f, 3, 0xfff7d774);
  985. const auto snare = channel ("Snare", InstrumentKind::snare, 0.7f, 4, 0xffe8835a);
  986. const auto bass = channel ("Reese Bass", InstrumentKind::synth, 0.8f, 5, 0xff5bc0de);
  987. song.channels[(std::size_t) bass].synth = preset ("Reese Bass"); // preset name as defined in core/SynthPresets
  988. const auto pad = channel ("Pad", InstrumentKind::synth, 0.7f, 6, 0xff9b7fd6);
  989. song.channels[(std::size_t) pad].synth = preset ("Pad");
  990. const auto pluck = channel ("Pluck", InstrumentKind::synth, 0.72f, 7, 0xff5cb85c);
  991. song.channels[(std::size_t) pluck].synth = preset ("Pluck");
  992. const auto lead = channel ("Supersaw", InstrumentKind::synth, 0.6f, 8, 0xff4fc3a1);
  993. song.channels[(std::size_t) lead].synth = preset ("Supersaw");
  994. auto addPattern = [&] (const char* name, std::uint32_t colour) {
  995. auto& p = song.patterns.emplace_back();
  996. p.name = name;
  997. p.colour = colour;
  998. return (int) song.patterns.size() - 1;
  999. };
  1000. auto note = [&] (int pattern, int ch, double beat, double beats, int key, float velocity = 0.8f) {
  1001. Note n;
  1002. n.channel = ch;
  1003. n.start = (std::int64_t) (beat * ppq);
  1004. n.length = (std::int64_t) (beats * ppq);
  1005. n.key = key;
  1006. n.velocity = velocity;
  1007. song.patterns[(std::size_t) pattern].notes.push_back (n);
  1008. };
  1009. const auto beat = addPattern ("Beat", 0xffd9534f);
  1010. for (int s = 0; s < 16; s += 4)
  1011. song.patterns[(std::size_t) beat].toggleStep (kick, s);
  1012. for (int s : { 4, 12 })
  1013. song.patterns[(std::size_t) beat].toggleStep (clap, s);
  1014. for (int s = 2; s < 16; s += 4)
  1015. song.patterns[(std::size_t) beat].toggleStep (hat, s);
  1016. for (int s : { 7, 15 })
  1017. song.patterns[(std::size_t) beat].toggleStep (snare, s);
  1018. const auto groove = addPattern ("Groove", 0xfff0ad4e);
  1019. for (int s = 0; s < 16; ++s)
  1020. song.patterns[(std::size_t) groove].toggleStep (hat, s);
  1021. for (int s : { 4, 12 })
  1022. song.patterns[(std::size_t) groove].toggleStep (clap, s);
  1023. // Am – F – C – G, one bar each
  1024. const int roots[4] = { 45, 41, 48, 43 };
  1025. const int chords[4][3] = { { 57, 60, 64 }, { 53, 57, 60 }, { 55, 60, 64 }, { 55, 59, 62 } };
  1026. const auto bassline = addPattern ("Bass", 0xff5bc0de);
  1027. for (int bar = 0; bar < 4; ++bar)
  1028. for (int e = 0; e < 8; ++e)
  1029. if (e != 3)
  1030. note (bassline, bass, bar * 4 + e * 0.5, 0.4, roots[bar] - 12 + (e == 6 ? 12 : 0), e % 2 == 0 ? 0.9f : 0.65f);
  1031. const auto chordsPattern = addPattern ("Chords", 0xff9b7fd6);
  1032. for (int bar = 0; bar < 4; ++bar)
  1033. for (int k = 0; k < 3; ++k)
  1034. note (chordsPattern, pad, bar * 4, 3.9, chords[bar][k], 0.7f);
  1035. const auto melody = addPattern ("Melody", 0xff5cb85c);
  1036. const int line[] = { 69, 72, 76, 74, 72, 69, 67, 69, 65, 69, 72, 74, 72, 69, 67, 64,
  1037. 72, 76, 79, 76, 74, 72, 74, 76, 71, 74, 79, 78, 76, 74, 71, 67 };
  1038. for (int k = 0; k < 32; ++k)
  1039. if (k % 8 != 7)
  1040. note (melody, pluck, k * 0.5, k % 4 == 3 ? 0.9 : 0.4, line[k], k % 2 == 0 ? 0.85f : 0.65f);
  1041. const auto hook = addPattern ("Hook", 0xff4fc3a1);
  1042. for (int bar = 0; bar < 4; ++bar)
  1043. for (int k = 0; k < 3; ++k)
  1044. note (hook, lead, bar * 4 + k * 1.5, k == 2 ? 1.0 : 1.4, chords[bar][2] + 12 - k * 3, 0.8f);
  1045. // Playlist: intro, verse, drop, breakdown, final drop
  1046. song.playlistTracks = { { "Drums" }, { "Groove" }, { "Bass" }, { "Chords" }, { "Melody" }, { "Hook" }, { "Automation" } };
  1047. const auto bar = (std::int64_t) ppq * 4;
  1048. auto clip = [&] (int pattern, int track, int fromBar, int bars) {
  1049. const auto length = song.patterns[(std::size_t) pattern].effectiveLength (song.beatsPerBar);
  1050. for (int b = fromBar; b < fromBar + bars;)
  1051. {
  1052. Clip c;
  1053. c.pattern = pattern;
  1054. c.track = track;
  1055. c.start = b * bar;
  1056. c.length = length;
  1057. song.playlist.push_back (c);
  1058. b += (int) std::max<std::int64_t> (1, length / bar);
  1059. }
  1060. };
  1061. clip (chordsPattern, 3, 0, 8);
  1062. clip (melody, 4, 4, 4);
  1063. clip (beat, 0, 8, 16);
  1064. clip (groove, 1, 12, 12);
  1065. clip (bassline, 2, 8, 8);
  1066. clip (melody, 4, 8, 8);
  1067. clip (chordsPattern, 3, 16, 4);
  1068. clip (bassline, 2, 20, 4);
  1069. clip (hook, 5, 20, 4);
  1070. clip (melody, 4, 20, 4);
  1071. song.addMarker ({ 0, "Intro" });
  1072. song.addMarker ({ 8 * bar, "Drop" });
  1073. song.addMarker ({ 16 * bar, "Breakdown" });
  1074. song.addMarker ({ 20 * bar, "Final" });
  1075. // automation: the pad volume opens up during the intro
  1076. Automation a;
  1077. a.name = "Pad Volume";
  1078. a.target = { AutomationTargetKind::mixerVolume, 6, 0, 0 };
  1079. a.points = { { 0, 0.15f, 0.4f }, { 8 * bar, 0.8f, 0.0f } };
  1080. song.automations.push_back (a);
  1081. Clip ac;
  1082. ac.kind = ClipKind::automation;
  1083. ac.automation = 0;
  1084. ac.track = 6;
  1085. ac.start = 0;
  1086. ac.length = 8 * bar;
  1087. song.playlist.push_back (ac);
  1088. // mixer: names, colours and effects (bass compressor sidechained to the kick)
  1089. const char* names[] = { "Master", "Kick", "Clap", "Hat", "Snare", "Bass", "Pad", "Pluck", "Lead" };
  1090. for (int t = 0; t < 9; ++t)
  1091. {
  1092. song.mixer[(std::size_t) t].name = names[t];
  1093. if (t > 0)
  1094. song.mixer[(std::size_t) t].colour = song.channels[(std::size_t) t - 1].colour;
  1095. }
  1096. auto fx = [&] (int track, EffectKind kind) -> EffectSlot& {
  1097. song.mixer[(std::size_t) track].effects.push_back (makeEffectSlot (kind));
  1098. return song.mixer[(std::size_t) track].effects.back();
  1099. };
  1100. {
  1101. // kick EQ: cut below 30 Hz, weight at 60 Hz, remove the "boxiness" at 350 Hz, brightness at 4 kHz
  1102. auto& eq = fx (1, EffectKind::parametricEq);
  1103. auto band = [&] (int b, peq::BandType type, double hz, double db, double q) {
  1104. eq.params[(std::size_t) peq::param (b, 0)] = peq::typeValue (type);
  1105. eq.params[(std::size_t) peq::param (b, 1)] = peq::hzValue (hz);
  1106. eq.params[(std::size_t) peq::param (b, 2)] = peq::gainValue (db);
  1107. eq.params[(std::size_t) peq::param (b, 3)] = peq::qValue (q);
  1108. };
  1109. band (0, peq::BandType::lowCut, 30.0, 0.0, 0.7);
  1110. band (1, peq::BandType::peak, 62.0, 5.0, 1.2);
  1111. band (2, peq::BandType::peak, 350.0, -6.0, 2.0);
  1112. band (3, peq::BandType::peak, 4200.0, 3.5, 1.5);
  1113. band (4, peq::BandType::highCut, 14000.0, 0.0, 0.7);
  1114. for (int b = 5; b < peq::bands; ++b)
  1115. eq.params[(std::size_t) peq::param (b, 0)] = peq::typeValue (peq::BandType::off);
  1116. }
  1117. fx (1, EffectKind::distortion).mix = 0.3f;
  1118. auto& comp = fx (5, EffectKind::compressor);
  1119. comp.params[0] = 0.55f;
  1120. comp.params[1] = 0.8f;
  1121. comp.sidechain = 1;
  1122. fx (5, EffectKind::parametricEq);
  1123. fx (6, EffectKind::chorus);
  1124. fx (6, EffectKind::reverb);
  1125. fx (7, EffectKind::delay);
  1126. fx (7, EffectKind::reverb).mix = 0.4f;
  1127. fx (8, EffectKind::effector);
  1128. fx (8, EffectKind::delay);
  1129. fx (0, EffectKind::parametricEq);
  1130. auto& limiter = fx (0, EffectKind::limiter);
  1131. limiter.params = { 11.7f / 12.0f, 0.1f, 0.5f };
  1132. song.mixer[1].volume = 0.78f;
  1133. song.mixer[5].volume = 0.72f;
  1134. song.mixer[6].volume = 0.6f;
  1135. song.mixer[6].pan = -0.2f;
  1136. song.mixer[7].pan = 0.25f;
  1137. song.mode = PlayMode::song;
  1138. song.currentPattern = std::clamp (currentPattern, 0, (int) song.patterns.size() - 1);
  1139. juce::String error;
  1140. const auto ok = ProjectFile::save (song, juce::File (outputPath), error);
  1141. setApplicationReturnValue (ok ? 0 : 1);
  1142. quit();
  1143. }
  1144. // LYNX.exe --sandboxtest plugin.vst3 report.txt: opens the instrument in a separate process, plays a
  1145. // note, changes a parameter, checks the state (back in an in-process plugin) and makes the child hang
  1146. // to check that LYNX keeps going (silence, without waiting longer than the timeout).
  1147. void runSandboxTest (const juce::String& pluginPath, const juce::String& reportPath)
  1148. {
  1149. juce::String report;
  1150. bool ok = false;
  1151. lynx::setPluginSandboxAlerts (false);
  1152. const juce::File log (reportPath + ".log");
  1153. auto step = [&] (const char* what) { log.appendText (juce::String (what) + "\n"); };
  1154. log.deleteFile();
  1155. {
  1156. lynx::PluginHost host (false);
  1157. host.addPluginFile (juce::File (pluginPath));
  1158. const auto types = host.getKnownPlugins().getTypes(); // getTypes() returns a copy
  1159. const juce::PluginDescription* instrument = nullptr;
  1160. for (const auto& type : types)
  1161. if (type.isInstrument)
  1162. instrument = &type;
  1163. step ("host");
  1164. juce::String error;
  1165. auto remote = instrument != nullptr ? lynx::createSandboxedPlugin (*instrument, 48000.0, 512, {}, error) : nullptr;
  1166. report << "opened=" << (remote != nullptr ? 1 : 0) << " error=" << error << "\n";
  1167. step ("created");
  1168. if (remote != nullptr)
  1169. {
  1170. auto& proxy = *remote;
  1171. lynx::PluginInstrument voice (std::move (remote), 512);
  1172. std::vector<float> l (48000), r (48000);
  1173. auto peakOf = [&] {
  1174. float peak = 0.0f;
  1175. for (std::size_t k = 0; k < l.size(); ++k)
  1176. peak = std::max ({ peak, std::abs (l[k]), std::abs (r[k]) });
  1177. return peak;
  1178. };
  1179. const auto start = juce::Time::getMillisecondCounterHiRes();
  1180. voice.noteOn (60, 0.9f);
  1181. voice.render (l.data(), r.data(), 48000, 1.0f, 1.0f);
  1182. const auto renderMs = juce::Time::getMillisecondCounterHiRes() - start;
  1183. const auto peak = peakOf();
  1184. step ("played");
  1185. report << "parameters=" << proxy.getParameters().size() << " peak=" << peak << " render_1s_ms=" << renderMs << "\n";
  1186. // parameter -> state -> in-process plugin
  1187. bool stateOk = false;
  1188. if (! proxy.getParameters().isEmpty())
  1189. {
  1190. auto* p = proxy.getParameters()[0];
  1191. const auto target = p->getValue() > 0.5f ? 0.13f : 0.87f;
  1192. p->setValue (target);
  1193. std::fill (l.begin(), l.end(), 0.0f);
  1194. voice.render (l.data(), r.data(), 512, 1.0f, 1.0f); // carries the change to the child
  1195. juce::MemoryBlock state;
  1196. proxy.getStateInformation (state);
  1197. if (auto local = host.getFormats().createPluginInstance (*instrument, 48000.0, 512, error))
  1198. {
  1199. local->setStateInformation (state.getData(), (int) state.getSize());
  1200. const auto back = local->getParameters()[0]->getValue();
  1201. report << "state_bytes=" << (int) state.getSize() << " target=" << target << " in_process=" << back << "\n";
  1202. stateOk = std::abs (back - target) < 0.02f;
  1203. }
  1204. }
  1205. step ("state");
  1206. // hung child: the block returns in ~0.5 s, muted, and the plugin is marked dead
  1207. lynx::hangSandboxedPluginForTest (proxy);
  1208. juce::Thread::sleep (200);
  1209. std::fill (l.begin(), l.end(), 1.0f);
  1210. std::fill (r.begin(), r.end(), 1.0f);
  1211. const auto hangStart = juce::Time::getMillisecondCounterHiRes();
  1212. voice.render (l.data(), r.data(), 4096, 0.0f, 0.0f);
  1213. std::fill (l.begin(), l.end(), 0.0f);
  1214. std::fill (r.begin(), r.end(), 0.0f);
  1215. voice.render (l.data(), r.data(), 4096, 1.0f, 1.0f);
  1216. const auto hangMs = juce::Time::getMillisecondCounterHiRes() - hangStart;
  1217. const auto dead = lynx::isSandboxedPluginDead (proxy);
  1218. report << "hung_ms=" << hangMs << " dead=" << (dead ? 1 : 0) << " peak_after=" << peakOf() << "\n";
  1219. ok = peak > 1e-4f && stateOk && dead && hangMs < 1500.0 && peakOf() == 0.0f;
  1220. }
  1221. }
  1222. report << "result=" << (ok ? "OK" : "FAILED") << "\n";
  1223. juce::File (reportPath).replaceWithText (report);
  1224. setApplicationReturnValue (ok ? 0 : 1);
  1225. quit();
  1226. }
  1227. // --rtstress: opens the project in the normal window with the saved audio device, plays it from the start for
  1228. // `seconds` and writes the real-time statistics (deadline misses, late device calls, load histogram, heaviest units)
  1229. void runRealtimeStress (const juce::File& project, const juce::File& report, double seconds, int bufferSize,
  1230. const juce::String& deviceType, const juce::String& deviceName, const juce::String& recordTo = {})
  1231. {
  1232. startupOptions = lynx::StartupOptions::load();
  1233. engine = std::make_unique<lynx::AudioEngine>();
  1234. crashEngine = engine.get();
  1235. // the user's saved device stays as it was: this run's choices are undone before quitting
  1236. savedDeviceState = engine->getDeviceManager().createStateXml();
  1237. auto& devices = engine->getDeviceManager();
  1238. const auto driverFile = addDriverFileDeviceType();
  1239. const auto type = deviceType.isEmpty() && driverFile ? juce::String (lynx::dllAsioTypeName) : deviceType;
  1240. if (type.isNotEmpty() && devices.getCurrentAudioDeviceType() != type)
  1241. devices.setCurrentAudioDeviceType (type, true);
  1242. if (bufferSize > 0 || deviceName.isNotEmpty())
  1243. {
  1244. auto setup = devices.getAudioDeviceSetup();
  1245. if (bufferSize > 0)
  1246. setup.bufferSize = bufferSize;
  1247. if (deviceName.isNotEmpty())
  1248. setup.outputDeviceName = deviceName;
  1249. const auto error = devices.setAudioDeviceSetup (setup, true);
  1250. if (error.isNotEmpty())
  1251. report.replaceWithText ("device error: " + error + "\n");
  1252. }
  1253. createMainWindow();
  1254. if (! juce::JUCEApplication::getCommandLineParameters().contains ("--no-window")) // --no-window: is it the UI?
  1255. mainWindow->reveal();
  1256. juce::String error;
  1257. auto ok = false;
  1258. const auto loadStart = juce::Time::getMillisecondCounterHiRes();
  1259. if (project.hasFileExtension ("flp"))
  1260. ok = engine->importFlpFile (project, error);
  1261. else if (auto song = lynx::ProjectFile::load (project, error))
  1262. {
  1263. engine->setSong (std::move (*song));
  1264. ok = true;
  1265. }
  1266. const auto loadMs = juce::Time::getMillisecondCounterHiRes() - loadStart;
  1267. if (! ok)
  1268. {
  1269. report.replaceWithText ("project: " + project.getFullPathName() + "\nresult=ERROR " + error + "\n");
  1270. restoreSavedDeviceState();
  1271. setApplicationReturnValue (1);
  1272. quit();
  1273. return;
  1274. }
  1275. if (recordTo.isNotEmpty())
  1276. engine->setAudioRecordingArmed (true); // opens the input of the driver
  1277. // let the window draw the project, then play from the start with fresh statistics
  1278. juce::Timer::callAfterDelay (1500, [this, project, report, seconds, loadMs, recordTo] {
  1279. if (engine == nullptr)
  1280. return;
  1281. engine->stop();
  1282. engine->rewind();
  1283. engine->getRtStats().reset();
  1284. engine->takeUiPulse();
  1285. if (recordTo.isNotEmpty())
  1286. engine->setRecording (true);
  1287. engine->play();
  1288. juce::Timer::callAfterDelay ((int) (seconds * 1000.0), [this, project, report, seconds, loadMs, recordTo] {
  1289. if (engine == nullptr)
  1290. return;
  1291. engine->stop();
  1292. juce::String recording;
  1293. if (recordTo.isNotEmpty())
  1294. recording = finishStressTake (juce::File (recordTo), seconds);
  1295. const auto s = engine->getRtStats().snapshot();
  1296. juce::String text;
  1297. text << "project: " << project.getFullPathName() << "\n"
  1298. << "LYNX " << getApplicationVersion() << ", " << juce::SystemStats::getOperatingSystemName() << ", "
  1299. << juce::SystemStats::getNumCpus() << " logical CPUs (" << juce::SystemStats::getNumPhysicalCpus() << " cores), "
  1300. << juce::SystemStats::getCpuModel() << "\n"
  1301. << "load " << juce::String (loadMs / 1000.0, 1) << " s, played " << juce::String (seconds, 0) << " s\n"
  1302. << engine->describeRealtime();
  1303. const auto pulse = engine->takeUiPulse();
  1304. text << " UI: the 30 Hz engine timer ran " << pulse.calls << " times (" << juce::String (pulse.calls / seconds, 1)
  1305. << "/s), longest gap " << juce::String (pulse.maxGapMs, 0) << " ms" << (mainWindow == nullptr || ! mainWindow->isVisible() ? " (window hidden)" : "") << "\n";
  1306. text << " load histogram (share of the deadline: callbacks):";
  1307. for (std::size_t b = 0; b < s.histogram.size(); ++b)
  1308. if (s.histogram[b] > 0)
  1309. text << " " << (int) (b * 10) << (b + 1 == s.histogram.size() ? juce::String ("+") : "-" + juce::String ((int) (b * 10 + 10))) << "%:" << (juce::int64) s.histogram[b];
  1310. text << "\n";
  1311. text << recording;
  1312. text << "result=" << (s.callbacks == 0 ? "ERROR no audio callbacks" : s.overBudget == 0 && s.lateCalls == 0 ? "OK" : "GLITCHES") << "\n";
  1313. report.replaceWithText (text);
  1314. restoreSavedDeviceState();
  1315. setApplicationReturnValue (s.callbacks == 0 ? 1 : 0);
  1316. quit();
  1317. });
  1318. });
  1319. }
  1320. // --rtstress --record: stops recording (the take becomes a clip of the song, as in the app), moves the take's WAV to
  1321. // `target` and describes it: length against the time played, channels, peak, the latencies the driver reported.
  1322. juce::String finishStressTake (const juce::File& target, double seconds)
  1323. {
  1324. juce::String text;
  1325. auto* device = engine->getDeviceManager().getCurrentAudioDevice();
  1326. text << " recording: input " << (device != nullptr ? device->getActiveInputChannels().countNumberOfSetBits() : 0) << " channel(s)";
  1327. if (device != nullptr)
  1328. text << ", input latency " << device->getInputLatencyInSamples() << " + output latency " << device->getOutputLatencyInSamples() << " samples";
  1329. engine->setRecording (false); // closes the take: a clip of the song
  1330. juce::File take;
  1331. for (const auto& c : engine->getSong().channels)
  1332. if (c.instrument == lynx::InstrumentKind::audioClip)
  1333. take = juce::File (juce::String::fromUTF8 (c.samplePath.c_str()));
  1334. if (! take.existsAsFile())
  1335. return text + "\n recording: no take (" + engine->getLastRecordingError() + ")\n";
  1336. target.deleteFile();
  1337. if (! take.moveFileTo (target))
  1338. take.copyFileTo (target);
  1339. juce::AudioFormatManager formats;
  1340. formats.registerBasicFormats();
  1341. if (std::unique_ptr<juce::AudioFormatReader> reader (formats.createReaderFor (target)); reader != nullptr)
  1342. {
  1343. juce::AudioBuffer<float> audio ((int) reader->numChannels, (int) reader->lengthInSamples);
  1344. reader->read (&audio, 0, (int) reader->lengthInSamples, 0, true, true);
  1345. const auto peak = audio.getMagnitude (0, audio.getNumSamples());
  1346. const auto length = (double) reader->lengthInSamples / reader->sampleRate;
  1347. text << "\n recording: take " << juce::String (length, 3) << " s of " << juce::String (seconds, 0) << " s played, "
  1348. << (int) reader->numChannels << " ch @ " << (int) reader->sampleRate << " Hz, peak "
  1349. << juce::String (juce::Decibels::gainToDecibels (peak, -150.0f), 1) << " dBFS -> " << target.getFullPathName() << "\n";
  1350. }
  1351. else
  1352. text << "\n recording: take unreadable (" << target.getFullPathName() << ")\n";
  1353. return text;
  1354. }
  1355. // LYNX.exe --render project.(flp|lynx) output.wav [seconds]
  1356. // Exports the current pattern to 24-bit WAV (for an imported .flp, the one with the most notes).
  1357. void runRender (const juce::String& inputPath, const juce::String& outputPath, double seconds)
  1358. {
  1359. lynx::AudioEngine offline (false);
  1360. const juce::File input (inputPath);
  1361. juce::String error, report;
  1362. bool ok = false;
  1363. if (input.hasFileExtension ("flp"))
  1364. ok = offline.importFlpFile (input, error);
  1365. else if (auto song = lynx::ProjectFile::load (input, error))
  1366. {
  1367. offline.setSong (std::move (*song));
  1368. ok = true;
  1369. }
  1370. int samplers = 0, samplersLoaded = 0;
  1371. if (ok)
  1372. {
  1373. for (const auto& c : offline.getSong().channels)
  1374. if (c.instrument == lynx::InstrumentKind::sampler || c.instrument == lynx::InstrumentKind::audioClip)
  1375. {
  1376. ++samplers;
  1377. samplersLoaded += offline.getSampleLibrary().load (juce::String::fromUTF8 (c.samplePath.c_str())) != nullptr;
  1378. }
  1379. const juce::File output (outputPath);
  1380. output.deleteFile();
  1381. juce::WavAudioFormat wav;
  1382. std::unique_ptr<juce::AudioFormatWriter> writer (
  1383. wav.createWriterFor (output.createOutputStream().release(), 44100.0, 2, 24, {}, 0));
  1384. if (writer == nullptr)
  1385. {
  1386. ok = false;
  1387. error = lynx::utf8 ("could not create ") + outputPath;
  1388. }
  1389. else
  1390. {
  1391. const auto peak = offline.renderOffline (seconds > 0.0 ? seconds : 10.0, 44100.0, writer.get());
  1392. report << "peak=" << peak << "\n";
  1393. ok = peak > 0.001f;
  1394. }
  1395. }
  1396. report << "samples=" << samplersLoaded << "/" << samplers << "\n"
  1397. << "result=" << (ok ? "OK" : "ERROR " + error) << "\n";
  1398. juce::File (outputPath + ".txt").replaceWithText (report);
  1399. setApplicationReturnValue (ok ? 0 : 1);
  1400. quit();
  1401. }
  1402. // LYNX.exe --export project.(flp|lynx) output.(wav|flac|ogg|mp3) [--pattern] [--insert N]
  1403. // Same path as "Export" in the UI: the whole song (or the current pattern) with its tail.
  1404. void runExport (const juce::String& inputPath, const juce::String& outputPath, bool patternOnly, int insert)
  1405. {
  1406. juce::String error, report;
  1407. bool ok = false;
  1408. const auto started = juce::Time::getMillisecondCounterHiRes();
  1409. {
  1410. lynx::AudioEngine loader (false);
  1411. const juce::File input (inputPath);
  1412. // --find-plugins: first the targeted scan opening the project in the app runs (its plugins not known yet)
  1413. if (input.hasFileExtension ("flp") && juce::JUCEApplication::getCommandLineParameters().contains ("--find-plugins"))
  1414. {
  1415. juce::MemoryBlock data;
  1416. if (input.loadFileAsData (data))
  1417. try
  1418. {
  1419. const auto uses = lynx::flpForeignPlugins (flp::parseProject ({ static_cast<const std::uint8_t*> (data.getData()), data.getSize() }));
  1420. auto& host = loader.getPluginHost();
  1421. report << "scanned=" << host.filesToScanFor (uses).joinIntoString (";") << "\n";
  1422. host.scanFiles (host.filesToScanFor (uses), {});
  1423. }
  1424. catch (const flp::Error&)
  1425. {
  1426. }
  1427. }
  1428. if (input.hasFileExtension ("flp"))
  1429. ok = loader.importFlpFile (input, error);
  1430. else if (auto song = lynx::ProjectFile::load (input, error))
  1431. {
  1432. loader.setSong (std::move (*song));
  1433. ok = true;
  1434. }
  1435. if (ok)
  1436. {
  1437. const juce::File output (outputPath);
  1438. lynx::ExportSettings settings;
  1439. settings.wholeSong = ! patternOnly;
  1440. settings.format = output.hasFileExtension ("flac") ? lynx::ExportSettings::Format::flac24
  1441. : output.hasFileExtension ("ogg") ? lynx::ExportSettings::Format::ogg
  1442. : lynx::ExportSettings::Format::wav24;
  1443. // --insert N: only that insert's output (what "Render to audio" records)
  1444. if (juce::JUCEApplication::getCommandLineParameters().contains ("--no-effects")
  1445. || juce::JUCEApplication::getCommandLineParameters().contains ("--sem-efeitos")) // performance diagnostics; --sem-efeitos: legacy alias
  1446. loader.editSong ([] (lynx::Song& s) {
  1447. for (auto& t : s.mixer)
  1448. t.effects.clear();
  1449. }, false);
  1450. if (juce::JUCEApplication::getCommandLineParameters().contains ("--no-automation")
  1451. || juce::JUCEApplication::getCommandLineParameters().contains ("--sem-automacao")) // --sem-automacao: legacy alias
  1452. loader.editSong ([] (lynx::Song& s) { s.automations.clear(); }, false);
  1453. const auto loaded = juce::Time::getMillisecondCounterHiRes();
  1454. // .mp3: the Export window's MP3 (320 kbps); everything else as before
  1455. auto options = settings.toOptions();
  1456. if (output.hasFileExtension ("mp3"))
  1457. {
  1458. options.format = lynx::exportopts::Format::mp3;
  1459. options.mp3Kbps = 320;
  1460. }
  1461. lynx::ExportJob job (insert > 0 ? lynx::makeBounceSong (loader.getSong(), insert) : loader.getSong(), options, output);
  1462. const auto prepared = juce::Time::getMillisecondCounterHiRes();
  1463. int lastPercent = -1;
  1464. ok = job.run ([&lastPercent] (double p) {
  1465. lastPercent = (int) (p * 100.0);
  1466. return true;
  1467. }, error);
  1468. auto joined = [] (const std::map<std::string, int>& items) {
  1469. juce::StringArray names;
  1470. for (const auto& [name, count] : items)
  1471. names.add (juce::String::fromUTF8 (name.c_str()) + "x" + juce::String (count));
  1472. return names.joinIntoString (", ");
  1473. };
  1474. const auto& importReport = loader.getImportReport();
  1475. report << "converted=" << joined (importReport.converted) << "\n"
  1476. << "approximated=" << joined (importReport.approximated) << "\n"
  1477. << "unsupported=" << joined (importReport.unsupported) << "\n"
  1478. << "dropped_effects=" << joined (importReport.droppedEffects) << "\n"
  1479. << "missing_samples=" << importReport.missingSamples << "\n";
  1480. // third-party plugins: how each was found, or what plays in its place (diagnostics for level differences)
  1481. for (const auto& line : loader.getMatchedPlugins())
  1482. report << "plugin_found=" << line << "\n";
  1483. for (const auto& m : loader.getMissingPluginDetails())
  1484. report << "plugin_missing=" << juce::String::fromUTF8 (m.name.c_str()) << " -> "
  1485. << juce::String::fromUTF8 (m.replacement.c_str()).replace ("{0}", juce::String::fromUTF8 (m.replacementArg.c_str())) << "\n";
  1486. {
  1487. const auto& song = loader.getSong();
  1488. for (std::size_t t = 0; t < song.mixer.size(); ++t)
  1489. {
  1490. const auto& track = song.mixer[t];
  1491. if (track.effects.empty() && track.sends.empty())
  1492. continue;
  1493. report << "insert " << (int) t << " vol=" << juce::String (track.volume / lynx::unityFader, 3)
  1494. << (track.muted ? " muted" : "") << (track.toMaster ? "" : " noMaster");
  1495. for (const auto& s : track.sends)
  1496. report << " send>" << s.target << "@" << juce::String (s.level, 3);
  1497. report << " |";
  1498. for (const auto& fx : track.effects)
  1499. report << " [" << (fx.kind == lynx::EffectKind::plugin ? juce::String::fromUTF8 (fx.plugin.name.c_str())
  1500. : juce::String::fromUTF8 (lynx::effectInfo (fx.kind).name))
  1501. << (fx.isSubstitute() ? " (substitute)" : "") << (fx.enabled ? "" : " off")
  1502. << (fx.mix < 0.999f ? " mix=" + juce::String (fx.mix, 2) : juce::String()) << "]";
  1503. report << "\n";
  1504. }
  1505. }
  1506. report << "open_ms=" << juce::roundToInt (loaded - started) << "\n"
  1507. << "prepare_ms=" << juce::roundToInt (prepared - loaded) << "\n"
  1508. << "render_ms=" << juce::roundToInt (juce::Time::getMillisecondCounterHiRes() - prepared) << "\n"
  1509. << "graph_ms=" << juce::roundToInt (job.getEngine().getLastRenderStats().graphMs) << "\n"
  1510. << "write_ms=" << juce::roundToInt (job.getEngine().getLastRenderStats().writeMs) << "\n"
  1511. << "song_seconds=" << job.getMusicSeconds() << "\n"
  1512. << "peak=" << job.getPeak() << "\n"
  1513. << "final_progress=" << lastPercent << "\n"
  1514. << "bytes=" << output.getSize() << "\n";
  1515. ok = ok && job.getPeak() > 0.001f;
  1516. }
  1517. }
  1518. report << "result=" << (ok ? "OK" : "ERROR " + error) << "\n";
  1519. juce::File (outputPath + ".txt").replaceWithText (report);
  1520. setApplicationReturnValue (ok ? 0 : 1);
  1521. quit();
  1522. }
  1523. // LYNX.exe --snapshot prefix [project]: draws the window off-screen and writes
  1524. // prefix-rack.png, -pianoroll.png and -playlist.png (to check the UI without touching the screen).
  1525. void runPluginEditorSnapshots (const juce::String& folder)
  1526. {
  1527. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  1528. {
  1529. const juce::File out (folder);
  1530. out.createDirectory();
  1531. lynx::AudioEngine offline (false);
  1532. const auto roots = lynx::findFlStudioRoots();
  1533. const auto presets = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects");
  1534. auto kinds = lynx::plugui::flLayoutKinds();
  1535. kinds.push_back (lynx::EffectKind::maximus); // Soundgoodizer (below)
  1536. for (const auto own : lynx::plugui::ownLayoutKinds()) // LYNX's own panels (mixing suite, round 96)
  1537. kinds.push_back (own);
  1538. const auto database = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin database/Effects");
  1539. auto maximusPasses = 0; // Maximus has its own page (first pass); the second pass shows Soundgoodizer
  1540. for (const auto kind : kinds)
  1541. {
  1542. auto fx = lynx::makeEffectSlot (kind);
  1543. juce::String name (lynx::effectInfo (kind).name);
  1544. for (const auto& plugin : lynx::flPluginsForEffect (kind))
  1545. {
  1546. const auto dir = presets.getChildFile (juce::String::fromUTF8 (plugin.c_str()));
  1547. auto file = dir.getChildFile ("Default.fst");
  1548. if (! file.existsAsFile()) // plugins without presets: their entry of FL's plugin database
  1549. for (const auto& f : database.findChildFiles (juce::File::findFiles, true, juce::String::fromUTF8 (plugin.c_str()) + ".fst"))
  1550. file = f;
  1551. if (! file.existsAsFile())
  1552. {
  1553. auto files = dir.findChildFiles (juce::File::findFiles, true, "*.fst");
  1554. std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFullPathName().compareNatural (b.getFullPathName()) < 0; });
  1555. file = files.isEmpty() ? juce::File() : files[0];
  1556. }
  1557. juce::MemoryBlock data;
  1558. if (file.existsAsFile() && file.loadFileAsData (data))
  1559. {
  1560. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  1561. if (auto loaded = lynx::effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), 130.0); loaded && loaded->kind == kind)
  1562. fx = *loaded;
  1563. }
  1564. name = juce::String::fromUTF8 (plugin.c_str());
  1565. break;
  1566. }
  1567. if (kind == lynx::EffectKind::maximus && ++maximusPasses == 2) // Soundgoodizer: preset A of the installation, Amount 60 %
  1568. {
  1569. juce::MemoryBlock data;
  1570. juce::File (juce::String::fromUTF8 (roots.factoryData.c_str())).getChildFile ("Plugins/Fruity/Effects/Soundgoodizer/Data/Presets/a.dat").loadFileAsData (data);
  1571. lynx::maximusfx::Blob blob;
  1572. blob.build = lynx::hlfx::MaximusBuild::soundgoodizer;
  1573. blob.mix = 600;
  1574. const auto* b = static_cast<const std::uint8_t*> (data.getData());
  1575. blob.state.assign (b, b + data.getSize());
  1576. fx = lynx::makeEffectSlot (kind);
  1577. fx.state = lynx::maximusfx::pack (blob);
  1578. name = "Soundgoodizer";
  1579. }
  1580. if (kind == lynx::EffectKind::ridgeStrip) // a vocal setting, so the graphs show something
  1581. for (const auto& [param, value] : { std::pair<const char*, float> { "HPF", 0.3f }, { "LMF gain", 0.35f }, { "HF gain", 0.7f },
  1582. { "Ratio", 0.3f }, { "Comp. threshold", 0.55f } })
  1583. fx.params[(std::size_t) lynx::plugui::paramIndex (kind, param)] = value;
  1584. if (kind == lynx::EffectKind::ember)
  1585. {
  1586. fx.params[(std::size_t) lynx::plugui::paramIndex (kind, "Drive")] = 0.5f;
  1587. fx.params[(std::size_t) lynx::plugui::paramIndex (kind, "Bands")] = 1.0f; // round 108: the band rows
  1588. fx.params[(std::size_t) lynx::plugui::paramIndex (kind, "B3 drive")] = 0.6f;
  1589. }
  1590. if (kind == lynx::EffectKind::crestCompressor) // round 108: a curve with a knee and a side-chain low cut
  1591. for (const auto& [param, value] : { std::pair<const char*, float> { "Threshold", 0.55f }, { "Knee", 0.15f },
  1592. { "SC1 shape", 0.5f }, { "SC1 freq.", 0.3f } })
  1593. fx.params[(std::size_t) lynx::plugui::paramIndex (kind, param)] = value;
  1594. lynx::Song song;
  1595. song.mixer.resize (2);
  1596. song.mixer[0].name = "Master";
  1597. song.mixer[1].name = "Insert 1";
  1598. song.mixer[1].effects.push_back (fx);
  1599. offline.setSong (std::move (song));
  1600. offline.dispatchPendingMessages();
  1601. const auto pages = name == "Soundgoodizer" ? 1 : juce::jmax (1, (int) lynx::plugui::layoutFor (kind).pages.size());
  1602. for (int page = 0; page < pages; ++page)
  1603. {
  1604. auto editor = lynx::makeNativeEffectEditor (offline, 1, 0, 1.0f, page);
  1605. juce::Image image (juce::Image::ARGB, editor->getWidth(), editor->getHeight(), true);
  1606. {
  1607. juce::Graphics g (image);
  1608. g.fillAll (lynx::theme::panel);
  1609. editor->paintEntireComponent (g, false);
  1610. }
  1611. const auto file = out.getChildFile (name + (page > 0 ? "-p" + juce::String (page + 1) : juce::String()) + ".png");
  1612. file.deleteFile();
  1613. juce::PNGImageFormat png;
  1614. if (auto stream = file.createOutputStream())
  1615. png.writeImageToStream (image, *stream);
  1616. }
  1617. }
  1618. // LYNX's own editors with live displays (round 103): Facet EQ (a mixing curve, one dynamic band, demo analyser)
  1619. // and LYNX Tune (demo pitch phrase)
  1620. {
  1621. lynx::setNativeEditorDemo (true);
  1622. using namespace lynx::facet;
  1623. auto eq = lynx::makeEffectSlot (lynx::EffectKind::facetEq);
  1624. const struct { Shape s; double f, g, q; int slope; double range; } bandsDemo[] = {
  1625. { Shape::lowCut, 32, 0, 1, 24, 0 }, { Shape::bell, 110, 3, 1.2, 12, 0 }, { Shape::bell, 380, -3.5, 1.6, 12, 0 },
  1626. { Shape::bell, 3200, 0, 2.5, 12, -6 }, { Shape::highShelf, 9000, 2.5, 0.8, 12, 0 }
  1627. };
  1628. for (int b = 0; b < 5; ++b)
  1629. {
  1630. eq.params[(std::size_t) param (b, 0)] = shapeValue (bandsDemo[b].s);
  1631. eq.params[(std::size_t) param (b, 1)] = hzValue (bandsDemo[b].f);
  1632. eq.params[(std::size_t) param (b, 2)] = gainValue (bandsDemo[b].g);
  1633. eq.params[(std::size_t) param (b, 3)] = qValue (bandsDemo[b].q);
  1634. eq.params[(std::size_t) param (b, 4)] = slopeValue (bandsDemo[b].slope);
  1635. eq.params[(std::size_t) (rangeParam0 + b)] = rangeValue (bandsDemo[b].range);
  1636. }
  1637. eq.params[(std::size_t) phaseParam] = phaseValue (Phase::natural);
  1638. const auto own = [&] (const lynx::EffectSlot& fx, const juce::String& file, bool facetEditor) {
  1639. lynx::Song song;
  1640. song.mixer.resize (2);
  1641. song.mixer[0].name = "Master";
  1642. song.mixer[1].name = "Vocal";
  1643. song.mixer[1].effects.push_back (fx);
  1644. offline.setSong (std::move (song));
  1645. offline.dispatchPendingMessages();
  1646. auto editor = facetEditor ? lynx::makeFacetEqEditor (offline, 1, 0, true) : lynx::makeNativeEffectEditor (offline, 1, 0, 1.25f, 0);
  1647. juce::Image image (juce::Image::ARGB, editor->getWidth(), editor->getHeight(), true);
  1648. {
  1649. juce::Graphics g (image);
  1650. g.fillAll (lynx::theme::panel);
  1651. editor->paintEntireComponent (g, false);
  1652. }
  1653. const auto f = out.getChildFile (file);
  1654. f.deleteFile();
  1655. juce::PNGImageFormat png;
  1656. if (auto stream = f.createOutputStream())
  1657. png.writeImageToStream (image, *stream);
  1658. };
  1659. own (eq, "Facet EQ.png", true);
  1660. own (lynx::makeEffectSlot (lynx::EffectKind::lynxTune), "LYNX Tune.png", false);
  1661. lynx::setNativeEditorDemo (false);
  1662. }
  1663. // generators in FL's arrangement: the channel's plugin page with the FL preset's settings
  1664. const auto generators = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Generators");
  1665. for (auto [folder, preset] : std::vector<std::pair<const char*, const char*>> { { "3x Osc", "Default.fst" }, { "FL Keys", "Grand Piano.fst" }, { "BooBass", "" }, { "Sytrus", "Default.fst" }, { "Harmor", "Default.fst" } })
  1666. {
  1667. juce::MemoryBlock data;
  1668. if (juce::String (folder) == "Harmor") // the first preset whose state the engine reads
  1669. {
  1670. auto files = generators.getChildFile (folder).findChildFiles (juce::File::findFiles, true, "*.fst");
  1671. files.sort();
  1672. for (const auto& f : files)
  1673. {
  1674. juce::MemoryBlock block;
  1675. if (! f.loadFileAsData (block))
  1676. continue;
  1677. const auto* b = static_cast<const std::uint8_t*> (block.getData());
  1678. try
  1679. {
  1680. const auto p = flp::parseProject (std::vector<std::uint8_t> (b, b + block.getSize()), true);
  1681. if (! p.channels.empty() && lynx::harmorStateUsable (p.channels.front().pluginState))
  1682. {
  1683. preset = nullptr;
  1684. data = block;
  1685. break;
  1686. }
  1687. }
  1688. catch (const std::exception&)
  1689. {
  1690. }
  1691. }
  1692. }
  1693. auto file = preset == nullptr ? juce::File() : juce::String (preset).isEmpty() ? database.getSiblingFile ("Generators").getChildFile ("Misc").getChildFile (juce::String (folder) + ".fst")
  1694. : generators.getChildFile (folder).getChildFile (preset);
  1695. if (! file.existsAsFile())
  1696. {
  1697. auto files = generators.getChildFile (folder).findChildFiles (juce::File::findFiles, true, "*.fst");
  1698. files.sort();
  1699. file = files.isEmpty() ? juce::File() : files[0];
  1700. }
  1701. if (data.isEmpty() && ! file.loadFileAsData (data))
  1702. continue;
  1703. try
  1704. {
  1705. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  1706. auto project = flp::parseProject (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), true);
  1707. if (project.channels.empty())
  1708. continue;
  1709. project.channels.front().type = flp::ChannelType::native;
  1710. lynx::FlpImportOptions options;
  1711. options.roots = roots;
  1712. options.fileExists = [] (const std::string& path) { return lynx::platform::localFile (path).existsAsFile(); };
  1713. options.readFile = [] (const std::string& path) {
  1714. juce::MemoryBlock block;
  1715. lynx::platform::localFile (path).loadFileAsData (block);
  1716. const auto* b = static_cast<const std::uint8_t*> (block.getData());
  1717. return std::vector<std::uint8_t> (b, b + block.getSize());
  1718. };
  1719. options.saveEmbedded = [out] (const std::vector<std::uint8_t>& wav, const std::string& name) {
  1720. const auto f = out.getChildFile ("samples").getNonexistentChildFile (juce::String::fromUTF8 (name.c_str()), ".wav");
  1721. f.getParentDirectory().createDirectory();
  1722. f.replaceWithData (wav.data(), wav.size());
  1723. return f.getFullPathName().toStdString();
  1724. };
  1725. auto song = lynx::importFlp (project, options);
  1726. // the page only needs the plugin's saved state (FL Keys' sample zones need the installed wavetables)
  1727. if (! song.channels.empty() && project.channels.front().pluginName == "BooBass" && song.channels.front().instrument != lynx::InstrumentKind::boobass)
  1728. {
  1729. song.channels.front().instrument = lynx::InstrumentKind::boobass; // (its sound needs the engine DLL; the page does not)
  1730. song.channels.front().modelParams.assign (3, 32768.0f);
  1731. }
  1732. if (! song.channels.empty() && project.channels.front().pluginName == "FL Keys")
  1733. {
  1734. song.channels.front().instrument = lynx::InstrumentKind::flkeys;
  1735. song.channels.front().pluginState = project.channels.front().pluginState;
  1736. }
  1737. offline.setSong (std::move (song));
  1738. offline.dispatchPendingMessages();
  1739. if (offline.getSong().channels.empty())
  1740. continue;
  1741. auto panel = lynx::makeChannelSettingsPanel (offline, 0);
  1742. juce::Image image (juce::Image::ARGB, panel->getWidth(), panel->getHeight(), true);
  1743. {
  1744. juce::Graphics g (image);
  1745. g.fillAll (lynx::theme::panel);
  1746. panel->paintEntireComponent (g, false);
  1747. }
  1748. const auto out2 = out.getChildFile (juce::String (folder) + ".png");
  1749. out2.deleteFile();
  1750. juce::PNGImageFormat png;
  1751. if (auto stream = out2.createOutputStream())
  1752. png.writeImageToStream (image, *stream);
  1753. }
  1754. catch (const std::exception&)
  1755. {
  1756. }
  1757. }
  1758. }
  1759. quit();
  1760. }
  1761. void runSnapshot (const juce::String& prefix, const juce::String& projectPath)
  1762. {
  1763. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  1764. {
  1765. lynx::AudioEngine offline (false);
  1766. lynx::MainComponent ui (offline, false); // default layout and keys, nothing saved
  1767. // LYNX_SNAPSHOT_SIZE=WxH (default 1280x720)
  1768. const auto size = juce::StringArray::fromTokens (juce::SystemStats::getEnvironmentVariable ("LYNX_SNAPSHOT_SIZE", "1280x720"), "x", "");
  1769. ui.setSize (juce::jlimit (800, 3840, size[0].getIntValue()), juce::jlimit (450, 2160, size[1].getIntValue()));
  1770. if (projectPath.isNotEmpty())
  1771. ui.openFile (juce::File (projectPath));
  1772. offline.dispatchPendingMessages(); // change notifications are asynchronous
  1773. ui.waitForBrowserForSnapshot();
  1774. // the workspace desktop: the default layout, then with the Piano Roll and Mixer floating too
  1775. // (and a sample hint in the status strip, as when hovering a knob)
  1776. ui.showDesktopForSnapshot (false);
  1777. ui.setMetersForSnapshot (0.23, (std::int64_t) 412 << 20, 6);
  1778. offline.dispatchPendingMessages();
  1779. saveSnapshot (ui, prefix + "-desktop.png");
  1780. // the start-up desktop and the toolbar at the usual window sizes: the untouched default layout
  1781. // follows the window (default rects, not scaled ones); panels drop from the toolbar by priority
  1782. {
  1783. const auto size = ui.getBounds();
  1784. for (const auto& [w, h] : std::vector<std::pair<int, int>> { { 1280, 720 }, { 1600, 900 }, { 1920, 1080 }, { 2560, 1440 } })
  1785. {
  1786. ui.setSize (w, h);
  1787. offline.dispatchPendingMessages();
  1788. saveSnapshot (ui, prefix + "-desktop-" + juce::String (w) + ".png");
  1789. saveArea (ui, ui.getToolbarBoundsForSnapshot(), prefix + "-toolbar-" + juce::String (w) + ".png");
  1790. if (w == 1920) // the rack scrolled to its last steps: the controls column stays in view (round 90)
  1791. {
  1792. ui.scrollRackForSnapshot (100000);
  1793. offline.dispatchPendingMessages();
  1794. saveSnapshot (ui, prefix + "-desktop-rack-scrolled.png");
  1795. ui.scrollRackForSnapshot (0);
  1796. }
  1797. }
  1798. // the toolbar with small and large icons, and a customized one (groups hidden and reordered)
  1799. ui.setSize (1600, 900);
  1800. for (auto [iconSize, name] : { std::pair { lynx::toolbarlayout::IconSize::small, "small" }, { lynx::toolbarlayout::IconSize::large, "large" } })
  1801. {
  1802. auto layout = lynx::toolbarlayout::Layout::makeDefault();
  1803. layout.iconSize = iconSize;
  1804. ui.setToolbarLayoutForSnapshot (layout);
  1805. saveArea (ui, ui.getToolbarBoundsForSnapshot(), prefix + "-toolbar-" + name + "-1600.png");
  1806. }
  1807. {
  1808. auto layout = lynx::toolbarlayout::Layout::makeDefault();
  1809. layout.move (lynx::toolbarlayout::Group::windows, -3);
  1810. layout.setShown (lynx::toolbarlayout::Group::record, false);
  1811. layout.setShown (lynx::toolbarlayout::Group::meters, false);
  1812. ui.setToolbarLayoutForSnapshot (layout);
  1813. saveArea (ui, ui.getToolbarBoundsForSnapshot(), prefix + "-toolbar-custom-1600.png");
  1814. }
  1815. ui.setToolbarLayoutForSnapshot (lynx::toolbarlayout::Layout::makeDefault());
  1816. // quick tips: the toolbar and title bars with a few name bubbles, and every tip on one sheet
  1817. offline.dispatchPendingMessages();
  1818. saveQuickTips (ui, prefix);
  1819. ui.setBounds (size);
  1820. offline.dispatchPendingMessages();
  1821. }
  1822. // the hint bar: a value control while it is dragged (live value), a gesture line with mouse and key
  1823. // glyphs, and a text too long for one line (two lines)
  1824. {
  1825. const auto toolbar = ui.getToolbarBoundsForSnapshot().withWidth (juce::jmin (ui.getWidth(), 900));
  1826. const lynx::ui::Hint hints[] = {
  1827. { lynx::tr ("Volume") + " - " + lynx::tr ("drag (Ctrl: fine), wheel, Alt+click resets"), "-3.2 dB", true, true },
  1828. { lynx::tr ("Piano Roll: [LMB] add a note, drag to move [RMB] delete [Ctrl][LMB] drag to select [Ctrl][Wheel] zoom"), {}, false, false },
  1829. { lynx::tr ("Global snap: the grid of the Piano Roll and Playlist (when they follow it) and the quantise of recorded notes "
  1830. "[LMB] choose [Wheel] step [RMB] length of new notes [Backspace] snap on/off [Alt] while dragging: no snap"), {}, false, true },
  1831. };
  1832. for (int i = 0; i < 3; ++i)
  1833. {
  1834. ui.setHintForSnapshot (hints[i], i == 0);
  1835. saveArea (ui, toolbar, prefix + "-hint-" + juce::String (i + 1) + ".png");
  1836. }
  1837. }
  1838. ui.showDesktopForSnapshot (true);
  1839. ui.setHintForSnapshot ({ lynx::tr ("Volume") + " - " + lynx::tr ("drag (Ctrl: fine), wheel, Alt+click resets"), "78%", true, true });
  1840. saveSnapshot (ui, prefix + "-desktop-all.png");
  1841. ui.selectTabForSnapshot (0);
  1842. saveSnapshot (ui, prefix + "-rack.png");
  1843. {
  1844. // a pattern with piano-roll notes: those rows show a miniature instead of steps (round 90)
  1845. int found = -1;
  1846. const auto before = offline.getSong().currentPattern;
  1847. {
  1848. const auto& song = offline.getSong();
  1849. for (int p = 0; p < (int) song.patterns.size() && found < 0; ++p)
  1850. for (int c = 0; c < (int) song.channels.size() && found < 0; ++c)
  1851. if (lynx::showsNotePreview (song.patterns[(std::size_t) p], c))
  1852. found = p;
  1853. }
  1854. if (found >= 0)
  1855. {
  1856. offline.editSong ([found] (lynx::Song& s) { s.currentPattern = found; }, false);
  1857. offline.dispatchPendingMessages();
  1858. saveSnapshot (ui, prefix + "-rack-preview.png");
  1859. offline.editSong ([before] (lynx::Song& s) { s.currentPattern = before; }, false);
  1860. offline.dispatchPendingMessages();
  1861. }
  1862. }
  1863. ui.selectTabForSnapshot (1);
  1864. saveSnapshot (ui, prefix + "-pianoroll.png");
  1865. if (const auto strip = ui.getToolStripAreaForSnapshot (false); ! strip.isEmpty())
  1866. saveArea (ui, strip, prefix + "-pianoroll-tools.png");
  1867. // the editors' mouse feel: the hovered note / clip edge (grip, outline) and its hint in the hint bar
  1868. ui.setHintForSnapshot (ui.getPianoRollForSnapshot().hoverForSnapshot());
  1869. saveSnapshot (ui, prefix + "-pianoroll-hover.png");
  1870. ui.selectTabForSnapshot (2);
  1871. saveSnapshot (ui, prefix + "-playlist.png");
  1872. if (const auto strip = ui.getToolStripAreaForSnapshot (true); ! strip.isEmpty())
  1873. saveArea (ui, strip, prefix + "-playlist-tools.png");
  1874. ui.setHintForSnapshot (ui.getPlaylistForSnapshot().hoverForSnapshot());
  1875. saveSnapshot (ui, prefix + "-playlist-hover.png");
  1876. ui.setHintForSnapshot ({ lynx::tr ("Volume") + " - " + lynx::tr ("drag (Ctrl: fine), wheel, Alt+click resets"), "78%", true, true });
  1877. // the Playlist with a time selection over bars 2-3 (it selects the clips it touches) and the Knife tool
  1878. ui.getPlaylistForSnapshot().setTimeSelectionForSnapshot (1, 3);
  1879. ui.getPlaylistForSnapshot().setToolForSnapshot (lynx::EditTool::knife);
  1880. offline.dispatchPendingMessages();
  1881. saveSnapshot (ui, prefix + "-playlist-timesel.png");
  1882. ui.getPlaylistForSnapshot().setToolForSnapshot (lynx::EditTool::pencil);
  1883. // round 104: a folded track group (FL's thin member rows) and the Picker's audio tab
  1884. {
  1885. int header = -1;
  1886. for (int t = 0; t < (int) offline.getSong().playlistTracks.size() && header < 0; ++t)
  1887. if (lynx::noteedit::isGroupHeader (offline.getSong(), t))
  1888. header = t;
  1889. if (header >= 0)
  1890. {
  1891. offline.editSong ([header] (lynx::Song& s) { lynx::noteedit::setGroupCollapsed (s, header, true); }, false);
  1892. offline.dispatchPendingMessages();
  1893. saveSnapshot (ui, prefix + "-playlist-group-folded.png");
  1894. offline.editSong ([header] (lynx::Song& s) { lynx::noteedit::setGroupCollapsed (s, header, false); }, false);
  1895. }
  1896. ui.getPickerForSnapshot().setView (1);
  1897. offline.dispatchPendingMessages();
  1898. saveSnapshot (ui, prefix + "-playlist-picker-audio.png");
  1899. ui.getPickerForSnapshot().setView (0);
  1900. }
  1901. // round 104: the Channel Rack filtered to its first filter group
  1902. if (! offline.getSong().channelGroups.empty())
  1903. {
  1904. ui.selectTabForSnapshot (0);
  1905. ui.getRackForSnapshot().setFilterGroup (0);
  1906. offline.dispatchPendingMessages();
  1907. saveSnapshot (ui, prefix + "-rack-filter.png");
  1908. ui.getRackForSnapshot().setFilterGroup (-1);
  1909. }
  1910. ui.selectTabForSnapshot (3);
  1911. // LYNX_SNAPSHOT_TRACK=n: shows the effects of that mixer track
  1912. if (const auto track = juce::SystemStats::getEnvironmentVariable ("LYNX_SNAPSHOT_TRACK", {}); track.isNotEmpty())
  1913. {
  1914. ui.selectMixerTrackForSnapshot (track.getIntValue(),
  1915. juce::SystemStats::getEnvironmentVariable ("LYNX_SNAPSHOT_SLOT", "-1").getIntValue());
  1916. offline.dispatchPendingMessages();
  1917. }
  1918. saveSnapshot (ui, prefix + "-mixer.png");
  1919. // standalone windows, with the theme background
  1920. auto saveWindow = [&prefix] (std::unique_ptr<juce::Component> c, const juce::String& name) {
  1921. juce::Component frame;
  1922. frame.setSize (c->getWidth(), c->getHeight());
  1923. frame.setOpaque (true);
  1924. frame.addAndMakeVisible (*c);
  1925. c->setTopLeftPosition (0, 0);
  1926. juce::Image image (juce::Image::ARGB, frame.getWidth(), frame.getHeight(), true);
  1927. {
  1928. juce::Graphics g (image);
  1929. g.fillAll (lynx::theme::panel);
  1930. frame.paintEntireComponent (g, false);
  1931. }
  1932. const juce::File file (prefix + name);
  1933. file.deleteFile();
  1934. juce::PNGImageFormat png;
  1935. if (auto out = file.createOutputStream())
  1936. png.writeImageToStream (image, *out);
  1937. };
  1938. saveWindow (lynx::makeExportPanel (offline), "-export.png");
  1939. saveWindow (lynx::makeExportPanel (offline, 1), "-export-mp3.png");
  1940. saveWindow (lynx::makeExportPanel (offline, 3), "-export-flac-stems.png");
  1941. saveSplashFrames (prefix);
  1942. saveIconSheet (prefix + "-icons.png", 1.0f);
  1943. saveIconSheet (prefix + "-icons-150.png", 1.5f);
  1944. saveWindow (lynx::MainComponent::makeHelpContent(), "-help.png");
  1945. saveWindow (std::make_unique<lynx::toolbar::CustomizePanel> (lynx::toolbarlayout::Layout::makeDefault()), "-customize-toolbar.png");
  1946. saveMenus (ui, prefix + "-menus.png");
  1947. {
  1948. // the windows' own menus (title bars) and the toolbar's recording menu
  1949. juce::StringArray names;
  1950. std::vector<juce::PopupMenu> menus;
  1951. for (auto [panel, name] : { std::pair { lynx::workspace::Panel::playlist, "Playlist" }, { lynx::workspace::Panel::channelRack, "Channel Rack" },
  1952. { lynx::workspace::Panel::pianoRoll, "Piano Roll" }, { lynx::workspace::Panel::mixer, "Mixer" },
  1953. { lynx::workspace::Panel::browser, "Browser" } })
  1954. {
  1955. names.add (name);
  1956. menus.push_back (ui.getPanelMenuForSnapshot (panel));
  1957. }
  1958. names.add ("Recording");
  1959. menus.push_back (ui.getRecordMenuForSnapshot());
  1960. names.add ("Toolbar");
  1961. menus.push_back (ui.getToolbarMenuForSnapshot());
  1962. saveMenus (names, menus, prefix + "-panel-menus.png");
  1963. }
  1964. auto saveAlert = [&] (std::unique_ptr<juce::AlertWindow> alert, const juce::String& name) {
  1965. alert->setOpaque (true);
  1966. saveWindow (std::move (alert), name);
  1967. };
  1968. saveAlert (ui.makeConfirmDiscardWindow(), "-confirm.png");
  1969. saveAlert (lynx::MainComponent::makeAboutWindow(), "-about.png");
  1970. saveAlert (lynx::makeNameAndColourDialog (lynx::tr ("Rename pattern"), "Pattern 2", lynx::lynxPalette()[6]), "-rename.png");
  1971. saveAlert (lynx::makeRecordChoiceDialog(), "-record-dialog.png");
  1972. saveWindow (lynx::makeSetupWizardContent (offline, {}, {}), "-setup.png");
  1973. saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 0, 1), "-missing-files.png");
  1974. saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 1), "-missing-plugins.png");
  1975. saveWindow (lynx::makeMissingFilesPanel (lynx::missingFilesSnapshotInfo(), 2), "-missing-found.png");
  1976. {
  1977. // the Settings pages, with credits like a project imported from FL would carry
  1978. offline.editSong ([] (lynx::Song& s) {
  1979. s.info = { "Night Drive", "LYNX demo", "Synthwave", "https://lynx-share.com",
  1980. "Made with LYNX.\nDrums and bass from the Channel Rack, pads from the Browser.", false };
  1981. }, false);
  1982. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::project), "-settings-project.png");
  1983. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::info), "-settings-info.png");
  1984. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::files), "-settings-files.png");
  1985. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::general), "-settings-general.png");
  1986. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::audio), "-settings-audio.png");
  1987. saveWindow (lynx::makeSettingsPanel (offline, lynx::SettingsPage::midi), "-settings-midi.png");
  1988. saveWindow (lynx::makePluginManagerPanel (offline, false), "-plugin-manager.png");
  1989. saveWindow (lynx::makeShortcutManagerPanel (false), "-shortcuts.png");
  1990. }
  1991. {
  1992. // round 84: New project, Clip properties, Arrangements, Plugin performance monitor, Touch keyboard
  1993. saveWindow (lynx::makeNewProjectPanel(), "-new-project.png");
  1994. const auto& clips = offline.getSong().playlist;
  1995. for (int i = 0; i < (int) clips.size(); ++i)
  1996. if (clips[(std::size_t) i].kind == lynx::ClipKind::pattern)
  1997. {
  1998. saveWindow (lynx::makeClipPropertiesPanel (offline, i, { i, (i + 1) % (int) clips.size() }), "-clip-properties.png");
  1999. break;
  2000. }
  2001. for (int i = 0; i < (int) clips.size(); ++i)
  2002. if (clips[(std::size_t) i].kind == lynx::ClipKind::audio)
  2003. {
  2004. saveWindow (lynx::makeClipPropertiesPanel (offline, i, { i }), "-clip-properties-audio.png");
  2005. break;
  2006. }
  2007. if (offline.getSong().arrangements.size() < 2)
  2008. offline.editSong ([] (lynx::Song& s) {
  2009. const auto current = s.currentArrangement;
  2010. s.addArrangement ("Radio edit", true);
  2011. s.addArrangement ("Intro loop");
  2012. s.selectArrangement (current);
  2013. }, false);
  2014. saveWindow (lynx::makeArrangementsPanel (offline), "-arrangements.png");
  2015. saveWindow (lynx::makePluginMonitorPanel (offline), "-plugin-monitor.png");
  2016. saveWindow (lynx::makeTouchKeyboardPanel (offline), "-touch-keyboard.png");
  2017. }
  2018. if (! offline.getSong().automations.empty())
  2019. {
  2020. auto editor = lynx::makeAutomationEditor (offline, 0);
  2021. editor->setSize (760, 300);
  2022. saveWindow (std::move (editor), "-automation.png");
  2023. }
  2024. saveWindow (lynx::makeChannelSettingsPanel (offline, 0), "-sampler.png");
  2025. for (int c = 0; c < (int) offline.getSong().channels.size(); ++c)
  2026. if (offline.getSong().channels[(std::size_t) c].instrument == lynx::InstrumentKind::synth)
  2027. {
  2028. saveWindow (lynx::makeChannelSettingsPanel (offline, c), "-synth.png");
  2029. saveWindow (lynx::makeChannelModulationPanel (offline, c), "-modulation.png");
  2030. break;
  2031. }
  2032. for (int c = 0; c < (int) offline.getSong().channels.size(); ++c)
  2033. if (offline.getSong().channels[(std::size_t) c].instrument == lynx::InstrumentKind::controller)
  2034. {
  2035. saveWindow (lynx::makeChannelSettingsPanel (offline, c), "-controller.png");
  2036. break;
  2037. }
  2038. for (const auto kind : { lynx::InstrumentKind::sakura, lynx::InstrumentKind::drumpad })
  2039. for (int c = 0; c < (int) offline.getSong().channels.size(); ++c)
  2040. if (offline.getSong().channels[(std::size_t) c].instrument == kind)
  2041. {
  2042. saveWindow (lynx::makeChannelSettingsPanel (offline, c), kind == lynx::InstrumentKind::sakura ? "-sakura.png" : "-drumpad.png");
  2043. break;
  2044. }
  2045. // parametric EQ: the one with the most pronounced curve (in an imported .flp, with FL's settings)
  2046. {
  2047. int bestTrack = -1, bestSlot = -1;
  2048. double bestShape = -1.0;
  2049. const auto& mixer = offline.getSong().mixer;
  2050. for (int t = 0; t < (int) mixer.size(); ++t)
  2051. for (int s = 0; s < (int) mixer[(std::size_t) t].effects.size(); ++s)
  2052. if (const auto& fx = mixer[(std::size_t) t].effects[(std::size_t) s]; fx.kind == lynx::EffectKind::parametricEq)
  2053. {
  2054. double shape = 0.0;
  2055. for (double hz = 30.0; hz < 18000.0; hz *= 1.5)
  2056. shape += std::abs (lynx::peq::responseDb (fx.params, 48000.0, hz));
  2057. if (shape > bestShape)
  2058. {
  2059. bestShape = shape;
  2060. bestTrack = t;
  2061. bestSlot = s;
  2062. }
  2063. }
  2064. if (bestTrack >= 0)
  2065. saveWindow (lynx::makeParametricEqEditor (offline, bestTrack, bestSlot), "-peq.png");
  2066. }
  2067. // Note inspector for the Piano Roll's notes (its selection, or all of the channel's notes)
  2068. if (auto inspector = ui.getPianoRollForSnapshot().makeNoteInspectorForSnapshot())
  2069. saveWindow (std::move (inspector), "-noteinspector.png");
  2070. if (auto inspector = ui.getPianoRollForSnapshot().makeNoteInspectorForSnapshot (true))
  2071. saveWindow (std::move (inspector), "-noteinspector-one.png");
  2072. // workflow P2: note tool dialogs (they preview on the pattern; each one puts the notes back when destroyed)
  2073. {
  2074. auto& roll = ui.getPianoRollForSnapshot();
  2075. const std::pair<lynx::NoteTool, const char*> tools[] = { { lynx::NoteTool::strum, "-tool-strum.png" },
  2076. { lynx::NoteTool::arpeggiate, "-tool-arpeggiate.png" },
  2077. { lynx::NoteTool::flip, "-tool-flip.png" },
  2078. { lynx::NoteTool::randomise, "-tool-randomise.png" },
  2079. { lynx::NoteTool::scaleLevels, "-tool-scalelevels.png" },
  2080. { lynx::NoteTool::limit, "-tool-limit.png" },
  2081. { lynx::NoteTool::quantize, "-tool-quantize.png" },
  2082. { lynx::NoteTool::chop, "-tool-chop.png" },
  2083. { lynx::NoteTool::flam, "-tool-flam.png" },
  2084. { lynx::NoteTool::lfo, "-tool-lfo.png" },
  2085. { lynx::NoteTool::claw, "-tool-claw.png" },
  2086. { lynx::NoteTool::articulate, "-tool-articulate.png" },
  2087. { lynx::NoteTool::riffMachine, "-tool-riff.png" },
  2088. { lynx::NoteTool::chordProgression, "-tool-chords.png" } };
  2089. for (const auto& [tool, name] : tools)
  2090. saveWindow (lynx::makeNoteToolPanel (offline, tool, roll.noteIndicesForSnapshot(), roll.gridForSnapshot()), name);
  2091. }
  2092. // round 83: the event editor, with sample events on the selected channel's volume (removed afterwards)
  2093. {
  2094. const lynx::AutomationTarget volume { lynx::AutomationTargetKind::channelVolume, offline.getSelectedChannel() };
  2095. const auto before = offline.getSong().patterns[(std::size_t) offline.getSong().currentPattern].events;
  2096. offline.editSong ([&] (lynx::Song& s) {
  2097. auto& lane = lynx::eventedit::laneFor (s.patterns[(std::size_t) s.currentPattern], volume);
  2098. lynx::eventedit::line (lane, 0, lynx::ppq * 2, 0.2f, 0.9f, lynx::ticksPerStep);
  2099. lynx::prtools::LfoOptions lfo;
  2100. lfo.startSpeed = 7 * 4096; // one beat
  2101. lynx::eventedit::applyLfo (lane, lynx::ppq * 2, lynx::ppq * 4, lfo, lynx::ticksPerStep);
  2102. }, false);
  2103. saveWindow (lynx::makeEventEditor (offline, volume), "-eventeditor.png");
  2104. offline.editSong ([&] (lynx::Song& s) { s.patterns[(std::size_t) s.currentPattern].events = before; }, false);
  2105. }
  2106. // round 86: the audio editor with a synthetic drum loop (markers, a region, a loop), waveform and spectrogram,
  2107. // and its menu items (-audioeditor-menu.txt)
  2108. {
  2109. namespace ae = lynx::audioedit;
  2110. ae::Document d;
  2111. d.title = "Drum loop";
  2112. d.audio.sampleRate = 44100.0;
  2113. const auto frames = (std::size_t) (44100 * 2);
  2114. d.audio.channels.assign (2, std::vector<float> (frames, 0.0f));
  2115. std::uint32_t seed = 7;
  2116. for (int hit = 0; hit < 8; ++hit)
  2117. {
  2118. const auto at = (std::size_t) hit * frames / 8;
  2119. const auto kick = hit % 2 == 0;
  2120. double phase = 0.0;
  2121. for (std::size_t i = 0; i < 12000 && at + i < frames; ++i)
  2122. {
  2123. seed = seed * 1664525u + 1013904223u;
  2124. const auto noise = (float) (seed >> 8) / 16777216.0f - 0.5f;
  2125. const auto t = (double) i / 44100.0;
  2126. phase += 2.0 * 3.141592653589793 * (kick ? 45.0 + 160.0 * std::exp (-t * 30.0) : 190.0) / 44100.0;
  2127. const auto body = (float) std::sin (phase) * (float) std::exp (-t * (kick ? 9.0 : 22.0));
  2128. const auto v = kick ? 0.85f * body : 0.35f * body + 0.6f * noise * (float) std::exp (-t * 18.0);
  2129. d.audio.channels[0][at + i] += v;
  2130. d.audio.channels[1][at + i] += kick ? v : v * 0.8f + 0.1f * noise * (float) std::exp (-t * 30.0);
  2131. }
  2132. }
  2133. ae::addMarker (d, (std::int64_t) frames / 8, "Snare");
  2134. ae::addRegion (d, { (std::int64_t) frames / 2, (std::int64_t) frames * 3 / 4 }, "Fill");
  2135. ae::setLoop (d, { 0, (std::int64_t) frames });
  2136. auto wave = lynx::makeAudioEditorForSnapshot (offline, d, false);
  2137. juce::File (prefix + "-audioeditor-menu.txt").replaceWithText (lynx::audioEditorMenuForSnapshot (*wave).joinIntoString ("\n") + "\n");
  2138. saveWindow (std::move (wave), "-audioeditor.png");
  2139. saveWindow (lynx::makeAudioEditorForSnapshot (offline, d, true), "-audioeditor-spectrum.png");
  2140. }
  2141. // the Channel Rack with the step graph lane (velocity), and the Euclidean fill window
  2142. ui.selectTabForSnapshot (0);
  2143. ui.getRackForSnapshot().setGraphLevelForSnapshot (0);
  2144. offline.dispatchPendingMessages();
  2145. saveSnapshot (ui, prefix + "-rack-graph.png");
  2146. ui.getRackForSnapshot().setGraphLevelForSnapshot (1);
  2147. saveSnapshot (ui, prefix + "-rack-graph-pan.png");
  2148. ui.getRackForSnapshot().toggleGraphLanes();
  2149. saveWindow (ui.getRackForSnapshot().makeEuclideanPanel (0), "-euclidean.png");
  2150. // the Mixer with three inserts selected and one armed for recording
  2151. ui.selectTabForSnapshot (3);
  2152. if (offline.getSong().mixer.size() > 4)
  2153. {
  2154. ui.getMixerForSnapshot().getStripsForSnapshot().setSelection ({ 1, 2, 3 }, 2);
  2155. offline.setInsertArmed (3, true);
  2156. offline.dispatchPendingMessages();
  2157. saveSnapshot (ui, prefix + "-mixer-multi.png");
  2158. // the armed insert with an audio input (its input row in the side panel, the level bar on the strip)
  2159. offline.editSong ([] (lynx::Song& s) { s.mixer[3].inputChannel = 0; });
  2160. ui.getMixerForSnapshot().selectTrack (3);
  2161. offline.dispatchPendingMessages();
  2162. saveSnapshot (ui, prefix + "-mixer-input.png");
  2163. offline.undo();
  2164. offline.setInsertArmed (3, false);
  2165. ui.getMixerForSnapshot().getStripsForSnapshot().setSelection ({}, 0);
  2166. }
  2167. // the Mixer's routing lane: an insert with sends selected (send knobs and wires)
  2168. if (offline.getSong().mixer.size() > 6)
  2169. {
  2170. int source = -1;
  2171. for (int t = 1; t < (int) offline.getSong().mixer.size() && source < 0; ++t)
  2172. if (! offline.getSong().mixer[(std::size_t) t].sends.empty())
  2173. source = t;
  2174. const auto temporary = source < 0;
  2175. if (temporary) // the demo has no sends: add two for the picture
  2176. {
  2177. source = 1;
  2178. offline.editSong ([] (lynx::Song& s) { s.setRoute (1, 5, true, 0.6f); s.setRoute (1, 6, true, 0.3f); s.setRoute (4, 1, true, 0.8f); });
  2179. }
  2180. ui.getMixerForSnapshot().selectTrack (source);
  2181. offline.dispatchPendingMessages();
  2182. saveSnapshot (ui, prefix + "-mixer-sends.png");
  2183. if (temporary)
  2184. offline.editSong ([] (lynx::Song& s) { s.setRoute (1, 5, false); s.setRoute (1, 6, false); s.setRoute (4, 1, false); });
  2185. ui.getMixerForSnapshot().selectTrack (0);
  2186. }
  2187. // the Playlist with ripple editing on
  2188. ui.selectTabForSnapshot (2);
  2189. ui.getPlaylistForSnapshot().setRipple (true);
  2190. saveSnapshot (ui, prefix + "-playlist-ripple.png");
  2191. ui.getPlaylistForSnapshot().setRipple (false);
  2192. // quick-add palette, and the Browser searching
  2193. saveWindow (ui.makeQuickAddForSnapshot(), "-quickadd.png");
  2194. ui.showDesktopForSnapshot (false);
  2195. ui.getBrowserForSnapshot().setSearchForSnapshot ("kick");
  2196. offline.dispatchPendingMessages();
  2197. saveSnapshot (ui, prefix + "-browser-search.png");
  2198. ui.getBrowserForSnapshot().setSearchForSnapshot ({});
  2199. ui.getBrowserForSnapshot().selectFirstSampleForSnapshot(); // the tree with a sample selected and its waveform
  2200. offline.dispatchPendingMessages();
  2201. saveSnapshot (ui, prefix + "-browser-tree.png");
  2202. // the undo history after a few edits
  2203. offline.editSong ([] (lynx::Song& s) { s.bpm += 1.0; });
  2204. offline.editSong ([] (lynx::Song& s) { if (! s.channels.empty()) s.channels[0].muted = ! s.channels[0].muted; });
  2205. offline.editSong ([] (lynx::Song& s) { if (! s.patterns.empty()) s.patterns[(std::size_t) s.currentPattern].notes.push_back ({}); });
  2206. offline.undo();
  2207. saveWindow (lynx::makeHistoryPanel (offline), "-history.png");
  2208. // spectral waveforms: a synthetic beat (kick, hats, a chord, a noise riser) as audio clips in spectral
  2209. // colours, zoomed in, classic and stereo; the same file in the Sampler editor and the Browser preview
  2210. {
  2211. const juce::File wav (prefix + "-wavedemo.wav");
  2212. writeWaveDemo (wav, offline.getSong().bpm);
  2213. const auto path = wav.getFullPathName();
  2214. const auto pathUtf8 = path.toStdString();
  2215. int samplerChannel = -1, firstTrack = 0;
  2216. offline.editSong ([&] (lynx::Song& s) {
  2217. for (const auto& clip : s.playlist)
  2218. firstTrack = std::max (firstTrack, clip.track + 1);
  2219. lynx::ChannelDef audio;
  2220. audio.name = "Beat (audio)";
  2221. audio.instrument = lynx::InstrumentKind::audioClip;
  2222. audio.samplePath = pathUtf8;
  2223. s.channels.push_back (audio);
  2224. const auto audioChannel = (int) s.channels.size() - 1;
  2225. lynx::ChannelDef sampler = audio;
  2226. sampler.name = "Beat (sampler)";
  2227. sampler.instrument = lynx::InstrumentKind::sampler;
  2228. sampler.sampler.regionStart = 0.06f;
  2229. sampler.sampler.regionEnd = 0.94f;
  2230. s.channels.push_back (sampler);
  2231. samplerChannel = (int) s.channels.size() - 1;
  2232. const auto bar = (std::int64_t) lynx::ppq * std::max (1, s.beatsPerBar);
  2233. const auto whole = (std::int64_t) std::llround (8.0 * s.bpm / 60.0 * lynx::ppq);
  2234. lynx::Clip clip;
  2235. clip.kind = lynx::ClipKind::audio;
  2236. clip.channel = audioChannel;
  2237. clip.track = firstTrack;
  2238. clip.length = whole;
  2239. s.playlist.push_back (clip);
  2240. clip.track = firstTrack + 1; // a slice of it, later in the song
  2241. clip.start = bar;
  2242. clip.offset = bar;
  2243. clip.length = 2 * bar;
  2244. s.playlist.push_back (clip);
  2245. // taller rows for the audio (tracks can be resized: P18)
  2246. if ((int) s.playlistTracks.size() < firstTrack + 2)
  2247. s.playlistTracks.resize ((std::size_t) firstTrack + 2);
  2248. s.playlistTracks[(std::size_t) firstTrack].height = 80;
  2249. s.playlistTracks[(std::size_t) firstTrack + 1].height = 60;
  2250. });
  2251. offline.dispatchPendingMessages();
  2252. auto& cache = *lynx::ui::WaveformCache::getInstance();
  2253. cache.find (path, [&offline, path] { return offline.getSampleLibrary().load (path); });
  2254. cache.waitUntilIdle (30000);
  2255. ui.selectTabForSnapshot (2);
  2256. auto& playlist = ui.getPlaylistForSnapshot();
  2257. playlist.setTimeSelectionForSnapshot (0, 0);
  2258. {
  2259. // the Playlist alone (the floating Channel Rack would cover the clips)
  2260. auto saveSnapshot = [&playlist] (juce::Component&, const juce::String& file) { saveArea (playlist, playlist.getLocalBounds(), file); };
  2261. playlist.setViewForSnapshot (180.0, 0, std::max (0, firstTrack - 3));
  2262. saveSnapshot (ui, prefix + "-playlist-audio.png");
  2263. playlist.setViewForSnapshot (1400.0, 0, std::max (0, firstTrack - 3));
  2264. saveSnapshot (ui, prefix + "-playlist-audio-zoom.png");
  2265. lynx::ui::WaveformCache::stereo = true;
  2266. saveSnapshot (ui, prefix + "-playlist-audio-stereo.png");
  2267. lynx::ui::WaveformCache::stereo = false;
  2268. lynx::ui::WaveformCache::spectral = true;
  2269. playlist.setViewForSnapshot (180.0, 0, std::max (0, firstTrack - 3));
  2270. saveSnapshot (ui, prefix + "-playlist-audio-spectral.png");
  2271. lynx::ui::WaveformCache::spectral = false;
  2272. playlist.setViewForSnapshot (40.0, 0, 0);
  2273. saveSnapshot (ui, prefix + "-playlist-audio-far.png");
  2274. // LYNX_SNAPSHOT_AUDIO=a.wav;b.wav...: real audio as clips (default-height tracks, one tall,
  2275. // a fade, a reversed copy), at three zoom levels
  2276. if (const auto files = juce::StringArray::fromTokens (juce::SystemStats::getEnvironmentVariable ("LYNX_SNAPSHOT_AUDIO", {}), ";", "");
  2277. ! files.isEmpty())
  2278. {
  2279. const auto realTrack = firstTrack + 2;
  2280. std::vector<juce::String> paths;
  2281. for (const auto& f : files)
  2282. if (juce::File (f.trim()).existsAsFile())
  2283. paths.push_back (f.trim());
  2284. offline.editSong ([&] (lynx::Song& s) {
  2285. const auto bar = (std::int64_t) lynx::ppq * std::max (1, s.beatsPerBar);
  2286. const std::uint32_t colours[] = { 0, 0xffd9a441, 0xff6fb36a, 0xffb06fd0, 0xff5fb7c9, 0xffd06f6f };
  2287. for (std::size_t i = 0; i < paths.size(); ++i)
  2288. {
  2289. lynx::ChannelDef audio;
  2290. audio.name = juce::File (paths[i]).getFileNameWithoutExtension().toStdString();
  2291. audio.instrument = lynx::InstrumentKind::audioClip;
  2292. audio.samplePath = paths[i].toStdString();
  2293. audio.colour = colours[i % 6];
  2294. audio.sampler.stretchBeats = i % 2 == 0 ? 16.0f : 0.0f; // fitted to 4 bars, or as recorded
  2295. audio.sampler.keepPitch = true;
  2296. s.channels.push_back (audio);
  2297. lynx::Clip clip;
  2298. clip.kind = lynx::ClipKind::audio;
  2299. clip.channel = (int) s.channels.size() - 1;
  2300. clip.track = realTrack + (int) i;
  2301. clip.length = 4 * bar;
  2302. clip.fadeIn = i == 1 ? bar / 2 : 0;
  2303. s.playlist.push_back (clip);
  2304. clip.start = 4 * bar;
  2305. clip.fadeIn = 0;
  2306. clip.fadeOut = i == 0 ? bar : 0;
  2307. s.playlist.push_back (clip);
  2308. }
  2309. if ((int) s.playlistTracks.size() < realTrack + (int) paths.size())
  2310. s.playlistTracks.resize ((std::size_t) realTrack + paths.size());
  2311. if (! paths.empty())
  2312. s.playlistTracks[(std::size_t) realTrack].height = 90;
  2313. });
  2314. offline.dispatchPendingMessages();
  2315. for (const auto& path2 : paths)
  2316. cache.find (path2, [&offline, path2] { return offline.getSampleLibrary().load (path2); });
  2317. cache.waitUntilIdle (60000);
  2318. playlist.setViewForSnapshot (160.0, 0, std::max (0, realTrack - 4));
  2319. saveSnapshot (ui, prefix + "-playlist-real.png");
  2320. playlist.setViewForSnapshot (700.0, 0, std::max (0, realTrack - 1));
  2321. saveSnapshot (ui, prefix + "-playlist-real-zoom.png");
  2322. playlist.setViewForSnapshot (2400.0, 0, std::max (0, realTrack - 1));
  2323. saveSnapshot (ui, prefix + "-playlist-real-close.png");
  2324. playlist.setViewForSnapshot (50.0, 0, std::max (0, realTrack - 4));
  2325. saveSnapshot (ui, prefix + "-playlist-real-far.png");
  2326. // the clip menu of the first real clip
  2327. if (const auto menu = playlist.getClipMenuForSnapshot ((int) offline.getSong().playlist.size() - (int) paths.size() * 2); menu.getNumItems() > 0)
  2328. saveMenus (juce::StringArray { "Audio clip" }, std::vector<juce::PopupMenu> { menu }, prefix + "-clip-menu-audio.png");
  2329. if (const auto menu = playlist.getClipMenuForSnapshot (0); menu.getNumItems() > 0)
  2330. saveMenus (juce::StringArray { "Pattern clip" }, std::vector<juce::PopupMenu> { menu }, prefix + "-clip-menu-pattern.png");
  2331. // the clip menu's actions, run through the menu itself; results in -clip-actions.txt
  2332. {
  2333. juce::StringArray log;
  2334. auto clipOf = [&offline] (const std::string& channelName, int nth) {
  2335. const auto& sg = offline.getSong();
  2336. for (int i = 0; i < (int) sg.playlist.size(); ++i)
  2337. {
  2338. const auto& c = sg.playlist[(std::size_t) i];
  2339. if (c.kind == lynx::ClipKind::audio && c.channel >= 0 && sg.channels[(std::size_t) c.channel].name == channelName && nth-- == 0)
  2340. return i;
  2341. }
  2342. return -1;
  2343. };
  2344. std::function<bool (const juce::PopupMenu&, const juce::String&)> run = [&run] (const juce::PopupMenu& m, const juce::String& text) {
  2345. for (juce::PopupMenu::MenuItemIterator it (m); it.next();)
  2346. {
  2347. auto& item = it.getItem();
  2348. if (item.subMenu != nullptr && run (*item.subMenu, text))
  2349. return true;
  2350. if (item.text.startsWith (text) && item.isEnabled && item.action)
  2351. {
  2352. item.action();
  2353. return true;
  2354. }
  2355. }
  2356. return false;
  2357. };
  2358. auto act = [&] (const std::string& name, int nth, const juce::String& text) {
  2359. const auto clip = clipOf (name, nth);
  2360. const auto ok = clip >= 0 && run (playlist.getClipMenuForSnapshot (clip), text);
  2361. offline.dispatchPendingMessages();
  2362. return ok;
  2363. };
  2364. auto channelOf = [&] (const std::string& name) -> const lynx::ChannelDef* {
  2365. for (const auto& c : offline.getSong().channels)
  2366. if (c.name == name)
  2367. return &c;
  2368. return nullptr;
  2369. };
  2370. auto check = [&log] (const juce::String& what, bool ok) { log.add ((ok ? "OK " : "FAIL ") + what); };
  2371. const auto names = [&] { std::vector<std::string> n; for (auto& p2 : paths) n.push_back (juce::File (p2).getFileNameWithoutExtension().toStdString()); return n; }();
  2372. if (names.size() >= 4)
  2373. {
  2374. const auto channelsBefore = offline.getSong().channels.size();
  2375. check ("Reverse", act (names[2], 0, lynx::tr ("Reverse")) && channelOf (names[2])->sampler.reverse);
  2376. offline.undo();
  2377. offline.dispatchPendingMessages();
  2378. check ("Reverse undone", ! channelOf (names[2])->sampler.reverse);
  2379. act (names[2], 0, lynx::tr ("Reverse"));
  2380. check ("Make unique", act (names[3], 1, lynx::tr ("Make unique")) && offline.getSong().channels.size() == channelsBefore + 1
  2381. && channelOf (names[3] + " #2") != nullptr);
  2382. check ("Fit to tempo, resample", act (names[1], 0, lynx::tr ("Fit to tempo, resample ({0})", { juce::String() }).upToFirstOccurrenceOf ("(", false, false))
  2383. && channelOf (names[1])->sampler.stretchBeats > 0.0f && ! channelOf (names[1])->sampler.keepPitch);
  2384. const auto gainBefore = offline.getSong().playlist[(std::size_t) clipOf (names[0], 1)].gain;
  2385. check ("Normalize", act (names[0], 1, lynx::tr ("Normalize"))
  2386. && offline.getSong().playlist[(std::size_t) clipOf (names[0], 1)].gain != gainBefore);
  2387. const auto clipsBefore = offline.getSong().playlist.size();
  2388. check ("Split here", act (names[3], 0, lynx::tr ("Split here")) && offline.getSong().playlist.size() == clipsBefore + 1);
  2389. check ("Mute", act (names[0], 0, lynx::tr ("Mute")) && offline.getSong().playlist[(std::size_t) clipOf (names[0], 0)].muted);
  2390. check ("Copy + Paste here", act (names[0], 0, lynx::tr ("Copy")) && act (names[0], 1, lynx::tr ("Paste here"))
  2391. && offline.getSong().playlist.size() == clipsBefore + 2);
  2392. check ("Delete", act (names[0], 2, lynx::tr ("Delete")) && offline.getSong().playlist.size() == clipsBefore + 1);
  2393. check ("Chop to grid", act (names[3], 0, lynx::tr ("Chop to grid")) && offline.getSong().playlist.size() > clipsBefore + 1);
  2394. }
  2395. playlist.setViewForSnapshot (160.0, 0, std::max (0, realTrack - 4));
  2396. saveSnapshot (ui, prefix + "-playlist-real-actions.png");
  2397. juce::File (prefix + "-clip-actions.txt").replaceWithText (log.joinIntoString ("\n") + "\n");
  2398. }
  2399. }
  2400. }
  2401. saveWindow (lynx::makeChannelSettingsPanel (offline, samplerChannel), "-sampler-wave.png");
  2402. ui.showDesktopForSnapshot (false);
  2403. ui.getBrowserForSnapshot().showPreviewForSnapshot (wav);
  2404. saveSnapshot (ui, prefix + "-browser-preview.png");
  2405. }
  2406. }
  2407. juce::LookAndFeel::setDefaultLookAndFeel (nullptr);
  2408. quit();
  2409. }
  2410. // --snapshot: 8 s of a synthetic stereo beat whose parts sit in different bands (kick = low, chord = mid,
  2411. // hats and the noise riser = high), to show the spectral waveform colours
  2412. static void writeWaveDemo (const juce::File& file, double bpm)
  2413. {
  2414. constexpr double rate = 44100.0;
  2415. const auto frames = (int) (8.0 * rate);
  2416. juce::AudioBuffer<float> buffer (2, frames);
  2417. buffer.clear();
  2418. auto* l = buffer.getWritePointer (0);
  2419. auto* r = buffer.getWritePointer (1);
  2420. const auto beat = 60.0 / juce::jlimit (40.0, 300.0, bpm);
  2421. std::uint32_t noise = 0x9e3779b9u;
  2422. auto white = [&noise] {
  2423. noise ^= noise << 13;
  2424. noise ^= noise >> 17;
  2425. noise ^= noise << 5;
  2426. return (float) (noise & 0xffffff) / (float) 0x800000 - 1.0f;
  2427. };
  2428. float previous = 0.0f;
  2429. for (int i = 0; i < frames; ++i)
  2430. {
  2431. const auto t = i / rate;
  2432. const auto inBeat = std::fmod (t, beat);
  2433. const auto bar = (int) (t / (beat * 4.0));
  2434. float left = 0.0f, right = 0.0f;
  2435. // kick on every beat: a falling sine
  2436. {
  2437. const auto phase = 2.0 * juce::MathConstants<double>::pi * (48.0 * inBeat + 4.0 * (1.0 - std::exp (-inBeat * 30.0)));
  2438. const auto k = (float) (std::sin (phase) * std::exp (-inBeat * 7.0)) * 0.85f;
  2439. left += k;
  2440. right += k;
  2441. }
  2442. // hats on the off-beats: high-passed noise bursts, a little to the right
  2443. {
  2444. const auto h = std::fmod (t + beat * 0.5, beat);
  2445. const auto n = white();
  2446. const auto hp = (n - previous) * 0.5f;
  2447. previous = n;
  2448. const auto hat = hp * (float) std::exp (-h * 45.0) * 0.55f;
  2449. left += hat * 0.6f;
  2450. right += hat;
  2451. }
  2452. // a chord in the second and third bars (mid band)
  2453. if (bar == 1 || bar == 2)
  2454. {
  2455. const auto env = (float) std::min (1.0, std::min (t - beat * 4.0, beat * 12.0 - t) * 8.0);
  2456. float chord = 0.0f;
  2457. for (const auto hz : { 523.25, 659.25, 783.99 })
  2458. chord += (float) (std::sin (2.0 * juce::MathConstants<double>::pi * hz * t) + 0.3 * std::sin (4.0 * juce::MathConstants<double>::pi * hz * t));
  2459. left += chord * 0.09f * std::max (0.0f, env);
  2460. right += chord * 0.09f * std::max (0.0f, env);
  2461. }
  2462. // a white-noise riser over the last two seconds (high band)
  2463. if (t > 6.0)
  2464. {
  2465. const auto rise = (float) ((t - 6.0) / 2.0);
  2466. left += white() * 0.4f * rise * rise;
  2467. right += white() * 0.4f * rise * rise;
  2468. }
  2469. l[i] = left;
  2470. r[i] = right;
  2471. }
  2472. buffer.applyGain (0.9f / juce::jmax (1.0e-6f, buffer.getMagnitude (0, frames)));
  2473. file.deleteFile();
  2474. juce::WavAudioFormat wav;
  2475. if (std::unique_ptr<juce::AudioFormatWriter> writer { wav.createWriterFor (file.createOutputStream().release(), rate, 2, 24, {}, 0) })
  2476. writer->writeFromAudioSampleBuffer (buffer, 0, frames);
  2477. }
  2478. // the menu bar's menus side by side, drawn with the LookAndFeel as they appear when opened
  2479. static void saveMenus (lynx::MainComponent& ui, const juce::String& path)
  2480. {
  2481. const auto names = ui.getMenuNamesForSnapshot();
  2482. std::vector<juce::PopupMenu> source;
  2483. for (int m = 0; m < names.size(); ++m)
  2484. source.push_back (ui.getMenuForSnapshot (m));
  2485. saveMenus (names, source, path);
  2486. }
  2487. // menus side by side, each under its name
  2488. static void saveMenus (const juce::StringArray& names, const std::vector<juce::PopupMenu>& source, const juce::String& path)
  2489. {
  2490. auto& lf = juce::LookAndFeel::getDefaultLookAndFeel();
  2491. struct Laid
  2492. {
  2493. juce::PopupMenu menu;
  2494. int width = 0, height = 0;
  2495. };
  2496. std::vector<Laid> menus;
  2497. const auto border = lf.getPopupMenuBorderSize();
  2498. const auto itemHeight = 26;
  2499. for (int m = 0; m < names.size(); ++m)
  2500. {
  2501. Laid laid { source[(std::size_t) m] };
  2502. int width = 160, height = 2 * border;
  2503. for (juce::PopupMenu::MenuItemIterator it (laid.menu); it.next();)
  2504. {
  2505. const auto& item = it.getItem();
  2506. int w = 0, h = 0;
  2507. lf.getIdealPopupMenuItemSize (item.text, item.isSeparator, item.isSectionHeader ? 22 : itemHeight, w, h);
  2508. if (item.shortcutKeyDescription.isNotEmpty() || item.text.containsChar ('\t'))
  2509. w += 90;
  2510. width = juce::jmax (width, w + 10);
  2511. height += h;
  2512. }
  2513. laid.width = width;
  2514. laid.height = height;
  2515. menus.push_back (std::move (laid));
  2516. }
  2517. int totalWidth = 16, totalHeight = 0;
  2518. for (const auto& l : menus)
  2519. {
  2520. totalWidth += l.width + 16;
  2521. totalHeight = juce::jmax (totalHeight, l.height + 32);
  2522. }
  2523. juce::Image image (juce::Image::ARGB, totalWidth, totalHeight, true);
  2524. {
  2525. juce::Graphics g (image);
  2526. g.fillAll (lynx::theme::colour::bg1);
  2527. int x = 16;
  2528. for (int m = 0; m < (int) menus.size(); ++m)
  2529. {
  2530. const auto& l = menus[(std::size_t) m];
  2531. g.setColour (lynx::theme::colour::textSecondary);
  2532. g.setFont (lynx::theme::font (lynx::theme::type::small, true));
  2533. g.drawText (names[m], x, 0, l.width, 24, juce::Justification::centredLeft);
  2534. {
  2535. juce::Graphics::ScopedSaveState state (g);
  2536. g.reduceClipRegion (x, 24, l.width, l.height);
  2537. g.setOrigin (x, 24);
  2538. lf.drawPopupMenuBackground (g, l.width, l.height);
  2539. int y = border;
  2540. bool first = true;
  2541. for (juce::PopupMenu::MenuItemIterator it (l.menu); it.next();)
  2542. {
  2543. const auto& item = it.getItem();
  2544. int w = 0, h = 0;
  2545. lf.getIdealPopupMenuItemSize (item.text, item.isSeparator, item.isSectionHeader ? 22 : itemHeight, w, h);
  2546. const juce::Rectangle<int> r (0, y, l.width, h);
  2547. auto text = item.text, shortcut = item.shortcutKeyDescription;
  2548. if (text.containsChar ('\t'))
  2549. {
  2550. shortcut = text.fromFirstOccurrenceOf ("\t", false, false);
  2551. text = text.upToFirstOccurrenceOf ("\t", false, false);
  2552. }
  2553. if (item.isSectionHeader)
  2554. lf.drawPopupMenuSectionHeader (g, r, text);
  2555. else
  2556. lf.drawPopupMenuItem (g, r, item.isSeparator, item.isEnabled, first && ! item.isSeparator && m == 0, item.isTicked,
  2557. item.subMenu != nullptr, text, shortcut, item.image.get(), nullptr);
  2558. first = false;
  2559. y += h;
  2560. }
  2561. }
  2562. x += l.width + 16;
  2563. }
  2564. }
  2565. const juce::File file (path);
  2566. file.deleteFile();
  2567. juce::PNGImageFormat png;
  2568. if (auto out = file.createOutputStream())
  2569. png.writeImageToStream (image, *out);
  2570. }
  2571. static void writePng (const juce::Image& image, const juce::String& path)
  2572. {
  2573. const juce::File file (path);
  2574. file.deleteFile();
  2575. juce::PNGImageFormat png;
  2576. if (auto out = file.createOutputStream())
  2577. png.writeImageToStream (image, *out);
  2578. }
  2579. // the splash screen: one settled frame, and a strip of frames through its animation
  2580. static void saveSplashFrames (const juce::String& prefix)
  2581. {
  2582. lynx::SplashScreen splash;
  2583. splash.setStatus (lynx::tr ("Loading the workspace..."));
  2584. splash.setTimeForSnapshot (1.6);
  2585. writePng (splash.createComponentSnapshot (splash.getLocalBounds()), prefix + "-splash.png");
  2586. const double times[] = { 0.10, 0.22, 0.29, 0.40, 0.58, 0.75, 1.00, 1.30 };
  2587. const auto w = lynx::SplashScreen::width / 2, h = lynx::SplashScreen::height / 2;
  2588. juce::Image strip (juce::Image::ARGB, 4 * (w + 8) + 8, 2 * (h + 8) + 8, true);
  2589. {
  2590. juce::Graphics g (strip);
  2591. g.fillAll (lynx::theme::colour::bg1);
  2592. for (int i = 0; i < 8; ++i)
  2593. {
  2594. splash.setTimeForSnapshot (times[i]);
  2595. const auto frame = splash.createComponentSnapshot (splash.getLocalBounds());
  2596. g.drawImage (frame, 8 + (i % 4) * (w + 8), 8 + (i / 4) * (h + 8), w, h, 0, 0, frame.getWidth(), frame.getHeight());
  2597. }
  2598. }
  2599. writePng (strip, prefix + "-splash-frames.png");
  2600. }
  2601. // every icon at 16, 20 and 24 px (at `scale`, e.g. 1.5 for a 150% display), in the toolbar's
  2602. // colours: at rest, hovered and switched on
  2603. static void saveIconSheet (const juce::String& path, float scale)
  2604. {
  2605. const int sizes[] = { 16, 20, 24 };
  2606. const int cell = 34, columns = 3 * 3, labelWidth = 110;
  2607. const auto w = labelWidth + columns * cell + 16, h = lynx::iconCount * cell + 16;
  2608. juce::Image image (juce::Image::ARGB, juce::roundToInt ((float) w * scale), juce::roundToInt ((float) h * scale), true);
  2609. {
  2610. juce::Graphics g (image); // (drawing is flushed when it goes out of scope)
  2611. g.addTransform (juce::AffineTransform::scale (scale));
  2612. g.fillAll (lynx::theme::colour::bg3);
  2613. g.setFont (lynx::theme::font (lynx::theme::type::small));
  2614. for (int i = 1; i < lynx::iconCount; ++i)
  2615. {
  2616. const auto y = 8 + (i - 1) * cell;
  2617. g.setColour (lynx::theme::colour::textDisabled);
  2618. g.drawText (juce::String (i), 8, y, labelWidth - 8, cell, juce::Justification::centredLeft);
  2619. for (int v = 0; v < 3; ++v)
  2620. for (int s = 0; s < 3; ++s)
  2621. {
  2622. const juce::Rectangle<float> box ((float) (labelWidth + (v * 3 + s) * cell), (float) y, (float) cell, (float) cell);
  2623. const auto bg = v == 2 ? lynx::theme::colour::accent : v == 1 ? lynx::theme::colour::bg5 : lynx::theme::colour::bg3;
  2624. g.setColour (bg);
  2625. g.fillRoundedRectangle (box.reduced (2.0f), 4.0f);
  2626. const auto fg = v == 2 ? lynx::theme::colour::onAccent : v == 1 ? lynx::theme::colour::textPrimary
  2627. : lynx::theme::colour::textSecondary.brighter (0.25f);
  2628. lynx::icons::draw (g, (lynx::Icon) i, box.withSizeKeepingCentre ((float) sizes[s], (float) sizes[s]), fg);
  2629. }
  2630. }
  2631. }
  2632. writePng (image, path);
  2633. }
  2634. // a part of a component (e.g. the main toolbar)
  2635. static void saveArea (juce::Component& c, juce::Rectangle<int> area, const juce::String& path)
  2636. {
  2637. const juce::File file (path);
  2638. file.deleteFile();
  2639. juce::PNGImageFormat png;
  2640. if (auto out = file.createOutputStream())
  2641. png.writeImageToStream (c.createComponentSnapshot (area), *out);
  2642. }
  2643. static void savePng (const juce::Image& image, const juce::String& path)
  2644. {
  2645. const juce::File file (path);
  2646. file.deleteFile();
  2647. juce::PNGImageFormat png;
  2648. if (auto out = file.createOutputStream())
  2649. png.writeImageToStream (image, *out);
  2650. }
  2651. // -toolbar-tips.png: the top of the window with the bubbles of a few controls as they appear under the
  2652. // mouse; -tips-sheet.png: every quick tip of the window, to check names, shortcuts and translations
  2653. static void saveQuickTips (lynx::MainComponent& ui, const juce::String& prefix)
  2654. {
  2655. const auto tips = ui.getQuickTipsForSnapshot();
  2656. const auto top = juce::Rectangle<int> (0, 0, ui.getWidth(), juce::jmin (ui.getHeight(), ui.getToolbarBoundsForSnapshot().getHeight() + 72));
  2657. auto image = ui.createComponentSnapshot (top);
  2658. {
  2659. juce::Graphics g (image);
  2660. const juce::String shown[] = { lynx::tr ("Pattern mode"), lynx::tr ("Play"), lynx::tr ("Metronome"), lynx::tr ("Mixer"), lynx::tr ("Save project"),
  2661. lynx::tr ("Window options"), lynx::tr ("Close") };
  2662. std::vector<juce::Rectangle<int>> used;
  2663. for (const auto& [area, tip] : tips)
  2664. {
  2665. const auto name = tip.upToFirstOccurrenceOf ("\t", false, false);
  2666. if (std::find (std::begin (shown), std::end (shown), name) == std::end (shown))
  2667. continue;
  2668. const auto bubble = lynx::ui::quickTipBounds (tip, area, top);
  2669. if (std::any_of (used.begin(), used.end(), [&] (const auto& r) { return r.intersects (bubble); }))
  2670. continue;
  2671. used.push_back (bubble);
  2672. g.setColour (juce::Colours::white.withAlpha (0.075f)); // the hovered control
  2673. g.fillRoundedRectangle (area.toFloat().reduced (0.5f), lynx::theme::radius::md);
  2674. lynx::ui::paintQuickTip (g, bubble.toFloat(), tip);
  2675. }
  2676. }
  2677. savePng (image, prefix + "-toolbar-tips.png");
  2678. // the sheet: bubbles in rows
  2679. const int width = 900;
  2680. int x = 12, y = 12;
  2681. std::vector<std::pair<juce::Rectangle<int>, juce::String>> placed;
  2682. for (const auto& [area, tip] : tips)
  2683. {
  2684. auto r = lynx::ui::quickTipSize (tip);
  2685. if (x + r.getWidth() > width - 12)
  2686. {
  2687. x = 12;
  2688. y += r.getHeight() + 10;
  2689. }
  2690. placed.emplace_back (r.withPosition (x, y), tip);
  2691. x += r.getWidth() + 10;
  2692. }
  2693. juce::Image sheet (juce::Image::ARGB, width, y + 20 + 12, true);
  2694. {
  2695. juce::Graphics g (sheet);
  2696. g.fillAll (lynx::theme::colour::bg3);
  2697. for (const auto& [r, tip] : placed)
  2698. lynx::ui::paintQuickTip (g, r.toFloat(), tip);
  2699. }
  2700. savePng (sheet, prefix + "-tips-sheet.png");
  2701. }
  2702. static void saveSnapshot (juce::Component& c, const juce::String& path)
  2703. {
  2704. const juce::File file (path);
  2705. file.deleteFile();
  2706. juce::PNGImageFormat png;
  2707. if (auto out = file.createOutputStream())
  2708. png.writeImageToStream (c.createComponentSnapshot (c.getLocalBounds()), *out);
  2709. }
  2710. class MainWindow final : public juce::DocumentWindow
  2711. {
  2712. public:
  2713. MainWindow (const juce::String& name, lynx::AudioEngine& engine)
  2714. : DocumentWindow (name, lynx::theme::window, DocumentWindow::allButtons)
  2715. {
  2716. setUsingNativeTitleBar (true);
  2717. setIcon (lynx::logoImage());
  2718. content = new lynx::MainComponent (engine);
  2719. setContentOwned (content, true);
  2720. setResizable (true, true);
  2721. setResizeLimits (800, 400, 10000, 10000);
  2722. // ~88% of the main display's usable area (at least the UI's design size)
  2723. if (const auto* display = juce::Desktop::getInstance().getDisplays().getPrimaryDisplay())
  2724. {
  2725. const auto area = display->userArea;
  2726. setSize (juce::jmax (getWidth(), (int) (area.getWidth() * 0.88)), juce::jmax (getHeight(), (int) (area.getHeight() * 0.88)));
  2727. }
  2728. centreWithSize (getWidth(), getHeight());
  2729. }
  2730. // Shows the window (built hidden while the splash screen is up).
  2731. void reveal()
  2732. {
  2733. setVisible (true);
  2734. lynx::applyWindowChrome (*this);
  2735. toFront (true);
  2736. content->grabKeyboardFocus();
  2737. }
  2738. void openFile (const juce::File& file) { content->openFile (file); }
  2739. void showSetupWizard() { content->showSetupWizard(); }
  2740. void confirmDiscard (std::function<void()> then) { content->confirmDiscard (std::move (then)); }
  2741. void closeButtonPressed() override { JUCEApplication::getInstance()->systemRequestedQuit(); }
  2742. private:
  2743. lynx::MainComponent* content = nullptr; // owned by the window
  2744. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  2745. };
  2746. lynx::theme::LookAndFeel lookAndFeel;
  2747. std::unique_ptr<lynx::AudioEngine> engine;
  2748. std::unique_ptr<juce::XmlElement> savedDeviceState; // --rtstress: the user's device before this run's --type/--buffer
  2749. // Hidden test mode --asiodll "<driver.dll>[|{CLSID}]" (REA round 97): an ASIO driver loaded straight from its file,
  2750. // without registering it, listed as the driver type "ASIO driver file". True when one was added.
  2751. bool addDriverFileDeviceType()
  2752. {
  2753. const auto args = juce::JUCEApplication::getCommandLineParameterArray();
  2754. const auto i = args.indexOf ("--asiodll");
  2755. if (i < 0 || i + 1 >= args.size() || engine == nullptr)
  2756. return false;
  2757. auto& devices = engine->getDeviceManager();
  2758. devices.getAvailableDeviceTypes(); // creates the standard types first
  2759. for (auto* t : devices.getAvailableDeviceTypes())
  2760. if (t->getTypeName() == lynx::dllAsioTypeName)
  2761. return true;
  2762. auto type = lynx::makeDllAsioDeviceType (args[i + 1].unquoted());
  2763. if (type == nullptr)
  2764. return false;
  2765. devices.addAudioDeviceType (std::move (type));
  2766. return true;
  2767. }
  2768. void restoreSavedDeviceState()
  2769. {
  2770. if (engine != nullptr)
  2771. engine->restoreAudioDeviceState (savedDeviceState.get());
  2772. }
  2773. std::unique_ptr<MainWindow> mainWindow;
  2774. std::unique_ptr<lynx::SplashScreen> splash;
  2775. lynx::StartupOptions startupOptions;
  2776. juce::File fileToOpen;
  2777. };
  2778. START_JUCE_APPLICATION (LynxApplication)