1. /*
  2. * @(#)SoundbankResource.java 1.12 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sound.midi;
  8. /**
  9. * A <code>SoundbankResource</code> represents any audio resource stored
  10. * in a <code>{@link Soundbank}</code>. Common soundbank resources include:
  11. * <ul>
  12. * <li>Instruments. An instrument may be specified in a variety of
  13. * ways. However, all soundbanks have some mechanism for defining
  14. * instruments. In doing so, they may reference other resources
  15. * stored in the soundbank. Each instrument has a <code>Patch</code>
  16. * which specifies the MIDI program and bank by which it may be
  17. * referenced in MIDI messages. Instrument information may be
  18. * stored in <code>{@link Instrument}</code> objects.
  19. * <li>Audio samples. A sample typically is a sampled audio waveform
  20. * which contains a short sound recording whose duration is a fraction of
  21. * a second, or at most a few seconds. These audio samples may be
  22. * used by a <code>{@link Synthesizer}</code> to synthesize sound in response to MIDI
  23. * commands, or extracted for use by an application.
  24. * (The terminology reflects musicians' use of the word "sample" to refer
  25. * collectively to a series of contiguous audio samples or frames, rather than
  26. * to a single, instantaneous sample.)
  27. * The data class for an audio sample will be an object
  28. * that encapsulates the audio sample data itself and information
  29. * about how to interpret it (the format of the audio data), such
  30. * as an <code>{@link javax.sound.sampled.AudioInputStream}</code>. </li>
  31. * <li>Embedded sequences. A sound bank may contain built-in
  32. * song data stored in a data object such as a <code>{@link Sequence}</code>.
  33. * </ul>
  34. * <p>
  35. * Synthesizers that use wavetable synthesis or related
  36. * techniques play back the audio in a sample when
  37. * synthesizing notes, often when emulating the real-world instrument that
  38. * was originally recorded. However, there is not necessarily a one-to-one
  39. * correspondence between the <code>Instruments</code> and samples
  40. * in a <code>Soundbank</code>. A single <code>Instrument</code> can use
  41. * multiple SoundbankResources (typically for notes of dissimilar pitch or
  42. * brightness). Also, more than one <code>Instrument</code> can use the same
  43. * sample.
  44. *
  45. * @version 1.12, 03/01/23
  46. * @author Kara Kytle
  47. */
  48. public abstract class SoundbankResource {
  49. /**
  50. * The sound bank that contains the <code>SoundbankResources</code>
  51. */
  52. private final Soundbank soundBank;
  53. /**
  54. * The name of the <code>SoundbankResource</code>
  55. */
  56. private final String name;
  57. /**
  58. * The class used to represent the sample's data.
  59. */
  60. private final Class dataClass;
  61. /**
  62. * The wavetable index.
  63. */
  64. //private final int index;
  65. /**
  66. * Constructs a new <code>SoundbankResource</code> from the given sound bank
  67. * and wavetable index. (Setting the <code>SoundbankResource's</code> name,
  68. * sampled audio data, and instruments is a subclass responsibility.)
  69. * @param soundBank the sound bank containing this <code>SoundbankResource</code>
  70. * @param name the name of the sample
  71. * @param dataClass the class used to represent the sample's data
  72. *
  73. * @see #getSoundbank
  74. * @see #getName
  75. * @see #getDataClass
  76. * @see #getData
  77. */
  78. protected SoundbankResource(Soundbank soundBank, String name, Class dataClass) {
  79. this.soundBank = soundBank;
  80. this.name = name;
  81. this.dataClass = dataClass;
  82. }
  83. /**
  84. * Obtains the sound bank that contains this <code>SoundbankResource</code>.
  85. * @return the sound bank in which this <code>SoundbankResource</code> is stored
  86. */
  87. public Soundbank getSoundbank() {
  88. return soundBank;
  89. }
  90. /**
  91. * Obtains the name of the resource. This should generally be a string
  92. * descriptive of the resource, and it should be unique within a given
  93. * soundbank, so that a user can select an instrument based on its name.
  94. * @return the instrument's name
  95. */
  96. public String getName() {
  97. return name;
  98. }
  99. /**
  100. * Obtains the class used by this sample to represent its data.
  101. * The object returned by <code>getData</code> will be of this
  102. * class. If this <code>SoundbankResource</code> object does not support
  103. * direct access to its data, returns <code>null</code>.
  104. * @return the class used to represent the sample's data, or
  105. * null if the data is not accessible
  106. */
  107. public Class getDataClass() {
  108. return dataClass;
  109. }
  110. /**
  111. * Obtains the sampled audio that is stored in this <code>SoundbankResource</code>.
  112. * The type of object returned depends on the implementation of the
  113. * concrete class, and may be queried using <code>getDataClass</code>.
  114. * @return an object containing the sampled audio data
  115. * @see #getDataClass
  116. */
  117. public abstract Object getData();
  118. /**
  119. * Obtains the index of this <code>SoundbankResource</code> into the
  120. * <code>Soundbank's</code> set of <code>SoundbankResources</code>.
  121. * @return the wavetable index
  122. */
  123. //public int getIndex() {
  124. // return index;
  125. //}
  126. /**
  127. * Obtains a list of the instruments in the sound bank that use the
  128. * <code>SoundbankResource</code> for sound synthesis.
  129. * @return an array of <code>Instruments</code> that reference this
  130. * <code>SoundbankResource</code>
  131. *
  132. * @see Instrument#getSamples
  133. */
  134. //public abstract Instrument[] getInstruments();
  135. }