Search in sources :

Example 1 with Instrument

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

the class SimpleSoundbank method getInstrument.

public Instrument getInstrument(Patch patch) {
    int program = patch.getProgram();
    int bank = patch.getBank();
    boolean percussion = false;
    if (patch instanceof ModelPatch)
        percussion = ((ModelPatch) patch).isPercussion();
    for (Instrument instrument : instruments) {
        Patch patch2 = instrument.getPatch();
        int program2 = patch2.getProgram();
        int bank2 = patch2.getBank();
        if (program == program2 && bank == bank2) {
            boolean percussion2 = false;
            if (patch2 instanceof ModelPatch)
                percussion2 = ((ModelPatch) patch2).isPercussion();
            if (percussion == percussion2)
                return instrument;
        }
    }
    return null;
}
Also used : Instrument(javax.sound.midi.Instrument) Patch(javax.sound.midi.Patch)

Example 2 with Instrument

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

the class SoftSynthesizer method getAvailableInstruments.

public Instrument[] getAvailableInstruments() {
    Soundbank defsbk = getDefaultSoundbank();
    if (defsbk == null)
        return new Instrument[0];
    Instrument[] inslist_array = defsbk.getInstruments();
    Arrays.sort(inslist_array, new ModelInstrumentComparator());
    return inslist_array;
}
Also used : Soundbank(javax.sound.midi.Soundbank) Instrument(javax.sound.midi.Instrument)

Example 3 with Instrument

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

the class DLSSoundbank method getInstrument.

public Instrument getInstrument(Patch patch) {
    int program = patch.getProgram();
    int bank = patch.getBank();
    boolean percussion = false;
    if (patch instanceof ModelPatch)
        percussion = ((ModelPatch) patch).isPercussion();
    for (Instrument instrument : instruments) {
        Patch patch2 = instrument.getPatch();
        int program2 = patch2.getProgram();
        int bank2 = patch2.getBank();
        if (program == program2 && bank == bank2) {
            boolean percussion2 = false;
            if (patch2 instanceof ModelPatch)
                percussion2 = ((ModelPatch) patch2).isPercussion();
            if (percussion == percussion2)
                return instrument;
        }
    }
    return null;
}
Also used : Instrument(javax.sound.midi.Instrument) Patch(javax.sound.midi.Patch)

Example 4 with Instrument

use of javax.sound.midi.Instrument 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 5 with Instrument

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

Aggregations

Instrument (javax.sound.midi.Instrument)9 Patch (javax.sound.midi.Patch)7 Soundbank (javax.sound.midi.Soundbank)3 ArrayList (java.util.ArrayList)1 SoundbankResource (javax.sound.midi.SoundbankResource)1