1. /*
  2. * @(#)MidiChannel.java 1.39 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. /**
  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.39, 01/23/03
  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. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  96. * @param pressure value for the specified key, from 0 to 127 (127 =
  97. * maximum pressure)
  98. *
  99. * @see #getPolyPressure(int)
  100. */
  101. public void setPolyPressure(int noteNumber, int pressure);
  102. /**
  103. * Obtains the pressure with which the specified key is being depressed.
  104. *
  105. * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
  106. * @return the amount of pressure for that note, from 0 to 127
  107. * (127 = maximum pressure)
  108. *
  109. * @see #setPolyPressure(int, int)
  110. */
  111. public int getPolyPressure(int noteNumber);
  112. /**
  113. * Reacts to a change in the keyboard pressure. Channel
  114. * pressure indicates how hard the keyboard player is depressing
  115. * the entire keyboard. This can be the maximum or
  116. * average of the per-key pressure-sensor values, as set by
  117. * <code>setPolyPressure</code>. More commonly, it is a measurement of
  118. * a single sensor on a device that doesn't implement polyphonic key
  119. * pressure. Pressure can be used to control various aspects of the sound,
  120. * as described under {@link #setPolyPressure(int, int) setPolyPressure}.
  121. *
  122. * @param pressure the pressure with which the keyboard is being depressed,
  123. * from 0 to 127 (127 = maximum pressure)
  124. * @see #setPolyPressure(int, int)
  125. * @see #getChannelPressure
  126. */
  127. public void setChannelPressure(int pressure);
  128. /**
  129. * Obtains the channel's keyboard pressure.
  130. * @return the pressure with which the keyboard is being depressed,
  131. * from 0 to 127 (127 = maximum pressure)
  132. * @see #setChannelPressure(int)
  133. */
  134. public int getChannelPressure();
  135. /**
  136. * Reacts to a change in the specified controller's value. A controller
  137. * is some control other than a keyboard key, such as a
  138. * switch, slider, pedal, wheel, or breath-pressure sensor.
  139. * The MIDI 1.0 Specification provides standard numbers for typical
  140. * controllers on MIDI devices, and describes the intended effect
  141. * for some of the controllers.
  142. * The way in which an
  143. * <code>Instrument</code> reacts to a controller change may be
  144. * specific to the <code>Instrument</code>.
  145. * <p>
  146. * The MIDI 1.0 Specification defines both 7-bit controllers
  147. * and 14-bit controllers. Continuous controllers, such
  148. * as wheels and sliders, typically have 14 bits (two MIDI bytes),
  149. * while discrete controllers, such as switches, typically have 7 bits
  150. * (one MIDI byte). Refer to the specification to see the
  151. * expected resolution for each type of control.
  152. * <p>
  153. * Controllers 64 through 95 (0x40 - 0x5F) allow 7-bit precision.
  154. * The value of a 7-bit controller is set completely by the
  155. * <code>value</code> argument. An additional set of controllers
  156. * provide 14-bit precision by using two controller numbers, one
  157. * for the most significant 7 bits and another for the least significant
  158. * 7 bits. Controller numbers 0 through 31 (0x00 - 0x1F) control the
  159. * most significant 7 bits of 14-bit controllers; controller numbers
  160. * 32 through 63 (0x20 - 0x3F) control the least significant 7 bits of
  161. * these controllers. For example, controller number 7 (0x07) controls
  162. * the upper 7 bits of the channel volume controller, and controller
  163. * number 39 (0x27) controls the lower 7 bits.
  164. * The value of a 14-bit controller is determined
  165. * by the interaction of the two halves. When the most significant 7 bits
  166. * of a controller are set (using controller numbers 0 through 31), the
  167. * lower 7 bits are automatically set to 0. The corresponding controller
  168. * number for the lower 7 bits may then be used to further modulate the
  169. * controller value.
  170. *
  171. * @param controller the controller number (0 to 127; see the MIDI
  172. * 1.0 Specification for the interpretation)
  173. * @param value the value to which the specified controller is changed (0 to 127)
  174. *
  175. * @see #getController(int)
  176. */
  177. public void controlChange(int controller, int value);
  178. /**
  179. * Obtains the current value of the specified controller. The return
  180. * value is represented with 7 bits. For 14-bit controllers, the MSB and
  181. * LSB controller value needs to be obtained separately. For example,
  182. * the 14-bit value of the volume controller can be calculated by
  183. * multiplying the value of controller 7 (0x07, channel volume MSB)
  184. * with 128 and adding the
  185. * value of controller 39 (0x27, channel volume LSB).
  186. *
  187. * @param controller the number of the controller whose value is desired.
  188. * The allowed range is 0-127; see the MIDI
  189. * 1.0 Specification for the interpretation.
  190. * @return the current value of the specified controller (0 to 127)
  191. * @see #controlChange(int, int)
  192. */
  193. public int getController(int controller);
  194. /**
  195. * Changes a program (patch). This selects a specific
  196. * instrument from the currently selected bank of instruments.
  197. * <p>
  198. * The MIDI specification does not
  199. * dictate whether notes that are already sounding should switch
  200. * to the new instrument (timbre) or continue with their original timbre
  201. * until terminated by a note-off.
  202. * <p>
  203. * The program number is zero-based (expressed from 0 to 127).
  204. * Note that MIDI hardware displays and literature about MIDI
  205. * typically use the range 1 to 128 instead.
  206. * @param program the program number to switch to (0 to 127)
  207. *
  208. * @see #programChange(int, int)
  209. * @see #getProgram()
  210. */
  211. public void programChange(int program);
  212. /**
  213. * Changes the program using bank and program (patch) numbers.
  214. *
  215. * @param bank the bank number to switch to (0 to 16383)
  216. * @param program the program (patch) to use in the specified bank (0 to 127)
  217. * @see #programChange(int)
  218. * @see #getProgram()
  219. */
  220. public void programChange(int bank, int program);
  221. /**
  222. * Obtains the current program number for this channel.
  223. * @return the program number of the currently selected patch
  224. * @see Patch#getProgram
  225. * @see Synthesizer#loadInstrument
  226. * @see #programChange(int)
  227. */
  228. public int getProgram();
  229. /**
  230. * Changes the pitch offset for all notes on this channel.
  231. * This affects all currently sounding notes as well as subsequent ones.
  232. * (For pitch bend to cease, the value needs to be reset to the
  233. * center position.)
  234. * <p> The MIDI specification
  235. * stipulates that pitch bend be a 14-bit value, where zero
  236. * is maximum downward bend, 16383 is maximum upward bend, and
  237. * 8192 is the center (no pitch bend). The actual
  238. * amount of pitch change is not specified; it can be changed by
  239. * a pitch-bend sensitivity setting. However, the General MIDI
  240. * specification says that the default range should be two semitones
  241. * up and down from center.
  242. *
  243. * @param bend the amount of pitch change, as a nonnegative 14-bit value
  244. * (8192 = no bend)
  245. *
  246. * @see #getPitchBend
  247. */
  248. public void setPitchBend(int bend);
  249. /**
  250. * Obtains the upward or downward pitch offset for this channel.
  251. * @return bend amount, as a nonnegative 14-bit value (8192 = no bend)
  252. *
  253. * @see #setPitchBend(int)
  254. */
  255. public int getPitchBend();
  256. /**
  257. * Resets all the implemented controllers to their default values.
  258. *
  259. * @see #controlChange(int, int)
  260. */
  261. public void resetAllControllers();
  262. /**
  263. * Turns off all notes that are currently sounding on this channel.
  264. * The notes might not die away instantaneously; their decay
  265. * rate is determined by the internals of the <code>Instrument</code>.
  266. * If the Hold Pedal controller (see
  267. * {@link #controlChange(int, int) controlChange})
  268. * is down, the effect of this method is deferred until the pedal is
  269. * released.
  270. *
  271. * @see #allSoundOff
  272. * @see #noteOff(int)
  273. */
  274. public void allNotesOff();
  275. /**
  276. * Immediately turns off all sounding notes on this channel, ignoring the
  277. * state of the Hold Pedal and the internal decay rate of the current
  278. * <code>Instrument</code>.
  279. *
  280. * @see #allNotesOff
  281. */
  282. public void allSoundOff();
  283. /**
  284. * Turns local control on or off. The default is for local control
  285. * to be on. The "on" setting means that if a device is capable
  286. * of both synthesizing sound and transmitting MIDI messages,
  287. * it will synthesize sound in response to the note-on and
  288. * note-off messages that it itself transmits. It will also respond
  289. * to messages received from other transmitting devices.
  290. * The "off" setting means that the synthesizer will ignore its
  291. * own transmitted MIDI messages, but not those received from other devices.
  292. *
  293. * @param on <code>true</code> to turn local control on, <code>false</code>
  294. * to turn local control off
  295. * @return the new local-control value
  296. *
  297. */
  298. public boolean localControl(boolean on);
  299. /**
  300. * Turns mono mode on or off. In mono mode, the channel synthesizes
  301. * only one note at a time. In poly mode (identical to mono mode off),
  302. * the channel can synthesize multiple notes simultaneously.
  303. * The default is mono off (poly mode on).
  304. * <p>
  305. * "Mono" is short for the word "monophonic," which in this context
  306. * is opposed to the word "polyphonic" and refers to a single synthesizer
  307. * voice per MIDI channel. It
  308. * has nothing to do with how many audio channels there might be
  309. * (as in "monophonic" versus "stereophonic" recordings).
  310. *
  311. * @param on <code>true</code> to turn mono mode on, <code>false</code> to
  312. * turn it off (which means turning poly mode on).
  313. *
  314. * @see #getMono
  315. * @see VoiceStatus
  316. */
  317. public void setMono(boolean on);
  318. /**
  319. * Obtains the current mono/poly mode.
  320. * @return <code>true</code> if mono mode is on, otherwise
  321. * <code>false</code> (meaning poly mode is on).
  322. *
  323. * @see #setMono(boolean)
  324. */
  325. public boolean getMono();
  326. /**
  327. * Turns omni mode on or off. In omni mode, the channel responds
  328. * to messages sent on all channels. When omni is off, the channel
  329. * responds only to messages sent on its channel number.
  330. * The default is omni off.
  331. *
  332. * @param on <code>true</code> to turn omni mode on, <code>false</code> to
  333. * turn it off.
  334. *
  335. * @see #getOmni
  336. * @see VoiceStatus
  337. */
  338. public void setOmni(boolean on);
  339. /**
  340. * Obtains the current omni mode status.
  341. * @return <code>true</code> if omni mode is on, otherwise
  342. * <code>false</code>.
  343. *
  344. * @see #setOmni(boolean)
  345. */
  346. public boolean getOmni();
  347. /**
  348. * Sets the mute state for this channel. A value of
  349. * <code>true</code> means the channel is to be muted, <code>false</code>
  350. * means the channel can sound (if other channels are not soloed).
  351. * <p>
  352. * Unlike {@link #allSoundOff()}, this method
  353. * applies to only a specific channel, not to all channels. Further, it
  354. * silences not only currently sounding notes, but also subsequently
  355. * received notes.
  356. *
  357. * @param mute the new mute state
  358. *
  359. * @see #getMute
  360. * @see #setSolo(boolean)
  361. */
  362. public void setMute(boolean mute);
  363. /**
  364. * Obtains the current mute state for this channel.
  365. * @return <code>true</code> the channel is muted, <code>false</code> if
  366. * not
  367. *
  368. * @see #setMute(boolean)
  369. */
  370. public boolean getMute();
  371. /**
  372. * Sets the solo state for this channel.
  373. * If <code>solo</code> is <code>true</code> only this channel
  374. * and other soloed channels will sound. If <code>solo</code>
  375. * is <code>false</code> then only other soloed channels will
  376. * sound, unless no channels are soloed, in which case all
  377. * unmuted channels will sound.
  378. *
  379. * @param soloState new solo state for the channel
  380. * @see #getSolo
  381. * @see #setMute(boolean)
  382. */
  383. public void setSolo(boolean soloState);
  384. /**
  385. * Obtains the current solo state for this channel.
  386. * @return <code>true</code> if soloed, <code>false</code> if not
  387. * @see #setSolo(boolean)
  388. */
  389. public boolean getSolo();
  390. }