*/}}

la_audio.c 77 KB

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