changed2 — k-rate signal change detector.
This opcode outputs a trigger signal that informs when any one of its k-rate arguments has changed, or a value in an array. Useful with valuator widgets or MIDI controllers.
ktrig - Outputs a value of 1 when any of the k-rate signals has changed, or any value in the array, otherwise outputs 0.
kvar1 [, kvar2,..., kvarN] - k-rate variables to watch for changes.
xarray - any array type.
Unlike the opcode changed this opcode will never report the first cycle as a change.
Here are two examples of the changed2 opcode. They use the files changed2.csd and changed2a.csd.
Example 131. Example of the changed2 opcode.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;RT audio out ;-iadc ;;;uncomment -iadc if RT audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o changed.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 instr 1 ksig oscil 2, 0.5, 1 kint = int(ksig) ktrig changed2 kint printk 0.2, kint printk2 ktrig endin </CsInstruments> <CsScore> f 1 0 1024 10 1 i 1 0 20 e </CsScore> </CsoundSynthesizer>
Its output should include lines like:
i 1 time 0.00267: 0.00000 i1 0.00000 i1 1.00000 i1 0.00000 i 1 time 0.20267: 1.00000 i 1 time 0.40267: 1.00000 i1 1.00000 i1 0.00000 i 1 time 0.60267: 1.00000 i 1 time 0.80267: 1.00000 i1 1.00000 i1 0.00000 i 1 time 1.00000: 0.00000 i1 1.00000 i1 0.00000 i 1 time 1.20267: -1.00000 i 1 time 1.40267: -1.00000 i1 1.00000 i1 0.00000 i 1 time 1.60267: -1.00000 i 1 time 1.80000: -1.00000 i1 1.00000 i1 0.00000 i 1 time 2.00000: -0.00000 i1 1.00000 i1 0.00000 .........
Example 132. Example of the changed2 opcode.
<CsoundSynthesizer> <CsOptions> -n </CsOptions> <CsInstruments> gkArray[][] init 2,3 gkArray fillarray 1,2,3,7,6,5 instr 1 k1 changed2 gkArray if k1==1 then printks "An element in the array changed", 0 endif endin instr 2; change value of channel 'step1' gkArray[1][0] = 3 endin </CsInstruments> <CsScore> i1 0 100 i2 4 .1 </CsScore> </CsoundSynthesizer>