Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerIntInt.java
38859 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@summary Test SimpleInstrument add(ModelPerformer,int,int) method */2526import javax.sound.sampled.*;2728import com.sun.media.sound.*;2930public class AddModelPerformerIntInt {3132private static void assertEquals(Object a, Object b) throws Exception33{34if(!a.equals(b))35throw new RuntimeException("assertEquals fails!");36}3738public static void main(String[] args) throws Exception {3940SimpleInstrument instrument = new SimpleInstrument();4142ModelPerformer[] performers = new ModelPerformer[2];4344performers[0] = new ModelPerformer();45performers[0].setExclusiveClass(1);46performers[0].setKeyFrom(36);47performers[0].setKeyTo(48);48performers[0].setVelFrom(16);49performers[0].setVelTo(80);50performers[0].setSelfNonExclusive(true);51performers[0].setDefaultConnectionsEnabled(false);52performers[0].getConnectionBlocks().add(new ModelConnectionBlock());53performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));5455performers[1] = new ModelPerformer();56performers[1].setExclusiveClass(0);57performers[1].setKeyFrom(12);58performers[1].setKeyTo(24);59performers[1].setVelFrom(20);60performers[1].setVelTo(90);61performers[1].setSelfNonExclusive(false);62performers[0].setDefaultConnectionsEnabled(true);63performers[1].getConnectionBlocks().add(new ModelConnectionBlock());64performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));6566instrument.add(performers[0],18,40);67ModelPerformer[] performers2 = instrument.getPerformers();68for (int i = 0; i < performers2.length; i++) {69assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());70assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());71if(performers[i].getKeyFrom() < 18)72assertEquals(18, performers2[i].getKeyFrom());73else74assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());75if(performers[i].getKeyTo() > 40)76assertEquals(40, performers2[i].getKeyTo());77else78assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());79assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());80assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());81assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());82assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());83assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());84}85}86}878889