;Writen by Iain McCurdy, 2006

<CsoundSynthesizer>

<CsOptions>
-odevaudio --midi-device=0 -b400 
</CsOptions>    

<CsInstruments>

sr 		= 	44100	;SAMPLE RATE
ksmps 		= 	100	;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
nchnls 		= 	2	;NUMBER OF CHANNELS (2=STEREO)
0dbfs		=	1	;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH

;FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FLcolor	255, 255, 255, 0, 0, 0
;INSTRUCTIONS AND INFO PANEL                 WIDTH | HEIGHT | X | Y
				FLpanel	" ", 515,      640,   0,  0
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"   Activating an Instrument Through Realtime MIDI Control    ", 	1,      5,     14,    490,    20,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,      5,     14,    490,    20,     5,  20
ih		 	FLbox  	"Basic activation of csound instruments through the use of a  ", 	1,      5,     14,    490,    20,     5,  40
ih		 	FLbox  	"connected MIDI keyboard is transparent to the user. The only ", 	1,      5,     14,    490,    20,     5,  60
ih		 	FLbox  	"requirement is that a Csound flag for live MIDI input is     ", 	1,      5,     14,    490,    20,     5,  80
ih		 	FLbox  	"given so that Csound knows to expect MIDI information.       ", 	1,      5,     14,    490,    20,     5, 100
ih		 	FLbox  	"In the code of this example '--midi-device=0' ('-M0' would be", 	1,      5,     14,    490,    20,     5, 120
ih		 	FLbox  	"a less verbose equilvalent) is included in the <CsOptions>   ", 	1,      5,     14,    490,    20,     5, 140
ih		 	FLbox  	"of the section csd to activate realtime MIDI. The number     ", 	1,      5,     14,    490,    20,     5, 160
ih		 	FLbox  	"after the flag selects which of your computer's MIDI input   ", 	1,      5,     14,    490,    20,     5, 180
ih		 	FLbox  	"devices to use. If your computer has only one MIDI input     ", 	1,      5,     14,    490,    20,     5, 200
ih		 	FLbox  	"device then a zero (as I have used here) will select it. If  ", 	1,      5,     14,    490,    20,     5, 220
ih		 	FLbox  	"your computer has more than one MIDI input device installed  ", 	1,      5,     14,    490,    20,     5, 240
ih		 	FLbox  	"(including virtual devices such as MIDI yoke) then you may   ", 	1,      5,     14,    490,    20,     5, 260
ih		 	FLbox  	"need to give some other value here. If you are not sure what ", 	1,      5,     14,    490,    20,     5, 280
ih		 	FLbox  	"MIDI input devices your computer has you can overestimate the", 	1,      5,     14,    490,    20,     5, 300
ih		 	FLbox  	"value given here (e.g. '-M99') in which case an error will be", 	1,      5,     14,    490,    20,     5, 320
ih		 	FLbox  	"produced and the Csound terminal window will print a list of ", 	1,      5,     14,    490,    20,     5, 340
ih		 	FLbox  	"legal MIDI input devices and their related numbers.          ", 	1,      5,     14,    490,    20,     5, 360
ih		 	FLbox  	"This example is very basic and merely produces a beep each   ", 	1,      5,     14,    490,    20,     5, 380
ih		 	FLbox  	"time a note is played on your MIDI keyboard. Note duration   ", 	1,      5,     14,    490,    20,     5, 400
ih		 	FLbox  	"corresponds with how long you hold the note for. Csound      ", 	1,      5,     14,    490,    20,     5, 420
ih		 	FLbox  	"regards MIDI notes as held notes so there is no point in     ", 	1,      5,     14,    490,    20,     5, 440
ih		 	FLbox  	"trying to use 'p3' in, for example envelopes, in the         ", 	1,      5,     14,    490,    20,     5, 460
ih		 	FLbox  	"instrument code for a MIDI activated instrument. Polyphony is", 	1,      5,     14,    490,    20,     5, 480
ih		 	FLbox  	"possible although it is rather difficult to hear in this     ", 	1,      5,     14,    490,    20,     5, 500
ih		 	FLbox  	"example as all beeps are the same pitch.                     ", 	1,      5,     14,    490,    20,     5, 520
ih		 	FLbox  	"If an orchestra contains more that one instrument, MIDI notes", 	1,      5,     14,    490,    20,     5, 540
ih		 	FLbox  	"on MIDI channel 1 will be directed to instrument 1, channel 2", 	1,      5,     14,    490,    20,     5, 560
ih		 	FLbox  	"will be directed to instrument 2 and so on. Modification to  ", 	1,      5,     14,    490,    20,     5, 580
ih		 	FLbox  	"this default arrangement is possible using the 'massign'     ", 	1,      5,     14,    490,    20,     5, 600
ih		 	FLbox  	"opcode.                                                      ", 	1,      5,     14,    490,    20,     5, 620
				FLpanel_end
				FLrun	;RUN THE FLTK WIDGET THREAD
;END OF FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

instr	1	; SIMPLE BEEP INSTRUMENT - CAN BE ACTIVATED VIA A CONNECTED MIDI KEYBOARD
	;OUTPUT	OPCODE	AMPLITUDE | FREQUENCY | FUNCTION_TABLE
	asig	oscili	0.2,           440,         1
		outs	asig, asig	;SEND AUDIO OUTPUT OF OSCILLATOR TO THE SPEAKERS
endin

</CsInstruments>

<CsScore>
f 1 0 1024 10 1	; SINE WAVE
f 0 600	; THIS LINE FUNCTIONS AS A DUMMY SCORE EVENT AND ALLOWS REALTIME MIDI PLAYING FOR 10 MINUTES
</CsScore>

</CsoundSynthesizer>