*/}}

la_audio.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  1. /*
  2. * Tiny la: A light weight game engine.
  3. * Copyright (C) 2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define MINIAUDIO_IMPLEMENTATION
  19. #include "miniaudio.h"
  20. #include "la_5.h"
  21. extern LA MAIN;
  22. laPropContainer* LA_PC_SYNTH;
  23. laPropContainer* LA_PC_CHANNEL;
  24. laNodeCategory* LA_NODE_CATEGORY_SYNTHESIZER;
  25. laNodeCategory* LA_NODE_CATEGORY_SYSTEM_SOUND;
  26. laBaseNodeType LA_IDN_INPUT;
  27. laBaseNodeType LA_IDN_PULSE;
  28. laBaseNodeType LA_IDN_FM;
  29. laBaseNodeType LA_IDN_VCA;
  30. laBaseNodeType LA_IDN_NOISE;
  31. laBaseNodeType LA_IDN_OUTPUT;
  32. laBaseNodeType LA_IDN_SCOPE;
  33. laBaseNodeType LA_IDN_ENVELOPE;
  34. laBaseNodeType LA_IDN_QUANTIZE;
  35. laBaseNodeType LA_IDN_SYNTH_DRIVER;
  36. laBaseNodeType LA_IDN_SYNTH_TRIGGER;
  37. laPropContainer* LA_PC_IDN_INPUT;
  38. laPropContainer* LA_PC_IDN_PULSE;
  39. laPropContainer* LA_PC_IDN_FM;
  40. laPropContainer* LA_PC_IDN_VCA;
  41. laPropContainer* LA_PC_IDN_NOISE;
  42. laPropContainer* LA_PC_IDN_OUTPUT;
  43. laPropContainer* LA_PC_IDN_SCOPE;
  44. laPropContainer* LA_PC_IDN_ENVELOPE;
  45. laPropContainer* LA_PC_IDN_QUANTIZE;
  46. laPropContainer* LA_PC_IDN_SYNTH_DRIVER;
  47. laPropContainer* LA_PC_IDN_SYNTH_TRIGGER;
  48. #define _2PI 6.283185307
  49. #define VAL2FREQ(val) \
  50. 16.0f*pow(2,val) // 0-10, 16-16384Hz
  51. #define VAL13 -0.218640286
  52. #define VAL27 0.78135971352
  53. #define VAL440 4.78135971352 // 2^FREQC*16=440
  54. #define VALHALF (1.0f/12.0f)
  55. #define WRAPPHASE(p) \
  56. while(p>_2PI){ p-=_2PI; }
  57. #define INITPACKET(arr) \
  58. if(!arr){ arr=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  59. #define INPUTPACKET(ptr,socket) \
  60. {if(socket->Source && socket->Source->DataType==(LA_PROP_FLOAT|LA_PROP_ARRAY) && socket->Source->ArrLen>=LA_SYNTH_PLEN){ \
  61. ptr=((real*)socket->Source->Data); }else{ ptr=0; } }
  62. #define FRAME_INTERVAL (MAIN.Audio->AudioFrameInterval)
  63. #define SAMPLE_RATE (MAIN.Audio->AudioSampleRate)
  64. void IDN_InputInit(laSynthNodeInput* n, int NoCreate){
  65. INITPACKET(n->rTime); INITPACKET(n->rTrigger); //INITPACKET(n->rSamplesL); INITPACKET(n->rSamplesR);
  66. if(NoCreate){
  67. if(!n->OutL) n->OutL=laCreateOutSocket(n,"L",LA_PROP_FLOAT|LA_PROP_ARRAY);
  68. if(!n->OutR) n->OutR=laCreateOutSocket(n,"R",LA_PROP_FLOAT|LA_PROP_ARRAY);
  69. return;
  70. }
  71. n->OutL=laCreateOutSocket(n,"L",LA_PROP_FLOAT|LA_PROP_ARRAY);
  72. n->OutR=laCreateOutSocket(n,"R",LA_PROP_FLOAT|LA_PROP_ARRAY);
  73. n->OutTime=laCreateOutSocket(n,"TIME",LA_PROP_FLOAT|LA_PROP_ARRAY);
  74. n->OutTrigger=laCreateOutSocket(n,"TRIGGER",LA_PROP_FLOAT|LA_PROP_ARRAY);
  75. strSafeSet(&n->Base.Name,"Input");
  76. }
  77. void IDN_InputDestroy(laSynthNodeInput* n){
  78. laDestroyOutSocket(n->OutTime); laDestroyOutSocket(n->OutTrigger);
  79. laDestroyOutSocket(n->OutL); laDestroyOutSocket(n->OutR); strSafeDestroy(&n->Base.Name);
  80. memFree(n->rTime); memFree(n->rTrigger); memFree(n->rSamplesL); memFree(n->rSamplesL);
  81. }
  82. int IDN_InputVisit(laSynthNodeInput* n, laNodeVisitInfo* vi){
  83. LA_GUARD_THIS_NODE(n,vi);
  84. LA_ADD_THIS_NODE(n,vi);
  85. return LA_DAG_FLAG_PERM;
  86. }
  87. int IDN_InputEval(laSynthNodeInput* n){
  88. laSynth*ss=MAIN.Audio->AudioEvalSynth;
  89. real time=ss->EvalTime,target_time=time+(real)LA_SYNTH_PLEN/(real)MAIN.Audio->AudioSampleRate;
  90. for(int i=0;i<LA_SYNTH_PLEN;i++){
  91. real fac=(real)i/(real)LA_SYNTH_PLEN;
  92. n->rTime[i] = tnsLinearItp(time,target_time,fac);
  93. }
  94. if(ss->EvalSamples==0){ n->rTrigger[0] = 10; }else{ n->rTrigger[0]=0; }
  95. n->OutTime->Data=n->rTime; n->OutTrigger->Data=n->rTrigger; n->OutTime->ArrLen=LA_SYNTH_PLEN; n->OutTrigger->ArrLen=LA_SYNTH_PLEN;
  96. n->OutL->Data=MAIN.Audio->InputSamplesL; n->OutR->Data=MAIN.Audio->InputSamplesR; n->OutL->ArrLen=LA_SYNTH_PLEN; n->OutR->ArrLen=LA_SYNTH_PLEN;
  97. return 1;
  98. }
  99. void IDN_InputCopy(laSynthNodeInput* new, laSynthNodeInput* old, int DoRematch){
  100. if(DoRematch){ return; }
  101. LA_IDN_OLD_DUPL(OutTime); LA_IDN_OLD_DUPL(OutTrigger);
  102. }
  103. void laui_InputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  104. laColumn* c=laFirstColumn(uil); laSynthNodeInput*n=This->EndInstance;
  105. LA_BASE_NODE_HEADER(uil,c,This);
  106. laUiItem* b=laBeginRow(uil,c,0,0);
  107. laUiItem* ui=laShowLabel(uil,c,"Capture",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
  108. laShowNodeSocket(uil,c,This,"out_l",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  109. laShowNodeSocket(uil,c,This,"out_r",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  110. laEndRow(uil,b);
  111. b=laBeginRow(uil,c,0,0);
  112. ui=laShowLabel(uil,c,"Synth",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
  113. laShowNodeSocket(uil,c,This,"out_time",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  114. laShowNodeSocket(uil,c,This,"out_trigger",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  115. laEndRow(uil,b);
  116. }
  117. void IDN_PulseInit(laSynthNodePulse* n, int NoCreate){
  118. INITPACKET(n->rOut);
  119. if(NoCreate){ return; }
  120. n->InTrigger = laCreateInSocket("TRIGGER",0);
  121. n->InWidth = laCreateInSocket("WIDTH",0);
  122. n->InGate = laCreateInSocket("GATE",0);
  123. n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  124. strSafeSet(&n->Base.Name,"Pulse");
  125. }
  126. void IDN_PulseDestroy(laSynthNodePulse* n){
  127. laDestroyOutSocket(n->Out); laDestroyInSocket(n->InWidth); laDestroyInSocket(n->InTrigger); laDestroyInSocket(n->InGate);
  128. strSafeDestroy(&n->Base.Name); memFree(n->rOut);
  129. }
  130. int IDN_PulseVisit(laSynthNodePulse* n, laNodeVisitInfo* vi){
  131. LA_GUARD_THIS_NODE(n,vi);
  132. if(LA_SRC_AND_PARENT(n->InTrigger)){ laBaseNode*bn=n->InTrigger->Source->Parent; LA_VISIT_NODE(bn,vi); }
  133. if(LA_SRC_AND_PARENT(n->InWidth)){ laBaseNode*bn=n->InWidth->Source->Parent; LA_VISIT_NODE(bn,vi); }
  134. if(LA_SRC_AND_PARENT(n->InGate)){ laBaseNode*bn=n->InGate->Source->Parent; LA_VISIT_NODE(bn,vi); }
  135. n->Out->Data = n->rOut; n->Out->ArrLen=LA_SYNTH_PLEN;
  136. LA_ADD_THIS_NODE(n,vi);
  137. return LA_DAG_FLAG_PERM;
  138. }
  139. int IDN_PulseEval(laSynthNodePulse* n){
  140. laSynth*ss=MAIN.Audio->AudioEvalSynth;
  141. real* trigger=0; real trig=n->iTrigger?100:-100; INPUTPACKET(trigger,n->InTrigger); LA_GET_SRC_AS_VALUE(trig,n->InTrigger);
  142. real* gate=0; real gt=n->rGate; INPUTPACKET(gate,n->InGate); LA_GET_SRC_AS_VALUE(gt,n->InGate);
  143. real* width=0; real w=n->rWidth; INPUTPACKET(width,n->InWidth);
  144. real wi=0; LA_GET_SRC_AS_VALUE(wi,n->InWidth); if(!width){ w=n->rWidth+wi*n->rInfluence; }
  145. for(int i=0;i<LA_SYNTH_PLEN;i++){
  146. if(trigger){ trig=trigger[i]; } if(gate){ gt=gate[i]; } if(width){ w=n->rWidth+width[i]*n->rInfluence; }
  147. if(!n->Triggered){ if(trig>gt){ n->Triggered=1; n->EvalSamples=1; } }
  148. else{ if(trig<=gt){ n->Triggered=0; } }
  149. int totalsamples=w*MAIN.Audio->AudioSampleRate;
  150. if(n->EvalSamples) n->EvalSamples++;
  151. n->rOut[i]= (n->Triggered || (n->EvalSamples > 0 && n->EvalSamples < totalsamples)) ? 10.0f : 0.0f;
  152. if(n->EvalSamples > totalsamples && !n->Triggered){ n->EvalSamples=0; }
  153. }
  154. return 1;
  155. }
  156. void IDN_PulseCopy(laSynthNodePulse* new, laSynthNodePulse* old, int DoRematch){
  157. if(DoRematch){ LA_IDN_NEW_LINK(InTrigger); LA_IDN_NEW_LINK(InWidth); LA_IDN_NEW_LINK(InGate); return; }
  158. LA_IDN_OLD_DUPL(Out); new->rGate = old->rGate; new->rInfluence=old->rInfluence; new->rWidth=old->rWidth;
  159. }
  160. void laui_PulseNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  161. laColumn* c=laFirstColumn(uil); laSynthNodePulse*n=This->EndInstance;
  162. LA_BASE_NODE_HEADER(uil,c,This);
  163. laUiItem* b;
  164. b=laBeginRow(uil,c,0,0);
  165. laShowNodeSocket(uil,c,This,"in_width",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  166. laShowItem(uil,c,This,"influence");
  167. laShowItem(uil,c,This,"width")->Expand=1;
  168. laEndRow(uil,b);
  169. b=laBeginRow(uil,c,0,0);
  170. laShowItem(uil,c,This,"gate")->Expand=1;
  171. laShowNodeSocket(uil,c,This,"in_gate",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  172. laShowNodeSocket(uil,c,This,"in_trigger",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  173. laEndRow(uil,b);
  174. b=laBeginRow(uil,c,0,0);
  175. laShowSeparator(uil,c)->Expand=1;
  176. laShowItem(uil,c,This,"trigger")->Flags|=LA_UI_FLAGS_MOMENTARY|LA_UI_FLAGS_HIGHLIGHT;
  177. laShowItem(uil,c,This,"out")->Flags|=LA_UI_SOCKET_LABEL_W;
  178. laEndRow(uil,b);
  179. }
  180. void IDN_FMInit(laSynthNodeFM* n, int NoCreate){
  181. INITPACKET(n->OutSamples);
  182. if(NoCreate){ return; }
  183. n->InFrequency=laCreateInSocket("FREQ",0); n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  184. strSafeSet(&n->Base.Name,"FM"); n->Frequency=4;
  185. }
  186. void IDN_FMDestroy(laSynthNodeFM* n){
  187. laDestroyInSocket(n->InFrequency); laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  188. }
  189. int IDN_FMVisit(laSynthNodeFM* n, laNodeVisitInfo* vi){
  190. LA_GUARD_THIS_NODE(n,vi);
  191. if(LA_SRC_AND_PARENT(n->InFrequency)){ laBaseNode*bn=n->InFrequency->Source->Parent; LA_VISIT_NODE(bn,vi); }
  192. LA_ADD_THIS_NODE(n,vi);
  193. return LA_DAG_FLAG_PERM;
  194. }
  195. int IDN_FMEval(laSynthNodeFM* n){
  196. real f=n->Frequency, constf=0; real* inputf;
  197. INPUTPACKET(inputf,n->InFrequency); LA_GET_SRC_AS_VALUE(constf,n->InFrequency);
  198. for(int i=0;i<LA_SYNTH_PLEN;i++){
  199. real useF=inputf?(inputf[i]*n->rInfluence+f):(f+constf); if(n->Slow) useF-=10;
  200. n->Phase+=FRAME_INTERVAL*VAL2FREQ(useF)*_2PI;
  201. WRAPPHASE(n->Phase);
  202. n->OutSamples[i]=sin(n->Phase)*10;
  203. }
  204. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  205. return 1;
  206. }
  207. void IDN_FMCopy(laSynthNodeFM* new, laSynthNodeFM* old, int DoRematch){
  208. if(DoRematch){ LA_IDN_NEW_LINK(InFrequency) return; }
  209. LA_IDN_OLD_DUPL(Out); new->Frequency=old->Frequency; new->Slow=old->Slow; new->rInfluence=old->rInfluence;
  210. }
  211. void laui_FMNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  212. laColumn* c=laFirstColumn(uil); laSynthNodeFM*n=This->EndInstance;
  213. LA_BASE_NODE_HEADER(uil,c,This);
  214. laUiItem* b=laBeginRow(uil,c,0,0);
  215. laShowItem(uil,c,This,"slow");
  216. laShowNodeSocket(uil,c,This,"in_frequency",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  217. laShowItem(uil,c,This,"influence");
  218. laShowItem(uil,c,This,"frequency")->Expand=1;
  219. laShowNodeSocket(uil,c,This,"out",0);
  220. laEndRow(uil,b);
  221. }
  222. void IDN_VCAInit(laSynthNodeVCA* n, int NoCreate){
  223. INITPACKET(n->OutSamples);
  224. if(NoCreate){ return; }
  225. n->InAmp=laCreateInSocket("AMP",0); n->In=laCreateInSocket("IN",0);
  226. n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  227. strSafeSet(&n->Base.Name,"FM"); n->Amp=10;
  228. }
  229. void IDN_VCADestroy(laSynthNodeVCA* n){
  230. laDestroyInSocket(n->InAmp); laDestroyInSocket(n->In);
  231. laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  232. }
  233. int IDN_VCAVisit(laSynthNodeVCA* n, laNodeVisitInfo* vi){
  234. LA_GUARD_THIS_NODE(n,vi);
  235. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  236. if(LA_SRC_AND_PARENT(n->InAmp)){ laBaseNode*bn=n->InAmp->Source->Parent; LA_VISIT_NODE(bn,vi); }
  237. LA_ADD_THIS_NODE(n,vi);
  238. return LA_DAG_FLAG_PERM;
  239. }
  240. int IDN_VCAEval(laSynthNodeVCA* n){
  241. real amp=n->Amp, constamp=amp; real* inputamp=0,*input=0;
  242. INPUTPACKET(input,n->In); INPUTPACKET(inputamp,n->InAmp);
  243. if(!inputamp) LA_GET_SRC_AS_VALUE(constamp,n->InAmp); constamp/=10;
  244. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  245. if(!input){ memset(n->OutSamples,0,sizeof(real)*LA_SYNTH_PLEN); return 0; }
  246. for(int i=0;i<LA_SYNTH_PLEN;i++){
  247. real useA= inputamp?tnsInterpolate(1.0f,inputamp[i]/10.0f,n->rInfluence)*constamp:constamp;
  248. n->OutSamples[i]= input[i]*useA;
  249. }
  250. return 1;
  251. }
  252. void IDN_VCACopy(laSynthNodeVCA* new, laSynthNodeVCA* old, int DoRematch){
  253. if(DoRematch){ LA_IDN_NEW_LINK(InAmp) LA_IDN_NEW_LINK(In) return; }
  254. LA_IDN_OLD_DUPL(Out); new->Amp=old->Amp; new->rInfluence = old->rInfluence;
  255. }
  256. void laui_VCANode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  257. laColumn* c=laFirstColumn(uil); laSynthNodeVCA*n=This->EndInstance;
  258. LA_BASE_NODE_HEADER(uil,c,This);
  259. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  260. laUiItem* b=laBeginRow(uil,c,0,0);
  261. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  262. laShowNodeSocket(uil,c,This,"in_amp",0);
  263. laShowItem(uil,c,This,"influence");
  264. laShowItem(uil,c,This,"amp")->Expand=1;
  265. laShowNodeSocket(uil,cr,This,"out",0);
  266. laEndRow(uil,b);
  267. }
  268. void IDN_NoiseInit(laSynthNodeNoise* n, int NoCreate){
  269. INITPACKET(n->OutWhiteSamples); INITPACKET(n->OutPinkSamples);
  270. n->PinkA[0]=0.02109238; n->PinkA[1]=0.07113478; n->PinkA[2]=0.68873558;
  271. n->PinkP[0]=0.3190; n->PinkP[1]=0.7756; n->PinkP[2]=0.9613;
  272. if(NoCreate){ return; }
  273. n->OutWhite=laCreateOutSocket(n,"WHITE",LA_PROP_FLOAT|LA_PROP_ARRAY);
  274. n->OutPink=laCreateOutSocket(n,"PINK",LA_PROP_FLOAT|LA_PROP_ARRAY);
  275. strSafeSet(&n->Base.Name,"Noise");
  276. }
  277. void IDN_NoiseDestroy(laSynthNodeNoise* n){
  278. laDestroyOutSocket(n->OutWhite); laDestroyOutSocket(n->OutPink); strSafeDestroy(&n->Base.Name);
  279. memFree(n->OutWhiteSamples); memFree(n->OutPinkSamples);
  280. }
  281. int IDN_NoiseVisit(laSynthNodeNoise* n, laNodeVisitInfo* vi){
  282. LA_GUARD_THIS_NODE(n,vi); LA_ADD_THIS_NODE(n,vi);
  283. return LA_DAG_FLAG_PERM;
  284. }
  285. int IDN_NoiseEval(laSynthNodeNoise* n){
  286. real RMI2 = 2.0 / (real)RAND_MAX; // + 1.0; // change for range [0,1)
  287. real offset = n->PinkA[0] + n->PinkA[1] + n->PinkA[2];
  288. for(int i=0;i<LA_SYNTH_PLEN;i++){
  289. real R1=(real)rand()/(real)RAND_MAX;
  290. real R2=(real)rand()/(real)RAND_MAX;
  291. real X=(real)sqrt(-2.0f*log(R1))*cos(2.0f*TNS_PI*R2);
  292. n->OutWhiteSamples[i]=X*2.5;
  293. real temp; for(int i=0;i<3;i++){ temp=(real)rand();
  294. n->PinkStates[i] = n->PinkP[i] * (n->PinkStates[i] - temp) + temp;
  295. }
  296. n->OutPinkSamples[i]=(n->PinkA[0]*n->PinkStates[0]+
  297. n->PinkA[1]*n->PinkStates[1]+
  298. n->PinkA[2]*n->PinkStates[2])*RMI2-offset;
  299. n->OutPinkSamples[i]*=40;
  300. }
  301. n->OutWhite->Data=n->OutWhiteSamples; n->OutWhite->ArrLen=LA_SYNTH_PLEN;
  302. n->OutPink->Data=n->OutPinkSamples; n->OutPink->ArrLen=LA_SYNTH_PLEN;
  303. return 1;
  304. }
  305. void IDN_NoiseCopy(laSynthNodeNoise* new, laSynthNodeNoise* old, int DoRematch){
  306. if(DoRematch){ return; }
  307. LA_IDN_OLD_DUPL(OutWhite);
  308. }
  309. void laui_NoiseNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  310. laColumn* c=laFirstColumn(uil); laSynthNodeNoise*n=This->EndInstance;
  311. LA_BASE_NODE_HEADER(uil,c,This);
  312. laUiItem* b=laBeginRow(uil,c,0,0);
  313. laShowNodeSocket(uil,c,This,"out_white",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  314. laShowNodeSocket(uil,c,This,"out_pink",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  315. laEndRow(uil,b);
  316. }
  317. void IDN_ScopeInit(laSynthNodeScope* n, int NoCreate){
  318. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  319. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  320. laSpinInit(&n->Lock);
  321. if(NoCreate){ return; }
  322. n->In1=laCreateInSocket("CH1",0); n->In2=laCreateInSocket("CH2",0);
  323. strSafeSet(&n->Base.Name,"SCOPE"); n->Time=5; n->Brightness1=0.7f; n->Brightness2=0.4f;
  324. n->Gain1=1; n->Gain2=1;
  325. }
  326. void IDN_ScopeDestroy(laSynthNodeScope* n){
  327. laDestroyInSocket(n->In1); laDestroyOutSocket(n->In2); strSafeDestroy(&n->Base.Name);
  328. memFree(n->Display1); memFree(n->Display2);
  329. laSpinDestroy(&n->Lock);
  330. }
  331. int IDN_ScopeVisit(laSynthNodeScope* n, laNodeVisitInfo* vi){
  332. LA_GUARD_THIS_NODE(n,vi);
  333. if(LA_SRC_AND_PARENT(n->In1)){ laBaseNode*bn=n->In1->Source->Parent; LA_VISIT_NODE(bn,vi); }
  334. if(LA_SRC_AND_PARENT(n->In2)){ laBaseNode*bn=n->In2->Source->Parent; LA_VISIT_NODE(bn,vi); }
  335. LA_ADD_THIS_NODE(n,vi);
  336. return LA_DAG_FLAG_PERM;
  337. }
  338. int IDN_ScopeEval(laSynthNodeScope* n){
  339. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  340. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  341. real* ch1,*ch2; INPUTPACKET(ch1,n->In1); INPUTPACKET(ch2,n->In2);
  342. int Frame=1<<(n->Time-1); TNS_CLAMP(Frame,1,LA_SYNTH_PLEN);
  343. int Times=LA_SYNTH_PLEN/Frame; int sp=0; laSpinLock(&n->Lock);
  344. for(int t=0;t<Times;t++){
  345. real smin1=FLT_MAX,smax1=-FLT_MAX,smin2=FLT_MAX,smax2=-FLT_MAX;
  346. for(int i=0;i<Frame;i++){
  347. if(ch1){ smin1=TNS_MIN2(smin1,ch1[sp]); smax1=TNS_MAX2(smax1,ch1[sp]); }
  348. if(ch2){ smin2=TNS_MIN2(smin2,ch2[sp]); smax2=TNS_MAX2(smax2,ch2[sp]); }
  349. sp++;
  350. }
  351. if(!ch1){smin1=smax1=0; LA_GET_SRC_AS_VALUE(smin1,n->In1); smax1=smin1; }
  352. if(!ch2){smin2=smax2=0; LA_GET_SRC_AS_VALUE(smin2,n->In2); smax2=smin2; }
  353. int ns=n->NextSample;
  354. n->Display1[ns]=smin1; n->Display1[ns+LA_SYNTH_PLEN]=smax1;
  355. n->Display2[ns]=smin2; n->Display2[ns+LA_SYNTH_PLEN]=smax2;
  356. n->NextSample++; if(n->NextSample>=LA_SYNTH_PLEN) n->NextSample=0;
  357. }
  358. n->FromSynth=MAIN.Audio->AudioEvalSynth;
  359. laSpinUnlock(&n->Lock);
  360. return 1;
  361. }
  362. void IDN_ScopeCopy(laSynthNodeScope* new, laSynthNodeScope* old, int DoRematch){
  363. if(DoRematch){ LA_IDN_NEW_LINK(In1) LA_IDN_NEW_LINK(In2) return; }
  364. new->Brightness1=old->Brightness1; new->Brightness2=old->Brightness2;
  365. new->Gain1=old->Gain1; new->Gain2=old->Gain2;
  366. new->Offset1=old->Offset1; new->Offset2=old->Offset2;
  367. new->Time=old->Time;
  368. }
  369. void laui_ScopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  370. laColumn* c=laFirstColumn(uil); laSynthNodeScope*n=This->EndInstance;
  371. LA_BASE_NODE_HEADER(uil,c,This);
  372. laColumn* cl,*cr; laSplitColumn(uil,c,0.5); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  373. laUiItem* b=laBeginRow(uil,c,0,0);
  374. laUiItem* u=laShowItem(uil,c,This,"gain1");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  375. laShowNodeSocket(uil,c,This,"in1",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  376. laEndRow(uil,b);
  377. b=laBeginRow(uil,c,0,0);
  378. u=laShowItem(uil,c,This,"gain2");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  379. laShowNodeSocket(uil,c,This,"in2",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  380. laEndRow(uil,b);
  381. laShowItem(uil,c,This,"scope")->Extra->HeightCoeff=6;
  382. laShowLabel(uil,cl,"CH1",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  383. laShowItem(uil,cl,This,"bright1"); laShowItem(uil,cl,This,"offset1");
  384. laShowLabel(uil,cr,"CH2",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  385. laShowItem(uil,cr,This,"bright2"); laShowItem(uil,cr,This,"offset2");
  386. laShowItem(uil,c,This,"time")->Flags|=LA_UI_FLAGS_EXPAND;
  387. }
  388. void IDN_OutputInit(laSynthNodeOutput* n, int NoCreate){
  389. if(NoCreate){
  390. laAudioChannel* outchannel = laGetAudioChannel(SSTR(n->SendName));
  391. if(outchannel) memAssignRef(n,&n->Send,outchannel);
  392. if(!n->InL) n->InL=laCreateInSocket("L/M",0);
  393. if(!n->InR) n->InR=laCreateInSocket("R",0);
  394. return;
  395. }
  396. n->InL=laCreateInSocket("L/M",0); n->InR=laCreateInSocket("R",0); strSafeSet(&n->Base.Name,"Output");
  397. }
  398. void IDN_OutputDestroy(laSynthNodeOutput* n){
  399. laDestroyInSocket(n->InL); laDestroyInSocket(n->InR); strSafeDestroy(&n->Base.Name);
  400. }
  401. int IDN_OutputVisit(laSynthNodeOutput* n, laNodeVisitInfo* vi){
  402. if(LA_SRC_AND_PARENT(n->InL)){ laBaseNode*bn=n->InL->Source->Parent; LA_VISIT_NODE(bn,vi); }
  403. if(LA_SRC_AND_PARENT(n->InR)){ laBaseNode*bn=n->InR->Source->Parent; LA_VISIT_NODE(bn,vi); }
  404. LA_ADD_THIS_NODE(n,vi);
  405. laAudioChannel* outchannel = laGetAudioChannel(SSTR(n->SendName));
  406. memAssignRef(n,&n->Send,outchannel);
  407. return LA_DAG_FLAG_PERM;
  408. }
  409. int IDN_OutputEval(laSynthNodeOutput* n){
  410. if(!n->Send)return 1;
  411. real* inputL; INPUTPACKET(inputL,n->InL); real* inputR; INPUTPACKET(inputR,n->InR); if(!inputL && !inputR) return 1;
  412. real Samples[LA_SYNTH_PLEN];
  413. if(inputL){
  414. for(int i=0;i<LA_SYNTH_PLEN;i++){ n->Send->SamplesL[i] += inputL[i]; }
  415. if(n->Send){ n->Send->IsMono=1; }
  416. }
  417. if(inputR){
  418. for(int i=0;i<LA_SYNTH_PLEN;i++){ n->Send->SamplesR[i] += inputR[i]; }
  419. if(n->Send){ n->Send->IsMono=0; }
  420. }
  421. return 1;
  422. }
  423. void IDN_OutputCopy(laSynthNodeOutput* new, laSynthNodeOutput* old, int DoRematch){
  424. if(DoRematch){ LA_IDN_NEW_LINK(InL) return; }
  425. if(DoRematch){ LA_IDN_NEW_LINK(InR) return; }
  426. strSafeSet(&new->SendName,SSTR(old->SendName)); new->Send=old->Send;
  427. }
  428. void laui_OutputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  429. laColumn* c=laFirstColumn(uil); laSynthNodeOutput*n=This->EndInstance;
  430. LA_BASE_NODE_HEADER(uil,c,This);
  431. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  432. laUiItem* b=laBeginRow(uil,c,0,0);
  433. laShowNodeSocket(uil,c,This,"in_l",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  434. laShowNodeSocket(uil,c,This,"in_r",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  435. laShowLabel(uil,c,"🕪",0,0);
  436. laShowItemFull(uil,c,This,"send_channel_selector",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0)->Flags|=LA_UI_COLLECTION_SIMPLE_SELECTOR;
  437. laShowItem(uil,c,This,"send_channel_name")->Expand = 1;
  438. laEndRow(uil,b);
  439. }
  440. void IDN_EnvelopeInit(laSynthNodeEnvelope* n, int NoCreate){
  441. if(!NoCreate){ strSafeSet(&n->Base.Name,"Envelope");
  442. n->Attack=laCreateInSocket("ATTACK",0); n->Delay=laCreateInSocket("DELAY",0);
  443. n->Sustain=laCreateInSocket("SUSTAIN",0); n->Release=laCreateInSocket("RELEASE",0);
  444. n->Trigger=laCreateInSocket("TRIGGER",0); n->Out=laCreateOutSocket(n, "OUT",0);
  445. n->Time=20; n->rAttack=1; n->rDelay=5; n->rSustain=5; n->rRelease=7; n->rGate=5;
  446. }
  447. if(!n->Gate){ n->Gate=laCreateInSocket("GATE",0); }
  448. if(!n->Restart){ n->Restart=laCreateInSocket("RESTART",0); }
  449. if(!n->OutSamples){ n->OutSamples=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  450. n->Out->Data = n->OutSamples; n->Out->DataType = LA_PROP_FLOAT|LA_PROP_ARRAY; n->Out->ArrLen=LA_SYNTH_PLEN;
  451. }
  452. void IDN_EnvelopeDestroy(laSynthNodeEnvelope* n){
  453. laDestroyInSocket(n->Attack); laDestroyInSocket(n->Delay); laDestroyInSocket(n->Gate);
  454. laDestroyInSocket(n->Sustain); laDestroyInSocket(n->Release);
  455. laDestroyInSocket(n->Trigger); laDestroyOutSocket(n->Out);
  456. memFree(n->OutSamples);
  457. strSafeDestroy(&n->Base.Name);
  458. }
  459. int IDN_EnvelopeVisit(laSynthNodeEnvelope* n, laNodeVisitInfo* vi){
  460. LA_GUARD_THIS_NODE(n,vi);
  461. if(LA_SRC_AND_PARENT(n->Attack)){ laBaseNode*bn=n->Attack->Source->Parent; LA_VISIT_NODE(bn,vi); }
  462. if(LA_SRC_AND_PARENT(n->Delay)){ laBaseNode*bn=n->Delay->Source->Parent; LA_VISIT_NODE(bn,vi); }
  463. if(LA_SRC_AND_PARENT(n->Sustain)){ laBaseNode*bn=n->Sustain->Source->Parent; LA_VISIT_NODE(bn,vi); }
  464. if(LA_SRC_AND_PARENT(n->Release)){ laBaseNode*bn=n->Release->Source->Parent; LA_VISIT_NODE(bn,vi); }
  465. if(LA_SRC_AND_PARENT(n->Trigger)){ laBaseNode*bn=n->Trigger->Source->Parent; LA_VISIT_NODE(bn,vi); }
  466. if(LA_SRC_AND_PARENT(n->Restart)){ laBaseNode*bn=n->Restart->Source->Parent; LA_VISIT_NODE(bn,vi); }
  467. LA_ADD_THIS_NODE(n,vi);
  468. return LA_DAG_FLAG_PERM;
  469. }
  470. int IDN_EnvelopeEval(laSynthNodeEnvelope* n){
  471. int trigger_at=-1; real trig=n->bTrigger?n->bTrigger*100:-100; real res=0;
  472. real* trigger; INPUTPACKET(trigger,n->Trigger); if(!trigger){ LA_GET_SRC_AS_VALUE(trig,n->Trigger); }
  473. real* restart; INPUTPACKET(restart,n->Restart); if(!restart){ LA_GET_SRC_AS_VALUE(res,n->Restart); }
  474. real *att,*del,*sus,*rel,*gat;
  475. real attack=n->rAttack,delay=n->rDelay,sustain=n->rSustain,release=n->rRelease;
  476. real gate = n->rGate; INPUTPACKET(gat,n->Gate); if(!gat) LA_GET_SRC_AS_VALUE(gate,n->Gate);
  477. INPUTPACKET(att,n->Attack); if(!att) LA_GET_SRC_AS_VALUE(attack,n->Attack);
  478. INPUTPACKET(del,n->Delay); if(!del) LA_GET_SRC_AS_VALUE(delay,n->Delay);
  479. INPUTPACKET(sus,n->Sustain); if(!sus) LA_GET_SRC_AS_VALUE(sustain,n->Sustain);
  480. INPUTPACKET(rel,n->Release); if(!rel) LA_GET_SRC_AS_VALUE(release,n->Release);
  481. attack=attack?pow(attack/10,2):0; delay=delay?pow(delay/10,2):0; release=release?pow(release/10,2):0;
  482. for(int i=0;i<LA_SYNTH_PLEN;i++){
  483. if(trigger){ trig=trigger[i]; } if(gat){ gate=gat[i]; } if(restart){ res=restart[i]; }
  484. if(att){ attack=att[i]*n->iAttack+n->rAttack; }
  485. if(del){ delay=del[i]*n->iDelay+n->rDelay; }
  486. if(sus){ sustain=sus[i]*n->iSustain+n->rSustain; }
  487. if(rel){ release=rel[i]*n->iRelease+n->rRelease; }
  488. if(res){ n->Time=0; n->ReleaseTime=-10000; n->Triggered=0;}
  489. if(!n->Triggered){ if(trig > gate){ n->Triggered = 1; n->Time = 0; n->ReleaseTime=10000; n->AtLevel=0; } }
  490. else{ if(trig < gate-0.0001f){ n->Triggered = 0; n->ReleaseTime = n->Time; } }
  491. if(n->Time < n->ReleaseTime){
  492. if(n->Time<=attack){
  493. n->OutSamples[i]=10.0f*pow(n->Time/attack,0.3);
  494. }elif(n->Time<=delay + attack){
  495. real fac=pow((n->Time-attack)/delay,0.3);
  496. n->OutSamples[i]= tnsLinearItp(10.0f, sustain, fac);
  497. }else{
  498. n->OutSamples[i]=sustain;
  499. }
  500. n->AtLevel=n->OutSamples[i];
  501. }else{
  502. if(n->Time - n->ReleaseTime < release){
  503. real fac=pow((n->Time - n->ReleaseTime)/release,0.3);
  504. n->OutSamples[i]= tnsLinearItp(n->AtLevel,0.0f, fac);
  505. }else{
  506. n->OutSamples[i]=0;
  507. }
  508. }
  509. n->Time+=FRAME_INTERVAL;
  510. }
  511. return 1;
  512. }
  513. void IDN_EnvelopeCopy(laSynthNodeEnvelope* new, laSynthNodeEnvelope* old, int DoRematch){
  514. if(DoRematch){
  515. LA_IDN_NEW_LINK(Attack) LA_IDN_NEW_LINK(Delay)
  516. LA_IDN_NEW_LINK(Sustain) LA_IDN_NEW_LINK(Release) LA_IDN_NEW_LINK(Trigger) return;
  517. }
  518. LA_IDN_OLD_DUPL(Out);
  519. new->rGate=old->rGate;
  520. new->rAttack=old->rAttack;new->rSustain=old->rSustain;new->rDelay=old->rDelay;new->rRelease=old->rRelease;
  521. new->iAttack=old->iAttack;new->iSustain=old->iSustain;new->iDelay=old->iDelay;new->iRelease=old->rRelease;
  522. }
  523. void laui_EnvelopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  524. laColumn* c=laFirstColumn(uil); laSynthNodeEnvelope*n=This->EndInstance;
  525. LA_BASE_NODE_HEADER(uil,c,This);
  526. laUiItem* b,*b1;
  527. #define ADSR_ROW(what) \
  528. b=laBeginRow(uil,c,0,0);{ \
  529. laShowNodeSocket(uil,c,This,"in_" what,0)->Flags|=LA_UI_SOCKET_LABEL_E; \
  530. laUiItem* value=laShowItem(uil,c,This,"i" what); \
  531. value=laShowItem(uil,c,This,what);value->Expand=1; \
  532. }laEndRow(uil,b);
  533. ADSR_ROW("attack") ADSR_ROW("delay") ADSR_ROW("sustain") ADSR_ROW("release")
  534. b=laBeginRow(uil,c,0,0);
  535. laShowItem(uil,c,This,"gate")->Expand=1;
  536. laShowNodeSocket(uil,c,This,"in_gate",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  537. laShowNodeSocket(uil,c,This,"in_trigger",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  538. laEndRow(uil,b);
  539. b=laBeginRow(uil,c,0,0);
  540. laShowSeparator(uil,c)->Expand=1;
  541. laShowItem(uil,c,This,"in_restart")->Flags|=LA_UI_SOCKET_LABEL_E;
  542. laShowItem(uil,c,This,"trigger")->Flags|=LA_UI_FLAGS_MOMENTARY|LA_UI_FLAGS_HIGHLIGHT;
  543. laShowItem(uil,c,This,"out")->Flags|=LA_UI_SOCKET_LABEL_W;
  544. laEndRow(uil,b);
  545. }
  546. void IDN_QuantizeInit(laSynthNodeQuantize* n, int NoCreate){
  547. if(!NoCreate){ strSafeSet(&n->Base.Name,"Envelope");
  548. n->In=laCreateInSocket("IN",0); n->Out=laCreateOutSocket(n, "OUT",0);
  549. }
  550. if(!n->OutSamples){ n->OutSamples=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  551. n->Out->Data = n->OutSamples; n->Out->DataType = LA_PROP_FLOAT|LA_PROP_ARRAY; n->Out->ArrLen=LA_SYNTH_PLEN;
  552. int Enabled[12]={1,0,1,0,1,1,0,1,0,1,0,1};
  553. memcpy(n->EnabledBits,Enabled,sizeof(Enabled));
  554. }
  555. void IDN_QuantizeDestroy(laSynthNodeQuantize* n){
  556. laDestroyInSocket(n->In); laDestroyOutSocket(n->Out);
  557. memFree(n->OutSamples);
  558. strSafeDestroy(&n->Base.Name);
  559. }
  560. int IDN_QuantizeVisit(laSynthNodeQuantize* n, laNodeVisitInfo* vi){
  561. LA_GUARD_THIS_NODE(n,vi);
  562. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  563. LA_ADD_THIS_NODE(n,vi);
  564. return LA_DAG_FLAG_PERM;
  565. }
  566. static const real QTABLE[12]={ VAL13-VALHALF*9, VAL13-VALHALF*8, VAL13-VALHALF*7, VAL13-VALHALF*6,
  567. VAL13-VALHALF*5, VAL13-VALHALF*4, VAL13-VALHALF*3, VAL13-VALHALF*2,
  568. VAL13-VALHALF*1, VAL13, VAL13+VALHALF*1, VAL13+VALHALF*2 };
  569. static void set_quantize_out_bit(laSynthNodeQuantize* n, int which){
  570. for(int i=0;i<12;i++){
  571. if(n->EnabledBits[i]){ n->EnabledBits[i]=1; }
  572. if(i==which && n->EnabledBits){ n->EnabledBits[i]=3; }
  573. }
  574. }
  575. int IDN_QuantizeEval(laSynthNodeQuantize* n){ real cv0=QTABLE[0]+5; /*C4*/ LA_GET_SRC_AS_VALUE(cv0, n->In);
  576. real* cv; INPUTPACKET(cv,n->In); real dists[12];
  577. for(int i=0;i<LA_SYNTH_PLEN;i++){
  578. int octave = (int)(cv0-QTABLE[0]); int minkey=0;
  579. if(cv){ cv0=cv[i]; }
  580. real use_cv = cv0 - octave;
  581. for(int j=0;j<12;j++){ dists[j] = fabs(use_cv - QTABLE[j]); }
  582. for(int j=1;j<12;j++){ if(n->EnabledBits[j] && dists[j] < dists[minkey]){ minkey=j; } }
  583. set_quantize_out_bit(n,minkey);
  584. n->OutSamples[i] = QTABLE[minkey]+octave;
  585. }
  586. return 1;
  587. }
  588. void IDN_QuantizeCopy(laSynthNodeQuantize* new, laSynthNodeQuantize* old, int DoRematch){
  589. if(DoRematch){
  590. LA_IDN_NEW_LINK(In) return;
  591. }
  592. LA_IDN_OLD_DUPL(Out);
  593. memcpy(new->EnabledBits,old->EnabledBits,sizeof(int)*12);
  594. }
  595. void laui_QuantizeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  596. laColumn* c=laFirstColumn(uil); laSynthNodeQuantize*n=This->EndInstance;
  597. LA_BASE_NODE_HEADER(uil,c,This);
  598. laUiItem* b;
  599. b=laBeginRow(uil,c,0,0);
  600. laUiItem* ui=laShowItem(uil,c,This,"enabled_keys");
  601. ui->Flags|=LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_TRANSPOSE|LA_UI_FLAGS_ICON; ui->Expand=1;
  602. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  603. laShowNodeSocket(uil,c,This,"out",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  604. laEndRow(uil,b);
  605. }
  606. void IDN_SynthDriverInit(laSynthNodeDriver* n, int NoCreate){
  607. if(NoCreate){ return; }
  608. n->Prev=laCreateInSocket("PREV",0); n->Next=laCreateOutSocket(n,"NEXT",0);
  609. n->InTransport=laCreateInSocket("TRANSPORT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  610. n->InReset=laCreateInSocket("RESET",LA_PROP_FLOAT|LA_PROP_ARRAY);
  611. strSafeSet(&n->Base.Name,"Sound Player");
  612. }
  613. void IDN_SynthDriverDestroy(laSynthNodeDriver* n){
  614. laDestroyInSocket(n->InTransport); laDestroyInSocket(n->InReset); strSafeDestroy(&n->Base.Name);
  615. laDestroyInSocket(n->Prev); laDestroyOutSocket(n->Next);
  616. }
  617. int IDN_SynthDriverVisit(laSynthNodeDriver* n, laNodeVisitInfo* vi){
  618. LA_GUARD_THIS_NODE(n,vi);
  619. if(LA_SRC_AND_PARENT(n->Prev)){ laBaseNode*bn=n->Prev->Source->Parent; LA_VISIT_NODE(bn,vi); }
  620. if(LA_SRC_AND_PARENT(n->InTransport)){ laBaseNode*bn=n->InTransport->Source->Parent; LA_VISIT_NODE(bn,vi); }
  621. if(LA_SRC_AND_PARENT(n->InReset)){ laBaseNode*bn=n->InReset->Source->Parent; LA_VISIT_NODE(bn,vi); }
  622. LA_ADD_THIS_NODE(n,vi);
  623. return LA_DAG_FLAG_PERM;
  624. }
  625. int IDN_SynthDriverEval(laSynthNodeDriver* n){
  626. laSynth*ss=n->Target; if(!ss){ return 0; }
  627. int trans=n->iTransport; LA_GET_SRC_AS_VALUE(trans,n->InTransport);
  628. int res=n->iReset; LA_GET_SRC_AS_VALUE(res,n->InReset); int dif=0;
  629. if(n->AlreadyReset && res==0){ n->AlreadyReset=0; res=0; }
  630. elif(!n->AlreadyReset && res!=0){ n->AlreadyReset=1; }
  631. else{ res=0; }
  632. laSpinLock(&ss->Lock);
  633. if(ss->Playing!=trans){ dif=1; }
  634. ss->Playing = trans; if(res){ ss->EvalSamples=0; ss->EvalTime=0; }
  635. laSpinUnlock(&ss->Lock);
  636. if(dif){ laNotifyInstanceUsers(ss); }
  637. return 1;
  638. }
  639. void IDN_SynthDriverCopy(laSynthNodeDriver* new, laSynthNodeDriver* old, int DoRematch){
  640. if(DoRematch){ LA_IDN_NEW_LINK(InTransport); LA_IDN_NEW_LINK(InReset); return; }
  641. new->iTransport = old->iTransport; new->iReset = old->iReset;
  642. memAssignRef(new,&new->Target,old->Target);
  643. }
  644. void laui_SynthDriverNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  645. laColumn* c=laFirstColumn(uil),*cl,*cr,*cll,*clr;
  646. LA_BASE_NODE_HEADER(uil,c,This);
  647. laSplitColumn(uil,c,0.6); cl=laLeftColumn(c,0); cr=laRightColumn(c,3);
  648. //laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,3); clr=laRightColumn(cl,0);
  649. laUiItem* b2, *rui;
  650. laShowNodeSocket(uil,cr,This,"prev",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  651. laShowNodeSocket(uil,cr,This,"next",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  652. laUiItem* b=laBeginRow(uil,cl,0,0);
  653. laShowNodeSocket(uil,cl,This,"in_transport",0); b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"in_transport.source")));{
  654. laShowItemFull(uil,cl,This,"transport",0,"text=Transport",0,0)->Expand=1;
  655. }laElse(uil,b2);{
  656. laShowLabel(uil,cl,"Transport",0,0)->Expand=1;
  657. }laEndCondition(uil,b2);
  658. laShowNodeSocket(uil,cl,This,"in_reset",0); b2=laOnConditionThat(uil,c,laNot(laPropExpression(This,"in_reset.source")));{
  659. laUiItem* u=laShowItemFull(uil,cl,This,"reset",0,"text=Reset",0,0);u->Expand=1;u->Flags|=LA_UI_FLAGS_MOMENTARY;
  660. }laElse(uil,b2);{
  661. laShowLabel(uil,cl,"Reset",0,0)->Expand=1;
  662. }laEndCondition(uil,b2);
  663. laEndRow(uil,b);
  664. laShowItemFull(uil,cl,This,"target",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  665. }
  666. void IDN_SynthTriggerInit(laSynthNodeTrigger* n, int NoCreate){
  667. if(NoCreate){ return; }
  668. n->Prev=laCreateInSocket("PREV",0); n->Next=laCreateOutSocket(n,"NEXT",0);
  669. n->InTrigger=laCreateInSocket("TRIGGER",LA_PROP_FLOAT|LA_PROP_ARRAY);
  670. strSafeSet(&n->Base.Name,"Sound Trigger"); n->TriggerEdge=1;
  671. }
  672. void IDN_SynthTriggerDestroy(laSynthNodeTrigger* n){
  673. laDestroyInSocket(n->InTrigger); strSafeDestroy(&n->Base.Name);
  674. laDestroyInSocket(n->Prev); laDestroyOutSocket(n->Next);
  675. }
  676. int IDN_SynthTriggerVisit(laSynthNodeTrigger* n, laNodeVisitInfo* vi){
  677. LA_GUARD_THIS_NODE(n,vi);
  678. if(LA_SRC_AND_PARENT(n->Prev)){ laBaseNode*bn=n->Prev->Source->Parent; LA_VISIT_NODE(bn,vi); }
  679. if(LA_SRC_AND_PARENT(n->InTrigger)){ laBaseNode*bn=n->InTrigger->Source->Parent; LA_VISIT_NODE(bn,vi); }
  680. LA_ADD_THIS_NODE(n,vi);
  681. return LA_DAG_FLAG_PERM;
  682. }
  683. int IDN_SynthTriggerEval(laSynthNodeTrigger* n){
  684. laSynth*ss=n->Target; if(!ss){ return 0; }
  685. real trig=0; real* trigger=0; INPUTPACKET(trigger,n->InTrigger); LA_GET_SRC_AS_VALUE(trig,n->InTrigger);
  686. if(MAIN.Audio->AudioEvalSynth == ss){ return 0; }
  687. if(trigger){
  688. for(int i=0;i<LA_SYNTH_PLEN;i++){
  689. if(trigger[i]>=5){
  690. if(n->TriggerEdge){ if(!n->Triggered){ n->Triggered=1; laSynthTriggerLater(ss); } }
  691. else{ laSynthTriggerLater(ss); }
  692. }else{ n->Triggered=0; }
  693. }
  694. }else{
  695. if(trig>=0.5){
  696. if(n->TriggerEdge){ if(!n->Triggered){ n->Triggered=1; laSynthTriggerLater(ss); } }
  697. else{ laSynthTriggerLater(ss); }
  698. }else{ n->Triggered=0; }
  699. }
  700. return 1;
  701. }
  702. void IDN_SynthTriggerCopy(laSynthNodeTrigger* new, laSynthNodeTrigger* old, int DoRematch){
  703. if(DoRematch){ LA_IDN_NEW_LINK(InTrigger); return; }
  704. new->TriggerEdge = old->TriggerEdge;
  705. memAssignRef(new,&new->Target,old->Target);
  706. }
  707. void laui_SynthTriggerNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  708. laColumn* c=laFirstColumn(uil),*cl,*cr,*cll,*clr;
  709. LA_BASE_NODE_HEADER(uil,c,This);
  710. laSplitColumn(uil,c,0.6); cl=laLeftColumn(c,0); cr=laRightColumn(c,3);
  711. //laSplitColumn(uil,cl,0.4); cll=laLeftColumn(cl,3); clr=laRightColumn(cl,0);
  712. laUiItem* b2, *rui;
  713. laShowNodeSocket(uil,cr,This,"prev",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  714. laShowNodeSocket(uil,cr,This,"next",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  715. laUiItem* b=laBeginRow(uil,cl,0,0);
  716. laShowItemFull(uil,cl,This,"trigger_edge",0,0,0,0)->Flags|=LA_UI_FLAGS_ICON;
  717. laShowNodeSocket(uil,cl,This,"in_trigger",0);
  718. laShowItemFull(uil,cl,This,"trigger",0,"text=Trigger",0,0)->Flags|=LA_UI_FLAGS_MOMENTARY|LA_UI_FLAGS_HIGHLIGHT;
  719. laShowSeparator(uil,cl)->Expand=1;
  720. laEndRow(uil,b);
  721. laShowItemFull(uil,cl,This,"target",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0);
  722. }
  723. void laRebuildSynthGraphs(int current_only){
  724. if(MAIN.Audio->CurrentSynth && current_only){
  725. laSpinLock(&MAIN.Audio->CurrentSynth->Lock);
  726. laRebuildPageEval(MAIN.Audio->CurrentSynth->Page);
  727. laSpinUnlock(&MAIN.Audio->CurrentSynth->Lock);
  728. }else{
  729. for(laSynth* s=MAIN.Audio->Synths.pFirst;s;s=s->Item.pNext){
  730. laSpinLock(&s->Lock);
  731. laRebuildPageEval(s->Page);
  732. laSpinUnlock(&s->Lock);
  733. }
  734. }
  735. }
  736. int laEvalSingleSynth(laSynth* ss){
  737. laSynth* FirstInst=0; int any=0;
  738. laSpinLock(&ss->Lock);
  739. if(ss->Playing){
  740. MAIN.Audio->AudioEvalSynth=ss;
  741. laRunPage(ss->Page,1);
  742. ss->EvalSamples += LA_SYNTH_PLEN;
  743. ss->EvalTime = (real)ss->EvalSamples/MAIN.Audio->AudioSampleRate;
  744. any=1;
  745. }
  746. FirstInst=ss->PolyphonicInstances.pFirst;
  747. laSpinUnlock(&ss->Lock);
  748. laSpinLock(&MAIN.Audio->AudioStatusLock);
  749. laSynth* pending; while(pending=lstPopPointer(&MAIN.Audio->PolyLaterTrigger)){ laSynthTriggerNew(pending); }
  750. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  751. laListHandle to_remove={0}; int count=0;
  752. for(laSynth* inst=FirstInst;inst;inst=inst->Item.pNext){
  753. any+=laEvalSingleSynth(inst); count++;
  754. if(inst->EvalTime > ss->Length || count>ss->MaxPoly){ lstAppendPointer(&to_remove,inst); }
  755. }
  756. laSynth* inst; while(inst=lstPopPointer(&to_remove)){
  757. la_SynthRemovePolyInstance(ss,inst);
  758. }
  759. return any;
  760. }
  761. int laEvalSynthGraphs(){
  762. laSynth* ss; int any=0;
  763. memset(MAIN.Audio->OutputSamplesL,0,sizeof(real)*LA_SYNTH_PLEN);
  764. memset(MAIN.Audio->OutputSamplesR,0,sizeof(real)*LA_SYNTH_PLEN);
  765. for(laAudioChannel* ac=MAIN.Audio->Channels.pFirst;ac;ac=ac->Item.pNext){
  766. memset(ac->SamplesL,0,sizeof(real)*LA_SYNTH_PLEN);
  767. memset(ac->SamplesR,0,sizeof(real)*LA_SYNTH_PLEN);
  768. }
  769. for(ss=MAIN.Audio->Synths.pFirst;ss;ss=ss->Item.pNext){
  770. if(laEvalSingleSynth(ss)){ any=1; }
  771. }
  772. for(laAudioChannel* ac=MAIN.Audio->Channels.pFirst;ac;ac=ac->Item.pNext){
  773. real *RSamples = ac->IsMono?ac->SamplesL:ac->SamplesR;
  774. for(int i=0;i<LA_SYNTH_PLEN;i++){
  775. MAIN.Audio->OutputSamplesL[i] += ac->SamplesL[i]*(ac->Volume/10);
  776. MAIN.Audio->OutputSamplesR[i] += RSamples[i]*(ac->Volume/10);
  777. }
  778. }
  779. return any;
  780. }
  781. void laSetAudioCallback(laAudioCallbackF Callback){
  782. MAIN.Audio->Callback = Callback;
  783. }
  784. void laaudio_DataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){
  785. float* out=pOutput; const float *in=pInput; int Paused; int any=0;
  786. laSpinLock(&MAIN.Audio->AudioStatusLock);
  787. Paused = MAIN.Audio->Paused;
  788. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  789. if(MAIN.Audio->Callback){
  790. if(MAIN.Audio->Callback(Paused, pInput, pOutput, frameCount)) return;
  791. }
  792. if(Paused){ memset(out,0,sizeof(float)*LA_SYNTH_PLEN);
  793. memset(MAIN.Audio->InputSamplesL,0,sizeof(float)*LA_SYNTH_PLEN);
  794. memset(MAIN.Audio->InputSamplesR,0,sizeof(float)*LA_SYNTH_PLEN); return;
  795. }
  796. for(int i=0;i<frameCount;i++){
  797. if(MAIN.Audio->NextAudioSample>=LA_SYNTH_PLEN){
  798. MAIN.Audio->NextAudioSample=0;
  799. if(laEvalSynthGraphs()){ any=1; }
  800. }
  801. int s=i*2;
  802. out[s]=MAIN.Audio->OutputSamplesL[MAIN.Audio->NextAudioSample]/10;
  803. out[s+1]=MAIN.Audio->OutputSamplesR[MAIN.Audio->NextAudioSample]/10;
  804. MAIN.Audio->InputSamplesL[MAIN.Audio->NextAudioSample] = in[s] * 10;
  805. MAIN.Audio->InputSamplesR[MAIN.Audio->NextAudioSample] = in[s+1] * 10;
  806. MAIN.Audio->NextAudioSample++;
  807. }
  808. }
  809. void la_SelectAudioDevice(laAudioDevice* ad){
  810. memAssignRef(MAIN.Audio, &MAIN.Audio->UsingDevice, ad);
  811. ma_device_stop(&MAIN.Audio->AudioDevice);
  812. ma_device_uninit(&MAIN.Audio->AudioDevice);
  813. if(!ad) return;
  814. int SampleRate=48000;
  815. ma_device_config config = ma_device_config_init(ma_device_type_duplex);
  816. config.capture.pDeviceID = ad->MiniAudioID;
  817. config.capture.format = ma_format_f32;
  818. config.capture.channels = 2;
  819. config.playback.pDeviceID= ad->MiniAudioID;
  820. config.playback.format = ma_format_f32;
  821. config.playback.channels = 2;
  822. config.sampleRate = SampleRate;
  823. config.dataCallback = laaudio_DataCallback;
  824. config.pUserData = 0;
  825. if (ma_device_init(&MAIN.Audio->MiniAudioContext, &config, &MAIN.Audio->AudioDevice) != MA_SUCCESS){ return; }
  826. MAIN.Audio->AudioSampleRate=SampleRate;
  827. MAIN.Audio->NextAudioSample=LA_SYNTH_PLEN;
  828. MAIN.Audio->AudioFrameInterval=1.0f/SampleRate;
  829. }
  830. void la_AddAudioDevice(int id, char* Name){
  831. laAudioDevice* ad=memAcquire(sizeof(laAudioDevice));
  832. strSafeSet(&ad->Name,Name); ad->MiniAudioID=id;
  833. lstAppendItem(&MAIN.Audio->AudioDevices,ad);
  834. }
  835. void la_ClearAudioDevices(){
  836. laAudioDevice* ad; while(ad=lstPopItem(&MAIN.Audio->AudioDevices)){
  837. strSafeDestroy(&ad->Name); memFree(ad);
  838. }
  839. }
  840. void laRefreshAudioDevices(){
  841. if(!MAIN.Audio) return; la_ClearAudioDevices();
  842. ma_device_info* pPlaybackInfos;
  843. ma_uint32 playbackCount;
  844. ma_device_info* pCaptureInfos;
  845. ma_uint32 captureCount;
  846. if (ma_context_get_devices(&MAIN.Audio->MiniAudioContext, &pPlaybackInfos, &playbackCount, &pCaptureInfos, &captureCount) != MA_SUCCESS) {
  847. logPrintNew("Can't get audio devices.\n");
  848. }
  849. for (ma_uint32 iDevice = 0; iDevice < playbackCount; iDevice += 1) {
  850. la_AddAudioDevice(iDevice, pPlaybackInfos[iDevice].name);
  851. }
  852. }
  853. void laInitMiniAudio(){
  854. MAIN.Audio->MiniAudioBackend=ma_backend_null;
  855. if (ma_context_init(NULL, 0, NULL, &MAIN.Audio->MiniAudioContext) != MA_SUCCESS) {
  856. printf("Can't init miniaudio context\n");
  857. }
  858. laRefreshAudioDevices();
  859. laSpinInit(&MAIN.Audio->AudioStatusLock);
  860. INITPACKET(MAIN.Audio->InputSamplesL);
  861. INITPACKET(MAIN.Audio->InputSamplesR);
  862. INITPACKET(MAIN.Audio->OutputSamplesL);
  863. INITPACKET(MAIN.Audio->OutputSamplesR);
  864. la_SelectAudioDevice(MAIN.Audio->AudioDevices.pFirst);
  865. }
  866. void laDeinitAudio(){
  867. memFree(MAIN.Audio->InputSamplesL);
  868. memFree(MAIN.Audio->InputSamplesR);
  869. memFree(MAIN.Audio->OutputSamplesR);
  870. memFree(MAIN.Audio->OutputSamplesL);
  871. laSpinDestroy(&MAIN.Audio->AudioStatusLock);
  872. ma_device_stop(&MAIN.Audio->AudioDevice);
  873. ma_device_uninit(&MAIN.Audio->AudioDevice);
  874. ma_context_uninit(&MAIN.Audio->MiniAudioContext);
  875. }
  876. void laStartAudio(){
  877. laSpinLock(&MAIN.Audio->AudioStatusLock);
  878. MAIN.Audio->Paused = 0;
  879. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  880. ma_device_start(&MAIN.Audio->AudioDevice);
  881. }
  882. void laStopAudio(){
  883. ma_device_stop(&MAIN.Audio->AudioDevice);
  884. }
  885. void laPauseAudio(){
  886. laSpinLock(&MAIN.Audio->AudioStatusLock);
  887. MAIN.Audio->Paused = 1;
  888. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  889. }
  890. void laResetAudio(){
  891. for(laSynth* s=MAIN.Audio->Synths.pFirst;s;s=s->Item.pNext){
  892. laSpinLock(&s->Lock);
  893. s->EvalTime = 0; s->EvalSamples = 0; s->Playing = 0;
  894. laSpinUnlock(&s->Lock);
  895. }
  896. }
  897. // Operations
  898. int OPINV_RefreshAudioDevices(laOperator* a, laEvent* e){
  899. laRefreshAudioDevices(); return LA_FINISHED;
  900. }
  901. laSynth* laFindSynth(const char* Name){
  902. for(laSynth* ss=MAIN.Audio->Synths.pFirst;ss;ss=ss->Item.pNext){
  903. if(strSame(SSTR(ss->Name),Name)) return ss;
  904. }
  905. return 0;
  906. }
  907. laSynth* laNewSynth(char* Name){
  908. laSynth* ss=memAcquireHyper(sizeof(laSynth));
  909. ss->Page=memAcquire(sizeof(laRackPage));
  910. ss->Page->RackType=LA_RACK_TYPE_AUDIO;
  911. ss->Length=5; ss->MaxPoly=8;
  912. strSafeSet(&ss->Name,Name);
  913. lstAppendItem(&MAIN.Audio->Synths,ss);
  914. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,ss);
  915. laSpinInit(&ss->Lock);
  916. return ss;
  917. }
  918. void laRemoveSynth(laSynth* ss){ if(!ss) return;
  919. strSafeDestroy(&ss->Name);
  920. if(MAIN.Audio->CurrentSynth==ss){
  921. laSynth* nss=ss->Item.pNext?ss->Item.pNext:ss->Item.pPrev;
  922. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,nss);
  923. }laNotifyInstanceUsers(ss);
  924. while(ss->Page->Racks.pFirst){ laDestroyRack(ss->Page->Racks.pFirst); } memLeave(ss->Page); //ss->Page=0;
  925. lstRemoveItem(&MAIN.Audio->Synths,ss);
  926. laSpinDestroy(&ss->Lock);
  927. memLeave(ss);
  928. }
  929. int OPINV_ShedNewSynth(laOperator* a, laEvent* e){
  930. laNewSynth("New Synth");
  931. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","New synth", 0);
  932. return LA_FINISHED;
  933. }
  934. int OPCHK_IslaSynth(laPropPack *This, laStringSplitor *ss){
  935. if (This && This->EndInstance && la_EnsureSubTarget(This->LastPs->p,0) == LA_PC_SYNTH) return 1;
  936. return 0;
  937. }
  938. int OPINV_ShedRemoveSynth(laOperator* a, laEvent* e){
  939. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  940. if(strSame(strGetArgumentString(a->ExtraInstructionsP,"confirm"),"true")){
  941. laRemoveSynth(ss);
  942. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","Remove synthesizer", 0);
  943. return LA_FINISHED;
  944. }
  945. laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
  946. return LA_RUNNING;
  947. }
  948. void laui_RemoveSynth(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  949. laColumn* c=laFirstColumn(uil);
  950. laShowItemFull(uil,c,This,"remove_synth",0,"confirm=true;text=Confirm",0,0);
  951. }
  952. int OPINV_SynthPlay(laOperator* a, laEvent* e){
  953. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  954. char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
  955. int play=0; if(str && strSame(str,"PLAY")) play=1;
  956. laRebuildPageEval(ss->Page);
  957. laSpinLock(&ss->Lock);
  958. ss->Playing=play; if(!play){ ss->EvalSamples=0; ss->EvalTime=0; }
  959. laSpinUnlock(&ss->Lock);
  960. if(play){ laStartAudio(); } laNotifyInstanceUsers(ss);
  961. return LA_FINISHED;
  962. }
  963. int OPINV_SynthTriggerNew(laOperator* a, laEvent* e){
  964. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  965. laSynthTriggerNew(ss);
  966. laStartAudio();
  967. return LA_FINISHED;
  968. }
  969. void la_SynthAddPolyInstance(laSynth* s){
  970. int count=0;
  971. laSpinLock(&s->Lock); count = s->PolyCount; laSpinUnlock(&s->Lock);
  972. if(s->PolyCount>s->MaxPoly){ return; }
  973. laSpinLock(&s->Lock);
  974. laSynth* ns=memAcquire(sizeof(laSynth)); ns->Length=s->Length; ns->Playing=1;
  975. ns->Page = laDuplicateRackPage(0,s->Page);
  976. laRebuildPageEval(ns->Page);
  977. laSpinInit(&ns->Lock);
  978. //laSpinLock(&s->Lock);
  979. lstPushItem(&s->PolyphonicInstances,ns);
  980. s->PolyCount++;
  981. laSpinUnlock(&s->Lock);
  982. }
  983. void la_SynthRemovePolyInstance(laSynth* s, laSynth* inst){
  984. laSpinLock(&inst->Lock);
  985. while(inst->Page->Racks.pFirst){ laDestroyRack(inst->Page->Racks.pFirst); } memFree(inst->Page); //ss->Page=0;
  986. laSpinUnlock(&inst->Lock);
  987. laSpinDestroy(&inst->Lock);
  988. laSpinLock(&s->Lock);
  989. lstRemoveItem(&s->PolyphonicInstances,inst);
  990. s->PolyCount--;
  991. laSpinUnlock(&s->Lock);
  992. memFree(inst);
  993. }
  994. void laSynthTriggerNew(laSynth* s){
  995. if(!s || !s->Poly){ return; } la_SynthAddPolyInstance(s);
  996. }
  997. void laSynthTriggerLater(laSynth* s){
  998. if(!s || !s->Poly){ return; }
  999. laSpinLock(&MAIN.Audio->AudioStatusLock);
  1000. lstAppendPointer(&MAIN.Audio->PolyLaterTrigger,s);
  1001. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  1002. }
  1003. laAudioChannel* laNewAudioChannel(char* Name){
  1004. laAudioChannel* ac=memAcquireHyper(sizeof(laAudioChannel)); lstAppendItem(&MAIN.Audio->Channels,ac);
  1005. strSafeSet(&ac->Name,Name);
  1006. ac->Volume = 10.0f;
  1007. return ac;
  1008. }
  1009. void laRemoveAudioChannel(laAudioChannel* ac){
  1010. lstRemoveItem(&MAIN.Audio->Channels,ac); strSafeDestroy(&ac->Name);
  1011. memLeave(ac);
  1012. }
  1013. laAudioChannel* laGetAudioChannel(char* Name){
  1014. for(laAudioChannel* ac=MAIN.Audio->Channels.pFirst;ac;ac=ac->Item.pNext){
  1015. if(strSame(SSTR(ac->Name),Name)) return ac;
  1016. }
  1017. return 0;
  1018. }
  1019. int OPCHK_IslaAudioChannel(laPropPack *This, laStringSplitor *ss){
  1020. if (This && This->EndInstance && la_EnsureSubTarget(This->LastPs->p,0) == LA_PC_CHANNEL) return 1;
  1021. return 0;
  1022. }
  1023. int OPINV_ShedNewAudioChannel(laOperator* a, laEvent* e){
  1024. laNewAudioChannel("Output");
  1025. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","New channel", 0);
  1026. return LA_FINISHED;
  1027. }
  1028. int OPINV_ShedRemoveAudioChannel(laOperator* a, laEvent* e){
  1029. laAudioChannel*ac=a->This?a->This->EndInstance:0; if(!ac)return LA_CANCELED;
  1030. if(strSame(strGetArgumentString(a->ExtraInstructionsP,"confirm"),"true")){
  1031. laRemoveAudioChannel(ac); laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","Remove audio channel", 0);
  1032. return LA_FINISHED;
  1033. }
  1034. laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
  1035. return LA_RUNNING;
  1036. }
  1037. void laui_RemoveAudioChannel(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  1038. laColumn* c=laFirstColumn(uil);
  1039. laShowItemFull(uil,c,This,"remove",0,"confirm=true;text=Confirm",0,0);
  1040. }
  1041. void lauidetached_Synthersizers(laPanel* p){
  1042. la_MakeDetachedProp(p, "la.detached_view_switch", "detached");
  1043. la_MakeDetachedProp(p, "la.audio.current_synth", "page");
  1044. }
  1045. void laui_Synthersizers(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  1046. laColumn* c=laFirstColumn(uil),*cl, *cr,*crl,*crr;
  1047. laSplitColumn(uil,c,0.4); cl=laLeftColumn(c,1); cr=laRightColumn(c,0);
  1048. laSplitColumn(uil,cr,0.6); crl=laLeftColumn(cr,0); crr=laRightColumn(cr,2);
  1049. laShowItemFull(uil,cl,Extra,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  1050. #define ADD_PAGE \
  1051. laUiItem* b=laBeginRow(uil,crl,0,0); \
  1052. laShowItemFull(uil,crl,&rb->PP,"",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0) \
  1053. ->Flags|=LA_UI_COLLECTION_SIMPLE_SELECTOR; \
  1054. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{ \
  1055. laShowItem(uil,crl,&rb->PP,"name"); \
  1056. laShowItem(uil,crl,0,"LA_new_synth")->Flags|=LA_UI_FLAGS_ICON; \
  1057. laShowSeparator(uil,crl); \
  1058. laShowItem(uil,crl,&rb->PP,"remove_synth")->Flags|=LA_UI_FLAGS_ICON; \
  1059. laShowSeparator(uil,crl)->Expand=1; \
  1060. laUiItem* b4=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,"poly"));{ \
  1061. laShowItem(uil,crl,&rb->PP,"max_poly"); \
  1062. laShowItem(uil,crl,&rb->PP,"length"); \
  1063. laShowItemFull(uil,crl,&rb->PP,"trigger",0,"icon=▶;",0,0)->Flags|=LA_UI_FLAGS_ICON; \
  1064. }laEndCondition(uil,b4); \
  1065. laUiItem* poly=laShowItem(uil,crl,&rb->PP,"poly");poly->Flags|=LA_UI_FLAGS_EXPAND; \
  1066. }laElse(uil,b3);{ \
  1067. laShowItem(uil,crl,0,"LA_new_synth"); \
  1068. }laEndCondition(uil,b3); \
  1069. laEndRow(uil,b); \
  1070. b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{ \
  1071. laUiItem* b4=laOnConditionThat(uil,crr,laPropExpression(&rb->PP,"playing"));{ \
  1072. laShowItemFull(uil,crr,&rb->PP,"play",0,"text=❚❚;",0,0) \
  1073. ->Flags|=LA_UI_FLAGS_EXIT_WHEN_TRIGGERED|LA_TEXT_ALIGN_CENTER; \
  1074. }laElse(uil,b4);{ \
  1075. laShowItemFull(uil,crr,&rb->PP,"play",0,"icon=▶;mode=PLAY;",0,0) \
  1076. ->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_EXIT_WHEN_TRIGGERED; \
  1077. }laEndCondition(uil,b4); \
  1078. laShowItemFull(uil,c,&rb->PP,"page",LA_WIDGET_COLLECTION_SINGLE,0,laui_RackPage,0)->Flags|=LA_UI_FLAGS_NO_DECAL; \
  1079. }laEndCondition(uil,b3); \
  1080. laUiItem* b1=laOnConditionThat(uil,cr,laPropExpression(Extra,"detached"));{
  1081. laUiItem* rb=laShowInvisibleItem(uil,cr,Extra,"page");
  1082. ADD_PAGE
  1083. }laElse(uil,b1);{
  1084. laUiItem* rb=laShowInvisibleItem(uil,cr,0,"la.audio.current_synth");
  1085. ADD_PAGE
  1086. }laEndCondition(uil,b1);
  1087. #undef ADD_PAGE
  1088. }
  1089. void laui_AudioChannel(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  1090. laColumn* c=laFirstColumn(uil); laSplitColumn(uil,c,0.3); laColumn* c1=laLeftColumn(c,1),*c2=laRightColumn(c,0); laUiItem* b;
  1091. laShowHeightAdjuster(uil,c1,This,"__move",0);
  1092. b=laBeginRow(uil,c2,0,0);
  1093. laShowItem(uil,c2,This,"name")->Expand=1;
  1094. laShowItem(uil,c2,This,"remove")->Flags|=LA_UI_FLAGS_ICON;
  1095. laEndRow(uil,b);
  1096. laShowItem(uil,c2,This,"volume");
  1097. laShowSeparator(uil,c);
  1098. }
  1099. void laui_AudioChannels(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  1100. laColumn* c=laFirstColumn(uil); laUiItem* b;
  1101. b=laBeginRow(uil,c,0,0);
  1102. laShowItem(uil,c,0,"LA_new_channel");
  1103. laEndRow(uil,b);
  1104. // if horizontal look:
  1105. // laUiItem* g=laMakeGroup(uil,c,"Racks",0);{ g->Flags|=/*LA_UI_FLAGS_NO_GAP|LA_UI_FLAGS_NO_DECAL|*/LA_UI_FLAGS_NODE_CONTAINER;
  1106. // laUiList* gu=g->Page; laColumn* gc=laFirstColumn(gu); gu->HeightCoeff=-1; g->State=LA_UI_ACTIVE;
  1107. // laShowItemFull(gu,gc,0,"la.audio.channels",0,0,laui_AudioChannel,0)->Expand=5;
  1108. // }
  1109. laShowItemFull(uil,c,0,"la.audio.channels",0,0,laui_AudioChannel,0);
  1110. }
  1111. void* laget_FirstAudioDevice(void* unused1,void* unused2){
  1112. return MAIN.Audio->AudioDevices.pFirst;
  1113. }
  1114. void* laget_FirstSynth(void* unused1,void* unused2){
  1115. return MAIN.Audio->Synths.pFirst;
  1116. }
  1117. void* laget_FirstAudioChannel(void* unused1, void* unused2){
  1118. return MAIN.Audio->Channels.pFirst;
  1119. }
  1120. void lapost_Synth(laSynth* ss){
  1121. laSpinInit(&ss->Lock);
  1122. laRebuildPageEval(ss->Page);
  1123. }
  1124. int laget_SynthPlaying(laSynth* ss){
  1125. int play=0;
  1126. laSpinLock(&ss->Lock); play=ss->Playing; laSpinUnlock(&ss->Lock);
  1127. return play;
  1128. }
  1129. void laset_CurrentSynth(laAudio* a,laSynth* s){
  1130. memAssignRef(a,&a->CurrentSynth,s);
  1131. }
  1132. void laset_CurrentAudioDevice(laAudio* a,laAudioDevice* ad){
  1133. la_SelectAudioDevice(ad);
  1134. }
  1135. void laset_OutputSendChannel(laSynthNodeOutput* n,laAudioChannel* ac){
  1136. if(ac){ strSafeSet(&n->SendName, SSTR(ac->Name)); } else { strSafeSet(&n->SendName,""); }
  1137. laAudioChannel* outchannel = laGetAudioChannel(SSTR(n->SendName));
  1138. memAssignRef(n,&n->Send,outchannel);
  1139. }
  1140. void laset_OutputSendName(laSynthNodeOutput* n,char* name){
  1141. strSafeSet(&n->SendName,name);
  1142. laAudioChannel* outchannel = laGetAudioChannel(name);
  1143. memAssignRef(n,&n->Send,outchannel);
  1144. }
  1145. void laset_QuantizeEnabledKeys(laSynthNodeQuantize* n, int index, int val_UNUSED){
  1146. if(n->EnabledBits[index] & 0x1){ n->EnabledBits[index]=0; }
  1147. else{ n->EnabledBits[index]=1; }
  1148. }
  1149. void laset_AudioChannelMove(laAudioChannel* ac, int move){
  1150. if(move<0 && ac->Item.pPrev){ lstMoveUp(&MAIN.Audio->Channels, ac); laNotifyUsers("la.audio"); }
  1151. elif(move>0 && ac->Item.pNext){ lstMoveDown(&MAIN.Audio->Channels, ac); laNotifyUsers("la.audio"); }
  1152. }
  1153. void laset_SynthTriggerTrigger(laSynthNodeTrigger* n, int trig){
  1154. if(trig){ laSynthTriggerNew(n->Target); } n->iTrigger=trig;
  1155. }
  1156. void laset_MiniAudioBackend(void* unused, int backend){
  1157. laStopAudio();
  1158. ma_device_uninit(&MAIN.Audio->AudioDevice);
  1159. ma_context_uninit(&MAIN.Audio->MiniAudioContext);
  1160. MAIN.Audio->MiniAudioBackend = backend;
  1161. ma_backend _backends[1]; _backends[0] = MAIN.Audio->MiniAudioBackend; ma_backend* backends=_backends;
  1162. int numback=1;
  1163. if(backend==ma_backend_null){ numback=0; backends=0; }
  1164. if (ma_context_init(backends, numback, NULL, &MAIN.Audio->MiniAudioContext) != MA_SUCCESS) {
  1165. printf("Can't init miniaudio context\n"); MAIN.Audio->MiniAudioBackend=ma_backend_null;
  1166. }
  1167. laRefreshAudioDevices();
  1168. la_SelectAudioDevice(MAIN.Audio->AudioDevices.pFirst);
  1169. }
  1170. void la_AudioPreFrame(){
  1171. if(MAIN.GraphNeedsRebuild){ laRebuildSynthGraphs(1); }
  1172. }
  1173. void laInitAudio(){
  1174. laPropContainer* pc; laProp* p; laSubProp* sp;
  1175. laInitMiniAudio();
  1176. laRegisterUiTemplate("LAUI_synthesizers","Synthesizers",laui_Synthersizers,lauidetached_Synthersizers,0,"Audio",0,0,0);
  1177. laRegisterUiTemplate("LAUI_audio_channels","Mixer",laui_AudioChannels,0,0,0,0,0,0);
  1178. laCreateOperatorType("LA_new_synth", "New Synthesizer", "Add a synthesizer",0,0,0,OPINV_ShedNewSynth,0,'+',0);
  1179. laCreateOperatorType("LA_remove_synth", "Remove Synthesizer", "Remove a synthesizer",OPCHK_IslaSynth,0,0,OPINV_ShedRemoveSynth,OPMOD_FinishOnData,L'🗴',0)
  1180. ->UiDefine=laui_RemoveSynth;
  1181. laCreateOperatorType("LA_synth_play", "Play Synthesizer", "Play a synthesizer",OPCHK_IslaSynth,0,0,OPINV_SynthPlay,0,0,0);
  1182. laCreateOperatorType("LA_synth_trigger_new", "Trigger New", "Trigger a new polyphonic note",OPCHK_IslaSynth,0,0,OPINV_SynthTriggerNew,0,0,0);
  1183. laCreateOperatorType("LA_refresh_audio_devices", "Refresh Audio Devices", "Enumerate audio devices for selection",0,0,0,OPINV_RefreshAudioDevices,0,U'🗘',0);
  1184. laCreateOperatorType("LA_new_channel", "New Channel", "Add an audio channel",0,0,0,OPINV_ShedNewAudioChannel,0,'+',0);
  1185. laCreateOperatorType("LA_remove_channel", "Remove Channel", "Remove an audio channel",OPCHK_IslaAudioChannel,0,0,OPINV_ShedRemoveAudioChannel,OPMOD_FinishOnData,L'🗴',0)
  1186. ->UiDefine=laui_RemoveAudioChannel;
  1187. pc = laAddPropertyContainer("la_audio_device","LaGUI Audio Device","LaGUI enumerated audio device",0,0,sizeof(laAudioDevice),0,0,1);{
  1188. laAddStringProperty(pc,"name","Name","Name of the audio device",0,0,0,0,1,offsetof(laAudioDevice,Name),0,0,0,0,LA_AS_IDENTIFIER);
  1189. }
  1190. pc = laAddPropertyContainer("la_synth", "LaGUI Synthesizer", "LaGUI synthesizer", 0,0,sizeof(laSynth),lapost_Synth,0,2);{
  1191. LA_PC_SYNTH=pc;
  1192. laAddStringProperty(pc,"name","Name","Name of the synthesizer",0,0,0,0,1,offsetof(laSynth,Name),0,0,0,0,LA_AS_IDENTIFIER);
  1193. laAddSubGroup(pc, "page", "Page", "Rack page","la_rack_page",0,0,0,offsetof(laSynth,Page),0,0,0,0,0,0,0,LA_UDF_SINGLE|LA_HIDE_IN_SAVE);
  1194. p=laAddEnumProperty(pc,"playing","Playing","Synth is playing",0,0,0,0,0,-1,laget_SynthPlaying,0,0,0,0,0,0,0,0,LA_READ_ONLY);
  1195. laAddEnumItemAs(p,"IDLE","Idle","Synth is not playing",0,0);
  1196. laAddEnumItemAs(p,"PLAYING","Playing","Synth is playing",1,0);
  1197. laAddFloatProperty(pc,"length","Length","Length of this sound",0,0,"s",10,0,0,5,0,offsetof(laSynth,Length),0,0,0,0,0,0,0,0,0,0,0);
  1198. p=laAddEnumProperty(pc,"poly","Polyphonic","Whether this synth supports polyphonic triggering",0,0,0,0,0,offsetof(laSynth,Poly),0,0,0,0,0,0,0,0,0,0);
  1199. p->ElementBytes=2;
  1200. laAddEnumItemAs(p,"MONO","Mono","Synth is monophonic",0,0);
  1201. laAddEnumItemAs(p,"POLY","Poly","Synth is polyphonic",1,0);
  1202. laAddIntProperty(pc,"max_poly","Max Poly","Max polyphonic sound count",0,0,0,16,0,0,0,0,offsetof(laSynth,MaxPoly),0,0,0,0,0,0,0,0,0,0,0)->ElementBytes=2;
  1203. laAddOperatorProperty(pc,"remove_synth","Remove Synth", "Remove synth", "LA_remove_synth", L'🗴', 0);
  1204. laAddOperatorProperty(pc,"play","Play Synth", "Play synth", "LA_synth_play", 0, 0);
  1205. laAddOperatorProperty(pc,"trigger","Trigger", "Trigger a new polyphonic node", "LA_synth_trigger_new", 0, 0);
  1206. }
  1207. pc = laAddPropertyContainer("la_audio_channel", "LaGUI Audio Channel", "LaGUI Audio Channel", 0,0,sizeof(laAudioChannel),0,0,2);{
  1208. LA_PC_CHANNEL=pc;
  1209. laAddStringProperty(pc,"name","Name","Name of the channel",0,0,0,0,1,offsetof(laAudioChannel,Name),0,0,0,0,LA_AS_IDENTIFIER);
  1210. laAddFloatProperty(pc,"volume","Volume","Volume of this channel",0,0,0,15,0,0.05,0,0,offsetof(laAudioChannel,Volume),0,0,0,0,0,0,0,0,0,0,0);
  1211. laAddOperatorProperty(pc,"remove","Remove Channel", "Remove this channel", "LA_remove_channel", L'🗴', 0);
  1212. laAddIntProperty(pc,"__move","Move Slider","Move Slider",LA_WIDGET_HEIGHT_ADJUSTER,0,0,0,0,0,0,0,0,0,laset_AudioChannelMove,0,0,0,0,0,0,0,0,LA_UDF_IGNORE);
  1213. }
  1214. pc=laAddPropertyContainer("la_node_synth_input", "Synth Input Node", "Synthesizer time and trigger input",0,laui_InputNode,sizeof(laSynthNodeInput),lapost_Node,0,1);
  1215. LA_PC_IDN_INPUT=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1216. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1217. laAddSubGroup(pc,"out_time", "Out Time","Time output","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutTime),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1218. laAddSubGroup(pc,"out_trigger", "Out Trigger","Trigger output","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutTrigger),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1219. laAddSubGroup(pc,"out_l", "Out Left","Capture left","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutL),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1220. laAddSubGroup(pc,"out_r", "Out Right","Capture right","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutR),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1221. pc=laAddPropertyContainer("la_node_synth_pulse", "Synth Pulse Node", "Pulse generate node for synth",0,laui_PulseNode,sizeof(laSynthNodePulse),lapost_Node,0,1);
  1222. LA_PC_IDN_PULSE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1223. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1224. laAddSubGroup(pc,"out", "Out","Pulse output","la_out_socket",0,0,0,offsetof(laSynthNodePulse,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1225. laAddSubGroup(pc,"in_trigger", "In Trigger","Trigger input","la_in_socket",0,0,0,offsetof(laSynthNodePulse,InTrigger),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1226. laAddSubGroup(pc,"in_width", "In Width","Width input","la_in_socket",0,0,0,offsetof(laSynthNodePulse,InWidth),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1227. laAddSubGroup(pc,"in_gate", "In Gate","Gate input","la_in_socket",0,0,0,offsetof(laSynthNodePulse,InGate),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1228. laAddFloatProperty(pc,"influence","Influence","Influence of the width input",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodePulse,rInfluence),0,0,0,0,0,0,0,0,0,0,0);
  1229. laAddFloatProperty(pc,"width","Width","Width of the pulse",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodePulse,rWidth),0,0,0,0,0,0,0,0,0,0,0);
  1230. laAddFloatProperty(pc,"gate","Gate","Gate of the trigger",0,0,0,10,-10,0.1,0,0,offsetof(laSynthNodePulse,rGate),0,0,0,0,0,0,0,0,0,0,0);
  1231. p=laAddEnumProperty(pc,"trigger","Trigger","Trigger the envelope",LA_WIDGET_ENUM_CYCLE,0,0,0,0,offsetof(laSynthNodePulse,iTrigger),0,0,0,0,0,0,0,0,0,0);
  1232. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  1233. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  1234. pc=laAddPropertyContainer("la_node_synth_fm", "FM OSC Node", "Osilliator node with frequency modulation",0,laui_FMNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
  1235. LA_PC_IDN_FM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1236. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1237. laAddSubGroup(pc,"in_frequency", "In Frequency","Input frequency","la_in_socket",0,0,0,offsetof(laSynthNodeFM,InFrequency),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1238. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeFM,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1239. laAddFloatProperty(pc,"frequency","Frequency","Frequency of the oscilliator",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeFM,Frequency),0,0,0,0,0,0,0,0,0,0,0);
  1240. laAddFloatProperty(pc,"influence","Influence","Influence of the molulation input",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeFM,rInfluence),0,0,0,0,0,0,0,0,0,0,0);
  1241. p=laAddEnumProperty(pc,"slow","Slow","Low frequency oscilliator",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laSynthNodeFM,Slow),0,0,0,0,0,0,0,0,0,0);
  1242. laAddEnumItemAs(p,"NONE","None","Regular frequency range",0,0);
  1243. laAddEnumItemAs(p,"SLOW","Slow","Slow frequency range",1,0);
  1244. pc=laAddPropertyContainer("la_node_synth_vca", "VCA Node", "Voltage controlled amplifier",0,laui_VCANode,sizeof(laSynthNodeVCA),lapost_Node,0,1);
  1245. LA_PC_IDN_VCA=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1246. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1247. laAddSubGroup(pc,"in_amp", "In Amptitude","Input amptitude","la_in_socket",0,0,0,offsetof(laSynthNodeVCA,InAmp),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1248. laAddSubGroup(pc,"in", "Input","Input","la_in_socket",0,0,0,offsetof(laSynthNodeVCA,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1249. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeVCA,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1250. laAddFloatProperty(pc,"amp","Amptitude","Amptitude of the output signal",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeVCA,Amp),0,0,0,0,0,0,0,0,0,0,0);
  1251. laAddFloatProperty(pc,"influence","Influence","Influence of the modulating signal",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeVCA,rInfluence),0,0,0,0,0,0,0,0,0,0,0);
  1252. pc=laAddPropertyContainer("la_node_synth_noise", "Noise Node", "Noise node",0,laui_NoiseNode,sizeof(laSynthNodeNoise),lapost_Node,0,1);
  1253. LA_PC_IDN_NOISE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1254. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1255. laAddSubGroup(pc,"out_white", "White","White noise output","la_out_socket",0,0,0,offsetof(laSynthNodeNoise,OutWhite),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1256. laAddSubGroup(pc,"out_pink", "Pink","Pinknoise output","la_out_socket",0,0,0,offsetof(laSynthNodeNoise,OutPink),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1257. pc=laAddPropertyContainer("la_node_synth_scope", "Scope Node", "Scope for synthesizer",0,laui_ScopeNode,sizeof(laSynthNodeScope),lapost_Node,0,1);
  1258. LA_PC_IDN_SCOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1259. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1260. laAddSubGroup(pc,"scope", "Scope","Synth scope","la_node_synth_scope",0,LA_WIDGET_SCOPE,0,-1,0,laget_InstanceSelf,0,0,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  1261. laAddSubGroup(pc,"in1", "In 1","Input Channel 1","la_in_socket",0,0,0,offsetof(laSynthNodeScope,In1),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1262. laAddSubGroup(pc,"in2", "In 2","Input Channel 2","la_in_socket",0,0,0,offsetof(laSynthNodeScope,In2),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1263. p=laAddEnumProperty(pc,"time","Time","Time factor of the scope",0,0,0,5,0,offsetof(laSynthNodeScope,Time),0,0,0,0,0,0,0,0,0,0);
  1264. #define _STR(a) #a
  1265. #define ADD_TIME_FACTOR(a) laAddEnumItemAs(p,"FAC"_STR(a),_STR(a),"^"_STR(a)" time",a,0);
  1266. ADD_TIME_FACTOR(1) ADD_TIME_FACTOR(2) ADD_TIME_FACTOR(3) ADD_TIME_FACTOR(4) ADD_TIME_FACTOR(5)
  1267. ADD_TIME_FACTOR(6) ADD_TIME_FACTOR(7) ADD_TIME_FACTOR(8) ADD_TIME_FACTOR(9) ADD_TIME_FACTOR(10)
  1268. #undef ADD_TIME_FACTOR
  1269. p=laAddEnumProperty(pc,"gain1","Gain 1","Channel 1 Gain",0,0,0,5,0,offsetof(laSynthNodeScope,Gain1),0,0,0,0,0,0,0,0,0,0);
  1270. #define ADD_GAIN(a) laAddEnumItemAs(p,"GAIN"_STR(a),_STR(a),"^"_STR(a)" gain",a,0);
  1271. #define ADD_GAIN_S(a,s) laAddEnumItemAs(p,"GAIN"_STR(a),s,"^"s" gain",a,0);
  1272. ADD_GAIN_S(-1,"¼") ADD_GAIN_S(0,"½") ADD_GAIN(1) ADD_GAIN(2) ADD_GAIN(3) ADD_GAIN(4) ADD_GAIN(5) ADD_GAIN(6)
  1273. p=laAddEnumProperty(pc,"gain2","Gain 2","Channel 2 Gain",0,0,0,5,0,offsetof(laSynthNodeScope,Gain2),0,0,0,0,0,0,0,0,0,0);
  1274. ADD_GAIN_S(-1,"¼") ADD_GAIN_S(0,"½") ADD_GAIN(1) ADD_GAIN(2) ADD_GAIN(3) ADD_GAIN(4) ADD_GAIN(5) ADD_GAIN(6)
  1275. #undef ADD_GAIN
  1276. #undef ADD_GAIN_S
  1277. laAddFloatProperty(pc,"offset1","Offset 1","Channel 1 offset",0,0,0,10,-10,0.1,0,0,offsetof(laSynthNodeScope,Offset1),0,0,0,0,0,0,0,0,0,0,0);
  1278. laAddFloatProperty(pc,"offset2","Offset 2","Channel 2 offset",0,0,0,10,-10,0.1,0,0,offsetof(laSynthNodeScope,Offset2),0,0,0,0,0,0,0,0,0,0,0);
  1279. laAddFloatProperty(pc,"bright1","Brightness 1","Channel 1 brightness",0,0,0,1,0,0.1,0,0,offsetof(laSynthNodeScope,Brightness1),0,0,0,0,0,0,0,0,0,0,0);
  1280. laAddFloatProperty(pc,"bright2","Brightness 2","Channel 2 brightness",0,0,0,1,0,0.1,0,0,offsetof(laSynthNodeScope,Brightness2),0,0,0,0,0,0,0,0,0,0,0);
  1281. pc=laAddPropertyContainer("la_node_synth_output", "Output Node", "Sound output to system",0,laui_OutputNode,sizeof(laSynthNodeOutput),lapost_Node,0,1);
  1282. LA_PC_IDN_OUTPUT=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1283. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1284. laAddSubGroup(pc,"in_l", "Input Left","Input sound left channel","la_in_socket",0,0,0,offsetof(laSynthNodeOutput,InL),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1285. laAddSubGroup(pc,"in_r", "Input Right","Input sound right channel","la_in_socket",0,0,0,offsetof(laSynthNodeOutput,InR),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1286. laAddStringProperty(pc,"send_channel_name","Channel Name","Channel name of this send target",0,0,0,0,1,offsetof(laSynthNodeOutput,SendName),0,0,laset_OutputSendName,0,0);
  1287. laAddSubGroup(pc,"send_channel_selector","Send","Send to channel","la_audio_channel",0,0,0,-1,laget_FirstAudioChannel,0,laget_ListNext,laset_OutputSendChannel,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  1288. pc=laAddPropertyContainer("la_node_synth_envelope", "Envelope Node", "Sound envelope",0,laui_EnvelopeNode,sizeof(laSynthNodeEnvelope),lapost_Node,0,1);
  1289. LA_PC_IDN_ENVELOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1290. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1291. laAddSubGroup(pc,"in_gate", "Gate","Gate input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Gate),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1292. laAddSubGroup(pc,"in_attack", "Attack","Attack input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Attack),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1293. laAddSubGroup(pc,"in_delay", "Delay","Delay input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Delay),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1294. laAddSubGroup(pc,"in_sustain", "Sustain","Sustain input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Sustain),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1295. laAddSubGroup(pc,"in_release", "Release","Release input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Release),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1296. laAddSubGroup(pc,"in_trigger", "Trigger","Trigger input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Trigger),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1297. laAddSubGroup(pc,"in_restart", "Restart","Restart input","la_in_socket",0,0,0,offsetof(laSynthNodeEnvelope,Restart),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1298. laAddSubGroup(pc,"out", "Output","Envelope output","la_out_socket",0,0,0,offsetof(laSynthNodeEnvelope,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1299. laAddFloatProperty(pc,"gate","Gate","Gate for the trigger",0,0,0,10,-10,0.01,0,0,offsetof(laSynthNodeEnvelope,rGate),0,0,0,0,0,0,0,0,0,0,0);
  1300. laAddFloatProperty(pc,"attack","Attack","Attack value",0,0,0,10,0,0.01,0,0,offsetof(laSynthNodeEnvelope,rAttack),0,0,0,0,0,0,0,0,0,0,0);
  1301. laAddFloatProperty(pc,"delay","Delay","Delay value",0,0,0,10,0,0.01,0,0,offsetof(laSynthNodeEnvelope,rDelay),0,0,0,0,0,0,0,0,0,0,0);
  1302. laAddFloatProperty(pc,"sustain","Sustain","Sustain value",0,0,0,10,0,0.01,0,0,offsetof(laSynthNodeEnvelope,rSustain),0,0,0,0,0,0,0,0,0,0,0);
  1303. laAddFloatProperty(pc,"release","Release","Release value",0,0,0,10,0,0.01,0,0,offsetof(laSynthNodeEnvelope,rRelease),0,0,0,0,0,0,0,0,0,0,0);
  1304. laAddFloatProperty(pc,"iattack","Attack Influence","Attack modulation influence value",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeEnvelope,iAttack),0,0,0,0,0,0,0,0,0,0,0);
  1305. laAddFloatProperty(pc,"idelay","Delay Influence","Delay modulation influence value",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeEnvelope,iDelay),0,0,0,0,0,0,0,0,0,0,0);
  1306. laAddFloatProperty(pc,"isustain","Sustain Influence","Sustain modulation influence value",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeEnvelope,iSustain),0,0,0,0,0,0,0,0,0,0,0);
  1307. laAddFloatProperty(pc,"irelease","Release Influence","Release modulation influence value",LA_WIDGET_KNOB,0,0,1,-1,0.01,0,0,offsetof(laSynthNodeEnvelope,iRelease),0,0,0,0,0,0,0,0,0,0,0);
  1308. p=laAddEnumProperty(pc,"trigger","Trigger","Trigger the envelope",LA_WIDGET_ENUM_CYCLE,0,0,0,0,offsetof(laSynthNodeEnvelope,bTrigger),0,0,0,0,0,0,0,0,0,0);
  1309. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  1310. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  1311. pc=laAddPropertyContainer("la_node_synth_driver", "Synth Driver Node", "Control playing status of the synth",0,laui_SynthDriverNode,sizeof(laSynthNodeDriver),lapost_Node,0,1);
  1312. LA_PC_IDN_SYNTH_DRIVER=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1313. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1314. laAddSubGroup(pc,"prev", "Previous","Previous node","la_in_socket",0,0,0,offsetof(laSynthNodeDriver,Prev),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1315. laAddSubGroup(pc,"next", "Next","Next node","la_out_socket",0,0,0,offsetof(laSynthNodeDriver,Next),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1316. laAddSubGroup(pc,"in_transport", "In Transport","Transport input","la_in_socket",0,0,0,offsetof(laSynthNodeDriver,InTransport),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1317. laAddSubGroup(pc,"in_reset", "In Reset","Reset input (trigger on rising edge)","la_in_socket",0,0,0,offsetof(laSynthNodeDriver,InReset),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1318. p=laAddEnumProperty(pc,"transport","Transport","Play or stop the synth playing",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laSynthNodeDriver,iTransport),0,0,0,0,0,0,0,0,0,0);
  1319. laAddEnumItemAs(p,"STOPPED","Stopped","Synth is stopped",0,0);
  1320. laAddEnumItemAs(p,"PLAYING","Playing","Synth is playing",1,0);
  1321. p=laAddEnumProperty(pc,"reset","Reset","Reset Synth",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laSynthNodeDriver,iReset),0,0,0,0,0,0,0,0,0,0);
  1322. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  1323. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  1324. laAddSubGroup(pc,"target","Target","Target synth to control","la_synth",0,0,0,offsetof(laSynthNodeDriver,Target),laget_FirstSynth,0,laget_ListNext,0,0,0,0,LA_UDF_REFER);
  1325. pc=laAddPropertyContainer("la_node_synth_trigger", "Synth Trigger Node", "Trigger a new polyphonic note",0,laui_SynthTriggerNode,sizeof(laSynthNodeTrigger),lapost_Node,0,1);
  1326. LA_PC_IDN_SYNTH_TRIGGER=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1327. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1328. laAddSubGroup(pc,"prev", "Previous","Previous node","la_in_socket",0,0,0,offsetof(laSynthNodeTrigger,Prev),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1329. laAddSubGroup(pc,"next", "Next","Next node","la_out_socket",0,0,0,offsetof(laSynthNodeTrigger,Next),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1330. laAddSubGroup(pc,"in_trigger", "In Trigger","Trigger input","la_in_socket",0,0,0,offsetof(laSynthNodeTrigger,InTrigger),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1331. p=laAddEnumProperty(pc,"trigger","Trigger","Trigger new note",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laSynthNodeTrigger,iTrigger),0,laset_SynthTriggerTrigger,0,0,0,0,0,0,0,0);
  1332. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  1333. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  1334. p=laAddEnumProperty(pc,"trigger_edge","Edge","Trigger on rising edge",LA_WIDGET_ENUM_HIGHLIGHT,0,0,0,0,offsetof(laSynthNodeTrigger,TriggerEdge),0,0,0,0,0,0,0,0,0,0);
  1335. laAddEnumItemAs(p,"LEVEL","Level","Trigger on high level",0,'-');
  1336. laAddEnumItemAs(p,"RISING_EDGE","Rising Edge","Trigger on rising edge",1,U'⮥');
  1337. laAddSubGroup(pc,"target","Target","Target synth to trigger","la_synth",0,0,0,offsetof(laSynthNodeTrigger,Target),laget_FirstSynth,0,laget_ListNext,0,0,0,0,LA_UDF_REFER);
  1338. pc=laAddPropertyContainer("la_node_synth_quantize", "Quantize Node", "Quantize control voltages",0,laui_QuantizeNode,sizeof(laSynthNodeQuantize),lapost_Node,0,1);
  1339. LA_PC_IDN_QUANTIZE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  1340. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  1341. laAddSubGroup(pc,"in", "Input","CV input","la_in_socket",0,0,0,offsetof(laSynthNodeQuantize,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1342. laAddSubGroup(pc,"out", "Output","CV output","la_out_socket",0,0,0,offsetof(laSynthNodeQuantize,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  1343. p=laAddEnumProperty(pc,"enabled_keys","Keys","Enabled keys",LA_WIDGET_ENUM_CYCLE,0,0,0,0,offsetof(laSynthNodeQuantize,EnabledBits),0,0,12,0,laset_QuantizeEnabledKeys,0,0,0,0,0);
  1344. laAddEnumItemAs(p,"DISABLED","Disabled","Key is disabled",0,' ');
  1345. laAddEnumItemAs(p,"ENABLED","Enabled","Key is enabled",1,' ');
  1346. laAddEnumItemAs(p,"OUTPUT","Outputting","Key is Outputting",3,U'🌑');
  1347. LA_IDN_REGISTER("Inputs",U'🔌',LA_IDN_INPUT, LA_PC_IDN_INPUT, IDN_Input, laSynthNodeInput);
  1348. LA_IDN_REGISTER("Pulse",U'⎍',LA_IDN_PULSE, LA_PC_IDN_PULSE, IDN_Pulse, laSynthNodePulse);
  1349. LA_IDN_REGISTER("VCO",'f',LA_IDN_FM, LA_PC_IDN_FM, IDN_FM, laSynthNodeFM);
  1350. LA_IDN_REGISTER("VCA",'a',LA_IDN_VCA, LA_PC_IDN_VCA, IDN_VCA, laSynthNodeVCA);
  1351. LA_IDN_REGISTER("Noise",'~',LA_IDN_NOISE, LA_PC_IDN_NOISE, IDN_Noise, laSynthNodeNoise);
  1352. LA_IDN_REGISTER("Scope",'s',LA_IDN_SCOPE, LA_PC_IDN_SCOPE, IDN_Scope, laSynthNodeScope);
  1353. LA_IDN_REGISTER("Sound Output",U'🕪',LA_IDN_OUTPUT, LA_PC_IDN_OUTPUT, IDN_Output, laSynthNodeOutput);
  1354. LA_IDN_REGISTER("Envelope",U'^',LA_IDN_ENVELOPE, LA_PC_IDN_ENVELOPE, IDN_Envelope, laSynthNodeEnvelope);
  1355. LA_IDN_REGISTER("Quantize",U'#',LA_IDN_QUANTIZE, LA_PC_IDN_QUANTIZE, IDN_Quantize, laSynthNodeQuantize);
  1356. LA_IDN_REGISTER("Sound Player",U'⏯',LA_IDN_SYNTH_DRIVER, LA_PC_IDN_SYNTH_DRIVER, IDN_SynthDriver, laSynthNodeDriver);
  1357. LA_IDN_REGISTER("Sound Trigger",U'🎵',LA_IDN_SYNTH_TRIGGER, LA_PC_IDN_SYNTH_TRIGGER, IDN_SynthTrigger, laSynthNodeTrigger);
  1358. LA_NODE_CATEGORY_SYNTHESIZER=laEnsureNodeCategory("OSC",0,LA_RACK_TYPE_AUDIO);
  1359. LA_NODE_CATEGORY_SYSTEM_SOUND=laEnsureNodeCategory("System",0,LA_RACK_TYPE_AUDIO);
  1360. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER,
  1361. &LA_IDN_INPUT,&LA_IDN_PULSE,&LA_IDN_FM,&LA_IDN_NOISE,&LA_IDN_VCA,&LA_IDN_ENVELOPE,&LA_IDN_QUANTIZE,&LA_IDN_SCOPE,&LA_IDN_SYNTH_TRIGGER,0LL);
  1362. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYSTEM_SOUND, &LA_IDN_OUTPUT,0LL);
  1363. LA_NODE_CATEGORY_DRIVER=laEnsureNodeCategory("Driver",0,LA_RACK_TYPE_DRIVER);
  1364. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_DRIVER, &LA_IDN_SYNTH_DRIVER, &LA_IDN_SYNTH_TRIGGER,0LL);
  1365. }