;WRITTEN BY IAIN MCCURDY, 2010

<CsoundSynthesizer>

<CsOptions>
-odevaudio -b2048 -B4096
</CsOptions>

<CsInstruments>

sr	= 	44100
ksmps	= 	128
nchnls	= 	2
0dbfs	=	1

FLcolor	0,100,0, 0,100,255

;				LABEL          | WIDTH | HEIGHT | X | Y
	FLpanel	"Position Sensitive FLbutton",    600,    400,   10, 10

;SWITCHES                               ON | OFF | TYPE | WIDTH | HEIGHT | X | Y  | OPCODE | INS | STARTTIM | IDUR
gkTrigNote, ihTrigNote	FLbutton 	"",	1,    0,    21,    500,    300,   50,  50,    0,      2,      0,       0.01

FLpanel_end
FLcolor	255, 255, 255, 0, 0, 0
;INSTRUCTIONS AND INFO PANEL
				FLpanel	" ", 500, 220, 30, 480
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"     FLxyin used to create a position sensitive button       ", 	1,      5,     14,    490,    15,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,      5,     14,    490,    15,     5,  20
ih		 	FLbox  	"By combining a FLxyin position sensitive area with an        ", 	1,      5,     14,    490,    15,     5,  40
ih		 	FLbox  	"FLbutton a button with position sensitivity can be created.  ", 	1,      5,     14,    490,    15,     5,  60
ih		 	FLbox  	"In this example clicking nthe button triggers a note but     ", 	1,      5,     14,    490,    15,     5,  80
ih		 	FLbox  	"position along its x axis controls the note duration and     ", 	1,      5,     14,    490,    15,     5, 100
ih		 	FLbox  	"position along its y axis controls the starting cutoff       ", 	1,      5,     14,    490,    15,     5, 120
ih		 	FLbox  	"frequency of the filter envelope.                            ", 	1,      5,     14,    490,    15,     5, 140
ih		 	FLbox  	"In order for this example to work it is important that the   ", 	1,      5,     14,    490,    15,     5, 160
ih		 	FLbox  	"dimensions of the FLbutton correspond to the dimensions of   ", 	1,      5,     14,    490,    15,     5, 180
ih		 	FLbox  	"the FLxyin panel.                                            ", 	1,      5,     14,    490,    15,     5, 200

				FLpanel_end

FLrun

gisine	ftgen	0,0,65536,10,1

instr	1	;ALWAYS ON INSTRUMENT - SCANS X-Y LOCATION OF MOUSE OVER FLTK BUTTON
	;KOUTX, KOUTY, KINSIDE    FLXYIN IOUTX_MIN, IOUTX_MAX, IOUTY_MIN, IOUTY_MAX, IWINDX_MIN, IWINDX_MAX, IWINDY_MIN, IWINDY_MAX [, IEXPX, IEXPY, IOUTX, IOUTY] 
	gkoutx, gkouty,  kinside  FLxyin    0.1,         7,        0,         1,        50,         550,         50,         350,        -1,     0
endin

instr	2	;SOUND GENERATING INSTRUMENT. TRIGGERED FROM FLTK BUTTON
	p3	=	i(gkoutx)	
	aenv	expseg	1,p3,0.001
	a1	vco	aenv, 200, 1, 0.5, gisine
	kcf	expon	(12000*i(gkouty))+50,p3,50 
	a1	moogladder	a1, kcf, 0.8
	outs	a1,a1
endin

</CsInstruments>

<CsScore>
i 1 0 3600	;INSTRUMENT 1 (ALWAYS ON) SENSES XY POSITION OF THE MOUSE
</CsScore>

</CsoundSynthesizer>

