ProEditors.cpp 218 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861
  1. #include "ui/SlotWatch.h"
  2. #include "ui/ProEditors.h"
  3. #include "ui/PluginEditors.h"
  4. #include <cmath>
  5. #include <map>
  6. #include <tuple>
  7. #include "core/MixerOps.h"
  8. #include "core/ApexLimiter.h"
  9. #include "core/DynamicsSuite.h"
  10. #include "core/FacetEq.h"
  11. #include "core/MixSuite.h"
  12. #include "ui/DynamicsDisplays.h"
  13. #include "ui/ParametricEqEditor.h"
  14. #include "ui/ProEditorBase.h"
  15. #include "ui/WindowOwner.h"
  16. namespace lynx
  17. {
  18. namespace
  19. {
  20. using namespace pro;
  21. using namespace theme;
  22. // a synthetic programme for the --plugui snapshots: a beat (kick on the beat, snare on the off-beat) over a
  23. // sustained part, 10 ms columns, deterministic
  24. float demoInDb (int i)
  25. {
  26. const auto t = (double) i * 0.01;
  27. const auto beat = std::fmod (t, 0.5), off = std::fmod (t + 0.25, 0.5);
  28. const auto noise = (float) ((std::sin ((double) i * 12.9898) * 43758.5453) - std::floor (std::sin ((double) i * 12.9898) * 43758.5453));
  29. const auto body = -20.0 + 3.0 * std::sin (t * 0.9) + 2.5 * (double) noise;
  30. const auto kick = 13.0 * std::exp (-beat / 0.05);
  31. const auto snare = 9.0 * std::exp (-off / 0.035);
  32. return (float) juce::jmin (-0.5, body + juce::jmax (kick, snare));
  33. }
  34. juce::Colour inColour() { return juce::Colour (0xff7d8597); }
  35. juce::Colour outColour() { return colour::info; }
  36. // --- the scrolling level display shared by the limiter, compressor, gate and de-esser ----------------------
  37. // dB → y over a display area: a linear part from 0 to `knee` dB over the top 70 % and the rest down to `floor`
  38. struct LevelScale
  39. {
  40. float knee = -15.0f, floor = -48.0f, top = 0.0f;
  41. float y (float db, juce::Rectangle<float> a) const
  42. {
  43. const auto d = juce::jlimit (floor, top + 6.0f, db) - top;
  44. const auto k = knee - top;
  45. const auto f = d >= k ? 0.7f * d / k : 0.7f + 0.3f * (d - k) / (floor - knee);
  46. return a.getY() + a.getHeight() * f;
  47. }
  48. float db (float yy, juce::Rectangle<float> a) const
  49. {
  50. const auto f = (yy - a.getY()) / juce::jmax (1.0f, a.getHeight());
  51. const auto k = knee - top;
  52. return f <= 0.7f ? top + k * f / 0.7f : knee + (floor - knee) * (f - 0.7f) / 0.3f;
  53. }
  54. };
  55. void scaleLabels (juce::Graphics& g, const LevelScale& s, juce::Rectangle<float> a, float labelX, std::initializer_list<float> marks, bool lines = true)
  56. {
  57. g.setFont (font (type::caption));
  58. for (const auto m : marks)
  59. {
  60. const auto y = s.y (m, a);
  61. if (lines)
  62. {
  63. g.setColour (colour::gridBeat);
  64. g.drawHorizontalLine ((int) y, a.getX(), a.getRight());
  65. }
  66. g.setColour (colour::textDisabled);
  67. g.drawText (m == 0.0f ? juce::String ("0 dB") : juce::String ((int) m), juce::Rectangle<float> (labelX, y - 7.0f, 40.0f, 14.0f),
  68. juce::Justification::centredLeft, false);
  69. }
  70. }
  71. // =============================================================================================================
  72. // Apex Limiter — the reference limiter's workflow: the scrolling display is the window (input after gain in grey,
  73. // output in blue, gain reduction hanging from the top in red, the biggest reductions tagged), the GAIN slider on
  74. // its left edge, the output / gain-reduction meters on the right, the style / look-ahead / release / link panel at
  75. // the bottom left (folds away), true-peak and the output ceiling in the bottom bar.
  76. class ApexEditor final : public ProEditor
  77. {
  78. public:
  79. ApexEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::apexLimiter, d, 950, 600) { knobRanges = true; fillDemo(); }
  80. private:
  81. enum { idPanel = 1, idGain, idCeiling, idTp, idAdvanced, idLoudness, idLoudReset };
  82. // round tp172b4: the reference opens with its knob panel folded into the tab at the lower left (its idle view)
  83. bool panelOpen = false, advancedOpen = false;
  84. static constexpr const char* styles = "Clean|Glue|Punch|Dynamic|Dense|Loud|Bus|Safe";
  85. // the display / meter scale chosen with the meter-scale menu (round 128): −16 / −32 / −48 dB, K-12 / K-14 / K-20
  86. int meterScale() const { return apex::meterScale (v (apex::pMeterScale)); }
  87. LevelScale scaleNow() const
  88. {
  89. switch (meterScale())
  90. {
  91. case 0: return { -6.0f, -16.0f };
  92. case 1: return { -12.0f, -32.0f };
  93. case 3: return { -24.0f, -60.0f };
  94. case 4: return { -26.0f, -62.0f };
  95. case 5: return { -32.0f, -68.0f };
  96. default: return { -15.0f, -48.0f };
  97. }
  98. }
  99. float kOffset() const { const auto m = meterScale(); return m == 3 ? 12.0f : m == 4 ? 14.0f : m == 5 ? 20.0f : 0.0f; }
  100. float outHold = -120.0f, grHold = 0.0f;
  101. int holdAge = 0;
  102. // round 135: the display modes (Fast = 10 ms a pixel, Slow = 30 ms, Slow down = recent fast and the past
  103. // compressed, Infinite = 0.5 s a pixel from a long history, Off = meters only) and the loudness panel
  104. int displayMode() const { return apex::displayMode (v (apex::pDisplayMode)); }
  105. bool loudnessShown() const { return v (apex::pLoudnessShown) >= 0.5f; }
  106. bool truePeakMeter() const { return v (apex::pPeakMeter) >= 0.5f; }
  107. static constexpr int longSpan = 50; // history columns (10 ms) per column of the infinite history
  108. std::vector<Column> longHistory = std::vector<Column> ((std::size_t) historyLength);
  109. int longPos = 0, longCount = 0, seenPos = 0;
  110. Column longAcc;
  111. static void merge (Column& into, const Column& c)
  112. {
  113. into.in = juce::jmax (into.in, c.in);
  114. into.out = juce::jmax (into.out, c.out);
  115. into.gr = juce::jmax (into.gr, c.gr);
  116. }
  117. // the columns drawn, newest first (one per pixel)
  118. std::vector<Column> view (int n) const
  119. {
  120. std::vector<Column> out ((std::size_t) juce::jmax (0, n));
  121. const auto mode = displayMode();
  122. if (mode == 0)
  123. {
  124. for (int k = 0; k < n; ++k) out[(std::size_t) k] = columnBack (k);
  125. return out;
  126. }
  127. if (mode == 3 && ! demo)
  128. {
  129. for (int k = 0; k < n; ++k)
  130. {
  131. auto c = longHistory[(std::size_t) ((longPos - 1 - k + historyLength * 4) % historyLength)];
  132. if (k == 0) merge (c, longAcc);
  133. out[(std::size_t) k] = c;
  134. }
  135. return out;
  136. }
  137. // Slow: 3 columns a pixel; Slow down: 1 column a pixel at the right edge, the span growing to the left
  138. // (demo snapshots show the infinite mode as Slow)
  139. double start = 0.0;
  140. for (int k = 0; k < n; ++k)
  141. {
  142. const double span = mode == 2 ? 1.0 + 3.0 * ((double) k / juce::jmax (1, n)) * ((double) k / juce::jmax (1, n)) : 3.0;
  143. const auto a = (int) start, b = juce::jmax (a + 1, (int) (start + span));
  144. Column c { -120.0f, -120.0f, 0.0f };
  145. for (int j = a; j < b && j < historyLength; ++j) merge (c, columnBack (j));
  146. out[(std::size_t) k] = c;
  147. start += span;
  148. }
  149. return out;
  150. }
  151. juce::Rectangle<float> loudnessArea() const { return bodyArea().withTrimmedLeft (bodyArea().getWidth() - 196.0f).reduced (6.0f, 8.0f); }
  152. juce::String title() const override { return "Apex Limiter"; }
  153. juce::String gestures() const override { return tr ("Drag GAIN on the left - drag the red ceiling line - wheel on the display: gain"); }
  154. bool usesHistory() const override { return true; }
  155. float grDb() const override { return liveMeter (0) * 30.0f; }
  156. double gainDb() const { return apex::gainDb (v (0)); }
  157. double ceilingDb() const { return apex::ceilingDb (v (1)); }
  158. juce::Rectangle<float> display() const { return bodyArea().withTrimmedRight (104.0f + (loudnessShown() ? 196.0f : 0.0f)); }
  159. juce::Rectangle<float> plot() const { return display().withTrimmedTop (14.0f).withTrimmedBottom (6.0f); }
  160. juce::Rectangle<float> gainTrack() const
  161. {
  162. const auto p = plot();
  163. return { p.getX() + 14.0f, p.getY() + 6.0f, 34.0f, p.getHeight() * 0.62f };
  164. }
  165. juce::Rectangle<float> gainBox() const
  166. {
  167. const auto tr_ = gainTrack();
  168. const auto y = tr_.getBottom() - tr_.getHeight() * v (0);
  169. return { tr_.getX() - 4.0f, y - 11.0f, 50.0f, 22.0f };
  170. }
  171. juce::Rectangle<float> panel() const
  172. {
  173. const auto p = plot();
  174. return { p.getX() + 8.0f, p.getBottom() - 104.0f, 560.0f, 96.0f };
  175. }
  176. Column demoColumn (int i) const override
  177. {
  178. // gain into the ceiling, instant attack and the release recovering ~0.25 dB per column
  179. float gr = 0.0f;
  180. for (int k = 0; k < 80 && i - k >= 0; ++k)
  181. gr = juce::jmax (gr, demoInDb (i - k) + (float) gainDb() - (float) ceilingDb() - 0.25f * (float) k);
  182. const auto in = demoInDb (i);
  183. return { in, in + (float) gainDb() - gr, gr };
  184. }
  185. void layoutControls (std::vector<Ctl>& out) const override
  186. {
  187. out.push_back (custom (gainTrack().expanded (8.0f, 14.0f), idGain, 0));
  188. const auto d = plot();
  189. out.push_back (custom ({ d.getX() + 60.0f, scaleNow().y ((float) ceilingDb(), d) - 5.0f, d.getWidth() - 60.0f, 10.0f }, idCeiling, 1,
  190. tr ("Output ceiling: drag up or down (the bottom bar's Out does the same)")));
  191. // round tp172b4: the reference's strip at the display's lower right — TP, the loudness meters, the meter scale —
  192. // with the display speed left of it
  193. out.push_back (button ({ d.getRight() - 154.0f, d.getBottom() - 26.0f, 30.0f, 20.0f }, idTp, "TP", v (5) >= 0.5f,
  194. tr ("True peak: the ceiling also holds between the samples (4x interpolation)")));
  195. out.push_back (button ({ d.getRight() - 123.0f, d.getBottom() - 26.0f, 46.0f, 20.0f }, idLoudness, "LUFS", loudnessShown(),
  196. tr ("Loudness meter: momentary, short term and integrated LUFS, loudness range, peak")));
  197. {
  198. auto dm = menu ({ d.getRight() - 240.0f, d.getBottom() - 26.0f, 82.0f, 20.0f }, apex::pDisplayMode, {}, "Fast|Slow|Slow down|Infinite|Off");
  199. dm.hint = tr ("Display speed: Fast, Slow, Slow down (the past compressed), Infinite (the whole take), Off (meters only)");
  200. out.push_back (dm);
  201. }
  202. if (loudnessShown())
  203. {
  204. const auto la = loudnessArea();
  205. auto tgt = menu ({ la.getRight() - 84.0f, la.getY() + 4.0f, 80.0f, 20.0f }, apex::pLoudnessTarget, {}, "-23 LUFS|-18 LUFS|-16 LUFS|-14 LUFS|-11 LUFS|-9 LUFS");
  206. tgt.hint = tr ("Loudness target: the line on the loudness bars");
  207. out.push_back (tgt);
  208. out.push_back (tabs ({ la.getX() + 4.0f, la.getBottom() - 54.0f, la.getWidth() - 8.0f, 22.0f }, apex::pPeakMeter, "Sample peak|True peak"));
  209. out.push_back (button ({ la.getX() + 4.0f, la.getBottom() - 26.0f, la.getWidth() - 8.0f, 22.0f }, idLoudReset, tr ("Reset"), false,
  210. tr ("Reset the integrated loudness, the range and the peak hold")));
  211. }
  212. if (panelOpen)
  213. {
  214. const auto p = panel();
  215. out.push_back (button ({ p.getX() - 2.0f, p.getY() + 6.0f, 16.0f, 18.0f }, idPanel, juce::String::fromUTF8 ("\xc2\xab"), false, tr ("Hide the knobs")));
  216. out.push_back (menu ({ p.getX() + 16.0f, p.getY() + 40.0f, 96.0f, 26.0f }, apex::pStyle, {}, styles));
  217. out.push_back (knob ({ p.getX() + 122.0f, p.getY() + 22.0f, 68.0f, 72.0f }, apex::pLookahead, tr ("Lookahead")));
  218. out.push_back (knob ({ p.getX() + 192.0f, p.getY() + 22.0f, 68.0f, 72.0f }, apex::pAttack, tr ("Attack")));
  219. out.push_back (knob ({ p.getX() + 262.0f, p.getY() + 22.0f, 68.0f, 72.0f }, apex::pRelease, tr ("Release")));
  220. out.push_back (knob ({ p.getX() + 346.0f, p.getY() + 22.0f, 80.0f, 72.0f }, apex::pLink, tr ("Transients")));
  221. out.push_back (knob ({ p.getX() + 428.0f, p.getY() + 22.0f, 80.0f, 72.0f }, apex::pLinkRelease, tr ("Release")));
  222. out.push_back (button ({ p.getRight() - 30.0f, p.getY() + 4.0f, 26.0f, p.getHeight() - 8.0f }, idAdvanced,
  223. juce::String::fromUTF8 (advancedOpen ? "\xc2\xab" : "\xc2\xbb"), advancedOpen,
  224. tr ("Advanced: DC offset filter, unity gain, audition limiting, side-chain triggering")));
  225. if (advancedOpen)
  226. {
  227. const auto ad = advanced();
  228. out.push_back (toggle ({ ad.getX() + 10.0f, ad.getY() + 22.0f, ad.getWidth() - 20.0f, 17.0f }, apex::pDcFilter, tr ("DC offset filter")));
  229. out.push_back (toggle ({ ad.getX() + 10.0f, ad.getY() + 40.0f, ad.getWidth() - 20.0f, 17.0f }, apex::pUnity, tr ("Unity gain")));
  230. out.push_back (toggle ({ ad.getX() + 10.0f, ad.getY() + 58.0f, ad.getWidth() - 20.0f, 17.0f }, apex::pAudition, tr ("Audition limiting")));
  231. auto sc = toggle ({ ad.getX() + 10.0f, ad.getY() + 76.0f, ad.getWidth() - 20.0f, 17.0f }, apex::pSidechain, tr ("Side-chain triggering"));
  232. sc.hint = tr ("The limiter reacts to the slot's side-chain input (mixer: right-click the slot - Side chain)");
  233. out.push_back (sc);
  234. }
  235. }
  236. else // (its caption, CONTROLS, is written up the tab by paintBody)
  237. out.push_back (button ({ 0.0f, plot().getBottom() - 120.0f, 20.0f, 106.0f }, idPanel, {}, false, tr ("Show the knobs: style, look-ahead, attack, release, channel linking")));
  238. // the meter scale next to the TP button (bottom right of the display)
  239. {
  240. const auto d = plot();
  241. auto ms = menu ({ d.getRight() - 76.0f, d.getBottom() - 26.0f, 70.0f, 20.0f }, apex::pMeterScale, {}, "-16 dB|-32 dB|-48 dB|K-12|K-14|K-20");
  242. ms.hint = tr ("Meter scale of the display and the meters");
  243. out.push_back (ms);
  244. }
  245. const auto b = barArea();
  246. const auto cy = b.getCentreY();
  247. // round tp172b4: the reference's order — true peak limiting, oversampling, dither (then our noise shaping)
  248. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 160.0f, 22.0f }, apex::pTruePeak, tr ("True peak limiting"), "Off|On"));
  249. out.push_back (barMenu ({ 176.0f, cy - 11.0f, 140.0f, 22.0f }, apex::pOversampling, tr ("Oversampling"), "Off|2x|4x|8x"));
  250. out.push_back (barMenu ({ 322.0f, cy - 11.0f, 130.0f, 22.0f }, apex::pDither, tr ("Dither"), "Off|16 bits|18 bits|20 bits|22 bits|24 bits"));
  251. out.push_back (barMenu ({ 458.0f, cy - 11.0f, 160.0f, 22.0f }, apex::pShaping, tr ("Noise shaping"), "None|Basic|Optimized|Weighted"));
  252. out.push_back (barValue ({ b.getRight() - 150.0f, cy - 11.0f, 140.0f, 22.0f }, 1, tr ("Out")));
  253. out.push_back (barValue ({ b.getRight() - 300.0f, cy - 11.0f, 140.0f, 22.0f }, 0, tr ("Gain")));
  254. }
  255. juce::Rectangle<float> advanced() const
  256. {
  257. const auto pn = panel();
  258. return { pn.getRight() + 6.0f, pn.getY(), 170.0f, pn.getHeight() };
  259. }
  260. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  261. {
  262. if (c.id == idPanel) panelOpen = ! panelOpen;
  263. if (c.id == idAdvanced) advancedOpen = ! advancedOpen;
  264. if (c.id == idTp) set ({ { 5, v (5) >= 0.5f ? 0.0f : 1.0f } });
  265. if (c.id == idLoudness) set ({ { apex::pLoudnessShown, loudnessShown() ? 0.0f : 1.0f } });
  266. if (c.id == idLoudReset) set ({ { apex::pLoudnessReset, v (apex::pLoudnessReset) >= 0.5f ? 0.0f : 1.0f } }, false);
  267. repaint();
  268. }
  269. void customDown (const Ctl& c, const juce::MouseEvent& e) override
  270. {
  271. if (ui::isResetClick (e))
  272. {
  273. set ({ { c.param, (float) specFor (c.param).defaultValue } });
  274. return;
  275. }
  276. if (e.mods.isPopupMenu())
  277. {
  278. ui::showValueMenu (*this, &engine, specFor (c.param), v (c.param), [this, p = c.param] (double x) { set ({ { p, (float) x } }); });
  279. return;
  280. }
  281. customDrag (c, e);
  282. }
  283. void customDrag (const Ctl& c, const juce::MouseEvent& e) override
  284. {
  285. if (c.id == idGain)
  286. {
  287. const auto tr_ = gainTrack();
  288. auto x = (tr_.getBottom() - e.position.y) / tr_.getHeight();
  289. if (e.mods.isCtrlDown()) x = v (0) + (x - v (0)) * 0.25f;
  290. set ({ { 0, juce::jlimit (0.0f, 1.0f, x) } });
  291. ui::showValueTip (*this, gainBox().toNearestInt(), tr ("Gain") + " " + text (0));
  292. }
  293. else if (c.id == idCeiling)
  294. {
  295. const auto db = juce::jlimit (-30.0f, 0.0f, scaleNow().db (e.position.y, plot()));
  296. set ({ { 1, (float) (db / 30.0 + 1.0) } });
  297. ui::showValueTip (*this, juce::Rectangle<int> (60, 16).withCentre (e.position.toInt()), tr ("Out") + " " + text (1));
  298. }
  299. }
  300. bool bodyWheel (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
  301. {
  302. if (! plot().contains (e.position)) return false;
  303. const auto spec = specFor (0);
  304. if (const auto x = ui::wheelValue (v (0), e, w, spec))
  305. {
  306. set ({ { 0, (float) *x } });
  307. ui::flashValueTip (*this, gainBox().toNearestInt(), tr ("Gain") + " " + spec.text (*x));
  308. }
  309. return true;
  310. }
  311. ui::Hint bodyHint (juce::Point<float> p) override
  312. {
  313. ui::Hint h;
  314. if (plot().contains (p))
  315. h.text = tr ("Grey: the input after the gain; blue: the output; red from the top: the gain reduction. Wheel: gain");
  316. return h;
  317. }
  318. void tick() override
  319. {
  320. const auto& c = columnBack (0);
  321. if (++holdAge > 60) { outHold = -120.0f; grHold = 0.0f; holdAge = 0; }
  322. outHold = juce::jmax (outHold, truePeakMeter() && ! demo ? dbOf (liveMeter (3)) : c.out);
  323. grHold = juce::jmax (grHold, c.gr);
  324. // the infinite history: one column per 0.5 s (the loudest of its 50 columns)
  325. for (int guard = 0; seenPos != historyPos && guard < historyLength; ++guard)
  326. {
  327. merge (longAcc, history[(std::size_t) seenPos]);
  328. seenPos = (seenPos + 1) % historyLength;
  329. if (++longCount >= longSpan)
  330. {
  331. longHistory[(std::size_t) longPos] = longAcc;
  332. longPos = (longPos + 1) % historyLength;
  333. longAcc = { -120.0f, -120.0f, 0.0f };
  334. longCount = 0;
  335. }
  336. }
  337. }
  338. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  339. {
  340. const auto d = display();
  341. const auto p = plot();
  342. displayBackground (g, bodyArea());
  343. // the history, newest at the right edge
  344. const auto n = displayMode() == 4 ? 0 : (int) p.getWidth();
  345. const auto cols = view (n);
  346. const auto gain = (float) gainDb();
  347. juce::Path inPath, outPath, grPath, outLine;
  348. inPath.startNewSubPath (p.getRight(), p.getBottom());
  349. outPath.startNewSubPath (p.getRight(), p.getBottom());
  350. grPath.startNewSubPath (p.getRight(), p.getY());
  351. for (int k = 0; k < n; ++k)
  352. {
  353. const auto& c = cols[(std::size_t) k];
  354. const auto x = p.getRight() - (float) k;
  355. inPath.lineTo (x, scaleNow().y (c.in + gain, p));
  356. outPath.lineTo (x, scaleNow().y (c.out, p));
  357. grPath.lineTo (x, scaleNow().y (-c.gr, p));
  358. if (k == 0) outLine.startNewSubPath (x, scaleNow().y (c.out, p));
  359. else outLine.lineTo (x, scaleNow().y (c.out, p));
  360. }
  361. inPath.lineTo (p.getX(), p.getBottom());
  362. outPath.lineTo (p.getX(), p.getBottom());
  363. grPath.lineTo (p.getX(), p.getY());
  364. for (auto* path : { &inPath, &outPath, &grPath }) path->closeSubPath();
  365. fillLevel (g, inPath, inColour(), p, 0.55f, 0.22f);
  366. fillLevel (g, outPath, outColour(), p, 0.7f, 0.18f);
  367. g.setColour (colour::textPrimary.withAlpha (0.6f));
  368. g.strokePath (outLine, juce::PathStrokeType (1.0f)); // (no glow on the 100-column-a-second history: it is redrawn at 30 Hz)
  369. fillLevel (g, grPath, colour::accent, p, fx.enabled ? 0.8f : 0.25f, fx.enabled ? 0.35f : 0.1f);
  370. drawScale (g, p, d.getRight() + 6.0f);
  371. if (n == 0)
  372. {
  373. g.setColour (colour::textDisabled);
  374. g.setFont (font (type::small));
  375. g.drawText (tr ("Display off"), p.withTrimmedBottom (p.getHeight() * 0.5f), juce::Justification::centred, false);
  376. }
  377. // the biggest reductions, tagged (one tag per 1.5 s at most)
  378. g.setFont (font (type::caption, true));
  379. for (int k0 = 20; k0 + 150 < n; k0 += 150)
  380. {
  381. int best = -1;
  382. float bestGr = 1.0f;
  383. for (int k = k0; k < k0 + 150; ++k)
  384. if (cols[(std::size_t) k].gr > bestGr) { bestGr = cols[(std::size_t) k].gr; best = k; }
  385. if (best < 0) continue;
  386. const auto x = p.getRight() - (float) best;
  387. const auto r = juce::Rectangle<float> (46.0f, 16.0f).withCentre ({ x, scaleNow().y (-bestGr, p) + 12.0f });
  388. g.setColour (colour::bg3.withAlpha (0.92f));
  389. g.fillRoundedRectangle (r, 3.0f);
  390. g.setColour (colour::accent);
  391. g.drawRoundedRectangle (r, 3.0f, 1.0f);
  392. g.setColour (colour::textPrimary);
  393. g.drawText (juce::String (-bestGr, 1) + " dB", r, juce::Justification::centred, false);
  394. }
  395. // the ceiling line (red) with its value at the right
  396. const auto cy = scaleNow().y ((float) ceilingDb(), p);
  397. g.setColour (accent.withMultipliedBrightness (0.8f)); // round tp172b4: the reference's dimmer red
  398. g.drawHorizontalLine ((int) cy, p.getX(), p.getRight());
  399. g.setFont (font (type::caption, true));
  400. g.drawText (tr ("Out") + " " + text (1), juce::Rectangle<float> (p.getRight() - 130.0f, cy + 2.0f, 124.0f, 14.0f), juce::Justification::centredRight, false);
  401. // the GAIN slider on the left edge (round tp172b4: the reference's look — a column of dim red light from the top
  402. // of the display down to the slider's foot, framed on the left and below, a slate value box)
  403. const auto tr_ = gainTrack();
  404. {
  405. const auto col = juce::Rectangle<float> (tr_.getX() - 2.0f, p.getY() - 14.0f, tr_.getWidth() + 14.0f, tr_.getBottom() + 14.0f - (p.getY() - 14.0f));
  406. g.setGradientFill (juce::ColourGradient (accent.withAlpha (0.20f), col.getCentreX(), col.getY(), accent.withAlpha (0.0f), col.getRight() + 6.0f, col.getY(), false));
  407. g.fillRect (col);
  408. g.setGradientFill (juce::ColourGradient (juce::Colours::transparentBlack, 0.0f, col.getY(), colour::bg0.withAlpha (0.35f), 0.0f, col.getBottom(), false));
  409. g.fillRect (col);
  410. g.setColour (juce::Colours::white.withAlpha (0.16f));
  411. g.drawVerticalLine ((int) col.getX(), col.getY(), col.getBottom());
  412. g.drawHorizontalLine ((int) col.getBottom(), col.getX(), col.getRight());
  413. }
  414. const auto box = gainBox();
  415. const auto hot = box.expanded (6.0f).contains (mouse) || (dragCtl == -2 && pressed.id == idGain);
  416. g.setGradientFill (juce::ColourGradient (juce::Colour (hot ? 0xff6a7392 : 0xff5d6681), 0.0f, box.getY(), juce::Colour (hot ? 0xff4f5672 : 0xff474e66), 0.0f, box.getBottom(), false));
  417. g.fillRoundedRectangle (box, 4.0f);
  418. g.setColour (hot ? accent : juce::Colour (0xff2a2d3a));
  419. g.drawRoundedRectangle (box, 4.0f, 1.0f);
  420. g.setColour (colour::textPrimary);
  421. g.setFont (font (type::small, true));
  422. g.drawText ((gainDb() >= 0.05 ? "+" : "") + juce::String (gainDb(), 1), box, juce::Justification::centred, false);
  423. caption (g, juce::Rectangle<float> (tr_.getX() - 10.0f, tr_.getBottom() + 18.0f, 54.0f, 14.0f), tr ("Gain"));
  424. // the meters: output and gain reduction
  425. const auto m = juce::Rectangle<float> (d.getRight() + 46.0f, p.getY(), 52.0f, p.getHeight());
  426. const auto outR = m.withWidth (22.0f);
  427. const auto grR = m.withTrimmedLeft (28.0f);
  428. const auto newest = columnBack (0);
  429. const auto outY = scaleNow().y (truePeakMeter() && ! demo ? dbOf (liveMeter (3)) : newest.out, p);
  430. skin::meterSolid (g, outR, (outR.getBottom() - outY) / outR.getHeight(), outColour(), false);
  431. skin::meterSolid (g, grR, (scaleNow().y (-newest.gr, p) - grR.getY()) / grR.getHeight(), colour::accent, true);
  432. g.setColour (colour::bg0.withAlpha (0.5f));
  433. for (auto y = m.getY() + 3.0f; y < m.getBottom(); y += 3.0f) g.drawHorizontalLine ((int) y, m.getX(), m.getRight());
  434. g.setFont (font (type::caption, true));
  435. g.setColour (colour::ledOn);
  436. g.drawText (outHold > -100.0f ? juce::String (outHold, 1) : "-inf", outR.withY (d.getY()).withHeight (14.0f).expanded (6.0f, 0.0f), juce::Justification::centred, false);
  437. g.setColour (colour::accent);
  438. g.drawText (juce::String (-grHold, 1), grR.withY (d.getY()).withHeight (14.0f).expanded (6.0f, 0.0f), juce::Justification::centred, false);
  439. // the knob panel
  440. if (panelOpen)
  441. {
  442. const auto pn = panel();
  443. drawPanel (g, pn);
  444. caption (g, { pn.getX() + 16.0f, pn.getY() + 8.0f, 96.0f, 14.0f }, tr ("Style"));
  445. caption (g, { pn.getX() + 120.0f, pn.getY() + 8.0f, 212.0f, 14.0f }, tr ("Envelope"));
  446. caption (g, { pn.getX() + 340.0f, pn.getY() + 8.0f, 176.0f, 14.0f }, tr ("Channel linking"));
  447. g.setColour (colour::border);
  448. g.drawVerticalLine ((int) pn.getX() + 116, pn.getY() + 10.0f, pn.getBottom() - 10.0f);
  449. g.drawVerticalLine ((int) pn.getX() + 336, pn.getY() + 10.0f, pn.getBottom() - 10.0f);
  450. if (advancedOpen)
  451. {
  452. const auto ad = advanced();
  453. drawPanel (g, ad);
  454. caption (g, { ad.getX(), ad.getY() + 6.0f, ad.getWidth(), 14.0f }, tr ("Advanced"));
  455. }
  456. }
  457. // latency (constant: the maximum look-ahead, + the oversampler)
  458. {
  459. // on a dark plate at the top left of the display, right of the GAIN slider
  460. const auto lr = juce::Rectangle<float> (p.getX() + 64.0f, p.getY() + 2.0f, 132.0f, 15.0f);
  461. g.setColour (colour::textDisabled); // round tp172b4: plain dim text (the reference has no plate there)
  462. g.setFont (font (type::caption));
  463. g.drawText (tr ("latency {0} samples", { juce::String (apex::latencyFor (48000.0, apex::oversamplingFactor (v (apex::pOversampling)))) }),
  464. lr.reduced (5.0f, 0.0f), juce::Justification::centredLeft, true);
  465. }
  466. if (loudnessShown()) paintLoudness (g);
  467. }
  468. void paintOverlay (juce::Graphics& g, const EffectSlot&) override
  469. {
  470. if (! panelOpen) // the folded knob panel's tab: CONTROLS written up it, a » at its top
  471. {
  472. Ctl tab;
  473. for (const auto& c : controls())
  474. if (c.type == K::button && c.id == idPanel) tab = c;
  475. if (! tab.r.isEmpty())
  476. {
  477. g.setColour (colour::textSecondary);
  478. g.setFont (font (type::small, true));
  479. g.drawText (juce::String::fromUTF8 ("\xc2\xbb"), tab.r.withHeight (18.0f), juce::Justification::centred, false);
  480. g.saveState();
  481. g.addTransform (juce::AffineTransform::rotation (juce::MathConstants<float>::halfPi, tab.r.getCentreX(), tab.r.getCentreY() + 8.0f));
  482. g.setFont (font (type::caption, true));
  483. g.drawText (caps (tr ("Controls")), juce::Rectangle<float> (tab.r.getHeight() - 22.0f, 14.0f).withCentre ({ tab.r.getCentreX(), tab.r.getCentreY() + 8.0f }),
  484. juce::Justification::centred, false);
  485. g.restoreState();
  486. }
  487. }
  488. }
  489. // the loudness panel (round 135): short-term and momentary bars with the target line, integrated / range / peak
  490. void paintLoudness (juce::Graphics& g)
  491. {
  492. const auto la = loudnessArea();
  493. drawPanel (g, la);
  494. caption (g, { la.getX() + 6.0f, la.getY() + 7.0f, 90.0f, 14.0f }, tr ("Loudness"), juce::Justification::centredLeft);
  495. auto lufs = [this] (int k, float demoValue) { return demo ? demoValue : liveMeter (k); };
  496. const auto momentary = lufs (1, -11.8f), shortTerm = lufs (4, -12.6f), integrated = lufs (5, -13.1f), range = lufs (6, 5.4f), peak = lufs (7, -0.3f);
  497. const auto target = (float) apex::loudnessTarget (v (apex::pLoudnessTarget));
  498. // the bars: −48 … 0 LUFS
  499. const auto bars = juce::Rectangle<float> (la.getX() + 10.0f, la.getY() + 34.0f, 64.0f, la.getHeight() - 34.0f - 64.0f);
  500. auto bar = [&] (juce::Rectangle<float> r, float l, const juce::String& name) {
  501. const auto f = juce::jlimit (0.0f, 1.0f, (l + 48.0f) / 48.0f);
  502. skin::meterSolid (g, r.withTrimmedBottom (14.0f), f, l > target + 1.0f ? colour::accent : outColour(), false);
  503. caption (g, r.withTop (r.getBottom() - 13.0f), name);
  504. };
  505. bar (bars.withWidth (26.0f), shortTerm, "S");
  506. bar (bars.withTrimmedLeft (34.0f).withWidth (26.0f), momentary, "M");
  507. const auto meterH = bars.getHeight() - 14.0f;
  508. const auto ty = bars.getY() + meterH * (1.0f - juce::jlimit (0.0f, 1.0f, (target + 48.0f) / 48.0f));
  509. g.setColour (colour::textPrimary.withAlpha (0.8f));
  510. g.drawHorizontalLine ((int) ty, bars.getX() - 3.0f, bars.getRight() + 3.0f);
  511. g.setFont (font (type::caption));
  512. g.setColour (colour::textDisabled);
  513. for (int m = 0; m >= -48; m -= 12)
  514. g.drawText (juce::String (m), juce::Rectangle<float> (bars.getRight() + 2.0f, bars.getY() + meterH * (float) -m / 48.0f - 6.0f, 22.0f, 12.0f), juce::Justification::centredLeft, false);
  515. // the read-outs
  516. auto readout = [&] (float y, const juce::String& name, float value, const juce::String& unit, bool big) {
  517. const auto x = bars.getRight() + 26.0f, w = la.getRight() - x - 6.0f;
  518. g.setColour (colour::textDisabled);
  519. g.setFont (font (type::caption));
  520. g.drawText (name, juce::Rectangle<float> (x, y, w, 12.0f), juce::Justification::centredLeft, false);
  521. g.setColour (colour::textPrimary);
  522. g.setFont (font (big ? type::title : type::small, true));
  523. g.drawText (value <= -100.0f ? juce::String ("-inf") : juce::String (value, 1) + " " + unit, juce::Rectangle<float> (x, y + 12.0f, w, big ? 22.0f : 16.0f),
  524. juce::Justification::centredLeft, false);
  525. };
  526. auto y = bars.getY();
  527. readout (y, tr ("Integrated"), integrated, "LUFS", true); y += 40.0f;
  528. readout (y, tr ("Short term"), shortTerm, "LUFS", false); y += 32.0f;
  529. readout (y, tr ("Momentary"), momentary, "LUFS", false); y += 32.0f;
  530. readout (y, tr ("Range"), range, "LU", false); y += 32.0f;
  531. readout (y, truePeakMeter() ? tr ("True peak") : tr ("Peak"), peak, truePeakMeter() ? "dBTP" : "dB", false);
  532. }
  533. void paintCustom (juce::Graphics&, const Ctl&) override {}
  534. // the dB marks of the chosen meter scale (K scales are labelled relative to their 0 VU)
  535. void drawScale (juce::Graphics& g, juce::Rectangle<float> p, float labelX) const
  536. {
  537. const auto sc = scaleNow();
  538. const auto k = kOffset();
  539. std::vector<float> marks;
  540. switch (meterScale())
  541. {
  542. case 0: marks = { 0.0f, -2.0f, -4.0f, -6.0f, -9.0f, -12.0f, -16.0f }; break;
  543. case 1: marks = { 0.0f, -3.0f, -6.0f, -9.0f, -12.0f, -18.0f, -24.0f, -32.0f }; break;
  544. case 2: marks = { 0.0f, -3.0f, -6.0f, -9.0f, -12.0f, -15.0f, -24.0f, -36.0f }; break;
  545. default: for (float m = 8.0f; m >= -36.0f; m -= (m > -12.0f ? 4.0f : 12.0f)) marks.push_back (m - k); break;
  546. }
  547. g.setFont (font (type::caption));
  548. for (const auto m : marks)
  549. {
  550. const auto y = sc.y (m, p);
  551. g.setColour (colour::gridBeat);
  552. g.drawHorizontalLine ((int) y, p.getX(), p.getRight());
  553. g.setColour (colour::textDisabled);
  554. const auto label = k > 0.0f ? (m + k > 0.0f ? "+" : "") + juce::String ((int) std::lround (m + k)) : (m == 0.0f ? juce::String ("0 dB") : juce::String ((int) m));
  555. g.drawText (label, juce::Rectangle<float> (labelX, y - 7.0f, 40.0f, 14.0f), juce::Justification::centredLeft, false);
  556. }
  557. }
  558. };
  559. // =============================================================================================================
  560. // Hush De-esser — the reference de-esser's workflow: the scrolling waveform on top with the reduction marked in
  561. // red and the threshold line, the big THRESHOLD and RANGE knobs with the listen button, the frequency slider with
  562. // the detection region under them, the mode buttons in the middle, release / output on the right, the input and
  563. // reduction meters at the right edge.
  564. class HushEditor final : public ProEditor
  565. {
  566. public:
  567. HushEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::hushDeEsser, d, 720, 500)
  568. {
  569. knobRanges = true; // round tp172b4: each knob's scale under it, the value on hover
  570. fillDemo();
  571. if (! displayShown()) setSize (720, 500 - (int) waveH);
  572. }
  573. private:
  574. enum { idThreshold = 1, idFreq, idMeterThreshold, idDisplay, idExternal, idOutMeter, idGrMeter, idLink };
  575. float grHoldDb = 0.0f; // round 144: the attenuation meter's infinite peak hold (DeEsser's Attn meter), click to reset
  576. float outPeakDb = -100.0f; // round 135w: the output meter's highest peak since the last click (DeEsser's read-out)
  577. static constexpr float waveH = 194.0f; // the waveform display (DISPLAY hides it and the window shrinks)
  578. bool displayShown() const { return v (P ("Display")) >= 0.5f; }
  579. // which handle of the frequency slider is being dragged: 0 = high-pass (Frequency), 1 = low-pass
  580. int dragHandle = 0;
  581. static float freqPos (double hz) { return (float) (std::log (hz / 2000.0) / std::log (10.0)); } // 2 .. 20 kHz
  582. // round 165x: the extended law's high-pass reaches 20 kHz (the old law and the classic voicing: 16 kHz)
  583. bool ext() const { return v (P ("Range law")) >= 0.5f && v (P ("Voicing")) < 0.5f; }
  584. double hpHz() const { return mixsuite::hush::hpHz (v (pFreq()), ext()); }
  585. float hpPos() const { return freqPos (hpHz()); }
  586. // round 165x: the 0 … 200 % link knob as one 0 … 1 position (Stereo link fills the first half, Link only the second)
  587. float linkPos() const { return 0.5f * (v (P ("Stereo link")) + (v (P ("Stereo link")) >= 0.999f ? v (P ("Link only")) : 0.0f)); }
  588. void setLinkPos (double u)
  589. {
  590. u = juce::jlimit (0.0, 1.0, u);
  591. set ({ { P ("Stereo link"), (float) juce::jmin (1.0, 2.0 * u) }, { P ("Link only"), (float) juce::jmax (0.0, 2.0 * u - 1.0) } });
  592. }
  593. juce::String linkText() const
  594. {
  595. const auto u = linkPos();
  596. if (u <= 0.5f)
  597. return juce::String (juce::roundToInt (200.0f * u)) + " %";
  598. return "100 %, " + juce::String (juce::roundToInt (200.0f * u - 100.0f)) + " % " + (v (P ("Link only side")) >= 0.5f ? tr ("side only") : tr ("mid only"));
  599. }
  600. ui::ValueSpec linkSpec() const
  601. {
  602. auto spec = ui::percentSpec (tr ("Stereo link"), 0.5);
  603. spec.toText = [] (double u) { return u <= 0.5 ? juce::String (juce::roundToInt (200.0 * u)) + " %" : juce::String (juce::roundToInt (200.0 * u)) + " % (100 % + " + juce::String (juce::roundToInt (200.0 * u - 100.0)) + " %)"; };
  604. spec.fromText = ui::inverseOf (spec.toText, 0.0, 1.0);
  605. return spec;
  606. }
  607. float lpPos() const { return v (P ("Low-pass freq.")) >= 0.999f ? 1.0f : freqPos (mixsuite::hush::lowPassHz (v (P ("Low-pass freq.")))); }
  608. juce::String title() const override { return "Hush De-esser"; }
  609. juce::String gestures() const override { return tr ("Drag the threshold line or the meter's arrow - drag the frequency slider") ; }
  610. bool usesHistory() const override { return true; }
  611. float grDb() const override { return liveMeter (0) * 30.0f; }
  612. int pFreq() const { return P ("Frequency"); }
  613. int pThr() const { return P ("Threshold"); }
  614. juce::Rectangle<float> wave() const
  615. {
  616. // round 135w: 142 px on the right for the IN / GR / OUT meters and their scale (was 112: IN / GR)
  617. return displayShown() ? bodyArea().withTrimmedRight (142.0f).withHeight (190.0f).reduced (0.0f, 4.0f)
  618. : bodyArea().withTrimmedRight (142.0f).withHeight (0.0f).translated (0.0f, -4.0f);
  619. }
  620. // round 135w: the input meter moved left to make room for the output meter (In | GR | Out)
  621. juce::Rectangle<float> meters() const { return { (float) getWidth() - 100.0f, headerH + 18.0f, 26.0f, bodyArea().getHeight() - 26.0f }; }
  622. juce::Rectangle<float> outMeter() const { return meters().translated (56.0f, 0.0f).withWidth (16.0f).withTrimmedTop (12.0f).withTrimmedBottom (16.0f); }
  623. juce::Rectangle<float> freqTrack() const { return { 34.0f, wave().getBottom() + 182.0f, 250.0f, 24.0f }; }
  624. double thresholdDb() const { return mixsuite::hush::thresholdDb (v (pThr())); }
  625. // mirrored waveform: the height follows the amplitude (linear), like a waveform view; 0 dBFS at the edges
  626. float waveY (float db, bool upper) const
  627. {
  628. const auto a = wave();
  629. const auto f = juce::jlimit (0.0f, 1.0f, std::pow (10.0f, db / 20.0f));
  630. return upper ? a.getCentreY() - a.getHeight() * 0.48f * f : a.getCentreY() + a.getHeight() * 0.48f * f;
  631. }
  632. float meterY (float db) const
  633. {
  634. const auto m = meters();
  635. return m.getBottom() - m.getHeight() * juce::jlimit (0.0f, 1.0f, (db + 60.0f) / 60.0f);
  636. }
  637. Column demoColumn (int i) const override
  638. {
  639. // sibilant bursts every 0.8 s over speech
  640. const auto t = (double) i * 0.01;
  641. const auto s = std::fmod (t, 0.8);
  642. const auto in = demoInDb (i) - 4.0f + (float) (s > 0.42 && s < 0.56 ? 7.0 : 0.0);
  643. const auto over = in - (float) thresholdDb();
  644. const auto gr = juce::jlimit (0.0f, (float) mixsuite::hush::rangeDb (v (P ("Range"))), over > 0.0f ? over * 0.8f : 0.0f);
  645. return { in, in - gr, gr };
  646. }
  647. void layoutControls (std::vector<Ctl>& out) const override
  648. {
  649. const auto w = wave();
  650. const auto y0 = w.getBottom() + 10.0f;
  651. // threshold line on the waveform (both halves)
  652. if (displayShown())
  653. {
  654. out.push_back (custom ({ w.getX(), waveY ((float) thresholdDb(), true) - 5.0f, w.getWidth(), 10.0f }, idThreshold, pThr(), tr ("Threshold: drag up or down")));
  655. out.push_back (custom ({ w.getX(), waveY ((float) thresholdDb(), false) - 5.0f, w.getWidth(), 10.0f }, idThreshold, pThr(), tr ("Threshold: drag up or down")));
  656. }
  657. auto thr = knob ({ 44.0f, y0 + 4.0f, 110.0f, 142.0f }, pThr(), tr ("Threshold"), 2);
  658. thr.colour = colour::warning;
  659. out.push_back (thr);
  660. auto rng = knob ({ 170.0f, y0 + 4.0f, 110.0f, 142.0f }, P ("Range"), tr ("Range"), 2);
  661. rng.colour = colour::warning;
  662. out.push_back (rng);
  663. out.push_back (custom (freqTrack().expanded (0.0f, 4.0f), idFreq, pFreq(), tr ("Drag the left handle: where the band starts (high-pass); the right one: where it ends (low-pass, far right = off)")));
  664. auto aud = toggle ({ freqTrack().getCentreX() - 50.0f, freqTrack().getBottom() + 8.0f, 100.0f, 22.0f }, P ("Listen"), tr ("Audition"));
  665. aud.hint = tr ("Listen: hear only what the de-esser takes away (the detection band)");
  666. out.push_back (aud);
  667. // middle: display, mode, processing, side chain
  668. const auto mx = 304.0f;
  669. // round tp172b4: a dark tab, as the reference's (the display above shows whether it is on)
  670. out.push_back (button ({ mx + 40.0f, y0 - 2.0f, 110.0f, 20.0f }, idDisplay, tr ("Display"), false, tr ("Show or hide the scrolling display")));
  671. auto md = tabs ({ mx, y0 + 40.0f, 190.0f, 28.0f }, P ("Allround"), "Single vocal|Allround", { 0.0f, 1.0f });
  672. md.hint = tr ("Single vocal: one voice; Allround: a mix or other material (the sibilance must also stand out from the whole signal)");
  673. out.push_back (md);
  674. out.push_back (tabs ({ mx, y0 + 96.0f, 190.0f, 28.0f }, P ("Wideband"), "Wide band|Split band", { 1.0f, 0.0f }));
  675. out.push_back (custom ({ mx + 90.0f, y0 + 148.0f, 100.0f, 26.0f }, idExternal, P ("External SC"), tr ("Side chain: detect this signal (In) or another track (Ext)")));
  676. // right: stereo link (with MID) and look-ahead (with its power button)
  677. if (ext())
  678. {
  679. // round 165x: the reference's link knob runs 0 … 200 %: up to 100 % the channels share their detection (100 % =
  680. // the mid), past it a share of the processing acts on the mid (or side) signal only — one knob over Stereo link
  681. // and Link only
  682. out.push_back (custom ({ 512.0f, y0 + 2.0f, 84.0f, 90.0f }, idLink, P ("Stereo link"),
  683. tr ("Stereo link: up to 100 % the channels share their detection; past 100 % a share of the processing acts on the mid (or side) signal only")));
  684. auto ms = tabs ({ 516.0f, y0 + 96.0f, 76.0f, 18.0f }, P ("Link only side"), "Mid|Side", { 0.0f, 1.0f });
  685. ms.hint = tr ("Which signal the processing past 100 % link acts on alone: the mid or the side");
  686. out.push_back (ms);
  687. }
  688. else
  689. {
  690. auto link = knob ({ 512.0f, y0 + 2.0f, 84.0f, 90.0f }, P ("Stereo link"), tr ("Stereo link"));
  691. link.cap = juce::Colour (0xff53524f); // round tp172b4: the reference's small knobs are grey
  692. out.push_back (link);
  693. auto mid = toggle ({ 522.0f, y0 + 96.0f, 64.0f, 18.0f }, P ("Link mid"), "MID");
  694. mid.hint = tr ("Mid: detect on the middle of the stereo image only");
  695. out.push_back (mid);
  696. }
  697. auto lat = knob ({ 512.0f, y0 + 120.0f, 84.0f, 90.0f }, P ("Lookahead time"), tr ("Lookahead"));
  698. lat.cap = juce::Colour (0xff53524f);
  699. out.push_back (lat);
  700. auto la = toggle ({ 522.0f, y0 + 214.0f, 64.0f, 18.0f }, P ("Lookahead"), tr ("On"));
  701. la.hint = tr ("Look-ahead on / off");
  702. out.push_back (la);
  703. // the meter's threshold arrow
  704. out.push_back (custom ({ meters().getX() - 12.0f, meterY ((float) thresholdDb()) - 7.0f, 12.0f, 14.0f }, idMeterThreshold, pThr(), tr ("Threshold: drag up or down")));
  705. // round 135w: the output meter (−30 … 0 dBFS, the reference's), its peak read-out and clip lamp: click to reset
  706. // round 144: the reduction meter's held peak: click to reset (the reference's Attn meter)
  707. out.push_back (custom (meters().translated (32.0f, 0.0f).withWidth (14.0f).expanded (3.0f, 0.0f), idGrMeter, -1,
  708. tr ("Gain reduction (dB); the number and the line hold the deepest reduction; click to reset")));
  709. out.push_back (custom (outMeter().expanded (4.0f, 28.0f), idOutMeter, -1, tr ("Output level (peak, dBFS): the lamp lights when the output clips, the number holds the highest peak; click to reset")));
  710. const auto b = barArea();
  711. const auto cy = b.getCentreY();
  712. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 130.0f, 22.0f }, P ("Band detector"), tr ("Detection"), "High-pass|Band", { 0.0f, 1.0f }));
  713. out.push_back (barValue ({ 146.0f, cy - 11.0f, 110.0f, 22.0f }, P ("Release"), tr ("Release")));
  714. // round 135: oversampling (the reference's bottom bar; Hush's own voicing)
  715. out.push_back (barMenu ({ 262.0f, cy - 11.0f, 112.0f, 22.0f }, P ("Oversampling"), tr ("Oversampling"), "Off|2x|4x|8x"));
  716. // round 148: the measured single-vocal detector (Vocal voicing)
  717. auto vocal = barMenu ({ 380.0f, cy - 11.0f, 118.0f, 22.0f }, P ("Vocal voicing"), tr ("Detector"), "Hush|Vocal", { 0.0f, 1.0f });
  718. vocal.hint = tr ("Vocal: the measured single-vocal detector (sibilants that stand out from the voice)");
  719. out.push_back (vocal);
  720. out.push_back (barValue ({ b.getRight() - 214.0f, cy - 11.0f, 100.0f, 22.0f }, P ("Input"), tr ("In")));
  721. out.push_back (barValue ({ b.getRight() - 108.0f, cy - 11.0f, 100.0f, 22.0f }, P ("Output"), tr ("Out")));
  722. }
  723. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  724. {
  725. if (c.id == idDisplay)
  726. {
  727. const auto show = ! displayShown();
  728. set ({ { P ("Display"), show ? 1.0f : 0.0f } }, false);
  729. setSize (720, show ? 500 : 500 - (int) waveH);
  730. }
  731. repaint();
  732. }
  733. void showSideChainMenu()
  734. {
  735. const auto* fx = current();
  736. if (fx == nullptr) return;
  737. juce::PopupMenu menu;
  738. const auto ext = v (P ("External SC")) >= 0.5f;
  739. menu.addItem (tr ("In: detect this signal"), true, ! ext, [this] { set ({ { P ("External SC"), 0.0f } }); });
  740. juce::PopupMenu from;
  741. const auto assign = [this] (int source) {
  742. const auto p = P ("External SC");
  743. engine.editSong ([tk = track, sl = slot, source, p] (Song& s) {
  744. // round 177b: the pick makes the route (a level-0 send) as the mixer's picker does; a loop changes nothing
  745. if (mixerops::sidechainFrom (s, tk, sl, source) == mixerops::SidechainPick::cycle)
  746. return;
  747. auto& target = s.mixer[(std::size_t) tk].effects[(std::size_t) sl];
  748. target.params[(std::size_t) p] = source >= 0 ? 1.0f : 0.0f;
  749. });
  750. };
  751. const auto& song = engine.getSong();
  752. for (int t = 1; t < (int) song.mixer.size(); ++t)
  753. if (t != track)
  754. from.addItem (juce::String (t) + " " + juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()), true, ext && fx->sidechain == t, [assign, t] { assign (t); });
  755. menu.addSubMenu (tr ("Ext: side chain from"), from);
  756. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
  757. }
  758. void customDown (const Ctl& c, const juce::MouseEvent& e) override
  759. {
  760. if (c.id == idOutMeter)
  761. {
  762. outPeakDb = -100.0f;
  763. repaint();
  764. return;
  765. }
  766. if (c.id == idGrMeter) // round 144
  767. {
  768. grHoldDb = 0.0f;
  769. repaint();
  770. return;
  771. }
  772. if (c.id == idLink) // round 165x: the 0 … 200 % link knob
  773. {
  774. if (ui::isResetClick (e))
  775. setLinkPos (0.5);
  776. else if (e.mods.isPopupMenu())
  777. ui::showValueMenu (*this, nullptr, linkSpec(), linkPos(), [this] (double x) { setLinkPos (x); });
  778. else
  779. valueDrag.begin (e, linkPos());
  780. return;
  781. }
  782. if (c.id == idExternal)
  783. {
  784. const auto* fx = current();
  785. const auto ext = e.position.x >= c.r.getCentreX();
  786. if (ext && (fx == nullptr || fx->sidechain < 0 || e.mods.isPopupMenu())) showSideChainMenu();
  787. else set ({ { c.param, ext ? 1.0f : 0.0f } });
  788. return;
  789. }
  790. if (c.id == idFreq)
  791. {
  792. const auto x = (e.position.x - freqTrack().getX()) / freqTrack().getWidth();
  793. dragHandle = std::abs (x - lpPos()) < std::abs (x - hpPos()) ? 1 : 0;
  794. }
  795. if (ui::isResetClick (e))
  796. {
  797. const auto p = c.id == idFreq && dragHandle == 1 ? P ("Low-pass freq.") : c.param;
  798. set ({ { p, (float) specFor (p).defaultValue } });
  799. return;
  800. }
  801. if (e.mods.isPopupMenu())
  802. {
  803. ui::showValueMenu (*this, &engine, specFor (c.param), v (c.param), [this, p = c.param] (double x) { set ({ { p, (float) x } }); });
  804. return;
  805. }
  806. customDrag (c, e);
  807. }
  808. void customDrag (const Ctl& c, const juce::MouseEvent& e) override
  809. {
  810. if (c.id == idOutMeter || c.id == idGrMeter)
  811. return;
  812. if (c.id == idLink)
  813. {
  814. if (valueDrag.isActive())
  815. {
  816. setLinkPos (valueDrag.update (e, linkSpec()));
  817. ui::showValueTip (*this, c.r.toNearestInt(), linkText());
  818. }
  819. return;
  820. }
  821. if (c.id == idFreq)
  822. {
  823. const auto tr_ = freqTrack();
  824. const auto x = juce::jlimit (0.0, 1.0, (double) ((e.position.x - tr_.getX()) / tr_.getWidth()));
  825. const auto hz = 2000.0 * std::pow (10.0, x);
  826. if (dragHandle == 1)
  827. {
  828. const auto lp = P ("Low-pass freq.");
  829. set ({ { lp, x >= 0.985 ? 1.0f : invert ([] (float y) { return mixsuite::hush::lowPassHz (y); }, juce::jmax (hz, hpHz())) } });
  830. ui::showValueTip (*this, tr_.toNearestInt(), tr ("Low pass") + " " + text (lp));
  831. }
  832. else
  833. {
  834. set ({ { pFreq(), mixsuite::hush::hpValue (juce::jmin (hz, ext() ? 20000.0 : 16000.0), ext()) } });
  835. ui::showValueTip (*this, tr_.toNearestInt(), tr ("Frequency") + " " + text (pFreq()));
  836. }
  837. return;
  838. }
  839. float db;
  840. if (c.id == idMeterThreshold) db = (meters().getBottom() - e.position.y) / meters().getHeight() * 60.0f - 60.0f;
  841. else
  842. {
  843. const auto a = wave();
  844. const auto f = std::abs (e.position.y - a.getCentreY()) / (a.getHeight() * 0.48f);
  845. db = 20.0f * std::log10 (juce::jlimit (0.001f, 1.0f, f));
  846. }
  847. set ({ { pThr(), invert ([] (float x) { return mixsuite::hush::thresholdDb (x); }, juce::jlimit (-60.0f, 0.0f, db)) } });
  848. ui::showValueTip (*this, juce::Rectangle<int> (80, 16).withCentre (e.position.toInt()), tr ("Threshold") + " " + text (pThr()));
  849. }
  850. ui::Hint bodyHint (juce::Point<float> p) override
  851. {
  852. ui::Hint h;
  853. if (wave().contains (p))
  854. h.text = tr ("The voice scrolls by; red: what the de-esser takes away. Drag the dashed line to set the threshold");
  855. return h;
  856. }
  857. void paintCustom (juce::Graphics& g, const Ctl& c) override
  858. {
  859. if (c.id == idFreq)
  860. {
  861. const auto tr_ = freqTrack();
  862. const auto band = v (P ("Band detector")) >= 0.5f;
  863. const auto x1 = tr_.getX() + tr_.getWidth() * juce::jlimit (0.0f, 1.0f, hpPos());
  864. const auto x2 = tr_.getX() + tr_.getWidth() * juce::jlimit (0.0f, 1.0f, lpPos());
  865. g.setColour (colour::bg1);
  866. g.fillRoundedRectangle (tr_, 4.0f);
  867. // the detection region: between the two handles (band mode: a band around the left one, cut at the right one)
  868. g.setColour (colour::warning.withAlpha (0.35f));
  869. const auto left = band ? x1 - 34.0f : x1;
  870. const auto right = band ? juce::jmin (x1 + 34.0f, x2) : x2;
  871. g.fillRect (juce::Rectangle<float> (left, tr_.getY() + 2.0f, juce::jmax (1.0f, right - left), tr_.getHeight() - 4.0f).getIntersection (tr_));
  872. g.setColour (colour::borderStrong);
  873. g.drawRoundedRectangle (tr_, 4.0f, 1.0f);
  874. const auto hot = c.r.contains (mouse) || (dragCtl == -2 && pressed.id == idFreq);
  875. for (const auto [x, k] : { std::pair<float, int> { x1, 0 }, std::pair<float, int> { x2, 1 } })
  876. {
  877. juce::Path handle;
  878. handle.addTriangle (x - 9.0f, tr_.getBottom() - 1.0f, x + 9.0f, tr_.getBottom() - 1.0f, x, tr_.getY() + 2.0f);
  879. g.setColour (hot && dragHandle == k ? colour::textPrimary : colour::textSecondary);
  880. g.fillPath (handle);
  881. }
  882. g.setFont (font (type::small, true));
  883. g.setColour (colour::warning);
  884. g.drawText (text (pFreq()), juce::Rectangle<float> (tr_.getX() - 6.0f, tr_.getBottom() + 10.0f, 70.0f, 14.0f), juce::Justification::centredLeft, false);
  885. const auto lpOff = v (P ("Low-pass freq.")) >= 0.999f;
  886. g.drawText (lpOff ? juce::String ("20 kHz") : text (P ("Low-pass freq.")), juce::Rectangle<float> (tr_.getRight() - 64.0f, tr_.getBottom() + 10.0f, 70.0f, 14.0f),
  887. juce::Justification::centredRight, false);
  888. }
  889. else if (c.id == idLink)
  890. {
  891. const auto d = juce::jmin (c.r.getWidth() - 10.0f, c.r.getHeight() - 34.0f);
  892. const auto knobR = juce::Rectangle<float> (c.r.getCentreX() - d / 2.0f, c.r.getY() + 2.0f, d, d);
  893. const auto hover = c.r.contains (mouse), active = valueDrag.isActive() && pressed.id == idLink;
  894. skin::KnobLook look;
  895. look.value = linkPos();
  896. look.accent = accent;
  897. look.hover = hover ? 1.0f : 0.0f;
  898. look.active = active;
  899. look.enabled = current() == nullptr || current()->enabled;
  900. look.capTint = juce::Colour (0xff53524f); // round tp172b4: grey, as the other small knob
  901. skin::knob (g, knobR, look);
  902. // round tp172b4: its scale (0 … 200 %) under it, the value while hovered or dragged, then the caption
  903. const auto row = knobR.withY (knobR.getBottom() + 1.0f).withHeight (12.0f);
  904. if (hover || active)
  905. {
  906. g.setColour (skin::valueColour (true));
  907. g.setFont (font (type::caption, true));
  908. g.drawText (linkText(), row.expanded (40.0f, 0.0f), juce::Justification::centred, false);
  909. }
  910. else
  911. {
  912. g.setColour (colour::textDisabled);
  913. g.setFont (font (type::caption));
  914. g.drawText ("0 %", row.withWidth (row.getWidth() * 0.5f + 10.0f).translated (-10.0f, 0.0f), juce::Justification::centredLeft, false);
  915. g.drawText ("200 %", row.withTrimmedLeft (row.getWidth() * 0.5f - 10.0f).translated (10.0f, 0.0f), juce::Justification::centredRight, false);
  916. }
  917. g.setColour (skin::captionColour().interpolatedWith (colour::textPrimary, hover ? 0.5f : 0.0f));
  918. g.setFont (font (type::caption, true));
  919. g.drawText (caps (tr ("Stereo link")), juce::Rectangle<float> (c.r.getX() - 14.0f, knobR.getBottom() + 14.0f, c.r.getWidth() + 28.0f, 14.0f),
  920. juce::Justification::centred, false);
  921. }
  922. else if (c.id == idExternal)
  923. {
  924. const auto ext = v (c.param) >= 0.5f;
  925. const auto half = c.r.withWidth (c.r.getWidth() / 2.0f);
  926. skin::button (g, half, ! ext, half.contains (mouse), accent, radius::sm);
  927. skin::button (g, half.translated (half.getWidth(), 0.0f), ext, half.translated (half.getWidth(), 0.0f).contains (mouse), accent, radius::sm);
  928. g.setColour (colour::textPrimary);
  929. g.setFont (font (type::small, true));
  930. g.drawText (tr ("In"), half, juce::Justification::centred, false);
  931. g.drawText (tr ("Ext"), half.translated (half.getWidth(), 0.0f), juce::Justification::centred, false);
  932. caption (g, { c.r.getX() - 92.0f, c.r.getY(), 88.0f, c.r.getHeight() }, tr ("Side chain"), juce::Justification::centredRight);
  933. }
  934. else if (c.id == idMeterThreshold)
  935. {
  936. juce::Path a;
  937. const auto r = c.r;
  938. a.addTriangle (r.getX(), r.getY(), r.getX(), r.getBottom(), r.getRight(), r.getCentreY());
  939. g.setColour (colour::warning);
  940. g.fillPath (a);
  941. }
  942. }
  943. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  944. {
  945. const auto w = wave();
  946. displayBackground (g, bodyArea());
  947. if (displayShown())
  948. paintWave (g, fx, w);
  949. paintControlsArea (g, w);
  950. }
  951. void paintWave (juce::Graphics& g, const EffectSlot& fx, juce::Rectangle<float> w)
  952. {
  953. // round tp172b4: the waveform lies on the field (the reference's display has no well), faint level lines across
  954. g.setColour (juce::Colours::white.withAlpha (0.045f));
  955. for (const auto db : { -2.0f, -6.0f, -12.0f, -24.0f })
  956. for (const auto upper : { true, false })
  957. g.drawHorizontalLine ((int) waveY (db, upper), w.getX(), w.getRight());
  958. g.setColour (colour::gridBeat);
  959. g.drawHorizontalLine ((int) w.getCentreY(), w.getX(), w.getRight());
  960. const auto n = (int) w.getWidth();
  961. juce::Path inP, outP;
  962. for (int k = 0; k < n; ++k)
  963. {
  964. const auto& c = columnBack (k);
  965. const auto x = w.getRight() - (float) k;
  966. inP.addRectangle (x, waveY (c.in, true), 1.0f, juce::jmax (1.0f, waveY (c.in, false) - waveY (c.in, true)));
  967. outP.addRectangle (x, waveY (c.out, true), 1.0f, juce::jmax (1.0f, waveY (c.out, false) - waveY (c.out, true)));
  968. }
  969. g.setColour (colour::accent.withAlpha (fx.enabled ? 0.8f : 0.25f)); // the reduction = input − output
  970. g.fillPath (inP);
  971. g.setGradientFill (juce::ColourGradient (accent.withAlpha (0.95f), 0.0f, w.getY(), juce::Colour (0xffc8ccd6).withAlpha (0.9f), 0.0f, w.getCentreY(), true));
  972. if (! outP.isEmpty()) g.fillPath (outP); // (round 170c: an empty path with a gradient flooded macOS editors)
  973. // threshold lines
  974. const auto dashes = std::array<float, 2> { 6.0f, 4.0f };
  975. g.setColour (colour::warning.withAlpha (0.9f));
  976. for (const auto upper : { true, false })
  977. {
  978. const auto y = waveY ((float) thresholdDb(), upper);
  979. g.drawDashedLine (juce::Line<float> (w.getX(), y, w.getRight(), y), dashes.data(), 2, 1.2f);
  980. }
  981. g.setFont (font (type::caption, true));
  982. g.drawText (tr ("Threshold") + " " + text (pThr()), juce::Rectangle<float> (w.getX() + 6.0f, waveY ((float) thresholdDb(), true) - 16.0f, 160.0f, 14.0f),
  983. juce::Justification::centredLeft, false);
  984. }
  985. void paintControlsArea (juce::Graphics& g, juce::Rectangle<float> w)
  986. {
  987. // the control area
  988. // round tp172b4: the knobs sit on the field itself (no card), as in the reference
  989. caption (g, { 304.0f, w.getBottom() + 34.0f, 190.0f, 14.0f }, tr ("Mode"));
  990. caption (g, { 304.0f, w.getBottom() + 90.0f, 190.0f, 14.0f }, tr ("Processing"));
  991. // meters: input level and reduction, with the dB scale between them
  992. const auto m = meters();
  993. const auto newest = columnBack (0);
  994. drawMeter (g, m, newest.in, -60.0f, colour::meterLow.withAlpha (0.85f));
  995. // round 147: the detector's energy (what the threshold is compared with, DeEsser's Energy Detector) as a
  996. // blue bar inside the input meter, against the same scale as the threshold arrow
  997. if (const auto det = liveMeter (1); det > 0.0f)
  998. {
  999. const auto y = juce::jlimit (m.getY(), m.getBottom(), meterY (det * 60.0f - 60.0f));
  1000. g.setColour (juce::Colour (0xff4aa3df).withAlpha (0.9f));
  1001. g.fillRect (juce::Rectangle<float> (m.getCentreX() - 3.0f, y, 6.0f, m.getBottom() - y));
  1002. }
  1003. const auto grR = m.translated (32.0f, 0.0f).withWidth (14.0f);
  1004. g.setColour (colour::bg1);
  1005. g.fillRect (grR);
  1006. g.setColour (colour::accent);
  1007. g.fillRect (grR.withHeight (grR.getHeight() * juce::jlimit (0.0f, 1.0f, newest.gr / 24.0f)));
  1008. // round 144: the held peak (a line on the bar and the number under it), as the reference's Attn meter
  1009. grHoldDb = juce::jmax (grHoldDb, newest.gr);
  1010. if (grHoldDb > 0.05f)
  1011. {
  1012. g.setColour (colour::textPrimary);
  1013. g.fillRect (grR.withY (grR.getY() + grR.getHeight() * juce::jlimit (0.0f, 1.0f, grHoldDb / 24.0f) - 1.0f).withHeight (2.0f));
  1014. }
  1015. g.setFont (font (type::caption));
  1016. g.setColour (colour::textSecondary);
  1017. g.drawText (juce::String (grHoldDb, 1), juce::Rectangle<float> (grR.getX() - 8.0f, grR.getBottom() - 13.0f, grR.getWidth() + 16.0f, 12.0f), juce::Justification::centred, false);
  1018. g.setFont (font (type::caption));
  1019. g.setColour (colour::textDisabled);
  1020. for (const auto db : { 0.0f, -6.0f, -12.0f, -24.0f, -36.0f, -48.0f })
  1021. g.drawText (juce::String ((int) db), juce::Rectangle<float> (m.getX() - 34.0f, meterY (db) - 6.0f, 20.0f, 12.0f), juce::Justification::centredRight, false);
  1022. caption (g, { m.getX() - 6.0f, m.getY() - 16.0f, 38.0f, 14.0f }, tr ("In"));
  1023. caption (g, { grR.getX() - 10.0f, m.getY() - 16.0f, 34.0f, 14.0f }, "GR");
  1024. // round 135w: the output meter, −30 … 0 dBFS, a clip lamp above it and the highest peak under it
  1025. const auto o = outMeter();
  1026. outPeakDb = juce::jmax (outPeakDb, newest.out);
  1027. drawMeter (g, o, newest.out, -30.0f, colour::meterLow.withAlpha (0.85f));
  1028. const auto lamp = juce::Rectangle<float> (o.getX(), o.getY() - 10.0f, o.getWidth(), 6.0f);
  1029. g.setColour (outPeakDb > -0.1f ? juce::Colour (0xffe5383b) : colour::bg1);
  1030. g.fillRoundedRectangle (lamp, 2.0f);
  1031. caption (g, { o.getX() - 10.0f, m.getY() - 16.0f, 36.0f, 14.0f }, tr ("Out"));
  1032. g.setFont (font (type::caption));
  1033. g.setColour (outPeakDb > -0.1f ? juce::Colour (0xffe5383b) : colour::textSecondary);
  1034. g.drawText (outPeakDb > -99.0f ? juce::String (outPeakDb, 1) : juce::String ("-inf"), juce::Rectangle<float> (o.getX() - 10.0f, o.getBottom() + 2.0f, o.getWidth() + 20.0f, 12.0f),
  1035. juce::Justification::centred, false);
  1036. }
  1037. };
  1038. // =============================================================================================================
  1039. // Crest Compressor — the reference compressor's workflow: the display is the window (input in grey, output in
  1040. // blue, the gain reduction as a red line from the top, the threshold as a dashed line that can be dragged), the
  1041. // knee / transfer curve slides out from the left edge, the knobs float over the bottom of the display (THRESHOLD,
  1042. // RATIO, the style button, ATTACK, RELEASE; KNEE, RANGE, LOOKAHEAD, HOLD under them; make-up gain and mix on the
  1043. // right), and the side chain opens below the display.
  1044. class CrestEditor final : public ProEditor
  1045. {
  1046. public:
  1047. CrestEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::crestCompressor, d, 860, 560) { knobRanges = true; fillDemo(); }
  1048. private:
  1049. enum { idThreshold = 1, idKnee, idSideChain, idInMeter, idScNode0 = 10 };
  1050. // the display's level scale: the meter-scale setting (9 … 90 dB) is its floor, the upper 70 % shows its top 42 %
  1051. LevelScale sc() const
  1052. {
  1053. const auto range = (float) dyn::crest::meterRangeDb (v (dyn::crest::meterScale));
  1054. return { -range * 30.0f / 72.0f, -range };
  1055. }
  1056. bool kneeOpen = true, scOpen = false; // round tp172b4: the transfer curve shows by default, as in the reference
  1057. static constexpr float scH = 170.0f;
  1058. int scDrag = -1;
  1059. juce::String title() const override { return "Crest Compressor"; }
  1060. juce::String gestures() const override { return tr ("Drag the dashed threshold line - KNEE on the left: the curve - SIDE CHAIN: the detector"); }
  1061. bool usesHistory() const override { return true; }
  1062. float grDb() const override { return liveMeter (0) * 30.0f; }
  1063. juce::Rectangle<float> main() const { return bodyArea().withTrimmedBottom (scOpen ? scH : 0.0f); }
  1064. juce::Rectangle<float> plot() const { return main().withTrimmedRight (100.0f).withTrimmedTop (10.0f).withTrimmedBottom (8.0f); }
  1065. juce::Rectangle<float> scPanel() const { return { 0.0f, main().getBottom(), (float) getWidth(), scH }; }
  1066. // round tp172b4: down to just above the knob row's Auto toggles (it covered them)
  1067. juce::Rectangle<float> kneeArea() const { auto p = plot(); return { p.getX(), p.getY(), juce::jmin (330.0f, p.getWidth() * 0.42f), juce::jmax (80.0f, p.getHeight() - 222.0f) }; }
  1068. double thresholdDb() const { return dyn::crest::thresholdDb (v (dyn::crest::threshold)); }
  1069. Column demoColumn (int i) const override
  1070. {
  1071. const auto* fx = current();
  1072. const auto in = demoInDb (i) + 6.0f;
  1073. float gr = 0.0f;
  1074. if (fx != nullptr)
  1075. for (int k = 0; k < 30 && i - k >= 0; ++k)
  1076. gr = juce::jmax (gr, (float) -dyn::crest::staticGainDb (fx->params, demoInDb (i - k) + 6.0f) - 0.4f * (float) k);
  1077. return { in, in - gr, gr };
  1078. }
  1079. void layoutControls (std::vector<Ctl>& out) const override
  1080. {
  1081. using namespace dyn::crest;
  1082. const auto p = plot();
  1083. out.push_back (custom ({ p.getX() + 24.0f, sc().y ((float) thresholdDb(), p) - 5.0f, p.getWidth() - 24.0f, 10.0f }, idThreshold, threshold,
  1084. tr ("Threshold: drag up or down")));
  1085. out.push_back (button ({ kneeOpen ? kneeArea().getRight() : p.getX(), p.getY() + 80.0f, 20.0f, 64.0f }, idKnee,
  1086. juce::String::fromUTF8 (kneeOpen ? "\xc2\xab" : "\xc2\xbb"), false, tr ("Knee: show the transfer curve"))); // (a grey tab, as the reference's)
  1087. // the knob row over the bottom of the display
  1088. const auto by = p.getBottom() - 190.0f;
  1089. out.push_back (knob ({ 96.0f, by, 104.0f, 118.0f }, threshold, tr ("Threshold"), 2));
  1090. out.push_back (toggle ({ 108.0f, by - 26.0f, 80.0f, 20.0f }, autoThreshold, tr ("Auto")));
  1091. out.push_back (knob ({ 214.0f, by, 104.0f, 118.0f }, ratio, tr ("Ratio"), 2));
  1092. // round tp172b4: the style button at the knobs' height, then the character and the voicing under it (labelled),
  1093. // where the reference keeps its character control
  1094. // round tp172b4 (second pass): the style a single pill button at the knobs' height, as the reference's; the
  1095. // character and the voicing (LYNX's) small text buttons under it ("Character: Warm")
  1096. {
  1097. auto st = menu ({ 334.0f, by + 30.0f, 96.0f, 24.0f }, style, {}, "Clean|Allround|Punch|Upward|Two-way|Vari-mu|Classic|Opto|Vocal|Bus|Pumping");
  1098. st.look = 1;
  1099. out.push_back (st);
  1100. }
  1101. out.push_back (barMenu ({ 318.0f, by + 62.0f, 128.0f, 18.0f }, character, tr ("Character"), "Off|Warm|Crisp|Bright"));
  1102. // round tp172b2: Pro-C 3's Smooth / Op-El / Mastering characters, a voicing over the style
  1103. out.push_back (barMenu ({ 318.0f, by + 82.0f, 128.0f, 18.0f }, voicing, tr ("Voicing"), "None|Smooth|Op-El|Mastering"));
  1104. out.push_back (knob ({ 446.0f, by, 104.0f, 118.0f }, attack, tr ("Attack"), 2));
  1105. out.push_back (knob ({ 564.0f, by, 104.0f, 118.0f }, release, tr ("Release"), 2));
  1106. out.push_back (toggle ({ 576.0f, by - 26.0f, 80.0f, 20.0f }, autoRelease, tr ("Auto")));
  1107. out.push_back (knob ({ 680.0f, by - 6.0f, 62.0f, 82.0f }, P ("Output"), tr ("Gain"), 1, true));
  1108. out.push_back (toggle ({ 670.0f, by + 76.0f, 82.0f, 20.0f }, autoGain, tr ("Auto gain")));
  1109. out.push_back (knob ({ 680.0f, by + 100.0f, 62.0f, 82.0f }, dryGain, tr ("Dry")));
  1110. // the display's scale (bottom right, like the reference's dB box) and the input meter switch
  1111. out.push_back (menu ({ p.getRight() - 16.0f, p.getBottom() - 20.0f, 60.0f, 20.0f }, meterScale, {}, "9 dB|18 dB|36 dB|72 dB|90 dB"));
  1112. out.push_back (button ({ p.getRight() + 42.0f, main().getY(), 18.0f, 12.0f }, idInMeter, "IN", v (inputMeter) >= 0.5f,
  1113. tr ("Input meter: show or hide")));
  1114. // round tp172b4 (second pass): KNEE, RANGE, LOOKAHEAD and HOLD as the reference's short curved bars under the big
  1115. // knobs (DRIVE, LYNX's, the same in the middle), the side-chain button under them
  1116. const auto sy = p.getBottom() - 70.0f;
  1117. for (const auto& [x, prm, cap] : { std::tuple<float, int, juce::String> { 108.0f, (int) knee, tr ("Knee") }, { 226.0f, (int) range, tr ("Range") },
  1118. { 342.0f, (int) drive, tr ("Drive") }, { 458.0f, (int) lookahead, tr ("Lookahead") },
  1119. { 576.0f, (int) hold, tr ("Hold") } })
  1120. {
  1121. auto bar = knob ({ x, sy, 80.0f, 46.0f }, prm, cap, 0);
  1122. bar.look = 1;
  1123. out.push_back (bar);
  1124. }
  1125. out.push_back (button ({ 334.0f, sy + 48.0f, 96.0f, 20.0f }, idSideChain, tr ("Side chain"), scOpen, tr ("Open the side chain: detector EQ, level, external input, stereo link")));
  1126. if (scOpen)
  1127. {
  1128. const auto s = scPanel();
  1129. out.push_back (toggle ({ 14.0f, s.getY() + 14.0f, 104.0f, 22.0f }, scListen, tr ("Listen")));
  1130. out.push_back (tabs ({ 14.0f, s.getY() + 44.0f, 104.0f, 24.0f }, scExternal, "Int|Ext"));
  1131. out.push_back (knob ({ 130.0f, s.getY() + 12.0f, 70.0f, 82.0f }, scLevel, tr ("Level"), 1, true));
  1132. out.push_back (knob ({ 130.0f, s.getY() + 92.0f, 70.0f, 70.0f }, stereoLink, tr ("Stereo link"), 0));
  1133. out.push_back (menu ({ 14.0f, s.getY() + 108.0f, 104.0f, 22.0f }, linkMode, tr ("Link mode"), "Stereo|Mid only|Side only|Mid > side|Side > mid"));
  1134. for (int b = 0; b < scBands; ++b)
  1135. out.push_back (menu ({ 216.0f, s.getY() + 16.0f + 46.0f * (float) b, 92.0f, 22.0f }, scParam (b, 0), {},
  1136. "Off|Bell|Low shelf|High shelf|Low cut|High cut|Notch|Band pass|Tilt shelf"));
  1137. out.push_back (custom (scEqArea(), idScNode0, -1, tr ("Detector EQ: drag a node (frequency / gain), wheel = Q")));
  1138. // round 135: the wet (compressed) and dry paths' stereo balance, at the panel's right end
  1139. out.push_back (knob ({ s.getRight() - 136.0f, s.getY() + 14.0f, 62.0f, 82.0f }, wetPan, tr ("Wet pan"), 0, true));
  1140. out.push_back (knob ({ s.getRight() - 70.0f, s.getY() + 14.0f, 62.0f, 82.0f }, dryPan, tr ("Dry pan"), 0, true));
  1141. // round 137: the trigger (the reference's side-chain Host Sync / MIDI inputs): the detector hears a pulse
  1142. const auto tx = s.getRight() - 268.0f;
  1143. out.push_back (menu ({ tx, s.getY() + 16.0f, 120.0f, 22.0f }, trigger, tr ("Trigger"), "Off|Host sync|MIDI"));
  1144. const auto trig = triggerOf (v (trigger));
  1145. if (trig == Trigger::hostSync)
  1146. {
  1147. out.push_back (menu ({ tx, s.getY() + 46.0f, 120.0f, 22.0f }, triggerSync, tr ("Note"), "1/1|1/2|1/4|1/8|1/16"));
  1148. out.push_back (knob ({ tx, s.getY() + 74.0f, 58.0f, 78.0f }, triggerRate, tr ("Rate"), 0));
  1149. out.push_back (knob ({ tx + 62.0f, s.getY() + 74.0f, 58.0f, 78.0f }, triggerLength, tr ("Length"), 0));
  1150. }
  1151. else if (trig == Trigger::midi)
  1152. out.push_back (knob ({ tx + 20.0f, s.getY() + 50.0f, 80.0f, 92.0f }, triggerChannel, tr ("Channel"), 0));
  1153. }
  1154. const auto b = barArea();
  1155. const auto cy = b.getCentreY();
  1156. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 150.0f, 22.0f }, oversampling, tr ("Oversampling"), "Off|2x|4x|8x"));
  1157. out.push_back (barMenu ({ 165.0f, cy - 11.0f, 140.0f, 22.0f }, maxLookahead, tr ("Lookahead"), "Off|1 ms|2 ms|5 ms|10 ms|20 ms"));
  1158. out.push_back (barMenu ({ 310.0f, cy - 11.0f, 125.0f, 22.0f }, characterPre, tr ("Character"), "Post|Pre"));
  1159. out.push_back (barValue ({ 440.0f, cy - 11.0f, 110.0f, 22.0f }, mix, tr ("Mix")));
  1160. out.push_back (barValue ({ b.getRight() - 300.0f, cy - 11.0f, 140.0f, 22.0f }, P ("Input"), tr ("In")));
  1161. out.push_back (barValue ({ b.getRight() - 150.0f, cy - 11.0f, 140.0f, 22.0f }, P ("Output"), tr ("Out")));
  1162. }
  1163. juce::Rectangle<float> scEqArea() const
  1164. {
  1165. const auto s = scPanel();
  1166. return { 320.0f, s.getY() + 10.0f, s.getWidth() - 334.0f - 140.0f - 132.0f, s.getHeight() - 20.0f }; // round 137: − the trigger column
  1167. }
  1168. float scX (double hz) const
  1169. {
  1170. const auto a = scEqArea();
  1171. return a.getX() + a.getWidth() * (float) (std::log (juce::jlimit (20.0, 20000.0, hz) / 20.0) / std::log (1000.0));
  1172. }
  1173. float scY (double db) const
  1174. {
  1175. const auto a = scEqArea();
  1176. return a.getCentreY() - a.getHeight() * 0.5f * juce::jlimit (-1.0f, 1.0f, (float) db / 24.0f);
  1177. }
  1178. juce::Point<float> scNode (int b) const
  1179. {
  1180. using namespace dyn::crest;
  1181. return { scX (facet::hz (v (scParam (b, 1)))), scY (facet::gainDb (v (scParam (b, 2)))) };
  1182. }
  1183. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  1184. {
  1185. if (c.id == idKnee) kneeOpen = ! kneeOpen;
  1186. if (c.id == idInMeter) set ({ { dyn::crest::inputMeter, v (dyn::crest::inputMeter) >= 0.5f ? 0.0f : 1.0f } });
  1187. if (c.id == idSideChain)
  1188. {
  1189. scOpen = ! scOpen;
  1190. setSize (getWidth(), getHeight() + (int) (scOpen ? scH : -scH));
  1191. }
  1192. repaint();
  1193. }
  1194. void customDown (const Ctl& c, const juce::MouseEvent& e) override
  1195. {
  1196. if (c.id == idScNode0)
  1197. {
  1198. scDrag = -1;
  1199. for (int b = 0; b < dyn::crest::scBands; ++b)
  1200. if (facet::shape (v (dyn::crest::scParam (b, 0))) != facet::Shape::off && scNode (b).getDistanceFrom (e.position) < 10.0f)
  1201. scDrag = b;
  1202. return;
  1203. }
  1204. if (ui::isResetClick (e)) { set ({ { c.param, (float) specFor (c.param).defaultValue } }); return; }
  1205. if (e.mods.isPopupMenu())
  1206. {
  1207. ui::showValueMenu (*this, &engine, specFor (c.param), v (c.param), [this, p = c.param] (double x) { set ({ { p, (float) x } }); });
  1208. return;
  1209. }
  1210. customDrag (c, e);
  1211. }
  1212. void customDrag (const Ctl& c, const juce::MouseEvent& e) override
  1213. {
  1214. using namespace dyn::crest;
  1215. if (c.id == idScNode0)
  1216. {
  1217. if (scDrag < 0) return;
  1218. const auto a = scEqArea();
  1219. const auto hz = 20.0 * std::pow (1000.0, juce::jlimit (0.0, 1.0, (double) ((e.position.x - a.getX()) / a.getWidth())));
  1220. const auto db = juce::jlimit (-24.0, 24.0, (double) ((a.getCentreY() - e.position.y) / (a.getHeight() * 0.5f)) * 24.0);
  1221. set ({ { scParam (scDrag, 1), facet::hzValue (hz) }, { scParam (scDrag, 2), facet::gainValue (db) } });
  1222. ui::showValueTip (*this, juce::Rectangle<int> (16, 16).withCentre (scNode (scDrag).toInt()), text (scParam (scDrag, 1)) + " " + text (scParam (scDrag, 2)));
  1223. return;
  1224. }
  1225. const auto db = juce::jlimit (-60.0f, 0.0f, sc().db (e.position.y, plot()));
  1226. set ({ { threshold, invert ([] (float x) { return dyn::crest::thresholdDb (x); }, db) } });
  1227. ui::showValueTip (*this, juce::Rectangle<int> (80, 16).withCentre (e.position.toInt()), tr ("Threshold") + " " + text (threshold));
  1228. }
  1229. bool bodyWheel (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
  1230. {
  1231. if (! scOpen || ! scEqArea().contains (e.position)) return false;
  1232. for (int b = 0; b < dyn::crest::scBands; ++b)
  1233. if (scNode (b).getDistanceFrom (e.position) < 14.0f)
  1234. {
  1235. const auto p = dyn::crest::scParam (b, 3);
  1236. if (const auto x = ui::wheelValue (v (p), e, w, specFor (p))) set ({ { p, (float) *x } });
  1237. return true;
  1238. }
  1239. return false;
  1240. }
  1241. void paintCustom (juce::Graphics& g, const Ctl& c) override
  1242. {
  1243. if (c.id != idScNode0) return;
  1244. const auto* fx = current();
  1245. if (fx == nullptr) return;
  1246. dynui::History none;
  1247. dynui::paint (g, "crestsceq", c.r, 1.0f, *fx, [] (int) { return 0.0f; }, none);
  1248. for (int b = 0; b < dyn::crest::scBands; ++b)
  1249. {
  1250. if (facet::shape (v (dyn::crest::scParam (b, 0))) == facet::Shape::off) continue;
  1251. const auto n = scNode (b);
  1252. g.setColour (peqview::bandColour (b));
  1253. g.fillEllipse (juce::Rectangle<float> (12.0f, 12.0f).withCentre (n));
  1254. g.setColour (colour::bg0);
  1255. g.setFont (font (type::caption, true));
  1256. g.drawText (juce::String (b + 1), juce::Rectangle<float> (12.0f, 12.0f).withCentre (n), juce::Justification::centred, false);
  1257. }
  1258. }
  1259. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  1260. {
  1261. const auto m = main();
  1262. const auto p = plot();
  1263. displayBackground (g, bodyArea());
  1264. {
  1265. // the marks of the chosen scale: six steps over the upper part, two more down to the floor
  1266. const auto s = sc();
  1267. const auto step = -s.knee / 5.0f;
  1268. const auto lower = std::round ((s.knee + s.floor) * 0.5f / 3.0f) * 3.0f; // one mark between the knee and the floor
  1269. const float marks[] { 0.0f, -step, -2.0f * step, -3.0f * step, -4.0f * step, s.knee, lower };
  1270. g.setFont (font (type::caption));
  1271. for (const auto mk : marks)
  1272. {
  1273. const auto y = s.y (mk, p);
  1274. g.setColour (colour::gridBeat);
  1275. g.drawHorizontalLine ((int) y, p.getX(), p.getRight());
  1276. g.setColour (colour::textDisabled);
  1277. const auto label = mk == 0.0f ? juce::String ("0 dB")
  1278. : std::abs (mk) < 10.0f && std::abs (mk - std::round (mk)) > 0.05f ? juce::String (mk, 1) : juce::String (juce::roundToInt (mk));
  1279. g.drawText (label, juce::Rectangle<float> (p.getRight() + 8.0f, y - 6.0f, 34.0f, 12.0f), juce::Justification::centredLeft, false);
  1280. }
  1281. }
  1282. const auto n = (int) p.getWidth();
  1283. juce::Path inP, outLine, grLine;
  1284. inP.startNewSubPath (p.getRight(), p.getBottom());
  1285. for (int k = 0; k < n; ++k)
  1286. {
  1287. const auto& c = columnBack (k);
  1288. const auto x = p.getRight() - (float) k;
  1289. inP.lineTo (x, sc().y (c.in, p));
  1290. const juce::Point<float> o { x, sc().y (c.out, p) }, r { x, sc().y (-c.gr, p) };
  1291. if (k == 0) { outLine.startNewSubPath (o); grLine.startNewSubPath (r); }
  1292. else { outLine.lineTo (o); grLine.lineTo (r); }
  1293. }
  1294. inP.lineTo (p.getX(), p.getBottom());
  1295. inP.closeSubPath();
  1296. fillLevel (g, inP, inColour(), p, 0.42f, 0.12f);
  1297. g.setColour (outColour().withAlpha (0.9f));
  1298. g.strokePath (outLine, juce::PathStrokeType (1.2f));
  1299. g.setColour (colour::accent.withAlpha (fx.enabled ? 1.0f : 0.3f));
  1300. g.strokePath (grLine, juce::PathStrokeType (2.0f));
  1301. // threshold
  1302. const auto ty = sc().y ((float) thresholdDb(), p);
  1303. const auto dashes = std::array<float, 2> { 7.0f, 5.0f };
  1304. g.setColour (colour::textSecondary);
  1305. g.drawDashedLine (juce::Line<float> (p.getX(), ty, p.getRight(), ty), dashes.data(), 2, 1.2f);
  1306. g.setFont (font (type::caption, true));
  1307. g.drawText (text (dyn::crest::threshold), juce::Rectangle<float> (p.getRight() - 90.0f, ty - 16.0f, 84.0f, 14.0f), juce::Justification::centredRight, false);
  1308. // a darker band under the knobs keeps them readable over the history
  1309. const auto knobs = juce::Rectangle<float> (p.getX(), p.getBottom() - 206.0f, p.getWidth(), 206.0f);
  1310. g.setGradientFill (juce::ColourGradient (colour::bg0.withAlpha (0.0f), 0.0f, knobs.getY(), colour::bg0.withAlpha (0.85f), 0.0f, knobs.getY() + 60.0f, false));
  1311. g.fillRect (knobs);
  1312. // the transfer curve, slid out from the left
  1313. if (kneeOpen)
  1314. {
  1315. // round tp172b4: as the reference draws it — a plain light line on the field (no box, no fill), the unity
  1316. // diagonal faint, a divider at the panel's edge, the live input as a dot
  1317. const auto k = kneeArea();
  1318. constexpr float lo = -60.0f;
  1319. const auto xOf = [&k] (float db) { return k.getX() + k.getWidth() * (db - lo) / -lo; };
  1320. const auto yOf = [&k] (float db) { return k.getBottom() - k.getHeight() * (juce::jlimit (lo, 0.0f, db) - lo) / -lo; };
  1321. g.setColour (colour::textDisabled.withAlpha (0.35f));
  1322. g.drawLine (k.getX(), k.getBottom(), k.getRight(), k.getY(), 1.0f);
  1323. g.drawVerticalLine ((int) k.getRight(), k.getY(), k.getBottom());
  1324. juce::Path curve;
  1325. for (int i = 0; i <= 120; ++i)
  1326. {
  1327. const auto in = lo + -lo * (float) i / 120.0f;
  1328. const juce::Point<float> pt { xOf (in), yOf (in + (float) dyn::crest::staticGainDb (fx.params, in)) };
  1329. if (i == 0) curve.startNewSubPath (pt); else curve.lineTo (pt);
  1330. }
  1331. g.setColour (fx.enabled ? colour::textSecondary : colour::textDisabled);
  1332. g.strokePath (curve, juce::PathStrokeType (1.6f));
  1333. const auto lm = liveMeter (2);
  1334. const auto live = lm > 1e-6f ? 20.0f * std::log10 (lm) : -120.0f;
  1335. if (fx.enabled && live > lo)
  1336. {
  1337. g.setColour (colour::textPrimary);
  1338. g.fillEllipse (juce::Rectangle<float> (6.0f, 6.0f).withCentre ({ xOf (live), yOf (live + (float) dyn::crest::staticGainDb (fx.params, live)) }));
  1339. }
  1340. }
  1341. // meters: input, output and gain reduction
  1342. const auto mr = juce::Rectangle<float> (p.getRight() + 46.0f, p.getY(), 50.0f, p.getHeight());
  1343. const auto nw = columnBack (0);
  1344. if (v (dyn::crest::inputMeter) >= 0.5f)
  1345. drawMeter (g, mr.withWidth (14.0f), nw.in, -60.0f, colour::meterLow.withAlpha (0.8f));
  1346. drawMeter (g, mr.withX (mr.getX() + 17.0f).withWidth (14.0f), nw.out, -60.0f, outColour());
  1347. const auto gr = mr.withX (mr.getX() + 34.0f).withWidth (14.0f);
  1348. skin::meterSolid (g, gr, (sc().y (-nw.gr, p) - gr.getY()) / juce::jmax (1.0f, gr.getHeight()), colour::accent, true);
  1349. g.setFont (font (type::caption));
  1350. g.setColour (colour::textDisabled);
  1351. g.drawText ("OUT GR", mr.withY (m.getY()).withHeight (12.0f).withTrimmedLeft (17.0f).expanded (6.0f, 0.0f), juce::Justification::centred, false);
  1352. if (scOpen)
  1353. {
  1354. const auto s = scPanel();
  1355. g.setColour (colour::bg2);
  1356. g.fillRect (s);
  1357. g.setColour (colour::border);
  1358. g.drawHorizontalLine ((int) s.getY(), 0.0f, s.getRight());
  1359. for (int b = 0; b < dyn::crest::scBands; ++b)
  1360. caption (g, { 216.0f, s.getY() + 40.0f + 46.0f * (float) b, 92.0f, 12.0f }, tr ("Band {0}", { juce::String (b + 1) }));
  1361. }
  1362. }
  1363. dynui::History none;
  1364. };
  1365. // =============================================================================================================
  1366. // Sentry Gate — the reference gate's workflow: THRESHOLD (big) with RATIO and RANGE on the left, the display in the
  1367. // middle (the input level scrolling behind the transfer curve, the threshold dashed — drag it), the style button and
  1368. // ATTACK / RELEASE on the right with HOLD, KNEE and LOOKAHEAD beside them, the EXPERT strip (side chain, filters,
  1369. // upward expansion, dry, output) opening below.
  1370. class SentryEditor final : public ProEditor
  1371. {
  1372. public:
  1373. SentryEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::sentryGate, d, 730, 380) { knobRanges = true; fillDemo(); }
  1374. private:
  1375. enum { idThreshold = 1, idExpert, idFilters };
  1376. bool expertOpen = false;
  1377. static constexpr float expertH = 240.0f;
  1378. int filterDrag = -1;
  1379. juce::String title() const override { return "Sentry Gate"; }
  1380. juce::String gestures() const override { return tr ("Drag the dashed threshold - EXPERT: side chain and filters"); }
  1381. bool usesHistory() const override { return true; }
  1382. float grDb() const override { return liveMeter (0) * 30.0f; }
  1383. juce::Rectangle<float> main() const { return bodyArea().withTrimmedBottom (expertOpen ? expertH : 0.0f); }
  1384. juce::Rectangle<float> disp() const { const auto m = main(); return { 196.0f, m.getY() + 12.0f, 270.0f, m.getHeight() - 58.0f }; }
  1385. juce::Rectangle<float> expert() const { return { 0.0f, main().getBottom(), (float) getWidth(), expertH }; }
  1386. double thresholdDb() const { return dyn::sentry::thresholdDb (v (dyn::sentry::threshold)); }
  1387. float yDb (float db) const { const auto d = disp(); return d.getY() + d.getHeight() * juce::jlimit (0.0f, 1.0f, -db / 66.0f); }
  1388. float xDb (float db) const { const auto d = disp(); return d.getX() + d.getWidth() * juce::jlimit (0.0f, 1.0f, (db + 66.0f) / 66.0f); }
  1389. juce::Rectangle<float> filterTrack() const { const auto e = expert(); return { 240.0f, e.getY() + 60.0f, 220.0f, 22.0f }; }
  1390. Column demoColumn (int i) const override
  1391. {
  1392. const auto* fx = current();
  1393. const auto in = demoInDb (i) - 8.0f;
  1394. const auto g = fx != nullptr ? (float) -dyn::sentry::staticGainDb (fx->params, in) : 0.0f;
  1395. return { in, in - g, juce::jmax (0.0f, g) };
  1396. }
  1397. void layoutControls (std::vector<Ctl>& out) const override
  1398. {
  1399. using namespace dyn::sentry;
  1400. const auto m = main();
  1401. const auto d = disp();
  1402. out.push_back (custom ({ d.getX(), yDb ((float) thresholdDb()) - 5.0f, d.getWidth(), 10.0f }, idThreshold, threshold, tr ("Threshold: drag up or down")));
  1403. out.push_back (custom ({ xDb ((float) thresholdDb()) - 5.0f, d.getY(), 10.0f, d.getHeight() }, idThreshold, threshold, tr ("Threshold: drag left or right")));
  1404. out.push_back (knob ({ 30.0f, m.getY() + 18.0f, 130.0f, 152.0f }, threshold, tr ("Threshold"), 2));
  1405. out.push_back (knob ({ 10.0f, m.getY() + 182.0f, 84.0f, 104.0f }, ratio, tr ("Ratio")));
  1406. out.push_back (knob ({ 98.0f, m.getY() + 182.0f, 84.0f, 104.0f }, range, tr ("Range")));
  1407. out.push_back (menu ({ 530.0f, m.getY() + 12.0f, 100.0f, 26.0f }, style, {}, "Classic|Clean|Vocal|Guitar|Upward"));
  1408. if (v (ducking) >= 0.5f)
  1409. out.push_back (toggle ({ 530.0f, m.getY() + 39.0f, 100.0f, 14.0f }, ducking, tr ("Ducking")));
  1410. out.push_back (knob ({ 530.0f, m.getY() + 54.0f, 100.0f, 108.0f }, attack, tr ("Attack")));
  1411. out.push_back (knob ({ 530.0f, m.getY() + 178.0f, 100.0f, 108.0f }, release, tr ("Release")));
  1412. // round tp172b4: the reference's small knobs have darker slate caps
  1413. for (const auto& [y, prm, cap] : { std::tuple<float, int, juce::String> { 8.0f, (int) hold, tr ("Hold") }, { 102.0f, (int) knee, tr ("Knee") },
  1414. { 196.0f, (int) lookahead, tr ("Lookahead") } })
  1415. {
  1416. auto k = knob ({ 644.0f, m.getY() + y, 76.0f, 88.0f }, prm, cap, 0);
  1417. k.cap = juce::Colour (0xff4f5370);
  1418. out.push_back (k);
  1419. }
  1420. out.push_back (toggle ({ 646.0f, m.getY() + 290.0f, 72.0f, 20.0f }, lookaheadOn, tr ("On")));
  1421. out.push_back (button ({ d.getCentreX() - 60.0f, m.getBottom() - 30.0f, 120.0f, 24.0f }, idExpert, tr ("Expert"), expertOpen,
  1422. tr ("Expert: side chain (internal / external, gain and mix per channel), side-chain filters, upward expansion, ducking, wet / dry level and pan")));
  1423. if (expertOpen)
  1424. {
  1425. const auto e = expert();
  1426. out.push_back (knob ({ 14.0f, e.getY() + 14.0f, 84.0f, 100.0f }, upThreshold, tr ("Up threshold")));
  1427. out.push_back (knob ({ 104.0f, e.getY() + 14.0f, 84.0f, 100.0f }, upRatio, tr ("Up ratio")));
  1428. out.push_back (tabs ({ filterTrack().getCentreX() - 70.0f, e.getY() + 18.0f, 140.0f, 24.0f }, scExternal, "Int|Ext"));
  1429. out.push_back (custom (filterTrack().expanded (8.0f, 6.0f), idFilters, -1, tr ("Side-chain filters: drag the left handle (high pass) or the right one (low pass)")));
  1430. out.push_back (toggle ({ filterTrack().getCentreX() - 50.0f, filterTrack().getBottom() + 14.0f, 100.0f, 22.0f }, scListen, tr ("Audition")));
  1431. out.push_back (knob ({ 530.0f, e.getY() + 14.0f, 84.0f, 100.0f }, dry, tr ("Dry")));
  1432. out.push_back (knob ({ 630.0f, e.getY() + 14.0f, 84.0f, 100.0f }, P ("Output"), tr ("Output"), 1, true));
  1433. // round 128: the side-chain gain and mix of each detector channel (left / right, or mid / side), ducking,
  1434. // the wet and dry pans
  1435. const bool msMode = v (channelMode) >= 0.5f;
  1436. const auto ry = e.getY() + 130.0f;
  1437. out.push_back (knob ({ 10.0f, ry, 70.0f, 96.0f }, scGainL, msMode ? tr ("Gain M") : tr ("Gain L"), 1, true));
  1438. out.push_back (knob ({ 80.0f, ry, 70.0f, 96.0f }, scMixL, msMode ? tr ("Mix M") : tr ("Mix L"), 0, true));
  1439. out.push_back (knob ({ 160.0f, ry, 70.0f, 96.0f }, scGainR, msMode ? tr ("Gain S") : tr ("Gain R"), 1, true));
  1440. out.push_back (knob ({ 230.0f, ry, 70.0f, 96.0f }, scMixR, msMode ? tr ("Mix S") : tr ("Mix R"), 0, true));
  1441. out.push_back (toggle ({ 330.0f, ry + 36.0f, 110.0f, 22.0f }, ducking, tr ("Ducking")));
  1442. out.push_back (knob ({ 530.0f, ry, 84.0f, 96.0f }, wetPan, tr ("Wet pan"), 0, true));
  1443. out.push_back (knob ({ 630.0f, ry, 84.0f, 96.0f }, dryPan, tr ("Dry pan"), 0, true));
  1444. }
  1445. const auto b = barArea();
  1446. const auto cy = b.getCentreY();
  1447. // round 135: the oversampling menu (Pro-G's bottom bar); the look-ahead switch stays under its knob
  1448. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 140.0f, 22.0f }, oversampling, tr ("Oversampling"), "Off|2x|4x|8x"));
  1449. out.push_back (barMenu ({ 155.0f, cy - 11.0f, 145.0f, 22.0f }, scExternal, tr ("Side chain"), "Internal|External"));
  1450. out.push_back (barMenu ({ 305.0f, cy - 11.0f, 150.0f, 22.0f }, channelMode, tr ("Channel mode"), "Left/Right|Mid/Side"));
  1451. out.push_back (barValue ({ b.getRight() - 275.0f, cy - 11.0f, 128.0f, 22.0f }, input, tr ("In")));
  1452. out.push_back (barValue ({ b.getRight() - 142.0f, cy - 11.0f, 132.0f, 22.0f }, P ("Output"), tr ("Out")));
  1453. }
  1454. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  1455. {
  1456. if (c.id == idExpert)
  1457. {
  1458. expertOpen = ! expertOpen;
  1459. setSize (getWidth(), getHeight() + (int) (expertOpen ? expertH : -expertH));
  1460. }
  1461. repaint();
  1462. }
  1463. void customDown (const Ctl& c, const juce::MouseEvent& e) override
  1464. {
  1465. using namespace dyn::sentry;
  1466. if (c.id == idFilters)
  1467. {
  1468. const auto t = filterTrack();
  1469. const auto xh = t.getX() + t.getWidth() * v (highPass), xl = t.getX() + t.getWidth() * v (lowPass);
  1470. filterDrag = std::abs (e.position.x - xh) < std::abs (e.position.x - xl) ? highPass : lowPass;
  1471. if (ui::isResetClick (e)) { set ({ { filterDrag, filterDrag == highPass ? 0.0f : 1.0f } }); filterDrag = -1; return; }
  1472. customDrag (c, e);
  1473. return;
  1474. }
  1475. if (ui::isResetClick (e)) { set ({ { c.param, (float) specFor (c.param).defaultValue } }); return; }
  1476. if (e.mods.isPopupMenu())
  1477. {
  1478. ui::showValueMenu (*this, &engine, specFor (c.param), v (c.param), [this, p = c.param] (double x) { set ({ { p, (float) x } }); });
  1479. return;
  1480. }
  1481. customDrag (c, e);
  1482. }
  1483. void customDrag (const Ctl& c, const juce::MouseEvent& e) override
  1484. {
  1485. using namespace dyn::sentry;
  1486. if (c.id == idFilters)
  1487. {
  1488. if (filterDrag < 0) return;
  1489. const auto t = filterTrack();
  1490. set ({ { filterDrag, juce::jlimit (0.0f, 1.0f, (e.position.x - t.getX()) / t.getWidth()) } });
  1491. ui::showValueTip (*this, t.toNearestInt(), text (filterDrag));
  1492. return;
  1493. }
  1494. const auto d = disp();
  1495. const auto vertical = c.r.getWidth() < 20.0f; // the vertical line moves left / right
  1496. const auto db = vertical ? (e.position.x - d.getX()) / d.getWidth() * 66.0f - 66.0f : -(e.position.y - d.getY()) / d.getHeight() * 66.0f;
  1497. set ({ { threshold, invert ([] (float x) { return dyn::sentry::thresholdDb (x); }, juce::jlimit (-60.0f, 0.0f, db)) } });
  1498. ui::showValueTip (*this, juce::Rectangle<int> (80, 16).withCentre (e.position.toInt()), tr ("Threshold") + " " + text (threshold));
  1499. }
  1500. void paintCustom (juce::Graphics& g, const Ctl& c) override
  1501. {
  1502. using namespace dyn::sentry;
  1503. if (c.id != idFilters) return;
  1504. const auto t = filterTrack();
  1505. const auto xh = t.getX() + t.getWidth() * v (highPass), xl = t.getX() + t.getWidth() * v (lowPass);
  1506. g.setColour (colour::bg1);
  1507. g.fillRoundedRectangle (t, 4.0f);
  1508. g.setColour (colour::info.withAlpha (0.35f));
  1509. g.fillRect (juce::Rectangle<float> (xh, t.getY() + 2.0f, juce::jmax (0.0f, xl - xh), t.getHeight() - 4.0f));
  1510. for (const auto x : { xh, xl })
  1511. {
  1512. g.setColour (colour::textPrimary);
  1513. g.fillRoundedRectangle (juce::Rectangle<float> (8.0f, t.getHeight() + 6.0f).withCentre ({ x, t.getCentreY() }), 2.0f);
  1514. }
  1515. g.setFont (font (type::small));
  1516. g.setColour (colour::warning);
  1517. g.drawText (text (highPass), juce::Rectangle<float> (t.getX() - 30.0f, t.getBottom() + 4.0f, 80.0f, 14.0f), juce::Justification::centredLeft, false);
  1518. g.drawText (text (lowPass), juce::Rectangle<float> (t.getRight() - 50.0f, t.getBottom() + 4.0f, 80.0f, 14.0f), juce::Justification::centredRight, false);
  1519. caption (g, { t.getX(), t.getY() - 16.0f, t.getWidth(), 14.0f }, tr ("Side-chain filters"));
  1520. }
  1521. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  1522. {
  1523. using namespace dyn::sentry;
  1524. const auto d = disp();
  1525. skin::canvas (g, bodyArea(), accent);
  1526. // round tp172b4: the transfer graph lies on the field (the reference draws no well), only its grid
  1527. // the input level scrolling behind (newest at the right), on the vertical dB scale
  1528. const auto n = (int) d.getWidth();
  1529. juce::Path in;
  1530. in.startNewSubPath (d.getRight(), d.getBottom());
  1531. for (int k = 0; k < n; ++k)
  1532. in.lineTo (d.getRight() - (float) k, yDb (columnBack (k / 2).in));
  1533. in.lineTo (d.getX(), d.getBottom());
  1534. in.closeSubPath();
  1535. fillLevel (g, in, inColour(), d, 0.45f, 0.12f);
  1536. // grid and labels
  1537. g.setFont (font (type::caption));
  1538. for (int db = 0; db >= -60; db -= 10)
  1539. {
  1540. g.setColour (colour::gridBeat);
  1541. g.drawHorizontalLine ((int) yDb ((float) db), d.getX(), d.getRight());
  1542. g.drawVerticalLine ((int) xDb ((float) db), d.getY(), d.getBottom());
  1543. g.setColour (colour::textDisabled);
  1544. g.drawText (juce::String (db), juce::Rectangle<float> (d.getRight() + 6.0f, yDb ((float) db) - 6.0f, 26.0f, 12.0f), juce::Justification::centredLeft, false);
  1545. g.drawText (juce::String (db), juce::Rectangle<float> (xDb ((float) db) - 14.0f, d.getBottom() + 4.0f, 28.0f, 12.0f), juce::Justification::centred, false);
  1546. }
  1547. // the transfer curve (input → output)
  1548. juce::Path curve;
  1549. for (int i = 0; i <= 132; ++i)
  1550. {
  1551. const auto inDb = -66.0f + (float) i * 0.5f;
  1552. const auto outDb = inDb + (float) staticGainDb (fx.params, inDb);
  1553. const juce::Point<float> pt { xDb (inDb), yDb (outDb) };
  1554. if (i == 0) curve.startNewSubPath (pt);
  1555. else curve.lineTo (pt);
  1556. }
  1557. if (! fx.enabled)
  1558. skin::glowStroke (g, curve, colour::textDisabled, 2.2f, 0.0f);
  1559. else
  1560. {
  1561. g.setColour (accent.withAlpha (0.25f));
  1562. g.strokePath (curve, juce::PathStrokeType (6.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1563. g.setColour (colour::textPrimary);
  1564. g.strokePath (curve, juce::PathStrokeType (2.2f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1565. }
  1566. // the live input on the curve
  1567. const auto now = columnBack (0).in;
  1568. if (now > -66.0f)
  1569. {
  1570. g.setColour (colour::accent);
  1571. g.fillEllipse (juce::Rectangle<float> (8.0f, 8.0f).withCentre ({ xDb (now), yDb (now + (float) staticGainDb (fx.params, now)) }));
  1572. }
  1573. // threshold
  1574. const auto dashes = std::array<float, 2> { 5.0f, 4.0f };
  1575. const auto tx = xDb ((float) thresholdDb()), ty = yDb ((float) thresholdDb());
  1576. g.setColour (colour::warning.withAlpha (0.85f));
  1577. g.drawDashedLine (juce::Line<float> (d.getX(), ty, d.getRight(), ty), dashes.data(), 2, 1.0f);
  1578. g.drawDashedLine (juce::Line<float> (tx, d.getY(), tx, d.getBottom()), dashes.data(), 2, 1.0f);
  1579. // meter: input level and gain reduction (round tp172b4: slim dark slots, a pale level, as the reference's)
  1580. const auto mr = juce::Rectangle<float> (d.getRight() + 32.0f, d.getY(), 10.0f, d.getHeight());
  1581. g.setColour (juce::Colours::black.withAlpha (0.3f));
  1582. g.fillRect (mr);
  1583. g.fillRect (mr.translated (12.0f, 0.0f));
  1584. g.setColour (juce::Colour (0xffc9cede).withAlpha (0.8f));
  1585. g.fillRect (mr.withTop (yDb (now)));
  1586. g.setColour (colour::accent);
  1587. g.fillRect (mr.translated (12.0f, 0.0f).withBottom (d.getY() + d.getHeight() * juce::jlimit (0.0f, 1.0f, columnBack (0).gr / 66.0f)));
  1588. if (expertOpen)
  1589. {
  1590. const auto e = expert();
  1591. g.setColour (colour::bg2);
  1592. g.fillRect (e);
  1593. g.setColour (colour::border);
  1594. g.drawHorizontalLine ((int) e.getY(), 0.0f, e.getRight());
  1595. caption (g, { 14.0f, e.getY() + 2.0f, 174.0f, 12.0f }, tr ("Upward expansion"));
  1596. caption (g, { filterTrack().getCentreX() - 70.0f, e.getY() + 2.0f, 140.0f, 12.0f }, tr ("Side chain"));
  1597. caption (g, { 10.0f, e.getY() + 118.0f, 290.0f, 12.0f }, v (channelMode) >= 0.5f ? tr ("Side-chain mid / side") : tr ("Side-chain left / right"));
  1598. caption (g, { 530.0f, e.getY() + 118.0f, 184.0f, 12.0f }, tr ("Wet / dry balance"));
  1599. g.setColour (colour::border.withAlpha (0.5f));
  1600. g.drawHorizontalLine ((int) (e.getY() + 114.0f), 10.0f, e.getRight() - 10.0f);
  1601. }
  1602. }
  1603. };
  1604. // =============================================================================================================
  1605. // Prism Multiband — the reference multiband's workflow: the spectrum is the window, each band a coloured region
  1606. // with a node on the 0 dB line — drag it up / down for the range (how far the band may move), left / right to move
  1607. // the band; drag a region's edge to move a crossover; the band's live gain change fills the region; click a band
  1608. // for its floating panel (threshold, range, attack, release, output, mode, ratio, knee).
  1609. class PrismEditor final : public ProEditor
  1610. {
  1611. public:
  1612. PrismEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::prismMultiband, d, 920, 600)
  1613. {
  1614. knobRanges = true; // round tp172b4: each knob's scale under it, the value on hover
  1615. specArea = plot();
  1616. specMinHz = 20.0;
  1617. specMaxHz = 20000.0;
  1618. fillDemo();
  1619. }
  1620. private:
  1621. enum { idPrev = 1, idNext, idClose, idRange, idAnalyzer, idClassic, idExpert, idClassicDet, idSplit, idFree, idSolo0 = 20, idMute0 = 30 };
  1622. // round tp172b4: no band panel until a band is clicked (the reference opens on the bare display)
  1623. int selected = -1, hoverBand = -1, dragBand = -1, dragEdge = -1;
  1624. bool expert = false; // round 147: the band panel's expert part (side-chain filtering, stereo link), view only
  1625. double rangeView = 12.0;
  1626. int analyzer = 3; // 0 off, 1 pre, 2 post, 3 pre + post (view only)
  1627. juce::Point<float> dragStart;
  1628. float dragX0[dyn::prism::bands - 1] {};
  1629. float dragLo0 = 0.0f, dragHi0 = 0.0f; // round 150: the free band's edges when its drag started
  1630. juce::String title() const override { return "Prism Multiband"; }
  1631. juce::String gestures() const override { return tr ("Drag a node: range (up / down), band (left / right) - drag an edge: crossover - double-click: new band - wheel: threshold"); }
  1632. bool usesSpectrum() const override { return analyzer > 0; }
  1633. juce::Rectangle<float> plot() const { return bodyArea().withTrimmedRight (74.0f).withTrimmedTop (8.0f).withTrimmedBottom (24.0f); }
  1634. juce::Rectangle<float> panelArea() const
  1635. {
  1636. const auto p = plot();
  1637. const auto w = expert ? 820.0f : 600.0f;
  1638. return { p.getCentreX() - w * 0.5f, p.getBottom() - 176.0f, w, 166.0f };
  1639. }
  1640. static int bp (int b, int f) { return dyn::prism::param (b, f); }
  1641. bool bandOn (int b) const { return v (bp (b, dyn::prism::fEnabled)) >= 0.5f; }
  1642. // round 135: up to six bands (the band count); a double-click splits a band, the band menu removes one
  1643. int nb() const
  1644. {
  1645. const auto* fx = current();
  1646. return fx != nullptr ? dyn::prism::bandCount (fx->params) : dyn::prism::legacyBands;
  1647. }
  1648. double xoHz (int i) const
  1649. {
  1650. const auto* fx = current();
  1651. return fx != nullptr ? dyn::prism::crossovers (fx->params)[(std::size_t) i] : dyn::prism::crossoverHz (v (dyn::prism::crossoverParam (i)));
  1652. }
  1653. float edgeX (int i) const // 0 … band count
  1654. {
  1655. const auto p = plot();
  1656. if (i <= 0) return p.getX();
  1657. if (i >= nb()) return p.getRight();
  1658. return xForHz (xoHz (i - 1), p);
  1659. }
  1660. // round 150: the free layout (Pro-MB's): each band has its own edges, the room between bands passes untouched
  1661. bool isFree() const { return v (dyn::prism::bandLayout) >= 0.5f; }
  1662. dyn::prism::Layout layout() const
  1663. {
  1664. const auto* fx = current();
  1665. if (fx != nullptr) return dyn::prism::layoutOf (fx->params);
  1666. EffectParams p {};
  1667. const auto& in = effectInfo (EffectKind::prismMultiband);
  1668. for (std::size_t k = 0; k < in.params.size(); ++k) p[k] = in.params[k].defaultValue;
  1669. return dyn::prism::layoutOf (p);
  1670. }
  1671. float edgeXOfHz (double hz) const
  1672. {
  1673. const auto p = plot();
  1674. if (hz <= 0.0) return p.getX();
  1675. return juce::jlimit (p.getX(), p.getRight(), xForHz (hz, p));
  1676. }
  1677. float bandLoX (int b) const
  1678. {
  1679. if (! isFree()) return edgeX (b);
  1680. const auto L = layout();
  1681. return L.segmentOf[(std::size_t) b] < 0 ? plot().getRight() : edgeXOfHz (L.loHz[(std::size_t) b]);
  1682. }
  1683. float bandHiX (int b) const
  1684. {
  1685. if (! isFree()) return edgeX (b + 1);
  1686. const auto L = layout();
  1687. if (L.segmentOf[(std::size_t) b] < 0) return plot().getRight();
  1688. return L.hiHz[(std::size_t) b] <= 0.0 ? plot().getRight() : edgeXOfHz (L.hiHz[(std::size_t) b]);
  1689. }
  1690. // every per-band parameter of band b (fields, look-ahead, pan)
  1691. static std::vector<int> bandParams (int b)
  1692. {
  1693. using namespace dyn::prism;
  1694. std::vector<int> out;
  1695. for (int f = 0; f < fieldsPerBand; ++f) out.push_back (bp (b, f));
  1696. out.push_back (bandLookaheadParam (b));
  1697. out.push_back (bandPanParam (b));
  1698. // round 147 / 150: the expert panel, the free layout's edges / slopes and the side-chain input go with the band
  1699. for (const int base : { (int) bandLink0, (int) bandLinkMode0, (int) bandScFree0, (int) bandScLow0, (int) bandScHigh0,
  1700. (int) bandLo0, (int) bandHi0, (int) bandLoSlope0, (int) bandHiSlope0, (int) bandScInput0 })
  1701. out.push_back (base + b);
  1702. return out;
  1703. }
  1704. // round 150: a new free band around `hz` (an octave wide, inside the gap there), the defaults of a band
  1705. void addFreeBand (double hz)
  1706. {
  1707. using namespace dyn::prism;
  1708. const auto n = nb();
  1709. if (n >= bands) return;
  1710. const auto L = layout();
  1711. double lo = hz / std::sqrt (2.0), hi = hz * std::sqrt (2.0);
  1712. for (int b = 0; b < n; ++b) // stay inside the gap
  1713. {
  1714. if (L.segmentOf[(std::size_t) b] < 0) continue;
  1715. const auto blo = L.loHz[(std::size_t) b], bhi = L.hiHz[(std::size_t) b] > 0.0 ? L.hiHz[(std::size_t) b] : 30000.0;
  1716. if (bhi <= hz) lo = std::max (lo, bhi);
  1717. if (blo >= hz) hi = std::min (hi, blo);
  1718. }
  1719. if (hi < lo * 1.1) return;
  1720. std::vector<std::pair<int, float>> c;
  1721. const auto& in = effectInfo (kind);
  1722. for (const auto k : bandParams (n)) c.push_back ({ k, in.params[(std::size_t) k].defaultValue });
  1723. c.push_back ({ bandLo0 + n, edgeValue (lo) });
  1724. c.push_back ({ bandHi0 + n, edgeValue (hi) });
  1725. c.push_back ({ bp (n, fEnabled), 1.0f });
  1726. c.push_back ({ bandCountParam, bandCountValue (n + 1) });
  1727. set (c);
  1728. selected = n;
  1729. }
  1730. // round 150: switching the layout keeps the sound — the free bands take the split's crossovers and slopes, the
  1731. // split takes the free bands' edges (between two bands: the middle of their gap)
  1732. void setLayout (bool free)
  1733. {
  1734. using namespace dyn::prism;
  1735. if (free == isFree()) return;
  1736. const auto L = layout();
  1737. std::vector<std::pair<int, float>> c;
  1738. const auto n = nb();
  1739. if (free)
  1740. {
  1741. for (int b = 0; b < n; ++b)
  1742. {
  1743. c.push_back ({ bandLo0 + b, edgeValue (L.loHz[(std::size_t) b] > 0.0 ? L.loHz[(std::size_t) b] : 30.0) });
  1744. c.push_back ({ bandHi0 + b, edgeValue (L.hiHz[(std::size_t) b] > 0.0 ? L.hiHz[(std::size_t) b] : 30000.0) });
  1745. c.push_back ({ bandLoSlope0 + b, slopeValue (L.loSlope[(std::size_t) b]) });
  1746. c.push_back ({ bandHiSlope0 + b, slopeValue (L.hiSlope[(std::size_t) b]) });
  1747. }
  1748. c.push_back ({ bandLayout, 1.0f });
  1749. }
  1750. else
  1751. {
  1752. for (int k = 0; k + 1 < n; ++k)
  1753. {
  1754. const auto a = L.hiHz[(std::size_t) k] > 0.0 ? L.hiHz[(std::size_t) k] : 18000.0;
  1755. const auto b = L.loHz[(std::size_t) (k + 1)] > 0.0 ? L.loHz[(std::size_t) (k + 1)] : a;
  1756. c.push_back ({ crossoverParam (k), crossoverValue (std::sqrt (a * b)) });
  1757. }
  1758. c.push_back ({ bandLayout, 0.0f });
  1759. }
  1760. set (c);
  1761. }
  1762. // split band b at `hz`: the bands above move up one, the new band (b + 1) starts as a copy of b
  1763. void splitBand (int b, double hz)
  1764. {
  1765. using namespace dyn::prism;
  1766. const auto n = nb();
  1767. if (n >= bands || b < 0 || b >= n) return;
  1768. const auto lo = b > 0 ? xoHz (b - 1) * 1.08 : 30.0, hi = b < n - 1 ? xoHz (b) / 1.08 : 18000.0;
  1769. if (lo >= hi) return;
  1770. std::vector<std::pair<int, float>> c;
  1771. for (int k = n - 1; k >= b; --k)
  1772. {
  1773. const auto from = bandParams (k), to = bandParams (k + 1);
  1774. for (std::size_t j = 0; j < from.size(); ++j) c.push_back ({ to[j], v (from[j]) });
  1775. }
  1776. for (int k = n - 2; k >= b; --k) c.push_back ({ crossoverParam (k + 1), v (crossoverParam (k)) });
  1777. c.push_back ({ crossoverParam (b), crossoverValue (juce::jlimit (lo, hi, hz)) });
  1778. c.push_back ({ bandCountParam, bandCountValue (n + 1) });
  1779. set (c);
  1780. selected = b + 1;
  1781. }
  1782. // remove band b: the bands above move down one, its neighbour takes its range
  1783. void removeBand (int b)
  1784. {
  1785. using namespace dyn::prism;
  1786. const auto n = nb();
  1787. if (n <= 1 || b < 0 || b >= n) return;
  1788. std::vector<std::pair<int, float>> c;
  1789. for (int k = b; k < n - 1; ++k)
  1790. {
  1791. const auto from = bandParams (k + 1), to = bandParams (k);
  1792. for (std::size_t j = 0; j < from.size(); ++j) c.push_back ({ to[j], v (from[j]) });
  1793. }
  1794. const auto gone = b < n - 1 ? b : b - 1; // the crossover that disappears
  1795. for (int k = gone; k < n - 2; ++k) c.push_back ({ crossoverParam (k), v (crossoverParam (k + 1)) });
  1796. c.push_back ({ bandCountParam, bandCountValue (n - 1) });
  1797. set (c);
  1798. selected = juce::jmin (b, n - 2);
  1799. }
  1800. float gainY (double db) const
  1801. {
  1802. const auto p = plot();
  1803. return p.getY() + p.getHeight() * 0.30f - p.getHeight() * 0.25f * juce::jlimit (-1.15f, 1.15f, (float) (db / rangeView));
  1804. }
  1805. double dbAtY (float y) const
  1806. {
  1807. const auto p = plot();
  1808. return (p.getY() + p.getHeight() * 0.30f - y) / (p.getHeight() * 0.25f) * rangeView;
  1809. }
  1810. float specY (float db) const
  1811. {
  1812. const auto p = plot();
  1813. return p.getY() + p.getHeight() * juce::jlimit (0.0f, 1.0f, -db / 100.0f);
  1814. }
  1815. juce::Point<float> node (int b) const
  1816. {
  1817. return { 0.5f * (bandLoX (b) + bandHiX (b)), gainY (dyn::prism::rangeDb (v (bp (b, dyn::prism::fRange)))) };
  1818. }
  1819. int nodeAt (juce::Point<float> p) const
  1820. {
  1821. for (int b = 0; b < nb(); ++b)
  1822. if (node (b).getDistanceFrom (p) < 11.0f) return b;
  1823. return -1;
  1824. }
  1825. int edgeAt (juce::Point<float> p) const
  1826. {
  1827. if (! plot().contains (p)) return -1;
  1828. if (isFree()) // round 150: 2b + 1 = band b's low edge, 2b + 2 its high edge
  1829. {
  1830. for (int b = 0; b < nb(); ++b)
  1831. {
  1832. if (std::abs (bandLoX (b) - p.x) < 5.0f && bandLoX (b) > plot().getX() + 1.0f) return 2 * b + 1;
  1833. if (std::abs (bandHiX (b) - p.x) < 5.0f && bandHiX (b) < plot().getRight() - 1.0f) return 2 * b + 2;
  1834. }
  1835. return -1;
  1836. }
  1837. for (int i = 1; i < nb(); ++i)
  1838. if (std::abs (edgeX (i) - p.x) < 5.0f) return i;
  1839. return -1;
  1840. }
  1841. int bandAtX (float x) const // round 150: −1 in a gap of the free layout
  1842. {
  1843. if (isFree())
  1844. {
  1845. for (int b = 0; b < nb(); ++b)
  1846. if (x >= bandLoX (b) && x < bandHiX (b)) return b;
  1847. return -1;
  1848. }
  1849. for (int b = 0; b < nb(); ++b)
  1850. if (x < edgeX (b + 1)) return b;
  1851. return nb() - 1;
  1852. }
  1853. double liveDb (int b) const
  1854. {
  1855. if (demo) return b == 1 ? -4.5 : b == 2 ? -2.0 : b == 3 ? 1.5 : -1.0;
  1856. return bandOn (b) ? (double) liveMeter (dyn::prism::bandMeter (b)) * 30.0 : 0.0;
  1857. }
  1858. void layoutControls (std::vector<Ctl>& out) const override
  1859. {
  1860. using namespace dyn::prism;
  1861. const auto p = plot();
  1862. for (int b = 0; b < nb(); ++b)
  1863. {
  1864. const auto x = bandLoX (b) + 4.0f;
  1865. if (bandHiX (b) - bandLoX (b) < 40.0f) continue;
  1866. out.push_back (button ({ x, p.getY() + 4.0f, 18.0f, 16.0f }, idSolo0 + b, "S", v (bp (b, fSolo)) >= 0.5f, tr ("Solo the band")));
  1867. out.push_back (button ({ x, p.getY() + 22.0f, 18.0f, 16.0f }, idMute0 + b, "M", ! bandOn (b), tr ("Bypass the band (the band passes untouched)")));
  1868. }
  1869. out.push_back (button ({ p.getRight() + 8.0f, p.getY() + 2.0f, 50.0f, 20.0f }, idRange, juce::String ((int) rangeView) + " dB", false,
  1870. tr ("Gain scale: click to switch between 3, 6, 12 and 30 dB")));
  1871. if (selected >= 0)
  1872. {
  1873. const auto a = panelArea();
  1874. const auto b = selected;
  1875. auto add = [&] (Ctl c) { c.colour = peqview::bandColour (b); out.push_back (c); };
  1876. add (toggle ({ a.getX() + 12.0f, a.getY() + 10.0f, 64.0f, 22.0f }, bp (b, fEnabled), tr ("On")));
  1877. add (toggle ({ a.getX() + 12.0f, a.getY() + 38.0f, 64.0f, 22.0f }, bp (b, fSolo), tr ("Solo")));
  1878. add (knob ({ a.getX() + 86.0f, a.getY() + 8.0f, 88.0f, 104.0f }, bp (b, fThreshold), tr ("Threshold"), 2));
  1879. add (knob ({ a.getX() + 182.0f, a.getY() + 8.0f, 88.0f, 104.0f }, bp (b, fRange), tr ("Range"), 2, true));
  1880. add (knob ({ a.getX() + 286.0f, a.getY() + 14.0f, 70.0f, 90.0f }, bp (b, fAttack), tr ("Attack")));
  1881. add (knob ({ a.getX() + 362.0f, a.getY() + 14.0f, 70.0f, 90.0f }, bp (b, fRelease), tr ("Release")));
  1882. add (knob ({ a.getX() + 446.0f, a.getY() + 14.0f, 70.0f, 90.0f }, bp (b, fLevel), tr ("Output"), 1, true));
  1883. add (tabs ({ a.getX() + 86.0f, a.getY() + 128.0f, 184.0f, 26.0f }, bp (b, fMode), "Compress|Expand"));
  1884. add (knob ({ a.getX() + 290.0f, a.getY() + 112.0f, 66.0f, 54.0f }, bp (b, fRatio), tr ("Ratio"), 0));
  1885. add (knob ({ a.getX() + 366.0f, a.getY() + 112.0f, 66.0f, 54.0f }, bp (b, fKnee), tr ("Knee"), 0));
  1886. add (knob ({ a.getX() + 446.0f, a.getY() + 112.0f, 66.0f, 54.0f }, bandLookaheadParam (b), tr ("Lookahead"), 0));
  1887. add (knob ({ a.getX() + 522.0f, a.getY() + 112.0f, 66.0f, 54.0f }, bandPanParam (b), tr ("Pan"), 0, true)); // round 135: the band's output balance
  1888. // round 144: the crossover slope (one for every band) and the side-chain input, in the band panel
  1889. out.push_back (menu ({ a.getX() + 522.0f, a.getY() + 36.0f, 70.0f, 22.0f }, slope, tr ("Slope"), "12 dB|24 dB|48 dB"));
  1890. out.push_back (menu ({ a.getX() + 522.0f, a.getY() + 76.0f, 70.0f, 22.0f }, scExternal, tr ("Side chain"), "Int|Ext"));
  1891. out.push_back (tabs ({ a.getX() + 12.0f, a.getY() + 72.0f, 64.0f, 22.0f }, panMode, "L/R|M/S")); // round 144: what PAN balances
  1892. // round 147: the expert part (the reference's »): side-chain filtering and the stereo link of this band
  1893. out.push_back (button ({ a.getX() + 12.0f, a.getY() + 104.0f, 64.0f, 22.0f }, idExpert, expert ? tr ("Expert <<") : tr ("Expert >>"), expert,
  1894. tr ("Show the band's expert settings: side-chain filtering (band or a free range) and the stereo link")));
  1895. if (expert)
  1896. {
  1897. const auto x0 = a.getX() + 600.0f;
  1898. add (tabs ({ x0 + 10.0f, a.getY() + 26.0f, 100.0f, 22.0f }, bandScFree0 + b, "Band|Free"));
  1899. add (knob ({ x0 + 4.0f, a.getY() + 52.0f, 56.0f, 66.0f }, bandScLow0 + b, tr ("Low"), 0));
  1900. add (knob ({ x0 + 58.0f, a.getY() + 52.0f, 56.0f, 66.0f }, bandScHigh0 + b, tr ("High"), 0));
  1901. // the band's own slopes (Pro-MB's per-band slopes): the free layout's continuous 6 … 48 dB/oct, or the
  1902. // split layout's lower / upper crossover's slope (or the global one)
  1903. if (isFree())
  1904. {
  1905. add (menu ({ x0 + 4.0f, a.getY() + 122.0f, 54.0f, 20.0f }, bandLoSlope0 + b, tr ("Low slope"), "6|12|18|24|30|36|42|48"));
  1906. add (menu ({ x0 + 60.0f, a.getY() + 122.0f, 54.0f, 20.0f }, bandHiSlope0 + b, tr ("High slope"), "6|12|18|24|30|36|42|48"));
  1907. }
  1908. else
  1909. {
  1910. if (b > 0)
  1911. add (menu ({ x0 + 4.0f, a.getY() + 122.0f, 54.0f, 20.0f }, xoverSlope0 + b - 1, tr ("Low slope"), "Global|12|24|48"));
  1912. if (b < nb() - 1)
  1913. add (menu ({ x0 + 60.0f, a.getY() + 122.0f, 54.0f, 20.0f }, xoverSlope0 + b, tr ("High slope"), "Global|12|24|48"));
  1914. }
  1915. add (knob ({ x0 + 126.0f, a.getY() + 22.0f, 84.0f, 92.0f }, bandLink0 + b, tr ("Link"), 1));
  1916. add (tabs ({ x0 + 132.0f, a.getY() + 122.0f, 74.0f, 22.0f }, bandLinkMode0 + b, "Mid|Side"));
  1917. // round 150: the band's own side-chain input (the reference's per band choice)
  1918. add (menu ({ x0 + 4.0f, a.getY() + 144.0f, 110.0f, 20.0f }, bandScInput0 + b, tr ("Input"), "Global|Plug-in|External"));
  1919. }
  1920. out.push_back (button ({ a.getRight() - 72.0f, a.getY() + 8.0f, 20.0f, 20.0f }, idPrev, "<", false, tr ("Previous / next band")));
  1921. out.push_back (button ({ a.getRight() - 50.0f, a.getY() + 8.0f, 20.0f, 20.0f }, idNext, ">", false, tr ("Previous / next band")));
  1922. out.push_back (button ({ a.getRight() - 26.0f, a.getY() + 8.0f, 20.0f, 20.0f }, idClose, "x", false, tr ("Close the band panel (click on the empty display does the same)")));
  1923. }
  1924. const auto bar = barArea();
  1925. const auto cy = bar.getCentreY();
  1926. static const char* const analyzerNames[] { TR_NOOP ("Off"), TR_NOOP ("Pre"), TR_NOOP ("Post"), TR_NOOP ("Pre + Post") };
  1927. // round 144: the reference's bottom bar order — processing mode, oversampling, look-ahead, analyser; the
  1928. // crossover slope and the side-chain input moved into the band panel (where the reference has them)
  1929. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 150.0f, 22.0f }, processingMode, tr ("Phase"), "Linear|Dynamic|Minimum"));
  1930. out.push_back (barMenu ({ 166.0f, cy - 11.0f, 134.0f, 22.0f }, oversampling, tr ("Oversampling"), "Off|2x|4x"));
  1931. out.push_back (barValue ({ 306.0f, cy - 11.0f, 124.0f, 22.0f }, lookahead, tr ("Lookahead")));
  1932. out.push_back (button ({ 436.0f, cy - 11.0f, 150.0f, 22.0f }, idAnalyzer, tr ("Analyzer:") + " " + tr (analyzerNames[analyzer]) + (specFrozen ? " *" : ""), false,
  1933. tr ("Spectrum analyzer: off, pre, post or pre + post; speed; freeze")));
  1934. // round 147: a project saved before the measured Dynamic phase keeps its classic engine; one click updates it
  1935. // round 150: the layout (split = contiguous bands on crossovers; free = Pro-MB's bands anywhere, the gaps pass
  1936. // untouched) and the old-project indicators, in the column right of the display (the bottom bar is full)
  1937. {
  1938. const auto x = p.getRight() + 6.0f;
  1939. out.push_back (button ({ x, p.getY() + 28.0f, 30.0f, 20.0f }, idSplit, tr ("Split"), ! isFree(),
  1940. tr ("Split layout: the bands sit side by side on crossovers")));
  1941. out.push_back (button ({ x + 32.0f, p.getY() + 28.0f, 30.0f, 20.0f }, idFree, tr ("Free"), isFree(),
  1942. tr ("Free layout (as Pro-MB): each band has its own edges and slopes; the room between bands passes untouched")));
  1943. auto y = p.getY() + 54.0f;
  1944. // round 147: a project saved before the measured Dynamic phase keeps its classic engine; one click updates it
  1945. if (v (dynamicEngine) < 0.5f && phaseOf (v (processingMode)) == Phase::dynamic)
  1946. {
  1947. out.push_back (button ({ x, y, 62.0f, 20.0f }, idClassic, tr ("Classic"), true,
  1948. tr ("This project's Dynamic phase runs the engine it was saved with (before round 147). Click to use the measured one (Pro-MB's response).")));
  1949. y += 24.0f;
  1950. }
  1951. if (v (detectorLaw) < 0.5f || v (rev152) < 0.5f)
  1952. out.push_back (button ({ x, y, 62.0f, 20.0f }, idClassicDet, tr ("Old det."), true,
  1953. tr ("This project's bands use the detector they were saved with (before round 152). Click to use the measured one (Pro-MB's attack, release and range).")));
  1954. }
  1955. out.push_back (barValue ({ bar.getRight() - 312.0f, cy - 11.0f, 92.0f, 22.0f }, mix, tr ("Mix")));
  1956. out.push_back (barValue ({ bar.getRight() - 216.0f, cy - 11.0f, 100.0f, 22.0f }, input, tr ("In")));
  1957. out.push_back (barValue ({ bar.getRight() - 112.0f, cy - 11.0f, 104.0f, 22.0f }, output, tr ("Out")));
  1958. }
  1959. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  1960. {
  1961. using namespace dyn::prism;
  1962. if (c.id == idPrev) selected = (selected + nb() - 1) % nb();
  1963. else if (c.id == idNext) selected = (selected + 1) % nb();
  1964. else if (c.id == idClose) selected = -1;
  1965. else if (c.id == idRange) rangeView = rangeView >= 30.0 ? 3.0 : rangeView >= 12.0 ? 30.0 : rangeView >= 6.0 ? 12.0 : 6.0;
  1966. else if (c.id == idAnalyzer) { showAnalyzerMenu(); return; }
  1967. else if (c.id == idClassic) set ({ { dynamicEngine, 1.0f } });
  1968. else if (c.id == idClassicDet) set ({ { detectorLaw, 1.0f }, { rev152, 1.0f } });
  1969. else if (c.id == idSplit || c.id == idFree) setLayout (c.id == idFree);
  1970. else if (c.id == idExpert) expert = ! expert;
  1971. else if (c.id >= idSolo0 && c.id < idSolo0 + bands) set ({ { bp (c.id - idSolo0, fSolo), v (bp (c.id - idSolo0, fSolo)) >= 0.5f ? 0.0f : 1.0f } });
  1972. else if (c.id >= idMute0 && c.id < idMute0 + bands) set ({ { bp (c.id - idMute0, fEnabled), bandOn (c.id - idMute0) ? 0.0f : 1.0f } });
  1973. repaint();
  1974. }
  1975. // the analyser's options, as the reference's analyser menu: what it shows, its speed, freeze
  1976. void showAnalyzerMenu()
  1977. {
  1978. static const char* const names[] { TR_NOOP ("Off"), TR_NOOP ("Pre"), TR_NOOP ("Post"), TR_NOOP ("Pre + Post") };
  1979. static const char* const speeds[] { TR_NOOP ("Very slow"), TR_NOOP ("Slow"), TR_NOOP ("Medium"), TR_NOOP ("Fast"), TR_NOOP ("Very fast") };
  1980. static const float falls[] { 0.3f, 0.75f, 1.5f, 3.0f, 6.0f };
  1981. juce::PopupMenu m;
  1982. for (int k = 0; k < 4; ++k)
  1983. m.addItem (tr (names[k]), true, analyzer == k, [this, k] { analyzer = k; repaint(); });
  1984. m.addSeparator();
  1985. juce::PopupMenu sp;
  1986. for (int k = 0; k < 5; ++k)
  1987. sp.addItem (tr (speeds[k]), true, specFall == falls[k], [this, k] { specFall = falls[k]; });
  1988. m.addSubMenu (tr ("Speed"), sp);
  1989. // round 144: the reference's resolution and tilt choices
  1990. static const char* const resolutions[] { TR_NOOP ("Low"), TR_NOOP ("Medium"), TR_NOOP ("High"), TR_NOOP ("Maximum") };
  1991. juce::PopupMenu res;
  1992. for (int k = 0; k < 4; ++k)
  1993. res.addItem (tr (resolutions[k]), true, specResolution == k, [this, k] { specResolution = k; });
  1994. m.addSubMenu (tr ("Resolution"), res);
  1995. juce::PopupMenu tilt;
  1996. for (const double t : { 0.0, 1.5, 3.0, 4.5, 6.0 })
  1997. tilt.addItem (juce::String (t, 1) + " dB/oct", true, specTilt == t, [this, t] { specTilt = t; });
  1998. m.addSubMenu (tr ("Tilt"), tilt);
  1999. m.addItem (tr ("Freeze"), true, specFrozen, [this] { specFrozen = ! specFrozen; repaint(); });
  2000. m.showMenuAsync (juce::PopupMenu::Options().withMousePosition()); // round 152 (checked by hand): at the mouse, not under the window
  2001. }
  2002. void showBandMenu (int b)
  2003. {
  2004. using namespace dyn::prism;
  2005. juce::PopupMenu m;
  2006. m.addItem (tr ("On"), true, bandOn (b), [this, b] { set ({ { bp (b, fEnabled), bandOn (b) ? 0.0f : 1.0f } }); });
  2007. m.addItem (tr ("Solo"), true, v (bp (b, fSolo)) >= 0.5f, [this, b] { set ({ { bp (b, fSolo), v (bp (b, fSolo)) >= 0.5f ? 0.0f : 1.0f } }); });
  2008. m.addSeparator();
  2009. m.addItem (tr ("Compress"), true, v (bp (b, fMode)) < 0.5f, [this, b] { set ({ { bp (b, fMode), 0.0f } }); });
  2010. m.addItem (tr ("Expand"), true, v (bp (b, fMode)) >= 0.5f, [this, b] { set ({ { bp (b, fMode), 1.0f } }); });
  2011. m.addSeparator();
  2012. m.addItem (tr ("Reset the band"), [this, b] {
  2013. std::vector<std::pair<int, float>> c;
  2014. const auto& in = effectInfo (kind);
  2015. for (const auto k : bandParams (b)) c.push_back ({ k, in.params[(std::size_t) k].defaultValue });
  2016. set (c);
  2017. });
  2018. m.addSeparator();
  2019. if (! isFree())
  2020. m.addItem (tr ("Split the band"), nb() < bands, false, [this, b] { splitBand (b, std::sqrt ((b > 0 ? xoHz (b - 1) : 30.0) * (b < nb() - 1 ? xoHz (b) : 18000.0))); });
  2021. m.addItem (tr ("Remove the band"), nb() > 1, false, [this, b] { removeBand (b); });
  2022. m.showMenuAsync (juce::PopupMenu::Options().withMousePosition()); // round 152 (checked by hand): at the mouse, not under the window
  2023. }
  2024. bool bodyDown (const juce::MouseEvent& e) override
  2025. {
  2026. using namespace dyn::prism;
  2027. const auto p = e.position;
  2028. if (selected >= 0 && panelArea().contains (p)) return false;
  2029. if (! plot().contains (p)) return false;
  2030. dragBand = dragEdge = -1;
  2031. if (const auto b = nodeAt (p); b >= 0)
  2032. {
  2033. selected = b;
  2034. if (e.mods.isPopupMenu()) { showBandMenu (b); return false; }
  2035. if (e.mods.isAltDown()) { set ({ { bp (b, fEnabled), 0.0f } }); return false; }
  2036. dragBand = b;
  2037. dragStart = p;
  2038. for (int i = 0; i < nb() - 1; ++i) dragX0[i] = edgeX (i + 1);
  2039. dragLo0 = bandLoX (b);
  2040. dragHi0 = bandHiX (b);
  2041. return true;
  2042. }
  2043. if (const auto i = edgeAt (p); i > 0 && ! e.mods.isPopupMenu())
  2044. {
  2045. dragEdge = i;
  2046. return true;
  2047. }
  2048. const auto b = bandAtX (p.x);
  2049. if (b < 0) // round 150: a gap of the free layout
  2050. {
  2051. if (e.mods.isPopupMenu() && nb() < bands)
  2052. {
  2053. const auto hz = hzForX (p.x, plot());
  2054. juce::PopupMenu m;
  2055. m.addItem (tr ("New band here"), [this, hz] { addFreeBand (hz); });
  2056. m.showMenuAsync (juce::PopupMenu::Options().withMousePosition()); // round 152 (checked by hand): at the mouse, not under the window
  2057. return false;
  2058. }
  2059. selected = -1;
  2060. repaint();
  2061. return false;
  2062. }
  2063. if (e.mods.isPopupMenu()) { showBandMenu (b); return false; }
  2064. selected = selected == b ? -1 : b; // a click on a band opens its panel, a second click closes it
  2065. repaint();
  2066. return false;
  2067. }
  2068. void moveEdge (int i, float x, std::vector<std::pair<int, float>>& c) const
  2069. {
  2070. using namespace dyn::prism;
  2071. if (isFree()) // round 150: one band's own edge (2b + 1 low, 2b + 2 high), kept inside the display and the band
  2072. {
  2073. const auto b = (i - 1) / 2;
  2074. const bool high = (i - 1) % 2 != 0;
  2075. const auto pl = plot();
  2076. const auto xx = high ? juce::jlimit (bandLoX (b) + 12.0f, pl.getRight() - 2.0f, x) : juce::jlimit (pl.getX() + 2.0f, bandHiX (b) - 12.0f, x);
  2077. c.push_back ({ (high ? bandHi0 : bandLo0) + b, edgeValue (juce::jlimit (30.0, 30000.0, hzForX (xx, pl))) });
  2078. return;
  2079. }
  2080. const auto lo = i > 1 ? edgeX (i - 1) + 12.0f : plot().getX() + 4.0f;
  2081. const auto hi = i < nb() - 1 ? edgeX (i + 1) - 12.0f : plot().getRight() - 4.0f;
  2082. const auto hz = hzForX (juce::jlimit (lo, hi, x), plot());
  2083. c.push_back ({ crossoverParam (i - 1), crossoverValue (juce::jlimit (30.0, 18000.0, hz)) });
  2084. }
  2085. void bodyDrag (const juce::MouseEvent& e) override
  2086. {
  2087. using namespace dyn::prism;
  2088. std::vector<std::pair<int, float>> c;
  2089. if (dragEdge > 0)
  2090. {
  2091. moveEdge (dragEdge, e.position.x, c);
  2092. set (c);
  2093. const auto prm = isFree() ? ((dragEdge - 1) % 2 != 0 ? bandHi0 : bandLo0) + (dragEdge - 1) / 2 : crossoverParam (dragEdge - 1);
  2094. ui::showValueTip (*this, juce::Rectangle<int> (16, 16).withCentre (e.position.toInt()), tr ("Crossover") + " " + text (prm));
  2095. return;
  2096. }
  2097. if (dragBand < 0) return;
  2098. const auto b = dragBand;
  2099. const auto d = e.position - dragStart;
  2100. const auto fine = e.mods.isCtrlDown() ? 0.25f : 1.0f;
  2101. if (std::abs (d.y) > 2.0f || ! e.mods.isShiftDown())
  2102. c.push_back ({ bp (b, fRange), (float) ((juce::jlimit (-30.0, 30.0, dbAtY (dragStart.y + d.y * fine)) + 30.0) / 60.0) });
  2103. if (std::abs (d.x) > 3.0f && ! (e.mods.isShiftDown() && std::abs (d.y) > std::abs (d.x)))
  2104. {
  2105. // move the band: its edges follow the mouse (the outer bands move one edge)
  2106. if (isFree()) // round 150: the free band's own edges (an edge at the display's end stays there)
  2107. {
  2108. const auto pl = plot();
  2109. if (dragLo0 > pl.getX() + 1.0f)
  2110. c.push_back ({ bandLo0 + b, edgeValue (juce::jlimit (30.0, 30000.0, hzForX (dragLo0 + d.x * fine, pl))) });
  2111. if (dragHi0 < pl.getRight() - 1.0f)
  2112. c.push_back ({ bandHi0 + b, edgeValue (juce::jlimit (30.0, 30000.0, hzForX (dragHi0 + d.x * fine, pl))) });
  2113. }
  2114. else if (b > 0) c.push_back ({ crossoverParam (b - 1), crossoverValue (juce::jlimit (30.0, 18000.0, hzForX (dragX0[b - 1] + d.x * fine, plot()))) });
  2115. if (b < nb() - 1) c.push_back ({ crossoverParam (b), crossoverValue (juce::jlimit (30.0, 18000.0, hzForX (dragX0[b] + d.x * fine, plot()))) });
  2116. }
  2117. set (c);
  2118. ui::showValueTip (*this, juce::Rectangle<int> (16, 16).withCentre (node (b).toInt()), tr ("Band {0}", { juce::String (b + 1) }) + " " + tr ("Range") + " " + text (bp (b, fRange)));
  2119. }
  2120. bool bodyDoubleClick (const juce::MouseEvent& e) override
  2121. {
  2122. using namespace dyn::prism;
  2123. if (! plot().contains (e.position)) return false;
  2124. // round 135: double-click on a node = on / off; on the empty display = a new band there (the band under the
  2125. // mouse splits at that frequency), as the reference creates bands anywhere
  2126. if (isFree()) // round 150: on a node = on / off; in a gap = a new band there (up to six)
  2127. {
  2128. if (const auto nodeB = nodeAt (e.position); nodeB >= 0)
  2129. {
  2130. set ({ { bp (nodeB, fEnabled), bandOn (nodeB) ? 0.0f : 1.0f } });
  2131. selected = nodeB;
  2132. }
  2133. else if (bandAtX (e.position.x) < 0)
  2134. addFreeBand (hzForX (e.position.x, plot()));
  2135. return true;
  2136. }
  2137. if (const auto nodeB = nodeAt (e.position); nodeB >= 0 || nb() >= bands)
  2138. {
  2139. const auto b = nodeB >= 0 ? nodeB : bandAtX (e.position.x);
  2140. set ({ { bp (b, fEnabled), bandOn (b) ? 0.0f : 1.0f } });
  2141. selected = b;
  2142. return true;
  2143. }
  2144. splitBand (bandAtX (e.position.x), hzForX (e.position.x, plot()));
  2145. return true;
  2146. }
  2147. bool bodyWheel (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
  2148. {
  2149. using namespace dyn::prism;
  2150. if (! plot().contains (e.position)) return false;
  2151. auto b = nodeAt (e.position);
  2152. if (b < 0) b = selected;
  2153. if (b < 0) return true;
  2154. const auto prm = bp (b, fThreshold);
  2155. if (const auto x = ui::wheelValue (v (prm), e, w, specFor (prm)))
  2156. {
  2157. set ({ { prm, (float) *x } });
  2158. ui::flashValueTip (*this, juce::Rectangle<int> (16, 16).withCentre (node (b).toInt()), tr ("Threshold") + " " + text (prm));
  2159. }
  2160. return true;
  2161. }
  2162. void bodyMove (juce::Point<float> p) override { hoverBand = nodeAt (p); }
  2163. ui::Hint bodyHint (juce::Point<float> p) override
  2164. {
  2165. ui::Hint h;
  2166. if (! plot().contains (p)) return h;
  2167. if (nodeAt (p) >= 0)
  2168. h.text = tr ("Band node: drag up / down = range, left / right = move the band (Shift: one direction, Ctrl: fine); wheel = threshold; Alt-click = bypass; right-click = menu");
  2169. else if (edgeAt (p) > 0)
  2170. h.text = tr ("Crossover: drag left or right");
  2171. else if (isFree() && bandAtX (p.x) < 0)
  2172. h.text = tr ("Free layout: this range passes untouched; double-click = a new band here (up to six)");
  2173. else
  2174. h.text = tr ("Click a band to open its panel; double-click = a new band here (up to six); right-click = band menu");
  2175. h.hasMenu = true;
  2176. return h;
  2177. }
  2178. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  2179. {
  2180. using namespace dyn::prism;
  2181. if (selected >= nb()) selected = nb() - 1; // a band removed (or a smaller preset): keep the panel on a band
  2182. const auto p = plot();
  2183. displayBackground (g, bodyArea());
  2184. // round tp172b4: the reference's full log grid (every 1 … 9 of each decade, faint)
  2185. for (double dec = 10.0; dec <= 10000.0; dec *= 10.0)
  2186. for (int k = 2; k <= 9; ++k)
  2187. if (const auto hz = dec * k; hz > 20.0 && hz < 20000.0 && k != 2 && k != 5)
  2188. {
  2189. g.setColour (juce::Colours::white.withAlpha (0.045f));
  2190. g.drawVerticalLine ((int) xForHz (hz, p), p.getY(), p.getBottom());
  2191. }
  2192. frequencyLabels (g, p, p.getBottom() + 12.0f);
  2193. // the analyser
  2194. if (analyzer == 1 || analyzer == 3)
  2195. paintSpectrum (g, specPre, [this] (float db) { return specY (db); }, inColour().withAlpha (0.18f), inColour().withAlpha (0.4f));
  2196. if (analyzer >= 2)
  2197. paintSpectrum (g, specPost, [this] (float db) { return specY (db); }, outColour().withAlpha (0.12f), outColour().withAlpha (0.5f));
  2198. // gain scale labels (right) and the 0 dB line
  2199. g.setFont (font (type::caption));
  2200. for (const auto f : { -1.0, -0.5, 0.0, 0.5, 1.0 })
  2201. {
  2202. const auto db = f * rangeView;
  2203. const auto y = gainY (db);
  2204. g.setColour (f == 0.0 ? colour::gridBar : colour::gridBeat);
  2205. g.drawHorizontalLine ((int) y, p.getX(), p.getRight());
  2206. g.setColour (accent.withAlpha (0.85f));
  2207. g.drawText ((db > 0 ? "+" : "") + juce::String ((int) db), juce::Rectangle<float> (p.getRight() + 8.0f, y - 7.0f, 30.0f, 14.0f), juce::Justification::centredLeft, false);
  2208. }
  2209. for (const auto db : { -20.0f, -40.0f, -60.0f, -80.0f })
  2210. {
  2211. g.setColour (colour::textDisabled);
  2212. g.drawText (juce::String ((int) db), juce::Rectangle<float> (p.getRight() + 40.0f, specY (db) - 7.0f, 30.0f, 14.0f), juce::Justification::centredLeft, false);
  2213. }
  2214. // the bands
  2215. double gains[bands] {};
  2216. for (int b = 0; b < nb(); ++b)
  2217. {
  2218. const auto c = peqview::bandColour (b);
  2219. const auto region = juce::Rectangle<float> (bandLoX (b), p.getY(), juce::jmax (0.0f, bandHiX (b) - bandLoX (b)), p.getHeight());
  2220. const auto on = bandOn (b);
  2221. g.setColour (c.withAlpha (on ? (b == selected ? 0.2f : 0.12f) : 0.03f));
  2222. g.fillRect (region);
  2223. gains[b] = on ? liveDb (b) + levelDb (v (bp (b, fLevel))) : 0.0;
  2224. if (on)
  2225. {
  2226. // the range the band may move (dashed) and its live gain change (filled)
  2227. const auto ry = gainY (rangeDb (v (bp (b, fRange))));
  2228. const auto dashes = std::array<float, 2> { 4.0f, 4.0f };
  2229. g.setColour (c.withAlpha (0.6f));
  2230. g.drawDashedLine (juce::Line<float> (region.getX(), ry, region.getRight(), ry), dashes.data(), 2, 1.0f);
  2231. const auto ly = gainY (liveDb (b));
  2232. g.setColour (c.withAlpha (0.35f));
  2233. g.fillRect (region.withTop (juce::jmin (ly, gainY (0.0))).withBottom (juce::jmax (ly, gainY (0.0))));
  2234. }
  2235. }
  2236. const auto edgeLine = [&] (float x) {
  2237. g.setColour (std::abs (mouse.x - x) < 5.0f && p.contains (mouse) ? colour::textPrimary : colour::textSecondary.withAlpha (0.5f));
  2238. const auto dashes = std::array<float, 2> { 3.0f, 3.0f };
  2239. g.drawDashedLine (juce::Line<float> (x, p.getY(), x, p.getBottom()), dashes.data(), 2, 1.0f);
  2240. };
  2241. if (isFree()) // round 150: each band's own edges
  2242. {
  2243. for (int b = 0; b < nb(); ++b)
  2244. {
  2245. if (bandLoX (b) > p.getX() + 1.0f) edgeLine (bandLoX (b));
  2246. if (bandHiX (b) < p.getRight() - 1.0f) edgeLine (bandHiX (b));
  2247. }
  2248. }
  2249. else
  2250. for (int i = 1; i < nb(); ++i)
  2251. edgeLine (edgeX (i));
  2252. // the summed response with the live band gains
  2253. juce::Path resp;
  2254. for (int i = 0; i <= 300; ++i)
  2255. {
  2256. const auto x = p.getX() + p.getWidth() * (float) i / 300.0f;
  2257. const auto db = responseDb (fx.params, gains, 48000.0, hzForX (x, p));
  2258. if (i == 0) resp.startNewSubPath (x, gainY (db));
  2259. else resp.lineTo (x, gainY (db));
  2260. }
  2261. skin::glowStroke (g, resp, fx.enabled ? accent : colour::textDisabled, 2.0f, fx.enabled ? 0.6f : 0.0f); // (tp172b4: the reference's orange)
  2262. // the nodes
  2263. for (int b = 0; b < nb(); ++b)
  2264. {
  2265. const auto n = node (b);
  2266. const auto c = peqview::bandColour (b);
  2267. const auto r = juce::Rectangle<float> (b == hoverBand || b == selected ? 16.0f : 13.0f, b == hoverBand || b == selected ? 16.0f : 13.0f).withCentre (n);
  2268. g.setColour (bandOn (b) ? c : c.withAlpha (0.3f));
  2269. g.fillEllipse (r);
  2270. g.setColour (b == selected ? colour::textPrimary : colour::bg0);
  2271. g.drawEllipse (r, 1.5f);
  2272. }
  2273. // the hovered node's read-out
  2274. if (hoverBand >= 0 && dragCtl == -1)
  2275. {
  2276. const auto n = node (hoverBand);
  2277. auto r = juce::Rectangle<float> (n.x - 54.0f, n.y + 14.0f, 108.0f, 48.0f).constrainedWithin (p);
  2278. // round 152 (checked by hand): the open band panel hid the read-out under the node; then it goes above
  2279. if (selected >= 0 && r.intersects (panelArea()))
  2280. r = juce::Rectangle<float> (n.x - 54.0f, n.y - 62.0f, 108.0f, 48.0f).constrainedWithin (p);
  2281. g.setColour (colour::bg3.withAlpha (0.95f));
  2282. g.fillRoundedRectangle (r, 5.0f);
  2283. g.setColour (colour::textPrimary);
  2284. g.setFont (font (type::small, true));
  2285. g.drawText (tr ("Band {0}", { juce::String (hoverBand + 1) }), r.withHeight (16.0f).translated (0.0f, 2.0f), juce::Justification::centred, false);
  2286. g.setFont (font (type::caption));
  2287. g.drawText (tr ("Range") + " " + text (bp (hoverBand, fRange)), r.withTrimmedTop (17.0f).withHeight (14.0f), juce::Justification::centred, false);
  2288. g.drawText (tr ("Threshold") + " " + text (bp (hoverBand, fThreshold)), r.withTrimmedTop (31.0f).withHeight (14.0f), juce::Justification::centred, false);
  2289. }
  2290. // the band panel
  2291. if (selected >= 0)
  2292. {
  2293. const auto a = panelArea();
  2294. const auto c = peqview::bandColour (selected);
  2295. drawPanel (g, a, c);
  2296. g.setColour (c);
  2297. g.fillRoundedRectangle (juce::Rectangle<float> (a.getX() + 14.0f, a.getY() - 1.0f, 46.0f, 3.0f), 1.5f);
  2298. g.setColour (colour::textSecondary);
  2299. g.setFont (font (type::small, true));
  2300. g.drawText (tr ("Band {0}", { juce::String (selected + 1) }), juce::Rectangle<float> (a.getRight() - 160.0f, a.getY() + 8.0f, 86.0f, 20.0f), juce::Justification::centredRight, false);
  2301. caption (g, { a.getX() + 86.0f, a.getY() + 114.0f, 184.0f, 12.0f }, tr ("Mode"));
  2302. if (expert) // round 147: the expert part's captions and its separator
  2303. {
  2304. const auto x0 = a.getX() + 600.0f;
  2305. g.setColour (colour::border);
  2306. g.drawVerticalLine ((int) x0, a.getY() + 10.0f, a.getBottom() - 10.0f);
  2307. caption (g, { x0 + 6.0f, a.getY() + 10.0f, 110.0f, 12.0f }, tr ("Side chain"));
  2308. caption (g, { x0 + 120.0f, a.getY() + 10.0f, 96.0f, 12.0f }, tr ("Stereo link"));
  2309. }
  2310. }
  2311. // output meter
  2312. const auto m = juce::Rectangle<float> ((float) getWidth() - 14.0f, p.getY(), 8.0f, p.getHeight());
  2313. drawMeter (g, m, dbOf (liveMeter (5)), -60.0f, colour::meterLow.withAlpha (0.85f));
  2314. }
  2315. };
  2316. // =============================================================================================================
  2317. // Ember Saturator — the reference saturator's workflow: the spectrum on top with the bands side by side (drag a
  2318. // crossover line to move it, drag a band's handle up / down for its drive, double-click to split a band in two),
  2319. // the selected band's panel floating below (style, mix, the big DRIVE, the tone faders, level, remove), global
  2320. // settings in the bottom bar.
  2321. class EmberEditor final : public ProEditor
  2322. {
  2323. public:
  2324. EmberEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::ember, d, 960, 540)
  2325. {
  2326. specArea = disp();
  2327. specMinHz = 20.0;
  2328. specMaxHz = 20000.0;
  2329. fillDemo();
  2330. }
  2331. private:
  2332. enum { idRemove = 1, idPrev, idNext, idPower, idSolo, idMute, idBands, idMod, idClassic };
  2333. int selected = 0, dragHandle = -1, dragEdge = -1, hoverHandle = -1;
  2334. bool showMod = false; // round 152: the panel shows the modulation (LFOs, follower, four slots) instead of the band
  2335. int xp (int b, int f) const { return mixsuite::ember::bandExtra (b, f); } // round 128: a band's power, state, tone, feedback, dynamics
  2336. bool powered (int b) const { return v (xp (b, 0)) >= 0.5f; }
  2337. mixsuite::ember::BandState state (int b) const { return mixsuite::ember::bandState (v (xp (b, 1))); }
  2338. juce::String title() const override { return "Ember Saturator"; }
  2339. juce::String gestures() const override { return tr ("Double-click: split a band - drag a band's handle: drive - drag a line: crossover"); }
  2340. bool usesSpectrum() const override { return true; }
  2341. juce::Rectangle<float> disp() const { return bodyArea().withTrimmedBottom (24.0f).withTrimmedTop (4.0f); }
  2342. juce::Rectangle<float> panelArea() const
  2343. {
  2344. const auto d = disp();
  2345. return { d.getCentreX() - 420.0f, d.getBottom() - 176.0f, 840.0f, 168.0f };
  2346. }
  2347. int count() const
  2348. {
  2349. // round 150: up to six bands (Bands + More bands)
  2350. const auto more = juce::jlimit (0, 2, juce::roundToInt (v (mixsuite::ember::bandsMore) * 2.0f));
  2351. return more > 0 ? mixsuite::ember::firstBands + more : mixsuite::ember::bandCount (v (mixsuite::ember::bands));
  2352. }
  2353. int chr (int b) const { return mixsuite::ember::characterIndex (v (mixsuite::ember::characterParam (b))); }
  2354. // round 135: the Decapitator-role strip along the top of the display (voice row, PUNISH, THUMP, STEEP, the wide
  2355. // filter ranges) and the in / out meter at its right; the band handles start under it
  2356. static constexpr float handleTop = 64.0f;
  2357. juce::Rectangle<float> stripArea() const { const auto d = disp(); return { d.getX() + 8.0f, d.getY() + 6.0f, d.getWidth() - 16.0f, 24.0f }; }
  2358. juce::Rectangle<float> vuArea() const { const auto d = disp(); return { d.getRight() - 64.0f, d.getY() + 38.0f, 56.0f, 120.0f }; }
  2359. bool wide() const { return v (mixsuite::ember::wideCuts) >= 0.5f; }
  2360. int fp (int b, int f) const { return mixsuite::ember::bandParam (b, f); }
  2361. double xoHz (int i) const { return mixsuite::ember::crossoverHz (v (mixsuite::ember::crossoverParam (i))); }
  2362. float edgeX (int i) const
  2363. {
  2364. const auto d = disp();
  2365. if (i <= 0) return d.getX();
  2366. if (i >= count()) return d.getRight();
  2367. return xForHz (xoHz (i - 1), d);
  2368. }
  2369. float handleY (int b) const
  2370. {
  2371. const auto d = disp();
  2372. return d.getY() + handleTop + (panelArea().getY() - 30.0f - d.getY() - handleTop) * (1.0f - v (fp (b, 1)));
  2373. }
  2374. juce::Rectangle<float> handle (int b) const { return juce::Rectangle<float> (38.0f, 16.0f).withCentre ({ 0.5f * (edgeX (b) + edgeX (b + 1)), handleY (b) }); }
  2375. int handleAt (juce::Point<float> p) const
  2376. {
  2377. for (int b = 0; b < count(); ++b)
  2378. if (handle (b).expanded (4.0f).contains (p)) return b;
  2379. return -1;
  2380. }
  2381. int edgeAt (juce::Point<float> p) const
  2382. {
  2383. for (int i = 1; i < count(); ++i)
  2384. if (std::abs (edgeX (i) - p.x) < 5.0f) return i;
  2385. return -1;
  2386. }
  2387. int bandAtX (float x) const
  2388. {
  2389. for (int b = 0; b < count(); ++b)
  2390. if (x < edgeX (b + 1)) return b;
  2391. return count() - 1;
  2392. }
  2393. float specY (float db) const { const auto d = disp(); return d.getY() + d.getHeight() * juce::jlimit (0.0f, 1.0f, (-db - 12.0f) / 90.0f); }
  2394. void layoutControls (std::vector<Ctl>& out) const override
  2395. {
  2396. using namespace mixsuite::ember;
  2397. if (selected >= count()) return;
  2398. const auto a = panelArea();
  2399. const auto b = selected;
  2400. auto add = [&] (Ctl c) { c.colour = peqview::bandColour (b); out.push_back (c); };
  2401. // round 152 (Saturn 2's modulation, measured laws): MOD swaps the band panel for the modulation panel
  2402. out.push_back (button ({ a.getRight() - 146.0f, a.getY() + 10.0f, 66.0f, 20.0f }, idMod, tr ("Mod"), showMod,
  2403. tr ("Modulation: two LFOs and an envelope follower moving up to four targets")));
  2404. if (showMod)
  2405. {
  2406. out.push_back (knob ({ a.getX() + 10.0f, a.getY() + 40.0f, 60.0f, 74.0f }, lfo1Rate, tr ("LFO 1")));
  2407. out.push_back (menu ({ a.getX() + 10.0f, a.getY() + 122.0f, 60.0f, 22.0f }, lfo1Shape, {}, tr ("Sine|Triangle|Square|Ease in|Ease out")));
  2408. out.push_back (knob ({ a.getX() + 76.0f, a.getY() + 40.0f, 60.0f, 74.0f }, lfo2Rate, tr ("LFO 2")));
  2409. out.push_back (menu ({ a.getX() + 76.0f, a.getY() + 122.0f, 60.0f, 22.0f }, lfo2Shape, {}, tr ("Sine|Triangle|Square|Ease in|Ease out")));
  2410. out.push_back (knob ({ a.getX() + 150.0f, a.getY() + 40.0f, 60.0f, 74.0f }, envAttack, tr ("Attack")));
  2411. out.push_back (knob ({ a.getX() + 214.0f, a.getY() + 40.0f, 60.0f, 74.0f }, envRelease, tr ("Release")));
  2412. juce::String targets;
  2413. for (int t = 0; t < modTargets; ++t) targets << (t > 0 ? "|" : "") << tr (modTargetName (t));
  2414. for (int k = 0; k < modSlots; ++k)
  2415. {
  2416. const auto y = a.getY() + 38.0f + 31.0f * (float) k;
  2417. out.push_back (menu ({ a.getX() + 300.0f, y, 96.0f, 24.0f }, mod1Source + 3 * k, {}, tr ("Off|LFO 1|LFO 2|Envelope")));
  2418. out.push_back (menu ({ a.getX() + 402.0f, y, 140.0f, 24.0f }, mod1Target + 3 * k, {}, targets));
  2419. out.push_back (barValue ({ a.getX() + 548.0f, y, 120.0f, 24.0f }, mod1Amount + 3 * k, tr ("Amount")));
  2420. }
  2421. return;
  2422. }
  2423. // round 152: the band's own crossover slope (its upper edge; Global = the bottom bar's Crossover) and the
  2424. // processing mode (linear phase: zero-phase bands, 64 ms latency at 48 kHz)
  2425. if (b < count() - 1)
  2426. add (menu ({ a.getX() + 10.0f, a.getY() + 36.0f, 60.0f, 20.0f }, crossSlope1 + b, {}, tr ("Global") + "|6|12|24|36|48"));
  2427. out.push_back (toggle ({ a.getRight() - 146.0f, a.getY() + 32.0f, 136.0f, 18.0f }, processing, tr ("Linear phase")));
  2428. // Saturn's band panel order (round 128): power, solo / mute, style | MIX, FEEDBACK, FREQ, DYNAMICS | DRIVE |
  2429. // the band's TONE (bass, mid, treble, presence) | LEVEL; the whole effect's auto gain and dry / wet on the right
  2430. out.push_back (button ({ a.getX() + 70.0f, a.getY() + 12.0f, 32.0f, 22.0f }, idPower, tr ("On"), powered (b), tr ("Band on / off: a band switched off passes clean")));
  2431. out.push_back (button ({ a.getX() + 106.0f, a.getY() + 12.0f, 22.0f, 22.0f }, idSolo, "S", state (b) == BandState::solo, tr ("Solo the band")));
  2432. out.push_back (button ({ a.getX() + 130.0f, a.getY() + 12.0f, 22.0f, 22.0f }, idMute, "M", state (b) == BandState::mute, tr ("Mute the band")));
  2433. add (menu ({ a.getX() + 160.0f, a.getY() + 10.0f, 92.0f, 26.0f }, fp (b, 0), {}, "Tube|Tape|Transistor|Fuzz"));
  2434. // round 150: the band's character (the 28 voicings measured on the reference's styles; Off = the Style menu)
  2435. {
  2436. juce::String opts = tr ("Off");
  2437. for (int k = 1; k <= characters; ++k) opts << "|" << tr (characterName (k));
  2438. add (menu ({ a.getX() + 256.0f, a.getY() + 10.0f, 92.0f, 26.0f }, characterParam (b), {}, opts));
  2439. }
  2440. add (knob ({ a.getX() + 10.0f, a.getY() + 60.0f, 66.0f, 92.0f }, fp (b, 2), tr ("Mix")));
  2441. add (knob ({ a.getX() + 78.0f, a.getY() + 60.0f, 66.0f, 92.0f }, xp (b, 6), tr ("Feedback")));
  2442. add (knob ({ a.getX() + 146.0f, a.getY() + 60.0f, 66.0f, 92.0f }, xp (b, 7), tr ("Freq")));
  2443. add (knob ({ a.getX() + 214.0f, a.getY() + 60.0f, 70.0f, 92.0f }, xp (b, 8), tr ("Dynamics"), 1, true));
  2444. add (knob ({ a.getX() + 290.0f, a.getY() + 40.0f, 124.0f, 128.0f }, fp (b, 1), tr ("Drive"), 2));
  2445. // round 147 (Saturn 2): the drive pan beside the drive (the far channel's drive shrinks), the band's pan under
  2446. // its level; both act on left / right or on mid / side (the bottom bar's Channel)
  2447. add (knob ({ a.getX() + 352.0f, a.getY() + 2.0f, 74.0f, 52.0f }, bandDrivePanParam (b), tr ("Drive pan"), 0, true));
  2448. add (fader ({ a.getX() + 432.0f, a.getY() + 14.0f, 42.0f, 148.0f }, xp (b, 2), tr ("Bass"), true));
  2449. add (fader ({ a.getX() + 476.0f, a.getY() + 14.0f, 42.0f, 148.0f }, xp (b, 3), tr ("Mid"), true));
  2450. add (fader ({ a.getX() + 520.0f, a.getY() + 14.0f, 42.0f, 148.0f }, xp (b, 4), tr ("Treble"), true));
  2451. add (fader ({ a.getX() + 564.0f, a.getY() + 14.0f, 42.0f, 148.0f }, xp (b, 5), tr ("Presence"), true));
  2452. add (knob ({ a.getX() + 612.0f, a.getY() + 8.0f, 70.0f, 78.0f }, fp (b, 3), tr ("Level"), 1, true));
  2453. add (knob ({ a.getX() + 612.0f, a.getY() + 88.0f, 70.0f, 78.0f }, bandPanParam (b), tr ("Pan"), 1, true));
  2454. if (count() > 1)
  2455. {
  2456. out.push_back (button ({ a.getRight() - 72.0f, a.getY() + 10.0f, 20.0f, 20.0f }, idPrev, "<", false, tr ("Previous / next band")));
  2457. out.push_back (button ({ a.getRight() - 50.0f, a.getY() + 10.0f, 20.0f, 20.0f }, idNext, ">", false, tr ("Previous / next band")));
  2458. out.push_back (button ({ a.getRight() - 26.0f, a.getY() + 10.0f, 20.0f, 20.0f }, idRemove, "x", false, tr ("Remove the band (its neighbour takes its range)")));
  2459. }
  2460. out.push_back (toggle ({ a.getRight() - 146.0f, a.getY() + 52.0f, 136.0f, 22.0f }, autoGain, tr ("Auto gain")));
  2461. out.push_back (knob ({ a.getRight() - 148.0f, a.getY() + 84.0f, 66.0f, 80.0f }, mix, tr ("Dry / wet"), 0));
  2462. out.push_back (knob ({ a.getRight() - 78.0f, a.getY() + 84.0f, 66.0f, 80.0f }, output, tr ("Output"), 0, true)); // round 135: on the panel
  2463. // round 135: the strip (one click per voicing, the reference's switches)
  2464. const auto s = stripArea();
  2465. out.push_back (tabs ({ s.getX(), s.getY(), 372.0f, s.getHeight() }, voice, tr ("Style menu|Tape pre|Console|Grit|Triode|Pentode"),
  2466. { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f }));
  2467. out.push_back (toggle ({ s.getX() + 376.0f, s.getY(), 76.0f, s.getHeight() }, punish, tr ("Punish")));
  2468. out.push_back (toggle ({ s.getX() + 456.0f, s.getY(), 70.0f, s.getHeight() }, thump, tr ("Thump")));
  2469. out.push_back (toggle ({ s.getX() + 530.0f, s.getY(), 64.0f, s.getHeight() }, steep, tr ("Steep")));
  2470. out.push_back (toggle ({ s.getX() + 598.0f, s.getY(), 92.0f, s.getHeight() }, wideCuts, tr ("Wide cuts")));
  2471. // round 150 (Saturn 2): the whole effect's input / output pan (left / right, or mid / side with Channel M/S);
  2472. // they end left of the IN / OUT meter
  2473. out.push_back (barValue ({ s.getX() + 698.0f, s.getY(), 86.0f, s.getHeight() }, inputPan, tr ("In pan")));
  2474. out.push_back (barValue ({ s.getX() + 788.0f, s.getY(), 86.0f, s.getHeight() }, outputPan, tr ("Out pan")));
  2475. // round tp172d: back to the Classic panel (the Voicing on; Ember's Classic window replaces this one)
  2476. out.push_back (button ({ s.getX() + 880.0f, s.getY(), 64.0f, s.getHeight() }, idClassic, tr ("Classic"), false,
  2477. tr ("The Classic panel: one-screen hardware saturator (Drive, Punish, five styles)")));
  2478. const auto bar = barArea();
  2479. const auto cy = bar.getCentreY();
  2480. out.push_back (barMenu ({ 10.0f, cy - 11.0f, 150.0f, 22.0f }, xoverSlope, tr ("Crossover"), "12 dB/oct|24 dB/oct|48 dB/oct", { 0.0f, 0.5f, 1.0f }));
  2481. out.push_back (barMenu ({ 166.0f, cy - 11.0f, 130.0f, 22.0f }, quality, tr ("Oversampling"), "2x|4x|8x", { 0.0f, 0.5f, 1.0f }));
  2482. out.push_back (button ({ 302.0f, cy - 11.0f, 90.0f, 22.0f }, idBands, tr ("Bands") + " " + juce::String (count()), false,
  2483. tr ("Number of bands (1 to 6)")));
  2484. out.push_back (barValue ({ 398.0f, cy - 11.0f, 90.0f, 22.0f }, inputGain, tr ("In")));
  2485. out.push_back (barValue ({ 494.0f, cy - 11.0f, 80.0f, 22.0f }, tone, tr ("Tilt")));
  2486. out.push_back (barValue ({ 580.0f, cy - 11.0f, 110.0f, 22.0f }, wide() ? lowCutWide : lowCut, tr ("Low cut")));
  2487. out.push_back (barValue ({ 696.0f, cy - 11.0f, 120.0f, 22.0f }, wide() ? highCutWide : highCut, tr ("High cut")));
  2488. // round 147 (Saturn 2's channel mode): the bands work on left / right or on mid / side
  2489. out.push_back (barMenu ({ 822.0f, cy - 11.0f, 128.0f, 22.0f }, channelMode, tr ("Channel"), "L/R|M/S", { 0.0f, 1.0f }));
  2490. }
  2491. // band settings as a block (style, drive, mix, level + round 128's power, state, tone, feedback, dynamics) to move
  2492. // bands around when splitting / removing
  2493. static constexpr int blockSize = 4 + mixsuite::ember::extraFields + 3; // round 147: + drive pan, pan; round 150: + character
  2494. int blockParam (int b, int k) const
  2495. {
  2496. if (k == blockSize - 3) return mixsuite::ember::bandDrivePanParam (b);
  2497. if (k == blockSize - 2) return mixsuite::ember::bandPanParam (b);
  2498. if (k == blockSize - 1) return mixsuite::ember::characterParam (b);
  2499. return k < 4 ? fp (b, k) : xp (b, k - 4);
  2500. }
  2501. std::array<float, blockSize> bandValues (int b) const
  2502. {
  2503. std::array<float, blockSize> out {};
  2504. for (int k = 0; k < blockSize; ++k) out[(std::size_t) k] = v (blockParam (b, k));
  2505. return out;
  2506. }
  2507. void splitAt (float x)
  2508. {
  2509. using namespace mixsuite::ember;
  2510. const auto n = count();
  2511. if (n >= maxBands) return;
  2512. const auto hz = juce::jlimit (30.0, 18000.0, hzForX (x, disp()));
  2513. const auto at = bandAtX (x); // the band split in two: band at + 1 is the new upper half
  2514. std::vector<double> xo;
  2515. std::vector<float> sl; // round 152: each crossover's own slope moves with it
  2516. for (int i = 0; i < n - 1; ++i) { xo.push_back (xoHz (i)); sl.push_back (v (crossSlope1 + i)); }
  2517. xo.insert (xo.begin() + at, hz);
  2518. sl.insert (sl.begin() + at, at < (int) sl.size() ? sl[(std::size_t) at] : 0.0f);
  2519. std::vector<std::array<float, blockSize>> vals;
  2520. for (int b = 0; b < n; ++b) vals.push_back (bandValues (b));
  2521. vals.insert (vals.begin() + at + 1, vals[(std::size_t) at]);
  2522. apply (xo, vals, sl);
  2523. selected = at + 1;
  2524. }
  2525. void removeBand (int b)
  2526. {
  2527. const auto n = count();
  2528. if (n <= 1) return;
  2529. std::vector<double> xo;
  2530. std::vector<float> sl;
  2531. for (int i = 0; i < n - 1; ++i) { xo.push_back (xoHz (i)); sl.push_back (v (mixsuite::ember::crossSlope1 + i)); }
  2532. xo.erase (xo.begin() + juce::jmin (b, n - 2)); // the line on its right (the last band: on its left)
  2533. sl.erase (sl.begin() + juce::jmin (b, n - 2));
  2534. std::vector<std::array<float, blockSize>> vals;
  2535. for (int k = 0; k < n; ++k)
  2536. if (k != b) vals.push_back (bandValues (k));
  2537. apply (xo, vals, sl);
  2538. selected = juce::jmin (b, n - 2);
  2539. }
  2540. void apply (const std::vector<double>& xo, const std::vector<std::array<float, blockSize>>& vals, const std::vector<float>& slopes = {})
  2541. {
  2542. using namespace mixsuite::ember;
  2543. std::vector<std::pair<int, float>> c;
  2544. const auto n = (int) vals.size();
  2545. const auto [bv, mv] = bandCountValues (n);
  2546. c.push_back ({ bands, bv });
  2547. c.push_back ({ bandsMore, mv });
  2548. for (int i = 0; i < (int) xo.size(); ++i) c.push_back ({ crossoverParam (i), crossoverValue (xo[(std::size_t) i]) });
  2549. for (int i = 0; i < (int) slopes.size() && i < maxBands - 1; ++i) c.push_back ({ crossSlope1 + i, slopes[(std::size_t) i] });
  2550. for (int b = 0; b < n; ++b)
  2551. for (int f = 0; f < blockSize; ++f) c.push_back ({ blockParam (b, f), vals[(std::size_t) b][(std::size_t) f] });
  2552. set (c);
  2553. }
  2554. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  2555. {
  2556. using mixsuite::ember::BandState;
  2557. if (c.id == idRemove) removeBand (selected);
  2558. else if (c.id == idPower) set ({ { xp (selected, 0), powered (selected) ? 0.0f : 1.0f } });
  2559. else if (c.id == idSolo) set ({ { xp (selected, 1), state (selected) == BandState::solo ? 0.0f : 0.5f } });
  2560. else if (c.id == idMute) set ({ { xp (selected, 1), state (selected) == BandState::mute ? 0.0f : 1.0f } });
  2561. else if (c.id == idPrev) selected = (selected + count() - 1) % count();
  2562. else if (c.id == idNext) selected = (selected + 1) % count();
  2563. else if (c.id == idBands) showBandsMenu();
  2564. else if (c.id == idMod) showMod = ! showMod; // round 152
  2565. else if (c.id == idClassic) // round tp172d
  2566. {
  2567. set ({ { mixsuite::ember::voicing, 1.0f } });
  2568. if (! demo) NativeEffectWindows::switchEmberEditor (engine, track, slot, true);
  2569. return;
  2570. }
  2571. repaint();
  2572. }
  2573. // round 150: 1 … 6 bands; more bands split the top band, fewer remove the top ones
  2574. void showBandsMenu()
  2575. {
  2576. juce::PopupMenu m;
  2577. for (int k = 1; k <= mixsuite::ember::maxBands; ++k)
  2578. m.addItem (juce::String (k), true, count() == k, [this, k] { setBandCount (k); });
  2579. m.showMenuAsync (juce::PopupMenu::Options().withMousePosition()); // round 152 (checked by hand): at the mouse, not under the window
  2580. }
  2581. void setBandCount (int target)
  2582. {
  2583. while (count() > target) removeBand (count() - 1);
  2584. while (count() < target)
  2585. {
  2586. const auto n = count();
  2587. const auto lo = n > 1 ? edgeX (n - 1) : disp().getX();
  2588. const auto before = n;
  2589. splitAt (0.5f * (lo + disp().getRight()));
  2590. if (count() == before) break;
  2591. }
  2592. repaint();
  2593. }
  2594. bool bodyDown (const juce::MouseEvent& e) override
  2595. {
  2596. const auto p = e.position;
  2597. dragHandle = dragEdge = -1;
  2598. if (selected < count() && panelArea().contains (p)) return false;
  2599. if (! disp().contains (p)) return false;
  2600. if (const auto h = handleAt (p); h >= 0)
  2601. {
  2602. selected = h;
  2603. if (e.mods.isAltDown()) { removeBand (h); return false; }
  2604. if (ui::isResetClick (e)) { set ({ { fp (h, 1), 0.0f } }); return false; }
  2605. dragHandle = h;
  2606. return true;
  2607. }
  2608. if (const auto i = edgeAt (p); i > 0) { dragEdge = i; return true; }
  2609. selected = bandAtX (p.x);
  2610. repaint();
  2611. return false;
  2612. }
  2613. void bodyDrag (const juce::MouseEvent& e) override
  2614. {
  2615. using namespace mixsuite::ember;
  2616. const auto d = disp();
  2617. if (dragHandle >= 0)
  2618. {
  2619. const auto f = 1.0f - (e.position.y - d.getY() - handleTop) / (panelArea().getY() - 30.0f - d.getY() - handleTop);
  2620. set ({ { fp (dragHandle, 1), juce::jlimit (0.0f, 1.0f, f) } });
  2621. ui::showValueTip (*this, handle (dragHandle).toNearestInt(), tr ("Drive") + " " + text (fp (dragHandle, 1)));
  2622. return;
  2623. }
  2624. if (dragEdge > 0)
  2625. {
  2626. const auto lo = edgeX (dragEdge - 1) + 14.0f, hi = edgeX (dragEdge + 1) - 14.0f;
  2627. const auto hz = juce::jlimit (30.0, 18000.0, hzForX (juce::jlimit (lo, hi, e.position.x), d));
  2628. set ({ { crossoverParam (dragEdge - 1), crossoverValue (hz) } });
  2629. ui::showValueTip (*this, juce::Rectangle<int> (16, 16).withCentre (e.position.toInt()), tr ("Crossover") + " " + text (crossoverParam (dragEdge - 1)));
  2630. }
  2631. }
  2632. bool bodyDoubleClick (const juce::MouseEvent& e) override
  2633. {
  2634. if (! disp().contains (e.position) || (selected < count() && panelArea().contains (e.position))) return false;
  2635. if (const auto h = handleAt (e.position); h >= 0) { removeBand (h); return true; }
  2636. splitAt (e.position.x);
  2637. return true;
  2638. }
  2639. bool bodyWheel (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
  2640. {
  2641. const auto h = handleAt (e.position);
  2642. if (h < 0) return false;
  2643. const auto prm = fp (h, 1);
  2644. if (const auto x = ui::wheelValue (v (prm), e, w, specFor (prm))) set ({ { prm, (float) *x } });
  2645. return true;
  2646. }
  2647. void bodyMove (juce::Point<float> p) override { hoverHandle = handleAt (p); }
  2648. ui::Hint bodyHint (juce::Point<float> p) override
  2649. {
  2650. ui::Hint h;
  2651. if (! disp().contains (p)) return h;
  2652. if (handleAt (p) >= 0) h.text = tr ("Band handle: drag up / down = drive, wheel = drive, Alt-click or double-click = remove the band");
  2653. else if (edgeAt (p) > 0) h.text = tr ("Crossover: drag left or right");
  2654. else h.text = tr ("Click a band to edit it; double-click to split it in two (up to six bands)");
  2655. return h;
  2656. }
  2657. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  2658. {
  2659. using namespace mixsuite::ember;
  2660. const auto d = disp();
  2661. displayBackground (g, bodyArea());
  2662. frequencyLabels (g, d, d.getBottom() + 12.0f);
  2663. paintSpectrum (g, specPost, [this] (float db) { return specY (db); }, inColour().withAlpha (0.14f), inColour().withAlpha (0.45f));
  2664. const auto n = count();
  2665. for (int b = 0; b < n; ++b)
  2666. {
  2667. const auto c = peqview::bandColour (b);
  2668. const auto region = juce::Rectangle<float> (edgeX (b), d.getY(), edgeX (b + 1) - edgeX (b), d.getHeight());
  2669. g.setColour (c.withAlpha (b == selected ? 0.12f : 0.04f));
  2670. g.fillRect (region);
  2671. // the drive level line across the band, its handle and the band's name / drive
  2672. const auto h = handle (b);
  2673. g.setColour (c.withAlpha (0.5f));
  2674. g.drawHorizontalLine ((int) h.getCentreY(), region.getX(), region.getRight());
  2675. const auto hot = b == hoverHandle || b == dragHandle;
  2676. g.setColour (hot ? c.brighter (0.3f) : c);
  2677. g.fillRoundedRectangle (h, 4.0f);
  2678. g.setColour (colour::bg0);
  2679. g.drawRoundedRectangle (h, 4.0f, 1.0f);
  2680. g.setColour (colour::textPrimary);
  2681. g.setFont (font (type::caption, true));
  2682. // round 135: band 1 shows the voicing when one is chosen (it replaces the style)
  2683. const auto vk = mixsuite::ember::voiceIndex (v (mixsuite::ember::voice));
  2684. juce::String tag = caps (chr (b) > 0 ? tr (mixsuite::ember::characterName (chr (b)))
  2685. : (b == 0 && vk > 0 && n == 1 ? tr (mixsuite::ember::voiceName (vk)) : text (fp (b, 0)))) + " " + text (fp (b, 1));
  2686. if (! powered (b)) tag = tr ("OFF") + " " + tag;
  2687. else if (state (b) == mixsuite::ember::BandState::solo) tag = "S " + tag;
  2688. else if (state (b) == mixsuite::ember::BandState::mute) tag = "M " + tag;
  2689. g.drawText (tag, juce::Rectangle<float> (region.getX() + 2.0f, h.getY() - 18.0f, region.getWidth() - 4.0f, 14.0f), juce::Justification::centred, true);
  2690. }
  2691. // round 135: the in / out level meter (the reference's VU: what the drive does to the level)
  2692. {
  2693. const auto m = vuArea();
  2694. g.setColour (colour::bg0.withAlpha (0.7f));
  2695. g.fillRoundedRectangle (m.expanded (4.0f, 16.0f).withTrimmedBottom (-2.0f), 4.0f);
  2696. const auto bars = m.withTrimmedTop (2.0f).withTrimmedBottom (14.0f);
  2697. const auto in = dbOf (liveMeter (2)), out = dbOf (liveMeter (3));
  2698. drawMeter (g, bars.withWidth (bars.getWidth() * 0.5f - 2.0f), in, -48.0f, inColour());
  2699. drawMeter (g, bars.withTrimmedLeft (bars.getWidth() * 0.5f + 2.0f), out, -48.0f, colour::accent);
  2700. g.setColour (colour::textSecondary);
  2701. g.setFont (font (type::caption));
  2702. g.drawText (tr ("IN"), juce::Rectangle<float> (bars.getX(), m.getY() - 14.0f, bars.getWidth() * 0.5f, 12.0f), juce::Justification::centred, false);
  2703. g.drawText (tr ("OUT"), juce::Rectangle<float> (bars.getCentreX(), m.getY() - 14.0f, bars.getWidth() * 0.5f, 12.0f), juce::Justification::centred, false);
  2704. g.drawText (juce::String (out > -100.0f ? out : -99.0f, 1), juce::Rectangle<float> (m.getX() - 4.0f, bars.getBottom() + 1.0f, m.getWidth() + 8.0f, 12.0f), juce::Justification::centred, false);
  2705. }
  2706. for (int i = 1; i < n; ++i)
  2707. {
  2708. const auto x = edgeX (i);
  2709. const auto hot = std::abs (mouse.x - x) < 5.0f && d.contains (mouse);
  2710. g.setColour (hot || dragEdge == i ? colour::textPrimary : colour::textSecondary.withAlpha (0.6f));
  2711. g.drawVerticalLine ((int) x, d.getY(), d.getBottom());
  2712. const auto knobR = juce::Rectangle<float> (16.0f, 16.0f).withCentre ({ x, d.getY() + 44.0f }); // round 135: under the strip
  2713. g.setColour (colour::bg5);
  2714. g.fillRoundedRectangle (knobR, 3.0f);
  2715. g.setColour (colour::textSecondary);
  2716. g.setFont (font (type::caption));
  2717. g.drawText (text (mixsuite::ember::crossoverParam (i - 1)), juce::Rectangle<float> (x + 10.0f, d.getY() + 37.0f, 70.0f, 14.0f), juce::Justification::centredLeft, false);
  2718. }
  2719. if (selected < n)
  2720. {
  2721. const auto a = panelArea();
  2722. const auto c = peqview::bandColour (selected);
  2723. drawPanel (g, a, c);
  2724. g.setColour (c);
  2725. g.fillRoundedRectangle (juce::Rectangle<float> (a.getX() + 14.0f, a.getY() - 1.0f, 46.0f, 3.0f), 1.5f);
  2726. g.setColour (colour::textSecondary);
  2727. g.setFont (font (type::small, true));
  2728. if (showMod) // round 152: the modulation panel's captions
  2729. {
  2730. g.drawText (tr ("Modulation"), juce::Rectangle<float> (a.getX() + 12.0f, a.getY() + 10.0f, 120.0f, 26.0f), juce::Justification::centredLeft, false);
  2731. caption (g, { a.getX() + 150.0f, a.getY() + 24.0f, 124.0f, 12.0f }, tr ("Envelope"));
  2732. caption (g, { a.getX() + 300.0f, a.getY() + 20.0f, 368.0f, 12.0f }, tr ("Source / target / amount"));
  2733. return;
  2734. }
  2735. g.drawText (tr ("Band {0}", { juce::String (selected + 1) }), juce::Rectangle<float> (a.getX() + 12.0f, a.getY() + 10.0f, 58.0f, 26.0f), juce::Justification::centredLeft, false);
  2736. caption (g, { a.getX() + 432.0f, a.getY() + 2.0f, 174.0f, 12.0f }, tr ("Tone"));
  2737. // the curve of the band's style, as a small preview
  2738. const auto cv = juce::Rectangle<float> (a.getX() + 228.0f, a.getY() + 10.0f, 0.0f, 0.0f);
  2739. juce::ignoreUnused (cv, fx);
  2740. }
  2741. }
  2742. };
  2743. // =============================================================================================================
  2744. // Aether — the reference "air" processor's workflow: the output level on an arc meter fills the top; under it two
  2745. // big knobs side by side (MID AIR = the presence exciter, HIGH AIR = the air shelf) with the link button between
  2746. // them, the power switch at the bottom left and the small TRIM at the bottom right. LYNX's extra settings (the two
  2747. // frequencies, the exciter's character, mix) sit in the bottom bar.
  2748. class AetherEditor final : public ProEditor
  2749. {
  2750. public:
  2751. AetherEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::aether, d, 720, 520) { fillDemo(); }
  2752. private:
  2753. enum { idLink = 1, idPower };
  2754. bool linked = false;
  2755. juce::String title() const override { return "Aether"; }
  2756. juce::String gestures() const override { return tr ("Link: both knobs move together"); }
  2757. bool usesHistory() const override { return true; }
  2758. // the dynamic air model (round 124) has its own two amounts; the classic mode drives the exciter and the shelf
  2759. bool dynamicModel() const { return v (P ("Dynamic")) >= 0.5f; }
  2760. int pMid() const { return dynamicModel() ? P ("Mid air") : P ("Harmonics"); }
  2761. int pHigh() const { return dynamicModel() ? P ("High air") : P ("Air"); }
  2762. juce::Rectangle<float> display() const { return bodyArea().withHeight (206.0f); }
  2763. juce::Rectangle<float> panel() const { return bodyArea().withTrimmedTop (206.0f); }
  2764. Column demoColumn (int i) const override
  2765. {
  2766. const auto in = demoInDb (i) - 4.0f;
  2767. return { in, in + 1.5f, 0.0f };
  2768. }
  2769. void linkChanges (std::vector<std::pair<int, float>>& changes) const override
  2770. {
  2771. if (! linked || changes.size() != 1) return;
  2772. const auto [p, x] = changes.front();
  2773. if (p != pMid() && p != pHigh()) return;
  2774. const auto other = p == pMid() ? pHigh() : pMid();
  2775. changes.push_back ({ other, juce::jlimit (0.0f, 1.0f, v (other) + (x - v (p))) });
  2776. }
  2777. void layoutControls (std::vector<Ctl>& out) const override
  2778. {
  2779. const auto a = panel();
  2780. const auto cy = a.getY() + 12.0f;
  2781. out.push_back (knob ({ 125.0f, cy + 10.0f, 150.0f, 184.0f }, pMid(), tr ("Mid air"), 2));
  2782. out.push_back (knob ({ 445.0f, cy + 10.0f, 150.0f, 184.0f }, pHigh(), tr ("High air"), 2));
  2783. out.push_back (button ({ 330.0f, cy + 70.0f, 60.0f, 28.0f }, idLink, tr ("Link"), linked,
  2784. tr ("Link: move both knobs together (keeps their difference)")));
  2785. out.push_back (custom ({ 28.0f, a.getBottom() - 70.0f, 48.0f, 48.0f }, idPower, -1, tr ("Power: switch the effect on or off")));
  2786. out.push_back (knob ({ 626.0f, a.getBottom() - 92.0f, 72.0f, 86.0f }, P ("Output"), tr ("Trim"), 0, true));
  2787. const auto b = barArea();
  2788. const auto y = b.getCentreY() - 11.0f;
  2789. out.push_back (barValue ({ 8.0f, y, 110.0f, 22.0f }, P ("Dynamic"), tr ("Dynamic")));
  2790. if (dynamicModel())
  2791. {
  2792. out.push_back (barValue ({ 490.0f, y, 110.0f, 22.0f }, P ("Mix"), tr ("Mix")));
  2793. out.push_back (barValue ({ 604.0f, y, 110.0f, 22.0f }, P ("Output"), tr ("Trim")));
  2794. return;
  2795. }
  2796. out.push_back (barValue ({ 122.0f, y, 120.0f, 22.0f }, P ("Exciter freq."), tr ("Mid freq")));
  2797. out.push_back (barValue ({ 246.0f, y, 120.0f, 22.0f }, P ("Character"), tr ("Even / odd")));
  2798. out.push_back (barValue ({ 370.0f, y, 116.0f, 22.0f }, P ("Air freq."), tr ("High freq")));
  2799. out.push_back (barValue ({ 490.0f, y, 110.0f, 22.0f }, P ("Mix"), tr ("Mix")));
  2800. out.push_back (barValue ({ 604.0f, y, 110.0f, 22.0f }, P ("Output"), tr ("Trim")));
  2801. }
  2802. void buttonPressed (const Ctl& c, const juce::MouseEvent&) override
  2803. {
  2804. if (c.id == idLink) { linked = ! linked; repaint(); }
  2805. }
  2806. void customDown (const Ctl& c, const juce::MouseEvent&) override
  2807. {
  2808. if (c.id == idPower) toggleEnabled();
  2809. }
  2810. // --- the frosted panel (round tp172c: the reference's light lower half, drawn here from scratch) -------------
  2811. static inline const juce::Colour kSlate { 0xff33414d }, kSlateDim { 0xff6a7884 };
  2812. void frostFill (juce::Graphics& g, juce::Rectangle<float> r) const
  2813. {
  2814. const auto a = panel();
  2815. g.setGradientFill (juce::ColourGradient (juce::Colour (0xffe3edf2), 0.0f, a.getY(), juce::Colour (0xffc6d6df), 0.0f, a.getBottom(), false));
  2816. g.fillRect (r);
  2817. }
  2818. static void frostDisc (juce::Graphics& g, juce::Rectangle<float> r, bool hover)
  2819. {
  2820. const auto R = r.getWidth() * 0.5f;
  2821. for (int i = 4; i >= 1; --i) // a soft shadow under the disc
  2822. {
  2823. g.setColour (juce::Colour (0xff4f6878).withAlpha (0.05f));
  2824. g.fillEllipse (r.translated (0.0f, R * 0.05f * (float) i).expanded (R * 0.025f * (float) i));
  2825. }
  2826. g.setGradientFill (juce::ColourGradient (juce::Colour (hover ? 0xffffffff : 0xfffbfdfe), r.getX() + R * 0.6f, r.getY() + R * 0.3f,
  2827. juce::Colour (0xffd7e3ea), r.getRight() - R * 0.3f, r.getBottom(), true));
  2828. g.fillEllipse (r);
  2829. g.setColour (juce::Colour (0xffb7c7d1));
  2830. g.drawEllipse (r.reduced (0.5f), 1.0f);
  2831. g.setColour (juce::Colours::white);
  2832. g.drawEllipse (r.reduced (R * 0.07f), 1.0f);
  2833. }
  2834. void slateText (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& t, float size, bool bold, juce::Colour col = kSlate) const
  2835. {
  2836. g.setColour (col);
  2837. g.setFont (juce::Font (theme::font (size, bold)).withExtraKerningFactor (bold ? 0.08f : 0.0f));
  2838. g.drawText (bold ? caps (t) : t, r, juce::Justification::centred, false);
  2839. }
  2840. // a disc knob: the value inside, a short pointer at the rim (angles as LYNX's knobs: −135°…+135°)
  2841. void discKnob (juce::Graphics& g, juce::Rectangle<float> slot, juce::Rectangle<float> disc, int param, const juce::String& cap, bool big)
  2842. {
  2843. frostFill (g, slot);
  2844. const auto hover = slot.contains (mouse);
  2845. frostDisc (g, disc, hover || dragCtl == param);
  2846. const auto R = disc.getWidth() * 0.5f;
  2847. const auto c = disc.getCentre();
  2848. const auto ang = juce::MathConstants<float>::pi * (-0.75f + 1.5f * v (param));
  2849. const juce::Point<float> d { std::sin (ang), -std::cos (ang) };
  2850. g.setColour (dragCtl == param ? accent.darker (0.3f) : kSlate);
  2851. g.drawLine ({ c + d * R * 0.70f, c + d * R * 0.90f }, big ? 2.6f : 2.0f);
  2852. if (big)
  2853. {
  2854. slateText (g, juce::Rectangle<float> (disc.getWidth(), 34.0f).withCentre (c.translated (0.0f, -8.0f)), text (param), 24.0f, false);
  2855. slateText (g, juce::Rectangle<float> (disc.getWidth(), 14.0f).withCentre (c.translated (0.0f, 18.0f)), cap, 11.0f, true, kSlateDim);
  2856. }
  2857. else
  2858. {
  2859. slateText (g, disc, text (param), 10.5f, false);
  2860. slateText (g, juce::Rectangle<float> (disc.getWidth() + 40.0f, 14.0f).withCentre ({ c.x, disc.getY() - 12.0f }), cap, 10.5f, true);
  2861. }
  2862. }
  2863. void paintOverlay (juce::Graphics& g, const EffectSlot&) override
  2864. {
  2865. const auto a = panel();
  2866. const auto cy = a.getY() + 12.0f;
  2867. // the two big discs (the slots drawn by layoutControls; their captions and values move inside the disc)
  2868. for (const auto& [x, p, cap, top] : { std::tuple<float, int, juce::String, const char*> { 125.0f, pMid(), tr ("Mid air"), "100" },
  2869. std::tuple<float, int, juce::String, const char*> { 445.0f, pHigh(), tr ("High air"), "15 dB" } })
  2870. {
  2871. const auto slot = juce::Rectangle<float> (x - 14.0f, cy + 10.0f, 178.0f, 184.0f);
  2872. const auto disc = juce::Rectangle<float> (146.0f, 146.0f).withCentre ({ x + 75.0f, cy + 12.0f + 73.0f });
  2873. discKnob (g, slot, disc, p, cap, true);
  2874. // the scale's ends beside the disc's foot
  2875. g.setColour (kSlateDim);
  2876. g.setFont (theme::font (10.5f, true));
  2877. g.drawText ("0", juce::Rectangle<float> (disc.getX() - 34.0f, disc.getBottom() - 16.0f, 30.0f, 14.0f), juce::Justification::centredRight, false);
  2878. g.drawText (top, juce::Rectangle<float> (disc.getRight() + 4.0f, disc.getBottom() - 16.0f, 52.0f, 14.0f), juce::Justification::centredLeft, false);
  2879. }
  2880. // the trim: a small disc
  2881. const auto trimSlot = juce::Rectangle<float> (612.0f, a.getBottom() - 112.0f, 100.0f, 108.0f);
  2882. discKnob (g, trimSlot, juce::Rectangle<float> (46.0f, 46.0f).withCentre ({ 662.0f, a.getBottom() - 62.0f }), P ("Output"), tr ("Trim"), false);
  2883. // the link: a frosted pill with two chain links, rimmed in the accent while linked
  2884. const auto link = juce::Rectangle<float> (330.0f, cy + 70.0f, 60.0f, 28.0f);
  2885. frostFill (g, link.expanded (2.0f));
  2886. const auto hover = link.contains (mouse);
  2887. g.setGradientFill (juce::ColourGradient (juce::Colour (hover ? 0xffffffff : 0xfff6fafc), 0.0f, link.getY(), juce::Colour (0xffd5e1e8), 0.0f, link.getBottom(), false));
  2888. g.fillRoundedRectangle (link, link.getHeight() * 0.5f);
  2889. g.setColour (linked ? accent.darker (0.2f) : juce::Colour (0xffa9bbc6));
  2890. g.drawRoundedRectangle (link.reduced (0.5f), link.getHeight() * 0.5f, linked ? 1.8f : 1.0f);
  2891. g.setColour (linked ? accent.darker (0.35f) : kSlate);
  2892. const auto lc = link.getCentre();
  2893. for (const auto dx : { -5.0f, 5.0f })
  2894. g.drawRoundedRectangle (juce::Rectangle<float> (13.0f, 8.0f).withCentre (lc.translated (dx, 0.0f)), 4.0f, 1.6f);
  2895. }
  2896. void paintCustom (juce::Graphics& g, const Ctl& c) override
  2897. {
  2898. if (c.id != idPower) return;
  2899. const auto* fx = current();
  2900. const auto on = fx != nullptr && fx->enabled;
  2901. // round tp172c: a small frosted disc on the pale panel, the power glyph lit in the accent
  2902. const auto r = c.r.reduced (2.0f);
  2903. frostDisc (g, r, c.r.contains (mouse));
  2904. juce::Path glyph;
  2905. const auto cx = r.getCentreX(), cy = r.getCentreY(), rr = r.getWidth() * 0.22f;
  2906. glyph.addCentredArc (cx, cy, rr, rr, 0.0f, 0.75f, juce::MathConstants<float>::twoPi - 0.75f, true);
  2907. glyph.startNewSubPath (cx, cy - rr * 1.3f);
  2908. glyph.lineTo (cx, cy - rr * 0.2f);
  2909. g.setColour (on ? accent.darker (0.35f) : kSlateDim);
  2910. g.strokePath (glyph, juce::PathStrokeType (2.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  2911. slateText (g, c.r.translated (0.0f, -18.0f).withHeight (14.0f).expanded (20.0f, 0.0f), tr ("Power"), 10.5f, true);
  2912. }
  2913. // the arc meter's scale: compressed at the bottom, open near 0 dB, like a programme meter
  2914. static float arcFrac (float db)
  2915. {
  2916. static constexpr std::array<std::pair<float, float>, 8> marks { { { -120.0f, 0.0f }, { -96.0f, 0.08f }, { -48.0f, 0.26f }, { -24.0f, 0.46f },
  2917. { -12.0f, 0.64f }, { -6.0f, 0.78f }, { -3.0f, 0.87f }, { 0.0f, 0.95f } } };
  2918. if (db <= marks.front().first) return 0.0f;
  2919. if (db >= 0.0f) return juce::jmin (1.0f, 0.95f + db * 0.0167f);
  2920. for (std::size_t k = 1; k < marks.size(); ++k)
  2921. if (db <= marks[k].first)
  2922. {
  2923. const auto [d0, f0] = marks[k - 1];
  2924. const auto [d1, f1] = marks[k];
  2925. return f0 + (f1 - f0) * (db - d0) / (d1 - d0);
  2926. }
  2927. return 0.95f;
  2928. }
  2929. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  2930. {
  2931. const auto d = display();
  2932. displayBackground (g, bodyArea());
  2933. juce::ColourGradient bg (colour::bg1.brighter (0.06f), d.getCentreX(), d.getY(), colour::bg0, d.getCentreX(), d.getBottom(), false);
  2934. g.setGradientFill (bg);
  2935. g.fillRect (d);
  2936. // the output level (peak of the last 100 ms, with a hold)
  2937. auto level = -120.0f, hold = -120.0f;
  2938. for (int k = 0; k < 10; ++k) level = juce::jmax (level, columnBack (k).out);
  2939. for (int k = 0; k < 150; ++k) hold = juce::jmax (hold, columnBack (k).out);
  2940. if (! fx.enabled) level = hold = -120.0f;
  2941. const juce::Point<float> centre { d.getCentreX(), d.getBottom() + 40.0f };
  2942. const auto radius = d.getHeight() * 0.86f;
  2943. const auto a0 = -0.36f * juce::MathConstants<float>::pi, a1 = 0.36f * juce::MathConstants<float>::pi;
  2944. const auto angleOf = [&] (float db) { return a0 + (a1 - a0) * arcFrac (db); };
  2945. const auto at = [&] (float angle, float rad) { return centre + juce::Point<float> { std::sin (angle), -std::cos (angle) } * rad; };
  2946. // the track and the lit part (blue, red above −6 dB)
  2947. juce::Path track;
  2948. track.addCentredArc (centre.x, centre.y, radius, radius, 0.0f, a0, a1, true);
  2949. g.setColour (juce::Colour (0xff08090b));
  2950. g.strokePath (track, juce::PathStrokeType (13.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  2951. g.setColour (colour::bg4);
  2952. g.strokePath (track, juce::PathStrokeType (10.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  2953. if (level > -119.0f)
  2954. {
  2955. const auto split = angleOf (-6.0f), now = angleOf (level);
  2956. juce::Path lit;
  2957. lit.addCentredArc (centre.x, centre.y, radius, radius, 0.0f, a0, juce::jmin (now, split), true);
  2958. g.setColour (accent.withAlpha (0.14f));
  2959. g.strokePath (lit, juce::PathStrokeType (24.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  2960. g.setGradientFill (juce::ColourGradient (colour::info, centre.x - radius, centre.y, accent, centre.x + radius * 0.4f, centre.y - radius, false));
  2961. g.strokePath (lit, juce::PathStrokeType (10.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  2962. if (now > split)
  2963. {
  2964. juce::Path hot;
  2965. hot.addCentredArc (centre.x, centre.y, radius, radius, 0.0f, split, now, true);
  2966. g.setColour (colour::accent);
  2967. g.strokePath (hot, juce::PathStrokeType (10.0f, juce::PathStrokeType::curved, juce::PathStrokeType::butt));
  2968. }
  2969. }
  2970. if (hold > -119.0f)
  2971. {
  2972. g.setColour (hold > -6.0f ? colour::accent : colour::textPrimary);
  2973. g.fillEllipse (juce::Rectangle<float> (9.0f, 9.0f).withCentre (at (angleOf (hold), radius)));
  2974. }
  2975. // the red zone and the scale
  2976. juce::Path zone;
  2977. zone.addCentredArc (centre.x, centre.y, radius + 12.0f, radius + 12.0f, 0.0f, angleOf (-6.0f), a1, true);
  2978. g.setColour (colour::accent.withAlpha (0.6f));
  2979. g.strokePath (zone, juce::PathStrokeType (2.0f));
  2980. g.setFont (font (type::caption, true));
  2981. for (const auto db : { -120.0f, -96.0f, -48.0f, -24.0f, -12.0f, -6.0f, -3.0f, 0.0f })
  2982. {
  2983. const auto angle = angleOf (db);
  2984. g.setColour (db >= -6.0f ? colour::accent : colour::textSecondary);
  2985. g.drawLine ({ at (angle, radius + 8.0f), at (angle, radius + 15.0f) }, 1.4f);
  2986. g.drawText (db <= -120.0f ? juce::String::fromUTF8 ("-\xe2\x88\x9e") : juce::String ((int) db),
  2987. juce::Rectangle<float> (40.0f, 14.0f).withCentre (at (angle, radius + 26.0f)), juce::Justification::centred, false);
  2988. }
  2989. g.setColour (colour::textPrimary);
  2990. g.setFont (font (type::title, true));
  2991. g.drawText (level > -119.0f ? juce::String (level, 1) + " dB" : juce::String::fromUTF8 ("-\xe2\x88\x9e dB"),
  2992. juce::Rectangle<float> (160.0f, 22.0f).withCentre ({ centre.x, d.getBottom() - 46.0f }), juce::Justification::centred, false);
  2993. caption (g, juce::Rectangle<float> (160.0f, 14.0f).withCentre ({ centre.x, d.getBottom() - 26.0f }), tr ("Output peak"));
  2994. // the knob panel (round tp172c): a pale frosted plate under the dark display, as on the reference
  2995. const auto a = panel();
  2996. frostFill (g, a);
  2997. g.setColour (juce::Colours::black.withAlpha (0.55f));
  2998. g.drawHorizontalLine ((int) a.getY(), 0.0f, a.getRight());
  2999. g.setColour (juce::Colours::white.withAlpha (0.8f));
  3000. g.drawHorizontalLine ((int) a.getY() + 1, 0.0f, a.getRight());
  3001. }
  3002. };
  3003. // round tp172c7: Kiln Channel, LYNX's console channel — the compact dark single-channel console of its role, drawn here
  3004. // from scratch: near-black side columns (a stereo meter pair on a 0 .. 66 dB scale with -inf read-outs, IN / OUT with a
  3005. // big knob and its dB read-out), the brushed centre module with corner screws, LYNX's kiln emblem over an amber VU with a
  3006. // dual scale (VU over %), the name plate, Input / Output on dotted rings with the GROUP I/O and LINK I/O lamps between,
  3007. // the chicken-head console switch with its six models round it, Drive and Group with their numbers printed round them,
  3008. // and the Noise reduction / Group bypass keys with their labels below; the name and an info mark under the module.
  3009. class KilnEditor final : public ProEditor
  3010. {
  3011. public:
  3012. KilnEditor (AudioEngine& e, int t, int s, bool d) : ProEditor (e, t, s, EffectKind::kilnChannel, d, 460, 680) {}
  3013. private:
  3014. static constexpr int idParam = 100, idModel = 200, idInfo = 300;
  3015. static constexpr float y0 = headerH; // the body's top
  3016. juce::String title() const override { return "Kiln Channel"; }
  3017. juce::String gestures() const override { return {}; }
  3018. // geometry (design units = pixels at 100 %)
  3019. static juce::Point<float> at (float x, float y) { return { x, y0 + y }; }
  3020. static juce::Point<float> knobCentre (int p)
  3021. {
  3022. namespace k = mixsuite::kiln;
  3023. switch (p)
  3024. {
  3025. case k::input: return at (172.0f, 208.0f);
  3026. case k::output: return at (288.0f, 208.0f);
  3027. case k::console: return at (230.0f, 316.0f);
  3028. case k::drive: return at (178.0f, 432.0f);
  3029. case k::group: return at (282.0f, 432.0f);
  3030. case k::mainIn: return at (51.0f, 536.0f);
  3031. case k::mainOut: return at (409.0f, 536.0f);
  3032. default: return {};
  3033. }
  3034. }
  3035. static float knobRadius (int p)
  3036. {
  3037. namespace k = mixsuite::kiln;
  3038. return p == k::console ? 30.0f : (p == k::mainIn || p == k::mainOut) ? 25.0f : 18.0f;
  3039. }
  3040. static int stepsOf (int p) { namespace k = mixsuite::kiln; return p == k::console ? 5 : p == k::group ? 8 : 0; }
  3041. static juce::Rectangle<float> lampRect (int p) { return juce::Rectangle<float> (20.0f, 13.0f).withCentre (at (230.0f, p == mixsuite::kiln::ioGroup ? 198.0f : 222.0f)); }
  3042. static juce::Rectangle<float> keyRect (int p) { return juce::Rectangle<float> (50.0f, 22.0f).withCentre (at (p == mixsuite::kiln::noiseReduction ? 178.0f : 282.0f, 516.0f)); }
  3043. static float stopAngle (int step, int steps) { return juce::MathConstants<float>::pi * (-0.75f + 1.5f * (float) step / (float) steps); }
  3044. static juce::Point<float> polar (juce::Point<float> c, float a, float r) { return c + juce::Point<float> { std::sin (a), -std::cos (a) } * r; }
  3045. juce::Rectangle<float> modelLabel (int step) const
  3046. {
  3047. const auto c = knobCentre (mixsuite::kiln::console);
  3048. const auto a = stopAngle (step, 5);
  3049. const auto p = polar (c, a, 50.0f);
  3050. const auto w = 74.0f;
  3051. const auto x = std::sin (a) < -0.2f ? p.x - w : std::sin (a) > 0.2f ? p.x : p.x - w * 0.5f;
  3052. return { x, p.y - 7.0f, w, 14.0f };
  3053. }
  3054. void layoutControls (std::vector<Ctl>& out) const override
  3055. {
  3056. namespace k = mixsuite::kiln;
  3057. for (const auto p : { k::input, k::output, k::console, k::drive, k::group, k::mainIn, k::mainOut })
  3058. {
  3059. const auto r = knobRadius (p) + 8.0f;
  3060. out.push_back (custom (juce::Rectangle<float> (r * 2.0f, r * 2.0f).withCentre (knobCentre (p)), idParam + p, -1,
  3061. p == k::mainOut ? hintFor (p) + ". " + tr ("Power: switch the effect on or off") : hintFor (p)));
  3062. }
  3063. for (int s = 0; s < 6; ++s)
  3064. out.push_back (custom (modelLabel (s), idModel + s, -1, tr ("Console") + ": " + utf8 (mixsuite::kiln::consoleName (s))));
  3065. for (const auto p : { k::ioGroup, k::ioLink })
  3066. out.push_back (custom (lampRect (p).expanded (8.0f, 4.0f), idParam + p, -1, hintFor (p)));
  3067. for (const auto p : { k::noiseReduction, k::groupBypass })
  3068. out.push_back (custom (keyRect (p).withHeight (40.0f), idParam + p, -1, hintFor (p)));
  3069. out.push_back (custom (juce::Rectangle<float> (16.0f, 16.0f).withCentre (at (266.0f, 601.0f)), idInfo, -1,
  3070. tr ("Kiln Channel: LYNX's console channel. Drag a knob, Alt+click resets it, right-click for automation")));
  3071. }
  3072. juce::String hintFor (int p) const
  3073. {
  3074. const auto& info = effectInfo (kind);
  3075. const auto name = tr (info.params[(std::size_t) p].name);
  3076. const auto what = pluginheader::describe (kind, info.params[(std::size_t) p].name);
  3077. return what.isNotEmpty() ? name + juce::String::fromUTF8 (" \xe2\x80\x94 ") + what : name;
  3078. }
  3079. // --- edits: Link I/O moves Output against Input; Group I/O carries the trims to the group's other channels with
  3080. // Group I/O on, and Group bypass to every channel of the group (the original's keys move together)
  3081. void edit (int p, float x)
  3082. {
  3083. namespace k = mixsuite::kiln;
  3084. const auto* fx = current();
  3085. if (fx == nullptr) return;
  3086. x = juce::jlimit (0.0f, 1.0f, x);
  3087. if (const auto steps = stepsOf (p); steps > 0)
  3088. x = (float) std::lround (x * (float) steps) / (float) steps;
  3089. bar.willEdit();
  3090. const auto changes = k::linkedEdit (fx->params, p, x);
  3091. const auto grp = k::groupOf (fx->params[(std::size_t) k::group]);
  3092. std::vector<std::pair<int, float>> deltas;
  3093. if (grp > 0 && fx->params[(std::size_t) k::ioGroup] >= 0.5f)
  3094. for (const auto& [q, val] : changes)
  3095. if (q == k::input || q == k::output)
  3096. deltas.push_back ({ q, val - fx->params[(std::size_t) q] });
  3097. const bool bypassAll = grp > 0 && p == k::groupBypass;
  3098. engine.editSong ([tk = track, sl = slot, changes, deltas, bypassAll, grp, x] (Song& song) {
  3099. if (tk < 0 || tk >= (int) song.mixer.size() || sl < 0 || sl >= (int) song.mixer[(std::size_t) tk].effects.size()) return;
  3100. auto& self = song.mixer[(std::size_t) tk].effects[(std::size_t) sl];
  3101. for (const auto& [q, val] : changes)
  3102. self.params[(std::size_t) q] = juce::jlimit (0.0f, 1.0f, val);
  3103. if (deltas.empty() && ! bypassAll) return;
  3104. for (auto& strip : song.mixer)
  3105. for (auto& other : strip.effects)
  3106. {
  3107. if (&other == &self || other.kind != EffectKind::kilnChannel || k::groupOf (other.params[(std::size_t) k::group]) != grp)
  3108. continue;
  3109. if (bypassAll)
  3110. other.params[(std::size_t) k::groupBypass] = x;
  3111. if (other.params[(std::size_t) k::ioGroup] >= 0.5f)
  3112. for (const auto& [q, d] : deltas)
  3113. other.params[(std::size_t) q] = juce::jlimit (0.0f, 1.0f, other.params[(std::size_t) q] + d);
  3114. }
  3115. });
  3116. }
  3117. int dragParam = -1;
  3118. bool dragging (int p) const { return dragParam == p && isMouseButtonDown(); }
  3119. void customDown (const Ctl& c, const juce::MouseEvent& e) override
  3120. {
  3121. namespace k = mixsuite::kiln;
  3122. dragParam = -1;
  3123. if (c.id >= idModel && c.id < idModel + 6)
  3124. {
  3125. edit (k::console, k::consoleValue (c.id - idModel));
  3126. return;
  3127. }
  3128. if (c.id < idParam || c.id >= idModel) return;
  3129. const auto p = c.id - idParam;
  3130. if (e.mods.isPopupMenu())
  3131. {
  3132. ui::showValueMenu (*this, &engine, specFor (p, stepsOf (p)), v (p), [this, p] (double x) { edit (p, (float) x); });
  3133. return;
  3134. }
  3135. if (p == k::ioGroup || p == k::ioLink || p == k::noiseReduction || p == k::groupBypass)
  3136. {
  3137. edit (p, v (p) >= 0.5f ? 0.0f : 1.0f);
  3138. return;
  3139. }
  3140. if (p == k::mainOut && e.position.getDistanceFrom (knobCentre (p)) < knobRadius (p) * 0.55f)
  3141. {
  3142. toggleEnabled(); // the power symbol on the OUT knob: the plugin on / bypassed
  3143. return;
  3144. }
  3145. if (ui::isResetClick (e))
  3146. {
  3147. edit (p, (float) specFor (p).defaultValue);
  3148. return;
  3149. }
  3150. dragParam = p;
  3151. valueDrag.begin (e, v (p));
  3152. }
  3153. void customDrag (const Ctl& c, const juce::MouseEvent& e) override
  3154. {
  3155. if (dragParam < 0) return;
  3156. const auto spec = specFor (dragParam, stepsOf (dragParam));
  3157. const auto x = (float) valueDrag.update (e, spec);
  3158. edit (dragParam, x);
  3159. ui::showValueTip (*this, c.r.toNearestInt(), spec.text (v (dragParam)));
  3160. }
  3161. bool bodyWheel (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  3162. {
  3163. Ctl c;
  3164. if (! controlAt (e.position, c) || c.id < idParam || c.id >= idModel) return false;
  3165. const auto p = c.id - idParam;
  3166. if (knobRadius (p) <= 0.0f || knobCentre (p).y <= 0.0f) return false;
  3167. const auto spec = specFor (p, stepsOf (p));
  3168. if (const auto x = ui::wheelValue (v (p), e, wheel, spec))
  3169. {
  3170. edit (p, (float) *x);
  3171. ui::flashValueTip (*this, c.r.toNearestInt(), spec.text (v (p)));
  3172. }
  3173. return true;
  3174. }
  3175. // --- metering: VU ballistics on the output, peak bars with holds on both sides
  3176. float vuDb = -40.0f;
  3177. std::array<float, 4> barDb { -120.0f, -120.0f, -120.0f, -120.0f }, holdDb { -120.0f, -120.0f, -120.0f, -120.0f };
  3178. bool moving = false;
  3179. void tick() override
  3180. {
  3181. const auto* fx = current();
  3182. const auto on = fx != nullptr && fx->enabled;
  3183. auto toDb = [] (float lin) { return lin > 1e-6f ? 20.0f * std::log10 (lin) : -120.0f; };
  3184. moving = false;
  3185. const auto vuTarget = on ? toDb (liveMeter (3)) + 18.0f - 3.0f : -40.0f; // 0 VU = -18 dBFS (sine RMS ~ peak - 3 dB)
  3186. const auto vuNew = vuDb + (juce::jmax (-40.0f, vuTarget) - vuDb) * 0.3f;
  3187. moving = moving || std::abs (vuNew - vuDb) > 0.05f;
  3188. vuDb = vuNew;
  3189. for (int i = 0; i < 4; ++i)
  3190. {
  3191. const auto now = on ? toDb (liveMeter (4 + i)) : -120.0f;
  3192. const auto next = now > barDb[(std::size_t) i] ? now : juce::jmax (-120.0f, barDb[(std::size_t) i] - 1.5f); // ~45 dB/s fall
  3193. moving = moving || std::abs (next - barDb[(std::size_t) i]) > 0.01f;
  3194. barDb[(std::size_t) i] = next;
  3195. holdDb[(std::size_t) i] = juce::jmax (holdDb[(std::size_t) i], now);
  3196. }
  3197. if (moving) repaint();
  3198. }
  3199. bool bodyDown (const juce::MouseEvent& e) override
  3200. {
  3201. // a click on a side column's read-outs resets the peak holds
  3202. if (e.position.y < y0 + 64.0f && (e.position.x < 100.0f || e.position.x > 360.0f))
  3203. {
  3204. holdDb.fill (-120.0f);
  3205. repaint();
  3206. return true;
  3207. }
  3208. return false;
  3209. }
  3210. // --- drawing --------------------------------------------------------------------------------------------
  3211. static void text (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& t, float size, bool bold, juce::Colour c,
  3212. juce::Justification j = juce::Justification::centred, float kern = 0.0f)
  3213. {
  3214. g.setColour (c);
  3215. g.setFont (juce::Font (theme::font (size, bold)).withExtraKerningFactor (kern));
  3216. g.drawText (t, r, j, false);
  3217. }
  3218. static inline const juce::Colour kWhite { 0xffeeeeea }, kGrey { 0xffa9abae }, kAmber { 0xfff3a93a };
  3219. static void screw (juce::Graphics& g, juce::Point<float> c, float r)
  3220. {
  3221. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff5b5d61), c.x - r, c.y - r, juce::Colour (0xff1a1b1d), c.x + r, c.y + r, false));
  3222. g.fillEllipse (juce::Rectangle<float> (r * 2.0f, r * 2.0f).withCentre (c));
  3223. g.setColour (juce::Colours::black.withAlpha (0.7f));
  3224. g.drawEllipse (juce::Rectangle<float> (r * 2.0f, r * 2.0f).withCentre (c), 1.0f);
  3225. g.setColour (juce::Colour (0xff0c0c0d));
  3226. for (const auto a : { 0.6f, 0.6f + juce::MathConstants<float>::halfPi }) // a cross head
  3227. g.drawLine ({ polar (c, a, r * 0.7f), polar (c, a + juce::MathConstants<float>::pi, r * 0.7f) }, 1.4f);
  3228. }
  3229. static void emblem (juce::Graphics& g, juce::Point<float> c, float r)
  3230. {
  3231. // LYNX's kiln mark: an arched kiln mouth with a flame inside, on a dark badge with a light rim
  3232. const auto badge = juce::Rectangle<float> (r * 1.9f, r * 2.3f).withCentre (c);
  3233. g.setColour (juce::Colour (0xff0b0b0c));
  3234. g.fillRoundedRectangle (badge, r * 0.3f);
  3235. g.setColour (juce::Colour (0xffc9cbcf));
  3236. g.drawRoundedRectangle (badge.reduced (1.0f), r * 0.3f, 1.6f);
  3237. const auto m = badge.reduced (r * 0.4f, r * 0.42f);
  3238. juce::Path mouth;
  3239. mouth.startNewSubPath (m.getX(), m.getBottom());
  3240. mouth.lineTo (m.getX(), m.getY() + m.getHeight() * 0.42f);
  3241. mouth.quadraticTo (m.getCentreX(), m.getY() - m.getHeight() * 0.2f, m.getRight(), m.getY() + m.getHeight() * 0.42f);
  3242. mouth.lineTo (m.getRight(), m.getBottom());
  3243. g.strokePath (mouth, juce::PathStrokeType (1.6f));
  3244. juce::Path flame;
  3245. const auto fx = m.getCentreX(), fb = m.getBottom() - 1.5f, fh = m.getHeight() * 0.62f, fw = m.getWidth() * 0.26f;
  3246. flame.startNewSubPath (fx, fb - fh);
  3247. flame.cubicTo (fx + fw * 1.4f, fb - fh * 0.45f, fx + fw, fb, fx, fb);
  3248. flame.cubicTo (fx - fw, fb, fx - fw * 1.4f, fb - fh * 0.45f, fx, fb - fh);
  3249. g.setGradientFill (juce::ColourGradient (juce::Colour (0xffffd27a), fx, fb, juce::Colour (0xffd2461e), fx, fb - fh, false));
  3250. g.fillPath (flame);
  3251. }
  3252. // a black console knob: a ridged skirt, a dark cap and a white pointer line
  3253. void consoleKnob (juce::Graphics& g, juce::Point<float> c, float r, float value, bool hot) const
  3254. {
  3255. const auto skirt = juce::Rectangle<float> (r * 2.0f, r * 2.0f).withCentre (c);
  3256. for (int i = 3; i >= 1; --i)
  3257. {
  3258. g.setColour (juce::Colours::black.withAlpha (0.18f));
  3259. g.fillEllipse (skirt.translated (0.0f, (float) i * 1.2f).expanded ((float) i));
  3260. }
  3261. g.setGradientFill (juce::ColourGradient (juce::Colour (hot ? 0xff3e4044 : 0xff323337), c.x, c.y - r, juce::Colour (0xff0b0b0c), c.x, c.y + r, false));
  3262. g.fillEllipse (skirt);
  3263. g.setColour (juce::Colour (0xff060607));
  3264. for (int i = 0; i < 24; ++i) // the knurl
  3265. {
  3266. const auto a = juce::MathConstants<float>::twoPi * (float) i / 24.0f;
  3267. g.drawLine ({ polar (c, a, r * 0.84f), polar (c, a, r) }, 1.0f);
  3268. }
  3269. const auto cap = skirt.reduced (r * 0.2f);
  3270. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff2c2d31), c.x - r * 0.4f, c.y - r * 0.6f, juce::Colour (0xff111113), c.x + r * 0.4f, c.y + r * 0.6f, false));
  3271. g.fillEllipse (cap);
  3272. g.setColour (juce::Colours::white.withAlpha (0.08f));
  3273. g.drawEllipse (cap, 1.0f);
  3274. const auto a = juce::MathConstants<float>::pi * (-0.75f + 1.5f * value);
  3275. g.setColour (kWhite);
  3276. g.drawLine ({ polar (c, a, r * 0.25f), polar (c, a, r * 0.78f) }, juce::jmax (2.0f, r * 0.11f));
  3277. }
  3278. // the chicken-head selector: a round boss with a long tapered pointer
  3279. void chickenHead (juce::Graphics& g, juce::Point<float> c, float r, int step, bool hot) const
  3280. {
  3281. const auto a = stopAngle (step, 5);
  3282. for (int i = 3; i >= 1; --i)
  3283. {
  3284. g.setColour (juce::Colours::black.withAlpha (0.2f));
  3285. g.fillEllipse (juce::Rectangle<float> (r * 1.5f, r * 1.5f).withCentre (c).translated (0.0f, (float) i * 1.5f).expanded ((float) i));
  3286. }
  3287. juce::Path head;
  3288. // the round boss and a long tapered beak toward the stop (one path; the fill joins them)
  3289. head.addEllipse (-r * 0.74f, -r * 0.74f, r * 1.48f, r * 1.48f);
  3290. head.startNewSubPath (-r * 0.5f, -r * 0.2f);
  3291. head.quadraticTo (-r * 0.22f, -r * 0.9f, 0.0f, -r * 1.6f);
  3292. head.quadraticTo (r * 0.22f, -r * 0.9f, r * 0.5f, -r * 0.2f);
  3293. head.closeSubPath();
  3294. const auto t = juce::AffineTransform::rotation (a).translated (c.x, c.y);
  3295. g.setGradientFill (juce::ColourGradient (juce::Colour (hot ? 0xff3c3e42 : 0xff2e2f33), c.x, c.y - r, juce::Colour (0xff09090a), c.x, c.y + r, false));
  3296. g.fillPath (head, t);
  3297. g.setColour (juce::Colours::black);
  3298. g.strokePath (head, juce::PathStrokeType (1.2f), t);
  3299. g.setColour (juce::Colours::white.withAlpha (0.10f));
  3300. g.drawEllipse (juce::Rectangle<float> (r * 1.1f, r * 1.1f).withCentre (c), 1.0f);
  3301. g.setColour (kWhite); // the pointer line along the beak
  3302. g.drawLine ({ polar (c, a, r * 0.45f), polar (c, a, r * 1.45f) }, 2.2f);
  3303. }
  3304. void dottedRing (juce::Graphics& g, juce::Point<float> c, float r, int dots, int lit) const
  3305. {
  3306. for (int i = 0; i < dots; ++i)
  3307. {
  3308. const auto a = stopAngle (i, dots - 1);
  3309. g.setColour (i == lit ? kWhite : kGrey.withAlpha (0.85f));
  3310. g.fillEllipse (juce::Rectangle<float> (2.6f, 2.6f).withCentre (polar (c, a, r)));
  3311. }
  3312. }
  3313. void hoverValue (juce::Graphics& g, int p, juce::Point<float> c, float r) const
  3314. {
  3315. if (! juce::Rectangle<float> ((r + 8.0f) * 2.0f, (r + 8.0f) * 2.0f).withCentre (c).contains (mouse) || dragging (p)) return;
  3316. const auto t = ProEditor::text (p);
  3317. const auto box = juce::Rectangle<float> (64.0f, 16.0f).withCentre (c.translated (0.0f, r + 18.0f));
  3318. g.setColour (juce::Colour (0xe0101012));
  3319. g.fillRoundedRectangle (box, 3.0f);
  3320. text (g, box, t, 10.0f, false, kWhite);
  3321. }
  3322. void meterColumn (juce::Graphics& g, juce::Rectangle<float> col, int first, const juce::String& name, int mainParam) const
  3323. {
  3324. g.setColour (juce::Colour (0xff0d0d0e));
  3325. g.fillRoundedRectangle (col, 6.0f);
  3326. g.setColour (juce::Colours::white.withAlpha (0.06f));
  3327. g.drawRoundedRectangle (col.reduced (0.5f), 6.0f, 1.0f);
  3328. // the well: two thin bars, the scale between them, the peak read-outs on top
  3329. const auto well = juce::Rectangle<float> (col.getX() + 10.0f, col.getY() + 8.0f, col.getWidth() - 20.0f, 384.0f);
  3330. g.setColour (juce::Colour (0xff050505));
  3331. g.fillRoundedRectangle (well, 4.0f);
  3332. g.setColour (juce::Colours::white.withAlpha (0.07f));
  3333. g.drawRoundedRectangle (well, 4.0f, 1.0f);
  3334. const auto top = well.getY() + 34.0f, pxPerDb = 5.0f;
  3335. const float barX[2] { well.getCentreX() - 25.0f, well.getCentreX() + 19.0f }; // left bar | numbers | right bar
  3336. for (int ch = 0; ch < 2; ++ch)
  3337. {
  3338. const auto h = holdDb[(std::size_t) (first + ch)];
  3339. text (g, { barX[ch] - 14.0f, well.getY() + 8.0f, 34.0f, 12.0f }, h > -119.0f ? juce::String (h, 1) : juce::String ("-inf"), 9.0f, true,
  3340. h > -0.1f ? juce::Colour (0xffe5383b) : kGrey);
  3341. const auto slot = juce::Rectangle<float> (barX[ch], top - 4.0f, 6.0f, 66.0f * pxPerDb + 8.0f);
  3342. g.setColour (juce::Colour (0xff1b1c1f));
  3343. g.fillRect (slot);
  3344. g.setColour (juce::Colours::white.withAlpha (0.06f));
  3345. g.drawRect (slot, 1.0f);
  3346. const auto db = barDb[(std::size_t) (first + ch)];
  3347. if (db > -66.0f)
  3348. {
  3349. const auto y = top + juce::jlimit (0.0f, 66.0f, -db) * pxPerDb;
  3350. const auto lit = juce::Rectangle<float> (slot.getX() + 1.0f, y, slot.getWidth() - 2.0f, slot.getBottom() - 4.0f - y);
  3351. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff2fbf8f), 0.0f, top + 66.0f * pxPerDb, juce::Colour (0xff7be0b9), 0.0f, top, false));
  3352. g.fillRect (lit);
  3353. if (db > -6.0f)
  3354. {
  3355. g.setColour (juce::Colour (0xffe8b23a));
  3356. g.fillRect (lit.withHeight (juce::jmin (lit.getHeight(), (6.0f + db) * pxPerDb)));
  3357. }
  3358. }
  3359. }
  3360. for (const auto mark : { 0, 6, 12, 18, 24, 36, 48, 66 })
  3361. {
  3362. const auto y = top + (float) mark * pxPerDb;
  3363. text (g, { well.getCentreX() - 14.0f, y - 6.0f, 28.0f, 12.0f }, juce::String (mark), 9.5f, true, kWhite.withAlpha (0.85f));
  3364. g.setColour (kGrey.withAlpha (0.5f));
  3365. for (const auto x : { barX[0] + 8.0f, barX[1] - 5.0f })
  3366. g.drawHorizontalLine ((int) y, x, x + 3.0f);
  3367. }
  3368. // IN / OUT, the big knob, its read-out
  3369. text (g, { col.getX(), y0 + 452.0f, col.getWidth(), 22.0f }, name, 15.0f, true, kWhite, juce::Justification::centred, 0.08f);
  3370. const auto c = knobCentre (mainParam);
  3371. consoleKnob (g, c, knobRadius (mainParam), v (mainParam), juce::Rectangle<float> (60.0f, 60.0f).withCentre (c).contains (mouse));
  3372. if (mainParam == mixsuite::kiln::mainOut) // the power symbol: lit while the plugin runs, dim while bypassed
  3373. {
  3374. const auto* fx = current();
  3375. const auto on = fx != nullptr && fx->enabled;
  3376. const auto rr = knobRadius (mainParam) * 0.3f;
  3377. juce::Path glyph;
  3378. glyph.addCentredArc (c.x, c.y, rr, rr, 0.0f, 0.7f, juce::MathConstants<float>::twoPi - 0.7f, true);
  3379. glyph.startNewSubPath (c.x, c.y - rr * 1.25f);
  3380. glyph.lineTo (c.x, c.y - rr * 0.25f);
  3381. g.setColour (juce::Colour (0xff141416));
  3382. g.fillEllipse (juce::Rectangle<float> (rr * 3.4f, rr * 3.4f).withCentre (c));
  3383. g.setColour (on ? kWhite : kGrey.withAlpha (0.5f));
  3384. g.strokePath (glyph, juce::PathStrokeType (2.0f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  3385. }
  3386. text (g, { col.getX(), c.y + 38.0f, col.getWidth(), 16.0f }, juce::String (mixsuite::kiln::mainDb (v (mainParam)), 2) + "dB", 11.0f, true, kWhite);
  3387. }
  3388. void vu (juce::Graphics& g, juce::Rectangle<float> r, bool on) const
  3389. {
  3390. // the bezel, the lamp-lit amber face, VU over %, the needle from a pivot under the face
  3391. g.setColour (juce::Colour (0xff050505));
  3392. g.fillRoundedRectangle (r.expanded (5.0f), 7.0f);
  3393. g.setColour (juce::Colours::white.withAlpha (0.14f));
  3394. g.drawRoundedRectangle (r.expanded (5.0f).reduced (0.5f), 7.0f, 1.0f);
  3395. g.setGradientFill (juce::ColourGradient (juce::Colour (on ? 0xfffbd88a : 0xffb59a63), r.getCentreX(), r.getCentreY() + r.getHeight() * 0.1f,
  3396. juce::Colour (on ? 0xffc88c2e : 0xff6e5532), r.getX(), r.getY(), true));
  3397. g.fillRoundedRectangle (r, 4.0f);
  3398. const juce::Point<float> pivot { r.getCentreX(), r.getBottom() + r.getHeight() * 0.32f };
  3399. const auto R = r.getHeight() * 1.02f;
  3400. const auto fracOf = [] (float db) {
  3401. const auto lo = std::pow (10.0f, -1.0f), hi = std::pow (10.0f, 3.0f / 20.0f);
  3402. return juce::jlimit (0.0f, 1.0f, (std::pow (10.0f, db / 20.0f) - lo) / (hi - lo));
  3403. };
  3404. const auto angleOf = [] (float frac) { return juce::MathConstants<float>::pi * (-0.26f + 0.52f * frac); };
  3405. const juce::Colour ink (0xff2a2016), red (0xffc0281e);
  3406. juce::Path arc;
  3407. arc.addCentredArc (pivot.x, pivot.y, R * 0.8f, R * 0.8f, 0.0f, angleOf (0.0f), angleOf (1.0f), true);
  3408. g.setColour (ink);
  3409. g.strokePath (arc, juce::PathStrokeType (1.0f));
  3410. juce::Path redArc;
  3411. redArc.addCentredArc (pivot.x, pivot.y, R * 0.82f, R * 0.82f, 0.0f, angleOf (fracOf (0.0f)), angleOf (1.0f), true);
  3412. g.setColour (red);
  3413. g.strokePath (redArc, juce::PathStrokeType (3.0f));
  3414. for (const auto db : { -20.0f, -10.0f, -7.0f, -5.0f, -3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f })
  3415. {
  3416. const auto a = angleOf (fracOf (db));
  3417. g.setColour (db > 0.0f ? red : ink);
  3418. g.drawLine ({ polar (pivot, a, R * 0.8f), polar (pivot, a, R * 0.88f) }, 1.2f);
  3419. text (g, juce::Rectangle<float> (18.0f, 10.0f).withCentre (polar (pivot, a, R * 0.95f)), db > 0.0f ? juce::String ((int) db) : juce::String ((int) -db),
  3420. 7.5f, true, db > 0.0f ? red : ink);
  3421. }
  3422. for (int pc = 0; pc <= 100; pc += 20) // the % scale under the arc
  3423. {
  3424. const auto a = angleOf ((float) pc / 100.0f * fracOf (0.0f));
  3425. g.setColour (ink);
  3426. g.drawLine ({ polar (pivot, a, R * 0.72f), polar (pivot, a, R * 0.78f) }, 1.0f);
  3427. text (g, juce::Rectangle<float> (18.0f, 9.0f).withCentre (polar (pivot, a, R * 0.66f)), juce::String (pc), 6.5f, false, ink);
  3428. }
  3429. text (g, juce::Rectangle<float> (40.0f, 12.0f).withCentre ({ r.getX() + 16.0f, r.getBottom() - 14.0f }), "VU", 9.0f, true, ink);
  3430. text (g, juce::Rectangle<float> (40.0f, 10.0f).withCentre ({ r.getRight() - 18.0f, r.getBottom() - 14.0f }), "%", 8.0f, true, ink);
  3431. const auto a = angleOf (fracOf (juce::jlimit (-22.0f, 4.0f, vuDb)));
  3432. g.saveState();
  3433. g.reduceClipRegion (r.toNearestInt());
  3434. g.setColour (juce::Colour (0xff17120d));
  3435. g.drawLine ({ polar (pivot, a, R * 0.32f), polar (pivot, a, R * 0.98f) }, 1.4f);
  3436. g.restoreState();
  3437. g.setColour (juce::Colours::black.withAlpha (0.45f)); // the face's inner shadow
  3438. g.drawRoundedRectangle (r, 4.0f, 2.0f);
  3439. }
  3440. void key (juce::Graphics& g, int p, const juce::String& label) const
  3441. {
  3442. const auto r = keyRect (p);
  3443. const auto on = v (p) >= 0.5f;
  3444. g.setColour (juce::Colour (0xff050505));
  3445. g.fillRoundedRectangle (r.expanded (3.0f), 3.0f);
  3446. g.setGradientFill (on ? juce::ColourGradient (juce::Colour (0xffffd78a), r.getCentreX(), r.getCentreY(), juce::Colour (0xffd8801e), r.getX(), r.getY(), true)
  3447. : juce::ColourGradient (juce::Colour (0xff8d8f93), 0.0f, r.getY(), juce::Colour (0xff4b4d51), 0.0f, r.getBottom(), false));
  3448. g.fillRoundedRectangle (r, 2.0f);
  3449. g.setColour (on ? juce::Colour (0xfffff1cf).withAlpha (0.8f) : juce::Colours::white.withAlpha (0.35f));
  3450. g.drawRoundedRectangle (r.reduced (2.5f), 1.5f, 1.0f);
  3451. g.setColour (juce::Colours::black.withAlpha (0.6f));
  3452. g.drawRoundedRectangle (r, 2.0f, 1.0f);
  3453. text (g, { r.getCentreX() - 60.0f, r.getBottom() + 7.0f, 120.0f, 12.0f }, label, 9.0f, true, kWhite, juce::Justification::centred, 0.04f);
  3454. }
  3455. void lamp (juce::Graphics& g, int p) const
  3456. {
  3457. const auto r = lampRect (p);
  3458. const auto on = v (p) >= 0.5f;
  3459. g.setColour (juce::Colour (0xff050505));
  3460. g.fillRoundedRectangle (r.expanded (2.0f), 2.0f);
  3461. if (on)
  3462. {
  3463. g.setColour (kAmber.withAlpha (0.25f));
  3464. g.fillRoundedRectangle (r.expanded (5.0f), 5.0f);
  3465. }
  3466. g.setGradientFill (on ? juce::ColourGradient (juce::Colour (0xffffe3a0), r.getCentreX(), r.getCentreY(), juce::Colour (0xffe08a1c), r.getX(), r.getY(), true)
  3467. : juce::ColourGradient (juce::Colour (0xff4a3a24), r.getCentreX(), r.getCentreY(), juce::Colour (0xff221a10), r.getX(), r.getY(), true));
  3468. g.fillRoundedRectangle (r, 1.5f);
  3469. }
  3470. // the shared bottom bar carries nothing here: the panel's black runs down to the description line
  3471. void paintOverlay (juce::Graphics& g, const EffectSlot&) override
  3472. {
  3473. g.setColour (juce::Colour (0xff060606));
  3474. g.fillRect (barArea());
  3475. }
  3476. void paintBody (juce::Graphics& g, const EffectSlot& fx) override
  3477. {
  3478. namespace k = mixsuite::kiln;
  3479. const auto body = bodyArea();
  3480. g.setColour (juce::Colour (0xff060606));
  3481. g.fillRect (body);
  3482. meterColumn (g, { 6.0f, y0 + 6.0f, 90.0f, 610.0f }, 0, caps (tr ("In")), k::mainIn);
  3483. meterColumn (g, { 364.0f, y0 + 6.0f, 90.0f, 610.0f }, 2, caps (tr ("Out")), k::mainOut);
  3484. // the centre column: its frame, the module, the name under it
  3485. const auto column = juce::Rectangle<float> (102.0f, y0 + 6.0f, 256.0f, 610.0f);
  3486. g.setColour (juce::Colour (0xff0d0d0e));
  3487. g.fillRoundedRectangle (column, 6.0f);
  3488. const auto mod = juce::Rectangle<float> (108.0f, y0 + 10.0f, 244.0f, 578.0f);
  3489. g.setGradientFill (juce::ColourGradient (juce::Colour (0xff2a2b2e), mod.getX(), mod.getY(), juce::Colour (0xff161719), mod.getRight(), mod.getBottom(), false));
  3490. g.fillRect (mod);
  3491. juce::Random rnd (172);
  3492. for (int i = 0; i < 1800; ++i) // the brushing: a fine, low-contrast grain (short strokes, barely lighter or darker)
  3493. {
  3494. const auto x = mod.getX() + rnd.nextFloat() * mod.getWidth();
  3495. const auto y = mod.getY() + rnd.nextFloat() * mod.getHeight();
  3496. const auto len = 3.0f + rnd.nextFloat() * 22.0f;
  3497. g.setColour ((rnd.nextBool() ? juce::Colours::white : juce::Colours::black).withAlpha (0.008f + 0.016f * rnd.nextFloat()));
  3498. g.drawVerticalLine ((int) x, y, juce::jmin (mod.getBottom(), y + len));
  3499. }
  3500. g.setGradientFill (juce::ColourGradient (juce::Colours::white.withAlpha (0.035f), mod.getCentreX(), mod.getY() + 60.0f, juce::Colours::transparentWhite,
  3501. mod.getCentreX(), mod.getY() + 340.0f, true));
  3502. g.fillRect (mod);
  3503. g.setColour (juce::Colours::black.withAlpha (0.8f));
  3504. g.drawRect (mod, 1.5f);
  3505. g.setColour (juce::Colours::white.withAlpha (0.09f));
  3506. g.drawRect (mod.reduced (2.0f), 1.0f);
  3507. for (const auto& c : { mod.getTopLeft().translated (11.0f, 11.0f), mod.getTopRight().translated (-11.0f, 11.0f),
  3508. mod.getBottomLeft().translated (11.0f, -11.0f), mod.getBottomRight().translated (-11.0f, -11.0f) })
  3509. screw (g, c, 6.0f);
  3510. emblem (g, at (230.0f, 30.0f), 12.0f);
  3511. vu (g, { 160.0f, y0 + 54.0f, 140.0f, 78.0f }, fx.enabled);
  3512. text (g, { mod.getX(), y0 + 144.0f, mod.getWidth(), 24.0f }, "KILN CHANNEL", 17.0f, false, kWhite, juce::Justification::centred, 0.06f);
  3513. // Input / Output: dotted rings, 0 on top, -18 / +18 at the ends, the caption under
  3514. for (const auto [p, cap] : { std::pair<int, const char*> { k::input, TR_NOOP ("Input") }, std::pair<int, const char*> { k::output, TR_NOOP ("Output") } })
  3515. {
  3516. const auto c = knobCentre (p);
  3517. dottedRing (g, c, 26.0f, 11, -1);
  3518. text (g, juce::Rectangle<float> (20.0f, 10.0f).withCentre (polar (c, 0.0f, 34.0f)), "0", 8.5f, true, kWhite);
  3519. text (g, juce::Rectangle<float> (24.0f, 10.0f).withCentre (polar (c, stopAngle (0, 1), 30.0f).translated (-4.0f, 9.0f)), "-18", 8.5f, true, kWhite);
  3520. text (g, juce::Rectangle<float> (24.0f, 10.0f).withCentre (polar (c, stopAngle (1, 1), 30.0f).translated (4.0f, 9.0f)), "+18", 8.5f, true, kWhite);
  3521. consoleKnob (g, c, knobRadius (p), v (p), dragging (p));
  3522. text (g, { c.x - 40.0f, c.y + 30.0f, 80.0f, 12.0f }, caps (tr (cap)), 9.0f, true, kWhite, juce::Justification::centred, 0.04f);
  3523. }
  3524. // GROUP I/O over LINK I/O, between them
  3525. text (g, juce::Rectangle<float> (80.0f, 10.0f).withCentre (at (230.0f, 184.0f)), caps (tr ("Group I/O")), 8.0f, true, kWhite, juce::Justification::centred, 0.04f);
  3526. lamp (g, k::ioGroup);
  3527. lamp (g, k::ioLink);
  3528. text (g, juce::Rectangle<float> (80.0f, 10.0f).withCentre (at (230.0f, 237.0f)), caps (tr ("Link I/O")), 8.0f, true, kWhite, juce::Justification::centred, 0.04f);
  3529. // the console switch and its six models
  3530. const auto cc = knobCentre (k::console);
  3531. const auto step = k::consoleStep (v (k::console));
  3532. for (int s = 0; s < 6; ++s)
  3533. {
  3534. const auto a = stopAngle (s, 5);
  3535. g.setColour (s == step ? kWhite : kGrey);
  3536. g.drawLine ({ polar (cc, a, 36.0f), polar (cc, a, 44.0f) }, s == step ? 1.8f : 1.2f);
  3537. const auto lr = modelLabel (s);
  3538. const auto j = lr.getCentreX() < cc.x - 10.0f ? juce::Justification::centredRight : lr.getCentreX() > cc.x + 10.0f ? juce::Justification::centredLeft : juce::Justification::centred;
  3539. text (g, lr.reduced (2.0f, 0.0f), tr (k::consoleName (s)), 11.0f, false, kWhite, j);
  3540. }
  3541. chickenHead (g, cc, knobRadius (k::console), step, dragging (k::console) || juce::Rectangle<float> (76.0f, 76.0f).withCentre (cc).contains (mouse));
  3542. // Drive and Group with their numbers round them
  3543. {
  3544. const auto c = knobCentre (k::drive);
  3545. for (int i = 0; i <= 6; ++i)
  3546. text (g, juce::Rectangle<float> (18.0f, 10.0f).withCentre (polar (c, stopAngle (i, 6), 30.0f)), juce::String (i * 3), 8.0f, true, kWhite);
  3547. consoleKnob (g, c, knobRadius (k::drive), v (k::drive), dragging (k::drive));
  3548. text (g, { c.x - 40.0f, c.y + 32.0f, 80.0f, 12.0f }, caps (tr ("Drive")), 9.0f, true, kGrey, juce::Justification::centred, 0.04f);
  3549. }
  3550. {
  3551. const auto c = knobCentre (k::group);
  3552. for (int i = 0; i <= 8; ++i)
  3553. text (g, juce::Rectangle<float> (i == 0 ? 30.0f : 14.0f, 10.0f).withCentre (polar (c, stopAngle (i, 8), i == 0 ? 33.0f : 30.0f)),
  3554. i == 0 ? tr ("None") : juce::String (i), 8.0f, true, kWhite);
  3555. consoleKnob (g, c, knobRadius (k::group), (float) k::groupOf (v (k::group)) / 8.0f, dragging (k::group));
  3556. text (g, { c.x - 40.0f, c.y + 32.0f, 80.0f, 12.0f }, caps (tr ("Group")), 9.0f, true, kGrey, juce::Justification::centred, 0.04f);
  3557. }
  3558. key (g, k::noiseReduction, caps (tr ("Noise reduction")));
  3559. key (g, k::groupBypass, caps (tr ("Group bypass")));
  3560. // the name and the info mark under the module
  3561. text (g, { column.getX(), y0 + 590.0f, column.getWidth() - 24.0f, 22.0f }, "Kiln Channel", 12.0f, true, kWhite);
  3562. const auto info = juce::Rectangle<float> (13.0f, 13.0f).withCentre (at (266.0f, 601.0f));
  3563. g.setColour (kWhite);
  3564. g.drawEllipse (info, 1.2f);
  3565. text (g, info, "i", 9.0f, true, kWhite);
  3566. for (const auto p : { k::input, k::output, k::drive, k::group, k::mainIn, k::mainOut })
  3567. hoverValue (g, p, knobCentre (p), knobRadius (p));
  3568. }
  3569. };
  3570. // --- windows -------------------------------------------------------------------------------------------------
  3571. std::unique_ptr<ProEditor> make (AudioEngine& engine, int track, int slot, bool demo)
  3572. {
  3573. const auto& mixer = engine.getSong().mixer;
  3574. if (track < 0 || track >= (int) mixer.size() || slot < 0 || slot >= (int) mixer[(std::size_t) track].effects.size())
  3575. return nullptr;
  3576. switch (mixer[(std::size_t) track].effects[(std::size_t) slot].kind)
  3577. {
  3578. case EffectKind::apexLimiter: return std::make_unique<ApexEditor> (engine, track, slot, demo);
  3579. case EffectKind::hushDeEsser: return std::make_unique<HushEditor> (engine, track, slot, demo);
  3580. case EffectKind::crestCompressor: return std::make_unique<CrestEditor> (engine, track, slot, demo);
  3581. case EffectKind::sentryGate: return std::make_unique<SentryEditor> (engine, track, slot, demo);
  3582. case EffectKind::prismMultiband: return std::make_unique<PrismEditor> (engine, track, slot, demo);
  3583. case EffectKind::ember: return std::make_unique<EmberEditor> (engine, track, slot, demo);
  3584. case EffectKind::aether: return std::make_unique<AetherEditor> (engine, track, slot, demo);
  3585. case EffectKind::kilnChannel: return std::make_unique<KilnEditor> (engine, track, slot, demo);
  3586. default: return nullptr;
  3587. }
  3588. }
  3589. // The editor drawn at the window's size (round 128: the originals' windows can be resized): the layout is fixed, the
  3590. // whole editor is scaled (mouse positions follow the transform), the window keeps the editor's proportions.
  3591. class ScaledHolder final : public juce::Component
  3592. {
  3593. public:
  3594. explicit ScaledHolder (std::unique_ptr<ProEditor> e) : editor (std::move (e))
  3595. {
  3596. baseW = juce::jmax (1, editor->getWidth());
  3597. baseH = juce::jmax (1, editor->getHeight());
  3598. addAndMakeVisible (*editor);
  3599. setSize (baseW, baseH);
  3600. }
  3601. void resized() override
  3602. {
  3603. const auto s = juce::jmin ((float) getWidth() / (float) baseW, (float) getHeight() / (float) baseH);
  3604. editor->setBounds (0, 0, baseW, baseH);
  3605. editor->setTransform (juce::AffineTransform::scale (s));
  3606. }
  3607. std::unique_ptr<ProEditor> editor;
  3608. int baseW = 1, baseH = 1;
  3609. };
  3610. class ProEditorWindow final : public juce::DocumentWindow
  3611. {
  3612. public:
  3613. ProEditorWindow (std::unique_ptr<ProEditor> editor, const juce::String& title, AudioEngine& engine, int track, int slot)
  3614. : DocumentWindow (title, colour::bg1, DocumentWindow::closeButton | DocumentWindow::minimiseButton),
  3615. gone (engine, track, slot, [this] { closeButtonPressed(); })
  3616. {
  3617. setUsingNativeTitleBar (true);
  3618. content = editor.get();
  3619. auto holder = std::make_unique<ScaledHolder> (std::move (editor));
  3620. const auto w = holder->baseW, h = holder->baseH;
  3621. setContentOwned (holder.release(), true);
  3622. setResizable (true, false);
  3623. if (auto* c = getConstrainer())
  3624. {
  3625. c->setFixedAspectRatio ((double) w / (double) h);
  3626. c->setMinimumSize (juce::roundToInt (w * 0.7), juce::roundToInt (h * 0.7));
  3627. c->setMaximumSize (w * 2, h * 2);
  3628. }
  3629. centreWithSize (getWidth(), getHeight());
  3630. setVisible (true);
  3631. keepAboveMainWindow (*this);
  3632. if (content != nullptr) skin::playOpenAnimation (*content, content->editorStyle()); // round 126: fade / scale in
  3633. }
  3634. void closeButtonPressed() override;
  3635. ProEditor* content = nullptr;
  3636. private:
  3637. ui::SlotGoneWatcher gone;
  3638. };
  3639. std::map<std::pair<int, int>, std::unique_ptr<ProEditorWindow>>& windows()
  3640. {
  3641. static std::map<std::pair<int, int>, std::unique_ptr<ProEditorWindow>> open;
  3642. return open;
  3643. }
  3644. void ProEditorWindow::closeButtonPressed()
  3645. {
  3646. for (auto& [key, window] : windows())
  3647. if (window.get() == this)
  3648. {
  3649. juce::MessageManager::callAsync ([k = key] { windows().erase (k); });
  3650. return;
  3651. }
  3652. }
  3653. } // namespace
  3654. namespace ProEditorWindows
  3655. {
  3656. bool handles (EffectKind kind) noexcept
  3657. {
  3658. return kind == EffectKind::apexLimiter || kind == EffectKind::hushDeEsser || kind == EffectKind::crestCompressor
  3659. || kind == EffectKind::sentryGate || kind == EffectKind::prismMultiband || kind == EffectKind::ember
  3660. || kind == EffectKind::aether || kind == EffectKind::kilnChannel;
  3661. }
  3662. void open (AudioEngine& engine, int track, int slot)
  3663. {
  3664. auto& open = windows();
  3665. const auto key = std::make_pair (track, slot);
  3666. if (auto it = open.find (key); it != open.end())
  3667. {
  3668. if (it->second->content != nullptr && it->second->content->current() != nullptr)
  3669. {
  3670. it->second->toFront (true);
  3671. return;
  3672. }
  3673. open.erase (it); // the slot now holds another effect
  3674. }
  3675. auto editor = make (engine, track, slot, false);
  3676. if (editor == nullptr) return;
  3677. const auto& mixer = engine.getSong().mixer;
  3678. const auto name = track == 0 ? tr ("Master") : juce::String::fromUTF8 (mixer[(std::size_t) track].name.c_str());
  3679. const auto title = utf8 (effectInfo (mixer[(std::size_t) track].effects[(std::size_t) slot].kind).name) + " - "
  3680. + (name.isNotEmpty() ? name : tr ("Insert {0}", { juce::String (track) })) + " (" + tr ("slot {0}", { juce::String (slot + 1) }) + ")";
  3681. open[key] = std::make_unique<ProEditorWindow> (std::move (editor), title, engine, track, slot);
  3682. }
  3683. void close (int track, int slot) { windows().erase ({ track, slot }); }
  3684. void closeAll() { windows().clear(); }
  3685. } // namespace ProEditorWindows
  3686. std::unique_ptr<juce::Component> makeProEditor (AudioEngine& engine, int track, int slot, bool demo)
  3687. {
  3688. return make (engine, track, slot, demo);
  3689. }
  3690. } // namespace lynx