233 long nextTime = us + ticks2microsec(ticks[i] - ticks[i - 1],
234 tempos[i - 1], resolution);
235 if (nextTime > micros) {
236 break;
237 }
238 us = nextTime;
239 i++;
240 }
241 tick = ticks[i - 1] + microsec2ticks(micros - us, tempos[i - 1], resolution);
242 if (Printer.debug) Printer.debug("microsecond2tick(" + (micros / 1000)+") = "+tick+" ticks.");
243 //if (Printer.debug) Printer.debug(" -> convert back = " + (tick2microsecond(seq, tick, null) / 1000)+" microseconds");
244 }
245 cache.currTempo = tempos[i - 1];
246 return tick;
247 }
248
249
250 /**
251 * Binary search for the event indexes of the track
252 *
253 * @param tick - tick number of index to be found in array
254 * @return index in track which is on or after "tick".
255 * if no entries are found that follow after tick, track.size() is returned
256 */
257 public static int tick2index(Track track, long tick) {
258 int ret = 0;
259 if (tick > 0) {
260 int low = 0;
261 int high = track.size() - 1;
262 while (low < high) {
263 // take the middle event as estimate
264 ret = (low + high) >> 1;
265 // tick of estimate
266 long t = track.get(ret).getTick();
267 if (t == tick) {
268 break;
269 } else if (t < tick) {
270 // estimate too low
271 if (low == high - 1) {
272 // "or after tick"
273 ret++;
|
233 long nextTime = us + ticks2microsec(ticks[i] - ticks[i - 1],
234 tempos[i - 1], resolution);
235 if (nextTime > micros) {
236 break;
237 }
238 us = nextTime;
239 i++;
240 }
241 tick = ticks[i - 1] + microsec2ticks(micros - us, tempos[i - 1], resolution);
242 if (Printer.debug) Printer.debug("microsecond2tick(" + (micros / 1000)+") = "+tick+" ticks.");
243 //if (Printer.debug) Printer.debug(" -> convert back = " + (tick2microsecond(seq, tick, null) / 1000)+" microseconds");
244 }
245 cache.currTempo = tempos[i - 1];
246 return tick;
247 }
248
249
250 /**
251 * Binary search for the event indexes of the track
252 *
253 * @param tick tick number of index to be found in array
254 * @return index in track which is on or after "tick".
255 * if no entries are found that follow after tick, track.size() is returned
256 */
257 public static int tick2index(Track track, long tick) {
258 int ret = 0;
259 if (tick > 0) {
260 int low = 0;
261 int high = track.size() - 1;
262 while (low < high) {
263 // take the middle event as estimate
264 ret = (low + high) >> 1;
265 // tick of estimate
266 long t = track.get(ret).getTick();
267 if (t == tick) {
268 break;
269 } else if (t < tick) {
270 // estimate too low
271 if (low == high - 1) {
272 // "or after tick"
273 ret++;
|