-odac -iadc -d -m0
sr=44100
ksmps=64
nchnls=2
gks init 1
gks2 init 2
gamix init 0 
/* oscillator packs */
FLcolor  200,10,40, 140,60,60
FLpanel  "synthesizer panel", 500, 260, 100, 100
FLcolor  200,10,40,200,10,40
ib1	FLbox	"osc 1", 1, 1, 16, 50, 20, 45, 10 
FLcolor  10,100,180,255,160,100
gixoff = 20
giyoff = 30
gk4, gib4 FLbutton "on", 1, 0, 2, 50, 30, 10+gixoff, 10+giyoff, 105, gks, 0, -1, 16000, 200
FLcolor  10,100,180,180,0,0
gk5, gik5 FLknob	  "pitch", 0.1, 10, -1, 1, -1, 50, 80+gixoff, 10+giyoff
FLsetVal_i  1, gik5
FLcolor  200,10,40,200,10,40
ib11	FLbox	"saw", 1, 1, 16, 50, 30, 10+gixoff, 52+giyoff
FLcolor  200,10,40,200,10,40
ib1	FLbox	"osc 2", 1, 1, 16, 50, 20, 45, 130 
FLcolor  200,10,40, 140,60,60
FLcolor  10,100,180,255,160,100
gixoff = 20
giyoff = 150
gk6, gib6 FLbutton "on", 1, 0, 2, 50, 30, 10+gixoff, 10+giyoff, 105, gks2, 0, -1, 32000, 200
FLcolor  10,100,180,180,0,0
gk7, gik7 FLknob	  "pitch", 0.1, 10, -1, 1, -1, 50, 80+gixoff, 10+giyoff
FLsetVal_i  1, gik7
FLcolor  200,10,40,200,10,40
ib1	FLbox	"pulse", 1, 1, 16, 50, 30, 10+gixoff, 52+giyoff
FLcolor  200,10,40,200,10,40
ib1	FLbox	"moog ladder filter", 1, 1, 16, 150, 20, 270, 10 
/* filter pack */
FLcolor  200,10,40, 140,60,60
gixoff = 230
giyoff = 30
FLcolor  255,255,255,255,255,255
iv1 FLvalue  " ", 50, 20, 160+gixoff, 10+giyoff
iv2 FLvalue  " ", 50, 20, 160+gixoff, 60+giyoff
FLcolor  200,10,40, 140,60,60
gk1, gis1 FLslider "cutoff frequency", 1, 20000, -1, 5, iv1, 140, 10, 10+gixoff, 10+giyoff
gk2, gis2 FLslider "resonance",        0,     1,  0, 5, iv2, 140, 10, 10+gixoff, 60+giyoff
FLsetVal_i 5000, gis1
FLsetVal_i 0.8, gis2
FLcolor  200,10,40,200,10,40
ib1	FLbox	"mixer", 1, 1, 16, 50, 20, 310, 130 
/* mixer pack */
gk3 init -90
gk8 init -90
gk9 init -90
gk10 init -90
FLcolor  200,10,40, 140,60,60
giyoff = 150
gixoff = 200
FLcolor  10,100,180,255,160,100
gk3, gik3 FLknob	  "osc 1", -90, 0, 0, 1, -1,  50, 10+gixoff, 10+giyoff
gk8, gik8 FLknob	  "osc 2", -90, 0, 0, 1, -1,  50, 80+gixoff, 10+giyoff
gk9, gik9 FLknob	  "noise", -90, 0, 0, 1, -1,  50, 150+gixoff, 10+giyoff
gk10, gik10 FLknob  "mic input", -90, 0, 0, 1, -1,  50, 220+gixoff, 10+giyoff
FLpanelEnd
FLsetVal_i -90, gik10
FLsetVal_i -90, gik9
FLsetVal_i -16, gik8
FLsetVal_i -16, gik3
FLrun 
gkchk init 0
gkfun init 400
massign 1, 11
/* MIDI keyboard input */
instr 11
gkchk = 1  /* activates MIDI input */
gkfun cpsmidib /* gets the key freq */
endin
/* oscillator 1 */
instr 1
kon init 1  /* initially ON */
if gkchk == 1 then /* if MIDI is present, checks for key press */
kon active 11      /* checks for  key press to control amp */
endif
iamp = p4
ifund = p5
kamp init -90
kfun tonek gk5*gkfun, 10
if kon == 0 then   
kamp = -90       /* amp = -90 if not ON */
else
kamp = gk3       /* otherwise amp comes from mixer */
endif
kamp tonek kamp, 10
asig  oscili  p4, kfun, 1
gamix = gamix +  asig*ampdb(kamp)
    
endin
instr 2
kon init 1
if gkchk == 1 then
kon active 11
endif
iamp = p4
ifund = p5
kamp init -90
kfun tonek gk7*gkfun, 10
if kon == 0 then
kamp = -90
else
kamp = gk8
endif
kamp tonek kamp, 10
asig   buzz  p4, kfun, sr/(2*kfun), 2
gamix = gamix +  asig*ampdb(kamp)
    
endin
instr 10
ain1,ain2   ins
ain = (ain1+ain2)/2
anoi  rand  16000
kcf  tonek gk1, 10
kres tonek gk2, 10
knoi  tonek gk9, 10
kin   tonek gk10, 10
asig = gamix + anoi*ampdb(knoi) + ain*ampdb(kin)
afil moogladder   asig, kcf, kres
      outs   afil,afil
gamix = 0
/* MIDI control */
initc7 1, 7, 0.75 ; osc 1 amp
initc7 2, 7, 0.75 ; osc 2 amp
initc7 3, 7, 0    ; noise amp
initc7 4, 7, 0    ; mic amp
initc7 1, 10, 0.9 ; filter freq
initc7 2, 10, 0.9 ; filter bw
initc7 3, 10, 0.5 ; osc 1 pitch
initc7 4, 10, 0.5 ; osc 2 pitch
initc7 1, 11, 0    
initc7 2, 11, 0   
kc3 init 0
k3  ctrl7  1, 7, -90, 0 
if k3 != kc3 then
kc3 = k3
    FLsetVal 1, k3, gik3
endif
kc8 init 0 
k8  ctrl7  2, 7, -90, 0
if kc8 != k8 then
kc8 = k8
    FLsetVal 1, k8, gik8
endif
 
kc9 init 0
k9  ctrl7  3, 7, -90, 0
if kc9 != k9 then
kc9 = k9
    FLsetVal 1, k9, gik9
endif
 
kc10 init 0
k10  ctrl7  4, 7, -90, 0
if kc10 != k10 then
kc10 = k10
    FLsetVal 1, k10, gik10
endif
 
kc1 init 0
k1  ctrl7  1, 10, 0, 1 
if kc1 != k1 then
kc1 = k1
kex pow 20000, k1
    FLsetVal 1, kex, gis1
endif
 
kc2 init 0
k2  ctrl7  2, 10, 0, 1
if kc2 != k2 then
kc2 = k2
    FLsetVal 1, k2, gis2
endif
 
kc5 init 0
k5  ctrl7  3, 10, 0, 1 
if kc5 != k5 then
kc5 = k5
kex pow 100, k5
    FLsetVal 1, kex*0.1, gik5
endif
 
kc7 init 0
k7  ctrl7  4, 10, 0, 1
if kc7 != k7 then
kc7 = k7
kex pow 100, k7
    FLsetVal 1, kex*0.1, gik7
endif
endin
instr 100
gks = 1 - gk4*2
gks2 = 2 - gk6*4
endin
f1 0 16384 10 1 .5 .4 .3 .2 .1 .05 .04 .03 .02 .01 .01 .01 .01
f2 0 16384 10 1
i10  0 60000
i100 0 60000