you may also find it helpful to look at the code I used for Atomic Beats: https://github.com/billtg/Rhythm-Pattern