;WRITTEN BY IAIN MCCURDY, 2008

<CsoundSynthesizer>

<CsOptions>
-odevaudio -b1000
</CsOptions>

<CsInstruments>

sr	= 	44100
kr	=	4410
ksmps	= 	10
nchnls	= 	2

FLcolor2	237, 135, 139


		FLpanel	"Snapshots",  500, 220, 0, 0

;			OPCODE 		TYPE | NUMX | NUMY | WIDTH | HEIGHT | X | Y | IOPCODE | P1 | P2 | P3
gksnap, ihsnap		FLbutBank	11,     8,      1,   200,     25,    75,  25,    0,      3,   0,   0
;                                                	ON | OFF | TYPE | WIDTH | HEIGHT | X | Y  | OPCODE | INS | STARTTIM | IDUR
gkSSmode, gihstore 	FLbutton 	"Store",	1,    1,    11,    50,     25,    25,  25,    0,      1,      0,       0
gkSSmode, gihrecall 	FLbutton 	"Recall",	0,    0,    11,    50,     25,    25,  25,    0,      2,      0,       0
gkSSmode		init	1
			FLsetColor	255, 0, 0, gihstore	;RED
			FLsetColor	0,  255, 0, gihrecall	;GREEN

FLcolor	255, 255, 255, 0, 0, 0
;SLIDERS
;THESE THREE SLIDER WILL BE USED TO SET THE FREQUENCIES OF THREE OSCILLATORS
;					            		MIN | MAX | EXP | TYPE | DISP | WIDTH | HEIGHT | X | Y
gkcps1,ihcps1		FLslider 	"Frequency Slider 1",	100,  8000, -1,    5,     -1,    275,    30,     10, 60
gkcps2,ihcps2		FLslider 	"Frequency Slider 2",	100,  8000, -1,    5,     -1,    275,    30,     10, 110
gkcps3,ihcps3		FLslider 	"Frequency Slider 3",	100,  8000, -1,    5,     -1,    275,    30,     10, 160

		FLpanel_end

;INSTRUCTIONS AND INFO PANEL
				FLpanel	" ", 500, 540, 512, 0
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"                           Snapshots                         ", 	1,      5,     14,    490,    15,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,      5,     14,    490,    15,     5,  20
ih		 	FLbox  	"This example demonstrates how to create snapshots of all FLTK", 	1,      5,     14,    490,    15,     5,  40
ih		 	FLbox  	"valuators in a patch.                                        ", 	1,      5,     14,    490,    15,     5,  60
ih		 	FLbox  	"The opcodes that are used to work with snapshots save and    ", 	1,      5,     14,    490,    15,     5,  80
ih		 	FLbox  	"load snapshots are FLsetsnap, FLsavesnap, FLloadsnap and     ", 	1,      5,     14,    490,    15,     5, 100
ih		 	FLbox  	"FLgetsnap.                                                   ", 	1,      5,     14,    490,    15,     5, 120
ih		 	FLbox  	"To create a tidier interface an FLTK button whose function   ", 	1,      5,     14,    490,    15,     5, 140
ih		 	FLbox  	"toggles between 'store' and 'recall' is implemented. Actually", 	1,      5,     14,    490,    15,     5, 160
ih		 	FLbox  	"two buttons are created which are laid one on top of the     ", 	1,      5,     14,    490,    15,     5, 180
ih		 	FLbox  	"other which are then alternately shown and hidden using the  ", 	1,      5,     14,    490,    15,     5, 200
ih		 	FLbox  	"opcodes FLshow and FLhide as the switches are toggled        ", 	1,      5,     14,    490,    15,     5, 220
ih	  	 	FLbox  	"between.                                                     ", 	1,      5,     14,    490,    15,     5, 240
ih		 	FLbox  	"If 'store' is currently selected, clicking on the numbered   ", 	1,      5,     14,    490,    15,     5, 260
ih		 	FLbox  	"buttons stores all valuators current values to a snapshot    ", 	1,      5,     14,    490,    15,     5, 280
ih		 	FLbox  	"file. Each time a new numbered button is pressed, a new      ", 	1,      5,     14,    490,    15,     5, 300
ih		 	FLbox  	"snapshot file is created. Your current working directory will", 	1,      5,     14,    490,    15,     5, 320
ih		 	FLbox  	"quickly fill up with snapshot files so you may consider      ", 	1,      5,     14,    490,    15,     5, 340
ih		 	FLbox  	"setting up a folder specifically for snapshots.              ", 	1,      5,     14,    490,    15,     5, 360
ih		 	FLbox  	"Currently the facility to save and recall snapshots from     ", 	1,      5,     14,    490,    15,     5, 380
ih		 	FLbox  	"within a bank of snapshots using FLsetsnap and FLgetsnap does", 	1,      5,     14,    490,    15,     5, 400
ih		 	FLbox  	"not work. What this example does as a workaround is to save  ", 	1,      5,     14,    490,    15,     5, 420
ih		 	FLbox  	"(or recall) a unique snapshot bank with only one snapshot    ", 	1,      5,     14,    490,    15,     5, 440
ih		 	FLbox  	"each time one of the numbered buttons is pressed.            ", 	1,      5,     14,    490,    15,     5, 460
ih		 	FLbox  	"There exists the facility to only store specified valuators  ", 	1,      5,     14,    490,    15,     5, 460
ih		 	FLbox  	"within the snapshot - currently this function does not appear", 	1,      5,     14,    490,    15,     5, 460
ih		 	FLbox  	"to work.                                                     ", 	1,      5,     14,    490,    15,     5, 480
ih		 	FLbox  	"Be aware that If you add additional valuators to your patch  ", 	1,      5,     14,    490,    15,     5, 500
ih		 	FLbox  	"your old snapshots will no longer work.                      ", 	1,      5,     14,    490,    15,     5, 520


				FLpanel_end

		
		FLrun

gisine	ftgen	0, 0, 65536, 10, 1

instr	1	;TOGGLE TO RECALL
	FLhide		gihstore	;HIDE 'STORE' BUTTON
	FLshow		gihrecall	;SHOW 'RECALL' BUTTON
endin
                	
instr	2	;TOGGLE TO STORE
	FLhide		gihrecall	;HIDE 'RECALL' BUTTON	
	FLshow		gihstore	;SHOW 'STORE' BUTTON
endin

instr	3	;TEST WHETHER TO STORE OR RECALL
	if			i(gkSSmode)==0	then	;IF CURRENTLY IN 'STORE' MODE...
		event_i	"i", 4, 0, 0		;CREATE A NOTE EVENT FOR INSTR 4
	endif
	if			i(gkSSmode)==1	then	;IF CURRENTLY IN 'RECALL' MODE...
		event_i	"i", 5, 0, 0		;CREATE A NOTE EVENT FOR INSTR 5
	endif
endin

instr	4	;STORE SNAPSHOT
	Sfile 	sprintf 	"snapshot%d.snap", i(gksnap)	;DEFINE STRING VARIABLE Sfile
	inumsnap, inumval	FLsetsnap 	0
	FLsavesnap 	Sfile
endin

instr 	5 	;RECALL SNAPSHOT
	Sfile	sprintf 	"snapshot%d.snap", i(gksnap)
	FLloadsnap 	Sfile
	inumload 	FLgetsnap 	0
endin

instr	10	;OSCILLATORS
	asig1			oscil		1000, gkcps1, gisine	;OSCILLATOR 1
	asig2			oscil		1000, gkcps2, gisine	;OSCILLATOR 2
	asig3			oscil		1000, gkcps3, gisine ;OSCILLATOR 3
	outs		asig1+asig2+asig3, asig1+asig2+asig3
endin

</CsInstruments>

<CsScore>
i  10 0 3600
e
</CsScore>

</CsoundSynthesizer>