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>SoundbankResource</code> represents any audio resource stored 30 * in a <code>{@link Soundbank}</code>. Common soundbank resources include: 31 * <ul> 32 * <li>Instruments. An instrument may be specified in a variety of 33 * ways. However, all soundbanks have some mechanism for defining 34 * instruments. In doing so, they may reference other resources 35 * stored in the soundbank. Each instrument has a <code>Patch</code> 36 * which specifies the MIDI program and bank by which it may be 37 * referenced in MIDI messages. Instrument information may be 38 * stored in <code>{@link Instrument}</code> objects. 39 * <li>Audio samples. A sample typically is a sampled audio waveform 40 * which contains a short sound recording whose duration is a fraction of 41 * a second, or at most a few seconds. These audio samples may be 42 * used by a <code>{@link Synthesizer}</code> to synthesize sound in response to MIDI 43 * commands, or extracted for use by an application. 44 * (The terminology reflects musicians' use of the word "sample" to refer 45 * collectively to a series of contiguous audio samples or frames, rather than 46 * to a single, instantaneous sample.) 47 * The data class for an audio sample will be an object 48 * that encapsulates the audio sample data itself and information 49 * about how to interpret it (the format of the audio data), such 50 * as an <code>{@link javax.sound.sampled.AudioInputStream}</code>. </li> 51 * <li>Embedded sequences. A sound bank may contain built-in 52 * song data stored in a data object such as a <code>{@link Sequence}</code>. 53 * </ul> 54 * <p> 55 * Synthesizers that use wavetable synthesis or related 56 * techniques play back the audio in a sample when 57 * synthesizing notes, often when emulating the real-world instrument that 58 * was originally recorded. However, there is not necessarily a one-to-one 59 * correspondence between the <code>Instruments</code> and samples 60 * in a <code>Soundbank</code>. A single <code>Instrument</code> can use 61 * multiple SoundbankResources (typically for notes of dissimilar pitch or 62 * brightness). Also, more than one <code>Instrument</code> can use the same 63 * sample. 64 * 65 * @author Kara Kytle 66 */ 67 68 public abstract class SoundbankResource { 69 70 71 /** 72 * The sound bank that contains the <code>SoundbankResources</code> 73 */ 74 private final Soundbank soundBank; 75 76 77 /** 78 * The name of the <code>SoundbankResource</code> 79 */ 80 private final String name; 81 82 83 /** 84 * The class used to represent the sample's data. 85 */ 86 private final Class<?> dataClass; 87 88 89 /** 90 * The wavetable index. 91 */ 92 //private final int index; 93 94 95 /** 96 * Constructs a new <code>SoundbankResource</code> from the given sound bank 97 * and wavetable index. (Setting the <code>SoundbankResource's</code> name, 98 * sampled audio data, and instruments is a subclass responsibility.) 99 * @param soundBank the sound bank containing this <code>SoundbankResource</code> 100 * @param name the name of the sample 101 * @param dataClass the class used to represent the sample's data 102 * 103 * @see #getSoundbank 104 * @see #getName 105 * @see #getDataClass 106 * @see #getData 107 */ 108 protected SoundbankResource(Soundbank soundBank, String name, Class<?> dataClass) { 109 110 this.soundBank = soundBank; 111 this.name = name; 112 this.dataClass = dataClass; 113 } 114 115 116 /** 117 * Obtains the sound bank that contains this <code>SoundbankResource</code>. 118 * @return the sound bank in which this <code>SoundbankResource</code> is stored 119 */ 120 public Soundbank getSoundbank() { 121 return soundBank; 122 } 123 124 125 /** 126 * Obtains the name of the resource. This should generally be a string 127 * descriptive of the resource. 128 * @return the instrument's name 129 */ 130 public String getName() { 131 return name; 132 } 133 134 135 /** 136 * Obtains the class used by this sample to represent its data. 137 * The object returned by <code>getData</code> will be of this 138 * class. If this <code>SoundbankResource</code> object does not support 139 * direct access to its data, returns <code>null</code>. 140 * @return the class used to represent the sample's data, or 141 * null if the data is not accessible 142 */ 143 public Class<?> getDataClass() { 144 return dataClass; 145 } 146 147 148 /** 149 * Obtains the sampled audio that is stored in this <code>SoundbankResource</code>. 150 * The type of object returned depends on the implementation of the 151 * concrete class, and may be queried using <code>getDataClass</code>. 152 * @return an object containing the sampled audio data 153 * @see #getDataClass 154 */ 155 public abstract Object getData(); 156 157 158 /** 159 * Obtains the index of this <code>SoundbankResource</code> into the 160 * <code>Soundbank's</code> set of <code>SoundbankResources</code>. 161 * @return the wavetable index 162 */ 163 //public int getIndex() { 164 // return index; 165 //} 166 167 168 /** 169 * Obtains a list of the instruments in the sound bank that use the 170 * <code>SoundbankResource</code> for sound synthesis. 171 * @return an array of <code>Instruments</code> that reference this 172 * <code>SoundbankResource</code> 173 * 174 * @see Instrument#getSamples 175 */ 176 //public abstract Instrument[] getInstruments(); 177 } | 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 import javax.sound.sampled.AudioInputStream; 29 30 /** 31 * A {@code SoundbankResource} represents any audio resource stored in a 32 * {@link Soundbank}. Common soundbank resources include: 33 * <ul> 34 * <li>Instruments. An instrument may be specified in a variety of ways. 35 * However, all soundbanks have some mechanism for defining instruments. In 36 * doing so, they may reference other resources stored in the soundbank. Each 37 * instrument has a {@code Patch} which specifies the MIDI program and bank by 38 * which it may be referenced in MIDI messages. Instrument information may be 39 * stored in {@link Instrument} objects.</li> 40 * <li>Audio samples. A sample typically is a sampled audio waveform which 41 * contains a short sound recording whose duration is a fraction of a second, or 42 * at most a few seconds. These audio samples may be used by a 43 * {@link Synthesizer} to synthesize sound in response to MIDI commands, or 44 * extracted for use by an application. (The terminology reflects musicians' use 45 * of the word "sample" to refer collectively to a series of contiguous audio 46 * samples or frames, rather than to a single, instantaneous sample.) The data 47 * class for an audio sample will be an object that encapsulates the audio 48 * sample data itself and information about how to interpret it (the format of 49 * the audio data), such as an {@link AudioInputStream}.</li> 50 * <li>Embedded sequences. A sound bank may contain built-in song data stored in 51 * a data object such as a {@link Sequence}.</li> 52 * </ul> 53 * Synthesizers that use wavetable synthesis or related techniques play back the 54 * audio in a sample when synthesizing notes, often when emulating the 55 * real-world instrument that was originally recorded. However, there is not 56 * necessarily a one-to-one correspondence between the {@code Instruments} and 57 * samples in a {@code Soundbank}. A single {@code Instrument} can use multiple 58 * SoundbankResources (typically for notes of dissimilar pitch or brightness). 59 * Also, more than one {@code Instrument} can use the same sample. 60 * 61 * @author Kara Kytle 62 */ 63 public abstract class SoundbankResource { 64 65 /** 66 * The sound bank that contains the {@code SoundbankResources}. 67 */ 68 private final Soundbank soundBank; 69 70 /** 71 * The name of the {@code SoundbankResource}. 72 */ 73 private final String name; 74 75 /** 76 * The class used to represent the sample's data. 77 */ 78 private final Class<?> dataClass; 79 80 /** 81 * The wavetable index. 82 */ 83 //private final int index; 84 85 /** 86 * Constructs a new {@code SoundbankResource} from the given sound bank and 87 * wavetable index. (Setting the {@code SoundbankResource's} name, sampled 88 * audio data, and instruments is a subclass responsibility.) 89 * 90 * @param soundBank the sound bank containing this 91 * {@code SoundbankResource} 92 * @param name the name of the sample 93 * @param dataClass the class used to represent the sample's data 94 * @see #getSoundbank 95 * @see #getName 96 * @see #getDataClass 97 * @see #getData 98 */ 99 protected SoundbankResource(Soundbank soundBank, String name, Class<?> dataClass) { 100 101 this.soundBank = soundBank; 102 this.name = name; 103 this.dataClass = dataClass; 104 } 105 106 /** 107 * Obtains the sound bank that contains this {@code SoundbankResource}. 108 * 109 * @return the sound bank in which this {@code SoundbankResource} is stored 110 */ 111 public Soundbank getSoundbank() { 112 return soundBank; 113 } 114 115 /** 116 * Obtains the name of the resource. This should generally be a string 117 * descriptive of the resource. 118 * 119 * @return the instrument's name 120 */ 121 public String getName() { 122 return name; 123 } 124 125 /** 126 * Obtains the class used by this sample to represent its data. The object 127 * returned by {@code getData} will be of this class. If this 128 * {@code SoundbankResource} object does not support direct access to its 129 * data, returns {@code null}. 130 * 131 * @return the class used to represent the sample's data, or null if the 132 * data is not accessible 133 */ 134 public Class<?> getDataClass() { 135 return dataClass; 136 } 137 138 /** 139 * Obtains the sampled audio that is stored in this 140 * {@code SoundbankResource}. The type of object returned depends on the 141 * implementation of the concrete class, and may be queried using 142 * {@code getDataClass}. 143 * 144 * @return an object containing the sampled audio data 145 * @see #getDataClass 146 */ 147 public abstract Object getData(); 148 149 /** 150 * Obtains the index of this {@code SoundbankResource} into the 151 * {@code Soundbank's} set of {@code SoundbankResources}. 152 * 153 * @return the wavetable index 154 */ 155 //public int getIndex() { 156 // return index; 157 //} 158 159 /** 160 * Obtains a list of the instruments in the sound bank that use the 161 * {@code SoundbankResource} for sound synthesis. 162 * 163 * @return an array of {@code Instruments} that reference this 164 * {@code SoundbankResource} 165 * @see Instrument#getSamples 166 */ 167 //public abstract Instrument[] getInstruments(); 168 } |