1. /*
  2. * @(#)MidiFileFormat.java 1.15 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sound.midi;
  8. import java.io.InputStream;
  9. import java.io.IOException;
  10. /**
  11. * A <code>MidiFileFormat</code> object encapsulates a MIDI file's
  12. * type, as well as its length and timing information.
  13. *
  14. * @see MidiSystem#getMidiFileFormat(java.io.File)
  15. * @see Sequencer#setSequence(java.io.InputStream stream)
  16. *
  17. * @version 1.15, 03/01/23
  18. * @author Kara Kytle
  19. */
  20. public class MidiFileFormat {
  21. /**
  22. * Represents unknown length.
  23. * @see #getByteLength
  24. * @see #getMicrosecondLength
  25. */
  26. public static final int UNKNOWN_LENGTH = -1;
  27. /**
  28. * The type of MIDI file.
  29. */
  30. protected int type;
  31. /**
  32. * The division type of the MIDI file.
  33. *
  34. * @see Sequence#PPQ
  35. * @see Sequence#SMPTE_24
  36. * @see Sequence#SMPTE_25
  37. * @see Sequence#SMPTE_30DROP
  38. * @see Sequence#SMPTE_30
  39. */
  40. protected float divisionType;
  41. /**
  42. * The timing resolution of the MIDI file.
  43. */
  44. protected int resolution;
  45. /**
  46. * The length of the MIDI file in bytes.
  47. */
  48. protected int byteLength;
  49. /**
  50. * The duration of the MIDI file in microseconds.
  51. */
  52. protected long microsecondLength;
  53. /**
  54. * Constructs a <code>MidiFileFormat</code>.
  55. *
  56. * @param type the MIDI file type (0, 1, or 2)
  57. * @param divisionType the timing division type (PPQ or one of the SMPTE types)
  58. * @param resolution the timing resolution
  59. * @param bytes the length of the MIDI file in bytes, or UNKNOWN_LENGTH if not known
  60. * @param microseconds the duration of the file in microseconds, or UNKNOWN_LENGTH if not known
  61. * @see #UNKNOWN_LENGTH
  62. * @see Sequence#PPQ
  63. * @see Sequence#SMPTE_24
  64. * @see Sequence#SMPTE_25
  65. * @see Sequence#SMPTE_30DROP
  66. * @see Sequence#SMPTE_30
  67. */
  68. public MidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds) {
  69. this.type = type;
  70. this.divisionType = divisionType;
  71. this.resolution = resolution;
  72. this.byteLength = bytes;
  73. this.microsecondLength = microseconds;
  74. }
  75. /**
  76. * Obtains the MIDI file type.
  77. * @return the file's type (0, 1, or 2)
  78. */
  79. public int getType() {
  80. return type;
  81. }
  82. /**
  83. * Obtains the timing division type for the MIDI file.
  84. *
  85. * @return the division type (PPQ or one of the SMPTE types)
  86. *
  87. * @see Sequence#Sequence(float, int)
  88. * @see Sequence#PPQ
  89. * @see Sequence#SMPTE_24
  90. * @see Sequence#SMPTE_25
  91. * @see Sequence#SMPTE_30DROP
  92. * @see Sequence#SMPTE_30
  93. * @see Sequence#getDivisionType()
  94. */
  95. public float getDivisionType() {
  96. return divisionType;
  97. }
  98. /**
  99. * Obtains the timing resolution for the MIDI file.
  100. * If the division type is PPQ, the resolution is specified in ticks per beat.
  101. * For SMTPE timing, the resolution is specified in ticks per frame.
  102. *
  103. * @return the number of ticks per beat (PPQ) or per frame (SMPTE)
  104. * @see #getDivisionType
  105. * @see Sequence#getResolution()
  106. */
  107. public int getResolution() {
  108. return resolution;
  109. }
  110. /**
  111. * Obtains the length of the MIDI file, expressed in 8-bit bytes.
  112. * @return the number of bytes in the file, or UNKNOWN_LENGTH if not known
  113. * @see #UNKNOWN_LENGTH
  114. */
  115. public int getByteLength() {
  116. return byteLength;
  117. }
  118. /**
  119. * Obtains the length of the MIDI file, expressed in microseconds.
  120. * @return the file's duration in microseconds, or UNKNOWN_LENGTH if not known
  121. * @see Sequence#getMicrosecondLength()
  122. * @see #getByteLength
  123. * @see #UNKNOWN_LENGTH
  124. */
  125. public long getMicrosecondLength() {
  126. return microsecondLength;
  127. }
  128. }