<CsoundSynthesizer>
<CsVersion>
	5.06
</CsVersion>
/*
	Soundfile Playback instrument
	by David Akbari, February 2008	
*/
<CsInstruments>

sr	=	44100
ksmps	=	100
nchnls	=	2

gkndx	init	0

/*===	===*/

	FLcolor	195, 195, 195
	FLpanel	"sound file playback", 210, 65, 240, 240
	FLcolor	-1

	FLcolor	209, 209, 209
	FLcolor2 237, 237, 237
gkstop, gistop	FLbutton "@square", 1, 1, 1, 40, 40, 5, 5, 0, 55, 0, -1
gkplay, giplay	FLbutton "@>", 1, 1, 1, 40, 40, 50, 5, 0, 44, 0, -1
	FLcolor	-1
	FLcolor2 -1

	FLcolor	222, 222, 202
giseconds	FLvalue "", 60, 25, 100, 5
	FLcolor	-1

	FLcolor		194, 99, 79
gkexit, giexit	FLbutton "x", 1, 1, 1, 25, 25, 180, 5, 0, 66, 0, 0.1
	FLcolor	-1

	FLcolor 209, 209, 209
	FLcolor2	85, 85, 85
gkmeter, gimeter FLbutton "time", 1, 0, 2, 45, 15, 100, 33, 0, 45, 0, -1
gkpos, gipos FLbutton "pos", 1, 0, 2, 45, 15, 160, 33, 0, 46, 0, -1
	FLcolor	-1
	FLcolor2 -1

	FLcolor	0,101, 190
	FLcolor2	133, 191, 239
gkpos, gipos	FLslider	"", 0, 1, 0, 1, -1, 200, 8, 5, 50
	FLcolor	-1
	FLcolor2	-1

;	FLsetVal_i
	FLpanel_end

/*
	FLpanel	"strip", 45, 150, 512, 250

	FLcolor		0, 255, 0
	FLcolor2	0, 0, 0
gklvol, gilvol	FLslider	"L", -32768, 0, 0, 2, -1, 15, 130, 5, 5
gkrvol, girvol	FLslider	"R", -32768, 0, 0, 2, -1, 15, 130, 25, 5
	FLcolor		-1
	FLcolor2	-1

	FLpanel_end
*/
  FLrun

/*===	===*/
/*---	

		instr 1
kon	trigger	gkplay, 1, 1
	schedkwhen	kon, -1, -1, 44, 0, -1
printk2	kon
		endin


		instr 2
kon	trigger	gkstop, 1, 1
	schedkwhen	kon, -1, -1, 55, 0, -1
	printk2	kon
		endin

---*/


		instr 44

ilen	filelen	"$FILE"
gilen	init	ilen
ichnls	filenchnls	"$FILE"
kndx	phasor	1/(ilen)
ksamps	=	ilen
kndx	=	kndx * ilen
gkndx	=	kndx

;	FLprintk2	kndx, giseconds

	if	(ichnls == 1) then
al	diskin2	"$FILE", 1, 0, 1
ar	=	al
elseif	(ichnls == 2) then
al, ar	diskin2	"$FILE", 1, 0, 1
elseif (ichnls > 2) then
	printks	"\nGreater than 2 channels not currently supported.\n\n", 0
	endif

krmsl	rms	al
krmsr	rms	ar

	outs	al, ar
;	FLsetVal	1, -krmsl, gilvol
;	FLsetVal	1, -krmsr, girvol

		endin

/*---	---*/

		instr 45
	if	(gkmeter == 1) then
	FLprintk2	gkndx, giseconds
else
	endif
		endin

/*---	---*/

		instr 46
	if (gkpos == 0) then
	turnoff
else
	FLsetVal	gkndx, gkndx/gilen, gipos
	endif
		endin

/*---	---*/

		instr	55
	turnoff2	44, 0, 0
	turnoff
		endin

/*---	---*/

		instr	66
	turnoff2	44, 0, 0
	exitnow
		endin

/*---	---*/
</CsInstruments>
<CsScore>
f0	8888

e
</CsScore>
</CsoundSynthesizer>