aboutsummaryrefslogtreecommitdiff
path: root/BUG9/BUG9.csd
blob: f32092178c3f72ce9e4975b4e51aacc49d02650a (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
141
142
143
144
145
<CsoundSynthesizer>
<CsOptions>
-odac
-m0
</CsOptions>
<CsInstruments>
/*
	Debugger - Unfixed Bugs : BUG #8
	
	http://git.1bpm.net/csd-unfixedbugs1/about/

	By Richard Knight 2021
		http://1bpm.net
		q@1bpm.net

*/

sr = 44100
ksmps = 100
nchnls = 2
0dbfs = 1
seed 0

#define NOFILEIO ## 		; file IO with readfi not supported on all platforms: disables bid_loadfile

gkmastergain init 1		; master gain
gkpump = 0			; kick ducking control
gksection init -1

#include "wavetables.udo"	; general waveforms
#include "bussing.udo"		; global audio bussing
#include "bid.udo"		; Bug Infested Directive tools and parsing
#include "instruments.udo"	; sound generators
#include "txt_tools.udo"	; text tools


/*
	Master audio output
*/
instr global_master
	igain = 1
	aL, aR bus_read "master"	
	aL limit aL*0.5, -1, 1
	aR limit aR*0.5, -1, 1
	outs aL*gkmastergain*igain, aR*gkmastergain*igain
endin


/*
	Print notification of performance time since last notification
		or if isection is -1, print completion notification
*/
gitimetrack times
instr notify_change
	isection = p4
	itime times
	if (isection == -1) then
		tt_notify(sprintf"Complete, runtime: %s", tt_parsetime(itime)))
		exitnow
	else
		isectiontime = itime - gitimetrack
		tt_notify(sprintf("%s : section %d complete in %s", tt_parsetime(itime), isection, tt_parsetime(isectiontime)))
		gitimetrack = itime
	endif
	turnoff
endin


/*
	Parse BID file and run the sequencer
*/
instr parseandrun
	tt_notify("Parsing events")

	#include "bid_source.udo"
	bid_loadtext(SBID)

	tt_notify("Running sequencer")
	event_i "i", "sequencer", 0, 3600
	turnoff
endin



/*
	Sequence BID elements
*/
instr sequencer
	isection = 1
	event_i "i", "bid_setcurrentchord", 0, 1, isection, 0
	event_i "i", "global_master", 0, p3
	kmetro metro (gibid_tempo / 60) * 4
	kpos init 0
	kposabs init 0
	ksection init isection
	kposchord init 0
	gksection = ksection
	if (kmetro == 1) then
		if (ksection > gibid_maxsection) then
			event "i", "notify_change", p3, 1, -1
			turnoff
		endif

		; sequence BID elements
		bid_seq "kick", kpos, ksection
		bid_seq "clap", kpos, ksection
		bid_seq "hat1", kpos, ksection
		bid_seq "hat2", kpos, ksection
		bid_seq "bass", kpos, ksection
		bid_seq "mel1", kpos, ksection
		bid_seq "mel2", kpos, ksection

		kpos = (kpos < 31) ? kpos + 1 : 0
		ksection16ths = bid_getsectionlength(ksection) * 4

		if (kposabs+1 < ksection16ths) then
			kposabs += 1
		else
			event "i", "notify_change", 0, 1, ksection
			;event "i", "play_crash", 0, gibid_beattime
			ksection += 1
			kposchord = 0
			kpos = 0
			kposabs = 0
			event "i", "bid_setcurrentchord", 0, 1, ksection, 1
		endif
		
		
		if (kposchord+1 < gkbid_chordlength*4) then
			kposchord += 1
		else
			kposchord = 0
			event "i", "bid_setcurrentchord", 0, 1, ksection, 1
		endif
		

	endif

endin

</CsInstruments>
<CsScore>
i"parseandrun" 0 1
</CsScore>
</CsoundSynthesizer>