libmid: calculate ticks correctly