| User-Defined Opcode Database |
|---|
Step counter
Download UDO FileCounts steps upwards or downwards, whenever a trigger signal has been received. This is meant to be used in live interaction, and is simliar to counter objects in realtime programs like Max or Pd. The example shows how the basic function can be extended to repeat sequences in a certain range.
kcount Counter kup, kdown [, istep [, istart]]
istep - step size (default = 1)
istart - starting value (default = 0)
kup - counts upwards when 1
kdown - counts downwards when 1
kcount - current count as output
opcode Counter, k, kkio
kup, kdown, istep, istart xin
kcount init istart
kchange changed kup, kdown
if kchange == 1 then
if kup == 1 then
kcount = kcount+istep
elseif kdown == 1 then
kcount = kcount-istep
endif
endif
xout kcount
endop
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
opcode Counter, k, kkio
;adds (subtracts) istep to the current value (beginning at istart) whenever kup (kdown) is 1
kup, kdown, istep, istart xin
kcount init istart
kchange changed kup, kdown
if kchange == 1 then
if kup == 1 then
kcount = kcount+istep
elseif kdown == 1 then
kcount = kcount-istep
endif
endif
xout kcount
endop
opcode KeyOnce, kk, kkk
;returns '1' just in the k-cycle a certain key has been pressed (kdown) or released (kup)
key, kd, kascii xin ;sensekey output and ascii code of the key (e.g. 32 for space)
knew changed key
kdown = (key == kascii && knew == 1 && kd == 1 ? 1 : 0)
kup = (key == kascii && knew == 1 && kd == 0 ? 1 : 0)
xout kdown, kup
endop
instr 1 ;counts up or down for the "+" or "-" key
;can be used either endless (kcount) or in a step sequencer (kseq)
iseq = 7 ;how many steps to use in a sequencer
key,kd sensekey
kup,k0 KeyOnce key, kd, 43
kdown,k0 KeyOnce key, kd, 45
kcount Counter kup, kdown, 1, 0
kseq = kcount % iseq ;sequencer 1-7
kseq = (kseq > 0 ? kseq : iseq+kseq)
knew changed kcount
if knew == 1 then
printks "kcount = %.0f, kseq = %.0f%n", 0, kcount, kseq
endif
endin
</CsInstruments>
<CsScore>
i 1 0 1000
</CsScore>
</CsoundSynthesizer>
joachim heintz 2011
| Previous | Home | Next |
| circumspect | cpsmid |