Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/sound/midi/SoundbankResource.java
41159 views
1
/*
2
* Copyright (c) 1999, 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
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.
37
* Each instrument has a {@code Patch} which specifies the MIDI program and
38
* bank by which it may be referenced in MIDI messages. Instrument information
39
* may be stored in {@link Instrument} objects.
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
42
* second, or 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'
45
* use of the word "sample" to refer collectively to a series of contiguous
46
* audio samples or frames, rather than to a single, instantaneous sample.)
47
* The data class for an audio sample will be an object that encapsulates
48
* the audio sample data itself and information about how to interpret it
49
* (the format of the audio data), such as an {@link AudioInputStream}.
50
* <li>Embedded sequences. A sound bank may contain built-in song data stored
51
* in a data object such as a {@link Sequence}.
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
}
169
170