Search in sources :

Example 21 with Soundbank

use of javax.sound.midi.Soundbank in project jdk8u_jdk by JetBrains.

the class TestGetSoundbankInputStream2 method main.

public static void main(String[] args) throws Exception {
    File file = new File(System.getProperty("test.src", "."), "ding.sf2");
    FileInputStream fis = new FileInputStream(file);
    BufferedInputStream bis = new BufferedInputStream(fis);
    try {
        InputStream badis = new BadInputStream(bis);
        Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis);
        assertTrue(sf2.getInstruments().length == 1);
        Patch patch = sf2.getInstruments()[0].getPatch();
        assertTrue(patch.getProgram() == 0);
        assertTrue(patch.getBank() == 0);
    } finally {
        bis.close();
    }
}
Also used : Soundbank(javax.sound.midi.Soundbank) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SF2SoundbankReader(com.sun.media.sound.SF2SoundbankReader) File(java.io.File) Patch(javax.sound.midi.Patch) FileInputStream(java.io.FileInputStream)

Example 22 with Soundbank

use of javax.sound.midi.Soundbank in project jdk8u_jdk by JetBrains.

the class TestGetSoundbankUrl method main.

public static void main(String[] args) throws Exception {
    File file = new File(System.getProperty("test.src", "."), "ding.sf2");
    URL url = file.toURI().toURL();
    Soundbank sf2 = new SF2SoundbankReader().getSoundbank(url);
    assertTrue(sf2.getInstruments().length == 1);
    Patch patch = sf2.getInstruments()[0].getPatch();
    assertTrue(patch.getProgram() == 0);
    assertTrue(patch.getBank() == 0);
}
Also used : Soundbank(javax.sound.midi.Soundbank) SF2SoundbankReader(com.sun.media.sound.SF2SoundbankReader) File(java.io.File) Patch(javax.sound.midi.Patch) URL(java.net.URL)

Example 23 with Soundbank

use of javax.sound.midi.Soundbank in project jdk8u_jdk by JetBrains.

the class UnloadInstrument method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    synth.openStream(null, null);
    Soundbank defsbk = synth.getDefaultSoundbank();
    if (defsbk != null) {
        synth.unloadAllInstruments(defsbk);
        SimpleSoundbank sbk = new SimpleSoundbank();
        SimpleInstrument ins = new SimpleInstrument();
        ins.setPatch(new Patch(0, 1));
        sbk.addInstrument(ins);
        SimpleInstrument ins2 = new SimpleInstrument();
        ins2.setPatch(new Patch(0, 2));
        sbk.addInstrument(ins2);
        synth.loadInstrument(ins2);
        assertTrue(synth.getLoadedInstruments().length == 1);
        synth.unloadInstrument(ins2);
        assertTrue(synth.getLoadedInstruments().length == 0);
    }
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank) Patch(javax.sound.midi.Patch)

Example 24 with Soundbank

use of javax.sound.midi.Soundbank in project jdk8u_jdk by JetBrains.

the class UnloadInstruments method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    synth.openStream(null, null);
    Soundbank defsbk = synth.getDefaultSoundbank();
    if (defsbk != null) {
        synth.unloadAllInstruments(defsbk);
        SimpleSoundbank sbk = new SimpleSoundbank();
        SimpleInstrument ins = new SimpleInstrument();
        ins.setPatch(new Patch(0, 1));
        sbk.addInstrument(ins);
        SimpleInstrument ins2 = new SimpleInstrument();
        ins2.setPatch(new Patch(0, 2));
        sbk.addInstrument(ins2);
        synth.loadInstrument(ins2);
        assertTrue(synth.getLoadedInstruments().length == 1);
        synth.unloadInstruments(sbk, new Patch[] { ins2.getPatch() });
        assertTrue(synth.getLoadedInstruments().length == 0);
    }
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank) Patch(javax.sound.midi.Patch)

Aggregations

Soundbank (javax.sound.midi.Soundbank)24 Patch (javax.sound.midi.Patch)12 File (java.io.File)5 SF2SoundbankReader (com.sun.media.sound.SF2SoundbankReader)4 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Instrument (javax.sound.midi.Instrument)3 AudioInputStream (javax.sound.sampled.AudioInputStream)3 ArrayList (java.util.ArrayList)2 MidiUnavailableException (javax.sound.midi.MidiUnavailableException)2 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)2 EmergencySoundbank (com.sun.media.sound.EmergencySoundbank)1 ModelInstrument (com.sun.media.sound.ModelInstrument)1 ModelPatch (com.sun.media.sound.ModelPatch)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1