<info>
ESM Csound Library instrument algorithm ccsamprev :
midiins algorithm : ccsamprev
(routes input soundfiles through Csound reverberator "reverb2")
Default score file includes the "xylo" input soundfile functions
Move the foot pedal before playing or you may get no sound.
CS1 controls % of reverb vs. dry signal (0 - 100 %)
CS2 controls the reverb time (0 - 4 seconds)
Mod wheel controls "brightness"  (khdif, or high frequency
   diffusion; range .2 - 1.)
Foot controller 2 affects output amplitude.
Pitch bend wheel affects pitch.
Allan Schindler  1/97
</info>
<tk_interface>


</tk_interface>
<mono>
; 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 2 ; pitch with +/- 2 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  imidic7  64, .2, 40
idecay = (isust = 0 ? .2 : 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  =  .006
   igoto gotartic
;  ------- end of pedal controller input ----------
gotartic:

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

a1	loscil	kamp, kcps , ifno, cpsoct(ibasoct)


;  ====== MIDI continuous controllers on MCS2:  ========================
      ; mod wheel =  controller 01  controls "brightness" (high freq.
                   ; diffusion - best not to move during performance
        ; Foot controllers Sliders:
        ; fc2       =   controller # 07    Amplitude (volume)
        ; fc1       =   controller # 04    Not used
        ; Continuous Sliders:
        ; cs1       =   controller # 06    wet/dry mix
        ; cs2       =   controller # 05    Reverb time
      
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    midic7 7, 0, 1  ; foot controller # 2 = midi controller 07 {"volume"}
; "No Legal Opcode error   gkfc2    kpow  gkfc2, 2, 1    ; convert linear to exponential
  gkfc2 = sqrt(gkfc2)

  ; REVERB signal variables:
  gkmod    midic7 8, 0, 1  ; mod wheel controls khdif {hgh frequency diffusion}

; ---  continuous sliders 1 & 2 on MCS2 control wet/dry mix & rev time:
   gkcs1  midic7 8,0, 1. ; continuous slider 1 = midi controller # 8
                         ; controls wet/dry mix
   gkcs2  midic7 5,0, 4. ; continuous slider 2 = midi controller # 5
                         ; controls reverb time
gotcontrollers:
kamp    port  gkfc2, .08   ; 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
       out a1 
gaudio = gaudio + aglobal
       endin 
; ---  global mono reverberation instrument: ------------------
instr 16

    gkcs1     port  gkcs1, .02   ; smooth out abrupt changes in this controller
    gkcs2     port  gkcs2, .02   ; smooth out abrupt changes in this controller
    gkmod     port  gkmod, .01   ; smooth out abrupt changes
a1     nreverb  gaudio , gkcs2 , .2 + (.8 * (1. - gkmod))
out .25 * a1  ; note 75 % attentuation of reverb signal
       gaudio = 0
        ; do not zero out kmod, gkcs1 or gkcs2
       gktest = 0
       endin

</mono>
<stereo>


</stereo>
<quad>


</quad>
<score>
; default example  score
;  xylo (xylophone) soundfile functions  
f1 0 0 -1  "/sflib/perc/xylo.a4"  0 0 0; dur = 1.938
f2 0 0 -1  "/sflib/perc/xylo.cs5"  0 0 0; dur = 1.856
f3 0 0 -1  "/sflib/perc/xylo.fs5"  0 0 0; dur = 1.49
f4 0 0 -1  "/sflib/perc/xylo.b5"  0 0 0; dur = 1.748
f5 0 0 -1  "/sflib/perc/xylo.e6"  0 0 0; dur = 1.42
f6 0 0 -1  "/sflib/perc/xylo.a6"  0 0 0; dur = 1.56
f7 0 0 -1  "/sflib/perc/xylo.d7"  0 0 0; dur = 1.078
f8 0 0 -1  "/sflib/perc/xylo.g7"  0 0 0; dur = 1.11
f9 0 0 -1  "/sflib/perc/xylo.c8"  0 0 0; dur = .634
 
   ;; f99 = gen1 funcs & midi note split pts
f99 0 128 -17 0 1 71 2 75 3 81 4 86 5 91 6 96 7 101 8 105 9 ;
   ;; f98 = midi notes of samples
f98 0  16  -2 0 69 73 78 83 88 93 98 103 108 ;

f97 0 128 5 1 128 33                ; veloc to non-linear amp
f96 0 128 5 .005 120 1. 128 1.      ; brightness scaling
;   End of XYLO  functions  

f100 0 1024 10 1.       ; sine wave control function
 
f0 300 
i16 0.000 300
e 

</score>

