Super quick summary:
* Every time an instrument is triggered to perform it will run an initial init-pass, followed by a succession of k-passes. There will be
sr/ksmps k-cycles each second.
* All variables get set to an initial value during the init pass, even k-rate variables.
* After the init pass only k and a variables can be updated.
* To find the initial value of a k-rate variable during the init pass cast the variable to i(), i.e,
Testing the values of variables:
If you wish to test variables during the init pass, test i-rate variables or cast your k variable to i-rate (see above). if-statements testing k-rate variables are only effective during k-cycles, i.e, all cycles after the init pass. For example, this instrument will print hello the first time it is run:
k1 init 10
if k1 == 0 then
It looks like the value of k1 is set to 10, yet the test returns true when asked if k1 is equal to 0. k1 is indeed set to 10, but the k-rate test will fail during the init pass and result in fall-through. However, if we test
i(k1), it won't print "Hello", because the initial value of k1 is set to 10.
Sorry I don't have time to go into much more details. Feel free to query any of this. It's really a subject of much confusion for anyone starting Csound!