;Written by Iain McCurdy, 2009

<CsoundSynthesizer>

<CsOptions>
-odevaudio -b400
</CsOptions>

<CsInstruments>

;DEMONSTRATION OF THE FLcount OPCODE
;CLICKING ON THE SINGLE ARROW BUTTONS INCREMENTS THE OSCILLATOR IN SEMITONE STEPS
;CLICKING ON THE DOUBLE ARROW BUTTONS INCREMENTS THE OSCILLATOR IN OCTAVE STEPS

sr		=	44100
kr		=	4410
ksmps		=	10
nchnls		=	2
0dbfs		=	1	;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH

;		OPCODE	LABEL       | WIDTH | HEIGHT | X | Y
		FLpanel	"Counter",     500,     400,  50,  50

imin		=	5	;MINIMUM VALUE OUTPUT BY COUNTER
imax		=	12	;MAXIMUM VALUE OUTPUT BY COUNTER
istep1		=	.01	;SINGLE ARROW STEP SIZE (SEMITONES)
istep2		=	1	;DOUBLE ARROW STEP SIZE (OCTAVE)
itype		=	1	;COUNTER TYPE (1=DOUBLE ARROW COUNTER)
iwidth		=	200	;WIDTH OF THE COUNTER IN PIXELS
iheight		=	30	;HEIGHT OF THE COUNTER IN PIXELS
ix		=	33	;DISTANCE OF THE LEFT EDGE OF THE COUNTER FROM THE LEFT EDGE OF THE PANEL
iy		=	50	;DISTANCE OF THE TOP EDGE OF THE COUNTER FROM THE TOP EDGE OF THE PANEL
iopcode		=	-1	;SCORE EVENT TYPE (-1=IGNORED)
gkpch,ihandle1 	FLcount  "pitch in pch format", imin, imax, istep1, istep2, itype, iwidth, iheight, ix, iy, iopcode
gkamp,ihandle2 	FLcount  "On/Off", 		0,       1,      1,      1,     2, iwidth, iheight, 266,iy, iopcode
;SET INITIAL VALUES OF VALUATOR
		FLsetVal_i	7, ihandle1
		FLsetVal_i	0, ihandle2

FLcolor	255,255,255
;TEXT BOXES							TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 FLbox  	"Type 1 counter has two sets", 	1,      5,     14,    220,    20,    23, 100
ih		 FLbox  	"of arrow buttons for       ", 	1,      5,     14,    220,    20,    23, 120
ih		 FLbox  	"incrementing its output in ", 	1,      5,     14,    220,    20,    23, 140
ih		 FLbox  	"two step sizes.            ", 	1,      5,     14,    220,    20,    23, 160
ih		 FLbox  	"In this example step 1     ", 	1,      5,     14,    220,    20,    23, 180
ih		 FLbox  	"(inner arrows) step size is", 	1,      5,     14,    220,    20,    23, 200
ih		 FLbox  	"0.01 and step size 2 (outer", 	1,      5,     14,    220,    20,    23, 220
ih		 FLbox  	"arrows) is 1.              ", 	1,      5,     14,    220,    20,    23, 240
ih		 FLbox  	"In this case therefore the ", 	1,      5,     14,    220,    20,    23, 260
ih		 FLbox  	"inner arrows shift the     ", 	1,      5,     14,    220,    20,    23, 280
ih		 FLbox  	"pitch of an oscillator in  ", 	1,      5,     14,    220,    20,    23, 300
ih		 FLbox  	"semitone steps and the     ", 	1,      5,     14,    220,    20,    23, 320
ih		 FLbox  	"outer arrows shift its     ", 	1,      5,     14,    220,    20,    23, 340
ih		 FLbox  	"pitch in octave steps.     ", 	1,      5,     14,    220,    20,    23, 360

ih		 FLbox  	"Type 2 counter has just a  ", 	1,      5,     14,    220,    20,   255, 100
ih		 FLbox  	"single set of arrow buttons", 	1,      5,     14,    220,    20,   255, 120
ih		 FLbox  	"in this case only two      ", 	1,      5,     14,    220,    20,   255, 140
ih		 FLbox  	"values have been allowed: 1", 	1,      5,     14,    220,    20,   255, 160
ih		 FLbox  	"or zero which will turn the", 	1,      5,     14,    220,    20,   255, 180
ih		 FLbox  	"oscillator on or off.      ", 	1,      5,     14,    220,    20,   255, 200

		FLpanel_end	;END OF PANEL CONTENTS
		FLrun		;RUN THE WIDGET THREAD

gisine	ftgen 0, 0, 65536, 10, 1		;FUNCTION TABLE THAT DEFINES A SINGLE CYCLE OF A SINE WAVE

instr 	1
	kcps		=	cpspch(gkpch)
	kcps		port	kcps, 0.005	;SMOOTH SLIDER VARIABLE
	kamp		port	gkamp, 0.005	;SMOOTH SLIDER VARIABLE
	acps		interp	kcps		;INTERPOLATE AND CREATE AN AUDIO RATE VERSION OF K-RATE VARIABLE
	aamp		interp	kamp		;INTERPOLATE AND CREATE AN AUDIO RATE VERSION OF K-RATE VARIABLE
	;OUTPUT		OPCODE	AMPLITUDE |  FREQUENCY   | FUNCTION_TABLE
	asig		oscil	0.1*aamp,       acps,         gisine	;cpsoct() CONVERTS A pch FORMAT PITCH EXPRESSION TO A cps FORMAT PITCH EXPRESSION
		outs	asig, asig	;SEND AUDIO TO OUTPUTS
endin
		
</CsInstruments>

<CsScore>
i 1 0 3600		;INSTRUMENT 1 WILL PLAY A NOTE FOR 1 HOUR
</CsScore>

</CsoundSynthesizer>