; instrument algorithm midisampbright -- velocity value applied to high & low pass
; filters to determine timbral brightness
	instr	1
inum	notnum
ifno	table	inum, 99	;keyboard mapping to gen1 ftables 

ibasno	table	ifno, 98        ; returns midi notes of the sonudfile samples
ibasoct	=	ibasno/12. + 3.

icps	cpsmidi

iatt  =  0  ; default no fade-in to soundfile, modified only for "legato" (left
            ; Clavinola pedal down

; ------ Clavinola pedals :  ------------------------
    ; Clavinla RIGHT pedal, MIDI ctrl #  64 (continuous but very poor resolution)
    ; used as a sustain pedal :
     ; isust  midictrl  64 
isust  imidic7  64, .2, 40
isust  midictrl  64
idecay = (isust = 0 ? .2 : .4 * isust )  ; "fade-out" time after key released
iatdec  =  .02

   ; Clavinola left and middle pedals
   ; left pedal (ctrl # 66) creates staccato, center pedal (ctrl # 67) creates legato
    ;  these 2 controllers are NOT continuous -- they are inits (either off or on)
ileftped    imidic7 67, 0, 1.
imidped    imidic7 66, 0, 1.

if imidped > .5 igoto legato  ; if middle ped down, legato articulation
if ileftped > .5 igoto staccato  ; if left ped down, staccato articulation
   igoto gotartic

legato:    ; MIDDLE pedal down
   ; if both left & middle pedals are down, use default normal articulation values
if imidped > .5 igoto gotartic 
   iatt    ampmidi  .5
   iatt  =  .5 - iatt
   iatt  = (iatt < .15 ? 0 : 2.2  * iatt)
   idecay  = 1.3 * idecay
   iatdec  =  .04
   igoto gotartic
staccato:   ; LEFT pedal down
   idecay  = .4 * idecay
   iatdec  =  .005
   igoto gotartic
;  ------- end of pedal controller input ----------
gotartic:

iamp	ampmidi	1, 97        ; max amp & non-linear scaling in f97
amp	linenr	iamp, iatt , idecay , .02

a1	loscil	amp, icps , ifno, cpsoct(ibasoct)

; brightness 
ibright ampmidi 1, 96
alo     tone   a1, .7 * icps
ahi     atone  a1, .7 * icps
a1 = (ibright * ahi) + ((1. - ibright) * alo)
