small suggestion; you may want to skip setting softcut.rec(voice, 0) at runtime, like here:
[ https://github.com/frederickk/b-b-b-b-beat/blob/primary/b-b-b-b-beat.lua#L119 ]
rec(0) will immediately disable the write heads for a voice, usually causing a click in the buffer, and rendering the following call to rec_level irrelevant. (whereas rec_level(voice, 0) applies smoothing, but should probably be accompanied by pre_level(voice, 1).)
using rec_level and pre_level alone during runtime is usually sufficient and produces less artifacts
(use rec() as a set-and-forget flag indicating to softcut that you do or do not want to use the voice for writing during the lifetime of the script or when transitioning to some mode where potential write-discontinuities are not a problem. i should obviously have named these functions better and softcut 2.0 will break the API to be less surprising.)