Source for javax.sound.midi.MidiFileFormat

   1: /* MidiFileFormat.java -- Information about a MIDI file
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.sound.midi;
  40: 
  41: /**
  42:  * Describe a MIDI file, including specifics about its type, length and timing.
  43:  * 
  44:  * @author Anthony Green (green@redhat.com)
  45:  * @since 1.3
  46:  *
  47:  */
  48: public class MidiFileFormat
  49: {
  50:   /**
  51:    * The MIDI file type.  This is either 0, 1 or 2.  
  52:    * 
  53:    * Type 0 files contain a single track and represents a single song
  54:    * performance.
  55:    * Type 1 may contain multiple tracks for a single song performance.
  56:    * Type 2 may contain multiple tracks, each representing a
  57:    * separate song performance.
  58:    * 
  59:    * See http://en.wikipedia.org/wiki/MIDI#MIDI_file_formats for more
  60:    * information.
  61:    */
  62:   protected int type;
  63: 
  64:   /**
  65:    * The division type of the MIDI file. 
  66:    */
  67:   protected float divisionType;
  68:   
  69:   /**
  70:    * The timing resolution of the MIDI file.
  71:    */
  72:   protected int resolution;
  73:   
  74:   /**
  75:    * The size of the MIDI file in bytes. 
  76:    */
  77:   protected int byteLength = UNKNOWN_LENGTH;
  78:   
  79:   /**
  80:    * The length of the MIDI file in microseconds. 
  81:    */
  82:   protected long microsecondLength = UNKNOWN_LENGTH;
  83:   
  84:   /**
  85:    * A special value indicating an unknown quantity.
  86:    */
  87:   public static final int UNKNOWN_LENGTH = -1; // FIXME is this really -1?
  88:   
  89:   /**
  90:    * Create a MidiFileFormat object from the given parameters.
  91:    *
  92:    * @param type the MIDI file type (0, 1, or 2)
  93:    * @param divisionType the MIDI file division type
  94:    * @param resolution the MIDI file timing resolution
  95:    * @param bytes the MIDI file size in bytes
  96:    * @param microseconds the MIDI file length in microseconds
  97:    */
  98:   public MidiFileFormat(int type, float divisionType, 
  99:             int resolution, int bytes, long microseconds)
 100:   {
 101:     this.type = type;
 102:     this.divisionType = divisionType;
 103:     this.resolution = resolution;
 104:     this.byteLength = bytes;
 105:     this.microsecondLength = microseconds;
 106:   }
 107:   
 108:   /**
 109:    * Get the MIDI file type (0, 1, or 2).
 110:    * 
 111:    * @return the MIDI file type (0, 1, or 2)
 112:    */
 113:   public int getType()
 114:   {
 115:     return type;
 116:   }
 117:   
 118:   /**
 119:    * Get the file division type.
 120:    * 
 121:    * @return the file divison type
 122:    */
 123:   public float getDivisionType()
 124:   {
 125:     return divisionType;    
 126:   }
 127:   
 128:   /**
 129:    * Get the file timing resolution.  If the division type is PPQ, then this
 130:    * is value represents ticks per beat, otherwise it's ticks per frame (SMPTE).
 131:    * 
 132:    * @return the timing resolution in ticks per beat or ticks per frame
 133:    */
 134:   public int getResolution()
 135:   {
 136:     return resolution;
 137:   }
 138:   
 139:   /**
 140:    * Get the file length in bytes.
 141:    * 
 142:    * @return the file length in bytes or UNKNOWN_LENGTH
 143:    */
 144:   public int getByteLength()
 145:   {
 146:     return byteLength;
 147:   }
 148: 
 149:   /**
 150:    * Get the file length in microseconds.
 151:    * 
 152:    * @return the file length in microseconds or UNKNOWN_LENGTH
 153:    */
 154:   public long getMicrosecondLength()
 155:   {
 156:     return microsecondLength;
 157:   }
 158: }