SimpleDock.cpp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  1. #include "ui/SimpleDock.h"
  2. #include <algorithm>
  3. #include <cmath>
  4. #include "core/ChainPresets.h"
  5. #include "core/DetailChain.h"
  6. #include "core/GoalKnobs.h"
  7. #include "core/MixerOps.h"
  8. #include "core/SimpleTracks.h"
  9. #include "core/SoundLibrary.h"
  10. #include "engine/AudioEngine.h"
  11. #include "engine/PluginHost.h"
  12. #include "engine/ProjectFile.h"
  13. #include "platform/Paths.h"
  14. #include "ui/FileChoosers.h"
  15. #include "ui/I18n.h"
  16. #include "ui/MixerComponent.h"
  17. #include "ui/QuickPick.h"
  18. #include "ui/SoundFontEditor.h"
  19. #include "ui/Theme.h"
  20. namespace lynx
  21. {
  22. using namespace theme;
  23. namespace
  24. {
  25. juce::String utf8 (const std::string& s) { return juce::String::fromUTF8 (s.c_str()); }
  26. juce::String glyph (const char* bytes) { return juce::String::fromUTF8 (bytes); }
  27. // geometry (px at 100 %)
  28. constexpr int sideWidth = 212, cardWidth = 148, cardGap = 8, addWidth = 52, titleHeight = 26, pad = 8;
  29. constexpr int rowHeight = 24, categoryWidth = 168;
  30. // Words that mean something else elsewhere in the UI get their own translation here ("Keys" the instruments, not
  31. // the computer's keys; "Punch" the effect, not punch-in recording)
  32. juce::String goalText (int id) { return id == goals::punch ? trc ("@one-knob effect: Punch") : tr (goals::name (id)); }
  33. juce::String soundCategoryText (soundlib::Category c)
  34. {
  35. using C = soundlib::Category;
  36. return c == C::keys ? trc ("@sound category: Keys") : c == C::bass ? trc ("@instrument: Bass") : c == C::lead ? trc ("@sound category: Lead")
  37. : c == C::effects ? trc ("@sound category: Effects") : tr (soundlib::categoryName (c));
  38. }
  39. juce::String chainCategoryText (const char* name)
  40. {
  41. const juce::String n (name);
  42. return n == "Keys" ? trc ("@sound category: Keys") : n == "Bass" ? trc ("@instrument: Bass") : n == "Space" ? trc ("@preset category: Space") : tr (name);
  43. }
  44. juce::String percent (float v) { return juce::String (juce::roundToInt (v * 100.0f)) + " %"; }
  45. juce::String trackTitle (const Song& song, int track)
  46. {
  47. if (track >= 0 && track < (int) song.playlistTracks.size() && ! song.playlistTracks[(std::size_t) track].name.empty())
  48. return utf8 (song.playlistTracks[(std::size_t) track].name);
  49. return tr ("Track {0}", { juce::String (track + 1) });
  50. }
  51. // One rotary control of the dock: a value 0..1 with its text under the ring. Drag up / down (Shift: fine), the wheel,
  52. // the arrow keys; a double click goes back to `resetValue`. While it is dragged it keeps its own value, so the
  53. // song's change messages don't fight the hand.
  54. class DockKnob final : public juce::Component,
  55. public juce::SettableTooltipClient
  56. {
  57. public:
  58. std::function<void (float)> onChange;
  59. std::function<juce::String (float)> valueText;
  60. float resetValue = 0.5f;
  61. bool big = false;
  62. DockKnob()
  63. {
  64. setWantsKeyboardFocus (true);
  65. setMouseCursor (juce::MouseCursor::UpDownResizeCursor);
  66. }
  67. float value() const noexcept { return shown; }
  68. void setValue (float v)
  69. {
  70. v = juce::jlimit (0.0f, 1.0f, v);
  71. if (dragging || std::abs (v - shown) < 1.0e-6f)
  72. return;
  73. shown = v;
  74. repaint();
  75. }
  76. void setDimmed (bool d)
  77. {
  78. if (dimmed != d)
  79. {
  80. dimmed = d;
  81. repaint();
  82. }
  83. }
  84. // the user's move (tests call it as a drag does)
  85. void turnTo (float v)
  86. {
  87. shown = juce::jlimit (0.0f, 1.0f, v);
  88. repaint();
  89. if (onChange)
  90. onChange (shown);
  91. }
  92. void paint (juce::Graphics& g) override
  93. {
  94. auto r = getLocalBounds().toFloat();
  95. const auto textHeight = big ? 20.0f : 16.0f;
  96. const auto text = r.removeFromBottom (textHeight);
  97. const auto d = juce::jmin (r.getWidth(), r.getHeight());
  98. const auto ring = juce::Rectangle<float> (d, d).withCentre (r.getCentre()).reduced (big ? 3.0f : 2.0f);
  99. const bool hot = dragging || isMouseOver() || hasKeyboardFocus (false);
  100. if (big) // a face under the ring, so the one knob reads as the card's control
  101. {
  102. g.setColour (colour::bg0);
  103. g.fillEllipse (ring.reduced (ring.getWidth() * 0.16f));
  104. g.setColour (hot ? colour::borderStrong : colour::border);
  105. g.drawEllipse (ring.reduced (ring.getWidth() * 0.16f), 1.0f);
  106. }
  107. drawKnob (g, ring, shown, false, dimmed ? colour::textDisabled : dragging ? colour::accent : colour::knobArc, hot);
  108. g.setColour (dimmed ? colour::textDisabled : colour::textPrimary);
  109. g.setFont (font (big ? type::body : type::small, big));
  110. g.drawText (valueText ? valueText (shown) : percent (shown), text, juce::Justification::centred, false);
  111. }
  112. void mouseDown (const juce::MouseEvent& e) override
  113. {
  114. if (e.mods.isPopupMenu())
  115. return;
  116. dragging = true;
  117. start = shown;
  118. grabKeyboardFocus();
  119. repaint();
  120. }
  121. void mouseDrag (const juce::MouseEvent& e) override
  122. {
  123. if (! dragging)
  124. return;
  125. const auto span = e.mods.isShiftDown() ? 640.0f : 160.0f;
  126. turnTo (start - (float) e.getDistanceFromDragStartY() / span);
  127. }
  128. void mouseUp (const juce::MouseEvent&) override
  129. {
  130. dragging = false;
  131. repaint();
  132. }
  133. void mouseDoubleClick (const juce::MouseEvent&) override { turnTo (resetValue); }
  134. void mouseWheelMove (const juce::MouseEvent&, const juce::MouseWheelDetails& wheel) override
  135. {
  136. if (std::abs (wheel.deltaY) > 0.0f)
  137. turnTo (shown + (wheel.deltaY > 0.0f ? 0.02f : -0.02f));
  138. }
  139. bool keyPressed (const juce::KeyPress& key) override
  140. {
  141. const auto step = key.getModifiers().isShiftDown() ? 0.01f : 0.05f;
  142. if (key.isKeyCode (juce::KeyPress::upKey) || key.isKeyCode (juce::KeyPress::rightKey))
  143. return turnTo (shown + step), true;
  144. if (key.isKeyCode (juce::KeyPress::downKey) || key.isKeyCode (juce::KeyPress::leftKey))
  145. return turnTo (shown - step), true;
  146. return false;
  147. }
  148. void mouseEnter (const juce::MouseEvent&) override { repaint(); }
  149. void mouseExit (const juce::MouseEvent&) override { repaint(); }
  150. void focusGained (FocusChangeType) override { repaint(); }
  151. void focusLost (FocusChangeType) override { repaint(); }
  152. private:
  153. float shown = 0.0f, start = 0.0f;
  154. bool dragging = false, dimmed = false;
  155. };
  156. // A small flat button of a card's title bar (‹ › ×)
  157. class GlyphButton final : public juce::Button
  158. {
  159. public:
  160. explicit GlyphButton (const juce::String& text) : juce::Button (text) {}
  161. void paintButton (juce::Graphics& g, bool over, bool down) override
  162. {
  163. if (over || down)
  164. fillRoundRect (g, getLocalBounds().toFloat().reduced (1.0f), radius::sm, down ? colour::bg6 : colour::bg5);
  165. g.setColour (! isEnabled() ? colour::textDisabled : over ? colour::textPrimary : colour::textSecondary);
  166. g.setFont (font (type::title));
  167. g.drawText (getName(), getLocalBounds(), juce::Justification::centred, false);
  168. }
  169. };
  170. // The last "card" of the chain: a big + in a dashed frame
  171. class AddCardButton final : public juce::Button
  172. {
  173. public:
  174. AddCardButton() : juce::Button ("+") {}
  175. void paintButton (juce::Graphics& g, bool over, bool down) override
  176. {
  177. const auto r = getLocalBounds().toFloat().reduced (0.5f);
  178. fillRoundRect (g, r, radius::lg, down ? colour::bg4 : over ? colour::bg3 : colour::bg2);
  179. juce::Path frame;
  180. frame.addRoundedRectangle (r.reduced (0.5f), radius::lg);
  181. const float dashes[] { 4.0f, 4.0f };
  182. juce::Path dashed;
  183. juce::PathStrokeType (1.0f).createDashedStroke (dashed, frame, dashes, 2);
  184. g.setColour (! isEnabled() ? colour::border : over ? colour::textSecondary : colour::borderStrong);
  185. g.fillPath (dashed);
  186. const auto c = r.getCentre();
  187. g.setColour (! isEnabled() ? colour::textDisabled : over ? colour::textPrimary : colour::textSecondary);
  188. g.fillRect (juce::Rectangle<float> (18.0f, 2.0f).withCentre (c));
  189. g.fillRect (juce::Rectangle<float> (2.0f, 18.0f).withCentre (c));
  190. }
  191. };
  192. void styleCaption (juce::Label& label, const juce::String& text)
  193. {
  194. label.setText (text, juce::dontSendNotification);
  195. label.setFont (font (type::caption));
  196. label.setColour (juce::Label::textColourId, colour::textSecondary);
  197. label.setInterceptsMouseClicks (false, false);
  198. }
  199. } // namespace
  200. // =====================================================================================================================
  201. // Effects
  202. // =====================================================================================================================
  203. class SimpleDock::EffectsPage final : public juce::Component
  204. {
  205. public:
  206. explicit EffectsPage (AudioEngine& e) : engine (e), slotActions (e)
  207. {
  208. addChildComponent (slotActions); // (never shown: the Mixer slot's own menus, windows and edits on this insert)
  209. slotActions.setMenuTarget (this);
  210. styleCaption (presetCaption, tr ("Preset"));
  211. addAndMakeVisible (presetCaption);
  212. presetButton.setTooltip (tr ("A ready chain of effects for this track"));
  213. presetButton.onClick = [this] { presetMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&presetButton)); };
  214. addAndMakeVisible (presetButton);
  215. saveButton.setButtonText (tr ("Save"));
  216. saveButton.setTooltip (tr ("Keeps this chain as one of your presets"));
  217. saveButton.onClick = [this] { askSaveName(); };
  218. addAndMakeVisible (saveButton);
  219. styleCaption (blendCaption, tr ("Blend"));
  220. addAndMakeVisible (blendCaption);
  221. blend.resetValue = 1.0f;
  222. blend.setTooltip (tr ("How much of the effects you hear: 0 % is the track without them"));
  223. blend.setTitle (tr ("Blend"));
  224. blend.onChange = [this] (float v) {
  225. const auto t = insert;
  226. if (t >= 0)
  227. engine.editSong ([t, v] (Song& s) {
  228. if (t < (int) s.mixer.size())
  229. s.mixer[(std::size_t) t].chainBlend = v;
  230. });
  231. };
  232. addAndMakeVisible (blend);
  233. view.setViewedComponent (&strip, false);
  234. view.setScrollBarsShown (false, true);
  235. view.setScrollBarThickness (8);
  236. addAndMakeVisible (view);
  237. addCard.setTooltip (tr ("Add an effect"));
  238. addCard.onClick = [this] { addMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&addCard)); };
  239. strip.addAndMakeVisible (addCard);
  240. styleCaption (emptyHint, {});
  241. emptyHint.setFont (font (type::body));
  242. emptyHint.setJustificationType (juce::Justification::centredLeft);
  243. strip.addAndMakeVisible (emptyHint);
  244. }
  245. void show (int newInsert)
  246. {
  247. if (insert != newInsert)
  248. {
  249. insert = newInsert;
  250. cards.clear();
  251. view.setViewPosition (0, 0);
  252. }
  253. slotActions.setTrack (juce::jmax (0, insert));
  254. refresh();
  255. }
  256. void refresh()
  257. {
  258. const auto& song = engine.getSong();
  259. const bool has = insert >= 0 && insert < (int) song.mixer.size();
  260. presetButton.setEnabled (has);
  261. blend.setEnabled (has);
  262. addCard.setEnabled (has);
  263. if (! has)
  264. {
  265. cards.clear();
  266. presetButton.setButtonText (tr ("None"));
  267. saveButton.setEnabled (false);
  268. blend.setValue (1.0f);
  269. emptyHint.setText (tr ("Select a track to see its effects."), juce::dontSendNotification);
  270. layoutStrip();
  271. return;
  272. }
  273. const auto& mixer = song.mixer[(std::size_t) insert];
  274. const auto& fx = mixer.effects;
  275. // the cards are kept while the chain has the same shape: a knob being dragged stays the same component
  276. bool same = cards.size() == fx.size();
  277. for (std::size_t i = 0; same && i < fx.size(); ++i)
  278. same = cards[i]->kind == fx[i].kind && cards[i]->goal == (goals::active (fx[i]) ? (int) fx[i].goal : 0);
  279. if (! same)
  280. {
  281. cards.clear();
  282. for (std::size_t i = 0; i < fx.size(); ++i)
  283. {
  284. cards.push_back (std::make_unique<Card> (*this, (int) i));
  285. strip.addAndMakeVisible (*cards.back());
  286. }
  287. }
  288. for (std::size_t i = 0; i < fx.size(); ++i)
  289. cards[i]->update (fx[i], (int) i, (int) fx.size());
  290. auto name = mixer.chainPreset.empty() ? tr ("None") : utf8 (mixer.chainPreset);
  291. if (! mixer.chainPreset.empty() && ! chains::unchanged (song, insert))
  292. name << " " << tr ("(edited)");
  293. presetButton.setButtonText (name + glyph (" \xe2\x96\xbe"));
  294. saveButton.setEnabled (! fx.empty());
  295. blend.setValue (mixer.chainBlend);
  296. blend.setDimmed (fx.empty());
  297. addCard.setEnabled ((int) fx.size() < maxEffectSlots);
  298. emptyHint.setText (fx.empty() ? tr ("No effects yet. Press + to add one, or pick a preset.") : juce::String(), juce::dontSendNotification);
  299. layoutStrip();
  300. }
  301. void resized() override
  302. {
  303. auto r = getLocalBounds().reduced (pad);
  304. auto side = r.removeFromLeft (sideWidth - pad);
  305. presetCaption.setBounds (side.removeFromTop (16));
  306. auto row = side.removeFromTop (26);
  307. saveButton.setBounds (row.removeFromRight (58));
  308. row.removeFromRight (6);
  309. presetButton.setBounds (row);
  310. side.removeFromTop (10);
  311. blendCaption.setBounds (side.removeFromTop (16));
  312. blend.setBounds (side.removeFromTop (juce::jmin (84, side.getHeight())).withWidth (72));
  313. r.removeFromLeft (pad);
  314. view.setBounds (r);
  315. layoutStrip();
  316. }
  317. void paint (juce::Graphics& g) override
  318. {
  319. g.setColour (colour::border);
  320. g.fillRect (sideWidth, pad, 1, getHeight() - 2 * pad);
  321. }
  322. // --- menus ------------------------------------------------------------------------------------------------------
  323. juce::PopupMenu presetMenu()
  324. {
  325. juce::PopupMenu menu;
  326. const auto& song = engine.getSong();
  327. const auto current = insert >= 0 && insert < (int) song.mixer.size() ? song.mixer[(std::size_t) insert].chainPreset : std::string();
  328. auto files = userPresetFolder().findChildFiles (juce::File::findFiles, false, juce::String ("*") + ProjectFile::mixerTrackStateExtension);
  329. files.sort();
  330. // round 190dg: the favourites first, under their own heading (a factory preset or one of the user's)
  331. const auto favs = favouritePresets();
  332. if (! favs.isEmpty())
  333. {
  334. juce::PopupMenu starred;
  335. for (const auto& f : favs)
  336. {
  337. const auto name = f.toStdString();
  338. if (chains::find (name) != nullptr)
  339. starred.addItem (f, true, current == name, [this, name] { applyFactory (name); });
  340. else if (const auto file = userPresetFolder().getChildFile (f + ProjectFile::mixerTrackStateExtension); file.existsAsFile())
  341. starred.addItem (f, true, current == name, [this, file] { loadUserPreset (engine, insert, file); });
  342. }
  343. if (starred.getNumItems() > 0)
  344. {
  345. menu.addSubMenu (glyph ("\xe2\x98\x85 ") + tr ("Favourites"), starred, true, nullptr, favs.contains (utf8 (current)));
  346. menu.addSeparator();
  347. }
  348. }
  349. for (const auto* category : chains::categories())
  350. {
  351. juce::PopupMenu sub;
  352. bool ticked = false;
  353. for (const auto& p : chains::factory())
  354. if (std::string (p.category) == category)
  355. {
  356. const bool on = current == p.name;
  357. ticked = ticked || on;
  358. sub.addItem (utf8 (p.name) + glyph (" \xe2\x80\x94 ") + tr (p.description), true, on, [this, name = std::string (p.name)] { applyFactory (name); });
  359. }
  360. menu.addSubMenu (chainCategoryText (category), sub, true, nullptr, ticked);
  361. }
  362. menu.addSeparator();
  363. juce::PopupMenu mine;
  364. for (const auto& f : files)
  365. mine.addItem (f.getFileNameWithoutExtension(), true, current == f.getFileNameWithoutExtension().toStdString(),
  366. [this, f] { loadUserPreset (engine, insert, f); });
  367. if (files.isEmpty())
  368. mine.addItem (tr ("(none yet)"), false, false, nullptr);
  369. menu.addSubMenu (tr ("My presets"), mine);
  370. menu.addItem (tr ("Save as my preset..."), hasEffects(), false, [this] { askSaveName(); });
  371. if (! current.empty()) // the track's own preset as a favourite (or not any more)
  372. {
  373. const auto shown = utf8 (current);
  374. const bool starred = favs.contains (shown);
  375. menu.addItem (starred ? tr ("Remove \"{0}\" from favourites", { shown }) : tr ("Add \"{0}\" to favourites", { shown }),
  376. [shown, starred] { setFavouritePreset (shown, ! starred); });
  377. }
  378. if (! files.isEmpty()) // (to the system's bin: a preset removed by mistake can be taken back)
  379. {
  380. juce::PopupMenu bin;
  381. for (const auto& f : files)
  382. bin.addItem (f.getFileNameWithoutExtension(), [f] { f.moveToTrash(); });
  383. menu.addSubMenu (tr ("Delete one of my presets"), bin);
  384. }
  385. menu.addSeparator();
  386. menu.addItem (tr ("Remove all effects"), hasEffects(), false, [this] {
  387. const auto t = insert;
  388. engine.editSongStructural ([t] (Song& s) { chains::applyChain (s, t, {}, 1.0f, {}); });
  389. });
  390. return menu;
  391. }
  392. juce::PopupMenu addMenu()
  393. {
  394. juce::PopupMenu menu;
  395. menu.addSectionHeader (tr ("One-knob effects"));
  396. for (int id = 1; id <= goals::count; ++id)
  397. menu.addItem (goalText (id) + glyph (" \xe2\x80\x94 ") + tr (goals::description (id)), [this, id] { addOneKnob (id); });
  398. menu.addSeparator();
  399. menu.addItem (tr ("More effects..."), [this] { slotActions.showAddMenuFor (nextFreeRow()); });
  400. return menu;
  401. }
  402. // --- edits (each through the Mixer's own paths) -------------------------------------------------------------------
  403. void addOneKnob (int goal)
  404. {
  405. const auto t = insert;
  406. if (t < 0)
  407. return;
  408. engine.editSongStructural ([t, goal] (Song& s) {
  409. if (t < (int) s.mixer.size())
  410. detailchain::insertEffectAt (s, t, goals::make (goal), (int) s.mixer[(std::size_t) t].effects.size());
  411. });
  412. }
  413. void turn (int index, bool oneKnob, float v)
  414. {
  415. const auto t = insert;
  416. if (oneKnob)
  417. engine.editSong ([t, index, v] (Song& s) {
  418. if (t >= 0 && t < (int) s.mixer.size() && index < (int) s.mixer[(std::size_t) t].effects.size())
  419. goals::setAmount (s.mixer[(std::size_t) t].effects[(std::size_t) index], v);
  420. });
  421. else
  422. slotActions.setSlotParam (-1, index, v); // the slot's Mix, as the Mixer sets it
  423. }
  424. void toggle (int index)
  425. {
  426. const auto t = insert;
  427. engine.editSong ([t, index] (Song& s) {
  428. if (t >= 0 && t < (int) s.mixer.size() && index < (int) s.mixer[(std::size_t) t].effects.size())
  429. s.mixer[(std::size_t) t].effects[(std::size_t) index].enabled = ! s.mixer[(std::size_t) t].effects[(std::size_t) index].enabled;
  430. });
  431. }
  432. void move (int index, int delta)
  433. {
  434. const auto t = insert;
  435. // (moveEffectBefore: `position` is the card it lands before, counted with the moved card still in place)
  436. const auto position = delta < 0 ? index - 1 : index + 2;
  437. if (position < 0 || position > (int) cards.size())
  438. return;
  439. engine.editSongStructural ([t, index, position] (Song& s) { detailchain::moveEffectBefore (s, t, index, position); });
  440. }
  441. void moveTo (int index, int position)
  442. {
  443. const auto t = insert;
  444. if (position == index || position == index + 1)
  445. return;
  446. engine.editSongStructural ([t, index, position] (Song& s) { detailchain::moveEffectBefore (s, t, index, position); });
  447. }
  448. void remove (int index) { slotActions.deleteSlot (index); }
  449. void openEditor (int index) { slotActions.toggleSlotEditor (index); }
  450. void applyFactory (const std::string& name)
  451. {
  452. const auto t = insert;
  453. if (const auto* preset = chains::find (name); preset != nullptr && t >= 0)
  454. engine.editSongStructural ([t, preset] (Song& s) { chains::apply (s, t, *preset); });
  455. }
  456. void askSaveName()
  457. {
  458. if (! hasEffects())
  459. return;
  460. const auto& mixer = engine.getSong().mixer[(std::size_t) insert];
  461. auto* window = new juce::AlertWindow (tr ("Save as my preset"), tr ("A name for this chain of effects. A preset of yours with the same name is replaced."),
  462. juce::MessageBoxIconType::NoIcon);
  463. const auto factory = chains::find (mixer.chainPreset) != nullptr;
  464. window->addTextEditor ("name", mixer.chainPreset.empty() ? tr ("My preset") : factory ? tr ("{0} (my version)", { utf8 (mixer.chainPreset) }) : utf8 (mixer.chainPreset));
  465. window->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
  466. window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
  467. juce::Component::SafePointer<EffectsPage> safe (this);
  468. window->enterModalState (true, juce::ModalCallbackFunction::create ([window, safe] (int result) {
  469. if (result == 1 && safe != nullptr)
  470. saveUserPreset (safe->engine, safe->insert, window->getTextEditorContents ("name"));
  471. }),
  472. true);
  473. }
  474. // --- dragging a card by its title --------------------------------------------------------------------------------
  475. void dragCard (int index, int stripX)
  476. {
  477. dragging = index;
  478. // the gap the card would land in: before the first card whose middle is right of the pointer
  479. int position = (int) cards.size();
  480. for (int i = 0; i < (int) cards.size(); ++i)
  481. if (stripX < cards[(std::size_t) i]->getBounds().getCentreX())
  482. {
  483. position = i;
  484. break;
  485. }
  486. if (dropAt != position)
  487. {
  488. dropAt = position;
  489. strip.repaint();
  490. }
  491. }
  492. void dropCard()
  493. {
  494. const auto from = dragging, to = dropAt;
  495. dragging = dropAt = -1;
  496. strip.repaint();
  497. if (from >= 0 && to >= 0)
  498. moveTo (from, to);
  499. }
  500. int cardCount() const noexcept { return (int) cards.size(); }
  501. int oneKnobCards() const noexcept
  502. {
  503. return (int) std::count_if (cards.begin(), cards.end(), [] (const auto& c) { return c->goal != 0; });
  504. }
  505. void turnForCheck (int card, float v)
  506. {
  507. if (card >= 0 && card < (int) cards.size())
  508. cards[(std::size_t) card]->knob.turnTo (v);
  509. }
  510. void blendForCheck (float v) { blend.turnTo (v); }
  511. const juce::Component* cardForSnapshot (int card) const
  512. {
  513. return card >= 0 && card < (int) cards.size() ? cards[(std::size_t) card].get() : nullptr;
  514. }
  515. AudioEngine& engine;
  516. int insert = -1;
  517. private:
  518. // One slot of the insert. A one-knob effect shows its goal and one big knob; any other effect its name and its Mix.
  519. class Card final : public juce::Component
  520. {
  521. public:
  522. Card (EffectsPage& o, int i) : owner (o), index (i)
  523. {
  524. knob.big = true;
  525. knob.onChange = [this] (float v) { owner.turn (index, goal != 0, v); };
  526. addAndMakeVisible (knob);
  527. editor.setButtonText (tr ("Editor"));
  528. editor.setTooltip (tr ("Opens the effect's own window with every control"));
  529. editor.onClick = [this] { owner.openEditor (index); };
  530. addAndMakeVisible (editor);
  531. left.setTooltip (tr ("Move earlier in the chain"));
  532. left.onClick = [this] { owner.move (index, -1); };
  533. right.setTooltip (tr ("Move later in the chain"));
  534. right.onClick = [this] { owner.move (index, 1); };
  535. close.setTooltip (tr ("Remove this effect"));
  536. close.onClick = [this] { owner.remove (index); };
  537. for (auto* b : { &left, &right, &close })
  538. addAndMakeVisible (*b);
  539. }
  540. void update (const EffectSlot& slot, int newIndex, int count)
  541. {
  542. index = newIndex;
  543. kind = slot.kind;
  544. goal = goals::active (slot) ? (int) slot.goal : 0;
  545. on = slot.enabled;
  546. const auto effectName = quickpick::slotName (owner.engine, slot);
  547. title = goal != 0 ? goalText (goal) : effectName;
  548. sub = goal != 0 ? effectName : tr ("Mix");
  549. knob.resetValue = goal != 0 ? goals::defaultAmount (goal) : 1.0f;
  550. knob.setValue (goal != 0 ? slot.goalAmount : slot.mix);
  551. knob.setDimmed (! on);
  552. knob.setTitle (title);
  553. knob.setTooltip (goal != 0 ? tr (goals::description (goal)) : tr ("How much of this effect is mixed in"));
  554. left.setEnabled (index > 0);
  555. right.setEnabled (index + 1 < count);
  556. repaint();
  557. }
  558. juce::Rectangle<int> ledBounds() const { return { 8, 7, 12, 12 }; }
  559. void resized() override
  560. {
  561. auto r = getLocalBounds();
  562. auto bar = r.removeFromTop (titleHeight);
  563. close.setBounds (bar.removeFromRight (22).reduced (0, 2));
  564. right.setBounds (bar.removeFromRight (20).reduced (0, 2));
  565. left.setBounds (bar.removeFromRight (20).reduced (0, 2));
  566. r.reduce (pad, 6);
  567. editor.setBounds (r.removeFromBottom (24));
  568. r.removeFromBottom (4);
  569. r.removeFromBottom (16); // (the effect's own name, painted)
  570. knob.setBounds (r.withSizeKeepingCentre (juce::jmin (r.getWidth(), 96), juce::jmin (r.getHeight(), 104)));
  571. }
  572. void paint (juce::Graphics& g) override
  573. {
  574. const auto r = getLocalBounds().toFloat();
  575. fillRoundRect (g, r, radius::lg, colour::bg2);
  576. {
  577. juce::Graphics::ScopedSaveState save (g);
  578. g.reduceClipRegion (getLocalBounds().withHeight (titleHeight));
  579. fillRoundRect (g, r.withHeight ((float) titleHeight + radius::lg), radius::lg, colour::bg3);
  580. }
  581. g.setColour (owner.dragging == index ? colour::accent : colour::border);
  582. g.drawRoundedRectangle (r.reduced (0.5f), radius::lg, 1.0f);
  583. g.setColour (on ? colour::accent : colour::ledOff);
  584. g.fillEllipse (ledBounds().toFloat());
  585. if (ledHover)
  586. {
  587. g.setColour (colour::textPrimary.withAlpha (0.6f));
  588. g.drawEllipse (ledBounds().toFloat().expanded (1.5f), 1.0f);
  589. }
  590. g.setColour (on ? colour::textPrimary : colour::textSecondary);
  591. g.setFont (font (type::body, true));
  592. g.drawText (title, juce::Rectangle<int> (26, 0, left.getX() - 28, titleHeight), juce::Justification::centredLeft, true);
  593. g.setColour (colour::textSecondary);
  594. g.setFont (font (type::caption));
  595. g.drawText (sub, juce::Rectangle<int> (pad, editor.getY() - 20, getWidth() - 2 * pad, 16), juce::Justification::centred, true);
  596. }
  597. void mouseMove (const juce::MouseEvent& e) override
  598. {
  599. const bool over = ledBounds().expanded (3).contains (e.getPosition());
  600. if (over != ledHover)
  601. {
  602. ledHover = over;
  603. repaint();
  604. }
  605. setMouseCursor (! over && e.y < titleHeight ? juce::MouseCursor::DraggingHandCursor : juce::MouseCursor::NormalCursor);
  606. }
  607. void mouseExit (const juce::MouseEvent&) override
  608. {
  609. ledHover = false;
  610. repaint();
  611. }
  612. void mouseDown (const juce::MouseEvent& e) override
  613. {
  614. pressedLed = ledBounds().expanded (3).contains (e.getPosition());
  615. pressedTitle = ! pressedLed && e.y < titleHeight;
  616. }
  617. void mouseDrag (const juce::MouseEvent& e) override
  618. {
  619. if (pressedTitle && e.getDistanceFromDragStart() > 5)
  620. owner.dragCard (index, e.getEventRelativeTo (getParentComponent()).x);
  621. }
  622. void mouseUp (const juce::MouseEvent& e) override
  623. {
  624. if (owner.dragging == index)
  625. owner.dropCard();
  626. else if (pressedLed && ledBounds().expanded (3).contains (e.getPosition()))
  627. owner.toggle (index);
  628. pressedLed = pressedTitle = false;
  629. }
  630. void mouseDoubleClick (const juce::MouseEvent& e) override
  631. {
  632. if (e.y < titleHeight && ! ledBounds().expanded (3).contains (e.getPosition()))
  633. owner.openEditor (index);
  634. }
  635. EffectsPage& owner;
  636. int index = 0, goal = 0;
  637. EffectKind kind = EffectKind::eq;
  638. bool on = true, ledHover = false, pressedLed = false, pressedTitle = false;
  639. juce::String title, sub;
  640. DockKnob knob;
  641. juce::TextButton editor;
  642. GlyphButton left { glyph ("\xe2\x80\xb9") }, right { glyph ("\xe2\x80\xba") }, close { glyph ("\xc3\x97") };
  643. };
  644. // The row of cards (inside the viewport): it paints the drop mark while a card is dragged
  645. class Strip final : public juce::Component
  646. {
  647. public:
  648. explicit Strip (EffectsPage& o) : owner (o) {}
  649. void paintOverChildren (juce::Graphics& g) override
  650. {
  651. if (owner.dragging < 0 || owner.dropAt < 0)
  652. return;
  653. const auto x = owner.dropAt < (int) owner.cards.size() ? owner.cards[(std::size_t) owner.dropAt]->getX() - cardGap / 2
  654. : owner.addCard.getX() - cardGap / 2;
  655. g.setColour (colour::accent);
  656. g.fillRect (x - 1, 0, 2, getHeight());
  657. }
  658. EffectsPage& owner;
  659. };
  660. void layoutStrip()
  661. {
  662. const auto h = juce::jmax (40, view.getHeight() - (view.isHorizontalScrollBarShown() ? view.getScrollBarThickness() : 0));
  663. int x = 0;
  664. for (auto& c : cards)
  665. {
  666. c->setBounds (x, 0, cardWidth, h);
  667. x += cardWidth + cardGap;
  668. }
  669. addCard.setBounds (x, 0, addWidth, h);
  670. x += addWidth;
  671. const auto hintWidth = emptyHint.getText().isEmpty() ? 0 : 360;
  672. emptyHint.setBounds (x + 12, 0, hintWidth, h);
  673. strip.setSize (juce::jmax (view.getWidth(), x + (hintWidth > 0 ? hintWidth + 12 : 0)), h);
  674. }
  675. bool hasEffects() const
  676. {
  677. const auto& song = engine.getSong();
  678. return insert >= 0 && insert < (int) song.mixer.size() && ! song.mixer[(std::size_t) insert].effects.empty();
  679. }
  680. int nextFreeRow() const
  681. {
  682. const auto& song = engine.getSong();
  683. if (insert < 0 || insert >= (int) song.mixer.size())
  684. return 0;
  685. const auto& fx = song.mixer[(std::size_t) insert].effects;
  686. const auto rows = mixerops::effectRows (fx);
  687. for (int r = rows.empty() ? 0 : rows.back() + 1; r < maxEffectSlots; ++r)
  688. if (mixerops::effectAtRow (fx, r) < 0)
  689. return r;
  690. for (int r = 0; r < maxEffectSlots; ++r)
  691. if (mixerops::effectAtRow (fx, r) < 0)
  692. return r;
  693. return 0;
  694. }
  695. EffectsPanel slotActions;
  696. juce::Label presetCaption, blendCaption, emptyHint;
  697. juce::TextButton presetButton, saveButton;
  698. AddCardButton addCard;
  699. DockKnob blend;
  700. juce::Viewport view;
  701. Strip strip { *this };
  702. std::vector<std::unique_ptr<Card>> cards;
  703. int dragging = -1, dropAt = -1;
  704. };
  705. // =====================================================================================================================
  706. // Instrument
  707. // =====================================================================================================================
  708. class SimpleDock::InstrumentPage final : public juce::Component,
  709. private juce::Timer
  710. {
  711. public:
  712. InstrumentPage (AudioEngine& e, Hooks& h) : engine (e), hooks (h), categoryModel (*this), soundModel (*this)
  713. {
  714. styleCaption (soundCaption, tr ("Sound"));
  715. addAndMakeVisible (soundCaption);
  716. prev.setTooltip (tr ("Previous sound"));
  717. prev.onClick = [this] { stepSound (-1); };
  718. next.setTooltip (tr ("Next sound"));
  719. next.onClick = [this] { stepSound (1); };
  720. addAndMakeVisible (prev);
  721. addAndMakeVisible (next);
  722. name.setFont (font (type::title, true));
  723. name.setColour (juce::Label::textColourId, colour::textPrimary);
  724. name.setJustificationType (juce::Justification::centred);
  725. name.setMinimumHorizontalScale (0.7f);
  726. addAndMakeVisible (name);
  727. styleCaption (detail, {});
  728. detail.setJustificationType (juce::Justification::centred);
  729. addAndMakeVisible (detail);
  730. editorButton.setButtonText (tr ("Open full editor"));
  731. editorButton.setTooltip (tr ("Opens the instrument's own window with every control"));
  732. editorButton.onClick = [this] {
  733. if (channel >= 0 && hooks.toggleChannelWindow)
  734. hooks.toggleChannelWindow (channel);
  735. };
  736. addAndMakeVisible (editorButton);
  737. keysButton.setButtonText (tr ("Keyboard"));
  738. keysButton.setTooltip (tr ("Shows the on-screen keyboard to play this track"));
  739. keysButton.onClick = [this] {
  740. if (hooks.showKeys)
  741. hooks.showKeys();
  742. };
  743. addAndMakeVisible (keysButton);
  744. search.setTextToShowWhenEmpty (tr ("Search sounds"), colour::textDisabled);
  745. search.onTextChange = [this] { refilter(); };
  746. search.setTitle (tr ("Search sounds"));
  747. addAndMakeVisible (search);
  748. ownButton.setButtonText (tr ("LYNX sounds"));
  749. fontsButton.setButtonText (tr ("My SoundFonts"));
  750. fontsButton.setTooltip (tr ("The sounds of your own .sf2 and .sf3 files"));
  751. pluginsButton.setButtonText (tr ("My plugins"));
  752. pluginsButton.setTooltip (tr ("The instrument plugins installed on this computer"));
  753. for (auto* b : { &ownButton, &fontsButton, &pluginsButton })
  754. {
  755. b->setClickingTogglesState (true);
  756. b->setRadioGroupId (1902);
  757. addAndMakeVisible (*b);
  758. }
  759. ownButton.setConnectedEdges (juce::Button::ConnectedOnRight);
  760. fontsButton.setConnectedEdges (juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight);
  761. pluginsButton.setConnectedEdges (juce::Button::ConnectedOnLeft);
  762. ownButton.setToggleState (true, juce::dontSendNotification);
  763. ownButton.onClick = [this] {
  764. if (ownButton.getToggleState())
  765. setSource (From::own);
  766. };
  767. fontsButton.onClick = [this] {
  768. if (fontsButton.getToggleState())
  769. setSource (From::fonts);
  770. };
  771. pluginsButton.onClick = [this] {
  772. if (pluginsButton.getToggleState())
  773. setSource (From::plugins);
  774. };
  775. folderButton.setButtonText (tr ("Add folder..."));
  776. folderButton.setTooltip (tr ("Adds a folder with your SoundFont files to the list"));
  777. folderButton.onClick = [this] { addFolder(); };
  778. addChildComponent (folderButton);
  779. categories.setModel (&categoryModel);
  780. categories.setRowHeight (rowHeight);
  781. categories.setColour (juce::ListBox::backgroundColourId, colour::bg1);
  782. categories.setTitle (tr ("Category"));
  783. addAndMakeVisible (categories);
  784. sounds.setModel (&soundModel);
  785. sounds.setRowHeight (rowHeight);
  786. sounds.setColour (juce::ListBox::backgroundColourId, colour::bg1);
  787. sounds.setTitle (tr ("Sounds"));
  788. addAndMakeVisible (sounds);
  789. styleCaption (listHint, {});
  790. listHint.setFont (font (type::body));
  791. listHint.setJustificationType (juce::Justification::centred);
  792. addChildComponent (listHint);
  793. }
  794. ~InstrumentPage() override { stopTimer(); }
  795. void show (int newChannel)
  796. {
  797. channel = newChannel;
  798. refresh();
  799. }
  800. void refresh()
  801. {
  802. if (! isVisible()) // (the Effects tab is in front: nothing of the list is worked out until it shows)
  803. {
  804. stale = true;
  805. return;
  806. }
  807. stale = false;
  808. const auto& song = engine.getSong();
  809. const bool has = channel >= 0 && channel < (int) song.channels.size();
  810. prev.setEnabled (has);
  811. next.setEnabled (has);
  812. editorButton.setEnabled (has);
  813. if (! has)
  814. {
  815. name.setText ({}, juce::dontSendNotification);
  816. detail.setText ({}, juce::dontSendNotification);
  817. current = -1;
  818. sounds.repaint();
  819. return;
  820. }
  821. const auto& def = song.channels[(std::size_t) channel];
  822. // which sound of the list the channel plays (looked up again only when its instrument changed)
  823. if (! known || ! soundlib::sameSound (lastDef, def) || lastListSize != list().size())
  824. {
  825. current = soundlib::find (list(), def);
  826. currentOwn = from != From::own ? soundlib::find (soundlib::builtIn(), def) : current;
  827. lastDef = def;
  828. lastListSize = list().size();
  829. known = true;
  830. }
  831. const soundlib::Sound* sound = current >= 0 ? &list()[(std::size_t) current]
  832. : currentOwn >= 0 ? &soundlib::builtIn()[(std::size_t) currentOwn] : nullptr;
  833. if (sound != nullptr)
  834. {
  835. name.setText (utf8 (sound->name), juce::dontSendNotification);
  836. detail.setText (soundCategoryText (sound->category) + glyph (" \xc2\xb7 ") + utf8 (sound->origin), juce::dontSendNotification);
  837. }
  838. else
  839. {
  840. name.setText (utf8 (def.name), juce::dontSendNotification);
  841. detail.setText (tr ("Its own sound"), juce::dontSendNotification);
  842. }
  843. if (current >= 0 && ! categoryPicked)
  844. category = (int) list()[(std::size_t) current].category;
  845. else if (! categoryPicked && soundlib::filter (list(), (soundlib::Category) category).empty())
  846. for (int c = 0; c < (int) soundlib::Category::count; ++c) // (the first category this list has sounds in)
  847. if (! soundlib::filter (list(), (soundlib::Category) c).empty())
  848. {
  849. category = c;
  850. break;
  851. }
  852. refilter();
  853. }
  854. void resized() override
  855. {
  856. auto r = getLocalBounds().reduced (pad);
  857. auto side = r.removeFromLeft (sideWidth - pad);
  858. soundCaption.setBounds (side.removeFromTop (16));
  859. auto row = side.removeFromTop (30);
  860. prev.setBounds (row.removeFromLeft (26));
  861. next.setBounds (row.removeFromRight (26));
  862. name.setBounds (row);
  863. detail.setBounds (side.removeFromTop (18));
  864. side.removeFromTop (8);
  865. editorButton.setBounds (side.removeFromTop (26));
  866. side.removeFromTop (6);
  867. keysButton.setBounds (side.removeFromTop (26));
  868. r.removeFromLeft (pad + 1 + pad);
  869. auto top = r.removeFromTop (26);
  870. ownButton.setBounds (top.removeFromLeft (juce::jmin (120, top.getWidth() / 5)));
  871. fontsButton.setBounds (top.removeFromLeft (juce::jmin (130, top.getWidth() / 4)));
  872. pluginsButton.setBounds (top.removeFromLeft (juce::jmin (110, top.getWidth() / 3)));
  873. top.removeFromLeft (pad);
  874. if (folderButton.isVisible())
  875. {
  876. folderButton.setBounds (top.removeFromRight (juce::jmin (130, top.getWidth() / 3)));
  877. top.removeFromRight (pad);
  878. }
  879. search.setBounds (top.withWidth (juce::jmin (top.getWidth(), 280)));
  880. r.removeFromTop (6);
  881. categories.setBounds (r.removeFromLeft (juce::jmin (categoryWidth, r.getWidth() / 3)));
  882. r.removeFromLeft (6);
  883. sounds.setBounds (r);
  884. listHint.setBounds (r.reduced (12));
  885. }
  886. void paint (juce::Graphics& g) override
  887. {
  888. g.setColour (colour::border);
  889. g.fillRect (sideWidth, pad, 1, getHeight() - 2 * pad);
  890. }
  891. void visibilityChanged() override
  892. {
  893. if (isVisible() && stale)
  894. refresh();
  895. updateTimer();
  896. }
  897. void parentHierarchyChanged() override { updateTimer(); }
  898. // --- the list ----------------------------------------------------------------------------------------------------
  899. enum class From { own, fonts, plugins };
  900. const std::vector<soundlib::Sound>& list() const
  901. {
  902. return from == From::fonts ? fontSounds : from == From::plugins ? pluginSounds : soundlib::builtIn();
  903. }
  904. void setSource (From source)
  905. {
  906. from = source;
  907. fonts = from == From::fonts;
  908. (from == From::fonts ? fontsButton : from == From::plugins ? pluginsButton : ownButton).setToggleState (true, juce::dontSendNotification);
  909. folderButton.setVisible (fonts);
  910. if (fonts && ! injected)
  911. {
  912. ensureSoundFontIndex();
  913. takeFonts();
  914. }
  915. if (from == From::plugins && ! pluginsInjected)
  916. takePlugins();
  917. known = false;
  918. categoryPicked = false;
  919. resized();
  920. refresh();
  921. updateTimer();
  922. }
  923. void setFonts (std::vector<sf::IndexedFont> indexed, bool inject)
  924. {
  925. injected = inject;
  926. fontSounds = soundlib::fromFonts (indexed);
  927. known = false;
  928. }
  929. void pickCategory (int c)
  930. {
  931. category = juce::jlimit (0, (int) soundlib::Category::count - 1, c);
  932. categoryPicked = true;
  933. refilter();
  934. }
  935. void refilter()
  936. {
  937. rows = soundlib::filter (list(), (soundlib::Category) category, search.getText().toStdString());
  938. counts.assign ((std::size_t) soundlib::Category::count, 0);
  939. for (int c = 0; c < (int) soundlib::Category::count; ++c)
  940. counts[(std::size_t) c] = (int) soundlib::filter (list(), (soundlib::Category) c, search.getText().toStdString()).size();
  941. // the categories this source has sounds in (a search greys the ones without a match, it doesn't remove them)
  942. shownCategories.clear();
  943. for (int c = 0; c < (int) soundlib::Category::count; ++c)
  944. if (! soundlib::filter (list(), (soundlib::Category) c).empty())
  945. shownCategories.push_back (c);
  946. categories.updateContent();
  947. const auto shown = std::find (shownCategories.begin(), shownCategories.end(), category);
  948. if (shown != shownCategories.end())
  949. categories.selectRow ((int) (shown - shownCategories.begin()), true, true);
  950. else
  951. categories.deselectAllRows();
  952. categories.repaint();
  953. sounds.updateContent();
  954. const auto it = std::find (rows.begin(), rows.end(), current);
  955. if (it != rows.end())
  956. sounds.selectRow ((int) (it - rows.begin()), true, true);
  957. else
  958. sounds.deselectAllRows();
  959. sounds.repaint();
  960. const bool noFonts = fonts && fontSounds.empty();
  961. const bool noPlugins = from == From::plugins && pluginSounds.empty();
  962. listHint.setVisible (noFonts || noPlugins || rows.empty());
  963. listHint.setText (noFonts ? (sf::PresetIndex::shared().busy() && ! injected
  964. ? tr ("Looking for your SoundFont files...")
  965. : tr ("No SoundFont files found yet. Add a folder with your .sf2 or .sf3 files."))
  966. : noPlugins ? tr ("No instrument plugins found yet. Scan for plugins in the Plugin manager.")
  967. : rows.empty() ? tr ("No sounds here.") : juce::String(),
  968. juce::dontSendNotification);
  969. }
  970. // --- picking and hearing -----------------------------------------------------------------------------------------
  971. bool audition (const soundlib::Sound& s)
  972. {
  973. const auto def = soundlib::channelFor (s);
  974. return def && engine.auditionSound (*def, soundlib::auditionKeys (s));
  975. }
  976. void pick (int listIndex, bool hear)
  977. {
  978. if (listIndex < 0 || listIndex >= (int) list().size() || channel < 0)
  979. return;
  980. const auto sound = list()[(std::size_t) listIndex];
  981. const auto c = channel;
  982. bool done = false;
  983. engine.editSongStructural ([c, &sound, &done] (Song& s) {
  984. if (c >= (int) s.channels.size())
  985. return;
  986. if (auto next = soundlib::withSound (s.channels[(std::size_t) c], sound))
  987. {
  988. s.channels[(std::size_t) c] = std::move (*next);
  989. done = true;
  990. }
  991. });
  992. if (done && hear)
  993. {
  994. if (sound.source == soundlib::Source::plugin) // (heard on the track itself, as it loaded)
  995. engine.auditionChannelSound (c);
  996. else
  997. audition (sound);
  998. }
  999. }
  1000. void stepSound (int delta)
  1001. {
  1002. const auto fallback = (soundlib::Category) category;
  1003. const auto to = soundlib::step (list(), current, delta, fallback);
  1004. if (to >= 0)
  1005. {
  1006. categoryPicked = false;
  1007. pick (to, true);
  1008. }
  1009. }
  1010. void clickRow (int row, bool previewOnly)
  1011. {
  1012. if (row < 0 || row >= (int) rows.size())
  1013. return;
  1014. // (a plugin can only be heard once it runs on the track: its ▶ uses it too, and Ctrl+Z goes back)
  1015. if (previewOnly && list()[(std::size_t) rows[(std::size_t) row]].source != soundlib::Source::plugin)
  1016. audition (list()[(std::size_t) rows[(std::size_t) row]]);
  1017. else
  1018. pick (rows[(std::size_t) row], true);
  1019. }
  1020. int rowCount() const noexcept { return (int) rows.size(); }
  1021. void searchFor (const juce::String& text)
  1022. {
  1023. search.setText (text, false);
  1024. refilter(); // (what typing does, at once: the editor's own change message is posted)
  1025. }
  1026. juce::String shownName() const { return name.getText() + " [" + detail.getText() + "]"; }
  1027. AudioEngine& engine;
  1028. Hooks& hooks;
  1029. int channel = -1;
  1030. private:
  1031. struct CategoryModel final : juce::ListBoxModel
  1032. {
  1033. explicit CategoryModel (InstrumentPage& p) : page (p) {}
  1034. int getNumRows() override { return (int) page.shownCategories.size(); }
  1035. void paintListBoxItem (int index, juce::Graphics& g, int width, int height, bool selected) override
  1036. {
  1037. if (index < 0 || index >= (int) page.shownCategories.size())
  1038. return;
  1039. const auto row = page.shownCategories[(std::size_t) index];
  1040. const auto n = row < (int) page.counts.size() ? page.counts[(std::size_t) row] : 0;
  1041. if (selected)
  1042. fillRoundRect (g, juce::Rectangle<float> (0.0f, 1.0f, (float) width, (float) height - 2.0f), radius::sm, colour::accentMuted);
  1043. g.setColour (n == 0 ? colour::textDisabled : selected ? colour::textPrimary : colour::textSecondary);
  1044. g.setFont (font (type::body, selected));
  1045. g.drawText (soundCategoryText ((soundlib::Category) row), 10, 0, width - 50, height, juce::Justification::centredLeft, true);
  1046. g.setColour (colour::textDisabled);
  1047. g.setFont (font (type::caption));
  1048. g.drawText (juce::String (n), width - 40, 0, 32, height, juce::Justification::centredRight, false);
  1049. }
  1050. void selectedRowsChanged (int index) override
  1051. {
  1052. if (index >= 0 && index < (int) page.shownCategories.size() && page.shownCategories[(std::size_t) index] != page.category)
  1053. page.pickCategory (page.shownCategories[(std::size_t) index]);
  1054. }
  1055. juce::String getNameForRow (int index) override
  1056. {
  1057. return index >= 0 && index < (int) page.shownCategories.size() ? soundCategoryText ((soundlib::Category) page.shownCategories[(std::size_t) index])
  1058. : juce::String();
  1059. }
  1060. InstrumentPage& page;
  1061. };
  1062. struct SoundModel final : juce::ListBoxModel
  1063. {
  1064. explicit SoundModel (InstrumentPage& p) : page (p) {}
  1065. int getNumRows() override { return (int) page.rows.size(); }
  1066. void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool) override
  1067. {
  1068. if (row < 0 || row >= (int) page.rows.size())
  1069. return;
  1070. const auto index = page.rows[(std::size_t) row];
  1071. const auto& s = page.list()[(std::size_t) index];
  1072. const bool isCurrent = index == page.current;
  1073. if (isCurrent)
  1074. fillRoundRect (g, juce::Rectangle<float> (0.0f, 1.0f, (float) width, (float) height - 2.0f), radius::sm, colour::accentMuted);
  1075. else if (row % 2 == 1)
  1076. g.fillAll (colour::bg2.withAlpha (0.5f));
  1077. // ▶: hear it without choosing it
  1078. juce::Path play;
  1079. const auto cx = 15.0f, cy = (float) height * 0.5f;
  1080. play.addTriangle (cx - 4.0f, cy - 5.5f, cx - 4.0f, cy + 5.5f, cx + 5.5f, cy);
  1081. g.setColour (isCurrent ? colour::accent : colour::textSecondary);
  1082. g.fillPath (play);
  1083. g.setColour (isCurrent ? colour::textPrimary : colour::textPrimary.withAlpha (0.9f));
  1084. g.setFont (font (type::body, isCurrent));
  1085. const auto originWidth = juce::jmin (180, width / 3);
  1086. g.drawText (utf8 (s.name), 32, 0, width - 40 - originWidth, height, juce::Justification::centredLeft, true);
  1087. g.setColour (colour::textSecondary);
  1088. g.setFont (font (type::small));
  1089. g.drawText (utf8 (s.origin), width - originWidth - 8, 0, originWidth, height, juce::Justification::centredRight, true);
  1090. }
  1091. void listBoxItemClicked (int row, const juce::MouseEvent& e) override { page.clickRow (row, e.x < 30); }
  1092. void returnKeyPressed (int row) override { page.clickRow (row, false); }
  1093. juce::String getNameForRow (int row) override
  1094. {
  1095. return row >= 0 && row < (int) page.rows.size() ? utf8 (page.list()[(std::size_t) page.rows[(std::size_t) row]].name) : juce::String();
  1096. }
  1097. juce::String getTooltipForRow (int) override
  1098. {
  1099. return page.from == From::plugins ? tr ("Click to load this plugin on the track and hear it (Ctrl+Z goes back)")
  1100. : tr ("Click to use this sound; the arrow plays it without choosing it");
  1101. }
  1102. InstrumentPage& page;
  1103. };
  1104. // the plugin host's scanned instruments (the list the plugin picker shows)
  1105. void takePlugins()
  1106. {
  1107. std::vector<soundlib::InstalledPlugin> installed;
  1108. for (const auto& t : engine.getPluginHost().getKnownPlugins().getTypes())
  1109. if (t.isInstrument)
  1110. installed.push_back ({ t.createIdentifierString().toStdString(), t.name.toStdString(), t.manufacturerName.toStdString(),
  1111. t.pluginFormatName.toStdString(), t.category.toStdString() });
  1112. pluginSounds = soundlib::fromPlugins (installed);
  1113. known = false;
  1114. }
  1115. public:
  1116. void setPlugins (std::vector<soundlib::InstalledPlugin> installed)
  1117. {
  1118. pluginsInjected = true;
  1119. pluginSounds = soundlib::fromPlugins (installed);
  1120. known = false;
  1121. }
  1122. private:
  1123. void takeFonts()
  1124. {
  1125. auto& index = sf::PresetIndex::shared();
  1126. generation = index.generation();
  1127. fontSounds = soundlib::fromFonts (index.fonts());
  1128. known = false;
  1129. }
  1130. // the SoundFont index fills in the background: follow it only while its list is on screen
  1131. void updateTimer()
  1132. {
  1133. if (fonts && ! injected && isShowing())
  1134. startTimer (500);
  1135. else
  1136. stopTimer();
  1137. }
  1138. void timerCallback() override
  1139. {
  1140. if (sf::PresetIndex::shared().generation() != generation)
  1141. {
  1142. takeFonts();
  1143. refresh();
  1144. }
  1145. }
  1146. void addFolder()
  1147. {
  1148. chooser = lynx::ui::makeFileChooser (tr ("Add a SoundFont folder"), juce::File::getSpecialLocation (juce::File::userDocumentsDirectory));
  1149. juce::Component::SafePointer<InstrumentPage> safe (this);
  1150. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
  1151. [safe] (const juce::FileChooser& fc) {
  1152. if (fc.getResult() == juce::File())
  1153. return;
  1154. // (the same list the LYNX Soundfont editor's "SoundFont folders" menu keeps)
  1155. auto lines = juce::StringArray::fromLines (soundFontFoldersFile().loadFileAsString());
  1156. lines.removeEmptyStrings();
  1157. lines.addIfNotAlreadyThere (fc.getResult().getFullPathName());
  1158. soundFontFoldersFile().getParentDirectory().createDirectory();
  1159. soundFontFoldersFile().replaceWithText (lines.joinIntoString ("\n") + "\n");
  1160. ensureSoundFontIndex (true);
  1161. if (safe != nullptr)
  1162. safe->refilter();
  1163. });
  1164. }
  1165. juce::Label soundCaption, name, detail, listHint;
  1166. GlyphButton prev { glyph ("\xe2\x80\xb9") }, next { glyph ("\xe2\x80\xba") };
  1167. juce::TextButton editorButton, keysButton, ownButton, fontsButton, pluginsButton, folderButton;
  1168. juce::TextEditor search;
  1169. CategoryModel categoryModel;
  1170. SoundModel soundModel;
  1171. juce::ListBox categories, sounds;
  1172. std::unique_ptr<juce::FileChooser> chooser;
  1173. std::vector<soundlib::Sound> fontSounds, pluginSounds;
  1174. std::vector<int> rows, counts, shownCategories;
  1175. ChannelDef lastDef;
  1176. std::size_t lastListSize = 0;
  1177. int category = 0, current = -1, currentOwn = -1, generation = -1;
  1178. bool fonts = false, injected = false, pluginsInjected = false, known = false, categoryPicked = false, stale = true;
  1179. From from = From::own;
  1180. };
  1181. // =====================================================================================================================
  1182. // The dock
  1183. // =====================================================================================================================
  1184. SimpleDock::SimpleDock (AudioEngine& e, Hooks h) : engine (e), hooks (std::move (h))
  1185. {
  1186. effectsPage = std::make_unique<EffectsPage> (engine);
  1187. instrumentPage = std::make_unique<InstrumentPage> (engine, hooks);
  1188. addChildComponent (*effectsPage);
  1189. addChildComponent (*instrumentPage);
  1190. instrumentButton.setButtonText (tr ("Instrument"));
  1191. effectsButton.setButtonText (tr ("Effects"));
  1192. for (auto* b : { &instrumentButton, &effectsButton })
  1193. {
  1194. b->setClickingTogglesState (true);
  1195. b->setRadioGroupId (1901);
  1196. addAndMakeVisible (*b);
  1197. }
  1198. instrumentButton.setConnectedEdges (juce::Button::ConnectedOnRight);
  1199. effectsButton.setConnectedEdges (juce::Button::ConnectedOnLeft);
  1200. instrumentButton.onClick = [this] {
  1201. if (instrumentButton.getToggleState())
  1202. {
  1203. tabChosen = true;
  1204. setTab (Tab::instrument);
  1205. }
  1206. };
  1207. effectsButton.onClick = [this] {
  1208. if (effectsButton.getToggleState())
  1209. {
  1210. tabChosen = true;
  1211. setTab (Tab::effects);
  1212. }
  1213. };
  1214. hideButton.setButtonText (glyph ("\xe2\x96\xbe"));
  1215. hideButton.setTooltip (tr ("Hide the track dock"));
  1216. hideButton.onClick = [this] {
  1217. shownSetting = false;
  1218. if (hooks.layoutChanged)
  1219. hooks.layoutChanged();
  1220. };
  1221. addAndMakeVisible (hideButton);
  1222. showTrack (-1);
  1223. }
  1224. SimpleDock::~SimpleDock() = default;
  1225. void SimpleDock::showTrack (int newTrack)
  1226. {
  1227. if (newTrack != track)
  1228. tabChosen = false;
  1229. track = newTrack;
  1230. refresh();
  1231. }
  1232. void SimpleDock::refresh()
  1233. {
  1234. const auto& song = engine.getSong();
  1235. insert = channel = -1;
  1236. instrumentTab = false;
  1237. if (track >= 0)
  1238. {
  1239. const auto chain = detailchain::forTrack (song, track);
  1240. insert = chain.insert;
  1241. channel = chain.channel;
  1242. // a sound can be picked for a track that plays one instrument (not a sample, an audio clip or a drum kit)
  1243. if (channel >= 0 && channel < (int) song.channels.size())
  1244. {
  1245. const auto kind = song.channels[(std::size_t) channel].instrument;
  1246. instrumentTab = kind != InstrumentKind::audioClip && kind != InstrumentKind::sampler
  1247. && simpletracks::kindOf (song, track).value_or (simpletracks::Kind::instrument) == simpletracks::Kind::instrument;
  1248. }
  1249. }
  1250. instrumentButton.setVisible (instrumentTab);
  1251. if (! instrumentTab)
  1252. tab = Tab::effects;
  1253. else if (! tabChosen)
  1254. tab = Tab::instrument; // (an instrument track opens on its sound; an audio track on its effects)
  1255. effectsPage->show (insert);
  1256. instrumentPage->show (instrumentTab ? channel : -1);
  1257. showPage();
  1258. resized();
  1259. repaint();
  1260. }
  1261. void SimpleDock::setTab (Tab t)
  1262. {
  1263. tab = t == Tab::instrument && ! instrumentTab ? Tab::effects : t;
  1264. showPage();
  1265. }
  1266. void SimpleDock::cycleTab()
  1267. {
  1268. tabChosen = true;
  1269. setTab (tab == Tab::effects ? Tab::instrument : Tab::effects);
  1270. }
  1271. void SimpleDock::showPage()
  1272. {
  1273. (tab == Tab::instrument ? instrumentButton : effectsButton).setToggleState (true, juce::dontSendNotification);
  1274. instrumentPage->setVisible (tab == Tab::instrument);
  1275. effectsPage->setVisible (tab == Tab::effects);
  1276. }
  1277. int SimpleDock::heightFor (int available) const noexcept
  1278. {
  1279. return juce::jlimit (std::min (minHeight, available / 2), std::max (minHeight, available * 6 / 10), preferredHeight);
  1280. }
  1281. void SimpleDock::paint (juce::Graphics& g)
  1282. {
  1283. g.fillAll (colour::bg1);
  1284. auto strip = getLocalBounds().withHeight (stripHeight);
  1285. g.setColour (colour::bg3);
  1286. g.fillRect (strip);
  1287. g.setColour (colour::border);
  1288. g.fillRect (0, 0, getWidth(), 1);
  1289. g.fillRect (0, stripHeight - 1, getWidth(), 1);
  1290. // the resize grip in the middle of the top edge
  1291. g.setColour (colour::borderStrong);
  1292. g.fillRoundedRectangle ((float) getWidth() * 0.5f - 16.0f, 2.0f, 32.0f, 2.0f, 1.0f);
  1293. const auto& song = engine.getSong();
  1294. // round 190dg: the track's chain preset, right of the tabs (the header's FX button is too small to name it)
  1295. if (insert > 0 && insert < (int) song.mixer.size() && ! song.mixer[(std::size_t) insert].chainPreset.empty())
  1296. {
  1297. auto name = utf8 (song.mixer[(std::size_t) insert].chainPreset);
  1298. if (! chains::unchanged (song, insert))
  1299. name << " " << tr ("(edited)");
  1300. const auto area = strip.withLeft (effectsButton.getRight() + 16).withRight (hideButton.getX() - 10);
  1301. g.setColour (colour::textSecondary);
  1302. g.setFont (font (type::small));
  1303. g.drawText (tr ("Preset") + glyph (": ") + name, area, juce::Justification::centredRight, true);
  1304. }
  1305. auto text = strip.withTrimmedLeft (12).withRight (instrumentButton.isVisible() ? instrumentButton.getX() - 12 : effectsButton.getX() - 12);
  1306. if (track < 0)
  1307. {
  1308. g.setColour (colour::textSecondary);
  1309. g.setFont (font (type::body));
  1310. g.drawText (tr ("No track selected"), text, juce::Justification::centredLeft, true);
  1311. return;
  1312. }
  1313. const auto own = track < (int) song.playlistTracks.size() ? song.playlistTracks[(std::size_t) track].colour : 0u;
  1314. const auto kind = simpletracks::kindOf (song, track);
  1315. g.setColour (own != 0 ? juce::Colour (own) : kind ? juce::Colour (simpletracks::defaultColour (*kind)) : colour::textSecondary);
  1316. g.fillRoundedRectangle ((float) text.getX(), (float) strip.getCentreY() - 7.0f, 4.0f, 14.0f, 2.0f);
  1317. text.removeFromLeft (12);
  1318. g.setColour (colour::textPrimary);
  1319. g.setFont (font (type::body, true));
  1320. const auto title = trackTitle (song, track);
  1321. const auto titleWidth = juce::jmin (text.getWidth(), juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), title) + 4);
  1322. g.drawText (title, text.removeFromLeft (titleWidth), juce::Justification::centredLeft, true);
  1323. if (kind)
  1324. {
  1325. g.setColour (colour::textSecondary);
  1326. g.setFont (font (type::small));
  1327. g.drawText (glyph ("\xc2\xb7 ") + tr (simpletracks::defaultName (*kind)), text.withTrimmedLeft (6), juce::Justification::centredLeft, true);
  1328. }
  1329. }
  1330. void SimpleDock::resized()
  1331. {
  1332. auto strip = getLocalBounds().withHeight (stripHeight).reduced (0, 4);
  1333. hideButton.setBounds (strip.removeFromRight (34).withTrimmedRight (8));
  1334. // the tabs sit after the track's name, left of the middle
  1335. auto tabs = strip.withLeft (juce::jmin (300, getWidth() / 3)).withWidth (instrumentTab ? 220 : 110);
  1336. if (instrumentTab)
  1337. instrumentButton.setBounds (tabs.removeFromLeft (110));
  1338. effectsButton.setBounds (tabs.removeFromLeft (110));
  1339. const auto body = getLocalBounds().withTrimmedTop (stripHeight);
  1340. effectsPage->setBounds (body);
  1341. instrumentPage->setBounds (body);
  1342. }
  1343. void SimpleDock::mouseMove (const juce::MouseEvent& e)
  1344. {
  1345. setMouseCursor (e.y < edgeHeight ? juce::MouseCursor::UpDownResizeCursor : juce::MouseCursor::NormalCursor);
  1346. }
  1347. void SimpleDock::mouseDown (const juce::MouseEvent& e)
  1348. {
  1349. resizing = e.y < edgeHeight;
  1350. dragStartHeight = getHeight();
  1351. }
  1352. void SimpleDock::mouseDrag (const juce::MouseEvent& e)
  1353. {
  1354. if (! resizing)
  1355. return;
  1356. const auto wanted = juce::jmax (minHeight, dragStartHeight - e.getDistanceFromDragStartY());
  1357. if (wanted != preferredHeight)
  1358. {
  1359. preferredHeight = wanted;
  1360. if (auto* parent = getParentComponent())
  1361. parent->resized();
  1362. }
  1363. }
  1364. void SimpleDock::mouseUp (const juce::MouseEvent&)
  1365. {
  1366. if (resizing && hooks.layoutChanged)
  1367. hooks.layoutChanged(); // (saves the height)
  1368. resizing = false;
  1369. }
  1370. // --- the user's own chain presets ------------------------------------------------------------------------------------
  1371. juce::File SimpleDock::userPresetFolder() { return platform::documentsFolder().getChildFile ("LYNX/Chain presets"); }
  1372. // round 190dg: the favourite chain presets, one name a line, in the order they were starred
  1373. juce::File SimpleDock::favouritesFile() { return userPresetFolder().getChildFile ("Favourites.txt"); }
  1374. juce::StringArray SimpleDock::favouritePresets()
  1375. {
  1376. auto lines = juce::StringArray::fromLines (favouritesFile().loadFileAsString());
  1377. lines.trim();
  1378. lines.removeEmptyStrings();
  1379. lines.removeDuplicates (false);
  1380. return lines;
  1381. }
  1382. bool SimpleDock::setFavouritePreset (const juce::String& name, bool on)
  1383. {
  1384. auto lines = favouritePresets();
  1385. if (on)
  1386. lines.addIfNotAlreadyThere (name.trim());
  1387. else
  1388. lines.removeString (name.trim());
  1389. favouritesFile().getParentDirectory().createDirectory();
  1390. return favouritesFile().replaceWithText (lines.joinIntoString ("\n") + (lines.isEmpty() ? "" : "\n"));
  1391. }
  1392. bool SimpleDock::saveUserPreset (AudioEngine& engine, int insert, const juce::String& rawName)
  1393. {
  1394. const auto name = juce::File::createLegalFileName (rawName.trim());
  1395. if (name.isEmpty() || insert < 0 || insert >= (int) engine.getSong().mixer.size())
  1396. return false;
  1397. engine.capturePluginStates(); // the plugins' current settings go into the preset
  1398. const auto file = userPresetFolder().getChildFile (name + ProjectFile::mixerTrackStateExtension);
  1399. file.getParentDirectory().createDirectory();
  1400. const auto state = chains::stateOf (engine.getSong().mixer[(std::size_t) insert], name.toStdString());
  1401. if (! file.replaceWithText (ProjectFile::mixerTrackStateToJson (state)))
  1402. return false;
  1403. engine.editSong ([insert, n = name.toStdString()] (Song& s) {
  1404. if (insert < (int) s.mixer.size())
  1405. s.mixer[(std::size_t) insert].chainPreset = n;
  1406. });
  1407. return true;
  1408. }
  1409. bool SimpleDock::loadUserPreset (AudioEngine& engine, int insert, const juce::File& file)
  1410. {
  1411. juce::String error;
  1412. auto state = ProjectFile::mixerTrackStateFromJson (file.loadFileAsString(), error);
  1413. if (! state || insert < 0 || insert >= (int) engine.getSong().mixer.size())
  1414. return false;
  1415. const auto name = file.getFileNameWithoutExtension().toStdString();
  1416. engine.editSongStructural ([insert, &state, &name] (Song& s) { chains::applyChain (s, insert, state->effects, state->chainBlend, name); });
  1417. return true;
  1418. }
  1419. // --- tests and --simplefxshot ----------------------------------------------------------------------------------------
  1420. int SimpleDock::cardCountForCheck() const { return effectsPage->cardCount(); }
  1421. int SimpleDock::oneKnobCardsForCheck() const { return effectsPage->oneKnobCards(); }
  1422. juce::PopupMenu SimpleDock::presetMenuForSnapshot() { return effectsPage->presetMenu(); }
  1423. juce::PopupMenu SimpleDock::addMenuForSnapshot() { return effectsPage->addMenu(); }
  1424. void SimpleDock::setFontsForSnapshot (std::vector<sf::IndexedFont> fonts)
  1425. {
  1426. instrumentPage->setFonts (std::move (fonts), true);
  1427. instrumentPage->setSource (InstrumentPage::From::fonts);
  1428. }
  1429. void SimpleDock::setPluginsForSnapshot (std::vector<soundlib::InstalledPlugin> plugins)
  1430. {
  1431. instrumentPage->setPlugins (std::move (plugins));
  1432. instrumentPage->setSource (InstrumentPage::From::plugins);
  1433. }
  1434. void SimpleDock::showCategoryForSnapshot (int category) { instrumentPage->pickCategory (category); }
  1435. int SimpleDock::soundRowsForCheck() const { return instrumentPage->rowCount(); }
  1436. juce::String SimpleDock::soundNameForCheck() const { return instrumentPage->shownName(); }
  1437. void SimpleDock::clickSoundForCheck (int row) { instrumentPage->clickRow (row, false); }
  1438. void SimpleDock::stepSoundForCheck (int delta) { instrumentPage->stepSound (delta); }
  1439. void SimpleDock::turnKnobForCheck (int card, float value) { effectsPage->turnForCheck (card, value); }
  1440. void SimpleDock::moveCardForCheck (int card, int delta) { effectsPage->move (card, delta); }
  1441. void SimpleDock::removeCardForCheck (int card) { effectsPage->remove (card); }
  1442. void SimpleDock::addOneKnobForCheck (int goal) { effectsPage->addOneKnob (goal); }
  1443. void SimpleDock::setBlendForCheck (float value) { effectsPage->blendForCheck (value); }
  1444. juce::Rectangle<int> SimpleDock::cardBoundsForSnapshot (int card) const
  1445. {
  1446. const auto* c = effectsPage->cardForSnapshot (card);
  1447. return c != nullptr ? getLocalArea (c, c->getLocalBounds()) : juce::Rectangle<int>();
  1448. }
  1449. void SimpleDock::setSearchForSnapshot (const juce::String& text) { instrumentPage->searchFor (text); }
  1450. } // namespace lynx