SettingsPages.cpp 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  1. #include "ui/SettingsPages.h"
  2. #include "platform/Paths.h"
  3. #include "platform/FileTypes.h"
  4. #include "platform/Package.h"
  5. #include "core/LayoutStyle.h"
  6. #include "core/LynxExtras.h"
  7. #include "core/PlaylistOps.h"
  8. #include "core/ToolbarLayout.h"
  9. #include "engine/AudioEngine.h"
  10. #include "engine/PluginHost.h"
  11. #include "platform/LinuxRealtime.h"
  12. #include "ui/AutomationUi.h"
  13. #include "ui/DetailView.h"
  14. #include "ui/Dialogs.h"
  15. #include "ui/I18n.h"
  16. #include "ui/MixerComponent.h"
  17. #include "ui/NewProjectDialog.h"
  18. #include "ui/PianoRollComponent.h"
  19. #include "ui/PluginSkin.h"
  20. #include "ui/Updater.h"
  21. #include <algorithm>
  22. namespace lynx
  23. {
  24. using namespace settingsui;
  25. juce::File autosaveFolder()
  26. {
  27. return lynx::platform::settingsFile ("autosave");
  28. }
  29. namespace
  30. {
  31. constexpr int labelWidth = 190;
  32. constexpr int rowHeight = 26;
  33. constexpr int rowGap = 5; // round 163: tighter (was 8)
  34. constexpr int sectionHeight = 24;
  35. void styleCombo (juce::ComboBox& box)
  36. {
  37. box.setColour (juce::ComboBox::outlineColourId, theme::colour::borderStrong);
  38. }
  39. void styleToggle (juce::ToggleButton& t, const juce::String& text)
  40. {
  41. t.setButtonText (text);
  42. }
  43. // Lays out rows top to bottom inside a page of a given width.
  44. struct Rows
  45. {
  46. juce::Rectangle<int> area;
  47. int y = 0;
  48. explicit Rows (int width) : area (20, 14, width - 40, 100000), y (14) {}
  49. void section (juce::Component& title, bool first = false)
  50. {
  51. if (! first)
  52. y += 10;
  53. title.setBounds (area.getX(), y, area.getWidth(), sectionHeight);
  54. y += sectionHeight + rowGap;
  55. }
  56. // label + control (control width 0 = to the right edge)
  57. // round 165o: a caption wider than the label column (a long translation) gets its own line above the control
  58. juce::Rectangle<int> row (juce::Label& label, int controlWidth = 260, int height = rowHeight)
  59. {
  60. if (theme::labelColumnWidth ({ &label }, 0, 2000) > labelWidth + labelWidth / 10) // a slight squeeze is fine
  61. {
  62. label.setBounds (area.getX(), y, area.getWidth(), 18);
  63. y += 18;
  64. }
  65. else
  66. label.setBounds (area.getX(), y, labelWidth, height);
  67. auto r = juce::Rectangle<int> (area.getX() + labelWidth, y, controlWidth > 0 ? controlWidth : area.getWidth() - labelWidth, height);
  68. y += height + rowGap;
  69. return r;
  70. }
  71. juce::Rectangle<int> full (int height = rowHeight)
  72. {
  73. auto r = juce::Rectangle<int> (area.getX(), y, area.getWidth(), height);
  74. y += height + rowGap;
  75. return r;
  76. }
  77. juce::Rectangle<int> indented (int height = rowHeight)
  78. {
  79. auto r = juce::Rectangle<int> (area.getX() + labelWidth, y, area.getWidth() - labelWidth, height);
  80. y += height + rowGap;
  81. return r;
  82. }
  83. int bottom() const { return y + 14; }
  84. };
  85. // ================================================================================================================
  86. // General
  87. // ================================================================================================================
  88. class GeneralPage final : public ScrollingPage
  89. {
  90. public:
  91. GeneralPage (AudioEngine& e, SettingsHooks h, bool keep) : engine (e), hooks (std::move (h)), persistent (keep)
  92. {
  93. if (hooks.getGeneral)
  94. options = hooks.getGeneral();
  95. else
  96. options.language = i18n::current(); // --snapshot: the language of the run
  97. for (auto* c : std::initializer_list<juce::Component*> { &workflowTitle, &layoutStyleLabel, &layoutStyleBox, &layoutStyleNote, &alsSessionLabel, &alsSessionBox, &languageTitle, &displayTitle, &startupTitle, &editingTitle, &backupTitle,
  98. &pluginsTitle, &languageLabel, &languageBox, &languageNote, &scaleLabel, &scaleBox, &menuLabel, &menuBox,
  99. &wavesLabel, &wavesBox, &stereoWaves, &noteNamesLabel, &noteNamesBox, &blackNotesLabel, &blackNotesBox, &everyKeyNames, &rackColumn, &rackStepColour, &pluginStyleLabel, &pluginStyleBox, &artMotion, &reducedEffects, &uiAnimations, &animationLabel, &animationBox, &animationNote, &gpuRendering, &templateLabel, &templateBox, &templateNote, &startupProjectLabel, &startupProjectBox, &splash, &startupSound, &scanAtStart, &menuEntry,
  100. &typingPiano, &keepEditors, &rememberSeek, &clipsLoop, &autoClipsAtPlayback, &firstChannel, &monoPaint, &autoSelectLinked, &noTypingPriority, &hoverValues, &editInLabel, &editInBox, &undoLabel,
  101. &undoBox, &alternateUndo, &hintsTitle, &manageMessages, &messagesNote, &autosaveLabel, &autosaveBox, &keepLabel, &keepBox, &openBackups, &backupQuiet, &longestWaitLabel, &longestWaitBox, &unusedTakes, &detachNew,
  102. &sandbox, &sandboxNote, &substitutes, &substitutesNote, &limitEditors, &managePlugins, &manageShortcuts, &shortcutsNote,
  103. &reportsTitle, &crashLabel, &crashBox, &crashNote, &updatesTitle, &checkUpdates, &checkNow, &updatesNote })
  104. add (*c);
  105. setupFontRow();
  106. styleLabel (layoutStyleLabel, tr ("Layout style"));
  107. layoutStyleBox.setComponentID ("layoutStyle"); // (--simpleshot finds it)
  108. layoutStyleBox.addItem (tr ("Pattern workflow (default)"), layoutstyle::comboId (layoutstyle::Style::pattern));
  109. layoutStyleBox.addItem (tr ("Clip-launch workflow"), layoutstyle::comboId (layoutstyle::Style::clipLaunch));
  110. layoutStyleBox.addItem (tr ("Simple workflow"), layoutstyle::comboId (layoutstyle::Style::simple));
  111. layoutStyleBox.setSelectedId (layoutstyle::comboId ((layoutstyle::Style) juce::jlimit (0, layoutstyle::count - 1, options.layoutStyle)), juce::dontSendNotification);
  112. layoutStyleBox.onChange = [this] {
  113. options.layoutStyle = (int) layoutstyle::fromComboId (layoutStyleBox.getSelectedId());
  114. if (hooks.setGeneral)
  115. hooks.setGeneral (options);
  116. };
  117. styleNote (layoutStyleNote, tr ("Pattern workflow: channel rack, patterns and a Playlist.") + "\n"
  118. + tr ("Clip-launch workflow: a clip grid with scenes beside the Playlist; patterns and the channel rack stay one click away.") + "\n"
  119. + tr ("Simple workflow: one window with the tracks and the timeline; the other windows stay one click away."));
  120. styleLabel (alsSessionLabel, tr ("Session clips of Live sets"));
  121. alsSessionBox.addItem (tr ("Clip grid (default)"), 1);
  122. alsSessionBox.addItem (tr ("Playlist, after the arrangement"), 2);
  123. alsSessionBox.setSelectedId (options.alsSessionOnPlaylist ? 2 : 1, juce::dontSendNotification);
  124. alsSessionBox.onChange = [this] {
  125. options.alsSessionOnPlaylist = alsSessionBox.getSelectedId() == 2;
  126. if (hooks.setGeneral)
  127. hooks.setGeneral (options);
  128. };
  129. styleLabel (languageLabel, tr ("Language"));
  130. styleNote (languageNote, tr ("A new language is applied when LYNX SHARE restarts."));
  131. int id = 1;
  132. for (const auto& l : i18n::languages())
  133. {
  134. languageBox.addItem (juce::String::fromUTF8 (l.nativeName), id);
  135. if (options.language == l.id)
  136. languageBox.setSelectedId (id, juce::dontSendNotification);
  137. ++id;
  138. }
  139. languageBox.onChange = [this] {
  140. const auto index = languageBox.getSelectedId() - 1;
  141. if (juce::isPositiveAndBelow (index, (int) i18n::languages().size()))
  142. change ([&] { options.language = i18n::languages()[(std::size_t) index].id; });
  143. updateTranslationLink();
  144. resized();
  145. };
  146. // the translations added in 0.1.20: an invitation to improve them (GitHub issue form)
  147. translationLink.setFont (juce::FontOptions (13.0f), false, juce::Justification::centredLeft);
  148. translationLink.setColour (juce::HyperlinkButton::textColourId, theme::colour::accent);
  149. add (translationLink);
  150. updateTranslationLink();
  151. styleLabel (scaleLabel, tr ("Interface size"));
  152. for (auto percent : toolbarlayout::uiScales)
  153. scaleBox.addItem (juce::String (percent) + "%", percent);
  154. scaleBox.setSelectedId (options.uiScale, juce::dontSendNotification);
  155. scaleBox.onChange = [this] { change ([&] { options.uiScale = scaleBox.getSelectedId(); }); };
  156. styleLabel (menuLabel, tr ("Menu density"));
  157. menuBox.addItem (tr ("Compact"), 1);
  158. menuBox.addItem (tr ("Comfortable"), 2);
  159. menuBox.setSelectedId (options.compactMenus ? 1 : 2, juce::dontSendNotification);
  160. menuBox.onChange = [this] { change ([&] { options.compactMenus = menuBox.getSelectedId() == 1; }); };
  161. styleLabel (wavesLabel, tr ("Waveforms"));
  162. wavesBox.addItem (tr ("Clean (the clip colour)"), 1);
  163. wavesBox.addItem (tr ("Spectral colours (warm = bass, cool = treble)"), 2);
  164. wavesBox.setSelectedId (options.waveSpectral ? 2 : 1, juce::dontSendNotification);
  165. wavesBox.onChange = [this] { change ([&] { options.waveSpectral = wavesBox.getSelectedId() == 2; }); };
  166. toggle (stereoWaves, tr ("Stereo (left and right channels apart)"), options.waveStereo, [this] (bool on) { options.waveStereo = on; });
  167. styleLabel (noteNamesLabel, tr ("Note names"));
  168. noteNamesBox.addItem (tr ("English (C, D, E)"), 1);
  169. noteNamesBox.addItem (tr ("Germanic (H for B)"), 2);
  170. noteNamesBox.addItem (tr ("Solfège (do, re, mi)"), 3);
  171. noteNamesBox.setSelectedId (juce::jlimit (0, 2, options.noteNames) + 1, juce::dontSendNotification);
  172. noteNamesBox.onChange = [this] { change ([&] { options.noteNames = noteNamesBox.getSelectedId() - 1; }); };
  173. styleLabel (blackNotesLabel, tr ("Black notes"));
  174. blackNotesBox.addItem (tr ("Sharps (#)"), 1);
  175. blackNotesBox.addItem (tr ("Flats (b)"), 2);
  176. blackNotesBox.setSelectedId (options.noteFlats ? 2 : 1, juce::dontSendNotification);
  177. blackNotesBox.onChange = [this] { change ([&] { options.noteFlats = blackNotesBox.getSelectedId() == 2; }); };
  178. toggle (everyKeyNames, tr ("Note names on every Piano roll key"), options.noteNamesEveryKey, [this] (bool on) { options.noteNamesEveryKey = on; });
  179. toggle (rackColumn, tr ("Playhead column in the Channel Rack"), options.rackPlayheadColumn, [this] (bool on) { options.rackPlayheadColumn = on; });
  180. toggle (rackStepColour, tr ("Steps use channel colour"), options.rackStepsChannelColour, [this] (bool on) { options.rackStepsChannelColour = on; });
  181. styleLabel (pluginStyleLabel, tr ("Plugin style"));
  182. pluginStyleBox.addItem (tr ("Automatic (each plugin its own style)"), 1);
  183. for (int i = 0; i < skin::styleCount; ++i)
  184. pluginStyleBox.addItem (tr ("{0} for every plugin", { tr (skin::styleName ((skin::Style) i)) }), i + 2);
  185. pluginStyleBox.setSelectedId (juce::jlimit (-1, skin::styleCount - 1, options.pluginStyle) + 2, juce::dontSendNotification);
  186. pluginStyleBox.onChange = [this] { change ([&] { options.pluginStyle = pluginStyleBox.getSelectedId() - 2; }); };
  187. toggle (artMotion, tr ("Animate the plugin art (falling petals, glows; Themed style)"), options.artMotion,
  188. [this] (bool on) { options.artMotion = on; });
  189. toggle (reducedEffects, tr ("Reduced effects in plugin editors (no glows or animations, for slower graphics cards)"), options.reducedEffects,
  190. [this] (bool on) { options.reducedEffects = on; });
  191. // round 179a: FL's General › Animations, as one switch (REA_rodada179a.md part D)
  192. toggle (uiAnimations, tr ("Animations: panels fade in and out, buttons light up gently, the wheel glides"), options.uiAnimations,
  193. [this] (bool on) { options.uiAnimations = on; });
  194. // round 174e2: how often the playhead, meters and scopes move (the display's refresh by default, as FL)
  195. styleLabel (animationLabel, tr ("Animation rate"));
  196. animationBox.addItem (tr ("Display (default)"), 1);
  197. animationBox.addItem (tr ("60 Hz"), 2);
  198. animationBox.addItem (tr ("30 Hz"), 3);
  199. animationBox.setSelectedId (options.animationRate == 30 ? 3 : options.animationRate == 60 ? 2 : 1, juce::dontSendNotification);
  200. animationBox.onChange = [this] {
  201. change ([&] { options.animationRate = animationBox.getSelectedId() == 3 ? 30 : animationBox.getSelectedId() == 2 ? 60 : 0; });
  202. };
  203. styleNote (animationNote, tr ("How often the playhead, meters and scopes move. Display follows your screen's refresh rate "
  204. "(smoothest); 60 Hz or 30 Hz use less CPU on slower computers."));
  205. toggle (gpuRendering, tr ("Draw with the GPU (Direct2D). Turn off if LYNX SHARE crashes in the graphics driver or the screen flickers"),
  206. options.gpuRendering, [this] (bool on) { options.gpuRendering = on; });
  207. #if ! JUCE_WINDOWS
  208. gpuRendering.setVisible (false);
  209. #endif
  210. // FL's Options › General › Miscellaneous › "Default template" (REA_rodada186a; issue #123)
  211. styleLabel (templateLabel, tr ("Default template"));
  212. templateChoices = availableTemplates();
  213. for (int i = 0; i < (int) templateChoices.size(); ++i)
  214. {
  215. if (i == 1 || (templateChoices[(std::size_t) i].kind == TemplateChoice::Kind::user && templateChoices[(std::size_t) i - 1].kind != TemplateChoice::Kind::user))
  216. templateBox.addSeparator();
  217. templateBox.addItem (i == 0 ? tr ("Default (LYNX SHARE)") : templateChoiceName (templateChoices[(std::size_t) i]), i + 1);
  218. }
  219. {
  220. const auto current = TemplateChoice::parse (options.defaultTemplate.toStdString());
  221. auto at = std::find (templateChoices.begin(), templateChoices.end(), current);
  222. if (at == templateChoices.end()) // a user template whose file is gone: shown, so it can be changed
  223. {
  224. templateChoices.push_back (current);
  225. templateBox.addItem (tr ("{0} (not found)", { templateChoiceName (current) }), (int) templateChoices.size());
  226. at = templateChoices.end() - 1;
  227. }
  228. templateBox.setSelectedId ((int) (at - templateChoices.begin()) + 1, juce::dontSendNotification);
  229. }
  230. templateBox.setTooltip (tr ("Select default project template"));
  231. templateBox.onChange = [this] {
  232. const auto index = templateBox.getSelectedId() - 1;
  233. if (juce::isPositiveAndBelow (index, (int) templateChoices.size()))
  234. change ([&] { options.defaultTemplate = juce::String::fromUTF8 (templateChoices[(std::size_t) index].toText().c_str()); });
  235. };
  236. // FL's "Startup project", under it (FL's order)
  237. styleLabel (startupProjectLabel, tr ("Startup project"));
  238. startupProjectBox.addItem (tr ("Empty project"), 1);
  239. startupProjectBox.addItem (tr ("Default template"), 2);
  240. startupProjectBox.addItem (tr ("Last used project"), 3);
  241. startupProjectBox.setSelectedId (juce::jlimit (0, 2, options.startupProject) + 1, juce::dontSendNotification);
  242. startupProjectBox.onChange = [this] { change ([&] { options.startupProject = startupProjectBox.getSelectedId() - 1; }); };
  243. styleNote (templateNote, tr ("The default template opens with File › New, and at start-up when Startup project is \"Default template\", "
  244. "as a new untitled project, so the template itself is never overwritten. File › Save as template... adds your own."));
  245. toggle (splash, tr ("Show the splash screen at startup"), options.splash, [this] (bool on) { options.splash = on; });
  246. toggle (startupSound, tr ("Play the startup sound"), options.startupSound, [this] (bool on) { options.startupSound = on; });
  247. toggle (scanAtStart, tr ("Look for new plugins in the background at every start"), options.scanAtStart,
  248. [this] (bool on) { options.scanAtStart = on; });
  249. // the AppImage on Linux (round 161): its menu entry and the .lynx file type, in the user's ~/.local/share
  250. toggle (menuEntry, tr ("Show LYNX SHARE in the applications menu and open .lynx files with it"), options.menuEntry,
  251. [this] (bool on) { options.menuEntry = on; });
  252. menuEntry.setVisible (runningAsAppImage());
  253. toggle (typingPiano, tr ("Typing keyboard to piano"), options.typingPiano, [this] (bool on) { options.typingPiano = on; });
  254. toggle (keepEditors, tr ("Keep channel editors open (a channel button click doesn't close the previous editor)"), options.keepEditorsOpen,
  255. [this] (bool on) { options.keepEditorsOpen = on; });
  256. toggle (firstChannel, tr ("Select first channel with notes when the pattern changes"), options.selectFirstChannelWithNotes,
  257. [this] (bool on) { options.selectFirstChannelWithNotes = on; });
  258. // FL's General › Miscellaneous (round 189o): the Paint tool is monophonic without Shift
  259. toggle (monoPaint, tr ("Monophonic painting in piano roll"), options.monophonicPainting,
  260. [this] (bool on) { options.monophonicPainting = on; });
  261. monoPaint.setTooltip (tr ("On: the Paint tool replaces the notes under each new note, and Shift paints over them. Off: the other way round"));
  262. // FL's next Miscellaneous box, DisablePlugFocusDefaultBox (off; round 187a, issue #96)
  263. toggle (noTypingPriority, tr ("Disable typing keyboard priority by default"), options.disableTypingPriority,
  264. [this] (bool on) { options.disableTypingPriority = on; });
  265. noTypingPriority.setTooltip (tr ("Disable typing keyboard priority for all newly added plugins by default"));
  266. // FL's Miscellaneous "Auto select linked modules" (AutoSelectBox, on; round 187a)
  267. toggle (autoSelectLinked, tr ("Auto select linked modules"), options.autoSelectLinked, [this] (bool on) { options.autoSelectLinked = on; });
  268. autoSelectLinked.setTooltip (tr ("Focusing plugin windows selects mixer tracks"));
  269. toggle (rememberSeek, tr ("Remember seek time: Stop goes back to the position clicked on the Playlist ruler"), options.rememberSeek,
  270. [this] (bool on) { options.rememberSeek = on; });
  271. toggle (hoverValues, tr ("Show a control's value next to the mouse when hovering over it (LYNX)"), options.hoverValues,
  272. [this] (bool on) { options.hoverValues = on; });
  273. // LYNX extra (issue #25): FL plays a stretched pattern clip once; off = FL's behaviour
  274. toggle (clipsLoop, tr ("Stretched pattern clips loop their pattern (LYNX)"), options.stretchedClipsLoop,
  275. [this] (bool on) { options.stretchedClipsLoop = on; });
  276. clipsLoop.setTooltip (tr ("On: a pattern clip stretched past its pattern repeats the pattern. Off: it plays the pattern once, as in FL Studio"));
  277. // FL's Options › General › Miscellaneous (round 177b): where "Create automation clip" puts the clip
  278. // FL's General › Miscellaneous › "Detach all new plugins" (issue #116): plugin windows dock in the desktop by default
  279. toggle (detachNew, tr ("Detach all new plugins"), options.detachNewPlugins, [this] (bool on) { options.detachNewPlugins = on; });
  280. detachNew.setTooltip (tr ("On: the window of a plugin you add opens detached, on top of the panels. Off: it opens docked in the desktop, "
  281. "behind a panel you click. Each plugin's window menu › Detached changes it for that plugin"));
  282. toggle (autoClipsAtPlayback, tr ("Create automation clips at the playback position"), options.autoClipsAtPlayback,
  283. [this] (bool on) { options.autoClipsAtPlayback = on; });
  284. autoClipsAtPlayback.setTooltip (tr ("On: a new automation clip starts at the song position (without a time selection). Off: at the start of the song"));
  285. styleLabel (editInLabel, tr ("Double-click on a pattern clip opens"));
  286. const char* choices[] = { TR_NOOP ("Piano Roll when it has piano-roll notes, else Channel Rack"), TR_NOOP ("Channel Rack"), TR_NOOP ("Piano Roll") };
  287. for (int i = 0; i < 3; ++i)
  288. editInBox.addItem (tr (choices[i]), i + 1);
  289. editInBox.setSelectedId (options.editPatternsIn + 1, juce::dontSendNotification);
  290. editInBox.onChange = [this] { change ([&] { options.editPatternsIn = editInBox.getSelectedId() - 1; }); };
  291. styleLabel (undoLabel, tr ("Maximum undo levels"));
  292. for (auto n : { 25, 50, 100, 200, 500, 1000 })
  293. undoBox.addItem (juce::String (n), n);
  294. selectNearest (undoBox, options.undoLevels);
  295. undoBox.onChange = [this] { change ([&] { options.undoLevels = undoBox.getSelectedId(); }); };
  296. toggle (alternateUndo, tr ("Alternate undo mode (classic undo, instead of undo/redo on the same shortcut)"), options.alternateUndo,
  297. [this] (bool on) { options.alternateUndo = on; });
  298. styleLabel (autosaveLabel, tr ("Save a backup copy"));
  299. for (auto minutes : prefs::autosaveIntervals())
  300. autosaveBox.addItem (minutes == 0 ? tr ("Never")
  301. : minutes == 1 ? tr ("Every minute")
  302. : tr ("Every {0} minutes", { juce::String (minutes) }),
  303. minutes + 1);
  304. autosaveBox.setSelectedId (prefs::clampAutosaveMinutes (options.autosaveMinutes) + 1, juce::dontSendNotification);
  305. autosaveBox.onChange = [this] {
  306. change ([&] { options.autosaveMinutes = autosaveBox.getSelectedId() - 1; });
  307. keepBox.setEnabled (options.autosaveMinutes > 0);
  308. };
  309. styleLabel (keepLabel, tr ("Backups kept per project"));
  310. for (auto n : { 1, 3, 5, 10, 20, 50 })
  311. keepBox.addItem (juce::String (n), n);
  312. selectNearest (keepBox, options.autosaveKeep);
  313. keepBox.setEnabled (options.autosaveMinutes > 0);
  314. keepBox.onChange = [this] { change ([&] { options.autosaveKeep = keepBox.getSelectedId(); }); };
  315. openBackups.onClick = [] {
  316. autosaveFolder().createDirectory();
  317. autosaveFolder().startAsProcess();
  318. };
  319. toggle (backupQuiet, tr ("Wait with backups while the song plays or a MIDI keyboard is being played"), options.backupWaitsForQuiet,
  320. [this] (bool on) {
  321. options.backupWaitsForQuiet = on;
  322. longestWaitBox.setEnabled (on);
  323. });
  324. styleLabel (longestWaitLabel, tr ("Longest wait between backups") /* (fits the label column, as the other rows) */);
  325. for (const auto minutes : prefs::backupLongestWaitChoices)
  326. longestWaitBox.addItem (tr ("{0} minutes", { juce::String (minutes) }), minutes);
  327. selectNearest (longestWaitBox, options.backupLongestWaitMinutes);
  328. longestWaitBox.setEnabled (options.backupWaitsForQuiet);
  329. longestWaitBox.onChange = [this] { change ([&] { options.backupLongestWaitMinutes = longestWaitBox.getSelectedId(); }); };
  330. toggle (unusedTakes, tr ("When a project closes, offer to delete the recordings it no longer uses"), options.askUnusedRecordings,
  331. [this] (bool on) { options.askUnusedRecordings = on; });
  332. toggle (sandbox, tr ("Run plugins in a separate process (protects LYNX SHARE from crashes)"), options.pluginSandbox,
  333. [this] (bool on) { options.pluginSandbox = on; });
  334. styleNote (sandboxNote, tr ("Applies to plugins opened from now on; reopen the project to move the others."));
  335. toggle (substitutes, tr ("Substitute missing plugins with LYNX SHARE equivalents"), options.pluginSubstitutes,
  336. [this] (bool on) { options.pluginSubstitutes = on; });
  337. styleNote (substitutesNote, tr ("A project keeps the original plugin and uses it again once it is installed."));
  338. // FL's General › Miscellaneous (round 189o): at most 25 plugin editors open, the oldest closes; FL warns before
  339. // turning it off (FUN_013559c0) and keeps it on with No
  340. toggle (limitEditors, tr ("Limit the number of open plugin editors"), options.limitEditors, [this] (bool on) {
  341. options.limitEditors = on;
  342. if (on)
  343. return;
  344. juce::AlertWindow::showOkCancelBox (
  345. juce::MessageBoxIconType::WarningIcon, tr ("Warning"),
  346. tr ("It is recommended to keep this setting turned on for performance reasons. Are you sure you want to turn it off?"),
  347. tr ("Yes"), tr ("No"), this, juce::ModalCallbackFunction::create ([safe = juce::Component::SafePointer (this)] (int result) {
  348. if (safe != nullptr && result == 0)
  349. safe->limitEditors.setToggleState (true, juce::sendNotification);
  350. }));
  351. });
  352. limitEditors.setTooltip (tr ("Limit the number of open plugin editor windows to 25"));
  353. // FL's "Manage messages" (round 186c): which questions are asked; a ticked "Remember my choice" unticks its message
  354. manageMessages.onClick = [this] {
  355. messages::manageMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&manageMessages));
  356. };
  357. styleNote (messagesNote, tr ("Ticked messages are shown; untick one to skip its question."));
  358. managePlugins.onClick = [this] {
  359. if (hooks.managePlugins)
  360. hooks.managePlugins();
  361. };
  362. manageShortcuts.onClick = [this] {
  363. if (hooks.manageShortcuts)
  364. hooks.manageShortcuts();
  365. };
  366. styleNote (shortcutsNote, tr ("See, search and change every keyboard shortcut."));
  367. styleLabel (crashLabel, tr ("Crash reports"));
  368. crashBox.addItem (tr ("Ask after a crash or freeze"), 1);
  369. crashBox.addItem (tr ("Always send"), 2);
  370. crashBox.addItem (tr ("Never send"), 3);
  371. crashBox.setSelectedId (juce::jlimit (0, 2, options.crashReports) + 1, juce::dontSendNotification);
  372. crashBox.onChange = [this] { change ([&] { options.crashReports = crashBox.getSelectedId() - 1; }); };
  373. styleNote (crashNote, tr ("A report holds LYNX SHARE's version, your system and audio device, the crash or freeze file and the last steps, without "
  374. "your name, file names or projects. It goes to lynx-share.com only with your consent (Help > Report a problem... "
  375. "sends one by hand)."));
  376. // round 166b: the update check (ui/Updater.h); the Store build has none (the Store updates it)
  377. toggle (checkUpdates, tr ("Check for updates automatically"), options.checkUpdates, [this] (bool on) { options.checkUpdates = on; });
  378. checkNow.onClick = [] { updater::checkNow(); };
  379. styleNote (updatesNote, tr ("At start-up LYNX SHARE asks GitHub for the newest version number (nothing about you is sent) and shows a bar "
  380. "when a new version is out. Help > Check for updates... asks at any time."));
  381. for (auto* c : std::initializer_list<juce::Component*> { &updatesTitle, &checkUpdates, &checkNow, &updatesNote })
  382. c->setVisible (updater::offered());
  383. for (auto* b : { &templateBox, &startupProjectBox, &longestWaitBox, &languageBox, &fontBox, &scaleBox, &menuBox, &wavesBox, &noteNamesBox, &blackNotesBox, &pluginStyleBox, &animationBox, &editInBox, &undoBox, &longestWaitBox, &autosaveBox, &keepBox, &crashBox })
  384. styleCombo (*b);
  385. juce::ignoreUnused (engine, persistent);
  386. }
  387. private:
  388. int layout (int width) override
  389. {
  390. Rows r (width);
  391. r.section (workflowTitle, true);
  392. layoutStyleBox.setBounds (r.row (layoutStyleLabel, 260));
  393. layoutStyleNote.setBounds (r.indented (66).translated (0, -3));
  394. alsSessionBox.setBounds (r.row (alsSessionLabel, 260));
  395. r.section (languageTitle);
  396. languageBox.setBounds (r.row (languageLabel, 220));
  397. languageNote.setBounds (r.indented (languageNote.getText().length() > 60 ? 32 : 16).translated (0, -3));
  398. if (translationLink.isVisible())
  399. translationLink.setBounds (r.indented (18).translated (0, -4).withWidth (juce::jmin (420, width - 40)));
  400. {
  401. // (the reset button as wide as its text: "Auf Standard zurücksetzen" wrapped at a fixed width)
  402. const auto resetWidth = juce::jlimit (110, 240, juce::roundToInt (juce::GlyphArrangement::getStringWidth (
  403. getLookAndFeel().getTextButtonFont (fontReset, 24), fontReset.getButtonText())) + 24);
  404. auto row = r.row (fontLabel, 228 + resetWidth);
  405. fontBox.setBounds (row.removeFromLeft (220));
  406. fontReset.setBounds (row.withTrimmedLeft (8));
  407. }
  408. fontPreview.setBounds (r.indented (22).translated (0, -3));
  409. fontNote.setBounds (r.indented (16).translated (0, -5));
  410. scaleBox.setBounds (r.row (scaleLabel, 120));
  411. menuBox.setBounds (r.row (menuLabel, 160));
  412. wavesBox.setBounds (r.row (wavesLabel, 0));
  413. stereoWaves.setBounds (r.indented (24));
  414. noteNamesBox.setBounds (r.row (noteNamesLabel, 220));
  415. blackNotesBox.setBounds (r.row (blackNotesLabel, 160));
  416. everyKeyNames.setBounds (r.indented (24));
  417. rackColumn.setBounds (r.full (24));
  418. rackStepColour.setBounds (r.full (24));
  419. pluginStyleBox.setBounds (r.row (pluginStyleLabel, 300));
  420. artMotion.setBounds (r.full (24));
  421. reducedEffects.setBounds (r.full (24));
  422. uiAnimations.setBounds (r.full (24));
  423. animationBox.setBounds (r.row (animationLabel, 180));
  424. animationNote.setBounds (r.indented (32).translated (0, -3));
  425. #if JUCE_WINDOWS
  426. gpuRendering.setBounds (r.full (24));
  427. #endif
  428. r.section (startupTitle);
  429. templateBox.setBounds (r.row (templateLabel, 260));
  430. startupProjectBox.setBounds (r.row (startupProjectLabel, 260));
  431. templateNote.setBounds (r.indented (32).translated (0, -3));
  432. for (auto* t : { &splash, &startupSound, &scanAtStart })
  433. t->setBounds (r.full (24));
  434. if (menuEntry.isVisible())
  435. menuEntry.setBounds (r.full (24));
  436. r.section (editingTitle);
  437. for (auto* t : { &typingPiano, &keepEditors, &detachNew, &rememberSeek, &clipsLoop, &autoClipsAtPlayback, &firstChannel, &monoPaint, &autoSelectLinked, &noTypingPriority, &hoverValues })
  438. t->setBounds (r.full (24));
  439. editInBox.setBounds (r.row (editInLabel, 0));
  440. undoBox.setBounds (r.row (undoLabel, 120));
  441. alternateUndo.setBounds (r.full (24));
  442. r.section (hintsTitle); // FL's General › Hints and warnings (round 186c)
  443. {
  444. auto row = r.full();
  445. manageMessages.setBounds (row.removeFromLeft (180));
  446. row.removeFromLeft (12);
  447. messagesNote.setBounds (row.withTrimmedTop (6));
  448. }
  449. r.section (backupTitle);
  450. {
  451. auto row = r.row (autosaveLabel, 0);
  452. autosaveBox.setBounds (row.removeFromLeft (220));
  453. row.removeFromLeft (8);
  454. openBackups.setBounds (row.removeFromLeft (juce::jmin (row.getWidth(), 170)));
  455. }
  456. keepBox.setBounds (r.row (keepLabel, 120));
  457. backupQuiet.setBounds (r.full (24));
  458. longestWaitBox.setBounds (r.row (longestWaitLabel, 120));
  459. unusedTakes.setBounds (r.full (24));
  460. r.section (pluginsTitle);
  461. sandbox.setBounds (r.full (24));
  462. sandboxNote.setBounds (r.full (16).translated (0, -3));
  463. substitutes.setBounds (r.full (24));
  464. substitutesNote.setBounds (r.full (16).translated (0, -3));
  465. limitEditors.setBounds (r.full (24));
  466. {
  467. auto row = r.full();
  468. managePlugins.setBounds (row.removeFromLeft (180));
  469. row.removeFromLeft (8);
  470. manageShortcuts.setBounds (row.removeFromLeft (180));
  471. row.removeFromLeft (12);
  472. shortcutsNote.setBounds (row.withTrimmedTop (6));
  473. }
  474. r.section (reportsTitle);
  475. crashBox.setBounds (r.row (crashLabel, 260));
  476. crashNote.setBounds (r.full (46).translated (0, -3));
  477. if (updatesTitle.isVisible())
  478. {
  479. r.section (updatesTitle);
  480. auto row = r.full (24);
  481. checkNow.setBounds (row.removeFromRight (juce::jmin (row.getWidth() / 3, 150)));
  482. checkUpdates.setBounds (row.withTrimmedRight (8));
  483. updatesNote.setBounds (r.full (32).translated (0, -1));
  484. }
  485. displayTitle.setVisible (false);
  486. return r.bottom();
  487. }
  488. void toggle (juce::ToggleButton& t, const juce::String& text, bool value, std::function<void (bool)> set)
  489. {
  490. styleToggle (t, text);
  491. t.setToggleState (value, juce::dontSendNotification);
  492. t.onClick = [this, &t, set = std::move (set)] { change ([&] { set (t.getToggleState()); }); };
  493. }
  494. // the LYNX extras page switches this one too (round 190am): the copy kept here follows when the page comes back
  495. void visibilityChanged() override
  496. {
  497. if (isVisible() && hooks.getGeneral)
  498. {
  499. options.hoverValues = hooks.getGeneral().hoverValues;
  500. hoverValues.setToggleState (options.hoverValues, juce::dontSendNotification);
  501. }
  502. }
  503. static void selectNearest (juce::ComboBox& box, int value)
  504. {
  505. auto best = box.getItemId (0);
  506. for (int i = 0; i < box.getNumItems(); ++i)
  507. if (std::abs (box.getItemId (i) - value) < std::abs (best - value))
  508. best = box.getItemId (i);
  509. box.setSelectedId (best, juce::dontSendNotification);
  510. }
  511. void change (const std::function<void()>& fn)
  512. {
  513. fn();
  514. if (hooks.setGeneral)
  515. hooks.setGeneral (options);
  516. }
  517. // The interface font: the platform's default or any installed family, saved at once, applied by the next start
  518. // (Labels and caches hold the old font's shapes). The sample line shows the choice right away.
  519. void setupFontRow()
  520. {
  521. for (auto* c : std::initializer_list<juce::Component*> { &fontLabel, &fontBox, &fontReset, &fontPreview, &fontNote })
  522. add (*c);
  523. styleLabel (fontLabel, tr ("Interface font"));
  524. styleNote (fontNote, tr ("A new interface font is applied when LYNX SHARE restarts."));
  525. const auto fallback = theme::defaultUiFont();
  526. fontBox.addItem (fallback.isNotEmpty() ? tr ("Default ({0})", { fallback }) : tr ("Default"), 1);
  527. fontBox.addSeparator();
  528. fontNames = theme::installedUiFonts();
  529. for (int i = 0; i < fontNames.size(); ++i)
  530. fontBox.addItem (fontNames[i], i + 2);
  531. // (a saved font that is gone reads as the default here too, as at start-up)
  532. const auto at = fontNames.indexOf (options.uiFont);
  533. fontBox.setSelectedId (at >= 0 ? at + 2 : 1, juce::dontSendNotification);
  534. fontBox.onChange = [this] {
  535. const auto index = fontBox.getSelectedId() - 2;
  536. change ([&] { options.uiFont = juce::isPositiveAndBelow (index, fontNames.size()) ? fontNames[index] : juce::String(); });
  537. updateFontPreview();
  538. };
  539. fontReset.onClick = [this] { fontBox.setSelectedId (1, juce::sendNotificationSync); };
  540. fontPreview.setText ("LYNX SHARE AaBbCc 0123456789", juce::dontSendNotification);
  541. fontPreview.setColour (juce::Label::textColourId, theme::colour::textPrimary);
  542. updateFontPreview();
  543. }
  544. void updateFontPreview()
  545. {
  546. const auto index = fontBox.getSelectedId() - 2;
  547. const auto family = juce::isPositiveAndBelow (index, fontNames.size()) ? fontNames[index] : theme::defaultUiFont();
  548. fontPreview.setFont (family.isNotEmpty() ? juce::Font (juce::FontOptions (family, 14.0f, juce::Font::plain))
  549. : juce::Font (juce::FontOptions (14.0f)));
  550. fontReset.setEnabled (fontBox.getSelectedId() != 1);
  551. }
  552. void updateTranslationLink()
  553. {
  554. // shown in the language just picked when it is already running, else in the current one
  555. const auto id = options.language;
  556. translationLink.setVisible (i18n::isNewTranslation (id));
  557. // Linux without Noto CJK & co.: the language would show empty boxes
  558. const auto noFont = theme::needsOwnFont (id) && theme::uiFontForLanguage (id).isEmpty();
  559. languageNote.setText (noFont ? tr ("This language needs a Chinese / Japanese / Korean font: install the Noto Sans CJK fonts "
  560. "(fonts-noto-cjk or google-noto-sans-cjk-fonts), then restart LYNX SHARE.")
  561. : tr ("A new language is applied when LYNX SHARE restarts."),
  562. juce::dontSendNotification);
  563. languageNote.setColour (juce::Label::textColourId, noFont ? theme::colour::accent : theme::colour::textDisabled);
  564. translationLink.setButtonText (tr ("New translation — suggestions welcome"));
  565. translationLink.setTooltip (tr ("Opens a GitHub issue to suggest a better translation"));
  566. translationLink.setURL (juce::URL ("https://github.com/Ka1-S/LYNX-SHARE/issues/new")
  567. .withParameter ("title", "Translation (" + id + "): ")
  568. .withParameter ("labels", "translation"));
  569. }
  570. AudioEngine& engine;
  571. SettingsHooks hooks;
  572. bool persistent;
  573. GeneralOptions options;
  574. SectionTitle workflowTitle { tr ("Workflow") };
  575. juce::Label layoutStyleLabel, layoutStyleNote;
  576. juce::ComboBox layoutStyleBox;
  577. juce::Label alsSessionLabel;
  578. juce::ComboBox alsSessionBox;
  579. SectionTitle languageTitle { tr ("Language and display") }, displayTitle, startupTitle { tr ("Startup") }, editingTitle { tr ("Editing") },
  580. backupTitle { tr ("Backup") }, hintsTitle { tr ("Hints and warnings") }, pluginsTitle { tr ("Plugins and shortcuts") }, reportsTitle { tr ("Crash reports") }, updatesTitle { tr ("Updates") };
  581. juce::Label longestWaitLabel, animationLabel, animationNote, languageLabel, languageNote, scaleLabel, menuLabel, wavesLabel, noteNamesLabel, blackNotesLabel, pluginStyleLabel, editInLabel, undoLabel, autosaveLabel, keepLabel, sandboxNote, substitutesNote, shortcutsNote, crashLabel, crashNote, updatesNote;
  582. juce::Label fontLabel, fontPreview, fontNote;
  583. juce::ComboBox fontBox;
  584. juce::Label templateLabel, templateNote, startupProjectLabel;
  585. juce::ComboBox templateBox, startupProjectBox;
  586. std::vector<TemplateChoice> templateChoices; // templateBox's item id - 1
  587. juce::TextButton fontReset { tr ("Reset to default") };
  588. juce::StringArray fontNames;
  589. juce::HyperlinkButton translationLink;
  590. juce::ComboBox animationBox, crashBox, languageBox, scaleBox, menuBox, wavesBox, noteNamesBox, blackNotesBox, pluginStyleBox, editInBox, undoBox, autosaveBox, keepBox, longestWaitBox;
  591. juce::ToggleButton detachNew, stereoWaves, everyKeyNames, rackColumn, rackStepColour, artMotion, reducedEffects, uiAnimations, gpuRendering, splash, startupSound, scanAtStart, menuEntry, typingPiano, keepEditors, rememberSeek, clipsLoop, autoClipsAtPlayback, firstChannel, monoPaint, hoverValues, alternateUndo, sandbox, substitutes, limitEditors, backupQuiet, unusedTakes, checkUpdates, noTypingPriority, autoSelectLinked;
  592. juce::TextButton openBackups { tr ("Open backup folder") }, managePlugins { tr ("Plugin manager...") }, manageShortcuts { tr ("Manage shortcuts...") },
  593. checkNow { tr ("Check now") }, manageMessages { tr ("Manage messages") };
  594. juce::Label messagesNote;
  595. };
  596. // ================================================================================================================
  597. // Audio
  598. // ================================================================================================================
  599. class AudioPage final : public ScrollingPage,
  600. private juce::ChangeListener,
  601. private juce::Timer
  602. {
  603. public:
  604. AudioPage (AudioEngine& e) : engine (e), devices (e.getDeviceManager())
  605. {
  606. for (auto* c : std::initializer_list<juce::Component*> { &deviceTitle, &statusTitle, &recordTitle, &driverLabel, &driverBox, &driverNote, &outputLabel,
  607. &outputBox, &inputLabel, &inputBox, &rateLabel, &rateBox, &bufferLabel, &bufferBox,
  608. &bufferNote, &panelButton, &testButton, &status, &load, &outputChannels, &realtime, &recordInput, &recordNote, &inputChannels,
  609. &formatLabel, &formatBox, &takeNames, &latencyTitle, &latencyText, &pingOutLabel, &pingOutBox,
  610. &pingInLabel, &pingInBox, &measureButton, &pingNote, &useMeasured, &offsetLabel, &offsetSlider, &offsetNote,
  611. &mixerTitle, &metronomeTrackLabel, &metronomeTrackBox, &metronomeTrackNote, &playTruncated, &resetPlugins })
  612. add (*c);
  613. setupRecordingControls();
  614. setupMixerControls();
  615. styleLabel (driverLabel, tr ("Driver"));
  616. styleLabel (outputLabel, tr ("Output device"));
  617. styleLabel (inputLabel, tr ("Input device"));
  618. styleLabel (rateLabel, tr ("Sample rate"));
  619. styleLabel (bufferLabel, tr ("Buffer size"));
  620. styleNote (driverNote, {});
  621. styleNote (bufferNote, tr ("Smaller buffers answer faster when you play; larger ones give the CPU more room (fewer clicks)."));
  622. styleNote (realtime, {});
  623. for (auto* l : { &status, &load })
  624. {
  625. styleLabel (*l, {}, false);
  626. l->setJustificationType (juce::Justification::centredLeft);
  627. }
  628. for (auto* b : { &driverBox, &outputBox, &inputBox, &rateBox, &bufferBox })
  629. {
  630. styleCombo (*b);
  631. b->setTextWhenNoChoicesAvailable (tr ("(open an output device first)"));
  632. b->setTextWhenNothingSelected (tr ("(choose)"));
  633. }
  634. driverBox.onChange = [this] {
  635. if (updating)
  636. return;
  637. auto& types = devices.getAvailableDeviceTypes();
  638. const auto index = driverBox.getSelectedId() - 1;
  639. if (juce::isPositiveAndBelow (index, types.size()))
  640. devices.setCurrentAudioDeviceType (types[index]->getTypeName(), true);
  641. refresh();
  642. };
  643. outputBox.onChange = [this] {
  644. apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.outputDeviceName = outputBox.getText(); });
  645. };
  646. inputBox.onChange = [this] {
  647. if (updating)
  648. return;
  649. if (inputBox.getSelectedId() <= 1)
  650. apply ([] (juce::AudioDeviceManager::AudioDeviceSetup& s) {
  651. s.inputDeviceName = {};
  652. s.useDefaultInputChannels = false;
  653. s.inputChannels.clear();
  654. });
  655. else
  656. {
  657. // every channel of the device opens: each mixer insert picks its own (pair or single channel)
  658. const auto result = engine.openAudioInput (inputBox.getText());
  659. error = result.issue == AudioEngine::InputIssue::failed ? result.detail : juce::String();
  660. refresh();
  661. }
  662. };
  663. rateBox.onChange = [this] {
  664. apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.sampleRate = (double) rateBox.getSelectedId(); });
  665. };
  666. bufferBox.onChange = [this] {
  667. apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.bufferSize = bufferBox.getSelectedId(); });
  668. };
  669. panelButton.onClick = [this] {
  670. // the driver's own window (ASIO); AudioEngine::showDriverPanel reopens the device with what was set there
  671. // (0.1.17 / 0.1.18 closed the device first and then called the deleted device: issues #12 and #13)
  672. AudioEngine::showDriverPanel (devices);
  673. refresh();
  674. };
  675. testButton.onClick = [this] { devices.playTestSound(); };
  676. styleToggle (recordInput, tr ("Record input audio"));
  677. styleNote (recordNote, tr ("Choose each mixer insert's input in the Mixer (the input box above its effect slots), arm it, then Rec + Play. "
  678. "This switch records the first two input channels into a new insert when nothing is armed."));
  679. recordInput.onClick = [this] { engine.setAudioRecordingArmed (recordInput.getToggleState()); };
  680. devices.addChangeListener (this);
  681. refresh();
  682. startTimerHz (2);
  683. }
  684. ~AudioPage() override { devices.removeChangeListener (this); }
  685. private:
  686. int layout (int width) override
  687. {
  688. Rows r (width);
  689. r.section (deviceTitle, true);
  690. driverBox.setBounds (r.row (driverLabel, 320));
  691. driverNote.setBounds (r.indented (46).translated (0, -3));
  692. outputBox.setBounds (r.row (outputLabel, 0));
  693. inputBox.setBounds (r.row (inputLabel, 0));
  694. rateBox.setBounds (r.row (rateLabel, 160));
  695. bufferBox.setBounds (r.row (bufferLabel, 260));
  696. bufferNote.setBounds (r.indented (18).translated (0, -3));
  697. {
  698. auto row = r.indented();
  699. panelButton.setBounds (row.removeFromLeft (170));
  700. row.removeFromLeft (8);
  701. testButton.setBounds (row.removeFromLeft (150));
  702. }
  703. r.section (statusTitle);
  704. status.setBounds (r.full (22));
  705. load.setBounds (r.full (22));
  706. outputChannels.setBounds (r.full (22));
  707. #if JUCE_LINUX
  708. realtime.setBounds (r.full (realtimeDenied ? 50 : 22));
  709. #endif
  710. r.section (recordTitle);
  711. inputChannels.setBounds (r.full (34));
  712. recordInput.setBounds (r.full (24));
  713. recordNote.setBounds (r.full (32).translated (0, -3));
  714. formatBox.setBounds (r.row (formatLabel, 320));
  715. takeNames.setBounds (r.full (24));
  716. r.section (latencyTitle);
  717. latencyText.setBounds (r.full (50));
  718. pingOutBox.setBounds (r.row (pingOutLabel, 260));
  719. pingInBox.setBounds (r.row (pingInLabel, 260));
  720. measureButton.setBounds (r.indented().withWidth (240));
  721. pingNote.setBounds (r.full (48).translated (0, -2));
  722. useMeasured.setBounds (r.full (24));
  723. offsetSlider.setBounds (r.row (offsetLabel, 200));
  724. offsetNote.setBounds (r.full (32).translated (0, -3));
  725. r.section (mixerTitle);
  726. metronomeTrackBox.setBounds (r.row (metronomeTrackLabel, 260));
  727. metronomeTrackNote.setBounds (r.full (32).translated (0, -3));
  728. playTruncated.setBounds (r.full (24));
  729. resetPlugins.setBounds (r.full (24));
  730. return r.bottom();
  731. }
  732. // FL's Settings › Audio › Mixer › "Metronome track" (round 165z-a2): "---" = the Master, else an insert. A global
  733. // setting, like FL's; a song without that insert plays the click on the Master.
  734. void setupMixerControls()
  735. {
  736. styleLabel (metronomeTrackLabel, tr ("Metronome track"));
  737. styleCombo (metronomeTrackBox);
  738. metronomeTrackBox.setTooltip (tr ("Metronome target mixer track"));
  739. styleNote (metronomeTrackNote, tr ("The mixer track the metronome plays through (--- is the Master). The click is never in an export."));
  740. const auto& mixer = engine.getSong().mixer;
  741. metronomeTrackBox.addItem ("---", 1);
  742. for (int t = 1; t < maxMixerTracks; ++t)
  743. {
  744. const auto name = t < (int) mixer.size() ? juce::String (mixer[(std::size_t) t].name) : juce::String();
  745. metronomeTrackBox.addItem (name.isEmpty() ? juce::String (t) : juce::String (t) + " " + name, t + 1);
  746. }
  747. metronomeTrackBox.setSelectedId (engine.getTransport().metronomeTrack.load() + 1, juce::dontSendNotification);
  748. metronomeTrackBox.onChange = [this] {
  749. engine.getTransport().metronomeTrack.store (juce::jmax (0, metronomeTrackBox.getSelectedId() - 1));
  750. if (mixeroptions::changed)
  751. mixeroptions::changed(); // (ui-options.txt)
  752. };
  753. // FL's Settings › Audio › Mixer (round 167j): "Play truncated notes on transport" (FL: "Play notes crossing
  754. // start position", on by default) and "Reset plugins on transport" (FL: off by default)
  755. styleToggle (playTruncated, tr ("Play truncated notes on transport"));
  756. playTruncated.setTooltip (tr ("Play notes crossing start position"));
  757. playTruncated.setToggleState (engine.getTransport().playTruncatedOnTransport.load(), juce::dontSendNotification);
  758. playTruncated.onClick = [this] {
  759. engine.getTransport().playTruncatedOnTransport.store (playTruncated.getToggleState());
  760. if (mixeroptions::changed)
  761. mixeroptions::changed();
  762. };
  763. styleToggle (resetPlugins, tr ("Reset plugins on transport"));
  764. resetPlugins.setTooltip (tr ("Clears the effects' tails when playback starts or jumps. Uncheck for faster response when relocating"));
  765. resetPlugins.setToggleState (engine.getTransport().resetPluginsOnTransport.load(), juce::dontSendNotification);
  766. resetPlugins.onClick = [this] {
  767. engine.getTransport().resetPluginsOnTransport.store (resetPlugins.getToggleState());
  768. if (mixeroptions::changed)
  769. mixeroptions::changed();
  770. };
  771. }
  772. void apply (const std::function<void (juce::AudioDeviceManager::AudioDeviceSetup&)>& change)
  773. {
  774. if (updating)
  775. return;
  776. auto setup = devices.getAudioDeviceSetup();
  777. change (setup);
  778. error = devices.setAudioDeviceSetup (setup, true);
  779. refresh();
  780. }
  781. void refresh()
  782. {
  783. const juce::ScopedValueSetter<bool> guard (updating, true);
  784. auto* type = devices.getCurrentDeviceTypeObject();
  785. auto* device = devices.getCurrentAudioDevice();
  786. const auto setup = devices.getAudioDeviceSetup();
  787. driverBox.clear (juce::dontSendNotification);
  788. auto& types = devices.getAvailableDeviceTypes();
  789. for (int i = 0; i < types.size(); ++i)
  790. {
  791. driverBox.addItem (driverDisplayName (types[i]->getTypeName()), i + 1);
  792. if (types[i] == type)
  793. driverBox.setSelectedId (i + 1, juce::dontSendNotification);
  794. }
  795. outputBox.clear (juce::dontSendNotification);
  796. inputBox.clear (juce::dontSendNotification);
  797. inputBox.addItem (tr ("(none)"), 1);
  798. inputBox.setSelectedId (1, juce::dontSendNotification);
  799. if (type != nullptr)
  800. {
  801. if (type->getDeviceNames (false).isEmpty())
  802. type->scanForDevices(); // (a driver type not opened yet this session)
  803. const auto outs = type->getDeviceNames (false);
  804. for (int i = 0; i < outs.size(); ++i)
  805. {
  806. outputBox.addItem (outs[i], i + 1);
  807. if (outs[i] == setup.outputDeviceName)
  808. outputBox.setSelectedId (i + 1, juce::dontSendNotification);
  809. }
  810. if (type->hasSeparateInputsAndOutputs())
  811. {
  812. const auto ins = type->getDeviceNames (true);
  813. for (int i = 0; i < ins.size(); ++i)
  814. {
  815. inputBox.addItem (ins[i], i + 2);
  816. if (ins[i] == setup.inputDeviceName && ! setup.inputChannels.isZero())
  817. inputBox.setSelectedId (i + 2, juce::dontSendNotification);
  818. }
  819. }
  820. else if (setup.outputDeviceName.isNotEmpty())
  821. {
  822. // ASIO: one device does both
  823. inputBox.addItem (setup.outputDeviceName, 2);
  824. if (! setup.inputChannels.isZero())
  825. inputBox.setSelectedId (2, juce::dontSendNotification);
  826. }
  827. }
  828. rateBox.clear (juce::dontSendNotification);
  829. bufferBox.clear (juce::dontSendNotification);
  830. if (device != nullptr)
  831. {
  832. const auto rate = device->getCurrentSampleRate();
  833. for (auto r : device->getAvailableSampleRates())
  834. rateBox.addItem (juce::String ((int) r) + " Hz", (int) r);
  835. rateBox.setSelectedId ((int) rate, juce::dontSendNotification);
  836. const auto kind = prefs::driverKind (device->getTypeName().toStdString());
  837. std::vector<int> offered;
  838. for (auto b : device->getAvailableBufferSizes())
  839. offered.push_back (b);
  840. for (auto b : prefs::usableBufferSizes (kind, offered, device->getDefaultBufferSize()))
  841. bufferBox.addItem (tr ("{0} samples ({1} ms)", { juce::String (b), juce::String (prefs::bufferLatencyMs (b, rate), 1) }), b);
  842. bufferBox.setSelectedId (device->getCurrentBufferSizeSamples(), juce::dontSendNotification);
  843. }
  844. for (auto* b : { &outputBox, &inputBox, &rateBox, &bufferBox })
  845. b->setEnabled (b->getNumItems() > 0);
  846. driverNote.setText (driverExplanation (type != nullptr ? type->getTypeName() : juce::String(), device), juce::dontSendNotification);
  847. panelButton.setEnabled (device != nullptr && device->hasControlPanel());
  848. testButton.setEnabled (device != nullptr);
  849. recordInput.setToggleState (engine.isAudioRecordingArmed(), juce::dontSendNotification);
  850. refreshRecording();
  851. {
  852. // what the mixer inserts can take their input from
  853. const auto names = engine.getInputChannelNames();
  854. juce::StringArray list;
  855. for (const auto& n : names)
  856. list.add (juce::String::fromUTF8 (n.c_str()));
  857. styleNote (inputChannels, names.empty() ? tr ("Input channels: none open. Choose an input device above to record a microphone or an instrument.")
  858. : tr ("Input channels ({0}): {1}", { juce::String ((int) names.size()), list.joinIntoString (", ") }));
  859. }
  860. {
  861. // the device's outputs by name (PipeWire / JACK / ASIO name their channels)
  862. juce::StringArray outs;
  863. if (device != nullptr)
  864. {
  865. const auto names = device->getOutputChannelNames();
  866. const auto active = device->getActiveOutputChannels();
  867. for (int c = 0; c < names.size(); ++c)
  868. outs.add (names[c] + (active[c] ? juce::String() : " (" + tr ("off") + ")"));
  869. }
  870. styleNote (outputChannels, outs.isEmpty() ? juce::String()
  871. : tr ("Output channels ({0}): {1}", { juce::String (outs.size()), outs.joinIntoString (", ") }));
  872. }
  873. updateStatus();
  874. }
  875. void updateStatus()
  876. {
  877. auto* device = devices.getCurrentAudioDevice();
  878. if (device == nullptr)
  879. {
  880. status.setText (error.isNotEmpty() ? error : tr ("No audio device is open: choose an output device."), juce::dontSendNotification);
  881. status.setColour (juce::Label::textColourId, theme::colour::warning);
  882. load.setText ({}, juce::dontSendNotification);
  883. return;
  884. }
  885. const auto rate = device->getCurrentSampleRate();
  886. const auto latency = prefs::bufferLatencyMs (device->getOutputLatencyInSamples() + device->getCurrentBufferSizeSamples(), rate);
  887. status.setText (tr ("{0} is running: {1} Hz, output latency {2} ms",
  888. { device->getName(), juce::String ((int) rate), juce::String (latency, 1) }),
  889. juce::dontSendNotification);
  890. status.setColour (juce::Label::textColourId, theme::colour::textPrimary);
  891. const auto xruns = device->getXRunCount();
  892. const auto rt = engine.getRtStats().snapshot();
  893. const auto dot = juce::String::fromUTF8 (" \xc2\xb7 ");
  894. load.setText (tr ("Audio CPU load: {0}%", { juce::String (juce::roundToInt (devices.getCpuUsage() * 100.0)) })
  895. + (xruns > 0 ? dot + tr ("{0} dropouts (buffer underruns) so far", { juce::String (xruns) }) : juce::String())
  896. + (rt.overBudget > 0 ? dot + tr ("{0} blocks over the deadline (max {1}%)", { juce::String ((juce::int64) rt.overBudget), juce::String (juce::roundToInt (rt.maxLoad * 100.0)) })
  897. : juce::String()),
  898. juce::dontSendNotification);
  899. load.setColour (juce::Label::textColourId, xruns > 0 || rt.overBudget > 0 ? theme::colour::warning : theme::colour::textSecondary);
  900. #if JUCE_LINUX
  901. updateRealtime();
  902. #endif
  903. }
  904. // Linux: whether the audio thread got real-time priority (round 161), and how to get it when it did not
  905. void updateRealtime()
  906. {
  907. const auto state = lynx::rt::status();
  908. const auto denied = state == lynx::rt::Status::denied;
  909. if (state == lynx::rt::Status::unknown)
  910. realtime.setText ({}, juce::dontSendNotification);
  911. else if (denied)
  912. realtime.setText (tr ("Audio thread: normal priority, so the sound breaks up more easily under load. To allow real-time priority, "
  913. "install rtkit (most desktops have it) or add yourself to the \"audio\" group with an rtprio limit "
  914. "(/etc/security/limits.d), then log in again. LYNX SHARE never needs root."),
  915. juce::dontSendNotification);
  916. else
  917. realtime.setText (tr ("Audio thread: real-time priority ({0})", { lynx::rt::describe() }), juce::dontSendNotification);
  918. realtime.setColour (juce::Label::textColourId, denied ? theme::colour::warning : theme::colour::textSecondary);
  919. if (denied != realtimeDenied)
  920. {
  921. realtimeDenied = denied;
  922. resized();
  923. }
  924. }
  925. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  926. void timerCallback() override
  927. {
  928. updateStatus();
  929. if (measuring && ! engine.isPinging())
  930. {
  931. measuring = false;
  932. const auto r = engine.finishLatencyPing();
  933. pingResult = r.ok ? tr ("Measured: {0} samples ({1} ms) round trip, {2} of {3} clicks, level {4} dB.",
  934. { juce::String (r.samples), juce::String (1000.0 * r.samples / juce::jmax (1.0, sampleRate()), 2), juce::String (r.found),
  935. juce::String (r.sent), juce::String (juce::Decibels::gainToDecibels (r.peak, -100.0f), 1) })
  936. : r.problem == "no signal" ? tr ("No click came back. Connect the output to the input (cable or loopback) and try again.")
  937. : r.problem == "unstable" ? tr ("The clicks came back at different times ({0} samples apart): the driver is not stable at this buffer size. Nothing was stored.",
  938. { juce::String (r.spread) })
  939. : tr ("Only {0} of {1} clicks came back: raise the input level or use a cable loopback. Nothing was stored.",
  940. { juce::String (r.found), juce::String (r.sent) });
  941. refreshRecording();
  942. }
  943. }
  944. double sampleRate() const
  945. {
  946. auto* device = devices.getCurrentAudioDevice();
  947. return device != nullptr && device->getCurrentSampleRate() > 0.0 ? device->getCurrentSampleRate() : 48000.0;
  948. }
  949. // Recording format, file names and the latency compensation (round 163)
  950. void setupRecordingControls()
  951. {
  952. styleLabel (formatLabel, tr ("File format"));
  953. styleCombo (formatBox);
  954. formatBox.addItem (tr ("WAV 24-bit (the device's sample rate)"), 1);
  955. formatBox.addItem (tr ("WAV 32-bit float (the device's sample rate)"), 2);
  956. formatBox.onChange = [this] {
  957. if (updating)
  958. return;
  959. auto s = engine.getRecordingSettings();
  960. s.format = formatBox.getSelectedId() == 2 ? takes::SampleFormat::float32 : takes::SampleFormat::pcm24;
  961. engine.setRecordingSettings (s);
  962. };
  963. styleToggle (takeNames, tr ("Name takes after the track (\"Bass DI_Take3.wav\"); off: project, date and time as FL does"));
  964. takeNames.onClick = [this] {
  965. auto s = engine.getRecordingSettings();
  966. s.trackTakeNames = takeNames.getToggleState();
  967. engine.setRecordingSettings (s);
  968. };
  969. styleNote (latencyText, {});
  970. styleLabel (pingOutLabel, tr ("Ping output"));
  971. styleLabel (pingInLabel, tr ("Ping input"));
  972. for (auto* b : { &pingOutBox, &pingInBox })
  973. {
  974. styleCombo (*b);
  975. b->setTextWhenNoChoicesAvailable (tr ("(open an input device first)"));
  976. }
  977. pingOutBox.onChange = [this] {
  978. if (updating)
  979. return;
  980. auto s = engine.getRecordingSettings();
  981. s.pingOutput = juce::jmax (0, pingOutBox.getSelectedId() - 1);
  982. engine.setRecordingSettings (s);
  983. };
  984. pingInBox.onChange = [this] {
  985. if (updating)
  986. return;
  987. auto s = engine.getRecordingSettings();
  988. s.pingInput = juce::jmax (0, pingInBox.getSelectedId() - 1);
  989. engine.setRecordingSettings (s);
  990. };
  991. measureButton.onClick = [this] {
  992. if (measuring)
  993. {
  994. engine.cancelLatencyPing();
  995. return;
  996. }
  997. const auto problem = engine.startLatencyPing();
  998. if (problem.isNotEmpty())
  999. {
  1000. pingResult = tr ("Can't measure: {0}", { tr (problem) });
  1001. refreshRecording();
  1002. return;
  1003. }
  1004. measuring = true;
  1005. pingResult = tr ("Measuring... (8 clicks)");
  1006. refreshRecording();
  1007. };
  1008. styleNote (pingNote, tr ("Connect the ping output to the ping input with a cable (or a loopback in your interface's mixer) and turn your speakers "
  1009. "down: LYNX SHARE plays 8 clicks and times their way back. The result is kept for this driver, device, sample rate and buffer size."));
  1010. styleToggle (useMeasured, tr ("Use the measured round trip instead of the driver's figures"));
  1011. useMeasured.onClick = [this] {
  1012. auto s = engine.getRecordingSettings();
  1013. s.useMeasured = useMeasured.getToggleState();
  1014. engine.setRecordingSettings (s);
  1015. };
  1016. styleLabel (offsetLabel, tr ("Fine adjust (samples)"));
  1017. offsetSlider.setSliderStyle (juce::Slider::IncDecButtons);
  1018. offsetSlider.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 80, 24);
  1019. offsetSlider.setRange (-4800.0, 4800.0, 1.0);
  1020. offsetSlider.onValueChange = [this] {
  1021. if (updating)
  1022. return;
  1023. auto s = engine.getRecordingSettings();
  1024. s.manualOffset = (int) offsetSlider.getValue();
  1025. engine.setRecordingSettings (s);
  1026. };
  1027. styleNote (offsetNote, tr ("Moves every new take: positive = earlier on the Playlist. Leave it at 0 after a measurement."));
  1028. }
  1029. void refreshRecording()
  1030. {
  1031. const juce::ScopedValueSetter<bool> guard (updating, true);
  1032. const auto& s = engine.getRecordingSettings();
  1033. formatBox.setSelectedId (s.format == takes::SampleFormat::float32 ? 2 : 1, juce::dontSendNotification);
  1034. takeNames.setToggleState (s.trackTakeNames, juce::dontSendNotification);
  1035. useMeasured.setToggleState (s.useMeasured, juce::dontSendNotification);
  1036. offsetSlider.setValue (s.manualOffset, juce::dontSendNotification);
  1037. pingOutBox.clear (juce::dontSendNotification);
  1038. pingInBox.clear (juce::dontSendNotification);
  1039. if (auto* device = devices.getCurrentAudioDevice())
  1040. {
  1041. const auto outs = device->getOutputChannelNames();
  1042. for (int c = 0; c + 1 < outs.size(); c += 2)
  1043. pingOutBox.addItem (outs[c] + " - " + outs[c + 1], c + 1);
  1044. if (outs.size() == 1)
  1045. pingOutBox.addItem (outs[0], 1);
  1046. pingOutBox.setSelectedId (s.pingOutput + 1, juce::dontSendNotification);
  1047. const auto ins = engine.getInputChannelNames();
  1048. for (int c = 0; c < (int) ins.size(); ++c)
  1049. pingInBox.addItem (juce::String::fromUTF8 (ins[(std::size_t) c].c_str()), c + 1);
  1050. pingInBox.setSelectedId (s.pingInput + 1, juce::dontSendNotification);
  1051. }
  1052. measureButton.setButtonText (measuring ? tr ("Stop measuring") : tr ("Measure the round trip"));
  1053. measureButton.setEnabled (pingInBox.getNumItems() > 0);
  1054. const auto l = engine.currentLatency();
  1055. const auto rate = sampleRate();
  1056. const auto ms = [rate] (int samples) { return juce::String (1000.0 * samples / rate, 2); };
  1057. auto text = tr ("Takes are moved back by {0} samples ({1} ms) so they sit where you played them:", { juce::String (l.total()), ms (l.total()) }) + " ";
  1058. text += l.measured >= 0 ? tr ("measured round trip {0}", { juce::String (l.measured) })
  1059. : tr ("driver's input {0} + output {1}", { juce::String (l.driverInput), juce::String (l.driverOutput) });
  1060. if (l.manual != 0)
  1061. text += ", " + tr ("fine adjust {0}", { juce::String (l.manual) });
  1062. if (l.pdc != 0)
  1063. text += ", " + tr ("plugin delay compensation {0}", { juce::String (l.pdc) });
  1064. text += ".";
  1065. if (pingResult.isNotEmpty())
  1066. text += "\n" + pingResult;
  1067. latencyText.setText (text, juce::dontSendNotification);
  1068. }
  1069. // The driver types with what they mean (JUCE's type names stay the identity in the saved setup).
  1070. static juce::String driverDisplayName (const juce::String& typeName)
  1071. {
  1072. switch (prefs::driverKind (typeName.toStdString()))
  1073. {
  1074. case prefs::DriverKind::wasapiShared: return tr ("Windows Audio (shared)");
  1075. case prefs::DriverKind::wasapiLowLatency: return tr ("Windows Audio (shared, low-latency period)");
  1076. case prefs::DriverKind::wasapiExclusive: return tr ("Windows Audio (exclusive, lowest latency)");
  1077. case prefs::DriverKind::directSound: return tr ("DirectSound (legacy)");
  1078. case prefs::DriverKind::asio: return "ASIO";
  1079. case prefs::DriverKind::lynxAsio: return tr ("LYNX ASIO (built in)");
  1080. case prefs::DriverKind::coreAudio: return "Core Audio";
  1081. case prefs::DriverKind::alsa: return "ALSA";
  1082. case prefs::DriverKind::jack: return tr ("JACK / PipeWire");
  1083. case prefs::DriverKind::pipewire: return tr ("PipeWire (native)");
  1084. case prefs::DriverKind::other: break;
  1085. }
  1086. return typeName;
  1087. }
  1088. // What the selected driver type does, and for shared mode the period this device mixes at (REA round 97).
  1089. static juce::String driverExplanation (const juce::String& typeName, juce::AudioIODevice* device)
  1090. {
  1091. const auto rate = device != nullptr && device->getCurrentSampleRate() > 0 ? device->getCurrentSampleRate() : 48000.0;
  1092. const auto period = device != nullptr ? device->getDefaultBufferSize() : 0;
  1093. switch (prefs::driverKind (typeName.toStdString()))
  1094. {
  1095. case prefs::DriverKind::wasapiShared:
  1096. return tr ("Other programs keep their sound. Windows mixes every program in steps of {0} ms on this device, so the buffer cannot go below that. "
  1097. "For lower latency choose the exclusive mode or an ASIO driver.",
  1098. { juce::String (prefs::bufferLatencyMs (period > 0 ? period : 480, rate), 1) });
  1099. case prefs::DriverKind::wasapiLowLatency:
  1100. return period > 0 && device != nullptr && device->getAvailableBufferSizes().size() <= 1
  1101. ? tr ("This device does not support a shorter period in shared mode (it stays at {0} ms). Use the exclusive mode or an ASIO driver for lower latency.",
  1102. { juce::String (prefs::bufferLatencyMs (period, rate), 1) })
  1103. : tr ("Shared like the normal mode, but asks Windows for a shorter mixing period. Only some drivers support it.");
  1104. case prefs::DriverKind::wasapiExclusive:
  1105. return tr ("LYNX SHARE uses the device alone: the lowest latency without ASIO, but other programs go silent while LYNX SHARE plays.");
  1106. case prefs::DriverKind::directSound:
  1107. return tr ("Old Windows audio path with high latency. Use it only when the others fail.");
  1108. case prefs::DriverKind::asio:
  1109. return tr ("Low-latency drivers. LYNX ASIO, FL Studio ASIO and ASIO4ALL work with any device; a manufacturer's ASIO driver works with its own device.");
  1110. case prefs::DriverKind::lynxAsio:
  1111. if (platform::runningPackaged()) // the Store build: the package folder moves with every update
  1112. return tr ("LYNX SHARE's own ASIO driver, with any device: playback and recording (microphone) at low latency. \"Driver settings...\" chooses shared or exclusive mode, the output and input devices and shows the latency. "
  1113. "To use it in other programs, install LYNX SHARE from lynx-share.com (the installer registers it).");
  1114. return tr ("LYNX SHARE's own ASIO driver, with any device: playback and recording (microphone) at low latency. \"Driver settings...\" chooses shared or exclusive mode, the output and input devices and shows the latency. "
  1115. "For other programs, run \"Register LYNX ASIO\" in LYNX SHARE's folder once.");
  1116. case prefs::DriverKind::coreAudio:
  1117. return tr ("macOS's own audio system: low latency with any device, shared with other programs.");
  1118. case prefs::DriverKind::alsa:
  1119. return tr ("Talks to the sound card directly. Choose \"default\" or \"pipewire\" to share the device with other programs; a \"hw:\" device gives the lowest latency but takes the card for LYNX SHARE alone.");
  1120. case prefs::DriverKind::jack:
  1121. return tr ("Low latency, shared with other programs and routable. On current distributions PipeWire answers as JACK (package pipewire-jack); otherwise start a JACK server first.");
  1122. case prefs::DriverKind::pipewire:
  1123. return tr ("LYNX SHARE talks to PipeWire directly: low latency, shared with other programs. \"System default\" follows the output chosen in "
  1124. "the system's sound settings (also when a device is plugged in or removed); LYNX SHARE appears as \"LYNX\" in pw-link, qpwgraph or Helvum.");
  1125. case prefs::DriverKind::other:
  1126. break;
  1127. }
  1128. return {};
  1129. }
  1130. AudioEngine& engine;
  1131. juce::AudioDeviceManager& devices;
  1132. bool updating = false;
  1133. juce::String error;
  1134. SectionTitle deviceTitle { tr ("Audio device") }, statusTitle { tr ("Status") }, recordTitle { tr ("Recording") };
  1135. juce::Label driverLabel, driverNote, outputLabel, inputLabel, rateLabel, bufferLabel, bufferNote, status, load, outputChannels, realtime, recordNote, inputChannels;
  1136. bool realtimeDenied = false;
  1137. juce::ComboBox driverBox, outputBox, inputBox, rateBox, bufferBox;
  1138. juce::TextButton panelButton { tr ("Driver settings...") }, testButton { tr ("Play a test sound") };
  1139. juce::ToggleButton recordInput;
  1140. // recording format and latency compensation (round 163)
  1141. SectionTitle latencyTitle { tr ("Recording latency compensation") };
  1142. juce::Label formatLabel, latencyText, pingOutLabel, pingInLabel, pingNote, offsetLabel, offsetNote;
  1143. juce::ComboBox formatBox, pingOutBox, pingInBox;
  1144. juce::ToggleButton takeNames, useMeasured;
  1145. juce::TextButton measureButton { tr ("Measure the round trip") };
  1146. juce::Slider offsetSlider;
  1147. bool measuring = false;
  1148. juce::String pingResult;
  1149. SectionTitle mixerTitle { tr ("Mixer") };
  1150. juce::Label metronomeTrackLabel, metronomeTrackNote;
  1151. juce::ComboBox metronomeTrackBox;
  1152. juce::ToggleButton playTruncated, resetPlugins;
  1153. };
  1154. // ================================================================================================================
  1155. // MIDI
  1156. // ================================================================================================================
  1157. // One input device: on/off, which MIDI channel it listens to, what it plays, and its controller type (FL's Options ›
  1158. // MIDI "Controller type" of the selected input; round 190aw: the controller profiles of core/ControllerProfile.h).
  1159. class MidiInputRow final : public juce::Component
  1160. {
  1161. public:
  1162. // What the Controller type list offers and shows for this device.
  1163. struct Controllers
  1164. {
  1165. std::vector<std::pair<std::string, juce::String>> profiles; // id, name as listed
  1166. juce::String detected; // the profile its port name matches ("" = none)
  1167. juce::String status; // where the feedback goes
  1168. };
  1169. MidiInputRow (const juce::String& deviceName, const prefs::MidiInputPrefs& p, const std::vector<std::string>& channels,
  1170. const Controllers& controllers, std::function<void (const prefs::MidiInputPrefs&)> changed)
  1171. : prefsNow (p), onChange (std::move (changed))
  1172. {
  1173. typeLabel.setText (tr ("Controller type"), juce::dontSendNotification);
  1174. typeLabel.setFont (theme::font (theme::type::small));
  1175. typeLabel.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  1176. addAndMakeVisible (typeLabel);
  1177. // FL's list: "(generic controller)" first, then the device scripts; LYNX adds the automatic choice on top
  1178. type.addItem (controllers.detected.isNotEmpty() ? tr ("Detect automatically ({0})", { controllers.detected })
  1179. : tr ("Detect automatically ({0})", { tr ("Generic controller") }),
  1180. 1);
  1181. type.addItem (tr ("Generic controller"), 2);
  1182. if (! controllers.profiles.empty())
  1183. type.addSeparator();
  1184. auto chosen = p.controller.empty() ? 1 : p.controller == controller::genericChoice ? 2 : 0;
  1185. for (int i = 0; i < (int) controllers.profiles.size(); ++i)
  1186. {
  1187. type.addItem (controllers.profiles[(std::size_t) i].second, i + 3);
  1188. typeIds.push_back (controllers.profiles[(std::size_t) i].first);
  1189. if (p.controller == controllers.profiles[(std::size_t) i].first)
  1190. chosen = i + 3;
  1191. }
  1192. if (chosen == 0) // a profile that is gone (kept; the device runs as a generic controller)
  1193. {
  1194. typeIds.push_back (p.controller);
  1195. chosen = (int) typeIds.size() + 2;
  1196. type.addItem (juce::String::fromUTF8 (p.controller.c_str()), chosen);
  1197. }
  1198. type.setSelectedId (chosen, juce::dontSendNotification);
  1199. type.setTooltip (tr ("A controller profile sets up the device's transport buttons, faders, knobs, pads, lights and display. "
  1200. "Controls you link by hand keep their links."));
  1201. type.onChange = [this] {
  1202. const auto id = type.getSelectedId();
  1203. prefsNow.controller = id <= 1 ? std::string() : id == 2 ? std::string (controller::genericChoice) : typeIds[(std::size_t) (id - 3)];
  1204. update();
  1205. };
  1206. styleCombo (type);
  1207. addAndMakeVisible (type);
  1208. status.setText (controllers.status, juce::dontSendNotification);
  1209. status.setFont (theme::font (theme::type::small));
  1210. status.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  1211. status.setMinimumHorizontalScale (1.0f);
  1212. addAndMakeVisible (status);
  1213. enabled.setButtonText (deviceName);
  1214. enabled.setToggleState (p.enabled, juce::dontSendNotification);
  1215. enabled.onClick = [this] {
  1216. prefsNow.enabled = enabled.getToggleState();
  1217. update();
  1218. };
  1219. addAndMakeVisible (enabled);
  1220. channel.addItem (tr ("Any MIDI channel"), 1);
  1221. for (int c = 1; c <= 16; ++c)
  1222. channel.addItem (tr ("MIDI channel {0}", { juce::String (c) }), c + 1);
  1223. channel.setSelectedId (p.midiChannel + 1, juce::dontSendNotification);
  1224. channel.onChange = [this] {
  1225. prefsNow.midiChannel = channel.getSelectedId() - 1;
  1226. update();
  1227. };
  1228. plays.addItem (tr ("Plays the selected channels"), 1);
  1229. for (int i = 0; i < (int) channels.size(); ++i)
  1230. plays.addItem (tr ("Plays {0}", { juce::String (i + 1) + " " + juce::String::fromUTF8 (channels[(std::size_t) i].c_str()) }), i + 2);
  1231. if (p.target >= (int) channels.size()) // a channel this project doesn't have (kept)
  1232. plays.addItem (tr ("Plays channel {0}", { juce::String (p.target + 1) }), p.target + 2);
  1233. plays.setSelectedId (p.target + 2, juce::dontSendNotification);
  1234. plays.onChange = [this] {
  1235. prefsNow.target = plays.getSelectedId() - 2;
  1236. update();
  1237. };
  1238. for (auto* b : { &channel, &plays })
  1239. {
  1240. styleCombo (*b);
  1241. addAndMakeVisible (b);
  1242. }
  1243. update (false);
  1244. }
  1245. void resized() override
  1246. {
  1247. auto r = getLocalBounds().reduced (8, 4);
  1248. auto top = r.removeFromTop (26);
  1249. plays.setBounds (top.removeFromRight (230));
  1250. top.removeFromRight (8);
  1251. channel.setBounds (top.removeFromRight (150));
  1252. top.removeFromRight (8);
  1253. enabled.setBounds (top);
  1254. r.removeFromTop (4);
  1255. // the second line, as the output rows have: the controller type under the device's name
  1256. auto bottom = r.removeFromTop (26);
  1257. bottom.removeFromLeft (28); // (under the name, past the check box)
  1258. typeLabel.setBounds (bottom.removeFromLeft (110));
  1259. type.setBounds (bottom.removeFromLeft (260));
  1260. bottom.removeFromLeft (10);
  1261. status.setBounds (bottom);
  1262. }
  1263. void paint (juce::Graphics& g) override
  1264. {
  1265. g.setColour (theme::colour::bg1);
  1266. g.fillRoundedRectangle (getLocalBounds().toFloat(), theme::radius::md);
  1267. }
  1268. private:
  1269. void update (bool notify = true)
  1270. {
  1271. channel.setEnabled (prefsNow.enabled);
  1272. plays.setEnabled (prefsNow.enabled);
  1273. type.setEnabled (prefsNow.enabled);
  1274. if (notify && onChange)
  1275. onChange (prefsNow);
  1276. }
  1277. prefs::MidiInputPrefs prefsNow;
  1278. std::function<void (const prefs::MidiInputPrefs&)> onChange;
  1279. juce::ToggleButton enabled;
  1280. juce::ComboBox channel, plays, type;
  1281. juce::Label typeLabel, status;
  1282. std::vector<std::string> typeIds; // [item id − 3] the profile's id
  1283. };
  1284. // One output device (FL's Options › MIDI "Output" panel, round 165f): master sync (MIDI clock or MTC) with its
  1285. // offset, and all notes off on init and after an export.
  1286. class MidiOutputRow final : public juce::Component
  1287. {
  1288. public:
  1289. MidiOutputRow (const juce::String& deviceName, const prefs::MidiOutputPrefs& p, std::function<void (const prefs::MidiOutputPrefs&)> changed)
  1290. : prefsNow (p), onChange (std::move (changed))
  1291. {
  1292. name.setText (deviceName, juce::dontSendNotification);
  1293. name.setFont (theme::font (theme::type::body));
  1294. name.setColour (juce::Label::textColourId, theme::colour::textPrimary);
  1295. addAndMakeVisible (name);
  1296. sync.setButtonText (tr ("Send master sync"));
  1297. sync.setTooltip (tr ("Send master synchronization to this device"));
  1298. sync.setToggleState (p.masterSync, juce::dontSendNotification);
  1299. sync.onClick = [this] {
  1300. prefsNow.masterSync = sync.getToggleState();
  1301. update();
  1302. };
  1303. for (int t = 0; t < midisync::syncTypeCount; ++t)
  1304. type.addItem (tr (midisync::syncTypeName ((midisync::SyncType) t)), t + 1);
  1305. type.setTooltip (tr ("MIDI clock: 24 pulses per quarter note, Start / Continue / Stop and Song Position Pointer. "
  1306. "MTC: MIDI Time Code quarter frames and a full frame when the position moves."));
  1307. type.setSelectedId ((int) midisync::syncTypeFromKey (p.syncType) + 1, juce::dontSendNotification);
  1308. type.onChange = [this] {
  1309. prefsNow.syncType = midisync::syncTypeKey ((midisync::SyncType) (type.getSelectedId() - 1));
  1310. update();
  1311. };
  1312. styleCombo (type);
  1313. offsetLabel.setText (tr ("Offset (ms)"), juce::dontSendNotification);
  1314. offsetLabel.setFont (theme::font (theme::type::small));
  1315. offsetLabel.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  1316. offset.setSliderStyle (juce::Slider::IncDecButtons);
  1317. offset.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 56, 24);
  1318. offset.setRange (-1000.0, 1000.0, 1.0);
  1319. offset.setValue (p.offsetMs, juce::dontSendNotification);
  1320. offset.setTooltip (tr ("Master sync offset (milliseconds): positive sends the sync later, negative earlier"));
  1321. offset.setDoubleClickReturnValue (true, 0.0);
  1322. offset.onValueChange = [this] {
  1323. prefsNow.offsetMs = (int) offset.getValue();
  1324. update();
  1325. };
  1326. notesOff.setButtonText (tr ("Send all notes off"));
  1327. notesOff.setTooltip (tr ("Send all notes off to this device on init and after an export"));
  1328. notesOff.setToggleState (p.allNotesOff, juce::dontSendNotification);
  1329. notesOff.onClick = [this] {
  1330. prefsNow.allNotesOff = notesOff.getToggleState();
  1331. update();
  1332. };
  1333. for (auto* c : std::initializer_list<juce::Component*> { &sync, &type, &offsetLabel, &offset, &notesOff })
  1334. addAndMakeVisible (c);
  1335. update (false);
  1336. }
  1337. void resized() override
  1338. {
  1339. auto r = getLocalBounds().reduced (8, 4);
  1340. auto top = r.removeFromTop (24);
  1341. notesOff.setBounds (top.removeFromRight (170));
  1342. name.setBounds (top);
  1343. r.removeFromTop (4);
  1344. auto bottom = r.removeFromTop (26);
  1345. sync.setBounds (bottom.removeFromLeft (150));
  1346. bottom.removeFromLeft (8);
  1347. type.setBounds (bottom.removeFromLeft (190));
  1348. bottom.removeFromLeft (12);
  1349. offsetLabel.setBounds (bottom.removeFromLeft (76));
  1350. offset.setBounds (bottom.removeFromLeft (110));
  1351. }
  1352. void paint (juce::Graphics& g) override
  1353. {
  1354. g.setColour (theme::colour::bg1);
  1355. g.fillRoundedRectangle (getLocalBounds().toFloat(), theme::radius::md);
  1356. }
  1357. private:
  1358. void update (bool notify = true)
  1359. {
  1360. type.setEnabled (prefsNow.masterSync);
  1361. offset.setEnabled (prefsNow.masterSync);
  1362. if (notify && onChange)
  1363. onChange (prefsNow);
  1364. }
  1365. prefs::MidiOutputPrefs prefsNow;
  1366. std::function<void (const prefs::MidiOutputPrefs&)> onChange;
  1367. juce::Label name, offsetLabel;
  1368. juce::ToggleButton sync, notesOff;
  1369. juce::ComboBox type;
  1370. juce::Slider offset;
  1371. };
  1372. class MidiPage final : public ScrollingPage,
  1373. private juce::ChangeListener,
  1374. private juce::Timer,
  1375. private juce::ListBoxModel
  1376. {
  1377. public:
  1378. MidiPage (AudioEngine& e, SettingsHooks h, bool keep) : engine (e), hooks (std::move (h)), persistent (keep)
  1379. {
  1380. for (auto* c : std::initializer_list<juce::Component*> { &inputsTitle, &notesTitle, &controllersTitle, &inputsNote, &refresh, &noDevices,
  1381. &velocityLabel, &velocityBox, &velocityNote, &perfLabel, &perfBox, &perfNote, &typeLabel, &typeValue, &pickup, &footPedal,
  1382. &pickupNote, &linksLabel, &links, &removeLink, &removeAll, &outputsTitle,
  1383. &outputsNote, &noOutputs, &syncTitle, &clockLabel, &clockBox, &clockOffsetLabel,
  1384. &clockOffset, &clockStatusLabel, &clockStatus, &clockNote, &jumpLabel, &jumpBox,
  1385. &jumpNote, &gamepadToggle, &gamepadNote })
  1386. add (*c);
  1387. styleNote (outputsNote, tr ("Send master sync drives drum machines, synths and other software from LYNX SHARE's transport: MIDI clock "
  1388. "with Song Position Pointer, or MIDI Time Code."));
  1389. styleLabel (noOutputs, tr ("No MIDI output devices found."));
  1390. styleLabel (clockLabel, tr ("External clock sync"));
  1391. clockBox.setTooltip (tr ("LYNX SHARE follows the MIDI clock of this input: its tempo, Start / Continue / Stop and Song Position Pointer"));
  1392. clockBox.onChange = [this] {
  1393. if (loading)
  1394. return;
  1395. auto p = engine.getMidiPrefs();
  1396. const auto id = clockBox.getSelectedId();
  1397. p.clockInput = id > 1 && id - 2 < clockInputs.size() ? clockInputs[id - 2].toStdString() : std::string();
  1398. // (FL asks "The device isn't enabled" → Enable device: the clock input is turned on with it)
  1399. if (! p.clockInput.empty() && ! p.input (p.clockInput).enabled)
  1400. {
  1401. auto in = p.input (p.clockInput);
  1402. in.enabled = true;
  1403. p.setInput (in);
  1404. set (p);
  1405. rebuildInputs();
  1406. return;
  1407. }
  1408. set (p);
  1409. };
  1410. styleCombo (clockBox);
  1411. styleLabel (clockOffsetLabel, tr ("External sync offset (milliseconds)"));
  1412. clockOffset.setSliderStyle (juce::Slider::IncDecButtons);
  1413. clockOffset.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 56, 24);
  1414. clockOffset.setRange (-1000.0, 1000.0, 1.0);
  1415. clockOffset.setDoubleClickReturnValue (true, 0.0);
  1416. clockOffset.setTooltip (tr ("Positive plays LYNX SHARE later than the clock, negative earlier"));
  1417. clockOffset.onValueChange = [this] {
  1418. if (loading)
  1419. return;
  1420. auto p = engine.getMidiPrefs();
  1421. p.clockOffsetMs = (int) clockOffset.getValue();
  1422. set (p);
  1423. };
  1424. styleLabel (clockStatusLabel, tr ("Status"));
  1425. styleLabel (clockStatus, tr ("No clock"), false);
  1426. styleNote (clockNote, tr ("Choosing an input turns it on in Input devices above. Song time will match the clock."));
  1427. startTimerHz (4);
  1428. styleNote (inputsNote, tr ("Each input device can be turned off, listen to one MIDI channel only and play a fixed channel of the "
  1429. "Channel Rack instead of the selected ones."));
  1430. styleLabel (noDevices, tr ("No MIDI input devices found. Connect one and refresh the list."));
  1431. refresh.onClick = [this] {
  1432. if (persistent)
  1433. {
  1434. engine.reloadControllerProfiles(); // (FL's "Update MIDI scripts": the user's profile files are read again)
  1435. engine.reconnectMidiInputs(); // also wakes a device that stopped sending
  1436. }
  1437. rebuildInputs();
  1438. };
  1439. profilesFolder.setTooltip (tr ("Your own controller profiles (*.lynxctl) go here; Refresh device list reads them again"));
  1440. profilesFolder.onClick = [] {
  1441. const auto folder = AudioEngine::controllerProfilesFolder();
  1442. folder.createDirectory();
  1443. folder.revealToUser();
  1444. };
  1445. add (profilesFolder);
  1446. styleLabel (velocityLabel, tr ("Velocity"));
  1447. velocityBox.addItem (tr ("As played"), 1);
  1448. velocityBox.addItem (tr ("Soft (light playing sounds louder)"), 2);
  1449. velocityBox.addItem (tr ("Hard (needs harder playing)"), 3);
  1450. velocityBox.addItem (tr ("Fixed (every note at full velocity)"), 4);
  1451. velocityBox.onChange = [this] {
  1452. auto p = engine.getMidiPrefs();
  1453. p.velocity = (prefs::VelocityCurve) (velocityBox.getSelectedId() - 1);
  1454. set (p);
  1455. };
  1456. styleCombo (velocityBox);
  1457. styleNote (velocityNote, tr ("For notes from MIDI devices (the typing keyboard always plays at the Piano Roll's velocity)."));
  1458. // FL's "MIDI channel used for playlist live mode" (round 165m)
  1459. styleLabel (perfLabel, tr ("Performance mode channel"));
  1460. perfBox.addItem (tr ("Off"), 1);
  1461. for (int c = 1; c <= 16; ++c)
  1462. perfBox.addItem (tr ("Channel") + " " + juce::String (c), c + 1);
  1463. perfBox.onChange = [this] {
  1464. auto p = engine.getMidiPrefs();
  1465. p.performanceChannel = juce::jlimit (0, 16, perfBox.getSelectedId() - 1);
  1466. set (p);
  1467. };
  1468. styleCombo (perfBox);
  1469. styleNote (perfNote, tr ("With Performance mode on, its notes launch the Playlist's clips: an octave per track, a note per clip; "
  1470. "notes 120/121 move the tracks, 122/123 the clips, 124 switches big steps."));
  1471. // FL's Options › MIDI "Song marker jump (MIDI channel)"
  1472. styleLabel (jumpLabel, tr ("Song marker jump"));
  1473. jumpBox.addItem (tr ("Off"), 1);
  1474. for (int c = 1; c <= 16; ++c)
  1475. jumpBox.addItem (tr ("MIDI channel {0}", { juce::String (c) }), c + 1);
  1476. jumpBox.onChange = [this] {
  1477. auto p = engine.getMidiPrefs();
  1478. p.songMarkerJumpChannel = juce::jlimit (0, 16, jumpBox.getSelectedId() - 1);
  1479. set (p);
  1480. };
  1481. styleCombo (jumpBox);
  1482. styleNote (jumpNote, tr ("Notes on this channel move the song to a marker instead of playing: note 0 goes to the first "
  1483. "marker, the next one to the second... (Playlist › Quantize song jumps applies while playing)."));
  1484. // FL's MIDI input panel: "Foot pedal controls note off" (KbHoldSupportBox, on; round 187a)
  1485. styleToggle (footPedal, tr ("Foot pedal controls note off"));
  1486. footPedal.setTooltip (tr ("Disable to send sustain to plugins"));
  1487. footPedal.onClick = [this] {
  1488. auto p = engine.getMidiPrefs();
  1489. p.footPedalNoteOff = footPedal.getToggleState();
  1490. set (p);
  1491. };
  1492. styleLabel (typeLabel, tr ("Controller type"));
  1493. typeLabel.setJustificationType (juce::Justification::topLeft);
  1494. styleLabel (typeValue, tr ("Generic controller: link a knob or fader with a control's right-click menu > Link to MIDI controller."), false);
  1495. typeValue.setMinimumHorizontalScale (1.0f);
  1496. typeValue.setJustificationType (juce::Justification::topLeft);
  1497. styleToggle (pickup, tr ("Pickup (takeover mode)"));
  1498. pickup.onClick = [this] {
  1499. auto p = engine.getMidiPrefs();
  1500. p.pickup = pickup.getToggleState();
  1501. set (p);
  1502. };
  1503. styleNote (pickupNote, tr ("A controller moves a parameter only after reaching its current value, so nothing jumps."));
  1504. // round 184a, S16: a game controller as one more controller (core/GamepadMap.h)
  1505. styleToggle (gamepadToggle, tr ("Use a game controller"));
  1506. gamepadToggle.onClick = [this] {
  1507. auto p = engine.getMidiPrefs();
  1508. p.gamepad = gamepadToggle.getToggleState();
  1509. set (p);
  1510. };
  1511. styleNote (gamepadNote, tr ("A plays and stops, B records, X undoes, the D-pad picks the track and moves by bars, the triggers set the "
  1512. "track's volume. Hold Back to see the whole map. Every button and stick can be linked like a MIDI control."));
  1513. styleLabel (linksLabel, tr ("Links (this project, then global)"));
  1514. linksLabel.setJustificationType (juce::Justification::topLeft);
  1515. links.setModel (this);
  1516. links.setRowHeight (24);
  1517. links.setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
  1518. links.setColour (juce::ListBox::outlineColourId, theme::colour::border);
  1519. links.setOutlineThickness (1);
  1520. removeLink.onClick = [this] {
  1521. const auto row = links.getSelectedRow();
  1522. const auto projectLinks = (int) engine.getSong().midiLinks.size();
  1523. if (juce::isPositiveAndBelow (row, projectLinks))
  1524. engine.editSong ([row] (Song& s) { s.midiLinks.erase (s.midiLinks.begin() + row); });
  1525. else if (const auto global = engine.getGlobalLinks(); juce::isPositiveAndBelow (row - projectLinks, (int) global.size()))
  1526. engine.removeGlobalLink (global[(std::size_t) (row - projectLinks)].target);
  1527. };
  1528. removeAll.onClick = [this] { engine.editSong ([] (Song& s) { s.midiLinks.clear(); }); };
  1529. if (! persistent)
  1530. {
  1531. // --snapshot: devices of a typical setup, and two links
  1532. sampleDevices = { "Mackie Control", "Akai MPD218" }; // (one with a built-in controller profile, one generic)
  1533. sampleOutputs = { "Roland TR-8S", "Korg volca sample" };
  1534. auto p = engine.getMidiPrefs();
  1535. prefs::MidiOutputPrefs drums;
  1536. drums.name = "Roland TR-8S";
  1537. drums.masterSync = true;
  1538. drums.allNotesOff = true;
  1539. p.setOutput (drums);
  1540. p.clockInput = "Akai MPD218";
  1541. engine.setMidiPrefs (p, false);
  1542. engine.editSong ([] (Song& s) {
  1543. AutomationTarget volume;
  1544. volume.kind = AutomationTargetKind::mixerVolume;
  1545. volume.index = 0;
  1546. AutomationTarget pan;
  1547. pan.kind = AutomationTargetKind::channelPan;
  1548. pan.index = 0;
  1549. s.midiLinks = { { 7, -1, volume }, { 10, 0, pan } };
  1550. }, false);
  1551. }
  1552. engine.addChangeListener (this);
  1553. rebuildInputs();
  1554. load();
  1555. timerCallback(); // (the status at once, not after the first tick)
  1556. }
  1557. ~MidiPage() override
  1558. {
  1559. stopTimer();
  1560. engine.removeChangeListener (this);
  1561. }
  1562. private:
  1563. int layout (int width) override
  1564. {
  1565. Rows r (width);
  1566. r.section (inputsTitle, true);
  1567. inputsNote.setBounds (r.full (32).translated (0, -4));
  1568. if (rows.empty())
  1569. noDevices.setBounds (r.full (24));
  1570. for (auto& row : rows)
  1571. row->setBounds (r.full (66).translated (0, -4));
  1572. {
  1573. auto buttons = r.full();
  1574. refresh.setBounds (buttons.removeFromLeft (150));
  1575. buttons.removeFromLeft (8);
  1576. profilesFolder.setBounds (buttons.removeFromLeft (210));
  1577. }
  1578. r.section (outputsTitle);
  1579. outputsNote.setBounds (r.full (32).translated (0, -4));
  1580. if (outputRows.empty())
  1581. noOutputs.setBounds (r.full (24));
  1582. for (auto& row : outputRows)
  1583. row->setBounds (r.full (66).translated (0, -4));
  1584. r.section (syncTitle);
  1585. clockBox.setBounds (r.row (clockLabel, 300));
  1586. clockOffset.setBounds (r.row (clockOffsetLabel, 140));
  1587. clockStatus.setBounds (r.row (clockStatusLabel, 0));
  1588. clockNote.setBounds (r.indented (16).translated (0, -3));
  1589. r.section (notesTitle);
  1590. velocityBox.setBounds (r.row (velocityLabel, 300));
  1591. velocityNote.setBounds (r.indented (16).translated (0, -3));
  1592. perfBox.setBounds (r.row (perfLabel, 300));
  1593. perfNote.setBounds (r.indented (32).translated (0, -3));
  1594. jumpBox.setBounds (r.row (jumpLabel, 300));
  1595. jumpNote.setBounds (r.indented (32).translated (0, -3));
  1596. r.section (controllersTitle);
  1597. typeLabel.setVisible (false); // (round 190aw: the Controller type is each input device's, above, as in FL)
  1598. typeValue.setBounds (r.full (20));
  1599. pickup.setBounds (r.full (24));
  1600. pickupNote.setBounds (r.full (16).translated (0, -3));
  1601. footPedal.setBounds (r.full (24)); // (FL: right under Pickup, round 187a [UI shots/fl d07c])
  1602. gamepadToggle.setBounds (r.full (24));
  1603. gamepadNote.setBounds (r.full (32).translated (0, -3));
  1604. {
  1605. auto row = r.row (linksLabel, 0, 110);
  1606. linksLabel.setBounds (linksLabel.getBounds().withTrimmedTop (4));
  1607. auto buttons = row.removeFromRight (120);
  1608. row.removeFromRight (8);
  1609. links.setBounds (row);
  1610. removeLink.setBounds (buttons.removeFromTop (26));
  1611. buttons.removeFromTop (6);
  1612. removeAll.setBounds (buttons.removeFromTop (26));
  1613. }
  1614. return r.bottom();
  1615. }
  1616. void set (const prefs::MidiPrefs& p)
  1617. {
  1618. if (loading)
  1619. return;
  1620. engine.setMidiPrefs (p, persistent);
  1621. if (hooks.midiChanged)
  1622. hooks.midiChanged();
  1623. }
  1624. // the LYNX extras page switches the game controller too (round 190am)
  1625. void visibilityChanged() override
  1626. {
  1627. if (isVisible())
  1628. gamepadToggle.setToggleState (engine.getMidiPrefs().gamepad, juce::dontSendNotification);
  1629. }
  1630. void load()
  1631. {
  1632. const juce::ScopedValueSetter<bool> guard (loading, true);
  1633. const auto& p = engine.getMidiPrefs();
  1634. velocityBox.setSelectedId ((int) p.velocity + 1, juce::dontSendNotification);
  1635. pickup.setToggleState (p.pickup, juce::dontSendNotification);
  1636. footPedal.setToggleState (p.footPedalNoteOff, juce::dontSendNotification);
  1637. gamepadToggle.setToggleState (p.gamepad, juce::dontSendNotification);
  1638. jumpBox.setSelectedId (p.songMarkerJumpChannel + 1, juce::dontSendNotification);
  1639. perfBox.setSelectedId (p.performanceChannel + 1, juce::dontSendNotification);
  1640. {
  1641. auto id = 1;
  1642. for (int i = 0; i < clockInputs.size(); ++i)
  1643. if (clockInputs[i].toStdString() == p.clockInput)
  1644. id = i + 2;
  1645. clockBox.setSelectedId (id, juce::dontSendNotification);
  1646. }
  1647. clockOffset.setValue (p.clockOffsetMs, juce::dontSendNotification);
  1648. links.updateContent();
  1649. links.repaint();
  1650. removeLink.setEnabled (links.getSelectedRow() >= 0);
  1651. removeAll.setEnabled (! engine.getSong().midiLinks.empty());
  1652. }
  1653. // --snapshot: the sample devices answer on a port of their own name
  1654. static std::string sampleFeedback (const juce::String& input) { return input.toStdString(); }
  1655. // the project's links, then the global ones (settings; FL's "Override global link...", REA round 146)
  1656. int linkRows() const { return (int) (engine.getSong().midiLinks.size() + engine.getGlobalLinks().size()); }
  1657. void rebuildInputs()
  1658. {
  1659. rows.clear();
  1660. juce::StringArray names;
  1661. if (persistent)
  1662. for (const auto& d : juce::MidiInput::getAvailableDevices())
  1663. names.add (d.name);
  1664. else
  1665. names = sampleDevices;
  1666. std::vector<std::string> channels;
  1667. for (const auto& c : engine.getSong().channels)
  1668. channels.push_back (c.name);
  1669. // the controller profiles (round 190aw): FL lists its device scripts with "(user)" after the user's own
  1670. const auto& controllers = engine.getControllers();
  1671. MidiInputRow::Controllers types;
  1672. for (const auto& profile : controllers.library().profiles)
  1673. types.profiles.push_back ({ profile->id, profile->user ? tr ("{0} (user)", { juce::String::fromUTF8 (profile->name.c_str()) })
  1674. : juce::String::fromUTF8 (profile->name.c_str()) });
  1675. std::sort (types.profiles.begin(), types.profiles.end(),
  1676. [] (const auto& a, const auto& b) { return a.second.compareNatural (b.second) < 0; });
  1677. for (const auto& name : names)
  1678. {
  1679. const auto settings = engine.getMidiPrefs().input (name.toStdString());
  1680. const auto detected = controllers.library().detect (name.toStdString());
  1681. types.detected = detected != nullptr ? juce::String::fromUTF8 (detected->name.c_str()) : juce::String();
  1682. types.status = {};
  1683. if (settings.enabled && controllers.library().resolve (settings.controller, name.toStdString()) != nullptr)
  1684. {
  1685. const auto output = persistent ? controllers.outputOf (name.toStdString()) : sampleFeedback (name);
  1686. types.status = output.empty() ? tr ("No output port for its lights and display") : tr ("Feedback to {0}", { juce::String::fromUTF8 (output.c_str()) });
  1687. }
  1688. auto row = std::make_unique<MidiInputRow> (name, settings, channels, types,
  1689. [this] (const prefs::MidiInputPrefs& in) {
  1690. auto p = engine.getMidiPrefs();
  1691. const auto typeChanged = p.input (in.name).controller != in.controller;
  1692. p.setInput (in);
  1693. set (p);
  1694. if (typeChanged) // (the row's status line follows the new type)
  1695. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<MidiPage> (this)] {
  1696. if (safe != nullptr)
  1697. safe->rebuildInputs();
  1698. });
  1699. });
  1700. add (*row);
  1701. rows.push_back (std::move (row));
  1702. }
  1703. noDevices.setVisible (rows.empty());
  1704. // the clock input list: off, then the inputs (a saved one missing now stays listed)
  1705. clockInputs = names;
  1706. if (const auto saved = juce::String::fromUTF8 (engine.getMidiPrefs().clockInput.c_str()); saved.isNotEmpty() && ! clockInputs.contains (saved))
  1707. clockInputs.add (saved);
  1708. clockBox.clear (juce::dontSendNotification);
  1709. clockBox.addItem (tr ("Off"), 1);
  1710. for (int i = 0; i < clockInputs.size(); ++i)
  1711. clockBox.addItem (clockInputs[i], i + 2);
  1712. outputRows.clear();
  1713. juce::StringArray outputs;
  1714. if (persistent)
  1715. for (const auto& d : juce::MidiOutput::getAvailableDevices())
  1716. outputs.add (d.name);
  1717. else
  1718. outputs = sampleOutputs;
  1719. for (const auto& name : outputs)
  1720. {
  1721. auto row = std::make_unique<MidiOutputRow> (name, engine.getMidiPrefs().output (name.toStdString()), [this] (const prefs::MidiOutputPrefs& out) {
  1722. auto p = engine.getMidiPrefs();
  1723. p.setOutput (out);
  1724. set (p);
  1725. });
  1726. add (*row);
  1727. outputRows.push_back (std::move (row));
  1728. }
  1729. noOutputs.setVisible (outputRows.empty());
  1730. load();
  1731. resized();
  1732. }
  1733. void timerCallback() override
  1734. {
  1735. // FL's "Status: off / ready / running [Beat n] / error" (REA 165f), with the tempo received
  1736. const auto& p = engine.getMidiPrefs();
  1737. auto& sync = engine.getMidiSync();
  1738. const auto now = juce::Time::getMillisecondCounterHiRes() * 0.001;
  1739. juce::String text;
  1740. if (p.clockInput.empty())
  1741. text = tr ("Off");
  1742. else if (! persistent)
  1743. text = tr ("Running: beat {0}, {1} BPM", { "17", "120.0" }); // --snapshot
  1744. else if (! engine.getActiveMidiInputs().contains (juce::String::fromUTF8 (p.clockInput.c_str())))
  1745. text = tr ("Error: the input is not open");
  1746. else if (! sync.receiver().receiving (now))
  1747. text = tr ("Ready, no clock");
  1748. else if (sync.receiver().tooFast())
  1749. text = tr ("Clock is too fast!");
  1750. else if (sync.receiver().running())
  1751. text = tr ("Running: beat {0}, {1} BPM", { juce::String ((int) (engine.getTransport().positionInBeats()) + 1),
  1752. juce::String (sync.receiver().bpm(), 1) });
  1753. else
  1754. text = tr ("Receiving clock {0} BPM", { juce::String (sync.receiver().bpm(), 1) });
  1755. if (clockStatus.getText() != text)
  1756. clockStatus.setText (text, juce::dontSendNotification);
  1757. }
  1758. // links list
  1759. int getNumRows() override { return juce::jmax (1, linkRows()); }
  1760. void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
  1761. {
  1762. auto list = engine.getSong().midiLinks;
  1763. const auto projectLinks = (int) list.size();
  1764. for (const auto& l : engine.getGlobalLinks())
  1765. list.push_back (l);
  1766. if (list.empty() || row >= (int) list.size())
  1767. {
  1768. g.setFont (theme::font (theme::type::small));
  1769. g.setColour (theme::colour::textDisabled);
  1770. g.drawText (tr ("(none yet)"), 10, 0, width - 20, height, juce::Justification::centredLeft);
  1771. return;
  1772. }
  1773. if (selected)
  1774. {
  1775. g.setColour (theme::colour::accentMuted);
  1776. g.fillRect (0, 0, width, height);
  1777. }
  1778. const auto& link = list[(std::size_t) row];
  1779. g.setFont (theme::font (theme::type::body));
  1780. g.setColour (theme::colour::info);
  1781. const auto source = "CC " + juce::String (link.cc) + (link.channel >= 0 ? juce::String::fromUTF8 (" \xc2\xb7 ") + tr ("ch. {0}", { juce::String (link.channel + 1) }) : juce::String());
  1782. g.drawText (source, 10, 0, 110, height, juce::Justification::centredLeft);
  1783. g.setColour (theme::colour::textPrimary);
  1784. g.drawText (describeAutomationTarget (engine, link.target) + (row >= projectLinks ? " (" + tr ("global") + ")" : juce::String()), 124, 0,
  1785. width - 134, height, juce::Justification::centredLeft, true);
  1786. }
  1787. void selectedRowsChanged (int) override { removeLink.setEnabled (links.getSelectedRow() >= 0 && linkRows() > 0); }
  1788. void changeListenerCallback (juce::ChangeBroadcaster*) override
  1789. {
  1790. if (engine.getSong().channels.size() != channelCount)
  1791. {
  1792. channelCount = engine.getSong().channels.size();
  1793. rebuildInputs();
  1794. }
  1795. load();
  1796. }
  1797. AudioEngine& engine;
  1798. SettingsHooks hooks;
  1799. bool persistent;
  1800. bool loading = false;
  1801. std::size_t channelCount = 0;
  1802. juce::StringArray sampleDevices;
  1803. std::vector<std::unique_ptr<MidiInputRow>> rows;
  1804. std::vector<std::unique_ptr<MidiOutputRow>> outputRows;
  1805. juce::StringArray sampleOutputs, clockInputs;
  1806. SectionTitle outputsTitle { tr ("Output devices") }, syncTitle { tr ("External sync") };
  1807. juce::Label outputsNote, noOutputs, clockLabel, clockOffsetLabel, clockStatusLabel, clockStatus, clockNote;
  1808. juce::ComboBox clockBox;
  1809. juce::Slider clockOffset;
  1810. SectionTitle inputsTitle { tr ("Input devices") }, notesTitle { tr ("Notes") }, controllersTitle { tr ("Controllers") };
  1811. juce::Label inputsNote, noDevices, velocityLabel, velocityNote, perfLabel, perfNote, typeLabel, typeValue, pickupNote, linksLabel, jumpLabel, jumpNote;
  1812. juce::TextButton refresh { tr ("Refresh device list") }, removeLink { tr ("Remove link") }, removeAll { tr ("Remove all") };
  1813. juce::TextButton profilesFolder { tr ("Controller profiles folder") };
  1814. juce::ComboBox velocityBox, perfBox, jumpBox;
  1815. juce::ToggleButton pickup, footPedal, gamepadToggle;
  1816. juce::Label gamepadNote;
  1817. juce::ListBox links;
  1818. };
  1819. // ================================================================================================================
  1820. // LYNX extras (round 190am)
  1821. // ================================================================================================================
  1822. class ExtrasPage final : public ScrollingPage
  1823. {
  1824. public:
  1825. ExtrasPage (AudioEngine& e, SettingsHooks h, bool keep) : engine (e), hooks (std::move (h)), persistent (keep)
  1826. {
  1827. styleNote (intro, tr ("LYNX's own improvements. All of them are off by default, so LYNX SHARE looks and behaves like FL Studio "
  1828. "until you switch one on. Each switch is the same setting as in the place its line names."));
  1829. intro.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  1830. add (intro);
  1831. std::string_view section;
  1832. for (const auto& item : extras::items)
  1833. {
  1834. if (item.section != section)
  1835. {
  1836. section = item.section;
  1837. titles.push_back (std::make_unique<SectionTitle> (tr (std::string (item.section).c_str())));
  1838. add (*titles.back());
  1839. }
  1840. auto& row = *rows.emplace_back (std::make_unique<Row>());
  1841. row.id = std::string (item.id);
  1842. row.title = titles.back().get();
  1843. styleToggle (row.toggle, tr (std::string (item.title).c_str()));
  1844. row.toggle.setComponentID (juce::String (row.id)); // (--snapshot and tests find a switch by its id)
  1845. row.toggle.onClick = [this, &row] {
  1846. setLynxExtra (engine, hooks, row.id, row.toggle.getToggleState(), persistent);
  1847. refresh(); // (what the app really did, e.g. an action that was refused)
  1848. };
  1849. styleNote (row.note, tr (std::string (item.note).c_str()));
  1850. add (row.toggle);
  1851. add (row.note);
  1852. }
  1853. refresh();
  1854. }
  1855. // another page or a menu may have switched one meanwhile
  1856. void visibilityChanged() override
  1857. {
  1858. if (isVisible())
  1859. refresh();
  1860. }
  1861. int layout (int width) override
  1862. {
  1863. Rows r (width);
  1864. const auto noteFont = theme::font (theme::type::small);
  1865. const auto linesOf = [&noteFont] (const juce::Label& label, int w) {
  1866. juce::AttributedString text (label.getText());
  1867. text.setFont (noteFont);
  1868. juce::TextLayout fitted;
  1869. fitted.createLayout (text, (float) juce::jmax (40, w - 8));
  1870. return juce::jmax (1, fitted.getNumLines());
  1871. };
  1872. intro.setBounds (r.full (4 + 15 * linesOf (intro, r.area.getWidth())));
  1873. const SectionTitle* title = nullptr;
  1874. for (auto& row : rows)
  1875. {
  1876. if (row->title != title)
  1877. {
  1878. r.section (*row->title, title == nullptr);
  1879. title = row->title;
  1880. }
  1881. row->toggle.setBounds (r.full (24));
  1882. const auto noteWidth = r.area.getWidth() - noteIndent;
  1883. const auto noteHeight = 4 + 15 * linesOf (row->note, noteWidth);
  1884. row->note.setBounds (r.full (noteHeight).withTrimmedLeft (noteIndent).translated (0, -5));
  1885. }
  1886. return r.bottom();
  1887. }
  1888. private:
  1889. struct Row
  1890. {
  1891. std::string id;
  1892. SectionTitle* title = nullptr;
  1893. juce::ToggleButton toggle;
  1894. juce::Label note;
  1895. };
  1896. void refresh()
  1897. {
  1898. for (auto& row : rows)
  1899. row->toggle.setToggleState (lynxExtraOn (engine, hooks, row->id), juce::dontSendNotification);
  1900. }
  1901. static constexpr int noteIndent = 27; // under the caption, past the check box
  1902. AudioEngine& engine;
  1903. SettingsHooks hooks;
  1904. bool persistent;
  1905. juce::Label intro;
  1906. std::vector<std::unique_ptr<SectionTitle>> titles;
  1907. std::vector<std::unique_ptr<Row>> rows;
  1908. };
  1909. } // namespace
  1910. bool lynxExtraOn (AudioEngine& engine, const SettingsHooks& hooks, std::string_view id)
  1911. {
  1912. if (id == "mixer.loudness") return MixerStrips::showLoudness;
  1913. if (id == "mixer.usedOnly") return MixerStrips::showUsedOnly;
  1914. if (id == "mixer.keepLostLinks") return MixerStrips::keepLostLinks;
  1915. if (id == "mixer.followPlaylist") return MixerStrips::followPlaylist;
  1916. if (id == "playlist.automationLanes") return autolanes::shown();
  1917. if (id == "pianoRoll.songBarsRuler") return PianoRollComponent::songBarsRuler;
  1918. if (id == "general.hoverValues") return hooks.getGeneral && hooks.getGeneral().hoverValues;
  1919. if (id == "record.lastLoopPassPlays") return engine.getRecordOptions().lastLoopPassPlays;
  1920. if (id == "detail.windowKey") return DetailView::extraWindowKey;
  1921. if (id == "detail.selectInMixer") return DetailView::extraSelectInMixer;
  1922. if (id == "midi.gamepad") return engine.getMidiPrefs().gamepad;
  1923. return false;
  1924. }
  1925. void setLynxExtra (AudioEngine& engine, const SettingsHooks& hooks, std::string_view id, bool on, bool persistent)
  1926. {
  1927. if (lynxExtraOn (engine, hooks, id) == on)
  1928. return;
  1929. const auto saved = [] { // the main window writes ui-options.txt
  1930. if (mixeroptions::changed)
  1931. mixeroptions::changed();
  1932. };
  1933. // a view option with an action: the action is what its menu item runs (it also refreshes the editor and saves)
  1934. const auto toggledBy = [&hooks] (const char* action) { return hooks.runAction && hooks.runAction (action); };
  1935. if (id == "mixer.loudness")
  1936. {
  1937. if (mixeroptions::setShowLoudness)
  1938. mixeroptions::setShowLoudness (on);
  1939. else
  1940. MixerStrips::showLoudness = on;
  1941. saved();
  1942. }
  1943. else if (id == "mixer.usedOnly")
  1944. {
  1945. if (mixeroptions::setShowUsedOnly)
  1946. mixeroptions::setShowUsedOnly (on);
  1947. else
  1948. MixerStrips::showUsedOnly = on;
  1949. saved();
  1950. }
  1951. else if (id == "mixer.keepLostLinks")
  1952. {
  1953. MixerStrips::keepLostLinks = on;
  1954. saved();
  1955. }
  1956. else if (id == "mixer.followPlaylist")
  1957. {
  1958. MixerStrips::followPlaylist = on;
  1959. if (on)
  1960. engine.editSong ([] (Song& s) { mixerops::followPlaylistGroups (s); });
  1961. saved();
  1962. }
  1963. else if (id == "playlist.automationLanes")
  1964. {
  1965. if (! toggledBy ("playlist.automationLanes"))
  1966. {
  1967. autolanes::setShown (on);
  1968. saved();
  1969. }
  1970. }
  1971. else if (id == "pianoRoll.songBarsRuler")
  1972. {
  1973. if (! toggledBy ("pianoRoll.songBarsRuler"))
  1974. {
  1975. PianoRollComponent::songBarsRuler = on;
  1976. saved();
  1977. }
  1978. }
  1979. else if (id == "general.hoverValues")
  1980. {
  1981. if (hooks.getGeneral && hooks.setGeneral)
  1982. {
  1983. auto options = hooks.getGeneral();
  1984. options.hoverValues = on;
  1985. hooks.setGeneral (options);
  1986. }
  1987. }
  1988. else if (id == "record.lastLoopPassPlays")
  1989. {
  1990. auto options = engine.getRecordOptions();
  1991. options.lastLoopPassPlays = on;
  1992. engine.setRecordOptions (options);
  1993. saved();
  1994. }
  1995. else if (id == "detail.windowKey" || id == "detail.selectInMixer")
  1996. {
  1997. (id == "detail.windowKey" ? DetailView::extraWindowKey : DetailView::extraSelectInMixer) = on;
  1998. saved();
  1999. }
  2000. else if (id == "midi.gamepad")
  2001. {
  2002. auto prefs = engine.getMidiPrefs();
  2003. prefs.gamepad = on;
  2004. engine.setMidiPrefs (prefs, persistent);
  2005. if (hooks.midiChanged)
  2006. hooks.midiChanged();
  2007. }
  2008. }
  2009. std::unique_ptr<juce::Component> makeExtrasPage (AudioEngine& engine, const SettingsHooks& hooks, bool persistent)
  2010. {
  2011. return std::make_unique<ExtrasPage> (engine, hooks, persistent);
  2012. }
  2013. std::unique_ptr<juce::Component> makeGeneralPage (AudioEngine& engine, const SettingsHooks& hooks, bool persistent)
  2014. {
  2015. return std::make_unique<GeneralPage> (engine, hooks, persistent);
  2016. }
  2017. std::unique_ptr<juce::Component> makeAudioPage (AudioEngine& engine, bool persistent)
  2018. {
  2019. juce::ignoreUnused (persistent);
  2020. return std::make_unique<AudioPage> (engine);
  2021. }
  2022. std::unique_ptr<juce::Component> makeMidiPage (AudioEngine& engine, const SettingsHooks& hooks, bool persistent)
  2023. {
  2024. return std::make_unique<MidiPage> (engine, hooks, persistent);
  2025. }
  2026. } // namespace lynx