KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > midi > MidiChannel


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
8 package javax.sound.midi;
9
10
11 /**
12  * A <code>MidiChannel</code> object represents a single MIDI channel.
13  * Generally, each <code>MidiChannel</code> method processes a like-named MIDI
14  * "channel voice" or "channel mode" message as defined by the MIDI specification. However,
15  * <code>MidiChannel</code> adds some "get" methods that retrieve the value
16  * most recently set by one of the standard MIDI channel messages. Similarly,
17  * methods for per-channel solo and mute have been added.
18  * <p>
19  * A <code>{@link Synthesizer}</code> object has a collection
20  * of <code>MidiChannels</code>, usually one for each of the 16 channels
21  * prescribed by the MIDI 1.0 specification. The <code>Synthesizer</code>
22  * generates sound when its <code>MidiChannels</code> receive
23  * <code>noteOn</code> messages.
24  * <p>
25  * See the MIDI 1.0 Specification for more information about the prescribed
26  * behavior of the MIDI channel messages, which are not exhaustively
27  * documented here. The specification is titled <code>MIDI Reference:
28  * The Complete MIDI 1.0 Detailed Specification</code>, and is published by
29  * the MIDI Manufacturer's Association (<a href = http://www.midi.org>
30  * http://www.midi.org</a>).
31  * <p>
32  * MIDI was originally a protocol for reporting the gestures of a keyboard
33  * musician. This genesis is visible in the <code>MidiChannel</code> API, which
34  * preserves such MIDI concepts as key number, key velocity, and key pressure.
35  * It should be understood that the MIDI data does not necessarily originate
36  * with a keyboard player (the source could be a different kind of musician, or
37  * software). Some devices might generate constant values for velocity
38  * and pressure, regardless of how the note was performed.
39  * Also, the MIDI specification often leaves it up to the
40  * synthesizer to use the data in the way the implementor sees fit. For
41  * example, velocity data need not always be mapped to volume and/or brightness.
42  *
43  * @see Synthesizer#getChannels
44  *
45  * @version 1.43, 04/22/04
46  * @author David Rivas
47  * @author Kara Kytle
48  */

49
50 public interface MidiChannel {
51
52     /**
53      * Starts the specified note sounding. The key-down velocity
54      * usually controls the note's volume and/or brightness.
55      * If <code>velocity</code> is zero, this method instead acts like
56      * {@link #noteOff(int)}, terminating the note.
57      *
58      * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
59      * @param velocity the speed with which the key was depressed
60      *
61      * @see #noteOff(int, int)
62      */

63     public void noteOn(int noteNumber, int velocity);
64
65     /**
66      * Turns the specified note off. The key-up velocity, if not ignored, can
67      * be used to affect how quickly the note decays.
68      * In any case, the note might not die away instantaneously; its decay
69      * rate is determined by the internals of the <code>Instrument</code>.
70      * If the Hold Pedal (a controller; see
71      * {@link #controlChange(int, int) controlChange})
72      * is down, the effect of this method is deferred until the pedal is
73      * released.
74      *
75      *
76      * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
77      * @param velocity the speed with which the key was released
78      *
79      * @see #noteOff(int)
80      * @see #noteOn
81      * @see #allNotesOff
82      * @see #allSoundOff
83      */

84     public void noteOff(int noteNumber, int velocity);
85
86     /**
87      * Turns the specified note off.
88      *
89      * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
90      *
91      * @see #noteOff(int, int)
92      */

93     public void noteOff(int noteNumber);
94
95     /**
96      * Reacts to a change in the specified note's key pressure.
97      * Polyphonic key pressure
98      * allows a keyboard player to press multiple keys simultaneously, each
99      * with a different amount of pressure. The pressure, if not ignored,
100      * is typically used to vary such features as the volume, brightness,
101      * or vibrato of the note.
102      *
103      * It is possible that the underlying synthesizer
104      * does not support this MIDI message. In order
105      * to verify that <code>setPolyPressure</code>
106      * was successful, use <code>getPolyPressure</code>.
107      *
108      * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
109      * @param pressure value for the specified key, from 0 to 127 (127 =
110      * maximum pressure)
111      *
112      * @see #getPolyPressure(int)
113      */

114     public void setPolyPressure(int noteNumber, int pressure);
115
116     /**
117      * Obtains the pressure with which the specified key is being depressed.
118      *
119      * @param noteNumber the MIDI note number, from 0 to 127 (60 = Middle C)
120      *
121      * If the device does not support setting poly pressure,
122      * this method always returns 0. Calling
123      * <code>setPolyPressure</code> will have no effect then.
124      *
125      * @return the amount of pressure for that note, from 0 to 127
126      * (127 = maximum pressure)
127      *
128      * @see #setPolyPressure(int, int)
129      */

130     public int getPolyPressure(int noteNumber);
131
132     /**
133      * Reacts to a change in the keyboard pressure. Channel
134      * pressure indicates how hard the keyboard player is depressing
135      * the entire keyboard. This can be the maximum or
136      * average of the per-key pressure-sensor values, as set by
137      * <code>setPolyPressure</code>. More commonly, it is a measurement of
138      * a single sensor on a device that doesn't implement polyphonic key
139      * pressure. Pressure can be used to control various aspects of the sound,
140      * as described under {@link #setPolyPressure(int, int) setPolyPressure}.
141      *
142      * It is possible that the underlying synthesizer
143      * does not support this MIDI message. In order
144      * to verify that <code>setChannelPressure</code>
145      * was successful, use <code>getChannelPressure</code>.
146      *
147      * @param pressure the pressure with which the keyboard is being depressed,
148      * from 0 to 127 (127 = maximum pressure)
149      * @see #setPolyPressure(int, int)
150      * @see #getChannelPressure
151      */

152     public void setChannelPressure(int pressure);
153
154     /**
155      * Obtains the channel's keyboard pressure.
156      * If the device does not support setting channel pressure,
157      * this method always returns 0. Calling
158      * <code>setChannelPressure</code> will have no effect then.
159      *
160      * @return the amount of pressure for that note,
161      * from 0 to 127 (127 = maximum pressure)
162      *
163      * @see #setChannelPressure(int)
164      */

165     public int getChannelPressure();
166
167     /**
168      * Reacts to a change in the specified controller's value. A controller
169      * is some control other than a keyboard key, such as a
170      * switch, slider, pedal, wheel, or breath-pressure sensor.
171      * The MIDI 1.0 Specification provides standard numbers for typical
172      * controllers on MIDI devices, and describes the intended effect
173      * for some of the controllers.
174      * The way in which an
175      * <code>Instrument</code> reacts to a controller change may be
176      * specific to the <code>Instrument</code>.
177      * <p>
178      * The MIDI 1.0 Specification defines both 7-bit controllers
179      * and 14-bit controllers. Continuous controllers, such
180      * as wheels and sliders, typically have 14 bits (two MIDI bytes),
181      * while discrete controllers, such as switches, typically have 7 bits
182      * (one MIDI byte). Refer to the specification to see the
183      * expected resolution for each type of control.
184      * <p>
185      * Controllers 64 through 95 (0x40 - 0x5F) allow 7-bit precision.
186      * The value of a 7-bit controller is set completely by the
187      * <code>value</code> argument. An additional set of controllers
188      * provide 14-bit precision by using two controller numbers, one
189      * for the most significant 7 bits and another for the least significant
190      * 7 bits. Controller numbers 0 through 31 (0x00 - 0x1F) control the
191      * most significant 7 bits of 14-bit controllers; controller numbers
192      * 32 through 63 (0x20 - 0x3F) control the least significant 7 bits of
193      * these controllers. For example, controller number 7 (0x07) controls
194      * the upper 7 bits of the channel volume controller, and controller
195      * number 39 (0x27) controls the lower 7 bits.
196      * The value of a 14-bit controller is determined
197      * by the interaction of the two halves. When the most significant 7 bits
198      * of a controller are set (using controller numbers 0 through 31), the
199      * lower 7 bits are automatically set to 0. The corresponding controller
200      * number for the lower 7 bits may then be used to further modulate the
201      * controller value.
202      *
203      * It is possible that the underlying synthesizer
204      * does not support a specific controller message. In order
205      * to verify that a call to <code>controlChange</code>
206      * was successful, use <code>getController</code>.
207      *
208      * @param controller the controller number (0 to 127; see the MIDI
209      * 1.0 Specification for the interpretation)
210      * @param value the value to which the specified controller is changed (0 to 127)
211      *
212      * @see #getController(int)
213      */

214     public void controlChange(int controller, int value);
215
216     /**
217      * Obtains the current value of the specified controller. The return
218      * value is represented with 7 bits. For 14-bit controllers, the MSB and
219      * LSB controller value needs to be obtained separately. For example,
220      * the 14-bit value of the volume controller can be calculated by
221      * multiplying the value of controller 7 (0x07, channel volume MSB)
222      * with 128 and adding the
223      * value of controller 39 (0x27, channel volume LSB).
224      *
225      * If the device does not support setting a specific controller,
226      * this method returns 0 for that controller.
227      * Calling <code>controlChange</code> will have no effect then.
228      *
229      * @param controller the number of the controller whose value is desired.
230      * The allowed range is 0-127; see the MIDI
231      * 1.0 Specification for the interpretation.
232      *
233      * @return the current value of the specified controller (0 to 127)
234      *
235      * @see #controlChange(int, int)
236      */

237     public int getController(int controller);
238
239     /**
240      * Changes a program (patch). This selects a specific
241      * instrument from the currently selected bank of instruments.
242      * <p>
243      * The MIDI specification does not
244      * dictate whether notes that are already sounding should switch
245      * to the new instrument (timbre) or continue with their original timbre
246      * until terminated by a note-off.
247      * <p>
248      * The program number is zero-based (expressed from 0 to 127).
249      * Note that MIDI hardware displays and literature about MIDI
250      * typically use the range 1 to 128 instead.
251      *
252      * It is possible that the underlying synthesizer
253      * does not support a specific program. In order
254      * to verify that a call to <code>programChange</code>
255      * was successful, use <code>getProgram</code>.
256      *
257      * @param program the program number to switch to (0 to 127)
258      *
259      * @see #programChange(int, int)
260      * @see #getProgram()
261      */

262     public void programChange(int program);
263
264     /**
265      * Changes the program using bank and program (patch) numbers.
266      *
267      * It is possible that the underlying synthesizer
268      * does not support a specific bank, or program. In order
269      * to verify that a call to <code>programChange</code>
270      * was successful, use <code>getProgram</code> and
271      * <code>getController</code>.
272      * Since banks are changed by way of control changes,
273      * you can verify the current bank with the following
274      * statement:
275      * <pre>
276      * int bank = (getController(0) * 128)
277      * + getController(32);
278      * </pre>
279      *
280      * @param bank the bank number to switch to (0 to 16383)
281      * @param program the program (patch) to use in the specified bank (0 to 127)
282      * @see #programChange(int)
283      * @see #getProgram()
284      */

285     public void programChange(int bank, int program);
286
287     /**
288      * Obtains the current program number for this channel.
289      * @return the program number of the currently selected patch
290      * @see Patch#getProgram
291      * @see Synthesizer#loadInstrument
292      * @see #programChange(int)
293      */

294     public int getProgram();
295
296     /**
297      * Changes the pitch offset for all notes on this channel.
298      * This affects all currently sounding notes as well as subsequent ones.
299      * (For pitch bend to cease, the value needs to be reset to the
300      * center position.)
301      * <p> The MIDI specification
302      * stipulates that pitch bend be a 14-bit value, where zero
303      * is maximum downward bend, 16383 is maximum upward bend, and
304      * 8192 is the center (no pitch bend). The actual
305      * amount of pitch change is not specified; it can be changed by
306      * a pitch-bend sensitivity setting. However, the General MIDI
307      * specification says that the default range should be two semitones
308      * up and down from center.
309      *
310      * It is possible that the underlying synthesizer
311      * does not support this MIDI message. In order
312      * to verify that <code>setPitchBend</code>
313      * was successful, use <code>getPitchBend</code>.
314      *
315      * @param bend the amount of pitch change, as a nonnegative 14-bit value
316      * (8192 = no bend)
317      *
318      * @see #getPitchBend
319      */

320     public void setPitchBend(int bend);
321
322     /**
323      * Obtains the upward or downward pitch offset for this channel.
324      * If the device does not support setting pitch bend,
325      * this method always returns 8192. Calling
326      * <code>setPitchBend</code> will have no effect then.
327      *
328      * @return bend amount, as a nonnegative 14-bit value (8192 = no bend)
329      *
330      * @see #setPitchBend(int)
331      */

332     public int getPitchBend();
333
334     /**
335      * Resets all the implemented controllers to their default values.
336      *
337      * @see #controlChange(int, int)
338      */

339     public void resetAllControllers();
340
341     /**
342      * Turns off all notes that are currently sounding on this channel.
343      * The notes might not die away instantaneously; their decay
344      * rate is determined by the internals of the <code>Instrument</code>.
345      * If the Hold Pedal controller (see
346      * {@link #controlChange(int, int) controlChange})
347      * is down, the effect of this method is deferred until the pedal is
348      * released.
349      *
350      * @see #allSoundOff
351      * @see #noteOff(int)
352      */

353     public void allNotesOff();
354
355     /**
356      * Immediately turns off all sounding notes on this channel, ignoring the
357      * state of the Hold Pedal and the internal decay rate of the current
358      * <code>Instrument</code>.
359      *
360      * @see #allNotesOff
361      */

362     public void allSoundOff();
363
364     /**
365      * Turns local control on or off. The default is for local control
366      * to be on. The "on" setting means that if a device is capable
367      * of both synthesizing sound and transmitting MIDI messages,
368      * it will synthesize sound in response to the note-on and
369      * note-off messages that it itself transmits. It will also respond
370      * to messages received from other transmitting devices.
371      * The "off" setting means that the synthesizer will ignore its
372      * own transmitted MIDI messages, but not those received from other devices.
373      *
374      * It is possible that the underlying synthesizer
375      * does not support local control. In order
376      * to verify that a call to <code>localControl</code>
377      * was successful, check the return value.
378      *
379      * @param on <code>true</code> to turn local control on, <code>false</code>
380      * to turn local control off
381      * @return the new local-control value, or false
382      * if local control is not supported
383      *
384      */

385     public boolean localControl(boolean on);
386
387     /**
388      * Turns mono mode on or off. In mono mode, the channel synthesizes
389      * only one note at a time. In poly mode (identical to mono mode off),
390      * the channel can synthesize multiple notes simultaneously.
391      * The default is mono off (poly mode on).
392      * <p>
393      * "Mono" is short for the word "monophonic," which in this context
394      * is opposed to the word "polyphonic" and refers to a single synthesizer
395      * voice per MIDI channel. It
396      * has nothing to do with how many audio channels there might be
397      * (as in "monophonic" versus "stereophonic" recordings).
398      *
399      * It is possible that the underlying synthesizer
400      * does not support mono mode. In order
401      * to verify that a call to <code>setMono</code>
402      * was successful, use <code>getMono</code>.
403      *
404      * @param on <code>true</code> to turn mono mode on, <code>false</code> to
405      * turn it off (which means turning poly mode on).
406      *
407      * @see #getMono
408      * @see VoiceStatus
409      */

410     public void setMono(boolean on);
411
412     /**
413      * Obtains the current mono/poly mode.
414      * Synthesizers that do not allow changing mono/poly mode
415      * will always return the same value, regardless
416      * of calls to <code>setMono</code>.
417      * @return <code>true</code> if mono mode is on, otherwise
418      * <code>false</code> (meaning poly mode is on).
419      *
420      * @see #setMono(boolean)
421      */

422     public boolean getMono();
423
424     /**
425      * Turns omni mode on or off. In omni mode, the channel responds
426      * to messages sent on all channels. When omni is off, the channel
427      * responds only to messages sent on its channel number.
428      * The default is omni off.
429      *
430      * It is possible that the underlying synthesizer
431      * does not support omni mode. In order
432      * to verify that <code>setOmni</code>
433      * was successful, use <code>getOmni</code>.
434      *
435      * @param on <code>true</code> to turn omni mode on, <code>false</code> to
436      * turn it off.
437      *
438      * @see #getOmni
439      * @see VoiceStatus
440      */

441     public void setOmni(boolean on);
442
443     /**
444      * Obtains the current omni mode.
445      * Synthesizers that do not allow changing the omni mode
446      * will always return the same value, regardless
447      * of calls to <code>setOmni</code>.
448      * @return <code>true</code> if omni mode is on, otherwise
449      * <code>false</code> (meaning omni mode is off).
450      *
451      * @see #setOmni(boolean)
452      */

453     public boolean getOmni();
454
455     /**
456      * Sets the mute state for this channel. A value of
457      * <code>true</code> means the channel is to be muted, <code>false</code>
458      * means the channel can sound (if other channels are not soloed).
459      * <p>
460      * Unlike {@link #allSoundOff()}, this method
461      * applies to only a specific channel, not to all channels. Further, it
462      * silences not only currently sounding notes, but also subsequently
463      * received notes.
464      *
465      * It is possible that the underlying synthesizer
466      * does not support muting channels. In order
467      * to verify that a call to <code>setMute</code>
468      * was successful, use <code>getMute</code>.
469      *
470      * @param mute the new mute state
471      *
472      * @see #getMute
473      * @see #setSolo(boolean)
474      */

475     public void setMute(boolean mute);
476
477     /**
478      * Obtains the current mute state for this channel.
479      * If the underlying synthesizer does not support
480      * muting this channel, this method always returns
481      * <code>false</code>.
482      *
483      * @return <code>true</code> the channel is muted,
484      * or <code>false</code> if not
485      *
486      * @see #setMute(boolean)
487      */

488     public boolean getMute();
489
490     /**
491      * Sets the solo state for this channel.
492      * If <code>solo</code> is <code>true</code> only this channel
493      * and other soloed channels will sound. If <code>solo</code>
494      * is <code>false</code> then only other soloed channels will
495      * sound, unless no channels are soloed, in which case all
496      * unmuted channels will sound.
497      *
498      * It is possible that the underlying synthesizer
499      * does not support solo channels. In order
500      * to verify that a call to <code>setSolo</code>
501      * was successful, use <code>getSolo</code>.
502      *
503      * @param soloState new solo state for the channel
504      * @see #getSolo()
505      */

506     public void setSolo(boolean soloState);
507
508     /**
509      * Obtains the current solo state for this channel.
510      * If the underlying synthesizer does not support
511      * solo on this channel, this method always returns
512      * <code>false</code>.
513      *
514      * @return <code>true</code> the channel is solo,
515      * or <code>false</code> if not
516      *
517      * @see #setSolo(boolean)
518      */

519     public boolean getSolo();
520 }
521
Popular Tags