Path: blob/master/src/java.desktop/share/classes/javax/sound/midi/MidiChannel.java
41159 views
/*1* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.midi;2627/**28* A {@code MidiChannel} object represents a single MIDI channel. Generally,29* each {@code MidiChannel} method processes a like-named MIDI "channel voice"30* or "channel mode" message as defined by the MIDI specification. However,31* {@code MidiChannel} adds some "get" methods that retrieve the value most32* recently set by one of the standard MIDI channel messages. Similarly, methods33* for per-channel solo and mute have been added.34* <p>35* A {@link Synthesizer} object has a collection of {@code MidiChannels},36* usually one for each of the 16 channels prescribed by the MIDI 1.037* specification. The {@code Synthesizer} generates sound when its38* {@code MidiChannels} receive {@code noteOn} messages.39* <p>40* See the MIDI 1.0 Specification for more information about the prescribed41* behavior of the MIDI channel messages, which are not exhaustively documented42* here. The specification is titled43* {@code MIDI Reference: The Complete MIDI 1.0 Detailed Specification}, and is44* published by the MIDI Manufacturer's Association45* (<a href = http://www.midi.org>http://www.midi.org</a>).46* <p>47* MIDI was originally a protocol for reporting the gestures of a keyboard48* musician. This genesis is visible in the {@code MidiChannel} API, which49* preserves such MIDI concepts as key number, key velocity, and key pressure.50* It should be understood that the MIDI data does not necessarily originate51* with a keyboard player (the source could be a different kind of musician, or52* software). Some devices might generate constant values for velocity and53* pressure, regardless of how the note was performed. Also, the MIDI54* specification often leaves it up to the synthesizer to use the data in the55* way the implementor sees fit. For example, velocity data need not always be56* mapped to volume and/or brightness.57*58* @author David Rivas59* @author Kara Kytle60* @see Synthesizer#getChannels61*/62public interface MidiChannel {6364/**65* Starts the specified note sounding. The key-down velocity usually66* controls the note's volume and/or brightness. If {@code velocity} is67* zero, this method instead acts like {@link #noteOff(int)}, terminating68* the note.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 depressed72* @see #noteOff(int, int)73*/74void noteOn(int noteNumber, int velocity);7576/**77* Turns the specified note off. The key-up velocity, if not ignored, can be78* used to affect how quickly the note decays. In any case, the note might79* not die away instantaneously; its decay rate is determined by the80* internals of the {@code Instrument}. If the Hold Pedal (a controller; see81* {@link #controlChange(int, int) controlChange}) is down, the effect of82* this method is deferred until the pedal is released.83*84* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)85* @param velocity the speed with which the key was released86* @see #noteOff(int)87* @see #noteOn88* @see #allNotesOff89* @see #allSoundOff90*/91void noteOff(int noteNumber, int velocity);9293/**94* Turns the specified note off.95*96* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)97* @see #noteOff(int, int)98*/99void noteOff(int noteNumber);100101/**102* Reacts to a change in the specified note's key pressure. Polyphonic key103* pressure allows a keyboard player to press multiple keys simultaneously,104* each with a different amount of pressure. The pressure, if not ignored,105* is typically used to vary such features as the volume, brightness, or106* vibrato of the note.107* <p>108* It is possible that the underlying synthesizer does not support this MIDI109* message. In order to verify that {@code setPolyPressure} was successful,110* use {@code getPolyPressure}.111*112* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)113* @param pressure value for the specified key, from 0 to 127114* (127 = maximum pressure)115* @see #getPolyPressure(int)116*/117void setPolyPressure(int noteNumber, int pressure);118119/**120* Obtains the pressure with which the specified key is being depressed.121* <p>122* If the device does not support setting poly pressure, this method always123* returns 0. Calling {@code setPolyPressure} will have no effect then.124*125* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)126* @return the amount of pressure for that note, from 0 to 127127* (127 = maximum pressure)128* @see #setPolyPressure(int, int)129*/130int getPolyPressure(int noteNumber);131132/**133* Reacts to a change in the keyboard pressure. Channel pressure indicates134* how hard the keyboard player is depressing the entire keyboard. This can135* be the maximum or average of the per-key pressure-sensor values, as set136* by {@code setPolyPressure}. More commonly, it is a measurement of a137* single sensor on a device that doesn't implement polyphonic key pressure.138* Pressure can be used to control various aspects of the sound, as139* described under {@link #setPolyPressure(int, int) setPolyPressure}.140* <p>141* It is possible that the underlying synthesizer does not support this MIDI142* message. In order to verify that {@code setChannelPressure} was143* successful, use {@code getChannelPressure}.144*145* @param pressure the pressure with which the keyboard is being depressed,146* from 0 to 127 (127 = maximum pressure)147* @see #setPolyPressure(int, int)148* @see #getChannelPressure149*/150void setChannelPressure(int pressure);151152/**153* Obtains the channel's keyboard pressure.154* <p>155* If the device does not support setting channel pressure, this method156* always returns 0. Calling {@code setChannelPressure} will have no effect157* then.158*159* @return the amount of pressure for that note, from 0 to 127160* (127 = maximum pressure)161* @see #setChannelPressure(int)162*/163int getChannelPressure();164165/**166* Reacts to a change in the specified controller's value. A controller is167* some control other than a keyboard key, such as a switch, slider, pedal,168* wheel, or breath-pressure sensor. The MIDI 1.0 Specification provides169* standard numbers for typical controllers on MIDI devices, and describes170* the intended effect for some of the controllers. The way in which an171* {@code Instrument} reacts to a controller change may be specific to the172* {@code Instrument}.173* <p>174* The MIDI 1.0 Specification defines both 7-bit controllers and 14-bit175* controllers. Continuous controllers, such as wheels and sliders,176* typically have 14 bits (two MIDI bytes), while discrete controllers, such177* as switches, typically have 7 bits (one MIDI byte). Refer to the178* specification to see the expected resolution for each type of control.179* <p>180* Controllers 64 through 95 (0x40 - 0x5F) allow 7-bit precision. The value181* of a 7-bit controller is set completely by the {@code value} argument. An182* additional set of controllers provide 14-bit precision by using two183* controller numbers, one for the most significant 7 bits and another for184* the least significant 7 bits. Controller numbers 0 through 31185* (0x00 - 0x1F) control the most significant 7 bits of 14-bit controllers;186* controller numbers 32 through 63 (0x20 - 0x3F) control the least187* significant 7 bits of these controllers. For example, controller number 7188* (0x07) controls the upper 7 bits of the channel volume controller, and189* controller number 39 (0x27) controls the lower 7 bits. The value of a190* 14-bit controller is determined by the interaction of the two halves.191* When the most significant 7 bits of a controller are set (using192* controller numbers 0 through 31), the lower 7 bits are automatically set193* to 0. The corresponding controller number for the lower 7 bits may then194* be used to further modulate the controller value.195* <p>196* It is possible that the underlying synthesizer does not support a197* specific controller message. In order to verify that a call to198* {@code controlChange} was successful, use {@code getController}.199*200* @param controller the controller number (0 to 127; see the MIDI 1.0201* Specification for the interpretation)202* @param value the value to which the specified controller is changed203* (0 to 127)204* @see #getController(int)205*/206void controlChange(int controller, int value);207208/**209* Obtains the current value of the specified controller. The return value210* is represented with 7 bits. For 14-bit controllers, the MSB and LSB211* controller value needs to be obtained separately. For example, the 14-bit212* value of the volume controller can be calculated by multiplying the value213* of controller 7 (0x07, channel volume MSB) with 128 and adding the value214* of controller 39 (0x27, channel volume LSB).215* <p>216* If the device does not support setting a specific controller, this method217* returns 0 for that controller. Calling {@code controlChange} will have no218* effect then.219*220* @param controller the number of the controller whose value is desired.221* The allowed range is 0-127; see the MIDI 1.0 Specification for222* the interpretation.223* @return the current value of the specified controller (0 to 127)224* @see #controlChange(int, int)225*/226int getController(int controller);227228/**229* Changes a program (patch). This selects a specific instrument from the230* currently selected bank of instruments.231* <p>232* The MIDI specification does not dictate whether notes that are already233* sounding should switch to the new instrument (timbre) or continue with234* their original timbre until terminated by a note-off.235* <p>236* The program number is zero-based (expressed from 0 to 127). Note that237* MIDI hardware displays and literature about MIDI typically use the range238* 1 to 128 instead.239* <p>240* It is possible that the underlying synthesizer does not support a241* specific program. In order to verify that a call to {@code programChange}242* was successful, use {@code getProgram}.243*244* @param program the program number to switch to (0 to 127)245* @see #programChange(int, int)246* @see #getProgram()247*/248void programChange(int program);249250/**251* Changes the program using bank and program (patch) numbers.252* <p>253* It is possible that the underlying synthesizer does not support a254* specific bank, or program. In order to verify that a call to255* {@code programChange} was successful, use {@code getProgram} and256* {@code getController}. Since banks are changed by way of control changes,257* you can verify the current bank with the following statement:258* <pre>259* int bank = (getController(0) * 128) + getController(32);260* </pre>261*262* @param bank the bank number to switch to (0 to 16383)263* @param program the program (patch) to use in the specified bank264* (0 to 127)265* @see #programChange(int)266* @see #getProgram()267*/268void programChange(int bank, int program);269270/**271* Obtains the current program number for this channel.272*273* @return the program number of the currently selected patch274* @see Patch#getProgram275* @see Synthesizer#loadInstrument276* @see #programChange(int)277*/278int getProgram();279280/**281* Changes the pitch offset for all notes on this channel. This affects all282* currently sounding notes as well as subsequent ones. (For pitch bend to283* cease, the value needs to be reset to the center position.)284* <p>285* The MIDI specification stipulates that pitch bend be a 14-bit value,286* where zero is maximum downward bend, 16383 is maximum upward bend, and287* 8192 is the center (no pitch bend). The actual amount of pitch change is288* not specified; it can be changed by a pitch-bend sensitivity setting.289* However, the General MIDI specification says that the default range290* should be two semitones up and down from center.291* <p>292* It is possible that the underlying synthesizer does not support this MIDI293* message. In order to verify that {@code setPitchBend} was successful, use294* {@code getPitchBend}.295*296* @param bend the amount of pitch change, as a nonnegative 14-bit value297* (8192 = no bend)298* @see #getPitchBend299*/300void setPitchBend(int bend);301302/**303* Obtains the upward or downward pitch offset for this channel. If the304* device does not support setting pitch bend, this method always returns305* 8192. Calling {@code setPitchBend} will have no effect then.306*307* @return bend amount, as a nonnegative 14-bit value (8192 = no bend)308* @see #setPitchBend(int)309*/310int getPitchBend();311312/**313* Resets all the implemented controllers to their default values.314*315* @see #controlChange(int, int)316*/317void resetAllControllers();318319/**320* Turns off all notes that are currently sounding on this channel. The321* notes might not die away instantaneously; their decay rate is determined322* by the internals of the {@code Instrument}. If the Hold Pedal controller323* (see {@link #controlChange(int, int) controlChange}) is down, the effect324* of this method is deferred until the pedal is released.325*326* @see #allSoundOff327* @see #noteOff(int)328*/329void allNotesOff();330331/**332* Immediately turns off all sounding notes on this channel, ignoring the333* state of the Hold Pedal and the internal decay rate of the current334* {@code Instrument}.335*336* @see #allNotesOff337*/338void allSoundOff();339340/**341* Turns local control on or off. The default is for local control to be on.342* The "on" setting means that if a device is capable of both synthesizing343* sound and transmitting MIDI messages, it will synthesize sound in344* response to the note-on and note-off messages that it itself transmits.345* It will also respond to messages received from other transmitting346* devices. The "off" setting means that the synthesizer will ignore its own347* transmitted MIDI messages, but not those received from other devices.348* <p>349* It is possible that the underlying synthesizer does not support local350* control. In order to verify that a call to {@code localControl} was351* successful, check the return value.352*353* @param on {@code true} to turn local control on, {@code false} to turn354* local control off355* @return the new local-control value, or false if local control is not356* supported357*/358boolean localControl(boolean on);359360/**361* Turns mono mode on or off. In mono mode, the channel synthesizes only one362* note at a time. In poly mode (identical to mono mode off), the channel363* can synthesize multiple notes simultaneously. The default is mono off364* (poly mode on).365* <p>366* "Mono" is short for the word "monophonic," which in this context is367* opposed to the word "polyphonic" and refers to a single synthesizer voice368* per MIDI channel. It has nothing to do with how many audio channels there369* might be (as in "monophonic" versus "stereophonic" recordings).370* <p>371* It is possible that the underlying synthesizer does not support mono372* mode. In order to verify that a call to {@code setMono} was successful,373* use {@code getMono}.374*375* @param on {@code true} to turn mono mode on, {@code false} to turn it376* off (which means turning poly mode on)377* @see #getMono378* @see VoiceStatus379*/380void setMono(boolean on);381382/**383* Obtains the current mono/poly mode. Synthesizers that do not allow384* changing mono/poly mode will always return the same value, regardless of385* calls to {@code setMono}.386*387* @return {@code true} if mono mode is on, otherwise {@code false} (meaning388* poly mode is on)389* @see #setMono(boolean)390*/391boolean getMono();392393/**394* Turns omni mode on or off. In omni mode, the channel responds to messages395* sent on all channels. When omni is off, the channel responds only to396* messages sent on its channel number. The default is omni off.397* <p>398* It is possible that the underlying synthesizer does not support omni399* mode. In order to verify that {@code setOmni} was successful, use400* {@code getOmni}.401*402* @param on {@code true} to turn omni mode on, {@code false} to turn it403* off404* @see #getOmni405* @see VoiceStatus406*/407void setOmni(boolean on);408409/**410* Obtains the current omni mode. Synthesizers that do not allow changing411* the omni mode will always return the same value, regardless of calls to412* {@code setOmni}.413*414* @return {@code true} if omni mode is on, otherwise {@code false} (meaning415* omni mode is off)416* @see #setOmni(boolean)417*/418boolean getOmni();419420/**421* Sets the mute state for this channel. A value of {@code true} means the422* channel is to be muted, {@code false} means the channel can sound (if423* other channels are not soloed).424* <p>425* Unlike {@link #allSoundOff()}, this method applies to only a specific426* channel, not to all channels. Further, it silences not only currently427* sounding notes, but also subsequently received notes.428* <p>429* It is possible that the underlying synthesizer does not support muting430* channels. In order to verify that a call to {@code setMute} was431* successful, use {@code getMute}.432*433* @param mute the new mute state434* @see #getMute435* @see #setSolo(boolean)436*/437void setMute(boolean mute);438439/**440* Obtains the current mute state for this channel. If the underlying441* synthesizer does not support muting this channel, this method always442* returns {@code false}.443*444* @return {@code true} the channel is muted, or {@code false} if not445* @see #setMute(boolean)446*/447boolean getMute();448449/**450* Sets the solo state for this channel. If {@code solo} is {@code true}451* only this channel and other soloed channels will sound. If {@code solo}452* is {@code false} then only other soloed channels will sound, unless no453* channels are soloed, in which case all unmuted channels will sound.454* <p>455* It is possible that the underlying synthesizer does not support solo456* channels. In order to verify that a call to {@code setSolo} was457* successful, use {@code getSolo}.458*459* @param soloState new solo state for the channel460* @see #getSolo()461*/462void setSolo(boolean soloState);463464/**465* Obtains the current solo state for this channel. If the underlying466* synthesizer does not support solo on this channel, this method always467* returns {@code false}.468*469* @return {@code true} the channel is solo, or {@code false} if not470* @see #setSolo(boolean)471*/472boolean getSolo();473}474475476