ChannelSettings.cpp 175 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464
  1. #include "ui/WindowOwner.h"
  2. #include "core/NoteNames.h"
  3. #include "ui/ChannelSettings.h"
  4. #include "ui/LayerEditor.h"
  5. #include "ui/DanceView.h"
  6. #include "ui/Controllers164.h"
  7. #include "ui/VoltageEditor.h"
  8. #include "core/MixerOps.h"
  9. #include <cstring>
  10. #include <functional>
  11. #include "core/DrumSynthLive.h"
  12. #include "core/FlSynths.h"
  13. #include "core/FlKeys.h"
  14. #include "core/ChannelMiscFx.h"
  15. #include "core/FlpImport.h"
  16. #include "core/Harmor.h"
  17. #include "core/Gms.h"
  18. #include "core/MiniSynth.h"
  19. #include "core/SimSynth.h"
  20. #include "core/Drumaxx.h"
  21. #include "core/Granulizer.h"
  22. #include "core/Morphine.h"
  23. #include "core/Ogun.h"
  24. #include "core/Dx10.h"
  25. #include "core/Kepler.h"
  26. #include "core/PoiZone.h"
  27. #include "core/BassDrum.h"
  28. #include "core/FruitKick.h"
  29. #include "core/Toxic.h"
  30. #include "core/ThreeOsc.h"
  31. #include "core/BeepMap.h"
  32. #include "core/Sawer.h"
  33. #include "core/Slayer.h"
  34. #include "core/SytrusEngine.h"
  35. #include "core/SynthPresets.h"
  36. #include "core/PluginLayout.h"
  37. #include "engine/Text.h"
  38. #include "core/RackOps.h"
  39. #include "ui/ControllerEditors.h"
  40. #include "ui/HintBar.h"
  41. #include "ui/ValueControl.h"
  42. #include "ui/I18n.h"
  43. #include "ui/PluginSkin.h"
  44. #include "ui/Theme.h"
  45. #include "ui/WaveformView.h"
  46. #include "ui/SoundFontEditor.h"
  47. #include "ui/VfxEditors.h"
  48. #include "ui/VideoPlayerView.h"
  49. namespace lynx
  50. {
  51. namespace
  52. {
  53. // Which channel a page edits (round 164f): a Channel Rack channel, or the generator of a Patcher node found through
  54. // `locate` (index −1) — the same pages edit both, so a node opens the editor its engine has on a channel.
  55. struct ChannelRef
  56. {
  57. std::function<ChannelDef* (Song&)> locate;
  58. int index = -1; // the Channel Rack index (automation targets, its windows); −1 = a Patcher node
  59. static ChannelRef rack (int c)
  60. {
  61. return { [c] (Song& s) -> ChannelDef* { return c >= 0 && c < (int) s.channels.size() ? &s.channels[(std::size_t) c] : nullptr; }, c };
  62. }
  63. const ChannelDef* get (const AudioEngine& engine) const { return locate ? locate (const_cast<Song&> (engine.getSong())) : nullptr; }
  64. void edit (AudioEngine& engine, std::function<void (ChannelDef&)> change) const
  65. {
  66. engine.editSong ([l = locate, change = std::move (change)] (Song& s) {
  67. if (auto* d = l ? l (s) : nullptr)
  68. change (*d);
  69. });
  70. }
  71. };
  72. void showModulationFor (juce::Component& from, AudioEngine& engine, int channel);
  73. // Cutoff and pitch envelopes (FL's channel envelopes), used by the synth and the sampler.
  74. class ModEnvelopeEditor final : public juce::Component
  75. {
  76. public:
  77. std::function<void()> onChange;
  78. static constexpr int preferredHeight = 16 + 2 * 62;
  79. ModEnvelopeEditor()
  80. {
  81. const juce::String titles[] = { tr ("Cutoff env."), tr ("Pitch env.") };
  82. for (int e = 0; e < 2; ++e)
  83. {
  84. auto& row = rows[(std::size_t) e];
  85. row.title.setText (titles[e], juce::dontSendNotification);
  86. row.title.setFont (theme::font (theme::type::small));
  87. addAndMakeVisible (row.title);
  88. knob (row.amount, e == 0 ? -10.0 : -48.0, e == 0 ? 10.0 : 48.0, 0.01, e == 0 ? " oct" : " st");
  89. row.amount.setDoubleClickReturnValue (true, 0.0);
  90. row.amount.setTooltip (tr ("0 = off"));
  91. for (auto* s : { &row.attack, &row.hold, &row.decay, &row.release })
  92. {
  93. knob (*s, 0.0, 10.0, 0.001, " s");
  94. s->setSkewFactorFromMidPoint (0.5);
  95. }
  96. knob (row.sustain, 0.0, 1.0, 0.01, "");
  97. }
  98. const char* names[] = { TR_NOOP ("Amount"), TR_NOOP ("Attack"), TR_NOOP ("Hold"), TR_NOOP ("Decay"), TR_NOOP ("Sustain"), TR_NOOP ("Release") };
  99. for (int i = 0; i < 6; ++i)
  100. {
  101. labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
  102. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  103. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  104. addAndMakeVisible (labels[(std::size_t) i]);
  105. }
  106. }
  107. void resized() override
  108. {
  109. auto area = getLocalBounds();
  110. auto header = area.removeFromTop (16);
  111. header.removeFromLeft (80);
  112. const auto w = header.getWidth() / 6;
  113. for (auto& l : labels)
  114. l.setBounds (header.removeFromLeft (w));
  115. for (auto& row : rows)
  116. {
  117. auto line = area.removeFromTop (62);
  118. row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
  119. for (auto* s : { &row.amount, &row.attack, &row.hold, &row.decay, &row.sustain, &row.release })
  120. s->setBounds (line.removeFromLeft (w));
  121. }
  122. }
  123. void show (const ModEnvelope& filter, const ModEnvelope& pitch)
  124. {
  125. rows[0].show (filter);
  126. rows[1].show (pitch);
  127. }
  128. ModEnvelope filter() const { return rows[0].read(); }
  129. ModEnvelope pitch() const { return rows[1].read(); }
  130. private:
  131. struct Row
  132. {
  133. juce::Label title;
  134. juce::Slider amount, attack, hold, decay, sustain, release;
  135. void show (const ModEnvelope& e)
  136. {
  137. amount.setValue (e.amount, juce::dontSendNotification);
  138. attack.setValue (e.attack, juce::dontSendNotification);
  139. hold.setValue (e.hold, juce::dontSendNotification);
  140. decay.setValue (e.decay, juce::dontSendNotification);
  141. sustain.setValue (e.sustain, juce::dontSendNotification);
  142. release.setValue (e.release, juce::dontSendNotification);
  143. }
  144. ModEnvelope read() const
  145. {
  146. return { (float) amount.getValue(), (float) attack.getValue(), (float) hold.getValue(),
  147. (float) decay.getValue(), (float) sustain.getValue(), (float) release.getValue() };
  148. }
  149. };
  150. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  151. {
  152. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  153. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  154. s.setRange (lo, hi, step);
  155. s.setTextValueSuffix (suffix);
  156. s.onValueChange = [this] {
  157. if (onChange)
  158. onChange();
  159. };
  160. addAndMakeVisible (s);
  161. }
  162. std::array<Row, 2> rows;
  163. std::array<juce::Label, 6> labels;
  164. };
  165. // Channel LFOs (pan, volume, cutoff, pitch), like FL's.
  166. class LfoEditor final : public juce::Component
  167. {
  168. public:
  169. std::function<void()> onChange;
  170. static constexpr int preferredHeight = 18 + lfoTargets * 60;
  171. LfoEditor()
  172. {
  173. const juce::String titles[] = { tr ("Pan LFO"), tr ("Volume LFO"), tr ("Cutoff LFO"), tr ("Pitch LFO") };
  174. const double amountRange[] = { 1.0, 1.0, 8.0, 24.0 };
  175. const char* amountSuffix[] = { "", "", " oct", " st" };
  176. for (int i = 0; i < lfoTargets; ++i)
  177. {
  178. auto& row = rows[(std::size_t) i];
  179. row.title.setText (titles[i], juce::dontSendNotification);
  180. row.title.setFont (theme::font (theme::type::small));
  181. addAndMakeVisible (row.title);
  182. knob (row.amount, -amountRange[i], amountRange[i], 0.01, amountSuffix[i]);
  183. row.amount.setDoubleClickReturnValue (true, 0.0);
  184. row.amount.setTooltip (tr ("0 = off"));
  185. knob (row.period, 0.01, 16.0, 0.001, "");
  186. row.period.setSkewFactorFromMidPoint (0.5);
  187. knob (row.delay, 0.0, 8.0, 0.001, "");
  188. row.delay.setSkewFactorFromMidPoint (0.5);
  189. knob (row.attack, 0.0, 8.0, 0.001, "");
  190. row.attack.setSkewFactorFromMidPoint (0.5);
  191. row.shape.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Pulse") }, 1);
  192. row.shape.onChange = [this] { changed(); };
  193. addAndMakeVisible (row.shape);
  194. row.sync.setButtonText (tr ("Beats"));
  195. row.sync.setTooltip (tr ("Period, delay and fade-in in beats (follows the BPM) instead of seconds"));
  196. row.sync.onClick = [this] { changed(); };
  197. addAndMakeVisible (row.sync);
  198. row.global.setButtonText (tr ("Global"));
  199. row.global.setTooltip (tr ("Phase follows the song position instead of restarting on each note"));
  200. row.global.onClick = [this] { changed(); };
  201. addAndMakeVisible (row.global);
  202. }
  203. const juce::String headers[] = { tr ("Amount"), tr ("Period"), tr ("Shape"), tr ("Delay"), tr ("Fade-in"), tr ("Unit") };
  204. for (int i = 0; i < 6; ++i)
  205. {
  206. labels[(std::size_t) i].setText (headers[i], juce::dontSendNotification);
  207. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  208. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  209. addAndMakeVisible (labels[(std::size_t) i]);
  210. }
  211. }
  212. void resized() override
  213. {
  214. auto area = getLocalBounds();
  215. auto header = area.removeFromTop (18);
  216. header.removeFromLeft (80);
  217. const auto w = header.getWidth() / 6;
  218. for (auto& l : labels)
  219. l.setBounds (header.removeFromLeft (w));
  220. for (auto& row : rows)
  221. {
  222. auto line = area.removeFromTop (60);
  223. row.title.setBounds (line.removeFromLeft (80).withSizeKeepingCentre (80, 24));
  224. row.amount.setBounds (line.removeFromLeft (w));
  225. row.period.setBounds (line.removeFromLeft (w));
  226. row.shape.setBounds (line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 24));
  227. row.delay.setBounds (line.removeFromLeft (w));
  228. row.attack.setBounds (line.removeFromLeft (w));
  229. auto toggles = line.removeFromLeft (w).withSizeKeepingCentre (w - 6, 50);
  230. row.sync.setBounds (toggles.removeFromTop (24));
  231. row.global.setBounds (toggles.removeFromBottom (24));
  232. }
  233. }
  234. void show (const std::array<ChannelLfo, lfoTargets>& lfo)
  235. {
  236. for (std::size_t i = 0; i < lfoTargets; ++i)
  237. {
  238. auto& row = rows[i];
  239. const auto& l = lfo[i];
  240. row.amount.setValue (l.amount, juce::dontSendNotification);
  241. row.period.setValue (l.period, juce::dontSendNotification);
  242. row.delay.setValue (l.delay, juce::dontSendNotification);
  243. row.attack.setValue (l.attack, juce::dontSendNotification);
  244. row.shape.setSelectedId (l.shape + 1, juce::dontSendNotification);
  245. row.sync.setToggleState (l.sync, juce::dontSendNotification);
  246. row.global.setToggleState (l.global, juce::dontSendNotification);
  247. const auto unit = l.sync ? " t" : " s";
  248. for (auto* s : { &row.period, &row.delay, &row.attack })
  249. s->setTextValueSuffix (unit);
  250. }
  251. }
  252. std::array<ChannelLfo, lfoTargets> read() const
  253. {
  254. std::array<ChannelLfo, lfoTargets> lfo {};
  255. for (std::size_t i = 0; i < lfoTargets; ++i)
  256. {
  257. const auto& row = rows[i];
  258. lfo[i] = { (float) row.amount.getValue(), (float) row.period.getValue(), row.sync.getToggleState(),
  259. juce::jlimit (0, 2, row.shape.getSelectedId() - 1), (float) row.delay.getValue(), (float) row.attack.getValue(),
  260. row.global.getToggleState() };
  261. }
  262. return lfo;
  263. }
  264. private:
  265. struct Row
  266. {
  267. juce::Label title;
  268. juce::Slider amount, period, delay, attack;
  269. juce::ComboBox shape;
  270. juce::ToggleButton sync, global;
  271. };
  272. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  273. {
  274. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  275. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  276. s.setRange (lo, hi, step);
  277. s.setTextValueSuffix (suffix);
  278. s.onValueChange = [this] { changed(); };
  279. addAndMakeVisible (s);
  280. }
  281. void changed()
  282. {
  283. if (onChange)
  284. onChange();
  285. }
  286. std::array<Row, lfoTargets> rows;
  287. std::array<juce::Label, 6> labels;
  288. };
  289. // Channel modulation window: cutoff/pitch envelopes and LFOs of the synth or the sampler.
  290. class ModulationPanel final : public juce::Component,
  291. private juce::ChangeListener
  292. {
  293. public:
  294. ModulationPanel (AudioEngine& e, ChannelRef c)
  295. : engine (e),
  296. ref (std::move (c))
  297. {
  298. envelopes.onChange = [this] { apply(); };
  299. lfos.onChange = [this] { apply(); };
  300. addAndMakeVisible (envelopes);
  301. addAndMakeVisible (lfos);
  302. refresh();
  303. engine.addChangeListener (this);
  304. setSize (660, 20 + ModEnvelopeEditor::preferredHeight + 16 + LfoEditor::preferredHeight);
  305. }
  306. ~ModulationPanel() override { engine.removeChangeListener (this); }
  307. void resized() override
  308. {
  309. auto area = getLocalBounds().reduced (10);
  310. envelopes.setBounds (area.removeFromTop (ModEnvelopeEditor::preferredHeight));
  311. area.removeFromTop (16);
  312. lfos.setBounds (area.removeFromTop (LfoEditor::preferredHeight));
  313. }
  314. int getChannel() const noexcept { return ref.index; }
  315. private:
  316. const ChannelDef* current() const
  317. {
  318. return ref.get (engine);
  319. }
  320. bool isSynth() const { return current() != nullptr && current()->instrument == InstrumentKind::synth; }
  321. void refresh()
  322. {
  323. const auto* c = current();
  324. if (c == nullptr)
  325. return;
  326. if (isSynth())
  327. {
  328. envelopes.show (c->synth.filterEnv, c->synth.pitchEnv);
  329. lfos.show (c->synth.lfo);
  330. }
  331. else
  332. {
  333. envelopes.show (c->sampler.filterEnv, c->sampler.pitchEnv);
  334. lfos.show (c->sampler.lfo);
  335. }
  336. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  337. w->setName (tr ("Modulation - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
  338. }
  339. void apply()
  340. {
  341. if (current() == nullptr)
  342. return;
  343. const auto filter = envelopes.filter(), pitch = envelopes.pitch();
  344. const auto lfo = lfos.read();
  345. const auto synth = isSynth();
  346. ref.edit (engine, [synth, filter, pitch, lfo] (ChannelDef& channelDef) {
  347. auto& ch = channelDef;
  348. if (synth)
  349. {
  350. ch.synth.filterEnv = filter;
  351. ch.synth.pitchEnv = pitch;
  352. ch.synth.lfo = lfo;
  353. }
  354. else
  355. {
  356. ch.sampler.filterEnv = filter;
  357. ch.sampler.pitchEnv = pitch;
  358. ch.sampler.lfo = lfo;
  359. }
  360. });
  361. }
  362. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  363. AudioEngine& engine;
  364. ChannelRef ref;
  365. ModEnvelopeEditor envelopes;
  366. LfoEditor lfos;
  367. };
  368. // Physical-model channels (Sakura, Drumpad; REA_rodada28): knobs for the main raw FL parameters (0..1)
  369. class ModelPanel final : public juce::Component
  370. {
  371. public:
  372. ModelPanel (AudioEngine& e, ChannelRef c)
  373. : engine (e),
  374. ref (std::move (c))
  375. {
  376. static const ChannelDef none;
  377. const auto* found = ref.get (engine);
  378. const auto& def = found != nullptr ? *found : none;
  379. sakura = def.instrument == InstrumentKind::sakura;
  380. boobass = def.instrument == InstrumentKind::boobass;
  381. drumsynth = def.instrument == InstrumentKind::drumsynth;
  382. harmless = def.instrument == InstrumentKind::harmless;
  383. harmor = def.instrument == InstrumentKind::harmor;
  384. gms = def.instrument == InstrumentKind::gms;
  385. morphine = def.instrument == InstrumentKind::morphine;
  386. autogun = def.instrument == InstrumentKind::autogun;
  387. transistorBass = def.instrument == InstrumentKind::transistorbass;
  388. ogun = def.instrument == InstrumentKind::ogun || autogun; // Autogun: Ogun's parameter layout (REA_rodada57)
  389. miniSynth = def.instrument == InstrumentKind::minisynth;
  390. dx10 = def.instrument == InstrumentKind::dx10;
  391. kepler = def.instrument == InstrumentKind::kepler;
  392. poizone = def.instrument == InstrumentKind::poizone;
  393. fruitkick = def.instrument == InstrumentKind::fruitkick;
  394. bassdrum = def.instrument == InstrumentKind::bassdrum;
  395. toxic = def.instrument == InstrumentKind::toxic;
  396. threeOsc = def.instrument == InstrumentKind::threeosc;
  397. simSynth = def.instrument == InstrumentKind::simsynth;
  398. wasp = def.instrument == InstrumentKind::wasp;
  399. plucked = def.instrument == InstrumentKind::plucked;
  400. beepMap = def.instrument == InstrumentKind::beepmap;
  401. sawer = def.instrument == InstrumentKind::sawer;
  402. flKeys = def.instrument == InstrumentKind::flkeys;
  403. granulizer = def.instrument == InstrumentKind::granulizer;
  404. drumaxx = def.instrument == InstrumentKind::drumaxx;
  405. slayer = def.instrument == InstrumentKind::slayer;
  406. fruityDance = def.instrument == InstrumentKind::fruitydance;
  407. sytrus = def.instrument == InstrumentKind::sytrus;
  408. // DrumSynth Live: the patch on the key selected in FL's editor (raw FL values)
  409. if (drumsynth)
  410. {
  411. if (lynx::drumSynthEditorKeyIndex < (int) def.modelParams.size())
  412. editorKey = (int) def.modelParams[(std::size_t) lynx::drumSynthEditorKeyIndex];
  413. if (drumSynthKeyToSlot (editorKey) < 0)
  414. editorKey = 60;
  415. wavesFound = ! def.samplePath.empty();
  416. }
  417. const auto offset = drumsynth ? drumSynthPatchParams * drumSynthKeyToSlot (editorKey) : 0;
  418. static const std::pair<int, const char*> sakuraKnobs[] = {
  419. { 0, "Master" }, { 1, "Tune" }, { 2, "Attack" }, { 3, "Decay" }, { 4, "Sustain" }, { 5, "Release" },
  420. { 6, "Str1 decay" }, { 9, "Str1 damp" }, { 11, "Str2 decay" }, { 14, "Str2 damp" }, { 16, "Saturation" },
  421. { 17, "String mix" }, { 18, "Stereo sep" }, { 19, "Comb ratio" }, { 22, "Comb level" }, { 24, "Lo-cut" },
  422. { 29, "Hi-cut" }, { 30, "Hi-cut res" }, { 31, "Noise level" }, { 32, "Noise rate" } };
  423. static const std::pair<int, const char*> drumpadKnobs[] = {
  424. { 2, "Mallet amp" }, { 3, "Mallet decay" }, { 4, "Mallet noise" }, { 6, "Decay" }, { 7, "Cutoff" },
  425. { 8, "Tension" }, { 9, "Phase" }, { 10, "Material" }, { 11, "Size" }, { 12, "Shape" }, { 13, "Low freq" },
  426. { 18, "Mid freq" }, { 19, "Mid level" }, { 24, "High freq" }, { 25, "High level" }, { 27, "Lo-fi" },
  427. { 28, "Hold" }, { 29, "Pitch" } };
  428. auto add = [&] (int index, const char* name, double low = 0.0, double high = -1.0) {
  429. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  430. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  431. index += offset;
  432. if (high > low)
  433. knob->setRange (low, high, 1.0);
  434. else
  435. knob->setRange (0.0, boobass ? 65535.0 : 1.0, boobass ? 1.0 : 0.001);
  436. knob->setValue (index < (int) def.modelParams.size() ? def.modelParams[(std::size_t) index] : 0.0, juce::dontSendNotification);
  437. knob->setName (name);
  438. knob->onValueChange = [this, index, k = knob.get()] {
  439. ref.edit (engine, [index, v = (float) k->getValue()] (ChannelDef& channelDef) {
  440. auto& params = channelDef.modelParams;
  441. if (index < (int) params.size())
  442. params[(std::size_t) index] = v;
  443. });
  444. };
  445. addAndMakeVisible (*knob);
  446. knobs.push_back (std::move (knob));
  447. };
  448. static const std::pair<int, const char*> booBassKnobs[] = { { 0, "Bass" }, { 1, "Mid" }, { 2, "Treble" } };
  449. struct Ranged { int index; const char* name; double low, high; };
  450. static const Ranged drumSynthKnobs[] = {
  451. { 0, "Level", 0, 128 }, { 1, "Pan", -64, 64 }, { 2, "Tone", -50, 50 }, { 3, "Harmonics", -50, 50 },
  452. { 4, "Osc1 freq", 0, 1000 }, { 7, "Osc1 decay", 0, 127 }, { 8, "Osc1 level", 0, 127 }, { 10, "Osc2 freq", 0, 1000 },
  453. { 13, "Osc2 decay", 0, 127 }, { 14, "Osc2 level", 0, 127 }, { 17, "Wave mix", 0, 127 }, { 21, "Release", 0, 127 },
  454. { 23, "Click", 0, 100 }, { 33, "Ring mod", 0, 127 } };
  455. // Harmless: raw FL values (REA_rodada21/32 ranges)
  456. static const Ranged harmlessKnobs[] = {
  457. { 36, "Volume", 0, 2000 }, { 26, "Attack", 0, 1000 }, { 27, "Decay", 0, 1000 }, { 28, "Release", 0, 1000 },
  458. { 54, "Cutoff", 0, 8192 }, { 59, "Resonance", 0, 1000 }, { 52, "Filter env", -1000, 1000 },
  459. { 31, "Pluck", 0, 1000 }, { 23, "Mask mix", 0, 1000 }, { 65, "Unison", 1, 9 }, { 67, "Uni detune", 0, 256 },
  460. { 25, "Tremolo", 0, 1000 }, { 71, "Phaser mix", 0, 1000 }, { 79, "Harmonizer", 0, 1000 } };
  461. // Harmor: raw FL integers inside the saved state (part A, and the global master / A–B mix; REA_rodada34)
  462. struct HarmorKnob { int part, index; const char* name; double low, high; };
  463. static const HarmorKnob harmorKnobs[] = {
  464. { -1, 12, "Master vol", 0, 2000 }, { -1, 10, "A/B mix", 0, 1000 }, { 0, 11, "A volume", -1000, 1000 },
  465. { 0, 4, "Timbre mix", 0, 1000 }, { 0, 52, "Cutoff", 0, 8192 }, { 0, 57, "Resonance", 0, 1000 },
  466. { 0, 75, "Pluck", 0, 1000 }, { 0, 34, "Unison", 1, 9 }, { 0, 38, "Uni detune", 0, 256 },
  467. { 0, 27, "Harmonizer", 0, 1000 }, { 0, 76, "Phaser mix", 0, 1000 }, { 0, 23, "Harm. blur", 0, 10000 },
  468. { 0, 45, "Vibrato", 0, 1000 }, { 0, 17, "Tremolo", 0, 1000 } };
  469. auto addHarmor = [&] (const HarmorKnob& k) {
  470. const auto at = harmorParamOffset (def.pluginState, k.part, k.index);
  471. if (at < 0)
  472. return;
  473. std::int32_t value = 0;
  474. std::memcpy (&value, def.pluginState.data() + at, 4);
  475. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  476. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  477. knob->setRange (k.low, k.high, 1.0);
  478. knob->setValue (value, juce::dontSendNotification);
  479. knob->setName (k.name);
  480. knob->onValueChange = [this, k, s = knob.get()] {
  481. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  482. auto& st = channelDef.pluginState;
  483. if (const auto o = harmorParamOffset (st, k.part, k.index); o >= 0)
  484. std::memcpy (st.data() + o, &v, 4);
  485. });
  486. };
  487. addAndMakeVisible (*knob);
  488. knobs.push_back (std::move (knob));
  489. };
  490. // GMS / Morphine: the plugin's own 0…1 floats inside the saved state (GMS P[i], Morphine global A[i]; REA_rodada39)
  491. struct FloatKnob { int index; const char* name; };
  492. static const FloatKnob gmsKnobs[] = {
  493. { 0, "Master" }, { 1, "Pan" }, { 8, "Level" }, { 4, "Attack" }, { 5, "Decay" }, { 6, "Sustain" }, { 7, "Release" },
  494. { 12, "Cutoff" }, { 13, "Resonance" }, { 16, "Env1 amount" }, { 50, "Modulation" }, { 48, "Osc2 mix" }, { 49, "Osc3 mix" },
  495. { 45, "Noise" }, { 41, "Unison" }, { 42, "Uni detune" }, { 43, "Stereo" }, { 10, "Slide time" } };
  496. static const FloatKnob morphineKnobs[] = {
  497. { 0, "Master" }, { 9, "Attack" }, { 10, "Decay" }, { 11, "Sustain" }, { 12, "Release" }, { 1, "Glide" }, { 4, "Vel curve" },
  498. { 7, "Overdrive" }, { 14, "Chorus mix" }, { 21, "Delay mix" }, { 25, "Reverb mix" }, { 36, "Noise mix" } };
  499. // BassDrum: its 23 floats 0…1 inside the saved state (REA_rodada15 §12.3 / rodada43 §2.2)
  500. static const FloatKnob bassDrumKnobs[] = {
  501. { 0, "Output" }, { 6, "Base" }, { 7, "Peak" }, { 8, "Slide" }, { 2, "Duration" }, { 5, "Attack" }, { 4, "Drive" },
  502. { 3, "Butt" }, { 15, "Click level" }, { 14, "Click freq" }, { 13, "Click cut" }, { 21, "Noise mix" }, { 22, "Noise filter" },
  503. { 20, "Noise pitch" }, { 19, "Noise start" }, { 1, "Sampling" } };
  504. // Toxic Biohazard: the plugin's 0…1 parameters P[i] inside the saved state (REA_rodada45)
  505. static const FloatKnob toxicKnobs[] = {
  506. { 0, "Gain" }, { 1, "Distortion" }, { 3, "Attack" }, { 4, "Decay" }, { 5, "Sustain" }, { 6, "Release" },
  507. { 15, "Cutoff" }, { 16, "Resonance" }, { 23, "Filter env" }, { 8, "Uni detune" }, { 9, "Uni pan" },
  508. { 10, "Glide" }, { 7, "Vel curve" }, { 2, "Transpose" } };
  509. // MiniSynth: its 43 floats 0…1 inside the saved state (REA_rodada41 §1.2)
  510. static const FloatKnob miniSynthKnobs[] = {
  511. { 5, "Osc kind" }, { 6, "Osc mod" }, { 7, "Noise" }, { 1, "Transpose" }, { 8, "Cutoff" }, { 9, "Resonance" },
  512. { 16, "Filter env" }, { 21, "Attack" }, { 22, "Decay" }, { 23, "Sustain" }, { 24, "Release" }, { 20, "LFO amount" },
  513. { 19, "LFO rate" }, { 2, "Slide time" } };
  514. // PoiZone: the plugin's own floats P[i] inside the saved state (REA_rodada44 §1.3)
  515. static const FloatKnob poizoneKnobs[] = {
  516. { 15, "Gain" }, { 8, "Osc balance" }, { 9, "Noise" }, { 18, "Cutoff" }, { 19, "Resonance" }, { 10, "EG amount" },
  517. { 22, "Attack" }, { 23, "Decay" }, { 24, "Sustain" }, { 25, "Release" }, { 26, "LFO amount" }, { 28, "LFO rate" },
  518. { 46, "Glide" }, { 38, "Delay wet" }, { 42, "Chorus wet" }, { 47, "Gate mix" } };
  519. auto paramOffset = [this] (const std::vector<std::uint8_t>& st, int index) {
  520. return gms ? gmsParamOffset (st, index)
  521. : miniSynth ? miniSynthParamOffset (st, index)
  522. : poizone ? poizoneParamOffset (st, index)
  523. : bassdrum ? bassDrumParamOffset (st, index)
  524. : toxic ? toxicParamOffset (st, index) : morphineParamOffset (st, index);
  525. };
  526. auto addFloat = [&] (const FloatKnob& k) {
  527. const auto at = paramOffset (def.pluginState, k.index);
  528. if (at < 0)
  529. return;
  530. float value = 0.0f;
  531. std::memcpy (&value, def.pluginState.data() + at, 4);
  532. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  533. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  534. knob->setRange (0.0, 1.0, 0.001);
  535. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  536. knob->setName (k.name);
  537. knob->onValueChange = [this, k, paramOffset, s = knob.get()] {
  538. ref.edit (engine, [k, paramOffset, v = (float) s->getValue()] (ChannelDef& channelDef) {
  539. auto& st = channelDef.pluginState;
  540. if (const auto o = paramOffset (st, k.index); o >= 0)
  541. std::memcpy (st.data() + o, &v, 4);
  542. });
  543. };
  544. addAndMakeVisible (*knob);
  545. knobs.push_back (std::move (knob));
  546. };
  547. // SimSynth: its 45 doubles 0…1 at the start of the saved state (REA_rodada64 §1.1)
  548. static const FloatKnob simSynthKnobs[] = {
  549. { 3, "Osc 1 level" }, { 10, "Osc 2 level" }, { 17, "Osc 3 level" }, { 26, "Cutoff" }, { 27, "Resonance" },
  550. { 28, "Filter env" }, { 30, "Key track" }, { 35, "Attack" }, { 36, "Decay" }, { 37, "Sustain" }, { 38, "Release" },
  551. { 22, "LFO rate" }, { 29, "LFO cutoff" }, { 39, "Volume" } };
  552. auto addDouble = [&] (const FloatKnob& k) {
  553. const auto at = 8 * (std::size_t) k.index;
  554. if (! simSynthStateUsable (def.pluginState))
  555. return;
  556. double value = 0.0;
  557. std::memcpy (&value, def.pluginState.data() + at, 8);
  558. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  559. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  560. knob->setRange (0.0, 1.0, 0.001);
  561. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0, 1.0) : 0.0, juce::dontSendNotification);
  562. knob->setName (k.name);
  563. knob->onValueChange = [this, at, s = knob.get()] {
  564. ref.edit (engine, [at, v = s->getValue()] (ChannelDef& channelDef) {
  565. auto& st = channelDef.pluginState;
  566. if (simSynthStateUsable (st))
  567. std::memcpy (st.data() + at, &v, 8);
  568. });
  569. };
  570. addAndMakeVisible (*knob);
  571. knobs.push_back (std::move (knob));
  572. };
  573. // FL Slayer: the 28 parameter integers of the saved state (REA_rodada68 §6.1), ranges of the plugin's controls
  574. static const Ranged slayerKnobs[] = {
  575. { 0, "Strings", 0, 6 }, { 1, "Coils", 0, 2 }, { 2, "Pickup", 0, 65535 }, { 3, "Tone", 0, 65535 }, { 4, "Slap", 0, 65535 },
  576. { 5, "Fret", 0, 65535 }, { 6, "Harmonic", 0, 65535 }, { 7, "Damp", 0, 65535 }, { 8, "Vel volume", 0, 65535 },
  577. { 9, "Vel damp", 0, 65535 }, { 12, "Amp type", 0, 3 }, { 13, "Drive", 0, 65535 }, { 14, "Presence", 0, 65535 },
  578. { 15, "Feedback", 0, 65535 }, { 16, "EQ low", 0, 65535 }, { 17, "EQ mid", 0, 65535 }, { 18, "EQ high", 0, 65535 },
  579. { 19, "Cabinet", 0, 3 }, { 20, "Effect", 0, 15 }, { 21, "FX par 1", 0, 65535 }, { 22, "FX par 2", 0, 65535 },
  580. { 24, "Mode", 0, 5 }, { 25, "Timing", 0, 65535 }, { 26, "Latch", 0, 1 }, { 27, "Glissando", 0, 1 } };
  581. auto addSlayer = [&] (const Ranged& k) {
  582. const auto at = 4 + 4 * (std::size_t) k.index;
  583. if (! slayerStateUsable (def.pluginState) || at + 4 > def.pluginState.size())
  584. return;
  585. std::int32_t value = 0;
  586. std::memcpy (&value, def.pluginState.data() + at, 4);
  587. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  588. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  589. knob->setRange ((double) k.low, (double) k.high, 1.0);
  590. knob->setValue ((double) std::clamp ((int) value, (int) k.low, (int) k.high), juce::dontSendNotification);
  591. knob->setName (k.name);
  592. knob->onValueChange = [this, at, s = knob.get()] {
  593. ref.edit (engine, [at, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  594. auto& st = channelDef.pluginState;
  595. if (slayerStateUsable (st) && at + 4 <= st.size())
  596. std::memcpy (st.data() + at, &v, 4);
  597. });
  598. };
  599. addAndMakeVisible (*knob);
  600. knobs.push_back (std::move (knob));
  601. };
  602. // Sytrus: its "Main settings" page, raw FL integers inside the saved (zlib) state (REA_rodada74 §3)
  603. auto addSytrus = [&] (int setting) {
  604. const auto value = sytrus::settingValue (def.pluginState, setting);
  605. if (! value)
  606. return;
  607. const auto& d = sytrus::settings()[(std::size_t) setting];
  608. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  609. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  610. knob->setRange (d.low, d.high, 1.0);
  611. knob->setValue (std::clamp (*value, d.low, d.high), juce::dontSendNotification);
  612. knob->setName (d.name);
  613. knob->onValueChange = [this, setting, s = knob.get()] {
  614. ref.edit (engine, [setting, v = (int) s->getValue()] (ChannelDef& channelDef) {
  615. sytrus::setSetting (channelDef.pluginState, setting, v);
  616. });
  617. };
  618. addAndMakeVisible (*knob);
  619. knobs.push_back (std::move (knob));
  620. };
  621. // Ogun: raw FL integers P0…P63 inside the saved (zlib) state (REA_rodada37 §1.3)
  622. static const Ranged ogunKnobs[] = {
  623. { 0, "Master vol", 0, 256 }, { 5, "Pre-decay", 0, 1000 }, { 6, "Decay", 0, 10000 }, { 7, "Release", 0, 10000 },
  624. { 8, "Fullness", -1000, 1000 }, { 9, "Morph", 0, 1000 }, { 10, "Seed 1", 0, 1000 }, { 11, "Seed 2", 0, 1000 },
  625. { 52, "Richness", 6, 16 }, { 12, "Unison", 1, 9 }, { 15, "Uni pitch", 0, 256 }, { 17, "Cutoff", 0, 256 },
  626. { 18, "Resonance", 0, 256 }, { 3, "Mod X", 0, 512 }, { 4, "Mod Y", 0, 512 }, { 54, "Quality", 0, 4 } };
  627. static const Ranged autogunKnobs[] = { { 63, "Magic dust", 0, 1000 } };
  628. auto addOgun = [&] (const Ranged& k) {
  629. const auto value = ogunParam (def.pluginState, k.index);
  630. if (! value)
  631. return;
  632. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  633. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  634. knob->setRange (k.low, k.high, 1.0);
  635. knob->setValue (*value, juce::dontSendNotification);
  636. knob->setName (k.name);
  637. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  638. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  639. ogunSetParam (channelDef.pluginState, index, v);
  640. });
  641. };
  642. addAndMakeVisible (*knob);
  643. knobs.push_back (std::move (knob));
  644. };
  645. // Fruit Kick: its six integers (REA_rodada10 §4.2 ranges)
  646. static const Ranged fruitKickKnobs[] = {
  647. { 0, "Max freq", -2400, 3600 }, { 1, "Min freq", -1200, 1200 }, { 2, "Freq decay", 0, 256 }, { 3, "Amp decay", 0, 256 },
  648. { 4, "Click", 0, 64 }, { 5, "Distortion", 0, 128 } };
  649. auto addFruitKick = [&] (const Ranged& k) {
  650. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  651. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  652. knob->setRange (k.low, k.high, 1.0);
  653. knob->setValue (fruitKickParam (def.pluginState, k.index), juce::dontSendNotification);
  654. knob->setName (k.name);
  655. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  656. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  657. fruitKickSetParam (channelDef.pluginState, index, v);
  658. });
  659. };
  660. addAndMakeVisible (*knob);
  661. knobs.push_back (std::move (knob));
  662. };
  663. // Fruity DX10: the 22 raw FL integers of the saved state (REA_rodada42 §1.2)
  664. static const Ranged dx10Knobs[] = {
  665. { 0, "Attack", 0, 65536 }, { 1, "Decay", 0, 65536 }, { 2, "Release", 0, 65536 }, { 21, "Coarse", -3, 3 },
  666. { 11, "Waveform", 0, 65536 }, { 10, "Vibrato", 0, 65536 }, { 13, "LFO rate", 0, 65536 },
  667. { 3, "Mod 1 coarse", 0, 65536 }, { 4, "Mod 1 fine", 0, 65536 }, { 5, "Mod 1 init", 0, 65536 }, { 6, "Mod 1 time", 0, 65536 },
  668. { 7, "Mod 1 sustain", 0, 65536 }, { 8, "Mod 1 release", 0, 65536 }, { 9, "Mod 1 velocity", 0, 65536 },
  669. { 14, "Mod 2 coarse", 0, 65536 }, { 15, "Mod 2 fine", 0, 65536 }, { 16, "Mod 2 init", 0, 65536 }, { 17, "Mod 2 time", 0, 65536 },
  670. { 18, "Mod 2 sustain", 0, 65536 }, { 19, "Mod 2 release", 0, 65536 }, { 20, "Mod 2 velocity", 0, 65536 }, { 12, "Mod thru", 0, 65536 } };
  671. auto addDx10 = [&] (const Ranged& k) {
  672. const auto value = dx10Param (def.pluginState, k.index);
  673. if (! value)
  674. return;
  675. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  676. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  677. knob->setRange (k.low, k.high, 1.0);
  678. knob->setValue (*value, juce::dontSendNotification);
  679. knob->setName (k.name);
  680. knob->onValueChange = [this, index = k.index, s = knob.get()] {
  681. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  682. dx10SetParam (channelDef.pluginState, index, v);
  683. });
  684. };
  685. addAndMakeVisible (*knob);
  686. knobs.push_back (std::move (knob));
  687. };
  688. // 3x Osc: the 21 parameters of the saved state, then invert ×3, AM and HQ (REA_rodada47 §1.1)
  689. static const char* const threeOscNames[] = {
  690. "Osc 1 pan", "Osc 1 shape", "Osc 1 coarse", "Osc 1 fine", "Osc 1 phase", "Osc 1 detune", "Osc 2 mix", "Osc 2 pan",
  691. "Osc 2 shape", "Osc 2 coarse", "Osc 2 fine", "Osc 2 phase", "Osc 2 detune", "Osc 3 mix", "Osc 3 pan", "Osc 3 shape",
  692. "Osc 3 coarse", "Osc 3 fine", "Osc 3 phase", "Osc 3 detune", "Phase rand", "Invert 1", "Invert 2", "Invert 3",
  693. "Osc 3 AM", "HQ" };
  694. auto addThreeOsc = [&] (int index) {
  695. const auto value = threeOscParam (def.pluginState, index);
  696. if (! value)
  697. return;
  698. const auto [low, high] = threeOscParamRange (index);
  699. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  700. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  701. knob->setRange (low, high, 1.0);
  702. knob->setValue (*value, juce::dontSendNotification);
  703. knob->setName (threeOscNames[index]);
  704. knob->onValueChange = [this, index, s = knob.get()] {
  705. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  706. threeOscSetParam (channelDef.pluginState, index, v);
  707. });
  708. };
  709. addAndMakeVisible (*knob);
  710. knobs.push_back (std::move (knob));
  711. };
  712. // Fruity Granulizer: the 12 parameters of the saved state (REA_rodada67 §1)
  713. static const char* const granulizerNames[] = {
  714. "Grain attack", "Grain hold", "Grain spacing", "Wave spacing", "Effect depth", "Effect speed", "Randomness",
  715. "Stereo", "Loop", "Freeze", "Sample start", "Transient hold" };
  716. auto addGranulizer = [&] (int index) {
  717. const auto value = granulizerParam (def.pluginState, index);
  718. if (! value)
  719. return;
  720. const auto [low, high] = granulizerParamRange (index);
  721. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  722. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  723. knob->setRange (low, high, 1.0);
  724. knob->setValue (*value, juce::dontSendNotification);
  725. knob->setName (granulizerNames[index]);
  726. knob->onValueChange = [this, index, s = knob.get()] {
  727. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  728. granulizerSetParam (channelDef.pluginState, index, v);
  729. });
  730. };
  731. addAndMakeVisible (*knob);
  732. knobs.push_back (std::move (knob));
  733. };
  734. // Drumaxx: the master level and the 16 pad volumes, 0…1 floats of the saved state (REA_rodada67 §6)
  735. auto addDrumaxx = [&] (int index, const juce::String& name) {
  736. const auto value = drumaxxParam (def.pluginState, index);
  737. if (! std::isfinite (value))
  738. return;
  739. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  740. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  741. knob->setRange (0.0, 1.0, 0.001);
  742. knob->setValue (std::clamp ((double) value, 0.0, 1.0), juce::dontSendNotification);
  743. knob->setName (name);
  744. knob->onValueChange = [this, index, s = knob.get()] {
  745. ref.edit (engine, [index, v = (float) s->getValue()] (ChannelDef& channelDef) {
  746. drumaxxSetParam (channelDef.pluginState, index, v);
  747. });
  748. };
  749. addAndMakeVisible (*knob);
  750. knobs.push_back (std::move (knob));
  751. };
  752. // Kepler: the panel's 0…1 floats inside the saved state ("Kepler-1" order, REA_rodada46 §1.1)
  753. static const FloatKnob keplerKnobs[] = {
  754. { 33, "Volume" }, { 19, "Cutoff" }, { 20, "Resonance" }, { 22, "Env amount" }, { 26, "Attack" }, { 27, "Decay" },
  755. { 28, "Sustain" }, { 29, "Release" }, { 11, "PW" }, { 16, "Sub level" }, { 17, "Noise" }, { 5, "LFO rate" },
  756. { 10, "Vibrato" }, { 18, "High-pass" }, { 30, "Chorus" } };
  757. auto addKepler = [&] (const FloatKnob& k) {
  758. const auto at = keplerPanelOffset (def.pluginState, k.index);
  759. if (at < 0)
  760. return;
  761. float value = 0.0f;
  762. std::memcpy (&value, def.pluginState.data() + at, 4);
  763. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  764. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  765. knob->setRange (0.0, 1.0, 0.001);
  766. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  767. knob->setName (k.name);
  768. knob->onValueChange = [this, k, s = knob.get()] {
  769. ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
  770. auto& st = channelDef.pluginState;
  771. if (const auto o = keplerPanelOffset (st, k.index); o >= 0)
  772. std::memcpy (st.data() + o, &v, 4);
  773. });
  774. };
  775. addAndMakeVisible (*knob);
  776. knobs.push_back (std::move (knob));
  777. };
  778. // Plucked!: the five int32 knobs of the saved state (REA_rodada65 §1.1)
  779. static const Ranged pluckedKnobs[] = { { 0, "Decay", 0, 256 }, { 1, "Color", 0, 128 }, { 2, "Normalize", 0, 1 },
  780. { 3, "Gate", 0, 1 }, { 4, "Widen", 0, 1 } };
  781. auto addPlucked = [&] (const Ranged& k) {
  782. if (def.pluginState.size() < 20)
  783. return;
  784. std::int32_t value = 0;
  785. std::memcpy (&value, def.pluginState.data() + 4 * k.index, 4);
  786. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  787. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  788. knob->setRange (k.low, k.high, 1.0);
  789. knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
  790. knob->setName (k.name);
  791. knob->onValueChange = [this, k, s = knob.get()] {
  792. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  793. auto& st = channelDef.pluginState;
  794. if (st.size() >= 20)
  795. std::memcpy (st.data() + 4 * k.index, &v, 4);
  796. });
  797. };
  798. addAndMakeVisible (*knob);
  799. knobs.push_back (std::move (knob));
  800. };
  801. // BeepMap: the int32 settings of the saved state (REA_rodada65 §2.1; Frequency's range not confirmed)
  802. static const Ranged beepMapKnobs[] = { { 0, "Frequency", 0, 9600 }, { 1, "Length", 0, 4096 }, { 2, "Scale", 0, 2 },
  803. { 3, "Use blue", 0, 1 }, { 4, "Grainy", 0, 1 }, { 5, "Loop", 0, 1 }, { 6, "Widen", 0, 1 } };
  804. auto addBeepMap = [&] (const Ranged& k) {
  805. const auto at = beepMapParamOffset (def.pluginState, k.index);
  806. if (at < 0)
  807. return;
  808. std::int32_t value = 0;
  809. std::memcpy (&value, def.pluginState.data() + at, 4);
  810. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  811. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  812. knob->setRange (k.low, k.high, 1.0);
  813. knob->setValue (std::clamp ((double) value, k.low, k.high), juce::dontSendNotification);
  814. knob->setName (k.name);
  815. knob->onValueChange = [this, k, s = knob.get()] {
  816. ref.edit (engine, [k, v = (std::int32_t) s->getValue()] (ChannelDef& channelDef) {
  817. auto& st = channelDef.pluginState;
  818. if (const auto o = beepMapParamOffset (st, k.index); o >= 0)
  819. std::memcpy (st.data() + o, &v, 4);
  820. });
  821. };
  822. addAndMakeVisible (*knob);
  823. knobs.push_back (std::move (knob));
  824. };
  825. // Sawer: 0…1 floats of the saved state (REA_rodada65 §3.3)
  826. static const FloatKnob sawerKnobs[] = {
  827. { 0, "Level" }, { 27, "Cutoff" }, { 28, "Resonance" }, { 36, "EGF amount" }, { 2, "Attack" }, { 3, "Decay" },
  828. { 4, "Sustain" }, { 5, "Release" }, { 19, "Sub level" }, { 18, "Sub harmonic" }, { 26, "Noise" }, { 14, "Unison" },
  829. { 15, "Uni detune" }, { 45, "LFO amount" } };
  830. auto addSawer = [&] (const FloatKnob& k) {
  831. const auto at = sawerParamOffset (def.pluginState, k.index);
  832. if (at < 0)
  833. return;
  834. float value = 0.0f;
  835. std::memcpy (&value, def.pluginState.data() + at, 4);
  836. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  837. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  838. knob->setRange (0.0, 1.0, 0.001);
  839. knob->setValue (std::isfinite (value) ? std::clamp (value, 0.0f, 1.0f) : 0.0f, juce::dontSendNotification);
  840. knob->setName (k.name);
  841. knob->onValueChange = [this, k, s = knob.get()] {
  842. ref.edit (engine, [k, v = (float) s->getValue()] (ChannelDef& channelDef) {
  843. auto& st = channelDef.pluginState;
  844. if (const auto o = sawerParamOffset (st, k.index); o >= 0)
  845. std::memcpy (st.data() + o, &v, 4);
  846. });
  847. };
  848. addAndMakeVisible (*knob);
  849. knobs.push_back (std::move (knob));
  850. };
  851. // FL Keys: the 15 int32 knobs of the saved state (REA_rodada69 §8.1)
  852. auto addFlKeys = [&] (int index) {
  853. const auto state = flkeys::parseState (def.pluginState);
  854. if (! state)
  855. return;
  856. const auto& r = flkeys::knobRange[index];
  857. auto knob = std::make_unique<juce::Slider> (juce::Slider::RotaryHorizontalVerticalDrag, juce::Slider::TextBoxBelow);
  858. knob->setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 16);
  859. knob->setRange (r.min, r.max, 1.0);
  860. knob->setValue (std::clamp ((double) state->knobs[(std::size_t) index], (double) r.min, (double) r.max), juce::dontSendNotification);
  861. knob->setName (r.name);
  862. knob->onValueChange = [this, index, s = knob.get()] {
  863. ref.edit (engine, [index, v = (int) s->getValue()] (ChannelDef& channelDef) {
  864. auto& st = channelDef.pluginState;
  865. if (auto parsed = flkeys::parseState (st))
  866. {
  867. parsed->knobs[(std::size_t) index] = v;
  868. st = flkeys::writeState (*parsed);
  869. }
  870. });
  871. };
  872. addAndMakeVisible (*knob);
  873. knobs.push_back (std::move (knob));
  874. };
  875. if (flKeys)
  876. for (int i = 0; i < 15; ++i)
  877. addFlKeys (i);
  878. else if (plucked)
  879. for (const auto& k : pluckedKnobs)
  880. addPlucked (k);
  881. else if (beepMap)
  882. for (const auto& k : beepMapKnobs)
  883. addBeepMap (k);
  884. else if (sawer)
  885. for (const auto& k : sawerKnobs)
  886. addSawer (k);
  887. else if (threeOsc)
  888. for (int i = 0; i < threeOscParamCount(); ++i)
  889. addThreeOsc (i);
  890. else if (granulizer)
  891. for (int i = 0; i < granulizerParamCount(); ++i)
  892. addGranulizer (i);
  893. else if (drumaxx)
  894. {
  895. addDrumaxx (0x2c1, "Master");
  896. for (int pad = 0; pad < 16; ++pad)
  897. addDrumaxx (pad * 44, "Pad " + juce::String (pad + 1));
  898. }
  899. else if (dx10)
  900. for (const auto& k : dx10Knobs)
  901. addDx10 (k);
  902. else if (kepler)
  903. for (const auto& k : keplerKnobs)
  904. addKepler (k);
  905. else if (gms)
  906. for (const auto& k : gmsKnobs)
  907. addFloat (k);
  908. else if (bassdrum)
  909. for (const auto& k : bassDrumKnobs)
  910. addFloat (k);
  911. else if (fruitkick)
  912. for (const auto& k : fruitKickKnobs)
  913. addFruitKick (k);
  914. else if (morphine)
  915. for (const auto& k : morphineKnobs)
  916. addFloat (k);
  917. else if (poizone)
  918. for (const auto& k : poizoneKnobs)
  919. addFloat (k);
  920. else if (miniSynth)
  921. for (const auto& k : miniSynthKnobs)
  922. addFloat (k);
  923. else if (simSynth)
  924. for (const auto& k : simSynthKnobs)
  925. addDouble (k);
  926. else if (wasp || fruityDance)
  927. ;
  928. else if (slayer)
  929. for (const auto& k : slayerKnobs)
  930. addSlayer (k);
  931. else if (sytrus)
  932. for (int i = 0; i < (int) sytrus::settings().size(); ++i)
  933. addSytrus (i);
  934. else if (toxic)
  935. for (const auto& k : toxicKnobs)
  936. addFloat (k);
  937. else if (ogun)
  938. {
  939. for (const auto& k : ogunKnobs)
  940. addOgun (k);
  941. if (autogun)
  942. for (const auto& k : autogunKnobs)
  943. addOgun (k);
  944. }
  945. else if (harmor)
  946. for (const auto& k : harmorKnobs)
  947. addHarmor (k);
  948. else if (harmless)
  949. for (const auto& k : harmlessKnobs)
  950. add (k.index, k.name, k.low, k.high);
  951. else if (drumsynth)
  952. for (const auto& k : drumSynthKnobs)
  953. add (k.index, k.name, k.low, k.high);
  954. else if (boobass)
  955. for (const auto& [index, name] : booBassKnobs)
  956. add (index, name);
  957. else if (sakura)
  958. for (const auto& [index, name] : sakuraKnobs)
  959. add (index, name);
  960. else
  961. for (const auto& [index, name] : drumpadKnobs)
  962. add (index, name);
  963. const auto rows = ((int) knobs.size() + 6) / 7; // the grid of resized()
  964. setSize (720, std::max (dx10 || threeOsc ? 500 : 384, 46 + rows * 110 + 8));
  965. // a Granulizer node inside a Patcher (round 165c): no channel to drop a sample on, so its own Sample button
  966. if (granulizer && ref.index < 0)
  967. {
  968. sampleButton.setButtonText (tr ("Sample..."));
  969. const auto path = juce::String::fromUTF8 (def.samplePath.c_str());
  970. ui::setHint (sampleButton, path.isEmpty() ? tr ("Choose the sample the Granulizer plays") : path);
  971. sampleButton.onClick = [this] {
  972. chooser = std::make_unique<juce::FileChooser> (tr ("Sample"), juce::File(), "*.wav;*.aif;*.aiff;*.flac;*.ogg;*.mp3");
  973. chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  974. [safe = juce::Component::SafePointer<ModelPanel> (this)] (const juce::FileChooser& fc) {
  975. if (safe == nullptr || fc.getResult() == juce::File())
  976. return;
  977. const auto file = fc.getResult();
  978. safe->ref.edit (safe->engine, [path = file.getFullPathName().toStdString()] (ChannelDef& d) { d.samplePath = path; });
  979. ui::setHint (safe->sampleButton, file.getFullPathName());
  980. safe->repaint();
  981. });
  982. };
  983. addAndMakeVisible (sampleButton);
  984. resized(); // (setSize above laid the page out before the button existed)
  985. }
  986. // FL's arrangement of the plugin's page (core/PluginLayout.cpp): the knobs at FL's places, faders and
  987. // switches drawn by the panel
  988. layout = plugui::instrumentLayout (def.instrument);
  989. // a state the engine cannot read gives no knobs: keep the plain page then
  990. if (layout != nullptr && std::none_of (knobs.begin(), knobs.end(), [this] (const auto& k) { return itemFor (k->getName()) != nullptr; }))
  991. layout = nullptr;
  992. if (layout != nullptr)
  993. {
  994. accent = flKeys ? skin::colour::azure : boobass || transistorBass ? skin::colour::ember : harmor || sytrus || harmless || morphine ? skin::colour::violet
  995. : skin::colour::crimson;
  996. // round 126: the page's own style (FL Keys hardware, BooBass vivid, the synths neon)
  997. pageStyle = flKeys ? skin::Style::hardware : boobass || transistorBass ? skin::Style::vivid : skin::Style::neon;
  998. for (auto& k : knobs)
  999. {
  1000. k->getProperties().set (skin::sliderProperty, (juce::int64) accent.getARGB());
  1001. k->getProperties().set (skin::styleProperty, (int) pageStyle);
  1002. const auto* item = itemFor (k->getName());
  1003. if (item == nullptr || (item->type != plugui::Item::knob && item->type != plugui::Item::vslider && item->type != plugui::Item::hslider))
  1004. {
  1005. k->setVisible (false); // edited by a switch of the panel (or not shown by FL)
  1006. continue;
  1007. }
  1008. k->setTextBoxStyle (juce::Slider::NoTextBox, false, 0, 0);
  1009. if (item->type == plugui::Item::vslider)
  1010. k->setSliderStyle (juce::Slider::LinearVertical);
  1011. if (item->type == plugui::Item::hslider)
  1012. k->setSliderStyle (juce::Slider::LinearHorizontal);
  1013. k->setPopupDisplayEnabled (true, true, this);
  1014. k->setTooltip (k->getName());
  1015. }
  1016. // FL's size × 1.25, at most about 1200 × 760 (big pages such as Harmor's fit a laptop screen)
  1017. const auto f = juce::jmin (layoutScale, 1200.0f / (float) layout->width, 720.0f / (float) layout->height);
  1018. setSize ((int) std::ceil (f * (float) layout->width) + 16, (int) std::ceil (f * (float) layout->height) + layoutTop + 8);
  1019. }
  1020. }
  1021. // --- FL's arrangement ------------------------------------------------------------------------------
  1022. static constexpr float layoutScale = 1.25f;
  1023. static constexpr int layoutTop = 34;
  1024. const plugui::LayoutItem* itemFor (const juce::String& name) const
  1025. {
  1026. if (layout == nullptr)
  1027. return nullptr;
  1028. const plugui::LayoutItem* any = nullptr;
  1029. for (const auto& item : layout->items) // the knob / fader of the parameter first (a pad may share it)
  1030. if (item.param != nullptr && name == item.param)
  1031. {
  1032. if (item.type == plugui::Item::knob || item.type == plugui::Item::vslider)
  1033. return &item;
  1034. if (any == nullptr && item.type != plugui::Item::display)
  1035. any = &item;
  1036. }
  1037. return any;
  1038. }
  1039. juce::Slider* knobFor (const char* name) const
  1040. {
  1041. for (const auto& k : knobs)
  1042. if (name != nullptr && k->getName() == name)
  1043. return k.get();
  1044. return nullptr;
  1045. }
  1046. float layoutFactor() const
  1047. {
  1048. if (layout == nullptr)
  1049. return 1.0f;
  1050. return juce::jmax (0.4f, juce::jmin ((float) (getWidth() - 16) / (float) layout->width, (float) (getHeight() - layoutTop - 8) / (float) layout->height));
  1051. }
  1052. juce::Rectangle<float> layoutRect (const plugui::LayoutItem& item) const
  1053. {
  1054. const auto f = layoutFactor();
  1055. return { 8.0f + item.x * f, (float) layoutTop + item.y * f, item.w * f, item.h * f };
  1056. }
  1057. static float normalised (const juce::Slider& k)
  1058. {
  1059. const auto range = k.getMaximum() - k.getMinimum();
  1060. return range > 0.0 ? (float) ((k.getValue() - k.getMinimum()) / range) : 0.0f;
  1061. }
  1062. static void setNormalised (juce::Slider& k, float v)
  1063. {
  1064. k.setValue (k.getMinimum() + (double) v * (k.getMaximum() - k.getMinimum()), juce::sendNotificationSync);
  1065. }
  1066. // the radio's option cell (grids fill row by row)
  1067. juce::Rectangle<float> optionCell (const plugui::LayoutItem& item, int o, int count) const
  1068. {
  1069. const auto r = layoutRect (item);
  1070. const auto columns = juce::jmax (1, item.columns);
  1071. const auto rows = (count + columns - 1) / columns;
  1072. const auto w = r.getWidth() / (float) columns, h = r.getHeight() / (float) juce::jmax (1, rows);
  1073. return { r.getX() + w * (float) (o % columns), r.getY() + h * (float) (o / columns), w, h };
  1074. }
  1075. // a small drawing of an oscillator shape (3x Osc's shape buttons)
  1076. static void drawShape (juce::Graphics& g, juce::Rectangle<float> r, const juce::String& name)
  1077. {
  1078. juce::Path p;
  1079. const auto x0 = r.getX(), w = r.getWidth(), yc = r.getCentreY(), a = r.getHeight() * 0.5f;
  1080. const auto n = 48;
  1081. for (int i = 0; i <= n; ++i)
  1082. {
  1083. const auto t = (float) i / (float) n;
  1084. float y = 0.0f;
  1085. if (name == "Sine") y = std::sin (t * juce::MathConstants<float>::twoPi);
  1086. else if (name == "Square") y = t < 0.5f ? 1.0f : -1.0f;
  1087. else if (name == "Rounded") y = t < 0.46f ? 1.0f - 2.0f * std::pow (0.997f, t * 16384.0f) : (t < 0.83f ? 1.0f : -1.0f);
  1088. else if (name == "Triangle") y = t < 0.25f ? 4.0f * t : (t < 0.75f ? 2.0f - 4.0f * t : 4.0f * t - 4.0f);
  1089. else if (name == "Saw") y = 2.0f * t - 1.0f;
  1090. else if (name == "Noise") y = std::sin ((float) i * 12.9898f) * std::cos ((float) i * 4.1414f) * 1.6f;
  1091. else /* custom */ y = std::sin (t * juce::MathConstants<float>::twoPi * 3.0f) * std::exp (-std::abs (t - 0.5f) * 5.0f);
  1092. y = juce::jlimit (-1.0f, 1.0f, y);
  1093. const juce::Point<float> pt { x0 + w * t, yc - a * y };
  1094. if (i == 0)
  1095. p.startNewSubPath (pt);
  1096. else
  1097. p.lineTo (pt);
  1098. }
  1099. g.strokePath (p, juce::PathStrokeType (1.5f, juce::PathStrokeType::curved, juce::PathStrokeType::rounded));
  1100. }
  1101. void paintLayout (juce::Graphics& g)
  1102. {
  1103. using namespace theme;
  1104. const skin::StyleScope styleScope (skin::resolve (pageStyle));
  1105. const auto f = layoutFactor();
  1106. const auto* found = ref.get (engine);
  1107. if (found == nullptr)
  1108. return;
  1109. const auto& def = *found;
  1110. const auto caption = [&] (const char* text, juce::Rectangle<float> r, bool dimmed, juce::Justification j) {
  1111. if (text == nullptr || *text == 0)
  1112. return;
  1113. g.setColour (dimmed ? colour::textDisabled : colour::textSecondary);
  1114. g.setFont (font (juce::jmax (8.0f, 9.5f * f), true));
  1115. g.drawFittedText (caps (tr (text)), r.toNearestInt(), j, 1, 0.7f);
  1116. };
  1117. for (const auto& item : layout->items)
  1118. {
  1119. const auto r = layoutRect (item);
  1120. const auto dimmed = (item.style & plugui::dim) != 0;
  1121. auto* k = knobFor (item.param);
  1122. switch (item.type)
  1123. {
  1124. case plugui::Item::section:
  1125. skin::section (g, r, radius::lg * f, (item.style & plugui::raised) != 0, accent);
  1126. if (item.label != nullptr && (item.style & plugui::boxed) == 0)
  1127. skin::sectionTitle (g, r.withHeight (16.0f * f).translated (0.0f, 1.0f * f), caps (tr (item.label)), accent, juce::jmax (8.0f, 10.0f * f));
  1128. break;
  1129. case plugui::Item::label:
  1130. if (item.label != nullptr && juce::String (item.label).length() <= 2 && dimmed) // big dim numbers (3x Osc rows)
  1131. {
  1132. g.setColour (colour::bg4);
  1133. g.setFont (font (r.getHeight() * 0.9f, true));
  1134. g.drawText (item.label, r, juce::Justification::centred, false);
  1135. }
  1136. else if (dimmed && r.getHeight() > 30.0f * f) // the plugin's name, big and quiet
  1137. {
  1138. g.setColour (colour::bg4);
  1139. g.setFont (font (r.getHeight() * 0.6f, true));
  1140. g.drawFittedText (item.label, r.toNearestInt(),
  1141. (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centredRight, 1, 0.8f);
  1142. }
  1143. else
  1144. caption (item.label, r, dimmed, (item.style & plugui::alignLeft) != 0 ? juce::Justification::centredLeft : juce::Justification::centred);
  1145. break;
  1146. case plugui::Item::knob:
  1147. if ((item.style & plugui::noCaption) == 0)
  1148. caption (item.label, r.withTop (r.getBottom() - 12.0f * f), dimmed, juce::Justification::centred);
  1149. break;
  1150. case plugui::Item::vslider:
  1151. case plugui::Item::hslider:
  1152. if ((item.style & plugui::noCaption) == 0)
  1153. caption (item.label, r.withTop (r.getBottom() - 12.0f * f).expanded (16.0f * f, 0.0f), dimmed, juce::Justification::centred);
  1154. break;
  1155. case plugui::Item::radio:
  1156. if (k != nullptr)
  1157. {
  1158. const auto labels = plugui::optionLabels (item);
  1159. const auto chosen = plugui::optionAt (item, normalised (*k));
  1160. for (int o = 0; o < (int) labels.size(); ++o)
  1161. {
  1162. const auto cell = optionCell (item, o, (int) labels.size()).reduced (3.0f * f);
  1163. skin::button (g, cell, o == chosen, false, accent, radius::md * f);
  1164. g.setColour (o == chosen ? accent.brighter (0.5f) : colour::textSecondary);
  1165. if (item.columns > 0)
  1166. drawShape (g, cell.reduced (cell.getWidth() * 0.22f, cell.getHeight() * 0.3f), labels[(std::size_t) o]);
  1167. else
  1168. g.drawFittedText (tr (labels[(std::size_t) o]), cell.toNearestInt(), juce::Justification::centred, 1, 0.7f);
  1169. }
  1170. }
  1171. break;
  1172. case plugui::Item::toggle:
  1173. if (k != nullptr)
  1174. {
  1175. const auto on = normalised (*k) >= 0.5f;
  1176. if ((item.style & plugui::boxed) != 0)
  1177. {
  1178. const auto box = r.reduced (3.0f * f);
  1179. skin::button (g, box, on, false, accent, radius::md * f);
  1180. g.setColour (on ? colour::onAccent : colour::textSecondary);
  1181. g.setFont (font (juce::jmax (8.0f, 11.0f * f), true));
  1182. g.drawText (item.label != nullptr ? item.label : "", box, juce::Justification::centred, false);
  1183. }
  1184. else
  1185. {
  1186. const auto dot = juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre ({ r.getX() + 6.0f * f, r.getCentreY() });
  1187. if (on)
  1188. {
  1189. g.setColour (accent.withAlpha (0.3f));
  1190. g.fillEllipse (dot.expanded (3.0f * f));
  1191. }
  1192. g.setColour (on ? accent : juce::Colour (0xff0b0c0f));
  1193. g.fillEllipse (dot);
  1194. g.setColour (juce::Colours::white.withAlpha (on ? 0.4f : 0.08f));
  1195. g.drawEllipse (dot.reduced (0.5f), 1.0f);
  1196. caption (item.label, r.withTrimmedLeft (14.0f * f), false, juce::Justification::centredLeft);
  1197. }
  1198. }
  1199. break;
  1200. case plugui::Item::stepper:
  1201. if (k != nullptr)
  1202. {
  1203. auto box = r;
  1204. if (item.label != nullptr)
  1205. caption (item.label, box.removeFromTop (12.0f * f), false, juce::Justification::centred);
  1206. skin::valuePlate (g, box, radius::sm * f);
  1207. g.setColour (colour::textPrimary);
  1208. g.setFont (font (juce::jmax (9.0f, 12.0f * f), true));
  1209. // oversampling orders read as FL shows them (0 → 1x … 3 → 8x)
  1210. const auto text = juce::String (item.param).containsIgnoreCase ("oversampling") ? juce::String (1 << juce::jlimit (0, 8, (int) k->getValue())) + "x"
  1211. : juce::String ((int) k->getValue());
  1212. g.drawText (text, box.withTrimmedRight (8.0f * f), juce::Justification::centred, false);
  1213. g.setColour (colour::textSecondary);
  1214. g.drawText (juce::String::fromUTF8 ("\xe2\x96\xb4"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withHeight (box.getHeight() * 0.5f), juce::Justification::centred, false);
  1215. g.drawText (juce::String::fromUTF8 ("\xe2\x96\xbe"), box.withTrimmedLeft (box.getWidth() - 10.0f * f).withTrimmedTop (box.getHeight() * 0.5f), juce::Justification::centred, false);
  1216. }
  1217. break;
  1218. case plugui::Item::display:
  1219. skin::well (g, r, radius::md * f);
  1220. if (juce::String (item.display) == "xy")
  1221. if (auto* kx = knobFor (item.param); kx != nullptr)
  1222. if (auto* ky = knobFor (item.param2); ky != nullptr)
  1223. {
  1224. g.setColour (colour::gridBeat);
  1225. g.drawVerticalLine ((int) r.getCentreX(), r.getY(), r.getBottom());
  1226. g.drawHorizontalLine ((int) r.getCentreY(), r.getX(), r.getRight());
  1227. const juce::Point<float> pt { r.getX() + r.getWidth() * normalised (*kx), r.getBottom() - r.getHeight() * normalised (*ky) };
  1228. g.setColour (accent.withAlpha (0.3f));
  1229. g.fillEllipse (juce::Rectangle<float> (16.0f * f, 16.0f * f).withCentre (pt));
  1230. g.setColour (accent);
  1231. g.drawEllipse (juce::Rectangle<float> (10.0f * f, 10.0f * f).withCentre (pt), 2.0f);
  1232. }
  1233. if (juce::String (item.display) == "flkeysname")
  1234. if (const auto st = flkeys::parseState (def.pluginState))
  1235. {
  1236. g.setColour (colour::textPrimary);
  1237. g.setFont (font (juce::jmax (9.0f, 11.0f * f)));
  1238. g.drawFittedText (juce::String::fromUTF8 (st->wavetable.c_str()), r.reduced (6.0f * f, 0.0f).toNearestInt(),
  1239. juce::Justification::centredLeft, 1, 0.8f);
  1240. }
  1241. break;
  1242. default:
  1243. break;
  1244. }
  1245. }
  1246. }
  1247. void resizeLayout()
  1248. {
  1249. for (auto& k : knobs)
  1250. {
  1251. const auto* item = itemFor (k->getName());
  1252. if (item == nullptr || ! k->isVisible())
  1253. continue;
  1254. auto r = layoutRect (*item);
  1255. if ((item->type == plugui::Item::vslider || item->type == plugui::Item::hslider) && (item->style & plugui::noCaption) == 0 && item->label != nullptr)
  1256. r.removeFromBottom (13.0f * layoutFactor());
  1257. if (item->type == plugui::Item::knob)
  1258. {
  1259. if ((item->style & plugui::noCaption) == 0)
  1260. r.removeFromBottom (14.0f * layoutFactor());
  1261. const auto d = juce::jmin (r.getWidth(), r.getHeight());
  1262. r = r.withSizeKeepingCentre (d, d).withY (r.getY());
  1263. }
  1264. k->setBounds (r.toNearestInt());
  1265. }
  1266. }
  1267. void mouseDrag (const juce::MouseEvent& e) override
  1268. {
  1269. if (xyItem == nullptr)
  1270. return;
  1271. const auto r = layoutRect (*xyItem);
  1272. if (auto* kx = knobFor (xyItem->param))
  1273. setNormalised (*kx, juce::jlimit (0.0f, 1.0f, (e.position.x - r.getX()) / r.getWidth()));
  1274. if (auto* ky = knobFor (xyItem->param2))
  1275. setNormalised (*ky, juce::jlimit (0.0f, 1.0f, (r.getBottom() - e.position.y) / r.getHeight()));
  1276. repaint();
  1277. }
  1278. void mouseUp (const juce::MouseEvent&) override { xyItem = nullptr; }
  1279. void mouseDown (const juce::MouseEvent& e) override
  1280. {
  1281. if (layout == nullptr)
  1282. return;
  1283. for (const auto& item : layout->items)
  1284. {
  1285. auto* k = knobFor (item.param);
  1286. if (k == nullptr || ! layoutRect (item).contains (e.position))
  1287. continue;
  1288. if (item.type == plugui::Item::display && juce::String (item.display) == "xy")
  1289. {
  1290. xyItem = &item;
  1291. mouseDrag (e);
  1292. return;
  1293. }
  1294. if (item.type == plugui::Item::stepper)
  1295. {
  1296. const auto r = layoutRect (item);
  1297. const auto up = e.position.y < r.getY() + (item.label != nullptr ? 12.0f * layoutFactor() : 0.0f) + (r.getHeight() - (item.label != nullptr ? 12.0f * layoutFactor() : 0.0f)) * 0.5f;
  1298. k->setValue (k->getValue() + (up ? 1.0 : -1.0), juce::sendNotificationSync);
  1299. }
  1300. else if (item.type == plugui::Item::toggle)
  1301. setNormalised (*k, normalised (*k) >= 0.5f ? 0.0f : 1.0f);
  1302. else if (item.type == plugui::Item::radio)
  1303. {
  1304. const auto count = (int) plugui::optionLabels (item).size();
  1305. for (int o = 0; o < count; ++o)
  1306. if (optionCell (item, o, count).contains (e.position))
  1307. setNormalised (*k, plugui::optionValue (item, o));
  1308. }
  1309. repaint();
  1310. return;
  1311. }
  1312. }
  1313. void paint (juce::Graphics& g) override
  1314. {
  1315. g.fillAll (theme::colour::bg2);
  1316. if (layout != nullptr) // a plugin page in FL's arrangement: the plugin skin's canvas
  1317. skin::canvas (g, getLocalBounds().toFloat(), accent);
  1318. g.setColour (theme::colour::textPrimary);
  1319. g.setFont (theme::font (layout != nullptr ? theme::type::body : theme::type::title));
  1320. g.drawText (drumsynth ? tr ("DrumSynth Live — FL's engine, patch on key {0}", { juce::String (editorKey) })
  1321. + (wavesFound ? tr (" (next hit; recorded waves from your FL installation)")
  1322. : tr (" (next hit; recorded waves not found: silent)"))
  1323. : harmless ? tr ("Harmless — FL's additive engine (chorus/delay/reverb/compressor rack off)")
  1324. : harmor ? tr ("Harmor — FL's additive engine (effects rack off; image synthesis not decoded)")
  1325. : gms ? tr ("GMS — FL's engine (waves read from your FL installation)")
  1326. : morphine ? tr ("Morphine — FL's additive engine (new settings restart the voices)")
  1327. : transistorBass ? tr ("Transistor Bass — FL's engine with its sequencer and effects (oscillator cycles read from your FL installation)")
  1328. : autogun ? tr ("Autogun — FL's engine with its effects and Magic Dust (SG.dat read from your FL installation)")
  1329. : ogun ? tr ("Ogun — FL's engine with its effects (Seed 2 Random is a fixed draw per channel)")
  1330. : poizone ? tr ("PoiZone — FL's engine with its gate, chorus, delay and arpeggiator (new settings restart the voices)")
  1331. : miniSynth ? tr ("MiniSynth — FL's engine with its effects (wave tables read from your FL installation)")
  1332. : dx10 ? tr ("Fruity DX10 — FL's FM engine")
  1333. : kepler ? tr ("Kepler — FL's engine (LFO shape and noise read from your FL installation; new settings restart the voices)")
  1334. : fruitkick ? tr ("Fruit Kick — FL's engine (channel envelopes stepped per tick)")
  1335. : bassdrum ? tr ("BassDrum — FL's engine (table and noise samples read from your FL installation)")
  1336. : toxic ? tr ("Toxic Biohazard — FL's engine with its effects (waves read from your FL installation)")
  1337. : threeOsc ? tr ("3x Osc — FL's engine (custom wave from the channel's sample)")
  1338. : simSynth ? tr ("SimSynth — FL's engine (new settings restart the voices)")
  1339. : wasp ? tr ("Wasp — FL Studio 2026 has no 64-bit Wasp: the channel keeps its settings and stays silent, as in FL")
  1340. : flKeys ? tr ("FL Keys — FL's engine (wavetable read from your FL installation)")
  1341. : plucked ? tr ("Plucked! — FL's plucked-string engine")
  1342. : beepMap ? tr ("BeepMap — FL's engine (plays the bitmap saved with the channel)")
  1343. : sawer ? tr ("Sawer — FL's engine with its effects (oscillator cycle read from your FL installation)")
  1344. : granulizer ? tr ("Fruity Granulizer — FL's engine on the channel's sample")
  1345. : drumaxx ? tr ("Drumaxx — FL's physical drum engine (pads on their keys; patterns not played)")
  1346. : slayer ? tr ("FL Slayer — FL's engine with its effects, amp and cabinet (picks read from your FL installation; new settings restart the voices)")
  1347. : sytrus ? tr ("Sytrus — FL's engine, main settings (operators, filters and effects keep the saved patch)")
  1348. : fruityDance ? tr ("Fruity Dance — a visual plugin: it makes no sound, the channel keeps its settings")
  1349. : boobass ? tr ("BooBass — FL's engine, its sound read from your FL installation (knobs: 3-band EQ)")
  1350. : sakura ? tr ("Sakura — physical strings (FL's engine; new parameters apply to the next note)")
  1351. : tr ("Drumpad — physical drum (FL's engine; new parameters apply to the next hit)"),
  1352. 10, 6, getWidth() - 20, 20, juce::Justification::centredLeft);
  1353. if (layout != nullptr)
  1354. {
  1355. paintLayout (g);
  1356. return;
  1357. }
  1358. g.setFont (theme::font (theme::type::small));
  1359. for (const auto& k : knobs)
  1360. g.drawText (k->getName(), k->getBounds().withHeight (14).translated (0, -14), juce::Justification::centred);
  1361. }
  1362. void resized() override
  1363. {
  1364. if (sampleButton.isVisible())
  1365. sampleButton.setBounds (getWidth() - 128, 4, 120, 24);
  1366. if (layout != nullptr)
  1367. {
  1368. resizeLayout();
  1369. return;
  1370. }
  1371. constexpr int columns = 7, w = 96, h = 92;
  1372. for (std::size_t i = 0; i < knobs.size(); ++i)
  1373. knobs[i]->setBounds (12 + (int) (i % columns) * (w + 4), 46 + (int) (i / columns) * (h + 18), w, h);
  1374. }
  1375. private:
  1376. AudioEngine& engine;
  1377. ChannelRef ref;
  1378. juce::Colour accent { skin::colour::crimson }; // the plugin page's accent (ui/PluginSkin.h)
  1379. skin::Style pageStyle = skin::Style::glow; // the plugin page's automatic style (round 126)
  1380. bool sakura = true, boobass = false, drumsynth = false, harmless = false, harmor = false, gms = false, morphine = false, ogun = false, autogun = false, transistorBass = false, miniSynth = false, dx10 = false, kepler = false, poizone = false,
  1381. fruitkick = false, bassdrum = false, toxic = false, threeOsc = false, simSynth = false, wasp = false, plucked = false, beepMap = false,
  1382. sawer = false, flKeys = false, granulizer = false, drumaxx = false, slayer = false, fruityDance = false, sytrus = false, wavesFound = false;
  1383. int editorKey = 60;
  1384. std::vector<std::unique_ptr<juce::Slider>> knobs;
  1385. const plugui::Layout* layout = nullptr;
  1386. const plugui::LayoutItem* xyItem = nullptr; // the pad being dragged
  1387. juce::TextButton sampleButton; // (a Granulizer node: round 165c)
  1388. std::unique_ptr<juce::FileChooser> chooser;
  1389. };
  1390. class SettingsPanel final : public juce::Component,
  1391. private juce::ChangeListener
  1392. {
  1393. public:
  1394. SettingsPanel (AudioEngine& e, ChannelRef c)
  1395. : engine (e),
  1396. ref (std::move (c))
  1397. {
  1398. setup (pitch, pitchLabel, TR_NOOP ("Pitch"), -24.0, 24.0, 0.01, " st");
  1399. pitch.setTooltip (tr ("The sample's pitch in semitones (0.5 = 50 cents). The Piano Roll's keys play it chromatically around its root note (Misc › Root note, C5 by default); right-click the channel › Pitch... for semitones + cents"));
  1400. setup (gain, gainLabel, TR_NOOP ("Gain"), -24.0, 24.0, 0.1, " dB");
  1401. gain.textFromValueFunction = [] (double v) { return (v > 0.04 ? "+" : "") + juce::String (std::abs (v) < 0.05 ? 0.0 : v, 1) + " dB"; };
  1402. gain.valueFromTextFunction = [] (const juce::String& t) { return t.retainCharacters ("+-0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
  1403. gain.setTooltip (tr ("Sample gain: boosts or cuts the sample's level before the channel volume (-24 to +24 dB, double-click = 0 dB)"));
  1404. gain.setValue (0.0, juce::dontSendNotification);
  1405. setup (attack, attackLabel, TR_NOOP ("Attack"), 0.0, 2.0, 0.001, " s");
  1406. setup (release, releaseLabel, TR_NOOP ("Release"), 0.0, 4.0, 0.001, " s");
  1407. setup (decay, decayLabel, TR_NOOP ("Decay"), 0.0, 10.0, 0.001, " s");
  1408. setup (sustain, sustainLabel, TR_NOOP ("Sustain"), 0.0, 1.0, 0.01, "");
  1409. setup (stretch, stretchLabel, TR_NOOP ("Stretch"), 0.0, 64.0, 0.25, " beats");
  1410. setup (regionStart, regionStartLabel, TR_NOOP ("Start"), 0.0, 1.0, 0.001, "");
  1411. setup (regionEnd, regionEndLabel, TR_NOOP ("End"), 0.0, 1.0, 0.001, "");
  1412. setup (cutoff, cutoffLabel, TR_NOOP ("Cutoff"), 20.0, 20000.0, 1.0, " Hz");
  1413. setup (resonance, resonanceLabel, TR_NOOP ("Resonance"), 0.0, 1.0, 0.01, "");
  1414. cutoff.setSkewFactorFromMidPoint (1000.0);
  1415. cutoff.setDoubleClickReturnValue (true, 20000.0);
  1416. cutoff.setTooltip (tr ("Channel filter cutoff (low-pass at maximum with no resonance = off)"));
  1417. filterType.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
  1418. filterType.onChange = [this] { apply(); };
  1419. addAndMakeVisible (filterType);
  1420. modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
  1421. modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
  1422. addAndMakeVisible (modulationButton);
  1423. regionEnd.setDoubleClickReturnValue (true, 1.0);
  1424. regionStart.setTooltip (tr ("Where the sample starts playing (fraction of the file)"));
  1425. sustain.setDoubleClickReturnValue (true, 1.0);
  1426. decay.setSkewFactorFromMidPoint (0.5);
  1427. stretch.setTooltip (tr ("0 = off. Otherwise the whole sample lasts this many beats and follows the BPM (by resampling, like FL's Resample mode)"));
  1428. attack.setSkewFactorFromMidPoint (0.2);
  1429. release.setSkewFactorFromMidPoint (0.4);
  1430. release.setTooltip (tr ("0 = the whole sample plays (one-shot), like FL's steps"));
  1431. keepPitch.setButtonText (tr ("Keep length (stretch engine)"));
  1432. keepPitch.setTooltip (tr ("On: the pitch, the fine tune and the keys change the pitch without changing the length, and \"Stretch\" changes the length without changing the pitch (like FL's Stretch modes). Off: resample, pitch and speed change together"));
  1433. keepPitch.onClick = [this] { apply(); };
  1434. addAndMakeVisible (keepPitch);
  1435. stretchMethod.addItem (tr ("General"), 1);
  1436. stretchMethod.addItem (tr ("Drums / transients"), 2);
  1437. stretchMethod.addItem (tr ("Vocal / mono"), 3);
  1438. stretchMethod.setTooltip (tr ("How the stretch keeping pitch is computed: General for full mixes and chords, Drums for loops and percussive sounds (attacks kept sharp), Vocal for a single voice or instrument"));
  1439. stretchMethod.onChange = [this] { apply(); };
  1440. addAndMakeVisible (stretchMethod);
  1441. reverse.setButtonText (tr ("Reverse"));
  1442. cut.setButtonText (tr ("Cut itself"));
  1443. porta.setButtonText ("Porta");
  1444. porta.setTooltip (tr ("Portamento: the note starts from the previous note's pitch (with Cut itself, the 808 glide)"));
  1445. cut.setTooltip (tr ("A new note cuts the previous one (good for hi-hats and 808s)"));
  1446. for (auto* b : { &reverse, &cut, &porta })
  1447. {
  1448. addAndMakeVisible (b);
  1449. b->onClick = [this] { apply(); };
  1450. }
  1451. wave.setEmptyText (tr ("No sample loaded"));
  1452. wave.setTooltip (tr ("The sample: colours show where it is bass-heavy (warm) or bright (cool); outside Start/End is dimmed"));
  1453. addAndMakeVisible (wave);
  1454. refresh();
  1455. engine.addChangeListener (this);
  1456. setSize (420, 676);
  1457. }
  1458. ~SettingsPanel() override { engine.removeChangeListener (this); }
  1459. void resized() override
  1460. {
  1461. auto area = getLocalBounds().reduced (12);
  1462. wave.setBounds (area.removeFromTop (92));
  1463. area.removeFromTop (8);
  1464. auto place = [] (juce::Rectangle<int> row, std::initializer_list<std::pair<juce::Slider*, juce::Label*>> items) {
  1465. const auto w = row.getWidth() / 3;
  1466. for (auto [slider, label] : items)
  1467. {
  1468. auto column = row.removeFromLeft (w);
  1469. label->setBounds (column.removeFromTop (18));
  1470. slider->setBounds (column);
  1471. }
  1472. };
  1473. auto top = area.removeFromTop (110);
  1474. {
  1475. // Gain, Pitch, Stretch and the keep-pitch switch in four columns
  1476. const auto w4 = top.getWidth() / 4;
  1477. for (auto [slider, label] : { std::pair { &gain, &gainLabel }, { &pitch, &pitchLabel }, { &stretch, &stretchLabel } })
  1478. {
  1479. auto column = top.removeFromLeft (w4);
  1480. label->setBounds (column.removeFromTop (18));
  1481. slider->setBounds (column);
  1482. }
  1483. auto column = top.withSizeKeepingCentre (juce::jmin (top.getWidth(), 140), juce::jmin (top.getHeight(), 64));
  1484. keepPitch.setBounds (column.removeFromTop (column.getHeight() / 2));
  1485. stretchMethod.setBounds (column.withSizeKeepingCentre (column.getWidth(), juce::jmin (column.getHeight(), 24)));
  1486. }
  1487. area.removeFromTop (6);
  1488. auto envelope = area.removeFromTop (110);
  1489. const auto w = envelope.getWidth() / 4;
  1490. for (auto [slider, label] : { std::pair { &attack, &attackLabel }, { &decay, &decayLabel }, { &sustain, &sustainLabel }, { &release, &releaseLabel } })
  1491. {
  1492. auto column = envelope.removeFromLeft (w);
  1493. label->setBounds (column.removeFromTop (18));
  1494. slider->setBounds (column);
  1495. }
  1496. area.removeFromTop (8);
  1497. area.removeFromTop (6);
  1498. place (area.removeFromTop (110), { { &regionStart, &regionStartLabel }, { &regionEnd, &regionEndLabel } });
  1499. area.removeFromTop (6);
  1500. {
  1501. auto filterRow = area.removeFromTop (110);
  1502. filterType.setBounds (filterRow.removeFromRight (filterRow.getWidth() / 3).withSizeKeepingCentre (124, 24));
  1503. place (filterRow.withWidth (filterRow.getWidth() * 3 / 2), { { &cutoff, &cutoffLabel }, { &resonance, &resonanceLabel } });
  1504. }
  1505. modulationButton.setBounds (area.removeFromBottom (26).withSizeKeepingCentre (260, 26));
  1506. area.removeFromTop (6);
  1507. reverse.setBounds (area.removeFromLeft (150).removeFromTop (24));
  1508. cut.setBounds (area.removeFromLeft (130).removeFromTop (24));
  1509. porta.setBounds (area.removeFromLeft (100).removeFromTop (24));
  1510. }
  1511. int getChannel() const noexcept { return ref.index; }
  1512. private:
  1513. void setup (juce::Slider& s, juce::Label& label, const char* name, double lo, double hi, double step, const char* suffix)
  1514. {
  1515. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  1516. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 70, 18);
  1517. s.setRange (lo, hi, step);
  1518. s.setTextValueSuffix (suffix);
  1519. s.setDoubleClickReturnValue (true, 0.0);
  1520. s.onValueChange = [this] { apply(); };
  1521. label.setText (tr (name), juce::dontSendNotification);
  1522. label.setJustificationType (juce::Justification::centred);
  1523. addAndMakeVisible (s);
  1524. addAndMakeVisible (label);
  1525. }
  1526. const ChannelDef* current() const
  1527. {
  1528. return ref.get (engine);
  1529. }
  1530. void refresh()
  1531. {
  1532. if (const auto* c = current())
  1533. {
  1534. updating = true;
  1535. pitch.setValue (c->sampler.pitch, juce::dontSendNotification);
  1536. gain.setValue (c->sampler.gainDb, juce::dontSendNotification);
  1537. attack.setValue (c->sampler.attack, juce::dontSendNotification);
  1538. decay.setValue (c->sampler.decay, juce::dontSendNotification);
  1539. sustain.setValue (c->sampler.sustain, juce::dontSendNotification);
  1540. stretch.setValue (c->sampler.stretchBeats, juce::dontSendNotification);
  1541. keepPitch.setToggleState (c->sampler.keepPitch, juce::dontSendNotification);
  1542. stretchMethod.setSelectedId ((int) c->sampler.stretchMethod + 1, juce::dontSendNotification);
  1543. stretchMethod.setEnabled (c->sampler.keepPitch);
  1544. regionStart.setValue (c->sampler.regionStart, juce::dontSendNotification);
  1545. regionEnd.setValue (c->sampler.regionEnd, juce::dontSendNotification);
  1546. cutoff.setValue (c->sampler.cutoff, juce::dontSendNotification);
  1547. resonance.setValue (c->sampler.resonance, juce::dontSendNotification);
  1548. filterType.setSelectedId (c->sampler.filterType + 1, juce::dontSendNotification);
  1549. release.setValue (c->sampler.release, juce::dontSendNotification);
  1550. reverse.setToggleState (c->sampler.reverse, juce::dontSendNotification);
  1551. cut.setToggleState (c->sampler.cut, juce::dontSendNotification);
  1552. porta.setToggleState (c->sampler.porta, juce::dontSendNotification);
  1553. updating = false;
  1554. const auto path = juce::String::fromUTF8 ((c->samplePath.empty() && ! c->zones.empty() ? c->zones.front().path : c->samplePath).c_str());
  1555. wave.setFile (path, [&e = engine, path] { return e.getSampleLibrary().load (path); });
  1556. wave.setRegion (c->sampler.regionStart, c->sampler.regionEnd);
  1557. wave.setReversed (c->sampler.reverse);
  1558. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  1559. w->setName (tr ("Sampler settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) })
  1560. + (c->zones.empty() ? juce::String() : tr (" (multi-sample: {0} zones)", { juce::String ((int) c->zones.size()) })));
  1561. }
  1562. }
  1563. void apply()
  1564. {
  1565. if (updating || current() == nullptr)
  1566. return;
  1567. auto s = current()->sampler; // keeps what the panel does not show (slices)
  1568. s.pitch = (float) pitch.getValue();
  1569. s.gainDb = std::abs (gain.getValue()) < 0.05 ? 0.0f : (float) gain.getValue();
  1570. s.attack = (float) attack.getValue();
  1571. s.decay = (float) decay.getValue();
  1572. s.sustain = (float) sustain.getValue();
  1573. s.stretchBeats = (float) stretch.getValue();
  1574. s.keepPitch = keepPitch.getToggleState();
  1575. s.stretchMethod = (StretchMethod) juce::jlimit (0, 2, stretchMethod.getSelectedId() - 1);
  1576. stretchMethod.setEnabled (s.keepPitch);
  1577. s.regionStart = (float) regionStart.getValue();
  1578. s.regionEnd = (float) regionEnd.getValue();
  1579. s.release = (float) release.getValue();
  1580. s.reverse = reverse.getToggleState();
  1581. s.cut = cut.getToggleState();
  1582. s.porta = porta.getToggleState();
  1583. s.cutoff = (float) cutoff.getValue();
  1584. s.resonance = (float) resonance.getValue();
  1585. s.filterType = juce::jlimit (0, 3, filterType.getSelectedId() - 1);
  1586. {
  1587. // an ADSR edited by hand replaces FL's imported volume envelope
  1588. const auto& old = current()->sampler;
  1589. auto moved = [] (float a, float b) { return std::abs (a - b) > 1.0e-4f; };
  1590. const auto adsr = moved (s.attack, old.attack) || moved (s.decay, old.decay) || moved (s.sustain, old.sustain) || moved (s.release, old.release);
  1591. if (adsr)
  1592. s.flVolumeEnvelope.clear();
  1593. // so does an edited envelope or filter for FL's whole sampler voice (REA_rodada76)
  1594. if (adsr || moved (s.cutoff, old.cutoff) || moved (s.resonance, old.resonance) || s.filterType != old.filterType)
  1595. s.flChannel.clear();
  1596. }
  1597. if (s == current()->sampler)
  1598. return;
  1599. ref.edit (engine, [s] (ChannelDef& channelDef) { channelDef.sampler = s; });
  1600. }
  1601. void changeListenerCallback (juce::ChangeBroadcaster*) override
  1602. {
  1603. if (current() == nullptr) // channel removed
  1604. {
  1605. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  1606. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
  1607. if (safe != nullptr)
  1608. safe->closeButtonPressed();
  1609. });
  1610. return;
  1611. }
  1612. refresh();
  1613. }
  1614. AudioEngine& engine;
  1615. ChannelRef ref;
  1616. bool updating = false;
  1617. juce::Slider pitch, gain, attack, release, decay, sustain, stretch, regionStart, regionEnd, cutoff, resonance;
  1618. juce::Label pitchLabel, gainLabel, attackLabel, releaseLabel, decayLabel, sustainLabel, stretchLabel, regionStartLabel, regionEndLabel,
  1619. cutoffLabel, resonanceLabel;
  1620. juce::ToggleButton reverse, cut, keepPitch, porta;
  1621. juce::ComboBox filterType, stretchMethod;
  1622. juce::TextButton modulationButton;
  1623. ui::WaveformDisplay wave;
  1624. };
  1625. // Built-in synth page: 3 oscillators, envelope and filter.
  1626. class SynthPanel final : public juce::Component,
  1627. private juce::ChangeListener
  1628. {
  1629. public:
  1630. SynthPanel (AudioEngine& e, ChannelRef c)
  1631. : engine (e),
  1632. ref (std::move (c))
  1633. {
  1634. for (int o = 0; o < 3; ++o)
  1635. {
  1636. auto& row = rows[(std::size_t) o];
  1637. row.title.setText (tr ("Osc {0}", { juce::String (o + 1) }), juce::dontSendNotification);
  1638. row.wave.addItemList ({ tr ("Sine"), tr ("Triangle"), tr ("Saw"), tr ("Square"), tr ("Noise"), tr ("Harmonics") }, 1);
  1639. row.wave.onChange = [this] { apply(); };
  1640. knob (row.octave, -3.0, 3.0, 1.0, " oct");
  1641. knob (row.semitones, -11.0, 11.0, 1.0, " st");
  1642. knob (row.detune, -100.0, 100.0, 1.0, " ct");
  1643. knob (row.pan, -1.0, 1.0, 0.01, "");
  1644. knob (row.level, 0.0, 4.0, 0.01, "");
  1645. row.level.setSkewFactorFromMidPoint (1.0); // above 1: gain (Harmor goes up to +12 dB)
  1646. addAndMakeVisible (row.title);
  1647. addAndMakeVisible (row.wave);
  1648. }
  1649. knob (attack, 0.0, 5.0, 0.001, " s");
  1650. knob (decay, 0.0, 5.0, 0.001, " s");
  1651. knob (sustain, 0.0, 1.0, 0.01, "");
  1652. knob (release, 0.0, 5.0, 0.001, " s");
  1653. knob (cutoff, 20.0, 20000.0, 1.0, " Hz");
  1654. knob (resonance, 0.0, 1.0, 0.01, "");
  1655. knob (fm, 0.0, 8.0, 0.01, "");
  1656. fm.setSkewFactorFromMidPoint (1.0);
  1657. fm.setTooltip (tr ("FM: osc 3 (which stops sounding) modulates the phase of osc 1 and 2; 0 = off"));
  1658. knob (fmDecay, 0.0, 5.0, 0.001, " s");
  1659. fmDecay.setSkewFactorFromMidPoint (0.5);
  1660. fmDecay.setTooltip (tr ("Time for the FM index to decay (0 = constant); the brightness fades like an electric piano"));
  1661. knob (keyTrack, -1.0, 2.0, 0.01, "");
  1662. keyTrack.setTooltip (tr ("Cutoff follows the note: cutoff octaves per note octave, relative to C3 (130.8 Hz)"));
  1663. knob (sweep, 0.0, 100.0, 0.01, "");
  1664. sweep.setSkewFactorFromMidPoint (2.0);
  1665. sweep.setTooltip (tr ("Kick pitch sweep: the note starts (1 + value) times higher and falls"));
  1666. knob (sweepTime, 0.001, 2.0, 0.001, " s");
  1667. sweepTime.setSkewFactorFromMidPoint (0.1);
  1668. sweepTime.setTooltip (tr ("Sweep time constant"));
  1669. for (auto* b : { &bandLow, &bandMid, &bandHigh })
  1670. {
  1671. knob (*b, 0.0, 2.0, 0.01, "");
  1672. b->setTooltip (tr ("3-band tone after the filter (low < 178 Hz < mid < 1.18 kHz < high); 1 = unchanged"));
  1673. }
  1674. ring.setButtonText (tr ("Ring"));
  1675. ring.setTooltip (tr ("With AM on: ring modulation, (osc 1 + 2) × (1 − level + osc 3), like Sytrus's RM"));
  1676. ring.onClick = [this] { apply(); };
  1677. addAndMakeVisible (ring);
  1678. modulationButton.setButtonText (tr ("Modulation (envelopes and LFOs)..."));
  1679. modulationButton.onClick = [this] { showModulationFor (*this, engine, ref.index); };
  1680. addAndMakeVisible (modulationButton);
  1681. for (auto* s : { &attack, &decay, &release })
  1682. s->setSkewFactorFromMidPoint (0.5);
  1683. cutoff.setSkewFactorFromMidPoint (1000.0);
  1684. const char* names[] = { TR_NOOP ("Octave"), TR_NOOP ("Semitone"), TR_NOOP ("Fine"), TR_NOOP ("Pan"), TR_NOOP ("Level"), TR_NOOP ("Attack"), TR_NOOP ("Decay"), TR_NOOP ("Sustain"), TR_NOOP ("Release"), TR_NOOP ("Cutoff"), TR_NOOP ("Resonance"), TR_NOOP ("Porta time"), TR_NOOP ("FM"), TR_NOOP ("FM decay"),
  1685. TR_NOOP ("Keytrack"), TR_NOOP ("Sweep"), TR_NOOP ("Sweep time"), TR_NOOP ("Low"), TR_NOOP ("Mid"), TR_NOOP ("High") };
  1686. for (int i = 0; i < (int) labels.size(); ++i)
  1687. {
  1688. labels[(std::size_t) i].setText (tr (names[i]), juce::dontSendNotification);
  1689. labels[(std::size_t) i].setJustificationType (juce::Justification::centred);
  1690. labels[(std::size_t) i].setFont (theme::font (theme::type::caption));
  1691. addAndMakeVisible (labels[(std::size_t) i]);
  1692. }
  1693. presetBox.setTextWhenNothingSelected (tr ("Presets..."));
  1694. const auto presets = synthPresets();
  1695. for (int i = 0; i < (int) presets.size(); ++i)
  1696. presetBox.addItem (juce::String::fromUTF8 (presets[(std::size_t) i].first.c_str()), i + 1);
  1697. presetBox.onChange = [this] {
  1698. const auto presets = synthPresets();
  1699. const auto index = presetBox.getSelectedId() - 1;
  1700. if (juce::isPositiveAndBelow (index, (int) presets.size()) && current() != nullptr)
  1701. ref.edit (engine, [s = presets[(std::size_t) index].second] (ChannelDef& channelDef) { channelDef.synth = s; });
  1702. presetBox.setSelectedId (0, juce::dontSendNotification);
  1703. };
  1704. addAndMakeVisible (presetBox);
  1705. flPresets.setButtonText (tr ("FL presets..."));
  1706. flPresets.setTooltip (tr ("The 3x Osc channel presets that ship with FL Studio (Patches\\Channel presets\\3x Osc)"));
  1707. flPresets.onClick = [this] { showFlPresets(); };
  1708. addAndMakeVisible (flPresets);
  1709. filterTypeBox.addItemList ({ tr ("Low-pass"), tr ("Band-pass"), tr ("High-pass"), tr ("Notch") }, 1);
  1710. filterTypeBox.setTooltip (tr ("Filter type"));
  1711. filterTypeBox.onChange = [this] { apply(); };
  1712. addAndMakeVisible (filterTypeBox);
  1713. am.setButtonText ("AM");
  1714. am.setTooltip (tr ("Osc 3 modulates the amplitude of osc 1 and 2 (like 3x Osc's AM); its level is the depth"));
  1715. am.onClick = [this] { apply(); };
  1716. addAndMakeVisible (am);
  1717. knob (porta, 0.0, 2.0, 0.005, " t");
  1718. porta.setSkewFactorFromMidPoint (0.25);
  1719. porta.setTooltip (tr ("Portamento time, in beats (applies to the Porta button and to notes marked porta)"));
  1720. portaOn.setButtonText ("Porta");
  1721. portaOn.setTooltip (tr ("Portamento: the new note glides from the previous one (notes marked porta invert this)"));
  1722. portaOn.onClick = [this] { apply(); };
  1723. addAndMakeVisible (portaOn);
  1724. mono.setButtonText ("Mono");
  1725. mono.setTooltip (tr ("Single voice: the new note takes over the one currently sounding (basses and leads)"));
  1726. mono.onClick = [this] { apply(); };
  1727. addAndMakeVisible (mono);
  1728. refresh();
  1729. engine.addChangeListener (this);
  1730. setSize (720, 510);
  1731. }
  1732. ~SynthPanel() override { engine.removeChangeListener (this); }
  1733. int getChannel() const noexcept { return ref.index; }
  1734. void resized() override
  1735. {
  1736. auto area = getLocalBounds().reduced (10);
  1737. auto topRow = area.removeFromTop (24);
  1738. presetBox.setBounds (topRow.removeFromLeft (200));
  1739. mono.setBounds (topRow.removeFromLeft (90).withTrimmedLeft (16));
  1740. am.setBounds (topRow.removeFromLeft (52));
  1741. ring.setBounds (topRow.removeFromLeft (60));
  1742. flPresets.setBounds (topRow.removeFromLeft (130).reduced (4, 0));
  1743. portaOn.setBounds (topRow.removeFromLeft (70));
  1744. filterTypeBox.setBounds (topRow.removeFromRight (140));
  1745. area.removeFromTop (6);
  1746. auto header = area.removeFromTop (16);
  1747. header.removeFromLeft (150);
  1748. for (int i = 0; i < oscKnobs; ++i)
  1749. labels[(std::size_t) i].setBounds (header.removeFromLeft (88));
  1750. for (auto& row : rows)
  1751. {
  1752. auto line = area.removeFromTop (64);
  1753. row.title.setBounds (line.removeFromLeft (50).withSizeKeepingCentre (50, 24));
  1754. row.wave.setBounds (line.removeFromLeft (100).withSizeKeepingCentre (96, 24));
  1755. for (auto* s : { &row.octave, &row.semitones, &row.detune, &row.pan, &row.level })
  1756. s->setBounds (line.removeFromLeft (88));
  1757. }
  1758. area.removeFromTop (10);
  1759. auto names = area.removeFromTop (16);
  1760. const auto w = area.getWidth() / 9;
  1761. for (int i = oscKnobs; i < oscKnobs + 9; ++i)
  1762. labels[(std::size_t) i].setBounds (names.removeFromLeft (w));
  1763. auto knobsRow = area.removeFromTop (80);
  1764. for (auto* s : { &attack, &decay, &sustain, &release, &cutoff, &resonance, &porta, &fm, &fmDecay })
  1765. s->setBounds (knobsRow.removeFromLeft (w));
  1766. area.removeFromTop (6);
  1767. auto names2 = area.removeFromTop (16);
  1768. for (int i = oscKnobs + 9; i < (int) labels.size(); ++i)
  1769. labels[(std::size_t) i].setBounds (names2.removeFromLeft (w));
  1770. auto knobsRow2 = area.removeFromTop (80);
  1771. for (auto* s : { &keyTrack, &sweep, &sweepTime, &bandLow, &bandMid, &bandHigh })
  1772. s->setBounds (knobsRow2.removeFromLeft (w));
  1773. area.removeFromTop (12);
  1774. modulationButton.setBounds (area.removeFromTop (26).withSizeKeepingCentre (260, 26));
  1775. }
  1776. private:
  1777. struct Row
  1778. {
  1779. juce::Label title;
  1780. juce::ComboBox wave;
  1781. juce::Slider octave, semitones, detune, pan, level;
  1782. };
  1783. static constexpr int oscKnobs = 5; // oscillator knob labels come first
  1784. juce::TextButton modulationButton;
  1785. juce::ToggleButton mono, am, portaOn;
  1786. juce::TextButton flPresets;
  1787. // menu with the presets from the FL install for the synths LYNX converts: the 3x Osc channel .fst
  1788. // files (by letter) and, per generator, the "Plugin presets" folders (Sytrus, Harmor, GMS...)
  1789. void showFlPresets()
  1790. {
  1791. const auto roots = findFlStudioRoots();
  1792. const auto patches = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches");
  1793. auto sorted = [] (juce::Array<juce::File> files) {
  1794. std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) {
  1795. return a.getFileName().compareNatural (b.getFileName()) < 0;
  1796. });
  1797. return files;
  1798. };
  1799. juce::PopupMenu menu;
  1800. // 3x Osc: ~170 presets grouped by first letter
  1801. {
  1802. juce::PopupMenu threeOsc, sub;
  1803. juce::juce_wchar letter = 0;
  1804. for (const auto& f : sorted (patches.getChildFile ("Channel presets/3x Osc").findChildFiles (juce::File::findFiles, false, "*.fst")))
  1805. {
  1806. const auto first = juce::CharacterFunctions::toUpperCase (f.getFileName()[0]);
  1807. if (first != letter && sub.getNumItems() > 0)
  1808. {
  1809. threeOsc.addSubMenu (juce::String::charToString (letter), sub);
  1810. sub = {};
  1811. }
  1812. letter = first;
  1813. sub.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
  1814. }
  1815. if (sub.getNumItems() > 0)
  1816. threeOsc.addSubMenu (juce::String::charToString (letter), sub);
  1817. if (threeOsc.getNumItems() > 0)
  1818. menu.addSubMenu ("3x Osc", threeOsc);
  1819. }
  1820. // a preset folder as a menu: subfolders become submenus
  1821. std::function<juce::PopupMenu (const juce::File&, int)> folderMenu = [&] (const juce::File& folder, int depth) {
  1822. juce::PopupMenu m;
  1823. if (depth < 3)
  1824. for (const auto& dir : sorted (folder.findChildFiles (juce::File::findDirectories, false)))
  1825. if (auto sub = folderMenu (dir, depth + 1); sub.getNumItems() > 0)
  1826. m.addSubMenu (dir.getFileName(), sub);
  1827. for (const auto& f : sorted (folder.findChildFiles (juce::File::findFiles, false, "*.fst;*.gmsynth")))
  1828. m.addItem (f.getFileNameWithoutExtension(), [this, f] { loadFlPreset (f); });
  1829. return m;
  1830. };
  1831. const auto generators = patches.getChildFile ("Plugin presets/Generators");
  1832. for (const auto* name : { "Sytrus", "Harmor", "GMS", "Harmless", "MiniSynth", "Fruity DX10", "Fruit Kick", "Ogun", "Sakura", "Kepler",
  1833. "PoiZone", "Toxic Biohazard", "BassDrum" })
  1834. if (auto sub = folderMenu (generators.getChildFile (name), 0); sub.getNumItems() > 0)
  1835. menu.addSubMenu (name, sub);
  1836. if (menu.getNumItems() == 0)
  1837. {
  1838. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::InfoIcon, tr ("FL presets"),
  1839. tr ("FL presets not found (install FL Studio or check the Data\\Patches folder)."));
  1840. return;
  1841. }
  1842. menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&flPresets));
  1843. }
  1844. void loadFlPreset (const juce::File& file)
  1845. {
  1846. juce::MemoryBlock data;
  1847. if (! file.loadFileAsData (data) || current() == nullptr)
  1848. return;
  1849. const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
  1850. if (auto synth = synthFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize())))
  1851. ref.edit (engine, [s = *synth] (ChannelDef& channelDef) { channelDef.synth = s; });
  1852. else
  1853. juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("FL presets"),
  1854. tr ("This preset is not for a synth LYNX converts, or it could not be read."));
  1855. }
  1856. juce::Slider porta;
  1857. juce::ComboBox filterTypeBox;
  1858. void knob (juce::Slider& s, double lo, double hi, double step, const char* suffix)
  1859. {
  1860. s.setSliderStyle (juce::Slider::RotaryHorizontalVerticalDrag);
  1861. s.setTextBoxStyle (juce::Slider::TextBoxBelow, false, 64, 16);
  1862. s.setRange (lo, hi, step);
  1863. s.setTextValueSuffix (suffix);
  1864. s.onValueChange = [this] { apply(); };
  1865. addAndMakeVisible (s);
  1866. }
  1867. const ChannelDef* current() const
  1868. {
  1869. return ref.get (engine);
  1870. }
  1871. void refresh()
  1872. {
  1873. const auto* c = current();
  1874. if (c == nullptr)
  1875. return;
  1876. updating = true;
  1877. const auto& s = c->synth;
  1878. for (std::size_t o = 0; o < 3; ++o)
  1879. {
  1880. rows[o].wave.setSelectedId ((int) s.osc[o].wave + 1, juce::dontSendNotification);
  1881. rows[o].octave.setValue (s.osc[o].octave, juce::dontSendNotification);
  1882. rows[o].detune.setValue (s.osc[o].detune, juce::dontSendNotification);
  1883. rows[o].semitones.setValue (s.osc[o].semitones, juce::dontSendNotification);
  1884. rows[o].pan.setValue (s.osc[o].pan, juce::dontSendNotification);
  1885. rows[o].level.setValue (s.osc[o].level, juce::dontSendNotification);
  1886. }
  1887. attack.setValue (s.attack, juce::dontSendNotification);
  1888. decay.setValue (s.decay, juce::dontSendNotification);
  1889. sustain.setValue (s.sustain, juce::dontSendNotification);
  1890. release.setValue (s.release, juce::dontSendNotification);
  1891. cutoff.setValue (s.cutoff, juce::dontSendNotification);
  1892. resonance.setValue (s.resonance, juce::dontSendNotification);
  1893. mono.setToggleState (s.mono, juce::dontSendNotification);
  1894. am.setToggleState (s.am, juce::dontSendNotification);
  1895. porta.setValue (s.portaBeats, juce::dontSendNotification);
  1896. portaOn.setToggleState (s.porta, juce::dontSendNotification);
  1897. filterTypeBox.setSelectedId (s.filterType + 1, juce::dontSendNotification);
  1898. fm.setValue (s.fm, juce::dontSendNotification);
  1899. fmDecay.setValue (s.fmDecay, juce::dontSendNotification);
  1900. keyTrack.setValue (s.keyTrack, juce::dontSendNotification);
  1901. sweep.setValue (s.sweep, juce::dontSendNotification);
  1902. sweepTime.setValue (s.sweepTime, juce::dontSendNotification);
  1903. bandLow.setValue (s.bandGain[0], juce::dontSendNotification);
  1904. bandMid.setValue (s.bandGain[1], juce::dontSendNotification);
  1905. bandHigh.setValue (s.bandGain[2], juce::dontSendNotification);
  1906. ring.setToggleState (s.ring, juce::dontSendNotification);
  1907. updating = false;
  1908. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  1909. w->setName (tr ("Synth settings - {0}", { juce::String::fromUTF8 (c->name.c_str()) }));
  1910. }
  1911. void apply()
  1912. {
  1913. if (updating || current() == nullptr)
  1914. return;
  1915. auto s = current()->synth; // keeps what this window does not show (envelopes and LFOs)
  1916. for (std::size_t o = 0; o < 3; ++o)
  1917. s.osc[o] = { (Waveform) juce::jlimit (0, 5, rows[o].wave.getSelectedId() - 1), (int) rows[o].octave.getValue(),
  1918. (float) rows[o].detune.getValue(), (float) rows[o].level.getValue(), (int) rows[o].semitones.getValue(),
  1919. (float) rows[o].pan.getValue() };
  1920. s.attack = (float) attack.getValue();
  1921. s.decay = (float) decay.getValue();
  1922. s.sustain = (float) sustain.getValue();
  1923. s.release = (float) release.getValue();
  1924. s.cutoff = (float) cutoff.getValue();
  1925. s.resonance = (float) resonance.getValue();
  1926. s.mono = mono.getToggleState();
  1927. s.am = am.getToggleState();
  1928. s.portaBeats = (float) porta.getValue();
  1929. s.porta = portaOn.getToggleState();
  1930. s.filterType = juce::jlimit (0, 3, filterTypeBox.getSelectedId() - 1);
  1931. s.fm = (float) fm.getValue();
  1932. s.fmDecay = (float) fmDecay.getValue();
  1933. if (s.fmDecay <= 0.0f)
  1934. s.fmSustain = 1.0f;
  1935. s.keyTrack = (float) keyTrack.getValue();
  1936. s.sweep = (float) sweep.getValue();
  1937. s.sweepTime = (float) sweepTime.getValue();
  1938. s.bandGain = { (float) bandLow.getValue(), (float) bandMid.getValue(), (float) bandHigh.getValue() };
  1939. s.ring = ring.getToggleState();
  1940. if (s == current()->synth)
  1941. return;
  1942. ref.edit (engine, [s] (ChannelDef& channelDef) { channelDef.synth = s; });
  1943. }
  1944. void changeListenerCallback (juce::ChangeBroadcaster*) override
  1945. {
  1946. if (current() == nullptr)
  1947. {
  1948. if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
  1949. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::DocumentWindow> (w)] {
  1950. if (safe != nullptr)
  1951. safe->closeButtonPressed();
  1952. });
  1953. return;
  1954. }
  1955. refresh();
  1956. }
  1957. AudioEngine& engine;
  1958. ChannelRef ref;
  1959. bool updating = false;
  1960. std::array<Row, 3> rows;
  1961. juce::Slider attack, decay, sustain, release, cutoff, resonance, fm, fmDecay, keyTrack, sweep, sweepTime, bandLow, bandMid, bandHigh;
  1962. juce::ToggleButton ring;
  1963. std::array<juce::Label, 20> labels;
  1964. juce::ComboBox presetBox;
  1965. };
  1966. // --- FL's channel window frame (REA round 143b) --------------------------------------------------------------
  1967. // FL 2026 draws every channel's settings window the same way: a header strip with the channel's tabs on the left
  1968. // (the instrument / plugin page, the wrench "Miscellaneous functions" page) and ON, PAN, VOL and TRACK on the right
  1969. // [EXEC: FL 2026 build 5654, "Detailed settings" of a generator and of a sampler]. LYNX does the same around its own
  1970. // instrument pages, in its own style; the envelopes and LFOs of the synth and the sampler are the "Envelope /
  1971. // instrument" tab instead of a second window.
  1972. // A small rotary control with LYNX's control contract (drag, Ctrl = fine, wheel, Alt / middle-click / double-click
  1973. // reset, right-click menu with automation items when the spec has a target); the hint bar shows its name and value.
  1974. class FrameKnob final : public juce::Component,
  1975. public ui::HintSource
  1976. {
  1977. public:
  1978. FrameKnob (AudioEngine& e, std::function<ui::ValueSpec()> makeSpec, std::function<double()> get, std::function<void (double)> set,
  1979. juce::String caption)
  1980. : engine (e), specOf (std::move (makeSpec)), getter (std::move (get)), setter (std::move (set)), label (std::move (caption))
  1981. {
  1982. setRepaintsOnMouseActivity (true);
  1983. }
  1984. ui::Hint hintAt (juce::Point<int>) override { return ui::valueHint (specOf(), getter(), ui::valueGestures()); }
  1985. void paint (juce::Graphics& g) override
  1986. {
  1987. const auto spec = specOf();
  1988. auto area = getLocalBounds().toFloat();
  1989. const auto caption = area.removeFromBottom (13.0f);
  1990. const auto valueArea = area.removeFromBottom (13.0f);
  1991. const auto size = juce::jmin (area.getWidth(), area.getHeight());
  1992. const auto v = (float) juce::jlimit (0.0, 1.0, (getter() - spec.minimum) / juce::jmax (1e-9, spec.maximum - spec.minimum));
  1993. theme::drawKnob (g, juce::Rectangle<float> (size, size).withCentre (area.getCentre()), v, spec.minimum < 0.0,
  1994. isMouseOverOrDragging() ? theme::colour::accent : theme::colour::knobArc, isMouseOver());
  1995. g.setFont (theme::font (theme::type::caption));
  1996. g.setColour (theme::colour::textPrimary);
  1997. g.drawText (spec.text (getter()), valueArea, juce::Justification::centred);
  1998. g.setColour (theme::colour::textSecondary);
  1999. g.drawText (theme::caps (label), caption, juce::Justification::centred);
  2000. }
  2001. void mouseDown (const juce::MouseEvent& e) override
  2002. {
  2003. if (e.mods.isPopupMenu())
  2004. {
  2005. ui::showValueMenu (*this, &engine, specOf(), getter(), setter);
  2006. return;
  2007. }
  2008. if (ui::isResetClick (e))
  2009. {
  2010. setter (specOf().defaultValue);
  2011. repaint();
  2012. return;
  2013. }
  2014. drag.begin (e, getter());
  2015. }
  2016. void mouseDrag (const juce::MouseEvent& e) override
  2017. {
  2018. if (! drag.isActive())
  2019. return;
  2020. const auto spec = specOf();
  2021. setter (drag.update (e, spec));
  2022. ui::showValueTip (*this, getLocalBounds(), spec.text (getter()));
  2023. repaint();
  2024. }
  2025. void mouseUp (const juce::MouseEvent&) override
  2026. {
  2027. drag.end();
  2028. ui::hideValueTip();
  2029. }
  2030. void mouseDoubleClick (const juce::MouseEvent&) override
  2031. {
  2032. setter (specOf().defaultValue);
  2033. repaint();
  2034. }
  2035. void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
  2036. {
  2037. if (const auto v = ui::wheelValue (getter(), e, wheel, specOf()))
  2038. {
  2039. setter (*v);
  2040. ui::flashValueTip (*this, getLocalBounds(), specOf().text (getter()));
  2041. repaint();
  2042. }
  2043. }
  2044. private:
  2045. AudioEngine& engine;
  2046. std::function<ui::ValueSpec()> specOf;
  2047. std::function<double()> getter;
  2048. std::function<void (double)> setter;
  2049. juce::String label;
  2050. ui::ValueDrag drag;
  2051. };
  2052. juce::String channelNameOf (const Song& song, int channel)
  2053. {
  2054. if (channel < 0 || channel >= (int) song.channels.size())
  2055. return "?";
  2056. const auto& n = song.channels[(std::size_t) channel].name;
  2057. return n.empty() ? tr ("Channel {0}", { juce::String (channel + 1) }) : juce::String::fromUTF8 (n.c_str());
  2058. }
  2059. // An integer spec shown as a number, 0 as "--" (FL's empty number boxes).
  2060. ui::ValueSpec countSpec (const juce::String& name, int maximum, int defaultValue, std::function<juce::String (int)> text = {})
  2061. {
  2062. ui::ValueSpec spec;
  2063. spec.name = name;
  2064. spec.maximum = maximum;
  2065. spec.defaultValue = defaultValue;
  2066. spec.interval = 1.0;
  2067. spec.pixelsForRange = juce::jlimit (60.0, 400.0, 5.0 * maximum);
  2068. spec.toText = [text] (double v) {
  2069. const auto i = juce::roundToInt (v);
  2070. if (text)
  2071. return text (i);
  2072. return i == 0 ? juce::String ("--") : juce::String (i);
  2073. };
  2074. spec.fromText = [] (const juce::String& t) -> std::optional<double> {
  2075. const auto digits = t.retainCharacters ("0123456789");
  2076. return digits.isEmpty() ? std::optional<double> (0.0) : std::optional<double> (digits.getDoubleValue());
  2077. };
  2078. return spec;
  2079. }
  2080. // The wrench tab: FL's "Miscellaneous functions" with what LYNX's channels have (Levels, Polyphony, Time, Group,
  2081. // Arpeggiator).
  2082. // FL's Root note keyboard (Misc tab, REA round 149): every key 0…127 (C0…G10, C5 = 60), the channel's root marked;
  2083. // a click sets it. LYNX's own drawing.
  2084. class RootKeyboard final : public juce::Component, public juce::SettableTooltipClient
  2085. {
  2086. public:
  2087. std::function<void (int)> onPick;
  2088. // FL's key region ruler (round 164): a drag on the strip above the keys sets the notes the channel plays,
  2089. // a double-click there gives it the whole keyboard back
  2090. std::function<void (int, int)> onRegion;
  2091. void setRoot (int key)
  2092. {
  2093. root = key;
  2094. repaint();
  2095. }
  2096. void setRegion (int low, int high)
  2097. {
  2098. if (low != regionLow || high != regionHigh)
  2099. {
  2100. regionLow = low;
  2101. regionHigh = high;
  2102. repaint();
  2103. }
  2104. }
  2105. void paint (juce::Graphics& g) override
  2106. {
  2107. using namespace theme;
  2108. const auto w = whiteWidth();
  2109. const auto top = (float) rulerHeight();
  2110. const auto keysH = (float) getHeight() - top;
  2111. if (onRegion)
  2112. {
  2113. const auto ruler = juce::Rectangle<float> (0.0f, 0.0f, (float) getWidth(), top - 2.0f);
  2114. g.setColour (colour::bg0);
  2115. g.fillRect (ruler);
  2116. const auto full = regionLow <= 0 && regionHigh >= 127;
  2117. const auto x0 = keyLeft (regionLow), x1 = keyRight (regionHigh);
  2118. g.setColour (full ? colour::bg5 : colour::accent);
  2119. g.fillRect (juce::Rectangle<float> (x0, 1.0f, juce::jmax (2.0f, x1 - x0), ruler.getHeight() - 2.0f));
  2120. }
  2121. for (int k = 0, white = 0; k < 128; ++k)
  2122. if (! isBlack (k))
  2123. {
  2124. const auto r = juce::Rectangle<float> ((float) (white++) * w, top, w - 1.0f, keysH);
  2125. const auto outside = onRegion && (k < regionLow || k > regionHigh);
  2126. g.setColour (k == root ? colour::accent : k == hover ? juce::Colour (0xffc8ccd4) : outside ? juce::Colour (0xff9a9ea8) : juce::Colour (0xffe6e8ec));
  2127. g.fillRect (r);
  2128. if (k % 12 == 0 && w * 7.0f >= 14.0f) // the octave's C named (FL's C5 = 60)
  2129. {
  2130. g.setColour (k == root ? colour::onAccent : juce::Colour (0xff5a5f6a));
  2131. g.setFont (font (8.5f));
  2132. g.drawText ("C" + juce::String (k / 12), r.withTrimmedTop (r.getHeight() - 11.0f).expanded (6.0f, 0.0f).toNearestInt(),
  2133. juce::Justification::centred);
  2134. }
  2135. }
  2136. for (int k = 0; k < 128; ++k)
  2137. if (isBlack (k))
  2138. {
  2139. const auto x = (float) whitesBefore (k) * w - w * 0.32f;
  2140. g.setColour (k == root ? colour::accent : k == hover ? colour::bg5 : colour::bg0);
  2141. g.fillRect (juce::Rectangle<float> (x, top, w * 0.64f, keysH * 0.6f));
  2142. }
  2143. }
  2144. void mouseMove (const juce::MouseEvent& e) override
  2145. {
  2146. const auto onRuler = onRegion && e.position.y < (float) rulerHeight();
  2147. if (const auto k = keyAt (e.position); k != hover || onRuler != hoverRuler)
  2148. {
  2149. hover = k;
  2150. hoverRuler = onRuler;
  2151. if (onRuler)
  2152. setTooltip (tr ("Key region: {0} to {1} (drag to set, double-click for the whole keyboard)",
  2153. { keyName (regionLow), keyName (regionHigh) }));
  2154. else
  2155. setTooltip (k >= 0 ? tr ("Root note: {0}", { keyName (k) }) : juce::String());
  2156. repaint();
  2157. }
  2158. }
  2159. void mouseExit (const juce::MouseEvent&) override
  2160. {
  2161. hover = -1;
  2162. repaint();
  2163. }
  2164. void mouseDown (const juce::MouseEvent& e) override
  2165. {
  2166. dragFrom = -1;
  2167. if (onRegion && e.position.y < (float) rulerHeight())
  2168. {
  2169. dragFrom = keyAtX (e.position.x);
  2170. if (dragFrom >= 0)
  2171. onRegion (dragFrom, dragFrom);
  2172. return;
  2173. }
  2174. if (const auto k = keyAt (e.position); k >= 0 && onPick)
  2175. onPick (k);
  2176. }
  2177. void mouseDrag (const juce::MouseEvent& e) override
  2178. {
  2179. if (dragFrom < 0 || ! onRegion)
  2180. return;
  2181. const auto k = keyAtX (e.position.x);
  2182. if (k >= 0)
  2183. onRegion (juce::jmin (dragFrom, k), juce::jmax (dragFrom, k));
  2184. }
  2185. void mouseDoubleClick (const juce::MouseEvent& e) override
  2186. {
  2187. if (onRegion && e.position.y < (float) rulerHeight())
  2188. onRegion (0, 127);
  2189. }
  2190. static juce::String keyName (int key)
  2191. {
  2192. return juce::String (notenames::keyName (key)); // Settings › General › Note names (round 165f)
  2193. }
  2194. private:
  2195. static bool isBlack (int k) noexcept
  2196. {
  2197. const auto n = k % 12;
  2198. return n == 1 || n == 3 || n == 6 || n == 8 || n == 10;
  2199. }
  2200. static int whitesBefore (int k) noexcept
  2201. {
  2202. int count = 0;
  2203. for (int i = 0; i < k; ++i)
  2204. count += isBlack (i) ? 0 : 1;
  2205. return count;
  2206. }
  2207. int rulerHeight() const noexcept { return onRegion ? 9 : 0; }
  2208. float whiteWidth() const noexcept { return (float) getWidth() / 75.0f; } // 75 white keys in 0…127
  2209. float keyLeft (int k) const noexcept
  2210. {
  2211. const auto w = whiteWidth();
  2212. return isBlack (k) ? (float) whitesBefore (k) * w - w * 0.32f : (float) whitesBefore (k) * w;
  2213. }
  2214. float keyRight (int k) const noexcept
  2215. {
  2216. const auto w = whiteWidth();
  2217. return isBlack (k) ? keyLeft (k) + w * 0.64f : keyLeft (k) + w;
  2218. }
  2219. // the key under x on the ruler (each key owns its own horizontal span; black keys win where they overlap)
  2220. int keyAtX (float x) const noexcept
  2221. {
  2222. for (int k = 0; k < 128; ++k)
  2223. if (isBlack (k) && x >= keyLeft (k) && x < keyRight (k))
  2224. return k;
  2225. const auto white = (int) std::floor (x / whiteWidth());
  2226. for (int k = 0, n = 0; k < 128; ++k)
  2227. if (! isBlack (k) && n++ == white)
  2228. return k;
  2229. return x < 0.0f ? 0 : 127;
  2230. }
  2231. int keyAt (juce::Point<float> p) const noexcept
  2232. {
  2233. const auto w = whiteWidth();
  2234. const auto top = (float) rulerHeight();
  2235. if (p.y < top)
  2236. return keyAtX (p.x);
  2237. if (p.y < top + ((float) getHeight() - top) * 0.6f)
  2238. for (int k = 0; k < 128; ++k)
  2239. if (isBlack (k))
  2240. {
  2241. const auto x = (float) whitesBefore (k) * w - w * 0.32f;
  2242. if (p.x >= x && p.x < x + w * 0.64f)
  2243. return k;
  2244. }
  2245. const auto white = (int) std::floor (p.x / w);
  2246. for (int k = 0, n = 0; k < 128; ++k)
  2247. if (! isBlack (k) && n++ == white)
  2248. return k;
  2249. return -1;
  2250. }
  2251. int root = 60, hover = -1, dragFrom = -1;
  2252. int regionLow = 0, regionHigh = 127;
  2253. bool hoverRuler = false;
  2254. };
  2255. class MiscPanel final : public juce::Component,
  2256. private juce::ChangeListener
  2257. {
  2258. public:
  2259. static constexpr int preferredWidth = 800, preferredHeight = 360;
  2260. MiscPanel (AudioEngine& e, int c) : engine (e), channel (c)
  2261. {
  2262. const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
  2263. auto knob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get,
  2264. std::function<void (ChannelDef&, double)> set, const char* caption) {
  2265. auto k = std::make_unique<FrameKnob> (
  2266. engine, std::move (spec), [this, get] { return current() != nullptr ? get (*current()) : 0.0; },
  2267. [this, set] (double v) {
  2268. if (current() == nullptr)
  2269. return;
  2270. engine.editSong ([ch = channel, set, v] (Song& s) {
  2271. if (ch < (int) s.channels.size())
  2272. set (s.channels[(std::size_t) ch], v);
  2273. });
  2274. },
  2275. tr (caption));
  2276. addAndMakeVisible (*k);
  2277. knobs.push_back (std::move (k));
  2278. return knobs.back().get();
  2279. };
  2280. // Levels adjustment
  2281. pan = knob ([this, name] {
  2282. auto s = ui::panSpec (name() + " - " + tr ("Pan"));
  2283. s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
  2284. return s;
  2285. },
  2286. [] (const ChannelDef& d) { return (double) d.pan; }, [] (ChannelDef& d, double v) { d.pan = (float) v; }, TR_NOOP ("Pan"));
  2287. volume = knob ([this, name] {
  2288. auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
  2289. s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
  2290. return s;
  2291. },
  2292. [] (const ChannelDef& d) { return (double) d.volume; }, [] (ChannelDef& d, double v) { d.volume = (float) v; },
  2293. TR_NOOP ("Vol"));
  2294. // Polyphony
  2295. maxPoly = knob ([name] { return countSpec (name() + " - " + tr ("Maximum polyphony (-- = no limit)"), 64, 0); },
  2296. [] (const ChannelDef& d) { return (double) d.maxPolyphony; },
  2297. [] (ChannelDef& d, double v) { d.maxPolyphony = juce::jlimit (0, 64, juce::roundToInt (v)); }, TR_NOOP ("Max"));
  2298. slide = knob (
  2299. [name] {
  2300. ui::ValueSpec s;
  2301. s.name = name() + " - " + tr ("Portamento time");
  2302. s.maximum = 2.0;
  2303. s.defaultValue = 0.125;
  2304. s.toText = [] (double v) { return tr ("{0} beats", { juce::String (v, 3) }); };
  2305. s.fromText = [] (const juce::String& t) -> std::optional<double> { return t.retainCharacters ("0123456789.,").replaceCharacter (',', '.').getDoubleValue(); };
  2306. return s;
  2307. },
  2308. [] (const ChannelDef& d) { return (double) channelPortamentoBeats (d); },
  2309. [] (ChannelDef& d, double v) { setChannelPortamento (d, channelPortamento (d), (float) v); }, TR_NOOP ("Slide"));
  2310. porta.setButtonText (tr ("Porta"));
  2311. porta.setTooltip (tr ("Portamento: each note glides from the previous one's pitch (the Slide knob sets the time)"));
  2312. porta.onClick = [this] { edit ([on = porta.getToggleState()] (ChannelDef& d) { setChannelPortamento (d, on, channelPortamentoBeats (d)); }); };
  2313. mono.setButtonText (tr ("Mono"));
  2314. mono.setTooltip (tr ("Mono: one voice; a new note takes over the sounding one"));
  2315. mono.onClick = [this] { edit ([on = mono.getToggleState()] (ChannelDef& d) { setChannelMono (d, on); }); };
  2316. // Time
  2317. swing = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Swing mix"), 1.0); },
  2318. [] (const ChannelDef& d) { return (double) d.swingMix; }, [] (ChannelDef& d, double v) { d.swingMix = (float) v; },
  2319. TR_NOOP ("Swing"));
  2320. // Levels adjustment: Mod X / Mod Y = the channel filter's cutoff / resonance (sampler, synth)
  2321. modX = knob ([name] {
  2322. ui::ValueSpec s;
  2323. s.name = name() + " - " + tr ("Mod X (filter cutoff)");
  2324. s.defaultValue = 1.0;
  2325. s.toText = [] (double v) { const auto hz = 20.0 * std::pow (1000.0, v); return hz >= 1000.0 ? juce::String (hz / 1000.0, 1) + " kHz" : juce::String (juce::roundToInt (hz)) + " Hz"; };
  2326. return s;
  2327. },
  2328. [] (const ChannelDef& d) {
  2329. const auto hz = d.instrument == InstrumentKind::synth ? d.synth.cutoff : d.sampler.cutoff;
  2330. return juce::jlimit (0.0, 1.0, std::log ((double) hz / 20.0) / std::log (1000.0));
  2331. },
  2332. [] (ChannelDef& d, double v) {
  2333. const auto hz = (float) (20.0 * std::pow (1000.0, v));
  2334. if (d.instrument == InstrumentKind::synth)
  2335. d.synth.cutoff = hz;
  2336. else if (d.instrument == InstrumentKind::sampler)
  2337. {
  2338. d.sampler.cutoff = hz;
  2339. d.sampler.flChannel.clear(); // an edited filter replaces FL's whole sampler voice (REA_rodada76)
  2340. }
  2341. },
  2342. TR_NOOP ("Mod X"));
  2343. modY = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Mod Y (filter resonance)"), 0.0); },
  2344. [] (const ChannelDef& d) { return (double) (d.instrument == InstrumentKind::synth ? d.synth.resonance : d.sampler.resonance); },
  2345. [] (ChannelDef& d, double v) {
  2346. if (d.instrument == InstrumentKind::synth)
  2347. d.synth.resonance = (float) v;
  2348. else if (d.instrument == InstrumentKind::sampler)
  2349. {
  2350. d.sampler.resonance = (float) v;
  2351. d.sampler.flChannel.clear();
  2352. }
  2353. },
  2354. TR_NOOP ("Mod Y"));
  2355. // Time: Gate and Shift on FL's time-knob scale (REA round 146b)
  2356. auto timeSpec = [name] (const char* what, int maximum, int defaultValue, bool offAtMax) {
  2357. ui::ValueSpec s;
  2358. s.name = name() + " - " + tr (what);
  2359. s.maximum = maximum;
  2360. s.defaultValue = defaultValue;
  2361. s.interval = 1.0;
  2362. s.pixelsForRange = 300.0;
  2363. s.toText = [maximum, offAtMax] (double v) {
  2364. const auto i = juce::roundToInt (v);
  2365. if (offAtMax && i >= maximum)
  2366. return tr ("Off");
  2367. // steps:ticks, as FL shows them (24 ticks per step)
  2368. const auto ticks = juce::roundToInt (channelmisc::flTimeKnobBeats (i) * 96.0);
  2369. return juce::String (ticks / 24) + ":" + juce::String (ticks % 24).paddedLeft ('0', 2);
  2370. };
  2371. return s;
  2372. };
  2373. timeGate = knob ([timeSpec] { return timeSpec (TR_NOOP ("Gate: long notes are cut to this length (Off = no limit)"), 1446, 1446, true); },
  2374. [] (const ChannelDef& d) { return d.misc.gateBeats > 0.0f ? (double) channelmisc::flTimeKnobValue (d.misc.gateBeats) : 1446.0; },
  2375. [] (ChannelDef& d, double v) {
  2376. const auto i = juce::roundToInt (v);
  2377. d.misc.gateBeats = i >= 1446 ? 0.0f : (float) std::max (1.0 / 96.0, channelmisc::flTimeKnobBeats (i));
  2378. },
  2379. TR_NOOP ("Gate"));
  2380. timeShift = knob ([timeSpec] { return timeSpec (TR_NOOP ("Fine time shift: delays the notes, up to one step"), 1024, 0, false); },
  2381. [] (const ChannelDef& d) { return (double) channelmisc::flTimeKnobValue (d.misc.shiftBeats); },
  2382. [] (ChannelDef& d, double v) { d.misc.shiftBeats = (float) channelmisc::flTimeKnobBeats (juce::roundToInt (v)); },
  2383. TR_NOOP ("Shift"));
  2384. fullPorta.setButtonText (tr ("Full porta"));
  2385. fullPorta.setTooltip (tr ("Full porta: portamento notes ignore the Gate and play their whole length"));
  2386. fullPorta.onClick = [this] { edit ([on = fullPorta.getToggleState()] (ChannelDef& d) { d.misc.fullPorta = on; }); };
  2387. // Vol / Key tracking
  2388. trackVol.setButtonText (tr ("Vol"));
  2389. trackKey.setButtonText (tr ("Key"));
  2390. for (auto* b : { &trackVol, &trackKey })
  2391. {
  2392. b->setClickingTogglesState (true);
  2393. b->setRadioGroupId (146);
  2394. b->onClick = [this] { repaint(); for (auto& k : knobs) k->repaint(); };
  2395. addAndMakeVisible (b);
  2396. }
  2397. trackVol.setTooltip (tr ("Velocity tracking: the note's velocity moves its pan"));
  2398. trackKey.setTooltip (tr ("Keyboard tracking: the note's key moves its pan"));
  2399. trackKey.setToggleState (true, juce::dontSendNotification);
  2400. auto tracking = [this] (ChannelDef& d) -> NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
  2401. auto trackingOf = [this] (const ChannelDef& d) -> const NoteTracking& { return trackKey.getToggleState() ? d.misc.key : d.misc.velocity; };
  2402. trackPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: pan")); },
  2403. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).pan; },
  2404. [tracking] (ChannelDef& d, double v) { tracking (d).pan = (float) v; }, TR_NOOP ("Pan"));
  2405. trackMid = knob ([this, name] {
  2406. const auto key = trackKey.getToggleState();
  2407. auto s = countSpec (name() + " - " + tr ("Tracking: the middle value (no offset)"), key ? 131 : 128, key ? 60 : 100,
  2408. [key] (int v) { return key ? juce::MidiMessage::getMidiNoteName (120 - v, true, true, 5) : juce::String (v); }); // FL: C5 = 60
  2409. return s;
  2410. },
  2411. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).mid; },
  2412. [tracking] (ChannelDef& d, double v) { tracking (d).mid = juce::roundToInt (v); }, TR_NOOP ("Mid"));
  2413. // FL's tracking Mod X / Y (round 151): the notes' Mod X / Y follow the velocity / key like their pan
  2414. trackModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod X (the note's filter cutoff / a plugin's MOD X)")); },
  2415. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modX; },
  2416. [tracking] (ChannelDef& d, double v) { tracking (d).modX = (float) v; }, TR_NOOP ("Mod X"));
  2417. trackModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Tracking: Mod Y (the note's filter resonance)")); },
  2418. [trackingOf] (const ChannelDef& d) { return (double) trackingOf (d).modY; },
  2419. [tracking] (ChannelDef& d, double v) { tracking (d).modY = (float) v; }, TR_NOOP ("Mod Y"));
  2420. // Echo delay / fat mode
  2421. echoFeed = knob ([name] { return ui::percentSpec (name() + " - " + tr ("Delay feedback (100% = the echoes as loud as the note)"), 0.0); },
  2422. [] (const ChannelDef& d) { return (double) d.misc.echo.feedback / 2.0; },
  2423. [] (ChannelDef& d, double v) { d.misc.echo.feedback = (float) (2.0 * v); }, TR_NOOP ("Feed"));
  2424. echoPan = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay pan: each echo moves this much")); },
  2425. [] (const ChannelDef& d) { return (double) d.misc.echo.pan; }, [] (ChannelDef& d, double v) { d.misc.echo.pan = (float) v; },
  2426. TR_NOOP ("Pan"));
  2427. echoModX = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod X: each echo moves the note's Mod X this much")); },
  2428. [] (const ChannelDef& d) { return (double) d.misc.echo.modX; }, [] (ChannelDef& d, double v) { d.misc.echo.modX = (float) v; },
  2429. TR_NOOP ("Mod X"));
  2430. echoModY = knob ([name] { return ui::panSpec (name() + " - " + tr ("Delay Mod Y: each echo moves the note's Mod Y this much")); },
  2431. [] (const ChannelDef& d) { return (double) d.misc.echo.modY; }, [] (ChannelDef& d, double v) { d.misc.echo.modY = (float) v; },
  2432. TR_NOOP ("Mod Y"));
  2433. echoPitch = knob ([name] {
  2434. ui::ValueSpec s;
  2435. s.name = name() + " - " + tr ("Delay pitch: each echo moves this many cents");
  2436. s.minimum = -1200.0;
  2437. s.maximum = 1200.0;
  2438. s.interval = 1.0;
  2439. s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v)) }); };
  2440. return s;
  2441. },
  2442. [] (const ChannelDef& d) { return (double) d.misc.echo.pitch; }, [] (ChannelDef& d, double v) { d.misc.echo.pitch = (float) v; },
  2443. TR_NOOP ("Pitch"));
  2444. echoTime = knob ([name] {
  2445. ui::ValueSpec s;
  2446. s.name = name() + " - " + tr ("Delay time (steps:ticks)");
  2447. s.minimum = 1.0;
  2448. s.maximum = 192.0 * 4.0;
  2449. s.defaultValue = 144.0;
  2450. s.interval = 1.0;
  2451. s.pixelsForRange = 400.0;
  2452. s.toText = [] (double v) { const auto t = juce::roundToInt (v); return juce::String (t / 48) + ":" + juce::String ((t % 48) / 2).paddedLeft ('0', 2); };
  2453. return s;
  2454. },
  2455. [] (const ChannelDef& d) { return (double) d.misc.echo.timeBeats * 192.0; },
  2456. [] (ChannelDef& d, double v) { d.misc.echo.timeBeats = (float) (juce::roundToInt (v) / 192.0); }, TR_NOOP ("Time"));
  2457. echoCount = knob ([name] { return countSpec (name() + " - " + tr ("Delay number of echoes"), 10, 4); },
  2458. [] (const ChannelDef& d) { return (double) d.misc.echo.echoes; },
  2459. [] (ChannelDef& d, double v) { d.misc.echo.echoes = juce::jlimit (1, 10, juce::roundToInt (v)); }, TR_NOOP ("Echoes"));
  2460. pingPong.setButtonText (tr ("Ping pong"));
  2461. pingPong.setTooltip (tr ("Ping pong: the echoes' pan bounces off the left and right ends"));
  2462. pingPong.onClick = [this] { edit ([on = pingPong.getToggleState()] (ChannelDef& d) { d.misc.echo.pingPong = on; }); };
  2463. fatMode.setButtonText (tr ("Fat mode"));
  2464. fatMode.setTooltip (tr ("Fat mode: a second, mirrored series of echoes (opposite pan and pitch steps), all at the feedback level"));
  2465. fatMode.onClick = [this] { edit ([on = fatMode.getToggleState()] (ChannelDef& d) { d.misc.echo.fat = on; }); };
  2466. // Root note row: main pitch
  2467. mainPitch.setButtonText (tr ("Enable main pitch"));
  2468. mainPitch.setTooltip (tr ("The channel follows the main pitch (the toolbar's master pitch)"));
  2469. mainPitch.onClick = [this] { edit ([on = mainPitch.getToggleState()] (ChannelDef& d) { d.misc.mainPitch = on; }); };
  2470. // FL's Add to key and Root note keyboard (round 149): a sampler's root moves its pitch, other instruments are
  2471. // transposed by (C5 − root) with Add to key
  2472. addToKey.setButtonText (tr ("Add to key"));
  2473. addToKey.setTooltip (tr ("Add to key: the notes are played the root note's distance from C5 away (instruments that are not samplers)"));
  2474. addToKey.onClick = [this] { edit ([on = addToKey.getToggleState()] (ChannelDef& d) { d.misc.addToKey = on; }); };
  2475. // FL's Root note › Fine tune (round 151 [DATA: .flp event 0x8E, cents]): every note of the channel this many
  2476. // cents away
  2477. fineTune = knob ([name] {
  2478. ui::ValueSpec s;
  2479. s.name = name() + " - " + tr ("Fine tuning");
  2480. s.minimum = -100.0;
  2481. s.maximum = 100.0;
  2482. s.interval = 1.0;
  2483. s.toText = [] (double v) { return tr ("{0} cents", { (v > 0.0 ? "+" : "") + juce::String (juce::roundToInt (v)) }); };
  2484. return s;
  2485. },
  2486. [] (const ChannelDef& d) { return (double) d.misc.fineTune; }, [] (ChannelDef& d, double v) { d.misc.fineTune = (float) v; },
  2487. TR_NOOP ("Fine tune"));
  2488. rootReset.setButtonText (tr ("Reset"));
  2489. rootReset.setTooltip (tr ("Reset the root note to C5"));
  2490. rootReset.onClick = [this] { if (rootKeys.onPick) rootKeys.onPick (60); };
  2491. addAndMakeVisible (rootReset);
  2492. rootKeys.onPick = [this] (int key) {
  2493. edit ([key] (ChannelDef& d) {
  2494. if (d.instrument == InstrumentKind::sampler)
  2495. {
  2496. // the sample plays at its own pitch on the root: the pitch moves by the root's change (within ±24)
  2497. const auto pitch = std::clamp (d.sampler.pitch + (float) (d.misc.rootNote - key), -24.0f, 24.0f);
  2498. const auto moved = (int) std::lround (pitch - d.sampler.pitch);
  2499. d.sampler.pitch = pitch;
  2500. d.misc.rootNote = std::clamp (d.misc.rootNote - moved, 0, 127);
  2501. }
  2502. else
  2503. d.misc.rootNote = key;
  2504. });
  2505. };
  2506. rootKeys.onRegion = [this] (int low, int high) {
  2507. edit ([low, high] (ChannelDef& d) {
  2508. d.keyLow = juce::jlimit (0, 127, low);
  2509. d.keyHigh = juce::jlimit (d.keyLow, 127, high);
  2510. });
  2511. };
  2512. addAndMakeVisible (addToKey);
  2513. addAndMakeVisible (rootKeys);
  2514. // Arpeggiator: FL's Slide and Chord
  2515. arpSlide.setButtonText (tr ("Slide"));
  2516. arpSlide.setTooltip (tr ("Slide: the arpeggio glides from note to note (instruments that slide)"));
  2517. arpSlide.onClick = [this] { edit ([on = arpSlide.getToggleState()] (ChannelDef& d) { d.arp.slide = on; }); };
  2518. arpChord.addItem (tr ("Auto (sustain)"), 1);
  2519. arpChord.addItem (tr ("None (octaves)"), 2);
  2520. for (const auto& [chordName, intervals] : arpChords())
  2521. arpChord.addItem (tr (chordName), arpChord.getNumItems() + 1);
  2522. arpChord.setTooltip (tr ("Chord: Auto plays the held notes; a chord plays it on the lowest held note"));
  2523. arpChord.onChange = [this] {
  2524. const auto id = arpChord.getSelectedId();
  2525. if (id <= 0)
  2526. return;
  2527. edit ([id] (ChannelDef& d) {
  2528. if (id == 1)
  2529. d.arp.chord.clear();
  2530. else if (id == 2)
  2531. d.arp.chord = { 0 };
  2532. else if (id - 3 < (int) arpChords().size())
  2533. d.arp.chord = arpChords()[(std::size_t) (id - 3)].second;
  2534. });
  2535. };
  2536. for (auto* b : { &fullPorta, &pingPong, &fatMode, &mainPitch, &arpSlide })
  2537. addAndMakeVisible (b);
  2538. addAndMakeVisible (arpChord);
  2539. // Group
  2540. cut = knob ([this, name] { return countSpec (name() + " - " + tr ("Cut: notes of this channel stop the channels cut by this group"),
  2541. juce::jmax (99, current() != nullptr ? current()->cutGroup : 0), 0,
  2542. [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
  2543. [] (const ChannelDef& d) { return (double) d.cutGroup; }, [] (ChannelDef& d, double v) { d.cutGroup = juce::jmax (0, juce::roundToInt (v)); },
  2544. TR_NOOP ("Cut group"));
  2545. cutBy = knob ([this, name] { return countSpec (name() + " - " + tr ("By: this channel is cut by the channels of this group"),
  2546. juce::jmax (99, current() != nullptr ? current()->cutBy : 0), 0,
  2547. [this] (int g) { return juce::String (cutGroupText (g, channel)); }); },
  2548. [] (const ChannelDef& d) { return (double) d.cutBy; }, [] (ChannelDef& d, double v) { d.cutBy = juce::jmax (0, juce::roundToInt (v)); },
  2549. TR_NOOP ("Cut by"));
  2550. cutSelf.setButtonText (tr ("Cut self"));
  2551. cutSelf.setClickingTogglesState (true);
  2552. cutSelf.setTooltip (tr ("Cut self: a new note of this channel stops its own sounding note (hi-hats, 808s)"));
  2553. cutSelf.onClick = [this] { edit ([on = cutSelf.getToggleState(), ch = channel] (ChannelDef& d) { setChannelCutsItself (d, ch, on); }); };
  2554. // Arpeggiator
  2555. arpDirection.addItemList ({ tr ("Off"), tr ("Up"), tr ("Down"), tr ("Up and down"), tr ("Random"), tr ("Up and down (sticky)") }, 1);
  2556. arpDirection.setTooltip (tr ("Arpeggiator direction (Off = the notes play as written)"));
  2557. arpDirection.onChange = [this] { edit ([d = arpDirection.getSelectedId() - 1] (ChannelDef& c) { c.arp.direction = juce::jlimit (0, 5, d); }); };
  2558. for (const auto& [text, beats] : arpSpeeds())
  2559. arpTime.addItem (tr (text), arpTime.getNumItems() + 1);
  2560. arpTime.setTooltip (tr ("Arpeggiator time: the length of each step"));
  2561. arpTime.onChange = [this] {
  2562. const auto i = arpTime.getSelectedId() - 1;
  2563. if (i >= 0 && i < (int) arpSpeeds().size())
  2564. edit ([b = arpSpeeds()[(std::size_t) i].second] (ChannelDef& c) { c.arp.stepBeats = b; });
  2565. };
  2566. arpRange = knob ([name] { return countSpec (name() + " - " + tr ("Arpeggiator range (octaves)"), 4, 1); },
  2567. [] (const ChannelDef& d) { return (double) d.arp.range; },
  2568. [] (ChannelDef& d, double v) { d.arp.range = juce::jlimit (1, 4, juce::roundToInt (v)); }, TR_NOOP ("Range"));
  2569. arpGate = knob ([name] {
  2570. auto s = ui::percentSpec (name() + " - " + tr ("Arpeggio gate (past 100% the next note waits)"), 0.5);
  2571. s.minimum = 0.05;
  2572. s.maximum = 128.0 / 48.0;
  2573. return s;
  2574. },
  2575. [] (const ChannelDef& d) { return (double) d.arp.gate; },
  2576. [] (ChannelDef& d, double v) { d.arp.gate = juce::jlimit (0.05f, 128.0f / 48.0f, (float) v); }, TR_NOOP ("Gate"));
  2577. // FL's Repeat 0 plays the whole chord at once on each step (round 149)
  2578. arpRepeat = knob ([name] { return countSpec (name() + " - " + tr ("Arpeggiator repeat: times the arpeggio plays in an octave before the next one (0: the chord at once)"), 16, 1,
  2579. [] (int i) { return i == 0 ? tr ("Chord") : juce::String (i); }); },
  2580. [] (const ChannelDef& d) { return (double) d.arp.octaveRepeat; },
  2581. [] (ChannelDef& d, double v) { d.arp.octaveRepeat = juce::jlimit (0, 16, juce::roundToInt (v)); }, TR_NOOP ("Repeat"));
  2582. for (auto* b : { &porta, &mono })
  2583. addAndMakeVisible (b);
  2584. addAndMakeVisible (cutSelf);
  2585. addAndMakeVisible (arpDirection);
  2586. addAndMakeVisible (arpTime);
  2587. refresh();
  2588. engine.addChangeListener (this);
  2589. setSize (preferredWidth, preferredHeight);
  2590. }
  2591. ~MiscPanel() override { engine.removeChangeListener (this); }
  2592. void paint (juce::Graphics& g) override
  2593. {
  2594. g.fillAll (theme::colour::bg2);
  2595. for (const auto& [area, title] : sections)
  2596. {
  2597. g.setColour (theme::colour::bg3);
  2598. g.fillRoundedRectangle (area.toFloat(), 4.0f);
  2599. g.setColour (theme::colour::textSecondary);
  2600. g.setFont (theme::font (theme::type::caption, true));
  2601. auto text = theme::caps (title);
  2602. if (&title == &sections[(std::size_t) juce::jmax (0, rootSection)].second && rootSection >= 0 && current() != nullptr)
  2603. text << ": " << RootKeyboard::keyName (current()->misc.rootNote); // FL's "Root note: C5"
  2604. g.drawText (text, area.withHeight (20).reduced (8, 0), juce::Justification::centredLeft);
  2605. }
  2606. }
  2607. void resized() override
  2608. {
  2609. sections.clear();
  2610. auto area = getLocalBounds().reduced (8);
  2611. auto section = [this] (juce::Rectangle<int> r, const juce::String& title) {
  2612. sections.push_back ({ r, title });
  2613. return r.withTrimmedTop (20).reduced (6, 4);
  2614. };
  2615. constexpr int knobW = 50, knobH = 64;
  2616. auto row = [] (juce::Rectangle<int>& r, std::initializer_list<FrameKnob*> ks) {
  2617. auto line = r.removeFromTop (knobH);
  2618. for (auto* k : ks)
  2619. k->setBounds (line.removeFromLeft (knobW));
  2620. };
  2621. auto top = area.removeFromTop (118);
  2622. {
  2623. auto levels = section (top.removeFromLeft (4 * knobW + 12), tr ("Levels adjustment"));
  2624. row (levels, { pan, volume, modX, modY });
  2625. }
  2626. top.removeFromLeft (6);
  2627. {
  2628. auto poly = section (top.removeFromLeft (2 * knobW + 30), tr ("Polyphony"));
  2629. row (poly, { maxPoly, slide });
  2630. auto toggles = poly.removeFromTop (22);
  2631. porta.setBounds (toggles.removeFromLeft (64));
  2632. mono.setBounds (toggles);
  2633. }
  2634. top.removeFromLeft (6);
  2635. {
  2636. auto time = section (top.removeFromLeft (3 * knobW + 12), tr ("Time"));
  2637. row (time, { timeGate, timeShift, swing });
  2638. fullPorta.setBounds (time.removeFromTop (22));
  2639. }
  2640. top.removeFromLeft (6);
  2641. {
  2642. auto track = section (top, tr ("Tracking"));
  2643. auto tabs = track.removeFromTop (0);
  2644. juce::ignoreUnused (tabs);
  2645. const auto title = sections.back().first;
  2646. trackVol.setBounds (title.getRight() - 84, title.getY() + 2, 38, 16);
  2647. trackKey.setBounds (title.getRight() - 44, title.getY() + 2, 38, 16);
  2648. row (track, { trackPan, trackModX, trackModY, trackMid });
  2649. }
  2650. area.removeFromTop (6);
  2651. auto bottom = area.removeFromTop (130);
  2652. {
  2653. auto group = section (bottom.removeFromLeft (2 * knobW + 16), tr ("Group"));
  2654. row (group, { cut, cutBy });
  2655. cutSelf.setBounds (group.removeFromTop (24).reduced (4, 0));
  2656. }
  2657. bottom.removeFromLeft (6);
  2658. {
  2659. auto arp = section (bottom.removeFromLeft (330), tr ("Arpeggiator"));
  2660. auto boxes = arp.removeFromLeft (118);
  2661. arpDirection.setBounds (boxes.removeFromTop (22));
  2662. boxes.removeFromTop (4);
  2663. arpTime.setBounds (boxes.removeFromTop (22));
  2664. boxes.removeFromTop (4);
  2665. arpChord.setBounds (boxes.removeFromTop (22));
  2666. boxes.removeFromTop (4);
  2667. arpSlide.setBounds (boxes.removeFromTop (22));
  2668. arp.removeFromLeft (6);
  2669. row (arp, { arpRange, arpGate, arpRepeat });
  2670. }
  2671. bottom.removeFromLeft (6);
  2672. {
  2673. auto echo = section (bottom, tr ("Echo delay / fat mode"));
  2674. {
  2675. // seven knobs (round 151 added Mod X / Y): narrower when the window is
  2676. auto line = echo.removeFromTop (knobH);
  2677. const auto w = juce::jmin (knobW, line.getWidth() / 7);
  2678. for (auto* k : { echoFeed, echoPan, echoModX, echoModY, echoPitch, echoTime, echoCount })
  2679. k->setBounds (line.removeFromLeft (w));
  2680. }
  2681. auto toggles = echo.removeFromTop (22);
  2682. pingPong.setBounds (toggles.removeFromLeft (100));
  2683. fatMode.setBounds (toggles.removeFromLeft (100));
  2684. }
  2685. area.removeFromTop (6);
  2686. {
  2687. auto rootRow = section (area.removeFromTop (74), tr ("Root note"));
  2688. rootSection = (int) sections.size() - 1;
  2689. auto toggles = rootRow.removeFromLeft (150);
  2690. mainPitch.setBounds (toggles.removeFromTop (22));
  2691. auto line = toggles.removeFromTop (22);
  2692. rootReset.setBounds (line.removeFromRight (50).reduced (0, 1));
  2693. addToKey.setBounds (line);
  2694. auto fine = rootRow.removeFromLeft (58);
  2695. row (fine, { fineTune });
  2696. rootKeys.setBounds (rootRow.reduced (4, 2));
  2697. }
  2698. }
  2699. private:
  2700. // LYNX's chord choices for the arpeggiator (the piano roll's chord stamps)
  2701. static const std::vector<std::pair<const char*, std::vector<int>>>& arpChords()
  2702. {
  2703. static const std::vector<std::pair<const char*, std::vector<int>>> chords {
  2704. { TR_NOOP ("Major"), { 0, 4, 7 } }, { TR_NOOP ("Minor"), { 0, 3, 7 } }, { "Dim", { 0, 3, 6 } }, { "Aug", { 0, 4, 8 } },
  2705. { "Sus2", { 0, 2, 7 } }, { "Sus4", { 0, 5, 7 } }, { "7", { 0, 4, 7, 10 } }, { "Maj7", { 0, 4, 7, 11 } },
  2706. { "m7", { 0, 3, 7, 10 } }, { "m9", { 0, 3, 7, 10, 14 } }, { TR_NOOP ("Octave"), { 0, 12 } },
  2707. };
  2708. return chords;
  2709. }
  2710. static const std::vector<std::pair<const char*, float>>& arpSpeeds()
  2711. {
  2712. static const std::vector<std::pair<const char*, float>> speeds { { "1/4", 1.0f }, { "1/8", 0.5f },
  2713. { TR_NOOP ("1/8 triplet"), 1.0f / 3.0f }, { "1/16", 0.25f },
  2714. { TR_NOOP ("1/16 triplet"), 1.0f / 6.0f }, { "1/32", 0.125f } };
  2715. return speeds;
  2716. }
  2717. const ChannelDef* current() const
  2718. {
  2719. const auto& channels = engine.getSong().channels;
  2720. return channel >= 0 && channel < (int) channels.size() ? &channels[(std::size_t) channel] : nullptr;
  2721. }
  2722. void edit (std::function<void (ChannelDef&)> change)
  2723. {
  2724. if (updating || current() == nullptr)
  2725. return;
  2726. engine.editSong ([ch = channel, change] (Song& s) {
  2727. if (ch < (int) s.channels.size())
  2728. change (s.channels[(std::size_t) ch]);
  2729. });
  2730. }
  2731. void refresh()
  2732. {
  2733. const auto* c = current();
  2734. if (c == nullptr)
  2735. return;
  2736. updating = true;
  2737. porta.setToggleState (channelPortamento (*c), juce::dontSendNotification);
  2738. porta.setEnabled (channelHasPortamento (*c));
  2739. slide->setEnabled (channelHasPortamento (*c));
  2740. mono.setToggleState (channelMono (*c), juce::dontSendNotification);
  2741. mono.setEnabled (channelHasMono (*c));
  2742. cutSelf.setToggleState (channelCutsItself (*c), juce::dontSendNotification);
  2743. arpDirection.setSelectedId (juce::jlimit (0, 5, c->arp.direction) + 1, juce::dontSendNotification);
  2744. fullPorta.setToggleState (c->misc.fullPorta, juce::dontSendNotification);
  2745. pingPong.setToggleState (c->misc.echo.pingPong, juce::dontSendNotification);
  2746. fatMode.setToggleState (c->misc.echo.fat, juce::dontSendNotification);
  2747. mainPitch.setToggleState (c->misc.mainPitch, juce::dontSendNotification);
  2748. addToKey.setToggleState (c->misc.addToKey, juce::dontSendNotification);
  2749. addToKey.setEnabled (c->instrument != InstrumentKind::sampler);
  2750. rootKeys.setRoot (c->misc.rootNote);
  2751. rootKeys.setRegion (c->keyLow, c->keyHigh);
  2752. arpSlide.setToggleState (c->arp.slide, juce::dontSendNotification);
  2753. const auto filter = c->instrument == InstrumentKind::synth || c->instrument == InstrumentKind::sampler;
  2754. modX->setEnabled (filter);
  2755. modY->setEnabled (filter);
  2756. {
  2757. auto chordId = c->arp.chord.empty() ? 1 : (c->arp.chord == std::vector<int> { 0 } ? 2 : 0);
  2758. for (int i = 0; chordId == 0 && i < (int) arpChords().size(); ++i)
  2759. if (arpChords()[(std::size_t) i].second == c->arp.chord)
  2760. chordId = i + 3;
  2761. arpChord.setSelectedId (chordId, juce::dontSendNotification);
  2762. if (chordId == 0)
  2763. arpChord.setText (tr ("Chord from FL"), juce::dontSendNotification);
  2764. }
  2765. int speed = 0;
  2766. for (int i = 0; i < (int) arpSpeeds().size(); ++i)
  2767. if (std::abs (arpSpeeds()[(std::size_t) i].second - c->arp.stepBeats) < 1e-4f)
  2768. speed = i + 1;
  2769. arpTime.setSelectedId (speed, juce::dontSendNotification);
  2770. if (speed == 0)
  2771. arpTime.setText (tr ("{0} beats", { juce::String (c->arp.stepBeats, 3) }), juce::dontSendNotification);
  2772. updating = false;
  2773. repaint();
  2774. }
  2775. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  2776. AudioEngine& engine;
  2777. int channel;
  2778. bool updating = false;
  2779. std::vector<std::unique_ptr<FrameKnob>> knobs;
  2780. FrameKnob *pan = nullptr, *volume = nullptr, *maxPoly = nullptr, *slide = nullptr, *swing = nullptr, *cut = nullptr, *cutBy = nullptr,
  2781. *arpRange = nullptr, *arpGate = nullptr, *arpRepeat = nullptr, *modX = nullptr, *modY = nullptr, *timeGate = nullptr,
  2782. *timeShift = nullptr, *trackPan = nullptr, *trackMid = nullptr, *echoFeed = nullptr, *echoPan = nullptr, *echoPitch = nullptr,
  2783. *echoTime = nullptr, *echoCount = nullptr, *trackModX = nullptr, *trackModY = nullptr, *echoModX = nullptr, *echoModY = nullptr,
  2784. *fineTune = nullptr;
  2785. juce::ToggleButton porta, mono, fullPorta, pingPong, fatMode, mainPitch, arpSlide, addToKey;
  2786. RootKeyboard rootKeys;
  2787. juce::TextButton rootReset;
  2788. int rootSection = -1;
  2789. juce::TextButton trackVol, trackKey;
  2790. juce::ComboBox arpChord;
  2791. juce::TextButton cutSelf;
  2792. juce::ComboBox arpDirection, arpTime;
  2793. std::vector<std::pair<juce::Rectangle<int>, juce::String>> sections;
  2794. };
  2795. // The frame: header strip (tabs on the left; ON, PAN, VOL, TRACK on the right) over the page of the selected tab.
  2796. class ChannelFrame final : public juce::Component,
  2797. private juce::ChangeListener
  2798. {
  2799. public:
  2800. static constexpr int headerHeight = 62;
  2801. // c.index < 0 (a Patcher node, round 164f): the instrument's pages alone, without the channel's header and Misc tab
  2802. ChannelFrame (AudioEngine& e, ChannelRef c, std::unique_ptr<juce::Component> instrumentPage, std::unique_ptr<juce::Component> envelopePage)
  2803. : engine (e), channel (c.index), node (c.index < 0)
  2804. {
  2805. auto addPage = [this] (std::unique_ptr<juce::Component> page, const juce::String& title, const juce::String& tip) {
  2806. auto button = std::make_unique<juce::TextButton> (title);
  2807. button->setTooltip (tip);
  2808. button->setClickingTogglesState (true);
  2809. button->setRadioGroupId (1);
  2810. const auto index = (int) pages.size();
  2811. button->onClick = [this, index] { showTab (index); };
  2812. addAndMakeVisible (*button);
  2813. addChildComponent (*page);
  2814. sizes.push_back ({ juce::jmax (1, page->getWidth()), juce::jmax (1, page->getHeight()) });
  2815. tabs.push_back (std::move (button));
  2816. pages.push_back (std::move (page));
  2817. };
  2818. if (instrumentPage != nullptr) // (none: a channel whose instrument has its own window, e.g. a hosted plugin)
  2819. addPage (std::move (instrumentPage), tr ("Plugin"), tr ("The instrument's own settings"));
  2820. if (envelopePage != nullptr)
  2821. addPage (std::move (envelopePage), tr ("Envelope / instrument"), tr ("Envelope / instrument settings: the filter and pitch envelopes and the LFOs"));
  2822. if (node)
  2823. {
  2824. int width = 1, height = 1;
  2825. for (auto& p : pages)
  2826. {
  2827. width = juce::jmax (width, p->getWidth());
  2828. height = juce::jmax (height, p->getHeight());
  2829. }
  2830. setSize (width, headerHeight + height);
  2831. showTab (0);
  2832. return;
  2833. }
  2834. addPage (std::make_unique<MiscPanel> (engine, channel), tr ("Misc"), tr ("Miscellaneous functions: levels, polyphony, time, tracking, cut groups, arpeggiator, echo delay"));
  2835. on.setButtonText (tr ("On"));
  2836. on.setTooltip (tr ("Channel on / off (mute)"));
  2837. on.onClick = [this] {
  2838. const auto muted = ! on.getToggleState();
  2839. engine.editSong ([ch = channel, muted] (Song& s) {
  2840. if (ch < (int) s.channels.size())
  2841. s.channels[(std::size_t) ch].muted = muted;
  2842. });
  2843. };
  2844. addAndMakeVisible (on);
  2845. const auto name = [this] { return channelNameOf (engine.getSong(), channel); };
  2846. auto headerKnob = [this] (std::function<ui::ValueSpec()> spec, std::function<double (const ChannelDef&)> get, std::function<void (Song&, int, double)> set,
  2847. const char* caption) {
  2848. auto k = std::make_unique<FrameKnob> (
  2849. engine, std::move (spec),
  2850. [this, get] { return channel < (int) engine.getSong().channels.size() ? get (engine.getSong().channels[(std::size_t) channel]) : 0.0; },
  2851. [this, set] (double v) {
  2852. engine.editSong ([ch = channel, set, v] (Song& s) {
  2853. if (ch < (int) s.channels.size())
  2854. set (s, ch, v);
  2855. });
  2856. },
  2857. tr (caption));
  2858. addAndMakeVisible (*k);
  2859. header.push_back (std::move (k));
  2860. };
  2861. headerKnob ([this, name] {
  2862. auto s = ui::panSpec (name() + " - " + tr ("Pan"));
  2863. s.target = AutomationTarget { AutomationTargetKind::channelPan, channel };
  2864. return s;
  2865. },
  2866. [] (const ChannelDef& d) { return (double) d.pan; }, [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].pan = (float) v; },
  2867. TR_NOOP ("Pan"));
  2868. headerKnob ([this, name] {
  2869. auto s = ui::percentSpec (name() + " - " + tr ("Volume"), 0.78);
  2870. s.target = AutomationTarget { AutomationTargetKind::channelVolume, channel };
  2871. return s;
  2872. },
  2873. [] (const ChannelDef& d) { return (double) d.volume; },
  2874. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].volume = (float) v; }, TR_NOOP ("Vol"));
  2875. // FL's PITCH knob and its RANGE (REA round 146b): the channel's pitch, within ± range semitones
  2876. headerKnob ([this, name] {
  2877. ui::ValueSpec s;
  2878. s.name = name() + " - " + tr ("Pitch (semitones, within the range)");
  2879. const auto range = channel < (int) engine.getSong().channels.size() ? engine.getSong().channels[(std::size_t) channel].misc.pitchRange : 2;
  2880. s.minimum = -juce::jmax (1, range);
  2881. s.maximum = juce::jmax (1, range);
  2882. s.toText = [] (double v) { return tr ("{0} cents", { juce::String (juce::roundToInt (v * 100.0)) }); };
  2883. return s;
  2884. },
  2885. [] (const ChannelDef& d) { return (double) d.sampler.pitch; },
  2886. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].sampler.pitch = (float) juce::jlimit (-24.0, 24.0, v); }, TR_NOOP ("Pitch"));
  2887. headerKnob ([name] { return countSpec (name() + " - " + tr ("Pitch knob range (semitones)"), 48, 2,
  2888. [] (int v) { return juce::String (v); }); },
  2889. [] (const ChannelDef& d) { return (double) d.misc.pitchRange; },
  2890. [] (Song& s, int ch, double v) { s.channels[(std::size_t) ch].misc.pitchRange = juce::jlimit (0, 48, juce::roundToInt (v)); },
  2891. TR_NOOP ("Range"));
  2892. headerKnob ([this, name] {
  2893. return countSpec (name() + " - " + tr ("Target mixer track"), maxMixerTracks - 1, 0,
  2894. [] (int t) { return t == 0 ? tr ("Master") : juce::String (t); });
  2895. },
  2896. [] (const ChannelDef& d) { return (double) d.mixerTrack; },
  2897. [] (Song& s, int ch, double v) {
  2898. mixerops::routeChannel (s, ch, juce::roundToInt (v)); // any insert (round 162): missing ones are added
  2899. },
  2900. TR_NOOP ("Track"));
  2901. int width = MiscPanel::preferredWidth, height = MiscPanel::preferredHeight;
  2902. for (auto& p : pages)
  2903. {
  2904. width = juce::jmax (width, p->getWidth());
  2905. height = juce::jmax (height, p->getHeight());
  2906. }
  2907. refresh();
  2908. engine.addChangeListener (this);
  2909. setSize (width, headerHeight + height);
  2910. showTab (0);
  2911. }
  2912. ~ChannelFrame() override
  2913. {
  2914. if (! node)
  2915. engine.removeChangeListener (this);
  2916. }
  2917. void showTab (int index)
  2918. {
  2919. index = juce::jlimit (0, (int) pages.size() - 1, index);
  2920. current = index;
  2921. for (int i = 0; i < (int) pages.size(); ++i)
  2922. {
  2923. pages[(std::size_t) i]->setVisible (i == index);
  2924. tabs[(std::size_t) i]->setToggleState (i == index, juce::dontSendNotification);
  2925. }
  2926. }
  2927. int getTab() const noexcept { return current; }
  2928. int tabCount() const noexcept { return (int) pages.size(); }
  2929. void paint (juce::Graphics& g) override
  2930. {
  2931. g.fillAll (theme::colour::bg2);
  2932. g.setColour (theme::colour::bg3);
  2933. g.fillRect (getLocalBounds().removeFromTop (headerHeight));
  2934. g.setColour (theme::colour::border);
  2935. g.drawHorizontalLine (headerHeight - 1, 0.0f, (float) getWidth());
  2936. }
  2937. void resized() override
  2938. {
  2939. auto tabsArea = getLocalBounds().removeFromTop (headerHeight).reduced (8, 6);
  2940. for (auto& t : tabs)
  2941. {
  2942. const auto w = juce::jmax (64, (int) juce::GlyphArrangement::getStringWidth (juce::Font (theme::font (theme::type::body)), t->getButtonText()) + 24);
  2943. t->setBounds (tabsArea.removeFromLeft (w).withSizeKeepingCentre (w, 26));
  2944. tabsArea.removeFromLeft (4);
  2945. }
  2946. auto right = getLocalBounds().removeFromTop (headerHeight).reduced (6, 2);
  2947. for (auto it = header.rbegin(); it != header.rend(); ++it)
  2948. (*it)->setBounds (right.removeFromRight (48));
  2949. on.setBounds (right.removeFromRight (52).withSizeKeepingCentre (52, 24));
  2950. // each page keeps its own size (some scale their drawing with it), centred under the header
  2951. const auto body = getLocalBounds().withTrimmedTop (headerHeight);
  2952. for (std::size_t i = 0; i < pages.size(); ++i)
  2953. {
  2954. const auto w = juce::jmin (body.getWidth(), sizes[i].x), h = juce::jmin (body.getHeight(), sizes[i].y);
  2955. pages[i]->setBounds (body.getX() + (body.getWidth() - w) / 2, body.getY(), w, h);
  2956. }
  2957. }
  2958. private:
  2959. void refresh()
  2960. {
  2961. if (channel < (int) engine.getSong().channels.size())
  2962. on.setToggleState (! engine.getSong().channels[(std::size_t) channel].muted, juce::dontSendNotification);
  2963. for (auto& k : header)
  2964. k->repaint();
  2965. }
  2966. void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
  2967. AudioEngine& engine;
  2968. int channel;
  2969. bool node = false;
  2970. int current = 0;
  2971. std::vector<std::unique_ptr<juce::TextButton>> tabs;
  2972. std::vector<std::unique_ptr<juce::Component>> pages;
  2973. std::vector<juce::Point<int>> sizes;
  2974. std::vector<std::unique_ptr<FrameKnob>> header;
  2975. juce::ToggleButton on;
  2976. };
  2977. bool hasEnvelopeTab (InstrumentKind kind) noexcept
  2978. {
  2979. return kind == InstrumentKind::synth || kind == InstrumentKind::sampler;
  2980. }
  2981. void showModulationFor (juce::Component& from, AudioEngine& engine, int channel)
  2982. {
  2983. if (auto* frame = from.findParentComponentOfClass<ChannelFrame>(); frame != nullptr && frame->tabCount() >= 2)
  2984. frame->showTab (1);
  2985. else if (channel >= 0)
  2986. openChannelModulation (engine, channel);
  2987. }
  2988. bool isModelKind (InstrumentKind kind) noexcept
  2989. {
  2990. return kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
  2991. || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
  2992. || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
  2993. || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
  2994. || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::poizone
  2995. || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
  2996. || kind == InstrumentKind::threeosc
  2997. || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
  2998. || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
  2999. || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
  3000. || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
  3001. || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus;
  3002. }
  3003. // The instrument page of a channel or a Patcher node (null: none of its own)
  3004. std::unique_ptr<juce::Component> makeInstrumentPage (AudioEngine& engine, const ChannelRef& ref)
  3005. {
  3006. const auto* def = ref.get (engine);
  3007. if (def == nullptr)
  3008. return nullptr;
  3009. const auto kind = def->instrument;
  3010. if (kind == InstrumentKind::fruitydance && ref.index >= 0)
  3011. return makeDanceEditor (engine, ref.index); // round 165e
  3012. if (kind == InstrumentKind::videoplayer)
  3013. return makeVideoPlayerEditor (engine, ref.locate, ref.index); // round 165g
  3014. if (kind == InstrumentKind::synth)
  3015. return std::make_unique<SynthPanel> (engine, ref);
  3016. if (isModelKind (kind))
  3017. return std::make_unique<ModelPanel> (engine, ref);
  3018. if (kind == InstrumentKind::sampler)
  3019. return std::make_unique<SettingsPanel> (engine, ref);
  3020. return nullptr;
  3021. }
  3022. class SettingsWindow final : public juce::DocumentWindow
  3023. {
  3024. public:
  3025. SettingsWindow (AudioEngine& engine, int c, bool modulationWindow)
  3026. : juce::DocumentWindow (tr ("Channel settings"), theme::colour::bg2, DocumentWindow::closeButton),
  3027. channel (c),
  3028. modulation (modulationWindow)
  3029. {
  3030. setUsingNativeTitleBar (true);
  3031. // FL names the window after the channel and its mixer track (REA round 149 [EXEC]: "FL Studio VSTi (Master)",
  3032. // "Synth Bass (Synth Bass)")
  3033. if (const auto& song = engine.getSong(); channel >= 0 && channel < (int) song.channels.size())
  3034. {
  3035. const auto& def = song.channels[(std::size_t) channel];
  3036. const auto t = def.mixerTrack;
  3037. const auto track = t <= 0 || t >= (int) song.mixer.size() ? tr ("Master")
  3038. : song.mixer[(std::size_t) t].name.empty() ? tr ("Insert {0}", { juce::String (t) })
  3039. : juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str());
  3040. setName (juce::String::fromUTF8 (def.name.c_str()) + " (" + track + ")"
  3041. + (modulation ? " - " + tr ("Envelope / instrument") : juce::String()));
  3042. }
  3043. if (modulation)
  3044. setContentOwned (new ModulationPanel (engine, ChannelRef::rack (channel)), true);
  3045. else if (! hasChannelSettings (engine.getSong().channels[(std::size_t) channel].instrument))
  3046. setContentOwned (new ChannelFrame (engine, ChannelRef::rack (channel), nullptr, nullptr), true); // the Misc tab alone
  3047. else
  3048. setContentOwned (makeChannelFrame (engine, channel).release(), true);
  3049. centreWithSize (getWidth(), getHeight());
  3050. setVisible (true);
  3051. keepAboveMainWindow (*this);
  3052. }
  3053. int getChannel() const { return channel; }
  3054. bool isModulation() const { return modulation; }
  3055. void closeButtonPressed() override;
  3056. private:
  3057. int channel;
  3058. bool modulation;
  3059. };
  3060. std::vector<std::unique_ptr<SettingsWindow>>& windows()
  3061. {
  3062. static std::vector<std::unique_ptr<SettingsWindow>> open;
  3063. return open;
  3064. }
  3065. void SettingsWindow::closeButtonPressed()
  3066. {
  3067. auto* self = this;
  3068. juce::MessageManager::callAsync ([self] {
  3069. auto& open = windows();
  3070. open.erase (std::remove_if (open.begin(), open.end(), [self] (auto& w) { return w.get() == self; }), open.end());
  3071. });
  3072. }
  3073. } // namespace
  3074. namespace
  3075. {
  3076. void openWindow (AudioEngine& engine, int channel, bool modulation)
  3077. {
  3078. for (auto& w : windows())
  3079. if (w->getChannel() == channel && w->isModulation() == modulation)
  3080. {
  3081. w->toFront (true);
  3082. return;
  3083. }
  3084. windows().push_back (std::make_unique<SettingsWindow> (engine, channel, modulation));
  3085. }
  3086. } // namespace
  3087. void openChannelSettings (AudioEngine& engine, int channel)
  3088. {
  3089. openWindow (engine, channel, false);
  3090. }
  3091. void openChannelMisc (AudioEngine& engine, int channel)
  3092. {
  3093. openWindow (engine, channel, false);
  3094. for (auto& w : windows())
  3095. if (w->getChannel() == channel && ! w->isModulation())
  3096. if (auto* frame = dynamic_cast<ChannelFrame*> (w->getContentComponent()))
  3097. frame->showTab (frame->tabCount() - 1);
  3098. }
  3099. void openChannelModulation (AudioEngine& engine, int channel)
  3100. {
  3101. openWindow (engine, channel, true);
  3102. }
  3103. void closeChannelSettings()
  3104. {
  3105. windows().clear();
  3106. }
  3107. bool hasChannelSettings (InstrumentKind kind) noexcept
  3108. {
  3109. switch (kind)
  3110. {
  3111. case InstrumentKind::synth:
  3112. case InstrumentKind::sampler:
  3113. case InstrumentKind::controller:
  3114. case InstrumentKind::midiOut:
  3115. case InstrumentKind::sakura:
  3116. case InstrumentKind::drumpad:
  3117. case InstrumentKind::boobass:
  3118. case InstrumentKind::drumsynth:
  3119. case InstrumentKind::harmless:
  3120. case InstrumentKind::harmor:
  3121. case InstrumentKind::gms:
  3122. case InstrumentKind::morphine:
  3123. case InstrumentKind::ogun:
  3124. case InstrumentKind::minisynth:
  3125. case InstrumentKind::dx10:
  3126. case InstrumentKind::kepler:
  3127. case InstrumentKind::poizone:
  3128. case InstrumentKind::fruitkick:
  3129. case InstrumentKind::bassdrum:
  3130. case InstrumentKind::toxic:
  3131. case InstrumentKind::threeosc:
  3132. case InstrumentKind::autogun:
  3133. case InstrumentKind::transistorbass:
  3134. case InstrumentKind::simsynth:
  3135. case InstrumentKind::wasp:
  3136. case InstrumentKind::plucked:
  3137. case InstrumentKind::beepmap:
  3138. case InstrumentKind::sawer:
  3139. case InstrumentKind::flkeys:
  3140. case InstrumentKind::granulizer:
  3141. case InstrumentKind::drumaxx:
  3142. case InstrumentKind::slayer:
  3143. case InstrumentKind::fruitydance:
  3144. case InstrumentKind::sytrus:
  3145. case InstrumentKind::soundfont:
  3146. case InstrumentKind::layer:
  3147. case InstrumentKind::dashboard:
  3148. case InstrumentKind::voltage:
  3149. case InstrumentKind::vfx:
  3150. return true;
  3151. default:
  3152. return false;
  3153. }
  3154. }
  3155. bool isChannelSettingsOpen (int channel)
  3156. {
  3157. return std::any_of (windows().begin(), windows().end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); });
  3158. }
  3159. void closeChannelSettings (int channel)
  3160. {
  3161. auto& open = windows();
  3162. open.erase (std::remove_if (open.begin(), open.end(), [channel] (auto& w) { return w->getChannel() == channel && ! w->isModulation(); }),
  3163. open.end());
  3164. }
  3165. std::unique_ptr<juce::Component> makeChannelModulationPanel (AudioEngine& engine, int channel)
  3166. {
  3167. return std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel));
  3168. }
  3169. std::unique_ptr<juce::Component> makeChannelFrame (AudioEngine& engine, int channel, int tab)
  3170. {
  3171. const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
  3172. auto frame = std::make_unique<ChannelFrame> (engine, ChannelRef::rack (channel), makeChannelSettingsPanel (engine, channel),
  3173. hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ChannelRef::rack (channel)) : nullptr);
  3174. frame->showTab (tab < 0 ? frame->tabCount() - 1 : tab);
  3175. return frame;
  3176. }
  3177. std::unique_ptr<juce::Component> makeChannelSettingsPanel (AudioEngine& engine, int channel)
  3178. {
  3179. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::synth)
  3180. return std::make_unique<SynthPanel> (engine, ChannelRef::rack (channel));
  3181. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::controller)
  3182. {
  3183. if (parseKeyboardController (engine.getSong().channels[(std::size_t) channel].controllerState))
  3184. return makeKeyboardControllerEditor (engine, channel); // round 165c (it showed the Envelope Controller's read-only page)
  3185. return makeEnvelopeControllerEditor (engine, channel);
  3186. }
  3187. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::midiOut)
  3188. return makeMidiOutEditor (engine, channel);
  3189. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::soundfont)
  3190. return makeSoundFontEditor (engine, channel);
  3191. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::layer)
  3192. return makeLayerEditor (engine, channel);
  3193. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::dashboard)
  3194. return makeDashboardEditor (engine, channel);
  3195. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::voltage)
  3196. return makeVoltageControllerEditor (engine, channel);
  3197. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::vfx)
  3198. return makeVfxEditor (engine, channel);
  3199. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::fruitydance)
  3200. return makeDanceEditor (engine, channel); // round 165e
  3201. if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::videoplayer)
  3202. return makeVideoPlayerEditor (engine, channel); // round 165g
  3203. if (const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
  3204. kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
  3205. || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor
  3206. || kind == InstrumentKind::gms || kind == InstrumentKind::morphine
  3207. || kind == InstrumentKind::ogun || kind == InstrumentKind::minisynth
  3208. || kind == InstrumentKind::dx10 || kind == InstrumentKind::kepler || kind == InstrumentKind::poizone
  3209. || kind == InstrumentKind::fruitkick || kind == InstrumentKind::bassdrum || kind == InstrumentKind::toxic
  3210. || kind == InstrumentKind::threeosc
  3211. || kind == InstrumentKind::autogun || kind == InstrumentKind::transistorbass
  3212. || kind == InstrumentKind::simsynth || kind == InstrumentKind::wasp || kind == InstrumentKind::plucked
  3213. || kind == InstrumentKind::beepmap || kind == InstrumentKind::sawer || kind == InstrumentKind::flkeys
  3214. || kind == InstrumentKind::granulizer || kind == InstrumentKind::drumaxx
  3215. || kind == InstrumentKind::slayer || kind == InstrumentKind::fruitydance || kind == InstrumentKind::sytrus)
  3216. return std::make_unique<ModelPanel> (engine, ChannelRef::rack (channel));
  3217. return std::make_unique<SettingsPanel> (engine, ChannelRef::rack (channel));
  3218. }
  3219. bool hasNodeEditor (const ChannelDef& channel) noexcept
  3220. {
  3221. return channel.instrument == InstrumentKind::synth || channel.instrument == InstrumentKind::sampler || isModelKind (channel.instrument);
  3222. }
  3223. std::unique_ptr<juce::Component> makeNodeChannelFrame (AudioEngine& engine, std::function<ChannelDef* (Song&)> locate)
  3224. {
  3225. ChannelRef ref { std::move (locate), -1 };
  3226. const auto* def = ref.get (engine);
  3227. if (def == nullptr)
  3228. return nullptr;
  3229. auto page = makeInstrumentPage (engine, ref);
  3230. if (page == nullptr)
  3231. return nullptr;
  3232. const auto kind = def->instrument;
  3233. return std::make_unique<ChannelFrame> (engine, ref, std::move (page), hasEnvelopeTab (kind) ? std::make_unique<ModulationPanel> (engine, ref) : nullptr);
  3234. }
  3235. } // namespace lynx