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
|
#ifndef UDO_FNMI_TIKCLAY
#define UDO_FNMI_TIKCLAY ##
#include "sounddb.udo"
#include "bussing.udo"
#include "wavetables.udo"
#include "uniqueid.udo"
#include "sequencing_melodic.udo"
gitikfn_clay[], gicl_clay sounddb_getcollection "Clay.Hit"
instr _tik_clay_play
instanceid = p4
ifileid = p5
ipitch = p6
iwsize = p7
irandw = p8
ipan = p9
iresonfreq = p10
idoreson = p11
ifn = gisounddb[ifileid][0]
idur = gisounddb[ifileid][2]
istart = idur * random(0, 0.1)
atime linseg istart, p3, idur*0.9
kamp linseg 1, p3*0.8, 1, p3*0.2, 0
aL, aR sndwarpst 1, atime, ipitch, ifn, istart, iwsize, irandw, 2, gifnHalfSine, 1
if (idoreson == 1) then
aLr resony aL, iresonfreq, 6, 16, 10
aRr resony aR, iresonfreq, 6, 16, 10
aL balance aLr, aL
aR balance aRr, aR
endif
ilpf = random(2000, 22050)
aL butterlp aL, ilpf
aR butterlp aR, ilpf
bus_mix(sprintf("tikclayaudio%d", instanceid), aL*ipan*kamp, aR*(1-ipan)*kamp)
endin
instr _tik_clay_item
instanceid = p4
index = p5
kreset init 1
kfreq = chnget:k(sprintf("tikclay_%d_%d", instanceid, index))
if (kfreq == 0) then
if (kreset == 0) then
kreset = 1
endif
kplaying = 0
else
kplaying = 1
endif
if (kreset == 1) then
kfileid = gitikfn_clay[round:k(random:k(0, lenarray:k(gitikfn_clay) - 1))]
kdur = random:k(0.4, 1.3) * gisounddb[kfileid][2]
kpitch = random:k(0.1, 2.2)
kwsize = random:k(44, 441)
krandw = kwsize / 10
kpan = random:k(0, 1)
kresonfreq = cpsmidinn:k(mel_randomnote:k()) * 2
if (random:k(0, 1) >= 0.5) then
kresonfreq *= 2
endif
kreset = 0
endif
if (kplaying == 1) then
kmetro metro kfreq, random(0, 1)
if (kmetro == 1) then
kresonchance = chnget:k(sprintf("tikclay_resonchance_%d", instanceid))
kdoreson = (random:k(0, 0.99999) < kresonchance) ? 1 : 0
schedulek "_tik_clay_play", 0, kdur, instanceid, kfileid, kpitch, kwsize, krandw, kpan, kresonfreq, kdoreson
endif
endif
endin
opcode tik_clay_bank, iaa, i
inum xin
icollection[] = gitikfn_clay
instanceid = uniqueid()
iusedinstruments[] uniqueinstrnums "_tik_clay_item", inum
index = 0
ifileindex = 0
while (index < lenarray(iusedinstruments)) do
ifileid = icollection[ifileindex]
schedule iusedinstruments[index], 0, p3, instanceid, index
if (ifileindex + 1 < lenarray(icollection)) then
ifileindex += 1
else
ifileindex = 0
endif
index += 1
od
if (release:k() == 1) then
kindex = 0
while (kindex < lenarray(iusedinstruments)) do
turnoff2 iusedinstruments[kindex], 4, 1
kindex += 1
od
endif
aL, aR bus_read sprintf("tikclayaudio%d", instanceid)
xout instanceid, aL, aR
endop
#end
|