*/}}

la_audio.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. laNodeCategory* LA_NODE_CATEGORY_SYNTHESIZER;
  24. laNodeCategory* LA_NODE_CATEGORY_SYSTEM_SOUND;
  25. laBaseNodeType LA_IDN_FM;
  26. laBaseNodeType LA_IDN_VCA;
  27. laBaseNodeType LA_IDN_NOISE;
  28. laBaseNodeType LA_IDN_OUTPUT;
  29. laBaseNodeType LA_IDN_SCOPE;
  30. laBaseNodeType LA_IDN_ENVELOPE;
  31. laPropContainer* LA_PC_IDN_FM;
  32. laPropContainer* LA_PC_IDN_VCA;
  33. laPropContainer* LA_PC_IDN_NOISE;
  34. laPropContainer* LA_PC_IDN_OUTPUT;
  35. laPropContainer* LA_PC_IDN_SCOPE;
  36. laPropContainer* LA_PC_IDN_ENVELOPE;
  37. #define _2PI 6.283185307
  38. #define VAL2FREQ(val) \
  39. 16.0f*pow(2,val) // 0-10, 16-16384Hz
  40. #define WRAPPHASE(p) \
  41. while(p>_2PI){ p-=_2PI; }
  42. #define INITPACKET(arr) \
  43. if(!arr){ arr=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  44. #define INPUTPACKET(ptr,socket) \
  45. {if(socket->Source && socket->Source->DataType==(LA_PROP_FLOAT|LA_PROP_ARRAY) && socket->Source->ArrLen>=LA_SYNTH_PLEN){ \
  46. ptr=((real*)socket->Source->Data); }else{ ptr=0; } }
  47. #define FRAME_INTERVAL (MAIN.Audio->AudioFrameInterval)
  48. #define SAMPLE_RATE (MAIN.Audio->AudioSampleRate)
  49. void IDN_FMInit(laSynthNodeFM* n, int NoCreate){
  50. INITPACKET(n->OutSamples);
  51. if(NoCreate){ return; }
  52. n->InFrequency=laCreateInSocket("FREQ",0); n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  53. strSafeSet(&n->Base.Name,"FM"); n->Frequency=4;
  54. }
  55. void IDN_FMDestroy(laSynthNodeFM* n){
  56. laDestroyInSocket(n->InFrequency); laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  57. }
  58. int IDN_FMVisit(laSynthNodeFM* n, laNodeVisitInfo* vi){
  59. LA_GUARD_THIS_NODE(n,vi);
  60. if(LA_SRC_AND_PARENT(n->InFrequency)){ laBaseNode*bn=n->InFrequency->Source->Parent; LA_VISIT_NODE(bn,vi); }
  61. LA_ADD_THIS_NODE(n,vi);
  62. return LA_DAG_FLAG_PERM;
  63. }
  64. int IDN_FMEval(laSynthNodeFM* n){
  65. real f=n->Frequency, constf=0; real* inputf;
  66. INPUTPACKET(inputf,n->InFrequency); LA_GET_SRC_AS_VALUE(constf,n->InFrequency);
  67. for(int i=0;i<LA_SYNTH_PLEN;i++){
  68. real useF=inputf?(inputf[i]+f):(f+constf); if(n->Slow) useF-=10;
  69. n->Phase+=FRAME_INTERVAL*VAL2FREQ(useF)*_2PI;
  70. WRAPPHASE(n->Phase);
  71. n->OutSamples[i]=sin(n->Phase)*10;
  72. }
  73. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  74. return 1;
  75. }
  76. void IDN_FMCopy(laSynthNodeFM* new, laSynthNodeFM* old, int DoRematch){
  77. if(DoRematch){ LA_IDN_NEW_LINK(InFrequency) return; }
  78. LA_IDN_OLD_DUPL(Out); new->Frequency=old->Frequency; new->Slow=old->Slow;
  79. }
  80. void laui_FMNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  81. laColumn* c=laFirstColumn(uil); laSynthNodeFM*n=This->EndInstance;
  82. LA_BASE_NODE_HEADER(uil,c,This);
  83. laUiItem* b=laBeginRow(uil,c,0,0);
  84. laShowNodeSocket(uil,c,This,"in_frequency",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  85. laShowItem(uil,c,This,"slow");
  86. laShowItem(uil,c,This,"frequency")->Expand=1;
  87. laShowNodeSocket(uil,c,This,"out",0);
  88. laEndRow(uil,b);
  89. }
  90. void IDN_VCAInit(laSynthNodeVCA* n, int NoCreate){
  91. INITPACKET(n->OutSamples);
  92. if(NoCreate){ return; }
  93. n->InAmp=laCreateInSocket("AMP",0); n->In=laCreateInSocket("IN",0);
  94. n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  95. strSafeSet(&n->Base.Name,"FM"); n->Amp=10;
  96. }
  97. void IDN_VCADestroy(laSynthNodeVCA* n){
  98. laDestroyInSocket(n->InAmp); laDestroyInSocket(n->In);
  99. laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  100. }
  101. int IDN_VCAVisit(laSynthNodeVCA* n, laNodeVisitInfo* vi){
  102. LA_GUARD_THIS_NODE(n,vi);
  103. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  104. if(LA_SRC_AND_PARENT(n->InAmp)){ laBaseNode*bn=n->InAmp->Source->Parent; LA_VISIT_NODE(bn,vi); }
  105. LA_ADD_THIS_NODE(n,vi);
  106. return LA_DAG_FLAG_PERM;
  107. }
  108. int IDN_VCAEval(laSynthNodeVCA* n){
  109. real amp=n->Amp, constamp=amp; real* inputamp=0,*input=0;
  110. INPUTPACKET(input,n->In); INPUTPACKET(inputamp,n->InAmp);
  111. if(!inputamp) LA_GET_SRC_AS_VALUE(constamp,n->InAmp); constamp/=10;
  112. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  113. if(!input){ memset(n->OutSamples,0,sizeof(real)*LA_SYNTH_PLEN); return 0; }
  114. for(int i=0;i<LA_SYNTH_PLEN;i++){
  115. real useA=(inputamp?(inputamp[i]/10):1)*constamp;
  116. n->OutSamples[i]= input[i]*useA;
  117. }
  118. return 1;
  119. }
  120. void IDN_VCACopy(laSynthNodeVCA* new, laSynthNodeVCA* old, int DoRematch){
  121. if(DoRematch){ LA_IDN_NEW_LINK(InAmp) LA_IDN_NEW_LINK(In) return; }
  122. LA_IDN_OLD_DUPL(Out); new->Amp=old->Amp;
  123. }
  124. void laui_VCANode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  125. laColumn* c=laFirstColumn(uil); laSynthNodeVCA*n=This->EndInstance;
  126. LA_BASE_NODE_HEADER(uil,c,This);
  127. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  128. laUiItem* b=laBeginRow(uil,c,0,0);
  129. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  130. laShowNodeSocket(uil,c,This,"in_amp",0);
  131. laShowItem(uil,c,This,"amp")->Expand=1;
  132. laShowNodeSocket(uil,cr,This,"out",0);
  133. laEndRow(uil,b);
  134. }
  135. void IDN_NoiseInit(laSynthNodeNoise* n, int NoCreate){
  136. INITPACKET(n->OutWhiteSamples); INITPACKET(n->OutPinkSamples);
  137. n->PinkA[0]=0.02109238; n->PinkA[1]=0.07113478; n->PinkA[2]=0.68873558;
  138. n->PinkP[0]=0.3190; n->PinkP[1]=0.7756; n->PinkP[2]=0.9613;
  139. if(NoCreate){ return; }
  140. n->OutWhite=laCreateOutSocket(n,"WHITE",LA_PROP_FLOAT|LA_PROP_ARRAY);
  141. n->OutPink=laCreateOutSocket(n,"PINK",LA_PROP_FLOAT|LA_PROP_ARRAY);
  142. strSafeSet(&n->Base.Name,"Noise");
  143. }
  144. void IDN_NoiseDestroy(laSynthNodeNoise* n){
  145. laDestroyOutSocket(n->OutWhite); laDestroyOutSocket(n->OutPink); strSafeDestroy(&n->Base.Name);
  146. memFree(n->OutWhiteSamples); memFree(n->OutPinkSamples);
  147. }
  148. int IDN_NoiseVisit(laSynthNodeNoise* n, laNodeVisitInfo* vi){
  149. LA_GUARD_THIS_NODE(n,vi); LA_ADD_THIS_NODE(n,vi);
  150. return LA_DAG_FLAG_PERM;
  151. }
  152. int IDN_NoiseEval(laSynthNodeNoise* n){
  153. real RMI2 = 2.0 / (real)RAND_MAX; // + 1.0; // change for range [0,1)
  154. real offset = n->PinkA[0] + n->PinkA[1] + n->PinkA[2];
  155. for(int i=0;i<LA_SYNTH_PLEN;i++){
  156. real R1=(real)rand()/(real)RAND_MAX;
  157. real R2=(real)rand()/(real)RAND_MAX;
  158. real X=(real)sqrt(-2.0f*log(R1))*cos(2.0f*TNS_PI*R2);
  159. n->OutWhiteSamples[i]=X*2.5;
  160. real temp; for(int i=0;i<3;i++){ temp=(real)rand();
  161. n->PinkStates[i] = n->PinkP[i] * (n->PinkStates[i] - temp) + temp;
  162. }
  163. n->OutPinkSamples[i]=(n->PinkA[0]*n->PinkStates[0]+
  164. n->PinkA[1]*n->PinkStates[1]+
  165. n->PinkA[2]*n->PinkStates[2])*RMI2-offset;
  166. n->OutPinkSamples[i]*=40;
  167. }
  168. n->OutWhite->Data=n->OutWhiteSamples; n->OutWhite->ArrLen=LA_SYNTH_PLEN;
  169. n->OutPink->Data=n->OutPinkSamples; n->OutPink->ArrLen=LA_SYNTH_PLEN;
  170. return 1;
  171. }
  172. void IDN_NoiseCopy(laSynthNodeNoise* new, laSynthNodeNoise* old, int DoRematch){
  173. if(DoRematch){ return; }
  174. LA_IDN_OLD_DUPL(OutWhite);
  175. }
  176. void laui_NoiseNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  177. laColumn* c=laFirstColumn(uil); laSynthNodeNoise*n=This->EndInstance;
  178. LA_BASE_NODE_HEADER(uil,c,This);
  179. laUiItem* b=laBeginRow(uil,c,0,0);
  180. laShowNodeSocket(uil,c,This,"out_white",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  181. laShowNodeSocket(uil,c,This,"out_pink",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  182. laEndRow(uil,b);
  183. }
  184. void IDN_ScopeInit(laSynthNodeScope* n, int NoCreate){
  185. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  186. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  187. laSpinInit(&n->Lock);
  188. if(NoCreate){ return; }
  189. n->In1=laCreateInSocket("CH1",0); n->In2=laCreateInSocket("CH2",0);
  190. strSafeSet(&n->Base.Name,"SCOPE"); n->Time=5; n->Brightness1=0.7f; n->Brightness2=0.4f;
  191. n->Gain1=1; n->Gain2=1;
  192. }
  193. void IDN_ScopeDestroy(laSynthNodeScope* n){
  194. laDestroyInSocket(n->In1); laDestroyOutSocket(n->In2); strSafeDestroy(&n->Base.Name);
  195. memFree(n->Display1); memFree(n->Display2);
  196. laSpinDestroy(&n->Lock);
  197. }
  198. int IDN_ScopeVisit(laSynthNodeScope* n, laNodeVisitInfo* vi){
  199. LA_GUARD_THIS_NODE(n,vi);
  200. if(LA_SRC_AND_PARENT(n->In1)){ laBaseNode*bn=n->In1->Source->Parent; LA_VISIT_NODE(bn,vi); }
  201. if(LA_SRC_AND_PARENT(n->In2)){ laBaseNode*bn=n->In2->Source->Parent; LA_VISIT_NODE(bn,vi); }
  202. LA_ADD_THIS_NODE(n,vi);
  203. return LA_DAG_FLAG_PERM;
  204. }
  205. int IDN_ScopeEval(laSynthNodeScope* n){
  206. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  207. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  208. real* ch1,*ch2; INPUTPACKET(ch1,n->In1); INPUTPACKET(ch2,n->In2);
  209. int Frame=1<<(n->Time-1); TNS_CLAMP(Frame,1,LA_SYNTH_PLEN);
  210. int Times=LA_SYNTH_PLEN/Frame; int sp=0; laSpinLock(&n->Lock);
  211. for(int t=0;t<Times;t++){
  212. real smin1=FLT_MAX,smax1=-FLT_MAX,smin2=FLT_MAX,smax2=-FLT_MAX;
  213. for(int i=0;i<Frame;i++){
  214. if(ch1){ smin1=TNS_MIN2(smin1,ch1[sp]); smax1=TNS_MAX2(smax1,ch1[sp]); }
  215. if(ch2){ smin2=TNS_MIN2(smin2,ch2[sp]); smax2=TNS_MAX2(smax2,ch2[sp]); }
  216. sp++;
  217. }
  218. if(!ch1){smin1=smax1=0; LA_GET_SRC_AS_VALUE(smin1,n->In1); smax1=smin1; }
  219. if(!ch2){smin2=smax2=0; LA_GET_SRC_AS_VALUE(smin2,n->In2); smax2=smin2; }
  220. int ns=n->NextSample;
  221. n->Display1[ns]=smin1; n->Display1[ns+LA_SYNTH_PLEN]=smax1;
  222. n->Display2[ns]=smin2; n->Display2[ns+LA_SYNTH_PLEN]=smax2;
  223. n->NextSample++; if(n->NextSample>=LA_SYNTH_PLEN) n->NextSample=0;
  224. }
  225. n->FromSynth=MAIN.Audio->AudioEvalSynth;
  226. laSpinUnlock(&n->Lock);
  227. return 1;
  228. }
  229. void IDN_ScopeCopy(laSynthNodeScope* new, laSynthNodeScope* old, int DoRematch){
  230. if(DoRematch){ LA_IDN_NEW_LINK(In1) LA_IDN_NEW_LINK(In2) return; }
  231. new->Brightness1=old->Brightness1; new->Brightness2=old->Brightness2;
  232. new->Gain1=old->Gain1; new->Gain2=old->Gain2;
  233. new->Offset1=old->Offset1; new->Offset2=old->Offset2;
  234. new->Time=old->Time;
  235. }
  236. void laui_ScopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  237. laColumn* c=laFirstColumn(uil); laSynthNodeScope*n=This->EndInstance;
  238. LA_BASE_NODE_HEADER(uil,c,This);
  239. laColumn* cl,*cr; laSplitColumn(uil,c,0.5); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  240. laUiItem* b=laBeginRow(uil,c,0,0);
  241. laUiItem* u=laShowItem(uil,c,This,"gain1");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  242. laShowNodeSocket(uil,c,This,"in1",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  243. laEndRow(uil,b);
  244. b=laBeginRow(uil,c,0,0);
  245. u=laShowItem(uil,c,This,"gain2");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  246. laShowNodeSocket(uil,c,This,"in2",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  247. laEndRow(uil,b);
  248. laShowItem(uil,c,This,"scope")->Extra->HeightCoeff=6;
  249. laShowLabel(uil,cl,"CH1",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  250. laShowItem(uil,cl,This,"bright1"); laShowItem(uil,cl,This,"offset1");
  251. laShowLabel(uil,cr,"CH2",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  252. laShowItem(uil,cr,This,"bright2"); laShowItem(uil,cr,This,"offset2");
  253. laShowItem(uil,c,This,"time")->Flags|=LA_UI_FLAGS_EXPAND;
  254. }
  255. void IDN_OutputInit(laSynthNodeOutput* n, int NoCreate){
  256. if(NoCreate){ return; }
  257. n->In=laCreateInSocket("IN",0); strSafeSet(&n->Base.Name,"Output");
  258. }
  259. void IDN_OutputDestroy(laSynthNodeOutput* n){
  260. laDestroyInSocket(n->In); strSafeDestroy(&n->Base.Name);
  261. }
  262. int IDN_OutputVisit(laSynthNodeOutput* n, laNodeVisitInfo* vi){
  263. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  264. LA_ADD_THIS_NODE(n,vi);
  265. return LA_DAG_FLAG_PERM;
  266. }
  267. int IDN_OutputEval(laSynthNodeOutput* n){
  268. real* input; INPUTPACKET(input,n->In);
  269. if(input) memcpy(MAIN.Audio->AudioEvalSynth->AudioSamples,input,sizeof(real)*LA_SYNTH_PLEN);
  270. else memset(MAIN.Audio->AudioEvalSynth->AudioSamples,0,sizeof(real)*LA_SYNTH_PLEN);
  271. return 1;
  272. }
  273. void IDN_OutputCopy(laSynthNodeOutput* new, laSynthNodeOutput* old, int DoRematch){
  274. if(DoRematch){ LA_IDN_NEW_LINK(In) return; }
  275. }
  276. void laui_OutputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  277. laColumn* c=laFirstColumn(uil); laSynthNodeOutput*n=This->EndInstance;
  278. LA_BASE_NODE_HEADER(uil,c,This);
  279. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  280. laUiItem* b=laBeginRow(uil,c,0,0);
  281. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  282. laShowLabel(uil,c,"🕪",0,0);
  283. laEndRow(uil,b);
  284. }
  285. void IDN_EnvelopeInit(laSynthNodeEnvelope* n, int NoCreate){
  286. if(!NoCreate){ strSafeSet(&n->Base.Name,"Envelope");
  287. n->Attack=laCreateInSocket("ATTACK",0); n->Delay=laCreateInSocket("DELAY",0);
  288. n->Sustain=laCreateInSocket("SUSTAIN",0); n->Release=laCreateInSocket("RELEASE",0);
  289. n->Trigger=laCreateInSocket("TRIGGER",0); n->Out=laCreateOutSocket(n, "OUT",0);
  290. }
  291. if(!n->OutSamples){ n->OutSamples=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  292. n->Out->Data = n->OutSamples; n->Out->DataType = LA_PROP_FLOAT|LA_PROP_ARRAY; n->Out->ArrLen=LA_SYNTH_PLEN;
  293. n->Time=20; n->rAttack=1; n->rDelay=5; n->rSustain=5; n->rRelease=7;
  294. }
  295. void IDN_EnvelopeDestroy(laSynthNodeEnvelope* n){
  296. laDestroyInSocket(n->Attack); laDestroyInSocket(n->Delay);
  297. laDestroyInSocket(n->Sustain); laDestroyInSocket(n->Release);
  298. laDestroyInSocket(n->Trigger); laDestroyOutSocket(n->Out);
  299. memFree(n->OutSamples);
  300. strSafeDestroy(&n->Base.Name);
  301. }
  302. int IDN_EnvelopeVisit(laSynthNodeEnvelope* n, laNodeVisitInfo* vi){
  303. LA_GUARD_THIS_NODE(n,vi);
  304. if(LA_SRC_AND_PARENT(n->Attack)){ laBaseNode*bn=n->Attack->Source->Parent; LA_VISIT_NODE(bn,vi); }
  305. if(LA_SRC_AND_PARENT(n->Delay)){ laBaseNode*bn=n->Delay->Source->Parent; LA_VISIT_NODE(bn,vi); }
  306. if(LA_SRC_AND_PARENT(n->Sustain)){ laBaseNode*bn=n->Sustain->Source->Parent; LA_VISIT_NODE(bn,vi); }
  307. if(LA_SRC_AND_PARENT(n->Release)){ laBaseNode*bn=n->Release->Source->Parent; LA_VISIT_NODE(bn,vi); }
  308. if(LA_SRC_AND_PARENT(n->Trigger)){ laBaseNode*bn=n->Trigger->Source->Parent; LA_VISIT_NODE(bn,vi); }
  309. LA_ADD_THIS_NODE(n,vi);
  310. return LA_DAG_FLAG_PERM;
  311. }
  312. int IDN_EnvelopeEval(laSynthNodeEnvelope* n){
  313. int trigger_at=-1; real trig=n->bTrigger*100;
  314. real* trigger; INPUTPACKET(trigger,n->Trigger); if(!trigger){ LA_GET_SRC_AS_VALUE(trig,n->Trigger); }
  315. real attack=n->rAttack,delay=n->rDelay,sustain=n->rSustain,release=n->rRelease;
  316. LA_GET_SRC_AS_VALUE(attack,n->Attack); LA_GET_SRC_AS_VALUE(delay,n->Delay);
  317. LA_GET_SRC_AS_VALUE(sustain,n->Sustain); LA_GET_SRC_AS_VALUE(release,n->Release);
  318. attack=attack?pow(attack/10,2):0; delay=delay?pow(delay/10,2):0; release=release?pow(release/10,2):0;
  319. for(int i=0;i<LA_SYNTH_PLEN;i++){
  320. if(trigger){ trig=trigger[i]; }
  321. if(!n->Triggered){ if(trig > 5.0f){ n->Triggered = 1; n->Time = 0; n->ReleaseTime=10000; n->AtLevel=0; } }
  322. else{ if(trig < 2.0f){ n->Triggered = 0; n->ReleaseTime = n->Time; } }
  323. if(n->Time < n->ReleaseTime){
  324. if(n->Time<=attack){
  325. n->OutSamples[i]=10.0f*pow(n->Time/attack,0.3);
  326. }elif(n->Time<=delay + attack){
  327. real fac=pow((n->Time-attack)/delay,0.3);
  328. n->OutSamples[i]= tnsLinearItp(10.0f, sustain, fac);
  329. }else{
  330. n->OutSamples[i]=sustain;
  331. }
  332. n->AtLevel=n->OutSamples[i];
  333. }else{
  334. if(n->Time - n->ReleaseTime < release){
  335. real fac=pow((n->Time - n->ReleaseTime)/release,0.3);
  336. n->OutSamples[i]= tnsLinearItp(n->AtLevel,0.0f, fac);
  337. }else{
  338. n->OutSamples[i]=0;
  339. }
  340. }
  341. n->Time+=FRAME_INTERVAL;
  342. }
  343. return 1;
  344. }
  345. void IDN_EnvelopeCopy(laSynthNodeEnvelope* new, laSynthNodeEnvelope* old, int DoRematch){
  346. if(DoRematch){
  347. LA_IDN_NEW_LINK(Attack) LA_IDN_NEW_LINK(Delay)
  348. LA_IDN_NEW_LINK(Sustain) LA_IDN_NEW_LINK(Release) LA_IDN_NEW_LINK(Trigger) return;
  349. }
  350. LA_IDN_OLD_DUPL(Out);
  351. new->rAttack=old->rAttack;new->rSustain=old->rSustain;new->rDelay=old->rDelay;new->rRelease=old->rRelease;
  352. }
  353. void laui_EnvelopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  354. laColumn* c=laFirstColumn(uil); laSynthNodeEnvelope*n=This->EndInstance;
  355. LA_BASE_NODE_HEADER(uil,c,This);
  356. laUiItem* b,*b1;
  357. #define ADSR_ROW(what) \
  358. b=laBeginRow(uil,c,0,0); \
  359. laShowNodeSocket(uil,c,This,"in_" what,0)->Flags|=LA_UI_SOCKET_LABEL_E; \
  360. b1=laOnConditionThat(uil,c,laNot(laPropExpression(This,"in_" what ".source")));{ \
  361. laShowItem(uil,c,This,what)->Expand=1; \
  362. } laEndCondition(uil,b1); \
  363. laEndRow(uil,b);
  364. ADSR_ROW("attack") ADSR_ROW("delay") ADSR_ROW("sustain") ADSR_ROW("release")
  365. b=laBeginRow(uil,c,0,0);
  366. laShowItem(uil,c,This,"in_trigger"); laShowItem(uil,c,This,"trigger")->Flags|=LA_UI_FLAGS_CYCLE;
  367. laShowSeparator(uil,c); laShowItem(uil,c,This,"out");
  368. laEndRow(uil,b);
  369. }
  370. void laRebuildSynthGraphs(){
  371. if(MAIN.Audio->CurrentSynth){
  372. laSpinLock(&MAIN.Audio->CurrentSynth->Lock);
  373. laRebuildPageEval(MAIN.Audio->CurrentSynth->Page);
  374. laSpinUnlock(&MAIN.Audio->CurrentSynth->Lock);
  375. }
  376. }
  377. int laEvalSynthGraphs(){
  378. laSynth* ss; int any=0;
  379. memset(MAIN.Audio->AudioSamples,0,sizeof(real)*LA_SYNTH_PLEN);
  380. for(ss=MAIN.Audio->Synths.pFirst;ss;ss=ss->Item.pNext){
  381. laSpinLock(&ss->Lock);
  382. if(!ss->Playing){ laSpinUnlock(&ss->Lock); continue; }
  383. MAIN.Audio->AudioEvalSynth=ss; MAIN.Audio->AudioEvalTime=0; INITPACKET(ss->AudioSamples);
  384. laRunPage(ss->Page,1);
  385. laSpinUnlock(&ss->Lock);
  386. for(int i=0;i<LA_SYNTH_PLEN;i++){
  387. MAIN.Audio->AudioSamples[i]+=ss->AudioSamples[i];
  388. }
  389. any=1;
  390. }
  391. return any;
  392. }
  393. void laaudio_DataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){
  394. float* out=pOutput; int any=1;
  395. for(int i=0;i<frameCount;i++){
  396. if(MAIN.Audio->NextAudioSample>=LA_SYNTH_PLEN){
  397. MAIN.Audio->NextAudioSample=0;
  398. if(laEvalSynthGraphs()){
  399. MAIN.Audio->AudioEvalTotalSamples+=LA_SYNTH_PLEN;
  400. MAIN.Audio->AudioEvalTime=(real)MAIN.Audio->AudioEvalTotalSamples/MAIN.Audio->AudioSampleRate;
  401. }else{ any=0;}
  402. }
  403. out[i]=MAIN.Audio->AudioSamples[MAIN.Audio->NextAudioSample]/10;
  404. MAIN.Audio->NextAudioSample++;
  405. }
  406. laSpinLock(&MAIN.Audio->AudioStatusLock);
  407. MAIN.Audio->AudioAny=any;
  408. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  409. }
  410. void la_SelectAudioDevice(laAudioDevice* ad){
  411. memAssignRef(MAIN.Audio, &MAIN.Audio->UsingDevice, ad);
  412. ma_device_stop(&MAIN.Audio->AudioDevice);
  413. ma_device_uninit(&MAIN.Audio->AudioDevice);
  414. if(!ad) return;
  415. int SampleRate=48000;
  416. ma_device_config config = ma_device_config_init(ma_device_type_playback);
  417. config.playback.pDeviceID= 0;
  418. config.playback.format = ma_format_f32;
  419. config.playback.channels = 1;
  420. config.sampleRate = SampleRate;
  421. config.dataCallback = laaudio_DataCallback;
  422. config.pUserData = 0;
  423. if (ma_device_init(NULL, &config, &MAIN.Audio->AudioDevice) != MA_SUCCESS){ return; }
  424. MAIN.Audio->AudioSampleRate=SampleRate;
  425. MAIN.Audio->NextAudioSample=LA_SYNTH_PLEN;
  426. MAIN.Audio->AudioFrameInterval=1.0f/SampleRate;
  427. }
  428. void la_AddAudioDevice(int id, char* Name){
  429. laAudioDevice* ad=memAcquire(sizeof(laAudioDevice));
  430. strSafeSet(&ad->Name,Name); ad->MiniAudioID=id;
  431. lstAppendItem(&MAIN.Audio->AudioDevices,ad);
  432. }
  433. void la_ClearAudioDevices(){
  434. laAudioDevice* ad; while(ad=lstPopItem(&MAIN.Audio->AudioDevices)){
  435. strSafeDestroy(&ad->Name); memFree(ad);
  436. }
  437. }
  438. void laRefreshAudioDevices(){
  439. if(!MAIN.Audio) return; la_ClearAudioDevices();
  440. ma_device_info* pPlaybackInfos;
  441. ma_uint32 playbackCount;
  442. ma_device_info* pCaptureInfos;
  443. ma_uint32 captureCount;
  444. if (ma_context_get_devices(&MAIN.Audio->MiniAudioContext, &pPlaybackInfos, &playbackCount, &pCaptureInfos, &captureCount) != MA_SUCCESS) {
  445. logPrintNew("Can't get audio devices.\n");
  446. }
  447. for (ma_uint32 iDevice = 0; iDevice < playbackCount; iDevice += 1) {
  448. la_AddAudioDevice(iDevice, pPlaybackInfos[iDevice].name);
  449. }
  450. }
  451. void laInitMiniAudio(){
  452. if (ma_context_init(NULL, 0, NULL, &MAIN.Audio->MiniAudioContext) != MA_SUCCESS) {
  453. printf("Can't init miniaudio context\n");
  454. }
  455. laRefreshAudioDevices();
  456. la_SelectAudioDevice(MAIN.Audio->AudioDevices.pFirst);
  457. INITPACKET(MAIN.Audio->AudioSamples);
  458. laSpinInit(&MAIN.Audio->AudioStatusLock);
  459. }
  460. void laDeinitAudio(){
  461. laSpinDestroy(&MAIN.Audio->AudioStatusLock);
  462. ma_device_stop(&MAIN.Audio->AudioDevice);
  463. ma_device_uninit(&MAIN.Audio->AudioDevice);
  464. ma_context_uninit(&MAIN.Audio->MiniAudioContext);
  465. }
  466. // Operations
  467. int OPINV_laRefreshAudioDevices(laOperator* a, laEvent* e){
  468. laRefreshAudioDevices(); return LA_FINISHED;
  469. }
  470. laSynth* laNewSynth(char* Name){
  471. laSynth* ss=memAcquireHyper(sizeof(laSynth));
  472. ss->Page=memAcquire(sizeof(laRackPage));
  473. ss->Page->RackType=LA_RACK_TYPE_AUDIO;
  474. strSafeSet(&ss->Name,Name);
  475. lstAppendItem(&MAIN.Audio->Synths,ss);
  476. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,ss);
  477. laSpinInit(&ss->Lock);
  478. return ss;
  479. }
  480. void laRemoveSynth(laSynth* ss){ if(!ss) return;
  481. strSafeDestroy(&ss->Name);
  482. if(MAIN.Audio->CurrentSynth==ss){
  483. laSynth* nss=ss->Item.pNext?ss->Item.pNext:ss->Item.pPrev;
  484. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,nss);
  485. }laNotifyInstanceUsers(ss);
  486. while(ss->Page->Racks.pFirst){ laDestroyRack(ss->Page->Racks.pFirst); } memLeave(ss->Page); ss->Page=0;
  487. lstRemoveItem(&MAIN.Audio->Synths,ss);
  488. laSpinDestroy(&ss->Lock);
  489. memLeave(ss);
  490. }
  491. int OPINV_ShedNewSynth(laOperator* a, laEvent* e){
  492. laNewSynth("New Synth");
  493. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","New synth", 0);
  494. return LA_FINISHED;
  495. }
  496. int OPCHK_IslaSynth(laPropPack *This, laStringSplitor *ss){
  497. if (This && This->EndInstance && la_EnsureSubTarget(This->LastPs->p,0) == LA_PC_SYNTH) return 1;
  498. return 0;
  499. }
  500. int OPINV_ShedRemoveSynth(laOperator* a, laEvent* e){
  501. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  502. if(strSame(strGetArgumentString(a->ExtraInstructionsP,"confirm"),"true")){
  503. laRemoveSynth(ss);
  504. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","Remove la project", 0);
  505. return LA_FINISHED;
  506. }
  507. laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
  508. return LA_RUNNING;
  509. }
  510. void laui_RemoveSynth(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  511. laColumn* c=laFirstColumn(uil);
  512. laShowItemFull(uil,c,This,"remove_synth",0,"confirm=true;text=Confirm",0,0);
  513. }
  514. int OPINV_laSynthPlay(laOperator* a, laEvent* e){
  515. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  516. char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
  517. int play=0; if(str && strSame(str,"PLAY")) play=1;
  518. if(play){ MAIN.Audio->AudioAny=1; }
  519. laSpinLock(&ss->Lock); ss->Playing=play; laSpinUnlock(&ss->Lock);
  520. ma_device_start(&MAIN.Audio->AudioDevice); laNotifyInstanceUsers(ss);
  521. return LA_FINISHED;
  522. }
  523. void lauidetached_Synthersizers(laPanel* p){
  524. la_MakeDetachedProp(p, "la.detached_view_switch", "detached");
  525. la_MakeDetachedProp(p, "la.audio.current_synth", "page");
  526. }
  527. void laui_Synthersizers(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  528. laColumn* c=laFirstColumn(uil),*cl, *cr,*crl,*crr;
  529. laSplitColumn(uil,c,0.4); cl=laLeftColumn(c,1); cr=laRightColumn(c,0);
  530. laSplitColumn(uil,cr,0.6); crl=laLeftColumn(cr,0); crr=laRightColumn(cr,2);
  531. laShowItemFull(uil,cl,Extra,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  532. #define ADD_PAGE \
  533. laUiItem* b=laBeginRow(uil,crl,0,0);\
  534. laShowItemFull(uil,crl,&rb->PP,"",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0)\
  535. ->Flags|=LA_UI_COLLECTION_SIMPLE_SELECTOR;\
  536. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{\
  537. laShowItem(uil,crl,&rb->PP,"name");\
  538. laShowItem(uil,crl,0,"LA_new_synth")->Flags|=LA_UI_FLAGS_ICON;\
  539. laShowSeparator(uil,crl);\
  540. laShowItem(uil,crl,&rb->PP,"remove_synth")->Flags|=LA_UI_FLAGS_ICON;\
  541. laShowSeparator(uil,crl)->Expand=1;\
  542. }laElse(uil,b3);{\
  543. laShowItem(uil,crl,0,"LA_new_synth");\
  544. }laEndCondition(uil,b3);\
  545. laEndRow(uil,b);\
  546. b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{\
  547. laUiItem* b4=laOnConditionThat(uil,crr,laPropExpression(&rb->PP,"playing"));{\
  548. laShowItemFull(uil,crr,&rb->PP,"play",0,"text=❚❚;",0,0) \
  549. ->Flags|=LA_UI_FLAGS_EXIT_WHEN_TRIGGERED|LA_TEXT_ALIGN_CENTER; \
  550. }laElse(uil,b4);{\
  551. laShowItemFull(uil,crr,&rb->PP,"play",0,"icon=▶;mode=PLAY;",0,0) \
  552. ->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_EXIT_WHEN_TRIGGERED; \
  553. }laEndCondition(uil,b4);\
  554. laShowItemFull(uil,c,&rb->PP,"page",LA_WIDGET_COLLECTION_SINGLE,0,laui_RackPage,0)->Flags|=LA_UI_FLAGS_NO_DECAL;\
  555. }laEndCondition(uil,b3);\
  556. laUiItem* b1=laOnConditionThat(uil,cr,laPropExpression(Extra,"detached"));{
  557. laUiItem* rb=laShowInvisibleItem(uil,cr,Extra,"page");
  558. ADD_PAGE
  559. }laElse(uil,b1);{
  560. laUiItem* rb=laShowInvisibleItem(uil,cr,0,"la.audio.current_synth");
  561. ADD_PAGE
  562. }laEndCondition(uil,b1);
  563. #undef ADD_PAGE
  564. }
  565. void* laget_FirstAudioDevice(void* unused1,void* unused2){
  566. return MAIN.Audio->AudioDevices.pFirst;
  567. }
  568. void* laget_FirstSynth(void* unused1,void* unused2){
  569. return MAIN.Audio->Synths.pFirst;
  570. }
  571. void lapost_Synth(laSynth* ss){
  572. laSpinInit(&ss->Lock);
  573. }
  574. int laget_SynthPlaying(laSynth* ss){
  575. int play=0;
  576. laSpinLock(&ss->Lock); play=ss->Playing; laSpinUnlock(&ss->Lock);
  577. return play;
  578. }
  579. void laset_CurrentSynth(laAudio* a,laSynth* s){
  580. memAssignRef(a,&a->CurrentSynth,s);
  581. }
  582. void laset_CurrentAudioDevice(laAudio* a,laAudioDevice* ad){
  583. la_SelectAudioDevice(ad);
  584. }
  585. void la_AudioPreFrame(){
  586. if(MAIN.GraphNeedsRebuild){ laRebuildSynthGraphs(); }
  587. int anyaudio=0;
  588. laSpinLock(&MAIN.Audio->AudioStatusLock);
  589. anyaudio=MAIN.Audio->AudioAny;
  590. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  591. if(!anyaudio){ ma_device_stop(&MAIN.Audio->AudioDevice); }
  592. }
  593. void laInitAudio(){
  594. laPropContainer* pc; laProp* p; laSubProp* sp;
  595. laInitMiniAudio();
  596. laRegisterUiTemplate("LAUI_synthesizers","Synthesizers",laui_Synthersizers,lauidetached_Synthersizers,0,"Audio",0,0,0);
  597. laCreateOperatorType("LA_new_synth", "New Synthesizer", "Add a synthesizer",0,0,0,OPINV_ShedNewSynth,0,'+',0);
  598. laCreateOperatorType("LA_remove_synth", "Remove Synthesizer", "Remove a synthesizer",OPCHK_IslaSynth,0,0,OPINV_ShedRemoveSynth,OPMOD_FinishOnData,L'🗴',0)
  599. ->UiDefine=laui_RemoveSynth;
  600. laCreateOperatorType("LA_synth_play", "Play Synthesizer", "Play a synthesizer",OPCHK_IslaSynth,0,0,OPINV_laSynthPlay,0,0,0);
  601. laCreateOperatorType("LA_refresh_audio_devices", "Refresh Audio Devices", "Enumerate audio devices for selection",0,0,0,OPINV_laRefreshAudioDevices,0,U'🗘',0);
  602. pc = laAddPropertyContainer("la_audio_device","LaGUI Audio Device","LaGUI enumerated audio device",0,0,sizeof(laAudioDevice),0,0,1);{
  603. laAddStringProperty(pc,"name","Name","Name of the audio device",0,0,0,0,1,offsetof(laAudioDevice,Name),0,0,0,0,LA_AS_IDENTIFIER);
  604. }
  605. pc = laAddPropertyContainer("la_synth", "LaGUI Synthesizer", "LaGUI synthesizer", 0,0,sizeof(laSynth),lapost_Synth,0,2);{
  606. LA_PC_SYNTH=pc;
  607. laAddStringProperty(pc,"name","Name","Name of the synthesizer",0,0,0,0,1,offsetof(laSynth,Name),0,0,0,0,LA_AS_IDENTIFIER);
  608. 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);
  609. 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);
  610. laAddEnumItemAs(p,"IDLE","Idle","Synth is not playing",0,0);
  611. laAddEnumItemAs(p,"PLAYING","Playing","Synth is playing",1,0);
  612. laAddOperatorProperty(pc,"remove_synth","Remove Synth", "Remove synth", "LA_remove_synth", L'🗴', 0);
  613. laAddOperatorProperty(pc,"play","Play Synth", "Play synth", "LA_synth_play", 0, 0);
  614. }
  615. pc=laAddPropertyContainer("la_node_synth_fm", "FM OSC Node", "Osilliator node with frequency modulation",0,laui_FMNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
  616. LA_PC_IDN_FM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  617. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  618. 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);
  619. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeFM,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  620. 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);
  621. 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);
  622. laAddEnumItemAs(p,"NONE","None","Regular frequency range",0,0);
  623. laAddEnumItemAs(p,"SLOW","Slow","Slow frequency range",1,0);
  624. pc=laAddPropertyContainer("la_node_synth_vca", "VCA Node", "Voltage controlled amplifier",0,laui_VCANode,sizeof(laSynthNodeVCA),lapost_Node,0,1);
  625. LA_PC_IDN_VCA=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  626. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  627. 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);
  628. laAddSubGroup(pc,"in", "Input","Input","la_in_socket",0,0,0,offsetof(laSynthNodeVCA,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  629. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeVCA,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  630. 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);
  631. pc=laAddPropertyContainer("la_node_synth_noise", "Noise Node", "Noise node",0,laui_NoiseNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
  632. LA_PC_IDN_NOISE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  633. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  634. 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);
  635. 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);
  636. pc=laAddPropertyContainer("la_node_synth_scope", "Scope Node", "Scope for synthesizer",0,laui_ScopeNode,sizeof(laSynthNodeScope),lapost_Node,0,1);
  637. LA_PC_IDN_SCOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  638. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  639. 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);
  640. 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);
  641. 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);
  642. 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);
  643. #define _STR(a) #a
  644. #define ADD_TIME_FACTOR(a) laAddEnumItemAs(p,"FAC"_STR(a),_STR(a),"^"_STR(a)" time",a,0);
  645. ADD_TIME_FACTOR(1) ADD_TIME_FACTOR(2) ADD_TIME_FACTOR(3) ADD_TIME_FACTOR(4) ADD_TIME_FACTOR(5)
  646. ADD_TIME_FACTOR(6) ADD_TIME_FACTOR(7) ADD_TIME_FACTOR(8) ADD_TIME_FACTOR(9) ADD_TIME_FACTOR(10)
  647. #undef ADD_TIME_FACTOR
  648. 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);
  649. #define ADD_GAIN(a) laAddEnumItemAs(p,"GAIN"_STR(a),_STR(a),"^"_STR(a)" gain",a,0);
  650. #define ADD_GAIN_S(a,s) laAddEnumItemAs(p,"GAIN"_STR(a),s,"^"s" gain",a,0);
  651. 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)
  652. 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);
  653. 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)
  654. #undef ADD_GAIN
  655. #undef ADD_GAIN_S
  656. 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);
  657. 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);
  658. 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);
  659. 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);
  660. pc=laAddPropertyContainer("la_node_synth_output", "Output Node", "Sound output to system",0,laui_OutputNode,sizeof(laSynthNodeOutput),lapost_Node,0,1);
  661. LA_PC_IDN_OUTPUT=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  662. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  663. laAddSubGroup(pc,"in", "Input","Input sound","la_in_socket",0,0,0,offsetof(laSynthNodeOutput,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  664. pc=laAddPropertyContainer("la_node_synth_envelope", "Envelope Node", "Sound envelope",0,laui_EnvelopeNode,sizeof(laSynthNodeEnvelope),lapost_Node,0,1);
  665. LA_PC_IDN_ENVELOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  666. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  667. 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);
  668. 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);
  669. 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);
  670. 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);
  671. 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);
  672. 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);
  673. laAddFloatProperty(pc,"attack","Attack","Attack value",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeEnvelope,rAttack),0,0,0,0,0,0,0,0,0,0,0);
  674. laAddFloatProperty(pc,"delay","Delay","Delay value",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeEnvelope,rDelay),0,0,0,0,0,0,0,0,0,0,0);
  675. laAddFloatProperty(pc,"sustain","Sustain","Sustain value",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeEnvelope,rSustain),0,0,0,0,0,0,0,0,0,0,0);
  676. laAddFloatProperty(pc,"release","Release","Release value",0,0,0,10,0,0.1,0,0,offsetof(laSynthNodeEnvelope,rRelease),0,0,0,0,0,0,0,0,0,0,0);
  677. 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);
  678. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  679. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  680. LA_IDN_REGISTER("VCO",'f',LA_IDN_FM, LA_PC_IDN_FM, IDN_FM, laSynthNodeFM);
  681. LA_IDN_REGISTER("VCA",'a',LA_IDN_VCA, LA_PC_IDN_VCA, IDN_VCA, laSynthNodeVCA);
  682. LA_IDN_REGISTER("Noise",'~',LA_IDN_NOISE, LA_PC_IDN_NOISE, IDN_Noise, laSynthNodeNoise);
  683. LA_IDN_REGISTER("Scope",'s',LA_IDN_SCOPE, LA_PC_IDN_SCOPE, IDN_Scope, laSynthNodeScope);
  684. LA_IDN_REGISTER("Sound Output",U'🕪',LA_IDN_OUTPUT, LA_PC_IDN_OUTPUT, IDN_Output, laSynthNodeOutput);
  685. LA_IDN_REGISTER("Envelope",U'^',LA_IDN_ENVELOPE, LA_PC_IDN_ENVELOPE, IDN_Envelope, laSynthNodeEnvelope);
  686. LA_NODE_CATEGORY_SYNTHESIZER=laAddNodeCategory("OSC",0,LA_RACK_TYPE_AUDIO);
  687. LA_NODE_CATEGORY_SYSTEM_SOUND=laAddNodeCategory("System",0,LA_RACK_TYPE_AUDIO);
  688. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER, &LA_IDN_FM,&LA_IDN_NOISE,&LA_IDN_VCA,&LA_IDN_ENVELOPE,&LA_IDN_SCOPE,0);
  689. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYSTEM_SOUND, &LA_IDN_OUTPUT,0);
  690. }
  691. void laAudioDummy(){
  692. return 0;
  693. }