APIdia Launch Partner
Top Description Fields Constructors Methods
javax.sound.midi

public Class MidiFileFormat

extends Object
Class Inheritance
Imports
java.util.Collections, .HashMap, .Map

A MidiFileFormat object encapsulates a MIDI file's type, as well as its length and timing information.

A MidiFileFormat object can include a set of properties. A property is a pair of key and value: the key is of type String, the associated property value is an arbitrary object. Properties specify additional informational meta data (like a author, or copyright). Properties are optional information, and file reader and file writer implementations are not required to provide or recognize properties.

The following table lists some common properties that should be used in implementations:

MIDI File Format Properties
Property key Value type Description
"author" String name of the author of this file
"title" String title of this file
"copyright" String copyright message
"date" Date date of the recording or release
"comment" String an arbitrary text
Authors
Kara Kytle, Florian Bomers
See Also
MidiSystem#getMidiFileFormat(java.io.File), Sequencer#setSequence(java.io.InputStream stream)

Field Summary

Modifier and TypeField and Description
protected int
byteLength

The length of the MIDI file in bytes.

protected float
divisionType

The division type of the MIDI file.

protected long
microsecondLength

The duration of the MIDI file in microseconds.

private HashMap<String, Object>
properties

The set of properties.

protected int
resolution

The timing resolution of the MIDI file.

protected int
type

The type of MIDI file.

public static final int
UNKNOWN_LENGTH

Represents unknown length.

Constructor Summary

AccessConstructor and Description
public
MidiFileFormat(int
the MIDI file type (0, 1, or 2)
type
,
float
the timing division type (PPQ or one of the SMPTE types)
divisionType
,
int
the timing resolution
resolution
,
int
the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known
bytes
,
long
the duration of the file in microseconds, or UNKNOWN_LENGTH if not known
microseconds
)

Constructs a MidiFileFormat.

public
MidiFileFormat(int
the MIDI file type (0, 1, or 2)
type
,
float
the timing division type (PPQ or one of the SMPTE types)
divisionType
,
int
the timing resolution
resolution
,
int
the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known
bytes
,
long
the duration of the file in microseconds, or UNKNOWN_LENGTH if not known
microseconds
,
Map<String, Object>
a Map<String,Object> object with properties
properties
)

Construct a MidiFileFormat with a set of properties.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of bytes in the file, or UNKNOWN_LENGTH if not known
getByteLength
()

Obtains the length of the MIDI file, expressed in 8-bit bytes.

public float

Returns:

the division type (PPQ or one of the SMPTE types)
getDivisionType
()

Obtains the timing division type for the MIDI file.

public long

Returns:

the file's duration in microseconds, or UNKNOWN_LENGTH if not known
getMicrosecondLength
()

Obtains the length of the MIDI file, expressed in microseconds.

public Object

Returns:

the value of the property with the specified key, or null if the property does not exist
getProperty
(String
the key of the desired property
key
)

Obtain the property value specified by the key.

public int

Returns:

the number of ticks per beat (PPQ) or per frame (SMPTE)
getResolution
()

Obtains the timing resolution for the MIDI file.

public int

Returns:

the file's type (0, 1, or 2)
getType
()

Obtains the MIDI file type.

public Map<String, Object>

Returns:

a Map<String,Object> object containing all properties. If no properties are recognized, an empty map is returned.
properties
()

Obtain an unmodifiable map of properties.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

byteLengthback to summary
protected int byteLength

The length of the MIDI file in bytes.

divisionTypeback to summary
protected float divisionType

The division type of the MIDI file.

See Also
Sequence#PPQ, Sequence#SMPTE_24, Sequence#SMPTE_25, Sequence#SMPTE_30DROP, Sequence#SMPTE_30
microsecondLengthback to summary
protected long microsecondLength

The duration of the MIDI file in microseconds.

propertiesback to summary
private HashMap<String, Object> properties

The set of properties.

resolutionback to summary
protected int resolution

The timing resolution of the MIDI file.

typeback to summary
protected int type

The type of MIDI file.

UNKNOWN_LENGTHback to summary
public static final int UNKNOWN_LENGTH

Represents unknown length.

See Also
getByteLength, getMicrosecondLength

Constructor Detail

MidiFileFormatback to summary
public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds)

Constructs a MidiFileFormat.

Parameters
type:int

the MIDI file type (0, 1, or 2)

divisionType:float

the timing division type (PPQ or one of the SMPTE types)

resolution:int

the timing resolution

bytes:int

the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known

microseconds:long

the duration of the file in microseconds, or UNKNOWN_LENGTH if not known

See Also
UNKNOWN_LENGTH, Sequence#PPQ, Sequence#SMPTE_24, Sequence#SMPTE_25, Sequence#SMPTE_30DROP, Sequence#SMPTE_30
MidiFileFormatback to summary
public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds, Map<String, Object> properties)

Construct a MidiFileFormat with a set of properties.

Parameters
type:int

the MIDI file type (0, 1, or 2)

divisionType:float

the timing division type (PPQ or one of the SMPTE types)

resolution:int

the timing resolution

bytes:int

the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known

microseconds:long

the duration of the file in microseconds, or UNKNOWN_LENGTH if not known

properties:Map<String, Object>

a Map<String,Object> object with properties

Since
1.5
See Also
UNKNOWN_LENGTH, Sequence#PPQ, Sequence#SMPTE_24, Sequence#SMPTE_25, Sequence#SMPTE_30DROP, Sequence#SMPTE_30

Method Detail

getByteLengthback to summary
public int getByteLength()

Obtains the length of the MIDI file, expressed in 8-bit bytes.

Returns:int

the number of bytes in the file, or UNKNOWN_LENGTH if not known

See Also
UNKNOWN_LENGTH
getDivisionTypeback to summary
public float getDivisionType()

Obtains the timing division type for the MIDI file.

Returns:float

the division type (PPQ or one of the SMPTE types)

See Also
Sequence#Sequence(float, int), Sequence#PPQ, Sequence#SMPTE_24, Sequence#SMPTE_25, Sequence#SMPTE_30DROP, Sequence#SMPTE_30, Sequence#getDivisionType()
getMicrosecondLengthback to summary
public long getMicrosecondLength()

Obtains the length of the MIDI file, expressed in microseconds.

Returns:long

the file's duration in microseconds, or UNKNOWN_LENGTH if not known

See Also
Sequence#getMicrosecondLength(), getByteLength, UNKNOWN_LENGTH
getPropertyback to summary
public Object getProperty(String key)

Obtain the property value specified by the key. The concept of properties is further explained in the class description.

If the specified property is not defined for a particular file format, this method returns null.

Parameters
key:String

the key of the desired property

Returns:Object

the value of the property with the specified key, or null if the property does not exist

Since
1.5
See Also
properties()
getResolutionback to summary
public int getResolution()

Obtains the timing resolution for the MIDI file. If the division type is PPQ, the resolution is specified in ticks per beat. For SMPTE timing, the resolution is specified in ticks per frame.

Returns:int

the number of ticks per beat (PPQ) or per frame (SMPTE)

See Also
getDivisionType, Sequence#getResolution()
getTypeback to summary
public int getType()

Obtains the MIDI file type.

Returns:int

the file's type (0, 1, or 2)

propertiesback to summary
public Map<String, Object> properties()

Obtain an unmodifiable map of properties. The concept of properties is further explained in the class description.

Returns:Map<String, Object>

a Map<String,Object> object containing all properties. If no properties are recognized, an empty map is returned.

Annotations
@SuppressWarnings:unchecked
Since
1.5
See Also
getProperty(String)