4
0

ChannelSettings.cpp 180 KB

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