form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
keyboard bounds(8, 158, 381, 95)
button bounds(16, 10, 80, 40), text("Write to table"), channel("write")
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
; simple UDO that will write the incoming audio stream
; to a function table when triggered..
opcode TableWrite, 0, akii
aSig, kTrig, iTableSize, iTableNum xin
kCnt init 0
setksmps 1
kSig = aSig
if changed(kTrig) == 1 then
printks "Sampling again", 0
kCnt = 0
endif
if kCnt < iTableSize then
tablew kSig, kCnt, iTableNum
printk2 kSig
kCnt +=1
endif
endop
; always playing instrument. Pressing the "Write to table" button
; will write 4096 samples to function table 1
instr 200
p3 = filelen("pianoMood.wav")
a1, a2 diskin2 "pianoMood.wav", 1, 0, 1
TableWrite a1, chnget:k("write"), 4096, 1
endin
;instrument will be triggered by keyboard widget
instr 1
kEnv madsr .1, .2, .6, .4
aFade oscili 1, p4, 99
a1 oscili p5*aFade, p4, 1
outs a1, a1
endin
; table that samples are written to..
f1 0 4096 7 0
; table to apply fade to samples
f99 0 4096 7 0 48 1 4000 1 48 0
i200 0 z
f0 z