Debian Codegraph @

examples/ftset.csd

raw
1 csdo<CsoundSynthesizer>
2 <CsOptions>
3 </CsOptions>
4 <CsInstruments>
5
6 ; Example file ftset
7
8 /*
9
10 ftset:
11
12 Write a value to the whole table, or a slice of it.
13
14 Syntax:
15
16 ftset ktablenum, kvalue, kstart=0, kend=0, kstep=1
17 ftset itablenum, ivalue, istart=0, iend=0, istep=1
18
19 ktablenum / itablenum:
20 table to be modified
21
22 kvalue / ivalue:
23 value to write to the table
24
25 kstart / istart:
26 the index to start modifying
27
28 kend / iend:
29 the end index to stop modifying. This is NOT inclusive. 0=end of table
30 Any negative index will be interpreted as counting from the end of the
31 table, so -2 will modify the whole table but the last two elements
32
33 kstep / istep:
34 how many elements to skip
35
36 See also: tablecopy, tableicopy, tab2array
37 */
38
39 instr 1
40 ; clear the table
41 itable ftgentmp 0, 0, 13, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
42 ftset itable, 0
43 ; print it at perf-time
44 ftprint itable, -1
45 turnoff
46 endin
47
48 instr 2
49 ; Set all elements but the last 5 to 99
50 itable ftgentmp 0, 0, 13, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
51
52 ftset itable, 99, 0, -5
53 ftprint itable, -1
54 turnoff
55 endin
56
57 instr 3
58 ; ftset works at k-time so it can be used inside an if clause
59 ; Set all even elements to 0 at the 10th k-cycle
60 itable ftgentmp 0, 0, 10, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
61 kcycle = timeinstk()
62 if kcycle == 10 then
63 ftset itable, 0, 0, 0, 2
64 endif
65 println "cycle num: %d", kcycle
66 ftprint itable, -1 ; print at each cycle
67 ; turnoff the instrument if table was indeed modified
68 if tab:k(6, itable) == 0 then
69 println "Table was modified, turning off"
70 turnoff
71 endif
72 endin
73
74 </CsInstruments>
75 <CsScore>
76 i 1 0 0.1
77 i 2 + 0.1
78 i 3 + 0.1
79
80 </CsScore>
81 </CsoundSynthesizer>