1 /*
   2  * Copyright (c) 1999, 2014, 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  * An instrument is a sound-synthesis algorithm with certain parameter settings,
  30  * usually designed to emulate a specific real-world musical instrument or to
  31  * achieve a specific sort of sound effect. Instruments are typically stored in
  32  * collections called soundbanks. Before the instrument can be used to play
  33  * notes, it must first be loaded onto a synthesizer, and then it must be
  34  * selected for use on one or more channels, via a program-change command. MIDI
  35  * notes that are subsequently received on those channels will be played using
  36  * the sound of the selected instrument.
  37  *
  38  * @author Kara Kytle
  39  * @see Soundbank
  40  * @see Soundbank#getInstruments
  41  * @see Patch
  42  * @see Synthesizer#loadInstrument(Instrument)
  43  * @see MidiChannel#programChange(int, int)
  44  */
  45 public abstract class Instrument extends SoundbankResource {
  46 
  47     /**
  48      * Instrument patch.
  49      */
  50     private final Patch patch;
  51 
  52     /**
  53      * Constructs a new MIDI instrument from the specified {@code Patch}. When a
  54      * subsequent request is made to load the instrument, the sound bank will
  55      * search its contents for this instrument's {@code Patch}, and the
  56      * instrument will be loaded into the synthesizer at the bank and program
  57      * location indicated by the {@code Patch} object.
  58      *
  59      * @param  soundbank sound bank containing the instrument
  60      * @param  patch the patch of this instrument
  61      * @param  name the name of this instrument
  62      * @param  dataClass the class used to represent the sample's data
  63      * @see Synthesizer#loadInstrument(Instrument)
  64      */
  65     protected Instrument(Soundbank soundbank, Patch patch, String name, Class<?> dataClass) {
  66 
  67         super(soundbank, name, dataClass);
  68         this.patch = patch;
  69     }
  70 
  71     /**
  72      * Obtains the {@code Patch} object that indicates the bank and program
  73      * numbers where this instrument is to be stored in the synthesizer.
  74      *
  75      * @return this instrument's patch
  76      */
  77     public Patch getPatch() {
  78         return patch;
  79     }
  80 }