Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/midi/MidiChannel.java
38830 views
/*1* Copyright (c) 1998, 2004, 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;262728/**29* A <code>MidiChannel</code> object represents a single MIDI channel.30* Generally, each <code>MidiChannel</code> method processes a like-named MIDI31* "channel voice" or "channel mode" message as defined by the MIDI specification. However,32* <code>MidiChannel</code> adds some "get" methods that retrieve the value33* most recently set by one of the standard MIDI channel messages. Similarly,34* methods for per-channel solo and mute have been added.35* <p>36* A <code>{@link Synthesizer}</code> object has a collection37* of <code>MidiChannels</code>, usually one for each of the 16 channels38* prescribed by the MIDI 1.0 specification. The <code>Synthesizer</code>39* generates sound when its <code>MidiChannels</code> receive40* <code>noteOn</code> messages.41* <p>42* See the MIDI 1.0 Specification for more information about the prescribed43* behavior of the MIDI channel messages, which are not exhaustively44* documented here. The specification is titled <code>MIDI Reference:45* The Complete MIDI 1.0 Detailed Specification</code>, and is published by46* the MIDI Manufacturer's Association (<a href = http://www.midi.org>47* http://www.midi.org</a>).48* <p>49* MIDI was originally a protocol for reporting the gestures of a keyboard50* musician. This genesis is visible in the <code>MidiChannel</code> API, which51* preserves such MIDI concepts as key number, key velocity, and key pressure.52* It should be understood that the MIDI data does not necessarily originate53* with a keyboard player (the source could be a different kind of musician, or54* software). Some devices might generate constant values for velocity55* and pressure, regardless of how the note was performed.56* Also, the MIDI specification often leaves it up to the57* synthesizer to use the data in the way the implementor sees fit. For58* example, velocity data need not always be mapped to volume and/or brightness.59*60* @see Synthesizer#getChannels61*62* @author David Rivas63* @author Kara Kytle64*/6566public interface MidiChannel {6768/**69* Starts the specified note sounding. The key-down velocity70* usually controls the note's volume and/or brightness.71* If <code>velocity</code> is zero, this method instead acts like72* {@link #noteOff(int)}, terminating the note.73*74* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)75* @param velocity the speed with which the key was depressed76*77* @see #noteOff(int, int)78*/79public void noteOn(int noteNumber, int velocity);8081/**82* Turns the specified note off. The key-up velocity, if not ignored, can83* be used to affect how quickly the note decays.84* In any case, the note might not die away instantaneously; its decay85* rate is determined by the internals of the <code>Instrument</code>.86* If the Hold Pedal (a controller; see87* {@link #controlChange(int, int) controlChange})88* is down, the effect of this method is deferred until the pedal is89* released.90*91*92* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)93* @param velocity the speed with which the key was released94*95* @see #noteOff(int)96* @see #noteOn97* @see #allNotesOff98* @see #allSoundOff99*/100public void noteOff(int noteNumber, int velocity);101102/**103* Turns the specified note off.104*105* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)106*107* @see #noteOff(int, int)108*/109public void noteOff(int noteNumber);110111/**112* Reacts to a change in the specified note's key pressure.113* Polyphonic key pressure114* allows a keyboard player to press multiple keys simultaneously, each115* with a different amount of pressure. The pressure, if not ignored,116* is typically used to vary such features as the volume, brightness,117* or vibrato of the note.118*119* It is possible that the underlying synthesizer120* does not support this MIDI message. In order121* to verify that <code>setPolyPressure</code>122* was successful, use <code>getPolyPressure</code>.123*124* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)125* @param pressure value for the specified key, from 0 to 127 (127 =126* maximum pressure)127*128* @see #getPolyPressure(int)129*/130public void setPolyPressure(int noteNumber, int pressure);131132/**133* Obtains the pressure with which the specified key is being depressed.134*135* @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)136*137* If the device does not support setting poly pressure,138* this method always returns 0. Calling139* <code>setPolyPressure</code> will have no effect then.140*141* @return the amount of pressure for that note, from 0 to 127142* (127 = maximum pressure)143*144* @see #setPolyPressure(int, int)145*/146public int getPolyPressure(int noteNumber);147148/**149* Reacts to a change in the keyboard pressure. Channel150* pressure indicates how hard the keyboard player is depressing151* the entire keyboard. This can be the maximum or152* average of the per-key pressure-sensor values, as set by153* <code>setPolyPressure</code>. More commonly, it is a measurement of154* a single sensor on a device that doesn't implement polyphonic key155* pressure. Pressure can be used to control various aspects of the sound,156* as described under {@link #setPolyPressure(int, int) setPolyPressure}.157*158* It is possible that the underlying synthesizer159* does not support this MIDI message. In order160* to verify that <code>setChannelPressure</code>161* was successful, use <code>getChannelPressure</code>.162*163* @param pressure the pressure with which the keyboard is being depressed,164* from 0 to 127 (127 = maximum pressure)165* @see #setPolyPressure(int, int)166* @see #getChannelPressure167*/168public void setChannelPressure(int pressure);169170/**171* Obtains the channel's keyboard pressure.172* If the device does not support setting channel pressure,173* this method always returns 0. Calling174* <code>setChannelPressure</code> will have no effect then.175*176* @return the amount of pressure for that note,177* from 0 to 127 (127 = maximum pressure)178*179* @see #setChannelPressure(int)180*/181public int getChannelPressure();182183/**184* Reacts to a change in the specified controller's value. A controller185* is some control other than a keyboard key, such as a186* switch, slider, pedal, wheel, or breath-pressure sensor.187* The MIDI 1.0 Specification provides standard numbers for typical188* controllers on MIDI devices, and describes the intended effect189* for some of the controllers.190* The way in which an191* <code>Instrument</code> reacts to a controller change may be192* specific to the <code>Instrument</code>.193* <p>194* The MIDI 1.0 Specification defines both 7-bit controllers195* and 14-bit controllers. Continuous controllers, such196* as wheels and sliders, typically have 14 bits (two MIDI bytes),197* while discrete controllers, such as switches, typically have 7 bits198* (one MIDI byte). Refer to the specification to see the199* expected resolution for each type of control.200* <p>201* Controllers 64 through 95 (0x40 - 0x5F) allow 7-bit precision.202* The value of a 7-bit controller is set completely by the203* <code>value</code> argument. An additional set of controllers204* provide 14-bit precision by using two controller numbers, one205* for the most significant 7 bits and another for the least significant206* 7 bits. Controller numbers 0 through 31 (0x00 - 0x1F) control the207* most significant 7 bits of 14-bit controllers; controller numbers208* 32 through 63 (0x20 - 0x3F) control the least significant 7 bits of209* these controllers. For example, controller number 7 (0x07) controls210* the upper 7 bits of the channel volume controller, and controller211* number 39 (0x27) controls the lower 7 bits.212* The value of a 14-bit controller is determined213* by the interaction of the two halves. When the most significant 7 bits214* of a controller are set (using controller numbers 0 through 31), the215* lower 7 bits are automatically set to 0. The corresponding controller216* number for the lower 7 bits may then be used to further modulate the217* controller value.218*219* It is possible that the underlying synthesizer220* does not support a specific controller message. In order221* to verify that a call to <code>controlChange</code>222* was successful, use <code>getController</code>.223*224* @param controller the controller number (0 to 127; see the MIDI225* 1.0 Specification for the interpretation)226* @param value the value to which the specified controller is changed (0 to 127)227*228* @see #getController(int)229*/230public void controlChange(int controller, int value);231232/**233* Obtains the current value of the specified controller. The return234* value is represented with 7 bits. For 14-bit controllers, the MSB and235* LSB controller value needs to be obtained separately. For example,236* the 14-bit value of the volume controller can be calculated by237* multiplying the value of controller 7 (0x07, channel volume MSB)238* with 128 and adding the239* value of controller 39 (0x27, channel volume LSB).240*241* If the device does not support setting a specific controller,242* this method returns 0 for that controller.243* Calling <code>controlChange</code> will have no effect then.244*245* @param controller the number of the controller whose value is desired.246* The allowed range is 0-127; see the MIDI247* 1.0 Specification for the interpretation.248*249* @return the current value of the specified controller (0 to 127)250*251* @see #controlChange(int, int)252*/253public int getController(int controller);254255/**256* Changes a program (patch). This selects a specific257* instrument from the currently selected bank of instruments.258* <p>259* The MIDI specification does not260* dictate whether notes that are already sounding should switch261* to the new instrument (timbre) or continue with their original timbre262* until terminated by a note-off.263* <p>264* The program number is zero-based (expressed from 0 to 127).265* Note that MIDI hardware displays and literature about MIDI266* typically use the range 1 to 128 instead.267*268* It is possible that the underlying synthesizer269* does not support a specific program. In order270* to verify that a call to <code>programChange</code>271* was successful, use <code>getProgram</code>.272*273* @param program the program number to switch to (0 to 127)274*275* @see #programChange(int, int)276* @see #getProgram()277*/278public void programChange(int program);279280/**281* Changes the program using bank and program (patch) numbers.282*283* It is possible that the underlying synthesizer284* does not support a specific bank, or program. In order285* to verify that a call to <code>programChange</code>286* was successful, use <code>getProgram</code> and287* <code>getController</code>.288* Since banks are changed by way of control changes,289* you can verify the current bank with the following290* statement:291* <pre>292* int bank = (getController(0) * 128)293* + getController(32);294* </pre>295*296* @param bank the bank number to switch to (0 to 16383)297* @param program the program (patch) to use in the specified bank (0 to 127)298* @see #programChange(int)299* @see #getProgram()300*/301public void programChange(int bank, int program);302303/**304* Obtains the current program number for this channel.305* @return the program number of the currently selected patch306* @see Patch#getProgram307* @see Synthesizer#loadInstrument308* @see #programChange(int)309*/310public int getProgram();311312/**313* Changes the pitch offset for all notes on this channel.314* This affects all currently sounding notes as well as subsequent ones.315* (For pitch bend to cease, the value needs to be reset to the316* center position.)317* <p> The MIDI specification318* stipulates that pitch bend be a 14-bit value, where zero319* is maximum downward bend, 16383 is maximum upward bend, and320* 8192 is the center (no pitch bend). The actual321* amount of pitch change is not specified; it can be changed by322* a pitch-bend sensitivity setting. However, the General MIDI323* specification says that the default range should be two semitones324* up and down from center.325*326* It is possible that the underlying synthesizer327* does not support this MIDI message. In order328* to verify that <code>setPitchBend</code>329* was successful, use <code>getPitchBend</code>.330*331* @param bend the amount of pitch change, as a nonnegative 14-bit value332* (8192 = no bend)333*334* @see #getPitchBend335*/336public void setPitchBend(int bend);337338/**339* Obtains the upward or downward pitch offset for this channel.340* If the device does not support setting pitch bend,341* this method always returns 8192. Calling342* <code>setPitchBend</code> will have no effect then.343*344* @return bend amount, as a nonnegative 14-bit value (8192 = no bend)345*346* @see #setPitchBend(int)347*/348public int getPitchBend();349350/**351* Resets all the implemented controllers to their default values.352*353* @see #controlChange(int, int)354*/355public void resetAllControllers();356357/**358* Turns off all notes that are currently sounding on this channel.359* The notes might not die away instantaneously; their decay360* rate is determined by the internals of the <code>Instrument</code>.361* If the Hold Pedal controller (see362* {@link #controlChange(int, int) controlChange})363* is down, the effect of this method is deferred until the pedal is364* released.365*366* @see #allSoundOff367* @see #noteOff(int)368*/369public void allNotesOff();370371/**372* Immediately turns off all sounding notes on this channel, ignoring the373* state of the Hold Pedal and the internal decay rate of the current374* <code>Instrument</code>.375*376* @see #allNotesOff377*/378public void allSoundOff();379380/**381* Turns local control on or off. The default is for local control382* to be on. The "on" setting means that if a device is capable383* of both synthesizing sound and transmitting MIDI messages,384* it will synthesize sound in response to the note-on and385* note-off messages that it itself transmits. It will also respond386* to messages received from other transmitting devices.387* The "off" setting means that the synthesizer will ignore its388* own transmitted MIDI messages, but not those received from other devices.389*390* It is possible that the underlying synthesizer391* does not support local control. In order392* to verify that a call to <code>localControl</code>393* was successful, check the return value.394*395* @param on <code>true</code> to turn local control on, <code>false</code>396* to turn local control off397* @return the new local-control value, or false398* if local control is not supported399*400*/401public boolean localControl(boolean on);402403/**404* Turns mono mode on or off. In mono mode, the channel synthesizes405* only one note at a time. In poly mode (identical to mono mode off),406* the channel can synthesize multiple notes simultaneously.407* The default is mono off (poly mode on).408* <p>409* "Mono" is short for the word "monophonic," which in this context410* is opposed to the word "polyphonic" and refers to a single synthesizer411* voice per MIDI channel. It412* has nothing to do with how many audio channels there might be413* (as in "monophonic" versus "stereophonic" recordings).414*415* It is possible that the underlying synthesizer416* does not support mono mode. In order417* to verify that a call to <code>setMono</code>418* was successful, use <code>getMono</code>.419*420* @param on <code>true</code> to turn mono mode on, <code>false</code> to421* turn it off (which means turning poly mode on).422*423* @see #getMono424* @see VoiceStatus425*/426public void setMono(boolean on);427428/**429* Obtains the current mono/poly mode.430* Synthesizers that do not allow changing mono/poly mode431* will always return the same value, regardless432* of calls to <code>setMono</code>.433* @return <code>true</code> if mono mode is on, otherwise434* <code>false</code> (meaning poly mode is on).435*436* @see #setMono(boolean)437*/438public boolean getMono();439440/**441* Turns omni mode on or off. In omni mode, the channel responds442* to messages sent on all channels. When omni is off, the channel443* responds only to messages sent on its channel number.444* The default is omni off.445*446* It is possible that the underlying synthesizer447* does not support omni mode. In order448* to verify that <code>setOmni</code>449* was successful, use <code>getOmni</code>.450*451* @param on <code>true</code> to turn omni mode on, <code>false</code> to452* turn it off.453*454* @see #getOmni455* @see VoiceStatus456*/457public void setOmni(boolean on);458459/**460* Obtains the current omni mode.461* Synthesizers that do not allow changing the omni mode462* will always return the same value, regardless463* of calls to <code>setOmni</code>.464* @return <code>true</code> if omni mode is on, otherwise465* <code>false</code> (meaning omni mode is off).466*467* @see #setOmni(boolean)468*/469public boolean getOmni();470471/**472* Sets the mute state for this channel. A value of473* <code>true</code> means the channel is to be muted, <code>false</code>474* means the channel can sound (if other channels are not soloed).475* <p>476* Unlike {@link #allSoundOff()}, this method477* applies to only a specific channel, not to all channels. Further, it478* silences not only currently sounding notes, but also subsequently479* received notes.480*481* It is possible that the underlying synthesizer482* does not support muting channels. In order483* to verify that a call to <code>setMute</code>484* was successful, use <code>getMute</code>.485*486* @param mute the new mute state487*488* @see #getMute489* @see #setSolo(boolean)490*/491public void setMute(boolean mute);492493/**494* Obtains the current mute state for this channel.495* If the underlying synthesizer does not support496* muting this channel, this method always returns497* <code>false</code>.498*499* @return <code>true</code> the channel is muted,500* or <code>false</code> if not501*502* @see #setMute(boolean)503*/504public boolean getMute();505506/**507* Sets the solo state for this channel.508* If <code>solo</code> is <code>true</code> only this channel509* and other soloed channels will sound. If <code>solo</code>510* is <code>false</code> then only other soloed channels will511* sound, unless no channels are soloed, in which case all512* unmuted channels will sound.513*514* It is possible that the underlying synthesizer515* does not support solo channels. In order516* to verify that a call to <code>setSolo</code>517* was successful, use <code>getSolo</code>.518*519* @param soloState new solo state for the channel520* @see #getSolo()521*/522public void setSolo(boolean soloState);523524/**525* Obtains the current solo state for this channel.526* If the underlying synthesizer does not support527* solo on this channel, this method always returns528* <code>false</code>.529*530* @return <code>true</code> the channel is solo,531* or <code>false</code> if not532*533* @see #setSolo(boolean)534*/535public boolean getSolo();536}537538539