<info>
ESM Csound Library instrument algorithm ccsampdel :
midiins algorithm : ccsampdel
(routes input soundfiles through a delay line with feedback)
Default score file includes the "strings.p" functions
(a set of pizzicato string tones)
Move the foot pedal before playing or you may get no sound.
CS1 controls % of delayed vs. direct signal (0 - 100 %)
CS2 controls the delay time (0 - 8 seconds)
Mod wheel controls % feedback (0 - 100 %)
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 delay line
	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  =  .005
   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 feedback %
        ; Foot controllers Sliders:
        ; fc2       =   controller # 07    Amplitude (volume)
        ; fc1       =   controller # 04    Not used
        ; Continuous Sliders:
        ; cs1       =   controller # 08    delay/direct mix
        ; cs2       =   controller # 05    delay 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
                        ; redundantly
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)

  ; DELAY signal variables:
  gkmod    midic7 1, 0, .98 ; mod wheel controls delay feedback %

  ; ---  continuous sliders 1 & 2 on MCS2 control wet/dry mix & delay time:
   gkcs1  midic7 8, 0, 1. ; continuous slider 1 = midi controller # 8
                          ; controls wet/dry mix
   gkcs2  midic7 5,0, 1.  ; continuous slider 2 = midi controller # 5
   ;gkcs2  kpow  gkcs2, 2, .125 ; rescale exponentially 0 - 8
   gkcs2 = sqrt(gkcs2)    ; fudge for line above
   gkcs2 = gkcs2 * 8000
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
       out a1 
gaudio = gaudio + aglobal
       endin 
; =================================================================================
instr 16  ; global delay line instrument

   gkcs1     port  gkcs1, .02   ; smooth out abrupt changes in this controller
   gadeltime   interp  gkcs2  ; change k-rate cs2 value to a-rate with interpolation
   gkmod     port  gkmod, .02   ; smooth out abrupt changes
a1     vdelay gaudio + gafeedback , gadeltime, 8001
out a1  

gafeedback = (gkmod * a1)
gaudio = 0
gktest = 0
   ; do NOT do this : gkcs1 = 0  or gkcs2 = 0  or gkmod = 0
endin


</mono>
<stereo>


</stereo>
<quad>


</quad>
<score>
; default example  score
;  STRING PIZZ FUNCTIONS [cb, vc and vln]  
f1 0 0 -1  "/sflib/string/cb.p.c1"  0 0 0; ; dur = 2.35
f2 0 0 -1  "/sflib/string/cb.p.e1"  0 0 0; ; dur = 2.08
f3 0 0 -1  "/sflib/string/cb.p.gs1"  0 0 0; ; dur = 1.59
f4 0 0 -1  "/sflib/string/vc.p.c2"  0 0 0; ; dur = 3.251
f5 0 0 -1  "/sflib/string/vc.p.e2"  0 0 0; ; dur = 2.316
f6 0 0 -1  "/sflib/string/vc.p.gs2"  0 0 0; ; dur = 1.858
f7 0 0 -1  "/sflib/string/vc.p.c3"  0 0 0; ; dur = 2.287
f8 0 0 -1  "/sflib/string/vc.p.e3"  0 0 0; ; dur = 2.415
f9 0 0 -1  "/sflib/string/vc.p.gs3"  0 0 0; ; dur = .86
f10 0 0 -1  "/sflib/string/vc.p.c4"  0 0 0; ; dur = 1.928
f11 0 0 -1  "/sflib/string/vln.p.ds4"  0 0 0; ; dur =  .4
f12 0 0 -1  "/sflib/string/vln.p.g4"  0 0 0; ; dur =  .4
f13 0 0 -1  "/sflib/string/vln.p.b4"  0 0 0; ; dur =  .27
f14 0 0 -1  "/sflib/string/vln.p.ds5"  0 0 0; ; dur =  .25
f15 0 0 -1  "/sflib/string/vln.p.g5"  0 0 0; ; dur =  .36
f16 0 0 -1  "/sflib/string/vln.p.b5"  0 0 0; ; dur =  .33
f17 0 0 -1  "/sflib/string/vln.p.ds6"  0 0 0; ; dur =  .19
f18 0 0 -1  "/sflib/string/vln.p.g6"  0 0 0; ; dur =  .17

    ; f99 = soundfile function numbers & keymap split points
f99 0 128 -17 0 1 26 2 30 3 34 4 38 5 42 6 46 7 50 8 54 9 58 10 62
 11 66 12 69 13 73 14 77 15 81 16 85 17 89 18 ;
    ; f98 = midi note numbers for base key { soundfile at original pitch}
f98 0  32 -2 0 24 28 32 36 40 44 48 52 56 60 63 67 71 75 79 83 87 91;

f97 0 128 5 1 128 33               ;  veloc to non-linear amplitude
f96 0 128 5 .005 120 1. 128 1.     ;  brightness scaling for midisampbright
;   End of STRINGS PIZZ  functions  

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

</score>

