public class

MidiUtils

extends Object
java.lang.Object
   ↳ com.sun.media.sound.MidiUtils

Class Overview

Some utilities for MIDI (some stuff is used from javax.sound.midi)

Summary

Nested Classes
class MidiUtils.TempoCache  
Constants
int DEFAULT_TEMPO_MPQ
int META_END_OF_TRACK_TYPE
int META_TEMPO_TYPE
Public Constructors
MidiUtils()
Public Methods
static double convertTempo(double tempo)
converts
1 - MPQ-Tempo to BPM tempo
2 - BPM tempo to MPQ tempo
static int getTempoMPQ(MidiMessage midiMsg)
parses this message for a META tempo message and returns the tempo in MPQ, or -1 if this isn't a tempo message
static boolean isMetaEndOfTrack(MidiMessage midiMsg)
return true if the passed message is Meta End Of Track
static boolean isMetaTempo(MidiMessage midiMsg)
return if the given message is a meta tempo message
static long microsec2ticks(long us, double tempoMPQ, int resolution)
convert tempo to microsecond with given tempo Does not take tempo changes into account.
static long microsecond2tick(Sequence seq, long micros, MidiUtils.TempoCache cache)
Given a microsecond time, convert to tick.
static int tick2index(Track track, long tick)
Binary search for the event indexes of the track
static long tick2microsecond(Sequence seq, long tick, MidiUtils.TempoCache cache)
Given a tick, convert to microsecond
static long ticks2microsec(long tick, double tempoMPQ, int resolution)
convert tick to microsecond with given tempo.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_TEMPO_MPQ

Constant Value: 500000 (0x0007a120)

public static final int META_END_OF_TRACK_TYPE

Constant Value: 47 (0x0000002f)

public static final int META_TEMPO_TYPE

Constant Value: 81 (0x00000051)

Public Constructors

public MidiUtils ()

Public Methods

public static double convertTempo (double tempo)

converts
1 - MPQ-Tempo to BPM tempo
2 - BPM tempo to MPQ tempo

public static int getTempoMPQ (MidiMessage midiMsg)

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 boolean isMetaEndOfTrack (MidiMessage midiMsg)

return true if the passed message is Meta End Of Track

public static boolean isMetaTempo (MidiMessage midiMsg)

return if the given message is a meta tempo message

public static long microsec2ticks (long us, double tempoMPQ, int resolution)

convert tempo to microsecond with given tempo Does not take tempo changes into account. Does not work for SMPTE timing!

public static long microsecond2tick (Sequence seq, long micros, MidiUtils.TempoCache cache)

Given a microsecond time, convert to tick. returns tempo at the given time in cache.getCurrTempoMPQ

public static int tick2index (Track track, long tick)

Binary search for the event indexes of the track

Parameters
tick - tick number of index to be found in array
Returns
  • index in track which is on or after "tick". if no entries are found that follow after tick, track.size() is returned

public static long tick2microsecond (Sequence seq, long tick, MidiUtils.TempoCache cache)

Given a tick, convert to microsecond

Parameters
cache tempo info and current tempo

public static long ticks2microsec (long tick, double tempoMPQ, int resolution)

convert tick to microsecond with given tempo. Does not take tempo changes into account. Does not work for SMPTE timing!