I’m testing a midi-instrument doing a sequence of notes while
triggered by a midi note.
Although the code is very straightforward I can’t make it loop while the midi note is pressed.
The loop should be going in a ‘until condition do’ construction, but fails to do so. Testing on kEnd release == 1, or midinoteoff key, key == currentkey doesn’t seem to do nothing at all.
I suppose it’s something very basic that I’m forgetting, but it is annoying. I tried to make it work for a couple of days now without any success.
My code is as follows:
sr = 44100
ksmps = 8
nchnls = 2
0dbfs = 1
giSine ftgen 0, 0 , 2048, 10, 1, 0, .5, 0, -.25, 0, .125, 0, - 0.0625
massign 0, “arpeggiator”
instr arpeggiator
iNoteNr notnum
kEnd release ; should return 1 when the key is released
kkey init 0 ; initializing k-values for midinoteoff
kvel init 0
midinoteoff kkey, kvel ;kkey should return the current, running midinote
ipch1 cpsmidinn iNoteNr
ipch2 cpsmidinn iNoteNr - 1
ipch3 cpsmidinn iNoteNr - 2
ipch4 cpsmidinn iNoteNr - 3
iamp ampmidi .6
iNoteDur = 0.26
until kkey == iNoteNr do
; Or until kEnd == 1 do
schedule "playNote", 0, iNoteDur, ipch1, 0.6
schedule "playNote", 0.25, iNoteDur, ipch2, 0.4
schedule "playNote", 0.5, iNoteDur, ipch3, 0.4
schedule "playNote", 0.75, iNoteDur, ipch4, 0.5
schedule "playNote", 1.0, iNoteDur,ipch3, 0.4
schedule "playNote", 1.25, iNoteDur, ipch2, 0.4
od
endin
instr playNote
iDur = p3
iPitch = p4
iAmp = p5
aEnv adsr p30.05, p30.5, 0.5, p3*0.45
aMid poscil iAmpaEnv, iPitch, giSine
aLft poscil iAmpaEnv, iPitch1.03, giSine
aRgt poscil iAmpaEnv, iPitch*0.97, giSine
aLeft = (aMid + aLft) /2
aRight = (aMid + aRgt)/2
outs aLeft, aRight
endin