Debian Codegraph @

examples/strcpyk.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 -odac ;;;realtime audio out
5 ;-iadc ;;;uncomment -iadc if realtime audio input is needed too
6 ; For Non-realtime ouput leave only the line below:
7 ; -o strcpyk.wav -W ;;; for file output any platform
8 </CsOptions>
9 <CsInstruments>
10
11 sr = 44100
12 ksmps = 32
13 nchnls = 2
14 0dbfs = 1
15
16 seed 0
17
18 instr 1
19 ;get one element of the input string whenever the metro
20 ;triggers, and call a subinstrument to play the file
21
22 Smember strget p4
23 istrlen strlen Smember
24 kprint init 0
25 ktrig metro .6
26
27 if ktrig == 1 then ;whenever the trigger gives signal
28 kel random 0, 3.9999 ;choose a random element (0, 1 or 2)
29 kel = int(kel)
30 Scopy strcpyk Smember ;make a copy for leaving Smember intact
31 kndx = 0 ;set the initial index for reading substrings
32 kcount = 0 ;set counter for searching the element
33
34 loop: ;start looping over the elements in Smember
35 kdelim strindexk Scopy, ":"
36
37 if kdelim > 0 then ;as long as ":" occurs in Scopy, do:
38 if kel == kcount then ;if this is the element to get
39 Sfile strsubk Scopy, kndx, kdelim ;read it as substring
40 kprint = kprint+1
41 kgoto call ;and jump out
42 else ;if not
43 Scopy strsubk Scopy, kdelim+1, istrlen ;cut off this element from Scopy
44 endif
45 kcount = kcount+1 ;if no element has been found,go back to loop
46 kgoto loop ;and look for the next element
47 else ;if there is no delimiter left, the rest is the searched element
48 Sfile strcpyk Scopy
49 endif
50 call: ;print the result, call the subinstrument and play the file
51 printf "kel = %d, file = '%s'\n", ktrig+kprint, kel, Sfile
52 S_call sprintfk {{i 2 0 1 "%s"}}, Sfile
53 scoreline S_call, ktrig
54 endif
55
56 endin
57
58 instr 2 ;play
59 Sfile strget p4
60 ilen filelen Sfile
61 p3 = ilen
62 asig soundin Sfile
63 outs asig, asig
64 endin
65 </CsInstruments>
66 <CsScore>
67
68 i 1 0 30 "marimba.aif:fox.wav:drumsMlp.wav:flute.aiff"
69 e
70 </CsScore>
71 </CsoundSynthesizer>