*/}}

la_audio.c 73 KB

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