1. /*
  2. * @(#)MidiDevice.java 1.34 03/01/27
  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. /**
  9. * <code>MidiDevice</code> is the base interface for all MIDI devices.
  10. * Common devices include synthesizers, sequencers, MIDI input ports, and MIDI
  11. * output ports. A <code>MidiDevice</code>
  12. * can be a transmitter or a receiver of MIDI events, or both. To this end, it
  13. * typically also implements the <code>{@link Transmitter}</code> or
  14. * <code>{@link Receiver}</code> interface (or both), or has access to objects that do.
  15. * <p>
  16. * A <code>MidiDevice</code> includes a <code>{@link MidiDevice.Info}</code> object
  17. * to provide manufacturer information and so on.
  18. *
  19. * @see Synthesizer
  20. * @see Sequencer
  21. * @see MidiChannel#setMono(boolean)
  22. *
  23. * @version 1.34, 03/01/27
  24. * @author Kara Kytle
  25. */
  26. public interface MidiDevice {
  27. /**
  28. * Obtains information about the device, including its Java class and
  29. * <code>Strings</code> containing its name, vendor, and description.
  30. *
  31. * @return device info
  32. */
  33. public Info getDeviceInfo();
  34. /**
  35. * Opens the device, indicating that it should now acquire any
  36. * system resources it requires and become operational.
  37. * <p>
  38. * Note that some devices, once closed, cannot be reopened. Attempts
  39. * to reopen such a device will always result in a MidiUnavailableException.
  40. *
  41. * @throws MidiUnavailableException thrown if the device cannot be
  42. * opened due to resource restrictions.
  43. * @throws SecurityException thrown if the device cannot be
  44. * opened due to security restrictions.
  45. *
  46. * @see #close
  47. * @see #isOpen
  48. */
  49. public void open() throws MidiUnavailableException;
  50. /**
  51. * Closes the device, indicating that the device should now release
  52. * any system resources it is using.
  53. *
  54. * @see #open
  55. * @see #isOpen
  56. */
  57. public void close();
  58. /**
  59. * Reports whether the device is open. The mechanism for
  60. * opening particular devices is defined by subinterfaces
  61. * and/or by classes implementing this interface.
  62. *
  63. * @return <code>true</code> if the device is open, otherwise
  64. * <code>false</code>
  65. * @see #close
  66. */
  67. public boolean isOpen();
  68. /**
  69. * Obtains the current time-stamp of the device, in microseconds.
  70. * If a device supports time-stamps, it should start counting at
  71. * 0 when the device is opened and continue incrementing its
  72. * time-stamp in microseconds until the device is closed.
  73. * If it does not support time-stamps, it should always return
  74. * -1.
  75. * @return the current time-stamp of the device in microseconds,
  76. * or -1 if time-stamping is not supported by the device.
  77. */
  78. public long getMicrosecondPosition();
  79. /**
  80. * Obtains the maximum number of MIDI IN connections available on this
  81. * MIDI device for receiving MIDI data.
  82. * @return maximum number of MIDI IN connections,
  83. * or -1 if an unlimited number of connections is available.
  84. */
  85. public int getMaxReceivers();
  86. /**
  87. * Obtains the maximum number of MIDI OUT connections available on this
  88. * MIDI device for transmitting MIDI data.
  89. * @return maximum number of MIDI OUT connections,
  90. * or -1 if an unlimited number of connections is available.
  91. */
  92. public int getMaxTransmitters();
  93. /**
  94. * Obtains the maximum number of MIDI THRU connections available on this
  95. * MIDI device for transmitting MIDI data.
  96. * @return maximum number of MIDI THRU connections
  97. */
  98. //public int getMaxThruTransmitters();
  99. /**
  100. * Obtains a MIDI IN receiver through which the MIDI device may receive
  101. * MIDI data. The returned receiver must be closed when the application
  102. * has finished using it.
  103. * @return a receiver for the device.
  104. * @throws MidiUnavailableException thrown if a receiver is not available
  105. * due to resource restrictions
  106. * @see Receiver#close()
  107. */
  108. public Receiver getReceiver() throws MidiUnavailableException;
  109. /**
  110. * Obtains a MIDI OUT connection from which the MIDI device will transmit
  111. * MIDI data The returned transmitter must be closed when the application
  112. * has finished using it.
  113. * @return a MIDI OUT transmitter for the device.
  114. * @throws MidiUnavailableException thrown if a transmitter is not available
  115. * due to resource restrictions
  116. * @see Transmitter#close()
  117. */
  118. public Transmitter getTransmitter() throws MidiUnavailableException;
  119. /**
  120. * Obtains a MIDI THRU connection from which the MIDI device will transmit
  121. * MIDI data The returned transmitter must be closed when the application
  122. * has finished using it.
  123. * @return a MIDI THRU transmitter for the device.
  124. * @throws MidiUnavailableException thrown if a transmitter is not available
  125. * due to resource restrictions
  126. * @see Transmitter#close()
  127. */
  128. //public Transmitter getThruTransmitter() throws MidiUnavailableException;
  129. /**
  130. * A <code>MidiDevice.Info</code> object contains assorted
  131. * data about a <code>{@link MidiDevice}</code>, including its
  132. * name, the company who created it, and descriptive text.
  133. *
  134. * @see MidiDevice#getDeviceInfo
  135. */
  136. public static class Info {
  137. /**
  138. * The device's name.
  139. */
  140. private String name;
  141. /**
  142. * The name of the company who provides the device.
  143. */
  144. private String vendor;
  145. /**
  146. * A description of the device.
  147. */
  148. private String description;
  149. /**
  150. * Device version.
  151. */
  152. private String version;
  153. /**
  154. * Constructs a device info object.
  155. *
  156. * @param name the name of the device
  157. * @param vendor the name of the company who provides the device
  158. * @param description a description of the device
  159. * @param version version information for the device
  160. */
  161. protected Info(String name, String vendor, String description, String version) {
  162. this.name = name;
  163. this.vendor = vendor;
  164. this.description = description;
  165. this.version = version;
  166. }
  167. /**
  168. * Reports whether two objects are equal.
  169. * Returns <code>true</code> if the objects are identical.
  170. * @param obj the reference object with which to compare this
  171. * object
  172. * @return <code>true</code> if this object is the same as the
  173. * <code>obj</code> argument; <code>false</code> otherwise
  174. */
  175. public final boolean equals(Object obj) {
  176. return super.equals(obj);
  177. }
  178. /**
  179. * Finalizes the hashcode method.
  180. */
  181. public final int hashCode() {
  182. return super.hashCode();
  183. }
  184. /**
  185. * Obtains the name of the device.
  186. *
  187. * @return a string containing the device's name
  188. */
  189. public final String getName() {
  190. return name;
  191. }
  192. /**
  193. * Obtains the name of the company who supplies the device.
  194. * @return device the vendor's name
  195. */
  196. public final String getVendor() {
  197. return vendor;
  198. }
  199. /**
  200. * Obtains the description of the device.
  201. * @return a description of the device
  202. */
  203. public final String getDescription() {
  204. return description;
  205. }
  206. /**
  207. * Obtains the version of the device.
  208. * @return textual version information for the device.
  209. */
  210. public final String getVersion() {
  211. return version;
  212. }
  213. /**
  214. * Provides a string representation of the device information.
  215. * @return a description of the info object
  216. */
  217. public final String toString() {
  218. return name;
  219. }
  220. } // class Info
  221. // OLD
  222. /**
  223. * MIDI Mode 1: Omni On/Poly.
  224. *
  225. * @see #setMode(int)
  226. */
  227. //public static final int OMNI_ON_POLY = 1;
  228. /**
  229. * MIDI Mode 2: Omni On/Mono.
  230. *
  231. * @see #setMode(int)
  232. */
  233. //public static final int OMNI_ON_MONO = 2;
  234. /**
  235. * MIDI Mode 3: Omni Off/Poly.
  236. *
  237. * @see #setMode(int)
  238. */
  239. //public static final int OMNI_OFF_POLY = 3;
  240. /**
  241. * MIDI Mode 4: Omni Off/Mono.
  242. *
  243. * @see #setMode(int)
  244. */
  245. //public static final int OMNI_OFF_MONO = 4;
  246. /**
  247. * Sets the current omni and mono/poly mode. The argument should be
  248. * one of the integers returned by <code>getModes()</code>. Any other
  249. * value will be ignored, leaving the current mode unchanged.
  250. *
  251. * @param mode the desired new mode
  252. *
  253. * @see #OMNI_ON_POLY
  254. * @see #OMNI_ON_MONO
  255. * @see #OMNI_OFF_POLY
  256. * @see #OMNI_OFF_MONO
  257. * @see #getMode
  258. * @see #getModes
  259. */
  260. //public void setMode(int mode);
  261. /**
  262. * Obtains the current omni and mono/poly mode.
  263. *
  264. * @return the current mode
  265. *
  266. * @see #OMNI_ON_POLY
  267. * @see #OMNI_ON_MONO
  268. * @see #OMNI_OFF_POLY
  269. * @see #OMNI_OFF_MONO
  270. * @see #setMode(int)
  271. * @see #getModes
  272. */
  273. //public int getMode();
  274. /**
  275. * Obtains the set of omni and mono/poly modes supported by this device.
  276. *
  277. * @return the list of supported modes
  278. *
  279. * @see #OMNI_ON_POLY
  280. * @see #OMNI_ON_MONO
  281. * @see #OMNI_OFF_POLY
  282. * @see #OMNI_OFF_MONO
  283. * @see #getMode
  284. * @see #setMode(int)
  285. */
  286. //public int[] getModes();
  287. }