no they always work, and extend the duration of a event. you can try
with this code:
instr Try
aSound = poscil:a(.2,400)
aOut = linenr:a(aSound,.1,3,.01)
outall(aOut)
endin
schedule(“Try”,0,1)
you will hear a tone of one second plus three seconds fade-out.
but i think the question in your code is about the architecture. if i
get it right, you want to be able to toggle a tone via the computer
keyboard. so linenr will not help, as it only adds one release segment
at the end of the whole note, but not during this event.
i think you have two options:
- you soften the transitions between the rapid changes of either 0 or 1
by an interpolating opcode. for instance with lag:
instr 1
krel init 1
kenv linen 1, 0.01, p3 ,0.5
kKey, kDown sensekey
if (kDown == 1 && kKey == 49) then
krel = 0
endif
kinterp lag krel,0.1
aSound poscil 0.5, 400
outall aSoundkenvkinterp
endin
schedule(1,0,99)
you can also implement a constant toggle with this approach:
instr 1
ktoggle init 1
kenv linen 1, 0.01, p3 ,0.5
kKey, kDown sensekey
if (kDown == 1 && kKey == 49) then
ktoggle = 1-ktoggle
endif
kinterp lag ktoggle,0.1
aSound poscil 0.5, 400
outall aSoundkenvkinterp
endin
schedule(1,0,99)
- you separate both jobs in two instruments: one instrument is for
turning on and off, the other one is producing the sound. in this
approach you can then use linenr:
instr Control
ktoggle init 1
kKey, kDown sensekey
if (kDown == 1 && kKey == 49) then
if (ktoggle == 1) then
turnoff2 “Tone”,0,1
else
schedulek(“Tone”,0,99)
endif
ktoggle = 1-ktoggle
endif
endin
schedule(“Control”,0,99)
instr Tone
kenv linenr 1, 0.01, .1 ,0.01
aSound poscil 0.5, 400
outall aSound*kenv
endin
schedule(“Tone”,0,99)
i think for your case solution 1 is better (more simple). but i think
it is good to know that we can always separate the jobs between two
instruments. in many cases this solves problems and the code reflects
more about what happens as interaction.
best -
joachim