20 * |
20 * |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
|
25 |
25 package com.sun.media.sound; |
26 package com.sun.media.sound; |
26 |
27 |
27 import java.io.File; |
28 import java.io.File; |
28 import java.io.FileInputStream; |
29 import java.io.FileInputStream; |
29 import java.io.IOException; |
30 import java.io.IOException; |
79 // The Sample Data loaded from the SoundFont |
80 // The Sample Data loaded from the SoundFont |
80 private ModelByteBuffer sampleData = null; |
81 private ModelByteBuffer sampleData = null; |
81 private ModelByteBuffer sampleData24 = null; |
82 private ModelByteBuffer sampleData24 = null; |
82 private File sampleFile = null; |
83 private File sampleFile = null; |
83 private boolean largeFormat = false; |
84 private boolean largeFormat = false; |
84 private final List<SF2Instrument> instruments = new ArrayList<SF2Instrument>(); |
85 private final List<SF2Instrument> instruments = new ArrayList<>(); |
85 private final List<SF2Layer> layers = new ArrayList<SF2Layer>(); |
86 private final List<SF2Layer> layers = new ArrayList<>(); |
86 private final List<SF2Sample> samples = new ArrayList<SF2Sample>(); |
87 private final List<SF2Sample> samples = new ArrayList<>(); |
87 |
88 |
88 public SF2Soundbank() { |
89 public SF2Soundbank() { |
89 } |
90 } |
90 |
91 |
91 public SF2Soundbank(URL url) throws IOException { |
92 public SF2Soundbank(URL url) throws IOException { |
222 } |
223 } |
223 } |
224 } |
224 |
225 |
225 private void readPdtaChunk(RIFFReader riff) throws IOException { |
226 private void readPdtaChunk(RIFFReader riff) throws IOException { |
226 |
227 |
227 List<SF2Instrument> presets = new ArrayList<SF2Instrument>(); |
228 List<SF2Instrument> presets = new ArrayList<>(); |
228 List<Integer> presets_bagNdx = new ArrayList<Integer>(); |
229 List<Integer> presets_bagNdx = new ArrayList<>(); |
229 List<SF2InstrumentRegion> presets_splits_gen |
230 List<SF2InstrumentRegion> presets_splits_gen = new ArrayList<>(); |
230 = new ArrayList<SF2InstrumentRegion>(); |
231 List<SF2InstrumentRegion> presets_splits_mod = new ArrayList<>(); |
231 List<SF2InstrumentRegion> presets_splits_mod |
232 |
232 = new ArrayList<SF2InstrumentRegion>(); |
233 List<SF2Layer> instruments = new ArrayList<>(); |
233 |
234 List<Integer> instruments_bagNdx = new ArrayList<>(); |
234 List<SF2Layer> instruments = new ArrayList<SF2Layer>(); |
235 List<SF2LayerRegion> instruments_splits_gen = new ArrayList<>(); |
235 List<Integer> instruments_bagNdx = new ArrayList<Integer>(); |
236 List<SF2LayerRegion> instruments_splits_mod = new ArrayList<>(); |
236 List<SF2LayerRegion> instruments_splits_gen |
|
237 = new ArrayList<SF2LayerRegion>(); |
|
238 List<SF2LayerRegion> instruments_splits_mod |
|
239 = new ArrayList<SF2LayerRegion>(); |
|
240 |
237 |
241 while (riff.hasNextChunk()) { |
238 while (riff.hasNextChunk()) { |
242 RIFFReader chunk = riff.nextChunk(); |
239 RIFFReader chunk = riff.nextChunk(); |
243 String format = chunk.getFormat(); |
240 String format = chunk.getFormat(); |
244 if (format.equals("phdr")) { |
241 if (format.equals("phdr")) { |
828 shdr_chunk.writeString("EOS", 20); |
825 shdr_chunk.writeString("EOS", 20); |
829 shdr_chunk.write(new byte[26]); |
826 shdr_chunk.write(new byte[26]); |
830 |
827 |
831 } |
828 } |
832 |
829 |
|
830 @Override |
833 public String getName() { |
831 public String getName() { |
834 return name; |
832 return name; |
835 } |
833 } |
836 |
834 |
|
835 @Override |
837 public String getVersion() { |
836 public String getVersion() { |
838 return major + "." + minor; |
837 return major + "." + minor; |
839 } |
838 } |
840 |
839 |
|
840 @Override |
841 public String getVendor() { |
841 public String getVendor() { |
842 return engineers; |
842 return engineers; |
843 } |
843 } |
844 |
844 |
|
845 @Override |
845 public String getDescription() { |
846 public String getDescription() { |
846 return comments; |
847 return comments; |
847 } |
848 } |
848 |
849 |
849 public void setName(String s) { |
850 public void setName(String s) { |
856 |
857 |
857 public void setDescription(String s) { |
858 public void setDescription(String s) { |
858 comments = s; |
859 comments = s; |
859 } |
860 } |
860 |
861 |
|
862 @Override |
861 public SoundbankResource[] getResources() { |
863 public SoundbankResource[] getResources() { |
862 SoundbankResource[] resources |
864 SoundbankResource[] resources |
863 = new SoundbankResource[layers.size() + samples.size()]; |
865 = new SoundbankResource[layers.size() + samples.size()]; |
864 int j = 0; |
866 int j = 0; |
865 for (int i = 0; i < layers.size(); i++) |
867 for (int i = 0; i < layers.size(); i++) |
867 for (int i = 0; i < samples.size(); i++) |
869 for (int i = 0; i < samples.size(); i++) |
868 resources[j++] = samples.get(i); |
870 resources[j++] = samples.get(i); |
869 return resources; |
871 return resources; |
870 } |
872 } |
871 |
873 |
|
874 @Override |
872 public SF2Instrument[] getInstruments() { |
875 public SF2Instrument[] getInstruments() { |
873 SF2Instrument[] inslist_array |
876 SF2Instrument[] inslist_array |
874 = instruments.toArray(new SF2Instrument[instruments.size()]); |
877 = instruments.toArray(new SF2Instrument[instruments.size()]); |
875 Arrays.sort(inslist_array, new ModelInstrumentComparator()); |
878 Arrays.sort(inslist_array, new ModelInstrumentComparator()); |
876 return inslist_array; |
879 return inslist_array; |
882 |
885 |
883 public SF2Sample[] getSamples() { |
886 public SF2Sample[] getSamples() { |
884 return samples.toArray(new SF2Sample[samples.size()]); |
887 return samples.toArray(new SF2Sample[samples.size()]); |
885 } |
888 } |
886 |
889 |
|
890 @Override |
887 public Instrument getInstrument(Patch patch) { |
891 public Instrument getInstrument(Patch patch) { |
888 int program = patch.getProgram(); |
892 int program = patch.getProgram(); |
889 int bank = patch.getBank(); |
893 int bank = patch.getBank(); |
890 boolean percussion = false; |
894 boolean percussion = false; |
891 if (patch instanceof ModelPatch) |
895 if (patch instanceof ModelPatch) |
970 samples.add((SF2Sample)resource); |
974 samples.add((SF2Sample)resource); |
971 } |
975 } |
972 |
976 |
973 public void removeResource(SoundbankResource resource) { |
977 public void removeResource(SoundbankResource resource) { |
974 if (resource instanceof SF2Instrument) |
978 if (resource instanceof SF2Instrument) |
975 instruments.remove((SF2Instrument)resource); |
979 instruments.remove(resource); |
976 if (resource instanceof SF2Layer) |
980 if (resource instanceof SF2Layer) |
977 layers.remove((SF2Layer)resource); |
981 layers.remove(resource); |
978 if (resource instanceof SF2Sample) |
982 if (resource instanceof SF2Sample) |
979 samples.remove((SF2Sample)resource); |
983 samples.remove(resource); |
980 } |
984 } |
981 |
985 |
982 public void addInstrument(SF2Instrument resource) { |
986 public void addInstrument(SF2Instrument resource) { |
983 instruments.add(resource); |
987 instruments.add(resource); |
984 } |
988 } |