*/}}

la_audio.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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_FM;
  27. laBaseNodeType LA_IDN_VCA;
  28. laBaseNodeType LA_IDN_NOISE;
  29. laBaseNodeType LA_IDN_OUTPUT;
  30. laBaseNodeType LA_IDN_SCOPE;
  31. laBaseNodeType LA_IDN_ENVELOPE;
  32. laBaseNodeType LA_IDN_QUANTIZE;
  33. laPropContainer* LA_PC_IDN_FM;
  34. laPropContainer* LA_PC_IDN_VCA;
  35. laPropContainer* LA_PC_IDN_NOISE;
  36. laPropContainer* LA_PC_IDN_OUTPUT;
  37. laPropContainer* LA_PC_IDN_SCOPE;
  38. laPropContainer* LA_PC_IDN_ENVELOPE;
  39. laPropContainer* LA_PC_IDN_QUANTIZE;
  40. #define _2PI 6.283185307
  41. #define VAL2FREQ(val) \
  42. 16.0f*pow(2,val) // 0-10, 16-16384Hz
  43. #define VAL13 -0.218640286
  44. #define VAL27 0.78135971352
  45. #define VAL440 4.78135971352 // 2^FREQC*16=440
  46. #define VALHALF (1.0f/12.0f)
  47. #define WRAPPHASE(p) \
  48. while(p>_2PI){ p-=_2PI; }
  49. #define INITPACKET(arr) \
  50. if(!arr){ arr=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  51. #define INPUTPACKET(ptr,socket) \
  52. {if(socket->Source && socket->Source->DataType==(LA_PROP_FLOAT|LA_PROP_ARRAY) && socket->Source->ArrLen>=LA_SYNTH_PLEN){ \
  53. ptr=((real*)socket->Source->Data); }else{ ptr=0; } }
  54. #define FRAME_INTERVAL (MAIN.Audio->AudioFrameInterval)
  55. #define SAMPLE_RATE (MAIN.Audio->AudioSampleRate)
  56. void IDN_FMInit(laSynthNodeFM* n, int NoCreate){
  57. INITPACKET(n->OutSamples);
  58. if(NoCreate){ return; }
  59. n->InFrequency=laCreateInSocket("FREQ",0); n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  60. strSafeSet(&n->Base.Name,"FM"); n->Frequency=4;
  61. }
  62. void IDN_FMDestroy(laSynthNodeFM* n){
  63. laDestroyInSocket(n->InFrequency); laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  64. }
  65. int IDN_FMVisit(laSynthNodeFM* n, laNodeVisitInfo* vi){
  66. LA_GUARD_THIS_NODE(n,vi);
  67. if(LA_SRC_AND_PARENT(n->InFrequency)){ laBaseNode*bn=n->InFrequency->Source->Parent; LA_VISIT_NODE(bn,vi); }
  68. LA_ADD_THIS_NODE(n,vi);
  69. return LA_DAG_FLAG_PERM;
  70. }
  71. int IDN_FMEval(laSynthNodeFM* n){
  72. real f=n->Frequency, constf=0; real* inputf;
  73. INPUTPACKET(inputf,n->InFrequency); LA_GET_SRC_AS_VALUE(constf,n->InFrequency);
  74. for(int i=0;i<LA_SYNTH_PLEN;i++){
  75. real useF=inputf?(inputf[i]*n->rInfluence+f):(f+constf); if(n->Slow) useF-=10;
  76. n->Phase+=FRAME_INTERVAL*VAL2FREQ(useF)*_2PI;
  77. WRAPPHASE(n->Phase);
  78. n->OutSamples[i]=sin(n->Phase)*10;
  79. }
  80. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  81. return 1;
  82. }
  83. void IDN_FMCopy(laSynthNodeFM* new, laSynthNodeFM* old, int DoRematch){
  84. if(DoRematch){ LA_IDN_NEW_LINK(InFrequency) return; }
  85. LA_IDN_OLD_DUPL(Out); new->Frequency=old->Frequency; new->Slow=old->Slow;
  86. }
  87. void laui_FMNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  88. laColumn* c=laFirstColumn(uil); laSynthNodeFM*n=This->EndInstance;
  89. LA_BASE_NODE_HEADER(uil,c,This);
  90. laUiItem* b=laBeginRow(uil,c,0,0);
  91. laShowItem(uil,c,This,"slow");
  92. laShowNodeSocket(uil,c,This,"in_frequency",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  93. laShowItem(uil,c,This,"influence");
  94. laShowItem(uil,c,This,"frequency")->Expand=1;
  95. laShowNodeSocket(uil,c,This,"out",0);
  96. laEndRow(uil,b);
  97. }
  98. void IDN_VCAInit(laSynthNodeVCA* n, int NoCreate){
  99. INITPACKET(n->OutSamples);
  100. if(NoCreate){ return; }
  101. n->InAmp=laCreateInSocket("AMP",0); n->In=laCreateInSocket("IN",0);
  102. n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
  103. strSafeSet(&n->Base.Name,"FM"); n->Amp=10;
  104. }
  105. void IDN_VCADestroy(laSynthNodeVCA* n){
  106. laDestroyInSocket(n->InAmp); laDestroyInSocket(n->In);
  107. laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
  108. }
  109. int IDN_VCAVisit(laSynthNodeVCA* n, laNodeVisitInfo* vi){
  110. LA_GUARD_THIS_NODE(n,vi);
  111. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  112. if(LA_SRC_AND_PARENT(n->InAmp)){ laBaseNode*bn=n->InAmp->Source->Parent; LA_VISIT_NODE(bn,vi); }
  113. LA_ADD_THIS_NODE(n,vi);
  114. return LA_DAG_FLAG_PERM;
  115. }
  116. int IDN_VCAEval(laSynthNodeVCA* n){
  117. real amp=n->Amp, constamp=amp; real* inputamp=0,*input=0;
  118. INPUTPACKET(input,n->In); INPUTPACKET(inputamp,n->InAmp);
  119. if(!inputamp) LA_GET_SRC_AS_VALUE(constamp,n->InAmp); constamp/=10;
  120. n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
  121. if(!input){ memset(n->OutSamples,0,sizeof(real)*LA_SYNTH_PLEN); return 0; }
  122. for(int i=0;i<LA_SYNTH_PLEN;i++){
  123. real useA=(inputamp?(inputamp[i]*n->rInfluence/10):1)*constamp;
  124. n->OutSamples[i]= input[i]*useA;
  125. }
  126. return 1;
  127. }
  128. void IDN_VCACopy(laSynthNodeVCA* new, laSynthNodeVCA* old, int DoRematch){
  129. if(DoRematch){ LA_IDN_NEW_LINK(InAmp) LA_IDN_NEW_LINK(In) return; }
  130. LA_IDN_OLD_DUPL(Out); new->Amp=old->Amp;
  131. }
  132. void laui_VCANode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  133. laColumn* c=laFirstColumn(uil); laSynthNodeVCA*n=This->EndInstance;
  134. LA_BASE_NODE_HEADER(uil,c,This);
  135. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  136. laUiItem* b=laBeginRow(uil,c,0,0);
  137. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  138. laShowNodeSocket(uil,c,This,"in_amp",0);
  139. laShowItem(uil,c,This,"influence");
  140. laShowItem(uil,c,This,"amp")->Expand=1;
  141. laShowNodeSocket(uil,cr,This,"out",0);
  142. laEndRow(uil,b);
  143. }
  144. void IDN_NoiseInit(laSynthNodeNoise* n, int NoCreate){
  145. INITPACKET(n->OutWhiteSamples); INITPACKET(n->OutPinkSamples);
  146. n->PinkA[0]=0.02109238; n->PinkA[1]=0.07113478; n->PinkA[2]=0.68873558;
  147. n->PinkP[0]=0.3190; n->PinkP[1]=0.7756; n->PinkP[2]=0.9613;
  148. if(NoCreate){ return; }
  149. n->OutWhite=laCreateOutSocket(n,"WHITE",LA_PROP_FLOAT|LA_PROP_ARRAY);
  150. n->OutPink=laCreateOutSocket(n,"PINK",LA_PROP_FLOAT|LA_PROP_ARRAY);
  151. strSafeSet(&n->Base.Name,"Noise");
  152. }
  153. void IDN_NoiseDestroy(laSynthNodeNoise* n){
  154. laDestroyOutSocket(n->OutWhite); laDestroyOutSocket(n->OutPink); strSafeDestroy(&n->Base.Name);
  155. memFree(n->OutWhiteSamples); memFree(n->OutPinkSamples);
  156. }
  157. int IDN_NoiseVisit(laSynthNodeNoise* n, laNodeVisitInfo* vi){
  158. LA_GUARD_THIS_NODE(n,vi); LA_ADD_THIS_NODE(n,vi);
  159. return LA_DAG_FLAG_PERM;
  160. }
  161. int IDN_NoiseEval(laSynthNodeNoise* n){
  162. real RMI2 = 2.0 / (real)RAND_MAX; // + 1.0; // change for range [0,1)
  163. real offset = n->PinkA[0] + n->PinkA[1] + n->PinkA[2];
  164. for(int i=0;i<LA_SYNTH_PLEN;i++){
  165. real R1=(real)rand()/(real)RAND_MAX;
  166. real R2=(real)rand()/(real)RAND_MAX;
  167. real X=(real)sqrt(-2.0f*log(R1))*cos(2.0f*TNS_PI*R2);
  168. n->OutWhiteSamples[i]=X*2.5;
  169. real temp; for(int i=0;i<3;i++){ temp=(real)rand();
  170. n->PinkStates[i] = n->PinkP[i] * (n->PinkStates[i] - temp) + temp;
  171. }
  172. n->OutPinkSamples[i]=(n->PinkA[0]*n->PinkStates[0]+
  173. n->PinkA[1]*n->PinkStates[1]+
  174. n->PinkA[2]*n->PinkStates[2])*RMI2-offset;
  175. n->OutPinkSamples[i]*=40;
  176. }
  177. n->OutWhite->Data=n->OutWhiteSamples; n->OutWhite->ArrLen=LA_SYNTH_PLEN;
  178. n->OutPink->Data=n->OutPinkSamples; n->OutPink->ArrLen=LA_SYNTH_PLEN;
  179. return 1;
  180. }
  181. void IDN_NoiseCopy(laSynthNodeNoise* new, laSynthNodeNoise* old, int DoRematch){
  182. if(DoRematch){ return; }
  183. LA_IDN_OLD_DUPL(OutWhite);
  184. }
  185. void laui_NoiseNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  186. laColumn* c=laFirstColumn(uil); laSynthNodeNoise*n=This->EndInstance;
  187. LA_BASE_NODE_HEADER(uil,c,This);
  188. laUiItem* b=laBeginRow(uil,c,0,0);
  189. laShowNodeSocket(uil,c,This,"out_white",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  190. laShowNodeSocket(uil,c,This,"out_pink",0)->Flags|=LA_UI_SOCKET_LABEL_N;
  191. laEndRow(uil,b);
  192. }
  193. void IDN_ScopeInit(laSynthNodeScope* n, int NoCreate){
  194. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  195. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  196. laSpinInit(&n->Lock);
  197. if(NoCreate){ return; }
  198. n->In1=laCreateInSocket("CH1",0); n->In2=laCreateInSocket("CH2",0);
  199. strSafeSet(&n->Base.Name,"SCOPE"); n->Time=5; n->Brightness1=0.7f; n->Brightness2=0.4f;
  200. n->Gain1=1; n->Gain2=1;
  201. }
  202. void IDN_ScopeDestroy(laSynthNodeScope* n){
  203. laDestroyInSocket(n->In1); laDestroyOutSocket(n->In2); strSafeDestroy(&n->Base.Name);
  204. memFree(n->Display1); memFree(n->Display2);
  205. laSpinDestroy(&n->Lock);
  206. }
  207. int IDN_ScopeVisit(laSynthNodeScope* n, laNodeVisitInfo* vi){
  208. LA_GUARD_THIS_NODE(n,vi);
  209. if(LA_SRC_AND_PARENT(n->In1)){ laBaseNode*bn=n->In1->Source->Parent; LA_VISIT_NODE(bn,vi); }
  210. if(LA_SRC_AND_PARENT(n->In2)){ laBaseNode*bn=n->In2->Source->Parent; LA_VISIT_NODE(bn,vi); }
  211. LA_ADD_THIS_NODE(n,vi);
  212. return LA_DAG_FLAG_PERM;
  213. }
  214. int IDN_ScopeEval(laSynthNodeScope* n){
  215. if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  216. if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
  217. real* ch1,*ch2; INPUTPACKET(ch1,n->In1); INPUTPACKET(ch2,n->In2);
  218. int Frame=1<<(n->Time-1); TNS_CLAMP(Frame,1,LA_SYNTH_PLEN);
  219. int Times=LA_SYNTH_PLEN/Frame; int sp=0; laSpinLock(&n->Lock);
  220. for(int t=0;t<Times;t++){
  221. real smin1=FLT_MAX,smax1=-FLT_MAX,smin2=FLT_MAX,smax2=-FLT_MAX;
  222. for(int i=0;i<Frame;i++){
  223. if(ch1){ smin1=TNS_MIN2(smin1,ch1[sp]); smax1=TNS_MAX2(smax1,ch1[sp]); }
  224. if(ch2){ smin2=TNS_MIN2(smin2,ch2[sp]); smax2=TNS_MAX2(smax2,ch2[sp]); }
  225. sp++;
  226. }
  227. if(!ch1){smin1=smax1=0; LA_GET_SRC_AS_VALUE(smin1,n->In1); smax1=smin1; }
  228. if(!ch2){smin2=smax2=0; LA_GET_SRC_AS_VALUE(smin2,n->In2); smax2=smin2; }
  229. int ns=n->NextSample;
  230. n->Display1[ns]=smin1; n->Display1[ns+LA_SYNTH_PLEN]=smax1;
  231. n->Display2[ns]=smin2; n->Display2[ns+LA_SYNTH_PLEN]=smax2;
  232. n->NextSample++; if(n->NextSample>=LA_SYNTH_PLEN) n->NextSample=0;
  233. }
  234. n->FromSynth=MAIN.Audio->AudioEvalSynth;
  235. laSpinUnlock(&n->Lock);
  236. return 1;
  237. }
  238. void IDN_ScopeCopy(laSynthNodeScope* new, laSynthNodeScope* old, int DoRematch){
  239. if(DoRematch){ LA_IDN_NEW_LINK(In1) LA_IDN_NEW_LINK(In2) return; }
  240. new->Brightness1=old->Brightness1; new->Brightness2=old->Brightness2;
  241. new->Gain1=old->Gain1; new->Gain2=old->Gain2;
  242. new->Offset1=old->Offset1; new->Offset2=old->Offset2;
  243. new->Time=old->Time;
  244. }
  245. void laui_ScopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  246. laColumn* c=laFirstColumn(uil); laSynthNodeScope*n=This->EndInstance;
  247. LA_BASE_NODE_HEADER(uil,c,This);
  248. laColumn* cl,*cr; laSplitColumn(uil,c,0.5); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  249. laUiItem* b=laBeginRow(uil,c,0,0);
  250. laUiItem* u=laShowItem(uil,c,This,"gain1");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  251. laShowNodeSocket(uil,c,This,"in1",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  252. laEndRow(uil,b);
  253. b=laBeginRow(uil,c,0,0);
  254. u=laShowItem(uil,c,This,"gain2");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
  255. laShowNodeSocket(uil,c,This,"in2",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  256. laEndRow(uil,b);
  257. laShowItem(uil,c,This,"scope")->Extra->HeightCoeff=6;
  258. laShowLabel(uil,cl,"CH1",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  259. laShowItem(uil,cl,This,"bright1"); laShowItem(uil,cl,This,"offset1");
  260. laShowLabel(uil,cr,"CH2",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
  261. laShowItem(uil,cr,This,"bright2"); laShowItem(uil,cr,This,"offset2");
  262. laShowItem(uil,c,This,"time")->Flags|=LA_UI_FLAGS_EXPAND;
  263. }
  264. void IDN_OutputInit(laSynthNodeOutput* n, int NoCreate){
  265. if(NoCreate){ return; }
  266. n->In=laCreateInSocket("IN",0); strSafeSet(&n->Base.Name,"Output");
  267. }
  268. void IDN_OutputDestroy(laSynthNodeOutput* n){
  269. laDestroyInSocket(n->In); strSafeDestroy(&n->Base.Name);
  270. }
  271. int IDN_OutputVisit(laSynthNodeOutput* n, laNodeVisitInfo* vi){
  272. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  273. LA_ADD_THIS_NODE(n,vi);
  274. return LA_DAG_FLAG_PERM;
  275. }
  276. int IDN_OutputEval(laSynthNodeOutput* n){
  277. real* input; INPUTPACKET(input,n->In);
  278. if(input) memcpy(MAIN.Audio->AudioEvalSynth->AudioSamples,input,sizeof(real)*LA_SYNTH_PLEN);
  279. else memset(MAIN.Audio->AudioEvalSynth->AudioSamples,0,sizeof(real)*LA_SYNTH_PLEN);
  280. return 1;
  281. }
  282. void IDN_OutputCopy(laSynthNodeOutput* new, laSynthNodeOutput* old, int DoRematch){
  283. if(DoRematch){ LA_IDN_NEW_LINK(In) return; }
  284. }
  285. void laui_OutputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  286. laColumn* c=laFirstColumn(uil); laSynthNodeOutput*n=This->EndInstance;
  287. LA_BASE_NODE_HEADER(uil,c,This);
  288. laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
  289. laUiItem* b=laBeginRow(uil,c,0,0);
  290. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  291. laShowLabel(uil,c,"🕪",0,0);
  292. laEndRow(uil,b);
  293. }
  294. void IDN_EnvelopeInit(laSynthNodeEnvelope* n, int NoCreate){
  295. if(!NoCreate){ strSafeSet(&n->Base.Name,"Envelope");
  296. n->Attack=laCreateInSocket("ATTACK",0); n->Delay=laCreateInSocket("DELAY",0);
  297. n->Sustain=laCreateInSocket("SUSTAIN",0); n->Release=laCreateInSocket("RELEASE",0);
  298. n->Trigger=laCreateInSocket("TRIGGER",0); n->Out=laCreateOutSocket(n, "OUT",0);
  299. n->Time=20; n->rAttack=1; n->rDelay=5; n->rSustain=5; n->rRelease=7; n->rGate=5;
  300. }
  301. if(!n->Gate){ n->Gate=laCreateInSocket("GATE",0); }
  302. if(!n->OutSamples){ n->OutSamples=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  303. n->Out->Data = n->OutSamples; n->Out->DataType = LA_PROP_FLOAT|LA_PROP_ARRAY; n->Out->ArrLen=LA_SYNTH_PLEN;
  304. }
  305. void IDN_EnvelopeDestroy(laSynthNodeEnvelope* n){
  306. laDestroyInSocket(n->Attack); laDestroyInSocket(n->Delay); laDestroyInSocket(n->Gate);
  307. laDestroyInSocket(n->Sustain); laDestroyInSocket(n->Release);
  308. laDestroyInSocket(n->Trigger); laDestroyOutSocket(n->Out);
  309. memFree(n->OutSamples);
  310. strSafeDestroy(&n->Base.Name);
  311. }
  312. int IDN_EnvelopeVisit(laSynthNodeEnvelope* n, laNodeVisitInfo* vi){
  313. LA_GUARD_THIS_NODE(n,vi);
  314. if(LA_SRC_AND_PARENT(n->Attack)){ laBaseNode*bn=n->Attack->Source->Parent; LA_VISIT_NODE(bn,vi); }
  315. if(LA_SRC_AND_PARENT(n->Delay)){ laBaseNode*bn=n->Delay->Source->Parent; LA_VISIT_NODE(bn,vi); }
  316. if(LA_SRC_AND_PARENT(n->Sustain)){ laBaseNode*bn=n->Sustain->Source->Parent; LA_VISIT_NODE(bn,vi); }
  317. if(LA_SRC_AND_PARENT(n->Release)){ laBaseNode*bn=n->Release->Source->Parent; LA_VISIT_NODE(bn,vi); }
  318. if(LA_SRC_AND_PARENT(n->Trigger)){ laBaseNode*bn=n->Trigger->Source->Parent; LA_VISIT_NODE(bn,vi); }
  319. LA_ADD_THIS_NODE(n,vi);
  320. return LA_DAG_FLAG_PERM;
  321. }
  322. int IDN_EnvelopeEval(laSynthNodeEnvelope* n){
  323. int trigger_at=-1; real trig=n->bTrigger?n->bTrigger*100:-100;
  324. real* trigger; INPUTPACKET(trigger,n->Trigger); if(!trigger){ LA_GET_SRC_AS_VALUE(trig,n->Trigger); }
  325. real *att,*del,*sus,*rel,*gat;
  326. real attack=n->rAttack,delay=n->rDelay,sustain=n->rSustain,release=n->rRelease;
  327. real gate = n->rGate; INPUTPACKET(gat,n->Gate); if(!gat) LA_GET_SRC_AS_VALUE(gate,n->Gate);
  328. INPUTPACKET(att,n->Attack); if(!att) LA_GET_SRC_AS_VALUE(attack,n->Attack);
  329. INPUTPACKET(del,n->Delay); if(!del) LA_GET_SRC_AS_VALUE(delay,n->Delay);
  330. INPUTPACKET(sus,n->Sustain); if(!sus) LA_GET_SRC_AS_VALUE(sustain,n->Sustain);
  331. INPUTPACKET(rel,n->Release); if(!rel) LA_GET_SRC_AS_VALUE(release,n->Release);
  332. attack=attack?pow(attack/10,2):0; delay=delay?pow(delay/10,2):0; release=release?pow(release/10,2):0;
  333. for(int i=0;i<LA_SYNTH_PLEN;i++){
  334. if(trigger){ trig=trigger[i]; } if(gat){ gate=gat[i]; }
  335. if(att){ attack=att[i]*n->iAttack+n->rAttack; }
  336. if(del){ delay=del[i]*n->iDelay+n->rDelay; }
  337. if(sus){ sustain=sus[i]*n->iSustain+n->rSustain; }
  338. if(rel){ release=rel[i]*n->iRelease+n->rRelease; }
  339. if(!n->Triggered){ if(trig > gate){ n->Triggered = 1; n->Time = 0; n->ReleaseTime=10000; n->AtLevel=0; } }
  340. else{ if(trig < gate-0.0001f){ n->Triggered = 0; n->ReleaseTime = n->Time; } }
  341. if(n->Time < n->ReleaseTime){
  342. if(n->Time<=attack){
  343. n->OutSamples[i]=10.0f*pow(n->Time/attack,0.3);
  344. }elif(n->Time<=delay + attack){
  345. real fac=pow((n->Time-attack)/delay,0.3);
  346. n->OutSamples[i]= tnsLinearItp(10.0f, sustain, fac);
  347. }else{
  348. n->OutSamples[i]=sustain;
  349. }
  350. n->AtLevel=n->OutSamples[i];
  351. }else{
  352. if(n->Time - n->ReleaseTime < release){
  353. real fac=pow((n->Time - n->ReleaseTime)/release,0.3);
  354. n->OutSamples[i]= tnsLinearItp(n->AtLevel,0.0f, fac);
  355. }else{
  356. n->OutSamples[i]=0;
  357. }
  358. }
  359. n->Time+=FRAME_INTERVAL;
  360. }
  361. return 1;
  362. }
  363. void IDN_EnvelopeCopy(laSynthNodeEnvelope* new, laSynthNodeEnvelope* old, int DoRematch){
  364. if(DoRematch){
  365. LA_IDN_NEW_LINK(Attack) LA_IDN_NEW_LINK(Delay)
  366. LA_IDN_NEW_LINK(Sustain) LA_IDN_NEW_LINK(Release) LA_IDN_NEW_LINK(Trigger) return;
  367. }
  368. LA_IDN_OLD_DUPL(Out);
  369. new->rAttack=old->rAttack;new->rSustain=old->rSustain;new->rDelay=old->rDelay;new->rRelease=old->rRelease;
  370. }
  371. void laui_EnvelopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  372. laColumn* c=laFirstColumn(uil); laSynthNodeEnvelope*n=This->EndInstance;
  373. LA_BASE_NODE_HEADER(uil,c,This);
  374. laUiItem* b,*b1;
  375. #define ADSR_ROW(what) \
  376. b=laBeginRow(uil,c,0,0);{ \
  377. laShowNodeSocket(uil,c,This,"in_" what,0)->Flags|=LA_UI_SOCKET_LABEL_E; \
  378. laUiItem* value=laShowItem(uil,c,This,"i" what); \
  379. value=laShowItem(uil,c,This,what);value->Expand=1; \
  380. }laEndRow(uil,b);
  381. ADSR_ROW("attack") ADSR_ROW("delay") ADSR_ROW("sustain") ADSR_ROW("release")
  382. b=laBeginRow(uil,c,0,0);
  383. laShowItem(uil,c,This,"gate")->Expand=1;
  384. laShowNodeSocket(uil,c,This,"in_gate",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  385. laShowNodeSocket(uil,c,This,"in_trigger",0)->Flags|=LA_UI_SOCKET_LABEL_E;
  386. laEndRow(uil,b);
  387. b=laBeginRow(uil,c,0,0);
  388. laShowSeparator(uil,c)->Expand=1;
  389. laShowItem(uil,c,This,"trigger")->Flags|=LA_UI_FLAGS_MOMENTARY|LA_UI_FLAGS_HIGHLIGHT;
  390. laShowItem(uil,c,This,"out")->Flags|=LA_UI_SOCKET_LABEL_W;
  391. laEndRow(uil,b);
  392. }
  393. void IDN_QuantizeInit(laSynthNodeQuantize* n, int NoCreate){
  394. if(!NoCreate){ strSafeSet(&n->Base.Name,"Envelope");
  395. n->In=laCreateInSocket("IN",0); n->Out=laCreateOutSocket(n, "OUT",0);
  396. }
  397. if(!n->OutSamples){ n->OutSamples=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN); }
  398. n->Out->Data = n->OutSamples; n->Out->DataType = LA_PROP_FLOAT|LA_PROP_ARRAY; n->Out->ArrLen=LA_SYNTH_PLEN;
  399. int Enabled[12]={1,0,1,0,1,1,0,1,0,1,0,1};
  400. memcpy(n->EnabledBits,Enabled,sizeof(Enabled));
  401. }
  402. void IDN_QuantizeDestroy(laSynthNodeQuantize* n){
  403. laDestroyInSocket(n->In); laDestroyOutSocket(n->Out);
  404. memFree(n->OutSamples);
  405. strSafeDestroy(&n->Base.Name);
  406. }
  407. int IDN_QuantizeVisit(laSynthNodeQuantize* n, laNodeVisitInfo* vi){
  408. LA_GUARD_THIS_NODE(n,vi);
  409. if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
  410. LA_ADD_THIS_NODE(n,vi);
  411. return LA_DAG_FLAG_PERM;
  412. }
  413. static const real QTABLE[12]={ VAL13-VALHALF*9, VAL13-VALHALF*8, VAL13-VALHALF*7, VAL13-VALHALF*6,
  414. VAL13-VALHALF*5, VAL13-VALHALF*4, VAL13-VALHALF*3, VAL13-VALHALF*2,
  415. VAL13-VALHALF*1, VAL13, VAL13+VALHALF*1, VAL13+VALHALF*2 };
  416. static void set_quantize_out_bit(laSynthNodeQuantize* n, int which){
  417. for(int i=0;i<12;i++){
  418. if(n->EnabledBits[i]){ n->EnabledBits[i]=1; }
  419. if(i==which && n->EnabledBits){ n->EnabledBits[i]=3; }
  420. }
  421. }
  422. int IDN_QuantizeEval(laSynthNodeQuantize* n){ real cv0=QTABLE[0]+5; /*C4*/ LA_GET_SRC_AS_VALUE(cv0, n->In);
  423. real* cv; INPUTPACKET(cv,n->In); real dists[12];
  424. for(int i=0;i<LA_SYNTH_PLEN;i++){
  425. int octave = (int)(cv0-QTABLE[0]); int minkey=0;
  426. if(cv){ cv0=cv[i]; }
  427. real use_cv = cv0 - octave;
  428. for(int j=0;j<12;j++){ dists[j] = fabs(use_cv - QTABLE[j]); }
  429. for(int j=1;j<12;j++){ if(n->EnabledBits[j] && dists[j] < dists[minkey]){ minkey=j; } }
  430. set_quantize_out_bit(n,minkey);
  431. n->OutSamples[i] = QTABLE[minkey]+octave;
  432. }
  433. return 1;
  434. }
  435. void IDN_QuantizeCopy(laSynthNodeQuantize* new, laSynthNodeQuantize* old, int DoRematch){
  436. if(DoRematch){
  437. LA_IDN_NEW_LINK(In) return;
  438. }
  439. LA_IDN_OLD_DUPL(Out);
  440. memcpy(new->EnabledBits,old->EnabledBits,sizeof(int)*12);
  441. }
  442. void laui_QuantizeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  443. laColumn* c=laFirstColumn(uil); laSynthNodeQuantize*n=This->EndInstance;
  444. LA_BASE_NODE_HEADER(uil,c,This);
  445. laUiItem* b;
  446. b=laBeginRow(uil,c,0,0);
  447. laUiItem* ui=laShowItem(uil,c,This,"enabled_keys");
  448. ui->Flags|=LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_TRANSPOSE|LA_UI_FLAGS_ICON; ui->Expand=1;
  449. laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  450. laShowNodeSocket(uil,c,This,"out",0)->Flags|=LA_UI_SOCKET_LABEL_W;
  451. laEndRow(uil,b);
  452. }
  453. void laRebuildSynthGraphs(){
  454. if(MAIN.Audio->CurrentSynth){
  455. laSpinLock(&MAIN.Audio->CurrentSynth->Lock);
  456. laRebuildPageEval(MAIN.Audio->CurrentSynth->Page);
  457. laSpinUnlock(&MAIN.Audio->CurrentSynth->Lock);
  458. }
  459. }
  460. int laEvalSynthGraphs(){
  461. laSynth* ss; int any=0;
  462. memset(MAIN.Audio->AudioSamples,0,sizeof(real)*LA_SYNTH_PLEN);
  463. for(ss=MAIN.Audio->Synths.pFirst;ss;ss=ss->Item.pNext){
  464. laSpinLock(&ss->Lock);
  465. if(!ss->Playing){ laSpinUnlock(&ss->Lock); continue; }
  466. MAIN.Audio->AudioEvalSynth=ss; MAIN.Audio->AudioEvalTime=0; INITPACKET(ss->AudioSamples);
  467. laRunPage(ss->Page,1);
  468. laSpinUnlock(&ss->Lock);
  469. for(int i=0;i<LA_SYNTH_PLEN;i++){
  470. MAIN.Audio->AudioSamples[i]+=ss->AudioSamples[i];
  471. }
  472. any=1;
  473. }
  474. return any;
  475. }
  476. void laaudio_DataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){
  477. float* out=pOutput; int any=1;
  478. for(int i=0;i<frameCount;i++){
  479. if(MAIN.Audio->NextAudioSample>=LA_SYNTH_PLEN){
  480. MAIN.Audio->NextAudioSample=0;
  481. if(laEvalSynthGraphs()){
  482. MAIN.Audio->AudioEvalTotalSamples+=LA_SYNTH_PLEN;
  483. MAIN.Audio->AudioEvalTime=(real)MAIN.Audio->AudioEvalTotalSamples/MAIN.Audio->AudioSampleRate;
  484. }else{ any=0;}
  485. }
  486. out[i]=MAIN.Audio->AudioSamples[MAIN.Audio->NextAudioSample]/10;
  487. MAIN.Audio->NextAudioSample++;
  488. }
  489. laSpinLock(&MAIN.Audio->AudioStatusLock);
  490. MAIN.Audio->AudioAny=any;
  491. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  492. }
  493. void la_SelectAudioDevice(laAudioDevice* ad){
  494. memAssignRef(MAIN.Audio, &MAIN.Audio->UsingDevice, ad);
  495. ma_device_stop(&MAIN.Audio->AudioDevice);
  496. ma_device_uninit(&MAIN.Audio->AudioDevice);
  497. if(!ad) return;
  498. int SampleRate=48000;
  499. ma_device_config config = ma_device_config_init(ma_device_type_playback);
  500. config.playback.pDeviceID= 0;
  501. config.playback.format = ma_format_f32;
  502. config.playback.channels = 1;
  503. config.sampleRate = SampleRate;
  504. config.dataCallback = laaudio_DataCallback;
  505. config.pUserData = 0;
  506. if (ma_device_init(NULL, &config, &MAIN.Audio->AudioDevice) != MA_SUCCESS){ return; }
  507. MAIN.Audio->AudioSampleRate=SampleRate;
  508. MAIN.Audio->NextAudioSample=LA_SYNTH_PLEN;
  509. MAIN.Audio->AudioFrameInterval=1.0f/SampleRate;
  510. }
  511. void la_AddAudioDevice(int id, char* Name){
  512. laAudioDevice* ad=memAcquire(sizeof(laAudioDevice));
  513. strSafeSet(&ad->Name,Name); ad->MiniAudioID=id;
  514. lstAppendItem(&MAIN.Audio->AudioDevices,ad);
  515. }
  516. void la_ClearAudioDevices(){
  517. laAudioDevice* ad; while(ad=lstPopItem(&MAIN.Audio->AudioDevices)){
  518. strSafeDestroy(&ad->Name); memFree(ad);
  519. }
  520. }
  521. void laRefreshAudioDevices(){
  522. if(!MAIN.Audio) return; la_ClearAudioDevices();
  523. ma_device_info* pPlaybackInfos;
  524. ma_uint32 playbackCount;
  525. ma_device_info* pCaptureInfos;
  526. ma_uint32 captureCount;
  527. if (ma_context_get_devices(&MAIN.Audio->MiniAudioContext, &pPlaybackInfos, &playbackCount, &pCaptureInfos, &captureCount) != MA_SUCCESS) {
  528. logPrintNew("Can't get audio devices.\n");
  529. }
  530. for (ma_uint32 iDevice = 0; iDevice < playbackCount; iDevice += 1) {
  531. la_AddAudioDevice(iDevice, pPlaybackInfos[iDevice].name);
  532. }
  533. }
  534. void laInitMiniAudio(){
  535. if (ma_context_init(NULL, 0, NULL, &MAIN.Audio->MiniAudioContext) != MA_SUCCESS) {
  536. printf("Can't init miniaudio context\n");
  537. }
  538. laRefreshAudioDevices();
  539. la_SelectAudioDevice(MAIN.Audio->AudioDevices.pFirst);
  540. INITPACKET(MAIN.Audio->AudioSamples);
  541. laSpinInit(&MAIN.Audio->AudioStatusLock);
  542. }
  543. void laDeinitAudio(){
  544. laSpinDestroy(&MAIN.Audio->AudioStatusLock);
  545. ma_device_stop(&MAIN.Audio->AudioDevice);
  546. ma_device_uninit(&MAIN.Audio->AudioDevice);
  547. ma_context_uninit(&MAIN.Audio->MiniAudioContext);
  548. }
  549. // Operations
  550. int OPINV_laRefreshAudioDevices(laOperator* a, laEvent* e){
  551. laRefreshAudioDevices(); return LA_FINISHED;
  552. }
  553. laSynth* laNewSynth(char* Name){
  554. laSynth* ss=memAcquireHyper(sizeof(laSynth));
  555. ss->Page=memAcquire(sizeof(laRackPage));
  556. ss->Page->RackType=LA_RACK_TYPE_AUDIO;
  557. strSafeSet(&ss->Name,Name);
  558. lstAppendItem(&MAIN.Audio->Synths,ss);
  559. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,ss);
  560. laSpinInit(&ss->Lock);
  561. return ss;
  562. }
  563. void laRemoveSynth(laSynth* ss){ if(!ss) return;
  564. strSafeDestroy(&ss->Name);
  565. if(MAIN.Audio->CurrentSynth==ss){
  566. laSynth* nss=ss->Item.pNext?ss->Item.pNext:ss->Item.pPrev;
  567. memAssignRef(MAIN.Audio,&MAIN.Audio->CurrentSynth,nss);
  568. }laNotifyInstanceUsers(ss);
  569. while(ss->Page->Racks.pFirst){ laDestroyRack(ss->Page->Racks.pFirst); } memLeave(ss->Page); ss->Page=0;
  570. lstRemoveItem(&MAIN.Audio->Synths,ss);
  571. laSpinDestroy(&ss->Lock);
  572. memLeave(ss);
  573. }
  574. int OPINV_ShedNewSynth(laOperator* a, laEvent* e){
  575. laNewSynth("New Synth");
  576. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","New synth", 0);
  577. return LA_FINISHED;
  578. }
  579. int OPCHK_IslaSynth(laPropPack *This, laStringSplitor *ss){
  580. if (This && This->EndInstance && la_EnsureSubTarget(This->LastPs->p,0) == LA_PC_SYNTH) return 1;
  581. return 0;
  582. }
  583. int OPINV_ShedRemoveSynth(laOperator* a, laEvent* e){
  584. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  585. if(strSame(strGetArgumentString(a->ExtraInstructionsP,"confirm"),"true")){
  586. laRemoveSynth(ss);
  587. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","Remove synthesizer", 0);
  588. return LA_FINISHED;
  589. }
  590. laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
  591. return LA_RUNNING;
  592. }
  593. void laui_RemoveSynth(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  594. laColumn* c=laFirstColumn(uil);
  595. laShowItemFull(uil,c,This,"remove_synth",0,"confirm=true;text=Confirm",0,0);
  596. }
  597. int OPINV_laSynthPlay(laOperator* a, laEvent* e){
  598. laSynth* ss=a->This?a->This->EndInstance:0; if(!ss)return LA_CANCELED;
  599. char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
  600. int play=0; if(str && strSame(str,"PLAY")) play=1;
  601. if(play){ MAIN.Audio->AudioAny=1; }
  602. laSpinLock(&ss->Lock); ss->Playing=play; laSpinUnlock(&ss->Lock);
  603. ma_device_start(&MAIN.Audio->AudioDevice); laNotifyInstanceUsers(ss);
  604. return LA_FINISHED;
  605. }
  606. void laAudioEnsureChannelPtr(){
  607. for(laAudioChannel* iac=MAIN.Audio->Channels.pFirst;iac;iac=iac->Item.pNext){
  608. TNS_CLAMP(iac->ID,0,31);
  609. MAIN.Audio->ChannelPtr[iac->ID]=iac;
  610. }
  611. }
  612. laAudioChannel* laNewAudioChannel(char* Name){
  613. laAudioChannel* ac=memAcquireHyper(sizeof(laAudioChannel)); lstAppendItem(&MAIN.Audio->Channels,ac);
  614. strSafeSet(&ac->Name,Name); int has=0,i;
  615. for(i=0;i<64;i++){
  616. for(laAudioChannel* iac=MAIN.Audio->Channels.pFirst;iac;iac=iac->Item.pNext){ if(iac->ID==i){ has=1; break; } }
  617. }
  618. if(!has){ac->ID = i;}else{ac->ID=0;}
  619. ac->Volume = 10.0f; laAudioEnsureChannelPtr();
  620. }
  621. void laRemoveAudioChannel(laAudioChannel* ac){
  622. lstRemoveItem(&MAIN.Audio->Channels,ac); strSafeDestroy(&ac->Name);
  623. memFree(ac); laAudioEnsureChannelPtr();
  624. }
  625. int OPCHK_IslaAudioChannel(laPropPack *This, laStringSplitor *ss){
  626. if (This && This->EndInstance && la_EnsureSubTarget(This->LastPs->p,0) == LA_PC_CHANNEL) return 1;
  627. return 0;
  628. }
  629. int OPINV_ShedNewAudioChannel(laOperator* a, laEvent* e){
  630. laNewAudioChannel("Output");
  631. laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","New channel", 0); // TODO: hint for laAudioEnsureChannelPtr
  632. return LA_FINISHED;
  633. }
  634. int OPINV_ShedRemoveAudioChannel(laOperator* a, laEvent* e){
  635. laAudioChannel*ac=a->This?a->This->EndInstance:0; if(!ac)return LA_CANCELED;
  636. if(strSame(strGetArgumentString(a->ExtraInstructionsP,"confirm"),"true")){
  637. laRemoveAudioChannel(ac); laNotifyInstanceUsers(MAIN.Audio); laRecordAndPush(0,"la.audio","Remove audio channel", 0);
  638. return LA_FINISHED;
  639. }
  640. laEnableOperatorPanel(a,a->This,e->x,e->y,200,200,0,0,0,0,0,0,0,0,e);
  641. return LA_RUNNING;
  642. }
  643. void laui_RemoveAudioChannel(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  644. laColumn* c=laFirstColumn(uil);
  645. laShowItemFull(uil,c,This,"remove",0,"confirm=true;text=Confirm",0,0);
  646. }
  647. void lauidetached_Synthersizers(laPanel* p){
  648. la_MakeDetachedProp(p, "la.detached_view_switch", "detached");
  649. la_MakeDetachedProp(p, "la.audio.current_synth", "page");
  650. }
  651. void laui_Synthersizers(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  652. laColumn* c=laFirstColumn(uil),*cl, *cr,*crl,*crr;
  653. laSplitColumn(uil,c,0.4); cl=laLeftColumn(c,1); cr=laRightColumn(c,0);
  654. laSplitColumn(uil,cr,0.6); crl=laLeftColumn(cr,0); crr=laRightColumn(cr,2);
  655. laShowItemFull(uil,cl,Extra,"detached",0,0,0,0)->Flags|=LA_UI_FLAGS_HIGHLIGHT|LA_UI_FLAGS_ICON;
  656. #define ADD_PAGE \
  657. laUiItem* b=laBeginRow(uil,crl,0,0);\
  658. laShowItemFull(uil,crl,&rb->PP,"",LA_WIDGET_COLLECTION_SELECTOR,0,laui_IdentifierOnly,0)\
  659. ->Flags|=LA_UI_COLLECTION_SIMPLE_SELECTOR;\
  660. laUiItem* b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{\
  661. laShowItem(uil,crl,&rb->PP,"name");\
  662. laShowItem(uil,crl,0,"LA_new_synth")->Flags|=LA_UI_FLAGS_ICON;\
  663. laShowSeparator(uil,crl);\
  664. laShowItem(uil,crl,&rb->PP,"remove_synth")->Flags|=LA_UI_FLAGS_ICON;\
  665. laShowSeparator(uil,crl)->Expand=1;\
  666. }laElse(uil,b3);{\
  667. laShowItem(uil,crl,0,"LA_new_synth");\
  668. }laEndCondition(uil,b3);\
  669. laEndRow(uil,b);\
  670. b3=laOnConditionThat(uil,cr,laPropExpression(&rb->PP,""));{\
  671. laUiItem* b4=laOnConditionThat(uil,crr,laPropExpression(&rb->PP,"playing"));{\
  672. laShowItemFull(uil,crr,&rb->PP,"play",0,"text=❚❚;",0,0) \
  673. ->Flags|=LA_UI_FLAGS_EXIT_WHEN_TRIGGERED|LA_TEXT_ALIGN_CENTER; \
  674. }laElse(uil,b4);{\
  675. laShowItemFull(uil,crr,&rb->PP,"play",0,"icon=▶;mode=PLAY;",0,0) \
  676. ->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_EXIT_WHEN_TRIGGERED; \
  677. }laEndCondition(uil,b4);\
  678. laShowItemFull(uil,c,&rb->PP,"page",LA_WIDGET_COLLECTION_SINGLE,0,laui_RackPage,0)->Flags|=LA_UI_FLAGS_NO_DECAL;\
  679. }laEndCondition(uil,b3);\
  680. laUiItem* b1=laOnConditionThat(uil,cr,laPropExpression(Extra,"detached"));{
  681. laUiItem* rb=laShowInvisibleItem(uil,cr,Extra,"page");
  682. ADD_PAGE
  683. }laElse(uil,b1);{
  684. laUiItem* rb=laShowInvisibleItem(uil,cr,0,"la.audio.current_synth");
  685. ADD_PAGE
  686. }laEndCondition(uil,b1);
  687. #undef ADD_PAGE
  688. }
  689. void laui_AudioChannel(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  690. laColumn* c=laFirstColumn(uil); laSplitColumn(uil,c,0.3); laColumn* c1=laLeftColumn(c,1),*c2=laRightColumn(c,0); laUiItem* b;
  691. laShowHeightAdjuster(uil,c1,This,"__move",0);
  692. laShowItem(uil,c2,This,"name");
  693. b=laBeginRow(uil,c2,0,0);
  694. laShowItem(uil,c2,This,"id")->Expand=1; laShowItem(uil,c,This,"remove")->Flags|=LA_UI_FLAGS_ICON;
  695. laEndRow(uil,b);
  696. laShowItem(uil,c2,This,"volume");
  697. laShowSeparator(uil,c);
  698. }
  699. void laui_AudioChannels(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  700. laColumn* c=laFirstColumn(uil); laUiItem* b;
  701. b=laBeginRow(uil,c,0,0);
  702. laShowItem(uil,c,0,"LA_new_channel");
  703. laEndRow(uil,b);
  704. // if horizontal look:
  705. // laUiItem* g=laMakeGroup(uil,c,"Racks",0);{ g->Flags|=/*LA_UI_FLAGS_NO_GAP|LA_UI_FLAGS_NO_DECAL|*/LA_UI_FLAGS_NODE_CONTAINER;
  706. // laUiList* gu=g->Page; laColumn* gc=laFirstColumn(gu); gu->HeightCoeff=-1; g->State=LA_UI_ACTIVE;
  707. // laShowItemFull(gu,gc,0,"la.audio.channels",0,0,laui_AudioChannel,0)->Expand=5;
  708. // }
  709. laShowItemFull(uil,c,0,"la.audio.channels",0,0,laui_AudioChannel,0);
  710. }
  711. void* laget_FirstAudioDevice(void* unused1,void* unused2){
  712. return MAIN.Audio->AudioDevices.pFirst;
  713. }
  714. void* laget_FirstSynth(void* unused1,void* unused2){
  715. return MAIN.Audio->Synths.pFirst;
  716. }
  717. void lapost_Synth(laSynth* ss){
  718. laSpinInit(&ss->Lock);
  719. }
  720. int laget_SynthPlaying(laSynth* ss){
  721. int play=0;
  722. laSpinLock(&ss->Lock); play=ss->Playing; laSpinUnlock(&ss->Lock);
  723. return play;
  724. }
  725. void laset_CurrentSynth(laAudio* a,laSynth* s){
  726. memAssignRef(a,&a->CurrentSynth,s);
  727. }
  728. void laset_CurrentAudioDevice(laAudio* a,laAudioDevice* ad){
  729. la_SelectAudioDevice(ad);
  730. }
  731. void laget_OutputSendChannelName(laSynthNodeOutput* n, char* str, char** target){
  732. if(!MAIN.Audio||!MAIN.Audio->ChannelPtr[n->Send]) *target="-";
  733. *target = SSTR(MAIN.Audio->ChannelPtr[n->Send]->Name);
  734. }
  735. void laset_QuantizeEnabledKeys(laSynthNodeQuantize* n, int index, int val_UNUSED){
  736. if(n->EnabledBits[index] & 0x1){ n->EnabledBits[index]=0; }
  737. else{ n->EnabledBits[index]=1; }
  738. }
  739. void laset_AudioChannelID(laAudioChannel* ac, int id){
  740. ac->ID=id; laAudioEnsureChannelPtr();
  741. }
  742. void laset_AudioChannelMove(laAudioChannel* ac, int move){
  743. if(move<0 && ac->Item.pPrev){ lstMoveUp(&MAIN.Audio->Channels, ac); laNotifyUsers("la.audio"); }
  744. elif(move>0 && ac->Item.pNext){ lstMoveDown(&MAIN.Audio->Channels, ac); laNotifyUsers("la.audio"); }
  745. }
  746. void la_AudioPreFrame(){
  747. if(MAIN.GraphNeedsRebuild){ laRebuildSynthGraphs(); }
  748. int anyaudio=0;
  749. laSpinLock(&MAIN.Audio->AudioStatusLock);
  750. anyaudio=MAIN.Audio->AudioAny;
  751. laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  752. if(!anyaudio){ ma_device_stop(&MAIN.Audio->AudioDevice); }
  753. }
  754. void laInitAudio(){
  755. laPropContainer* pc; laProp* p; laSubProp* sp;
  756. laInitMiniAudio();
  757. laRegisterUiTemplate("LAUI_synthesizers","Synthesizers",laui_Synthersizers,lauidetached_Synthersizers,0,"Audio",0,0,0);
  758. laRegisterUiTemplate("LAUI_audio_channels","Mixer",laui_AudioChannels,0,0,0,0,0,0);
  759. laCreateOperatorType("LA_new_synth", "New Synthesizer", "Add a synthesizer",0,0,0,OPINV_ShedNewSynth,0,'+',0);
  760. laCreateOperatorType("LA_remove_synth", "Remove Synthesizer", "Remove a synthesizer",OPCHK_IslaSynth,0,0,OPINV_ShedRemoveSynth,OPMOD_FinishOnData,L'🗴',0)
  761. ->UiDefine=laui_RemoveSynth;
  762. laCreateOperatorType("LA_synth_play", "Play Synthesizer", "Play a synthesizer",OPCHK_IslaSynth,0,0,OPINV_laSynthPlay,0,0,0);
  763. laCreateOperatorType("LA_refresh_audio_devices", "Refresh Audio Devices", "Enumerate audio devices for selection",0,0,0,OPINV_laRefreshAudioDevices,0,U'🗘',0);
  764. laCreateOperatorType("LA_new_channel", "New Channel", "Add an audio channel",0,0,0,OPINV_ShedNewAudioChannel,0,'+',0);
  765. laCreateOperatorType("LA_remove_channel", "Remove Channel", "Remove an audio channel",OPCHK_IslaAudioChannel,0,0,OPINV_ShedRemoveAudioChannel,OPMOD_FinishOnData,L'🗴',0)
  766. ->UiDefine=laui_RemoveAudioChannel;
  767. pc = laAddPropertyContainer("la_audio_device","LaGUI Audio Device","LaGUI enumerated audio device",0,0,sizeof(laAudioDevice),0,0,1);{
  768. laAddStringProperty(pc,"name","Name","Name of the audio device",0,0,0,0,1,offsetof(laAudioDevice,Name),0,0,0,0,LA_AS_IDENTIFIER);
  769. }
  770. pc = laAddPropertyContainer("la_synth", "LaGUI Synthesizer", "LaGUI synthesizer", 0,0,sizeof(laSynth),lapost_Synth,0,2);{
  771. LA_PC_SYNTH=pc;
  772. laAddStringProperty(pc,"name","Name","Name of the synthesizer",0,0,0,0,1,offsetof(laSynth,Name),0,0,0,0,LA_AS_IDENTIFIER);
  773. 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);
  774. 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);
  775. laAddEnumItemAs(p,"IDLE","Idle","Synth is not playing",0,0);
  776. laAddEnumItemAs(p,"PLAYING","Playing","Synth is playing",1,0);
  777. laAddOperatorProperty(pc,"remove_synth","Remove Synth", "Remove synth", "LA_remove_synth", L'🗴', 0);
  778. laAddOperatorProperty(pc,"play","Play Synth", "Play synth", "LA_synth_play", 0, 0);
  779. }
  780. pc = laAddPropertyContainer("la_audio_channel", "LaGUI Audio Channel", "LaGUI Audio Channel", 0,0,sizeof(laAudioChannel),0,0,2);{
  781. LA_PC_CHANNEL=pc;
  782. laAddStringProperty(pc,"name","Name","Name of the synthesizer",0,0,0,0,1,offsetof(laAudioChannel,Name),0,0,0,0,LA_AS_IDENTIFIER);
  783. laAddIntProperty(pc,"id","ID","Identifier of this channel",0,0,0,31,0,0,0,0,offsetof(laAudioChannel,ID),0,laset_AudioChannelID,0,0,0,0,0,0,0,0,0);
  784. //laAddIntProperty(pc,"id","ID","Identifier of this channel",0,0,0,31,0,0,0,0,offsetof(laAudioChannel,ID),0,laset_AudioChannelID,0,0,0,0,0,0,0,0,0);
  785. 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);
  786. laAddOperatorProperty(pc,"remove","Remove Channel", "Remove this channel", "LA_remove_channel", L'🗴', 0);
  787. 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);
  788. }
  789. pc=laAddPropertyContainer("la_node_synth_fm", "FM OSC Node", "Osilliator node with frequency modulation",0,laui_FMNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
  790. LA_PC_IDN_FM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  791. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  792. 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);
  793. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeFM,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  794. 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);
  795. 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);
  796. 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);
  797. laAddEnumItemAs(p,"NONE","None","Regular frequency range",0,0);
  798. laAddEnumItemAs(p,"SLOW","Slow","Slow frequency range",1,0);
  799. pc=laAddPropertyContainer("la_node_synth_vca", "VCA Node", "Voltage controlled amplifier",0,laui_VCANode,sizeof(laSynthNodeVCA),lapost_Node,0,1);
  800. LA_PC_IDN_VCA=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  801. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  802. 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);
  803. laAddSubGroup(pc,"in", "Input","Input","la_in_socket",0,0,0,offsetof(laSynthNodeVCA,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  804. laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeVCA,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
  805. 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);
  806. 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);
  807. pc=laAddPropertyContainer("la_node_synth_noise", "Noise Node", "Noise node",0,laui_NoiseNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
  808. LA_PC_IDN_NOISE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  809. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  810. 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);
  811. 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);
  812. pc=laAddPropertyContainer("la_node_synth_scope", "Scope Node", "Scope for synthesizer",0,laui_ScopeNode,sizeof(laSynthNodeScope),lapost_Node,0,1);
  813. LA_PC_IDN_SCOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  814. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  815. 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);
  816. 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);
  817. 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);
  818. 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);
  819. #define _STR(a) #a
  820. #define ADD_TIME_FACTOR(a) laAddEnumItemAs(p,"FAC"_STR(a),_STR(a),"^"_STR(a)" time",a,0);
  821. ADD_TIME_FACTOR(1) ADD_TIME_FACTOR(2) ADD_TIME_FACTOR(3) ADD_TIME_FACTOR(4) ADD_TIME_FACTOR(5)
  822. ADD_TIME_FACTOR(6) ADD_TIME_FACTOR(7) ADD_TIME_FACTOR(8) ADD_TIME_FACTOR(9) ADD_TIME_FACTOR(10)
  823. #undef ADD_TIME_FACTOR
  824. 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);
  825. #define ADD_GAIN(a) laAddEnumItemAs(p,"GAIN"_STR(a),_STR(a),"^"_STR(a)" gain",a,0);
  826. #define ADD_GAIN_S(a,s) laAddEnumItemAs(p,"GAIN"_STR(a),s,"^"s" gain",a,0);
  827. 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)
  828. 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);
  829. 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)
  830. #undef ADD_GAIN
  831. #undef ADD_GAIN_S
  832. 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);
  833. 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);
  834. 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);
  835. 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);
  836. pc=laAddPropertyContainer("la_node_synth_output", "Output Node", "Sound output to system",0,laui_OutputNode,sizeof(laSynthNodeOutput),lapost_Node,0,1);
  837. LA_PC_IDN_OUTPUT=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  838. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  839. 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);
  840. laAddIntProperty(pc,"send","Send","Send to channel",0,0,0,128,0,0,0,0,offsetof(laSynthNodeOutput,Send),0,0,0,0,0,0,0,0,0,0,0);
  841. laAddStringProperty(pc,"send_channel_name","Channel Name","Channel name of this send target",0,0,0,0,0,-1,0,laget_OutputSendChannelName,0,0,LA_READ_ONLY|LA_UDF_IGNORE);
  842. pc=laAddPropertyContainer("la_node_synth_envelope", "Envelope Node", "Sound envelope",0,laui_EnvelopeNode,sizeof(laSynthNodeEnvelope),lapost_Node,0,1);
  843. LA_PC_IDN_ENVELOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  844. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  845. 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);
  846. 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);
  847. 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);
  848. 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);
  849. 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);
  850. 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);
  851. 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);
  852. 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);
  853. 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);
  854. 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);
  855. 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);
  856. 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);
  857. 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);
  858. 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);
  859. 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);
  860. 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);
  861. 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);
  862. laAddEnumItemAs(p,"IDLE","Idle","Trigger idle",0,0);
  863. laAddEnumItemAs(p,"TRIG","Trigger","Trigger active",1,0);
  864. pc=laAddPropertyContainer("la_node_synth_quantize", "Quantize Node", "Quantize control voltages",0,laui_QuantizeNode,sizeof(laSynthNodeQuantize),lapost_Node,0,1);
  865. LA_PC_IDN_QUANTIZE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
  866. laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
  867. 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);
  868. 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);
  869. 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);
  870. laAddEnumItemAs(p,"DISABLED","Disabled","Key is disabled",0,' ');
  871. laAddEnumItemAs(p,"ENABLED","Enabled","Key is enabled",1,' ');
  872. laAddEnumItemAs(p,"OUTPUT","Outputting","Key is Outputting",3,U'🌑');
  873. LA_IDN_REGISTER("VCO",'f',LA_IDN_FM, LA_PC_IDN_FM, IDN_FM, laSynthNodeFM);
  874. LA_IDN_REGISTER("VCA",'a',LA_IDN_VCA, LA_PC_IDN_VCA, IDN_VCA, laSynthNodeVCA);
  875. LA_IDN_REGISTER("Noise",'~',LA_IDN_NOISE, LA_PC_IDN_NOISE, IDN_Noise, laSynthNodeNoise);
  876. LA_IDN_REGISTER("Scope",'s',LA_IDN_SCOPE, LA_PC_IDN_SCOPE, IDN_Scope, laSynthNodeScope);
  877. LA_IDN_REGISTER("Sound Output",U'🕪',LA_IDN_OUTPUT, LA_PC_IDN_OUTPUT, IDN_Output, laSynthNodeOutput);
  878. LA_IDN_REGISTER("Envelope",U'^',LA_IDN_ENVELOPE, LA_PC_IDN_ENVELOPE, IDN_Envelope, laSynthNodeEnvelope);
  879. LA_IDN_REGISTER("Quantize",U'#',LA_IDN_QUANTIZE, LA_PC_IDN_QUANTIZE, IDN_Quantize, laSynthNodeQuantize);
  880. LA_NODE_CATEGORY_SYNTHESIZER=laAddNodeCategory("OSC",0,LA_RACK_TYPE_AUDIO);
  881. LA_NODE_CATEGORY_SYSTEM_SOUND=laAddNodeCategory("System",0,LA_RACK_TYPE_AUDIO);
  882. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER, &LA_IDN_FM,&LA_IDN_NOISE,&LA_IDN_VCA,&LA_IDN_ENVELOPE,&LA_IDN_QUANTIZE,&LA_IDN_SCOPE,0);
  883. laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYSTEM_SOUND, &LA_IDN_OUTPUT,0);
  884. }
  885. void laAudioDummy(){
  886. return 0;
  887. }