Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/midi/VoiceStatus.java
38830 views
/*1* Copyright (c) 1998, 2002, 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>VoiceStatus</code> object contains information about the current30* status of one of the voices produced by a {@link Synthesizer}.31* <p>32* MIDI synthesizers are generally capable of producing some maximum number of33* simultaneous notes, also referred to as voices. A voice is a stream34* of successive single notes, and the process of assigning incoming MIDI notes to35* specific voices is known as voice allocation.36* However, the voice-allocation algorithm and the contents of each voice are37* normally internal to a MIDI synthesizer and hidden from outside view. One can, of38* course, learn from MIDI messages which notes the synthesizer is playing, and39* one might be able deduce something about the assignment of notes to voices.40* But MIDI itself does not provide a means to report which notes a41* synthesizer has assigned to which voice, nor even to report how many voices42* the synthesizer is capable of synthesizing.43* <p>44* In Java Sound, however, a45* <code>Synthesizer</code> class can expose the contents of its voices through its46* {@link Synthesizer#getVoiceStatus() getVoiceStatus()} method.47* This behavior is recommended but optional;48* synthesizers that don't expose their voice allocation simply return a49* zero-length array. A <code>Synthesizer</code> that does report its voice status50* should maintain this information at51* all times for all of its voices, whether they are currently sounding or52* not. In other words, a given type of <code>Synthesizer</code> always has a fixed53* number of voices, equal to the maximum number of simultaneous notes it is54* capable of sounding.55* <p>56* <A NAME="description_of_active"></A>57* If the voice is not currently processing a MIDI note, it58* is considered inactive. A voice is inactive when it has59* been given no note-on commands, or when every note-on command received has60* been terminated by a corresponding note-off (or by an "all notes off"61* message). For example, this happens when a synthesizer capable of playing 1662* simultaneous notes is told to play a four-note chord; only63* four voices are active in this case (assuming no earlier notes are still playing).64* Usually, a voice whose status is reported as active is producing audible sound, but this65* is not always true; it depends on the details of the instrument (that66* is, the synthesis algorithm) and how long the note has been going on.67* For example, a voice may be synthesizing the sound of a single hand-clap. Because68* this sound dies away so quickly, it may become inaudible before a note-off69* message is received. In such a situation, the voice is still considered active70* even though no sound is currently being produced.71* <p>72* Besides its active or inactive status, the <code>VoiceStatus</code> class73* provides fields that reveal the voice's current MIDI channel, bank and74* program number, MIDI note number, and MIDI volume. All of these can75* change during the course of a voice. While the voice is inactive, each76* of these fields has an unspecified value, so you should check the active77* field first.78*79* @see Synthesizer#getMaxPolyphony80* @see Synthesizer#getVoiceStatus81*82* @author David Rivas83* @author Kara Kytle84*/8586public class VoiceStatus {878889/**90* Indicates whether the voice is currently processing a MIDI note.91* See the explanation of92* <A HREF="#description_of_active">active and inactive voices</A>.93*/94public boolean active = false;959697/**98* The MIDI channel on which this voice is playing. The value is a99* zero-based channel number if the voice is active, or100* unspecified if the voice is inactive.101*102* @see MidiChannel103* @see #active104*/105public int channel = 0;106107108/**109* The bank number of the instrument that this voice is currently using.110* This is a number dictated by the MIDI bank-select message; it does not111* refer to a <code>SoundBank</code> object.112* The value ranges from 0 to 16383 if the voice is active, and is113* unspecified if the voice is inactive.114* @see Patch115* @see Soundbank116* @see #active117* @see MidiChannel#programChange(int, int)118*/119public int bank = 0;120121122/**123* The program number of the instrument that this voice is currently using.124* The value ranges from 0 to 127 if the voice is active, and is125* unspecified if the voice is inactive.126*127* @see MidiChannel#getProgram128* @see Patch129* @see #active130*/131public int program = 0;132133134/**135* The MIDI note that this voice is playing. The range for an active voice136* is from 0 to 127 in semitones, with 60 referring to Middle C.137* The value is unspecified if the voice is inactive.138*139* @see MidiChannel#noteOn140* @see #active141*/142public int note = 0;143144145/**146* The current MIDI volume level for the voice.147* The value ranges from 0 to 127 if the voice is active, and is148* unspecified if the voice is inactive.149* <p>150* Note that this value does not necessarily reflect151* the instantaneous level of the sound produced by this152* voice; that level is the result of many contributing153* factors, including the current instrument and the154* shape of the amplitude envelope it produces.155*156* @see #active157*/158public int volume = 0;159}160161162