aboutsummaryrefslogtreecommitdiff
path: root/site/udo/fnml/instrument_tikbank.udo
blob: 895c8b0748ed366e371c27f1ef2314660ae5132b (plain)
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
#ifndef UDO_FNMI_TIKBANK
#define UDO_FNMI_TIKBANK ##



#include "sounddb.udo"
#include "bussing.udo"
#include "uniqueid.udo"


instr _tik_play
	ifn = p4
	ipitch = p5
	ipan = p6
	instanceid = p7

	aL, aR loscil 0.4, ipitch, ifn, 1
	bus_mix(sprintf("tikaudio%d", instanceid), aL*ipan, aR*(1-ipan))
endin


instr _tik_item
	ifn = p4
	idur = p5
	ipitch = p6
	instanceid = p7
	index = p8

	kfreq chnget sprintf("tikitemfreq_%d_%d", instanceid, index)
	ipan = random(0, 1)

	if (kfreq != 0) then
		kmetro metro kfreq*2, random(0, 1)
		if (kmetro == 1) then
			schedulek "_tik_play", 0, idur, ifn, ipitch, ipan, instanceid
		endif
	endif
endin


opcode tik_bank, iaa, i[]ipj
	icollection[], inum, ipitch, instanceid xin
	
	if (instanceid == -1) then
		instanceid = uniqueid()
	endif

	iusedinstruments[] uniqueinstrnums "_tik_item", inum

	index = 0
	ifileindex = 0
	while (index < lenarray(iusedinstruments)) do
		idbindex = icollection[ifileindex]
		ifn = gisounddb[idbindex][0]
		idur = gisounddb[idbindex][2] / ipitch

		schedule iusedinstruments[index], 0, p3, ifn, idur, ipitch, 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("tikaudio%d", instanceid)
	xout instanceid, aL, aR
endop

#end