Path: blob/master/src/java.desktop/share/classes/javax/sound/midi/VoiceStatus.java
41159 views
/*1* Copyright (c) 1998, 2020, 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 VoiceStatus} object contains information about the current status of29* one of the voices produced by a {@link Synthesizer}.30* <p>31* MIDI synthesizers are generally capable of producing some maximum number of32* simultaneous notes, also referred to as voices. A voice is a stream of33* successive single notes, and the process of assigning incoming MIDI notes to34* specific voices is known as voice allocation. However, the voice-allocation35* algorithm and the contents of each voice are normally internal to a MIDI36* synthesizer and hidden from outside view. One can, of course, learn from MIDI37* messages which notes the synthesizer is playing, and one might be able deduce38* something about the assignment of notes to voices. But MIDI itself does not39* provide a means to report which notes a synthesizer has assigned to which40* voice, nor even to report how many voices the synthesizer is capable of41* synthesizing.42* <p>43* In Java Sound, however, a {@code Synthesizer} class can expose the contents44* of its voices through its45* {@link Synthesizer#getVoiceStatus() getVoiceStatus()} method. This behavior46* is recommended but optional; synthesizers that don't expose their voice47* allocation simply return a zero-length array. A {@code Synthesizer} that does48* report its voice status should maintain this information at all times for all49* of its voices, whether they are currently sounding or not. In other words, a50* given type of {@code Synthesizer} always has a fixed number of voices, equal51* to the maximum number of simultaneous notes it is capable of sounding.52* <p>53* <a id="description_of_active"></a>If the voice is not currently processing a54* MIDI note, it is considered inactive. A voice is inactive when it has been55* given no note-on commands, or when every note-on command received has been56* terminated by a corresponding note-off (or by an "all notes off" message).57* For example, this happens when a synthesizer capable of playing 1658* simultaneous notes is told to play a four-note chord; only four voices are59* active in this case (assuming no earlier notes are still playing). Usually, a60* voice whose status is reported as active is producing audible sound, but this61* is not always true; it depends on the details of the instrument (that is, the62* synthesis algorithm) and how long the note has been going on. For example, a63* voice may be synthesizing the sound of a single hand-clap. Because this sound64* dies away so quickly, it may become inaudible before a note-off message is65* received. In such a situation, the voice is still considered active even66* though no sound is currently being produced.67* <p>68* Besides its active or inactive status, the {@code VoiceStatus} class provides69* fields that reveal the voice's current MIDI channel, bank and program number,70* MIDI note number, and MIDI volume. All of these can change during the course71* of a voice. While the voice is inactive, each of these fields has an72* unspecified value, so you should check the active field first.73*74* @author David Rivas75* @author Kara Kytle76* @see Synthesizer#getMaxPolyphony77* @see Synthesizer#getVoiceStatus78*/79public class VoiceStatus {8081/**82* Indicates whether the voice is currently processing a MIDI note. See the83* explanation of84* <a HREF="#description_of_active">active and inactive voices</a>.85*/86public boolean active = false;8788/**89* The MIDI channel on which this voice is playing. The value is a90* zero-based channel number if the voice is active, or unspecified if the91* voice is inactive.92*93* @see MidiChannel94* @see #active95*/96public int channel = 0;9798/**99* The bank number of the instrument that this voice is currently using.100* This is a number dictated by the MIDI bank-select message; it does not101* refer to a {@code SoundBank} object. The value ranges from 0 to 16383 if102* the voice is active, and is unspecified if the voice is inactive.103*104* @see Patch105* @see Soundbank106* @see #active107* @see MidiChannel#programChange(int, int)108*/109public int bank = 0;110111/**112* The program number of the instrument that this voice is currently using.113* The value ranges from 0 to 127 if the voice is active, and is unspecified114* if the voice is inactive.115*116* @see MidiChannel#getProgram117* @see Patch118* @see #active119*/120public int program = 0;121122/**123* The MIDI note that this voice is playing. The range for an active voice124* is from 0 to 127 in semitones, with 60 referring to Middle C. The value125* is unspecified if the voice is inactive.126*127* @see MidiChannel#noteOn128* @see #active129*/130public int note = 0;131132/**133* The current MIDI volume level for the voice. The value ranges from 0 to134* 127 if the voice is active, and is unspecified if the voice is inactive.135* <p>136* Note that this value does not necessarily reflect the instantaneous level137* of the sound produced by this voice; that level is the result of many138* contributing factors, including the current instrument and the shape of139* the amplitude envelope it produces.140*141* @see #active142*/143public int volume = 0;144145/**146* Constructs a {@code VoiceStatus}.147*/148public VoiceStatus() {}149}150151152