<Cabbage>
form caption("FluidSequencer"), size(300, 200)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0d
</CsOptions>
<CsInstruments>
sr 	= 	44100 
ksmps 	= 	32
nchnls 	= 	2
0dbfs	=	1 

gienginenum1	fluidEngine
isfnum1	fluidLoad "sf_GMbank.sf2", gienginenum1, 1
		fluidProgramSelect	gienginenum1, 1, isfnum1, 0, 10

instr ROW_SEQUENCER
	kNotesAmps[] fillarray 0, 0, 0, 0, 0, 0, 0, 0

	;each Row will take one of these notes and use it when a beat is enabled
	kNoteValues[] fillarray 60, 62, 64, 65, 67, 69, 70, 72

	;run through note amps array and trigger note if amp is set to 1/on
	kBeat init 0
	kTempo chnget "tempo"
	if metro(kTempo) == 1 then
		if kNotesAmps[kBeat] == 1 then
			;event "i", "SYNTH", 0, 3, kNoteValues[p4-1]
			event "i", "Fluid", 0, 3, kNoteValues[p4-1],127
		endif
		chnset kBeat, "beat"
		kBeat = (kBeat<7 ? kBeat+1 : 0)
		
	endif

	;get row number and create unique channel name
	SRowCubeIndex sprintf "rowCubeIndex%d", p4
	SRowCubeState sprintf "rowCubeState%d", p4
	kCubeIndex chnget SRowCubeIndex
	kCubeState chnget SRowCubeState

	;if user has enabled a note, update note amp array
	kChanged changed kCubeState, kCubeIndex
	if changed(kChanged) == 1 then
		kNotesAmps[kCubeIndex] = kCubeState;
		printks "Updating row %d - index: %d - value %d", 0, p4, kCubeIndex, kNotesAmps[kCubeIndex]
	endif

endin

instr SYNTH
	a1 expon .1, .25, 0.001
	aOut oscili a1, cpsmidinn(p4)
	outs aOut, aOut
endin

instr Fluid ; GM soundfont
	ichannel   = 1
	ikey       = p4
	ivelocity  = p5
	fluidNote gienginenum1, ichannel, ikey, ivelocity
endin

instr FluidVol ; Fluidsynth output
	iamplitude1 = 7
	aleft1, aright1 fluidOut   gienginenum1
	outs aleft1 * iamplitude1, aright1 * iamplitude1
endin


</CsInstruments>
<CsScore>
f100 0 8 2 0 10 0 0 8 0 0 0
i"ROW_SEQUENCER" 0 [3600*12] 1
i"ROW_SEQUENCER" 0 [3600*12] 2
i"ROW_SEQUENCER" 0 [3600*12] 3
i"ROW_SEQUENCER" 0 [3600*12] 4
i"ROW_SEQUENCER" 0 [3600*12] 5
i"ROW_SEQUENCER" 0 [3600*12] 6
i"ROW_SEQUENCER" 0 [3600*12] 7
i"ROW_SEQUENCER" 0 [3600*12] 8
i"FluidVol" 0 z
</CsScore>
</CsoundSynthesizer>