LoadInstruments.java revision 829:b06c29386f63
1233294Sstas/* 2178825Sdfr * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 3178825Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4178825Sdfr * 5178825Sdfr * This code is free software; you can redistribute it and/or modify it 6178825Sdfr * under the terms of the GNU General Public License version 2 only, as 7178825Sdfr * published by the Free Software Foundation. Sun designates this 8178825Sdfr * particular file as subject to the "Classpath" exception as provided 9178825Sdfr * by Sun in the LICENSE file that accompanied this code. 10178825Sdfr * 11178825Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 12178825Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13178825Sdfr * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14178825Sdfr * version 2 for more details (a copy is included in the LICENSE file that 15178825Sdfr * accompanied this code). 16178825Sdfr * 17178825Sdfr * You should have received a copy of the GNU General Public License version 18178825Sdfr * 2 along with this work; if not, write to the Free Software Foundation, 19178825Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20178825Sdfr * 21178825Sdfr * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22178825Sdfr * CA 95054 USA or visit www.sun.com if you need additional information or 23178825Sdfr * have any questions. 24178825Sdfr */ 25178825Sdfr 26178825Sdfr/* @test 27178825Sdfr @summary Test SoftSynthesizer loadAllInstruments method */ 28178825Sdfr 29178825Sdfrimport javax.sound.midi.MidiDevice; 30178825Sdfrimport javax.sound.midi.MidiUnavailableException; 31178825Sdfrimport javax.sound.midi.Patch; 32178825Sdfrimport javax.sound.midi.Soundbank; 33178825Sdfrimport javax.sound.sampled.*; 34178825Sdfrimport javax.sound.midi.MidiDevice.Info; 35178825Sdfr 36178825Sdfrimport com.sun.media.sound.*; 37178825Sdfr 38178825Sdfrpublic class LoadInstruments { 39178825Sdfr 40178825Sdfr private static void assertEquals(Object a, Object b) throws Exception 41178825Sdfr { 42178825Sdfr if(!a.equals(b)) 43178825Sdfr throw new RuntimeException("assertEquals fails!"); 44178825Sdfr } 45178825Sdfr 46178825Sdfr private static void assertTrue(boolean value) throws Exception 47178825Sdfr { 48178825Sdfr if(!value) 49178825Sdfr throw new RuntimeException("assertTrue fails!"); 50178825Sdfr } 51178825Sdfr 52178825Sdfr public static void main(String[] args) throws Exception { 53178825Sdfr AudioSynthesizer synth = new SoftSynthesizer(); 54178825Sdfr synth.openStream(null, null); 55178825Sdfr Soundbank defsbk = synth.getDefaultSoundbank(); 56178825Sdfr if(defsbk != null) 57178825Sdfr { 58178825Sdfr assertTrue(synth.getLoadedInstruments().length == 0); 59178825Sdfr synth.unloadAllInstruments(defsbk); 60178825Sdfr SimpleSoundbank sbk = new SimpleSoundbank(); 61178825Sdfr SimpleInstrument ins = new SimpleInstrument(); 62178825Sdfr ins.setPatch(new Patch(0,1)); 63178825Sdfr sbk.addInstrument(ins); 64178825Sdfr SimpleInstrument ins2 = new SimpleInstrument(); 65178825Sdfr ins2.setPatch(new Patch(0,2)); 66178825Sdfr sbk.addInstrument(ins2); 67178825Sdfr synth.loadInstruments(sbk, new Patch[] {ins2.getPatch()}); 68178825Sdfr assertTrue(synth.getLoadedInstruments().length == 1); 69178825Sdfr } 70178825Sdfr synth.close(); 71178825Sdfr 72178825Sdfr } 73178825Sdfr} 74178825Sdfr