1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
; SAMPLEPLAY (2011) for realtime Csound5 - by Arthur B. Hunkins
; Requires MIDI device with up to 25 keys, buttons or pads
; optionally, keys/button/pads velocity sensitive
; optionally, 1 additional key/button/pad and/or 1-4 MIDI knobs or sliders
; 0-1 background loop, 1-25 single-shot samples.
; Files may be mono or stereo; can have different sample rates, may be a variety of
; uncompressed types including WAV and AIFF; also Ogg/Vorbis (with Sugar 0.86/
; Blueberry or later, or Sugar 0.84/Strawberry with updated libsndfile) but not MP3.
; Background loop must be named soundin.0, and samples labeled soundin.1 and up.
; They must be placed in the same folder as this file or they may be loaded
; through the Journal (with Sugar 0.84/Strawberry or later).
<CsoundSynthesizer>
<CsOptions>
-odac -+rtaudio=alsa -+rtmidi=alsa -M hw:1,0 -m0d --expression-opt -b128 -B2048 -+raw_controller_mode=1
</CsOptions>
<CsInstruments>
sr = 44100
; change sample rate to 48000 (or 32000 if necessary) when 44100 gives no audio.
; (Necessary for Intel Classmate PC and some other systems.)
ksmps = 100
nchnls = 2
seed 0
massign 0, 0
ga1 init 0
ga2 init 0
gichan chnexport "Chan", 1
gibackgnd chnexport "Backgnd", 1
gibgmax chnexport "Bgmax", 1
gistctrl chnexport "Stctrl", 1
gistnote chnexport "Stnote", 1
gistfade chnexport "Stfade", 1
gisamps chnexport "Samps", 1
gisampamp chnexport "Sampamp", 1
gisampmax chnexport "Sampmax", 1
gismpctrl chnexport "Smpctrl", 1
gimidi1 chnexport "MIDI1", 1
gireplace chnexport "Replace", 1
gismpfreq chnexport "Smpfreq", 1
gifrqctrl chnexport "Frqctrl", 1
gipanpos chnexport "Panpos", 1
gipanctrl chnexport "Panctrl", 1
gifilter chnexport "Filter", 1
gicutoff chnexport "Cutoff", 1
instr 1
gkfreq init 0
gkpan init .5
kflag init 0
isampmax = gisampmax * .1
if ((gibackgnd == 0) || (kflag == 1)) goto skip
event "i", 2, 0, -1
kflag = 1
skip:
gkstat,gkchan,gkd1,gkd2 midiin
if ((gkstat == 0) || (gkchan != gichan)) goto end
if ((gkstat != 144) && (gkstat != 128)) goto end
if ((gireplace != 2) && ((gkstat == 128) || ((gkstat == 144) && (gkd2 == 0)))) goto end
if ((gkd1 < gimidi1) || (gkd1 > (gimidi1 + (gisamps - 1)))) goto end
ksamp = gkd1 - gimidi1 + 1
kinstr = ksamp + 2
if gisampamp > 0 goto skip2
kamp = 1
goto skip3
skip2:
if gisampamp > 1 goto skip4
kamp random .1, 1
goto skip3
skip4:
if gisampamp > 2 goto skip5
kamp = gkd2 / 127
goto skip3
skip5:
kamp ctrl7 gichan, gismpctrl, 0, 1
skip3:
if gismpfreq == 0 goto skip6
if gismpfreq > 1 goto skip7
gkfreq trirand .05
goto skip6
skip7:
if gismpfreq > 2 goto skip8
gkfreq = ((gkd2 / 64) - 1) * .05
goto skip6
skip8:
gkfreq ctrl7 gichan, gifrqctrl, -.05, .05
skip6:
if gipanpos = 0 goto skip9
if gipanpos > 1 goto skip10
gkpan linrand 1
goto skip9
skip10:
if gipanpos > 2 goto skip11
gkpan = gkd2 / 127
goto skip9
skip11:
gkpan ctrl7 gichan, gipanctrl, 0, 1
skip9:
if gireplace > 0 goto skip12
goto skip13
skip14:
ilen filelen i(ksamp)
rireturn
skip13:
reinit skip14
event "i", kinstr, 0, ilen, kamp * isampmax, gkfreq, gkpan
goto end
skip12:
if (((gkstat == 144) && (gkd2 == 0)) || (gkstat == 128)) goto skip15
event "i", kinstr, 0, -1, kamp * isampmax, gkfreq, gkpan
goto end
skip15:
event "i", -kinstr, 0, 1
end: endin
instr 2
kamp init 0
ibgmax = gibgmax * .1
Sname chnget "file0"
i1 strcmp Sname, "0"
if i1 != 0 goto cont
Sname = "soundin.0"
cont:
ichans filenchnls Sname
if gibackgnd == 2 goto skip
if ((gkstat == 144) && (gkd1 == gistnote) && (gkd2 > 0)) goto skip2
goto skip3
skip2:
kamp = (kamp == 0? ibgmax: 0)
skip3:
kamp2 lineto kamp, gistfade
kamp2 = (kamp2 < .01? 0: kamp2)
goto skip4
skip:
kamp2 ctrl7 gichan, gistctrl, 0, ibgmax
skip4:
if ichans == 2 goto skip5
aout diskin2 Sname, 1, 0, 1
ga1 = aout * kamp2
ga2 = aout * kamp2
goto end
skip5:
a1, a2 diskin2 Sname, 1, 0, 1
ga1 = a1 * kamp2
ga2 = a2 * kamp2
end: endin
instr 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
if p1 != 3 goto cont
Sname chnget "file1"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.1"
goto cont2
cont:
if p1 != 4 goto cont3
Sname chnget "file2"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.2"
goto cont2
cont3:
if p1 != 5 goto cont4
Sname chnget "file3"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.3"
goto cont2
cont4:
if p1 != 6 goto cont5
Sname chnget "file4"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.4"
goto cont2
cont5:
if p1 != 7 goto cont6
Sname chnget "file5"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.5"
goto cont2
cont6:
if p1 != 8 goto cont7
Sname chnget "file6"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.6"
goto cont2
cont7:
if p1 != 9 goto cont8
Sname chnget "file7"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.7"
goto cont2
cont8:
if p1 != 10 goto cont9
Sname chnget "file8"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.8"
goto cont2
cont9:
if p1 != 11 goto cont10
Sname chnget "file9"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.9"
goto cont2
cont10:
if p1 != 12 goto cont11
Sname chnget "file10"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.10"
goto cont2
cont11:
if p1 != 13 goto cont12
Sname chnget "file11"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.11"
goto cont2
cont12:
if p1 != 14 goto cont13
Sname chnget "file12"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.12"
goto cont2
cont13:
if p1 != 15 goto cont14
Sname chnget "file13"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.13"
goto cont2
cont14:
if p1 != 16 goto cont15
Sname chnget "file14"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.14"
goto cont2
cont15:
if p1 != 17 goto cont16
Sname chnget "file15"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.15"
goto cont2
cont16:
if p1 != 18 goto cont17
Sname chnget "file16"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.16"
goto cont2
cont17:
if p1 != 19 goto cont18
Sname chnget "file17"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.17"
goto cont2
cont18:
if p1 != 20 goto cont19
Sname chnget "file18"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.18"
goto cont2
cont19:
if p1 != 21 goto cont20
Sname chnget "file19"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.19"
goto cont2
cont20:
if p1 != 22 goto cont21
Sname chnget "file20"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.20"
goto cont2
cont21:
if p1 != 23 goto cont22
Sname chnget "file21"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.21"
goto cont2
cont22:
if p1 != 24 goto cont23
Sname chnget "file22"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.22"
goto cont2
cont23:
if p1 != 25 goto cont24
Sname chnget "file23"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.23"
goto cont2
cont24:
if p1 != 26 goto cont25
Sname chnget "file24"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.24"
goto cont2
cont25:
Sname chnget "file25"
i1 strcmp Sname, "0"
if i1 != 0 goto cont2
Sname = "soundin.25"
cont2:
ichans filenchnls Sname
ilen filelen Sname
if gireplace == 2 goto skip
kamp linseg 0, .025, p4, ilen - .35, p4, .325, 0
goto skip2
skip:
kamp linsegr 0, .025, p4, ilen - .35, p4, .325, 0
skip2:
if ichans == 2 goto skip3
aout diskin2 Sname, 1 + p5, 0, 0
a1,a2,a3,a4 pan aout, p6, 1, 1, 1
ga1 = ga1 + (a1 * kamp)
ga2 = ga2 + (a2 * kamp)
goto skip4
skip3:
aout,aout2 diskin2 Sname, 1 + p5, 0, 0
a1,a2,a3,a4 pan aout, p6, 1, 1, 1
a5,a6,a7,a8 pan aout2, p6, 1, 1, 1
ga1 = ga1 + ((a1 + a5) * kamp)
ga2 = ga2 + ((a2 + a6) * kamp)
skip4:
ktime timeinsts
if ((gireplace < 2) || (ktime < (ilen - .2))) goto end
turnoff
end: endin
instr 100
if gifilter == 0 goto skip
a1 atonex ga1, gicutoff
a2 atonex ga2, gicutoff
outs a1, a2
goto skip2
skip:
outs ga1, ga2
skip2:
ga1 = 0
ga2 = 0
end: endin
</CsInstruments>
<CsScore>
f1 0 8193 9 .25 1 0
i1 0 3600
i100 0 3600
e
</CsScore>
</CsoundSynthesizer>
|