Search in sources :

Example 21 with Patch

use of javax.sound.midi.Patch 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 22 with Patch

use of javax.sound.midi.Patch 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)

Example 23 with Patch

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

the class NewSoftTuningPatch method main.

public static void main(String[] args) throws Exception {
    SoftTuning tuning = new SoftTuning(new Patch(8, 32));
    assertEquals(tuning.getPatch().getProgram(), 32);
    assertEquals(tuning.getPatch().getBank(), 8);
}
Also used : Patch(javax.sound.midi.Patch)

Example 24 with Patch

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

the class SoftSynthesizer method loadInstruments.

public boolean loadInstruments(Soundbank soundbank, Patch[] patchList) {
    List<ModelInstrument> instruments = new ArrayList<ModelInstrument>();
    for (Patch patch : patchList) {
        Instrument ins = soundbank.getInstrument(patch);
        if (ins == null || !(ins instanceof ModelInstrument)) {
            throw new IllegalArgumentException("Unsupported instrument: " + ins);
        }
        instruments.add((ModelInstrument) ins);
    }
    return loadInstruments(instruments);
}
Also used : ArrayList(java.util.ArrayList) Instrument(javax.sound.midi.Instrument) Patch(javax.sound.midi.Patch)

Example 25 with Patch

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

the class ModelInstrument method getPatchAlias.

// Get General MIDI 2 Alias patch for this instrument.
public final Patch getPatchAlias() {
    Patch patch = getPatch();
    int program = patch.getProgram();
    int bank = patch.getBank();
    if (bank != 0)
        return patch;
    boolean percussion = false;
    if (getPatch() instanceof ModelPatch)
        percussion = ((ModelPatch) getPatch()).isPercussion();
    if (percussion)
        return new Patch(0x78 << 7, program);
    else
        return new Patch(0x79 << 7, program);
}
Also used : Patch(javax.sound.midi.Patch)

Aggregations

Patch (javax.sound.midi.Patch)28 Soundbank (javax.sound.midi.Soundbank)12 Instrument (javax.sound.midi.Instrument)7 SF2SoundbankReader (com.sun.media.sound.SF2SoundbankReader)4 File (java.io.File)4 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)2 AudioSynthesizer (com.sun.media.sound.AudioSynthesizer)1 EmergencySoundbank (com.sun.media.sound.EmergencySoundbank)1 ModelInstrument (com.sun.media.sound.ModelInstrument)1 ModelPatch (com.sun.media.sound.ModelPatch)1 SF2Instrument (com.sun.media.sound.SF2Instrument)1 SF2InstrumentRegion (com.sun.media.sound.SF2InstrumentRegion)1 SF2Layer (com.sun.media.sound.SF2Layer)1 SF2LayerRegion (com.sun.media.sound.SF2LayerRegion)1 SF2Sample (com.sun.media.sound.SF2Sample)1 SF2Soundbank (com.sun.media.sound.SF2Soundbank)1 SoftSynthesizer (com.sun.media.sound.SoftSynthesizer)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1