<info>
ESM Csound Library instrument algorithm: midisamp 
Mono or stereo inputs/output.
If the channels argument in the main window is set to "1,"
mono soundfiles must be read in, and the output also will
be monophonic. The default score file in this module includes
a monophonic set of "vln" (violin) soundfiles from the sflib/string
directory.
Stereo modules require stereo input soundfiles. See example
module "midisamp.winds" in the MORE_EX subdirectory.
For a list of currently available Library input soundfile
function definition sets, type "lsmidifuncs."
To create a score file for this algorithm incorporating one
of these function sets, run the "gemidiscore" command
in a shell window.
Like all of the MIDI algorithms in this directory, "midisamp"
currently can only be run in real-time play mode.
Do not attempt to write a soundfile with this algorithm, as this
will create a very large silent soundfile.
Allan Schindler  1/97
</info>
<tk_interface>


</tk_interface>
<mono>
; instrument algorithm midisamp -- after Vercoe
	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 :
     ; midictrl opcodes obsolete as of Csond 3.48
     ; these two lines & other midictrl lines below changed to imidic7
     ; by A.S. on 10/28/98
     ; isust  midictrl  64 
     ;idecay = (isust = 0 ? .2 : .4 * isust )  ; "fade-out" time after key released
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, icps , ifno, cpsoct(ibasoct)
       out a1 
       endin 
    
</mono>
<stereo>
; instrument algorithm midisamp -- after Vercoe
	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 :
     ; midictrl opcodes obsolete as of Csond 3.48
     ; these two lines & other midictrl lines below changed to imidic7
     ; by A.S. on 10/28/98
     ; isust  midictrl  64 
     ;idecay = (isust = 0 ? .2 : .4 * isust )  ; "fade-out" time after key released
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,a2	loscil	kamp, icps , ifno, cpsoct(ibasoct)
       endin 

</stereo>
<quad>


</quad>
<score>
;  VLN ARCO ORD. function tables 
f1 0 0 -1  "/sflib/string/vln.g3"  0 0 0; ; dur = 3.8
f2 0 0 -1  "/sflib/string/vln.b3"  0 0 0; dur = 3.58
f3 0 0 -1  "/sflib/string/vln.ds4"  0 0 0; dur = 3.61
f4 0 0 -1  "/sflib/string/vln.g4"  0 0 0; dur = 3.8
f5 0 0 -1  "/sflib/string/vln.b4"  0 0 0; dur = 3.31
f6 0 0 -1  "/sflib/string/vln.ds5"  0 0 0; dur = 2.85
f7 0 0 -1  "/sflib/string/vln.g5"  0 0 0; dur = 3.65
f8 0 0 -1  "/sflib/string/vln.b5"  0 0 0; dur = 2.85
f9 0 0 -1  "/sflib/string/vln.ds6"  0 0 0; dur = 2.9
f10 0 0 -1 "/sflib/string/vln.g6"  0 0 0; dur = 2.91
f11 0 0 -1 "/sflib/string/vln.c7"  0 0 0; dur = 3.34
  
    ; f99 = soundfile function numbers & keymap split points
f99 0 128 -17 0 1 57 2 61 3 65 4 69 5 73 6 77 7 81 8 85 9 89 10 93 11
    ; f98 = midi note numbers for base key { soundfile at original pitch}
f98 0  16  -2 0 55 59 63 67 71 75 79 83 87 91 96 

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 VLN Arco Ord. functions ---------
 
f0 300 
e 

</score>

