Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/midi/MidiFileFormat.java
38830 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.midi;2627import java.io.InputStream;28import java.io.IOException;29import java.util.Collections;30import java.util.HashMap;31import java.util.Map;323334/**35* A <code>MidiFileFormat</code> object encapsulates a MIDI file's36* type, as well as its length and timing information.37*38* <p>A <code>MidiFileFormat</code> object can39* include a set of properties. A property is a pair of key and value:40* the key is of type <code>String</code>, the associated property41* value is an arbitrary object.42* Properties specify additional informational43* meta data (like a author, or copyright).44* Properties are optional information, and file reader and file45* writer implementations are not required to provide or46* recognize properties.47*48* <p>The following table lists some common properties that should49* be used in implementations:50*51* <table border=1>52<caption>MIDI File Format Properties</caption>53* <tr>54* <th>Property key</th>55* <th>Value type</th>56* <th>Description</th>57* </tr>58* <tr>59* <td>"author"</td>60* <td>{@link java.lang.String String}</td>61* <td>name of the author of this file</td>62* </tr>63* <tr>64* <td>"title"</td>65* <td>{@link java.lang.String String}</td>66* <td>title of this file</td>67* </tr>68* <tr>69* <td>"copyright"</td>70* <td>{@link java.lang.String String}</td>71* <td>copyright message</td>72* </tr>73* <tr>74* <td>"date"</td>75* <td>{@link java.util.Date Date}</td>76* <td>date of the recording or release</td>77* </tr>78* <tr>79* <td>"comment"</td>80* <td>{@link java.lang.String String}</td>81* <td>an arbitrary text</td>82* </tr>83* </table>84*85* @see MidiSystem#getMidiFileFormat(java.io.File)86* @see Sequencer#setSequence(java.io.InputStream stream)87*88* @author Kara Kytle89* @author Florian Bomers90*/9192public class MidiFileFormat {939495/**96* Represents unknown length.97* @see #getByteLength98* @see #getMicrosecondLength99*/100public static final int UNKNOWN_LENGTH = -1;101102103/**104* The type of MIDI file.105*/106protected int type;107108/**109* The division type of the MIDI file.110*111* @see Sequence#PPQ112* @see Sequence#SMPTE_24113* @see Sequence#SMPTE_25114* @see Sequence#SMPTE_30DROP115* @see Sequence#SMPTE_30116*/117protected float divisionType;118119/**120* The timing resolution of the MIDI file.121*/122protected int resolution;123124/**125* The length of the MIDI file in bytes.126*/127protected int byteLength;128129/**130* The duration of the MIDI file in microseconds.131*/132protected long microsecondLength;133134135/** The set of properties */136private HashMap<String, Object> properties;137138139/**140* Constructs a <code>MidiFileFormat</code>.141*142* @param type the MIDI file type (0, 1, or 2)143* @param divisionType the timing division type (PPQ or one of the SMPTE types)144* @param resolution the timing resolution145* @param bytes the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known146* @param microseconds the duration of the file in microseconds, or UNKNOWN_LENGTH if not known147* @see #UNKNOWN_LENGTH148* @see Sequence#PPQ149* @see Sequence#SMPTE_24150* @see Sequence#SMPTE_25151* @see Sequence#SMPTE_30DROP152* @see Sequence#SMPTE_30153*/154public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds) {155156this.type = type;157this.divisionType = divisionType;158this.resolution = resolution;159this.byteLength = bytes;160this.microsecondLength = microseconds;161this.properties = null;162}163164165/**166* Construct a <code>MidiFileFormat</code> with a set of properties.167*168* @param type the MIDI file type (0, 1, or 2)169* @param divisionType the timing division type170* (PPQ or one of the SMPTE types)171* @param resolution the timing resolution172* @param bytes the length of the MIDI file in bytes,173* or UNKNOWN_LENGTH if not known174* @param microseconds the duration of the file in microseconds,175* or UNKNOWN_LENGTH if not known176* @param properties a <code>Map<String,Object></code> object177* with properties178*179* @see #UNKNOWN_LENGTH180* @see Sequence#PPQ181* @see Sequence#SMPTE_24182* @see Sequence#SMPTE_25183* @see Sequence#SMPTE_30DROP184* @see Sequence#SMPTE_30185* @since 1.5186*/187public MidiFileFormat(int type, float divisionType,188int resolution, int bytes,189long microseconds, Map<String, Object> properties) {190this(type, divisionType, resolution, bytes, microseconds);191this.properties = new HashMap<String, Object>(properties);192}193194195196/**197* Obtains the MIDI file type.198* @return the file's type (0, 1, or 2)199*/200public int getType() {201return type;202}203204/**205* Obtains the timing division type for the MIDI file.206*207* @return the division type (PPQ or one of the SMPTE types)208*209* @see Sequence#Sequence(float, int)210* @see Sequence#PPQ211* @see Sequence#SMPTE_24212* @see Sequence#SMPTE_25213* @see Sequence#SMPTE_30DROP214* @see Sequence#SMPTE_30215* @see Sequence#getDivisionType()216*/217public float getDivisionType() {218return divisionType;219}220221222/**223* Obtains the timing resolution for the MIDI file.224* If the division type is PPQ, the resolution is specified in ticks per beat.225* For SMTPE timing, the resolution is specified in ticks per frame.226*227* @return the number of ticks per beat (PPQ) or per frame (SMPTE)228* @see #getDivisionType229* @see Sequence#getResolution()230*/231public int getResolution() {232return resolution;233}234235236/**237* Obtains the length of the MIDI file, expressed in 8-bit bytes.238* @return the number of bytes in the file, or UNKNOWN_LENGTH if not known239* @see #UNKNOWN_LENGTH240*/241public int getByteLength() {242return byteLength;243}244245/**246* Obtains the length of the MIDI file, expressed in microseconds.247* @return the file's duration in microseconds, or UNKNOWN_LENGTH if not known248* @see Sequence#getMicrosecondLength()249* @see #getByteLength250* @see #UNKNOWN_LENGTH251*/252public long getMicrosecondLength() {253return microsecondLength;254}255256/**257* Obtain an unmodifiable map of properties.258* The concept of properties is further explained in259* the {@link MidiFileFormat class description}.260*261* @return a <code>Map<String,Object></code> object containing262* all properties. If no properties are recognized, an empty map is263* returned.264*265* @see #getProperty(String)266* @since 1.5267*/268public Map<String,Object> properties() {269Map<String,Object> ret;270if (properties == null) {271ret = new HashMap<String,Object>(0);272} else {273ret = (Map<String,Object>) (properties.clone());274}275return (Map<String,Object>) Collections.unmodifiableMap(ret);276}277278279/**280* Obtain the property value specified by the key.281* The concept of properties is further explained in282* the {@link MidiFileFormat class description}.283*284* <p>If the specified property is not defined for a285* particular file format, this method returns286* <code>null</code>.287*288* @param key the key of the desired property289* @return the value of the property with the specified key,290* or <code>null</code> if the property does not exist.291*292* @see #properties()293* @since 1.5294*/295public Object getProperty(String key) {296if (properties == null) {297return null;298}299return properties.get(key);300}301302303}304305306