changed with array?
Date | 2016-02-21 13:16 |
From | Rory Walsh |
Subject | changed with array? |
This csd is not producing the output I expect. I first create a global k-array. I then set a list of channels to 0 and initialise all values in said array to 0. Then in instr3 I query the current value of each channels, and pass it to my array. I then check the value of each element in the array to see if it has changed. If an element has changed since the last kcycle we should get a single message printed to the console output, but instead we get a constant stream of messages. Once I set a channel to 1, it seems to continuously trigger the changed opcode? Or am I reading this wrong? instr 1: sets channels and initialises array instr 3: reads values from channels and looks for changes instr 2: changes the value of channel 'note1' from 0 to 1 <CsoundSynthesizer> <CsOptions> -+rtaudio=jack -odac -b4096 </CsOptions> <CsInstruments> gkLabels[] init 144 instr 1; set all channels to 0 iCnt init 0 until iCnt > 144 do S1 sprintf "note%d", iCnt+1 chnset 0, S1 gkLabels[iCnt] = 0 iCnt=iCnt+1 enduntil endin instr 2; change value of channel 'step1' chnset 1, "note1" endin instr 3; kIndex = 0 until kIndex==144 do gkLabels[kIndex] chnget sprintfk("note%d", kIndex+1) kTrig changed gkLabels[kIndex] if kTrig==1 then printks "Index of channel that has changed:%d\n", .1, kIndex endif kIndex +=1 enduntil endin </CsInstruments> <CsScore> i1 0 1 i3 1 30 i2 4 .1 </CsScore> |
Date | 2016-02-21 13:48 |
From | Victor Lazzarini |
Subject | Re: changed with array? |
I think you can't use changed as if it were a function. It has state, so you can't use it in a loop as if it were stateless. In your code I expect it to compare against the previous array slot, then it would show a change every time you go from a set slot to an unset one and viceversa. You would need to have an array with the previous states and compare to that. An UDO can be written for this. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
Date | 2016-02-21 15:11 |
From | Rory Walsh |
Subject | Re: changed with array? |
Thanks for your reply Victor. I'll rework it. On 21 Feb 2016 13:48, "Victor Lazzarini" <Victor.Lazzarini@nuim.ie> wrote:
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
|
Date | 2016-02-21 15:57 |
From | Rory Walsh |
Subject | Re: changed with array? |
Should the following code not work then? At the end of each k-cycle I write the values of gkLabels1 to gkLabels2. Then on the next k-cycle I compare the two arrays. Still not notification about any changes.. <CsoundSynthesizer> <CsOptions> -+rtaudio=jack -odac -b4096 </CsOptions> <CsInstruments> gkLabels1[] init 144 gkLabels2[] init 144 instr 1; set all channels to 0 iCnt init 0 until iCnt > 144 do S1 sprintf "note%d", iCnt+1 chnset 0, S1 gkLabels1[iCnt] = 0 gkLabels2[iCnt] = 0 iCnt=iCnt+1 enduntil endin instr 2; change value of channel 'step1' chnset p4, "note1" turnoff endin instr 3; pass values from channels into array kIndex = 0 until kIndex<144 do gkLabels1[kIndex] chnget sprintfk("note%d", kIndex+1) if gkLabels1[kIndex] != gkLabels2[kIndex] then printks "Index of channel that has changed:%d\n", 0, kIndex endif kIndex = kIndex+1 enduntil ;assign values to gkLabels2 gkLabels2[] = gkLabels1 endin </CsInstruments> <CsScore> i1 0 1 i3 1 30 i2 4 .1 1 i2 6 .1 0 </CsScore> On 21 February 2016 at 15:11, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2016-02-21 17:45 |
From | Rory Walsh |
Subject | Re: changed with array? |
Even with ksmps = 1 this still doesn't work. But I'm guessing there is a good reason? On 21 February 2016 at 15:57, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2016-02-21 18:07 |
From | Steven Yi |
Subject | Re: changed with array? |
I tested here and the problem is with your until loop, it should be: until kIndex >= 144 do On Sun, Feb 21, 2016 at 12:45 PM, Rory Walsh |
Date | 2016-02-21 18:10 |
From | Rory Walsh |
Subject | Re: changed with array? |
Oh dear God. I can't think why I changed it from ==, must have been a copy and paste botch job.. On 21 Feb 2016 18:07, "Steven Yi" <stevenyi@gmail.com> wrote:
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
I tested here and the problem is with your until loop, it should be: |