Path: blob/master/test/jdk/javax/sound/midi/Gervill/SoftReceiver/Send_ResetAllControllers.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 SoftReceiver send method25@modules java.desktop/com.sun.media.sound26*/2728import javax.sound.midi.*;29import javax.sound.sampled.*;3031import com.sun.media.sound.*;3233public class Send_ResetAllControllers {3435public static boolean[] dontResetControls = new boolean[128];36static {37for (int i = 0; i < dontResetControls.length; i++)38dontResetControls[i] = false;3940dontResetControls[0] = true; // Bank Select (MSB)41dontResetControls[32] = true; // Bank Select (LSB)42dontResetControls[7] = true; // Channel Volume (MSB)43dontResetControls[8] = true; // Balance (MSB)44dontResetControls[10] = true; // Pan (MSB)45dontResetControls[11] = true; // Expression (MSB)46dontResetControls[91] = true; // Effects 1 Depth (default: Reverb Send)47dontResetControls[92] = true; // Effects 2 Depth (default: Tremolo Depth)48dontResetControls[93] = true; // Effects 3 Depth (default: Chorus Send)49dontResetControls[94] = true; // Effects 4 Depth (default: Celeste [Detune] Depth)50dontResetControls[95] = true; // Effects 5 Depth (default: Phaser Depth)51dontResetControls[70] = true; // Sound Controller 1 (default: Sound Variation)52dontResetControls[71] = true; // Sound Controller 2 (default: Timbre / Harmonic Quality)53dontResetControls[72] = true; // Sound Controller 3 (default: Release Time)54dontResetControls[73] = true; // Sound Controller 4 (default: Attack Time)55dontResetControls[74] = true; // Sound Controller 5 (default: Brightness)56dontResetControls[75] = true; // Sound Controller 6 (GM2 default: Decay Time)57dontResetControls[76] = true; // Sound Controller 7 (GM2 default: Vibrato Rate)58dontResetControls[77] = true; // Sound Controller 8 (GM2 default: Vibrato Depth)59dontResetControls[78] = true; // Sound Controller 9 (GM2 default: Vibrato Delay)60dontResetControls[79] = true; // Sound Controller 10 (GM2 default: Undefined)61dontResetControls[120] = true; // All Sound Off62dontResetControls[121] = true; // Reset All Controllers63dontResetControls[122] = true; // Local Control On/Off64dontResetControls[123] = true; // All Notes Off65dontResetControls[124] = true; // Omni Mode Off66dontResetControls[125] = true; // Omni Mode On67dontResetControls[126] = true; // Poly Mode Off68dontResetControls[127] = true; // Poly Mode On6970dontResetControls[6] = true; // Data Entry (MSB)71dontResetControls[38] = true; // Data Entry (LSB)72dontResetControls[96] = true; // Data Increment73dontResetControls[97] = true; // Data Decrement74dontResetControls[98] = true; // Non-Registered Parameter Number (LSB)75dontResetControls[99] = true; // Non-Registered Parameter Number(MSB)76dontResetControls[100] = true; // RPN = Null77dontResetControls[101] = true; // RPN = Null78}7980private static void assertEquals(Object a, Object b) throws Exception81{82if(!a.equals(b))83throw new RuntimeException("assertEquals fails!");84}8586private static void assertTrue(boolean value) throws Exception87{88if(!value)89throw new RuntimeException("assertTrue fails!");90}9192public static void main(String[] args) throws Exception {93SoftTestUtils soft = new SoftTestUtils();94MidiChannel channel = soft.synth.getChannels()[0];95Receiver receiver = soft.synth.getReceiver();9697// First let all controls contain non-default values98for (int i = 0; i < 128; i++)99channel.setPolyPressure(i, 10);100channel.setChannelPressure(10);101channel.setPitchBend(2192);102for (int i = 0; i < 120; i++)103channel.controlChange(i, 1);104105ShortMessage smsg = new ShortMessage();106smsg.setMessage(ShortMessage.CONTROL_CHANGE,0, 121,0);107receiver.send(smsg, -1);108109// Now check if resetAllControllers did what it was suppose to do110111for (int i = 0; i < 128; i++)112assertEquals(channel.getPolyPressure(i), 0);113assertEquals(channel.getChannelPressure(), 0);114assertEquals(channel.getPitchBend(),8192);115for (int i = 0; i < 120; i++)116if(!dontResetControls[i])117assertEquals(channel.getController(i), 0);118assertEquals(channel.getController(71), 64); // Filter Resonance119assertEquals(channel.getController(72), 64); // Release Time120assertEquals(channel.getController(73), 64); // Attack Time121assertEquals(channel.getController(74), 64); // Brightness122assertEquals(channel.getController(75), 64); // Decay Time123assertEquals(channel.getController(76), 64); // Vibrato Rate124assertEquals(channel.getController(77), 64); // Vibrato Depth125assertEquals(channel.getController(78), 64); // Vibrato Delay126assertEquals(channel.getController(8), 64); // Balance127assertEquals(channel.getController(11), 127); // Expression128assertEquals(channel.getController(98), 127); // NRPN Null129assertEquals(channel.getController(99), 127); // NRPN Null130assertEquals(channel.getController(100), 127); // RPN = Null131assertEquals(channel.getController(101), 127); // RPN = Null132133soft.close();134}135}136137138