What’s tricky about this is the fact that the host will process a block of sample at a time. And within that block it will schedule any MIDI event that need to take place at some point within that block, for example it might schedule a midi note one to take place 18 samples in. Any of the playhead info you retrieve will only be available once per block. TIME_IN_SAMPLES
will give you the best resolution clock, but it will also jump by ksmps on each k-cycle. You could also use IS_PLAYING
to determine when an instrument starts, and construct your own timer within Csound, but keep in mind, this info will also be restricted to a block boundary. If the user somehow presses play in the middle of the a processing block, you won’t get that info until the next k cycle. In practical terms the maximum delay is about 4ms. It’s all about finding the best balance I guess.
If you really need sample accurate timing* within Cabbage, you’ll need to set ksmps to 1.
- MIDI events are sample accurate - the playhead info is not…