Debian Codegraph @

examples/scogen.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 ; Select audio/midi flags here according to platform
4 ; Audio out Audio in No messages
5 ; -odac -iadc -d ;;;RT audio I/O
6 ; For Non-realtime ouput leave only the line below:
7 -n
8 ;Don't write audio ouput to disk
9 </CsOptions>
10 <CsInstruments>
11 ;===========================================================
12 ; scogen.csd by: Matt Ingalls
13 ;
14 ; a "port" of sorts
15 ; of the old "mills" score generator (scogen)
16 ;
17 ; this instrument creates a schottstaedt.sco file
18 ; to be used with the schottstaedt.orc file
19 ;
20 ; as long as you dont save schottstaedt.orc as a .csd
21 ; file, you should be able to keep it open in MacCsound
22 ; and render each newly generated .sco file.
23 ;
24 ;===========================================================
25
26
27 gScoName = "schottstaedt.sco" ; the name of the file to be generated
28
29 sr = 100 ; this defines our temporal resolution,
30 ; an sr of 100 means we will generate p2 and p3 values
31 ; to the nearest 1/100th of a second
32
33 ksmps = 1 ; set kr=sr so we can do everything at k-rate
34
35
36 ; some print opcodes
37 opcode PrintInteger, 0, k
38 kval xin
39 fprintks gScoName, "%d", kval
40 endop
41
42 opcode PrintFloat, 0, k
43 kval xin
44 fprintks gScoName, "%f", kval
45 endop
46
47 opcode PrintTab, 0, 0
48 fprintks gScoName, "%n"
49 endop
50
51 opcode PrintReturn, 0, 0
52 fprintks gScoName, "%r"
53 endop
54
55
56 ; recursively calling opcode to handle all the optional parameters
57 opcode ProcessAdditionalPfields, 0, ikio
58 iPtable, kndx, iNumPfields, iPfield xin
59
60 ; additional pfields start at 5, we use a default 0 to identify the first call
61 iPfield = (iPfield == 0 ? 5 : iPfield)
62
63 if (iPfield > iNumPfields) goto endloop
64 ; find our tables
65 iMinTable table 2*iPfield-1, iPtable
66 iMaxTable table 2*iPfield, iPtable
67
68 ; get values from our tables
69 kMin tablei kndx, iMinTable
70 kMax tablei kndx, iMaxTable
71
72 ; find a random value in the range and write it to the score
73 fprintks gScoName, "%t%f", kMin + rnd(kMax-kMin)
74
75 ; recursively call for any additional pfields.
76 ProcessAdditionalPfields iPtable, kndx, iNumPfields, iPfield + 1
77 endloop:
78
79 endop
80
81
82 /* ===========================================================
83 Generate a gesture of i-statements
84
85 p2 = start of the gesture
86 p3 = duration of the gesture
87 p4 = number of a function that contains a list of all
88 function table numbers used to define the
89 pfield random distribution
90 p5 = scale generated p4 values according to density (0=off, 1=on) [todo]
91 p6 = let durations overlap gesture duration (0=off, 1=on) [todo]
92 p7 = seed for random number generator seed [todo]
93 ===========================================================
94 */
95 instr Gesture
96
97 ; initialize
98 iResolution = 1/sr
99
100 kNextStart init p2
101 kCurrentTime init p2
102
103 iNumPfields table 0, p4
104 iInstrMinTable table 1, p4
105 iInstrMaxTable table 2, p4
106 iDensityMinTable table 3, p4
107 iDensityMaxTable table 4, p4
108 iDurMinTable table 5, p4
109 iDurMaxTable table 6, p4
110 iAmpMinTable table 7, p4
111 iAmpMaxTable table 8, p4
112
113 ; check to make sure there is enough data
114 print iNumPfields
115 if iNumPfields < 4 then
116 prints "%dError: At least 4 p-fields (8 functions) need to be specified.%n", iNumPfields
117 turnoff
118 endif
119
120 ; initial comment
121 fprints gScoName, "%!Generated Gesture from %f to %f seconds%n %!%t%twith a p-max of %d%n%n", p2, p3, iNumPfields
122
123 ; k-rate stuff
124 if (kCurrentTime >= kNextStart) then ; write a new note!
125
126 kndx = (kCurrentTime-p2)/p3
127
128 ; get the required pfield ranges
129 kInstMin tablei kndx, iInstrMinTable
130 kInstMax tablei kndx, iInstrMaxTable
131 kDensMin tablei kndx, iDensityMinTable
132 kDensMax tablei kndx, iDensityMaxTable
133 kDurMin tablei kndx, iDurMinTable
134 kDurMax tablei kndx, iDurMaxTable
135 kAmpMin tablei kndx, iAmpMinTable
136 kAmpMax tablei kndx, iAmpMaxTable
137
138 ; find random values for all our required parameters and print the i-statement
139 fprintks gScoName, "i%d%t%f%t%f%t%f", kInstMin + rnd(kInstMax-kInstMin), kNextStart, kDurMin + rnd(kDurMax-kDurMin), kAmpMin + rnd(kAmpMax-kAmpMin)
140
141 ; now any additional pfields
142 ProcessAdditionalPfields p4, kndx, iNumPfields
143
144 PrintReturn
145
146 ; calculate next starttime
147 kDensity = kDensMin + rnd(kDensMax-kDensMin)
148 if (kDensity < iResolution) then
149 kDensity = iResolution
150 endif
151 kNextStart = kNextStart + kDensity
152 endif
153
154 kCurrentTime = kCurrentTime + iResolution
155 endin
156
157
158 </CsInstruments>
159 <CsScore>
160 /*
161 ===========================================================
162 scogen.sco
163
164 this csound module generates a score file
165 you specify a gesture of notes by giving
166 the "gesture" instrument a number to a
167 (negative) gen2 table.
168
169 this table stores numbers to pairs of functions.
170 each function-pair represents a range (min-max)
171 of randomness for every pfield for the notes to
172 be generated.
173 ===========================================================
174 */
175
176
177 ; common tables for pfield ranges
178 f100 0 2 -7 0 2 0 ; static 0
179 f101 0 2 -7 1 2 1 ; static 1
180 f102 0 2 -7 0 2 1 ; ramp 0->1
181 f103 0 2 -7 1 2 0 ; ramp 1->0
182 f105 0 2 -7 10 2 10 ; static 10
183 f106 0 2 -7 .1 2 .1 ; static .1
184
185 ; specific pfield ranges
186 f10 0 2 -7 .8 2 .01 ; density
187 f11 0 2 -7 8 2 4 ; pitchmin
188 f12 0 2 -7 8 2 12 ; pitchmax
189
190
191 ;=== table containing the function numbers used for all the p-field distributions
192 ;
193 ; p1 - table number
194 ; p2 - time table is instantiated
195 ; p3 - size of table (must be >= p5!)
196 ; p4 - gen# (should be = -2)
197 ; p5 - number of pfields of each note to be generated
198 ; p6 - table number of the function representing the minimum possible note number (p1) of a generated note
199 ; p7 - table number of the function representing the maximum possible note number (p1) of a generated note
200 ; p8 - table number of the function representing the minimum possible noteon-to-noteon time (p2 density) of a generated note
201 ; p9 - table number of the function representing the maximum possible noteon-to-noteon time (p2 density) of a generated note
202 ; p10 - table number of the function representing the minimum possible duration (p3) of a generated note
203 ; p11 - table number of the function representing the maximum possible duration (p3) of a generated note
204 ; p12 - table number of the function representing the maximum possible amplitude (p4) of a generated note
205 ; p13 - table number of the function representing the maximum possible amplitude (p5) of a generated note
206 ; p14,p16.. - table number of the function representing the minimum possible value for additional pfields (p5,p6..) of a generated note
207 ; p15,p17.. - table number of the function representing the maximum possible value for additional pfields (p5,p6..) of a generated note
208
209 ; siz 2 #pds p1min p1max p2min p2max p3min p3max p4min p4max p5min p5max p6min p6max
210 f1 0 32 -2 6 101 101 10 10 101 105 100 106 11 12 100 101
211
212
213 ;gesture definitions
214 ; start dur pTble scale overlap seed
215 i"Gesture" 0 60 1 ;todo-->0 0 123
216 </CsScore>
217
218 </CsoundSynthesizer>
219