; A monophonic legato instrument, playable from a MIDI keyboard.
; By Jim Aikin, based on a method suggested by Victor Lazzarini.
sr = 44100
ksmps = 4
nchnls = 2
0dbfs = 1
alwayson "ToneGenerator"
giSaw ftgen 0, 0, 8192, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
gkCheck init 0
gkPitch init 260
instr 1 ; activated from MIDI channel 1, tracks the pitch
gkPitch cpsmidib 2
gkCheck = 1
endin
instr ToneGenerator
kon active 1 ; check whether any instances of instr 1 are active
; velocity sensing -- only accept a new velocity input if
; there's no note overlap (if kon == 1) -- scale the velocity
; to a range of 0.2 - 1.0
kvel init 0
kstatus, kchan, kdata1, kdata2 midiin
if kstatus == 144 && kdata2 != 0 && kon == 1 then
kvel = kdata2 * 0.006 + 0.2
endif
katt invalue "att"
krel invalue "rel"
; amplitude control
kampraw init 0
if kon != 0 then
kampraw = 0.5 * kvel
kenvramp = katt ; 50 = fast attack
else
kampraw = 0
kenvramp = krel ; 1 = slow release
endif
kamp tonek kampraw, kenvramp
kpitchglide invalue "pitchglide"
ipitchglide = 4 ; higher numbers cause faster glide
kpitch tonek gkPitch, kpitchglide
; oscillators
idetune = 0.3
asig1 oscil kamp, kpitch + idetune, giSaw
asig2 oscil kamp, kpitch, giSaw
asig3 oscil kamp, kpitch - idetune, giSaw
asig = asig1 + asig2 + asig3
; if no MIDI keys are pressed, reinit the filter envelope
if gkCheck == 1 && kon == 0 then
reinit filtenv
endif
ifiltdec1 = 1.5
ifiltdec2 = 3
filtenv:
kfilt expseg 500, 0.01, 8000, ifiltdec1, 2000, ifiltdec2, 500, 1, 500
rireturn
; smooth the filter envelope so a reinit won't cause it to jump --
; also have the cutoff track the keyboard and velocity
kfilt tonek (kfilt * (0.6 + kvel * 0.5)) + kpitch, kenvramp
afilt lpf18 asig, kfilt, 0.3, 0.1
outs afilt, afilt
endin
e 3600
198
290
352
212
true
85
170
127
att
60
49
20
100
{d9bc8180-98f8-400a-978c-9bedbbee8c34}
true
0
0
1.00000000
80.00000000
1.00000000
lin
continuous
-1.00000000
false
29
147
80
25
{e887fef3-be7e-47c6-b2d5-ef5761197823}
true
0
0
center
Arial
10
3
0
0
0
255
255
255
noborder
1
1
rel
117
49
20
100
{1b8f2ec1-d0d8-4f4f-905e-cc302929c6c5}
true
0
0
1.00000000
50.00000000
47.06000000
lin
continuous
-1.00000000
false
86
147
80
25
{695caaa8-f252-4487-8e9b-97cd19647a41}
true
0
0
center
Arial
10
3
0
0
0
255
255
255
noborder
1
1
248
128
80
25
{1602d8a5-715e-4794-9c95-29d8487b60de}
true
0
0
left
Arial
10
3
0
0
0
255
255
255
noborder
1
1
247
49
80
25
{c2aa0e27-472b-4b75-ba40-2537fe6d3082}
true
0
0
left
Arial
10
3
0
0
0
255
255
255
noborder
1
1
257
72
10
60
{158e8a3a-a4e1-4bc2-b32e-017d6b7109c1}
true
0
0
left
Arial
10
3
0
0
0
0
0
0
border
1
1
pitchglide
195
49
20
100
{dc0d7428-b329-44e8-afb4-b76a0b5b734c}
true
0
0
1.00000000
50.00000000
16.68000000
lin
continuous
-1.00000000
false
164
147
80
25
{73ffdd1b-bc20-4c21-8442-35b5c04dba11}
true
0
0
center
Arial
10
3
0
0
0
255
255
255
noborder
1
1
Version: 3
Render: Real
Ask: Yes
Functions: ioObject
Listing: Window
WindowBounds: 72 179 400 200
CurrentView: io
IOViewEdit: On
Options:
ioView background {21845, 43690, 32639}
ioSlider {60, 49} {20, 100} 1.000000 80.000000 1.000000 att
ioText {176, 172} {80, 25} label 0.000000 0.00100 "" center "Arial" 10 {0, 0, 0} {61440, 60160, 57856} nobackground noborder Attack
ioSlider {117, 49} {20, 100} 1.000000 50.000000 47.060000 rel
ioText {225, 164} {80, 25} label 0.000000 0.00100 "" center "Arial" 10 {0, 0, 0} {61440, 60160, 57856} nobackground noborder Release
ioText {199, 116} {80, 25} label 0.000000 0.00100 "" left "Arial" 10 {0, 0, 0} {61440, 60160, 57856} nobackground noborder Slow
ioText {173, 35} {80, 25} label 0.000000 0.00100 "" left "Arial" 10 {0, 0, 0} {61440, 60160, 57856} nobackground noborder Fast
ioText {183, 56} {10, 60} label 0.000000 0.00100 "" left "Arial" 10 {0, 0, 0} {0, 0, 0} nobackground noborder
ioSlider {195, 49} {20, 100} 1.000000 50.000000 16.680000 pitchglide
ioText {164, 147} {80, 25} label 0.000000 0.00100 "" center "Arial" 10 {0, 0, 0} {61440, 60160, 57856} nobackground noborder Glide