1. /*
  2. * @(#)MidiChannel.java 1.43 04/04/22
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sound.midi;
  8. /**
  9. * A <code>MidiChannel</code> object represents a single MIDI channel.
  10. * Generally, each <code>MidiChannel</code> method processes a like-named MIDI
  11. * "channel voice" or "channel mode" message as defined by the MIDI specification. However,
  12. * <code>MidiChannel</code> adds some "get" methods that retrieve the value
  13. * most recently set by one of the standard MIDI channel messages. Similarly,
  14. * methods for per-channel solo and mute have been added.
  15. * <p>
  16. * A <code>{@link Synthesizer}</code> object has a collection
  17. * of <code>MidiChannels</code>, usually one for each of the 16 channels
  18. * prescribed by the MIDI 1.0 specification. The <code>Synthesizer</code>
  19. * generates sound when its <code>MidiChannels</code> receive
  20. * <code>noteOn</code> messages.
  21. * <p>
  22. * See the MIDI 1.0 Specification for more information about the prescribed
  23. * behavior of the MIDI channel messages, which are not exhaustively
  24. * documented here. The specification is titled <code>MIDI Reference:
  25. * The Complete MIDI 1.0 Detailed Specification</code>, and is published by
  26. * the MIDI Manufacturer's Association (<a href = http://www.midi.org>
  27. * http://www.midi.org</a>).
  28. * <p>
  29. * MIDI was originally a protocol for reporting the gestures of a keyboard
  30. * musician. This genesis is visible in the <code>MidiChannel</code> API, which
  31. * preserves such MIDI concepts as key number, key velocity, and key pressure.
  32. * It should be understood that the MIDI data does not necessarily originate
  33. * with a keyboard player (the source could be a different kind of musician, or
  34. * software). Some devices might generate constant values for velocity
  35. * and pressure, regardless of how the note was performed.
  36. * Also, the MIDI specification often leaves it up to the
  37. * synthesizer to use the data in the way the implementor sees fit. For
  38. * example, velocity data need not always be mapped to volume and/or brightness.
  39. *
  40. * @see Synthesizer#getChannels
  41. *
  42. * @version 1.43, 04/22/04
  43. * @author David Rivas
  44. * @author Kara Kytle
  45. */
  46. public interface MidiChannel {
  47. /**
  48. * Starts the specified note sounding. The key-down velocity
  49. * usually controls the note's volume and/or brightness.
  50. * If <code>velocity</code> is zero, this method instead acts like
  51. * {@link #noteOff(int)}, terminating the note.
  52. *
  53. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  54. * @param velocity the speed with which the key was depressed
  55. *
  56. * @see #noteOff(int, int)
  57. */
  58. public void noteOn(int noteNumber, int velocity);
  59. /**
  60. * Turns the specified note off. The key-up velocity, if not ignored, can
  61. * be used to affect how quickly the note decays.
  62. * In any case, the note might not die away instantaneously; its decay
  63. * rate is determined by the internals of the <code>Instrument</code>.
  64. * If the Hold Pedal (a controller; see
  65. * {@link #controlChange(int, int) controlChange})
  66. * is down, the effect of this method is deferred until the pedal is
  67. * released.
  68. *
  69. *
  70. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  71. * @param velocity the speed with which the key was released
  72. *
  73. * @see #noteOff(int)
  74. * @see #noteOn
  75. * @see #allNotesOff
  76. * @see #allSoundOff
  77. */
  78. public void noteOff(int noteNumber, int velocity);
  79. /**
  80. * Turns the specified note off.
  81. *
  82. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  83. *
  84. * @see #noteOff(int, int)
  85. */
  86. public void noteOff(int noteNumber);
  87. /**
  88. * Reacts to a change in the specified note's key pressure.
  89. * Polyphonic key pressure
  90. * allows a keyboard player to press multiple keys simultaneously, each
  91. * with a different amount of pressure. The pressure, if not ignored,
  92. * is typically used to vary such features as the volume, brightness,
  93. * or vibrato of the note.
  94. *
  95. * It is possible that the underlying synthesizer
  96. * does not support this MIDI message. In order
  97. * to verify that <code>setPolyPressure</code>
  98. * was successful, use <code>getPolyPressure</code>.
  99. *
  100. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  101. * @param pressure value for the specified key, from 0 to 127 (127 =
  102. * maximum pressure)
  103. *
  104. * @see #getPolyPressure(int)
  105. */
  106. public void setPolyPressure(int noteNumber, int pressure);
  107. /**
  108. * Obtains the pressure with which the specified key is being depressed.
  109. *
  110. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  111. *
  112. * If the device does not support setting poly pressure,
  113. * this method always returns 0. Calling
  114. * <code>setPolyPressure</code> will have no effect then.
  115. *
  116. * @return the amount of pressure for that note, from 0 to 127
  117. * (127 = maximum pressure)
  118. *
  119. * @see #setPolyPressure(int, int)
  120. */
  121. public int getPolyPressure(int noteNumber);
  122. /**
  123. * Reacts to a change in the keyboard pressure. Channel
  124. * pressure indicates how hard the keyboard player is depressing
  125. * the entire keyboard. This can be the maximum or
  126. * average of the per-key pressure-sensor values, as set by
  127. * <code>setPolyPressure</code>. More commonly, it is a measurement of
  128. * a single sensor on a device that doesn't implement polyphonic key
  129. * pressure. Pressure can be used to control various aspects of the sound,
  130. * as described under {@link #setPolyPressure(int, int) setPolyPressure}.
  131. *
  132. * It is possible that the underlying synthesizer
  133. * does not support this MIDI message. In order
  134. * to verify that <code>setChannelPressure</code>
  135. * was successful, use <code>getChannelPressure</code>.
  136. *
  137. * @param pressure the pressure with which the keyboard is being depressed,
  138. * from 0 to 127 (127 = maximum pressure)
  139. * @see #setPolyPressure(int, int)
  140. * @see #getChannelPressure
  141. */
  142. public void setChannelPressure(int pressure);
  143. /**
  144. * Obtains the channel's keyboard pressure.
  145. * If the device does not support setting channel pressure,
  146. * this method always returns 0. Calling
  147. * <code>setChannelPressure</code> will have no effect then.
  148. *
  149. * @return the amount of pressure for that note,
  150. * from 0 to 127 (127 = maximum pressure)
  151. *
  152. * @see #setChannelPressure(int)
  153. */
  154. public int getChannelPressure();
  155. /**
  156. * Reacts to a change in the specified controller's value. A controller
  157. * is some control other than a keyboard key, such as a
  158. * switch, slider, pedal, wheel, or breath-pressure sensor.
  159. * The MIDI 1.0 Specification provides standard numbers for typical
  160. * controllers on MIDI devices, and describes the intended effect
  161. * for some of the controllers.
  162. * The way in which an
  163. * <code>Instrument</code> reacts to a controller change may be
  164. * specific to the <code>Instrument</code>.
  165. * <p>
  166. * The MIDI 1.0 Specification defines both 7-bit controllers
  167. * and 14-bit controllers. Continuous controllers, such
  168. * as wheels and sliders, typically have 14 bits (two MIDI bytes),
  169. * while discrete controllers, such as switches, typically have 7 bits
  170. * (one MIDI byte). Refer to the specification to see the
  171. * expected resolution for each type of control.
  172. * <p>
  173. * Controllers 64 through 95 (0x40 - 0x5F) allow 7-bit precision.
  174. * The value of a 7-bit controller is set completely by the
  175. * <code>value</code> argument. An additional set of controllers
  176. * provide 14-bit precision by using two controller numbers, one
  177. * for the most significant 7 bits and another for the least significant
  178. * 7 bits. Controller numbers 0 through 31 (0x00 - 0x1F) control the
  179. * most significant 7 bits of 14-bit controllers; controller numbers
  180. * 32 through 63 (0x20 - 0x3F) control the least significant 7 bits of
  181. * these controllers. For example, controller number 7 (0x07) controls
  182. * the upper 7 bits of the channel volume controller, and controller
  183. * number 39 (0x27) controls the lower 7 bits.
  184. * The value of a 14-bit controller is determined
  185. * by the interaction of the two halves. When the most significant 7 bits
  186. * of a controller are set (using controller numbers 0 through 31), the
  187. * lower 7 bits are automatically set to 0. The corresponding controller
  188. * number for the lower 7 bits may then be used to further modulate the
  189. * controller value.
  190. *
  191. * It is possible that the underlying synthesizer
  192. * does not support a specific controller message. In order
  193. * to verify that a call to <code>controlChange</code>
  194. * was successful, use <code>getController</code>.
  195. *
  196. * @param controller the controller number (0 to 127; see the MIDI
  197. * 1.0 Specification for the interpretation)
  198. * @param value the value to which the specified controller is changed (0 to 127)
  199. *
  200. * @see #getController(int)
  201. */
  202. public void controlChange(int controller, int value);
  203. /**
  204. * Obtains the current value of the specified controller. The return
  205. * value is represented with 7 bits. For 14-bit controllers, the MSB and
  206. * LSB controller value needs to be obtained separately. For example,
  207. * the 14-bit value of the volume controller can be calculated by
  208. * multiplying the value of controller 7 (0x07, channel volume MSB)
  209. * with 128 and adding the
  210. * value of controller 39 (0x27, channel volume LSB).
  211. *
  212. * If the device does not support setting a specific controller,
  213. * this method returns 0 for that controller.
  214. * Calling <code>controlChange</code> will have no effect then.
  215. *
  216. * @param controller the number of the controller whose value is desired.
  217. * The allowed range is 0-127; see the MIDI
  218. * 1.0 Specification for the interpretation.
  219. *
  220. * @return the current value of the specified controller (0 to 127)
  221. *
  222. * @see #controlChange(int, int)
  223. */
  224. public int getController(int controller);
  225. /**
  226. * Changes a program (patch). This selects a specific
  227. * instrument from the currently selected bank of instruments.
  228. * <p>
  229. * The MIDI specification does not
  230. * dictate whether notes that are already sounding should switch
  231. * to the new instrument (timbre) or continue with their original timbre
  232. * until terminated by a note-off.
  233. * <p>
  234. * The program number is zero-based (expressed from 0 to 127).
  235. * Note that MIDI hardware displays and literature about MIDI
  236. * typically use the range 1 to 128 instead.
  237. *
  238. * It is possible that the underlying synthesizer
  239. * does not support a specific program. In order
  240. * to verify that a call to <code>programChange</code>
  241. * was successful, use <code>getProgram</code>.
  242. *
  243. * @param program the program number to switch to (0 to 127)
  244. *
  245. * @see #programChange(int, int)
  246. * @see #getProgram()
  247. */
  248. public void programChange(int program);
  249. /**
  250. * Changes the program using bank and program (patch) numbers.
  251. *
  252. * It is possible that the underlying synthesizer
  253. * does not support a specific bank, or program. In order
  254. * to verify that a call to <code>programChange</code>
  255. * was successful, use <code>getProgram</code> and
  256. * <code>getController</code>.
  257. * Since banks are changed by way of control changes,
  258. * you can verify the current bank with the following
  259. * statement:
  260. * <pre>
  261. * int bank = (getController(0) * 128)
  262. * + getController(32);
  263. * </pre>
  264. *
  265. * @param bank the bank number to switch to (0 to 16383)
  266. * @param program the program (patch) to use in the specified bank (0 to 127)
  267. * @see #programChange(int)
  268. * @see #getProgram()
  269. */
  270. public void programChange(int bank, int program);
  271. /**
  272. * Obtains the current program number for this channel.
  273. * @return the program number of the currently selected patch
  274. * @see Patch#getProgram
  275. * @see Synthesizer#loadInstrument
  276. * @see #programChange(int)
  277. */
  278. public int getProgram();
  279. /**
  280. * Changes the pitch offset for all notes on this channel.
  281. * This affects all currently sounding notes as well as subsequent ones.
  282. * (For pitch bend to cease, the value needs to be reset to the
  283. * center position.)
  284. * <p> The MIDI specification
  285. * stipulates that pitch bend be a 14-bit value, where zero
  286. * is maximum downward bend, 16383 is maximum upward bend, and
  287. * 8192 is the center (no pitch bend). The actual
  288. * amount of pitch change is not specified; it can be changed by
  289. * a pitch-bend sensitivity setting. However, the General MIDI
  290. * specification says that the default range should be two semitones
  291. * up and down from center.
  292. *
  293. * It is possible that the underlying synthesizer
  294. * does not support this MIDI message. In order
  295. * to verify that <code>setPitchBend</code>
  296. * was successful, use <code>getPitchBend</code>.
  297. *
  298. * @param bend the amount of pitch change, as a nonnegative 14-bit value
  299. * (8192 = no bend)
  300. *
  301. * @see #getPitchBend
  302. */
  303. public void setPitchBend(int bend);
  304. /**
  305. * Obtains the upward or downward pitch offset for this channel.
  306. * If the device does not support setting pitch bend,
  307. * this method always returns 8192. Calling
  308. * <code>setPitchBend</code> will have no effect then.
  309. *
  310. * @return bend amount, as a nonnegative 14-bit value (8192 = no bend)
  311. *
  312. * @see #setPitchBend(int)
  313. */
  314. public int getPitchBend();
  315. /**
  316. * Resets all the implemented controllers to their default values.
  317. *
  318. * @see #controlChange(int, int)
  319. */
  320. public void resetAllControllers();
  321. /**
  322. * Turns off all notes that are currently sounding on this channel.
  323. * The notes might not die away instantaneously; their decay
  324. * rate is determined by the internals of the <code>Instrument</code>.
  325. * If the Hold Pedal controller (see
  326. * {@link #controlChange(int, int) controlChange})
  327. * is down, the effect of this method is deferred until the pedal is
  328. * released.
  329. *
  330. * @see #allSoundOff
  331. * @see #noteOff(int)
  332. */
  333. public void allNotesOff();
  334. /**
  335. * Immediately turns off all sounding notes on this channel, ignoring the
  336. * state of the Hold Pedal and the internal decay rate of the current
  337. * <code>Instrument</code>.
  338. *
  339. * @see #allNotesOff
  340. */
  341. public void allSoundOff();
  342. /**
  343. * Turns local control on or off. The default is for local control
  344. * to be on. The "on" setting means that if a device is capable
  345. * of both synthesizing sound and transmitting MIDI messages,
  346. * it will synthesize sound in response to the note-on and
  347. * note-off messages that it itself transmits. It will also respond
  348. * to messages received from other transmitting devices.
  349. * The "off" setting means that the synthesizer will ignore its
  350. * own transmitted MIDI messages, but not those received from other devices.
  351. *
  352. * It is possible that the underlying synthesizer
  353. * does not support local control. In order
  354. * to verify that a call to <code>localControl</code>
  355. * was successful, check the return value.
  356. *
  357. * @param on <code>true</code> to turn local control on, <code>false</code>
  358. * to turn local control off
  359. * @return the new local-control value, or false
  360. * if local control is not supported
  361. *
  362. */
  363. public boolean localControl(boolean on);
  364. /**
  365. * Turns mono mode on or off. In mono mode, the channel synthesizes
  366. * only one note at a time. In poly mode (identical to mono mode off),
  367. * the channel can synthesize multiple notes simultaneously.
  368. * The default is mono off (poly mode on).
  369. * <p>
  370. * "Mono" is short for the word "monophonic," which in this context
  371. * is opposed to the word "polyphonic" and refers to a single synthesizer
  372. * voice per MIDI channel. It
  373. * has nothing to do with how many audio channels there might be
  374. * (as in "monophonic" versus "stereophonic" recordings).
  375. *
  376. * It is possible that the underlying synthesizer
  377. * does not support mono mode. In order
  378. * to verify that a call to <code>setMono</code>
  379. * was successful, use <code>getMono</code>.
  380. *
  381. * @param on <code>true</code> to turn mono mode on, <code>false</code> to
  382. * turn it off (which means turning poly mode on).
  383. *
  384. * @see #getMono
  385. * @see VoiceStatus
  386. */
  387. public void setMono(boolean on);
  388. /**
  389. * Obtains the current mono/poly mode.
  390. * Synthesizers that do not allow changing mono/poly mode
  391. * will always return the same value, regardless
  392. * of calls to <code>setMono</code>.
  393. * @return <code>true</code> if mono mode is on, otherwise
  394. * <code>false</code> (meaning poly mode is on).
  395. *
  396. * @see #setMono(boolean)
  397. */
  398. public boolean getMono();
  399. /**
  400. * Turns omni mode on or off. In omni mode, the channel responds
  401. * to messages sent on all channels. When omni is off, the channel
  402. * responds only to messages sent on its channel number.
  403. * The default is omni off.
  404. *
  405. * It is possible that the underlying synthesizer
  406. * does not support omni mode. In order
  407. * to verify that <code>setOmni</code>
  408. * was successful, use <code>getOmni</code>.
  409. *
  410. * @param on <code>true</code> to turn omni mode on, <code>false</code> to
  411. * turn it off.
  412. *
  413. * @see #getOmni
  414. * @see VoiceStatus
  415. */
  416. public void setOmni(boolean on);
  417. /**
  418. * Obtains the current omni mode.
  419. * Synthesizers that do not allow changing the omni mode
  420. * will always return the same value, regardless
  421. * of calls to <code>setOmni</code>.
  422. * @return <code>true</code> if omni mode is on, otherwise
  423. * <code>false</code> (meaning omni mode is off).
  424. *
  425. * @see #setOmni(boolean)
  426. */
  427. public boolean getOmni();
  428. /**
  429. * Sets the mute state for this channel. A value of
  430. * <code>true</code> means the channel is to be muted, <code>false</code>
  431. * means the channel can sound (if other channels are not soloed).
  432. * <p>
  433. * Unlike {@link #allSoundOff()}, this method
  434. * applies to only a specific channel, not to all channels. Further, it
  435. * silences not only currently sounding notes, but also subsequently
  436. * received notes.
  437. *
  438. * It is possible that the underlying synthesizer
  439. * does not support muting channels. In order
  440. * to verify that a call to <code>setMute</code>
  441. * was successful, use <code>getMute</code>.
  442. *
  443. * @param mute the new mute state
  444. *
  445. * @see #getMute
  446. * @see #setSolo(boolean)
  447. */
  448. public void setMute(boolean mute);
  449. /**
  450. * Obtains the current mute state for this channel.
  451. * If the underlying synthesizer does not support
  452. * muting this channel, this method always returns
  453. * <code>false</code>.
  454. *
  455. * @return <code>true</code> the channel is muted,
  456. * or <code>false</code> if not
  457. *
  458. * @see #setMute(boolean)
  459. */
  460. public boolean getMute();
  461. /**
  462. * Sets the solo state for this channel.
  463. * If <code>solo</code> is <code>true</code> only this channel
  464. * and other soloed channels will sound. If <code>solo</code>
  465. * is <code>false</code> then only other soloed channels will
  466. * sound, unless no channels are soloed, in which case all
  467. * unmuted channels will sound.
  468. *
  469. * It is possible that the underlying synthesizer
  470. * does not support solo channels. In order
  471. * to verify that a call to <code>setSolo</code>
  472. * was successful, use <code>getSolo</code>.
  473. *
  474. * @param soloState new solo state for the channel
  475. * @see #getSolo()
  476. */
  477. public void setSolo(boolean soloState);
  478. /**
  479. * Obtains the current solo state for this channel.
  480. * If the underlying synthesizer does not support
  481. * solo on this channel, this method always returns
  482. * <code>false</code>.
  483. *
  484. * @return <code>true</code> the channel is solo,
  485. * or <code>false</code> if not
  486. *
  487. * @see #setSolo(boolean)
  488. */
  489. public boolean getSolo();
  490. }