APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.media.sound

public final Class MidiUtils

extends Object
Class Inheritance
Imports
java.util.ArrayList, javax.sound.midi.InvalidMidiDataException, .MetaMessage, .MidiDevice, .MidiEvent, .MidiMessage, .Sequence, .Track

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
private
MidiUtils()

Suppresses default constructor, ensuring non-instantiability.

Method Summary

Modifier and TypeMethod and Description
public static void
checkSysexStatus(final byte[]
the system exclusive message data
data
,
final int
the length of the valid message data in the array
length
)

Checks the status byte for the system exclusive message.

public static void
checkSysexStatus(final int
the status byte for the message (0xF0 or 0xF7)
status
)

Checks the status byte for the system exclusive message.

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.

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

Given a microsecond time, convert to tick.

public static int

Returns:

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

Binary search for the event indexes of the track

public static long
tick2microsecond(Sequence seq, long tick, MidiUtils.TempoCache
tempo info and current tempo
cache
)

Given a tick, convert to microsecond

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

convert tick to microsecond with given tempo.

pack-priv static RuntimeException

Returns:

an exception instance
unsupportedDevice
(final MidiDevice.Info
an info object that describes the desired device
info
)

Returns an exception which should be thrown if MidiDevice is unsupported.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_TEMPO_MPQback to summary
public static final int DEFAULT_TEMPO_MPQ
META_END_OF_TRACK_TYPEback to summary
public static final int META_END_OF_TRACK_TYPE
META_TEMPO_TYPEback to summary
public static final int META_TEMPO_TYPE

Constructor Detail

MidiUtilsback to summary
private MidiUtils()

Suppresses default constructor, ensuring non-instantiability.

Method Detail

checkSysexStatusback to summary
public static void checkSysexStatus(final byte[] data, final int length) throws InvalidMidiDataException

Checks the status byte for the system exclusive message.

Parameters
data:byte[]

the system exclusive message data

length:int

the length of the valid message data in the array

Exceptions
InvalidMidiDataException:
if the status byte is invalid for a system exclusive message
checkSysexStatusback to summary
public static void checkSysexStatus(final int status) throws InvalidMidiDataException

Checks the status byte for the system exclusive message.

Parameters
status:int

the status byte for the message (0xF0 or 0xF7)

Exceptions
InvalidMidiDataException:
if the status byte is invalid for a system exclusive message
convertTempoback to summary
public static double convertTempo(double tempo)

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

getTempoMPQback to summary
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

isMetaEndOfTrackback to summary
public static boolean isMetaEndOfTrack(MidiMessage midiMsg)

return true if the passed message is Meta End Of Track

isMetaTempoback to summary
public static boolean isMetaTempo(MidiMessage midiMsg)

return if the given message is a meta tempo message

microsec2ticksback to summary
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!

microsecond2tickback to summary
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

tick2indexback to summary
public static int tick2index(Track track, long tick)

Binary search for the event indexes of the track

Parameters
tick:long

tick number of index to be found in array

Returns:int

index in track which is on or after "tick". if no entries are found that follow after tick, track.size() is returned

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

Given a tick, convert to microsecond

Parameters
cache:MidiUtils.TempoCache

tempo info and current tempo

ticks2microsecback to summary
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!

unsupportedDeviceback to summary
pack-priv static RuntimeException unsupportedDevice(final MidiDevice.Info info)

Returns an exception which should be thrown if MidiDevice is unsupported.

Parameters
info:MidiDevice.Info

an info object that describes the desired device

Returns:RuntimeException

an exception instance

com.sun.media.sound back to summary

public final Class MidiUtils.TempoCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
private boolean
pack-priv int
pack-priv int
pack-priv int[]
pack-priv long[]

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public int
pack-priv float
getTempoMPQAt(long tick)

pack-priv synchronized float
getTempoMPQAt(long tick, float startTempoMPQ)

public synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currTempoback to summary
pack-priv int currTempo
firstTempoIsFakeback to summary
private boolean firstTempoIsFake
snapshotIndexback to summary
pack-priv int snapshotIndex
snapshotMicroback to summary
pack-priv int snapshotMicro
temposback to summary
pack-priv int[] tempos
ticksback to summary
pack-priv long[] ticks

Constructor Detail

TempoCacheback to summary
public TempoCache()
TempoCacheback to summary
public TempoCache(Sequence seq)

Method Detail

getCurrTempoMPQback to summary
public int getCurrTempoMPQ()
getTempoMPQAtback to summary
pack-priv float getTempoMPQAt(long tick)
getTempoMPQAtback to summary
pack-priv synchronized float getTempoMPQAt(long tick, float startTempoMPQ)
refreshback to summary
public synchronized void refresh(Sequence seq)