Hi!
I have also been able to reproduce it after simplifying a little your
example, changing i1 like this:
instr i1 () {
imports exports table cyc1;
asig a1;
ivar attack;
ivar release;
ivar sustain;
ksig env;
attack = dur/2;
release = dur/2;
sustain = 0;
env = kline(0, attack, 1, sustain, 1, release, 0);
a1 = env*oscil(cyc1, 440);
output(a1);
}
Initially I also thought it was a bug, but after looking more
carefully, I think that this behaviour is the right one. Consider
these:
- The first instrument instantiation takes place BEFORE the first
tempo line is executed. This is consistent with the SAOL
specification.
- attack, release and sustain are initialized during this
instantiation. They are ivar signals, so they wont change their
value. Your initial tempo line has not yet been executed, so dur
will be set acording to the default tempo (60 beats/second)
- After your tempo change takes place, i1 dur variable gets updated
(or should be, acording to the standard), but your asignments to
attack, release, and sustain are not being executed any more.
So it seems you have hit a limitation in kline (and other signal
generators) rather than a bug: kline arguments are ivars, so you can
not change your envelope configuration during instrument execution.
In this particular example, you can do an easy workaround by
instantiatin your first instrument a bit latter than 0.0 segs, so that
the tempo line is executed first:
0.1 i1 1
2.1 i1 1
4.1 i1 1
0 tempo 100
This works, but it would stop working if you send tempo changes in the
middle of an instrument execution:
0.1 i1 1
2.1 i1 1
4.1 i1 1
0 tempo 100
0.5 tempo 200
A better approach would be to implement your own k-rate envelope
generator, so you can do tempo changes during instrument executions,
and get the proper envelope applied.
Please let me know if you think that this explanation is
wrong. I may also be missing something.
Thanks,
Enrique.