*/}}
1
0
فهرست منبع

VCA and Oscilloscope

YimingWu 1 سال پیش
والد
کامیت
b906c0eff7
5فایلهای تغییر یافته به همراه282 افزوده شده و 19 حذف شده
  1. 173 14
      la_audio.c
  2. 31 0
      la_interface.h
  3. 21 5
      la_kernel.c
  4. 1 0
      la_resource.c
  5. 56 0
      resources/la_widgets.c

+ 173 - 14
la_audio.c

@@ -28,10 +28,14 @@ laNodeCategory* LA_NODE_CATEGORY_SYNTHESIZER;
 laNodeCategory* LA_NODE_CATEGORY_SYSTEM_SOUND;
 
 laBaseNodeType LA_IDN_FM;
+laBaseNodeType LA_IDN_VCA;
 laBaseNodeType LA_IDN_OUTPUT;
+laBaseNodeType LA_IDN_SCOPE;
 
 laPropContainer* LA_PC_IDN_FM;
+laPropContainer* LA_PC_IDN_VCA;
 laPropContainer* LA_PC_IDN_OUTPUT;
+laPropContainer* LA_PC_IDN_SCOPE;
 
 #define _2PI 6.283185307
 
@@ -50,13 +54,13 @@ laPropContainer* LA_PC_IDN_OUTPUT;
 
 
 void IDN_FMInit(laSynthNodeFM* n, int NoCreate){
+    INITPACKET(n->OutSamples);
     if(NoCreate){ return; }
     n->InFrequency=laCreateInSocket("FREQ",0); n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
     strSafeSet(&n->Base.Name,"FM"); n->Frequency=4;
-    INITPACKET(n->OutSamples);
 }
 void IDN_FMDestroy(laSynthNodeFM* n){
-    laDestroyInSocket(n->InFrequency); laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name);
+    laDestroyInSocket(n->InFrequency); laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
 }
 int IDN_FMVisit(laSynthNodeFM* n, laNodeVisitInfo* vi){
     if(LA_SRC_AND_PARENT(n->InFrequency)){ laBaseNode*bn=n->InFrequency->Source->Parent; LA_VISIT_NODE(bn,vi); }
@@ -67,7 +71,7 @@ int IDN_FMEval(laSynthNodeFM* n){
     real f=n->Frequency, constf=0; real* inputf;
     INPUTPACKET(inputf,n->InFrequency); LA_GET_SRC_AS_VALUE(constf,n->InFrequency); 
     for(int i=0;i<LA_SYNTH_PLEN;i++){
-        real useF=inputf?(inputf[i]+f):(f+constf);
+        real useF=inputf?(inputf[i]+f):(f+constf); if(n->Slow) useF-=10;
         n->Phase+=MAIN.Audio->AudioFrameInterval*VAL2FREQ(useF)*_2PI;
         WRAPPHASE(n->Phase);
         n->OutSamples[i]=sin(n->Phase)*10;
@@ -77,22 +81,139 @@ int IDN_FMEval(laSynthNodeFM* n){
 }
 void IDN_FMCopy(laSynthNodeFM* new, laSynthNodeFM* old, int DoRematch){
     if(DoRematch){ LA_IDN_NEW_LINK(InFrequency) return; }
-    LA_IDN_OLD_DUPL(Out);
+    LA_IDN_OLD_DUPL(Out); new->Frequency=old->Frequency;
 }
-void la_FMNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
+void laui_FMNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil); laSynthNodeFM*n=This->EndInstance;
     LA_BASE_NODE_HEADER(uil,c,This);
-    laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
 
     laUiItem* b=laBeginRow(uil,c,0,0);
     laShowNodeSocket(uil,c,This,"in_frequency",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    laShowItem(uil,c,This,"slow");
     laShowItem(uil,c,This,"frequency")->Expand=1;
+    laShowNodeSocket(uil,c,This,"out",0);
+    laEndRow(uil,b);
+}
+
+void IDN_VCAInit(laSynthNodeVCA* n, int NoCreate){
+    INITPACKET(n->OutSamples);
+    if(NoCreate){ return; }
+    n->InAmp=laCreateInSocket("AMP",0); n->In=laCreateInSocket("IN",0);
+    n->Out=laCreateOutSocket(n,"OUT",LA_PROP_FLOAT|LA_PROP_ARRAY);
+    strSafeSet(&n->Base.Name,"FM"); n->Amp=10;
+}
+void IDN_VCADestroy(laSynthNodeVCA* n){
+    laDestroyInSocket(n->InAmp); laDestroyInSocket(n->In);
+    laDestroyOutSocket(n->Out); strSafeDestroy(&n->Base.Name); memFree(n->OutSamples);
+}
+int IDN_VCAVisit(laSynthNodeVCA* n, laNodeVisitInfo* vi){
+    if(LA_SRC_AND_PARENT(n->In)){ laBaseNode*bn=n->In->Source->Parent; LA_VISIT_NODE(bn,vi); }
+    if(LA_SRC_AND_PARENT(n->InAmp)){ laBaseNode*bn=n->InAmp->Source->Parent; LA_VISIT_NODE(bn,vi); }
+    LA_ADD_THIS_NODE(n,vi);
+    return LA_DAG_FLAG_PERM;
+}
+int IDN_VCAEval(laSynthNodeVCA* n){
+    real amp=n->Amp, constamp=amp; real* inputamp=0,*input=0;
+    INPUTPACKET(input,n->In); INPUTPACKET(inputamp,n->InAmp);
+    if(!inputamp) LA_GET_SRC_AS_VALUE(constamp,n->InAmp); constamp/=10;
+    n->Out->Data=n->OutSamples; n->Out->ArrLen=LA_SYNTH_PLEN;
+    if(!input){ memset(n->OutSamples,0,sizeof(real)*LA_SYNTH_PLEN); return 0; }
+    for(int i=0;i<LA_SYNTH_PLEN;i++){
+        real useA=(inputamp?(inputamp[i]/10):1)*constamp;
+        n->OutSamples[i]= input[i]*useA;
+    }
+    return 1;
+}
+void IDN_VCACopy(laSynthNodeVCA* new, laSynthNodeVCA* old, int DoRematch){
+    if(DoRematch){ LA_IDN_NEW_LINK(InAmp) LA_IDN_NEW_LINK(In) return; }
+    LA_IDN_OLD_DUPL(Out); new->Amp=old->Amp;
+}
+void laui_VCANode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
+    laColumn* c=laFirstColumn(uil); laSynthNodeVCA*n=This->EndInstance;
+    LA_BASE_NODE_HEADER(uil,c,This);
+    laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
+
+    laUiItem* b=laBeginRow(uil,c,0,0);
+    laShowNodeSocket(uil,c,This,"in",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    laShowNodeSocket(uil,c,This,"in_amp",0);
+    laShowItem(uil,c,This,"amp")->Expand=1;
+    laShowNodeSocket(uil,cr,This,"out",0);
     laEndRow(uil,b);
+}
 
-    b=laBeginRow(uil,cr,0,0);
-    laShowSeparator(uil,cr)->Expand=1;
-    laShowNodeSocket(uil,cr,This,"out",0)->Flags|=LA_UI_SOCKET_LABEL_W;
+void IDN_ScopeInit(laSynthNodeScope* n, int NoCreate){
+    if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
+    if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
+    pthread_spin_init(&n->Lock,0);
+    if(NoCreate){ return; }
+    n->In1=laCreateInSocket("CH1",0); n->In2=laCreateInSocket("CH2",0);
+    strSafeSet(&n->Base.Name,"SCOPE"); n->Time=5; n->Brightness1=1.0f; n->Brightness2=0.5f;
+    n->Gain1=1; n->Gain2=1;
+}
+void IDN_ScopeDestroy(laSynthNodeScope* n){
+    laDestroyInSocket(n->In1); laDestroyOutSocket(n->In2); strSafeDestroy(&n->Base.Name);
+    memFree(n->Display1); memFree(n->Display2);
+    pthread_spin_destroy(&n->Lock);
+}
+int IDN_ScopeVisit(laSynthNodeScope* n, laNodeVisitInfo* vi){
+    if(LA_SRC_AND_PARENT(n->In1)){ laBaseNode*bn=n->In1->Source->Parent; LA_VISIT_NODE(bn,vi); }
+    if(LA_SRC_AND_PARENT(n->In2)){ laBaseNode*bn=n->In2->Source->Parent; LA_VISIT_NODE(bn,vi); }
+    LA_ADD_THIS_NODE(n,vi);
+    return LA_DAG_FLAG_PERM;
+}
+int IDN_ScopeEval(laSynthNodeScope* n){
+    if(!n->Display1){ n->Display1=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
+    if(!n->Display2){ n->Display2=memAcquireSimple(sizeof(real)*LA_SYNTH_PLEN*2); }
+    real* ch1,*ch2; INPUTPACKET(ch1,n->In1); INPUTPACKET(ch2,n->In2);
+    int Frame=1<<(n->Time-1); TNS_CLAMP(Frame,1,LA_SYNTH_PLEN);
+    int Times=LA_SYNTH_PLEN/Frame; int sp=0; pthread_spin_lock(&n->Lock);
+    for(int t=0;t<Times;t++){
+        real smin1=FLT_MAX,smax1=-FLT_MAX,smin2=FLT_MAX,smax2=-FLT_MAX;
+        for(int i=0;i<Frame;i++){
+            if(ch1){ smin1=TNS_MIN2(smin1,ch1[sp]); smax1=TNS_MAX2(smax1,ch1[sp]); }
+            if(ch2){ smin2=TNS_MIN2(smin2,ch2[sp]); smax2=TNS_MAX2(smax2,ch2[sp]); }
+            sp++;
+        }
+        if(!ch1){smin1=smax1=0;} if(!ch2){smin2=smax2=0;}
+        int ns=n->NextSample;
+        n->Display1[ns]=smin1; n->Display1[ns+LA_SYNTH_PLEN]=smax1;
+        n->Display2[ns]=smin2; n->Display2[ns+LA_SYNTH_PLEN]=smax2;
+        n->NextSample++; if(n->NextSample>=LA_SYNTH_PLEN) n->NextSample=0;
+    }
+    n->FromSynth=MAIN.Audio->AudioEvalSynth;
+    pthread_spin_unlock(&n->Lock);
+    return 1;
+}
+void IDN_ScopeCopy(laSynthNodeScope* new, laSynthNodeScope* old, int DoRematch){
+    if(DoRematch){ LA_IDN_NEW_LINK(In1)  LA_IDN_NEW_LINK(In2) return; }
+    new->Brightness1=old->Brightness1; new->Brightness2=old->Brightness2;
+    new->Gain1=old->Gain1; new->Gain2=old->Gain2;
+    new->Offset1=old->Offset1; new->Offset2=old->Offset2;
+    new->Time=old->Time;
+}
+void laui_ScopeNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
+    laColumn* c=laFirstColumn(uil); laSynthNodeScope*n=This->EndInstance;
+    LA_BASE_NODE_HEADER(uil,c,This);
+    laColumn* cl,*cr; laSplitColumn(uil,c,0.5); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
+
+    laUiItem* b=laBeginRow(uil,c,0,0);
+    laShowNodeSocket(uil,c,This,"in1",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    laUiItem* u=laShowItem(uil,c,This,"gain1");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
     laEndRow(uil,b);
+
+    b=laBeginRow(uil,c,0,0);
+    laShowNodeSocket(uil,c,This,"in2",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    u=laShowItem(uil,c,This,"gain2");u->Flags|=LA_UI_FLAGS_EXPAND; u->Expand=1;
+    laEndRow(uil,b);
+
+    laShowItem(uil,c,This,"scope")->Extra->HeightCoeff=6;
+
+    laShowLabel(uil,cl,"CH1",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
+    laShowItem(uil,cl,This,"bright1"); laShowItem(uil,cl,This,"offset1");
+    laShowLabel(uil,cr,"CH2",0,0)->Flags|=LA_TEXT_ALIGN_CENTER;
+    laShowItem(uil,cr,This,"bright2"); laShowItem(uil,cr,This,"offset2");
+
+    laShowItem(uil,c,This,"time")->Flags|=LA_UI_FLAGS_EXPAND;
 }
 
 void IDN_OutputInit(laSynthNodeOutput* n, int NoCreate){
@@ -116,7 +237,7 @@ int IDN_OutputEval(laSynthNodeOutput* n){
 void IDN_OutputCopy(laSynthNodeOutput* new, laSynthNodeOutput* old, int DoRematch){
     if(DoRematch){ LA_IDN_NEW_LINK(In) return; }
 }
-void la_OutputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
+void laui_OutputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil); laSynthNodeOutput*n=This->EndInstance;
     LA_BASE_NODE_HEADER(uil,c,This);
     laColumn* cl,*cr; laSplitColumn(uil,c,0.3); cl=laLeftColumn(c,0); cr=laRightColumn(c,0);
@@ -327,7 +448,7 @@ void* laget_FirstSynth(void* unused1,void* unused2){
 void lapost_Synth(laSynth* ss){
     pthread_spin_init(&ss->Lock,0);
 }
-int laget_Playing(laSynth* ss){
+int laget_SynthPlaying(laSynth* ss){
     int play=0;
     pthread_spin_lock(&ss->Lock); play=ss->Playing; pthread_spin_unlock(&ss->Lock);
     return play;
@@ -362,31 +483,69 @@ void laInitAudio(){
         LA_PC_SYNTH=pc;
         laAddStringProperty(pc,"name","Name","Name of the synthesizer",0,0,0,0,1,offsetof(laSynth,Name),0,0,0,0,LA_AS_IDENTIFIER);
         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);
-        p=laAddEnumProperty(pc,"playing","Playing","Synth is playing",0,0,0,0,0,-1,laget_Playing,0,0,0,0,0,0,0,0,LA_READ_ONLY);
+        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);
         laAddEnumItemAs(p,"IDLE","Idle","Synth is not playing",0,0);
         laAddEnumItemAs(p,"PLAYING","Playing","Synth is playing",1,0);
         laAddOperatorProperty(pc,"remove_synth","Remove Synth", "Remove synth", "LA_remove_synth", L'🗴', 0);
         laAddOperatorProperty(pc,"play","Play Synth", "Play synth", "LA_synth_play", 0, 0);
     }
 
-    pc=laAddPropertyContainer("la_node_synth_fm", "FM OSC Node", "Osilliator node with frequency modulation",0,la_FMNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
+    pc=laAddPropertyContainer("la_node_synth_fm", "FM OSC Node", "Osilliator node with frequency modulation",0,laui_FMNode,sizeof(laSynthNodeFM),lapost_Node,0,1);
     LA_PC_IDN_FM=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
     laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
     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);
     laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeFM,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
     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);
+    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);
+    laAddEnumItemAs(p,"NONE","None","Regular frequency range",0,0);
+    laAddEnumItemAs(p,"SLOW","Slow","Slow frequency range",1,0);
 
-    pc=laAddPropertyContainer("la_node_synth_output", "Output Node", "Sound output to system",0,la_OutputNode,sizeof(laSynthNodeOutput),lapost_Node,0,1);
+    pc=laAddPropertyContainer("la_node_synth_vca", "VCA Node", "Voltage controlled amplifier",0,laui_VCANode,sizeof(laSynthNodeVCA),lapost_Node,0,1);
+    LA_PC_IDN_VCA=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
+    laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
+    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);
+    laAddSubGroup(pc,"in", "Input","Input","la_in_socket",0,0,0,offsetof(laSynthNodeVCA,In),0,0,0,0,0,0,0,LA_UDF_SINGLE);
+    laAddSubGroup(pc,"out", "Out","Output","la_out_socket",0,0,0,offsetof(laSynthNodeVCA,Out),0,0,0,0,0,0,0,LA_UDF_SINGLE);
+    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);
+
+    pc=laAddPropertyContainer("la_node_synth_scope", "Scope Node", "Scope for synthesizer",0,laui_ScopeNode,sizeof(laSynthNodeScope),lapost_Node,0,1);
+    LA_PC_IDN_SCOPE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
+    laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
+    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);
+    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);
+    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);
+    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);
+#define _STR(a) #a
+#define ADD_TIME_FACTOR(a) laAddEnumItemAs(p,"FAC"_STR(a),_STR(a),"^"_STR(a)" time",a,0);
+    ADD_TIME_FACTOR(1) ADD_TIME_FACTOR(2) ADD_TIME_FACTOR(3) ADD_TIME_FACTOR(4) ADD_TIME_FACTOR(5)
+    ADD_TIME_FACTOR(6) ADD_TIME_FACTOR(7) ADD_TIME_FACTOR(8) ADD_TIME_FACTOR(9) ADD_TIME_FACTOR(10)
+#undef ADD_TIME_FACTOR
+    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);
+#define ADD_GAIN(a) laAddEnumItemAs(p,"GAIN"_STR(a),_STR(a),"^"_STR(a)" gain",a,0);
+    ADD_GAIN(1) ADD_GAIN(2) ADD_GAIN(3) ADD_GAIN(4) ADD_GAIN(5) ADD_GAIN(6)
+    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);
+    ADD_GAIN(1) ADD_GAIN(2) ADD_GAIN(3) ADD_GAIN(4) ADD_GAIN(5) ADD_GAIN(6)
+#undef ADD_GAIN
+    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);
+    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);
+    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);
+    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);
+
+    pc=laAddPropertyContainer("la_node_synth_output", "Output Node", "Sound output to system",0,laui_OutputNode,sizeof(laSynthNodeOutput),lapost_Node,0,1);
     LA_PC_IDN_OUTPUT=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);
     laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
     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);
 
     LA_IDN_REGISTER("VCO",'f',LA_IDN_FM, LA_PC_IDN_FM, IDN_FM, laSynthNodeFM);
+    LA_IDN_REGISTER("VCA",'a',LA_IDN_VCA, LA_PC_IDN_VCA, IDN_VCA, laSynthNodeVCA);
+    LA_IDN_REGISTER("Scope",'s',LA_IDN_SCOPE, LA_PC_IDN_SCOPE, IDN_Scope, laSynthNodeScope);
     LA_IDN_REGISTER("Sound Output",U'🕪',LA_IDN_OUTPUT, LA_PC_IDN_OUTPUT, IDN_Output, laSynthNodeOutput);
 
     LA_NODE_CATEGORY_SYNTHESIZER=laAddNodeCategory("OSC",0,LA_RACK_TYPE_AUDIO);
     LA_NODE_CATEGORY_SYSTEM_SOUND=laAddNodeCategory("System",0,LA_RACK_TYPE_AUDIO);
 
     laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER, &LA_IDN_FM,0);
+    laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER, &LA_IDN_VCA,0);
+    laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYNTHESIZER, &LA_IDN_SCOPE,0);
     laNodeCategoryAddNodeTypes(LA_NODE_CATEGORY_SYSTEM_SOUND, &LA_IDN_OUTPUT,0);
 }

+ 31 - 0
la_interface.h

@@ -368,6 +368,8 @@ STRUCTURE(LA){
     laWindow *CurrentWindow;
     laPanel *CurrentPanel;
 
+    laListHandle DeferredRedrawList;
+
     laProgressDisplay Progress;
 
     laAudio* Audio;
@@ -1109,6 +1111,7 @@ extern laWidget *LA_WIDGET_HEIGHT_ADJUSTER;
 extern laWidget *LA_WIDGET_RAW;
 extern laWidget *LA_WIDGET_MAPPER;
 extern laWidget *LA_WIDGET_IMAGE;
+extern laWidget *LA_WIDGET_SCOPE;
 
 #define LA_CONDITION_TRUE 1
 #define LA_CONDITION_FALSE 2
@@ -1386,6 +1389,7 @@ void lapost_Node(laBaseNode *bn);
 laBaseNode* la_CreateDriverNode(laNodeRack* ir, laBaseNodeType* NodeType);
 laBaseNode* la_CreateInputMapperNode(laNodeRack* ir, laBaseNodeType* NodeType);
 
+void* laget_InstanceSelf(void* instace);
 laPropContainer* laget_BaseNodeType(laBaseNode* bn);
 void laRegisterNode(laBaseNodeType* type, laPropContainer* pc,
                     laBaseNodeInitF init, laBaseNodeDestroyF destroy, laBaseNodeVisitF visit, laBaseNodeEvalF eval, laBaseNodeCopyF copy,
@@ -1672,6 +1676,7 @@ STRUCTURE(laSynth){
 
 STRUCTURE(laSynthNodeFM){
     laBaseNode Base;
+    int Slow;
     real Frequency;
     laNodeInSocket* InFrequency;
     laNodeOutSocket* Out;
@@ -1680,6 +1685,29 @@ STRUCTURE(laSynthNodeFM){
     real* OutSamples;
 };
 
+STRUCTURE(laSynthNodeVCA){
+    laBaseNode Base;
+    real Amp;
+    laNodeInSocket* In;
+    laNodeInSocket* InAmp;
+    laNodeOutSocket* Out;
+    real* OutSamples;
+};
+
+STRUCTURE(laSynthNodeScope){
+    laBaseNode Base;
+    int Time;
+    int Gain1,Gain2;
+    real Offset1,Offset2;
+    real Brightness1,Brightness2;
+    laNodeInSocket* In1;
+    laNodeInSocket* In2;
+    real *Display1,*Display2; // each PLEN*2, upper/lower bounds.
+    int NextSample;
+    pthread_spinlock_t Lock;
+    laSynth* FromSynth;
+};
+
 STRUCTURE(laSynthNodeOutput){
     laBaseNode Base;
     laNodeInSocket* In;
@@ -1702,6 +1730,7 @@ STRUCTURE(laAudio){
 };
 
 
+int laget_SynthPlaying(laSynth* ss);
 void* laget_FirstSynth(void* unused1,void* unused2);
 void laset_CurrentSynth(laAudio* a,laSynth* s);
 
@@ -1994,6 +2023,7 @@ void la_PropPanelUserRemover(void* This, laItemUserLinker* iul);
 
 void la_EnsurePanelExtras(laPanel *p);
 
+void laDeferredRedraw(laPanel* p);
 void laRedrawAllWindows();
 void laRefreshWindow();
 void laRedrawCurrentWindow();
@@ -2259,6 +2289,7 @@ extern laUiType *_LA_UI_HEIGHT_ADJUSTER;
 extern laUiType *_LA_UI_RAW;
 extern laUiType *_LA_UI_MAPPER;
 extern laUiType *_LA_UI_IMAGE;
+extern laUiType *_LA_UI_SCOPE;
  
 extern laUiDescriptor _LA_UI_DESCRIPTOR_REF_UI;
 extern laUiDescriptor _LA_UI_DESCRIPTOR_REF_UIE;

+ 21 - 5
la_kernel.c

@@ -2565,6 +2565,7 @@ laPanel* la_GivePanelNode(){
 }
 void la_ReturnPanelNode(laPanel* p){
     memset(p,0,sizeof(laPanel));
+    lstRemovePointer(&MAIN.DeferredRedrawList,p);
     lstAppendItem(&MAIN.WastedPanels, p);
 }
 laPanel *la_NewPanel(laUiTemplate* uit, int X, int Y, int W, int H, int MaxW, int MaxH, int MinW, int MinH, int SnapL, int SnapR, int SnapT, int SnapB){
@@ -3181,6 +3182,13 @@ laPanel *laEnableMessagePanel(laOperator *a, laPanel *Attachment, char *Title, c
     return p;
 }
 
+void laDeferredRedraw(laPanel* p){
+    for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
+        if(lip->p==p) return;
+    }
+    lstAppendPointer(&MAIN.DeferredRedrawList, p);
+}
+
 void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win)) return;
     laWindow* cur=MAIN.CurrentWindow;
     for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
@@ -7172,6 +7180,17 @@ int laFinalize(){
 
     return 1;
 }
+void la_PreFrame(){
+    if(MAIN.PreFrame){ MAIN.PreFrame(); }
+    la_AnimationPreFrame();
+    la_AudioPreFrame();
+}
+void la_PostFrame(){
+    for(laListItemPointer* lip=MAIN.DeferredRedrawList.pFirst;lip;lip=lip->pNext){
+        laRedrawPanel(lip->p);
+    }
+    if(MAIN.PostFrame){ MAIN.PostFrame(); }
+}
 void laMainLoop(){
     laWindow *w = MAIN.Windows.pFirst, *NextW;
     laTimeRecorder FrameStartTime, FrameEndTime;
@@ -7186,10 +7205,7 @@ void laMainLoop(){
     while (1){
         laRecordTime(&FrameStartTime);
 
-        if(MAIN.PreFrame){ MAIN.PreFrame(); }
-
-        la_AnimationPreFrame();
-        la_AudioPreFrame();
+        la_PreFrame();
 
         if(!la_ProcessSysMessage()){ return; }
 
@@ -7219,7 +7235,7 @@ void laMainLoop(){
 #endif
         }
 
-        if(MAIN.PostFrame){ MAIN.PostFrame(); }
+        la_PostFrame();
 
         //t2 = clock();
         laRecordTime(&FrameEndTime);

+ 1 - 0
la_resource.c

@@ -57,6 +57,7 @@ laUiType *_LA_UI_HEIGHT_ADJUSTER;
 laUiType *_LA_UI_RAW;
 laUiType *_LA_UI_MAPPER;
 laUiType *_LA_UI_IMAGE;
+laUiType *_LA_UI_SCOPE;
 
 laUiDefineFunc _LA_SUBPROP_DONT_CARE;
 

+ 56 - 0
resources/la_widgets.c

@@ -62,6 +62,7 @@ laWidget _LA_WIDGET_HEIGHT_ADJUSTER={0};
 laWidget _LA_WIDGET_RAW={0};
 laWidget _LA_WIDGET_MAPPER={0};
 laWidget _LA_WIDGET_IMAGE={0};
+laWidget _LA_WIDGET_SCOPE={0};
 
 laWidget *LA_WIDGET_FIXED_GROUP=&_LA_WIDGET_FIXED_GROUP;
 laWidget *LA_WIDGET_TAB=&_LA_WIDGET_TAB;
@@ -104,6 +105,7 @@ laWidget *LA_WIDGET_HEIGHT_ADJUSTER=&_LA_WIDGET_HEIGHT_ADJUSTER;
 laWidget *LA_WIDGET_RAW=&_LA_WIDGET_RAW;
 laWidget *LA_WIDGET_MAPPER=&_LA_WIDGET_MAPPER;
 laWidget *LA_WIDGET_IMAGE=&_LA_WIDGET_IMAGE;
+laWidget *LA_WIDGET_SCOPE=&_LA_WIDGET_SCOPE;
 
 //============================================== [Draw]
 
@@ -1551,6 +1553,57 @@ void la_ValueMeter2DDraw(laUiItem *ui, int h){
     glLineWidth(1);
 }
 
+void la_ScopeDraw(laUiItem *ui, int h){
+    laBoxedTheme *bt = (*ui->Type->Theme); laSynthNodeScope* s=ui->PP.EndInstance;
+    if(!s) return;
+    real* lcolor=laAccentColor(LA_BT_TEXT); int plen=LA_SYNTH_PLEN;
+    int cl=ui->L, cr=ui->R, cu=ui->U, cb=ui->B; real cc=(real)(cu+cb)/2;
+    real yfac1=1<<(s->Gain1-1), yfac2=1<<(s->Gain2-1); yfac1/=10; yfac2/=10;
+    pthread_spin_lock(&s->Lock);
+    real arrx[LA_SYNTH_PLEN];
+    real arru1[LA_SYNTH_PLEN],arrb1[LA_SYNTH_PLEN];
+    real arru2[LA_SYNTH_PLEN],arrb2[LA_SYNTH_PLEN];
+
+    tnsUseNoTexture(); tnsLineWidth(3.0);
+
+    for(int i=0;i<plen;i++){
+        arrx[i]=tnsInterpolate(cl,cr,((real)i)/plen);
+        arru1[i]=tnsInterpolate(cc,cb,yfac1*s->Display1[i]);
+        arrb1[i]=tnsInterpolate(cc,cb,yfac1*s->Display1[i+plen]);
+        tnsVertex2d(arrx[i],arru1[i]); tnsVertex2d(arrx[i],arrb1[i]);
+    }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness1*0.5);
+    tnsPackAs(GL_TRIANGLE_STRIP); tnsFlush();
+
+    for(int i=0;i<plen;i++){
+        arru2[i]=tnsInterpolate(cc,cb,yfac2*s->Display2[i]);
+        arrb2[i]=tnsInterpolate(cc,cb,yfac2*s->Display2[i+plen]);
+        tnsVertex2d(arrx[i],arru2[i]); tnsVertex2d(arrx[i],arrb2[i]);
+    }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness2*0.5);
+    tnsPackAs(GL_TRIANGLE_STRIP); tnsFlush();
+
+    for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arru1[i]); }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness1);
+    tnsPackAs(GL_LINE_STRIP);
+    for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arrb1[i]); }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness1);
+    tnsPackAs(GL_LINE_STRIP);
+
+    for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arru2[i]); }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness2);
+    tnsPackAs(GL_LINE_STRIP);
+    for(int i=0;i<plen;i++){ tnsVertex2d(arrx[i],arrb2[i]); }
+    tnsColor4d(LA_COLOR3(lcolor),s->Brightness2);
+    tnsPackAs(GL_LINE_STRIP);
+
+    tnsFlush(); tnsLineWidth(1.0);
+
+    pthread_spin_unlock(&s->Lock);
+
+    if(s->FromSynth && laget_SynthPlaying(s->FromSynth)){ laDeferredRedraw(MAIN.CurrentPanel); }
+}
+
 void la_ConditionNodeFreeRecursive(laUiConditionNode *ucn);
 void la_GeneralUiInit(laUiItem *ui){
     ui->Extra = memAcquireSimple(sizeof(laGeneralUiExtraData));
@@ -1724,6 +1777,9 @@ void la_RegisterUiTypesBasic(){
     _LA_UI_IMAGE = la_RegisterUiType("LA_image_default", 0, 0, &_LA_THEME_COLLECTION_GROUP, la_ImageDraw, la_ImageGetHeight, la_ImageUiInit, la_ImageUiDestroy);
     _LA_UI_IMAGE->GetMinWidth=la_ImageGetMinWidth;
 
+    LA_WIDGET_SCOPE->Type=
+    _LA_UI_SCOPE = la_RegisterUiType("LA_scope_default", 0, "LA_synth_scope", &_LA_THEME_COLLECTION_GROUP, la_ScopeDraw, la_ColorPickerGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
+
     _LA_UI_INVISIBLE.Theme=&_LA_THEME_BUTTON;
     _LA_UI_ROW_BEGIN.Theme=&_LA_THEME_BUTTON;
     _LA_UI_ROW_END.Theme=&_LA_THEME_BUTTON;