Search in sources :

Example 16 with Soundbank

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

the class LoadInstrument 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.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank) Patch(javax.sound.midi.Patch)

Example 17 with Soundbank

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

the class RemapInstrument 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) {
        Instrument ins3 = defsbk.getInstrument(new Patch(0, 3));
        Instrument ins10 = defsbk.getInstrument(new Patch(0, 10));
        assertTrue(synth.remapInstrument(ins3, ins10));
        Instrument[] loaded = synth.getLoadedInstruments();
        for (int i = 0; i < loaded.length; i++) {
            if (loaded[i].getPatch().getBank() == ins3.getPatch().getBank())
                if (loaded[i].getPatch().getProgram() == ins3.getPatch().getProgram()) {
                    assertEquals(loaded[i].getName(), ins10.getName());
                    break;
                }
        }
    }
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank) Instrument(javax.sound.midi.Instrument) Patch(javax.sound.midi.Patch)

Example 18 with Soundbank

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

the class IsSoundbankSupported method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    synth.openStream(null, null);
    SimpleSoundbank sbk = new SimpleSoundbank();
    SimpleInstrument ins = new SimpleInstrument();
    sbk.addInstrument(ins);
    assertTrue(synth.isSoundbankSupported(sbk));
    Soundbank dummysbk = new Soundbank() {

        public String getName() {
            return null;
        }

        public String getVersion() {
            return null;
        }

        public String getVendor() {
            return null;
        }

        public String getDescription() {
            return null;
        }

        public SoundbankResource[] getResources() {
            return null;
        }

        public Instrument[] getInstruments() {
            Instrument ins = new Instrument(null, null, null, null) {

                public Object getData() {
                    return null;
                }
            };
            return new Instrument[] { ins };
        }

        public Instrument getInstrument(Patch patch) {
            return null;
        }
    };
    assertTrue(!synth.isSoundbankSupported(dummysbk));
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank) SoundbankResource(javax.sound.midi.SoundbankResource) Instrument(javax.sound.midi.Instrument) Patch(javax.sound.midi.Patch)

Example 19 with Soundbank

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

the class GetLoadedInstruments2 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) {
        assertTrue(defsbk.getInstruments().length == synth.getLoadedInstruments().length);
    }
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank)

Example 20 with Soundbank

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

the class GetAvailableInstruments 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) {
        assertTrue(defsbk.getInstruments().length == synth.getAvailableInstruments().length);
    }
    synth.close();
}
Also used : Soundbank(javax.sound.midi.Soundbank)

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