jdk/src/share/classes/javax/sound/midi/MidiFileFormat.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sound.midi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * A <code>MidiFileFormat</code> object encapsulates a MIDI file's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * type, as well as its length and timing information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>A <code>MidiFileFormat</code> object can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * include a set of properties. A property is a pair of key and value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * the key is of type <code>String</code>, the associated property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * value is an arbitrary object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Properties specify additional informational
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * meta data (like a author, or copyright).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Properties are optional information, and file reader and file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * writer implementations are not required to provide or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * recognize properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>The following table lists some common properties that should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * be used in implementations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <table border=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   <th>Property key</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <th>Value type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   <td>&quot;author&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   <td>name of the author of this file</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   <td>&quot;title&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <td>title of this file</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   <td>&quot;copyright&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   <td>copyright message</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   <td>&quot;date&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   <td>{@link java.util.Date Date}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   <td>date of the recording or release</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *  <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *   <td>&quot;comment&quot;</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *   <td>{@link java.lang.String String}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *   <td>an arbitrary text</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *  </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see MidiSystem#getMidiFileFormat(java.io.File)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @see Sequencer#setSequence(java.io.InputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class MidiFileFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Represents unknown length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @see #getByteLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see #getMicrosecondLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final int UNKNOWN_LENGTH = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * The type of MIDI file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    protected int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * The division type of the MIDI file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see Sequence#PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see Sequence#SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see Sequence#SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see Sequence#SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see Sequence#SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected float divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The timing resolution of the MIDI file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected int resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * The length of the MIDI file in bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected int byteLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * The duration of the MIDI file in microseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected long microsecondLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /** The set of properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private HashMap<String, Object> properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Constructs a <code>MidiFileFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param type the MIDI file type (0, 1, or 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param divisionType the timing division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param resolution the timing resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param bytes the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param microseconds the duration of the file in microseconds, or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #UNKNOWN_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see Sequence#PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see Sequence#SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see Sequence#SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see Sequence#SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see Sequence#SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.divisionType = divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.resolution = resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.byteLength = bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this.microsecondLength = microseconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.properties = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Construct a <code>MidiFileFormat</code> with a set of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param type         the MIDI file type (0, 1, or 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param divisionType the timing division type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *      (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param resolution   the timing resolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param bytes the length of the MIDI file in bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *      or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param microseconds the duration of the file in microseconds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *      or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param properties  a <code>Map&lt;String,Object&gt;</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *        with properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see #UNKNOWN_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see Sequence#PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see Sequence#SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see Sequence#SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see Sequence#SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @see Sequence#SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public MidiFileFormat(int type, float divisionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                          int resolution, int bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                          long microseconds, Map<String, Object> properties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this(type, divisionType, resolution, bytes, microseconds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this.properties = new HashMap<String, Object>(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Obtains the MIDI file type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return the file's type (0, 1, or 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Obtains the timing division type for the MIDI file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return the division type (PPQ or one of the SMPTE types)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see Sequence#Sequence(float, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see Sequence#PPQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see Sequence#SMPTE_24
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see Sequence#SMPTE_25
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see Sequence#SMPTE_30DROP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see Sequence#SMPTE_30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see Sequence#getDivisionType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public float getDivisionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return divisionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Obtains the timing resolution for the MIDI file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * If the division type is PPQ, the resolution is specified in ticks per beat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * For SMTPE timing, the resolution is specified in ticks per frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the number of ticks per beat (PPQ) or per frame (SMPTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @see #getDivisionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @see Sequence#getResolution()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public int getResolution() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return resolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Obtains the length of the MIDI file, expressed in 8-bit bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return the number of bytes in the file, or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see #UNKNOWN_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public int getByteLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return byteLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Obtains the length of the MIDI file, expressed in microseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the file's duration in microseconds, or UNKNOWN_LENGTH if not known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see Sequence#getMicrosecondLength()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see #getByteLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #UNKNOWN_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public long getMicrosecondLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return microsecondLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Obtain an unmodifiable map of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * The concept of properties is further explained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * the {@link MidiFileFormat class description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @return a <code>Map&lt;String,Object&gt;</code> object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *         all properties. If no properties are recognized, an empty map is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #getProperty(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public Map<String,Object> properties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        Map<String,Object> ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            ret = new HashMap<String,Object>(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            ret = (Map<String,Object>) (properties.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return (Map<String,Object>) Collections.unmodifiableMap(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Obtain the property value specified by the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * The concept of properties is further explained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * the {@link MidiFileFormat class description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p>If the specified property is not defined for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * particular file format, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param key the key of the desired property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @return the value of the property with the specified key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *         or <code>null</code> if the property does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see #properties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public Object getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (properties == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return properties.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}