;Written by Iain McCurdy, 2009

<CsoundSynthesizer>

<CsOptions>
;COMMENT/UNCOMMENT AS REQUIRED
-odevaudio -b400			;NO MIDI
</CsOptions>

<CsInstruments>

sr	=	44100
kr	=	441
ksmps	=	100
nchnls	=	2

;FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FLcolor	255, 255, 255, 0, 0, 0
;		LABEL     | WIDTH | HEIGHT | X | Y
	FLpanel	"wgbrass",   500,    350,    0,  0

;                                                      ON | OFF | TYPE | WIDTH | HEIGHT | X | Y | OPCODE | INS | STARTTIM | IDUR
gkOnOff,ihOnOff	FLbutton	"On/Off",		1,   0,    22,    120,     25,    5,  5,    0,      1,      0,       3600
FLsetColor2	255, 255, 50, ihOnOff		;SET SECONDARY COLOUR TO YELLOW

;VALUE DISPLAY BOXES					WIDTH | HEIGHT | X |  Y
idamp				FLvalue	" ",     	60,       20,    5,   75
idfreq				FLvalue	" ",     	60,       20,    5,  125
idtens				FLvalue	" ",     	60,       20,    5,  175
idatt				FLvalue	" ",     	60,       20,    5,  225
idvibf				FLvalue	" ",     	60,       20,    5,  275
idvamp				FLvalue	" ",     	60,       20,    5,  325

;SLIDERS				            				MIN  |   MAX | EXP | TYPE |  DISP  | WIDTH | HEIGHT | X | Y
gkamp, ihamp			FLslider 	"Amplitude",			0,         1,   0,    23,    idamp,   490,    25,     5,  50
gkfreq, gihfreq			FLslider 	"Frequency",			20,    20000,  -1,    23,   idfreq,   490,    25,     5, 100
gktens, ihtens			FLslider 	"Lip Tension",			0,         1,   0,    23,   idtens,   490,    25,     5, 150
gkatt, ihatt			FLslider 	"Attack Time",			0.0001,    2,  -1,    23,    idatt,   490,    25,     5, 200
gkvibf, ihvibf			FLslider 	"Vibrato Frequency (hertz)",	0,        16,   0,    23,   idvibf,   490,    25,     5, 250
gkvamp, gihvamp			FLslider 	"Vibrato Amplitude",		0,       0.1,   0,    23,   idvamp,   490,    25,     5, 300

			FLsetVal_i	0.18, 	ihamp
			FLsetVal_i	400, 	gihfreq
			FLsetVal_i	0.4, 	ihtens
			FLsetVal_i	0.01, 	ihatt
			FLsetVal_i	5, 	ihvibf
			FLsetVal_i	0.01, 	gihvamp

			FLpanel_end

;INSTRUCTIONS AND INFO PANEL
				FLpanel	" ", 500, 140, 512, 0
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"                           wgbrass                           ", 	1,      5,     14,    490,    20,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,      5,     14,    490,    20,     5,  20
ih		 	FLbox  	"'wgbrass' creates a physical model of a brass instrument.    ", 	1,      5,     14,    490,    20,     5,  40
ih		 	FLbox  	"It seems rather unstable. Experimentation with the settings  ", 	1,      5,     14,    490,    20,     5,  60
ih		 	FLbox  	"for 'Frequency' and 'Lip Tension' are sometimes required in  ", 	1,      5,     14,    490,    20,     5,  80
ih		 	FLbox  	"order to get the instrument to sound.                        ", 	1,      5,     14,    490,    20,     5, 100
ih		 	FLbox  	"Perhaps it will be improved in future releases of Csound.    ", 	1,      5,     14,    490,    20,     5, 120

				FLpanel_end
				FLrun	;RUN THE FLTK WIDGET THREAD
;END OF FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0dbfs	=	1

givfn	ftgen	0, 0, 256, 10, 1	;VIBRATO WAVEFORM (A SINE WAVE)

instr	1	;WGBRASS INSTRUMENT
	if	gkOnOff!=0	kgoto	CONTINUE	;SENSE IF FLTK INSTRUMENT ON/OFF SWITCH IS NOT OFF (IN WHICH CASE SKIP THE NEXT LINE)
		turnoff					;TURN THIS INSTRUMENT OFF IMMEDIATELY
	CONTINUE:					;A LABEL
	iporttime	=	0.03
	kporttime	linseg	0, 0.001, iporttime, 1, iporttime
	kfreq	portk	gkfreq, kporttime
	ktens	portk	gktens, kporttime
	ares	wgbrass gkamp, kfreq, ktens, i(gkatt), gkvibf, gkvamp, givfn
		outs	ares, ares	;SEND AUDIO TO OUTPUTS
endin

</CsInstruments>

<CsScore>
f 0 3600	;DUMMY SCORE EVENT KEEPS REALTIME PERFORMANCE GOING FOR 1 HOUR
</CsScore>

</CsoundSynthesizer>