<info>
ESM Csound Library instrument algorithm ccsampvib :
midiins algorithm : ccsampvib
Default score file includes the "sop2" functions
(long soprano tones sung softly).
Move the foot pedal before playing or you will get no sound.
CS1 controls vibrato depth (+/- 1/4 tone)
CS2 controls vibrato rate (0 - 10 hz.)
Mod wheel has no effect.
Allan Schindler  1/97
</info>
<tk_interface>


</tk_interface>
<mono>
; instrument algorithm ccsampvib -- sampler with vibrato
gktest init 0

	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  ; note num + pitch bend 1 semitone range
; I would like
; koct  octmidib 2 ; but octmidib currently is broken, so
koct =  octcps(kcps)

;  ====== MIDI continuous controllers on MCS2:  ========================
        ; mod wheel =   controller 01 ;controls init. phase of vib. osc.
        ; Foot controllers Sliders:
        ; fc2       =   controller # 07    Amplitude (volume)
        ; fc1       =   controller # 04    Not used
        ; Continuous Sliders:
        ; cs1       =   controller # 08    Vibrato depth
        ; cs2       =   controller # 05    Vibrato rate
      
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)

; VIBRATO : time varying depth & rate
         ; continuous sliders 1 & 2 on MCS2 :
   gkcs1  midic7 8, 0, .008  ; continuous slider 1 = midi controller # 8
                               ; vibrato depth
   gkcs2  midic7 5, 0 , 12.  ; continuous slider 2 = midi controller # 5
                                 ; vibrato rate 0 - 10.
   gkcs2    port  gkcs2, .01   ; smooth out abrupt changes in this controller
  ; starting phase of vibrato oscillator
   iphase  imidic7 1, 0, 1  ;
 if iphase < .96 igoto gotcontrollers
     iphase = rnd(1.) ; if mod wheel all the way up, random phase

gotcontrollers:

kvib    oscil gkcs1, gkcs2 , 100 ,iphase ; sine wave vibrato LFO
koct = koct + (kvib * koct)
;   ===========  end of MCS2 continuous controller inputs =======================

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

; ====== Clavinola pedals, used as 3 foot switches : ===============================
    ; 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:
;  ======= end of Clavinola foot pedal switch controller input ================

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

kamp2   port  gkfc2, .08   ; smooth out abrupt changes 
a1	loscil	kamp * kamp2, cpsoct(koct) , ifno, cpsoct(ibasoct)
 out a1
endin
instr 16  ; global instrument
        ; in this algorithm, the only function of this global instrument
        ; is to zero out the gktest variable of the above instrument
        ; the actual global variables {gkfc2, gkcs1, gkcs2 etc.} should NOT be zeroed
gktest  =  0
endin

</mono>
<stereo>


</stereo>
<quad>


</quad>
<score>
; default score
;  sop2 {soprano, long tones sung softly }function tables  
f1 0 0 -1  "/sflib/voice/sop2.a3"   0 0 0; dur = 5.17
f2 0 0 -1  "/sflib/voice/sop2.cs4"  0 0 0; ; dur = 5.39
f3 0 0 -1  "/sflib/voice/sop2.e4"   0 0 0; ; dur = 4.59
f4 0 0 -1  "/sflib/voice/sop2.g4"   0 0 0; ; dur = 4.22
f5 0 0 -1  "/sflib/voice/sop2.a4"   0 0 0; ; dur = 4.34
f6 0 0 -1  "/sflib/voice/sop2.cs5"  0 0 0; ; dur = 4.59
f7 0 0 -1  "/sflib/voice/sop2.e5"   0 0 0; ; dur = 3.648
f8 0 0 -1  "/sflib/voice/sop2.g5"   0 0 0; ; dur = 4.56
f9 0 0 -1  "/sflib/voice/sop2.a5"   0 0 0; ; dur = 3.996

    ; f99 = soundfile function numbers & keymap split points
f99 0 128 -17 0 1 59 2 63 3 66 4 68 5 71 6 75 7 77 8 80 9 ;
    ; f98 = midi note numbers for base key { soundfile at original pitch}
f98 0  16  -2 0 57 61 64 67 69 73 76 79 81 ;

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 SOP2 functions ---------
f100 0 1024 10 1.       ; sine wave control function
 
f0 300 
i16 0.000 300
e 

</score>

