Re: [Csnd] monophonic synths

massign 0, 1 ; all MIDI to instr 1

instr 1 ; triggered by MIDI notes
iNote notnum ; MIDI note number played
gkNote = iNote ; gkNote will always adopt the value of the most recently played note

iNumNotes active 1 ; outputs the number of notes currently being played by instr 1. i.e. if this is the first note, iNumNotes = 1
if iNumNotes==1 then ; if this is the first note of a sequence
event_i “i”, 2, 0, -1 ; event_i creates a score event at i-time. p3 = -1 means a ‘held’ note.
endif
endin

instr 2 ; synthesises audio (monophonic)
kNumNotes active 1 ; outputs the number of notes currently being played by instr 1. Notice that this time it is k-rate.
if kNumNotes==0 then
turnoff ; ‘turnoff’ turns off this note. It will allow release envelopes to complete, thereby preventing clicks.
endif

kRelease release ; this creates a release flag indicator as to whether this note is in it release stage or not. 0 = sustain, 1 = release

; maybe add some portamento to the note value
kPortTime linseg 0, 0.01, 0.03
if kRelease==0 then ; only update note while in the sustain portion of the note
kNote portk gkNote, kPortTime
endif

kEnv linsegr 0, 0.01, 1, 0.2, 0
aSig vco2 0.1 * kEnv, cpsmidinn(kNote), 4, 0.5
outs aSig, aSig
endin

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here