Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/midi/SoundbankResource.java
38830 views
/*1* Copyright (c) 1999, 2004, 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>SoundbankResource</code> represents any audio resource stored29* in a <code>{@link Soundbank}</code>. Common soundbank resources include:30* <ul>31* <li>Instruments. An instrument may be specified in a variety of32* ways. However, all soundbanks have some mechanism for defining33* instruments. In doing so, they may reference other resources34* stored in the soundbank. Each instrument has a <code>Patch</code>35* which specifies the MIDI program and bank by which it may be36* referenced in MIDI messages. Instrument information may be37* stored in <code>{@link Instrument}</code> objects.38* <li>Audio samples. A sample typically is a sampled audio waveform39* which contains a short sound recording whose duration is a fraction of40* a second, or at most a few seconds. These audio samples may be41* used by a <code>{@link Synthesizer}</code> to synthesize sound in response to MIDI42* commands, or extracted for use by an application.43* (The terminology reflects musicians' use of the word "sample" to refer44* collectively to a series of contiguous audio samples or frames, rather than45* to a single, instantaneous sample.)46* The data class for an audio sample will be an object47* that encapsulates the audio sample data itself and information48* about how to interpret it (the format of the audio data), such49* as an <code>{@link javax.sound.sampled.AudioInputStream}</code>. </li>50* <li>Embedded sequences. A sound bank may contain built-in51* song data stored in a data object such as a <code>{@link Sequence}</code>.52* </ul>53* <p>54* Synthesizers that use wavetable synthesis or related55* techniques play back the audio in a sample when56* synthesizing notes, often when emulating the real-world instrument that57* was originally recorded. However, there is not necessarily a one-to-one58* correspondence between the <code>Instruments</code> and samples59* in a <code>Soundbank</code>. A single <code>Instrument</code> can use60* multiple SoundbankResources (typically for notes of dissimilar pitch or61* brightness). Also, more than one <code>Instrument</code> can use the same62* sample.63*64* @author Kara Kytle65*/6667public abstract class SoundbankResource {686970/**71* The sound bank that contains the <code>SoundbankResources</code>72*/73private final Soundbank soundBank;747576/**77* The name of the <code>SoundbankResource</code>78*/79private final String name;808182/**83* The class used to represent the sample's data.84*/85private final Class dataClass;868788/**89* The wavetable index.90*/91//private final int index;929394/**95* Constructs a new <code>SoundbankResource</code> from the given sound bank96* and wavetable index. (Setting the <code>SoundbankResource's</code> name,97* sampled audio data, and instruments is a subclass responsibility.)98* @param soundBank the sound bank containing this <code>SoundbankResource</code>99* @param name the name of the sample100* @param dataClass the class used to represent the sample's data101*102* @see #getSoundbank103* @see #getName104* @see #getDataClass105* @see #getData106*/107protected SoundbankResource(Soundbank soundBank, String name, Class<?> dataClass) {108109this.soundBank = soundBank;110this.name = name;111this.dataClass = dataClass;112}113114115/**116* Obtains the sound bank that contains this <code>SoundbankResource</code>.117* @return the sound bank in which this <code>SoundbankResource</code> is stored118*/119public Soundbank getSoundbank() {120return soundBank;121}122123124/**125* Obtains the name of the resource. This should generally be a string126* descriptive of the resource.127* @return the instrument's name128*/129public String getName() {130return name;131}132133134/**135* Obtains the class used by this sample to represent its data.136* The object returned by <code>getData</code> will be of this137* class. If this <code>SoundbankResource</code> object does not support138* direct access to its data, returns <code>null</code>.139* @return the class used to represent the sample's data, or140* null if the data is not accessible141*/142public Class<?> getDataClass() {143return dataClass;144}145146147/**148* Obtains the sampled audio that is stored in this <code>SoundbankResource</code>.149* The type of object returned depends on the implementation of the150* concrete class, and may be queried using <code>getDataClass</code>.151* @return an object containing the sampled audio data152* @see #getDataClass153*/154public abstract Object getData();155156157/**158* Obtains the index of this <code>SoundbankResource</code> into the159* <code>Soundbank's</code> set of <code>SoundbankResources</code>.160* @return the wavetable index161*/162//public int getIndex() {163// return index;164//}165166167/**168* Obtains a list of the instruments in the sound bank that use the169* <code>SoundbankResource</code> for sound synthesis.170* @return an array of <code>Instruments</code> that reference this171* <code>SoundbankResource</code>172*173* @see Instrument#getSamples174*/175//public abstract Instrument[] getInstruments();176}177178179