 <CsoundSynthesizer>
<CsOptions>

-+S -b1000 -+O -m0  -+*  -ocello.raw -+C

=-=-=-=  Command flags for  =-=-=-=
=-=-=-=  Live input and gui    =-=-=-=
=-=-=-=  Control.                   =-=-=-=


;===================================
; * Enter own input arguments above or in command line*                           
;  -+S -- Realtime audio out                                   
;  -+C -- Realtime audio capture (check instr 1)    
;  -bxxx  -- set buffer size   (set to 1000 here for safety)                                  
;===================================


</CsOptions>



;=====================================================
;       			"SCHNACKERTRONICS"
;
;	 AN ENVIRONMENT FOR REAL-TIME SAMPLING/PHRASE LOOPING
;
;			       Glenn Ianaro
;			             2001
;=====================================================


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Schnackertronics 1.2 Performance Documentation 
; by Glenn Ianaro (2001)
;
;                =-=-=-  For use with DirectCsound 5.1 or later --  http://web.tiscali.it/G-Maldonado/download.htm -=-=-=
;
;   I. Selecting Input Source
;  II. Setting Performance time
; III. Interface/ Recording & Playback 
; IV.  Extra Stuff
;
;
; I.   Selecting the Input Source
; To select where you would like the input source to come from (live input or sample) you must choose between the two lines in instr 
; 2.  Line one reads live sound input from your soundcard (must be used with the -+C flag), Line 2 reads a soundfile from disk as the input. 
; Comment out the line that you DO NOT want to use with a semicolon (;).  Don't forget to also enter the name of the sound file between 
; the quotation marks after soundin.  Right now it is set to read a file called "riley.wav"
;
; II.  Setting Performance time
;
; One must tell Csound how long to run by editing the times in the score.  In the score there are 5 instr calls after the ftables.  Set the value 
; in the duration collumn (3rd collunm) to the desired runtime in seconds.  Each column should have the same value.  Currently the values are 
; set to 540 seconds or 9 minutes of runtime.
;
; III. Interface/Recording & Playback of a loop
;
; The system has a master volume control on the bottom of the screen as well as individual volume controls for each part including all 4 loops 
; and the unprocessed through signal.  Loops can still be recorded with the thru volume turned down, which may be desireable in some situations 
; as the latency of audio hardware and processing can make a substancial delay (a nice effect as well).  
;
; To record a loop, push the "Record Start" button twice to start the recording.  In the console window (depending on what command flags you've 
; selected) you will see the message  "Recording. . ."  This will display at regular intervals.  To finish the recording press the "Record End" Button
; twice.  You will see the ridiculous message "Recording Complete!"  This means your audio has been recorded sucessfully.  
;
; To playback the loop press the "Loop Play" buttons labed "0" & "1".  It does not matter which one you press, but 2 are available to you for 
; retriggering of the loop.  The loop will playback at the original speed panned center with the filter closed, ringmod & phaser off.
;
; IV.  EXTRA STUFF
;
; Currently there is sligtly less than 24 seconds of sample memory available to use for the loops.  when the end of the sample memory is reached, the 
; audio wraps around and begins recording at the beginning again.  THe pointers for the audio loop do not change though.  This feature provides a 
; method to reload the loops with material and keep a composition moving forward (at the expense of not being able to move backwards).
;
; SNAPSHOTS --  These work, but will provide unwanted side effects unless all 4 loops have been manually assigned .  This is cause by the way the 
; shapshots work; when you recal a shapshot, it also recals the buttons which activate the recording and record finish buttons, making a 1 sample loop.  
; To avoid this use the snapshots after all the loops have been manually programmed.  This can be used creatively as the 1 sample loop ran through 
; the filter and then the ring mod makes a nice controllable oscillator.
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-






<CsInstruments>

sr=44100
kr=4410
ksmps=10
nchnls=2

	gitablen=1048576		;*** need to change this for longer tables***
	gitabcps = 1/(gitablen/sr)	; standard read through audio table
	gasig	init	0	;initialization of global variables for passing data between instruments
	gasig1	init	0	
	gasig2	init	0
	gasig3	init	0
	gasig4	init	0
	garing1	init	0
	garing2	init	0
	garing3	init	0
	garing4	init	0
	gkindexprev init	0
	gkindexno    init	0
	gkkill	init	0
	gkflag	init	0
	gaplay1	init	0
	gaplay2	init	0
	gaplay3	init	0
	gaplay4	init	0
	gaphas1 	init	0
	gaphas2 	init	0
	gaphas3 	init	0
	gaphas4 	init	0
	gafxL	init	0
	gafxR	init	0
	
;----------------------------------------------------GUI------------------------------------------------------------------------------------------
;*******************
;*     GUI    (instr 0)      *
;*******************
			FLpanel	"Schnackertronics", 624, 697, 5, 0, 4
ihandle			FLbox  	"S C H N A C K E R T R O N I C S", 1, 11, 26, 400, 20, 134, 20
ihandle			FLbox  	"by  Glenn Ianaro", 1, 11, 14, 100, 10, 274, 54
ihandle3			FLbox	"Play Loop",     1, 14, 12, 70, 40, 68, 114
ihandle4			FLbox	"Phaser",     1, 14, 12, 70, 40, 520, 100
 gkval,ih1		FLbutton	"Record Start", 1,   1,     2,      91,        35,   206, 88,-1
 gkval,ih2		FLbutton	"Record End", 0, 2, 2, 91, 35, 355, 88,-1
 gkvolm,ih3		FLslider	"Master Volume", .001, 1, -1, 5, -1, 455, 25, 97, 605
 gkvol,ih4		FLslider	"Thru Volume"    , .001, 1, -1, 6, -1, 19, 421,33, 134
 gkvol1,ih5		FLslider	"Loop 1 Volume", 0, 1, 0, 5, -1, 200, 20, 132, 127
 gkvol2,ih6		FLslider	"Loop 2 Volume", 0, 1, 0, 5, -1, 200, 20, 132, 232
 gkvol3,ih7		FLslider	"Loop 3 Volume", 0, 1, 0, 5, -1, 200, 21, 133, 338
 gkvol4,ih8	  	FLslider	"Loop 4 Volume", 0, 1, 0, 5, -1, 200, 22, 132, 445
; gk9,ih9			FLbutton	"Loop 1", 1, 0, 3, 60, 40, 74, 149, -1
;gk10,ih10		FLbutton	"Loop 2", 1, 0, 3, 60, 40, 74, 252, -1
;gk11,ih11		FLbutton	"Loop 3", 1, 0, 3, 60, 40, 74, 377, -1
;gk12,ih12		FLbutton	"Loop 4", 1, 0, 3, 60, 40, 74, 462, -1
gk9,ih9			FLbutBank	3, 2, 1,60, 40, 74, 149, 0 ,5,0,10000
gk10,ih10		FLbutBank	3, 2, 1,60, 40, 74, 252, 0 ,6,0,10000
gk11,ih11		FLbutBank	3, 2, 1,60, 40, 74, 370, 0 ,7,0,10000
gk12,ih12		FLbutBank	3, 2, 1,60, 40, 74, 462, 0 ,8,0,10000

gkcut1,gkres1,ih13,ih14	FLjoy		"Filter 1", 1, 200, 1, 18, -1, -1, -1, -1, 83, 76, 342, 137
gkamp1,gkcps1,ih15,ih16	FLjoy		"Ring Mod 1", 0, 2, 0, 500, 0, 0, -1, -1, 83, 76, 425, 137
gkcut2,gkres2,ih17,ih18	FLjoy		"Filter 2", 1, 200, 1,1 8, -1, -1, -1, -1, 83, 76, 342, 242
gkamp2,gkcps2,ih19,ih20	FLjoy		"Ring Mod 2", 0, 2, 0, 500, 0, 0, -1, -1, 83, 76, 425, 242
gkcut3,gkres3,ih21,ih22	FLjoy		"Filter 3", 1, 200, 1, 18, -1, -1, -1, -1, 83, 76, 342, 346
gkamp3,gkcps3,ih23,ih24	FLjoy		"Ring Mod 3", 0, 2, 0, 500, 0, 0, -1, -1, 83, 76, 425, 346
gkcut4,gkres4,ih25,ih26	FLjoy		"Filter 4", 1, 200, 1, 18, -1, -1, -1, -1, 83, 76, 342, 463
gkamp4,gkcps4,ih27,ih28	FLjoy		"Ring Mod 4", 0, 2, 0, 500, 0, 0, -1, -1, 83, 76, 425, 463
gkfeedback1,ih29		FLknob		"feedback", 0, 1, 0, 1, -1, 44, 515, 175
gkfreq1,ih30		FLknob		"Freq", 0, 100, 0, 1, -1, 44, 568, 175
gkfeedback2,ih29		FLknob		"feedback", 0, 1, 0, 1, -1, 44, 515, 275
gkfreq2,ih30		FLknob		"Freq", 0, 100, 0, 1, -1, 44, 568, 275
gkfeedback3,ih29		FLknob		"feedback", 0, 1, 0, 1, -1, 44, 515, 393
gkfreq3,ih30		FLknob		"Freq", 0, 100, 0, 1, -1, 44, 568, 393
gkfeedback4,ih29		FLknob		"feedback", 0, 1, 0, 1, -1, 44, 515, 510
gkfreq4,ih30		FLknob		"Freq", 0, 100, 0, 1, -1, 44, 568, 510
gkphpn1,ih40		FLknob		"pan", 0, 1, 0, 3, -1, 25, 522, 135
gkphpn2,ih41		FLknob		"pan", 0, 1, 0, 3, -1, 25, 522, 235
gkphpn3,ih42		FLknob		"pan", 0, 1, 0, 3, -1, 25, 522, 348
gkphpn4,ih43		FLknob		"pan", 0, 1, 0, 3, -1, 25, 522, 468
gkphv1,ih44		FLknob		"vol", 0, .7, 0, 3, -1, 25, 572, 135
gkphv2,ih45		FLknob		"vol", 0, .7, 0, 3, -1, 25, 572, 235
gkphv3,ih46		FLknob		"vol", 0, .7, 0, 3, -1, 25, 572, 348
gkphv4,ih47		FLknob		"vol", 0, .7, 0, 3, -1, 25, 572, 468
ih90			FLvalue	" ", 	47,	35,	268,	171
ih91			FLvalue	" ", 	47,	35,	268,	275
ih92			FLvalue	" ", 	47,	35,	268,	383
ih93			FLvalue	" ", 	47,	35,	268,	499
			FLsetBox		14, ih90
			FLsetBox		14, ih91
			FLsetBox		14, ih92
			FLsetBox		14, ih93
gkspeed1,ih31		FLknob		"speed", 0, 2, 0, 3, ih90, 35, 220, 170
gkspeed2,ih32		FLknob		"speed", 0, 2, 0, 3, ih91, 30, 220, 275
gkspeed3,ih33		FLknob		"speed", 0, 2, 0, 3, ih92, 30, 220, 383
gkspeed4,ih34		FLknob		"speed", 0, 2, 0, 3, ih93, 30, 220, 499
gkpctrlt,ih35		FLknob		"thru pan", 0, 1, 0, 3, -1, 30, 34, 590
gkpctrl1,ih36		FLknob		"pan 1", 0, 1, 0, 3, -1, 30, 170, 170
gkpctrl2,ih37		FLknob		"pan 2", 0, 1, 0, 3, -1, 30, 170, 275
gkpctrl3,ih38		FLknob		"pan 3", 0, 1, 0, 3, -1, 30, 170, 383
gkpctrl4,ih39		FLknob		"pan 4", 0, 1, 0, 3, -1, 30, 170, 498
			FLpanel_end	

			FLpanel		"Presets", 201, 250, 640, 0, 5
ihandle			FLbox  "Snapshots", 1, 11, 22, 50, 10, 72, 15
gkStore,ih1 		FLcount	" ",0,15,1,5,21,150,15,20,50,    -1,4,0,0
			FLlabel  8, 14, 1, 111, 111, 111 
gk9,ih			FLbutton	"Store ",  3,0, 11,50,21,71,67,    0,32,0,0
gk9,ih			FLbutton	"Save bank", 1,0, 11,60,20,20,100,    0,35,0,0
gk9,ih			FLbutton	"Load bank", 1,0, 11,60,20,120,100,    0,36,0,0

gkGet,ih			FLbutBank	12, 2,8,       160,120, 20,120,    0,37,0,0


			FLpanel_end
			FLrun
gkvol	init	0
gkvolm	init	1
gkcut1	init	1
gkres1	init	1
gkcut2	init	1
gkres2	init	1
gkcut3	init	1
gkres3	init	1
gkcut4	init	1
gkres4 	init	1
gkspeed1 init	1
gkspeed2 init	1
gkspeed3 init	1
gkspeed4 init	1
gkpctrlt	init	.5
gkpctrl1 	init	.5
gkpctrl2 	init	.5
gkpctrl3 	init	.5
gkpctrl4 	init	.5
gkphpn1	init	.5
gkphpn2	init	.5
gkphpn3	init	.5
gkphpn4	init	.5

			;************************************************************
			;*** This instrument should be only run external midi control is desired.  ***  
			;*** It is a good idea to comment out either the MIDI Control block or    ***
			;*** The GUI block above for better performance and to avoid conflicts ***			
			;************************************************************
;--------------------------------------------------------MIDI INPUT----------------------------------------------------------------
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=		This block reads in all control values and sends
;		*  MIDI CONTROL * 					them out to global variables to control instrument.  
; output  ctrl7       channel, Controller #, Minimum value, Maximum value
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=--=
	instr 1
;------global control------
gkval	ctrl7	2, 1,   0, 127		;
;------playback engine------
gkspeed1 ctrl7	3, 66, 0, 2 		;******************
gkcut1	ctrl7	3, 74, 1, 200		;*  Playback Controls *
gkres1	ctrl7	3, 75, 1, 8		;******************
gkspeed2 ctrl7	3, 40, 0, 2 		;
gkcut2	ctrl7	3, 80, 1, 200		;
gkres2	ctrl7	3, 81, 1, 8		;
gkspeed3 ctrl7	3, 32, 0, 2 		;
gkcut3	ctrl7	3, 78, 1, 200		;
gkres3	ctrl7	3, 79, 1, 8		; 
gkspeed4 ctrl7	3, 24, 0, 2 		;
gkcut4	ctrl7	3, 76, 1,200		;
gkres4	ctrl7	3, 77, 1, 8		;
;------fx section------
gkfreq1	         ctrl7	3, 70, 0, 100	;************
gkfeedback1  ctrl7	3, 71, 0, 1		;** Phaser   **
gkfreq2	         ctrl7	3, 44, 0, 100	;************
gkfeedback2  ctrl7	3, 45, 0, 1
kfreq3	         ctrl7	3, 36, 0, 100
gkfeedback3  ctrl7	3, 37, 0, 1
gkfreq4	         ctrl7	3, 28, 0, 100
gkfeedback4  ctrl7	3, 29, 0, 1
gkphpn1 ctrl7	3, 68, 0, 1 		;*****************************
gkphpn2 ctrl7	3, 42, 0, 1		;**  Phaser phanning and volume **
gkphpn3 ctrl7	3, 34, 0, 1		;*****************************
gkphpn4 ctrl7	3, 26, 0, 1
gkphv1	ctrl7	3, 69, 0, 1
gkphv2	ctrl7	3, 43, 0, 1
gkphv3	ctrl7	3, 35, 0, 1
gkphv4	ctrl7	3, 27, 0, 1
gkamp1	ctrl7	3, 72, 0, 2		; ********************
gkcps1	ctrl7	3, 73, 0, 500		; *   RING MODULATOR  *
gkamp2	ctrl7	3, 46, 0, 2		; ********************
gkcps2	ctrl7	3, 47, 0, 500		; 
gkamp3	ctrl7	3, 38, 0, 2		; 
gkcps3	ctrl7	3, 39, 0, 500		; 
gkamp4	ctrl7	3, 30, 0, 2		;
gkcps4	ctrl7	3, 31, 0, 500		;
;------mixer------
	initc7	3, 7,   1			; initilizes the volumes	
	initc7	3, 17, 1			; Master volume is at maximum (1)
	initc7	3, 18, 0			; while the loop volumes are set to 0
	initc7	3, 19, 0
	initc7	3, 20, 0
gkvolm	ctrl7	3, 7,   0, 1		; reads MIDI CC#7 for master volume control
gkvol	ctrl7	3, 16, 0, 1		; CC#16,20, 21, 22, 23 for control of instrument dry signal, loop1, loop2, loop3,loop4 respectively
gkvol1	ctrl7	3, 17, 0, 1	
gkvol2	ctrl7	3, 18, 0, 1
gkvol3	ctrl7	3, 19, 0, 1
gkvol4	ctrl7	3, 20, 0, 1
	endin


;-----------------------------------------------------IN--------------------------------------------------------------------------
;********************************************		-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;*                                AUDIO IN                                     *		 adjust comments for realtime audio in or soundfile input
;********************************************		-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=
	instr 2	;read sample in  *** 
gasig	in					; Use this line for REALTIME audio i/o  << Substitute your soundfile between "quotes"
;gasig	soundin	"riley.wav", 0, 4			; This line for reading a long soundfile from disk
	endin	
	
;-------------------------------------------------RECORDING CONTROL-------------------------------------------------------------
;****************************
;***   RECORDING CONTROL   ***
;****************************
	instr 3					; Reads CC# / sets flag accoringly / flag transmitted to INSTR 3
kvalold	init	0
if	kvalold = gkval	kgoto	skip		; Testing to see if The Midi Control Change messages has changed
if	kvalold != gkval	kgoto	next			
next:
gkflag = (gkval=1 ? 1 : 0)				; set the flag
gkflag  = (gkval=2 ? 2 : gkflag)
kvalold	=	gkval				; kvalold is a flag used by INSTR 2 to see if the midi CC has changed values between k rate cycles
skip:
	endin


;-----------------------------------------------RECORDING ENGINE-------------------------------------------------------------------
;**************************************
;** WRITE AUDIO AND POINTERS TO TABLE **
;**************************************

	instr 4	;Writes to Audio and Data Tables
kflag	init	0
if	gkflag  = 0	kgoto end
if 	gkflag  = 1	kgoto audio
if	gkflag  = 2	kgoto data

;;;;;;;;;;;;;;;;;;;;;;;;;;
;write incoming audio;
;;;;;;;;;;;;;;;;;;;;;;;;;;
audio:						;Writes audio to the table
printks	"Recording. . . ", 1				;Printks printes the message to screen for debugging purposes - turn off for performance
and	phasor	gitabcps				;Set the sampling rate of the table (gitabcps = 44100 Hz/Length of Table)
andex	=	and * gitablen			;step through the table at the audio rate
	tablew	gasig, andex, 1, 0, 0, 1		;Writes audio to Audio Storage Table
	kgoto end
;;;;;;;;;;;;;;;;;;;;
;write datatable;
;;;;;;;;;;;;;;;;;;;;
data:						; Writes data pointer after audio write is done
printks	"Recording Complete! ", 1			;Printks printes the message to screen for debugging purposes - turn off for performance
gkindexprev =	gkindexno			
gkindexno    =	gkindexno + 1			;increments the pointer of the Data Pointer table
klocation    =	andex
	tablew	klocation, gkindexno, 3, 0, 0, 1	;Writes the number of samples recorded into the Audio Storage Table
kflag	=	1
gkflag	=	0
;;;;;;;;;;;;;;;;;;;;
;end instrument;
;;;;;;;;;;;;;;;;;;;;
end:		
printks	". ", 1				; The End: loop acts as a Kind of bypass from table writes

	endin


;-----------------------------------------------------------PLAYBACK ENGINE 1--------------------------------------------------------------------
;******************************
;** READS FROM AUDIO TABLE  #1**
;******************************

	instr 5	;Reads from Data Table
inote	notnum				; instrument starts with a NOTEON messonge on Channel 5
ibeg	table	0, 3			; Gets the value stored at location 0 in the Data pointer table
iend	table	1, 3			; Gets the value stored at loction 1 in the Data pointer table
ilength	=	iend - ibeg		; Calculates the length of the segment
itabcps = 1/(ilength/sr)			; calculates the sampling rate of the segment for the phasor
and	phasor	itabcps ;gitabcps		; steps through the table
andex	=	gkspeed1*and * ilength	; 
gaplay1	table	andex, 1, 0 , 0, 0 		; This section is a table lookup oscillator readint audio data rather than single cycle waveforms
;=-=-=- Lowpass Filter 1 -=-=-=
gasig1	lowres	gaplay1, gkcut1, gkres1

	endin

;-----------------------------------------------------------PLAYBACK ENGINE 2--------------------------------------------------------------------
;******************************
;** READS FROM AUDIO TABLE #2 **
;******************************

	instr 6	;Reads from Data Table
inote	notnum				; instrument starts with a NOTEON messonge on Channel 6
ibeg	table	1, 3			; Gets the value stored at location 1 in the Data pointer table
iend	table	2, 3			; Gets the value stored at loction 2 in the Data pointer table
ilength	=	iend - ibeg		; Calculates the length of the segment
itabcps = 1/(ilength/sr)			; calculates the sampling rate of the segment for the phasor
and	phasor	itabcps ;gitabcps		; steps through the table	
andex	=	(gkspeed2*and * ilength)+ibeg	;
gaplay2	table	andex, 1, 0 , 0, 0 		; This section is a table lookup oscillator reading audio data rather than single cycle waveforms
;=-=-=- Lowpass Filter 2 -=-=-=
gasig2	lowres	gaplay2, gkcut2, gkres2

	endin
;-----------------------------------------------------------PLAYBACK ENGINE 3--------------------------------------------------------------------
;******************************
;** READS FROM AUDIO TABLE #3 **
;******************************

	instr 7	;Reads from Data Table
inote	notnum				; instrument starts with a NOTEON messonge on Channel 7
ibeg	table	2, 3			; Gets the value stored at location 1 in the Data pointer table
iend	table	3, 3			; Gets the value stored at location 2 in the Data pointer table
ilength	=	iend - ibeg		; Calculates the length of the segment
itabcps = 1/(ilength/sr)			; Calculates the sampling rate of the segment for the phasor
and	phasor	itabcps ;gitabcps		; Steps through the table
andex	=	(gkspeed3*and * ilength)+ibeg	; 
gaplay3	table	andex, 1, 0 , 0, 0		; This section is a table lookup oscillator reading an audio phrase rathan than a single cycle waveform
;=-=-=- Lowpass Filter 3 -=-=-=
gasig3	lowres	gaplay3, gkcut3, gkres3
	endin


;-----------------------------------------------------------PLAYBACK ENGINE 4--------------------------------------------------------------------
;******************************
;** READS FROM AUDIO TABLE #4 **
;******************************

	instr 8	;Reads from Data Table
inote	notnum				; instrument starts with a NOTEON messonge on Channel 8
ibeg	table	3, 3			; Gets the value stored at location 1 in the Data pointer table
iend	table	4, 3			; Gets the value stored at location 2 in the Data pointer table
ilength	=	iend - ibeg		; Calculates the length of the segment
itabcps = 1/(ilength/sr)			; Calculates the sampling rate of the segment for the phasor
and	phasor	itabcps ;gitabcps		; Steps through the table
andex	=	(gkspeed3*and * ilength)+ibeg	; 
gaplay4	table	andex, 1, 0 , 0, 0		; This section is a table lookup oscillator reading an audio phrase rathan than a single cycle waveform
;=-=-=- Lowpass Filter 4 -=-=-=
gasig4	lowres	gaplay4, gkcut4, gkres4
	endin

;----------------------------------------------------------------------FX--------------------------------------------------------------------
;    ************************************
;   **                       FX Section                           **
;  **                                                                     **
; **  gasig(X) is the output of the loop playback  **
;*****************************************
	instr 11
;-----RING MODULATOR-----
amod	oscil	gkamp1, gkcps1, 9		; Ringmod oscillator 1
amod2	oscil	gkamp2,gkcps2, 9		; Ringmod Oscillator 2
amod3	oscil	gkamp3, gkcps3, 9		; Ringmod Oscillator 3
amod4	oscil	gkamp4, gkcps4, 9		; Ringmod Oscillator 3
garing1	=	amod*gasig1 		; Signal multiplication
garing2	=	amod2*gasig2
garing3	=	amod3*gasig3
garing4	=	amod4*gasig4

;-----PHASER-----
gaphas1	phaser1	gasig1, gkfreq1, 100, gkfeedback1	; phasor with 100 allpass filters
gaphas2	phaser1	gasig2, gkfreq2, 100, gkfeedback2
gaphas3	phaser1	gasig3, gkfreq3, 100, gkfeedback3
gaphas4	phaser1	gasig4, gkfreq4, 100, gkfeedback4

;------FX OUTPUT------
aphasL	=	(sqrt(1-gkphpn1)*gkphv1*gaphas1+sqrt(1-gkphpn2)*gkphv2*gaphas2+sqrt(1-gkphpn3)*gkphv3*gaphas3+sqrt(1-gkphpn4)*gkphv4*gaphas4)
aphasR	=	(sqrt(gkphpn1)*gkphv1*gaphas1+sqrt(gkphpn2)*gkphv2*gaphas2+sqrt(gkphpn3)*gkphv3*gaphas3+sqrt(gkphpn4)*gkphv4*gaphas4)
a13	=	(garing1+garing2+garing3+garing4)
gafxL	=	aphasL+a13
gafxR	=	aphasR+a13
	endin

;----------------------------------------------------------------------MIXER----------------------------------------------------------------------------------------
;***********************
;** OUTPUT INSTRUMENT **
;***********************
	instr 21
;krtl    =         sqrt(gkphpn1)               ; SQRT PANNING TECHNIQUE
;krtr    =         sqrt(1-gkphpn1)             ; pg 247,FIG.7.20 DODGE/JERSE BOOK
a1	=	(gkvol*gasig*sqrt(1-gkpctrlt))
a2	=	(gkvol1*gasig1*sqrt(1-gkpctrl1))
a3	=	(gkvol2*gasig2*sqrt(1-gkpctrl2))
a4	=	(gkvol3*gasig3*sqrt(1-gkpctrl3)) 
a5	=	(gkvol4*gasig4*sqrt(1-gkpctrl4))
a6	=	(gkvol*gasig*sqrt(gkpctrlt))
a7	=	(gkvol1*gasig1*sqrt(gkpctrl1))
a8	=	(gkvol2*gasig2*sqrt(gkpctrl2))
a9	=	(gkvol3*gasig3*sqrt(gkpctrl3))
a10	=	(gkvol4*gasig4*sqrt(gkpctrl4)) 
;	outs	gkvolm*( gkvol*gasig*(1-gkpctrlt)+gkvol1*gasig1*(1-gkpctrl1) +gkvol2*gasig2*(1-gkpctrl2) +gkvol3*gasig3*(1-gkpctrl3) +gkvol4*gasig4*(1-gkpctrl4)  + garing1 + garing2 + garing3 +garing4) , gkvolm*(gkvol*gasig*gkpctrlt+gkvol1*gasig1*gkpctrl1 +gkvol2*gasig2*gkpctrl2 +gkvol3*gasig3*gkpctrl3 +gkvol4*gasig4*gkpctrl4 + garing1 + garing2 + garing3 +garing4)	;MIXES and OUTPUTS the signals
	outs	gkvolm*(a1+a2 +a3 +a4 +a5 +gafxL) , gkvolm*(a6+a7 +a8 +a9 +a10 +gafxR)	;MIXES and OUTPUTS the signals

gasig	=	0			
gasig1	= 	0			;Sets the volume of Global variables back to 0	
gasig2	= 	0			;at the end of a Computation cycle to avoid a highpitch ringing
gasig3	=	0
gasig4	=	0
garing1	=	0
garing2	=	0
garing3	=	0
garing4	=	0
gaplay1	=	0
gaplay2	=	0
gaplay3	=	0
gaplay4	=	0
gaphas1	=	0
gaphas2	=	0
gaphas3	=	0
gaphas4	=	0
gafxL	=	0
gafxR	=	0
	endin


;----------------------------------------------------------GUI SNAPSHOTS------------------------------------------------------------------------

	instr	32
inumsnap	inumval FLsetsnap	i(gkStore)
	endin

	instr	35
	FLsavesnap	"schnackertronics.set"
	endin

	instr	36
	FLloadsnap	"schnackertronics.set"
	endin

	instr	37
inumel	FLgetsnap	i(gkGet)
	endin



</CsInstruments>
<CsScore>





;**************************************
;**************************************
;**    SCORE    **************************
;**************************************
;**************************************

f1	0	1048576 -10 	1		; Audio storage table
f3	0	128	-2	0		; Data index Table
f9 	0	 8192 	7	0 	2048 1 4096 -1 2048 0 ;triangle

;i1 0 540		; Instrument 1 --MIDI Controll instrument
i2 1 540		; Start Instrument 1 -- plays soundfile from disk  into a global variable
i3 0 540		; Start Instrument 2 -- Reads controller values and sets flags
i4 2 540		; Start Instrument 2 -- writes audio to table and write data pointers to data table
i11 0 540
i21 0 540		; Start instrument 11 -- Audio output instrument


</CsScore>
</CsoundSynthesizer>