I am in the process of making a program similar to SonicPI, in which will allow me to programmatically make music. I have made the sound and file reading logic, but I am stuck on figuring out how to manage the playback timing (BPM): If the user inputs this, and the BPM is 120: thread () { loop (4) { play(piano.wav, C4, 1); } } thread () { loop (4) { play(click.wav, C4, 2); } } It should play a piano note every beat, and a click sound every second beat. I was originally using Thread.Sleep and a few calculations, but it is very out of sync when threads are brought into the mix. Any help would be brilliant