; sampler signal sent through a reverberator
	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   ; needed only for CHAN options
kcps	cpsmidib   ; pitch with +/- semitone bend from pitch bend wheel

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
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    midictrl 67
imidped    midictrl 66

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.2 * idecay
   iatdec  =  .03
   igoto gotartic
staccato:   ; LEFT pedal down
   idecay  = .5 * idecay
   iatdec  =  .01
   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, kcps , ifno, cpsoct(ibasoct)


;  ====== MIDI continuous controllers on MCS2:  ========================
        ; mod wheel =   controller 01    controls wet (reverb) vs. "dry" (direct) mix
        ; Foot controllers Sliders:
        ; fc2       =   controller # 07    Amplitude (volume)
        ; fc1       =   controller # 04    Not used
        ; Continuous Sliders:
        ; cs1       =   controller # 06    Reverb time
        ; cs2       =   controller # 05    Reverb "brightness" (decay rate
                                         ;  of high frequencies)
      
gktest =  gktest + 1    ; test to see if more than one note is playing on this MIDI
                        ; channel, so that these global variables are not recomputed
                        ; unnecessarily
if gktest > 1 kgoto gotcontrollers

         ; fc2 {foot controller 2} controls global AMPLITUDE {"volume"}
  gkfc2    midictrl 7    ; foot controller # 2 = midi controller 07 {"volume"}
  gkfc2 =  gkfc2 * .0078    ; = gkfc2/127, rescale to 0 - 1.
  gkfc2    kpow   gkfc2, 2. , 1.    ; convert linear to exponential

  ; REVERB signal variables:
  gkmod    midictrl  1  ; mod wheel controls reverb2 khdif {hgh frequency diffusion}
  gkmod =  gkmod * .0078    ;  rescale to 0 - 1.

; ---  continuous sliders 1 & 2 on MCS2 control wet/dry mix & rev time:
   gkcs1  midictrl  8   ; continuous slider 1 = midi controller # 8
   gkcs1 = gkcs1 * .0078  ; rescale to 0 - 1.  ; wet/dry mix
   gkcs2  midictrl  5   ; continuous slider 2 = midi controller # 5
   gkcs2 = gkcs2 * .0315  ; rescale to 0 - 4.  ; reverb time
gotcontrollers:
kamp    port  gkfc2, .02   ; smooth out abrupt changes in this controller
                           ; kamp must be local {not global} variable
                           ; else clicks result on ends of notes
a1 = a1 * kamp
aglobal =  gkcs1 * a1 
a1 =  (1. - gkcs1) * a1
