Debian Codegraph @

src/Examples/FLOSS Manual Examples/03 Csound Language/03F09_Events_sprintf.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 -odac
4 </CsOptions>
5 <CsInstruments>
6 sr = 44100
7 ksmps = 32
8 nchnls = 2
9 0dbfs = 1
10
11 giPch ftgen 0, 0, 4, -2, 7.09, 8.04, 8.03, 8.04
12 seed 0; random seed different each time
13
14 instr 1 ; master instrument with event pool
15 itimes = 7 ;number of events to produce
16 icnt = 0 ;counter
17 istart = 0
18 Slines = ""
19 loop: ;start of the i-time loop
20 idur random 1, 2.9999 ;duration of each note:
21 idur = int(idur) ;either 1 or 2
22 itabndx random 0, 3.9999 ;index for the giPch table:
23 itabndx = int(itabndx) ;0-3
24 ipch table itabndx, giPch ;random pitch value from the table
25 Sline sprintf "i 2 %d %d %.2f\n", istart, idur, ipch ;new scoreline
26 Slines strcat Slines, Sline ;append to previous scorelines
27 istart = istart + idur ;recalculate start for next scoreline
28 loop_lt icnt, 1, itimes, loop ;end of the i-time loop
29 puts Slines, 1 ;print the scorelines
30 scoreline_i Slines ;execute them
31 iend = istart + idur ;calculate the total duration
32 p3 = iend ;set p3 to the sum of all durations
33 print p3 ;print it
34 endin
35
36 instr 2 ;plays the notes
37 asig pluck .2, cpspch(p4), cpspch(p4), 0, 1
38 aenv transeg 1, p3, 0, 0
39 outs asig*aenv, asig*aenv
40 endin
41
42 </CsInstruments>
43 <CsScore>
44 i 1 0 1 ;p3 is automatically set to the total duration
45 e
46 </CsScore>
47 </CsoundSynthesizer>
48 ;example by joachim heintz