I have a midi editor app in Java swing that can play back the loaded music. The resolution (ticks per quarter note value) can vary from 24 to 1000, with most midi files being in the higher range. I implemented a feature where the user can set the playback tempo in quarter beats per minute. The program varies the speed of the playback by calculating the Swing timer delay using
where BPM and resolution are the variables. Basically, the function just looks like y = 1/x, fixing a value for BPM. However, the Swing timer delay is an int value in milliseconds. For higher resolutions, the delay always rounds to 1 regardless of the BPM due to the nature of the function.
What is the best solution so that I can play back the music at a roughly accurate speed? Would I need to just use a faster timer? If so, what are the options? Should I write some logic that moves forward x midi ticks every timer tick instead of 1 to work around the Swing timer's limitations?