Path: blob/master/src/java.desktop/share/classes/javax/sound/midi/SoundbankResource.java
41159 views
/*1* Copyright (c) 1999, 2017, 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;2627import javax.sound.sampled.AudioInputStream;2829/**30* A {@code SoundbankResource} represents any audio resource stored in a31* {@link Soundbank}. Common soundbank resources include:32* <ul>33* <li>Instruments. An instrument may be specified in a variety of ways.34* However, all soundbanks have some mechanism for defining instruments. In35* doing so, they may reference other resources stored in the soundbank.36* Each instrument has a {@code Patch} which specifies the MIDI program and37* bank by which it may be referenced in MIDI messages. Instrument information38* may be stored in {@link Instrument} objects.39* <li>Audio samples. A sample typically is a sampled audio waveform which40* contains a short sound recording whose duration is a fraction of a41* second, or at most a few seconds. These audio samples may be used by a42* {@link Synthesizer} to synthesize sound in response to MIDI commands, or43* extracted for use by an application. (The terminology reflects musicians'44* use of the word "sample" to refer collectively to a series of contiguous45* audio samples or frames, rather than to a single, instantaneous sample.)46* The data class for an audio sample will be an object that encapsulates47* the audio sample data itself and information about how to interpret it48* (the format of the audio data), such as an {@link AudioInputStream}.49* <li>Embedded sequences. A sound bank may contain built-in song data stored50* in a data object such as a {@link Sequence}.51* </ul>52* Synthesizers that use wavetable synthesis or related techniques play back the53* audio in a sample when synthesizing notes, often when emulating the54* real-world instrument that was originally recorded. However, there is not55* necessarily a one-to-one correspondence between the {@code Instruments} and56* samples in a {@code Soundbank}. A single {@code Instrument} can use multiple57* SoundbankResources (typically for notes of dissimilar pitch or brightness).58* Also, more than one {@code Instrument} can use the same sample.59*60* @author Kara Kytle61*/62public abstract class SoundbankResource {6364/**65* The sound bank that contains the {@code SoundbankResources}.66*/67private final Soundbank soundBank;6869/**70* The name of the {@code SoundbankResource}.71*/72private final String name;7374/**75* The class used to represent the sample's data.76*/77private final Class<?> dataClass;7879/**80* The wavetable index.81*/82//private final int index;8384/**85* Constructs a new {@code SoundbankResource} from the given sound bank and86* wavetable index. (Setting the {@code SoundbankResource's} name, sampled87* audio data, and instruments is a subclass responsibility.)88*89* @param soundBank the sound bank containing this90* {@code SoundbankResource}91* @param name the name of the sample92* @param dataClass the class used to represent the sample's data93* @see #getSoundbank94* @see #getName95* @see #getDataClass96* @see #getData97*/98protected SoundbankResource(Soundbank soundBank, String name, Class<?> dataClass) {99100this.soundBank = soundBank;101this.name = name;102this.dataClass = dataClass;103}104105/**106* Obtains the sound bank that contains this {@code SoundbankResource}.107*108* @return the sound bank in which this {@code SoundbankResource} is stored109*/110public Soundbank getSoundbank() {111return soundBank;112}113114/**115* Obtains the name of the resource. This should generally be a string116* descriptive of the resource.117*118* @return the instrument's name119*/120public String getName() {121return name;122}123124/**125* Obtains the class used by this sample to represent its data. The object126* returned by {@code getData} will be of this class. If this127* {@code SoundbankResource} object does not support direct access to its128* data, returns {@code null}.129*130* @return the class used to represent the sample's data, or null if the131* data is not accessible132*/133public Class<?> getDataClass() {134return dataClass;135}136137/**138* Obtains the sampled audio that is stored in this139* {@code SoundbankResource}. The type of object returned depends on the140* implementation of the concrete class, and may be queried using141* {@code getDataClass}.142*143* @return an object containing the sampled audio data144* @see #getDataClass145*/146public abstract Object getData();147148/**149* Obtains the index of this {@code SoundbankResource} into the150* {@code Soundbank's} set of {@code SoundbankResources}.151*152* @return the wavetable index153*/154//public int getIndex() {155// return index;156//}157158/**159* Obtains a list of the instruments in the sound bank that use the160* {@code SoundbankResource} for sound synthesis.161*162* @return an array of {@code Instruments} that reference this163* {@code SoundbankResource}164* @see Instrument#getSamples165*/166//public abstract Instrument[] getInstruments();167}168169170