| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820 |
- #include "ui/SimpleDock.h"
- #include "ui/TrackerComponent.h"
- #include "ui/DemoMode.h" // (round 190np: the Drum Machine is a demo::CellSource)
- #include <algorithm>
- #include <array>
- #include <cmath>
- #include <set>
- #include "core/ChainPresets.h"
- #include "core/DetailChain.h"
- #include "core/GoalKnobs.h"
- #include "core/KeyFollow.h"
- #include "core/MixerOps.h"
- #include "core/SimplePads.h"
- #include "core/SimpleSteps.h"
- #include "core/SmartControls.h"
- #include "core/SimpleTracks.h"
- #include "core/SoundLibrary.h"
- #include "engine/AudioEngine.h"
- #include "engine/PluginHost.h"
- #include "engine/ProjectFile.h"
- #include "platform/Paths.h"
- #include "ui/FileChoosers.h"
- #include "ui/BrowserComponent.h"
- #include "ui/I18n.h"
- #include "ui/MixerComponent.h"
- #include "ui/PianoRollComponent.h"
- #include "ui/QuickPick.h"
- #include "ui/SimpleLook.h"
- #include "ui/SoundFontEditor.h"
- #include "ui/TrackIcons.h"
- #include "ui/Icons.h"
- #include "ui/HintBar.h"
- #include "core/AudioCapture.h"
- #include "ui/Motion.h"
- #include "ui/Theme.h"
- #include "ui/TouchKeyboard.h"
- namespace lynx
- {
- using namespace theme;
- namespace
- {
- juce::String utf8 (const std::string& s) { return juce::String::fromUTF8 (s.c_str()); }
- juce::String glyph (const char* bytes) { return juce::String::fromUTF8 (bytes); }
- // geometry (px at 100 %)
- constexpr int sideWidth = 212, cardWidth = 148, cardGap = 8, addWidth = 52, titleHeight = 26, pad = 8;
- constexpr int rowHeight = 28, categoryWidth = 168; // (round 190jc, SG-9: sound rows 24 -> 28 px)
- // Words that mean something else elsewhere in the UI get their own translation here ("Keys" the instruments, not
- // the computer's keys; "Punch" the effect, not punch-in recording)
- juce::String goalText (int id) { return id == goals::punch ? trc ("@one-knob effect: Punch") : tr (goals::name (id)); }
- juce::String soundCategoryText (soundlib::Category c)
- {
- using C = soundlib::Category;
- return c == C::keys ? trc ("@sound category: Keys") : c == C::bass ? trc ("@instrument: Bass") : c == C::lead ? trc ("@sound category: Lead")
- : c == C::effects ? trc ("@sound category: Effects") : tr (soundlib::categoryName (c));
- }
- juce::String chainCategoryText (const char* name)
- {
- const juce::String n (name);
- return n == "Keys" ? trc ("@sound category: Keys") : n == "Bass" ? trc ("@instrument: Bass") : n == "Space" ? trc ("@preset category: Space") : tr (name);
- }
- juce::String percent (float v) { return juce::String (juce::roundToInt (v * 100.0f)) + " %"; }
- juce::String trackTitle (const Song& song, int track)
- {
- if (track >= 0 && track < (int) song.playlistTracks.size() && ! song.playlistTracks[(std::size_t) track].name.empty())
- return utf8 (song.playlistTracks[(std::size_t) track].name);
- return tr ("Track {0}", { juce::String (track + 1) });
- }
- // One rotary control of the dock: a value 0..1 with its text under the ring. Drag up / down (Shift: fine), the wheel,
- // the arrow keys; a double click goes back to `resetValue`. While it is dragged it keeps its own value, so the
- // song's change messages don't fight the hand.
- class DockKnob final : public juce::Component,
- public juce::SettableTooltipClient
- {
- public:
- std::function<void (float)> onChange;
- std::function<juce::String (float)> valueText;
- float resetValue = 0.5f;
- bool big = false;
- DockKnob()
- {
- setWantsKeyboardFocus (true);
- getProperties().set ("lynxClickKeepsKeys", true); // (round 190fc: clicked, the arrow keys turn it; Space still plays)
- setMouseCursor (juce::MouseCursor::UpDownResizeCursor);
- }
- float value() const noexcept { return shown; }
- void setValue (float v)
- {
- v = juce::jlimit (0.0f, 1.0f, v);
- if (dragging || std::abs (v - shown) < 1.0e-6f)
- return;
- shown = v;
- repaint();
- }
- void setDimmed (bool d)
- {
- if (dimmed != d)
- {
- dimmed = d;
- repaint();
- }
- }
- // the user's move (tests call it as a drag does)
- void turnTo (float v)
- {
- shown = juce::jlimit (0.0f, 1.0f, v);
- repaint();
- if (onChange)
- onChange (shown);
- }
- void paint (juce::Graphics& g) override
- {
- auto r = getLocalBounds().toFloat();
- const auto textHeight = big ? 20.0f : 16.0f;
- const auto text = r.removeFromBottom (textHeight);
- const auto d = juce::jmin (r.getWidth(), r.getHeight());
- const auto ring = juce::Rectangle<float> (d, d).withCentre (r.getCentre()).reduced (big ? 3.0f : 2.0f);
- const bool hot = dragging || isMouseOver() || hasKeyboardFocus (false);
- if (big) // a face under the ring, so the one knob reads as the card's control
- {
- g.setColour (colour::bg0);
- g.fillEllipse (ring.reduced (ring.getWidth() * 0.16f));
- g.setColour (hot ? colour::borderStrong : colour::border);
- g.drawEllipse (ring.reduced (ring.getWidth() * 0.16f), 1.0f);
- }
- drawKnob (g, ring, shown, false, dimmed ? colour::textDisabled : dragging ? colour::accent : colour::knobArc, hot);
- g.setColour (dimmed ? colour::textDisabled : colour::textPrimary);
- g.setFont (font (big ? type::body : type::small, big));
- g.drawText (valueText ? valueText (shown) : percent (shown), text, juce::Justification::centred, false);
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- if (e.mods.isPopupMenu())
- return;
- dragging = true;
- start = shown;
- grabKeyboardFocus();
- repaint();
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (! dragging)
- return;
- const auto span = e.mods.isShiftDown() ? 640.0f : 160.0f;
- turnTo (start - (float) e.getDistanceFromDragStartY() / span);
- }
- void mouseUp (const juce::MouseEvent&) override
- {
- dragging = false;
- repaint();
- }
- void mouseDoubleClick (const juce::MouseEvent&) override { turnTo (resetValue); }
- void mouseWheelMove (const juce::MouseEvent&, const juce::MouseWheelDetails& wheel) override
- {
- if (std::abs (wheel.deltaY) > 0.0f)
- turnTo (shown + (wheel.deltaY > 0.0f ? 0.02f : -0.02f));
- }
- bool keyPressed (const juce::KeyPress& key) override
- {
- const auto step = key.getModifiers().isShiftDown() ? 0.01f : 0.05f;
- if (key.isKeyCode (juce::KeyPress::upKey) || key.isKeyCode (juce::KeyPress::rightKey))
- return turnTo (shown + step), true;
- if (key.isKeyCode (juce::KeyPress::downKey) || key.isKeyCode (juce::KeyPress::leftKey))
- return turnTo (shown - step), true;
- return false;
- }
- void mouseEnter (const juce::MouseEvent&) override { repaint(); }
- void mouseExit (const juce::MouseEvent&) override { repaint(); }
- void focusGained (FocusChangeType) override { repaint(); }
- void focusLost (FocusChangeType) override { repaint(); }
- private:
- float shown = 0.0f, start = 0.0f;
- bool dragging = false, dimmed = false;
- };
- // A small flat button of a card's title bar and of the sound picker (‹ › ×). Round 190jc (design190ia SG-9, SG-10): vector
- // glyphs (`size` px: chevrons 5 x 9 / 6 x 10, the X 8 x 8, stroke 1.5) instead of 2-5 px text glyphs; a round hover fill.
- class GlyphButton final : public juce::Button
- {
- public:
- GlyphButton (const juce::String& name, ui::simplelook::Glyph g, juce::Point<float> glyphSize, bool roundHover = true)
- : juce::Button (name), glyph (g), size (glyphSize), round (roundHover)
- {
- }
- void paintButton (juce::Graphics& g, bool over, bool down) override
- {
- const auto r = getLocalBounds().toFloat();
- if (isEnabled() && (over || down))
- {
- g.setColour (down ? colour::bg6 : colour::bg5);
- if (round)
- g.fillEllipse (r.withSizeKeepingCentre (juce::jmin (r.getWidth(), r.getHeight()), juce::jmin (r.getWidth(), r.getHeight())).reduced (0.5f));
- else
- g.fillRoundedRectangle (r.reduced (1.0f), radius::lg);
- }
- const auto scale = ui::simplelook::px (1.0f, 1.4f);
- ui::simplelook::drawGlyph (g, glyph, r.withSizeKeepingCentre (size.x * scale, size.y * scale),
- ! isEnabled() ? colour::textDisabled : over ? colour::textPrimary : colour::textSecondary, 1.5f);
- }
- private:
- ui::simplelook::Glyph glyph;
- juce::Point<float> size;
- bool round;
- };
- // The last "card" of the chain: a big + in a dashed frame
- class AddCardButton final : public juce::Button
- {
- public:
- AddCardButton() : juce::Button ("+") {}
- void paintButton (juce::Graphics& g, bool over, bool down) override
- {
- const auto r = getLocalBounds().toFloat().reduced (0.5f);
- fillRoundRect (g, r, radius::lg, down ? colour::bg4 : over ? colour::bg3 : colour::bg2);
- juce::Path frame;
- frame.addRoundedRectangle (r.reduced (0.5f), radius::lg);
- const float dashes[] { 4.0f, 4.0f };
- juce::Path dashed;
- juce::PathStrokeType (1.0f).createDashedStroke (dashed, frame, dashes, 2);
- g.setColour (! isEnabled() ? colour::border : over ? colour::textSecondary : colour::borderStrong);
- g.fillPath (dashed);
- const auto c = r.getCentre();
- g.setColour (! isEnabled() ? colour::textDisabled : over ? colour::textPrimary : colour::textSecondary);
- g.fillRect (juce::Rectangle<float> (18.0f, 2.0f).withCentre (c));
- g.fillRect (juce::Rectangle<float> (2.0f, 18.0f).withCentre (c));
- }
- };
- // BandLab's preset stepper chevrons and its chain bypass button (round 190kn, DS-26 / DS-28: bandlab190p
- // 11-sounds-free-loops.png "‹ Bass Boost ›" and the struck "Fx" disc beside Save). LYNX vectors.
- class ChevronButton final : public juce::Button
- {
- public:
- explicit ChevronButton (bool pointsRight) : juce::Button (pointsRight ? "next" : "previous"), right (pointsRight)
- {
- setMouseCursor (juce::MouseCursor::PointingHandCursor);
- }
- void paintButton (juce::Graphics& g, bool over, bool down) override
- {
- auto r = getLocalBounds().toFloat();
- if (over || down)
- {
- g.setColour (down ? colour::bg5 : colour::bg4);
- g.fillRoundedRectangle (r.reduced (1.0f), radius::sm);
- }
- const auto c = r.getCentre();
- const auto s = 3.5f, d = right ? 1.0f : -1.0f;
- juce::Path p;
- p.startNewSubPath (c.x - d * s * 0.5f, c.y - s);
- p.lineTo (c.x + d * s * 0.5f, c.y);
- p.lineTo (c.x - d * s * 0.5f, c.y + s);
- g.setColour (! isEnabled() ? colour::textDisabled : over ? colour::textPrimary : colour::textSecondary);
- g.strokePath (p, juce::PathStrokeType (1.5f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
- }
- private:
- bool right;
- };
- // BandLab's ⓘ on an effect card (round 190kn, DS-25: bandlab190p 11-sounds-free-loops.png, the card's title bar)
- class InfoButton final : public juce::Button
- {
- public:
- InfoButton() : juce::Button ("about") { setMouseCursor (juce::MouseCursor::PointingHandCursor); }
- void paintButton (juce::Graphics& g, bool over, bool down) override
- {
- const auto r = getLocalBounds().toFloat().reduced (1.0f);
- const auto ink = down ? colour::textPrimary : over ? colour::textPrimary : colour::textSecondary;
- g.setColour (ink);
- g.drawEllipse (r.reduced (0.5f), 1.2f);
- const auto c = r.getCentre();
- const auto u = r.getWidth() / 12.0f;
- g.fillEllipse (c.x - 0.9f * u, c.y - 3.6f * u, 1.8f * u, 1.8f * u);
- g.fillRoundedRectangle (c.x - 0.8f * u, c.y - 1.0f * u, 1.6f * u, 4.6f * u, 0.6f * u);
- }
- };
- class ChainBypassButton final : public juce::Button
- {
- public:
- ChainBypassButton() : juce::Button ("bypass") { setMouseCursor (juce::MouseCursor::PointingHandCursor); }
- bool bypassed = false; // every effect of the chain off
- void paintButton (juce::Graphics& g, bool over, bool down) override
- {
- const auto r = getLocalBounds().toFloat().withSizeKeepingCentre (26.0f, 26.0f).reduced (0.5f);
- g.setColour (bypassed ? colour::accent : down ? colour::bg5 : over ? colour::bg4 : colour::bg3);
- g.fillEllipse (r);
- const auto ink = ! isEnabled() ? colour::textDisabled : bypassed ? colour::onAccent : over ? colour::textPrimary : colour::textSecondary;
- g.setColour (ink);
- g.setFont (font (type::caption, true).withStyle (juce::Font::bold | juce::Font::italic));
- g.drawText ("Fx", r.toNearestInt(), juce::Justification::centred, false);
- // the stroke through it (BandLab's bypass glyph)
- g.drawLine (r.getX() + 7.0f, r.getBottom() - 7.0f, r.getRight() - 7.0f, r.getY() + 7.0f, 1.4f);
- }
- };
- void styleCaption (juce::Label& label, const juce::String& text)
- {
- label.setText (text, juce::dontSendNotification);
- label.setFont (font (type::caption));
- label.setColour (juce::Label::textColourId, colour::textSecondary);
- label.setInterceptsMouseClicks (false, false);
- }
- } // namespace
- // =====================================================================================================================
- // Effects
- // =====================================================================================================================
- class SimpleDock::EffectsPage final : public juce::Component
- {
- public:
- explicit EffectsPage (AudioEngine& e) : engine (e), slotActions (e)
- {
- addChildComponent (slotActions); // (never shown: the Mixer slot's own menus, windows and edits on this insert)
- slotActions.setMenuTarget (this);
- styleCaption (presetCaption, tr ("Preset"));
- addAndMakeVisible (presetCaption);
- presetButton.setTooltip (tr ("A ready chain of effects for this track"));
- presetButton.onClick = [this] { presetMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&presetButton)); };
- addAndMakeVisible (presetButton);
- saveButton.setButtonText (tr ("Save"));
- saveButton.setTooltip (tr ("Keeps this chain as one of your presets"));
- saveButton.onClick = [this] { askSaveName(); };
- addAndMakeVisible (saveButton);
- // round 190kn: BandLab's ‹ › on the preset and its chain bypass
- previousPreset.setTooltip (tr ("Previous preset"));
- nextPreset.setTooltip (tr ("Next preset"));
- previousPreset.onClick = [this] { stepPreset (-1); };
- nextPreset.onClick = [this] { stepPreset (1); };
- addAndMakeVisible (previousPreset);
- addAndMakeVisible (nextPreset);
- bypassButton.setTooltip (tr ("Bypass all effects of this track (again: back on)"));
- bypassButton.onClick = [this] {
- const auto t = insert;
- if (t < 0 || ! hasEffects())
- return;
- const auto on = ! mixerops::anyEffectEnabled (engine.getSong(), t);
- engine.editSong ([t, on] (Song& s) { mixerops::setAllEffectsEnabled (s, t, on); });
- };
- addAndMakeVisible (bypassButton);
- styleCaption (blendCaption, tr ("Blend"));
- addAndMakeVisible (blendCaption);
- blend.resetValue = 1.0f;
- blend.setTooltip (tr ("How much of the effects you hear: 0 % is the track without them"));
- blend.setTitle (tr ("Blend"));
- blend.onChange = [this] (float v) {
- const auto t = insert;
- if (t >= 0)
- engine.editSong ([t, v] (Song& s) {
- if (t < (int) s.mixer.size())
- s.mixer[(std::size_t) t].chainBlend = v;
- });
- };
- addAndMakeVisible (blend);
- // round 190fo: the track's send into the shared "Reverb" insert (the original's per-track Reverb knob)
- styleCaption (reverbCaption, tr ("Reverb"));
- addAndMakeVisible (reverbCaption);
- reverb.resetValue = 0.0f;
- reverb.setTooltip (tr ("How much of the track goes to the shared reverb (one Reverb insert for every track)"));
- reverb.setTitle (tr ("Reverb"));
- reverb.onChange = [this] (float v) {
- const auto t = insert;
- if (t > 0)
- engine.editSong ([t, v] (Song& s) { simpletracks::setReverbSend (s, t, v < 0.005f ? 0.0f : v); });
- };
- addAndMakeVisible (reverb);
- // round 190ot (research190oe P5): the second shared send, an echo (GarageBand's Echo and Reverb sends)
- styleCaption (echoCaption, tr ("Echo"));
- addAndMakeVisible (echoCaption);
- echo.resetValue = 0.0f;
- echo.setTooltip (tr ("How much of the track goes to the shared echo (one Echo insert for every track, a dotted quarter note at the song's tempo)"));
- echo.setTitle (tr ("Echo"));
- echo.onChange = [this] (float v) {
- const auto t = insert;
- if (t > 0)
- engine.editSong ([t, v] (Song& s) { simpletracks::setEchoSend (s, t, v < 0.005f ? 0.0f : v); });
- };
- addAndMakeVisible (echo);
- // round 190ot: "Duck under..." — the track dips on every hit of the one picked (sidechain pumping in one pick)
- styleCaption (duckCaption, tr ("Duck under"));
- addAndMakeVisible (duckCaption);
- duckButton.setTooltip (tr ("Dips this track on every hit of another track, a kick say (sidechain pumping). The Duck card's knob sets how much"));
- duckButton.setComponentID ("simple.dock.duck");
- duckButton.onClick = [this] { duckMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&duckButton)); };
- addAndMakeVisible (duckButton);
- view.setViewedComponent (&strip, false);
- view.setScrollBarsShown (false, true);
- view.setScrollBarThickness (8);
- addAndMakeVisible (view);
- addCard.setTooltip (tr ("Add an effect"));
- addCard.setComponentID ("simple.dock.addEffect"); // (round 190dv: the tour's ring)
- addCard.onClick = [this] { addMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&addCard)); };
- strip.addAndMakeVisible (addCard);
- styleCaption (emptyHint, {});
- emptyHint.setFont (font (type::body));
- emptyHint.setJustificationType (juce::Justification::centredLeft);
- strip.addAndMakeVisible (emptyHint);
- }
- void show (int newInsert)
- {
- if (insert != newInsert)
- {
- insert = newInsert;
- cards.clear();
- view.setViewPosition (0, 0);
- }
- slotActions.setTrack (juce::jmax (0, insert));
- refresh();
- }
- void refresh()
- {
- const auto& song = engine.getSong();
- const bool has = insert >= 0 && insert < (int) song.mixer.size();
- presetButton.setEnabled (has);
- previousPreset.setEnabled (has);
- nextPreset.setEnabled (has);
- blend.setEnabled (has);
- reverb.setValue (has ? simpletracks::reverbSend (song, insert) : 0.0f);
- const auto bus = has && insert > 0 && insert != simpletracks::sharedReverb (song) && insert != simpletracks::sharedEcho (song);
- reverb.setEnabled (bus);
- echo.setEnabled (bus);
- echo.setValue (has ? simpletracks::echoSend (song, insert) : 0.0f);
- duckButton.setEnabled (bus);
- {
- const auto trigger = has ? simpletracks::duckTrigger (song, insert) : -1;
- duckButton.setButtonText ((trigger > 0 ? insertTitle (trigger) : tr ("None")) + glyph (" \xe2\x96\xbe"));
- }
- addCard.setEnabled (has);
- if (! has)
- {
- cards.clear();
- presetButton.setButtonText (tr ("None"));
- saveButton.setEnabled (false);
- bypassButton.setEnabled (false);
- bypassButton.bypassed = false;
- bypassButton.repaint();
- blend.setValue (1.0f);
- // (round 190oj CS-26: with no track the knobs looked live next to a greyed Save and preset)
- blend.setDimmed (true);
- reverb.setDimmed (true);
- emptyHint.setText (tr ("Select a track to see its effects."), juce::dontSendNotification);
- layoutStrip();
- return;
- }
- const auto& mixer = song.mixer[(std::size_t) insert];
- const auto& fx = mixer.effects;
- // the cards are kept while the chain has the same shape: a knob being dragged stays the same component
- bool same = cards.size() == fx.size();
- for (std::size_t i = 0; same && i < fx.size(); ++i)
- same = cards[i]->kind == fx[i].kind && cards[i]->goal == (goals::active (fx[i]) ? (int) fx[i].goal : 0);
- if (! same)
- {
- cards.clear();
- for (std::size_t i = 0; i < fx.size(); ++i)
- {
- cards.push_back (std::make_unique<Card> (*this, (int) i));
- strip.addAndMakeVisible (*cards.back());
- }
- }
- for (std::size_t i = 0; i < fx.size(); ++i)
- cards[i]->update (fx[i], (int) i, (int) fx.size());
- auto name = mixer.chainPreset.empty() ? tr ("None") : utf8 (mixer.chainPreset);
- if (! mixer.chainPreset.empty() && ! chains::unchanged (song, insert))
- name << " " << tr ("(edited)");
- presetButton.setButtonText (name + glyph (" \xe2\x96\xbe"));
- saveButton.setEnabled (! fx.empty());
- bypassButton.setEnabled (! fx.empty());
- if (const auto off = ! fx.empty() && ! mixerops::anyEffectEnabled (song, insert); off != bypassButton.bypassed)
- {
- bypassButton.bypassed = off;
- bypassButton.repaint();
- }
- blend.setValue (mixer.chainBlend);
- blend.setDimmed (fx.empty());
- reverb.setDimmed (! reverb.isEnabled());
- addCard.setEnabled ((int) fx.size() < maxEffectSlots);
- emptyHint.setText (fx.empty() ? tr ("No effects yet. Press + to add one, or pick a preset.") : juce::String(), juce::dontSendNotification);
- layoutStrip();
- }
- void resized() override
- {
- auto r = getLocalBounds().reduced (pad);
- auto side = r.removeFromLeft (sideWidth - pad);
- presetCaption.setBounds (side.removeFromTop (16));
- auto row = side.removeFromTop (26);
- presetButton.setBounds (row); // (BandLab: "‹ Bass Boost ›", the arrows inside the preset's capsule)
- previousPreset.setBounds (row.removeFromLeft (22).reduced (0, 2));
- nextPreset.setBounds (row.removeFromRight (22).reduced (0, 2));
- side.removeFromTop (6);
- auto second = side.removeFromTop (26); // BandLab: Save and the chain bypass under the preset
- saveButton.setBounds (second.removeFromLeft (theme::buttonWidth (saveButton, 58, 110))); // (round 190oj WG-12: de "Speiche...")
- second.removeFromLeft (8);
- bypassButton.setBounds (second.removeFromLeft (26));
- side.removeFromTop (8);
- // round 190ot: "Duck under [track ▾]" (a caption, then its picker), then Blend | Reverb | Echo
- auto duckRow = side.removeFromTop (24);
- duckCaption.setBounds (duckRow.removeFromLeft (76));
- duckButton.setBounds (duckRow);
- side.removeFromTop (8);
- auto captions = side.removeFromTop (16);
- auto knobs = side.removeFromTop (juce::jmin (84, side.getHeight()));
- const auto third = side.getWidth() / 3;
- blendCaption.setBounds (captions.removeFromLeft (third));
- blend.setBounds (knobs.removeFromLeft (third).withSizeKeepingCentre (juce::jmin (third - 4, 64), knobs.getHeight()).withX (blendCaption.getX()));
- reverbCaption.setBounds (captions.removeFromLeft (third));
- reverb.setBounds (knobs.removeFromLeft (third).withSizeKeepingCentre (juce::jmin (third - 4, 64), knobs.getHeight()).withX (reverbCaption.getX()));
- echoCaption.setBounds (captions);
- echo.setBounds (knobs.withSizeKeepingCentre (juce::jmin (third - 4, 64), knobs.getHeight()).withX (echoCaption.getX()));
- r.removeFromLeft (pad);
- view.setBounds (r);
- layoutStrip();
- }
- void paint (juce::Graphics& g) override
- {
- g.setColour (colour::border);
- g.fillRect (sideWidth, pad, 1, getHeight() - 2 * pad);
- }
- // --- menus ------------------------------------------------------------------------------------------------------
- juce::PopupMenu presetMenu()
- {
- juce::PopupMenu menu;
- const auto& song = engine.getSong();
- const auto current = insert >= 0 && insert < (int) song.mixer.size() ? song.mixer[(std::size_t) insert].chainPreset : std::string();
- auto files = userPresetFolder().findChildFiles (juce::File::findFiles, false, juce::String ("*") + ProjectFile::mixerTrackStateExtension);
- files.sort();
- // round 190dg: the favourites first, under their own heading (a factory preset or one of the user's)
- const auto favs = favouritePresets();
- if (! favs.isEmpty())
- {
- juce::PopupMenu starred;
- for (const auto& f : favs)
- {
- const auto name = f.toStdString();
- if (chains::find (name) != nullptr)
- starred.addItem (f, true, current == name, [this, name] { applyFactory (name); });
- else if (const auto file = userPresetFolder().getChildFile (f + ProjectFile::mixerTrackStateExtension); file.existsAsFile())
- starred.addItem (f, true, current == name, [this, file] { loadUserPreset (engine, insert, file); });
- }
- if (starred.getNumItems() > 0)
- {
- menu.addSubMenu (glyph ("\xe2\x98\x85 ") + tr ("Favourites"), starred, true, nullptr, favs.contains (utf8 (current)));
- menu.addSeparator();
- }
- }
- for (const auto* category : chains::categories())
- {
- juce::PopupMenu sub;
- bool ticked = false;
- for (const auto& p : chains::factory())
- if (std::string (p.category) == category)
- {
- const bool on = current == p.name;
- ticked = ticked || on;
- sub.addItem (utf8 (p.name) + glyph (" \xe2\x80\x94 ") + tr (p.description), true, on, [this, name = std::string (p.name)] { applyFactory (name); });
- }
- menu.addSubMenu (chainCategoryText (category), sub, true, nullptr, ticked);
- }
- menu.addSeparator();
- juce::PopupMenu mine;
- for (const auto& f : files)
- mine.addItem (f.getFileNameWithoutExtension(), true, current == f.getFileNameWithoutExtension().toStdString(),
- [this, f] { loadUserPreset (engine, insert, f); });
- if (files.isEmpty())
- mine.addItem (tr ("(none yet)"), false, false, nullptr);
- menu.addSubMenu (tr ("My presets"), mine);
- menu.addItem (tr ("Save as my preset..."), hasEffects(), false, [this] { askSaveName(); });
- if (! current.empty()) // the track's own preset as a favourite (or not any more)
- {
- const auto shown = utf8 (current);
- const bool starred = favs.contains (shown);
- menu.addItem (starred ? tr ("Remove \"{0}\" from favourites", { shown }) : tr ("Add \"{0}\" to favourites", { shown }),
- [shown, starred] { setFavouritePreset (shown, ! starred); });
- }
- if (! files.isEmpty()) // (to the system's bin: a preset removed by mistake can be taken back)
- {
- juce::PopupMenu bin;
- for (const auto& f : files)
- bin.addItem (f.getFileNameWithoutExtension(), [f] { f.moveToTrash(); });
- menu.addSubMenu (tr ("Delete one of my presets"), bin);
- }
- menu.addSeparator();
- menu.addItem (tr ("Remove all effects"), hasEffects(), false, [this] {
- const auto t = insert;
- engine.editSongStructural ([t] (Song& s) { chains::applyChain (s, t, {}, 1.0f, {}); });
- });
- return menu;
- }
- juce::PopupMenu addMenu()
- {
- juce::PopupMenu menu;
- menu.addSectionHeader (tr ("One-knob effects"));
- for (int id = 1; id <= goals::count; ++id)
- menu.addItem (goalText (id) + glyph (" \xe2\x80\x94 ") + tr (goals::description (id)), [this, id] { addOneKnob (id); });
- menu.addSeparator();
- menu.addItem (tr ("More effects..."), [this] { slotActions.showAddMenuFor (nextFreeRow()); });
- return menu;
- }
- // round 190ot: "Duck under..." — None, the other tracks of the song (a track this one feeds cannot be picked: the
- // sidechain would make a loop), then the three styles (the Duck card's knob at Subtle / Pumping / Hard)
- juce::PopupMenu duckMenu()
- {
- juce::PopupMenu menu;
- const auto& song = engine.getSong();
- const auto t = insert;
- if (t <= 0 || t >= (int) song.mixer.size())
- return menu;
- const auto trigger = simpletracks::duckTrigger (song, t);
- menu.addSectionHeader (tr ("Duck under"));
- menu.addItem (tr ("None"), trigger > 0 || simpletracks::duckSlot (song, t) >= 0, trigger <= 0, [this] { pickDuck (-1); });
- std::vector<int> seen;
- for (int track = 0; track < (int) song.playlistTracks.size(); ++track)
- {
- if (! simpletracks::kindOf (song, track))
- continue;
- const auto from = simpletracks::insertOf (song, track);
- if (from <= 0 || from == t || std::find (seen.begin(), seen.end(), from) != seen.end())
- continue;
- seen.push_back (from);
- const auto possible = song.routes (from, t) || song.canRoute (from, t);
- menu.addItem (trackTitle (song, track), possible, from == trigger, [this, from] { pickDuck (from); });
- }
- if (seen.empty())
- menu.addItem (tr ("(no other track yet)"), false, false, nullptr);
- menu.addSeparator();
- menu.addSectionHeader (tr ("Style"));
- const auto slot = simpletracks::duckSlot (song, t);
- const auto amount = slot >= 0 ? song.mixer[(std::size_t) t].effects[(std::size_t) slot].goalAmount : -1.0f;
- for (const auto style : { simpletracks::DuckStyle::subtle, simpletracks::DuckStyle::pumping, simpletracks::DuckStyle::hard })
- {
- const auto value = simpletracks::duckAmount (style);
- menu.addItem (duckStyleText (style), slot >= 0, slot >= 0 && std::abs (amount - value) < 0.005f, [this, value] {
- const auto at = insert;
- engine.editSong ([at, value] (Song& s) { simpletracks::setDuckAmount (s, at, value); });
- });
- }
- return menu;
- }
- void pickDuck (int from)
- {
- const auto t = insert;
- if (t <= 0)
- return;
- engine.editSongStructural ([t, from] (Song& s) { simpletracks::setDuck (s, t, from); });
- }
- static juce::String duckStyleText (simpletracks::DuckStyle style)
- {
- using S = simpletracks::DuckStyle;
- return style == S::subtle ? trc ("@duck style: Subtle") : style == S::pumping ? trc ("@duck style: Pumping") : trc ("@duck style: Hard");
- }
- // a mixer insert as the Simple layout names it: the track that plays through it, else the insert's own name
- juce::String insertTitle (int at) const
- {
- const auto& song = engine.getSong();
- for (int track = 0; track < (int) song.playlistTracks.size(); ++track)
- if (simpletracks::kindOf (song, track) && simpletracks::insertOf (song, track) == at)
- return trackTitle (song, track);
- return at > 0 && at < (int) song.mixer.size() ? utf8 (song.mixer[(std::size_t) at].name) : juce::String();
- }
- // --- edits (each through the Mixer's own paths) -------------------------------------------------------------------
- void addOneKnob (int goal)
- {
- const auto t = insert;
- if (t < 0)
- return;
- engine.editSongStructural ([t, goal] (Song& s) {
- if (t < (int) s.mixer.size())
- detailchain::insertEffectAt (s, t, goals::make (goal), (int) s.mixer[(std::size_t) t].effects.size());
- });
- }
- void turn (int index, bool oneKnob, float v)
- {
- const auto t = insert;
- if (oneKnob)
- engine.editSong ([t, index, v] (Song& s) {
- if (t >= 0 && t < (int) s.mixer.size() && index < (int) s.mixer[(std::size_t) t].effects.size())
- goals::setAmount (s.mixer[(std::size_t) t].effects[(std::size_t) index], v);
- });
- else
- slotActions.setSlotParam (-1, index, v); // the slot's Mix, as the Mixer sets it
- }
- void toggle (int index)
- {
- const auto t = insert;
- engine.editSong ([t, index] (Song& s) {
- if (t >= 0 && t < (int) s.mixer.size() && index < (int) s.mixer[(std::size_t) t].effects.size())
- s.mixer[(std::size_t) t].effects[(std::size_t) index].enabled = ! s.mixer[(std::size_t) t].effects[(std::size_t) index].enabled;
- });
- }
- void move (int index, int delta)
- {
- const auto t = insert;
- // (moveEffectBefore: `position` is the card it lands before, counted with the moved card still in place)
- const auto position = delta < 0 ? index - 1 : index + 2;
- if (position < 0 || position > (int) cards.size())
- return;
- engine.editSongStructural ([t, index, position] (Song& s) { detailchain::moveEffectBefore (s, t, index, position); });
- }
- void moveTo (int index, int position)
- {
- const auto t = insert;
- if (position == index || position == index + 1)
- return;
- engine.editSongStructural ([t, index, position] (Song& s) { detailchain::moveEffectBefore (s, t, index, position); });
- }
- void remove (int index) { slotActions.deleteSlot (index); }
- void openEditor (int index) { slotActions.toggleSlotEditor (index); }
- void stepPreset (int direction)
- {
- const auto& song = engine.getSong();
- if (insert < 0 || insert >= (int) song.mixer.size())
- return;
- if (const auto* p = chains::stepped (song.mixer[(std::size_t) insert].chainPreset, direction))
- applyFactory (p->name);
- }
- void applyFactory (const std::string& name)
- {
- const auto t = insert;
- if (const auto* preset = chains::find (name); preset != nullptr && t >= 0)
- engine.editSongStructural ([t, preset] (Song& s) { chains::apply (s, t, *preset); });
- }
- void askSaveName()
- {
- if (! hasEffects())
- return;
- const auto& mixer = engine.getSong().mixer[(std::size_t) insert];
- 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."),
- juce::MessageBoxIconType::NoIcon);
- const auto factory = chains::find (mixer.chainPreset) != nullptr;
- window->addTextEditor ("name", mixer.chainPreset.empty() ? tr ("My preset") : factory ? tr ("{0} (my version)", { utf8 (mixer.chainPreset) }) : utf8 (mixer.chainPreset));
- window->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- juce::Component::SafePointer<EffectsPage> safe (this);
- window->enterModalState (true, juce::ModalCallbackFunction::create ([window, safe] (int result) {
- if (result == 1 && safe != nullptr)
- saveUserPreset (safe->engine, safe->insert, window->getTextEditorContents ("name"));
- }),
- true);
- }
- // --- dragging a card by its title --------------------------------------------------------------------------------
- void dragCard (int index, int stripX)
- {
- dragging = index;
- // the gap the card would land in: before the first card whose middle is right of the pointer
- int position = (int) cards.size();
- for (int i = 0; i < (int) cards.size(); ++i)
- if (stripX < cards[(std::size_t) i]->getBounds().getCentreX())
- {
- position = i;
- break;
- }
- if (dropAt != position)
- {
- dropAt = position;
- strip.repaint();
- }
- }
- void dropCard()
- {
- const auto from = dragging, to = dropAt;
- dragging = dropAt = -1;
- strip.repaint();
- if (from >= 0 && to >= 0)
- moveTo (from, to);
- }
- int cardCount() const noexcept { return (int) cards.size(); }
- int oneKnobCards() const noexcept
- {
- return (int) std::count_if (cards.begin(), cards.end(), [] (const auto& c) { return c->goal != 0; });
- }
- void turnForCheck (int card, float v)
- {
- if (card >= 0 && card < (int) cards.size())
- cards[(std::size_t) card]->knob.turnTo (v);
- }
- void blendForCheck (float v) { blend.turnTo (v); }
- void reverbForCheck (float v) { reverb.turnTo (v); }
- void echoForCheck (float v) { echo.turnTo (v); } // round 190ot
- void duckForCheck (int from) { pickDuck (from); }
- juce::PopupMenu duckMenuForCheck() { return duckMenu(); }
- juce::String duckButtonTextForCheck() const { return duckButton.getButtonText(); }
- void bypassForCheck() { bypassButton.onClick(); } // round 190kn
- bool bypassLitForCheck() const noexcept { return bypassButton.bypassed; }
- const juce::Component* cardForSnapshot (int card) const
- {
- return card >= 0 && card < (int) cards.size() ? cards[(std::size_t) card].get() : nullptr;
- }
- AudioEngine& engine;
- int insert = -1;
- private:
- // One slot of the insert. A one-knob effect shows its goal and one big knob; any other effect its name and its Mix.
- class Card final : public juce::Component
- {
- public:
- Card (EffectsPage& o, int i) : owner (o), index (i)
- {
- knob.big = true;
- knob.onChange = [this] (float v) { owner.turn (index, goal != 0, v); };
- addAndMakeVisible (knob);
- editor.setButtonText (tr ("Editor"));
- editor.setTooltip (tr ("Opens the effect's own window with every control"));
- editor.onClick = [this] { owner.openEditor (index); };
- addAndMakeVisible (editor);
- left.setTooltip (tr ("Move earlier in the chain"));
- left.onClick = [this] { owner.move (index, -1); };
- right.setTooltip (tr ("Move later in the chain"));
- right.onClick = [this] { owner.move (index, 1); };
- close.setTooltip (tr ("Remove this effect"));
- close.onClick = [this] { owner.remove (index); };
- for (auto* b : { &left, &right, &close })
- addAndMakeVisible (*b);
- // round 190kn (DS-25, BandLab's card: toggle, ⓘ, name, ×): what the effect does, in a bubble
- info.setTooltip (tr ("About this effect"));
- info.onClick = [this] { showAbout(); };
- addAndMakeVisible (info);
- }
- juce::String aboutText() const
- {
- if (goal != 0)
- return goalText (goal) + ": " + tr (goals::description (goal));
- return tr ("{0}: its knob sets how much of the effect is mixed in; Editor opens all of its controls.", { title });
- }
- void showAbout()
- {
- auto label = std::make_unique<juce::Label> (juce::String(), aboutText());
- label->setFont (font (type::body));
- label->setColour (juce::Label::textColourId, colour::textPrimary);
- label->setJustificationType (juce::Justification::topLeft);
- const auto width = 240;
- const auto lines = juce::jmax (1, (int) std::ceil (juce::GlyphArrangement::getStringWidth (label->getFont(), label->getText()) / (float) (width - 12)));
- label->setSize (width, 12 + lines * (int) std::ceil (label->getFont().getHeight() + 3.0f));
- juce::CallOutBox::launchAsynchronously (std::move (label), info.getScreenBounds(), nullptr);
- }
- void update (const EffectSlot& slot, int newIndex, int count)
- {
- index = newIndex;
- kind = slot.kind;
- goal = goals::active (slot) ? (int) slot.goal : 0;
- on = slot.enabled;
- const auto effectName = quickpick::slotName (owner.engine, slot);
- title = goal != 0 ? goalText (goal) : effectName;
- sub = goal != 0 ? effectName : tr ("Mix");
- if (goal == goals::duck) // round 190ot: the trigger it listens to
- sub = slot.sidechain > 0 ? tr ("under {0}", { owner.insertTitle (slot.sidechain) }) : tr ("under no track yet");
- knob.resetValue = goal != 0 ? goals::defaultAmount (goal) : 1.0f;
- knob.setValue (goal != 0 ? slot.goalAmount : slot.mix);
- knob.setDimmed (! on);
- knob.setTitle (title);
- knob.setTooltip (goal != 0 ? tr (goals::description (goal)) : tr ("How much of this effect is mixed in"));
- left.setEnabled (index > 0);
- right.setEnabled (index + 1 < count);
- repaint();
- }
- juce::Rectangle<int> ledBounds() const { return { 7, 6, 14, 14 }; } // (round 190jc, SG-10: 14 px, ringed when off)
- juce::String aboutForCheck() const { return aboutText(); }
- void resized() override
- {
- auto r = getLocalBounds();
- auto bar = r.removeFromTop (titleHeight);
- // round 190jc (SG-10): 20 x 20 hit boxes
- bar.removeFromRight (3);
- close.setBounds (bar.removeFromRight (20).withSizeKeepingCentre (20, 20));
- right.setBounds (bar.removeFromRight (20).withSizeKeepingCentre (20, 20));
- left.setBounds (bar.removeFromRight (20).withSizeKeepingCentre (20, 20));
- info.setBounds (ledBounds().getRight() + 3, ledBounds().getY(), 14, 14);
- r.reduce (pad, 6);
- editor.setBounds (r.removeFromBottom (24));
- r.removeFromBottom (4);
- r.removeFromBottom (16); // (the effect's own name, painted)
- knob.setBounds (r.withSizeKeepingCentre (juce::jmin (r.getWidth(), 96), juce::jmin (r.getHeight(), 104)));
- }
- void paint (juce::Graphics& g) override
- {
- const auto r = getLocalBounds().toFloat();
- fillRoundRect (g, r, radius::lg, colour::bg2);
- {
- juce::Graphics::ScopedSaveState save (g);
- g.reduceClipRegion (getLocalBounds().withHeight (titleHeight));
- fillRoundRect (g, r.withHeight ((float) titleHeight + radius::lg), radius::lg, colour::bg3);
- }
- g.setColour (owner.dragging == index ? colour::accent : colour::border);
- g.drawRoundedRectangle (r.reduced (0.5f), radius::lg, 1.0f);
- g.setColour (on ? colour::accent : colour::ledOff);
- g.fillEllipse (ledBounds().toFloat());
- if (! on)
- {
- g.setColour (colour::textDisabled);
- g.drawEllipse (ledBounds().toFloat().reduced (0.5f), 1.0f);
- }
- if (ledHover)
- {
- g.setColour (colour::textPrimary.withAlpha (0.6f));
- g.drawEllipse (ledBounds().toFloat().expanded (1.5f), 1.0f);
- }
- g.setColour (on ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::body, true));
- g.drawText (title, juce::Rectangle<int> (info.getRight() + 5, 0, left.getX() - info.getRight() - 7, titleHeight), juce::Justification::centredLeft, true);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::caption));
- g.drawText (sub, juce::Rectangle<int> (pad, editor.getY() - 20, getWidth() - 2 * pad, 16), juce::Justification::centred, true);
- }
- void mouseMove (const juce::MouseEvent& e) override
- {
- const bool over = ledBounds().expanded (3).contains (e.getPosition());
- if (over != ledHover)
- {
- ledHover = over;
- repaint();
- }
- setMouseCursor (! over && e.y < titleHeight ? juce::MouseCursor::DraggingHandCursor : juce::MouseCursor::NormalCursor);
- }
- void mouseExit (const juce::MouseEvent&) override
- {
- ledHover = false;
- repaint();
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- pressedLed = ledBounds().expanded (3).contains (e.getPosition());
- pressedTitle = ! pressedLed && e.y < titleHeight;
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (pressedTitle && e.getDistanceFromDragStart() > 5)
- owner.dragCard (index, e.getEventRelativeTo (getParentComponent()).x);
- }
- void mouseUp (const juce::MouseEvent& e) override
- {
- if (owner.dragging == index)
- owner.dropCard();
- else if (pressedLed && ledBounds().expanded (3).contains (e.getPosition()))
- owner.toggle (index);
- pressedLed = pressedTitle = false;
- }
- void mouseDoubleClick (const juce::MouseEvent& e) override
- {
- if (e.y < titleHeight && ! ledBounds().expanded (3).contains (e.getPosition()))
- owner.openEditor (index);
- }
- EffectsPage& owner;
- int index = 0, goal = 0;
- EffectKind kind = EffectKind::eq;
- bool on = true, ledHover = false, pressedLed = false, pressedTitle = false;
- juce::String title, sub;
- DockKnob knob;
- juce::TextButton editor;
- InfoButton info; // (round 190kn: BandLab's ⓘ)
- GlyphButton left { glyph ("\xe2\x80\xb9"), ui::simplelook::Glyph::chevronLeft, { 5.0f, 9.0f } },
- right { glyph ("\xe2\x80\xba"), ui::simplelook::Glyph::chevronRight, { 5.0f, 9.0f } },
- close { glyph ("\xc3\x97"), ui::simplelook::Glyph::cross, { 8.0f, 8.0f } };
- };
- // The row of cards (inside the viewport): it paints the drop mark while a card is dragged
- class Strip final : public juce::Component
- {
- public:
- explicit Strip (EffectsPage& o) : owner (o) {}
- void paintOverChildren (juce::Graphics& g) override
- {
- if (owner.dragging < 0 || owner.dropAt < 0)
- return;
- const auto x = owner.dropAt < (int) owner.cards.size() ? owner.cards[(std::size_t) owner.dropAt]->getX() - cardGap / 2
- : owner.addCard.getX() - cardGap / 2;
- g.setColour (colour::accent);
- g.fillRect (x - 1, 0, 2, getHeight());
- }
- EffectsPage& owner;
- };
- void layoutStrip()
- {
- const auto h = juce::jmax (40, view.getHeight() - (view.isHorizontalScrollBarShown() ? view.getScrollBarThickness() : 0));
- int x = 0;
- for (auto& c : cards)
- {
- c->setBounds (x, 0, cardWidth, h);
- x += cardWidth + cardGap;
- }
- addCard.setBounds (x, 0, addWidth, h);
- x += addWidth;
- const auto hintWidth = emptyHint.getText().isEmpty() ? 0 : 360;
- emptyHint.setBounds (x + 12, 0, hintWidth, h);
- strip.setSize (juce::jmax (view.getWidth(), x + (hintWidth > 0 ? hintWidth + 12 : 0)), h);
- }
- bool hasEffects() const
- {
- const auto& song = engine.getSong();
- return insert >= 0 && insert < (int) song.mixer.size() && ! song.mixer[(std::size_t) insert].effects.empty();
- }
- int nextFreeRow() const
- {
- const auto& song = engine.getSong();
- if (insert < 0 || insert >= (int) song.mixer.size())
- return 0;
- const auto& fx = song.mixer[(std::size_t) insert].effects;
- const auto rows = mixerops::effectRows (fx);
- for (int r = rows.empty() ? 0 : rows.back() + 1; r < maxEffectSlots; ++r)
- if (mixerops::effectAtRow (fx, r) < 0)
- return r;
- for (int r = 0; r < maxEffectSlots; ++r)
- if (mixerops::effectAtRow (fx, r) < 0)
- return r;
- return 0;
- }
- EffectsPanel slotActions;
- juce::Label presetCaption, blendCaption, reverbCaption, echoCaption, duckCaption, emptyHint;
- juce::TextButton presetButton, saveButton, duckButton;
- ChevronButton previousPreset { false }, nextPreset { true };
- ChainBypassButton bypassButton;
- AddCardButton addCard;
- DockKnob blend, reverb, echo;
- juce::Viewport view;
- Strip strip { *this };
- std::vector<std::unique_ptr<Card>> cards;
- int dragging = -1, dropAt = -1;
- };
- // =====================================================================================================================
- // Instrument
- // =====================================================================================================================
- class SimpleDock::InstrumentPage final : public juce::Component,
- private juce::Timer
- {
- public:
- InstrumentPage (AudioEngine& e, Hooks& h) : engine (e), hooks (h), categoryModel (*this), soundModel (*this)
- {
- styleCaption (soundCaption, tr ("Sound"));
- addAndMakeVisible (soundCaption);
- prev.setTooltip (tr ("Previous sound"));
- prev.onClick = [this] { stepSound (-1); };
- next.setTooltip (tr ("Next sound"));
- next.onClick = [this] { stepSound (1); };
- addAndMakeVisible (prev);
- addAndMakeVisible (next);
- name.setFont (font (type::title, true));
- name.setColour (juce::Label::textColourId, colour::textPrimary);
- name.setJustificationType (juce::Justification::centred);
- name.setMinimumHorizontalScale (0.7f);
- addAndMakeVisible (name);
- styleCaption (detail, {});
- detail.setJustificationType (juce::Justification::centred);
- addAndMakeVisible (detail);
- editorButton.setButtonText (tr ("Open full editor"));
- editorButton.setTooltip (tr ("Opens the instrument's own window with every control"));
- editorButton.onClick = [this] {
- if (channel >= 0 && hooks.toggleChannelWindow)
- hooks.toggleChannelWindow (channel);
- };
- addAndMakeVisible (editorButton);
- keysButton.setButtonText (tr ("Keyboard"));
- keysButton.setTooltip (tr ("Shows the on-screen keyboard to play this track"));
- keysButton.onClick = [this] {
- if (hooks.showKeys)
- hooks.showKeys();
- };
- addAndMakeVisible (keysButton);
- search.setTextToShowWhenEmpty (tr ("Search sounds"), colour::textDisabled);
- search.onTextChange = [this] { refilter(); };
- search.setTitle (tr ("Search sounds"));
- addAndMakeVisible (search);
- ownButton.setButtonText (tr ("LYNX sounds"));
- fontsButton.setButtonText (tr ("My SoundFonts"));
- fontsButton.setTooltip (tr ("The sounds of your own .sf2 and .sf3 files"));
- pluginsButton.setButtonText (tr ("My plugins"));
- pluginsButton.setTooltip (tr ("The instrument plugins installed on this computer"));
- for (auto* b : { &ownButton, &fontsButton, &pluginsButton })
- {
- b->setClickingTogglesState (true);
- b->setRadioGroupId (1902);
- addAndMakeVisible (*b);
- }
- ownButton.setConnectedEdges (juce::Button::ConnectedOnRight);
- fontsButton.setConnectedEdges (juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight);
- pluginsButton.setConnectedEdges (juce::Button::ConnectedOnLeft);
- ownButton.setToggleState (true, juce::dontSendNotification);
- ownButton.onClick = [this] {
- if (ownButton.getToggleState())
- setSource (From::own);
- };
- fontsButton.onClick = [this] {
- if (fontsButton.getToggleState())
- setSource (From::fonts);
- };
- pluginsButton.onClick = [this] {
- if (pluginsButton.getToggleState())
- setSource (From::plugins);
- };
- folderButton.setButtonText (tr ("Add folder..."));
- folderButton.setTooltip (tr ("Adds a folder with your SoundFont files to the list"));
- folderButton.onClick = [this] { addFolder(); };
- addChildComponent (folderButton);
- categories.setModel (&categoryModel);
- categories.setRowHeight (rowHeight);
- categories.setColour (juce::ListBox::backgroundColourId, colour::bg1);
- categories.setTitle (tr ("Category"));
- addAndMakeVisible (categories);
- sounds.setModel (&soundModel);
- sounds.setRowHeight (rowHeight);
- sounds.setColour (juce::ListBox::backgroundColourId, colour::bg1);
- sounds.setTitle (tr ("Sounds"));
- addAndMakeVisible (sounds);
- styleCaption (listHint, {});
- listHint.setFont (font (type::body));
- listHint.setJustificationType (juce::Justification::centred);
- addChildComponent (listHint);
- }
- ~InstrumentPage() override { stopTimer(); }
- void show (int newChannel)
- {
- channel = newChannel;
- refresh();
- }
- void refresh()
- {
- if (! isVisible()) // (the Effects tab is in front: nothing of the list is worked out until it shows)
- {
- stale = true;
- return;
- }
- stale = false;
- const auto& song = engine.getSong();
- const bool has = channel >= 0 && channel < (int) song.channels.size();
- prev.setEnabled (has);
- next.setEnabled (has);
- editorButton.setEnabled (has);
- if (! has)
- {
- name.setText ({}, juce::dontSendNotification);
- detail.setText ({}, juce::dontSendNotification);
- current = -1;
- sounds.repaint();
- return;
- }
- const auto& def = song.channels[(std::size_t) channel];
- // which sound of the list the channel plays (looked up again only when its instrument changed)
- if (! known || ! soundlib::sameSound (lastDef, def) || lastListSize != list().size())
- {
- current = soundlib::find (list(), def);
- currentOwn = from != From::own ? soundlib::find (soundlib::builtIn(), def) : current;
- lastDef = def;
- lastListSize = list().size();
- known = true;
- }
- const soundlib::Sound* sound = current >= 0 ? &list()[(std::size_t) current]
- : currentOwn >= 0 ? &soundlib::builtIn()[(std::size_t) currentOwn] : nullptr;
- if (sound != nullptr)
- {
- name.setText (utf8 (sound->name), juce::dontSendNotification);
- detail.setText (soundCategoryText (sound->category) + glyph (" \xc2\xb7 ") + utf8 (sound->origin), juce::dontSendNotification);
- }
- else
- {
- name.setText (utf8 (def.name), juce::dontSendNotification);
- detail.setText (tr ("Its own sound"), juce::dontSendNotification);
- }
- if (current >= 0 && ! categoryPicked)
- category = (int) list()[(std::size_t) current].category;
- else if (! categoryPicked && soundlib::filter (list(), (soundlib::Category) category).empty())
- for (int c = 0; c < (int) soundlib::Category::count; ++c) // (the first category this list has sounds in)
- if (! soundlib::filter (list(), (soundlib::Category) c).empty())
- {
- category = c;
- break;
- }
- refilter();
- }
- void resized() override
- {
- auto r = getLocalBounds().reduced (pad);
- auto side = r.removeFromLeft (sideWidth - pad);
- soundCaption.setBounds (side.removeFromTop (16));
- // round 190jc (SG-9, BandLab's "‹ Studio Grand ›" field): a 32 px field with the chevrons in 28 px ends
- auto row = side.removeFromTop (32);
- pickerField = row;
- prev.setBounds (row.removeFromLeft (28));
- next.setBounds (row.removeFromRight (28));
- name.setBounds (row);
- detail.setBounds (side.removeFromTop (18));
- side.removeFromTop (8);
- editorButton.setBounds (side.removeFromTop (26));
- side.removeFromTop (6);
- keysButton.setBounds (side.removeFromTop (26));
- r.removeFromLeft (pad + 1 + pad);
- auto top = r.removeFromTop (26);
- ownButton.setBounds (top.removeFromLeft (juce::jmin (120, top.getWidth() / 5)));
- fontsButton.setBounds (top.removeFromLeft (juce::jmin (130, top.getWidth() / 4)));
- pluginsButton.setBounds (top.removeFromLeft (juce::jmin (110, top.getWidth() / 3)));
- top.removeFromLeft (pad);
- if (folderButton.isVisible())
- {
- folderButton.setBounds (top.removeFromRight (juce::jmin (130, top.getWidth() / 3)));
- top.removeFromRight (pad);
- }
- search.setBounds (top.withWidth (juce::jmin (top.getWidth(), 280)));
- r.removeFromTop (6);
- categories.setBounds (r.removeFromLeft (juce::jmin (categoryWidth, r.getWidth() / 3)));
- r.removeFromLeft (6);
- sounds.setBounds (r);
- listHint.setBounds (r.reduced (12));
- }
- void paint (juce::Graphics& g) override
- {
- g.setColour (colour::border);
- g.fillRect (sideWidth, pad, 1, getHeight() - 2 * pad);
- g.setColour (colour::bg4);
- g.fillRoundedRectangle (pickerField.toFloat(), radius::lg);
- }
- juce::Rectangle<int> pickerField;
- void visibilityChanged() override
- {
- if (isVisible() && stale)
- refresh();
- updateTimer();
- }
- void parentHierarchyChanged() override { updateTimer(); }
- // --- the list ----------------------------------------------------------------------------------------------------
- enum class From { own, fonts, plugins };
- const std::vector<soundlib::Sound>& list() const
- {
- return from == From::fonts ? fontSounds : from == From::plugins ? pluginSounds : soundlib::builtIn();
- }
- void setSource (From source)
- {
- from = source;
- fonts = from == From::fonts;
- (from == From::fonts ? fontsButton : from == From::plugins ? pluginsButton : ownButton).setToggleState (true, juce::dontSendNotification);
- folderButton.setVisible (fonts);
- if (fonts && ! injected)
- {
- ensureSoundFontIndex();
- takeFonts();
- }
- if (from == From::plugins && ! pluginsInjected)
- takePlugins();
- known = false;
- categoryPicked = false;
- resized();
- refresh();
- updateTimer();
- }
- void setFonts (std::vector<sf::IndexedFont> indexed, bool inject)
- {
- injected = inject;
- fontSounds = soundlib::fromFonts (indexed);
- known = false;
- }
- void pickCategory (int c)
- {
- category = juce::jlimit (0, (int) soundlib::Category::count - 1, c);
- categoryPicked = true;
- refilter();
- }
- void refilter()
- {
- rows = soundlib::filter (list(), (soundlib::Category) category, search.getText().toStdString());
- counts.assign ((std::size_t) soundlib::Category::count, 0);
- for (int c = 0; c < (int) soundlib::Category::count; ++c)
- counts[(std::size_t) c] = (int) soundlib::filter (list(), (soundlib::Category) c, search.getText().toStdString()).size();
- // the categories this source has sounds in (a search greys the ones without a match, it doesn't remove them)
- shownCategories.clear();
- for (int c = 0; c < (int) soundlib::Category::count; ++c)
- if (! soundlib::filter (list(), (soundlib::Category) c).empty())
- shownCategories.push_back (c);
- categories.updateContent();
- const auto shown = std::find (shownCategories.begin(), shownCategories.end(), category);
- if (shown != shownCategories.end())
- categories.selectRow ((int) (shown - shownCategories.begin()), true, true);
- else
- categories.deselectAllRows();
- categories.repaint();
- sounds.updateContent();
- const auto it = std::find (rows.begin(), rows.end(), current);
- if (it != rows.end())
- sounds.selectRow ((int) (it - rows.begin()), true, true);
- else
- sounds.deselectAllRows();
- sounds.repaint();
- const bool noFonts = fonts && fontSounds.empty();
- const bool noPlugins = from == From::plugins && pluginSounds.empty();
- listHint.setVisible (noFonts || noPlugins || rows.empty());
- listHint.setText (noFonts ? (sf::PresetIndex::shared().busy() && ! injected
- ? tr ("Looking for your SoundFont files...")
- : tr ("No SoundFont files found yet. Add a folder with your .sf2 or .sf3 files."))
- : noPlugins ? tr ("No instrument plugins found yet. Scan for plugins in the Plugin manager.")
- : rows.empty() ? tr ("No sounds here.") : juce::String(),
- juce::dontSendNotification);
- }
- // --- picking and hearing -----------------------------------------------------------------------------------------
- bool audition (const soundlib::Sound& s)
- {
- const auto def = soundlib::channelFor (s);
- return def && engine.auditionSound (*def, soundlib::auditionKeys (s));
- }
- void pick (int listIndex, bool hear)
- {
- if (listIndex < 0 || listIndex >= (int) list().size() || channel < 0)
- return;
- const auto sound = list()[(std::size_t) listIndex];
- const auto c = channel;
- bool done = false;
- engine.editSongStructural ([c, &sound, &done] (Song& s) {
- if (c >= (int) s.channels.size())
- return;
- if (auto next = soundlib::withSound (s.channels[(std::size_t) c], sound))
- {
- s.channels[(std::size_t) c] = std::move (*next);
- done = true;
- }
- });
- if (done && hear)
- {
- if (sound.source == soundlib::Source::plugin) // (heard on the track itself, as it loaded)
- engine.auditionChannelSound (c);
- else
- audition (sound);
- }
- }
- void stepSound (int delta)
- {
- const auto fallback = (soundlib::Category) category;
- const auto to = soundlib::step (list(), current, delta, fallback);
- if (to >= 0)
- {
- categoryPicked = false;
- pick (to, true);
- }
- }
- void clickRow (int row, bool previewOnly)
- {
- if (row < 0 || row >= (int) rows.size())
- return;
- // (a plugin can only be heard once it runs on the track: its ▶ uses it too, and Ctrl+Z goes back)
- if (previewOnly && list()[(std::size_t) rows[(std::size_t) row]].source != soundlib::Source::plugin)
- audition (list()[(std::size_t) rows[(std::size_t) row]]);
- else
- pick (rows[(std::size_t) row], true);
- }
- int rowCount() const noexcept { return (int) rows.size(); }
- void searchFor (const juce::String& text)
- {
- search.setText (text, false);
- refilter(); // (what typing does, at once: the editor's own change message is posted)
- }
- juce::String shownName() const { return name.getText() + " [" + detail.getText() + "]"; }
- AudioEngine& engine;
- Hooks& hooks;
- int channel = -1;
- private:
- struct CategoryModel final : juce::ListBoxModel
- {
- explicit CategoryModel (InstrumentPage& p) : page (p) {}
- int getNumRows() override { return (int) page.shownCategories.size(); }
- void paintListBoxItem (int index, juce::Graphics& g, int width, int height, bool selected) override
- {
- if (index < 0 || index >= (int) page.shownCategories.size())
- return;
- const auto row = page.shownCategories[(std::size_t) index];
- const auto n = row < (int) page.counts.size() ? page.counts[(std::size_t) row] : 0;
- if (selected)
- fillRoundRect (g, juce::Rectangle<float> (0.0f, 1.0f, (float) width, (float) height - 2.0f), radius::sm, colour::accentMuted);
- g.setColour (n == 0 ? colour::textDisabled : selected ? colour::textPrimary : colour::textSecondary);
- g.setFont (font (type::body, selected));
- g.drawText (soundCategoryText ((soundlib::Category) row), 10, 0, width - 50, height, juce::Justification::centredLeft, true);
- // (round 190oo, CS-31: the counts were textDisabled, 2.95:1 on the list; #8f939b reads >= 4.5:1, the selected row's
- // textSecondary on accentMuted too; an empty category's 0 stays disabled with its name)
- g.setColour (n == 0 ? colour::textDisabled : selected ? colour::textSecondary : juce::Colour (0xff8f939b));
- g.setFont (font (type::caption));
- g.drawText (juce::String (n), width - 40, 0, 32, height, juce::Justification::centredRight, false);
- }
- void selectedRowsChanged (int index) override
- {
- if (index >= 0 && index < (int) page.shownCategories.size() && page.shownCategories[(std::size_t) index] != page.category)
- page.pickCategory (page.shownCategories[(std::size_t) index]);
- }
- juce::String getNameForRow (int index) override
- {
- return index >= 0 && index < (int) page.shownCategories.size() ? soundCategoryText ((soundlib::Category) page.shownCategories[(std::size_t) index])
- : juce::String();
- }
- InstrumentPage& page;
- };
- struct SoundModel final : juce::ListBoxModel
- {
- explicit SoundModel (InstrumentPage& p) : page (p) {}
- int getNumRows() override { return (int) page.rows.size(); }
- void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool) override
- {
- if (row < 0 || row >= (int) page.rows.size())
- return;
- const auto index = page.rows[(std::size_t) row];
- const auto& s = page.list()[(std::size_t) index];
- const bool isCurrent = index == page.current;
- if (isCurrent)
- fillRoundRect (g, juce::Rectangle<float> (0.0f, 1.0f, (float) width, (float) height - 2.0f), radius::sm, colour::accentMuted);
- else if (row % 2 == 1)
- g.fillAll (colour::bg2.withAlpha (0.5f));
- // ▶: hear it without choosing it
- juce::Path play;
- const auto cx = 15.0f, cy = (float) height * 0.5f;
- play.addTriangle (cx - 4.0f, cy - 5.5f, cx - 4.0f, cy + 5.5f, cx + 5.5f, cy);
- g.setColour (isCurrent ? colour::accent : colour::textSecondary);
- g.fillPath (play);
- g.setColour (isCurrent ? colour::textPrimary : colour::textPrimary.withAlpha (0.9f));
- g.setFont (font (type::body, isCurrent));
- const auto originWidth = juce::jmin (180, width / 3);
- g.drawText (utf8 (s.name), 32, 0, width - 40 - originWidth, height, juce::Justification::centredLeft, true);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::small));
- g.drawText (utf8 (s.origin), width - originWidth - 8, 0, originWidth, height, juce::Justification::centredRight, true);
- }
- void listBoxItemClicked (int row, const juce::MouseEvent& e) override { page.clickRow (row, e.x < 30); }
- void returnKeyPressed (int row) override { page.clickRow (row, false); }
- juce::String getNameForRow (int row) override
- {
- return row >= 0 && row < (int) page.rows.size() ? utf8 (page.list()[(std::size_t) page.rows[(std::size_t) row]].name) : juce::String();
- }
- juce::String getTooltipForRow (int) override
- {
- return page.from == From::plugins ? tr ("Click to load this plugin on the track and hear it (Ctrl+Z goes back)")
- : tr ("Click to use this sound; the arrow plays it without choosing it");
- }
- InstrumentPage& page;
- };
- // the plugin host's scanned instruments (the list the plugin picker shows)
- void takePlugins()
- {
- std::vector<soundlib::InstalledPlugin> installed;
- for (const auto& t : engine.getPluginHost().getKnownPlugins().getTypes())
- if (t.isInstrument)
- installed.push_back ({ t.createIdentifierString().toStdString(), t.name.toStdString(), t.manufacturerName.toStdString(),
- t.pluginFormatName.toStdString(), t.category.toStdString() });
- pluginSounds = soundlib::fromPlugins (installed);
- known = false;
- }
- public:
- void setPlugins (std::vector<soundlib::InstalledPlugin> installed)
- {
- pluginsInjected = true;
- pluginSounds = soundlib::fromPlugins (installed);
- known = false;
- }
- private:
- void takeFonts()
- {
- auto& index = sf::PresetIndex::shared();
- generation = index.generation();
- fontSounds = soundlib::fromFonts (index.fonts());
- known = false;
- }
- // the SoundFont index fills in the background: follow it only while its list is on screen
- void updateTimer()
- {
- if (fonts && ! injected && isShowing())
- startTimer (500);
- else
- stopTimer();
- }
- void timerCallback() override
- {
- if (sf::PresetIndex::shared().generation() != generation)
- {
- takeFonts();
- refresh();
- }
- }
- void addFolder()
- {
- chooser = lynx::ui::makeFileChooser (tr ("Add a SoundFont folder"), juce::File::getSpecialLocation (juce::File::userDocumentsDirectory));
- juce::Component::SafePointer<InstrumentPage> safe (this);
- lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
- [safe] (const juce::FileChooser& fc) {
- if (fc.getResult() == juce::File())
- return;
- // (the same list the LYNX Soundfont editor's "SoundFont folders" menu keeps)
- auto lines = juce::StringArray::fromLines (soundFontFoldersFile().loadFileAsString());
- lines.removeEmptyStrings();
- lines.addIfNotAlreadyThere (fc.getResult().getFullPathName());
- soundFontFoldersFile().getParentDirectory().createDirectory();
- soundFontFoldersFile().replaceWithText (lines.joinIntoString ("\n") + "\n");
- ensureSoundFontIndex (true);
- if (safe != nullptr)
- safe->refilter();
- });
- }
- juce::Label soundCaption, name, detail, listHint;
- GlyphButton prev { glyph ("\xe2\x80\xb9"), ui::simplelook::Glyph::chevronLeft, { 6.0f, 10.0f }, false },
- next { glyph ("\xe2\x80\xba"), ui::simplelook::Glyph::chevronRight, { 6.0f, 10.0f }, false };
- juce::TextButton editorButton, keysButton, ownButton, fontsButton, pluginsButton, folderButton;
- juce::TextEditor search;
- CategoryModel categoryModel;
- SoundModel soundModel;
- juce::ListBox categories, sounds;
- std::unique_ptr<juce::FileChooser> chooser;
- std::vector<soundlib::Sound> fontSounds, pluginSounds;
- std::vector<int> rows, counts, shownCategories;
- ChannelDef lastDef;
- std::size_t lastListSize = 0;
- int category = 0, current = -1, currentOwn = -1, generation = -1;
- bool fonts = false, injected = false, pluginsInjected = false, known = false, categoryPicked = false, stale = true;
- From from = From::own;
- };
- // =====================================================================================================================
- // The dock
- // =====================================================================================================================
- // --- Editor: the Piano roll docked on the track's pattern (round 190ds) ---------------------------------------------
- class SimpleDock::EditorPage final : public juce::Component
- {
- public:
- EditorPage (AudioEngine& e, Hooks& h) : engine (e), hooks (h)
- {
- fold.setButtonText (tr ("Only notes in key"));
- fold.setTooltip (tr ("Shows only the rows of the project key's notes"));
- fold.onClick = [this] {
- if (hooks.setFoldToKey)
- hooks.setFoldToKey (fold.getToggleState());
- };
- open.setButtonText (tr ("Open in the Piano roll"));
- open.setTooltip (tr ("The full Piano roll window, with every tool"));
- open.onClick = [this] {
- if (hooks.openPianoRollPanel)
- hooks.openPianoRollPanel();
- };
- again.setButtonText (tr ("Show the editor here"));
- again.onClick = [this] {
- takenBack = false;
- update();
- };
- makePattern.setButtonText (tr ("New pattern"));
- makePattern.setTooltip (tr ("An empty 4-bar pattern on this track, to write notes into"));
- makePattern.onClick = [this] { make(); };
- // round 190mc (discussion #105): the Chord helper of the docked editor, in the Simple look
- chordHelper.setButtonText (tr ("Chord helper"));
- chordHelper.setTooltip (tr ("Select a chord: related keys and borrowed chords to insert after it"));
- chordHelper.onClick = [this] {
- if (auto* roll = dynamic_cast<PianoRollComponent*> (editor))
- roll->openChordHelper();
- };
- addAndMakeVisible (chordHelper);
- addAndMakeVisible (fold);
- addAndMakeVisible (open);
- addChildComponent (again);
- addChildComponent (makePattern);
- }
- ~EditorPage() override { release(); }
- void show (int newTrack, int newChannel)
- {
- if (newTrack != track)
- takenBack = false;
- track = newTrack;
- channel = newChannel;
- update();
- }
- // Docks the Piano roll on the track's pattern while this page shows. A track without a pattern gets one the first
- // time (after this call returns: no song edit inside the dock's own refresh); after an undo removed it, a button.
- void update()
- {
- const auto& song = engine.getSong();
- const auto pattern = track >= 0 ? simpletracks::editorPattern (song, track) : -1;
- const auto canHave = track >= 0 && (simpletracks::kindOf (song, track) == simpletracks::Kind::instrument
- || simpletracks::kindOf (song, track) == simpletracks::Kind::sampler);
- if (! shownInTree() || ! canHave)
- {
- release();
- refreshControls (pattern);
- return;
- }
- if (pattern < 0)
- {
- release();
- if (made.count (song.playlistTracks[(std::size_t) track].channel) == 0 && ! pendingMake)
- {
- pendingMake = true;
- juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<EditorPage> (this)] {
- if (safe != nullptr)
- {
- safe->pendingMake = false;
- if (safe->shownInTree())
- safe->make();
- }
- });
- }
- refreshControls (pattern);
- return;
- }
- if (channel >= 0 && engine.getSelectedChannel() != channel)
- engine.setSelectedChannel (channel); // (the Piano roll shows the selected channel's notes)
- if (! takenBack && (editor == nullptr || dockedPattern != pattern || song.currentPattern != pattern) && hooks.dockPianoRoll)
- {
- if (auto* e = hooks.dockPianoRoll (pattern))
- {
- editor = e;
- dockedPattern = pattern;
- addAndMakeVisible (*editor);
- resized();
- }
- }
- refreshControls (pattern);
- }
- void release()
- {
- if (editor != nullptr && hooks.undockPianoRoll)
- {
- editor = nullptr;
- hooks.undockPianoRoll();
- }
- editor = nullptr;
- dockedPattern = -1;
- }
- void takenBackByPanel()
- {
- if (editor != nullptr)
- {
- editor = nullptr;
- dockedPattern = -1;
- takenBack = true;
- }
- refreshControls (dockedPattern);
- }
- bool docked() const noexcept { return editor != nullptr; }
- void clickFold (bool on)
- {
- fold.setToggleState (on, juce::dontSendNotification);
- if (fold.onClick)
- fold.onClick();
- }
- void visibilityChanged() override { update(); }
- void parentHierarchyChanged() override
- {
- if (! shownInTree())
- release();
- }
- // visible with all its parents (isShowing() also asks for a window on the desktop, which --snapshot has not)
- bool shownInTree() const
- {
- for (auto* c = static_cast<const juce::Component*> (this); c != nullptr; c = c->getParentComponent())
- if (! c->isVisible())
- return false;
- return getParentComponent() != nullptr;
- }
- void resized() override
- {
- auto bar = getLocalBounds().removeFromTop (barHeight).reduced (10, 4);
- open.setBounds (bar.removeFromRight (170));
- bar.removeFromRight (8);
- fold.setBounds (bar.removeFromRight (160));
- bar.removeFromRight (8);
- chordHelper.setBounds (bar.removeFromRight (120));
- const auto body = getLocalBounds().withTrimmedTop (barHeight);
- again.setBounds (body.withSizeKeepingCentre (220, 30));
- makePattern.setBounds (body.withSizeKeepingCentre (160, 30));
- if (editor != nullptr)
- editor->setBounds (body);
- }
- void paint (juce::Graphics& g) override
- {
- g.fillAll (colour::bg1);
- const auto& song = engine.getSong();
- auto bar = getLocalBounds().removeFromTop (barHeight).reduced (12, 0);
- const auto pattern = track >= 0 ? simpletracks::editorPattern (song, track) : -1;
- g.setColour (colour::textSecondary);
- g.setFont (font (type::small));
- if (pattern >= 0)
- g.drawText (tr ("Notes of {0}", { utf8 (song.patterns[(std::size_t) pattern].name) }), bar, juce::Justification::centredLeft, true);
- if (editor == nullptr)
- {
- g.setFont (font (type::body));
- const auto body = getLocalBounds().withTrimmedTop (barHeight).withTrimmedBottom (80);
- g.drawText (takenBack ? tr ("The Piano roll is open in its own window") : pattern < 0 ? tr ("This track has no pattern yet") : juce::String(),
- body, juce::Justification::centred, true);
- }
- }
- static constexpr int barHeight = 30;
- private:
- void make()
- {
- if (track < 0)
- return;
- const auto t = track;
- int ch = -1;
- if (t < (int) engine.getSong().playlistTracks.size())
- ch = engine.getSong().playlistTracks[(std::size_t) t].channel;
- made.insert (ch);
- engine.editSong ([t] (Song& s) { simpletracks::ensurePattern (s, t, 4); });
- update();
- }
- void refreshControls (int pattern)
- {
- const auto& song = engine.getSong();
- fold.setEnabled (projectkey::get (song).has_value() && editor != nullptr);
- chordHelper.setEnabled (editor != nullptr);
- fold.setToggleState (hooks.foldedToKey && hooks.foldedToKey(), juce::dontSendNotification);
- again.setVisible (takenBack && editor == nullptr);
- makePattern.setVisible (! takenBack && editor == nullptr && pattern < 0 && track >= 0 && ! pendingMake);
- repaint();
- }
- AudioEngine& engine;
- Hooks& hooks;
- juce::ToggleButton fold;
- juce::TextButton open, again, makePattern, chordHelper;
- juce::Component* editor = nullptr; // the main window's Piano roll while docked here (not owned)
- int track = -1, channel = -1, dockedPattern = -1;
- bool takenBack = false, pendingMake = false;
- std::set<int> made; // channels whose pattern this page made once (an undo then asks, it doesn't make it again)
- };
- // =====================================================================================================================
- // Pads (round 190fo): the Sampler track's 16 pads (core/SimplePads.h)
- // =====================================================================================================================
- namespace
- {
- // LYNX's own pad colours (index 1…8; 0 = the track's colour)
- juce::Colour padColour (int index, juce::Colour track)
- {
- static const juce::uint32 palette[simplepads::colourCount] { 0xffe5383b, 0xffe8833a, 0xffe2c044, 0xff5fbf6a,
- 0xff3fb6b0, 0xff4f8ee0, 0xff9a6fe0, 0xffe06aa8 };
- return index >= 1 && index <= simplepads::colourCount ? juce::Colour (palette[index - 1]) : track;
- }
- juce::String padColourName (int index)
- {
- switch (index)
- {
- case 1: return trc ("@colour: Red");
- case 2: return trc ("@colour: Orange");
- case 3: return trc ("@colour: Yellow");
- case 4: return trc ("@colour: Green");
- case 5: return trc ("@colour: Teal");
- case 6: return trc ("@colour: Blue");
- case 7: return trc ("@colour: Violet");
- case 8: return trc ("@colour: Pink");
- default: break;
- }
- return tr ("Track colour");
- }
- // the pad knobs' names
- juce::String padKnobName (int k)
- {
- switch (k)
- {
- case 0: return tr ("Attack");
- case 1: return tr ("Release");
- case 2: return tr ("Tone");
- case 3: return tr ("Pitch");
- case 4: return trc ("@mixer: Pan");
- default: break;
- }
- return trc ("@mixer: Volume");
- }
- juce::String modeText (simplepads::Mode m)
- {
- return m == simplepads::Mode::gate ? trc ("@pad mode: Gate") : m == simplepads::Mode::oneShot ? tr ("One-shot") : trc ("@pad mode: Loop");
- }
- juce::String toneLabel (float tone)
- {
- const auto t = simplepads::toneFilter (tone);
- if (! t.on)
- return tr ("Off");
- const auto hz = t.cutoff >= 1000.0f ? juce::String (t.cutoff / 1000.0f, 1) + " kHz" : juce::String (juce::roundToInt (t.cutoff)) + " Hz";
- return (t.filterType == 0 ? tr ("Low-pass") : tr ("High-pass")) + " " + hz;
- }
- // the knobs' laws: the dock's knob is 0…1
- float attackFrom (float v) { return v * v * simplepads::maxAttack; }
- float attackTo (float s) { return std::sqrt (juce::jlimit (0.0f, 1.0f, s / simplepads::maxAttack)); }
- float releaseFrom (float v) { return v * v * simplepads::maxRelease; }
- float releaseTo (float s) { return std::sqrt (juce::jlimit (0.0f, 1.0f, s / simplepads::maxRelease)); }
- juce::String secondsText (float s) { return s < 1.0f ? juce::String (juce::roundToInt (s * 1000.0f)) + " ms" : juce::String (s, 2) + " s"; }
- juce::String panText (float pan)
- {
- const auto p = juce::roundToInt (pan * 100.0f);
- return p == 0 ? tr ("Centre") : p < 0 ? "L " + juce::String (-p) : "R " + juce::String (p);
- }
- juce::String pitchText (float semis)
- {
- const auto cents = juce::roundToInt (semis * 100.0f);
- if (cents % 100 == 0)
- return (cents > 0 ? "+" : "") + juce::String (cents / 100) + " st";
- return (semis > 0.0f ? "+" : "") + juce::String (semis, 2) + " st";
- }
- } // namespace
- class SimpleDock::PadsPage final : public juce::Component,
- public juce::FileDragAndDropTarget,
- public juce::DragAndDropTarget,
- private juce::Timer
- {
- public:
- explicit PadsPage (AudioEngine& e) : engine (e)
- {
- load.setButtonText (tr ("Import..."));
- load.setTooltip (tr ("Put an audio file on the selected pad"));
- load.onClick = [this] { chooseFile (selected); };
- browse.setButtonText (tr ("Browse sounds"));
- browse.setTooltip (tr ("The sample browser: drag a sound onto a pad"));
- browse.onClick = [this] {
- if (onBrowse)
- onBrowse();
- };
- // round 190mr (DS-36, BandLab's empty sampler, bandlab190p 21-sampler-empty.png + capture 190mr C1): an empty pad's
- // three calls to action — Record via an audio input, import a file, Browse Sounds — each a pill under its icon
- ctaRecord.setButtonText (tr ("Record"));
- ctaRecord.onClick = [this] { recording ? stopPadRecording() : startPadRecording(); };
- ctaImport.setButtonText (tr ("Import"));
- ctaImport.onClick = [this] { chooseFile (selected); };
- ctaBrowse.setButtonText (tr ("Browse"));
- ctaBrowse.onClick = [this] {
- if (onBrowse)
- onBrowse();
- };
- for (auto* b : { &ctaRecord, &ctaImport, &ctaBrowse })
- addChildComponent (*b);
- kit.setButtonText (tr ("Kit"));
- kit.setTooltip (tr ("Save the pads as a kit, open one of your kits, or fill the pads from a folder"));
- kit.onClick = [this] { showKitMenu(); };
- reverse.setButtonText (tr ("Reverse"));
- reverse.onClick = [this] { edit ([on = reverse.getToggleState()] (ChannelDef& c) { c.sampler.reverse = on; }); };
- normalize.setButtonText (tr ("Normalize"));
- normalize.setTooltip (tr ("Brings the pad's loudest point to full level"));
- normalize.onClick = [this] { normalizePad(); };
- group.setTooltip (tr ("Pads of the same group cut each other off (an open and a closed hi-hat)"));
- group.onClick = [this] { showGroupMenu(); };
- for (int m = 0; m < 3; ++m)
- {
- auto& b = modes[(std::size_t) m];
- b.setButtonText (modeText ((simplepads::Mode) m));
- b.setClickingTogglesState (true);
- b.setRadioGroupId (1902);
- b.onClick = [this, m, &b] {
- if (b.getToggleState())
- edit ([m] (ChannelDef& c) { c.simplePad.mode = (std::uint8_t) m; });
- };
- addAndMakeVisible (b);
- }
- modes[0].setTooltip (tr ("Plays while the key is held"));
- modes[1].setTooltip (tr ("Plays to its end, however short the hit"));
- modes[2].setTooltip (tr ("Repeats while the key is held"));
- for (int k = 0; k < knobCount; ++k)
- {
- auto& knob = knobs[(std::size_t) k];
- styleCaption (captions[(std::size_t) k], padKnobName (k));
- captions[(std::size_t) k].setJustificationType (juce::Justification::centred);
- addAndMakeVisible (captions[(std::size_t) k]);
- knob.onChange = [this, k] (float v) { turn (k, v); };
- addAndMakeVisible (knob);
- }
- knobs[0].resetValue = 0.0f;
- knobs[0].valueText = [] (float v) { return secondsText (attackFrom (v)); };
- knobs[1].resetValue = 0.0f;
- knobs[1].valueText = [] (float v) { return secondsText (releaseFrom (v)); };
- knobs[2].valueText = [] (float v) { return toneLabel (v * 2.0f - 1.0f); };
- knobs[3].valueText = [] (float v) { return pitchText ((v * 2.0f - 1.0f) * simplepads::maxPitch); };
- knobs[4].valueText = [] (float v) { return panText (v * 2.0f - 1.0f); };
- knobs[5].resetValue = 0.78f;
- knobs[2].setTooltip (tr ("Left: darker (low-pass). Right: thinner (high-pass). Middle: off"));
- knobs[3].setTooltip (tr ("In semitones; Shift + drag for cents"));
- for (auto* c : std::initializer_list<juce::Component*> { &load, &browse, &kit, &reverse, &normalize, &group })
- addAndMakeVisible (c);
- setWantsKeyboardFocus (false);
- }
- std::function<void()> onBrowse;
- void show (int newTrack)
- {
- track = newTrack;
- update();
- }
- void update()
- {
- const auto& song = engine.getSong();
- channels = simplepads::padChannels (song, track);
- const auto c = channelOf (selected);
- const bool has = c != nullptr && ! c->samplePath.empty();
- if (c != nullptr)
- {
- const auto mode = simplepads::modeOf (*c);
- modes[(std::size_t) mode].setToggleState (true, juce::dontSendNotification);
- knobs[0].setValue (attackTo (c->sampler.attack));
- knobs[1].setValue (releaseTo (c->simplePad.release));
- knobs[2].setValue ((c->simplePad.tone + 1.0f) * 0.5f);
- knobs[3].setValue ((c->sampler.pitch / simplepads::maxPitch + 1.0f) * 0.5f);
- knobs[4].setValue ((c->pan + 1.0f) * 0.5f);
- knobs[5].setValue (c->volume);
- reverse.setToggleState (c->sampler.reverse, juce::dontSendNotification);
- group.setButtonText (tr ("Group: {0}", { c->simplePad.group > 0 ? juce::String (c->simplePad.group) : tr ("None") }));
- knobs[1].setDimmed (mode == simplepads::Mode::oneShot);
- }
- for (auto* comp : std::initializer_list<juce::Component*> { &reverse, &normalize, &group, &modes[0], &modes[1], &modes[2] })
- comp->setEnabled (has);
- for (auto& k : knobs)
- k.setEnabled (has);
- for (auto* b : { &ctaRecord, &ctaImport, &ctaBrowse }) // round 190mr (DS-36): an empty pad's calls to action
- b->setVisible (! has || recording);
- styleRecordCta();
- waveFor = {};
- resized();
- repaint();
- }
- int selectedPad() const noexcept { return selected; }
- void select (int pad)
- {
- selected = juce::jlimit (0, simplepads::padCount - 1, pad);
- update();
- }
- // a click on pad `pad`, as the mouse does (tests, --reabl190foshot)
- void hit (int pad)
- {
- select (pad);
- lightPad (selected);
- if (const auto ch = channelIndex (selected); ch >= 0 && hasSound (selected))
- {
- engine.sendLiveNote (ch, simplepads::padKey, 0.8f, true, true);
- engine.sendLiveNote (ch, simplepads::padKey, 0.0f, false, true);
- }
- repaint();
- }
- // tests / shots: the same edits the controls make
- void loadFileForCheck (int pad, const juce::File& file) { loadFile (pad, file); }
- void turnForCheck (int knob, float v) { knobs[(std::size_t) knob].turnTo (v); }
- void setModeForCheck (int mode) // (the button's own edit, at once: triggerClick would post it)
- {
- modes[(std::size_t) mode].setToggleState (true, juce::dontSendNotification);
- edit ([mode] (ChannelDef& c) { c.simplePad.mode = (std::uint8_t) mode; });
- }
- void dragPadForCheck (int from, int to, bool copy) { dropPad (from, to, copy); }
- void setRegionForCheck (float start, float end)
- {
- edit ([start, end] (ChannelDef& c) {
- c.sampler.regionStart = start;
- c.sampler.regionEnd = end;
- });
- }
- void normalizeForCheck() { normalizePad(); }
- juce::PopupMenu kitMenuForSnapshot() { return kitMenu(); }
- juce::PopupMenu padMenuForSnapshot (int pad) { return padMenu (pad); }
- void paint (juce::Graphics& g) override
- {
- const auto& song = engine.getSong();
- const auto trackColour = juce::Colour (track >= 0 && track < (int) song.playlistTracks.size() && song.playlistTracks[(std::size_t) track].colour != 0
- ? song.playlistTracks[(std::size_t) track].colour
- : simpletracks::defaultColour (simpletracks::Kind::pads));
- for (int p = 0; p < simplepads::padCount; ++p)
- {
- const auto r = padBounds (p).toFloat();
- const auto* c = channelOf (p);
- const bool has = c != nullptr && ! c->samplePath.empty();
- const auto tint = padColour (c != nullptr ? c->simplePad.colour : 0, trackColour);
- // round 190jc (design190ia SG-11): the label is black or white, whichever reads better on the pad (>= 4.58:1 on any
- // fill; white "Hat" on orange was 2.71:1). Round 190jj: a press darkens the plate (BandLab); the label keeps the
- // ink of the pad at rest, as BandLab's glyph keeps its colour
- const auto rest = has ? tint.withMultipliedBrightness (0.55f).withMultipliedSaturation (0.8f) : colour::bg2;
- const auto press = pressShown[(std::size_t) p];
- const auto fill = has && press > 0.0f ? rest.withMultipliedBrightness (1.0f - pressDepth * press) : rest;
- const auto ink = ui::simplelook::inkOn (rest);
- if (has)
- {
- fillRoundRect (g, r, radius::md, fill);
- g.setColour (ink);
- g.setFont (font (ui::simplelook::largeControls() ? type::body : type::small, true));
- g.drawFittedText (utf8 (c->name), r.reduced (6.0f, 4.0f).withTrimmedTop (12.0f).toNearestInt(), juce::Justification::centredLeft, 2, 0.8f);
- }
- else
- {
- fillRoundRect (g, r, radius::md, p == dropTarget ? colour::bg4 : colour::bg2);
- juce::Path frame, dashed;
- frame.addRoundedRectangle (r.reduced (0.5f), radius::md);
- const float dashes[] { 3.0f, 3.0f };
- juce::PathStrokeType (1.0f).createDashedStroke (dashed, frame, dashes, 2);
- g.setColour (colour::borderStrong);
- g.fillPath (dashed);
- g.setColour (colour::textDisabled);
- g.fillRect (juce::Rectangle<float> (10.0f, 1.5f).withCentre (r.getCentre()));
- g.fillRect (juce::Rectangle<float> (1.5f, 10.0f).withCentre (r.getCentre()));
- }
- // the typing key that plays it, top left
- g.setColour (has ? ink : colour::textSecondary);
- g.setFont (font (type::caption, true));
- g.drawText (juce::String::charToString ((juce::juce_wchar) simplepads::typingKey (p)), r.reduced (6.0f, 3.0f).toNearestInt(),
- juce::Justification::topLeft, false);
- if (p == selected)
- {
- g.setColour (colour::accent);
- g.drawRoundedRectangle (r.reduced (1.0f), radius::md, 2.0f);
- }
- if (p == selected && recording) // round 190mr (DS-36, capture 190mr C1): the pad being recorded is red with a dot
- {
- fillRoundRect (g, r.reduced (2.0f), radius::md, colour::accent.withAlpha (0.55f));
- g.setColour (colour::accent);
- g.fillEllipse (juce::Rectangle<float> (9.0f, 9.0f).withCentre (r.getCentre()));
- }
- if (p == dropTarget)
- {
- g.setColour (colour::textPrimary);
- g.drawRoundedRectangle (r.reduced (2.5f), radius::md, 1.0f);
- }
- }
- // the selected pad: its title and its waveform with the played region (not when only a pad repaints)
- if (! g.clipRegionIntersects (titleArea.getUnion (waveArea)))
- return;
- const auto* c = channelOf (selected);
- const bool has = c != nullptr && ! c->samplePath.empty();
- g.setColour (colour::textPrimary);
- g.setFont (font (type::body, true));
- const auto title = tr ("Pad {0}", { juce::String (selected + 1) })
- + (has ? juce::String::fromUTF8 (" \xc2\xb7 ") + utf8 (c->name) : juce::String())
- + juce::String::fromUTF8 (" \xc2\xb7 ") + tr ("key {0}", { juce::String::charToString ((juce::juce_wchar) simplepads::typingKey (selected)) });
- g.drawFittedText (title, titleArea, juce::Justification::centredLeft, 1, 0.8f);
- const auto w = waveArea.toFloat();
- fillRoundRect (g, w, radius::md, colour::bg0);
- if (! has || recording)
- {
- // round 190mr (DS-36): BandLab's three columns — icon, caption, the pill under them (the pills are buttons)
- static const char* const captions[] { TR_NOOP ("Record via an audio input"), TR_NOOP ("Drag and drop or import an audio file"),
- TR_NOOP ("Browse Sounds") };
- const Icon glyphs[] { Icon::mic, Icon::audioFile, Icon::listen };
- for (int k = 0; k < 3; ++k)
- {
- const auto column = ctaColumn (k);
- const auto icon = juce::Rectangle<float> (22.0f, 22.0f).withCentre ({ (float) column.getCentreX(), (float) column.getY() + 14.0f });
- icons::draw (g, glyphs[k], icon, k == 0 && recording ? colour::accent : colour::textPrimary);
- g.setColour (k == 0 && recording ? colour::accent : colour::textSecondary);
- g.setFont (font (type::small));
- g.drawFittedText (k == 0 && recording ? tr ("Recording...") : tr (captions[k]),
- column.withTrimmedTop (32).withHeight (18), juce::Justification::centred, 1, 0.8f);
- }
- return;
- }
- drawWave (g, *c, w, padColour (c->simplePad.colour, trackColour));
- }
- void resized() override
- {
- auto r = getLocalBounds().reduced (pad, 6);
- // round 190jc (SG-11): touch size at least (44 px; Large controls 48), up to 72
- const auto side = juce::jlimit (ui::simplelook::px (44, 48), 72, (r.getHeight() - 3 * 4) / 4);
- gridArea = r.removeFromLeft (side * 4 + 3 * 4).withHeight (side * 4 + 3 * 4);
- r.removeFromLeft (14);
- auto top = r.removeFromTop (26);
- kit.setBounds (top.removeFromRight (64));
- top.removeFromRight (6);
- browse.setBounds (top.removeFromRight (124));
- top.removeFromRight (6);
- load.setBounds (top.removeFromRight (84));
- titleArea = top;
- r.removeFromTop (4);
- auto controls = r.removeFromBottom (juce::jmin (84, r.getHeight() / 2 + 8));
- waveArea = r.reduced (0, 2);
- for (int k = 0; k < 3; ++k) // round 190mr (DS-36): each pill under its column's caption
- {
- auto* b = k == 0 ? &ctaRecord : k == 1 ? &ctaImport : &ctaBrowse;
- const auto column = ctaColumn (k);
- b->setBounds (juce::Rectangle<int> (juce::jmin (84, column.getWidth() - 8), 26).withCentre ({ column.getCentreX(), column.getY() + 70 }));
- }
- auto row = controls.removeFromTop (24);
- for (auto& b : modes)
- b.setBounds (row.removeFromLeft (84)), row.removeFromLeft (2);
- row.removeFromLeft (10);
- reverse.setBounds (row.removeFromLeft (84));
- row.removeFromLeft (6);
- normalize.setBounds (row.removeFromLeft (92));
- row.removeFromLeft (6);
- group.setBounds (row.removeFromLeft (110));
- controls.removeFromTop (4);
- const auto kw = juce::jmin (78, controls.getWidth() / knobCount);
- for (int k = 0; k < knobCount; ++k)
- {
- auto cell = controls.removeFromLeft (kw);
- captions[(std::size_t) k].setBounds (cell.removeFromTop (13));
- knobs[(std::size_t) k].setBounds (cell);
- }
- }
- void mouseDown (const juce::MouseEvent& e) override
- {
- dragFrom = -1;
- regionDrag = 0;
- if (const auto p = padAt (e.getPosition()); p >= 0)
- {
- if (e.mods.isPopupMenu())
- {
- select (p);
- padMenu (p).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
- return;
- }
- dragFrom = p;
- // a click plays the pad while the button is held (a Gate pad stops when it is let go)
- select (p);
- lightPad (p);
- if (const auto ch = channelIndex (p); ch >= 0 && hasSound (p))
- {
- engine.sendLiveNote (ch, simplepads::padKey, 0.8f, true, true);
- heldChannel = ch;
- }
- return;
- }
- if (waveArea.contains (e.getPosition()))
- {
- const auto* c = channelOf (selected);
- if (c == nullptr || c->samplePath.empty())
- return;
- const auto x = (float) (e.x - waveArea.getX()) / (float) juce::jmax (1, waveArea.getWidth());
- regionDrag = std::abs (x - c->sampler.regionStart) <= std::abs (x - c->sampler.regionEnd) ? 1 : 2;
- mouseDrag (e);
- }
- }
- void mouseDrag (const juce::MouseEvent& e) override
- {
- if (regionDrag != 0)
- {
- const auto x = juce::jlimit (0.0f, 1.0f, (float) (e.x - waveArea.getX()) / (float) juce::jmax (1, waveArea.getWidth()));
- const bool start = regionDrag == 1;
- edit ([x, start] (ChannelDef& c) {
- if (start)
- c.sampler.regionStart = juce::jmin (x, c.sampler.regionEnd - 0.01f);
- else
- c.sampler.regionEnd = juce::jmax (x, c.sampler.regionStart + 0.01f);
- });
- return;
- }
- if (dragFrom >= 0 && e.getDistanceFromDragStart() > 6)
- {
- const auto over = padAt (e.getPosition());
- if (over != dropTarget)
- {
- dropTarget = over == dragFrom ? -1 : over;
- repaint();
- }
- }
- }
- void mouseUp (const juce::MouseEvent& e) override
- {
- if (heldChannel >= 0)
- {
- engine.sendLiveNote (heldChannel, simplepads::padKey, 0.0f, false, true);
- heldChannel = -1;
- }
- if (dragFrom >= 0 && dropTarget >= 0)
- dropPad (dragFrom, dropTarget, e.mods.isAltDown());
- dragFrom = dropTarget = -1;
- regionDrag = 0;
- repaint();
- }
- // files from the system and sounds from LYNX's browser land on the pad under the pointer
- bool isInterestedInFileDrag (const juce::StringArray& files) override { return track >= 0 && ! files.isEmpty(); }
- void fileDragMove (const juce::StringArray&, int x, int y) override { setDropTarget (padAt ({ x, y })); }
- void fileDragExit (const juce::StringArray&) override { setDropTarget (-1); }
- void filesDropped (const juce::StringArray& files, int x, int y) override
- {
- auto at = padAt ({ x, y });
- setDropTarget (-1);
- if (at < 0)
- at = selected;
- // several files fill the pads from there on
- for (const auto& f : files)
- if (SampleLibrary::isSampleFile (juce::File (f)) && at < simplepads::padCount)
- loadFile (at++, juce::File (f));
- }
- bool isInterestedInDragSource (const SourceDetails& d) override
- {
- return track >= 0 && BrowserComponent::isBrowserDrag (d) && SampleLibrary::isSampleFile (BrowserComponent::draggedFile (d));
- }
- void itemDragMove (const SourceDetails& d) override { setDropTarget (padAt (d.localPosition)); }
- void itemDragExit (const SourceDetails&) override { setDropTarget (-1); }
- void itemDropped (const SourceDetails& d) override
- {
- const auto at = padAt (d.localPosition);
- setDropTarget (-1);
- loadFile (at >= 0 ? at : selected, BrowserComponent::draggedFile (d));
- }
- // Round 190jj (capture190ji §1a, shots/bl-a-pads-flash-z2.png, films/play-sampler-pads): BandLab's pad "press" — a
- // pad that sounds darkens from its colour to ~55 % brightness in ~50 ms and back in ~90 ms (eased both ways), for a
- // click, a key, and the notes the song plays. The timer runs only while a press runs (60 Hz with Animations on; with
- // Animations off the pad darkens at once and comes back after the same 140 ms: two repaints). Only the pressed pad
- // repaints. (Round 190ih, DS-34: the page is never repainted whole for a press.)
- static constexpr double pressInMs = 50.0, pressOutMs = 90.0;
- static constexpr float pressDepth = 0.45f; // (to 55 % of the colour)
- float pressAmount (int p, double nowMs) const
- {
- const auto start = pressStart[(std::size_t) p];
- if (start < 0.0)
- return 0.0f;
- const auto t = nowMs - start;
- if (t >= pressInMs + pressOutMs || t < 0.0)
- return 0.0f;
- if (! ui::motion::enabled())
- return 1.0f;
- auto ease = [] (double x) { return (float) (x * x * (3.0 - 2.0 * x)); }; // (smoothstep: eased both ways)
- return t < pressInMs ? ease (t / pressInMs) : 1.0f - ease ((t - pressInMs) / pressOutMs);
- }
- void timerCallback() override
- {
- const auto now = juce::Time::getMillisecondCounterHiRes();
- bool any = false;
- for (int p = 0; p < simplepads::padCount; ++p)
- {
- if (pressStart[(std::size_t) p] < 0.0)
- continue;
- const auto amount = pressAmount (p, now);
- if (amount <= 0.0f && now - pressStart[(std::size_t) p] >= pressInMs + pressOutMs)
- pressStart[(std::size_t) p] = -1.0;
- if (amount != pressShown[(std::size_t) p])
- {
- pressShown[(std::size_t) p] = amount;
- repaint (padBounds (p).expanded (2));
- }
- any = any || pressStart[(std::size_t) p] >= 0.0;
- }
- if (! any)
- stopTimer();
- }
- void lightPad (int pad)
- {
- if (pad >= 0 && pad < simplepads::padCount)
- {
- pressStart[(std::size_t) pad] = juce::Time::getMillisecondCounterHiRes();
- if (! isTimerRunning())
- startTimerHz (ui::motion::enabled() ? 60 : 30);
- timerCallback(); // (the first frame now)
- }
- }
- // Round 190jj: the notes the song plays press their pads (BandLab). Called on the main window's 30 Hz timer; it reads
- // the pads' channels' note-strike counters (the engine's activity counters: a new note-on, even one shorter than a
- // frame) only while the song runs and the page shows; stopped it does nothing.
- void watchPlayback()
- {
- const auto runs = engine.getTransport().playing.load (std::memory_order_relaxed) && isShowing() && track >= 0;
- for (int p = 0; p < simplepads::padCount; ++p)
- {
- const auto ch = channelIndex (p);
- const auto strikes = runs && ch >= 0 ? engine.noteStrikes (ch) : 0u;
- if (runs && watching && ch == seenChannel[(std::size_t) p] && strikes != seenStrikes[(std::size_t) p] && hasSound (p))
- lightPad (p);
- seenStrikes[(std::size_t) p] = strikes;
- seenChannel[(std::size_t) p] = ch;
- }
- watching = runs;
- }
- float pressShownForCheck (int pad) const { return pad >= 0 && pad < simplepads::padCount && pressStart[(std::size_t) pad] >= 0.0 ? 1.0f : pressShown[(std::size_t) pad]; }
- float pressForSnapshot (int pad, float amount)
- {
- pressStart[(std::size_t) pad] = -1.0;
- pressShown[(std::size_t) pad] = amount;
- repaint();
- return amount;
- }
- private:
- static constexpr int knobCount = 6;
- const ChannelDef* channelOf (int p) const
- {
- const auto& song = engine.getSong();
- const auto i = p >= 0 && p < (int) channels.size() ? channels[(std::size_t) p] : -1;
- return i >= 0 && i < (int) song.channels.size() ? &song.channels[(std::size_t) i] : nullptr;
- }
- int channelIndex (int p) const { return p >= 0 && p < (int) channels.size() ? channels[(std::size_t) p] : -1; }
- bool hasSound (int p) const
- {
- const auto* c = channelOf (p);
- return c != nullptr && ! c->samplePath.empty();
- }
- // the grid: pad 0 bottom left, pad 15 top right (the keys' shape)
- juce::Rectangle<int> padBounds (int p) const
- {
- const auto side = (gridArea.getWidth() - 3 * 4) / 4;
- const auto col = p % 4, row = 3 - p / 4;
- return { gridArea.getX() + col * (side + 4), gridArea.getY() + row * (side + 4), side, side };
- }
- int padAt (juce::Point<int> pos) const
- {
- for (int p = 0; p < simplepads::padCount; ++p)
- if (padBounds (p).contains (pos))
- return p;
- return -1;
- }
- void setDropTarget (int p)
- {
- if (p != dropTarget)
- {
- dropTarget = p;
- repaint();
- }
- }
- std::int64_t framesOf (const ChannelDef& c)
- {
- if (c.samplePath.empty())
- return 0;
- const auto data = engine.getSampleLibrary().load (utf8 (c.samplePath));
- return data != nullptr ? (std::int64_t) data->frames() : 0;
- }
- // one undoable edit of the selected pad's channel; the pad's own settings are applied to the channel after it
- void edit (const std::function<void (ChannelDef&)>& change, int pad = -1)
- {
- const auto p = pad >= 0 ? pad : selected;
- const auto ch = channelIndex (p);
- if (ch < 0)
- return;
- const auto frames = framesOf (engine.getSong().channels[(std::size_t) ch]);
- engine.editSong ([ch, change, frames] (Song& s) {
- if (ch < (int) s.channels.size())
- {
- change (s.channels[(std::size_t) ch]);
- simplepads::apply (s.channels[(std::size_t) ch], frames);
- }
- });
- update();
- }
- void turn (int k, float v)
- {
- switch (k)
- {
- case 0: edit ([s = attackFrom (v)] (ChannelDef& c) { c.sampler.attack = s; }); break;
- case 1: edit ([s = releaseFrom (v)] (ChannelDef& c) { c.simplePad.release = s; }); break;
- case 2: edit ([t = v * 2.0f - 1.0f] (ChannelDef& c) { c.simplePad.tone = std::abs (t) < 0.02f ? 0.0f : t; }); break;
- case 3: edit ([p = (v * 2.0f - 1.0f) * simplepads::maxPitch] (ChannelDef& c) { c.sampler.pitch = p; }); break;
- case 4: edit ([p = v * 2.0f - 1.0f] (ChannelDef& c) { c.pan = std::abs (p) < 0.01f ? 0.0f : p; }); break;
- default: edit ([v] (ChannelDef& c) { c.volume = v; }); break;
- }
- }
- // the same value on every pad (the knob's menu): what the original's "copy value to other pads" does
- void copyKnobToAll (int k)
- {
- const auto* src = channelOf (selected);
- if (src == nullptr)
- return;
- const auto from = *src;
- const auto chans = channels;
- std::vector<std::int64_t> frames;
- for (auto ch : chans)
- frames.push_back (ch >= 0 ? framesOf (engine.getSong().channels[(std::size_t) ch]) : 0);
- engine.editSong ([k, from, chans, frames] (Song& s) {
- for (std::size_t i = 0; i < chans.size(); ++i)
- {
- if (chans[i] < 0 || chans[i] >= (int) s.channels.size())
- continue;
- auto& c = s.channels[(std::size_t) chans[i]];
- switch (k)
- {
- case 0: c.sampler.attack = from.sampler.attack; break;
- case 1: c.simplePad.release = from.simplePad.release; break;
- case 2: c.simplePad.tone = from.simplePad.tone; break;
- case 3: c.sampler.pitch = from.sampler.pitch; break;
- case 4: c.pan = from.pan; break;
- default: c.volume = from.volume; break;
- }
- simplepads::apply (c, frames[i]);
- }
- });
- update();
- }
- void loadFile (int p, const juce::File& file)
- {
- if (p < 0 || ! file.existsAsFile())
- return;
- const auto data = engine.getSampleLibrary().load (file.getFullPathName());
- if (data == nullptr)
- {
- juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not import"),
- tr ("Could not read {0}", { file.getFileName() }));
- return;
- }
- const auto t = track;
- const auto path = file.getFullPathName().toStdString(), name = file.getFileNameWithoutExtension().toStdString();
- const auto frames = (std::int64_t) data->frames();
- const auto seconds = data->sampleRate > 0.0 ? (double) frames / data->sampleRate : 0.0;
- engine.editSong ([t, p, path, name, frames, seconds] (Song& s) { simplepads::loadSample (s, t, p, path, name, frames, seconds); });
- folder = file.getParentDirectory();
- select (p);
- }
- void chooseFile (int p)
- {
- chooser = ui::makeFileChooser (tr ("Choose sample"), folder, engine.getSampleLibrary().wildcard());
- ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
- [safe = juce::Component::SafePointer<PadsPage> (this), p] (const juce::FileChooser& fc) {
- if (safe != nullptr)
- safe->loadFile (p, fc.getResult());
- });
- }
- void dropPad (int from, int to, bool copy)
- {
- if (from < 0 || to < 0 || from == to || ! hasSound (from))
- return;
- const auto t = track;
- const auto ch = channelIndex (from);
- const auto frames = ch >= 0 ? framesOf (engine.getSong().channels[(std::size_t) ch]) : 0;
- // onto an empty pad it moves, onto a pad with a sound the two swap; with Alt it is copied
- engine.editSong ([t, from, to, copy, frames] (Song& s) {
- if (copy)
- simplepads::copyPad (s, t, from, to, frames);
- else
- simplepads::swapPads (s, t, from, to);
- });
- select (to);
- }
- void normalizePad()
- {
- const auto* c = channelOf (selected);
- if (c == nullptr || c->samplePath.empty())
- return;
- const auto data = engine.getSampleLibrary().load (utf8 (c->samplePath));
- if (data == nullptr || data->frames() == 0)
- return;
- const auto n = (std::int64_t) data->frames();
- const auto a = (std::int64_t) (c->sampler.regionStart * (float) n), b = juce::jmax (a + 1, (std::int64_t) (c->sampler.regionEnd * (float) n));
- float peak = 0.0f;
- for (auto i = a; i < b && i < n; ++i)
- peak = juce::jmax (peak, std::abs (data->leftData()[i]), std::abs (data->rightData()[i]));
- edit ([g = simplepads::normalizeGainDb (peak)] (ChannelDef& ch) { ch.sampler.gainDb = g; });
- }
- void showGroupMenu()
- {
- juce::PopupMenu m;
- const auto* c = channelOf (selected);
- const auto now = c != nullptr ? c->simplePad.group : 0;
- m.addItem (tr ("None"), true, now == 0, [this] { edit ([] (ChannelDef& ch) { ch.simplePad.group = 0; }); });
- for (int g = 1; g <= simplepads::groupCount; ++g)
- m.addItem (tr ("Group {0}", { juce::String (g) }), true, now == g, [this, g] { edit ([g] (ChannelDef& ch) { ch.simplePad.group = g; }); });
- m.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&group));
- }
- juce::PopupMenu padMenu (int p)
- {
- juce::PopupMenu m;
- const bool has = hasSound (p);
- m.addItem (tr ("Import..."), [this, p] { chooseFile (p); });
- m.addSeparator();
- m.addItem (tr ("Copy"), has, false, [this, p] { clipboard = p; });
- m.addItem (tr ("Paste"), clipboard >= 0 && clipboard != p && hasSound (clipboard), false, [this, p] { dropPad (clipboard, p, true); });
- m.addItem (tr ("Clear the pad"), has, false, [this, p] {
- const auto t = track;
- engine.editSong ([t, p] (Song& s) { simplepads::clearPad (s, t, p); });
- update();
- });
- juce::PopupMenu colours;
- const auto* c = channelOf (p);
- const auto now = c != nullptr ? c->simplePad.colour : 0;
- for (int i = 0; i <= simplepads::colourCount; ++i)
- colours.addItem (padColourName (i), true, now == i, [this, p, i] { edit ([i] (ChannelDef& ch) { ch.simplePad.colour = i; }, p); });
- m.addSubMenu (tr ("Colour"), colours);
- juce::PopupMenu copyTo;
- for (int k = 0; k < knobCount; ++k)
- copyTo.addItem (padKnobName (k), has, false, [this, p, k] {
- select (p);
- copyKnobToAll (k);
- });
- m.addSubMenu (tr ("Copy a value to every pad"), copyTo, has);
- return m;
- }
- // kits: the pads' sounds and settings in a file of the user's (Documents/LYNX/Sampler kits/<name>.lynxkit)
- static juce::File kitFolder() { return platform::documentsFolder().getChildFile ("LYNX/Sampler kits"); }
- juce::PopupMenu kitMenu()
- {
- juce::PopupMenu m;
- m.addItem (tr ("Save the pads as a kit..."), track >= 0, false, [this] { askKitName(); });
- juce::PopupMenu mine, rename, remove;
- const auto files = kitFolder().findChildFiles (juce::File::findFiles, false, "*.lynxkit");
- auto sorted = files;
- std::sort (sorted.begin(), sorted.end(), [] (const juce::File& a, const juce::File& b) { return a.getFileName().compareNatural (b.getFileName()) < 0; });
- for (const auto& f : sorted)
- {
- mine.addItem (f.getFileNameWithoutExtension(), [this, f] { openKit (f); });
- rename.addItem (f.getFileNameWithoutExtension(), [this, f] { askRename (f); });
- remove.addItem (f.getFileNameWithoutExtension(), [f] { f.moveToTrash(); });
- }
- m.addSubMenu (tr ("My kits"), mine, ! sorted.isEmpty());
- m.addItem (tr ("Fill the pads from a folder..."), track >= 0, false, [this] { chooseKitFolder(); });
- m.addSeparator();
- m.addSubMenu (tr ("Rename a kit"), rename, ! sorted.isEmpty());
- m.addSubMenu (tr ("Delete a kit"), remove, ! sorted.isEmpty());
- return m;
- }
- void showKitMenu() { kitMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&kit)); }
- void askKitName()
- {
- auto* w = new juce::AlertWindow (tr ("Save the pads as a kit"), tr ("Name of the kit:"), juce::MessageBoxIconType::NoIcon);
- w->addTextEditor ("name", utf8 (track >= 0 && track < (int) engine.getSong().playlistTracks.size() ? engine.getSong().playlistTracks[(std::size_t) track].name : std::string()));
- w->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([this, w, safe = juce::Component::SafePointer<PadsPage> (this)] (int r) {
- if (r == 1 && safe != nullptr)
- saveKit (w->getTextEditorContents ("name").trim());
- }),
- true);
- }
- void askRename (const juce::File& kitFile)
- {
- auto* w = new juce::AlertWindow (tr ("Rename the kit"), tr ("New name of the kit:"), juce::MessageBoxIconType::NoIcon);
- w->addTextEditor ("name", kitFile.getFileNameWithoutExtension());
- w->addButton (tr ("Rename"), 1, juce::KeyPress (juce::KeyPress::returnKey));
- w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
- w->enterModalState (true, juce::ModalCallbackFunction::create ([w, kitFile] (int r) {
- if (r == 1)
- renameKit (kitFile, w->getTextEditorContents ("name"));
- }),
- true);
- }
- public:
- // a kit file gets another name (2 to 50 characters, not taken); false when it can't
- static bool renameKit (const juce::File& kitFile, const juce::String& rawName)
- {
- const auto name = juce::File::createLegalFileName (rawName).trim();
- const auto target = kitFile.getSiblingFile (name + ".lynxkit");
- if (name.length() < 2 || name.length() > 50 || target.exists() || ! kitFile.existsAsFile())
- return false;
- auto json = juce::JSON::parse (kitFile.loadFileAsString());
- if (auto* o = json.getDynamicObject())
- o->setProperty ("name", name);
- return target.replaceWithText (juce::JSON::toString (json)) && kitFile.deleteFile();
- }
- bool saveKit (const juce::String& rawName)
- {
- const auto name = juce::File::createLegalFileName (rawName).trim();
- if (name.length() < 2 || name.length() > 50) // (the original's rule for a kit's name)
- return false;
- auto pads = juce::Array<juce::var>();
- for (int p = 0; p < simplepads::padCount; ++p)
- {
- const auto* c = channelOf (p);
- if (c == nullptr || c->samplePath.empty())
- continue;
- auto o = std::make_unique<juce::DynamicObject>();
- o->setProperty ("pad", p);
- o->setProperty ("file", utf8 (c->samplePath));
- o->setProperty ("name", utf8 (c->name));
- o->setProperty ("mode", (int) c->simplePad.mode);
- o->setProperty ("tone", c->simplePad.tone);
- o->setProperty ("release", c->simplePad.release);
- o->setProperty ("group", c->simplePad.group);
- o->setProperty ("colour", c->simplePad.colour);
- o->setProperty ("attack", c->sampler.attack);
- o->setProperty ("pitch", c->sampler.pitch);
- o->setProperty ("start", c->sampler.regionStart);
- o->setProperty ("end", c->sampler.regionEnd);
- o->setProperty ("reverse", c->sampler.reverse);
- o->setProperty ("gainDb", c->sampler.gainDb);
- o->setProperty ("volume", c->volume);
- o->setProperty ("pan", c->pan);
- pads.add (juce::var (o.release()));
- }
- auto root = std::make_unique<juce::DynamicObject>();
- root->setProperty ("lynxSamplerKit", 1);
- root->setProperty ("name", name);
- root->setProperty ("pads", pads);
- kitFolder().createDirectory();
- return kitFolder().getChildFile (name + ".lynxkit").replaceWithText (juce::JSON::toString (juce::var (root.release())));
- }
- bool openKit (const juce::File& file)
- {
- const auto json = juce::JSON::parse (file.loadFileAsString());
- if ((int) json.getProperty ("lynxSamplerKit", 0) != 1)
- return false;
- struct Loaded
- {
- int pad;
- ChannelDef def;
- std::int64_t frames;
- };
- std::vector<Loaded> loaded;
- if (const auto* list = json.getProperty ("pads", {}).getArray())
- for (const auto& v : *list)
- {
- const auto p = (int) v.getProperty ("pad", -1);
- const juce::File f (v.getProperty ("file", "").toString());
- const auto data = f.existsAsFile() ? engine.getSampleLibrary().load (f.getFullPathName()) : nullptr;
- if (p < 0 || p >= simplepads::padCount || data == nullptr)
- continue;
- ChannelDef d;
- d.samplePath = f.getFullPathName().toStdString();
- d.name = v.getProperty ("name", f.getFileNameWithoutExtension()).toString().toStdString();
- d.simplePad.mode = (std::uint8_t) juce::jlimit (0, 2, (int) v.getProperty ("mode", 0));
- d.simplePad.tone = (float) v.getProperty ("tone", 0.0);
- d.simplePad.release = (float) v.getProperty ("release", 0.0);
- d.simplePad.group = (int) v.getProperty ("group", 0);
- d.simplePad.colour = (int) v.getProperty ("colour", 0);
- d.sampler.attack = (float) v.getProperty ("attack", 0.0);
- d.sampler.pitch = (float) v.getProperty ("pitch", 0.0);
- d.sampler.regionStart = (float) v.getProperty ("start", 0.0);
- d.sampler.regionEnd = (float) v.getProperty ("end", 1.0);
- d.sampler.reverse = (bool) v.getProperty ("reverse", false);
- d.sampler.gainDb = (float) v.getProperty ("gainDb", 0.0);
- d.volume = (float) v.getProperty ("volume", 0.78);
- d.pan = (float) v.getProperty ("pan", 0.0);
- loaded.push_back ({ p, std::move (d), (std::int64_t) data->frames() });
- }
- const auto t = track;
- engine.editSong ([t, loaded] (Song& s) {
- for (int p = 0; p < simplepads::padCount; ++p)
- simplepads::clearPad (s, t, p);
- for (const auto& l : loaded)
- {
- const auto ch = simplepads::padChannel (s, t, l.pad);
- if (ch < 0)
- continue;
- auto& c = s.channels[(std::size_t) ch];
- c.samplePath = l.def.samplePath;
- c.name = l.def.name;
- c.sampler.attack = l.def.sampler.attack;
- c.sampler.pitch = l.def.sampler.pitch;
- c.sampler.regionStart = l.def.sampler.regionStart;
- c.sampler.regionEnd = l.def.sampler.regionEnd;
- c.sampler.reverse = l.def.sampler.reverse;
- c.sampler.gainDb = l.def.sampler.gainDb;
- c.volume = l.def.volume;
- c.pan = l.def.pan;
- const auto index = c.simplePad.index;
- c.simplePad = l.def.simplePad;
- c.simplePad.index = index;
- simplepads::apply (c, l.frames);
- }
- });
- update();
- return true;
- }
- // the first 16 sounds of a folder (by name), pad by pad
- int fillFromFolder (const juce::File& dir)
- {
- auto files = dir.findChildFiles (juce::File::findFiles, false);
- std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFileName().compareNatural (b.getFileName()) < 0; });
- int p = 0;
- for (const auto& f : files)
- if (p < simplepads::padCount && SampleLibrary::isSampleFile (f))
- loadFile (p++, f);
- select (0);
- return p;
- }
- private:
- void chooseKitFolder()
- {
- chooser = ui::makeFileChooser (tr ("Choose a folder of sounds"), folder, {});
- ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
- [safe = juce::Component::SafePointer<PadsPage> (this)] (const juce::FileChooser& fc) {
- if (safe != nullptr && fc.getResult().isDirectory())
- safe->fillFromFolder (fc.getResult());
- });
- }
- // round 190jc (SG-11): the waveform in the pad's colour, one column per PHYSICAL pixel (at @2x it stepped every 2 px)
- void drawWave (juce::Graphics& g, const ChannelDef& c, juce::Rectangle<float> w, juce::Colour hue)
- {
- const auto scale = juce::jlimit (1.0f, 4.0f, g.getInternalContext().getPhysicalPixelScaleFactor());
- const auto width = juce::jmax (1, (int) std::round (w.getWidth() * scale));
- if (waveFor != c.samplePath || (int) wave.size() != width)
- {
- wave.assign ((std::size_t) width, 0.0f);
- if (const auto data = engine.getSampleLibrary().load (utf8 (c.samplePath)); data != nullptr && data->frames() > 0)
- {
- const auto n = (std::int64_t) data->frames();
- for (int x = 0; x < width; ++x)
- {
- const auto a = n * x / width, b = juce::jmax (a + 1, n * (x + 1) / width);
- float peak = 0.0f;
- for (auto i = a; i < b; ++i) // (every sample: a stride aliases a low tone into a moiré; done once per sample)
- peak = juce::jmax (peak, std::abs (data->leftData()[i]), std::abs (data->rightData()[i]));
- wave[(std::size_t) x] = peak;
- }
- }
- waveFor = c.samplePath;
- }
- const auto mid = w.getCentreY(), half = w.getHeight() * 0.45f;
- const auto s = w.getX() + c.sampler.regionStart * w.getWidth(), e = w.getX() + c.sampler.regionEnd * w.getWidth();
- const auto played = ui::simplelook::readableOn (hue, colour::bg0, 3.0f);
- juce::RectangleList<float> inRegion, outside; // (two fills, not one per column)
- for (int x = 0; x < width; ++x)
- {
- const auto px = w.getX() + (float) x / scale;
- const auto idx = c.sampler.reverse ? width - 1 - x : x;
- const auto h = juce::jmax (0.5f / scale, wave[(std::size_t) idx] * half);
- (px >= s && px <= e ? inRegion : outside).addWithoutMerging ({ px, mid - h, 1.0f / scale, h * 2.0f });
- }
- g.setColour (played.withAlpha (0.95f));
- g.fillRectList (inRegion);
- g.setColour (colour::textDisabled.withAlpha (0.6f));
- g.fillRectList (outside);
- // the region's handles
- g.setColour (colour::textPrimary);
- for (auto x : { s, e })
- {
- g.fillRect (x - 1.0f, w.getY(), 2.0f, w.getHeight());
- g.fillRect (x - 4.0f, w.getY(), 8.0f, 4.0f);
- }
- if (simplepads::modeOf (c) == simplepads::Mode::loop)
- {
- g.setFont (font (type::caption, true));
- g.setColour (colour::textSecondary);
- g.drawText (juce::String::fromUTF8 ("\xe2\x9f\xb3 ") + trc ("@pad mode: Loop"), w.reduced (6.0f, 3.0f).toNearestInt(), juce::Justification::topRight, false);
- }
- }
- public:
- ~PadsPage() override
- {
- if (recording) // (closed while recording: the tap and the input are let go, nothing is kept)
- {
- recorder.stopTimer();
- engine.getMeters().capture.setSource (AudioCapture::off);
- releaseInput();
- }
- }
- bool recordingForCheck() const noexcept { return recording; }
- void startRecordingForCheck() { startPadRecording(); }
- void recordingLookForSnapshot (bool on) // (the look only: no input is opened)
- {
- recording = on;
- recordingPad = on ? selected : -1;
- update();
- }
- void stopRecordingForCheck() { stopPadRecording(); }
- juce::Component* ctaForCheck (int k) { return k == 0 ? &ctaRecord : k == 1 ? (juce::Component*) &ctaImport : &ctaBrowse; }
- private:
- // --- round 190mr (DS-36): recording into the selected pad (BandLab: Record starts at once, no count-in; the dock says
- // "Recording...", the button turns into a red Stop and the pad turns red; Stop puts the take on the pad) ---------
- juce::Rectangle<int> ctaColumn (int k) const
- {
- const auto area = waveArea.reduced (8, 0);
- const auto w = area.getWidth() / 3;
- const auto top = area.getY() + juce::jmax (4, (area.getHeight() - 100) / 2);
- return { area.getX() + k * w, top, w, 100 };
- }
- void styleRecordCta()
- {
- ctaRecord.setButtonText (recording ? tr ("Stop") : tr ("Record"));
- ctaRecord.setColour (juce::TextButton::buttonColourId, recording ? colour::accent : colour::bg4);
- ctaRecord.setColour (juce::TextButton::textColourOffId, colour::textPrimary);
- }
- struct PadRecorder final : juce::Timer
- {
- std::function<void()> tick;
- void timerCallback() override { tick(); }
- };
- void startPadRecording()
- {
- if (recording || track < 0)
- return;
- if (! engine.hasAudioInput())
- {
- if (const auto result = engine.openAudioInput(); result.issue != AudioEngine::InputIssue::none)
- {
- ui::postNotice ({ result.detail.isNotEmpty() ? result.detail : tr ("No active audio input (Settings > Audio)"), {}, false, false });
- return;
- }
- openedInput = true;
- }
- auto* device = engine.getDeviceManager().getCurrentAudioDevice();
- if (device == nullptr || device->getActiveInputChannels().countNumberOfSetBits() == 0)
- {
- ui::postNotice ({ tr ("No active audio input (Settings > Audio)"), {}, false, false });
- releaseInput();
- return;
- }
- recRate = device->getCurrentSampleRate();
- recStereo = device->getActiveInputChannels().countNumberOfSetBits() > 1;
- recL.clear();
- recR.clear();
- recordingPad = selected;
- engine.getMeters().capture.setSource (AudioCapture::input);
- recording = true;
- recorder.tick = [this] { pullRecording(); };
- recorder.startTimerHz (20);
- update();
- }
- void pullRecording()
- {
- std::vector<float> l, r;
- engine.getMeters().capture.pull (l, r);
- recL.insert (recL.end(), l.begin(), l.end());
- recR.insert (recR.end(), r.begin(), r.end());
- if ((double) recL.size() >= recRate * maxPadSeconds) // (a pad holds a sound, not a song: it stops by itself)
- stopPadRecording();
- }
- void releaseInput()
- {
- if (std::exchange (openedInput, false))
- engine.releaseAudioInputIfUnused();
- }
- void stopPadRecording()
- {
- if (! recording)
- return;
- pullRecording();
- recorder.stopTimer();
- engine.getMeters().capture.setSource (AudioCapture::off);
- releaseInput();
- recording = false;
- const auto pad = std::exchange (recordingPad, -1);
- if (recL.empty() || recRate <= 0.0)
- {
- ui::postHint ({ tr ("Nothing was recorded"), {}, false, false }, 3000);
- update();
- return;
- }
- const auto folder = engine.getRecordingFolder();
- folder.createDirectory();
- const auto file = folder.getNonexistentChildFile (tr ("Pad {0}", { juce::String (pad + 1) }) + " " + juce::Time::getCurrentTime().formatted ("%Y-%m-%d %H%M%S"), ".wav", false);
- juce::AudioBuffer<float> buffer (recStereo ? 2 : 1, (int) recL.size());
- buffer.copyFrom (0, 0, recL.data(), (int) recL.size());
- if (recStereo)
- buffer.copyFrom (1, 0, recR.data(), (int) juce::jmin (recR.size(), recL.size()));
- bool written = false;
- if (auto out = std::unique_ptr<juce::FileOutputStream> (file.createOutputStream()))
- {
- juce::WavAudioFormat wav;
- if (auto writer = std::unique_ptr<juce::AudioFormatWriter> (wav.createWriterFor (out.get(), recRate, (unsigned) buffer.getNumChannels(), 24, {}, 0)))
- {
- out.release();
- written = writer->writeFromAudioSampleBuffer (buffer, 0, buffer.getNumSamples());
- }
- }
- recL.clear();
- recR.clear();
- if (written)
- loadFile (pad, file);
- else
- ui::postNotice ({ tr ("Could not write {0}", { file.getFullPathName() }), {}, false, false });
- update();
- }
- static constexpr double maxPadSeconds = 60.0;
- PadRecorder recorder;
- bool recording = false, recStereo = false, openedInput = false;
- int recordingPad = -1;
- double recRate = 0.0;
- std::vector<float> recL, recR;
- juce::TextButton ctaRecord, ctaImport, ctaBrowse;
- AudioEngine& engine;
- int track = -1, selected = 0, dragFrom = -1, dropTarget = -1, regionDrag = 0, clipboard = -1, heldChannel = -1;
- std::vector<int> channels;
- std::array<double, simplepads::padCount> pressStart = [] { std::array<double, simplepads::padCount> a; a.fill (-1.0); return a; }();
- std::array<float, simplepads::padCount> pressShown {};
- std::array<std::uint32_t, simplepads::padCount> seenStrikes {};
- std::array<int, simplepads::padCount> seenChannel {};
- bool watching = false;
- juce::Rectangle<int> gridArea, titleArea, waveArea;
- juce::TextButton load, browse, kit, normalize, group;
- juce::ToggleButton reverse;
- std::array<juce::TextButton, 3> modes;
- std::array<DockKnob, knobCount> knobs;
- std::array<juce::Label, knobCount> captions;
- std::vector<float> wave;
- std::string waveFor;
- juce::File folder;
- std::unique_ptr<juce::FileChooser> chooser;
- };
- #include "ui/SimpleControlsPage.inc" // round 190ke: the Controls tab
- #include "ui/SimpleStepsPage.inc" // round 190lr: the Drum Machine tab
- // Round 190nw: the Tracker tab, the track's pattern in the tracker editor (ui/TrackerComponent.h, compact: no pattern box
- // or side panel), the track's channel only. A track without a pattern gets the "New pattern" button (as the Editor tab).
- class SimpleDock::TrackerPage final : public juce::Component
- {
- public:
- explicit TrackerPage (AudioEngine& e) : engine (e)
- {
- makePattern.setButtonText (tr ("New pattern"));
- makePattern.setTooltip (tr ("An empty 4-bar pattern on this track, to write notes into"));
- makePattern.onClick = [this] {
- const auto t = track;
- engine.editSong ([t] (Song& s) { simpletracks::ensurePattern (s, t); });
- update();
- };
- addChildComponent (makePattern);
- }
- void show (int newTrack, int newChannel)
- {
- track = newTrack;
- channel = newChannel;
- update();
- }
- void update()
- {
- const auto& song = engine.getSong();
- const auto pattern = track >= 0 && isVisible() ? simpletracks::patternOf (song, track) : -1;
- if (pattern >= 0 && editor == nullptr)
- {
- editor = makeTracker (engine, true);
- addAndMakeVisible (*editor);
- resized();
- }
- if (editor != nullptr)
- {
- editor->setVisible (pattern >= 0);
- if (pattern >= 0 && (editor->shownPattern() != pattern || shownChannel != channel))
- {
- shownChannel = channel;
- editor->setOnlyChannels (channel >= 0 ? std::optional<std::vector<int>> (std::vector<int> { channel }) : std::nullopt);
- editor->showPattern (pattern);
- }
- }
- makePattern.setVisible (pattern < 0 && track >= 0 && isVisible());
- }
- void visibilityChanged() override { update(); }
- void resized() override
- {
- if (editor != nullptr)
- editor->setBounds (getLocalBounds());
- makePattern.setBounds (getLocalBounds().withSizeKeepingCentre (180, 32));
- }
- juce::Component* trackerComponent() { return editor.get(); }
- private:
- AudioEngine& engine;
- std::unique_ptr<TrackerComponent> editor;
- juce::TextButton makePattern;
- int track = -1, channel = -1, shownChannel = -2;
- };
- SimpleDock::SimpleDock (AudioEngine& e, Hooks h) : engine (e), hooks (std::move (h))
- {
- controlsPage = std::make_unique<ControlsPage> (e);
- addChildComponent (*controlsPage);
- stepsPage = std::make_unique<StepsPage> (e);
- addChildComponent (*stepsPage);
- // the Instrument tab's "Keyboard" button shows the dock's own Keyboard tab (round 190ds)
- hooks.showKeys = [this] { showKeyboard(); };
- effectsPage = std::make_unique<EffectsPage> (engine);
- instrumentPage = std::make_unique<InstrumentPage> (engine, hooks);
- editorPage = std::make_unique<EditorPage> (engine, hooks);
- padsPage = std::make_unique<PadsPage> (engine);
- padsPage->onBrowse = [this] {
- if (onBrowseSounds)
- onBrowseSounds();
- };
- addChildComponent (*padsPage);
- addChildComponent (*effectsPage);
- addChildComponent (*instrumentPage);
- addChildComponent (*editorPage);
- instrumentButton.setButtonText (tr ("Instrument"));
- keyboardButton.setButtonText (tr ("Keyboard"));
- keyboardButton.setTooltip (tr ("Play the track: piano, Scale keys or Chord pad"));
- editorButton.setButtonText (tr ("Editor"));
- editorButton.setTooltip (tr ("Write the track's notes"));
- effectsButton.setButtonText (tr ("Effects"));
- padsButton.setButtonText (tr ("Pads"));
- padsButton.setTooltip (tr ("The Sampler track's 16 pads: their sounds and how they play"));
- padsButton.setComponentID ("simple.dock.pads");
- controlsButton.setButtonText (tr ("Controls"));
- controlsButton.setTooltip (tr ("Eight big knobs for the track's main settings (its sound, its effects and its level)"));
- controlsButton.setComponentID ("simple.dock.controls");
- stepsButton.setButtonText (tr ("Drum Machine"));
- stepsButton.setTooltip (tr ("The drum track's step grid: patterns A to H, length and swing"));
- stepsButton.setComponentID ("simple.dock.steps");
- trackerButton.setButtonText (tr ("Tracker"));
- trackerButton.setTooltip (tr ("The track's notes as rows: typed from the keyboard, tracker style"));
- trackerButton.setComponentID ("simple.dock.tracker");
- trackerPage = std::make_unique<TrackerPage> (engine);
- addChildComponent (*trackerPage);
- // round 190dv: what the first-song tour's ring finds
- setComponentID ("simple.dock"); // (round 190jp: the tour keeps its card off the dock)
- keyboardButton.setComponentID ("simple.dock.keyboard");
- editorButton.setComponentID ("simple.dock.editor");
- effectsButton.setComponentID ("simple.dock.effects");
- const std::pair<juce::TextButton*, Tab> tabs[] { { &instrumentButton, Tab::instrument }, { &keyboardButton, Tab::keyboard },
- { &editorButton, Tab::editor }, { &trackerButton, Tab::tracker }, { &padsButton, Tab::pads }, { &stepsButton, Tab::steps }, { &controlsButton, Tab::controls },
- { &effectsButton, Tab::effects } };
- for (auto [b, t] : tabs)
- {
- b->setClickingTogglesState (true);
- b->setRadioGroupId (1901);
- addAndMakeVisible (*b);
- b->onClick = [this, b = b, t = t] {
- if (b->getToggleState())
- {
- tabChosen = true;
- setTab (t);
- }
- };
- }
- followButton.setButtonText (tr ("Follow the project key"));
- followButton.setTooltip (tr ("The loop is moved to the project key (its length stays); off: it plays in its own key"));
- followButton.onClick = [this] { clickFollowForCheck(); };
- addChildComponent (followButton);
- // round 190jc (SG-8): each tab's icon; (SG-7) the hide button is the round close X at the strip's left
- instrumentButton.glyph = (int) ui::simplelook::Glyph::piano;
- keyboardButton.glyph = (int) ui::simplelook::Glyph::keyboard;
- editorButton.glyph = (int) ui::simplelook::Glyph::notes;
- effectsButton.glyph = (int) ui::simplelook::Glyph::fx;
- padsButton.glyph = (int) ui::simplelook::Glyph::pads;
- controlsButton.glyph = (int) ui::simplelook::Glyph::dials;
- stepsButton.glyph = (int) ui::simplelook::Glyph::drumMachine;
- trackerButton.glyph = (int) ui::simplelook::Glyph::tracker;
- hideButton.setButtonText (tr ("Hide the track dock"));
- hideButton.setTooltip (tr ("Hide the track dock"));
- hideButton.onClick = [this] {
- shownSetting = false;
- if (hooks.layoutChanged)
- hooks.layoutChanged();
- };
- addAndMakeVisible (hideButton);
- showTrack (-1);
- }
- SimpleDock::~SimpleDock() = default;
- void SimpleDock::showTrack (int newTrack)
- {
- if (newTrack != track)
- tabChosen = false;
- track = newTrack;
- refresh();
- }
- void SimpleDock::refresh()
- {
- const auto& song = engine.getSong();
- insert = channel = -1;
- instrumentTab = false;
- playTabs = false;
- padsTab = track >= 0 && simpletracks::kindOf (song, track) == simpletracks::Kind::pads;
- stepsTab = track >= 0 && simpletracks::kindOf (song, track) == simpletracks::Kind::drums; // round 190lr (DS-39)
- if (track >= 0)
- {
- const auto chain = detailchain::forTrack (song, track);
- insert = chain.insert;
- channel = chain.channel;
- // a sound can be picked for a track that plays one instrument (not a sample, an audio clip or a drum kit)
- if (channel >= 0 && channel < (int) song.channels.size())
- {
- const auto kind = song.channels[(std::size_t) channel].instrument;
- instrumentTab = kind != InstrumentKind::audioClip && kind != InstrumentKind::sampler
- && simpletracks::kindOf (song, track).value_or (simpletracks::Kind::instrument) == simpletracks::Kind::instrument;
- // the track plays notes: it can be played and written (round 190ds)
- const auto trackKind = simpletracks::kindOf (song, track);
- playTabs = trackKind == simpletracks::Kind::instrument || trackKind == simpletracks::Kind::sampler;
- }
- }
- instrumentButton.setVisible (instrumentTab);
- keyboardButton.setVisible (playTabs);
- editorButton.setVisible (playTabs);
- trackerButton.setVisible (playTabs);
- padsButton.setVisible (padsTab);
- stepsButton.setVisible (stepsTab);
- controlsTab = track >= 0 && insert > 0 && insert < (int) song.mixer.size();
- controlsButton.setVisible (controlsTab);
- if ((tab == Tab::instrument && ! instrumentTab) || ((tab == Tab::keyboard || tab == Tab::editor || tab == Tab::tracker) && ! playTabs) || (tab == Tab::pads && ! padsTab)
- || (tab == Tab::controls && ! controlsTab) || (tab == Tab::steps && ! stepsTab))
- tab = Tab::effects;
- if (! tabChosen && (instrumentTab || playTabs))
- tab = instrumentTab ? Tab::instrument : Tab::keyboard; // (an instrument track opens on its sound; an audio track on its effects)
- else if (! tabChosen && padsTab)
- tab = Tab::pads; // (round 190fo: a Sampler track opens on its pads)
- else if (! tabChosen && stepsTab)
- tab = Tab::steps; // (round 190lr: a Drums track opens on its step grid, as BandLab's drum machine)
- else if (! tabChosen)
- tab = Tab::effects;
- effectsPage->show (insert);
- instrumentPage->show (instrumentTab ? channel : -1);
- showPage();
- editorPage->show (playTabs ? track : -1, channel);
- trackerPage->show (playTabs ? track : -1, channel);
- padsPage->show (padsTab ? track : -1);
- stepsPage->show (stepsTab ? track : -1);
- controlsPage->show (controlsTab ? track : -1, channel, controlsTab ? insert : -1);
- updateFollow();
- resized();
- repaint();
- }
- void SimpleDock::setTab (Tab t)
- {
- tabChosen = true; // (a refresh keeps a tab that was asked for)
- if ((t == Tab::instrument && ! instrumentTab) || ((t == Tab::keyboard || t == Tab::editor || t == Tab::tracker) && ! playTabs) || (t == Tab::pads && ! padsTab)
- || (t == Tab::controls && ! controlsTab) || (t == Tab::steps && ! stepsTab))
- t = Tab::effects;
- const auto padsBefore = tab == Tab::pads;
- tab = t;
- showPage();
- if (padsBefore != (tab == Tab::pads)) // (round 190jc: the Pads tab's least height: the holder lays the dock out again)
- if (auto* holder = getParentComponent())
- holder->resized();
- }
- void SimpleDock::cycleTab()
- {
- tabChosen = true;
- std::vector<Tab> shown;
- if (instrumentTab)
- shown.push_back (Tab::instrument);
- if (playTabs)
- shown.push_back (Tab::keyboard), shown.push_back (Tab::editor), shown.push_back (Tab::tracker);
- if (padsTab)
- shown.push_back (Tab::pads);
- if (stepsTab)
- shown.push_back (Tab::steps);
- if (controlsTab)
- shown.push_back (Tab::controls);
- shown.push_back (Tab::effects);
- const auto at = std::find (shown.begin(), shown.end(), tab);
- setTab (at == shown.end() || at + 1 == shown.end() ? shown.front() : *(at + 1));
- }
- void SimpleDock::showPage()
- {
- auto& button = tab == Tab::instrument ? instrumentButton : tab == Tab::keyboard ? keyboardButton : tab == Tab::editor ? editorButton
- : tab == Tab::tracker ? trackerButton
- : tab == Tab::pads ? padsButton
- : tab == Tab::steps ? stepsButton
- : tab == Tab::controls ? controlsButton
- : effectsButton;
- button.setToggleState (true, juce::dontSendNotification);
- if (tab == Tab::keyboard && keyboardPage == nullptr)
- {
- keyboardPage = makeKeyboardPanel (engine, [this] { return channel; }, [this] { return trackColourNow(); });
- addChildComponent (*keyboardPage);
- resized();
- }
- if (tab == Tab::keyboard && channel >= 0 && engine.getSelectedChannel() != channel)
- engine.setSelectedChannel (channel); // (the typing keys play the selected channel: this track)
- instrumentPage->setVisible (tab == Tab::instrument);
- effectsPage->setVisible (tab == Tab::effects);
- editorPage->setVisible (tab == Tab::editor);
- trackerPage->setVisible (tab == Tab::tracker);
- padsPage->setVisible (tab == Tab::pads);
- stepsPage->setVisible (tab == Tab::steps);
- controlsPage->setVisible (tab == Tab::controls);
- if (keyboardPage != nullptr)
- keyboardPage->setVisible (tab == Tab::keyboard);
- }
- void SimpleDock::showKeyboard()
- {
- tabChosen = true;
- setTab (Tab::keyboard);
- }
- void SimpleDock::editorTakenBack() { editorPage->takenBackByPanel(); }
- juce::Component* SimpleDock::trackerForSnapshot() { return trackerPage != nullptr ? trackerPage->trackerComponent() : nullptr; }
- void SimpleDock::padsLoadForCheck (int pad, const juce::File& file) { padsPage->loadFileForCheck (pad, file); }
- void SimpleDock::padsSelectForCheck (int pad) { padsPage->select (pad); }
- void SimpleDock::padsModeForCheck (int mode) { padsPage->setModeForCheck (mode); }
- void SimpleDock::padsKnobForCheck (int knob, float v) { padsPage->turnForCheck (knob, v); }
- void SimpleDock::padsRegionForCheck (float start, float end) { padsPage->setRegionForCheck (start, end); }
- void SimpleDock::padsNormalizeForCheck() { padsPage->normalizeForCheck(); }
- void SimpleDock::padsHitForCheck (int pad) { padsPage->hit (pad); }
- juce::Component* SimpleDock::padsCtaForCheck (int k) { return padsPage->ctaForCheck (k); }
- bool SimpleDock::padsRecordingForCheck() const { return padsPage->recordingForCheck(); }
- void SimpleDock::padsRecordForCheck() { padsPage->startRecordingForCheck(); }
- void SimpleDock::padsRecordingLookForSnapshot (bool on) { padsPage->recordingLookForSnapshot (on); }
- void SimpleDock::controlsTurnForCheck (int knob, float value) { controlsPage->turnForCheck (knob, value); }
- juce::String SimpleDock::controlsNameForCheck (int knob) const { return controlsPage->nameForCheck (knob); }
- float SimpleDock::controlsValueForCheck (int knob) const { return controlsPage->valueForCheck (knob); }
- void SimpleDock::controlsEditingForSnapshot (bool on) { controlsPage->setEditingForSnapshot (on); }
- juce::PopupMenu SimpleDock::controlsMenuForSnapshot (int knob) { return controlsPage->remapMenu (knob); }
- void SimpleDock::padsPressForSnapshot (int pad, float amount) { padsPage->pressForSnapshot (pad, amount); }
- void SimpleDock::padsWatchForCheck() { padsPage->watchPlayback(); }
- float SimpleDock::padsPressForCheck (int pad) const { return padsPage->pressShownForCheck (pad); }
- void SimpleDock::padsDragForCheck (int from, int to, bool copy) { padsPage->dragPadForCheck (from, to, copy); }
- void SimpleDock::padsUpdateForCheck() { padsPage->update(); }
- juce::PopupMenu SimpleDock::padMenuForSnapshot (int pad) { return padsPage->padMenuForSnapshot (pad); }
- juce::PopupMenu SimpleDock::kitMenuForSnapshot() { return padsPage->kitMenuForSnapshot(); }
- bool SimpleDock::saveKitForCheck (const juce::String& name) { return padsPage->saveKit (name); }
- bool SimpleDock::openKitForCheck (const juce::File& file) { return padsPage->openKit (file); }
- bool SimpleDock::renameKitForCheck (const juce::File& file, const juce::String& name) { return PadsPage::renameKit (file, name); }
- // Round 190ih (PLAN R14, DS-9): BandLab's dock shows "Input Level" with a slim bar on the right of its header
- // (bandlab190p shots/22-sampler-kits.png). Here it shows while the track's insert is armed to record from an input
- // (no input = no level), fed by the main window's 30 Hz timer only while the dock shows; only the bar repaints, and
- // only when its drawn width changes.
- bool SimpleDock::inputMeterShown() const
- {
- if (inputMeterForced)
- return true;
- const auto& song = engine.getSong();
- if (track < 0 || insert <= 0 || insert >= (int) song.mixer.size() || ! engine.isInsertArmed (insert) || song.mixer[(std::size_t) insert].inputChannel < 0)
- return false;
- const auto kind = simpletracks::kindOf (song, track);
- return kind && simpletracks::isAudioKind (*kind);
- }
- juce::Rectangle<int> SimpleDock::inputMeterArea() const
- {
- const auto right = followButton.isVisible() ? followButton.getX() - 10 : getWidth() - 10; // (round 190jj merge: 190jc moved the hide button to the left)
- // the label ("Input Level") takes its text's width, at least 70 px: "Nível de entrada" (pt-BR) was cut to "Nível de en..." (190nx)
- const auto label = juce::jmax (70, juce::GlyphArrangement::getStringWidthInt (font (type::small, true), tr ("Input Level")) + 6);
- const auto width = 162 + label;
- return { right - width, 0, width, stripHeight() };
- }
- juce::Rectangle<int> SimpleDock::inputMeterBar() const
- {
- const auto a = inputMeterArea();
- return { a.getRight() - 42 - 110, a.getCentreY() - 2, 110, 4 };
- }
- // round 190ld (DS-9, BandLab B22: a round headphones switch right of the input bar): hear the input while recording
- juce::Rectangle<int> SimpleDock::monitorButton() const
- {
- const auto a = inputMeterArea();
- const auto d = juce::jmin (32, a.getHeight() - 4);
- return { a.getRight() - d, a.getCentreY() - d / 2, d, d };
- }
- bool SimpleDock::monitoring() const
- {
- const auto& song = engine.getSong();
- if (insert <= 0 || insert >= (int) song.mixer.size())
- return false;
- const auto mode = song.mixer[(std::size_t) insert].monitor;
- return mode == InputMonitor::on || (mode != InputMonitor::off && engine.isInsertArmed (insert));
- }
- juce::Colour SimpleDock::trackColourNow() const
- {
- const auto& song = engine.getSong();
- if (track < 0)
- return theme::colour::accent;
- const auto own = track < (int) song.playlistTracks.size() ? song.playlistTracks[(std::size_t) track].colour : 0u;
- const auto kind = simpletracks::kindOf (song, track);
- return own != 0 ? juce::Colour (own).withAlpha (1.0f) : kind ? juce::Colour (simpletracks::defaultColour (*kind)).withAlpha (1.0f) : theme::colour::accent;
- }
- void SimpleDock::tickInputMeter()
- {
- if (! isShowing())
- return;
- if (padsPage != nullptr && padsPage->isVisible()) // round 190jj: the song's notes press the pads (BandLab)
- padsPage->watchPlayback();
- if (stepsPage != nullptr && stepsPage->isVisible()) // round 190lr: the step the song plays (only its two columns repaint)
- stepsPage->watchPlayback();
- const auto shown = inputMeterShown();
- auto level = 0.0f;
- if (shown && insert > 0)
- {
- const auto peak = juce::jmax (engine.takeInputPeak (insert, 0), engine.takeInputPeak (insert, 1));
- const auto db = juce::Decibels::gainToDecibels (peak, -60.0f);
- level = juce::jmax ((db + 60.0f) / 60.0f, inputLevel * 0.86f); // (a quick fall, as the Mixer's)
- if (level < 0.01f)
- level = 0.0f;
- }
- const auto width = juce::roundToInt (level * (float) inputMeterBar().getWidth());
- if (shown != inputMeterWasShown)
- {
- inputMeterWasShown = shown;
- repaint (getLocalBounds().withHeight (stripHeight())); // (the record hint moves left of it)
- }
- else if (width != juce::roundToInt (inputLevel * (float) inputMeterBar().getWidth()))
- repaint (inputMeterBar().expanded (1));
- inputLevel = level;
- }
- bool SimpleDock::recordHintShown() const
- {
- const auto& song = engine.getSong();
- if (track < 0 || insert <= 0 || insert >= (int) song.mixer.size() || ! engine.isInsertArmed (insert) || song.mixer[(std::size_t) insert].inputChannel < 0)
- return false;
- const auto kind = simpletracks::kindOf (song, track);
- return kind && simpletracks::isAudioKind (*kind) && *kind != simpletracks::Kind::audio;
- }
- juce::Component* SimpleDock::stepsComponentForSnapshot() { return stepsPage.get(); }
- int SimpleDock::stepsRowsForCheck() const { return stepsPage->rowCountForCheck(); }
- int SimpleDock::stepsCountForCheck() const { return stepsPage->stepCountForCheck(); }
- void SimpleDock::stepsClickForCheck (int row, int step) { stepsPage->clickStepForCheck (row, step); }
- void SimpleDock::stepsLetterForCheck (int letter) { stepsPage->pickLetterForCheck (letter); }
- void SimpleDock::stepsAddClipForCheck() { stepsPage->addClipForCheck(); }
- int SimpleDock::stepsMessagesShownForCheck() const { return stepsPage->messagesShownForCheck(); }
- void SimpleDock::stepsLengthForCheck (int bars) { stepsPage->setLengthForCheck (bars); }
- void SimpleDock::stepsSwingForCheck (float v) { stepsPage->setSwingForCheck (v); }
- void SimpleDock::stepsPreviewForCheck() { stepsPage->previewForCheck(); }
- bool SimpleDock::stepsPreviewingForCheck() const { return stepsPage->previewingForCheck(); }
- int SimpleDock::stepsPatternForCheck() const { return stepsPage->patternForCheck(); }
- int SimpleDock::stepsPlayingStepForCheck() const { return stepsPage->playingStepForCheck(); }
- void SimpleDock::stepsPlayingStepForSnapshot (int step) { stepsPage->playingStepForSnapshot (step); }
- juce::PopupMenu SimpleDock::stepsLengthMenuForSnapshot() { return stepsPage->lengthMenuForSnapshot(); }
- void SimpleDock::stepsWatchForCheck() { stepsPage->watchPlayback(); }
- void SimpleDock::stepsVelocityForCheck (int row, int step, float v) { stepsPage->velocityForCheck (row, step, v); }
- void SimpleDock::stepsVelocityToolForSnapshot (bool on) { stepsPage->velocityToolForSnapshot (on); }
- int SimpleDock::stepsChannelForKey (int keyCode)
- {
- if (! stepsTab || tab != Tab::steps)
- return -1;
- const auto channel = stepsPage->channelForKey (keyCode);
- if (channel >= 0)
- stepsPage->lightRow (simplesteps::rowForKey (keyCode));
- return channel;
- }
- void SimpleDock::lightPad (int pad)
- {
- if (padsTab && tab == Tab::pads)
- padsPage->lightPad (pad);
- }
- void SimpleDock::releaseEditor() { editorPage->release(); }
- bool SimpleDock::isEditorDocked() const noexcept { return editorPage->docked(); }
- std::vector<int> SimpleDock::trackAudioClips() const
- {
- std::vector<int> out;
- const auto& song = engine.getSong();
- for (int i = 0; i < (int) song.playlist.size(); ++i)
- if (const auto& c = song.playlist[(std::size_t) i]; c.kind == ClipKind::audio && c.track == track && track >= 0)
- out.push_back (i);
- return out;
- }
- // "Loop key: G minor · moved −5" and the switch, for an audio track whose loop has a known key (round 190ds)
- void SimpleDock::updateFollow()
- {
- const auto& song = engine.getSong();
- std::optional<keyfollow::LoopKey> key;
- bool all = true;
- int shift = 0;
- for (const auto i : trackAudioClips())
- {
- const auto& c = song.playlist[(std::size_t) i];
- if (const auto k = keyfollow::loopKeyOf (song, c.channel); k && ! key)
- {
- key = k;
- shift = keyfollow::shiftOf (song, c);
- }
- all = all && c.followKey;
- }
- const auto show = key.has_value() && simpletracks::kindOf (song, track) == simpletracks::Kind::audio;
- followButton.setVisible (show);
- followText.clear();
- if (show)
- {
- followButton.setToggleState (all, juce::dontSendNotification);
- const auto name = utf8 (projectkey::rootName (key->root)) + " " + (key->minor ? tr ("minor") : tr ("major"));
- followText = tr ("Loop key: {0}", { name }) + glyph (" \xc2\xb7 ")
- + (! projectkey::get (song) ? tr ("no project key") : ! all ? tr ("plays in its own key")
- : shift == 0 ? tr ("already in key") : tr ("moved {0} semitones", { (shift > 0 ? "+" : "") + juce::String (shift) }));
- }
- }
- bool SimpleDock::followShownForCheck() const { return followButton.isVisible(); }
- void SimpleDock::clickFollowForCheck()
- {
- const auto clips = trackAudioClips();
- bool all = ! clips.empty();
- for (const auto i : clips)
- all = all && engine.getSong().playlist[(std::size_t) i].followKey;
- engine.editSong ([clips, on = ! all] (Song& s) { keyfollow::setFollow (s, clips, on); });
- updateFollow();
- repaint();
- }
- void SimpleDock::clickFoldForCheck (bool on) { editorPage->clickFold (on); }
- juce::Component* SimpleDock::keyboardPanelForSnapshot()
- {
- setTab (Tab::keyboard);
- return keyboardPage.get();
- }
- int SimpleDock::heightFor (int available) const noexcept
- {
- // round 190jc (SG-11): the Pads tab needs its 4 x 44 px pads (Large controls: 48) under the strip
- const auto least = tab == Tab::pads && padsTab ? stripHeight() + 4 * ui::simplelook::px (44, 48) + 12 + 12 + 8 : minHeight;
- return juce::jlimit (std::min (least, available / 2), std::max (least, available * 6 / 10), juce::jmax (least, preferredHeight));
- }
- void SimpleDock::paint (juce::Graphics& g)
- {
- g.fillAll (colour::bg1);
- auto strip = getLocalBounds().withHeight (stripHeight());
- g.setColour (colour::bg3);
- g.fillRect (strip);
- g.setColour (colour::border);
- g.fillRect (0, 0, getWidth(), 1);
- g.fillRect (0, stripHeight() - 1, getWidth(), 1);
- // the resize grip in the middle of the top edge
- g.setColour (colour::borderStrong);
- g.fillRoundedRectangle ((float) getWidth() * 0.5f - 16.0f, 2.0f, 32.0f, 2.0f, 1.0f);
- const auto& song = engine.getSong();
- // round 190dg: the track's chain preset, right of the tabs (the header's FX button is too small to name it)
- auto rightEdge = followButton.isVisible() ? followButton.getX() - 10 : getWidth() - 10;
- if (inputMeterShown()) // round 190ih: "Input Level" and its bar (BandLab's dock header)
- {
- const auto area = inputMeterArea(), bar = inputMeterBar();
- g.setColour (colour::textPrimary);
- g.setFont (font (type::small, true));
- g.drawText (tr ("Input Level"), area.withRight (bar.getX() - 10), juce::Justification::centredRight, true);
- fillRoundRect (g, bar.toFloat(), 2.0f, colour::bg1);
- if (const auto w = juce::roundToInt (inputLevel * (float) bar.getWidth()); w > 0)
- {
- const auto db = inputLevel * 60.0f - 60.0f;
- fillRoundRect (g, bar.withWidth (w).toFloat(), 2.0f, db >= -0.5f ? colour::meterClip : db >= -9.0f ? colour::meterMid : colour::meterLow);
- }
- // the monitor switch (round 190ld): lit while the input is heard
- const auto button = monitorButton().toFloat();
- const auto on = monitoring();
- g.setColour (on ? colour::accent : colour::bg4);
- g.fillEllipse (button);
- ui::simplelook::drawGlyph (g, ui::simplelook::Glyph::headphones, button.reduced (button.getWidth() * 0.28f), on ? colour::onAccent : colour::textPrimary);
- rightEdge = area.getX() - 10;
- }
- if (followButton.isVisible()) // round 190ds: the loop's key and what following does
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (type::small));
- const auto area = strip.withLeft (effectsButton.getRight() + 16).withRight (rightEdge);
- g.drawText (followText, area, juce::Justification::centredRight, true);
- }
- else if (recordHintShown())
- {
- // round 190fo: a track armed to record from an input (the original's mobile app warns the same way)
- const auto area = strip.withLeft (effectsButton.getRight() + 16).withRight (rightEdge);
- g.setColour (colour::warning);
- g.setFont (font (type::small));
- g.drawFittedText (tr ("Recording: wear headphones, so the microphone does not pick up the playback"), area, juce::Justification::centredRight, 1, 0.8f);
- }
- else if (insert > 0 && insert < (int) song.mixer.size() && ! song.mixer[(std::size_t) insert].chainPreset.empty())
- {
- auto name = utf8 (song.mixer[(std::size_t) insert].chainPreset);
- if (! chains::unchanged (song, insert))
- name << " " << tr ("(edited)");
- const auto area = strip.withLeft (effectsButton.getRight() + 16).withRight (rightEdge);
- g.setColour (colour::textSecondary);
- g.setFont (font (type::small));
- g.drawText (tr ("Preset") + glyph (": ") + name, area, juce::Justification::centredRight, true);
- }
- auto text = strip.withLeft (hideButton.getRight() + 10).withRight (instrumentButton.isVisible() ? instrumentButton.getX() - 12
- : keyboardButton.isVisible() ? keyboardButton.getX() - 12
- : padsButton.isVisible() ? padsButton.getX() - 12
- : controlsButton.isVisible() ? controlsButton.getX() - 12
- : effectsButton.getX() - 12);
- if (track < 0)
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (type::body));
- g.drawText (tr ("No track selected"), text, juce::Justification::centredLeft, true);
- return;
- }
- const auto own = track < (int) song.playlistTracks.size() ? song.playlistTracks[(std::size_t) track].colour : 0u;
- const auto kind = simpletracks::kindOf (song, track);
- const auto hue = own != 0 ? juce::Colour (own) : kind ? juce::Colour (simpletracks::defaultColour (*kind)) : colour::textSecondary;
- // round 190jc (SG-7): the track's type icon in its colour (BandLab's Track View header), else the colour bar
- const auto ownIcon = track < (int) song.playlistTracks.size() ? trackicons::iconFor (song.playlistTracks[(std::size_t) track].icon) : trackicons::Icon::none;
- const auto icon = ownIcon != trackicons::Icon::none ? ownIcon : kind ? simpletracks::iconOf (*kind) : trackicons::Icon::none;
- if (icon != trackicons::Icon::none)
- {
- const auto size = (float) ui::simplelook::px (16, 20);
- ui::drawTrackIcon (g, icon, juce::Rectangle<float> ((float) text.getX(), (float) strip.getCentreY() - size * 0.5f, size, size),
- ui::simplelook::readableOn (hue, colour::bg3, 3.0f));
- text.removeFromLeft ((int) size + 8);
- }
- else
- {
- g.setColour (hue);
- g.fillRoundedRectangle ((float) text.getX(), (float) strip.getCentreY() - 7.0f, 4.0f, 14.0f, 2.0f);
- text.removeFromLeft (12);
- }
- g.setColour (colour::textPrimary);
- g.setFont (font (ui::simplelook::largeControls() ? type::title : type::body, true));
- const auto title = trackTitle (song, track);
- const auto titleWidth = juce::jmin (text.getWidth(), juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), title) + 4);
- g.drawText (title, text.removeFromLeft (titleWidth), juce::Justification::centredLeft, true);
- if (kind)
- {
- g.setColour (colour::textSecondary);
- g.setFont (font (type::small));
- g.drawText (glyph ("\xc2\xb7 ") + tr (simpletracks::defaultName (*kind)), text.withTrimmedLeft (6), juce::Justification::centredLeft, true);
- }
- }
- int SimpleDock::stripHeight() { return ui::simplelook::px (36, 48); }
- void SimpleDock::lookChanged()
- {
- refresh(); // (lays the strip and the pages out again)
- padsPage->resized(); // (the pads' size floor; its bounds may stay the same)
- if (keyboardPage != nullptr)
- keyboardPage->resized();
- if (auto* holder = getParentComponent())
- holder->resized();
- }
- void SimpleDock::StripButton::paintButton (juce::Graphics& g, bool over, bool down)
- {
- using namespace theme;
- const auto r = getLocalBounds().toFloat();
- if (glyph < 0) // BandLab's round close X (the same action as the old caret: hides the dock)
- {
- const auto d = juce::jmin (r.getWidth(), r.getHeight());
- const auto circle = juce::Rectangle<float> (d, d).withCentre (r.getCentre());
- g.setColour (down ? colour::bg6 : over ? colour::bg5 : colour::bg4);
- g.fillEllipse (circle);
- ui::simplelook::drawGlyph (g, ui::simplelook::Glyph::cross, circle.withSizeKeepingCentre (d * 0.34f, d * 0.34f), colour::textPrimary, 1.5f);
- return;
- }
- const auto on = getToggleState() && ! lone;
- if (! lone)
- {
- // one pill per tab, joined into a segmented control: rounded only at the group's ends
- const auto left = ! isConnectedOnLeft(), right = ! isConnectedOnRight();
- const auto fill = on ? (down ? colour::accentPressed : over ? colour::accentHover : colour::accent) : down ? colour::bg6 : over ? colour::bg5 : colour::bg4;
- juce::Path p;
- p.addRoundedRectangle (r.getX(), r.getY(), r.getWidth() - (right ? 0.0f : 1.0f), r.getHeight(), radius::lg, radius::lg, left, right, left, right);
- g.setColour (fill);
- g.fillPath (p);
- }
- const auto f = font (ui::simplelook::largeControls() ? type::title : type::body, on || lone);
- const auto text = getButtonText();
- const auto iconSize = (float) ui::simplelook::px (14, 18), gap = 6.0f;
- const auto textWidth = juce::GlyphArrangement::getStringWidth (f, text);
- const auto total = juce::jmin (r.getWidth() - 12.0f, iconSize + gap + textWidth);
- auto content = lone ? r.withTrimmedLeft (4.0f).withWidth (total) : r.withSizeKeepingCentre (total, r.getHeight());
- const auto ink = on ? colour::onAccent : lone ? colour::textPrimary : over ? colour::textPrimary : colour::textSecondary;
- ui::simplelook::drawGlyph (g, (ui::simplelook::Glyph) glyph, content.removeFromLeft (iconSize).withSizeKeepingCentre (iconSize, iconSize), ink, 1.4f);
- content.removeFromLeft (gap);
- g.setColour (ink);
- g.setFont (f);
- g.drawFittedText (text, content.toNearestInt(), juce::Justification::centredLeft, 1, 0.8f);
- if (lone) // a section title: a short accent line under it
- {
- g.setColour (colour::accent);
- g.fillRoundedRectangle (r.getX() + 4.0f, r.getBottom() - 2.0f, 24.0f, 2.0f, 1.0f);
- }
- }
- void SimpleDock::resized()
- {
- // round 190jc (SG-7, SG-8): the round close X at the left (28 px; Large controls 40), tabs 28 px tall (40) with icons
- const auto stripAll = getLocalBounds().withHeight (stripHeight());
- const auto closeSize = ui::simplelook::px (28, 40);
- hideButton.setBounds (juce::Rectangle<int> (8, (stripAll.getHeight() - closeSize) / 2, closeSize, closeSize));
- const auto tabHeight = ui::simplelook::px (28, 40), tabWidth = ui::simplelook::px (112, 136);
- auto strip = stripAll.withSizeKeepingCentre (stripAll.getWidth(), tabHeight);
- followButton.setBounds (strip.removeFromRight (190).withTrimmedRight (10).withSizeKeepingCentre (180, juce::jmin (24, tabHeight)));
- // the tabs sit after the track's name, left of the middle
- const auto count = 1 + (instrumentTab ? 1 : 0) + (playTabs ? 3 : 0) + (padsTab ? 1 : 0) + (stepsTab ? 1 : 0) + (controlsTab ? 1 : 0);
- auto tabs = strip.withLeft (juce::jmin (300, getWidth() / 3)).withWidth (tabWidth * count);
- std::vector<juce::TextButton*> shown;
- if (instrumentTab)
- shown.push_back (&instrumentButton);
- if (playTabs)
- shown.push_back (&keyboardButton), shown.push_back (&editorButton), shown.push_back (&trackerButton);
- if (padsTab)
- shown.push_back (&padsButton);
- if (stepsTab)
- shown.push_back (&stepsButton);
- if (controlsTab)
- shown.push_back (&controlsButton);
- shown.push_back (&effectsButton);
- for (std::size_t i = 0; i < shown.size(); ++i)
- {
- shown[i]->setConnectedEdges ((i > 0 ? juce::Button::ConnectedOnLeft : 0) | (i + 1 < shown.size() ? juce::Button::ConnectedOnRight : 0));
- static_cast<StripButton*> (shown[i])->lone = shown.size() == 1; // (round 190jc: an audio track's only tab is a title)
- shown[i]->setBounds (tabs.removeFromLeft (tabWidth));
- }
- const auto body = getLocalBounds().withTrimmedTop (stripHeight());
- effectsPage->setBounds (body);
- instrumentPage->setBounds (body);
- editorPage->setBounds (body);
- trackerPage->setBounds (body);
- padsPage->setBounds (body);
- stepsPage->setBounds (body);
- controlsPage->setBounds (body);
- if (keyboardPage != nullptr)
- keyboardPage->setBounds (body);
- }
- void SimpleDock::mouseMove (const juce::MouseEvent& e)
- {
- setMouseCursor (e.y < edgeHeight ? juce::MouseCursor::UpDownResizeCursor : juce::MouseCursor::NormalCursor);
- }
- void SimpleDock::mouseDown (const juce::MouseEvent& e)
- {
- if (inputMeterShown() && insert > 0 && monitorButton().contains (e.getPosition()) && ! e.mods.isPopupMenu())
- {
- // hear the input (Monitor On) / don't (Off); the Mixer's input menu has the other modes
- engine.editSong ([i = insert, on = ! monitoring()] (Song& s) {
- if (i < (int) s.mixer.size())
- s.mixer[(std::size_t) i].monitor = on ? InputMonitor::on : InputMonitor::off;
- });
- repaint (monitorButton().expanded (2));
- return;
- }
- resizing = e.y < edgeHeight;
- dragStartHeight = getHeight();
- }
- void SimpleDock::mouseDrag (const juce::MouseEvent& e)
- {
- if (! resizing)
- return;
- const auto wanted = juce::jmax (minHeight, dragStartHeight - e.getDistanceFromDragStartY());
- if (wanted != preferredHeight)
- {
- preferredHeight = wanted;
- if (auto* parent = getParentComponent())
- parent->resized();
- }
- }
- void SimpleDock::mouseUp (const juce::MouseEvent&)
- {
- if (resizing && hooks.layoutChanged)
- hooks.layoutChanged(); // (saves the height)
- resizing = false;
- }
- // --- the user's own chain presets ------------------------------------------------------------------------------------
- juce::File SimpleDock::userPresetFolder() { return platform::documentsFolder().getChildFile ("LYNX/Chain presets"); }
- // round 190dg: the favourite chain presets, one name a line, in the order they were starred
- juce::File SimpleDock::favouritesFile() { return userPresetFolder().getChildFile ("Favourites.txt"); }
- juce::StringArray SimpleDock::favouritePresets()
- {
- auto lines = juce::StringArray::fromLines (favouritesFile().loadFileAsString());
- lines.trim();
- lines.removeEmptyStrings();
- lines.removeDuplicates (false);
- return lines;
- }
- bool SimpleDock::setFavouritePreset (const juce::String& name, bool on)
- {
- auto lines = favouritePresets();
- if (on)
- lines.addIfNotAlreadyThere (name.trim());
- else
- lines.removeString (name.trim());
- favouritesFile().getParentDirectory().createDirectory();
- return favouritesFile().replaceWithText (lines.joinIntoString ("\n") + (lines.isEmpty() ? "" : "\n"));
- }
- bool SimpleDock::saveUserPreset (AudioEngine& engine, int insert, const juce::String& rawName)
- {
- const auto name = juce::File::createLegalFileName (rawName.trim());
- if (name.isEmpty() || insert < 0 || insert >= (int) engine.getSong().mixer.size())
- return false;
- engine.capturePluginStates(); // the plugins' current settings go into the preset
- const auto file = userPresetFolder().getChildFile (name + ProjectFile::mixerTrackStateExtension);
- file.getParentDirectory().createDirectory();
- const auto state = chains::stateOf (engine.getSong().mixer[(std::size_t) insert], name.toStdString());
- if (! file.replaceWithText (ProjectFile::mixerTrackStateToJson (state)))
- return false;
- engine.editSong ([insert, n = name.toStdString()] (Song& s) {
- if (insert < (int) s.mixer.size())
- s.mixer[(std::size_t) insert].chainPreset = n;
- });
- return true;
- }
- bool SimpleDock::loadUserPreset (AudioEngine& engine, int insert, const juce::File& file)
- {
- juce::String error;
- auto state = ProjectFile::mixerTrackStateFromJson (file.loadFileAsString(), error);
- if (! state || insert < 0 || insert >= (int) engine.getSong().mixer.size())
- return false;
- const auto name = file.getFileNameWithoutExtension().toStdString();
- engine.editSongStructural ([insert, &state, &name] (Song& s) { chains::applyChain (s, insert, state->effects, state->chainBlend, name); });
- return true;
- }
- // --- tests and --simplefxshot ----------------------------------------------------------------------------------------
- int SimpleDock::cardCountForCheck() const { return effectsPage->cardCount(); }
- int SimpleDock::oneKnobCardsForCheck() const { return effectsPage->oneKnobCards(); }
- juce::PopupMenu SimpleDock::presetMenuForSnapshot() { return effectsPage->presetMenu(); }
- void SimpleDock::stepPresetForCheck (int delta) { effectsPage->stepPreset (delta); }
- void SimpleDock::bypassChainForCheck() { effectsPage->bypassForCheck(); }
- bool SimpleDock::bypassLitForCheck() const { return effectsPage->bypassLitForCheck(); }
- juce::PopupMenu SimpleDock::addMenuForSnapshot() { return effectsPage->addMenu(); }
- void SimpleDock::setFontsForSnapshot (std::vector<sf::IndexedFont> fonts)
- {
- instrumentPage->setFonts (std::move (fonts), true);
- instrumentPage->setSource (InstrumentPage::From::fonts);
- }
- void SimpleDock::setPluginsForSnapshot (std::vector<soundlib::InstalledPlugin> plugins)
- {
- instrumentPage->setPlugins (std::move (plugins));
- instrumentPage->setSource (InstrumentPage::From::plugins);
- }
- void SimpleDock::showCategoryForSnapshot (int category) { instrumentPage->pickCategory (category); }
- int SimpleDock::soundRowsForCheck() const { return instrumentPage->rowCount(); }
- juce::String SimpleDock::soundNameForCheck() const { return instrumentPage->shownName(); }
- void SimpleDock::clickSoundForCheck (int row) { instrumentPage->clickRow (row, false); }
- void SimpleDock::stepSoundForCheck (int delta) { instrumentPage->stepSound (delta); }
- void SimpleDock::turnKnobForCheck (int card, float value) { effectsPage->turnForCheck (card, value); }
- void SimpleDock::moveCardForCheck (int card, int delta) { effectsPage->move (card, delta); }
- void SimpleDock::removeCardForCheck (int card) { effectsPage->remove (card); }
- void SimpleDock::addOneKnobForCheck (int goal) { effectsPage->addOneKnob (goal); }
- void SimpleDock::setBlendForCheck (float value) { effectsPage->blendForCheck (value); }
- void SimpleDock::setReverbForCheck (float value) { effectsPage->reverbForCheck (value); }
- void SimpleDock::setEchoForCheck (float value) { effectsPage->echoForCheck (value); }
- void SimpleDock::duckUnderForCheck (int triggerInsert) { effectsPage->duckForCheck (triggerInsert); }
- juce::PopupMenu SimpleDock::duckMenuForCheck() { return effectsPage->duckMenuForCheck(); }
- juce::String SimpleDock::duckButtonTextForCheck() const { return effectsPage->duckButtonTextForCheck(); }
- juce::Rectangle<int> SimpleDock::cardBoundsForSnapshot (int card) const
- {
- const auto* c = effectsPage->cardForSnapshot (card);
- return c != nullptr ? getLocalArea (c, c->getLocalBounds()) : juce::Rectangle<int>();
- }
- void SimpleDock::setSearchForSnapshot (const juce::String& text) { instrumentPage->searchFor (text); }
- } // namespace lynx
|