Path: blob/master/test/jdk/javax/sound/midi/Gervill/SimpleInstrument/AddModelPerformerIntIntIntInt.java
41159 views
/*1* Copyright (c) 2007, 2015, 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,int,int) method25@modules java.desktop/com.sun.media.sound26*/2728import javax.sound.sampled.*;2930import com.sun.media.sound.*;3132public class AddModelPerformerIntIntIntInt {3334private static void assertEquals(Object a, Object b) throws Exception35{36if(!a.equals(b))37throw new RuntimeException("assertEquals fails!");38}3940public static void main(String[] args) throws Exception {4142SimpleInstrument instrument = new SimpleInstrument();4344ModelPerformer[] performers = new ModelPerformer[2];4546performers[0] = new ModelPerformer();47performers[0].setExclusiveClass(1);48performers[0].setKeyFrom(36);49performers[0].setKeyTo(48);50performers[0].setVelFrom(16);51performers[0].setVelTo(80);52performers[0].setSelfNonExclusive(true);53performers[0].setDefaultConnectionsEnabled(false);54performers[0].getConnectionBlocks().add(new ModelConnectionBlock());55performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));5657performers[1] = new ModelPerformer();58performers[1].setExclusiveClass(0);59performers[1].setKeyFrom(12);60performers[1].setKeyTo(24);61performers[1].setVelFrom(20);62performers[1].setVelTo(90);63performers[1].setSelfNonExclusive(false);64performers[0].setDefaultConnectionsEnabled(true);65performers[1].getConnectionBlocks().add(new ModelConnectionBlock());66performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));6768instrument.add(performers[0],18,40,20,75);69ModelPerformer[] performers2 = instrument.getPerformers();70for (int i = 0; i < performers2.length; i++) {71assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());72assertEquals(performers[i].getExclusiveClass(), performers2[i].getExclusiveClass());73if(performers[i].getKeyFrom() < 18)74assertEquals(18, performers2[i].getKeyFrom());75else76assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());77if(performers[i].getKeyTo() > 40)78assertEquals(40, performers2[i].getKeyTo());79else80assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());81if(performers[i].getVelFrom() < 20)82assertEquals(20, performers2[i].getVelFrom());83else84assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());85if(performers[i].getVelTo() > 75)86assertEquals(75, performers2[i].getVelTo());87else88assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());89assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());90assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());91assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());92}93}94}959697