1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.sound.midi;
  27 
  28 /**
  29  * A {@code VoiceStatus} object contains information about the current status of
  30  * one of the voices produced by a {@link Synthesizer}.
  31  * <p>
  32  * MIDI synthesizers are generally capable of producing some maximum number of
  33  * simultaneous notes, also referred to as voices. A voice is a stream of
  34  * successive single notes, and the process of assigning incoming MIDI notes to
  35  * specific voices is known as voice allocation. However, the voice-allocation
  36  * algorithm and the contents of each voice are normally internal to a MIDI
  37  * synthesizer and hidden from outside view. One can, of course, learn from MIDI
  38  * messages which notes the synthesizer is playing, and one might be able deduce
  39  * something about the assignment of notes to voices. But MIDI itself does not
  40  * provide a means to report which notes a synthesizer has assigned to which
  41  * voice, nor even to report how many voices the synthesizer is capable of
  42  * synthesizing.
  43  * <p>
  44  * In Java Sound, however, a {@code Synthesizer} class can expose the contents
  45  * of its voices through its
  46  * {@link Synthesizer#getVoiceStatus() getVoiceStatus()} method. This behavior
  47  * is recommended but optional; synthesizers that don't expose their voice
  48  * allocation simply return a zero-length array. A {@code Synthesizer} that does
  49  * report its voice status should maintain this information at all times for all
  50  * of its voices, whether they are currently sounding or not. In other words, a
  51  * given type of {@code Synthesizer} always has a fixed number of voices, equal
  52  * to the maximum number of simultaneous notes it is capable of sounding.
  53  * <p>
  54  * <a id="description_of_active"></a> If the voice is not currently processing
  55  * a MIDI note, it is considered inactive. A voice is inactive when it has been
  56  * given no note-on commands, or when every note-on command received has been
  57  * terminated by a corresponding note-off (or by an "all notes off" message).
  58  * For example, this happens when a synthesizer capable of playing 16
  59  * simultaneous notes is told to play a four-note chord; only four voices are
  60  * active in this case (assuming no earlier notes are still playing). Usually, a
  61  * voice whose status is reported as active is producing audible sound, but this
  62  * is not always true; it depends on the details of the instrument (that is, the
  63  * synthesis algorithm) and how long the note has been going on. For example, a
  64  * voice may be synthesizing the sound of a single hand-clap. Because this sound
  65  * dies away so quickly, it may become inaudible before a note-off message is
  66  * received. In such a situation, the voice is still considered active even
  67  * though no sound is currently being produced.
  68  * <p>
  69  * Besides its active or inactive status, the {@code VoiceStatus} class provides
  70  * fields that reveal the voice's current MIDI channel, bank and program number,
  71  * MIDI note number, and MIDI volume. All of these can change during the course
  72  * of a voice. While the voice is inactive, each of these fields has an
  73  * unspecified value, so you should check the active field first.
  74  *
  75  * @author David Rivas
  76  * @author Kara Kytle
  77  * @see Synthesizer#getMaxPolyphony
  78  * @see Synthesizer#getVoiceStatus
  79  */
  80 public class VoiceStatus {
  81 
  82     /**
  83      * Indicates whether the voice is currently processing a MIDI note. See the
  84      * explanation of
  85      * <a HREF="#description_of_active">active and inactive voices</a>.
  86      */
  87     public boolean active = false;
  88 
  89     /**
  90      * The MIDI channel on which this voice is playing. The value is a
  91      * zero-based channel number if the voice is active, or unspecified if the
  92      * voice is inactive.
  93      *
  94      * @see MidiChannel
  95      * @see #active
  96      */
  97     public int channel = 0;
  98 
  99     /**
 100      * The bank number of the instrument that this voice is currently using.
 101      * This is a number dictated by the MIDI bank-select message; it does not
 102      * refer to a {@code SoundBank} object. The value ranges from 0 to 16383 if
 103      * the voice is active, and is unspecified if the voice is inactive.
 104      *
 105      * @see Patch
 106      * @see Soundbank
 107      * @see #active
 108      * @see MidiChannel#programChange(int, int)
 109      */
 110     public int bank = 0;
 111 
 112     /**
 113      * The program number of the instrument that this voice is currently using.
 114      * The value ranges from 0 to 127 if the voice is active, and is unspecified
 115      * if the voice is inactive.
 116      *
 117      * @see MidiChannel#getProgram
 118      * @see Patch
 119      * @see #active
 120      */
 121     public int program = 0;
 122 
 123     /**
 124      * The MIDI note that this voice is playing. The range for an active voice
 125      * is from 0 to 127 in semitones, with 60 referring to Middle C. The value
 126      * is unspecified if the voice is inactive.
 127      *
 128      * @see MidiChannel#noteOn
 129      * @see #active
 130      */
 131     public int note = 0;
 132 
 133     /**
 134      * The current MIDI volume level for the voice. The value ranges from 0 to
 135      * 127 if the voice is active, and is unspecified if the voice is inactive.
 136      * <p>
 137      * Note that this value does not necessarily reflect the instantaneous level
 138      * of the sound produced by this voice; that level is the result of many
 139      * contributing factors, including the current instrument and the shape of
 140      * the amplitude envelope it produces.
 141      *
 142      * @see #active
 143      */
 144     public int volume = 0;
 145 }