< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/MidiUtils.java
Print this page
*** 75,85 ****
// now get message and check for end of track
byte[] msg = midiMsg.getMessage();
return ((msg[1] & 0xFF) == META_END_OF_TRACK_TYPE) && (msg[2] == 0);
}
-
/** return if the given message is a meta tempo message */
public static boolean isMetaTempo(MidiMessage midiMsg) {
// first check if it is a META message at all
if (midiMsg.getLength() != 6
|| midiMsg.getStatus() != MetaMessage.META) {
--- 75,84 ----
*** 89,99 ****
byte[] msg = midiMsg.getMessage();
// meta type must be 0x51, and data length must be 3
return ((msg[1] & 0xFF) == META_TEMPO_TYPE) && (msg[2] == 3);
}
-
/** parses this message for a META tempo message and returns
* the tempo in MPQ, or -1 if this isn't a tempo message
*/
public static int getTempoMPQ(MidiMessage midiMsg) {
// first check if it is a META message at all
--- 88,97 ----
*** 109,119 ****
| ((msg[4] & 0xFF) << 8)
| ((msg[3] & 0xFF) << 16);
return tempo;
}
-
/**
* converts<br>
* 1 - MPQ-Tempo to BPM tempo<br>
* 2 - BPM tempo to MPQ tempo<br>
*/
--- 107,116 ----
*** 122,132 ****
tempo = 1;
}
return ((double) 60000000l) / tempo;
}
-
/**
* convert tick to microsecond with given tempo.
* Does not take tempo changes into account.
* Does not work for SMPTE timing!
*/
--- 119,128 ----
*** 143,153 ****
// do not round to nearest tick
//return (long) Math.round((((double)us) * resolution) / tempoMPQ);
return (long) ((((double)us) * resolution) / tempoMPQ);
}
-
/**
* Given a tick, convert to microsecond
* @param cache tempo info and current tempo
*/
public static long tick2microsecond(Sequence seq, long tick, TempoCache cache) {
--- 139,148 ----
*** 244,254 ****
}
cache.currTempo = tempos[i - 1];
return tick;
}
-
/**
* Binary search for the event indexes of the track
*
* @param tick tick number of index to be found in array
* @return index in track which is on or after "tick".
--- 239,248 ----
*** 281,291 ****
}
}
return ret;
}
-
public static final class TempoCache {
long[] ticks;
int[] tempos; // in MPQ
// index in ticks/tempos at the snapshot
int snapshotIndex = 0;
--- 275,284 ----
*** 308,318 ****
public TempoCache(Sequence seq) {
this();
refresh(seq);
}
-
public synchronized void refresh(Sequence seq) {
ArrayList<MidiEvent> list = new ArrayList<>();
Track[] tracks = seq.getTracks();
if (tracks.length > 0) {
// tempo events only occur in track 0
--- 301,310 ----
*** 371,378 ****
return (float) tempos[i];
}
}
return tempos[tempos.length - 1];
}
-
}
}
--- 363,369 ----
< prev index next >