getting it in time with the music is about knowing what your tempo is and then working out
- how long a beat is in ms (milliseconds or thousandths of a second), and
- then dialing in the required time based on that basic information
For example if your tempo is 120bpm then your beat is 500ms long (if we accept that you are using the quarter note (crotchet) as the beat and that your time signature/meter is 4/4)
An 8th note delay would be 250ms
A 16th note delay would be 125ms
A 32nd note delay would be 62.5ms
Here is a tempo/delay time calculators that you can use
BPM to Milliseconds Calculator. It allows you to set the minim/half-note, crotchet/quareter-note,quaver/8th-note as the basic beat value and then will calculate several different delay times based on different rhythmic ideas