aboutsummaryrefslogtreecommitdiff
path: root/site/udo/fnml/transition_snare.udo
blob: 16ed2e20b3017961bbbbb99cdc5cfebfebc61dfd (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
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
#ifndef UDO_TRANSITION_SNARE
#define UDO_TRANSITION_SNARE ##

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

gifnmt_rollfndamp[] sounddb_getcollection "Snare.Dampened"
gifnmt_rollfnregular[] sounddb_getcollection "Snare.Regular"
gifnmt_rollfnrimhard[] sounddb_getcollection "Snare.Rim.Hard"
gifnmt_rollfnrimsoft[] sounddb_getcollection "Snare.Rim.Soft"
gifnmt_rollfnunrestrained[] sounddb_getcollection "Snare.Unrestrained"


instr fnmt_rollplay
	istartbeats = p4 ; number of beats before next event as specified in iwaitmode
	iwaitmode = p5 ; -1 = start of next bar, -2 = start of next bargroup , any other = number of total beats before event point
	iampmode = p6 ; 0 = linear, 1 = exponential, 2 = random (randomises each individually)
	idorelease = p7	; do release, 0 or 1
	idotune = p8 ; do tuning, 0 or 1
	idorandom = p9 ; do random sound selection for each click
	Sbus = strget(p10) ; bus to send to ; defaults to "main"
	SonHit = strget(p11) ; instrument to call when hit point is reached

	if (strcmp(Sbus, "") == 0) then
		Sbus = "main"
	endif

	p3 = 600

	if (iwaitmode == -1) then
		kwaittrig = bar_lastbeatxof(istartbeats)
	elseif (iwaitmode == -2) then
		kwaittrig = bargroup_lastbeatxof(istartbeats)
	else
		kwaittrig = lastbeatxof(iwaitmode, istartbeats)
	endif

	if (kwaittrig == 1) then
		schedulek "_fnmt_rollplay1", 0, i(gkseq_beattime) * istartbeats, iampmode, idorelease, idotune, idorandom, Sbus, SonHit
		turnoff
	endif
endin



instr _fnmt_rollplay1
	imode = p4 ; 0 = linear, 1 = exponential, 2 = random (randomises each individually)
	idorelease = p5
	idotune = p6
	idorandom = p7
	Sbus = p8
	SonHit = p9

	ichannelid = uniqueid()
	if (idotune == 1) then  ; TODO: separate channel for tuned ones
		ichannelidtuned = uniqueid()
	endif

	ibeattime = i(gkseq_beattime)
	itempo = i(gkseq_tempo)
	ibeathz = itempo / 60
	ireltime = (idorelease == 1) ? random(ibeattime, ibeattime*4) : 0
	imtime = p3

	if (strcmp(SonHit, "") != 0) then
		schedule(SonHit, imtime, 1)
	endif

	krelease release

	if (imode == 0 || (imode == 2 && random(0, 1) >= 0.5)) then
		kfreq linsegr ibeathz * round(random(4, 16)), imtime, ibeathz * round(random(4, 16)), ireltime, ibeathz * round(random(4, 16))
	else
		kfreq expsegr ibeathz * round(random(4, 16)), imtime, ibeathz * round(random(4, 16)), ireltime, ibeathz * round(random(4, 16))
	endif

	if (imode == 0 || (imode == 2 && random(0, 1) >= 0.5)) then
		kamp linsegr 0, p3, 1, ireltime, 0
	else
		kamp expsegr 0.0001, imtime, 1, ireltime, 0.0001
	endif

	ichancepercent = 100

	kmetro metro kfreq
	ktrig = (kmetro == 1 && random:k(0, 100) < ichancepercent) ? 1: 0
	
	ksampleset = 1
	if (krelease == 1) then
		ksampleset = 0
	endif

	if (ktrig == 1) then
		event "i", "_fnmt_rollitem", 0, 1, ksampleset, kamp, ichannelid
	endif

	aL, aR bus_read sprintf("fnmt_roll%d", ichannelid)

	if (idotune == 1) then
		aL, aR mel_tune_portamento aL, aR, 0, 16
		aL butterhp aL, 120
		aR butterhp aR, 120
	endif

	bus_mix(Sbus, aL, aR)
endin



instr _fnmt_rollitem
	isampleset = p4
	iamp = p5
	ichannelid = p6
	if (isampleset == 0) then
		ifileid = gifnmt_rollfndamp[round(random(0, lenarray(gifnmt_rollfndamp) - 1))]
		
	elseif (isampleset == 1) then
		ifileid = gifnmt_rollfnrimhard[round(random(0, lenarray(gifnmt_rollfnrimhard) - 1))]
		
	endif

	;index = round(random(0, gimaxes[isampleset] - 1))
	;ifn = gisamples[isampleset][index]
	;p3 = (ftlen(ifn) / ftsr(ifn)) + 0.1

	p3 = gisounddb[ifileid][2]
	ifn = gisounddb[ifileid][0]
	if (gisounddb[ifileid][1] == 2) then
		aL, aR loscil iamp, 1, ifn, 1
	else
		aL loscil iamp, 1, ifn, 1
		aR = aL
	endif
	bus_mix(sprintf("fnmt_roll%d", ichannelid), aL, aR)
endin

#end