DetailView.cpp 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465
  1. #include "ui/TextCache.h"
  2. #include "ui/ShotShowing.h"
  3. #include "ui/DetailView.h"
  4. #include "core/StandIns.h"
  5. #include "ui/MapMode.h"
  6. #include <algorithm>
  7. #include <array>
  8. #include <cmath>
  9. #include <map>
  10. #include <set>
  11. #include "core/AlsImport.h"
  12. #include "core/Braid.h"
  13. #include "core/ClipLauncher.h"
  14. #include "core/ClipLoopOps.h"
  15. #include "core/ClipSample.h"
  16. #include "core/DetailChain.h"
  17. #include "core/RackOps.h"
  18. #include "core/Groove.h"
  19. #include "core/GrooveAudio.h"
  20. #include "core/Effects.h"
  21. #include "core/FlEffects.h"
  22. #include "core/HotSwap.h"
  23. #include "core/MeterBallistics.h"
  24. #include "core/NoteEdit.h"
  25. #include "core/NoteNames.h"
  26. #include "core/NoteTools.h"
  27. #include "core/PlaylistOps.h"
  28. #include "core/ProjectKey.h"
  29. #include "core/Rack.h"
  30. #include "core/NativeEngines.h"
  31. #include "engine/AudioEngine.h"
  32. #include "engine/FlStudio.h"
  33. #include "ui/BrowserComponent.h"
  34. #include "ui/ClipAudioPanel.h"
  35. #include "ui/ColourPicker.h"
  36. #include "ui/EditorTools.h"
  37. #include "ui/EventEditor.h"
  38. #include "ui/FlMods.h"
  39. #include "ui/HintBar.h"
  40. #include "ui/I18n.h"
  41. #include "ui/MidiToolsPanel.h"
  42. #include "ui/MixerComponent.h"
  43. #include "ui/NumBox.h"
  44. #include "ui/LiveClipLook.h"
  45. #include "ui/LiveLook.h"
  46. #include "ui/PianoRollComponent.h"
  47. #include "ui/PlaylistComponent.h"
  48. #include "ui/PluginHeader.h"
  49. #include "ui/PluginThumbs.h"
  50. #include "ui/QuickPick.h"
  51. #include "ui/RackEditor.h"
  52. #include "ui/Theme.h"
  53. #include "ui/TimerWhileShowing.h"
  54. #include "ui/ValueControl.h"
  55. namespace lynx
  56. {
  57. using namespace theme;
  58. namespace
  59. {
  60. juce::String utf8 (const std::string& s) { return juce::String::fromUTF8 (s.c_str()); }
  61. // A size in LYNX's look and in Live's (round 190jn, design190ia CL-21: the Clip-launch layout's Live look); reads as an int.
  62. struct LookMetric
  63. {
  64. int classic, live;
  65. operator int() const noexcept { return theme::livelook::active() ? live : classic; }
  66. };
  67. // card geometry (px at 100 %); Live 12.4's device title bar is 17 px (live-session.png Utility y 807..823)
  68. constexpr int contextWidth = 132, meterWidth = 22, gap = 4, foldedWidth = 22, addWidth = 44;
  69. const LookMetric titleHeight { 20, 17 };
  70. constexpr int knobColumn = 62, knobRow = 70, knobSize = 30, instrumentWidth = 196, pluginWidth = 172;
  71. constexpr int maxEffectKnobs = 7; // + the slot's Mix
  72. // Round 190ko: an instrument card can show its engine's main parameters as knobs (Live's generic device look: knob
  73. // columns, two rows), as an effect card does. Knob id = engineKnobBase + the engine's parameter index.
  74. constexpr int engineKnobBase = 100;
  75. const std::vector<int>& engineCardParams (InstrumentKind kind)
  76. {
  77. namespace b = braid;
  78. // Braid (Live's Meld): engine A on the top row, B below — oscillator type and macros, filter frequency and macros, volume
  79. static const std::vector<int> braidKnobs = [] {
  80. std::vector<int> v;
  81. for (const int p : { b::eng::oscType, b::eng::oscMacro1, b::eng::oscMacro2, b::eng::filterFreq, b::eng::filterMacro1, b::eng::filterMacro2,
  82. b::eng::volume })
  83. for (int k = 0; k < 2; ++k)
  84. v.push_back (b::engineBase (k) + p);
  85. return v;
  86. }();
  87. static const std::vector<int> none;
  88. return kind == InstrumentKind::braid ? braidKnobs : none;
  89. }
  90. juce::String insertName (const Song& song, int insert)
  91. {
  92. if (insert == 0)
  93. return tr ("Master");
  94. if (insert < 0 || insert >= (int) song.mixer.size())
  95. return {};
  96. const auto own = utf8 (song.mixer[(std::size_t) insert].name);
  97. const auto number = tr ("Insert {0}", { juce::String (insert) });
  98. // (round 190oo CS-13: an insert still called by its default name read "Insert 1 Insert 1")
  99. const auto isDefault = own == "Insert " + juce::String (insert) || own == number;
  100. return own.isNotEmpty() && ! isDefault ? number + " " + own : number;
  101. }
  102. juce::String trackName (const Song& song, int track)
  103. {
  104. if (track >= 0 && track < (int) song.playlistTracks.size() && ! song.playlistTracks[(std::size_t) track].name.empty())
  105. return utf8 (song.playlistTracks[(std::size_t) track].name);
  106. return tr ("Track {0}", { juce::String (track + 1) });
  107. }
  108. void drawVerticalText (juce::Graphics& g, const juce::String& text, juce::Rectangle<int> area)
  109. {
  110. juce::Graphics::ScopedSaveState save (g);
  111. g.addTransform (juce::AffineTransform::rotation (-juce::MathConstants<float>::halfPi, (float) area.getCentreX(), (float) area.getCentreY()));
  112. const auto turned = juce::Rectangle<int> (area.getHeight(), area.getWidth()).withCentre (area.getCentre());
  113. g.drawText (text, turned.reduced (4, 0), juce::Justification::centredRight, true);
  114. }
  115. // The window glyph on a card's title bar.
  116. void drawWindowGlyph (juce::Graphics& g, juce::Rectangle<int> r, bool hot)
  117. {
  118. const auto box = r.toFloat().withSizeKeepingCentre (11.0f, 9.0f);
  119. g.setColour (hot ? colour::textPrimary : colour::textSecondary);
  120. g.drawRect (box, 1.0f);
  121. g.fillRect (box.withHeight (2.5f));
  122. }
  123. // Round 190ce: the hot-swap button of a card's title bar (the reference's round button with two arrows, left of its
  124. // save button [lesson image BrowseButtonInst.png, shot d04]); filled with the accent colour while the Browser is linked.
  125. void drawSwapGlyph (juce::Graphics& g, juce::Rectangle<int> r, bool hot, bool linked)
  126. {
  127. const auto box = r.toFloat().withSizeKeepingCentre (13.0f, 13.0f);
  128. if (linked)
  129. {
  130. g.setColour (colour::accent);
  131. g.fillEllipse (box);
  132. }
  133. g.setColour (linked ? juce::Colours::white : hot ? colour::textPrimary : colour::textSecondary);
  134. g.drawEllipse (box, 1.0f);
  135. const auto cx = box.getCentreX(), cy = box.getCentreY();
  136. juce::Path p; // two arrows, one each way
  137. p.startNewSubPath (cx - 3.0f, cy - 2.0f);
  138. p.lineTo (cx + 3.0f, cy - 2.0f);
  139. p.lineTo (cx + 1.0f, cy - 4.0f);
  140. p.startNewSubPath (cx + 3.0f, cy + 2.0f);
  141. p.lineTo (cx - 3.0f, cy + 2.0f);
  142. p.lineTo (cx - 1.0f, cy + 4.0f);
  143. g.strokePath (p, juce::PathStrokeType (1.0f));
  144. }
  145. // Round 190jn (CL-21): Live's title-bar wells (theme::livelook::drawWell) and the LYNX vector glyphs drawn in them.
  146. void drawLiveWellGlyph (juce::Graphics& g, juce::Rectangle<int> r, int kind, bool hot, bool lit)
  147. {
  148. namespace ll = theme::livelook;
  149. const auto box = r.toFloat();
  150. auto ink = ll::drawWell (g, box, lit);
  151. if (hot && ! lit)
  152. ink = colour::textPrimary;
  153. g.setColour (ink);
  154. const auto cx = box.getCentreX(), cy = box.getCentreY();
  155. if (kind == 0) // window: a small frame with its title band
  156. {
  157. const auto f = juce::Rectangle<float> (7.0f, 6.0f).withCentre ({ cx, cy });
  158. g.drawRect (f, 1.0f);
  159. g.fillRect (f.withHeight (2.0f));
  160. }
  161. else if (kind == 1) // hot-swap: two arrows, one each way
  162. {
  163. juce::Path p;
  164. p.startNewSubPath (cx - 3.0f, cy - 1.5f);
  165. p.lineTo (cx + 3.0f, cy - 1.5f);
  166. p.lineTo (cx + 1.0f, cy - 3.5f);
  167. p.startNewSubPath (cx + 3.0f, cy + 1.5f);
  168. p.lineTo (cx - 3.0f, cy + 1.5f);
  169. p.lineTo (cx - 1.0f, cy + 3.5f);
  170. g.strokePath (p, juce::PathStrokeType (1.2f));
  171. }
  172. else // save: a filled disk with its label slot
  173. {
  174. const auto d = juce::Rectangle<float> (7.0f, 7.0f).withCentre ({ cx, cy });
  175. g.fillRoundedRectangle (d, 1.0f);
  176. g.setColour (lit ? ll::on : ll::well);
  177. g.fillRect (d.getX() + 2.0f, d.getY() + 1.0f, 3.0f, 2.0f);
  178. }
  179. }
  180. // The save-preset button beside it (the reference's disk).
  181. void drawSaveGlyph (juce::Graphics& g, juce::Rectangle<int> r, bool hot)
  182. {
  183. const auto box = r.toFloat().withSizeKeepingCentre (11.0f, 11.0f);
  184. g.setColour (hot ? colour::textPrimary : colour::textSecondary);
  185. g.drawRoundedRectangle (box, 1.5f, 1.0f);
  186. g.fillRect (box.getX() + 3.0f, box.getY() + 1.0f, 5.0f, 3.0f);
  187. g.fillRect (box.getX() + 2.5f, box.getBottom() - 4.5f, 6.0f, 3.0f);
  188. }
  189. } // namespace
  190. // ---------------------------------------------------------------------------------------------------------------------
  191. // The Device View: the chain of cards.
  192. class DetailView::DeviceChain final : public juce::Component,
  193. public ui::HintSource,
  194. public mapmode::SpotSource,
  195. public juce::DragAndDropTarget,
  196. private juce::ChangeListener,
  197. private juce::Timer,
  198. private juce::ScrollBar::Listener
  199. {
  200. public:
  201. DeviceChain (AudioEngine& e, Hooks& h) : engine (e), hooks (h), slotActions (e)
  202. {
  203. setWantsKeyboardFocus (true);
  204. setTitle (tr ("Device view"));
  205. // the cards' menus are the Mixer slot's own (same code), opened over this view, with Fold / Unfold first
  206. slotActions.setMenuTarget (this);
  207. slotActions.extendSlotMenu = [this] (juce::PopupMenu& menu, int slot) {
  208. const auto key = tagOf (slot);
  209. // round 190ce: the reference's device menu starts with Cut / Copy, then Fold [shot d04]; Paste and
  210. // Duplicate are its Edit menu's commands on the selected device. Round gap190og (deviceview-0012): "Pasted
  211. // devices are inserted in front of the selected device" [DOC Live 12 manual, Working with Instruments and
  212. // Effects] (before: after it)
  213. menu.addItem (tr ("Cut") + "\tCtrl+X", [this, slot] { copyDevice (slot, true); });
  214. menu.addItem (tr ("Copy") + "\tCtrl+C", [this, slot] { copyDevice (slot, false); });
  215. menu.addItem (tr ("Paste") + "\tCtrl+V", deviceClipboard().has_value() && effectCount() < maxEffectSlots, false, [this, slot] { pasteDevice (slot); });
  216. menu.addItem (tr ("Duplicate") + "\tCtrl+D", effectCount() < maxEffectSlots, false, [this, slot] { duplicateDevice (slot, -1); });
  217. menu.addSeparator();
  218. menu.addItem (folded.count (key) > 0 ? tr ("Unfold") : tr ("Fold"), [this, key] { toggleFold (key); });
  219. menu.addItem (tr ("Hot-swap in the Browser") + "\tQ", hooks.toggleHotSwap != nullptr, linkedTo (hotswap::Kind::effect, key), [this, slot] { toggleSwap (hotswap::targetOfEffect (engine.getSong(), insert, slot)); });
  220. if (canSavePreset (slot))
  221. menu.addItem (tr ("Save preset..."), [this, slot] { savePreset (slot); });
  222. menu.addSeparator();
  223. };
  224. addAndMakeVisible (cardHost); // (custom card bodies; clicks elsewhere fall through to this view)
  225. cardHost.setInterceptsMouseClicks (false, true);
  226. addChildComponent (scrollBar);
  227. scrollBar.addListener (this);
  228. scrollBar.setAutoHide (false);
  229. engine.addChangeListener (this);
  230. showingTimer = std::make_unique<ui::TimerWhileShowing> (*this, static_cast<juce::Timer&> (*this), 30);
  231. showingTimer->onRunningChanged = [this] (bool running) {
  232. if (! running)
  233. watchDevices (false); // (round 190lr: hidden, the audio thread stops measuring the devices' levels)
  234. };
  235. }
  236. ~DeviceChain() override
  237. {
  238. watchDevices (false);
  239. engine.removeChangeListener (this);
  240. }
  241. void setTrack (int t)
  242. {
  243. if (t != track)
  244. chosenInsert = -1;
  245. track = t;
  246. refresh();
  247. }
  248. int insertShown() const noexcept { return insert; }
  249. int channelShown() const noexcept { return channel; }
  250. int cardCount() const noexcept { return (int) cards.size(); }
  251. // (issue #191's check: where the card's window button is, in this component's coordinates; empty: none)
  252. juce::Rectangle<int> windowButtonOf (int i) const
  253. {
  254. if (i < 0 || i >= (int) cards.size() || cards[(std::size_t) i].kind == Card::add || cards[(std::size_t) i].folded)
  255. return {};
  256. return windowBounds (cards[(std::size_t) i]);
  257. }
  258. bool isCardFolded (int i) const { return i >= 0 && i < (int) cards.size() && cards[(std::size_t) i].folded; }
  259. // (--zorder191test, rollup 0.1.31 step 2: the card's window button pressed when a plugin editor covers it on screen)
  260. bool pressWindowButtonForCheck (int i)
  261. {
  262. if (i < 0 || i >= (int) cards.size())
  263. return false;
  264. toggleWindow (cards[(std::size_t) i]);
  265. return true;
  266. }
  267. void toggleCardFold (int i)
  268. {
  269. if (i >= 0 && i < (int) cards.size() && cards[(std::size_t) i].kind != Card::add)
  270. toggleFold (keyOf (cards[(std::size_t) i]));
  271. }
  272. // round 190ce: what the hot-swap key links the Browser to (the selected card; none: nothing selected)
  273. hotswap::Target selectedTarget() const
  274. {
  275. const auto i = selectedCard();
  276. return i < 0 ? hotswap::Target() : targetOf (cards[(std::size_t) i]);
  277. }
  278. void selectCard (int i) { select (i); }
  279. void showCardMenuForSnapshot (int i)
  280. {
  281. if (i >= 0 && i < (int) cards.size() && cards[(std::size_t) i].kind != Card::add)
  282. showCardMenu (i);
  283. }
  284. // (round 190hr shots and checks) Ctrl+G / Ctrl+Shift+G on the instrument card
  285. bool groupCardForCheck (int i, bool ungroup)
  286. {
  287. if (i < 0 || i >= (int) cards.size() || cards[(std::size_t) i].kind != Card::instrument)
  288. return false;
  289. const auto channel = cards[(std::size_t) i].index;
  290. if (ungroup)
  291. ungroupInstrument (channel);
  292. else
  293. groupInstrument (channel);
  294. const auto& song = engine.getSong();
  295. return channel < (int) song.channels.size() && rack::isRack (song.channels[(std::size_t) channel]) != ungroup;
  296. }
  297. // the 0 key: the selected device on / off
  298. bool toggleSelectedOn()
  299. {
  300. const auto i = selectedCard();
  301. if (i < 0)
  302. return false;
  303. toggleOn (cards[(std::size_t) i]);
  304. return true;
  305. }
  306. // round gap190og (deviceview-0012): Live's Edit menu on the selected device — Cut, Copy, Paste, Duplicate, Delete
  307. // [SHOT live190gu/screens-live/live-edit-menu.png; DOC Live 12 manual: "Edit menu commands such as cut, copy, paste,
  308. // and duplicate can be used on devices", "select Delete from the Edit menu"]. Paste goes in front of the selected
  309. // device, at the end of the chain with none (or the instrument) selected.
  310. enum class EditCommand { cut, copy, paste, duplicate, remove };
  311. bool canEdit (EditCommand command) const
  312. {
  313. const auto i = selectedCard();
  314. const auto effect = i >= 0 && cards[(std::size_t) i].kind == Card::effect;
  315. switch (command)
  316. {
  317. case EditCommand::cut:
  318. case EditCommand::copy:
  319. case EditCommand::remove: return effect;
  320. case EditCommand::paste: return insert >= 0 && deviceClipboard().has_value() && effectCount() < maxEffectSlots;
  321. case EditCommand::duplicate: return effect && effectCount() < maxEffectSlots;
  322. }
  323. return false;
  324. }
  325. bool runEdit (EditCommand command)
  326. {
  327. if (! canEdit (command))
  328. return false;
  329. const auto i = selectedCard();
  330. const auto effect = i >= 0 && cards[(std::size_t) i].kind == Card::effect;
  331. const auto slot = effect ? cards[(std::size_t) i].index : -1;
  332. switch (command)
  333. {
  334. case EditCommand::cut: copyDevice (slot, true); break;
  335. case EditCommand::copy: copyDevice (slot, false); break;
  336. case EditCommand::paste: pasteDevice (effect ? slot : effectCount()); break;
  337. case EditCommand::duplicate: duplicateDevice (slot, -1); break;
  338. case EditCommand::remove:
  339. slotActions.deleteSlot (slot);
  340. refresh();
  341. break;
  342. }
  343. return true;
  344. }
  345. bool duplicateCard (int i)
  346. {
  347. if (i < 0 || i >= (int) cards.size() || cards[(std::size_t) i].kind != Card::effect)
  348. return false;
  349. duplicateDevice (cards[(std::size_t) i].index, -1);
  350. return true;
  351. }
  352. void paint (juce::Graphics& g) override
  353. {
  354. g.fillAll (theme::livelook::active() ? theme::livelook::window : colour::bg1); // (Live: the cards lie on #2A2A2A)
  355. paintContext (g);
  356. const auto area = chainArea();
  357. {
  358. juce::Graphics::ScopedSaveState save (g);
  359. g.reduceClipRegion (area);
  360. for (int i = 0; i < (int) cards.size(); ++i)
  361. {
  362. paintCard (g, i);
  363. if (const auto& card = cards[(std::size_t) i]; card.kind != Card::add && cardLocked (card))
  364. {
  365. // (round 190ff) a frozen device: dimmed, with the freeze tag on its title
  366. g.setColour (colour::bg1.withAlpha (0.45f));
  367. g.fillRect (card.bounds.reduced (1));
  368. theme::drawFrozenTag (g, juce::Rectangle<float> ((float) card.bounds.getRight() - 22.0f, (float) card.bounds.getY() + 4.0f, 14.0f, 13.0f),
  369. colour::info.withAlpha (0.85f), colour::bg1);
  370. }
  371. }
  372. if (insert < 0 && channel < 0)
  373. {
  374. g.setColour (colour::textSecondary); // (round 190oj CS-15: the hints read 3.0-3.2:1)
  375. g.setFont (font (type::small));
  376. g.drawText (track < 0 ? tr ("Select a track in the clip grid to see its devices")
  377. : tr ("This track has no clips yet: put a clip on it to see its devices"),
  378. area, juce::Justification::centred, true);
  379. }
  380. else if (insert >= 0) // the free room after the last card shows the drop hint, as the reference does [SHOT d01]
  381. {
  382. const auto room = area.withLeft (cards.empty() ? area.getX() : cards.back().bounds.getRight() + cardGap());
  383. if (room.getWidth() > 120)
  384. {
  385. g.setColour (colour::textSecondary);
  386. g.setFont (font (type::small));
  387. g.drawText (tr ("Drop effects here"), room, juce::Justification::centred, true);
  388. }
  389. }
  390. if (dropBefore >= 0)
  391. {
  392. g.setColour (colour::accent);
  393. g.fillRect (juce::Rectangle<int> (dropLineX (dropBefore) - 1, area.getY() + 2, 3, area.getHeight() - 4));
  394. }
  395. paintDeviceMeters (g); // round 190lr (DL-87)
  396. }
  397. paintMeter (g);
  398. }
  399. void resized() override
  400. {
  401. const auto area = chainArea();
  402. scrollBar.setBounds (area.getX(), getHeight() - 8, area.getWidth(), 8);
  403. cardHost.setBounds (area);
  404. layoutCards();
  405. }
  406. // --- mouse ---------------------------------------------------------------------------------------------------
  407. void mouseDown (const juce::MouseEvent& e) override
  408. {
  409. grabKeyboardFocus();
  410. const auto hit = hitAt (e.getPosition());
  411. dragCard = -1;
  412. dragging = false;
  413. if (hit.part == Part::picker)
  414. return showInsertMenu();
  415. if (hit.card < 0)
  416. return;
  417. const auto& card = cards[(std::size_t) hit.card];
  418. if (card.kind == Card::add)
  419. {
  420. if (! refuseLocked (card))
  421. slotActions.showAddMenuFor (nextFreeRow());
  422. return;
  423. }
  424. select (hit.card);
  425. // round 190ld (DL-83): the clicked parameter is the selected one, which Delete returns to its default
  426. selectedKnobCard = hit.part == Part::knob ? hit.card : -1;
  427. selectedKnob = hit.part == Part::knob ? hit.knob : -1;
  428. if (hit.part != Part::title && hit.part != Part::folded && refuseLocked (card, hit.part == Part::knob ? hit.knob : -2))
  429. return;
  430. if (hit.part == Part::knob)
  431. {
  432. const auto spec = knobSpec (card, hit.knob);
  433. const auto value = knobValue (card, hit.knob);
  434. if (flmods::popup (e.mods))
  435. {
  436. ui::showValueMenu (*this, &engine, spec, value, [this, card, knob = hit.knob] (double v) { setKnob (card, knob, v); });
  437. return;
  438. }
  439. if (ui::isResetClick (e))
  440. {
  441. setKnob (card, hit.knob, spec.defaultValue);
  442. ui::flashValueTip (*this, knobBounds (card, hit.knob), spec.text (spec.defaultValue));
  443. return;
  444. }
  445. knobDrag = hit.knob;
  446. knobCard = hit.card;
  447. drag.begin (e, value);
  448. ui::showValueTip (*this, knobBounds (card, hit.knob), spec.text (value));
  449. return;
  450. }
  451. if (flmods::popup (e.mods))
  452. return showCardMenu (hit.card);
  453. if (hit.part == Part::led)
  454. return toggleOn (card);
  455. if (hit.part == Part::window)
  456. return toggleWindow (card);
  457. if (hit.part == Part::swap)
  458. return toggleSwap (targetOf (card));
  459. if (hit.part == Part::save)
  460. return savePreset (card.index);
  461. if (hit.part == Part::title && card.kind == Card::effect)
  462. dragCard = hit.card; // (a drag moves it; a click only selects; Ctrl + drag copies it)
  463. }
  464. void mouseDrag (const juce::MouseEvent& e) override
  465. {
  466. if (knobDrag >= 0 && knobCard >= 0 && knobCard < (int) cards.size())
  467. {
  468. const auto card = cards[(std::size_t) knobCard];
  469. const auto spec = knobSpec (card, knobDrag);
  470. const auto v = drag.update (e, spec);
  471. setKnob (card, knobDrag, v);
  472. ui::reportTweak (spec);
  473. ui::showValueTip (*this, knobBounds (card, knobDrag), spec.text (v));
  474. return;
  475. }
  476. // round 190dr: out of the chain, the card goes on as a drag-and-drop the clip grid takes (another track)
  477. if (dragCard >= 0 && dragCard < (int) cards.size() && cards[(std::size_t) dragCard].kind == Card::effect && insert >= 0
  478. && (e.y < 0 || e.y >= getHeight()))
  479. if (auto* container = juce::DragAndDropContainer::findParentDragContainerFor (this); container != nullptr && ! container->isDragAndDropActive())
  480. {
  481. const auto& card = cards[(std::size_t) dragCard];
  482. auto image = createComponentSnapshot (card.bounds.getIntersection (getLocalBounds()).withHeight (juce::jmin (card.bounds.getHeight(), 28)));
  483. container->startDragging (deviceDragDescription (insert, card.index), this, juce::ScaledImage (image), true);
  484. dragCard = -1;
  485. dragging = false;
  486. dropBefore = -1;
  487. repaint();
  488. return;
  489. }
  490. if (dragCard >= 0 && (dragging || e.getDistanceFromDragStart() > 4))
  491. {
  492. dragging = true;
  493. dropBefore = positionAt (e.x);
  494. repaint();
  495. }
  496. }
  497. void mouseUp (const juce::MouseEvent& e) override
  498. {
  499. if (knobDrag >= 0)
  500. {
  501. drag.end();
  502. ui::hideValueTip();
  503. knobDrag = knobCard = -1;
  504. return;
  505. }
  506. if (dragging && dragCard >= 0 && dragCard < (int) cards.size())
  507. {
  508. const auto from = cards[(std::size_t) dragCard].index;
  509. const auto to = effectPositionFor (positionAt (e.x));
  510. const auto tag = tagOf (from);
  511. if (e.mods.isCtrlDown()) // round 190ce: Ctrl + drag leaves the device where it was and drops a copy
  512. duplicateDevice (from, to);
  513. else
  514. {
  515. engine.editSongStructural ([t = insert, from, to] (Song& song) { detailchain::moveEffectBefore (song, t, from, to); });
  516. selectedTag = tag;
  517. }
  518. }
  519. dragCard = -1;
  520. dragging = false;
  521. dropBefore = -1;
  522. refresh();
  523. }
  524. void mouseDoubleClick (const juce::MouseEvent& e) override
  525. {
  526. const auto hit = hitAt (e.getPosition());
  527. if (hit.card < 0 || cards[(std::size_t) hit.card].kind == Card::add)
  528. return;
  529. const auto& card = cards[(std::size_t) hit.card];
  530. if (hit.part == Part::knob)
  531. {
  532. if (! refuseLocked (card, hit.knob))
  533. setKnob (card, hit.knob, knobSpec (card, hit.knob).defaultValue);
  534. return;
  535. }
  536. if (hit.part == Part::title || hit.part == Part::folded) // fold / unfold (the reference: double-click the title bar)
  537. toggleFold (keyOf (card));
  538. }
  539. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  540. {
  541. const auto hit = hitAt (e.getPosition());
  542. if (hit.part == Part::knob && ! cardLocked (cards[(std::size_t) hit.card], hit.knob))
  543. {
  544. const auto& card = cards[(std::size_t) hit.card];
  545. const auto spec = knobSpec (card, hit.knob);
  546. if (const auto v = ui::wheelValue (knobValue (card, hit.knob), e, wheel, spec))
  547. {
  548. setKnob (card, hit.knob, *v);
  549. ui::reportTweak (spec);
  550. ui::flashValueTip (*this, knobBounds (card, hit.knob), spec.text (*v));
  551. return;
  552. }
  553. }
  554. const auto delta = wheel.deltaX != 0.0f ? wheel.deltaX : wheel.deltaY;
  555. if (delta != 0.0f && contentWidth > chainArea().getWidth())
  556. {
  557. ui::noteWheelScroll();
  558. setScroll (scroll - juce::roundToInt (delta * 240.0f));
  559. }
  560. }
  561. void mouseMove (const juce::MouseEvent& e) override
  562. {
  563. const auto hit = hitAt (e.getPosition());
  564. if (hit.card != hover.card || hit.part != hover.part || hit.knob != hover.knob)
  565. {
  566. hover = hit;
  567. repaint();
  568. }
  569. }
  570. void mouseExit (const juce::MouseEvent&) override
  571. {
  572. hover = {};
  573. repaint();
  574. }
  575. bool keyPressed (const juce::KeyPress& key) override
  576. {
  577. const auto i = selectedCard();
  578. // Live (manual 17.1, details DL-83): "Delete returns the selected parameter to its default" — the knob clicked
  579. // last; with no parameter selected Delete removes the selected device as before
  580. if ((key.isKeyCode (juce::KeyPress::deleteKey) || key.isKeyCode (juce::KeyPress::backspaceKey)) && ! key.getModifiers().isAnyModifierKeyDown()
  581. && selectedKnobCard >= 0 && selectedKnobCard == i && selectedKnobCard < (int) cards.size() && selectedKnob >= 0)
  582. {
  583. const auto& card = cards[(std::size_t) selectedKnobCard];
  584. if (! cardLocked (card, selectedKnob))
  585. {
  586. const auto spec = knobSpec (card, selectedKnob);
  587. setKnob (card, selectedKnob, spec.defaultValue);
  588. ui::flashValueTip (*this, knobBounds (card, selectedKnob), spec.text (spec.defaultValue));
  589. }
  590. return true;
  591. }
  592. if ((key.isKeyCode (juce::KeyPress::deleteKey) || key.isKeyCode (juce::KeyPress::backspaceKey)) && i >= 0
  593. && cards[(std::size_t) i].kind == Card::effect)
  594. {
  595. slotActions.deleteSlot (cards[(std::size_t) i].index);
  596. refresh();
  597. return true;
  598. }
  599. // round 190ce: the reference's Edit commands on the selected device, and its Group / Ungroup keys
  600. if (key.getModifiers().isCommandDown() && ! key.getModifiers().isAltDown() && i >= 0 && cards[(std::size_t) i].kind == Card::effect)
  601. {
  602. const auto slot = cards[(std::size_t) i].index;
  603. const auto shift = key.getModifiers().isShiftDown();
  604. const auto code = juce::CharacterFunctions::toUpperCase ((juce::juce_wchar) key.getKeyCode());
  605. if (! shift && (code == 'C' || code == 'X'))
  606. {
  607. copyDevice (slot, code == 'X');
  608. return true;
  609. }
  610. if (! shift && code == 'D')
  611. {
  612. duplicateDevice (slot, -1);
  613. return true;
  614. }
  615. if (! shift && code == 'V')
  616. {
  617. pasteDevice (slot); // (round gap190og: in front of the selected device, Live's rule)
  618. return true;
  619. }
  620. if (code == 'G')
  621. {
  622. if (! shift)
  623. slotActions.groupIntoRack (slot, false);
  624. else
  625. ungroupDevice (slot);
  626. refresh();
  627. return true;
  628. }
  629. }
  630. // round 190hr (racks-061 / -062): Group and Ungroup on the instrument: an Instrument Rack holding it, and back
  631. if (key.getModifiers().isCommandDown() && ! key.getModifiers().isAltDown() && i >= 0 && cards[(std::size_t) i].kind == Card::instrument
  632. && juce::CharacterFunctions::toUpperCase ((juce::juce_wchar) key.getKeyCode()) == 'G')
  633. {
  634. if (key.getModifiers().isShiftDown())
  635. ungroupInstrument (cards[(std::size_t) i].index);
  636. else
  637. groupInstrument (cards[(std::size_t) i].index);
  638. return true;
  639. }
  640. if (key.getModifiers().isCommandDown() && ! key.getModifiers().isAltDown() && ! key.getModifiers().isShiftDown()
  641. && juce::CharacterFunctions::toUpperCase ((juce::juce_wchar) key.getKeyCode()) == 'V' && insert >= 0 && deviceClipboard().has_value())
  642. {
  643. pasteDevice (effectCount()); // (nothing selected, or the instrument: at the end of the chain)
  644. return true;
  645. }
  646. // the reference's 0 key: the selected device on / off (the typing keyboard keeps the key while it is on)
  647. if (! key.getModifiers().isAnyModifierKeyDown() && (key.getKeyCode() == '0' || key.getTextCharacter() == '0')
  648. && (hooks.typingKeyboardOn == nullptr || ! hooks.typingKeyboardOn()) && toggleSelectedOn())
  649. return true;
  650. if (key.isKeyCode (juce::KeyPress::leftKey) || key.isKeyCode (juce::KeyPress::rightKey))
  651. {
  652. const auto step = key.isKeyCode (juce::KeyPress::leftKey) ? -1 : 1;
  653. const auto last = (int) cards.size() - (cards.empty() || cards.back().kind != Card::add ? 1 : 2);
  654. if (last >= 0)
  655. select (juce::jlimit (0, last, (i < 0 ? 0 : i + step)));
  656. return true;
  657. }
  658. // LYNX extra (off by default): W shows or hides the selected card's window
  659. if (DetailView::extraWindowKey && ! key.getModifiers().isAnyModifierKeyDown() && i >= 0
  660. && (key.getKeyCode() == 'W' || juce::CharacterFunctions::toUpperCase (key.getTextCharacter()) == 'W'))
  661. {
  662. toggleWindow (cards[(std::size_t) i]);
  663. return true;
  664. }
  665. return false;
  666. }
  667. // round 190ef: every device knob is mappable (MIDI / Key Map Mode)
  668. void mapSpots (std::vector<mapmode::Spot>& out) override
  669. {
  670. for (const auto& c : cards)
  671. if (c.kind != Card::add && c.custom == nullptr)
  672. for (int k = 0; k < (int) c.knobs.size(); ++k)
  673. if (const auto r = knobBounds (c, k); ! r.isEmpty())
  674. if (const auto target = knobSpec (c, k).target)
  675. out.push_back ({ r, remotemap::Target::parameter (*target) });
  676. }
  677. // --- hints ---------------------------------------------------------------------------------------------------
  678. ui::Hint hintAt (juce::Point<int> p) override
  679. {
  680. const auto hit = hitAt (p);
  681. if (hit.part == Part::picker)
  682. return { tr ("The insert this track plays through: click to pick another of its inserts"), insertName (engine.getSong(), insert), false, true };
  683. if (hit.card < 0)
  684. return {};
  685. const auto& card = cards[(std::size_t) hit.card];
  686. switch (hit.part)
  687. {
  688. case Part::knob:
  689. {
  690. const auto spec = knobSpec (card, hit.knob);
  691. return { spec.name, spec.text (knobValue (card, hit.knob)), spec.target.has_value(), true };
  692. }
  693. case Part::led: return { card.kind == Card::instrument ? tr ("Channel on / off (its mute)") : tr ("Effect on / off (bypass)"), {}, false, false };
  694. case Part::window: return { tr ("Show or hide the window"), {}, false, false };
  695. case Part::swap: return { tr ("Hot-swap: link the Browser to this device; what you load there takes its place (Q, again to end)"), cardName (card), false, false };
  696. case Part::save: return { tr ("Save the device's settings as a preset"), cardName (card), false, false };
  697. case Part::title:
  698. case Part::folded:
  699. return { tr ("Click: select. Double-click: fold / unfold. Drag: move it in the chain (Ctrl + drag: copy). Right-click: its menu"), cardName (card), false, true };
  700. default: break;
  701. }
  702. if (card.kind == Card::add)
  703. return { tr ("Add an effect to this insert (or drop one from the Browser)"), {}, false, true };
  704. return { {}, cardName (card), false, false };
  705. }
  706. // --- drops from the Browser ----------------------------------------------------------------------------------
  707. bool isInterestedInDragSource (const SourceDetails& details) override
  708. {
  709. int from = -1, slot = -1;
  710. return insert >= 0
  711. && ((BrowserComponent::isBrowserDrag (details) && BrowserComponent::draggedFile (details).hasFileExtension ("fst;adv;adg"))
  712. || BrowserComponent::isEffectDrag (details) || BrowserComponent::isGeneratorDrag (details)
  713. || (detailDeviceDrag (details.description, from, slot) && from == insert)); // (round 190dr: back into its own chain)
  714. }
  715. void itemDragMove (const SourceDetails& details) override
  716. {
  717. const auto at = BrowserComponent::isGeneratorDrag (details) ? -1 : positionAt (details.localPosition.x);
  718. if (at != dropBefore)
  719. {
  720. dropBefore = at;
  721. repaint();
  722. }
  723. }
  724. void itemDragExit (const SourceDetails&) override
  725. {
  726. dropBefore = -1;
  727. repaint();
  728. }
  729. void itemDropped (const SourceDetails& details) override
  730. {
  731. const auto position = effectPositionFor (positionAt (details.localPosition.x));
  732. dropBefore = -1;
  733. repaint();
  734. if (freeze::frozenByInsert (engine.getSong(), insert) >= 0) // (round 190ff: a frozen track's devices stay as they are)
  735. {
  736. ui::postNotice ({ tr ("This track is frozen: Unfreeze the track to edit its devices"), {} }, 3000);
  737. return;
  738. }
  739. // round 190dr: a card that left the chain and came back: a move inside the chain (Ctrl: a copy), as a plain drag
  740. if (int from = -1, slot = -1; detailDeviceDrag (details.description, from, slot))
  741. {
  742. if (from != insert)
  743. return;
  744. if (juce::ModifierKeys::currentModifiers.isCommandDown())
  745. duplicateDevice (slot, position);
  746. else
  747. {
  748. const auto tag = tagOf (slot);
  749. engine.editSongStructural ([t = insert, slot, position] (Song& song) { detailchain::moveEffectBefore (song, t, slot, position); });
  750. selectedTag = tag;
  751. }
  752. refresh();
  753. return;
  754. }
  755. if (BrowserComponent::isGeneratorDrag (details))
  756. {
  757. auto c = BrowserComponent::draggedGenerator (details);
  758. if (! c)
  759. return;
  760. // issue #152 point 6 (Live: an instrument dropped onto the track's instrument in the Device View replaces
  761. // only it; its effects stay): the instrument card under the mouse takes the plugin
  762. if (const auto hit = hitAt (details.localPosition); juce::isPositiveAndBelow (hit.card, (int) cards.size())
  763. && cards[(std::size_t) hit.card].kind == Card::instrument)
  764. {
  765. const auto channel = cards[(std::size_t) hit.card].index;
  766. if (c->instrument != InstrumentKind::audioClip && c->instrument != InstrumentKind::controller)
  767. {
  768. engine.editSong ([channel, gen = std::move (*c)] (Song& song) mutable { replaceGenerator (song, channel, std::move (gen)); });
  769. refresh();
  770. }
  771. return;
  772. }
  773. if (hooks.instrumentDropped != nullptr)
  774. hooks.instrumentDropped (insert, std::move (*c));
  775. return;
  776. }
  777. std::optional<EffectSlot> fx;
  778. if (BrowserComponent::isEffectDrag (details))
  779. fx = BrowserComponent::draggedEffect (details);
  780. else if (const auto file = BrowserComponent::draggedFile (details); RackWindows::isLivePreset (file))
  781. {
  782. // round 190hr: Live's device / rack presets — an effect into the chain; an instrument (an .adv instrument, an
  783. // Instrument or Drum Rack) onto the instrument card replaces it, elsewhere it makes a channel, as a dropped plugin
  784. juce::MemoryBlock data;
  785. if (file.loadFileAsData (data))
  786. {
  787. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  788. if (auto live = importLiveDevicePreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize())))
  789. fx = std::move (live->slot);
  790. }
  791. if (! fx)
  792. {
  793. juce::String error;
  794. auto c = RackWindows::instrumentFromLivePreset (file, error);
  795. if (! c)
  796. return ui::postHint ({ error, {} }, 3000);
  797. if (const auto hit = hitAt (details.localPosition); juce::isPositiveAndBelow (hit.card, (int) cards.size())
  798. && cards[(std::size_t) hit.card].kind == Card::instrument)
  799. {
  800. engine.editSong ([channel = cards[(std::size_t) hit.card].index, gen = std::move (*c)] (Song& song) mutable { replaceGenerator (song, channel, std::move (gen)); });
  801. refresh();
  802. }
  803. else if (hooks.instrumentDropped != nullptr)
  804. hooks.instrumentDropped (insert, std::move (*c));
  805. return;
  806. }
  807. }
  808. else
  809. {
  810. juce::MemoryBlock data;
  811. if (BrowserComponent::draggedFile (details).loadFileAsData (data))
  812. {
  813. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  814. fx = effectFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), engine.getSong().bpm,
  815. natives::flDataReader (flStudioAccess()));
  816. }
  817. if (! fx)
  818. {
  819. ui::postHint ({ tr ("LYNX SHARE can't build an effect from this preset."), {} }, 3000);
  820. return;
  821. }
  822. }
  823. if (! fx)
  824. return;
  825. dropEffect (std::move (*fx), position);
  826. }
  827. private:
  828. struct Card
  829. {
  830. enum Kind { instrument, effect, add } kind = effect;
  831. int index = -1; // effect: its slot index; instrument: the channel
  832. std::uint64_t tag = 0; // effect: the slot's instance (fold and selection follow it through moves)
  833. bool folded = false;
  834. juce::Rectangle<int> bounds; // in this component (scroll applied)
  835. std::vector<int> knobs; // effect: parameter ids (-1 = Mix); instrument: 0 volume, 1 pan
  836. DetailCard* custom = nullptr; // a body drawn by another module (DetailView::*CardFactory)
  837. };
  838. struct CustomEntry
  839. {
  840. int kind = -1; // the slot's EffectKind / the channel's InstrumentKind it was made for
  841. std::unique_ptr<DetailCard> card;
  842. };
  843. enum class Part { none, picker, title, led, window, swap, save, knob, body, folded };
  844. int selectedKnobCard = -1, selectedKnob = -1; // round 190ld (DL-83): the parameter Delete resets
  845. struct Hit
  846. {
  847. Part part = Part::none;
  848. int card = -1, knob = -1;
  849. };
  850. // --- the model -----------------------------------------------------------------------------------------------
  851. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  852. void refresh()
  853. {
  854. const auto& song = engine.getSong();
  855. const auto c = detailchain::forTrack (song, track);
  856. auto wanted = c.insert;
  857. if (chosenInsert >= 0 && chosenInsert < (int) song.mixer.size()
  858. && (chosenInsert == c.insert || std::find (c.inserts.begin(), c.inserts.end(), chosenInsert) != c.inserts.end()))
  859. wanted = chosenInsert;
  860. if (wanted < 0 && ! c.inserts.empty())
  861. wanted = c.inserts.front(); // several inserts: the first until one is picked
  862. inserts = c.inserts;
  863. if (c.insert >= 0 && std::find (inserts.begin(), inserts.end(), c.insert) == inserts.end())
  864. inserts.insert (std::lower_bound (inserts.begin(), inserts.end(), c.insert), c.insert);
  865. insert = wanted;
  866. channel = c.channel >= 0 && detailchain::insertOfChannel (song, c.channel) == insert ? c.channel
  867. : c.channel >= 0 && c.fromTrackMode ? c.channel
  868. : -1;
  869. if (insert >= 0 && insert != actionsInsert)
  870. {
  871. slotActions.setTrack (insert);
  872. actionsInsert = insert;
  873. }
  874. layoutCards();
  875. repaint();
  876. }
  877. int effectCount() const
  878. {
  879. const auto& song = engine.getSong();
  880. return insert >= 0 && insert < (int) song.mixer.size() ? (int) song.mixer[(std::size_t) insert].effects.size() : 0;
  881. }
  882. const EffectSlot* effectAt (int index) const
  883. {
  884. const auto& song = engine.getSong();
  885. if (insert < 0 || insert >= (int) song.mixer.size() || index < 0 || index >= (int) song.mixer[(std::size_t) insert].effects.size())
  886. return nullptr;
  887. return &song.mixer[(std::size_t) insert].effects[(std::size_t) index];
  888. }
  889. std::uint64_t tagOf (int index) const
  890. {
  891. const auto* fx = effectAt (index);
  892. return fx != nullptr ? fx->instance.id : 0;
  893. }
  894. // fold keys: an effect by its slot instance, the instrument by its channel (high bit set)
  895. std::uint64_t keyOf (const Card& c) const noexcept
  896. {
  897. return c.kind == Card::instrument ? (std::uint64_t (1) << 63) | (std::uint64_t) c.index : c.tag;
  898. }
  899. void toggleFold (std::uint64_t key)
  900. {
  901. if (folded.erase (key) == 0)
  902. folded.insert (key);
  903. layoutCards();
  904. repaint();
  905. }
  906. // Freeze (round 190ff): a frozen track's devices are not loaded and cannot be edited, as in the reference (its frozen
  907. // devices are greyed out). The instrument card of a frozen channel (its body; with a track freeze its volume and pan
  908. // too) and every card of an insert whose effects a track freeze holds.
  909. bool cardLocked (const Card& c, int knob = -2) const
  910. {
  911. const auto& song = engine.getSong();
  912. if (c.kind == Card::instrument)
  913. {
  914. if (c.index < 0 || c.index >= (int) song.channels.size() || ! song.channels[(std::size_t) c.index].freeze.on())
  915. return false;
  916. const auto levelsLive = song.channels[(std::size_t) c.index].freeze.insert == 0; // (a channel freeze: they apply live)
  917. return ! (levelsLive && knob >= 0);
  918. }
  919. return freeze::frozenByInsert (song, insert) >= 0;
  920. }
  921. bool refuseLocked (const Card& c, int knob = -2)
  922. {
  923. if (! cardLocked (c, knob))
  924. return false;
  925. ui::postNotice ({ tr ("This track is frozen: Unfreeze the track to edit its devices"), {} }, 3000);
  926. return true;
  927. }
  928. void layoutCards()
  929. {
  930. cards.clear();
  931. const auto area = chainArea();
  932. auto x = area.getX() - scroll;
  933. const auto top = area.getY(), height = area.getHeight();
  934. if (channel >= 0)
  935. {
  936. Card c;
  937. c.kind = Card::instrument;
  938. c.index = channel;
  939. c.folded = folded.count (keyOf (c)) > 0;
  940. c.knobs = { 0, 1 };
  941. for (const auto p : engineCardParams (engine.getSong().channels[(std::size_t) channel].instrument))
  942. c.knobs.push_back (engineKnobBase + p);
  943. c.custom = customFor (keyOf (c), (int) engine.getSong().channels[(std::size_t) channel].instrument, [&] {
  944. return DetailView::instrumentCardFactory != nullptr
  945. ? DetailView::instrumentCardFactory (engine, channel, engine.getSong().channels[(std::size_t) channel])
  946. : nullptr;
  947. });
  948. if (c.custom != nullptr)
  949. c.knobs.clear();
  950. const auto w = c.folded ? foldedWidth
  951. : c.custom != nullptr ? customWidth (*c.custom, height, x)
  952. : c.knobs.size() > 2u ? std::max (instrumentWidth, 16 + (((int) c.knobs.size() + 1) / 2) * knobColumn)
  953. : instrumentWidth;
  954. c.bounds = { x, top, w, height };
  955. x += w + cardGap();
  956. cards.push_back (std::move (c));
  957. }
  958. for (int i = 0; i < effectCount(); ++i)
  959. {
  960. const auto& fx = *effectAt (i);
  961. Card c;
  962. c.kind = Card::effect;
  963. c.index = i;
  964. c.tag = fx.instance.id;
  965. c.folded = folded.count (c.tag) > 0;
  966. const auto& info = effectInfo (fx.kind);
  967. if (fx.kind != EffectKind::plugin)
  968. for (int p = 0; p < std::min (maxEffectKnobs, (int) info.params.size()); ++p)
  969. c.knobs.push_back (p);
  970. c.knobs.push_back (-1); // the slot's Mix
  971. c.custom = customFor (c.tag, (int) fx.kind, [&] {
  972. return DetailView::effectCardFactory != nullptr ? DetailView::effectCardFactory (engine, insert, i, fx) : nullptr;
  973. });
  974. if (c.custom != nullptr)
  975. c.knobs.clear();
  976. const auto columns = ((int) c.knobs.size() + 1) / 2;
  977. const auto w = c.folded ? foldedWidth
  978. : c.custom != nullptr ? customWidth (*c.custom, height, x)
  979. : fx.kind == EffectKind::plugin ? pluginWidth
  980. : std::max (136, 16 + columns * knobColumn);
  981. c.bounds = { x, top, w, height };
  982. x += w + cardGap();
  983. cards.push_back (std::move (c));
  984. }
  985. if (insert >= 0 && effectCount() < maxEffectSlots)
  986. {
  987. Card c;
  988. c.kind = Card::add;
  989. c.bounds = { x, top, addWidth, height };
  990. x += addWidth + cardGap();
  991. cards.push_back (std::move (c));
  992. }
  993. placeCustomCards();
  994. for (const auto& c : cards) // (round 190ff: a frozen device's own body takes no clicks)
  995. if (c.custom != nullptr)
  996. c.custom->setEnabled (! cardLocked (c));
  997. contentWidth = x + scroll - area.getX();
  998. const auto overflow = contentWidth > area.getWidth();
  999. scrollBar.setVisible (overflow);
  1000. scrollBar.setRangeLimits (0.0, (double) std::max (contentWidth, area.getWidth()), juce::dontSendNotification);
  1001. scrollBar.setCurrentRange ((double) scroll, (double) area.getWidth(), juce::dontSendNotification);
  1002. if (! overflow && scroll != 0)
  1003. {
  1004. scroll = 0;
  1005. layoutCards();
  1006. }
  1007. }
  1008. // the custom card of `key`, made once (again when the slot's kind changes); nullptr = an ordinary card
  1009. DetailCard* customFor (std::uint64_t key, int kind, const std::function<std::unique_ptr<DetailCard>()>& make)
  1010. {
  1011. if (DetailView::effectCardFactory == nullptr && DetailView::instrumentCardFactory == nullptr)
  1012. return nullptr;
  1013. auto& entry = customs[key];
  1014. if (entry.kind != kind)
  1015. {
  1016. entry.kind = kind;
  1017. if (entry.card != nullptr)
  1018. cardHost.removeChildComponent (entry.card.get());
  1019. entry.card = make();
  1020. if (entry.card != nullptr)
  1021. {
  1022. cardHost.addChildComponent (*entry.card);
  1023. entry.card->onPreferredWidthChanged = [this] {
  1024. layoutCards();
  1025. repaint();
  1026. };
  1027. if (auto* extra = entry.card->titleAccessory())
  1028. cardHost.addChildComponent (*extra);
  1029. }
  1030. }
  1031. return entry.card.get();
  1032. }
  1033. int customWidth (DetailCard& card, int height, int x) const
  1034. {
  1035. // (x: the card's left with the scroll applied; the room is measured with the chain at its start, so the width
  1036. // doesn't change while it scrolls)
  1037. const auto area = chainArea();
  1038. card.widthLimit = std::max (area.getWidth() / 2, area.getRight() - (x + scroll) - cardGap());
  1039. return std::max (foldedWidth * 2, card.preferredWidth (height - titleHeight - 6));
  1040. }
  1041. void placeCustomCards()
  1042. {
  1043. std::set<DetailCard*> shown;
  1044. const auto origin = chainArea().getPosition();
  1045. for (const auto& c : cards)
  1046. if (c.custom != nullptr)
  1047. {
  1048. shown.insert (c.custom);
  1049. const auto besideTitle = c.custom->titleBarWidth() > 0; // (round 190nc: Live's inline chain devices)
  1050. c.custom->setBounds ((besideTitle ? c.bounds : c.bounds.withTrimmedTop (titleHeight + 2)).reduced (2, 0).withTrimmedBottom (2) - origin);
  1051. c.custom->setVisible (! c.folded);
  1052. if (auto* extra = c.custom->titleAccessory())
  1053. {
  1054. const auto w = c.custom->titleAccessoryWidth();
  1055. extra->setBounds (juce::Rectangle<int> (barRight (c) - 4 - titleButtonsWidth (c) - w, c.bounds.getY() + 2, w, titleHeight - 4) - origin);
  1056. extra->setVisible (! c.folded);
  1057. }
  1058. }
  1059. for (auto it = customs.begin(); it != customs.end();) // (slots gone: their cards go too)
  1060. {
  1061. if (it->second.card != nullptr && shown.count (it->second.card.get()) == 0)
  1062. {
  1063. if (auto* extra = it->second.card->titleAccessory())
  1064. cardHost.removeChildComponent (extra);
  1065. cardHost.removeChildComponent (it->second.card.get());
  1066. it = customs.erase (it);
  1067. }
  1068. else
  1069. ++it;
  1070. }
  1071. }
  1072. juce::Rectangle<int> chainArea() const
  1073. {
  1074. return { contextWidth, 2, std::max (0, getWidth() - contextWidth - meterWidth - 4), std::max (0, getHeight() - 12) };
  1075. }
  1076. void setScroll (int s)
  1077. {
  1078. scroll = juce::jlimit (0, std::max (0, contentWidth - chainArea().getWidth()), s);
  1079. layoutCards();
  1080. repaint();
  1081. }
  1082. void scrollBarMoved (juce::ScrollBar*, double start) override { setScroll ((int) start); }
  1083. // where a drop or a dragged card goes: before card `position` (cards.size() or the "+" card = after the last)
  1084. int positionAt (int x) const
  1085. {
  1086. for (int i = 0; i < (int) cards.size(); ++i)
  1087. if (x < cards[(std::size_t) i].bounds.getCentreX())
  1088. return cards[(std::size_t) i].kind == Card::instrument ? i + 1 : i; // (nothing goes before the instrument)
  1089. return (int) cards.size();
  1090. }
  1091. int dropLineX (int position) const
  1092. {
  1093. if (position >= 0 && position < (int) cards.size())
  1094. return cards[(std::size_t) position].bounds.getX() - cardGap() / 2;
  1095. return cards.empty() ? chainArea().getX() : cards.back().bounds.getRight() + cardGap() / 2;
  1096. }
  1097. // a card position as a place in the effect chain (0 = the first effect)
  1098. int effectPositionFor (int position) const
  1099. {
  1100. int effects = 0;
  1101. for (int i = 0; i < std::min (position, (int) cards.size()); ++i)
  1102. effects += cards[(std::size_t) i].kind == Card::effect ? 1 : 0;
  1103. return effects;
  1104. }
  1105. int nextFreeRow() const
  1106. {
  1107. const auto& song = engine.getSong();
  1108. if (insert < 0 || insert >= (int) song.mixer.size())
  1109. return 0;
  1110. const auto& fx = song.mixer[(std::size_t) insert].effects;
  1111. const auto rows = mixerops::effectRows (fx);
  1112. for (int r = rows.empty() ? 0 : rows.back() + 1; r < maxEffectSlots; ++r)
  1113. if (mixerops::effectAtRow (fx, r) < 0)
  1114. return r;
  1115. for (int r = 0; r < maxEffectSlots; ++r)
  1116. if (mixerops::effectAtRow (fx, r) < 0)
  1117. return r;
  1118. return 0;
  1119. }
  1120. void dropEffect (EffectSlot fx, int position)
  1121. {
  1122. if (effectCount() >= maxEffectSlots)
  1123. {
  1124. ui::postHint ({ tr ("This insert has no free slot ({0} effects)", { juce::String (maxEffectSlots) }), {} }, 3000);
  1125. return;
  1126. }
  1127. int added = -1;
  1128. engine.editSong ([t = insert, position, &added, fx = std::move (fx)] (Song& song) mutable {
  1129. added = detailchain::insertEffectAt (song, t, std::move (fx), position);
  1130. if (added >= 0)
  1131. mixerops::linkAddedSidechain (song, t, added); // (as the Mixer's add: a sole sidechain sender feeds it)
  1132. });
  1133. if (added >= 0)
  1134. {
  1135. selectedTag = tagOf (added);
  1136. refresh();
  1137. if (const auto* fx2 = effectAt (added); fx2 != nullptr && fx2->kind == EffectKind::plugin)
  1138. slotActions.toggleSlotEditor (added); // (a plugin opens its window when added, as in the Mixer)
  1139. }
  1140. }
  1141. // --- selection and actions -----------------------------------------------------------------------------------
  1142. int selectedCard() const
  1143. {
  1144. for (int i = 0; i < (int) cards.size(); ++i)
  1145. if ((instrumentSelected && cards[(std::size_t) i].kind == Card::instrument)
  1146. || (! instrumentSelected && selectedTag != 0 && cards[(std::size_t) i].tag == selectedTag))
  1147. return i;
  1148. return -1;
  1149. }
  1150. void select (int i)
  1151. {
  1152. if (i < 0 || i >= (int) cards.size() || cards[(std::size_t) i].kind == Card::add)
  1153. return;
  1154. const auto& c = cards[(std::size_t) i];
  1155. instrumentSelected = c.kind == Card::instrument;
  1156. selectedTag = c.tag;
  1157. if (c.kind == Card::effect)
  1158. slotActions.selectSlot (c.index);
  1159. if (DetailView::extraSelectInMixer && hooks.selectInMixer != nullptr && insert >= 0)
  1160. hooks.selectInMixer (insert);
  1161. repaint();
  1162. }
  1163. void toggleOn (const Card& c)
  1164. {
  1165. if (c.kind == Card::instrument)
  1166. engine.editSong ([ch = c.index] (Song& song) {
  1167. if (ch >= 0 && ch < (int) song.channels.size())
  1168. song.channels[(std::size_t) ch].muted = ! song.channels[(std::size_t) ch].muted;
  1169. });
  1170. else
  1171. engine.editSong ([t = insert, i = c.index] (Song& song) { // (the Mixer LED's edit)
  1172. if (t >= 0 && t < (int) song.mixer.size() && i >= 0 && i < (int) song.mixer[(std::size_t) t].effects.size())
  1173. song.mixer[(std::size_t) t].effects[(std::size_t) i].enabled = ! song.mixer[(std::size_t) t].effects[(std::size_t) i].enabled;
  1174. });
  1175. }
  1176. void toggleWindow (const Card& c)
  1177. {
  1178. if (c.kind == Card::instrument)
  1179. {
  1180. if (hooks.toggleChannelWindow != nullptr)
  1181. hooks.toggleChannelWindow (c.index);
  1182. }
  1183. else if (c.kind == Card::effect)
  1184. slotActions.toggleSlotEditor (c.index);
  1185. }
  1186. void showCardMenu (int i)
  1187. {
  1188. const auto& c = cards[(std::size_t) i];
  1189. if (c.kind == Card::effect)
  1190. {
  1191. slotActions.showSlotMenuFor (c.index);
  1192. return;
  1193. }
  1194. juce::PopupMenu menu;
  1195. const auto key = keyOf (c);
  1196. menu.addItem (folded.count (key) > 0 ? tr ("Unfold") : tr ("Fold"), [this, key] { toggleFold (key); });
  1197. menu.addItem (tr ("Hot-swap in the Browser") + "\tQ", hooks.toggleHotSwap != nullptr, linkedTo (targetOf (c)), [this, c] { toggleSwap (targetOf (c)); });
  1198. menu.addItem (tr ("Show or hide the window"), [this, c] { toggleWindow (c); });
  1199. if (c.kind == Card::instrument) // round 190hr: Live's Group / Ungroup on the instrument, and a rack's Save Preset
  1200. {
  1201. const auto& song = engine.getSong();
  1202. menu.addSeparator();
  1203. menu.addItem (tr ("Group") + "\tCtrl+G", rack::canGroupChannel (song, c.index), false, [this, ch = c.index] { groupInstrument (ch); });
  1204. menu.addItem (tr ("Ungroup") + "\tCtrl+Shift+G", rack::canUngroupChannel (song, c.index), false, [this, ch = c.index] { ungroupInstrument (ch); });
  1205. if (c.index >= 0 && c.index < (int) song.channels.size() && rack::isRack (song.channels[(std::size_t) c.index]))
  1206. menu.addItem (tr ("Save as Live rack preset (.adg)..."), [this, ch = c.index] { saveRackPreset (ch, -1); });
  1207. }
  1208. if (EffectsPanel::slotMenuForSnapshot != nullptr) // (shots: the menu as built)
  1209. {
  1210. *EffectsPanel::slotMenuForSnapshot = menu;
  1211. return;
  1212. }
  1213. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  1214. }
  1215. // --- round 190ce: hot-swap, presets, copies ------------------------------------------------------------------------
  1216. hotswap::Target targetOf (const Card& c) const
  1217. {
  1218. const auto& song = engine.getSong();
  1219. return c.kind == Card::instrument ? hotswap::targetOfChannel (song, c.index)
  1220. : c.kind == Card::effect ? hotswap::targetOfEffect (song, insert, c.index)
  1221. : hotswap::Target();
  1222. }
  1223. bool linkedTo (const hotswap::Target& t) const { return t.active() && hooks.hotSwapTarget != nullptr && hooks.hotSwapTarget() == t; }
  1224. bool linkedTo (hotswap::Kind kind, std::uint64_t instance) const { return linkedTo (hotswap::Target { kind, instance }); }
  1225. void toggleSwap (const hotswap::Target& t)
  1226. {
  1227. if (t.active() && hooks.toggleHotSwap != nullptr)
  1228. hooks.toggleHotSwap (t);
  1229. repaint();
  1230. }
  1231. // LYNX's own effects save their settings as presets (ui/PluginHeader.h); a plugin saves in its own window, a rack
  1232. // or a Patcher in its editor.
  1233. bool canSavePreset (int slot) const
  1234. {
  1235. const auto* fx = effectAt (slot);
  1236. if (fx != nullptr && rack::isRack (*fx)) // (round 190hr: a rack saves as Live's rack preset, .adg)
  1237. return true;
  1238. return fx != nullptr && fx->kind != EffectKind::plugin && fx->kind != EffectKind::patcher && pluginheader::PresetBar (engine, insert, slot).hasLynxPresets();
  1239. }
  1240. void savePreset (int slot)
  1241. {
  1242. if (! canSavePreset (slot))
  1243. return;
  1244. if (const auto* fx = effectAt (slot); fx != nullptr && rack::isRack (*fx))
  1245. return saveRackPreset (-1, slot);
  1246. presetBar = std::make_unique<pluginheader::PresetBar> (engine, insert, slot);
  1247. presetBar->savePreset (*this);
  1248. }
  1249. static std::optional<EffectSlot>& deviceClipboard()
  1250. {
  1251. static std::optional<EffectSlot> clip; // (one for every Device View of the session)
  1252. return clip;
  1253. }
  1254. void copyDevice (int slot, bool cut)
  1255. {
  1256. engine.capturePluginStates(); // (a plugin's current settings go with the copy)
  1257. const auto* fx = effectAt (slot);
  1258. if (fx == nullptr)
  1259. return;
  1260. deviceClipboard() = *fx;
  1261. if (cut)
  1262. {
  1263. slotActions.deleteSlot (slot);
  1264. refresh();
  1265. }
  1266. }
  1267. void pasteDevice (int position)
  1268. {
  1269. if (! deviceClipboard().has_value() || insert < 0)
  1270. return;
  1271. if (effectCount() >= maxEffectSlots)
  1272. {
  1273. ui::postHint ({ tr ("This insert has no free slot ({0} effects)", { juce::String (maxEffectSlots) }), {} }, 3000);
  1274. return;
  1275. }
  1276. int added = -1;
  1277. engine.editSong ([t = insert, position, &added, fx = *deviceClipboard()] (Song& song) mutable { added = detailchain::pasteEffect (song, t, std::move (fx), position); });
  1278. if (added >= 0)
  1279. {
  1280. selectedTag = tagOf (added);
  1281. instrumentSelected = false;
  1282. }
  1283. refresh();
  1284. }
  1285. void duplicateDevice (int slot, int position)
  1286. {
  1287. if (effectCount() >= maxEffectSlots)
  1288. {
  1289. ui::postHint ({ tr ("This insert has no free slot ({0} effects)", { juce::String (maxEffectSlots) }), {} }, 3000);
  1290. return;
  1291. }
  1292. engine.capturePluginStates();
  1293. int added = -1;
  1294. engine.editSong ([t = insert, slot, position, &added] (Song& song) { added = detailchain::duplicateEffect (song, t, slot, position); });
  1295. if (added >= 0)
  1296. {
  1297. selectedTag = tagOf (added);
  1298. instrumentSelected = false;
  1299. }
  1300. refresh();
  1301. }
  1302. // round 190hr: Group (Ctrl+G) on the instrument card: the channel's instrument into an Instrument Rack (Live's
  1303. // Group on an instrument [STR "Group"; Live 12 manual]); its automated plugin parameters become macros at their values
  1304. void groupInstrument (int channel)
  1305. {
  1306. const auto& song = engine.getSong();
  1307. if (! rack::canGroupChannel (song, channel))
  1308. return;
  1309. if (channel >= 0 && channel < (int) song.channels.size() && song.channels[(std::size_t) channel].freeze.on())
  1310. return (void) refuseLocked (Card { Card::instrument, channel });
  1311. engine.capturePluginStates();
  1312. // the plugin's parameters the song automates or links: their values now (read before the edit)
  1313. std::map<int, float> values;
  1314. auto probe = song;
  1315. probe.forEachTarget ([&] (AutomationTarget& t) {
  1316. if (t.kind == AutomationTargetKind::channelParam && t.index == channel && values.count (t.param) == 0)
  1317. values[t.param] = engine.currentTargetValue (t);
  1318. });
  1319. auto value = [values] (int, int param) {
  1320. const auto it = values.find (param);
  1321. return it != values.end() ? it->second : -1.0f;
  1322. };
  1323. auto trial = song;
  1324. if (! rack::groupChannel (trial, channel, value))
  1325. {
  1326. ui::postNotice ({ tr ("This instrument can't go into a rack (more than 16 automated parameters, or their values are unknown)"), {} }, 3000);
  1327. return;
  1328. }
  1329. engine.editSong ([channel, value] (Song& s) { rack::groupChannel (s, channel, value); });
  1330. refresh();
  1331. }
  1332. void ungroupInstrument (int channel)
  1333. {
  1334. if (! rack::canUngroupChannel (engine.getSong(), channel))
  1335. return;
  1336. engine.capturePluginStates();
  1337. engine.editSong ([channel] (Song& s) { rack::ungroupChannel (s, channel); });
  1338. refresh();
  1339. }
  1340. // round 190hr: a rack's Save Preset (Live's .adg): channel `channel`'s Instrument Rack, or effect slot `slot`'s rack
  1341. void saveRackPreset (int channel, int slot)
  1342. {
  1343. const auto& song = engine.getSong();
  1344. juce::String name;
  1345. RackLocator locate;
  1346. if (slot >= 0)
  1347. {
  1348. const auto* fx = effectAt (slot);
  1349. if (fx == nullptr || ! rack::isRack (*fx))
  1350. return;
  1351. name = utf8 (rack::rackOf (fx->patcher)->name);
  1352. locate = [t = insert, slot] (Song& s) -> PatcherDoc* {
  1353. if (t < 0 || t >= (int) s.mixer.size() || slot >= (int) s.mixer[(std::size_t) t].effects.size())
  1354. return nullptr;
  1355. auto& x = s.mixer[(std::size_t) t].effects[(std::size_t) slot];
  1356. return rack::isRack (x) ? &x.patcher : nullptr;
  1357. };
  1358. }
  1359. else
  1360. {
  1361. if (channel < 0 || channel >= (int) song.channels.size() || ! rack::isRack (song.channels[(std::size_t) channel]))
  1362. return;
  1363. const auto& ch = song.channels[(std::size_t) channel];
  1364. name = utf8 (! rack::rackOf (ch.patcher)->name.empty() ? rack::rackOf (ch.patcher)->name : ch.name);
  1365. locate = [channel] (Song& s) -> PatcherDoc* {
  1366. if (channel >= (int) s.channels.size() || ! rack::isRack (s.channels[(std::size_t) channel]))
  1367. return nullptr;
  1368. return &s.channels[(std::size_t) channel].patcher;
  1369. };
  1370. }
  1371. RackWindows::saveLivePreset (engine, std::move (locate), name);
  1372. }
  1373. void ungroupDevice (int slot)
  1374. {
  1375. const auto* fx = effectAt (slot);
  1376. if (fx == nullptr || ! rack::isRack (*fx))
  1377. return;
  1378. const auto* r = rack::rackOf (fx->patcher);
  1379. if (r == nullptr || r->kind != RackDoc::Kind::audioEffect || r->chains.size() != 1)
  1380. return; // (as the slot menu's Ungroup: one-chain Audio Effect Racks)
  1381. engine.capturePluginStates();
  1382. engine.editSong ([t = insert, slot] (Song& song) { rack::ungroupSlot (song, t, slot); });
  1383. }
  1384. // the title bar's buttons at the right: [hot-swap] [save] [window]
  1385. int titleButtonsWidth (const Card& c) const
  1386. {
  1387. const auto pitch = theme::livelook::active() ? 16 : 18;
  1388. return pitch + (c.kind == Card::add ? 0 : pitch) + (c.kind == Card::effect && canSavePreset (c.index) ? pitch : 0);
  1389. }
  1390. juce::Rectangle<int> saveBounds (const Card& c) const
  1391. {
  1392. if (! (c.kind == Card::effect && canSavePreset (c.index)))
  1393. return {};
  1394. if (theme::livelook::active())
  1395. return { barRight (c) - 32, c.bounds.getY() + 2, 13, 13 };
  1396. return juce::Rectangle<int> (barRight (c) - 38, c.bounds.getY() + 3, 16, 14);
  1397. }
  1398. juce::Rectangle<int> swapBounds (const Card& c) const
  1399. {
  1400. if (c.kind == Card::add)
  1401. return {};
  1402. if (theme::livelook::active())
  1403. return { barRight (c) - 32 - (saveBounds (c).isEmpty() ? 0 : 16), c.bounds.getY() + 2, 13, 13 };
  1404. return { barRight (c) - 38 - (saveBounds (c).isEmpty() ? 0 : 18), c.bounds.getY() + 3, 16, 14 };
  1405. }
  1406. void showInsertMenu()
  1407. {
  1408. if (inserts.size() < 2)
  1409. return;
  1410. juce::PopupMenu menu;
  1411. const auto& song = engine.getSong();
  1412. for (const auto t : inserts)
  1413. menu.addItem (insertName (song, t), true, t == insert, [this, t] {
  1414. chosenInsert = t;
  1415. refresh();
  1416. });
  1417. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  1418. }
  1419. juce::String cardName (const Card& c) const
  1420. {
  1421. const auto& song = engine.getSong();
  1422. if (c.kind == Card::instrument)
  1423. return c.index >= 0 && c.index < (int) song.channels.size() ? utf8 (song.channels[(std::size_t) c.index].name) : juce::String();
  1424. if (const auto* fx = effectAt (c.index))
  1425. return quickpick::slotName (engine, *fx);
  1426. return {};
  1427. }
  1428. bool cardOn (const Card& c) const
  1429. {
  1430. const auto& song = engine.getSong();
  1431. if (c.kind == Card::instrument)
  1432. return c.index >= 0 && c.index < (int) song.channels.size() && ! song.channels[(std::size_t) c.index].muted;
  1433. const auto* fx = effectAt (c.index);
  1434. return fx != nullptr && fx->enabled;
  1435. }
  1436. // --- knobs ---------------------------------------------------------------------------------------------------
  1437. // --- an engine parameter on the instrument card (round 190ko): the knob moves the parameter's 0..1 (its automation
  1438. // value), shown in the engine's own units
  1439. const EngineParam* engineParamOf (const Card& c, int param) const
  1440. {
  1441. const auto& song = engine.getSong();
  1442. if (c.index < 0 || c.index >= (int) song.channels.size() || song.channels[(std::size_t) c.index].instrument != InstrumentKind::braid)
  1443. return nullptr;
  1444. const auto& list = braidEngineParams();
  1445. return param >= 0 && param < (int) list.size() ? &list[(std::size_t) param] : nullptr;
  1446. }
  1447. juce::String engineKnobLabel (const Card& c, int param) const
  1448. {
  1449. const auto* p = engineParamOf (c, param);
  1450. return p != nullptr ? utf8 (p->name) : juce::String();
  1451. }
  1452. ui::ValueSpec engineKnobSpec (const Card& c, int param) const
  1453. {
  1454. ui::ValueSpec spec;
  1455. const auto* p = engineParamOf (c, param);
  1456. if (p == nullptr)
  1457. return spec;
  1458. spec.name = cardName (c) + " - " + utf8 (p->name);
  1459. spec.minimum = 0.0, spec.maximum = 1.0;
  1460. const auto span = (double) (p->high - p->low);
  1461. spec.defaultValue = span > 0.0 ? (braid::defaults()[(std::size_t) param] - p->low) / span : 0.0;
  1462. if (p->stepped && span > 0.0)
  1463. spec.interval = 1.0 / span;
  1464. spec.toText = [param, lo = (double) p->low, span] (double v) { return utf8 (braid::paramText (param, lo + v * span)); };
  1465. spec.target = AutomationTarget { AutomationTargetKind::channelParam, c.index, 0, param };
  1466. return spec;
  1467. }
  1468. double engineKnobValue (const Card& c, int param) const
  1469. {
  1470. const auto* p = engineParamOf (c, param);
  1471. if (p == nullptr)
  1472. return 0.0;
  1473. const auto& ch = engine.getSong().channels[(std::size_t) c.index];
  1474. const auto raw = param < (int) ch.modelParams.size() ? (double) ch.modelParams[(std::size_t) param] : braid::defaults()[(std::size_t) param];
  1475. const auto span = (double) (p->high - p->low);
  1476. return span > 0.0 ? juce::jlimit (0.0, 1.0, (raw - p->low) / span) : 0.0;
  1477. }
  1478. void setEngineKnob (const Card& c, int param, double v)
  1479. {
  1480. const auto* p = engineParamOf (c, param);
  1481. if (p == nullptr)
  1482. return;
  1483. auto raw = (double) p->low + juce::jlimit (0.0, 1.0, v) * (double) (p->high - p->low);
  1484. if (p->stepped)
  1485. raw = std::round (raw);
  1486. engine.editSong ([ch = c.index, param, raw] (Song& s) {
  1487. if (ch < 0 || ch >= (int) s.channels.size() || s.channels[(std::size_t) ch].instrument != InstrumentKind::braid)
  1488. return;
  1489. auto& mp = s.channels[(std::size_t) ch].modelParams;
  1490. if ((int) mp.size() < braid::stateSize)
  1491. {
  1492. const auto d = braidDefaults();
  1493. const auto have = mp.size();
  1494. mp.resize ((std::size_t) braid::stateSize);
  1495. std::copy (d.begin() + (std::ptrdiff_t) have, d.end(), mp.begin() + (std::ptrdiff_t) have);
  1496. }
  1497. mp[(std::size_t) param] = (float) raw;
  1498. });
  1499. repaint();
  1500. }
  1501. ui::ValueSpec knobSpec (const Card& c, int knob) const
  1502. {
  1503. if (c.kind == Card::effect)
  1504. return slotActions.slotParamSpec (c.knobs[(std::size_t) knob], c.index);
  1505. if (c.knobs[(std::size_t) knob] >= engineKnobBase)
  1506. return engineKnobSpec (c, c.knobs[(std::size_t) knob] - engineKnobBase);
  1507. const auto name = cardName (c);
  1508. if (c.knobs[(std::size_t) knob] == 1)
  1509. {
  1510. auto spec = ui::panSpec (name + " - " + tr ("Pan"));
  1511. spec.target = AutomationTarget { AutomationTargetKind::channelPan, c.index };
  1512. return spec;
  1513. }
  1514. auto spec = ui::percentSpec (name + " - " + tr ("Volume"), 0.78); // (the Channel Rack's knob)
  1515. spec.target = AutomationTarget { AutomationTargetKind::channelVolume, c.index };
  1516. return spec;
  1517. }
  1518. double knobValue (const Card& c, int knob) const
  1519. {
  1520. if (c.kind == Card::effect)
  1521. return shownValue (c, knob, slotActions.slotParamValue (c.knobs[(std::size_t) knob], c.index));
  1522. if (c.knobs[(std::size_t) knob] >= engineKnobBase)
  1523. return engineKnobValue (c, c.knobs[(std::size_t) knob] - engineKnobBase);
  1524. const auto& song = engine.getSong();
  1525. if (c.index < 0 || c.index >= (int) song.channels.size())
  1526. return 0.0;
  1527. const auto& ch = song.channels[(std::size_t) c.index];
  1528. return shownValue (c, knob, c.knobs[(std::size_t) knob] == 1 ? ch.pan : ch.volume);
  1529. }
  1530. // Hotfix 0.1.31.1 (kainproctor, Discord: "tweaking any knob inside any plugin isn't reflected here"): while the song
  1531. // plays, a knob whose control automation drives shows the automation's value (core/AutomationDisplay), as the
  1532. // plugin's own window, the Mixer and FL do; while a mouse button is down the Song's value (the hand wins). `base`:
  1533. // the Song's value in the knob's own range.
  1534. double shownValue (const Card& c, int knob, double base) const
  1535. {
  1536. if (juce::ModifierKeys::currentModifiers.isAnyMouseButtonDown())
  1537. return base;
  1538. const auto& shown = engine.getAutomationDisplay();
  1539. if (! shown.any())
  1540. return base;
  1541. const auto k = c.knobs[(std::size_t) knob];
  1542. if (c.kind == Card::effect)
  1543. {
  1544. const auto t = k < 0 ? AutomationTarget { AutomationTargetKind::effectMix, insert, c.index, 0 }
  1545. : AutomationTarget { AutomationTargetKind::effectParam, insert, c.index, k };
  1546. return (double) shown.shown (t, (float) base);
  1547. }
  1548. if (k == 1) // (pan: the target's 0..1 is the knob's -1..1)
  1549. return (double) shown.shown ({ AutomationTargetKind::channelPan, c.index, 0, 0 }, (float) ((base + 1.0) * 0.5)) * 2.0 - 1.0;
  1550. return (double) shown.shown ({ AutomationTargetKind::channelVolume, c.index, 0, 0 }, (float) base);
  1551. }
  1552. // (the timer's test: a shown value of this chain changed since the last repaint)
  1553. bool automationMoved()
  1554. {
  1555. const auto& shown = engine.getAutomationDisplay();
  1556. if (shown.getGeneration() == shownGeneration)
  1557. return false;
  1558. shownGeneration = shown.getGeneration();
  1559. for (const auto& t : shown.automatedTargets())
  1560. if (((t.kind == AutomationTargetKind::effectParam || t.kind == AutomationTargetKind::effectMix) && t.index == insert && insert >= 0)
  1561. || ((t.kind == AutomationTargetKind::channelVolume || t.kind == AutomationTargetKind::channelPan) && t.index == channel && channel >= 0))
  1562. return true;
  1563. return false;
  1564. }
  1565. public:
  1566. double knobValueForCheck (int card, int knob) const
  1567. {
  1568. return card >= 0 && card < (int) cards.size() && knob >= 0 && knob < (int) cards[(std::size_t) card].knobs.size()
  1569. ? knobValue (cards[(std::size_t) card], knob) : -100.0;
  1570. }
  1571. private:
  1572. void setKnob (const Card& c, int knob, double v)
  1573. {
  1574. if (c.kind == Card::effect)
  1575. {
  1576. slotActions.setSlotParam (c.knobs[(std::size_t) knob], c.index, v);
  1577. return;
  1578. }
  1579. if (c.knobs[(std::size_t) knob] >= engineKnobBase)
  1580. {
  1581. setEngineKnob (c, c.knobs[(std::size_t) knob] - engineKnobBase, v);
  1582. return;
  1583. }
  1584. const auto pan = c.knobs[(std::size_t) knob] == 1;
  1585. engine.editLevels ([ch = c.index, pan, v = (float) v] (Song& song) {
  1586. if (ch < 0 || ch >= (int) song.channels.size())
  1587. return;
  1588. if (pan)
  1589. song.channels[(std::size_t) ch].pan = juce::jlimit (-1.0f, 1.0f, v);
  1590. else
  1591. song.channels[(std::size_t) ch].volume = juce::jlimit (0.0f, 1.0f, v);
  1592. });
  1593. repaint();
  1594. }
  1595. juce::Rectangle<int> knobBounds (const Card& c, int knob) const
  1596. {
  1597. if (c.folded || knob < 0 || knob >= (int) c.knobs.size())
  1598. return {};
  1599. const auto body = c.bounds.withTrimmedTop (titleHeight + 6);
  1600. if (c.kind == Card::instrument && c.knobs.size() <= 2u)
  1601. return { c.bounds.getX() + 16 + knob * knobColumn, body.getY() + 92, knobColumn - 8, knobRow - 6 };
  1602. if (c.kind == Card::effect)
  1603. if (const auto* fx = effectAt (c.index); fx != nullptr && fx->kind == EffectKind::plugin)
  1604. return { c.bounds.getX() + 8, body.getY() + 92, knobColumn - 8, knobRow - 6 };
  1605. const auto column = knob / 2, row = knob % 2;
  1606. return { c.bounds.getX() + 8 + column * knobColumn, body.getY() + row * knobRow, knobColumn - 8, knobRow - 6 };
  1607. }
  1608. // --- hit testing ---------------------------------------------------------------------------------------------
  1609. juce::Rectangle<int> pickerBounds() const { return { 8, 40, contextWidth - 16, 20 }; }
  1610. // round 190nc (DL-95): a rack with its chain's devices inline has its title bar over its own part only
  1611. static int barRight (const Card& c)
  1612. {
  1613. if (! c.folded && c.custom != nullptr)
  1614. if (const auto w = c.custom->titleBarWidth(); w > 0)
  1615. return c.bounds.getX() + std::min (w, c.bounds.getWidth());
  1616. return c.bounds.getRight();
  1617. }
  1618. static juce::Rectangle<int> titleBounds (const Card& c) { return c.bounds.withHeight (titleHeight).withRight (barRight (c)); }
  1619. // Live's look (round 190jn, CL-21): the 13 px power disc 3 px in, 2 px down; the title bar's round 13 px wells on a
  1620. // 16 px pitch, the last 3 px from the right edge (live-session.png Utility: disc x 1078..1090, wells 1166 / 1182 / 1198)
  1621. static juce::Rectangle<int> ledBounds (const Card& c)
  1622. {
  1623. if (theme::livelook::active())
  1624. return { c.bounds.getX() + 3, c.bounds.getY() + 2, 13, 13 };
  1625. return { c.bounds.getX() + 5, c.bounds.getY() + 5, 11, 11 };
  1626. }
  1627. static juce::Rectangle<int> windowBounds (const Card& c)
  1628. {
  1629. if (theme::livelook::active())
  1630. return { barRight (c) - 16, c.bounds.getY() + 2, 13, 13 };
  1631. return { barRight (c) - 20, c.bounds.getY() + 3, 16, 14 };
  1632. }
  1633. Hit hitAt (juce::Point<int> p) const
  1634. {
  1635. Hit h;
  1636. if (inserts.size() > 1 && pickerBounds().contains (p))
  1637. {
  1638. h.part = Part::picker;
  1639. return h;
  1640. }
  1641. if (! chainArea().contains (p))
  1642. return h;
  1643. for (int i = 0; i < (int) cards.size(); ++i)
  1644. {
  1645. const auto& c = cards[(std::size_t) i];
  1646. if (! c.bounds.contains (p))
  1647. continue;
  1648. h.card = i;
  1649. if (c.kind == Card::add)
  1650. return h;
  1651. if (ledBounds (c).expanded (2).contains (p))
  1652. h.part = Part::led;
  1653. else if (c.folded)
  1654. h.part = Part::folded;
  1655. else if (windowBounds (c).contains (p))
  1656. h.part = Part::window;
  1657. else if (swapBounds (c).contains (p))
  1658. h.part = Part::swap;
  1659. else if (saveBounds (c).contains (p))
  1660. h.part = Part::save;
  1661. else if (titleBounds (c).contains (p))
  1662. h.part = Part::title;
  1663. else
  1664. {
  1665. h.part = Part::body;
  1666. for (int k = 0; k < (int) c.knobs.size(); ++k)
  1667. if (knobBounds (c, k).contains (p))
  1668. {
  1669. h.part = Part::knob;
  1670. h.knob = k;
  1671. }
  1672. }
  1673. return h;
  1674. }
  1675. return h;
  1676. }
  1677. // --- painting ------------------------------------------------------------------------------------------------
  1678. void paintContext (juce::Graphics& g)
  1679. {
  1680. const auto& song = engine.getSong();
  1681. auto r = juce::Rectangle<int> (0, 0, contextWidth - 6, getHeight());
  1682. const auto live = theme::livelook::active(); // (round 190jn: Live's greys; Live has no such panel, LYNX keeps it)
  1683. g.setColour (live ? theme::livelook::surface : colour::bg2);
  1684. g.fillRect (r);
  1685. g.setColour (live ? theme::livelook::separator : colour::border);
  1686. g.fillRect (r.getRight(), 0, 1, getHeight());
  1687. r = r.reduced (8, 6);
  1688. g.setColour (live ? theme::livelook::text : colour::textPrimary);
  1689. g.setFont (font (type::body, true));
  1690. g.drawText (track >= 0 ? trackName (song, track) : juce::String(), r.removeFromTop (18), juce::Justification::centredLeft, true);
  1691. g.setColour (colour::textSecondary);
  1692. g.setFont (font (type::caption));
  1693. g.drawText (tr ("Insert"), r.removeFromTop (14), juce::Justification::centredLeft, true);
  1694. const auto box = pickerBounds();
  1695. const bool choice = inserts.size() > 1;
  1696. if (choice)
  1697. {
  1698. g.setColour (live ? (hover.part == Part::picker ? theme::livelook::raised : theme::livelook::well) : hover.part == Part::picker ? colour::bg5 : colour::bg4);
  1699. g.fillRoundedRectangle (box.toFloat(), 3.0f);
  1700. }
  1701. g.setColour (insert >= 0 ? colour::textPrimary : colour::textDisabled);
  1702. g.setFont (font (type::small));
  1703. g.drawText ((insert >= 0 ? insertName (song, insert) : tr ("None")) + (choice ? juce::String::fromUTF8 (" \xe2\x96\xbe") : juce::String()),
  1704. box.reduced (choice ? 6 : 0, 0), juce::Justification::centredLeft, true);
  1705. r = r.withTop (box.getBottom() + 8);
  1706. if (channel >= 0)
  1707. {
  1708. g.setColour (colour::textSecondary);
  1709. g.setFont (font (type::caption));
  1710. g.drawText (tr ("Channel"), r.removeFromTop (14), juce::Justification::centredLeft, true);
  1711. g.setColour (colour::textPrimary);
  1712. g.setFont (font (type::small));
  1713. g.drawText (utf8 (song.channels[(std::size_t) channel].name), r.removeFromTop (16), juce::Justification::centredLeft, true);
  1714. }
  1715. else if (inserts.size() > 1)
  1716. {
  1717. g.setColour (colour::textSecondary); // (round 190oj CS-14: 2.4:1, and squeezed into two lines)
  1718. g.setFont (font (type::caption));
  1719. g.drawFittedText (tr ("This track plays through {0} inserts", { juce::String ((int) inserts.size()) }), r.removeFromTop (42),
  1720. juce::Justification::topLeft, 3, 1.0f);
  1721. }
  1722. }
  1723. void paintCard (juce::Graphics& g, int i)
  1724. {
  1725. const auto& c = cards[(std::size_t) i];
  1726. if (! c.bounds.intersects (chainArea()))
  1727. return;
  1728. if (theme::livelook::active())
  1729. {
  1730. paintCardLive (g, i);
  1731. return;
  1732. }
  1733. if (c.kind == Card::add)
  1734. {
  1735. const bool hot = hover.card == i;
  1736. g.setColour (hot ? colour::bg3 : colour::bg2);
  1737. g.fillRect (c.bounds.reduced (0, 1));
  1738. g.setColour (colour::border);
  1739. g.drawRect (c.bounds.reduced (0, 1));
  1740. g.setColour (hot ? colour::textPrimary : colour::textSecondary);
  1741. g.setFont (font (22.0f));
  1742. g.drawText ("+", c.bounds, juce::Justification::centred, false);
  1743. return;
  1744. }
  1745. const bool selected = i == selectedCard();
  1746. const bool on = cardOn (c);
  1747. const auto name = cardName (c);
  1748. g.setColour (c.folded ? colour::bg3 : colour::bg2);
  1749. g.fillRect (c.bounds);
  1750. // the title bar: LED, name, window button
  1751. if (! c.folded)
  1752. {
  1753. g.setColour (colour::bg3);
  1754. g.fillRect (titleBounds (c));
  1755. }
  1756. g.setColour (on ? colour::accent : colour::bg5);
  1757. g.fillEllipse (ledBounds (c).toFloat());
  1758. if (hover.card == i && hover.part == Part::led)
  1759. {
  1760. g.setColour (colour::textPrimary.withAlpha (0.6f));
  1761. g.drawEllipse (ledBounds (c).toFloat().expanded (1.0f), 1.0f);
  1762. }
  1763. g.setColour (on ? colour::textPrimary : colour::textSecondary);
  1764. g.setFont (font (type::caption, true));
  1765. if (c.folded)
  1766. drawVerticalText (g, name, c.bounds.withTrimmedTop (titleHeight));
  1767. else
  1768. {
  1769. g.drawText (name, titleBounds (c).withTrimmedLeft (21).withTrimmedRight (4 + titleButtonsWidth (c) + (c.custom != nullptr ? c.custom->titleAccessoryWidth() : 0)),
  1770. juce::Justification::centredLeft, true);
  1771. drawWindowGlyph (g, windowBounds (c), hover.card == i && hover.part == Part::window);
  1772. drawSwapGlyph (g, swapBounds (c), hover.card == i && hover.part == Part::swap, linkedTo (targetOf (c)));
  1773. if (const auto save = saveBounds (c); ! save.isEmpty())
  1774. drawSaveGlyph (g, save, hover.card == i && hover.part == Part::save);
  1775. if (c.custom != nullptr)
  1776. {
  1777. // (its own component draws the body)
  1778. }
  1779. else if (on)
  1780. paintBody (g, i);
  1781. else // switched off: its controls dim, as the reference shows [SHOT d02]
  1782. {
  1783. g.beginTransparencyLayer (0.45f);
  1784. paintBody (g, i);
  1785. g.endTransparencyLayer();
  1786. }
  1787. }
  1788. g.setColour (selected ? colour::accent : colour::border);
  1789. g.drawRect (c.bounds, selected ? 2 : 1);
  1790. }
  1791. // Round 190jn (design190ia CL-21): a card in Live 12.4's device chrome (live-session.png Utility 1075..1213 × 807..995):
  1792. // body #363636 with 3 px corners on the #2A2A2A chain, a 17 px #464646 title bar (selected: #637E86 with #070707 text),
  1793. // the 13 px power disc (#FFAD56 on, #1E1E1E off), the name in #B5B5B5, round 13 px wells for hot-swap / save / window;
  1794. // no outline. A folded card is the title bar turned on its side. The body: Live's open-ring knobs (paintBodyLive).
  1795. void paintCardLive (juce::Graphics& g, int i)
  1796. {
  1797. namespace ll = theme::livelook;
  1798. const auto& c = cards[(std::size_t) i];
  1799. if (c.kind == Card::add)
  1800. {
  1801. const bool hot = hover.card == i;
  1802. g.setColour (hot ? ll::raised : ll::surface);
  1803. g.fillRoundedRectangle (c.bounds.reduced (0, 1).toFloat(), 3.0f);
  1804. g.setColour (hot ? colour::textPrimary : ll::text);
  1805. g.setFont (font (22.0f));
  1806. g.drawText ("+", c.bounds, juce::Justification::centred, false);
  1807. return;
  1808. }
  1809. const bool selected = i == selectedCard();
  1810. const bool on = cardOn (c);
  1811. const auto name = cardName (c);
  1812. const auto box = c.bounds.toFloat();
  1813. const auto bar = selected ? ll::selectionUnfocused : ll::raised;
  1814. g.setColour (c.folded ? bar : ll::surface);
  1815. g.fillRoundedRectangle (box, 3.0f);
  1816. if (! c.folded)
  1817. {
  1818. juce::Path title;
  1819. title.addRoundedRectangle (box.getX(), box.getY(), (float) titleBounds (c).getWidth(), (float) (int) titleHeight, 3.0f, 3.0f, true, true, false, false);
  1820. g.setColour (bar);
  1821. g.fillPath (title);
  1822. }
  1823. ll::drawPower (g, ledBounds (c).toFloat(), on);
  1824. if (hover.card == i && hover.part == Part::led)
  1825. {
  1826. g.setColour (colour::textPrimary.withAlpha (0.6f));
  1827. g.drawEllipse (ledBounds (c).toFloat().expanded (1.0f), 1.0f);
  1828. }
  1829. g.setColour (selected ? ll::ink : ll::text);
  1830. g.setFont (font (type::small));
  1831. if (c.folded)
  1832. drawVerticalText (g, name, c.bounds.withTrimmedTop (titleHeight));
  1833. else
  1834. {
  1835. g.drawText (name, titleBounds (c).withTrimmedLeft (20).withTrimmedRight (4 + titleButtonsWidth (c) + (c.custom != nullptr ? c.custom->titleAccessoryWidth() : 0)),
  1836. juce::Justification::centredLeft, true);
  1837. drawLiveWellGlyph (g, windowBounds (c), 0, hover.card == i && hover.part == Part::window, false);
  1838. drawLiveWellGlyph (g, swapBounds (c), 1, hover.card == i && hover.part == Part::swap, linkedTo (targetOf (c)));
  1839. if (const auto save = saveBounds (c); ! save.isEmpty())
  1840. drawLiveWellGlyph (g, save, 2, hover.card == i && hover.part == Part::save, false);
  1841. if (c.custom != nullptr)
  1842. {
  1843. // (its own component draws the body)
  1844. }
  1845. else if (on)
  1846. paintBodyLive (g, i);
  1847. else // switched off: its controls dim (Live 12.4: round 183a's d02-utility-off.png)
  1848. {
  1849. g.beginTransparencyLayer (0.45f);
  1850. paintBodyLive (g, i);
  1851. g.endTransparencyLayer();
  1852. }
  1853. }
  1854. }
  1855. // Live's body: label and value in #B5B5B5 (the UI font at 12 px: Live's cap height 7 px), the 25 px open-ring knob
  1856. void paintBodyLive (juce::Graphics& g, int i)
  1857. {
  1858. namespace ll = theme::livelook;
  1859. const auto& c = cards[(std::size_t) i];
  1860. const auto body = c.bounds.withTrimmedTop (titleHeight + 6).reduced (8, 0);
  1861. const auto* fx = c.kind == Card::effect ? effectAt (c.index) : nullptr;
  1862. if (c.kind == Card::instrument || (fx != nullptr && fx->kind == EffectKind::plugin))
  1863. paintPicture (g, c, body.withHeight (80));
  1864. for (int k = 0; k < (int) c.knobs.size(); ++k)
  1865. {
  1866. const auto r = knobBounds (c, k);
  1867. if (r.isEmpty())
  1868. continue;
  1869. const auto spec = knobSpec (c, k);
  1870. const auto value = knobValue (c, k);
  1871. const auto label = c.kind == Card::effect && c.knobs[(std::size_t) k] < 0 ? (fx != nullptr && hasOwnMix (fx->kind) ? tr ("Slot mix") : tr ("Mix"))
  1872. : c.kind == Card::effect && fx != nullptr ? utf8 (effectInfo (fx->kind).params[(std::size_t) c.knobs[(std::size_t) k]].name)
  1873. : c.knobs[(std::size_t) k] == 1 ? tr ("Pan")
  1874. : tr ("Volume");
  1875. auto rr = r;
  1876. const auto hot = (hover.card == i && hover.knob == k) || (knobCard == i && knobDrag == k);
  1877. g.setColour (hot ? colour::textPrimary : ll::text);
  1878. g.setFont (font (type::small));
  1879. g.drawText (label, rr.removeFromTop (14), juce::Justification::centred, true);
  1880. const auto knob = rr.removeFromTop (knobSize).toFloat().withSizeKeepingCentre (27.0f, 27.0f);
  1881. const auto range = spec.maximum - spec.minimum;
  1882. const auto v01 = range > 0.0 ? (float) ((value - spec.minimum) / range) : 0.0f;
  1883. const auto home = range > 0.0 ? (float) ((juce::jlimit (spec.minimum, spec.maximum, spec.defaultValue) - spec.minimum) / range) : 0.0f;
  1884. ll::drawKnob (g, knob, juce::jlimit (0.0f, 1.0f, v01), home);
  1885. if (spec.target) // round 190lx (DL-59, capture 190lx L04): Live's red LED on an automated device knob
  1886. {
  1887. const auto& automated = engine.getAutomationDisplay().automatedTargets();
  1888. if (std::find (automated.begin(), automated.end(), *spec.target) != automated.end())
  1889. theme::drawLiveKnobAutomationLed (g, knob);
  1890. }
  1891. g.setColour (hot ? colour::textPrimary : ll::text);
  1892. g.drawText (spec.text (value), rr.removeFromTop (14), juce::Justification::centred, true);
  1893. }
  1894. }
  1895. void paintBody (juce::Graphics& g, int i)
  1896. {
  1897. const auto& c = cards[(std::size_t) i];
  1898. const auto body = c.bounds.withTrimmedTop (titleHeight + 6).reduced (8, 0);
  1899. const auto* fx = c.kind == Card::effect ? effectAt (c.index) : nullptr;
  1900. if ((c.kind == Card::instrument && c.knobs.size() <= 2u) || (fx != nullptr && fx->kind == EffectKind::plugin))
  1901. paintPicture (g, c, body.withHeight (80));
  1902. for (int k = 0; k < (int) c.knobs.size(); ++k)
  1903. {
  1904. const auto r = knobBounds (c, k);
  1905. if (r.isEmpty())
  1906. continue;
  1907. const auto spec = knobSpec (c, k);
  1908. const auto value = knobValue (c, k);
  1909. const auto label = c.kind == Card::effect && c.knobs[(std::size_t) k] < 0 ? (fx != nullptr && hasOwnMix (fx->kind) ? tr ("Slot mix") : tr ("Mix"))
  1910. : c.kind == Card::effect && fx != nullptr ? utf8 (effectInfo (fx->kind).params[(std::size_t) c.knobs[(std::size_t) k]].name)
  1911. : c.knobs[(std::size_t) k] >= engineKnobBase ? engineKnobLabel (c, c.knobs[(std::size_t) k] - engineKnobBase)
  1912. : c.knobs[(std::size_t) k] == 1 ? tr ("Pan")
  1913. : tr ("Volume");
  1914. auto rr = r;
  1915. g.setColour (colour::textSecondary);
  1916. g.setFont (font (type::caption));
  1917. g.drawText (label, rr.removeFromTop (14), juce::Justification::centred, true);
  1918. const auto knob = rr.removeFromTop (knobSize).toFloat().withSizeKeepingCentre ((float) knobSize, (float) knobSize);
  1919. const auto range = spec.maximum - spec.minimum;
  1920. const auto v01 = range > 0.0 ? (float) ((value - spec.minimum) / range) : 0.0f;
  1921. drawKnob (g, knob, juce::jlimit (0.0f, 1.0f, v01), spec.minimum < 0.0, (hover.card == i && hover.knob == k) || (knobCard == i && knobDrag == k) ? colour::accent : colour::knobArc,
  1922. hover.card == i && hover.knob == k);
  1923. g.setColour (colour::textPrimary);
  1924. g.drawText (spec.text (value), rr.removeFromTop (14), juce::Justification::centred, true);
  1925. }
  1926. }
  1927. // The Plugin picker's key of a LYNX generator kind ("lynx:gen:<English name>"), from its entries once per run; ""
  1928. // for a hosted plugin or a kind the picker doesn't list.
  1929. std::string generatorKeyOf (InstrumentKind kind)
  1930. {
  1931. static std::map<int, std::string> keys;
  1932. static bool filled = false;
  1933. if (! filled)
  1934. {
  1935. filled = true;
  1936. for (const auto& e : quickpick::generatorEntries (engine))
  1937. if (e.folder == 0 && e.key.rfind ("lynx:gen:", 0) == 0)
  1938. keys.emplace ((int) e.kind, e.key); // (the first entry of a kind)
  1939. }
  1940. if (kind == InstrumentKind::plugin)
  1941. return {};
  1942. const auto it = keys.find ((int) kind);
  1943. return it != keys.end() ? it->second : std::string();
  1944. }
  1945. // the effect has a parameter called Mix of its own: the slot's dry/wet is then labelled "Slot mix"
  1946. static bool hasOwnMix (EffectKind kind)
  1947. {
  1948. for (const auto& p : effectInfo (kind).params)
  1949. if (juce::String (p.name).equalsIgnoreCase ("Mix"))
  1950. return true;
  1951. return false;
  1952. }
  1953. // the plugin's picture (Plugin picker thumbnails), else a tile with its name
  1954. void paintPicture (juce::Graphics& g, const Card& c, juce::Rectangle<int> area)
  1955. {
  1956. const auto& song = engine.getSong();
  1957. std::string key;
  1958. if (c.kind == Card::instrument && c.index >= 0 && c.index < (int) song.channels.size())
  1959. key = generatorKeyOf (song.channels[(std::size_t) c.index].instrument);
  1960. juce::Image picture;
  1961. if (! key.empty())
  1962. if (const auto file = pluginthumbs::fileFor (key, true); file.existsAsFile())
  1963. picture = juce::ImageCache::getFromFile (file);
  1964. g.setColour (theme::livelook::active() ? theme::livelook::well : colour::bg0);
  1965. g.fillRect (area);
  1966. if (picture.isValid())
  1967. {
  1968. g.drawImageWithin (picture, area.getX(), area.getY(), area.getWidth(), area.getHeight(), juce::RectanglePlacement::centred);
  1969. return;
  1970. }
  1971. g.setColour (colour::textSecondary);
  1972. g.setFont (font (type::small, true));
  1973. g.drawFittedText (cardName (c), area.reduced (6), juce::Justification::centred, 2);
  1974. }
  1975. void paintMeter (juce::Graphics& g)
  1976. {
  1977. const auto r = meterBounds();
  1978. g.setColour (theme::livelook::active() ? theme::livelook::meterWell : colour::bg0);
  1979. g.fillRect (r);
  1980. for (int side = 0; side < 2; ++side)
  1981. {
  1982. const auto bar = juce::Rectangle<int> (r.getX() + 3 + side * 8, r.getY() + 2, 6, r.getHeight() - 4);
  1983. const auto& m = levels[(std::size_t) side];
  1984. const auto db = juce::Decibels::gainToDecibels (m.level, -60.0f);
  1985. const auto h = juce::roundToInt ((float) bar.getHeight() * juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f));
  1986. g.setColour (colour::meterZonesOwn ? (db >= colour::meterRedDb ? colour::meterClip : db >= colour::meterYellowDb ? colour::meterMid : colour::meterLow) // (round 190qh)
  1987. : m.level >= 1.0f ? colour::meterClip : db > -6.0f ? colour::meterMid : colour::meterLow);
  1988. g.fillRect (bar.withTop (bar.getBottom() - h));
  1989. }
  1990. }
  1991. juce::Rectangle<int> meterBounds() const { return { getWidth() - meterWidth, 4, meterWidth - 4, std::max (0, getHeight() - 16) }; }
  1992. // Round 190lr (DL-87, Live manual 23.2 "Devices in Live's tracks have input and output level meters"; capture
  1993. // live-device-meters.png): in Live's look a slim meter stands in the gap after each device, the level that leaves it
  1994. // (after the instrument: what enters the first effect). The slots' peaks come from the audio thread only while this
  1995. // view shows (RackRenderer's levelWanted / slotLevels, the editors' own level taps); mono (the louder side).
  1996. bool deviceMeters() const { return theme::livelook::active(); }
  1997. int cardGap() const { return deviceMeters() ? deviceMeterGap : gap; }
  1998. static constexpr int deviceMeterGap = 9; // (Live, L28: 9 px between two devices, the meter in its middle)
  1999. std::size_t slotKey (int slot) const { return (std::size_t) juce::jmax (0, insert) * (std::size_t) maxEffectSlots + (std::size_t) slot; }
  2000. void watchDevices (bool on)
  2001. {
  2002. std::vector<std::size_t> want;
  2003. if (on && deviceMeters() && insert >= 0)
  2004. for (int i = 0; i < effectCount() && i < maxEffectSlots; ++i)
  2005. want.push_back (slotKey (i));
  2006. if (want == watched)
  2007. return;
  2008. if (auto* times = engine.getProcessTimes())
  2009. {
  2010. for (const auto k : watched)
  2011. if (k < times->levelWanted.size())
  2012. times->levelWanted[k].fetch_sub (1, std::memory_order_relaxed);
  2013. for (const auto k : want)
  2014. if (k < times->levelWanted.size())
  2015. times->levelWanted[k].fetch_add (1, std::memory_order_relaxed);
  2016. watched = std::move (want);
  2017. }
  2018. else
  2019. watched.clear();
  2020. }
  2021. // the meter after card `i` (empty: none): Live's 2 + 1 + 2 px well in the middle of the gap, centred on the device's
  2022. // height (L28: 108 of 188 px; its top 11 px cut off by a line, as Live's)
  2023. juce::Rectangle<int> deviceMeterBounds (int i) const
  2024. {
  2025. if (! deviceMeters() || i < 0 || i >= (int) cards.size())
  2026. return {};
  2027. const auto& c = cards[(std::size_t) i];
  2028. if (c.kind == Card::add || (c.kind == Card::instrument && effectCount() == 0))
  2029. return {};
  2030. const auto inset = juce::roundToInt ((float) c.bounds.getHeight() * 0.21f);
  2031. return { c.bounds.getRight() + (deviceMeterGap - 5) / 2 + 1, c.bounds.getY() + inset, 5, juce::jmax (0, c.bounds.getHeight() - 2 * inset) };
  2032. }
  2033. // its level, one side: an effect's output, the instrument's = the first effect's input
  2034. float takeDeviceLevel (const Card& c, int side)
  2035. {
  2036. auto* times = engine.getProcessTimes();
  2037. if (times == nullptr)
  2038. return 0.0f;
  2039. auto& sides = c.kind == Card::effect ? times->slotOutputSides : times->slotInputSides;
  2040. const auto k = (c.kind == Card::effect ? slotKey (c.index) : slotKey (0)) * 2 + (std::size_t) side;
  2041. return k < sides.size() ? sides[k].exchange (0.0f, std::memory_order_relaxed) : 0.0f;
  2042. }
  2043. void tickDeviceMeters()
  2044. {
  2045. watchDevices (true);
  2046. if (! deviceMeters())
  2047. return;
  2048. if (deviceLevels.size() != cards.size() * 2)
  2049. deviceLevels.assign (cards.size() * 2, {});
  2050. for (int i = 0; i < (int) cards.size(); ++i)
  2051. {
  2052. const auto r = deviceMeterBounds (i);
  2053. if (r.isEmpty())
  2054. continue;
  2055. for (int side = 0; side < 2; ++side)
  2056. {
  2057. auto& m = deviceLevels[(std::size_t) i * 2 + (std::size_t) side];
  2058. const auto before = m.level;
  2059. const auto beforePeak = m.peak;
  2060. m.tick (takeDeviceLevel (cards[(std::size_t) i], side));
  2061. if (std::abs (m.level - before) > 1e-4f || std::abs (m.peak - beforePeak) > 1e-4f)
  2062. repaint (r.expanded (1));
  2063. }
  2064. }
  2065. }
  2066. void paintDeviceMeters (juce::Graphics& g)
  2067. {
  2068. if (! deviceMeters())
  2069. return;
  2070. namespace lv = theme::livelook;
  2071. for (int i = 0; i < (int) cards.size(); ++i)
  2072. {
  2073. const auto r = deviceMeterBounds (i);
  2074. if (r.isEmpty() || ! g.clipRegionIntersects (r))
  2075. continue;
  2076. // (Live, capture L28: two 2 px wells #181818 with the window between, a 1 px #363636 line 11 px under the top;
  2077. // the level #00F758, the peak hold a 1 px line)
  2078. const auto body = r.withTrimmedTop (12);
  2079. for (int side = 0; side < 2; ++side)
  2080. {
  2081. const auto bar = juce::Rectangle<int> (r.getX() + side * 3, r.getY(), 2, r.getHeight());
  2082. g.setColour (lv::meterWell);
  2083. g.fillRect (bar);
  2084. g.setColour (lv::surface);
  2085. g.fillRect (bar.getX(), r.getY() + 11, 2, 1);
  2086. const auto& m = (std::size_t) i * 2 + (std::size_t) side < deviceLevels.size() ? deviceLevels[(std::size_t) i * 2 + (std::size_t) side]
  2087. : meters::PeakHold {};
  2088. const auto yOf = [&body] (float gain) {
  2089. const auto db = juce::Decibels::gainToDecibels (gain, -60.0f);
  2090. return body.getBottom() - juce::roundToInt ((float) body.getHeight() * juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 66.0f));
  2091. };
  2092. if (m.level > 0.0f)
  2093. {
  2094. g.setColour (juce::Colour (0xff00f758)); // (Live's meter green)
  2095. g.fillRect (bar.withTop (yOf (m.level)).withBottom (body.getBottom()));
  2096. }
  2097. if (m.peak > 0.001f)
  2098. {
  2099. g.setColour (juce::Colour (0xff00f758));
  2100. g.fillRect (bar.getX(), juce::jmin (body.getBottom() - 1, yOf (m.peak)), 2, 1);
  2101. }
  2102. if (m.clipped)
  2103. {
  2104. g.setColour (juce::Colour (0xffff3a3a));
  2105. g.fillRect (bar.withHeight (11));
  2106. }
  2107. }
  2108. }
  2109. }
  2110. std::vector<std::size_t> watched;
  2111. std::vector<meters::PeakHold> deviceLevels;
  2112. public:
  2113. void deviceLevelsForSnapshot (float left, float right)
  2114. {
  2115. deviceLevels.assign (cards.size() * 2, {});
  2116. for (std::size_t i = 0; i < deviceLevels.size(); ++i)
  2117. {
  2118. deviceLevels[i].level = i % 2 == 0 ? left : right;
  2119. deviceLevels[i].peak = juce::jmin (1.0f, (i % 2 == 0 ? left : right) * 1.25f);
  2120. }
  2121. repaint();
  2122. }
  2123. private:
  2124. void timerCallback() override
  2125. {
  2126. tickDeviceMeters(); // round 190lr (DL-87)
  2127. if (automationMoved()) // hotfix 0.1.31.1: the knobs follow their automation (only while the chain shows)
  2128. repaint();
  2129. if (insert < 0 || hooks.levelOf == nullptr)
  2130. return;
  2131. bool moved = false;
  2132. for (int side = 0; side < 2; ++side)
  2133. {
  2134. auto& m = levels[(std::size_t) side];
  2135. const auto before = m.level;
  2136. m.tick (hooks.levelOf (insert, side));
  2137. moved = moved || std::abs (m.level - before) > 1e-4f;
  2138. }
  2139. if (moved)
  2140. repaint (meterBounds());
  2141. }
  2142. AudioEngine& engine;
  2143. Hooks& hooks;
  2144. EffectsPanel slotActions; // never shown: the Mixer slot's own menus, windows and edits, on this view's insert
  2145. std::unique_ptr<pluginheader::PresetBar> presetBar; // (round 190ce: the Save preset dialog of the card last asked)
  2146. juce::Component cardHost; // the chain area: custom card bodies live here (clipped to it)
  2147. std::map<std::uint64_t, CustomEntry> customs;
  2148. juce::ScrollBar scrollBar { false };
  2149. std::unique_ptr<ui::TimerWhileShowing> showingTimer;
  2150. std::uint32_t shownGeneration = 0; // (hotfix 0.1.31.1: the AutomationDisplay generation last drawn)
  2151. std::array<meters::PeakHold, 2> levels {};
  2152. int track = -1, insert = -1, channel = -1, chosenInsert = -1, actionsInsert = -1;
  2153. std::vector<int> inserts;
  2154. std::vector<Card> cards;
  2155. std::set<std::uint64_t> folded; // UI only, not saved (D2a)
  2156. std::uint64_t selectedTag = 0;
  2157. bool instrumentSelected = false;
  2158. int scroll = 0, contentWidth = 0;
  2159. Hit hover;
  2160. ui::ValueDrag drag;
  2161. int knobDrag = -1, knobCard = -1;
  2162. int dragCard = -1, dropBefore = -1;
  2163. bool dragging = false;
  2164. };
  2165. // ---------------------------------------------------------------------------------------------------------------------
  2166. // Slice 2b: the Clip page's left column, the reference's Clip / Launch / Notes panels [SHOT d08, m3-live-clipview2] over
  2167. // LYNX's existing model: the grid clip's offset and length, its slot's loop and launch settings, and the pattern's
  2168. // notes through the Piano roll's own note tools. No new model: Signature is the project's, Scale is the project key
  2169. // (core/ProjectKey.h; round 190o), Groove has no LYNX model (listed as missing in REA_rodada183a.md).
  2170. // The clip's colour and activator in one square, as the reference's clip title bar [LIVE 12.4 Clip View] (round 190s,
  2171. // GAPMAP-0126 D15): filled = the clip plays, hollow = deactivated. Click switches it; right-click picks the colour.
  2172. // Round 190kc: the Clip box's Commit button. Live 12.4 draws it as a 13 px round well with an arrow beside the Groove
  2173. // label (shots/ref/live-clipview-midi-groove.png x 156..168 y 797..809; dim while the clip has no groove); the classic
  2174. // look keeps a text button.
  2175. class GrooveCommitButton final : public juce::TextButton
  2176. {
  2177. public:
  2178. void paintButton (juce::Graphics& g, bool over, bool down) override
  2179. {
  2180. if (! theme::livelook::active())
  2181. {
  2182. juce::TextButton::paintButton (g, over, down);
  2183. return;
  2184. }
  2185. namespace lv = theme::livelook;
  2186. const auto r = getLocalBounds().toFloat().withSizeKeepingCentre (13.0f, 13.0f);
  2187. const auto ink = lv::drawWell (g, r, down, true);
  2188. g.setColour (isEnabled() ? ink : ink.withAlpha (0.35f));
  2189. const auto cx = std::round (r.getCentreX()), cy = std::round (r.getCentreY());
  2190. g.fillRect (cx - 3.0f, cy, 6.0f, 1.0f); // (→: the shaft and the head)
  2191. g.fillRect (cx + 1.0f, cy - 2.0f, 1.0f, 5.0f);
  2192. g.fillRect (cx + 2.0f, cy - 1.0f, 1.0f, 3.0f);
  2193. }
  2194. };
  2195. class ClipChip final : public juce::Component, public juce::SettableTooltipClient
  2196. {
  2197. public:
  2198. ClipChip() { setRepaintsOnMouseActivity (true); }
  2199. void set (juce::Colour c, bool on)
  2200. {
  2201. if (c != fill || on != active)
  2202. {
  2203. fill = c;
  2204. active = on;
  2205. repaint();
  2206. }
  2207. }
  2208. void paint (juce::Graphics& g) override
  2209. {
  2210. if (theme::livelook::active()) // (round 190jn: Live's activator in the clip-coloured title bar: a 9 px square, orange while on)
  2211. {
  2212. const auto sq = getLocalBounds().toFloat().withSizeKeepingCentre (9.0f, 9.0f);
  2213. g.setColour (isMouseOver() ? theme::livelook::ink : liveclip::rim);
  2214. g.fillRect (sq);
  2215. g.setColour (active ? theme::livelook::on : theme::livelook::well);
  2216. g.fillRect (sq.reduced (1.0f));
  2217. return;
  2218. }
  2219. const auto r = getLocalBounds().toFloat().reduced (2.0f);
  2220. g.setColour (fill);
  2221. if (active)
  2222. g.fillRect (r);
  2223. else
  2224. g.drawRect (r, 2.0f);
  2225. g.setColour (isMouseOver() ? colour::textPrimary : colour::borderStrong);
  2226. g.drawRect (r, 1.0f);
  2227. }
  2228. void mouseUp (const juce::MouseEvent& e) override
  2229. {
  2230. if (! contains (e.getPosition()))
  2231. return;
  2232. if (e.mods.isPopupMenu())
  2233. {
  2234. if (onColourMenu != nullptr)
  2235. onColourMenu();
  2236. }
  2237. else if (onToggle != nullptr)
  2238. onToggle();
  2239. }
  2240. std::function<void()> onToggle, onColourMenu;
  2241. private:
  2242. juce::Colour fill { colour::bg5 };
  2243. bool active = true;
  2244. };
  2245. class ClipColumn final : public juce::Component, private juce::ChangeListener, private juce::Timer
  2246. {
  2247. public:
  2248. explicit ClipColumn (AudioEngine& e)
  2249. : engine (e),
  2250. tools (e, [this] { return toolTarget(); },
  2251. [this] (const std::vector<int>& indices) {
  2252. if (auto* roll = editorOf != nullptr ? editorOf() : nullptr)
  2253. roll->selectMidiToolResult (indices);
  2254. })
  2255. {
  2256. // Live's Transform section [LIVE 12.4 Clip View] (round 190s): the fourth panel, foldable as Live's sections are
  2257. addChildComponent (tools);
  2258. foldTools.setConnectedEdges (0);
  2259. foldTools.setTooltip (tr ("Transform: show or hide the MIDI Tools"));
  2260. foldTools.onClick = [this] {
  2261. toolsFolded = ! toolsFolded;
  2262. load();
  2263. if (auto* parent = getParentComponent())
  2264. parent->resized();
  2265. };
  2266. addChildComponent (foldTools);
  2267. // round 190s (GAPMAP-0126 D15, D6, D4): the clip's colour / activator square, the notes' pitch range (drag it
  2268. // to transpose) and Add interval with its size
  2269. chip.setTooltip (tr ("The clip's colour. Click: deactivate or activate the clip. Right-click: change its colour"));
  2270. chip.onToggle = [this] { editClip ([] (Clip& c, ClipGridSlot&) { c.muted = ! c.muted; }); };
  2271. chip.onColourMenu = [this] {
  2272. const auto* c = clip();
  2273. const auto& song = engine.getSong();
  2274. if (c == nullptr || c->gridSlot < 0 || c->gridSlot >= (int) song.clipGrid->slots.size())
  2275. return;
  2276. const juce::Component::SafePointer<ClipColumn> safe (this);
  2277. ui::colourMenu (song.clipGrid->slots[(std::size_t) c->gridSlot].colour,
  2278. [safe] (std::uint32_t colour) {
  2279. if (safe != nullptr)
  2280. safe->editClip ([colour] (Clip&, ClipGridSlot& slot) { slot.colour = colour; });
  2281. },
  2282. chip.getScreenBounds())
  2283. .showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&chip));
  2284. };
  2285. addAndMakeVisible (chip);
  2286. {
  2287. ui::ValueSpec range;
  2288. range.name = tr ("Pitch range: drag up or down to transpose the notes");
  2289. range.minimum = -96.0;
  2290. range.maximum = 96.0;
  2291. range.interval = 1.0;
  2292. range.pixelsForRange = 192.0 * 6.0; // 6 px per semitone
  2293. range.toText = [this] (double) { return rangeText; };
  2294. pitchRange = std::make_unique<ui::NumBox> (range, [this] { return (double) transposed; }, [this] (double v) {
  2295. const auto by = juce::roundToInt (v) - transposed;
  2296. if (by == 0)
  2297. return;
  2298. transposed += by;
  2299. notes ([by] (Pattern& p, const std::vector<int>& all, const Song&) {
  2300. for (auto i : all)
  2301. p.notes[(std::size_t) i].key = std::clamp (p.notes[(std::size_t) i].key + by, 0, 131);
  2302. });
  2303. });
  2304. addAndMakeVisible (*pitchRange);
  2305. ui::ValueSpec size;
  2306. size.name = tr ("Interval size");
  2307. size.minimum = -24.0;
  2308. size.maximum = 24.0;
  2309. size.interval = 1.0;
  2310. size.defaultValue = 0.0;
  2311. size.pixelsForRange = 48.0 * 6.0;
  2312. size.toText = [] (double v) { return juce::String (juce::roundToInt (v)) + " st"; };
  2313. intervalSize = std::make_unique<ui::NumBox> (size, [this] { return (double) interval; }, [this] (double v) { interval = juce::roundToInt (v); });
  2314. addAndMakeVisible (*intervalSize);
  2315. }
  2316. addInterval.setButtonText (tr ("Add interval"));
  2317. addInterval.setTooltip (tr ("Adds to every note a note this many semitones away"));
  2318. addInterval.setConnectedEdges (0);
  2319. addInterval.onClick = [this] {
  2320. if (interval == 0)
  2321. return;
  2322. notes ([by = interval] (Pattern& p, const std::vector<int>& all, const Song&) {
  2323. std::vector<Note> added;
  2324. for (auto i : all)
  2325. {
  2326. auto n = p.notes[(std::size_t) i];
  2327. n.key += by;
  2328. if (n.key >= 0 && n.key <= 131)
  2329. added.push_back (n);
  2330. }
  2331. p.notes.insert (p.notes.end(), added.begin(), added.end());
  2332. });
  2333. };
  2334. addAndMakeVisible (addInterval);
  2335. for (auto* t : { &clipTitle, &launchTitle, &notesTitle })
  2336. {
  2337. t->setFont (font (type::small, true));
  2338. t->setColour (juce::Label::textColourId, colour::textSecondary);
  2339. addAndMakeVisible (*t);
  2340. }
  2341. clipTitle.setText (tr ("Clip"), juce::dontSendNotification);
  2342. launchTitle.setText (tr ("Launch"), juce::dontSendNotification);
  2343. notesTitle.setText (tr ("Notes"), juce::dontSendNotification);
  2344. const std::pair<juce::Label*, const char*> labels[] = { { &nameLabel, TR_NOOP ("Name") }, { &startLabel, TR_NOOP ("Start") },
  2345. { &endLabel, TR_NOOP ("End") }, { &lengthLabel, TR_NOOP ("Length") },
  2346. { &positionLabel, TR_NOOP ("Position") }, { &grooveLabel, TR_NOOP ("Groove") },
  2347. { &signatureLabel, TR_NOOP ("Signature") }, { &modeLabel, TR_NOOP ("Launch mode") },
  2348. { &quantLabel, TR_NOOP ("Launch quantisation") }, { &scaleLabel, TR_NOOP ("Scale") } };
  2349. for (const auto& [l, text] : labels)
  2350. {
  2351. l->setText (tr (text), juce::dontSendNotification);
  2352. l->setFont (font (type::caption));
  2353. l->setColour (juce::Label::textColourId, colour::textSecondary);
  2354. addAndMakeVisible (*l);
  2355. }
  2356. for (auto* ed : { &name, &start, &end, &position, &length })
  2357. {
  2358. addAndMakeVisible (*ed);
  2359. ed->setFont (font (type::small));
  2360. ed->onReturnKey = [this] { apply(); };
  2361. ed->onFocusLost = [this] { apply(); };
  2362. ed->onEscapeKey = [this] { load(); };
  2363. }
  2364. // round 190dr-2: Live's fields [SHOT live-clipview-audio-panel.png] in bars. beats. sixteenths ("1. 1. 1"; lengths
  2365. // "8. 0. 0"), seconds for an unwarped audio clip; LYNX's loop starts where the clip starts, so Position is the start
  2366. // moved with the end and Length is the clip's length (core/ClipSample.h)
  2367. start.setTooltip (tr ("Start: where the clip starts in its source (bar. beat. sixteenth; seconds for unwarped audio)"));
  2368. end.setTooltip (tr ("End: where the clip ends in its source"));
  2369. // round 190hr (detail-016): with Loop on, Start is a marker of its own inside the loop (Live's StartRelative)
  2370. position.setTooltip (tr ("Loop Position: where the loop starts; the Start marker stays where it is"));
  2371. length.setTooltip (tr ("Loop Length (bars. beats. sixteenths)"));
  2372. // round 190dr: Live's Set buttons beside the fields: the marker goes to where the playing clip is now; dim while
  2373. // the clip does not play
  2374. for (auto* b : { &setStart, &setEnd, &setPosition, &setLength })
  2375. {
  2376. b->setButtonText (tr ("Set"));
  2377. b->setConnectedEdges (0);
  2378. b->setEnabled (false);
  2379. b->onClick = [this, b] { setHere (b == &setStart ? 0 : b == &setEnd ? 1 : b == &setPosition ? 2 : 3); };
  2380. addAndMakeVisible (*b);
  2381. }
  2382. setStart.setTooltip (tr ("Set: the clip starts where it plays now"));
  2383. setEnd.setTooltip (tr ("Set: the clip ends where it plays now"));
  2384. setPosition.setTooltip (tr ("Set: the loop moves to start where the clip plays now"));
  2385. start.setTooltip (tr ("Start: where the clip starts playing in its source (with Loop on, a marker inside the loop; bar. beat. sixteenth; seconds for unwarped audio)"));
  2386. setLength.setTooltip (tr ("Set: the loop ends where the clip plays now"));
  2387. showingTimer = std::make_unique<ui::TimerWhileShowing> (*this, static_cast<juce::Timer&> (*this), 10);
  2388. // the Groove chooser: the project's Groove Pool (round 190bv), for MIDI clips (LYNX's grooves act on MIDI clips)
  2389. groove.onChange = [this] {
  2390. if (loading)
  2391. return;
  2392. const auto& pool = engine.getSong().grooves.grooves;
  2393. const auto index = groove.getSelectedId() - 2;
  2394. const auto id = index >= 0 && index < (int) pool.size() ? pool[(std::size_t) index].id : 0u;
  2395. engine.editSong ([t = track, sc = scene, id] (Song& s) { groove::setClipGroove (s, t, sc, id); });
  2396. };
  2397. addAndMakeVisible (groove);
  2398. // round 190kc: Live's Commit (manual 14.1.2): the groove written into the clip — MIDI notes moved, an audio clip's
  2399. // warp markers at its attacks — and the chooser back to None
  2400. commitGroove.setButtonText (tr ("Commit"));
  2401. commitGroove.setConnectedEdges (0);
  2402. commitGroove.setTooltip (tr ("Commit: writes the groove into the clip (MIDI: the notes move; audio: warp markers at its attacks) and sets the groove to None"));
  2403. commitGroove.onClick = [this] { commitClipGroove(); };
  2404. addAndMakeVisible (commitGroove);
  2405. signature.setFont (font (type::small));
  2406. signature.setColour (juce::Label::textColourId, colour::textPrimary);
  2407. signature.setTooltip (tr ("The project's time signature (clips have no signature of their own in LYNX SHARE)"));
  2408. addAndMakeVisible (signature);
  2409. loop.setButtonText (tr ("Loop"));
  2410. loop.onClick = [this] { editSlot ([on = loop.getToggleState()] (ClipGridSlot& slot) { slot.loop = on; }); };
  2411. // round gap190og (detail-019): Live 12's Clip panel "Duplicate" button under Start / End = Duplicate Loop [SHOT
  2412. // ableton187c/shots/live-01-velocity-lane.png; STR DuplicateLoop in Live's ClipRegionPanel; DOC manual 8.9]
  2413. duplicateLoop.setButtonText (tr ("Duplicate"));
  2414. duplicateLoop.setTooltip (tr ("Duplicate Loop: the loop and its notes twice as long; notes after the loop move on with its end"));
  2415. duplicateLoop.onClick = [this] { duplicateClipLoop(); };
  2416. addAndMakeVisible (duplicateLoop);
  2417. legato.setButtonText (tr ("Legato"));
  2418. legato.setTooltip (tr ("Legato (keep the position)"));
  2419. legato.onClick = [this] { editSlot ([on = legato.getToggleState()] (ClipGridSlot& slot) { slot.legato = on; }); };
  2420. for (auto* b : { &loop, &legato })
  2421. addAndMakeVisible (*b);
  2422. const char* modes[] = { TR_NOOP ("Trigger"), TR_NOOP ("Gate"), TR_NOOP ("Toggle"), TR_NOOP ("Repeat") };
  2423. for (int i = 0; i < 4; ++i)
  2424. mode.addItem (tr (modes[i]), i + 1);
  2425. mode.onChange = [this] { editSlot ([m = mode.getSelectedId() - 1] (ClipGridSlot& slot) { slot.mode = (LaunchMode) juce::jlimit (0, 3, m); }); };
  2426. const char* quants[] = { TR_NOOP ("Global"), TR_NOOP ("None"), TR_NOOP ("8 bars"), TR_NOOP ("4 bars"), TR_NOOP ("2 bars"), TR_NOOP ("1 bar"),
  2427. "1/2", "1/2T", "1/4", "1/4T", "1/8", "1/8T", "1/16", "1/16T", "1/32" };
  2428. for (int i = 0; i < 15; ++i)
  2429. quant.addItem (i < 6 ? tr (quants[i]) : juce::String (quants[i]), i + 1);
  2430. quant.onChange = [this] { editSlot ([q = quant.getSelectedId() - 1] (ClipGridSlot& slot) { slot.quant = (LaunchQuant) juce::jlimit (0, 14, q); }); };
  2431. for (auto* c : { &mode, &quant })
  2432. addAndMakeVisible (*c);
  2433. // round 190hr (detail-028): the Launch panel's Follow Action controls over the slot's follow action (the same model
  2434. // as the grid slot menu's Follow action submenu). Live 12's controls [STR live-exe-strings-u16.txt 2061-2075:
  2435. // Follow Action Enabled, A, B, Chance A, Chance B, Time, Linked, Multiplier, Jump Index A / B]
  2436. followOn.setButtonText (tr ("Follow Action"));
  2437. followOn.setClickingTogglesState (true);
  2438. followOn.setConnectedEdges (0);
  2439. followOn.setTooltip (tr ("Follow Action: after its time the clip launches another, A or B by their chances"));
  2440. followOn.onClick = [this] { editFollow ([on = followOn.getToggleState()] (ClipFollow& f) { f.enabled = on; }); };
  2441. linked.setButtonText (tr ("Linked"));
  2442. linked.setClickingTogglesState (true);
  2443. linked.setConnectedEdges (0);
  2444. linked.setTooltip (tr ("Linked: the follow action comes after the clip has played Multiplier times; off: after the Time"));
  2445. linked.onClick = [this] { editFollow ([on = linked.getToggleState()] (ClipFollow& f) { f.linked = on; }); };
  2446. for (auto* b : { &followOn, &linked })
  2447. addAndMakeVisible (*b);
  2448. const std::pair<FollowKind, const char*> actions[] = {
  2449. { FollowKind::none, TR_NOOP ("No action") }, { FollowKind::stop, TR_NOOP ("Stop") }, { FollowKind::playAgain, TR_NOOP ("Play again") },
  2450. { FollowKind::previous, TR_NOOP ("Previous") }, { FollowKind::next, TR_NOOP ("Next") }, { FollowKind::first, TR_NOOP ("First") },
  2451. { FollowKind::last, TR_NOOP ("Last") }, { FollowKind::any, TR_NOOP ("Any") }, { FollowKind::other, TR_NOOP ("Other") },
  2452. { FollowKind::jump, TR_NOOP ("Jump") }
  2453. };
  2454. for (auto* box : { &followA, &followB })
  2455. {
  2456. for (const auto& [k, text] : actions)
  2457. box->addItem (tr (text), (int) k + 1);
  2458. box->setTooltip (box == &followA ? tr ("Follow Action A") : tr ("Follow Action B"));
  2459. box->onChange = [this, box] {
  2460. if (loading || box->getSelectedId() < 1)
  2461. return;
  2462. const auto k = (FollowKind) (box->getSelectedId() - 1);
  2463. editFollow ([k, isA = box == &followA] (ClipFollow& f) { (isA ? f.a : f.b) = k; });
  2464. };
  2465. addAndMakeVisible (*box);
  2466. }
  2467. const auto numberBox = [this] (std::unique_ptr<ui::NumBox>& box, const juce::String& name, double lo, double hi, std::function<juce::String (double)> text,
  2468. std::function<double (const ClipFollow&)> get, std::function<void (ClipFollow&, int)> set) {
  2469. ui::ValueSpec spec;
  2470. spec.name = name;
  2471. spec.minimum = lo;
  2472. spec.maximum = hi;
  2473. spec.interval = 1.0;
  2474. spec.pixelsForRange = std::min (300.0, (hi - lo) * 4.0);
  2475. spec.toText = std::move (text);
  2476. box = std::make_unique<ui::NumBox> (spec, [this, get] { const auto* f = follow(); return f != nullptr ? get (*f) : 0.0; },
  2477. [this, set] (double v) { editFollow ([set, v] (ClipFollow& f) { set (f, juce::roundToInt (v)); }); });
  2478. addAndMakeVisible (*box);
  2479. };
  2480. const auto percent = [] (double v) { return juce::String (juce::roundToInt (v)) + " %"; };
  2481. numberBox (chanceA, tr ("Follow Action Chance A"), 0, 100, percent, [] (const ClipFollow& f) { return (double) f.chanceA; }, [] (ClipFollow& f, int v) { f.chanceA = v; });
  2482. numberBox (chanceB, tr ("Follow Action Chance B"), 0, 100, percent, [] (const ClipFollow& f) { return (double) f.chanceB; }, [] (ClipFollow& f, int v) { f.chanceB = v; });
  2483. numberBox (multiplier, tr ("Follow Action Multiplier"), 1, 64, [] (double v) { return juce::String::fromUTF8 ("\xc3\x97") + juce::String (juce::roundToInt (v)); },
  2484. [] (const ClipFollow& f) { return (double) f.iterations; }, [] (ClipFollow& f, int v) { f.iterations = std::max (1, v); });
  2485. const auto scene = [] (double v) { return juce::String (juce::roundToInt (v)); };
  2486. numberBox (jumpA, tr ("Follow Action Jump Index A"), 1, launcher::maxScenes, scene, [] (const ClipFollow& f) { return (double) f.jumpA + 1; }, [] (ClipFollow& f, int v) { f.jumpA = std::max (0, v - 1); });
  2487. numberBox (jumpB, tr ("Follow Action Jump Index B"), 1, launcher::maxScenes, scene, [] (const ClipFollow& f) { return (double) f.jumpB + 1; }, [] (ClipFollow& f, int v) { f.jumpB = std::max (0, v - 1); });
  2488. followTime.setFont (font (type::small));
  2489. followTime.setTooltip (tr ("Follow Action Time (bars. beats. sixteenths): with Linked off, the follow action comes after this time"));
  2490. followTime.onReturnKey = [this] { applyFollowTime(); };
  2491. followTime.onFocusLost = [this] { applyFollowTime(); };
  2492. followTime.onEscapeKey = [this] { load(); };
  2493. addAndMakeVisible (followTime);
  2494. for (auto* l : { &followTitle })
  2495. {
  2496. l->setFont (font (type::small, true));
  2497. l->setColour (juce::Label::textColourId, colour::textSecondary);
  2498. l->setText (tr ("Follow Action"), juce::dontSendNotification);
  2499. addAndMakeVisible (*l);
  2500. }
  2501. // the reference's note tools, each the Piano roll's own operation on every note of the clip's pattern
  2502. const std::pair<juce::TextButton*, const char*> tools[] = {
  2503. { &invert, TR_NOOP ("Invert") }, { &reverse, TR_NOOP ("Reverse") }, { &makeLegato, TR_NOOP ("Make legato") },
  2504. { &humanize, TR_NOOP ("Humanize") }, { &duplicate, TR_NOOP ("Duplicate") }, { &quantize, TR_NOOP ("Quantize") },
  2505. { &randomize, TR_NOOP ("Randomize velocity") } };
  2506. for (const auto& [b, text] : tools)
  2507. {
  2508. b->setButtonText (tr (text));
  2509. b->setConnectedEdges (0);
  2510. addAndMakeVisible (*b);
  2511. }
  2512. invert.onClick = [this] { notes ([] (Pattern& p, const std::vector<int>& all, const Song&) { notetools::flip (p, all, false, true); }); };
  2513. reverse.onClick = [this] { notes ([] (Pattern& p, const std::vector<int>& all, const Song&) { notetools::flip (p, all, true, false); }); };
  2514. makeLegato.onClick = [this] { notes ([] (Pattern& p, const std::vector<int>& all, const Song&) { noteedit::legato (p, all); }); };
  2515. humanize.onClick = [this] {
  2516. notes ([seed = (std::uint32_t) juce::Random::getSystemRandom().nextInt()] (Pattern& p, const std::vector<int>& all, const Song&) {
  2517. notetools::HumanizeOptions o;
  2518. o.seed = seed;
  2519. notetools::humanize (p, all, o);
  2520. });
  2521. };
  2522. duplicate.onClick = [this] { notes ([] (Pattern& p, const std::vector<int>& all, const Song& song) { noteedit::duplicateBars (p, all, song.meter()); }); };
  2523. quantize.onClick = [this] { notes ([] (Pattern& p, const std::vector<int>& all, const Song&) { noteedit::quantize (p, all, ppq / 4); }); };
  2524. randomize.onClick = [this] {
  2525. notes ([seed = (std::uint32_t) juce::Random::getSystemRandom().nextInt()] (Pattern& p, const std::vector<int>& all, const Song&) {
  2526. notetools::RandomiseOptions o;
  2527. o.velocity = 0.5f; // ±0.25 as before round 190ez halved the randomizer's law to FL's
  2528. o.seed = seed;
  2529. notetools::randomise (p, all, o);
  2530. });
  2531. };
  2532. // Live's Stretch ×2 and /2 and Fit to Scale [LIVE 12.4 Clip View, Pitch & Time] (round 190o)
  2533. timesTwo.setButtonText (juce::String::fromUTF8 ("\xc3\x97" "2"));
  2534. divideTwo.setButtonText (juce::String::fromUTF8 ("\xc3\xb7" "2"));
  2535. fitScale.setButtonText (tr ("Fit to scale"));
  2536. timesTwo.setTooltip (tr ("Twice as slow: doubles every note's start and length"));
  2537. divideTwo.setTooltip (tr ("Twice as fast: halves every note's start and length"));
  2538. fitScale.setTooltip (tr ("Moves every note of the clip onto the clip's scale"));
  2539. for (auto* b : { &timesTwo, &divideTwo, &fitScale })
  2540. {
  2541. b->setConnectedEdges (0);
  2542. addAndMakeVisible (*b);
  2543. }
  2544. // LYNX's Chord helper (round 190mc, discussion #105): the docked editor's selection, in Live's look
  2545. chordHelper.setButtonText (tr ("Chord helper"));
  2546. chordHelper.setTooltip (tr ("Select a chord: related keys and borrowed chords to insert after it"));
  2547. chordHelper.setConnectedEdges (0);
  2548. chordHelper.onClick = [this] {
  2549. if (editorOf)
  2550. if (auto* roll = editorOf())
  2551. roll->openChordHelper();
  2552. };
  2553. addAndMakeVisible (chordHelper);
  2554. const auto stretch = [this] (bool twice) {
  2555. notes ([twice] (Pattern& p, const std::vector<int>& all, const Song&) {
  2556. for (auto i : all)
  2557. {
  2558. auto& n = p.notes[(std::size_t) i];
  2559. n.start = twice ? n.start * 2 : n.start / 2;
  2560. n.length = std::max<std::int64_t> (1, twice ? n.length * 2 : n.length / 2);
  2561. }
  2562. if (p.lengthTicks > 0)
  2563. p.lengthTicks = std::max<std::int64_t> (1, twice ? p.lengthTicks * 2 : p.lengthTicks / 2);
  2564. });
  2565. };
  2566. timesTwo.onClick = [stretch] { stretch (true); };
  2567. divideTwo.onClick = [stretch] { stretch (false); };
  2568. fitScale.onClick = [this] {
  2569. notes ([key = clipKeyOf (engine.getSong())] (Pattern& p, const std::vector<int>& all, const Song&) {
  2570. if (key && projectkey::lynxScale (*key) > 0)
  2571. notetools::snapNotesToScale (p, all, key->root, projectkey::lynxScale (*key));
  2572. });
  2573. };
  2574. // the Clip panel's Scale row (round 190hr, detail-022): the clip's own scale, as Live's Clip Scale [SHOT
  2575. // live190gu/warp/live-clipview-beats-defaults-full.png, ableton190o/shots/live-02-clipview-scale-bhairav.png: the
  2576. // Scale Mode switch, the root and the scale name]. A clip follows the project key until its row is changed.
  2577. scaleMode.setButtonText (juce::String::fromUTF8 ("\xe2\x99\xad\xe2\x99\xaf")); // (flat sharp, Live's switch)
  2578. scaleMode.setClickingTogglesState (true);
  2579. scaleMode.setConnectedEdges (0);
  2580. scaleMode.setTooltip (tr ("Scale Mode: the clip's notes, editor and tools follow the clip's scale"));
  2581. scaleMode.onClick = [this] { editClip ([on = scaleMode.getToggleState()] (Clip&, ClipGridSlot& slot) { slot.scaleOn = on; }); };
  2582. addAndMakeVisible (scaleMode);
  2583. for (int root = 0; root < 12; ++root)
  2584. scaleRoot.addItem (juce::String (projectkey::rootName (root)), root + 1);
  2585. for (auto index : projectkey::commonFirst())
  2586. scaleName.addItem (tr (notetools::flReferenceScales()[(std::size_t) index].name), index + 1);
  2587. for (auto* c : { &scaleRoot, &scaleName })
  2588. {
  2589. c->setTooltip (tr ("The clip's scale: its root and name (a new clip follows the project's key)"));
  2590. addAndMakeVisible (*c);
  2591. c->onChange = [this] {
  2592. if (loading || scaleRoot.getSelectedId() < 1)
  2593. return;
  2594. const auto root = scaleRoot.getSelectedId() - 1;
  2595. const auto index = scaleName.getSelectedId() >= 1 ? scaleName.getSelectedId() - 1 : projectkey::commonFirst().front();
  2596. editClip ([root, index] (Clip&, ClipGridSlot& slot) {
  2597. slot.ownScale = true;
  2598. slot.scaleRoot = (std::int8_t) root;
  2599. slot.scaleIndex = (std::int16_t) index;
  2600. });
  2601. };
  2602. }
  2603. engine.addChangeListener (this);
  2604. }
  2605. ~ClipColumn() override { engine.removeChangeListener (this); }
  2606. // the reference's Clip / Launch / Notes panels side by side under the clip's name [SHOT d08]
  2607. static constexpr int clipPanel = 164, clipPanel2 = 164, launchPanel = 136, followPanel = 144, notesPanel = 172, gap = 8;
  2608. static constexpr int foldedTools = 20;
  2609. int preferredWidth() const
  2610. {
  2611. if (theme::livelook::active()) // (round 190jn: Live's 170 px column + its 2 px separator; the MIDI Tools stay at its right)
  2612. return liveclip::columnWidth + 2 + (hasNotes ? gap + (toolsFolded ? foldedTools : MidiToolsPanel::panelWidth) + gap : 0);
  2613. return gap + clipPanel + gap + clipPanel2 + gap + launchPanel + gap + followPanel + gap + (hasNotes ? notesPanel + gap + (toolsFolded ? foldedTools : MidiToolsPanel::panelWidth) + gap : 0);
  2614. }
  2615. // the docked Piano roll (nullptr while it is not docked here): the MIDI Tools work on its selection
  2616. std::function<PianoRollComponent*()> editorOf;
  2617. MidiToolsPanel& midiTools() noexcept { return tools; }
  2618. static inline bool toolsFolded = false; // UI only, not saved
  2619. void setSlot (int t, int s)
  2620. {
  2621. if (t != track || s != scene)
  2622. transposed = 0; // (the pitch range's drag counts from this clip as it is)
  2623. track = t;
  2624. scene = s;
  2625. load();
  2626. }
  2627. void paint (juce::Graphics& g) override
  2628. {
  2629. if (liveShown)
  2630. {
  2631. paintLive (g);
  2632. return;
  2633. }
  2634. g.fillAll (colour::bg2);
  2635. g.setColour (colour::border);
  2636. g.fillRect (getWidth() - 1, 0, 1, getHeight());
  2637. }
  2638. void resized() override
  2639. {
  2640. applyLook();
  2641. if (liveShown)
  2642. {
  2643. resizedLive();
  2644. return;
  2645. }
  2646. auto r = getLocalBounds().reduced (gap, 4).withTrimmedRight (1);
  2647. const auto take = [] (juce::Rectangle<int>& area, int h) { auto x = area.removeFromTop (h); area.removeFromTop (3); return x; };
  2648. if (hasNotes)
  2649. {
  2650. // Transform: the whole height at the right; folded, only its button
  2651. auto t = r.removeFromRight (toolsFolded ? foldedTools : MidiToolsPanel::panelWidth);
  2652. r.removeFromRight (gap);
  2653. foldTools.setBounds (t.getRight() - 18, t.getY(), 18, 16);
  2654. tools.setBounds (t);
  2655. }
  2656. clipTitle.setBounds (take (r, 16));
  2657. auto top = take (r, 20);
  2658. chip.setBounds (top.removeFromLeft (20));
  2659. top.removeFromLeft (6);
  2660. nameLabel.setBounds (top.removeFromLeft (44));
  2661. name.setBounds (top);
  2662. r.removeFromTop (2);
  2663. // Clip: Start | End, Loop, Length | Signature
  2664. auto c = r.removeFromLeft (clipPanel);
  2665. r.removeFromLeft (gap);
  2666. const auto halves = [] (juce::Rectangle<int> row, juce::Component& a, juce::Component& b) {
  2667. const auto w = (row.getWidth() - 6) / 2;
  2668. a.setBounds (row.removeFromLeft (w));
  2669. row.removeFromLeft (6);
  2670. b.setBounds (row);
  2671. };
  2672. {
  2673. // Start [Set] | End [Set]
  2674. auto row = take (c, 16);
  2675. const auto w = (row.getWidth() - 6) / 2;
  2676. auto a = row.removeFromLeft (w);
  2677. row.removeFromLeft (6);
  2678. setStart.setBounds (a.removeFromRight (30));
  2679. startLabel.setBounds (a);
  2680. setEnd.setBounds (row.removeFromRight (30));
  2681. endLabel.setBounds (row);
  2682. }
  2683. halves (take (c, 20), start, end);
  2684. loop.setBounds (take (c, 20));
  2685. {
  2686. // Position [Set] | Length [Set]
  2687. auto row = take (c, 16);
  2688. const auto w = (row.getWidth() - 6) / 2;
  2689. auto a = row.removeFromLeft (w);
  2690. row.removeFromLeft (6);
  2691. setPosition.setBounds (a.removeFromRight (30));
  2692. positionLabel.setBounds (a);
  2693. setLength.setBounds (row.removeFromRight (30));
  2694. lengthLabel.setBounds (row);
  2695. }
  2696. halves (take (c, 20), position, length);
  2697. // Signature | Groove, then Scale: a second column beside them (Live stacks them below; the dock is lower)
  2698. auto c2 = r.removeFromLeft (clipPanel2);
  2699. r.removeFromLeft (gap);
  2700. halves (take (c2, 14), signatureLabel, grooveLabel);
  2701. commitGroove.setBounds (grooveLabel.getBounds().removeFromRight (46).withTrimmedTop (1)); // (round 190kc)
  2702. halves (take (c2, 20), signature, groove);
  2703. scaleLabel.setBounds (take (c2, 14));
  2704. {
  2705. auto row = take (c2, 20);
  2706. scaleMode.setBounds (row.removeFromLeft (22));
  2707. row.removeFromLeft (3);
  2708. const auto w = (row.getWidth() - 4) * 2 / 5;
  2709. scaleRoot.setBounds (row.removeFromLeft (w));
  2710. row.removeFromLeft (4);
  2711. scaleName.setBounds (row);
  2712. }
  2713. // Launch: mode, quantisation, legato
  2714. auto l = r.removeFromLeft (launchPanel);
  2715. r.removeFromLeft (gap);
  2716. launchTitle.setBounds (take (l, 14));
  2717. modeLabel.setBounds (take (l, 12));
  2718. mode.setBounds (take (l, 20));
  2719. quantLabel.setBounds (take (l, 12));
  2720. quant.setBounds (take (l, 20));
  2721. legato.setBounds (take (l, 20));
  2722. // Follow Action (round 190hr): the switch; A | B with their jump targets; the chances; Linked with the
  2723. // multiplier; the time
  2724. auto f = r.removeFromLeft (followPanel);
  2725. r.removeFromLeft (gap);
  2726. followTitle.setBounds (take (f, 14));
  2727. followOn.setBounds (take (f, 18));
  2728. halves (take (f, 20), followA, followB);
  2729. {
  2730. auto row = take (f, 18);
  2731. const auto w = (row.getWidth() - 6) / 2;
  2732. auto a = row.removeFromLeft (w);
  2733. row.removeFromLeft (6);
  2734. jumpA->setBounds (a.removeFromRight (jumpA->isVisible() ? 30 : 0));
  2735. chanceA->setBounds (a.withTrimmedRight (jumpA->isVisible() ? 3 : 0));
  2736. jumpB->setBounds (row.removeFromRight (jumpB->isVisible() ? 30 : 0));
  2737. chanceB->setBounds (row.withTrimmedRight (jumpB->isVisible() ? 3 : 0));
  2738. }
  2739. halves (take (f, 18), linked, *multiplier);
  2740. followTime.setBounds (take (f, 18));
  2741. // Notes: the note tools, two columns
  2742. auto n = r.removeFromLeft (notesPanel);
  2743. notesTitle.setBounds (take (n, 14));
  2744. // six rows of two (round 190s): the pitch range | Invert; Reverse | Make legato; Humanize | Quantize; x2 /2 |
  2745. // Fit to scale; the interval size | Add interval; Duplicate | Randomize velocity (the wider one)
  2746. const auto w = (n.getWidth() - 4) / 2;
  2747. const auto cell = [&n, w] (int row, int col) { return juce::Rectangle<int> (n.getX() + col * (w + 4), n.getY() + row * 22, w, 19); };
  2748. pitchRange->setBounds (cell (0, 0));
  2749. invert.setBounds (cell (0, 1));
  2750. reverse.setBounds (cell (1, 0));
  2751. makeLegato.setBounds (cell (1, 1));
  2752. humanize.setBounds (cell (2, 0));
  2753. quantize.setBounds (cell (2, 1));
  2754. const auto small = (w - 4) / 2;
  2755. timesTwo.setBounds (cell (3, 0).withWidth (small));
  2756. divideTwo.setBounds (cell (3, 0).withTrimmedLeft (small + 4));
  2757. fitScale.setBounds (cell (3, 1));
  2758. intervalSize->setBounds (cell (4, 0));
  2759. addInterval.setBounds (cell (4, 1));
  2760. duplicate.setBounds (cell (5, 0).withWidth (60));
  2761. randomize.setBounds (cell (5, 0).withTrimmedLeft (64).withRight (n.getRight()));
  2762. chordHelper.setBounds (cell (6, 0).withRight (n.getRight()));
  2763. }
  2764. void reload() { load(); } // (the page docked an editor: it gets the column's hooks)
  2765. // --- round 190jn (design190ia CL-20a / CL-20b): Live 12.4's Clip View column ----------------------------------------
  2766. // A 170 px column (live-clipview-audio.png 249..418, live-01-clipview-notes.png 9..178): the 17 px title bar in the
  2767. // clip's colour (the activator square, the name in colour × 0.24) stays; under it Live's sections, each a 17 px #464646
  2768. // header (click: fold / unfold) over its rows — Clip; Launch (with LYNX's Follow Action, as Live 12 puts it there;
  2769. // folded at first, as Live shows it); for MIDI clips Pitch & Time (LYNX's note tools). Rows are 13 px fields and pills.
  2770. // When the open sections are taller than the view, the wheel scrolls them under the title bar (Live does the same).
  2771. // The fold states are UI state, not saved. The MIDI Tools (Transform / Generate) stay at the column's right.
  2772. static inline bool clipOpen = true, launchOpen = false, notesOpen = true;
  2773. bool isLive() const noexcept { return liveShown; }
  2774. void setScrollForSnapshot (int y)
  2775. {
  2776. scrollY = y;
  2777. resized();
  2778. repaint();
  2779. }
  2780. void mouseDown (const juce::MouseEvent& e) override
  2781. {
  2782. if (! liveShown || e.x >= liveclip::columnWidth)
  2783. return;
  2784. for (int k = 0; k < 3; ++k)
  2785. if (headerY[(std::size_t) k] >= liveclip::headerHeight && e.y >= headerY[(std::size_t) k] && e.y < headerY[(std::size_t) k] + liveclip::headerHeight)
  2786. {
  2787. auto& open = k == 0 ? clipOpen : k == 1 ? launchOpen : notesOpen;
  2788. open = ! open;
  2789. resized();
  2790. repaint();
  2791. return;
  2792. }
  2793. }
  2794. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  2795. {
  2796. if (! liveShown || e.x >= liveclip::columnWidth)
  2797. {
  2798. juce::Component::mouseWheelMove (e, wheel);
  2799. return;
  2800. }
  2801. const auto before = scrollY;
  2802. scrollY = juce::jlimit (0, maxScroll(), scrollY - juce::roundToInt (wheel.deltaY * 120.0f));
  2803. if (scrollY != before)
  2804. {
  2805. resized();
  2806. repaint();
  2807. }
  2808. }
  2809. private:
  2810. bool liveShown = false;
  2811. int scrollY = 0, contentHeight = 0;
  2812. std::array<int, 3> headerY {}; // the sections' header tops (Clip, Launch, Pitch & Time; < 17: not shown)
  2813. juce::Colour titleColour { colour::bg5 };
  2814. int maxScroll() const { return std::max (0, contentHeight - getHeight()); }
  2815. std::vector<juce::Component*> styledChildren()
  2816. {
  2817. return { &start, &end, &position, &length, &followTime, &setStart, &setEnd, &setPosition, &setLength, &followOn, &linked, &invert, &reverse,
  2818. &makeLegato, &humanize, &duplicate, &quantize, &randomize, &timesTwo, &divideTwo, &fitScale, &chordHelper, &addInterval, &scaleMode, &groove, &mode,
  2819. &quant, &followA, &followB, &scaleRoot, &scaleName, &loop, &duplicateLoop, &legato, &nameLabel, &startLabel, &endLabel, &lengthLabel,
  2820. &positionLabel, &grooveLabel, &signatureLabel, &modeLabel, &quantLabel, &scaleLabel, &signature, &commitGroove };
  2821. }
  2822. // the look follows the layout's switch (checked on every layout and load; nothing changes while it stays the same)
  2823. void applyLook()
  2824. {
  2825. const auto live = theme::livelook::active();
  2826. if (live == liveShown)
  2827. return;
  2828. liveShown = live;
  2829. for (auto* c : styledChildren())
  2830. liveclip::style (*c, live);
  2831. for (auto* l : { &clipTitle, &launchTitle, &notesTitle, &followTitle, &nameLabel })
  2832. l->setVisible (! live);
  2833. nameColours();
  2834. if (! live)
  2835. scrollY = 0;
  2836. }
  2837. // the name sits on the title bar in the clip's ink (Live: colour × 0.24)
  2838. void nameColours()
  2839. {
  2840. const auto ink = liveMarkOn (titleColour, 0.24f, 4.5f, colour::textPrimary); // (round 190oj: readable on dark clip colours too)
  2841. liveclip::swapColour (name, juce::TextEditor::backgroundColourId, juce::Colours::transparentBlack, liveShown);
  2842. liveclip::swapColour (name, juce::TextEditor::outlineColourId, juce::Colours::transparentBlack, liveShown);
  2843. liveclip::swapColour (name, juce::TextEditor::textColourId, ink, liveShown);
  2844. if (liveShown)
  2845. name.setColour (juce::TextEditor::textColourId, ink);
  2846. name.applyColourToAllText (name.findColour (juce::TextEditor::textColourId), true);
  2847. name.setTextToShowWhenEmpty (nameFallback, name.findColour (juce::TextEditor::textColourId)); // (round 190oj CS-33)
  2848. }
  2849. void paintLive (juce::Graphics& g)
  2850. {
  2851. namespace ll = theme::livelook;
  2852. const auto w = liveclip::columnWidth;
  2853. g.fillAll (ll::window);
  2854. g.setColour (ll::surface);
  2855. g.fillRect (0, 0, w, getHeight());
  2856. g.setColour (ll::separator);
  2857. g.fillRect (w, 0, 2, getHeight());
  2858. {
  2859. juce::Graphics::ScopedSaveState save (g);
  2860. g.reduceClipRegion (0, liveclip::headerHeight + 1, w, getHeight());
  2861. const char* titles[] { TR_NOOP ("Clip"), TR_NOOP ("Launch"), TR_NOOP ("Pitch & Time") };
  2862. const bool open[] { clipOpen, launchOpen, notesOpen };
  2863. for (int k = 0; k < 3; ++k)
  2864. if (k < 2 || hasNotes)
  2865. liveclip::paintHeader (g, { 0, headerY[(std::size_t) k], w, liveclip::headerHeight }, tr (titles[k]), k == 2 ? 3 : k, open[k]);
  2866. }
  2867. g.setColour (titleColour);
  2868. g.fillRect (0, 0, w, liveclip::headerHeight);
  2869. g.setColour (ll::separator);
  2870. g.fillRect (0, liveclip::headerHeight, w, 1);
  2871. }
  2872. void resizedLive()
  2873. {
  2874. const auto w = liveclip::columnWidth;
  2875. const auto top = liveclip::headerHeight + 1;
  2876. const int row = liveclip::row, x0 = 11, inner = w - 22, half = (inner - 4) / 2;
  2877. // a child goes where the layout puts it while that is wholly under the title bar and in view; else it hides
  2878. const auto put = [this, top] (juce::Component& c, juce::Rectangle<int> r) {
  2879. c.setBounds (r.getY() >= top && r.getBottom() <= getHeight() ? r : juce::Rectangle<int>());
  2880. };
  2881. const auto hide = [] (std::initializer_list<juce::Component*> list) {
  2882. for (auto* c : list)
  2883. c->setBounds ({});
  2884. };
  2885. chip.setBounds (2, 2, 13, 13);
  2886. name.setBounds (17, 1, w - 21, 15);
  2887. for (auto* l : { &clipTitle, &launchTitle, &notesTitle, &followTitle, &nameLabel })
  2888. l->setBounds ({});
  2889. if (hasNotes)
  2890. {
  2891. auto t = getLocalBounds().withTrimmedLeft (w + 2 + gap).withTrimmedRight (gap).reduced (0, 4);
  2892. foldTools.setBounds (t.getRight() - 18, t.getY(), 18, 16);
  2893. tools.setBounds (t.withWidth (toolsFolded ? foldedTools : MidiToolsPanel::panelWidth).withRightX (t.getRight()));
  2894. }
  2895. int y = top - scrollY;
  2896. const auto labelRow = [&] (juce::Component& a, juce::Component* set, int x, int width) {
  2897. put (a, { x, y, width - (set != nullptr ? 24 : 0), row });
  2898. if (set != nullptr)
  2899. put (*set, { x + width - 22, y + 1, 22, row - 2 });
  2900. };
  2901. // Clip
  2902. headerY[0] = y;
  2903. y += liveclip::headerHeight + 1;
  2904. if (clipOpen)
  2905. {
  2906. y += 4;
  2907. labelRow (startLabel, &setStart, x0, half);
  2908. labelRow (endLabel, &setEnd, x0 + half + 4, half);
  2909. y += row + 1;
  2910. put (start, { x0, y, half, row });
  2911. put (end, { x0 + half + 4, y, half, row });
  2912. y += row + 5;
  2913. if (hasNotes) // (round gap190og, detail-019: Live's Duplicate button between the Start / End fields and Loop)
  2914. {
  2915. put (duplicateLoop, { x0, y, inner, row });
  2916. y += row + 5;
  2917. }
  2918. else
  2919. duplicateLoop.setBounds ({});
  2920. put (loop, { x0, y, inner, row });
  2921. y += row + 5;
  2922. labelRow (positionLabel, &setPosition, x0, half);
  2923. labelRow (lengthLabel, &setLength, x0 + half + 4, half);
  2924. y += row + 1;
  2925. put (position, { x0, y, half, row });
  2926. put (length, { x0 + half + 4, y, half, row });
  2927. y += row + 5;
  2928. put (signatureLabel, { x0, y, half, row });
  2929. put (grooveLabel, { x0 + half + 4, y, half - 16, row });
  2930. put (commitGroove, { x0 + 2 * half + 4 - 14, y, 14, row }); // (round 190kc: Live's round well)
  2931. y += row + 1;
  2932. put (signature, { x0, y, half, row });
  2933. put (groove, { x0 + half + 4, y, half, row });
  2934. y += row + 5;
  2935. put (scaleLabel, { x0, y, inner, row });
  2936. y += row + 1;
  2937. put (scaleMode, { x0, y, 18, row });
  2938. put (scaleRoot, { x0 + 21, y, 50, row });
  2939. put (scaleName, { x0 + 74, y, inner - 74, row });
  2940. y += row + 6;
  2941. }
  2942. else
  2943. hide ({ &startLabel, &setStart, &endLabel, &setEnd, &start, &end, &loop, &duplicateLoop, &positionLabel, &setPosition, &lengthLabel, &setLength, &position,
  2944. &length, &signatureLabel, &grooveLabel, &signature, &groove, &scaleLabel, &scaleMode, &scaleRoot, &scaleName, &commitGroove });
  2945. // Launch (+ Follow Action)
  2946. headerY[1] = y;
  2947. y += liveclip::headerHeight + 1;
  2948. if (launchOpen)
  2949. {
  2950. y += 4;
  2951. put (modeLabel, { x0, y, inner, row });
  2952. y += row + 1;
  2953. put (mode, { x0, y, inner, row });
  2954. y += row + 5;
  2955. put (quantLabel, { x0, y, inner, row });
  2956. y += row + 1;
  2957. put (quant, { x0, y, inner, row });
  2958. y += row + 5;
  2959. put (legato, { x0, y, inner, row });
  2960. y += row + 5;
  2961. put (followOn, { x0, y, inner, row });
  2962. y += row + 4;
  2963. put (followA, { x0, y, half, row });
  2964. put (followB, { x0 + half + 4, y, half, row });
  2965. y += row + 4;
  2966. {
  2967. const auto jw = 26;
  2968. put (*jumpA, { x0 + half - (jumpA->isVisible() ? jw : 0), y, jumpA->isVisible() ? jw : 0, row });
  2969. put (*chanceA, { x0, y, half - (jumpA->isVisible() ? jw + 3 : 0), row });
  2970. put (*jumpB, { x0 + inner - (jumpB->isVisible() ? jw : 0), y, jumpB->isVisible() ? jw : 0, row });
  2971. put (*chanceB, { x0 + half + 4, y, half - (jumpB->isVisible() ? jw + 3 : 0), row });
  2972. }
  2973. y += row + 4;
  2974. put (linked, { x0, y, half, row });
  2975. put (*multiplier, { x0 + half + 4, y, half, row });
  2976. y += row + 4;
  2977. put (followTime, { x0, y, inner, row });
  2978. y += row + 6;
  2979. }
  2980. else
  2981. hide ({ &modeLabel, &mode, &quantLabel, &quant, &legato, &followOn, &followA, &followB, jumpA.get(), chanceA.get(), jumpB.get(), chanceB.get(),
  2982. &linked, multiplier.get(), &followTime });
  2983. // Pitch & Time (MIDI clips): LYNX's note tools, two columns of 13 px pills
  2984. headerY[2] = hasNotes ? y : -1;
  2985. if (hasNotes)
  2986. {
  2987. y += liveclip::headerHeight + 1;
  2988. if (notesOpen)
  2989. {
  2990. y += 4;
  2991. const auto cell = [&] (int r, int c) { return juce::Rectangle<int> (x0 + c * (half + 4), y + r * (row + 4), half, row); };
  2992. put (*pitchRange, cell (0, 0));
  2993. put (invert, cell (0, 1));
  2994. put (reverse, cell (1, 0));
  2995. put (makeLegato, cell (1, 1));
  2996. put (humanize, cell (2, 0));
  2997. put (quantize, cell (2, 1));
  2998. const auto small = (half - 4) / 2;
  2999. put (timesTwo, cell (3, 0).withWidth (small));
  3000. put (divideTwo, cell (3, 0).withTrimmedLeft (small + 4));
  3001. put (fitScale, cell (3, 1));
  3002. put (*intervalSize, cell (4, 0));
  3003. put (addInterval, cell (4, 1));
  3004. put (duplicate, cell (5, 0));
  3005. put (randomize, cell (5, 1));
  3006. put (chordHelper, cell (6, 0).withRight (cell (6, 1).getRight()));
  3007. y += 7 * (row + 4) + 4;
  3008. }
  3009. else
  3010. hide ({ pitchRange.get(), &invert, &reverse, &makeLegato, &humanize, &quantize, &timesTwo, &divideTwo, &fitScale, intervalSize.get(),
  3011. &addInterval, &duplicate, &randomize, &chordHelper });
  3012. }
  3013. contentHeight = y + scrollY;
  3014. if (scrollY > maxScroll()) // (a section folded at the bottom: the column scrolls back)
  3015. {
  3016. scrollY = maxScroll();
  3017. resizedLive();
  3018. }
  3019. }
  3020. void changeListenerCallback (juce::ChangeBroadcaster*) override { load(); }
  3021. // the Set buttons are lit only while this clip plays
  3022. bool clipPlays (float* progress = nullptr) const
  3023. {
  3024. const auto* state = engine.launcherState();
  3025. if (state == nullptr || track < 0 || track >= launcher::maxTracks || clip() == nullptr)
  3026. return false;
  3027. const auto& view = state->tracks[(std::size_t) track];
  3028. if (view.playing.load (std::memory_order_relaxed) != scene || ! state->running.load (std::memory_order_relaxed))
  3029. return false;
  3030. if (progress != nullptr)
  3031. *progress = view.progress.load (std::memory_order_relaxed);
  3032. return true;
  3033. }
  3034. void timerCallback() override
  3035. {
  3036. const auto on = clipPlays();
  3037. for (auto* b : { &setStart, &setEnd })
  3038. if (b->isEnabled() != on)
  3039. b->setEnabled (on);
  3040. for (auto* b : { &setPosition, &setLength }) // (the loop's: only with Loop on)
  3041. if (b->isEnabled() != (on && loop.getToggleState()))
  3042. b->setEnabled (on && loop.getToggleState());
  3043. }
  3044. // 0 Start, 1 End, 2 Position, 3 Length (Length's Set ends the loop there: LYNX's loop ends where the clip does)
  3045. // round 190kc: Commit (the Clip box's button)
  3046. void commitClipGroove()
  3047. {
  3048. const auto& song = engine.getSong();
  3049. const auto* c = song.clipGrid ? launcher::clipAt (*song.clipGrid, track, scene) : nullptr;
  3050. if (c == nullptr)
  3051. return;
  3052. if (c->kind == ClipKind::pattern)
  3053. engine.editSong ([t = track, sc = scene] (Song& s) { groove::commit (s, t, sc); });
  3054. else if (c->kind == ClipKind::audio && c->channel >= 0 && c->channel < (int) song.channels.size())
  3055. if (const auto sample = engine.getSampleLibrary().load (juce::String::fromUTF8 (song.channels[(std::size_t) c->channel].samplePath.c_str())))
  3056. engine.editSong ([t = track, sc = scene, sample] (Song& s) { grooveaudio::commit (s, t, sc, *sample); });
  3057. }
  3058. void setHere (int which)
  3059. {
  3060. float progress = 0.0f;
  3061. if (! clipPlays (&progress))
  3062. return;
  3063. editClip ([which, progress] (Clip& c, ClipGridSlot& slot) {
  3064. const auto at = clipsample::playPosition (c, progress);
  3065. const auto marker = c.offset + (std::int64_t) launcher::startLead (slot, c.length);
  3066. if (which == 0 && slot.loop && at >= c.offset && at < c.offset + c.length)
  3067. slot.startMarker = at - c.offset; // (round 190hr: the Start marker inside the loop)
  3068. else if (which == 0)
  3069. {
  3070. clipsample::setStartAt (c, at);
  3071. slot.startMarker = 0;
  3072. }
  3073. else if (which == 2)
  3074. {
  3075. clipsample::setPositionAt (c, at);
  3076. slot.startMarker = marker >= c.offset && marker < c.offset + c.length ? marker - c.offset : 0;
  3077. }
  3078. else
  3079. {
  3080. clipsample::setEndAt (c, at);
  3081. if (slot.startMarker >= c.length)
  3082. slot.startMarker = 0;
  3083. }
  3084. });
  3085. }
  3086. // The clip's content is in seconds (an unwarped audio clip) rather than in beats
  3087. bool inSeconds (const Clip& c) const
  3088. {
  3089. const auto& song = engine.getSong();
  3090. return c.kind == ClipKind::audio && c.channel >= 0 && c.channel < (int) song.channels.size()
  3091. && ! clipsample::isWarped (song.channels[(std::size_t) c.channel].sampler);
  3092. }
  3093. juce::String fieldText (std::int64_t ticks, bool asLength, bool seconds) const
  3094. {
  3095. const auto& song = engine.getSong();
  3096. return juce::String (seconds ? clipsample::secondsText (ticks, song.bpm) : clipsample::positionText (ticks, song.meter(), asLength));
  3097. }
  3098. std::int64_t fieldTicks (const juce::TextEditor& ed, bool asLength, bool seconds) const
  3099. {
  3100. const auto& song = engine.getSong();
  3101. const auto text = ed.getText().trim().toStdString();
  3102. return seconds ? clipsample::parseSeconds (text, song.bpm) : clipsample::parsePosition (text, song.meter(), asLength);
  3103. }
  3104. // the grid clip of the slot (const) and its settings
  3105. const Clip* clip() const
  3106. {
  3107. const auto& song = engine.getSong();
  3108. return song.clipGrid && track >= 0 && scene >= 0 ? launcher::clipAt (*song.clipGrid, track, scene) : nullptr;
  3109. }
  3110. void load()
  3111. {
  3112. const auto* c = clip();
  3113. setVisible (c != nullptr);
  3114. if (c == nullptr)
  3115. return;
  3116. const auto& song = engine.getSong();
  3117. const auto bpb = song.beatsPerBar;
  3118. const ClipGridSlot* slot = c->gridSlot >= 0 && c->gridSlot < (int) song.clipGrid->slots.size() ? &song.clipGrid->slots[(std::size_t) c->gridSlot] : nullptr;
  3119. const auto n = juce::dontSendNotification;
  3120. if (! name.hasKeyboardFocus (false))
  3121. name.setText (slot != nullptr ? utf8 (slot->name) : juce::String(), false);
  3122. // round 190oj (CS-33): a clip without its own name shows the name the grid shows (its pattern's or its sample
  3123. // channel's) on the title band, as Live does, in the band's ink; typing gives the clip its own name
  3124. {
  3125. juce::String shownName;
  3126. if (slot == nullptr || ! slot->blankName)
  3127. {
  3128. if (c->kind == ClipKind::pattern && c->pattern >= 0 && c->pattern < (int) song.patterns.size())
  3129. shownName = utf8 (song.patterns[(std::size_t) c->pattern].name);
  3130. else if (c->kind == ClipKind::audio && c->channel >= 0 && c->channel < (int) song.channels.size())
  3131. shownName = utf8 (song.channels[(std::size_t) c->channel].name);
  3132. }
  3133. if (shownName != nameFallback)
  3134. {
  3135. nameFallback = shownName;
  3136. name.setTextToShowWhenEmpty (nameFallback, name.findColour (juce::TextEditor::textColourId));
  3137. }
  3138. }
  3139. const auto secs = inSeconds (*c);
  3140. const auto marker = slot != nullptr ? (std::int64_t) launcher::startLead (*slot, c->length) : 0;
  3141. if (! start.hasKeyboardFocus (false))
  3142. start.setText (fieldText (c->offset + marker, false, secs), false);
  3143. if (! end.hasKeyboardFocus (false))
  3144. end.setText (fieldText (c->offset + c->length, false, secs), false);
  3145. if (! position.hasKeyboardFocus (false))
  3146. position.setText (fieldText (c->offset, false, secs), false);
  3147. if (! length.hasKeyboardFocus (false))
  3148. length.setText (fieldText (c->length, true, secs), false);
  3149. signature.setText (juce::String (bpb) + " / " + juce::String (meterUnit (song.beatUnit)), n);
  3150. {
  3151. // the Groove chooser: None + the pool's grooves; MIDI clips only
  3152. const juce::ScopedValueSetter<bool> guard (loading, true);
  3153. groove.clear (n);
  3154. groove.addItem (tr ("None"), 1);
  3155. const auto& pool = song.grooves.grooves;
  3156. for (int i = 0; i < (int) pool.size(); ++i)
  3157. groove.addItem (utf8 (pool[(std::size_t) i].name), i + 2);
  3158. int selected = 1;
  3159. if (slot != nullptr && slot->groove != 0)
  3160. for (int i = 0; i < (int) pool.size(); ++i)
  3161. if (pool[(std::size_t) i].id == slot->groove)
  3162. selected = i + 2;
  3163. groove.setSelectedId (selected, n);
  3164. // (round 190kc: audio clips take a groove too, for Commit: LYNX plays grooves live on MIDI clips only)
  3165. groove.setEnabled (c->kind == ClipKind::pattern || c->kind == ClipKind::audio);
  3166. groove.setTooltip (c->kind == ClipKind::pattern ? tr ("The groove this clip plays through (the Groove Pool)")
  3167. : tr ("The groove for this audio clip: Commit writes it as warp markers (LYNX SHARE plays grooves live on MIDI clips only)"));
  3168. commitGroove.setEnabled (slot != nullptr && slot->groove != 0 && (c->kind == ClipKind::pattern || c->kind == ClipKind::audio));
  3169. }
  3170. if (slot != nullptr)
  3171. {
  3172. loop.setToggleState (slot->loop, n);
  3173. for (auto* ed : { &position, &length }) // (Live: the loop's fields are off with Loop off)
  3174. ed->setEnabled (slot->loop);
  3175. legato.setToggleState (slot->legato, n);
  3176. {
  3177. const juce::ScopedValueSetter<bool> guard (loading, true);
  3178. const auto& fa = slot->follow;
  3179. followOn.setToggleState (fa.enabled, n);
  3180. followA.setSelectedId ((int) fa.a + 1, n);
  3181. followB.setSelectedId ((int) fa.b + 1, n);
  3182. linked.setToggleState (fa.linked, n);
  3183. if (! followTime.hasKeyboardFocus (false))
  3184. followTime.setText (fieldText (fa.ticks, true, false), false);
  3185. followTime.setEnabled (! fa.linked);
  3186. multiplier->setEnabled (fa.linked);
  3187. const auto jumps = jumpA->isVisible() != (fa.a == FollowKind::jump) || jumpB->isVisible() != (fa.b == FollowKind::jump);
  3188. jumpA->setVisible (fa.a == FollowKind::jump);
  3189. jumpB->setVisible (fa.b == FollowKind::jump);
  3190. for (auto* box : { chanceA.get(), chanceB.get(), multiplier.get(), jumpA.get(), jumpB.get() })
  3191. box->repaint();
  3192. if (jumps)
  3193. resized();
  3194. }
  3195. mode.setSelectedId ((int) slot->mode + 1, n);
  3196. quant.setSelectedId ((int) slot->quant + 1, n);
  3197. }
  3198. const bool pattern = c->kind == ClipKind::pattern;
  3199. if (std::exchange (hasNotes, pattern) != pattern)
  3200. if (auto* parent = getParentComponent())
  3201. parent->resized();
  3202. for (auto* b : { &notesTitle })
  3203. b->setVisible (pattern);
  3204. for (auto* b : { &invert, &reverse, &makeLegato, &humanize, &duplicate, &quantize, &randomize, &timesTwo, &divideTwo, &fitScale, &addInterval, &chordHelper })
  3205. b->setVisible (pattern);
  3206. pitchRange->setVisible (pattern);
  3207. intervalSize->setVisible (pattern);
  3208. // the notes' lowest and highest pitch, as the reference's "C3 - C4" [LIVE 12.4 Pitch & Time]
  3209. juce::String newRange;
  3210. if (pattern && c->pattern >= 0 && c->pattern < (int) song.patterns.size() && ! song.patterns[(std::size_t) c->pattern].notes.empty())
  3211. {
  3212. const auto& all = song.patterns[(std::size_t) c->pattern].notes;
  3213. const auto [lo, hi] = std::minmax_element (all.begin(), all.end(), [] (const Note& a, const Note& b) { return a.key < b.key; });
  3214. newRange = juce::String (notenames::keyName (lo->key)) + " - " + juce::String (notenames::keyName (hi->key));
  3215. }
  3216. if (newRange != rangeText)
  3217. {
  3218. rangeText = newRange;
  3219. pitchRange->repaint();
  3220. }
  3221. auto fill = slot != nullptr && slot->colour != 0 ? juce::Colour (slot->colour)
  3222. : c->kind == ClipKind::audio ? colour::audioClip : tame (PlaylistComponent::patternColour (song, c->pattern));
  3223. chip.set (fill, ! c->muted);
  3224. applyLook();
  3225. if (fill != titleColour)
  3226. {
  3227. titleColour = fill;
  3228. if (liveShown)
  3229. {
  3230. nameColours();
  3231. repaint (0, 0, liveclip::columnWidth, liveclip::headerHeight);
  3232. }
  3233. }
  3234. {
  3235. const juce::ScopedValueSetter<bool> guard (loading, true);
  3236. const auto shown = slot != nullptr ? projectkey::clipScale (*slot, song) : projectkey::get (song);
  3237. // (round 190oj CS-34: with no key, Live's defaults "C" / "Major" with the switch off — before, the switch was lit
  3238. // over two empty choosers)
  3239. scaleRoot.setSelectedId (shown ? shown->root + 1 : 1, n);
  3240. scaleName.setSelectedId (shown ? shown->flScale + 1 : projectkey::commonFirst().front() + 1, n);
  3241. scaleMode.setToggleState (shown.has_value() && (slot == nullptr || slot->scaleOn), n);
  3242. for (auto* box : { &scaleRoot, &scaleName })
  3243. box->setEnabled (pattern);
  3244. scaleMode.setEnabled (pattern);
  3245. }
  3246. // round 190hr: the docked editor's Quantize keys use the MIDI Tools' Quantize tool (Live 12's Edit › Quantize /
  3247. // Quantize Settings…)
  3248. if (auto* roll = editorOf != nullptr ? editorOf() : nullptr)
  3249. {
  3250. const juce::Component::SafePointer<ClipColumn> safe (this);
  3251. roll->onLiveQuantize = [safe] {
  3252. if (safe != nullptr)
  3253. safe->tools.quantizeNow();
  3254. };
  3255. roll->onLiveQuantizeSettings = [safe] {
  3256. if (safe == nullptr)
  3257. return;
  3258. if (std::exchange (toolsFolded, false))
  3259. {
  3260. safe->load();
  3261. if (auto* parent = safe->getParentComponent())
  3262. parent->resized();
  3263. }
  3264. safe->tools.showQuantize();
  3265. };
  3266. }
  3267. const auto key = clipKeyOf (song);
  3268. // the docked editor shows the clip's scale (Live: the clip's Scale drives its editor), when it changes
  3269. if (auto* roll = editorOf != nullptr ? editorOf() : nullptr; roll != nullptr && pattern && key != shownKey)
  3270. {
  3271. shownKey = key;
  3272. roll->setScale (key ? key->root : 0, key ? projectkey::lynxScale (*key) : 0);
  3273. }
  3274. tools.setVisible (pattern && ! toolsFolded);
  3275. foldTools.setVisible (pattern);
  3276. foldTools.setButtonText (toolsFolded ? juce::String ("+") : juce::String::fromUTF8 ("\xe2\x88\x92")); // (+ / minus sign)
  3277. foldTools.toFront (false);
  3278. fitScale.setEnabled (key && projectkey::lynxScale (*key) > 0);
  3279. timerCallback(); // (the Set buttons)
  3280. }
  3281. // the clip's own fields (one undo step)
  3282. void apply()
  3283. {
  3284. const auto* c = clip();
  3285. if (c == nullptr)
  3286. return;
  3287. // the field that was typed in decides. Loop off: Start keeps the end, Position keeps the length. Loop on (round
  3288. // 190hr, Live's model): Start moves only the Start marker inside the loop; Position moves the loop and the Start
  3289. // marker stays where it is in the source; End / Length change the loop's end.
  3290. const auto secs = inSeconds (*c);
  3291. const auto& song0 = engine.getSong();
  3292. const auto* slot0 = c->gridSlot >= 0 && c->gridSlot < (int) song0.clipGrid->slots.size() ? &song0.clipGrid->slots[(std::size_t) c->gridSlot] : nullptr;
  3293. const auto looping = slot0 != nullptr && slot0->loop;
  3294. const auto marker0 = slot0 != nullptr ? (std::int64_t) launcher::startLead (*slot0, c->length) : 0;
  3295. const auto end0 = c->offset + c->length;
  3296. auto offset = c->offset, len = c->length;
  3297. auto marker = marker0;
  3298. if (start.getText() != fieldText (c->offset + marker0, false, secs))
  3299. {
  3300. if (const auto t = fieldTicks (start, false, secs); t >= 0 && t < end0)
  3301. {
  3302. if (looping && t >= c->offset)
  3303. marker = t - c->offset;
  3304. else
  3305. {
  3306. offset = t;
  3307. len = end0 - t;
  3308. marker = 0;
  3309. }
  3310. }
  3311. }
  3312. else if (position.getText() != fieldText (c->offset, false, secs))
  3313. {
  3314. if (const auto t = fieldTicks (position, false, secs); t >= 0)
  3315. {
  3316. offset = t;
  3317. const auto at = c->offset + marker0 - t; // (the Start marker keeps its place in the source)
  3318. marker = at >= 0 && at < len ? at : 0;
  3319. }
  3320. }
  3321. else if (end.getText() != fieldText (end0, false, secs))
  3322. {
  3323. if (const auto e = fieldTicks (end, false, secs); e > offset)
  3324. len = e - offset;
  3325. }
  3326. else if (length.getText() != fieldText (c->length, true, secs))
  3327. {
  3328. if (const auto t = fieldTicks (length, true, secs); t > 0)
  3329. len = t;
  3330. }
  3331. if (marker >= len)
  3332. marker = 0;
  3333. const auto newName = name.getText().trim().toStdString();
  3334. const int t = track, sc = scene;
  3335. engine.editSong ([t, sc, offset, len, marker, newName] (Song& song) {
  3336. if (! song.clipGrid)
  3337. return;
  3338. for (auto& clip : song.clipGrid->clips)
  3339. if (clip.track == t && clip.length > 0 && clip.gridSlot >= 0 && clip.gridSlot < (int) song.clipGrid->slots.size()
  3340. && song.clipGrid->slots[(std::size_t) clip.gridSlot].scene == sc)
  3341. {
  3342. clip.offset = offset;
  3343. clip.length = len;
  3344. song.clipGrid->slots[(std::size_t) clip.gridSlot].name = newName;
  3345. song.clipGrid->slots[(std::size_t) clip.gridSlot].startMarker = marker;
  3346. }
  3347. });
  3348. load();
  3349. }
  3350. // round 190hr: the slot's follow action (one undo step) and its typed time
  3351. const ClipFollow* follow() const
  3352. {
  3353. const auto* c = clip();
  3354. const auto& song = engine.getSong();
  3355. return c != nullptr && c->gridSlot >= 0 && c->gridSlot < (int) song.clipGrid->slots.size() ? &song.clipGrid->slots[(std::size_t) c->gridSlot].follow : nullptr;
  3356. }
  3357. void editFollow (std::function<void (ClipFollow&)> fn)
  3358. {
  3359. editSlot ([fn] (ClipGridSlot& slot) { fn (slot.follow); });
  3360. }
  3361. void applyFollowTime()
  3362. {
  3363. const auto* f = follow();
  3364. if (f == nullptr)
  3365. return;
  3366. const auto t = fieldTicks (followTime, true, false);
  3367. if (t > 0 && t != f->ticks)
  3368. editFollow ([t] (ClipFollow& x) { x.ticks = t; });
  3369. else
  3370. load();
  3371. }
  3372. // the grid clip of the slot and its settings (one undo step)
  3373. void editClip (std::function<void (Clip&, ClipGridSlot&)> fn)
  3374. {
  3375. const int t = track, sc = scene;
  3376. engine.editSong ([t, sc, fn] (Song& song) {
  3377. if (! song.clipGrid)
  3378. return;
  3379. for (auto& c : song.clipGrid->clips)
  3380. if (c.track == t && c.length > 0 && c.gridSlot >= 0 && c.gridSlot < (int) song.clipGrid->slots.size()
  3381. && song.clipGrid->slots[(std::size_t) c.gridSlot].scene == sc)
  3382. fn (c, song.clipGrid->slots[(std::size_t) c.gridSlot]);
  3383. });
  3384. }
  3385. void editSlot (std::function<void (ClipGridSlot&)> fn)
  3386. {
  3387. const int t = track, sc = scene;
  3388. engine.editSong ([t, sc, fn] (Song& song) {
  3389. if (song.clipGrid)
  3390. if (auto* slot = launcher::settingsAt (*song.clipGrid, t, sc))
  3391. fn (*slot);
  3392. });
  3393. }
  3394. // round gap190og (detail-019): Live's Duplicate Loop on this MIDI clip (core/ClipLoopOps.h; one undo step)
  3395. void duplicateClipLoop()
  3396. {
  3397. const int t = track, sc = scene;
  3398. engine.editSong ([t, sc] (Song& song) {
  3399. if (auto* c = gridClip (song, t, sc))
  3400. cliploop::duplicateLoop (song, *c);
  3401. });
  3402. load();
  3403. }
  3404. static Clip* gridClip (Song& song, int t, int sc)
  3405. {
  3406. if (! song.clipGrid)
  3407. return nullptr;
  3408. for (auto& c : song.clipGrid->clips)
  3409. if (c.track == t && c.length > 0 && c.gridSlot >= 0 && c.gridSlot < (int) song.clipGrid->slots.size()
  3410. && song.clipGrid->slots[(std::size_t) c.gridSlot].scene == sc)
  3411. return &c;
  3412. return nullptr;
  3413. }
  3414. public:
  3415. bool duplicateLoopForCheck()
  3416. {
  3417. if (! ui::showingOrShot (duplicateLoop) || duplicateLoop.getBounds().isEmpty() || ! duplicateLoop.isEnabled())
  3418. return false;
  3419. duplicateClipLoop(); // (what its click does; triggerClick would post it)
  3420. return true;
  3421. }
  3422. juce::Rectangle<int> duplicateLoopBoundsForCheck() const { return duplicateLoop.getBounds(); }
  3423. private:
  3424. // a note tool on every note of the clip's pattern (one undo step)
  3425. void notes (std::function<void (Pattern&, const std::vector<int>&, const Song&)> fn)
  3426. {
  3427. const auto* c = clip();
  3428. if (c == nullptr || c->kind != ClipKind::pattern)
  3429. return;
  3430. engine.editSong ([pattern = c->pattern, fn] (Song& song) {
  3431. if (pattern < 0 || pattern >= (int) song.patterns.size())
  3432. return;
  3433. auto& p = song.patterns[(std::size_t) pattern];
  3434. std::vector<int> all ((std::size_t) p.notes.size());
  3435. for (int i = 0; i < (int) all.size(); ++i)
  3436. all[(std::size_t) i] = i;
  3437. fn (p, all, song);
  3438. noteedit::sortTracking (p, all);
  3439. });
  3440. }
  3441. // what the MIDI Tools change: the docked Piano roll's selection (or all its channel's notes) while it shows this
  3442. // clip's pattern; otherwise every note of the pattern
  3443. MidiToolsPanel::Target toolTarget() const
  3444. {
  3445. MidiToolsPanel::Target t;
  3446. const auto* c = clip();
  3447. const auto& song = engine.getSong();
  3448. if (c == nullptr || c->kind != ClipKind::pattern || c->pattern < 0 || c->pattern >= (int) song.patterns.size())
  3449. return t;
  3450. t.pattern = c->pattern;
  3451. if (auto* roll = editorOf != nullptr ? editorOf() : nullptr; roll != nullptr && song.currentPattern == c->pattern)
  3452. {
  3453. t.indices = roll->midiToolNotes (t.selected);
  3454. t.grid = roll->midiToolGrid();
  3455. t.from = roll->timeSelectionFrom(); // round 190fm: Generate writes into the time selection…
  3456. t.to = roll->timeSelectionTo();
  3457. }
  3458. if (t.to <= t.from && c->length > 0) // …else the part of the pattern the clip plays (Live: the clip's loop)
  3459. {
  3460. t.from = std::max<std::int64_t> (0, c->offset);
  3461. t.to = t.from + c->length;
  3462. }
  3463. else
  3464. {
  3465. t.indices.resize (song.patterns[(std::size_t) c->pattern].notes.size());
  3466. for (int i = 0; i < (int) t.indices.size(); ++i)
  3467. t.indices[(std::size_t) i] = i;
  3468. }
  3469. return t;
  3470. }
  3471. AudioEngine& engine;
  3472. int track = -1, scene = -1;
  3473. bool hasNotes = true;
  3474. MidiToolsPanel tools;
  3475. juce::TextButton foldTools;
  3476. ClipChip chip;
  3477. std::unique_ptr<ui::NumBox> pitchRange, intervalSize;
  3478. juce::TextButton addInterval;
  3479. juce::String rangeText;
  3480. int transposed = 0, interval = 0;
  3481. juce::Label clipTitle, launchTitle, notesTitle, nameLabel, startLabel, endLabel, lengthLabel, signatureLabel, modeLabel, quantLabel, signature;
  3482. juce::TextEditor name, start, end, position, length;
  3483. juce::String nameFallback; // (round 190oj CS-33: the name shown while the clip has none of its own)
  3484. juce::TextButton setStart, setEnd, setPosition, setLength; // round 190dr
  3485. juce::Label positionLabel, grooveLabel;
  3486. juce::ComboBox groove;
  3487. GrooveCommitButton commitGroove; // round 190kc: Live's Commit button beside the Groove label
  3488. bool loading = false;
  3489. std::unique_ptr<ui::TimerWhileShowing> showingTimer;
  3490. juce::ToggleButton loop, legato;
  3491. // round gap190og (detail-019): Live's Duplicate Loop button of the Clip panel (its Live column only; MIDI clips)
  3492. liveclip::PillButton duplicateLoop { "duplicateLoop" };
  3493. // round 190hr: the Follow Action controls
  3494. juce::Label followTitle;
  3495. juce::TextButton followOn, linked;
  3496. juce::ComboBox followA, followB;
  3497. std::unique_ptr<ui::NumBox> chanceA, chanceB, multiplier, jumpA, jumpB;
  3498. juce::TextEditor followTime;
  3499. juce::ComboBox mode, quant;
  3500. juce::TextButton invert, reverse, makeLegato, humanize, duplicate, quantize, randomize, timesTwo, divideTwo, fitScale, chordHelper;
  3501. juce::Label scaleLabel;
  3502. juce::ComboBox scaleRoot, scaleName; // the clip's scale (round 190hr; before: the project key)
  3503. juce::TextButton scaleMode; // Live's Scale Mode switch of the clip (IsInKey)
  3504. std::optional<projectkey::Key> shownKey; // the scale last handed to the docked editor
  3505. // the key the clip's tools use: its own scale (or the project's) while its Scale Mode is on
  3506. std::optional<projectkey::Key> clipKeyOf (const Song& song) const
  3507. {
  3508. const auto* c = clip();
  3509. if (c == nullptr || ! song.clipGrid || c->gridSlot < 0 || c->gridSlot >= (int) song.clipGrid->slots.size())
  3510. return projectkey::get (song);
  3511. return projectkey::clipKey (song.clipGrid->slots[(std::size_t) c->gridSlot], song);
  3512. }
  3513. };
  3514. // ---------------------------------------------------------------------------------------------------------------------
  3515. // The Clip View (slice 1: the selected slot's clip and a button to its editor; slice 2 docks the editors here).
  3516. class DetailView::ClipPage final : public juce::Component, private juce::ChangeListener
  3517. {
  3518. public:
  3519. bool duplicateLoopForCheck() { return column.isVisible() && column.duplicateLoopForCheck(); } // (round gap190og)
  3520. ClipPage (AudioEngine& e, Hooks& h) : engine (e), hooks (h), column (e)
  3521. {
  3522. addChildComponent (column); // (slice 2b: shown while a grid clip is)
  3523. column.editorOf = [this] { return dynamic_cast<PianoRollComponent*> (editor); };
  3524. for (auto* b : { &notesTab, &envelopesTab, &mpeTab })
  3525. {
  3526. addChildComponent (*b);
  3527. b->setConnectedEdges (0);
  3528. b->setClickingTogglesState (false);
  3529. b->setColour (juce::TextButton::buttonOnColourId, colour::accent);
  3530. b->setColour (juce::TextButton::textColourOnId, colour::onAccent);
  3531. }
  3532. notesTab.setButtonText (tr ("Notes"));
  3533. envelopesTab.setButtonText (tr ("Envelopes"));
  3534. envelopesTab.setTooltip (tr ("The pattern's events: the levels and controls it changes while it plays"));
  3535. mpeTab.setButtonText (tr ("MPE"));
  3536. mpeTab.setTooltip (tr ("Each note's own pitch bend, slide and pressure curves (MPE)"));
  3537. notesTab.onClick = [this] { showTab (false); };
  3538. envelopesTab.onClick = [this] { showTab (true); };
  3539. mpeTab.onClick = [this] { showTab (false, true); };
  3540. addChildComponent (open);
  3541. open.onClick = [this] {
  3542. if (dockable())
  3543. {
  3544. takenBack = false;
  3545. update();
  3546. }
  3547. else if (arrangement >= 0 && hooks.openArrangementClip != nullptr) // (round 190qu)
  3548. hooks.openArrangementClip (arrangement);
  3549. else if (hooks.openClip != nullptr)
  3550. hooks.openClip (track, scene);
  3551. };
  3552. engine.addChangeListener (this);
  3553. }
  3554. ~ClipPage() override
  3555. {
  3556. engine.removeChangeListener (this);
  3557. release();
  3558. }
  3559. void setSlot (int t, int s)
  3560. {
  3561. if (t != track || s != scene || arrangement >= 0)
  3562. takenBack = false; // (a new clip docks again)
  3563. track = t;
  3564. scene = s;
  3565. arrangement = -1;
  3566. column.setSlot (t, s);
  3567. update();
  3568. }
  3569. // Round 190qu (Discord 11-24, kainproctor): an Arrangement clip selected in the Clip-launch layout shows here as in Live's
  3570. // Clip View — a pattern clip's notes (the docked Piano roll with Notes / Envelopes / MPE), an audio clip's name and its
  3571. // editor's button. −1: the clip grid's slot again. The Clip box column is the grid slot's (its launch settings), so an
  3572. // Arrangement clip shows the editor across the page.
  3573. void setArrangementClip (int index)
  3574. {
  3575. if (index == arrangement)
  3576. return;
  3577. takenBack = false;
  3578. arrangement = index;
  3579. const auto& song = engine.getSong();
  3580. if (index >= 0 && index < (int) song.playlist.size())
  3581. arrangementLike = song.playlist[(std::size_t) index];
  3582. column.setSlot (index >= 0 ? -1 : track, index >= 0 ? -1 : scene);
  3583. update();
  3584. }
  3585. int arrangementClip() const noexcept { return arrangement; }
  3586. bool editorDockedForCheck() const noexcept { return editor != nullptr && editor->getParentComponent() == this; }
  3587. MidiToolsPanel& midiTools() noexcept { return column.midiTools(); }
  3588. void sectionsForSnapshot (bool clipOpen, bool launchOpen, bool notesOpen, int scroll)
  3589. {
  3590. ClipColumn::clipOpen = clipOpen;
  3591. ClipColumn::launchOpen = launchOpen;
  3592. ClipColumn::notesOpen = notesOpen;
  3593. column.setScrollForSnapshot (scroll);
  3594. }
  3595. void editorTakenBack()
  3596. {
  3597. if (editor != nullptr)
  3598. {
  3599. editor = nullptr; // (its panel has it now)
  3600. dockedTrack = dockedScene = -1;
  3601. takenBack = true;
  3602. }
  3603. update();
  3604. }
  3605. void showTab (bool envelopes, bool mpe = false)
  3606. {
  3607. DetailView::envelopesTab = envelopes;
  3608. DetailView::mpeTab = mpe && ! envelopes;
  3609. if (! envelopes)
  3610. takenBack = false; // (Notes / MPE: the Piano roll docks again)
  3611. update();
  3612. }
  3613. // (round 190hy) the docked Piano roll shows the MPE lanes while the MPE tab does
  3614. void applyMpeView()
  3615. {
  3616. if (auto* roll = dynamic_cast<PianoRollComponent*> (editor))
  3617. {
  3618. roll->setMpeView (DetailView::mpeTab && ! DetailView::envelopesTab);
  3619. // round 190jn (CL-20b): in Live's look the docked notes take the clip's colour (PianoRollComponent::liveNotes)
  3620. const auto* clip = clipShown();
  3621. const auto colour = theme::livelook::active() && clip != nullptr ? clipColourOf (*clip) : juce::Colours::transparentBlack;
  3622. if (roll->liveNoteColour != colour)
  3623. {
  3624. roll->liveNoteColour = colour;
  3625. roll->liveFooterCheck(); // (round gap190og: Live's Velocity footer comes with the Live notes)
  3626. roll->repaint();
  3627. }
  3628. }
  3629. }
  3630. // the clip's colour as its title bar shows it (ClipColumn::load's rule)
  3631. juce::Colour clipColourOf (const Clip& c) const
  3632. {
  3633. const auto& song = engine.getSong();
  3634. const ClipGridSlot* slot = song.clipGrid && c.gridSlot >= 0 && c.gridSlot < (int) song.clipGrid->slots.size() ? &song.clipGrid->slots[(std::size_t) c.gridSlot] : nullptr;
  3635. return slot != nullptr && slot->colour != 0 ? juce::Colour (slot->colour)
  3636. : c.kind == ClipKind::audio ? colour::audioClip : tame (PlaylistComponent::patternColour (song, c.pattern));
  3637. }
  3638. // Round 190im (R13, DL-74): the docked clip's position in its pattern while it is launched from the grid (the
  3639. // launcher clock − its anchor, wrapped at its length, from its start offset); −1 when it does not play
  3640. double launchedTick() const
  3641. {
  3642. const auto* state = engine.launcherState();
  3643. if (state == nullptr || dockedTrack < 0 || dockedTrack >= launcher::maxTracks || ! state->running.load (std::memory_order_relaxed))
  3644. return -1.0;
  3645. const auto& view = state->tracks[(std::size_t) dockedTrack];
  3646. if (view.playing.load (std::memory_order_relaxed) != dockedScene)
  3647. return -1.0;
  3648. const auto& song = engine.getSong();
  3649. const auto* clip = song.clipGrid ? launcher::clipAt (*song.clipGrid, dockedTrack, dockedScene) : nullptr;
  3650. if (clip == nullptr || clip->kind != ClipKind::pattern || clip->length <= 0)
  3651. return -1.0;
  3652. return (double) clip->offset + std::fmod (juce::jmax (0.0, state->clockNow.load (std::memory_order_relaxed) + engine.playheadAdvanceTicks()
  3653. - view.anchor.load (std::memory_order_relaxed)), (double) clip->length);
  3654. }
  3655. void release()
  3656. {
  3657. dropEvents();
  3658. dockedTrack = dockedScene = -1;
  3659. if (auto* roll = dynamic_cast<PianoRollComponent*> (editor)) // (round 190jn: its own colours again at home)
  3660. {
  3661. roll->liveNoteColour = juce::Colours::transparentBlack;
  3662. roll->liveFooterCheck(); // (round gap190og: no Live footer outside the dock)
  3663. }
  3664. if (editor != nullptr && hooks.undockPianoRoll != nullptr)
  3665. {
  3666. editor = nullptr;
  3667. hooks.undockPianoRoll();
  3668. }
  3669. editor = nullptr;
  3670. }
  3671. void paint (juce::Graphics& g) override
  3672. {
  3673. g.fillAll (liveTabs ? theme::livelook::window : colour::bg1);
  3674. if (liveTabs && notesTab.isVisible()) // (round 190jn: Live's 17 px tab bar over the editor, #363636)
  3675. {
  3676. g.setColour (theme::livelook::surface);
  3677. g.fillRect (tabBar);
  3678. g.setColour (theme::livelook::separator);
  3679. g.fillRect (tabBar.getX(), tabBar.getBottom(), tabBar.getWidth(), 1);
  3680. }
  3681. if (editor != nullptr || events != nullptr)
  3682. return;
  3683. g.setColour (colour::textSecondary);
  3684. g.setFont (font (type::body));
  3685. g.drawText (text, getLocalBounds().withTrimmedLeft (column.isVisible() ? column.preferredWidth() : 0).withTrimmedBottom (40),
  3686. juce::Justification::centred, true);
  3687. }
  3688. void resized() override
  3689. {
  3690. auto area = getLocalBounds();
  3691. if (column.isVisible())
  3692. column.setBounds (area.removeFromLeft (column.preferredWidth()));
  3693. open.setBounds (area.withSizeKeepingCentre (240, 26).translated (0, 16));
  3694. if (audioPanel != nullptr) // round 190cg (ui/ClipAudioPanel)
  3695. audioPanel->setBounds (area);
  3696. applyLook();
  3697. tabBar = {};
  3698. if (notesTab.isVisible() && liveTabs)
  3699. {
  3700. // round 190jn (CL-20b): Live's tab bar — 17 px #363636 across the editor, the tabs (60 px, MPE 40 px) centred,
  3701. // the shown one #464646 (live-01-clipview-notes.png 691..873, live-clipview-audio.png 962..1082)
  3702. tabBar = area.removeFromTop (liveclip::headerHeight);
  3703. area.removeFromTop (1);
  3704. const auto total = 60 + 1 + 60 + 1 + 40;
  3705. auto bar = tabBar.withSizeKeepingCentre (total, liveclip::headerHeight);
  3706. notesTab.setBounds (bar.removeFromLeft (60));
  3707. bar.removeFromLeft (1);
  3708. envelopesTab.setBounds (bar.removeFromLeft (60));
  3709. bar.removeFromLeft (1);
  3710. mpeTab.setBounds (bar);
  3711. }
  3712. else if (notesTab.isVisible())
  3713. {
  3714. // the clip's tabs, top right, as the reference's Notes | Envelopes [SHOT d08] (| MPE: Live 11+, round 190hy)
  3715. auto bar = area.removeFromTop (tabHeight).reduced (2, 2);
  3716. mpeTab.setBounds (bar.removeFromRight (72));
  3717. bar.removeFromRight (2);
  3718. envelopesTab.setBounds (bar.removeFromRight (96));
  3719. bar.removeFromRight (2);
  3720. notesTab.setBounds (bar.removeFromRight (96));
  3721. }
  3722. if (events != nullptr)
  3723. events->setBounds (area);
  3724. if (editor != nullptr)
  3725. {
  3726. editor->setBounds (area);
  3727. if (auto* sharer = dynamic_cast<SharesTitleBar*> (editor))
  3728. sharer->setTitleBarInsets (0, 0); // (its toolbar runs across the top, there is no title bar here)
  3729. }
  3730. }
  3731. void visibilityChanged() override { update(); }
  3732. private:
  3733. void changeListenerCallback (juce::ChangeBroadcaster*) override { update(); }
  3734. // round 190jn: the tabs in Live's colours (the shown one #464646, the others #363636, text #B5B5B5) and square, or
  3735. // LYNX's back; follows the layout's switch
  3736. bool liveTabs = false;
  3737. juce::Rectangle<int> tabBar;
  3738. void applyLook()
  3739. {
  3740. const auto live = theme::livelook::active();
  3741. if (live == liveTabs)
  3742. return;
  3743. liveTabs = live;
  3744. for (auto* b : { &notesTab, &envelopesTab, &mpeTab })
  3745. {
  3746. liveclip::swapColour (*b, juce::TextButton::buttonColourId, theme::livelook::surface, live);
  3747. liveclip::swapColour (*b, juce::TextButton::buttonOnColourId, liveclip::header, live);
  3748. liveclip::swapColour (*b, juce::TextButton::textColourOffId, theme::livelook::text, live);
  3749. liveclip::swapColour (*b, juce::TextButton::textColourOnId, theme::livelook::text, live);
  3750. b->setConnectedEdges (live ? juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight : 0);
  3751. }
  3752. }
  3753. // this page and every parent visible (not isShowing(): an off-screen --detailshot has no window, and a minimised
  3754. // window keeps its dock)
  3755. bool onScreen() const
  3756. {
  3757. for (const juce::Component* c = this; c != nullptr; c = c->getParentComponent())
  3758. if (! c->isVisible())
  3759. return false;
  3760. return getParentComponent() != nullptr;
  3761. }
  3762. const Clip* clipShown() const
  3763. {
  3764. const auto& song = engine.getSong();
  3765. if (arrangement >= 0) // (round 190qu: an Arrangement clip, found again after an edit moved it in the list)
  3766. {
  3767. const auto& like = arrangementLike;
  3768. const auto sameSource = [&like] (const Clip& c) {
  3769. return c.gridSlot < 0 && c.kind == like.kind && c.pattern == like.pattern && c.channel == like.channel && c.automation == like.automation;
  3770. };
  3771. const auto& list = song.playlist;
  3772. if (arrangement < (int) list.size() && sameSource (list[(std::size_t) arrangement]) && list[(std::size_t) arrangement].track == like.track
  3773. && list[(std::size_t) arrangement].start == like.start)
  3774. return &list[(std::size_t) arrangement];
  3775. for (int i = 0; i < (int) list.size(); ++i)
  3776. if (sameSource (list[(std::size_t) i]) && list[(std::size_t) i].track == like.track && list[(std::size_t) i].start == like.start)
  3777. {
  3778. arrangement = i;
  3779. return &list[(std::size_t) i];
  3780. }
  3781. if (arrangement < (int) list.size() && sameSource (list[(std::size_t) arrangement])) // (moved or resized in place)
  3782. {
  3783. arrangementLike = list[(std::size_t) arrangement];
  3784. return &list[(std::size_t) arrangement];
  3785. }
  3786. return nullptr;
  3787. }
  3788. return song.clipGrid && track >= 0 && scene >= 0 ? launcher::clipAt (*song.clipGrid, track, scene) : nullptr;
  3789. }
  3790. // what is docked: the grid slot, or (round 190qu) the Arrangement clip as track −2
  3791. int shownTrack() const noexcept { return arrangement >= 0 ? -2 : track; }
  3792. int shownScene() const noexcept { return arrangement >= 0 ? arrangement : scene; }
  3793. bool dockable() const
  3794. {
  3795. const auto* clip = clipShown();
  3796. return clip != nullptr && clip->kind == ClipKind::pattern && hooks.dockPianoRoll != nullptr;
  3797. }
  3798. // The Event editor of the clip's pattern, made for this slot (its own target box picks another target): preset to
  3799. // the pattern's first event lane, else the volume of the track's channel (or of the pattern's first channel).
  3800. void showEvents (const Clip& clip)
  3801. {
  3802. if (events != nullptr && eventsTrack == shownTrack() && eventsScene == shownScene())
  3803. return;
  3804. dropEvents();
  3805. const auto& song = engine.getSong();
  3806. if (hooks.selectPattern != nullptr && clip.pattern != song.currentPattern)
  3807. hooks.selectPattern (clip.pattern);
  3808. AutomationTarget target;
  3809. if (clip.pattern >= 0 && clip.pattern < (int) song.patterns.size() && ! song.patterns[(std::size_t) clip.pattern].events.empty())
  3810. target = song.patterns[(std::size_t) clip.pattern].events.front().target;
  3811. else
  3812. {
  3813. const auto chain = detailchain::forTrack (song, arrangement >= 0 ? -1 : track);
  3814. auto channel = chain.channel;
  3815. if (channel < 0 && clip.pattern >= 0 && clip.pattern < (int) song.patterns.size() && ! song.patterns[(std::size_t) clip.pattern].notes.empty())
  3816. channel = song.patterns[(std::size_t) clip.pattern].notes.front().channel;
  3817. target = AutomationTarget { AutomationTargetKind::channelVolume, std::max (0, channel) };
  3818. }
  3819. events = makeEventEditor (engine, target);
  3820. eventsTrack = shownTrack();
  3821. eventsScene = shownScene();
  3822. addAndMakeVisible (*events);
  3823. resized();
  3824. }
  3825. void dropEvents()
  3826. {
  3827. if (events != nullptr)
  3828. removeChildComponent (events.get());
  3829. events.reset();
  3830. eventsTrack = eventsScene = -1;
  3831. }
  3832. void update()
  3833. {
  3834. if (theme::livelook::active() != liveTabs)
  3835. {
  3836. applyLook();
  3837. resized();
  3838. }
  3839. const auto& song = engine.getSong();
  3840. const auto* clip = clipShown();
  3841. if (column.isVisible() != (clip != nullptr && arrangement < 0)) // (round 190qu: the grid slot's column only)
  3842. {
  3843. column.setVisible (clip != nullptr && arrangement < 0);
  3844. resized();
  3845. }
  3846. // a pattern clip, on screen: the Piano roll docks here (unless its panel took it back since this clip was picked)
  3847. const bool patternClip = clip != nullptr && clip->kind == ClipKind::pattern;
  3848. const bool tabs = patternClip && onScreen();
  3849. if (tabs != notesTab.isVisible())
  3850. {
  3851. notesTab.setVisible (tabs);
  3852. envelopesTab.setVisible (tabs);
  3853. mpeTab.setVisible (tabs);
  3854. resized();
  3855. }
  3856. notesTab.setToggleState (! DetailView::envelopesTab && ! DetailView::mpeTab, juce::dontSendNotification);
  3857. envelopesTab.setToggleState (DetailView::envelopesTab, juce::dontSendNotification);
  3858. mpeTab.setToggleState (DetailView::mpeTab && ! DetailView::envelopesTab, juce::dontSendNotification);
  3859. if (tabs && DetailView::envelopesTab)
  3860. {
  3861. if (editor != nullptr && hooks.undockPianoRoll != nullptr) // (the Piano roll goes home while Envelopes shows)
  3862. {
  3863. if (auto* roll = dynamic_cast<PianoRollComponent*> (editor))
  3864. roll->setMpeView (false);
  3865. editor = nullptr;
  3866. dockedTrack = dockedScene = -1;
  3867. hooks.undockPianoRoll();
  3868. }
  3869. showEvents (*clip);
  3870. open.setVisible (false);
  3871. repaint();
  3872. return;
  3873. }
  3874. dropEvents();
  3875. if (clip != nullptr && clip->kind == ClipKind::pattern && onScreen() && ! takenBack && hooks.dockPianoRoll != nullptr)
  3876. {
  3877. if (editor != nullptr && dockedTrack == shownTrack() && dockedScene == shownScene())
  3878. {
  3879. applyMpeView();
  3880. return; // (already showing this clip: the user may have picked another pattern in it meanwhile)
  3881. }
  3882. dockedTrack = shownTrack();
  3883. dockedScene = shownScene();
  3884. auto* e = hooks.dockPianoRoll (clip->pattern);
  3885. if (auto* roll = dynamic_cast<PianoRollComponent*> (e)) // (round 190im, R13: the launched clip's position)
  3886. roll->launchedPlayhead = [safe = juce::Component::SafePointer<ClipPage> (this), roll] {
  3887. return safe != nullptr && safe->editor == roll ? safe->launchedTick() : -1.0;
  3888. };
  3889. if (e != nullptr && e != editor)
  3890. {
  3891. editor = e;
  3892. addAndMakeVisible (*editor);
  3893. column.reload(); // (round 190hr: the column gives the docked editor its Quantize keys and the clip's scale)
  3894. resized();
  3895. }
  3896. applyMpeView();
  3897. open.setVisible (false);
  3898. repaint();
  3899. return;
  3900. }
  3901. if (editor != nullptr && (! onScreen() || clip == nullptr || clip->kind != ClipKind::pattern))
  3902. release();
  3903. // round 190cg: an audio clip shows its Audio panel and the audio editor (ui/ClipAudioPanel)
  3904. const auto audioKey = clip != nullptr && clip->kind == ClipKind::audio && arrangement < 0 && onScreen() ? (track * 2000 + scene) * 4096 + (clip->channel & 4095) : -1;
  3905. if (audioKey != audioPanelKey)
  3906. {
  3907. audioPanel.reset();
  3908. audioPanelKey = audioKey;
  3909. if (audioKey >= 0)
  3910. if (audioPanel = makeClipAudioPanel (engine, track, scene); audioPanel != nullptr)
  3911. {
  3912. addAndMakeVisible (*audioPanel);
  3913. resized();
  3914. }
  3915. }
  3916. if (audioPanel != nullptr)
  3917. {
  3918. open.setVisible (false);
  3919. repaint();
  3920. return;
  3921. }
  3922. if (clip == nullptr)
  3923. {
  3924. text = tr ("Select a clip in the clip grid or the Arrangement to see it here"); // (round 190qu)
  3925. open.setVisible (false);
  3926. }
  3927. else if (clip->kind == ClipKind::audio)
  3928. {
  3929. text = clip->channel >= 0 && clip->channel < (int) song.channels.size() ? utf8 (song.channels[(std::size_t) clip->channel].name) : tr ("Audio clip");
  3930. open.setButtonText (tr ("Open in the audio editor"));
  3931. open.setVisible (true);
  3932. }
  3933. else if (clip->kind == ClipKind::automation) // (round 190qu: an Arrangement automation clip, its points' editor)
  3934. {
  3935. text = clip->automation >= 0 && clip->automation < (int) song.automations.size() ? utf8 (song.automations[(std::size_t) clip->automation].name)
  3936. : tr ("Automation clip");
  3937. open.setButtonText (tr ("Edit points..."));
  3938. open.setVisible (hooks.openArrangementClip != nullptr);
  3939. }
  3940. else
  3941. {
  3942. text = clip->pattern >= 0 && clip->pattern < (int) song.patterns.size() ? utf8 (song.patterns[(std::size_t) clip->pattern].name) : tr ("Pattern");
  3943. if (takenBack)
  3944. text << " - " << tr ("the piano roll is in its own panel now");
  3945. open.setButtonText (takenBack ? tr ("Dock the piano roll here") : tr ("Open in the piano roll"));
  3946. open.setVisible (true);
  3947. }
  3948. repaint();
  3949. }
  3950. AudioEngine& engine;
  3951. Hooks& hooks;
  3952. juce::TextButton open;
  3953. juce::String text;
  3954. ClipColumn column;
  3955. juce::TextButton notesTab, envelopesTab, mpeTab;
  3956. static constexpr int tabHeight = 26;
  3957. std::unique_ptr<juce::Component> events; // the Envelopes tab's Event editor
  3958. int eventsTrack = -1, eventsScene = -1;
  3959. juce::Component* editor = nullptr; // the docked Piano roll (not owned)
  3960. std::unique_ptr<juce::Component> audioPanel; // round 190cg: an audio clip's panel and editor
  3961. int audioPanelKey = -1;
  3962. int dockedTrack = -1, dockedScene = -1;
  3963. bool takenBack = false;
  3964. int track = -1, scene = -1;
  3965. mutable int arrangement = -1; // round 190qu: the Arrangement clip shown (an index into Song::playlist), −1: the grid slot
  3966. mutable Clip arrangementLike; // (what it was, to find it again after an edit)
  3967. };
  3968. // ---------------------------------------------------------------------------------------------------------------------
  3969. DetailView::DetailView (AudioEngine& e, Hooks h) : engine (e), hooks (std::move (h))
  3970. {
  3971. setTitle (tr ("Detail view"));
  3972. info = std::make_unique<ui::InfoView>();
  3973. addChildComponent (*info);
  3974. info->setInterceptsMouseClicks (false, false);
  3975. chain = std::make_unique<DeviceChain> (engine, hooks);
  3976. clipPage = std::make_unique<ClipPage> (engine, hooks);
  3977. addChildComponent (*chain);
  3978. addChildComponent (*clipPage);
  3979. for (auto* b : { &clipTab, &devicesTab, &optionsButton })
  3980. {
  3981. addAndMakeVisible (*b);
  3982. b->setConnectedEdges (0);
  3983. b->setColour (juce::TextButton::buttonOnColourId, colour::accent);
  3984. b->setColour (juce::TextButton::textColourOnId, colour::onAccent);
  3985. }
  3986. clipTab.setButtonText (tr ("Clip"));
  3987. devicesTab.setButtonText (tr ("Devices"));
  3988. clipTab.setTooltip (tr ("The selected clip (Shift+Tab switches, Ctrl+Alt+3)"));
  3989. devicesTab.setTooltip (tr ("The selected track's devices: its instrument and its insert's effects (Shift+Tab switches, Ctrl+Alt+4)"));
  3990. clipTab.onClick = [this] { setPage (Page::clip); };
  3991. devicesTab.onClick = [this] { setPage (Page::devices); };
  3992. optionsButton.setButtonText (juce::String::fromUTF8 ("\xe2\x8b\xaf"));
  3993. optionsButton.setTooltip (tr ("Detail view options"));
  3994. optionsButton.onClick = [this] { showOptionsMenu(); };
  3995. showPage();
  3996. }
  3997. DetailView::~DetailView() = default;
  3998. void DetailView::showSelection (int t, int s)
  3999. {
  4000. track = t;
  4001. scene = s;
  4002. chain->setTrack (t);
  4003. clipPage->setSlot (t, s);
  4004. }
  4005. bool DetailView::clipEditorDockedForCheck() const { return clipPage->editorDockedForCheck(); }
  4006. int DetailView::arrangementClipForCheck() const { return clipPage->arrangementClip(); }
  4007. void DetailView::showArrangementClip (int index)
  4008. {
  4009. if (index < 0 && clipPage->arrangementClip() < 0)
  4010. return;
  4011. if (index < 0)
  4012. clipPage->setSlot (track, scene); // (the grid's selection again)
  4013. else
  4014. clipPage->setArrangementClip (index);
  4015. }
  4016. void DetailView::setPage (Page page)
  4017. {
  4018. devicesPage = page == Page::devices;
  4019. if (! shownSetting)
  4020. {
  4021. shownSetting = true;
  4022. setVisible (true);
  4023. }
  4024. showPage();
  4025. if (hooks.layoutChanged != nullptr)
  4026. hooks.layoutChanged();
  4027. }
  4028. void DetailView::togglePage() { setPage (devicesPage ? Page::clip : Page::devices); }
  4029. void DetailView::editorTakenBack() { clipPage->editorTakenBack(); }
  4030. void DetailView::releaseEditor() { clipPage->release(); }
  4031. void DetailView::setClipTab (bool envelopes) { clipPage->showTab (envelopes); }
  4032. void DetailView::setMpeTab() { clipPage->showTab (false, true); }
  4033. bool DetailView::duplicateLoopForCheck() { return clipPage != nullptr && clipPage->duplicateLoopForCheck(); } // (round gap190og)
  4034. void DetailView::showPage()
  4035. {
  4036. chain->setVisible (devicesPage);
  4037. clipPage->setVisible (! devicesPage);
  4038. clipTab.setToggleState (! devicesPage, juce::dontSendNotification);
  4039. devicesTab.setToggleState (devicesPage, juce::dontSendNotification);
  4040. repaint();
  4041. }
  4042. int DetailView::heightFor (int available) const noexcept
  4043. {
  4044. return juce::jlimit (std::min (minHeight, available / 2), std::max (minHeight, available * 6 / 10), preferredHeight);
  4045. }
  4046. void DetailView::showOptionsMenu()
  4047. {
  4048. juce::PopupMenu menu;
  4049. menu.addSectionHeader (tr ("LYNX extras"));
  4050. menu.addItem (tr ("W shows or hides the selected device's window"), true, extraWindowKey, [this] {
  4051. extraWindowKey = ! extraWindowKey;
  4052. if (hooks.layoutChanged != nullptr)
  4053. hooks.layoutChanged();
  4054. });
  4055. menu.addItem (tr ("Selecting a device selects its insert in the Mixer"), true, extraSelectInMixer, [this] {
  4056. extraSelectInMixer = ! extraSelectInMixer;
  4057. if (hooks.layoutChanged != nullptr)
  4058. hooks.layoutChanged();
  4059. });
  4060. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&optionsButton));
  4061. }
  4062. void DetailView::paint (juce::Graphics& g)
  4063. {
  4064. if (theme::livelook::active())
  4065. {
  4066. paintLiveStrip (g);
  4067. return;
  4068. }
  4069. g.fillAll (colour::bg1);
  4070. // the top edge: drag to resize
  4071. g.setColour (colour::bg3);
  4072. g.fillRect (0, 0, getWidth(), edgeHeight);
  4073. g.setColour (colour::border);
  4074. g.fillRect (0, edgeHeight - 1, getWidth(), 1);
  4075. g.setColour (colour::bg5);
  4076. g.fillRect (getWidth() / 2 - 16, 2, 32, 1);
  4077. // the bottom strip: what is shown, then the selectors on the right
  4078. const auto strip = getLocalBounds().removeFromBottom (stripHeight);
  4079. g.setColour (colour::border);
  4080. g.fillRect (strip.withHeight (1));
  4081. g.setColour (colour::textSecondary);
  4082. g.setFont (font (type::small));
  4083. const auto& song = engine.getSong();
  4084. juce::String what;
  4085. if (devicesPage)
  4086. {
  4087. what = track >= 0 ? tr ("Devices") + ": " + trackName (song, track) : tr ("Devices");
  4088. if (const auto i = chain->insertShown(); i >= 0)
  4089. what << juce::String::fromUTF8 (" \xc2\xb7 ") << insertName (song, i);
  4090. }
  4091. else
  4092. what = tr ("Clip");
  4093. what << " (" << tr ("Shift+Tab: {0}", { devicesPage ? tr ("Clip") : tr ("Devices") }) << ")";
  4094. g.drawText (what, strip.reduced (8, 0).withTrimmedRight (240), juce::Justification::centredLeft, true);
  4095. }
  4096. void DetailView::resized()
  4097. {
  4098. auto r = getLocalBounds();
  4099. r.removeFromTop (edgeHeight);
  4100. const auto live = theme::livelook::active();
  4101. clipTab.setVisible (! live);
  4102. devicesTab.setVisible (! live);
  4103. info->setVisible (live && infoViewShown);
  4104. if (live)
  4105. {
  4106. // Live: the status strip under everything; the Info View 9..240 then the views from 249 (live-session.png)
  4107. r.removeFromBottom (stripHeight);
  4108. optionsButton.setBounds (getWidth() - 28, getHeight() - stripHeight + 2, 26, stripHeight - 4);
  4109. if (infoViewShown)
  4110. {
  4111. auto left = r.removeFromLeft (249);
  4112. info->setBounds (left.withTrimmedLeft (9).withTrimmedRight (9).withTrimmedTop (2).withTrimmedBottom (1));
  4113. }
  4114. chain->setBounds (r);
  4115. clipPage->setBounds (r);
  4116. return;
  4117. }
  4118. auto strip = r.removeFromBottom (stripHeight).reduced (2, 2);
  4119. optionsButton.setBounds (strip.removeFromRight (26));
  4120. strip.removeFromRight (4);
  4121. devicesTab.setBounds (strip.removeFromRight (96));
  4122. strip.removeFromRight (2);
  4123. clipTab.setBounds (strip.removeFromRight (96));
  4124. chain->setBounds (r);
  4125. clipPage->setBounds (r);
  4126. }
  4127. void DetailView::mouseMove (const juce::MouseEvent& e)
  4128. {
  4129. setMouseCursor (e.y < edgeHeight ? juce::MouseCursor::UpDownResizeCursor : juce::MouseCursor::NormalCursor);
  4130. }
  4131. void DetailView::mouseDown (const juce::MouseEvent& e)
  4132. {
  4133. resizing = e.y < edgeHeight;
  4134. dragStartHeight = getHeight();
  4135. if (resizing || ! theme::livelook::active() || e.mods.isPopupMenu())
  4136. return;
  4137. if (infoButtonArea().expanded (2).contains (e.getPosition()))
  4138. toggleInfoView();
  4139. else if (pageGlyphArea (false).expanded (1).contains (e.getPosition()))
  4140. setPage (Page::clip);
  4141. else if (pageGlyphArea (true).expanded (1).contains (e.getPosition()))
  4142. setPage (Page::devices);
  4143. }
  4144. // --- round 190jn: Live's Info View and status strip (design190ia CL-23 / CL-24) -----------------------------------------
  4145. void DetailView::setInfoHint (const ui::Hint& hint)
  4146. {
  4147. if (info->isVisible())
  4148. info->setHint (hint);
  4149. }
  4150. void DetailView::toggleInfoView()
  4151. {
  4152. infoViewShown = ! infoViewShown;
  4153. resized();
  4154. repaint();
  4155. if (hooks.layoutChanged != nullptr)
  4156. hooks.layoutChanged();
  4157. }
  4158. ui::InfoView& DetailView::infoViewForSnapshot() { return *info; }
  4159. // Live 12.4's status bar (live-session.png y 1004..1022): the (i) button 15 px at x 11 (orange: the Info View shows),
  4160. // the status text in a #363636 field from x 42; at the right the selected track's name and the view selector
  4161. // (here: a Clip glyph and a Device glyph, 17 px, the shown one lit #FFAD56); LYNX's "..." options last.
  4162. juce::Rectangle<int> DetailView::infoButtonArea() const
  4163. {
  4164. return { 11, getHeight() - stripHeight + (stripHeight - 15) / 2, 15, 15 };
  4165. }
  4166. juce::Rectangle<int> DetailView::pageGlyphArea (bool devices) const
  4167. {
  4168. const auto right = getWidth() - 34;
  4169. return { right - (devices ? 19 : 38), getHeight() - stripHeight + (stripHeight - 17) / 2, 17, 17 };
  4170. }
  4171. void DetailView::paintLiveStrip (juce::Graphics& g)
  4172. {
  4173. namespace ll = theme::livelook;
  4174. g.fillAll (ll::window);
  4175. // the top edge: drag to resize (a 1 px #464646 line as Live's split, the grip in the middle)
  4176. g.setColour (ll::separator);
  4177. g.fillRect (0, edgeHeight - 1, getWidth(), 1);
  4178. g.setColour (ll::raised);
  4179. g.fillRect (getWidth() / 2 - 16, 2, 32, 1);
  4180. const auto strip = getLocalBounds().removeFromBottom (stripHeight);
  4181. // (i)
  4182. const auto ib = infoButtonArea().toFloat();
  4183. g.setColour (infoViewShown ? ll::on : ll::well);
  4184. g.fillEllipse (ib);
  4185. g.setColour (infoViewShown ? ll::ink : ll::text);
  4186. g.fillEllipse (juce::Rectangle<float> (2.0f, 2.0f).withCentre ({ ib.getCentreX(), ib.getY() + 4.0f }));
  4187. g.fillRect (juce::Rectangle<float> (ib.getCentreX() - 1.0f, ib.getY() + 6.0f, 2.0f, 6.0f));
  4188. // the status text field
  4189. const auto& song = engine.getSong();
  4190. const auto glyphs = pageGlyphArea (false).getX();
  4191. const auto name = track >= 0 ? trackName (song, track) : juce::String();
  4192. g.setFont (font (type::small));
  4193. static juce::String measuredName; // (the name's width, measured once per name)
  4194. static int measuredWidth = 0;
  4195. if (name != measuredName)
  4196. {
  4197. measuredName = name;
  4198. measuredWidth = name.isEmpty() ? 0 : juce::jmin (180, juce::roundToInt (juce::TextLayout::getStringWidth (g.getCurrentFont(), name)) + 12);
  4199. }
  4200. const auto nameWidth = measuredWidth;
  4201. auto field = juce::Rectangle<int> (42, strip.getY() + (stripHeight - 19) / 2, std::max (0, glyphs - nameWidth - 12 - 42), 19);
  4202. g.setColour (ll::surface);
  4203. g.fillRoundedRectangle (field.toFloat(), 3.0f);
  4204. juce::String what;
  4205. if (devicesPage)
  4206. {
  4207. what = track >= 0 ? tr ("Devices") + ": " + trackName (song, track) : tr ("Devices");
  4208. if (const auto i = chain->insertShown(); i >= 0)
  4209. what << juce::String::fromUTF8 (" \xc2\xb7 ") << insertName (song, i);
  4210. }
  4211. else
  4212. what = tr ("Clip");
  4213. what << " (" << tr ("Shift+Tab: {0}", { devicesPage ? tr ("Clip") : tr ("Devices") }) << ")";
  4214. g.setColour (ll::text);
  4215. textcache::drawText (g, what, field.reduced (6, 0), juce::Justification::centredLeft, true);
  4216. if (nameWidth > 0)
  4217. textcache::drawText (g, name, juce::Rectangle<int> (glyphs - nameWidth - 6, strip.getY(), nameWidth, stripHeight), juce::Justification::centredLeft, true);
  4218. // the Clip glyph (a clip block with its waveform) and the Device glyph (Live's three bars)
  4219. for (const auto devices : { false, true })
  4220. {
  4221. const auto r = pageGlyphArea (devices).toFloat();
  4222. const auto lit = devicesPage == devices;
  4223. g.setColour (lit ? ll::on : ll::well);
  4224. g.fillRoundedRectangle (r, 2.0f);
  4225. g.setColour (lit ? ll::ink : ll::text);
  4226. if (devices)
  4227. for (int k = 0; k < 3; ++k)
  4228. {
  4229. const auto h = k == 1 ? 9.0f : 6.0f;
  4230. g.fillRect (juce::Rectangle<float> (r.getX() + 4.0f + (float) k * 3.5f, r.getBottom() - 4.0f - h, 2.0f, h));
  4231. }
  4232. else
  4233. {
  4234. const auto b = r.reduced (3.5f, 5.0f);
  4235. g.drawRect (b, 1.0f);
  4236. g.drawLine (b.getX() + 2.0f, b.getCentreY(), b.getRight() - 2.0f, b.getCentreY(), 1.0f);
  4237. }
  4238. }
  4239. }
  4240. juce::String DetailView::getTooltip()
  4241. {
  4242. if (! theme::livelook::active())
  4243. return {};
  4244. const auto p = getMouseXYRelative();
  4245. if (infoButtonArea().expanded (2).contains (p))
  4246. return tr ("Info View: shows what the control under the mouse does. Click or press Shift+? to show or hide it");
  4247. if (pageGlyphArea (false).expanded (1).contains (p))
  4248. return clipTab.getTooltip();
  4249. if (pageGlyphArea (true).expanded (1).contains (p))
  4250. return devicesTab.getTooltip();
  4251. return {};
  4252. }
  4253. void DetailView::mouseDrag (const juce::MouseEvent& e)
  4254. {
  4255. if (! resizing)
  4256. return;
  4257. preferredHeight = std::max (minHeight, dragStartHeight - e.getDistanceFromDragStartY());
  4258. if (hooks.layoutChanged != nullptr)
  4259. hooks.layoutChanged();
  4260. }
  4261. void DetailView::mouseUp (const juce::MouseEvent&)
  4262. {
  4263. if (resizing && getParentComponent() != nullptr)
  4264. preferredHeight = getHeight(); // (what the dock allowed)
  4265. resizing = false;
  4266. }
  4267. MidiToolsPanel& DetailView::midiToolsForSnapshot() { return clipPage->midiTools(); }
  4268. void DetailView::clipSectionsForSnapshot (bool clipOpen, bool launchOpen, bool notesOpen, int scroll) { clipPage->sectionsForSnapshot (clipOpen, launchOpen, notesOpen, scroll); }
  4269. hotswap::Target DetailView::selectedDeviceTarget() const { return devicesPage && isShowing() ? chain->selectedTarget() : hotswap::Target(); }
  4270. void DetailView::hotSwapChanged() { chain->repaint(); }
  4271. void DetailView::selectCardForCheck (int card) { chain->selectCard (card); }
  4272. // round gap190og (deviceview-0012): the main window's Edit menu (Clip-launch layout) on the Device View
  4273. bool DetailView::devicesHaveFocus (const juce::Component* focused) const
  4274. {
  4275. return chain != nullptr && chain->isVisible() && ui::showingOrShot (*chain) && focused != nullptr && (focused == chain.get() || chain->isParentOf (focused));
  4276. }
  4277. bool DetailView::canEditDevice (EditCommand command) const
  4278. {
  4279. return chain != nullptr && chain->isVisible() && ui::showingOrShot (*chain) && chain->canEdit ((DeviceChain::EditCommand) command);
  4280. }
  4281. bool DetailView::editDevice (EditCommand command)
  4282. {
  4283. return chain != nullptr && chain->isVisible() && ui::showingOrShot (*chain) && chain->runEdit ((DeviceChain::EditCommand) command);
  4284. }
  4285. bool DetailView::duplicateCardForCheck (int card) { return chain->duplicateCard (card); }
  4286. bool DetailView::groupCardForCheck (int card, bool ungroup) { return chain->groupCardForCheck (card, ungroup); }
  4287. juce::PopupMenu DetailView::cardMenuForSnapshot (int card)
  4288. {
  4289. juce::PopupMenu menu;
  4290. EffectsPanel::slotMenuForSnapshot = &menu;
  4291. chain->showCardMenuForSnapshot (card);
  4292. EffectsPanel::slotMenuForSnapshot = nullptr;
  4293. return menu;
  4294. }
  4295. int DetailView::cardCountForCheck() const { return chain->cardCount(); }
  4296. juce::Rectangle<int> DetailView::windowButtonForCheck (int card) const
  4297. {
  4298. const auto r = chain->windowButtonOf (card);
  4299. return r.isEmpty() ? r : getLocalArea (chain.get(), r);
  4300. }
  4301. bool DetailView::pressWindowButtonForCheck (int card) { return chain->pressWindowButtonForCheck (card); }
  4302. int DetailView::chainInsertForCheck() const { return chain->insertShown(); }
  4303. double DetailView::knobValueForCheck (int card, int knob) const { return chain->knobValueForCheck (card, knob); }
  4304. int DetailView::chainChannelForCheck() const { return chain->channelShown(); }
  4305. bool DetailView::isFoldedForCheck (int card) const { return chain->isCardFolded (card); }
  4306. void DetailView::toggleFoldForCheck (int card) { chain->toggleCardFold (card); }
  4307. void DetailView::deviceLevelsForSnapshot (float left, float right) { chain->deviceLevelsForSnapshot (left, right); }
  4308. // ---------------------------------------------------------------------------------------------------------------------
  4309. // Round 190dr: the description of a device card dragged out of the Device View
  4310. namespace
  4311. {
  4312. constexpr const char* deviceDragTag = "lynx-device";
  4313. }
  4314. juce::String deviceDragDescription (int insert, int slot)
  4315. {
  4316. return juce::String (deviceDragTag) + "|" + juce::String (insert) + "|" + juce::String (slot);
  4317. }
  4318. bool detailDeviceDrag (const juce::var& description, int& insert, int& slot)
  4319. {
  4320. const auto parts = juce::StringArray::fromTokens (description.toString(), "|", "");
  4321. if (parts.size() != 3 || parts[0] != deviceDragTag)
  4322. return false;
  4323. insert = parts[1].getIntValue();
  4324. slot = parts[2].getIntValue();
  4325. return insert >= 0 && slot >= 0;
  4326. }
  4327. } // namespace lynx