aboutsummaryrefslogtreecommitdiff
path: root/BUG7/oprepare.udo
blob: b4fdb0592039d717061bfafb3bd3d35f1fef8568 (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
#ifndef UDO_OPREPARE
#define UDO_OPREPARE ##
/*
	Debugger - Unfixed Bugs : BUG #3

	Offline preparation system: record a sound in one k-cycle to a ftable for future use
	To be used where online playback would be too CPU heavy
	In the case of BUG3, it is used for the 909 hi-hat

	Instruments to be prepared should be prepended with src_
*/


/*
	Internal preparation instrument: loop through gSoprepare
	p4	index of gSoprepare to process
	p5	instrument name to schedule when all sounds have been prepared
*/
gSoprepare[] init 1 		; filled by oprepare opcode: input instrument names without src_ prepended
giopreparedfns[] init 1		; filled by oprepare opcode: output ftable numbers corresponding to above
instr _oprepare
	iprepareindex = p4
	SonComplete = p5
	if (iprepareindex >= lenarray(gSoprepare)) then
		event_i "i", SonComplete, 0, 3600
		turnoff
	else 
		Sprepareinstr = gSoprepare[iprepareindex]
		Srcinstr = sprintf("src_%s", Sprepareinstr)
		ilen = 0.8
		p3 = ilen
		ifn ftgen 0, 0, sr*ilen, 7, 0
		giopreparedfns[iprepareindex] = ifn
		ktimek timeinstk
		if (ktimek == 1) then
			kcycles = ilen * kr
			kcount init 0
loop:
			apos phasor (1/(ftlen(ifn)/sr))
			aproc subinstr Srcinstr, 1, 0.1
			tabw aproc, apos, ifn, 1
			loop_lt kcount, 1, kcycles, loop
		elseif (ktimek == 5) then
			scoreline_i sprintf("i\"_oprepare\" 0 1 %d \"%s\"", iprepareindex+1, SonComplete)
			turnoff
		endif
	endif
	
endin


/*
	Start the offline preparation

	oprepare Snames[], SonComplete

	Snames[]	list of instruments to process (instrument name without src_ prepended)
	SonComplete	instrument to be scheduled when preparation process has completed
*/
opcode oprepare, 0, S[]S
	Snames[], SonComplete xin
	gSoprepare = Snames
	giopreparedfns[] init lenarray(Snames)
	scoreline_i sprintf("i\"_oprepare\" 0 1 0 \"%s\"", SonComplete)
endop


/*
	Get the ftable number of a specified instrument name as originally passed to oprepare

	ifn oprepare_getfn Sname

	ifn	the ftable
	Sname	name of offline-prepared instrument
*/
opcode oprepare_getfn, i, S
	Sname xin
	ifn = -1
	index = 0
	while (index < lenarray(gSoprepare)) do
		if (strcmp(gSoprepare[index], Sname) == 0) then
			ifn = giopreparedfns[index]
		endif
		index += 1
	od
complete:
	xout ifn
endop


#end